1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+bmi | FileCheck %s --check-prefixes=CHECK,BEXTR-SLOW,BMI1,BMI1-SLOW
3 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+bmi,+bmi2 | FileCheck %s --check-prefixes=CHECK,BEXTR-SLOW,BMI2,BMI2-SLOW
4 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+bmi,+fast-bextr | FileCheck %s --check-prefixes=CHECK,BEXTR-FAST,BMI1,BMI1-FAST
5 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+bmi,+bmi2,+fast-bextr | FileCheck %s --check-prefixes=CHECK,BEXTR-FAST,BMI2,BMI2-FAST
7 declare i64 @llvm.x86.bmi.bextr.64(i64, i64)
9 define i64 @bextr64(i64 %x, i64 %y) {
10 ; CHECK-LABEL: bextr64:
12 ; CHECK-NEXT: bextrq %rsi, %rdi, %rax
14 %tmp = tail call i64 @llvm.x86.bmi.bextr.64(i64 %x, i64 %y)
18 define i64 @bextr64b(i64 %x) uwtable ssp {
19 ; BEXTR-SLOW-LABEL: bextr64b:
20 ; BEXTR-SLOW: # %bb.0:
21 ; BEXTR-SLOW-NEXT: movq %rdi, %rax
22 ; BEXTR-SLOW-NEXT: shrl $4, %eax
23 ; BEXTR-SLOW-NEXT: andl $4095, %eax # imm = 0xFFF
24 ; BEXTR-SLOW-NEXT: retq
26 ; BEXTR-FAST-LABEL: bextr64b:
27 ; BEXTR-FAST: # %bb.0:
28 ; BEXTR-FAST-NEXT: movl $3076, %eax # imm = 0xC04
29 ; BEXTR-FAST-NEXT: bextrl %eax, %edi, %eax
30 ; BEXTR-FAST-NEXT: retq
36 ; Make sure we still use the AH subreg trick to extract 15:8
37 define i64 @bextr64_subreg(i64 %x) uwtable ssp {
38 ; CHECK-LABEL: bextr64_subreg:
40 ; CHECK-NEXT: movq %rdi, %rax
41 ; CHECK-NEXT: movzbl %ah, %eax
48 define i64 @bextr64b_load(i64* %x) {
49 ; BEXTR-SLOW-LABEL: bextr64b_load:
50 ; BEXTR-SLOW: # %bb.0:
51 ; BEXTR-SLOW-NEXT: movl (%rdi), %eax
52 ; BEXTR-SLOW-NEXT: shrl $4, %eax
53 ; BEXTR-SLOW-NEXT: andl $4095, %eax # imm = 0xFFF
54 ; BEXTR-SLOW-NEXT: retq
56 ; BEXTR-FAST-LABEL: bextr64b_load:
57 ; BEXTR-FAST: # %bb.0:
58 ; BEXTR-FAST-NEXT: movl $3076, %eax # imm = 0xC04
59 ; BEXTR-FAST-NEXT: bextrl %eax, (%rdi), %eax
60 ; BEXTR-FAST-NEXT: retq
61 %1 = load i64, i64* %x, align 8
68 define i64 @bextr64c(i64 %x, i32 %y) {
69 ; CHECK-LABEL: bextr64c:
71 ; CHECK-NEXT: # kill: def $esi killed $esi def $rsi
72 ; CHECK-NEXT: bextrq %rsi, %rdi, %rax
74 %tmp0 = sext i32 %y to i64
75 %tmp1 = tail call i64 @llvm.x86.bmi.bextr.64(i64 %x, i64 %tmp0)
79 define i64 @bextr64d(i64 %a) {
80 ; BMI1-SLOW-LABEL: bextr64d:
81 ; BMI1-SLOW: # %bb.0: # %entry
82 ; BMI1-SLOW-NEXT: shrq $2, %rdi
83 ; BMI1-SLOW-NEXT: movl $8448, %eax # imm = 0x2100
84 ; BMI1-SLOW-NEXT: bextrq %rax, %rdi, %rax
85 ; BMI1-SLOW-NEXT: retq
87 ; BMI2-SLOW-LABEL: bextr64d:
88 ; BMI2-SLOW: # %bb.0: # %entry
89 ; BMI2-SLOW-NEXT: shrq $2, %rdi
90 ; BMI2-SLOW-NEXT: movb $33, %al
91 ; BMI2-SLOW-NEXT: bzhiq %rax, %rdi, %rax
92 ; BMI2-SLOW-NEXT: retq
94 ; BEXTR-FAST-LABEL: bextr64d:
95 ; BEXTR-FAST: # %bb.0: # %entry
96 ; BEXTR-FAST-NEXT: movl $8450, %eax # imm = 0x2102
97 ; BEXTR-FAST-NEXT: bextrq %rax, %rdi, %rax
98 ; BEXTR-FAST-NEXT: retq
100 %shr = lshr i64 %a, 2
101 %and = and i64 %shr, 8589934591
105 define i64 @non_bextr64(i64 %x) {
106 ; CHECK-LABEL: non_bextr64:
107 ; CHECK: # %bb.0: # %entry
108 ; CHECK-NEXT: shrq $2, %rdi
109 ; CHECK-NEXT: movabsq $8589934590, %rax # imm = 0x1FFFFFFFE
110 ; CHECK-NEXT: andq %rdi, %rax
113 %shr = lshr i64 %x, 2
114 %and = and i64 %shr, 8589934590