[llvm] [ValueTracking] Don't special case depth for phi of select (PR #114996)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 5 06:22:05 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Nikita Popov (nikic)
<details>
<summary>Changes</summary>
As discussed on https://github.com/llvm/llvm-project/pull/114689#pullrequestreview-2411822612 and following, there is no principled reason why the phi of select case should have a different recursion limit than the general case. There may still be fan-out, and there may still be indirect recursion. Revert that part of #<!-- -->113707.
---
Full diff: https://github.com/llvm/llvm-project/pull/114996.diff
1 Files Affected:
- (modified) llvm/lib/Analysis/ValueTracking.cpp (+8-10)
``````````diff
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 5c20c24d0ae00a..7d8e0d65dbfebb 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<SelectInst>(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.
``````````
</details>
https://github.com/llvm/llvm-project/pull/114996
More information about the llvm-commits
mailing list