[libc-commits] [PATCH] D152923: [libc] Add support for FMA in the GPU utilities

Tue Ly via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Jun 14 12:05:23 PDT 2023


lntue added a comment.

In D152923#4422026 <https://reviews.llvm.org/D152923#4422026>, @arsenm wrote:

> If you do not care about the precision semantics of FMA, you really don't need to know anything about the target. You should just emit fmul contract or the fmuladd intrinsic (which you get using FP_CONTRACT on the basic expression). The backend trivially then only introduces fma if profitable

Unfortunately, completely relying on backend is not enough for us.  There are cases (at least for math functions) knowing exactly when `fma` instructions are available / unavailable is critical for performance and accuracy, such as using different efficient algorithms:

https://github.com/llvm/llvm-project/blob/main/libc/src/math/generic/log1p.cpp#L997 ,
https://github.com/llvm/llvm-project/blob/main/libc/src/math/generic/tanhf.cpp#L64 ,

or different exceptional values:

https://github.com/llvm/llvm-project/blob/main/libc/src/math/generic/expm1f.cpp#L42

> This is just a bug. The backend should always be able to handle llvm.fma. Whether or not x86 respects nobuiltin when lowering it is another question, but it should always be able to inline > expand it or call into compiler-rt.

I totally agree with you on this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152923/new/

https://reviews.llvm.org/D152923



More information about the libc-commits mailing list