@@ -2804,17 +2804,19 @@ LogicalResult OperationLegalizer::legalizePatternResult(
28042804 assert (impl.pendingRootUpdates .empty () && " dangling root updates" );
28052805
28062806#if MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS
2807- // Check that the root was either replaced or updated in place.
2808- auto newRewrites = llvm::drop_begin (impl.rewrites , curState.numRewrites );
2809- auto replacedRoot = [&] {
2810- return hasRewrite<ReplaceOperationRewrite>(newRewrites, op);
2811- };
2812- auto updatedRootInPlace = [&] {
2813- return hasRewrite<ModifyOperationRewrite>(newRewrites, op);
2814- };
2815- if (!replacedRoot () && !updatedRootInPlace ())
2816- llvm::report_fatal_error (
2817- " expected pattern to replace the root operation or modify it in place" );
2807+ if (impl.config .allowPatternRollback ) {
2808+ // Check that the root was either replaced or updated in place.
2809+ auto newRewrites = llvm::drop_begin (impl.rewrites , curState.numRewrites );
2810+ auto replacedRoot = [&] {
2811+ return hasRewrite<ReplaceOperationRewrite>(newRewrites, op);
2812+ };
2813+ auto updatedRootInPlace = [&] {
2814+ return hasRewrite<ModifyOperationRewrite>(newRewrites, op);
2815+ };
2816+ if (!replacedRoot () && !updatedRootInPlace ())
2817+ llvm::report_fatal_error (" expected pattern to replace the root operation "
2818+ " or modify it in place" );
2819+ }
28182820#endif // MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS
28192821
28202822 // Legalize each of the actions registered during application.
0 commit comments