Skip to content

Commit abbef2f

Browse files
committed
[ValueTracking] isGuaranteedNotToBePoison should return true on undef
This is a one-line fix to isGuaranteedNotToBePoison to return true if undef is given.
1 parent 8e293fe commit abbef2f

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4888,7 +4888,7 @@ static bool isGuaranteedNotToBeUndefOrPoison(const Value *V,
48884888

48894889
if (auto *C = dyn_cast<Constant>(V)) {
48904890
if (isa<UndefValue>(C))
4891-
return PoisonOnly;
4891+
return PoisonOnly && !isa<PoisonValue>(C);
48924892

48934893
if (isa<ConstantInt>(C) || isa<GlobalVariable>(C) || isa<ConstantFP>(V) ||
48944894
isa<ConstantPointerNull>(C) || isa<Function>(C))

llvm/unittests/Analysis/ValueTrackingTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,10 @@ TEST_F(ValueTrackingTest, isGuaranteedNotToBeUndefOrPoison) {
884884
" ret void\n"
885885
"}\n");
886886
EXPECT_EQ(isGuaranteedNotToBeUndefOrPoison(A), true);
887+
EXPECT_EQ(isGuaranteedNotToBeUndefOrPoison(UndefValue::get(IntegerType::get(Context, 8))), false);
888+
EXPECT_EQ(isGuaranteedNotToBeUndefOrPoison(PoisonValue::get(IntegerType::get(Context, 8))), false);
889+
EXPECT_EQ(isGuaranteedNotToBePoison(UndefValue::get(IntegerType::get(Context, 8))), true);
890+
EXPECT_EQ(isGuaranteedNotToBePoison(PoisonValue::get(IntegerType::get(Context, 8))), false);
887891
}
888892

889893
TEST_F(ValueTrackingTest, isGuaranteedNotToBeUndefOrPoison_assume) {

0 commit comments

Comments
 (0)