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

Graham Hunter via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 18 04:02:57 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))
----------------
huntergr-arm wrote:

I'm following convention here, as this is used in various functions in VPlanTransforms.cpp to bail out.

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. This means a VF of 1 ends up with its own plan, possibly with interleaving.

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


More information about the llvm-commits mailing list