Skip to content

Commit 9958c24

Browse files
committed
[mlir][vector] Add alignment to maskedstore.
1 parent 96ba831 commit 9958c24

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

mlir/include/mlir/Dialect/Vector/IR/VectorOps.td

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1970,7 +1970,9 @@ def Vector_MaskedStoreOp :
19701970
Arguments<(ins Arg<AnyMemRef, "", [MemWrite]>:$base,
19711971
Variadic<Index>:$indices,
19721972
VectorOfNonZeroRankOf<[I1]>:$mask,
1973-
AnyVectorOfNonZeroRank:$valueToStore)> {
1973+
AnyVectorOfNonZeroRank:$valueToStore,
1974+
ConfinedAttr<OptionalAttr<I64Attr>,
1975+
[AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment)> {
19741976

19751977
let summary = "stores elements from a vector into memory as defined by a mask vector";
19761978

@@ -2005,6 +2007,12 @@ def Vector_MaskedStoreOp :
20052007
vector.maskedstore %base[%i, %j], %mask, %value
20062008
: memref<?x?xf32>, vector<16xi1>, vector<16xf32>
20072009
```
2010+
2011+
An optional `alignment` attribute allows to specify the byte alignment of the
2012+
store operation. It must be a positive power of 2. The operation must access
2013+
memory at an address aligned to this boundary. Violations may lead to
2014+
architecture-specific faults or performance penalties.
2015+
A value of 0 indicates no specific alignment requirement.
20082016
}];
20092017
let extraClassDeclaration = [{
20102018
MemRefType getMemRefType() {
@@ -2023,6 +2031,18 @@ def Vector_MaskedStoreOp :
20232031
let hasCanonicalizer = 1;
20242032
let hasFolder = 1;
20252033
let hasVerifier = 1;
2034+
2035+
let builders = [
2036+
OpBuilder<(ins "Value":$base,
2037+
"ValueRange":$indices,
2038+
"Value":$mask,
2039+
"Value":$valueToStore,
2040+
CArg<"uint64_t", "0">:$alignment), [{
2041+
return build($_builder, $_state, base, indices, mask, valueToStore,
2042+
alignment != 0 ? $_builder.getI64IntegerAttr(alignment) :
2043+
nullptr);
2044+
}]>
2045+
];
20262046
}
20272047

20282048
def Vector_GatherOp :

mlir/test/Dialect/Vector/invalid.mlir

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,28 @@ func.func @maskedload_memref_mismatch(%base: memref<?xf32>, %mask: vector<16xi1>
13581358

13591359
// -----
13601360

1361+
//===----------------------------------------------------------------------===//
1362+
// vector.maskedstore
1363+
//===----------------------------------------------------------------------===//
1364+
1365+
func.func @maskedstore_negative_alignment(%base: memref<?xf32>, %mask: vector<16xi1>, %value: vector<16xf32>) {
1366+
%c0 = arith.constant 0 : index
1367+
// expected-error@+1 {{'vector.maskedstore' op attribute 'alignment' failed to satisfy constraint: 64-bit signless integer attribute whose value is positive and whose value is a power of two > 0}}
1368+
vector.maskedstore %base[%c0], %mask, %value { alignment = -1 } : memref<?xf32>, vector<16xi1>, vector<16xf32> into vector<16xf32>
1369+
return
1370+
}
1371+
1372+
// -----
1373+
1374+
func.func @maskedload_nonpower2_alignment(%base: memref<?xf32>, %mask: vector<16xi1>, %value: vector<16xf32>) {
1375+
%c0 = arith.constant 0 : index
1376+
// expected-error@+1 {{'vector.maskedstore' op attribute 'alignment' failed to satisfy constraint: 64-bit signless integer attribute whose value is positive and whose value is a power of two > 0}}
1377+
vector.maskedstore %base[%c0], %mask, %value { alignment = 3 } : memref<?xf32>, vector<16xi1>, vector<16xf32> into vector<16xf32>
1378+
return
1379+
}
1380+
1381+
// -----
1382+
13611383
func.func @maskedstore_base_type_mismatch(%base: memref<?xf64>, %mask: vector<16xi1>, %value: vector<16xf32>) {
13621384
%c0 = arith.constant 0 : index
13631385
// expected-error@+1 {{'vector.maskedstore' op base and valueToStore element type should match}}

0 commit comments

Comments
 (0)