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.
7 define void @vectorDiv (ptr addrspace(1) %nsource, ptr addrspace(1) %dsource, ptr addrspace(1) %qdest) nounwind {
8 ; CHECK-LABEL: vectorDiv:
9 ; CHECK: # %bb.0: # %entry
10 ; CHECK-NEXT: movq %rdx, %rcx
11 ; CHECK-NEXT: movq %rdi, -{{[0-9]+}}(%rsp)
12 ; CHECK-NEXT: movq %rsi, -{{[0-9]+}}(%rsp)
13 ; CHECK-NEXT: movq %rdx, -{{[0-9]+}}(%rsp)
14 ; CHECK-NEXT: movslq -{{[0-9]+}}(%rsp), %r8
15 ; CHECK-NEXT: movq (%rdi,%r8,8), %rdi
16 ; CHECK-NEXT: movq (%rsi,%r8,8), %r9
17 ; CHECK-NEXT: movq %rdi, %rax
18 ; CHECK-NEXT: shrq $32, %rax
19 ; CHECK-NEXT: movq %r9, %rsi
20 ; CHECK-NEXT: shrq $32, %rsi
21 ; CHECK-NEXT: # kill: def $eax killed $eax killed $rax
23 ; CHECK-NEXT: idivl %esi
24 ; CHECK-NEXT: movl %eax, %esi
25 ; CHECK-NEXT: movl %edi, %eax
27 ; CHECK-NEXT: idivl %r9d
28 ; CHECK-NEXT: movd %eax, %xmm0
29 ; CHECK-NEXT: pinsrd $1, %esi, %xmm0
30 ; CHECK-NEXT: movq %xmm0, (%rcx,%r8,8)
33 %nsource.addr = alloca ptr addrspace(1), align 4
34 %dsource.addr = alloca ptr addrspace(1), align 4
35 %qdest.addr = alloca ptr addrspace(1), align 4
36 %index = alloca i32, align 4
37 store ptr addrspace(1) %nsource, ptr %nsource.addr
38 store ptr addrspace(1) %dsource, ptr %dsource.addr
39 store ptr addrspace(1) %qdest, ptr %qdest.addr
40 %tmp = load ptr addrspace(1), ptr %qdest.addr
41 %tmp1 = load i32, ptr %index
42 %arrayidx = getelementptr <2 x i32>, ptr addrspace(1) %tmp, i32 %tmp1
43 %tmp2 = load ptr addrspace(1), ptr %nsource.addr
44 %tmp3 = load i32, ptr %index
45 %arrayidx4 = getelementptr <2 x i32>, ptr addrspace(1) %tmp2, i32 %tmp3
46 %tmp5 = load <2 x i32>, ptr addrspace(1) %arrayidx4
47 %tmp6 = load ptr addrspace(1), ptr %dsource.addr
48 %tmp7 = load i32, ptr %index
49 %arrayidx8 = getelementptr <2 x i32>, ptr addrspace(1) %tmp6, i32 %tmp7
50 %tmp9 = load <2 x i32>, ptr addrspace(1) %arrayidx8
51 %tmp10 = sdiv <2 x i32> %tmp5, %tmp9
52 store <2 x i32> %tmp10, ptr addrspace(1) %arrayidx
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: movsbl %dil, %eax
60 ; CHECK-NEXT: idivb %cl
61 ; CHECK-NEXT: movl %eax, %ecx
62 ; CHECK-NEXT: movsbl %sil, %eax
63 ; CHECK-NEXT: idivb %r8b
64 ; CHECK-NEXT: movl %eax, %esi
65 ; CHECK-NEXT: movsbl %dl, %eax
66 ; CHECK-NEXT: idivb %r9b
67 ; CHECK-NEXT: movl %eax, %edi
68 ; CHECK-NEXT: movl %ecx, %eax
69 ; CHECK-NEXT: movl %esi, %edx
70 ; CHECK-NEXT: movl %edi, %ecx
72 %div.r = sdiv <3 x i8> %num, %div
76 define <3 x i8> @test_uchar_div(<3 x i8> %num, <3 x i8> %div) {
77 ; CHECK-LABEL: test_uchar_div:
79 ; CHECK-NEXT: movzbl %dil, %eax
80 ; CHECK-NEXT: divb %cl
81 ; CHECK-NEXT: movl %eax, %ecx
82 ; CHECK-NEXT: movzbl %sil, %eax
83 ; CHECK-NEXT: divb %r8b
84 ; CHECK-NEXT: movl %eax, %esi
85 ; CHECK-NEXT: movzbl %dl, %eax
86 ; CHECK-NEXT: divb %r9b
87 ; CHECK-NEXT: movl %eax, %edi
88 ; CHECK-NEXT: movl %ecx, %eax
89 ; CHECK-NEXT: movl %esi, %edx
90 ; CHECK-NEXT: movl %edi, %ecx
92 %div.r = udiv <3 x i8> %num, %div
96 define <5 x i16> @test_short_div(<5 x i16> %num, <5 x i16> %div) {
97 ; CHECK-LABEL: test_short_div:
99 ; CHECK-NEXT: pextrw $4, %xmm0, %eax
100 ; CHECK-NEXT: pextrw $4, %xmm1, %ecx
101 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
103 ; CHECK-NEXT: idivw %cx
104 ; CHECK-NEXT: movl %eax, %ecx
105 ; CHECK-NEXT: pextrw $3, %xmm0, %eax
106 ; CHECK-NEXT: pextrw $3, %xmm1, %esi
107 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
109 ; CHECK-NEXT: idivw %si
110 ; CHECK-NEXT: movl %eax, %esi
111 ; CHECK-NEXT: pextrw $2, %xmm0, %eax
112 ; CHECK-NEXT: pextrw $2, %xmm1, %edi
113 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
115 ; CHECK-NEXT: idivw %di
116 ; CHECK-NEXT: movl %eax, %edi
117 ; CHECK-NEXT: movd %xmm0, %eax
118 ; CHECK-NEXT: movd %xmm1, %r8d
119 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
121 ; CHECK-NEXT: idivw %r8w
122 ; CHECK-NEXT: movl %eax, %r8d
123 ; CHECK-NEXT: pextrw $1, %xmm0, %eax
124 ; CHECK-NEXT: pextrw $1, %xmm1, %r9d
125 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
127 ; CHECK-NEXT: idivw %r9w
128 ; CHECK-NEXT: # kill: def $ax killed $ax def $eax
129 ; CHECK-NEXT: movd %r8d, %xmm0
130 ; CHECK-NEXT: pinsrw $1, %eax, %xmm0
131 ; CHECK-NEXT: pinsrw $2, %edi, %xmm0
132 ; CHECK-NEXT: pinsrw $3, %esi, %xmm0
133 ; CHECK-NEXT: pinsrw $4, %ecx, %xmm0
135 %div.r = sdiv <5 x i16> %num, %div
139 define <4 x i16> @test_ushort_div(<4 x i16> %num, <4 x i16> %div) {
140 ; CHECK-LABEL: test_ushort_div:
142 ; CHECK-NEXT: pextrw $1, %xmm0, %eax
143 ; CHECK-NEXT: pextrw $1, %xmm1, %ecx
144 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
145 ; CHECK-NEXT: xorl %edx, %edx
146 ; CHECK-NEXT: divw %cx
147 ; CHECK-NEXT: movl %eax, %ecx
148 ; CHECK-NEXT: movd %xmm0, %eax
149 ; CHECK-NEXT: movd %xmm1, %esi
150 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
151 ; CHECK-NEXT: xorl %edx, %edx
152 ; CHECK-NEXT: divw %si
153 ; CHECK-NEXT: # kill: def $ax killed $ax def $eax
154 ; CHECK-NEXT: movd %eax, %xmm2
155 ; CHECK-NEXT: pinsrw $1, %ecx, %xmm2
156 ; CHECK-NEXT: pextrw $2, %xmm0, %eax
157 ; CHECK-NEXT: pextrw $2, %xmm1, %ecx
158 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
159 ; CHECK-NEXT: xorl %edx, %edx
160 ; CHECK-NEXT: divw %cx
161 ; CHECK-NEXT: # kill: def $ax killed $ax def $eax
162 ; CHECK-NEXT: pinsrw $2, %eax, %xmm2
163 ; CHECK-NEXT: pextrw $3, %xmm0, %eax
164 ; CHECK-NEXT: pextrw $3, %xmm1, %ecx
165 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
166 ; CHECK-NEXT: xorl %edx, %edx
167 ; CHECK-NEXT: divw %cx
168 ; CHECK-NEXT: # kill: def $ax killed $ax def $eax
169 ; CHECK-NEXT: pinsrw $3, %eax, %xmm2
170 ; CHECK-NEXT: movdqa %xmm2, %xmm0
172 %div.r = udiv <4 x i16> %num, %div
176 define <3 x i32> @test_uint_div(<3 x i32> %num, <3 x i32> %div) {
177 ; CHECK-LABEL: test_uint_div:
179 ; CHECK-NEXT: pextrd $2, %xmm0, %eax
180 ; CHECK-NEXT: pextrd $2, %xmm1, %ecx
181 ; CHECK-NEXT: xorl %edx, %edx
182 ; CHECK-NEXT: divl %ecx
183 ; CHECK-NEXT: movl %eax, %ecx
184 ; CHECK-NEXT: pextrd $1, %xmm0, %eax
185 ; CHECK-NEXT: pextrd $1, %xmm1, %esi
186 ; CHECK-NEXT: xorl %edx, %edx
187 ; CHECK-NEXT: divl %esi
188 ; CHECK-NEXT: movl %eax, %esi
189 ; CHECK-NEXT: movd %xmm0, %eax
190 ; CHECK-NEXT: movd %xmm1, %edi
191 ; CHECK-NEXT: xorl %edx, %edx
192 ; CHECK-NEXT: divl %edi
193 ; CHECK-NEXT: movd %eax, %xmm0
194 ; CHECK-NEXT: pinsrd $1, %esi, %xmm0
195 ; CHECK-NEXT: pinsrd $2, %ecx, %xmm0
197 %div.r = udiv <3 x i32> %num, %div
201 define <3 x i64> @test_long_div(<3 x i64> %num, <3 x i64> %div) {
202 ; CHECK-LABEL: test_long_div:
204 ; CHECK-NEXT: movq %rdx, %r10
205 ; CHECK-NEXT: movq %rdi, %rax
207 ; CHECK-NEXT: idivq %rcx
208 ; CHECK-NEXT: movq %rax, %rcx
209 ; CHECK-NEXT: movq %rsi, %rax
211 ; CHECK-NEXT: idivq %r8
212 ; CHECK-NEXT: movq %rax, %rsi
213 ; CHECK-NEXT: movq %r10, %rax
215 ; CHECK-NEXT: idivq %r9
216 ; CHECK-NEXT: movq %rax, %rdi
217 ; CHECK-NEXT: movq %rcx, %rax
218 ; CHECK-NEXT: movq %rsi, %rdx
219 ; CHECK-NEXT: movq %rdi, %rcx
221 %div.r = sdiv <3 x i64> %num, %div
225 define <3 x i64> @test_ulong_div(<3 x i64> %num, <3 x i64> %div) {
226 ; CHECK-LABEL: test_ulong_div:
228 ; CHECK-NEXT: movq %rdx, %r10
229 ; CHECK-NEXT: movq %rdi, %rax
230 ; CHECK-NEXT: xorl %edx, %edx
231 ; CHECK-NEXT: divq %rcx
232 ; CHECK-NEXT: movq %rax, %rcx
233 ; CHECK-NEXT: movq %rsi, %rax
234 ; CHECK-NEXT: xorl %edx, %edx
235 ; CHECK-NEXT: divq %r8
236 ; CHECK-NEXT: movq %rax, %rsi
237 ; CHECK-NEXT: movq %r10, %rax
238 ; CHECK-NEXT: xorl %edx, %edx
239 ; CHECK-NEXT: divq %r9
240 ; CHECK-NEXT: movq %rax, %rdi
241 ; CHECK-NEXT: movq %rcx, %rax
242 ; CHECK-NEXT: movq %rsi, %rdx
243 ; CHECK-NEXT: movq %rdi, %rcx
245 %div.r = udiv <3 x i64> %num, %div
249 define <4 x i8> @test_char_rem(<4 x i8> %num, <4 x i8> %rem) {
250 ; CHECK-LABEL: test_char_rem:
252 ; CHECK-NEXT: pextrb $1, %xmm1, %ecx
253 ; CHECK-NEXT: pextrb $1, %xmm0, %eax
255 ; CHECK-NEXT: idivb %cl
256 ; CHECK-NEXT: movsbl %ah, %ecx
257 ; CHECK-NEXT: movd %xmm1, %edx
258 ; CHECK-NEXT: movd %xmm0, %eax
260 ; CHECK-NEXT: idivb %dl
261 ; CHECK-NEXT: movsbl %ah, %eax
262 ; CHECK-NEXT: movd %eax, %xmm2
263 ; CHECK-NEXT: pinsrb $1, %ecx, %xmm2
264 ; CHECK-NEXT: pextrb $2, %xmm1, %ecx
265 ; CHECK-NEXT: pextrb $2, %xmm0, %eax
267 ; CHECK-NEXT: idivb %cl
268 ; CHECK-NEXT: movsbl %ah, %eax
269 ; CHECK-NEXT: pinsrb $2, %eax, %xmm2
270 ; CHECK-NEXT: pextrb $3, %xmm1, %ecx
271 ; CHECK-NEXT: pextrb $3, %xmm0, %eax
273 ; CHECK-NEXT: idivb %cl
274 ; CHECK-NEXT: movsbl %ah, %eax
275 ; CHECK-NEXT: pinsrb $3, %eax, %xmm2
276 ; CHECK-NEXT: movdqa %xmm2, %xmm0
278 %rem.r = srem <4 x i8> %num, %rem
282 define <5 x i16> @test_short_rem(<5 x i16> %num, <5 x i16> %rem) {
283 ; CHECK-LABEL: test_short_rem:
285 ; CHECK-NEXT: pextrw $4, %xmm0, %eax
286 ; CHECK-NEXT: pextrw $4, %xmm1, %ecx
287 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
289 ; CHECK-NEXT: idivw %cx
290 ; CHECK-NEXT: movl %edx, %ecx
291 ; CHECK-NEXT: pextrw $3, %xmm0, %eax
292 ; CHECK-NEXT: pextrw $3, %xmm1, %esi
293 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
295 ; CHECK-NEXT: idivw %si
296 ; CHECK-NEXT: movl %edx, %esi
297 ; CHECK-NEXT: pextrw $2, %xmm0, %eax
298 ; CHECK-NEXT: pextrw $2, %xmm1, %edi
299 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
301 ; CHECK-NEXT: idivw %di
302 ; CHECK-NEXT: movl %edx, %edi
303 ; CHECK-NEXT: movd %xmm0, %eax
304 ; CHECK-NEXT: movd %xmm1, %r8d
305 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
307 ; CHECK-NEXT: idivw %r8w
308 ; CHECK-NEXT: movl %edx, %r8d
309 ; CHECK-NEXT: pextrw $1, %xmm0, %eax
310 ; CHECK-NEXT: pextrw $1, %xmm1, %r9d
311 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
313 ; CHECK-NEXT: idivw %r9w
314 ; CHECK-NEXT: # kill: def $dx killed $dx def $edx
315 ; CHECK-NEXT: movd %r8d, %xmm0
316 ; CHECK-NEXT: pinsrw $1, %edx, %xmm0
317 ; CHECK-NEXT: pinsrw $2, %edi, %xmm0
318 ; CHECK-NEXT: pinsrw $3, %esi, %xmm0
319 ; CHECK-NEXT: pinsrw $4, %ecx, %xmm0
321 %rem.r = srem <5 x i16> %num, %rem
325 define <4 x i32> @test_uint_rem(<4 x i32> %num, <4 x i32> %rem) {
326 ; CHECK-LABEL: test_uint_rem:
328 ; CHECK-NEXT: pextrd $1, %xmm0, %eax
329 ; CHECK-NEXT: pextrd $1, %xmm1, %ecx
331 ; CHECK-NEXT: idivl %ecx
332 ; CHECK-NEXT: movl %edx, %ecx
333 ; CHECK-NEXT: movd %xmm0, %eax
334 ; CHECK-NEXT: movd %xmm1, %esi
336 ; CHECK-NEXT: idivl %esi
337 ; CHECK-NEXT: movd %edx, %xmm2
338 ; CHECK-NEXT: pinsrd $1, %ecx, %xmm2
339 ; CHECK-NEXT: pextrd $2, %xmm0, %eax
340 ; CHECK-NEXT: pextrd $2, %xmm1, %ecx
342 ; CHECK-NEXT: idivl %ecx
343 ; CHECK-NEXT: pinsrd $2, %edx, %xmm2
344 ; CHECK-NEXT: pextrd $3, %xmm0, %eax
345 ; CHECK-NEXT: pextrd $3, %xmm1, %ecx
347 ; CHECK-NEXT: idivl %ecx
348 ; CHECK-NEXT: pinsrd $3, %edx, %xmm2
349 ; CHECK-NEXT: movdqa %xmm2, %xmm0
351 %rem.r = srem <4 x i32> %num, %rem
356 define <5 x i64> @test_ulong_rem(<5 x i64> %num, <5 x i64> %rem) {
357 ; CHECK-LABEL: test_ulong_rem:
359 ; CHECK-NEXT: movq %rdx, %rax
360 ; CHECK-NEXT: xorl %edx, %edx
361 ; CHECK-NEXT: divq {{[0-9]+}}(%rsp)
362 ; CHECK-NEXT: movq %rdx, %xmm0
363 ; CHECK-NEXT: movq %rsi, %rax
364 ; CHECK-NEXT: xorl %edx, %edx
365 ; CHECK-NEXT: divq {{[0-9]+}}(%rsp)
366 ; CHECK-NEXT: movq %rdx, %xmm1
367 ; CHECK-NEXT: punpcklqdq {{.*#+}} xmm1 = xmm1[0],xmm0[0]
368 ; CHECK-NEXT: movq %r8, %rax
369 ; CHECK-NEXT: xorl %edx, %edx
370 ; CHECK-NEXT: divq {{[0-9]+}}(%rsp)
371 ; CHECK-NEXT: movq %rdx, %xmm0
372 ; CHECK-NEXT: movq %rcx, %rax
373 ; CHECK-NEXT: xorl %edx, %edx
374 ; CHECK-NEXT: divq {{[0-9]+}}(%rsp)
375 ; CHECK-NEXT: movq %rdx, %xmm2
376 ; CHECK-NEXT: punpcklqdq {{.*#+}} xmm2 = xmm2[0],xmm0[0]
377 ; CHECK-NEXT: movq %r9, %rax
378 ; CHECK-NEXT: xorl %edx, %edx
379 ; CHECK-NEXT: divq {{[0-9]+}}(%rsp)
380 ; CHECK-NEXT: movq %rdx, 32(%rdi)
381 ; CHECK-NEXT: movdqa %xmm2, 16(%rdi)
382 ; CHECK-NEXT: movdqa %xmm1, (%rdi)
383 ; CHECK-NEXT: movq %rdi, %rax
385 %rem.r = urem <5 x i64> %num, %rem
389 define void @test_int_div(ptr %dest, ptr %old, i32 %n) {
390 ; CHECK-LABEL: test_int_div:
391 ; CHECK: # %bb.0: # %entry
392 ; CHECK-NEXT: testl %edx, %edx
393 ; CHECK-NEXT: jle .LBB12_3
394 ; CHECK-NEXT: # %bb.1: # %bb.nph
395 ; CHECK-NEXT: movl %edx, %ecx
396 ; CHECK-NEXT: xorl %r10d, %r10d
397 ; CHECK-NEXT: .p2align 4, 0x90
398 ; CHECK-NEXT: .LBB12_2: # %for.body
399 ; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
400 ; CHECK-NEXT: movl (%rdi,%r10), %r8d
401 ; CHECK-NEXT: movl 4(%rdi,%r10), %eax
403 ; CHECK-NEXT: idivl 4(%rsi,%r10)
404 ; CHECK-NEXT: movl %eax, %r9d
405 ; CHECK-NEXT: movl %r8d, %eax
407 ; CHECK-NEXT: idivl (%rsi,%r10)
408 ; CHECK-NEXT: movd %eax, %xmm0
409 ; CHECK-NEXT: pinsrd $1, %r9d, %xmm0
410 ; CHECK-NEXT: movl 8(%rdi,%r10), %eax
412 ; CHECK-NEXT: idivl 8(%rsi,%r10)
413 ; CHECK-NEXT: movl %eax, 8(%rdi,%r10)
414 ; CHECK-NEXT: movq %xmm0, (%rdi,%r10)
415 ; CHECK-NEXT: addq $16, %r10
416 ; CHECK-NEXT: decl %ecx
417 ; CHECK-NEXT: jne .LBB12_2
418 ; CHECK-NEXT: .LBB12_3: # %for.end
421 %cmp13 = icmp sgt i32 %n, 0
422 br i1 %cmp13, label %bb.nph, label %for.end
428 %i.014 = phi i32 [ 0, %bb.nph ], [ %inc, %for.body ]
429 %arrayidx11 = getelementptr <3 x i32>, ptr %dest, i32 %i.014
430 %tmp4 = load <3 x i32>, ptr %arrayidx11 ; <<3 x i32>> [#uses=1]
431 %arrayidx7 = getelementptr inbounds <3 x i32>, ptr %old, i32 %i.014
432 %tmp8 = load <3 x i32>, ptr %arrayidx7 ; <<3 x i32>> [#uses=1]
433 %div = sdiv <3 x i32> %tmp4, %tmp8
434 store <3 x i32> %div, ptr %arrayidx11
435 %inc = add nsw i32 %i.014, 1
436 %exitcond = icmp eq i32 %inc, %n
437 br i1 %exitcond, label %for.end, label %for.body
439 for.end: ; preds = %for.body, %entry