This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Support use-def cycles in graph regions during regionDCE
ClosedPublic

Authored by youngar on Mar 18 2021, 9:18 PM.

Details

Summary

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.

Diff Detail

Event Timeline

youngar created this revision.Mar 18 2021, 9:18 PM
youngar requested review of this revision.Mar 18 2021, 9:18 PM

I realize I am stepping on some toes with this patch, sorry about that! This problem is currently resulting in memory corruptions in CIRCT: https://github.com/llvm/circt/issues/775

mehdi_amini accepted this revision.Mar 18 2021, 9:42 PM
This revision is now accepted and ready to land.Mar 18 2021, 9:42 PM
rriddle accepted this revision.Mar 18 2021, 9:47 PM

No worries about stepping on toes! Fixing bugs takes priority!