diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 5c20c24d0ae00..7d8e0d65dbfeb 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -1566,20 +1566,12 @@ static void computeKnownBitsFromOperator(const Operator *I, // Skip direct self references. if (IncValue == P) continue; - // Recurse, but cap the recursion to one level, because we don't - // want to waste time spinning around in loops. - // TODO: See if we can base recursion limiter on number of incoming phi - // edges so we don't overly clamp analysis. - unsigned IncDepth = MaxAnalysisRecursionDepth - 1; - // 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(IncValue)) { - if (SI->getTrueValue() == P || SI->getFalseValue() == P) { + if (SI->getTrueValue() == P || SI->getFalseValue() == P) IncValue = SI->getTrueValue() == P ? SI->getFalseValue() : SI->getTrueValue(); - IncDepth = Depth + 1; - } } // Change the context instruction to the "edge" that flows into the @@ -1590,7 +1582,13 @@ static void computeKnownBitsFromOperator(const Operator *I, RecQ.CxtI = P->getIncomingBlock(u)->getTerminator(); Known2 = KnownBits(BitWidth); - computeKnownBits(IncValue, DemandedElts, Known2, IncDepth, RecQ); + + // Recurse, but cap the recursion to one level, because we don't + // want to waste time spinning around in loops. + // TODO: See if we can base recursion limiter on number of incoming phi + // edges so we don't overly clamp analysis. + computeKnownBits(IncValue, DemandedElts, Known2, + MaxAnalysisRecursionDepth - 1, RecQ); // See if we can further use a conditional branch into the phi // to help us determine the range of the value.