Skip to content

Commit 3437af1

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 3437af1

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
@@ -8553,9 +8553,9 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
85538553
if (auto Plan = tryToBuildVPlanWithVPRecipes(SubRange)) {
85548554
// Now optimize the initial VPlan.
85558555
if (!Plan->hasVF(ElementCount::getFixed(1)))
8556-
VPlanTransforms::truncateToMinimalBitwidths(
8557-
*Plan, CM.getMinimalBitwidths(), PSE.getSE()->getContext());
8558-
VPlanTransforms::optimize(*Plan, *PSE.getSE());
8556+
VPlanTransforms::truncateToMinimalBitwidths(*Plan,
8557+
CM.getMinimalBitwidths());
8558+
VPlanTransforms::optimize(*Plan);
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);
16291629
VPlans.push_back(std::move(Plan));
16301630
VF = SubRange.End;
16311631
}

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -523,9 +523,8 @@ static void removeDeadRecipes(VPlan &Plan) {
523523
static VPScalarIVStepsRecipe *
524524
createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
525525
Instruction::BinaryOps InductionOpcode,
526-
FPMathOperator *FPBinOp, ScalarEvolution &SE,
527-
Instruction *TruncI, VPValue *StartV, VPValue *Step,
528-
VPBasicBlock::iterator IP) {
526+
FPMathOperator *FPBinOp, Instruction *TruncI,
527+
VPValue *StartV, VPValue *Step, VPBasicBlock::iterator IP) {
529528
VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
530529
VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
531530
VPSingleDefRecipe *BaseIV = CanonicalIV;
@@ -535,8 +534,8 @@ createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
535534
}
536535

537536
// Truncate base induction if needed.
538-
VPTypeAnalysis TypeInfo(Plan.getCanonicalIV()->getScalarType(),
539-
SE.getContext());
537+
Type *CanonicalIVType = CanonicalIV->getScalarType();
538+
VPTypeAnalysis TypeInfo(CanonicalIVType, CanonicalIVType->getContext());
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) {
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+
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()),
622621
WideIV->getTruncInst(), WideIV->getStartValue(), WideIV->getStepValue(),
623622
InsertPt);
624623

@@ -976,10 +975,11 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
976975
}
977976

978977
/// Try to simplify the recipes in \p Plan.
979-
static void simplifyRecipes(VPlan &Plan, LLVMContext &Ctx) {
978+
static void simplifyRecipes(VPlan &Plan) {
980979
ReversePostOrderTraversal<VPBlockDeepTraversalWrapper<VPBlockBase *>> RPOT(
981980
Plan.getEntry());
982-
VPTypeAnalysis TypeInfo(Plan.getCanonicalIV()->getScalarType(), Ctx);
981+
Type *CanonicalIVType = Plan.getCanonicalIV()->getScalarType();
982+
VPTypeAnalysis TypeInfo(CanonicalIVType, CanonicalIVType->getContext());
983983
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT)) {
984984
for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
985985
simplifyRecipe(R, TypeInfo);
@@ -988,8 +988,7 @@ static void simplifyRecipes(VPlan &Plan, LLVMContext &Ctx) {
988988
}
989989

990990
void VPlanTransforms::truncateToMinimalBitwidths(
991-
VPlan &Plan, const MapVector<Instruction *, uint64_t> &MinBWs,
992-
LLVMContext &Ctx) {
991+
VPlan &Plan, const MapVector<Instruction *, uint64_t> &MinBWs) {
993992
#ifndef NDEBUG
994993
// Count the processed recipes and cross check the count later with MinBWs
995994
// size, to make sure all entries in MinBWs have been handled.
@@ -1000,7 +999,9 @@ void VPlanTransforms::truncateToMinimalBitwidths(
1000999
// other uses have different types for their operands, making them invalidly
10011000
// typed.
10021001
DenseMap<VPValue *, VPWidenCastRecipe *> ProcessedTruncs;
1003-
VPTypeAnalysis TypeInfo(Plan.getCanonicalIV()->getScalarType(), Ctx);
1002+
Type *CanonicalIVType = Plan.getCanonicalIV()->getScalarType();
1003+
LLVMContext &Ctx = CanonicalIVType->getContext();
1004+
VPTypeAnalysis TypeInfo(CanonicalIVType, Ctx);
10041005
VPBasicBlock *PH = Plan.getEntry();
10051006
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
10061007
vp_depth_first_deep(Plan.getVectorLoopRegion()))) {
@@ -1119,12 +1120,12 @@ void VPlanTransforms::truncateToMinimalBitwidths(
11191120
"some entries in MinBWs haven't been processed");
11201121
}
11211122

1122-
void VPlanTransforms::optimize(VPlan &Plan, ScalarEvolution &SE) {
1123+
void VPlanTransforms::optimize(VPlan &Plan) {
11231124
removeRedundantCanonicalIVs(Plan);
11241125
removeRedundantInductionCasts(Plan);
11251126

1126-
simplifyRecipes(Plan, SE.getContext());
1127-
legalizeAndOptimizeInductions(Plan, SE);
1127+
simplifyRecipes(Plan);
1128+
legalizeAndOptimizeInductions(Plan);
11281129
removeDeadRecipes(Plan);
11291130

11301131
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)