[llvm] [LV]: Improve accuracy of calculating remaining iterations of MainLoopVF (PR #156723)

Hassnaa Hamdi via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 20 08:58:20 PDT 2025


================
@@ -4372,8 +4372,21 @@ VectorizationFactor LoopVectorizationPlanner::selectEpilogueVectorizationFactor(
   const SCEV *TC =
       vputils::getSCEVExprForVPValue(getPlanFor(MainLoopVF).getTripCount(), SE);
   assert(!isa<SCEVCouldNotCompute>(TC) && "Trip count SCEV must be computable");
-  RemainingIterations =
-      SE.getURemExpr(TC, SE.getElementCount(TCType, MainLoopVF * IC));
+  const SCEV *KnownMinTC;
+  bool ScalableTC = match(TC, m_scev_Mul(m_SCEV(KnownMinTC), m_SCEVVScale())) ||
+                    match(TC, m_scev_Mul(m_SCEVVScale(), m_SCEV(KnownMinTC)));
+  // Use versions of TC and VF in which both are either scalable or fixed.
+  if (ScalableTC == MainLoopVF.isScalable())
+    RemainingIterations =
+        SE.getURemExpr(TC, SE.getElementCount(TCType, MainLoopVF * IC));
+  else if (ScalableTC) {
+    const SCEV *EstimatedTC = SE.getMulExpr(
+        KnownMinTC, SE.getConstant(TCType, CM.getVScaleForTuning().value()));
----------------
hassnaaHamdi wrote:

Given that TC is already scalable, isn't that an evidence for the availability of CM.getVScaleForTuning() ?

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


More information about the llvm-commits mailing list