1 ; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck -check-prefix=GCN %s
2 ; RUN: llc -march=amdgcn -mcpu=gfx902 -verify-machineinstrs < %s | FileCheck -check-prefix=GFX9 %s
4 ; GCN-LABEL: {{^}}add1:
5 ; GCN: v_cmp_gt_u32_e{{32|64}} [[CC:[^,]+]], v{{[0-9]+}}, v{{[0-9]+}}
6 ; GCN: v_addc_u32_e{{32|64}} v{{[0-9]+}}, {{[^,]+}}, 0, v{{[0-9]+}}, [[CC]]
9 ; GFX9-LABEL: {{^}}add1:
10 ; GFX9: v_addc_co_u32_e{{32|64}} v{{[0-9]+}}, vcc
11 define amdgpu_kernel void @add1(i32 addrspace(1)* nocapture %arg) {
13 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
14 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
15 %gep = getelementptr inbounds i32, i32 addrspace(1)* %arg, i32 %x
16 %v = load i32, i32 addrspace(1)* %gep, align 4
17 %cmp = icmp ugt i32 %x, %y
18 %ext = zext i1 %cmp to i32
19 %add = add i32 %v, %ext
20 store i32 %add, i32 addrspace(1)* %gep, align 4
24 ; GCN-LABEL: {{^}}add1_i16:
25 ; GCN: v_cmp_gt_u32_e{{32|64}} [[CC:[^,]+]], v{{[0-9]+}}, v{{[0-9]+}}
26 ; GCN: v_addc_u32_e{{32|64}} v{{[0-9]+}}, {{[^,]+}}, 0, v{{[0-9]+}}, [[CC]]
29 ; GFX9-LABEL: {{^}}add1_i16:
30 ; GFX9: v_addc_co_u32_e{{32|64}} v{{[0-9]+}}, vcc
31 define i16 @add1_i16(i32 addrspace(1)* nocapture %arg, i16 addrspace(1)* nocapture %dst) {
33 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
34 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
35 %gep = getelementptr inbounds i32, i32 addrspace(1)* %arg, i32 %x
36 %v = load i32, i32 addrspace(1)* %gep, align 4
37 %cmp = icmp ugt i32 %x, %y
38 %ext = zext i1 %cmp to i32
39 %add = add i32 %v, %ext
40 %trunc = trunc i32 %add to i16
44 ; GCN-LABEL: {{^}}sub1:
45 ; GCN: v_cmp_gt_u32_e32 vcc, v{{[0-9]+}}, v{{[0-9]+}}
46 ; GCN: v_subbrev_u32_e32 v{{[0-9]+}}, vcc, 0, v{{[0-9]+}}, vcc
49 ; GFX9-LABEL: {{^}}sub1:
50 ; GFX9: v_subbrev_co_u32_e{{32|64}} v{{[0-9]+}}, vcc
51 define amdgpu_kernel void @sub1(i32 addrspace(1)* nocapture %arg) {
53 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
54 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
55 %gep = getelementptr inbounds i32, i32 addrspace(1)* %arg, i32 %x
56 %v = load i32, i32 addrspace(1)* %gep, align 4
57 %cmp = icmp ugt i32 %x, %y
58 %ext = sext i1 %cmp to i32
59 %add = add i32 %v, %ext
60 store i32 %add, i32 addrspace(1)* %gep, align 4
64 ; GCN-LABEL: {{^}}add_adde:
65 ; GCN: v_cmp_gt_u32_e{{32|64}} [[CC:[^,]+]], v{{[0-9]+}}, v{{[0-9]+}}
66 ; GCN: v_addc_u32_e{{32|64}} v{{[0-9]+}}, {{[^,]+}}, v{{[0-9]+}}, v{{[0-9]+}}, [[CC]]
70 ; GFX9-LABEL: {{^}}add_adde:
71 ; GFX9: v_addc_co_u32_e{{32|64}} v{{[0-9]+}}, vcc
72 define amdgpu_kernel void @add_adde(i32 addrspace(1)* nocapture %arg, i32 %a) {
74 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
75 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
76 %gep = getelementptr inbounds i32, i32 addrspace(1)* %arg, i32 %x
77 %v = load i32, i32 addrspace(1)* %gep, align 4
78 %cmp = icmp ugt i32 %x, %y
79 %ext = zext i1 %cmp to i32
80 %adde = add i32 %v, %ext
81 %add2 = add i32 %adde, %a
82 store i32 %add2, i32 addrspace(1)* %gep, align 4
86 ; GCN-LABEL: {{^}}adde_add:
87 ; GCN: v_cmp_gt_u32_e{{32|64}} [[CC:[^,]+]], v{{[0-9]+}}, v{{[0-9]+}}
88 ; GCN: v_addc_u32_e{{32|64}} v{{[0-9]+}}, {{[^,]+}}, v{{[0-9]+}}, v{{[0-9]+}}, [[CC]]
92 ; GFX9-LABEL: {{^}}adde_add:
93 ; GFX9: v_addc_co_u32_e{{32|64}} v{{[0-9]+}}, vcc
94 define amdgpu_kernel void @adde_add(i32 addrspace(1)* nocapture %arg, i32 %a) {
96 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
97 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
98 %gep = getelementptr inbounds i32, i32 addrspace(1)* %arg, i32 %x
99 %v = load i32, i32 addrspace(1)* %gep, align 4
100 %cmp = icmp ugt i32 %x, %y
101 %ext = zext i1 %cmp to i32
102 %add = add i32 %v, %a
103 %adde = add i32 %add, %ext
104 store i32 %adde, i32 addrspace(1)* %gep, align 4
108 ; GCN-LABEL: {{^}}sub_sube:
109 ; GCN: v_cmp_gt_u32_e{{32|64}} [[CC:[^,]+]], v{{[0-9]+}}, v{{[0-9]+}}
110 ; GCN: v_subb_u32_e{{32|64}} v{{[0-9]+}}, {{[^,]+}}, v{{[0-9]+}}, v{{[0-9]+}}, [[CC]]
114 ; GFX9-LABEL: {{^}}sub_sube:
115 ; GFX9: v_subb_co_u32_e{{32|64}} v{{[0-9]+}}, vcc
116 define amdgpu_kernel void @sub_sube(i32 addrspace(1)* nocapture %arg, i32 %a) {
118 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
119 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
120 %gep = getelementptr inbounds i32, i32 addrspace(1)* %arg, i32 %x
121 %v = load i32, i32 addrspace(1)* %gep, align 4
122 %cmp = icmp ugt i32 %x, %y
123 %ext = sext i1 %cmp to i32
124 %adde = add i32 %v, %ext
125 %sub = sub i32 %adde, %a
126 store i32 %sub, i32 addrspace(1)* %gep, align 4
130 ; GCN-LABEL: {{^}}sub_sube_commuted:
131 ; GCN-DAG: v_cmp_gt_u32_e{{32|64}} [[CC:[^,]+]], v{{[0-9]+}}, v{{[0-9]+}}
132 ; GCN-DAG: buffer_load_dword [[V:v[0-9]+]],
133 ; GCN: v_subbrev_u32_e{{32|64}} [[SUBB:v[0-9]+]], {{[^,]+}}, 0, [[V]], [[CC]]
134 ; GCN: v_sub_i32_e32 [[SUB:v[0-9]+]], vcc, s{{[0-9]+}}, [[SUBB]]
135 ; GCN: v_add_i32_e32 {{.*}}, 0x64, [[SUB]]
137 ; GFX9-LABEL: {{^}}sub_sube_commuted:
138 ; GFX9-DAG: v_cmp_gt_u32_e{{32|64}} [[CC:[^,]+]], v{{[0-9]+}}, v{{[0-9]+}}
139 ; GFX9-DAG: global_load_dword [[V:v[0-9]+]],
140 ; GFX9: v_subbrev_co_u32_e{{32|64}} [[SUBB:v[0-9]+]], {{[^,]+}}, 0, [[V]], [[CC]]
141 ; GFX9: v_sub_u32_e32 [[SUB:v[0-9]+]], s{{[0-9]+}}, [[SUBB]]
142 ; GFX9: v_add_u32_e32 {{.*}}, 0x64, [[SUB]]
143 define amdgpu_kernel void @sub_sube_commuted(i32 addrspace(1)* nocapture %arg, i32 %a) {
145 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
146 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
147 %gep = getelementptr inbounds i32, i32 addrspace(1)* %arg, i32 %x
148 %v = load i32, i32 addrspace(1)* %gep, align 4
149 %cmp = icmp ugt i32 %x, %y
150 %ext = sext i1 %cmp to i32
151 %adde = add i32 %v, %ext
152 %sub = sub i32 %adde, %a
153 %sub2 = sub i32 100, %sub
154 store i32 %sub2, i32 addrspace(1)* %gep, align 4
158 ; GCN-LABEL: {{^}}sube_sub:
159 ; GCN: v_cmp_gt_u32_e{{32|64}} [[CC:[^,]+]], v{{[0-9]+}}, v{{[0-9]+}}
160 ; GCN: v_subb_u32_e{{32|64}} v{{[0-9]+}}, {{[^,]+}}, v{{[0-9]+}}, v{{[0-9]+}}, [[CC]]
164 ; GFX9-LABEL: {{^}}sube_sub:
165 ; GFX9: v_subb_co_u32_e{{32|64}} v{{[0-9]+}}, vcc
166 define amdgpu_kernel void @sube_sub(i32 addrspace(1)* nocapture %arg, i32 %a) {
168 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
169 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
170 %gep = getelementptr inbounds i32, i32 addrspace(1)* %arg, i32 %x
171 %v = load i32, i32 addrspace(1)* %gep, align 4
172 %cmp = icmp ugt i32 %x, %y
173 %ext = sext i1 %cmp to i32
174 %sub = sub i32 %v, %a
175 %adde = add i32 %sub, %ext
176 store i32 %adde, i32 addrspace(1)* %gep, align 4
180 ; GCN-LABEL: {{^}}zext_flclass:
181 ; GCN: v_cmp_class_f32_e{{32|64}} [[CC:[^,]+]],
182 ; GCN: v_addc_u32_e{{32|64}} v{{[0-9]+}}, {{[^,]+}}, 0, v{{[0-9]+}}, [[CC]]
185 ; GFX9-LABEL: {{^}}zext_flclass:
186 ; GFX9: v_addc_co_u32_e{{32|64}} v{{[0-9]+}}, vcc
187 define amdgpu_kernel void @zext_flclass(i32 addrspace(1)* nocapture %arg, float %x) {
189 %id = tail call i32 @llvm.amdgcn.workitem.id.x()
190 %gep = getelementptr inbounds i32, i32 addrspace(1)* %arg, i32 %id
191 %v = load i32, i32 addrspace(1)* %gep, align 4
192 %cmp = tail call zeroext i1 @llvm.amdgcn.class.f32(float %x, i32 608)
193 %ext = zext i1 %cmp to i32
194 %add = add i32 %v, %ext
195 store i32 %add, i32 addrspace(1)* %gep, align 4
199 ; GCN-LABEL: {{^}}sext_flclass:
200 ; GCN: v_cmp_class_f32_e32 vcc,
201 ; GCN: v_subbrev_u32_e32 v{{[0-9]+}}, vcc, 0, v{{[0-9]+}}, vcc
204 ; GFX9-LABEL: {{^}}sext_flclass:
205 ; GFX9: v_subbrev_co_u32_e32 v{{[0-9]+}}, vcc
206 define amdgpu_kernel void @sext_flclass(i32 addrspace(1)* nocapture %arg, float %x) {
208 %id = tail call i32 @llvm.amdgcn.workitem.id.x()
209 %gep = getelementptr inbounds i32, i32 addrspace(1)* %arg, i32 %id
210 %v = load i32, i32 addrspace(1)* %gep, align 4
211 %cmp = tail call zeroext i1 @llvm.amdgcn.class.f32(float %x, i32 608)
212 %ext = sext i1 %cmp to i32
213 %add = add i32 %v, %ext
214 store i32 %add, i32 addrspace(1)* %gep, align 4
218 ; GCN-LABEL: {{^}}add_and:
219 ; GCN: s_and_b64 [[CC:[^,]+]],
220 ; GCN: v_addc_u32_e{{32|64}} v{{[0-9]+}}, {{[^,]+}}, 0, v{{[0-9]+}}, [[CC]]
223 ; GFX9-LABEL: {{^}}add_and:
224 ; GFX9: v_addc_co_u32_e{{32|64}} v{{[0-9]+}}, vcc
225 define amdgpu_kernel void @add_and(i32 addrspace(1)* nocapture %arg) {
227 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
228 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
229 %gep = getelementptr inbounds i32, i32 addrspace(1)* %arg, i32 %x
230 %v = load i32, i32 addrspace(1)* %gep, align 4
231 %cmp1 = icmp ugt i32 %x, %y
232 %cmp2 = icmp ugt i32 %x, 1
233 %cmp = and i1 %cmp1, %cmp2
234 %ext = zext i1 %cmp to i32
235 %add = add i32 %v, %ext
236 store i32 %add, i32 addrspace(1)* %gep, align 4
240 declare i1 @llvm.amdgcn.class.f32(float, i32) #0
242 declare i32 @llvm.amdgcn.workitem.id.x() #0
244 declare i32 @llvm.amdgcn.workitem.id.y() #0
246 attributes #0 = { nounwind readnone speculatable }