* [PATCH] debug/105158 - improve debug stmt retaining for forwarder removal
@ 2022-04-05 14:12 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2022-04-05 14:12 UTC (permalink / raw)
To: gcc-patches
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.
Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
Queued for stage1.
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.
---
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);
--
2.34.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-04-05 14:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-05 14:12 [PATCH] debug/105158 - improve debug stmt retaining for forwarder removal Richard Biener
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).