1 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=verde -verify-machineinstrs < %s | FileCheck -allow-deprecated-dag-overlap -check-prefixes=GCN,SI,FUNC %s
2 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=tonga -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -allow-deprecated-dag-overlap -check-prefixes=GCN,VI,FUNC %s
3 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=gfx900 -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -allow-deprecated-dag-overlap -check-prefixes=FUNC,GFX9_10 %s
4 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=gfx1010 -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -allow-deprecated-dag-overlap -check-prefixes=FUNC,GFX9_10 %s
5 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=r600 -mcpu=redwood < %s | FileCheck -allow-deprecated-dag-overlap -check-prefixes=EG,FUNC %s
7 ; mul24 and mad24 are affected
9 ; FUNC-LABEL: {{^}}test_mul_v2i32:
10 ; EG: MULLO_INT {{\*? *}}T{{[0-9]+\.[XYZW], T[0-9]+\.[XYZW], T[0-9]+\.[XYZW]}}
11 ; EG: MULLO_INT {{\*? *}}T{{[0-9]+\.[XYZW], T[0-9]+\.[XYZW], T[0-9]+\.[XYZW]}}
13 ; GCN: v_mul_lo_u32 v{{[0-9]+, v[0-9]+, v[0-9]+}}
14 ; GCN: v_mul_lo_u32 v{{[0-9]+, v[0-9]+, v[0-9]+}}
16 define amdgpu_kernel void @test_mul_v2i32(<2 x i32> addrspace(1)* %out, <2 x i32> addrspace(1)* %in) {
17 %b_ptr = getelementptr <2 x i32>, <2 x i32> addrspace(1)* %in, i32 1
18 %a = load <2 x i32>, <2 x i32> addrspace(1) * %in
19 %b = load <2 x i32>, <2 x i32> addrspace(1) * %b_ptr
20 %result = mul <2 x i32> %a, %b
21 store <2 x i32> %result, <2 x i32> addrspace(1)* %out
25 ; FUNC-LABEL: {{^}}v_mul_v4i32:
26 ; EG: MULLO_INT {{\*? *}}T{{[0-9]+\.[XYZW], T[0-9]+\.[XYZW], T[0-9]+\.[XYZW]}}
27 ; EG: MULLO_INT {{\*? *}}T{{[0-9]+\.[XYZW], T[0-9]+\.[XYZW], T[0-9]+\.[XYZW]}}
28 ; EG: MULLO_INT {{\*? *}}T{{[0-9]+\.[XYZW], T[0-9]+\.[XYZW], T[0-9]+\.[XYZW]}}
29 ; EG: MULLO_INT {{\*? *}}T{{[0-9]+\.[XYZW], T[0-9]+\.[XYZW], T[0-9]+\.[XYZW]}}
31 ; GCN: v_mul_lo_u32 v{{[0-9]+, v[0-9]+, v[0-9]+}}
32 ; GCN: v_mul_lo_u32 v{{[0-9]+, v[0-9]+, v[0-9]+}}
33 ; GCN: v_mul_lo_u32 v{{[0-9]+, v[0-9]+, v[0-9]+}}
34 ; GCN: v_mul_lo_u32 v{{[0-9]+, v[0-9]+, v[0-9]+}}
36 define amdgpu_kernel void @v_mul_v4i32(<4 x i32> addrspace(1)* %out, <4 x i32> addrspace(1)* %in) {
37 %b_ptr = getelementptr <4 x i32>, <4 x i32> addrspace(1)* %in, i32 1
38 %a = load <4 x i32>, <4 x i32> addrspace(1) * %in
39 %b = load <4 x i32>, <4 x i32> addrspace(1) * %b_ptr
40 %result = mul <4 x i32> %a, %b
41 store <4 x i32> %result, <4 x i32> addrspace(1)* %out
45 ; FUNC-LABEL: {{^}}s_trunc_i64_mul_to_i32:
49 ; GCN: buffer_store_dword
50 define amdgpu_kernel void @s_trunc_i64_mul_to_i32(i32 addrspace(1)* %out, i64 %a, i64 %b) {
52 %trunc = trunc i64 %mul to i32
53 store i32 %trunc, i32 addrspace(1)* %out, align 8
57 ; FUNC-LABEL: {{^}}v_trunc_i64_mul_to_i32:
61 ; GCN: buffer_store_dword
62 define amdgpu_kernel void @v_trunc_i64_mul_to_i32(i32 addrspace(1)* %out, i64 addrspace(1)* %aptr, i64 addrspace(1)* %bptr) nounwind {
63 %a = load i64, i64 addrspace(1)* %aptr, align 8
64 %b = load i64, i64 addrspace(1)* %bptr, align 8
66 %trunc = trunc i64 %mul to i32
67 store i32 %trunc, i32 addrspace(1)* %out, align 8
71 ; This 64-bit multiply should just use MUL_HI and MUL_LO, since the top
72 ; 32-bits of both arguments are sign bits.
73 ; FUNC-LABEL: {{^}}mul64_sext_c:
77 ; GCN-DAG: v_mul_hi_i32
78 define amdgpu_kernel void @mul64_sext_c(i64 addrspace(1)* %out, i32 %in) {
80 %0 = sext i32 %in to i64
82 store i64 %1, i64 addrspace(1)* %out
86 ; FUNC-LABEL: {{^}}v_mul64_sext_c:
89 ; GCN-DAG: v_mul_lo_u32
90 ; GCN-DAG: v_mul_hi_i32
92 define amdgpu_kernel void @v_mul64_sext_c(i64 addrspace(1)* %out, i32 addrspace(1)* %in) {
93 %val = load i32, i32 addrspace(1)* %in, align 4
94 %ext = sext i32 %val to i64
95 %mul = mul i64 %ext, 80
96 store i64 %mul, i64 addrspace(1)* %out, align 8
100 ; FUNC-LABEL: {{^}}v_mul64_sext_inline_imm:
101 ; GCN-DAG: v_mul_lo_u32 v{{[0-9]+}}, v{{[0-9]+}}, 9
102 ; GCN-DAG: v_mul_hi_i32 v{{[0-9]+}}, v{{[0-9]+}}, 9
104 define amdgpu_kernel void @v_mul64_sext_inline_imm(i64 addrspace(1)* %out, i32 addrspace(1)* %in) {
105 %val = load i32, i32 addrspace(1)* %in, align 4
106 %ext = sext i32 %val to i64
107 %mul = mul i64 %ext, 9
108 store i64 %mul, i64 addrspace(1)* %out, align 8
112 ; FUNC-LABEL: {{^}}s_mul_i32:
113 ; GCN: s_load_dword [[SRC0:s[0-9]+]],
114 ; GCN: s_load_dword [[SRC1:s[0-9]+]],
115 ; GCN: s_mul_i32 [[SRESULT:s[0-9]+]], [[SRC0]], [[SRC1]]
116 ; GCN: v_mov_b32_e32 [[VRESULT:v[0-9]+]], [[SRESULT]]
117 ; GCN: buffer_store_dword [[VRESULT]],
119 define amdgpu_kernel void @s_mul_i32(i32 addrspace(1)* %out, [8 x i32], i32 %a, [8 x i32], i32 %b) nounwind {
120 %mul = mul i32 %a, %b
121 store i32 %mul, i32 addrspace(1)* %out, align 4
125 ; FUNC-LABEL: {{^}}v_mul_i32:
126 ; GCN: v_mul_lo_u32 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}
127 define amdgpu_kernel void @v_mul_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in) {
128 %b_ptr = getelementptr i32, i32 addrspace(1)* %in, i32 1
129 %a = load i32, i32 addrspace(1)* %in
130 %b = load i32, i32 addrspace(1)* %b_ptr
131 %result = mul i32 %a, %b
132 store i32 %result, i32 addrspace(1)* %out
136 ; A standard 64-bit multiply. The expansion should be around 6 instructions.
137 ; It would be difficult to match the expansion correctly without writing
138 ; a really complicated list of FileCheck expressions. I don't want
139 ; to confuse people who may 'break' this test with a correct optimization,
140 ; so this test just uses FUNC-LABEL to make sure the compiler does not
141 ; crash with a 'failed to select' error.
143 ; FUNC-LABEL: {{^}}s_mul_i64:
144 define amdgpu_kernel void @s_mul_i64(i64 addrspace(1)* %out, i64 %a, i64 %b) nounwind {
145 %mul = mul i64 %a, %b
146 store i64 %mul, i64 addrspace(1)* %out, align 8
150 ; FUNC-LABEL: {{^}}v_mul_i64:
152 define amdgpu_kernel void @v_mul_i64(i64 addrspace(1)* %out, i64 addrspace(1)* %aptr, i64 addrspace(1)* %bptr) {
153 %a = load i64, i64 addrspace(1)* %aptr, align 8
154 %b = load i64, i64 addrspace(1)* %bptr, align 8
155 %mul = mul i64 %a, %b
156 store i64 %mul, i64 addrspace(1)* %out, align 8
160 ; FUNC-LABEL: {{^}}mul32_in_branch:
162 define amdgpu_kernel void @mul32_in_branch(i32 addrspace(1)* %out, i32 addrspace(1)* %in, i32 %a, i32 %b, i32 %c) {
164 %0 = icmp eq i32 %a, 0
165 br i1 %0, label %if, label %else
168 %1 = load i32, i32 addrspace(1)* %in
176 %3 = phi i32 [%1, %if], [%2, %else]
177 store i32 %3, i32 addrspace(1)* %out
181 ; FUNC-LABEL: {{^}}mul64_in_branch:
183 ; GCN-DAG: v_mul_hi_u32
185 define amdgpu_kernel void @mul64_in_branch(i64 addrspace(1)* %out, i64 addrspace(1)* %in, i64 %a, i64 %b, i64 %c) {
187 %0 = icmp eq i64 %a, 0
188 br i1 %0, label %if, label %else
191 %1 = load i64, i64 addrspace(1)* %in
199 %3 = phi i64 [%1, %if], [%2, %else]
200 store i64 %3, i64 addrspace(1)* %out
204 ; FIXME: Load dwordx4
205 ; FUNC-LABEL: {{^}}s_mul_i128:
206 ; GCN: s_load_dwordx4
207 ; GCN: s_load_dwordx4
217 ; SI-DAG: v_mul_hi_u32
218 ; SI-DAG: v_mul_hi_u32
221 ; SI-DAG: v_mul_hi_u32
238 ; GCN: buffer_store_dwordx4
239 define amdgpu_kernel void @s_mul_i128(i128 addrspace(1)* %out, [8 x i32], i128 %a, [8 x i32], i128 %b) nounwind #0 {
240 %mul = mul i128 %a, %b
241 store i128 %mul, i128 addrspace(1)* %out
245 ; FUNC-LABEL: {{^}}v_mul_i128:
246 ; GCN: {{buffer|flat}}_load_dwordx4
247 ; GCN: {{buffer|flat}}_load_dwordx4
249 ; SI-DAG: v_mul_lo_u32
250 ; SI-DAG: v_mul_hi_u32
251 ; SI-DAG: v_mul_hi_u32
252 ; SI-DAG: v_mul_lo_u32
253 ; SI-DAG: v_mul_hi_u32
254 ; SI-DAG: v_mul_hi_u32
255 ; SI-DAG: v_mul_lo_u32
256 ; SI-DAG: v_mul_lo_u32
257 ; SI-DAG: v_add_i32_e32
259 ; SI-DAG: v_mul_hi_u32
260 ; SI-DAG: v_mul_lo_u32
261 ; SI-DAG: v_mul_hi_u32
262 ; SI-DAG: v_mul_lo_u32
263 ; SI-DAG: v_mul_lo_u32
264 ; SI-DAG: v_mul_lo_u32
265 ; SI-DAG: v_mul_lo_u32
266 ; SI-DAG: v_mul_lo_u32
268 ; VI-DAG: v_mul_lo_u32
269 ; VI-DAG: v_mul_hi_u32
274 ; GCN: {{buffer|flat}}_store_dwordx4
275 define amdgpu_kernel void @v_mul_i128(i128 addrspace(1)* %out, i128 addrspace(1)* %aptr, i128 addrspace(1)* %bptr) #0 {
276 %tid = call i32 @llvm.r600.read.tidig.x()
277 %gep.a = getelementptr inbounds i128, i128 addrspace(1)* %aptr, i32 %tid
278 %gep.b = getelementptr inbounds i128, i128 addrspace(1)* %bptr, i32 %tid
279 %gep.out = getelementptr inbounds i128, i128 addrspace(1)* %bptr, i32 %tid
280 %a = load i128, i128 addrspace(1)* %gep.a
281 %b = load i128, i128 addrspace(1)* %gep.b
282 %mul = mul i128 %a, %b
283 store i128 %mul, i128 addrspace(1)* %gep.out
287 declare i32 @llvm.r600.read.tidig.x() #1
289 attributes #0 = { nounwind }
290 attributes #1 = { nounwind readnone}