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

compiler: untangle SIMD alignment assumptions #137256

Merged
merged 4 commits into from
Feb 23, 2025

Conversation

workingjubilee
Copy link
Member

@workingjubilee workingjubilee commented Feb 19, 2025

There were a number of puzzling assumptions being made about SIMD types and their layout that I have corrected in this diff. These are mostly no-op edits in actual fact, but they do subtly alter a pair of checks in our invariant-checking and union layout computation that rested on those peculiar assumptions. Those unfortunately stand in the way of any further actual fixes. I submit this for review, even though it's not clearly motivated without its followups, because it should still be possible to independently conclude whether this is correct.

One of these checks is yours, I believe?
r? RalfJung

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented Feb 19, 2025

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

cc @rust-lang/rust-analyzer

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 19, 2025
@RalfJung
Copy link
Member

Sorry, I don't have any knowledge of the vast majority of the code being touched here. I won't be able to review this. I'm not even sure who our experts here are, maybe @bjorn3 or @nikic ?

r? compiler

@rustbot rustbot assigned oli-obk and unassigned RalfJung Feb 19, 2025
@RalfJung
Copy link
Member

Looking at #130402, repr(align) was also implicated in the issues around Scalar/ScalarPair that I mentioned above. For those types, the fix is to use BackendRepr::Aggregate instead when repr(align) is present. Maybe that is also the right fix for SIMD types? Or maybe those can have their alignment overridden in Layout without causing havoc in the rest of the compiler?

@RalfJung
Copy link
Member

(Unrelated, maybe we should rename BackendRepr::Vector to BackendRepr::SimdVector, since for most Rustaceans "vector" will refer to Vec.)

@workingjubilee
Copy link
Member Author

Looking at #130402, repr(align) was also implicated in the issues around Scalar/ScalarPair that I mentioned above. For those types, the fix is to use BackendRepr::Aggregate instead when repr(align) is present. Maybe that is also the right fix for SIMD types? Or maybe those can have their alignment overridden in Layout without causing havoc in the rest of the compiler?

What exactly is "causing havoc in the rest of the compiler"? The code that I am adjusting is the layout code.

@workingjubilee
Copy link
Member Author

workingjubilee commented Feb 19, 2025

Ah, I see what I missed now, GitHub's UI improvements are "even better" when high latency is involved!

@RalfJung
Copy link
Member

Yeah sorry I was referring to the issues mentioned here.

@workingjubilee
Copy link
Member Author

will revise accordingly

@rustbot author

@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 Feb 19, 2025
@workingjubilee workingjubilee force-pushed the untangle-vector-abi-assumptions branch from 3a5fe77 to a96ec2a Compare February 19, 2025 23:14
@workingjubilee
Copy link
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 Feb 19, 2025
@workingjubilee
Copy link
Member Author

Will conflict with #136985 so should not be put in the queue yet but is otherwise ready for review

@rust-log-analyzer

This comment has been minimized.

@workingjubilee workingjubilee force-pushed the untangle-vector-abi-assumptions branch from a96ec2a to efb89c9 Compare February 19, 2025 23:24
@rust-log-analyzer

This comment has been minimized.

@workingjubilee workingjubilee force-pushed the untangle-vector-abi-assumptions branch from efb89c9 to 1f1bd7c Compare February 20, 2025 02:33
@workingjubilee workingjubilee force-pushed the untangle-vector-abi-assumptions branch from b611749 to f964368 Compare February 20, 2025 18:36
@workingjubilee
Copy link
Member Author

@bors r=bjorn3,RalfJung

@bors
Copy link
Contributor

bors commented Feb 20, 2025

📌 Commit f964368 has been approved by bjorn3,RalfJung

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 20, 2025
@workingjubilee
Copy link
Member Author

I swear I have incorporated that diff like five times.

@workingjubilee workingjubilee force-pushed the untangle-vector-abi-assumptions branch from f964368 to 7173d84 Compare February 20, 2025 20:11
@rustbot
Copy link
Collaborator

rustbot commented Feb 20, 2025

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

This PR changes Stable MIR

cc @oli-obk, @celinval, @ouz-a

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

Some changes occurred to the CTFE machinery

cc @rust-lang/wg-const-eval

@workingjubilee
Copy link
Member Author

huh, unexpected. 🫠

oh well, rebased on #136985 since it will break this anyways

This pair of fn was introduced to perform invariant checks for scalars.
Their current behavior doesn't mesh as well with checking SIMD types,
so change the name of the fn to reflect their actual use-case and
refactor the corresponding checks.

Also simplify the returns from Option<AbiAndPrefAlign> to Option<Align>,
because every site was mapping away the "preferred" alignment anyways.
Introduce a pair of functions that actually describe what they do,
because it wasn't clear the alignment is sometimes a forgery.
@workingjubilee workingjubilee force-pushed the untangle-vector-abi-assumptions branch from 7173d84 to 46f7a7d Compare February 21, 2025 03:55
@workingjubilee
Copy link
Member Author

