summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2014-03-13 22:51:43 +0000
committerOwen Anderson <resistor@mac.com>2014-03-13 22:51:43 +0000
commitd3fc1be4f634df136220ffc6e2ec381ae3f55c31 (patch)
tree9ce58a4e5ae86196d2dea1a36144fe253adc5de4
parent43d5e074aa8c24506aedf6b7d95839fdd28030b7 (diff)
downloadllvm-d3fc1be4f634df136220ffc6e2ec381ae3f55c31.tar.gz
llvm-d3fc1be4f634df136220ffc6e2ec381ae3f55c31.tar.bz2
llvm-d3fc1be4f634df136220ffc6e2ec381ae3f55c31.tar.xz
Fix a bug in InstCombine where we would incorrectly attempt to construct a
bitcast between pointers of two different address spaces if they happened to have the same pointer size. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203862 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp7
-rw-r--r--test/Transforms/InstCombine/load-addrspace-cast.ll12
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index 1db55fea00..a34acdd832 100644
--- a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -335,6 +335,13 @@ static Instruction *InstCombineLoadCast(InstCombiner &IC, LoadInst &LI,
NewLoad->setAlignment(LI.getAlignment());
NewLoad->setAtomic(LI.getOrdering(), LI.getSynchScope());
// Now cast the result of the load.
+ PointerType *OldTy = dyn_cast<PointerType>(NewLoad->getType());
+ PointerType *NewTy = dyn_cast<PointerType>(LI.getType());
+ if (OldTy && NewTy &&
+ OldTy->getAddressSpace() != NewTy->getAddressSpace()) {
+ return new AddrSpaceCastInst(NewLoad, LI.getType());
+ }
+
return new BitCastInst(NewLoad, LI.getType());
}
}
diff --git a/test/Transforms/InstCombine/load-addrspace-cast.ll b/test/Transforms/InstCombine/load-addrspace-cast.ll
new file mode 100644
index 0000000000..fd6339cc92
--- /dev/null
+++ b/test/Transforms/InstCombine/load-addrspace-cast.ll
@@ -0,0 +1,12 @@
+; RUN: opt -instcombine -S < %s | FileCheck %s
+target datalayout = "e-p:64:64:64-n8:16:32:64"
+
+define i32* @pointer_to_addrspace_pointer(i32 addrspace(1)** %x) nounwind {
+; CHECK-LABEL: @pointer_to_addrspace_pointer(
+; CHECK: load
+; CHECK: addrspacecast
+ %y = bitcast i32 addrspace(1)** %x to i32**
+ %z = load i32** %y
+ ret i32* %z
+}
+