<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/107730>107730</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
MIPS tail calls are disabled by default at all optimization levels
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
InBetweenNames
</td>
</tr>
</table>
<pre>
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:
https://github.com/llvm/llvm-project/blob/98563b19c2d13bac7fb5ee2717ccae6279699e4c/llvm/lib/Target/Mips/MipsSEISelLowering.cpp#L54-L56
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:
https://github.com/llvm/llvm-project/issues/47971
https://github.com/llvm/llvm-project/issues/51709
https://github.com/llvm/llvm-project/issues/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.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVUGP2zYT_TX0ZWBDpizLOuiQTT4jBjYfgu4CPQ_JkcQsJQocysb21xekd2O3aQu0uUiARM48vvfmEZltPxG1onoQ1acVLnHwoT1NDxQvRNP_cSReKW9e28_knBfyI5xg8tFqMhAHjBDROtDoHPg52tH-htH6CSyDsYzKkQE_wZfT1yfACD-sc3Qmx6BewVCHi4sbAHgeLKcKGhe2Uw-WeSGGi40DxIFA7Itx4Zhai30BGGOwaokEdoKPgJOBj0I-CPkAc_B9wJET8MtAgW54-Yrfx4HCxTLBxS_OgCIgZ3urHAEGSocFRQlFDISRDCADL3rYi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