[LLVMdev] Query on optimization and tail call.

Basile STARYNKEVITCH basile at starynkevitch.net
Tue Jun 10 23:38:42 PDT 2008

Eli Friedman wrote:
> On Tue, Jun 10, 2008 at 11:07 PM, Mahadevan R <mdevan.foobar at gmail.com> wrote:
>> int sum(int n)
>> {
>>    return n + sum(n-1);
>> }

Sorry, but this is not a tail recursive call. There is some computation 
involved (the addition) after the inner call to sum! The continuation of 
the inner call to sum is not the continuation of the called sum.

In other words, the equivalent in languages or implementations claiming 
to know about tail recursion (Scheme, Ocaml) is not compiled like tail 

So I believe that llvm should not handle something which is not a tail 
call like a tail call!

Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***

More information about the llvm-dev mailing list