public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-99] debug/105158 - improve debug stmt retaining for forwarder removal
Date: Wed,  4 May 2022 07:52:14 +0000 (GMT)	[thread overview]
Message-ID: <20220504075214.9EC723858C56@sourceware.org> (raw)

https://gcc.gnu.org/g:1ba68f78c9d2510eb095f7d8a90c87cd5fd4183d

commit r13-99-g1ba68f78c9d2510eb095f7d8a90c87cd5fd4183d
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Apr 5 15:23:54 2022 +0200

    debug/105158 - improve debug stmt retaining for forwarder removal
    
    Currently when we cannot move debug stmt from a forwarder to the
    destination block we drop/reset them.  But in some cases as for
    the testcase we can move them to the predecessor when that has
    a single successor and we can insert after the last stmt of the
    block.  That allows us to preserve debug info here.
    
    2022-04-05  Richard Biener  <rguenther@suse.de>
    
            PR debug/105158
            * tree-cfgcleanup.cc (move_debug_stmts_from_forwarder):
            Move debug stmts to the predecessor if moving to the
            destination is not possible.
            (remove_forwarder_block): Adjust.
            (remove_forwarder_block_with_phi): Likewise.

Diff:
---
 gcc/tree-cfgcleanup.cc | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/gcc/tree-cfgcleanup.cc b/gcc/tree-cfgcleanup.cc
index 6c05ef2464e..893619eaaa4 100644
--- a/gcc/tree-cfgcleanup.cc
+++ b/gcc/tree-cfgcleanup.cc
@@ -468,15 +468,34 @@ phi_alternatives_equal (basic_block dest, edge e1, edge e2)
   return true;
 }
 
-/* Move debug stmts from the forwarder block SRC to DEST.  */
+/* Move debug stmts from the forwarder block SRC to DEST or PRED.  */
 
 static void
-move_debug_stmts_from_forwarder (basic_block src, basic_block dest,
-				 bool dest_single_pred_p)
+move_debug_stmts_from_forwarder (basic_block src,
+				 basic_block dest, bool dest_single_pred_p,
+				 basic_block pred, bool pred_single_succ_p)
 {
   if (!MAY_HAVE_DEBUG_STMTS)
     return;
 
+  /* If we cannot move to the destination but to the predecessor do that.  */
+  if (!dest_single_pred_p && pred_single_succ_p)
+    {
+      gimple_stmt_iterator gsi_to = gsi_last_bb (pred);
+      if (gsi_end_p (gsi_to) || !stmt_ends_bb_p (gsi_stmt (gsi_to)))
+	{
+	  for (gimple_stmt_iterator gsi = gsi_after_labels (src);
+	       !gsi_end_p (gsi);)
+	    {
+	      gimple *debug = gsi_stmt (gsi);
+	      gcc_assert (is_gimple_debug (debug));
+	      gsi_move_after (&gsi, &gsi_to);
+	    }
+	  return;
+	}
+    }
+
+  /* Else move to DEST or drop/reset them.  */
   gimple_stmt_iterator gsi_to = gsi_after_labels (dest);
   for (gimple_stmt_iterator gsi = gsi_after_labels (src); !gsi_end_p (gsi);)
     {
@@ -627,7 +646,8 @@ remove_forwarder_block (basic_block bb)
 
   /* Move debug statements.  Reset them if the destination does not
      have a single predecessor.  */
-  move_debug_stmts_from_forwarder (bb, dest, dest_single_pred_p);
+  move_debug_stmts_from_forwarder (bb, dest, dest_single_pred_p,
+				   pred, pred && single_succ_p (pred));
 
   bitmap_set_bit (cfgcleanup_altered_bbs, dest->index);
 
@@ -1309,7 +1329,8 @@ remove_forwarder_block_with_phi (basic_block bb)
 
   /* Move debug statements.  Reset them if the destination does not
      have a single predecessor.  */
-  move_debug_stmts_from_forwarder (bb, dest, dest_single_pred_p);
+  move_debug_stmts_from_forwarder (bb, dest, dest_single_pred_p,
+				   pred, pred && single_succ_p (pred));
 
   /* Update the dominators.  */
   dombb = get_immediate_dominator (CDI_DOMINATORS, bb);


                 reply	other threads:[~2022-05-04  7:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220504075214.9EC723858C56@sourceware.org \
    --to=rguenth@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).