This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Recursion Optimization
- To: Zack Weinberg <zack@bitmover.com>
- Subject: Re: Recursion Optimization
- From: Branko Cibej <branko.cibej@hermes.si>
- Date: Tue, 17 Aug 1999 10:27:16 +0200
- CC: Kevin Atkinson <kevinatk@home.com>, gcc@gcc.gnu.org
- Organization: HERMES SoftLab
- References: <199908161800.LAA25487@zack.bitmover.com>
Zack Weinberg wrote:
> A genius compiler would recognize that
> the values pushed on the stack are predictable, and generate
>
> int sum(int i, int stop)
> {
> int tmp = 0;
> while(i <= stop) tmp += i++;
> return tmp;
> }
And a genius compiler who had also gone to school would recognise
that as a sum of a sequence and generate
int sum (int i, int stop)
{
return (stop * (stop + 1) - i * (i + 1)) / 2;
}
-- then get it wrong if i or stop are negative.
That would be fixed in the next release, of course ;-)
Brane
--
Branko Čibej <branko.cibej@hermes.si>
HERMES SoftLab, Litijska 51, 1000 Ljubljana, Slovenia
voice: (+386 61) 186 53 49 fax: (+386 61) 186 52 70