[Mlir-commits] [mlir] 662c626 - [mlir][arith] Refine the verifier for arith.constant (#86178)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Apr 8 05:59:31 PDT 2024
Author: Andrzej WarzyĆski
Date: 2024-04-08T13:59:27+01:00
New Revision: 662c62609e8ee2dc996da69e11c0d594e799c299
URL: https://github.com/llvm/llvm-project/commit/662c62609e8ee2dc996da69e11c0d594e799c299
DIFF: https://github.com/llvm/llvm-project/commit/662c62609e8ee2dc996da69e11c0d594e799c299.diff
LOG: [mlir][arith] Refine the verifier for arith.constant (#86178)
Disallows initialization of scalable vectors with an attribute of
arbitrary values, e.g.:
```mlir
%c = arith.constant dense<[0, 1]> : vector<[2] x i32>
```
Initialization using vector splats remains allowed (i.e. when all the
init values are identical):
```mlir
%c = arith.constant dense<[1, 1]> : vector<[2] x i32>
```
Added:
Modified:
mlir/lib/Dialect/Arith/IR/ArithOps.cpp
mlir/test/Dialect/Arith/invalid.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
index 1d68a4f7292b53..efc4bfe622d53a 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
@@ -213,6 +213,12 @@ LogicalResult arith::ConstantOp::verify() {
return emitOpError(
"value must be an integer, float, or elements attribute");
}
+
+ auto vecType = dyn_cast<VectorType>(type);
+ if (vecType && vecType.isScalable() && !isa<SplatElementsAttr>(getValue()))
+ return emitOpError(
+ "intializing scalable vectors with elements attribute is not supported"
+ " unless it's a vector splat");
return success();
}
diff --git a/mlir/test/Dialect/Arith/invalid.mlir b/mlir/test/Dialect/Arith/invalid.mlir
index 6d8ac0ada52be3..fdc907a7c6af13 100644
--- a/mlir/test/Dialect/Arith/invalid.mlir
+++ b/mlir/test/Dialect/Arith/invalid.mlir
@@ -64,6 +64,15 @@ func.func @constant_out_of_range() {
// -----
+func.func @constant_invalid_scalable_vec_initialization() {
+^bb0:
+ // expected-error at +1 {{'arith.constant' op intializing scalable vectors with elements attribute is not supported unless it's a vector splat}}
+ %c = arith.constant dense<[0, 1]> : vector<[2] x i32>
+ return
+}
+
+// -----
+
func.func @constant_wrong_type() {
^bb:
%x = "arith.constant"(){value = 10.} : () -> f32 // expected-error {{'arith.constant' op failed to verify that all of {value, result} have same type}}
More information about the Mlir-commits
mailing list