Skip to content
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

Windows x86: Change i128 to return via the vector ABI #134290

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tgross35
Copy link
Contributor

@tgross35 tgross35 commented Dec 14, 2024

Clang and GCC both return i128 in xmm0 on windows-msvc and windows-gnu. Currently, Rust returns the type on the stack. Add a calling convention adjustment so we also return scalar i128s using the vector ABI, which makes our i128 compatible with C.

In the future, Clang may change to return i128 on the stack for its -msvc targets (more at [1]). If this happens, the change here will need to be adjusted to only affect MinGW.

Link: #134288 (does not fix) [1]

try-job: x86_64-msvc
try-job: x86_64-msvc-ext1
try-job: x86_64-mingw-1
try-job: x86_64-mingw-2

@rustbot
Copy link
Collaborator

rustbot commented Dec 14, 2024

r? @SparrowLii

rustbot has assigned @SparrowLii.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Dec 14, 2024
@tgross35
Copy link
Contributor Author

tgross35 commented Dec 14, 2024

This should make us consistent for now, even if Clang isn't yet doing the best thing on MSVC.

The third commit's diff shows how the tests change.

Cc @beetrees @wesleywiser

@tgross35
Copy link
Contributor Author

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 14, 2024
Windows x86: Change i128 to return via the vector ABI

Clang and GCC both return `i128` in xmm0 on windows-msvc and windows-gnu. Currently, Rust returns the type on the stack. Add a calling convention adjustment so we also return scalar `i128`s using the vector ABI, which makes our `i128` compatible with C.

In the future, Clang may change to return `i128` on the stack for its `-msvc` targets (more at [1]). If this happens, the change here will need to be adjusted to only affect MinGW.

Link: rust-lang#134288 (does not fix)

try-job: x86_64-msvc
try-job: x86_64-msvc-ext1
try-job: x86_64-mingw-1
try-job: x86_64-mingw-2
@bors
Copy link
Contributor

bors commented Dec 14, 2024

⌛ Trying commit 706db2b with merge 4c26894...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Dec 14, 2024

💔 Test failed - checks-actions

@bors bors 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 Dec 14, 2024
@tgross35
Copy link
Contributor Author

I validated the codegen on a non-windows machine - it looks like the default filecheck labels get applied based on the host rather than the target? That’s interesting.

@bjorn3
Copy link
Member

bjorn3 commented Dec 14, 2024

Please double check that this doesn't break ABI compat between cg_llvm and cg_clif. And

// Pass i128 arguments by-ref on Windows.
will almost certainly need to be adjusted too.

@tgross35
Copy link
Contributor Author

tgross35 commented Dec 14, 2024

Please double check that this doesn't break ABI compat between cg_llvm and cg_clif. And

// Pass i128 arguments by-ref on Windows.

will almost certainly need to be adjusted too.

That link looks to be for libcalls but those have to already be correct on cranelift, right? We have a hack to use Clang/GCC's return ABI in builtins https://github.com/rust-lang/compiler-builtins/blob/a09218f1c4d23ffbd97d68f0fefb5feed2469dc5/src/macros.rs#L583C9-L583C30.

What is the best way to verify Cranelift's ABI? If asm tests can run with both backends then I can add that (also does this get covered in one of the CI jobs?)

@bjorn3
Copy link
Member

bjorn3 commented Dec 14, 2024

__rust_i128_mulo and __rust_u128_mulo do change ABI with this PR:

if is_signed { "__rust_i128_mulo" } else { "__rust_u128_mulo" },

Adjusting the lib_call function directly would also allow getting rid of the if condition at

