Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upadd a wrapper around Mir with an exit node, dominators returns error when nodes are unreachable #34556
Conversation
scottcarr
added some commits
Jun 27, 2016
rust-highfive
assigned
Aatch
Jun 29, 2016
This comment has been minimized.
This comment has been minimized.
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Aatch (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. |
This comment has been minimized.
This comment has been minimized.
rust-highfive
assigned
nikomatsakis
and unassigned
Aatch
Jun 29, 2016
scottcarr
added some commits
Jun 29, 2016
This comment has been minimized.
This comment has been minimized.
|
What is the motivation for postdoms here? LLVM seems to use them only for its region analysis. BTW, this does not handle loops without an exit. |
This comment has been minimized.
This comment has been minimized.
For the "move up propagation" optimization I'm working on (which eliminates a temporary), it only fires if this particular use post dominates the temporary's definition.
The way I was thinking to handle it is: If the Mir CFG has loops without an exit, then there is no "the exit node" and the post-dominators are undefined. When we calculate the dominators of the transposed MirWithExit CFG (which are the post-dominators of the original Mir CFG), that graph will have unreachable nodes and dominators returns an error in that case. |
scottcarr
added some commits
Jun 29, 2016
This comment has been minimized.
This comment has been minimized.
|
Use post-dominates definition? That means it won't work if there are panics in the middle, right? |
This comment has been minimized.
This comment has been minimized.
I'm not sure 100% sure what you're asking. For some variable v, I want to know if some particular use (ex: x = ... v ..) post dominates some definition of v (ex: v = ...).
Dominators::dominators doesn't panic when it encounters unreachable nodes, it returns an Result. Callers should check the result if the graph might have unreachable nodes. Mir's CFG shouldn't have unreachable nodes, AFAIK, but I can change Mir::dominators to return the Result if needed. |
This comment has been minimized.
This comment has been minimized.
|
The problem is that if you consider panic edges, your analysis will be reduced to be basically local, as every call has a panic edge which means that nothing post-dominates anything. |
This comment has been minimized.
This comment has been minimized.
|
Let me make sure I understand what you mean. If we have:
You are suggesting we should optimize to:
.. because "tmp3 = tmp0" is on all paths from "tmp0 = 5" to some "exit" that do not end in a |
This comment has been minimized.
This comment has been minimized.
|
FWIW, move up optimization does fire a non-zero number of times when building the compiler. But it may be that all the statement pairs it optimizes are pretty local to each other. |
This comment has been minimized.
This comment has been minimized.
|
So I chatted a bit with @scottcarr on IRC. I don't think that panic edges are actually particularly relevant. I think that what it comes down to is that if you are going to move the write B0: {
TMP = ... // Point A
...
}
Bn: {
X = TMP // Point B
...
}then basically anything reachable from A without passing through B must not be able to observe the fact that In other words, I think @arielb1 is right that it might be better not to consider post-doms, but I think the focus on panics etc isn't that important. |
This comment has been minimized.
This comment has been minimized.
|
(To be clear, I didn't read all the comments on this PR in depth.) |
This comment has been minimized.
This comment has been minimized.
|
I think we got this discussion totally wrong anyway. Here's my model of the optimization: The optimization is to transform
to
I think this is best split into 4 steps. I don't think we ever want to do the steps separately, but this clarifies the analysis rules. Step 0 (original)
Step 1 - add additional dead write
This requires that Step 2: common subexpression introduction
This requires that the newly-added read links with the write of This also requires that the address of Step 3: remove write-of-read
After step 2, Step 4: remove
|
This comment has been minimized.
This comment has been minimized.
|
Since we're not planning to use post dominators for move-up-propagation, should be close this PR and move discussion to #34693? |
This comment has been minimized.
This comment has been minimized.
|
@scottcarr I think we should. |
scottcarr commentedJun 29, 2016
We want the Mir CFG to have an exit node to calculate post dominators. The MirWithExit type allows us to add the exit node on demand.
When nodes are unreachable from the start node, dominators are undefined, so dominators now returns an error in that case.