Skip to content

Commit d9a0a63

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

File tree

1 file changed

+3
-26
lines changed

1 file changed

+3
-26
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -689,31 +689,6 @@ static void legalizeAndOptimizeInductions(VPlan &Plan) {
689689
if (!PhiR)
690690
continue;
691691

692-
// Try to narrow wide and replicating recipes to uniform recipes, based on
693-
// VPlan analysis.
694-
// TODO: Apply to all recipes in the future, to replace legacy uniformity
695-
// analysis.
696-
auto Users = collectUsersRecursively(PhiR);
697-
for (VPUser *U : reverse(Users)) {
698-
auto *Def = dyn_cast<VPRecipeWithIRFlags>(U);
699-
auto *RepR = dyn_cast<VPReplicateRecipe>(U);
700-
// Skip recipes that shouldn't be narrowed.
701-
if (!Def || !isa<VPReplicateRecipe, VPWidenRecipe>(Def) ||
702-
Def->getNumUsers() == 0 || !Def->getUnderlyingValue() ||
703-
(RepR && (RepR->isSingleScalar() || RepR->isPredicated())))
704-
continue;
705-
706-
// Skip recipes that may have other lanes than their first used.
707-
if (!vputils::isSingleScalar(Def) && !vputils::onlyFirstLaneUsed(Def))
708-
continue;
709-
710-
auto *Clone = new VPReplicateRecipe(Def->getUnderlyingInstr(),
711-
Def->operands(), /*IsUniform*/ true,
712-
/*Mask*/ nullptr, /*Flags*/ *Def);
713-
Clone->insertAfter(Def);
714-
Def->replaceAllUsesWith(Clone);
715-
}
716-
717692
// Replace wide pointer inductions which have only their scalars used by
718693
// PtrAdd(IndStart, ScalarIVSteps (0, Step)).
719694
if (auto *PtrIV = dyn_cast<VPWidenPointerInductionRecipe>(&Phi)) {
@@ -1450,7 +1425,9 @@ static void narrowToSingleScalarRecipes(VPlan &Plan) {
14501425
// Skip recipes that aren't single scalars or don't have only their
14511426
// scalar results used. In the latter case, we would introduce extra
14521427
// broadcasts.
1453-
if (!vputils::isSingleScalar(RepOrWidenR) ||
1428+
if ((!vputils::isSingleScalar(RepOrWidenR) &&
1429+
!vputils::onlyFirstLaneUsed(RepOrWidenR)) ||
1430+
RepOrWidenR->getNumUsers() == 0 ||
14541431
!all_of(RepOrWidenR->users(), [RepOrWidenR](const VPUser *U) {
14551432
if (auto *Store = dyn_cast<VPWidenStoreRecipe>(U)) {
14561433
// VPWidenStore doesn't have users, and stores are always

0 commit comments

Comments
 (0)