1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
2 ; RUN: llc -amdgpu-scalarize-global-loads=false -mtriple=amdgcn -mcpu=tahiti -verify-machineinstrs < %s | FileCheck -check-prefixes=SI %s
3 ; RUN: llc -amdgpu-scalarize-global-loads=false -mtriple=amdgcn -mcpu=fiji -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -check-prefixes=VI %s
4 ; RUN: llc -amdgpu-scalarize-global-loads=false -mtriple=amdgcn -mcpu=gfx1100 -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -check-prefixes=GFX11 %s
6 declare half @llvm.trunc.f16(half %a)
7 declare <2 x half> @llvm.trunc.v2f16(<2 x half> %a)
9 define amdgpu_kernel void @trunc_f16(
10 ; SI-LABEL: trunc_f16:
11 ; SI: ; %bb.0: ; %entry
12 ; SI-NEXT: s_load_dwordx4 s[0:3], s[2:3], 0x9
13 ; SI-NEXT: s_mov_b32 s7, 0xf000
14 ; SI-NEXT: s_mov_b32 s6, -1
15 ; SI-NEXT: s_mov_b32 s10, s6
16 ; SI-NEXT: s_mov_b32 s11, s7
17 ; SI-NEXT: s_waitcnt lgkmcnt(0)
18 ; SI-NEXT: s_mov_b32 s8, s2
19 ; SI-NEXT: s_mov_b32 s9, s3
20 ; SI-NEXT: buffer_load_ushort v0, off, s[8:11], 0
21 ; SI-NEXT: s_mov_b32 s4, s0
22 ; SI-NEXT: s_mov_b32 s5, s1
23 ; SI-NEXT: s_waitcnt vmcnt(0)
24 ; SI-NEXT: v_cvt_f32_f16_e32 v0, v0
25 ; SI-NEXT: v_trunc_f32_e32 v0, v0
26 ; SI-NEXT: v_cvt_f16_f32_e32 v0, v0
27 ; SI-NEXT: buffer_store_short v0, off, s[4:7], 0
30 ; VI-LABEL: trunc_f16:
31 ; VI: ; %bb.0: ; %entry
32 ; VI-NEXT: s_load_dwordx4 s[0:3], s[2:3], 0x24
33 ; VI-NEXT: s_mov_b32 s7, 0xf000
34 ; VI-NEXT: s_mov_b32 s6, -1
35 ; VI-NEXT: s_mov_b32 s10, s6
36 ; VI-NEXT: s_mov_b32 s11, s7
37 ; VI-NEXT: s_waitcnt lgkmcnt(0)
38 ; VI-NEXT: s_mov_b32 s8, s2
39 ; VI-NEXT: s_mov_b32 s9, s3
40 ; VI-NEXT: buffer_load_ushort v0, off, s[8:11], 0
41 ; VI-NEXT: s_mov_b32 s4, s0
42 ; VI-NEXT: s_mov_b32 s5, s1
43 ; VI-NEXT: s_waitcnt vmcnt(0)
44 ; VI-NEXT: v_trunc_f16_e32 v0, v0
45 ; VI-NEXT: buffer_store_short v0, off, s[4:7], 0
48 ; GFX11-LABEL: trunc_f16:
49 ; GFX11: ; %bb.0: ; %entry
50 ; GFX11-NEXT: s_load_b128 s[0:3], s[2:3], 0x24
51 ; GFX11-NEXT: s_mov_b32 s6, -1
52 ; GFX11-NEXT: s_mov_b32 s7, 0x31016000
53 ; GFX11-NEXT: s_mov_b32 s10, s6
54 ; GFX11-NEXT: s_mov_b32 s11, s7
55 ; GFX11-NEXT: s_waitcnt lgkmcnt(0)
56 ; GFX11-NEXT: s_mov_b32 s8, s2
57 ; GFX11-NEXT: s_mov_b32 s9, s3
58 ; GFX11-NEXT: s_mov_b32 s4, s0
59 ; GFX11-NEXT: buffer_load_u16 v0, off, s[8:11], 0
60 ; GFX11-NEXT: s_mov_b32 s5, s1
61 ; GFX11-NEXT: s_waitcnt vmcnt(0)
62 ; GFX11-NEXT: v_trunc_f16_e32 v0, v0
63 ; GFX11-NEXT: buffer_store_b16 v0, off, s[4:7], 0
65 ; GFX11-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
66 ; GFX11-NEXT: s_endpgm
68 ptr addrspace(1) %a) {
70 %a.val = load half, ptr addrspace(1) %a
71 %r.val = call half @llvm.trunc.f16(half %a.val)
72 store half %r.val, ptr addrspace(1) %r
76 ; The original test with manual checks also had these NOT directives:
77 ; COM: SI-DAG: v_lshlrev_b32_e32 v[[R_F16_HI:[0-9]+]], 16, v[[R_F16_1]]
78 ; COM: SI-NOT: v_and_b32
79 ; COM: SI: v_or_b32_e32 v[[R_V2_F16:[0-9]+]], v[[R_F16_0]], v[[R_F16_HI]]
80 ; COM: VI-DAG: v_trunc_f16_e32 v[[R_F16_0:[0-9]+]], v[[A_V2_F16]]
81 ; COM: VI-DAG: v_trunc_f16_sdwa v[[R_F16_1:[0-9]+]], v[[A_V2_F16]] dst_sel:WORD_1 dst_unused:UNUSED_PAD src0_sel:WORD_1
82 ; COM: VI-NOT: v_and_b32
83 ; COM: VI: v_or_b32_e32 v[[R_V2_F16:[0-9]+]], v[[R_F16_0]], v[[R_F16_1]]
84 define amdgpu_kernel void @trunc_v2f16(
85 ; SI-LABEL: trunc_v2f16:
86 ; SI: ; %bb.0: ; %entry
87 ; SI-NEXT: s_load_dwordx4 s[0:3], s[2:3], 0x9
88 ; SI-NEXT: s_mov_b32 s7, 0xf000
89 ; SI-NEXT: s_mov_b32 s6, -1
90 ; SI-NEXT: s_mov_b32 s10, s6
91 ; SI-NEXT: s_mov_b32 s11, s7
92 ; SI-NEXT: s_waitcnt lgkmcnt(0)
93 ; SI-NEXT: s_mov_b32 s8, s2
94 ; SI-NEXT: s_mov_b32 s9, s3
95 ; SI-NEXT: buffer_load_dword v0, off, s[8:11], 0
96 ; SI-NEXT: s_mov_b32 s4, s0
97 ; SI-NEXT: s_mov_b32 s5, s1
98 ; SI-NEXT: s_waitcnt vmcnt(0)
99 ; SI-NEXT: v_lshrrev_b32_e32 v1, 16, v0
100 ; SI-NEXT: v_cvt_f32_f16_e32 v1, v1
101 ; SI-NEXT: v_cvt_f32_f16_e32 v0, v0
102 ; SI-NEXT: v_trunc_f32_e32 v1, v1
103 ; SI-NEXT: v_cvt_f16_f32_e32 v1, v1
104 ; SI-NEXT: v_trunc_f32_e32 v0, v0
105 ; SI-NEXT: v_cvt_f16_f32_e32 v0, v0
106 ; SI-NEXT: v_lshlrev_b32_e32 v1, 16, v1
107 ; SI-NEXT: v_or_b32_e32 v0, v0, v1
108 ; SI-NEXT: buffer_store_dword v0, off, s[4:7], 0
111 ; VI-LABEL: trunc_v2f16:
112 ; VI: ; %bb.0: ; %entry
113 ; VI-NEXT: s_load_dwordx4 s[0:3], s[2:3], 0x24
114 ; VI-NEXT: s_mov_b32 s7, 0xf000
115 ; VI-NEXT: s_mov_b32 s6, -1
116 ; VI-NEXT: s_mov_b32 s10, s6
117 ; VI-NEXT: s_mov_b32 s11, s7
118 ; VI-NEXT: s_waitcnt lgkmcnt(0)
119 ; VI-NEXT: s_mov_b32 s8, s2
120 ; VI-NEXT: s_mov_b32 s9, s3
121 ; VI-NEXT: buffer_load_dword v0, off, s[8:11], 0
122 ; VI-NEXT: s_mov_b32 s4, s0
123 ; VI-NEXT: s_mov_b32 s5, s1
124 ; VI-NEXT: s_waitcnt vmcnt(0)
125 ; VI-NEXT: v_trunc_f16_sdwa v1, v0 dst_sel:WORD_1 dst_unused:UNUSED_PAD src0_sel:WORD_1
126 ; VI-NEXT: v_trunc_f16_e32 v0, v0
127 ; VI-NEXT: v_or_b32_e32 v0, v0, v1
128 ; VI-NEXT: buffer_store_dword v0, off, s[4:7], 0
131 ; GFX11-LABEL: trunc_v2f16:
132 ; GFX11: ; %bb.0: ; %entry
133 ; GFX11-NEXT: s_load_b128 s[0:3], s[2:3], 0x24
134 ; GFX11-NEXT: s_mov_b32 s6, -1
135 ; GFX11-NEXT: s_mov_b32 s7, 0x31016000
136 ; GFX11-NEXT: s_mov_b32 s10, s6
137 ; GFX11-NEXT: s_mov_b32 s11, s7
138 ; GFX11-NEXT: s_waitcnt lgkmcnt(0)
139 ; GFX11-NEXT: s_mov_b32 s8, s2
140 ; GFX11-NEXT: s_mov_b32 s9, s3
141 ; GFX11-NEXT: s_mov_b32 s4, s0
142 ; GFX11-NEXT: buffer_load_b32 v0, off, s[8:11], 0
143 ; GFX11-NEXT: s_mov_b32 s5, s1
144 ; GFX11-NEXT: s_waitcnt vmcnt(0)
145 ; GFX11-NEXT: v_lshrrev_b32_e32 v1, 16, v0
146 ; GFX11-NEXT: v_trunc_f16_e32 v0, v0
147 ; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
148 ; GFX11-NEXT: v_trunc_f16_e32 v1, v1
149 ; GFX11-NEXT: v_pack_b32_f16 v0, v0, v1
150 ; GFX11-NEXT: buffer_store_b32 v0, off, s[4:7], 0
151 ; GFX11-NEXT: s_nop 0
152 ; GFX11-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
153 ; GFX11-NEXT: s_endpgm
155 ptr addrspace(1) %a) {
157 %a.val = load <2 x half>, ptr addrspace(1) %a
158 %r.val = call <2 x half> @llvm.trunc.v2f16(<2 x half> %a.val)
159 store <2 x half> %r.val, ptr addrspace(1) %r