]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/109327 - forwprop stmt removal issue
authorRichard Biener <rguenther@suse.de>
Wed, 29 Mar 2023 07:51:58 +0000 (09:51 +0200)
committerRichard Biener <rguenther@suse.de>
Wed, 29 Mar 2023 08:34:22 +0000 (10:34 +0200)
There's interfering between the to_removed queue and other mechanisms
removing stmts, in this case remove_prop_source_from_use.  The following
makes the to_remove queue draining more permissive.

PR tree-optimization/109327
* tree-ssa-forwprop.cc (pass_forwprop::execute): Deal with
already removed stmts when draining to_remove.

* gcc.dg/pr109327.c: New testcase.

gcc/testsuite/gcc.dg/pr109327.c [new file with mode: 0644]
gcc/tree-ssa-forwprop.cc

diff --git a/gcc/testsuite/gcc.dg/pr109327.c b/gcc/testsuite/gcc.dg/pr109327.c
new file mode 100644 (file)
index 0000000..827b26f
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fno-tree-ccp" } */
+
+int a;
+void b(int c) {}
+int main()
+{
+  int d = 0, *e = &a;
+  if (d) {
+    int *f = e;
+    while (a)
+      b(e != f);
+  }
+  return 0;
+}
index 5eccc7a89b59eaa288199e5b5c1dff1bd64e0c5a..bb0fa306312fa3a10dfd03336da05ea3435c90c3 100644 (file)
@@ -4061,6 +4061,10 @@ pass_forwprop::execute (function *fun)
   while (!to_remove.is_empty())
     {
       gimple *stmt = to_remove.pop ();
+      /* For example remove_prop_source_from_use can remove stmts queued
+        for removal.  Deal with this gracefully.  */
+      if (!gimple_bb (stmt))
+       continue;
       if (dump_file && (dump_flags & TDF_DETAILS))
        {
          fprintf (dump_file, "Removing dead stmt ");