Skip to content

Commit 82c6214

Browse files
committed
[VPlan] Introduce vputils::onlyScalarsUsed (NFC)
1 parent 48beed5 commit 82c6214

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::onlyScalarsUsed(WidenOriginalIV) ||
524521
vputils::onlyFirstLaneUsed(WidenNewIV)) {
525522
WidenNewIV->replaceAllUsesWith(WidenOriginalIV);
526523
WidenNewIV->eraseFromParent();
@@ -1264,9 +1261,7 @@ static void narrowToSingleScalarRecipes(VPlan &Plan) {
12641261
// scalar results used. In the latter case, we would introduce extra
12651262
// broadcasts.
12661263
if (!vputils::isSingleScalar(RepOrWidenR) ||
1267-
any_of(RepOrWidenR->users(), [RepOrWidenR](VPUser *U) {
1268-
return !U->usesScalars(RepOrWidenR);
1269-
}))
1264+
!vputils::onlyScalarsUsed(RepOrWidenR))
12701265
continue;
12711266

12721267
auto *Clone = new VPReplicateRecipe(RepOrWidenR->getUnderlyingInstr(),
@@ -3219,8 +3214,7 @@ void VPlanTransforms::materializeBroadcasts(VPlan &Plan) {
32193214

32203215
auto *VectorPreheader = Plan.getVectorPreheader();
32213216
for (VPValue *VPV : VPValues) {
3222-
if (all_of(VPV->users(),
3223-
[VPV](VPUser *U) { return U->usesScalars(VPV); }) ||
3217+
if (vputils::onlyScalarsUsed(VPV) ||
32243218
(VPV->isLiveIn() && VPV->getLiveInIRValue() &&
32253219
isa<Constant>(VPV->getLiveInIRValue())))
32263220
continue;
@@ -3376,7 +3370,7 @@ void VPlanTransforms::materializeVFAndVFxUF(VPlan &Plan, VPBasicBlock *VectorPH,
33763370
// For users of the runtime VF, compute it as VF * vscale, and VFxUF as (VF *
33773371
// vscale) * UF.
33783372
VPValue *RuntimeVF = Builder.createElementCount(TCTy, VFEC);
3379-
if (any_of(VF.users(), [&VF](VPUser *U) { return !U->usesScalars(&VF); })) {
3373+
if (!vputils::onlyScalarsUsed(&VF)) {
33803374
VPValue *BC = Builder.createNaryOp(VPInstruction::Broadcast, RuntimeVF);
33813375
VF.replaceUsesWithIf(
33823376
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::onlyScalarsUsed(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 \p Def only uses scalars.
29+
bool onlyScalarsUsed(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)