1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=amdgcn -mcpu=gfx600 -amdgpu-bypass-slow-div=0 -verify-machineinstrs < %s | FileCheck -check-prefix=GCN %s
3 ; RUN: llc -mtriple=amdgcn -mcpu=gfx600 -amdgpu-bypass-slow-div=0 -amdgpu-codegenprepare-expand-div64 -verify-machineinstrs < %s | FileCheck -check-prefix=GCN-IR %s
5 define amdgpu_kernel void @s_test_sdiv(ptr addrspace(1) %out, i64 %x, i64 %y) {
6 ; GCN-LABEL: s_test_sdiv:
8 ; GCN-NEXT: s_load_dwordx2 s[0:1], s[4:5], 0xd
9 ; GCN-NEXT: s_mov_b32 s7, 0xf000
10 ; GCN-NEXT: s_mov_b32 s6, -1
11 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
12 ; GCN-NEXT: s_ashr_i32 s8, s1, 31
13 ; GCN-NEXT: s_add_u32 s0, s0, s8
14 ; GCN-NEXT: s_mov_b32 s9, s8
15 ; GCN-NEXT: s_addc_u32 s1, s1, s8
16 ; GCN-NEXT: s_xor_b64 s[10:11], s[0:1], s[8:9]
17 ; GCN-NEXT: v_cvt_f32_u32_e32 v0, s10
18 ; GCN-NEXT: v_cvt_f32_u32_e32 v1, s11
19 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0x9
20 ; GCN-NEXT: s_sub_u32 s4, 0, s10
21 ; GCN-NEXT: s_subb_u32 s5, 0, s11
22 ; GCN-NEXT: v_madmk_f32 v0, v1, 0x4f800000, v0
23 ; GCN-NEXT: v_rcp_f32_e32 v0, v0
24 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
25 ; GCN-NEXT: s_ashr_i32 s12, s3, 31
26 ; GCN-NEXT: s_add_u32 s2, s2, s12
27 ; GCN-NEXT: s_mov_b32 s13, s12
28 ; GCN-NEXT: v_mul_f32_e32 v0, 0x5f7ffffc, v0
29 ; GCN-NEXT: v_mul_f32_e32 v1, 0x2f800000, v0
30 ; GCN-NEXT: v_trunc_f32_e32 v1, v1
31 ; GCN-NEXT: v_madmk_f32 v0, v1, 0xcf800000, v0
32 ; GCN-NEXT: v_cvt_u32_f32_e32 v1, v1
33 ; GCN-NEXT: v_cvt_u32_f32_e32 v0, v0
34 ; GCN-NEXT: s_addc_u32 s3, s3, s12
35 ; GCN-NEXT: s_xor_b64 s[2:3], s[2:3], s[12:13]
36 ; GCN-NEXT: v_mul_lo_u32 v2, s4, v1
37 ; GCN-NEXT: v_mul_hi_u32 v3, s4, v0
38 ; GCN-NEXT: v_mul_lo_u32 v5, s5, v0
39 ; GCN-NEXT: v_mul_lo_u32 v4, s4, v0
40 ; GCN-NEXT: v_add_i32_e32 v2, vcc, v2, v3
41 ; GCN-NEXT: v_add_i32_e32 v2, vcc, v2, v5
42 ; GCN-NEXT: v_mul_hi_u32 v3, v0, v4
43 ; GCN-NEXT: v_mul_lo_u32 v5, v0, v2
44 ; GCN-NEXT: v_mul_hi_u32 v7, v0, v2
45 ; GCN-NEXT: v_mul_lo_u32 v6, v1, v4
46 ; GCN-NEXT: v_mul_hi_u32 v4, v1, v4
47 ; GCN-NEXT: v_mul_hi_u32 v8, v1, v2
48 ; GCN-NEXT: v_add_i32_e32 v3, vcc, v3, v5
49 ; GCN-NEXT: v_addc_u32_e32 v5, vcc, 0, v7, vcc
50 ; GCN-NEXT: v_mul_lo_u32 v2, v1, v2
51 ; GCN-NEXT: v_add_i32_e32 v3, vcc, v3, v6
52 ; GCN-NEXT: v_addc_u32_e32 v3, vcc, v5, v4, vcc
53 ; GCN-NEXT: v_addc_u32_e32 v4, vcc, 0, v8, vcc
54 ; GCN-NEXT: v_add_i32_e32 v2, vcc, v3, v2
55 ; GCN-NEXT: v_addc_u32_e32 v3, vcc, 0, v4, vcc
56 ; GCN-NEXT: v_add_i32_e32 v0, vcc, v0, v2
57 ; GCN-NEXT: v_addc_u32_e32 v1, vcc, v1, v3, vcc
58 ; GCN-NEXT: v_mul_lo_u32 v2, s4, v1
59 ; GCN-NEXT: v_mul_hi_u32 v3, s4, v0
60 ; GCN-NEXT: v_mul_lo_u32 v4, s5, v0
61 ; GCN-NEXT: s_mov_b32 s5, s1
62 ; GCN-NEXT: v_add_i32_e32 v2, vcc, v2, v3
63 ; GCN-NEXT: v_mul_lo_u32 v3, s4, v0
64 ; GCN-NEXT: v_add_i32_e32 v2, vcc, v2, v4
65 ; GCN-NEXT: v_mul_lo_u32 v6, v0, v2
66 ; GCN-NEXT: v_mul_hi_u32 v7, v0, v3
67 ; GCN-NEXT: v_mul_hi_u32 v8, v0, v2
68 ; GCN-NEXT: v_mul_hi_u32 v5, v1, v3
69 ; GCN-NEXT: v_mul_lo_u32 v3, v1, v3
70 ; GCN-NEXT: v_mul_hi_u32 v4, v1, v2
71 ; GCN-NEXT: v_add_i32_e32 v6, vcc, v7, v6
72 ; GCN-NEXT: v_addc_u32_e32 v7, vcc, 0, v8, vcc
73 ; GCN-NEXT: v_mul_lo_u32 v2, v1, v2
74 ; GCN-NEXT: v_add_i32_e32 v3, vcc, v6, v3
75 ; GCN-NEXT: v_addc_u32_e32 v3, vcc, v7, v5, vcc
76 ; GCN-NEXT: v_addc_u32_e32 v4, vcc, 0, v4, vcc
77 ; GCN-NEXT: v_add_i32_e32 v2, vcc, v3, v2
78 ; GCN-NEXT: v_addc_u32_e32 v3, vcc, 0, v4, vcc
79 ; GCN-NEXT: v_add_i32_e32 v0, vcc, v0, v2
80 ; GCN-NEXT: v_addc_u32_e32 v1, vcc, v1, v3, vcc
81 ; GCN-NEXT: v_mul_lo_u32 v2, s2, v1
82 ; GCN-NEXT: v_mul_hi_u32 v3, s2, v0
83 ; GCN-NEXT: v_mul_hi_u32 v4, s2, v1
84 ; GCN-NEXT: v_mul_hi_u32 v5, s3, v1
85 ; GCN-NEXT: v_mul_lo_u32 v1, s3, v1
86 ; GCN-NEXT: v_add_i32_e32 v2, vcc, v3, v2
87 ; GCN-NEXT: v_addc_u32_e32 v3, vcc, 0, v4, vcc
88 ; GCN-NEXT: v_mul_lo_u32 v4, s3, v0
89 ; GCN-NEXT: v_mul_hi_u32 v0, s3, v0
90 ; GCN-NEXT: s_mov_b32 s4, s0
91 ; GCN-NEXT: v_add_i32_e32 v2, vcc, v2, v4
92 ; GCN-NEXT: v_addc_u32_e32 v0, vcc, v3, v0, vcc
93 ; GCN-NEXT: v_addc_u32_e32 v2, vcc, 0, v5, vcc
94 ; GCN-NEXT: v_add_i32_e32 v0, vcc, v0, v1
95 ; GCN-NEXT: v_addc_u32_e32 v1, vcc, 0, v2, vcc
96 ; GCN-NEXT: v_mul_lo_u32 v2, s10, v1
97 ; GCN-NEXT: v_mul_hi_u32 v3, s10, v0
98 ; GCN-NEXT: v_mul_lo_u32 v4, s11, v0
99 ; GCN-NEXT: v_mov_b32_e32 v5, s11
100 ; GCN-NEXT: v_add_i32_e32 v2, vcc, v2, v3
101 ; GCN-NEXT: v_mul_lo_u32 v3, s10, v0
102 ; GCN-NEXT: v_add_i32_e32 v2, vcc, v4, v2
103 ; GCN-NEXT: v_sub_i32_e32 v4, vcc, s3, v2
104 ; GCN-NEXT: v_sub_i32_e32 v3, vcc, s2, v3
105 ; GCN-NEXT: v_subb_u32_e64 v4, s[0:1], v4, v5, vcc
106 ; GCN-NEXT: v_subrev_i32_e64 v5, s[0:1], s10, v3
107 ; GCN-NEXT: v_subbrev_u32_e64 v4, s[0:1], 0, v4, s[0:1]
108 ; GCN-NEXT: v_cmp_le_u32_e64 s[0:1], s11, v4
109 ; GCN-NEXT: v_cndmask_b32_e64 v6, 0, -1, s[0:1]
110 ; GCN-NEXT: v_cmp_le_u32_e64 s[0:1], s10, v5
111 ; GCN-NEXT: v_cndmask_b32_e64 v5, 0, -1, s[0:1]
112 ; GCN-NEXT: v_cmp_eq_u32_e64 s[0:1], s11, v4
113 ; GCN-NEXT: v_cndmask_b32_e64 v4, v6, v5, s[0:1]
114 ; GCN-NEXT: v_add_i32_e64 v5, s[0:1], 1, v0
115 ; GCN-NEXT: v_addc_u32_e64 v6, s[0:1], 0, v1, s[0:1]
116 ; GCN-NEXT: v_add_i32_e64 v7, s[0:1], 2, v0
117 ; GCN-NEXT: v_addc_u32_e64 v8, s[0:1], 0, v1, s[0:1]
118 ; GCN-NEXT: v_cmp_ne_u32_e64 s[0:1], 0, v4
119 ; GCN-NEXT: v_cndmask_b32_e64 v4, v5, v7, s[0:1]
120 ; GCN-NEXT: v_cndmask_b32_e64 v5, v6, v8, s[0:1]
121 ; GCN-NEXT: v_mov_b32_e32 v6, s3
122 ; GCN-NEXT: v_subb_u32_e32 v2, vcc, v6, v2, vcc
123 ; GCN-NEXT: v_cmp_le_u32_e32 vcc, s11, v2
124 ; GCN-NEXT: v_cndmask_b32_e64 v6, 0, -1, vcc
125 ; GCN-NEXT: v_cmp_le_u32_e32 vcc, s10, v3
126 ; GCN-NEXT: v_cndmask_b32_e64 v3, 0, -1, vcc
127 ; GCN-NEXT: v_cmp_eq_u32_e32 vcc, s11, v2
128 ; GCN-NEXT: v_cndmask_b32_e32 v2, v6, v3, vcc
129 ; GCN-NEXT: v_cmp_ne_u32_e32 vcc, 0, v2
130 ; GCN-NEXT: v_cndmask_b32_e32 v0, v0, v4, vcc
131 ; GCN-NEXT: s_xor_b64 s[0:1], s[12:13], s[8:9]
132 ; GCN-NEXT: v_cndmask_b32_e32 v1, v1, v5, vcc
133 ; GCN-NEXT: v_xor_b32_e32 v0, s0, v0
134 ; GCN-NEXT: v_xor_b32_e32 v1, s1, v1
135 ; GCN-NEXT: v_mov_b32_e32 v2, s1
136 ; GCN-NEXT: v_subrev_i32_e32 v0, vcc, s0, v0
137 ; GCN-NEXT: v_subb_u32_e32 v1, vcc, v1, v2, vcc
138 ; GCN-NEXT: buffer_store_dwordx2 v[0:1], off, s[4:7], 0
141 ; GCN-IR-LABEL: s_test_sdiv:
142 ; GCN-IR: ; %bb.0: ; %_udiv-special-cases
143 ; GCN-IR-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0x9
144 ; GCN-IR-NEXT: s_load_dwordx2 s[8:9], s[4:5], 0xd
145 ; GCN-IR-NEXT: s_mov_b32 s15, 0
146 ; GCN-IR-NEXT: s_waitcnt lgkmcnt(0)
147 ; GCN-IR-NEXT: s_ashr_i32 s4, s3, 31
148 ; GCN-IR-NEXT: s_mov_b32 s5, s4
149 ; GCN-IR-NEXT: s_ashr_i32 s6, s9, 31
150 ; GCN-IR-NEXT: s_xor_b64 s[2:3], s[2:3], s[4:5]
151 ; GCN-IR-NEXT: s_mov_b32 s7, s6
152 ; GCN-IR-NEXT: s_sub_u32 s12, s2, s4
153 ; GCN-IR-NEXT: s_subb_u32 s13, s3, s4
154 ; GCN-IR-NEXT: s_xor_b64 s[2:3], s[8:9], s[6:7]
155 ; GCN-IR-NEXT: s_sub_u32 s2, s2, s6
156 ; GCN-IR-NEXT: s_subb_u32 s3, s3, s6
157 ; GCN-IR-NEXT: v_cmp_eq_u64_e64 s[8:9], s[12:13], 0
158 ; GCN-IR-NEXT: v_cmp_eq_u64_e64 s[10:11], s[2:3], 0
159 ; GCN-IR-NEXT: s_flbit_i32_b64 s14, s[2:3]
160 ; GCN-IR-NEXT: s_or_b64 s[10:11], s[10:11], s[8:9]
161 ; GCN-IR-NEXT: s_flbit_i32_b64 s20, s[12:13]
162 ; GCN-IR-NEXT: s_sub_u32 s16, s14, s20
163 ; GCN-IR-NEXT: s_subb_u32 s17, 0, 0
164 ; GCN-IR-NEXT: v_cmp_gt_u64_e64 s[18:19], s[16:17], 63
165 ; GCN-IR-NEXT: v_cmp_eq_u64_e64 s[22:23], s[16:17], 63
166 ; GCN-IR-NEXT: s_or_b64 s[18:19], s[10:11], s[18:19]
167 ; GCN-IR-NEXT: s_and_b64 s[10:11], s[18:19], exec
168 ; GCN-IR-NEXT: s_cselect_b32 s11, 0, s13
169 ; GCN-IR-NEXT: s_cselect_b32 s10, 0, s12
170 ; GCN-IR-NEXT: s_or_b64 s[18:19], s[18:19], s[22:23]
171 ; GCN-IR-NEXT: s_mov_b64 s[8:9], 0
172 ; GCN-IR-NEXT: s_andn2_b64 vcc, exec, s[18:19]
173 ; GCN-IR-NEXT: s_cbranch_vccz .LBB0_5
174 ; GCN-IR-NEXT: ; %bb.1: ; %udiv-bb1
175 ; GCN-IR-NEXT: s_add_u32 s18, s16, 1
176 ; GCN-IR-NEXT: s_addc_u32 s19, s17, 0
177 ; GCN-IR-NEXT: v_cmp_eq_u64_e64 s[10:11], s[18:19], 0
178 ; GCN-IR-NEXT: s_sub_i32 s16, 63, s16
179 ; GCN-IR-NEXT: s_andn2_b64 vcc, exec, s[10:11]
180 ; GCN-IR-NEXT: s_lshl_b64 s[10:11], s[12:13], s16
181 ; GCN-IR-NEXT: s_cbranch_vccz .LBB0_4
182 ; GCN-IR-NEXT: ; %bb.2: ; %udiv-preheader
183 ; GCN-IR-NEXT: s_lshr_b64 s[16:17], s[12:13], s18
184 ; GCN-IR-NEXT: s_add_u32 s18, s2, -1
185 ; GCN-IR-NEXT: s_addc_u32 s19, s3, -1
186 ; GCN-IR-NEXT: s_not_b64 s[8:9], s[14:15]
187 ; GCN-IR-NEXT: s_add_u32 s12, s8, s20
188 ; GCN-IR-NEXT: s_addc_u32 s13, s9, 0
189 ; GCN-IR-NEXT: s_mov_b64 s[14:15], 0
190 ; GCN-IR-NEXT: s_mov_b32 s9, 0
191 ; GCN-IR-NEXT: .LBB0_3: ; %udiv-do-while
192 ; GCN-IR-NEXT: ; =>This Inner Loop Header: Depth=1
193 ; GCN-IR-NEXT: s_lshl_b64 s[16:17], s[16:17], 1
194 ; GCN-IR-NEXT: s_lshr_b32 s8, s11, 31
195 ; GCN-IR-NEXT: s_lshl_b64 s[10:11], s[10:11], 1
196 ; GCN-IR-NEXT: s_or_b64 s[16:17], s[16:17], s[8:9]
197 ; GCN-IR-NEXT: s_or_b64 s[10:11], s[14:15], s[10:11]
198 ; GCN-IR-NEXT: s_sub_u32 s8, s18, s16
199 ; GCN-IR-NEXT: s_subb_u32 s8, s19, s17
200 ; GCN-IR-NEXT: s_ashr_i32 s14, s8, 31
201 ; GCN-IR-NEXT: s_mov_b32 s15, s14
202 ; GCN-IR-NEXT: s_and_b32 s8, s14, 1
203 ; GCN-IR-NEXT: s_and_b64 s[14:15], s[14:15], s[2:3]
204 ; GCN-IR-NEXT: s_sub_u32 s16, s16, s14
205 ; GCN-IR-NEXT: s_subb_u32 s17, s17, s15
206 ; GCN-IR-NEXT: s_add_u32 s12, s12, 1
207 ; GCN-IR-NEXT: s_addc_u32 s13, s13, 0
208 ; GCN-IR-NEXT: v_cmp_eq_u64_e64 s[20:21], s[12:13], 0
209 ; GCN-IR-NEXT: s_mov_b64 s[14:15], s[8:9]
210 ; GCN-IR-NEXT: s_and_b64 vcc, exec, s[20:21]
211 ; GCN-IR-NEXT: s_cbranch_vccz .LBB0_3
212 ; GCN-IR-NEXT: .LBB0_4: ; %Flow7
213 ; GCN-IR-NEXT: s_lshl_b64 s[2:3], s[10:11], 1
214 ; GCN-IR-NEXT: s_or_b64 s[10:11], s[8:9], s[2:3]
215 ; GCN-IR-NEXT: .LBB0_5: ; %udiv-end
216 ; GCN-IR-NEXT: s_xor_b64 s[4:5], s[6:7], s[4:5]
217 ; GCN-IR-NEXT: s_xor_b64 s[6:7], s[10:11], s[4:5]
218 ; GCN-IR-NEXT: s_sub_u32 s4, s6, s4
219 ; GCN-IR-NEXT: s_subb_u32 s5, s7, s5
220 ; GCN-IR-NEXT: v_mov_b32_e32 v0, s4
221 ; GCN-IR-NEXT: s_mov_b32 s3, 0xf000
222 ; GCN-IR-NEXT: s_mov_b32 s2, -1
223 ; GCN-IR-NEXT: v_mov_b32_e32 v1, s5
224 ; GCN-IR-NEXT: buffer_store_dwordx2 v[0:1], off, s[0:3], 0
225 ; GCN-IR-NEXT: s_endpgm
226 %result = sdiv i64 %x, %y
227 store i64 %result, ptr addrspace(1) %out
231 define i64 @v_test_sdiv(i64 %x, i64 %y) {
232 ; GCN-LABEL: v_test_sdiv:
234 ; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
235 ; GCN-NEXT: v_ashrrev_i32_e32 v4, 31, v3
236 ; GCN-NEXT: v_add_i32_e32 v5, vcc, v2, v4
237 ; GCN-NEXT: v_addc_u32_e32 v2, vcc, v3, v4, vcc
238 ; GCN-NEXT: v_xor_b32_e32 v2, v2, v4
239 ; GCN-NEXT: v_xor_b32_e32 v3, v5, v4
240 ; GCN-NEXT: v_cvt_f32_u32_e32 v5, v3
241 ; GCN-NEXT: v_cvt_f32_u32_e32 v6, v2
242 ; GCN-NEXT: v_sub_i32_e32 v7, vcc, 0, v3
243 ; GCN-NEXT: v_subb_u32_e32 v8, vcc, 0, v2, vcc
244 ; GCN-NEXT: v_madmk_f32 v5, v6, 0x4f800000, v5
245 ; GCN-NEXT: v_rcp_f32_e32 v5, v5
246 ; GCN-NEXT: v_mul_f32_e32 v5, 0x5f7ffffc, v5
247 ; GCN-NEXT: v_mul_f32_e32 v6, 0x2f800000, v5
248 ; GCN-NEXT: v_trunc_f32_e32 v6, v6
249 ; GCN-NEXT: v_madmk_f32 v5, v6, 0xcf800000, v5
250 ; GCN-NEXT: v_cvt_u32_f32_e32 v5, v5
251 ; GCN-NEXT: v_cvt_u32_f32_e32 v6, v6
252 ; GCN-NEXT: v_mul_hi_u32 v9, v7, v5
253 ; GCN-NEXT: v_mul_lo_u32 v10, v7, v6
254 ; GCN-NEXT: v_mul_lo_u32 v11, v8, v5
255 ; GCN-NEXT: v_add_i32_e32 v9, vcc, v9, v10
256 ; GCN-NEXT: v_mul_lo_u32 v10, v7, v5
257 ; GCN-NEXT: v_add_i32_e32 v9, vcc, v9, v11
258 ; GCN-NEXT: v_mul_lo_u32 v11, v5, v9
259 ; GCN-NEXT: v_mul_hi_u32 v12, v5, v10
260 ; GCN-NEXT: v_mul_hi_u32 v13, v5, v9
261 ; GCN-NEXT: v_mul_hi_u32 v14, v6, v9
262 ; GCN-NEXT: v_mul_lo_u32 v9, v6, v9
263 ; GCN-NEXT: v_add_i32_e32 v11, vcc, v12, v11
264 ; GCN-NEXT: v_addc_u32_e32 v12, vcc, 0, v13, vcc
265 ; GCN-NEXT: v_mul_lo_u32 v13, v6, v10
266 ; GCN-NEXT: v_mul_hi_u32 v10, v6, v10
267 ; GCN-NEXT: v_add_i32_e32 v11, vcc, v11, v13
268 ; GCN-NEXT: v_addc_u32_e32 v10, vcc, v12, v10, vcc
269 ; GCN-NEXT: v_addc_u32_e32 v11, vcc, 0, v14, vcc
270 ; GCN-NEXT: v_add_i32_e32 v9, vcc, v10, v9
271 ; GCN-NEXT: v_addc_u32_e32 v10, vcc, 0, v11, vcc
272 ; GCN-NEXT: v_add_i32_e32 v5, vcc, v5, v9
273 ; GCN-NEXT: v_addc_u32_e32 v6, vcc, v6, v10, vcc
274 ; GCN-NEXT: v_mul_lo_u32 v9, v7, v6
275 ; GCN-NEXT: v_mul_hi_u32 v10, v7, v5
276 ; GCN-NEXT: v_mul_lo_u32 v8, v8, v5
277 ; GCN-NEXT: v_mul_lo_u32 v7, v7, v5
278 ; GCN-NEXT: v_add_i32_e32 v9, vcc, v10, v9
279 ; GCN-NEXT: v_add_i32_e32 v8, vcc, v9, v8
280 ; GCN-NEXT: v_mul_lo_u32 v11, v5, v8
281 ; GCN-NEXT: v_mul_hi_u32 v12, v5, v7
282 ; GCN-NEXT: v_mul_hi_u32 v13, v5, v8
283 ; GCN-NEXT: v_mul_hi_u32 v10, v6, v7
284 ; GCN-NEXT: v_mul_lo_u32 v7, v6, v7
285 ; GCN-NEXT: v_mul_hi_u32 v9, v6, v8
286 ; GCN-NEXT: v_add_i32_e32 v11, vcc, v12, v11
287 ; GCN-NEXT: v_addc_u32_e32 v12, vcc, 0, v13, vcc
288 ; GCN-NEXT: v_mul_lo_u32 v8, v6, v8
289 ; GCN-NEXT: v_add_i32_e32 v7, vcc, v11, v7
290 ; GCN-NEXT: v_addc_u32_e32 v7, vcc, v12, v10, vcc
291 ; GCN-NEXT: v_addc_u32_e32 v9, vcc, 0, v9, vcc
292 ; GCN-NEXT: v_add_i32_e32 v7, vcc, v7, v8
293 ; GCN-NEXT: v_addc_u32_e32 v8, vcc, 0, v9, vcc
294 ; GCN-NEXT: v_add_i32_e32 v5, vcc, v5, v7
295 ; GCN-NEXT: v_addc_u32_e32 v6, vcc, v6, v8, vcc
296 ; GCN-NEXT: v_ashrrev_i32_e32 v7, 31, v1
297 ; GCN-NEXT: v_add_i32_e32 v0, vcc, v0, v7
298 ; GCN-NEXT: v_xor_b32_e32 v0, v0, v7
299 ; GCN-NEXT: v_mul_lo_u32 v8, v0, v6
300 ; GCN-NEXT: v_mul_hi_u32 v9, v0, v5
301 ; GCN-NEXT: v_mul_hi_u32 v10, v0, v6
302 ; GCN-NEXT: v_addc_u32_e32 v1, vcc, v1, v7, vcc
303 ; GCN-NEXT: v_xor_b32_e32 v1, v1, v7
304 ; GCN-NEXT: v_add_i32_e32 v8, vcc, v9, v8
305 ; GCN-NEXT: v_addc_u32_e32 v9, vcc, 0, v10, vcc
306 ; GCN-NEXT: v_mul_lo_u32 v10, v1, v5
307 ; GCN-NEXT: v_mul_hi_u32 v5, v1, v5
308 ; GCN-NEXT: v_mul_hi_u32 v11, v1, v6
309 ; GCN-NEXT: v_mul_lo_u32 v6, v1, v6
310 ; GCN-NEXT: v_add_i32_e32 v8, vcc, v8, v10
311 ; GCN-NEXT: v_addc_u32_e32 v5, vcc, v9, v5, vcc
312 ; GCN-NEXT: v_addc_u32_e32 v8, vcc, 0, v11, vcc
313 ; GCN-NEXT: v_add_i32_e32 v5, vcc, v5, v6
314 ; GCN-NEXT: v_addc_u32_e32 v6, vcc, 0, v8, vcc
315 ; GCN-NEXT: v_mul_lo_u32 v8, v3, v6
316 ; GCN-NEXT: v_mul_hi_u32 v9, v3, v5
317 ; GCN-NEXT: v_mul_lo_u32 v10, v2, v5
318 ; GCN-NEXT: v_add_i32_e32 v8, vcc, v9, v8
319 ; GCN-NEXT: v_mul_lo_u32 v9, v3, v5
320 ; GCN-NEXT: v_add_i32_e32 v8, vcc, v8, v10
321 ; GCN-NEXT: v_sub_i32_e32 v10, vcc, v1, v8
322 ; GCN-NEXT: v_sub_i32_e32 v0, vcc, v0, v9
323 ; GCN-NEXT: v_subb_u32_e64 v9, s[4:5], v10, v2, vcc
324 ; GCN-NEXT: v_sub_i32_e64 v10, s[4:5], v0, v3
325 ; GCN-NEXT: v_subbrev_u32_e64 v9, s[4:5], 0, v9, s[4:5]
326 ; GCN-NEXT: v_cmp_ge_u32_e64 s[4:5], v9, v2
327 ; GCN-NEXT: v_cndmask_b32_e64 v11, 0, -1, s[4:5]
328 ; GCN-NEXT: v_cmp_ge_u32_e64 s[4:5], v10, v3
329 ; GCN-NEXT: v_cndmask_b32_e64 v10, 0, -1, s[4:5]
330 ; GCN-NEXT: v_cmp_eq_u32_e64 s[4:5], v9, v2
331 ; GCN-NEXT: v_cndmask_b32_e64 v9, v11, v10, s[4:5]
332 ; GCN-NEXT: v_add_i32_e64 v10, s[4:5], 2, v5
333 ; GCN-NEXT: v_subb_u32_e32 v1, vcc, v1, v8, vcc
334 ; GCN-NEXT: v_addc_u32_e64 v11, s[4:5], 0, v6, s[4:5]
335 ; GCN-NEXT: v_cmp_ge_u32_e32 vcc, v1, v2
336 ; GCN-NEXT: v_add_i32_e64 v12, s[4:5], 1, v5
337 ; GCN-NEXT: v_cndmask_b32_e64 v8, 0, -1, vcc
338 ; GCN-NEXT: v_cmp_ge_u32_e32 vcc, v0, v3
339 ; GCN-NEXT: v_addc_u32_e64 v13, s[4:5], 0, v6, s[4:5]
340 ; GCN-NEXT: v_cndmask_b32_e64 v0, 0, -1, vcc
341 ; GCN-NEXT: v_cmp_eq_u32_e32 vcc, v1, v2
342 ; GCN-NEXT: v_cmp_ne_u32_e64 s[4:5], 0, v9
343 ; GCN-NEXT: v_cndmask_b32_e32 v0, v8, v0, vcc
344 ; GCN-NEXT: v_cndmask_b32_e64 v9, v13, v11, s[4:5]
345 ; GCN-NEXT: v_cmp_ne_u32_e32 vcc, 0, v0
346 ; GCN-NEXT: v_cndmask_b32_e64 v1, v12, v10, s[4:5]
347 ; GCN-NEXT: v_cndmask_b32_e32 v0, v6, v9, vcc
348 ; GCN-NEXT: v_cndmask_b32_e32 v1, v5, v1, vcc
349 ; GCN-NEXT: v_xor_b32_e32 v2, v7, v4
350 ; GCN-NEXT: v_xor_b32_e32 v3, v0, v2
351 ; GCN-NEXT: v_xor_b32_e32 v0, v1, v2
352 ; GCN-NEXT: v_sub_i32_e32 v0, vcc, v0, v2
353 ; GCN-NEXT: v_subb_u32_e32 v1, vcc, v3, v2, vcc
354 ; GCN-NEXT: s_setpc_b64 s[30:31]
356 ; GCN-IR-LABEL: v_test_sdiv:
357 ; GCN-IR: ; %bb.0: ; %_udiv-special-cases
358 ; GCN-IR-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
359 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v12, 31, v1
360 ; GCN-IR-NEXT: v_xor_b32_e32 v0, v0, v12
361 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v13, 31, v3
362 ; GCN-IR-NEXT: v_xor_b32_e32 v1, v1, v12
363 ; GCN-IR-NEXT: v_sub_i32_e32 v6, vcc, v0, v12
364 ; GCN-IR-NEXT: v_subb_u32_e32 v7, vcc, v1, v12, vcc
365 ; GCN-IR-NEXT: v_xor_b32_e32 v0, v2, v13
366 ; GCN-IR-NEXT: v_xor_b32_e32 v1, v3, v13
367 ; GCN-IR-NEXT: v_sub_i32_e32 v0, vcc, v0, v13
368 ; GCN-IR-NEXT: v_subb_u32_e32 v1, vcc, v1, v13, vcc
369 ; GCN-IR-NEXT: v_ffbh_u32_e32 v2, v0
370 ; GCN-IR-NEXT: v_add_i32_e64 v2, s[6:7], 32, v2
371 ; GCN-IR-NEXT: v_ffbh_u32_e32 v3, v1
372 ; GCN-IR-NEXT: v_min_u32_e32 v10, v2, v3
373 ; GCN-IR-NEXT: v_ffbh_u32_e32 v2, v6
374 ; GCN-IR-NEXT: v_add_i32_e64 v2, s[6:7], 32, v2
375 ; GCN-IR-NEXT: v_ffbh_u32_e32 v3, v7
376 ; GCN-IR-NEXT: v_min_u32_e32 v11, v2, v3
377 ; GCN-IR-NEXT: v_sub_i32_e64 v2, s[6:7], v10, v11
378 ; GCN-IR-NEXT: v_cmp_eq_u64_e32 vcc, 0, v[0:1]
379 ; GCN-IR-NEXT: v_cmp_eq_u64_e64 s[4:5], 0, v[6:7]
380 ; GCN-IR-NEXT: v_subb_u32_e64 v3, s[6:7], 0, 0, s[6:7]
381 ; GCN-IR-NEXT: v_cmp_lt_u64_e64 s[6:7], 63, v[2:3]
382 ; GCN-IR-NEXT: s_or_b64 s[4:5], vcc, s[4:5]
383 ; GCN-IR-NEXT: s_or_b64 s[4:5], s[4:5], s[6:7]
384 ; GCN-IR-NEXT: v_cmp_ne_u64_e32 vcc, 63, v[2:3]
385 ; GCN-IR-NEXT: s_xor_b64 s[6:7], s[4:5], -1
386 ; GCN-IR-NEXT: v_mov_b32_e32 v14, v12
387 ; GCN-IR-NEXT: v_mov_b32_e32 v15, v13
388 ; GCN-IR-NEXT: v_cndmask_b32_e64 v5, v7, 0, s[4:5]
389 ; GCN-IR-NEXT: v_cndmask_b32_e64 v4, v6, 0, s[4:5]
390 ; GCN-IR-NEXT: s_and_b64 s[4:5], s[6:7], vcc
391 ; GCN-IR-NEXT: s_and_saveexec_b64 s[6:7], s[4:5]
392 ; GCN-IR-NEXT: s_cbranch_execz .LBB1_6
393 ; GCN-IR-NEXT: ; %bb.1: ; %udiv-bb1
394 ; GCN-IR-NEXT: v_add_i32_e32 v8, vcc, 1, v2
395 ; GCN-IR-NEXT: v_addc_u32_e32 v9, vcc, 0, v3, vcc
396 ; GCN-IR-NEXT: v_sub_i32_e64 v2, s[4:5], 63, v2
397 ; GCN-IR-NEXT: v_cmp_ne_u64_e32 vcc, 0, v[8:9]
398 ; GCN-IR-NEXT: v_lshl_b64 v[2:3], v[6:7], v2
399 ; GCN-IR-NEXT: v_mov_b32_e32 v4, 0
400 ; GCN-IR-NEXT: v_mov_b32_e32 v5, 0
401 ; GCN-IR-NEXT: s_and_saveexec_b64 s[4:5], vcc
402 ; GCN-IR-NEXT: s_xor_b64 s[8:9], exec, s[4:5]
403 ; GCN-IR-NEXT: s_cbranch_execz .LBB1_5
404 ; GCN-IR-NEXT: ; %bb.2: ; %udiv-preheader
405 ; GCN-IR-NEXT: v_add_i32_e32 v16, vcc, -1, v0
406 ; GCN-IR-NEXT: v_addc_u32_e32 v17, vcc, -1, v1, vcc
407 ; GCN-IR-NEXT: v_not_b32_e32 v5, v10
408 ; GCN-IR-NEXT: v_lshr_b64 v[8:9], v[6:7], v8
409 ; GCN-IR-NEXT: v_not_b32_e32 v4, 0
410 ; GCN-IR-NEXT: v_add_i32_e32 v6, vcc, v5, v11
411 ; GCN-IR-NEXT: v_mov_b32_e32 v10, 0
412 ; GCN-IR-NEXT: v_addc_u32_e32 v7, vcc, 0, v4, vcc
413 ; GCN-IR-NEXT: s_mov_b64 s[10:11], 0
414 ; GCN-IR-NEXT: v_mov_b32_e32 v11, 0
415 ; GCN-IR-NEXT: v_mov_b32_e32 v5, 0
416 ; GCN-IR-NEXT: .LBB1_3: ; %udiv-do-while
417 ; GCN-IR-NEXT: ; =>This Inner Loop Header: Depth=1
418 ; GCN-IR-NEXT: v_lshl_b64 v[8:9], v[8:9], 1
419 ; GCN-IR-NEXT: v_lshrrev_b32_e32 v4, 31, v3
420 ; GCN-IR-NEXT: v_or_b32_e32 v8, v8, v4
421 ; GCN-IR-NEXT: v_lshl_b64 v[2:3], v[2:3], 1
422 ; GCN-IR-NEXT: v_sub_i32_e32 v4, vcc, v16, v8
423 ; GCN-IR-NEXT: v_subb_u32_e32 v4, vcc, v17, v9, vcc
424 ; GCN-IR-NEXT: v_or_b32_e32 v2, v10, v2
425 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v10, 31, v4
426 ; GCN-IR-NEXT: v_add_i32_e32 v6, vcc, 1, v6
427 ; GCN-IR-NEXT: v_or_b32_e32 v3, v11, v3
428 ; GCN-IR-NEXT: v_and_b32_e32 v4, 1, v10
429 ; GCN-IR-NEXT: v_and_b32_e32 v11, v10, v1
430 ; GCN-IR-NEXT: v_and_b32_e32 v10, v10, v0
431 ; GCN-IR-NEXT: v_addc_u32_e32 v7, vcc, 0, v7, vcc
432 ; GCN-IR-NEXT: v_cmp_eq_u64_e32 vcc, 0, v[6:7]
433 ; GCN-IR-NEXT: v_sub_i32_e64 v8, s[4:5], v8, v10
434 ; GCN-IR-NEXT: v_subb_u32_e64 v9, s[4:5], v9, v11, s[4:5]
435 ; GCN-IR-NEXT: v_mov_b32_e32 v11, v5
436 ; GCN-IR-NEXT: s_or_b64 s[10:11], vcc, s[10:11]
437 ; GCN-IR-NEXT: v_mov_b32_e32 v10, v4
438 ; GCN-IR-NEXT: s_andn2_b64 exec, exec, s[10:11]
439 ; GCN-IR-NEXT: s_cbranch_execnz .LBB1_3
440 ; GCN-IR-NEXT: ; %bb.4: ; %Flow
441 ; GCN-IR-NEXT: s_or_b64 exec, exec, s[10:11]
442 ; GCN-IR-NEXT: .LBB1_5: ; %Flow4
443 ; GCN-IR-NEXT: s_or_b64 exec, exec, s[8:9]
444 ; GCN-IR-NEXT: v_lshl_b64 v[0:1], v[2:3], 1
445 ; GCN-IR-NEXT: v_or_b32_e32 v5, v5, v1
446 ; GCN-IR-NEXT: v_or_b32_e32 v4, v4, v0
447 ; GCN-IR-NEXT: .LBB1_6: ; %Flow5
448 ; GCN-IR-NEXT: s_or_b64 exec, exec, s[6:7]
449 ; GCN-IR-NEXT: v_xor_b32_e32 v0, v13, v12
450 ; GCN-IR-NEXT: v_xor_b32_e32 v1, v15, v14
451 ; GCN-IR-NEXT: v_xor_b32_e32 v3, v4, v0
452 ; GCN-IR-NEXT: v_xor_b32_e32 v2, v5, v1
453 ; GCN-IR-NEXT: v_sub_i32_e32 v0, vcc, v3, v0
454 ; GCN-IR-NEXT: v_subb_u32_e32 v1, vcc, v2, v1, vcc
455 ; GCN-IR-NEXT: s_setpc_b64 s[30:31]
456 %result = sdiv i64 %x, %y
460 define amdgpu_kernel void @s_test_sdiv24_64(ptr addrspace(1) %out, i64 %x, i64 %y) {
461 ; GCN-LABEL: s_test_sdiv24_64:
463 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0x9
464 ; GCN-NEXT: s_load_dword s5, s[4:5], 0xe
465 ; GCN-NEXT: s_mov_b32 s7, 0xf000
466 ; GCN-NEXT: s_mov_b32 s6, -1
467 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
468 ; GCN-NEXT: s_mov_b32 s4, s0
469 ; GCN-NEXT: s_ashr_i64 s[8:9], s[4:5], 40
470 ; GCN-NEXT: v_cvt_f32_i32_e32 v0, s8
471 ; GCN-NEXT: s_mov_b32 s5, s1
472 ; GCN-NEXT: s_ashr_i64 s[0:1], s[2:3], 40
473 ; GCN-NEXT: v_cvt_f32_i32_e32 v1, s0
474 ; GCN-NEXT: v_rcp_iflag_f32_e32 v2, v0
475 ; GCN-NEXT: s_xor_b32 s0, s0, s8
476 ; GCN-NEXT: s_ashr_i32 s0, s0, 30
477 ; GCN-NEXT: s_or_b32 s2, s0, 1
478 ; GCN-NEXT: v_mul_f32_e32 v2, v1, v2
479 ; GCN-NEXT: v_trunc_f32_e32 v2, v2
480 ; GCN-NEXT: v_mad_f32 v1, -v2, v0, v1
481 ; GCN-NEXT: v_cvt_i32_f32_e32 v2, v2
482 ; GCN-NEXT: v_cmp_ge_f32_e64 s[0:1], |v1|, |v0|
483 ; GCN-NEXT: s_and_b64 s[0:1], s[0:1], exec
484 ; GCN-NEXT: s_cselect_b32 s0, s2, 0
485 ; GCN-NEXT: v_add_i32_e32 v0, vcc, s0, v2
486 ; GCN-NEXT: v_bfe_i32 v0, v0, 0, 24
487 ; GCN-NEXT: v_ashrrev_i32_e32 v1, 31, v0
488 ; GCN-NEXT: buffer_store_dwordx2 v[0:1], off, s[4:7], 0
491 ; GCN-IR-LABEL: s_test_sdiv24_64:
493 ; GCN-IR-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0x9
494 ; GCN-IR-NEXT: s_load_dword s5, s[4:5], 0xe
495 ; GCN-IR-NEXT: s_mov_b32 s7, 0xf000
496 ; GCN-IR-NEXT: s_mov_b32 s6, -1
497 ; GCN-IR-NEXT: s_waitcnt lgkmcnt(0)
498 ; GCN-IR-NEXT: s_mov_b32 s4, s0
499 ; GCN-IR-NEXT: s_ashr_i64 s[8:9], s[4:5], 40
500 ; GCN-IR-NEXT: v_cvt_f32_i32_e32 v0, s8
501 ; GCN-IR-NEXT: s_mov_b32 s5, s1
502 ; GCN-IR-NEXT: s_ashr_i64 s[0:1], s[2:3], 40
503 ; GCN-IR-NEXT: v_cvt_f32_i32_e32 v1, s0
504 ; GCN-IR-NEXT: v_rcp_iflag_f32_e32 v2, v0
505 ; GCN-IR-NEXT: s_xor_b32 s0, s0, s8
506 ; GCN-IR-NEXT: s_ashr_i32 s0, s0, 30
507 ; GCN-IR-NEXT: s_or_b32 s2, s0, 1
508 ; GCN-IR-NEXT: v_mul_f32_e32 v2, v1, v2
509 ; GCN-IR-NEXT: v_trunc_f32_e32 v2, v2
510 ; GCN-IR-NEXT: v_mad_f32 v1, -v2, v0, v1
511 ; GCN-IR-NEXT: v_cvt_i32_f32_e32 v2, v2
512 ; GCN-IR-NEXT: v_cmp_ge_f32_e64 s[0:1], |v1|, |v0|
513 ; GCN-IR-NEXT: s_and_b64 s[0:1], s[0:1], exec
514 ; GCN-IR-NEXT: s_cselect_b32 s0, s2, 0
515 ; GCN-IR-NEXT: v_add_i32_e32 v0, vcc, s0, v2
516 ; GCN-IR-NEXT: v_bfe_i32 v0, v0, 0, 24
517 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v1, 31, v0
518 ; GCN-IR-NEXT: buffer_store_dwordx2 v[0:1], off, s[4:7], 0
519 ; GCN-IR-NEXT: s_endpgm
522 %result = sdiv i64 %1, %2
523 store i64 %result, ptr addrspace(1) %out
527 define i64 @v_test_sdiv24_64(i64 %x, i64 %y) {
528 ; GCN-LABEL: v_test_sdiv24_64:
530 ; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
531 ; GCN-NEXT: v_lshrrev_b32_e32 v0, 8, v3
532 ; GCN-NEXT: v_cvt_f32_u32_e32 v2, v0
533 ; GCN-NEXT: v_sub_i32_e32 v3, vcc, 0, v0
534 ; GCN-NEXT: v_lshrrev_b32_e32 v1, 8, v1
535 ; GCN-NEXT: v_rcp_iflag_f32_e32 v2, v2
536 ; GCN-NEXT: v_mul_f32_e32 v2, 0x4f7ffffe, v2
537 ; GCN-NEXT: v_cvt_u32_f32_e32 v2, v2
538 ; GCN-NEXT: v_mul_lo_u32 v3, v3, v2
539 ; GCN-NEXT: v_mul_hi_u32 v3, v2, v3
540 ; GCN-NEXT: v_add_i32_e32 v2, vcc, v2, v3
541 ; GCN-NEXT: v_mul_hi_u32 v2, v1, v2
542 ; GCN-NEXT: v_mul_u32_u24_e32 v3, v2, v0
543 ; GCN-NEXT: v_add_i32_e32 v4, vcc, 1, v2
544 ; GCN-NEXT: v_sub_i32_e32 v1, vcc, v1, v3
545 ; GCN-NEXT: v_cmp_ge_u32_e32 vcc, v1, v0
546 ; GCN-NEXT: v_cndmask_b32_e32 v2, v2, v4, vcc
547 ; GCN-NEXT: v_sub_i32_e64 v3, s[4:5], v1, v0
548 ; GCN-NEXT: v_cndmask_b32_e32 v1, v1, v3, vcc
549 ; GCN-NEXT: v_add_i32_e32 v3, vcc, 1, v2
550 ; GCN-NEXT: v_cmp_ge_u32_e32 vcc, v1, v0
551 ; GCN-NEXT: v_cndmask_b32_e32 v0, v2, v3, vcc
552 ; GCN-NEXT: v_ashrrev_i32_e32 v1, 31, v0
553 ; GCN-NEXT: s_setpc_b64 s[30:31]
555 ; GCN-IR-LABEL: v_test_sdiv24_64:
557 ; GCN-IR-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
558 ; GCN-IR-NEXT: v_lshrrev_b32_e32 v0, 8, v3
559 ; GCN-IR-NEXT: v_cvt_f32_u32_e32 v2, v0
560 ; GCN-IR-NEXT: v_sub_i32_e32 v3, vcc, 0, v0
561 ; GCN-IR-NEXT: v_lshrrev_b32_e32 v1, 8, v1
562 ; GCN-IR-NEXT: v_rcp_iflag_f32_e32 v2, v2
563 ; GCN-IR-NEXT: v_mul_f32_e32 v2, 0x4f7ffffe, v2
564 ; GCN-IR-NEXT: v_cvt_u32_f32_e32 v2, v2
565 ; GCN-IR-NEXT: v_mul_lo_u32 v3, v3, v2
566 ; GCN-IR-NEXT: v_mul_hi_u32 v3, v2, v3
567 ; GCN-IR-NEXT: v_add_i32_e32 v2, vcc, v2, v3
568 ; GCN-IR-NEXT: v_mul_hi_u32 v2, v1, v2
569 ; GCN-IR-NEXT: v_mul_u32_u24_e32 v3, v2, v0
570 ; GCN-IR-NEXT: v_add_i32_e32 v4, vcc, 1, v2
571 ; GCN-IR-NEXT: v_sub_i32_e32 v1, vcc, v1, v3
572 ; GCN-IR-NEXT: v_cmp_ge_u32_e32 vcc, v1, v0
573 ; GCN-IR-NEXT: v_cndmask_b32_e32 v2, v2, v4, vcc
574 ; GCN-IR-NEXT: v_sub_i32_e64 v3, s[4:5], v1, v0
575 ; GCN-IR-NEXT: v_cndmask_b32_e32 v1, v1, v3, vcc
576 ; GCN-IR-NEXT: v_add_i32_e32 v3, vcc, 1, v2
577 ; GCN-IR-NEXT: v_cmp_ge_u32_e32 vcc, v1, v0
578 ; GCN-IR-NEXT: v_cndmask_b32_e32 v0, v2, v3, vcc
579 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v1, 31, v0
580 ; GCN-IR-NEXT: s_setpc_b64 s[30:31]
583 %result = sdiv i64 %1, %2
587 define amdgpu_kernel void @s_test_sdiv32_64(ptr addrspace(1) %out, i64 %x, i64 %y) {
588 ; GCN-LABEL: s_test_sdiv32_64:
590 ; GCN-NEXT: s_load_dword s8, s[4:5], 0xe
591 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0x9
592 ; GCN-NEXT: s_mov_b32 s7, 0xf000
593 ; GCN-NEXT: s_mov_b32 s6, -1
594 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
595 ; GCN-NEXT: s_abs_i32 s9, s8
596 ; GCN-NEXT: v_cvt_f32_u32_e32 v0, s9
597 ; GCN-NEXT: s_sub_i32 s2, 0, s9
598 ; GCN-NEXT: s_mov_b32 s4, s0
599 ; GCN-NEXT: s_abs_i32 s0, s3
600 ; GCN-NEXT: v_rcp_iflag_f32_e32 v0, v0
601 ; GCN-NEXT: s_mov_b32 s5, s1
602 ; GCN-NEXT: s_xor_b32 s1, s3, s8
603 ; GCN-NEXT: s_ashr_i32 s1, s1, 31
604 ; GCN-NEXT: v_mul_f32_e32 v0, 0x4f7ffffe, v0
605 ; GCN-NEXT: v_cvt_u32_f32_e32 v0, v0
606 ; GCN-NEXT: v_mul_lo_u32 v1, s2, v0
607 ; GCN-NEXT: v_mul_hi_u32 v1, v0, v1
608 ; GCN-NEXT: v_add_i32_e32 v0, vcc, v0, v1
609 ; GCN-NEXT: v_mul_hi_u32 v0, s0, v0
610 ; GCN-NEXT: v_readfirstlane_b32 s2, v0
611 ; GCN-NEXT: s_mul_i32 s3, s2, s9
612 ; GCN-NEXT: s_sub_i32 s0, s0, s3
613 ; GCN-NEXT: s_add_i32 s8, s2, 1
614 ; GCN-NEXT: s_sub_i32 s3, s0, s9
615 ; GCN-NEXT: s_cmp_ge_u32 s0, s9
616 ; GCN-NEXT: s_cselect_b32 s2, s8, s2
617 ; GCN-NEXT: s_cselect_b32 s0, s3, s0
618 ; GCN-NEXT: s_add_i32 s3, s2, 1
619 ; GCN-NEXT: s_cmp_ge_u32 s0, s9
620 ; GCN-NEXT: s_cselect_b32 s0, s3, s2
621 ; GCN-NEXT: s_xor_b32 s0, s0, s1
622 ; GCN-NEXT: s_sub_i32 s0, s0, s1
623 ; GCN-NEXT: s_ashr_i32 s1, s0, 31
624 ; GCN-NEXT: v_mov_b32_e32 v0, s0
625 ; GCN-NEXT: v_mov_b32_e32 v1, s1
626 ; GCN-NEXT: buffer_store_dwordx2 v[0:1], off, s[4:7], 0
629 ; GCN-IR-LABEL: s_test_sdiv32_64:
631 ; GCN-IR-NEXT: s_load_dword s8, s[4:5], 0xe
632 ; GCN-IR-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0x9
633 ; GCN-IR-NEXT: s_mov_b32 s7, 0xf000
634 ; GCN-IR-NEXT: s_mov_b32 s6, -1
635 ; GCN-IR-NEXT: s_waitcnt lgkmcnt(0)
636 ; GCN-IR-NEXT: s_abs_i32 s9, s8
637 ; GCN-IR-NEXT: v_cvt_f32_u32_e32 v0, s9
638 ; GCN-IR-NEXT: s_sub_i32 s2, 0, s9
639 ; GCN-IR-NEXT: s_mov_b32 s4, s0
640 ; GCN-IR-NEXT: s_abs_i32 s0, s3
641 ; GCN-IR-NEXT: v_rcp_iflag_f32_e32 v0, v0
642 ; GCN-IR-NEXT: s_mov_b32 s5, s1
643 ; GCN-IR-NEXT: s_xor_b32 s1, s3, s8
644 ; GCN-IR-NEXT: s_ashr_i32 s1, s1, 31
645 ; GCN-IR-NEXT: v_mul_f32_e32 v0, 0x4f7ffffe, v0
646 ; GCN-IR-NEXT: v_cvt_u32_f32_e32 v0, v0
647 ; GCN-IR-NEXT: v_mul_lo_u32 v1, s2, v0
648 ; GCN-IR-NEXT: v_mul_hi_u32 v1, v0, v1
649 ; GCN-IR-NEXT: v_add_i32_e32 v0, vcc, v0, v1
650 ; GCN-IR-NEXT: v_mul_hi_u32 v0, s0, v0
651 ; GCN-IR-NEXT: v_readfirstlane_b32 s2, v0
652 ; GCN-IR-NEXT: s_mul_i32 s3, s2, s9
653 ; GCN-IR-NEXT: s_sub_i32 s0, s0, s3
654 ; GCN-IR-NEXT: s_add_i32 s8, s2, 1
655 ; GCN-IR-NEXT: s_sub_i32 s3, s0, s9
656 ; GCN-IR-NEXT: s_cmp_ge_u32 s0, s9
657 ; GCN-IR-NEXT: s_cselect_b32 s2, s8, s2
658 ; GCN-IR-NEXT: s_cselect_b32 s0, s3, s0
659 ; GCN-IR-NEXT: s_add_i32 s3, s2, 1
660 ; GCN-IR-NEXT: s_cmp_ge_u32 s0, s9
661 ; GCN-IR-NEXT: s_cselect_b32 s0, s3, s2
662 ; GCN-IR-NEXT: s_xor_b32 s0, s0, s1
663 ; GCN-IR-NEXT: s_sub_i32 s0, s0, s1
664 ; GCN-IR-NEXT: s_ashr_i32 s1, s0, 31
665 ; GCN-IR-NEXT: v_mov_b32_e32 v0, s0
666 ; GCN-IR-NEXT: v_mov_b32_e32 v1, s1
667 ; GCN-IR-NEXT: buffer_store_dwordx2 v[0:1], off, s[4:7], 0
668 ; GCN-IR-NEXT: s_endpgm
671 %result = sdiv i64 %1, %2
672 store i64 %result, ptr addrspace(1) %out
676 define amdgpu_kernel void @s_test_sdiv31_64(ptr addrspace(1) %out, i64 %x, i64 %y) {
677 ; GCN-LABEL: s_test_sdiv31_64:
679 ; GCN-NEXT: s_load_dword s1, s[4:5], 0xe
680 ; GCN-NEXT: s_mov_b32 s7, 0xf000
681 ; GCN-NEXT: s_mov_b32 s6, -1
682 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
683 ; GCN-NEXT: s_ashr_i64 s[8:9], s[0:1], 33
684 ; GCN-NEXT: s_abs_i32 s9, s8
685 ; GCN-NEXT: v_cvt_f32_u32_e32 v0, s9
686 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0x9
687 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
688 ; GCN-NEXT: s_sub_i32 s2, 0, s9
689 ; GCN-NEXT: v_rcp_iflag_f32_e32 v0, v0
690 ; GCN-NEXT: s_mov_b32 s4, s0
691 ; GCN-NEXT: s_mov_b32 s5, s1
692 ; GCN-NEXT: v_mul_f32_e32 v0, 0x4f7ffffe, v0
693 ; GCN-NEXT: v_cvt_u32_f32_e32 v0, v0
694 ; GCN-NEXT: v_mul_lo_u32 v1, s2, v0
695 ; GCN-NEXT: s_ashr_i64 s[2:3], s[2:3], 33
696 ; GCN-NEXT: s_abs_i32 s0, s2
697 ; GCN-NEXT: s_xor_b32 s1, s2, s8
698 ; GCN-NEXT: v_mul_hi_u32 v1, v0, v1
699 ; GCN-NEXT: s_ashr_i32 s1, s1, 31
700 ; GCN-NEXT: v_add_i32_e32 v0, vcc, v0, v1
701 ; GCN-NEXT: v_mul_hi_u32 v0, s0, v0
702 ; GCN-NEXT: v_readfirstlane_b32 s2, v0
703 ; GCN-NEXT: s_mul_i32 s3, s2, s9
704 ; GCN-NEXT: s_sub_i32 s0, s0, s3
705 ; GCN-NEXT: s_add_i32 s8, s2, 1
706 ; GCN-NEXT: s_sub_i32 s3, s0, s9
707 ; GCN-NEXT: s_cmp_ge_u32 s0, s9
708 ; GCN-NEXT: s_cselect_b32 s2, s8, s2
709 ; GCN-NEXT: s_cselect_b32 s0, s3, s0
710 ; GCN-NEXT: s_add_i32 s3, s2, 1
711 ; GCN-NEXT: s_cmp_ge_u32 s0, s9
712 ; GCN-NEXT: s_cselect_b32 s0, s3, s2
713 ; GCN-NEXT: s_xor_b32 s0, s0, s1
714 ; GCN-NEXT: s_sub_i32 s0, s0, s1
715 ; GCN-NEXT: s_ashr_i32 s1, s0, 31
716 ; GCN-NEXT: v_mov_b32_e32 v0, s0
717 ; GCN-NEXT: v_mov_b32_e32 v1, s1
718 ; GCN-NEXT: buffer_store_dwordx2 v[0:1], off, s[4:7], 0
721 ; GCN-IR-LABEL: s_test_sdiv31_64:
723 ; GCN-IR-NEXT: s_load_dword s1, s[4:5], 0xe
724 ; GCN-IR-NEXT: s_mov_b32 s7, 0xf000
725 ; GCN-IR-NEXT: s_mov_b32 s6, -1
726 ; GCN-IR-NEXT: s_waitcnt lgkmcnt(0)
727 ; GCN-IR-NEXT: s_ashr_i64 s[8:9], s[0:1], 33
728 ; GCN-IR-NEXT: s_abs_i32 s9, s8
729 ; GCN-IR-NEXT: v_cvt_f32_u32_e32 v0, s9
730 ; GCN-IR-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0x9
731 ; GCN-IR-NEXT: s_waitcnt lgkmcnt(0)
732 ; GCN-IR-NEXT: s_sub_i32 s2, 0, s9
733 ; GCN-IR-NEXT: v_rcp_iflag_f32_e32 v0, v0
734 ; GCN-IR-NEXT: s_mov_b32 s4, s0
735 ; GCN-IR-NEXT: s_mov_b32 s5, s1
736 ; GCN-IR-NEXT: v_mul_f32_e32 v0, 0x4f7ffffe, v0
737 ; GCN-IR-NEXT: v_cvt_u32_f32_e32 v0, v0
738 ; GCN-IR-NEXT: v_mul_lo_u32 v1, s2, v0
739 ; GCN-IR-NEXT: s_ashr_i64 s[2:3], s[2:3], 33
740 ; GCN-IR-NEXT: s_abs_i32 s0, s2
741 ; GCN-IR-NEXT: s_xor_b32 s1, s2, s8
742 ; GCN-IR-NEXT: v_mul_hi_u32 v1, v0, v1
743 ; GCN-IR-NEXT: s_ashr_i32 s1, s1, 31
744 ; GCN-IR-NEXT: v_add_i32_e32 v0, vcc, v0, v1
745 ; GCN-IR-NEXT: v_mul_hi_u32 v0, s0, v0
746 ; GCN-IR-NEXT: v_readfirstlane_b32 s2, v0
747 ; GCN-IR-NEXT: s_mul_i32 s3, s2, s9
748 ; GCN-IR-NEXT: s_sub_i32 s0, s0, s3
749 ; GCN-IR-NEXT: s_add_i32 s8, s2, 1
750 ; GCN-IR-NEXT: s_sub_i32 s3, s0, s9
751 ; GCN-IR-NEXT: s_cmp_ge_u32 s0, s9
752 ; GCN-IR-NEXT: s_cselect_b32 s2, s8, s2
753 ; GCN-IR-NEXT: s_cselect_b32 s0, s3, s0
754 ; GCN-IR-NEXT: s_add_i32 s3, s2, 1
755 ; GCN-IR-NEXT: s_cmp_ge_u32 s0, s9
756 ; GCN-IR-NEXT: s_cselect_b32 s0, s3, s2
757 ; GCN-IR-NEXT: s_xor_b32 s0, s0, s1
758 ; GCN-IR-NEXT: s_sub_i32 s0, s0, s1
759 ; GCN-IR-NEXT: s_ashr_i32 s1, s0, 31
760 ; GCN-IR-NEXT: v_mov_b32_e32 v0, s0
761 ; GCN-IR-NEXT: v_mov_b32_e32 v1, s1
762 ; GCN-IR-NEXT: buffer_store_dwordx2 v[0:1], off, s[4:7], 0
763 ; GCN-IR-NEXT: s_endpgm
766 %result = sdiv i64 %1, %2
767 store i64 %result, ptr addrspace(1) %out
771 define amdgpu_kernel void @s_test_sdiv23_64(ptr addrspace(1) %out, i64 %x, i64 %y) {
772 ; GCN-LABEL: s_test_sdiv23_64:
774 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0x9
775 ; GCN-NEXT: s_load_dword s5, s[4:5], 0xe
776 ; GCN-NEXT: s_mov_b32 s7, 0xf000
777 ; GCN-NEXT: s_mov_b32 s6, -1
778 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
779 ; GCN-NEXT: s_mov_b32 s4, s0
780 ; GCN-NEXT: s_ashr_i64 s[8:9], s[4:5], 41
781 ; GCN-NEXT: v_cvt_f32_i32_e32 v0, s8
782 ; GCN-NEXT: s_mov_b32 s5, s1
783 ; GCN-NEXT: s_ashr_i64 s[0:1], s[2:3], 41
784 ; GCN-NEXT: v_cvt_f32_i32_e32 v1, s0
785 ; GCN-NEXT: v_rcp_iflag_f32_e32 v2, v0
786 ; GCN-NEXT: s_xor_b32 s0, s0, s8
787 ; GCN-NEXT: s_ashr_i32 s0, s0, 30
788 ; GCN-NEXT: s_or_b32 s2, s0, 1
789 ; GCN-NEXT: v_mul_f32_e32 v2, v1, v2
790 ; GCN-NEXT: v_trunc_f32_e32 v2, v2
791 ; GCN-NEXT: v_mad_f32 v1, -v2, v0, v1
792 ; GCN-NEXT: v_cvt_i32_f32_e32 v2, v2
793 ; GCN-NEXT: v_cmp_ge_f32_e64 s[0:1], |v1|, |v0|
794 ; GCN-NEXT: s_and_b64 s[0:1], s[0:1], exec
795 ; GCN-NEXT: s_cselect_b32 s0, s2, 0
796 ; GCN-NEXT: v_add_i32_e32 v0, vcc, s0, v2
797 ; GCN-NEXT: v_bfe_i32 v0, v0, 0, 23
798 ; GCN-NEXT: v_ashrrev_i32_e32 v1, 31, v0
799 ; GCN-NEXT: buffer_store_dwordx2 v[0:1], off, s[4:7], 0
802 ; GCN-IR-LABEL: s_test_sdiv23_64:
804 ; GCN-IR-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0x9
805 ; GCN-IR-NEXT: s_load_dword s5, s[4:5], 0xe
806 ; GCN-IR-NEXT: s_mov_b32 s7, 0xf000
807 ; GCN-IR-NEXT: s_mov_b32 s6, -1
808 ; GCN-IR-NEXT: s_waitcnt lgkmcnt(0)
809 ; GCN-IR-NEXT: s_mov_b32 s4, s0
810 ; GCN-IR-NEXT: s_ashr_i64 s[8:9], s[4:5], 41
811 ; GCN-IR-NEXT: v_cvt_f32_i32_e32 v0, s8
812 ; GCN-IR-NEXT: s_mov_b32 s5, s1
813 ; GCN-IR-NEXT: s_ashr_i64 s[0:1], s[2:3], 41
814 ; GCN-IR-NEXT: v_cvt_f32_i32_e32 v1, s0
815 ; GCN-IR-NEXT: v_rcp_iflag_f32_e32 v2, v0
816 ; GCN-IR-NEXT: s_xor_b32 s0, s0, s8
817 ; GCN-IR-NEXT: s_ashr_i32 s0, s0, 30
818 ; GCN-IR-NEXT: s_or_b32 s2, s0, 1
819 ; GCN-IR-NEXT: v_mul_f32_e32 v2, v1, v2
820 ; GCN-IR-NEXT: v_trunc_f32_e32 v2, v2
821 ; GCN-IR-NEXT: v_mad_f32 v1, -v2, v0, v1
822 ; GCN-IR-NEXT: v_cvt_i32_f32_e32 v2, v2
823 ; GCN-IR-NEXT: v_cmp_ge_f32_e64 s[0:1], |v1|, |v0|
824 ; GCN-IR-NEXT: s_and_b64 s[0:1], s[0:1], exec
825 ; GCN-IR-NEXT: s_cselect_b32 s0, s2, 0
826 ; GCN-IR-NEXT: v_add_i32_e32 v0, vcc, s0, v2
827 ; GCN-IR-NEXT: v_bfe_i32 v0, v0, 0, 23
828 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v1, 31, v0
829 ; GCN-IR-NEXT: buffer_store_dwordx2 v[0:1], off, s[4:7], 0
830 ; GCN-IR-NEXT: s_endpgm
833 %result = sdiv i64 %1, %2
834 store i64 %result, ptr addrspace(1) %out
838 define amdgpu_kernel void @s_test_sdiv25_64(ptr addrspace(1) %out, i64 %x, i64 %y) {
839 ; GCN-LABEL: s_test_sdiv25_64:
841 ; GCN-NEXT: s_load_dword s1, s[4:5], 0xe
842 ; GCN-NEXT: s_mov_b32 s7, 0xf000
843 ; GCN-NEXT: s_mov_b32 s6, -1
844 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
845 ; GCN-NEXT: s_ashr_i64 s[8:9], s[0:1], 39
846 ; GCN-NEXT: s_abs_i32 s9, s8
847 ; GCN-NEXT: v_cvt_f32_u32_e32 v0, s9
848 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0x9
849 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
850 ; GCN-NEXT: s_sub_i32 s2, 0, s9
851 ; GCN-NEXT: v_rcp_iflag_f32_e32 v0, v0
852 ; GCN-NEXT: s_mov_b32 s4, s0
853 ; GCN-NEXT: s_mov_b32 s5, s1
854 ; GCN-NEXT: v_mul_f32_e32 v0, 0x4f7ffffe, v0
855 ; GCN-NEXT: v_cvt_u32_f32_e32 v0, v0
856 ; GCN-NEXT: v_mul_lo_u32 v1, s2, v0
857 ; GCN-NEXT: s_ashr_i64 s[2:3], s[2:3], 39
858 ; GCN-NEXT: s_abs_i32 s0, s2
859 ; GCN-NEXT: s_xor_b32 s1, s2, s8
860 ; GCN-NEXT: v_mul_hi_u32 v1, v0, v1
861 ; GCN-NEXT: s_ashr_i32 s1, s1, 31
862 ; GCN-NEXT: v_add_i32_e32 v0, vcc, v0, v1
863 ; GCN-NEXT: v_mul_hi_u32 v0, s0, v0
864 ; GCN-NEXT: v_readfirstlane_b32 s2, v0
865 ; GCN-NEXT: s_mul_i32 s3, s2, s9
866 ; GCN-NEXT: s_sub_i32 s0, s0, s3
867 ; GCN-NEXT: s_add_i32 s8, s2, 1
868 ; GCN-NEXT: s_sub_i32 s3, s0, s9
869 ; GCN-NEXT: s_cmp_ge_u32 s0, s9
870 ; GCN-NEXT: s_cselect_b32 s2, s8, s2
871 ; GCN-NEXT: s_cselect_b32 s0, s3, s0
872 ; GCN-NEXT: s_add_i32 s3, s2, 1
873 ; GCN-NEXT: s_cmp_ge_u32 s0, s9
874 ; GCN-NEXT: s_cselect_b32 s0, s3, s2
875 ; GCN-NEXT: s_xor_b32 s0, s0, s1
876 ; GCN-NEXT: s_sub_i32 s0, s0, s1
877 ; GCN-NEXT: s_ashr_i32 s1, s0, 31
878 ; GCN-NEXT: v_mov_b32_e32 v0, s0
879 ; GCN-NEXT: v_mov_b32_e32 v1, s1
880 ; GCN-NEXT: buffer_store_dwordx2 v[0:1], off, s[4:7], 0
883 ; GCN-IR-LABEL: s_test_sdiv25_64:
885 ; GCN-IR-NEXT: s_load_dword s1, s[4:5], 0xe
886 ; GCN-IR-NEXT: s_mov_b32 s7, 0xf000
887 ; GCN-IR-NEXT: s_mov_b32 s6, -1
888 ; GCN-IR-NEXT: s_waitcnt lgkmcnt(0)
889 ; GCN-IR-NEXT: s_ashr_i64 s[8:9], s[0:1], 39
890 ; GCN-IR-NEXT: s_abs_i32 s9, s8
891 ; GCN-IR-NEXT: v_cvt_f32_u32_e32 v0, s9
892 ; GCN-IR-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0x9
893 ; GCN-IR-NEXT: s_waitcnt lgkmcnt(0)
894 ; GCN-IR-NEXT: s_sub_i32 s2, 0, s9
895 ; GCN-IR-NEXT: v_rcp_iflag_f32_e32 v0, v0
896 ; GCN-IR-NEXT: s_mov_b32 s4, s0
897 ; GCN-IR-NEXT: s_mov_b32 s5, s1
898 ; GCN-IR-NEXT: v_mul_f32_e32 v0, 0x4f7ffffe, v0
899 ; GCN-IR-NEXT: v_cvt_u32_f32_e32 v0, v0
900 ; GCN-IR-NEXT: v_mul_lo_u32 v1, s2, v0
901 ; GCN-IR-NEXT: s_ashr_i64 s[2:3], s[2:3], 39
902 ; GCN-IR-NEXT: s_abs_i32 s0, s2
903 ; GCN-IR-NEXT: s_xor_b32 s1, s2, s8
904 ; GCN-IR-NEXT: v_mul_hi_u32 v1, v0, v1
905 ; GCN-IR-NEXT: s_ashr_i32 s1, s1, 31
906 ; GCN-IR-NEXT: v_add_i32_e32 v0, vcc, v0, v1
907 ; GCN-IR-NEXT: v_mul_hi_u32 v0, s0, v0
908 ; GCN-IR-NEXT: v_readfirstlane_b32 s2, v0
909 ; GCN-IR-NEXT: s_mul_i32 s3, s2, s9
910 ; GCN-IR-NEXT: s_sub_i32 s0, s0, s3
911 ; GCN-IR-NEXT: s_add_i32 s8, s2, 1
912 ; GCN-IR-NEXT: s_sub_i32 s3, s0, s9
913 ; GCN-IR-NEXT: s_cmp_ge_u32 s0, s9
914 ; GCN-IR-NEXT: s_cselect_b32 s2, s8, s2
915 ; GCN-IR-NEXT: s_cselect_b32 s0, s3, s0
916 ; GCN-IR-NEXT: s_add_i32 s3, s2, 1
917 ; GCN-IR-NEXT: s_cmp_ge_u32 s0, s9
918 ; GCN-IR-NEXT: s_cselect_b32 s0, s3, s2
919 ; GCN-IR-NEXT: s_xor_b32 s0, s0, s1
920 ; GCN-IR-NEXT: s_sub_i32 s0, s0, s1
921 ; GCN-IR-NEXT: s_ashr_i32 s1, s0, 31
922 ; GCN-IR-NEXT: v_mov_b32_e32 v0, s0
923 ; GCN-IR-NEXT: v_mov_b32_e32 v1, s1
924 ; GCN-IR-NEXT: buffer_store_dwordx2 v[0:1], off, s[4:7], 0
925 ; GCN-IR-NEXT: s_endpgm
928 %result = sdiv i64 %1, %2
929 store i64 %result, ptr addrspace(1) %out
933 define amdgpu_kernel void @s_test_sdiv24_v2i64(ptr addrspace(1) %out, <2 x i64> %x, <2 x i64> %y) {
934 ; GCN-LABEL: s_test_sdiv24_v2i64:
936 ; GCN-NEXT: s_load_dwordx8 s[8:15], s[4:5], 0xd
937 ; GCN-NEXT: s_load_dwordx2 s[0:1], s[4:5], 0x9
938 ; GCN-NEXT: s_mov_b32 s3, 0xf000
939 ; GCN-NEXT: s_mov_b32 s2, -1
940 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
941 ; GCN-NEXT: s_ashr_i64 s[6:7], s[12:13], 40
942 ; GCN-NEXT: v_cvt_f32_i32_e32 v0, s6
943 ; GCN-NEXT: s_ashr_i64 s[8:9], s[8:9], 40
944 ; GCN-NEXT: v_cvt_f32_i32_e32 v1, s8
945 ; GCN-NEXT: s_ashr_i64 s[4:5], s[10:11], 40
946 ; GCN-NEXT: v_rcp_iflag_f32_e32 v2, v0
947 ; GCN-NEXT: s_xor_b32 s5, s8, s6
948 ; GCN-NEXT: s_ashr_i32 s5, s5, 30
949 ; GCN-NEXT: s_ashr_i64 s[10:11], s[14:15], 40
950 ; GCN-NEXT: v_mul_f32_e32 v2, v1, v2
951 ; GCN-NEXT: v_trunc_f32_e32 v2, v2
952 ; GCN-NEXT: v_mad_f32 v1, -v2, v0, v1
953 ; GCN-NEXT: v_cvt_i32_f32_e32 v2, v2
954 ; GCN-NEXT: s_or_b32 s5, s5, 1
955 ; GCN-NEXT: v_cmp_ge_f32_e64 s[6:7], |v1|, |v0|
956 ; GCN-NEXT: s_and_b64 s[6:7], s[6:7], exec
957 ; GCN-NEXT: s_cselect_b32 s5, s5, 0
958 ; GCN-NEXT: v_add_i32_e32 v0, vcc, s5, v2
959 ; GCN-NEXT: v_cvt_f32_i32_e32 v2, s10
960 ; GCN-NEXT: v_cvt_f32_i32_e32 v3, s4
961 ; GCN-NEXT: s_xor_b32 s4, s4, s10
962 ; GCN-NEXT: s_ashr_i32 s4, s4, 30
963 ; GCN-NEXT: v_rcp_iflag_f32_e32 v4, v2
964 ; GCN-NEXT: s_or_b32 s6, s4, 1
965 ; GCN-NEXT: v_bfe_i32 v0, v0, 0, 24
966 ; GCN-NEXT: v_ashrrev_i32_e32 v1, 31, v0
967 ; GCN-NEXT: v_mul_f32_e32 v4, v3, v4
968 ; GCN-NEXT: v_trunc_f32_e32 v4, v4
969 ; GCN-NEXT: v_mad_f32 v3, -v4, v2, v3
970 ; GCN-NEXT: v_cvt_i32_f32_e32 v4, v4
971 ; GCN-NEXT: v_cmp_ge_f32_e64 s[4:5], |v3|, |v2|
972 ; GCN-NEXT: s_and_b64 s[4:5], s[4:5], exec
973 ; GCN-NEXT: s_cselect_b32 s4, s6, 0
974 ; GCN-NEXT: v_add_i32_e32 v2, vcc, s4, v4
975 ; GCN-NEXT: v_bfe_i32 v2, v2, 0, 24
976 ; GCN-NEXT: v_ashrrev_i32_e32 v3, 31, v2
977 ; GCN-NEXT: buffer_store_dwordx4 v[0:3], off, s[0:3], 0
980 ; GCN-IR-LABEL: s_test_sdiv24_v2i64:
982 ; GCN-IR-NEXT: s_load_dwordx8 s[8:15], s[4:5], 0xd
983 ; GCN-IR-NEXT: s_load_dwordx2 s[0:1], s[4:5], 0x9
984 ; GCN-IR-NEXT: s_mov_b32 s3, 0xf000
985 ; GCN-IR-NEXT: s_mov_b32 s2, -1
986 ; GCN-IR-NEXT: s_waitcnt lgkmcnt(0)
987 ; GCN-IR-NEXT: s_ashr_i64 s[6:7], s[12:13], 40
988 ; GCN-IR-NEXT: v_cvt_f32_i32_e32 v0, s6
989 ; GCN-IR-NEXT: s_ashr_i64 s[8:9], s[8:9], 40
990 ; GCN-IR-NEXT: v_cvt_f32_i32_e32 v1, s8
991 ; GCN-IR-NEXT: s_ashr_i64 s[4:5], s[10:11], 40
992 ; GCN-IR-NEXT: v_rcp_iflag_f32_e32 v2, v0
993 ; GCN-IR-NEXT: s_xor_b32 s5, s8, s6
994 ; GCN-IR-NEXT: s_ashr_i32 s5, s5, 30
995 ; GCN-IR-NEXT: s_ashr_i64 s[10:11], s[14:15], 40
996 ; GCN-IR-NEXT: v_mul_f32_e32 v2, v1, v2
997 ; GCN-IR-NEXT: v_trunc_f32_e32 v2, v2
998 ; GCN-IR-NEXT: v_mad_f32 v1, -v2, v0, v1
999 ; GCN-IR-NEXT: v_cvt_i32_f32_e32 v2, v2
1000 ; GCN-IR-NEXT: s_or_b32 s5, s5, 1
1001 ; GCN-IR-NEXT: v_cmp_ge_f32_e64 s[6:7], |v1|, |v0|
1002 ; GCN-IR-NEXT: s_and_b64 s[6:7], s[6:7], exec
1003 ; GCN-IR-NEXT: s_cselect_b32 s5, s5, 0
1004 ; GCN-IR-NEXT: v_add_i32_e32 v0, vcc, s5, v2
1005 ; GCN-IR-NEXT: v_cvt_f32_i32_e32 v2, s10
1006 ; GCN-IR-NEXT: v_cvt_f32_i32_e32 v3, s4
1007 ; GCN-IR-NEXT: s_xor_b32 s4, s4, s10
1008 ; GCN-IR-NEXT: s_ashr_i32 s4, s4, 30
1009 ; GCN-IR-NEXT: v_rcp_iflag_f32_e32 v4, v2
1010 ; GCN-IR-NEXT: s_or_b32 s6, s4, 1
1011 ; GCN-IR-NEXT: v_bfe_i32 v0, v0, 0, 24
1012 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v1, 31, v0
1013 ; GCN-IR-NEXT: v_mul_f32_e32 v4, v3, v4
1014 ; GCN-IR-NEXT: v_trunc_f32_e32 v4, v4
1015 ; GCN-IR-NEXT: v_mad_f32 v3, -v4, v2, v3
1016 ; GCN-IR-NEXT: v_cvt_i32_f32_e32 v4, v4
1017 ; GCN-IR-NEXT: v_cmp_ge_f32_e64 s[4:5], |v3|, |v2|
1018 ; GCN-IR-NEXT: s_and_b64 s[4:5], s[4:5], exec
1019 ; GCN-IR-NEXT: s_cselect_b32 s4, s6, 0
1020 ; GCN-IR-NEXT: v_add_i32_e32 v2, vcc, s4, v4
1021 ; GCN-IR-NEXT: v_bfe_i32 v2, v2, 0, 24
1022 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v3, 31, v2
1023 ; GCN-IR-NEXT: buffer_store_dwordx4 v[0:3], off, s[0:3], 0
1024 ; GCN-IR-NEXT: s_endpgm
1025 %1 = ashr <2 x i64> %x, <i64 40, i64 40>
1026 %2 = ashr <2 x i64> %y, <i64 40, i64 40>
1027 %result = sdiv <2 x i64> %1, %2
1028 store <2 x i64> %result, ptr addrspace(1) %out
1032 define amdgpu_kernel void @s_test_sdiv24_48(ptr addrspace(1) %out, i48 %x, i48 %y) {
1033 ; GCN-LABEL: s_test_sdiv24_48:
1035 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0x9
1036 ; GCN-NEXT: s_load_dwordx2 s[8:9], s[4:5], 0xd
1037 ; GCN-NEXT: s_mov_b32 s7, 0xf000
1038 ; GCN-NEXT: s_mov_b32 s6, -1
1039 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
1040 ; GCN-NEXT: s_mov_b32 s5, s1
1041 ; GCN-NEXT: s_sext_i32_i16 s1, s9
1042 ; GCN-NEXT: v_mov_b32_e32 v0, s8
1043 ; GCN-NEXT: v_alignbit_b32 v0, s1, v0, 24
1044 ; GCN-NEXT: v_cvt_f32_i32_e32 v1, v0
1045 ; GCN-NEXT: s_mov_b32 s4, s0
1046 ; GCN-NEXT: s_sext_i32_i16 s0, s3
1047 ; GCN-NEXT: v_mov_b32_e32 v2, s2
1048 ; GCN-NEXT: v_alignbit_b32 v2, s0, v2, 24
1049 ; GCN-NEXT: v_cvt_f32_i32_e32 v3, v2
1050 ; GCN-NEXT: v_rcp_iflag_f32_e32 v4, v1
1051 ; GCN-NEXT: v_xor_b32_e32 v0, v2, v0
1052 ; GCN-NEXT: v_ashrrev_i32_e32 v0, 30, v0
1053 ; GCN-NEXT: v_or_b32_e32 v0, 1, v0
1054 ; GCN-NEXT: v_mul_f32_e32 v2, v3, v4
1055 ; GCN-NEXT: v_trunc_f32_e32 v2, v2
1056 ; GCN-NEXT: v_mad_f32 v3, -v2, v1, v3
1057 ; GCN-NEXT: v_cvt_i32_f32_e32 v2, v2
1058 ; GCN-NEXT: v_cmp_ge_f32_e64 vcc, |v3|, |v1|
1059 ; GCN-NEXT: v_cndmask_b32_e32 v0, 0, v0, vcc
1060 ; GCN-NEXT: v_add_i32_e32 v0, vcc, v0, v2
1061 ; GCN-NEXT: v_bfe_i32 v0, v0, 0, 24
1062 ; GCN-NEXT: v_ashrrev_i32_e32 v1, 31, v0
1063 ; GCN-NEXT: buffer_store_dword v0, off, s[4:7], 0
1064 ; GCN-NEXT: buffer_store_short v1, off, s[4:7], 0 offset:4
1065 ; GCN-NEXT: s_endpgm
1067 ; GCN-IR-LABEL: s_test_sdiv24_48:
1068 ; GCN-IR: ; %bb.0: ; %_udiv-special-cases
1069 ; GCN-IR-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0xb
1070 ; GCN-IR-NEXT: s_mov_b32 s15, 0
1071 ; GCN-IR-NEXT: s_waitcnt lgkmcnt(0)
1072 ; GCN-IR-NEXT: s_sext_i32_i16 s1, s1
1073 ; GCN-IR-NEXT: s_ashr_i64 s[0:1], s[0:1], 24
1074 ; GCN-IR-NEXT: s_sext_i32_i16 s3, s3
1075 ; GCN-IR-NEXT: s_lshl_b64 s[0:1], s[0:1], 16
1076 ; GCN-IR-NEXT: s_ashr_i64 s[2:3], s[2:3], 24
1077 ; GCN-IR-NEXT: s_ashr_i64 s[6:7], s[0:1], 16
1078 ; GCN-IR-NEXT: s_ashr_i32 s0, s1, 31
1079 ; GCN-IR-NEXT: s_lshl_b64 s[2:3], s[2:3], 16
1080 ; GCN-IR-NEXT: s_mov_b32 s1, s0
1081 ; GCN-IR-NEXT: s_ashr_i64 s[8:9], s[2:3], 16
1082 ; GCN-IR-NEXT: s_ashr_i32 s2, s3, 31
1083 ; GCN-IR-NEXT: s_xor_b64 s[6:7], s[6:7], s[0:1]
1084 ; GCN-IR-NEXT: s_mov_b32 s3, s2
1085 ; GCN-IR-NEXT: s_sub_u32 s12, s6, s0
1086 ; GCN-IR-NEXT: s_subb_u32 s13, s7, s0
1087 ; GCN-IR-NEXT: s_xor_b64 s[6:7], s[8:9], s[2:3]
1088 ; GCN-IR-NEXT: s_sub_u32 s6, s6, s2
1089 ; GCN-IR-NEXT: s_subb_u32 s7, s7, s2
1090 ; GCN-IR-NEXT: v_cmp_eq_u64_e64 s[8:9], s[6:7], 0
1091 ; GCN-IR-NEXT: v_cmp_eq_u64_e64 s[10:11], s[12:13], 0
1092 ; GCN-IR-NEXT: s_flbit_i32_b64 s14, s[6:7]
1093 ; GCN-IR-NEXT: s_or_b64 s[10:11], s[8:9], s[10:11]
1094 ; GCN-IR-NEXT: s_flbit_i32_b64 s20, s[12:13]
1095 ; GCN-IR-NEXT: s_sub_u32 s16, s14, s20
1096 ; GCN-IR-NEXT: s_subb_u32 s17, 0, 0
1097 ; GCN-IR-NEXT: v_cmp_gt_u64_e64 s[18:19], s[16:17], 63
1098 ; GCN-IR-NEXT: v_cmp_eq_u64_e64 s[22:23], s[16:17], 63
1099 ; GCN-IR-NEXT: s_or_b64 s[18:19], s[10:11], s[18:19]
1100 ; GCN-IR-NEXT: s_and_b64 s[10:11], s[18:19], exec
1101 ; GCN-IR-NEXT: s_cselect_b32 s11, 0, s13
1102 ; GCN-IR-NEXT: s_cselect_b32 s10, 0, s12
1103 ; GCN-IR-NEXT: s_or_b64 s[18:19], s[18:19], s[22:23]
1104 ; GCN-IR-NEXT: s_mov_b64 s[8:9], 0
1105 ; GCN-IR-NEXT: s_andn2_b64 vcc, exec, s[18:19]
1106 ; GCN-IR-NEXT: s_cbranch_vccz .LBB9_5
1107 ; GCN-IR-NEXT: ; %bb.1: ; %udiv-bb1
1108 ; GCN-IR-NEXT: s_add_u32 s18, s16, 1
1109 ; GCN-IR-NEXT: s_addc_u32 s19, s17, 0
1110 ; GCN-IR-NEXT: v_cmp_eq_u64_e64 s[10:11], s[18:19], 0
1111 ; GCN-IR-NEXT: s_sub_i32 s16, 63, s16
1112 ; GCN-IR-NEXT: s_andn2_b64 vcc, exec, s[10:11]
1113 ; GCN-IR-NEXT: s_lshl_b64 s[10:11], s[12:13], s16
1114 ; GCN-IR-NEXT: s_cbranch_vccz .LBB9_4
1115 ; GCN-IR-NEXT: ; %bb.2: ; %udiv-preheader
1116 ; GCN-IR-NEXT: s_lshr_b64 s[16:17], s[12:13], s18
1117 ; GCN-IR-NEXT: s_add_u32 s18, s6, -1
1118 ; GCN-IR-NEXT: s_addc_u32 s19, s7, -1
1119 ; GCN-IR-NEXT: s_not_b64 s[8:9], s[14:15]
1120 ; GCN-IR-NEXT: s_add_u32 s12, s8, s20
1121 ; GCN-IR-NEXT: s_addc_u32 s13, s9, 0
1122 ; GCN-IR-NEXT: s_mov_b64 s[14:15], 0
1123 ; GCN-IR-NEXT: s_mov_b32 s9, 0
1124 ; GCN-IR-NEXT: .LBB9_3: ; %udiv-do-while
1125 ; GCN-IR-NEXT: ; =>This Inner Loop Header: Depth=1
1126 ; GCN-IR-NEXT: s_lshl_b64 s[16:17], s[16:17], 1
1127 ; GCN-IR-NEXT: s_lshr_b32 s8, s11, 31
1128 ; GCN-IR-NEXT: s_lshl_b64 s[10:11], s[10:11], 1
1129 ; GCN-IR-NEXT: s_or_b64 s[16:17], s[16:17], s[8:9]
1130 ; GCN-IR-NEXT: s_or_b64 s[10:11], s[14:15], s[10:11]
1131 ; GCN-IR-NEXT: s_sub_u32 s8, s18, s16
1132 ; GCN-IR-NEXT: s_subb_u32 s8, s19, s17
1133 ; GCN-IR-NEXT: s_ashr_i32 s14, s8, 31
1134 ; GCN-IR-NEXT: s_mov_b32 s15, s14
1135 ; GCN-IR-NEXT: s_and_b32 s8, s14, 1
1136 ; GCN-IR-NEXT: s_and_b64 s[14:15], s[14:15], s[6:7]
1137 ; GCN-IR-NEXT: s_sub_u32 s16, s16, s14
1138 ; GCN-IR-NEXT: s_subb_u32 s17, s17, s15
1139 ; GCN-IR-NEXT: s_add_u32 s12, s12, 1
1140 ; GCN-IR-NEXT: s_addc_u32 s13, s13, 0
1141 ; GCN-IR-NEXT: v_cmp_eq_u64_e64 s[20:21], s[12:13], 0
1142 ; GCN-IR-NEXT: s_mov_b64 s[14:15], s[8:9]
1143 ; GCN-IR-NEXT: s_and_b64 vcc, exec, s[20:21]
1144 ; GCN-IR-NEXT: s_cbranch_vccz .LBB9_3
1145 ; GCN-IR-NEXT: .LBB9_4: ; %Flow4
1146 ; GCN-IR-NEXT: s_lshl_b64 s[6:7], s[10:11], 1
1147 ; GCN-IR-NEXT: s_or_b64 s[10:11], s[8:9], s[6:7]
1148 ; GCN-IR-NEXT: .LBB9_5: ; %udiv-end
1149 ; GCN-IR-NEXT: s_load_dwordx2 s[4:5], s[4:5], 0x9
1150 ; GCN-IR-NEXT: s_xor_b64 s[0:1], s[2:3], s[0:1]
1151 ; GCN-IR-NEXT: s_xor_b64 s[2:3], s[10:11], s[0:1]
1152 ; GCN-IR-NEXT: s_sub_u32 s0, s2, s0
1153 ; GCN-IR-NEXT: s_subb_u32 s1, s3, s1
1154 ; GCN-IR-NEXT: s_mov_b32 s7, 0xf000
1155 ; GCN-IR-NEXT: s_mov_b32 s6, -1
1156 ; GCN-IR-NEXT: v_mov_b32_e32 v0, s1
1157 ; GCN-IR-NEXT: s_waitcnt lgkmcnt(0)
1158 ; GCN-IR-NEXT: buffer_store_short v0, off, s[4:7], 0 offset:4
1159 ; GCN-IR-NEXT: s_waitcnt expcnt(0)
1160 ; GCN-IR-NEXT: v_mov_b32_e32 v0, s0
1161 ; GCN-IR-NEXT: buffer_store_dword v0, off, s[4:7], 0
1162 ; GCN-IR-NEXT: s_endpgm
1163 %1 = ashr i48 %x, 24
1164 %2 = ashr i48 %y, 24
1165 %result = sdiv i48 %1, %2
1166 store i48 %result, ptr addrspace(1) %out
1170 define amdgpu_kernel void @s_test_sdiv_k_num_i64(ptr addrspace(1) %out, i64 %x) {
1171 ; GCN-LABEL: s_test_sdiv_k_num_i64:
1173 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0x9
1174 ; GCN-NEXT: s_mov_b32 s7, 0xf000
1175 ; GCN-NEXT: s_mov_b32 s6, -1
1176 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
1177 ; GCN-NEXT: s_ashr_i32 s8, s3, 31
1178 ; GCN-NEXT: s_add_u32 s2, s2, s8
1179 ; GCN-NEXT: s_mov_b32 s9, s8
1180 ; GCN-NEXT: s_addc_u32 s3, s3, s8
1181 ; GCN-NEXT: s_xor_b64 s[2:3], s[2:3], s[8:9]
1182 ; GCN-NEXT: v_cvt_f32_u32_e32 v0, s2
1183 ; GCN-NEXT: v_cvt_f32_u32_e32 v1, s3
1184 ; GCN-NEXT: s_sub_u32 s4, 0, s2
1185 ; GCN-NEXT: s_subb_u32 s5, 0, s3
1186 ; GCN-NEXT: v_madmk_f32 v0, v1, 0x4f800000, v0
1187 ; GCN-NEXT: v_rcp_f32_e32 v0, v0
1188 ; GCN-NEXT: v_mul_f32_e32 v0, 0x5f7ffffc, v0
1189 ; GCN-NEXT: v_mul_f32_e32 v1, 0x2f800000, v0
1190 ; GCN-NEXT: v_trunc_f32_e32 v1, v1
1191 ; GCN-NEXT: v_madmk_f32 v0, v1, 0xcf800000, v0
1192 ; GCN-NEXT: v_cvt_u32_f32_e32 v1, v1
1193 ; GCN-NEXT: v_cvt_u32_f32_e32 v0, v0
1194 ; GCN-NEXT: v_mul_lo_u32 v2, s4, v1
1195 ; GCN-NEXT: v_mul_hi_u32 v3, s4, v0
1196 ; GCN-NEXT: v_mul_lo_u32 v5, s5, v0
1197 ; GCN-NEXT: v_mul_lo_u32 v4, s4, v0
1198 ; GCN-NEXT: v_add_i32_e32 v2, vcc, v2, v3
1199 ; GCN-NEXT: v_add_i32_e32 v2, vcc, v2, v5
1200 ; GCN-NEXT: v_mul_hi_u32 v3, v0, v4
1201 ; GCN-NEXT: v_mul_lo_u32 v5, v0, v2
1202 ; GCN-NEXT: v_mul_hi_u32 v7, v0, v2
1203 ; GCN-NEXT: v_mul_hi_u32 v6, v1, v4
1204 ; GCN-NEXT: v_mul_lo_u32 v4, v1, v4
1205 ; GCN-NEXT: v_mul_hi_u32 v8, v1, v2
1206 ; GCN-NEXT: v_add_i32_e32 v3, vcc, v3, v5
1207 ; GCN-NEXT: v_addc_u32_e32 v5, vcc, 0, v7, vcc
1208 ; GCN-NEXT: v_mul_lo_u32 v2, v1, v2
1209 ; GCN-NEXT: v_add_i32_e32 v3, vcc, v3, v4
1210 ; GCN-NEXT: v_addc_u32_e32 v3, vcc, v5, v6, vcc
1211 ; GCN-NEXT: v_addc_u32_e32 v4, vcc, 0, v8, vcc
1212 ; GCN-NEXT: v_add_i32_e32 v2, vcc, v3, v2
1213 ; GCN-NEXT: v_addc_u32_e32 v3, vcc, 0, v4, vcc
1214 ; GCN-NEXT: v_add_i32_e32 v0, vcc, v0, v2
1215 ; GCN-NEXT: v_addc_u32_e32 v1, vcc, v1, v3, vcc
1216 ; GCN-NEXT: v_mul_lo_u32 v2, s4, v1
1217 ; GCN-NEXT: v_mul_hi_u32 v3, s4, v0
1218 ; GCN-NEXT: v_mul_lo_u32 v4, s5, v0
1219 ; GCN-NEXT: s_mov_b32 s5, s1
1220 ; GCN-NEXT: v_add_i32_e32 v2, vcc, v2, v3
1221 ; GCN-NEXT: v_mul_lo_u32 v3, s4, v0
1222 ; GCN-NEXT: v_add_i32_e32 v2, vcc, v2, v4
1223 ; GCN-NEXT: v_mul_lo_u32 v6, v0, v2
1224 ; GCN-NEXT: v_mul_hi_u32 v7, v0, v3
1225 ; GCN-NEXT: v_mul_hi_u32 v8, v0, v2
1226 ; GCN-NEXT: v_mul_hi_u32 v5, v1, v3
1227 ; GCN-NEXT: v_mul_lo_u32 v3, v1, v3
1228 ; GCN-NEXT: v_mul_hi_u32 v4, v1, v2
1229 ; GCN-NEXT: v_add_i32_e32 v6, vcc, v7, v6
1230 ; GCN-NEXT: v_addc_u32_e32 v7, vcc, 0, v8, vcc
1231 ; GCN-NEXT: v_mul_lo_u32 v2, v1, v2
1232 ; GCN-NEXT: v_add_i32_e32 v3, vcc, v6, v3
1233 ; GCN-NEXT: v_addc_u32_e32 v3, vcc, v7, v5, vcc
1234 ; GCN-NEXT: v_addc_u32_e32 v4, vcc, 0, v4, vcc
1235 ; GCN-NEXT: v_add_i32_e32 v2, vcc, v3, v2
1236 ; GCN-NEXT: v_addc_u32_e32 v3, vcc, 0, v4, vcc
1237 ; GCN-NEXT: v_add_i32_e32 v0, vcc, v0, v2
1238 ; GCN-NEXT: v_addc_u32_e32 v1, vcc, v1, v3, vcc
1239 ; GCN-NEXT: v_mul_lo_u32 v2, v1, 24
1240 ; GCN-NEXT: v_mul_hi_u32 v0, v0, 24
1241 ; GCN-NEXT: v_mul_hi_u32 v1, v1, 24
1242 ; GCN-NEXT: v_mov_b32_e32 v4, s3
1243 ; GCN-NEXT: s_mov_b32 s4, s0
1244 ; GCN-NEXT: v_add_i32_e32 v0, vcc, v0, v2
1245 ; GCN-NEXT: v_addc_u32_e32 v0, vcc, 0, v1, vcc
1246 ; GCN-NEXT: v_mul_lo_u32 v1, s3, v0
1247 ; GCN-NEXT: v_mul_hi_u32 v2, s2, v0
1248 ; GCN-NEXT: v_add_i32_e32 v1, vcc, v1, v2
1249 ; GCN-NEXT: v_mul_lo_u32 v2, s2, v0
1250 ; GCN-NEXT: v_sub_i32_e32 v3, vcc, 0, v1
1251 ; GCN-NEXT: v_sub_i32_e32 v2, vcc, 24, v2
1252 ; GCN-NEXT: v_subb_u32_e64 v3, s[0:1], v3, v4, vcc
1253 ; GCN-NEXT: v_subrev_i32_e64 v4, s[0:1], s2, v2
1254 ; GCN-NEXT: v_subbrev_u32_e64 v3, s[0:1], 0, v3, s[0:1]
1255 ; GCN-NEXT: v_cmp_le_u32_e64 s[0:1], s3, v3
1256 ; GCN-NEXT: v_cndmask_b32_e64 v5, 0, -1, s[0:1]
1257 ; GCN-NEXT: v_cmp_le_u32_e64 s[0:1], s2, v4
1258 ; GCN-NEXT: v_cndmask_b32_e64 v4, 0, -1, s[0:1]
1259 ; GCN-NEXT: v_cmp_eq_u32_e64 s[0:1], s3, v3
1260 ; GCN-NEXT: v_cndmask_b32_e64 v3, v5, v4, s[0:1]
1261 ; GCN-NEXT: v_add_i32_e64 v4, s[0:1], 1, v0
1262 ; GCN-NEXT: v_addc_u32_e64 v5, s[0:1], 0, 0, s[0:1]
1263 ; GCN-NEXT: v_add_i32_e64 v6, s[0:1], 2, v0
1264 ; GCN-NEXT: v_addc_u32_e64 v7, s[0:1], 0, 0, s[0:1]
1265 ; GCN-NEXT: v_subb_u32_e32 v1, vcc, 0, v1, vcc
1266 ; GCN-NEXT: v_cmp_ne_u32_e64 s[0:1], 0, v3
1267 ; GCN-NEXT: v_cmp_le_u32_e32 vcc, s3, v1
1268 ; GCN-NEXT: v_cndmask_b32_e64 v3, v4, v6, s[0:1]
1269 ; GCN-NEXT: v_cndmask_b32_e64 v4, v5, v7, s[0:1]
1270 ; GCN-NEXT: v_cndmask_b32_e64 v5, 0, -1, vcc
1271 ; GCN-NEXT: v_cmp_le_u32_e32 vcc, s2, v2
1272 ; GCN-NEXT: v_cndmask_b32_e64 v2, 0, -1, vcc
1273 ; GCN-NEXT: v_cmp_eq_u32_e32 vcc, s3, v1
1274 ; GCN-NEXT: v_cndmask_b32_e32 v1, v5, v2, vcc
1275 ; GCN-NEXT: v_cmp_ne_u32_e32 vcc, 0, v1
1276 ; GCN-NEXT: v_cndmask_b32_e32 v0, v0, v3, vcc
1277 ; GCN-NEXT: v_cndmask_b32_e32 v1, 0, v4, vcc
1278 ; GCN-NEXT: v_xor_b32_e32 v0, s8, v0
1279 ; GCN-NEXT: v_xor_b32_e32 v1, s8, v1
1280 ; GCN-NEXT: v_mov_b32_e32 v2, s8
1281 ; GCN-NEXT: v_subrev_i32_e32 v0, vcc, s8, v0
1282 ; GCN-NEXT: v_subb_u32_e32 v1, vcc, v1, v2, vcc
1283 ; GCN-NEXT: buffer_store_dwordx2 v[0:1], off, s[4:7], 0
1284 ; GCN-NEXT: s_endpgm
1286 ; GCN-IR-LABEL: s_test_sdiv_k_num_i64:
1287 ; GCN-IR: ; %bb.0: ; %_udiv-special-cases
1288 ; GCN-IR-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0x9
1289 ; GCN-IR-NEXT: s_mov_b64 s[6:7], 0
1290 ; GCN-IR-NEXT: s_waitcnt lgkmcnt(0)
1291 ; GCN-IR-NEXT: s_ashr_i32 s4, s3, 31
1292 ; GCN-IR-NEXT: s_mov_b32 s5, s4
1293 ; GCN-IR-NEXT: s_xor_b64 s[2:3], s[2:3], s[4:5]
1294 ; GCN-IR-NEXT: s_sub_u32 s2, s2, s4
1295 ; GCN-IR-NEXT: s_subb_u32 s3, s3, s4
1296 ; GCN-IR-NEXT: s_flbit_i32_b64 s14, s[2:3]
1297 ; GCN-IR-NEXT: s_add_u32 s10, s14, 0xffffffc5
1298 ; GCN-IR-NEXT: s_addc_u32 s11, 0, -1
1299 ; GCN-IR-NEXT: v_cmp_eq_u64_e64 s[8:9], s[2:3], 0
1300 ; GCN-IR-NEXT: v_cmp_gt_u64_e64 s[12:13], s[10:11], 63
1301 ; GCN-IR-NEXT: v_cmp_eq_u64_e64 s[16:17], s[10:11], 63
1302 ; GCN-IR-NEXT: s_or_b64 s[12:13], s[8:9], s[12:13]
1303 ; GCN-IR-NEXT: s_and_b64 s[8:9], s[12:13], exec
1304 ; GCN-IR-NEXT: s_cselect_b32 s8, 0, 24
1305 ; GCN-IR-NEXT: s_or_b64 s[12:13], s[12:13], s[16:17]
1306 ; GCN-IR-NEXT: s_andn2_b64 vcc, exec, s[12:13]
1307 ; GCN-IR-NEXT: s_mov_b32 s9, 0
1308 ; GCN-IR-NEXT: s_cbranch_vccz .LBB10_5
1309 ; GCN-IR-NEXT: ; %bb.1: ; %udiv-bb1
1310 ; GCN-IR-NEXT: s_add_u32 s12, s10, 1
1311 ; GCN-IR-NEXT: s_addc_u32 s13, s11, 0
1312 ; GCN-IR-NEXT: v_cmp_eq_u64_e64 s[8:9], s[12:13], 0
1313 ; GCN-IR-NEXT: s_sub_i32 s10, 63, s10
1314 ; GCN-IR-NEXT: s_andn2_b64 vcc, exec, s[8:9]
1315 ; GCN-IR-NEXT: s_lshl_b64 s[8:9], 24, s10
1316 ; GCN-IR-NEXT: s_cbranch_vccz .LBB10_4
1317 ; GCN-IR-NEXT: ; %bb.2: ; %udiv-preheader
1318 ; GCN-IR-NEXT: s_lshr_b64 s[12:13], 24, s12
1319 ; GCN-IR-NEXT: s_add_u32 s16, s2, -1
1320 ; GCN-IR-NEXT: s_addc_u32 s17, s3, -1
1321 ; GCN-IR-NEXT: s_sub_u32 s10, 58, s14
1322 ; GCN-IR-NEXT: s_subb_u32 s11, 0, 0
1323 ; GCN-IR-NEXT: s_mov_b64 s[14:15], 0
1324 ; GCN-IR-NEXT: s_mov_b32 s7, 0
1325 ; GCN-IR-NEXT: .LBB10_3: ; %udiv-do-while
1326 ; GCN-IR-NEXT: ; =>This Inner Loop Header: Depth=1
1327 ; GCN-IR-NEXT: s_lshl_b64 s[12:13], s[12:13], 1
1328 ; GCN-IR-NEXT: s_lshr_b32 s6, s9, 31
1329 ; GCN-IR-NEXT: s_lshl_b64 s[8:9], s[8:9], 1
1330 ; GCN-IR-NEXT: s_or_b64 s[12:13], s[12:13], s[6:7]
1331 ; GCN-IR-NEXT: s_or_b64 s[8:9], s[14:15], s[8:9]
1332 ; GCN-IR-NEXT: s_sub_u32 s6, s16, s12
1333 ; GCN-IR-NEXT: s_subb_u32 s6, s17, s13
1334 ; GCN-IR-NEXT: s_ashr_i32 s14, s6, 31
1335 ; GCN-IR-NEXT: s_mov_b32 s15, s14
1336 ; GCN-IR-NEXT: s_and_b32 s6, s14, 1
1337 ; GCN-IR-NEXT: s_and_b64 s[14:15], s[14:15], s[2:3]
1338 ; GCN-IR-NEXT: s_sub_u32 s12, s12, s14
1339 ; GCN-IR-NEXT: s_subb_u32 s13, s13, s15
1340 ; GCN-IR-NEXT: s_add_u32 s10, s10, 1
1341 ; GCN-IR-NEXT: s_addc_u32 s11, s11, 0
1342 ; GCN-IR-NEXT: v_cmp_eq_u64_e64 s[18:19], s[10:11], 0
1343 ; GCN-IR-NEXT: s_mov_b64 s[14:15], s[6:7]
1344 ; GCN-IR-NEXT: s_and_b64 vcc, exec, s[18:19]
1345 ; GCN-IR-NEXT: s_cbranch_vccz .LBB10_3
1346 ; GCN-IR-NEXT: .LBB10_4: ; %Flow6
1347 ; GCN-IR-NEXT: s_lshl_b64 s[2:3], s[8:9], 1
1348 ; GCN-IR-NEXT: s_or_b64 s[8:9], s[6:7], s[2:3]
1349 ; GCN-IR-NEXT: .LBB10_5: ; %udiv-end
1350 ; GCN-IR-NEXT: s_xor_b64 s[6:7], s[8:9], s[4:5]
1351 ; GCN-IR-NEXT: s_sub_u32 s4, s6, s4
1352 ; GCN-IR-NEXT: s_subb_u32 s5, s7, s5
1353 ; GCN-IR-NEXT: v_mov_b32_e32 v0, s4
1354 ; GCN-IR-NEXT: s_mov_b32 s3, 0xf000
1355 ; GCN-IR-NEXT: s_mov_b32 s2, -1
1356 ; GCN-IR-NEXT: v_mov_b32_e32 v1, s5
1357 ; GCN-IR-NEXT: buffer_store_dwordx2 v[0:1], off, s[0:3], 0
1358 ; GCN-IR-NEXT: s_endpgm
1359 %result = sdiv i64 24, %x
1360 store i64 %result, ptr addrspace(1) %out
1364 define i64 @v_test_sdiv_k_num_i64(i64 %x) {
1365 ; GCN-LABEL: v_test_sdiv_k_num_i64:
1367 ; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1368 ; GCN-NEXT: v_ashrrev_i32_e32 v2, 31, v1
1369 ; GCN-NEXT: v_add_i32_e32 v0, vcc, v0, v2
1370 ; GCN-NEXT: v_addc_u32_e32 v1, vcc, v1, v2, vcc
1371 ; GCN-NEXT: v_xor_b32_e32 v1, v1, v2
1372 ; GCN-NEXT: v_xor_b32_e32 v0, v0, v2
1373 ; GCN-NEXT: v_cvt_f32_u32_e32 v3, v0
1374 ; GCN-NEXT: v_cvt_f32_u32_e32 v4, v1
1375 ; GCN-NEXT: v_sub_i32_e32 v5, vcc, 0, v0
1376 ; GCN-NEXT: v_subb_u32_e32 v6, vcc, 0, v1, vcc
1377 ; GCN-NEXT: v_madmk_f32 v3, v4, 0x4f800000, v3
1378 ; GCN-NEXT: v_rcp_f32_e32 v3, v3
1379 ; GCN-NEXT: v_mul_f32_e32 v3, 0x5f7ffffc, v3
1380 ; GCN-NEXT: v_mul_f32_e32 v4, 0x2f800000, v3
1381 ; GCN-NEXT: v_trunc_f32_e32 v4, v4
1382 ; GCN-NEXT: v_madmk_f32 v3, v4, 0xcf800000, v3
1383 ; GCN-NEXT: v_cvt_u32_f32_e32 v3, v3
1384 ; GCN-NEXT: v_cvt_u32_f32_e32 v4, v4
1385 ; GCN-NEXT: v_mul_hi_u32 v7, v5, v3
1386 ; GCN-NEXT: v_mul_lo_u32 v8, v5, v4
1387 ; GCN-NEXT: v_mul_lo_u32 v9, v6, v3
1388 ; GCN-NEXT: v_add_i32_e32 v7, vcc, v7, v8
1389 ; GCN-NEXT: v_mul_lo_u32 v8, v5, v3
1390 ; GCN-NEXT: v_add_i32_e32 v7, vcc, v7, v9
1391 ; GCN-NEXT: v_mul_lo_u32 v9, v3, v7
1392 ; GCN-NEXT: v_mul_hi_u32 v10, v3, v8
1393 ; GCN-NEXT: v_mul_hi_u32 v11, v3, v7
1394 ; GCN-NEXT: v_mul_hi_u32 v12, v4, v7
1395 ; GCN-NEXT: v_mul_lo_u32 v7, v4, v7
1396 ; GCN-NEXT: v_add_i32_e32 v9, vcc, v10, v9
1397 ; GCN-NEXT: v_addc_u32_e32 v10, vcc, 0, v11, vcc
1398 ; GCN-NEXT: v_mul_lo_u32 v11, v4, v8
1399 ; GCN-NEXT: v_mul_hi_u32 v8, v4, v8
1400 ; GCN-NEXT: v_add_i32_e32 v9, vcc, v9, v11
1401 ; GCN-NEXT: v_addc_u32_e32 v8, vcc, v10, v8, vcc
1402 ; GCN-NEXT: v_addc_u32_e32 v9, vcc, 0, v12, vcc
1403 ; GCN-NEXT: v_add_i32_e32 v7, vcc, v8, v7
1404 ; GCN-NEXT: v_addc_u32_e32 v8, vcc, 0, v9, vcc
1405 ; GCN-NEXT: v_add_i32_e32 v3, vcc, v3, v7
1406 ; GCN-NEXT: v_addc_u32_e32 v4, vcc, v4, v8, vcc
1407 ; GCN-NEXT: v_mul_lo_u32 v7, v5, v4
1408 ; GCN-NEXT: v_mul_hi_u32 v8, v5, v3
1409 ; GCN-NEXT: v_mul_lo_u32 v6, v6, v3
1410 ; GCN-NEXT: v_mul_lo_u32 v5, v5, v3
1411 ; GCN-NEXT: v_add_i32_e32 v7, vcc, v8, v7
1412 ; GCN-NEXT: v_add_i32_e32 v6, vcc, v7, v6
1413 ; GCN-NEXT: v_mul_lo_u32 v9, v3, v6
1414 ; GCN-NEXT: v_mul_hi_u32 v10, v3, v5
1415 ; GCN-NEXT: v_mul_hi_u32 v11, v3, v6
1416 ; GCN-NEXT: v_mul_hi_u32 v8, v4, v5
1417 ; GCN-NEXT: v_mul_lo_u32 v5, v4, v5
1418 ; GCN-NEXT: v_mul_hi_u32 v7, v4, v6
1419 ; GCN-NEXT: v_add_i32_e32 v9, vcc, v10, v9
1420 ; GCN-NEXT: v_addc_u32_e32 v10, vcc, 0, v11, vcc
1421 ; GCN-NEXT: v_mul_lo_u32 v6, v4, v6
1422 ; GCN-NEXT: v_add_i32_e32 v5, vcc, v9, v5
1423 ; GCN-NEXT: v_addc_u32_e32 v5, vcc, v10, v8, vcc
1424 ; GCN-NEXT: v_addc_u32_e32 v7, vcc, 0, v7, vcc
1425 ; GCN-NEXT: v_add_i32_e32 v5, vcc, v5, v6
1426 ; GCN-NEXT: v_addc_u32_e32 v6, vcc, 0, v7, vcc
1427 ; GCN-NEXT: v_add_i32_e32 v3, vcc, v3, v5
1428 ; GCN-NEXT: v_addc_u32_e32 v4, vcc, v4, v6, vcc
1429 ; GCN-NEXT: v_mul_lo_u32 v5, v4, 24
1430 ; GCN-NEXT: v_mul_hi_u32 v3, v3, 24
1431 ; GCN-NEXT: v_mul_hi_u32 v4, v4, 24
1432 ; GCN-NEXT: v_add_i32_e32 v3, vcc, v3, v5
1433 ; GCN-NEXT: v_addc_u32_e32 v3, vcc, 0, v4, vcc
1434 ; GCN-NEXT: v_mul_lo_u32 v4, v1, v3
1435 ; GCN-NEXT: v_mul_hi_u32 v5, v0, v3
1436 ; GCN-NEXT: v_add_i32_e32 v4, vcc, v5, v4
1437 ; GCN-NEXT: v_mul_lo_u32 v5, v0, v3
1438 ; GCN-NEXT: v_sub_i32_e32 v6, vcc, 0, v4
1439 ; GCN-NEXT: v_sub_i32_e32 v5, vcc, 24, v5
1440 ; GCN-NEXT: v_subb_u32_e64 v6, s[4:5], v6, v1, vcc
1441 ; GCN-NEXT: v_sub_i32_e64 v7, s[4:5], v5, v0
1442 ; GCN-NEXT: v_subbrev_u32_e64 v6, s[4:5], 0, v6, s[4:5]
1443 ; GCN-NEXT: v_cmp_ge_u32_e64 s[4:5], v6, v1
1444 ; GCN-NEXT: v_cndmask_b32_e64 v8, 0, -1, s[4:5]
1445 ; GCN-NEXT: v_cmp_ge_u32_e64 s[4:5], v7, v0
1446 ; GCN-NEXT: v_cndmask_b32_e64 v7, 0, -1, s[4:5]
1447 ; GCN-NEXT: v_cmp_eq_u32_e64 s[4:5], v6, v1
1448 ; GCN-NEXT: v_cndmask_b32_e64 v6, v8, v7, s[4:5]
1449 ; GCN-NEXT: v_add_i32_e64 v7, s[4:5], 2, v3
1450 ; GCN-NEXT: v_addc_u32_e64 v8, s[4:5], 0, 0, s[4:5]
1451 ; GCN-NEXT: v_add_i32_e64 v9, s[4:5], 1, v3
1452 ; GCN-NEXT: v_addc_u32_e64 v10, s[4:5], 0, 0, s[4:5]
1453 ; GCN-NEXT: v_subb_u32_e32 v4, vcc, 0, v4, vcc
1454 ; GCN-NEXT: v_cmp_ne_u32_e64 s[4:5], 0, v6
1455 ; GCN-NEXT: v_cmp_ge_u32_e32 vcc, v4, v1
1456 ; GCN-NEXT: v_cndmask_b32_e64 v6, v10, v8, s[4:5]
1457 ; GCN-NEXT: v_cndmask_b32_e64 v8, 0, -1, vcc
1458 ; GCN-NEXT: v_cmp_ge_u32_e32 vcc, v5, v0
1459 ; GCN-NEXT: v_cndmask_b32_e64 v0, 0, -1, vcc
1460 ; GCN-NEXT: v_cmp_eq_u32_e32 vcc, v4, v1
1461 ; GCN-NEXT: v_cndmask_b32_e32 v0, v8, v0, vcc
1462 ; GCN-NEXT: v_cmp_ne_u32_e32 vcc, 0, v0
1463 ; GCN-NEXT: v_cndmask_b32_e64 v1, v9, v7, s[4:5]
1464 ; GCN-NEXT: v_cndmask_b32_e32 v0, 0, v6, vcc
1465 ; GCN-NEXT: v_cndmask_b32_e32 v1, v3, v1, vcc
1466 ; GCN-NEXT: v_xor_b32_e32 v3, v0, v2
1467 ; GCN-NEXT: v_xor_b32_e32 v0, v1, v2
1468 ; GCN-NEXT: v_sub_i32_e32 v0, vcc, v0, v2
1469 ; GCN-NEXT: v_subb_u32_e32 v1, vcc, v3, v2, vcc
1470 ; GCN-NEXT: s_setpc_b64 s[30:31]
1472 ; GCN-IR-LABEL: v_test_sdiv_k_num_i64:
1473 ; GCN-IR: ; %bb.0: ; %_udiv-special-cases
1474 ; GCN-IR-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1475 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v12, 31, v1
1476 ; GCN-IR-NEXT: v_xor_b32_e32 v0, v0, v12
1477 ; GCN-IR-NEXT: v_xor_b32_e32 v1, v1, v12
1478 ; GCN-IR-NEXT: v_sub_i32_e32 v0, vcc, v0, v12
1479 ; GCN-IR-NEXT: v_subb_u32_e32 v1, vcc, v1, v12, vcc
1480 ; GCN-IR-NEXT: v_ffbh_u32_e32 v2, v0
1481 ; GCN-IR-NEXT: v_add_i32_e32 v2, vcc, 32, v2
1482 ; GCN-IR-NEXT: v_ffbh_u32_e32 v3, v1
1483 ; GCN-IR-NEXT: v_min_u32_e32 v10, v2, v3
1484 ; GCN-IR-NEXT: s_movk_i32 s6, 0xffc5
1485 ; GCN-IR-NEXT: v_add_i32_e32 v2, vcc, s6, v10
1486 ; GCN-IR-NEXT: v_addc_u32_e64 v3, s[6:7], 0, -1, vcc
1487 ; GCN-IR-NEXT: v_cmp_eq_u64_e64 s[4:5], 0, v[0:1]
1488 ; GCN-IR-NEXT: v_cmp_lt_u64_e32 vcc, 63, v[2:3]
1489 ; GCN-IR-NEXT: v_cmp_ne_u64_e64 s[6:7], 63, v[2:3]
1490 ; GCN-IR-NEXT: s_or_b64 s[4:5], s[4:5], vcc
1491 ; GCN-IR-NEXT: v_cndmask_b32_e64 v4, 24, 0, s[4:5]
1492 ; GCN-IR-NEXT: s_xor_b64 s[4:5], s[4:5], -1
1493 ; GCN-IR-NEXT: v_mov_b32_e32 v13, v12
1494 ; GCN-IR-NEXT: v_mov_b32_e32 v5, 0
1495 ; GCN-IR-NEXT: s_and_b64 s[4:5], s[4:5], s[6:7]
1496 ; GCN-IR-NEXT: s_and_saveexec_b64 s[6:7], s[4:5]
1497 ; GCN-IR-NEXT: s_cbranch_execz .LBB11_6
1498 ; GCN-IR-NEXT: ; %bb.1: ; %udiv-bb1
1499 ; GCN-IR-NEXT: v_add_i32_e32 v6, vcc, 1, v2
1500 ; GCN-IR-NEXT: v_addc_u32_e32 v7, vcc, 0, v3, vcc
1501 ; GCN-IR-NEXT: v_sub_i32_e64 v2, s[4:5], 63, v2
1502 ; GCN-IR-NEXT: v_cmp_ne_u64_e32 vcc, 0, v[6:7]
1503 ; GCN-IR-NEXT: v_lshl_b64 v[2:3], 24, v2
1504 ; GCN-IR-NEXT: v_mov_b32_e32 v4, 0
1505 ; GCN-IR-NEXT: v_mov_b32_e32 v5, 0
1506 ; GCN-IR-NEXT: s_and_saveexec_b64 s[4:5], vcc
1507 ; GCN-IR-NEXT: s_xor_b64 s[8:9], exec, s[4:5]
1508 ; GCN-IR-NEXT: s_cbranch_execz .LBB11_5
1509 ; GCN-IR-NEXT: ; %bb.2: ; %udiv-preheader
1510 ; GCN-IR-NEXT: v_add_i32_e32 v14, vcc, -1, v0
1511 ; GCN-IR-NEXT: v_addc_u32_e32 v15, vcc, -1, v1, vcc
1512 ; GCN-IR-NEXT: v_lshr_b64 v[8:9], 24, v6
1513 ; GCN-IR-NEXT: v_sub_i32_e32 v6, vcc, 58, v10
1514 ; GCN-IR-NEXT: v_mov_b32_e32 v10, 0
1515 ; GCN-IR-NEXT: v_subb_u32_e64 v7, s[4:5], 0, 0, vcc
1516 ; GCN-IR-NEXT: s_mov_b64 s[10:11], 0
1517 ; GCN-IR-NEXT: v_mov_b32_e32 v11, 0
1518 ; GCN-IR-NEXT: v_mov_b32_e32 v5, 0
1519 ; GCN-IR-NEXT: .LBB11_3: ; %udiv-do-while
1520 ; GCN-IR-NEXT: ; =>This Inner Loop Header: Depth=1
1521 ; GCN-IR-NEXT: v_lshl_b64 v[8:9], v[8:9], 1
1522 ; GCN-IR-NEXT: v_lshrrev_b32_e32 v4, 31, v3
1523 ; GCN-IR-NEXT: v_or_b32_e32 v8, v8, v4
1524 ; GCN-IR-NEXT: v_lshl_b64 v[2:3], v[2:3], 1
1525 ; GCN-IR-NEXT: v_sub_i32_e32 v4, vcc, v14, v8
1526 ; GCN-IR-NEXT: v_subb_u32_e32 v4, vcc, v15, v9, vcc
1527 ; GCN-IR-NEXT: v_or_b32_e32 v2, v10, v2
1528 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v10, 31, v4
1529 ; GCN-IR-NEXT: v_add_i32_e32 v6, vcc, 1, v6
1530 ; GCN-IR-NEXT: v_or_b32_e32 v3, v11, v3
1531 ; GCN-IR-NEXT: v_and_b32_e32 v4, 1, v10
1532 ; GCN-IR-NEXT: v_and_b32_e32 v11, v10, v1
1533 ; GCN-IR-NEXT: v_and_b32_e32 v10, v10, v0
1534 ; GCN-IR-NEXT: v_addc_u32_e32 v7, vcc, 0, v7, vcc
1535 ; GCN-IR-NEXT: v_cmp_eq_u64_e32 vcc, 0, v[6:7]
1536 ; GCN-IR-NEXT: v_sub_i32_e64 v8, s[4:5], v8, v10
1537 ; GCN-IR-NEXT: v_subb_u32_e64 v9, s[4:5], v9, v11, s[4:5]
1538 ; GCN-IR-NEXT: v_mov_b32_e32 v11, v5
1539 ; GCN-IR-NEXT: s_or_b64 s[10:11], vcc, s[10:11]
1540 ; GCN-IR-NEXT: v_mov_b32_e32 v10, v4
1541 ; GCN-IR-NEXT: s_andn2_b64 exec, exec, s[10:11]
1542 ; GCN-IR-NEXT: s_cbranch_execnz .LBB11_3
1543 ; GCN-IR-NEXT: ; %bb.4: ; %Flow
1544 ; GCN-IR-NEXT: s_or_b64 exec, exec, s[10:11]
1545 ; GCN-IR-NEXT: .LBB11_5: ; %Flow4
1546 ; GCN-IR-NEXT: s_or_b64 exec, exec, s[8:9]
1547 ; GCN-IR-NEXT: v_lshl_b64 v[0:1], v[2:3], 1
1548 ; GCN-IR-NEXT: v_or_b32_e32 v5, v5, v1
1549 ; GCN-IR-NEXT: v_or_b32_e32 v4, v4, v0
1550 ; GCN-IR-NEXT: .LBB11_6: ; %Flow5
1551 ; GCN-IR-NEXT: s_or_b64 exec, exec, s[6:7]
1552 ; GCN-IR-NEXT: v_xor_b32_e32 v0, v4, v12
1553 ; GCN-IR-NEXT: v_xor_b32_e32 v1, v5, v13
1554 ; GCN-IR-NEXT: v_sub_i32_e32 v0, vcc, v0, v12
1555 ; GCN-IR-NEXT: v_subb_u32_e32 v1, vcc, v1, v13, vcc
1556 ; GCN-IR-NEXT: s_setpc_b64 s[30:31]
1557 %result = sdiv i64 24, %x
1561 define i64 @v_test_sdiv_pow2_k_num_i64(i64 %x) {
1562 ; GCN-LABEL: v_test_sdiv_pow2_k_num_i64:
1564 ; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1565 ; GCN-NEXT: v_ashrrev_i32_e32 v2, 31, v1
1566 ; GCN-NEXT: v_add_i32_e32 v0, vcc, v0, v2
1567 ; GCN-NEXT: v_addc_u32_e32 v1, vcc, v1, v2, vcc
1568 ; GCN-NEXT: v_xor_b32_e32 v1, v1, v2
1569 ; GCN-NEXT: v_xor_b32_e32 v0, v0, v2
1570 ; GCN-NEXT: v_cvt_f32_u32_e32 v3, v0
1571 ; GCN-NEXT: v_cvt_f32_u32_e32 v4, v1
1572 ; GCN-NEXT: v_sub_i32_e32 v5, vcc, 0, v0
1573 ; GCN-NEXT: v_subb_u32_e32 v6, vcc, 0, v1, vcc
1574 ; GCN-NEXT: v_madmk_f32 v3, v4, 0x4f800000, v3
1575 ; GCN-NEXT: v_rcp_f32_e32 v3, v3
1576 ; GCN-NEXT: v_mul_f32_e32 v3, 0x5f7ffffc, v3
1577 ; GCN-NEXT: v_mul_f32_e32 v4, 0x2f800000, v3
1578 ; GCN-NEXT: v_trunc_f32_e32 v4, v4
1579 ; GCN-NEXT: v_madmk_f32 v3, v4, 0xcf800000, v3
1580 ; GCN-NEXT: v_cvt_u32_f32_e32 v3, v3
1581 ; GCN-NEXT: v_cvt_u32_f32_e32 v4, v4
1582 ; GCN-NEXT: v_mul_hi_u32 v7, v5, v3
1583 ; GCN-NEXT: v_mul_lo_u32 v8, v5, v4
1584 ; GCN-NEXT: v_mul_lo_u32 v9, v6, v3
1585 ; GCN-NEXT: v_add_i32_e32 v7, vcc, v7, v8
1586 ; GCN-NEXT: v_mul_lo_u32 v8, v5, v3
1587 ; GCN-NEXT: v_add_i32_e32 v7, vcc, v7, v9
1588 ; GCN-NEXT: v_mul_lo_u32 v9, v3, v7
1589 ; GCN-NEXT: v_mul_hi_u32 v10, v3, v8
1590 ; GCN-NEXT: v_mul_hi_u32 v11, v3, v7
1591 ; GCN-NEXT: v_mul_hi_u32 v12, v4, v7
1592 ; GCN-NEXT: v_mul_lo_u32 v7, v4, v7
1593 ; GCN-NEXT: v_add_i32_e32 v9, vcc, v10, v9
1594 ; GCN-NEXT: v_addc_u32_e32 v10, vcc, 0, v11, vcc
1595 ; GCN-NEXT: v_mul_lo_u32 v11, v4, v8
1596 ; GCN-NEXT: v_mul_hi_u32 v8, v4, v8
1597 ; GCN-NEXT: v_add_i32_e32 v9, vcc, v9, v11
1598 ; GCN-NEXT: v_addc_u32_e32 v8, vcc, v10, v8, vcc
1599 ; GCN-NEXT: v_addc_u32_e32 v9, vcc, 0, v12, vcc
1600 ; GCN-NEXT: v_add_i32_e32 v7, vcc, v8, v7
1601 ; GCN-NEXT: v_addc_u32_e32 v8, vcc, 0, v9, vcc
1602 ; GCN-NEXT: v_add_i32_e32 v3, vcc, v3, v7
1603 ; GCN-NEXT: v_addc_u32_e32 v4, vcc, v4, v8, vcc
1604 ; GCN-NEXT: v_mul_lo_u32 v7, v5, v4
1605 ; GCN-NEXT: v_mul_hi_u32 v8, v5, v3
1606 ; GCN-NEXT: v_mul_lo_u32 v6, v6, v3
1607 ; GCN-NEXT: v_mul_lo_u32 v5, v5, v3
1608 ; GCN-NEXT: v_add_i32_e32 v7, vcc, v8, v7
1609 ; GCN-NEXT: v_add_i32_e32 v6, vcc, v7, v6
1610 ; GCN-NEXT: v_mul_lo_u32 v9, v3, v6
1611 ; GCN-NEXT: v_mul_hi_u32 v10, v3, v5
1612 ; GCN-NEXT: v_mul_hi_u32 v11, v3, v6
1613 ; GCN-NEXT: v_mul_hi_u32 v8, v4, v5
1614 ; GCN-NEXT: v_mul_lo_u32 v5, v4, v5
1615 ; GCN-NEXT: v_mul_hi_u32 v7, v4, v6
1616 ; GCN-NEXT: v_add_i32_e32 v9, vcc, v10, v9
1617 ; GCN-NEXT: v_addc_u32_e32 v10, vcc, 0, v11, vcc
1618 ; GCN-NEXT: v_mul_lo_u32 v6, v4, v6
1619 ; GCN-NEXT: v_add_i32_e32 v5, vcc, v9, v5
1620 ; GCN-NEXT: v_addc_u32_e32 v5, vcc, v10, v8, vcc
1621 ; GCN-NEXT: v_addc_u32_e32 v7, vcc, 0, v7, vcc
1622 ; GCN-NEXT: v_add_i32_e32 v5, vcc, v5, v6
1623 ; GCN-NEXT: v_addc_u32_e32 v6, vcc, 0, v7, vcc
1624 ; GCN-NEXT: v_add_i32_e32 v3, vcc, v3, v5
1625 ; GCN-NEXT: v_addc_u32_e32 v3, vcc, v4, v6, vcc
1626 ; GCN-NEXT: v_lshrrev_b32_e32 v3, 17, v3
1627 ; GCN-NEXT: v_mul_lo_u32 v4, v1, v3
1628 ; GCN-NEXT: v_mul_hi_u32 v5, v0, v3
1629 ; GCN-NEXT: v_add_i32_e32 v4, vcc, v5, v4
1630 ; GCN-NEXT: v_mul_lo_u32 v5, v0, v3
1631 ; GCN-NEXT: v_sub_i32_e32 v6, vcc, 0, v4
1632 ; GCN-NEXT: v_sub_i32_e32 v5, vcc, 0x8000, v5
1633 ; GCN-NEXT: v_subb_u32_e64 v6, s[4:5], v6, v1, vcc
1634 ; GCN-NEXT: v_sub_i32_e64 v7, s[4:5], v5, v0
1635 ; GCN-NEXT: v_subbrev_u32_e64 v6, s[4:5], 0, v6, s[4:5]
1636 ; GCN-NEXT: v_cmp_ge_u32_e64 s[4:5], v6, v1
1637 ; GCN-NEXT: v_cndmask_b32_e64 v8, 0, -1, s[4:5]
1638 ; GCN-NEXT: v_cmp_ge_u32_e64 s[4:5], v7, v0
1639 ; GCN-NEXT: v_cndmask_b32_e64 v7, 0, -1, s[4:5]
1640 ; GCN-NEXT: v_cmp_eq_u32_e64 s[4:5], v6, v1
1641 ; GCN-NEXT: v_cndmask_b32_e64 v6, v8, v7, s[4:5]
1642 ; GCN-NEXT: v_add_i32_e64 v7, s[4:5], 2, v3
1643 ; GCN-NEXT: v_addc_u32_e64 v8, s[4:5], 0, 0, s[4:5]
1644 ; GCN-NEXT: v_add_i32_e64 v9, s[4:5], 1, v3
1645 ; GCN-NEXT: v_addc_u32_e64 v10, s[4:5], 0, 0, s[4:5]
1646 ; GCN-NEXT: v_subb_u32_e32 v4, vcc, 0, v4, vcc
1647 ; GCN-NEXT: v_cmp_ne_u32_e64 s[4:5], 0, v6
1648 ; GCN-NEXT: v_cmp_ge_u32_e32 vcc, v4, v1
1649 ; GCN-NEXT: v_cndmask_b32_e64 v6, v10, v8, s[4:5]
1650 ; GCN-NEXT: v_cndmask_b32_e64 v8, 0, -1, vcc
1651 ; GCN-NEXT: v_cmp_ge_u32_e32 vcc, v5, v0
1652 ; GCN-NEXT: v_cndmask_b32_e64 v0, 0, -1, vcc
1653 ; GCN-NEXT: v_cmp_eq_u32_e32 vcc, v4, v1
1654 ; GCN-NEXT: v_cndmask_b32_e32 v0, v8, v0, vcc
1655 ; GCN-NEXT: v_cmp_ne_u32_e32 vcc, 0, v0
1656 ; GCN-NEXT: v_cndmask_b32_e64 v1, v9, v7, s[4:5]
1657 ; GCN-NEXT: v_cndmask_b32_e32 v0, 0, v6, vcc
1658 ; GCN-NEXT: v_cndmask_b32_e32 v1, v3, v1, vcc
1659 ; GCN-NEXT: v_xor_b32_e32 v3, v0, v2
1660 ; GCN-NEXT: v_xor_b32_e32 v0, v1, v2
1661 ; GCN-NEXT: v_sub_i32_e32 v0, vcc, v0, v2
1662 ; GCN-NEXT: v_subb_u32_e32 v1, vcc, v3, v2, vcc
1663 ; GCN-NEXT: s_setpc_b64 s[30:31]
1665 ; GCN-IR-LABEL: v_test_sdiv_pow2_k_num_i64:
1666 ; GCN-IR: ; %bb.0: ; %_udiv-special-cases
1667 ; GCN-IR-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1668 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v12, 31, v1
1669 ; GCN-IR-NEXT: v_xor_b32_e32 v0, v0, v12
1670 ; GCN-IR-NEXT: v_xor_b32_e32 v1, v1, v12
1671 ; GCN-IR-NEXT: v_sub_i32_e32 v0, vcc, v0, v12
1672 ; GCN-IR-NEXT: v_subb_u32_e32 v1, vcc, v1, v12, vcc
1673 ; GCN-IR-NEXT: v_ffbh_u32_e32 v2, v0
1674 ; GCN-IR-NEXT: v_add_i32_e32 v2, vcc, 32, v2
1675 ; GCN-IR-NEXT: v_ffbh_u32_e32 v3, v1
1676 ; GCN-IR-NEXT: v_min_u32_e32 v10, v2, v3
1677 ; GCN-IR-NEXT: s_movk_i32 s6, 0xffd0
1678 ; GCN-IR-NEXT: v_add_i32_e32 v2, vcc, s6, v10
1679 ; GCN-IR-NEXT: v_addc_u32_e64 v3, s[6:7], 0, -1, vcc
1680 ; GCN-IR-NEXT: v_cmp_eq_u64_e64 s[4:5], 0, v[0:1]
1681 ; GCN-IR-NEXT: v_cmp_lt_u64_e32 vcc, 63, v[2:3]
1682 ; GCN-IR-NEXT: v_cmp_ne_u64_e64 s[6:7], 63, v[2:3]
1683 ; GCN-IR-NEXT: v_mov_b32_e32 v4, 0x8000
1684 ; GCN-IR-NEXT: s_or_b64 s[4:5], s[4:5], vcc
1685 ; GCN-IR-NEXT: v_cndmask_b32_e64 v4, v4, 0, s[4:5]
1686 ; GCN-IR-NEXT: s_xor_b64 s[4:5], s[4:5], -1
1687 ; GCN-IR-NEXT: v_mov_b32_e32 v13, v12
1688 ; GCN-IR-NEXT: v_mov_b32_e32 v5, 0
1689 ; GCN-IR-NEXT: s_and_b64 s[4:5], s[4:5], s[6:7]
1690 ; GCN-IR-NEXT: s_and_saveexec_b64 s[6:7], s[4:5]
1691 ; GCN-IR-NEXT: s_cbranch_execz .LBB12_6
1692 ; GCN-IR-NEXT: ; %bb.1: ; %udiv-bb1
1693 ; GCN-IR-NEXT: v_add_i32_e32 v6, vcc, 1, v2
1694 ; GCN-IR-NEXT: v_sub_i32_e64 v2, s[4:5], 63, v2
1695 ; GCN-IR-NEXT: v_addc_u32_e32 v7, vcc, 0, v3, vcc
1696 ; GCN-IR-NEXT: s_mov_b64 s[4:5], 0x8000
1697 ; GCN-IR-NEXT: v_cmp_ne_u64_e32 vcc, 0, v[6:7]
1698 ; GCN-IR-NEXT: v_lshl_b64 v[2:3], s[4:5], v2
1699 ; GCN-IR-NEXT: v_mov_b32_e32 v4, 0
1700 ; GCN-IR-NEXT: v_mov_b32_e32 v5, 0
1701 ; GCN-IR-NEXT: s_and_saveexec_b64 s[8:9], vcc
1702 ; GCN-IR-NEXT: s_xor_b64 s[8:9], exec, s[8:9]
1703 ; GCN-IR-NEXT: s_cbranch_execz .LBB12_5
1704 ; GCN-IR-NEXT: ; %bb.2: ; %udiv-preheader
1705 ; GCN-IR-NEXT: v_add_i32_e32 v14, vcc, -1, v0
1706 ; GCN-IR-NEXT: v_addc_u32_e32 v15, vcc, -1, v1, vcc
1707 ; GCN-IR-NEXT: v_lshr_b64 v[8:9], s[4:5], v6
1708 ; GCN-IR-NEXT: v_sub_i32_e32 v6, vcc, 47, v10
1709 ; GCN-IR-NEXT: v_mov_b32_e32 v10, 0
1710 ; GCN-IR-NEXT: v_subb_u32_e64 v7, s[4:5], 0, 0, vcc
1711 ; GCN-IR-NEXT: s_mov_b64 s[10:11], 0
1712 ; GCN-IR-NEXT: v_mov_b32_e32 v11, 0
1713 ; GCN-IR-NEXT: v_mov_b32_e32 v5, 0
1714 ; GCN-IR-NEXT: .LBB12_3: ; %udiv-do-while
1715 ; GCN-IR-NEXT: ; =>This Inner Loop Header: Depth=1
1716 ; GCN-IR-NEXT: v_lshl_b64 v[8:9], v[8:9], 1
1717 ; GCN-IR-NEXT: v_lshrrev_b32_e32 v4, 31, v3
1718 ; GCN-IR-NEXT: v_or_b32_e32 v8, v8, v4
1719 ; GCN-IR-NEXT: v_lshl_b64 v[2:3], v[2:3], 1
1720 ; GCN-IR-NEXT: v_sub_i32_e32 v4, vcc, v14, v8
1721 ; GCN-IR-NEXT: v_subb_u32_e32 v4, vcc, v15, v9, vcc
1722 ; GCN-IR-NEXT: v_or_b32_e32 v2, v10, v2
1723 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v10, 31, v4
1724 ; GCN-IR-NEXT: v_add_i32_e32 v6, vcc, 1, v6
1725 ; GCN-IR-NEXT: v_or_b32_e32 v3, v11, v3
1726 ; GCN-IR-NEXT: v_and_b32_e32 v4, 1, v10
1727 ; GCN-IR-NEXT: v_and_b32_e32 v11, v10, v1
1728 ; GCN-IR-NEXT: v_and_b32_e32 v10, v10, v0
1729 ; GCN-IR-NEXT: v_addc_u32_e32 v7, vcc, 0, v7, vcc
1730 ; GCN-IR-NEXT: v_cmp_eq_u64_e32 vcc, 0, v[6:7]
1731 ; GCN-IR-NEXT: v_sub_i32_e64 v8, s[4:5], v8, v10
1732 ; GCN-IR-NEXT: v_subb_u32_e64 v9, s[4:5], v9, v11, s[4:5]
1733 ; GCN-IR-NEXT: v_mov_b32_e32 v11, v5
1734 ; GCN-IR-NEXT: s_or_b64 s[10:11], vcc, s[10:11]
1735 ; GCN-IR-NEXT: v_mov_b32_e32 v10, v4
1736 ; GCN-IR-NEXT: s_andn2_b64 exec, exec, s[10:11]
1737 ; GCN-IR-NEXT: s_cbranch_execnz .LBB12_3
1738 ; GCN-IR-NEXT: ; %bb.4: ; %Flow
1739 ; GCN-IR-NEXT: s_or_b64 exec, exec, s[10:11]
1740 ; GCN-IR-NEXT: .LBB12_5: ; %Flow4
1741 ; GCN-IR-NEXT: s_or_b64 exec, exec, s[8:9]
1742 ; GCN-IR-NEXT: v_lshl_b64 v[0:1], v[2:3], 1
1743 ; GCN-IR-NEXT: v_or_b32_e32 v5, v5, v1
1744 ; GCN-IR-NEXT: v_or_b32_e32 v4, v4, v0
1745 ; GCN-IR-NEXT: .LBB12_6: ; %Flow5
1746 ; GCN-IR-NEXT: s_or_b64 exec, exec, s[6:7]
1747 ; GCN-IR-NEXT: v_xor_b32_e32 v0, v4, v12
1748 ; GCN-IR-NEXT: v_xor_b32_e32 v1, v5, v13
1749 ; GCN-IR-NEXT: v_sub_i32_e32 v0, vcc, v0, v12
1750 ; GCN-IR-NEXT: v_subb_u32_e32 v1, vcc, v1, v13, vcc
1751 ; GCN-IR-NEXT: s_setpc_b64 s[30:31]
1752 %result = sdiv i64 32768, %x
1756 define i64 @v_test_sdiv_pow2_k_den_i64(i64 %x) {
1757 ; GCN-LABEL: v_test_sdiv_pow2_k_den_i64:
1759 ; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1760 ; GCN-NEXT: v_ashrrev_i32_e32 v2, 31, v1
1761 ; GCN-NEXT: v_lshrrev_b32_e32 v2, 17, v2
1762 ; GCN-NEXT: v_add_i32_e32 v0, vcc, v0, v2
1763 ; GCN-NEXT: v_addc_u32_e32 v1, vcc, 0, v1, vcc
1764 ; GCN-NEXT: v_ashr_i64 v[0:1], v[0:1], 15
1765 ; GCN-NEXT: s_setpc_b64 s[30:31]
1767 ; GCN-IR-LABEL: v_test_sdiv_pow2_k_den_i64:
1768 ; GCN-IR: ; %bb.0: ; %_udiv-special-cases
1769 ; GCN-IR-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1770 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v10, 31, v1
1771 ; GCN-IR-NEXT: v_xor_b32_e32 v0, v0, v10
1772 ; GCN-IR-NEXT: v_xor_b32_e32 v1, v1, v10
1773 ; GCN-IR-NEXT: v_sub_i32_e32 v4, vcc, v0, v10
1774 ; GCN-IR-NEXT: v_subb_u32_e32 v5, vcc, v1, v10, vcc
1775 ; GCN-IR-NEXT: v_ffbh_u32_e32 v0, v4
1776 ; GCN-IR-NEXT: v_add_i32_e64 v0, s[4:5], 32, v0
1777 ; GCN-IR-NEXT: v_ffbh_u32_e32 v1, v5
1778 ; GCN-IR-NEXT: v_min_u32_e32 v8, v0, v1
1779 ; GCN-IR-NEXT: v_sub_i32_e64 v0, s[4:5], 48, v8
1780 ; GCN-IR-NEXT: v_subb_u32_e64 v1, s[4:5], 0, 0, s[4:5]
1781 ; GCN-IR-NEXT: v_cmp_eq_u64_e32 vcc, 0, v[4:5]
1782 ; GCN-IR-NEXT: v_cmp_lt_u64_e64 s[4:5], 63, v[0:1]
1783 ; GCN-IR-NEXT: v_mov_b32_e32 v11, v10
1784 ; GCN-IR-NEXT: s_or_b64 s[4:5], vcc, s[4:5]
1785 ; GCN-IR-NEXT: v_cmp_ne_u64_e32 vcc, 63, v[0:1]
1786 ; GCN-IR-NEXT: s_xor_b64 s[6:7], s[4:5], -1
1787 ; GCN-IR-NEXT: v_cndmask_b32_e64 v3, v5, 0, s[4:5]
1788 ; GCN-IR-NEXT: v_cndmask_b32_e64 v2, v4, 0, s[4:5]
1789 ; GCN-IR-NEXT: s_and_b64 s[4:5], s[6:7], vcc
1790 ; GCN-IR-NEXT: s_and_saveexec_b64 s[6:7], s[4:5]
1791 ; GCN-IR-NEXT: s_cbranch_execz .LBB13_6
1792 ; GCN-IR-NEXT: ; %bb.1: ; %udiv-bb1
1793 ; GCN-IR-NEXT: v_add_i32_e32 v6, vcc, 1, v0
1794 ; GCN-IR-NEXT: v_addc_u32_e32 v7, vcc, 0, v1, vcc
1795 ; GCN-IR-NEXT: v_sub_i32_e64 v0, s[4:5], 63, v0
1796 ; GCN-IR-NEXT: v_cmp_ne_u64_e32 vcc, 0, v[6:7]
1797 ; GCN-IR-NEXT: v_lshl_b64 v[0:1], v[4:5], v0
1798 ; GCN-IR-NEXT: v_mov_b32_e32 v2, 0
1799 ; GCN-IR-NEXT: v_mov_b32_e32 v3, 0
1800 ; GCN-IR-NEXT: s_and_saveexec_b64 s[4:5], vcc
1801 ; GCN-IR-NEXT: s_xor_b64 s[8:9], exec, s[4:5]
1802 ; GCN-IR-NEXT: s_cbranch_execz .LBB13_5
1803 ; GCN-IR-NEXT: ; %bb.2: ; %udiv-preheader
1804 ; GCN-IR-NEXT: v_lshr_b64 v[6:7], v[4:5], v6
1805 ; GCN-IR-NEXT: v_add_i32_e32 v4, vcc, 0xffffffcf, v8
1806 ; GCN-IR-NEXT: v_mov_b32_e32 v8, 0
1807 ; GCN-IR-NEXT: v_addc_u32_e64 v5, s[4:5], 0, -1, vcc
1808 ; GCN-IR-NEXT: s_mov_b64 s[10:11], 0
1809 ; GCN-IR-NEXT: v_mov_b32_e32 v9, 0
1810 ; GCN-IR-NEXT: s_movk_i32 s12, 0x7fff
1811 ; GCN-IR-NEXT: v_mov_b32_e32 v3, 0
1812 ; GCN-IR-NEXT: .LBB13_3: ; %udiv-do-while
1813 ; GCN-IR-NEXT: ; =>This Inner Loop Header: Depth=1
1814 ; GCN-IR-NEXT: v_lshl_b64 v[6:7], v[6:7], 1
1815 ; GCN-IR-NEXT: v_lshrrev_b32_e32 v2, 31, v1
1816 ; GCN-IR-NEXT: v_or_b32_e32 v6, v6, v2
1817 ; GCN-IR-NEXT: v_sub_i32_e32 v2, vcc, s12, v6
1818 ; GCN-IR-NEXT: v_lshl_b64 v[0:1], v[0:1], 1
1819 ; GCN-IR-NEXT: v_subb_u32_e32 v2, vcc, 0, v7, vcc
1820 ; GCN-IR-NEXT: v_add_i32_e32 v4, vcc, 1, v4
1821 ; GCN-IR-NEXT: v_or_b32_e32 v0, v8, v0
1822 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v8, 31, v2
1823 ; GCN-IR-NEXT: v_addc_u32_e32 v5, vcc, 0, v5, vcc
1824 ; GCN-IR-NEXT: v_and_b32_e32 v2, 1, v8
1825 ; GCN-IR-NEXT: v_and_b32_e32 v8, 0x8000, v8
1826 ; GCN-IR-NEXT: v_cmp_eq_u64_e32 vcc, 0, v[4:5]
1827 ; GCN-IR-NEXT: v_or_b32_e32 v1, v9, v1
1828 ; GCN-IR-NEXT: v_sub_i32_e64 v6, s[4:5], v6, v8
1829 ; GCN-IR-NEXT: v_mov_b32_e32 v9, v3
1830 ; GCN-IR-NEXT: v_subbrev_u32_e64 v7, s[4:5], 0, v7, s[4:5]
1831 ; GCN-IR-NEXT: s_or_b64 s[10:11], vcc, s[10:11]
1832 ; GCN-IR-NEXT: v_mov_b32_e32 v8, v2
1833 ; GCN-IR-NEXT: s_andn2_b64 exec, exec, s[10:11]
1834 ; GCN-IR-NEXT: s_cbranch_execnz .LBB13_3
1835 ; GCN-IR-NEXT: ; %bb.4: ; %Flow
1836 ; GCN-IR-NEXT: s_or_b64 exec, exec, s[10:11]
1837 ; GCN-IR-NEXT: .LBB13_5: ; %Flow4
1838 ; GCN-IR-NEXT: s_or_b64 exec, exec, s[8:9]
1839 ; GCN-IR-NEXT: v_lshl_b64 v[0:1], v[0:1], 1
1840 ; GCN-IR-NEXT: v_or_b32_e32 v3, v3, v1
1841 ; GCN-IR-NEXT: v_or_b32_e32 v2, v2, v0
1842 ; GCN-IR-NEXT: .LBB13_6: ; %Flow5
1843 ; GCN-IR-NEXT: s_or_b64 exec, exec, s[6:7]
1844 ; GCN-IR-NEXT: v_xor_b32_e32 v0, v2, v10
1845 ; GCN-IR-NEXT: v_xor_b32_e32 v1, v3, v11
1846 ; GCN-IR-NEXT: v_sub_i32_e32 v0, vcc, v0, v10
1847 ; GCN-IR-NEXT: v_subb_u32_e32 v1, vcc, v1, v11, vcc
1848 ; GCN-IR-NEXT: s_setpc_b64 s[30:31]
1849 %result = sdiv i64 %x, 32768
1853 define amdgpu_kernel void @s_test_sdiv24_k_num_i64(ptr addrspace(1) %out, i64 %x) {
1854 ; GCN-LABEL: s_test_sdiv24_k_num_i64:
1856 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0x9
1857 ; GCN-NEXT: s_mov_b32 s7, 0xf000
1858 ; GCN-NEXT: s_mov_b32 s6, -1
1859 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
1860 ; GCN-NEXT: s_ashr_i64 s[2:3], s[2:3], 40
1861 ; GCN-NEXT: v_cvt_f32_i32_e32 v0, s2
1862 ; GCN-NEXT: s_mov_b32 s3, 0x41c00000
1863 ; GCN-NEXT: s_mov_b32 s4, s0
1864 ; GCN-NEXT: s_ashr_i32 s0, s2, 30
1865 ; GCN-NEXT: v_rcp_iflag_f32_e32 v1, v0
1866 ; GCN-NEXT: s_mov_b32 s5, s1
1867 ; GCN-NEXT: s_or_b32 s2, s0, 1
1868 ; GCN-NEXT: v_mul_f32_e32 v1, 0x41c00000, v1
1869 ; GCN-NEXT: v_trunc_f32_e32 v1, v1
1870 ; GCN-NEXT: v_mad_f32 v2, -v1, v0, s3
1871 ; GCN-NEXT: v_cvt_i32_f32_e32 v1, v1
1872 ; GCN-NEXT: v_cmp_ge_f32_e64 s[0:1], |v2|, |v0|
1873 ; GCN-NEXT: s_and_b64 s[0:1], s[0:1], exec
1874 ; GCN-NEXT: s_cselect_b32 s0, s2, 0
1875 ; GCN-NEXT: v_add_i32_e32 v0, vcc, s0, v1
1876 ; GCN-NEXT: v_bfe_i32 v0, v0, 0, 24
1877 ; GCN-NEXT: v_ashrrev_i32_e32 v1, 31, v0
1878 ; GCN-NEXT: buffer_store_dwordx2 v[0:1], off, s[4:7], 0
1879 ; GCN-NEXT: s_endpgm
1881 ; GCN-IR-LABEL: s_test_sdiv24_k_num_i64:
1883 ; GCN-IR-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0x9
1884 ; GCN-IR-NEXT: s_mov_b32 s7, 0xf000
1885 ; GCN-IR-NEXT: s_mov_b32 s6, -1
1886 ; GCN-IR-NEXT: s_waitcnt lgkmcnt(0)
1887 ; GCN-IR-NEXT: s_ashr_i64 s[2:3], s[2:3], 40
1888 ; GCN-IR-NEXT: v_cvt_f32_i32_e32 v0, s2
1889 ; GCN-IR-NEXT: s_mov_b32 s3, 0x41c00000
1890 ; GCN-IR-NEXT: s_mov_b32 s4, s0
1891 ; GCN-IR-NEXT: s_ashr_i32 s0, s2, 30
1892 ; GCN-IR-NEXT: v_rcp_iflag_f32_e32 v1, v0
1893 ; GCN-IR-NEXT: s_mov_b32 s5, s1
1894 ; GCN-IR-NEXT: s_or_b32 s2, s0, 1
1895 ; GCN-IR-NEXT: v_mul_f32_e32 v1, 0x41c00000, v1
1896 ; GCN-IR-NEXT: v_trunc_f32_e32 v1, v1
1897 ; GCN-IR-NEXT: v_mad_f32 v2, -v1, v0, s3
1898 ; GCN-IR-NEXT: v_cvt_i32_f32_e32 v1, v1
1899 ; GCN-IR-NEXT: v_cmp_ge_f32_e64 s[0:1], |v2|, |v0|
1900 ; GCN-IR-NEXT: s_and_b64 s[0:1], s[0:1], exec
1901 ; GCN-IR-NEXT: s_cselect_b32 s0, s2, 0
1902 ; GCN-IR-NEXT: v_add_i32_e32 v0, vcc, s0, v1
1903 ; GCN-IR-NEXT: v_bfe_i32 v0, v0, 0, 24
1904 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v1, 31, v0
1905 ; GCN-IR-NEXT: buffer_store_dwordx2 v[0:1], off, s[4:7], 0
1906 ; GCN-IR-NEXT: s_endpgm
1907 %x.shr = ashr i64 %x, 40
1908 %result = sdiv i64 24, %x.shr
1909 store i64 %result, ptr addrspace(1) %out
1913 define amdgpu_kernel void @s_test_sdiv24_k_den_i64(ptr addrspace(1) %out, i64 %x) {
1914 ; GCN-LABEL: s_test_sdiv24_k_den_i64:
1916 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0x9
1917 ; GCN-NEXT: s_mov_b32 s8, 0x46b6fe00
1918 ; GCN-NEXT: s_mov_b32 s7, 0xf000
1919 ; GCN-NEXT: s_mov_b32 s6, -1
1920 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
1921 ; GCN-NEXT: s_ashr_i64 s[2:3], s[2:3], 40
1922 ; GCN-NEXT: v_cvt_f32_i32_e32 v0, s2
1923 ; GCN-NEXT: s_mov_b32 s4, s0
1924 ; GCN-NEXT: s_ashr_i32 s0, s2, 30
1925 ; GCN-NEXT: s_mov_b32 s5, s1
1926 ; GCN-NEXT: v_mul_f32_e32 v1, 0x38331158, v0
1927 ; GCN-NEXT: v_trunc_f32_e32 v1, v1
1928 ; GCN-NEXT: v_mad_f32 v0, -v1, s8, v0
1929 ; GCN-NEXT: v_cvt_i32_f32_e32 v1, v1
1930 ; GCN-NEXT: s_or_b32 s2, s0, 1
1931 ; GCN-NEXT: v_cmp_ge_f32_e64 s[0:1], |v0|, s8
1932 ; GCN-NEXT: s_and_b64 s[0:1], s[0:1], exec
1933 ; GCN-NEXT: s_cselect_b32 s0, s2, 0
1934 ; GCN-NEXT: v_add_i32_e32 v0, vcc, s0, v1
1935 ; GCN-NEXT: v_bfe_i32 v0, v0, 0, 24
1936 ; GCN-NEXT: v_ashrrev_i32_e32 v1, 31, v0
1937 ; GCN-NEXT: buffer_store_dwordx2 v[0:1], off, s[4:7], 0
1938 ; GCN-NEXT: s_endpgm
1940 ; GCN-IR-LABEL: s_test_sdiv24_k_den_i64:
1942 ; GCN-IR-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0x9
1943 ; GCN-IR-NEXT: s_mov_b32 s8, 0x46b6fe00
1944 ; GCN-IR-NEXT: s_mov_b32 s7, 0xf000
1945 ; GCN-IR-NEXT: s_mov_b32 s6, -1
1946 ; GCN-IR-NEXT: s_waitcnt lgkmcnt(0)
1947 ; GCN-IR-NEXT: s_ashr_i64 s[2:3], s[2:3], 40
1948 ; GCN-IR-NEXT: v_cvt_f32_i32_e32 v0, s2
1949 ; GCN-IR-NEXT: s_mov_b32 s4, s0
1950 ; GCN-IR-NEXT: s_ashr_i32 s0, s2, 30
1951 ; GCN-IR-NEXT: s_mov_b32 s5, s1
1952 ; GCN-IR-NEXT: v_mul_f32_e32 v1, 0x38331158, v0
1953 ; GCN-IR-NEXT: v_trunc_f32_e32 v1, v1
1954 ; GCN-IR-NEXT: v_mad_f32 v0, -v1, s8, v0
1955 ; GCN-IR-NEXT: v_cvt_i32_f32_e32 v1, v1
1956 ; GCN-IR-NEXT: s_or_b32 s2, s0, 1
1957 ; GCN-IR-NEXT: v_cmp_ge_f32_e64 s[0:1], |v0|, s8
1958 ; GCN-IR-NEXT: s_and_b64 s[0:1], s[0:1], exec
1959 ; GCN-IR-NEXT: s_cselect_b32 s0, s2, 0
1960 ; GCN-IR-NEXT: v_add_i32_e32 v0, vcc, s0, v1
1961 ; GCN-IR-NEXT: v_bfe_i32 v0, v0, 0, 24
1962 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v1, 31, v0
1963 ; GCN-IR-NEXT: buffer_store_dwordx2 v[0:1], off, s[4:7], 0
1964 ; GCN-IR-NEXT: s_endpgm
1965 %x.shr = ashr i64 %x, 40
1966 %result = sdiv i64 %x.shr, 23423
1967 store i64 %result, ptr addrspace(1) %out
1971 define i64 @v_test_sdiv24_k_num_i64(i64 %x) {
1972 ; GCN-LABEL: v_test_sdiv24_k_num_i64:
1974 ; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1975 ; GCN-NEXT: v_ashr_i64 v[0:1], v[0:1], 40
1976 ; GCN-NEXT: s_mov_b32 s4, 0x41c00000
1977 ; GCN-NEXT: v_cvt_f32_i32_e32 v1, v0
1978 ; GCN-NEXT: v_ashrrev_i32_e32 v0, 30, v0
1979 ; GCN-NEXT: v_or_b32_e32 v0, 1, v0
1980 ; GCN-NEXT: v_rcp_iflag_f32_e32 v2, v1
1981 ; GCN-NEXT: v_mul_f32_e32 v2, 0x41c00000, v2
1982 ; GCN-NEXT: v_trunc_f32_e32 v2, v2
1983 ; GCN-NEXT: v_mad_f32 v3, -v2, v1, s4
1984 ; GCN-NEXT: v_cvt_i32_f32_e32 v2, v2
1985 ; GCN-NEXT: v_cmp_ge_f32_e64 vcc, |v3|, |v1|
1986 ; GCN-NEXT: v_cndmask_b32_e32 v0, 0, v0, vcc
1987 ; GCN-NEXT: v_add_i32_e32 v0, vcc, v2, v0
1988 ; GCN-NEXT: v_bfe_i32 v0, v0, 0, 24
1989 ; GCN-NEXT: v_ashrrev_i32_e32 v1, 31, v0
1990 ; GCN-NEXT: s_setpc_b64 s[30:31]
1992 ; GCN-IR-LABEL: v_test_sdiv24_k_num_i64:
1994 ; GCN-IR-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1995 ; GCN-IR-NEXT: v_ashr_i64 v[0:1], v[0:1], 40
1996 ; GCN-IR-NEXT: s_mov_b32 s4, 0x41c00000
1997 ; GCN-IR-NEXT: v_cvt_f32_i32_e32 v1, v0
1998 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v0, 30, v0
1999 ; GCN-IR-NEXT: v_or_b32_e32 v0, 1, v0
2000 ; GCN-IR-NEXT: v_rcp_iflag_f32_e32 v2, v1
2001 ; GCN-IR-NEXT: v_mul_f32_e32 v2, 0x41c00000, v2
2002 ; GCN-IR-NEXT: v_trunc_f32_e32 v2, v2
2003 ; GCN-IR-NEXT: v_mad_f32 v3, -v2, v1, s4
2004 ; GCN-IR-NEXT: v_cvt_i32_f32_e32 v2, v2
2005 ; GCN-IR-NEXT: v_cmp_ge_f32_e64 vcc, |v3|, |v1|
2006 ; GCN-IR-NEXT: v_cndmask_b32_e32 v0, 0, v0, vcc
2007 ; GCN-IR-NEXT: v_add_i32_e32 v0, vcc, v2, v0
2008 ; GCN-IR-NEXT: v_bfe_i32 v0, v0, 0, 24
2009 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v1, 31, v0
2010 ; GCN-IR-NEXT: s_setpc_b64 s[30:31]
2011 %x.shr = ashr i64 %x, 40
2012 %result = sdiv i64 24, %x.shr
2016 define i64 @v_test_sdiv24_pow2_k_num_i64(i64 %x) {
2017 ; GCN-LABEL: v_test_sdiv24_pow2_k_num_i64:
2019 ; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2020 ; GCN-NEXT: v_ashr_i64 v[0:1], v[0:1], 40
2021 ; GCN-NEXT: s_mov_b32 s4, 0x47000000
2022 ; GCN-NEXT: v_cvt_f32_i32_e32 v1, v0
2023 ; GCN-NEXT: v_ashrrev_i32_e32 v0, 30, v0
2024 ; GCN-NEXT: v_or_b32_e32 v0, 1, v0
2025 ; GCN-NEXT: v_rcp_iflag_f32_e32 v2, v1
2026 ; GCN-NEXT: v_mul_f32_e32 v2, 0x47000000, v2
2027 ; GCN-NEXT: v_trunc_f32_e32 v2, v2
2028 ; GCN-NEXT: v_mad_f32 v3, -v2, v1, s4
2029 ; GCN-NEXT: v_cvt_i32_f32_e32 v2, v2
2030 ; GCN-NEXT: v_cmp_ge_f32_e64 vcc, |v3|, |v1|
2031 ; GCN-NEXT: v_cndmask_b32_e32 v0, 0, v0, vcc
2032 ; GCN-NEXT: v_add_i32_e32 v0, vcc, v2, v0
2033 ; GCN-NEXT: v_bfe_i32 v0, v0, 0, 24
2034 ; GCN-NEXT: v_ashrrev_i32_e32 v1, 31, v0
2035 ; GCN-NEXT: s_setpc_b64 s[30:31]
2037 ; GCN-IR-LABEL: v_test_sdiv24_pow2_k_num_i64:
2039 ; GCN-IR-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2040 ; GCN-IR-NEXT: v_ashr_i64 v[0:1], v[0:1], 40
2041 ; GCN-IR-NEXT: s_mov_b32 s4, 0x47000000
2042 ; GCN-IR-NEXT: v_cvt_f32_i32_e32 v1, v0
2043 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v0, 30, v0
2044 ; GCN-IR-NEXT: v_or_b32_e32 v0, 1, v0
2045 ; GCN-IR-NEXT: v_rcp_iflag_f32_e32 v2, v1
2046 ; GCN-IR-NEXT: v_mul_f32_e32 v2, 0x47000000, v2
2047 ; GCN-IR-NEXT: v_trunc_f32_e32 v2, v2
2048 ; GCN-IR-NEXT: v_mad_f32 v3, -v2, v1, s4
2049 ; GCN-IR-NEXT: v_cvt_i32_f32_e32 v2, v2
2050 ; GCN-IR-NEXT: v_cmp_ge_f32_e64 vcc, |v3|, |v1|
2051 ; GCN-IR-NEXT: v_cndmask_b32_e32 v0, 0, v0, vcc
2052 ; GCN-IR-NEXT: v_add_i32_e32 v0, vcc, v2, v0
2053 ; GCN-IR-NEXT: v_bfe_i32 v0, v0, 0, 24
2054 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v1, 31, v0
2055 ; GCN-IR-NEXT: s_setpc_b64 s[30:31]
2056 %x.shr = ashr i64 %x, 40
2057 %result = sdiv i64 32768, %x.shr
2061 define i64 @v_test_sdiv24_pow2_k_den_i64(i64 %x) {
2062 ; GCN-LABEL: v_test_sdiv24_pow2_k_den_i64:
2064 ; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2065 ; GCN-NEXT: v_ashr_i64 v[0:1], v[0:1], 40
2066 ; GCN-NEXT: v_lshrrev_b32_e32 v2, 17, v1
2067 ; GCN-NEXT: v_add_i32_e32 v0, vcc, v0, v2
2068 ; GCN-NEXT: v_addc_u32_e32 v1, vcc, 0, v1, vcc
2069 ; GCN-NEXT: v_ashr_i64 v[0:1], v[0:1], 15
2070 ; GCN-NEXT: s_setpc_b64 s[30:31]
2072 ; GCN-IR-LABEL: v_test_sdiv24_pow2_k_den_i64:
2074 ; GCN-IR-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2075 ; GCN-IR-NEXT: v_ashr_i64 v[0:1], v[0:1], 40
2076 ; GCN-IR-NEXT: s_mov_b32 s4, 0x47000000
2077 ; GCN-IR-NEXT: v_cvt_f32_i32_e32 v1, v0
2078 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v0, 30, v0
2079 ; GCN-IR-NEXT: v_or_b32_e32 v0, 1, v0
2080 ; GCN-IR-NEXT: v_mul_f32_e32 v2, 0x38000000, v1
2081 ; GCN-IR-NEXT: v_trunc_f32_e32 v2, v2
2082 ; GCN-IR-NEXT: v_mad_f32 v1, -v2, s4, v1
2083 ; GCN-IR-NEXT: v_cvt_i32_f32_e32 v2, v2
2084 ; GCN-IR-NEXT: v_cmp_ge_f32_e64 vcc, |v1|, s4
2085 ; GCN-IR-NEXT: v_cndmask_b32_e32 v0, 0, v0, vcc
2086 ; GCN-IR-NEXT: v_add_i32_e32 v0, vcc, v2, v0
2087 ; GCN-IR-NEXT: v_bfe_i32 v0, v0, 0, 24
2088 ; GCN-IR-NEXT: v_ashrrev_i32_e32 v1, 31, v0
2089 ; GCN-IR-NEXT: s_setpc_b64 s[30:31]
2090 %x.shr = ashr i64 %x, 40
2091 %result = sdiv i64 %x.shr, 32768