1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv64 -mattr=+f -target-abi=lp64f -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefix=RV64IF
4 ; RUN: llc -mtriple=riscv64 -mattr=+zfinx -target-abi=lp64 -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefix=RV64IZFINX
7 ; This file exhaustively checks float<->i32 conversions. In general,
8 ; fcvt.l[u].s can be selected instead of fcvt.w[u].s 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(float %a) nounwind {
13 ; RV64IF-LABEL: aext_fptosi:
15 ; RV64IF-NEXT: fcvt.w.s a0, fa0, rtz
18 ; RV64IZFINX-LABEL: aext_fptosi:
19 ; RV64IZFINX: # %bb.0:
20 ; RV64IZFINX-NEXT: fcvt.w.s a0, a0, rtz
21 ; RV64IZFINX-NEXT: ret
22 %1 = fptosi float %a to i32
26 define signext i32 @sext_fptosi(float %a) nounwind {
27 ; RV64IF-LABEL: sext_fptosi:
29 ; RV64IF-NEXT: fcvt.w.s a0, fa0, rtz
32 ; RV64IZFINX-LABEL: sext_fptosi:
33 ; RV64IZFINX: # %bb.0:
34 ; RV64IZFINX-NEXT: fcvt.w.s a0, a0, rtz
35 ; RV64IZFINX-NEXT: ret
36 %1 = fptosi float %a to i32
40 define zeroext i32 @zext_fptosi(float %a) nounwind {
41 ; RV64IF-LABEL: zext_fptosi:
43 ; RV64IF-NEXT: fcvt.w.s a0, fa0, rtz
44 ; RV64IF-NEXT: slli a0, a0, 32
45 ; RV64IF-NEXT: srli a0, a0, 32
48 ; RV64IZFINX-LABEL: zext_fptosi:
49 ; RV64IZFINX: # %bb.0:
50 ; RV64IZFINX-NEXT: fcvt.w.s a0, a0, rtz
51 ; RV64IZFINX-NEXT: slli a0, a0, 32
52 ; RV64IZFINX-NEXT: srli a0, a0, 32
53 ; RV64IZFINX-NEXT: ret
54 %1 = fptosi float %a to i32
58 define i32 @aext_fptoui(float %a) nounwind {
59 ; RV64IF-LABEL: aext_fptoui:
61 ; RV64IF-NEXT: fcvt.wu.s a0, fa0, rtz
64 ; RV64IZFINX-LABEL: aext_fptoui:
65 ; RV64IZFINX: # %bb.0:
66 ; RV64IZFINX-NEXT: fcvt.wu.s a0, a0, rtz
67 ; RV64IZFINX-NEXT: ret
68 %1 = fptoui float %a to i32
72 define signext i32 @sext_fptoui(float %a) nounwind {
73 ; RV64IF-LABEL: sext_fptoui:
75 ; RV64IF-NEXT: fcvt.wu.s a0, fa0, rtz
78 ; RV64IZFINX-LABEL: sext_fptoui:
79 ; RV64IZFINX: # %bb.0:
80 ; RV64IZFINX-NEXT: fcvt.wu.s a0, a0, rtz
81 ; RV64IZFINX-NEXT: ret
82 %1 = fptoui float %a to i32
86 define zeroext i32 @zext_fptoui(float %a) nounwind {
87 ; RV64IF-LABEL: zext_fptoui:
89 ; RV64IF-NEXT: fcvt.lu.s a0, fa0, rtz
92 ; RV64IZFINX-LABEL: zext_fptoui:
93 ; RV64IZFINX: # %bb.0:
94 ; RV64IZFINX-NEXT: fcvt.lu.s a0, a0, rtz
95 ; RV64IZFINX-NEXT: ret
96 %1 = fptoui float %a to i32
100 define i32 @bcvt_f32_to_aext_i32(float %a, float %b) nounwind {
101 ; RV64IF-LABEL: bcvt_f32_to_aext_i32:
103 ; RV64IF-NEXT: fadd.s fa5, fa0, fa1
104 ; RV64IF-NEXT: fmv.x.w a0, fa5
107 ; RV64IZFINX-LABEL: bcvt_f32_to_aext_i32:
108 ; RV64IZFINX: # %bb.0:
109 ; RV64IZFINX-NEXT: fadd.s a0, a0, a1
110 ; RV64IZFINX-NEXT: ret
111 %1 = fadd float %a, %b
112 %2 = bitcast float %1 to i32
116 define signext i32 @bcvt_f32_to_sext_i32(float %a, float %b) nounwind {
117 ; RV64IF-LABEL: bcvt_f32_to_sext_i32:
119 ; RV64IF-NEXT: fadd.s fa5, fa0, fa1
120 ; RV64IF-NEXT: fmv.x.w a0, fa5
123 ; RV64IZFINX-LABEL: bcvt_f32_to_sext_i32:
124 ; RV64IZFINX: # %bb.0:
125 ; RV64IZFINX-NEXT: fadd.s a0, a0, a1
126 ; RV64IZFINX-NEXT: sext.w a0, a0
127 ; RV64IZFINX-NEXT: ret
128 %1 = fadd float %a, %b
129 %2 = bitcast float %1 to i32
133 define zeroext i32 @bcvt_f32_to_zext_i32(float %a, float %b) nounwind {
134 ; RV64IF-LABEL: bcvt_f32_to_zext_i32:
136 ; RV64IF-NEXT: fadd.s fa5, fa0, fa1
137 ; RV64IF-NEXT: fmv.x.w a0, fa5
138 ; RV64IF-NEXT: slli a0, a0, 32
139 ; RV64IF-NEXT: srli a0, a0, 32
142 ; RV64IZFINX-LABEL: bcvt_f32_to_zext_i32:
143 ; RV64IZFINX: # %bb.0:
144 ; RV64IZFINX-NEXT: fadd.s a0, a0, a1
145 ; RV64IZFINX-NEXT: slli a0, a0, 32
146 ; RV64IZFINX-NEXT: srli a0, a0, 32
147 ; RV64IZFINX-NEXT: ret
148 %1 = fadd float %a, %b
149 %2 = bitcast float %1 to i32
153 define float @bcvt_i64_to_f32_via_i32(i64 %a, i64 %b) nounwind {
154 ; RV64IF-LABEL: bcvt_i64_to_f32_via_i32:
156 ; RV64IF-NEXT: fmv.w.x fa5, a0
157 ; RV64IF-NEXT: fmv.w.x fa4, a1
158 ; RV64IF-NEXT: fadd.s fa0, fa5, fa4
161 ; RV64IZFINX-LABEL: bcvt_i64_to_f32_via_i32:
162 ; RV64IZFINX: # %bb.0:
163 ; RV64IZFINX-NEXT: fadd.s a0, a0, a1
164 ; RV64IZFINX-NEXT: ret
165 %1 = trunc i64 %a to i32
166 %2 = trunc i64 %b to i32
167 %3 = bitcast i32 %1 to float
168 %4 = bitcast i32 %2 to float
169 %5 = fadd float %3, %4
173 define float @uitofp_aext_i32_to_f32(i32 %a) nounwind {
174 ; RV64IF-LABEL: uitofp_aext_i32_to_f32:
176 ; RV64IF-NEXT: fcvt.s.wu fa0, a0
179 ; RV64IZFINX-LABEL: uitofp_aext_i32_to_f32:
180 ; RV64IZFINX: # %bb.0:
181 ; RV64IZFINX-NEXT: fcvt.s.wu a0, a0
182 ; RV64IZFINX-NEXT: ret
183 %1 = uitofp i32 %a to float
187 define float @uitofp_sext_i32_to_f32(i32 signext %a) nounwind {
188 ; RV64IF-LABEL: uitofp_sext_i32_to_f32:
190 ; RV64IF-NEXT: fcvt.s.wu fa0, a0
193 ; RV64IZFINX-LABEL: uitofp_sext_i32_to_f32:
194 ; RV64IZFINX: # %bb.0:
195 ; RV64IZFINX-NEXT: fcvt.s.wu a0, a0
196 ; RV64IZFINX-NEXT: ret
197 %1 = uitofp i32 %a to float
201 define float @uitofp_zext_i32_to_f32(i32 zeroext %a) nounwind {
202 ; RV64IF-LABEL: uitofp_zext_i32_to_f32:
204 ; RV64IF-NEXT: fcvt.s.wu fa0, a0
207 ; RV64IZFINX-LABEL: uitofp_zext_i32_to_f32:
208 ; RV64IZFINX: # %bb.0:
209 ; RV64IZFINX-NEXT: fcvt.s.wu a0, a0
210 ; RV64IZFINX-NEXT: ret
211 %1 = uitofp i32 %a to float
215 define float @sitofp_aext_i32_to_f32(i32 %a) nounwind {
216 ; RV64IF-LABEL: sitofp_aext_i32_to_f32:
218 ; RV64IF-NEXT: fcvt.s.w fa0, a0
221 ; RV64IZFINX-LABEL: sitofp_aext_i32_to_f32:
222 ; RV64IZFINX: # %bb.0:
223 ; RV64IZFINX-NEXT: fcvt.s.w a0, a0
224 ; RV64IZFINX-NEXT: ret
225 %1 = sitofp i32 %a to float
229 define float @sitofp_sext_i32_to_f32(i32 signext %a) nounwind {
230 ; RV64IF-LABEL: sitofp_sext_i32_to_f32:
232 ; RV64IF-NEXT: fcvt.s.w fa0, a0
235 ; RV64IZFINX-LABEL: sitofp_sext_i32_to_f32:
236 ; RV64IZFINX: # %bb.0:
237 ; RV64IZFINX-NEXT: fcvt.s.w a0, a0
238 ; RV64IZFINX-NEXT: ret
239 %1 = sitofp i32 %a to float
243 define float @sitofp_zext_i32_to_f32(i32 zeroext %a) nounwind {
244 ; RV64IF-LABEL: sitofp_zext_i32_to_f32:
246 ; RV64IF-NEXT: fcvt.s.w fa0, a0
249 ; RV64IZFINX-LABEL: sitofp_zext_i32_to_f32:
250 ; RV64IZFINX: # %bb.0:
251 ; RV64IZFINX-NEXT: fcvt.s.w a0, a0
252 ; RV64IZFINX-NEXT: ret
253 %1 = sitofp i32 %a to float