[llvm] [NFC][LoopVectorize] Avoid passing ScalarEvolution to VPlanTransforms::optimize (PR #108380)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 12 05:50:26 PDT 2024
https://github.com/david-arm created https://github.com/llvm/llvm-project/pull/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.
>From 830e526e93bd7442e078b899bff435b26da7ca2b Mon Sep 17 00:00:00 2001
From: David Sherwood <david.sherwood at arm.com>
Date: Thu, 12 Sep 2024 12:47:08 +0000
Subject: [PATCH] [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.
---
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 2 +-
llvm/lib/Transforms/Vectorize/VPlan.cpp | 2 +-
.../Transforms/Vectorize/VPlanTransforms.cpp | 17 ++++++++---------
llvm/lib/Transforms/Vectorize/VPlanTransforms.h | 2 +-
4 files changed, 11 insertions(+), 12 deletions(-)
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
More information about the llvm-commits
mailing list