1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-- -mattr=+sse4.2 | FileCheck %s
4 ; Verify when widening a divide/remainder operation, we only generate a
5 ; divide/rem per element since divide/remainder can trap.
8 define void @vectorDiv (<2 x i32> addrspace(1)* %nsource, <2 x i32> addrspace(1)* %dsource, <2 x i32> addrspace(1)* %qdest) nounwind {
9 ; CHECK-LABEL: vectorDiv:
10 ; CHECK: # %bb.0: # %entry
11 ; CHECK-NEXT: movq %rdx, %r8
12 ; CHECK-NEXT: movq %rdi, -{{[0-9]+}}(%rsp)
13 ; CHECK-NEXT: movq %rsi, -{{[0-9]+}}(%rsp)
14 ; CHECK-NEXT: movq %rdx, -{{[0-9]+}}(%rsp)
15 ; CHECK-NEXT: movslq -{{[0-9]+}}(%rsp), %rcx
16 ; CHECK-NEXT: movq {{.*#+}} xmm0 = mem[0],zero
17 ; CHECK-NEXT: movq {{.*#+}} xmm1 = mem[0],zero
18 ; CHECK-NEXT: pextrd $1, %xmm0, %eax
19 ; CHECK-NEXT: pextrd $1, %xmm1, %esi
21 ; CHECK-NEXT: idivl %esi
22 ; CHECK-NEXT: movl %eax, %esi
23 ; CHECK-NEXT: movd %xmm0, %eax
24 ; CHECK-NEXT: movd %xmm1, %edi
26 ; CHECK-NEXT: idivl %edi
27 ; CHECK-NEXT: movd %eax, %xmm0
28 ; CHECK-NEXT: pinsrd $1, %esi, %xmm0
29 ; CHECK-NEXT: movq %xmm0, (%r8,%rcx,8)
32 %nsource.addr = alloca <2 x i32> addrspace(1)*, align 4
33 %dsource.addr = alloca <2 x i32> addrspace(1)*, align 4
34 %qdest.addr = alloca <2 x i32> addrspace(1)*, align 4
35 %index = alloca i32, align 4
36 store <2 x i32> addrspace(1)* %nsource, <2 x i32> addrspace(1)** %nsource.addr
37 store <2 x i32> addrspace(1)* %dsource, <2 x i32> addrspace(1)** %dsource.addr
38 store <2 x i32> addrspace(1)* %qdest, <2 x i32> addrspace(1)** %qdest.addr
39 %tmp = load <2 x i32> addrspace(1)*, <2 x i32> addrspace(1)** %qdest.addr
40 %tmp1 = load i32, i32* %index
41 %arrayidx = getelementptr <2 x i32>, <2 x i32> addrspace(1)* %tmp, i32 %tmp1
42 %tmp2 = load <2 x i32> addrspace(1)*, <2 x i32> addrspace(1)** %nsource.addr
43 %tmp3 = load i32, i32* %index
44 %arrayidx4 = getelementptr <2 x i32>, <2 x i32> addrspace(1)* %tmp2, i32 %tmp3
45 %tmp5 = load <2 x i32>, <2 x i32> addrspace(1)* %arrayidx4
46 %tmp6 = load <2 x i32> addrspace(1)*, <2 x i32> addrspace(1)** %dsource.addr
47 %tmp7 = load i32, i32* %index
48 %arrayidx8 = getelementptr <2 x i32>, <2 x i32> addrspace(1)* %tmp6, i32 %tmp7
49 %tmp9 = load <2 x i32>, <2 x i32> addrspace(1)* %arrayidx8
50 %tmp10 = sdiv <2 x i32> %tmp5, %tmp9
51 store <2 x i32> %tmp10, <2 x i32> addrspace(1)* %arrayidx
55 ; CHECK: test_char_div
56 define <3 x i8> @test_char_div(<3 x i8> %num, <3 x i8> %div) {
57 ; CHECK-LABEL: test_char_div:
59 ; CHECK-NEXT: movl %edx, %r10d
60 ; CHECK-NEXT: movl %edi, %eax
61 ; CHECK-NEXT: # kill: def $al killed $al killed $eax
63 ; CHECK-NEXT: idivb %cl
64 ; CHECK-NEXT: movl %eax, %edi
65 ; CHECK-NEXT: movl %esi, %eax
67 ; CHECK-NEXT: idivb %r8b
68 ; CHECK-NEXT: movl %eax, %edx
69 ; CHECK-NEXT: movl %r10d, %eax
71 ; CHECK-NEXT: idivb %r9b
72 ; CHECK-NEXT: movl %eax, %ecx
73 ; CHECK-NEXT: movl %edi, %eax
75 %div.r = sdiv <3 x i8> %num, %div
79 ; CHECK: test_uchar_div
80 define <3 x i8> @test_uchar_div(<3 x i8> %num, <3 x i8> %div) {
81 ; CHECK-LABEL: test_uchar_div:
83 ; CHECK-NEXT: movzbl %dil, %eax
84 ; CHECK-NEXT: # kill: def $eax killed $eax def $ax
85 ; CHECK-NEXT: divb %cl
86 ; CHECK-NEXT: movl %eax, %edi
87 ; CHECK-NEXT: movzbl %sil, %eax
88 ; CHECK-NEXT: # kill: def $eax killed $eax def $ax
89 ; CHECK-NEXT: divb %r8b
90 ; CHECK-NEXT: movl %eax, %esi
91 ; CHECK-NEXT: movzbl %dl, %eax
92 ; CHECK-NEXT: # kill: def $eax killed $eax def $ax
93 ; CHECK-NEXT: divb %r9b
94 ; CHECK-NEXT: movl %eax, %ecx
95 ; CHECK-NEXT: movl %edi, %eax
96 ; CHECK-NEXT: movl %esi, %edx
98 %div.r = udiv <3 x i8> %num, %div
102 ; CHECK: test_short_div
103 define <5 x i16> @test_short_div(<5 x i16> %num, <5 x i16> %div) {
104 ; CHECK-LABEL: test_short_div:
106 ; CHECK-NEXT: pextrw $4, %xmm0, %eax
107 ; CHECK-NEXT: pextrw $4, %xmm1, %ecx
108 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
110 ; CHECK-NEXT: idivw %cx
111 ; CHECK-NEXT: movl %eax, %r8d
112 ; CHECK-NEXT: pextrw $3, %xmm0, %eax
113 ; CHECK-NEXT: pextrw $3, %xmm1, %ecx
114 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
116 ; CHECK-NEXT: idivw %cx
117 ; CHECK-NEXT: movl %eax, %r9d
118 ; CHECK-NEXT: pextrw $2, %xmm0, %eax
119 ; CHECK-NEXT: pextrw $2, %xmm1, %ecx
120 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
122 ; CHECK-NEXT: idivw %cx
123 ; CHECK-NEXT: movl %eax, %edi
124 ; CHECK-NEXT: movd %xmm0, %eax
125 ; CHECK-NEXT: movd %xmm1, %ecx
126 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
128 ; CHECK-NEXT: idivw %cx
129 ; CHECK-NEXT: movl %eax, %ecx
130 ; CHECK-NEXT: pextrw $1, %xmm0, %eax
131 ; CHECK-NEXT: pextrw $1, %xmm1, %esi
132 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
134 ; CHECK-NEXT: idivw %si
135 ; CHECK-NEXT: # kill: def $ax killed $ax def $eax
136 ; CHECK-NEXT: movd %ecx, %xmm0
137 ; CHECK-NEXT: pinsrw $1, %eax, %xmm0
138 ; CHECK-NEXT: pinsrw $2, %edi, %xmm0
139 ; CHECK-NEXT: pinsrw $3, %r9d, %xmm0
140 ; CHECK-NEXT: pinsrw $4, %r8d, %xmm0
142 %div.r = sdiv <5 x i16> %num, %div
146 ; CHECK: test_ushort_div
147 define <4 x i16> @test_ushort_div(<4 x i16> %num, <4 x i16> %div) {
148 ; CHECK-LABEL: test_ushort_div:
150 ; CHECK-NEXT: pxor %xmm2, %xmm2
151 ; CHECK-NEXT: pblendw {{.*#+}} xmm1 = xmm1[0],xmm2[1],xmm1[2],xmm2[3],xmm1[4],xmm2[5],xmm1[6],xmm2[7]
152 ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm0[0],xmm2[1],xmm0[2],xmm2[3],xmm0[4],xmm2[5],xmm0[6],xmm2[7]
153 ; CHECK-NEXT: pextrd $1, %xmm0, %eax
154 ; CHECK-NEXT: pextrd $1, %xmm1, %ecx
155 ; CHECK-NEXT: xorl %edx, %edx
156 ; CHECK-NEXT: divl %ecx
157 ; CHECK-NEXT: movl %eax, %ecx
158 ; CHECK-NEXT: movd %xmm0, %eax
159 ; CHECK-NEXT: movd %xmm1, %esi
160 ; CHECK-NEXT: xorl %edx, %edx
161 ; CHECK-NEXT: divl %esi
162 ; CHECK-NEXT: movd %eax, %xmm2
163 ; CHECK-NEXT: pinsrd $1, %ecx, %xmm2
164 ; CHECK-NEXT: pextrd $2, %xmm0, %eax
165 ; CHECK-NEXT: pextrd $2, %xmm1, %ecx
166 ; CHECK-NEXT: xorl %edx, %edx
167 ; CHECK-NEXT: divl %ecx
168 ; CHECK-NEXT: pinsrd $2, %eax, %xmm2
169 ; CHECK-NEXT: pextrd $3, %xmm0, %eax
170 ; CHECK-NEXT: pextrd $3, %xmm1, %ecx
171 ; CHECK-NEXT: xorl %edx, %edx
172 ; CHECK-NEXT: divl %ecx
173 ; CHECK-NEXT: pinsrd $3, %eax, %xmm2
174 ; CHECK-NEXT: movdqa %xmm2, %xmm0
176 %div.r = udiv <4 x i16> %num, %div
180 ; CHECK: test_uint_div
181 define <3 x i32> @test_uint_div(<3 x i32> %num, <3 x i32> %div) {
182 ; CHECK-LABEL: test_uint_div:
184 ; CHECK-NEXT: pextrd $2, %xmm0, %eax
185 ; CHECK-NEXT: pextrd $2, %xmm1, %ecx
186 ; CHECK-NEXT: xorl %edx, %edx
187 ; CHECK-NEXT: divl %ecx
188 ; CHECK-NEXT: movl %eax, %ecx
189 ; CHECK-NEXT: pextrd $1, %xmm0, %eax
190 ; CHECK-NEXT: pextrd $1, %xmm1, %esi
191 ; CHECK-NEXT: xorl %edx, %edx
192 ; CHECK-NEXT: divl %esi
193 ; CHECK-NEXT: movl %eax, %esi
194 ; CHECK-NEXT: movd %xmm0, %eax
195 ; CHECK-NEXT: movd %xmm1, %edi
196 ; CHECK-NEXT: xorl %edx, %edx
197 ; CHECK-NEXT: divl %edi
198 ; CHECK-NEXT: movd %eax, %xmm0
199 ; CHECK-NEXT: pinsrd $1, %esi, %xmm0
200 ; CHECK-NEXT: pinsrd $2, %ecx, %xmm0
202 %div.r = udiv <3 x i32> %num, %div
206 ; CHECK: test_long_div
207 define <3 x i64> @test_long_div(<3 x i64> %num, <3 x i64> %div) {
208 ; CHECK-LABEL: test_long_div:
210 ; CHECK-NEXT: movq %rdx, %r10
211 ; CHECK-NEXT: movq %rdi, %rax
213 ; CHECK-NEXT: idivq %rcx
214 ; CHECK-NEXT: movq %rax, %rcx
215 ; CHECK-NEXT: movq %rsi, %rax
217 ; CHECK-NEXT: idivq %r8
218 ; CHECK-NEXT: movq %rax, %rsi
219 ; CHECK-NEXT: movq %r10, %rax
221 ; CHECK-NEXT: idivq %r9
222 ; CHECK-NEXT: movq %rax, %rdi
223 ; CHECK-NEXT: movq %rcx, %rax
224 ; CHECK-NEXT: movq %rsi, %rdx
225 ; CHECK-NEXT: movq %rdi, %rcx
227 %div.r = sdiv <3 x i64> %num, %div
231 ; CHECK: test_ulong_div
232 define <3 x i64> @test_ulong_div(<3 x i64> %num, <3 x i64> %div) {
233 ; CHECK-LABEL: test_ulong_div:
235 ; CHECK-NEXT: movq %rdx, %r10
236 ; CHECK-NEXT: movq %rdi, %rax
237 ; CHECK-NEXT: xorl %edx, %edx
238 ; CHECK-NEXT: divq %rcx
239 ; CHECK-NEXT: movq %rax, %rcx
240 ; CHECK-NEXT: movq %rsi, %rax
241 ; CHECK-NEXT: xorl %edx, %edx
242 ; CHECK-NEXT: divq %r8
243 ; CHECK-NEXT: movq %rax, %rsi
244 ; CHECK-NEXT: movq %r10, %rax
245 ; CHECK-NEXT: xorl %edx, %edx
246 ; CHECK-NEXT: divq %r9
247 ; CHECK-NEXT: movq %rax, %rdi
248 ; CHECK-NEXT: movq %rcx, %rax
249 ; CHECK-NEXT: movq %rsi, %rdx
250 ; CHECK-NEXT: movq %rdi, %rcx
252 %div.r = udiv <3 x i64> %num, %div
256 ; CHECK: test_char_rem
257 define <4 x i8> @test_char_rem(<4 x i8> %num, <4 x i8> %rem) {
258 ; CHECK-LABEL: test_char_rem:
260 ; CHECK-NEXT: pslld $24, %xmm1
261 ; CHECK-NEXT: psrad $24, %xmm1
262 ; CHECK-NEXT: pslld $24, %xmm0
263 ; CHECK-NEXT: psrad $24, %xmm0
264 ; CHECK-NEXT: pextrd $1, %xmm0, %eax
265 ; CHECK-NEXT: pextrd $1, %xmm1, %ecx
267 ; CHECK-NEXT: idivl %ecx
268 ; CHECK-NEXT: movl %edx, %ecx
269 ; CHECK-NEXT: movd %xmm0, %eax
270 ; CHECK-NEXT: movd %xmm1, %esi
272 ; CHECK-NEXT: idivl %esi
273 ; CHECK-NEXT: movd %edx, %xmm2
274 ; CHECK-NEXT: pinsrd $1, %ecx, %xmm2
275 ; CHECK-NEXT: pextrd $2, %xmm0, %eax
276 ; CHECK-NEXT: pextrd $2, %xmm1, %ecx
278 ; CHECK-NEXT: idivl %ecx
279 ; CHECK-NEXT: pinsrd $2, %edx, %xmm2
280 ; CHECK-NEXT: pextrd $3, %xmm0, %eax
281 ; CHECK-NEXT: pextrd $3, %xmm1, %ecx
283 ; CHECK-NEXT: idivl %ecx
284 ; CHECK-NEXT: pinsrd $3, %edx, %xmm2
285 ; CHECK-NEXT: movdqa %xmm2, %xmm0
287 %rem.r = srem <4 x i8> %num, %rem
291 ; CHECK: test_short_rem
292 define <5 x i16> @test_short_rem(<5 x i16> %num, <5 x i16> %rem) {
293 ; CHECK-LABEL: test_short_rem:
295 ; CHECK-NEXT: pextrw $4, %xmm0, %eax
296 ; CHECK-NEXT: pextrw $4, %xmm1, %ecx
297 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
299 ; CHECK-NEXT: idivw %cx
300 ; CHECK-NEXT: movl %edx, %r8d
301 ; CHECK-NEXT: pextrw $3, %xmm0, %eax
302 ; CHECK-NEXT: pextrw $3, %xmm1, %ecx
303 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
305 ; CHECK-NEXT: idivw %cx
306 ; CHECK-NEXT: movl %edx, %r9d
307 ; CHECK-NEXT: pextrw $2, %xmm0, %eax
308 ; CHECK-NEXT: pextrw $2, %xmm1, %ecx
309 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
311 ; CHECK-NEXT: idivw %cx
312 ; CHECK-NEXT: movl %edx, %edi
313 ; CHECK-NEXT: movd %xmm0, %eax
314 ; CHECK-NEXT: movd %xmm1, %ecx
315 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
317 ; CHECK-NEXT: idivw %cx
318 ; CHECK-NEXT: movl %edx, %ecx
319 ; CHECK-NEXT: pextrw $1, %xmm0, %eax
320 ; CHECK-NEXT: pextrw $1, %xmm1, %esi
321 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
323 ; CHECK-NEXT: idivw %si
324 ; CHECK-NEXT: # kill: def $dx killed $dx def $edx
325 ; CHECK-NEXT: movd %ecx, %xmm0
326 ; CHECK-NEXT: pinsrw $1, %edx, %xmm0
327 ; CHECK-NEXT: pinsrw $2, %edi, %xmm0
328 ; CHECK-NEXT: pinsrw $3, %r9d, %xmm0
329 ; CHECK-NEXT: pinsrw $4, %r8d, %xmm0
331 %rem.r = srem <5 x i16> %num, %rem
335 ; CHECK: test_uint_rem
336 define <4 x i32> @test_uint_rem(<4 x i32> %num, <4 x i32> %rem) {
337 ; CHECK-LABEL: test_uint_rem:
339 ; CHECK-NEXT: pextrd $1, %xmm0, %eax
340 ; CHECK-NEXT: pextrd $1, %xmm1, %ecx
342 ; CHECK-NEXT: idivl %ecx
343 ; CHECK-NEXT: movl %edx, %ecx
344 ; CHECK-NEXT: movd %xmm0, %eax
345 ; CHECK-NEXT: movd %xmm1, %esi
347 ; CHECK-NEXT: idivl %esi
348 ; CHECK-NEXT: movd %edx, %xmm2
349 ; CHECK-NEXT: pinsrd $1, %ecx, %xmm2
350 ; CHECK-NEXT: pextrd $2, %xmm0, %eax
351 ; CHECK-NEXT: pextrd $2, %xmm1, %ecx
353 ; CHECK-NEXT: idivl %ecx
354 ; CHECK-NEXT: pinsrd $2, %edx, %xmm2
355 ; CHECK-NEXT: pextrd $3, %xmm0, %eax
356 ; CHECK-NEXT: pextrd $3, %xmm1, %ecx
358 ; CHECK-NEXT: idivl %ecx
359 ; CHECK-NEXT: pinsrd $3, %edx, %xmm2
360 ; CHECK-NEXT: movdqa %xmm2, %xmm0
362 %rem.r = srem <4 x i32> %num, %rem
367 ; CHECK: test_ulong_rem
368 define <5 x i64> @test_ulong_rem(<5 x i64> %num, <5 x i64> %rem) {
369 ; CHECK-LABEL: test_ulong_rem:
371 ; CHECK-NEXT: movq %rdx, %rax
372 ; CHECK-NEXT: xorl %edx, %edx
373 ; CHECK-NEXT: divq {{[0-9]+}}(%rsp)
374 ; CHECK-NEXT: movq %rdx, %xmm0
375 ; CHECK-NEXT: movq %rsi, %rax
376 ; CHECK-NEXT: xorl %edx, %edx
377 ; CHECK-NEXT: divq {{[0-9]+}}(%rsp)
378 ; CHECK-NEXT: movq %rdx, %xmm1
379 ; CHECK-NEXT: punpcklqdq {{.*#+}} xmm1 = xmm1[0],xmm0[0]
380 ; CHECK-NEXT: movq %r8, %rax
381 ; CHECK-NEXT: xorl %edx, %edx
382 ; CHECK-NEXT: divq {{[0-9]+}}(%rsp)
383 ; CHECK-NEXT: movq %rdx, %xmm0
384 ; CHECK-NEXT: movq %rcx, %rax
385 ; CHECK-NEXT: xorl %edx, %edx
386 ; CHECK-NEXT: divq {{[0-9]+}}(%rsp)
387 ; CHECK-NEXT: movq %rdx, %xmm2
388 ; CHECK-NEXT: punpcklqdq {{.*#+}} xmm2 = xmm2[0],xmm0[0]
389 ; CHECK-NEXT: movq %r9, %rax
390 ; CHECK-NEXT: xorl %edx, %edx
391 ; CHECK-NEXT: divq {{[0-9]+}}(%rsp)
392 ; CHECK-NEXT: movq %rdx, 32(%rdi)
393 ; CHECK-NEXT: movdqa %xmm2, 16(%rdi)
394 ; CHECK-NEXT: movdqa %xmm1, (%rdi)
395 ; CHECK-NEXT: movq %rdi, %rax
397 %rem.r = urem <5 x i64> %num, %rem
401 ; CHECK: test_int_div
402 define void @test_int_div(<3 x i32>* %dest, <3 x i32>* %old, i32 %n) {
403 ; CHECK-LABEL: test_int_div:
404 ; CHECK: # %bb.0: # %entry
405 ; CHECK-NEXT: testl %edx, %edx
406 ; CHECK-NEXT: jle .LBB12_3
407 ; CHECK-NEXT: # %bb.1: # %bb.nph
408 ; CHECK-NEXT: movl %edx, %r9d
409 ; CHECK-NEXT: xorl %ecx, %ecx
410 ; CHECK-NEXT: .p2align 4, 0x90
411 ; CHECK-NEXT: .LBB12_2: # %for.body
412 ; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
413 ; CHECK-NEXT: movdqa (%rdi,%rcx), %xmm0
414 ; CHECK-NEXT: movdqa (%rsi,%rcx), %xmm1
415 ; CHECK-NEXT: pextrd $1, %xmm0, %eax
416 ; CHECK-NEXT: pextrd $1, %xmm1, %r8d
418 ; CHECK-NEXT: idivl %r8d
419 ; CHECK-NEXT: movl %eax, %r8d
420 ; CHECK-NEXT: movd %xmm0, %eax
421 ; CHECK-NEXT: movd %xmm1, %r10d
423 ; CHECK-NEXT: idivl %r10d
424 ; CHECK-NEXT: movd %eax, %xmm2
425 ; CHECK-NEXT: pinsrd $1, %r8d, %xmm2
426 ; CHECK-NEXT: pextrd $2, %xmm0, %eax
427 ; CHECK-NEXT: pextrd $2, %xmm1, %r8d
429 ; CHECK-NEXT: idivl %r8d
430 ; CHECK-NEXT: movl %eax, 8(%rdi,%rcx)
431 ; CHECK-NEXT: movq %xmm2, (%rdi,%rcx)
432 ; CHECK-NEXT: addq $16, %rcx
433 ; CHECK-NEXT: decl %r9d
434 ; CHECK-NEXT: jne .LBB12_2
435 ; CHECK-NEXT: .LBB12_3: # %for.end
438 %cmp13 = icmp sgt i32 %n, 0
439 br i1 %cmp13, label %bb.nph, label %for.end
445 %i.014 = phi i32 [ 0, %bb.nph ], [ %inc, %for.body ]
446 %arrayidx11 = getelementptr <3 x i32>, <3 x i32>* %dest, i32 %i.014
447 %tmp4 = load <3 x i32>, <3 x i32>* %arrayidx11 ; <<3 x i32>> [#uses=1]
448 %arrayidx7 = getelementptr inbounds <3 x i32>, <3 x i32>* %old, i32 %i.014
449 %tmp8 = load <3 x i32>, <3 x i32>* %arrayidx7 ; <<3 x i32>> [#uses=1]
450 %div = sdiv <3 x i32> %tmp4, %tmp8
451 store <3 x i32> %div, <3 x i32>* %arrayidx11
452 %inc = add nsw i32 %i.014, 1
453 %exitcond = icmp eq i32 %inc, %n
454 br i1 %exitcond, label %for.end, label %for.body
456 for.end: ; preds = %for.body, %entry