From 3753001420bcb94c509d028f41fc6f957b72e8d3 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Fri, 26 Feb 2010 16:01:52 +0000 Subject: re PR tree-optimization/43186 (A loop in tree_unroll_loops_completely never ends) 2010-02-26 Richard Guenther PR tree-optimization/43186 * gimple.h (gimple_fold): Remove. * gimple.c (gimple_fold): Remove. Inline into single user ... * tree-cfgcleanup.c (cleanup_control_expr_graph): ... here. Try harder for conditions. * gcc.c-torture/compile/pr43186.c: New testcase. From-SVN: r157093 --- gcc/ChangeLog | 8 +++++ gcc/gimple.c | 48 --------------------------- gcc/gimple.h | 1 - gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/gcc.c-torture/compile/pr43186.c | 15 +++++++++ gcc/tree-cfgcleanup.c | 40 +++++++++++++++++++++- 6 files changed, 67 insertions(+), 50 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr43186.c (limited to 'gcc') diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 75f5aa7..91b9555 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2010-02-26 Richard Guenther + + PR tree-optimization/43186 + * gimple.h (gimple_fold): Remove. + * gimple.c (gimple_fold): Remove. Inline into single user ... + * tree-cfgcleanup.c (cleanup_control_expr_graph): ... here. + Try harder for conditions. + 2010-02-26 Jakub Jelinek PR debug/43190 diff --git a/gcc/gimple.c b/gcc/gimple.c index dce5ba5..717a020 100644 --- a/gcc/gimple.c +++ b/gcc/gimple.c @@ -1835,54 +1835,6 @@ gimple_set_bb (gimple stmt, basic_block bb) } -/* Fold the expression computed by STMT. If the expression can be - folded, return the folded result, otherwise return NULL. STMT is - not modified. */ - -tree -gimple_fold (const_gimple stmt) -{ - location_t loc = gimple_location (stmt); - switch (gimple_code (stmt)) - { - case GIMPLE_COND: - return fold_binary_loc (loc, gimple_cond_code (stmt), - boolean_type_node, - gimple_cond_lhs (stmt), - gimple_cond_rhs (stmt)); - - case GIMPLE_ASSIGN: - switch (get_gimple_rhs_class (gimple_assign_rhs_code (stmt))) - { - case GIMPLE_UNARY_RHS: - return fold_unary_loc (loc, gimple_assign_rhs_code (stmt), - TREE_TYPE (gimple_assign_lhs (stmt)), - gimple_assign_rhs1 (stmt)); - case GIMPLE_BINARY_RHS: - return fold_binary_loc (loc, gimple_assign_rhs_code (stmt), - TREE_TYPE (gimple_assign_lhs (stmt)), - gimple_assign_rhs1 (stmt), - gimple_assign_rhs2 (stmt)); - case GIMPLE_SINGLE_RHS: - return fold (gimple_assign_rhs1 (stmt)); - default:; - } - break; - - case GIMPLE_SWITCH: - return gimple_switch_index (stmt); - - case GIMPLE_CALL: - return NULL_TREE; - - default: - break; - } - - gcc_unreachable (); -} - - /* Modify the RHS of the assignment pointed-to by GSI using the operands in the expression tree EXPR. diff --git a/gcc/gimple.h b/gcc/gimple.h index 6377938..65cb6e1 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -841,7 +841,6 @@ bool gimple_assign_ssa_name_copy_p (gimple); bool gimple_assign_single_p (gimple); bool gimple_assign_unary_nop_p (gimple); void gimple_set_bb (gimple, struct basic_block_def *); -tree gimple_fold (const_gimple); void gimple_assign_set_rhs_from_tree (gimple_stmt_iterator *, tree); void gimple_assign_set_rhs_with_ops (gimple_stmt_iterator *, enum tree_code, tree, tree); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e3971a8..ea4404d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-02-26 Richard Guenther + + PR tree-optimization/43186 + * gcc.c-torture/compile/pr43186.c: New testcase. + 2010-02-26 Jakub Jelinek PR debug/43190 diff --git a/gcc/testsuite/gcc.c-torture/compile/pr43186.c b/gcc/testsuite/gcc.c-torture/compile/pr43186.c new file mode 100644 index 0000000..d235e97 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr43186.c @@ -0,0 +1,15 @@ +int n; + +void foo (int i) +{ + int a, b; + + if (!i) + for (a = 1; a < 3; a++) + if (a) + for (b = 1; b < 3; b++) + foo (b); + + n++; +} + diff --git a/gcc/tree-cfgcleanup.c b/gcc/tree-cfgcleanup.c index 6810f4b..68929f8 100644 --- a/gcc/tree-cfgcleanup.c +++ b/gcc/tree-cfgcleanup.c @@ -90,9 +90,47 @@ cleanup_control_expr_graph (basic_block bb, gimple_stmt_iterator gsi) edge e; edge_iterator ei; bool warned; + location_t loc; fold_defer_overflow_warnings (); - val = gimple_fold (stmt); + loc = gimple_location (stmt); + switch (gimple_code (stmt)) + { + case GIMPLE_COND: + { + tree lhs = gimple_cond_lhs (stmt); + tree rhs = gimple_cond_rhs (stmt); + /* For conditions try harder and lookup single-argument + PHI nodes. Only do so from the same basic-block though + as other basic-blocks may be dead already. */ + if (TREE_CODE (lhs) == SSA_NAME) + { + gimple def_stmt = SSA_NAME_DEF_STMT (lhs); + if (gimple_code (def_stmt) == GIMPLE_PHI + && gimple_phi_num_args (def_stmt) == 1 + && gimple_bb (def_stmt) == gimple_bb (stmt)) + lhs = PHI_ARG_DEF (def_stmt, 0); + } + if (TREE_CODE (rhs) == SSA_NAME) + { + gimple def_stmt = SSA_NAME_DEF_STMT (rhs); + if (gimple_code (def_stmt) == GIMPLE_PHI + && gimple_phi_num_args (def_stmt) == 1 + && gimple_bb (def_stmt) == gimple_bb (stmt)) + rhs = PHI_ARG_DEF (def_stmt, 0); + } + val = fold_binary_loc (loc, gimple_cond_code (stmt), + boolean_type_node, lhs, rhs); + break; + } + + case GIMPLE_SWITCH: + val = gimple_switch_index (stmt); + break; + + default: + val = NULL_TREE; + } taken_edge = find_taken_edge (bb, val); if (!taken_edge) { -- cgit v1.1