xref: /llvm-project/llvm/test/CodeGen/X86/shift-bmi2.ll (revision 2d92f7de800a1b1b3dca3dab1e11da712cd55f2b)
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -mtriple=i386-unknown-unknown -mcpu=core-avx2 < %s | FileCheck --check-prefix=BMI2 %s
3; RUN: llc -mtriple=x86_64-unknown-unknown -mcpu=core-avx2 < %s | FileCheck --check-prefix=BMI264 %s
4; RUN: llc -mtriple=x86_64-unknown-unknown -mcpu=core-avx2 -mattr=+egpr --show-mc-encoding < %s | FileCheck --check-prefix=EGPR %s
5
6define i32 @shl32(i32 %x, i32 %shamt) nounwind uwtable readnone {
7; BMI2-LABEL: shl32:
8; BMI2:       # %bb.0:
9; BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax
10; BMI2-NEXT:    shlxl %eax, {{[0-9]+}}(%esp), %eax
11; BMI2-NEXT:    retl
12;
13; BMI264-LABEL: shl32:
14; BMI264:       # %bb.0:
15; BMI264-NEXT:    shlxl %esi, %edi, %eax
16; BMI264-NEXT:    retq
17;
18; EGPR-LABEL: shl32:
19; EGPR:       # %bb.0:
20; EGPR-NEXT:    shlxl %esi, %edi, %eax # EVEX TO VEX Compression encoding: [0xc4,0xe2,0x49,0xf7,0xc7]
21; EGPR-NEXT:    retq # encoding: [0xc3]
22  %shl = shl i32 %x, %shamt
23  ret i32 %shl
24}
25
26define i32 @shl32i(i32 %x) nounwind uwtable readnone {
27; BMI2-LABEL: shl32i:
28; BMI2:       # %bb.0:
29; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax
30; BMI2-NEXT:    shll $5, %eax
31; BMI2-NEXT:    retl
32;
33; BMI264-LABEL: shl32i:
34; BMI264:       # %bb.0:
35; BMI264-NEXT:    movl %edi, %eax
36; BMI264-NEXT:    shll $5, %eax
37; BMI264-NEXT:    retq
38;
39; EGPR-LABEL: shl32i:
40; EGPR:       # %bb.0:
41; EGPR-NEXT:    movl %edi, %eax # encoding: [0x89,0xf8]
42; EGPR-NEXT:    shll $5, %eax # encoding: [0xc1,0xe0,0x05]
43; EGPR-NEXT:    retq # encoding: [0xc3]
44  %shl = shl i32 %x, 5
45  ret i32 %shl
46}
47
48define i32 @shl32p(ptr %p, i32 %shamt) nounwind uwtable readnone {
49; BMI2-LABEL: shl32p:
50; BMI2:       # %bb.0:
51; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax
52; BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx
53; BMI2-NEXT:    shlxl %ecx, (%eax), %eax
54; BMI2-NEXT:    retl
55;
56; BMI264-LABEL: shl32p:
57; BMI264:       # %bb.0:
58; BMI264-NEXT:    shlxl %esi, (%rdi), %eax
59; BMI264-NEXT:    retq
60;
61; EGPR-LABEL: shl32p:
62; EGPR:       # %bb.0:
63; EGPR-NEXT:    shlxl %esi, (%rdi), %eax # EVEX TO VEX Compression encoding: [0xc4,0xe2,0x49,0xf7,0x07]
64; EGPR-NEXT:    retq # encoding: [0xc3]
65  %x = load i32, ptr %p
66  %shl = shl i32 %x, %shamt
67  ret i32 %shl
68}
69
70define i32 @shl32pi(ptr %p) nounwind uwtable readnone {
71; BMI2-LABEL: shl32pi:
72; BMI2:       # %bb.0:
73; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax
74; BMI2-NEXT:    movl (%eax), %eax
75; BMI2-NEXT:    shll $5, %eax
76; BMI2-NEXT:    retl
77;
78; BMI264-LABEL: shl32pi:
79; BMI264:       # %bb.0:
80; BMI264-NEXT:    movl (%rdi), %eax
81; BMI264-NEXT:    shll $5, %eax
82; BMI264-NEXT:    retq
83;
84; EGPR-LABEL: shl32pi:
85; EGPR:       # %bb.0:
86; EGPR-NEXT:    movl (%rdi), %eax # encoding: [0x8b,0x07]
87; EGPR-NEXT:    shll $5, %eax # encoding: [0xc1,0xe0,0x05]
88; EGPR-NEXT:    retq # encoding: [0xc3]
89  %x = load i32, ptr %p
90  %shl = shl i32 %x, 5
91  ret i32 %shl
92}
93
94define i64 @shl64(i64 %x, i64 %shamt) nounwind uwtable readnone {
95; BMI2-LABEL: shl64:
96; BMI2:       # %bb.0:
97; BMI2-NEXT:    pushl %esi
98; BMI2-NEXT:    .cfi_def_cfa_offset 8
99; BMI2-NEXT:    .cfi_offset %esi, -8
100; BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx
101; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax
102; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %edx
103; BMI2-NEXT:    shldl %cl, %eax, %edx
104; BMI2-NEXT:    shlxl %ecx, %eax, %esi
105; BMI2-NEXT:    xorl %eax, %eax
106; BMI2-NEXT:    testb $32, %cl
107; BMI2-NEXT:    cmovnel %esi, %edx
108; BMI2-NEXT:    cmovel %esi, %eax
109; BMI2-NEXT:    popl %esi
110; BMI2-NEXT:    .cfi_def_cfa_offset 4
111; BMI2-NEXT:    retl
112;
113; BMI264-LABEL: shl64:
114; BMI264:       # %bb.0:
115; BMI264-NEXT:    shlxq %rsi, %rdi, %rax
116; BMI264-NEXT:    retq
117;
118; EGPR-LABEL: shl64:
119; EGPR:       # %bb.0:
120; EGPR-NEXT:    shlxq %rsi, %rdi, %rax # EVEX TO VEX Compression encoding: [0xc4,0xe2,0xc9,0xf7,0xc7]
121; EGPR-NEXT:    retq # encoding: [0xc3]
122  %shl = shl i64 %x, %shamt
123  ret i64 %shl
124}
125
126define i64 @shl64i(i64 %x) nounwind uwtable readnone {
127; BMI2-LABEL: shl64i:
128; BMI2:       # %bb.0:
129; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax
130; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %edx
131; BMI2-NEXT:    shldl $7, %eax, %edx
132; BMI2-NEXT:    shll $7, %eax
133; BMI2-NEXT:    retl
134;
135; BMI264-LABEL: shl64i:
136; BMI264:       # %bb.0:
137; BMI264-NEXT:    movq %rdi, %rax
138; BMI264-NEXT:    shlq $7, %rax
139; BMI264-NEXT:    retq
140;
141; EGPR-LABEL: shl64i:
142; EGPR:       # %bb.0:
143; EGPR-NEXT:    movq %rdi, %rax # encoding: [0x48,0x89,0xf8]
144; EGPR-NEXT:    shlq $7, %rax # encoding: [0x48,0xc1,0xe0,0x07]
145; EGPR-NEXT:    retq # encoding: [0xc3]
146  %shl = shl i64 %x, 7
147  ret i64 %shl
148}
149
150define i64 @shl64p(ptr %p, i64 %shamt) nounwind uwtable readnone {
151; BMI2-LABEL: shl64p:
152; BMI2:       # %bb.0:
153; BMI2-NEXT:    pushl %esi
154; BMI2-NEXT:    .cfi_def_cfa_offset 8
155; BMI2-NEXT:    .cfi_offset %esi, -8
156; BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx
157; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax
158; BMI2-NEXT:    movl (%eax), %esi
159; BMI2-NEXT:    movl 4(%eax), %edx
160; BMI2-NEXT:    shldl %cl, %esi, %edx
161; BMI2-NEXT:    shlxl %ecx, %esi, %esi
162; BMI2-NEXT:    xorl %eax, %eax
163; BMI2-NEXT:    testb $32, %cl
164; BMI2-NEXT:    cmovnel %esi, %edx
165; BMI2-NEXT:    cmovel %esi, %eax
166; BMI2-NEXT:    popl %esi
167; BMI2-NEXT:    .cfi_def_cfa_offset 4
168; BMI2-NEXT:    retl
169;
170; BMI264-LABEL: shl64p:
171; BMI264:       # %bb.0:
172; BMI264-NEXT:    shlxq %rsi, (%rdi), %rax
173; BMI264-NEXT:    retq
174;
175; EGPR-LABEL: shl64p:
176; EGPR:       # %bb.0:
177; EGPR-NEXT:    shlxq %rsi, (%rdi), %rax # EVEX TO VEX Compression encoding: [0xc4,0xe2,0xc9,0xf7,0x07]
178; EGPR-NEXT:    retq # encoding: [0xc3]
179  %x = load i64, ptr %p
180  %shl = shl i64 %x, %shamt
181  ret i64 %shl
182}
183
184define i64 @shl64pi(ptr %p) nounwind uwtable readnone {
185; BMI2-LABEL: shl64pi:
186; BMI2:       # %bb.0:
187; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %ecx
188; BMI2-NEXT:    movl (%ecx), %eax
189; BMI2-NEXT:    movl 4(%ecx), %edx
190; BMI2-NEXT:    shldl $7, %eax, %edx
191; BMI2-NEXT:    shll $7, %eax
192; BMI2-NEXT:    retl
193;
194; BMI264-LABEL: shl64pi:
195; BMI264:       # %bb.0:
196; BMI264-NEXT:    movq (%rdi), %rax
197; BMI264-NEXT:    shlq $7, %rax
198; BMI264-NEXT:    retq
199;
200; EGPR-LABEL: shl64pi:
201; EGPR:       # %bb.0:
202; EGPR-NEXT:    movq (%rdi), %rax # encoding: [0x48,0x8b,0x07]
203; EGPR-NEXT:    shlq $7, %rax # encoding: [0x48,0xc1,0xe0,0x07]
204; EGPR-NEXT:    retq # encoding: [0xc3]
205  %x = load i64, ptr %p
206  %shl = shl i64 %x, 7
207  ret i64 %shl
208}
209
210define i32 @lshr32(i32 %x, i32 %shamt) nounwind uwtable readnone {
211; BMI2-LABEL: lshr32:
212; BMI2:       # %bb.0:
213; BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax
214; BMI2-NEXT:    shrxl %eax, {{[0-9]+}}(%esp), %eax
215; BMI2-NEXT:    retl
216;
217; BMI264-LABEL: lshr32:
218; BMI264:       # %bb.0:
219; BMI264-NEXT:    shrxl %esi, %edi, %eax
220; BMI264-NEXT:    retq
221;
222; EGPR-LABEL: lshr32:
223; EGPR:       # %bb.0:
224; EGPR-NEXT:    shrxl %esi, %edi, %eax # EVEX TO VEX Compression encoding: [0xc4,0xe2,0x4b,0xf7,0xc7]
225; EGPR-NEXT:    retq # encoding: [0xc3]
226  %shl = lshr i32 %x, %shamt
227  ret i32 %shl
228}
229
230define i32 @lshr32p(ptr %p, i32 %shamt) nounwind uwtable readnone {
231; BMI2-LABEL: lshr32p:
232; BMI2:       # %bb.0:
233; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax
234; BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx
235; BMI2-NEXT:    shrxl %ecx, (%eax), %eax
236; BMI2-NEXT:    retl
237;
238; BMI264-LABEL: lshr32p:
239; BMI264:       # %bb.0:
240; BMI264-NEXT:    shrxl %esi, (%rdi), %eax
241; BMI264-NEXT:    retq
242;
243; EGPR-LABEL: lshr32p:
244; EGPR:       # %bb.0:
245; EGPR-NEXT:    shrxl %esi, (%rdi), %eax # EVEX TO VEX Compression encoding: [0xc4,0xe2,0x4b,0xf7,0x07]
246; EGPR-NEXT:    retq # encoding: [0xc3]
247  %x = load i32, ptr %p
248  %shl = lshr i32 %x, %shamt
249  ret i32 %shl
250}
251
252define i64 @lshr64(i64 %x, i64 %shamt) nounwind uwtable readnone {
253; BMI2-LABEL: lshr64:
254; BMI2:       # %bb.0:
255; BMI2-NEXT:    pushl %esi
256; BMI2-NEXT:    .cfi_def_cfa_offset 8
257; BMI2-NEXT:    .cfi_offset %esi, -8
258; BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx
259; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax
260; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %edx
261; BMI2-NEXT:    shrdl %cl, %edx, %eax
262; BMI2-NEXT:    shrxl %ecx, %edx, %esi
263; BMI2-NEXT:    xorl %edx, %edx
264; BMI2-NEXT:    testb $32, %cl
265; BMI2-NEXT:    cmovnel %esi, %eax
266; BMI2-NEXT:    cmovel %esi, %edx
267; BMI2-NEXT:    popl %esi
268; BMI2-NEXT:    .cfi_def_cfa_offset 4
269; BMI2-NEXT:    retl
270;
271; BMI264-LABEL: lshr64:
272; BMI264:       # %bb.0:
273; BMI264-NEXT:    shrxq %rsi, %rdi, %rax
274; BMI264-NEXT:    retq
275;
276; EGPR-LABEL: lshr64:
277; EGPR:       # %bb.0:
278; EGPR-NEXT:    shrxq %rsi, %rdi, %rax # EVEX TO VEX Compression encoding: [0xc4,0xe2,0xcb,0xf7,0xc7]
279; EGPR-NEXT:    retq # encoding: [0xc3]
280  %shl = lshr i64 %x, %shamt
281  ret i64 %shl
282}
283
284define i64 @lshr64p(ptr %p, i64 %shamt) nounwind uwtable readnone {
285; BMI2-LABEL: lshr64p:
286; BMI2:       # %bb.0:
287; BMI2-NEXT:    pushl %esi
288; BMI2-NEXT:    .cfi_def_cfa_offset 8
289; BMI2-NEXT:    .cfi_offset %esi, -8
290; BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx
291; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %edx
292; BMI2-NEXT:    movl (%edx), %eax
293; BMI2-NEXT:    movl 4(%edx), %edx
294; BMI2-NEXT:    shrdl %cl, %edx, %eax
295; BMI2-NEXT:    shrxl %ecx, %edx, %esi
296; BMI2-NEXT:    xorl %edx, %edx
297; BMI2-NEXT:    testb $32, %cl
298; BMI2-NEXT:    cmovnel %esi, %eax
299; BMI2-NEXT:    cmovel %esi, %edx
300; BMI2-NEXT:    popl %esi
301; BMI2-NEXT:    .cfi_def_cfa_offset 4
302; BMI2-NEXT:    retl
303;
304; BMI264-LABEL: lshr64p:
305; BMI264:       # %bb.0:
306; BMI264-NEXT:    shrxq %rsi, (%rdi), %rax
307; BMI264-NEXT:    retq
308;
309; EGPR-LABEL: lshr64p:
310; EGPR:       # %bb.0:
311; EGPR-NEXT:    shrxq %rsi, (%rdi), %rax # EVEX TO VEX Compression encoding: [0xc4,0xe2,0xcb,0xf7,0x07]
312; EGPR-NEXT:    retq # encoding: [0xc3]
313  %x = load i64, ptr %p
314  %shl = lshr i64 %x, %shamt
315  ret i64 %shl
316}
317
318define i32 @ashr32(i32 %x, i32 %shamt) nounwind uwtable readnone {
319; BMI2-LABEL: ashr32:
320; BMI2:       # %bb.0:
321; BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax
322; BMI2-NEXT:    sarxl %eax, {{[0-9]+}}(%esp), %eax
323; BMI2-NEXT:    retl
324;
325; BMI264-LABEL: ashr32:
326; BMI264:       # %bb.0:
327; BMI264-NEXT:    sarxl %esi, %edi, %eax
328; BMI264-NEXT:    retq
329;
330; EGPR-LABEL: ashr32:
331; EGPR:       # %bb.0:
332; EGPR-NEXT:    sarxl %esi, %edi, %eax # EVEX TO VEX Compression encoding: [0xc4,0xe2,0x4a,0xf7,0xc7]
333; EGPR-NEXT:    retq # encoding: [0xc3]
334  %shl = ashr i32 %x, %shamt
335  ret i32 %shl
336}
337
338define i32 @ashr32p(ptr %p, i32 %shamt) nounwind uwtable readnone {
339; BMI2-LABEL: ashr32p:
340; BMI2:       # %bb.0:
341; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax
342; BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx
343; BMI2-NEXT:    sarxl %ecx, (%eax), %eax
344; BMI2-NEXT:    retl
345;
346; BMI264-LABEL: ashr32p:
347; BMI264:       # %bb.0:
348; BMI264-NEXT:    sarxl %esi, (%rdi), %eax
349; BMI264-NEXT:    retq
350;
351; EGPR-LABEL: ashr32p:
352; EGPR:       # %bb.0:
353; EGPR-NEXT:    sarxl %esi, (%rdi), %eax # EVEX TO VEX Compression encoding: [0xc4,0xe2,0x4a,0xf7,0x07]
354; EGPR-NEXT:    retq # encoding: [0xc3]
355  %x = load i32, ptr %p
356  %shl = ashr i32 %x, %shamt
357  ret i32 %shl
358}
359
360define i64 @ashr64(i64 %x, i64 %shamt) nounwind uwtable readnone {
361; BMI2-LABEL: ashr64:
362; BMI2:       # %bb.0:
363; BMI2-NEXT:    pushl %esi
364; BMI2-NEXT:    .cfi_def_cfa_offset 8
365; BMI2-NEXT:    .cfi_offset %esi, -8
366; BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx
367; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax
368; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %edx
369; BMI2-NEXT:    shrdl %cl, %edx, %eax
370; BMI2-NEXT:    sarxl %ecx, %edx, %esi
371; BMI2-NEXT:    sarl $31, %edx
372; BMI2-NEXT:    testb $32, %cl
373; BMI2-NEXT:    cmovnel %esi, %eax
374; BMI2-NEXT:    cmovel %esi, %edx
375; BMI2-NEXT:    popl %esi
376; BMI2-NEXT:    .cfi_def_cfa_offset 4
377; BMI2-NEXT:    retl
378;
379; BMI264-LABEL: ashr64:
380; BMI264:       # %bb.0:
381; BMI264-NEXT:    sarxq %rsi, %rdi, %rax
382; BMI264-NEXT:    retq
383;
384; EGPR-LABEL: ashr64:
385; EGPR:       # %bb.0:
386; EGPR-NEXT:    sarxq %rsi, %rdi, %rax # EVEX TO VEX Compression encoding: [0xc4,0xe2,0xca,0xf7,0xc7]
387; EGPR-NEXT:    retq # encoding: [0xc3]
388  %shl = ashr i64 %x, %shamt
389  ret i64 %shl
390}
391
392define i64 @ashr64p(ptr %p, i64 %shamt) nounwind uwtable readnone {
393; BMI2-LABEL: ashr64p:
394; BMI2:       # %bb.0:
395; BMI2-NEXT:    pushl %esi
396; BMI2-NEXT:    .cfi_def_cfa_offset 8
397; BMI2-NEXT:    .cfi_offset %esi, -8
398; BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx
399; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %edx
400; BMI2-NEXT:    movl (%edx), %eax
401; BMI2-NEXT:    movl 4(%edx), %edx
402; BMI2-NEXT:    shrdl %cl, %edx, %eax
403; BMI2-NEXT:    sarxl %ecx, %edx, %esi
404; BMI2-NEXT:    sarl $31, %edx
405; BMI2-NEXT:    testb $32, %cl
406; BMI2-NEXT:    cmovnel %esi, %eax
407; BMI2-NEXT:    cmovel %esi, %edx
408; BMI2-NEXT:    popl %esi
409; BMI2-NEXT:    .cfi_def_cfa_offset 4
410; BMI2-NEXT:    retl
411;
412; BMI264-LABEL: ashr64p:
413; BMI264:       # %bb.0:
414; BMI264-NEXT:    sarxq %rsi, (%rdi), %rax
415; BMI264-NEXT:    retq
416;
417; EGPR-LABEL: ashr64p:
418; EGPR:       # %bb.0:
419; EGPR-NEXT:    sarxq %rsi, (%rdi), %rax # EVEX TO VEX Compression encoding: [0xc4,0xe2,0xca,0xf7,0x07]
420; EGPR-NEXT:    retq # encoding: [0xc3]
421  %x = load i64, ptr %p
422  %shl = ashr i64 %x, %shamt
423  ret i64 %shl
424}
425
426define i32 @shl32and(i32 %t, i32 %val) nounwind {
427; BMI2-LABEL: shl32and:
428; BMI2:       # %bb.0:
429; BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax
430; BMI2-NEXT:    shlxl %eax, {{[0-9]+}}(%esp), %eax
431; BMI2-NEXT:    retl
432;
433; BMI264-LABEL: shl32and:
434; BMI264:       # %bb.0:
435; BMI264-NEXT:    shlxl %edi, %esi, %eax
436; BMI264-NEXT:    retq
437;
438; EGPR-LABEL: shl32and:
439; EGPR:       # %bb.0:
440; EGPR-NEXT:    shlxl %edi, %esi, %eax # EVEX TO VEX Compression encoding: [0xc4,0xe2,0x41,0xf7,0xc6]
441; EGPR-NEXT:    retq # encoding: [0xc3]
442  %shamt = and i32 %t, 31
443  %res = shl i32 %val, %shamt
444  ret i32 %res
445}
446
447define i64 @shl64and(i64 %t, i64 %val) nounwind {
448; BMI2-LABEL: shl64and:
449; BMI2:       # %bb.0:
450; BMI2-NEXT:    pushl %esi
451; BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx
452; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax
453; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %edx
454; BMI2-NEXT:    shldl %cl, %eax, %edx
455; BMI2-NEXT:    shlxl %ecx, %eax, %esi
456; BMI2-NEXT:    xorl %eax, %eax
457; BMI2-NEXT:    testb $32, %cl
458; BMI2-NEXT:    cmovnel %esi, %edx
459; BMI2-NEXT:    cmovel %esi, %eax
460; BMI2-NEXT:    popl %esi
461; BMI2-NEXT:    retl
462;
463; BMI264-LABEL: shl64and:
464; BMI264:       # %bb.0:
465; BMI264-NEXT:    shlxq %rdi, %rsi, %rax
466; BMI264-NEXT:    retq
467;
468; EGPR-LABEL: shl64and:
469; EGPR:       # %bb.0:
470; EGPR-NEXT:    shlxq %rdi, %rsi, %rax # EVEX TO VEX Compression encoding: [0xc4,0xe2,0xc1,0xf7,0xc6]
471; EGPR-NEXT:    retq # encoding: [0xc3]
472  %shamt = and i64 %t, 63
473  %res = shl i64 %val, %shamt
474  ret i64 %res
475}
476
477define i32 @lshr32and(i32 %t, i32 %val) nounwind {
478; BMI2-LABEL: lshr32and:
479; BMI2:       # %bb.0:
480; BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax
481; BMI2-NEXT:    shrxl %eax, {{[0-9]+}}(%esp), %eax
482; BMI2-NEXT:    retl
483;
484; BMI264-LABEL: lshr32and:
485; BMI264:       # %bb.0:
486; BMI264-NEXT:    shrxl %edi, %esi, %eax
487; BMI264-NEXT:    retq
488;
489; EGPR-LABEL: lshr32and:
490; EGPR:       # %bb.0:
491; EGPR-NEXT:    shrxl %edi, %esi, %eax # EVEX TO VEX Compression encoding: [0xc4,0xe2,0x43,0xf7,0xc6]
492; EGPR-NEXT:    retq # encoding: [0xc3]
493  %shamt = and i32 %t, 31
494  %res = lshr i32 %val, %shamt
495  ret i32 %res
496}
497
498define i64 @lshr64and(i64 %t, i64 %val) nounwind {
499; BMI2-LABEL: lshr64and:
500; BMI2:       # %bb.0:
501; BMI2-NEXT:    pushl %esi
502; BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx
503; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax
504; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %edx
505; BMI2-NEXT:    shrdl %cl, %edx, %eax
506; BMI2-NEXT:    shrxl %ecx, %edx, %esi
507; BMI2-NEXT:    xorl %edx, %edx
508; BMI2-NEXT:    testb $32, %cl
509; BMI2-NEXT:    cmovnel %esi, %eax
510; BMI2-NEXT:    cmovel %esi, %edx
511; BMI2-NEXT:    popl %esi
512; BMI2-NEXT:    retl
513;
514; BMI264-LABEL: lshr64and:
515; BMI264:       # %bb.0:
516; BMI264-NEXT:    shrxq %rdi, %rsi, %rax
517; BMI264-NEXT:    retq
518;
519; EGPR-LABEL: lshr64and:
520; EGPR:       # %bb.0:
521; EGPR-NEXT:    shrxq %rdi, %rsi, %rax # EVEX TO VEX Compression encoding: [0xc4,0xe2,0xc3,0xf7,0xc6]
522; EGPR-NEXT:    retq # encoding: [0xc3]
523  %shamt = and i64 %t, 63
524  %res = lshr i64 %val, %shamt
525  ret i64 %res
526}
527
528define i32 @ashr32and(i32 %t, i32 %val) nounwind {
529; BMI2-LABEL: ashr32and:
530; BMI2:       # %bb.0:
531; BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax
532; BMI2-NEXT:    sarxl %eax, {{[0-9]+}}(%esp), %eax
533; BMI2-NEXT:    retl
534;
535; BMI264-LABEL: ashr32and:
536; BMI264:       # %bb.0:
537; BMI264-NEXT:    sarxl %edi, %esi, %eax
538; BMI264-NEXT:    retq
539;
540; EGPR-LABEL: ashr32and:
541; EGPR:       # %bb.0:
542; EGPR-NEXT:    sarxl %edi, %esi, %eax # EVEX TO VEX Compression encoding: [0xc4,0xe2,0x42,0xf7,0xc6]
543; EGPR-NEXT:    retq # encoding: [0xc3]
544  %shamt = and i32 %t, 31
545  %res = ashr i32 %val, %shamt
546  ret i32 %res
547}
548
549define i64 @ashr64and(i64 %t, i64 %val) nounwind {
550; BMI2-LABEL: ashr64and:
551; BMI2:       # %bb.0:
552; BMI2-NEXT:    pushl %esi
553; BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx
554; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax
555; BMI2-NEXT:    movl {{[0-9]+}}(%esp), %edx
556; BMI2-NEXT:    shrdl %cl, %edx, %eax
557; BMI2-NEXT:    sarxl %ecx, %edx, %esi
558; BMI2-NEXT:    sarl $31, %edx
559; BMI2-NEXT:    testb $32, %cl
560; BMI2-NEXT:    cmovnel %esi, %eax
561; BMI2-NEXT:    cmovel %esi, %edx
562; BMI2-NEXT:    popl %esi
563; BMI2-NEXT:    retl
564;
565; BMI264-LABEL: ashr64and:
566; BMI264:       # %bb.0:
567; BMI264-NEXT:    sarxq %rdi, %rsi, %rax
568; BMI264-NEXT:    retq
569;
570; EGPR-LABEL: ashr64and:
571; EGPR:       # %bb.0:
572; EGPR-NEXT:    sarxq %rdi, %rsi, %rax # EVEX TO VEX Compression encoding: [0xc4,0xe2,0xc2,0xf7,0xc6]
573; EGPR-NEXT:    retq # encoding: [0xc3]
574  %shamt = and i64 %t, 63
575  %res = ashr i64 %val, %shamt
576  ret i64 %res
577}
578