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

Mehdi Amini llvmlistbot at llvm.org
Wed Apr 29 01:49:25 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:

I found it more difficult to write the steps while proceeding it all at once.
I started with a walk, but I couldn't for example do the first step with a reverse traversal that eliminates the operations as I go..

Also the check `defOp->getParentRegion() != &region` would be more costly: have to check recursively all the predecessors. 

I can give it another try to see though, but ultimately the current approach looked also nicer from a mental model point of view: it processes only a "flat" structure inside the region at each step.

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


More information about the Mlir-commits mailing list