1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv64 -mattr=+zfhmin -verify-machineinstrs \
3 ; RUN: -target-abi lp64f < %s | FileCheck %s -check-prefix=RV64IZFHMIN
4 ; RUN: llc -mtriple=riscv64 -mattr=+zhinxmin -verify-machineinstrs \
5 ; RUN: -target-abi lp64 < %s | FileCheck %s -check-prefix=RV64IZHINXMIN
7 ; This file exhaustively checks half<->i32 conversions.
9 define i32 @aext_fptosi(half %a) nounwind {
10 ; RV64IZFHMIN-LABEL: aext_fptosi:
11 ; RV64IZFHMIN: # %bb.0:
12 ; RV64IZFHMIN-NEXT: fcvt.s.h fa5, fa0
13 ; RV64IZFHMIN-NEXT: fcvt.w.s a0, fa5, rtz
14 ; RV64IZFHMIN-NEXT: ret
16 ; RV64IZHINXMIN-LABEL: aext_fptosi:
17 ; RV64IZHINXMIN: # %bb.0:
18 ; RV64IZHINXMIN-NEXT: fcvt.s.h a0, a0
19 ; RV64IZHINXMIN-NEXT: fcvt.w.s a0, a0, rtz
20 ; RV64IZHINXMIN-NEXT: ret
21 %1 = fptosi half %a to i32
25 define signext i32 @sext_fptosi(half %a) nounwind {
26 ; RV64IZFHMIN-LABEL: sext_fptosi:
27 ; RV64IZFHMIN: # %bb.0:
28 ; RV64IZFHMIN-NEXT: fcvt.s.h fa5, fa0
29 ; RV64IZFHMIN-NEXT: fcvt.w.s a0, fa5, rtz
30 ; RV64IZFHMIN-NEXT: ret
32 ; RV64IZHINXMIN-LABEL: sext_fptosi:
33 ; RV64IZHINXMIN: # %bb.0:
34 ; RV64IZHINXMIN-NEXT: fcvt.s.h a0, a0
35 ; RV64IZHINXMIN-NEXT: fcvt.w.s a0, a0, rtz
36 ; RV64IZHINXMIN-NEXT: ret
37 %1 = fptosi half %a to i32
41 define zeroext i32 @zext_fptosi(half %a) nounwind {
42 ; RV64IZFHMIN-LABEL: zext_fptosi:
43 ; RV64IZFHMIN: # %bb.0:
44 ; RV64IZFHMIN-NEXT: fcvt.s.h fa5, fa0
45 ; RV64IZFHMIN-NEXT: fcvt.w.s a0, fa5, rtz
46 ; RV64IZFHMIN-NEXT: slli a0, a0, 32
47 ; RV64IZFHMIN-NEXT: srli a0, a0, 32
48 ; RV64IZFHMIN-NEXT: ret
50 ; RV64IZHINXMIN-LABEL: zext_fptosi:
51 ; RV64IZHINXMIN: # %bb.0:
52 ; RV64IZHINXMIN-NEXT: fcvt.s.h a0, a0
53 ; RV64IZHINXMIN-NEXT: fcvt.w.s a0, a0, rtz
54 ; RV64IZHINXMIN-NEXT: slli a0, a0, 32
55 ; RV64IZHINXMIN-NEXT: srli a0, a0, 32
56 ; RV64IZHINXMIN-NEXT: ret
57 %1 = fptosi half %a to i32
61 define i32 @aext_fptoui(half %a) nounwind {
62 ; RV64IZFHMIN-LABEL: aext_fptoui:
63 ; RV64IZFHMIN: # %bb.0:
64 ; RV64IZFHMIN-NEXT: fcvt.s.h fa5, fa0
65 ; RV64IZFHMIN-NEXT: fcvt.wu.s a0, fa5, rtz
66 ; RV64IZFHMIN-NEXT: ret
68 ; RV64IZHINXMIN-LABEL: aext_fptoui:
69 ; RV64IZHINXMIN: # %bb.0:
70 ; RV64IZHINXMIN-NEXT: fcvt.s.h a0, a0
71 ; RV64IZHINXMIN-NEXT: fcvt.wu.s a0, a0, rtz
72 ; RV64IZHINXMIN-NEXT: ret
73 %1 = fptoui half %a to i32
77 define signext i32 @sext_fptoui(half %a) nounwind {
78 ; RV64IZFHMIN-LABEL: sext_fptoui:
79 ; RV64IZFHMIN: # %bb.0:
80 ; RV64IZFHMIN-NEXT: fcvt.s.h fa5, fa0
81 ; RV64IZFHMIN-NEXT: fcvt.wu.s a0, fa5, rtz
82 ; RV64IZFHMIN-NEXT: ret
84 ; RV64IZHINXMIN-LABEL: sext_fptoui:
85 ; RV64IZHINXMIN: # %bb.0:
86 ; RV64IZHINXMIN-NEXT: fcvt.s.h a0, a0
87 ; RV64IZHINXMIN-NEXT: fcvt.wu.s a0, a0, rtz
88 ; RV64IZHINXMIN-NEXT: ret
89 %1 = fptoui half %a to i32
93 define zeroext i32 @zext_fptoui(half %a) nounwind {
94 ; RV64IZFHMIN-LABEL: zext_fptoui:
95 ; RV64IZFHMIN: # %bb.0:
96 ; RV64IZFHMIN-NEXT: fcvt.s.h fa5, fa0
97 ; RV64IZFHMIN-NEXT: fcvt.lu.s a0, fa5, rtz
98 ; RV64IZFHMIN-NEXT: ret
100 ; RV64IZHINXMIN-LABEL: zext_fptoui:
101 ; RV64IZHINXMIN: # %bb.0:
102 ; RV64IZHINXMIN-NEXT: fcvt.s.h a0, a0
103 ; RV64IZHINXMIN-NEXT: fcvt.lu.s a0, a0, rtz
104 ; RV64IZHINXMIN-NEXT: ret
105 %1 = fptoui half %a to i32
109 define i16 @bcvt_f16_to_aext_i16(half %a, half %b) nounwind {
110 ; RV64IZFHMIN-LABEL: bcvt_f16_to_aext_i16:
111 ; RV64IZFHMIN: # %bb.0:
112 ; RV64IZFHMIN-NEXT: fcvt.s.h fa5, fa1
113 ; RV64IZFHMIN-NEXT: fcvt.s.h fa4, fa0
114 ; RV64IZFHMIN-NEXT: fadd.s fa5, fa4, fa5
115 ; RV64IZFHMIN-NEXT: fcvt.h.s fa5, fa5
116 ; RV64IZFHMIN-NEXT: fmv.x.h a0, fa5
117 ; RV64IZFHMIN-NEXT: ret
119 ; RV64IZHINXMIN-LABEL: bcvt_f16_to_aext_i16:
120 ; RV64IZHINXMIN: # %bb.0:
121 ; RV64IZHINXMIN-NEXT: fcvt.s.h a1, a1
122 ; RV64IZHINXMIN-NEXT: fcvt.s.h a0, a0
123 ; RV64IZHINXMIN-NEXT: fadd.s a0, a0, a1
124 ; RV64IZHINXMIN-NEXT: fcvt.h.s a0, a0
125 ; RV64IZHINXMIN-NEXT: ret
126 %1 = fadd half %a, %b
127 %2 = bitcast half %1 to i16
131 define signext i16 @bcvt_f16_to_sext_i16(half %a, half %b) nounwind {
132 ; RV64IZFHMIN-LABEL: bcvt_f16_to_sext_i16:
133 ; RV64IZFHMIN: # %bb.0:
134 ; RV64IZFHMIN-NEXT: fcvt.s.h fa5, fa1
135 ; RV64IZFHMIN-NEXT: fcvt.s.h fa4, fa0
136 ; RV64IZFHMIN-NEXT: fadd.s fa5, fa4, fa5
137 ; RV64IZFHMIN-NEXT: fcvt.h.s fa5, fa5
138 ; RV64IZFHMIN-NEXT: fmv.x.h a0, fa5
139 ; RV64IZFHMIN-NEXT: ret
141 ; RV64IZHINXMIN-LABEL: bcvt_f16_to_sext_i16:
142 ; RV64IZHINXMIN: # %bb.0:
143 ; RV64IZHINXMIN-NEXT: fcvt.s.h a1, a1
144 ; RV64IZHINXMIN-NEXT: fcvt.s.h a0, a0
145 ; RV64IZHINXMIN-NEXT: fadd.s a0, a0, a1
146 ; RV64IZHINXMIN-NEXT: fcvt.h.s a0, a0
147 ; RV64IZHINXMIN-NEXT: ret
148 %1 = fadd half %a, %b
149 %2 = bitcast half %1 to i16
153 define zeroext i16 @bcvt_f16_to_zext_i16(half %a, half %b) nounwind {
154 ; RV64IZFHMIN-LABEL: bcvt_f16_to_zext_i16:
155 ; RV64IZFHMIN: # %bb.0:
156 ; RV64IZFHMIN-NEXT: fcvt.s.h fa5, fa1
157 ; RV64IZFHMIN-NEXT: fcvt.s.h fa4, fa0
158 ; RV64IZFHMIN-NEXT: fadd.s fa5, fa4, fa5
159 ; RV64IZFHMIN-NEXT: fcvt.h.s fa5, fa5
160 ; RV64IZFHMIN-NEXT: fmv.x.h a0, fa5
161 ; RV64IZFHMIN-NEXT: slli a0, a0, 48
162 ; RV64IZFHMIN-NEXT: srli a0, a0, 48
163 ; RV64IZFHMIN-NEXT: ret
165 ; RV64IZHINXMIN-LABEL: bcvt_f16_to_zext_i16:
166 ; RV64IZHINXMIN: # %bb.0:
167 ; RV64IZHINXMIN-NEXT: fcvt.s.h a1, a1
168 ; RV64IZHINXMIN-NEXT: fcvt.s.h a0, a0
169 ; RV64IZHINXMIN-NEXT: fadd.s a0, a0, a1
170 ; RV64IZHINXMIN-NEXT: fcvt.h.s a0, a0
171 ; RV64IZHINXMIN-NEXT: slli a0, a0, 48
172 ; RV64IZHINXMIN-NEXT: srli a0, a0, 48
173 ; RV64IZHINXMIN-NEXT: ret
174 %1 = fadd half %a, %b
175 %2 = bitcast half %1 to i16
179 define half @bcvt_i64_to_f16_via_i16(i64 %a, i64 %b) nounwind {
180 ; RV64IZFHMIN-LABEL: bcvt_i64_to_f16_via_i16:
181 ; RV64IZFHMIN: # %bb.0:
182 ; RV64IZFHMIN-NEXT: fmv.h.x fa5, a0
183 ; RV64IZFHMIN-NEXT: fmv.h.x fa4, a1
184 ; RV64IZFHMIN-NEXT: fcvt.s.h fa4, fa4
185 ; RV64IZFHMIN-NEXT: fcvt.s.h fa5, fa5
186 ; RV64IZFHMIN-NEXT: fadd.s fa5, fa5, fa4
187 ; RV64IZFHMIN-NEXT: fcvt.h.s fa0, fa5
188 ; RV64IZFHMIN-NEXT: ret
190 ; RV64IZHINXMIN-LABEL: bcvt_i64_to_f16_via_i16:
191 ; RV64IZHINXMIN: # %bb.0:
192 ; RV64IZHINXMIN-NEXT: fcvt.s.h a1, a1
193 ; RV64IZHINXMIN-NEXT: fcvt.s.h a0, a0
194 ; RV64IZHINXMIN-NEXT: fadd.s a0, a0, a1
195 ; RV64IZHINXMIN-NEXT: fcvt.h.s a0, a0
196 ; RV64IZHINXMIN-NEXT: ret
197 %1 = trunc i64 %a to i16
198 %2 = trunc i64 %b to i16
199 %3 = bitcast i16 %1 to half
200 %4 = bitcast i16 %2 to half
201 %5 = fadd half %3, %4
205 define half @uitofp_aext_i32_to_f16(i32 %a) nounwind {
206 ; RV64IZFHMIN-LABEL: uitofp_aext_i32_to_f16:
207 ; RV64IZFHMIN: # %bb.0:
208 ; RV64IZFHMIN-NEXT: slli a0, a0, 32
209 ; RV64IZFHMIN-NEXT: srli a0, a0, 32
210 ; RV64IZFHMIN-NEXT: fcvt.s.lu fa5, a0
211 ; RV64IZFHMIN-NEXT: fcvt.h.s fa0, fa5
212 ; RV64IZFHMIN-NEXT: ret
214 ; RV64IZHINXMIN-LABEL: uitofp_aext_i32_to_f16:
215 ; RV64IZHINXMIN: # %bb.0:
216 ; RV64IZHINXMIN-NEXT: slli a0, a0, 32
217 ; RV64IZHINXMIN-NEXT: srli a0, a0, 32
218 ; RV64IZHINXMIN-NEXT: fcvt.s.lu a0, a0
219 ; RV64IZHINXMIN-NEXT: fcvt.h.s a0, a0
220 ; RV64IZHINXMIN-NEXT: ret
221 %1 = uitofp i32 %a to half
225 define half @uitofp_sext_i32_to_f16(i32 signext %a) nounwind {
226 ; RV64IZFHMIN-LABEL: uitofp_sext_i32_to_f16:
227 ; RV64IZFHMIN: # %bb.0:
228 ; RV64IZFHMIN-NEXT: slli a0, a0, 32
229 ; RV64IZFHMIN-NEXT: srli a0, a0, 32
230 ; RV64IZFHMIN-NEXT: fcvt.s.lu fa5, a0
231 ; RV64IZFHMIN-NEXT: fcvt.h.s fa0, fa5
232 ; RV64IZFHMIN-NEXT: ret
234 ; RV64IZHINXMIN-LABEL: uitofp_sext_i32_to_f16:
235 ; RV64IZHINXMIN: # %bb.0:
236 ; RV64IZHINXMIN-NEXT: slli a0, a0, 32
237 ; RV64IZHINXMIN-NEXT: srli a0, a0, 32
238 ; RV64IZHINXMIN-NEXT: fcvt.s.lu a0, a0
239 ; RV64IZHINXMIN-NEXT: fcvt.h.s a0, a0
240 ; RV64IZHINXMIN-NEXT: ret
241 %1 = uitofp i32 %a to half
245 define half @uitofp_zext_i32_to_f16(i32 zeroext %a) nounwind {
246 ; RV64IZFHMIN-LABEL: uitofp_zext_i32_to_f16:
247 ; RV64IZFHMIN: # %bb.0:
248 ; RV64IZFHMIN-NEXT: fcvt.s.lu fa5, a0
249 ; RV64IZFHMIN-NEXT: fcvt.h.s fa0, fa5
250 ; RV64IZFHMIN-NEXT: ret
252 ; RV64IZHINXMIN-LABEL: uitofp_zext_i32_to_f16:
253 ; RV64IZHINXMIN: # %bb.0:
254 ; RV64IZHINXMIN-NEXT: fcvt.s.lu a0, a0
255 ; RV64IZHINXMIN-NEXT: fcvt.h.s a0, a0
256 ; RV64IZHINXMIN-NEXT: ret
257 %1 = uitofp i32 %a to half
261 define half @sitofp_aext_i32_to_f16(i32 %a) nounwind {
262 ; RV64IZFHMIN-LABEL: sitofp_aext_i32_to_f16:
263 ; RV64IZFHMIN: # %bb.0:
264 ; RV64IZFHMIN-NEXT: sext.w a0, a0
265 ; RV64IZFHMIN-NEXT: fcvt.s.l fa5, a0
266 ; RV64IZFHMIN-NEXT: fcvt.h.s fa0, fa5
267 ; RV64IZFHMIN-NEXT: ret
269 ; RV64IZHINXMIN-LABEL: sitofp_aext_i32_to_f16:
270 ; RV64IZHINXMIN: # %bb.0:
271 ; RV64IZHINXMIN-NEXT: sext.w a0, a0
272 ; RV64IZHINXMIN-NEXT: fcvt.s.l a0, a0
273 ; RV64IZHINXMIN-NEXT: fcvt.h.s a0, a0
274 ; RV64IZHINXMIN-NEXT: ret
275 %1 = sitofp i32 %a to half
279 define half @sitofp_sext_i32_to_f16(i32 signext %a) nounwind {
280 ; RV64IZFHMIN-LABEL: sitofp_sext_i32_to_f16:
281 ; RV64IZFHMIN: # %bb.0:
282 ; RV64IZFHMIN-NEXT: fcvt.s.l fa5, a0
283 ; RV64IZFHMIN-NEXT: fcvt.h.s fa0, fa5
284 ; RV64IZFHMIN-NEXT: ret
286 ; RV64IZHINXMIN-LABEL: sitofp_sext_i32_to_f16:
287 ; RV64IZHINXMIN: # %bb.0:
288 ; RV64IZHINXMIN-NEXT: fcvt.s.l a0, a0
289 ; RV64IZHINXMIN-NEXT: fcvt.h.s a0, a0
290 ; RV64IZHINXMIN-NEXT: ret
291 %1 = sitofp i32 %a to half
295 define half @sitofp_zext_i32_to_f16(i32 zeroext %a) nounwind {
296 ; RV64IZFHMIN-LABEL: sitofp_zext_i32_to_f16:
297 ; RV64IZFHMIN: # %bb.0:
298 ; RV64IZFHMIN-NEXT: sext.w a0, a0
299 ; RV64IZFHMIN-NEXT: fcvt.s.l fa5, a0
300 ; RV64IZFHMIN-NEXT: fcvt.h.s fa0, fa5
301 ; RV64IZFHMIN-NEXT: ret
303 ; RV64IZHINXMIN-LABEL: sitofp_zext_i32_to_f16:
304 ; RV64IZHINXMIN: # %bb.0:
305 ; RV64IZHINXMIN-NEXT: sext.w a0, a0
306 ; RV64IZHINXMIN-NEXT: fcvt.s.l a0, a0
307 ; RV64IZHINXMIN-NEXT: fcvt.h.s a0, a0
308 ; RV64IZHINXMIN-NEXT: ret
309 %1 = sitofp i32 %a to half