Skip to content

Enable MatchBranchSimplification#112001

Merged
bors merged 1 commit into
rust-lang:masterfrom
saethlin:enable-matchbranchsimplification
May 28, 2023
Merged

Enable MatchBranchSimplification#112001
bors merged 1 commit into
rust-lang:masterfrom
saethlin:enable-matchbranchsimplification

Conversation

@saethlin

@saethlin saethlin commented May 26, 2023

Copy link
Copy Markdown
Member

This pass is one of the small number of benefits from -Zmir-opt-level=3 that has motivated rustc_codegen_cranelift to use it:

if channel == "release" {
rustflags.push_str(" -Zmir-opt-level=3");
}

Cranelift's motivation for this is runtime performance improvements in debug builds. Lifting this pass all the way to -Zmir-opt-level=1 seems to come without significant perf overhead, so that's what I'm suggesting here.

@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 May 26, 2023
@saethlin

Copy link
Copy Markdown
Member 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 May 26, 2023
@bors

bors commented May 26, 2023

Copy link
Copy Markdown
Collaborator

⌛ Trying commit 4a46d791044568189a3087b08ef918f97b4f179d with merge 915cd328c0e78ffd700e8e29dca4916629ebdcef...

@saethlin saethlin added S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. S-waiting-on-perf Status: Waiting on a perf run to be completed. A-mir-opt Area: MIR optimizations and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-perf Status: Waiting on a perf run to be completed. labels May 26, 2023
@rust-log-analyzer

This comment has been minimized.

@bors

bors commented May 26, 2023

Copy link
Copy Markdown
Collaborator

☀️ Try build successful - checks-actions
Build commit: 915cd328c0e78ffd700e8e29dca4916629ebdcef (915cd328c0e78ffd700e8e29dca4916629ebdcef)

1 similar comment
@bors

bors commented May 26, 2023

Copy link
Copy Markdown
Collaborator

