[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:30 PDT 2025


================
@@ -6963,8 +6992,13 @@ const ConstantRange &ScalarEvolution::getRangeRef(
 
     // A range of Phi is a subset of union of all ranges of its input.
     if (PHINode *Phi = dyn_cast<PHINode>(V)) {
+      // SCEVExpander sometimes creates SCEVUnknowns that are secretly
+      // AddRecs; return the range for the corresponding AddRec.
+      if (auto *AR = dyn_cast<SCEVAddRecExpr>(getSCEV(V)))
+        return getRangeRef(AR, SignHint, Depth + 1);
+
       // Make sure that we do not run over cycled Phis.
-      if (PendingPhiRanges.insert(Phi).second) {
+      if (RangeRefPHIAllowedOperands(DT, Phi)) {
----------------
nikic wrote:

We could fall back to ValueTracking here to get at least some information. Not sure if that would be practically useful or not.

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


More information about the llvm-commits mailing list