diff --git a/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp b/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp index 03c5c2239ed7a..0df91a243d07a 100644 --- a/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp +++ b/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp @@ -630,14 +630,16 @@ DoWhileLowering::matchAndRewrite(WhileOp whileOp, // Loop around the "before" region based on condition. rewriter.setInsertionPointToEnd(before); auto condOp = cast(before->getTerminator()); - rewriter.replaceOpWithNewOp(condOp, condOp.getCondition(), - before, condOp.getArgs(), - continuation, ValueRange()); + rewriter.create(condOp.getLoc(), condOp.getCondition(), + before, condOp.getArgs(), continuation, + ValueRange()); // Replace the op with values "yielded" from the "before" region, which are // visible by dominance. rewriter.replaceOp(whileOp, condOp.getArgs()); + // Erase the condition op. + rewriter.eraseOp(condOp); return success(); }