[LLVMdev] fastcc, tail calls, and gcc

Jeff Kuskin jk500500 at yahoo.com
Fri Feb 13 06:57:59 PST 2009


--- On Thu, 2/12/09, Arnold Schwaighofer <arnold.schwaighofer at gmail.com> wrote:

> From: Arnold Schwaighofer <arnold.schwaighofer at gmail.com>
> Subject: Re: [LLVMdev] fastcc, tail calls, and gcc
> To: "LLVM Developers Mailing List" <llvmdev at cs.uiuc.edu>
> Date: Thursday, February 12, 2009, 6:56 PM
> On Thu, Feb 12, 2009 at 5:34 PM, Jeff Kuskin
> <jk500500 at yahoo.com> wrote:
> > Two related questions.
> 
> > (2) Why does the x86-64 JIT backend generate a
> "ret $0x8" instruction
> > to return from a fastcc function that is (a) marked as
> fastcc
> > (CallingConv::Fast); but (b) takes no arguments and
> returns 'void'?
>  fastcc generated code ends with this:
> >      c20800  ret $0x8
> > I assume the "ret 0x8" is meant to be the
> "callee pops args" portion
> > of the fastcc convention, but in this case the
> function has no
> > arguments (nor a return value), so why should 8 bytes
> be popped from
> > the stack on return?
>  If i remember correctly this has to do with stack
> alignment and tail
> calls. Note that to support tail calls between functions
> that have an
> arbitrary number of arguments the stack pointer of the
> caller of the
> tail calling function is modified.
> e.g if foo(i64) tail calls bar() the stack pointer of
> foo's caller
> would be adjusted by 8 bytes which could result in a
> misaligned stack
> (assuming a platform alignment of 16) on entry to the
> function bar.
> Hence when tailcallopt is enabled the size occupied by
> arguments is
> rounded up such that such a misalignment cant happen.


Hmmm.  I think I understand, but I don't see how the "ret 8" is
correct for a function that has no arguments.  In this case,
it seems to me that the "size occupied by the arguments" is zero,
and should remain zero even after rounding up.  Perhaps I
misunderstand.  Let me try to generate an actual testcase
with real C and x86 asm code.

Thanks.

-- Jeff

> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev


      



More information about the llvm-dev mailing list