[llvm] [VPlan] Dispatch to multiple exit blocks via middle blocks. (PR #112138)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 24 04:06:46 PDT 2024
================
@@ -1696,3 +1702,79 @@ void VPlanTransforms::createInterleaveGroups(
}
}
}
+
+void VPlanTransforms::convertToMultiCond(VPlan &Plan, ScalarEvolution &SE,
+ Loop *OrigLoop,
+ VPRecipeBuilder &RecipeBuilder) {
+ auto *LatchVPBB =
+ cast<VPBasicBlock>(Plan.getVectorLoopRegion()->getExiting());
+ VPBuilder Builder(LatchVPBB->getTerminator());
+ auto *MiddleVPBB =
+ cast<VPBasicBlock>(Plan.getVectorLoopRegion()->getSingleSuccessor());
+
+ VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
+
+ const SCEV *BackedgeTakenCount =
+ SE.getExitCount(OrigLoop, OrigLoop->getLoopLatch());
+ const SCEV *TripCount = SE.getTripCountFromExitCount(
+ BackedgeTakenCount, Plan.getCanonicalIV()->getScalarType(), OrigLoop);
+ VPValue *NewTC = vputils::getOrCreateVPValueForSCEVExpr(Plan, TripCount, SE);
+ Plan.getTripCount()->replaceAllUsesWith(NewTC);
+ Plan.resetTripCount(NewTC);
+
+ VPValue *EarlyExitTaken = nullptr;
+ SmallVector<BasicBlock *> ExitingBBs;
+ OrigLoop->getExitingBlocks(ExitingBBs);
+ for (BasicBlock *Exiting : ExitingBBs) {
+ auto *ExitingTerm = cast<BranchInst>(Exiting->getTerminator());
+ BasicBlock *TrueSucc = ExitingTerm->getSuccessor(0);
+ BasicBlock *FalseSucc = ExitingTerm->getSuccessor(1);
+ VPIRBasicBlock *VPExitBlock;
+ if (OrigLoop->getUniqueExitBlock())
----------------
david-arm wrote:
Hmm, I think I understand what you're trying to do with this a bit more now. Essentially, this patch is trying to take an existing supported vectorisation case (early countable exits) and apply a new vectorisation style. This permits you to test the new code you're adding without having to worry about the legality of vectorising loops with uncountable exits. I guess it's just the new flag I'm worried about since it conflicts with my existing PR #88385. It's almost like you want a flag to control the flavour of vectorisation for an already support case, i.e. something like `-prefer-multi-exit`.
https://github.com/llvm/llvm-project/pull/112138
More information about the llvm-commits
mailing list