1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: sed 's/iXLen/i32/g' %s | llc -mtriple=riscv32 -mattr=+v \
3 ; RUN: -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,VLENUNKNOWN
4 ; RUN: sed 's/iXLen/i64/g' %s | llc -mtriple=riscv64 -mattr=+v \
5 ; RUN: -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,VLENUNKNOWN
6 ; RUN: sed 's/iXLen/i32/g' %s | llc -mtriple=riscv32 -mattr=+v \
7 ; RUN: -riscv-v-vector-bits-max=128 -verify-machineinstrs \
8 ; RUN: | FileCheck %s --check-prefixes=CHECK,VLEN128
9 ; RUN: sed 's/iXLen/i64/g' %s | llc -mtriple=riscv64 -mattr=+v \
10 ; RUN: -riscv-v-vector-bits-max=128 -verify-machineinstrs \
11 ; RUN: | FileCheck %s --check-prefixes=CHECK,VLEN128
13 declare iXLen @llvm.riscv.vsetvli.iXLen(iXLen, iXLen, iXLen)
14 declare iXLen @llvm.riscv.vsetvlimax.iXLen(iXLen, iXLen)
16 define iXLen @test_vsetvli_e8m1(iXLen %avl) nounwind {
17 ; CHECK-LABEL: test_vsetvli_e8m1:
19 ; CHECK-NEXT: vsetvli a0, a0, e8, m1, ta, ma
21 %vl = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen %avl, iXLen 0, iXLen 0)
25 define iXLen @test_vsetvli_e16mf4(iXLen %avl) nounwind {
26 ; CHECK-LABEL: test_vsetvli_e16mf4:
28 ; CHECK-NEXT: vsetvli a0, a0, e16, mf4, ta, ma
30 %vl = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen %avl, iXLen 1, iXLen 6)
34 define iXLen @test_vsetvli_e64mf8(iXLen %avl) nounwind {
35 ; CHECK-LABEL: test_vsetvli_e64mf8:
37 ; CHECK-NEXT: vsetvli a0, a0, e64, mf8, ta, ma
39 %vl = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen %avl, iXLen 3, iXLen 5)
43 define iXLen @test_vsetvli_e8mf2_zero_avl() nounwind {
44 ; CHECK-LABEL: test_vsetvli_e8mf2_zero_avl:
46 ; CHECK-NEXT: vsetivli a0, 0, e8, mf2, ta, ma
48 %vl = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen 0, iXLen 0, iXLen 7)
52 define iXLen @test_vsetvli_e32mf8_zero_avl() nounwind {
53 ; CHECK-LABEL: test_vsetvli_e32mf8_zero_avl:
55 ; CHECK-NEXT: vsetivli a0, 0, e16, mf4, ta, ma
57 %vl = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen 0, iXLen 1, iXLen 6)
61 define iXLen @test_vsetvlimax_e32m2() nounwind {
62 ; CHECK-LABEL: test_vsetvlimax_e32m2:
64 ; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, ma
66 %vl = call iXLen @llvm.riscv.vsetvlimax.iXLen(iXLen 2, iXLen 1)
70 define iXLen @test_vsetvlimax_e64m4() nounwind {
71 ; CHECK-LABEL: test_vsetvlimax_e64m4:
73 ; CHECK-NEXT: vsetvli a0, zero, e64, m4, ta, ma
75 %vl = call iXLen @llvm.riscv.vsetvlimax.iXLen(iXLen 3, iXLen 2)
79 define iXLen @test_vsetvlimax_e64m8() nounwind {
80 ; CHECK-LABEL: test_vsetvlimax_e64m8:
82 ; CHECK-NEXT: vsetvli a0, zero, e64, m8, ta, ma
84 %vl = call iXLen @llvm.riscv.vsetvlimax.iXLen(iXLen 3, iXLen 3)
88 ; Check that we remove the intrinsic if it's unused.
89 define void @test_vsetvli_e8m1_nouse(iXLen %avl) nounwind {
90 ; CHECK-LABEL: test_vsetvli_e8m1_nouse:
93 call iXLen @llvm.riscv.vsetvli.iXLen(iXLen %avl, iXLen 0, iXLen 0)
97 define void @test_vsetvlimax_e32m2_nouse() nounwind {
98 ; CHECK-LABEL: test_vsetvlimax_e32m2_nouse:
101 call iXLen @llvm.riscv.vsetvlimax.iXLen(iXLen 2, iXLen 1)
105 declare <vscale x 4 x i32> @llvm.riscv.vle.nxv4i32.iXLen(<vscale x 4 x i32>, ptr, iXLen)
107 ; Check that we remove the redundant vsetvli when followed by another operation
108 define <vscale x 4 x i32> @redundant_vsetvli(iXLen %avl, ptr %ptr) nounwind {
109 ; CHECK-LABEL: redundant_vsetvli:
111 ; CHECK-NEXT: vsetvli zero, a0, e32, m2, ta, ma
112 ; CHECK-NEXT: vle32.v v8, (a1)
114 %vl = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen %avl, iXLen 2, iXLen 1)
115 %x = call <vscale x 4 x i32> @llvm.riscv.vle.nxv4i32.iXLen(<vscale x 4 x i32> undef, ptr %ptr, iXLen %vl)
116 ret <vscale x 4 x i32> %x
119 ; Check that we remove the repeated/redundant vsetvli when followed by another
121 ; FIXME: We don't catch the second vsetvli because it has a use of its output.
122 ; We could replace it with the output of the first vsetvli.
123 define <vscale x 4 x i32> @repeated_vsetvli(iXLen %avl, ptr %ptr) nounwind {
124 ; CHECK-LABEL: repeated_vsetvli:
126 ; CHECK-NEXT: vsetvli a0, a0, e32, m2, ta, ma
127 ; CHECK-NEXT: vsetvli zero, a0, e32, m2, ta, ma
128 ; CHECK-NEXT: vle32.v v8, (a1)
130 %vl0 = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen %avl, iXLen 2, iXLen 1)
131 %vl1 = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen %vl0, iXLen 2, iXLen 1)
132 %x = call <vscale x 4 x i32> @llvm.riscv.vle.nxv4i32.iXLen(<vscale x 4 x i32> undef, ptr %ptr, iXLen %vl1)
133 ret <vscale x 4 x i32> %x
136 define iXLen @test_vsetvli_negone_e8m1(iXLen %avl) nounwind {
137 ; CHECK-LABEL: test_vsetvli_negone_e8m1:
139 ; CHECK-NEXT: vsetvli a0, zero, e8, m1, ta, ma
141 %vl = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen -1, iXLen 0, iXLen 0)
145 define iXLen @test_vsetvli_eqvlmax_e8m8(iXLen %avl) nounwind {
146 ; VLENUNKNOWN-LABEL: test_vsetvli_eqvlmax_e8m8:
147 ; VLENUNKNOWN: # %bb.0:
148 ; VLENUNKNOWN-NEXT: li a0, 128
149 ; VLENUNKNOWN-NEXT: vsetvli a0, a0, e8, m8, ta, ma
150 ; VLENUNKNOWN-NEXT: ret
152 ; VLEN128-LABEL: test_vsetvli_eqvlmax_e8m8:
154 ; VLEN128-NEXT: vsetvli a0, zero, e8, m8, ta, ma
156 %vl = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen 128, iXLen 0, iXLen 3)