[llvm] [VPlan] Handle early exit before forming regions. (NFC) (PR #138393)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 8 05:31:35 PDT 2025
================
@@ -491,12 +484,37 @@ void VPlanTransforms::prepareForVectorization(VPlan &Plan, Type *InductionTy,
VPBlockUtils::insertBlockAfter(VecPreheader, Plan.getEntry());
VPBasicBlock *MiddleVPBB = Plan.createVPBasicBlock("middle.block");
- VPBlockUtils::connectBlocks(LatchVPB, MiddleVPBB);
- LatchVPB->swapSuccessors();
+ // Canonical LatchVPB has header block as last successor. If it has another
+ // successor, the latter is an exit block - insert middle block on its edge.
+ // Otherwise, add middle block as another successor retaining header as last.
+ if (LatchVPB->getNumSuccessors() == 2) {
+ VPBlockBase *LatchExitVPB = LatchVPB->getSuccessors()[0];
+ VPBlockUtils::insertOnEdge(LatchVPB, LatchExitVPB, MiddleVPBB);
+ } else {
+ VPBlockUtils::connectBlocks(LatchVPB, MiddleVPBB);
+ LatchVPB->swapSuccessors();
+ }
addCanonicalIVRecipes(Plan, cast<VPBasicBlock>(HeaderVPB),
cast<VPBasicBlock>(LatchVPB), InductionTy, IVDL);
+ if (HandleUncountableExit) {
+ // Convert VPlans with early exits to a form only exiting via the latch
+ // here, including adjusting the exit condition.
----------------
ayalz wrote:
```suggestion
// here, including adjusting the condition of the non-early exit.
```
https://github.com/llvm/llvm-project/pull/138393
More information about the llvm-commits
mailing list