-
Notifications
You must be signed in to change notification settings - Fork 13.4k
ABI for float builtins depends on target features #112885
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
Comments
I would argue this is a per-call-site decision, see also #70563. IIUC, the most problematic situation here is code that is generally built for i386 without any SSE support, but then has some fast-paths for when SSE2 is available. That code will presumably be linked with a compiler_rt built without SSE support, but float operations inside the functions that have SSE2 enabled will expect the callee to use the SSE register. If |
@RalfJung For calls to builtins, there is usually no |
Isn't that happening on some different IR? I'm not familiar with the lower ends of LLVM -- I heard there's Machine IR there. If this is never in any IR it should be easier -- the legalization "just" has to pass through the information which ABI to use, to make it clear that this should not be adjusted to whatever the target features of the current function are. (I'm sure it's not actually easy, the devil is always in the details.) |
The legalization call will be inserted in SelectionDAG or gMIR |
For reference both gcc and clang just reject |
Both GCC and Clang support |
@EugeneZelenko why was this tagged with "clang:..."? This is mostly an LLVM backend issue, causing some issues in Rust that will have to be resolved before we can fully ship f16 / f128.
So... does this mean that these builtins will actually be built with SSE support even on targets where SSE is off-by-default? |
What would an ideal solution look like here? If target features are always sufficient to indicate the ABI, then would a way to change the libcalls like
Which libraries? Since Clang and GCC both reject LLVM actually seems to use different symbols for |
This is leaking way too specific backend details in very a bad way. There should be a separate higher level ABI control to disable SSE registers, rather than having the target features directly set ABI |
What would this look like, since it needs to somehow be per-function controllable? As show in the top post's examples. LLVM could also specify different builtin names, e.g. suffix with |
Hm, I didn't say "library" so I am confused now... What I mean is: there are certain standard symbols LLVM expects to exist that provide these operations, such as
LLVM is already leaking all those details. Frontends have to know which target features affect the ABI and how to be able to guard against LLVM just making up a different unexpected ABI. I'd love to see this reformed. :) |
LLVM |
I don't believe SSE is ever somehow enabled for the purpose of supporting these symbols. As far as I can tell, when vector registers are not available, LLVM changes its default ABI for these types to pass as integers and expects builtin calls to do the same (which is reasonable). This is visible in Clang for As beetrees mentioned, compiler-rt has a fallback that uses the integer ABI but I don't think it could ever be used from C (also GCC doesn't seem to have something similar), though it does have the GCC rejects Some experimentation https://gcc.godbolt.org/z/Yc5s5ocE5 |
When LLVM needs to call a builtin (such as
__truncdfhf2
or__addtf3
), it will use whatever ABI is the default for the target features of the function that is currently being compiled. This means that on targets where the ABI of float types is target-feature dependant (e.g. the ABI ofhalf
changes of 32-bit x86 depending on whethersse2
is enabled, and the ABI offp128
changes on PowerPC depending on whethervsx
is enabled), LLVM will call the same builtin function using two different incompatible ABIs.The simplest solution to this seems to be extending the
target-abi
module flag to allow frontends to specify which float ABI gets used for function calls independent of the target features of a function. Other solutions include allowing the frontend to override the names of builtin functions on a per-function-being-compiled level.Related Rust issues: rust-lang/rust#131819, rust-lang/rust#125109
The text was updated successfully, but these errors were encountered: