Skip to content

Commit 662c626

Browse files
authored
[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> ```
1 parent eb07600 commit 662c626

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

mlir/lib/Dialect/Arith/IR/ArithOps.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ LogicalResult arith::ConstantOp::verify() {
213213
return emitOpError(
214214
"value must be an integer, float, or elements attribute");
215215
}
216+
217+
auto vecType = dyn_cast<VectorType>(type);
218+
if (vecType && vecType.isScalable() && !isa<SplatElementsAttr>(getValue()))
219+
return emitOpError(
220+
"intializing scalable vectors with elements attribute is not supported"
221+
" unless it's a vector splat");
216222
return success();
217223
}
218224

mlir/test/Dialect/Arith/invalid.mlir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ func.func @constant_out_of_range() {
6464

6565
// -----
6666

67+
func.func @constant_invalid_scalable_vec_initialization() {
68+
^bb0:
69+
// expected-error@+1 {{'arith.constant' op intializing scalable vectors with elements attribute is not supported unless it's a vector splat}}
70+
%c = arith.constant dense<[0, 1]> : vector<[2] x i32>
71+
return
72+
}
73+
74+
// -----
75+
6776
func.func @constant_wrong_type() {
6877
^bb:
6978
%x = "arith.constant"(){value = 10.} : () -> f32 // expected-error {{'arith.constant' op failed to verify that all of {value, result} have same type}}

0 commit comments

Comments
 (0)