@@ -472,6 +472,26 @@ static void removeRedundantCanonicalIVs(VPlan &Plan) {
472
472
}
473
473
}
474
474
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
+
475
495
static void removeDeadRecipes (VPlan &Plan) {
476
496
ReversePostOrderTraversal<VPBlockDeepTraversalWrapper<VPBlockBase *>> RPOT (
477
497
Plan.getEntry ());
@@ -480,22 +500,8 @@ static void removeDeadRecipes(VPlan &Plan) {
480
500
// The recipes in the block are processed in reverse order, to catch chains
481
501
// of dead recipes.
482
502
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 ();
499
505
}
500
506
}
501
507
}
0 commit comments