Skip to content

Commit 7b3ec51

Browse files
authored
[VPlan] Consolidate logic for narrowToSingleScalars (NFCI) (#167360)
The logic for narrowing to single scalar recipes is in two different places: narrowToSingleScalarRecipes and legalizeAndOptimizeInductions. Consolidate them.
1 parent 562d911 commit 7b3ec51

File tree

1 file changed

+5
-27
lines changed

1 file changed

+5
-27
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -757,31 +757,6 @@ static void legalizeAndOptimizeInductions(VPlan &Plan) {
757757
if (!PhiR)
758758
continue;
759759

760-
// Try to narrow wide and replicating recipes to uniform recipes, based on
761-
// VPlan analysis.
762-
// TODO: Apply to all recipes in the future, to replace legacy uniformity
763-
// analysis.
764-
auto Users = collectUsersRecursively(PhiR);
765-
for (VPUser *U : reverse(Users)) {
766-
auto *Def = dyn_cast<VPRecipeWithIRFlags>(U);
767-
auto *RepR = dyn_cast<VPReplicateRecipe>(U);
768-
// Skip recipes that shouldn't be narrowed.
769-
if (!Def || !isa<VPReplicateRecipe, VPWidenRecipe>(Def) ||
770-
Def->getNumUsers() == 0 || !Def->getUnderlyingValue() ||
771-
(RepR && (RepR->isSingleScalar() || RepR->isPredicated())))
772-
continue;
773-
774-
// Skip recipes that may have other lanes than their first used.
775-
if (!vputils::isSingleScalar(Def) && !vputils::onlyFirstLaneUsed(Def))
776-
continue;
777-
778-
auto *Clone = new VPReplicateRecipe(Def->getUnderlyingInstr(),
779-
Def->operands(), /*IsUniform*/ true,
780-
/*Mask*/ nullptr, /*Flags*/ *Def);
781-
Clone->insertAfter(Def);
782-
Def->replaceAllUsesWith(Clone);
783-
}
784-
785760
// Replace wide pointer inductions which have only their scalars used by
786761
// PtrAdd(IndStart, ScalarIVSteps (0, Step)).
787762
if (auto *PtrIV = dyn_cast<VPWidenPointerInductionRecipe>(&Phi)) {
@@ -1546,8 +1521,11 @@ static void narrowToSingleScalarRecipes(VPlan &Plan) {
15461521
continue;
15471522
}
15481523

1549-
// Skip recipes that aren't single scalars.
1550-
if (!vputils::isSingleScalar(RepOrWidenR))
1524+
// Skip recipes that aren't single scalars and don't just have their first
1525+
// lane used.
1526+
if (!vputils::isSingleScalar(RepOrWidenR) &&
1527+
(!vputils::onlyFirstLaneUsed(RepOrWidenR) ||
1528+
RepOrWidenR->getNumUsers() == 0))
15511529
continue;
15521530

15531531
// Skip recipes for which conversion to single-scalar does introduce

0 commit comments

Comments
 (0)