[Mlir-commits] [mlir] [MLIR][Test] Notify rewriter on in-place attrs in clone test patterns (PR #192215)
Hocky Yudhiono
llvmlistbot at llvm.org
Wed Apr 15 02:11:20 PDT 2026
https://github.com/hockyy created https://github.com/llvm/llvm-project/pull/192215
Test patterns `CloneOp` and `CloneRegionBeforeOp` set the `was_cloned` unit attribute with a direct `setAttr` on the operation. That mutates the IR without going through `RewriterBase::finalizeOpModification`, so `notifyOperationModified` is never sent to listeners.
When `MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS` is enabled, the greedy pattern driver’s fingerprint bookkeeping still holds stale entries for those ops and aborts with `LLVM ERROR: operation finger print changed` after a successful rewrite. This does not change IR semantics of the patterns; it aligns them with the rewriter notification contract expected by expensive checks and other listeners.
**Testing**
- `mlir-opt` on IR using `test.clone_region_before` with `-test-strict-pattern-driver=strictness=AnyOp` (no fingerprint fatal error with expensive checks on).
Assisted-by: Cursor (Composer 2)
>From 493cd7aa2f09831d7f0871de1c502c305fb5cf97 Mon Sep 17 00:00:00 2001
From: Hocky Yudhiono <hocky.yudhiono at gmail.com>
Date: Wed, 15 Apr 2026 17:09:26 +0800
Subject: [PATCH] [MLIR][Test] Notify rewriter on in-place attrs in clone test
patterns
---
mlir/test/lib/Dialect/Test/TestPatterns.cpp | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/mlir/test/lib/Dialect/Test/TestPatterns.cpp b/mlir/test/lib/Dialect/Test/TestPatterns.cpp
index c8be4bf3f0f8d..249ed7a42da0a 100644
--- a/mlir/test/lib/Dialect/Test/TestPatterns.cpp
+++ b/mlir/test/lib/Dialect/Test/TestPatterns.cpp
@@ -365,7 +365,9 @@ struct CloneOp : public RewritePattern {
if (op->hasAttr("was_cloned"))
return failure();
Operation *cloned = rewriter.clone(*op);
- cloned->setAttr("was_cloned", rewriter.getUnitAttr());
+ rewriter.modifyOpInPlace(cloned, [&]() {
+ cloned->setAttr("was_cloned", rewriter.getUnitAttr());
+ });
return success();
}
};
@@ -383,7 +385,9 @@ struct CloneRegionBeforeOp : public RewritePattern {
return failure();
for (Region &r : op->getRegions())
rewriter.cloneRegionBefore(r, op->getBlock());
- op->setAttr("was_cloned", rewriter.getUnitAttr());
+ rewriter.modifyOpInPlace(op, [&]() {
+ op->setAttr("was_cloned", rewriter.getUnitAttr());
+ });
return success();
}
};
More information about the Mlir-commits
mailing list