Description
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:
llvm-project/libc/src/__support/FPUtil/FMA.h
Lines 27 to 33 in 5eed019
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
.