[Mlir-commits] [mlir] [mlir] Dialect Conversion: Fix expensive pattern check in no-rollback mode (PR #166576)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Nov 5 08:06:00 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core
Author: Tim Noack (timnoack)
<details>
<summary>Changes</summary>
Fixes a bug causing every conversion to fail fatally with "expected pattern to replace the root operation or modify it in place" when `MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS` is enabled and pattern rollback is disabled.
When `allowPatternRollback` is disabled, the rewriter does not keep track of the rewrites it performs and can therefore not use that list to check whether the root op was replaced or updated in place.
---
Full diff: https://github.com/llvm/llvm-project/pull/166576.diff
1 Files Affected:
- (modified) mlir/lib/Transforms/Utils/DialectConversion.cpp (+13-11)
``````````diff
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 2fe06970eb568..424349b555228 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -2804,17 +2804,19 @@ LogicalResult OperationLegalizer::legalizePatternResult(
assert(impl.pendingRootUpdates.empty() && "dangling root updates");
#if MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS
- // Check that the root was either replaced or updated in place.
- auto newRewrites = llvm::drop_begin(impl.rewrites, curState.numRewrites);
- auto replacedRoot = [&] {
- return hasRewrite<ReplaceOperationRewrite>(newRewrites, op);
- };
- auto updatedRootInPlace = [&] {
- return hasRewrite<ModifyOperationRewrite>(newRewrites, op);
- };
- if (!replacedRoot() && !updatedRootInPlace())
- llvm::report_fatal_error(
- "expected pattern to replace the root operation or modify it in place");
+ if (impl.config.allowPatternRollback) {
+ // Check that the root was either replaced or updated in place.
+ auto newRewrites = llvm::drop_begin(impl.rewrites, curState.numRewrites);
+ auto replacedRoot = [&] {
+ return hasRewrite<ReplaceOperationRewrite>(newRewrites, op);
+ };
+ auto updatedRootInPlace = [&] {
+ return hasRewrite<ModifyOperationRewrite>(newRewrites, op);
+ };
+ if (!replacedRoot() && !updatedRootInPlace())
+ llvm::report_fatal_error("expected pattern to replace the root operation "
+ "or modify it in place");
+ }
#endif // MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS
// Legalize each of the actions registered during application.
``````````
</details>
https://github.com/llvm/llvm-project/pull/166576
More information about the Mlir-commits
mailing list