[llvm] 0cdf030 - [SCEV] `getRangeRefIter()`: don't forget to recurse into casts

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 22 12:28:22 PST 2023


Author: Roman Lebedev
Date: 2023-01-22T23:28:02+03:00
New Revision: 0cdf030cf8dcfb8bfe551c16b14a29e124497069

URL: https://github.com/llvm/llvm-project/commit/0cdf030cf8dcfb8bfe551c16b14a29e124497069
DIFF: https://github.com/llvm/llvm-project/commit/0cdf030cf8dcfb8bfe551c16b14a29e124497069.diff

LOG: [SCEV] `getRangeRefIter()`: don't forget to recurse into casts

I'm not really sure the problem can be nicely exposed via a lit test,
since we don't give up on range calculation for deeply nested ranges,
but if i add an assertion that those opcodes are never encountered,
the assertion fails in a number of existing tests.

In reality, the iterative approach is still pretty partial:
1. `Seen` should not be there. We want the last instance of expression, not the first one
2. There should be a check that `getRangeRefIter()` does not self-recurse

Added: 
    

Modified: 
    llvm/lib/Analysis/ScalarEvolution.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index ace8a5452096..97c80a711cbb 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -6542,17 +6542,15 @@ ScalarEvolution::getRangeRefIter(const SCEV *S,
     if (Cache.find(Expr) != Cache.end())
       return;
     switch (Expr->getSCEVType()) {
+    case scUnknown:
+      if (!isa<PHINode>(cast<SCEVUnknown>(Expr)->getValue()))
+        break;
+      [[fallthrough]];
     case scConstant:
     case scTruncate:
     case scZeroExtend:
     case scSignExtend:
     case scPtrToInt:
-      // FIXME: ???
-      break; // Don't bother recursing into these.
-    case scUnknown:
-      if (!isa<PHINode>(cast<SCEVUnknown>(Expr)->getValue()))
-        break;
-      [[fallthrough]];
     case scAddExpr:
     case scMulExpr:
     case scUDivExpr:


        


More information about the llvm-commits mailing list