public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] rtl-optimization/109237 - quadraticness in delete_trivially_dead_insns
@ 2023-03-22 10:01 Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-03-22 10:01 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek

The following addresses quadraticness in processing debug insns
in delete_trivially_dead_insns and insn_live_p by using TREE_VISITED
on the INSN_VAR_LOCATION_DECL to indicate a later debug bind
with the same decl and no intervening real insn or debug marker.
That gets rid of the NEXT_INSN walk in insn_live_p in favor of
first clearing TREE_VISITED in the first loop over insn and
the book-keeping of decls we set the bit since we need to clear
them when visiting a real or debug marker insn.

That improves the time spent in delete_trivially_dead_insns from
10.6s to 2.2s for the testcase.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

OK?

Thanks,
Richard.

	PR rtl-optimization/109237
	* cse.cc (insn_live_p): Remove NEXT_INSN walk, instead check
	TREE_VISITED on INSN_VAR_LOCATION_DECL.
	(delete_trivially_dead_insns): Maintain TREE_VISITED on
	active debug bind INSN_VAR_LOCATION_DECL.
---
 gcc/cse.cc | 39 ++++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/gcc/cse.cc b/gcc/cse.cc
index 8fbda4ecc86..204047b0e0b 100644
--- a/gcc/cse.cc
+++ b/gcc/cse.cc
@@ -6906,22 +6906,12 @@ insn_live_p (rtx_insn *insn, int *counts)
     }
   else if (DEBUG_INSN_P (insn))
     {
-      rtx_insn *next;
-
       if (DEBUG_MARKER_INSN_P (insn))
 	return true;
 
-      for (next = NEXT_INSN (insn); next; next = NEXT_INSN (next))
-	if (NOTE_P (next))
-	  continue;
-	else if (!DEBUG_INSN_P (next))
-	  return true;
-	/* If we find an inspection point, such as a debug begin stmt,
-	   we want to keep the earlier debug insn.  */
-	else if (DEBUG_MARKER_INSN_P (next))
-	  return true;
-	else if (INSN_VAR_LOCATION_DECL (insn) == INSN_VAR_LOCATION_DECL (next))
-	  return false;
+      if (DEBUG_BIND_INSN_P (insn)
+	  && TREE_VISITED (INSN_VAR_LOCATION_DECL (insn)))
+	return false;
 
       return true;
     }
@@ -7007,8 +6997,11 @@ delete_trivially_dead_insns (rtx_insn *insns, int nreg)
       counts = XCNEWVEC (int, nreg * 3);
       for (insn = insns; insn; insn = NEXT_INSN (insn))
 	if (DEBUG_BIND_INSN_P (insn))
-	  count_reg_usage (INSN_VAR_LOCATION_LOC (insn), counts + nreg,
-			   NULL_RTX, 1);
+	  {
+	    count_reg_usage (INSN_VAR_LOCATION_LOC (insn), counts + nreg,
+			     NULL_RTX, 1);
+	    TREE_VISITED (INSN_VAR_LOCATION_DECL (insn)) = 0;
+	  }
 	else if (INSN_P (insn))
 	  {
 	    count_reg_usage (insn, counts, NULL_RTX, 1);
@@ -7048,6 +7041,7 @@ delete_trivially_dead_insns (rtx_insn *insns, int nreg)
      the setter.  Then go through DEBUG_INSNs and if a DEBUG_EXPR
      has been created for the unused register, replace it with
      the DEBUG_EXPR, otherwise reset the DEBUG_INSN.  */
+  auto_vec<tree, 32> later_debug_set_vars;
   for (insn = get_last_insn (); insn; insn = prev)
     {
       int live_insn = 0;
@@ -7110,6 +7104,21 @@ delete_trivially_dead_insns (rtx_insn *insns, int nreg)
 	    }
 	  cse_cfg_altered |= delete_insn_and_edges (insn);
 	}
+      else
+	{
+	  if (!DEBUG_INSN_P (insn) || DEBUG_MARKER_INSN_P (insn))
+	    {
+	      for (tree var : later_debug_set_vars)
+		TREE_VISITED (var) = 0;
+	      later_debug_set_vars.truncate (0);
+	    }
+	  else if (DEBUG_BIND_INSN_P (insn)
+		   && !TREE_VISITED (INSN_VAR_LOCATION_DECL (insn)))
+	    {
+	      later_debug_set_vars.safe_push (INSN_VAR_LOCATION_DECL (insn));
+	      TREE_VISITED (INSN_VAR_LOCATION_DECL (insn)) = 1;
+	    }
+	}
     }
 
   if (MAY_HAVE_DEBUG_BIND_INSNS)
-- 
2.35.3

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] rtl-optimization/109237 - quadraticness in delete_trivially_dead_insns
       [not found] <20230322100210.AE2793857B9B@sourceware.org>
@ 2023-03-31 16:30 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2023-03-31 16:30 UTC (permalink / raw)
  To: Richard Biener, gcc-patches; +Cc: Jakub Jelinek



On 3/22/23 04:01, Richard Biener via Gcc-patches wrote:
> The following addresses quadraticness in processing debug insns
> in delete_trivially_dead_insns and insn_live_p by using TREE_VISITED
> on the INSN_VAR_LOCATION_DECL to indicate a later debug bind
> with the same decl and no intervening real insn or debug marker.
> That gets rid of the NEXT_INSN walk in insn_live_p in favor of
> first clearing TREE_VISITED in the first loop over insn and
> the book-keeping of decls we set the bit since we need to clear
> them when visiting a real or debug marker insn.
> 
> That improves the time spent in delete_trivially_dead_insns from
> 10.6s to 2.2s for the testcase.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu.
> 
> OK?
> 
> Thanks,
> Richard.
> 
> 	PR rtl-optimization/109237
> 	* cse.cc (insn_live_p): Remove NEXT_INSN walk, instead check
> 	TREE_VISITED on INSN_VAR_LOCATION_DECL.
> 	(delete_trivially_dead_insns): Maintain TREE_VISITED on
> 	active debug bind INSN_VAR_LOCATION_DECL.
OK
jeff

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-31 16:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-22 10:01 [PATCH] rtl-optimization/109237 - quadraticness in delete_trivially_dead_insns Richard Biener
     [not found] <20230322100210.AE2793857B9B@sourceware.org>
2023-03-31 16:30 ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).