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

MultipleReturnTerminators + SingleReturnTerminator #106550

Closed
wants to merge 6 commits into from

Conversation

saethlin
Copy link
Member

@saethlin saethlin commented Jan 7, 2023

MultipleReturnTerminators was added with the thinking that we would do better MIR optimizations with that form. But LLVM does better when there is a single return terminator. So adding a new pass which turns back into the single terminator form should give us the best of both worlds.

Locally, it looks like this change just rearranges/renames some things. If this doesn't look like an improvement in perf, I'm going to suggest that we remove MultipleReturnTerminators.

@rustbot
Copy link
Collaborator

rustbot commented Jan 7, 2023

r? @davidtwco

(rustbot has picked a reviewer for you, use r? to override)

@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 7, 2023
@saethlin
Copy link
Member Author

saethlin commented Jan 7, 2023

Ah crap sorry I forgot to ask for review from ghost

@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 7, 2023
@bors
Copy link
Collaborator

bors commented Jan 7, 2023

⌛ Trying commit ca521b0e1fb89c0813cd1d75f1fa8d0112d818c4 with merge ebf0d2d3df7ddf24af902c6cb1401231a299dc2d...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Jan 7, 2023

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ebf0d2d3df7ddf24af902c6cb1401231a299dc2d): 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.5% [0.2%, 1.9%] 6
Regressions ❌
(secondary)
1.1% [1.1%, 1.1%] 1
Improvements ✅
(primary)
-0.7% [-1.0%, -0.2%] 7
Improvements ✅
(secondary)
-0.5% [-0.6%, -0.4%] 4
All ❌✅ (primary) -0.1% [-1.0%, 1.9%] 13

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.4% [0.0%, 10.0%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.6% [-2.6%, -2.6%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 4.1% [-2.6%, 10.0%] 4

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

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jan 7, 2023
@cjgillot
Copy link
Contributor

cjgillot commented Jan 7, 2023

Can the SingleReturnTerminator be done on-the-fly during codegen?
MultipleReturnTerminator can have a secondary effect of shrinking MIR, which makes encoding/decoding faster.
Having SingleReturnTerminator before encoding nullifies this second effect.

@rust-log-analyzer

This comment has been minimized.

@saethlin
Copy link
Member Author

saethlin commented Jan 9, 2023

@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 9, 2023
@bors
Copy link
Collaborator

bors commented Jan 9, 2023

⌛ Trying commit b878a1c88dad18f70c45c3753469a49ce1e1bca6 with merge 0c68d2596c4617e0a308139af6ad56d4ac858bf1...

@bors
Copy link
Collaborator

bors commented Jan 9, 2023

☀️ Try build successful - checks-actions
Build commit: 0c68d2596c4617e0a308139af6ad56d4ac858bf1 (0c68d2596c4617e0a308139af6ad56d4ac858bf1)

1 similar comment
@bors
Copy link
Collaborator

bors commented Jan 9, 2023

☀️ Try build successful - checks-actions
Build commit: 0c68d2596c4617e0a308139af6ad56d4ac858bf1 (0c68d2596c4617e0a308139af6ad56d4ac858bf1)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0c68d2596c4617e0a308139af6ad56d4ac858bf1): 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.3%, 1.0%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.9% [-1.4%, -0.6%] 3
Improvements ✅
(secondary)
-1.3% [-1.4%, -1.1%] 3
All ❌✅ (primary) -0.2% [-1.4%, 1.0%] 6

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.4% [1.7%, 3.1%] 2
Regressions ❌
(secondary)
1.7% [1.7%, 1.7%] 1
Improvements ✅
(primary)
-1.2% [-2.4%, -0.1%] 2
Improvements ✅
(secondary)
-2.7% [-3.0%, -2.4%] 2
All ❌✅ (primary) 0.6% [-2.4%, 3.1%] 4

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)
4.9% [4.5%, 5.3%] 3
Improvements ✅
(primary)
-1.5% [-1.5%, -1.5%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.5% [-1.5%, -1.5%] 1

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (597042ea7995e0681a2e2fbdcbaa41ff8bcd6c3b): 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.3%, 1.1%] 15
Regressions ❌
(secondary)
1.3% [0.2%, 2.5%] 13
Improvements ✅
(primary)
-0.4% [-0.8%, -0.3%] 6
Improvements ✅
(secondary)
-1.0% [-1.4%, -0.4%] 3
All ❌✅ (primary) 0.3% [-0.8%, 1.1%] 21

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.4% [0.2%, 3.9%] 5
Regressions ❌
(secondary)
3.1% [3.1%, 3.1%] 1
Improvements ✅
(primary)
-3.9% [-4.9%, -3.0%] 2
Improvements ✅
(secondary)
-1.6% [-2.2%, -1.3%] 3
All ❌✅ (primary) 0.6% [-4.9%, 3.9%] 7

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

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 12, 2023
MultipleReturnTerminators is maybe good for us but bad for LLVM. So this
enables MultipleReturnTerminators and runs a SingleReturnTerminator pass
at the end of optimizations.
I also noticed that MultipleReturnTerminators doesn't seem to preserve
the SourceInfo quite as well as it could, the tweak to it here might
improve debuginfo.
@saethlin saethlin force-pushed the single-return-terminator branch from 9031375 to b9e06f1 Compare January 13, 2023 00:54
@saethlin
Copy link
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 Jan 13, 2023
@bors
Copy link
Collaborator

bors commented Jan 13, 2023

⌛ Trying commit b9e06f1 with merge cdbe287ec197b4df04fec87680c5779610f69a85...

@bors
Copy link
Collaborator

bors commented Jan 13, 2023

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

@saethlin
Copy link
Member Author

@rust-timer queue

@rust-timer

This comment has been minimized.

@saethlin
Copy link
Member Author

@rust-timer build cdbe287ec197b4df04fec87680c5779610f69a85

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (cdbe287ec197b4df04fec87680c5779610f69a85): 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.8% [0.4%, 1.4%] 6
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.6% [-0.7%, -0.5%] 2
Improvements ✅
(secondary)
-1.4% [-1.4%, -1.4%] 2
All ❌✅ (primary) 0.4% [-0.7%, 1.4%] 8

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.1% [0.2%, 5.5%] 4
Regressions ❌
(secondary)
2.3% [2.3%, 2.3%] 1
Improvements ✅
(primary)
-2.6% [-2.7%, -2.5%] 2
Improvements ✅
(secondary)
-4.6% [-5.0%, -4.3%] 2
All ❌✅ (primary) 1.2% [-2.7%, 5.5%] 6

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

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 13, 2023
@cjgillot cjgillot added the A-mir-opt Area: MIR optimizations label Jan 21, 2023
@Noratrieb Noratrieb added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 24, 2023
@Noratrieb
Copy link
Member

Marking as waiting on author given that it's a draft and has conflicts.

@saethlin
Copy link
Member Author

saethlin commented Apr 2, 2023

The theoretical benefit of this pass is that it could reduce the size of our MIR on disk. But based on the experimentation in this PR, it looks like this pass has a very marginal impact on the amount of MIR we produce. In addition, it looks to me like encoding/decoding MIR isn't a large enough fraction of our compile time to be concerned about marginal tweaks like this.

@saethlin saethlin closed this Apr 2, 2023
@saethlin saethlin deleted the single-return-terminator branch April 2, 2023 19:25
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 perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

8 participants