[llvm] [SystemZ/z/OS] Add library names for intrinsics (PR #68114)

Kai Nacke via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 3 08:00:16 PDT 2023


https://github.com/redstar created https://github.com/llvm/llvm-project/pull/68114

On z/OS, many library functions have a non-standard name. This change initializes the table of runtime function which results from lowering intrinsics to library calls.

>From 56f0e0c38df0ef380425c171c1c5ab5fcdd251fc Mon Sep 17 00:00:00 2001
From: Kai Nacke <kai.peter.nacke at ibm.com>
Date: Tue, 3 Oct 2023 14:56:15 +0000
Subject: [PATCH] [SystemZ/z/OS] Add library names for intrinsics

On z/OS, many library functions have a non-standard name. This change
initializes the table of runtime function which results from lowering
intrinsics to library calls.
---
 .../Target/SystemZ/SystemZISelLowering.cpp    |  10 ++
 llvm/lib/Target/SystemZ/ZOSLibcallNames.def   | 100 ++++++++++++++++++
 llvm/test/CodeGen/SystemZ/zos-intrinsics.ll   |  45 ++++++++
 3 files changed, 155 insertions(+)
 create mode 100644 llvm/lib/Target/SystemZ/ZOSLibcallNames.def
 create mode 100644 llvm/test/CodeGen/SystemZ/zos-intrinsics.ll

diff --git a/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp b/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp
index 886b5e93bffc0d6..9ef3b654aaf644e 100644
--- a/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp
@@ -691,6 +691,16 @@ SystemZTargetLowering::SystemZTargetLowering(const TargetMachine &TM,
 
   // Default to having -disable-strictnode-mutation on
   IsStrictFPEnabled = true;
+
+  if (Subtarget.isTargetzOS()) {
+    struct RTLibCallMapping { RTLIB::Libcall Code; const char *Name; };
+    static RTLibCallMapping RTLibCallCommon[] = {
+#define HANDLE_LIBCALL(code, name) { RTLIB::code, name },
+    #include "ZOSLibcallNames.def"
+    };
+    for (auto &E : RTLibCallCommon)
+      setLibcallName(E.Code, E.Name);
+  }
 }
 
 bool SystemZTargetLowering::useSoftFloat() const {
diff --git a/llvm/lib/Target/SystemZ/ZOSLibcallNames.def b/llvm/lib/Target/SystemZ/ZOSLibcallNames.def
new file mode 100644
index 000000000000000..12a01522a7e643f
--- /dev/null
+++ b/llvm/lib/Target/SystemZ/ZOSLibcallNames.def
@@ -0,0 +1,100 @@
+//===-- ZOSLibcallNames.def ----------------------------------- -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines all of the runtime library functions on z/OS which can be
+// generated during instruction selection.
+//
+//===----------------------------------------------------------------------===//
+
+#if !defined(HANDLE_LIBCALL)
+#error "HANDLE_LIBCALL must be defined"
+#endif
+
+HANDLE_LIBCALL(TRUNC_F64, "@@TRNC at B")
+HANDLE_LIBCALL(TRUNC_F32, "@@FTRC at B")
+HANDLE_LIBCALL(TRUNC_F128, "@@LTRC at B")
+HANDLE_LIBCALL(SQRT_F64, "@@WSQT at B")
+HANDLE_LIBCALL(SQRT_F32, "@@FSQT at B")
+HANDLE_LIBCALL(SQRT_F128, "@@LSQT at B")
+HANDLE_LIBCALL(SIN_F64, "@@SSIN at B")
+HANDLE_LIBCALL(SIN_F32, "@@FSIN at B")
+HANDLE_LIBCALL(SIN_F128, "@@LSIN at B")
+HANDLE_LIBCALL(ROUND_F64, "@@ROUN at B")
+HANDLE_LIBCALL(ROUND_F32, "@@ROUNFB")
+HANDLE_LIBCALL(ROUND_F128, "@@ROUNLB")
+HANDLE_LIBCALL(RINT_F64, "@@SRNT at B")
+HANDLE_LIBCALL(RINT_F32, "@@RINTFB")
+HANDLE_LIBCALL(RINT_F128, "@@RINTLB")
+HANDLE_LIBCALL(REM_F64, "@@WFMD at B")
+HANDLE_LIBCALL(REM_F32, "@@FFMD at B")
+HANDLE_LIBCALL(REM_F128, "@@LFMD at B")
+HANDLE_LIBCALL(POW_F64, "@@WPOW at B")
+HANDLE_LIBCALL(POW_F32, "@@FPOW at B")
+HANDLE_LIBCALL(POW_F128, "@@LPOW at B")
+HANDLE_LIBCALL(NEARBYINT_F64, "@@NBYI at B")
+HANDLE_LIBCALL(NEARBYINT_F32, "@@NBYIFB")
+HANDLE_LIBCALL(NEARBYINT_F128, "@@NBYILB")
+HANDLE_LIBCALL(LROUND_F64, "@@ROND at B")
+HANDLE_LIBCALL(LROUND_F32, "@@FRND at B")
+HANDLE_LIBCALL(LROUND_F128, "@@LRND at B")
+HANDLE_LIBCALL(LRINT_F64, "@@LRNT at B")
+HANDLE_LIBCALL(LRINT_F32, "@@LRNTFB")
+HANDLE_LIBCALL(LRINT_F128, "@@LRNTLB")
+HANDLE_LIBCALL(LOG_F64, "@@WLOG at B")
+HANDLE_LIBCALL(LOG_F32, "@@FLOG at B")
+HANDLE_LIBCALL(LOG_F128, "@@LLOG at B")
+HANDLE_LIBCALL(LOG2_F64, "@@LOG2 at B")
+HANDLE_LIBCALL(LOG2_F32, "@@FLG2 at B")
+HANDLE_LIBCALL(LOG2_F128, "@@LLG2 at B")
+HANDLE_LIBCALL(LOG10_F64, "@@WLG1 at B")
+HANDLE_LIBCALL(LOG10_F32, "@@FLG1 at B")
+HANDLE_LIBCALL(LOG10_F128, "@@LLG1 at B")
+HANDLE_LIBCALL(LLROUND_F64, "@@LLRD at B")
+HANDLE_LIBCALL(LLROUND_F32, "@@LLRDFB")
+HANDLE_LIBCALL(LLROUND_F128, "@@LLRDLB")
+HANDLE_LIBCALL(LLRINT_F64, "@@LLRT at B")
+HANDLE_LIBCALL(LLRINT_F32, "@@LLRTFB")
+HANDLE_LIBCALL(LLRINT_F128, "@@LLRTLB")
+HANDLE_LIBCALL(LDEXP_F64, "@@SLXP at B")
+HANDLE_LIBCALL(LDEXP_F32, "@@FLXP at B")
+HANDLE_LIBCALL(LDEXP_F128, "@@LLXP at B")
+HANDLE_LIBCALL(FREXP_F64, "@@SFXP at B")
+HANDLE_LIBCALL(FREXP_F32, "@@FFXP at B")
+HANDLE_LIBCALL(FREXP_F128, "@@LFXP at B")
+HANDLE_LIBCALL(FMIN_F64, "@@FMIN at B")
+HANDLE_LIBCALL(FMIN_F32, "@@FMINFB")
+HANDLE_LIBCALL(FMIN_F128, "@@FMINLB")
+HANDLE_LIBCALL(FMA_F64, "@@FMA at B")
+HANDLE_LIBCALL(FMA_F32, "@@FMAFB")
+HANDLE_LIBCALL(FMA_F128, "@@FMALB")
+HANDLE_LIBCALL(FMAX_F64, "@@FMAX at B")
+HANDLE_LIBCALL(FMAX_F32, "@@FMAXFB")
+HANDLE_LIBCALL(FMAX_F128, "@@FMAXLB")
+HANDLE_LIBCALL(FLOOR_F64, "@@SFLR at B")
+HANDLE_LIBCALL(FLOOR_F32, "@@FFLR at B")
+HANDLE_LIBCALL(FLOOR_F128, "@@LFLR at B")
+HANDLE_LIBCALL(EXP_F64, "@@WEXP at B")
+HANDLE_LIBCALL(EXP_F32, "@@FEXP at B")
+HANDLE_LIBCALL(EXP_F128, "@@LEXP at B")
+HANDLE_LIBCALL(EXP2_F64, "@@EXP2 at B")
+HANDLE_LIBCALL(EXP2_F32, "@@FXP2 at B")
+HANDLE_LIBCALL(EXP2_F128, "@@LXP2 at B")
+HANDLE_LIBCALL(COS_F64, "@@SCOS at B")
+HANDLE_LIBCALL(COS_F32, "@@FCOS at B")
+HANDLE_LIBCALL(COS_F128, "@@LCOS at B")
+HANDLE_LIBCALL(COPYSIGN_F64, "@@DCPY at B")
+HANDLE_LIBCALL(COPYSIGN_F32, "@@FCPY at B")
+HANDLE_LIBCALL(COPYSIGN_F128, "@@LCPY at B")
+HANDLE_LIBCALL(CEIL_F64, "@@SCEL at B")
+HANDLE_LIBCALL(CEIL_F32, "@@FCEL at B")
+HANDLE_LIBCALL(CEIL_F128, "@@LCEL at B")
+HANDLE_LIBCALL(CBRT_F64, "@@SCRT at B")
+HANDLE_LIBCALL(CBRT_F32, "@@FCBT at B")
+HANDLE_LIBCALL(CBRT_F128, "@@LCBT at B")
+
+#undef HANDLE_LIBCALL
diff --git a/llvm/test/CodeGen/SystemZ/zos-intrinsics.ll b/llvm/test/CodeGen/SystemZ/zos-intrinsics.ll
new file mode 100644
index 000000000000000..b1f0c9e5b8e54ff
--- /dev/null
+++ b/llvm/test/CodeGen/SystemZ/zos-intrinsics.ll
@@ -0,0 +1,45 @@
+; RUN: llc -mtriple s390x-zos < %s | FileCheck %s
+
+define float @sqrt_ieee(float %x) {
+entry:
+  %res = call float @llvm.sqrt.f32(float %x)
+  ret float %res
+}
+
+define float @cos_ieee(float %x) {
+entry:
+  %res = call float @llvm.cos.f32(float %x)
+  ret float %res
+}
+
+define double @sin_ieee(double %x) {
+entry:
+  %res = call double @llvm.sin.f64(double %x)
+  ret double %res
+}
+
+define fp128 @exp2_ieee(fp128 %x) {
+entry:
+  %res = call fp128 @llvm.exp2.f128(fp128 %x)
+  ret fp128 %res
+}
+
+declare float @llvm.sqrt.f32(float)
+declare float @llvm.cos.f32(float)
+declare double @llvm.sin.f64(double)
+declare fp128 @llvm.exp2.f128(fp128)
+
+; Check the calls in the ADA.
+; CHECK: .section ".ada"
+
+; Check that there is no call to sqrt.
+; CHECK-NOT:  .quad   R(@@WSQT at B)
+; CHECK-NOT:  .quad   V(@@WSQT at B)
+
+; Check that there is the correct library call.
+; CHECK:      .quad   R(@@FCOS at B)
+; CHECK-NEXT: .quad   V(@@FCOS at B)
+; CHECK:      .quad   R(@@SSIN at B)
+; CHECK-NEXT: .quad   V(@@SSIN at B)
+; CHECK:      .quad   R(@@LXP2 at B)
+; CHECK-NEXT: .quad   V(@@LXP2 at B)



More information about the llvm-commits mailing list