Re: Tail recursion

mrs@kithrup.com (Mike Stump)
21 Aug 2000 00:06:33 -0400

          From comp.compilers

Related articles
Tail recursion strohm@airmail.net (2000-08-10)
Re: Tail recursion pfaffben@msu.edu (Ben Pfaff) (2000-08-13)
Re: Tail recursion danwang+news@cs.princeton.edu (Daniel C. Wang) (2000-08-14)
Re: Tail recursion toon@moene.indiv.nluug.nl (Toon Moene) (2000-08-14)
Re: Tail recursion fjh@cs.mu.OZ.AU (2000-08-21)
Re: Tail recursion Wilco.Dijkstra@arm.com (Wilco Dijkstra) (2000-08-21)
Re: Tail recursion mrs@kithrup.com (2000-08-21)
Re: Tail recursion ian0kerr@my-deja.com (2000-09-08)
Tail recursion Alexey.Mikhailov@gmail.com (jjb) (2006-11-04)
Re: Tail recursion kym@ukato.freeshell.org (russell kym horsell) (2006-11-04)
Re: Tail recursion diablovision@yahoo.com (2006-11-05)
Re: Tail recursion owong@castortech.com (Oliver Wong) (2006-11-08)
Re: Tail recursion jboehm@gmx.net (=?ISO-8859-1?Q?J=FCrgen_B=F6hm?=) (2007-02-04)
| List of all articles for this month |
From: mrs@kithrup.com (Mike Stump)
Newsgroups: comp.compilers
Date: 21 Aug 2000 00:06:33 -0400
Organization: Kithrup Enterprises, Ltd.
References: 00-08-054 00-08-071 00-08-089
Keywords: optimize

Daniel C. Wang <danwang+news@cs.princeton.edu> wrote:
>Ben Pfaff <pfaffben@msu.edu> writes:
>
>> strohm@airmail.net (John R. Strohm) writes:
>>
>> > Do any of the commonly-available compilers for "mainstream" languages
>> > do tail recursion optimization? In particular, any C, c++, or Ada
>> > compilers?
>>
>> The GCC compiler suite does tail recursion optimization at least
>> for C and C++ and probably for its other languages as well.
>
>But only "intra-procedurally"
>
>Last I checked gcc didn't turn the above program into
>
>even:
> if (n == 0) {
> exit(0)
> } else {
> n--;
> goto odd;
> }


How does that differ from the output of gcc:


even:
                !#PROLOGUE# 0
                !#PROLOGUE# 1
                sethi %hi(n), %o0
                or %o0, %lo(n), %o3
                ld [%o3], %o1
                mov 0, %o0
                cmp %o1, 0
                bne .LL3
                add %o1, -1, %o2
                sethi %hi(exit), %g1
                jmpl %g1 + %lo(exit), %g0
                  nop
.LL3:
                sethi %hi(odd), %g1
                jmpl %g1 + %lo(odd), %g0
                st %o2, [%o3]
.LLfe1:
                .size even,.LLfe1-even


?


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.