1; RUN: llc < %s -march=x86 -mcpu=corei7 | FileCheck %s
2; RUN: llc < %s -march=x86 -mcpu=core-avx2 | FileCheck %s --check-prefix=BMI2
3
4define i32 @foo(i32 %x, i32 %y, i32 %z) nounwind readnone {
5entry:
6; CHECK-LABEL: foo:
7; CHECK: roll %cl
8	%0 = shl i32 %x, %z
9	%1 = sub i32 32, %z
10	%2 = lshr i32 %x, %1
11	%3 = or i32 %2, %0
12	ret i32 %3
13}
14
15define i32 @bar(i32 %x, i32 %y, i32 %z) nounwind readnone {
16entry:
17; CHECK-LABEL: bar:
18; CHECK: shldl %cl
19	%0 = shl i32 %y, %z
20	%1 = sub i32 32, %z
21	%2 = lshr i32 %x, %1
22	%3 = or i32 %2, %0
23	ret i32 %3
24}
25
26define i32 @un(i32 %x, i32 %y, i32 %z) nounwind readnone {
27entry:
28; CHECK-LABEL: un:
29; CHECK: rorl %cl
30	%0 = lshr i32 %x, %z
31	%1 = sub i32 32, %z
32	%2 = shl i32 %x, %1
33	%3 = or i32 %2, %0
34	ret i32 %3
35}
36
37define i32 @bu(i32 %x, i32 %y, i32 %z) nounwind readnone {
38entry:
39; CHECK-LABEL: bu:
40; CHECK: shrdl %cl
41	%0 = lshr i32 %y, %z
42	%1 = sub i32 32, %z
43	%2 = shl i32 %x, %1
44	%3 = or i32 %2, %0
45	ret i32 %3
46}
47
48define i32 @xfoo(i32 %x, i32 %y, i32 %z) nounwind readnone {
49entry:
50; CHECK-LABEL: xfoo:
51; CHECK: roll $7
52; BMI2-LABEL: xfoo:
53; BMI2: rorxl $25
54	%0 = lshr i32 %x, 25
55	%1 = shl i32 %x, 7
56	%2 = or i32 %0, %1
57	ret i32 %2
58}
59
60define i32 @xfoop(i32* %p) nounwind readnone {
61entry:
62; BMI2-LABEL: xfoop:
63; BMI2: rorxl $25, ({{.+}}), %{{.+}}
64	%x = load i32* %p
65	%a = lshr i32 %x, 25
66	%b = shl i32 %x, 7
67	%c = or i32 %a, %b
68	ret i32 %c
69}
70
71define i32 @xbar(i32 %x, i32 %y, i32 %z) nounwind readnone {
72entry:
73; CHECK-LABEL: xbar:
74; CHECK: shldl $7
75	%0 = shl i32 %y, 7
76	%1 = lshr i32 %x, 25
77	%2 = or i32 %0, %1
78	ret i32 %2
79}
80
81define i32 @xun(i32 %x, i32 %y, i32 %z) nounwind readnone {
82entry:
83; CHECK-LABEL: xun:
84; CHECK: roll $25
85; BMI2-LABEL: xun:
86; BMI2: rorxl $7
87	%0 = lshr i32 %x, 7
88	%1 = shl i32 %x, 25
89	%2 = or i32 %0, %1
90	ret i32 %2
91}
92
93define i32 @xunp(i32* %p) nounwind readnone {
94entry:
95; BMI2-LABEL: xunp:
96; BMI2: rorxl $7, ({{.+}}), %{{.+}}
97	%x = load i32* %p
98	%a = lshr i32 %x, 7
99	%b = shl i32 %x, 25
100	%c = or i32 %a, %b
101	ret i32 %c
102}
103
104define i32 @xbu(i32 %x, i32 %y, i32 %z) nounwind readnone {
105entry:
106; CHECK-LABEL: xbu:
107; CHECK: shldl
108	%0 = lshr i32 %y, 7
109	%1 = shl i32 %x, 25
110	%2 = or i32 %0, %1
111	ret i32 %2
112}
113