@@ -205,6 +205,11 @@ static cl::opt<unsigned> VectorizeMemoryCheckThreshold(
205
205
" vectorize-memory-check-threshold" , cl::init(128 ), cl::Hidden,
206
206
cl::desc(" The maximum allowed number of runtime memory checks" ));
207
207
208
+ static cl::opt<bool > UseLegacyCostModel (
209
+ " vectorize-use-legacy-cost-model" , cl::init(false ), cl::Hidden,
210
+ cl::desc(" Use the legacy cost model instead of the VPlan-based cost model. "
211
+ " This option will be removed in the future." ));
212
+
208
213
// Option prefer-predicate-over-epilogue indicates that an epilogue is undesired,
209
214
// that predication is preferred, and this lists all options. I.e., the
210
215
// vectorizer will try to fold the tail-loop (epilogue) into the vector body
@@ -10318,8 +10323,9 @@ bool LoopVectorizePass::processLoop(Loop *L) {
10318
10323
InnerLoopUnroller Unroller (L, PSE, LI, DT, TLI, TTI, AC, ORE, IC, &LVL,
10319
10324
&CM, BFI, PSI, Checks);
10320
10325
10321
- VPlan &BestPlan = LVP.getBestPlan ();
10322
- assert (BestPlan.hasScalarVFOnly () &&
10326
+ VPlan &BestPlan =
10327
+ UseLegacyCostModel ? LVP.getBestPlanFor (VF.Width ) : LVP.getBestPlan ();
10328
+ assert ((UseLegacyCostModel || BestPlan.hasScalarVFOnly ()) &&
10323
10329
" VPlan cost model and legacy cost model disagreed" );
10324
10330
LVP.executePlan (VF.Width , IC, BestPlan, Unroller, DT, false );
10325
10331
@@ -10436,14 +10442,18 @@ bool LoopVectorizePass::processLoop(Loop *L) {
10436
10442
if (!MainILV.areSafetyChecksAdded ())
10437
10443
DisableRuntimeUnroll = true ;
10438
10444
} else {
10439
- VPlan &BestPlan = LVP.getBestPlan ();
10440
- assert (size (BestPlan.vectorFactors ()) == 1 &&
10441
- " Plan should have a single VF" );
10442
- ElementCount Width = *BestPlan.vectorFactors ().begin ();
10443
- LLVM_DEBUG (dbgs () << " VF picked by VPlan cost model: " << Width
10444
- << " \n " );
10445
- assert (VF.Width == Width &&
10446
- " VPlan cost model and legacy cost model disagreed" );
10445
+ ElementCount Width = VF.Width ;
10446
+ VPlan &BestPlan =
10447
+ UseLegacyCostModel ? LVP.getBestPlanFor (Width) : LVP.getBestPlan ();
10448
+ if (!UseLegacyCostModel) {
10449
+ assert (size (BestPlan.vectorFactors ()) == 1 &&
10450
+ " Plan should have a single VF" );
10451
+ Width = *BestPlan.vectorFactors ().begin ();
10452
+ LLVM_DEBUG (dbgs ()
10453
+ << " VF picked by VPlan cost model: " << Width << " \n " );
10454
+ assert (VF.Width == Width &&
10455
+ " VPlan cost model and legacy cost model disagreed" );
10456
+ }
10447
10457
InnerLoopVectorizer LB (L, PSE, LI, DT, TLI, TTI, AC, ORE, Width,
10448
10458
VF.MinProfitableTripCount , IC, &LVL, &CM, BFI,
10449
10459
PSI, Checks);
0 commit comments