[llvm] [LV] Use SCEV to check if minimum iteration check is known. (PR #111310)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 10 04:58:10 PDT 2024


================
@@ -2440,12 +2440,20 @@ void InnerLoopVectorizer::emitIterationCountCheck(BasicBlock *Bypass) {
   };
 
   TailFoldingStyle Style = Cost->getTailFoldingStyle();
-  if (Style == TailFoldingStyle::None)
-    CheckMinIters =
-        Builder.CreateICmp(P, Count, CreateStep(), "min.iters.check");
-  else if (VF.isScalable() &&
-           !isIndvarOverflowCheckKnownFalse(Cost, VF, UF) &&
-           Style != TailFoldingStyle::DataAndControlFlowWithoutRuntimeCheck) {
+  if (Style == TailFoldingStyle::None) {
+    Value *Step = CreateStep();
+    ScalarEvolution &SE = *PSE.getSE();
+    // Check if we can prove that the trip count is >= the step.
+    const SCEV *TripCountSCEV = SE.getSCEV(Count);
+    if (SE.isKnownPredicate(CmpInst::getInversePredicate(P),
----------------
fhahn wrote:

There is one case where this improves, in case where we version the stride in LoopAccessAnalysis. Those predicates won't be used when retrieving the max trip count from SCEV, but triggers here.

Test case is in `llvm/test/Transforms/LoopVectorize/version-stride-with-integer-casts.ll`

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


More information about the llvm-commits mailing list