Skip to content

Don't compute FnAbi for LLVM intrinsics - #160077

Merged
rust-bors[bot] merged 5 commits into
rust-lang:mainfrom
bjorn3:no_unadjusted_fn_abi
Aug 14, 2026
Merged

Don't compute FnAbi for LLVM intrinsics#160077
rust-bors[bot] merged 5 commits into
rust-lang:mainfrom
bjorn3:no_unadjusted_fn_abi

Conversation

@bjorn3

@bjorn3 bjorn3 commented Jul 28, 2026

Copy link
Copy Markdown
Member

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

@rustbot

rustbot commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

These commits modify compiler targets.
(See the Target Tier Policy.)

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 28, 2026
@rustbot

rustbot commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

RalfJung is not on the review rotation at the moment.
They may take a while to respond.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Comment thread compiler/rustc_const_eval/src/interpret/step.rs Outdated
@rust-log-analyzer

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>);

@bjorn3 bjorn3 Jul 29, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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] }.

View changes since the review

@bjorn3
bjorn3 force-pushed the no_unadjusted_fn_abi branch from 7358ce7 to eacedff Compare July 29, 2026 10:58
@bjorn3

bjorn3 commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

Looks like compiler-builtins still has some extern "unadjusted" definitions. Will need to replace those.

@bjorn3
bjorn3 force-pushed the no_unadjusted_fn_abi branch 2 times, most recently from ef2938a to e2873a0 Compare July 31, 2026 12:28
@rustbot

rustbot commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

compiler-builtins is developed in its own repository. If possible, consider making this change to rust-lang/compiler-builtins instead.

cc @tgross35

@rustbot rustbot added the A-compiler-builtins Area: compiler-builtins (https://github.com/rust-lang/compiler-builtins) label Jul 31, 2026

@RalfJung RalfJung left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interpreter changes mostly LGTM.

compiler-builtins changes will need a review by @tgross35 .

View changes since this review

Comment thread compiler/rustc_const_eval/src/interpret/step.rs Outdated
Comment thread compiler/rustc_const_eval/src/interpret/step.rs Outdated
Comment thread compiler/rustc_monomorphize/src/mono_checks/abi_check.rs
Comment thread compiler/rustc_ty_utils/src/abi.rs
Comment thread tests/codegen-llvm/simd/unpadded-simd.rs Outdated
Comment on lines -282 to +310
#[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)
}

@tgross35 tgross35 Aug 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@RalfJung

RalfJung commented Aug 3, 2026

Copy link
Copy Markdown
Member

@rustbot author
Open discussions are: the test, and compiler-builtins.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 3, 2026
@rust-log-analyzer

This comment has been minimized.

@bjorn3
bjorn3 force-pushed the no_unadjusted_fn_abi branch from d2588c6 to a457bee Compare August 4, 2026 13:32
@bjorn3

bjorn3 commented Aug 4, 2026

Copy link
Copy Markdown
Member Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 4, 2026
@RalfJung

RalfJung commented Aug 4, 2026

Copy link
Copy Markdown
Member

r=me on the Miri part and the test.
r? @tgross35
for the compiler-builtins part

@rustbot rustbot assigned tgross35 and unassigned RalfJung Aug 4, 2026
@rustbot

rustbot commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

tgross35 is currently at their maximum review capacity.
They may take a while to respond.

Comment on lines -176 to +197
#[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
}

@tgross35 tgross35 Aug 13, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is just called f

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@rust-log-analyzer

This comment has been minimized.

@bjorn3
bjorn3 force-pushed the no_unadjusted_fn_abi branch from 85cb480 to 0417c4e Compare August 13, 2026 12:25
@rustbot

rustbot commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

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.

@bjorn3

bjorn3 commented Aug 13, 2026

Copy link
Copy Markdown
Member Author

Rebased, fixed test for LLVM 23 and changed the ABI cfg for __muloti4 to just x86_64 UEFI to match other 128bit intrinsics.

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c-b portion LGTM, so I think this is all set with Ralf's review. Though I still don't know why UEFI needs this special ABI in the first place.

Is the eventual goal to get rid of extern "unadjusted"?

View changes since this review

@bjorn3

bjorn3 commented Aug 13, 2026

Copy link
Copy Markdown
Member Author

With this PR extern "unadjusted" is effectively extern "llvm-intrinsic" just like we used to have extern "rust-intrinsic". Doing that rename would be a pain though.

@bors r=RalfJung,tgross35

@rust-bors

rust-bors Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 0417c4e has been approved by RalfJung,tgross35

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 13, 2026
@tgross35

Copy link
Copy Markdown
Contributor

With this PR extern "unadjusted" is effectively extern "llvm-intrinsic" just like we used to have extern "rust-intrinsic". Doing that rename would be a pain though.

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?

rust-bors Bot pushed a commit that referenced this pull request Aug 14, 2026
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")
rust-bors Bot pushed a commit that referenced this pull request Aug 14, 2026
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")
@rust-bors
rust-bors Bot merged commit a4b0909 into rust-lang:main Aug 14, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Aug 14, 2026
rust-timer added a commit that referenced this pull request Aug 14, 2026
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
rust-bors Bot pushed a commit that referenced this pull request Aug 14, 2026
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
@bjorn3
bjorn3 deleted the no_unadjusted_fn_abi branch August 14, 2026 11:09
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (a96bde1): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking 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 count

This 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.

Cycles

Results (primary -3.8%, secondary -1.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.0% [2.0%, 2.0%] 1
Improvements ✅
(primary)
-3.8% [-3.8%, -3.8%] 1
Improvements ✅
(secondary)
-4.2% [-4.2%, -4.2%] 1
All ❌✅ (primary) -3.8% [-3.8%, -3.8%] 1

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 455.615s -> 458.245s (0.58%)
Artifact size: 396.47 MiB -> 396.34 MiB (-0.03%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-compiler-builtins Area: compiler-builtins (https://github.com/rust-lang/compiler-builtins) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants