Skip to content

Block SIMD in transmute_immediate; delete OperandValueKind #143410

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

Merged
merged 3 commits into from
Jul 5, 2025

Conversation

scottmcm
Copy link
Member

@scottmcm scottmcm commented Jul 4, 2025

Vectors have been causing me problems for years in this code, for example #110021 (comment) and #143194

See conversation in https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Is.20transmuting.20a.20.60T.60.20to.20.60Tx1.60.20.28one-element.20SIMD.20vector.29.20UB.3F/near/526262799.

By blocking SIMD in transmute_immediate it can be simplified to just take the Scalars involved -- the backend types can be gotten from those Scalars, rather than needing to be passed. And there's an assert added to ICE it if it does get hit.

Accordingly, this changes rvalue_creates_operand to not send SIMD transmutes through the operand path, but to always go through memory instead, like they did back before #108442.

And thanks to those changes, I could also remove the OperandValueKind type that I added back then which @RalfJung rightly considers pretty sketchy.

cc @folkertdev @workingjubilee from the zulip conversation too

@rustbot
Copy link
Collaborator

rustbot commented Jul 4, 2025

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 Jul 4, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 4, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

Comment on lines -300 to -303
let in_a_ibty = bx.scalar_pair_element_backend_type(operand.layout, 0, false);
let in_b_ibty = bx.scalar_pair_element_backend_type(operand.layout, 1, false);
let out_a_ibty = bx.scalar_pair_element_backend_type(cast, 0, false);
let out_b_ibty = bx.scalar_pair_element_backend_type(cast, 1, false);
Copy link
Member Author

Choose a reason for hiding this comment

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

These just disappear entirely because transmute_immediate no longer needs them as arguments 🎉

@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member

RalfJung commented Jul 4, 2025

At this point I am happy with the codegen changes, but I have a hard time interpreting the test changes. Wouldn't mind someone else to take a look at those :)

@scottmcm scottmcm force-pushed the redo-transmute-again branch from 337cb31 to 4e61527 Compare July 4, 2025 19:29
@workingjubilee
Copy link
Member

The test changes seem to be fine.

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 5, 2025

📌 Commit 4e61527 has been approved by workingjubilee

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 Jul 5, 2025
@workingjubilee
Copy link
Member

@bors r=RalfJung,workingjubilee

@bors
Copy link
Collaborator

bors commented Jul 5, 2025

💡 This pull request was already approved, no need to approve it again.

@bors
Copy link
Collaborator

bors commented Jul 5, 2025

📌 Commit 4e61527 has been approved by RalfJung,workingjubilee

It is now in the queue for this repository.

@workingjubilee workingjubilee reopened this Jul 5, 2025
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 5, 2025
bors added a commit that referenced this pull request Jul 5, 2025
Rollup of 11 pull requests

Successful merges:

 - #142440 (`tests/ui`: A New Order [14/N])
 - #143040 (Add `const Rem`)
 - #143086 (Update poison.rs to fix the typo (sys->sync))
 - #143202 (`tests/ui`: A New Order [18/N])
 - #143296 (`tests/ui`: A New Order [21/N])
 - #143297 (`tests/ui`: A New Order [22/N])
 - #143299 (`tests/ui`: A New Order [24/N])
 - #143300 (`tests/ui`: A New Order [25/N])
 - #143397 (test passing a `VaList` from rust to C)
 - #143410 (Block SIMD in transmute_immediate; delete `OperandValueKind`)
 - #143452 (Fix CLI completion check in `tidy`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 33eb552 into rust-lang:master Jul 5, 2025
22 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 5, 2025
@rustbot rustbot added this to the 1.90.0 milestone Jul 5, 2025
rust-timer added a commit that referenced this pull request Jul 5, 2025
Rollup merge of #143410 - scottmcm:redo-transmute-again, r=RalfJung,workingjubilee

Block SIMD in transmute_immediate; delete `OperandValueKind`

Vectors have been causing me problems for years in this code, for example #110021 (comment) and #143194

See conversation in <https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Is.20transmuting.20a.20.60T.60.20to.20.60Tx1.60.20.28one-element.20SIMD.20vector.29.20UB.3F/near/526262799>.

By blocking SIMD in `transmute_immediate` it can be simplified to just take the `Scalar`s involved -- the backend types can be gotten from those `Scalar`s, rather than needing to be passed.  And there's an assert added to ICE it if it does get hit.

Accordingly, this changes `rvalue_creates_operand` to not send SIMD transmutes through the operand path, but to always go through memory instead, like they did back before #108442.

And thanks to those changes, I could also remove the `OperandValueKind` type that I added back then which `@RalfJung` rightly considers pretty sketchy.

cc `@folkertdev` `@workingjubilee` from the zulip conversation too
@scottmcm scottmcm deleted the redo-transmute-again branch July 5, 2025 15:36
bors added a commit that referenced this pull request Jul 5, 2025
Let `rvalue_creates_operand` return true for *all* `Rvalue::Aggregate`s

Draft for now because it's built on Ralf's #143291

Inspired by #138759 (comment) where I noticed that we were nearly at this point, plus the comments I was writing in #143410 that reminded me a type-dependent `true` is fine.

This PR splits the `OperandRef::builder` logic out to a separate type, with the updates needed to handle SIMD as well.  In doing so, that makes the existing `Aggregate` path in `codegen_rvalue_operand` capable of handing SIMD values just fine.

As a result, we no longer need to do layout calculations for aggregate result types when running the analysis to determine which things can be SSA in codegen.
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