Skip to content

Commit f4185e6

Browse files
committed
[mlir][spirv] Constraint alignment attribute
1 parent 76812fc commit f4185e6

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

mlir/include/mlir/Dialect/SPIRV/IR/SPIRVMemoryOps.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def SPIRV_LoadOp : SPIRV_Op<"Load", []> {
220220
let arguments = (ins
221221
SPIRV_AnyPtr:$ptr,
222222
OptionalAttr<SPIRV_MemoryAccessAttr>:$memory_access,
223-
OptionalAttr<I32Attr>:$alignment
223+
OptionalAttr<IntValidAlignment<I32Attr>>:$alignment
224224
);
225225

226226
let results = (outs
@@ -345,7 +345,7 @@ def SPIRV_StoreOp : SPIRV_Op<"Store", []> {
345345
SPIRV_AnyPtr:$ptr,
346346
SPIRV_Type:$value,
347347
OptionalAttr<SPIRV_MemoryAccessAttr>:$memory_access,
348-
OptionalAttr<I32Attr>:$alignment
348+
OptionalAttr<IntValidAlignment<I32Attr>>:$alignment
349349
);
350350

351351
let results = (outs);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: mlir-opt -split-input-file -verify-diagnostics %s
2+
3+
//===----------------------------------------------------------------------===//
4+
// spirv.LoadOp
5+
//===----------------------------------------------------------------------===//
6+
7+
func.func @aligned_load_non_positive() -> () {
8+
%0 = spirv.Variable : !spirv.ptr<f32, Function>
9+
// expected-error@below {{'spirv.Load' op attribute 'alignment' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive and whose value is a power of two > 0}}
10+
%1 = spirv.Load "Function" %0 ["Aligned", 0] : f32
11+
return
12+
}
13+
14+
// -----
15+
16+
func.func @aligned_load_non_power_of_two() -> () {
17+
%0 = spirv.Variable : !spirv.ptr<f32, Function>
18+
// expected-error@below {{'spirv.Load' op attribute 'alignment' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive and whose value is a power of two > 0}}
19+
%1 = spirv.Load "Function" %0 ["Aligned", 3] : f32
20+
return
21+
}
22+
23+
// -----
24+
25+
//===----------------------------------------------------------------------===//
26+
// spirv.StoreOp
27+
//===----------------------------------------------------------------------===//
28+
29+
func.func @aligned_store_non_positive(%arg0 : f32) -> () {
30+
%0 = spirv.Variable : !spirv.ptr<f32, Function>
31+
// expected-error@below {{'spirv.Store' op attribute 'alignment' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive and whose value is a power of two > 0}}
32+
spirv.Store "Function" %0, %arg0 ["Aligned", 0] : f32
33+
return
34+
}
35+
36+
// -----
37+
38+
func.func @aligned_store_non_power_of_two(%arg0 : f32) -> () {
39+
%0 = spirv.Variable : !spirv.ptr<f32, Function>
40+
// expected-error@below {{'spirv.Store' op attribute 'alignment' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive and whose value is a power of two > 0}}
41+
spirv.Store "Function" %0, %arg0 ["Aligned", 3] : f32
42+
return
43+
}

0 commit comments

Comments
 (0)