diff options
author | Florian Hahn <flo@fhahn.com> | 2025-04-26 22:03:18 +0100 |
---|---|---|
committer | Florian Hahn <flo@fhahn.com> | 2025-04-26 22:03:18 +0100 |
commit | 826f237cb4b44f6d95d66eea0e58f7d24585986b (patch) | |
tree | 63ea23edb2c2736517d3b9620046a5d1c156c257 /llvm/lib | |
parent | d403c70ff31830bf5311be11b51363ae98d06068 (diff) | |
download | llvm-826f237cb4b44f6d95d66eea0e58f7d24585986b.zip llvm-826f237cb4b44f6d95d66eea0e58f7d24585986b.tar.gz llvm-826f237cb4b44f6d95d66eea0e58f7d24585986b.tar.bz2 |
[VPlan] Don't added separate vector latch block (NFC).
Simplify initial VPlan construction by not creating a separate
vector.latch block, which isn't needed and will get folded away later.
This has been suggested as independent clean-up multiple times.
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 30 | ||||
-rw-r--r-- | llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp | 5 | ||||
-rw-r--r-- | llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp | 9 |
3 files changed, 20 insertions, 24 deletions
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 4beeabd..6b5b50a 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -9531,14 +9531,6 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) { VPBasicBlock::iterator MBIP = MiddleVPBB->getFirstNonPhi(); VPBlockBase *PrevVPBB = nullptr; for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT)) { - // Handle VPBBs down to the latch. - if (VPBB == LoopRegion->getExiting()) { - assert(!VPB2IRBB.contains(VPBB) && - "the latch block shouldn't have a corresponding IRBB"); - VPBlockUtils::connectBlocks(PrevVPBB, VPBB); - break; - } - // Create mask based on the IR BB corresponding to VPBB. // TODO: Predicate directly based on VPlan. Builder.setInsertPoint(VPBB, VPBB->begin()); @@ -9761,6 +9753,12 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlan(VFRange &Range) { for (ElementCount VF : Range) Plan->addVF(VF); + // Tail folding is not supported for outer loops, so the induction increment + // is guaranteed to not wrap. + bool HasNUW = true; + addCanonicalIVRecipes(*Plan, Legal->getWidestInductionType(), HasNUW, + DebugLoc()); + if (!VPlanTransforms::tryToConvertVPInstructionsToVPRecipes( Plan, [this](PHINode *P) { @@ -9769,12 +9767,6 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlan(VFRange &Range) { *PSE.getSE(), *TLI)) return nullptr; - // Tail folding is not supported for outer loops, so the induction increment - // is guaranteed to not wrap. - bool HasNUW = true; - addCanonicalIVRecipes(*Plan, Legal->getWidestInductionType(), HasNUW, - DebugLoc()); - // Collect mapping of IR header phis to header phi recipes, to be used in // addScalarResumePhis. VPRecipeBuilder RecipeBuilder(*Plan, OrigLoop, TLI, &TTI, Legal, CM, PSE, @@ -9939,14 +9931,18 @@ void LoopVectorizationPlanner::adjustRecipesForReductions( // ensure that it comes after all of it's inputs, including CondOp. // Delete CurrentLink as it will be invalid if its operand is replaced // with a reduction defined at the bottom of the block in the next link. - LinkVPBB->appendRecipe(RedRecipe); + if (LinkVPBB->getNumSuccessors() == 0) + RedRecipe->insertBefore(&*std::prev(std::prev(LinkVPBB->end()))); + else + LinkVPBB->appendRecipe(RedRecipe); + CurrentLink->replaceAllUsesWith(RedRecipe); ToDelete.push_back(CurrentLink); PreviousLink = RedRecipe; } } VPBasicBlock *LatchVPBB = VectorLoopRegion->getExitingBasicBlock(); - Builder.setInsertPoint(&*LatchVPBB->begin()); + Builder.setInsertPoint(&*std::prev(std::prev(LatchVPBB->end()))); VPBasicBlock::iterator IP = MiddleVPBB->getFirstNonPhi(); for (VPRecipeBase &R : Plan->getVectorLoopRegion()->getEntryBasicBlock()->phis()) { @@ -9966,8 +9962,6 @@ void LoopVectorizationPlanner::adjustRecipesForReductions( if (!PhiR->isInLoop() && CM.foldTailByMasking() && !isa<VPPartialReductionRecipe>(OrigExitingVPV->getDefiningRecipe())) { VPValue *Cond = RecipeBuilder.getBlockInMask(OrigLoop->getHeader()); - assert(OrigExitingVPV->getDefiningRecipe()->getParent() != LatchVPBB && - "reduction recipe must be defined before latch"); Type *PhiTy = PhiR->getOperand(0)->getLiveInIRValue()->getType(); std::optional<FastMathFlags> FMFs = PhiTy->isFloatingPointTy() diff --git a/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp b/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp index f24d422..b374371 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp @@ -451,10 +451,6 @@ void VPlanTransforms::createLoopRegions(VPlan &Plan, Type *InductionTy, createLoopRegion(Plan, HeaderVPB); VPRegionBlock *TopRegion = Plan.getVectorLoopRegion(); - auto *OrigExiting = TopRegion->getExiting(); - VPBasicBlock *LatchVPBB = Plan.createVPBasicBlock("vector.latch"); - VPBlockUtils::insertBlockAfter(LatchVPBB, OrigExiting); - TopRegion->setExiting(LatchVPBB); TopRegion->setName("vector loop"); TopRegion->getEntryBasicBlock()->setName("vector.body"); @@ -472,7 +468,6 @@ void VPlanTransforms::createLoopRegions(VPlan &Plan, Type *InductionTy, VPBasicBlock *VecPreheader = Plan.createVPBasicBlock("vector.ph"); VPBlockUtils::insertBlockAfter(VecPreheader, Plan.getEntry()); - VPBasicBlock *MiddleVPBB = Plan.createVPBasicBlock("middle.block"); VPBlockUtils::insertBlockAfter(MiddleVPBB, TopRegion); diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp index 95dfeea..fa16a64 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -55,6 +55,9 @@ bool VPlanTransforms::tryToConvertVPInstructionsToVPRecipes( make_early_inc_range(make_range(VPBB->begin(), EndIter))) { VPValue *VPV = Ingredient.getVPSingleValue(); + if (!VPV->getUnderlyingValue()) + continue; + Instruction *Inst = cast<Instruction>(VPV->getUnderlyingValue()); VPRecipeBase *NewRecipe = nullptr; @@ -387,9 +390,13 @@ static void addReplicateRegions(VPlan &Plan) { SplitBlock->setName( OrigBB->hasName() ? OrigBB->getName() + "." + Twine(BBNum++) : ""); // Record predicated instructions for above packing optimizations. - VPBlockBase *Region = createReplicateRegion(RepR, Plan); + VPRegionBlock *Region = createReplicateRegion(RepR, Plan); Region->setParent(CurrentBlock->getParent()); VPBlockUtils::insertOnEdge(CurrentBlock, SplitBlock, Region); + + VPRegionBlock *ParentRegion = Region->getParent(); + if (ParentRegion && ParentRegion->getExiting() == CurrentBlock) + ParentRegion->setExiting(SplitBlock); } } |