Open hiraditya opened 8 months ago
@llvm/issue-subscribers-backend-risc-v
Author: AdityaK (hiraditya)
RISCV's tail call eligibility check is a bit simplistic and bails if it sees arguments passed on the stack. To fully support musttail (and optimise more cases) it needs to also handle when the arguments passed on the stack fit in our frame.
Thanks for sharing the testcase. copy-pasting here for posterity
void foo(int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8);
void bar(int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) {
[[clang::musttail]] return foo(a0, a1, a2, a3, a4, a5, a6, a7, a8);
}
$ rv64gc-clang -O2
0. Program arguments: /opt/compiler-explorer/clang-17.0.1/bin/clang -g -o /app/output.s -S -target riscv64-unknown-linux-gnu -march=rv64gc -mabi=lp64d --gcc-toolchain=/opt/compiler-explorer/riscv64/gcc-8.2.0/riscv64-unknown-linux-gnu --sysroot=/opt/compiler-explorer/riscv64/gcc-8.2.0/riscv64-unknown-linux-gnu/riscv64-unknown-linux-gnu/sysroot -fcolor-diagnostics -fno-crash-diagnostics -O2 <source>
1. <eof> parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module '<source>'.
4. Running pass 'RISC-V DAG->DAG Pattern Instruction Selection' on function '@bar'
#0 0x0000000003349f18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-17.0.1/bin/clang+0x3349f18)
#1 0x0000000003348044 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-17.0.1/bin/clang+0x3348044)
#2 0x000000000329c553 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-17.0.1/bin/clang+0x329c553)
#3 0x000000000334007e llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-17.0.1/bin/clang+0x334007e)
#4 0x0000000000bd3b76 (/opt/compiler-explorer/clang-17.0.1/bin/clang+0xbd3b76)
#5 0x00000000032a5583 llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-17.0.1/bin/clang+0x32a5583)
#6 0x00000000032a56e8 (/opt/compiler-explorer/clang-17.0.1/bin/clang+0x32a56e8)
#7 0x0000000001d03bda llvm::RISCVTargetLowering::LowerCall(llvm::TargetLowering::CallLoweringInfo&, llvm::SmallVectorImpl<llvm::SDValue>&) const (/opt/compiler-explorer/clang-17.0.1/bin/clang+0x1d03bda)
Because of this skia had to disable
musttail
for RISC-V https://skia.googlesource.com/skcms/+/529510fe003a3ccbf2d0d76939bf49f88b825177%5E%21/src/skcms_internals.hUnofortunately I dont have a small repro testcase.