@@ -2652,29 +2652,21 @@ static Value *getExpandedStep(const InductionDescriptor &ID,
2652
2652
return I->second ;
2653
2653
}
2654
2654
2655
- // / Knowing that loop \p L would be fully unrolled after vectorisation , add
2656
- // / instructions that will get simplified and thus should not have any cost to
2657
- // / \p InstsToIgnore
2658
- static void AddFullyUnrolledInstructionsToIgnore (
2655
+ // / Knowing that loop \p L executes a single vector iteration , add instructions
2656
+ // / that will get simplified and thus should not have any cost to \p
2657
+ // / InstsToIgnore.
2658
+ static void addFullyUnrolledInstructionsToIgnore (
2659
2659
Loop *L, const LoopVectorizationLegality::InductionList &IL,
2660
2660
SmallPtrSetImpl<Instruction *> &InstsToIgnore) {
2661
2661
auto *Cmp = L->getLatchCmpInst ();
2662
- if (!Cmp)
2663
- return ;
2664
- InstsToIgnore.insert (Cmp);
2662
+ if (Cmp)
2663
+ InstsToIgnore.insert (Cmp);
2665
2664
for (const auto &[IV, IndDesc] : IL) {
2666
- // Get next iteration value of the induction variable
2665
+ // Get next iteration value of the induction variable.
2667
2666
Instruction *IVInst =
2668
2667
cast<Instruction>(IV->getIncomingValueForBlock (L->getLoopLatch ()));
2669
- bool IsSimplifiedAway = true ;
2670
- // Check that this value used only to exit the loop
2671
- for (auto *UIV : IVInst->users ()) {
2672
- if (UIV != IV && UIV != Cmp) {
2673
- IsSimplifiedAway = false ;
2674
- break ;
2675
- }
2676
- }
2677
- if (IsSimplifiedAway)
2668
+ if (all_of (IVInst->users (),
2669
+ [&](const User *U) { return U == IV || U == Cmp; }))
2678
2670
InstsToIgnore.insert (IVInst);
2679
2671
}
2680
2672
}
@@ -5586,12 +5578,13 @@ InstructionCost LoopVectorizationCostModel::computePredInstDiscount(
5586
5578
InstructionCost LoopVectorizationCostModel::expectedCost (ElementCount VF) {
5587
5579
InstructionCost Cost;
5588
5580
5589
- // If with the given fixed width VF loop gets fully unrolled, ignore the costs
5590
- // of comparison and induction instructions, as they'll get simplified away
5581
+ // If the vector loop gets executed exactly once with the given VF, ignore the
5582
+ // costs of comparison and induction instructions, as they'll get simplified
5583
+ // away.
5591
5584
SmallPtrSet<Instruction *, 2 > ValuesToIgnoreForVF;
5592
5585
auto TC = PSE.getSE ()->getSmallConstantTripCount (TheLoop);
5593
5586
if (VF.isFixed () && TC == VF.getFixedValue ())
5594
- AddFullyUnrolledInstructionsToIgnore (TheLoop, Legal->getInductionVars (),
5587
+ addFullyUnrolledInstructionsToIgnore (TheLoop, Legal->getInductionVars (),
5595
5588
ValuesToIgnoreForVF);
5596
5589
5597
5590
// For each block.
@@ -7284,11 +7277,14 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF,
7284
7277
IVInsts.push_back (CI);
7285
7278
}
7286
7279
7287
- // If with the given VF loop gets fully unrolled, ignore the costs of
7288
- // comparison and induction instructions, as they'll get simplified away
7280
+ // If the vector loop gets executed exactly once with the given VF, ignore
7281
+ // the costs of comparison and induction instructions, as they'll get
7282
+ // simplified away.
7283
+ // TODO: Remove this code after stepping away from the legacy cost model and
7284
+ // adding code to simplify VPlans before calculating their costs.
7289
7285
auto TC = PSE.getSE ()->getSmallConstantTripCount (OrigLoop);
7290
7286
if (VF.isFixed () && TC == VF.getFixedValue ())
7291
- AddFullyUnrolledInstructionsToIgnore (OrigLoop, Legal->getInductionVars (),
7287
+ addFullyUnrolledInstructionsToIgnore (OrigLoop, Legal->getInductionVars (),
7292
7288
CostCtx.SkipCostComputation );
7293
7289
7294
7290
for (Instruction *IVInst : IVInsts) {
0 commit comments