aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Analysis/ValueTrackingTest.cpp
diff options
context:
space:
mode:
authorJuneyoung Lee <aqjune@gmail.com>2020-09-26 23:56:30 +0900
committerJuneyoung Lee <aqjune@gmail.com>2020-09-28 23:24:20 +0900
commitba8911d560ef85cae55fc45440afa3bef374f1e0 (patch)
treed36673869917662e6f6dfec1a39486e8842df303 /llvm/unittests/Analysis/ValueTrackingTest.cpp
parentc372809f5a9f32c90b468094c19ae8e3b39566ed (diff)
downloadllvm-ba8911d560ef85cae55fc45440afa3bef374f1e0.zip
llvm-ba8911d560ef85cae55fc45440afa3bef374f1e0.tar.gz
llvm-ba8911d560ef85cae55fc45440afa3bef374f1e0.tar.bz2
[ValueTracking] Fix analyses to update CxtI to be phi's incoming edges' terminators
It was mentioned that D88276 that when a phi node is visited, terminators at their incoming edges should be used for CtxI. This is a patch that makes two functions (ComputeNumSignBitsImpl, isGuaranteedNotToBeUndefOrPoison) to do so. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D88360
Diffstat (limited to 'llvm/unittests/Analysis/ValueTrackingTest.cpp')
-rw-r--r--llvm/unittests/Analysis/ValueTrackingTest.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index 2cfca2c..43600ce 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -768,6 +768,30 @@ TEST_F(ValueTrackingTest, isGuaranteedNotToBePoison_exploitBranchCond) {
}
}
+TEST_F(ValueTrackingTest, isGuaranteedNotToBePoison_phi) {
+ parseAssembly("declare i32 @any_i32(i32)"
+ "define void @test() {\n"
+ "ENTRY:\n"
+ " br label %LOOP\n"
+ "LOOP:\n"
+ " %A = phi i32 [0, %ENTRY], [%A.next, %NEXT]\n"
+ " %A.next = call i32 @any_i32(i32 %A)\n"
+ " %cond = icmp eq i32 %A.next, 0\n"
+ " br i1 %cond, label %NEXT, label %EXIT\n"
+ "NEXT:\n"
+ " br label %LOOP\n"
+ "EXIT:\n"
+ " ret void\n"
+ "}\n");
+ DominatorTree DT(*F);
+ for (auto &BB : *F) {
+ if (BB.getName() == "LOOP") {
+ EXPECT_EQ(isGuaranteedNotToBePoison(A, A, &DT), true)
+ << "isGuaranteedNotToBePoison does not hold";
+ }
+ }
+}
+
TEST_F(ValueTrackingTest, isGuaranteedNotToBeUndefOrPoison) {
parseAssembly("declare void @f(i32 noundef)"
"define void @test(i32 %x) {\n"