[all-commits] [llvm/llvm-project] 34a188: [mlir] Refactor transform.apply_dce into a elimina...

Mehdi Amini via All-commits all-commits at lists.llvm.org
Thu Apr 30 01:25:39 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 34a1888bea787d35d1df2daf595222558681cb5b
      https://github.com/llvm/llvm-project/commit/34a1888bea787d35d1df2daf595222558681cb5b
  Author: Mehdi Amini <joker.eph at gmail.com>
  Date:   2026-04-30 (Thu, 30 Apr 2026)

  Changed paths:
    M mlir/include/mlir/Transforms/Passes.h
    M mlir/include/mlir/Transforms/Passes.td
    M mlir/include/mlir/Transforms/RegionUtils.h
    M mlir/lib/Dialect/Transform/IR/TransformOps.cpp
    M mlir/lib/Transforms/CMakeLists.txt
    A mlir/lib/Transforms/TrivialDeadCodeElimination.cpp
    M mlir/lib/Transforms/Utils/RegionUtils.cpp
    A mlir/test/Transforms/dead-code-elimination.mlir

  Log Message:
  -----------
  [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



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list