@bors r=bjorn3,RalfJung

@bors
Copy link
Contributor

bors commented Feb 21, 2025

📌 Commit 46f7a7d has been approved by bjorn3,RalfJung

It is now in the queue for this repository.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 22, 2025
…-assumptions, r=bjorn3,RalfJung

compiler: untangle SIMD alignment assumptions

There were a number of puzzling assumptions being made about SIMD types and their layout that I have corrected in this diff. These are mostly no-op edits in actual fact, but they do subtly alter a pair of checks in our invariant-checking and union layout computation that rested on those peculiar assumptions. Those unfortunately stand in the way of any further actual fixes. I submit this for review, even though it's not clearly motivated without its followups, because it should still be possible to independently conclude whether this is correct.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 22, 2025
…-assumptions, r=bjorn3,RalfJung

compiler: untangle SIMD alignment assumptions

There were a number of puzzling assumptions being made about SIMD types and their layout that I have corrected in this diff. These are mostly no-op edits in actual fact, but they do subtly alter a pair of checks in our invariant-checking and union layout computation that rested on those peculiar assumptions. Those unfortunately stand in the way of any further actual fixes. I submit this for review, even though it's not clearly motivated without its followups, because it should still be possible to independently conclude whether this is correct.
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 22, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#135501 (Inject `compiler_builtins` during postprocessing and ensure it is made private)
 - rust-lang#136543 (intrinsics: unify rint, roundeven, nearbyint in a single round_ties_even intrinsic)
 - rust-lang#137121 (stabilize `(const_)ptr_sub_ptr`)
 - rust-lang#137180 (Give `global_asm` a fake body to store typeck results, represent `sym fn` as a hir expr to fix `sym fn` operands with lifetimes)
 - rust-lang#137256 (compiler: untangle SIMD alignment assumptions)
 - rust-lang#137298 (Check signature WF when lowering MIR body)
 - rust-lang#137415 (Remove invalid suggestion of into_iter for extern macro)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 22, 2025
…-assumptions, r=bjorn3,RalfJung

compiler: untangle SIMD alignment assumptions

There were a number of puzzling assumptions being made about SIMD types and their layout that I have corrected in this diff. These are mostly no-op edits in actual fact, but they do subtly alter a pair of checks in our invariant-checking and union layout computation that rested on those peculiar assumptions. Those unfortunately stand in the way of any further actual fixes. I submit this for review, even though it's not clearly motivated without its followups, because it should still be possible to independently conclude whether this is correct.
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 22, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#135501 (Inject `compiler_builtins` during postprocessing and ensure it is made private)
 - rust-lang#136543 (intrinsics: unify rint, roundeven, nearbyint in a single round_ties_even intrinsic)
 - rust-lang#137121 (stabilize `(const_)ptr_sub_ptr`)
 - rust-lang#137180 (Give `global_asm` a fake body to store typeck results, represent `sym fn` as a hir expr to fix `sym fn` operands with lifetimes)
 - rust-lang#137256 (compiler: untangle SIMD alignment assumptions)
 - rust-lang#137383 (stabilize `unsigned_is_multiple_of`)
 - rust-lang#137415 (Remove invalid suggestion of into_iter for extern macro)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 23, 2025
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#135501 (Inject `compiler_builtins` during postprocessing and ensure it is made private)
 - rust-lang#137121 (stabilize `(const_)ptr_sub_ptr`)
 - rust-lang#137180 (Give `global_asm` a fake body to store typeck results, represent `sym fn` as a hir expr to fix `sym fn` operands with lifetimes)
 - rust-lang#137256 (compiler: untangle SIMD alignment assumptions)
 - rust-lang#137383 (stabilize `unsigned_is_multiple_of`)
 - rust-lang#137415 (Remove invalid suggestion of into_iter for extern macro)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 86008ea into rust-lang:master Feb 23, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Feb 23, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 23, 2025
Rollup merge of rust-lang#137256 - workingjubilee:untangle-vector-abi-assumptions, r=bjorn3,RalfJung

compiler: untangle SIMD alignment assumptions

There were a number of puzzling assumptions being made about SIMD types and their layout that I have corrected in this diff. These are mostly no-op edits in actual fact, but they do subtly alter a pair of checks in our invariant-checking and union layout computation that rested on those peculiar assumptions. Those unfortunately stand in the way of any further actual fixes. I submit this for review, even though it's not clearly motivated without its followups, because it should still be possible to independently conclude whether this is correct.
@workingjubilee workingjubilee deleted the untangle-vector-abi-assumptions branch March 5, 2025 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

7 participants