[compiler-rt] [builtins][AArch64] Fix __gnu_* functions (PR #137638)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 28 07:28:24 PDT 2025
https://github.com/saturn691 created https://github.com/llvm/llvm-project/pull/137638
Move to a consistent calling convention for both Clang and GNU such that they can be linked with each other.
**Context**
When compiling this function under GCC
```c
float h2f(_Float16 x)
{
return (float)x;
}
```
It returns a call to `__gnu_h2f_ieee`. This was using COMPILER_RT_ABI which meant `s0` was used as the argument and return register. However, `__aeabi_h2f`, the one that Clang uses, uses `r0` as the argument and return register.
This commit changes `__gnu_h2f_ieee` to use `r0`.
To me, it seems weird that we are using `r0` since it has to be moved to `s0` to be used with `__extendhfsf2`. I suspect there may have been some issues in the past for it to be purposely written this way, as it takes extra instructions for both conversions.
>From feabb903c275f30f22184fbca639b4081a344d54 Mon Sep 17 00:00:00 2001
From: William Huynh <William.Huynh at arm.com>
Date: Mon, 28 Apr 2025 15:16:26 +0100
Subject: [PATCH] [builtins][AArch64] Fix __gnu_* functions
Move to a consistent calling convention for both Clang and GNU such
that they can be linked with each other.
---
compiler-rt/lib/builtins/extendhfsf2.c | 4 ++--
compiler-rt/lib/builtins/truncsfhf2.c | 3 ++-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/compiler-rt/lib/builtins/extendhfsf2.c b/compiler-rt/lib/builtins/extendhfsf2.c
index 0159ab09d3ebb..0dc8cf33cccb6 100644
--- a/compiler-rt/lib/builtins/extendhfsf2.c
+++ b/compiler-rt/lib/builtins/extendhfsf2.c
@@ -16,12 +16,12 @@ COMPILER_RT_ABI NOINLINE float __extendhfsf2(src_t a) {
return __extendXfYf2__(a);
}
-COMPILER_RT_ABI float __gnu_h2f_ieee(src_t a) { return __extendhfsf2(a); }
-
#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
+AEABI_RTABI float __gnu_h2f_ieee(src_t a) { return __extendhfsf2(a); }
AEABI_RTABI float __aeabi_h2f(src_t a) { return __extendhfsf2(a); }
#else
+COMPILER_RT_ALIAS(__extendhfsf2, __gnu_h2f_ieee)
COMPILER_RT_ALIAS(__extendhfsf2, __aeabi_h2f)
#endif
#endif
diff --git a/compiler-rt/lib/builtins/truncsfhf2.c b/compiler-rt/lib/builtins/truncsfhf2.c
index 379e7cb6f7845..310cacd93c558 100644
--- a/compiler-rt/lib/builtins/truncsfhf2.c
+++ b/compiler-rt/lib/builtins/truncsfhf2.c
@@ -16,12 +16,13 @@ COMPILER_RT_ABI NOINLINE dst_t __truncsfhf2(float a) {
return __truncXfYf2__(a);
}
-COMPILER_RT_ABI dst_t __gnu_f2h_ieee(float a) { return __truncsfhf2(a); }
#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
+AEABI_RTABI dst_t __gnu_f2h_ieee(float a) { return __truncsfhf2(a); }
AEABI_RTABI dst_t __aeabi_f2h(float a) { return __truncsfhf2(a); }
#else
+COMPILER_RT_ALIAS(__truncsfhf2, __gnu_f2h_ieee)
COMPILER_RT_ALIAS(__truncsfhf2, __aeabi_f2h)
#endif
#endif
More information about the llvm-commits
mailing list