[compiler-rt] [builtins][AArch32] Fix __gnu_* functions (PR #137638)
Peter Smith via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 30 08:38:46 PDT 2025
smithp35 wrote:
Apologies for taking so long to reply, I wanted to track down the history to make sure that this isn't going to break any none Arm target, the code as it stands shouldn't have worked at all for Arm targets, but historically the __gnu_h2f_ieee used to be the default lowering for all targets (including non-Arm). The original commit was added in https://reviews.llvm.org/D9693 later the default lowering was changed in https://github.com/llvm/llvm-project/pull/126880 to go to `__truncsfhf2` so this won't affect other targets.
Apologies again for missing the not on the condition for machO, looking at the full code and the test at https://github.com/llvm/llvm-project/blob/main/llvm/test/CodeGen/ARM/fp16.ll it seems like the gnueabi musleabi are what selects the GNU libcall from LLVM.
>From clang it is possible to generate a call with `clang -march=armv7-a+fp16 -mfloat-abi=hard --target=arm-none-gnueabihf -S -o - h2f.c -O1`. If armv8-a is used there are inline instructions used instead.
```
h2f:
.fnstart
@ %bb.0: @ %entry
.save {r11, lr}
push {r11, lr}
.setfp r11, sp
mov r11, sp
vmov r0, s0
bl __gnu_h2f_ieee
vmov s0, r0
pop {r11, pc}
.Lfunc_end0:
```
Looking up what AEABI_RTABI expands to
```
compiler-rt/lib/builtins/int_lib.h:#define AEABI_RTABI __attribute__((__pcs__("aapcs")))
```
That will cause the function to use the soft-float calling convention regardless of the parameters so this should be compatible with the GCC prototypes regardless of prototype.
> 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.
It is a property of the ABI of the helper functions. In Arm the base-standard procedure call standard passes floating point values in core-registers, there is a hard-float variant that passes floating point values in floating point registers. The Arm ABI defines that the helper functions to always use the base standard (https://github.com/ARM-software/abi-aa/blob/main/rtabi32/rtabi32.rst#410__hardfp_-name-mangling). The `__extendhfsf2` function is not part of the Arm ABI so it has the hard-float ABI
https://github.com/llvm/llvm-project/pull/137638
More information about the llvm-commits
mailing list