[llvm] [LV] Transform to handle exits in the scalar loop (PR #148626)

Gaƫtan Bossu via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 28 08:36:04 PST 2025


================
@@ -8216,6 +8221,15 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
       if (CM.foldTailWithEVL())
         VPlanTransforms::runPass(VPlanTransforms::addExplicitVectorLength,
                                  *Plan, CM.getMaxSafeElements());
+
+      // See if we can convert an early exit vplan to bail out to a scalar
+      // loop if state-changing operations (like stores) are present and
+      // an exit will be taken in the next vector iteration.
+      // If not, discard the plan.
+      if (!Plan->hasScalarVFOnly() && HandleEarlyExitsInScalarTail &&
+          !VPlanTransforms::runPass(
+              VPlanTransforms::handleUncountableExitsInScalarLoop, *Plan))
----------------
gbossu wrote:

>Generally speaking, as soon as we encounter an instruction in the scalar loop where we would do something different between a scalar loop and a vector loop, we clamp the VF range and produce separate plans

I think here we should also do something different between scalar VF and vector ones because the transformation only really makes sense for VF>1 (as IC>1 is forbidden later).

AFAIU, currently we can run the transformation on a VPlan which contains `VF=1` as well as vector VFs.  Could the range be clamped to ensure the transform only runs for a plan with `VF>1`?



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


More information about the llvm-commits mailing list