1; RUN: opt -cost-model -analyze -mtriple=amdgcn-unknown-amdhsa -mcpu=gfx900  -mattr=+half-rate-64-ops < %s | FileCheck -check-prefixes=FASTF64,FASTF16,ALL %s
2; RUN: opt -cost-model -analyze -mtriple=amdgcn-unknown-amdhsa -mattr=-half-rate-64-ops < %s | FileCheck -check-prefixes=SLOWF64,SLOWF16,ALL %s
3; RUN: opt -cost-model -cost-kind=code-size -analyze -mtriple=amdgcn-unknown-amdhsa -mcpu=gfx900  -mattr=+half-rate-64-ops < %s | FileCheck -check-prefixes=FASTF16,SIZEALL,ALL %s
4; RUN: opt -cost-model -cost-kind=code-size -analyze -mtriple=amdgcn-unknown-amdhsa -mattr=-half-rate-64-ops < %s | FileCheck -check-prefixes=SLOWF16,SIZEALL,ALL %s
5; RUN: opt -cost-model -analyze -mtriple=amdgcn-unknown-amdhsa -mcpu=gfx90a  -mattr=+half-rate-64-ops < %s | FileCheck -check-prefixes=GFX90A-FASTF64,FASTF16,PACKEDF32,ALL %s
6
7; ALL-LABEL: 'fadd_f32'
8; ALL: estimated cost of 1 for {{.*}} fadd float
9define amdgpu_kernel void @fadd_f32(float addrspace(1)* %out, float addrspace(1)* %vaddr, float %b) #0 {
10  %vec = load float, float addrspace(1)* %vaddr
11  %add = fadd float %vec, %b
12  store float %add, float addrspace(1)* %out
13  ret void
14}
15
16; ALL-LABEL: 'fadd_v2f32'
17; NOPACKEDF32: estimated cost of 2 for {{.*}} fadd <2 x float>
18; PACKEDF32: estimated cost of 1 for {{.*}} fadd <2 x float>
19define amdgpu_kernel void @fadd_v2f32(<2 x float> addrspace(1)* %out, <2 x float> addrspace(1)* %vaddr, <2 x float> %b) #0 {
20  %vec = load <2 x float>, <2 x float> addrspace(1)* %vaddr
21  %add = fadd <2 x float> %vec, %b
22  store <2 x float> %add, <2 x float> addrspace(1)* %out
23  ret void
24}
25
26; ALL-LABEL: 'fadd_v3f32'
27; Allow for 4 when v3f32 is illegal and TargetLowering thinks it needs widening,
28; and 3 when it is legal.
29; NOPACKEDF32: estimated cost of {{[34]}} for {{.*}} fadd <3 x float>
30; PACKEDF32: estimated cost of 2 for {{.*}} fadd <3 x float>
31define amdgpu_kernel void @fadd_v3f32(<3 x float> addrspace(1)* %out, <3 x float> addrspace(1)* %vaddr, <3 x float> %b) #0 {
32  %vec = load <3 x float>, <3 x float> addrspace(1)* %vaddr
33  %add = fadd <3 x float> %vec, %b
34  store <3 x float> %add, <3 x float> addrspace(1)* %out
35  ret void
36}
37
38; ALL-LABEL: 'fadd_v5f32'
39; Allow for 8 when v5f32 is illegal and TargetLowering thinks it needs widening,
40; and 5 when it is legal.
41; NOPACKEDF32: estimated cost of {{[58]}} for {{.*}} fadd <5 x float>
42; PACKEDF32: estimated cost of 3 for {{.*}} fadd <5 x float>
43define amdgpu_kernel void @fadd_v5f32(<5 x float> addrspace(1)* %out, <5 x float> addrspace(1)* %vaddr, <5 x float> %b) #0 {
44  %vec = load <5 x float>, <5 x float> addrspace(1)* %vaddr
45  %add = fadd <5 x float> %vec, %b
46  store <5 x float> %add, <5 x float> addrspace(1)* %out
47  ret void
48}
49
50; ALL-LABEL: 'fadd_f64'
51; GFX90A-FASTF64: estimated cost of 1 for {{.*}} fadd double
52; FASTF64: estimated cost of 2 for {{.*}} fadd double
53; SLOWF64: estimated cost of 4 for {{.*}} fadd double
54; SIZEALL: estimated cost of 2 for {{.*}} fadd double
55define amdgpu_kernel void @fadd_f64(double addrspace(1)* %out, double addrspace(1)* %vaddr, double %b) #0 {
56  %vec = load double, double addrspace(1)* %vaddr
57  %add = fadd double %vec, %b
58  store double %add, double addrspace(1)* %out
59  ret void
60}
61
62; ALL-LABEL: 'fadd_v2f64'
63; GFX90A-FASTF64: estimated cost of 2 for {{.*}} fadd <2 x double>
64; FASTF64: estimated cost of 4 for {{.*}} fadd <2 x double>
65; SLOWF64: estimated cost of 8 for {{.*}} fadd <2 x double>
66; SIZEALL: estimated cost of 4 for {{.*}} fadd <2 x double>
67define amdgpu_kernel void @fadd_v2f64(<2 x double> addrspace(1)* %out, <2 x double> addrspace(1)* %vaddr, <2 x double> %b) #0 {
68  %vec = load <2 x double>, <2 x double> addrspace(1)* %vaddr
69  %add = fadd <2 x double> %vec, %b
70  store <2 x double> %add, <2 x double> addrspace(1)* %out
71  ret void
72}
73
74; ALL-LABEL: 'fadd_v3f64'
75; GFX90A-FASTF64: estimated cost of 3 for {{.*}} fadd <3 x double>
76; FASTF64: estimated cost of 6 for {{.*}} fadd <3 x double>
77; SLOWF64: estimated cost of 12 for {{.*}} fadd <3 x double>
78; SIZEALL: estimated cost of 6 for {{.*}} fadd <3 x double>
79define amdgpu_kernel void @fadd_v3f64(<3 x double> addrspace(1)* %out, <3 x double> addrspace(1)* %vaddr, <3 x double> %b) #0 {
80  %vec = load <3 x double>, <3 x double> addrspace(1)* %vaddr
81  %add = fadd <3 x double> %vec, %b
82  store <3 x double> %add, <3 x double> addrspace(1)* %out
83  ret void
84}
85
86; ALL-LABEL: 'fadd_f16'
87; ALL: estimated cost of 1 for {{.*}} fadd half
88define amdgpu_kernel void @fadd_f16(half addrspace(1)* %out, half addrspace(1)* %vaddr, half %b) #0 {
89  %vec = load half, half addrspace(1)* %vaddr
90  %add = fadd half %vec, %b
91  store half %add, half addrspace(1)* %out
92  ret void
93}
94
95; ALL-LABEL: 'fadd_v2f16'
96; SLOWF16: estimated cost of 2 for {{.*}} fadd <2 x half>
97; FASTF16: estimated cost of 1 for {{.*}} fadd <2 x half>
98define amdgpu_kernel void @fadd_v2f16(<2 x half> addrspace(1)* %out, <2 x half> addrspace(1)* %vaddr, <2 x half> %b) #0 {
99  %vec = load <2 x half>, <2 x half> addrspace(1)* %vaddr
100  %add = fadd <2 x half> %vec, %b
101  store <2 x half> %add, <2 x half> addrspace(1)* %out
102  ret void
103}
104
105; ALL-LABEL: 'fadd_v3f16'
106; SLOWF16: estimated cost of 4 for {{.*}} fadd <3 x half>
107; FASTF16: estimated cost of 2 for {{.*}} fadd <3 x half>
108define amdgpu_kernel void @fadd_v3f16(<3 x half> addrspace(1)* %out, <3 x half> addrspace(1)* %vaddr, <3 x half> %b) #0 {
109  %vec = load <3 x half>, <3 x half> addrspace(1)* %vaddr
110  %add = fadd <3 x half> %vec, %b
111  store <3 x half> %add, <3 x half> addrspace(1)* %out
112  ret void
113}
114
115; ALL-LABEL: 'fadd_v4f16'
116; SLOWF16: estimated cost of 4 for {{.*}} fadd <4 x half>
117; FASTF16: estimated cost of 2 for {{.*}} fadd <4 x half>
118define amdgpu_kernel void @fadd_v4f16(<4 x half> addrspace(1)* %out, <4 x half> addrspace(1)* %vaddr, <4 x half> %b) #0 {
119  %vec = load <4 x half>, <4 x half> addrspace(1)* %vaddr
120  %add = fadd <4 x half> %vec, %b
121  store <4 x half> %add, <4 x half> addrspace(1)* %out
122  ret void
123}
124
125attributes #0 = { nounwind }
126