[llvm] cf30aaf - [Analysis] recognize the 'null' pointer constant as not poison
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 21 11:24:01 PDT 2020
Author: Sanjay Patel
Date: 2020-04-21T14:23:06-04:00
New Revision: cf30aafa2d1ed79daabe979fedf9c34affb8b2a0
URL: https://github.com/llvm/llvm-project/commit/cf30aafa2d1ed79daabe979fedf9c34affb8b2a0
DIFF: https://github.com/llvm/llvm-project/commit/cf30aafa2d1ed79daabe979fedf9c34affb8b2a0.diff
LOG: [Analysis] recognize the 'null' pointer constant as not poison
Differential Revision: https://reviews.llvm.org/D78575
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Transforms/InstSimplify/freeze.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index f80ec73f789e..e547447cbf08 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 e8950a8ad527..31fbdabf163b 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
More information about the llvm-commits
mailing list