This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa] Tail recursion improvement
- From: Ken Wolcott <ken dot wolcott at med dot ge dot com>
- To: Paolo Carlini <pcarlini at unitus dot it>, Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 9 Dec 2003 15:29:18 -0600
- Subject: Re: [tree-ssa] Tail recursion improvement
- Organization: GEMS-IT
- References: <20031209211011.GA26876@atrey.karlin.mff.cuni.cz> <3FD63C0F.1080307@unitus.it>
- Reply-to: ken dot wolcott at med dot ge dot com
How does it handle the situation when n is initially less than zero?
On Tuesday 09 December 2003 15:18, Paolo Carlini wrote:
> Zdenek Dvorak wrote:
> >Hello,
> >
> >this patch enables tail recursive calls to be optimized in more cases;
> >for example it turns
> >
> >int sum (int n)
> >{
> > if (n == 0)
> > return 0;
> >
> > return n + sum (n - 1);
> >}
> >
> >into
> >
> >int sum (int n)
> >{
> > int acc = 0;
> >
> > for (; n != 0; n--)
> > acc += n;
> >
> > return acc;
> >}
>
> Hey, fantastic Zdenek! I think that all around the world *thousands* of
> students are told something like "an optimizing compiler is able to turn
> the recursive, elegant, formulation of the factorial into the iterative,
> efficient one". Now it's really true for GCC!
>
> Now I wonder: what about Fibonacci? Highly inefficient in the reursive
> formulation, but basically just a sum: fib(n) = fib(n-1) + fib (n-2)??
>
> Paolo.