]> 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:45:50 +0000 (10:45 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 10 May 2011 08:45:50 +0000 (10:45 +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: r173610

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

index 8e6fe76cc2eab21d0b45caacf80e44d6bb86a1ed..635fe99277b458dc0ad5ac3c9ba8039cf3b0667f 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-09  Eric Botcazou  <ebotcazou@adacore.com>
 
        * var-tracking.c (find_mem_expr_in_1pdv): Fix thinko.
index d05d1be9ddbac21050cc699f361d738c5e4eaf98..bab036cf2e0614c3f37d5a1e466b765211a52553 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 a9bbc9796019f53992b87e7f508b1f65faf52bad..92e510a236009f7826fbe6fe4e27c7efc666365a 100644 (file)
@@ -1007,6 +1007,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;