-
Notifications
You must be signed in to change notification settings - Fork 12k
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
ABI change in __extendhfsf2
and __truncsfhf2
on X86
#56854
Comments
@llvm/issue-subscribers-backend-x86 |
This seems like it would be a blocker. Who worked on Float16 and can chime in? |
@kparzysz-quic Which platform you are using? AFAIK, only Darwin uses |
I worked on that. I don't think this is a blocker. The change of the ABI is expected. GCC 12 uses the same ABI as well. https://godbolt.org/z/bc4xx5zoa |
To recap: I work on a project where LLVM libraries are used as code generator in another application.
|
I see your point, just wondering if it is an inherent problem for compiler-rt if codegen doing ABI break change. |
I guess a flag ( |
It's possible to do it in compiler, but there's still problem in compiler-rt. Because Thinking it again. I doubt if it really a reasonable user scenario in your case. We should always use the same compiler-rt with the same compiler version. E.g., D126953 introduced a libcall |
I think the best thing ultimately (for TVM) would be to just emit the conversion code directly into the module... |
The best way is keep the compiler-rt the same version as compiler. |
Just so I am following along correctly - is it something we want to try to fix before 15 - or can I remove this as a release blocker? |
Yes. I think so. Maybe we can close it @kparzysz-quic ? |
It doesn't seem like this is something that can be fixed, but maybe Saleem (@compnerd) could chime in before we close this. |
The compiler-rt builtins are supposed to match the GCC ABI. We are matching the GCC ABI so this seems like the correct behaviour. Overall, the builtins are supposed to have a pretty stable ABI, so it is rather unfortunate that this broke. Replacing the implementation for I am left wondering how bad of a problem would this be in practice. I haven't given it too much thought, but perhaps we can get away with something like providing both variants and an alias, associated with a comdat symbol and have the compiler select between the two if there is FP16 usage without FP16 hardware support. This would be a pretty hefty penalty for the compiler (and would potentially leak some impact into link times as well). I am rather reluctant to go down that path. |
The worst outcome is that user code compiles and links, but gives a wrong answer. Something like what we do for ABI breaking checks (i.e. introducing version symbols and forcing a linking error) would be nice, but given that we want to be able to link with GCC's runtime, this doesn't seem like a solution either. I don't want to impose any restrictions on compiler-rt that would hinder LLVM or clang, so maybe we're stuck with the current situation. I just wanted to make sure that we don't leave any option unexplored. |
I think that build time checks would be able to alleviate that concern (à la autotools). It should be possible to craft a simple test that helps identify which variant of the ABI is in use and then either abort or change the code generation. |
That may be the way out of this. Anyway, we should document this change in the release notes, if it's not there yet. Thanks everyone for your inputs. |
There's a very basic note there: https://github.com/llvm/llvm-project/blob/release/15.x/llvm/docs/ReleaseNotes.rst#changes-to-the-x86-backend |
@phoebewang you can do the change directly on the release/15.x branch and we will take care of the rest. |
Yeah, I can put it in my fork repo and then cherry-pick. Thanks @tru. |
I put a patch D131172. |
See llvm/llvm-project#56854 for more details.
#56854 shows a backwards compatibility problem when builtins of compiler-rt don't follow ABI. We need to prevent to fall into the trap again for BF16. Reviewed By: bkramer Differential Revision: https://reviews.llvm.org/D131147
compiler-rt 15 has a breaking ABI change affecting how half precision floating point values are passed between functions (llvm/llvm-project#56854). For reasons I don't fully understand, different versions of clang exhibit the issue on different OSes. For example on Ubuntu 22.04 clang-15 is affected and clang-16 is OK, but on Fedora clang-16 is affected. clang-16 is also the default on Fedora meaning that all the half precision tests fail with random numbers because they're reading garbage. There's a one-liner to test for this issue in the LLVM project, so make use of that to tell if the CLANG backend will produce correct results.
…e can Taking a hint from llvm/llvm-project#56854 (comment) we can make use of `-march=native` flag to replace the library call with a native instruction on Ivy Bridge and above. This doesn't fix the bug in compiler-rt, but it means that we can support CLANG on more hardware. Note that the usual issues of `-march=native` shouldn't affect us since we only compile these at runtime and we're building on the same machine that we're running on. I've not measured if this improves the speed, only that the tests now pass.
compiler-rt 15 has a breaking ABI change affecting how half precision floating point values are passed between functions (llvm/llvm-project#56854). For reasons I don't fully understand, different versions of clang exhibit the issue on different OSes. For example on Ubuntu 22.04 clang-15 is affected and clang-16 is OK, but on Fedora clang-16 is affected. clang-16 is also the default on Fedora meaning that all the half precision tests fail with random numbers because they're reading garbage. There's a one-liner to test for this issue in the LLVM project, so make use of that to tell if the CLANG backend will produce correct results.
…e can Taking a hint from llvm/llvm-project#56854 (comment) we can make use of `-march=native` flag to replace the library call with a native instruction on Ivy Bridge and above. This doesn't fix the bug in compiler-rt, but it means that we can support CLANG on more hardware. Note that the usual issues of `-march=native` shouldn't affect us since we only compile these at runtime and we're building on the same machine that we're running on. I've not measured if this improves the speed, only that the tests now pass.
Bug: llvm/llvm-project#69842 Bug: gentoo#33400 Reference: llvm/llvm-project#56854 Signed-off-by: Benda Xu <heroxbd@gentoo.org>
Closes: https://bugs.gentoo.org/916069 Bug: llvm/llvm-project#69842 Bug: gentoo#33400 Reference: llvm/llvm-project#56854 Signed-off-by: Benda Xu <heroxbd@gentoo.org>
See also: https://discourse.llvm.org/t/how-to-build-compiler-rt-for-new-x86-half-float-abi/63366/15
Support for
_Float16
was added in 15.0.0 (based on target capabilities). This had the unfortunate consequence that it changed the way calls to__truncsfhf2
and__extendhfsf2
are handled: in prior version of LLVM, or in the absence of support for_Float16
, the half-precision floating point value was passed asuint16_t
. In the x86 calling convention that type is passed in RDI, whereas_Float16
values are passed in XMM0. This introduces binary incompatibility between LLVM 15 and prior versions.The text was updated successfully, but these errors were encountered: