Don't compute FnAbi for LLVM intrinsics - #160077
Conversation
|
Some changes occurred to the CTFE machinery These commits modify compiler targets. Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri |
|
|
|
I guess this finishes my quest of getting rid of
There is still cleanup that can be done, but at least this wildly wrong combination is gone. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| fn test_f32x2(a: f32x2); | ||
| fn test_f32x2_arr(a: f32x2); | ||
| fn test_simd(a: Simd<i32, 4>); | ||
| fn test_simd_unaligned(a: Simd<i32, 3>); |
There was a problem hiding this comment.
There is no way to test this specific case anymore it seems. LLVM doesn't accept PackedSimd on intrinsics, extern "unadjusted" requires LLVM intrinsics and any other ABI doesn't pass non-power-of-2 vectors as { [3 x i32] }.
7358ce7 to
eacedff
Compare
|
Looks like compiler-builtins still has some |
ef2938a to
e2873a0
Compare
|
cc @tgross35 |
There was a problem hiding this comment.
interpreter changes mostly LGTM.
compiler-builtins changes will need a review by @tgross35 .
| #[cfg_attr(target_os = "uefi", unadjusted_on_win64)] | ||
| #[cfg(not(all(target_os = "uefi", target_arch = "x86_64")))] | ||
| pub extern "C" fn __floattisf(i: i128) -> f32 { | ||
| int_to_float::signed(i, int_to_float::u128_to_f32_bits) | ||
| } | ||
|
|
||
| #[cfg_attr(target_os = "uefi", unadjusted_on_win64)] | ||
| #[cfg(all(target_os = "uefi", target_arch = "x86_64"))] | ||
| pub extern "C" fn __floattisf(lo: u64, hi: u64) -> f32 { | ||
| int_to_float::signed((i128::from(hi) << 64) | i128::from(lo), int_to_float::u128_to_f32_bits) | ||
| } | ||
|
|
||
| #[cfg(not(all(target_os = "uefi", target_arch = "x86_64")))] | ||
| pub extern "C" fn __floattidf(i: i128) -> f64 { | ||
| int_to_float::signed(i, int_to_float::u128_to_f64_bits) | ||
| } | ||
|
|
||
| #[cfg(all(target_os = "uefi", target_arch = "x86_64"))] | ||
| pub extern "C" fn __floattidf(lo: u64, hi: u64) -> f64 { | ||
| int_to_float::signed((i128::from(hi) << 64) | i128::from(lo), int_to_float::u128_to_f64_bits) | ||
| } |
There was a problem hiding this comment.
Do we even need the special casing anymore? i128 has gone through some ABI changes on Windows and it doesn't look like https://github.com/llvm/llvm-project/blob/41322057c3af16d75e239ec6679c6c2bf7aec157/compiler-rt/lib/builtins/floattisf.c#L28 is doing anything special.
There was a problem hiding this comment.
Yes, they still have different ABIs: https://rust.godbolt.org/z/454nczzdr u128 is passed in xmm0 with extern "C", while u64 + u64 is passed in rdx/rcx just like u128 with extern "unadjusted": https://rust.godbolt.org/z/av1f38KrW
There was a problem hiding this comment.
Looking at https://rust.godbolt.org/z/fYMc6b8MP I think that Windows is in harmony; always pass indirectly, return in xmm0. I couldn't get it to emit __muloti4.
UEFI seems to be the one that's weird - if I'm reading right it's usually passed indirectly and returned in rax,rdx, but for the __floattisf libcall it seems to be loading into rcx and rdx? I have no idea where this comes from, it doesn't appear to be in https://github.com/llvm/llvm-project/blob/f532c2d780d3afe589b43cb920fbc445322d47f7/compiler-rt/lib/builtins/floattisf.c#L28 so I wonder if it's an oversight in LLVM.
|
@rustbot author |
This comment has been minimized.
This comment has been minimized.
d2588c6 to
a457bee
Compare
|
@rustbot ready |
|
r=me on the Miri part and the test. |
|
|
| #[unadjusted_on_win64] | ||
| #[cfg(not(all( | ||
| any(windows, target_os = "cygwin", all(target_os = "uefi", target_arch = "x86_64")), | ||
| target_pointer_width = "64", | ||
| )))] | ||
| pub extern "C" fn __muloti4(a: i128, b: i128, oflow: &mut i32) -> i128 { | ||
| let (mul, o) = i128_overflowing_mul(a, b); | ||
| *oflow = o as i32; | ||
| mul | ||
| } | ||
|
|
||
| #[cfg(all( | ||
| any(windows, target_os = "cygwin", all(target_os = "uefi", target_arch = "x86_64")), | ||
| target_pointer_width = "64", | ||
| ))] | ||
| pub extern "C" fn f(a_lo: u64, a_hi: u64, b_lo: u64, b_hi: u64, oflow: &mut i32) -> i128 { | ||
| let (mul, o) = i128_overflowing_mul( | ||
| (i128::from(a_hi) << 64) | i128::from(a_lo), | ||
| (i128::from(b_hi) << 64) | i128::from(b_lo), | ||
| ); | ||
| *oflow = o as i32; | ||
| mul | ||
| } |
There was a problem hiding this comment.
This function is just called f
There was a problem hiding this comment.
I think this can just be dropped; as mentioned in #160077 (comment), I can't get LLVM to emit __muloti4 and I'd expect/hope it to use the usual Windows ABI if it did.
Does cranelift need these on these targets with a different ABI?
There was a problem hiding this comment.
I've fixed the function name.
cg_clif used to use __muloti4, but stopped using it about 2 years ago. Would you mind if dropping unnecessary intrinsics is moved to a separate PR. That would make it easier to revert if it turns out to be used after all and avoids scope creep for this PR.
There was a problem hiding this comment.
I didn't mean entirely, could you just delete the __muloti4(a_lo: u64, a_hi: u64, b_lo: u64, b_hi: u64, oflow: &mut i32) and leave the existing __muloti4(a: i128, b: i128, oflow: &mut i32)? I just ideally don't want to break tests on Windows when this syncs back.
Or cfg to UEFI-only and match the others
This comment has been minimized.
This comment has been minimized.
85cb480 to
0417c4e
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Rebased, fixed test for LLVM 23 and changed the ABI cfg for |
|
With this PR @bors r=RalfJung,tgross35 |
That makes way more sense, I never understood what "unadjusted" was referring to. Perhaps both names should be accepted and stdarch can migrate in pieces? |
Rollup of 23 pull requests Successful merges: - #157428 (allocator: refactor for stabilisation) - #158918 (x86_64-win: Enable f128 on LLVM 23+) - #160077 (Don't compute FnAbi for LLVM intrinsics) - #160288 (rustdoc: use anonymous constant for primitives/keywords/attribute docs) - #160440 (Couple of misc improvements to the unwind infrastructure) - #160896 (tidy: Update Python version requirements to 3.11) - #160972 (std: map ERROR_NEGATIVE_SEEK to ErrorKind::InvalidInput on Windows) - #160984 (Fix ICE on { _ } const args in bodies by tracking const-only infer args) - #161036 (Use `with_types_for_suggestion!` in `write_struct_like()`) - #161037 (std: don't clean up the main thread's altstack) - #161040 (Optimize CStr backing slice bounds checks) - #161065 (core: Fix a typo in funnel shift documentation) - #158885 (Add `core::num::Complex`) - #160928 (check `mut`-restriction when tuple constructor is used as a value) - #160969 (give layout errors from `size_of_val` and `align_of_val` a span) - #161002 (disallow `#[cold]` on `extern "custom"` functions) - #161016 (Fix invalid suggestion from try unlabled block) - #161020 (io: Use `NonNull` for all `Custom` API related to `Box`, update documentation for `Custom`) - #161044 (rustc-dev-guide subtree update) - #161046 (Enable unrolling feature of bors) - #161054 (rustdoc: Fix link title attribute value when field of enum variants) - #161055 (`offload!` function-like macro) - #161064 (Revert "riscv: promote d, e, and f target_features to CfgStableToggleUnstable")
Rollup of 23 pull requests Successful merges: - #157428 (allocator: refactor for stabilisation) - #158918 (x86_64-win: Enable f128 on LLVM 23+) - #160077 (Don't compute FnAbi for LLVM intrinsics) - #160288 (rustdoc: use anonymous constant for primitives/keywords/attribute docs) - #160440 (Couple of misc improvements to the unwind infrastructure) - #160896 (tidy: Update Python version requirements to 3.11) - #160972 (std: map ERROR_NEGATIVE_SEEK to ErrorKind::InvalidInput on Windows) - #160984 (Fix ICE on { _ } const args in bodies by tracking const-only infer args) - #161036 (Use `with_types_for_suggestion!` in `write_struct_like()`) - #161037 (std: don't clean up the main thread's altstack) - #161040 (Optimize CStr backing slice bounds checks) - #161065 (core: Fix a typo in funnel shift documentation) - #158885 (Add `core::num::Complex`) - #160928 (check `mut`-restriction when tuple constructor is used as a value) - #160969 (give layout errors from `size_of_val` and `align_of_val` a span) - #161002 (disallow `#[cold]` on `extern "custom"` functions) - #161016 (Fix invalid suggestion from try unlabled block) - #161020 (io: Use `NonNull` for all `Custom` API related to `Box`, update documentation for `Custom`) - #161044 (rustc-dev-guide subtree update) - #161046 (Enable unrolling feature of bors) - #161054 (rustdoc: Fix link title attribute value when field of enum variants) - #161055 (`offload!` function-like macro) - #161064 (Revert "riscv: promote d, e, and f target_features to CfgStableToggleUnstable")
Rollup merge of #160077 - bjorn3:no_unadjusted_fn_abi, r=RalfJung,tgross35 Don't compute FnAbi for LLVM intrinsics They don't have a sensible FnAbi, so the fact that we still compute an FnAbi for them requires us to make the ABI sanity check more lenient than it should be. r? @RalfJung as all non-trivial changes are in Miri
Rollup merge of #160077 - bjorn3:no_unadjusted_fn_abi, r=RalfJung,tgross35 Don't compute FnAbi for LLVM intrinsics They don't have a sensible FnAbi, so the fact that we still compute an FnAbi for them requires us to make the ABI sanity check more lenient than it should be. r? @RalfJung as all non-trivial changes are in Miri
|
Finished benchmarking commit (a96bde1): comparison URL. Overall result: no relevant changes - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countThis perf run didn't have relevant results for this metric. Max RSS (memory usage)This perf run didn't have relevant results for this metric. CyclesResults (primary -3.8%, secondary -1.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 455.615s -> 458.245s (0.58%) |
View all comments
They don't have a sensible FnAbi, so the fact that we still compute an FnAbi for them requires us to make the ABI sanity check more lenient than it should be.
r? @RalfJung as all non-trivial changes are in Miri