[llvm] r277910 - [InstCombine] Don't coerce non-integral pointers to integers
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 5 19:58:48 PDT 2016
Author: sanjoy
Date: Fri Aug 5 21:58:48 2016
New Revision: 277910
URL: http://llvm.org/viewvc/llvm-project?rev=277910&view=rev
Log:
[InstCombine] Don't coerce non-integral pointers to integers
Reviewers: majnemer
Subscribers: mcrosier, llvm-commits
Differential Revision: https://reviews.llvm.org/D23231
Modified:
llvm/trunk/include/llvm/IR/DataLayout.h
llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/trunk/test/Transforms/InstCombine/non-integral-pointers.ll
Modified: llvm/trunk/include/llvm/IR/DataLayout.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DataLayout.h?rev=277910&r1=277909&r2=277910&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DataLayout.h (original)
+++ llvm/trunk/include/llvm/IR/DataLayout.h Fri Aug 5 21:58:48 2016
@@ -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.
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp?rev=277910&r1=277909&r2=277910&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp Fri Aug 5 21:58:48 2016
@@ -475,7 +475,8 @@ static Instruction *combineLoadToOperati
// 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;
Modified: llvm/trunk/test/Transforms/InstCombine/non-integral-pointers.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/non-integral-pointers.ll?rev=277910&r1=277909&r2=277910&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/non-integral-pointers.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/non-integral-pointers.ll Fri Aug 5 21:58:48 2016
@@ -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
+}
More information about the llvm-commits
mailing list