https://gcc.gnu.org/g:22d623dca3a8f3854a789f52c4a01e71c57a8724
commit r16-3375-g22d623dca3a8f3854a789f52c4a01e71c57a8724 Author: Andrew Pinski <andrew.pin...@oss.qualcomm.com> Date: Sat Aug 23 23:47:22 2025 -0700 forwprop: Mark the old switch index for (maybe) dceing While looking at this code I noticed that we don't remove the old switch index assignment if it is only used in the switch after it is modified in simplify_gimple_switch. This fixes that by marking the old switch index for the dce worklist. Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * tree-ssa-forwprop.cc (simplify_gimple_switch): Add simple_dce_worklist argument. Mark the old index when doing the replacement. (pass_forwprop::execute): Update call to simplify_gimple_switch. Signed-off-by: Andrew Pinski <andrew.pin...@oss.qualcomm.com> Diff: --- gcc/tree-ssa-forwprop.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc index ebf625f9c7ea..fc5d0bb34ca9 100644 --- a/gcc/tree-ssa-forwprop.cc +++ b/gcc/tree-ssa-forwprop.cc @@ -1054,7 +1054,8 @@ simplify_gimple_switch_label_vec (gswitch *stmt, tree index_type, static bool simplify_gimple_switch (gswitch *stmt, - vec<std::pair<int, int> > &edges_to_remove) + vec<std::pair<int, int> > &edges_to_remove, + bitmap simple_dce_worklist) { /* The optimization that we really care about is removing unnecessary casts. That will let us do much better in propagating the inferred @@ -1089,6 +1090,8 @@ simplify_gimple_switch (gswitch *stmt, if ((!min || int_fits_type_p (min, ti)) && (!max || int_fits_type_p (max, ti))) { + bitmap_set_bit (simple_dce_worklist, + SSA_NAME_VERSION (cond)); gimple_switch_set_index (stmt, def); simplify_gimple_switch_label_vec (stmt, ti, edges_to_remove); @@ -5051,7 +5054,8 @@ pass_forwprop::execute (function *fun) case GIMPLE_SWITCH: changed |= simplify_gimple_switch (as_a <gswitch *> (stmt), - edges_to_remove); + edges_to_remove, + simple_dce_worklist); break; case GIMPLE_COND: