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.

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Richard.

2020-05-12  Richard Biener  <rguent...@suse.de>

        * tree-ssa-live.c (remove_unused_locals): Remove dead debug
        bind resets.
---
 gcc/tree-ssa-live.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-live.c b/gcc/tree-ssa-live.c
index f3975320e8c..c2e3787f99a 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 (TREE_CODE (var) != DEBUG_EXPR_DECL)
+                   {
+                     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 (TREE_CODE (var) != DEBUG_EXPR_DECL
+                   && !bitmap_bit_p (useddebug, DECL_UID (var))
+                   && !bitmap_bit_p (usedvars, DECL_UID (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.16.4

Reply via email to