Issue 126025
Summary Clang should provide intrinsic that lowers directly to `llvm.fma.*` intrinsic
Labels clang
Assignees
Reporter petrhosek
    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`.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to