This is an archive of the discontinued LLVM Phabricator instance.

[NewGVN] Update dominator tree for unreachable blocks.
AbandonedPublic

Authored by fhahn on Jan 28 2017, 6:36 AM.

Details

Summary

The dominator tree has to be updated after all instructions for an
unreachable block have been removed.

This patch should fix all NewGVN test failures with EXPENSIVE_CHECKS.

Diff Detail

Event Timeline

fhahn created this revision.Jan 28 2017, 6:36 AM
fhahn added inline comments.Jan 28 2017, 6:39 AM
lib/Transforms/Scalar/NewGVN.cpp
1911

Another possibility would be to add a function to recursively erase all nodes dominated by BB. What do you think?

dberlin edited edge metadata.Jan 28 2017, 10:22 AM

Yeah, we discovered this yesterday.

The underlying issue is twofold

  1. changeToUnreachable is supposed to be local, but modifies the CFG :(
  2. You can't insert unreachableinst except as a terminator.

I'm torn here. Chandler's suggestion was to preserve the CFG. That will work, actually, right up until we add PRE.
Then we are going to split critical edges for sure.
(though we definitely miss some optimizations due to not splitting critical edges right now, it's just more common with PRE).

Current GVN does not preserve CFG.
If we want to preserve CFG, we should do a store of undef to null (which simplifycfg will transform into unreachable) and revert the original patch.

NewGVN is also an analysis with an elimination pass tacked on (and built so we can eventually split it up that way). The analysis should not modify the CFG for sure, but it isn't right now, so that's okay.
This is about the elimination part, and whether non-PRE should try to preserve CFG.

Chandler, your thoughts welcome on whether it's worth trying to preserve CFG in the case we don't do PRE

(also, many thanks for tackling this. :P)

Ah

  1. You can't insert unreachableinst except as a terminator.

Ah, I was wondering about that :)

chandlerc edited edge metadata.Jan 28 2017, 12:43 PM

Yeah, we discovered this yesterday.

The underlying issue is twofold

  1. changeToUnreachable is supposed to be local, but modifies the CFG :(
  2. You can't insert unreachableinst except as a terminator.

I'm torn here. Chandler's suggestion was to preserve the CFG. That will work, actually, right up until we add PRE.
Then we are going to split critical edges for sure.
(though we definitely miss some optimizations due to not splitting critical edges right now, it's just more common with PRE).

Current GVN does not preserve CFG.
If we want to preserve CFG, we should do a store of undef to null (which simplifycfg will transform into unreachable) and revert the original patch.

NewGVN is also an analysis with an elimination pass tacked on (and built so we can eventually split it up that way). The analysis should not modify the CFG for sure, but it isn't right now, so that's okay.
This is about the elimination part, and whether non-PRE should try to preserve CFG.

Chandler, your thoughts welcome on whether it's worth trying to preserve CFG in the case we don't do PRE

There is no fundamental reason you should preserve the CFG. The reason I suggest it whenever possible is only because it allows us to cache many more analyses. You can update domtree, but the number of analyses you get to preserve by preserving the CFG goes up *substantially* and you don't want to try to update all of them.

That said,, as long as this is one big pass, as you say, you'll want to split critical edges in part of it, etc. Don't stress about it in that context.

If you're going to split this, I think it is fairly likely that some reduced transformation passes will want to preserve the CFG so they can be relatively non-disruptive to analyses. Some use cases off the top of my head:

  • GVNHoist style code motion seems likely to want to leave analyses in tact
  • I'd love to have a fast, small LoopGVN that could be run in the middle of the loop pipeline to catch incremental improvements that allow subsequent loop passes to be more effective
  • Some of the places we currently use EarlyCSE

Anyways, all of this seems pretty forward-looking, so I don't think it should necessarily decide what you do right now, just something to keep in mind as things progress. If there are easy ways to set the pass up for this long term, might be worthwhile.

fhahn added a comment.Jan 30 2017, 7:30 AM

@davide should I abandon this review now you opened https://llvm.org/bugs/show_bug.cgi?id=31801 ?

davide edited edge metadata.Jan 30 2017, 7:36 AM

@davide should I abandon this review now you opened https://llvm.org/bugs/show_bug.cgi?id=31801 ?

No, I think something like this should go in anyway. PR30801 tracks a more general problem that will require time to be addressed properly.

For now i think we should revert the original change and insert the store, unless someone has evidence that doing something else produces actual performance improvement, instead of just looking nicer

We can always burn this bridge again when we come to it.

fhahn added a comment.Jan 30 2017, 8:55 AM

Sure that sounds like the simpler fix. Go for it.

An alternative version of this was committed, feel free to close whenever you want.

davide resigned from this revision.Feb 7 2017, 11:14 AM
davide added a subscriber: davide.

An alternative version was committed. Resigning so this gets out of my queue.

fhahn abandoned this revision.Feb 8 2017, 3:01 PM

Already fixed.