summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorSanjoy Das <sanjoy@playingwithpointers.com>2016-08-06 02:58:48 +0000
committerSanjoy Das <sanjoy@playingwithpointers.com>2016-08-06 02:58:48 +0000
commitba04d3a620fe70bc7b29dd91e0bdfe5158046b47 (patch)
tree42a20d7f55200277f9dc4824e035f464cd78cb82 /llvm
parent9a0035d8d218a99e8b76ad63c927a77d26a5d256 (diff)
downloadbcm5719-llvm-ba04d3a620fe70bc7b29dd91e0bdfe5158046b47.tar.gz
bcm5719-llvm-ba04d3a620fe70bc7b29dd91e0bdfe5158046b47.zip
[InstCombine] Don't coerce non-integral pointers to integers
Reviewers: majnemer Subscribers: mcrosier, llvm-commits Differential Revision: https://reviews.llvm.org/D23231 llvm-svn: 277910
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/IR/DataLayout.h5
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp3
-rw-r--r--llvm/test/Transforms/InstCombine/non-integral-pointers.ll28
3 files changed, 35 insertions, 1 deletions
diff --git a/llvm/include/llvm/IR/DataLayout.h b/llvm/include/llvm/IR/DataLayout.h
index 2b481fb6607..e309e93a14e 100644
--- a/llvm/include/llvm/IR/DataLayout.h
+++ b/llvm/include/llvm/IR/DataLayout.h
@@ -338,6 +338,11 @@ public:
NonIntegralSpaces.end();
}
+ bool isNonIntegralPointerType(Type *Ty) const {
+ auto *PTy = dyn_cast<PointerType>(Ty);
+ return PTy && isNonIntegralPointerType(PTy);
+ }
+
/// Layout pointer size, in bits
/// FIXME: The defaults need to be removed once all of
/// the backends/clients are updated.
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index 736c95adae1..8dcc6351ac7 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -475,7 +475,8 @@ static Instruction *combineLoadToOperationType(InstCombiner &IC, LoadInst &LI) {
// size is a legal integer type.
if (!Ty->isIntegerTy() && Ty->isSized() &&
DL.isLegalInteger(DL.getTypeStoreSizeInBits(Ty)) &&
- DL.getTypeStoreSizeInBits(Ty) == DL.getTypeSizeInBits(Ty)) {
+ DL.getTypeStoreSizeInBits(Ty) == DL.getTypeSizeInBits(Ty) &&
+ !DL.isNonIntegralPointerType(Ty)) {
if (std::all_of(LI.user_begin(), LI.user_end(), [&LI](User *U) {
auto *SI = dyn_cast<StoreInst>(U);
return SI && SI->getPointerOperand() != &LI;
diff --git a/llvm/test/Transforms/InstCombine/non-integral-pointers.ll b/llvm/test/Transforms/InstCombine/non-integral-pointers.ll
index d5e2569179b..4f54fe6737d 100644
--- a/llvm/test/Transforms/InstCombine/non-integral-pointers.ll
+++ b/llvm/test/Transforms/InstCombine/non-integral-pointers.ll
@@ -18,3 +18,31 @@ define i8 addrspace(3)* @f_1() {
%result = getelementptr i8, i8 addrspace(3)* null, i64 50
ret i8 addrspace(3)* %result
}
+
+define void @f_2(i8 addrspace(4)** %ptr0, i8 addrspace(4)** %ptr1) {
+; It is not okay to convert the load/store pair to load and store
+; integers, since pointers in address space 4 are non-integral.
+
+; CHECK-LABEL: @f_2(
+entry:
+; CHECK: %val = load i8 addrspace(4)*, i8 addrspace(4)** %ptr0, align 8
+; CHECK: store i8 addrspace(4)* %val, i8 addrspace(4)** %ptr1, align 8
+; CHECK-NOT: load i64
+; CHECK-NOT: store i64
+ %val = load i8 addrspace(4)*, i8 addrspace(4)** %ptr0
+ store i8 addrspace(4)* %val, i8 addrspace(4)** %ptr1
+ ret void
+}
+
+define void @f_3(i8 addrspace(3)** %ptr0, i8 addrspace(3)** %ptr1) {
+; It *is* okay to convert the load/store pair to load and store
+; integers, since pointers in address space 3 are integral.
+
+; CHECK-LABEL: @f_3(
+entry:
+; CHECK: load i64
+; CHECK: store i64
+ %val = load i8 addrspace(3)*, i8 addrspace(3)** %ptr0
+ store i8 addrspace(3)* %val, i8 addrspace(3)** %ptr1
+ ret void
+}
OpenPOWER on IntegriCloud