Skip to content

Commit e329b68

Browse files
committed
[VPlan] Factor out logic to check if recipe is dead (NFCI).
In preparation to use the helper in more places.
1 parent 95f9b08 commit e329b68

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,26 @@ static void removeRedundantCanonicalIVs(VPlan &Plan) {
472472
}
473473
}
474474

475+
/// Returns true if \p R is dead and can be removed.
476+
static bool isDeadRecipe(VPRecipeBase &R) {
477+
using namespace llvm::PatternMatch;
478+
// Do remove conditional assume instructions as their conditions may be
479+
// flattened.
480+
auto *RepR = dyn_cast<VPReplicateRecipe>(&R);
481+
bool IsConditionalAssume =
482+
RepR && RepR->isPredicated() &&
483+
match(RepR->getUnderlyingInstr(), m_Intrinsic<Intrinsic::assume>());
484+
if (IsConditionalAssume)
485+
return true;
486+
487+
if (R.mayHaveSideEffects())
488+
return false;
489+
490+
// Recipe is dead if no user keeps the recipe alive.
491+
return all_of(R.definedValues(),
492+
[](VPValue *V) { return V->getNumUsers() == 0; });
493+
}
494+
475495
static void removeDeadRecipes(VPlan &Plan) {
476496
ReversePostOrderTraversal<VPBlockDeepTraversalWrapper<VPBlockBase *>> RPOT(
477497
Plan.getEntry());
@@ -480,22 +500,8 @@ static void removeDeadRecipes(VPlan &Plan) {
480500
// The recipes in the block are processed in reverse order, to catch chains
481501
// of dead recipes.
482502
for (VPRecipeBase &R : make_early_inc_range(reverse(*VPBB))) {
483-
// A user keeps R alive:
484-
if (any_of(R.definedValues(),
485-
[](VPValue *V) { return V->getNumUsers(); }))
486-
continue;
487-
488-
using namespace llvm::PatternMatch;
489-
// Having side effects keeps R alive, but do remove conditional assume
490-
// instructions as their conditions may be flattened.
491-
auto *RepR = dyn_cast<VPReplicateRecipe>(&R);
492-
bool IsConditionalAssume =
493-
RepR && RepR->isPredicated() &&
494-
match(RepR->getUnderlyingInstr(), m_Intrinsic<Intrinsic::assume>());
495-
if (R.mayHaveSideEffects() && !IsConditionalAssume)
496-
continue;
497-
498-
R.eraseFromParent();
503+
if (isDeadRecipe(R))
504+
R.eraseFromParent();
499505
}
500506
}
501507
}

0 commit comments

Comments
 (0)