blob: 242075a878bbf1f136ce024cea427655d4cf28b0 [file] [log] [blame]
Craig Topper717cdb02011-10-19 07:48:35 +00001; RUN: llc < %s -march=x86-64 -mattr=+bmi,+bmi2 | FileCheck %s
Craig Topper909652f2011-10-14 03:21:46 +00002
Chandler Carruth131f7d32011-12-24 11:11:36 +00003declare i8 @llvm.cttz.i8(i8, i1) nounwind readnone
4declare i16 @llvm.cttz.i16(i16, i1) nounwind readnone
5declare i32 @llvm.cttz.i32(i32, i1) nounwind readnone
6declare i64 @llvm.cttz.i64(i64, i1) nounwind readnone
7
8define i8 @t1(i8 %x) nounwind {
9 %tmp = tail call i8 @llvm.cttz.i8( i8 %x, i1 false )
10 ret i8 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +000011; CHECK-LABEL: t1:
Chandler Carruth77821022011-12-24 12:12:34 +000012; CHECK: tzcntl
Craig Topper909652f2011-10-14 03:21:46 +000013}
14
Craig Topper909652f2011-10-14 03:21:46 +000015define i16 @t2(i16 %x) nounwind {
Chandler Carruth131f7d32011-12-24 11:11:36 +000016 %tmp = tail call i16 @llvm.cttz.i16( i16 %x, i1 false )
17 ret i16 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +000018; CHECK-LABEL: t2:
Craig Topper909652f2011-10-14 03:21:46 +000019; CHECK: tzcntw
20}
21
Chandler Carruth131f7d32011-12-24 11:11:36 +000022define i32 @t3(i32 %x) nounwind {
23 %tmp = tail call i32 @llvm.cttz.i32( i32 %x, i1 false )
24 ret i32 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +000025; CHECK-LABEL: t3:
Chandler Carruth131f7d32011-12-24 11:11:36 +000026; CHECK: tzcntl
27}
28
Craig Topperb72ae702012-12-17 05:02:29 +000029define i32 @tzcnt32_load(i32* %x) nounwind {
30 %x1 = load i32* %x
31 %tmp = tail call i32 @llvm.cttz.i32(i32 %x1, i1 false )
32 ret i32 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +000033; CHECK-LABEL: tzcnt32_load:
Craig Topperb72ae702012-12-17 05:02:29 +000034; CHECK: tzcntl ({{.*}})
35}
36
Chandler Carruth131f7d32011-12-24 11:11:36 +000037define i64 @t4(i64 %x) nounwind {
38 %tmp = tail call i64 @llvm.cttz.i64( i64 %x, i1 false )
39 ret i64 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +000040; CHECK-LABEL: t4:
Craig Topper909652f2011-10-14 03:21:46 +000041; CHECK: tzcntq
42}
43
Chandler Carruthd873a4b2011-12-24 11:11:38 +000044define i8 @t5(i8 %x) nounwind {
45 %tmp = tail call i8 @llvm.cttz.i8( i8 %x, i1 true )
46 ret i8 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +000047; CHECK-LABEL: t5:
Chandler Carruth77821022011-12-24 12:12:34 +000048; CHECK: tzcntl
Chandler Carruthd873a4b2011-12-24 11:11:38 +000049}
50
51define i16 @t6(i16 %x) nounwind {
52 %tmp = tail call i16 @llvm.cttz.i16( i16 %x, i1 true )
53 ret i16 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +000054; CHECK-LABEL: t6:
Chandler Carruthd873a4b2011-12-24 11:11:38 +000055; CHECK: tzcntw
56}
57
58define i32 @t7(i32 %x) nounwind {
59 %tmp = tail call i32 @llvm.cttz.i32( i32 %x, i1 true )
60 ret i32 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +000061; CHECK-LABEL: t7:
Chandler Carruthd873a4b2011-12-24 11:11:38 +000062; CHECK: tzcntl
63}
64
65define i64 @t8(i64 %x) nounwind {
66 %tmp = tail call i64 @llvm.cttz.i64( i64 %x, i1 true )
67 ret i64 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +000068; CHECK-LABEL: t8:
Chandler Carruthd873a4b2011-12-24 11:11:38 +000069; CHECK: tzcntq
70}
71
Craig Topper54a11172011-10-14 07:06:56 +000072define i32 @andn32(i32 %x, i32 %y) nounwind readnone {
73 %tmp1 = xor i32 %x, -1
74 %tmp2 = and i32 %y, %tmp1
75 ret i32 %tmp2
Stephen Lin8b2b8a12013-07-14 06:24:09 +000076; CHECK-LABEL: andn32:
Craig Topper54a11172011-10-14 07:06:56 +000077; CHECK: andnl
78}
79
Craig Topperb72ae702012-12-17 05:02:29 +000080define i32 @andn32_load(i32 %x, i32* %y) nounwind readnone {
81 %y1 = load i32* %y
82 %tmp1 = xor i32 %x, -1
83 %tmp2 = and i32 %y1, %tmp1
84 ret i32 %tmp2
Stephen Lin8b2b8a12013-07-14 06:24:09 +000085; CHECK-LABEL: andn32_load:
Craig Topperb72ae702012-12-17 05:02:29 +000086; CHECK: andnl ({{.*}})
87}
88
Craig Topper54a11172011-10-14 07:06:56 +000089define i64 @andn64(i64 %x, i64 %y) nounwind readnone {
90 %tmp1 = xor i64 %x, -1
91 %tmp2 = and i64 %tmp1, %y
92 ret i64 %tmp2
Stephen Lin8b2b8a12013-07-14 06:24:09 +000093; CHECK-LABEL: andn64:
Craig Topper54a11172011-10-14 07:06:56 +000094; CHECK: andnq
95}
Craig Topper717cdb02011-10-19 07:48:35 +000096
97define i32 @bextr32(i32 %x, i32 %y) nounwind readnone {
98 %tmp = tail call i32 @llvm.x86.bmi.bextr.32(i32 %x, i32 %y)
99 ret i32 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000100; CHECK-LABEL: bextr32:
Craig Topper717cdb02011-10-19 07:48:35 +0000101; CHECK: bextrl
102}
103
Craig Topperb72ae702012-12-17 05:02:29 +0000104define i32 @bextr32_load(i32* %x, i32 %y) nounwind readnone {
105 %x1 = load i32* %x
106 %tmp = tail call i32 @llvm.x86.bmi.bextr.32(i32 %x1, i32 %y)
107 ret i32 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000108; CHECK-LABEL: bextr32_load:
Craig Topperb72ae702012-12-17 05:02:29 +0000109; CHECK: bextrl {{.*}}, ({{.*}}), {{.*}}
110}
111
Craig Topper717cdb02011-10-19 07:48:35 +0000112declare i32 @llvm.x86.bmi.bextr.32(i32, i32) nounwind readnone
113
Craig Topper69c474f2013-09-02 07:53:17 +0000114define i32 @bextr32b(i32 %x) nounwind uwtable readnone ssp {
115 %1 = lshr i32 %x, 4
116 %2 = and i32 %1, 4095
117 ret i32 %2
118; CHECK-LABEL: bextr32b:
119; CHECK: bextrl
120}
121
122define i32 @bextr32b_load(i32* %x) nounwind uwtable readnone ssp {
123 %1 = load i32* %x
124 %2 = lshr i32 %1, 4
125 %3 = and i32 %2, 4095
126 ret i32 %3
127; CHECK-LABEL: bextr32b_load:
128; CHECK: bextrl {{.*}}, ({{.*}}), {{.*}}
129}
130
Craig Topper717cdb02011-10-19 07:48:35 +0000131define i64 @bextr64(i64 %x, i64 %y) nounwind readnone {
132 %tmp = tail call i64 @llvm.x86.bmi.bextr.64(i64 %x, i64 %y)
133 ret i64 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000134; CHECK-LABEL: bextr64:
Craig Topper717cdb02011-10-19 07:48:35 +0000135; CHECK: bextrq
136}
137
138declare i64 @llvm.x86.bmi.bextr.64(i64, i64) nounwind readnone
139
Craig Topper69c474f2013-09-02 07:53:17 +0000140define i64 @bextr64b(i64 %x) nounwind uwtable readnone ssp {
141 %1 = lshr i64 %x, 4
142 %2 = and i64 %1, 4095
143 ret i64 %2
144; CHECK-LABEL: bextr64b:
145; CHECK: bextrq
146}
147
Craig Topper717cdb02011-10-19 07:48:35 +0000148define i32 @bzhi32(i32 %x, i32 %y) nounwind readnone {
149 %tmp = tail call i32 @llvm.x86.bmi.bzhi.32(i32 %x, i32 %y)
150 ret i32 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000151; CHECK-LABEL: bzhi32:
Craig Topper717cdb02011-10-19 07:48:35 +0000152; CHECK: bzhil
153}
154
Craig Topperb72ae702012-12-17 05:02:29 +0000155define i32 @bzhi32_load(i32* %x, i32 %y) nounwind readnone {
156 %x1 = load i32* %x
157 %tmp = tail call i32 @llvm.x86.bmi.bzhi.32(i32 %x1, i32 %y)
158 ret i32 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000159; CHECK-LABEL: bzhi32_load:
Craig Topperb72ae702012-12-17 05:02:29 +0000160; CHECK: bzhil {{.*}}, ({{.*}}), {{.*}}
161}
162
Craig Topper717cdb02011-10-19 07:48:35 +0000163declare i32 @llvm.x86.bmi.bzhi.32(i32, i32) nounwind readnone
164
165define i64 @bzhi64(i64 %x, i64 %y) nounwind readnone {
166 %tmp = tail call i64 @llvm.x86.bmi.bzhi.64(i64 %x, i64 %y)
167 ret i64 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000168; CHECK-LABEL: bzhi64:
Craig Topper717cdb02011-10-19 07:48:35 +0000169; CHECK: bzhiq
170}
171
172declare i64 @llvm.x86.bmi.bzhi.64(i64, i64) nounwind readnone
173
Craig Topperb6ac30a2013-08-30 06:52:21 +0000174define i32 @bzhi32b(i32 %x, i8 zeroext %index) #0 {
175entry:
176 %conv = zext i8 %index to i32
177 %shl = shl i32 1, %conv
178 %sub = add nsw i32 %shl, -1
179 %and = and i32 %sub, %x
180 ret i32 %and
181; CHECK-LABEL: bzhi32b:
182; CHECK: bzhil
183}
184
185define i32 @bzhi32b_load(i32* %w, i8 zeroext %index) #0 {
186entry:
187 %x = load i32* %w
188 %conv = zext i8 %index to i32
189 %shl = shl i32 1, %conv
190 %sub = add nsw i32 %shl, -1
191 %and = and i32 %sub, %x
192 ret i32 %and
193; CHECK-LABEL: bzhi32b_load:
194; CHECK: bzhil {{.*}}, ({{.*}}), {{.*}}
195}
196
197define i32 @bzhi32c(i32 %x, i8 zeroext %index) #0 {
198entry:
199 %conv = zext i8 %index to i32
200 %shl = shl i32 1, %conv
201 %sub = add nsw i32 %shl, -1
202 %and = and i32 %x, %sub
203 ret i32 %and
204; CHECK-LABEL: bzhi32c:
205; CHECK: bzhil
206}
207
208define i64 @bzhi64b(i64 %x, i8 zeroext %index) #0 {
209entry:
210 %conv = zext i8 %index to i64
211 %shl = shl i64 1, %conv
212 %sub = add nsw i64 %shl, -1
213 %and = and i64 %x, %sub
214 ret i64 %and
215; CHECK-LABEL: bzhi64b:
216; CHECK: bzhiq
217}
218
Craig Topper717cdb02011-10-19 07:48:35 +0000219define i32 @blsi32(i32 %x) nounwind readnone {
Craig Topperb4c94572011-10-21 06:55:01 +0000220 %tmp = sub i32 0, %x
221 %tmp2 = and i32 %x, %tmp
222 ret i32 %tmp2
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000223; CHECK-LABEL: blsi32:
Craig Topper717cdb02011-10-19 07:48:35 +0000224; CHECK: blsil
225}
226
Craig Topperb72ae702012-12-17 05:02:29 +0000227define i32 @blsi32_load(i32* %x) nounwind readnone {
228 %x1 = load i32* %x
229 %tmp = sub i32 0, %x1
230 %tmp2 = and i32 %x1, %tmp
231 ret i32 %tmp2
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000232; CHECK-LABEL: blsi32_load:
Craig Topperb72ae702012-12-17 05:02:29 +0000233; CHECK: blsil ({{.*}})
234}
235
Craig Topper717cdb02011-10-19 07:48:35 +0000236define i64 @blsi64(i64 %x) nounwind readnone {
Craig Topperb4c94572011-10-21 06:55:01 +0000237 %tmp = sub i64 0, %x
238 %tmp2 = and i64 %tmp, %x
239 ret i64 %tmp2
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000240; CHECK-LABEL: blsi64:
Craig Topper717cdb02011-10-19 07:48:35 +0000241; CHECK: blsiq
242}
243
Craig Topper717cdb02011-10-19 07:48:35 +0000244define i32 @blsmsk32(i32 %x) nounwind readnone {
Craig Topperb4c94572011-10-21 06:55:01 +0000245 %tmp = sub i32 %x, 1
246 %tmp2 = xor i32 %x, %tmp
247 ret i32 %tmp2
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000248; CHECK-LABEL: blsmsk32:
Craig Topper717cdb02011-10-19 07:48:35 +0000249; CHECK: blsmskl
250}
251
Craig Topperb72ae702012-12-17 05:02:29 +0000252define i32 @blsmsk32_load(i32* %x) nounwind readnone {
253 %x1 = load i32* %x
254 %tmp = sub i32 %x1, 1
255 %tmp2 = xor i32 %x1, %tmp
256 ret i32 %tmp2
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000257; CHECK-LABEL: blsmsk32_load:
Craig Topperb72ae702012-12-17 05:02:29 +0000258; CHECK: blsmskl ({{.*}})
259}
260
Craig Topper717cdb02011-10-19 07:48:35 +0000261define i64 @blsmsk64(i64 %x) nounwind readnone {
Craig Topperb4c94572011-10-21 06:55:01 +0000262 %tmp = sub i64 %x, 1
263 %tmp2 = xor i64 %tmp, %x
264 ret i64 %tmp2
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000265; CHECK-LABEL: blsmsk64:
Craig Topper717cdb02011-10-19 07:48:35 +0000266; CHECK: blsmskq
267}
268
Craig Topper717cdb02011-10-19 07:48:35 +0000269define i32 @blsr32(i32 %x) nounwind readnone {
Craig Topperb4c94572011-10-21 06:55:01 +0000270 %tmp = sub i32 %x, 1
271 %tmp2 = and i32 %x, %tmp
272 ret i32 %tmp2
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000273; CHECK-LABEL: blsr32:
Craig Topper717cdb02011-10-19 07:48:35 +0000274; CHECK: blsrl
275}
276
Craig Topperb72ae702012-12-17 05:02:29 +0000277define i32 @blsr32_load(i32* %x) nounwind readnone {
278 %x1 = load i32* %x
279 %tmp = sub i32 %x1, 1
280 %tmp2 = and i32 %x1, %tmp
281 ret i32 %tmp2
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000282; CHECK-LABEL: blsr32_load:
Craig Topperb72ae702012-12-17 05:02:29 +0000283; CHECK: blsrl ({{.*}})
284}
285
Craig Topper717cdb02011-10-19 07:48:35 +0000286define i64 @blsr64(i64 %x) nounwind readnone {
Craig Topperb4c94572011-10-21 06:55:01 +0000287 %tmp = sub i64 %x, 1
288 %tmp2 = and i64 %tmp, %x
289 ret i64 %tmp2
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000290; CHECK-LABEL: blsr64:
Craig Topper717cdb02011-10-19 07:48:35 +0000291; CHECK: blsrq
292}
293
Craig Topper717cdb02011-10-19 07:48:35 +0000294define i32 @pdep32(i32 %x, i32 %y) nounwind readnone {
295 %tmp = tail call i32 @llvm.x86.bmi.pdep.32(i32 %x, i32 %y)
296 ret i32 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000297; CHECK-LABEL: pdep32:
Craig Topper717cdb02011-10-19 07:48:35 +0000298; CHECK: pdepl
299}
300
Craig Topperb72ae702012-12-17 05:02:29 +0000301define i32 @pdep32_load(i32 %x, i32* %y) nounwind readnone {
302 %y1 = load i32* %y
303 %tmp = tail call i32 @llvm.x86.bmi.pdep.32(i32 %x, i32 %y1)
304 ret i32 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000305; CHECK-LABEL: pdep32_load:
Craig Topperb72ae702012-12-17 05:02:29 +0000306; CHECK: pdepl ({{.*}})
307}
308
Craig Topper717cdb02011-10-19 07:48:35 +0000309declare i32 @llvm.x86.bmi.pdep.32(i32, i32) nounwind readnone
310
311define i64 @pdep64(i64 %x, i64 %y) nounwind readnone {
312 %tmp = tail call i64 @llvm.x86.bmi.pdep.64(i64 %x, i64 %y)
313 ret i64 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000314; CHECK-LABEL: pdep64:
Craig Topper717cdb02011-10-19 07:48:35 +0000315; CHECK: pdepq
316}
317
318declare i64 @llvm.x86.bmi.pdep.64(i64, i64) nounwind readnone
319
320define i32 @pext32(i32 %x, i32 %y) nounwind readnone {
321 %tmp = tail call i32 @llvm.x86.bmi.pext.32(i32 %x, i32 %y)
322 ret i32 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000323; CHECK-LABEL: pext32:
Craig Topper717cdb02011-10-19 07:48:35 +0000324; CHECK: pextl
325}
326
Craig Topperb72ae702012-12-17 05:02:29 +0000327define i32 @pext32_load(i32 %x, i32* %y) nounwind readnone {
328 %y1 = load i32* %y
329 %tmp = tail call i32 @llvm.x86.bmi.pext.32(i32 %x, i32 %y1)
330 ret i32 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000331; CHECK-LABEL: pext32_load:
Craig Topperb72ae702012-12-17 05:02:29 +0000332; CHECK: pextl ({{.*}})
333}
334
Craig Topper717cdb02011-10-19 07:48:35 +0000335declare i32 @llvm.x86.bmi.pext.32(i32, i32) nounwind readnone
336
337define i64 @pext64(i64 %x, i64 %y) nounwind readnone {
338 %tmp = tail call i64 @llvm.x86.bmi.pext.64(i64 %x, i64 %y)
339 ret i64 %tmp
Stephen Lin8b2b8a12013-07-14 06:24:09 +0000340; CHECK-LABEL: pext64:
Craig Topper717cdb02011-10-19 07:48:35 +0000341; CHECK: pextq
342}
343
344declare i64 @llvm.x86.bmi.pext.64(i64, i64) nounwind readnone
345