[llvm] [ValueTracking] Don't special case depth for phi of select (PR #114996)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 5 06:21:25 PST 2024
https://github.com/nikic created https://github.com/llvm/llvm-project/pull/114996
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.
>From 96f345d2e09bcff5ed0ba50e36bcd5806289fed1 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Tue, 5 Nov 2024 15:18:58 +0100
Subject: [PATCH] [ValueTracking] Don't special case depth for phi of select
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.
---
llvm/lib/Analysis/ValueTracking.cpp | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
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.
More information about the llvm-commits
mailing list