This is an archive of the discontinued LLVM Phabricator instance.

Teach ConstantFoldTerminator to preserve DomTree
ClosedPublic

Authored by arsenm on Jan 16 2018, 10:08 AM.

Details

Reviewers
kuhar
Summary

The pass I'm working on only cares about the BranchInst
handling, which I know works. I don't currently have a way
to test the switch handling, so alternatively I could
just assert there is no DomTree to update for now.

Diff Detail

Event Timeline

arsenm created this revision.Jan 16 2018, 10:08 AM
kuhar added inline comments.Jan 16 2018, 10:32 AM
lib/Transforms/Utils/Local.cpp
129

Can Dest1 and Dest2 be the same BB? If so, a check for that would be needed before removing the edge. LLVM IR forms a multigraph, while the DomTree updater API treats it more like a normal graph, and we have to check for multiedges.

205

Same as above: are we sure that this is the only edge from SI->getParent() to DefaultDest?

243

Same as with the other deletions.

arsenm updated this revision to Diff 130003.Jan 16 2018, 11:35 AM

Handle repeated successors correctly. Handle indirectbr, add unit tests.

kuhar accepted this revision.Jan 16 2018, 12:03 PM

LGTM.

I would only add a comment for where you insert and look at .second highlighting the multiedge problem.

This revision is now accepted and ready to land.Jan 16 2018, 12:03 PM
arsenm closed this revision.Jan 17 2018, 8:29 AM

It turns out this was just a waste of my time and this was already implemented differently in r322401. I don't see specific tests for ConstantFoldTerminator in that commit, so I've gone ahead and committed the test portion in r322683