diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp --- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp @@ -367,7 +367,9 @@ if (tensor::isSameTypeWithoutEncoding(srcType, dstType)) { if (Operation *def = op.getSource().getDefiningOp()) { if (def->hasOneUse() && isa(def)) { - def->getResult(0).setType(op->getResultTypes()[0]); + rewriter.updateRootInPlace(def, [&]() { + def->getResult(0).setType(op->getResultTypes()[0]); + }); rewriter.replaceOp(op, def->getResult(0)); return success(); }