[llvm] Enable logf128 constant folding for hosts with 128bit long double (PR #96287)

Matthew Devereau via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 16 01:07:52 PDT 2024


================
@@ -271,6 +260,64 @@ if(C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW)
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unguarded-availability-new")
 endif()
 
+function(logf128_test testname definition)
+  unset(LOGF128_TEST_RUN CACHE)
+  unset(LOGF128_TEST_COMPILE CACHE)
+  try_run(
+    LOGF128_TEST_RUN
+    LOGF128_TEST_COMPILE
+    ${CMAKE_CURRENT_BINARY_DIR}
+    ${CMAKE_CURRENT_BINARY_DIR}/logf128_${testname}.cpp
+    LINK_LIBRARIES m
+  )
+  if(LOGF128_TEST_RUN)
+    set (LLVM_HAS_LOGF128 true CACHE INTERNAL "")
+    set(${definition} true CACHE INTERNAL "")
+    message(STATUS "LLVM: found logf128 with type ${testname}")
+    add_compile_definitions(${definition})
+  endif()
+endfunction()
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/logf128_long_double.cpp"
+"
+extern \"C\" {
+long double logf128(long double);
----------------
MDevereau wrote:

The reason I ended up doing things this way is because Clang on x86 doesn't pick up the logf128 symbol when including cmath. Clang just doesn't seem to have the magic definitions to unlock it like GCC does. It's probably okay to include cmath for long double and _Float128, but for clang I think we do need to explicitly declare the function prototype to get it working on x86.

https://github.com/llvm/llvm-project/pull/96287


More information about the llvm-commits mailing list