1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=tahiti -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,GFX6 %s
3; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=fiji -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,GFX8 %s
4; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=gfx900 -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,GFX9 %s
5
6define amdgpu_kernel void @cos_f16(half addrspace(1)* %r, half addrspace(1)* %a) {
7; GFX6-LABEL: cos_f16:
8; GFX6:       ; %bb.0:
9; GFX6-NEXT:    s_load_dwordx4 s[4:7], s[0:1], 0x9
10; GFX6-NEXT:    s_mov_b32 s3, 0xf000
11; GFX6-NEXT:    s_mov_b32 s2, -1
12; GFX6-NEXT:    s_mov_b32 s10, s2
13; GFX6-NEXT:    s_mov_b32 s11, s3
14; GFX6-NEXT:    s_waitcnt lgkmcnt(0)
15; GFX6-NEXT:    s_mov_b32 s8, s6
16; GFX6-NEXT:    s_mov_b32 s9, s7
17; GFX6-NEXT:    buffer_load_ushort v0, off, s[8:11], 0
18; GFX6-NEXT:    s_mov_b32 s0, s4
19; GFX6-NEXT:    s_mov_b32 s1, s5
20; GFX6-NEXT:    s_waitcnt vmcnt(0)
21; GFX6-NEXT:    v_cvt_f32_f16_e32 v0, v0
22; GFX6-NEXT:    v_mul_f32_e32 v0, 0x3e22f983, v0
23; GFX6-NEXT:    v_fract_f32_e32 v0, v0
24; GFX6-NEXT:    v_cos_f32_e32 v0, v0
25; GFX6-NEXT:    v_cvt_f16_f32_e32 v0, v0
26; GFX6-NEXT:    buffer_store_short v0, off, s[0:3], 0
27; GFX6-NEXT:    s_endpgm
28;
29; GFX8-LABEL: cos_f16:
30; GFX8:       ; %bb.0:
31; GFX8-NEXT:    s_load_dwordx4 s[0:3], s[0:1], 0x24
32; GFX8-NEXT:    s_waitcnt lgkmcnt(0)
33; GFX8-NEXT:    v_mov_b32_e32 v0, s2
34; GFX8-NEXT:    v_mov_b32_e32 v1, s3
35; GFX8-NEXT:    flat_load_ushort v0, v[0:1]
36; GFX8-NEXT:    v_mov_b32_e32 v1, s1
37; GFX8-NEXT:    s_waitcnt vmcnt(0)
38; GFX8-NEXT:    v_mul_f16_e32 v0, 0.15915494, v0
39; GFX8-NEXT:    v_fract_f16_e32 v0, v0
40; GFX8-NEXT:    v_cos_f16_e32 v2, v0
41; GFX8-NEXT:    v_mov_b32_e32 v0, s0
42; GFX8-NEXT:    flat_store_short v[0:1], v2
43; GFX8-NEXT:    s_endpgm
44;
45; GFX9-LABEL: cos_f16:
46; GFX9:       ; %bb.0:
47; GFX9-NEXT:    s_load_dwordx4 s[0:3], s[0:1], 0x24
48; GFX9-NEXT:    s_waitcnt lgkmcnt(0)
49; GFX9-NEXT:    v_mov_b32_e32 v0, s2
50; GFX9-NEXT:    v_mov_b32_e32 v1, s3
51; GFX9-NEXT:    global_load_ushort v0, v[0:1], off
52; GFX9-NEXT:    v_mov_b32_e32 v1, s1
53; GFX9-NEXT:    s_waitcnt vmcnt(0)
54; GFX9-NEXT:    v_mul_f16_e32 v0, 0.15915494, v0
55; GFX9-NEXT:    v_cos_f16_e32 v2, v0
56; GFX9-NEXT:    v_mov_b32_e32 v0, s0
57; GFX9-NEXT:    global_store_short v[0:1], v2, off
58; GFX9-NEXT:    s_endpgm
59  %a.val = load half, half addrspace(1)* %a
60  %r.val = call half @llvm.cos.f16(half %a.val)
61  store half %r.val, half addrspace(1)* %r
62  ret void
63}
64
65define amdgpu_kernel void @cos_v2f16(<2 x half> addrspace(1)* %r, <2 x half> addrspace(1)* %a) {
66; GFX6-LABEL: cos_v2f16:
67; GFX6:       ; %bb.0:
68; GFX6-NEXT:    s_load_dwordx4 s[4:7], s[0:1], 0x9
69; GFX6-NEXT:    s_mov_b32 s3, 0xf000
70; GFX6-NEXT:    s_mov_b32 s2, -1
71; GFX6-NEXT:    s_mov_b32 s10, s2
72; GFX6-NEXT:    s_mov_b32 s11, s3
73; GFX6-NEXT:    s_waitcnt lgkmcnt(0)
74; GFX6-NEXT:    s_mov_b32 s8, s6
75; GFX6-NEXT:    s_mov_b32 s9, s7
76; GFX6-NEXT:    buffer_load_dword v0, off, s[8:11], 0
77; GFX6-NEXT:    s_mov_b32 s0, 0x3e22f983
78; GFX6-NEXT:    s_mov_b32 s1, s5
79; GFX6-NEXT:    s_waitcnt vmcnt(0)
80; GFX6-NEXT:    v_cvt_f32_f16_e32 v1, v0
81; GFX6-NEXT:    v_lshrrev_b32_e32 v0, 16, v0
82; GFX6-NEXT:    v_cvt_f32_f16_e32 v0, v0
83; GFX6-NEXT:    v_mul_f32_e32 v1, s0, v1
84; GFX6-NEXT:    v_fract_f32_e32 v1, v1
85; GFX6-NEXT:    v_mul_f32_e32 v0, s0, v0
86; GFX6-NEXT:    v_fract_f32_e32 v0, v0
87; GFX6-NEXT:    v_cos_f32_e32 v0, v0
88; GFX6-NEXT:    v_cos_f32_e32 v1, v1
89; GFX6-NEXT:    s_mov_b32 s0, s4
90; GFX6-NEXT:    v_cvt_f16_f32_e32 v0, v0
91; GFX6-NEXT:    v_cvt_f16_f32_e32 v1, v1
92; GFX6-NEXT:    v_lshlrev_b32_e32 v0, 16, v0
93; GFX6-NEXT:    v_or_b32_e32 v0, v1, v0
94; GFX6-NEXT:    buffer_store_dword v0, off, s[0:3], 0
95; GFX6-NEXT:    s_endpgm
96;
97; GFX8-LABEL: cos_v2f16:
98; GFX8:       ; %bb.0:
99; GFX8-NEXT:    s_load_dwordx4 s[0:3], s[0:1], 0x24
100; GFX8-NEXT:    s_waitcnt lgkmcnt(0)
101; GFX8-NEXT:    v_mov_b32_e32 v0, s2
102; GFX8-NEXT:    v_mov_b32_e32 v1, s3
103; GFX8-NEXT:    flat_load_dword v0, v[0:1]
104; GFX8-NEXT:    v_mov_b32_e32 v1, 0x3118
105; GFX8-NEXT:    s_waitcnt vmcnt(0)
106; GFX8-NEXT:    v_mul_f16_sdwa v1, v0, v1 dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:WORD_1 src1_sel:DWORD
107; GFX8-NEXT:    v_mul_f16_e32 v0, 0.15915494, v0
108; GFX8-NEXT:    v_fract_f16_e32 v1, v1
109; GFX8-NEXT:    v_fract_f16_e32 v0, v0
110; GFX8-NEXT:    v_cos_f16_sdwa v2, v1 dst_sel:WORD_1 dst_unused:UNUSED_PAD src0_sel:DWORD
111; GFX8-NEXT:    v_cos_f16_e32 v3, v0
112; GFX8-NEXT:    v_mov_b32_e32 v0, s0
113; GFX8-NEXT:    v_mov_b32_e32 v1, s1
114; GFX8-NEXT:    v_or_b32_e32 v2, v3, v2
115; GFX8-NEXT:    flat_store_dword v[0:1], v2
116; GFX8-NEXT:    s_endpgm
117;
118; GFX9-LABEL: cos_v2f16:
119; GFX9:       ; %bb.0:
120; GFX9-NEXT:    s_load_dwordx4 s[0:3], s[0:1], 0x24
121; GFX9-NEXT:    s_waitcnt lgkmcnt(0)
122; GFX9-NEXT:    v_mov_b32_e32 v0, s2
123; GFX9-NEXT:    v_mov_b32_e32 v1, s3
124; GFX9-NEXT:    global_load_dword v0, v[0:1], off
125; GFX9-NEXT:    v_mov_b32_e32 v1, 0x3118
126; GFX9-NEXT:    s_waitcnt vmcnt(0)
127; GFX9-NEXT:    v_mul_f16_e32 v2, 0.15915494, v0
128; GFX9-NEXT:    v_cos_f16_e32 v2, v2
129; GFX9-NEXT:    v_mul_f16_sdwa v0, v0, v1 dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:WORD_1 src1_sel:DWORD
130; GFX9-NEXT:    v_cos_f16_e32 v3, v0
131; GFX9-NEXT:    v_mov_b32_e32 v0, s0
132; GFX9-NEXT:    v_and_b32_e32 v2, 0xffff, v2
133; GFX9-NEXT:    v_mov_b32_e32 v1, s1
134; GFX9-NEXT:    v_lshl_or_b32 v2, v3, 16, v2
135; GFX9-NEXT:    global_store_dword v[0:1], v2, off
136; GFX9-NEXT:    s_endpgm
137  %a.val = load <2 x half>, <2 x half> addrspace(1)* %a
138  %r.val = call <2 x half> @llvm.cos.v2f16(<2 x half> %a.val)
139  store <2 x half> %r.val, <2 x half> addrspace(1)* %r
140  ret void
141}
142
143declare half @llvm.cos.f16(half %a)
144declare <2 x half> @llvm.cos.v2f16(<2 x half> %a)
145