Skip to content

Commit ccb2b01

Browse files
authored
Enable logf128 constant folding for hosts with 128bit floats (#96287)
Hosts which support a float size of 128 bits can benefit from constant fp128 folding.
1 parent 1b80ed4 commit ccb2b01

File tree

7 files changed

+18
-33
lines changed

7 files changed

+18
-33
lines changed

llvm/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,6 @@ set(LLVM_USE_STATIC_ZSTD FALSE CACHE BOOL "Use static version of zstd. Can be TR
560560

561561
set(LLVM_ENABLE_CURL "OFF" CACHE STRING "Use libcurl for the HTTP client if available. Can be ON, OFF, or FORCE_ON")
562562

563-
set(LLVM_HAS_LOGF128 "OFF" CACHE STRING "Use logf128 to constant fold fp128 logarithm calls. Can be ON, OFF, or FORCE_ON")
564-
565563
set(LLVM_ENABLE_HTTPLIB "OFF" CACHE STRING "Use cpp-httplib HTTP server library if available. Can be ON, OFF, or FORCE_ON")
566564

567565
set(LLVM_Z3_INSTALL_DIR "" CACHE STRING "Install directory of the Z3 solver.")

llvm/cmake/config-ix.cmake

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,17 +247,6 @@ else()
247247
set(HAVE_LIBEDIT 0)
248248
endif()
249249

250-
if(LLVM_HAS_LOGF128)
251-
include(CheckCXXSymbolExists)
252-
check_cxx_symbol_exists(logf128 math.h HAS_LOGF128)
253-
254-
if(LLVM_HAS_LOGF128 STREQUAL FORCE_ON AND NOT HAS_LOGF128)
255-
message(FATAL_ERROR "Failed to configure logf128")
256-
endif()
257-
258-
set(LLVM_HAS_LOGF128 "${HAS_LOGF128}")
259-
endif()
260-
261250
# function checks
262251
check_symbol_exists(arc4random "stdlib.h" HAVE_DECL_ARC4RANDOM)
263252
find_package(Backtrace)
@@ -271,6 +260,12 @@ if(C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW)
271260
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unguarded-availability-new")
272261
endif()
273262

263+
check_cxx_symbol_exists(logf128 cmath HAS_LOGF128)
264+
if(HAS_LOGF128)
265+
set(LLVM_HAS_LOGF128 On)
266+
add_compile_definitions(HAS_LOGF128)
267+
endif()
268+
274269
# Determine whether we can register EH tables.
275270
check_symbol_exists(__register_frame "${CMAKE_CURRENT_LIST_DIR}/unwind.h" HAVE_REGISTER_FRAME)
276271
check_symbol_exists(__deregister_frame "${CMAKE_CURRENT_LIST_DIR}/unwind.h" HAVE_DEREGISTER_FRAME)

llvm/include/llvm/ADT/APFloat.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ class IEEEFloat final : public APFloatBase {
378378
Expected<opStatus> convertFromString(StringRef, roundingMode);
379379
APInt bitcastToAPInt() const;
380380
double convertToDouble() const;
381-
#ifdef HAS_IEE754_FLOAT128
381+
#if defined(HAS_IEE754_FLOAT128)
382382
float128 convertToQuad() const;
383383
#endif
384384
float convertToFloat() const;
@@ -1279,7 +1279,7 @@ class APFloat : public APFloatBase {
12791279
/// \pre The APFloat must be built using semantics, that can be represented by
12801280
/// the host float type without loss of precision. It can be IEEEquad and
12811281
/// shorter semantics, like IEEEdouble and others.
1282-
#ifdef HAS_IEE754_FLOAT128
1282+
#if defined(HAS_IEE754_FLOAT128)
12831283
float128 convertToQuad() const;
12841284
#endif
12851285

llvm/include/llvm/Support/float128.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,16 @@
99
#ifndef LLVM_FLOAT128
1010
#define LLVM_FLOAT128
1111

12+
#include <cmath>
13+
1214
namespace llvm {
1315

14-
#if defined(__clang__) && defined(__FLOAT128__) && \
15-
defined(__SIZEOF_INT128__) && !defined(__LONG_DOUBLE_IBM128__)
16-
#define HAS_IEE754_FLOAT128
17-
typedef __float128 float128;
18-
#elif defined(__FLOAT128__) && defined(__SIZEOF_INT128__) && \
19-
!defined(__LONG_DOUBLE_IBM128__) && \
20-
(defined(__GNUC__) || defined(__GNUG__))
16+
#ifdef HAS_LOGF128
17+
#if !defined(__LONG_DOUBLE_IBM128__) && (__SIZEOF_INT128__ == 16)
18+
typedef decltype(logf128(0.)) float128;
2119
#define HAS_IEE754_FLOAT128
22-
typedef _Float128 float128;
2320
#endif
21+
#endif // HAS_LOGF128
2422

2523
} // namespace llvm
2624
#endif // LLVM_FLOAT128

llvm/lib/Analysis/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,3 @@ add_llvm_component_library(LLVMAnalysis
161161
Support
162162
TargetParser
163163
)
164-
165-
include(CheckCXXSymbolExists)
166-
check_cxx_symbol_exists(logf128 math.h HAS_LOGF128)
167-
if(HAS_LOGF128)
168-
target_compile_definitions(LLVMAnalysis PRIVATE HAS_LOGF128)
169-
endif()

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,7 +1781,7 @@ Constant *ConstantFoldFP(double (*NativeFP)(double), const APFloat &V,
17811781
return GetConstantFoldFPValue(Result, Ty);
17821782
}
17831783

1784-
#if defined(HAS_IEE754_FLOAT128) && defined(HAS_LOGF128)
1784+
#if defined(HAS_IEE754_FLOAT128)
17851785
Constant *ConstantFoldFP128(float128 (*NativeFP)(float128), const APFloat &V,
17861786
Type *Ty) {
17871787
llvm_fenv_clearexcept();
@@ -2114,7 +2114,7 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
21142114
if (IntrinsicID == Intrinsic::canonicalize)
21152115
return constantFoldCanonicalize(Ty, Call, U);
21162116

2117-
#if defined(HAS_IEE754_FLOAT128) && defined(HAS_LOGF128)
2117+
#if defined(HAS_IEE754_FLOAT128)
21182118
if (Ty->isFP128Ty()) {
21192119
if (IntrinsicID == Intrinsic::log) {
21202120
float128 Result = logf128(Op->getValueAPF().convertToQuad());

llvm/lib/Support/APFloat.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3749,7 +3749,7 @@ double IEEEFloat::convertToDouble() const {
37493749
return api.bitsToDouble();
37503750
}
37513751

3752-
#ifdef HAS_IEE754_FLOAT128
3752+
#if defined(HAS_IEE754_FLOAT128)
37533753
float128 IEEEFloat::convertToQuad() const {
37543754
assert(semantics == (const llvm::fltSemantics *)&semIEEEquad &&
37553755
"Float semantics are not IEEEquads");
@@ -5406,7 +5406,7 @@ double APFloat::convertToDouble() const {
54065406
return Temp.getIEEE().convertToDouble();
54075407
}
54085408

5409-
#ifdef HAS_IEE754_FLOAT128
5409+
#if defined(HAS_IEE754_FLOAT128)
54105410
float128 APFloat::convertToQuad() const {
54115411
if (&getSemantics() == (const llvm::fltSemantics *)&semIEEEquad)
54125412
return getIEEE().convertToQuad();

0 commit comments

Comments
 (0)