Skip to content

Commit 7024cec

Browse files
committed
[LV] Collect profitable VFs in ::getBestVF. (NFCI)
Move collectig profitable VFs to ::getBestVF, in preparation for retiring selectVectorizationFactor.
1 parent 4589bf9 commit 7024cec

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,9 @@ class LoopVectorizationPlanner {
365365
/// Return the best VPlan for \p VF.
366366
VPlan &getBestPlanFor(ElementCount VF) const;
367367

368-
/// Return the most profitable vectorization factor.
369-
ElementCount getBestVF() const;
368+
/// Return the most profitable vectorization factor. Also collect all
369+
/// profitable VFs in ProfitableVFs.
370+
ElementCount getBestVF();
370371

371372
/// Generate the IR code for the vectorized loop captured in VPlan \p BestPlan
372373
/// according to the best selected \p VF and \p UF.

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4606,10 +4606,6 @@ VectorizationFactor LoopVectorizationPlanner::selectVectorizationFactor() {
46064606
continue;
46074607
}
46084608

4609-
// If profitable add it to ProfitableVF list.
4610-
if (isMoreProfitable(Candidate, ScalarCost))
4611-
ProfitableVFs.push_back(Candidate);
4612-
46134609
if (isMoreProfitable(Candidate, ChosenFactor))
46144610
ChosenFactor = Candidate;
46154611
}
@@ -7200,7 +7196,7 @@ InstructionCost LoopVectorizationPlanner::cost(VPlan &Plan,
72007196
return Cost;
72017197
}
72027198

7203-
ElementCount LoopVectorizationPlanner::getBestVF() const {
7199+
ElementCount LoopVectorizationPlanner::getBestVF() {
72047200
// If there is a single VPlan with a single VF, return it directly.
72057201
VPlan &FirstPlan = *VPlans[0];
72067202
if (VPlans.size() == 1 && size(FirstPlan.vectorFactors()) == 1)
@@ -7212,7 +7208,8 @@ ElementCount LoopVectorizationPlanner::getBestVF() const {
72127208

72137209
// TODO: Compute scalar cost using VPlan-based cost model.
72147210
InstructionCost ScalarCost = CM.expectedCost(ScalarVF);
7215-
VectorizationFactor BestFactor(ScalarVF, ScalarCost, ScalarCost);
7211+
VectorizationFactor ScalarFactor(ScalarVF, ScalarCost, ScalarCost);
7212+
VectorizationFactor BestFactor = ScalarFactor;
72167213

72177214
bool ForceVectorization = Hints.getForce() == LoopVectorizeHints::FK_Enabled;
72187215
if (ForceVectorization) {
@@ -7238,6 +7235,10 @@ ElementCount LoopVectorizationPlanner::getBestVF() const {
72387235
VectorizationFactor CurrentFactor(VF, Cost, ScalarCost);
72397236
if (isMoreProfitable(CurrentFactor, BestFactor))
72407237
BestFactor = CurrentFactor;
7238+
7239+
// If profitable add it to ProfitableVF list.
7240+
if (isMoreProfitable(CurrentFactor, ScalarFactor))
7241+
ProfitableVFs.push_back(CurrentFactor);
72417242
}
72427243
}
72437244
return BestFactor.Width;

0 commit comments

Comments
 (0)