From 998fbe9f1f7e5ef53ca79fbd28f8a3875a477baa Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Tue, 14 Jan 2020 15:31:18 +0100 Subject: [PATCH] remove dead debug-bind resets This removes debug-bind resets aka # DEBUG b = NULL when the reset variable is otherwise unused. I've gathered statistics for a single TU, fold-const.ii which at -O2 -g shows 28 ssa "dead debug bind reset" 1 34 einline "dead debug bind reset" 340 54 release_ssa "dead debug bind reset" 176 54 release_ssa "live debug bind reset of dead var" 4 86 inline "dead debug bind reset" 5131 86 inline "live debug bind reset of dead var" 61 241 optimized "dead debug bind reset" 970 241 optimized "live debug bind reset of dead var" 287 where "live debug bind reset of dead var" means the variable is unused but there were debug binds with a value for them and "dead debug bind reset" means the variable is unused and there were only debug bind resets (each reset of the same variable is counted for both counters). This shows A considerable amount of dead stmts removed esp. after IPA inlining. 2020-05-12 Richard Biener * tree-ssa-live.c (remove_unused_locals): Remove dead debug bind resets. --- gcc/ChangeLog | 5 +++++ gcc/tree-ssa-live.c | 31 ++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e2b01aaae27..86fa5298110 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2020-05-12 Richard Biener + + * tree-ssa-live.c (remove_unused_locals): Remove dead debug + bind resets. + 2020-05-12 Jozef Lawrynowicz * config/msp430/msp430-protos.h (msp430_output_aligned_decl_common): diff --git a/gcc/tree-ssa-live.c b/gcc/tree-ssa-live.c index f3975320e8c..21a9ee43e6b 100644 --- a/gcc/tree-ssa-live.c +++ b/gcc/tree-ssa-live.c @@ -743,6 +743,7 @@ remove_unused_locals (void) mark_scope_block_unused (DECL_INITIAL (current_function_decl)); usedvars = BITMAP_ALLOC (NULL); + auto_bitmap useddebug; /* Walk the CFG marking all referenced symbols. */ FOR_EACH_BB_FN (bb, cfun) @@ -763,7 +764,21 @@ remove_unused_locals (void) do it. If the block is not otherwise used, the stmt will be cleaned up in clean_unused_block_pointer. */ if (is_gimple_debug (stmt)) - continue; + { + if (gimple_debug_bind_p (stmt)) + { + tree var = gimple_debug_bind_get_var (stmt); + if (VAR_P (var)) + { + if (!gimple_debug_bind_get_value (stmt)) + /* Run the 2nd phase. */ + have_local_clobbers = true; + else + bitmap_set_bit (useddebug, DECL_UID (var)); + } + } + continue; + } if (gimple_clobber_p (stmt)) { @@ -846,6 +861,20 @@ remove_unused_locals (void) if (b) TREE_USED (b) = true; } + else if (gimple_debug_bind_p (stmt)) + { + tree var = gimple_debug_bind_get_var (stmt); + if (VAR_P (var) + && !bitmap_bit_p (useddebug, DECL_UID (var)) + && !is_used_p (var)) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, "Dead debug bind reset to %u\n", + DECL_UID (var)); + gsi_remove (&gsi, true); + continue; + } + } gsi_next (&gsi); } } -- 2.30.2