[mlir] Support use-def cycles in graph regions during regionDCE
authorAndrew Young <youngar17@gmail.com>
Fri, 19 Mar 2021 03:06:02 +0000 (20:06 -0700)
committerAndrew Young <youngar17@gmail.com>
Fri, 19 Mar 2021 06:06:45 +0000 (23:06 -0700)
commitf178c13fa89960c7247a6367269919acf87fd1b3
tree7871cb20006b6794e6f50963bbbf782233c5e354
parent270a336ff46204acf887def32c92ad695f767471
[mlir] Support use-def cycles in graph regions during regionDCE

When deleting operations in DCE, the algorithm uses a post-order walk of
the IR to ensure that value uses were erased before value defs. Graph
regions do not have the same structural invariants as SSA CFG, and this
post order walk could delete value defs before uses.  This problem is
guaranteed to occur when there is a cycle in the use-def graph.

This change stops DCE from visiting the operations and blocks in any
meaningful order.  Instead, we rely on explicitly dropping all uses of a
value before deleting it.

Reviewed By: mehdi_amini, rriddle

Differential Revision: https://reviews.llvm.org/D98919
mlir/lib/Transforms/Utils/RegionUtils.cpp
mlir/test/Transforms/canonicalize-dce.mlir