Files
Mehdi Amini 34a1888bea [mlir] Refactor transform.apply_dce into a eliminateTriviallyDeadOps region-utils helper and expose as a Pass (#194041)
Introduce a lightweight, targeted dead-op eliminator that complements
the
existing liveness-based runRegionDCE. The algorithm is O(ops):
step 1 walks each op in reverse program order, erases it outright if
trivially dead, or recurses into nested regions when recursive cleanup
is
enabled; step 2 drives a per-region worklist that only ever holds ops
already verified dead, propagating new deadness by dropping each
operand's
use before re-checking isOpTriviallyDead on the defining op.

Unlike runRegionDCE, this does not touch dead block arguments, dead
successor operands, or dead use-def cycles. Use runRegionDCE when those
are required. An includeNestedRegions parameter lets callers restrict
simplification to the top-level region.

Switch transform.apply_dce to use the new helper, dropping a custom
worklist that had subtle invariants: SetVector dedup, linear search on
every erase, and pre-order walk with skip.

In general it is bad practice to implement complex custom logic in
Transform ops apply methods: this should be an adaptor exposing MLIR
transformations to the transform dialect; non-trivial logic deserves a
public API for reusability and proper layering.

Introduce a TrivialDeadCodeEliminationPass exposed as -trivial-dce. The
pass
removes trivially dead operations and, when removeBlocks is enabled,
unreachable blocks. It does not run liveness analysis and does not
remove
dead use-def cycles. Add recursive and removeBlocks options, both
defaulting
to true, to control whether nested regions are visited and whether
unreachable blocks are erased.

Assisted-by: Claude Code
2026-04-30 08:25:17 +00:00
..