Skip to content

Commit 6d7024d

Browse files
[Tensor] Simplify tenor.pad tiling length calculations.
Signed-off-by: Nirvedh <[email protected]>
1 parent f9e1150 commit 6d7024d

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

mlir/lib/Dialect/Tensor/IR/TensorTilingInterfaceImpl.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -746,11 +746,6 @@ FailureOr<TilingResult> tensor::bubbleUpPadSlice(OpBuilder &b,
746746
Location loc = padOp->getLoc();
747747
AffineExpr dim0, dim1;
748748
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-
};
754749
// Subtract two integers.
755750
auto subMap = AffineMap::get(2, 0, {dim0 - dim1});
756751
auto sub = [&](OpFoldResult v1, OpFoldResult v2) {
@@ -825,16 +820,13 @@ FailureOr<TilingResult> tensor::bubbleUpPadSlice(OpBuilder &b,
825820
// The original read could also have stopped in the high padding zone.
826821
// In that case, set the end positition of the read should be the end of
827822
// 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);
838830
newLengths.push_back(newLength);
839831

840832
// Check if newLength is zero. In that case, no SubTensorOp should be

0 commit comments

Comments
 (0)