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: slli a0, a0, 48
127 ; RV64IZHINX-NEXT: srai a0, a0, 48
128 ; RV64IZHINX-NEXT: ret
129 %1 = fadd half %a, %b
130 %2 = bitcast half %1 to i16
134 define zeroext i16 @bcvt_f16_to_zext_i16(half %a, half %b) nounwind {
135 ; RV64IZFH-LABEL: bcvt_f16_to_zext_i16:
137 ; RV64IZFH-NEXT: fadd.h fa5, fa0, fa1
138 ; RV64IZFH-NEXT: fmv.x.h a0, fa5
139 ; RV64IZFH-NEXT: slli a0, a0, 48
140 ; RV64IZFH-NEXT: srli a0, a0, 48
143 ; RV64IZHINX-LABEL: bcvt_f16_to_zext_i16:
144 ; RV64IZHINX: # %bb.0:
145 ; RV64IZHINX-NEXT: fadd.h a0, a0, a1
146 ; RV64IZHINX-NEXT: slli a0, a0, 48
147 ; RV64IZHINX-NEXT: srli a0, a0, 48
148 ; RV64IZHINX-NEXT: ret
149 %1 = fadd half %a, %b
150 %2 = bitcast half %1 to i16
154 define half @bcvt_i64_to_f16_via_i16(i64 %a, i64 %b) nounwind {
155 ; RV64IZFH-LABEL: bcvt_i64_to_f16_via_i16:
157 ; RV64IZFH-NEXT: fmv.h.x fa5, a0
158 ; RV64IZFH-NEXT: fmv.h.x fa4, a1
159 ; RV64IZFH-NEXT: fadd.h fa0, fa5, fa4
162 ; RV64IZHINX-LABEL: bcvt_i64_to_f16_via_i16:
163 ; RV64IZHINX: # %bb.0:
164 ; RV64IZHINX-NEXT: fadd.h a0, a0, a1
165 ; RV64IZHINX-NEXT: ret
166 %1 = trunc i64 %a to i16
167 %2 = trunc i64 %b to i16
168 %3 = bitcast i16 %1 to half
169 %4 = bitcast i16 %2 to half
170 %5 = fadd half %3, %4
174 define half @uitofp_aext_i32_to_f16(i32 %a) nounwind {
175 ; RV64IZFH-LABEL: uitofp_aext_i32_to_f16:
177 ; RV64IZFH-NEXT: fcvt.h.wu fa0, a0
180 ; RV64IZHINX-LABEL: uitofp_aext_i32_to_f16:
181 ; RV64IZHINX: # %bb.0:
182 ; RV64IZHINX-NEXT: fcvt.h.wu a0, a0
183 ; RV64IZHINX-NEXT: ret
184 %1 = uitofp i32 %a to half
188 define half @uitofp_sext_i32_to_f16(i32 signext %a) nounwind {
189 ; RV64IZFH-LABEL: uitofp_sext_i32_to_f16:
191 ; RV64IZFH-NEXT: fcvt.h.wu fa0, a0
194 ; RV64IZHINX-LABEL: uitofp_sext_i32_to_f16:
195 ; RV64IZHINX: # %bb.0:
196 ; RV64IZHINX-NEXT: fcvt.h.wu a0, a0
197 ; RV64IZHINX-NEXT: ret
198 %1 = uitofp i32 %a to half
202 define half @uitofp_zext_i32_to_f16(i32 zeroext %a) nounwind {
203 ; RV64IZFH-LABEL: uitofp_zext_i32_to_f16:
205 ; RV64IZFH-NEXT: fcvt.h.wu fa0, a0
208 ; RV64IZHINX-LABEL: uitofp_zext_i32_to_f16:
209 ; RV64IZHINX: # %bb.0:
210 ; RV64IZHINX-NEXT: fcvt.h.wu a0, a0
211 ; RV64IZHINX-NEXT: ret
212 %1 = uitofp i32 %a to half
216 define half @sitofp_aext_i32_to_f16(i32 %a) nounwind {
217 ; RV64IZFH-LABEL: sitofp_aext_i32_to_f16:
219 ; RV64IZFH-NEXT: fcvt.h.w fa0, a0
222 ; RV64IZHINX-LABEL: sitofp_aext_i32_to_f16:
223 ; RV64IZHINX: # %bb.0:
224 ; RV64IZHINX-NEXT: fcvt.h.w a0, a0
225 ; RV64IZHINX-NEXT: ret
226 %1 = sitofp i32 %a to half
230 define half @sitofp_sext_i32_to_f16(i32 signext %a) nounwind {
231 ; RV64IZFH-LABEL: sitofp_sext_i32_to_f16:
233 ; RV64IZFH-NEXT: fcvt.h.w fa0, a0
236 ; RV64IZHINX-LABEL: sitofp_sext_i32_to_f16:
237 ; RV64IZHINX: # %bb.0:
238 ; RV64IZHINX-NEXT: fcvt.h.w a0, a0
239 ; RV64IZHINX-NEXT: ret
240 %1 = sitofp i32 %a to half
244 define half @sitofp_zext_i32_to_f16(i32 zeroext %a) nounwind {
245 ; RV64IZFH-LABEL: sitofp_zext_i32_to_f16:
247 ; RV64IZFH-NEXT: fcvt.h.w fa0, a0
250 ; RV64IZHINX-LABEL: sitofp_zext_i32_to_f16:
251 ; RV64IZHINX: # %bb.0:
252 ; RV64IZHINX-NEXT: fcvt.h.w a0, a0
253 ; RV64IZHINX-NEXT: ret
254 %1 = sitofp i32 %a to half