[llvm] c7a34d3 - [VPlan] Require VFRange.End to be a power-of-2. (NFCI)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 8 05:05:01 PDT 2023
Author: Florian Hahn
Date: 2023-04-08T13:04:08+01:00
New Revision: c7a34d355a61396d438ea095e1e6996cde1ef880
URL: https://github.com/llvm/llvm-project/commit/c7a34d355a61396d438ea095e1e6996cde1ef880
DIFF: https://github.com/llvm/llvm-project/commit/c7a34d355a61396d438ea095e1e6996cde1ef880.diff
LOG: [VPlan] Require VFRange.End to be a power-of-2. (NFCI)
This removes the need to convert the end of the range to the next
power-of-2 for the end iterator after 4bd3fda5124962 and was suggested
as follow-up TODO in D147468.
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/lib/Transforms/Vectorize/VPlan.h
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 914fc4e1ccee..1d6dfdd49279 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8067,9 +8067,9 @@ bool LoopVectorizationPlanner::getDecisionAndClampRange(
/// buildVPlan().
void LoopVectorizationPlanner::buildVPlans(ElementCount MinVF,
ElementCount MaxVF) {
- auto MaxVFPlusOne = MaxVF.getWithIncrement(1);
- for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFPlusOne);) {
- VFRange SubRange = {VF, MaxVFPlusOne};
+ auto MaxVFTimes2 = MaxVF * 2;
+ for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFTimes2);) {
+ VFRange SubRange = {VF, MaxVFTimes2};
VPlans.push_back(buildVPlan(SubRange));
VF = SubRange.End;
}
@@ -8700,9 +8700,9 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
auto &ConditionalAssumes = Legal->getConditionalAssumes();
DeadInstructions.insert(ConditionalAssumes.begin(), ConditionalAssumes.end());
- auto MaxVFPlusOne = MaxVF.getWithIncrement(1);
- for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFPlusOne);) {
- VFRange SubRange = {VF, MaxVFPlusOne};
+ auto MaxVFTimes2 = MaxVF * 2;
+ for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFTimes2);) {
+ VFRange SubRange = {VF, MaxVFTimes2};
VPlans.push_back(buildVPlanWithVPRecipes(SubRange, DeadInstructions));
VF = SubRange.End;
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index e49ac0aaaf6f..b344fd1c98f0 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -80,12 +80,12 @@ const SCEV *createTripCountSCEV(Type *IdxTy, PredicatedScalarEvolution &PSE);
/// A range of powers-of-2 vectorization factors with fixed start and
/// adjustable end. The range includes start and excludes end, e.g.,:
-/// [1, 9) = {1, 2, 4, 8}
+/// [1, 16) = {1, 2, 4, 8}
struct VFRange {
// A power of 2.
const ElementCount Start;
- // Need not be a power of 2. If End <= Start range is empty.
+ // A power of 2. If End <= Start range is empty.
ElementCount End;
bool isEmpty() const {
@@ -98,6 +98,8 @@ struct VFRange {
"Both Start and End should have the same scalable flag");
assert(isPowerOf2_32(Start.getKnownMinValue()) &&
"Expected Start to be a power of 2");
+ assert(isPowerOf2_32(End.getKnownMinValue()) &&
+ "Expected End to be a power of 2");
}
/// Iterator to iterate over vectorization factors in a VFRange.
@@ -121,13 +123,8 @@ struct VFRange {
iterator begin() { return iterator(Start); }
iterator end() {
- ElementCount EndVF = End;
- // Make sure the end iterator is a power-of-2 so != comparisons with end
- // work as expected.
- if (!isPowerOf2_64(End.getKnownMinValue()))
- EndVF = ElementCount::get(NextPowerOf2(End.getKnownMinValue()),
- End.isScalable());
- return iterator(EndVF);
+ assert(isPowerOf2_32(End.getKnownMinValue()));
+ return iterator(End);
}
};
More information about the llvm-commits
mailing list