Skip to content

[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

Closed
wants to merge 1 commit into from

Conversation

scottcarr
Copy link
Contributor

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

@rust-highfive
Copy link
Contributor

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.

@scottcarr
Copy link
Contributor Author

r? @nikomatsakis

@@ -680,13 +680,13 @@ pub enum AssertMessage<'tcx> {
///////////////////////////////////////////////////////////////////////////
// Statements

#[derive(Clone, RustcEncodable, RustcDecodable)]
#[derive(Clone, RustcEncodable, RustcDecodable, Eq, PartialEq)]
Copy link
Contributor

@arielb1 arielb1 Jul 7, 2016

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.

@arielb1
Copy link
Contributor

arielb1 commented Jul 7, 2016

A move up-propagation can invalidate other move up-propagations. For example, a swap of 2 variables:

tmp0 = x
tmp1 = y
y = tmp0
x = tmp1

Here you can remove either of the temporaries, but not both of them.

This does not actually work out, but I am still not sure MUPs are independent.

Actual example:

start:
    tmp0 = x
    tmp1 = y
    br *, a, b
a:
    ret = tmp0
    goto exit
b:
    ret = tmp1
    goto exit

This can be optimized into either

start:
    ret = x
    tmp1 = y
    br *, a, b
a:
    goto exit
b:
    ret = tmp1
    goto exit

or

start:
    tmp0 = x
    ret = y
    br *, a, b
a:
    ret = tmp0
    goto exit
b:
    goto exit

but not

start:
    ret = x
    ret = y
    br *, a, b
a:
    goto exit
b:
    goto exit

obviously.

};
Ok((def_bb, def_idx))
}
fn get_temps_that_satisfy(&self, mir: &Mir<'a>) -> Vec<Temp> {
Copy link
Contributor

@arielb1 arielb1 Jul 7, 2016

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.

@nikomatsakis
Copy link
Contributor

@arielb1

This does not actually work out, but I am still not sure MUPs are independent.

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?)

@arielb1
Copy link
Contributor

arielb1 commented Jul 7, 2016

@nikomatsakis

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.

@scottcarr scottcarr force-pushed the move-up-propagation3 branch 3 times, most recently from d2b30fa to 2c2d05c Compare July 27, 2016 01:25
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) {
Copy link
Contributor

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.

@bors
Copy link
Collaborator

bors commented Aug 4, 2016

☔ 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] {
Copy link
Member

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)

@scottcarr scottcarr changed the title [WIP][MIR] Implement move up propagation without post dominators [MIR] Implement move up propagation without post dominators Aug 11, 2016
@bors
Copy link
Collaborator

bors commented Sep 18, 2016

☔ The latest upstream changes (presumably #36504) made this pull request unmergeable. Please resolve the merge conflicts.

@nikomatsakis
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants