Skip to content

MIR: opt-in normalization of BasicBlock and Local numbering #111813

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

Merged
merged 4 commits into from
May 29, 2023

Conversation

scottmcm
Copy link
Member

This doesn't matter at all for actual codegen, but after spending some time reading pre-codegen MIR, I was wishing I didn't have to jump around so much in reading post-inlining code.

So this add two passes that are off by default for every mir level, but can be enabled (-Zmir-enable-passes=+ReorderBasicBlocks,+ReorderLocals) for humans.

@rustbot
Copy link
Collaborator

rustbot commented May 21, 2023

r? @cjgillot

(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 May 21, 2023
@rustbot
Copy link
Collaborator

rustbot commented May 21, 2023

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rust-log-analyzer

This comment has been minimized.

@@ -4,6 +4,7 @@

// ignore-debug: the debug assertions prevent the inlining we are testing for
// compile-flags: -Zmir-opt-level=2 -Zinline-mir
// compile-flags: -Zmir-enable-passes=+ReorderBasicBlocks,+ReorderLocals
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this flag be passed by default for mir-opt tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ooh, I like it, since it'll only affect tests that are using the PreCodegen MIR, not all the intermediate stuff.

use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor};
use rustc_session::Session;

pub struct ReorderBasicBlocks;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you doc-comment in which order the blocks are ordered?

}
}

pub struct ReorderLocals;
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise.

map: finder.map.invert_bijective_mapping(),
tcx
};
debug_assert_eq!(updater.map[RETURN_PLACE], RETURN_PLACE);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we expand this assertion to arguments too?


impl<'tcx> Visitor<'tcx> for LocalFinder {
fn visit_local(&mut self, l: Local, context: PlaceContext, _location: Location) {
if context.is_use() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why exclude non-uses?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because otherwise StorageLive ends up putting locals much earlier in the list than makes sense to me. I'll comment it (and do the other suggestions).

@rustbot author

@rustbot rustbot 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 May 21, 2023
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels May 21, 2023
@rust-log-analyzer

This comment has been minimized.

scottmcm added 4 commits May 21, 2023 17:48
Since this only affects `PreCodegen MIR, and it would be nice for that to be resilient to permutations of things that don't affect the actual semantic behaviours.
@scottmcm
Copy link
Member Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 22, 2023
@@ -2,12 +2,10 @@ error[E0716]: temporary value dropped while borrowed
--> $DIR/issue-52049.rs:6:10
|
LL | foo(&unpromotable(5u32));
| -----^^^^^^^^^^^^^^^^^^-
| -----^^^^^^^^^^^^^^^^^^-- temporary value is freed at the end of this statement
Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

Copy link
Member Author

@scottmcm scottmcm May 27, 2023

Choose a reason for hiding this comment

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

Because I changed the RPO of

  A
 / \
B   C
 \ /
  D

from A C B D to A B C D, and apparently that changed some error locations.

I can pull that change out, if you'd prefer.

@cjgillot
Copy link
Contributor

Thanks! Those error are placed a bit better now anyway.
@bors r+

@bors
Copy link
Collaborator

bors commented May 28, 2023

📌 Commit d69725d 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
Copy link
Collaborator

bors commented May 28, 2023

⌛ Testing commit d69725d with merge 089677e...

@bors
Copy link
Collaborator

bors commented May 29, 2023

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

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 29, 2023
@bors bors merged commit 089677e into rust-lang:master May 29, 2023
@rustbot rustbot added this to the 1.72.0 milestone May 29, 2023
@scottmcm scottmcm deleted the pretty-mir branch May 29, 2023 00:26
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (089677e): 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.3% [0.3%, 0.3%] 1
Regressions ❌
(secondary)
0.7% [0.3%, 1.2%] 8
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.0% [-1.5%, -0.3%] 7
All ❌✅ (primary) 0.3% [0.3%, 0.3%] 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)
0.1% [0.1%, 0.1%] 1
Regressions ❌
(secondary)
2.3% [2.3%, 2.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [0.1%, 0.1%] 1

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)
-1.9% [-1.9%, -1.9%] 2
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.2% [0.0%, 0.6%] 50
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 6
Improvements ✅
(primary)
-0.0% [-0.0%, -0.0%] 8
Improvements ✅
(secondary)
-0.3% [-1.0%, -0.0%] 9
All ❌✅ (primary) 0.2% [-0.0%, 0.6%] 58

Bootstrap: 646.44s -> 646.979s (0.08%)

@rustbot rustbot added the perf-regression Performance regression. label May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc 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-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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