Skip to content

[mlir][vector] Relax operand type restrictions for vector.splat #145517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -2920,8 +2920,8 @@ def Vector_SplatOp : Vector_Op<"splat", [
]> {
let summary = "vector splat or broadcast operation";
let description = [{
Broadcast the operand to all elements of the result vector. The operand is
required to be of integer/index/float type.
Broadcast the operand to all elements of the result vector. The type of the
operand must match the element type of the vector type.

Example:

Expand All @@ -2931,8 +2931,7 @@ def Vector_SplatOp : Vector_Op<"splat", [
```
}];

let arguments = (ins AnyTypeOf<[AnySignlessInteger, Index, AnyFloat],
"integer/index/float type">:$input);
let arguments = (ins AnyType:$input);
let results = (outs AnyVectorOfAnyRank:$aggregate);

let builders = [
Expand Down
9 changes: 9 additions & 0 deletions mlir/test/Dialect/Vector/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,15 @@ func.func @flat_transpose_scalable(%arg0: vector<[16]xf32>) -> vector<[16]xf32>

// -----

// expected-note @+1 {{prior use here}}
func.func @vector_splat_type_mismatch(%a: f32) {
// expected-error @+1 {{expects different type than prior uses: 'i32' vs 'f32'}}
%0 = vector.splat %a : vector<1xi32>
return
}
Comment on lines +1978 to +1983
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[ultra-nit] #145699 :)


// -----

//===----------------------------------------------------------------------===//
// vector.load
//===----------------------------------------------------------------------===//
Expand Down
17 changes: 11 additions & 6 deletions mlir/test/Dialect/Vector/ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func.func @vector_transfer_ops_tensor(%arg0: tensor<?x?xf32>,
}

// CHECK-LABEL: @vector_broadcast
func.func @vector_broadcast(%a: f32, %b: vector<f32>, %c: vector<16xf32>, %d: vector<1x16xf32>, %e: vector<8x1xf32>) -> vector<8x16xf32> {
func.func @vector_broadcast(%a: f32, %b: vector<f32>, %c: vector<16xf32>, %d: vector<1x16xf32>, %e: vector<8x1xf32>, %f: vector<8x1x!llvm.ptr<1>>) {
// CHECK: vector.broadcast %{{.*}} : f32 to vector<f32>
%0 = vector.broadcast %a : f32 to vector<f32>
// CHECK: vector.broadcast %{{.*}} : vector<f32> to vector<4xf32>
Expand All @@ -162,7 +162,9 @@ func.func @vector_broadcast(%a: f32, %b: vector<f32>, %c: vector<16xf32>, %d: ve
%4 = vector.broadcast %d : vector<1x16xf32> to vector<8x16xf32>
// CHECK-NEXT: vector.broadcast %{{.*}} : vector<8x1xf32> to vector<8x16xf32>
%5 = vector.broadcast %e : vector<8x1xf32> to vector<8x16xf32>
return %4 : vector<8x16xf32>
// CHECK-NEXT: vector.broadcast %{{.*}} : vector<8x1x!llvm.ptr<1>> to vector<8x16x!llvm.ptr<1>>
%6 = vector.broadcast %f : vector<8x1x!llvm.ptr<1>> to vector<8x16x!llvm.ptr<1>>
return
}

// CHECK-LABEL: @shuffle0D
Expand Down Expand Up @@ -959,13 +961,16 @@ func.func @vector_scan(%0: vector<4x8x16x32xf32>) -> vector<4x8x16x32xf32> {
}

// CHECK-LABEL: func @test_splat_op
// CHECK-SAME: [[S:%arg[0-9]+]]: f32
func.func @test_splat_op(%s : f32) {
// CHECK: vector.splat [[S]] : vector<8xf32>
// CHECK-SAME: %[[s:.*]]: f32, %[[s2:.*]]: !llvm.ptr<1>
func.func @test_splat_op(%s : f32, %s2 : !llvm.ptr<1>) {
// CHECK: vector.splat %[[s]] : vector<8xf32>
%v = vector.splat %s : vector<8xf32>

// CHECK: vector.splat [[S]] : vector<4xf32>
// CHECK: vector.splat %[[s]] : vector<4xf32>
%u = "vector.splat"(%s) : (f32) -> vector<4xf32>

// CHECK: vector.splat %[[s2]] : vector<16x!llvm.ptr<1>>
%w = vector.splat %s2 : vector<16x!llvm.ptr<1>>
return
}

Expand Down