59 lines
1.3 KiB
Diff
59 lines
1.3 KiB
Diff
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.
|
|
|
|
--- gcc/tree-tailcall.c (revision 173533)
|
|
+++ gcc/tree-tailcall.c (revision 173534)
|
|
@@ -1021,6 +1021,14 @@ tree_optimize_tail_calls_1 (bool opt_tai
|
|
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;
|
|
--- gcc/testsuite/gcc.dg/pr48837.c (revision 0)
|
|
+++ gcc/testsuite/gcc.dg/pr48837.c (revision 173534)
|
|
@@ -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;
|
|
+}
|
|
+
|