@@ -7162,13 +7162,12 @@ InstructionCost LoopVectorizationPlanner::cost(VPlan &Plan,
7162
7162
return Cost;
7163
7163
}
7164
7164
7165
- VPlan & LoopVectorizationPlanner::getBestPlan () const {
7165
+ ElementCount LoopVectorizationPlanner::getBestVF () const {
7166
7166
// If there is a single VPlan with a single VF, return it directly.
7167
7167
VPlan &FirstPlan = *VPlans[0 ];
7168
7168
if (VPlans.size () == 1 && size (FirstPlan.vectorFactors ()) == 1 )
7169
- return FirstPlan;
7169
+ return * FirstPlan. vectorFactors (). begin () ;
7170
7170
7171
- VPlan *BestPlan = &FirstPlan;
7172
7171
ElementCount ScalarVF = ElementCount::getFixed (1 );
7173
7172
assert (hasPlanWithVF (ScalarVF) &&
7174
7173
" More than a single plan/VF w/o any plan having scalar VF" );
@@ -7199,14 +7198,11 @@ VPlan &LoopVectorizationPlanner::getBestPlan() const {
7199
7198
7200
7199
InstructionCost Cost = cost (*P, VF);
7201
7200
VectorizationFactor CurrentFactor (VF, Cost, ScalarCost);
7202
- if (isMoreProfitable (CurrentFactor, BestFactor)) {
7201
+ if (isMoreProfitable (CurrentFactor, BestFactor))
7203
7202
BestFactor = CurrentFactor;
7204
- BestPlan = &*P;
7205
- }
7206
7203
}
7207
7204
}
7208
- BestPlan->setVF (BestFactor.Width );
7209
- return *BestPlan;
7205
+ return BestFactor.Width ;
7210
7206
}
7211
7207
7212
7208
VPlan &LoopVectorizationPlanner::getBestPlanFor (ElementCount VF) const {
@@ -10001,10 +9997,11 @@ bool LoopVectorizePass::processLoop(Loop *L) {
10001
9997
InnerLoopUnroller Unroller (L, PSE, LI, DT, TLI, TTI, AC, ORE, IC, &LVL,
10002
9998
&CM, BFI, PSI, Checks);
10003
9999
10004
- VPlan &BestPlan = LVP.getBestPlan ();
10005
- assert (BestPlan. hasScalarVFOnly () &&
10000
+ ElementCount BestVF = LVP.getBestVF ();
10001
+ assert (BestVF. isScalar () &&
10006
10002
" VPlan cost model and legacy cost model disagreed" );
10007
- LVP.executePlan (VF.Width , IC, BestPlan, Unroller, DT, false );
10003
+ VPlan &BestPlan = LVP.getBestPlanFor (BestVF);
10004
+ LVP.executePlan (BestVF, IC, BestPlan, Unroller, DT, false );
10008
10005
10009
10006
ORE->emit ([&]() {
10010
10007
return OptimizationRemark (LV_NAME, " Interleaved" , L->getStartLoc (),
@@ -10015,21 +10012,25 @@ bool LoopVectorizePass::processLoop(Loop *L) {
10015
10012
} else {
10016
10013
// If we decided that it is *legal* to vectorize the loop, then do it.
10017
10014
10015
+ ElementCount BestVF = LVP.getBestVF ();
10016
+ LLVM_DEBUG (dbgs () << " VF picked by VPlan cost model: " << BestVF << " \n " );
10017
+ assert (VF.Width == BestVF &&
10018
+ " VPlan cost model and legacy cost model disagreed" );
10019
+ VPlan &BestPlan = LVP.getBestPlanFor (BestVF);
10018
10020
// Consider vectorizing the epilogue too if it's profitable.
10019
10021
VectorizationFactor EpilogueVF =
10020
- LVP.selectEpilogueVectorizationFactor (VF. Width , IC);
10022
+ LVP.selectEpilogueVectorizationFactor (BestVF , IC);
10021
10023
if (EpilogueVF.Width .isVector ()) {
10022
10024
10023
10025
// The first pass vectorizes the main loop and creates a scalar epilogue
10024
10026
// to be vectorized by executing the plan (potentially with a different
10025
10027
// factor) again shortly afterwards.
10026
- EpilogueLoopVectorizationInfo EPI (VF. Width , IC, EpilogueVF.Width , 1 );
10028
+ EpilogueLoopVectorizationInfo EPI (BestVF , IC, EpilogueVF.Width , 1 );
10027
10029
EpilogueVectorizerMainLoop MainILV (L, PSE, LI, DT, TLI, TTI, AC, ORE,
10028
10030
EPI, &LVL, &CM, BFI, PSI, Checks);
10029
10031
10030
10032
assert (EPI.MainLoopVF == VF.Width && " VFs must match" );
10031
- std::unique_ptr<VPlan> BestMainPlan (
10032
- LVP.getBestPlanFor (VF.Width ).duplicate ());
10033
+ std::unique_ptr<VPlan> BestMainPlan (BestPlan.duplicate ());
10033
10034
const auto &[ExpandedSCEVs, ReductionResumeValues] = LVP.executePlan (
10034
10035
EPI.MainLoopVF , EPI.MainLoopUF , *BestMainPlan, MainILV, DT, true );
10035
10036
++LoopsVectorized;
@@ -10120,18 +10121,10 @@ bool LoopVectorizePass::processLoop(Loop *L) {
10120
10121
if (!MainILV.areSafetyChecksAdded ())
10121
10122
DisableRuntimeUnroll = true ;
10122
10123
} else {
10123
- VPlan &BestPlan = LVP.getBestPlan ();
10124
- assert (size (BestPlan.vectorFactors ()) == 1 &&
10125
- " Plan should have a single VF" );
10126
- ElementCount Width = *BestPlan.vectorFactors ().begin ();
10127
- LLVM_DEBUG (dbgs () << " VF picked by VPlan cost model: " << Width
10128
- << " \n " );
10129
- assert (VF.Width == Width &&
10130
- " VPlan cost model and legacy cost model disagreed" );
10131
- InnerLoopVectorizer LB (L, PSE, LI, DT, TLI, TTI, AC, ORE, Width,
10124
+ InnerLoopVectorizer LB (L, PSE, LI, DT, TLI, TTI, AC, ORE, BestVF,
10132
10125
VF.MinProfitableTripCount , IC, &LVL, &CM, BFI,
10133
10126
PSI, Checks);
10134
- LVP.executePlan (Width , IC, BestPlan, LB, DT, false );
10127
+ LVP.executePlan (BestVF , IC, BestPlan, LB, DT, false );
10135
10128
++LoopsVectorized;
10136
10129
10137
10130
// Add metadata to disable runtime unrolling a scalar loop when there
0 commit comments