This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Recursion Optimization
- To: Andreas Schwab <schwab@suse.de>
- Subject: Re: Recursion Optimization
- From: Kevin Atkinson <kevinatk@home.com>
- Date: Mon, 16 Aug 1999 13:25:54 -0400
- CC: gcc@gcc.gnu.org
- References: <Pine.GSO.4.10.9908161213250.4524-100000@sun00epsl.wam.umd.edu> <jezozrsncl.fsf@hawking.suse.de>
Andreas Schwab wrote:
> |> > |> TWO:
> |> > |>
> |> > |> In a function call like this:
> |> > |>
> |> > |> int sum(int i, int stop) {
> |> > |> }
> |>
> |> > |> 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.
> |> >
> |> > This cannot be avoided.
> ...
> |> Gcc can handel nested functions, so with a smart enough optimization
> |> technoligy it out to be able to rewrite it as
> |>
> |> int sum (int i, int stop) {
> |> int sumh(int i) {
> |> if (i == stop) return i;
> |> else return sum(i+1, stop) + i;
> |> }
> |> return sumh(i);
> |> }
>
> In which way is this different from the previous version? You still have
> the same call to sum which requires a contiguous argument list on the stack.
Stop only gets allocated on the stack once as it is not a parameter of
sumh. Each call to sumh will only allocated a new copy of i, not stop.
Now back to my orignal question:
Will gcc recognize that the value of the __second__ parameter (IE stop)
never change so that it can avoid allocating multiple copies of it on
the stack.
--
Kevin Atkinson
kevinatk@home.com
http://metalab.unc.edu/kevina/