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
3 ; RUN: llc -mtriple=riscv64 -mattr=+v -verify-machineinstrs < %s | FileCheck %s
5 ; Test that the prepareSREMEqFold optimization doesn't crash on scalable
7 define <vscale x 4 x i1> @srem_eq_fold_nxv4i8(<vscale x 4 x i8> %va) {
8 ; CHECK-LABEL: srem_eq_fold_nxv4i8:
10 ; CHECK-NEXT: li a0, 42
11 ; CHECK-NEXT: vsetvli a1, zero, e8, mf2, ta, ma
12 ; CHECK-NEXT: vmv.v.x v9, a0
13 ; CHECK-NEXT: li a1, -85
14 ; CHECK-NEXT: vmacc.vx v9, a1, v8
15 ; CHECK-NEXT: vsll.vi v8, v9, 7
16 ; CHECK-NEXT: vsrl.vi v9, v9, 1
17 ; CHECK-NEXT: vor.vv v8, v9, v8
18 ; CHECK-NEXT: vmsleu.vx v0, v8, a0
20 %head_six = insertelement <vscale x 4 x i8> poison, i8 6, i32 0
21 %splat_six = shufflevector <vscale x 4 x i8> %head_six, <vscale x 4 x i8> poison, <vscale x 4 x i32> zeroinitializer
22 %rem = srem <vscale x 4 x i8> %va, %splat_six
24 %cc = icmp eq <vscale x 4 x i8> %rem, zeroinitializer
25 ret <vscale x 4 x i1> %cc
28 define <vscale x 1 x i32> @vmulh_vv_nxv1i32(<vscale x 1 x i32> %va, <vscale x 1 x i32> %vb) {
29 ; CHECK-LABEL: vmulh_vv_nxv1i32:
31 ; CHECK-NEXT: vsetvli a0, zero, e32, mf2, ta, ma
32 ; CHECK-NEXT: vmulh.vv v8, v9, v8
34 %vc = sext <vscale x 1 x i32> %vb to <vscale x 1 x i64>
35 %vd = sext <vscale x 1 x i32> %va to <vscale x 1 x i64>
36 %ve = mul <vscale x 1 x i64> %vc, %vd
37 %head = insertelement <vscale x 1 x i64> poison, i64 32, i32 0
38 %splat = shufflevector <vscale x 1 x i64> %head, <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer
39 %vf = lshr <vscale x 1 x i64> %ve, %splat
40 %vg = trunc <vscale x 1 x i64> %vf to <vscale x 1 x i32>
41 ret <vscale x 1 x i32> %vg
44 define <vscale x 1 x i32> @vmulh_vx_nxv1i32(<vscale x 1 x i32> %va, i32 %x) {
45 ; CHECK-LABEL: vmulh_vx_nxv1i32:
47 ; CHECK-NEXT: vsetvli a1, zero, e32, mf2, ta, ma
48 ; CHECK-NEXT: vmulh.vx v8, v8, a0
50 %head1 = insertelement <vscale x 1 x i32> poison, i32 %x, i32 0
51 %splat1 = shufflevector <vscale x 1 x i32> %head1, <vscale x 1 x i32> poison, <vscale x 1 x i32> zeroinitializer
52 %vb = sext <vscale x 1 x i32> %splat1 to <vscale x 1 x i64>
53 %vc = sext <vscale x 1 x i32> %va to <vscale x 1 x i64>
54 %vd = mul <vscale x 1 x i64> %vb, %vc
55 %head2 = insertelement <vscale x 1 x i64> poison, i64 32, i32 0
56 %splat2 = shufflevector <vscale x 1 x i64> %head2, <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer
57 %ve = lshr <vscale x 1 x i64> %vd, %splat2
58 %vf = trunc <vscale x 1 x i64> %ve to <vscale x 1 x i32>
59 ret <vscale x 1 x i32> %vf
62 define <vscale x 1 x i32> @vmulh_vi_nxv1i32_0(<vscale x 1 x i32> %va) {
63 ; CHECK-LABEL: vmulh_vi_nxv1i32_0:
65 ; CHECK-NEXT: li a0, -7
66 ; CHECK-NEXT: vsetvli a1, zero, e32, mf2, ta, ma
67 ; CHECK-NEXT: vmulh.vx v8, v8, a0
69 %head1 = insertelement <vscale x 1 x i32> poison, i32 -7, i32 0
70 %splat1 = shufflevector <vscale x 1 x i32> %head1, <vscale x 1 x i32> poison, <vscale x 1 x i32> zeroinitializer
71 %vb = sext <vscale x 1 x i32> %splat1 to <vscale x 1 x i64>
72 %vc = sext <vscale x 1 x i32> %va to <vscale x 1 x i64>
73 %vd = mul <vscale x 1 x i64> %vb, %vc
74 %head2 = insertelement <vscale x 1 x i64> poison, i64 32, i32 0
75 %splat2 = shufflevector <vscale x 1 x i64> %head2, <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer
76 %ve = lshr <vscale x 1 x i64> %vd, %splat2
77 %vf = trunc <vscale x 1 x i64> %ve to <vscale x 1 x i32>
78 ret <vscale x 1 x i32> %vf
81 define <vscale x 1 x i32> @vmulh_vi_nxv1i32_1(<vscale x 1 x i32> %va) {
82 ; CHECK-LABEL: vmulh_vi_nxv1i32_1:
84 ; CHECK-NEXT: li a0, 16
85 ; CHECK-NEXT: vsetvli a1, zero, e32, mf2, ta, ma
86 ; CHECK-NEXT: vmulh.vx v8, v8, a0
88 %head1 = insertelement <vscale x 1 x i32> poison, i32 16, i32 0
89 %splat1 = shufflevector <vscale x 1 x i32> %head1, <vscale x 1 x i32> poison, <vscale x 1 x i32> zeroinitializer
90 %vb = sext <vscale x 1 x i32> %splat1 to <vscale x 1 x i64>
91 %vc = sext <vscale x 1 x i32> %va to <vscale x 1 x i64>
92 %vd = mul <vscale x 1 x i64> %vb, %vc
93 %head2 = insertelement <vscale x 1 x i64> poison, i64 32, i32 0
94 %splat2 = shufflevector <vscale x 1 x i64> %head2, <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer
95 %ve = lshr <vscale x 1 x i64> %vd, %splat2
96 %vf = trunc <vscale x 1 x i64> %ve to <vscale x 1 x i32>
97 ret <vscale x 1 x i32> %vf
100 define <vscale x 2 x i32> @vmulh_vv_nxv2i32(<vscale x 2 x i32> %va, <vscale x 2 x i32> %vb) {
101 ; CHECK-LABEL: vmulh_vv_nxv2i32:
103 ; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, ma
104 ; CHECK-NEXT: vmulh.vv v8, v9, v8
106 %vc = sext <vscale x 2 x i32> %vb to <vscale x 2 x i64>
107 %vd = sext <vscale x 2 x i32> %va to <vscale x 2 x i64>
108 %ve = mul <vscale x 2 x i64> %vc, %vd
109 %head = insertelement <vscale x 2 x i64> poison, i64 32, i32 0
110 %splat = shufflevector <vscale x 2 x i64> %head, <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
111 %vf = lshr <vscale x 2 x i64> %ve, %splat
112 %vg = trunc <vscale x 2 x i64> %vf to <vscale x 2 x i32>
113 ret <vscale x 2 x i32> %vg
116 define <vscale x 2 x i32> @vmulh_vx_nxv2i32(<vscale x 2 x i32> %va, i32 %x) {
117 ; CHECK-LABEL: vmulh_vx_nxv2i32:
119 ; CHECK-NEXT: vsetvli a1, zero, e32, m1, ta, ma
120 ; CHECK-NEXT: vmulh.vx v8, v8, a0
122 %head1 = insertelement <vscale x 2 x i32> poison, i32 %x, i32 0
123 %splat1 = shufflevector <vscale x 2 x i32> %head1, <vscale x 2 x i32> poison, <vscale x 2 x i32> zeroinitializer
124 %vb = sext <vscale x 2 x i32> %splat1 to <vscale x 2 x i64>
125 %vc = sext <vscale x 2 x i32> %va to <vscale x 2 x i64>
126 %vd = mul <vscale x 2 x i64> %vb, %vc
127 %head2 = insertelement <vscale x 2 x i64> poison, i64 32, i32 0
128 %splat2 = shufflevector <vscale x 2 x i64> %head2, <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
129 %ve = lshr <vscale x 2 x i64> %vd, %splat2
130 %vf = trunc <vscale x 2 x i64> %ve to <vscale x 2 x i32>
131 ret <vscale x 2 x i32> %vf
134 define <vscale x 2 x i32> @vmulh_vi_nxv2i32_0(<vscale x 2 x i32> %va) {
135 ; CHECK-LABEL: vmulh_vi_nxv2i32_0:
137 ; CHECK-NEXT: li a0, -7
138 ; CHECK-NEXT: vsetvli a1, zero, e32, m1, ta, ma
139 ; CHECK-NEXT: vmulh.vx v8, v8, a0
141 %head1 = insertelement <vscale x 2 x i32> poison, i32 -7, i32 0
142 %splat1 = shufflevector <vscale x 2 x i32> %head1, <vscale x 2 x i32> poison, <vscale x 2 x i32> zeroinitializer
143 %vb = sext <vscale x 2 x i32> %splat1 to <vscale x 2 x i64>
144 %vc = sext <vscale x 2 x i32> %va to <vscale x 2 x i64>
145 %vd = mul <vscale x 2 x i64> %vb, %vc
146 %head2 = insertelement <vscale x 2 x i64> poison, i64 32, i32 0
147 %splat2 = shufflevector <vscale x 2 x i64> %head2, <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
148 %ve = lshr <vscale x 2 x i64> %vd, %splat2
149 %vf = trunc <vscale x 2 x i64> %ve to <vscale x 2 x i32>
150 ret <vscale x 2 x i32> %vf
153 define <vscale x 2 x i32> @vmulh_vi_nxv2i32_1(<vscale x 2 x i32> %va) {
154 ; CHECK-LABEL: vmulh_vi_nxv2i32_1:
156 ; CHECK-NEXT: li a0, 16
157 ; CHECK-NEXT: vsetvli a1, zero, e32, m1, ta, ma
158 ; CHECK-NEXT: vmulh.vx v8, v8, a0
160 %head1 = insertelement <vscale x 2 x i32> poison, i32 16, i32 0
161 %splat1 = shufflevector <vscale x 2 x i32> %head1, <vscale x 2 x i32> poison, <vscale x 2 x i32> zeroinitializer
162 %vb = sext <vscale x 2 x i32> %splat1 to <vscale x 2 x i64>
163 %vc = sext <vscale x 2 x i32> %va to <vscale x 2 x i64>
164 %vd = mul <vscale x 2 x i64> %vb, %vc
165 %head2 = insertelement <vscale x 2 x i64> poison, i64 32, i32 0
166 %splat2 = shufflevector <vscale x 2 x i64> %head2, <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
167 %ve = lshr <vscale x 2 x i64> %vd, %splat2
168 %vf = trunc <vscale x 2 x i64> %ve to <vscale x 2 x i32>
169 ret <vscale x 2 x i32> %vf
172 define <vscale x 4 x i32> @vmulh_vv_nxv4i32(<vscale x 4 x i32> %va, <vscale x 4 x i32> %vb) {
173 ; CHECK-LABEL: vmulh_vv_nxv4i32:
175 ; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, ma
176 ; CHECK-NEXT: vmulh.vv v8, v10, v8
178 %vc = sext <vscale x 4 x i32> %vb to <vscale x 4 x i64>
179 %vd = sext <vscale x 4 x i32> %va to <vscale x 4 x i64>
180 %ve = mul <vscale x 4 x i64> %vc, %vd
181 %head = insertelement <vscale x 4 x i64> poison, i64 32, i32 0
182 %splat = shufflevector <vscale x 4 x i64> %head, <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer
183 %vf = lshr <vscale x 4 x i64> %ve, %splat
184 %vg = trunc <vscale x 4 x i64> %vf to <vscale x 4 x i32>
185 ret <vscale x 4 x i32> %vg
188 define <vscale x 4 x i32> @vmulh_vx_nxv4i32(<vscale x 4 x i32> %va, i32 %x) {
189 ; CHECK-LABEL: vmulh_vx_nxv4i32:
191 ; CHECK-NEXT: vsetvli a1, zero, e32, m2, ta, ma
192 ; CHECK-NEXT: vmulh.vx v8, v8, a0
194 %head1 = insertelement <vscale x 4 x i32> poison, i32 %x, i32 0
195 %splat1 = shufflevector <vscale x 4 x i32> %head1, <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
196 %vb = sext <vscale x 4 x i32> %splat1 to <vscale x 4 x i64>
197 %vc = sext <vscale x 4 x i32> %va to <vscale x 4 x i64>
198 %vd = mul <vscale x 4 x i64> %vb, %vc
199 %head2 = insertelement <vscale x 4 x i64> poison, i64 32, i32 0
200 %splat2 = shufflevector <vscale x 4 x i64> %head2, <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer
201 %ve = lshr <vscale x 4 x i64> %vd, %splat2
202 %vf = trunc <vscale x 4 x i64> %ve to <vscale x 4 x i32>
203 ret <vscale x 4 x i32> %vf
206 define <vscale x 4 x i32> @vmulh_vi_nxv4i32_0(<vscale x 4 x i32> %va) {
207 ; CHECK-LABEL: vmulh_vi_nxv4i32_0:
209 ; CHECK-NEXT: li a0, -7
210 ; CHECK-NEXT: vsetvli a1, zero, e32, m2, ta, ma
211 ; CHECK-NEXT: vmulh.vx v8, v8, a0
213 %head1 = insertelement <vscale x 4 x i32> poison, i32 -7, i32 0
214 %splat1 = shufflevector <vscale x 4 x i32> %head1, <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
215 %vb = sext <vscale x 4 x i32> %splat1 to <vscale x 4 x i64>
216 %vc = sext <vscale x 4 x i32> %va to <vscale x 4 x i64>
217 %vd = mul <vscale x 4 x i64> %vb, %vc
218 %head2 = insertelement <vscale x 4 x i64> poison, i64 32, i32 0
219 %splat2 = shufflevector <vscale x 4 x i64> %head2, <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer
220 %ve = lshr <vscale x 4 x i64> %vd, %splat2
221 %vf = trunc <vscale x 4 x i64> %ve to <vscale x 4 x i32>
222 ret <vscale x 4 x i32> %vf
225 define <vscale x 4 x i32> @vmulh_vi_nxv4i32_1(<vscale x 4 x i32> %va) {
226 ; CHECK-LABEL: vmulh_vi_nxv4i32_1:
228 ; CHECK-NEXT: li a0, 16
229 ; CHECK-NEXT: vsetvli a1, zero, e32, m2, ta, ma
230 ; CHECK-NEXT: vmulh.vx v8, v8, a0
232 %head1 = insertelement <vscale x 4 x i32> poison, i32 16, i32 0
233 %splat1 = shufflevector <vscale x 4 x i32> %head1, <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
234 %vb = sext <vscale x 4 x i32> %splat1 to <vscale x 4 x i64>
235 %vc = sext <vscale x 4 x i32> %va to <vscale x 4 x i64>
236 %vd = mul <vscale x 4 x i64> %vb, %vc
237 %head2 = insertelement <vscale x 4 x i64> poison, i64 32, i32 0
238 %splat2 = shufflevector <vscale x 4 x i64> %head2, <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer
239 %ve = lshr <vscale x 4 x i64> %vd, %splat2
240 %vf = trunc <vscale x 4 x i64> %ve to <vscale x 4 x i32>
241 ret <vscale x 4 x i32> %vf
244 define <vscale x 8 x i32> @vmulh_vv_nxv8i32(<vscale x 8 x i32> %va, <vscale x 8 x i32> %vb) {
245 ; CHECK-LABEL: vmulh_vv_nxv8i32:
247 ; CHECK-NEXT: vsetvli a0, zero, e32, m4, ta, ma
248 ; CHECK-NEXT: vmulh.vv v8, v12, v8
250 %vc = sext <vscale x 8 x i32> %vb to <vscale x 8 x i64>
251 %vd = sext <vscale x 8 x i32> %va to <vscale x 8 x i64>
252 %ve = mul <vscale x 8 x i64> %vc, %vd
253 %head = insertelement <vscale x 8 x i64> poison, i64 32, i32 0
254 %splat = shufflevector <vscale x 8 x i64> %head, <vscale x 8 x i64> poison, <vscale x 8 x i32> zeroinitializer
255 %vf = lshr <vscale x 8 x i64> %ve, %splat
256 %vg = trunc <vscale x 8 x i64> %vf to <vscale x 8 x i32>
257 ret <vscale x 8 x i32> %vg
260 define <vscale x 8 x i32> @vmulh_vx_nxv8i32(<vscale x 8 x i32> %va, i32 %x) {
261 ; CHECK-LABEL: vmulh_vx_nxv8i32:
263 ; CHECK-NEXT: vsetvli a1, zero, e32, m4, ta, ma
264 ; CHECK-NEXT: vmulh.vx v8, v8, a0
266 %head1 = insertelement <vscale x 8 x i32> poison, i32 %x, i32 0
267 %splat1 = shufflevector <vscale x 8 x i32> %head1, <vscale x 8 x i32> poison, <vscale x 8 x i32> zeroinitializer
268 %vb = sext <vscale x 8 x i32> %splat1 to <vscale x 8 x i64>
269 %vc = sext <vscale x 8 x i32> %va to <vscale x 8 x i64>
270 %vd = mul <vscale x 8 x i64> %vb, %vc
271 %head2 = insertelement <vscale x 8 x i64> poison, i64 32, i32 0
272 %splat2 = shufflevector <vscale x 8 x i64> %head2, <vscale x 8 x i64> poison, <vscale x 8 x i32> zeroinitializer
273 %ve = lshr <vscale x 8 x i64> %vd, %splat2
274 %vf = trunc <vscale x 8 x i64> %ve to <vscale x 8 x i32>
275 ret <vscale x 8 x i32> %vf
278 define <vscale x 8 x i32> @vmulh_vi_nxv8i32_0(<vscale x 8 x i32> %va) {
279 ; CHECK-LABEL: vmulh_vi_nxv8i32_0:
281 ; CHECK-NEXT: li a0, -7
282 ; CHECK-NEXT: vsetvli a1, zero, e32, m4, ta, ma
283 ; CHECK-NEXT: vmulh.vx v8, v8, a0
285 %head1 = insertelement <vscale x 8 x i32> poison, i32 -7, i32 0
286 %splat1 = shufflevector <vscale x 8 x i32> %head1, <vscale x 8 x i32> poison, <vscale x 8 x i32> zeroinitializer
287 %vb = sext <vscale x 8 x i32> %splat1 to <vscale x 8 x i64>
288 %vc = sext <vscale x 8 x i32> %va to <vscale x 8 x i64>
289 %vd = mul <vscale x 8 x i64> %vb, %vc
290 %head2 = insertelement <vscale x 8 x i64> poison, i64 32, i32 0
291 %splat2 = shufflevector <vscale x 8 x i64> %head2, <vscale x 8 x i64> poison, <vscale x 8 x i32> zeroinitializer
292 %ve = lshr <vscale x 8 x i64> %vd, %splat2
293 %vf = trunc <vscale x 8 x i64> %ve to <vscale x 8 x i32>
294 ret <vscale x 8 x i32> %vf
297 define <vscale x 8 x i32> @vmulh_vi_nxv8i32_1(<vscale x 8 x i32> %va) {
298 ; CHECK-LABEL: vmulh_vi_nxv8i32_1:
300 ; CHECK-NEXT: li a0, 16
301 ; CHECK-NEXT: vsetvli a1, zero, e32, m4, ta, ma
302 ; CHECK-NEXT: vmulh.vx v8, v8, a0
304 %head1 = insertelement <vscale x 8 x i32> poison, i32 16, i32 0
305 %splat1 = shufflevector <vscale x 8 x i32> %head1, <vscale x 8 x i32> poison, <vscale x 8 x i32> zeroinitializer
306 %vb = sext <vscale x 8 x i32> %splat1 to <vscale x 8 x i64>
307 %vc = sext <vscale x 8 x i32> %va to <vscale x 8 x i64>
308 %vd = mul <vscale x 8 x i64> %vb, %vc
309 %head2 = insertelement <vscale x 8 x i64> poison, i64 32, i32 0
310 %splat2 = shufflevector <vscale x 8 x i64> %head2, <vscale x 8 x i64> poison, <vscale x 8 x i32> zeroinitializer
311 %ve = lshr <vscale x 8 x i64> %vd, %splat2
312 %vf = trunc <vscale x 8 x i64> %ve to <vscale x 8 x i32>
313 ret <vscale x 8 x i32> %vf