[PATCH] D147468: [VPlan] Add VFRange::begin() and end() iterators. (NFCI)
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 3 13:41:07 PDT 2023
fhahn created this revision.
fhahn added reviewers: Ayal, gilr, rengolin.
Herald added subscribers: StephenFan, tschuett, psnobl, rogfer01, bollu, hiraditya.
Herald added a project: All.
fhahn requested review of this revision.
Herald added subscribers: pcwang-thead, vkmr.
Herald added a project: LLVM.
Add an iterator to iterate over all VFs in VFRange. This simplifies some
existing code and allows using all_of,any_of and none_of on a VFRange.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D147468
Files:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/lib/Transforms/Vectorize/VPlan.h
Index: llvm/lib/Transforms/Vectorize/VPlan.h
===================================================================
--- llvm/lib/Transforms/Vectorize/VPlan.h
+++ llvm/lib/Transforms/Vectorize/VPlan.h
@@ -99,6 +99,35 @@
assert(isPowerOf2_32(Start.getKnownMinValue()) &&
"Expected Start to be a power of 2");
}
+
+ /// Iterator to iterate over vectorization factors in a VFRange.
+ class iterator
+ : public iterator_facade_base<iterator, std::forward_iterator_tag,
+ ElementCount> {
+ ElementCount VF;
+
+ public:
+ iterator(ElementCount VF) : VF(VF) {}
+
+ bool operator==(const iterator &Other) const { return VF == Other.VF; }
+
+ ElementCount operator*() const { return VF; }
+
+ iterator &operator++() {
+ VF *= 2;
+ return *this;
+ }
+ };
+
+ 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);
+ }
};
using VPlanPtr = std::unique_ptr<VPlan>;
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8049,8 +8049,7 @@
assert(!Range.isEmpty() && "Trying to test an empty VF range.");
bool PredicateAtRangeStart = Predicate(Range.Start);
- for (ElementCount TmpVF = Range.Start * 2;
- ElementCount::isKnownLT(TmpVF, Range.End); TmpVF *= 2)
+ for (ElementCount TmpVF : VFRange(Range.Start * 2, Range.End))
if (Predicate(TmpVF) != PredicateAtRangeStart) {
Range.End = TmpVF;
break;
@@ -8896,9 +8895,9 @@
// so this function is better to be conservative, rather than to split
// it up into different VPlans.
bool IVUpdateMayOverflow = false;
- for (ElementCount VF = Range.Start;
- ElementCount::isKnownLT(VF, Range.End); VF *= 2)
+ for (ElementCount VF : Range) {
IVUpdateMayOverflow |= !isIndvarOverflowCheckKnownFalse(&CM, VF);
+ }
Instruction *DLInst =
getDebugLocFromInstOrOperands(Legal->getPrimaryInduction());
@@ -9041,9 +9040,9 @@
}
}
- for (ElementCount VF = Range.Start; ElementCount::isKnownLT(VF, Range.End);
- VF *= 2)
+ for (ElementCount VF : Range) {
Plan->addVF(VF);
+ }
Plan->setName("Initial VPlan");
// From this point onwards, VPlan-to-VPlan transformations may change the plan
@@ -9077,9 +9076,9 @@
VPlanHCFGBuilder HCFGBuilder(OrigLoop, LI, *Plan);
HCFGBuilder.buildHierarchicalCFG();
- for (ElementCount VF = Range.Start; ElementCount::isKnownLT(VF, Range.End);
- VF *= 2)
+ for (ElementCount VF : Range) {
Plan->addVF(VF);
+ }
SmallPtrSet<Instruction *, 1> DeadInstructions;
VPlanTransforms::VPInstructionsToVPRecipes(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147468.510592.patch
Type: text/x-patch
Size: 3088 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230403/cde5ffa2/attachment.bin>
More information about the llvm-commits
mailing list