From: Andrew Pinski Date: Sun, 24 Aug 2025 06:47:22 +0000 (-0700) Subject: forwprop: Mark the old switch index for (maybe) dceing X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22d623dca3a8f3854a789f52c4a01e71c57a8724;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc index ebf625f9c7e..fc5d0bb34ca 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 > &edges_to_remove) + vec > &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 (stmt), - edges_to_remove); + edges_to_remove, + simple_dce_worklist); break; case GIMPLE_COND: