1// RUN: mlir-opt %s -test-vector-to-vector-conversion | FileCheck %s
2
3//
4// TODO: optimize this one too!
5//
6// CHECK-LABEL: func @maskedload0(
7// CHECK-SAME: %[[A0:.*]]: memref<?xf32>,
8// CHECK-SAME: %[[A1:.*]]: vector<16xf32>)
9// CHECK-NEXT: %[[M:.*]] = vector.constant_mask
10// CHECK-NEXT: %[[T:.*]] = vector.maskedload %[[A0]], %[[M]], %[[A1]] : memref<?xf32>, vector<16xi1>, vector<16xf32> into vector<16xf32>
11// CHECK-NEXT: return %[[T]] : vector<16xf32>
12
13func @maskedload0(%base: memref<?xf32>, %pass_thru: vector<16xf32>) -> vector<16xf32> {
14  %mask = vector.constant_mask [16] : vector<16xi1>
15  %ld = vector.maskedload %base, %mask, %pass_thru
16    : memref<?xf32>, vector<16xi1>, vector<16xf32> into vector<16xf32>
17  return %ld : vector<16xf32>
18}
19
20// CHECK-LABEL: func @maskedload1(
21// CHECK-SAME: %[[A0:.*]]: memref<16xf32>,
22// CHECK-SAME: %[[A1:.*]]: vector<16xf32>)
23// CHECK-NEXT: %[[T0:.*]] = vector.type_cast %[[A0]] : memref<16xf32> to memref<vector<16xf32>>
24// CHECK-NEXT: %[[T1:.*]] = load %[[T0]][] : memref<vector<16xf32>>
25// CHECK-NEXT: return %[[T1]] : vector<16xf32>
26
27func @maskedload1(%base: memref<16xf32>, %pass_thru: vector<16xf32>) -> vector<16xf32> {
28  %mask = vector.constant_mask [16] : vector<16xi1>
29  %ld = vector.maskedload %base, %mask, %pass_thru
30    : memref<16xf32>, vector<16xi1>, vector<16xf32> into vector<16xf32>
31  return %ld : vector<16xf32>
32}
33
34// CHECK-LABEL: func @maskedload2(
35// CHECK-SAME: %[[A0:.*]]: memref<16xf32>,
36// CHECK-SAME: %[[A1:.*]]: vector<16xf32>)
37// CHECK-NEXT: return %[[A1]] : vector<16xf32>
38
39func @maskedload2(%base: memref<16xf32>, %pass_thru: vector<16xf32>) -> vector<16xf32> {
40  %mask = vector.constant_mask [0] : vector<16xi1>
41  %ld = vector.maskedload %base, %mask, %pass_thru
42    : memref<16xf32>, vector<16xi1>, vector<16xf32> into vector<16xf32>
43  return %ld : vector<16xf32>
44}
45
46// CHECK-LABEL: func @maskedstore1(
47// CHECK-SAME: %[[A0:.*]]: memref<16xf32>,
48// CHECK-SAME: %[[A1:.*]]: vector<16xf32>)
49// CHECK-NEXT: %[[T0:.*]] = vector.type_cast %[[A0]] : memref<16xf32> to memref<vector<16xf32>>
50// CHECK-NEXT: store %[[A1]], %[[T0]][] : memref<vector<16xf32>>
51// CHECK-NEXT: return
52
53func @maskedstore1(%base: memref<16xf32>, %value: vector<16xf32>) {
54  %mask = vector.constant_mask [16] : vector<16xi1>
55  vector.maskedstore %base, %mask, %value
56    : vector<16xi1>, vector<16xf32> into memref<16xf32>
57  return
58}
59
60// CHECK-LABEL: func @maskedstore2(
61// CHECK-SAME: %[[A0:.*]]: memref<16xf32>,
62// CHECK-SAME: %[[A1:.*]]: vector<16xf32>)
63// CHECK-NEXT: return
64
65func @maskedstore2(%base: memref<16xf32>, %value: vector<16xf32>)  {
66  %mask = vector.constant_mask [0] : vector<16xi1>
67  vector.maskedstore %base, %mask, %value
68    : vector<16xi1>, vector<16xf32> into memref<16xf32>
69  return
70}
71
72// CHECK-LABEL: func @gather1(
73// CHECK-SAME: %[[A0:.*]]: memref<16xf32>,
74// CHECK-SAME: %[[A1:.*]]: vector<16xi32>,
75// CHECK-SAME: %[[A2:.*]]: vector<16xf32>)
76// CHECK-NEXT: %[[T0:.*]] = vector.constant_mask [16] : vector<16xi1>
77// CHECK-NEXT: %[[T1:.*]] = vector.gather %[[A0]], %[[A1]], %[[T0]], %[[A2]] : (memref<16xf32>, vector<16xi32>, vector<16xi1>, vector<16xf32>) -> vector<16xf32>
78// CHECK-NEXT: return %1 : vector<16xf32>
79
80func @gather1(%base: memref<16xf32>, %indices: vector<16xi32>, %pass_thru: vector<16xf32>) -> vector<16xf32> {
81  %mask = vector.constant_mask [16] : vector<16xi1>
82  %ld = vector.gather %base, %indices, %mask, %pass_thru
83    : (memref<16xf32>, vector<16xi32>, vector<16xi1>, vector<16xf32>) -> vector<16xf32>
84  return %ld : vector<16xf32>
85}
86
87// CHECK-LABEL: func @gather2(
88// CHECK-SAME: %[[A0:.*]]: memref<16xf32>,
89// CHECK-SAME: %[[A1:.*]]: vector<16xi32>,
90// CHECK-SAME: %[[A2:.*]]: vector<16xf32>)
91// CHECK-NEXT: return %[[A2]] : vector<16xf32>
92
93func @gather2(%base: memref<16xf32>, %indices: vector<16xi32>, %pass_thru: vector<16xf32>) -> vector<16xf32> {
94  %mask = vector.constant_mask [0] : vector<16xi1>
95  %ld = vector.gather %base, %indices, %mask, %pass_thru
96    : (memref<16xf32>, vector<16xi32>, vector<16xi1>, vector<16xf32>) -> vector<16xf32>
97  return %ld : vector<16xf32>
98}
99
100// CHECK-LABEL: func @scatter1(
101// CHECK-SAME: %[[A0:.*]]: memref<16xf32>,
102// CHECK-SAME: %[[A1:.*]]: vector<16xi32>,
103// CHECK-SAME: %[[A2:.*]]: vector<16xf32>)
104// CHECK-NEXT: %[[T0:.*]] = vector.constant_mask [16] : vector<16xi1>
105// CHECK-NEXT: vector.scatter %[[A0]], %[[A1]], %[[T0]], %[[A2]] : vector<16xi32>, vector<16xi1>, vector<16xf32> into memref<16xf32>
106// CHECK-NEXT: return
107
108func @scatter1(%base: memref<16xf32>, %indices: vector<16xi32>, %value: vector<16xf32>) {
109  %mask = vector.constant_mask [16] : vector<16xi1>
110  vector.scatter %base, %indices, %mask, %value
111    : vector<16xi32>, vector<16xi1>, vector<16xf32> into memref<16xf32>
112  return
113}
114
115// CHECK-LABEL: func @scatter2(
116// CHECK-SAME: %[[A0:.*]]: memref<16xf32>,
117// CHECK-SAME: %[[A1:.*]]: vector<16xi32>,
118// CHECK-SAME: %[[A2:.*]]: vector<16xf32>)
119// CHECK-NEXT: return
120
121func @scatter2(%base: memref<16xf32>, %indices: vector<16xi32>, %value: vector<16xf32>) {
122  %0 = vector.type_cast %base : memref<16xf32> to memref<vector<16xf32>>
123  %mask = vector.constant_mask [0] : vector<16xi1>
124  vector.scatter %base, %indices, %mask, %value
125    : vector<16xi32>, vector<16xi1>, vector<16xf32> into memref<16xf32>
126  return
127}
128
129// CHECK-LABEL: func @expand1(
130// CHECK-SAME: %[[A0:.*]]: memref<16xf32>,
131// CHECK-SAME: %[[A1:.*]]: vector<16xf32>)
132// CHECK-NEXT: %[[T0:.*]] = vector.type_cast %[[A0]] : memref<16xf32> to memref<vector<16xf32>>
133// CHECK-NEXT: %[[T1:.*]] = load %[[T0]][] : memref<vector<16xf32>>
134// CHECK-NEXT: return %[[T1]] : vector<16xf32>
135
136func @expand1(%base: memref<16xf32>, %pass_thru: vector<16xf32>) -> vector<16xf32> {
137  %mask = vector.constant_mask [16] : vector<16xi1>
138  %ld = vector.expandload %base, %mask, %pass_thru
139    : memref<16xf32>, vector<16xi1>, vector<16xf32> into vector<16xf32>
140  return %ld : vector<16xf32>
141}
142
143// CHECK-LABEL: func @expand2(
144// CHECK-SAME: %[[A0:.*]]: memref<16xf32>,
145// CHECK-SAME: %[[A1:.*]]: vector<16xf32>)
146// CHECK-NEXT: return %[[A1]] : vector<16xf32>
147
148func @expand2(%base: memref<16xf32>, %pass_thru: vector<16xf32>) -> vector<16xf32> {
149  %mask = vector.constant_mask [0] : vector<16xi1>
150  %ld = vector.expandload %base, %mask, %pass_thru
151    : memref<16xf32>, vector<16xi1>, vector<16xf32> into vector<16xf32>
152  return %ld : vector<16xf32>
153}
154
155// CHECK-LABEL: func @compress1(
156// CHECK-SAME: %[[A0:.*]]: memref<16xf32>,
157// CHECK-SAME: %[[A1:.*]]: vector<16xf32>)
158// CHECK-NEXT: %[[T0:.*]] = vector.type_cast %[[A0]] : memref<16xf32> to memref<vector<16xf32>>
159// CHECK-NEXT: store %[[A1]], %[[T0]][] : memref<vector<16xf32>>
160// CHECK-NEXT: return
161
162func @compress1(%base: memref<16xf32>, %value: vector<16xf32>) {
163  %mask = vector.constant_mask [16] : vector<16xi1>
164  vector.compressstore %base, %mask, %value  : memref<16xf32>, vector<16xi1>, vector<16xf32>
165  return
166}
167
168// CHECK-LABEL: func @compress2(
169// CHECK-SAME: %[[A0:.*]]: memref<16xf32>,
170// CHECK-SAME: %[[A1:.*]]: vector<16xf32>)
171// CHECK-NEXT: return
172
173func @compress2(%base: memref<16xf32>, %value: vector<16xf32>) {
174  %mask = vector.constant_mask [0] : vector<16xi1>
175  vector.compressstore %base, %mask, %value : memref<16xf32>, vector<16xi1>, vector<16xf32>
176  return
177}
178