diff options
author | Juneyoung Lee <aqjune@gmail.com> | 2020-09-26 23:56:30 +0900 |
---|---|---|
committer | Juneyoung Lee <aqjune@gmail.com> | 2020-09-28 23:24:20 +0900 |
commit | ba8911d560ef85cae55fc45440afa3bef374f1e0 (patch) | |
tree | d36673869917662e6f6dfec1a39486e8842df303 /llvm/lib/Analysis/ValueTracking.cpp | |
parent | c372809f5a9f32c90b468094c19ae8e3b39566ed (diff) | |
download | llvm-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/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 2b8b1ef..28a430e 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -2967,11 +2967,13 @@ static unsigned ComputeNumSignBitsImpl(const Value *V, // 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); - for (unsigned i = 1, e = NumIncomingValues; i != e; ++i) { + Query RecQ = Q; + Tmp = TyBits; + for (unsigned i = 0, 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; } @@ -4939,7 +4941,20 @@ static bool isGuaranteedNotToBeUndefOrPoison(const Value *V, return true; } - if (!canCreateUndefOrPoison(Opr) && all_of(Opr->operands(), OpCheck)) + if (const 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; } |