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: movzbl {{[0-9]+}}(%esp), %ecx
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: movzbl {{[0-9]+}}(%esp), %ecx
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: movzbl {{[0-9]+}}(%esp), %ecx
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: movzbl {{[0-9]+}}(%esp), %ecx
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: movzbl {{[0-9]+}}(%esp), %ecx
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: movzbl {{[0-9]+}}(%esp), %ecx
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: movzbl {{[0-9]+}}(%esp), %ecx
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: movzbl {{[0-9]+}}(%esp), %ecx
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: movzbl {{[0-9]+}}(%esp), %ecx
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: movzbl {{[0-9]+}}(%esp), %ecx
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: movzbl {{[0-9]+}}(%esp), %ecx
294 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
295 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
296 ; X86-NEXT: shldl %cl, %edx, %eax
301 ; X64-NEXT: movl %edx, %ecx
302 ; X64-NEXT: movl %edi, %eax
303 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
304 ; X64-NEXT: shldl %cl, %esi, %eax
306 %and = and i32 %bits, 31
307 %and32 = sub i32 32, %and
308 %sh_lo = lshr i32 %lo, %and32
309 %sh_hi = shl i32 %hi, %and
310 %sh = or i32 %sh_lo, %sh_hi
314 define i32 @test12(i32 %hi, i32 %lo, i32 %bits) nounwind {
317 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
318 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
319 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
320 ; X86-NEXT: shrdl %cl, %edx, %eax
325 ; X64-NEXT: movl %edx, %ecx
326 ; X64-NEXT: movl %esi, %eax
327 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
328 ; X64-NEXT: shrdl %cl, %edi, %eax
330 %and = and i32 %bits, 31
331 %and32 = sub i32 32, %and
332 %sh_lo = shl i32 %hi, %and32
333 %sh_hi = lshr i32 %lo, %and
334 %sh = or i32 %sh_lo, %sh_hi
338 define i32 @test13(i32 %hi, i32 %lo, i32 %bits) nounwind {
341 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
342 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
343 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
344 ; X86-NEXT: shldl %cl, %edx, %eax
349 ; X64-NEXT: movl %edx, %ecx
350 ; X64-NEXT: movl %edi, %eax
351 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
352 ; X64-NEXT: shldl %cl, %esi, %eax
354 %bits32 = sub i32 32, %bits
355 %sh_lo = lshr i32 %lo, %bits32
356 %sh_hi = shl i32 %hi, %bits
357 %sh = or i32 %sh_lo, %sh_hi
361 define i32 @test14(i32 %hi, i32 %lo, i32 %bits) nounwind {
364 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
365 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
366 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
367 ; X86-NEXT: shrdl %cl, %edx, %eax
372 ; X64-NEXT: movl %edx, %ecx
373 ; X64-NEXT: movl %esi, %eax
374 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
375 ; X64-NEXT: shrdl %cl, %edi, %eax
377 %bits32 = sub i32 32, %bits
378 %sh_lo = shl i32 %hi, %bits32
379 %sh_hi = lshr i32 %lo, %bits
380 %sh = or i32 %sh_lo, %sh_hi
384 define i32 @test15(i32 %hi, i32 %lo, i32 %bits) nounwind {
387 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
388 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
389 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
390 ; X86-NEXT: shldl %cl, %edx, %eax
395 ; X64-NEXT: movl %edx, %ecx
396 ; X64-NEXT: movl %edi, %eax
397 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
398 ; X64-NEXT: shldl %cl, %esi, %eax
400 %bits32 = xor i32 %bits, 31
401 %lo2 = lshr i32 %lo, 1
402 %sh_lo = lshr i32 %lo2, %bits32
403 %sh_hi = shl i32 %hi, %bits
404 %sh = or i32 %sh_lo, %sh_hi
408 define i32 @test16(i32 %hi, i32 %lo, i32 %bits) nounwind {
411 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
412 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
413 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
414 ; X86-NEXT: shrdl %cl, %edx, %eax
419 ; X64-NEXT: movl %edx, %ecx
420 ; X64-NEXT: movl %edi, %eax
421 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
422 ; X64-NEXT: shrdl %cl, %esi, %eax
424 %bits32 = xor i32 %bits, 31
425 %lo2 = shl i32 %lo, 1
426 %sh_lo = shl i32 %lo2, %bits32
427 %sh_hi = lshr i32 %hi, %bits
428 %sh = or i32 %sh_lo, %sh_hi
432 define i32 @test17(i32 %hi, i32 %lo, i32 %bits) nounwind {
435 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
436 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
437 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
438 ; X86-NEXT: shrdl %cl, %edx, %eax
443 ; X64-NEXT: movl %edx, %ecx
444 ; X64-NEXT: movl %edi, %eax
445 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
446 ; X64-NEXT: shrdl %cl, %esi, %eax
448 %bits32 = xor i32 %bits, 31
449 %lo2 = add i32 %lo, %lo
450 %sh_lo = shl i32 %lo2, %bits32
451 %sh_hi = lshr i32 %hi, %bits
452 %sh = or i32 %sh_lo, %sh_hi
456 define i32 @test18(i32 %hi, i32 %lo, i32 %bits) nounwind {
459 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
460 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
461 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
462 ; X86-NEXT: shldl %cl, %edx, %eax
467 ; X64-NEXT: movl %edx, %ecx
468 ; X64-NEXT: movl %edi, %eax
469 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
470 ; X64-NEXT: shldl %cl, %esi, %eax
472 %tbits = trunc i32 %bits to i8
473 %tand = and i8 %tbits, 31
474 %tand64 = sub i8 32, %tand
475 %and = zext i8 %tand to i32
476 %and64 = zext i8 %tand64 to i32
477 %sh_lo = lshr i32 %lo, %and64
478 %sh_hi = shl i32 %hi, %and
479 %sh = or i32 %sh_lo, %sh_hi
483 ; These are not valid shld/shrd patterns. When the shift amount modulo
484 ; the bitwidth is zero, the result should be an OR of both operands not a
487 define i32 @not_shld_i32(i32, i32, i32) {
488 ; X86-LABEL: not_shld_i32:
490 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
491 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
492 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
493 ; X86-NEXT: shll %cl, %edx
495 ; X86-NEXT: shrl %cl, %eax
496 ; X86-NEXT: orl %edx, %eax
499 ; X64-LABEL: not_shld_i32:
501 ; X64-NEXT: movl %edx, %ecx
502 ; X64-NEXT: movl %esi, %eax
503 ; X64-NEXT: shll %cl, %edi
505 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
506 ; X64-NEXT: shrl %cl, %eax
507 ; X64-NEXT: orl %edi, %eax
518 define i32 @not_shrd_i32(i32, i32, i32) {
519 ; X86-LABEL: not_shrd_i32:
521 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
522 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
523 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
524 ; X86-NEXT: shrl %cl, %edx
526 ; X86-NEXT: shll %cl, %eax
527 ; X86-NEXT: orl %edx, %eax
530 ; X64-LABEL: not_shrd_i32:
532 ; X64-NEXT: movl %edx, %ecx
533 ; X64-NEXT: movl %esi, %eax
534 ; X64-NEXT: shrl %cl, %edi
536 ; X64-NEXT: # kill: def $cl killed $cl killed $ecx
537 ; X64-NEXT: shll %cl, %eax
538 ; X64-NEXT: orl %edi, %eax