Description
Hello, I noticed that tail call optimization is disabled on MIPS at all optimization levels by default. This is causing issues with the musttail
attribute in C and C++ programs, where tail calls that otherwise would be eligible are not being treated as such.
The relevant flag is defined here:
llvm-project/llvm/lib/Target/Mips/MipsSEISelLowering.cpp
Lines 54 to 56 in 98563b1
When building with -mllvm -mips-tail-calls=1
, tail calls appear to be optimized accordingly (in the few tests I've done). I noticed that there are test cases for this flag throughout the backend (just search for mips-tail-calls=1
).
Here are a few issues that are affected by this behaviour:
#47971
#51709
#57795
Is it possible we could make the MIPS backend behave like the others in this respect? It seems to me that if a call site is marked musttail
, the backend should make every effort towards performing the tail call regardless of the current optimization level. I would be willing to submit a PR for this change if there's interest.