]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR tree-optimization/48837 (Wrong optimization of recursive function...
authorJakub Jelinek <jakub@redhat.com>
Tue, 10 May 2011 08:47:09 +0000 (10:47 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 10 May 2011 08:47:09 +0000 (10:47 +0200)
Backported from mainline
2011-05-07  Zdenek Dvorak  <ook@ucw.cz>

PR tree-optimization/48837
* tree-tailcall.c (tree_optimize_tail_calls_1): Do not mark tailcalls
when accumulator transformation is performed.

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

From-SVN: r173611

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr48837.c [new file with mode: 0644]
gcc/tree-tailcall.c

index fe0fc6a1146fc3636133cb8f69991fd37b7e71c6..145b36ab238bc594544e749ff676e4b8f1dd41fe 100644 (file)
@@ -1,3 +1,12 @@
+2011-05-10  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2011-05-07  Zdenek Dvorak  <ook@ucw.cz>
+
+       PR tree-optimization/48837
+       * tree-tailcall.c (tree_optimize_tail_calls_1): Do not mark tailcalls
+       when accumulator transformation is performed.
+
 2011-05-05  Jason Merrill  <jason@redhat.com>
 
        PR c++/40975
index e22b269a4a2043913e67350161ccc3622626a83c..8e1852893d180e05f5e9777500cce62fdd4efe22 100644 (file)
@@ -1,3 +1,11 @@
+2011-05-10  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2011-05-07  Zdenek Dvorak  <ook@ucw.cz>
+
+       PR tree-optimization/48837
+       * gcc.dg/pr48837.c: New testcase.
+
 2011-05-09  Jason Merrill  <jason@redhat.com>
 
        * g++.dg/template/nontype23.C: New.
diff --git a/gcc/testsuite/gcc.dg/pr48837.c b/gcc/testsuite/gcc.dg/pr48837.c
new file mode 100644 (file)
index 0000000..ffc65b9
--- /dev/null
@@ -0,0 +1,30 @@
+/* PR tree-optimization/48837 */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+void abort (void);
+
+__attribute__((noinline))
+int baz(void)
+{
+  return 1;
+}
+
+inline const int *bar(const int *a, const int *b)
+{
+ return *a ? a : b;
+}
+
+int foo(int a, int b)
+{
+   return a || b ? baz() : foo(*bar(&a, &b), 1) + foo(1, 0);
+}
+
+int main(void)
+{
+ if (foo(0, 0) != 2)
+   abort();
+
+ return 0;
+}
+
index 9d2513d271dc70931732e4c34688ebd58961d830..55cdc51042ca2580eb6456848038fd0691444e21 100644 (file)
@@ -953,6 +953,14 @@ tree_optimize_tail_calls_1 (bool opt_tailcalls)
                                             integer_one_node);
     }
 
+  if (a_acc || m_acc)
+    {
+      /* When the tail call elimination using accumulators is performed,
+        statements adding the accumulated value are inserted at all exits.
+        This turns all other tail calls to non-tail ones.  */
+      opt_tailcalls = false;
+    }
+
   for (; tailcalls; tailcalls = next)
     {
       next = tailcalls->next;