1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv64 -mattr=+f -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefix=RV64IF
5 ; This file exhaustively checks float<->i32 conversions. In general,
6 ; fcvt.l[u].s can be selected instead of fcvt.w[u].s because poison is
7 ; generated for an fpto[s|u]i conversion if the result doesn't fit in the
10 define i32 @aext_fptosi(float %a) nounwind {
11 ; RV64IF-LABEL: aext_fptosi:
13 ; RV64IF-NEXT: fmv.w.x ft0, a0
14 ; RV64IF-NEXT: fcvt.l.s a0, ft0, rtz
16 %1 = fptosi float %a to i32
20 define signext i32 @sext_fptosi(float %a) nounwind {
21 ; RV64IF-LABEL: sext_fptosi:
23 ; RV64IF-NEXT: fmv.w.x ft0, a0
24 ; RV64IF-NEXT: fcvt.l.s a0, ft0, rtz
26 %1 = fptosi float %a to i32
30 define zeroext i32 @zext_fptosi(float %a) nounwind {
31 ; RV64IF-LABEL: zext_fptosi:
33 ; RV64IF-NEXT: fmv.w.x ft0, a0
34 ; RV64IF-NEXT: fcvt.l.s a0, ft0, rtz
35 ; RV64IF-NEXT: slli a0, a0, 32
36 ; RV64IF-NEXT: srli a0, a0, 32
38 %1 = fptosi float %a to i32
42 define i32 @aext_fptoui(float %a) nounwind {
43 ; RV64IF-LABEL: aext_fptoui:
45 ; RV64IF-NEXT: fmv.w.x ft0, a0
46 ; RV64IF-NEXT: fcvt.lu.s a0, ft0, rtz
48 %1 = fptoui float %a to i32
52 define signext i32 @sext_fptoui(float %a) nounwind {
53 ; RV64IF-LABEL: sext_fptoui:
55 ; RV64IF-NEXT: fmv.w.x ft0, a0
56 ; RV64IF-NEXT: fcvt.wu.s a0, ft0, rtz
58 %1 = fptoui float %a to i32
62 define zeroext i32 @zext_fptoui(float %a) nounwind {
63 ; RV64IF-LABEL: zext_fptoui:
65 ; RV64IF-NEXT: fmv.w.x ft0, a0
66 ; RV64IF-NEXT: fcvt.lu.s a0, ft0, rtz
68 %1 = fptoui float %a to i32
72 define i32 @bcvt_f32_to_aext_i32(float %a, float %b) nounwind {
73 ; RV64IF-LABEL: bcvt_f32_to_aext_i32:
75 ; RV64IF-NEXT: fmv.w.x ft0, a1
76 ; RV64IF-NEXT: fmv.w.x ft1, a0
77 ; RV64IF-NEXT: fadd.s ft0, ft1, ft0
78 ; RV64IF-NEXT: fmv.x.w a0, ft0
80 %1 = fadd float %a, %b
81 %2 = bitcast float %1 to i32
85 define signext i32 @bcvt_f32_to_sext_i32(float %a, float %b) nounwind {
86 ; RV64IF-LABEL: bcvt_f32_to_sext_i32:
88 ; RV64IF-NEXT: fmv.w.x ft0, a1
89 ; RV64IF-NEXT: fmv.w.x ft1, a0
90 ; RV64IF-NEXT: fadd.s ft0, ft1, ft0
91 ; RV64IF-NEXT: fmv.x.w a0, ft0
93 %1 = fadd float %a, %b
94 %2 = bitcast float %1 to i32
98 define zeroext i32 @bcvt_f32_to_zext_i32(float %a, float %b) nounwind {
99 ; RV64IF-LABEL: bcvt_f32_to_zext_i32:
101 ; RV64IF-NEXT: fmv.w.x ft0, a1
102 ; RV64IF-NEXT: fmv.w.x ft1, a0
103 ; RV64IF-NEXT: fadd.s ft0, ft1, ft0
104 ; RV64IF-NEXT: fmv.x.w a0, ft0
105 ; RV64IF-NEXT: slli a0, a0, 32
106 ; RV64IF-NEXT: srli a0, a0, 32
108 %1 = fadd float %a, %b
109 %2 = bitcast float %1 to i32
113 define float @bcvt_i64_to_f32_via_i32(i64 %a, i64 %b) nounwind {
114 ; RV64IF-LABEL: bcvt_i64_to_f32_via_i32:
116 ; RV64IF-NEXT: fmv.w.x ft0, a0
117 ; RV64IF-NEXT: fmv.w.x ft1, a1
118 ; RV64IF-NEXT: fadd.s ft0, ft0, ft1
119 ; RV64IF-NEXT: fmv.x.w a0, ft0
121 %1 = trunc i64 %a to i32
122 %2 = trunc i64 %b to i32
123 %3 = bitcast i32 %1 to float
124 %4 = bitcast i32 %2 to float
125 %5 = fadd float %3, %4
129 define float @uitofp_aext_i32_to_f32(i32 %a) nounwind {
130 ; RV64IF-LABEL: uitofp_aext_i32_to_f32:
132 ; RV64IF-NEXT: fcvt.s.wu ft0, a0
133 ; RV64IF-NEXT: fmv.x.w a0, ft0
135 %1 = uitofp i32 %a to float
139 define float @uitofp_sext_i32_to_f32(i32 signext %a) nounwind {
140 ; RV64IF-LABEL: uitofp_sext_i32_to_f32:
142 ; RV64IF-NEXT: fcvt.s.wu ft0, a0
143 ; RV64IF-NEXT: fmv.x.w a0, ft0
145 %1 = uitofp i32 %a to float
149 define float @uitofp_zext_i32_to_f32(i32 zeroext %a) nounwind {
150 ; RV64IF-LABEL: uitofp_zext_i32_to_f32:
152 ; RV64IF-NEXT: fcvt.s.wu ft0, a0
153 ; RV64IF-NEXT: fmv.x.w a0, ft0
155 %1 = uitofp i32 %a to float
159 define float @sitofp_aext_i32_to_f32(i32 %a) nounwind {
160 ; RV64IF-LABEL: sitofp_aext_i32_to_f32:
162 ; RV64IF-NEXT: fcvt.s.w ft0, a0
163 ; RV64IF-NEXT: fmv.x.w a0, ft0
165 %1 = sitofp i32 %a to float
169 define float @sitofp_sext_i32_to_f32(i32 signext %a) nounwind {
170 ; RV64IF-LABEL: sitofp_sext_i32_to_f32:
172 ; RV64IF-NEXT: fcvt.s.l ft0, a0
173 ; RV64IF-NEXT: fmv.x.w a0, ft0
175 %1 = sitofp i32 %a to float
179 define float @sitofp_zext_i32_to_f32(i32 zeroext %a) nounwind {
180 ; RV64IF-LABEL: sitofp_zext_i32_to_f32:
182 ; RV64IF-NEXT: fcvt.s.w ft0, a0
183 ; RV64IF-NEXT: fmv.x.w a0, ft0
185 %1 = sitofp i32 %a to float