diff --git a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp --- a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp +++ b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp @@ -1837,17 +1837,18 @@ return failure(); /// Deduce the type of the result to use for the canonicalized operation. + auto sliceOpType = sliceOp.getType(); RankedTensorType resultType = ExtractSliceOp::inferCanonicalRankReducedResultType( - sliceOp.getType().getRank(), sliceOp.getSourceType(), + sliceOpType.getRank(), sliceOp.getSourceType(), sliceOp.getMixedOffsets(), sliceOp.getMixedSizes(), sliceOp.getMixedStrides()); Value newSlice = rewriter.create( sliceOp.getLoc(), resultType, castOp.getSource(), sliceOp.getOffsets(), sliceOp.getSizes(), sliceOp.getStrides(), sliceOp.getStaticOffsets(), sliceOp.getStaticSizes(), sliceOp.getStaticStrides()); - rewriter.replaceOpWithNewOp(sliceOp, sliceOp.getType(), - newSlice); + if (newSlice.getType() != sliceOpType) + rewriter.replaceOpWithNewOp(sliceOp, sliceOpType, newSlice); return success(); } };