[llvm] [ValueTracking] Handle recursive select/PHI in ComputeKnownBits (PR #114689)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 26 12:45:49 PST 2025
================
@@ -1641,25 +1671,19 @@ static void computeKnownBitsFromOperator(const Operator *I,
Known.Zero.setAllBits();
Known.One.setAllBits();
- for (unsigned u = 0, e = P->getNumIncomingValues(); u < e; ++u) {
- Value *IncValue = P->getIncomingValue(u);
+ for (const Use &U : P->operands()) {
+ Value *IncValue;
+ Instruction *CxtI;
+ breakSelfRecursivePHI(&U, P, IncValue, CxtI);
// Skip direct self references.
- if (IncValue == P) continue;
-
- // If the Use is a select of this phi, use the knownbit of the other
- // operand to break the recursion.
- if (auto *SI = dyn_cast<SelectInst>(IncValue)) {
- if (SI->getTrueValue() == P || SI->getFalseValue() == P)
- IncValue = SI->getTrueValue() == P ? SI->getFalseValue()
- : SI->getTrueValue();
- }
+ if (IncValue == P)
+ continue;
// Change the context instruction to the "edge" that flows into the
// phi. This is important because that is where the value is actually
// "evaluated" even though it is used later somewhere else. (see also
// D69571).
- SimplifyQuery RecQ = Q.getWithoutCondContext();
- RecQ.CxtI = P->getIncomingBlock(u)->getTerminator();
+ SimplifyQuery RecQ = Q.getWithoutCondContext().getWithInstruction(CxtI);
----------------
goldsteinn wrote:
see: https://github.com/llvm/llvm-project/pull/124481
https://github.com/llvm/llvm-project/pull/114689
More information about the llvm-commits
mailing list