diff options
author | David Green <david.green@arm.com> | 2024-11-01 13:38:29 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-01 13:38:29 +0000 |
commit | 0f919444adfa74b46df50aa2da12e7137c23a02c (patch) | |
tree | c6c46a508b288771b486569c5858f6530641d5ea /llvm/lib/Analysis/ValueTracking.cpp | |
parent | 340cb3951e53bc90706b39c16cd5ec59ca963324 (diff) | |
download | llvm-0f919444adfa74b46df50aa2da12e7137c23a02c.zip llvm-0f919444adfa74b46df50aa2da12e7137c23a02c.tar.gz llvm-0f919444adfa74b46df50aa2da12e7137c23a02c.tar.bz2 |
[ValueTracking] Handle recursive phis in knownFPClass (#114008)
As a follow-on to 113686, this breaks the recursion between phi nodes
that have p1 = phi(x, p2) and p2 = phi(y, p1). The knownFPClass can be
calculated from the classes of p1 and p2.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 6bcc844..dfa3ecd 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -6003,12 +6003,24 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts, if (IncValue == P) continue; + Instruction *CxtI = P->getIncomingBlock(U)->getTerminator(); + // If the Use is a select of this phi, use the fp class of the other - // operand to break the recursion. + // operand to break the recursion. Same around 2-operand phi nodes Value *V; if (match(IncValue, m_Select(m_Value(), m_Specific(P), m_Value(V))) || - match(IncValue, m_Select(m_Value(), m_Value(V), m_Specific(P)))) + match(IncValue, m_Select(m_Value(), m_Value(V), m_Specific(P)))) { IncValue = V; + } else if (auto *IncPhi = dyn_cast<PHINode>(IncValue); + IncPhi && IncPhi->getNumIncomingValues() == 2) { + for (int Idx = 0; Idx < 2; ++Idx) { + if (IncPhi->getIncomingValue(Idx) == P) { + IncValue = IncPhi->getIncomingValue(1 - Idx); + CxtI = IncPhi->getIncomingBlock(1 - Idx)->getTerminator(); + break; + } + } + } KnownFPClass KnownSrc; // Recurse, but cap the recursion to two levels, because we don't want @@ -6016,8 +6028,7 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts, // detect known sign bits. computeKnownFPClass(IncValue, DemandedElts, InterestedClasses, KnownSrc, PhiRecursionLimit, - Q.getWithoutCondContext().getWithInstruction( - P->getIncomingBlock(U)->getTerminator())); + Q.getWithoutCondContext().getWithInstruction(CxtI)); if (First) { Known = KnownSrc; |