Skip to content

Commit 204d715

Browse files
authored
[mlir][vector] Add more tests for ConvertVectorToLLVM (11/n) (#117160)
Adds tests with scalable vectors for the Vector-To-LLVM conversion pass. Covers the following Ops: * `vector.splat`. In addition: * Removed `@make_fixed_vector_of_scalable_vect`, which duplicated `@broadcast_vec2d_from_scalar_scalable` (and wasn't grouped with other tests for `vector.broadcast`). * Moved `@vector_bitcast_2d` near other tests for `vector.bitcast` and added a variant with scalable vectors.
1 parent e636434 commit 204d715

File tree

1 file changed

+49
-20
lines changed

1 file changed

+49
-20
lines changed

mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,38 @@ func.func @bitcast_index_to_i8_vector_scalable(%input: vector<[16]xindex>) -> ve
7878

7979
// -----
8080

81+
// CHECK-LABEL: func.func @bitcast_2d(
82+
// CHECK-SAME: %[[ARG_0:.*]]: vector<2x4xi32>) -> vector<2x2xi64> {
83+
// CHECK: %[[T0:.*]] = builtin.unrealized_conversion_cast %[[ARG_0]] : vector<2x4xi32> to !llvm.array<2 x vector<4xi32>>
84+
// CHECK: %[[VEC_1:.*]] = llvm.extractvalue %[[T0]][0] : !llvm.array<2 x vector<4xi32>>
85+
// CHECK: %[[BCAST_1:.*]] = llvm.bitcast %[[VEC_1]] : vector<4xi32> to vector<2xi64>
86+
// CHECK: %[[OUT_1:.*]] = llvm.insertvalue %[[BCAST_1]], {{.*}}[0] : !llvm.array<2 x vector<2xi64>>
87+
// CHECK: %[[VEC_2:.*]] = llvm.extractvalue %[[T0]][1] : !llvm.array<2 x vector<4xi32>>
88+
// CHECK: %[[BCAST_2:.*]] = llvm.bitcast %[[VEC_2]] : vector<4xi32> to vector<2xi64>
89+
// CHECK: %[[OUT_2:.*]] = llvm.insertvalue %[[BCAST_2]], %[[OUT_1]][1] : !llvm.array<2 x vector<2xi64>>
90+
func.func @bitcast_2d(%arg0: vector<2x4xi32>) -> vector<2x2xi64> {
91+
%0 = vector.bitcast %arg0 : vector<2x4xi32> to vector<2x2xi64>
92+
return %0 : vector<2x2xi64>
93+
}
94+
95+
// -----
96+
97+
// CHECK-LABEL: func.func @bitcast_2d_scalable(
98+
// CHECK-SAME: %[[ARG_0:.*]]: vector<2x[4]xi32>) -> vector<2x[2]xi64> {
99+
// CHECK: %[[T0:.*]] = builtin.unrealized_conversion_cast %[[ARG_0]] : vector<2x[4]xi32> to !llvm.array<2 x vector<[4]xi32>>
100+
// CHECK: %[[VEC_1:.*]] = llvm.extractvalue %[[T0]][0] : !llvm.array<2 x vector<[4]xi32>>
101+
// CHECK: %[[BCAST_1:.*]] = llvm.bitcast %[[VEC_1]] : vector<[4]xi32> to vector<[2]xi64>
102+
// CHECK: %[[OUT_1:.*]] = llvm.insertvalue %[[BCAST_1]], {{.*}}[0] : !llvm.array<2 x vector<[2]xi64>>
103+
// CHECK: %[[VEC_2:.*]] = llvm.extractvalue %[[T0]][1] : !llvm.array<2 x vector<[4]xi32>>
104+
// CHECK: %[[BCAST_2:.*]] = llvm.bitcast %[[VEC_2]] : vector<[4]xi32> to vector<[2]xi64>
105+
// CHECK: %[[OUT_2:.*]] = llvm.insertvalue %[[BCAST_2]], %[[OUT_1]][1] : !llvm.array<2 x vector<[2]xi64>>
106+
func.func @bitcast_2d_scalable(%arg0: vector<2x[4]xi32>) -> vector<2x[2]xi64> {
107+
%0 = vector.bitcast %arg0 : vector<2x[4]xi32> to vector<2x[2]xi64>
108+
return %0 : vector<2x[2]xi64>
109+
}
110+
111+
// -----
112+
81113
func.func @broadcast_vec0d_from_f32(%arg0: f32) -> vector<f32> {
82114
%0 = vector.broadcast %arg0 : f32 to vector<f32>
83115
return %0 : vector<f32>
@@ -3520,6 +3552,23 @@ func.func @splat(%a: vector<4xf32>, %b: f32) -> vector<4xf32> {
35203552

35213553
// -----
35223554

3555+
// CHECK-LABEL: @splat_scalable
3556+
// CHECK-SAME: %[[A:arg[0-9]+]]: vector<[4]xf32>
3557+
// CHECK-SAME: %[[ELT:arg[0-9]+]]: f32
3558+
func.func @splat_scalable(%a: vector<[4]xf32>, %b: f32) -> vector<[4]xf32> {
3559+
%vb = vector.splat %b : vector<[4]xf32>
3560+
%r = arith.mulf %a, %vb : vector<[4]xf32>
3561+
return %r : vector<[4]xf32>
3562+
}
3563+
// CHECK-NEXT: %[[UNDEF:[0-9]+]] = llvm.mlir.undef : vector<[4]xf32>
3564+
// CHECK-NEXT: %[[ZERO:[0-9]+]] = llvm.mlir.constant(0 : i32) : i32
3565+
// CHECK-NEXT: %[[V:[0-9]+]] = llvm.insertelement %[[ELT]], %[[UNDEF]][%[[ZERO]] : i32] : vector<[4]xf32>
3566+
// CHECK-NEXT: %[[SPLAT:[0-9]+]] = llvm.shufflevector %[[V]], %[[UNDEF]] [0, 0, 0, 0]
3567+
// CHECK-NEXT: %[[SCALE:[0-9]+]] = arith.mulf %[[A]], %[[SPLAT]] : vector<[4]xf32>
3568+
// CHECK-NEXT: return %[[SCALE]] : vector<[4]xf32>
3569+
3570+
// -----
3571+
35233572
// CHECK-LABEL: @vector_scalable_insert
35243573
// CHECK-SAME: %[[SUB:.*]]: vector<4xf32>, %[[SV:.*]]: vector<[4]xf32>
35253574
func.func @vector_scalable_insert(%sub: vector<4xf32>, %dsv: vector<[4]xf32>) -> vector<[4]xf32> {
@@ -3542,16 +3591,6 @@ func.func @vector_scalable_extract(%vec: vector<[4]xf32>) -> vector<8xf32> {
35423591

35433592
// -----
35443593

3545-
// CHECK-LABEL: @make_fixed_vector_of_scalable_vector
3546-
func.func @make_fixed_vector_of_scalable_vector(%f : f64) -> vector<3x[2]xf64>
3547-
{
3548-
// CHECK: %{{.*}} = llvm.mlir.undef : !llvm.array<3 x vector<[2]xf64>>
3549-
%res = vector.broadcast %f : f64 to vector<3x[2]xf64>
3550-
return %res : vector<3x[2]xf64>
3551-
}
3552-
3553-
// -----
3554-
35553594
// CHECK-LABEL: @vector_interleave_0d
35563595
// CHECK-SAME: %[[LHS:.*]]: vector<i8>, %[[RHS:.*]]: vector<i8>)
35573596
func.func @vector_interleave_0d(%a: vector<i8>, %b: vector<i8>) -> vector<2xi8> {
@@ -3647,16 +3686,6 @@ func.func @vector_deinterleave_2d_scalable(%a: vector<2x[8]xf32>) -> (vector<2x[
36473686

36483687
// -----
36493688

3650-
// CHECK-LABEL: func.func @vector_bitcast_2d
3651-
// CHECK: llvm.bitcast
3652-
// CHECK-NOT: vector.bitcast
3653-
func.func @vector_bitcast_2d(%arg0: vector<2x4xi32>) -> vector<2x2xi64> {
3654-
%0 = vector.bitcast %arg0 : vector<2x4xi32> to vector<2x2xi64>
3655-
return %0 : vector<2x2xi64>
3656-
}
3657-
3658-
// -----
3659-
36603689
// CHECK-LABEL: func.func @vector_from_elements_1d(
36613690
// CHECK-SAME: %[[a:.*]]: f32, %[[b:.*]]: f32)
36623691
// CHECK: %[[undef:.*]] = llvm.mlir.undef : vector<3xf32>

0 commit comments

Comments
 (0)