Skip to content

Commit e38c8bd

Browse files
[MLIR][scf.parallel] Don't allow a tile size of 0 (#68762)
Fix a crash reported in #64331. The crash is described in the following comment: > It looks like the bug is being caused by the command line argument --scf-parallel-loop-tiling=parallel-loop-tile-sizes=0. More specifically, --scf-parallel-loop-tiling=parallel-loop-tile-sizes sets the tileSize variable to 0 on [this line](https://github.com/llvm/llvm-project/blob/7cc1bfaf371c4a816cf4e62fe31d8515bf8f6fbd/mlir/lib/Dialect/SCF/Transforms/ParallelLoopTiling.cpp#L67). tileSize is then used on [this line](https://github.com/llvm/llvm-project/blob/7cc1bfaf371c4a816cf4e62fe31d8515bf8f6fbd/mlir/lib/Dialect/SCF/Transforms/ParallelLoopTiling.cpp#L117) causing a divide by zero exception. This PR will: 1. Call `signalPassFail()` when 0 is passed as a tile size. 2. Avoid the divide by zero that causes the crash. Note: This is my first PR for MLIR, so please liberally critique it.
1 parent f081248 commit e38c8bd

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

mlir/lib/Dialect/SCF/Transforms/ParallelLoopTiling.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ struct ParallelLoopTiling
195195
}
196196

197197
void runOnOperation() override {
198+
for (auto tileSize : tileSizes)
199+
if (tileSize == 0) {
200+
mlir::emitError(mlir::UnknownLoc::get(&Pass::getContext()),
201+
"tile size cannot be 0");
202+
return signalPassFailure();
203+
}
198204
auto *parentOp = getOperation();
199205
SmallVector<ParallelOp, 2> innermostPloops;
200206
getInnermostParallelLoops(parentOp, innermostPloops);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: mlir-opt %s -pass-pipeline='builtin.module(func.func(scf-parallel-loop-tiling{parallel-loop-tile-sizes=0,0}))' -split-input-file -verify-diagnostics
2+
3+
// The expected error is, "tile size cannot be 0" at an unknown location. (It's
4+
// location is unknown because the it's caused by an invalid command line
5+
// argument.)
6+
// XFAIL: *
7+
8+
func.func @parallel_loop(%arg0 : index, %arg1 : index, %arg2 : index) {
9+
scf.parallel (%i) = (%arg0) to (%arg1) step (%arg2) {}
10+
return
11+
}

0 commit comments

Comments
 (0)