]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end/118801 - excessive redundant DEBUG BEGIN_STMT
authorRichard Biener <rguenther@suse.de>
Mon, 10 Feb 2025 09:23:45 +0000 (10:23 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 7 Mar 2025 08:59:18 +0000 (09:59 +0100)
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 of each set of DEBUG BEGIN_STMT with unique location.

PR middle-end/118801
* tree-ssa-dce.cc (eliminate_unnecessary_stmts): Prune
sequences of uninterrupted DEBUG BEGIN_STMTs, keeping only
the last of a set with unique location.

gcc/tree-ssa-dce.cc

index 18af81866b7eaf00b16bedde676f48430cca1c84..ba9cd6536aeb19345823883e8d0aa2c564c8324a 100644 (file)
@@ -1508,6 +1508,7 @@ eliminate_unnecessary_stmts (bool aggressive)
 
       /* Remove dead statements.  */
       auto_bitmap debug_seen;
+      hash_set<int_hash <location_t, 0>> locs_seen;
       for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi = psi)
        {
          stmt = gsi_stmt (gsi);
@@ -1670,6 +1671,15 @@ 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 (locs_seen.add (gimple_location (stmt)))
+               remove_dead_stmt (&gsi, bb, to_remove_edges);
+             continue;
+           }
+         locs_seen.empty ();
          bitmap_clear (debug_seen);
        }