[llvm] [SCEV] Support scaled vscale as step in howFarToZero (PR #94411)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 5 07:30:15 PDT 2024


================
@@ -10483,29 +10494,32 @@ ScalarEvolution::ExitLimit ScalarEvolution::howFarToZero(const SCEV *V,
   // Get the initial value for the loop.
   const SCEV *Start = getSCEVAtScope(AddRec->getStart(), L->getParentLoop());
   const SCEV *Step = getSCEVAtScope(AddRec->getOperand(1), L->getParentLoop());
-
-  // For now we handle only constant steps.
-  //
-  // TODO: Handle a nonconstant Step given AddRec<NUW>. If the
-  // AddRec is NUW, then (in an unsigned sense) it cannot be counting up to wrap
-  // to 0, it must be counting down to equal 0. Consequently, N = Start / -Step.
-  // We have not yet seen any such cases.
   const SCEVConstant *StepC = dyn_cast<SCEVConstant>(Step);
-  if (!StepC || StepC->getValue()->isZero())
+  // The code below is correct for arbitrary non-constant steps, but we won't be
+  // able to prove useful properties given the lack of use dependenct reasoning
+  // here.  To avoid spending compile time for no value, bail early unless the
+  // step is a "useful" non-constant value.
+  if (!StepC && !matchScaledVScale(Step))
+    return getCouldNotCompute();
----------------
preames wrote:

Done.

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


More information about the llvm-commits mailing list