[llvm-branch-commits] [llvm] RuntimeLibcalls: Only provide fp128 long double libcalls when long double is fp128 (PR #214944)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Aug 8 01:43:36 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-tablegen
Author: Matt Arsenault (arsenm)
<details>
<summary>Changes</summary>
The l-suffixed long double math functions (e.g, acosl, sqrtl, ...) are fp128 only
when the target's long double is fp128. The default set provided them on every
target that was not x87 or ppc_fp128, so targets using double as long
double wrongly reported the fp128 l-suffixed functions.
Co-authored-by: Claude (Claude-Opus-4.8) <noreply@<!-- -->anthropic.com>
---
Full diff: https://github.com/llvm/llvm-project/pull/214944.diff
6 Files Affected:
- (modified) llvm/include/llvm/IR/RuntimeLibcalls.h (+4-2)
- (modified) llvm/include/llvm/IR/RuntimeLibcalls.td (+22-3)
- (modified) llvm/lib/IR/RuntimeLibcalls.cpp (+10-6)
- (modified) llvm/test/TableGen/RuntimeLibcallEmitter-calling-conv.td (+1-1)
- (modified) llvm/test/TableGen/RuntimeLibcallEmitter.td (+1-1)
- (modified) llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp (+1-1)
``````````diff
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h
index 78b75f3e81c3b..e8b472ca002c6 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.h
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.h
@@ -217,13 +217,15 @@ struct RuntimeLibcallsInfo {
void setTargetRuntimeLibcallSets(const Triple &TT,
ExceptionHandling ExceptionModel,
FloatABI::ABIType FloatABI, EABI ABIType,
- StringRef ABIName);
+ StringRef ABIName,
+ LongDoubleFormat LongDoubleFormat);
/// Set default libcall names. If a target wants to opt-out of a libcall it
/// should be placed here.
LLVM_ABI void initLibcalls(const Triple &TT, ExceptionHandling ExceptionModel,
FloatABI::ABIType FloatABI, EABI ABIType,
- StringRef ABIName);
+ StringRef ABIName,
+ LongDoubleFormat LongDoubleFormat);
};
} // namespace RTLIB
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td
index b0d9663cca395..4c2a786b49f0a 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.td
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.td
@@ -59,6 +59,8 @@ def IsAAPCS_ABI : LibcallPredicate<[{isAAPCS_ABI(TT, ABIName)}]>;
def IsEABI4 : LibcallPredicate<[{EABIVersion == EABI::EABI4}]>;
def IsEABI5 : LibcallPredicate<[{EABIVersion == EABI::EABI5}]>;
+def IsLongDoubleF128 : LibcallPredicate<[{LongDoubleFormat == LongDoubleFormat::IEEEquad}]>;
+
def IsAMDGPU : LibcallPredicate<[{TT.isAMDGPU()}]>;
def IsARM : LibcallPredicate<[{TT.isARM()}]>;
def IsThumb : LibcallPredicate<[{TT.isThumb()}]>;
@@ -108,6 +110,10 @@ def IsArchXtensa : LibcallPredicate<[{TT.getArch() == Triple::xtensa}]>;
def isOSDarwin : RuntimeLibcallAvailability<(all_of IsOSDarwin)>;
def isOSOpenBSD : RuntimeLibcallAvailability<(all_of IsOSOpenBSD)>;
def isNotOSOpenBSD : RuntimeLibcallAvailability<(not IsOSOpenBSD)>;
+
+// True when the C `long double` type is IEEE fp128.
+def isLongDoubleF128 : RuntimeLibcallAvailability<(all_of IsLongDoubleF128)>;
+
def isOSWindows : RuntimeLibcallAvailability<(all_of IsOSWindows)>;
def isNotOSWindows : RuntimeLibcallAvailability<(not IsOSWindows)>;
def isNotOSLinux : RuntimeLibcallAvailability<(not IsOSLinux)>;
@@ -1929,17 +1935,30 @@ defvar DefaultRuntimeLibcallImpls_f128 =
!filter(entry, AllDefaultRuntimeLibcallImpls,
!match(!cast<string>(entry.Provides), "_F128"));
+// The `l`-suffixed libm functions only exist when long double is
+// fp128.
+defvar DefaultRuntimeLibcallImpls_longdouble_f128 =
+ !filter(entry, AllDefaultRuntimeLibcallImpls,
+ !match(!cast<string>(entry), "l_f128"));
+
// FIXME: Ideally we would just use dags everywhere, but for the
// arm64ec case we need iterable lists so we can add the # prefix
+//
+// The long-double fp128 slice is dropped here and added back below gated on the
+// long double format.
defvar DefaultRuntimeLibcallImplsBaseList =
!listremove(
!listremove(
- !listremove(AllDefaultRuntimeLibcallImpls, Int128RTLibcalls),
- DefaultRuntimeLibcallImpls_f80),
- DefaultRuntimeLibcallImpls_ppcf128);
+ !listremove(
+ !listremove(AllDefaultRuntimeLibcallImpls, Int128RTLibcalls),
+ DefaultRuntimeLibcallImpls_f80),
+ DefaultRuntimeLibcallImpls_ppcf128),
+ DefaultRuntimeLibcallImpls_longdouble_f128);
defvar DefaultRuntimeLibcallImpls =
(add DefaultRuntimeLibcallImplsBaseList,
+ LibcallImpls<(add DefaultRuntimeLibcallImpls_longdouble_f128),
+ isLongDoubleF128>,
ExceptionModelCalls);
/// Default set of libcall impls for 32-bit architectures.
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index ad7d3320f8928..50c583306ccaf 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -38,7 +38,8 @@ RuntimeLibcallsInfo::RuntimeLibcallsInfo(const Triple &TT,
if (ExceptionModel == ExceptionHandling::None)
ExceptionModel = TT.getDefaultExceptionHandling();
- initLibcalls(TT, ExceptionModel, FloatABI, EABIVersion, ABIName);
+ initLibcalls(TT, ExceptionModel, FloatABI, EABIVersion, ABIName,
+ TT.getDefaultLongDoubleFormat());
// TODO: Tablegen should generate these sets
switch (VecLib) {
@@ -101,9 +102,11 @@ RuntimeLibcallsInfo::RuntimeLibcallsInfo(const Triple &TT,
}
}
-RuntimeLibcallsInfo::RuntimeLibcallsInfo(const Module &M)
- : RuntimeLibcallsInfo(M.getTargetTriple()) {
- // TODO: Consider module flags
+RuntimeLibcallsInfo::RuntimeLibcallsInfo(const Module &M) {
+ // TODO: Consider the remaining module flags.
+ const Triple &TT = M.getTargetTriple();
+ initLibcalls(TT, TT.getDefaultExceptionHandling(), FloatABI::Default,
+ EABI::Default, /*ABIName=*/"", M.getLongDoubleFormat());
}
/// Set default libcall names. If a target wants to opt-out of a libcall it
@@ -111,9 +114,10 @@ RuntimeLibcallsInfo::RuntimeLibcallsInfo(const Module &M)
void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
ExceptionHandling ExceptionModel,
FloatABI::ABIType FloatABI,
- EABI EABIVersion, StringRef ABIName) {
+ EABI EABIVersion, StringRef ABIName,
+ LongDoubleFormat LongDoubleFormat) {
setTargetRuntimeLibcallSets(TT, ExceptionModel, FloatABI, EABIVersion,
- ABIName);
+ ABIName, LongDoubleFormat);
}
LLVM_ATTRIBUTE_ALWAYS_INLINE
diff --git a/llvm/test/TableGen/RuntimeLibcallEmitter-calling-conv.td b/llvm/test/TableGen/RuntimeLibcallEmitter-calling-conv.td
index c4bf02c08dd2d..cd1f59067c7ba 100644
--- a/llvm/test/TableGen/RuntimeLibcallEmitter-calling-conv.td
+++ b/llvm/test/TableGen/RuntimeLibcallEmitter-calling-conv.td
@@ -46,7 +46,7 @@ def MSP430LibraryWithCondCC : SystemRuntimeLibrary<isMSP430,
>;
-// CHECK: void llvm::RTLIB::RuntimeLibcallsInfo::setTargetRuntimeLibcallSets(const llvm::Triple &TT, ExceptionHandling ExceptionModel, FloatABI::ABIType FloatABI, EABI EABIVersion, StringRef ABIName) {
+// CHECK: void llvm::RTLIB::RuntimeLibcallsInfo::setTargetRuntimeLibcallSets(const llvm::Triple &TT, ExceptionHandling ExceptionModel, FloatABI::ABIType FloatABI, EABI EABIVersion, StringRef ABIName, LongDoubleFormat LongDoubleFormat) {
// CHECK: if (TT.getArch() == Triple::avr && TT.isOSHurd()) {
// CHECK-NEXT: const CallingConv::ID DefaultCC = isFoo() ? CallingConv::Fast : CallingConv::GHC;
// CHECK-NEXT: for (CallingConv::ID &Entry : LibcallImplCallingConvs) {
diff --git a/llvm/test/TableGen/RuntimeLibcallEmitter.td b/llvm/test/TableGen/RuntimeLibcallEmitter.td
index d34c24a241bd6..51c3e02885f4b 100644
--- a/llvm/test/TableGen/RuntimeLibcallEmitter.td
+++ b/llvm/test/TableGen/RuntimeLibcallEmitter.td
@@ -210,7 +210,7 @@ def BlahLibrary : SystemRuntimeLibrary<isBlahArch, (add calloc, LibraryWithCondi
// CHECK: return enum_seq(RTLIB::Unsupported, RTLIB::Unsupported);
// CHECK-NEXT: }
-// CHECK: void llvm::RTLIB::RuntimeLibcallsInfo::setTargetRuntimeLibcallSets(const llvm::Triple &TT, ExceptionHandling ExceptionModel, FloatABI::ABIType FloatABI, EABI EABIVersion, StringRef ABIName) {
+// CHECK: void llvm::RTLIB::RuntimeLibcallsInfo::setTargetRuntimeLibcallSets(const llvm::Triple &TT, ExceptionHandling ExceptionModel, FloatABI::ABIType FloatABI, EABI EABIVersion, StringRef ABIName, LongDoubleFormat LongDoubleFormat) {
// CHECK-EMPTY:
// CHECK-NEXT: if (TT.getArch() == Triple::blah) {
// CHECK-NEXT: static constexpr LibcallImplBitset SystemAvailableImpls({
diff --git a/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp b/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp
index 7a0bd4228117c..1aae66918c609 100644
--- a/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp
@@ -344,7 +344,7 @@ void RuntimeLibcallEmitter::emitSystemRuntimeLibrarySetCalls(
OS << "void llvm::RTLIB::RuntimeLibcallsInfo::setTargetRuntimeLibcallSets("
"const llvm::Triple &TT, ExceptionHandling ExceptionModel, "
"FloatABI::ABIType FloatABI, EABI EABIVersion, "
- "StringRef ABIName) {\n";
+ "StringRef ABIName, LongDoubleFormat LongDoubleFormat) {\n";
ArrayRef<const Record *> AllLibs =
Records.getAllDerivedDefinitions("SystemRuntimeLibrary");
``````````
</details>
https://github.com/llvm/llvm-project/pull/214944
More information about the llvm-branch-commits
mailing list