-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Conversation
r? @cjgillot (rustbot has picked a reviewer for you, use r? to override) |
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
This comment has been minimized.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why exclude non-uses?
There was a problem hiding this comment.
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
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
@rustbot ready |
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
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.
Thanks! Those error are placed a bit better now anyway. |
☀️ Test successful - checks-actions |
Finished benchmarking commit (089677e): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesResultsThis 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.
Binary sizeResultsThis 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.
Bootstrap: 646.44s -> 646.979s (0.08%) |
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.