Skip to content

Commit 5a47fff

Browse files
committed
[mlir][vector] Add alignment to expandload
1 parent 2b51236 commit 5a47fff

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2175,7 +2175,9 @@ def Vector_ExpandLoadOp :
21752175
Arguments<(ins Arg<AnyMemRef, "", [MemRead]>:$base,
21762176
Variadic<Index>:$indices,
21772177
FixedVectorOfNonZeroRankOf<[I1]>:$mask,
2178-
AnyVectorOfNonZeroRank:$pass_thru)>,
2178+
AnyVectorOfNonZeroRank:$pass_thru,
2179+
ConfinedAttr<OptionalAttr<I64Attr>,
2180+
[AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment)>,
21792181
Results<(outs AnyVectorOfNonZeroRank:$result)> {
21802182

21812183
let summary = "reads elements from memory and spreads them into a vector as defined by a mask";
@@ -2237,6 +2239,29 @@ def Vector_ExpandLoadOp :
22372239
"type($base) `,` type($mask) `,` type($pass_thru) `into` type($result)";
22382240
let hasCanonicalizer = 1;
22392241
let hasVerifier = 1;
2242+
2243+
let builders = [
2244+
OpBuilder<(ins "VectorType":$resultType,
2245+
"Value":$base,
2246+
"ValueRange":$indices,
2247+
"Value":$mask,
2248+
"Value":$passthrough,
2249+
CArg<"llvm::Align", "llvm::Align()">:$alignment), [{
2250+
return build($_builder, $_state, resultType, base, indices, mask, passthrough,
2251+
alignment != llvm::Align() ? $_builder.getI64IntegerAttr(alignment.value()) :
2252+
nullptr);
2253+
}]>,
2254+
OpBuilder<(ins "TypeRange":$resultTypes,
2255+
"Value":$base,
2256+
"ValueRange":$indices,
2257+
"Value":$mask,
2258+
"Value":$passthrough,
2259+
CArg<"llvm::Align", "llvm::Align()">:$alignment), [{
2260+
return build($_builder, $_state, resultTypes, base, indices, mask, passthrough,
2261+
alignment != llvm::Align() ? $_builder.getI64IntegerAttr(alignment.value()) :
2262+
nullptr);
2263+
}]>
2264+
];
22402265
}
22412266

22422267
def Vector_CompressStoreOp :

mlir/test/Dialect/Vector/invalid.mlir

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,20 @@ func.func @expand_memref_mismatch(%base: memref<?x?xf32>, %mask: vector<16xi1>,
15671567

15681568
// -----
15691569

1570+
func.func @expand_invalid_alignment(%base: memref<?xf32>, %mask: vector<16xi1>, %pass_thru: vector<16xf32>, %c0: index) {
1571+
// expected-error@+1 {{'vector.expandload' 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}}
1572+
%0 = vector.expandload %base[%c0], %mask, %pass_thru { alignment = -1 } : memref<?xf32>, vector<16xi1>, vector<16xf32> into vector<16xf32>
1573+
}
1574+
1575+
// -----
1576+
1577+
func.func @expand_invalid_alignment(%base: memref<?xf32>, %mask: vector<16xi1>, %pass_thru: vector<16xf32>, %c0: index) {
1578+
// expected-error@+1 {{'vector.expandload' 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}}
1579+
%0 = vector.expandload %base[%c0], %mask, %pass_thru { alignment = 3 } : memref<?xf32>, vector<16xi1>, vector<16xf32> into vector<16xf32>
1580+
}
1581+
1582+
// -----
1583+
15701584
func.func @compress_base_type_mismatch(%base: memref<?xf64>, %mask: vector<16xi1>, %value: vector<16xf32>) {
15711585
%c0 = arith.constant 0 : index
15721586
// expected-error@+1 {{'vector.compressstore' op base and valueToStore element type should match}}

0 commit comments

Comments
 (0)