middle-end/118801 - excessive redundant DEBUG BEGIN_STMT

Message ID 20250210095816.6F3D73858CDA@sourceware.org
State New
Headers
Series middle-end/118801 - excessive redundant DEBUG BEGIN_STMT |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_simplebootstrap_build--master-aarch64-bootstrap success Build passed
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_simplebootstrap_build--master-arm-bootstrap success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 fail Test failed
linaro-tcwg-bot/tcwg_gcc_check--master-arm fail Test failed

Commit Message

Richard Biener Feb. 10, 2025, 9:57 a.m. UTC
  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(+)
  

Patch

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);
 	}