Skip to content

Commit 1fd280d

Browse files
authored
[MLIR][Affine] Add missing check in affine data copy nest generation (#127809)
Handle case where no lower or upper bound could be found for a dimension. Invalid IR was being generated silently for a test case. Fixes: #127808
1 parent 37c341d commit 1fd280d

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2001,8 +2001,15 @@ static LogicalResult generateCopy(
20012001
}
20022002

20032003
SmallVector<AffineMap, 4> lbMaps(rank), ubMaps(rank);
2004-
for (unsigned i = 0; i < rank; ++i)
2004+
for (unsigned i = 0; i < rank; ++i) {
20052005
region.getLowerAndUpperBound(i, lbMaps[i], ubMaps[i]);
2006+
if (lbMaps[i].getNumResults() == 0 || ubMaps[i].getNumResults() == 0) {
2007+
LLVM_DEBUG(llvm::dbgs()
2008+
<< "Missing lower or upper bound for region along dimension: "
2009+
<< i << '\n');
2010+
return failure();
2011+
}
2012+
}
20062013

20072014
const FlatAffineValueConstraints *cst = region.getConstraints();
20082015
// 'regionSymbols' hold values that this memory region is symbolic/parametric

mlir/test/Dialect/Affine/affine-data-copy.mlir

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,15 @@ func.func @affine_parallel(%85:memref<2x5x4x2xi64>) {
300300
}
301301
}
302302
}
303-
// CHECK: affine.for
304-
// CHECK-NEXT: affine.for %{{.*}} = 0 to 5
305-
// CHECK-NEXT: affine.for %{{.*}} = 0 to 4
306-
// CHECK-NEXT: affine.for %{{.*}} = 0 to 2
307-
303+
// Lower and upper bounds for the region can't be determined for the outermost
304+
// dimension. No fast buffer generation.
308305
// CHECK: affine.for
309306
// CHECK-NEXT: affine.parallel
310307
// CHECK-NEXT: affine.parallel
308+
// CHECK-NEXT: affine.for
309+
// CHECK-NOT: affine.for
310+
311+
311312
return
312313
}
313314

0 commit comments

Comments
 (0)