<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=http://email.email.llvm.org/c/eJytVVuPozYU_jXwYhWBExJ44CGz01ajzkPVRuruU2XsE_CMY0e2SSbz63sw5MZm1JF2UQIcOJfvfOdCbcSxitLHKF393dVm5-WWKcKNALIxlngmUWJKoaSUOYAg9ZF02gLjLasVDKbjeZGOvyAK4IpZIHsjBYnmae8GIKKFXMwjWl5bCthIfdEELdxB-vbf60DBjkQ0T9GYRMsHgsdg3t9dkN6Ld7K76H-fw_LxM5As-M7qn40GvQbNKZRbRtetdOTpL4JnbrY7qbAczJEasDLJGL31fuei2Sqiv-GvMaI2yifGNii94__38sX--v7N_HM3wl3mZwHi5Ijo7MNSndPqj13n2pAie7t9EegZr8jMPP3zeT1BMZJ9F8BdFKPBTZyX7Y5M43zsbb16ev6yen6-S8_1ed3iiHSae2k06QGQHgFB3XPx8f5mblA-FxpfcWTMgyPsql1OPhB0cg770HlyaEET_2HMm0n50ntn_eMTir5jQjSBdUAvONkt04POOfgl4BNxXdOA8wRd6kbqhmys2V579Oa7VGGPEOXmcyiTCalPyFSnBRojVulcB5gydjiOhjNq30Po_Zr6xRujIrp0WK5CSd29kVewGoZnw8uSHJjVATYusSh_eMzSPFuUUf6IRrcjYmEv4eASpfbbcU5O2rRMRnAbcjQdOtW-T5y3wF8HOFYiO7gxd9ZgUlvkPmhyJBf3hwhKFkTHkfk9WNdTYgaKBtTDrmWe_N_gum9va6fb_A_C0G8DGmyoJ-6D4IIbjdUISU_6oW-GqX-m5B7oddIcToHe22b1kMSimolyVrKYdb41tmqPYHRz7F7lNu6sqiaAscRdneBeQqF3O15-QWZegHsUQ1Ud3uSzLCvitqIFXcJciCVGmS2LTbmoiyLPaC7mUNZMxIrhbnMVFjCitGb8FbsJI34tFihjMeMfRyErmlKaZlmWzvKc0qRYpMuUF8DLDJZzyvv1ssU2P3MV2yq4rLvG4Uslnb90T8yck40GCKARoZdeQTX5tmL1Pvd5jQPaKkD9D6OuWKY>53118</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Suboptimal codegen for tail call followed by unreachable
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:X86
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hyeongyukim
</td>
</tr>
</table>
<pre>
Suboptimal code for tail call followed by unreachable
```
declare void @callee(i64)
define void @endswith_unreachable(i64 %0) {
tail call void @callee(i64 %0)
unreachable
}
define void @endswith_return(i64 %0) {
tail call void @callee(i64 %0)
ret void
}
```
This IR is compiled as below.
https://godbolt.org/z/G9jrEzYoW
```
endswith_unreachable: # @endswith_unreachable
push rax
call callee@PLT
endswith_return: # @endswith_return
jmp callee@PLT # TAILCALL
```
The function ends with `tail call` followed by `ret void` creates a tail call with `jmp.`
But when the function ends with `unreachable,` a `call` is created rather than a `tail call.`
I suggest changing from `call` to `tail call` even if the function ends with `unreachable.`
I found this issue while resolving the objtool's (linux kernel's tool) warning for [D105169](https://reviews.llvm.org/D105169).
If you want to check the original problem, you can find the reduced version of the kernel code at https://godbolt.org/z/sYxTsnh5K and generated IR code containing `unreachable` at https://alive2.llvm.org/ce/z/szhgAB.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVUuPqzYU_jWwsYqMMyRhwSJzp61GnUXVRmrvqjLmBDzj2JEfyWR-fQ-GvLgZdRZFCXDgPL7znQe1aY5VQp8Suvoz1Gbn5ZYrIkwDZGMs8VyixJVCSSlzgIbURxK0BS46XisYTMfznI6_KDYgFLdA9kY2JHmgvRuAhC3l_CFh5bVlAxupL5qgG3eQvvvnOlC0IwkrKBqTZPFI8BjM-7sL0nvxTnYX_R9zWDx9BZIFH6z-v9Gg16g5hXLL6LqTjjz_QfAszHYnFZaDO1IDViYbo3fe71wyWyXsF_y1pqmN8pmxLUof-P-1fLU_f3w3f92NcJf5WYQ4ORI2-7RU57T6YxdcF1Pk77cvIj3jFZl5oL-_rCcoRrLvAri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