Skip to content

Commit f3029b3

Browse files
authored
[NFC][LoopVectorize] Avoid passing ScalarEvolution to VPlanTransforms::optimize (#108380)
Whilst trying to write some VPlan unit tests I realised that we don't need to pass a ScalarEvolution object into VPlanTransforms::optimize because the only thing we actually need is a LLVMContext.
1 parent ebbc9ed commit f3029b3

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8598,9 +8598,9 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
85988598
if (auto Plan = tryToBuildVPlanWithVPRecipes(SubRange)) {
85998599
// Now optimize the initial VPlan.
86008600
if (!Plan->hasVF(ElementCount::getFixed(1)))
8601-
VPlanTransforms::truncateToMinimalBitwidths(
8602-
*Plan, CM.getMinimalBitwidths(), PSE.getSE()->getContext());
8603-
VPlanTransforms::optimize(*Plan, *PSE.getSE());
8601+
VPlanTransforms::truncateToMinimalBitwidths(*Plan,
8602+
CM.getMinimalBitwidths());
8603+
VPlanTransforms::optimize(*Plan);
86048604
// TODO: try to put it close to addActiveLaneMask().
86058605
// Discard the plan if it is not EVL-compatible
86068606
if (CM.foldTailWithEVL() &&

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,7 @@ void LoopVectorizationPlanner::buildVPlans(ElementCount MinVF,
16441644
for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFTimes2);) {
16451645
VFRange SubRange = {VF, MaxVFTimes2};
16461646
auto Plan = buildVPlan(SubRange);
1647-
VPlanTransforms::optimize(*Plan, *PSE.getSE());
1647+
VPlanTransforms::optimize(*Plan);
16481648
VPlans.push_back(std::move(Plan));
16491649
VF = SubRange.End;
16501650
}

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,8 @@ static void removeDeadRecipes(VPlan &Plan) {
526526
static VPScalarIVStepsRecipe *
527527
createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
528528
Instruction::BinaryOps InductionOpcode,
529-
FPMathOperator *FPBinOp, ScalarEvolution &SE,
530-
Instruction *TruncI, VPValue *StartV, VPValue *Step,
531-
VPBasicBlock::iterator IP) {
529+
FPMathOperator *FPBinOp, Instruction *TruncI,
530+
VPValue *StartV, VPValue *Step, VPBasicBlock::iterator IP) {
532531
VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
533532
VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
534533
VPSingleDefRecipe *BaseIV = CanonicalIV;
@@ -538,8 +537,8 @@ createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
538537
}
539538

540539
// Truncate base induction if needed.
541-
VPTypeAnalysis TypeInfo(Plan.getCanonicalIV()->getScalarType(),
542-
SE.getContext());
540+
Type *CanonicalIVType = CanonicalIV->getScalarType();
541+
VPTypeAnalysis TypeInfo(CanonicalIVType, CanonicalIVType->getContext());
543542
Type *ResultTy = TypeInfo.inferScalarType(BaseIV);
544543
if (TruncI) {
545544
Type *TruncTy = TruncI->getType();
@@ -579,7 +578,7 @@ createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
579578
/// if any of its users needs scalar values, by providing them scalar steps
580579
/// built on the canonical scalar IV and update the original IV's users. This is
581580
/// an optional optimization to reduce the needs of vector extracts.
582-
static void legalizeAndOptimizeInductions(VPlan &Plan, ScalarEvolution &SE) {
581+
static void legalizeAndOptimizeInductions(VPlan &Plan) {
583582
SmallVector<VPRecipeBase *> ToRemove;
584583
VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
585584
bool HasOnlyVectorVFs = !Plan.hasVF(ElementCount::getFixed(1));
@@ -597,7 +596,7 @@ static void legalizeAndOptimizeInductions(VPlan &Plan, ScalarEvolution &SE) {
597596
VPValue *StepV = PtrIV->getOperand(1);
598597
VPScalarIVStepsRecipe *Steps = createScalarIVSteps(
599598
Plan, InductionDescriptor::IK_IntInduction, Instruction::Add, nullptr,
600-
SE, nullptr, StartV, StepV, InsertPt);
599+
nullptr, StartV, StepV, InsertPt);
601600

602601
auto *Recipe = new VPInstruction(VPInstruction::PtrAdd,
603602
{PtrIV->getStartValue(), Steps},
@@ -621,7 +620,7 @@ static void legalizeAndOptimizeInductions(VPlan &Plan, ScalarEvolution &SE) {
621620
const InductionDescriptor &ID = WideIV->getInductionDescriptor();
622621
VPScalarIVStepsRecipe *Steps = createScalarIVSteps(
623622
Plan, ID.getKind(), ID.getInductionOpcode(),
624-
dyn_cast_or_null<FPMathOperator>(ID.getInductionBinOp()), SE,
623+
dyn_cast_or_null<FPMathOperator>(ID.getInductionBinOp()),
625624
WideIV->getTruncInst(), WideIV->getStartValue(), WideIV->getStepValue(),
626625
InsertPt);
627626

@@ -979,10 +978,11 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
979978
}
980979

981980
/// Try to simplify the recipes in \p Plan.
982-
static void simplifyRecipes(VPlan &Plan, LLVMContext &Ctx) {
981+
static void simplifyRecipes(VPlan &Plan) {
983982
ReversePostOrderTraversal<VPBlockDeepTraversalWrapper<VPBlockBase *>> RPOT(
984983
Plan.getEntry());
985-
VPTypeAnalysis TypeInfo(Plan.getCanonicalIV()->getScalarType(), Ctx);
984+
Type *CanonicalIVType = Plan.getCanonicalIV()->getScalarType();
985+
VPTypeAnalysis TypeInfo(CanonicalIVType, CanonicalIVType->getContext());
986986
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT)) {
987987
for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
988988
simplifyRecipe(R, TypeInfo);
@@ -991,8 +991,7 @@ static void simplifyRecipes(VPlan &Plan, LLVMContext &Ctx) {
991991
}
992992

993993
void VPlanTransforms::truncateToMinimalBitwidths(
994-
VPlan &Plan, const MapVector<Instruction *, uint64_t> &MinBWs,
995-
LLVMContext &Ctx) {
994+
VPlan &Plan, const MapVector<Instruction *, uint64_t> &MinBWs) {
996995
#ifndef NDEBUG
997996
// Count the processed recipes and cross check the count later with MinBWs
998997
// size, to make sure all entries in MinBWs have been handled.
@@ -1003,7 +1002,9 @@ void VPlanTransforms::truncateToMinimalBitwidths(
10031002
// other uses have different types for their operands, making them invalidly
10041003
// typed.
10051004
DenseMap<VPValue *, VPWidenCastRecipe *> ProcessedTruncs;
1006-
VPTypeAnalysis TypeInfo(Plan.getCanonicalIV()->getScalarType(), Ctx);
1005+
Type *CanonicalIVType = Plan.getCanonicalIV()->getScalarType();
1006+
LLVMContext &Ctx = CanonicalIVType->getContext();
1007+
VPTypeAnalysis TypeInfo(CanonicalIVType, Ctx);
10071008
VPBasicBlock *PH = Plan.getEntry();
10081009
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
10091010
vp_depth_first_deep(Plan.getVectorLoopRegion()))) {
@@ -1123,12 +1124,12 @@ void VPlanTransforms::truncateToMinimalBitwidths(
11231124
"some entries in MinBWs haven't been processed");
11241125
}
11251126

1126-
void VPlanTransforms::optimize(VPlan &Plan, ScalarEvolution &SE) {
1127+
void VPlanTransforms::optimize(VPlan &Plan) {
11271128
removeRedundantCanonicalIVs(Plan);
11281129
removeRedundantInductionCasts(Plan);
11291130

1130-
simplifyRecipes(Plan, SE.getContext());
1131-
legalizeAndOptimizeInductions(Plan, SE);
1131+
simplifyRecipes(Plan);
1132+
legalizeAndOptimizeInductions(Plan);
11321133
removeDeadRecipes(Plan);
11331134

11341135
createAndOptimizeReplicateRegions(Plan);

llvm/lib/Transforms/Vectorize/VPlanTransforms.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct VPlanTransforms {
5858
/// Apply VPlan-to-VPlan optimizations to \p Plan, including induction recipe
5959
/// optimizations, dead recipe removal, replicate region optimizations and
6060
/// block merging.
61-
static void optimize(VPlan &Plan, ScalarEvolution &SE);
61+
static void optimize(VPlan &Plan);
6262

6363
/// Wrap predicated VPReplicateRecipes with a mask operand in an if-then
6464
/// region block and remove the mask operand. Optimize the created regions by
@@ -82,8 +82,7 @@ struct VPlanTransforms {
8282
/// will be folded later.
8383
static void
8484
truncateToMinimalBitwidths(VPlan &Plan,
85-
const MapVector<Instruction *, uint64_t> &MinBWs,
86-
LLVMContext &Ctx);
85+
const MapVector<Instruction *, uint64_t> &MinBWs);
8786

8887
/// Drop poison flags from recipes that may generate a poison value that is
8988
/// used after vectorization, even when their operands are not poison. Those

0 commit comments

Comments
 (0)