[llvm] r366036 - [ValueTracking] Look through constant Int2Ptr/Ptr2Int expressions
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 14 20:24:36 PDT 2019
Author: jdoerfert
Date: Sun Jul 14 20:24:35 2019
New Revision: 366036
URL: http://llvm.org/viewvc/llvm-project?rev=366036&view=rev
Log:
[ValueTracking] Look through constant Int2Ptr/Ptr2Int expressions
Summary:
This is analogous to the int2ptr/ptr2int instruction handling introduced
in D54956.
Reviewers: fhahn, efriedma, spatel, nlopes, sanjoy, lebedev.ri
Subscribers: hiraditya, bollu, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64708
Modified:
llvm/trunk/lib/Analysis/ValueTracking.cpp
llvm/trunk/test/Transforms/FunctionAttrs/nonnull.ll
Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=366036&r1=366035&r2=366036&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Sun Jul 14 20:24:35 2019
@@ -1998,6 +1998,15 @@ bool isKnownNonZero(const Value *V, unsi
// Must be non-zero due to null test above.
return true;
+ if (auto *CE = dyn_cast<ConstantExpr>(C)) {
+ // See the comment for IntToPtr/PtrToInt instructions below.
+ if (CE->getOpcode() == Instruction::IntToPtr ||
+ CE->getOpcode() == Instruction::PtrToInt)
+ if (Q.DL.getTypeSizeInBits(CE->getOperand(0)->getType()) <=
+ Q.DL.getTypeSizeInBits(CE->getType()))
+ return isKnownNonZero(CE->getOperand(0), Depth, Q);
+ }
+
// For constant vectors, check that all elements are undefined or known
// non-zero to determine that the whole vector is known non-zero.
if (auto *VecTy = dyn_cast<VectorType>(C->getType())) {
Modified: llvm/trunk/test/Transforms/FunctionAttrs/nonnull.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionAttrs/nonnull.ll?rev=366036&r1=366035&r2=366036&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/FunctionAttrs/nonnull.ll (original)
+++ llvm/trunk/test/Transforms/FunctionAttrs/nonnull.ll Sun Jul 14 20:24:35 2019
@@ -237,4 +237,14 @@ define i32 addrspace(3)* @gep2(i32 addrs
ret i32 addrspace(3)* %q
}
+; CHECK: define internal nonnull i32* @f2()
+define internal i32* @f2() {
+ ret i32* inttoptr (i64 4 to i32*)
+}
+
+define i32* @f1() {
+ %c = call i32* @f2()
+ ret i32* %c
+}
+
attributes #0 = { "null-pointer-is-valid"="true" }
More information about the llvm-commits
mailing list