Skip to content

Commit 41b7341

Browse files
committed
[VPlan] Factor out helper to recursively collect all users (NFCI).
Factor out logic to collect all users recursively to be re-used in llvm#87816.
1 parent 3820571 commit 41b7341

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,11 @@ class VPRecipeWithIRFlags : public VPSingleDefRecipe {
10491049
R->getVPDefID() == VPRecipeBase::VPVectorPointerSC;
10501050
}
10511051

1052+
static inline bool classof(const VPUser *U) {
1053+
auto *R = dyn_cast<VPRecipeBase>(U);
1054+
return R && classof(R);
1055+
}
1056+
10521057
/// Drop all poison-generating flags.
10531058
void dropPoisonGeneratingFlags() {
10541059
// NOTE: This needs to be kept in-sync with

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,18 @@ bool VPlanTransforms::adjustFixedOrderRecurrences(VPlan &Plan,
852852
return true;
853853
}
854854

855+
static SmallVector<VPUser *> collectUsersRecursively(VPValue *V) {
856+
SetVector<VPUser *> Users(V->user_begin(), V->user_end());
857+
for (unsigned I = 0; I != Users.size(); ++I) {
858+
VPRecipeBase *Cur = dyn_cast<VPRecipeBase>(Users[I]);
859+
if (!Cur || isa<VPHeaderPHIRecipe>(Cur))
860+
continue;
861+
for (VPValue *V : Cur->definedValues())
862+
Users.insert(V->user_begin(), V->user_end());
863+
}
864+
return Users.takeVector();
865+
}
866+
855867
void VPlanTransforms::clearReductionWrapFlags(VPlan &Plan) {
856868
for (VPRecipeBase &R :
857869
Plan.getVectorLoopRegion()->getEntryBasicBlock()->phis()) {
@@ -863,24 +875,10 @@ void VPlanTransforms::clearReductionWrapFlags(VPlan &Plan) {
863875
if (RK != RecurKind::Add && RK != RecurKind::Mul)
864876
continue;
865877

866-
SmallSetVector<VPValue *, 8> Worklist;
867-
Worklist.insert(PhiR);
868-
869-
for (unsigned I = 0; I != Worklist.size(); ++I) {
870-
VPValue *Cur = Worklist[I];
871-
if (auto *RecWithFlags =
872-
dyn_cast<VPRecipeWithIRFlags>(Cur->getDefiningRecipe())) {
878+
for (VPUser *U : collectUsersRecursively(PhiR))
879+
if (auto *RecWithFlags = dyn_cast<VPRecipeWithIRFlags>(U)) {
873880
RecWithFlags->dropPoisonGeneratingFlags();
874881
}
875-
876-
for (VPUser *U : Cur->users()) {
877-
auto *UserRecipe = dyn_cast<VPRecipeBase>(U);
878-
if (!UserRecipe)
879-
continue;
880-
for (VPValue *V : UserRecipe->definedValues())
881-
Worklist.insert(V);
882-
}
883-
}
884882
}
885883
}
886884

0 commit comments

Comments
 (0)