1 ; RUN: llc -march=amdgcn -mcpu=tahiti -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,GFX6,GFX6_8_9,MAD %s
2 ; RUN: llc -march=amdgcn -mcpu=tonga -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,GFX8,GFX6_8_9,GFX8_9,GFX8_9_10,MAD %s
3 ; RUN: llc -march=amdgcn -mcpu=gfx900 -verify-machineinstrs -amdgpu-enable-global-sgpr-addr < %s | FileCheck -check-prefixes=GCN,GFX9,GFX6_8_9,GFX8_9,GFX8_9_10,MAD %s
4 ; RUN: llc -march=amdgcn -mcpu=gfx1010 -verify-machineinstrs -amdgpu-enable-global-sgpr-addr < %s | FileCheck -check-prefixes=GCN,GFX10,GFX8_9_10,MAD,GFX10-MAD %s
5 ; RUN: llc -march=amdgcn -mcpu=gfx1010 -verify-machineinstrs -fp-contract=fast -amdgpu-enable-global-sgpr-addr < %s | FileCheck -check-prefixes=GCN,GFX10,GFX8_9_10,FMA %s
7 declare i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
8 declare float @llvm.fabs.f32(float) nounwind readnone
10 ; GCN-LABEL: {{^}}madak_f32:
11 ; GFX6: buffer_load_dword [[VA:v[0-9]+]]
12 ; GFX6: buffer_load_dword [[VB:v[0-9]+]]
13 ; GFX8: {{flat|global}}_load_dword [[VB:v[0-9]+]]
14 ; GFX8: {{flat|global}}_load_dword [[VA:v[0-9]+]]
15 ; GFX9: {{flat|global}}_load_dword [[VA:v[0-9]+]]
16 ; GFX9: {{flat|global}}_load_dword [[VB:v[0-9]+]]
17 ; GFX10: {{flat|global}}_load_dword [[VA:v[0-9]+]]
18 ; GFX10: {{flat|global}}_load_dword [[VB:v[0-9]+]]
19 ; MAD: v_madak_f32 {{v[0-9]+}}, [[VA]], [[VB]], 0x41200000
20 ; FMA: v_fmaak_f32 {{v[0-9]+}}, [[VA]], [[VB]], 0x41200000
21 define amdgpu_kernel void @madak_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in.a, float addrspace(1)* noalias %in.b) nounwind {
22 %tid = tail call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
23 %in.a.gep = getelementptr float, float addrspace(1)* %in.a, i32 %tid
24 %in.b.gep = getelementptr float, float addrspace(1)* %in.b, i32 %tid
25 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid
27 %a = load float, float addrspace(1)* %in.a.gep, align 4
28 %b = load float, float addrspace(1)* %in.b.gep, align 4
30 %mul = fmul float %a, %b
31 %madak = fadd float %mul, 10.0
32 store float %madak, float addrspace(1)* %out.gep, align 4
36 ; Make sure this is only folded with one use. This is a code size
37 ; optimization and if we fold the immediate multiple times, we'll undo
40 ; GCN-LABEL: {{^}}madak_2_use_f32:
41 ; GFX8_9_10: v_mov_b32_e32 [[VK:v[0-9]+]], 0x41200000
42 ; GFX6-DAG: buffer_load_dword [[VA:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64{{$}}
43 ; GFX6-DAG: buffer_load_dword [[VB:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:4
44 ; GFX6-DAG: buffer_load_dword [[VC:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:8
45 ; GFX8_9_10: {{flat|global}}_load_dword [[VA:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}
46 ; GFX8_9_10: {{flat|global}}_load_dword [[VB:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}
47 ; GFX8_9_10: {{flat|global}}_load_dword [[VC:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}
48 ; GFX6-DAG: v_mov_b32_e32 [[VK:v[0-9]+]], 0x41200000
49 ; GFX6_8_9-DAG: v_madak_f32 {{v[0-9]+}}, [[VA]], [[VB]], 0x41200000
50 ; GFX10-MAD-DAG:v_madak_f32 {{v[0-9]+}}, [[VA]], [[VB]], 0x41200000
51 ; FMA-DAG: v_fmaak_f32 {{v[0-9]+}}, [[VA]], [[VB]], 0x41200000
52 ; MAD-DAG: v_mac_f32_e32 [[VK]], [[VA]], [[VC]]
53 ; FMA-DAG: v_fmac_f32_e32 [[VK]], [[VA]], [[VC]]
55 define amdgpu_kernel void @madak_2_use_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in) nounwind {
56 %tid = tail call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
58 %in.gep.0 = getelementptr float, float addrspace(1)* %in, i32 %tid
59 %in.gep.1 = getelementptr float, float addrspace(1)* %in.gep.0, i32 1
60 %in.gep.2 = getelementptr float, float addrspace(1)* %in.gep.0, i32 2
62 %out.gep.0 = getelementptr float, float addrspace(1)* %out, i32 %tid
63 %out.gep.1 = getelementptr float, float addrspace(1)* %in.gep.0, i32 1
65 %a = load volatile float, float addrspace(1)* %in.gep.0, align 4
66 %b = load volatile float, float addrspace(1)* %in.gep.1, align 4
67 %c = load volatile float, float addrspace(1)* %in.gep.2, align 4
69 %mul0 = fmul float %a, %b
70 %mul1 = fmul float %a, %c
71 %madak0 = fadd float %mul0, 10.0
72 %madak1 = fadd float %mul1, 10.0
74 store volatile float %madak0, float addrspace(1)* %out.gep.0, align 4
75 store volatile float %madak1, float addrspace(1)* %out.gep.1, align 4
79 ; GCN-LABEL: {{^}}madak_m_inline_imm_f32:
80 ; GCN: {{buffer|flat|global}}_load_dword [[VA:v[0-9]+]]
81 ; MAD: v_madak_f32 {{v[0-9]+}}, 4.0, [[VA]], 0x41200000
82 ; FMA: v_fmaak_f32 {{v[0-9]+}}, 4.0, [[VA]], 0x41200000
83 define amdgpu_kernel void @madak_m_inline_imm_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in.a) nounwind {
84 %tid = tail call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
85 %in.a.gep = getelementptr float, float addrspace(1)* %in.a, i32 %tid
86 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid
88 %a = load float, float addrspace(1)* %in.a.gep, align 4
90 %mul = fmul float 4.0, %a
91 %madak = fadd float %mul, 10.0
92 store float %madak, float addrspace(1)* %out.gep, align 4
96 ; Make sure nothing weird happens with a value that is also allowed as
97 ; an inline immediate.
99 ; GCN-LABEL: {{^}}madak_inline_imm_f32:
100 ; GFX6: buffer_load_dword [[VA:v[0-9]+]]
101 ; GFX6: buffer_load_dword [[VB:v[0-9]+]]
102 ; GFX8: {{flat|global}}_load_dword [[VB:v[0-9]+]]
103 ; GFX8: {{flat|global}}_load_dword [[VA:v[0-9]+]]
104 ; GFX9: {{flat|global}}_load_dword [[VA:v[0-9]+]]
105 ; GFX9: {{flat|global}}_load_dword [[VB:v[0-9]+]]
106 ; GFX10: {{flat|global}}_load_dword [[VA:v[0-9]+]]
107 ; GFX10: {{flat|global}}_load_dword [[VB:v[0-9]+]]
108 ; MAD: v_mad_f32 {{v[0-9]+}}, [[VA]], [[VB]], 4.0
109 ; FMA: v_fma_f32 {{v[0-9]+}}, [[VA]], [[VB]], 4.0
110 define amdgpu_kernel void @madak_inline_imm_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in.a, float addrspace(1)* noalias %in.b) nounwind {
111 %tid = tail call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
112 %in.a.gep = getelementptr float, float addrspace(1)* %in.a, i32 %tid
113 %in.b.gep = getelementptr float, float addrspace(1)* %in.b, i32 %tid
114 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid
116 %a = load float, float addrspace(1)* %in.a.gep, align 4
117 %b = load float, float addrspace(1)* %in.b.gep, align 4
119 %mul = fmul float %a, %b
120 %madak = fadd float %mul, 4.0
121 store float %madak, float addrspace(1)* %out.gep, align 4
125 ; We can't use an SGPR when forming madak
126 ; GCN-LABEL: {{^}}s_v_madak_f32:
127 ; GCN-DAG: s_load_dword [[SB:s[0-9]+]]
128 ; GFX6_8_9-DAG: v_mov_b32_e32 [[VK:v[0-9]+]], 0x41200000
129 ; GCN-DAG: {{buffer|flat|global}}_load_dword{{(_addtid)?}} [[VA:v[0-9]+]]
130 ; GCN-NOT: v_madak_f32
131 ; GFX6_8_9: v_mac_f32_e32 [[VK]], [[SB]], [[VA]]
132 ; GFX10-MAD: v_mad_f32 v{{[0-9]+}}, [[VA]], [[SB]], 0x41200000
133 ; FMA: v_fma_f32 v{{[0-9]+}}, [[VA]], [[SB]], 0x41200000
134 define amdgpu_kernel void @s_v_madak_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in.a, float %b) nounwind {
135 %tid = tail call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
136 %in.a.gep = getelementptr float, float addrspace(1)* %in.a, i32 %tid
137 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid
139 %a = load float, float addrspace(1)* %in.a.gep, align 4
141 %mul = fmul float %a, %b
142 %madak = fadd float %mul, 10.0
143 store float %madak, float addrspace(1)* %out.gep, align 4
147 ; GCN-LABEL: @v_s_madak_f32
148 ; GCN-DAG: s_load_dword [[SB:s[0-9]+]]
149 ; GFX6_8_9-DAG: v_mov_b32_e32 [[VK:v[0-9]+]], 0x41200000
150 ; GCN-DAG: {{buffer|flat|global}}_load_dword{{(_addtid)?}} [[VA:v[0-9]+]]
151 ; GFX6_8_9-NOT: v_madak_f32
152 ; GFX6_8_9: v_mac_f32_e32 [[VK]], [[SB]], [[VA]]
153 ; GFX10-MAD: v_madak_f32 v{{[0-9]+}}, [[SB]], [[VA]], 0x41200000
154 ; FMA: v_fmaak_f32 v{{[0-9]+}}, [[SB]], [[VA]], 0x41200000
155 define amdgpu_kernel void @v_s_madak_f32(float addrspace(1)* noalias %out, float %a, float addrspace(1)* noalias %in.b) nounwind {
156 %tid = tail call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
157 %in.b.gep = getelementptr float, float addrspace(1)* %in.b, i32 %tid
158 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid
160 %b = load float, float addrspace(1)* %in.b.gep, align 4
162 %mul = fmul float %a, %b
163 %madak = fadd float %mul, 10.0
164 store float %madak, float addrspace(1)* %out.gep, align 4
168 ; GCN-LABEL: {{^}}s_s_madak_f32:
169 ; GCN-NOT: v_madak_f32
170 ; GFX8_9: v_mac_f32_e32 {{v[0-9]+}}, {{s[0-9]+}}, {{v[0-9]+}}
171 ; GFX10-MAD: v_mac_f32_e64 {{v[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
172 ; FMA: v_fmac_f32_e64 {{v[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
173 define amdgpu_kernel void @s_s_madak_f32(float addrspace(1)* %out, float %a, float %b) nounwind {
174 %mul = fmul float %a, %b
175 %madak = fadd float %mul, 10.0
176 store float %madak, float addrspace(1)* %out, align 4
180 ; GCN-LABEL: {{^}}no_madak_src0_modifier_f32:
181 ; GFX6: buffer_load_dword [[VA:v[0-9]+]]
182 ; GFX6: buffer_load_dword [[VB:v[0-9]+]]
183 ; GFX8_9_10: {{flat|global}}_load_dword [[VB:v[0-9]+]]
184 ; GFX8_9_10: {{flat|global}}_load_dword [[VA:v[0-9]+]]
185 ; GFX6_8_9: v_mad_f32 {{v[0-9]+}}, |{{v[0-9]+}}|, {{v[0-9]+}}, {{[sv][0-9]+}}
186 ; GFX10-MAD: v_mad_f32 {{v[0-9]+}}, |{{v[0-9]+}}|, {{v[0-9]+}}, 0x41200000
187 ; FMA: v_fma_f32 {{v[0-9]+}}, |{{v[0-9]+}}|, {{v[0-9]+}}, 0x41200000
189 define amdgpu_kernel void @no_madak_src0_modifier_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in.a, float addrspace(1)* noalias %in.b) nounwind {
190 %tid = tail call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
191 %in.a.gep = getelementptr float, float addrspace(1)* %in.a, i32 %tid
192 %in.b.gep = getelementptr float, float addrspace(1)* %in.b, i32 %tid
193 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid
195 %a = load float, float addrspace(1)* %in.a.gep, align 4
196 %b = load float, float addrspace(1)* %in.b.gep, align 4
198 %a.fabs = call float @llvm.fabs.f32(float %a) nounwind readnone
200 %mul = fmul float %a.fabs, %b
201 %madak = fadd float %mul, 10.0
202 store float %madak, float addrspace(1)* %out.gep, align 4
206 ; GCN-LABEL: {{^}}no_madak_src1_modifier_f32:
207 ; GFX6: buffer_load_dword [[VA:v[0-9]+]]
208 ; GFX6: buffer_load_dword [[VB:v[0-9]+]]
209 ; GFX8_9_10: {{flat|global}}_load_dword [[VB:v[0-9]+]]
210 ; GFX8_9_10: {{flat|global}}_load_dword [[VA:v[0-9]+]]
211 ; GFX6_8_9: v_mad_f32 {{v[0-9]+}}, {{v[0-9]+}}, |{{v[0-9]+}}|, {{[sv][0-9]+}}
212 ; GFX10-MAD: v_mad_f32 {{v[0-9]+}}, {{v[0-9]+}}, |{{v[0-9]+}}|, 0x41200000
213 ; FMA: v_fma_f32 {{v[0-9]+}}, {{v[0-9]+}}, |{{v[0-9]+}}|, 0x41200000
215 define amdgpu_kernel void @no_madak_src1_modifier_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in.a, float addrspace(1)* noalias %in.b) nounwind {
216 %tid = tail call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
217 %in.a.gep = getelementptr float, float addrspace(1)* %in.a, i32 %tid
218 %in.b.gep = getelementptr float, float addrspace(1)* %in.b, i32 %tid
219 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid
221 %a = load float, float addrspace(1)* %in.a.gep, align 4
222 %b = load float, float addrspace(1)* %in.b.gep, align 4
224 %b.fabs = call float @llvm.fabs.f32(float %b) nounwind readnone
226 %mul = fmul float %a, %b.fabs
227 %madak = fadd float %mul, 10.0
228 store float %madak, float addrspace(1)* %out.gep, align 4
232 ; SIFoldOperands should not fold the SGPR copy into the instruction before GFX10
233 ; because the implicit immediate already uses the constant bus.
234 ; On GFX10+ we can use two scalar operands.
235 ; GCN-LABEL: {{^}}madak_constant_bus_violation:
236 ; GCN: s_load_dword [[SGPR0:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, {{0x12|0x48}}
237 ; GCN: v_mov_b32_e32 [[SGPR0_VCOPY:v[0-9]+]], [[SGPR0]]
238 ; GCN: {{buffer|flat|global}}_load_dword [[VGPR:v[0-9]+]]
239 ; MAD: v_madak_f32 [[MADAK:v[0-9]+]], 0.5, [[SGPR0_VCOPY]], 0x42280000
240 ; FMA: v_fmaak_f32 [[MADAK:v[0-9]+]], 0.5, [[SGPR0_VCOPY]], 0x42280000
241 ; GCN: v_mul_f32_e32 [[MUL:v[0-9]+]], [[MADAK]], [[VGPR]]
242 ; GFX6: buffer_store_dword [[MUL]]
243 ; GFX8_9_10: {{flat|global}}_store_dword v[{{[0-9:]+}}], [[MUL]]
244 define amdgpu_kernel void @madak_constant_bus_violation(i32 %arg1, [8 x i32], float %sgpr0, float %sgpr1) #0 {
246 %tmp = icmp eq i32 %arg1, 0
247 br i1 %tmp, label %bb3, label %bb4
250 store volatile float 0.0, float addrspace(1)* undef
254 %vgpr = load volatile float, float addrspace(1)* undef
255 %tmp0 = fmul float %sgpr0, 0.5
256 %tmp1 = fadd float %tmp0, 42.0
257 %tmp2 = fmul float %tmp1, %vgpr
258 store volatile float %tmp2, float addrspace(1)* undef, align 4
262 attributes #0 = { nounwind}