public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/109331 - make sure to clean up the CFG after forwprop
@ 2023-03-29 11:55 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-03-29 11:55 UTC (permalink / raw)
  To: gcc-patches

When forwprop discovers unreachable code or makes decisions based
on unreachable edges make sure to cleanup the CFG since otherwise
SSA form can become invalid.

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

	PR tree-optimization/109331
	* tree-ssa-forwprop.cc (pass_forwprop::execute): When we
	discover a taken edge make sure to cleanup the CFG.

	* gcc.dg/torture/pr109331.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr109331.c | 16 ++++++++++++++++
 gcc/tree-ssa-forwprop.cc                |  6 +++++-
 2 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr109331.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr109331.c b/gcc/testsuite/gcc.dg/torture/pr109331.c
new file mode 100644
index 00000000000..72c57b9b74c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr109331.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+
+char *ustol_dpp;
+void ustol(int flags)
+{
+  char *s;
+  if (s)
+    flags |= 3;
+  switch (flags & 3)
+  case 3:
+    while (*s)
+    case '+':
+      ++s;
+  if (flags)
+    ustol_dpp = s;
+}
diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index bb0fa306312..9b567440ba4 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -4046,7 +4046,11 @@ pass_forwprop::execute (function *fun)
 
       /* Mark outgoing exectuable edges.  */
       if (edge e = find_taken_edge (bb, NULL))
-	e->flags |= EDGE_EXECUTABLE;
+	{
+	  e->flags |= EDGE_EXECUTABLE;
+	  if (EDGE_COUNT (bb->succs) > 1)
+	    cfg_changed = true;
+	}
       else
 	{
 	  FOR_EACH_EDGE (e, ei, bb->succs)
-- 
2.35.3

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

only message in thread, other threads:[~2023-03-29 11:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-29 11:55 [PATCH] tree-optimization/109331 - make sure to clean up the CFG after forwprop 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).