[PATCH] D114620: [EarlyCSE] Avoid non-deterministic order when traversing DominatorTree

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 26 02:21:46 PST 2021


bjope created this revision.
Herald added subscribers: mgrang, hiraditya.
bjope requested review of this revision.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114620

Files:
  llvm/lib/Transforms/Scalar/EarlyCSE.cpp
  llvm/test/Transforms/EarlyCSE/deterministic-domtree-iteration.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114620.389958.patch
Type: text/x-patch
Size: 9847 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211126/55ff613f/attachment.bin>


More information about the llvm-commits mailing list