Skip to content

[mlir][vector] Add more tests for ConvertVectorToLLVM (11/n) #117160

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

Conversation

banach-space
Copy link
Contributor

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Nov 21, 2024

@llvm/pr-subscribers-mlir

Author: Andrzej Warzyński (banach-space)

Changes

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.

Full diff: https://github.com/llvm/llvm-project/pull/117160.diff

1 Files Affected:

  • (modified) mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir (+49-20)
diff --git a/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir b/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
index da0222bc942376..1c42538cf85912 100644
--- a/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
+++ b/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
@@ -78,6 +78,38 @@ func.func @bitcast_index_to_i8_vector_scalable(%input: vector<[16]xindex>) -> ve
 
 // -----
 
+// CHECK-LABEL:   func.func @bitcast_2d(
+// CHECK-SAME:      %[[ARG_0:.*]]: vector<2x4xi32>) -> vector<2x2xi64> {
+// CHECK:           %[[T0:.*]] = builtin.unrealized_conversion_cast %[[ARG_0]] : vector<2x4xi32> to !llvm.array<2 x vector<4xi32>>
+// CHECK:           %[[VEC_1:.*]] = llvm.extractvalue %[[T0]][0] : !llvm.array<2 x vector<4xi32>>
+// CHECK:           %[[BCAST_1:.*]] = llvm.bitcast %[[VEC_1]] : vector<4xi32> to vector<2xi64>
+// CHECK:           %[[OUT_1:.*]] = llvm.insertvalue %[[BCAST_1]], {{.*}}[0] : !llvm.array<2 x vector<2xi64>>
+// CHECK:           %[[VEC_2:.*]] = llvm.extractvalue %[[T0]][1] : !llvm.array<2 x vector<4xi32>>
+// CHECK:           %[[BCAST_2:.*]] = llvm.bitcast %[[VEC_2]] : vector<4xi32> to vector<2xi64>
+// CHECK:           %[[OUT_2:.*]] = llvm.insertvalue %[[BCAST_2]], %[[OUT_1]][1] : !llvm.array<2 x vector<2xi64>>
+func.func @bitcast_2d(%arg0: vector<2x4xi32>) -> vector<2x2xi64> {
+  %0 = vector.bitcast %arg0 : vector<2x4xi32> to vector<2x2xi64>
+  return %0 : vector<2x2xi64>
+}
+
+// -----
+
+// CHECK-LABEL:   func.func @bitcast_2d_scalable(
+// CHECK-SAME:      %[[ARG_0:.*]]: vector<2x[4]xi32>) -> vector<2x[2]xi64> {
+// CHECK:           %[[T0:.*]] = builtin.unrealized_conversion_cast %[[ARG_0]] : vector<2x[4]xi32> to !llvm.array<2 x vector<[4]xi32>>
+// CHECK:           %[[VEC_1:.*]] = llvm.extractvalue %[[T0]][0] : !llvm.array<2 x vector<[4]xi32>>
+// CHECK:           %[[BCAST_1:.*]] = llvm.bitcast %[[VEC_1]] : vector<[4]xi32> to vector<[2]xi64>
+// CHECK:           %[[OUT_1:.*]] = llvm.insertvalue %[[BCAST_1]], {{.*}}[0] : !llvm.array<2 x vector<[2]xi64>>
+// CHECK:           %[[VEC_2:.*]] = llvm.extractvalue %[[T0]][1] : !llvm.array<2 x vector<[4]xi32>>
+// CHECK:           %[[BCAST_2:.*]] = llvm.bitcast %[[VEC_2]] : vector<[4]xi32> to vector<[2]xi64>
+// CHECK:           %[[OUT_2:.*]] = llvm.insertvalue %[[BCAST_2]], %[[OUT_1]][1] : !llvm.array<2 x vector<[2]xi64>>
+func.func @bitcast_2d_scalable(%arg0: vector<2x[4]xi32>) -> vector<2x[2]xi64> {
+  %0 = vector.bitcast %arg0 : vector<2x[4]xi32> to vector<2x[2]xi64>
+  return %0 : vector<2x[2]xi64>
+}
+
+// -----
+
 func.func @broadcast_vec0d_from_f32(%arg0: f32) -> vector<f32> {
   %0 = vector.broadcast %arg0 : f32 to vector<f32>
   return %0 : vector<f32>
@@ -3520,6 +3552,23 @@ func.func @splat(%a: vector<4xf32>, %b: f32) -> vector<4xf32> {
 
 // -----
 
+// CHECK-LABEL: @splat_scalable
+// CHECK-SAME: %[[A:arg[0-9]+]]: vector<[4]xf32>
+// CHECK-SAME: %[[ELT:arg[0-9]+]]: f32
+func.func @splat_scalable(%a: vector<[4]xf32>, %b: f32) -> vector<[4]xf32> {
+  %vb = vector.splat %b : vector<[4]xf32>
+  %r = arith.mulf %a, %vb : vector<[4]xf32>
+  return %r : vector<[4]xf32>
+}
+// CHECK-NEXT: %[[UNDEF:[0-9]+]] = llvm.mlir.undef : vector<[4]xf32>
+// CHECK-NEXT: %[[ZERO:[0-9]+]] = llvm.mlir.constant(0 : i32) : i32
+// CHECK-NEXT: %[[V:[0-9]+]] = llvm.insertelement %[[ELT]], %[[UNDEF]][%[[ZERO]] : i32] : vector<[4]xf32>
+// CHECK-NEXT: %[[SPLAT:[0-9]+]] = llvm.shufflevector %[[V]], %[[UNDEF]] [0, 0, 0, 0]
+// CHECK-NEXT: %[[SCALE:[0-9]+]] = arith.mulf %[[A]], %[[SPLAT]] : vector<[4]xf32>
+// CHECK-NEXT: return %[[SCALE]] : vector<[4]xf32>
+
+// -----
+
 // CHECK-LABEL: @vector_scalable_insert
 // CHECK-SAME: %[[SUB:.*]]: vector<4xf32>, %[[SV:.*]]: vector<[4]xf32>
 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> {
 
 // -----
 
-// CHECK-LABEL: @make_fixed_vector_of_scalable_vector
-func.func @make_fixed_vector_of_scalable_vector(%f : f64) -> vector<3x[2]xf64>
-{
-  // CHECK: %{{.*}} = llvm.mlir.undef : !llvm.array<3 x vector<[2]xf64>>
-  %res = vector.broadcast %f : f64 to vector<3x[2]xf64>
-  return %res : vector<3x[2]xf64>
-}
-
-// -----
-
 // CHECK-LABEL: @vector_interleave_0d
 //  CHECK-SAME:     %[[LHS:.*]]: vector<i8>, %[[RHS:.*]]: vector<i8>)
 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[
 
 // -----
 
-// CHECK-LABEL: func.func @vector_bitcast_2d
-// CHECK:         llvm.bitcast
-// CHECK-NOT:     vector.bitcast
-func.func @vector_bitcast_2d(%arg0: vector<2x4xi32>) -> vector<2x2xi64> {
-  %0 = vector.bitcast %arg0 : vector<2x4xi32> to vector<2x2xi64>
-  return %0 : vector<2x2xi64>
-}
-
-// -----
-
 // CHECK-LABEL: func.func @vector_from_elements_1d(
 //  CHECK-SAME:     %[[a:.*]]: f32, %[[b:.*]]: f32)
 //       CHECK:   %[[undef:.*]] = llvm.mlir.undef : vector<3xf32>

Copy link
Contributor

@dcaballe dcaballe left a comment

Choose a reason for hiding this comment

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

Thanks! LG

@banach-space banach-space merged commit 204d715 into llvm:main Nov 27, 2024
10 checks passed
@banach-space banach-space deleted the andrzej/extend_vector_to_llvm_test_12 branch November 27, 2024 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants