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

Switch the BB CFG cache from postorder to RPO #112638

Merged
merged 8 commits into from
Jun 18, 2023
Merged

Switch the BB CFG cache from postorder to RPO #112638

merged 8 commits into from
Jun 18, 2023

Conversation

lqd
Copy link
Member

@lqd lqd commented Jun 14, 2023

The BasicBlocks CFG cache is interesting:

  • it stores a postorder, but traversal::postorder doesn't use it
  • traversal::reverse_postorder does traverse the postorder cache backwards
  • we do more RPO traversals than postorder traversals (around 20x on the perf.rlo benchmarks IIRC) but it's not cached
  • a couple places here and there were manually reversing the non-cached postorder traversal

This PR switches the order of the cache, and makes a bit more use of it. This is a tiny win locally, but it's also for consistency and aesthetics.

r? @ghost

@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 Jun 14, 2023
@lqd
Copy link
Member Author

lqd commented Jun 14, 2023

Sanity check: @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 Jun 14, 2023
@bors
Copy link
Contributor

bors commented Jun 14, 2023

⌛ Trying commit f134101 with merge 7f0a9c6034d4ceaeed051ae99e90c2d96d1a2c5e...

Comment on lines +121 to +122
let rpo = body.basic_blocks.reverse_postorder().to_vec();
for bb in rpo {
Copy link
Member Author

Choose a reason for hiding this comment

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

@tmiasko This is where it could have been cool to avoid this existing allocation, as it's not easy to combine lazy RPO + as_mut_preserves_cfg. Probably not worth it just for this single call-site though, I don't remember seeing this elsewhere.

@bors
Copy link
Contributor

bors commented Jun 15, 2023

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

1 similar comment
@bors
Copy link
Contributor

bors commented Jun 15, 2023

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (7f0a9c6034d4ceaeed051ae99e90c2d96d1a2c5e): comparison URL.

Overall result: ❌ regressions - 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.3% [0.3%, 0.3%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [0.3%, 0.3%] 3

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)
- - 0
Regressions ❌
(secondary)
1.6% [1.6%, 1.6%] 1
Improvements ✅
(primary)
-1.9% [-3.7%, -0.1%] 2
Improvements ✅
(secondary)
-2.0% [-2.0%, -2.0%] 1
All ❌✅ (primary) -1.9% [-3.7%, -0.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)
2.8% [2.8%, 2.8%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.2% [-2.2%, -2.2%] 1
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 649.904s -> 650.513s (0.09%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jun 15, 2023
@lqd
Copy link
Member Author

lqd commented Jun 15, 2023

bitmaps looks currently bimodal on these 0.3% swings

@Noratrieb
Copy link
Member

also see #112288

@lqd
Copy link
Member Author

lqd commented Jun 15, 2023

@Nilstrieb incredible timing :)

To me it looks like there's so few non-cached postorder traversals, that using the cache for them is a wash (all the uses of the postorder cache are the RPO traversals). Now, if we cache anything, at the very least let's cache the ordering we actually use: RPO. (But I saw this when looking to do RPO on the reverse CFG...)

That's a small but noticeable icount win in cg, and I think a cleanup. What do you think ?

Making traversal::postorder use that cache is a tiny (positive) difference in icounts as well, and I added it here for consistency, so that both traversal:: are cached, but it doesn't make a real difference on our benchmakrs, as you also saw yourself (and landing that via your PR would have made sense imho).

Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

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

This is a nice cleanup. We should definitely get this merged.

compiler/rustc_middle/src/mir/traversal.rs Outdated Show resolved Hide resolved
@lqd lqd marked this pull request as ready for review June 18, 2023 09:23
@rustbot
Copy link
Collaborator

rustbot commented Jun 18, 2023

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@lqd
Copy link
Member Author

lqd commented Jun 18, 2023

Probably no need for another perf run.

r? @cjgillot

@cjgillot
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jun 18, 2023

📌 Commit 08a9f25 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 Jun 18, 2023
@bors
Copy link
Contributor

bors commented Jun 18, 2023

⌛ Testing commit 08a9f25 with merge 677710e...

@bors
Copy link
Contributor

bors commented Jun 18, 2023

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

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 18, 2023
@bors bors merged commit 677710e into rust-lang:master Jun 18, 2023
@rustbot rustbot added this to the 1.72.0 milestone Jun 18, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (677710e): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

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

Max RSS (memory usage)

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

Cycles

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

Binary size

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

Bootstrap: 656.258s -> 656.279s (0.00%)

@rustbot rustbot removed the perf-regression Performance regression. label Jun 18, 2023
@lqd lqd deleted the rpo branch June 18, 2023 17:55
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. 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