1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=amdgcn-amd-mesa3d -mcpu=fiji -verify-machineinstrs | FileCheck -check-prefix=VI %s
3 ; RUN: llc < %s -mtriple=amdgcn-amd-mesa3d -mcpu=gfx900 -verify-machineinstrs | FileCheck -check-prefix=GFX9 %s
4 ; RUN: llc < %s -mtriple=amdgcn-amd-mesa3d -mcpu=gfx1010 -verify-machineinstrs | FileCheck -check-prefix=GFX10 %s
5 ; RUN: llc < %s -mtriple=amdgcn-amd-mesa3d -mcpu=gfx1100 -amdgpu-enable-delay-alu=0 -verify-machineinstrs | FileCheck -check-prefix=GFX10 %s
7 ; ===================================================================================
9 ; ===================================================================================
11 define amdgpu_ps float @add3(i32 %a, i32 %b, i32 %c) {
14 ; VI-NEXT: v_add_u32_e32 v0, vcc, v0, v1
15 ; VI-NEXT: v_add_u32_e32 v0, vcc, v0, v2
16 ; VI-NEXT: ; return to shader part epilog
20 ; GFX9-NEXT: v_add3_u32 v0, v0, v1, v2
21 ; GFX9-NEXT: ; return to shader part epilog
25 ; GFX10-NEXT: v_add3_u32 v0, v0, v1, v2
26 ; GFX10-NEXT: ; return to shader part epilog
28 %result = add i32 %x, %c
29 %bc = bitcast i32 %result to float
33 ; V_MAD_U32_U24 is given higher priority.
34 define amdgpu_ps float @mad_no_add3(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
35 ; VI-LABEL: mad_no_add3:
37 ; VI-NEXT: v_mad_u32_u24 v0, v0, v1, v4
38 ; VI-NEXT: v_mad_u32_u24 v0, v2, v3, v0
39 ; VI-NEXT: ; return to shader part epilog
41 ; GFX9-LABEL: mad_no_add3:
43 ; GFX9-NEXT: v_mad_u32_u24 v0, v0, v1, v4
44 ; GFX9-NEXT: v_mad_u32_u24 v0, v2, v3, v0
45 ; GFX9-NEXT: ; return to shader part epilog
47 ; GFX10-LABEL: mad_no_add3:
49 ; GFX10-NEXT: v_mad_u32_u24 v0, v0, v1, v4
50 ; GFX10-NEXT: v_mad_u32_u24 v0, v2, v3, v0
51 ; GFX10-NEXT: ; return to shader part epilog
56 %mul1 = mul i32 %a1, %b1
62 %mul2 = mul i32 %c1, %d1
64 %add0 = add i32 %e, %mul1
65 %add1 = add i32 %mul2, %add0
67 %bc = bitcast i32 %add1 to float
71 ; ThreeOp instruction variant not used due to Constant Bus Limitations
72 ; TODO: with reassociation it is possible to replace a v_add_u32_e32 with a s_add_i32
73 define amdgpu_ps float @add3_vgpr_b(i32 inreg %a, i32 %b, i32 inreg %c) {
74 ; VI-LABEL: add3_vgpr_b:
76 ; VI-NEXT: s_add_i32 s3, s3, s2
77 ; VI-NEXT: v_add_u32_e32 v0, vcc, s3, v0
78 ; VI-NEXT: ; return to shader part epilog
80 ; GFX9-LABEL: add3_vgpr_b:
82 ; GFX9-NEXT: s_add_i32 s3, s3, s2
83 ; GFX9-NEXT: v_add_u32_e32 v0, s3, v0
84 ; GFX9-NEXT: ; return to shader part epilog
86 ; GFX10-LABEL: add3_vgpr_b:
88 ; GFX10-NEXT: v_add3_u32 v0, s3, s2, v0
89 ; GFX10-NEXT: ; return to shader part epilog
91 %result = add i32 %x, %c
92 %bc = bitcast i32 %result to float
96 define amdgpu_ps float @add3_vgpr_all2(i32 %a, i32 %b, i32 %c) {
97 ; VI-LABEL: add3_vgpr_all2:
99 ; VI-NEXT: v_add_u32_e32 v1, vcc, v1, v2
100 ; VI-NEXT: v_add_u32_e32 v0, vcc, v0, v1
101 ; VI-NEXT: ; return to shader part epilog
103 ; GFX9-LABEL: add3_vgpr_all2:
105 ; GFX9-NEXT: v_add3_u32 v0, v1, v2, v0
106 ; GFX9-NEXT: ; return to shader part epilog
108 ; GFX10-LABEL: add3_vgpr_all2:
110 ; GFX10-NEXT: v_add3_u32 v0, v1, v2, v0
111 ; GFX10-NEXT: ; return to shader part epilog
113 %result = add i32 %a, %x
114 %bc = bitcast i32 %result to float
118 define amdgpu_ps float @add3_vgpr_bc(i32 inreg %a, i32 %b, i32 %c) {
119 ; VI-LABEL: add3_vgpr_bc:
121 ; VI-NEXT: v_add_u32_e32 v0, vcc, s2, v0
122 ; VI-NEXT: v_add_u32_e32 v0, vcc, v0, v1
123 ; VI-NEXT: ; return to shader part epilog
125 ; GFX9-LABEL: add3_vgpr_bc:
127 ; GFX9-NEXT: v_add3_u32 v0, s2, v0, v1
128 ; GFX9-NEXT: ; return to shader part epilog
130 ; GFX10-LABEL: add3_vgpr_bc:
132 ; GFX10-NEXT: v_add3_u32 v0, s2, v0, v1
133 ; GFX10-NEXT: ; return to shader part epilog
135 %result = add i32 %x, %c
136 %bc = bitcast i32 %result to float
140 define amdgpu_ps float @add3_vgpr_const(i32 %a, i32 %b) {
141 ; VI-LABEL: add3_vgpr_const:
143 ; VI-NEXT: v_add_u32_e32 v0, vcc, v0, v1
144 ; VI-NEXT: v_add_u32_e32 v0, vcc, 16, v0
145 ; VI-NEXT: ; return to shader part epilog
147 ; GFX9-LABEL: add3_vgpr_const:
149 ; GFX9-NEXT: v_add3_u32 v0, v0, v1, 16
150 ; GFX9-NEXT: ; return to shader part epilog
152 ; GFX10-LABEL: add3_vgpr_const:
154 ; GFX10-NEXT: v_add3_u32 v0, v0, v1, 16
155 ; GFX10-NEXT: ; return to shader part epilog
157 %result = add i32 %x, 16
158 %bc = bitcast i32 %result to float
162 define amdgpu_ps <2 x float> @add3_multiuse_outer(i32 %a, i32 %b, i32 %c, i32 %x) {
163 ; VI-LABEL: add3_multiuse_outer:
165 ; VI-NEXT: v_add_u32_e32 v0, vcc, v0, v1
166 ; VI-NEXT: v_add_u32_e32 v0, vcc, v0, v2
167 ; VI-NEXT: v_mul_lo_u32 v1, v0, v3
168 ; VI-NEXT: ; return to shader part epilog
170 ; GFX9-LABEL: add3_multiuse_outer:
172 ; GFX9-NEXT: v_add3_u32 v0, v0, v1, v2
173 ; GFX9-NEXT: v_mul_lo_u32 v1, v0, v3
174 ; GFX9-NEXT: ; return to shader part epilog
176 ; GFX10-LABEL: add3_multiuse_outer:
178 ; GFX10-NEXT: v_add3_u32 v0, v0, v1, v2
179 ; GFX10-NEXT: v_mul_lo_u32 v1, v0, v3
180 ; GFX10-NEXT: ; return to shader part epilog
181 %inner = add i32 %a, %b
182 %outer = add i32 %inner, %c
183 %x1 = mul i32 %outer, %x
184 %r1 = insertelement <2 x i32> undef, i32 %outer, i32 0
185 %r0 = insertelement <2 x i32> %r1, i32 %x1, i32 1
186 %bc = bitcast <2 x i32> %r0 to <2 x float>
190 define amdgpu_ps <2 x float> @add3_multiuse_inner(i32 %a, i32 %b, i32 %c) {
191 ; VI-LABEL: add3_multiuse_inner:
193 ; VI-NEXT: v_add_u32_e32 v0, vcc, v0, v1
194 ; VI-NEXT: v_add_u32_e32 v1, vcc, v0, v2
195 ; VI-NEXT: ; return to shader part epilog
197 ; GFX9-LABEL: add3_multiuse_inner:
199 ; GFX9-NEXT: v_add_u32_e32 v0, v0, v1
200 ; GFX9-NEXT: v_add_u32_e32 v1, v0, v2
201 ; GFX9-NEXT: ; return to shader part epilog
203 ; GFX10-LABEL: add3_multiuse_inner:
205 ; GFX10-NEXT: v_add_nc_u32_e32 v0, v0, v1
206 ; GFX10-NEXT: v_add_nc_u32_e32 v1, v0, v2
207 ; GFX10-NEXT: ; return to shader part epilog
208 %inner = add i32 %a, %b
209 %outer = add i32 %inner, %c
210 %r1 = insertelement <2 x i32> undef, i32 %inner, i32 0
211 %r0 = insertelement <2 x i32> %r1, i32 %outer, i32 1
212 %bc = bitcast <2 x i32> %r0 to <2 x float>
216 ; A case where uniform values end up in VGPRs -- we could use v_add3_u32 here,
218 define amdgpu_ps float @add3_uniform_vgpr(float inreg %a, float inreg %b, float inreg %c) {
219 ; VI-LABEL: add3_uniform_vgpr:
221 ; VI-NEXT: v_add_f32_e64 v0, s2, 1.0
222 ; VI-NEXT: v_add_f32_e64 v1, s3, 2.0
223 ; VI-NEXT: v_mov_b32_e32 v2, 0x40400000
224 ; VI-NEXT: v_add_f32_e32 v2, s4, v2
225 ; VI-NEXT: v_add_u32_e32 v0, vcc, v0, v1
226 ; VI-NEXT: v_add_u32_e32 v0, vcc, v0, v2
227 ; VI-NEXT: ; return to shader part epilog
229 ; GFX9-LABEL: add3_uniform_vgpr:
231 ; GFX9-NEXT: v_add_f32_e64 v0, s2, 1.0
232 ; GFX9-NEXT: v_add_f32_e64 v1, s3, 2.0
233 ; GFX9-NEXT: v_mov_b32_e32 v2, 0x40400000
234 ; GFX9-NEXT: v_add_f32_e32 v2, s4, v2
235 ; GFX9-NEXT: v_add_u32_e32 v0, v0, v1
236 ; GFX9-NEXT: v_add_u32_e32 v0, v0, v2
237 ; GFX9-NEXT: ; return to shader part epilog
239 ; GFX10-LABEL: add3_uniform_vgpr:
241 ; GFX10-NEXT: v_add_f32_e64 v0, s2, 1.0
242 ; GFX10-NEXT: v_add_f32_e64 v1, s3, 2.0
243 ; GFX10-NEXT: v_add_f32_e64 v2, 0x40400000, s4
244 ; GFX10-NEXT: v_add_nc_u32_e32 v0, v0, v1
245 ; GFX10-NEXT: v_add_nc_u32_e32 v0, v0, v2
246 ; GFX10-NEXT: ; return to shader part epilog
247 %a1 = fadd float %a, 1.0
248 %b2 = fadd float %b, 2.0
249 %c3 = fadd float %c, 3.0
250 %bc.a = bitcast float %a1 to i32
251 %bc.b = bitcast float %b2 to i32
252 %bc.c = bitcast float %c3 to i32
253 %x = add i32 %bc.a, %bc.b
254 %result = add i32 %x, %bc.c
255 %bc = bitcast i32 %result to float