[llvm] Emit float128 libcalls for some F128 variants (PR #79611)
Pranav Kant via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 8 11:14:43 PST 2024
https://github.com/pranavk updated https://github.com/llvm/llvm-project/pull/79611
>From 3ff2c65977748cf5c58ff68cfca9064ebdb5092b Mon Sep 17 00:00:00 2001
From: Pranav Kant <prka at google.com>
Date: Thu, 8 Feb 2024 01:32:50 +0000
Subject: [PATCH 1/2] f128 libcalls for x86_64
---
llvm/lib/CodeGen/TargetLoweringBase.cpp | 40 ++++++++++++++++
.../test/CodeGen/X86/fp128-libcalls-strict.ll | 48 +++++++++----------
2 files changed, 64 insertions(+), 24 deletions(-)
diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index 16cd14ba3de9bd..0b402c461b532d 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -122,6 +122,46 @@ void TargetLoweringBase::InitLibcalls(const Triple &TT) {
for (int LC = 0; LC < RTLIB::UNKNOWN_LIBCALL; ++LC)
setLibcallCallingConv((RTLIB::Libcall)LC, CallingConv::C);
+ // For float128 libcall names, use the f128 variants of math functions on x86
+ if (TT.isX86()) {
+ setLibcallName(RTLIB::REM_F128, "fmodf128");
+ setLibcallName(RTLIB::FMA_F128, "fmaf128");
+ setLibcallName(RTLIB::SQRT_F128, "sqrtf128");
+ setLibcallName(RTLIB::CBRT_F128, "cbrtf128");
+ setLibcallName(RTLIB::LOG_F128, "logf128");
+ setLibcallName(RTLIB::LOG_FINITE_F128, "__logf128_finite");
+ setLibcallName(RTLIB::LOG2_F128, "log2f128");
+ setLibcallName(RTLIB::LOG2_FINITE_F128, "__log2f128_finite");
+ setLibcallName(RTLIB::LOG10_F128, "log10f128");
+ setLibcallName(RTLIB::LOG10_FINITE_F128, "__log10f128_finite");
+ setLibcallName(RTLIB::EXP_F128, "expf128");
+ setLibcallName(RTLIB::EXP_FINITE_F128, "__expf128_finite");
+ setLibcallName(RTLIB::EXP2_F128, "exp2f128");
+ setLibcallName(RTLIB::EXP2_FINITE_F128, "__exp2f128_finite");
+ setLibcallName(RTLIB::EXP10_F128, "exp10f128");
+ setLibcallName(RTLIB::SIN_F128, "sinf128");
+ setLibcallName(RTLIB::COS_F128, "cosf128");
+ setLibcallName(RTLIB::SINCOS_F128, "sincosf128");
+ setLibcallName(RTLIB::POW_F128, "powf128");
+ setLibcallName(RTLIB::POW_FINITE_F128, "__powf128_finite");
+ setLibcallName(RTLIB::CEIL_F128, "ceilf128");
+ setLibcallName(RTLIB::TRUNC_F128, "truncf128");
+ setLibcallName(RTLIB::RINT_F128, "rintf128");
+ setLibcallName(RTLIB::NEARBYINT_F128, "nearbyintf128");
+ setLibcallName(RTLIB::ROUND_F128, "roundf128");
+ setLibcallName(RTLIB::ROUNDEVEN_F128, "roundevenf128");
+ setLibcallName(RTLIB::FLOOR_F128, "floorf128");
+ setLibcallName(RTLIB::COPYSIGN_F128, "copysignf128");
+ setLibcallName(RTLIB::FMIN_F128, "fminf128");
+ setLibcallName(RTLIB::FMAX_F128, "fmaxf128");
+ setLibcallName(RTLIB::LROUND_F128, "lroundf128");
+ setLibcallName(RTLIB::LLROUND_F128, "llroundf128");
+ setLibcallName(RTLIB::LRINT_F128, "lrintf128");
+ setLibcallName(RTLIB::LLRINT_F128, "llrintf128");
+ setLibcallName(RTLIB::LDEXP_F128, "ldexpf128");
+ setLibcallName(RTLIB::FREXP_F128, "frexpf128");
+ }
+
// For IEEE quad-precision libcall names, PPC uses "kf" instead of "tf".
if (TT.isPPC()) {
setLibcallName(RTLIB::ADD_F128, "__addkf3");
diff --git a/llvm/test/CodeGen/X86/fp128-libcalls-strict.ll b/llvm/test/CodeGen/X86/fp128-libcalls-strict.ll
index 4722ce62f6e56f..47234c365cad5f 100644
--- a/llvm/test/CodeGen/X86/fp128-libcalls-strict.ll
+++ b/llvm/test/CodeGen/X86/fp128-libcalls-strict.ll
@@ -163,7 +163,7 @@ define fp128 @fma(fp128 %x, fp128 %y, fp128 %z) nounwind strictfp {
; CHECK-LABEL: fma:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq fmal at PLT
+; CHECK-NEXT: callq fmaf128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
;
@@ -204,7 +204,7 @@ define fp128 @frem(fp128 %x, fp128 %y) nounwind strictfp {
; CHECK-LABEL: frem:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq fmodl at PLT
+; CHECK-NEXT: callq fmodf128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
;
@@ -241,7 +241,7 @@ define fp128 @ceil(fp128 %x) nounwind strictfp {
; CHECK-LABEL: ceil:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq ceill at PLT
+; CHECK-NEXT: callq ceilf128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
;
@@ -274,7 +274,7 @@ define fp128 @cos(fp128 %x) nounwind strictfp {
; CHECK-LABEL: cos:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq cosl at PLT
+; CHECK-NEXT: callq cosf128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
;
@@ -307,7 +307,7 @@ define fp128 @exp(fp128 %x) nounwind strictfp {
; CHECK-LABEL: exp:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq expl at PLT
+; CHECK-NEXT: callq expf128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
;
@@ -340,7 +340,7 @@ define fp128 @exp2(fp128 %x) nounwind strictfp {
; CHECK-LABEL: exp2:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq exp2l at PLT
+; CHECK-NEXT: callq exp2f128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
;
@@ -373,7 +373,7 @@ define fp128 @floor(fp128 %x) nounwind strictfp {
; CHECK-LABEL: floor:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq floorl at PLT
+; CHECK-NEXT: callq floorf128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
;
@@ -406,7 +406,7 @@ define fp128 @log(fp128 %x) nounwind strictfp {
; CHECK-LABEL: log:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq logl at PLT
+; CHECK-NEXT: callq logf128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
;
@@ -439,7 +439,7 @@ define fp128 @log10(fp128 %x) nounwind strictfp {
; CHECK-LABEL: log10:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq log10l at PLT
+; CHECK-NEXT: callq log10f128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
;
@@ -472,7 +472,7 @@ define fp128 @log2(fp128 %x) nounwind strictfp {
; CHECK-LABEL: log2:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq log2l at PLT
+; CHECK-NEXT: callq log2f128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
;
@@ -505,7 +505,7 @@ define fp128 @maxnum(fp128 %x, fp128 %y) nounwind strictfp {
; CHECK-LABEL: maxnum:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq fmaxl at PLT
+; CHECK-NEXT: callq fmaxf128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
;
@@ -542,7 +542,7 @@ define fp128 @minnum(fp128 %x, fp128 %y) nounwind strictfp {
; CHECK-LABEL: minnum:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq fminl at PLT
+; CHECK-NEXT: callq fminf128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
;
@@ -579,7 +579,7 @@ define fp128 @nearbyint(fp128 %x) nounwind strictfp {
; CHECK-LABEL: nearbyint:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq nearbyintl at PLT
+; CHECK-NEXT: callq nearbyintf128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
;
@@ -612,7 +612,7 @@ define fp128 @pow(fp128 %x, fp128 %y) nounwind strictfp {
; CHECK-LABEL: pow:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq powl at PLT
+; CHECK-NEXT: callq powf128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
;
@@ -683,7 +683,7 @@ define fp128 @rint(fp128 %x) nounwind strictfp {
; CHECK-LABEL: rint:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq rintl at PLT
+; CHECK-NEXT: callq rintf128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
;
@@ -716,7 +716,7 @@ define fp128 @round(fp128 %x) nounwind strictfp {
; CHECK-LABEL: round:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq roundl at PLT
+; CHECK-NEXT: callq roundf128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
;
@@ -749,7 +749,7 @@ define fp128 @roundeven(fp128 %x) nounwind strictfp {
; CHECK-LABEL: roundeven:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq roundevenl at PLT
+; CHECK-NEXT: callq roundevenf128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
;
@@ -782,7 +782,7 @@ define fp128 @sin(fp128 %x) nounwind strictfp {
; CHECK-LABEL: sin:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq sinl at PLT
+; CHECK-NEXT: callq sinf128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
;
@@ -815,7 +815,7 @@ define fp128 @sqrt(fp128 %x) nounwind strictfp {
; CHECK-LABEL: sqrt:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq sqrtl at PLT
+; CHECK-NEXT: callq sqrtf128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
;
@@ -848,7 +848,7 @@ define fp128 @trunc(fp128 %x) nounwind strictfp {
; CHECK-LABEL: trunc:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq truncl at PLT
+; CHECK-NEXT: callq truncf128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
;
@@ -881,7 +881,7 @@ define i32 @lrint(fp128 %x) nounwind strictfp {
; CHECK-LABEL: lrint:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq lrintl at PLT
+; CHECK-NEXT: callq lrintf128
; CHECK-NEXT: popq %rcx
; CHECK-NEXT: retq
;
@@ -904,7 +904,7 @@ define i64 @llrint(fp128 %x) nounwind strictfp {
; CHECK-LABEL: llrint:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq llrintl at PLT
+; CHECK-NEXT: callq llrintf128
; CHECK-NEXT: popq %rcx
; CHECK-NEXT: retq
;
@@ -927,7 +927,7 @@ define i32 @lround(fp128 %x) nounwind strictfp {
; CHECK-LABEL: lround:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq lroundl at PLT
+; CHECK-NEXT: callq lroundf128
; CHECK-NEXT: popq %rcx
; CHECK-NEXT: retq
;
@@ -950,7 +950,7 @@ define i64 @llround(fp128 %x) nounwind strictfp {
; CHECK-LABEL: llround:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq llroundl at PLT
+; CHECK-NEXT: callq llroundf128
; CHECK-NEXT: popq %rcx
; CHECK-NEXT: retq
;
>From 890b5383393c5beeb94c1a75fef126f18a5fad68 Mon Sep 17 00:00:00 2001
From: Pranav Kant <prka at google.com>
Date: Thu, 8 Feb 2024 19:00:47 +0000
Subject: [PATCH 2/2] Only for x86_64
---
llvm/lib/CodeGen/TargetLoweringBase.cpp | 4 ++--
llvm/test/CodeGen/X86/GlobalISel/roundeven.ll | 2 +-
llvm/test/CodeGen/X86/fp128-libcalls.ll | 24 +++++++++----------
llvm/test/CodeGen/X86/frem.ll | 2 +-
4 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index 0b402c461b532d..05de17d93d0954 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -122,8 +122,8 @@ void TargetLoweringBase::InitLibcalls(const Triple &TT) {
for (int LC = 0; LC < RTLIB::UNKNOWN_LIBCALL; ++LC)
setLibcallCallingConv((RTLIB::Libcall)LC, CallingConv::C);
- // For float128 libcall names, use the f128 variants of math functions on x86
- if (TT.isX86()) {
+ // For float128 libcall names, use the f128 variants of math functions on x86_64
+ if (TT.getArch() == Triple::ArchType::x86_64) {
setLibcallName(RTLIB::REM_F128, "fmodf128");
setLibcallName(RTLIB::FMA_F128, "fmaf128");
setLibcallName(RTLIB::SQRT_F128, "sqrtf128");
diff --git a/llvm/test/CodeGen/X86/GlobalISel/roundeven.ll b/llvm/test/CodeGen/X86/GlobalISel/roundeven.ll
index 119821e91b38c3..dae27ffe6c5b20 100644
--- a/llvm/test/CodeGen/X86/GlobalISel/roundeven.ll
+++ b/llvm/test/CodeGen/X86/GlobalISel/roundeven.ll
@@ -44,7 +44,7 @@ define fp128 @roundeven_f128(fp128 %x) {
; CHECK: # %bb.0:
; CHECK-NEXT: pushq %rax
; CHECK-NEXT: .cfi_def_cfa_offset 16
-; CHECK-NEXT: callq roundevenl
+; CHECK-NEXT: callq roundevenf128
; CHECK-NEXT: popq %rax
; CHECK-NEXT: .cfi_def_cfa_offset 8
; CHECK-NEXT: retq
diff --git a/llvm/test/CodeGen/X86/fp128-libcalls.ll b/llvm/test/CodeGen/X86/fp128-libcalls.ll
index 4e7e6b4d01944f..6946ca2d575b7f 100644
--- a/llvm/test/CodeGen/X86/fp128-libcalls.ll
+++ b/llvm/test/CodeGen/X86/fp128-libcalls.ll
@@ -299,7 +299,7 @@ define dso_local void @Test128Rem(fp128 %d1, fp128 %d2) nounwind {
; CHECK-LABEL: Test128Rem:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq fmodl at PLT
+; CHECK-NEXT: callq fmodf128
; CHECK-NEXT: movaps %xmm0, vf128(%rip)
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
@@ -335,7 +335,7 @@ define dso_local void @Test128_1Rem(fp128 %d1) nounwind {
; CHECK-NEXT: pushq %rax
; CHECK-NEXT: movaps %xmm0, %xmm1
; CHECK-NEXT: movaps vf128(%rip), %xmm0
-; CHECK-NEXT: callq fmodl at PLT
+; CHECK-NEXT: callq fmodf128
; CHECK-NEXT: movaps %xmm0, vf128(%rip)
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
@@ -370,7 +370,7 @@ define dso_local void @Test128Sqrt(fp128 %d1) nounwind {
; CHECK-LABEL: Test128Sqrt:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq sqrtl at PLT
+; CHECK-NEXT: callq sqrtf128
; CHECK-NEXT: movaps %xmm0, vf128(%rip)
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
@@ -401,7 +401,7 @@ define dso_local void @Test128Sin(fp128 %d1) nounwind {
; CHECK-LABEL: Test128Sin:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq sinl at PLT
+; CHECK-NEXT: callq sinf128
; CHECK-NEXT: movaps %xmm0, vf128(%rip)
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
@@ -432,7 +432,7 @@ define dso_local void @Test128Cos(fp128 %d1) nounwind {
; CHECK-LABEL: Test128Cos:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq cosl at PLT
+; CHECK-NEXT: callq cosf128
; CHECK-NEXT: movaps %xmm0, vf128(%rip)
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
@@ -463,7 +463,7 @@ define dso_local void @Test128Ceil(fp128 %d1) nounwind {
; CHECK-LABEL: Test128Ceil:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq ceill at PLT
+; CHECK-NEXT: callq ceilf128
; CHECK-NEXT: movaps %xmm0, vf128(%rip)
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
@@ -494,7 +494,7 @@ define dso_local void @Test128Floor(fp128 %d1) nounwind {
; CHECK-LABEL: Test128Floor:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq floorl at PLT
+; CHECK-NEXT: callq floorf128
; CHECK-NEXT: movaps %xmm0, vf128(%rip)
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
@@ -525,7 +525,7 @@ define dso_local void @Test128Trunc(fp128 %d1) nounwind {
; CHECK-LABEL: Test128Trunc:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq truncl at PLT
+; CHECK-NEXT: callq truncf128
; CHECK-NEXT: movaps %xmm0, vf128(%rip)
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
@@ -556,7 +556,7 @@ define dso_local void @Test128Nearbyint(fp128 %d1) nounwind {
; CHECK-LABEL: Test128Nearbyint:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq nearbyintl at PLT
+; CHECK-NEXT: callq nearbyintf128
; CHECK-NEXT: movaps %xmm0, vf128(%rip)
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
@@ -587,7 +587,7 @@ define dso_local void @Test128Rint(fp128 %d1) nounwind {
; CHECK-LABEL: Test128Rint:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq rintl at PLT
+; CHECK-NEXT: callq rintf128
; CHECK-NEXT: movaps %xmm0, vf128(%rip)
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
@@ -618,7 +618,7 @@ define dso_local void @Test128Round(fp128 %d1) nounwind {
; CHECK-LABEL: Test128Round:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq roundl at PLT
+; CHECK-NEXT: callq roundf128
; CHECK-NEXT: movaps %xmm0, vf128(%rip)
; CHECK-NEXT: popq %rax
; CHECK-NEXT: retq
@@ -648,7 +648,7 @@ declare fp128 @llvm.round.f128(fp128)
define fp128 @Test128FMA(fp128 %a, fp128 %b, fp128 %c) nounwind {
; CHECK-LABEL: Test128FMA:
; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: jmp fmal at PLT # TAILCALL
+; CHECK-NEXT: jmp fmaf128 at PLT # TAILCALL
;
; X86-LABEL: Test128FMA:
; X86: # %bb.0: # %entry
diff --git a/llvm/test/CodeGen/X86/frem.ll b/llvm/test/CodeGen/X86/frem.ll
index d91d4289a5994a..35d16c3bac70d2 100644
--- a/llvm/test/CodeGen/X86/frem.ll
+++ b/llvm/test/CodeGen/X86/frem.ll
@@ -82,7 +82,7 @@ define void @frem_f128(fp128 %a0, fp128 %a1, ptr%p3) nounwind {
; CHECK: # %bb.0:
; CHECK-NEXT: pushq %rbx
; CHECK-NEXT: movq %rdi, %rbx
-; CHECK-NEXT: callq fmodl at PLT
+; CHECK-NEXT: callq fmodf128
; CHECK-NEXT: vmovaps %xmm0, (%rbx)
; CHECK-NEXT: popq %rbx
; CHECK-NEXT: retq
More information about the llvm-commits
mailing list