Skip to content

Commit 3c938d0

Browse files
authored
[MLIR][Affine] Fix affine.parallel op verifier (llvm#127611)
Fix affine.parallel op verifier for missing check on zero result lower or upper bound maps. lb/ub maps should have at least one result. Fixes: llvm#120186
1 parent 1509b46 commit 3c938d0

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

mlir/lib/Dialect/Affine/IR/AffineOps.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3918,14 +3918,24 @@ LogicalResult AffineParallelOp::verify() {
39183918
}
39193919

39203920
unsigned expectedNumLBResults = 0;
3921-
for (APInt v : getLowerBoundsGroups())
3922-
expectedNumLBResults += v.getZExtValue();
3921+
for (APInt v : getLowerBoundsGroups()) {
3922+
unsigned results = v.getZExtValue();
3923+
if (results == 0)
3924+
return emitOpError()
3925+
<< "expected lower bound map to have at least one result";
3926+
expectedNumLBResults += results;
3927+
}
39233928
if (expectedNumLBResults != getLowerBoundsMap().getNumResults())
39243929
return emitOpError() << "expected lower bounds map to have "
39253930
<< expectedNumLBResults << " results";
39263931
unsigned expectedNumUBResults = 0;
3927-
for (APInt v : getUpperBoundsGroups())
3928-
expectedNumUBResults += v.getZExtValue();
3932+
for (APInt v : getUpperBoundsGroups()) {
3933+
unsigned results = v.getZExtValue();
3934+
if (results == 0)
3935+
return emitOpError()
3936+
<< "expected upper bound map to have at least one result";
3937+
expectedNumUBResults += results;
3938+
}
39293939
if (expectedNumUBResults != getUpperBoundsMap().getNumResults())
39303940
return emitOpError() << "expected upper bounds map to have "
39313941
<< expectedNumUBResults << " results";

mlir/test/Dialect/Affine/invalid.mlir

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,24 @@ func.func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) {
297297

298298
// -----
299299

300+
func.func @no_upper_bound_affine_parallel() {
301+
// expected-error@+1 {{expected lower bound map to have at least one result}}
302+
affine.parallel (%arg2) = (max()) to (1) {
303+
}
304+
return
305+
}
306+
307+
// -----
308+
309+
func.func @no_upper_bound_affine_parallel() {
310+
// expected-error@+1 {{expected upper bound map to have at least one result}}
311+
affine.parallel (%arg3) = (0) to (min()) {
312+
}
313+
return
314+
}
315+
316+
// -----
317+
300318
func.func @vector_load_invalid_vector_type() {
301319
%0 = memref.alloc() : memref<100xf32>
302320
affine.for %i0 = 0 to 16 step 8 {

0 commit comments

Comments
 (0)