xref: /llvm-project/mlir/test/Dialect/Vector/vector-bitcast-lowering-transforms.mlir (revision dc5d541081381e3dca80b982097596546e0619fc)
1// RUN: mlir-opt %s --transform-interpreter | FileCheck %s
2
3func.func @vector_bitcast_0d(%arg0: vector<i32>) -> vector<f32> {
4  %0 = vector.bitcast %arg0 : vector<i32> to vector<f32>
5  return %0 : vector<f32>
6}
7// CHECK-LABEL: func.func @vector_bitcast_0d
8// CHECK-SAME:    %[[IN:[a-zA-Z0-9]+]]
9// CHECK:         %[[RES:.+]] = vector.bitcast %[[IN]] : vector<i32> to vector<f32>
10// CHECK:         return %[[RES]]
11
12func.func @vector_bitcast_1d(%arg0: vector<10xi64>) -> vector<20xi32> {
13  %0 = vector.bitcast %arg0 : vector<10xi64> to vector<20xi32>
14  return %0 : vector<20xi32>
15}
16// CHECK-LABEL: func.func @vector_bitcast_1d
17// CHECK-SAME:    %[[IN:[a-zA-Z0-9]+]]
18// CHECK:         %[[RES:.+]] = vector.bitcast %[[IN]] : vector<10xi64> to vector<20xi32>
19// CHECK:         return %[[RES]]
20
21func.func @vector_bitcast_2d(%arg0: vector<2x4xi32>) -> vector<2x2xi64> {
22  %0 = vector.bitcast %arg0 : vector<2x4xi32> to vector<2x2xi64>
23  return %0 : vector<2x2xi64>
24}
25// CHECK-LABEL: func.func @vector_bitcast_2d
26// CHECK-SAME:    %[[IN:[a-zA-Z0-9]+]]
27// CHECK:         %[[INIT:.+]] = arith.constant {{.+}} : vector<2x2xi64>
28// CHECK:         %[[V1:.+]] = vector.extract %[[IN]][0] : vector<4xi32> from vector<2x4xi32>
29// CHECK:         %[[B1:.+]] = vector.bitcast %[[V1]] : vector<4xi32> to vector<2xi64>
30// CHECK:         %[[R1:.+]] = vector.insert %[[B1]], %[[INIT]] [0]
31// CHECK:         %[[V2:.+]] = vector.extract %[[IN]][1] : vector<4xi32> from vector<2x4xi32>
32// CHECK:         %[[B2:.+]] = vector.bitcast %[[V2]] : vector<4xi32> to vector<2xi64>
33// CHECK:         %[[R2:.+]] = vector.insert %[[B2]], %[[R1]] [1]
34// CHECK:         return %[[R2]]
35
36func.func @vector_bitcast_4d_with_scalable_dim(%arg0: vector<1x2x[3]x4xi64>) -> vector<1x2x[3]x8xi32> {
37  %0 = vector.bitcast %arg0 : vector<1x2x[3]x4xi64> to vector<1x2x[3]x8xi32>
38  return %0 : vector<1x2x[3]x8xi32>
39}
40// CHECK-LABEL: func.func @vector_bitcast_4d_with_scalable_dim
41// CHECK-SAME:    %[[IN:[a-zA-Z0-9]+]]
42// CHECK:         %[[INIT:.+]] = arith.constant dense<0> : vector<1x2x[3]x8xi32>
43// CHECK:         %[[V1:.+]] = vector.extract %[[IN]][0, 0] : vector<[3]x4xi64> from vector<1x2x[3]x4xi64>
44// CHECK:         %[[B1:.+]] = vector.bitcast %[[V1]] : vector<[3]x4xi64> to vector<[3]x8xi32>
45// CHECK:         %[[R1:.+]] = vector.insert %[[B1]], %[[INIT]] [0, 0] : vector<[3]x8xi32> into vector<1x2x[3]x8xi32>
46// CHECK:         %[[V2:.+]] = vector.extract %[[IN]][0, 1] : vector<[3]x4xi64> from vector<1x2x[3]x4xi64>
47// CHECK:         %[[B2:.+]] = vector.bitcast %[[V2]] : vector<[3]x4xi64> to vector<[3]x8xi32>
48// CHECK:         %[[R2:.+]] = vector.insert %[[B2]], %[[R1]] [0, 1] : vector<[3]x8xi32> into vector<1x2x[3]x8xi32>
49// CHECK:         return %[[R2]] : vector<1x2x[3]x8xi32>
50
51func.func @vector_bitcast_2d_trailing_scalable_dim(%arg0: vector<2x[2]xi64>) -> vector<2x[4]xi32> {
52  %0 = vector.bitcast %arg0 : vector<2x[2]xi64> to vector<2x[4]xi32>
53  return %0 : vector<2x[4]xi32>
54}
55// CHECK-LABEL: func.func @vector_bitcast_2d_trailing_scalable_dim
56// CHECK-SAME:    %[[IN:[a-zA-Z0-9]+]]
57// CHECK:         %[[INIT:.+]] = arith.constant dense<0> : vector<2x[4]xi32>
58// CHECK:         %[[V1:.+]] = vector.extract %[[IN]][0] : vector<[2]xi64> from vector<2x[2]xi64>
59// CHECK:         %[[B1:.+]] = vector.bitcast %[[V1]] : vector<[2]xi64> to vector<[4]xi32>
60// CHECK:         %[[R1:.+]] = vector.insert %[[B1]], %[[INIT]] [0] : vector<[4]xi32> into vector<2x[4]xi32>
61// CHECK:         %[[V2:.+]] = vector.extract %[[IN]][1] : vector<[2]xi64> from vector<2x[2]xi64>
62// CHECK:         %[[B2:.+]] = vector.bitcast %[[V2]] : vector<[2]xi64> to vector<[4]xi32>
63// CHECK:         %[[R2:.+]] = vector.insert %[[B2]], %[[R1]] [1] : vector<[4]xi32> into vector<2x[4]xi32>
64// CHECK:         return %[[R2]] : vector<2x[4]xi32>
65
66func.func @negative_vector_bitcast_2d_leading_scalable_dim(%arg0: vector<[2]x2xi64>) -> vector<[2]x4xi32>
67{
68  %0 = vector.bitcast %arg0 : vector<[2]x2xi64> to vector<[2]x4xi32>
69  return %0 : vector<[2]x4xi32>
70}
71// CHECK-LABEL: func.func @negative_vector_bitcast_2d_leading_scalable_dim
72// CHECK-NOT: vector.extract
73// CHECK-NOT: vector.insert
74
75module attributes {transform.with_named_sequence} {
76  transform.named_sequence @__transform_main(%module_op: !transform.any_op {transform.readonly}) {
77    %f = transform.structured.match ops{["func.func"]} in %module_op
78      : (!transform.any_op) -> !transform.any_op
79
80    transform.apply_patterns to %f {
81      transform.apply_patterns.vector.lower_bitcast
82    } : !transform.any_op
83    transform.yield
84  }
85}
86