1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -mattr=+d,+zfh,+zvfh,+v -target-abi=ilp32d \
3 ; RUN: -verify-machineinstrs < %s | FileCheck %s
4 ; RUN: llc -mtriple=riscv64 -mattr=+d,+zfh,+zvfh,+v -target-abi=lp64d \
5 ; RUN: -verify-machineinstrs < %s | FileCheck %s
7 ; This file tests the code generation for `llvm.round.*` on scalable vector type.
9 define <vscale x 1 x half> @round_nxv1f16(<vscale x 1 x half> %x) {
10 ; CHECK-LABEL: round_nxv1f16:
12 ; CHECK-NEXT: lui a0, %hi(.LCPI0_0)
13 ; CHECK-NEXT: flh fa5, %lo(.LCPI0_0)(a0)
14 ; CHECK-NEXT: vsetvli a0, zero, e16, mf4, ta, ma
15 ; CHECK-NEXT: vfabs.v v9, v8
16 ; CHECK-NEXT: vmflt.vf v0, v9, fa5
17 ; CHECK-NEXT: fsrmi a0, 4
18 ; CHECK-NEXT: vfcvt.x.f.v v9, v8, v0.t
20 ; CHECK-NEXT: vfcvt.f.x.v v9, v9, v0.t
21 ; CHECK-NEXT: vsetvli zero, zero, e16, mf4, ta, mu
22 ; CHECK-NEXT: vfsgnj.vv v8, v9, v8, v0.t
24 %a = call <vscale x 1 x half> @llvm.round.nxv1f16(<vscale x 1 x half> %x)
25 ret <vscale x 1 x half> %a
27 declare <vscale x 1 x half> @llvm.round.nxv1f16(<vscale x 1 x half>)
29 define <vscale x 2 x half> @round_nxv2f16(<vscale x 2 x half> %x) {
30 ; CHECK-LABEL: round_nxv2f16:
32 ; CHECK-NEXT: lui a0, %hi(.LCPI1_0)
33 ; CHECK-NEXT: flh fa5, %lo(.LCPI1_0)(a0)
34 ; CHECK-NEXT: vsetvli a0, zero, e16, mf2, ta, ma
35 ; CHECK-NEXT: vfabs.v v9, v8
36 ; CHECK-NEXT: vmflt.vf v0, v9, fa5
37 ; CHECK-NEXT: fsrmi a0, 4
38 ; CHECK-NEXT: vfcvt.x.f.v v9, v8, v0.t
40 ; CHECK-NEXT: vfcvt.f.x.v v9, v9, v0.t
41 ; CHECK-NEXT: vsetvli zero, zero, e16, mf2, ta, mu
42 ; CHECK-NEXT: vfsgnj.vv v8, v9, v8, v0.t
44 %a = call <vscale x 2 x half> @llvm.round.nxv2f16(<vscale x 2 x half> %x)
45 ret <vscale x 2 x half> %a
47 declare <vscale x 2 x half> @llvm.round.nxv2f16(<vscale x 2 x half>)
49 define <vscale x 4 x half> @round_nxv4f16(<vscale x 4 x half> %x) {
50 ; CHECK-LABEL: round_nxv4f16:
52 ; CHECK-NEXT: lui a0, %hi(.LCPI2_0)
53 ; CHECK-NEXT: flh fa5, %lo(.LCPI2_0)(a0)
54 ; CHECK-NEXT: vsetvli a0, zero, e16, m1, ta, ma
55 ; CHECK-NEXT: vfabs.v v9, v8
56 ; CHECK-NEXT: vmflt.vf v0, v9, fa5
57 ; CHECK-NEXT: fsrmi a0, 4
58 ; CHECK-NEXT: vfcvt.x.f.v v9, v8, v0.t
60 ; CHECK-NEXT: vfcvt.f.x.v v9, v9, v0.t
61 ; CHECK-NEXT: vsetvli zero, zero, e16, m1, ta, mu
62 ; CHECK-NEXT: vfsgnj.vv v8, v9, v8, v0.t
64 %a = call <vscale x 4 x half> @llvm.round.nxv4f16(<vscale x 4 x half> %x)
65 ret <vscale x 4 x half> %a
67 declare <vscale x 4 x half> @llvm.round.nxv4f16(<vscale x 4 x half>)
69 define <vscale x 8 x half> @round_nxv8f16(<vscale x 8 x half> %x) {
70 ; CHECK-LABEL: round_nxv8f16:
72 ; CHECK-NEXT: lui a0, %hi(.LCPI3_0)
73 ; CHECK-NEXT: flh fa5, %lo(.LCPI3_0)(a0)
74 ; CHECK-NEXT: vsetvli a0, zero, e16, m2, ta, ma
75 ; CHECK-NEXT: vfabs.v v10, v8
76 ; CHECK-NEXT: vmflt.vf v0, v10, fa5
77 ; CHECK-NEXT: fsrmi a0, 4
78 ; CHECK-NEXT: vfcvt.x.f.v v10, v8, v0.t
80 ; CHECK-NEXT: vfcvt.f.x.v v10, v10, v0.t
81 ; CHECK-NEXT: vsetvli zero, zero, e16, m2, ta, mu
82 ; CHECK-NEXT: vfsgnj.vv v8, v10, v8, v0.t
84 %a = call <vscale x 8 x half> @llvm.round.nxv8f16(<vscale x 8 x half> %x)
85 ret <vscale x 8 x half> %a
87 declare <vscale x 8 x half> @llvm.round.nxv8f16(<vscale x 8 x half>)
89 define <vscale x 16 x half> @round_nxv16f16(<vscale x 16 x half> %x) {
90 ; CHECK-LABEL: round_nxv16f16:
92 ; CHECK-NEXT: lui a0, %hi(.LCPI4_0)
93 ; CHECK-NEXT: flh fa5, %lo(.LCPI4_0)(a0)
94 ; CHECK-NEXT: vsetvli a0, zero, e16, m4, ta, ma
95 ; CHECK-NEXT: vfabs.v v12, v8
96 ; CHECK-NEXT: vmflt.vf v0, v12, fa5
97 ; CHECK-NEXT: fsrmi a0, 4
98 ; CHECK-NEXT: vfcvt.x.f.v v12, v8, v0.t
100 ; CHECK-NEXT: vfcvt.f.x.v v12, v12, v0.t
101 ; CHECK-NEXT: vsetvli zero, zero, e16, m4, ta, mu
102 ; CHECK-NEXT: vfsgnj.vv v8, v12, v8, v0.t
104 %a = call <vscale x 16 x half> @llvm.round.nxv16f16(<vscale x 16 x half> %x)
105 ret <vscale x 16 x half> %a
107 declare <vscale x 16 x half> @llvm.round.nxv16f16(<vscale x 16 x half>)
109 define <vscale x 32 x half> @round_nxv32f16(<vscale x 32 x half> %x) {
110 ; CHECK-LABEL: round_nxv32f16:
112 ; CHECK-NEXT: lui a0, %hi(.LCPI5_0)
113 ; CHECK-NEXT: flh fa5, %lo(.LCPI5_0)(a0)
114 ; CHECK-NEXT: vsetvli a0, zero, e16, m8, ta, ma
115 ; CHECK-NEXT: vfabs.v v16, v8
116 ; CHECK-NEXT: vmflt.vf v0, v16, fa5
117 ; CHECK-NEXT: fsrmi a0, 4
118 ; CHECK-NEXT: vfcvt.x.f.v v16, v8, v0.t
119 ; CHECK-NEXT: fsrm a0
120 ; CHECK-NEXT: vfcvt.f.x.v v16, v16, v0.t
121 ; CHECK-NEXT: vsetvli zero, zero, e16, m8, ta, mu
122 ; CHECK-NEXT: vfsgnj.vv v8, v16, v8, v0.t
124 %a = call <vscale x 32 x half> @llvm.round.nxv32f16(<vscale x 32 x half> %x)
125 ret <vscale x 32 x half> %a
127 declare <vscale x 32 x half> @llvm.round.nxv32f16(<vscale x 32 x half>)
129 define <vscale x 1 x float> @round_nxv1f32(<vscale x 1 x float> %x) {
130 ; CHECK-LABEL: round_nxv1f32:
132 ; CHECK-NEXT: vsetvli a0, zero, e32, mf2, ta, ma
133 ; CHECK-NEXT: vfabs.v v9, v8
134 ; CHECK-NEXT: lui a0, 307200
135 ; CHECK-NEXT: fmv.w.x fa5, a0
136 ; CHECK-NEXT: vmflt.vf v0, v9, fa5
137 ; CHECK-NEXT: fsrmi a0, 4
138 ; CHECK-NEXT: vfcvt.x.f.v v9, v8, v0.t
139 ; CHECK-NEXT: fsrm a0
140 ; CHECK-NEXT: vfcvt.f.x.v v9, v9, v0.t
141 ; CHECK-NEXT: vsetvli zero, zero, e32, mf2, ta, mu
142 ; CHECK-NEXT: vfsgnj.vv v8, v9, v8, v0.t
144 %a = call <vscale x 1 x float> @llvm.round.nxv1f32(<vscale x 1 x float> %x)
145 ret <vscale x 1 x float> %a
147 declare <vscale x 1 x float> @llvm.round.nxv1f32(<vscale x 1 x float>)
149 define <vscale x 2 x float> @round_nxv2f32(<vscale x 2 x float> %x) {
150 ; CHECK-LABEL: round_nxv2f32:
152 ; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, ma
153 ; CHECK-NEXT: vfabs.v v9, v8
154 ; CHECK-NEXT: lui a0, 307200
155 ; CHECK-NEXT: fmv.w.x fa5, a0
156 ; CHECK-NEXT: vmflt.vf v0, v9, fa5
157 ; CHECK-NEXT: fsrmi a0, 4
158 ; CHECK-NEXT: vfcvt.x.f.v v9, v8, v0.t
159 ; CHECK-NEXT: fsrm a0
160 ; CHECK-NEXT: vfcvt.f.x.v v9, v9, v0.t
161 ; CHECK-NEXT: vsetvli zero, zero, e32, m1, ta, mu
162 ; CHECK-NEXT: vfsgnj.vv v8, v9, v8, v0.t
164 %a = call <vscale x 2 x float> @llvm.round.nxv2f32(<vscale x 2 x float> %x)
165 ret <vscale x 2 x float> %a
167 declare <vscale x 2 x float> @llvm.round.nxv2f32(<vscale x 2 x float>)
169 define <vscale x 4 x float> @round_nxv4f32(<vscale x 4 x float> %x) {
170 ; CHECK-LABEL: round_nxv4f32:
172 ; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, ma
173 ; CHECK-NEXT: vfabs.v v10, v8
174 ; CHECK-NEXT: lui a0, 307200
175 ; CHECK-NEXT: fmv.w.x fa5, a0
176 ; CHECK-NEXT: vmflt.vf v0, v10, fa5
177 ; CHECK-NEXT: fsrmi a0, 4
178 ; CHECK-NEXT: vfcvt.x.f.v v10, v8, v0.t
179 ; CHECK-NEXT: fsrm a0
180 ; CHECK-NEXT: vfcvt.f.x.v v10, v10, v0.t
181 ; CHECK-NEXT: vsetvli zero, zero, e32, m2, ta, mu
182 ; CHECK-NEXT: vfsgnj.vv v8, v10, v8, v0.t
184 %a = call <vscale x 4 x float> @llvm.round.nxv4f32(<vscale x 4 x float> %x)
185 ret <vscale x 4 x float> %a
187 declare <vscale x 4 x float> @llvm.round.nxv4f32(<vscale x 4 x float>)
189 define <vscale x 8 x float> @round_nxv8f32(<vscale x 8 x float> %x) {
190 ; CHECK-LABEL: round_nxv8f32:
192 ; CHECK-NEXT: vsetvli a0, zero, e32, m4, ta, ma
193 ; CHECK-NEXT: vfabs.v v12, v8
194 ; CHECK-NEXT: lui a0, 307200
195 ; CHECK-NEXT: fmv.w.x fa5, a0
196 ; CHECK-NEXT: vmflt.vf v0, v12, fa5
197 ; CHECK-NEXT: fsrmi a0, 4
198 ; CHECK-NEXT: vfcvt.x.f.v v12, v8, v0.t
199 ; CHECK-NEXT: fsrm a0
200 ; CHECK-NEXT: vfcvt.f.x.v v12, v12, v0.t
201 ; CHECK-NEXT: vsetvli zero, zero, e32, m4, ta, mu
202 ; CHECK-NEXT: vfsgnj.vv v8, v12, v8, v0.t
204 %a = call <vscale x 8 x float> @llvm.round.nxv8f32(<vscale x 8 x float> %x)
205 ret <vscale x 8 x float> %a
207 declare <vscale x 8 x float> @llvm.round.nxv8f32(<vscale x 8 x float>)
209 define <vscale x 16 x float> @round_nxv16f32(<vscale x 16 x float> %x) {
210 ; CHECK-LABEL: round_nxv16f32:
212 ; CHECK-NEXT: vsetvli a0, zero, e32, m8, ta, ma
213 ; CHECK-NEXT: vfabs.v v16, v8
214 ; CHECK-NEXT: lui a0, 307200
215 ; CHECK-NEXT: fmv.w.x fa5, a0
216 ; CHECK-NEXT: vmflt.vf v0, v16, fa5
217 ; CHECK-NEXT: fsrmi a0, 4
218 ; CHECK-NEXT: vfcvt.x.f.v v16, v8, v0.t
219 ; CHECK-NEXT: fsrm a0
220 ; CHECK-NEXT: vfcvt.f.x.v v16, v16, v0.t
221 ; CHECK-NEXT: vsetvli zero, zero, e32, m8, ta, mu
222 ; CHECK-NEXT: vfsgnj.vv v8, v16, v8, v0.t
224 %a = call <vscale x 16 x float> @llvm.round.nxv16f32(<vscale x 16 x float> %x)
225 ret <vscale x 16 x float> %a
227 declare <vscale x 16 x float> @llvm.round.nxv16f32(<vscale x 16 x float>)
229 define <vscale x 1 x double> @round_nxv1f64(<vscale x 1 x double> %x) {
230 ; CHECK-LABEL: round_nxv1f64:
232 ; CHECK-NEXT: lui a0, %hi(.LCPI11_0)
233 ; CHECK-NEXT: fld fa5, %lo(.LCPI11_0)(a0)
234 ; CHECK-NEXT: vsetvli a0, zero, e64, m1, ta, ma
235 ; CHECK-NEXT: vfabs.v v9, v8
236 ; CHECK-NEXT: vmflt.vf v0, v9, fa5
237 ; CHECK-NEXT: fsrmi a0, 4
238 ; CHECK-NEXT: vfcvt.x.f.v v9, v8, v0.t
239 ; CHECK-NEXT: fsrm a0
240 ; CHECK-NEXT: vfcvt.f.x.v v9, v9, v0.t
241 ; CHECK-NEXT: vsetvli zero, zero, e64, m1, ta, mu
242 ; CHECK-NEXT: vfsgnj.vv v8, v9, v8, v0.t
244 %a = call <vscale x 1 x double> @llvm.round.nxv1f64(<vscale x 1 x double> %x)
245 ret <vscale x 1 x double> %a
247 declare <vscale x 1 x double> @llvm.round.nxv1f64(<vscale x 1 x double>)
249 define <vscale x 2 x double> @round_nxv2f64(<vscale x 2 x double> %x) {
250 ; CHECK-LABEL: round_nxv2f64:
252 ; CHECK-NEXT: lui a0, %hi(.LCPI12_0)
253 ; CHECK-NEXT: fld fa5, %lo(.LCPI12_0)(a0)
254 ; CHECK-NEXT: vsetvli a0, zero, e64, m2, ta, ma
255 ; CHECK-NEXT: vfabs.v v10, v8
256 ; CHECK-NEXT: vmflt.vf v0, v10, fa5
257 ; CHECK-NEXT: fsrmi a0, 4
258 ; CHECK-NEXT: vfcvt.x.f.v v10, v8, v0.t
259 ; CHECK-NEXT: fsrm a0
260 ; CHECK-NEXT: vfcvt.f.x.v v10, v10, v0.t
261 ; CHECK-NEXT: vsetvli zero, zero, e64, m2, ta, mu
262 ; CHECK-NEXT: vfsgnj.vv v8, v10, v8, v0.t
264 %a = call <vscale x 2 x double> @llvm.round.nxv2f64(<vscale x 2 x double> %x)
265 ret <vscale x 2 x double> %a
267 declare <vscale x 2 x double> @llvm.round.nxv2f64(<vscale x 2 x double>)
269 define <vscale x 4 x double> @round_nxv4f64(<vscale x 4 x double> %x) {
270 ; CHECK-LABEL: round_nxv4f64:
272 ; CHECK-NEXT: lui a0, %hi(.LCPI13_0)
273 ; CHECK-NEXT: fld fa5, %lo(.LCPI13_0)(a0)
274 ; CHECK-NEXT: vsetvli a0, zero, e64, m4, ta, ma
275 ; CHECK-NEXT: vfabs.v v12, v8
276 ; CHECK-NEXT: vmflt.vf v0, v12, fa5
277 ; CHECK-NEXT: fsrmi a0, 4
278 ; CHECK-NEXT: vfcvt.x.f.v v12, v8, v0.t
279 ; CHECK-NEXT: fsrm a0
280 ; CHECK-NEXT: vfcvt.f.x.v v12, v12, v0.t
281 ; CHECK-NEXT: vsetvli zero, zero, e64, m4, ta, mu
282 ; CHECK-NEXT: vfsgnj.vv v8, v12, v8, v0.t
284 %a = call <vscale x 4 x double> @llvm.round.nxv4f64(<vscale x 4 x double> %x)
285 ret <vscale x 4 x double> %a
287 declare <vscale x 4 x double> @llvm.round.nxv4f64(<vscale x 4 x double>)
289 define <vscale x 8 x double> @round_nxv8f64(<vscale x 8 x double> %x) {
290 ; CHECK-LABEL: round_nxv8f64:
292 ; CHECK-NEXT: lui a0, %hi(.LCPI14_0)
293 ; CHECK-NEXT: fld fa5, %lo(.LCPI14_0)(a0)
294 ; CHECK-NEXT: vsetvli a0, zero, e64, m8, ta, ma
295 ; CHECK-NEXT: vfabs.v v16, v8
296 ; CHECK-NEXT: vmflt.vf v0, v16, fa5
297 ; CHECK-NEXT: fsrmi a0, 4
298 ; CHECK-NEXT: vfcvt.x.f.v v16, v8, v0.t
299 ; CHECK-NEXT: fsrm a0
300 ; CHECK-NEXT: vfcvt.f.x.v v16, v16, v0.t
301 ; CHECK-NEXT: vsetvli zero, zero, e64, m8, ta, mu
302 ; CHECK-NEXT: vfsgnj.vv v8, v16, v8, v0.t
304 %a = call <vscale x 8 x double> @llvm.round.nxv8f64(<vscale x 8 x double> %x)
305 ret <vscale x 8 x double> %a
307 declare <vscale x 8 x double> @llvm.round.nxv8f64(<vscale x 8 x double>)