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

Gaƫtan Bossu via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 17 01:57:41 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:

Check me: I'm guessing the future-proof condition to check is something like `VF > 1 || IC > 1`. But currently, we don't allow interleaving for EE loops, so it is fine to check `VF` only. Still, should we actually check that `MinVF > 1`? AFAIU, the transform is not legal for `VF=1`.

~Is it worth adding an assert somewhere that `IC == 1`?~ IC is decided later, so there's not much we can check here.

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


More information about the llvm-commits mailing list