-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[WIP] Correct lowering of fp128
intrinsics
#76558
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
base: main
Are you sure you want to change the base?
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be 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 If you have received no comments on your PR for a week, you can request a review 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. |
@efriedma-quic was looking at this on phabricator |
16f30b5
to
f6b6ca7
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
f6b6ca7
to
efaf313
Compare
This is basically the approach I was expecting: we check the type of "long double" when we build the TargetLowering, and pick appropriate names based on that. I expect that for -mlong-double-128, you just want to add a module flag that overrides the default choice. I think I'd prefer to keep the clang type information computation independent from the backend's type information, even if it overlaps. We try to layer the clang frontend so it isn't directly tied to LLVM IR outside of CodeGen. My first thought was that the computation of the defaults should be in the backend, not Triple.h, since nothing else needs it at the moment. But I guess it could be useful outside the backend, so maybe that's fine. (At the moment, all the relevant optimizations just check the type of the call itself, but I can imagine certain optimizations could benefit from being able to compute the type without an existing signature to consult.) |
c00254c
to
67033b2
Compare
2208d1c
to
76e30ed
Compare
I'm struggling a bit with how to handle ABI information since that affects layout (e.g. ARM aapcs), which I think explains most of the errors in https://buildkite.com/llvm-project/github-pull-requests/builds/31198#018d26e2-fd17-4e15-a1eb-08580c189056. This needs to be available at TargetLoweringBase::InitLibcalls, which calls TargetMachine is available at that time, so would it be better to move CLayouts from Triple to TargetMachine? If so subclasses could be used rather than the if block, which more closely follows the Clang side. Also, are there currently any module flags that make it to TargetLowering? Looking for a reference on how get the -mlong-double-128 information. |
Putting a function in TargetMachine seems reasonable. |
For the question about querying module flags, we do that in a few different places in codegen; grep for "getModuleFlag". Not sure if there's anything specifically in TargetLowering. |
7a8ef29
to
8add5ca
Compare
`f128` intrinsic functions sometimes lower to `long double` library calls when they instead need to be `f128` versions. Add a test demonstrating current behavior.
Information about the size and alignment of `long double` is currently part of clang. Copy this logic to LLVM so it can be used to control lowering of intrinsics. Additionally, add an assertion to make sure Clang and LLVM agree.
Switch from emitting long double functions to using `f128`-specific functions. Fixes llvm#44744.
8add5ca
to
04e87bd
Compare
Finally getting around to this after more than a year. @efriedma-quic as an alternative to the current implementation of duplicating The advantage is avoided code duplication and the logic is easier to follow. Also this avoids problems if linking a library built with an unexpected The disadvantage is that frontends that don't know about C's (I handle the f128 support for Rust and would much rather never think about |
In either case, I need to have the module flags available pretty early and I'm not sure how to do that. Ideally they would be available when |
; REQUIRES: aarch64-registered-target | ||
; REQUIRES: powerpc-registered-target | ||
; REQUIRES: riscv-registered-target | ||
; REQUIRES: systemz-registered-target | ||
; REQUIRES: x86-registered-target |
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.
Todo: replace this with %if
somehow so this test still runs if only a subset of architectures is available https://llvm.org/docs/TestingGuide.html
Talked to arsenm on discord, long discussion starting around here https://discord.com/channels/636084430946959380/636732535434510338/1362207130559578185. The outcome is that this is effectively a target option and needs to be tied to the triple rather than per-module. Which makes sense and avoids the above problem. So, I'll be doing the following:
This should work because calling
|
Currently
fp128
math intrinsics are lowered to functions expectinglong double
, which is a problem whenlong double
andf128
do not have the same layout (e.g.long double
on x86 isf80
).This patchset does the following:
long double
layout logic from Clang to LLVM so we can use it on all targets__float128
math calls rather thanlong double
calls (sinf128
instead ofsinl
)long double == f128
,I still need to figure out how to support
-mlong-double-128
and similar flags, and need to add a test for a target whereld == f128
such as aarch64. A quick review at this point would still be appreciated to make sure I am on the right track.Fixes: #44744
Discourse discussion: https://discourse.llvm.org/t/fp128-math-functions-strange-results/72708
Initial patchset: https://reviews.llvm.org/D157836 / http://108.170.204.19/D157836