@@ -2682,29 +2682,21 @@ static Value *getExpandedStep(const InductionDescriptor &ID,
2682
2682
return I->second ;
2683
2683
}
2684
2684
2685
- // / Knowing that loop \p L would be fully unrolled after vectorisation , add
2686
- // / instructions that will get simplified and thus should not have any cost to
2687
- // / \p InstsToIgnore
2688
- static void AddFullyUnrolledInstructionsToIgnore (
2685
+ // / Knowing that loop \p L executes a single vector iteration , add instructions
2686
+ // / that will get simplified and thus should not have any cost to \p
2687
+ // / InstsToIgnore.
2688
+ static void addFullyUnrolledInstructionsToIgnore (
2689
2689
Loop *L, const LoopVectorizationLegality::InductionList &IL,
2690
2690
SmallPtrSetImpl<Instruction *> &InstsToIgnore) {
2691
2691
auto *Cmp = L->getLatchCmpInst ();
2692
- if (!Cmp)
2693
- return ;
2694
- InstsToIgnore.insert (Cmp);
2692
+ if (Cmp)
2693
+ InstsToIgnore.insert (Cmp);
2695
2694
for (const auto &[IV, IndDesc] : IL) {
2696
- // Get next iteration value of the induction variable
2695
+ // Get next iteration value of the induction variable.
2697
2696
Instruction *IVInst =
2698
2697
cast<Instruction>(IV->getIncomingValueForBlock (L->getLoopLatch ()));
2699
- bool IsSimplifiedAway = true ;
2700
- // Check that this value used only to exit the loop
2701
- for (auto *UIV : IVInst->users ()) {
2702
- if (UIV != IV && UIV != Cmp) {
2703
- IsSimplifiedAway = false ;
2704
- break ;
2705
- }
2706
- }
2707
- if (IsSimplifiedAway)
2698
+ if (all_of (IVInst->users (),
2699
+ [&](const User *U) { return U == IV || U == Cmp; }))
2708
2700
InstsToIgnore.insert (IVInst);
2709
2701
}
2710
2702
}
@@ -5619,12 +5611,13 @@ InstructionCost LoopVectorizationCostModel::computePredInstDiscount(
5619
5611
InstructionCost LoopVectorizationCostModel::expectedCost (ElementCount VF) {
5620
5612
InstructionCost Cost;
5621
5613
5622
- // If with the given fixed width VF loop gets fully unrolled, ignore the costs
5623
- // of comparison and induction instructions, as they'll get simplified away
5614
+ // If the vector loop gets executed exactly once with the given VF, ignore the
5615
+ // costs of comparison and induction instructions, as they'll get simplified
5616
+ // away.
5624
5617
SmallPtrSet<Instruction *, 2 > ValuesToIgnoreForVF;
5625
5618
auto TC = PSE.getSE ()->getSmallConstantTripCount (TheLoop);
5626
5619
if (VF.isFixed () && TC == VF.getFixedValue ())
5627
- AddFullyUnrolledInstructionsToIgnore (TheLoop, Legal->getInductionVars (),
5620
+ addFullyUnrolledInstructionsToIgnore (TheLoop, Legal->getInductionVars (),
5628
5621
ValuesToIgnoreForVF);
5629
5622
5630
5623
// For each block.
@@ -7317,11 +7310,14 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF,
7317
7310
IVInsts.push_back (CI);
7318
7311
}
7319
7312
7320
- // If with the given VF loop gets fully unrolled, ignore the costs of
7321
- // comparison and induction instructions, as they'll get simplified away
7313
+ // If the vector loop gets executed exactly once with the given VF, ignore
7314
+ // the costs of comparison and induction instructions, as they'll get
7315
+ // simplified away.
7316
+ // TODO: Remove this code after stepping away from the legacy cost model and
7317
+ // adding code to simplify VPlans before calculating their costs.
7322
7318
auto TC = PSE.getSE ()->getSmallConstantTripCount (OrigLoop);
7323
7319
if (VF.isFixed () && TC == VF.getFixedValue ())
7324
- AddFullyUnrolledInstructionsToIgnore (OrigLoop, Legal->getInductionVars (),
7320
+ addFullyUnrolledInstructionsToIgnore (OrigLoop, Legal->getInductionVars (),
7325
7321
CostCtx.SkipCostComputation );
7326
7322
7327
7323
for (Instruction *IVInst : IVInsts) {
0 commit comments