@@ -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