[PATCH] D64708: [ValueTracking] Look through constant Int2Ptr/Ptr2Int expressions

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 14 20:26:15 PDT 2019


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366036: [ValueTracking] Look through constant Int2Ptr/Ptr2Int expressions (authored by jdoerfert, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D64708?vs=209736&id=209755#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64708/new/

https://reviews.llvm.org/D64708

Files:
  llvm/trunk/lib/Analysis/ValueTracking.cpp
  llvm/trunk/test/Transforms/FunctionAttrs/nonnull.ll


Index: llvm/trunk/test/Transforms/FunctionAttrs/nonnull.ll
===================================================================
--- llvm/trunk/test/Transforms/FunctionAttrs/nonnull.ll
+++ llvm/trunk/test/Transforms/FunctionAttrs/nonnull.ll
@@ -237,4 +237,14 @@
   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" }
Index: llvm/trunk/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp
@@ -1998,6 +1998,15 @@
       // 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())) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64708.209755.patch
Type: text/x-patch
Size: 1459 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190715/5ec80a00/attachment.bin>


More information about the llvm-commits mailing list