diff options
author | Jeff Law <law@redhat.com> | 2005-12-18 00:23:08 -0700 |
---|---|---|
committer | Jeff Law <law@gcc.gnu.org> | 2005-12-18 00:23:08 -0700 |
commit | 6b62dff819633db96e4086f77470fa193bdcde6a (patch) | |
tree | 5c3f58b68d6bf5311edde0b6c488a15485c73c46 /gcc/tree-ssa-forwprop.c | |
parent | a7ceba73e5af3733ab19ecf6cb3dec3c2c64a87a (diff) | |
download | gcc-6b62dff819633db96e4086f77470fa193bdcde6a.zip gcc-6b62dff819633db96e4086f77470fa193bdcde6a.tar.gz gcc-6b62dff819633db96e4086f77470fa193bdcde6a.tar.bz2 |
tree-ssa-dom.c (simplify_switch_and_lookup_avail_expr): Code to simplify SWITCH_EXPR_CODE moved from here to ...
* tree-ssa-dom.c (simplify_switch_and_lookup_avail_expr): Code
to simplify SWITCH_EXPR_CODE moved from here to ...
* tree-ssa-forwprop.c (simplify_switch_expr): Here.
(tree-ssa-forward_propagate_single_use_vars): Call
simplify_switch_expr when appropriate.
From-SVN: r108738
Diffstat (limited to 'gcc/tree-ssa-forwprop.c')
-rw-r--r-- | gcc/tree-ssa-forwprop.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c index e3978d8..2d89494 100644 --- a/gcc/tree-ssa-forwprop.c +++ b/gcc/tree-ssa-forwprop.c @@ -739,6 +739,61 @@ simplify_not_neg_expr (tree stmt) } } +/* STMT is a SWITCH_EXPR for which we attempt to find equivalent forms of + the condition which we may be able to optimize better. */ + +static void +simplify_switch_expr (tree stmt) +{ + tree cond = SWITCH_COND (stmt); + tree def, to, ti; + + /* The optimization that we really care about is removing unnecessary + casts. That will let us do much better in propagating the inferred + constant at the switch target. */ + if (TREE_CODE (cond) == SSA_NAME) + { + def = SSA_NAME_DEF_STMT (cond); + if (TREE_CODE (def) == MODIFY_EXPR) + { + def = TREE_OPERAND (def, 1); + if (TREE_CODE (def) == NOP_EXPR) + { + int need_precision; + bool fail; + + def = TREE_OPERAND (def, 0); + +#ifdef ENABLE_CHECKING + /* ??? Why was Jeff testing this? We are gimple... */ + gcc_assert (is_gimple_val (def)); +#endif + + to = TREE_TYPE (cond); + ti = TREE_TYPE (def); + + /* If we have an extension that preserves value, then we + can copy the source value into the switch. */ + + need_precision = TYPE_PRECISION (ti); + fail = false; + if (TYPE_UNSIGNED (to) && !TYPE_UNSIGNED (ti)) + fail = true; + else if (!TYPE_UNSIGNED (to) && TYPE_UNSIGNED (ti)) + need_precision += 1; + if (TYPE_PRECISION (to) < need_precision) + fail = true; + + if (!fail) + { + SWITCH_COND (stmt) = def; + update_stmt (stmt); + } + } + } + } +} + /* Main entry point for the forward propagation optimizer. */ static void @@ -788,6 +843,11 @@ tree_ssa_forward_propagate_single_use_vars (void) else bsi_next (&bsi); } + else if (TREE_CODE (stmt) == SWITCH_EXPR) + { + simplify_switch_expr (stmt); + bsi_next (&bsi); + } else if (TREE_CODE (stmt) == COND_EXPR) { forward_propagate_into_cond (stmt); |