]> git.ipfire.org Git - people/ms/gcc.git/commitdiff
tree-optimization/107447 - avoid hoisting returns-twice calls in LIM
authorRichard Biener <rguenther@suse.de>
Fri, 28 Oct 2022 12:20:36 +0000 (14:20 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 28 Oct 2022 13:07:02 +0000 (15:07 +0200)
The following makes sure to not hoist returns-twice calls in LIM
since we have no way to move the abnormal edge associated with it
and we are prone having stray abnormal edges in the IL which will
then cause IL verification failures even when the actual call
does not return twice.

PR tree-optimization/107447
* tree-ssa-loop-im.cc (determine_max_movement): Do not
hoist returns-twice calls.

* gcc.dg/torture/pr107447.c: New testcase.

gcc/testsuite/gcc.dg/torture/pr107447.c [new file with mode: 0644]
gcc/tree-ssa-loop-im.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr107447.c b/gcc/testsuite/gcc.dg/torture/pr107447.c
new file mode 100644 (file)
index 0000000..06f7b7b
--- /dev/null
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+
+int n;
+
+void
+bar (int, int);
+
+__attribute__ ((noinline, returns_twice)) int
+zero (void)
+{
+  return 0;
+}
+
+void
+foo (void)
+{
+  (void) zero ();
+
+  n = 0;
+
+  for (;;)
+    bar (zero (), n);
+}
index 2ea815050d18b93422bc2add54bf7d6c4d85f9b1..2119d4072d3a9dd36ff5b92b8e7d563b9c8c1c5d 100644 (file)
@@ -835,10 +835,15 @@ determine_max_movement (gimple *stmt, bool must_preserve_exec)
 
       return true;
     }
-  else
-    FOR_EACH_SSA_TREE_OPERAND (val, stmt, iter, SSA_OP_USE)
-      if (!add_dependency (val, lim_data, loop, true))
-       return false;
+
+  /* A stmt that receives abnormal edges cannot be hoisted.  */
+  if (is_a <gcall *> (stmt)
+      && (gimple_call_flags (stmt) & ECF_RETURNS_TWICE))
+    return false;
+
+  FOR_EACH_SSA_TREE_OPERAND (val, stmt, iter, SSA_OP_USE)
+    if (!add_dependency (val, lim_data, loop, true))
+      return false;
 
   if (gimple_vuse (stmt))
     {