Allow enum
and union
literals to also create SSA values by scottmcm · Pull Request #138759 · rust-lang/rust (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation18 Commits4 Checks6 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
Today, Some(x)
always goes through an alloca
, even in trivial cases where the niching means the constructor doesn't even change the value.
For example, https://rust.godbolt.org/z/6KG6PqoYz
pub fn demo(r: &i32) -> Option<&i32> { Some(r) }
currently emits the IR
define align 4 ptr @demo(ptr align 4 %r) unnamed_addr { start: %_0 = alloca [8 x i8], align 8 store ptr %r, ptr %_0, align 8 %0 = load ptr, ptr %_0, align 8 ret ptr %0 }
but with this PR it becomes just
define align 4 ptr @demo(ptr align 4 %r) unnamed_addr { start: ret ptr %r }
(Of course the optimizer can clean that up, but it'd be nice if it didn't have to -- especially in debug where it doesn't run. This is like #123886, but that only handled non-simd struct
s -- this PR generalizes it to all non-simd ADTs.)
The commits:
- The first is simplifying how the aggregate handling works. Past-me wrote something overly complicated, needing arrayvecs and zipping, depending on a careful iteration order of the fields, and fragile enough that even for just structs it needed extra double-checks to make sure it even made the right variant. It's replaced with something far more direct that works just like
extract_field
: use the offset to put it in exactly the correct immediate in theOperandValue
. This doesn't support anything new, just refactors -- including moving some things offFunctionCx
that had no reason to be there. (I have no idea why my past self put them there.) - The second extends that work to support more ADTs. That means handing variants other than
FIRST_VARIANT
, handling the active field for unions, refactoring the discriminant code so the Place and Operand parts can share the calculation, etc. - Apparently I can't just remove a dep without updating the lock file, oops.
- I got annoyed at
tag_field
beingusize
, so changed it toFieldIdx
No need to build ArrayVec
s; just put everything exactly where it goes.
r? @Nadrieril
rustbot has assigned @Nadrieril.
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 added S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
Some changes occurred in compiler/rustc_codegen_ssa
This comment has been minimized.
These commits modify the Cargo.lock
file. Unintentional changes to Cargo.lock
can be introduced when switching branches and rebasing PRs.
If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.
This comment has been minimized.
bors added a commit to rust-lang-ci/rust that referenced this pull request
Allow enum
and union
literals to also create SSA values
Today, Some(x)
always goes through an alloca
, even in trivial cases where the niching means the constructor doesn't even change the value.
For example, <https://rust.godbolt.org/z/6KG6PqoYz>
pub fn demo(r: &i32) -> Option<&i32> {
Some(r)
}
currently emits the IR
define align 4 ptr `@demo(ptr` align 4 %r) unnamed_addr {
start:
%_0 = alloca [8 x i8], align 8
store ptr %r, ptr %_0, align 8
%0 = load ptr, ptr %_0, align 8
ret ptr %0
}
but with this PR it becomes just
define align 4 ptr `@demo(ptr` align 4 %r) unnamed_addr {
start:
ret ptr %r
}
(Of course the optimizer can clean that up, but it'd be nice if it didn't have to -- especially in debug where it doesn't run. This is like rust-lang#123886, but that only handled non-simd struct
s -- this PR generalizes it to all non-simd ADTs.)
There's two commits you can review independently:
- The first is simplifying how the aggregate handling works. Past-me wrote something overly complicated, needing arrayvecs and zipping, depending on a careful iteration order of the fields, and fragile enough that even for just structs it needed extra double-checks to make sure it even made the right variant. It's replaced with something far more direct that works just like
extract_field
: use the offset to put it in exactly the correct immediate in theOperandValue
. This doesn't support anything new, just refactors -- including moving some things offFunctionCx
that had no reason to be there. (I have no idea why my past self put them there.) - The second extends that work to support more ADTs. That means handing variants other than
FIRST_VARIANT
, handling the active field for unions, refactoring the discriminant code so the Place and Operand parts can share the calculation, etc.
☀️ Try build successful - checks-actions
Build commit: 875f416 (875f416b9aa583f09153eac5b56d36fcd932b274
)
This comment has been minimized.
Finished benchmarking commit (875f416): comparison URL.
Overall result: ❌✅ regressions and improvements - please read the text below
Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.
Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged
along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.
@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression
Instruction count
This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
mean | range | count | |
---|---|---|---|
Regressions ❌ (primary) | 0.0% | [0.0%, 0.0%] | 1 |
Regressions ❌ (secondary) | 0.2% | [0.2%, 0.3%] | 3 |
Improvements ✅ (primary) | -0.3% | [-0.5%, -0.2%] | 7 |
Improvements ✅ (secondary) | -0.3% | [-0.4%, -0.3%] | 2 |
All ❌✅ (primary) | -0.3% | [-0.5%, 0.0%] | 8 |
Max RSS (memory usage)
Results (primary -2.3%)
This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
mean | range | count | |
---|---|---|---|
Regressions ❌ (primary) | - | - | 0 |
Regressions ❌ (secondary) | - | - | 0 |
Improvements ✅ (primary) | -2.3% | [-2.3%, -2.3%] | 1 |
Improvements ✅ (secondary) | - | - | 0 |
All ❌✅ (primary) | -2.3% | [-2.3%, -2.3%] | 1 |
Cycles
Results (secondary -2.1%)
This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
mean | range | count | |
---|---|---|---|
Regressions ❌ (primary) | - | - | 0 |
Regressions ❌ (secondary) | - | - | 0 |
Improvements ✅ (primary) | - | - | 0 |
Improvements ✅ (secondary) | -2.1% | [-2.3%, -1.6%] | 8 |
All ❌✅ (primary) | - | - | 0 |
Binary size
Results (primary -0.1%, secondary -0.1%)
This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
mean | range | count | |
---|---|---|---|
Regressions ❌ (primary) | - | - | 0 |
Regressions ❌ (secondary) | - | - | 0 |
Improvements ✅ (primary) | -0.1% | [-0.2%, -0.0%] | 57 |
Improvements ✅ (secondary) | -0.1% | [-0.3%, -0.0%] | 27 |
All ❌✅ (primary) | -0.1% | [-0.2%, -0.0%] | 57 |
Bootstrap: 775.297s -> 774.424s (-0.11%)
Artifact size: 365.52 MiB -> 365.52 MiB (0.00%)
Some changes occurred to the CTFE machinery
Some changes occurred to the CTFE / Miri interpreter
cc @rust-lang/miri
Some changes occurred in compiler/rustc_codegen_cranelift
cc @bjorn3
This comment has been minimized.
It was already available as a generic parameter anyway, and it's not like we'll ever put a tag in the 5-billionth field.
Ben said I should re-roll this
r? codegen
ah, this is a "tomorrow" PR. poke me if I do not get to it then.