[llvm] [VPlan] Build initial VPlan 0 using HCFGBuilder for inner loops. (NFC) (PR #124432)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 8 13:05:06 PST 2025
================
@@ -9329,23 +9330,58 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
RecipeBuilder.collectScaledReductions(Range);
auto *MiddleVPBB = Plan->getMiddleBlock();
+
+ // Scan the body of the loop in a topological order to visit each basic block
+ // after having visited its predecessor basic blocks.
+ ReversePostOrderTraversal<VPBlockShallowTraversalWrapper<VPBlockBase *>> RPOT(
+ HeaderVPBB);
+
VPBasicBlock::iterator MBIP = MiddleVPBB->getFirstNonPhi();
- for (BasicBlock *BB : make_range(DFS.beginRPO(), DFS.endRPO())) {
- // Relevant instructions from basic block BB will be grouped into VPRecipe
- // ingredients and fill a new VPBasicBlock.
- if (VPBB != HeaderVPBB)
- VPBB->setName(BB->getName());
- Builder.setInsertPoint(VPBB);
+ VPBlockBase *PrevVPBB = nullptr;
+ for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT)) {
+ // Skip VPBBs not corresponding to any input IR basic blocks.
+ if (!HCFGBuilder.getIRBBForVPB(VPBB)) {
+ assert(VPBB == LoopRegion->getExiting() &&
+ "only the latch block shouldn't have a corresponding IRBB");
+ VPBlockUtils::connectBlocks(PrevVPBB, VPBB);
+ break;
+ }
- if (VPBB == HeaderVPBB)
+ // Create mask based on the IR BB corresponding to VPBB.
+ // TODO: Predicate directly based on VPlan.
+ Builder.setInsertPoint(VPBB, VPBB->begin());
----------------
fhahn wrote:
We need to insert at the begining here, as the blocks other than the header may contain VPWidenPhis that need to be converted to VPBlend, and the mask needs to be inserted at the beginning of the block for those blends.
https://github.com/llvm/llvm-project/pull/124432
More information about the llvm-commits
mailing list