[Mlir-commits] [mlir] 9782993 - [mlir][affine] Check the input vector sizes to be greater than 0 (#65293)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Oct 1 17:52:05 PDT 2023
Author: Kai Sasaki
Date: 2023-10-02T09:52:00+09:00
New Revision: 97829935844e7f35216e12c13231f35fbea640c3
URL: https://github.com/llvm/llvm-project/commit/97829935844e7f35216e12c13231f35fbea640c3
DIFF: https://github.com/llvm/llvm-project/commit/97829935844e7f35216e12c13231f35fbea640c3.diff
LOG: [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: https://github.com/llvm/llvm-project/issues/64262
Added:
mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir
Modified:
mlir/include/mlir/Dialect/Affine/Passes.td
mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
Removed:
################################################################################
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 f07ed626a916384..6b7a157925fae18 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
+}
+
More information about the Mlir-commits
mailing list