Skip to content

Commit 2159447

Browse files
committed
[VPlan] Consolidate logic for narrowToSingleScalars (NFCI)
The logic for narrowing to single scalar recipes is in two different places: narrowToSingleScalarRecipes and legalizeAndOptimizeInductions. Consolidate them.
1 parent 3ca85e7 commit 2159447

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
@@ -741,31 +741,6 @@ static void legalizeAndOptimizeInductions(VPlan &Plan) {
741741
if (!PhiR)
742742
continue;
743743

744-
// Try to narrow wide and replicating recipes to uniform recipes, based on
745-
// VPlan analysis.
746-
// TODO: Apply to all recipes in the future, to replace legacy uniformity
747-
// analysis.
748-
auto Users = collectUsersRecursively(PhiR);
749-
for (VPUser *U : reverse(Users)) {
750-
auto *Def = dyn_cast<VPRecipeWithIRFlags>(U);
751-
auto *RepR = dyn_cast<VPReplicateRecipe>(U);
752-
// Skip recipes that shouldn't be narrowed.
753-
if (!Def || !isa<VPReplicateRecipe, VPWidenRecipe>(Def) ||
754-
Def->getNumUsers() == 0 || !Def->getUnderlyingValue() ||
755-
(RepR && (RepR->isSingleScalar() || RepR->isPredicated())))
756-
continue;
757-
758-
// Skip recipes that may have other lanes than their first used.
759-
if (!vputils::isSingleScalar(Def) && !vputils::onlyFirstLaneUsed(Def))
760-
continue;
761-
762-
auto *Clone = new VPReplicateRecipe(Def->getUnderlyingInstr(),
763-
Def->operands(), /*IsUniform*/ true,
764-
/*Mask*/ nullptr, /*Flags*/ *Def);
765-
Clone->insertAfter(Def);
766-
Def->replaceAllUsesWith(Clone);
767-
}
768-
769744
// Replace wide pointer inductions which have only their scalars used by
770745
// PtrAdd(IndStart, ScalarIVSteps (0, Step)).
771746
if (auto *PtrIV = dyn_cast<VPWidenPointerInductionRecipe>(&Phi)) {
@@ -1530,8 +1505,11 @@ static void narrowToSingleScalarRecipes(VPlan &Plan) {
15301505
continue;
15311506
}
15321507

1533-
// Skip recipes that aren't single scalars.
1534-
if (!vputils::isSingleScalar(RepOrWidenR))
1508+
// Skip recipes that aren't single scalars and don't just have their first
1509+
// lane used.
1510+
if ((!vputils::isSingleScalar(RepOrWidenR) &&
1511+
!vputils::onlyFirstLaneUsed(RepOrWidenR)) ||
1512+
RepOrWidenR->getNumUsers() == 0)
15351513
continue;
15361514

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

0 commit comments

Comments
 (0)