1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefix=RV64I
4 ; RUN: llc -mtriple=riscv64 -mattr=+zbkb -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefix=RV64ZBKB
7 define signext i32 @pack_i32(i32 signext %a, i32 signext %b) nounwind {
8 ; RV64I-LABEL: pack_i32:
10 ; RV64I-NEXT: slli a0, a0, 48
11 ; RV64I-NEXT: srli a0, a0, 48
12 ; RV64I-NEXT: slliw a1, a1, 16
13 ; RV64I-NEXT: or a0, a1, a0
16 ; RV64ZBKB-LABEL: pack_i32:
18 ; RV64ZBKB-NEXT: packw a0, a0, a1
20 %shl = and i32 %a, 65535
21 %shl1 = shl i32 %b, 16
22 %or = or i32 %shl1, %shl
26 define signext i32 @pack_i32_2(i16 zeroext %a, i16 zeroext %b) nounwind {
27 ; RV64I-LABEL: pack_i32_2:
29 ; RV64I-NEXT: slliw a1, a1, 16
30 ; RV64I-NEXT: or a0, a1, a0
33 ; RV64ZBKB-LABEL: pack_i32_2:
35 ; RV64ZBKB-NEXT: packw a0, a0, a1
37 %zexta = zext i16 %a to i32
38 %zextb = zext i16 %b to i32
39 %shl1 = shl i32 %zextb, 16
40 %or = or i32 %shl1, %zexta
44 ; Test case where we don't have a sign_extend_inreg after the or.
45 define signext i32 @pack_i32_3(i16 zeroext %0, i16 zeroext %1, i32 signext %2) {
46 ; RV64I-LABEL: pack_i32_3:
48 ; RV64I-NEXT: slli a0, a0, 16
49 ; RV64I-NEXT: or a0, a0, a1
50 ; RV64I-NEXT: addw a0, a0, a2
53 ; RV64ZBKB-LABEL: pack_i32_3:
55 ; RV64ZBKB-NEXT: packw a0, a1, a0
56 ; RV64ZBKB-NEXT: addw a0, a0, a2
58 %4 = zext i16 %0 to i32
59 %5 = shl nuw i32 %4, 16
60 %6 = zext i16 %1 to i32
66 define i64 @pack_i64(i64 %a, i64 %b) nounwind {
67 ; RV64I-LABEL: pack_i64:
69 ; RV64I-NEXT: slli a0, a0, 32
70 ; RV64I-NEXT: srli a0, a0, 32
71 ; RV64I-NEXT: slli a1, a1, 32
72 ; RV64I-NEXT: or a0, a1, a0
75 ; RV64ZBKB-LABEL: pack_i64:
77 ; RV64ZBKB-NEXT: pack a0, a0, a1
79 %shl = and i64 %a, 4294967295
80 %shl1 = shl i64 %b, 32
81 %or = or i64 %shl1, %shl
85 define i64 @pack_i64_2(i32 signext %a, i32 signext %b) nounwind {
86 ; RV64I-LABEL: pack_i64_2:
88 ; RV64I-NEXT: slli a0, a0, 32
89 ; RV64I-NEXT: srli a0, a0, 32
90 ; RV64I-NEXT: slli a1, a1, 32
91 ; RV64I-NEXT: or a0, a1, a0
94 ; RV64ZBKB-LABEL: pack_i64_2:
96 ; RV64ZBKB-NEXT: pack a0, a0, a1
98 %zexta = zext i32 %a to i64
99 %zextb = zext i32 %b to i64
100 %shl1 = shl i64 %zextb, 32
101 %or = or i64 %shl1, %zexta
105 define i64 @pack_i64_3(ptr %0, ptr %1) {
106 ; RV64I-LABEL: pack_i64_3:
108 ; RV64I-NEXT: lw a0, 0(a0)
109 ; RV64I-NEXT: lwu a1, 0(a1)
110 ; RV64I-NEXT: slli a0, a0, 32
111 ; RV64I-NEXT: or a0, a0, a1
114 ; RV64ZBKB-LABEL: pack_i64_3:
116 ; RV64ZBKB-NEXT: lw a0, 0(a0)
117 ; RV64ZBKB-NEXT: lwu a1, 0(a1)
118 ; RV64ZBKB-NEXT: pack a0, a1, a0
120 %3 = load i32, ptr %0, align 4
121 %4 = zext i32 %3 to i64
123 %6 = load i32, ptr %1, align 4
124 %7 = zext i32 %6 to i64
129 define signext i32 @packh_i32(i32 signext %a, i32 signext %b) nounwind {
130 ; RV64I-LABEL: packh_i32:
132 ; RV64I-NEXT: andi a0, a0, 255
133 ; RV64I-NEXT: slli a1, a1, 56
134 ; RV64I-NEXT: srli a1, a1, 48
135 ; RV64I-NEXT: or a0, a1, a0
138 ; RV64ZBKB-LABEL: packh_i32:
140 ; RV64ZBKB-NEXT: packh a0, a0, a1
142 %and = and i32 %a, 255
143 %and1 = shl i32 %b, 8
144 %shl = and i32 %and1, 65280
145 %or = or i32 %shl, %and
149 define i32 @packh_i32_2(i32 %a, i32 %b) nounwind {
150 ; RV64I-LABEL: packh_i32_2:
152 ; RV64I-NEXT: andi a0, a0, 255
153 ; RV64I-NEXT: andi a1, a1, 255
154 ; RV64I-NEXT: slli a1, a1, 8
155 ; RV64I-NEXT: or a0, a1, a0
158 ; RV64ZBKB-LABEL: packh_i32_2:
160 ; RV64ZBKB-NEXT: packh a0, a0, a1
162 %and = and i32 %a, 255
163 %and1 = and i32 %b, 255
164 %shl = shl i32 %and1, 8
165 %or = or i32 %shl, %and
169 define i64 @packh_i64(i64 %a, i64 %b) nounwind {
170 ; RV64I-LABEL: packh_i64:
172 ; RV64I-NEXT: andi a0, a0, 255
173 ; RV64I-NEXT: slli a1, a1, 56
174 ; RV64I-NEXT: srli a1, a1, 48
175 ; RV64I-NEXT: or a0, a1, a0
178 ; RV64ZBKB-LABEL: packh_i64:
180 ; RV64ZBKB-NEXT: packh a0, a0, a1
182 %and = and i64 %a, 255
183 %and1 = shl i64 %b, 8
184 %shl = and i64 %and1, 65280
185 %or = or i64 %shl, %and
189 define i64 @packh_i64_2(i64 %a, i64 %b) nounwind {
190 ; RV64I-LABEL: packh_i64_2:
192 ; RV64I-NEXT: andi a0, a0, 255
193 ; RV64I-NEXT: andi a1, a1, 255
194 ; RV64I-NEXT: slli a1, a1, 8
195 ; RV64I-NEXT: or a0, a1, a0
198 ; RV64ZBKB-LABEL: packh_i64_2:
200 ; RV64ZBKB-NEXT: packh a0, a0, a1
202 %and = and i64 %a, 255
203 %and1 = and i64 %b, 255
204 %shl = shl i64 %and1, 8
205 %or = or i64 %shl, %and
209 define zeroext i16 @packh_i16(i8 zeroext %a, i8 zeroext %b) nounwind {
210 ; RV64I-LABEL: packh_i16:
212 ; RV64I-NEXT: slli a1, a1, 8
213 ; RV64I-NEXT: or a0, a1, a0
216 ; RV64ZBKB-LABEL: packh_i16:
218 ; RV64ZBKB-NEXT: packh a0, a0, a1
220 %zext = zext i8 %a to i16
221 %zext1 = zext i8 %b to i16
222 %shl = shl i16 %zext1, 8
223 %or = or i16 %shl, %zext
227 define zeroext i16 @packh_i16_2(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2) {
228 ; RV64I-LABEL: packh_i16_2:
230 ; RV64I-NEXT: add a0, a1, a0
231 ; RV64I-NEXT: slli a0, a0, 8
232 ; RV64I-NEXT: or a0, a0, a2
233 ; RV64I-NEXT: slli a0, a0, 48
234 ; RV64I-NEXT: srli a0, a0, 48
237 ; RV64ZBKB-LABEL: packh_i16_2:
239 ; RV64ZBKB-NEXT: add a0, a1, a0
240 ; RV64ZBKB-NEXT: packh a0, a2, a0
243 %5 = zext i8 %4 to i16
245 %7 = zext i8 %2 to i16
250 define void @packh_i16_3(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, ptr %p) {
251 ; RV64I-LABEL: packh_i16_3:
253 ; RV64I-NEXT: add a0, a1, a0
254 ; RV64I-NEXT: slli a0, a0, 8
255 ; RV64I-NEXT: or a0, a0, a2
256 ; RV64I-NEXT: sh a0, 0(a3)
259 ; RV64ZBKB-LABEL: packh_i16_3:
261 ; RV64ZBKB-NEXT: add a0, a1, a0
262 ; RV64ZBKB-NEXT: packh a0, a2, a0
263 ; RV64ZBKB-NEXT: sh a0, 0(a3)
266 %5 = zext i8 %4 to i16
268 %7 = zext i8 %2 to i16
274 define i64 @pack_i64_allWUsers(i32 signext %0, i32 signext %1, i32 signext %2) {
275 ; RV64I-LABEL: pack_i64_allWUsers:
277 ; RV64I-NEXT: add a0, a1, a0
278 ; RV64I-NEXT: slli a0, a0, 32
279 ; RV64I-NEXT: slli a2, a2, 32
280 ; RV64I-NEXT: srli a2, a2, 32
281 ; RV64I-NEXT: or a0, a0, a2
284 ; RV64ZBKB-LABEL: pack_i64_allWUsers:
286 ; RV64ZBKB-NEXT: add a0, a1, a0
287 ; RV64ZBKB-NEXT: pack a0, a2, a0
290 %5 = zext i32 %4 to i64
292 %7 = zext i32 %2 to i64
297 define signext i32 @pack_i32_allWUsers(i16 zeroext %0, i16 zeroext %1, i16 zeroext %2) {
298 ; RV64I-LABEL: pack_i32_allWUsers:
300 ; RV64I-NEXT: add a0, a1, a0
301 ; RV64I-NEXT: slliw a0, a0, 16
302 ; RV64I-NEXT: or a0, a0, a2
305 ; RV64ZBKB-LABEL: pack_i32_allWUsers:
307 ; RV64ZBKB-NEXT: add a0, a1, a0
308 ; RV64ZBKB-NEXT: packw a0, a2, a0
311 %5 = zext i16 %4 to i32
313 %7 = zext i16 %2 to i32
318 define i64 @pack_i64_imm() {
319 ; RV64I-LABEL: pack_i64_imm:
321 ; RV64I-NEXT: lui a0, 65793
322 ; RV64I-NEXT: addiw a0, a0, 16
323 ; RV64I-NEXT: slli a1, a0, 32
324 ; RV64I-NEXT: add a0, a0, a1
327 ; RV64ZBKB-LABEL: pack_i64_imm:
329 ; RV64ZBKB-NEXT: lui a0, 65793
330 ; RV64ZBKB-NEXT: addi a0, a0, 16
331 ; RV64ZBKB-NEXT: pack a0, a0, a0
333 ret i64 1157442765409226768 ; 0x0101010101010101
336 define i32 @zexth_i32(i32 %a) nounwind {
337 ; RV64I-LABEL: zexth_i32:
339 ; RV64I-NEXT: slli a0, a0, 48
340 ; RV64I-NEXT: srli a0, a0, 48
343 ; RV64ZBKB-LABEL: zexth_i32:
345 ; RV64ZBKB-NEXT: zext.h a0, a0
347 %and = and i32 %a, 65535
351 define i64 @zexth_i64(i64 %a) nounwind {
352 ; RV64I-LABEL: zexth_i64:
354 ; RV64I-NEXT: slli a0, a0, 48
355 ; RV64I-NEXT: srli a0, a0, 48
358 ; RV64ZBKB-LABEL: zexth_i64:
360 ; RV64ZBKB-NEXT: zext.h a0, a0
362 %and = and i64 %a, 65535
366 define i32 @zext_i16_to_i32(i16 %a) nounwind {
367 ; RV64I-LABEL: zext_i16_to_i32:
369 ; RV64I-NEXT: slli a0, a0, 48
370 ; RV64I-NEXT: srli a0, a0, 48
373 ; RV64ZBKB-LABEL: zext_i16_to_i32:
375 ; RV64ZBKB-NEXT: zext.h a0, a0
377 %1 = zext i16 %a to i32
381 define i64 @zext_i16_to_i64(i16 %a) nounwind {
382 ; RV64I-LABEL: zext_i16_to_i64:
384 ; RV64I-NEXT: slli a0, a0, 48
385 ; RV64I-NEXT: srli a0, a0, 48
388 ; RV64ZBKB-LABEL: zext_i16_to_i64:
390 ; RV64ZBKB-NEXT: zext.h a0, a0
392 %1 = zext i16 %a to i64