public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Guenther <richard.guenther@gmail.com>
To: Zdenek Dvorak <rakdver@kam.mff.cuni.cz>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [patch] PR 48837
Date: Fri, 06 May 2011 11:49:00 -0000	[thread overview]
Message-ID: <BANLkTi=_YEDxVw-n_EC7mn8bczAC=YaYng@mail.gmail.com> (raw)
In-Reply-To: <20110506104417.GA8664@kam.mff.cuni.cz>

On Fri, May 6, 2011 at 12:44 PM, Zdenek Dvorak <rakdver@kam.mff.cuni.cz> wrote:
> Hi,
>
> when accumulator transformation is performed on a function like
>
> foo(a)
> {
>  if (a > 0)
>    return 1 + foo (a - 1)
>
>  return bla();
> }
>
> this becomes
>
> foo(a)
> {
>  int tmp = 0;
>
>  while (a > 0)
>    tm = 1 + tmp;
>
>  return tmp + bla();
> }
>
> Before, bla was a tail-call, but after the optimization, it is not (since an addition
> has to be performed after the result of bla is known).  However, we used to mark bla
> as tail-call, leading to a misscompilation later.  Fixed by not marking tail-calls
> when the transformation is performed.  Bootstrapped and regtested on i686.

Ok.

Thanks,
Richard.

> Zdenek
>
>        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.
>
> Index: tree-tailcall.c
> ===================================================================
> --- tree-tailcall.c     (revision 173354)
> +++ tree-tailcall.c     (working copy)
> @@ -1021,6 +1021,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;
> Index: testsuite/gcc.dg/pr48837.c
> ===================================================================
> --- testsuite/gcc.dg/pr48837.c  (revision 0)
> +++ testsuite/gcc.dg/pr48837.c  (revision 0)
> @@ -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;
> +}
> +
>

  reply	other threads:[~2011-05-06 11:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-06 10:47 Zdenek Dvorak
2011-05-06 11:49 ` Richard Guenther [this message]
2011-05-06 15:19 ` Jeff Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='BANLkTi=_YEDxVw-n_EC7mn8bczAC=YaYng@mail.gmail.com' \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rakdver@kam.mff.cuni.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).