diff options
author | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-12-16 14:56:10 +0000 |
---|---|---|
committer | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-12-16 14:56:10 +0000 |
commit | b5e7cd42984528c5875e0d039f6ebe53fdb2b31c (patch) | |
tree | 58159337d2a2ac40cdb43c20c75ebe6433122b00 | |
parent | 6e71bbf2dec336831d5508b8c4cb6b9baf0ce84b (diff) | |
download | gcc-b5e7cd42984528c5875e0d039f6ebe53fdb2b31c.tar.gz |
2015-12-16 Richard Biener <rguenther@suse.de>
PR tree-optimization/68870
* tree-cfgcleanup.c (cleanup_control_expr_graph): Add first_p
parameter, if set only perform trivial constant folding.
Queue other blocks with conditions for later processing.
(cleanup_control_flow_bb): Add first_p parameter and pass it through.
(cleanup_tree_cfg_1): Pass true for the first iteration
cleanup_control_expr_graph.
* gcc.dg/torture/pr68870.c: New testcase.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@231695 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/torture/pr68870.c | 29 | ||||
-rw-r--r-- | gcc/tree-cfgcleanup.c | 40 |
4 files changed, 70 insertions, 14 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c04c01f86ea..90399d58f49 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2015-12-16 Richard Biener <rguenther@suse.de> + + PR tree-optimization/68870 + * tree-cfgcleanup.c (cleanup_control_expr_graph): Add first_p + parameter, if set only perform trivial constant folding. + Queue other blocks with conditions for later processing. + (cleanup_control_flow_bb): Add first_p parameter and pass it through. + (cleanup_tree_cfg_1): Pass true for the first iteration + cleanup_control_expr_graph. + 2015-12-16 Nathan Sidwell <nathan@acm.org> * config/nvptx/nvptx-protos.h (nvptx_hard_regno_mode_ok): Delete. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4a058fb7a01..d4ee11c6ecb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-12-16 Richard Biener <rguenther@suse.de> + + PR tree-optimization/68870 + * gcc.dg/torture/pr68870.c: New testcase. + 2015-12-16 Tom de Vries <tom@codesourcery.com> * g++.dg/ipa/devirt-37.C: Update for new fre2 pass. diff --git a/gcc/testsuite/gcc.dg/torture/pr68870.c b/gcc/testsuite/gcc.dg/torture/pr68870.c new file mode 100644 index 00000000000..1ad0f7b604b --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr68870.c @@ -0,0 +1,29 @@ +/* { dg-do compile } */ + +int printf (const char *, ...); + +int a, f, g; +char b, d; +short c; +static short e; + +char +fn1 () +{ + for (; b; b++) + { + int h = 5; + for (a = 0; a < 1; a++) + { + for (d = 0; d < 1; d++) + for (c = 0; c < 1; c++) + for (; e >= 0;) + return 5; + if (f) + h = 0; + } + if (h) + printf ("%d", 0); + } + return g; +} diff --git a/gcc/tree-cfgcleanup.c b/gcc/tree-cfgcleanup.c index 3f50c66af60..c5d94d07c82 100644 --- a/gcc/tree-cfgcleanup.c +++ b/gcc/tree-cfgcleanup.c @@ -78,7 +78,8 @@ remove_fallthru_edge (vec<edge, va_gc> *ev) at block BB. */ static bool -cleanup_control_expr_graph (basic_block bb, gimple_stmt_iterator gsi) +cleanup_control_expr_graph (basic_block bb, gimple_stmt_iterator gsi, + bool first_p) { edge taken_edge; bool retval = false; @@ -95,15 +96,26 @@ cleanup_control_expr_graph (basic_block bb, gimple_stmt_iterator gsi) switch (gimple_code (stmt)) { case GIMPLE_COND: - { - code_helper rcode; - tree ops[3] = {}; - if (gimple_simplify (stmt, &rcode, ops, NULL, no_follow_ssa_edges, - no_follow_ssa_edges) - && rcode == INTEGER_CST) - val = ops[0]; - break; - } + /* During a first iteration on the CFG only remove trivially + dead edges but mark other conditions for re-evaluation. */ + if (first_p) + { + val = const_binop (gimple_cond_code (stmt), boolean_type_node, + gimple_cond_lhs (stmt), + gimple_cond_rhs (stmt)); + if (! val) + bitmap_set_bit (cfgcleanup_altered_bbs, bb->index); + } + else + { + code_helper rcode; + tree ops[3] = {}; + if (gimple_simplify (stmt, &rcode, ops, NULL, no_follow_ssa_edges, + no_follow_ssa_edges) + && rcode == INTEGER_CST) + val = ops[0]; + } + break; case GIMPLE_SWITCH: val = gimple_switch_index (as_a <gswitch *> (stmt)); @@ -176,7 +188,7 @@ cleanup_call_ctrl_altering_flag (gimple *bb_end) true if anything changes. */ static bool -cleanup_control_flow_bb (basic_block bb) +cleanup_control_flow_bb (basic_block bb, bool first_p) { gimple_stmt_iterator gsi; bool retval = false; @@ -199,7 +211,7 @@ cleanup_control_flow_bb (basic_block bb) || gimple_code (stmt) == GIMPLE_SWITCH) { gcc_checking_assert (gsi_stmt (gsi_last_bb (bb)) == stmt); - retval |= cleanup_control_expr_graph (bb, gsi); + retval |= cleanup_control_expr_graph (bb, gsi, first_p); } else if (gimple_code (stmt) == GIMPLE_GOTO && TREE_CODE (gimple_goto_dest (stmt)) == ADDR_EXPR @@ -680,7 +692,7 @@ cleanup_tree_cfg_1 (void) { bb = BASIC_BLOCK_FOR_FN (cfun, i); if (bb) - retval |= cleanup_control_flow_bb (bb); + retval |= cleanup_control_flow_bb (bb, true); } /* After doing the above SSA form should be valid (or an update SSA @@ -708,7 +720,7 @@ cleanup_tree_cfg_1 (void) if (!bb) continue; - retval |= cleanup_control_flow_bb (bb); + retval |= cleanup_control_flow_bb (bb, false); retval |= cleanup_tree_cfg_bb (bb); } |