@@ -18771,10 +18771,6 @@ struct ExtendSlice final
1877118771 if (!extendOp)
1877218772 return rewriter.notifyMatchFailure(op, "Operand is not an ExtendOp");
1877318773
18774- if (extendOp.getResult().getNumUses() > 1)
18775- return rewriter.notifyMatchFailure(
18776- op, "ExtendOp result is used multiple times");
18777-
1877818774 // This transformation is simplified if strides are 1.
1877918775 if (llvm::any_of(op.getStrides(), [](int64_t s) { return s != 1; }))
1878018776 return rewriter.notifyMatchFailure(op, "Requires strides of 1");
@@ -18811,6 +18807,16 @@ struct ExtendSlice final
1881118807 int64_t new_rhs =
1881218808 std::max((int64_t)0, limit_d - std::max(start_d, lhs + size_d));
1881318809
18810+ if (new_lhs == 0 && new_rhs == 0) {
18811+ auto newSlice = rewriter.replaceOpWithNewOp<stablehlo::SliceOp>(
18812+ op, op.getType(), operand, new_starts, new_limits, new_strides);
18813+ return success();
18814+ }
18815+
18816+ if (extendOp.getResult().getNumUses() > 1) {
18817+ return rewriter.notifyMatchFailure(op, "ExtendOp result is used multiple times");
18818+ }
18819+
1881418820 // Create the new slice on the original tensor.
1881518821 auto newSlice = rewriter.create<stablehlo::SliceOp>(
1881618822 op.getLoc(), operand, new_starts, new_limits, new_strides);
0 commit comments