[Mlir-commits] [mlir] [mlir] Refactor transform.apply_dce into a eliminateTriviallyDeadOps region-utils helper and expose as a Pass (PR #194041)

Mehdi Amini llvmlistbot at llvm.org
Thu Apr 30 00:48:16 PDT 2026


================
@@ -506,6 +507,78 @@ LogicalResult mlir::runRegionDCE(RewriterBase &rewriter,
   return deleteDeadness(rewriter, regions, liveMap);
 }
 
+bool mlir::eliminateTriviallyDeadOps(RewriterBase &rewriter, Region &region,
+                                     bool includeNestedRegions) {
+  bool changed = false;
+
+  // Step 1: walk each op in reverse program order. If the op is already
----------------
joker-eph wrote:

The original has different tradeoffs, in particular the need to perform pruning of the queue when deleting an op (linear scan of the queue for all the nested operation), and calls to `isProperAncestor()` for enqueuing.

That said I just noticed the walk for catching defining ops of operands of nested ops: I think that is still needed. I'll craft a test that the current pass does not catch.

(it's not related to the recursive aspect, just to the enqueue mechanism)

https://github.com/llvm/llvm-project/pull/194041


More information about the Mlir-commits mailing list