xref: /llvm-project/llvm/test/CodeGen/X86/shift-and.ll (revision 401d123a1fdcbbf4ae7a20178957b7e3a625c044)
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc < %s -mtriple=i386-unknown-unknown   | FileCheck %s --check-prefix=X86
3; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefix=X64
4
5define i32 @t1(i32 %t, i32 %val) nounwind {
6; X86-LABEL: t1:
7; X86:       # %bb.0:
8; X86-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx
9; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
10; X86-NEXT:    shll %cl, %eax
11; X86-NEXT:    retl
12;
13; X64-LABEL: t1:
14; X64:       # %bb.0:
15; X64-NEXT:    movl %esi, %eax
16; X64-NEXT:    movl %edi, %ecx
17; X64-NEXT:    # kill: def $cl killed $cl killed $ecx
18; X64-NEXT:    shll %cl, %eax
19; X64-NEXT:    retq
20       %shamt = and i32 %t, 31
21       %res = shl i32 %val, %shamt
22       ret i32 %res
23}
24
25define i32 @t2(i32 %t, i32 %val) nounwind {
26; X86-LABEL: t2:
27; X86:       # %bb.0:
28; X86-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx
29; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
30; X86-NEXT:    shll %cl, %eax
31; X86-NEXT:    retl
32;
33; X64-LABEL: t2:
34; X64:       # %bb.0:
35; X64-NEXT:    movl %esi, %eax
36; X64-NEXT:    movl %edi, %ecx
37; X64-NEXT:    # kill: def $cl killed $cl killed $ecx
38; X64-NEXT:    shll %cl, %eax
39; X64-NEXT:    retq
40       %shamt = and i32 %t, 63
41       %res = shl i32 %val, %shamt
42       ret i32 %res
43}
44
45@X = internal global i16 0
46
47define void @t3(i16 %t) nounwind {
48; X86-LABEL: t3:
49; X86:       # %bb.0:
50; X86-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx
51; X86-NEXT:    sarw %cl, X
52; X86-NEXT:    retl
53;
54; X64-LABEL: t3:
55; X64:       # %bb.0:
56; X64-NEXT:    movl %edi, %ecx
57; X64-NEXT:    # kill: def $cl killed $cl killed $ecx
58; X64-NEXT:    sarw %cl, X(%rip)
59; X64-NEXT:    retq
60       %shamt = and i16 %t, 31
61       %tmp = load i16, ptr @X
62       %tmp1 = ashr i16 %tmp, %shamt
63       store i16 %tmp1, ptr @X
64       ret void
65}
66
67define i64 @t4(i64 %t, i64 %val) nounwind {
68; X86-LABEL: t4:
69; X86:       # %bb.0:
70; X86-NEXT:    pushl %esi
71; X86-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx
72; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
73; X86-NEXT:    movl {{[0-9]+}}(%esp), %esi
74; X86-NEXT:    movl %esi, %edx
75; X86-NEXT:    shrl %cl, %edx
76; X86-NEXT:    shrdl %cl, %esi, %eax
77; X86-NEXT:    testb $32, %cl
78; X86-NEXT:    je .LBB3_2
79; X86-NEXT:  # %bb.1:
80; X86-NEXT:    movl %edx, %eax
81; X86-NEXT:    xorl %edx, %edx
82; X86-NEXT:  .LBB3_2:
83; X86-NEXT:    popl %esi
84; X86-NEXT:    retl
85;
86; X64-LABEL: t4:
87; X64:       # %bb.0:
88; X64-NEXT:    movq %rsi, %rax
89; X64-NEXT:    movq %rdi, %rcx
90; X64-NEXT:    # kill: def $cl killed $cl killed $rcx
91; X64-NEXT:    shrq %cl, %rax
92; X64-NEXT:    retq
93       %shamt = and i64 %t, 63
94       %res = lshr i64 %val, %shamt
95       ret i64 %res
96}
97
98define i64 @t5(i64 %t, i64 %val) nounwind {
99; X86-LABEL: t5:
100; X86:       # %bb.0:
101; X86-NEXT:    pushl %esi
102; X86-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx
103; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
104; X86-NEXT:    movl {{[0-9]+}}(%esp), %esi
105; X86-NEXT:    movl %esi, %edx
106; X86-NEXT:    shrl %cl, %edx
107; X86-NEXT:    shrdl %cl, %esi, %eax
108; X86-NEXT:    testb $32, %cl
109; X86-NEXT:    je .LBB4_2
110; X86-NEXT:  # %bb.1:
111; X86-NEXT:    movl %edx, %eax
112; X86-NEXT:    xorl %edx, %edx
113; X86-NEXT:  .LBB4_2:
114; X86-NEXT:    popl %esi
115; X86-NEXT:    retl
116;
117; X64-LABEL: t5:
118; X64:       # %bb.0:
119; X64-NEXT:    movq %rsi, %rax
120; X64-NEXT:    movq %rdi, %rcx
121; X64-NEXT:    # kill: def $cl killed $cl killed $rcx
122; X64-NEXT:    shrq %cl, %rax
123; X64-NEXT:    retq
124       %shamt = and i64 %t, 191
125       %res = lshr i64 %val, %shamt
126       ret i64 %res
127}
128
129define void @t5ptr(i64 %t, ptr %ptr) nounwind {
130; X86-LABEL: t5ptr:
131; X86:       # %bb.0:
132; X86-NEXT:    pushl %edi
133; X86-NEXT:    pushl %esi
134; X86-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx
135; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
136; X86-NEXT:    movl (%eax), %edx
137; X86-NEXT:    movl 4(%eax), %edi
138; X86-NEXT:    movl %edi, %esi
139; X86-NEXT:    shrl %cl, %esi
140; X86-NEXT:    shrdl %cl, %edi, %edx
141; X86-NEXT:    testb $32, %cl
142; X86-NEXT:    je .LBB5_2
143; X86-NEXT:  # %bb.1:
144; X86-NEXT:    movl %esi, %edx
145; X86-NEXT:    xorl %esi, %esi
146; X86-NEXT:  .LBB5_2:
147; X86-NEXT:    movl %edx, (%eax)
148; X86-NEXT:    movl %esi, 4(%eax)
149; X86-NEXT:    popl %esi
150; X86-NEXT:    popl %edi
151; X86-NEXT:    retl
152;
153; X64-LABEL: t5ptr:
154; X64:       # %bb.0:
155; X64-NEXT:    movq %rdi, %rcx
156; X64-NEXT:    # kill: def $cl killed $cl killed $rcx
157; X64-NEXT:    shrq %cl, (%rsi)
158; X64-NEXT:    retq
159       %shamt = and i64 %t, 191
160       %tmp = load i64, ptr %ptr
161       %tmp1 = lshr i64 %tmp, %shamt
162       store i64 %tmp1, ptr %ptr
163       ret void
164}
165
166
167; rdar://11866926
168define i64 @t6(i64 %key, ptr nocapture %val) nounwind {
169; X86-LABEL: t6:
170; X86:       # %bb.0:
171; X86-NEXT:    pushl %esi
172; X86-NEXT:    movl {{[0-9]+}}(%esp), %edx
173; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx
174; X86-NEXT:    movl {{[0-9]+}}(%esp), %esi
175; X86-NEXT:    shrdl $3, %esi, %ecx
176; X86-NEXT:    shrl $3, %esi
177; X86-NEXT:    movl (%edx), %eax
178; X86-NEXT:    movl 4(%edx), %edx
179; X86-NEXT:    addl $-1, %eax
180; X86-NEXT:    adcl $-1, %edx
181; X86-NEXT:    andl %ecx, %eax
182; X86-NEXT:    andl %esi, %edx
183; X86-NEXT:    popl %esi
184; X86-NEXT:    retl
185;
186; X64-LABEL: t6:
187; X64:       # %bb.0:
188; X64-NEXT:    shrq $3, %rdi
189; X64-NEXT:    movq (%rsi), %rax
190; X64-NEXT:    decq %rax
191; X64-NEXT:    andq %rdi, %rax
192; X64-NEXT:    retq
193  %shr = lshr i64 %key, 3
194  %1 = load i64, ptr %val, align 8
195  %sub = add i64 %1, 2305843009213693951
196  %and = and i64 %sub, %shr
197  ret i64 %and
198}
199
200define i64 @big_mask_constant(i64 %x) nounwind {
201; X86-LABEL: big_mask_constant:
202; X86:       # %bb.0:
203; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
204; X86-NEXT:    andl $4, %eax
205; X86-NEXT:    shll $25, %eax
206; X86-NEXT:    xorl %edx, %edx
207; X86-NEXT:    retl
208;
209; X64-LABEL: big_mask_constant:
210; X64:       # %bb.0:
211; X64-NEXT:    movq %rdi, %rax
212; X64-NEXT:    shrq $7, %rax
213; X64-NEXT:    andl $134217728, %eax # imm = 0x8000000
214; X64-NEXT:    retq
215  %and = and i64 %x, 17179869184 ; 0x400000000
216  %sh = lshr i64 %and, 7
217  ret i64 %sh
218}
219
220