1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
2 ; RUN: llc -march=amdgcn -mcpu=gfx1100 -amdgpu-enable-delay-alu=0 -mattr=+wavefrontsize32,-wavefrontsize64 -global-isel=1 -verify-machineinstrs < %s | FileCheck -check-prefixes=GFX11,GISEL %s
3 ; RUN: llc -march=amdgcn -mcpu=gfx1100 -amdgpu-enable-delay-alu=0 -mattr=+wavefrontsize32,-wavefrontsize64 -global-isel=0 -verify-machineinstrs < %s | FileCheck -check-prefixes=GFX11,SDAG %s
5 declare i1 @llvm.amdgcn.inverse.ballot(i32)
8 define amdgpu_cs void @constant_false_inverse_ballot(ptr addrspace(1) %out) {
9 ; GFX11-LABEL: constant_false_inverse_ballot:
10 ; GFX11: ; %bb.0: ; %entry
11 ; GFX11-NEXT: s_mov_b32 s0, 0
12 ; GFX11-NEXT: v_cndmask_b32_e64 v2, 0, 1, s0
13 ; GFX11-NEXT: global_store_b32 v[0:1], v2, off
15 ; GFX11-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
16 ; GFX11-NEXT: s_endpgm
18 %ballot = call i1 @llvm.amdgcn.inverse.ballot(i32 0)
19 %sel = select i1 %ballot, i32 1, i32 0
20 store i32 %sel, ptr addrspace(1) %out
26 define amdgpu_cs void @constant_true_inverse_ballot(ptr addrspace(1) %out) {
27 ; GFX11-LABEL: constant_true_inverse_ballot:
28 ; GFX11: ; %bb.0: ; %entry
29 ; GFX11-NEXT: s_mov_b32 s0, -1
30 ; GFX11-NEXT: v_cndmask_b32_e64 v2, 0, 1, s0
31 ; GFX11-NEXT: global_store_b32 v[0:1], v2, off
33 ; GFX11-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
34 ; GFX11-NEXT: s_endpgm
36 %ballot = call i1 @llvm.amdgcn.inverse.ballot(i32 u0xFFFFFFFF)
37 %sel = select i1 %ballot, i32 1, i32 0
38 store i32 %sel, ptr addrspace(1) %out
42 define amdgpu_cs void @constant_mask_inverse_ballot(ptr addrspace(1) %out) {
43 ; GFX11-LABEL: constant_mask_inverse_ballot:
44 ; GFX11: ; %bb.0: ; %entry
45 ; GFX11-NEXT: s_movk_i32 s0, 0x1000
46 ; GFX11-NEXT: v_cndmask_b32_e64 v2, 0, 1, s0
47 ; GFX11-NEXT: global_store_b32 v[0:1], v2, off
49 ; GFX11-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
50 ; GFX11-NEXT: s_endpgm
52 %ballot = call i1 @llvm.amdgcn.inverse.ballot(i32 u0x00001000)
53 %sel = select i1 %ballot, i32 1, i32 0
54 store i32 %sel, ptr addrspace(1) %out
58 ; Test inverse ballot using a vgpr as input
60 define amdgpu_cs void @vgpr_inverse_ballot(i32 %input, ptr addrspace(1) %out) {
61 ; GFX11-LABEL: vgpr_inverse_ballot:
62 ; GFX11: ; %bb.0: ; %entry
63 ; GFX11-NEXT: v_readfirstlane_b32 s0, v0
64 ; GFX11-NEXT: v_cndmask_b32_e64 v0, 0, 1, s0
65 ; GFX11-NEXT: global_store_b32 v[1:2], v0, off
67 ; GFX11-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
68 ; GFX11-NEXT: s_endpgm
70 %ballot = call i1 @llvm.amdgcn.inverse.ballot(i32 %input)
71 %sel = select i1 %ballot, i32 1, i32 0
72 store i32 %sel, ptr addrspace(1) %out
76 define amdgpu_cs void @sgpr_inverse_ballot(i32 inreg %input, ptr addrspace(1) %out) {
77 ; GFX11-LABEL: sgpr_inverse_ballot:
78 ; GFX11: ; %bb.0: ; %entry
79 ; GFX11-NEXT: v_cndmask_b32_e64 v2, 0, 1, s0
80 ; GFX11-NEXT: global_store_b32 v[0:1], v2, off
82 ; GFX11-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
83 ; GFX11-NEXT: s_endpgm
85 %ballot = call i1 @llvm.amdgcn.inverse.ballot(i32 %input)
86 %sel = select i1 %ballot, i32 1, i32 0
87 store i32 %sel, ptr addrspace(1) %out
91 ; Test ballot after phi
92 define amdgpu_cs void @phi_uniform(i32 inreg %s0_1, i32 inreg %s2, ptr addrspace(1) %out) {
93 ; GFX11-LABEL: phi_uniform:
94 ; GFX11: ; %bb.0: ; %entry
95 ; GFX11-NEXT: s_cmp_lg_u32 s1, 0
96 ; GFX11-NEXT: s_cbranch_scc1 .LBB5_2
97 ; GFX11-NEXT: ; %bb.1: ; %if
98 ; GFX11-NEXT: s_add_i32 s0, s0, 1
99 ; GFX11-NEXT: .LBB5_2: ; %endif
100 ; GFX11-NEXT: v_cndmask_b32_e64 v2, 0, 1, s0
101 ; GFX11-NEXT: global_store_b32 v[0:1], v2, off
102 ; GFX11-NEXT: s_nop 0
103 ; GFX11-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
104 ; GFX11-NEXT: s_endpgm
106 %cc = icmp ne i32 %s2, 0
107 br i1 %cc, label %endif, label %if
110 %tmp = add i32 %s0_1, 1
114 %input = phi i32 [ %s0_1, %entry ], [ %tmp, %if ]
116 %ballot = call i1 @llvm.amdgcn.inverse.ballot(i32 %input)
117 %sel = select i1 %ballot, i32 1, i32 0
118 store i32 %sel, ptr addrspace(1) %out
123 ; GISel implementation is currently incorrect.
124 ; The change in the branch affects all lanes, not just the branching ones.
125 ; This test will be fixed once GISel correctly takes uniformity analysis into account.
126 define amdgpu_cs void @inverse_ballot_branch(i32 inreg %s0_1, i32 inreg %s2, ptr addrspace(1) %out) {
127 ; GISEL-LABEL: inverse_ballot_branch:
128 ; GISEL: ; %bb.0: ; %entry
129 ; GISEL-NEXT: s_xor_b32 s2, s1, -1
130 ; GISEL-NEXT: s_and_saveexec_b32 s1, s2
131 ; GISEL-NEXT: ; %bb.1: ; %if
132 ; GISEL-NEXT: s_add_i32 s0, s0, 1
133 ; GISEL-NEXT: ; %bb.2: ; %endif
134 ; GISEL-NEXT: s_or_b32 exec_lo, exec_lo, s1
135 ; GISEL-NEXT: v_mov_b32_e32 v2, s0
136 ; GISEL-NEXT: global_store_b32 v[0:1], v2, off
137 ; GISEL-NEXT: s_nop 0
138 ; GISEL-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
139 ; GISEL-NEXT: s_endpgm
141 ; SDAG-LABEL: inverse_ballot_branch:
142 ; SDAG: ; %bb.0: ; %entry
143 ; SDAG-NEXT: v_mov_b32_e32 v2, s0
144 ; SDAG-NEXT: s_xor_b32 s2, s1, -1
145 ; SDAG-NEXT: s_and_saveexec_b32 s1, s2
146 ; SDAG-NEXT: ; %bb.1: ; %if
147 ; SDAG-NEXT: s_add_i32 s0, s0, 1
148 ; SDAG-NEXT: v_mov_b32_e32 v2, s0
149 ; SDAG-NEXT: ; %bb.2: ; %endif
150 ; SDAG-NEXT: s_or_b32 exec_lo, exec_lo, s1
151 ; SDAG-NEXT: global_store_b32 v[0:1], v2, off
153 ; SDAG-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
154 ; SDAG-NEXT: s_endpgm
156 %ballot = call i1 @llvm.amdgcn.inverse.ballot(i32 %s2)
157 br i1 %ballot, label %endif, label %if
160 %tmp = add i32 %s0_1, 1
164 %input = phi i32 [ %s0_1, %entry ], [ %tmp, %if ]
165 store i32 %input, ptr addrspace(1) %out