This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Recursion Optimization
- To: kevinatk at home dot com (Kevin Atkinson)
- Subject: Re: Recursion Optimization
- From: Joe Buck <jbuck at synopsys dot COM>
- Date: Tue, 17 Aug 99 7:14:43 PDT
- Cc: gcc at gcc dot gnu dot org
> Does gcc optimize in any way to minimize the cost of recursive functions
> calls. In particular:
>
> ONE:
>
> Does gcc optimize tail recursive functions into simple loops?
Only in the special case of pure tail recursion (cases where, in effect,
the call can be turned into a goto). Pure tail recursion isn't that
common.
> In a function call like this:
>
> int sum(int i, int stop) {
> if (i == stop) return i;
> else return sum(i+1, stop) + i;
> }
>
> Will gcc recognize that the value of the second parameter never changes
> so that it can avoid allocating multiple copies of it on the stack.
No.