fgCanFastTailCall() is conservative and disallows many possible fast tail calls on x64 Linux and Arm64
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
-
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)
-
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)
Moving to future to align with other opt issues. Will bring back if this is deemed necessary during RTM perf push.
As in https://github.com/dotnet/coreclr/pull/4791, ARM64 also has similar issue since a struct can be passed in two registers.
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.