1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -mtriple=x86_64-unknown-unknown -S | FileCheck %s
4 declare i32 @llvm.x86.tbm.bextri.u32(i32, i32) nounwind readnone
5 declare i64 @llvm.x86.tbm.bextri.u64(i64, i64) nounwind readnone
6 declare i32 @llvm.x86.bmi.bextr.32(i32, i32) nounwind readnone
7 declare i64 @llvm.x86.bmi.bextr.64(i64, i64) nounwind readnone
8 declare i32 @llvm.x86.bmi.bzhi.32(i32, i32) nounwind readnone
9 declare i64 @llvm.x86.bmi.bzhi.64(i64, i64) nounwind readnone
10 declare i32 @llvm.x86.bmi.pext.32(i32, i32) nounwind readnone
11 declare i64 @llvm.x86.bmi.pext.64(i64, i64) nounwind readnone
12 declare i32 @llvm.x86.bmi.pdep.32(i32, i32) nounwind readnone
13 declare i64 @llvm.x86.bmi.pdep.64(i64, i64) nounwind readnone
15 define i32 @test_x86_tbm_bextri_u32(i32 %a) nounwind readnone {
16 ; CHECK-LABEL: @test_x86_tbm_bextri_u32(
17 ; CHECK-NEXT: [[TMP1:%.*]] = tail call i32 @llvm.x86.tbm.bextri.u32(i32 [[A:%.*]], i32 1296)
18 ; CHECK-NEXT: ret i32 [[TMP1]]
20 %1 = tail call i32 @llvm.x86.tbm.bextri.u32(i32 %a, i32 1296)
24 define i32 @test_x86_tbm_bextri_u32_zero_length(i32 %a) nounwind readnone {
25 ; CHECK-LABEL: @test_x86_tbm_bextri_u32_zero_length(
26 ; CHECK-NEXT: ret i32 0
28 %1 = tail call i32 @llvm.x86.tbm.bextri.u32(i32 %a, i32 1)
32 define i32 @test_x86_tbm_bextri_u32_large_shift(i32 %a) nounwind readnone {
33 ; CHECK-LABEL: @test_x86_tbm_bextri_u32_large_shift(
34 ; CHECK-NEXT: ret i32 0
36 %1 = tail call i32 @llvm.x86.tbm.bextri.u32(i32 %a, i32 288)
40 define i64 @test_x86_tbm_bextri_u64(i64 %a) nounwind readnone {
41 ; CHECK-LABEL: @test_x86_tbm_bextri_u64(
42 ; CHECK-NEXT: [[TMP1:%.*]] = tail call i64 @llvm.x86.tbm.bextri.u64(i64 [[A:%.*]], i64 1312)
43 ; CHECK-NEXT: ret i64 [[TMP1]]
45 %1 = tail call i64 @llvm.x86.tbm.bextri.u64(i64 %a, i64 1312)
49 define i64 @test_x86_tbm_bextri_u64_zero_length(i64 %a) nounwind readnone {
50 ; CHECK-LABEL: @test_x86_tbm_bextri_u64_zero_length(
51 ; CHECK-NEXT: ret i64 0
53 %1 = tail call i64 @llvm.x86.tbm.bextri.u64(i64 %a, i64 1)
57 define i64 @test_x86_tbm_bextri_u64_large_shift(i64 %a) nounwind readnone {
58 ; CHECK-LABEL: @test_x86_tbm_bextri_u64_large_shift(
59 ; CHECK-NEXT: ret i64 0
61 %1 = tail call i64 @llvm.x86.tbm.bextri.u64(i64 %a, i64 320)
65 define i32 @test_x86_tbm_bextri_u32_constfold() nounwind readnone {
66 ; CHECK-LABEL: @test_x86_tbm_bextri_u32_constfold(
67 ; CHECK-NEXT: ret i32 57005
69 %1 = tail call i32 @llvm.x86.tbm.bextri.u32(i32 3735928559, i32 4112) ; extract bits 31:16 from 0xDEADBEEF
73 define i32 @test_x86_tbm_bextri_u32_constfold2() nounwind readnone {
74 ; CHECK-LABEL: @test_x86_tbm_bextri_u32_constfold2(
75 ; CHECK-NEXT: ret i32 233495534
77 %1 = tail call i32 @llvm.x86.tbm.bextri.u32(i32 3735928559, i32 8196) ; extract bits 35:4 from 0xDEADBEEF
81 define i32 @test_x86_tbm_bextri_u32_constfold3() nounwind readnone {
82 ; CHECK-LABEL: @test_x86_tbm_bextri_u32_constfold3(
83 ; CHECK-NEXT: ret i32 233495534
85 %1 = tail call i32 @llvm.x86.tbm.bextri.u32(i32 3735928559, i32 16388) ; extract bits 67:4 from 0xDEADBEEF
89 define i64 @test_x86_tbm_bextri_u64_constfold() nounwind readnone {
90 ; CHECK-LABEL: @test_x86_tbm_bextri_u64_constfold(
91 ; CHECK-NEXT: ret i64 57005
93 %1 = tail call i64 @llvm.x86.tbm.bextri.u64(i64 3735928559, i64 4112) ; extract bits 31:16 from 0xDEADBEEF
97 define i64 @test_x86_tbm_bextri_u64_constfold2() nounwind readnone {
98 ; CHECK-LABEL: @test_x86_tbm_bextri_u64_constfold2(
99 ; CHECK-NEXT: ret i64 233495534
101 %1 = tail call i64 @llvm.x86.tbm.bextri.u64(i64 3735928559, i64 16388) ; extract bits 67:4 from 0xDEADBEEF
105 define i64 @test_x86_tbm_bextri_u64_constfold3() nounwind readnone {
106 ; CHECK-LABEL: @test_x86_tbm_bextri_u64_constfold3(
107 ; CHECK-NEXT: ret i64 233495534
109 %1 = tail call i64 @llvm.x86.tbm.bextri.u64(i64 3735928559, i64 32772) ; extract bits 131:4 from 0xDEADBEEF
113 define i32 @test_x86_bmi_bextri_32(i32 %a) nounwind readnone {
114 ; CHECK-LABEL: @test_x86_bmi_bextri_32(
115 ; CHECK-NEXT: [[TMP1:%.*]] = tail call i32 @llvm.x86.bmi.bextr.32(i32 [[A:%.*]], i32 1296)
116 ; CHECK-NEXT: ret i32 [[TMP1]]
118 %1 = tail call i32 @llvm.x86.bmi.bextr.32(i32 %a, i32 1296)
122 define i32 @test_x86_bmi_bextri_32_zero_length(i32 %a) nounwind readnone {
123 ; CHECK-LABEL: @test_x86_bmi_bextri_32_zero_length(
124 ; CHECK-NEXT: ret i32 0
126 %1 = tail call i32 @llvm.x86.bmi.bextr.32(i32 %a, i32 1)
130 define i32 @test_x86_bmi_bextri_32_large_shift(i32 %a) nounwind readnone {
131 ; CHECK-LABEL: @test_x86_bmi_bextri_32_large_shift(
132 ; CHECK-NEXT: ret i32 0
134 %1 = tail call i32 @llvm.x86.bmi.bextr.32(i32 %a, i32 288)
138 define i64 @test_x86_bmi_bextri_64(i64 %a) nounwind readnone {
139 ; CHECK-LABEL: @test_x86_bmi_bextri_64(
140 ; CHECK-NEXT: [[TMP1:%.*]] = tail call i64 @llvm.x86.bmi.bextr.64(i64 [[A:%.*]], i64 1312)
141 ; CHECK-NEXT: ret i64 [[TMP1]]
143 %1 = tail call i64 @llvm.x86.bmi.bextr.64(i64 %a, i64 1312)
147 define i64 @test_x86_bmi_bextri_64_zero_length(i64 %a) nounwind readnone {
148 ; CHECK-LABEL: @test_x86_bmi_bextri_64_zero_length(
149 ; CHECK-NEXT: ret i64 0
151 %1 = tail call i64 @llvm.x86.bmi.bextr.64(i64 %a, i64 1)
155 define i64 @test_x86_bmi_bextri_64_large_shift(i64 %a) nounwind readnone {
156 ; CHECK-LABEL: @test_x86_bmi_bextri_64_large_shift(
157 ; CHECK-NEXT: ret i64 0
159 %1 = tail call i64 @llvm.x86.bmi.bextr.64(i64 %a, i64 320)
163 define i32 @test_x86_bmi_bextri_32_constfold() nounwind readnone {
164 ; CHECK-LABEL: @test_x86_bmi_bextri_32_constfold(
165 ; CHECK-NEXT: ret i32 57005
167 %1 = tail call i32 @llvm.x86.bmi.bextr.32(i32 3735928559, i32 4112) ; extract bits 31:16 from 0xDEADBEEF
171 define i32 @test_x86_bmi_bextri_32_constfold2() nounwind readnone {
172 ; CHECK-LABEL: @test_x86_bmi_bextri_32_constfold2(
173 ; CHECK-NEXT: ret i32 233495534
175 %1 = tail call i32 @llvm.x86.bmi.bextr.32(i32 3735928559, i32 8196) ; extract bits 35:4 from 0xDEADBEEF
179 define i32 @test_x86_bmi_bextri_32_constfold3() nounwind readnone {
180 ; CHECK-LABEL: @test_x86_bmi_bextri_32_constfold3(
181 ; CHECK-NEXT: ret i32 233495534
183 %1 = tail call i32 @llvm.x86.bmi.bextr.32(i32 3735928559, i32 16388) ; extract bits 67:4 from 0xDEADBEEF
187 define i64 @test_x86_bmi_bextri_64_constfold() nounwind readnone {
188 ; CHECK-LABEL: @test_x86_bmi_bextri_64_constfold(
189 ; CHECK-NEXT: ret i64 57005
191 %1 = tail call i64 @llvm.x86.bmi.bextr.64(i64 3735928559, i64 4112) ; extract bits 31:16 from 0xDEADBEEF
195 define i64 @test_x86_bmi_bextri_64_constfold2() nounwind readnone {
196 ; CHECK-LABEL: @test_x86_bmi_bextri_64_constfold2(
197 ; CHECK-NEXT: ret i64 233495534
199 %1 = tail call i64 @llvm.x86.bmi.bextr.64(i64 3735928559, i64 16388) ; extract bits 67:4 from 0xDEADBEEF
203 define i64 @test_x86_bmi_bextri_64_constfold3() nounwind readnone {
204 ; CHECK-LABEL: @test_x86_bmi_bextri_64_constfold3(
205 ; CHECK-NEXT: ret i64 233495534
207 %1 = tail call i64 @llvm.x86.bmi.bextr.64(i64 3735928559, i64 32772) ; extract bits 131:4 from 0xDEADBEEF
211 define i32 @test_x86_bmi_bzhi_32(i32 %a) nounwind readnone {
212 ; CHECK-LABEL: @test_x86_bmi_bzhi_32(
213 ; CHECK-NEXT: [[TMP1:%.*]] = tail call i32 @llvm.x86.bmi.bzhi.32(i32 [[A:%.*]], i32 31)
214 ; CHECK-NEXT: ret i32 [[TMP1]]
216 %1 = tail call i32 @llvm.x86.bmi.bzhi.32(i32 %a, i32 31)
220 define i32 @test_x86_bmi_bzhi_32_zero(i32 %a) nounwind readnone {
221 ; CHECK-LABEL: @test_x86_bmi_bzhi_32_zero(
222 ; CHECK-NEXT: ret i32 0
224 %1 = tail call i32 @llvm.x86.bmi.bzhi.32(i32 %a, i32 0)
228 define i32 @test_x86_bmi_bzhi_32_max(i32 %a) nounwind readnone {
229 ; CHECK-LABEL: @test_x86_bmi_bzhi_32_max(
230 ; CHECK-NEXT: ret i32 [[A:%.*]]
232 %1 = tail call i32 @llvm.x86.bmi.bzhi.32(i32 %a, i32 32)
236 define i32 @test_x86_bmi_bzhi_32_constfold() nounwind readnone {
237 ; CHECK-LABEL: @test_x86_bmi_bzhi_32_constfold(
238 ; CHECK-NEXT: ret i32 1
240 %1 = tail call i32 @llvm.x86.bmi.bzhi.32(i32 5, i32 1)
244 define i64 @test_x86_bmi_bzhi_64(i64 %a) nounwind readnone {
245 ; CHECK-LABEL: @test_x86_bmi_bzhi_64(
246 ; CHECK-NEXT: [[TMP1:%.*]] = tail call i64 @llvm.x86.bmi.bzhi.64(i64 [[A:%.*]], i64 63)
247 ; CHECK-NEXT: ret i64 [[TMP1]]
249 %1 = tail call i64 @llvm.x86.bmi.bzhi.64(i64 %a, i64 63)
253 define i64 @test_x86_bmi_bzhi_64_zero(i64 %a) nounwind readnone {
254 ; CHECK-LABEL: @test_x86_bmi_bzhi_64_zero(
255 ; CHECK-NEXT: ret i64 0
257 %1 = tail call i64 @llvm.x86.bmi.bzhi.64(i64 %a, i64 0)
261 define i64 @test_x86_bmi_bzhi_64_max(i64 %a) nounwind readnone {
262 ; CHECK-LABEL: @test_x86_bmi_bzhi_64_max(
263 ; CHECK-NEXT: ret i64 [[A:%.*]]
265 %1 = tail call i64 @llvm.x86.bmi.bzhi.64(i64 %a, i64 64)
269 define i64 @test_x86_bmi_bzhi_64_constfold() nounwind readnone {
270 ; CHECK-LABEL: @test_x86_bmi_bzhi_64_constfold(
271 ; CHECK-NEXT: ret i64 1
273 %1 = tail call i64 @llvm.x86.bmi.bzhi.64(i64 5, i64 1)
277 define i32 @test_x86_pext_32_zero_mask(i32 %x) nounwind readnone {
278 ; CHECK-LABEL: @test_x86_pext_32_zero_mask(
279 ; CHECK-NEXT: ret i32 0
281 %1 = tail call i32 @llvm.x86.bmi.pext.32(i32 %x, i32 0)
285 define i64 @test_x86_pext_64_zero_mask(i64 %x) nounwind readnone {
286 ; CHECK-LABEL: @test_x86_pext_64_zero_mask(
287 ; CHECK-NEXT: ret i64 0
289 %1 = tail call i64 @llvm.x86.bmi.pext.64(i64 %x, i64 0)
293 define i32 @test_x86_pext_32_allones_mask(i32 %x) nounwind readnone {
294 ; CHECK-LABEL: @test_x86_pext_32_allones_mask(
295 ; CHECK-NEXT: ret i32 %x
297 %1 = tail call i32 @llvm.x86.bmi.pext.32(i32 %x, i32 -1)
301 define i64 @test_x86_pext_64_allones_mask(i64 %x) nounwind readnone {
302 ; CHECK-LABEL: @test_x86_pext_64_allones_mask(
303 ; CHECK-NEXT: ret i64 %x
305 %1 = tail call i64 @llvm.x86.bmi.pext.64(i64 %x, i64 -1)
309 define i32 @test_x86_pext_32_shifted_mask(i32 %x) nounwind readnone {
310 ; CHECK-LABEL: @test_x86_pext_32_shifted_mask(
311 ; CHECK-NEXT: %1 = lshr i32 %x, 1
312 ; CHECK-NEXT: %2 = and i32 %1, 3
313 ; CHECK-NEXT: ret i32 %2
315 %1 = tail call i32 @llvm.x86.bmi.pext.32(i32 %x, i32 6)
319 define i64 @test_x86_pext_64_shifted_mask(i64 %x) nounwind readnone {
320 ; CHECK-LABEL: @test_x86_pext_64_shifted_mask(
321 ; CHECK-NEXT: %1 = lshr i64 %x, 1
322 ; CHECK-NEXT: %2 = and i64 %1, 3
323 ; CHECK-NEXT: ret i64 %2
325 %1 = tail call i64 @llvm.x86.bmi.pext.64(i64 %x, i64 6)
330 define i32 @test_x86_pext_32_constant_fold() nounwind readnone {
331 ; CHECK-LABEL: @test_x86_pext_32_constant_fold(
332 ; CHECK-NEXT: ret i32 30001
334 %1 = tail call i32 @llvm.x86.bmi.pext.32(i32 1985229328, i32 4042322160)
338 define i64 @test_x86_pext_64_constant_fold() nounwind readnone {
339 ; CHECK-LABEL: @test_x86_pext_64_constant_fold(
340 ; CHECK-NEXT: ret i64 1966210489
342 %1 = tail call i64 @llvm.x86.bmi.pext.64(i64 8526495043095935640, i64 -1085102592571150096)
346 define i32 @test_x86_pext_32_constant_fold_2() nounwind readnone {
347 ; CHECK-LABEL: @test_x86_pext_32_constant_fold_2(
348 ; CHECK-NEXT: ret i32 30224
350 %1 = tail call i32 @llvm.x86.bmi.pext.32(i32 1985229328, i32 4278190335)
354 define i64 @test_x86_pext_64_constant_fold_2() nounwind readnone {
355 ; CHECK-LABEL: @test_x86_pext_64_constant_fold_2(
356 ; CHECK-NEXT: ret i64 1980816570
358 %1 = tail call i64 @llvm.x86.bmi.pext.64(i64 8526495043095935640, i64 -72056498804490496)
362 define i32 @test_x86_pdep_32_zero_mask(i32 %x) nounwind readnone {
363 ; CHECK-LABEL: @test_x86_pdep_32_zero_mask(
364 ; CHECK-NEXT: ret i32 0
366 %1 = tail call i32 @llvm.x86.bmi.pdep.32(i32 %x, i32 0)
370 define i64 @test_x86_pdep_64_zero_mask(i64 %x) nounwind readnone {
371 ; CHECK-LABEL: @test_x86_pdep_64_zero_mask(
372 ; CHECK-NEXT: ret i64 0
374 %1 = tail call i64 @llvm.x86.bmi.pdep.64(i64 %x, i64 0)
378 define i32 @test_x86_pdep_32_allones_mask(i32 %x) nounwind readnone {
379 ; CHECK-LABEL: @test_x86_pdep_32_allones_mask(
380 ; CHECK-NEXT: ret i32 %x
382 %1 = tail call i32 @llvm.x86.bmi.pdep.32(i32 %x, i32 -1)
386 define i64 @test_x86_pdep_64_allones_mask(i64 %x) nounwind readnone {
387 ; CHECK-LABEL: @test_x86_pdep_64_allones_mask(
388 ; CHECK-NEXT: ret i64 %x
390 %1 = tail call i64 @llvm.x86.bmi.pdep.64(i64 %x, i64 -1)
394 define i32 @test_x86_pdep_32_shifted_mask(i32 %x) nounwind readnone {
395 ; CHECK-LABEL: @test_x86_pdep_32_shifted_mask(
396 ; CHECK-NEXT: %1 = shl i32 %x, 2
397 ; CHECK-NEXT: %2 = and i32 %1, 12
398 ; CHECK-NEXT: ret i32 %2
400 %1 = tail call i32 @llvm.x86.bmi.pdep.32(i32 %x, i32 12)
404 define i64 @test_x86_pdep_64_shifted_mask(i64 %x) nounwind readnone {
405 ; CHECK-LABEL: @test_x86_pdep_64_shifted_mask(
406 ; CHECK-NEXT: %1 = shl i64 %x, 2
407 ; CHECK-NEXT: %2 = and i64 %1, 12
408 ; CHECK-NEXT: ret i64 %2
410 %1 = tail call i64 @llvm.x86.bmi.pdep.64(i64 %x, i64 12)
415 define i32 @test_x86_pdep_32_constant_fold() nounwind readnone {
416 ; CHECK-LABEL: @test_x86_pdep_32_constant_fold(
417 ; CHECK-NEXT: ret i32 807407616
419 %1 = tail call i32 @llvm.x86.bmi.pdep.32(i32 1985229328, i32 4042322160)
423 define i64 @test_x86_pdep_64_constant_fold() nounwind readnone {
424 ; CHECK-LABEL: @test_x86_pdep_64_constant_fold(
425 ; CHECK-NEXT: ret i64 -1089641583808049024
427 %1 = tail call i64 @llvm.x86.bmi.pdep.64(i64 8526495043095935640, i64 -1085102592571150096)
431 define i32 @test_x86_pdep_32_constant_fold_2() nounwind readnone {
432 ; CHECK-LABEL: @test_x86_pdep_32_constant_fold_2(
433 ; CHECK-NEXT: ret i32 838860816
435 %1 = tail call i32 @llvm.x86.bmi.pdep.32(i32 1985229328, i32 4278190335)
439 define i64 @test_x86_pdep_64_constant_fold_2() nounwind readnone {
440 ; CHECK-LABEL: @test_x86_pdep_64_constant_fold_2(
441 ; CHECK-NEXT: ret i64 -144114243170822144
443 %1 = tail call i64 @llvm.x86.bmi.pdep.64(i64 8526495043095935640, i64 -72056498804490496)