This is an archive of the discontinued LLVM Phabricator instance.

[EarlyCSE] Avoid non-deterministic order when traversing DominatorTree
AbandonedPublic

Authored by bjope on Nov 26 2021, 2:21 AM.

Details

Reviewers
None
Summary

When processing nodes the DominatorTree is traversed in depth-first
order. However, the order in which a DomTreeNode child iterator will
identify nodes depends on the history of DominatorTree updates that
resulted in a given DominatorTree. And since for quite some time
passes have been prepared DomTreeUpdater lists in random order, the
DominatorTree isn't always the same in the beginning of the EarlyCSE
pass (not even for a fixed input and a fixed clang/opt binary).

The idea behind this patch is to always recalculate the DominatorTree
from scratch in the beginning of EarlyCSE. This should give a
deterministic order of child nodes inside the DominatorTree, as long
as the recalculate function is deterministic (which I think it is).

There is ofcourse a cost of doing a full recalculation. Alternatives
being discussed in
https://lists.llvm.org/pipermail/llvm-dev/2021-September/152839.html
was to either make sure all other passes update DominatorTree:s in a
deterministic fashion, or do some kind of sorting of children when
doing the depth-first search in EarlyCSE. I'm not sure what it would
cost to do the latter solution, but given the comments describing the
reason for using deque:s and StackNode:s when doing the depth-first
walk (not using vectors or similar to keep track of the nodes to
process) it seemed a bit complicated (and probably costly considering
memory consumption) to implement that as well.

Diff Detail

Event Timeline

bjope created this revision.Nov 26 2021, 2:21 AM
bjope requested review of this revision.Nov 26 2021, 2:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 26 2021, 2:21 AM
foad added a subscriber: foad.Nov 26 2021, 2:34 AM
bjope abandoned this revision.Nov 29 2021, 4:27 AM

Abandoned, problem was dealt with in https://reviews.llvm.org/D110292