-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NFC][LoopVectorize] Avoid passing ScalarEvolution to VPlanTransforms::optimize #108380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-transforms Author: David Sherwood (david-arm) ChangesWhilst trying to write some VPlan unit tests I realised Full diff: https://github.com/llvm/llvm-project/pull/108380.diff 4 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index a8722db654f5c9..b70a9222b2937f 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8555,7 +8555,7 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
if (!Plan->hasVF(ElementCount::getFixed(1)))
VPlanTransforms::truncateToMinimalBitwidths(
*Plan, CM.getMinimalBitwidths(), PSE.getSE()->getContext());
- VPlanTransforms::optimize(*Plan, *PSE.getSE());
+ VPlanTransforms::optimize(*Plan, PSE.getSE()->getContext());
// TODO: try to put it close to addActiveLaneMask().
// Discard the plan if it is not EVL-compatible
if (CM.foldTailWithEVL() &&
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index ac322638056879..d17a65c6746c65 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -1625,7 +1625,7 @@ void LoopVectorizationPlanner::buildVPlans(ElementCount MinVF,
for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFTimes2);) {
VFRange SubRange = {VF, MaxVFTimes2};
auto Plan = buildVPlan(SubRange);
- VPlanTransforms::optimize(*Plan, *PSE.getSE());
+ VPlanTransforms::optimize(*Plan, PSE.getSE()->getContext());
VPlans.push_back(std::move(Plan));
VF = SubRange.End;
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 9796ee64f6ef90..7ed5a58e759a16 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -523,7 +523,7 @@ static void removeDeadRecipes(VPlan &Plan) {
static VPScalarIVStepsRecipe *
createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
Instruction::BinaryOps InductionOpcode,
- FPMathOperator *FPBinOp, ScalarEvolution &SE,
+ FPMathOperator *FPBinOp, LLVMContext &Ctx,
Instruction *TruncI, VPValue *StartV, VPValue *Step,
VPBasicBlock::iterator IP) {
VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
@@ -535,8 +535,7 @@ createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
}
// Truncate base induction if needed.
- VPTypeAnalysis TypeInfo(Plan.getCanonicalIV()->getScalarType(),
- SE.getContext());
+ VPTypeAnalysis TypeInfo(Plan.getCanonicalIV()->getScalarType(), Ctx);
Type *ResultTy = TypeInfo.inferScalarType(BaseIV);
if (TruncI) {
Type *TruncTy = TruncI->getType();
@@ -576,7 +575,7 @@ createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
/// if any of its users needs scalar values, by providing them scalar steps
/// built on the canonical scalar IV and update the original IV's users. This is
/// an optional optimization to reduce the needs of vector extracts.
-static void legalizeAndOptimizeInductions(VPlan &Plan, ScalarEvolution &SE) {
+static void legalizeAndOptimizeInductions(VPlan &Plan, LLVMContext &Ctx) {
SmallVector<VPRecipeBase *> ToRemove;
VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
bool HasOnlyVectorVFs = !Plan.hasVF(ElementCount::getFixed(1));
@@ -594,7 +593,7 @@ static void legalizeAndOptimizeInductions(VPlan &Plan, ScalarEvolution &SE) {
VPValue *StepV = PtrIV->getOperand(1);
VPScalarIVStepsRecipe *Steps = createScalarIVSteps(
Plan, InductionDescriptor::IK_IntInduction, Instruction::Add, nullptr,
- SE, nullptr, StartV, StepV, InsertPt);
+ Ctx, nullptr, StartV, StepV, InsertPt);
auto *Recipe = new VPInstruction(VPInstruction::PtrAdd,
{PtrIV->getStartValue(), Steps},
@@ -618,7 +617,7 @@ static void legalizeAndOptimizeInductions(VPlan &Plan, ScalarEvolution &SE) {
const InductionDescriptor &ID = WideIV->getInductionDescriptor();
VPScalarIVStepsRecipe *Steps = createScalarIVSteps(
Plan, ID.getKind(), ID.getInductionOpcode(),
- dyn_cast_or_null<FPMathOperator>(ID.getInductionBinOp()), SE,
+ dyn_cast_or_null<FPMathOperator>(ID.getInductionBinOp()), Ctx,
WideIV->getTruncInst(), WideIV->getStartValue(), WideIV->getStepValue(),
InsertPt);
@@ -1119,12 +1118,12 @@ void VPlanTransforms::truncateToMinimalBitwidths(
"some entries in MinBWs haven't been processed");
}
-void VPlanTransforms::optimize(VPlan &Plan, ScalarEvolution &SE) {
+void VPlanTransforms::optimize(VPlan &Plan, LLVMContext &Ctx) {
removeRedundantCanonicalIVs(Plan);
removeRedundantInductionCasts(Plan);
- simplifyRecipes(Plan, SE.getContext());
- legalizeAndOptimizeInductions(Plan, SE);
+ simplifyRecipes(Plan, Ctx);
+ legalizeAndOptimizeInductions(Plan, Ctx);
removeDeadRecipes(Plan);
createAndOptimizeReplicateRegions(Plan);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
index e714f69eeff1ab..8a98bd3d1b5581 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
@@ -58,7 +58,7 @@ struct VPlanTransforms {
/// Apply VPlan-to-VPlan optimizations to \p Plan, including induction recipe
/// optimizations, dead recipe removal, replicate region optimizations and
/// block merging.
- static void optimize(VPlan &Plan, ScalarEvolution &SE);
+ static void optimize(VPlan &Plan, LLVMContext &Ctx);
/// Wrap predicated VPReplicateRecipes with a mask operand in an if-then
/// region block and remove the mask operand. Optimize the created regions by
|
…::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.
830e526
to
3437af1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the cleanup!
VPTypeAnalysis TypeInfo(Plan.getCanonicalIV()->getScalarType(), | ||
SE.getContext()); | ||
Type *CanonicalIVType = CanonicalIV->getScalarType(); | ||
VPTypeAnalysis TypeInfo(CanonicalIVType, CanonicalIVType->getContext()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Post-commit nit, while we're here: is a context other than that of CanonicalIVType relevant, or can TypeInfo's constructor derive its second parameter from its first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.