-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[MIR] Implement move up propagation without post dominators #34693
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
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @arielb1 (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@@ -680,13 +680,13 @@ pub enum AssertMessage<'tcx> { | |||
/////////////////////////////////////////////////////////////////////////// | |||
// Statements | |||
|
|||
#[derive(Clone, RustcEncodable, RustcDecodable)] | |||
#[derive(Clone, RustcEncodable, RustcDecodable, Eq, PartialEq)] |
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? WHY?
I think you are intending to compare locations or something.
This does not actually work out, but I am still not sure MUPs are independent. Actual example:
This can be optimized into either
or
but not
obviously. |
}; | ||
Ok((def_bb, def_idx)) | ||
} | ||
fn get_temps_that_satisfy(&self, mir: &Mir<'a>) -> Vec<Temp> { |
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.
I would prefer to return a Vec<(Temp, Def, Use)>
or something.
BTW, you can use filter_map
or flat_map
instead of .filter
followed by .map
.
I agree they are not necessarily independent -- this is partly why "re-analyzing" the graph for each candidate can be easier (versus trying to do some kind of overall live analysis), since any changes we make will be automatically accounted for. In any case, were you just noting the potential problem, or proposing some kind of smarter, more global way to choose which optimizations to do? (Or were you suggesting that there is a problem where interference could cause the current code to do the wrong thing?) |
The current code is basically local, but a naïve non-local version of it would handle this case incorrectly. In any case, re-analyzing the graph for each candidate could get expensive. LLVM has some crazy heuristics for memdep - might be wise to try and copy them. |
d2b30fa
to
2c2d05c
Compare
let mut opt_counter = 0; | ||
let mut dead_temps = BitVector::new(mir.temp_decls.len()); | ||
let mut dead_vars = BitVector::new(mir.var_decls.len()); | ||
while let Some((tmp, use_bb, use_idx, def_bb, def_idx)) = get_one_optimization(mir) { |
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.
I would like to see more comments here. Ideally, we would explain what the optimization will do, like showing one example of the transformation, and labeling the various parts of it. Then we can have comments that link the code to that transformation.
☔ The latest upstream changes (presumably #35168) made this pull request unmergeable. Please resolve the merge conflicts. |
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
pub fn test(a: &[u64; 8]) -> [u64; 8] { |
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.
This file's name has "slice" in it but these are arrays being copied.
(move_chain
seems more relevant, the type itself doesn't really matter)
343ace3
to
71e589a
Compare
☔ The latest upstream changes (presumably #36504) made this pull request unmergeable. Please resolve the merge conflicts. |
OK, I'm going to close this PR because of inactivity, but I think we probably want to "rejuvenate" this code. @scottcarr if you are still interested in hacking on it, let's talk. |
This is a re-implementation of #34585 to not use post dominators.
Further potential improvements include:
Calculate live variable sets to avoid re-walking the graph for each potential replacement
Somehow cache whether a Call terminator is reachable from a given BasicBlock (to again avoid re-walking the graph)
I'm not sure if we still need the Call terminator restriction with the current precondition (the DEST is never borrowed)
See also: https://internals.rust-lang.org/t/mir-move-up-propagation/3610