Skip to content

Commit 2bf601c

Browse files
committed
[LV] Strengthen calls to collectInstsToScalarize (NFC)
Avoid the pattern of always calling collectInstsToScalarize after collectUniformsAndScalars, and call it in collectUniformsAndScalars instead. Also strengthen checks for early exits in the function.
1 parent dd86ece commit 2bf601c

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

+10-15
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,6 @@ class LoopVectorizationCostModel {
10111011
/// \return true if the UserVF is a feasible VF to be chosen.
10121012
bool selectUserVectorizationFactor(ElementCount UserVF) {
10131013
collectUniformsAndScalars(UserVF);
1014-
collectInstsToScalarize(UserVF);
10151014
return expectedCost(UserVF).isValid();
10161015
}
10171016

@@ -1281,6 +1280,7 @@ class LoopVectorizationCostModel {
12811280
collectLoopUniforms(VF);
12821281
setVectorizedCallDecision(VF);
12831282
collectLoopScalars(VF);
1283+
collectInstsToScalarize(VF);
12841284
}
12851285

12861286
/// Returns true if the target machine supports masked store operation
@@ -5393,20 +5393,21 @@ bool LoopVectorizationCostModel::useEmulatedMaskMemRefHack(Instruction *I,
53935393
}
53945394

53955395
void LoopVectorizationCostModel::collectInstsToScalarize(ElementCount VF) {
5396-
// If we aren't vectorizing the loop, or if we've already collected the
5397-
// instructions to scalarize, there's nothing to do. Collection may already
5398-
// have occurred if we have a user-selected VF and are now computing the
5399-
// expected cost for interleaving.
5400-
if (VF.isScalar() || VF.isZero() || InstsToScalarize.contains(VF))
5396+
assert(VF.isVector() && "Expected VF >= 2");
5397+
5398+
// If we've already collected the instructions to scalarize or the predicated
5399+
// BBs after vectorization, there's nothing to do. Collection may already have
5400+
// occurred if we have a user-selected VF and are now computing the expected
5401+
// cost for interleaving.
5402+
if (InstsToScalarize.contains(VF) ||
5403+
PredicatedBBsAfterVectorization.contains(VF))
54015404
return;
54025405

54035406
// Initialize a mapping for VF in InstsToScalalarize. If we find that it's
54045407
// not profitable to scalarize any instructions, the presence of VF in the
54055408
// map will indicate that we've analyzed it already.
54065409
ScalarCostsTy &ScalarCostsVF = InstsToScalarize[VF];
54075410

5408-
PredicatedBBsAfterVectorization[VF].clear();
5409-
54105411
// Find all the instructions that are scalar with predication in the loop and
54115412
// determine if it would be better to not if-convert the blocks they are in.
54125413
// If so, we also record the instructions to scalarize.
@@ -7193,16 +7194,10 @@ void LoopVectorizationPlanner::plan(ElementCount UserVF, unsigned UserIC) {
71937194
VFCandidates.push_back(VF);
71947195

71957196
CM.collectInLoopReductions();
7196-
for (const auto &VF : VFCandidates) {
7197+
for (const auto &VF : VFCandidates)
71977198
// Collect Uniform and Scalar instructions after vectorization with VF.
71987199
CM.collectUniformsAndScalars(VF);
71997200

7200-
// Collect the instructions (and their associated costs) that will be more
7201-
// profitable to scalarize.
7202-
if (VF.isVector())
7203-
CM.collectInstsToScalarize(VF);
7204-
}
7205-
72067201
buildVPlansWithVPRecipes(ElementCount::getFixed(1), MaxFactors.FixedVF);
72077202
buildVPlansWithVPRecipes(ElementCount::getScalable(1), MaxFactors.ScalableVF);
72087203

0 commit comments

Comments
 (0)