if fx.tcx.sess.target.is_like_windows {
which currently handles the adjustments for non-rust intrinsics.

@tgross35
Copy link
Contributor Author

tgross35 commented Dec 14, 2024

__rust_i128_mulo and __rust_u128_mulo do change ABI with this PR:

if is_signed { "__rust_i128_mulo" } else { "__rust_u128_mulo" },

I don't think these should change since they return an aggregate type https://github.com/rust-lang/compiler-builtins/blob/a09218f1c4d23ffbd97d68f0fefb5feed2469dc5/src/int/mul.rs#L131, and the change here is only for scalars. Testing with this PR the IR signature for that is:

define void @__rust_i128_mulo(ptr dead_on_unwind noalias nocapture noundef writable writeonly sret([32 x i8]) align 16 dereferenceable(32) %_0, ptr noalias nocapture noundef readonly align 16 dereferenceable(16) %a, ptr noalias nocapture noundef readonly align 16 dereferenceable(16) %b) unnamed_addr #0`

I can make the adjustments to lib_call. But does this handle all extern calls in Cranelift, or is there a separate place that I should also update for non-libcall extern "C"?

@workingjubilee
Copy link
Member

huh, why do we rely on certain tuples having a fixed meaning in the C ABI?

@tgross35
Copy link
Contributor Author

tgross35 commented Dec 14, 2024

Good question :) Maybe those should change to a C-like fn(a: &mut i128, b: i128) -> bool at some point?

@tgross35 tgross35 force-pushed the windows-i128-callconv branch from 706db2b to d5bc586 Compare December 15, 2024 08:18
@rustbot rustbot added A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Dec 15, 2024
@rustbot
Copy link
Collaborator

rustbot commented Dec 15, 2024

Some changes occurred in src/tools/compiletest

cc @jieyouxu

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

@tgross35
Copy link
Contributor Author

@bors try

@tgross35
Copy link
Contributor Author

@bors ping

@bors
Copy link
Contributor

bors commented Dec 15, 2024

😪 I'm awake I'm awake

@bors
Copy link
Contributor

bors commented Dec 15, 2024

⌛ Trying commit d5bc586 with merge 31dc001...

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 15, 2024
Windows x86: Change i128 to return via the vector ABI

Clang and GCC both return `i128` in xmm0 on windows-msvc and windows-gnu. Currently, Rust returns the type on the stack. Add a calling convention adjustment so we also return scalar `i128`s using the vector ABI, which makes our `i128` compatible with C.

In the future, Clang may change to return `i128` on the stack for its `-msvc` targets (more at [1]). If this happens, the change here will need to be adjusted to only affect MinGW.

Link: rust-lang#134288 (does not fix)

try-job: x86_64-msvc
try-job: x86_64-msvc-ext1
try-job: x86_64-mingw-1
try-job: x86_64-mingw-2
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 22, 2024
@tgross35 tgross35 added the O-windows Operating system: Windows label Dec 22, 2024
@bors
Copy link
Contributor

bors commented Dec 22, 2024

☀️ Try build successful - checks-actions
Build commit: a35b226 (a35b22680f28823a88b3520a52f7839f35a8fef2)

@tgross35
Copy link
Contributor Author

tgross35 commented Jan 9, 2025

@bjorn3 I saw the mention in the abi-cafe issue, are you able to double check the cranelift changes here?

@bjorn3
Copy link
Member

bjorn3 commented Jan 9, 2025

I don't have a Windows machine to test it on locally. Also I assumed that the __rust_u/i128_mulo change would land first. After that I think it would be possible to do a try build here and then in cg_clif's CI pull in the cg_clif changes and use rustup-toolchain-install-master to run against the try build.

@tgross35
Copy link
Contributor Author

tgross35 commented Jan 9, 2025

Oh, I was thinking they had to land the other way around. I’ll get that one ready to go then, but unfortunately updating compiler-builtins in r-l/rust is temporarily blocked on something like #13527 (or me reverting the libm submodule updates so the diagnostics don’t show up, but I’m hoping to not need that).

@bjorn3
Copy link
Member

bjorn3 commented Jan 9, 2025

I think you missed a digit in the issue number.

@tgross35
Copy link
Contributor Author

tgross35 commented Jan 9, 2025

Sorry, #135278 to fix new libm traits showing up in diagnostics.

Currently we both pass and return `i128` indirectly on Windows for MSVC
and MinGW, but this will be adjusted. Introduce a test verifying the
current state.
@tgross35 tgross35 force-pushed the windows-i128-callconv branch from 3557d39 to 6acd4e6 Compare January 15, 2025 20:26
@tgross35
Copy link
Contributor Author

