1# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2# RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=fiji -O0 -run-pass=legalizer %s -o - | FileCheck %s
3
4---
5name: ctlz_s32_s32
6
7body: |
8  bb.0:
9    liveins: $vgpr0
10    ; CHECK-LABEL: name: ctlz_s32_s32
11    ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $vgpr0
12    ; CHECK: [[CTLZ_ZERO_UNDEF:%[0-9]+]]:_(s32) = G_CTLZ_ZERO_UNDEF [[COPY]](s32)
13    ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
14    ; CHECK: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), [[COPY]](s32), [[C]]
15    ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 32
16    ; CHECK: [[SELECT:%[0-9]+]]:_(s32) = G_SELECT [[ICMP]](s1), [[C1]], [[CTLZ_ZERO_UNDEF]]
17    ; CHECK: $vgpr0 = COPY [[SELECT]](s32)
18    %0:_(s32) = COPY $vgpr0
19    %1:_(s32) = G_CTLZ %0
20    $vgpr0 = COPY %1
21...
22
23---
24name: ctlz_s32_s64
25
26body: |
27  bb.0:
28    liveins: $vgpr0_vgpr1
29    ; CHECK-LABEL: name: ctlz_s32_s64
30    ; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $vgpr0_vgpr1
31    ; CHECK: [[CTLZ_ZERO_UNDEF:%[0-9]+]]:_(s32) = G_CTLZ_ZERO_UNDEF [[COPY]](s64)
32    ; CHECK: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 0
33    ; CHECK: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), [[COPY]](s64), [[C]]
34    ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 64
35    ; CHECK: [[SELECT:%[0-9]+]]:_(s32) = G_SELECT [[ICMP]](s1), [[C1]], [[CTLZ_ZERO_UNDEF]]
36    ; CHECK: $vgpr0 = COPY [[SELECT]](s32)
37    %0:_(s64) = COPY $vgpr0_vgpr1
38    %1:_(s32) = G_CTLZ %0
39    $vgpr0 = COPY %1
40...
41
42---
43name: ctlz_s64_s64
44
45body: |
46  bb.0:
47    liveins: $vgpr0_vgpr1
48    ; CHECK-LABEL: name: ctlz_s64_s64
49    ; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $vgpr0_vgpr1
50    ; CHECK: [[CTLZ_ZERO_UNDEF:%[0-9]+]]:_(s32) = G_CTLZ_ZERO_UNDEF [[COPY]](s64)
51    ; CHECK: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 0
52    ; CHECK: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), [[COPY]](s64), [[C]]
53    ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 64
54    ; CHECK: [[SELECT:%[0-9]+]]:_(s32) = G_SELECT [[ICMP]](s1), [[C1]], [[CTLZ_ZERO_UNDEF]]
55    ; CHECK: [[ZEXT:%[0-9]+]]:_(s64) = G_ZEXT [[SELECT]](s32)
56    ; CHECK: $vgpr0_vgpr1 = COPY [[ZEXT]](s64)
57    %0:_(s64) = COPY $vgpr0_vgpr1
58    %1:_(s64) = G_CTLZ %0
59    $vgpr0_vgpr1 = COPY %1
60...
61
62---
63name: ctlz_s16_s32
64
65body: |
66  bb.0:
67    liveins: $vgpr0
68    ; CHECK-LABEL: name: ctlz_s16_s32
69    ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $vgpr0
70    ; CHECK: [[CTLZ_ZERO_UNDEF:%[0-9]+]]:_(s32) = G_CTLZ_ZERO_UNDEF [[COPY]](s32)
71    ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
72    ; CHECK: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), [[COPY]](s32), [[C]]
73    ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 32
74    ; CHECK: [[SELECT:%[0-9]+]]:_(s32) = G_SELECT [[ICMP]](s1), [[C1]], [[CTLZ_ZERO_UNDEF]]
75    ; CHECK: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 65535
76    ; CHECK: [[COPY1:%[0-9]+]]:_(s32) = COPY [[SELECT]](s32)
77    ; CHECK: [[AND:%[0-9]+]]:_(s32) = G_AND [[COPY1]], [[C2]]
78    ; CHECK: $vgpr0 = COPY [[AND]](s32)
79    %0:_(s32) = COPY $vgpr0
80    %1:_(s16) = G_CTLZ %0
81    %2:_(s32) = G_ZEXT %1
82    $vgpr0 = COPY %2
83...
84
85---
86name: ctlz_s16_s16
87
88body: |
89  bb.0:
90    liveins: $vgpr0
91    ; CHECK-LABEL: name: ctlz_s16_s16
92    ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $vgpr0
93    ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 65535
94    ; CHECK: [[COPY1:%[0-9]+]]:_(s32) = COPY [[COPY]](s32)
95    ; CHECK: [[AND:%[0-9]+]]:_(s32) = G_AND [[COPY1]], [[C]]
96    ; CHECK: [[CTLZ_ZERO_UNDEF:%[0-9]+]]:_(s32) = G_CTLZ_ZERO_UNDEF [[AND]](s32)
97    ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
98    ; CHECK: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), [[AND]](s32), [[C1]]
99    ; CHECK: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 32
100    ; CHECK: [[SELECT:%[0-9]+]]:_(s32) = G_SELECT [[ICMP]](s1), [[C2]], [[CTLZ_ZERO_UNDEF]]
101    ; CHECK: [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 16
102    ; CHECK: [[SUB:%[0-9]+]]:_(s32) = G_SUB [[SELECT]], [[C3]]
103    ; CHECK: [[COPY2:%[0-9]+]]:_(s32) = COPY [[SUB]](s32)
104    ; CHECK: [[COPY3:%[0-9]+]]:_(s32) = COPY [[COPY2]](s32)
105    ; CHECK: [[AND1:%[0-9]+]]:_(s32) = G_AND [[COPY3]], [[C]]
106    ; CHECK: $vgpr0 = COPY [[AND1]](s32)
107    %0:_(s32) = COPY $vgpr0
108    %1:_(s16) = G_TRUNC %0
109    %2:_(s16) = G_CTLZ %1
110    %3:_(s32) = G_ZEXT %2
111    $vgpr0 = COPY %3
112...
113
114---
115name: ctlz_v2s32_v2s32
116
117body: |
118  bb.0:
119    liveins: $vgpr0_vgpr1
120    ; CHECK-LABEL: name: ctlz_v2s32_v2s32
121    ; CHECK: [[COPY:%[0-9]+]]:_(<2 x s32>) = COPY $vgpr0_vgpr1
122    ; CHECK: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[COPY]](<2 x s32>)
123    ; CHECK: [[CTLZ_ZERO_UNDEF:%[0-9]+]]:_(s32) = G_CTLZ_ZERO_UNDEF [[UV]](s32)
124    ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
125    ; CHECK: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), [[UV]](s32), [[C]]
126    ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 32
127    ; CHECK: [[SELECT:%[0-9]+]]:_(s32) = G_SELECT [[ICMP]](s1), [[C1]], [[CTLZ_ZERO_UNDEF]]
128    ; CHECK: [[CTLZ_ZERO_UNDEF1:%[0-9]+]]:_(s32) = G_CTLZ_ZERO_UNDEF [[UV1]](s32)
129    ; CHECK: [[ICMP1:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), [[UV1]](s32), [[C]]
130    ; CHECK: [[SELECT1:%[0-9]+]]:_(s32) = G_SELECT [[ICMP1]](s1), [[C1]], [[CTLZ_ZERO_UNDEF1]]
131    ; CHECK: [[BUILD_VECTOR:%[0-9]+]]:_(<2 x s32>) = G_BUILD_VECTOR [[SELECT]](s32), [[SELECT1]](s32)
132    ; CHECK: $vgpr0_vgpr1 = COPY [[BUILD_VECTOR]](<2 x s32>)
133    %0:_(<2 x s32>) = COPY $vgpr0_vgpr1
134    %1:_(<2 x s32>) = G_CTLZ %0
135    $vgpr0_vgpr1 = COPY %1
136...
137
138---
139name: ctlz_v2s32_v2s64
140
141body: |
142  bb.0:
143    liveins: $vgpr0_vgpr1_vgpr2_vgpr3
144    ; CHECK-LABEL: name: ctlz_v2s32_v2s64
145    ; CHECK: [[COPY:%[0-9]+]]:_(<2 x s64>) = COPY $vgpr0_vgpr1_vgpr2_vgpr3
146    ; CHECK: [[UV:%[0-9]+]]:_(s64), [[UV1:%[0-9]+]]:_(s64) = G_UNMERGE_VALUES [[COPY]](<2 x s64>)
147    ; CHECK: [[CTLZ_ZERO_UNDEF:%[0-9]+]]:_(s32) = G_CTLZ_ZERO_UNDEF [[UV]](s64)
148    ; CHECK: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 0
149    ; CHECK: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), [[UV]](s64), [[C]]
150    ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 64
151    ; CHECK: [[SELECT:%[0-9]+]]:_(s32) = G_SELECT [[ICMP]](s1), [[C1]], [[CTLZ_ZERO_UNDEF]]
152    ; CHECK: [[CTLZ_ZERO_UNDEF1:%[0-9]+]]:_(s32) = G_CTLZ_ZERO_UNDEF [[UV1]](s64)
153    ; CHECK: [[ICMP1:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), [[UV1]](s64), [[C]]
154    ; CHECK: [[SELECT1:%[0-9]+]]:_(s32) = G_SELECT [[ICMP1]](s1), [[C1]], [[CTLZ_ZERO_UNDEF1]]
155    ; CHECK: [[BUILD_VECTOR:%[0-9]+]]:_(<2 x s32>) = G_BUILD_VECTOR [[SELECT]](s32), [[SELECT1]](s32)
156    ; CHECK: $vgpr0_vgpr1 = COPY [[BUILD_VECTOR]](<2 x s32>)
157    %0:_(<2 x s64>) = COPY $vgpr0_vgpr1_vgpr2_vgpr3
158    %1:_(<2 x s32>) = G_CTLZ %0
159    $vgpr0_vgpr1 = COPY %1
160...
161
162---
163name: ctlz_v2s16_v2s16
164
165body: |
166  bb.0:
167    liveins: $vgpr0
168    ; CHECK-LABEL: name: ctlz_v2s16_v2s16
169    ; CHECK: [[COPY:%[0-9]+]]:_(<2 x s16>) = COPY $vgpr0
170    ; CHECK: [[BITCAST:%[0-9]+]]:_(s32) = G_BITCAST [[COPY]](<2 x s16>)
171    ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 16
172    ; CHECK: [[LSHR:%[0-9]+]]:_(s32) = G_LSHR [[BITCAST]], [[C]](s32)
173    ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 65535
174    ; CHECK: [[COPY1:%[0-9]+]]:_(s32) = COPY [[BITCAST]](s32)
175    ; CHECK: [[AND:%[0-9]+]]:_(s32) = G_AND [[COPY1]], [[C1]]
176    ; CHECK: [[CTLZ_ZERO_UNDEF:%[0-9]+]]:_(s32) = G_CTLZ_ZERO_UNDEF [[AND]](s32)
177    ; CHECK: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
178    ; CHECK: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), [[AND]](s32), [[C2]]
179    ; CHECK: [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 32
180    ; CHECK: [[SELECT:%[0-9]+]]:_(s32) = G_SELECT [[ICMP]](s1), [[C3]], [[CTLZ_ZERO_UNDEF]]
181    ; CHECK: [[SUB:%[0-9]+]]:_(s32) = G_SUB [[SELECT]], [[C]]
182    ; CHECK: [[COPY2:%[0-9]+]]:_(s32) = COPY [[SUB]](s32)
183    ; CHECK: [[COPY3:%[0-9]+]]:_(s32) = COPY [[LSHR]](s32)
184    ; CHECK: [[AND1:%[0-9]+]]:_(s32) = G_AND [[COPY3]], [[C1]]
185    ; CHECK: [[CTLZ_ZERO_UNDEF1:%[0-9]+]]:_(s32) = G_CTLZ_ZERO_UNDEF [[AND1]](s32)
186    ; CHECK: [[ICMP1:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), [[AND1]](s32), [[C2]]
187    ; CHECK: [[SELECT1:%[0-9]+]]:_(s32) = G_SELECT [[ICMP1]](s1), [[C3]], [[CTLZ_ZERO_UNDEF1]]
188    ; CHECK: [[SUB1:%[0-9]+]]:_(s32) = G_SUB [[SELECT1]], [[C]]
189    ; CHECK: [[COPY4:%[0-9]+]]:_(s32) = COPY [[SUB1]](s32)
190    ; CHECK: [[COPY5:%[0-9]+]]:_(s32) = COPY [[COPY2]](s32)
191    ; CHECK: [[AND2:%[0-9]+]]:_(s32) = G_AND [[COPY5]], [[C1]]
192    ; CHECK: [[COPY6:%[0-9]+]]:_(s32) = COPY [[COPY4]](s32)
193    ; CHECK: [[AND3:%[0-9]+]]:_(s32) = G_AND [[COPY6]], [[C1]]
194    ; CHECK: [[SHL:%[0-9]+]]:_(s32) = G_SHL [[AND3]], [[C]](s32)
195    ; CHECK: [[OR:%[0-9]+]]:_(s32) = G_OR [[AND2]], [[SHL]]
196    ; CHECK: [[BITCAST1:%[0-9]+]]:_(<2 x s16>) = G_BITCAST [[OR]](s32)
197    ; CHECK: $vgpr0 = COPY [[BITCAST1]](<2 x s16>)
198    %0:_(<2 x s16>) = COPY $vgpr0
199    %1:_(<2 x s16>) = G_CTLZ %0
200    $vgpr0 = COPY %1
201...
202
203---
204name: ctlz_s7_s7
205
206body: |
207  bb.0:
208    liveins: $vgpr0
209
210    ; CHECK-LABEL: name: ctlz_s7_s7
211    ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $vgpr0
212    ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 127
213    ; CHECK: [[COPY1:%[0-9]+]]:_(s32) = COPY [[COPY]](s32)
214    ; CHECK: [[AND:%[0-9]+]]:_(s32) = G_AND [[COPY1]], [[C]]
215    ; CHECK: [[CTLZ_ZERO_UNDEF:%[0-9]+]]:_(s32) = G_CTLZ_ZERO_UNDEF [[AND]](s32)
216    ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
217    ; CHECK: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), [[AND]](s32), [[C1]]
218    ; CHECK: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 32
219    ; CHECK: [[SELECT:%[0-9]+]]:_(s32) = G_SELECT [[ICMP]](s1), [[C2]], [[CTLZ_ZERO_UNDEF]]
220    ; CHECK: [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 25
221    ; CHECK: [[SUB:%[0-9]+]]:_(s32) = G_SUB [[SELECT]], [[C3]]
222    ; CHECK: [[COPY2:%[0-9]+]]:_(s32) = COPY [[SUB]](s32)
223    ; CHECK: [[COPY3:%[0-9]+]]:_(s32) = COPY [[COPY2]](s32)
224    ; CHECK: [[AND1:%[0-9]+]]:_(s32) = G_AND [[COPY3]], [[C]]
225    ; CHECK: $vgpr0 = COPY [[AND1]](s32)
226    %0:_(s32) = COPY $vgpr0
227    %1:_(s7) = G_TRUNC %0
228    %2:_(s7) = G_CTLZ %1
229    %3:_(s32) = G_ZEXT %2
230    $vgpr0 = COPY %3
231...
232
233---
234name: ctlz_s33_s33
235
236body: |
237  bb.0:
238    liveins: $vgpr0_vgpr1
239
240    ; CHECK-LABEL: name: ctlz_s33_s33
241    ; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $vgpr0_vgpr1
242    ; CHECK: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 8589934591
243    ; CHECK: [[COPY1:%[0-9]+]]:_(s64) = COPY [[COPY]](s64)
244    ; CHECK: [[AND:%[0-9]+]]:_(s64) = G_AND [[COPY1]], [[C]]
245    ; CHECK: [[CTLZ_ZERO_UNDEF:%[0-9]+]]:_(s32) = G_CTLZ_ZERO_UNDEF [[AND]](s64)
246    ; CHECK: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 0
247    ; CHECK: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), [[AND]](s64), [[C1]]
248    ; CHECK: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 64
249    ; CHECK: [[SELECT:%[0-9]+]]:_(s32) = G_SELECT [[ICMP]](s1), [[C2]], [[CTLZ_ZERO_UNDEF]]
250    ; CHECK: [[ZEXT:%[0-9]+]]:_(s64) = G_ZEXT [[SELECT]](s32)
251    ; CHECK: [[C3:%[0-9]+]]:_(s64) = G_CONSTANT i64 31
252    ; CHECK: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[ZEXT]](s64)
253    ; CHECK: [[UV2:%[0-9]+]]:_(s32), [[UV3:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[C3]](s64)
254    ; CHECK: [[USUBO:%[0-9]+]]:_(s32), [[USUBO1:%[0-9]+]]:_(s1) = G_USUBO [[UV]], [[UV2]]
255    ; CHECK: [[USUBE:%[0-9]+]]:_(s32), [[USUBE1:%[0-9]+]]:_(s1) = G_USUBE [[UV1]], [[UV3]], [[USUBO1]]
256    ; CHECK: [[ZEXT1:%[0-9]+]]:_(s64) = G_ZEXT [[USUBO]](s32)
257    ; CHECK: $vgpr0_vgpr1 = COPY [[ZEXT1]](s64)
258    %0:_(s64) = COPY $vgpr0_vgpr1
259    %1:_(s33) = G_TRUNC %0
260    %2:_(s33) = G_CTLZ %1
261    %3:_(s64) = G_ANYEXT %2
262    $vgpr0_vgpr1 = COPY %3
263...
264
265# ---
266# name: ctlz_v2s7_v2s7
267
268# body: |
269#   bb.0:
270#     liveins: $vgpr0
271#     %0:_(<2 x s32>) = COPY $vgpr0_vgpr1
272#     %1:_(<2 x s7>) = G_TRUNC %0
273#     %2:_(<2 x s7>) = G_CTLZ %1
274#     %3:_(<2 x s32>) = G_ANYEXT %2
275#     $vgpr0_vgpr1 = COPY %3
276# ...
277