[PATCH] D105437: [LV] Collect a list of all element types found in the loop (NFC)
Kerry McLaughlin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 5 09:49:38 PDT 2021
kmclaughlin created this revision.
kmclaughlin added reviewers: sdesmalen, david-arm, CarolineConcatto.
Herald added a subscriber: hiraditya.
kmclaughlin requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Splits `getSmallestAndWidestTypes` into two functions, one of which now collects
a list of all element types found in the loop (`ElementTypesInLoop`). This ensures we do not
have to iterate over all instructions in the loop again in other places, such as in D102253 <https://reviews.llvm.org/D102253>
which disables scalable vectorization of a loop if any of the instructions use invalid types.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D105437
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
@@ -1305,6 +1305,9 @@
/// Collect values we want to ignore in the cost model.
void collectValuesToIgnore();
+ /// Collect all element types in the loop for which widening is needed.
+ void collectAllElementTypesInLoop();
+
/// Split reductions into those that happen in the loop, and those that happen
/// outside. In loop reductions are collected into InLoopReductionChains.
void collectInLoopReductions();
@@ -1890,6 +1893,9 @@
/// Values to ignore in the cost model when VF > 1.
SmallPtrSet<const Value *, 16> VecValuesToIgnore;
+ /// All element types found in the loop.
+ SmallPtrSet<Type *, 16> ElementTypesInLoop;
+
/// Profitable vector factors.
SmallVector<VectorizationFactor, 8> ProfitableVFs;
};
@@ -6246,7 +6252,19 @@
unsigned MinWidth = -1U;
unsigned MaxWidth = 8;
const DataLayout &DL = TheFunction->getParent()->getDataLayout();
+ for (Type *T : ElementTypesInLoop) {
+ MinWidth = std::min<unsigned>(
+ MinWidth, DL.getTypeSizeInBits(T->getScalarType()).getFixedSize());
+ MaxWidth = std::max<unsigned>(
+ MaxWidth, DL.getTypeSizeInBits(T->getScalarType()).getFixedSize());
+ }
+ return {MinWidth, MaxWidth};
+}
+
+
+void LoopVectorizationCostModel::collectAllElementTypesInLoop() {
+ ElementTypesInLoop.clear();
// For each block.
for (BasicBlock *BB : TheLoop->blocks()) {
// For each instruction in the loop.
@@ -6292,14 +6310,9 @@
!isAccessInterleaved(&I) && !isLegalGatherOrScatter(&I))
continue;
- MinWidth = std::min(MinWidth,
- (unsigned)DL.getTypeSizeInBits(T->getScalarType()));
- MaxWidth = std::max(MaxWidth,
- (unsigned)DL.getTypeSizeInBits(T->getScalarType()));
+ ElementTypesInLoop.insert(T);
}
}
-
- return {MinWidth, MaxWidth};
}
unsigned LoopVectorizationCostModel::selectInterleaveCount(ElementCount VF,
@@ -9840,6 +9853,8 @@
// Get user vectorization factor.
ElementCount UserVF = Hints.getWidth();
+ CM.collectAllElementTypesInLoop();
+
// Plan how to best vectorize, return the best VF and its cost.
const VectorizationFactor VF = LVP.planInVPlanNativePath(UserVF);
@@ -10061,6 +10076,7 @@
LoopVectorizationCostModel CM(SEL, L, PSE, LI, &LVL, *TTI, TLI, DB, AC, ORE,
F, &Hints, IAI);
CM.collectValuesToIgnore();
+ CM.collectAllElementTypesInLoop();
// Use the planner for vectorization.
LoopVectorizationPlanner LVP(L, LI, TLI, TTI, &LVL, CM, IAI, PSE, Hints,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105437.356521.patch
Type: text/x-patch
Size: 2772 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210705/b83e3346/attachment.bin>
More information about the llvm-commits
mailing list