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