[llvm] Emit float128 libcalls for some F128 variants (PR #79611)
Pranav Kant via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 7 17:33:19 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] 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
;
More information about the llvm-commits
mailing list