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 <[email protected]>
---
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 f7fb664a6b4..8bca917e722 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);
@@ -5170,7 +5173,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:
--
2.43.0