[LLVMdev] fastcc, tail calls, and gcc

Arnold Schwaighofer arnold.schwaighofer at gmail.com
Thu Feb 12 15:56:42 PST 2009


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.



More information about the llvm-dev mailing list