1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=i686-unknown < %s | FileCheck %s --check-prefix=X32
3 ; RUN: llc -mtriple=x86_64-unknown < %s | FileCheck %s --check-prefix=X64
5 @array = weak global [4 x i32] zeroinitializer
7 define i32 @test_lshr_and(i32 %x) {
8 ; X32-LABEL: test_lshr_and:
10 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
11 ; X32-NEXT: andl $12, %eax
12 ; X32-NEXT: movl array(%eax), %eax
15 ; X64-LABEL: test_lshr_and:
17 ; X64-NEXT: # kill: def $edi killed $edi def $rdi
18 ; X64-NEXT: shrl $2, %edi
19 ; X64-NEXT: andl $3, %edi
20 ; X64-NEXT: movl array(,%rdi,4), %eax
22 %tmp2 = lshr i32 %x, 2
23 %tmp3 = and i32 %tmp2, 3
24 %tmp4 = getelementptr [4 x i32], [4 x i32]* @array, i32 0, i32 %tmp3
25 %tmp5 = load i32, i32* %tmp4, align 4
29 define i32* @test_exact1(i32 %a, i32 %b, i32* %x) {
30 ; X32-LABEL: test_exact1:
32 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
33 ; X32-NEXT: subl {{[0-9]+}}(%esp), %eax
35 ; X32-NEXT: addl {{[0-9]+}}(%esp), %eax
38 ; X64-LABEL: test_exact1:
40 ; X64-NEXT: subl %edi, %esi
41 ; X64-NEXT: sarl $3, %esi
42 ; X64-NEXT: movslq %esi, %rax
43 ; X64-NEXT: leaq (%rdx,%rax,4), %rax
46 %shr = ashr exact i32 %sub, 3
47 %gep = getelementptr inbounds i32, i32* %x, i32 %shr
51 define i32* @test_exact2(i32 %a, i32 %b, i32* %x) {
52 ; X32-LABEL: test_exact2:
54 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
55 ; X32-NEXT: subl {{[0-9]+}}(%esp), %eax
57 ; X32-NEXT: addl {{[0-9]+}}(%esp), %eax
60 ; X64-LABEL: test_exact2:
62 ; X64-NEXT: subl %edi, %esi
63 ; X64-NEXT: sarl $3, %esi
64 ; X64-NEXT: movslq %esi, %rax
65 ; X64-NEXT: leaq (%rdx,%rax,4), %rax
68 %shr = ashr exact i32 %sub, 3
69 %gep = getelementptr inbounds i32, i32* %x, i32 %shr
73 define i32* @test_exact3(i32 %a, i32 %b, i32* %x) {
74 ; X32-LABEL: test_exact3:
76 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
77 ; X32-NEXT: subl {{[0-9]+}}(%esp), %eax
78 ; X32-NEXT: addl {{[0-9]+}}(%esp), %eax
81 ; X64-LABEL: test_exact3:
83 ; X64-NEXT: subl %edi, %esi
84 ; X64-NEXT: sarl $2, %esi
85 ; X64-NEXT: movslq %esi, %rax
86 ; X64-NEXT: leaq (%rdx,%rax,4), %rax
89 %shr = ashr exact i32 %sub, 2
90 %gep = getelementptr inbounds i32, i32* %x, i32 %shr
94 define i32* @test_exact4(i32 %a, i32 %b, i32* %x) {
95 ; X32-LABEL: test_exact4:
97 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
98 ; X32-NEXT: subl {{[0-9]+}}(%esp), %eax
100 ; X32-NEXT: addl {{[0-9]+}}(%esp), %eax
103 ; X64-LABEL: test_exact4:
105 ; X64-NEXT: # kill: def $esi killed $esi def $rsi
106 ; X64-NEXT: subl %edi, %esi
107 ; X64-NEXT: shrl $3, %esi
108 ; X64-NEXT: leaq (%rdx,%rsi,4), %rax
110 %sub = sub i32 %b, %a
111 %shr = lshr exact i32 %sub, 3
112 %gep = getelementptr inbounds i32, i32* %x, i32 %shr
116 define i32* @test_exact5(i32 %a, i32 %b, i32* %x) {
117 ; X32-LABEL: test_exact5:
119 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
120 ; X32-NEXT: subl {{[0-9]+}}(%esp), %eax
121 ; X32-NEXT: shrl %eax
122 ; X32-NEXT: addl {{[0-9]+}}(%esp), %eax
125 ; X64-LABEL: test_exact5:
127 ; X64-NEXT: # kill: def $esi killed $esi def $rsi
128 ; X64-NEXT: subl %edi, %esi
129 ; X64-NEXT: shrl $3, %esi
130 ; X64-NEXT: leaq (%rdx,%rsi,4), %rax
132 %sub = sub i32 %b, %a
133 %shr = lshr exact i32 %sub, 3
134 %gep = getelementptr inbounds i32, i32* %x, i32 %shr
138 define i32* @test_exact6(i32 %a, i32 %b, i32* %x) {
139 ; X32-LABEL: test_exact6:
141 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
142 ; X32-NEXT: subl {{[0-9]+}}(%esp), %eax
143 ; X32-NEXT: addl {{[0-9]+}}(%esp), %eax
146 ; X64-LABEL: test_exact6:
148 ; X64-NEXT: # kill: def $esi killed $esi def $rsi
149 ; X64-NEXT: subl %edi, %esi
150 ; X64-NEXT: leaq (%rsi,%rdx), %rax
152 %sub = sub i32 %b, %a
153 %shr = lshr exact i32 %sub, 2
154 %gep = getelementptr inbounds i32, i32* %x, i32 %shr
158 ; PR42644 - https://bugs.llvm.org/show_bug.cgi?id=42644
160 define i64 @ashr_add_shl_i32(i64 %r) nounwind {
161 ; X32-LABEL: ashr_add_shl_i32:
163 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
164 ; X32-NEXT: incl %eax
165 ; X32-NEXT: movl %eax, %edx
166 ; X32-NEXT: sarl $31, %edx
169 ; X64-LABEL: ashr_add_shl_i32:
171 ; X64-NEXT: incl %edi
172 ; X64-NEXT: movslq %edi, %rax
174 %conv = shl i64 %r, 32
175 %sext = add i64 %conv, 4294967296
176 %conv1 = ashr i64 %sext, 32
180 define i64 @ashr_add_shl_i8(i64 %r) nounwind {
181 ; X32-LABEL: ashr_add_shl_i8:
183 ; X32-NEXT: movb {{[0-9]+}}(%esp), %al
184 ; X32-NEXT: addb $2, %al
185 ; X32-NEXT: movsbl %al, %eax
186 ; X32-NEXT: movl %eax, %edx
187 ; X32-NEXT: sarl $31, %edx
190 ; X64-LABEL: ashr_add_shl_i8:
192 ; X64-NEXT: addb $2, %dil
193 ; X64-NEXT: movsbq %dil, %rax
195 %conv = shl i64 %r, 56
196 %sext = add i64 %conv, 144115188075855872
197 %conv1 = ashr i64 %sext, 56
201 define <4 x i32> @ashr_add_shl_v4i8(<4 x i32> %r) nounwind {
202 ; X32-LABEL: ashr_add_shl_v4i8:
204 ; X32-NEXT: pushl %edi
205 ; X32-NEXT: pushl %esi
206 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
207 ; X32-NEXT: movb {{[0-9]+}}(%esp), %cl
208 ; X32-NEXT: movb {{[0-9]+}}(%esp), %dl
209 ; X32-NEXT: movb {{[0-9]+}}(%esp), %ch
210 ; X32-NEXT: movb {{[0-9]+}}(%esp), %dh
212 ; X32-NEXT: movsbl %dh, %esi
214 ; X32-NEXT: movsbl %ch, %edi
216 ; X32-NEXT: movsbl %dl, %edx
218 ; X32-NEXT: movsbl %cl, %ecx
219 ; X32-NEXT: movl %ecx, 12(%eax)
220 ; X32-NEXT: movl %edx, 8(%eax)
221 ; X32-NEXT: movl %edi, 4(%eax)
222 ; X32-NEXT: movl %esi, (%eax)
223 ; X32-NEXT: popl %esi
224 ; X32-NEXT: popl %edi
227 ; X64-LABEL: ashr_add_shl_v4i8:
229 ; X64-NEXT: pand {{.*}}(%rip), %xmm0
230 ; X64-NEXT: packuswb %xmm0, %xmm0
231 ; X64-NEXT: packuswb %xmm0, %xmm0
232 ; X64-NEXT: pcmpeqd %xmm1, %xmm1
233 ; X64-NEXT: psubb %xmm1, %xmm0
234 ; X64-NEXT: punpcklbw {{.*#+}} xmm0 = xmm0[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
235 ; X64-NEXT: punpcklwd {{.*#+}} xmm0 = xmm0[0,0,1,1,2,2,3,3]
236 ; X64-NEXT: psrad $24, %xmm0
238 %conv = shl <4 x i32> %r, <i32 24, i32 24, i32 24, i32 24>
239 %sext = add <4 x i32> %conv, <i32 16777216, i32 16777216, i32 16777216, i32 16777216>
240 %conv1 = ashr <4 x i32> %sext, <i32 24, i32 24, i32 24, i32 24>
244 define i64 @ashr_add_shl_i36(i64 %r) nounwind {
245 ; X32-LABEL: ashr_add_shl_i36:
247 ; X32-NEXT: movl {{[0-9]+}}(%esp), %edx
248 ; X32-NEXT: shll $4, %edx
249 ; X32-NEXT: movl %edx, %eax
250 ; X32-NEXT: sarl $4, %eax
251 ; X32-NEXT: sarl $31, %edx
254 ; X64-LABEL: ashr_add_shl_i36:
256 ; X64-NEXT: movq %rdi, %rax
257 ; X64-NEXT: shlq $36, %rax
258 ; X64-NEXT: sarq $36, %rax
260 %conv = shl i64 %r, 36
261 %sext = add i64 %conv, 4294967296
262 %conv1 = ashr i64 %sext, 36
266 define i64 @ashr_add_shl_mismatch_shifts1(i64 %r) nounwind {
267 ; X32-LABEL: ashr_add_shl_mismatch_shifts1:
269 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
270 ; X32-NEXT: incl %eax
271 ; X32-NEXT: movl %eax, %edx
272 ; X32-NEXT: sarl $31, %edx
275 ; X64-LABEL: ashr_add_shl_mismatch_shifts1:
277 ; X64-NEXT: shlq $8, %rdi
278 ; X64-NEXT: movabsq $4294967296, %rax # imm = 0x100000000
279 ; X64-NEXT: addq %rdi, %rax
280 ; X64-NEXT: sarq $32, %rax
282 %conv = shl i64 %r, 8
283 %sext = add i64 %conv, 4294967296
284 %conv1 = ashr i64 %sext, 32
288 define i64 @ashr_add_shl_mismatch_shifts2(i64 %r) nounwind {
289 ; X32-LABEL: ashr_add_shl_mismatch_shifts2:
291 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
292 ; X32-NEXT: movl {{[0-9]+}}(%esp), %edx
293 ; X32-NEXT: shrdl $8, %edx, %eax
294 ; X32-NEXT: shrl $8, %edx
295 ; X32-NEXT: incl %edx
296 ; X32-NEXT: shrdl $8, %edx, %eax
297 ; X32-NEXT: shrl $8, %edx
300 ; X64-LABEL: ashr_add_shl_mismatch_shifts2:
302 ; X64-NEXT: shrq $8, %rdi
303 ; X64-NEXT: movabsq $4294967296, %rax # imm = 0x100000000
304 ; X64-NEXT: addq %rdi, %rax
305 ; X64-NEXT: shrq $8, %rax
307 %conv = lshr i64 %r, 8
308 %sext = add i64 %conv, 4294967296
309 %conv1 = ashr i64 %sext, 8
313 define i32 @ashr_add_shl_i32_i8_extra_use1(i32 %r, i32* %p) nounwind {
314 ; X32-LABEL: ashr_add_shl_i32_i8_extra_use1:
316 ; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
317 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
318 ; X32-NEXT: shll $24, %eax
319 ; X32-NEXT: addl $33554432, %eax # imm = 0x2000000
320 ; X32-NEXT: movl %eax, (%ecx)
321 ; X32-NEXT: sarl $24, %eax
324 ; X64-LABEL: ashr_add_shl_i32_i8_extra_use1:
326 ; X64-NEXT: movl %edi, %eax
327 ; X64-NEXT: shll $24, %eax
328 ; X64-NEXT: addl $33554432, %eax # imm = 0x2000000
329 ; X64-NEXT: movl %eax, (%rsi)
330 ; X64-NEXT: sarl $24, %eax
332 %conv = shl i32 %r, 24
333 %sext = add i32 %conv, 33554432
334 store i32 %sext, i32* %p
335 %conv1 = ashr i32 %sext, 24
339 define i32 @ashr_add_shl_i32_i8_extra_use2(i32 %r, i32* %p) nounwind {
340 ; X32-LABEL: ashr_add_shl_i32_i8_extra_use2:
342 ; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
343 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
344 ; X32-NEXT: shll $24, %eax
345 ; X32-NEXT: movl %eax, (%ecx)
346 ; X32-NEXT: addl $33554432, %eax # imm = 0x2000000
347 ; X32-NEXT: sarl $24, %eax
350 ; X64-LABEL: ashr_add_shl_i32_i8_extra_use2:
352 ; X64-NEXT: # kill: def $edi killed $edi def $rdi
353 ; X64-NEXT: shll $24, %edi
354 ; X64-NEXT: movl %edi, (%rsi)
355 ; X64-NEXT: leal 33554432(%rdi), %eax
356 ; X64-NEXT: sarl $24, %eax
358 %conv = shl i32 %r, 24
359 store i32 %conv, i32* %p
360 %sext = add i32 %conv, 33554432
361 %conv1 = ashr i32 %sext, 24
365 define i32 @ashr_add_shl_i32_i8_extra_use3(i32 %r, i32* %p1, i32* %p2) nounwind {
366 ; X32-LABEL: ashr_add_shl_i32_i8_extra_use3:
368 ; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
369 ; X32-NEXT: movl {{[0-9]+}}(%esp), %edx
370 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
371 ; X32-NEXT: shll $24, %eax
372 ; X32-NEXT: movl %eax, (%edx)
373 ; X32-NEXT: addl $33554432, %eax # imm = 0x2000000
374 ; X32-NEXT: movl %eax, (%ecx)
375 ; X32-NEXT: sarl $24, %eax
378 ; X64-LABEL: ashr_add_shl_i32_i8_extra_use3:
380 ; X64-NEXT: movl %edi, %eax
381 ; X64-NEXT: shll $24, %eax
382 ; X64-NEXT: movl %eax, (%rsi)
383 ; X64-NEXT: addl $33554432, %eax # imm = 0x2000000
384 ; X64-NEXT: movl %eax, (%rdx)
385 ; X64-NEXT: sarl $24, %eax
387 %conv = shl i32 %r, 24
388 store i32 %conv, i32* %p1
389 %sext = add i32 %conv, 33554432
390 store i32 %sext, i32* %p2
391 %conv1 = ashr i32 %sext, 24
395 %"class.QPainterPath" = type { double, double, i32 }
397 define void @PR42880(i32 %t0) {
398 ; X32-LABEL: PR42880:
400 ; X32-NEXT: xorl %eax, %eax
401 ; X32-NEXT: testb %al, %al
402 ; X32-NEXT: je .LBB16_1
403 ; X32-NEXT: # %bb.2: # %if
404 ; X32-NEXT: .LBB16_1: # %then
406 ; X64-LABEL: PR42880:
408 ; X64-NEXT: xorl %eax, %eax
409 ; X64-NEXT: testb %al, %al
410 ; X64-NEXT: je .LBB16_1
411 ; X64-NEXT: # %bb.2: # %if
412 ; X64-NEXT: .LBB16_1: # %then
413 %sub = add nsw i32 %t0, -1
414 %add.ptr.i94 = getelementptr inbounds %"class.QPainterPath", %"class.QPainterPath"* null, i32 %sub
415 %x = ptrtoint %"class.QPainterPath"* %add.ptr.i94 to i32
416 %sub2 = sub i32 %x, 0
417 %div = sdiv exact i32 %sub2, 24
418 br i1 undef, label %if, label %then
421 %t1 = xor i32 %div, -1