runtime icon indicating copy to clipboard operation
runtime copied to clipboard

fgCanFastTailCall() is conservative and disallows many possible fast tail calls on x64 Linux and Arm64

Open sivarv opened this issue 10 years ago • 3 comments

fgCanFastTailCall() is meant for performing ABI or architecture specific checks to see if a tail call can be dispatched as epilog+jmp. This routine is originally written keeping Windows Amd64 ABI in mind. Later it got adopted for Linux Amd64 and Arm64 with minor modification and in its present form is conservative in the following ways

  1. On Linux integer and floating point params do not share the same argument number space. This would mean the following calls can be fast tail called but which are not e.g. Caller(int a, int b, int c, int d, int e, int f) --> Callee(int a, int b, int c, int d, int e, int f, float/double x1) caller(int a, int b, int c, int d, int e, int f) --> Callee(float x1, float x2,..., float x8)

  2. Struct params that are passed in two registers to Callee. These are counted as two Callee arguments. But the same is not done for Caller arguments. As a result, the following call is not fast tail called

struct structofsize15 { } Caller(a, b, c, d, e, structofSize15) -> Callee(a,b,c,d,e, structofSize15)

sivarv avatar Jan 14 '16 22:01 sivarv

Moving to future to align with other opt issues. Will bring back if this is deemed necessary during RTM perf push.

RussKeldorph avatar Mar 24 '16 16:03 RussKeldorph

As in https://github.com/dotnet/coreclr/pull/4791, ARM64 also has similar issue since a struct can be passed in two registers.

kyulee1 avatar May 06 '16 20:05 kyulee1

Could this be all made moot by using a different calling convention for tail calls? That would allow all tail calls to be fast.

I suspect that Mono does this when compiling via LLVM.

DemiMarie avatar Jul 20 '16 04:07 DemiMarie