This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAG] Update the dominator after splitting critical edges
ClosedPublic

Authored by davide on Jun 1 2017, 2:32 PM.

Details

Summary

Running llc -verify-dom-info on the attached testcase results in a crash in the verifier, due to a stale dominator tree.

i.e.

DominatorTree is not up to date!
Computed:
=============================--------------------------------
Inorder Dominator Tree: 
  [1] %safe_mod_func_uint8_t_u_u.exit.i.i.i {0,7}
    [2] %lor.lhs.false.i61.i.i.i {1,2}
    [2] %safe_mod_func_int8_t_s_s.exit.i.i.i {3,6}
      [3] %safe_div_func_int64_t_s_s.exit66.i.i.i {4,5}

Actual:
=============================--------------------------------
Inorder Dominator Tree: 
  [1] %safe_mod_func_uint8_t_u_u.exit.i.i.i {0,9}
    [2] %lor.lhs.false.i61.i.i.i {1,2}
    [2] %safe_mod_func_int8_t_s_s.exit.i.i.i {3,8}
      [3] %safe_div_func_int64_t_s_s.exit66.i.i.i {4,5}
      [3] %safe_mod_func_int8_t_s_s.exit.i.i.i.lor.lhs.false.i61.i.i.i_crit_edge {6,7}

This is because in SelectionDAGIsel we split critical edges without updating the corresponding dominator for the function (and we claim in MachineFunctionPass::getAnalysisUsage() that the domtree is preserved).

We could either stop preserving the domtree in getAnalysisUsage or tell splitCriticalEdge() to update it.
As the second option is easy to implement, that's the one I chose.

Side note: not sure why this went unnoticed for so long.

Diff Detail

Repository
rL LLVM

Event Timeline

davide created this revision.Jun 1 2017, 2:32 PM
efriedma added inline comments.
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
405 ↗(On Diff #101109)

Can you use getAnalysisIfAvailable here?

test/CodeGen/X86/O0-pipeline.ll
35 ↗(On Diff #101109)

This test is specifically here to make sure we don't add unnecessary passes to -O0. This is not progress in the right direction.

davide added inline comments.Jun 1 2017, 2:58 PM
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
405 ↗(On Diff #101109)

I can indeed, updating this patch in a sec.

davide updated this revision to Diff 101120.Jun 1 2017, 3:01 PM

Update after Eli's review.

qcolombet added inline comments.Jun 1 2017, 3:17 PM
test/CodeGen/X86/pr33266.ll
3 ↗(On Diff #101120)

Could you use a more explicit filename and list the PR within the comment here?

davide added inline comments.Jun 1 2017, 3:22 PM
test/CodeGen/X86/pr33266.ll
3 ↗(On Diff #101120)

Done. I used selectiondag-dominator.ll, but if you have other suggestions, I'll be happy to change it.

davide updated this revision to Diff 101125.Jun 1 2017, 3:22 PM

Quentin's comment.

RKSimon added a subscriber: RKSimon.Jun 2 2017, 1:18 AM
This revision is now accepted and ready to land.Jun 5 2017, 11:06 AM
davide added a comment.Jun 5 2017, 3:04 PM

Thank you for the reviews. Submitting in a sec.

This revision was automatically updated to reflect the committed changes.