[llvm] [mlir][affine] Check the input vector sizes to be greater than 0 (PR #65293)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 26 19:29:10 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-affine
<details>
<summary>Changes</summary>
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: https://github.com/llvm/llvm-project/issues/64262
---
Full diff: https://github.com/llvm/llvm-project/pull/65293.diff
3 Files Affected:
- (modified) mlir/include/mlir/Dialect/Affine/Passes.td (+2-1)
- (modified) mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp (+5)
- (added) mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir (+9)
``````````diff
diff --git a/mlir/include/mlir/Dialect/Affine/Passes.td b/mlir/include/mlir/Dialect/Affine/Passes.td
index 891a6661ca87be7..1036e93a0392409 100644
--- a/mlir/include/mlir/Dialect/Affine/Passes.td
+++ b/mlir/include/mlir/Dialect/Affine/Passes.td
@@ -349,7 +349,8 @@ def AffineVectorize : Pass<"affine-super-vectorize", "func::FuncOp"> {
let dependentDialects = ["vector::VectorDialect"];
let options = [
ListOption<"vectorSizes", "virtual-vector-size", "int64_t",
- "Specify an n-D virtual vector size for vectorization">,
+ "Specify an n-D virtual vector size for vectorization. "
+ "This must be greater than zero.">,
// Optionally, the fixed mapping from loop to fastest varying MemRef
// dimension for all the MemRefs within a loop pattern:
// the index represents the loop depth, the value represents the k^th
diff --git a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
index 85c2602aa266d67..a1d9c7b56c4e154 100644
--- a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
+++ b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
@@ -1732,6 +1732,11 @@ void Vectorize::runOnOperation() {
return signalPassFailure();
}
+ if (llvm::any_of(vectorSizes, [](int64_t size) { return size <= 0; })) {
+ f.emitError("Vectorization factor must be greater than zero.");
+ return signalPassFailure();
+ }
+
DenseSet<Operation *> parallelLoops;
ReductionLoopMap reductionLoops;
diff --git a/mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir b/mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir
new file mode 100644
index 000000000000000..396cc933e25bcf4
--- /dev/null
+++ b/mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir
@@ -0,0 +1,9 @@
+// RUN: mlir-opt %s -verify-diagnostics --affine-super-vectorize=virtual-vector-size=0
+
+// expected-error at +1 {{Vectorization factor must be greater than zero}}
+func.func @with_zero_vector_size(%arg0: memref<21x12x12xi1>) {
+ affine.for %arg1 = 0 to 84 step 4294967295 {
+ }
+ return
+}
+
``````````
</details>
https://github.com/llvm/llvm-project/pull/65293
More information about the llvm-commits
mailing list