Skip to content

Commit 830e526

Browse files
committed
[NFC][LoopVectorize] Avoid passing ScalarEvolution to VPlanTransforms::optimize
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 44cfbef commit 830e526

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8555,7 +8555,7 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
85558555
if (!Plan->hasVF(ElementCount::getFixed(1)))
85568556
VPlanTransforms::truncateToMinimalBitwidths(
85578557
*Plan, CM.getMinimalBitwidths(), PSE.getSE()->getContext());
8558-
VPlanTransforms::optimize(*Plan, *PSE.getSE());
8558+
VPlanTransforms::optimize(*Plan, PSE.getSE()->getContext());
85598559
// TODO: try to put it close to addActiveLaneMask().
85608560
// Discard the plan if it is not EVL-compatible
85618561
if (CM.foldTailWithEVL() &&

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,7 @@ void LoopVectorizationPlanner::buildVPlans(ElementCount MinVF,
16251625
for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFTimes2);) {
16261626
VFRange SubRange = {VF, MaxVFTimes2};
16271627
auto Plan = buildVPlan(SubRange);
1628-
VPlanTransforms::optimize(*Plan, *PSE.getSE());
1628+
VPlanTransforms::optimize(*Plan, PSE.getSE()->getContext());
16291629
VPlans.push_back(std::move(Plan));
16301630
VF = SubRange.End;
16311631
}

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ static void removeDeadRecipes(VPlan &Plan) {
523523
static VPScalarIVStepsRecipe *
524524
createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
525525
Instruction::BinaryOps InductionOpcode,
526-
FPMathOperator *FPBinOp, ScalarEvolution &SE,
526+
FPMathOperator *FPBinOp, LLVMContext &Ctx,
527527
Instruction *TruncI, VPValue *StartV, VPValue *Step,
528528
VPBasicBlock::iterator IP) {
529529
VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
@@ -535,8 +535,7 @@ createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
535535
}
536536

537537
// Truncate base induction if needed.
538-
VPTypeAnalysis TypeInfo(Plan.getCanonicalIV()->getScalarType(),
539-
SE.getContext());
538+
VPTypeAnalysis TypeInfo(Plan.getCanonicalIV()->getScalarType(), Ctx);
540539
Type *ResultTy = TypeInfo.inferScalarType(BaseIV);
541540
if (TruncI) {
542541
Type *TruncTy = TruncI->getType();
@@ -576,7 +575,7 @@ createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
576575
/// if any of its users needs scalar values, by providing them scalar steps
577576
/// built on the canonical scalar IV and update the original IV's users. This is
578577
/// an optional optimization to reduce the needs of vector extracts.
579-
static void legalizeAndOptimizeInductions(VPlan &Plan, ScalarEvolution &SE) {
578+
static void legalizeAndOptimizeInductions(VPlan &Plan, LLVMContext &Ctx) {
580579
SmallVector<VPRecipeBase *> ToRemove;
581580
VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
582581
bool HasOnlyVectorVFs = !Plan.hasVF(ElementCount::getFixed(1));
@@ -594,7 +593,7 @@ static void legalizeAndOptimizeInductions(VPlan &Plan, ScalarEvolution &SE) {
594593
VPValue *StepV = PtrIV->getOperand(1);
595594
VPScalarIVStepsRecipe *Steps = createScalarIVSteps(
596595
Plan, InductionDescriptor::IK_IntInduction, Instruction::Add, nullptr,
597-
SE, nullptr, StartV, StepV, InsertPt);
596+
Ctx, nullptr, StartV, StepV, InsertPt);
598597

599598
auto *Recipe = new VPInstruction(VPInstruction::PtrAdd,
600599
{PtrIV->getStartValue(), Steps},
@@ -618,7 +617,7 @@ static void legalizeAndOptimizeInductions(VPlan &Plan, ScalarEvolution &SE) {
618617
const InductionDescriptor &ID = WideIV->getInductionDescriptor();
619618
VPScalarIVStepsRecipe *Steps = createScalarIVSteps(
620619
Plan, ID.getKind(), ID.getInductionOpcode(),
621-
dyn_cast_or_null<FPMathOperator>(ID.getInductionBinOp()), SE,
620+
dyn_cast_or_null<FPMathOperator>(ID.getInductionBinOp()), Ctx,
622621
WideIV->getTruncInst(), WideIV->getStartValue(), WideIV->getStepValue(),
623622
InsertPt);
624623

@@ -1119,12 +1118,12 @@ void VPlanTransforms::truncateToMinimalBitwidths(
11191118
"some entries in MinBWs haven't been processed");
11201119
}
11211120

1122-
void VPlanTransforms::optimize(VPlan &Plan, ScalarEvolution &SE) {
1121+
void VPlanTransforms::optimize(VPlan &Plan, LLVMContext &Ctx) {
11231122
removeRedundantCanonicalIVs(Plan);
11241123
removeRedundantInductionCasts(Plan);
11251124

1126-
simplifyRecipes(Plan, SE.getContext());
1127-
legalizeAndOptimizeInductions(Plan, SE);
1125+
simplifyRecipes(Plan, Ctx);
1126+
legalizeAndOptimizeInductions(Plan, Ctx);
11281127
removeDeadRecipes(Plan);
11291128

11301129
createAndOptimizeReplicateRegions(Plan);

llvm/lib/Transforms/Vectorize/VPlanTransforms.h

Lines changed: 1 addition & 1 deletion
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, LLVMContext &Ctx);
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

0 commit comments

Comments
 (0)