annotate llvm/test/CodeGen/AMDGPU/fabs.f16.ll @ 223:5f17cb93ff66 llvm-original

LLVM13 (2021/7/18)
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:43:00 +0900
parents 79ff65ed7e25
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 ; RUN: llc -mtriple=amdgcn--amdhsa -mcpu=kaveri -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,CI %s
anatofuz
parents:
diff changeset
2 ; RUN: llc -mtriple=amdgcn--amdhsa -mcpu=tonga -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,VI,GFX89 %s
anatofuz
parents:
diff changeset
3 ; RUN: llc -mtriple=amdgcn--amdhsa -mcpu=gfx900 -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,GFX9,GFX89 %s
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 ; DAGCombiner will transform:
anatofuz
parents:
diff changeset
6 ; (fabs (f16 bitcast (i16 a))) => (f16 bitcast (and (i16 a), 0x7FFFFFFF))
anatofuz
parents:
diff changeset
7 ; unless isFabsFree returns true
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 ; GCN-LABEL: {{^}}s_fabs_free_f16:
anatofuz
parents:
diff changeset
10 ; GCN: s_load_dword [[VAL:s[0-9]+]]
anatofuz
parents:
diff changeset
11 ; GCN: s_and_b32 [[RESULT:s[0-9]+]], [[VAL]], 0x7fff
anatofuz
parents:
diff changeset
12 ; GCN: v_mov_b32_e32 [[V_RESULT:v[0-9]+]], [[RESULT]]
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
13 ; GCN: {{flat|global}}_store_short v{{.+}}, [[V_RESULT]]
150
anatofuz
parents:
diff changeset
14 define amdgpu_kernel void @s_fabs_free_f16(half addrspace(1)* %out, i16 %in) {
anatofuz
parents:
diff changeset
15 %bc= bitcast i16 %in to half
anatofuz
parents:
diff changeset
16 %fabs = call half @llvm.fabs.f16(half %bc)
anatofuz
parents:
diff changeset
17 store half %fabs, half addrspace(1)* %out
anatofuz
parents:
diff changeset
18 ret void
anatofuz
parents:
diff changeset
19 }
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 ; GCN-LABEL: {{^}}s_fabs_f16:
anatofuz
parents:
diff changeset
22 ; GCN: s_load_dword [[VAL:s[0-9]+]]
anatofuz
parents:
diff changeset
23 ; GCN: s_and_b32 [[RESULT:s[0-9]+]], [[VAL]], 0x7fff
anatofuz
parents:
diff changeset
24 ; GCN: v_mov_b32_e32 [[V_RESULT:v[0-9]+]], [[RESULT]]
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
25 ; GCN: {{flat|global}}_store_short v{{.+}}, [[V_RESULT]]
150
anatofuz
parents:
diff changeset
26 define amdgpu_kernel void @s_fabs_f16(half addrspace(1)* %out, half %in) {
anatofuz
parents:
diff changeset
27 %fabs = call half @llvm.fabs.f16(half %in)
anatofuz
parents:
diff changeset
28 store half %fabs, half addrspace(1)* %out
anatofuz
parents:
diff changeset
29 ret void
anatofuz
parents:
diff changeset
30 }
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 ; GCN-LABEL: {{^}}s_fabs_v2f16:
anatofuz
parents:
diff changeset
33 ; GCN: s_load_dword [[VAL:s[0-9]+]]
anatofuz
parents:
diff changeset
34 ; GCN: s_and_b32 s{{[0-9]+}}, [[VAL]], 0x7fff7fff
anatofuz
parents:
diff changeset
35 define amdgpu_kernel void @s_fabs_v2f16(<2 x half> addrspace(1)* %out, <2 x half> %in) {
anatofuz
parents:
diff changeset
36 %fabs = call <2 x half> @llvm.fabs.v2f16(<2 x half> %in)
anatofuz
parents:
diff changeset
37 store <2 x half> %fabs, <2 x half> addrspace(1)* %out
anatofuz
parents:
diff changeset
38 ret void
anatofuz
parents:
diff changeset
39 }
anatofuz
parents:
diff changeset
40
anatofuz
parents:
diff changeset
41 ; GCN-LABEL: {{^}}s_fabs_v4f16:
anatofuz
parents:
diff changeset
42 ; CI: s_load_dwordx2 s{{\[}}[[LO:[0-9]+]]:[[HI:[0-9]+]]{{\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0x2
anatofuz
parents:
diff changeset
43 ; GFX89: s_load_dwordx2 s{{\[}}[[LO:[0-9]+]]:[[HI:[0-9]+]]{{\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0x8
anatofuz
parents:
diff changeset
44
anatofuz
parents:
diff changeset
45 ; GCN: s_mov_b32 [[MASK:s[0-9]+]], 0x7fff7fff
anatofuz
parents:
diff changeset
46 ; GCN-DAG: s_and_b32 s{{[0-9]+}}, s[[LO]], [[MASK]]
anatofuz
parents:
diff changeset
47 ; GCN-DAG: s_and_b32 s{{[0-9]+}}, s[[HI]], [[MASK]]
anatofuz
parents:
diff changeset
48 ; GCN: {{flat|global}}_store_dwordx2
anatofuz
parents:
diff changeset
49 define amdgpu_kernel void @s_fabs_v4f16(<4 x half> addrspace(1)* %out, <4 x half> %in) {
anatofuz
parents:
diff changeset
50 %fabs = call <4 x half> @llvm.fabs.v4f16(<4 x half> %in)
anatofuz
parents:
diff changeset
51 store <4 x half> %fabs, <4 x half> addrspace(1)* %out
anatofuz
parents:
diff changeset
52 ret void
anatofuz
parents:
diff changeset
53 }
anatofuz
parents:
diff changeset
54
anatofuz
parents:
diff changeset
55 ; GCN-LABEL: {{^}}fabs_fold_f16:
anatofuz
parents:
diff changeset
56 ; GCN: s_load_dword [[IN0:s[0-9]+]]
anatofuz
parents:
diff changeset
57 ; GCN-DAG: s_lshr_b32 [[IN1:s[0-9]+]], [[IN0]], 16
anatofuz
parents:
diff changeset
58
anatofuz
parents:
diff changeset
59 ; CI-DAG: v_cvt_f32_f16_e64 [[CVT0:v[0-9]+]], |[[IN0]]|
anatofuz
parents:
diff changeset
60 ; CI-DAG: v_cvt_f32_f16_e32 [[ABS_CVT1:v[0-9]+]], [[IN1]]
anatofuz
parents:
diff changeset
61 ; CI-DAG: v_mul_f32_e32 [[RESULT:v[0-9]+]], [[CVT0]], [[ABS_CVT1]]
anatofuz
parents:
diff changeset
62 ; CI-DAG: v_cvt_f16_f32_e32 [[CVTRESULT:v[0-9]+]], [[RESULT]]
anatofuz
parents:
diff changeset
63 ; CI: flat_store_short v{{\[[0-9]+:[0-9]+\]}}, [[CVTRESULT]]
anatofuz
parents:
diff changeset
64
anatofuz
parents:
diff changeset
65 ; GFX89-NOT: and
anatofuz
parents:
diff changeset
66 ; GFX89: v_mov_b32_e32 [[V_IN1:v[0-9]+]], [[IN1]]
anatofuz
parents:
diff changeset
67 ; GFX89: v_mul_f16_e64 [[RESULT:v[0-9]+]], |[[IN0]]|, [[V_IN1]]
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
68 ; GFX89: {{flat|global}}_store_short v{{.+}}, [[RESULT]]
150
anatofuz
parents:
diff changeset
69 define amdgpu_kernel void @fabs_fold_f16(half addrspace(1)* %out, half %in0, half %in1) {
anatofuz
parents:
diff changeset
70 %fabs = call half @llvm.fabs.f16(half %in0)
anatofuz
parents:
diff changeset
71 %fmul = fmul half %fabs, %in1
anatofuz
parents:
diff changeset
72 store half %fmul, half addrspace(1)* %out
anatofuz
parents:
diff changeset
73 ret void
anatofuz
parents:
diff changeset
74 }
anatofuz
parents:
diff changeset
75
anatofuz
parents:
diff changeset
76 ; GCN-LABEL: {{^}}v_fabs_v2f16:
anatofuz
parents:
diff changeset
77 ; GCN: {{flat|global}}_load_dword [[VAL:v[0-9]+]]
anatofuz
parents:
diff changeset
78 ; GCN: v_and_b32_e32 v{{[0-9]+}}, 0x7fff7fff, [[VAL]]
anatofuz
parents:
diff changeset
79 define amdgpu_kernel void @v_fabs_v2f16(<2 x half> addrspace(1)* %out, <2 x half> addrspace(1)* %in) #0 {
anatofuz
parents:
diff changeset
80 %tid = call i32 @llvm.amdgcn.workitem.id.x()
anatofuz
parents:
diff changeset
81 %gep.in = getelementptr inbounds <2 x half>, <2 x half> addrspace(1)* %in, i32 %tid
anatofuz
parents:
diff changeset
82 %gep.out = getelementptr inbounds <2 x half>, <2 x half> addrspace(1)* %in, i32 %tid
anatofuz
parents:
diff changeset
83 %val = load <2 x half>, <2 x half> addrspace(1)* %gep.in, align 2
anatofuz
parents:
diff changeset
84 %fabs = call <2 x half> @llvm.fabs.v2f16(<2 x half> %val)
anatofuz
parents:
diff changeset
85 store <2 x half> %fabs, <2 x half> addrspace(1)* %gep.out
anatofuz
parents:
diff changeset
86 ret void
anatofuz
parents:
diff changeset
87 }
anatofuz
parents:
diff changeset
88
anatofuz
parents:
diff changeset
89 ; GCN-LABEL: {{^}}fabs_free_v2f16:
anatofuz
parents:
diff changeset
90 ; GCN: s_load_dword [[VAL:s[0-9]+]]
anatofuz
parents:
diff changeset
91 ; GCN: s_and_b32 s{{[0-9]+}}, [[VAL]], 0x7fff7fff
anatofuz
parents:
diff changeset
92 define amdgpu_kernel void @fabs_free_v2f16(<2 x half> addrspace(1)* %out, i32 %in) #0 {
anatofuz
parents:
diff changeset
93 %bc = bitcast i32 %in to <2 x half>
anatofuz
parents:
diff changeset
94 %fabs = call <2 x half> @llvm.fabs.v2f16(<2 x half> %bc)
anatofuz
parents:
diff changeset
95 store <2 x half> %fabs, <2 x half> addrspace(1)* %out
anatofuz
parents:
diff changeset
96 ret void
anatofuz
parents:
diff changeset
97 }
anatofuz
parents:
diff changeset
98
anatofuz
parents:
diff changeset
99 ; FIXME: Should do fabs after conversion to avoid converting multiple
anatofuz
parents:
diff changeset
100 ; times in this particular case.
anatofuz
parents:
diff changeset
101
anatofuz
parents:
diff changeset
102 ; GCN-LABEL: {{^}}v_fabs_fold_self_v2f16:
anatofuz
parents:
diff changeset
103 ; GCN: {{flat|global}}_load_dword [[VAL:v[0-9]+]]
anatofuz
parents:
diff changeset
104
anatofuz
parents:
diff changeset
105 ; CI: v_lshrrev_b32_e32 [[VREG:v[0-9]+]], 16, v{{[0-9]+}}
anatofuz
parents:
diff changeset
106 ; CI: v_cvt_f32_f16_e32 [[NORM:v[0-9]+]], [[VREG]]
anatofuz
parents:
diff changeset
107 ; CI: v_cvt_f32_f16_e64 [[ABS:v[0-9]+]], {{\|}}[[VREG]]{{\|}}
anatofuz
parents:
diff changeset
108 ; CI: v_mul_f32_e32 v{{[0-9]+}}, [[ABS]], [[NORM]]
anatofuz
parents:
diff changeset
109 ; CI: v_cvt_f16_f32
anatofuz
parents:
diff changeset
110 ; CI: v_mul_f32_e32 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}
anatofuz
parents:
diff changeset
111 ; CI: v_cvt_f16_f32
anatofuz
parents:
diff changeset
112
anatofuz
parents:
diff changeset
113 ; VI: v_mul_f16_sdwa v{{[0-9]+}}, |v{{[0-9]+}}|, v{{[0-9]+}} dst_sel:WORD_1 dst_unused:UNUSED_PAD src0_sel:WORD_1 src1_sel:WORD_1
anatofuz
parents:
diff changeset
114 ; VI: v_mul_f16_e64 v{{[0-9]+}}, |v{{[0-9]+}}|, v{{[0-9]+}}
anatofuz
parents:
diff changeset
115
anatofuz
parents:
diff changeset
116 ; GFX9: v_and_b32_e32 [[FABS:v[0-9]+]], 0x7fff7fff, [[VAL]]
anatofuz
parents:
diff changeset
117 ; GFX9: v_pk_mul_f16 v{{[0-9]+}}, [[FABS]], v{{[0-9]+$}}
anatofuz
parents:
diff changeset
118 define amdgpu_kernel void @v_fabs_fold_self_v2f16(<2 x half> addrspace(1)* %out, <2 x half> addrspace(1)* %in) #0 {
anatofuz
parents:
diff changeset
119 %tid = call i32 @llvm.amdgcn.workitem.id.x()
anatofuz
parents:
diff changeset
120 %gep = getelementptr <2 x half>, <2 x half> addrspace(1)* %in, i32 %tid
anatofuz
parents:
diff changeset
121 %val = load <2 x half>, <2 x half> addrspace(1)* %gep
anatofuz
parents:
diff changeset
122 %fabs = call <2 x half> @llvm.fabs.v2f16(<2 x half> %val)
anatofuz
parents:
diff changeset
123 %fmul = fmul <2 x half> %fabs, %val
anatofuz
parents:
diff changeset
124 store <2 x half> %fmul, <2 x half> addrspace(1)* %out
anatofuz
parents:
diff changeset
125 ret void
anatofuz
parents:
diff changeset
126 }
anatofuz
parents:
diff changeset
127
anatofuz
parents:
diff changeset
128 ; GCN-LABEL: {{^}}v_fabs_fold_v2f16:
anatofuz
parents:
diff changeset
129 ; GCN: {{flat|global}}_load_dword [[VAL:v[0-9]+]]
anatofuz
parents:
diff changeset
130
anatofuz
parents:
diff changeset
131 ; CI: s_lshr_b32 s{{[0-9]+}}, s{{[0-9]+}}, 16
anatofuz
parents:
diff changeset
132 ; CI: v_cvt_f32_f16_e32
anatofuz
parents:
diff changeset
133 ; CI: v_cvt_f32_f16_e32
anatofuz
parents:
diff changeset
134 ; CI: v_lshrrev_b32_e32 v{{[0-9]+}}, 16, v{{[0-9]+}}
anatofuz
parents:
diff changeset
135 ; CI: v_mul_f32_e32 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}
anatofuz
parents:
diff changeset
136 ; CI: v_cvt_f16_f32
anatofuz
parents:
diff changeset
137 ; CI: v_mul_f32_e32 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}
anatofuz
parents:
diff changeset
138 ; CI: v_cvt_f16_f32
anatofuz
parents:
diff changeset
139
anatofuz
parents:
diff changeset
140 ; VI: v_mul_f16_sdwa v{{[0-9]+}}, |v{{[0-9]+}}|, v{{[0-9]+}} dst_sel:WORD_1 dst_unused:UNUSED_PAD src0_sel:WORD_1 src1_sel:DWORD
anatofuz
parents:
diff changeset
141 ; VI: v_mul_f16_e64 v{{[0-9]+}}, |v{{[0-9]+}}|, s{{[0-9]+}}
anatofuz
parents:
diff changeset
142
anatofuz
parents:
diff changeset
143 ; GFX9: v_and_b32_e32 [[FABS:v[0-9]+]], 0x7fff7fff, [[VAL]]
anatofuz
parents:
diff changeset
144 ; GFX9: v_pk_mul_f16 v{{[0-9]+}}, [[FABS]], s{{[0-9]+$}}
anatofuz
parents:
diff changeset
145 define amdgpu_kernel void @v_fabs_fold_v2f16(<2 x half> addrspace(1)* %out, <2 x half> addrspace(1)* %in, i32 %other.val) #0 {
anatofuz
parents:
diff changeset
146 %tid = call i32 @llvm.amdgcn.workitem.id.x()
anatofuz
parents:
diff changeset
147 %gep = getelementptr <2 x half>, <2 x half> addrspace(1)* %in, i32 %tid
anatofuz
parents:
diff changeset
148 %val = load <2 x half>, <2 x half> addrspace(1)* %gep
anatofuz
parents:
diff changeset
149 %fabs = call <2 x half> @llvm.fabs.v2f16(<2 x half> %val)
anatofuz
parents:
diff changeset
150 %other.val.cvt = bitcast i32 %other.val to <2 x half>
anatofuz
parents:
diff changeset
151 %fmul = fmul <2 x half> %fabs, %other.val.cvt
anatofuz
parents:
diff changeset
152 store <2 x half> %fmul, <2 x half> addrspace(1)* %out
anatofuz
parents:
diff changeset
153 ret void
anatofuz
parents:
diff changeset
154 }
anatofuz
parents:
diff changeset
155
anatofuz
parents:
diff changeset
156 ; GCN-LABEL: {{^}}v_extract_fabs_fold_v2f16:
anatofuz
parents:
diff changeset
157 ; GCN-DAG: {{flat|global}}_load_dword [[VAL:v[0-9]+]]
anatofuz
parents:
diff changeset
158 ; CI-DAG: v_mul_f32_e32 v{{[0-9]+}}, 4.0, v{{[0-9]+}}
anatofuz
parents:
diff changeset
159 ; CI-DAG: v_add_f32_e32 v{{[0-9]+}}, 2.0, v{{[0-9]+}}
anatofuz
parents:
diff changeset
160
anatofuz
parents:
diff changeset
161 ; GFX89-DAG: v_mul_f16_e64 v{{[0-9]+}}, |[[VAL]]|, 4.0
anatofuz
parents:
diff changeset
162 ; GFX89-DAG: v_mov_b32_e32 [[CONST2:v[0-9]+]], 0x4000
anatofuz
parents:
diff changeset
163 ; GFX89-DAG: v_add_f16_sdwa v{{[0-9]+}}, |[[VAL]]|, [[CONST2]] dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:WORD_1 src1_sel:DWORD
anatofuz
parents:
diff changeset
164 define amdgpu_kernel void @v_extract_fabs_fold_v2f16(<2 x half> addrspace(1)* %in) #0 {
anatofuz
parents:
diff changeset
165 %tid = call i32 @llvm.amdgcn.workitem.id.x()
anatofuz
parents:
diff changeset
166 %gep.in = getelementptr inbounds <2 x half>, <2 x half> addrspace(1)* %in, i32 %tid
anatofuz
parents:
diff changeset
167 %val = load <2 x half>, <2 x half> addrspace(1)* %gep.in
anatofuz
parents:
diff changeset
168 %fabs = call <2 x half> @llvm.fabs.v2f16(<2 x half> %val)
anatofuz
parents:
diff changeset
169 %elt0 = extractelement <2 x half> %fabs, i32 0
anatofuz
parents:
diff changeset
170 %elt1 = extractelement <2 x half> %fabs, i32 1
anatofuz
parents:
diff changeset
171
anatofuz
parents:
diff changeset
172 %fmul0 = fmul half %elt0, 4.0
anatofuz
parents:
diff changeset
173 %fadd1 = fadd half %elt1, 2.0
anatofuz
parents:
diff changeset
174 store volatile half %fmul0, half addrspace(1)* undef
anatofuz
parents:
diff changeset
175 store volatile half %fadd1, half addrspace(1)* undef
anatofuz
parents:
diff changeset
176 ret void
anatofuz
parents:
diff changeset
177 }
anatofuz
parents:
diff changeset
178
anatofuz
parents:
diff changeset
179 ; GCN-LABEL: {{^}}v_extract_fabs_no_fold_v2f16:
anatofuz
parents:
diff changeset
180 ; GCN: {{flat|global}}_load_dword [[VAL:v[0-9]+]]
anatofuz
parents:
diff changeset
181 ; GCN: v_and_b32_e32 [[AND:v[0-9]+]], 0x7fff7fff, [[VAL]]
anatofuz
parents:
diff changeset
182
anatofuz
parents:
diff changeset
183
anatofuz
parents:
diff changeset
184 ; VI: v_bfe_u32 v{{[0-9]+}}, v{{[0-9]+}}, 16, 15
anatofuz
parents:
diff changeset
185 ; VI: flat_store_short
anatofuz
parents:
diff changeset
186
anatofuz
parents:
diff changeset
187 ; GFX9: global_store_short_d16_hi v{{\[[0-9]+:[0-9]+\]}}, [[AND]], off
anatofuz
parents:
diff changeset
188 define amdgpu_kernel void @v_extract_fabs_no_fold_v2f16(<2 x half> addrspace(1)* %in) #0 {
anatofuz
parents:
diff changeset
189 %tid = call i32 @llvm.amdgcn.workitem.id.x()
anatofuz
parents:
diff changeset
190 %gep.in = getelementptr inbounds <2 x half>, <2 x half> addrspace(1)* %in, i32 %tid
anatofuz
parents:
diff changeset
191 %val = load <2 x half>, <2 x half> addrspace(1)* %gep.in
anatofuz
parents:
diff changeset
192 %fabs = call <2 x half> @llvm.fabs.v2f16(<2 x half> %val)
anatofuz
parents:
diff changeset
193 %elt0 = extractelement <2 x half> %fabs, i32 0
anatofuz
parents:
diff changeset
194 %elt1 = extractelement <2 x half> %fabs, i32 1
anatofuz
parents:
diff changeset
195 store volatile half %elt0, half addrspace(1)* undef
anatofuz
parents:
diff changeset
196 store volatile half %elt1, half addrspace(1)* undef
anatofuz
parents:
diff changeset
197 ret void
anatofuz
parents:
diff changeset
198 }
anatofuz
parents:
diff changeset
199
anatofuz
parents:
diff changeset
200 declare half @llvm.fabs.f16(half) #1
anatofuz
parents:
diff changeset
201 declare <2 x half> @llvm.fabs.v2f16(<2 x half>) #1
anatofuz
parents:
diff changeset
202 declare <4 x half> @llvm.fabs.v4f16(<4 x half>) #1
anatofuz
parents:
diff changeset
203 declare i32 @llvm.amdgcn.workitem.id.x() #1
anatofuz
parents:
diff changeset
204
anatofuz
parents:
diff changeset
205 attributes #0 = { nounwind }
anatofuz
parents:
diff changeset
206 attributes #1 = { nounwind readnone }