Skip to content

Commit 9782993

Browse files
authored
[mlir][affine] Check the input vector sizes to be greater than 0 (#65293)
In the process of vectorization of the affine loop, the 0 vector size causes the crash with building the invalid AffineForOp. We can catch the case beforehand propagating to the assertion. See: #64262
1 parent f0505c3 commit 9782993

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

mlir/include/mlir/Dialect/Affine/Passes.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ def AffineVectorize : Pass<"affine-super-vectorize", "func::FuncOp"> {
349349
let dependentDialects = ["vector::VectorDialect"];
350350
let options = [
351351
ListOption<"vectorSizes", "virtual-vector-size", "int64_t",
352-
"Specify an n-D virtual vector size for vectorization">,
352+
"Specify an n-D virtual vector size for vectorization. "
353+
"This must be greater than zero.">,
353354
// Optionally, the fixed mapping from loop to fastest varying MemRef
354355
// dimension for all the MemRefs within a loop pattern:
355356
// the index represents the loop depth, the value represents the k^th

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,6 +1732,11 @@ void Vectorize::runOnOperation() {
17321732
return signalPassFailure();
17331733
}
17341734

1735+
if (llvm::any_of(vectorSizes, [](int64_t size) { return size <= 0; })) {
1736+
f.emitError("Vectorization factor must be greater than zero.");
1737+
return signalPassFailure();
1738+
}
1739+
17351740
DenseSet<Operation *> parallelLoops;
17361741
ReductionLoopMap reductionLoops;
17371742

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: mlir-opt %s -verify-diagnostics --affine-super-vectorize=virtual-vector-size=0
2+
3+
// expected-error@+1 {{Vectorization factor must be greater than zero}}
4+
func.func @with_zero_vector_size(%arg0: memref<21x12x12xi1>) {
5+
affine.for %arg1 = 0 to 84 step 4294967295 {
6+
}
7+
return
8+
}
9+

0 commit comments

Comments
 (0)