[llvm] 1c69444 - [SCEV] `createNodeForSelectOrPHI()`: try constant-folding even if not an Instruction

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 10 06:47:06 PST 2022


Author: Roman Lebedev
Date: 2022-02-10T17:42:55+03:00
New Revision: 1c69444863f3d8170cd9931c19283fe44d85a2e7

URL: https://github.com/llvm/llvm-project/commit/1c69444863f3d8170cd9931c19283fe44d85a2e7
DIFF: https://github.com/llvm/llvm-project/commit/1c69444863f3d8170cd9931c19283fe44d85a2e7.diff

LOG: [SCEV] `createNodeForSelectOrPHI()`: try constant-folding even if not an Instruction

We'd catch the tautological select pattern later anyways
due to constant folding, so that leaves PHI-like select,
but it does not appear to fire there.

Added: 
    

Modified: 
    llvm/lib/Analysis/ScalarEvolution.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 53c1bc6ebf0f..358ec952ab24 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -5989,19 +5989,19 @@ const SCEV *ScalarEvolution::createNodeForSelectOrPHIInstWithICmpInstCond(
 const SCEV *ScalarEvolution::createNodeForSelectOrPHI(Value *V, Value *Cond,
                                                       Value *TrueVal,
                                                       Value *FalseVal) {
-  auto *I = dyn_cast<Instruction>(V);
-  if (!I)
-    return getUnknown(V);
-
   // Handle "constant" branch or select. This can occur for instance when a
   // loop pass transforms an inner loop and moves on to process the outer loop.
   if (auto *CI = dyn_cast<ConstantInt>(Cond))
     return getSCEV(CI->isOne() ? TrueVal : FalseVal);
 
-  // Try to match some simple smax or umax patterns.
-  if (auto *ICI = dyn_cast<ICmpInst>(Cond))
-    return createNodeForSelectOrPHIInstWithICmpInstCond(I, ICI, TrueVal,
-                                                        FalseVal);
+  if (auto *I = dyn_cast<Instruction>(V)) {
+    if (auto *ICI = dyn_cast<ICmpInst>(Cond)) {
+      const SCEV *S = createNodeForSelectOrPHIInstWithICmpInstCond(
+          I, ICI, TrueVal, FalseVal);
+      if (!isa<SCEVUnknown>(S))
+        return S;
+    }
+  }
 
   return getUnknown(V);
 }


        


More information about the llvm-commits mailing list