[PATCH] D109679: [LV][NFC] Optimize out an extra call to isMoreProfitable
Evgeniy via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 13 03:01:38 PDT 2021
ebrevnov created this revision.
Herald added a subscriber: hiraditya.
ebrevnov requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D109679
Files:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -1915,7 +1915,7 @@
SmallPtrSet<Type *, 16> ElementTypesInLoop;
/// Profitable vector factors.
- SmallVector<VectorizationFactor, 8> ProfitableVFs;
+ SmallVector<VectorizationFactor, 8> CachedVFs;
/// Cached cost of one scalar iteraton;
VectorizationFactor ScalarVF = {ElementCount::getFixed(1),
@@ -6108,9 +6108,9 @@
continue;
}
- // If profitable add it to ProfitableVF list.
- if (isMoreProfitable(Candidate, getScalarVF()))
- ProfitableVFs.push_back(Candidate);
+ // Cache calculated cost of the candidate since it will be needed again
+ // during epilogue vectorization cost modeling.
+ CachedVFs.push_back(Candidate);
if (isMoreProfitable(Candidate, ChosenFactor))
ChosenFactor = Candidate;
@@ -6250,7 +6250,7 @@
VectorizationFactor
LoopVectorizationCostModel::selectEpilogueVectorizationFactor(
const ElementCount MainLoopVF, const LoopVectorizationPlanner &LVP) {
- VectorizationFactor Result = VectorizationFactor::Disabled();
+ VectorizationFactor Result = getScalarVF();
if (!EnableEpilogueVectorization) {
LLVM_DEBUG(dbgs() << "LEV: Epilogue vectorization is disabled.\n";);
return Result;
@@ -6305,12 +6305,14 @@
if (!isEpilogueVectorizationProfitable(MainLoopVF))
return Result;
- for (auto &NextVF : ProfitableVFs)
+ for (auto &NextVF : CachedVFs) {
+ if (NextVF.Width.isScalar())
+ continue;
if (ElementCount::isKnownLT(NextVF.Width, MainLoopVF) &&
- (Result.Width.getFixedValue() == 1 ||
- isMoreProfitable(NextVF, Result)) &&
+ isMoreProfitable(NextVF, Result) &&
LVP.hasPlanWithVFs({MainLoopVF, NextVF.Width}))
Result = NextVF;
+ }
if (Result != VectorizationFactor::Disabled())
LLVM_DEBUG(dbgs() << "LEV: Vectorizing epilogue loop with VF = "
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109679.372197.patch
Type: text/x-patch
Size: 2054 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210913/a9c54989/attachment.bin>
More information about the llvm-commits
mailing list