Skip to content

Commit 34accad

Browse files
committed
[VPlan] Move logic to create VPScalarIVStepsRecipe to helper (NFC).
This allows for easier re-use in follow-on patches.
1 parent 8c6a0c8 commit 34accad

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,26 @@ void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
501501
}
502502
}
503503

504+
static VPValue *createScalarIVSteps(VPlan &Plan, const InductionDescriptor &ID,
505+
ScalarEvolution &SE, Instruction *TruncI,
506+
Type *IVTy, VPValue *StartV) {
507+
VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
508+
auto IP = HeaderVPBB->getFirstNonPhi();
509+
VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
510+
VPValue *Step =
511+
vputils::getOrCreateVPValueForSCEVExpr(Plan, ID.getStep(), SE);
512+
Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
513+
VPValue *BaseIV = CanonicalIV;
514+
if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step, TruncTy)) {
515+
BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step, TruncTy);
516+
HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
517+
}
518+
519+
VPScalarIVStepsRecipe *Steps = new VPScalarIVStepsRecipe(ID, BaseIV, Step);
520+
HeaderVPBB->insert(Steps, IP);
521+
return Steps;
522+
}
523+
504524
void VPlanTransforms::optimizeInductions(VPlan &Plan, ScalarEvolution &SE) {
505525
SmallVector<VPRecipeBase *> ToRemove;
506526
VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
@@ -514,23 +534,10 @@ void VPlanTransforms::optimizeInductions(VPlan &Plan, ScalarEvolution &SE) {
514534
}))
515535
continue;
516536

517-
auto IP = HeaderVPBB->getFirstNonPhi();
518-
VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
519-
Type *ResultTy = WideIV->getPHINode()->getType();
520-
if (Instruction *TruncI = WideIV->getTruncInst())
521-
ResultTy = TruncI->getType();
522537
const InductionDescriptor &ID = WideIV->getInductionDescriptor();
523-
VPValue *Step = WideIV->getStepValue();
524-
VPValue *BaseIV = CanonicalIV;
525-
if (!CanonicalIV->isCanonical(ID.getKind(), WideIV->getStartValue(), Step,
526-
ResultTy)) {
527-
BaseIV = new VPDerivedIVRecipe(ID, WideIV->getStartValue(), CanonicalIV,
528-
Step, ResultTy);
529-
HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
530-
}
531-
532-
VPScalarIVStepsRecipe *Steps = new VPScalarIVStepsRecipe(ID, BaseIV, Step);
533-
HeaderVPBB->insert(Steps, IP);
538+
VPValue *Steps = createScalarIVSteps(Plan, ID, SE, WideIV->getTruncInst(),
539+
WideIV->getPHINode()->getType(),
540+
WideIV->getStartValue());
534541

535542
// Update scalar users of IV to use Step instead. Use SetVector to ensure
536543
// the list of users doesn't contain duplicates.

0 commit comments

Comments
 (0)