1 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=verde -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,SI %s
2 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=fiji -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,VI,GFX89 %s
3 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=gfx900 -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,GFX9,GFX89 %s
5 declare i32 @llvm.amdgcn.workitem.id.x() nounwind readnone speculatable
7 ; GCN-LABEL: {{^}}s_sub_i32:
8 ; GCN: s_load_dwordx4 s[[[#LOAD:]]:{{[0-9]+}}]
9 ; GCN: s_sub_i32 s{{[0-9]+}}, s[[#LOAD + 2]], s[[#LOAD + 3]]
10 define amdgpu_kernel void @s_sub_i32(i32 addrspace(1)* %out, i32 %a, i32 %b) {
11 %result = sub i32 %a, %b
12 store i32 %result, i32 addrspace(1)* %out
16 ; GCN-LABEL: {{^}}s_sub_imm_i32:
17 ; GCN: s_load_dword [[A:s[0-9]+]]
18 ; GCN: s_sub_i32 s{{[0-9]+}}, 0x4d2, [[A]]
19 define amdgpu_kernel void @s_sub_imm_i32(i32 addrspace(1)* %out, i32 %a) {
20 %result = sub i32 1234, %a
21 store i32 %result, i32 addrspace(1)* %out
25 ; GCN-LABEL: {{^}}test_sub_i32:
26 ; SI: v_subrev_i32_e32 v{{[0-9]+, vcc, v[0-9]+, v[0-9]+}}
27 ; GFX9: v_sub_u32_e32 v{{[0-9]+, v[0-9]+, v[0-9]+}}
28 define amdgpu_kernel void @test_sub_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in) {
29 %b_ptr = getelementptr i32, i32 addrspace(1)* %in, i32 1
30 %a = load i32, i32 addrspace(1)* %in
31 %b = load i32, i32 addrspace(1)* %b_ptr
32 %result = sub i32 %a, %b
33 store i32 %result, i32 addrspace(1)* %out
37 ; GCN-LABEL: {{^}}test_sub_imm_i32:
38 ; SI: v_sub_i32_e32 v{{[0-9]+}}, vcc, 0x7b, v{{[0-9]+}}
39 ; GFX9: v_sub_u32_e32 v{{[0-9]+}}, 0x7b, v{{[0-9]+}}
40 define amdgpu_kernel void @test_sub_imm_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in) {
41 %a = load i32, i32 addrspace(1)* %in
42 %result = sub i32 123, %a
43 store i32 %result, i32 addrspace(1)* %out
47 ; GCN-LABEL: {{^}}test_sub_v2i32:
48 ; SI: v_sub_i32_e32 v{{[0-9]+, vcc, v[0-9]+, v[0-9]+}}
49 ; SI: v_subrev_i32_e32 v{{[0-9]+, vcc, v[0-9]+, v[0-9]+}}
51 ; GFX9: v_sub_u32_e32 v{{[0-9]+, v[0-9]+, v[0-9]+}}
52 ; GFX9: v_sub_u32_e32 v{{[0-9]+, v[0-9]+, v[0-9]+}}
53 define amdgpu_kernel void @test_sub_v2i32(<2 x i32> addrspace(1)* %out, <2 x i32> addrspace(1)* %in) {
54 %b_ptr = getelementptr <2 x i32>, <2 x i32> addrspace(1)* %in, i32 1
55 %a = load <2 x i32>, <2 x i32> addrspace(1) * %in
56 %b = load <2 x i32>, <2 x i32> addrspace(1) * %b_ptr
57 %result = sub <2 x i32> %a, %b
58 store <2 x i32> %result, <2 x i32> addrspace(1)* %out
62 ; GCN-LABEL: {{^}}test_sub_v4i32:
63 ; SI: v_subrev_i32_e32 v{{[0-9]+, vcc, v[0-9]+, v[0-9]+}}
64 ; SI: v_sub_i32_e32 v{{[0-9]+, vcc, v[0-9]+, v[0-9]+}}
65 ; SI: v_sub_i32_e32 v{{[0-9]+, vcc, v[0-9]+, v[0-9]+}}
66 ; SI: v_sub_i32_e32 v{{[0-9]+, vcc, v[0-9]+, v[0-9]+}}
68 ; GFX9: v_sub_u32_e32 v{{[0-9]+, v[0-9]+, v[0-9]+}}
69 ; GFX9: v_sub_u32_e32 v{{[0-9]+, v[0-9]+, v[0-9]+}}
70 ; GFX9: v_sub_u32_e32 v{{[0-9]+, v[0-9]+, v[0-9]+}}
71 ; GFX9: v_sub_u32_e32 v{{[0-9]+, v[0-9]+, v[0-9]+}}
72 define amdgpu_kernel void @test_sub_v4i32(<4 x i32> addrspace(1)* %out, <4 x i32> addrspace(1)* %in) {
73 %b_ptr = getelementptr <4 x i32>, <4 x i32> addrspace(1)* %in, i32 1
74 %a = load <4 x i32>, <4 x i32> addrspace(1) * %in
75 %b = load <4 x i32>, <4 x i32> addrspace(1) * %b_ptr
76 %result = sub <4 x i32> %a, %b
77 store <4 x i32> %result, <4 x i32> addrspace(1)* %out
81 ; GCN-LABEL: {{^}}test_sub_i16:
82 ; SI: v_sub_i32_e32 v{{[0-9]+}}, vcc,
83 ; GFX89: v_sub_u16_e32 v{{[0-9]+, v[0-9]+, v[0-9]+}}
84 define amdgpu_kernel void @test_sub_i16(i16 addrspace(1)* %out, i16 addrspace(1)* %in) {
85 %tid = call i32 @llvm.amdgcn.workitem.id.x()
86 %gep = getelementptr i16, i16 addrspace(1)* %in, i32 %tid
87 %b_ptr = getelementptr i16, i16 addrspace(1)* %gep, i32 1
88 %a = load volatile i16, i16 addrspace(1)* %gep
89 %b = load volatile i16, i16 addrspace(1)* %b_ptr
90 %result = sub i16 %a, %b
91 store i16 %result, i16 addrspace(1)* %out
95 ; GCN-LABEL: {{^}}test_sub_v2i16:
96 ; VI: v_sub_u16_e32 v{{[0-9]+, v[0-9]+, v[0-9]+}}
97 ; VI: v_sub_u16_sdwa v{{[0-9]+, v[0-9]+, v[0-9]+}}
100 define amdgpu_kernel void @test_sub_v2i16(<2 x i16> addrspace(1)* %out, <2 x i16> addrspace(1)* %in) {
101 %tid = call i32 @llvm.amdgcn.workitem.id.x()
102 %gep = getelementptr <2 x i16>, <2 x i16> addrspace(1)* %in, i32 %tid
103 %b_ptr = getelementptr <2 x i16>, <2 x i16> addrspace(1)* %gep, i16 1
104 %a = load <2 x i16>, <2 x i16> addrspace(1)* %gep
105 %b = load <2 x i16>, <2 x i16> addrspace(1)* %b_ptr
106 %result = sub <2 x i16> %a, %b
107 store <2 x i16> %result, <2 x i16> addrspace(1)* %out
111 ; GCN-LABEL: {{^}}test_sub_v4i16:
112 ; VI: v_sub_u16_e32 v{{[0-9]+, v[0-9]+, v[0-9]+}}
113 ; VI: v_sub_u16_sdwa v{{[0-9]+, v[0-9]+, v[0-9]+}}
114 ; VI: v_sub_u16_e32 v{{[0-9]+, v[0-9]+, v[0-9]+}}
115 ; VI: v_sub_u16_sdwa v{{[0-9]+, v[0-9]+, v[0-9]+}}
119 define amdgpu_kernel void @test_sub_v4i16(<4 x i16> addrspace(1)* %out, <4 x i16> addrspace(1)* %in) {
120 %tid = call i32 @llvm.amdgcn.workitem.id.x()
121 %gep = getelementptr <4 x i16>, <4 x i16> addrspace(1)* %in, i32 %tid
122 %b_ptr = getelementptr <4 x i16>, <4 x i16> addrspace(1)* %gep, i16 1
123 %a = load <4 x i16>, <4 x i16> addrspace(1) * %gep
124 %b = load <4 x i16>, <4 x i16> addrspace(1) * %b_ptr
125 %result = sub <4 x i16> %a, %b
126 store <4 x i16> %result, <4 x i16> addrspace(1)* %out
130 ; GCN-LABEL: {{^}}s_sub_i64:
133 define amdgpu_kernel void @s_sub_i64(i64 addrspace(1)* noalias %out, i64 %a, i64 %b) nounwind {
134 %result = sub i64 %a, %b
135 store i64 %result, i64 addrspace(1)* %out, align 8
139 ; GCN-LABEL: {{^}}v_sub_i64:
146 ; GFX9: v_sub_co_u32_e32
147 ; GFX9: v_subb_co_u32_e32
148 define amdgpu_kernel void @v_sub_i64(i64 addrspace(1)* noalias %out, i64 addrspace(1)* noalias %inA, i64 addrspace(1)* noalias %inB) nounwind {
149 %tid = call i32 @llvm.amdgcn.workitem.id.x() readnone
150 %a_ptr = getelementptr i64, i64 addrspace(1)* %inA, i32 %tid
151 %b_ptr = getelementptr i64, i64 addrspace(1)* %inB, i32 %tid
152 %a = load i64, i64 addrspace(1)* %a_ptr
153 %b = load i64, i64 addrspace(1)* %b_ptr
154 %result = sub i64 %a, %b
155 store i64 %result, i64 addrspace(1)* %out, align 8
159 ; GCN-LABEL: {{^}}v_test_sub_v2i64:
160 ; SI: v_sub_i32_e32 v{{[0-9]+}}, vcc,
161 ; SI: v_subb_u32_e32 v{{[0-9]+}}, vcc,
162 ; SI: v_sub_i32_e32 v{{[0-9]+}}, vcc,
163 ; SI: v_subb_u32_e32 v{{[0-9]+}}, vcc,
165 ; VI: v_sub_u32_e32 v{{[0-9]+}}, vcc,
166 ; VI: v_subb_u32_e32 v{{[0-9]+}}, vcc,
167 ; VI: v_sub_u32_e32 v{{[0-9]+}}, vcc,
168 ; VI: v_subb_u32_e32 v{{[0-9]+}}, vcc,
170 ; GFX9: v_sub_co_u32_e32 v{{[0-9]+}}, vcc,
171 ; GFX9: v_subb_co_u32_e32 v{{[0-9]+}}, vcc,
172 ; GFX9: v_sub_co_u32_e32 v{{[0-9]+}}, vcc,
173 ; GFX9: v_subb_co_u32_e32 v{{[0-9]+}}, vcc,
174 define amdgpu_kernel void @v_test_sub_v2i64(<2 x i64> addrspace(1)* %out, <2 x i64> addrspace(1)* noalias %inA, <2 x i64> addrspace(1)* noalias %inB) {
175 %tid = call i32 @llvm.amdgcn.workitem.id.x() readnone
176 %a_ptr = getelementptr <2 x i64>, <2 x i64> addrspace(1)* %inA, i32 %tid
177 %b_ptr = getelementptr <2 x i64>, <2 x i64> addrspace(1)* %inB, i32 %tid
178 %a = load <2 x i64>, <2 x i64> addrspace(1)* %a_ptr
179 %b = load <2 x i64>, <2 x i64> addrspace(1)* %b_ptr
180 %result = sub <2 x i64> %a, %b
181 store <2 x i64> %result, <2 x i64> addrspace(1)* %out
185 ; GCN-LABEL: {{^}}v_test_sub_v4i64:
186 ; SI: v_sub_i32_e32 v{{[0-9]+}}, vcc,
187 ; SI: v_subb_u32_e32 v{{[0-9]+}}, vcc,
188 ; SI: v_sub_i32_e32 v{{[0-9]+}}, vcc,
189 ; SI: v_subb_u32_e32 v{{[0-9]+}}, vcc,
190 ; SI: v_sub_i32_e32 v{{[0-9]+}}, vcc,
191 ; SI: v_subb_u32_e32 v{{[0-9]+}}, vcc,
192 ; SI: v_sub_i32_e32 v{{[0-9]+}}, vcc,
193 ; SI: v_subb_u32_e32 v{{[0-9]+}}, vcc,
195 ; VI: v_sub_u32_e32 v{{[0-9]+}}, vcc,
196 ; VI: v_subb_u32_e32 v{{[0-9]+}}, vcc,
197 ; VI: v_sub_u32_e32 v{{[0-9]+}}, vcc,
198 ; VI: v_subb_u32_e32 v{{[0-9]+}}, vcc,
199 ; VI: v_sub_u32_e32 v{{[0-9]+}}, vcc,
200 ; VI: v_subb_u32_e32 v{{[0-9]+}}, vcc,
201 ; VI: v_sub_u32_e32 v{{[0-9]+}}, vcc,
202 ; VI: v_subb_u32_e32 v{{[0-9]+}}, vcc,
204 ; GFX9: v_sub_co_u32_e32 v{{[0-9]+}}, vcc,
205 ; GFX9: v_subb_co_u32_e32 v{{[0-9]+}}, vcc,
206 ; GFX9: v_sub_co_u32_e32 v{{[0-9]+}}, vcc,
207 ; GFX9: v_subb_co_u32_e32 v{{[0-9]+}}, vcc,
208 ; GFX9: v_sub_co_u32_e32 v{{[0-9]+}}, vcc,
209 ; GFX9: v_subb_co_u32_e32 v{{[0-9]+}}, vcc,
210 ; GFX9: v_sub_co_u32_e32 v{{[0-9]+}}, vcc,
211 ; GFX9: v_subb_co_u32_e32 v{{[0-9]+}}, vcc,
212 define amdgpu_kernel void @v_test_sub_v4i64(<4 x i64> addrspace(1)* %out, <4 x i64> addrspace(1)* noalias %inA, <4 x i64> addrspace(1)* noalias %inB) {
213 %tid = call i32 @llvm.amdgcn.workitem.id.x() readnone
214 %a_ptr = getelementptr <4 x i64>, <4 x i64> addrspace(1)* %inA, i32 %tid
215 %b_ptr = getelementptr <4 x i64>, <4 x i64> addrspace(1)* %inB, i32 %tid
216 %a = load <4 x i64>, <4 x i64> addrspace(1)* %a_ptr
217 %b = load <4 x i64>, <4 x i64> addrspace(1)* %b_ptr
218 %result = sub <4 x i64> %a, %b
219 store <4 x i64> %result, <4 x i64> addrspace(1)* %out
223 ; Make sure the VOP3 form of sub is initially selected. Otherwise pair
224 ; of opies from/to VCC would be necessary
226 ; GCN-LABEL: {{^}}sub_select_vop3:
227 ; SI: v_subrev_i32_e64 v0, s[0:1], s0, v0
228 ; VI: v_subrev_u32_e64 v0, s[0:1], s0, v0
229 ; GFX9: v_subrev_u32_e32 v0, s0, v0
234 define amdgpu_ps void @sub_select_vop3(i32 inreg %s, i32 %v) {
235 %vcc = call i64 asm sideeffect "; def vcc", "={vcc}"()
236 %sub = sub i32 %v, %s
237 store i32 %sub, i32 addrspace(3)* undef
238 call void asm sideeffect "; use vcc", "{vcc}"(i64 %vcc)