llvm.org GIT mirror llvm / dfcb352
[InstructionSimplify] Apply sext/trunc after pointer stripping Summary: - As the pointer stripping could trace through `addrspacecast` now, need to sext/trunc the offset to ensure it has the same width as the pointer after stripping. Reviewers: jdoerfert Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64768 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366162 91177308-0d34-0410-b5e6-96231b3b80d8 Michael Liao a month ago
2 changed file(s) with 14 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
659659 APInt Offset = APInt::getNullValue(IntPtrTy->getIntegerBitWidth());
660660
661661 V = V->stripAndAccumulateConstantOffsets(DL, Offset, AllowNonInbounds);
662 // As that strip may trace through `addrspacecast`, need to sext or trunc
663 // the offset calculated.
664 IntPtrTy = DL.getIntPtrType(V->getType())->getScalarType();
665 Offset = Offset.sextOrTrunc(IntPtrTy->getIntegerBitWidth());
662666
663667 Constant *OffsetIntPtr = ConstantInt::get(IntPtrTy, Offset);
664668 if (V->getType()->isVectorTy())
0 ; RUN: opt < %s -instsimplify -S | FileCheck %s
1 target datalayout = "p:32:32"
1 target datalayout = "p:32:32-p1:64:64"
22
33 define i1 @ptrtoint() {
44 ; CHECK-LABEL: @ptrtoint(
13571357 ret i1 %x
13581358 }
13591359
1360 ; CHECK-LABEL: @cmp_through_addrspacecast(
1361 ; CHECK-NEXT: ret i1 true
1362 define i1 @cmp_through_addrspacecast(i32 addrspace(1)* %p1) {
1363 %p0 = addrspacecast i32 addrspace(1)* %p1 to i32*
1364 %p0.1 = getelementptr inbounds i32, i32* %p0, i64 1
1365 %cmp = icmp ne i32* %p0, %p0.1
1366 ret i1 %cmp
1367 }
1368
13601369 attributes #0 = { "null-pointer-is-valid"="true" }