[PATCH] D78575: [Analysis] recognize the 'null' pointer constant as not poison
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 21 10:47:59 PDT 2020
spatel created this revision.
spatel added reviewers: aqjune, lebedev.ri, nikic.
Herald added subscribers: hiraditya, mcrosier.
Just making sure that I'm not missing some corner-case for pointers here...
This is needed to create a safe-constant-substitution alternate to D78430 <https://reviews.llvm.org/D78430>.
https://reviews.llvm.org/D78575
Files:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Transforms/InstSimplify/freeze.ll
Index: llvm/test/Transforms/InstSimplify/freeze.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/freeze.ll
+++ llvm/test/Transforms/InstSimplify/freeze.ll
@@ -51,12 +51,9 @@
ret i32()* %k
}
-; TODO: This is not poison.
-
define i32* @make_const_null() {
; CHECK-LABEL: @make_const_null(
-; CHECK-NEXT: [[K:%.*]] = freeze i32* null
-; CHECK-NEXT: ret i32* [[K]]
+; CHECK-NEXT: ret i32* null
;
%k = freeze i32* null
ret i32* %k
@@ -208,8 +205,7 @@
define i32* @gep_inbounds_null() {
; CHECK-LABEL: @gep_inbounds_null(
-; CHECK-NEXT: [[K:%.*]] = freeze i32* null
-; CHECK-NEXT: ret i32* [[K]]
+; CHECK-NEXT: ret i32* null
;
%p = getelementptr inbounds i32, i32* null, i32 0
%k = freeze i32* %p
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -4693,8 +4693,9 @@
if (isa<UndefValue>(C) || isa<ConstantExpr>(C))
return false;
- // TODO: Add ConstantFP and pointers.
- if (isa<ConstantInt>(C) || isa<GlobalVariable>(C) )
+ // TODO: Add ConstantFP.
+ if (isa<ConstantInt>(C) || isa<GlobalVariable>(C) ||
+ isa<ConstantPointerNull>(C))
return true;
if (C->getType()->isVectorTy())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78575.259047.patch
Type: text/x-patch
Size: 1369 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200421/191027e8/attachment.bin>
More information about the llvm-commits
mailing list