@@ -56,19 +56,24 @@ namespace {
5656// `d0 + 2 * d1 + d3` is tiled by [0, 0, 0, 2] but not by [0, 0, 2, 0]
5757//
5858struct TileCheck : public AffineExprVisitor <TileCheck> {
59- TileCheck (ArrayRef<OpFoldResult> tileSizes, ArrayRef<OpFoldResult> sizeBounds)
60- : tileSizes(tileSizes), sizeBounds(sizeBounds) {}
59+ TileCheck (ArrayRef<OpFoldResult> tileSizes, ArrayRef<OpFoldResult> sizeBounds,
60+ bool isMonotonicallyIncreasing)
61+ : tileSizes(tileSizes), sizeBounds(sizeBounds),
62+ isMonotonicallyIncreasing (isMonotonicallyIncreasing) {}
6163
6264 void visitDimExpr (AffineDimExpr expr) {
6365 unsigned pos = expr.getPosition ();
6466
65- // This dimension is tiled if the tile size is larger than zero and not
66- // equal to its domain size (if statically known).
67- std::optional<int64_t > tileSize = getConstantIntValue (tileSizes[pos]);
68- if (tileSize && !sizeBounds.empty ()) {
69- std::optional<int64_t > sizeBound = getConstantIntValue (sizeBounds[pos]);
70- if (sizeBound && *sizeBound == *tileSize) {
71- return ;
67+ // If the expression is non monotonic, this dimension is tiled if the tile
68+ // size is larger than zero and not equal to its domain size (if statically
69+ // known).
70+ if (!isMonotonicallyIncreasing) {
71+ std::optional<int64_t > tileSize = getConstantIntValue (tileSizes[pos]);
72+ if (tileSize && !sizeBounds.empty ()) {
73+ std::optional<int64_t > sizeBound = getConstantIntValue (sizeBounds[pos]);
74+ if (sizeBound && *sizeBound == *tileSize) {
75+ return ;
76+ }
7277 }
7378 }
7479
@@ -84,6 +89,7 @@ struct TileCheck : public AffineExprVisitor<TileCheck> {
8489 bool isTiled = false ;
8590 ArrayRef<OpFoldResult> tileSizes;
8691 ArrayRef<OpFoldResult> sizeBounds;
92+ bool isMonotonicallyIncreasing;
8793};
8894
8995} // namespace
@@ -92,7 +98,7 @@ static bool isTiled(AffineExpr expr, ArrayRef<OpFoldResult> tileSizes,
9298 ArrayRef<OpFoldResult> sizeBounds) {
9399 if (!expr)
94100 return false ;
95- TileCheck t (tileSizes, sizeBounds);
101+ TileCheck t (tileSizes, sizeBounds, expr. isMonotonicallyIncreasing () );
96102 t.visit (expr);
97103 return t.isTiled ;
98104}
0 commit comments