summaryrefslogtreecommitdiff
path: root/lib/IR
diff options
context:
space:
mode:
authorJingyue Wu <jingyue@google.com>2014-06-06 21:52:55 +0000
committerJingyue Wu <jingyue@google.com>2014-06-06 21:52:55 +0000
commitc77dec905a58b2308e5efe3a7d1635e4965ccff3 (patch)
treec2ad9414c19dd640e04be7f60e6575713bae5f49 /lib/IR
parenta51acc7631fec5bc371d996d7cea45e8a3caee95 (diff)
downloadllvm-c77dec905a58b2308e5efe3a7d1635e4965ccff3.tar.gz
llvm-c77dec905a58b2308e5efe3a7d1635e4965ccff3.tar.bz2
llvm-c77dec905a58b2308e5efe3a7d1635e4965ccff3.tar.xz
InstCombine: Canonicalize addrspacecast between different element types
addrspacecast X addrspace(M)* to Y addrspace(N)* --> bitcast X addrspace(M)* to Y addrspace(M)* addrspacecast Y addrspace(M)* to Y addrspace(N)* Updat all affected tests and add several new tests in addrspacecast.ll. This patch is based on http://reviews.llvm.org/D2186 (authored by Matt Arsenault) with fixes and more tests. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210375 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR')
-rw-r--r--lib/IR/Instructions.cpp18
1 files changed, 6 insertions, 12 deletions
diff --git a/lib/IR/Instructions.cpp b/lib/IR/Instructions.cpp
index 592cdd85e8..051d63f7fc 100644
--- a/lib/IR/Instructions.cpp
+++ b/lib/IR/Instructions.cpp
@@ -2331,18 +2331,12 @@ unsigned CastInst::isEliminableCastPair(
// Allowed, use first cast's opcode
return firstOp;
case 14:
- // FIXME: this state can be merged with (2), but the following assert
- // is useful to check the correcteness of the sequence due to semantic
- // change of bitcast.
- assert(
- SrcTy->isPtrOrPtrVectorTy() &&
- MidTy->isPtrOrPtrVectorTy() &&
- DstTy->isPtrOrPtrVectorTy() &&
- SrcTy->getPointerAddressSpace() == MidTy->getPointerAddressSpace() &&
- MidTy->getPointerAddressSpace() != DstTy->getPointerAddressSpace() &&
- "Illegal bitcast, addrspacecast sequence!");
- // Allowed, use second cast's opcode
- return secondOp;
+ // bitcast, addrspacecast -> addrspacecast if the element type of
+ // bitcast's source is the same as that of addrspacecast's destination.
+ if (SrcTy->getPointerElementType() == DstTy->getPointerElementType())
+ return Instruction::AddrSpaceCast;
+ return 0;
+
case 15:
// FIXME: this state can be merged with (1), but the following assert
// is useful to check the correcteness of the sequence due to semantic