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

Do not deaggregate MIR #107267

Merged
merged 10 commits into from
Feb 4, 2023
Merged

Do not deaggregate MIR #107267

merged 10 commits into from
Feb 4, 2023

Conversation

cjgillot
Copy link
Contributor

This turns out to simplify a lot of things.
I haven't checked the consequences for miri yet.

cc @JakobDegen
r? @oli-obk

@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 Jan 24, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jan 24, 2023

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

This PR changes MIR

cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras

@cjgillot
Copy link
Contributor Author

@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 Jan 24, 2023
@bors
Copy link
Contributor

bors commented Jan 24, 2023

⌛ Trying commit bf1045f6445947bde254afb44e4f51e59d5ee3cd with merge 1c5362be2bfa0958bd3e3d628499105ba64bcef2...

@bors
Copy link
Contributor

bors commented Jan 24, 2023

☀️ Try build successful - checks-actions
Build commit: 1c5362be2bfa0958bd3e3d628499105ba64bcef2 (1c5362be2bfa0958bd3e3d628499105ba64bcef2)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1c5362be2bfa0958bd3e3d628499105ba64bcef2): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

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 a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.6% [0.4%, 0.9%] 4
Regressions ❌
(secondary)
0.6% [0.3%, 1.5%] 13
Improvements ✅
(primary)
-0.9% [-3.0%, -0.2%] 48
Improvements ✅
(secondary)
-5.9% [-13.4%, -0.3%] 28
All ❌✅ (primary) -0.7% [-3.0%, 0.9%] 52

Max RSS (memory usage)

Results

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)
4.0% [4.0%, 4.0%] 1
Regressions ❌
(secondary)
1.6% [1.6%, 1.6%] 1
Improvements ✅
(primary)
-3.6% [-8.4%, -0.1%] 10
Improvements ✅
(secondary)
-5.9% [-9.6%, -1.4%] 23
All ❌✅ (primary) -2.9% [-8.4%, 4.0%] 11

Cycles

Results

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)
1.7% [1.0%, 2.3%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.0% [-2.3%, -1.3%] 4
Improvements ✅
(secondary)
-7.0% [-10.8%, -4.3%] 27
All ❌✅ (primary) -0.8% [-2.3%, 2.3%] 6

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jan 25, 2023
@rust-log-analyzer

This comment has been minimized.

@oli-obk
Copy link
Contributor

oli-obk commented Jan 25, 2023

I reopened #35259 because there are conflicting desires

  • @eddyb would prefer to go all the way and remove Aggregate from the MIR entirely
    • this avoids having two ways to do the same thing, but needs a marker for when a value is fully constructed
  • @JakobDegen would prefer to do this PR and never deaggregate
    • this is easier on analyses and some optimizations, but now we have two ways to do the same thing (assigning each field separately vs assigning them all at once)

The discussion that caused this PR: https://rust-lang.zulipchat.com/#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Changing.20enum.20variant.20by.20writing.20to.20field

@JakobDegen
Copy link
Contributor

One thing we can do is keep deaggregating structs, but not enums. Then there won't be two ways of doing the same thing, as long as we don't allow SetDiscriminant for enums at all

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 26, 2023
Replace ZST operands and debuginfo by constants.

This is work that ConstProp will not have to do.
Split from rust-lang#107267
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 26, 2023
Replace ZST operands and debuginfo by constants.

This is work that ConstProp will not have to do.
Split from rust-lang#107267
@oli-obk
Copy link
Contributor

oli-obk commented Jan 27, 2023

So... basically the reason deaggregation was enabled for everything but arrays was to work towards named return value optimization. Instead of building all the components and then doing a single aggregate assignment at the end, you can assign to sub-places immediately and even end up with multiple layers of function calls that assign to a place in the outermost call.

I guess we can still do that as part of nrvo when it decides a return value should get that opt run on it.

@rust-log-analyzer

This comment has been minimized.

@JakobDegen
Copy link
Contributor

So... basically the reason deaggregation was enabled for everything but arrays was to work towards named return value optimization. Instead of building all the components and then doing a single aggregate assignment at the end, you can assign to sub-places immediately and even end up with multiple layers of function calls that assign to a place in the outermost call.

Honestly, this is a problem we should fix via SSA (or something similar, not via deaggregation)

@oli-obk
Copy link
Contributor

oli-obk commented Jan 29, 2023

Makes sense. So I guess the only thing left is to give codegen backends the ability to deaggregate so they don't have to implement both aggregate rvalues, field assignments and setdiscriminant unless they want to

@rust-log-analyzer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (9dee4e4): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.5% [0.2%, 1.1%] 51
Regressions ❌
(secondary)
0.8% [0.1%, 2.0%] 30
Improvements ✅
(primary)
-1.4% [-2.6%, -0.3%] 25
Improvements ✅
(secondary)
-6.0% [-12.9%, -0.6%] 27
All ❌✅ (primary) -0.1% [-2.6%, 1.1%] 76

Max RSS (memory usage)

Results

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)
2.6% [2.6%, 2.6%] 1
Regressions ❌
(secondary)
2.3% [1.4%, 2.6%] 5
Improvements ✅
(primary)
-3.9% [-9.5%, -0.1%] 8
Improvements ✅
(secondary)
-6.5% [-9.4%, -2.7%] 21
All ❌✅ (primary) -3.2% [-9.5%, 2.6%] 9

Cycles

Results

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.8% [0.7%, 0.9%] 3
Regressions ❌
(secondary)
2.3% [2.2%, 2.5%] 2
Improvements ✅
(primary)
-1.6% [-2.3%, -1.0%] 8
Improvements ✅
(secondary)
-6.3% [-10.4%, -1.2%] 28
All ❌✅ (primary) -1.0% [-2.3%, 0.9%] 11

@nnethercote
Copy link
Contributor

The wins here outweigh the losses, even if you ignore the handful of very good results among secondary benchmarks that skew the overall results.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Feb 5, 2023
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Feb 6, 2023
Adapt SROA MIR opt for aggregated MIR

The pass was broken by rust-lang#107267.

This PR extends it to replace:
```
x = Struct { 0: a, 1: b }
y = move? x
```

by assignment between locals
```
x_0 = a
x_1 = b
y_0 = move? x_0
y_1 = move? x_1
```

The improved pass runs to fixpoint, so we can flatten nested field accesses.
} else {
(dest, active_field_index)
}
let (variant_index, variant_dest, active_field_index) = match **kind {
Copy link
Member

@bjorn3 bjorn3 Feb 6, 2023

Choose a reason for hiding this comment

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

Cg_clif needs to be updated too. Will do this over at the cg_clif repo.

Edit: done in bjorn3/rustc_codegen_cranelift@8494882

@Manishearth
Copy link
Member

Manishearth commented Feb 8, 2023

This caused a regression: #107678

Should this be reverted? (Or perhaps you can help find the bug)

@saethlin
Copy link
Member

saethlin commented Feb 8, 2023

The fix is #107688, I think this PR just makes the root cause easier to access. I've seen similar-looking ICEs in other crates (associated type vs concrete type) but was never able to minimize them.

If you're curious there should be other examples like the referenced ICE here: #107051

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 16, 2023
Replace ZST operands and debuginfo by constants.

This is work that ConstProp will not have to do.
Split from rust-lang#107267
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this pull request Apr 20, 2024
Replace ZST operands and debuginfo by constants.

This is work that ConstProp will not have to do.
Split from rust-lang/rust#107267
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this pull request Apr 27, 2024
Replace ZST operands and debuginfo by constants.

This is work that ConstProp will not have to do.
Split from rust-lang/rust#107267
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. 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.