[llvm] r366162 - [InstructionSimplify] Apply sext/trunc after pointer stripping
Michael Liao via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 15 18:03:06 PDT 2019
Author: hliao
Date: Mon Jul 15 18:03:06 2019
New Revision: 366162
URL: http://llvm.org/viewvc/llvm-project?rev=366162&view=rev
Log:
[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
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/test/Transforms/InstSimplify/compare.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=366162&r1=366161&r2=366162&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Mon Jul 15 18:03:06 2019
@@ -660,6 +660,10 @@ static Constant *stripAndComputeConstant
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())
Modified: llvm/trunk/test/Transforms/InstSimplify/compare.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/compare.ll?rev=366162&r1=366161&r2=366162&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/compare.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/compare.ll Mon Jul 15 18:03:06 2019
@@ -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" }
More information about the llvm-commits
mailing list