1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
2 ; RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -amdgpu-enable-delay-alu=0 -mattr=+wavefrontsize64 -global-isel=1 -verify-machineinstrs < %s | FileCheck -check-prefixes=GISEL %s
3 ; RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -amdgpu-enable-delay-alu=0 -mattr=+wavefrontsize64 -global-isel=0 -verify-machineinstrs < %s | FileCheck -check-prefixes=SDAG %s
5 ; RUN: not --crash llc -mtriple=amdgcn -mcpu=gfx1100 -mattr=+wavefrontsize32 -global-isel=1 < %s 2>&1 | FileCheck -check-prefix=GISEL-ERR %s
6 ; RUN: not --crash llc -mtriple=amdgcn -mcpu=gfx1100 -mattr=+wavefrontsize32 -global-isel=0 < %s 2>&1 | FileCheck -check-prefix=SDAG-ERR %s
8 ; GISEL-ERR: LLVM ERROR: cannot select: {{.*}} = G_INTRINSIC intrinsic(@llvm.amdgcn.inverse.ballot)
9 ; SDAG-ERR: LLVM ERROR: Cannot select: intrinsic %llvm.amdgcn.inverse.ballot
11 declare i1 @llvm.amdgcn.inverse.ballot.i64(i64)
14 define amdgpu_cs void @constant_false_inverse_ballot(ptr addrspace(1) %out) {
15 ; GISEL-LABEL: constant_false_inverse_ballot:
16 ; GISEL: ; %bb.0: ; %entry
17 ; GISEL-NEXT: s_mov_b64 s[0:1], 0
18 ; GISEL-NEXT: v_mov_b32_e32 v3, 0
19 ; GISEL-NEXT: v_cndmask_b32_e64 v2, 0, 1, s[0:1]
20 ; GISEL-NEXT: global_store_b64 v[0:1], v[2:3], off
22 ; GISEL-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
23 ; GISEL-NEXT: s_endpgm
25 ; SDAG-LABEL: constant_false_inverse_ballot:
26 ; SDAG: ; %bb.0: ; %entry
27 ; SDAG-NEXT: s_mov_b32 s2, 0
28 ; SDAG-NEXT: s_mov_b64 s[0:1], 0
29 ; SDAG-NEXT: v_mov_b32_e32 v3, s2
30 ; SDAG-NEXT: v_cndmask_b32_e64 v2, 0, 1, s[0:1]
31 ; SDAG-NEXT: global_store_b64 v[0:1], v[2:3], off
33 ; SDAG-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
36 %ballot = call i1 @llvm.amdgcn.inverse.ballot.i64(i64 0)
37 %sel = select i1 %ballot, i64 1, i64 0
38 store i64 %sel, ptr addrspace(1) %out
44 define amdgpu_cs void @constant_true_inverse_ballot(ptr addrspace(1) %out) {
45 ; GISEL-LABEL: constant_true_inverse_ballot:
46 ; GISEL: ; %bb.0: ; %entry
47 ; GISEL-NEXT: s_mov_b64 s[0:1], -1
48 ; GISEL-NEXT: v_mov_b32_e32 v3, 0
49 ; GISEL-NEXT: v_cndmask_b32_e64 v2, 0, 1, s[0:1]
50 ; GISEL-NEXT: global_store_b64 v[0:1], v[2:3], off
52 ; GISEL-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
53 ; GISEL-NEXT: s_endpgm
55 ; SDAG-LABEL: constant_true_inverse_ballot:
56 ; SDAG: ; %bb.0: ; %entry
57 ; SDAG-NEXT: s_mov_b32 s2, 0
58 ; SDAG-NEXT: s_mov_b64 s[0:1], -1
59 ; SDAG-NEXT: v_mov_b32_e32 v3, s2
60 ; SDAG-NEXT: v_cndmask_b32_e64 v2, 0, 1, s[0:1]
61 ; SDAG-NEXT: global_store_b64 v[0:1], v[2:3], off
63 ; SDAG-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
66 %ballot = call i1 @llvm.amdgcn.inverse.ballot.i64(i64 u0xFFFFFFFFFFFFFFFF)
67 %sel = select i1 %ballot, i64 1, i64 0
68 store i64 %sel, ptr addrspace(1) %out
72 ; Test ballot(u0x0040F8010000)
74 define amdgpu_cs void @constant_mask_inverse_ballot(ptr addrspace(1) %out) {
75 ; GISEL-LABEL: constant_mask_inverse_ballot:
76 ; GISEL: ; %bb.0: ; %entry
77 ; GISEL-NEXT: s_mov_b32 s0, 0xf8010000
78 ; GISEL-NEXT: s_mov_b32 s1, 64
79 ; GISEL-NEXT: v_mov_b32_e32 v3, 0
80 ; GISEL-NEXT: v_cndmask_b32_e64 v2, 0, 1, s[0:1]
81 ; GISEL-NEXT: global_store_b64 v[0:1], v[2:3], off
83 ; GISEL-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
84 ; GISEL-NEXT: s_endpgm
86 ; SDAG-LABEL: constant_mask_inverse_ballot:
87 ; SDAG: ; %bb.0: ; %entry
88 ; SDAG-NEXT: s_mov_b32 s0, 0xf8010000
89 ; SDAG-NEXT: s_mov_b32 s2, 0
90 ; SDAG-NEXT: s_mov_b32 s1, 64
91 ; SDAG-NEXT: v_mov_b32_e32 v3, s2
92 ; SDAG-NEXT: v_cndmask_b32_e64 v2, 0, 1, s[0:1]
93 ; SDAG-NEXT: global_store_b64 v[0:1], v[2:3], off
95 ; SDAG-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
98 %ballot = call i1 @llvm.amdgcn.inverse.ballot.i64(i64 u0x0040F8010000)
99 %sel = select i1 %ballot, i64 1, i64 0
100 store i64 %sel, ptr addrspace(1) %out
104 ; Test inverse ballot using a vgpr as input
106 define amdgpu_cs void @vgpr_inverse_ballot(i64 %input, ptr addrspace(1) %out) {
107 ; GISEL-LABEL: vgpr_inverse_ballot:
108 ; GISEL: ; %bb.0: ; %entry
109 ; GISEL-NEXT: v_readfirstlane_b32 s0, v0
110 ; GISEL-NEXT: v_readfirstlane_b32 s1, v1
111 ; GISEL-NEXT: v_mov_b32_e32 v5, 0
112 ; GISEL-NEXT: v_cndmask_b32_e64 v4, 0, 1, s[0:1]
113 ; GISEL-NEXT: global_store_b64 v[2:3], v[4:5], off
114 ; GISEL-NEXT: s_nop 0
115 ; GISEL-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
116 ; GISEL-NEXT: s_endpgm
118 ; SDAG-LABEL: vgpr_inverse_ballot:
119 ; SDAG: ; %bb.0: ; %entry
120 ; SDAG-NEXT: v_readfirstlane_b32 s0, v0
121 ; SDAG-NEXT: v_readfirstlane_b32 s1, v1
122 ; SDAG-NEXT: s_mov_b32 s2, 0
123 ; SDAG-NEXT: v_mov_b32_e32 v1, s2
124 ; SDAG-NEXT: v_cndmask_b32_e64 v0, 0, 1, s[0:1]
125 ; SDAG-NEXT: global_store_b64 v[2:3], v[0:1], off
127 ; SDAG-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
128 ; SDAG-NEXT: s_endpgm
130 %ballot = call i1 @llvm.amdgcn.inverse.ballot.i64(i64 %input)
131 %sel = select i1 %ballot, i64 1, i64 0
132 store i64 %sel, ptr addrspace(1) %out
136 define amdgpu_cs void @sgpr_inverse_ballot(i64 inreg %input, ptr addrspace(1) %out) {
137 ; GISEL-LABEL: sgpr_inverse_ballot:
138 ; GISEL: ; %bb.0: ; %entry
139 ; GISEL-NEXT: v_cndmask_b32_e64 v2, 0, 1, s[0:1]
140 ; GISEL-NEXT: v_mov_b32_e32 v3, 0
141 ; GISEL-NEXT: global_store_b64 v[0:1], v[2:3], off
142 ; GISEL-NEXT: s_nop 0
143 ; GISEL-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
144 ; GISEL-NEXT: s_endpgm
146 ; SDAG-LABEL: sgpr_inverse_ballot:
147 ; SDAG: ; %bb.0: ; %entry
148 ; SDAG-NEXT: v_cndmask_b32_e64 v2, 0, 1, s[0:1]
149 ; SDAG-NEXT: s_mov_b32 s0, 0
150 ; SDAG-NEXT: s_waitcnt_depctr 0xfffe
151 ; SDAG-NEXT: v_mov_b32_e32 v3, s0
152 ; SDAG-NEXT: global_store_b64 v[0:1], v[2:3], off
154 ; SDAG-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
155 ; SDAG-NEXT: s_endpgm
157 %ballot = call i1 @llvm.amdgcn.inverse.ballot.i64(i64 %input)
158 %sel = select i1 %ballot, i64 1, i64 0
159 store i64 %sel, ptr addrspace(1) %out
163 ; Test ballot after phi
164 define amdgpu_cs void @phi_uniform(i64 inreg %s0_1, i64 inreg %s2, ptr addrspace(1) %out) {
165 ; GISEL-LABEL: phi_uniform:
166 ; GISEL: ; %bb.0: ; %entry
167 ; GISEL-NEXT: s_cmp_lg_u64 s[2:3], 0
168 ; GISEL-NEXT: s_cbranch_scc1 .LBB5_2
169 ; GISEL-NEXT: ; %bb.1: ; %if
170 ; GISEL-NEXT: s_add_u32 s0, s0, 1
171 ; GISEL-NEXT: s_addc_u32 s1, s1, 0
172 ; GISEL-NEXT: .LBB5_2: ; %endif
173 ; GISEL-NEXT: v_mov_b32_e32 v3, 0
174 ; GISEL-NEXT: v_cndmask_b32_e64 v2, 0, 1, s[0:1]
175 ; GISEL-NEXT: global_store_b64 v[0:1], v[2:3], off
176 ; GISEL-NEXT: s_nop 0
177 ; GISEL-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
178 ; GISEL-NEXT: s_endpgm
180 ; SDAG-LABEL: phi_uniform:
181 ; SDAG: ; %bb.0: ; %entry
182 ; SDAG-NEXT: s_cmp_lg_u64 s[2:3], 0
183 ; SDAG-NEXT: s_cbranch_scc1 .LBB5_2
184 ; SDAG-NEXT: ; %bb.1: ; %if
185 ; SDAG-NEXT: s_add_u32 s0, s0, 1
186 ; SDAG-NEXT: s_addc_u32 s1, s1, 0
187 ; SDAG-NEXT: .LBB5_2: ; %endif
188 ; SDAG-NEXT: s_mov_b32 s2, 0
189 ; SDAG-NEXT: v_cndmask_b32_e64 v2, 0, 1, s[0:1]
190 ; SDAG-NEXT: v_mov_b32_e32 v3, s2
191 ; SDAG-NEXT: global_store_b64 v[0:1], v[2:3], off
193 ; SDAG-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
194 ; SDAG-NEXT: s_endpgm
196 %cc = icmp ne i64 %s2, 0
197 br i1 %cc, label %endif, label %if
200 %tmp = add i64 %s0_1, 1
204 %input = phi i64 [ %s0_1, %entry ], [ %tmp, %if ]
206 %ballot = call i1 @llvm.amdgcn.inverse.ballot.i64(i64 %input)
207 %sel = select i1 %ballot, i64 1, i64 0
208 store i64 %sel, ptr addrspace(1) %out
213 ; GISel implementation is currently incorrect.
214 ; The change in the branch affects all lanes, not just the branching ones.
215 ; This test will be fixed once GISel correctly takes uniformity analysis into account.
216 define amdgpu_cs void @inverse_ballot_branch(i64 inreg %s0_1, i64 inreg %s2, ptr addrspace(1) %out) {
217 ; GISEL-LABEL: inverse_ballot_branch:
218 ; GISEL: ; %bb.0: ; %entry
219 ; GISEL-NEXT: s_xor_b64 s[4:5], s[2:3], -1
220 ; GISEL-NEXT: s_and_saveexec_b64 s[2:3], s[4:5]
221 ; GISEL-NEXT: ; %bb.1: ; %if
222 ; GISEL-NEXT: s_add_u32 s0, s0, 1
223 ; GISEL-NEXT: s_addc_u32 s1, s1, 0
224 ; GISEL-NEXT: ; %bb.2: ; %endif
225 ; GISEL-NEXT: s_or_b64 exec, exec, s[2:3]
226 ; GISEL-NEXT: v_mov_b32_e32 v3, s1
227 ; GISEL-NEXT: v_mov_b32_e32 v2, s0
228 ; GISEL-NEXT: global_store_b64 v[0:1], v[2:3], off
229 ; GISEL-NEXT: s_nop 0
230 ; GISEL-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
231 ; GISEL-NEXT: s_endpgm
233 ; SDAG-LABEL: inverse_ballot_branch:
234 ; SDAG: ; %bb.0: ; %entry
235 ; SDAG-NEXT: v_mov_b32_e32 v3, s1
236 ; SDAG-NEXT: v_mov_b32_e32 v2, s0
237 ; SDAG-NEXT: s_xor_b64 s[4:5], s[2:3], -1
238 ; SDAG-NEXT: s_and_saveexec_b64 s[2:3], s[4:5]
239 ; SDAG-NEXT: ; %bb.1: ; %if
240 ; SDAG-NEXT: s_add_u32 s0, s0, 1
241 ; SDAG-NEXT: s_addc_u32 s1, s1, 0
242 ; SDAG-NEXT: v_mov_b32_e32 v3, s1
243 ; SDAG-NEXT: v_mov_b32_e32 v2, s0
244 ; SDAG-NEXT: ; %bb.2: ; %endif
245 ; SDAG-NEXT: s_or_b64 exec, exec, s[2:3]
246 ; SDAG-NEXT: global_store_b64 v[0:1], v[2:3], off
248 ; SDAG-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
249 ; SDAG-NEXT: s_endpgm
251 %ballot = call i1 @llvm.amdgcn.inverse.ballot.i64(i64 %s2)
252 br i1 %ballot, label %endif, label %if
255 %tmp = add i64 %s0_1, 1
259 %sel = phi i64 [ %s0_1, %entry ], [ %tmp, %if ]
260 store i64 %sel, ptr addrspace(1) %out