1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -march=amdgcn -mcpu=tahiti -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=SI %s
4 ; Most SALU instructions ignore control flow, so we need to make sure
5 ; they don't overwrite values from other blocks.
7 ; If the branch decision is made based on a value in an SGPR then all
8 ; threads will execute the same code paths, so we don't need to worry
9 ; about instructions in different blocks overwriting each other.
11 define amdgpu_kernel void @sgpr_if_else_salu_br(ptr addrspace(1) %out, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
12 ; SI-LABEL: sgpr_if_else_salu_br:
13 ; SI: ; %bb.0: ; %entry
14 ; SI-NEXT: s_load_dwordx4 s[4:7], s[0:1], 0xb
15 ; SI-NEXT: s_load_dword s2, s[0:1], 0xf
16 ; SI-NEXT: s_waitcnt lgkmcnt(0)
17 ; SI-NEXT: s_cmp_lg_u32 s4, 0
18 ; SI-NEXT: s_cbranch_scc0 .LBB0_4
19 ; SI-NEXT: ; %bb.1: ; %else
20 ; SI-NEXT: s_add_i32 s7, s7, s2
21 ; SI-NEXT: s_cbranch_execnz .LBB0_3
22 ; SI-NEXT: .LBB0_2: ; %if
23 ; SI-NEXT: s_sub_i32 s7, s5, s6
24 ; SI-NEXT: .LBB0_3: ; %endif
25 ; SI-NEXT: s_load_dwordx2 s[0:1], s[0:1], 0x9
26 ; SI-NEXT: s_add_i32 s4, s7, s4
27 ; SI-NEXT: s_mov_b32 s3, 0xf000
28 ; SI-NEXT: s_mov_b32 s2, -1
29 ; SI-NEXT: v_mov_b32_e32 v0, s4
30 ; SI-NEXT: s_waitcnt lgkmcnt(0)
31 ; SI-NEXT: buffer_store_dword v0, off, s[0:3], 0
34 ; SI-NEXT: ; implicit-def: $sgpr7
35 ; SI-NEXT: s_branch .LBB0_2
38 %0 = icmp eq i32 %a, 0
39 br i1 %0, label %if, label %else
50 %3 = phi i32 [%1, %if], [%2, %else]
52 store i32 %4, ptr addrspace(1) %out
56 define amdgpu_kernel void @sgpr_if_else_salu_br_opt(ptr addrspace(1) %out, [8 x i32], i32 %a, [8 x i32], i32 %b, [8 x i32], i32 %c, [8 x i32], i32 %d, [8 x i32], i32 %e) {
57 ; SI-LABEL: sgpr_if_else_salu_br_opt:
58 ; SI: ; %bb.0: ; %entry
59 ; SI-NEXT: s_load_dword s4, s[0:1], 0x13
60 ; SI-NEXT: s_waitcnt lgkmcnt(0)
61 ; SI-NEXT: s_cmp_lg_u32 s4, 0
62 ; SI-NEXT: s_cbranch_scc0 .LBB1_4
63 ; SI-NEXT: ; %bb.1: ; %else
64 ; SI-NEXT: s_load_dword s2, s[0:1], 0x2e
65 ; SI-NEXT: s_load_dword s3, s[0:1], 0x37
66 ; SI-NEXT: s_waitcnt lgkmcnt(0)
67 ; SI-NEXT: s_add_i32 s5, s2, s3
68 ; SI-NEXT: s_cbranch_execnz .LBB1_3
69 ; SI-NEXT: .LBB1_2: ; %if
70 ; SI-NEXT: s_load_dword s2, s[0:1], 0x1c
71 ; SI-NEXT: s_load_dword s3, s[0:1], 0x25
72 ; SI-NEXT: s_waitcnt lgkmcnt(0)
73 ; SI-NEXT: s_add_i32 s5, s2, s3
74 ; SI-NEXT: .LBB1_3: ; %endif
75 ; SI-NEXT: s_load_dwordx2 s[0:1], s[0:1], 0x9
76 ; SI-NEXT: s_add_i32 s4, s5, s4
77 ; SI-NEXT: s_mov_b32 s3, 0xf000
78 ; SI-NEXT: s_mov_b32 s2, -1
79 ; SI-NEXT: v_mov_b32_e32 v0, s4
80 ; SI-NEXT: s_waitcnt lgkmcnt(0)
81 ; SI-NEXT: buffer_store_dword v0, off, s[0:3], 0
84 ; SI-NEXT: ; implicit-def: $sgpr5
85 ; SI-NEXT: s_branch .LBB1_2
88 %cmp0 = icmp eq i32 %a, 0
89 br i1 %cmp0, label %if, label %else
92 %add0 = add i32 %b, %c
96 %add1 = add i32 %d, %e
100 %phi = phi i32 [%add0, %if], [%add1, %else]
101 %add2 = add i32 %phi, %a
102 store i32 %add2, ptr addrspace(1) %out
106 ; The two S_ADD instructions should write to different registers, since
107 ; different threads will take different control flow paths.
108 define amdgpu_kernel void @sgpr_if_else_valu_br(ptr addrspace(1) %out, float %a, i32 %b, i32 %c, i32 %d, i32 %e) {
109 ; SI-LABEL: sgpr_if_else_valu_br:
110 ; SI: ; %bb.0: ; %entry
111 ; SI-NEXT: s_load_dwordx4 s[4:7], s[0:1], 0xc
112 ; SI-NEXT: v_cvt_f32_u32_e32 v0, v0
113 ; SI-NEXT: ; implicit-def: $sgpr8
114 ; SI-NEXT: v_cmp_lg_f32_e32 vcc, 0, v0
115 ; SI-NEXT: s_and_saveexec_b64 s[2:3], vcc
116 ; SI-NEXT: s_xor_b64 s[2:3], exec, s[2:3]
117 ; SI-NEXT: s_cbranch_execz .LBB2_2
118 ; SI-NEXT: ; %bb.1: ; %else
119 ; SI-NEXT: s_waitcnt lgkmcnt(0)
120 ; SI-NEXT: s_add_i32 s8, s6, s7
121 ; SI-NEXT: .LBB2_2: ; %Flow
122 ; SI-NEXT: s_or_saveexec_b64 s[2:3], s[2:3]
123 ; SI-NEXT: v_mov_b32_e32 v0, s8
124 ; SI-NEXT: s_xor_b64 exec, exec, s[2:3]
125 ; SI-NEXT: s_cbranch_execz .LBB2_4
126 ; SI-NEXT: ; %bb.3: ; %if
127 ; SI-NEXT: s_waitcnt lgkmcnt(0)
128 ; SI-NEXT: s_add_i32 s4, s4, s5
129 ; SI-NEXT: v_mov_b32_e32 v0, s4
130 ; SI-NEXT: .LBB2_4: ; %endif
131 ; SI-NEXT: s_or_b64 exec, exec, s[2:3]
132 ; SI-NEXT: s_load_dwordx2 s[0:1], s[0:1], 0x9
133 ; SI-NEXT: s_mov_b32 s3, 0xf000
134 ; SI-NEXT: s_mov_b32 s2, -1
135 ; SI-NEXT: s_waitcnt lgkmcnt(0)
136 ; SI-NEXT: buffer_store_dword v0, off, s[0:3], 0
139 %tid = call i32 @llvm.amdgcn.workitem.id.x() #0
140 %tid_f = uitofp i32 %tid to float
141 %tmp1 = fcmp ueq float %tid_f, 0.0
142 br i1 %tmp1, label %if, label %else
145 %tmp2 = add i32 %b, %c
149 %tmp3 = add i32 %d, %e
153 %tmp4 = phi i32 [%tmp2, %if], [%tmp3, %else]
154 store i32 %tmp4, ptr addrspace(1) %out
158 define amdgpu_kernel void @sgpr_if_else_valu_cmp_phi_br(ptr addrspace(1) %out, ptr addrspace(1) %a, ptr addrspace(1) %b) {
159 ; SI-LABEL: sgpr_if_else_valu_cmp_phi_br:
160 ; SI: ; %bb.0: ; %entry
161 ; SI-NEXT: s_load_dwordx4 s[4:7], s[0:1], 0x9
162 ; SI-NEXT: s_load_dwordx2 s[0:1], s[0:1], 0xd
163 ; SI-NEXT: s_mov_b32 s2, 0
164 ; SI-NEXT: v_cmp_ne_u32_e32 vcc, 0, v0
165 ; SI-NEXT: v_lshlrev_b32_e32 v0, 2, v0
166 ; SI-NEXT: ; implicit-def: $sgpr8_sgpr9
167 ; SI-NEXT: s_and_saveexec_b64 s[10:11], vcc
168 ; SI-NEXT: s_xor_b64 s[10:11], exec, s[10:11]
169 ; SI-NEXT: s_cbranch_execz .LBB3_2
170 ; SI-NEXT: ; %bb.1: ; %else
171 ; SI-NEXT: s_mov_b32 s3, 0xf000
172 ; SI-NEXT: v_mov_b32_e32 v1, 0
173 ; SI-NEXT: s_waitcnt lgkmcnt(0)
174 ; SI-NEXT: buffer_load_dword v0, v[0:1], s[0:3], 0 addr64
175 ; SI-NEXT: s_waitcnt vmcnt(0)
176 ; SI-NEXT: v_cmp_gt_i32_e32 vcc, 0, v0
177 ; SI-NEXT: s_and_b64 s[8:9], vcc, exec
178 ; SI-NEXT: ; implicit-def: $vgpr0
179 ; SI-NEXT: .LBB3_2: ; %Flow
180 ; SI-NEXT: s_waitcnt lgkmcnt(0)
181 ; SI-NEXT: s_andn2_saveexec_b64 s[0:1], s[10:11]
182 ; SI-NEXT: s_cbranch_execz .LBB3_4
183 ; SI-NEXT: ; %bb.3: ; %if
184 ; SI-NEXT: s_mov_b32 s15, 0xf000
185 ; SI-NEXT: s_mov_b32 s14, 0
186 ; SI-NEXT: s_mov_b64 s[12:13], s[6:7]
187 ; SI-NEXT: v_mov_b32_e32 v1, 0
188 ; SI-NEXT: buffer_load_dword v0, v[0:1], s[12:15], 0 addr64
189 ; SI-NEXT: s_andn2_b64 s[2:3], s[8:9], exec
190 ; SI-NEXT: s_waitcnt vmcnt(0)
191 ; SI-NEXT: v_cmp_eq_u32_e32 vcc, 0, v0
192 ; SI-NEXT: s_and_b64 s[6:7], vcc, exec
193 ; SI-NEXT: s_or_b64 s[8:9], s[2:3], s[6:7]
194 ; SI-NEXT: .LBB3_4: ; %endif
195 ; SI-NEXT: s_or_b64 exec, exec, s[0:1]
196 ; SI-NEXT: s_mov_b32 s7, 0xf000
197 ; SI-NEXT: s_mov_b32 s6, -1
198 ; SI-NEXT: v_cndmask_b32_e64 v0, 0, -1, s[8:9]
199 ; SI-NEXT: buffer_store_dword v0, off, s[4:7], 0
202 %tid = call i32 @llvm.amdgcn.workitem.id.x() #0
203 %tmp1 = icmp eq i32 %tid, 0
204 br i1 %tmp1, label %if, label %else
207 %gep.if = getelementptr i32, ptr addrspace(1) %a, i32 %tid
208 %a.val = load i32, ptr addrspace(1) %gep.if
209 %cmp.if = icmp eq i32 %a.val, 0
213 %gep.else = getelementptr i32, ptr addrspace(1) %b, i32 %tid
214 %b.val = load i32, ptr addrspace(1) %gep.else
215 %cmp.else = icmp slt i32 %b.val, 0
219 %tmp4 = phi i1 [%cmp.if, %if], [%cmp.else, %else]
220 %ext = sext i1 %tmp4 to i32
221 store i32 %ext, ptr addrspace(1) %out
225 declare i32 @llvm.amdgcn.workitem.id.x() #0
227 attributes #0 = { readnone }