[llvm] 9ba5244 - [LV] Add option to still enable the legacy cost model. (#99536)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 19 10:48:19 PDT 2024
Author: Florian Hahn
Date: 2024-07-19T18:48:15+01:00
New Revision: 9ba524427321b931bad156860755adf420aeec6a
URL: https://github.com/llvm/llvm-project/commit/9ba524427321b931bad156860755adf420aeec6a
DIFF: https://github.com/llvm/llvm-project/commit/9ba524427321b931bad156860755adf420aeec6a.diff
LOG: [LV] Add option to still enable the legacy cost model. (#99536)
This patch adds a new temporary option to still use the legacy cost
model after https://github.com/llvm/llvm-project/pull/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: https://github.com/llvm/llvm-project/pull/99536
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index cceed75aa50b0..ff60bd894cd40 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -205,6 +205,11 @@ static cl::opt<unsigned> VectorizeMemoryCheckThreshold(
"vectorize-memory-check-threshold", cl::init(128), cl::Hidden,
cl::desc("The maximum allowed number of runtime memory checks"));
+static cl::opt<bool> UseLegacyCostModel(
+ "vectorize-use-legacy-cost-model", cl::init(false), cl::Hidden,
+ cl::desc("Use the legacy cost model instead of the VPlan-based cost model. "
+ "This option will be removed in the future."));
+
// Option prefer-predicate-over-epilogue indicates that an epilogue is undesired,
// that predication is preferred, and this lists all options. I.e., the
// vectorizer will try to fold the tail-loop (epilogue) into the vector body
@@ -10319,8 +10324,9 @@ bool LoopVectorizePass::processLoop(Loop *L) {
InnerLoopUnroller Unroller(L, PSE, LI, DT, TLI, TTI, AC, ORE, IC, &LVL,
&CM, BFI, PSI, Checks);
- VPlan &BestPlan = LVP.getBestPlan();
- assert(BestPlan.hasScalarVFOnly() &&
+ VPlan &BestPlan =
+ UseLegacyCostModel ? LVP.getBestPlanFor(VF.Width) : LVP.getBestPlan();
+ assert((UseLegacyCostModel || BestPlan.hasScalarVFOnly()) &&
"VPlan cost model and legacy cost model disagreed");
LVP.executePlan(VF.Width, IC, BestPlan, Unroller, DT, false);
@@ -10437,14 +10443,18 @@ bool LoopVectorizePass::processLoop(Loop *L) {
if (!MainILV.areSafetyChecksAdded())
DisableRuntimeUnroll = true;
} else {
- VPlan &BestPlan = LVP.getBestPlan();
- assert(size(BestPlan.vectorFactors()) == 1 &&
- "Plan should have a single VF");
- ElementCount Width = *BestPlan.vectorFactors().begin();
- LLVM_DEBUG(dbgs() << "VF picked by VPlan cost model: " << Width
- << "\n");
- assert(VF.Width == Width &&
- "VPlan cost model and legacy cost model disagreed");
+ ElementCount Width = VF.Width;
+ VPlan &BestPlan =
+ UseLegacyCostModel ? LVP.getBestPlanFor(Width) : LVP.getBestPlan();
+ if (!UseLegacyCostModel) {
+ assert(size(BestPlan.vectorFactors()) == 1 &&
+ "Plan should have a single VF");
+ Width = *BestPlan.vectorFactors().begin();
+ LLVM_DEBUG(dbgs()
+ << "VF picked by VPlan cost model: " << Width << "\n");
+ assert(VF.Width == Width &&
+ "VPlan cost model and legacy cost model disagreed");
+ }
InnerLoopVectorizer LB(L, PSE, LI, DT, TLI, TTI, AC, ORE, Width,
VF.MinProfitableTripCount, IC, &LVL, &CM, BFI,
PSI, Checks);
More information about the llvm-commits
mailing list