Skip to content

Commit 9ba5244

Browse files
authored
[LV] Add option to still enable the legacy cost model. (llvm#99536)
This patch adds a new temporary option to still use the legacy cost model after llvm#92555. It defaults to false and the only intended use is to adjust the default to true in the soon-to-be-cut release branch. PR: llvm#99536
1 parent 2f8b64d commit 9ba5244

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ static cl::opt<unsigned> VectorizeMemoryCheckThreshold(
205205
"vectorize-memory-check-threshold", cl::init(128), cl::Hidden,
206206
cl::desc("The maximum allowed number of runtime memory checks"));
207207

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+
208213
// Option prefer-predicate-over-epilogue indicates that an epilogue is undesired,
209214
// that predication is preferred, and this lists all options. I.e., the
210215
// vectorizer will try to fold the tail-loop (epilogue) into the vector body
@@ -10319,8 +10324,9 @@ bool LoopVectorizePass::processLoop(Loop *L) {
1031910324
InnerLoopUnroller Unroller(L, PSE, LI, DT, TLI, TTI, AC, ORE, IC, &LVL,
1032010325
&CM, BFI, PSI, Checks);
1032110326

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()) &&
1032410330
"VPlan cost model and legacy cost model disagreed");
1032510331
LVP.executePlan(VF.Width, IC, BestPlan, Unroller, DT, false);
1032610332

@@ -10437,14 +10443,18 @@ bool LoopVectorizePass::processLoop(Loop *L) {
1043710443
if (!MainILV.areSafetyChecksAdded())
1043810444
DisableRuntimeUnroll = true;
1043910445
} 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+
}
1044810458
InnerLoopVectorizer LB(L, PSE, LI, DT, TLI, TTI, AC, ORE, Width,
1044910459
VF.MinProfitableTripCount, IC, &LVL, &CM, BFI,
1045010460
PSI, Checks);

0 commit comments

Comments
 (0)