[Mlir-commits] [mlir] [mlir] Refactor transform.apply_dce into a eliminateTriviallyDeadOps region-utils helper (PR #194041)
Matthias Springer
llvmlistbot at llvm.org
Wed Apr 29 03:01:11 PDT 2026
================
@@ -506,6 +507,78 @@ LogicalResult mlir::runRegionDCE(RewriterBase &rewriter,
return deleteDeadness(rewriter, regions, liveMap);
}
+bool mlir::eliminateTriviallyDeadOps(RewriterBase &rewriter, Region ®ion,
+ bool includeNestedRegions) {
+ bool changed = false;
+
+ // Step 1: walk each op in reverse program order. If the op is already
+ // trivially dead, erase it outright — there's no point recursing into
+ // regions that will be destroyed with it. Otherwise, if
+ // `includeNestedRegions` is set, recurse into its nested regions so values
+ // defined in `region` may lose their last user and show up as dead in
+ // step 2's seed. Reverse iteration lets dead chains propagate within this
+ // single pass.
+ for (Block &block : llvm::reverse(region)) {
----------------
matthias-springer wrote:
That's fine but does it potentially regress some cases compared to the previous implementation?
https://github.com/llvm/llvm-project/pull/194041
More information about the Mlir-commits
mailing list