1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=i686-unknown | FileCheck %s --check-prefix=X86
3 ; RUN: llc < %s -mtriple=x86_64-unknown | FileCheck %s --check-prefix=X64
5 ; Shift i64 integers on 32-bit target
7 define i64 @test1(i64 %X, i8 %C) nounwind {
10 ; X86-NEXT: pushl %esi
11 ; X86-NEXT: movb {{[0-9]+}}(%esp), %cl
12 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
13 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
14 ; X86-NEXT: movl %esi, %eax
15 ; X86-NEXT: shll %cl, %eax
16 ; X86-NEXT: shldl %cl, %esi, %edx
17 ; X86-NEXT: testb $32, %cl
18 ; X86-NEXT: je .LBB0_2
20 ; X86-NEXT: movl %eax, %edx
21 ; X86-NEXT: xorl %eax, %eax
28 ; X64-NEXT: movl %esi, %ecx
29 ; X64-NEXT: movq %rdi, %rax
30 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
31 ; X64-NEXT: shlq %cl, %rax
33 %shift.upgrd.1 = zext i8 %C to i64 ; <i64> [#uses=1]
34 %Y = shl i64 %X, %shift.upgrd.1 ; <i64> [#uses=1]
38 define i64 @test2(i64 %X, i8 %C) nounwind {
41 ; X86-NEXT: pushl %esi
42 ; X86-NEXT: movb {{[0-9]+}}(%esp), %cl
43 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
44 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
45 ; X86-NEXT: movl %esi, %edx
46 ; X86-NEXT: sarl %cl, %edx
47 ; X86-NEXT: shrdl %cl, %esi, %eax
48 ; X86-NEXT: testb $32, %cl
49 ; X86-NEXT: je .LBB1_2
51 ; X86-NEXT: sarl $31, %esi
52 ; X86-NEXT: movl %edx, %eax
53 ; X86-NEXT: movl %esi, %edx
60 ; X64-NEXT: movl %esi, %ecx
61 ; X64-NEXT: movq %rdi, %rax
62 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
63 ; X64-NEXT: sarq %cl, %rax
65 %shift.upgrd.2 = zext i8 %C to i64 ; <i64> [#uses=1]
66 %Y = ashr i64 %X, %shift.upgrd.2 ; <i64> [#uses=1]
70 define i64 @test3(i64 %X, i8 %C) nounwind {
73 ; X86-NEXT: pushl %esi
74 ; X86-NEXT: movb {{[0-9]+}}(%esp), %cl
75 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
76 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
77 ; X86-NEXT: movl %esi, %edx
78 ; X86-NEXT: shrl %cl, %edx
79 ; X86-NEXT: shrdl %cl, %esi, %eax
80 ; X86-NEXT: testb $32, %cl
81 ; X86-NEXT: je .LBB2_2
83 ; X86-NEXT: movl %edx, %eax
84 ; X86-NEXT: xorl %edx, %edx
91 ; X64-NEXT: movl %esi, %ecx
92 ; X64-NEXT: movq %rdi, %rax
93 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
94 ; X64-NEXT: shrq %cl, %rax
96 %shift.upgrd.3 = zext i8 %C to i64 ; <i64> [#uses=1]
97 %Y = lshr i64 %X, %shift.upgrd.3 ; <i64> [#uses=1]
101 ; Combine 2xi32/2xi16 shifts into SHLD
103 define i32 @test4(i32 %A, i32 %B, i8 %C) nounwind {
106 ; X86-NEXT: movb {{[0-9]+}}(%esp), %cl
107 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
108 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
109 ; X86-NEXT: shldl %cl, %edx, %eax
114 ; X64-NEXT: movl %edx, %ecx
115 ; X64-NEXT: movl %edi, %eax
116 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
117 ; X64-NEXT: shldl %cl, %esi, %eax
119 %shift.upgrd.4 = zext i8 %C to i32 ; <i32> [#uses=1]
120 %X = shl i32 %A, %shift.upgrd.4 ; <i32> [#uses=1]
121 %Cv = sub i8 32, %C ; <i8> [#uses=1]
122 %shift.upgrd.5 = zext i8 %Cv to i32 ; <i32> [#uses=1]
123 %Y = lshr i32 %B, %shift.upgrd.5 ; <i32> [#uses=1]
124 %Z = or i32 %Y, %X ; <i32> [#uses=1]
128 define i16 @test5(i16 %A, i16 %B, i8 %C) nounwind {
131 ; X86-NEXT: movzwl {{[0-9]+}}(%esp), %edx
132 ; X86-NEXT: movzwl {{[0-9]+}}(%esp), %eax
133 ; X86-NEXT: movb {{[0-9]+}}(%esp), %cl
134 ; X86-NEXT: andb $15, %cl
135 ; X86-NEXT: shldw %cl, %dx, %ax
140 ; X64-NEXT: movl %edx, %ecx
141 ; X64-NEXT: movl %edi, %eax
142 ; X64-NEXT: andb $15, %cl
143 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
144 ; X64-NEXT: shldw %cl, %si, %ax
145 ; X64-NEXT: # kill: def $ax killed $ax killed $eax
147 %shift.upgrd.6 = zext i8 %C to i16 ; <i16> [#uses=1]
148 %X = shl i16 %A, %shift.upgrd.6 ; <i16> [#uses=1]
149 %Cv = sub i8 16, %C ; <i8> [#uses=1]
150 %shift.upgrd.7 = zext i8 %Cv to i16 ; <i16> [#uses=1]
151 %Y = lshr i16 %B, %shift.upgrd.7 ; <i16> [#uses=1]
152 %Z = or i16 %Y, %X ; <i16> [#uses=1]
156 ; Combine 2xi32/2xi16 shifts into SHRD
158 define i32 @test6(i32 %A, i32 %B, i8 %C) nounwind {
161 ; X86-NEXT: movb {{[0-9]+}}(%esp), %cl
162 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
163 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
164 ; X86-NEXT: shrdl %cl, %edx, %eax
169 ; X64-NEXT: movl %edx, %ecx
170 ; X64-NEXT: movl %edi, %eax
171 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
172 ; X64-NEXT: shrdl %cl, %esi, %eax
174 %shift.upgrd.4 = zext i8 %C to i32 ; <i32> [#uses=1]
175 %X = lshr i32 %A, %shift.upgrd.4 ; <i32> [#uses=1]
176 %Cv = sub i8 32, %C ; <i8> [#uses=1]
177 %shift.upgrd.5 = zext i8 %Cv to i32 ; <i32> [#uses=1]
178 %Y = shl i32 %B, %shift.upgrd.5 ; <i32> [#uses=1]
179 %Z = or i32 %Y, %X ; <i32> [#uses=1]
183 define i16 @test7(i16 %A, i16 %B, i8 %C) nounwind {
186 ; X86-NEXT: movzwl {{[0-9]+}}(%esp), %edx
187 ; X86-NEXT: movzwl {{[0-9]+}}(%esp), %eax
188 ; X86-NEXT: movb {{[0-9]+}}(%esp), %cl
189 ; X86-NEXT: andb $15, %cl
190 ; X86-NEXT: shrdw %cl, %dx, %ax
195 ; X64-NEXT: movl %edx, %ecx
196 ; X64-NEXT: movl %edi, %eax
197 ; X64-NEXT: andb $15, %cl
198 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
199 ; X64-NEXT: shrdw %cl, %si, %ax
200 ; X64-NEXT: # kill: def $ax killed $ax killed $eax
202 %shift.upgrd.6 = zext i8 %C to i16 ; <i16> [#uses=1]
203 %X = lshr i16 %A, %shift.upgrd.6 ; <i16> [#uses=1]
204 %Cv = sub i8 16, %C ; <i8> [#uses=1]
205 %shift.upgrd.7 = zext i8 %Cv to i16 ; <i16> [#uses=1]
206 %Y = shl i16 %B, %shift.upgrd.7 ; <i16> [#uses=1]
207 %Z = or i16 %Y, %X ; <i16> [#uses=1]
211 ; Shift i64 integers on 32-bit target by shift value less then 32 (PR14593)
213 define i64 @test8(i64 %val, i32 %bits) nounwind {
216 ; X86-NEXT: pushl %esi
217 ; X86-NEXT: movb {{[0-9]+}}(%esp), %cl
218 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
219 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
220 ; X86-NEXT: movl %esi, %eax
221 ; X86-NEXT: shll %cl, %eax
222 ; X86-NEXT: shldl %cl, %esi, %edx
223 ; X86-NEXT: popl %esi
228 ; X64-NEXT: movl %esi, %ecx
229 ; X64-NEXT: movq %rdi, %rax
230 ; X64-NEXT: andb $31, %cl
231 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
232 ; X64-NEXT: shlq %cl, %rax
234 %and = and i32 %bits, 31
235 %sh_prom = zext i32 %and to i64
236 %shl = shl i64 %val, %sh_prom
240 define i64 @test9(i64 %val, i32 %bits) nounwind {
243 ; X86-NEXT: movb {{[0-9]+}}(%esp), %cl
244 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
245 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
246 ; X86-NEXT: shrdl %cl, %edx, %eax
247 ; X86-NEXT: sarl %cl, %edx
252 ; X64-NEXT: movl %esi, %ecx
253 ; X64-NEXT: movq %rdi, %rax
254 ; X64-NEXT: andb $31, %cl
255 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
256 ; X64-NEXT: sarq %cl, %rax
258 %and = and i32 %bits, 31
259 %sh_prom = zext i32 %and to i64
260 %ashr = ashr i64 %val, %sh_prom
264 define i64 @test10(i64 %val, i32 %bits) nounwind {
267 ; X86-NEXT: movb {{[0-9]+}}(%esp), %cl
268 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
269 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
270 ; X86-NEXT: shrdl %cl, %edx, %eax
271 ; X86-NEXT: shrl %cl, %edx
276 ; X64-NEXT: movl %esi, %ecx
277 ; X64-NEXT: movq %rdi, %rax
278 ; X64-NEXT: andb $31, %cl
279 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
280 ; X64-NEXT: shrq %cl, %rax
282 %and = and i32 %bits, 31
283 %sh_prom = zext i32 %and to i64
284 %lshr = lshr i64 %val, %sh_prom
288 ; SHLD/SHRD manual shifts
290 define i32 @test11(i32 %hi, i32 %lo, i32 %bits) nounwind {
293 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
294 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
295 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
296 ; X86-NEXT: andl $31, %ecx
297 ; X86-NEXT: # kill: def $cl killed $cl killed $ecx
298 ; X86-NEXT: shldl %cl, %edx, %eax
303 ; X64-NEXT: movl %edx, %ecx
304 ; X64-NEXT: movl %edi, %eax
305 ; X64-NEXT: andl $31, %ecx
306 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
307 ; X64-NEXT: shldl %cl, %esi, %eax
309 %and = and i32 %bits, 31
310 %and32 = sub i32 32, %and
311 %sh_lo = lshr i32 %lo, %and32
312 %sh_hi = shl i32 %hi, %and
313 %sh = or i32 %sh_lo, %sh_hi
317 define i32 @test12(i32 %hi, i32 %lo, i32 %bits) nounwind {
320 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
321 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
322 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
323 ; X86-NEXT: andl $31, %ecx
324 ; X86-NEXT: # kill: def $cl killed $cl killed $ecx
325 ; X86-NEXT: shrdl %cl, %edx, %eax
330 ; X64-NEXT: movl %edx, %ecx
331 ; X64-NEXT: movl %esi, %eax
332 ; X64-NEXT: andl $31, %ecx
333 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
334 ; X64-NEXT: shrdl %cl, %edi, %eax
336 %and = and i32 %bits, 31
337 %and32 = sub i32 32, %and
338 %sh_lo = shl i32 %hi, %and32
339 %sh_hi = lshr i32 %lo, %and
340 %sh = or i32 %sh_lo, %sh_hi
344 define i32 @test13(i32 %hi, i32 %lo, i32 %bits) nounwind {
347 ; X86-NEXT: movb {{[0-9]+}}(%esp), %cl
348 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
349 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
350 ; X86-NEXT: shldl %cl, %edx, %eax
355 ; X64-NEXT: movl %edx, %ecx
356 ; X64-NEXT: movl %edi, %eax
357 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
358 ; X64-NEXT: shldl %cl, %esi, %eax
360 %bits32 = sub i32 32, %bits
361 %sh_lo = lshr i32 %lo, %bits32
362 %sh_hi = shl i32 %hi, %bits
363 %sh = or i32 %sh_lo, %sh_hi
367 define i32 @test14(i32 %hi, i32 %lo, i32 %bits) nounwind {
370 ; X86-NEXT: movb {{[0-9]+}}(%esp), %cl
371 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
372 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
373 ; X86-NEXT: shrdl %cl, %edx, %eax
378 ; X64-NEXT: movl %edx, %ecx
379 ; X64-NEXT: movl %esi, %eax
380 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
381 ; X64-NEXT: shrdl %cl, %edi, %eax
383 %bits32 = sub i32 32, %bits
384 %sh_lo = shl i32 %hi, %bits32
385 %sh_hi = lshr i32 %lo, %bits
386 %sh = or i32 %sh_lo, %sh_hi
390 define i32 @test15(i32 %hi, i32 %lo, i32 %bits) nounwind {
393 ; X86-NEXT: movb {{[0-9]+}}(%esp), %cl
394 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
395 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
396 ; X86-NEXT: shldl %cl, %edx, %eax
401 ; X64-NEXT: movl %edx, %ecx
402 ; X64-NEXT: movl %edi, %eax
403 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
404 ; X64-NEXT: shldl %cl, %esi, %eax
406 %bits32 = xor i32 %bits, 31
407 %lo2 = lshr i32 %lo, 1
408 %sh_lo = lshr i32 %lo2, %bits32
409 %sh_hi = shl i32 %hi, %bits
410 %sh = or i32 %sh_lo, %sh_hi
414 define i32 @test16(i32 %hi, i32 %lo, i32 %bits) nounwind {
417 ; X86-NEXT: movb {{[0-9]+}}(%esp), %cl
418 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
419 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
420 ; X86-NEXT: shrdl %cl, %edx, %eax
425 ; X64-NEXT: movl %edx, %ecx
426 ; X64-NEXT: movl %edi, %eax
427 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
428 ; X64-NEXT: shrdl %cl, %esi, %eax
430 %bits32 = xor i32 %bits, 31
431 %lo2 = shl i32 %lo, 1
432 %sh_lo = shl i32 %lo2, %bits32
433 %sh_hi = lshr i32 %hi, %bits
434 %sh = or i32 %sh_lo, %sh_hi
438 define i32 @test17(i32 %hi, i32 %lo, i32 %bits) nounwind {
441 ; X86-NEXT: movb {{[0-9]+}}(%esp), %cl
442 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
443 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
444 ; X86-NEXT: shrdl %cl, %edx, %eax
449 ; X64-NEXT: movl %edx, %ecx
450 ; X64-NEXT: movl %edi, %eax
451 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
452 ; X64-NEXT: shrdl %cl, %esi, %eax
454 %bits32 = xor i32 %bits, 31
455 %lo2 = add i32 %lo, %lo
456 %sh_lo = shl i32 %lo2, %bits32
457 %sh_hi = lshr i32 %hi, %bits
458 %sh = or i32 %sh_lo, %sh_hi
462 define i32 @test18(i32 %hi, i32 %lo, i32 %bits) nounwind {
465 ; X86-NEXT: movb {{[0-9]+}}(%esp), %cl
466 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
467 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
468 ; X86-NEXT: shldl %cl, %edx, %eax
473 ; X64-NEXT: movl %edx, %ecx
474 ; X64-NEXT: movl %edi, %eax
475 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
476 ; X64-NEXT: shldl %cl, %esi, %eax
478 %tbits = trunc i32 %bits to i8
479 %tand = and i8 %tbits, 31
480 %tand64 = sub i8 32, %tand
481 %and = zext i8 %tand to i32
482 %and64 = zext i8 %tand64 to i32
483 %sh_lo = lshr i32 %lo, %and64
484 %sh_hi = shl i32 %hi, %and
485 %sh = or i32 %sh_lo, %sh_hi
489 ; PR34641 - Masked Shift Counts
491 define i32 @shld_safe_i32(i32, i32, i32) {
492 ; X86-LABEL: shld_safe_i32:
494 ; X86-NEXT: movb {{[0-9]+}}(%esp), %cl
495 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
496 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
497 ; X86-NEXT: shldl %cl, %edx, %eax
500 ; X64-LABEL: shld_safe_i32:
502 ; X64-NEXT: movl %edx, %ecx
503 ; X64-NEXT: movl %edi, %eax
504 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
505 ; X64-NEXT: shldl %cl, %esi, %eax
516 define i32 @shrd_safe_i32(i32, i32, i32) {
517 ; X86-LABEL: shrd_safe_i32:
519 ; X86-NEXT: movb {{[0-9]+}}(%esp), %cl
520 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
521 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
522 ; X86-NEXT: shrdl %cl, %edx, %eax
525 ; X64-LABEL: shrd_safe_i32:
527 ; X64-NEXT: movl %edx, %ecx
528 ; X64-NEXT: movl %edi, %eax
529 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
530 ; X64-NEXT: shrdl %cl, %esi, %eax