[llvm] [ScalarEvolution] Limit recursion in getRangeRef for PHI nodes. (PR #152823)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 10 07:39:31 PDT 2025


================
@@ -6581,6 +6592,28 @@ getRangeForUnknownRecurrence(const SCEVUnknown *U) {
   return FullSet;
 }
 
+// The goal of this function is to check if recursively visiting the operands
+// of this PHI might lead to an infinite loop. If we do see such a loop,
+// there's no good way to break it, so we avoid analyzing such cases.
+//
+// getRangeRef previously used a visited set to avoid infinite loops, but this
+// caused other issues: the result was dependent on the order of getRangeRef
+// calls, and the interaction with createSCEVIter could cause a stack overflow
+// in some cases (see issue #148253).
+//
+// FIXME: The way this is implemented is overly conservative.
+static bool RangeRefPHIAllowedOperands(DominatorTree &DT, PHINode *PH) {
----------------
nikic wrote:

nit: PH -> PHI, Phi, P

https://github.com/llvm/llvm-project/pull/152823


More information about the llvm-commits mailing list