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

Ivan Butygin llvmlistbot at llvm.org
Sat Oct 24 06:00:33 PDT 2026


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

>From 61a5a701d544c99ccebfec69a51aa7c25206b0d5 Mon Sep 17 00:00:00 2001
From: Ivan Butygin <ivan.butygin at gmail.com>
Date: Tue, 20 Oct 2026 11:21:34 +0200
Subject: [PATCH 1/2] [mlir] Find the pattern dump root only when IR debugging
 is enabled

---
 mlir/lib/Rewrite/PatternApplicator.cpp | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

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 =

>From 95cb4b562176e9a89a0730674e088c5e32e72b66 Mon Sep 17 00:00:00 2001
From: Ivan Butygin <ivan.butygin at gmail.com>
Date: Wed, 21 Oct 2026 20:43:32 +0200
Subject: [PATCH 2/2] [mlir] Guard pattern dump root lookup with DebugFlag
 explicitly

---
 mlir/lib/Rewrite/PatternApplicator.cpp | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/mlir/lib/Rewrite/PatternApplicator.cpp b/mlir/lib/Rewrite/PatternApplicator.cpp
index 4b6ca9bac0a0bd..fc415e7dbb3847 100644
--- a/mlir/lib/Rewrite/PatternApplicator.cpp
+++ b/mlir/lib/Rewrite/PatternApplicator.cpp
@@ -201,10 +201,9 @@ LogicalResult PatternApplicator::matchAndRewrite(
           // Operation `op` may be invalidated after applying the rewrite
           // pattern.
           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));
+          // Only find the dump root when level-2 IR debugging is enabled.
+          if (llvm::DebugFlag && llvm::isCurrentDebugType(DEBUG_TYPE, 2))
+            dumpRootOp = getDumpRootOp(op);
 #endif
           if (pdlMatch) {
             result =



More information about the Mlir-commits mailing list