I don't have a Windows machine to test it on locally. Also I assumed that the __rust_u/i128_mulo change would land first. After that I think it would be possible to do a try build here and then in cg_clif's CI pull in the cg_clif changes and use rustup-toolchain-install-master to run against the try build.

The mulo changes landed.

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 15, 2025
Windows x86: Change i128 to return via the vector ABI

Clang and GCC both return `i128` in xmm0 on windows-msvc and windows-gnu. Currently, Rust returns the type on the stack. Add a calling convention adjustment so we also return scalar `i128`s using the vector ABI, which makes our `i128` compatible with C.

In the future, Clang may change to return `i128` on the stack for its `-msvc` targets (more at [1]). If this happens, the change here will need to be adjusted to only affect MinGW.

Link: rust-lang#134288 (does not fix) [1]

try-job: x86_64-msvc
try-job: x86_64-msvc-ext1
try-job: x86_64-mingw-1
try-job: x86_64-mingw-2
@bors
Copy link
Contributor

bors commented Jan 15, 2025

⌛ Trying commit 6acd4e6 with merge f168ac9...

@bors
Copy link
Contributor

bors commented Jan 15, 2025

☀️ Try build successful - checks-actions
Build commit: f168ac9 (f168ac95ecc8e1903caa79ddf2515e8672e838ab)

@tgross35
Copy link
Contributor Author

@bjorn3 what exactly needs to happen in the cg_cranelift repo to test this? I don't see any obvious point that the toolchain should be changed.

Also unsure whether I should have run a dist job.

Clang and GCC both return `i128` in xmm0 on windows-msvc and
windows-gnu. Currently, Rust returns the type on the stack. Add a
calling convention adjustment so we also return scalar `i128`s using the
vector ABI, which makes our `i128` compatible with C.

In the future, Clang may change to return `i128` on the stack for its
`-msvc` targets (more at [1]). If this happens, the change here will
need to be adjusted to only affect MinGW.

Link: rust-lang#134288
@tgross35 tgross35 force-pushed the windows-i128-callconv branch from 6f893f9 to 2f13d43 Compare January 16, 2025 10:12
@bjorn3
Copy link
Member

bjorn3 commented Jan 16, 2025

#134338 didn't break anything in cg_clif's CI and the cg_clif changes in this PR LGTM.

@bors r=bjorn3,wesleywiser

@bors
Copy link
Contributor

bors commented Jan 16, 2025

📌 Commit 2f13d43 has been approved by bjorn3,wesleywiser

It is now in the queue for this repository.

@bors bors 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 Jan 16, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 17, 2025
…bjorn3,wesleywiser

Windows x86: Change i128 to return via the vector ABI

Clang and GCC both return `i128` in xmm0 on windows-msvc and windows-gnu. Currently, Rust returns the type on the stack. Add a calling convention adjustment so we also return scalar `i128`s using the vector ABI, which makes our `i128` compatible with C.

In the future, Clang may change to return `i128` on the stack for its `-msvc` targets (more at [1]). If this happens, the change here will need to be adjusted to only affect MinGW.

Link: rust-lang#134288 (does not fix) [1]

try-job: x86_64-msvc
try-job: x86_64-msvc-ext1
try-job: x86_64-mingw-1
try-job: x86_64-mingw-2
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 17, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#131806 (Treat other items as functions for the purpose of type-based search)
 - rust-lang#134290 (Windows x86: Change i128 to return via the vector ABI)
 - rust-lang#134980 (Location-sensitive polonius prototype: endgame)
 - rust-lang#135558 (Detect if-else chains with a missing final else in type errors)
 - rust-lang#135594 (fix error for when results in a rustdoc-js test are in the wrong order)
 - rust-lang#135601 (Fix suggestion to convert dereference of raw pointer to ref)
 - rust-lang#135604 (Expand docs for `E0207` with additional example)

r? `@ghost`
`@rustbot` modify labels: rollup
@matthiaskrgr
Copy link
Member

@bors r- rollup=iffy
#135613 (comment)

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-windows Operating system: Windows S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

10 participants