The following fixes PR90273 where the testcase exhibits an excessive
number of debug stmts after the recent fixes to CFG cleanup to not
throw away debug stmts it cannot move but instead move and reset them.
This excessiveness causes compile-time and memory-usage to go through the
roof.

The fix is to deploy a simple debug-stmt DCE eliminating all but the
last debug-bind (of non-DEBUG_EXPR_DECL vars) in a series of
debug-bind-only stmts.  This simple DCE is hooked into the DCE
pass and implemented BB-local.

Bootstrapped / tested a slightly older version, re-bootstrap/regtest
in progress on x86_64-unknown-linux-gnu.

OK for trunk and branch?

Thanks,
Richard.

2019-04-29  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/90273
        * tree-ssa-dce.c (eliminate_unnecessary_stmts): Eliminate
        useless debug stmts.

Index: gcc/tree-ssa-dce.c
===================================================================
--- gcc/tree-ssa-dce.c  (revision 270640)
+++ gcc/tree-ssa-dce.c  (working copy)
@@ -1237,6 +1237,7 @@ eliminate_unnecessary_stmts (void)
       bb = h.pop ();
 
       /* Remove dead statements.  */
+      auto_bitmap debug_seen;
       for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi = psi)
        {
          stmt = gsi_stmt (gsi);
@@ -1282,11 +1283,15 @@ eliminate_unnecessary_stmts (void)
                        }
                    }
                  if (!dead)
-                   continue;
+                   {
+                     bitmap_clear (debug_seen);
+                     continue;
+                   }
                }
              if (!is_gimple_debug (stmt))
                something_changed = true;
              remove_dead_stmt (&gsi, bb, to_remove_edges);
+             continue;
            }
          else if (is_gimple_call (stmt))
            {
@@ -1352,6 +1357,18 @@ eliminate_unnecessary_stmts (void)
                    break;
                  }
            }
+         else if (gimple_debug_bind_p (stmt))
+           {
+             /* We are only keeping the last debug-bind of a
+                non-DEBUG_EXPR_DECL variable in a series of
+                debug-bind stmts.  */
+             tree var = gimple_debug_bind_get_var (stmt);
+             if (TREE_CODE (var) != DEBUG_EXPR_DECL
+                 && !bitmap_set_bit (debug_seen, DECL_UID (var)))
+               remove_dead_stmt (&gsi, bb, to_remove_edges);
+             continue;
+           }
+         bitmap_clear (debug_seen);
        }
 
       /* Remove dead PHI nodes.  */

Reply via email to