1 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,SI %s
2 ; XUN: llc -march=amdgcn -mcpu=tonga -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,VI %s
4 ; FIXME: Enable for VI.
6 declare i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
7 declare float @llvm.amdgcn.div.fmas.f32(float, float, float, i1) nounwind readnone
8 declare double @llvm.amdgcn.div.fmas.f64(double, double, double, i1) nounwind readnone
10 ; GCN-LABEL: {{^}}test_div_fmas_f32:
11 ; SI-DAG: s_load_dword [[SA:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0x13
12 ; SI-DAG: s_load_dword [[SB:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0x1c
13 ; SI-DAG: s_load_dword [[SC:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0x25
15 ; VI-DAG: s_load_dword [[SA:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0x4c
16 ; VI-DAG: s_load_dword [[SB:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0x70
17 ; VI-DAG: s_load_dword [[SC:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0x94
19 ; GCN-DAG: s_and_b32 [[AND_I1:s[0-9]+]], 1, s{{[0-9]+}}
20 ; GCN: v_cmp_eq_u32_e64 vcc, [[AND_I1]], 1
22 ; GCN-DAG: v_mov_b32_e32 [[VC:v[0-9]+]], [[SC]]
23 ; GCN-DAG: v_mov_b32_e32 [[VB:v[0-9]+]], [[SB]]
24 ; GCN-DAG: v_mov_b32_e32 [[VA:v[0-9]+]], [[SA]]
25 ; GCN: v_div_fmas_f32 [[RESULT:v[0-9]+]], [[VA]], [[VB]], [[VC]]
26 ; GCN: buffer_store_dword [[RESULT]],
27 define amdgpu_kernel void @test_div_fmas_f32(float addrspace(1)* %out, [8 x i32], float %a, [8 x i32], float %b, [8 x i32], float %c, [8 x i32], i1 %d) nounwind {
28 %result = call float @llvm.amdgcn.div.fmas.f32(float %a, float %b, float %c, i1 %d) nounwind readnone
29 store float %result, float addrspace(1)* %out, align 4
33 ; GCN-LABEL: {{^}}test_div_fmas_f32_inline_imm_0:
34 ; SI-DAG: s_load_dword [[SB:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0x1c
35 ; SI-DAG: s_load_dword [[SC:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0x25
36 ; SI-DAG: v_mov_b32_e32 [[VC:v[0-9]+]], [[SC]]
37 ; SI-DAG: v_mov_b32_e32 [[VB:v[0-9]+]], [[SB]]
38 ; SI: v_div_fmas_f32 [[RESULT:v[0-9]+]], 1.0, [[VB]], [[VC]]
39 ; SI: buffer_store_dword [[RESULT]],
40 define amdgpu_kernel void @test_div_fmas_f32_inline_imm_0(float addrspace(1)* %out, [8 x i32], float %a, [8 x i32], float %b, [8 x i32], float %c, [8 x i32], i1 %d) nounwind {
41 %result = call float @llvm.amdgcn.div.fmas.f32(float 1.0, float %b, float %c, i1 %d) nounwind readnone
42 store float %result, float addrspace(1)* %out, align 4
46 ; GCN-LABEL: {{^}}test_div_fmas_f32_inline_imm_1:
47 ; SI-DAG: s_load_dword [[SA:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0xb
48 ; SI-DAG: s_load_dword [[SC:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0xd
50 ; VI-DAG: s_load_dword [[SA:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0x4c
51 ; VI-DAG: s_load_dword [[SC:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0x94
53 ; GCN-DAG: v_mov_b32_e32 [[VC:v[0-9]+]], [[SC]]
54 ; GCN-DAG: v_mov_b32_e32 [[VA:v[0-9]+]], [[SA]]
55 ; GCN: v_div_fmas_f32 [[RESULT:v[0-9]+]], [[VA]], 1.0, [[VC]]
56 ; GCN: buffer_store_dword [[RESULT]],
57 define amdgpu_kernel void @test_div_fmas_f32_inline_imm_1(float addrspace(1)* %out, float %a, float %b, float %c, [8 x i32], i1 %d) nounwind {
58 %result = call float @llvm.amdgcn.div.fmas.f32(float %a, float 1.0, float %c, i1 %d) nounwind readnone
59 store float %result, float addrspace(1)* %out, align 4
63 ; GCN-LABEL: {{^}}test_div_fmas_f32_inline_imm_2:
64 ; SI-DAG: s_load_dword [[SA:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0x13
65 ; SI-DAG: s_load_dword [[SB:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0x1c
67 ; VI-DAG: s_load_dword [[SA:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0x4c
68 ; VI-DAG: s_load_dword [[SB:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0x70
70 ; GCN-DAG: v_mov_b32_e32 [[VA:v[0-9]+]], [[SA]]
71 ; GCN-DAG: v_mov_b32_e32 [[VB:v[0-9]+]], [[SB]]
72 ; GCN: v_div_fmas_f32 [[RESULT:v[0-9]+]], [[VA]], [[VB]], 1.0
73 ; GCN: buffer_store_dword [[RESULT]],
74 define amdgpu_kernel void @test_div_fmas_f32_inline_imm_2(float addrspace(1)* %out, [8 x i32], float %a, [8 x i32], float %b, [8 x i32], float %c, [8 x i32], i1 %d) nounwind {
75 %result = call float @llvm.amdgcn.div.fmas.f32(float %a, float %b, float 1.0, i1 %d) nounwind readnone
76 store float %result, float addrspace(1)* %out, align 4
80 ; GCN-LABEL: {{^}}test_div_fmas_f64:
82 define amdgpu_kernel void @test_div_fmas_f64(double addrspace(1)* %out, double %a, double %b, double %c, i1 %d) nounwind {
83 %result = call double @llvm.amdgcn.div.fmas.f64(double %a, double %b, double %c, i1 %d) nounwind readnone
84 store double %result, double addrspace(1)* %out, align 8
88 ; GCN-LABEL: {{^}}test_div_fmas_f32_cond_to_vcc:
89 ; GCN: v_cmp_eq_u32_e64 vcc, s{{[0-9]+}}, 0{{$}}
90 ; GCN: v_div_fmas_f32 {{v[0-9]+}}, {{v[0-9]+}}, {{v[0-9]+}}, {{v[0-9]+}}
91 define amdgpu_kernel void @test_div_fmas_f32_cond_to_vcc(float addrspace(1)* %out, float %a, float %b, float %c, i32 %i) nounwind {
92 %cmp = icmp eq i32 %i, 0
93 %result = call float @llvm.amdgcn.div.fmas.f32(float %a, float %b, float %c, i1 %cmp) nounwind readnone
94 store float %result, float addrspace(1)* %out, align 4
98 ; GCN-LABEL: {{^}}test_div_fmas_f32_imm_false_cond_to_vcc:
99 ; GCN: s_mov_b64 vcc, 0
100 ; GCN: v_div_fmas_f32 {{v[0-9]+}}, {{v[0-9]+}}, {{v[0-9]+}}, {{v[0-9]+}}
101 define amdgpu_kernel void @test_div_fmas_f32_imm_false_cond_to_vcc(float addrspace(1)* %out, float %a, float %b, float %c) nounwind {
102 %result = call float @llvm.amdgcn.div.fmas.f32(float %a, float %b, float %c, i1 false) nounwind readnone
103 store float %result, float addrspace(1)* %out, align 4
107 ; GCN-LABEL: {{^}}test_div_fmas_f32_imm_true_cond_to_vcc:
108 ; GCN: s_mov_b64 vcc, -1
109 ; GCN: v_div_fmas_f32 {{v[0-9]+}}, {{v[0-9]+}}, {{v[0-9]+}}, {{v[0-9]+}}
110 define amdgpu_kernel void @test_div_fmas_f32_imm_true_cond_to_vcc(float addrspace(1)* %out, float %a, float %b, float %c) nounwind {
111 %result = call float @llvm.amdgcn.div.fmas.f32(float %a, float %b, float %c, i1 true) nounwind readnone
112 store float %result, float addrspace(1)* %out, align 4
116 ; GCN-LABEL: {{^}}test_div_fmas_f32_logical_cond_to_vcc:
117 ; SI-DAG: buffer_load_dword [[A:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64{{$}}
118 ; SI-DAG: buffer_load_dword [[B:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:4{{$}}
119 ; SI-DAG: buffer_load_dword [[C:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:8{{$}}
121 ; SI-DAG: v_cmp_eq_u32_e32 [[CMP0:vcc]], 0, v{{[0-9]+}}
122 ; SI-DAG: v_cmp_ne_u32_e64 [[CMP1:s\[[0-9]+:[0-9]+\]]], s{{[0-9]+}}, 0{{$}}
123 ; SI: s_and_b64 vcc, [[CMP0]], [[CMP1]]
124 ; SI: v_div_fmas_f32 {{v[0-9]+}}, [[A]], [[B]], [[C]]
126 define amdgpu_kernel void @test_div_fmas_f32_logical_cond_to_vcc(float addrspace(1)* %out, float addrspace(1)* %in, i32 %d) nounwind {
127 %tid = call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
128 %gep.a = getelementptr float, float addrspace(1)* %in, i32 %tid
129 %gep.b = getelementptr float, float addrspace(1)* %gep.a, i32 1
130 %gep.c = getelementptr float, float addrspace(1)* %gep.a, i32 2
131 %gep.out = getelementptr float, float addrspace(1)* %out, i32 2
133 %a = load volatile float, float addrspace(1)* %gep.a
134 %b = load volatile float, float addrspace(1)* %gep.b
135 %c = load volatile float, float addrspace(1)* %gep.c
137 %cmp0 = icmp eq i32 %tid, 0
138 %cmp1 = icmp ne i32 %d, 0
139 %and = and i1 %cmp0, %cmp1
141 %result = call float @llvm.amdgcn.div.fmas.f32(float %a, float %b, float %c, i1 %and) nounwind readnone
142 store float %result, float addrspace(1)* %gep.out, align 4
146 ; GCN-LABEL: {{^}}test_div_fmas_f32_i1_phi_vcc:
149 ; SI: v_cmp_eq_u32_e64 [[CMP:s\[[0-9]+:[0-9]+\]]], 0, {{v[0-9]+}}
150 ; SI: s_mov_b64 vcc, 0
151 ; SI: s_and_saveexec_b64 [[SAVE:s\[[0-9]+:[0-9]+\]]], [[CMP]]
154 ; SI: buffer_load_dword [[LOAD:v[0-9]+]],
155 ; SI: v_cmp_ne_u32_e32 vcc, 0, [[LOAD]]
156 ; SI: s_and_b64 vcc, vcc, exec
159 ; SI: s_or_b64 exec, exec, [[SAVE]]
161 ; SI: v_div_fmas_f32 {{v[0-9]+}}, {{v[0-9]+}}, {{v[0-9]+}}, {{v[0-9]+}}
162 ; SI: buffer_store_dword
165 define amdgpu_kernel void @test_div_fmas_f32_i1_phi_vcc(float addrspace(1)* %out, float addrspace(1)* %in, i32 addrspace(1)* %dummy) nounwind {
167 %tid = call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
168 %gep.out = getelementptr float, float addrspace(1)* %out, i32 2
169 %gep.a = getelementptr float, float addrspace(1)* %in, i32 %tid
170 %gep.b = getelementptr float, float addrspace(1)* %gep.a, i32 1
171 %gep.c = getelementptr float, float addrspace(1)* %gep.a, i32 2
173 %a = load float, float addrspace(1)* %gep.a
174 %b = load float, float addrspace(1)* %gep.b
175 %c = load float, float addrspace(1)* %gep.c
177 %cmp0 = icmp eq i32 %tid, 0
178 br i1 %cmp0, label %bb, label %exit
181 %val = load i32, i32 addrspace(1)* %dummy
182 %cmp1 = icmp ne i32 %val, 0
186 %cond = phi i1 [false, %entry], [%cmp1, %bb]
187 %result = call float @llvm.amdgcn.div.fmas.f32(float %a, float %b, float %c, i1 %cond) nounwind readnone
188 store float %result, float addrspace(1)* %gep.out, align 4