@@ -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
@@ -10319,8 +10324,9 @@ bool LoopVectorizePass::processLoop(Loop *L) {
10319
10324
InnerLoopUnroller Unroller (L, PSE, LI, DT, TLI, TTI, AC, ORE, IC, &LVL,
10320
10325
&CM, BFI, PSI, Checks);
10321
10326
10322
- VPlan &BestPlan = LVP.getBestPlan ();
10323
- assert (BestPlan.hasScalarVFOnly () &&
10327
+ VPlan &BestPlan =
10328
+ UseLegacyCostModel ? LVP.getBestPlanFor (VF.Width ) : LVP.getBestPlan ();
10329
+ assert ((UseLegacyCostModel || BestPlan.hasScalarVFOnly ()) &&
10324
10330
" VPlan cost model and legacy cost model disagreed" );
10325
10331
LVP.executePlan (VF.Width , IC, BestPlan, Unroller, DT, false );
10326
10332
@@ -10437,14 +10443,18 @@ bool LoopVectorizePass::processLoop(Loop *L) {
10437
10443
if (!MainILV.areSafetyChecksAdded ())
10438
10444
DisableRuntimeUnroll = true ;
10439
10445
} else {
10440
- VPlan &BestPlan = LVP.getBestPlan ();
10441
- assert (size (BestPlan.vectorFactors ()) == 1 &&
10442
- " Plan should have a single VF" );
10443
- ElementCount Width = *BestPlan.vectorFactors ().begin ();
10444
- LLVM_DEBUG (dbgs () << " VF picked by VPlan cost model: " << Width
10445
- << " \n " );
10446
- assert (VF.Width == Width &&
10447
- " VPlan cost model and legacy cost model disagreed" );
10446
+ ElementCount Width = VF.Width ;
10447
+ VPlan &BestPlan =
10448
+ UseLegacyCostModel ? LVP.getBestPlanFor (Width) : LVP.getBestPlan ();
10449
+ if (!UseLegacyCostModel) {
10450
+ assert (size (BestPlan.vectorFactors ()) == 1 &&
10451
+ " Plan should have a single VF" );
10452
+ Width = *BestPlan.vectorFactors ().begin ();
10453
+ LLVM_DEBUG (dbgs ()
10454
+ << " VF picked by VPlan cost model: " << Width << " \n " );
10455
+ assert (VF.Width == Width &&
10456
+ " VPlan cost model and legacy cost model disagreed" );
10457
+ }
10448
10458
InnerLoopVectorizer LB (L, PSE, LI, DT, TLI, TTI, AC, ORE, Width,
10449
10459
VF.MinProfitableTripCount , IC, &LVL, &CM, BFI,
10450
10460
PSI, Checks);
0 commit comments