[llvm] [VPlan] - Generalize dead cycle removal in removeDeadRecipes. (PR #213632)
Pawan Nirpal via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 26 10:55:25 PDT 2026
================
@@ -687,6 +687,32 @@ static void removeRedundantInductionCasts(VPlan &Plan) {
}
}
+/// If R is a phi-like recipe starting a dead cycle of recipes, erase all
+/// reachable recipes of the dead cycle.
+static void tryToRemoveDeadCycle(VPRecipeBase *R) {
+ auto *PhiR = dyn_cast<VPSingleDefRecipe>(R);
+ if (!PhiR || !isa<VPPhi, VPReductionPHIRecipe>(R))
----------------
pawan-nirpal-031 wrote:
Also I found that the dead widened IV (VPWidenIntOrFpInductionRecipe) doesn't need to be handled by tryToRemoveDeadCycle directly because it never forms a self-cycle. Once tryToRemoveDeadCycle breaks the reduction cycle, the widened IV becomes trivially dead and the existing isDeadRecipe check removes it.
I verified this with debug prints for a test with a predicated AnyOf reduction using icmp eq i32 %val, %iv (forcing the IV to be widened):
tryToRemoveDeadCycle: removing dead phi: WIDEN-REDUCTION-PHI ir<%rdx> = phi (any-of) ...
recursivelyDeleteDeadRecipes: deleting: BLEND ir<%rdx.next> = ...
recursivelyDeleteDeadRecipes: deleting: EMIT vp<%6> = or ...
...
isDeadRecipe: removing: ir<%iv> = WIDEN-INDUCTION ir<0>, ir<1>, vp<%0>
The WIDEN-INDUCTION is cleaned up by isDeadRecipe, not by tryToRemoveDeadCycle.
The existing dead_anyof_reduction_blend test already checks this (the widened IV disappears from the vector body in the output). I don't think a separate test for this adds value since it's not exercising a different code path, do you want me to add it anyway?
https://github.com/llvm/llvm-project/pull/213632
More information about the llvm-commits
mailing list