[Mlir-commits] [mlir] [mlir] Find the pattern dump root only when IR debugging is enabled (PR #233771)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Oct 20 02:53:29 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Ivan Butygin (Hardcode84)

<details>
<summary>Changes</summary>

Extracted from https://github.com/llvm/llvm-project/pull/231423

`PatternApplicator` debug printing was unconditionally calling `getDumpRootOp` which walks nested ops chains. This was taking a noticeable time in synthetic 1000-nested test. Call `getDumpRootOp` only if printing is actually enabled.

---
Full diff: https://github.com/llvm/llvm-project/pull/233771.diff


1 Files Affected:

- (modified) mlir/lib/Rewrite/PatternApplicator.cpp (+5-1) 


``````````diff
diff --git a/mlir/lib/Rewrite/PatternApplicator.cpp b/mlir/lib/Rewrite/PatternApplicator.cpp
index e1b56fd6efda00..4b6ca9bac0a0bd 100644
--- a/mlir/lib/Rewrite/PatternApplicator.cpp
+++ b/mlir/lib/Rewrite/PatternApplicator.cpp
@@ -200,7 +200,11 @@ LogicalResult PatternApplicator::matchAndRewrite(
 #ifndef NDEBUG
           // Operation `op` may be invalidated after applying the rewrite
           // pattern.
-          Operation *dumpRootOp = getDumpRootOp(op);
+          Operation *dumpRootOp = nullptr;
+          // LLVM_DEBUG enables level 1, but IR dumps require level 2. Avoid
+          // walking ancestors to find the dump root when no IR will be printed.
+          LLVM_DEBUG(if (llvm::isCurrentDebugType(DEBUG_TYPE, 2)) dumpRootOp =
+                         getDumpRootOp(op));
 #endif
           if (pdlMatch) {
             result =

``````````

</details>


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


More information about the Mlir-commits mailing list