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.
clang-format not found in user’s local PATH; not linting file.