]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
forwprop: Mark the old switch index for (maybe) dceing
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Sun, 24 Aug 2025 06:47:22 +0000 (23:47 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Mon, 25 Aug 2025 15:29:24 +0000 (08:29 -0700)
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.pinski@oss.qualcomm.com>
gcc/tree-ssa-forwprop.cc

index ebf625f9c7eaa24574f5eab8fb40acb431ac3b41..fc5d0bb34ca9d40762e58efa5da122634f857d06 100644 (file)
@@ -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: