From 956623c1378de3c48e77b23c2f2fa275f183e270 Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Mon, 3 Nov 2014 11:47:04 +0100 Subject: [PATCH] re PR tree-optimization/60770 (disappearing clobbers) 2014-11-03 Marc Glisse PR tree-optimization/60770 gcc/ * tree-into-ssa.c (rewrite_update_stmt): Return whether the statement should be removed. (maybe_register_def): Likewise. Replace clobbers with default definitions. (rewrite_dom_walker::before_dom_children): Remove statement if rewrite_update_stmt says so. * tree-ssa-live.c: Include tree-ssa.h. (set_var_live_on_entry): Do not mark undefined variables as live. (verify_live_on_entry): Do not check undefined variables. * tree-ssa.h (ssa_undefined_value_p): New parameter for the case of partially undefined variables. * tree-ssa.c (ssa_undefined_value_p): Likewise. (execute_update_addresses_taken): Do not drop clobbers. gcc/testsuite/ * gcc.dg/tree-ssa/pr60770-1.c: New file. From-SVN: r217034 --- gcc/ChangeLog | 17 +++++++++ gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/gcc.dg/tree-ssa/pr60770-1.c | 11 ++++++ gcc/tree-into-ssa.c | 42 ++++++++++++++++------- gcc/tree-ssa-live.c | 10 ++++++ gcc/tree-ssa.c | 19 +++------- gcc/tree-ssa.h | 2 +- 7 files changed, 78 insertions(+), 28 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr60770-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f31c42b9395..41a4f57c799 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,20 @@ +2014-11-03 Marc Glisse + + PR tree-optimization/60770 + * tree-into-ssa.c (rewrite_update_stmt): Return whether the + statement should be removed. + (maybe_register_def): Likewise. Replace clobbers with default + definitions. + (rewrite_dom_walker::before_dom_children): Remove statement if + rewrite_update_stmt says so. + * tree-ssa-live.c: Include tree-ssa.h. + (set_var_live_on_entry): Do not mark undefined variables as live. + (verify_live_on_entry): Do not check undefined variables. + * tree-ssa.h (ssa_undefined_value_p): New parameter for the case + of partially undefined variables. + * tree-ssa.c (ssa_undefined_value_p): Likewise. + (execute_update_addresses_taken): Do not drop clobbers. + 2014-11-03 Marc Glisse PR tree-optimization/63666 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 06e9bee3b44..7e97d61895f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-11-03 Marc Glisse + + PR tree-optimization/60770 + * gcc.dg/tree-ssa/pr60770-1.c: New file. + 2014-11-03 Jan Beulich * gcc.target/i386/i386.exp: Extend option set to test diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr60770-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr60770-1.c new file mode 100644 index 00000000000..021d88430c4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr60770-1.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O -Wall" } */ + +int f(int n){ + int*p; + { + int yyy=n; + p=&yyy; + } + return *p; /* { dg-warning "yyy" } */ +} diff --git a/gcc/tree-into-ssa.c b/gcc/tree-into-ssa.c index bf99160deea..d86efe47504 100644 --- a/gcc/tree-into-ssa.c +++ b/gcc/tree-into-ssa.c @@ -1833,14 +1833,15 @@ maybe_replace_use_in_debug_stmt (use_operand_p use_p) /* If the operand pointed to by DEF_P is an SSA name in NEW_SSA_NAMES or OLD_SSA_NAMES, or if it is a symbol marked for renaming, register it as the current definition for the names replaced by - DEF_P. */ + DEF_P. Returns whether the statement should be removed. */ -static inline void +static inline bool maybe_register_def (def_operand_p def_p, gimple stmt, gimple_stmt_iterator gsi) { tree def = DEF_FROM_PTR (def_p); tree sym = DECL_P (def) ? def : SSA_NAME_VAR (def); + bool to_delete = false; /* If DEF is a naked symbol that needs renaming, create a new name for it. */ @@ -1848,12 +1849,21 @@ maybe_register_def (def_operand_p def_p, gimple stmt, { if (DECL_P (def)) { - tree tracked_var; - - def = make_ssa_name (def, stmt); + if (gimple_clobber_p (stmt) && is_gimple_reg (sym)) + { + gcc_checking_assert (TREE_CODE (sym) == VAR_DECL); + /* Replace clobber stmts with a default def. This new use of a + default definition may make it look like SSA_NAMEs have + conflicting lifetimes, so we need special code to let them + coalesce properly. */ + to_delete = true; + def = get_or_create_ssa_default_def (cfun, sym); + } + else + def = make_ssa_name (def, stmt); SET_DEF (def_p, def); - tracked_var = target_for_debug_bind (sym); + tree tracked_var = target_for_debug_bind (sym); if (tracked_var) { gimple note = gimple_build_debug_bind (tracked_var, def, stmt); @@ -1911,6 +1921,8 @@ maybe_register_def (def_operand_p def_p, gimple stmt, if (is_old_name (def)) register_new_update_single (def, def); } + + return to_delete; } @@ -1919,9 +1931,9 @@ maybe_register_def (def_operand_p def_p, gimple stmt, OLD_SSA_NAMES used by SI will be updated to their current reaching definition. Names in OLD_SSA_NAMES or NEW_SSA_NAMES defined by SI will be registered as a new definition for their corresponding name - in OLD_SSA_NAMES. */ + in OLD_SSA_NAMES. Returns whether STMT should be removed. */ -static void +static bool rewrite_update_stmt (gimple stmt, gimple_stmt_iterator gsi) { use_operand_p use_p; @@ -1930,7 +1942,7 @@ rewrite_update_stmt (gimple stmt, gimple_stmt_iterator gsi) /* Only update marked statements. */ if (!rewrite_uses_p (stmt) && !register_defs_p (stmt)) - return; + return false; if (dump_file && (dump_flags & TDF_DETAILS)) { @@ -1981,9 +1993,12 @@ rewrite_update_stmt (gimple stmt, gimple_stmt_iterator gsi) /* Register definitions of names in NEW_SSA_NAMES and OLD_SSA_NAMES. Also register definitions for names whose underlying symbol is marked for renaming. */ + bool to_delete = false; if (register_defs_p (stmt)) FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, iter, SSA_OP_ALL_DEFS) - maybe_register_def (def_p, stmt, gsi); + to_delete |= maybe_register_def (def_p, stmt, gsi); + + return to_delete; } @@ -2149,8 +2164,11 @@ rewrite_update_dom_walker::before_dom_children (basic_block bb) if (bitmap_bit_p (interesting_blocks, bb->index)) { gcc_checking_assert (bitmap_bit_p (blocks_to_update, bb->index)); - for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) - rewrite_update_stmt (gsi_stmt (gsi), gsi); + for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); ) + if (rewrite_update_stmt (gsi_stmt (gsi), gsi)) + gsi_remove (&gsi, true); + else + gsi_next (&gsi); } /* Step 3. Update PHI nodes. */ diff --git a/gcc/tree-ssa-live.c b/gcc/tree-ssa-live.c index 1effb43bd38..22013e0ccdf 100644 --- a/gcc/tree-ssa-live.c +++ b/gcc/tree-ssa-live.c @@ -57,6 +57,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic-core.h" #include "debug.h" #include "flags.h" +#include "tree-ssa.h" #ifdef ENABLE_CHECKING static void verify_live_on_entry (tree_live_info_p); @@ -1103,6 +1104,10 @@ set_var_live_on_entry (tree ssa_name, tree_live_info_p live) else def_bb = ENTRY_BLOCK_PTR_FOR_FN (cfun); + /* An undefined local variable does not need to be very alive. */ + if (ssa_undefined_value_p (ssa_name, false)) + return; + /* Visit each use of SSA_NAME and if it isn't in the same block as the def, add it to the list of live on entry blocks. */ FOR_EACH_IMM_USE_FAST (use, imm_iter, ssa_name) @@ -1439,6 +1444,11 @@ verify_live_on_entry (tree_live_info_p live) else if (d == var) { + /* An undefined local variable does not need to be very + alive. */ + if (ssa_undefined_value_p (var, false)) + continue; + /* The only way this var shouldn't be marked live on entry is if it occurs in a PHI argument of the block. */ size_t z; diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c index bcf65e144e0..25354617a18 100644 --- a/gcc/tree-ssa.c +++ b/gcc/tree-ssa.c @@ -1188,10 +1188,11 @@ tree_ssa_strip_useless_type_conversions (tree exp) } -/* Return true if T, an SSA_NAME, has an undefined value. */ +/* Return true if T, an SSA_NAME, has an undefined value. PARTIAL is what + should be returned if the value is only partially undefined. */ bool -ssa_undefined_value_p (tree t) +ssa_undefined_value_p (tree t, bool partial) { gimple def_stmt; tree var = SSA_NAME_VAR (t); @@ -1215,7 +1216,7 @@ ssa_undefined_value_p (tree t) return true; /* Check if the complex was not only partially defined. */ - if (is_gimple_assign (def_stmt) + if (partial && is_gimple_assign (def_stmt) && gimple_assign_rhs_code (def_stmt) == COMPLEX_EXPR) { tree rhs1, rhs2; @@ -1561,18 +1562,6 @@ execute_update_addresses_taken (void) if (gimple_assign_lhs (stmt) != lhs) gimple_assign_set_lhs (stmt, lhs); - /* For var ={v} {CLOBBER}; where var lost - TREE_ADDRESSABLE just remove the stmt. */ - if (DECL_P (lhs) - && TREE_CLOBBER_P (rhs) - && bitmap_bit_p (suitable_for_renaming, DECL_UID (lhs))) - { - unlink_stmt_vdef (stmt); - gsi_remove (&gsi, true); - release_defs (stmt); - continue; - } - if (gimple_assign_rhs1 (stmt) != rhs) { gimple_stmt_iterator gsi = gsi_for_stmt (stmt); diff --git a/gcc/tree-ssa.h b/gcc/tree-ssa.h index 835686c664c..ed1ff6e7136 100644 --- a/gcc/tree-ssa.h +++ b/gcc/tree-ssa.h @@ -51,7 +51,7 @@ extern void delete_tree_ssa (void); extern bool tree_ssa_useless_type_conversion (tree); extern tree tree_ssa_strip_useless_type_conversions (tree); -extern bool ssa_undefined_value_p (tree); +extern bool ssa_undefined_value_p (tree, bool = true); extern void execute_update_addresses_taken (void); /* Given an edge_var_map V, return the PHI arg definition. */ -- 2.30.2