[llvm] [VPlan] Handle early exit before forming regions. (NFC) (PR #138393)

via llvm-commits llvm-commits at lists.llvm.org
Fri May 9 11:22:53 PDT 2025


================
@@ -491,19 +490,38 @@ void VPlanTransforms::prepareForVectorization(VPlan &Plan, Type *InductionTy,
   addCanonicalIVRecipes(Plan, cast<VPBasicBlock>(HeaderVPB),
                         cast<VPBasicBlock>(LatchVPB), InductionTy, IVDL);
 
-  // Disconnect all edges to exit blocks other than from the middle block.
-  // TODO: VPlans with early exits should be explicitly converted to a form
-  // exiting only via the latch here, including adjusting the exit condition,
-  // instead of simply disconnecting the edges and adjusting the VPlan later.
-  for (VPBlockBase *EB : Plan.getExitBlocks()) {
+  [[maybe_unused]] bool HandledUncountableEarlyExit = false;
+  // Handle the remaining early exits, either by converting the plan to one only
+  // exiting via the latch or by disconnecting all early exiting edges and
+  // requiring a scalar epilogue.
----------------
ayalz wrote:

```suggestion
  // Disconnect all early exits from the loop leaving it with a single exit from the latch. Early exits that are countable are left for a scalar epilog. The condition of uncountable early exits (currently at most one is supported) is fused into the latch exit, and used to branch from middle block to the early exit destination.
```
?

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


More information about the llvm-commits mailing list