Skip to content

Commit 4d17ae7

Browse files
authored
[MLIR][Affine] Fix affine-loop-tile zero cache size corner case crash (#130526)
Fixes: #64979
1 parent cdf1833 commit 4d17ae7

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

mlir/lib/Dialect/Affine/Transforms/LoopTiling.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,21 @@ void LoopTiling::getTileSizes(ArrayRef<AffineForOp> band,
110110
return;
111111
}
112112

113-
// Use tileSizes and fill them with default tile size if it's short.
113+
// Use supplied tile sizes and fill them with default tile size if it's short.
114114
if (!this->tileSizes.empty()) {
115115
tileSizes->assign(this->tileSizes.begin(), this->tileSizes.end());
116116
tileSizes->resize(band.size(), kDefaultTileSize);
117117
return;
118118
}
119119
tileSizes->resize(band.size());
120120

121+
// If the cache size is zero, set the minimum valid tile size. No good reason
122+
// to pick another specific size over this.
123+
if (cacheSizeInKiB == 0) {
124+
std::fill(tileSizes->begin(), tileSizes->end(), 1);
125+
return;
126+
}
127+
121128
// The first loop in the band.
122129
AffineForOp rootForOp = band[0];
123130
(void)rootForOp;

mlir/test/Dialect/Affine/loop-tiling.mlir

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// RUN: mlir-opt %s -split-input-file -affine-loop-tile="tile-size=32" | FileCheck %s
22
// RUN: mlir-opt %s -split-input-file -affine-loop-tile="cache-size=512" | FileCheck %s --check-prefix=MODEL
3+
// RUN: mlir-opt %s -split-input-file -affine-loop-tile="cache-size=0" | FileCheck %s --check-prefix=ZERO-CACHE
34
// RUN: mlir-opt %s -split-input-file -affine-loop-tile="tile-size=32 separate" | FileCheck %s --check-prefix=SEPARATE
45

5-
// -----
6-
76
// CHECK-DAG: [[$UB:#map[0-9]*]] = affine_map<(d0) -> (d0 + 32)>
87
// CHECK-DAG: [[$UB_MIN:#map[0-9]*]] = affine_map<(d0) -> (d0 + 32, 50)>
98
// CHECK-DAG: [[$ID:#map[0-9]*]] = affine_map<(d0) -> (d0)>
109
// CHECK-DAG: [[$ID_PLUS_21:#map[0-9]*]] = affine_map<(d0) -> (d0 + 21)>
10+
// ZERO-CACHE-DAG: affine_map<(d0) -> (d0)>
11+
// ZERO-CACHE-DAG: affine_map<(d0) -> (d0 + 1)>
1112

1213
// CHECK-LABEL: func @loop_tiling()
1314
// CHECK-NEXT: affine.for %{{.*}} = 0 to 256 step 32 {

0 commit comments

Comments
 (0)