[llvm] 371bb2c - [VPlan] Move createReplicateRegion out of VPRecipeBuilder.h. (NFC)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 18 13:31:05 PDT 2023
Author: Florian Hahn
Date: 2023-03-18T20:30:49Z
New Revision: 371bb2c9d34aa9b9809de6fcac5d60671f7cafed
URL: https://github.com/llvm/llvm-project/commit/371bb2c9d34aa9b9809de6fcac5d60671f7cafed
DIFF: https://github.com/llvm/llvm-project/commit/371bb2c9d34aa9b9809de6fcac5d60671f7cafed.diff
LOG: [VPlan] Move createReplicateRegion out of VPRecipeBuilder.h. (NFC)
The function doesn't use anything from VPRecipeBuilder, so move the
definition to where it is actually used and turn it into a simple static
function.
It also makes the VPRecipeBuilder argument for createAndOptimizeReplicateRegions
unnecessary.
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
llvm/lib/Transforms/Vectorize/VPlanTransforms.h
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index f460d95f5e65..1054f6aab074 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8583,43 +8583,6 @@ VPRecipeOrVPValueTy VPRecipeBuilder::handleReplication(Instruction *I,
return toVPRecipeResult(Recipe);
}
-VPRegionBlock *
-VPRecipeBuilder::createReplicateRegion(VPReplicateRecipe *PredRecipe,
- VPlan &Plan) {
- Instruction *Instr = PredRecipe->getUnderlyingInstr();
- // Build the triangular if-then region.
- std::string RegionName = (Twine("pred.") + Instr->getOpcodeName()).str();
- assert(Instr->getParent() && "Predicated instruction not in any basic block");
- auto *BlockInMask = PredRecipe->getMask();
- auto *BOMRecipe = new VPBranchOnMaskRecipe(BlockInMask);
- auto *Entry = new VPBasicBlock(Twine(RegionName) + ".entry", BOMRecipe);
-
- // Replace predicated replicate recipe with a replicate recipe without a
- // mask but in the replicate region.
- auto *RecipeWithoutMask = new VPReplicateRecipe(
- PredRecipe->getUnderlyingInstr(),
- make_range(PredRecipe->op_begin(), std::prev(PredRecipe->op_end())),
- PredRecipe->isUniform());
- auto *Pred = new VPBasicBlock(Twine(RegionName) + ".if", RecipeWithoutMask);
-
- VPPredInstPHIRecipe *PHIRecipe = nullptr;
- if (PredRecipe->getNumUsers() != 0) {
- PHIRecipe = new VPPredInstPHIRecipe(RecipeWithoutMask);
- PredRecipe->replaceAllUsesWith(PHIRecipe);
- PHIRecipe->setOperand(0, RecipeWithoutMask);
- }
- PredRecipe->eraseFromParent();
- auto *Exiting = new VPBasicBlock(Twine(RegionName) + ".continue", PHIRecipe);
- VPRegionBlock *Region = new VPRegionBlock(Entry, Exiting, RegionName, true);
-
- // Note: first set Entry as region entry and then connect successors starting
- // from it in order, to propagate the "parent" of each VPBasicBlock.
- VPBlockUtils::insertTwoBlocksAfter(Pred, Exiting, Entry);
- VPBlockUtils::connectBlocks(Pred, Exiting);
-
- return Region;
-}
-
VPRecipeOrVPValueTy
VPRecipeBuilder::tryToCreateWidenRecipe(Instruction *Instr,
ArrayRef<VPValue *> Operands,
@@ -9076,7 +9039,7 @@ VPlanPtr LoopVectorizationPlanner::buildVPlanWithVPRecipes(
VPlanTransforms::optimizeInductions(*Plan, *PSE.getSE());
VPlanTransforms::removeDeadRecipes(*Plan);
- VPlanTransforms::createAndOptimizeReplicateRegions(*Plan, RecipeBuilder);
+ VPlanTransforms::createAndOptimizeReplicateRegions(*Plan);
VPlanTransforms::removeRedundantExpandSCEVRecipes(*Plan);
VPlanTransforms::mergeBlocksIntoPredecessors(*Plan);
diff --git a/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h b/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h
index ca8ef71a48fb..8313b2ca4fdb 100644
--- a/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h
+++ b/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h
@@ -159,10 +159,6 @@ class VPRecipeBuilder {
return Ingredient2Recipe[I];
}
- /// Create a replicating region for \p PredRecipe.
- VPRegionBlock *createReplicateRegion(VPReplicateRecipe *PredRecipe,
- VPlan &Plan);
-
/// Build a VPReplicationRecipe for \p I. If it is predicated, add the mask as
/// last operand. Range.End may be decreased to ensure same recipe behavior
/// from \p Range.Start to \p Range.End.
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index e642d264b1c7..99f600002336 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -314,7 +314,43 @@ static bool mergeReplicateRegionsIntoSuccessors(VPlan &Plan) {
return !DeletedRegions.empty();
}
-static void addReplicateRegions(VPlan &Plan, VPRecipeBuilder &Builder) {
+static VPRegionBlock *createReplicateRegion(VPReplicateRecipe *PredRecipe,
+ VPlan &Plan) {
+ Instruction *Instr = PredRecipe->getUnderlyingInstr();
+ // Build the triangular if-then region.
+ std::string RegionName = (Twine("pred.") + Instr->getOpcodeName()).str();
+ assert(Instr->getParent() && "Predicated instruction not in any basic block");
+ auto *BlockInMask = PredRecipe->getMask();
+ auto *BOMRecipe = new VPBranchOnMaskRecipe(BlockInMask);
+ auto *Entry = new VPBasicBlock(Twine(RegionName) + ".entry", BOMRecipe);
+
+ // Replace predicated replicate recipe with a replicate recipe without a
+ // mask but in the replicate region.
+ auto *RecipeWithoutMask = new VPReplicateRecipe(
+ PredRecipe->getUnderlyingInstr(),
+ make_range(PredRecipe->op_begin(), std::prev(PredRecipe->op_end())),
+ PredRecipe->isUniform());
+ auto *Pred = new VPBasicBlock(Twine(RegionName) + ".if", RecipeWithoutMask);
+
+ VPPredInstPHIRecipe *PHIRecipe = nullptr;
+ if (PredRecipe->getNumUsers() != 0) {
+ PHIRecipe = new VPPredInstPHIRecipe(RecipeWithoutMask);
+ PredRecipe->replaceAllUsesWith(PHIRecipe);
+ PHIRecipe->setOperand(0, RecipeWithoutMask);
+ }
+ PredRecipe->eraseFromParent();
+ auto *Exiting = new VPBasicBlock(Twine(RegionName) + ".continue", PHIRecipe);
+ VPRegionBlock *Region = new VPRegionBlock(Entry, Exiting, RegionName, true);
+
+ // Note: first set Entry as region entry and then connect successors starting
+ // from it in order, to propagate the "parent" of each VPBasicBlock.
+ VPBlockUtils::insertTwoBlocksAfter(Pred, Exiting, Entry);
+ VPBlockUtils::connectBlocks(Pred, Exiting);
+
+ return Region;
+}
+
+static void addReplicateRegions(VPlan &Plan) {
SmallVector<VPReplicateRecipe *> WorkList;
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
vp_depth_first_deep(Plan.getEntry()))) {
@@ -334,7 +370,7 @@ static void addReplicateRegions(VPlan &Plan, VPRecipeBuilder &Builder) {
SplitBlock->setName(
OrigBB->hasName() ? OrigBB->getName() + "." + Twine(BBNum++) : "");
// Record predicated instructions for above packing optimizations.
- VPBlockBase *Region = Builder.createReplicateRegion(RepR, Plan);
+ VPBlockBase *Region = createReplicateRegion(RepR, Plan);
Region->setParent(CurrentBlock->getParent());
VPBlockUtils::disconnectBlocks(CurrentBlock, SplitBlock);
VPBlockUtils::connectBlocks(CurrentBlock, Region);
@@ -342,10 +378,9 @@ static void addReplicateRegions(VPlan &Plan, VPRecipeBuilder &Builder) {
}
}
-void VPlanTransforms::createAndOptimizeReplicateRegions(
- VPlan &Plan, VPRecipeBuilder &Builder) {
+void VPlanTransforms::createAndOptimizeReplicateRegions(VPlan &Plan) {
// Convert masked VPReplicateRecipes to if-then region blocks.
- addReplicateRegions(Plan, Builder);
+ addReplicateRegions(Plan);
bool ShouldSimplify = true;
while (ShouldSimplify) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
index 4c4a11fa7250..e5bd1a42f877 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
@@ -42,8 +42,7 @@ struct VPlanTransforms {
/// region block and remove the mask operand. Optimize the created regions by
/// iteratively sinking scalar operands into the region, followed by merging
/// regions until no improvements are remaining.
- static void createAndOptimizeReplicateRegions(VPlan &Plan,
- VPRecipeBuilder &Builder);
+ static void createAndOptimizeReplicateRegions(VPlan &Plan);
/// Remove redundant VPBasicBlocks by merging them into their predecessor if
/// the predecessor has a single successor.
More information about the llvm-commits
mailing list