diff --git a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp @@ -279,10 +279,21 @@ // Tiling creates a new slice at the proper index, the slice step is 1 // (i.e. the slice view does not subsample, stepping occurs in the loop). - auto m = map.getSubMap({r}); - auto offset = applyMapToValues(b, loc, m, lbs).front(); + AffineMap offsetMap = map.getSubMap({r}); + AffineMap sizeMap = offsetMap; + AffineExpr result = sizeMap.getResult(0); + if (result.getKind() == AffineExprKind::Add) { + auto binOp = result.dyn_cast(); + if (binOp.getLHS().getKind() == AffineExprKind::DimId && + binOp.getRHS().getKind() == AffineExprKind::DimId) { + auto newResult = result - 1; + sizeMap = AffineMap::get(sizeMap.getNumDims(), + sizeMap.getNumSymbols(), newResult); + } + } + auto offset = applyMapToValues(b, loc, offsetMap, lbs).front(); offsets.push_back(offset); - auto size = applyMapToValues(b, loc, m, subViewSizes).front(); + auto size = applyMapToValues(b, loc, sizeMap, subViewSizes).front(); // The size of the subview should be trimmed to avoid out-of-bounds // accesses, unless we statically know the subview size divides the view