Skip to content

Let rvalue_creates_operand return true for *all* Rvalue::Aggregates #143502

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

scottmcm
Copy link
Member

@scottmcm scottmcm commented Jul 5, 2025

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.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 5, 2025
@scottmcm
Copy link
Member Author

scottmcm commented Jul 5, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 5, 2025
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.
@bors
Copy link
Collaborator

bors commented Jul 5, 2025

⌛ Trying commit 1d74a5a with merge 3b510de...

@rust-log-analyzer

This comment has been minimized.

Immediate(Either<V, abi::Scalar>),
Pair(Either<V, abi::Scalar>, Either<V, abi::Scalar>),
/// SIMD vectors need special handling because they're the only case where
/// a type with a (non-ZST) `Memory`-ABI field can be `Scalar`-ABI.
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this comment... BackendRepr::Memory and BackendRepr::SimdVector are mutually exclusive, how can a type be both?

"ABI" is such an overused term, it may be good to use some more precise term here if there is one.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree it's weird for a SimdVector to have Memory fields, but that's what repr(simd) does :P

Hopefully the new comment is clearer.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I missed the fact that "field" is the key term here. :)

Yeah that is kind of odd... might be worth changing? Haven't you been working on entirely forbidding field projections for SIMD vectors?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah (rust-lang/compiler-team#838), but technically that's just about projections and there's no ProjectionElem involved here, just the Rvalue::Aggregate.

We've talked about potentially requiring transmutes to introduce them too, not just for consuming them, but it's not a thing yet.

Copy link
Member Author

@scottmcm scottmcm Jul 6, 2025

Choose a reason for hiding this comment

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

TBH if just letting it be supported only takes the couple of lines here (https://github.com/rust-lang/rust/pull/143502/files#diff-013fea668c72159276fa60d94808141397bb0ec0f53f93c79c91335cbcda135eR681-R688) then I probably wouldn't MCP banning it. The big reason that projections are annoying is things like borrowing them or setting sub-fields (like _2.0[3] = _4; when _2 is repr(simd)), but just the Aggregate doesn't have those problems.

Copy link
Member

Choose a reason for hiding this comment

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

Oh this is just for constructors? I see.

I didn't dig into the code, will trust you on there not being obvious improvements here. :)

@bors
Copy link
Collaborator

bors commented Jul 5, 2025

☀️ Try build successful - checks-actions
Build commit: 3b510de (3b510de7904a3e17643c1f7f93a5275f42f94ee6)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (3b510de): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (secondary -1.4%)

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.3% [2.3%, 2.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.2% [-5.2%, -5.2%] 1
All ❌✅ (primary) - - 0

Cycles

Results (secondary 3.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)
3.1% [3.1%, 3.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 461.008s -> 459.649s (-0.29%)
Artifact size: 372.14 MiB -> 372.16 MiB (0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 6, 2025
@scottmcm scottmcm marked this pull request as ready for review July 6, 2025 02:57
@rustbot
Copy link
Collaborator

rustbot commented Jul 6, 2025

r? @oli-obk

rustbot has assigned @oli-obk.
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 the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 6, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 6, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

Inspired by <rust-lang#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.
bors added a commit that referenced this pull request Jul 6, 2025
Don't require `alloca`s for consuming simple enums

Well, 4 months later I'm finally back to this.

Will stay as Draft until #143502 lands, since this builds on that.

For example, if you pass an `Option<u32>` to a function, don't immediately write it to an `alloca` then read it again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants