1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -mattr=+v -verify-machineinstrs < %s | FileCheck %s --check-prefixes=CHECK,RV32
3 ; RUN: llc -mtriple=riscv64 -mattr=+v -verify-machineinstrs < %s | FileCheck %s --check-prefixes=CHECK,RV64
5 define void @splat_v16i8(ptr %x, i8 %y) {
6 ; CHECK-LABEL: splat_v16i8:
8 ; CHECK-NEXT: vsetivli zero, 16, e8, m1, ta, ma
9 ; CHECK-NEXT: vmv.v.x v8, a1
10 ; CHECK-NEXT: vse8.v v8, (a0)
12 %a = insertelement <16 x i8> poison, i8 %y, i32 0
13 %b = shufflevector <16 x i8> %a, <16 x i8> poison, <16 x i32> zeroinitializer
14 store <16 x i8> %b, ptr %x
18 define void @splat_v8i16(ptr %x, i16 %y) {
19 ; CHECK-LABEL: splat_v8i16:
21 ; CHECK-NEXT: vsetivli zero, 8, e16, m1, ta, ma
22 ; CHECK-NEXT: vmv.v.x v8, a1
23 ; CHECK-NEXT: vse16.v v8, (a0)
25 %a = insertelement <8 x i16> poison, i16 %y, i32 0
26 %b = shufflevector <8 x i16> %a, <8 x i16> poison, <8 x i32> zeroinitializer
27 store <8 x i16> %b, ptr %x
31 define void @splat_v4i32(ptr %x, i32 %y) {
32 ; CHECK-LABEL: splat_v4i32:
34 ; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, ma
35 ; CHECK-NEXT: vmv.v.x v8, a1
36 ; CHECK-NEXT: vse32.v v8, (a0)
38 %a = insertelement <4 x i32> poison, i32 %y, i32 0
39 %b = shufflevector <4 x i32> %a, <4 x i32> poison, <4 x i32> zeroinitializer
40 store <4 x i32> %b, ptr %x
44 define void @splat_v2i64(ptr %x, i64 %y) {
45 ; RV32-LABEL: splat_v2i64:
47 ; RV32-NEXT: addi sp, sp, -16
48 ; RV32-NEXT: .cfi_def_cfa_offset 16
49 ; RV32-NEXT: sw a2, 12(sp)
50 ; RV32-NEXT: sw a1, 8(sp)
51 ; RV32-NEXT: addi a1, sp, 8
52 ; RV32-NEXT: vsetivli zero, 2, e64, m1, ta, ma
53 ; RV32-NEXT: vlse64.v v8, (a1), zero
54 ; RV32-NEXT: vse64.v v8, (a0)
55 ; RV32-NEXT: addi sp, sp, 16
58 ; RV64-LABEL: splat_v2i64:
60 ; RV64-NEXT: vsetivli zero, 2, e64, m1, ta, ma
61 ; RV64-NEXT: vmv.v.x v8, a1
62 ; RV64-NEXT: vse64.v v8, (a0)
64 %a = insertelement <2 x i64> poison, i64 %y, i32 0
65 %b = shufflevector <2 x i64> %a, <2 x i64> poison, <2 x i32> zeroinitializer
66 store <2 x i64> %b, ptr %x
70 define void @splat_v32i8(ptr %x, i8 %y) {
71 ; CHECK-LABEL: splat_v32i8:
73 ; CHECK-NEXT: li a2, 32
74 ; CHECK-NEXT: vsetvli zero, a2, e8, m2, ta, ma
75 ; CHECK-NEXT: vmv.v.x v8, a1
76 ; CHECK-NEXT: vse8.v v8, (a0)
78 %a = insertelement <32 x i8> poison, i8 %y, i32 0
79 %b = shufflevector <32 x i8> %a, <32 x i8> poison, <32 x i32> zeroinitializer
80 store <32 x i8> %b, ptr %x
84 define void @splat_v16i16(ptr %x, i16 %y) {
85 ; CHECK-LABEL: splat_v16i16:
87 ; CHECK-NEXT: vsetivli zero, 16, e16, m2, ta, ma
88 ; CHECK-NEXT: vmv.v.x v8, a1
89 ; CHECK-NEXT: vse16.v v8, (a0)
91 %a = insertelement <16 x i16> poison, i16 %y, i32 0
92 %b = shufflevector <16 x i16> %a, <16 x i16> poison, <16 x i32> zeroinitializer
93 store <16 x i16> %b, ptr %x
97 define void @splat_v8i32(ptr %x, i32 %y) {
98 ; CHECK-LABEL: splat_v8i32:
100 ; CHECK-NEXT: vsetivli zero, 8, e32, m2, ta, ma
101 ; CHECK-NEXT: vmv.v.x v8, a1
102 ; CHECK-NEXT: vse32.v v8, (a0)
104 %a = insertelement <8 x i32> poison, i32 %y, i32 0
105 %b = shufflevector <8 x i32> %a, <8 x i32> poison, <8 x i32> zeroinitializer
106 store <8 x i32> %b, ptr %x
110 define void @splat_v4i64(ptr %x, i64 %y) {
111 ; RV32-LABEL: splat_v4i64:
113 ; RV32-NEXT: addi sp, sp, -16
114 ; RV32-NEXT: .cfi_def_cfa_offset 16
115 ; RV32-NEXT: sw a2, 12(sp)
116 ; RV32-NEXT: sw a1, 8(sp)
117 ; RV32-NEXT: addi a1, sp, 8
118 ; RV32-NEXT: vsetivli zero, 4, e64, m2, ta, ma
119 ; RV32-NEXT: vlse64.v v8, (a1), zero
120 ; RV32-NEXT: vse64.v v8, (a0)
121 ; RV32-NEXT: addi sp, sp, 16
124 ; RV64-LABEL: splat_v4i64:
126 ; RV64-NEXT: vsetivli zero, 4, e64, m2, ta, ma
127 ; RV64-NEXT: vmv.v.x v8, a1
128 ; RV64-NEXT: vse64.v v8, (a0)
130 %a = insertelement <4 x i64> poison, i64 %y, i32 0
131 %b = shufflevector <4 x i64> %a, <4 x i64> poison, <4 x i32> zeroinitializer
132 store <4 x i64> %b, ptr %x
136 define void @splat_zero_v16i8(ptr %x) {
137 ; CHECK-LABEL: splat_zero_v16i8:
139 ; CHECK-NEXT: vsetivli zero, 16, e8, m1, ta, ma
140 ; CHECK-NEXT: vmv.v.i v8, 0
141 ; CHECK-NEXT: vse8.v v8, (a0)
143 store <16 x i8> splat (i8 0), ptr %x
147 define void @splat_zero_v8i16(ptr %x) {
148 ; CHECK-LABEL: splat_zero_v8i16:
150 ; CHECK-NEXT: vsetivli zero, 8, e16, m1, ta, ma
151 ; CHECK-NEXT: vmv.v.i v8, 0
152 ; CHECK-NEXT: vse16.v v8, (a0)
154 store <8 x i16> splat (i16 0), ptr %x
158 define void @splat_zero_v4i32(ptr %x) {
159 ; CHECK-LABEL: splat_zero_v4i32:
161 ; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, ma
162 ; CHECK-NEXT: vmv.v.i v8, 0
163 ; CHECK-NEXT: vse32.v v8, (a0)
165 store <4 x i32> splat (i32 0), ptr %x
169 define void @splat_zero_v2i64(ptr %x) {
170 ; CHECK-LABEL: splat_zero_v2i64:
172 ; CHECK-NEXT: vsetivli zero, 2, e64, m1, ta, ma
173 ; CHECK-NEXT: vmv.v.i v8, 0
174 ; CHECK-NEXT: vse64.v v8, (a0)
176 store <2 x i64> splat (i64 0), ptr %x
180 define void @splat_zero_v32i8(ptr %x) {
181 ; CHECK-LABEL: splat_zero_v32i8:
183 ; CHECK-NEXT: li a1, 32
184 ; CHECK-NEXT: vsetvli zero, a1, e8, m2, ta, ma
185 ; CHECK-NEXT: vmv.v.i v8, 0
186 ; CHECK-NEXT: vse8.v v8, (a0)
188 store <32 x i8> splat (i8 0), ptr %x
192 define void @splat_zero_v16i16(ptr %x) {
193 ; CHECK-LABEL: splat_zero_v16i16:
195 ; CHECK-NEXT: vsetivli zero, 16, e16, m2, ta, ma
196 ; CHECK-NEXT: vmv.v.i v8, 0
197 ; CHECK-NEXT: vse16.v v8, (a0)
199 store <16 x i16> splat (i16 0), ptr %x
203 define void @splat_zero_v8i32(ptr %x) {
204 ; CHECK-LABEL: splat_zero_v8i32:
206 ; CHECK-NEXT: vsetivli zero, 8, e32, m2, ta, ma
207 ; CHECK-NEXT: vmv.v.i v8, 0
208 ; CHECK-NEXT: vse32.v v8, (a0)
210 store <8 x i32> splat (i32 0), ptr %x
214 define void @splat_zero_v4i64(ptr %x) {
215 ; CHECK-LABEL: splat_zero_v4i64:
217 ; CHECK-NEXT: vsetivli zero, 4, e64, m2, ta, ma
218 ; CHECK-NEXT: vmv.v.i v8, 0
219 ; CHECK-NEXT: vse64.v v8, (a0)
221 store <4 x i64> splat (i64 0), ptr %x
225 define void @splat_zero_v2i16(ptr %p) {
226 ; CHECK-LABEL: splat_zero_v2i16:
228 ; CHECK-NEXT: sw zero, 0(a0)
230 store <2 x i16> zeroinitializer, ptr %p
234 define void @splat_zero_v2i16_unaligned(ptr %p) {
235 ; CHECK-LABEL: splat_zero_v2i16_unaligned:
237 ; CHECK-NEXT: vsetivli zero, 2, e16, mf4, ta, ma
238 ; CHECK-NEXT: vmv.v.i v8, 0
239 ; CHECK-NEXT: vsetivli zero, 4, e8, mf4, ta, ma
240 ; CHECK-NEXT: vse8.v v8, (a0)
242 store <2 x i16> zeroinitializer, ptr %p, align 1
246 define void @splat_zero_v4i16(ptr %p) {
247 ; RV32-LABEL: splat_zero_v4i16:
249 ; RV32-NEXT: vsetivli zero, 4, e16, mf2, ta, ma
250 ; RV32-NEXT: vmv.v.i v8, 0
251 ; RV32-NEXT: vse16.v v8, (a0)
254 ; RV64-LABEL: splat_zero_v4i16:
256 ; RV64-NEXT: sd zero, 0(a0)
258 store <4 x i16> zeroinitializer, ptr %p
262 define void @splat_zero_v2i32(ptr %p) {
263 ; RV32-LABEL: splat_zero_v2i32:
265 ; RV32-NEXT: vsetivli zero, 2, e32, mf2, ta, ma
266 ; RV32-NEXT: vmv.v.i v8, 0
267 ; RV32-NEXT: vse32.v v8, (a0)
270 ; RV64-LABEL: splat_zero_v2i32:
272 ; RV64-NEXT: sd zero, 0(a0)
274 store <2 x i32> zeroinitializer, ptr %p
278 ; Not a power of two and requires more than two scalar stores.
279 define void @splat_zero_v7i16(ptr %p) {
280 ; CHECK-LABEL: splat_zero_v7i16:
282 ; CHECK-NEXT: vsetivli zero, 8, e16, m1, ta, ma
283 ; CHECK-NEXT: vmv.v.i v8, 0
284 ; CHECK-NEXT: vsetivli zero, 7, e16, m1, ta, ma
285 ; CHECK-NEXT: vse16.v v8, (a0)
287 store <7 x i16> zeroinitializer, ptr %p
291 define void @splat_allones_v16i8(ptr %x) {
292 ; CHECK-LABEL: splat_allones_v16i8:
294 ; CHECK-NEXT: vsetivli zero, 16, e8, m1, ta, ma
295 ; CHECK-NEXT: vmv.v.i v8, -1
296 ; CHECK-NEXT: vse8.v v8, (a0)
298 store <16 x i8> splat (i8 -1), ptr %x
302 define void @splat_allones_v8i16(ptr %x) {
303 ; CHECK-LABEL: splat_allones_v8i16:
305 ; CHECK-NEXT: vsetivli zero, 8, e16, m1, ta, ma
306 ; CHECK-NEXT: vmv.v.i v8, -1
307 ; CHECK-NEXT: vse16.v v8, (a0)
309 store <8 x i16> splat (i16 -1), ptr %x
313 define void @splat_allones_v4i32(ptr %x) {
314 ; CHECK-LABEL: splat_allones_v4i32:
316 ; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, ma
317 ; CHECK-NEXT: vmv.v.i v8, -1
318 ; CHECK-NEXT: vse32.v v8, (a0)
320 store <4 x i32> splat (i32 -1), ptr %x
324 define void @splat_allones_v2i64(ptr %x) {
325 ; CHECK-LABEL: splat_allones_v2i64:
327 ; CHECK-NEXT: vsetivli zero, 2, e64, m1, ta, ma
328 ; CHECK-NEXT: vmv.v.i v8, -1
329 ; CHECK-NEXT: vse64.v v8, (a0)
331 store <2 x i64> splat (i64 -1), ptr %x
335 define void @splat_allones_v32i8(ptr %x) {
336 ; CHECK-LABEL: splat_allones_v32i8:
338 ; CHECK-NEXT: li a1, 32
339 ; CHECK-NEXT: vsetvli zero, a1, e8, m2, ta, ma
340 ; CHECK-NEXT: vmv.v.i v8, -1
341 ; CHECK-NEXT: vse8.v v8, (a0)
343 store <32 x i8> splat (i8 -1), ptr %x
347 define void @splat_allones_v16i16(ptr %x) {
348 ; CHECK-LABEL: splat_allones_v16i16:
350 ; CHECK-NEXT: vsetivli zero, 16, e16, m2, ta, ma
351 ; CHECK-NEXT: vmv.v.i v8, -1
352 ; CHECK-NEXT: vse16.v v8, (a0)
354 store <16 x i16> splat (i16 -1), ptr %x
358 define void @splat_allones_v8i32(ptr %x) {
359 ; CHECK-LABEL: splat_allones_v8i32:
361 ; CHECK-NEXT: vsetivli zero, 8, e32, m2, ta, ma
362 ; CHECK-NEXT: vmv.v.i v8, -1
363 ; CHECK-NEXT: vse32.v v8, (a0)
365 store <8 x i32> splat (i32 -1), ptr %x
369 define void @splat_allones_v4i64(ptr %x) {
370 ; CHECK-LABEL: splat_allones_v4i64:
372 ; CHECK-NEXT: vsetivli zero, 4, e64, m2, ta, ma
373 ; CHECK-NEXT: vmv.v.i v8, -1
374 ; CHECK-NEXT: vse64.v v8, (a0)
376 store <4 x i64> splat (i64 -1), ptr %x
380 ; This requires a bitcast on RV32 due to type legalization rewriting the
381 ; build_vector to v8i32.
382 ; FIXME: We should prevent this and use the implicit sign extension of vmv.v.x
383 ; with SEW=64 on RV32.
384 define void @splat_allones_with_use_v4i64(ptr %x) {
385 ; CHECK-LABEL: splat_allones_with_use_v4i64:
387 ; CHECK-NEXT: vsetivli zero, 4, e64, m2, ta, ma
388 ; CHECK-NEXT: vle64.v v8, (a0)
389 ; CHECK-NEXT: vadd.vi v8, v8, -1
390 ; CHECK-NEXT: vse64.v v8, (a0)
392 %a = load <4 x i64>, ptr %x
393 %b = add <4 x i64> %a, <i64 -1, i64 -1, i64 -1, i64 -1>
394 store <4 x i64> %b, ptr %x
398 ; This test used to crash at LMUL=8 when inserting a v16i64 subvector into
399 ; nxv8i64 at index 0: the v16i64 type was used to get the LMUL, the size of
400 ; which exceeded maximum-expected size of 512. The scalable container type of
401 ; nxv8i64 should have been used instead.
402 define void @vadd_vx_v16i64(ptr %a, i64 %b, ptr %c) {
403 ; RV32-LABEL: vadd_vx_v16i64:
405 ; RV32-NEXT: addi sp, sp, -16
406 ; RV32-NEXT: .cfi_def_cfa_offset 16
407 ; RV32-NEXT: vsetivli zero, 16, e64, m8, ta, ma
408 ; RV32-NEXT: vle64.v v8, (a0)
409 ; RV32-NEXT: sw a2, 12(sp)
410 ; RV32-NEXT: sw a1, 8(sp)
411 ; RV32-NEXT: addi a0, sp, 8
412 ; RV32-NEXT: vlse64.v v16, (a0), zero
413 ; RV32-NEXT: vadd.vv v8, v8, v16
414 ; RV32-NEXT: vse64.v v8, (a3)
415 ; RV32-NEXT: addi sp, sp, 16
418 ; RV64-LABEL: vadd_vx_v16i64:
420 ; RV64-NEXT: vsetivli zero, 16, e64, m8, ta, ma
421 ; RV64-NEXT: vle64.v v8, (a0)
422 ; RV64-NEXT: vadd.vx v8, v8, a1
423 ; RV64-NEXT: vse64.v v8, (a2)
425 %va = load <16 x i64>, ptr %a
426 %head = insertelement <16 x i64> poison, i64 %b, i32 0
427 %splat = shufflevector <16 x i64> %head, <16 x i64> poison, <16 x i32> zeroinitializer
428 %vc = add <16 x i64> %va, %splat
429 store <16 x i64> %vc, ptr %c