<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/126025>126025</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang should provide intrinsic that lowers directly to `llvm.fma.*` intrinsic
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
petrhosek
</td>
</tr>
</table>
<pre>
Clang already provides the `__builtin_fma` builtin intrinsic which is lowered either to `fma` call or `llvm.fma.*` Intrinsic depending on whether math `errno` is used or not (i.e. `-f[no-]math-errno`). This behavior makes [`__builtin_fma` unsuitable for implementing libc `fma` because unless libc is compiled with `-fno-math-errno`, on targets where math `errno` is used, this would result in an infinite recursion.
We encountered this issue in LLVM libc: https://github.com/llvm/llvm-project/blob/5eed019080a53af5a5be915a5cf411466b77bf4b/libc/src/__support/FPUtil/FMA.h#L27-L33
On baremetal targets where math `errno` is used, the `__builtin_fma` call is lowered to `fma` call resulting a function trivially calling itself. The current workaround is to compile LLVM libc with `-fno-math-errno`, but that is generally undesirable.
Ideally, Clang would provide a separate builtin intrinsic that always lowers to `llvm.fma.*` Intrinsic regardless of math `errno` behavior. We could then use this intrinsic to implement `fma`.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVE2P2zgM_TXKhYihyFbGOfiQtghQYIrdw-72OJBkOuaOLBn6mCD_fiHH03TbGRS9JLbFR_I9PkrFSGeH2DH5gclPG5XT6EM3Ywqjj_i80b6_dh-tcmdQNqDqrzAH_0I9RkgjAtvzpyedySZyT8Ok2J7D-grkUiAXycBlJDMCRbD-ggF7QEojBki-JFhhRlkLPpQv1r5M1TCpioljOfr8LVOPM7qe3Bm8g8uIS5pJpbHAMATnSzxFyBH7ks35BEy0VGFVQrYDkx-c3zL5qaC2rxAmDhX8NVIEjaN6IV-yPmOEIswbHLOLmZLSFmHwAWiaLU7oUunMkjbf8dJoVI4I2VmM8XZKEYyfZrLYw4Vu3W8H57c_NPWx0EwqnDHFQjfgu2RLcCoELj7bHgLGbBOQA1UmMZCjhBDQ5BDJu4rxI-PHrwjojM8uLWNZ8BRjxgJ8fPzny9Iuq48wpjRHVh-ZODFxOlMas66Mn5g4lWmtf9s5-H_RJCZO2nrNxEki9nx34C1XslaDVFLjYSeVNEOz2zX7vX540ENTQpdS4hRD-X16inmefSipTn_-nciWhy_HamSifhQP28e6vnH4w4FWASdMyv6WVm-7d7Hhd1b92aM3acukFQzZmURlSIFeSFl7XWLKIaWIdiiuQjA5BHQJLj48q-Cz60uJ5F9dcNf6F3bQOUEaVSrwMzoMS8nseowUih3XwX7usZwUyG17b65YdxcURJxVUAnf2NYlv7IXdV1ViKsI769lwLMK_eJvP_ws--tOVfAVwSydpBFdmcXquXtxf1-mu_DVpu_q_lAf1Aa73UPdtrWoebMZOzHs6mZfH6TiktcPZm8aY4xuuOH9AWW7oU5wIbnge97KVjTVcOCNlK1uBW-NPkjWcJwU2Wqh58N5s2xAtxN7LuTGKo02LhekEKZoyYQod2XoFsfrfI6s4ZZiivcUiZLF9eKM4_-0_0HoVeGeAppkr-9I_Q20ycF2v72MC6PIxGkl9dKJ_wIAAP__NN8BNg">