This is an archive of the discontinued LLVM Phabricator instance.

Do not verify Dominator tree if it has no roots
ClosedPublic

Authored by sepavloff on Jan 16 2017, 3:35 AM.

Details

Summary

If dominator tree has no roots, the pass that calculates it is
likely to be skipped, it occures for instance in the case of
entities with linkage available_externally. Do not run tree
verification in such case.

Event Timeline

sepavloff updated this revision to Diff 84540.Jan 16 2017, 3:35 AM
sepavloff retitled this revision from to Do not verify Dominator tree if it has no roots.
sepavloff updated this object.
sepavloff added a reviewer: mcrosier.
sepavloff added subscribers: llvm-commits, davide.
mcrosier edited edge metadata.Jan 16 2017, 11:04 AM

This seems reasonable to me, but I've added more reviews to see if they have any additional feedback.

IIRC, when I wrote the patch to add the verifyDomTree function here it was taken verbatim from the IR level dominator tree verifier. Therefore, it might be a good idea to make a similar change to the IR-level verifier.

lib/CodeGen/MachineDominators.cpp
147

I'd probably drop this comment in favor of the title of this revision, "Do not verify Dominator tree if it has no root."

sepavloff updated this revision to Diff 85576.Jan 24 2017, 5:50 AM

Added similar check in IR/Dominators.

IIRC, when I wrote the patch to add the verifyDomTree function here it was taken verbatim from the IR level dominator tree verifier. Therefore, it might be a good idea to make a similar change to the IR-level verifier.

This change fixes 11 test fails observer when llvm was build with LLVM_ENABLE_EXPENSIVE_CHECKS turned on. None of them occurs in IR but some time ago there were such fails. So added the respective check.

lib/CodeGen/MachineDominators.cpp
147

Rephrased the comment.

mssimpso edited edge metadata.Jan 24 2017, 7:53 AM

This patch looks good to me, but please let someone else approve.

mcrosier accepted this revision.Jan 24 2017, 9:35 AM

LGTM. It would be nice if we had a test case that covered the IR version as well.

This revision is now accepted and ready to land.Jan 24 2017, 9:35 AM
This revision was automatically updated to reflect the committed changes.

This looks, IMHO, very wrong.
We require domtrees to have roots at all times.
See getRoot, for example, which says:

NodeT *getRoot() const {
  assert(this->Roots.size() == 1 && "Should always have entry node!");
  return this->Roots[0];
}

So if we've created a DominatorTree to call verifyDomTree on,and it doesn't have a root, we have in fact, created a broken dom tree and verification *should* fail.

I'm not sure why we are creating such a tree, but it's *definitely invalid* according to how we work right now.
All this patch does is paper over that by calling getRoots instead of getRoot, because getRoots happens to not assert (we should add a non-emptyness assert there too).

I think you need to fix the underlying problem of creating DominatorTrees without roots, or start a discussion on llvmdev about whether the empty dom tree should be valid.
(Preferably, the former).

Because so far, we've never considered "the completely empty" domtree to be valid, and we haven't audited our functions to make sure they all work properly in such a world.

I very much trust Danny's opinion. Thus, this has been reverted in r293075. I defer Danny's other comments/suggestions (i.e., fixing DT creation w/o roots or starting a discussion on LLVM Dev) to Serge.