The following addresses the fact that we keep an excessive amount of
redundant DEBUG BEGIN_STMTs - in the testcase it sums up to 99.999%
of all stmts, sucking up compile-time in IL walks.  The patch amends
the GIMPLE DCE code that elides redundant DEBUG BIND stmts, also
pruning uninterrupted sequences of DEBUG BEGIN_STMTs, keeping only
the last one.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

For the testcase this brings down compile-time to 150% of -g0 levels
(and only 215 out of originally 1981380 DEBUG BEGIN_STMTs kept).

OK for trunk and possibly backports?

There's the open question of whether a mix of (redundant)
DEBUG BIND and BEGIN_STMT could be pruned and how, or whether
a DEBUG BEGIN_STMT without any following other DEBUG stmt but
followed by a real stmt with location is meaningful at all.

Thanks,
Richard.

        PR middle-end/118801
        * tree-ssa-dce.cc (eliminate_unnecessary_stmts): Prune
        sequences of uninterrupted DEBUG BEGIN_STMTs, keeping only
        the last.
---
 gcc/tree-ssa-dce.cc | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/gcc/tree-ssa-dce.cc b/gcc/tree-ssa-dce.cc
index be21a2d0b50..064e47cbf23 100644
--- a/gcc/tree-ssa-dce.cc
+++ b/gcc/tree-ssa-dce.cc
@@ -1508,6 +1508,7 @@ eliminate_unnecessary_stmts (bool aggressive)
 
       /* Remove dead statements.  */
       auto_bitmap debug_seen;
+      bool debug_begin_seen = false;
       for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi = psi)
        {
          stmt = gsi_stmt (gsi);
@@ -1670,6 +1671,16 @@ eliminate_unnecessary_stmts (bool aggressive)
                remove_dead_stmt (&gsi, bb, to_remove_edges);
              continue;
            }
+         else if (gimple_debug_begin_stmt_p (stmt))
+           {
+             /* We are only keeping the last debug-begin in a series of
+                debug-begin stmts.  */
+             if (debug_begin_seen)
+               remove_dead_stmt (&gsi, bb, to_remove_edges);
+             debug_begin_seen = true;
+             continue;
+           }
+         debug_begin_seen = false;
          bitmap_clear (debug_seen);
        }
 
-- 
2.43.0

Reply via email to