-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[builtins][AArch32] Fix __gnu_* functions #137638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Move to a consistent calling convention for both Clang and GNU such that they can be linked with each other.
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
I think we may need a bit more evidence collected to make sure we're doing the right thing across all platforms. When I look at the ARM libgcc prototypes https://github.com/gcc-mirror/gcc/blob/master/libgcc/config/arm/fp16.c#L56
These have a core register interface, and I'm not sure your proposed change reflects that for the source parameter. As it looks like src_t may be float. So if an Arm GCC compiled object calls one of these functions I think it will still be wrong. Looking at LLVM ARMISelLowering.cpp these functions may be called by MachO
It is highly likely that the interface is correct for MachO but not for calls via libgcc. Can you do some research to make sure:
|
float h2f(_Float16 x)
{
return (float)x;
}
int main()
{
float x = h2f(1.0f16);
return !(x == 1.0f);
} This is the test I am running.
LLVM uses __aeabi_h2f instead. Hence why this change is here to standardise the interfaces.
I've tested it on Linux- it works. It's actually quite hard to write a test case that works for this without inline assembly. Also, in the |
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 #126880 to go to 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
Looking up what AEABI_RTABI expands to
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.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your description will become the commit message (can be altered at squash and merge time).
Will be worth rewriting it to be closer to the intended commit message if you don't have commit access.
Will be worth mentioning that the __gnu_h2f_ieee
and __gnu_f2h_ieee
functions in Arm use the base-standard ABI like the __aeabi_
functions so we must use a call for hard-float Arm targets but can use an alias for base-standard targets.
@@ -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); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the default for all non-Arm targets, as written this will disappear from all but the __ARM_EABI__
targets.
This is probably fine in practice as at least recent versions of clang will not call __gnu_h2f_ieee
and __gnu_f2h_ieee
for non Arm targets. It will be worth a #else for #if defined(__ARM_EABI__
) with this line just in case a new compiler-rt is used with an old object with such a call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep it is below
Ok, commit is ready to merge at any time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved on my side. Will leave the PR open for a few days to give other reviewers a chance to comment
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks better, thanks. LGTM.
@saturn691 Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
Move to a consistent calling convention for both Clang/GNU such that they can be linked with each other.
All ARM targets now use the soft-float calling convention for
__gnu_h2f_ieee
and__gnu_f2h_ieee
, as described in https://github.com/ARM-software/abi-aa/blob/main/rtabi32/rtabi32.rst#the-floating-point-helper-functions.