Skip to content

Commit f34326d

Browse files
authored
[VPlan] Introduce vputils::onlyScalarValuesUsed (NFC) (#153577)
1 parent 868efdc commit f34326d

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,7 @@ static void removeRedundantCanonicalIVs(VPlan &Plan) {
517517
// everything WidenNewIV's users need. That is, WidenOriginalIV will
518518
// generate a vector phi or all users of WidenNewIV demand the first lane
519519
// only.
520-
if (any_of(WidenOriginalIV->users(),
521-
[WidenOriginalIV](VPUser *U) {
522-
return !U->usesScalars(WidenOriginalIV);
523-
}) ||
520+
if (!vputils::onlyScalarValuesUsed(WidenOriginalIV) ||
524521
vputils::onlyFirstLaneUsed(WidenNewIV)) {
525522
WidenNewIV->replaceAllUsesWith(WidenOriginalIV);
526523
WidenNewIV->eraseFromParent();
@@ -1263,9 +1260,7 @@ static void narrowToSingleScalarRecipes(VPlan &Plan) {
12631260
// scalar results used. In the latter case, we would introduce extra
12641261
// broadcasts.
12651262
if (!vputils::isSingleScalar(RepOrWidenR) ||
1266-
any_of(RepOrWidenR->users(), [RepOrWidenR](VPUser *U) {
1267-
return !U->usesScalars(RepOrWidenR);
1268-
}))
1263+
!vputils::onlyScalarValuesUsed(RepOrWidenR))
12691264
continue;
12701265

12711266
auto *Clone = new VPReplicateRecipe(RepOrWidenR->getUnderlyingInstr(),
@@ -3216,8 +3211,7 @@ void VPlanTransforms::materializeBroadcasts(VPlan &Plan) {
32163211

32173212
auto *VectorPreheader = Plan.getVectorPreheader();
32183213
for (VPValue *VPV : VPValues) {
3219-
if (all_of(VPV->users(),
3220-
[VPV](VPUser *U) { return U->usesScalars(VPV); }) ||
3214+
if (vputils::onlyScalarValuesUsed(VPV) ||
32213215
(VPV->isLiveIn() && VPV->getLiveInIRValue() &&
32223216
isa<Constant>(VPV->getLiveInIRValue())))
32233217
continue;
@@ -3373,7 +3367,7 @@ void VPlanTransforms::materializeVFAndVFxUF(VPlan &Plan, VPBasicBlock *VectorPH,
33733367
// For users of the runtime VF, compute it as VF * vscale, and VFxUF as (VF *
33743368
// vscale) * UF.
33753369
VPValue *RuntimeVF = Builder.createElementCount(TCTy, VFEC);
3376-
if (any_of(VF.users(), [&VF](VPUser *U) { return !U->usesScalars(&VF); })) {
3370+
if (!vputils::onlyScalarValuesUsed(&VF)) {
33773371
VPValue *BC = Builder.createNaryOp(VPInstruction::Broadcast, RuntimeVF);
33783372
VF.replaceUsesWithIf(
33793373
BC, [&VF](VPUser &U, unsigned) { return !U.usesScalars(&VF); });

llvm/lib/Transforms/Vectorize/VPlanUtils.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ bool vputils::onlyFirstPartUsed(const VPValue *Def) {
2424
[Def](const VPUser *U) { return U->onlyFirstPartUsed(Def); });
2525
}
2626

27+
bool vputils::onlyScalarValuesUsed(const VPValue *Def) {
28+
return all_of(Def->users(),
29+
[Def](const VPUser *U) { return U->usesScalars(Def); });
30+
}
31+
2732
VPValue *vputils::getOrCreateVPValueForSCEVExpr(VPlan &Plan, const SCEV *Expr,
2833
ScalarEvolution &SE) {
2934
if (auto *Expanded = Plan.getSCEVExpansion(Expr))

llvm/lib/Transforms/Vectorize/VPlanUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ bool onlyFirstLaneUsed(const VPValue *Def);
2525
/// Returns true if only the first part of \p Def is used.
2626
bool onlyFirstPartUsed(const VPValue *Def);
2727

28+
/// Returns true if only scalar values of \p Def are used by all users.
29+
bool onlyScalarValuesUsed(const VPValue *Def);
30+
2831
/// Get or create a VPValue that corresponds to the expansion of \p Expr. If \p
2932
/// Expr is a SCEVConstant or SCEVUnknown, return a VPValue wrapping the live-in
3033
/// value. Otherwise return a VPExpandSCEVRecipe to expand \p Expr. If \p Plan's

0 commit comments

Comments
 (0)