[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>
```
This commit is contained in:
Andrzej Warzyński
2024-04-08 13:59:27 +01:00
committed by GitHub
parent eb07600f8e
commit 662c62609e
2 changed files with 15 additions and 0 deletions

View File

@@ -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();
}

View File

@@ -64,6 +64,15 @@ func.func @constant_out_of_range() {
// -----
func.func @constant_invalid_scalable_vec_initialization() {
^bb0:
// expected-error@+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}}