1 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 2
2 # RUN: llc -mtriple=x86_64-linux-gnu -mattr=+bmi -run-pass=legalizer %s -o - | FileCheck %s --check-prefixes=CHECK,X64
3 # RUN: llc -mtriple=i386-linux-gnu -mattr=+bmi -run-pass=legalizer %s -o - | FileCheck %s --check-prefixes=CHECK,X86
5 # test count trailing zeros for s16, s32, and s64
11 regBankSelected: false
13 - { id: 0, class: _, preferred-register: '' }
16 ; X64-LABEL: name: test_cttz35
17 ; X64: [[COPY:%[0-9]+]]:_(s64) = COPY $rdx
18 ; X64-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 34359738368
19 ; X64-NEXT: [[OR:%[0-9]+]]:_(s64) = G_OR [[COPY]], [[C]]
20 ; X64-NEXT: [[CTTZ_ZERO_UNDEF:%[0-9]+]]:_(s64) = G_CTTZ_ZERO_UNDEF [[OR]](s64)
21 ; X64-NEXT: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 34359738367
22 ; X64-NEXT: [[AND:%[0-9]+]]:_(s64) = G_AND [[CTTZ_ZERO_UNDEF]], [[C1]]
23 ; X64-NEXT: RET 0, implicit [[AND]](s64)
25 ; X86-LABEL: name: test_cttz35
26 ; X86: [[COPY:%[0-9]+]]:_(s64) = COPY $rdx
27 ; X86-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
28 ; X86-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 8
29 ; X86-NEXT: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[COPY]](s64)
30 ; X86-NEXT: [[OR:%[0-9]+]]:_(s32) = G_OR [[UV]], [[C]]
31 ; X86-NEXT: [[OR1:%[0-9]+]]:_(s32) = G_OR [[UV1]], [[C1]]
32 ; X86-NEXT: [[ICMP:%[0-9]+]]:_(s8) = G_ICMP intpred(eq), [[OR]](s32), [[C]]
33 ; X86-NEXT: [[CTTZ_ZERO_UNDEF:%[0-9]+]]:_(s32) = G_CTTZ_ZERO_UNDEF [[OR1]](s32)
34 ; X86-NEXT: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 32
35 ; X86-NEXT: [[UADDO:%[0-9]+]]:_(s32), [[UADDO1:%[0-9]+]]:_(s1) = G_UADDO [[CTTZ_ZERO_UNDEF]], [[C2]]
36 ; X86-NEXT: [[UADDE:%[0-9]+]]:_(s32), [[UADDE1:%[0-9]+]]:_(s1) = G_UADDE [[C]], [[C]], [[UADDO1]]
37 ; X86-NEXT: [[CTTZ_ZERO_UNDEF1:%[0-9]+]]:_(s32) = G_CTTZ_ZERO_UNDEF [[OR]](s32)
38 ; X86-NEXT: [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[ICMP]](s8)
39 ; X86-NEXT: [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
40 ; X86-NEXT: [[AND:%[0-9]+]]:_(s32) = G_AND [[ANYEXT]], [[C3]]
41 ; X86-NEXT: [[SELECT:%[0-9]+]]:_(s32) = G_SELECT [[AND]](s32), [[UADDO]], [[CTTZ_ZERO_UNDEF1]]
42 ; X86-NEXT: [[SELECT1:%[0-9]+]]:_(s32) = G_SELECT [[AND]](s32), [[UADDE]], [[C]]
43 ; X86-NEXT: [[C4:%[0-9]+]]:_(s32) = G_CONSTANT i32 -1
44 ; X86-NEXT: [[C5:%[0-9]+]]:_(s32) = G_CONSTANT i32 7
45 ; X86-NEXT: [[AND1:%[0-9]+]]:_(s32) = G_AND [[SELECT]], [[C4]]
46 ; X86-NEXT: [[AND2:%[0-9]+]]:_(s32) = G_AND [[SELECT1]], [[C5]]
47 ; X86-NEXT: [[MV:%[0-9]+]]:_(s64) = G_MERGE_VALUES [[AND1]](s32), [[AND2]](s32)
48 ; X86-NEXT: RET 0, implicit [[MV]](s64)
50 %1:_(s35) = G_TRUNC %0(s64)
59 regBankSelected: false
61 - { id: 0, class: _, preferred-register: '' }
62 - { id: 1, class: _, preferred-register: '' }
65 ; CHECK-LABEL: name: test_cttz8
66 ; CHECK: [[DEF:%[0-9]+]]:_(s8) = IMPLICIT_DEF
67 ; CHECK-NEXT: [[ANYEXT:%[0-9]+]]:_(s16) = G_ANYEXT [[DEF]](s8)
68 ; CHECK-NEXT: [[C:%[0-9]+]]:_(s16) = G_CONSTANT i16 256
69 ; CHECK-NEXT: [[OR:%[0-9]+]]:_(s16) = G_OR [[ANYEXT]], [[C]]
70 ; CHECK-NEXT: [[CTTZ_ZERO_UNDEF:%[0-9]+]]:_(s16) = G_CTTZ_ZERO_UNDEF [[OR]](s16)
71 ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s8) = G_TRUNC [[CTTZ_ZERO_UNDEF]](s16)
72 ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s8) = COPY [[TRUNC]](s8)
73 ; CHECK-NEXT: RET 0, implicit [[COPY]](s8)
74 %0:_(s8) = IMPLICIT_DEF
76 %2:_(s8) = COPY %1(s8)
83 regBankSelected: false
85 - { id: 0, class: _, preferred-register: '' }
86 - { id: 1, class: _, preferred-register: '' }
89 ; X64-LABEL: name: test_cttz64
90 ; X64: [[DEF:%[0-9]+]]:_(s64) = IMPLICIT_DEF
91 ; X64-NEXT: [[CTTZ:%[0-9]+]]:_(s64) = G_CTTZ [[DEF]](s64)
92 ; X64-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY [[CTTZ]](s64)
93 ; X64-NEXT: RET 0, implicit [[COPY]](s64)
95 ; X86-LABEL: name: test_cttz64
96 ; X86: [[DEF:%[0-9]+]]:_(s64) = IMPLICIT_DEF
97 ; X86-NEXT: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[DEF]](s64)
98 ; X86-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
99 ; X86-NEXT: [[ICMP:%[0-9]+]]:_(s8) = G_ICMP intpred(eq), [[UV]](s32), [[C]]
100 ; X86-NEXT: [[CTTZ:%[0-9]+]]:_(s32) = G_CTTZ [[UV1]](s32)
101 ; X86-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 32
102 ; X86-NEXT: [[UADDO:%[0-9]+]]:_(s32), [[UADDO1:%[0-9]+]]:_(s1) = G_UADDO [[CTTZ]], [[C1]]
103 ; X86-NEXT: [[UADDE:%[0-9]+]]:_(s32), [[UADDE1:%[0-9]+]]:_(s1) = G_UADDE [[C]], [[C]], [[UADDO1]]
104 ; X86-NEXT: [[CTTZ_ZERO_UNDEF:%[0-9]+]]:_(s32) = G_CTTZ_ZERO_UNDEF [[UV]](s32)
105 ; X86-NEXT: [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[ICMP]](s8)
106 ; X86-NEXT: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
107 ; X86-NEXT: [[AND:%[0-9]+]]:_(s32) = G_AND [[ANYEXT]], [[C2]]
108 ; X86-NEXT: [[SELECT:%[0-9]+]]:_(s32) = G_SELECT [[AND]](s32), [[UADDO]], [[CTTZ_ZERO_UNDEF]]
109 ; X86-NEXT: [[SELECT1:%[0-9]+]]:_(s32) = G_SELECT [[AND]](s32), [[UADDE]], [[C]]
110 ; X86-NEXT: [[MV:%[0-9]+]]:_(s64) = G_MERGE_VALUES [[SELECT]](s32), [[SELECT1]](s32)
111 ; X86-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY [[MV]](s64)
112 ; X86-NEXT: RET 0, implicit [[COPY]](s64)
113 %0:_(s64) = IMPLICIT_DEF
114 %1:_(s64) = G_CTTZ %0
115 %2:_(s64) = COPY %1(s64)
122 regBankSelected: false
124 - { id: 0, class: _, preferred-register: '' }
125 - { id: 1, class: _, preferred-register: '' }
128 ; CHECK-LABEL: name: test_cttz32
129 ; CHECK: [[DEF:%[0-9]+]]:_(s32) = IMPLICIT_DEF
130 ; CHECK-NEXT: [[CTTZ:%[0-9]+]]:_(s32) = G_CTTZ [[DEF]](s32)
131 ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY [[CTTZ]](s32)
132 ; CHECK-NEXT: RET 0, implicit [[COPY]](s32)
133 %0:_(s32) = IMPLICIT_DEF
134 %1:_(s32) = G_CTTZ %0
135 %2:_(s32) = COPY %1(s32)
142 regBankSelected: false
144 - { id: 0, class: _, preferred-register: '' }
145 - { id: 1, class: _, preferred-register: '' }
148 ; CHECK-LABEL: name: test_cttz16
149 ; CHECK: [[DEF:%[0-9]+]]:_(s16) = IMPLICIT_DEF
150 ; CHECK-NEXT: [[CTTZ:%[0-9]+]]:_(s16) = G_CTTZ [[DEF]](s16)
151 ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s16) = COPY [[CTTZ]](s16)
152 ; CHECK-NEXT: RET 0, implicit [[COPY]](s16)
153 %0:_(s16) = IMPLICIT_DEF
154 %1:_(s16) = G_CTTZ %0
155 %2:_(s16) = COPY %1(s16)