diff options
| -rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 4 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstSimplify/compare.ll | 11 |
2 files changed, 14 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index c0d69f9275d..e34bf6f4e43 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -660,6 +660,10 @@ static Constant *stripAndComputeConstantOffsets(const DataLayout &DL, Value *&V, APInt Offset = APInt::getNullValue(IntPtrTy->getIntegerBitWidth()); V = V->stripAndAccumulateConstantOffsets(DL, Offset, AllowNonInbounds); + // As that strip may trace through `addrspacecast`, need to sext or trunc + // the offset calculated. + IntPtrTy = DL.getIntPtrType(V->getType())->getScalarType(); + Offset = Offset.sextOrTrunc(IntPtrTy->getIntegerBitWidth()); Constant *OffsetIntPtr = ConstantInt::get(IntPtrTy, Offset); if (V->getType()->isVectorTy()) diff --git a/llvm/test/Transforms/InstSimplify/compare.ll b/llvm/test/Transforms/InstSimplify/compare.ll index 899f198d48a..570239eaf0c 100644 --- a/llvm/test/Transforms/InstSimplify/compare.ll +++ b/llvm/test/Transforms/InstSimplify/compare.ll @@ -1,5 +1,5 @@ ; RUN: opt < %s -instsimplify -S | FileCheck %s -target datalayout = "p:32:32" +target datalayout = "p:32:32-p1:64:64" define i1 @ptrtoint() { ; CHECK-LABEL: @ptrtoint( @@ -1358,4 +1358,13 @@ define i1 @constant_fold_null_inttoptr() { ret i1 %x } +; CHECK-LABEL: @cmp_through_addrspacecast( +; CHECK-NEXT: ret i1 true +define i1 @cmp_through_addrspacecast(i32 addrspace(1)* %p1) { + %p0 = addrspacecast i32 addrspace(1)* %p1 to i32* + %p0.1 = getelementptr inbounds i32, i32* %p0, i64 1 + %cmp = icmp ne i32* %p0, %p0.1 + ret i1 %cmp +} + attributes #0 = { "null-pointer-is-valid"="true" } |

