Index: mlir/lib/Dialect/Affine/IR/AffineOps.cpp =================================================================== --- mlir/lib/Dialect/Affine/IR/AffineOps.cpp +++ mlir/lib/Dialect/Affine/IR/AffineOps.cpp @@ -1550,6 +1550,12 @@ } void AffineForOp::print(OpAsmPrinter &p) { + // Operation may be invalidated after applying a rewrite pattern. + if (region().empty()) { + p << " "; + return; + } + p << ' '; p.printOperand(getBody()->getArgument(0)); p << " = ";