[PATCH] D88360: [ValueTracking] Fix analyses to update CxtI to be phi's incoming edges' terminators
Juneyoung Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 26 08:13:05 PDT 2020
aqjune created this revision.
aqjune added reviewers: nikic, efriedma.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
aqjune requested review of this revision.
It was mentioned that D88276 <https://reviews.llvm.org/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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D88360
Files:
llvm/lib/Analysis/ValueTracking.cpp
llvm/unittests/Analysis/ValueTrackingTest.cpp
Index: llvm/unittests/Analysis/ValueTrackingTest.cpp
===================================================================
--- llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -768,6 +768,29 @@
}
}
+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, %LOOP]\n"
+ " %A.next = call i32 @any_i32(i32 %A)\n"
+ " udiv i32 1, %A.next\n"
+ " %cond = icmp eq i32 %A.next, 0\n"
+ " br i1 %cond, label %LOOP, label %EXIT\n"
+ "EXIT:\n"
+ " ret void\n"
+ "}\n");
+ for (auto &BB : *F) {
+ if (BB.getName() == "LOOP") {
+ auto *TI = BB.getTerminator();
+ EXPECT_EQ(isGuaranteedNotToBePoison(A), true)
+ << "isGuaranteedNotToBePoison does not hold at " << *TI;
+ }
+ }
+}
+
TEST_F(ValueTrackingTest, isGuaranteedNotToBeUndefOrPoison) {
parseAssembly("declare void @f(i32 noundef)"
"define void @test(i32 %x) {\n"
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -2967,11 +2967,14 @@
// Take the minimum of all incoming values. This can't infinitely loop
// because of our depth threshold.
- Tmp = ComputeNumSignBits(PN->getIncomingValue(0), Depth + 1, Q);
+ Query RecQ = Q;
+ RecQ.CxtI = PN->getIncomingBlock(0)->getTerminator();
+ Tmp = ComputeNumSignBits(PN->getIncomingValue(0), Depth + 1, RecQ);
for (unsigned i = 1, e = NumIncomingValues; i != e; ++i) {
if (Tmp == 1) return Tmp;
+ RecQ.CxtI = PN->getIncomingBlock(i)->getTerminator();
Tmp = std::min(
- Tmp, ComputeNumSignBits(PN->getIncomingValue(i), Depth + 1, Q));
+ Tmp, ComputeNumSignBits(PN->getIncomingValue(i), Depth + 1, RecQ));
}
return Tmp;
}
@@ -4930,7 +4933,20 @@
return true;
}
- if (!canCreateUndefOrPoison(Opr) && all_of(Opr->operands(), OpCheck))
+ if (auto *PN = dyn_cast<PHINode>(V)) {
+ unsigned Num = PN->getNumIncomingValues();
+ bool IsWellDefined = true;
+ for (unsigned i = 0; i < Num; ++i) {
+ auto *TI = PN->getIncomingBlock(i)->getTerminator();
+ if (!isGuaranteedNotToBeUndefOrPoison(PN->getIncomingValue(i), TI, DT,
+ Depth + 1, PoisonOnly)) {
+ IsWellDefined = false;
+ break;
+ }
+ }
+ if (IsWellDefined)
+ return true;
+ } else if (!canCreateUndefOrPoison(Opr) && all_of(Opr->operands(), OpCheck))
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88360.294505.patch
Type: text/x-patch
Size: 2953 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200926/6cd2d8c9/attachment.bin>
More information about the llvm-commits
mailing list