Skip to content

Commit b11529b

Browse files
authored
[libc] Use -fno-math-errno to for __builtin_fma* to generate fma instructions. (llvm#124200)
Fixes llvm#123387
1 parent 4405f72 commit b11529b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

libc/cmake/modules/LLVMLibCCompileOptionRules.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ function(_get_compile_options_from_flags output_var)
2828
elseif(LIBC_TARGET_ARCHITECTURE_IS_RISCV64)
2929
list(APPEND compile_options "-D__LIBC_RISCV_USE_FMA")
3030
endif()
31+
# For clang, we will build the math functions with `-fno-math-errno` so that
32+
# __builtin_fma* will generate the fused-mutliply-add instructions. We
33+
# don't put the control flag to the public config yet, and see if it makes
34+
# sense to just enable this flag by default.
35+
if(LIBC_ADD_FNO_MATH_ERRNO)
36+
list(APPEND compile_options "-fno-math-errno")
37+
endif()
3138
endif()
3239
if(ADD_ROUND_OPT_FLAG)
3340
if(LIBC_TARGET_ARCHITECTURE_IS_X86_64)

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
function(_get_common_test_compile_options output_var c_test flags)
22
_get_compile_options_from_flags(compile_flags ${flags})
33

4+
# Remove -fno-math-errno if it was added.
5+
if(LIBC_ADD_FNO_MATH_ERRNO)
6+
list(REMOVE_ITEM compile_options "-fno-math-errno")
7+
endif()
8+
49
set(compile_options
510
${LIBC_COMPILE_OPTIONS_DEFAULT}
611
${LIBC_TEST_COMPILE_OPTIONS_DEFAULT}

0 commit comments

Comments
 (0)