1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv64 -mattr=+zfh -verify-machineinstrs \
3 ; RUN: -target-abi lp64f < %s | FileCheck %s -check-prefix=RV64IZFH
4 ; RUN: llc -mtriple=riscv64 -mattr=+zhinx -verify-machineinstrs \
5 ; RUN: -target-abi lp64 < %s | FileCheck %s -check-prefix=RV64IZHINX
7 ; This file exhaustively checks half<->i32 conversions. In general,
8 ; fcvt.l[u].h can be selected instead of fcvt.w[u].h because poison is
9 ; generated for an fpto[s|u]i conversion if the result doesn't fit in the
12 define i32 @aext_fptosi(half %a) nounwind {
13 ; RV64IZFH-LABEL: aext_fptosi:
15 ; RV64IZFH-NEXT: fcvt.w.h a0, fa0, rtz
18 ; RV64IZHINX-LABEL: aext_fptosi:
19 ; RV64IZHINX: # %bb.0:
20 ; RV64IZHINX-NEXT: fcvt.w.h a0, a0, rtz
21 ; RV64IZHINX-NEXT: ret
22 %1 = fptosi half %a to i32
26 define signext i32 @sext_fptosi(half %a) nounwind {
27 ; RV64IZFH-LABEL: sext_fptosi:
29 ; RV64IZFH-NEXT: fcvt.w.h a0, fa0, rtz
32 ; RV64IZHINX-LABEL: sext_fptosi:
33 ; RV64IZHINX: # %bb.0:
34 ; RV64IZHINX-NEXT: fcvt.w.h a0, a0, rtz
35 ; RV64IZHINX-NEXT: ret
36 %1 = fptosi half %a to i32
40 define zeroext i32 @zext_fptosi(half %a) nounwind {
41 ; RV64IZFH-LABEL: zext_fptosi:
43 ; RV64IZFH-NEXT: fcvt.w.h a0, fa0, rtz
44 ; RV64IZFH-NEXT: slli a0, a0, 32
45 ; RV64IZFH-NEXT: srli a0, a0, 32
48 ; RV64IZHINX-LABEL: zext_fptosi:
49 ; RV64IZHINX: # %bb.0:
50 ; RV64IZHINX-NEXT: fcvt.w.h a0, a0, rtz
51 ; RV64IZHINX-NEXT: slli a0, a0, 32
52 ; RV64IZHINX-NEXT: srli a0, a0, 32
53 ; RV64IZHINX-NEXT: ret
54 %1 = fptosi half %a to i32
58 define i32 @aext_fptoui(half %a) nounwind {
59 ; RV64IZFH-LABEL: aext_fptoui:
61 ; RV64IZFH-NEXT: fcvt.wu.h a0, fa0, rtz
64 ; RV64IZHINX-LABEL: aext_fptoui:
65 ; RV64IZHINX: # %bb.0:
66 ; RV64IZHINX-NEXT: fcvt.wu.h a0, a0, rtz
67 ; RV64IZHINX-NEXT: ret
68 %1 = fptoui half %a to i32
72 define signext i32 @sext_fptoui(half %a) nounwind {
73 ; RV64IZFH-LABEL: sext_fptoui:
75 ; RV64IZFH-NEXT: fcvt.wu.h a0, fa0, rtz
78 ; RV64IZHINX-LABEL: sext_fptoui:
79 ; RV64IZHINX: # %bb.0:
80 ; RV64IZHINX-NEXT: fcvt.wu.h a0, a0, rtz
81 ; RV64IZHINX-NEXT: ret
82 %1 = fptoui half %a to i32
86 define zeroext i32 @zext_fptoui(half %a) nounwind {
87 ; RV64IZFH-LABEL: zext_fptoui:
89 ; RV64IZFH-NEXT: fcvt.lu.h a0, fa0, rtz
92 ; RV64IZHINX-LABEL: zext_fptoui:
93 ; RV64IZHINX: # %bb.0:
94 ; RV64IZHINX-NEXT: fcvt.lu.h a0, a0, rtz
95 ; RV64IZHINX-NEXT: ret
96 %1 = fptoui half %a to i32
100 define i16 @bcvt_f16_to_aext_i16(half %a, half %b) nounwind {
101 ; RV64IZFH-LABEL: bcvt_f16_to_aext_i16:
103 ; RV64IZFH-NEXT: fadd.h fa5, fa0, fa1
104 ; RV64IZFH-NEXT: fmv.x.h a0, fa5
107 ; RV64IZHINX-LABEL: bcvt_f16_to_aext_i16:
108 ; RV64IZHINX: # %bb.0:
109 ; RV64IZHINX-NEXT: fadd.h a0, a0, a1
110 ; RV64IZHINX-NEXT: ret
111 %1 = fadd half %a, %b
112 %2 = bitcast half %1 to i16
116 define signext i16 @bcvt_f16_to_sext_i16(half %a, half %b) nounwind {
117 ; RV64IZFH-LABEL: bcvt_f16_to_sext_i16:
119 ; RV64IZFH-NEXT: fadd.h fa5, fa0, fa1
120 ; RV64IZFH-NEXT: fmv.x.h a0, fa5
123 ; RV64IZHINX-LABEL: bcvt_f16_to_sext_i16:
124 ; RV64IZHINX: # %bb.0:
125 ; RV64IZHINX-NEXT: fadd.h a0, a0, a1
126 ; RV64IZHINX-NEXT: ret
127 %1 = fadd half %a, %b
128 %2 = bitcast half %1 to i16
132 define zeroext i16 @bcvt_f16_to_zext_i16(half %a, half %b) nounwind {
133 ; RV64IZFH-LABEL: bcvt_f16_to_zext_i16:
135 ; RV64IZFH-NEXT: fadd.h fa5, fa0, fa1
136 ; RV64IZFH-NEXT: fmv.x.h a0, fa5
137 ; RV64IZFH-NEXT: slli a0, a0, 48
138 ; RV64IZFH-NEXT: srli a0, a0, 48
141 ; RV64IZHINX-LABEL: bcvt_f16_to_zext_i16:
142 ; RV64IZHINX: # %bb.0:
143 ; RV64IZHINX-NEXT: fadd.h a0, a0, a1
144 ; RV64IZHINX-NEXT: slli a0, a0, 48
145 ; RV64IZHINX-NEXT: srli a0, a0, 48
146 ; RV64IZHINX-NEXT: ret
147 %1 = fadd half %a, %b
148 %2 = bitcast half %1 to i16
152 define half @bcvt_i64_to_f16_via_i16(i64 %a, i64 %b) nounwind {
153 ; RV64IZFH-LABEL: bcvt_i64_to_f16_via_i16:
155 ; RV64IZFH-NEXT: fmv.h.x fa5, a0
156 ; RV64IZFH-NEXT: fmv.h.x fa4, a1
157 ; RV64IZFH-NEXT: fadd.h fa0, fa5, fa4
160 ; RV64IZHINX-LABEL: bcvt_i64_to_f16_via_i16:
161 ; RV64IZHINX: # %bb.0:
162 ; RV64IZHINX-NEXT: fadd.h a0, a0, a1
163 ; RV64IZHINX-NEXT: ret
164 %1 = trunc i64 %a to i16
165 %2 = trunc i64 %b to i16
166 %3 = bitcast i16 %1 to half
167 %4 = bitcast i16 %2 to half
168 %5 = fadd half %3, %4
172 define half @uitofp_aext_i32_to_f16(i32 %a) nounwind {
173 ; RV64IZFH-LABEL: uitofp_aext_i32_to_f16:
175 ; RV64IZFH-NEXT: fcvt.h.wu fa0, a0
178 ; RV64IZHINX-LABEL: uitofp_aext_i32_to_f16:
179 ; RV64IZHINX: # %bb.0:
180 ; RV64IZHINX-NEXT: fcvt.h.wu a0, a0
181 ; RV64IZHINX-NEXT: ret
182 %1 = uitofp i32 %a to half
186 define half @uitofp_sext_i32_to_f16(i32 signext %a) nounwind {
187 ; RV64IZFH-LABEL: uitofp_sext_i32_to_f16:
189 ; RV64IZFH-NEXT: fcvt.h.wu fa0, a0
192 ; RV64IZHINX-LABEL: uitofp_sext_i32_to_f16:
193 ; RV64IZHINX: # %bb.0:
194 ; RV64IZHINX-NEXT: fcvt.h.wu a0, a0
195 ; RV64IZHINX-NEXT: ret
196 %1 = uitofp i32 %a to half
200 define half @uitofp_zext_i32_to_f16(i32 zeroext %a) nounwind {
201 ; RV64IZFH-LABEL: uitofp_zext_i32_to_f16:
203 ; RV64IZFH-NEXT: fcvt.h.wu fa0, a0
206 ; RV64IZHINX-LABEL: uitofp_zext_i32_to_f16:
207 ; RV64IZHINX: # %bb.0:
208 ; RV64IZHINX-NEXT: fcvt.h.wu a0, a0
209 ; RV64IZHINX-NEXT: ret
210 %1 = uitofp i32 %a to half
214 define half @sitofp_aext_i32_to_f16(i32 %a) nounwind {
215 ; RV64IZFH-LABEL: sitofp_aext_i32_to_f16:
217 ; RV64IZFH-NEXT: fcvt.h.w fa0, a0
220 ; RV64IZHINX-LABEL: sitofp_aext_i32_to_f16:
221 ; RV64IZHINX: # %bb.0:
222 ; RV64IZHINX-NEXT: fcvt.h.w a0, a0
223 ; RV64IZHINX-NEXT: ret
224 %1 = sitofp i32 %a to half
228 define half @sitofp_sext_i32_to_f16(i32 signext %a) nounwind {
229 ; RV64IZFH-LABEL: sitofp_sext_i32_to_f16:
231 ; RV64IZFH-NEXT: fcvt.h.w fa0, a0
234 ; RV64IZHINX-LABEL: sitofp_sext_i32_to_f16:
235 ; RV64IZHINX: # %bb.0:
236 ; RV64IZHINX-NEXT: fcvt.h.w a0, a0
237 ; RV64IZHINX-NEXT: ret
238 %1 = sitofp i32 %a to half
242 define half @sitofp_zext_i32_to_f16(i32 zeroext %a) nounwind {
243 ; RV64IZFH-LABEL: sitofp_zext_i32_to_f16:
245 ; RV64IZFH-NEXT: fcvt.h.w fa0, a0
248 ; RV64IZHINX-LABEL: sitofp_zext_i32_to_f16:
249 ; RV64IZHINX: # %bb.0:
250 ; RV64IZHINX-NEXT: fcvt.h.w a0, a0
251 ; RV64IZHINX-NEXT: ret
252 %1 = sitofp i32 %a to half