xref: /llvm-project/mlir/test/Integration/Dialect/Vector/CPU/0-d-vectors.mlir (revision eb206e9ea84eff0a0596fed2de8316d924f946d1)
1// RUN: mlir-opt %s -test-lower-to-llvm | \
2// RUN: mlir-runner -e entry -entry-point-result=void \
3// RUN:   -shared-libs=%mlir_c_runner_utils | \
4// RUN: FileCheck %s
5
6func.func @extract_element_0d(%a: vector<f32>) {
7  %1 = vector.extractelement %a[] : vector<f32>
8  // CHECK: 42
9  vector.print %1: f32
10  return
11}
12
13func.func @insert_element_0d(%a: f32, %b: vector<f32>) -> (vector<f32>) {
14  %1 = vector.insertelement %a, %b[] : vector<f32>
15  return %1: vector<f32>
16}
17
18func.func @print_vector_0d(%a: vector<f32>) {
19  // CHECK: ( 42 )
20  vector.print %a: vector<f32>
21  return
22}
23
24func.func @splat_0d(%a: f32) {
25  %1 = vector.splat %a : vector<f32>
26  // CHECK: ( 42 )
27  vector.print %1: vector<f32>
28  return
29}
30
31func.func @broadcast_0d(%a: f32) {
32  %1 = vector.broadcast %a : f32 to vector<f32>
33  // CHECK: ( 42 )
34  vector.print %1: vector<f32>
35
36  %2 = vector.broadcast %1 : vector<f32> to vector<f32>
37  // CHECK: ( 42 )
38  vector.print %2: vector<f32>
39
40  %3 = vector.broadcast %1 : vector<f32> to vector<1xf32>
41  // CHECK: ( 42 )
42  vector.print %3: vector<1xf32>
43
44  %4 = vector.broadcast %1 : vector<f32> to vector<2xf32>
45  // CHECK: ( 42, 42 )
46  vector.print %4: vector<2xf32>
47
48  %5 = vector.broadcast %1 : vector<f32> to vector<2x1xf32>
49  // CHECK: ( ( 42 ), ( 42 ) )
50  vector.print %5: vector<2x1xf32>
51
52  %6 = vector.broadcast %1 : vector<f32> to vector<2x3xf32>
53  // CHECK: ( ( 42, 42, 42 ), ( 42, 42, 42 ) )
54  vector.print %6: vector<2x3xf32>
55  return
56}
57
58func.func @bitcast_0d() {
59  %0 = arith.constant 42 : i32
60  %1 = arith.constant dense<0> : vector<i32>
61  %2 = vector.insertelement %0, %1[] : vector<i32>
62  %3 = vector.bitcast %2 : vector<i32> to vector<f32>
63  %4 = vector.extractelement %3[] : vector<f32>
64  %5 = arith.bitcast %4 : f32 to i32
65  // CHECK: 42
66  vector.print %5: i32
67  return
68}
69
70func.func @constant_mask_0d() {
71  %1 = vector.constant_mask [0] : vector<i1>
72  // CHECK: ( 0 )
73  vector.print %1: vector<i1>
74  %2 = vector.constant_mask [1] : vector<i1>
75  // CHECK: ( 1 )
76  vector.print %2: vector<i1>
77  return
78}
79
80func.func @arith_cmpi_0d(%smaller : vector<i32>, %bigger : vector<i32>) {
81  %0 = arith.cmpi ult, %smaller, %bigger : vector<i32>
82  // CHECK: ( 1 )
83  vector.print %0: vector<i1>
84
85  %1 = arith.cmpi ugt, %smaller, %bigger : vector<i32>
86  // CHECK: ( 0 )
87  vector.print %1: vector<i1>
88
89  %2 = arith.cmpi eq, %smaller, %bigger : vector<i32>
90  // CHECK: ( 0 )
91  vector.print %2: vector<i1>
92
93  return
94}
95
96func.func @create_mask_0d(%zero : index, %one : index) {
97  %zero_mask = vector.create_mask %zero : vector<i1>
98  // CHECK: ( 0 )
99  vector.print %zero_mask : vector<i1>
100
101  %one_mask = vector.create_mask %one : vector<i1>
102  // CHECK: ( 1 )
103  vector.print %one_mask : vector<i1>
104
105  return
106}
107
108func.func @reduce_add(%arg0: vector<f32>) {
109  %0 = vector.reduction <add>, %arg0 : vector<f32> into f32
110  vector.print %0 : f32
111  // CHECK: 5
112  return
113}
114
115func.func @fma_0d(%four: vector<f32>) {
116  %0 = vector.fma %four, %four, %four : vector<f32>
117  // 4 * 4 + 4 = 20
118  // CHECK: ( 20 )
119  vector.print %0: vector<f32>
120  return
121}
122
123func.func @transpose_0d(%arg: vector<i32>) {
124  %1 = vector.transpose %arg, [] : vector<i32> to vector<i32>
125  // CHECK: ( 42 )
126  vector.print %1: vector<i32>
127  return
128}
129
130func.func @shuffle_0d(%v0: vector<i32>, %v1: vector<i32>) {
131  %1 = vector.shuffle %v0, %v1 [0, 1, 0] : vector<i32>, vector<i32>
132  // CHECK: ( 42, 43, 42 )
133  vector.print %1: vector<3xi32>
134  return
135}
136
137func.func @entry() {
138  %0 = arith.constant 42.0 : f32
139  %1 = arith.constant dense<0.0> : vector<f32>
140  %2 = call  @insert_element_0d(%0, %1) : (f32, vector<f32>) -> (vector<f32>)
141  call  @extract_element_0d(%2) : (vector<f32>) -> ()
142
143  %3 = arith.constant dense<42.0> : vector<f32>
144  call  @print_vector_0d(%3) : (vector<f32>) -> ()
145
146  %4 = arith.constant 42.0 : f32
147
148  // Warning: these must be called in their textual order of definition in the
149  // file to not mess up FileCheck.
150  call  @splat_0d(%4) : (f32) -> ()
151  call  @broadcast_0d(%4) : (f32) -> ()
152  call  @bitcast_0d() : () -> ()
153  call  @constant_mask_0d() : () -> ()
154
155  %smaller = arith.constant dense<42> : vector<i32>
156  %bigger = arith.constant dense<4242> : vector<i32>
157  call  @arith_cmpi_0d(%smaller, %bigger) : (vector<i32>, vector<i32>) -> ()
158
159  %zero_idx = arith.constant 0 : index
160  %one_idx = arith.constant 1 : index
161  call  @create_mask_0d(%zero_idx, %one_idx) : (index, index) -> ()
162
163  %red_array = arith.constant dense<5.0> : vector<f32>
164  call  @reduce_add(%red_array) : (vector<f32>) -> ()
165
166  %5 = arith.constant dense<4.0> : vector<f32>
167  call  @fma_0d(%5) : (vector<f32>) -> ()
168  %6 = arith.constant dense<42> : vector<i32>
169  %7 = arith.constant dense<43> : vector<i32>
170  call @transpose_0d(%6) : (vector<i32>) -> ()
171  call @shuffle_0d(%6, %7) : (vector<i32>, vector<i32>) -> ()
172
173  return
174}
175