☀️ Try build successful - checks-actions
Build commit: 915cd328c0e78ffd700e8e29dca4916629ebdcef (915cd328c0e78ffd700e8e29dca4916629ebdcef)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (915cd328c0e78ffd700e8e29dca4916629ebdcef): 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.9% [0.7%, 1.1%] 7
Regressions ❌
(secondary)
0.4% [0.3%, 0.5%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 1
All ❌✅ (primary) 0.9% [0.7%, 1.1%] 7

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)
3.8% [2.2%, 6.5%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.0% [-0.0%, -0.0%] 1
Improvements ✅
(secondary)
-3.0% [-3.0%, -3.0%] 1
All ❌✅ (primary) 2.9% [-0.0%, 6.5%] 4

Cycles

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

Binary size

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.1% [0.0%, 0.2%] 4
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.1% [-0.2%, -0.0%] 26
Improvements ✅
(secondary)
-0.2% [-0.3%, -0.0%] 4
All ❌✅ (primary) -0.1% [-0.2%, 0.2%] 30

Bootstrap: 643.928s -> 643.82s (-0.02%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels May 26, 2023
@saethlin saethlin force-pushed the enable-matchbranchsimplification branch from 4a46d79 to a770220 Compare May 27, 2023 00:56
@saethlin

Copy link
Copy Markdown
Member 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 May 27, 2023
@bors

bors commented May 27, 2023

Copy link
Copy Markdown
Collaborator

⌛ Trying commit a770220fd1b41a35ddfffa79b328730e4b030302 with merge 31cb4817bc7bb15715807f7109f203feacd9abce...

@bors

bors commented May 27, 2023

Copy link
Copy Markdown
Collaborator

☀️ Try build successful - checks-actions
Build commit: 31cb4817bc7bb15715807f7109f203feacd9abce (31cb4817bc7bb15715807f7109f203feacd9abce)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (31cb4817bc7bb15715807f7109f203feacd9abce): comparison URL.

Overall result: ❌ regressions - no 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.

@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.7% [0.7%, 0.7%] 1
Regressions ❌
(secondary)
0.4% [0.4%, 0.5%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.7% [0.7%, 0.7%] 1

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)
7.1% [7.1%, 7.1%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.0% [-0.0%, -0.0%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.6% [-0.0%, 7.1%] 2

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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.7% [-0.7%, -0.7%] 1
Improvements ✅
(secondary)
-3.3% [-4.2%, -2.3%] 2
All ❌✅ (primary) -0.7% [-0.7%, -0.7%] 1

Binary size

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.1% [0.0%, 0.2%] 4
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.1% [-0.2%, -0.0%] 26
Improvements ✅
(secondary)
-0.2% [-0.3%, -0.0%] 4
All ❌✅ (primary) -0.1% [-0.2%, 0.2%] 30

Bootstrap: 644.897s -> 644.188s (-0.11%)

@rustbot rustbot removed S-waiting-on-perf Status: Waiting on a perf run to be completed. perf-regression Performance regression. labels May 27, 2023
@saethlin saethlin added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. labels May 27, 2023
@saethlin saethlin marked this pull request as ready for review May 27, 2023 04:05
@rustbot

rustbot commented May 27, 2023

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@cjgillot

Copy link
Copy Markdown
Contributor

Re-reading the pass, I found a possible bug. We do not check that bb_idx != first nor bb_idx != second, only that first != second. This will ICE at.
https://github.com/rust-lang/rust/blob/a770220fd1b41a35ddfffa79b328730e4b030302/compiler/rustc_mir_transform/src/match_branches.rs#L115

For instance: https://godbolt.org/z/dba95Y84P

Perf reports a slight improvement.
r=me with that bug fixed and a test.

@saethlin saethlin force-pushed the enable-matchbranchsimplification branch from a770220 to 7e04c93 Compare May 27, 2023 17:50
@cjgillot

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented May 28, 2023

Copy link
Copy Markdown
Collaborator

📌 Commit 7e04c93 has been approved by cjgillot

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 May 28, 2023
@bors

bors commented May 28, 2023

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 7e04c93 with merge f59d577...

@bors

bors commented May 28, 2023

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing f59d577 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 28, 2023
@bors bors merged commit f59d577 into rust-lang:master May 28, 2023
@rustbot rustbot added this to the 1.72.0 milestone May 28, 2023
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (f59d577): 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.3%, 0.7%] 5
Regressions ❌
(secondary)
0.6% [0.2%, 0.8%] 10
Improvements ✅
(primary)
-0.3% [-0.4%, -0.2%] 4
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.3%] 1
All ❌✅ (primary) 0.2% [-0.4%, 0.7%] 9

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)
6.3% [6.3%, 6.3%] 1
Regressions ❌
(secondary)
2.6% [2.6%, 2.6%] 1
Improvements ✅
(primary)
-0.0% [-0.0%, -0.0%] 1
Improvements ✅
(secondary)
-1.7% [-1.7%, -1.7%] 1
All ❌✅ (primary) 3.2% [-0.0%, 6.3%] 2

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
Regressions ❌
(secondary)
3.2% [3.2%, 3.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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.1% [0.0%, 0.2%] 4
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.1% [-0.2%, -0.0%] 26
Improvements ✅
(secondary)
-0.2% [-0.3%, -0.0%] 4
All ❌✅ (primary) -0.1% [-0.2%, 0.2%] 30

Bootstrap: 644.831s -> 647.057s (0.35%)

@rustbot rustbot added the perf-regression Performance regression. label May 28, 2023
@saethlin

Copy link
Copy Markdown
Member Author

That's definitely not what I expected. I wouldn't have suggested we merge that if I got a perf report like that before merge. I'll try to look into this today?

@saethlin

Copy link
Copy Markdown
Member Author

The codegen for process_obligations has a few surprise movs in it that it didn't before. We also now inline <Rc<ObligationCauseCode> as Drop>::drop.

The perf regression is only in icount, no other metrics look concerning. So I think this is probably fine to leave as-is but I'm going to keep investigating because it seems plausible that this could have moved our generated code a bit in the wrong direction.

@saethlin

Copy link
Copy Markdown
Member Author

There are two call sites for Rc<ObligationCauseCode> as Drop>::drop that show up in a perf-record profile. Only one of them gets inlined with this PR, and I think PGO has more to do with that change than a MIR opt change. So I think investigation here is basically a dead end.

bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 1, 2023
…tmcm

Enable ScalarReplacementOfAggregates in optimized builds

Like MatchBranchSimplification, this pass is known to produce significant runtime improvements in Cranelift artifacts, and I believe based on the perf runs here that the primary effect of this pass is to empower MatchBranchSimplification. ScalarReplacementOfAggregates on its own has little effect on anything, but when this was rebased up to include rust-lang#112001 we started seeing significant and majority-positive results.

Based on the fact that we see most of the regressions in debug builds (rust-lang#112002 (comment)) and some rather significant ones in cycles and wall time, I'm only enabling this in optimized builds at the moment.
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Jun 2, 2023
Enable ScalarReplacementOfAggregates in optimized builds

Like MatchBranchSimplification, this pass is known to produce significant runtime improvements in Cranelift artifacts, and I believe based on the perf runs here that the primary effect of this pass is to empower MatchBranchSimplification. ScalarReplacementOfAggregates on its own has little effect on anything, but when this was rebased up to include rust-lang/rust#112001 we started seeing significant and majority-positive results.

Based on the fact that we see most of the regressions in debug builds (rust-lang/rust#112002 (comment)) and some rather significant ones in cycles and wall time, I'm only enabling this in optimized builds at the moment.
@saethlin saethlin deleted the enable-matchbranchsimplification branch June 14, 2023 21:33
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this pull request Apr 20, 2024
Enable ScalarReplacementOfAggregates in optimized builds

Like MatchBranchSimplification, this pass is known to produce significant runtime improvements in Cranelift artifacts, and I believe based on the perf runs here that the primary effect of this pass is to empower MatchBranchSimplification. ScalarReplacementOfAggregates on its own has little effect on anything, but when this was rebased up to include rust-lang/rust#112001 we started seeing significant and majority-positive results.

Based on the fact that we see most of the regressions in debug builds (rust-lang/rust#112002 (comment)) and some rather significant ones in cycles and wall time, I'm only enabling this in optimized builds at the moment.
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this pull request Apr 27, 2024
Enable ScalarReplacementOfAggregates in optimized builds

Like MatchBranchSimplification, this pass is known to produce significant runtime improvements in Cranelift artifacts, and I believe based on the perf runs here that the primary effect of this pass is to empower MatchBranchSimplification. ScalarReplacementOfAggregates on its own has little effect on anything, but when this was rebased up to include rust-lang/rust#112001 we started seeing significant and majority-positive results.

Based on the fact that we see most of the regressions in debug builds (rust-lang/rust#112002 (comment)) and some rather significant ones in cycles and wall time, I'm only enabling this in optimized builds at the moment.
Kobzol pushed a commit to Kobzol/portable-simd that referenced this pull request Feb 3, 2026
Enable ScalarReplacementOfAggregates in optimized builds

Like MatchBranchSimplification, this pass is known to produce significant runtime improvements in Cranelift artifacts, and I believe based on the perf runs here that the primary effect of this pass is to empower MatchBranchSimplification. ScalarReplacementOfAggregates on its own has little effect on anything, but when this was rebased up to include rust-lang/rust#112001 we started seeing significant and majority-positive results.

Based on the fact that we see most of the regressions in debug builds (rust-lang/rust#112002 (comment)) and some rather significant ones in cycles and wall time, I'm only enabling this in optimized builds at the moment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-mir-opt Area: MIR optimizations merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. 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.

6 participants