[libc-commits] [libc] b11529b - [libc] Use -fno-math-errno to for __builtin_fma* to generate fma instructions. (#124200)

via libc-commits libc-commits at lists.llvm.org
Thu Jan 23 17:38:58 PST 2025


Author: lntue
Date: 2025-01-23T20:38:53-05:00
New Revision: b11529bfa26fe8f2abc7d57cd96716a494198327

URL: https://github.com/llvm/llvm-project/commit/b11529bfa26fe8f2abc7d57cd96716a494198327
DIFF: https://github.com/llvm/llvm-project/commit/b11529bfa26fe8f2abc7d57cd96716a494198327.diff

LOG: [libc] Use -fno-math-errno to for __builtin_fma* to generate fma instructions. (#124200)

Fixes https://github.com/llvm/llvm-project/issues/123387

Added: 
    

Modified: 
    libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
    libc/cmake/modules/LLVMLibCTestRules.cmake

Removed: 
    


################################################################################
diff  --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index 1795639011936c..12420db331961b 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -28,6 +28,13 @@ function(_get_compile_options_from_flags output_var)
       elseif(LIBC_TARGET_ARCHITECTURE_IS_RISCV64)
         list(APPEND compile_options "-D__LIBC_RISCV_USE_FMA")
       endif()
+      # For clang, we will build the math functions with `-fno-math-errno` so that
+      # __builtin_fma* will generate the fused-mutliply-add instructions.  We
+      # don't put the control flag to the public config yet, and see if it makes
+      # sense to just enable this flag by default.
+      if(LIBC_ADD_FNO_MATH_ERRNO)
+        list(APPEND compile_options "-fno-math-errno")
+      endif()
     endif()
     if(ADD_ROUND_OPT_FLAG)
       if(LIBC_TARGET_ARCHITECTURE_IS_X86_64)

diff  --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 96fa6c3a707e47..10bb9c9487d636 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -1,6 +1,11 @@
 function(_get_common_test_compile_options output_var c_test flags)
   _get_compile_options_from_flags(compile_flags ${flags})
 
+  # Remove -fno-math-errno if it was added.
+  if(LIBC_ADD_FNO_MATH_ERRNO)
+    list(REMOVE_ITEM compile_options "-fno-math-errno")
+  endif()
+
   set(compile_options
       ${LIBC_COMPILE_OPTIONS_DEFAULT}
       ${LIBC_TEST_COMPILE_OPTIONS_DEFAULT}


        


More information about the libc-commits mailing list