From abbef2fd46d48a0d92d86f0c00fa2973f8ae2c85 Mon Sep 17 00:00:00 2001 From: Juneyoung Lee Date: Tue, 5 Jan 2021 06:49:19 +0900 Subject: [PATCH] [ValueTracking] isGuaranteedNotToBePoison should return true on undef This is a one-line fix to isGuaranteedNotToBePoison to return true if undef is given. --- llvm/lib/Analysis/ValueTracking.cpp | 2 +- llvm/unittests/Analysis/ValueTrackingTest.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 303240d..e15d4f0 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -4888,7 +4888,7 @@ static bool isGuaranteedNotToBeUndefOrPoison(const Value *V, if (auto *C = dyn_cast(V)) { if (isa(C)) - return PoisonOnly; + return PoisonOnly && !isa(C); if (isa(C) || isa(C) || isa(V) || isa(C) || isa(C)) diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp index 009166a..0d65774 100644 --- a/llvm/unittests/Analysis/ValueTrackingTest.cpp +++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp @@ -884,6 +884,10 @@ TEST_F(ValueTrackingTest, isGuaranteedNotToBeUndefOrPoison) { " ret void\n" "}\n"); EXPECT_EQ(isGuaranteedNotToBeUndefOrPoison(A), true); + EXPECT_EQ(isGuaranteedNotToBeUndefOrPoison(UndefValue::get(IntegerType::get(Context, 8))), false); + EXPECT_EQ(isGuaranteedNotToBeUndefOrPoison(PoisonValue::get(IntegerType::get(Context, 8))), false); + EXPECT_EQ(isGuaranteedNotToBePoison(UndefValue::get(IntegerType::get(Context, 8))), true); + EXPECT_EQ(isGuaranteedNotToBePoison(PoisonValue::get(IntegerType::get(Context, 8))), false); } TEST_F(ValueTrackingTest, isGuaranteedNotToBeUndefOrPoison_assume) { -- 2.7.4