aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2020-04-21 14:22:13 -0400
committerSanjay Patel <spatel@rotateright.com>2020-04-21 14:23:06 -0400
commitcf30aafa2d1ed79daabe979fedf9c34affb8b2a0 (patch)
tree189f2a8843bbd81d7e48380c5344ab9cdacee4e7
parentb349098d2297f8637525ed162bf37506ed70d7c7 (diff)
downloadllvm-cf30aafa2d1ed79daabe979fedf9c34affb8b2a0.zip
llvm-cf30aafa2d1ed79daabe979fedf9c34affb8b2a0.tar.gz
llvm-cf30aafa2d1ed79daabe979fedf9c34affb8b2a0.tar.bz2
[Analysis] recognize the 'null' pointer constant as not poison
Differential Revision: https://reviews.llvm.org/D78575
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp5
-rw-r--r--llvm/test/Transforms/InstSimplify/freeze.ll8
2 files changed, 5 insertions, 8 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index f80ec73..e547447 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4693,8 +4693,9 @@ bool llvm::isGuaranteedNotToBeUndefOrPoison(const Value *V,
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())
diff --git a/llvm/test/Transforms/InstSimplify/freeze.ll b/llvm/test/Transforms/InstSimplify/freeze.ll
index e8950a8..31fbdabf 100644
--- a/llvm/test/Transforms/InstSimplify/freeze.ll
+++ b/llvm/test/Transforms/InstSimplify/freeze.ll
@@ -51,12 +51,9 @@ define i32()* @make_const_fn() {
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 i8* @gep_inbounds_noopt(i32 %arg) {
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