remove dead debug-bind resets
authorRichard Biener <rguenther@suse.de>
Tue, 14 Jan 2020 14:31:18 +0000 (15:31 +0100)
committerRichard Biener <rguenther@suse.de>
Tue, 12 May 2020 13:52:03 +0000 (15:52 +0200)
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  <rguenther@suse.de>

* tree-ssa-live.c (remove_unused_locals): Remove dead debug
bind resets.

gcc/ChangeLog
gcc/tree-ssa-live.c

index e2b01aaae27b7ab7b5ce68a530c23f77a560e5e0..86fa5298110a016411d9fd78d9a5c3ae3a83950c 100644 (file)
@@ -1,3 +1,8 @@
+2020-05-12  Richard Biener  <rguenther@suse.de>
+
+       * tree-ssa-live.c (remove_unused_locals): Remove dead debug
+       bind resets.
+
 2020-05-12  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
 
        * config/msp430/msp430-protos.h (msp430_output_aligned_decl_common):
index f3975320e8ca927319156cae6ccf59ccd551c05a..21a9ee43e6bb0e59a7686d5187eaf1848c56c2fd 100644 (file)
@@ -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);
          }
       }