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: movsbl %dil, %eax
60 ; CHECK-NEXT: idivb %cl
61 ; CHECK-NEXT: movl %eax, %edi
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, %ecx
68 ; CHECK-NEXT: movl %edi, %eax
69 ; CHECK-NEXT: movl %esi, %edx
71 %div.r = sdiv <3 x i8> %num, %div
75 ; CHECK: test_uchar_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, %edi
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, %ecx
88 ; CHECK-NEXT: movl %edi, %eax
89 ; CHECK-NEXT: movl %esi, %edx
91 %div.r = udiv <3 x i8> %num, %div
95 ; CHECK: test_short_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, %r8d
105 ; CHECK-NEXT: pextrw $3, %xmm0, %eax
106 ; CHECK-NEXT: pextrw $3, %xmm1, %ecx
107 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
109 ; CHECK-NEXT: idivw %cx
110 ; CHECK-NEXT: movl %eax, %r9d
111 ; CHECK-NEXT: pextrw $2, %xmm0, %eax
112 ; CHECK-NEXT: pextrw $2, %xmm1, %ecx
113 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
115 ; CHECK-NEXT: idivw %cx
116 ; CHECK-NEXT: movl %eax, %edi
117 ; CHECK-NEXT: movd %xmm0, %eax
118 ; CHECK-NEXT: movd %xmm1, %ecx
119 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
121 ; CHECK-NEXT: idivw %cx
122 ; CHECK-NEXT: movl %eax, %ecx
123 ; CHECK-NEXT: pextrw $1, %xmm0, %eax
124 ; CHECK-NEXT: pextrw $1, %xmm1, %esi
125 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
127 ; CHECK-NEXT: idivw %si
128 ; CHECK-NEXT: # kill: def $ax killed $ax def $eax
129 ; CHECK-NEXT: movd %ecx, %xmm0
130 ; CHECK-NEXT: pinsrw $1, %eax, %xmm0
131 ; CHECK-NEXT: pinsrw $2, %edi, %xmm0
132 ; CHECK-NEXT: pinsrw $3, %r9d, %xmm0
133 ; CHECK-NEXT: pinsrw $4, %r8d, %xmm0
135 %div.r = sdiv <5 x i16> %num, %div
139 ; CHECK: test_ushort_div
140 define <4 x i16> @test_ushort_div(<4 x i16> %num, <4 x i16> %div) {
141 ; CHECK-LABEL: test_ushort_div:
143 ; CHECK-NEXT: pextrw $1, %xmm0, %eax
144 ; CHECK-NEXT: pextrw $1, %xmm1, %ecx
145 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
146 ; CHECK-NEXT: xorl %edx, %edx
147 ; CHECK-NEXT: divw %cx
148 ; CHECK-NEXT: movl %eax, %ecx
149 ; CHECK-NEXT: movd %xmm0, %eax
150 ; CHECK-NEXT: movd %xmm1, %esi
151 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
152 ; CHECK-NEXT: xorl %edx, %edx
153 ; CHECK-NEXT: divw %si
154 ; CHECK-NEXT: # kill: def $ax killed $ax def $eax
155 ; CHECK-NEXT: movd %eax, %xmm2
156 ; CHECK-NEXT: pinsrw $1, %ecx, %xmm2
157 ; CHECK-NEXT: pextrw $2, %xmm0, %eax
158 ; CHECK-NEXT: pextrw $2, %xmm1, %ecx
159 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
160 ; CHECK-NEXT: xorl %edx, %edx
161 ; CHECK-NEXT: divw %cx
162 ; CHECK-NEXT: # kill: def $ax killed $ax def $eax
163 ; CHECK-NEXT: pinsrw $2, %eax, %xmm2
164 ; CHECK-NEXT: pextrw $3, %xmm0, %eax
165 ; CHECK-NEXT: pextrw $3, %xmm1, %ecx
166 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
167 ; CHECK-NEXT: xorl %edx, %edx
168 ; CHECK-NEXT: divw %cx
169 ; CHECK-NEXT: # kill: def $ax killed $ax def $eax
170 ; CHECK-NEXT: pinsrw $3, %eax, %xmm2
171 ; CHECK-NEXT: movdqa %xmm2, %xmm0
173 %div.r = udiv <4 x i16> %num, %div
177 ; CHECK: test_uint_div
178 define <3 x i32> @test_uint_div(<3 x i32> %num, <3 x i32> %div) {
179 ; CHECK-LABEL: test_uint_div:
181 ; CHECK-NEXT: pextrd $2, %xmm0, %eax
182 ; CHECK-NEXT: pextrd $2, %xmm1, %ecx
183 ; CHECK-NEXT: xorl %edx, %edx
184 ; CHECK-NEXT: divl %ecx
185 ; CHECK-NEXT: movl %eax, %ecx
186 ; CHECK-NEXT: pextrd $1, %xmm0, %eax
187 ; CHECK-NEXT: pextrd $1, %xmm1, %esi
188 ; CHECK-NEXT: xorl %edx, %edx
189 ; CHECK-NEXT: divl %esi
190 ; CHECK-NEXT: movl %eax, %esi
191 ; CHECK-NEXT: movd %xmm0, %eax
192 ; CHECK-NEXT: movd %xmm1, %edi
193 ; CHECK-NEXT: xorl %edx, %edx
194 ; CHECK-NEXT: divl %edi
195 ; CHECK-NEXT: movd %eax, %xmm0
196 ; CHECK-NEXT: pinsrd $1, %esi, %xmm0
197 ; CHECK-NEXT: pinsrd $2, %ecx, %xmm0
199 %div.r = udiv <3 x i32> %num, %div
203 ; CHECK: test_long_div
204 define <3 x i64> @test_long_div(<3 x i64> %num, <3 x i64> %div) {
205 ; CHECK-LABEL: test_long_div:
207 ; CHECK-NEXT: movq %rdx, %r10
208 ; CHECK-NEXT: movq %rdi, %rax
210 ; CHECK-NEXT: idivq %rcx
211 ; CHECK-NEXT: movq %rax, %rcx
212 ; CHECK-NEXT: movq %rsi, %rax
214 ; CHECK-NEXT: idivq %r8
215 ; CHECK-NEXT: movq %rax, %rsi
216 ; CHECK-NEXT: movq %r10, %rax
218 ; CHECK-NEXT: idivq %r9
219 ; CHECK-NEXT: movq %rax, %rdi
220 ; CHECK-NEXT: movq %rcx, %rax
221 ; CHECK-NEXT: movq %rsi, %rdx
222 ; CHECK-NEXT: movq %rdi, %rcx
224 %div.r = sdiv <3 x i64> %num, %div
228 ; CHECK: test_ulong_div
229 define <3 x i64> @test_ulong_div(<3 x i64> %num, <3 x i64> %div) {
230 ; CHECK-LABEL: test_ulong_div:
232 ; CHECK-NEXT: movq %rdx, %r10
233 ; CHECK-NEXT: movq %rdi, %rax
234 ; CHECK-NEXT: xorl %edx, %edx
235 ; CHECK-NEXT: divq %rcx
236 ; CHECK-NEXT: movq %rax, %rcx
237 ; CHECK-NEXT: movq %rsi, %rax
238 ; CHECK-NEXT: xorl %edx, %edx
239 ; CHECK-NEXT: divq %r8
240 ; CHECK-NEXT: movq %rax, %rsi
241 ; CHECK-NEXT: movq %r10, %rax
242 ; CHECK-NEXT: xorl %edx, %edx
243 ; CHECK-NEXT: divq %r9
244 ; CHECK-NEXT: movq %rax, %rdi
245 ; CHECK-NEXT: movq %rcx, %rax
246 ; CHECK-NEXT: movq %rsi, %rdx
247 ; CHECK-NEXT: movq %rdi, %rcx
249 %div.r = udiv <3 x i64> %num, %div
253 ; CHECK: test_char_rem
254 define <4 x i8> @test_char_rem(<4 x i8> %num, <4 x i8> %rem) {
255 ; CHECK-LABEL: test_char_rem:
257 ; CHECK-NEXT: pextrb $1, %xmm1, %ecx
258 ; CHECK-NEXT: pextrb $1, %xmm0, %eax
260 ; CHECK-NEXT: idivb %cl
261 ; CHECK-NEXT: movsbl %ah, %ecx
262 ; CHECK-NEXT: pextrb $0, %xmm1, %edx
263 ; CHECK-NEXT: pextrb $0, %xmm0, %eax
265 ; CHECK-NEXT: idivb %dl
266 ; CHECK-NEXT: movsbl %ah, %eax
267 ; CHECK-NEXT: movd %eax, %xmm2
268 ; CHECK-NEXT: pinsrb $1, %ecx, %xmm2
269 ; CHECK-NEXT: pextrb $2, %xmm1, %ecx
270 ; CHECK-NEXT: pextrb $2, %xmm0, %eax
272 ; CHECK-NEXT: idivb %cl
273 ; CHECK-NEXT: movsbl %ah, %eax
274 ; CHECK-NEXT: pinsrb $2, %eax, %xmm2
275 ; CHECK-NEXT: pextrb $3, %xmm1, %ecx
276 ; CHECK-NEXT: pextrb $3, %xmm0, %eax
278 ; CHECK-NEXT: idivb %cl
279 ; CHECK-NEXT: movsbl %ah, %eax
280 ; CHECK-NEXT: pinsrb $3, %eax, %xmm2
281 ; CHECK-NEXT: movdqa %xmm2, %xmm0
283 %rem.r = srem <4 x i8> %num, %rem
287 ; CHECK: test_short_rem
288 define <5 x i16> @test_short_rem(<5 x i16> %num, <5 x i16> %rem) {
289 ; CHECK-LABEL: test_short_rem:
291 ; CHECK-NEXT: pextrw $4, %xmm0, %eax
292 ; CHECK-NEXT: pextrw $4, %xmm1, %ecx
293 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
295 ; CHECK-NEXT: idivw %cx
296 ; CHECK-NEXT: movl %edx, %r8d
297 ; CHECK-NEXT: pextrw $3, %xmm0, %eax
298 ; CHECK-NEXT: pextrw $3, %xmm1, %ecx
299 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
301 ; CHECK-NEXT: idivw %cx
302 ; CHECK-NEXT: movl %edx, %r9d
303 ; CHECK-NEXT: pextrw $2, %xmm0, %eax
304 ; CHECK-NEXT: pextrw $2, %xmm1, %ecx
305 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
307 ; CHECK-NEXT: idivw %cx
308 ; CHECK-NEXT: movl %edx, %edi
309 ; CHECK-NEXT: movd %xmm0, %eax
310 ; CHECK-NEXT: movd %xmm1, %ecx
311 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
313 ; CHECK-NEXT: idivw %cx
314 ; CHECK-NEXT: movl %edx, %ecx
315 ; CHECK-NEXT: pextrw $1, %xmm0, %eax
316 ; CHECK-NEXT: pextrw $1, %xmm1, %esi
317 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
319 ; CHECK-NEXT: idivw %si
320 ; CHECK-NEXT: # kill: def $dx killed $dx def $edx
321 ; CHECK-NEXT: movd %ecx, %xmm0
322 ; CHECK-NEXT: pinsrw $1, %edx, %xmm0
323 ; CHECK-NEXT: pinsrw $2, %edi, %xmm0
324 ; CHECK-NEXT: pinsrw $3, %r9d, %xmm0
325 ; CHECK-NEXT: pinsrw $4, %r8d, %xmm0
327 %rem.r = srem <5 x i16> %num, %rem
331 ; CHECK: test_uint_rem
332 define <4 x i32> @test_uint_rem(<4 x i32> %num, <4 x i32> %rem) {
333 ; CHECK-LABEL: test_uint_rem:
335 ; CHECK-NEXT: pextrd $1, %xmm0, %eax
336 ; CHECK-NEXT: pextrd $1, %xmm1, %ecx
338 ; CHECK-NEXT: idivl %ecx
339 ; CHECK-NEXT: movl %edx, %ecx
340 ; CHECK-NEXT: movd %xmm0, %eax
341 ; CHECK-NEXT: movd %xmm1, %esi
343 ; CHECK-NEXT: idivl %esi
344 ; CHECK-NEXT: movd %edx, %xmm2
345 ; CHECK-NEXT: pinsrd $1, %ecx, %xmm2
346 ; CHECK-NEXT: pextrd $2, %xmm0, %eax
347 ; CHECK-NEXT: pextrd $2, %xmm1, %ecx
349 ; CHECK-NEXT: idivl %ecx
350 ; CHECK-NEXT: pinsrd $2, %edx, %xmm2
351 ; CHECK-NEXT: pextrd $3, %xmm0, %eax
352 ; CHECK-NEXT: pextrd $3, %xmm1, %ecx
354 ; CHECK-NEXT: idivl %ecx
355 ; CHECK-NEXT: pinsrd $3, %edx, %xmm2
356 ; CHECK-NEXT: movdqa %xmm2, %xmm0
358 %rem.r = srem <4 x i32> %num, %rem
363 ; CHECK: test_ulong_rem
364 define <5 x i64> @test_ulong_rem(<5 x i64> %num, <5 x i64> %rem) {
365 ; CHECK-LABEL: test_ulong_rem:
367 ; CHECK-NEXT: movq %rdx, %rax
368 ; CHECK-NEXT: xorl %edx, %edx
369 ; CHECK-NEXT: divq {{[0-9]+}}(%rsp)
370 ; CHECK-NEXT: movq %rdx, %xmm0
371 ; CHECK-NEXT: movq %rsi, %rax
372 ; CHECK-NEXT: xorl %edx, %edx
373 ; CHECK-NEXT: divq {{[0-9]+}}(%rsp)
374 ; CHECK-NEXT: movq %rdx, %xmm1
375 ; CHECK-NEXT: punpcklqdq {{.*#+}} xmm1 = xmm1[0],xmm0[0]
376 ; CHECK-NEXT: movq %r8, %rax
377 ; CHECK-NEXT: xorl %edx, %edx
378 ; CHECK-NEXT: divq {{[0-9]+}}(%rsp)
379 ; CHECK-NEXT: movq %rdx, %xmm0
380 ; CHECK-NEXT: movq %rcx, %rax
381 ; CHECK-NEXT: xorl %edx, %edx
382 ; CHECK-NEXT: divq {{[0-9]+}}(%rsp)
383 ; CHECK-NEXT: movq %rdx, %xmm2
384 ; CHECK-NEXT: punpcklqdq {{.*#+}} xmm2 = xmm2[0],xmm0[0]
385 ; CHECK-NEXT: movq %r9, %rax
386 ; CHECK-NEXT: xorl %edx, %edx
387 ; CHECK-NEXT: divq {{[0-9]+}}(%rsp)
388 ; CHECK-NEXT: movq %rdx, 32(%rdi)
389 ; CHECK-NEXT: movdqa %xmm2, 16(%rdi)
390 ; CHECK-NEXT: movdqa %xmm1, (%rdi)
391 ; CHECK-NEXT: movq %rdi, %rax
393 %rem.r = urem <5 x i64> %num, %rem
397 ; CHECK: test_int_div
398 define void @test_int_div(<3 x i32>* %dest, <3 x i32>* %old, i32 %n) {
399 ; CHECK-LABEL: test_int_div:
400 ; CHECK: # %bb.0: # %entry
401 ; CHECK-NEXT: testl %edx, %edx
402 ; CHECK-NEXT: jle .LBB12_3
403 ; CHECK-NEXT: # %bb.1: # %bb.nph
404 ; CHECK-NEXT: movl %edx, %r9d
405 ; CHECK-NEXT: xorl %ecx, %ecx
406 ; CHECK-NEXT: .p2align 4, 0x90
407 ; CHECK-NEXT: .LBB12_2: # %for.body
408 ; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
409 ; CHECK-NEXT: movdqa (%rdi,%rcx), %xmm0
410 ; CHECK-NEXT: movdqa (%rsi,%rcx), %xmm1
411 ; CHECK-NEXT: pextrd $1, %xmm0, %eax
412 ; CHECK-NEXT: pextrd $1, %xmm1, %r8d
414 ; CHECK-NEXT: idivl %r8d
415 ; CHECK-NEXT: movl %eax, %r8d
416 ; CHECK-NEXT: movd %xmm0, %eax
417 ; CHECK-NEXT: movd %xmm1, %r10d
419 ; CHECK-NEXT: idivl %r10d
420 ; CHECK-NEXT: movd %eax, %xmm2
421 ; CHECK-NEXT: pinsrd $1, %r8d, %xmm2
422 ; CHECK-NEXT: pextrd $2, %xmm0, %eax
423 ; CHECK-NEXT: pextrd $2, %xmm1, %r8d
425 ; CHECK-NEXT: idivl %r8d
426 ; CHECK-NEXT: movl %eax, 8(%rdi,%rcx)
427 ; CHECK-NEXT: movq %xmm2, (%rdi,%rcx)
428 ; CHECK-NEXT: addq $16, %rcx
429 ; CHECK-NEXT: decl %r9d
430 ; CHECK-NEXT: jne .LBB12_2
431 ; CHECK-NEXT: .LBB12_3: # %for.end
434 %cmp13 = icmp sgt i32 %n, 0
435 br i1 %cmp13, label %bb.nph, label %for.end
441 %i.014 = phi i32 [ 0, %bb.nph ], [ %inc, %for.body ]
442 %arrayidx11 = getelementptr <3 x i32>, <3 x i32>* %dest, i32 %i.014
443 %tmp4 = load <3 x i32>, <3 x i32>* %arrayidx11 ; <<3 x i32>> [#uses=1]
444 %arrayidx7 = getelementptr inbounds <3 x i32>, <3 x i32>* %old, i32 %i.014
445 %tmp8 = load <3 x i32>, <3 x i32>* %arrayidx7 ; <<3 x i32>> [#uses=1]
446 %div = sdiv <3 x i32> %tmp4, %tmp8
447 store <3 x i32> %div, <3 x i32>* %arrayidx11
448 %inc = add nsw i32 %i.014, 1
449 %exitcond = icmp eq i32 %inc, %n
450 br i1 %exitcond, label %for.end, label %for.body
452 for.end: ; preds = %for.body, %entry