[PATCH] D31843: [LCSSA] Try to not walk the dominator tree more than necessary

Michael Zolotukhin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 10 12:59:09 PDT 2017


mzolotukhin added a comment.

> This is precisely equivalent to the stack algorithm i outlined.

I didn't refresh the page before posting, sorry :)

Regarding your description: why do we need to sort exits and then check if the current block dominates an exit/other blocks from the set? Don't we get that for free just from the way we're building the set? I.e. we started from the set of exiting blocks - they all dominate at least one exit by definition. We put them to worklist/stack. We pop a block from the worklist, and if it's not the loop header, we add its immediate dominator to the worklist. By construction and from transitiveness of dominance property, the added block also dominates at least one exit. We continue until the worklist isn't empty. The algorithm is guaranteed to finish if the loop is well-formed (i.e. has one entry, which is the loop header).

All the blocks that we ever added to the worklist are the blocks that dominate at least one exit and the expensive check is replaced with a lookup in this set.

Sorry if it's again the same algorithm as you suggested - but at least we'll figure that out :)

Michael


https://reviews.llvm.org/D31843





More information about the llvm-commits mailing list