@@ -746,11 +746,6 @@ FailureOr<TilingResult> tensor::bubbleUpPadSlice(OpBuilder &b,
746
746
Location loc = padOp->getLoc ();
747
747
AffineExpr dim0, dim1;
748
748
bindDims (b.getContext (), dim0, dim1);
749
- // Add two integers.
750
- auto addMap = AffineMap::get (2 , 0 , {dim0 + dim1});
751
- auto add = [&](OpFoldResult v1, OpFoldResult v2) {
752
- return affine::makeComposedFoldedAffineApply (b, loc, addMap, {v1, v2});
753
- };
754
749
// Subtract two integers.
755
750
auto subMap = AffineMap::get (2 , 0 , {dim0 - dim1});
756
751
auto sub = [&](OpFoldResult v1, OpFoldResult v2) {
@@ -825,16 +820,13 @@ FailureOr<TilingResult> tensor::bubbleUpPadSlice(OpBuilder &b,
825
820
// The original read could also have stopped in the high padding zone.
826
821
// In that case, set the end positition of the read should be the end of
827
822
// the source tensor. (Similar to newOffset.)
828
- //
829
- // endLoc = min(max(offset - low + length, 0), srcSize)
830
- //
831
- // The new ExtractSliceOp length is `endLoc - newOffset`.
832
- //
833
- // Optimization: If low = 0, then the formula can be simplified.
834
- OpFoldResult endLoc =
835
- hasLowPad ? min (max (add (sub (offset, low), length), zero), srcSize)
836
- : min (add (offset, length), srcSize);
837
- OpFoldResult newLength = sub (endLoc, newOffset);
823
+ // srcSize - newOffset represents how much length we have available
824
+ // and length - newLow represents how much length we want at most.
825
+ OpFoldResult newLength = min (sub (srcSize, newOffset), sub (length, newLow));
826
+ // Optimization: If low = 0, then newLow = 0. then newLength >= 0 assuming
827
+ // length >= 0.
828
+ if (hasLowPad)
829
+ newLength = max (newLength, zero);
838
830
newLengths.push_back (newLength);
839
831
840
832
// Check if newLength is zero. In that case, no SubTensorOp should be
0 commit comments