[PATCH] D96019: [LoopVectorize] NFC: Change selectVectorizationFactor to work on ElementCount.
Sander de Smalen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 4 04:58:09 PST 2021
sdesmalen created this revision.
sdesmalen added reviewers: dmgreen, fhahn, gilr, david-arm.
Herald added a subscriber: hiraditya.
sdesmalen requested review of this revision.
Herald added a project: LLVM.
This patch is NFC and changes occurrences of `unsigned Width`
and `unsigned i` to work on type ElementCount instead.
This patch is a preparatory patch with the ultimate goal of making
`computeMaxVF()` return both a max fixed VF and a max scalable VF,
so that `selectVectorizationFactor()` can pick the most cost-effective
vectorization factor.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D96019
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
@@ -5792,7 +5792,7 @@
LLVM_DEBUG(dbgs() << "LV: Scalar loop costs: " << ExpectedCost << ".\n");
assert(ExpectedCost.isValid() && "Unexpected invalid cost for scalar loop");
- unsigned Width = 1;
+ auto Width = ElementCount::getFixed(1);
const float ScalarCost = *ExpectedCost.getValue();
float Cost = ScalarCost;
@@ -5804,13 +5804,14 @@
Cost = std::numeric_limits<float>::max();
}
- for (unsigned i = 2; i <= MaxVF.getFixedValue(); i *= 2) {
+ for (auto i = ElementCount::getFixed(2); ElementCount::isKnownLE(i, MaxVF);
+ i *= 2) {
// Notice that the vector loop needs to be executed less times, so
// we need to divide the cost of the vector loops by the width of
// the vector elements.
- VectorizationCostTy C = expectedCost(ElementCount::getFixed(i));
+ VectorizationCostTy C = expectedCost(i);
assert(C.first.isValid() && "Unexpected invalid cost for vector loop");
- float VectorCost = *C.first.getValue() / (float)i;
+ float VectorCost = *C.first.getValue() / (float)i.getKnownMinValue();
LLVM_DEBUG(dbgs() << "LV: Vector loop of width " << i
<< " costs: " << (int)VectorCost << ".\n");
if (!C.second && !ForceVectorization) {
@@ -5823,7 +5824,7 @@
// If profitable add it to ProfitableVF list.
if (VectorCost < ScalarCost) {
ProfitableVFs.push_back(VectorizationFactor(
- {ElementCount::getFixed(i), (unsigned)VectorCost}));
+ {i, (unsigned)VectorCost}));
}
if (VectorCost < Cost) {
@@ -5836,16 +5837,16 @@
reportVectorizationFailure("There are conditional stores.",
"store that is conditionally executed prevents vectorization",
"ConditionalStore", ORE, TheLoop);
- Width = 1;
+ Width = ElementCount::getFixed(1);
Cost = ScalarCost;
}
- LLVM_DEBUG(if (ForceVectorization && Width > 1 && Cost >= ScalarCost) dbgs()
+ LLVM_DEBUG(if (ForceVectorization && !Width.isScalar() && Cost >= ScalarCost) dbgs()
<< "LV: Vectorization seems to be not beneficial, "
<< "but was forced by a user.\n");
LLVM_DEBUG(dbgs() << "LV: Selecting VF: " << Width << ".\n");
- VectorizationFactor Factor = {ElementCount::getFixed(Width),
- (unsigned)(Width * Cost)};
+ VectorizationFactor Factor = {Width,
+ (unsigned)(Width.getKnownMinValue() * Cost)};
return Factor;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96019.321388.patch
Type: text/x-patch
Size: 2672 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210204/caf01299/attachment.bin>
More information about the llvm-commits
mailing list