@@ -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