Skip to content

Commit f22d588

Browse files
authored
[mlir] Dialect Conversion: Fix expensive pattern check in no-rollback mode (#166576)
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.
1 parent 342e28f commit f22d588

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

mlir/lib/Transforms/Utils/DialectConversion.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2856,17 +2856,19 @@ LogicalResult OperationLegalizer::legalizePatternResult(
28562856
assert(impl.pendingRootUpdates.empty() && "dangling root updates");
28572857

28582858
#if MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS
2859-
// Check that the root was either replaced or updated in place.
2860-
auto newRewrites = llvm::drop_begin(impl.rewrites, curState.numRewrites);
2861-
auto replacedRoot = [&] {
2862-
return hasRewrite<ReplaceOperationRewrite>(newRewrites, op);
2863-
};
2864-
auto updatedRootInPlace = [&] {
2865-
return hasRewrite<ModifyOperationRewrite>(newRewrites, op);
2866-
};
2867-
if (!replacedRoot() && !updatedRootInPlace())
2868-
llvm::report_fatal_error(
2869-
"expected pattern to replace the root operation or modify it in place");
2859+
if (impl.config.allowPatternRollback) {
2860+
// Check that the root was either replaced or updated in place.
2861+
auto newRewrites = llvm::drop_begin(impl.rewrites, curState.numRewrites);
2862+
auto replacedRoot = [&] {
2863+
return hasRewrite<ReplaceOperationRewrite>(newRewrites, op);
2864+
};
2865+
auto updatedRootInPlace = [&] {
2866+
return hasRewrite<ModifyOperationRewrite>(newRewrites, op);
2867+
};
2868+
if (!replacedRoot() && !updatedRootInPlace())
2869+
llvm::report_fatal_error("expected pattern to replace the root operation "
2870+
"or modify it in place");
2871+
}
28702872
#endif // MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS
28712873

28722874
// Legalize each of the actions registered during application.

0 commit comments

Comments
 (0)