public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-5958] tree-optimization/106722 - fix CD-DCE edge marking
@ 2023-02-13  7:27 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-02-13  7:27 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:338739645b8e5bf34636d8d4829d7650001ad08c

commit r13-5958-g338739645b8e5bf34636d8d4829d7650001ad08c
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Feb 10 10:28:29 2023 +0100

    tree-optimization/106722 - fix CD-DCE edge marking
    
    The following fixes a latent issue when we mark control edges but
    end up with marking a block with no stmts necessary.  In this case
    we fail to mark dependent control edges of that block.
    
            PR tree-optimization/106722
            * tree-ssa-dce.cc (mark_last_stmt_necessary): Return
            whether we marked a stmt.
            (mark_control_dependent_edges_necessary): When
            mark_last_stmt_necessary didn't mark any stmt make sure
            to mark its control dependent edges.
            (propagate_necessity): Likewise.
    
            * gcc.dg/torture/pr108737.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr108737.c | 19 +++++++++++++++++++
 gcc/tree-ssa-dce.cc                     | 20 +++++++++++++-------
 2 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr108737.c b/gcc/testsuite/gcc.dg/torture/pr108737.c
new file mode 100644
index 00000000000..c8388bcabeb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr108737.c
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+
+extern void exit (int);
+extern void abort (void);
+
+void __attribute__((noipa)) foo () { exit (0); }
+
+void __attribute__((noipa)) blah (int x)
+{
+  while (1) {
+      if(x) foo();
+  }
+}
+
+int main()
+{
+  blah (1);
+  abort ();
+}
diff --git a/gcc/tree-ssa-dce.cc b/gcc/tree-ssa-dce.cc
index 1f1ec2c8710..ceeb0ad5ab3 100644
--- a/gcc/tree-ssa-dce.cc
+++ b/gcc/tree-ssa-dce.cc
@@ -327,17 +327,23 @@ mark_stmt_if_obviously_necessary (gimple *stmt, bool aggressive)
 
 /* Mark the last statement of BB as necessary.  */
 
-static void
+static bool
 mark_last_stmt_necessary (basic_block bb)
 {
   gimple *stmt = last_stmt (bb);
 
-  bitmap_set_bit (last_stmt_necessary, bb->index);
+  if (!bitmap_set_bit (last_stmt_necessary, bb->index))
+    return true;
+
   bitmap_set_bit (bb_contains_live_stmts, bb->index);
 
   /* We actually mark the statement only if it is a control statement.  */
   if (stmt && is_ctrl_stmt (stmt))
-    mark_stmt_necessary (stmt, true);
+    {
+      mark_stmt_necessary (stmt, true);
+      return true;
+    }
+  return false;
 }
 
 
@@ -369,8 +375,8 @@ mark_control_dependent_edges_necessary (basic_block bb, bool ignore_self)
 	  continue;
 	}
 
-      if (!bitmap_bit_p (last_stmt_necessary, cd_bb->index))
-	mark_last_stmt_necessary (cd_bb);
+      if (!mark_last_stmt_necessary (cd_bb))
+	mark_control_dependent_edges_necessary (cd_bb, false);
     }
 
   if (!skipped)
@@ -790,8 +796,8 @@ propagate_necessity (bool aggressive)
 		  if (gimple_bb (stmt)
 		      != get_immediate_dominator (CDI_POST_DOMINATORS, arg_bb))
 		    {
-		      if (!bitmap_bit_p (last_stmt_necessary, arg_bb->index))
-			mark_last_stmt_necessary (arg_bb);
+		      if (!mark_last_stmt_necessary (arg_bb))
+			mark_control_dependent_edges_necessary (arg_bb, false);
 		    }
 		  else if (arg_bb != ENTRY_BLOCK_PTR_FOR_FN (cfun)
 		           && !bitmap_bit_p (visited_control_parents,

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-13  7:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-13  7:27 [gcc r13-5958] tree-optimization/106722 - fix CD-DCE edge marking 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).