[llvm] be9bbb5 - [LoopVectorize] NFC: Change selectVectorizationFactor to work on ElementCount.
Sander de Smalen via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 11 00:48:29 PST 2021
Author: Sander de Smalen
Date: 2021-02-11T08:47:59Z
New Revision: be9bbb57f4739e4653cee77979f6fb72310176c0
URL: https://github.com/llvm/llvm-project/commit/be9bbb57f4739e4653cee77979f6fb72310176c0
DIFF: https://github.com/llvm/llvm-project/commit/be9bbb57f4739e4653cee77979f6fb72310176c0.diff
LOG: [LoopVectorize] NFC: Change selectVectorizationFactor to work on ElementCount.
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.
Reviewed By: david-arm
Differential Revision: https://reviews.llvm.org/D96019
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 8fb4196288ba..71b626e8683f 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -5834,7 +5834,7 @@ LoopVectorizationCostModel::selectVectorizationFactor(ElementCount MaxVF) {
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;
@@ -5846,13 +5846,14 @@ LoopVectorizationCostModel::selectVectorizationFactor(ElementCount MaxVF) {
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.getFixedValue();
LLVM_DEBUG(dbgs() << "LV: Vector loop of width " << i
<< " costs: " << (int)VectorCost << ".\n");
if (!C.second && !ForceVectorization) {
@@ -5865,7 +5866,7 @@ LoopVectorizationCostModel::selectVectorizationFactor(ElementCount MaxVF) {
// 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) {
@@ -5878,16 +5879,16 @@ LoopVectorizationCostModel::selectVectorizationFactor(ElementCount MaxVF) {
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;
}
More information about the llvm-commits
mailing list