[llvm] [VPlan] Add transform to fold early-exit branches into loops (PR #148404)

Graham Hunter via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 14 06:57:04 PDT 2025


================
@@ -7242,6 +7246,10 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
   // Regions are dissolved after optimizing for VF and UF, which completely
   // removes unneeded loop regions first.
   VPlanTransforms::dissolveLoopRegions(BestVPlan);
+
+  if (FoldEarlyExitBranchIntoLoop)
----------------
huntergr-arm wrote:

This would only work nicely for state-changing early exit loops (such as those with stores) if all such operations take place before the exits; we need to make sure stores from active lanes execute when the early exit is before the store in the original loop. This is much easier to do if there's a single unified exit. Same goes for any reductions after the exit I think.

I see you're splitting just before the combined condition (the or), and that's normally after all the other recipes, but I think you'd need a check for that before performing that transform.

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


More information about the llvm-commits mailing list