[llvm] 34accad - [VPlan] Move logic to create VPScalarIVStepsRecipe to helper (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 8 13:26:18 PDT 2023
Author: Florian Hahn
Date: 2023-08-08T21:25:06+01:00
New Revision: 34accad1feae14c313751f0b3dbea71042484e94
URL: https://github.com/llvm/llvm-project/commit/34accad1feae14c313751f0b3dbea71042484e94
DIFF: https://github.com/llvm/llvm-project/commit/34accad1feae14c313751f0b3dbea71042484e94.diff
LOG: [VPlan] Move logic to create VPScalarIVStepsRecipe to helper (NFC).
This allows for easier re-use in follow-on patches.
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 5ab416e9be9d47..26e638aef4db45 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -501,6 +501,26 @@ void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
}
}
+static VPValue *createScalarIVSteps(VPlan &Plan, const InductionDescriptor &ID,
+ ScalarEvolution &SE, Instruction *TruncI,
+ Type *IVTy, VPValue *StartV) {
+ VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
+ auto IP = HeaderVPBB->getFirstNonPhi();
+ VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
+ VPValue *Step =
+ vputils::getOrCreateVPValueForSCEVExpr(Plan, ID.getStep(), SE);
+ Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
+ VPValue *BaseIV = CanonicalIV;
+ if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step, TruncTy)) {
+ BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step, TruncTy);
+ HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
+ }
+
+ VPScalarIVStepsRecipe *Steps = new VPScalarIVStepsRecipe(ID, BaseIV, Step);
+ HeaderVPBB->insert(Steps, IP);
+ return Steps;
+}
+
void VPlanTransforms::optimizeInductions(VPlan &Plan, ScalarEvolution &SE) {
SmallVector<VPRecipeBase *> ToRemove;
VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
@@ -514,23 +534,10 @@ void VPlanTransforms::optimizeInductions(VPlan &Plan, ScalarEvolution &SE) {
}))
continue;
- auto IP = HeaderVPBB->getFirstNonPhi();
- VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
- Type *ResultTy = WideIV->getPHINode()->getType();
- if (Instruction *TruncI = WideIV->getTruncInst())
- ResultTy = TruncI->getType();
const InductionDescriptor &ID = WideIV->getInductionDescriptor();
- VPValue *Step = WideIV->getStepValue();
- VPValue *BaseIV = CanonicalIV;
- if (!CanonicalIV->isCanonical(ID.getKind(), WideIV->getStartValue(), Step,
- ResultTy)) {
- BaseIV = new VPDerivedIVRecipe(ID, WideIV->getStartValue(), CanonicalIV,
- Step, ResultTy);
- HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
- }
-
- VPScalarIVStepsRecipe *Steps = new VPScalarIVStepsRecipe(ID, BaseIV, Step);
- HeaderVPBB->insert(Steps, IP);
+ VPValue *Steps = createScalarIVSteps(Plan, ID, SE, WideIV->getTruncInst(),
+ WideIV->getPHINode()->getType(),
+ WideIV->getStartValue());
// Update scalar users of IV to use Step instead. Use SetVector to ensure
// the list of users doesn't contain duplicates.
More information about the llvm-commits
mailing list