Debian Codegraph @

gcc/config/riscv/autovec.md

raw
1 ;; Machine description for auto-vectorization using RVV for GNU compiler.
2 ;; Copyright (C) 2023-2025 Free Software Foundation, Inc.
3 ;; Contributed by Juzhe Zhong ([email protected]), RiVAI Technologies Ltd.
4
5 ;; This file is part of GCC.
6
7 ;; GCC is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3, or (at your option)
10 ;; any later version.
11
12 ;; GCC is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3. If not see
19 ;; <http://www.gnu.org/licenses/>.
20
21 ;; =========================================================================
22 ;; == Loads/Stores
23 ;; =========================================================================
24
25 (define_expand "mask_len_load<mode><vm>"
26 [(match_operand:V 0 "register_operand")
27 (match_operand:V 1 "memory_operand")
28 (match_operand:<VM> 2 "vector_mask_operand")
29 (match_operand:V 3 "maskload_else_operand")
30 (match_operand 4 "autovec_length_operand")
31 (match_operand 5 "const_0_operand")]
32 "TARGET_VECTOR"
33 {
34 riscv_vector::expand_load_store (operands, true);
35 DONE;
36 })
37
38 (define_expand "mask_len_store<mode><vm>"
39 [(match_operand:V 0 "memory_operand")
40 (match_operand:V 1 "register_operand")
41 (match_operand:<VM> 2 "vector_mask_operand")
42 (match_operand 3 "autovec_length_operand")
43 (match_operand 4 "const_0_operand")]
44 "TARGET_VECTOR"
45 {
46 riscv_vector::expand_load_store (operands, false);
47 DONE;
48 })
49
50 ;; =========================================================================
51 ;; == Gather Load
52 ;; =========================================================================
53
54 (define_expand "mask_len_gather_load<RATIO64:mode><RATIO64I:mode>"
55 [(match_operand:RATIO64 0 "register_operand")
56 (match_operand 1 "pmode_reg_or_0_operand")
57 (match_operand:RATIO64I 2 "register_operand")
58 (match_operand 3 "<RATIO64:gs_extension>")
59 (match_operand 4 "<RATIO64:gs_scale>")
60 (match_operand:<RATIO64:VM> 5 "vector_mask_operand")
61 (match_operand 6 "maskload_else_operand")
62 (match_operand 7 "autovec_length_operand")
63 (match_operand 8 "const_0_operand")]
64 "TARGET_VECTOR && riscv_vector::gather_scatter_valid_offset_p (<RATIO64I:MODE>mode)"
65 {
66 riscv_vector::expand_gather_scatter (operands, true);
67 DONE;
68 })
69
70 (define_expand "mask_len_gather_load<RATIO32:mode><RATIO32I:mode>"
71 [(match_operand:RATIO32 0 "register_operand")
72 (match_operand 1 "pmode_reg_or_0_operand")
73 (match_operand:RATIO32I 2 "register_operand")
74 (match_operand 3 "<RATIO32:gs_extension>")
75 (match_operand 4 "<RATIO32:gs_scale>")
76 (match_operand:<RATIO32:VM> 5 "vector_mask_operand")
77 (match_operand 6 "maskload_else_operand")
78 (match_operand 7 "autovec_length_operand")
79 (match_operand 8 "const_0_operand")]
80 "TARGET_VECTOR && riscv_vector::gather_scatter_valid_offset_p (<RATIO32I:MODE>mode)"
81 {
82 riscv_vector::expand_gather_scatter (operands, true);
83 DONE;
84 })
85
86 (define_expand "mask_len_gather_load<RATIO16:mode><RATIO16I:mode>"
87 [(match_operand:RATIO16 0 "register_operand")
88 (match_operand 1 "pmode_reg_or_0_operand")
89 (match_operand:RATIO16I 2 "register_operand")
90 (match_operand 3 "<RATIO16:gs_extension>")
91 (match_operand 4 "<RATIO16:gs_scale>")
92 (match_operand:<RATIO16:VM> 5 "vector_mask_operand")
93 (match_operand 6 "maskload_else_operand")
94 (match_operand 7 "autovec_length_operand")
95 (match_operand 8 "const_0_operand")]
96 "TARGET_VECTOR && riscv_vector::gather_scatter_valid_offset_p (<RATIO16I:MODE>mode)"
97 {
98 riscv_vector::expand_gather_scatter (operands, true);
99 DONE;
100 })
101
102 (define_expand "mask_len_gather_load<RATIO8:mode><RATIO8I:mode>"
103 [(match_operand:RATIO8 0 "register_operand")
104 (match_operand 1 "pmode_reg_or_0_operand")
105 (match_operand:RATIO8I 2 "register_operand")
106 (match_operand 3 "<RATIO8:gs_extension>")
107 (match_operand 4 "<RATIO8:gs_scale>")
108 (match_operand:<RATIO8:VM> 5 "vector_mask_operand")
109 (match_operand 6 "maskload_else_operand")
110 (match_operand 7 "autovec_length_operand")
111 (match_operand 8 "const_0_operand")]
112 "TARGET_VECTOR && riscv_vector::gather_scatter_valid_offset_p (<RATIO8I:MODE>mode)"
113 {
114 riscv_vector::expand_gather_scatter (operands, true);
115 DONE;
116 })
117
118 (define_expand "mask_len_gather_load<RATIO4:mode><RATIO4I:mode>"
119 [(match_operand:RATIO4 0 "register_operand")
120 (match_operand 1 "pmode_reg_or_0_operand")
121 (match_operand:RATIO4I 2 "register_operand")
122 (match_operand 3 "<RATIO4:gs_extension>")
123 (match_operand 4 "<RATIO4:gs_scale>")
124 (match_operand:<RATIO4:VM> 5 "vector_mask_operand")
125 (match_operand 6 "maskload_else_operand")
126 (match_operand 7 "autovec_length_operand")
127 (match_operand 8 "const_0_operand")]
128 "TARGET_VECTOR && riscv_vector::gather_scatter_valid_offset_p (<RATIO4I:MODE>mode)"
129 {
130 riscv_vector::expand_gather_scatter (operands, true);
131 DONE;
132 })
133
134 (define_expand "mask_len_gather_load<RATIO2:mode><RATIO2I:mode>"
135 [(match_operand:RATIO2 0 "register_operand")
136 (match_operand 1 "pmode_reg_or_0_operand")
137 (match_operand:RATIO2I 2 "register_operand")
138 (match_operand 3 "<RATIO2:gs_extension>")
139 (match_operand 4 "<RATIO2:gs_scale>")
140 (match_operand:<RATIO2:VM> 5 "vector_mask_operand")
141 (match_operand 6 "maskload_else_operand")
142 (match_operand 7 "autovec_length_operand")
143 (match_operand 8 "const_0_operand")]
144 "TARGET_VECTOR && riscv_vector::gather_scatter_valid_offset_p (<RATIO2I:MODE>mode)"
145 {
146 riscv_vector::expand_gather_scatter (operands, true);
147 DONE;
148 })
149
150 ;; When SEW = 8 and LMUL = 8, we can't find any index mode with
151 ;; larger SEW. Since RVV indexed load/store support zero extend
152 ;; implicitly and not support scaling, we should only allow
153 ;; operands[3] and operands[4] to be const_1_operand.
154 (define_expand "mask_len_gather_load<mode><mode>"
155 [(match_operand:RATIO1 0 "register_operand")
156 (match_operand 1 "pmode_reg_or_0_operand")
157 (match_operand:RATIO1 2 "register_operand")
158 (match_operand 3 "<gs_extension>")
159 (match_operand 4 "<gs_scale>")
160 (match_operand:<VM> 5 "vector_mask_operand")
161 (match_operand 6 "maskload_else_operand")
162 (match_operand 7 "autovec_length_operand")
163 (match_operand 8 "const_0_operand")]
164 "TARGET_VECTOR"
165 {
166 riscv_vector::expand_gather_scatter (operands, true);
167 DONE;
168 })
169
170 ;; =========================================================================
171 ;; == Scatter Store
172 ;; =========================================================================
173
174 (define_expand "mask_len_scatter_store<RATIO64:mode><RATIO64I:mode>"
175 [(match_operand 0 "pmode_reg_or_0_operand")
176 (match_operand:RATIO64I 1 "register_operand")
177 (match_operand 2 "<RATIO64:gs_extension>")
178 (match_operand 3 "<RATIO64:gs_scale>")
179 (match_operand:RATIO64 4 "register_operand")
180 (match_operand:<RATIO64:VM> 5 "vector_mask_operand")
181 (match_operand 6 "autovec_length_operand")
182 (match_operand 7 "const_0_operand")]
183 "TARGET_VECTOR && riscv_vector::gather_scatter_valid_offset_p (<RATIO64I:MODE>mode)"
184 {
185 riscv_vector::expand_gather_scatter (operands, false);
186 DONE;
187 })
188
189 (define_expand "mask_len_scatter_store<RATIO32:mode><RATIO32I:mode>"
190 [(match_operand 0 "pmode_reg_or_0_operand")
191 (match_operand:RATIO32I 1 "register_operand")
192 (match_operand 2 "<RATIO32:gs_extension>")
193 (match_operand 3 "<RATIO32:gs_scale>")
194 (match_operand:RATIO32 4 "register_operand")
195 (match_operand:<RATIO32:VM> 5 "vector_mask_operand")
196 (match_operand 6 "autovec_length_operand")
197 (match_operand 7 "const_0_operand")]
198 "TARGET_VECTOR && riscv_vector::gather_scatter_valid_offset_p (<RATIO32I:MODE>mode)"
199 {
200 riscv_vector::expand_gather_scatter (operands, false);
201 DONE;
202 })
203
204 (define_expand "mask_len_scatter_store<RATIO16:mode><RATIO16I:mode>"
205 [(match_operand 0 "pmode_reg_or_0_operand")
206 (match_operand:RATIO16I 1 "register_operand")
207 (match_operand 2 "<RATIO16:gs_extension>")
208 (match_operand 3 "<RATIO16:gs_scale>")
209 (match_operand:RATIO16 4 "register_operand")
210 (match_operand:<RATIO16:VM> 5 "vector_mask_operand")
211 (match_operand 6 "autovec_length_operand")
212 (match_operand 7 "const_0_operand")]
213 "TARGET_VECTOR && riscv_vector::gather_scatter_valid_offset_p (<RATIO16I:MODE>mode)"
214 {
215 riscv_vector::expand_gather_scatter (operands, false);
216 DONE;
217 })
218
219 (define_expand "mask_len_scatter_store<RATIO8:mode><RATIO8I:mode>"
220 [(match_operand 0 "pmode_reg_or_0_operand")
221 (match_operand:RATIO8I 1 "register_operand")
222 (match_operand 2 "<RATIO8:gs_extension>")
223 (match_operand 3 "<RATIO8:gs_scale>")
224 (match_operand:RATIO8 4 "register_operand")
225 (match_operand:<RATIO8:VM> 5 "vector_mask_operand")
226 (match_operand 6 "autovec_length_operand")
227 (match_operand 7 "const_0_operand")]
228 "TARGET_VECTOR && riscv_vector::gather_scatter_valid_offset_p (<RATIO8I:MODE>mode)"
229 {
230 riscv_vector::expand_gather_scatter (operands, false);
231 DONE;
232 })
233
234 (define_expand "mask_len_scatter_store<RATIO4:mode><RATIO4I:mode>"
235 [(match_operand 0 "pmode_reg_or_0_operand")
236 (match_operand:RATIO4I 1 "register_operand")
237 (match_operand 2 "<RATIO4:gs_extension>")
238 (match_operand 3 "<RATIO4:gs_scale>")
239 (match_operand:RATIO4 4 "register_operand")
240 (match_operand:<RATIO4:VM> 5 "vector_mask_operand")
241 (match_operand 6 "autovec_length_operand")
242 (match_operand 7 "const_0_operand")]
243 "TARGET_VECTOR && riscv_vector::gather_scatter_valid_offset_p (<RATIO4I:MODE>mode)"
244 {
245 riscv_vector::expand_gather_scatter (operands, false);
246 DONE;
247 })
248
249 (define_expand "mask_len_scatter_store<RATIO2:mode><RATIO2I:mode>"
250 [(match_operand 0 "pmode_reg_or_0_operand")
251 (match_operand:RATIO2I 1 "register_operand")
252 (match_operand 2 "<RATIO2:gs_extension>")
253 (match_operand 3 "<RATIO2:gs_scale>")
254 (match_operand:RATIO2 4 "register_operand")
255 (match_operand:<RATIO2:VM> 5 "vector_mask_operand")
256 (match_operand 6 "autovec_length_operand")
257 (match_operand 7 "const_0_operand")]
258 "TARGET_VECTOR && riscv_vector::gather_scatter_valid_offset_p (<RATIO2I:MODE>mode)"
259 {
260 riscv_vector::expand_gather_scatter (operands, false);
261 DONE;
262 })
263
264 ;; When SEW = 8 and LMUL = 8, we can't find any index mode with
265 ;; larger SEW. Since RVV indexed load/store support zero extend
266 ;; implicitly and not support scaling, we should only allow
267 ;; operands[3] and operands[4] to be const_1_operand.
268 (define_expand "mask_len_scatter_store<mode><mode>"
269 [(match_operand 0 "pmode_reg_or_0_operand")
270 (match_operand:RATIO1 1 "register_operand")
271 (match_operand 2 "<gs_extension>")
272 (match_operand 3 "<gs_scale>")
273 (match_operand:RATIO1 4 "register_operand")
274 (match_operand:<VM> 5 "vector_mask_operand")
275 (match_operand 6 "autovec_length_operand")
276 (match_operand 7 "const_0_operand")]
277 "TARGET_VECTOR"
278 {
279 riscv_vector::expand_gather_scatter (operands, false);
280 DONE;
281 })
282
283 ;; =========================================================================
284 ;; == Array Load/Store
285 ;; =========================================================================
286
287 (define_expand "vec_mask_len_load_lanes<mode><vsingle>"
288 [(match_operand:VT 0 "register_operand")
289 (match_operand:VT 1 "memory_operand")
290 (match_operand:<VM> 2 "vector_mask_operand")
291 (match_operand 3 "maskload_else_operand")
292 (match_operand 4 "autovec_length_operand")
293 (match_operand 5 "const_0_operand")]
294 "TARGET_VECTOR_AUTOVEC_SEGMENT"
295 {
296 riscv_vector::expand_lanes_load_store (operands, true);
297 DONE;
298 }
299 )
300
301 (define_expand "vec_mask_len_store_lanes<mode><vsingle>"
302 [(match_operand:VT 0 "memory_operand")
303 (match_operand:VT 1 "register_operand")
304 (match_operand:<VM> 2 "vector_mask_operand")
305 (match_operand 3 "autovec_length_operand")
306 (match_operand 4 "const_0_operand")]
307 "TARGET_VECTOR_AUTOVEC_SEGMENT"
308 {
309 riscv_vector::expand_lanes_load_store (operands, false);
310 DONE;
311 }
312 )
313
314 ;; =========================================================================
315 ;; == Vector creation
316 ;; =========================================================================
317
318 ;; -------------------------------------------------------------------------
319 ;; ---- [BOOL] Duplicate element
320 ;; -------------------------------------------------------------------------
321 ;; The patterns in this section are synthetic.
322 ;; -------------------------------------------------------------------------
323
324 ;; Implement a predicate broadcast by shifting the low bit of the scalar
325 ;; input into the top bit by duplicate the input and do a compare with zero.
326 (define_expand "vec_duplicate<mode>"
327 [(set (match_operand:VB 0 "register_operand")
328 (vec_duplicate:VB (match_operand:QI 1 "register_operand")))]
329 "TARGET_VECTOR"
330 {
331 poly_int64 nunits = GET_MODE_NUNITS (<MODE>mode);
332 machine_mode mode = riscv_vector::get_vector_mode (QImode, nunits).require ();
333
334 /* The 1-bit mask is in a QImode register, make sure we only use the last
335 bit. See also PR119114 and the respective vec_init expander. */
336 rtx tmp = gen_reg_rtx (Xmode);
337 emit_insn
338 (gen_rtx_SET (tmp, gen_rtx_AND (Xmode, gen_lowpart (Xmode, operands[1]),
339 CONST1_RTX (Xmode))));
340
341 rtx dup = expand_vector_broadcast (mode, gen_lowpart (QImode, tmp));
342 riscv_vector::expand_vec_cmp (operands[0], NE, dup, CONST0_RTX (mode));
343 DONE;
344 }
345 )
346
347 ;; -------------------------------------------------------------------------
348 ;; ---- [INT] Linear series
349 ;; -------------------------------------------------------------------------
350 ;; Includes:
351 ;; - vid.v
352 ;; - vmul.vx
353 ;; - vadd.vx/vadd.vi
354 ;; -------------------------------------------------------------------------
355
356 (define_expand "vec_series<mode>"
357 [(match_operand:V_VLSI 0 "register_operand")
358 (match_operand:<VEL> 1 "reg_or_int_operand")
359 (match_operand:<VEL> 2 "reg_or_int_operand")]
360 "TARGET_VECTOR"
361 {
362 riscv_vector::expand_vec_series (operands[0], operands[1], operands[2]);
363 DONE;
364 }
365 )
366
367 ;; -------------------------------------------------------------------------
368 ;; ---- [INT,FP] permutation
369 ;; -------------------------------------------------------------------------
370 ;; This is the pattern permutes the vector
371 ;; -------------------------------------------------------------------------
372
373 (define_expand "vec_perm<mode>"
374 [(match_operand:V_VLS 0 "register_operand")
375 (match_operand:V_VLS 1 "register_operand")
376 (match_operand:V_VLS 2 "register_operand")
377 (match_operand:<VINDEX> 3 "vector_perm_operand")]
378 "TARGET_VECTOR && GET_MODE_NUNITS (<MODE>mode).is_constant ()"
379 {
380 riscv_vector::expand_vec_perm (operands[0], operands[1],
381 operands[2], operands[3]);
382 DONE;
383 }
384 )
385
386 ;; -------------------------------------------------------------------------
387 ;; ---- [INT,FP] Initialize from individual elements
388 ;; -------------------------------------------------------------------------
389 ;; This is the pattern initialize the vector
390 ;; -------------------------------------------------------------------------
391
392 (define_expand "vec_init<mode><vel>"
393 [(match_operand:V_VLSI 0 "register_operand")
394 (match_operand 1 "")]
395 "TARGET_VECTOR"
396 {
397 riscv_vector::expand_vec_init (operands[0], operands[1]);
398 DONE;
399 }
400 )
401
402 ;; We split RVV floating-point because we are going to
403 ;; use vfslide1down/vfslide1up for FP16 which need TARGET_ZVFH.
404 (define_expand "vec_init<mode><vel>"
405 [(match_operand:V_VLSF 0 "register_operand")
406 (match_operand 1 "")]
407 "TARGET_VECTOR"
408 {
409 riscv_vector::expand_vec_init (operands[0], operands[1]);
410 DONE;
411 }
412 )
413
414 ;; Provide a vec_init for mask registers by initializing
415 ;; a QImode vector and comparing it against 0.
416 ;; As we need to ignore all but the lowest bit apply an AND mask
417 ;; before doing the comparison.
418 (define_expand "vec_init<mode>qi"
419 [(match_operand:VB 0 "register_operand")
420 (match_operand 1 "")]
421 "TARGET_VECTOR"
422 {
423 /* Expand into a QImode vector.
424 For XTheadVector which does not have fractional-LMUL modes, we use
425 a full-size vector instead. */
426 bool fractional_p = known_lt (GET_MODE_NUNITS (<MODE>mode),
427 BYTES_PER_RISCV_VECTOR);
428 machine_mode qimode;
429 if (!TARGET_XTHEADVECTOR || !fractional_p)
430 qimode = riscv_vector::get_vector_mode
431 (QImode, GET_MODE_NUNITS (<MODE>mode)).require ();
432 else
433 qimode = riscv_vector::get_m1_mode
434 (QImode, GET_MODE_NUNITS (<MODE>mode).is_constant ()).require ();
435 rtx tmp = gen_reg_rtx (qimode);
436 riscv_vector::expand_vec_init (tmp, operands[1]);
437
438 /* & 0x1. */
439 insn_code icode = code_for_pred (AND, qimode);
440 rtx tmp2 = gen_reg_rtx (qimode);
441 rtx ones = gen_const_vec_duplicate (qimode, GEN_INT (1));
442 rtx ops[] = {tmp2, tmp, ones};
443 riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, ops);
444
445 /* Compare against zero. */
446 rtx op0;
447 if (!TARGET_XTHEADVECTOR || !fractional_p)
448 op0 = operands[0];
449 else
450 op0 = gen_lowpart (riscv_vector::get_mask_mode (qimode), operands[0]);
451 riscv_vector::expand_vec_cmp (op0, NE, tmp2, CONST0_RTX (qimode));
452 DONE;
453 }
454 )
455
456 ;; Slide an RVV vector left and insert a scalar into element 0.
457 (define_expand "vec_shl_insert_<mode>"
458 [(match_operand:VI 0 "register_operand")
459 (match_operand:VI 1 "register_operand")
460 (match_operand:<VEL> 2 "reg_or_0_operand")]
461 "TARGET_VECTOR"
462 {
463 insn_code icode = code_for_pred_slide (UNSPEC_VSLIDE1UP, <MODE>mode);
464 rtx ops[] = {operands[0], operands[1], operands[2]};
465 riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, ops);
466 DONE;
467 })
468
469 (define_expand "vec_shl_insert_<mode>"
470 [(match_operand:VF 0 "register_operand")
471 (match_operand:VF 1 "register_operand")
472 (match_operand:<VEL> 2 "register_operand")]
473 "TARGET_VECTOR"
474 {
475 insn_code icode = code_for_pred_slide (UNSPEC_VFSLIDE1UP, <MODE>mode);
476 rtx ops[] = {operands[0], operands[1], operands[2]};
477 riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, ops);
478 DONE;
479 })
480
481 ;; ========================================================================
482 ;; == Vector operations
483 ;; =========================================================================
484
485 ;; -------------------------------------------------------------------------
486 ;; ---- [INT] Binary operations
487 ;; -------------------------------------------------------------------------
488 ;; Includes:
489 ;; - vadd.vv/vsub.vv/...
490 ;; - vadd.vi/vsub.vi/...
491 ;; -------------------------------------------------------------------------
492
493 (define_insn_and_split "<optab><mode>3"
494 [(set (match_operand:V_VLSI 0 "register_operand")
495 (any_int_binop_no_shift:V_VLSI
496 (match_operand:V_VLSI 1 "<binop_rhs1_predicate>")
497 (match_operand:V_VLSI 2 "<binop_rhs2_predicate>")))]
498 "TARGET_VECTOR && can_create_pseudo_p ()"
499 "#"
500 "&& 1"
501 [(const_int 0)]
502 {
503 riscv_vector::emit_vlmax_insn (code_for_pred (<CODE>, <MODE>mode),
504 riscv_vector::BINARY_OP, operands);
505 DONE;
506 }
507 [(set_attr "type" "vialu")])
508
509 ;; -------------------------------------------------------------------------
510 ;; ---- [INT] Binary shifts by scalar.
511 ;; -------------------------------------------------------------------------
512 ;; Includes:
513 ;; - vsll.vx/vsra.vx/vsrl.vx
514 ;; - vsll.vi/vsra.vi/vsrl.vi
515 ;; -------------------------------------------------------------------------
516
517 (define_insn_and_split "<optab><mode>3"
518 [(set (match_operand:V_VLSI 0 "register_operand" "=vr")
519 (any_shift:V_VLSI
520 (match_operand:V_VLSI 1 "register_operand" " vr")
521 (match_operand:<VEL> 2 "vector_scalar_shift_operand" " rK")))]
522 "TARGET_VECTOR && can_create_pseudo_p ()"
523 "#"
524 "&& 1"
525 [(const_int 0)]
526 {
527 operands[2] = gen_lowpart (Pmode, operands[2]);
528 riscv_vector::emit_vlmax_insn (code_for_pred_scalar (<CODE>, <MODE>mode),
529 riscv_vector::BINARY_OP, operands);
530 DONE;
531 }
532 [(set_attr "type" "vshift")
533 (set_attr "mode" "<MODE>")])
534
535 ;; -------------------------------------------------------------------------
536 ;; ---- [INT] Binary shifts by vector.
537 ;; -------------------------------------------------------------------------
538 ;; Includes:
539 ;; - vsll.vv/vsra.vv/vsrl.vv
540 ;; -------------------------------------------------------------------------
541
542 (define_insn_and_split "v<optab><mode>3"
543 [(set (match_operand:V_VLSI 0 "register_operand" "=vr,vr")
544 (any_shift:V_VLSI
545 (match_operand:V_VLSI 1 "register_operand" " vr,vr")
546 (match_operand:V_VLSI 2 "vector_shift_operand" " vr,vk")))]
547 "TARGET_VECTOR && can_create_pseudo_p ()"
548 "#"
549 "&& 1"
550 [(const_int 0)]
551 {
552 riscv_vector::emit_vlmax_insn (code_for_pred (<CODE>, <MODE>mode),
553 riscv_vector::BINARY_OP, operands);
554 DONE;
555 }
556 [(set_attr "type" "vshift")
557 (set_attr "mode" "<MODE>")])
558
559 ;; -------------------------------------------------------------------------
560 ;; ---- [BOOL] Binary logical operations
561 ;; -------------------------------------------------------------------------
562 ;; Includes:
563 ;; - vmand.mm
564 ;; - vmxor.mm
565 ;; - vmor.mm
566 ;; -------------------------------------------------------------------------
567
568 (define_insn_and_split "<optab><mode>3"
569 [(set (match_operand:VB_VLS 0 "register_operand" "=vr")
570 (any_bitwise:VB_VLS (match_operand:VB_VLS 1 "register_operand" " vr")
571 (match_operand:VB_VLS 2 "register_operand" " vr")))]
572 "TARGET_VECTOR && can_create_pseudo_p ()"
573 "#"
574 "&& 1"
575 [(const_int 0)]
576 {
577 insn_code icode = code_for_pred (<CODE>, <MODE>mode);
578 riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_MASK_OP, operands);
579 DONE;
580 }
581 [(set_attr "type" "vmalu")
582 (set_attr "mode" "<MODE>")])
583
584 ;; -------------------------------------------------------------------------
585 ;; ---- [BOOL] Inverse
586 ;; -------------------------------------------------------------------------
587 ;; Includes:
588 ;; - vmnot.m
589 ;; -------------------------------------------------------------------------
590
591 (define_insn_and_split "one_cmpl<mode>2"
592 [(set (match_operand:VB_VLS 0 "register_operand" "=vr")
593 (not:VB_VLS (match_operand:VB_VLS 1 "register_operand" " vr")))]
594 "TARGET_VECTOR && can_create_pseudo_p ()"
595 "#"
596 "&& 1"
597 [(const_int 0)]
598 {
599 insn_code icode = code_for_pred_not (<MODE>mode);
600 riscv_vector::emit_vlmax_insn (icode, riscv_vector::UNARY_MASK_OP, operands);
601 DONE;
602 }
603 [(set_attr "type" "vmalu")
604 (set_attr "mode" "<MODE>")])
605
606 ;; =========================================================================
607 ;; == Comparisons and selects
608 ;; =========================================================================
609
610 ;; -------------------------------------------------------------------------
611 ;; ---- [INT,FP] Select based on masks
612 ;; -------------------------------------------------------------------------
613 ;; Includes merging patterns for:
614 ;; - vmerge.vv
615 ;; - vmerge.vx
616 ;; - vfmerge.vf
617 ;; -------------------------------------------------------------------------
618
619 (define_insn_and_split "vcond_mask_<mode><vm>"
620 [(set (match_operand:V_VLS 0 "register_operand")
621 (if_then_else:V_VLS
622 (match_operand:<VM> 3 "register_operand")
623 (match_operand:V_VLS 1 "nonmemory_operand")
624 (match_operand:V_VLS 2 "register_operand")))]
625 "TARGET_VECTOR && can_create_pseudo_p ()"
626 "#"
627 "&& 1"
628 [(const_int 0)]
629 {
630 /* The order of vcond_mask is opposite to pred_merge. */
631 std::swap (operands[1], operands[2]);
632 riscv_vector::emit_vlmax_insn (code_for_pred_merge (<MODE>mode),
633 riscv_vector::MERGE_OP, operands);
634 DONE;
635 }
636 [(set_attr "type" "vector")]
637 )
638
639 (define_expand "vcond_mask_len_<mode>"
640 [(match_operand:V 0 "register_operand")
641 (match_operand:<VM> 1 "nonmemory_operand")
642 (match_operand:V 2 "nonmemory_operand")
643 (match_operand:V 3 "autovec_else_operand")
644 (match_operand 4 "autovec_length_operand")
645 (match_operand 5 "const_0_operand")]
646 "TARGET_VECTOR"
647 {
648 if (satisfies_constraint_Wc1 (operands[1]))
649 riscv_vector::expand_cond_len_unop (code_for_pred_mov (<MODE>mode),
650 operands);
651 else
652 {
653 /* The order of then and else is opposite to pred_merge. */
654 rtx ops[] = {operands[0], operands[3], operands[3], operands[2],
655 operands[1]};
656 riscv_vector::emit_nonvlmax_insn (code_for_pred_merge (<MODE>mode),
657 riscv_vector::MERGE_OP_TU,
658 ops, operands[4]);
659 }
660 DONE;
661 }
662 [(set_attr "type" "vector")]
663 )
664
665 ;; -------------------------------------------------------------------------
666 ;; ---- [BOOL] Select based on masks
667 ;; -------------------------------------------------------------------------
668 ;; Includes merging patterns for:
669 ;; - vmand.mm
670 ;; - vmor.mm
671 ;; - vmnot.m
672 ;; -------------------------------------------------------------------------
673
674 (define_expand "vcond_mask_<mode><mode>"
675 [(match_operand:VB_VLS 0 "register_operand")
676 (match_operand:VB_VLS 1 "register_operand")
677 (match_operand:VB_VLS 2 "register_operand")
678 (match_operand:VB_VLS 3 "register_operand")]
679 "TARGET_VECTOR"
680 {
681 /* mask1 = operands[3] & operands[1]. */
682 rtx mask1 = expand_binop (<MODE>mode, and_optab, operands[1],
683 operands[3], NULL_RTX, 0,
684 OPTAB_DIRECT);
685 /* mask2 = ~operands[3] & operands[2]. */
686 rtx inverse = expand_unop (<MODE>mode, one_cmpl_optab, operands[3],
687 NULL_RTX, 0);
688 rtx mask2 = expand_binop (<MODE>mode, and_optab, operands[2],
689 inverse, NULL_RTX, 0,
690 OPTAB_DIRECT);
691 /* result = mask1 | mask2. */
692 rtx result = expand_binop (<MODE>mode, ior_optab, mask1,
693 mask2, NULL_RTX, 0,
694 OPTAB_DIRECT);
695 emit_move_insn (operands[0], result);
696 DONE;
697 })
698
699 ;; -------------------------------------------------------------------------
700 ;; ---- [INT,FP] Comparisons
701 ;; -------------------------------------------------------------------------
702 ;; Includes:
703 ;; - vms<eq/ne/ltu/lt/leu/le/gtu/gt>.<vv/vx/vi>
704 ;; -------------------------------------------------------------------------
705
706 (define_expand "vec_cmp<mode><vm>"
707 [(set (match_operand:<VM> 0 "register_operand")
708 (match_operator:<VM> 1 "comparison_operator"
709 [(match_operand:V_VLSI 2 "register_operand")
710 (match_operand:V_VLSI 3 "nonmemory_operand")]))]
711 "TARGET_VECTOR"
712 {
713 riscv_vector::expand_vec_cmp (operands[0], GET_CODE (operands[1]),
714 operands[2], operands[3]);
715 DONE;
716 }
717 )
718
719 (define_expand "vec_cmpu<mode><vm>"
720 [(set (match_operand:<VM> 0 "register_operand")
721 (match_operator:<VM> 1 "comparison_operator"
722 [(match_operand:V_VLSI 2 "register_operand")
723 (match_operand:V_VLSI 3 "nonmemory_operand")]))]
724 "TARGET_VECTOR"
725 {
726 riscv_vector::expand_vec_cmp (operands[0], GET_CODE (operands[1]),
727 operands[2], operands[3]);
728 DONE;
729 }
730 )
731
732 (define_expand "vec_cmp<mode><vm>"
733 [(set (match_operand:<VM> 0 "register_operand")
734 (match_operator:<VM> 1 "comparison_operator"
735 [(match_operand:V_VLSF 2 "register_operand")
736 (match_operand:V_VLSF 3 "register_operand")]))]
737 "TARGET_VECTOR"
738 {
739 riscv_vector::expand_vec_cmp_float (operands[0], GET_CODE (operands[1]),
740 operands[2], operands[3], false);
741 DONE;
742 }
743 )
744
745 ;; -------------------------------------------------------------------------
746 ;; ---- [INT] Sign and zero extension
747 ;; -------------------------------------------------------------------------
748 ;; Includes:
749 ;; - vzext.vf[2|4|8]
750 ;; - vsext.vf[2|4|8]
751 ;; -------------------------------------------------------------------------
752
753 ;; Use define_insn_and_split to define vsext.vf2/vzext.vf2 will help
754 ;; to combine instructions as below:
755 ;; vsext.vf2 + vsext.vf2 + vadd.vv ==> vwadd.vv
756 (define_insn_and_split "<optab><v_double_trunc><mode>2"
757 [(set (match_operand:VWEXTI 0 "register_operand" "=&vr")
758 (any_extend:VWEXTI
759 (match_operand:<V_DOUBLE_TRUNC> 1 "register_operand" "vr")))]
760 "TARGET_VECTOR && can_create_pseudo_p ()"
761 "#"
762 "&& 1"
763 [(const_int 0)]
764 {
765 insn_code icode = code_for_pred_vf2 (<CODE>, <MODE>mode);
766 riscv_vector::emit_vlmax_insn (icode, riscv_vector::UNARY_OP, operands);
767 DONE;
768 }
769 [(set_attr "type" "vext")
770 (set_attr "mode" "<MODE>")])
771
772 (define_insn_and_split "<optab><v_quad_trunc><mode>2"
773 [(set (match_operand:VQEXTI 0 "register_operand")
774 (any_extend:VQEXTI
775 (match_operand:<V_QUAD_TRUNC> 1 "register_operand")))]
776 "TARGET_VECTOR && can_create_pseudo_p ()"
777 "#"
778 "&& 1"
779 [(const_int 0)]
780 {
781 insn_code icode = code_for_pred_vf4 (<CODE>, <MODE>mode);
782 riscv_vector::emit_vlmax_insn (icode, riscv_vector::UNARY_OP, operands);
783 DONE;
784 }
785 [(set_attr "type" "vext")])
786
787 (define_insn_and_split "<optab><v_oct_trunc><mode>2"
788 [(set (match_operand:VOEXTI 0 "register_operand")
789 (any_extend:VOEXTI
790 (match_operand:<V_OCT_TRUNC> 1 "register_operand")))]
791 "TARGET_VECTOR && can_create_pseudo_p ()"
792 "#"
793 "&& 1"
794 [(const_int 0)]
795 {
796 insn_code icode = code_for_pred_vf8 (<CODE>, <MODE>mode);
797 riscv_vector::emit_vlmax_insn (icode, riscv_vector::UNARY_OP, operands);
798 DONE;
799 }
800 [(set_attr "type" "vext")])
801
802 ;; -------------------------------------------------------------------------
803 ;; ---- [INT] Truncation
804 ;; -------------------------------------------------------------------------
805 ;; - vncvt.x.x.w
806 ;; -------------------------------------------------------------------------
807 (define_insn_and_split "trunc<mode><v_double_trunc>2"
808 [(set (match_operand:<V_DOUBLE_TRUNC> 0 "register_operand" "=vr")
809 (truncate:<V_DOUBLE_TRUNC>
810 (match_operand:VWEXTI 1 "register_operand" " vr")))]
811 "TARGET_VECTOR && can_create_pseudo_p ()"
812 "#"
813 "&& 1"
814 [(const_int 0)]
815 {
816 insn_code icode = code_for_pred_trunc (<MODE>mode);
817 riscv_vector::emit_vlmax_insn (icode, riscv_vector::UNARY_OP, operands);
818 DONE;
819 }
820 [(set_attr "type" "vshift")
821 (set_attr "mode" "<MODE>")])
822
823 ;; -------------------------------------------------------------------------
824 ;; Truncation to a mode whose inner mode size is a quarter of mode's.
825 ;; We emulate this with two consecutive vncvts.
826 ;; -------------------------------------------------------------------------
827 (define_expand "trunc<mode><v_quad_trunc>2"
828 [(set (match_operand:<V_QUAD_TRUNC> 0 "register_operand")
829 (truncate:<V_QUAD_TRUNC>
830 (match_operand:VQEXTI 1 "register_operand")))]
831 "TARGET_VECTOR"
832 {
833 rtx half = gen_reg_rtx (<V_DOUBLE_TRUNC>mode);
834 emit_insn (gen_trunc<mode><v_double_trunc>2 (half, operands[1]));
835 emit_insn (gen_trunc<v_double_trunc><v_quad_trunc>2 (operands[0], half));
836 DONE;
837 })
838
839 ;; -------------------------------------------------------------------------
840 ;; Truncation to a mode whose inner mode size is an eighth of mode's.
841 ;; We emulate this with three consecutive vncvts.
842 ;; -------------------------------------------------------------------------
843 (define_expand "trunc<mode><v_oct_trunc>2"
844 [(set (match_operand:<V_OCT_TRUNC> 0 "register_operand")
845 (truncate:<V_OCT_TRUNC>
846 (match_operand:VOEXTI 1 "register_operand")))]
847 "TARGET_VECTOR"
848 {
849 rtx quarter = gen_reg_rtx (<V_QUAD_TRUNC>mode);
850 emit_insn (gen_trunc<mode><v_quad_trunc>2 (quarter, operands[1]));
851 emit_insn (gen_trunc<v_quad_trunc><v_oct_trunc>2 (operands[0], quarter));
852 DONE;
853 })
854
855 ;; -------------------------------------------------------------------------
856 ;; ---- [FP] Widening.
857 ;; -------------------------------------------------------------------------
858 ;; - vfwcvt.f.f.v
859 ;; -------------------------------------------------------------------------
860 (define_insn_and_split "extend<v_double_trunc><mode>2"
861 [(set (match_operand:VWEXTF_ZVFHMIN 0 "register_operand" "=&vr")
862 (float_extend:VWEXTF_ZVFHMIN
863 (match_operand:<V_DOUBLE_TRUNC> 1 "register_operand" " vr")))]
864 "TARGET_VECTOR && can_create_pseudo_p ()"
865 "#"
866 "&& 1"
867 [(const_int 0)]
868 {
869 insn_code icode = code_for_pred_extend (<MODE>mode);
870 riscv_vector::emit_vlmax_insn (icode, riscv_vector::UNARY_OP, operands);
871 DONE;
872 }
873 [(set_attr "type" "vfwcvtftof")
874 (set_attr "mode" "<MODE>")])
875
876 (define_expand "extend<v_quad_trunc><mode>2"
877 [(set (match_operand:VQEXTF 0 "register_operand")
878 (float_extend:VQEXTF
879 (match_operand:<V_QUAD_TRUNC> 1 "register_operand")))]
880 "TARGET_VECTOR && (TARGET_ZVFHMIN || TARGET_ZVFH)"
881 {
882 rtx dblw = gen_reg_rtx (<V_DOUBLE_TRUNC>mode);
883 emit_insn (gen_extend<v_quad_trunc><v_double_trunc>2 (dblw, operands[1]));
884 emit_insn (gen_extend<v_double_trunc><mode>2 (operands[0], dblw));
885 DONE;
886 })
887
888 ;; -------------------------------------------------------------------------
889 ;; ---- [FP] Narrowing.
890 ;; -------------------------------------------------------------------------
891 ;; - vfncvt.f.f.w
892 ;; -------------------------------------------------------------------------
893 (define_insn_and_split "trunc<mode><v_double_trunc>2"
894 [(set (match_operand:<V_DOUBLE_TRUNC> 0 "register_operand" "=vr")
895 (float_truncate:<V_DOUBLE_TRUNC>
896 (match_operand:VWEXTF_ZVFHMIN 1 "register_operand" " vr")))]
897 "TARGET_VECTOR && can_create_pseudo_p ()"
898 "#"
899 "&& 1"
900 [(const_int 0)]
901 {
902 insn_code icode = code_for_pred_trunc (<MODE>mode);
903 riscv_vector::emit_vlmax_insn (icode, riscv_vector::UNARY_OP_FRM_DYN, operands);
904 DONE;
905 }
906 [(set_attr "type" "vfncvtftof")
907 (set_attr "mode" "<MODE>")])
908
909 ;; -------------------------------------------------------------------------
910 ;; Narrowing to a mode whose inner mode size is a quarter of mode's.
911 ;; We emulate this with two consecutive vfncvts.
912 ;; -------------------------------------------------------------------------
913 (define_expand "trunc<mode><v_quad_trunc>2"
914 [(set (match_operand:<V_QUAD_TRUNC> 0 "register_operand")
915 (float_truncate:<V_QUAD_TRUNC>
916 (match_operand:VQEXTF 1 "register_operand")))]
917 "TARGET_VECTOR && (TARGET_ZVFHMIN || TARGET_ZVFH)"
918 {
919 rtx half = gen_reg_rtx (<V_DOUBLE_TRUNC>mode);
920 rtx opshalf[] = {half, operands[1]};
921
922 /* According to the RISC-V V Spec 13.19. we need to use
923 vfncvt.rod.f.f.w for all steps but the last. */
924 insn_code icode = code_for_pred_rod_trunc (<MODE>mode);
925 riscv_vector::emit_vlmax_insn (icode, riscv_vector::UNARY_OP, opshalf);
926
927 emit_insn (gen_trunc<v_double_trunc><v_quad_trunc>2 (operands[0], half));
928 DONE;
929 })
930
931
932 ;; =========================================================================
933 ;; == Conversions
934 ;; =========================================================================
935
936 ;; -------------------------------------------------------------------------
937 ;; ---- [INT<-FP] Conversions
938 ;; -------------------------------------------------------------------------
939 ;; Includes:
940 ;; - vfcvt.rtz.xu.f.v
941 ;; - vfcvt.rtz.x.f.v
942 ;; -------------------------------------------------------------------------
943
944 (define_insn_and_split "<optab><mode><vconvert>2"
945 [(set (match_operand:<VCONVERT> 0 "register_operand")
946 (any_fix:<VCONVERT>
947 (match_operand:V_VLSF 1 "register_operand")))]
948 "TARGET_VECTOR && can_create_pseudo_p ()"
949 "#"
950 "&& 1"
951 [(const_int 0)]
952 {
953 insn_code icode = code_for_pred (<CODE>, <MODE>mode);
954 riscv_vector::emit_vlmax_insn (icode, riscv_vector::UNARY_OP, operands);
955 DONE;
956 }
957 [(set_attr "type" "vfcvtftoi")])
958
959 ;; -------------------------------------------------------------------------
960 ;; ---- [FP<-INT] Conversions
961 ;; -------------------------------------------------------------------------
962 ;; Includes:
963 ;; - vfcvt.f.xu.v
964 ;; - vfcvt.f.x.v
965 ;; -------------------------------------------------------------------------
966
967 (define_insn_and_split "<float_cvt><vconvert><mode>2"
968 [(set (match_operand:V_VLSF 0 "register_operand")
969 (any_float:V_VLSF
970 (match_operand:<VCONVERT> 1 "register_operand")))]
971 "TARGET_VECTOR && can_create_pseudo_p ()"
972 "#"
973 "&& 1"
974 [(const_int 0)]
975 {
976 insn_code icode = code_for_pred (<CODE>, <MODE>mode);
977 riscv_vector::emit_vlmax_insn (icode, riscv_vector::UNARY_OP_FRM_DYN, operands);
978 DONE;
979 }
980 [(set_attr "type" "vfcvtitof")])
981
982 ;; =========================================================================
983 ;; == Widening/narrowing Conversions
984 ;; =========================================================================
985
986 ;; -------------------------------------------------------------------------
987 ;; ---- [INT<-FP] Widening Conversions
988 ;; -------------------------------------------------------------------------
989 ;; Includes:
990 ;; - vfwcvt.rtz.xu.f.v
991 ;; - vfwcvt.rtz.x.f.v
992 ;; -------------------------------------------------------------------------
993 (define_insn_and_split "<optab><vnconvert><mode>2"
994 [(set (match_operand:VWCONVERTI 0 "register_operand")
995 (any_fix:VWCONVERTI
996 (match_operand:<VNCONVERT> 1 "register_operand")))]
997 "TARGET_VECTOR && can_create_pseudo_p ()"
998 "#"
999 "&& 1"
1000 [(const_int 0)]
1001 {
1002 insn_code icode = code_for_pred_widen (<CODE>, <MODE>mode);
1003 riscv_vector::emit_vlmax_insn (icode, riscv_vector::UNARY_OP, operands);
1004 DONE;
1005 }
1006 [(set_attr "type" "vfwcvtftoi")])
1007
1008 ;; -------------------------------------------------------------------------
1009 ;; ---- [FP<-INT] Widening Conversions
1010 ;; -------------------------------------------------------------------------
1011 ;; Includes:
1012 ;; - vfwcvt.f.xu.v
1013 ;; - vfwcvt.f.x.v
1014 ;; -------------------------------------------------------------------------
1015 (define_insn_and_split "<float_cvt><vnconvert><mode>2"
1016 [(set (match_operand:V_VLSF 0 "register_operand")
1017 (any_float:V_VLSF
1018 (match_operand:<VNCONVERT> 1 "register_operand")))]
1019 "TARGET_VECTOR && can_create_pseudo_p ()"
1020 "#"
1021 "&& 1"
1022 [(const_int 0)]
1023 {
1024 insn_code icode = code_for_pred_widen (<CODE>, <MODE>mode);
1025 riscv_vector::emit_vlmax_insn (icode, riscv_vector::UNARY_OP, operands);
1026 DONE;
1027 }
1028 [(set_attr "type" "vfwcvtitof")])
1029
1030 ;; -------------------------------------------------------------------------
1031 ;; ---- [INT<-FP] Narrowing Conversions
1032 ;; -------------------------------------------------------------------------
1033 ;; Includes:
1034 ;; - vfncvt.rtz.xu.f.v
1035 ;; - vfncvt.rtz.x.f.v
1036 ;; -------------------------------------------------------------------------
1037 (define_insn_and_split "<optab><mode><vnconvert>2"
1038 [(set (match_operand:<VNCONVERT> 0 "register_operand")
1039 (any_fix:<VNCONVERT>
1040 (match_operand:V_VLSF 1 "register_operand")))]
1041 "TARGET_VECTOR && can_create_pseudo_p ()"
1042 "#"
1043 "&& 1"
1044 [(const_int 0)]
1045 {
1046 insn_code icode = code_for_pred_narrow (<CODE>, <MODE>mode);
1047 riscv_vector::emit_vlmax_insn (icode, riscv_vector::UNARY_OP, operands);
1048 DONE;
1049 }
1050 [(set_attr "type" "vfncvtftoi")])
1051
1052 ;; -------------------------------------------------------------------------
1053 ;; ---- [FP<-INT] Narrowing Conversions
1054 ;; -------------------------------------------------------------------------
1055 ;; Includes:
1056 ;; - vfncvt.f.xu.w
1057 ;; - vfncvt.f.x.w
1058 ;; -------------------------------------------------------------------------
1059 (define_insn_and_split "<float_cvt><mode><vnconvert>2"
1060 [(set (match_operand:<VNCONVERT> 0 "register_operand")
1061 (any_float:<VNCONVERT>
1062 (match_operand:VWCONVERTI 1 "register_operand")))]
1063 "TARGET_VECTOR && can_create_pseudo_p ()"
1064 "#"
1065 "&& 1"
1066 [(const_int 0)]
1067 {
1068 insn_code icode = code_for_pred_narrow (<CODE>, <MODE>mode);
1069 riscv_vector::emit_vlmax_insn (icode, riscv_vector::UNARY_OP_FRM_DYN, operands);
1070 DONE;
1071 }
1072 [(set_attr "type" "vfncvtitof")])
1073
1074 ;; This operation can be performed in the loop vectorizer but unfortunately
1075 ;; not applicable for now. We can remove this pattern after loop vectorizer
1076 ;; is able to take care of INT64 to FP16 conversion.
1077 (define_expand "<float_cvt><mode><vnnconvert>2"
1078 [(set (match_operand:<VNNCONVERT> 0 "register_operand")
1079 (any_float:<VNNCONVERT>
1080 (match_operand:VWWCONVERTI 1 "register_operand")))]
1081 "TARGET_VECTOR && TARGET_ZVFH && can_create_pseudo_p () && !flag_trapping_math"
1082 {
1083 rtx single = gen_reg_rtx (<VNCONVERT>mode); /* Get vector SF mode. */
1084
1085 /* Step-1, INT64 => FP32. */
1086 emit_insn (gen_<float_cvt><mode><vnconvert>2 (single, operands[1]));
1087 /* Step-2, FP32 => FP16. */
1088 emit_insn (gen_trunc<vnconvert><vnnconvert>2 (operands[0], single));
1089
1090 DONE;
1091 })
1092
1093 ;; =========================================================================
1094 ;; == Unary arithmetic
1095 ;; =========================================================================
1096
1097 ;; -------------------------------------------------------------------------------
1098 ;; ---- [INT] Unary operations
1099 ;; -------------------------------------------------------------------------------
1100 ;; Includes:
1101 ;; - vneg.v/vnot.v
1102 ;; -------------------------------------------------------------------------------
1103 (define_insn_and_split "<optab><mode>2"
1104 [(set (match_operand:V_VLSI 0 "register_operand")
1105 (any_int_unop:V_VLSI
1106 (match_operand:V_VLSI 1 "register_operand")))]
1107 "TARGET_VECTOR && can_create_pseudo_p ()"
1108 "#"
1109 "&& 1"
1110 [(const_int 0)]
1111 {
1112 insn_code icode = code_for_pred (<CODE>, <MODE>mode);
1113 riscv_vector::emit_vlmax_insn (icode, riscv_vector::UNARY_OP, operands);
1114 DONE;
1115 }
1116 [(set_attr "type" "vialu")])
1117
1118 ;; -------------------------------------------------------------------------------
1119 ;; - [INT] ABS expansion to vneg and vmax.
1120 ;; -------------------------------------------------------------------------------
1121
1122 (define_expand "abs<mode>2"
1123 [(set (match_operand:V_VLSI 0 "register_operand")
1124 (smax:V_VLSI
1125 (match_dup 0)
1126 (neg:V_VLSI
1127 (match_operand:V_VLSI 1 "register_operand"))))]
1128 "TARGET_VECTOR"
1129 {
1130 DONE;
1131 })
1132
1133 ;; -------------------------------------------------------------------------------
1134 ;; ---- [FP] Unary operations
1135 ;; -------------------------------------------------------------------------------
1136 ;; Includes:
1137 ;; - vfneg.v/vfabs.v
1138 ;; -------------------------------------------------------------------------------
1139 (define_insn_and_split "<optab><mode>2"
1140 [(set (match_operand:V_VLSF 0 "register_operand")
1141 (any_float_unop_nofrm:V_VLSF
1142 (match_operand:V_VLSF 1 "register_operand")))]
1143 "TARGET_VECTOR && can_create_pseudo_p ()"
1144 "#"
1145 "&& 1"
1146 [(const_int 0)]
1147 {
1148 insn_code icode = code_for_pred (<CODE>, <MODE>mode);
1149 riscv_vector::emit_vlmax_insn (icode, riscv_vector::UNARY_OP, operands);
1150 DONE;
1151 }
1152 [(set_attr "type" "vector")])
1153
1154 ;; -------------------------------------------------------------------------------
1155 ;; - [FP] Square root
1156 ;; -------------------------------------------------------------------------------
1157 ;; Includes:
1158 ;; - vfsqrt.v
1159 ;; -------------------------------------------------------------------------------
1160 (define_insn_and_split "<optab><mode>2"
1161 [(set (match_operand:V_VLSF 0 "register_operand")
1162 (any_float_unop:V_VLSF
1163 (match_operand:V_VLSF 1 "register_operand")))]
1164 "TARGET_VECTOR && can_create_pseudo_p ()"
1165 "#"
1166 "&& 1"
1167 [(const_int 0)]
1168 {
1169 insn_code icode = code_for_pred (<CODE>, <MODE>mode);
1170 riscv_vector::emit_vlmax_insn (icode, riscv_vector::UNARY_OP_FRM_DYN, operands);
1171 DONE;
1172 }
1173 [(set_attr "type" "vfsqrt")])
1174
1175 ;; =========================================================================
1176 ;; == Ternary arithmetic
1177 ;; =========================================================================
1178
1179 ;; -------------------------------------------------------------------------
1180 ;; ---- [INT] VMACC and VMADD
1181 ;; -------------------------------------------------------------------------
1182 ;; Includes:
1183 ;; - vmacc
1184 ;; - vmadd
1185 ;; -------------------------------------------------------------------------
1186
1187 (define_insn_and_split "fma<mode>4"
1188 [(set (match_operand:V_VLSI 0 "register_operand")
1189 (plus:V_VLSI
1190 (mult:V_VLSI
1191 (match_operand:V_VLSI 1 "register_operand")
1192 (match_operand:V_VLSI 2 "register_operand"))
1193 (match_operand:V_VLSI 3 "register_operand")))]
1194 "TARGET_VECTOR && can_create_pseudo_p ()"
1195 "#"
1196 "&& 1"
1197 [(const_int 0)]
1198 {
1199 rtx ops[] = {operands[0], operands[1], operands[2], operands[3],
1200 RVV_VUNDEF(<MODE>mode)};
1201 riscv_vector::emit_vlmax_insn (code_for_pred_mul_plus (<MODE>mode),
1202 riscv_vector::TERNARY_OP, ops);
1203 DONE;
1204 }
1205 [(set_attr "type" "vector")])
1206
1207 ;; -------------------------------------------------------------------------
1208 ;; ---- [INT] VNMSAC and VNMSUB
1209 ;; -------------------------------------------------------------------------
1210 ;; Includes:
1211 ;; - vnmsac
1212 ;; - vnmsub
1213 ;; -------------------------------------------------------------------------
1214
1215 (define_insn_and_split "fnma<mode>4"
1216 [(set (match_operand:V_VLSI 0 "register_operand")
1217 (minus:V_VLSI
1218 (match_operand:V_VLSI 3 "register_operand")
1219 (mult:V_VLSI
1220 (match_operand:V_VLSI 1 "register_operand")
1221 (match_operand:V_VLSI 2 "register_operand"))))]
1222 "TARGET_VECTOR && can_create_pseudo_p ()"
1223 "#"
1224 "&& 1"
1225 [(const_int 0)]
1226 {
1227 rtx ops[] = {operands[0], operands[1], operands[2], operands[3],
1228 RVV_VUNDEF(<MODE>mode)};
1229 riscv_vector::emit_vlmax_insn (code_for_pred_minus_mul (<MODE>mode),
1230 riscv_vector::TERNARY_OP, ops);
1231 DONE;
1232 }
1233 [(set_attr "type" "vector")])
1234
1235 ;; -------------------------------------------------------------------------
1236 ;; ---- [FP] VFMACC and VFMADD
1237 ;; -------------------------------------------------------------------------
1238 ;; Includes:
1239 ;; - vfmacc
1240 ;; - vfmadd
1241 ;; -------------------------------------------------------------------------
1242
1243 (define_insn_and_split "fma<mode>4"
1244 [(set (match_operand:V_VLSF 0 "register_operand")
1245 (plus:V_VLSF
1246 (mult:V_VLSF
1247 (match_operand:V_VLSF 1 "register_operand")
1248 (match_operand:V_VLSF 2 "register_operand"))
1249 (match_operand:V_VLSF 3 "register_operand")))]
1250 "TARGET_VECTOR && can_create_pseudo_p ()"
1251 "#"
1252 "&& 1"
1253 [(const_int 0)]
1254 {
1255 rtx ops[] = {operands[0], operands[1], operands[2], operands[3],
1256 RVV_VUNDEF(<MODE>mode)};
1257 riscv_vector::emit_vlmax_insn (code_for_pred_mul (PLUS, <MODE>mode),
1258 riscv_vector::TERNARY_OP_FRM_DYN, ops);
1259 DONE;
1260 }
1261 [(set_attr "type" "vector")])
1262
1263 ;; -------------------------------------------------------------------------
1264 ;; ---- [FP] VFNMSAC and VFNMSUB
1265 ;; -------------------------------------------------------------------------
1266 ;; Includes:
1267 ;; - vfnmsac
1268 ;; - vfnmsub
1269 ;; -------------------------------------------------------------------------
1270
1271 (define_insn_and_split "fnma<mode>4"
1272 [(set (match_operand:V_VLSF 0 "register_operand")
1273 (minus:V_VLSF
1274 (match_operand:V_VLSF 3 "register_operand")
1275 (mult:V_VLSF
1276 (match_operand:V_VLSF 1 "register_operand")
1277 (match_operand:V_VLSF 2 "register_operand"))))]
1278 "TARGET_VECTOR && can_create_pseudo_p ()"
1279 "#"
1280 "&& 1"
1281 [(const_int 0)]
1282 {
1283 rtx ops[] = {operands[0], operands[1], operands[2], operands[3],
1284 RVV_VUNDEF(<MODE>mode)};
1285 riscv_vector::emit_vlmax_insn (code_for_pred_mul_neg (PLUS, <MODE>mode),
1286 riscv_vector::TERNARY_OP_FRM_DYN, ops);
1287 DONE;
1288 }
1289 [(set_attr "type" "vector")])
1290
1291 ;; -------------------------------------------------------------------------
1292 ;; ---- [FP] VFMSAC and VFMSUB
1293 ;; -------------------------------------------------------------------------
1294 ;; Includes:
1295 ;; - vfmsac
1296 ;; - vfmsub
1297 ;; -------------------------------------------------------------------------
1298
1299 (define_insn_and_split "fms<mode>4"
1300 [(set (match_operand:V_VLSF 0 "register_operand")
1301 (minus:V_VLSF
1302 (mult:V_VLSF
1303 (match_operand:V_VLSF 1 "register_operand")
1304 (match_operand:V_VLSF 2 "register_operand"))
1305 (match_operand:V_VLSF 3 "register_operand")))]
1306 "TARGET_VECTOR && can_create_pseudo_p ()"
1307 "#"
1308 "&& 1"
1309 [(const_int 0)]
1310 {
1311 rtx ops[] = {operands[0], operands[1], operands[2], operands[3],
1312 RVV_VUNDEF(<MODE>mode)};
1313 riscv_vector::emit_vlmax_insn (code_for_pred_mul (MINUS, <MODE>mode),
1314 riscv_vector::TERNARY_OP_FRM_DYN, ops);
1315 DONE;
1316 }
1317 [(set_attr "type" "vector")])
1318
1319 ;; -------------------------------------------------------------------------
1320 ;; ---- [FP] VFNMACC and VFNMADD
1321 ;; -------------------------------------------------------------------------
1322 ;; Includes:
1323 ;; - vfnmacc
1324 ;; - vfnmadd
1325 ;; -------------------------------------------------------------------------
1326
1327 (define_insn_and_split "fnms<mode>4"
1328 [(set (match_operand:V_VLSF 0 "register_operand")
1329 (minus:V_VLSF
1330 (neg:V_VLSF
1331 (mult:V_VLSF
1332 (match_operand:V_VLSF 1 "register_operand")
1333 (match_operand:V_VLSF 2 "register_operand")))
1334 (match_operand:V_VLSF 3 "register_operand")))]
1335 "TARGET_VECTOR && can_create_pseudo_p ()"
1336 "#"
1337 "&& 1"
1338 [(const_int 0)]
1339 {
1340 rtx ops[] = {operands[0], operands[1], operands[2], operands[3],
1341 RVV_VUNDEF(<MODE>mode)};
1342 riscv_vector::emit_vlmax_insn (code_for_pred_mul_neg (MINUS, <MODE>mode),
1343 riscv_vector::TERNARY_OP_FRM_DYN, ops);
1344 DONE;
1345 }
1346 [(set_attr "type" "vector")])
1347
1348 ;; =========================================================================
1349 ;; == SELECT_VL
1350 ;; =========================================================================
1351
1352 (define_expand "select_vl<mode>"
1353 [(match_operand:P 0 "register_operand")
1354 (match_operand:P 1 "vector_length_operand")
1355 (match_operand:P 2 "")]
1356 "TARGET_VECTOR"
1357 {
1358 riscv_vector::expand_select_vl (operands);
1359 DONE;
1360 })
1361
1362 ;; -------------------------------------------------------------------------
1363 ;; ---- [INT,FP] Insert a vector element.
1364 ;; -------------------------------------------------------------------------
1365
1366 (define_expand "vec_set<mode>"
1367 [(match_operand:V_VLS 0 "register_operand")
1368 (match_operand:<VEL> 1 "register_operand")
1369 (match_operand 2 "nonmemory_operand")]
1370 "TARGET_VECTOR"
1371 {
1372 /* If we set the first element, emit an v(f)mv.s.[xf]. */
1373 if (operands[2] == const0_rtx)
1374 {
1375 rtx ops[] = {operands[0], operands[0], operands[1]};
1376 riscv_vector::emit_nonvlmax_insn (code_for_pred_broadcast (<MODE>mode),
1377 riscv_vector::SCALAR_MOVE_MERGED_OP_TU,
1378 ops, CONST1_RTX (Pmode));
1379 }
1380 else
1381 {
1382 /* Move the desired value into a vector register and insert
1383 it at the proper position using vslideup with an
1384 "effective length" of 1 i.e. a VL 1 past the offset. */
1385
1386 /* Here we set VL = offset + 1. */
1387 rtx length = gen_reg_rtx (Pmode);
1388 operands[2] = gen_lowpart (Pmode, operands[2]);
1389 if (CONST_INT_P (operands[2]))
1390 emit_move_insn (length, GEN_INT (INTVAL (operands[2]) + 1));
1391 else
1392 {
1393 rtx add = gen_rtx_PLUS (GET_MODE (operands[2]),
1394 operands[2], GEN_INT (1));
1395 emit_move_insn (length, add);
1396 }
1397
1398 /* Move operands[1] into a vector register via vmv.v.x using the same
1399 VL we need for the slide. */
1400 rtx tmp = gen_reg_rtx (<MODE>mode);
1401 rtx ops1[] = {tmp, operands[1]};
1402 emit_nonvlmax_insn (code_for_pred_broadcast (<MODE>mode),
1403 riscv_vector::UNARY_OP, ops1, length);
1404
1405 /* Slide exactly one element up leaving the tail elements
1406 unchanged. */
1407 rtx ops2[] = {operands[0], operands[0], tmp, operands[2]};
1408 riscv_vector::emit_nonvlmax_insn
1409 (code_for_pred_slide (UNSPEC_VSLIDEUP, <MODE>mode), riscv_vector::BINARY_OP_TUMA, ops2, length);
1410 }
1411 DONE;
1412 })
1413
1414 ;; -------------------------------------------------------------------------
1415 ;; ---- [INT,FP] Extract a vector element.
1416 ;; -------------------------------------------------------------------------
1417 (define_expand "vec_extract<mode><vel>"
1418 [(set (match_operand:<VEL> 0 "register_operand")
1419 (vec_select:<VEL>
1420 (match_operand:V_VLS_ZVFH 1 "register_operand")
1421 (parallel
1422 [(match_operand 2 "nonmemory_operand")])))]
1423 "TARGET_VECTOR"
1424 {
1425 /* Element extraction can be done by sliding down the requested element
1426 to index 0 and then v(f)mv.[xf].s it to a scalar register. */
1427
1428 /* When extracting any other than the first element we need to slide
1429 it down. */
1430 rtx tmp = NULL_RTX;
1431 if (operands[2] != const0_rtx)
1432 {
1433 /* Properly convert a poly_int value and put the result into a
1434 register. */
1435 if (CONST_POLY_INT_P (operands[2]))
1436 {
1437 rtx pos = gen_reg_rtx (Pmode);
1438 riscv_legitimize_poly_move (Pmode, pos, gen_reg_rtx (Pmode),
1439 operands[2]);
1440 operands[2] = pos;
1441 }
1442
1443 /* Emit the slide down to index 0 in a new vector. */
1444 tmp = gen_reg_rtx (<MODE>mode);
1445 operands[2] = gen_lowpart (Pmode, operands[2]);
1446 rtx ops[] = {tmp, operands[1], operands[2]};
1447 riscv_vector::emit_vlmax_insn
1448 (code_for_pred_slide (UNSPEC_VSLIDEDOWN, <MODE>mode),
1449 riscv_vector::BINARY_OP, ops);
1450 }
1451
1452 /* Emit v(f)mv.[xf].s. */
1453 emit_insn (gen_pred_extract_first (<MODE>mode, operands[0],
1454 tmp ? tmp : operands[1]));
1455 DONE;
1456 })
1457
1458 ;; -------------------------------------------------------------------------
1459 ;; This extracts a bit (via QImode) from a bitmask vector.
1460 ;; -------------------------------------------------------------------------
1461 (define_expand "vec_extract<mode>qi"
1462 [(set (match_operand:QI 0 "register_operand")
1463 (vec_select:QI
1464 (match_operand:VB_VLS 1 "register_operand")
1465 (parallel
1466 [(match_operand 2 "nonmemory_operand")])))]
1467 "TARGET_VECTOR"
1468 {
1469 /* Create an empty byte vector and set it to one under mask.
1470 For XTheadVector which does not have fractional-LMUL modes, we use
1471 a full-size vector instead. */
1472 bool fractional_p = known_lt (GET_MODE_NUNITS (<MODE>mode),
1473 BYTES_PER_RISCV_VECTOR);
1474 machine_mode qimode;
1475 if (!TARGET_XTHEADVECTOR || !fractional_p)
1476 qimode = riscv_vector::get_vector_mode
1477 (QImode, GET_MODE_NUNITS (<MODE>mode)).require ();
1478 else
1479 qimode = riscv_vector::get_m1_mode
1480 (QImode, GET_MODE_NUNITS (<MODE>mode).is_constant ()).require ();
1481
1482 rtx tmp1 = gen_reg_rtx (qimode);
1483 emit_move_insn (tmp1, gen_const_vec_duplicate (qimode, GEN_INT (0)));
1484 rtx ones = gen_const_vec_duplicate (qimode, GEN_INT (1));
1485
1486 rtx op1;
1487 if (!TARGET_XTHEADVECTOR || !fractional_p)
1488 op1 = operands[1];
1489 else
1490 op1 = gen_lowpart (riscv_vector::get_mask_mode (qimode), operands[1]);
1491
1492 rtx ops1[] = {tmp1, tmp1, ones, op1};
1493 riscv_vector::emit_vlmax_insn (code_for_pred_merge (qimode),
1494 riscv_vector::MERGE_OP, ops1);
1495
1496 /* Extract from it. */
1497 riscv_vector::emit_vec_extract (operands[0], tmp1, operands[2]);
1498 DONE;
1499 })
1500
1501 ;; Same for a BImode but still return a QImode.
1502 (define_expand "vec_extract<mode>bi"
1503 [(set (match_operand:QI 0 "register_operand")
1504 (vec_select:QI
1505 (match_operand:VB_VLS 1 "register_operand")
1506 (parallel
1507 [(match_operand 2 "nonmemory_operand")])))]
1508 "TARGET_VECTOR"
1509 {
1510 emit_insn (gen_vec_extract<mode>qi (operands[0], operands[1], operands[2]));
1511 DONE;
1512 })
1513
1514 ;; -------------------------------------------------------------------------
1515 ;; ---- [INT,FP] Extract a vector from a vector.
1516 ;; -------------------------------------------------------------------------
1517 ;; TODO: This can be extended to allow basically any extract mode.
1518 ;; For now this helps optimize VLS subregs like (subreg:V2DI (reg:V4DI) 16)
1519 ;; that would otherwise need to go via memory.
1520
1521 (define_expand "vec_extract<mode><vls_half>"
1522 [(set (match_operand:<VLS_HALF> 0 "nonimmediate_operand")
1523 (vec_select:<VLS_HALF>
1524 (match_operand:VLS_HAS_HALF 1 "register_operand")
1525 (parallel
1526 [(match_operand 2 "immediate_operand")])))]
1527 "TARGET_VECTOR"
1528 {
1529 int sz = GET_MODE_NUNITS (<VLS_HALF>mode).to_constant ();
1530 int part = INTVAL (operands[2]);
1531
1532 rtx start = GEN_INT (part * sz);
1533 rtx tmp = operands[1];
1534
1535 if (part != 0)
1536 {
1537 tmp = gen_reg_rtx (<MODE>mode);
1538
1539 rtx ops[] = {tmp, operands[1], start};
1540 riscv_vector::emit_vlmax_insn
1541 (code_for_pred_slide (UNSPEC_VSLIDEDOWN, <MODE>mode),
1542 riscv_vector::BINARY_OP, ops);
1543 }
1544
1545 emit_move_insn (operands[0], gen_lowpart (<VLS_HALF>mode, tmp));
1546 DONE;
1547 })
1548
1549 (define_expand "vec_extract<mode><vls_quarter>"
1550 [(set (match_operand:<VLS_QUARTER> 0 "nonimmediate_operand")
1551 (vec_select:<VLS_QUARTER>
1552 (match_operand:VLS_HAS_QUARTER 1 "register_operand")
1553 (parallel
1554 [(match_operand 2 "immediate_operand")])))]
1555 "TARGET_VECTOR"
1556 {
1557 int sz = GET_MODE_NUNITS (<VLS_QUARTER>mode).to_constant ();
1558 int part = INTVAL (operands[2]);
1559
1560 rtx start = GEN_INT (part * sz);
1561 rtx tmp = operands[1];
1562
1563 if (part != 0)
1564 {
1565 tmp = gen_reg_rtx (<MODE>mode);
1566
1567 rtx ops[] = {tmp, operands[1], start};
1568 riscv_vector::emit_vlmax_insn
1569 (code_for_pred_slide (UNSPEC_VSLIDEDOWN, <MODE>mode),
1570 riscv_vector::BINARY_OP, ops);
1571 }
1572
1573 emit_move_insn (operands[0], gen_lowpart (<VLS_QUARTER>mode, tmp));
1574 DONE;
1575 })
1576
1577 ;; -------------------------------------------------------------------------
1578 ;; ---- [FP] Binary operations
1579 ;; -------------------------------------------------------------------------
1580 ;; Includes:
1581 ;; - vfadd.vv/vfsub.vv/...
1582 ;; - vfadd.vf/vfsub.vf/...
1583 ;; -------------------------------------------------------------------------
1584 (define_insn_and_split "<optab><mode>3"
1585 [(set (match_operand:V_VLSF 0 "register_operand")
1586 (any_float_binop:V_VLSF
1587 (match_operand:V_VLSF 1 "register_operand")
1588 (match_operand:V_VLSF 2 "register_operand")))]
1589 "TARGET_VECTOR && can_create_pseudo_p ()"
1590 "#"
1591 "&& 1"
1592 [(const_int 0)]
1593 {
1594 riscv_vector::emit_vlmax_insn (code_for_pred (<CODE>, <MODE>mode),
1595 riscv_vector::BINARY_OP_FRM_DYN, operands);
1596 DONE;
1597 }
1598 [(set_attr "type" "vfalu")])
1599
1600 ;; -------------------------------------------------------------------------
1601 ;; Includes:
1602 ;; - vfmin.vv/vfmax.vv
1603 ;; - vfmin.vf/vfmax.vf
1604 ;; -------------------------------------------------------------------------
1605 (define_insn_and_split "<optab><mode>3"
1606 [(set (match_operand:V_VLSF 0 "register_operand")
1607 (any_float_binop_nofrm:V_VLSF
1608 (match_operand:V_VLSF 1 "register_operand")
1609 (match_operand:V_VLSF 2 "register_operand")))]
1610 "TARGET_VECTOR && can_create_pseudo_p ()"
1611 "#"
1612 "&& 1"
1613 [(const_int 0)]
1614 {
1615 riscv_vector::emit_vlmax_insn (code_for_pred (<CODE>, <MODE>mode),
1616 riscv_vector::BINARY_OP, operands);
1617 DONE;
1618 }
1619 [(set_attr "type" "vfminmax")])
1620
1621 (define_insn_and_split "<ieee_fmaxmin_op><mode>3"
1622 [(set (match_operand:V_VLSF 0 "register_operand")
1623 (unspec:V_VLSF
1624 [(match_operand:V_VLSF 1 "register_operand")
1625 (match_operand:V_VLSF 2 "register_operand")] UNSPEC_VFMAXMIN))]
1626 "TARGET_VECTOR && !HONOR_SNANS (<MODE>mode) && can_create_pseudo_p ()"
1627 "#"
1628 "&& 1"
1629 [(const_int 0)]
1630 {
1631 riscv_vector::emit_vlmax_insn (code_for_pred (<IEEE_FMAXMIN_OP>, <MODE>mode),
1632 riscv_vector::BINARY_OP, operands);
1633 DONE;
1634 }
1635 [(set_attr "type" "vfminmax")])
1636
1637 ;; -------------------------------------------------------------------------------
1638 ;; ---- [FP] Sign copying
1639 ;; -------------------------------------------------------------------------------
1640 ;; Includes:
1641 ;; - vfsgnj.vv/vfsgnjn.vv
1642 ;; - vfsgnj.vf/vfsgnjn.vf
1643 ;; -------------------------------------------------------------------------------
1644
1645 ;; Leave the pattern like this as to still allow combine to match
1646 ;; a negated copysign (see vector.md) before adding the UNSPEC_VPREDICATE later.
1647 (define_insn_and_split "copysign<mode>3"
1648 [(set (match_operand:V_VLSF 0 "register_operand" "=vd, vd, vr, vr")
1649 (unspec:V_VLSF
1650 [(match_operand:V_VLSF 1 "register_operand" " vr, vr, vr, vr")
1651 (match_operand:V_VLSF 2 "register_operand" " vr, vr, vr, vr")] UNSPEC_VCOPYSIGN))]
1652 "TARGET_VECTOR && can_create_pseudo_p ()"
1653 "#"
1654 "&& 1"
1655 [(const_int 0)]
1656 {
1657 riscv_vector::emit_vlmax_insn (code_for_pred (UNSPEC_VCOPYSIGN, <MODE>mode),
1658 riscv_vector::BINARY_OP, operands);
1659 DONE;
1660 }
1661 [(set_attr "type" "vfsgnj")
1662 (set_attr "mode" "<MODE>")])
1663
1664 ;; -------------------------------------------------------------------------------
1665 ;; Includes:
1666 ;; - vfsgnjx.vv
1667 ;; - vfsgnjx.vf
1668 ;; -------------------------------------------------------------------------------
1669 (define_expand "xorsign<mode>3"
1670 [(match_operand:V_VLSF 0 "register_operand")
1671 (match_operand:V_VLSF 1 "register_operand")
1672 (match_operand:V_VLSF 2 "register_operand")]
1673 "TARGET_VECTOR"
1674 {
1675 riscv_vector::emit_vlmax_insn (code_for_pred (UNSPEC_VXORSIGN, <MODE>mode),
1676 riscv_vector::BINARY_OP, operands);
1677 DONE;
1678 })
1679
1680 ;; -------------------------------------------------------------------------------
1681 ;; - [INT] POPCOUNT, CTZ and CLZ.
1682 ;; -------------------------------------------------------------------------------
1683
1684 (define_expand "popcount<mode>2"
1685 [(match_operand:V_VLSI 0 "register_operand")
1686 (match_operand:V_VLSI 1 "register_operand")]
1687 "TARGET_VECTOR"
1688 {
1689 if (!TARGET_ZVBB)
1690 riscv_vector::expand_popcount (operands);
1691 else
1692 {
1693 riscv_vector::emit_vlmax_insn (code_for_pred_v (POPCOUNT, <MODE>mode),
1694 riscv_vector::CPOP_OP, operands);
1695 }
1696 DONE;
1697 })
1698
1699 (define_expand "ctz<mode>2"
1700 [(match_operand:V_VLSI 0 "register_operand")
1701 (match_operand:V_VLSI 1 "register_operand")]
1702 "TARGET_ZVBB"
1703 {
1704 riscv_vector::emit_vlmax_insn (code_for_pred_v (CTZ, <MODE>mode),
1705 riscv_vector::CPOP_OP, operands);
1706 DONE;
1707 })
1708
1709 (define_expand "clz<mode>2"
1710 [(match_operand:V_VLSI 0 "register_operand")
1711 (match_operand:V_VLSI 1 "register_operand")]
1712 "TARGET_ZVBB"
1713 {
1714 riscv_vector::emit_vlmax_insn (code_for_pred_v (CLZ, <MODE>mode),
1715 riscv_vector::CPOP_OP, operands);
1716 DONE;
1717 })
1718
1719
1720 ;; -------------------------------------------------------------------------
1721 ;; ---- [INT] Highpart multiplication
1722 ;; -------------------------------------------------------------------------
1723 ;; Includes:
1724 ;; - vmulh.vv
1725 ;; - vmulhu.vv
1726 ;; -------------------------------------------------------------------------
1727
1728 (define_insn_and_split "<mulh_table><mode>3_highpart"
1729 [(set (match_operand:VFULLI 0 "register_operand")
1730 (mulh:VFULLI
1731 (match_operand:VFULLI 1 "register_operand")
1732 (match_operand:VFULLI 2 "register_operand")))]
1733 "TARGET_VECTOR && can_create_pseudo_p ()"
1734 "#"
1735 "&& 1"
1736 [(const_int 0)]
1737 {
1738 insn_code icode = code_for_pred_mulh (<MULH_UNSPEC>, <MODE>mode);
1739 riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, operands);
1740 DONE;
1741 }
1742 [(set_attr "type" "vimul")])
1743
1744 ;; -------------------------------------------------------------------------
1745 ;; ---- [INT] Conditional unary operations
1746 ;; -------------------------------------------------------------------------
1747 ;; Includes:
1748 ;; - vneg/vnot
1749 ;; -------------------------------------------------------------------------
1750
1751 (define_expand "cond_<optab><mode>"
1752 [(match_operand:V_VLSI 0 "register_operand")
1753 (match_operand:<VM> 1 "vector_mask_operand")
1754 (any_int_unop:V_VLSI
1755 (match_operand:V_VLSI 2 "register_operand"))
1756 (match_operand:V_VLSI 3 "autovec_else_operand")]
1757 "TARGET_VECTOR"
1758 {
1759 insn_code icode = code_for_pred (<CODE>, <MODE>mode);
1760 riscv_vector::expand_cond_unop (icode, operands);
1761 DONE;
1762 })
1763
1764 (define_expand "cond_len_<optab><mode>"
1765 [(match_operand:VI 0 "register_operand")
1766 (match_operand:<VM> 1 "vector_mask_operand")
1767 (any_int_unop:VI
1768 (match_operand:VI 2 "register_operand"))
1769 (match_operand:VI 3 "autovec_else_operand")
1770 (match_operand 4 "autovec_length_operand")
1771 (match_operand 5 "const_0_operand")]
1772 "TARGET_VECTOR"
1773 {
1774 insn_code icode = code_for_pred (<CODE>, <MODE>mode);
1775 riscv_vector::expand_cond_len_unop (icode, operands);
1776 DONE;
1777 })
1778
1779 ;; -------------------------------------------------------------------------
1780 ;; ---- [FP] Conditional unary operations
1781 ;; -------------------------------------------------------------------------
1782 ;; Includes:
1783 ;; - vfneg/vfabs
1784 ;; -------------------------------------------------------------------------
1785
1786 (define_expand "cond_<optab><mode>"
1787 [(match_operand:V_VLSF 0 "register_operand")
1788 (match_operand:<VM> 1 "vector_mask_operand")
1789 (any_float_unop_nofrm:V_VLSF
1790 (match_operand:V_VLSF 2 "register_operand"))
1791 (match_operand:V_VLSF 3 "autovec_else_operand")]
1792 "TARGET_VECTOR"
1793 {
1794 insn_code icode = code_for_pred (<CODE>, <MODE>mode);
1795 riscv_vector::expand_cond_unop (icode, operands);
1796 DONE;
1797 })
1798
1799 (define_expand "cond_len_<optab><mode>"
1800 [(match_operand:VF 0 "register_operand")
1801 (match_operand:<VM> 1 "vector_mask_operand")
1802 (any_float_unop_nofrm:VF
1803 (match_operand:VF 2 "register_operand"))
1804 (match_operand:VF 3 "autovec_else_operand")
1805 (match_operand 4 "autovec_length_operand")
1806 (match_operand 5 "const_0_operand")]
1807 "TARGET_VECTOR"
1808 {
1809 insn_code icode = code_for_pred (<CODE>, <MODE>mode);
1810 riscv_vector::expand_cond_len_unop (icode, operands);
1811 DONE;
1812 })
1813
1814 ;; -------------------------------------------------------------------------
1815 ;; ---- [INT] Conditional binary operations
1816 ;; -------------------------------------------------------------------------
1817 ;; Includes:
1818 ;; - vsra/vsrl/vsll
1819 ;; -------------------------------------------------------------------------
1820
1821 (define_expand "cond_<optab><mode>"
1822 [(match_operand:V_VLSI 0 "register_operand")
1823 (match_operand:<VM> 1 "vector_mask_operand")
1824 (any_shift:V_VLSI
1825 (match_operand:V_VLSI 2 "register_operand")
1826 (match_operand:V_VLSI 3 "vector_shift_operand"))
1827 (match_operand:V_VLSI 4 "autovec_else_operand")]
1828 "TARGET_VECTOR"
1829 {
1830 insn_code icode = code_for_pred (<CODE>, <MODE>mode);
1831 riscv_vector::expand_cond_binop (icode, operands);
1832 DONE;
1833 })
1834
1835 (define_expand "cond_len_<optab><mode>"
1836 [(match_operand:VI 0 "register_operand")
1837 (match_operand:<VM> 1 "vector_mask_operand")
1838 (any_shift:VI
1839 (match_operand:VI 2 "register_operand")
1840 (match_operand:VI 3 "vector_shift_operand"))
1841 (match_operand:VI 4 "autovec_else_operand")
1842 (match_operand 5 "autovec_length_operand")
1843 (match_operand 6 "const_0_operand")]
1844 "TARGET_VECTOR"
1845 {
1846 insn_code icode = code_for_pred (<CODE>, <MODE>mode);
1847 riscv_vector::expand_cond_len_binop (icode, operands);
1848 DONE;
1849 })
1850
1851 ;; -------------------------------------------------------------------------
1852 ;; ---- [INT] Conditional binary operations
1853 ;; -------------------------------------------------------------------------
1854 ;; Includes:
1855 ;; - vadd.vv/vsub.vv/...
1856 ;; - vadd.vi/vsub.vi/...
1857 ;; -------------------------------------------------------------------------
1858
1859 (define_expand "cond_<optab><mode>"
1860 [(match_operand:V_VLSI 0 "register_operand")
1861 (match_operand:<VM> 1 "vector_mask_operand")
1862 (any_int_binop_no_shift:V_VLSI
1863 (match_operand:V_VLSI 2 "<binop_rhs1_predicate>")
1864 (match_operand:V_VLSI 3 "<binop_rhs2_predicate>"))
1865 (match_operand:V_VLSI 4 "autovec_else_operand")]
1866 "TARGET_VECTOR"
1867 {
1868 insn_code icode = code_for_pred (<CODE>, <MODE>mode);
1869 riscv_vector::expand_cond_binop (icode, operands);
1870 DONE;
1871 })
1872
1873 (define_expand "cond_len_<optab><mode>"
1874 [(match_operand:VI 0 "register_operand")
1875 (match_operand:<VM> 1 "vector_mask_operand")
1876 (any_int_binop_no_shift:VI
1877 (match_operand:VI 2 "<binop_rhs1_predicate>")
1878 (match_operand:VI 3 "<binop_rhs2_predicate>"))
1879 (match_operand:VI 4 "autovec_else_operand")
1880 (match_operand 5 "autovec_length_operand")
1881 (match_operand 6 "const_0_operand")]
1882 "TARGET_VECTOR"
1883 {
1884 insn_code icode = code_for_pred (<CODE>, <MODE>mode);
1885 riscv_vector::expand_cond_len_binop (icode, operands);
1886 DONE;
1887 })
1888
1889 ;; -------------------------------------------------------------------------
1890 ;; ---- [FP] Conditional binary operations
1891 ;; -------------------------------------------------------------------------
1892 ;; Includes:
1893 ;; - vfadd.vv/vfsub.vv/...
1894 ;; - vfadd.vf/vfsub.vf/...
1895 ;; -------------------------------------------------------------------------
1896
1897 (define_expand "cond_<optab><mode>"
1898 [(match_operand:V_VLSF 0 "register_operand")
1899 (match_operand:<VM> 1 "vector_mask_operand")
1900 (any_float_binop:V_VLSF
1901 (match_operand:V_VLSF 2 "register_operand")
1902 (match_operand:V_VLSF 3 "register_operand"))
1903 (match_operand:V_VLSF 4 "autovec_else_operand")]
1904 "TARGET_VECTOR"
1905 {
1906 insn_code icode = code_for_pred (<CODE>, <MODE>mode);
1907 riscv_vector::expand_cond_binop (icode, operands);
1908 DONE;
1909 })
1910
1911 (define_expand "cond_len_<optab><mode>"
1912 [(match_operand:VF 0 "register_operand")
1913 (match_operand:<VM> 1 "vector_mask_operand")
1914 (any_float_binop:VF
1915 (match_operand:VF 2 "register_operand")
1916 (match_operand:VF 3 "register_operand"))
1917 (match_operand:VF 4 "autovec_else_operand")
1918 (match_operand 5 "autovec_length_operand")
1919 (match_operand 6 "const_0_operand")]
1920 "TARGET_VECTOR"
1921 {
1922 insn_code icode = code_for_pred (<CODE>, <MODE>mode);
1923 riscv_vector::expand_cond_len_binop (icode, operands);
1924 DONE;
1925 })
1926
1927 ;; -------------------------------------------------------------------------
1928 ;; Includes:
1929 ;; - vfmin.vv/vfmax.vv
1930 ;; - vfmin.vf/vfmax.vf
1931 ;; -------------------------------------------------------------------------
1932
1933 (define_expand "cond_<optab><mode>"
1934 [(match_operand:V_VLSF 0 "register_operand")
1935 (match_operand:<VM> 1 "vector_mask_operand")
1936 (any_float_binop_nofrm:V_VLSF
1937 (match_operand:V_VLSF 2 "register_operand")
1938 (match_operand:V_VLSF 3 "register_operand"))
1939 (match_operand:V_VLSF 4 "autovec_else_operand")]
1940 "TARGET_VECTOR"
1941 {
1942 insn_code icode = code_for_pred (<CODE>, <MODE>mode);
1943 riscv_vector::expand_cond_binop (icode, operands);
1944 DONE;
1945 })
1946
1947 (define_expand "cond_len_<optab><mode>"
1948 [(match_operand:VF 0 "register_operand")
1949 (match_operand:<VM> 1 "vector_mask_operand")
1950 (any_float_binop_nofrm:VF
1951 (match_operand:VF 2 "register_operand")
1952 (match_operand:VF 3 "register_operand"))
1953 (match_operand:VF 4 "autovec_else_operand")
1954 (match_operand 5 "autovec_length_operand")
1955 (match_operand 6 "const_0_operand")]
1956 "TARGET_VECTOR"
1957 {
1958 insn_code icode = code_for_pred (<CODE>, <MODE>mode);
1959 riscv_vector::expand_cond_len_binop (icode, operands);
1960 DONE;
1961 })
1962
1963 (define_expand "cond_<ieee_fmaxmin_op><mode>"
1964 [(match_operand:V_VLSF 0 "register_operand")
1965 (match_operand:<VM> 1 "vector_mask_operand")
1966 (unspec:V_VLSF
1967 [(match_operand:V_VLSF 2 "register_operand")
1968 (match_operand:V_VLSF 3 "register_operand")] UNSPEC_VFMAXMIN)
1969 (match_operand:V_VLSF 4 "autovec_else_operand")]
1970 "TARGET_VECTOR && !HONOR_SNANS (<MODE>mode)"
1971 {
1972 insn_code icode = code_for_pred (<IEEE_FMAXMIN_OP>, <MODE>mode);
1973 riscv_vector::expand_cond_binop (icode, operands);
1974 DONE;
1975 })
1976
1977 (define_expand "cond_len_<ieee_fmaxmin_op><mode>"
1978 [(match_operand:VF 0 "register_operand")
1979 (match_operand:<VM> 1 "vector_mask_operand")
1980 (unspec:VF
1981 [(match_operand:VF 2 "register_operand")
1982 (match_operand:VF 3 "register_operand")] UNSPEC_VFMAXMIN)
1983 (match_operand:VF 4 "autovec_else_operand")
1984 (match_operand 5 "autovec_length_operand")
1985 (match_operand 6 "const_0_operand")]
1986 "TARGET_VECTOR && !HONOR_SNANS (<MODE>mode)"
1987 {
1988 insn_code icode = code_for_pred (<IEEE_FMAXMIN_OP>, <MODE>mode);
1989 riscv_vector::expand_cond_len_binop (icode, operands);
1990 DONE;
1991 })
1992
1993 ;; -------------------------------------------------------------------------
1994 ;; ---- [FP] Conditional copysign operations
1995 ;; -------------------------------------------------------------------------
1996 ;; Includes:
1997 ;; - vfsgnj
1998 ;; -------------------------------------------------------------------------
1999
2000 (define_expand "cond_copysign<mode>"
2001 [(match_operand:V_VLSF 0 "register_operand")
2002 (match_operand:<VM> 1 "register_operand")
2003 (match_operand:V_VLSF 2 "register_operand")
2004 (match_operand:V_VLSF 3 "register_operand")
2005 (match_operand:V_VLSF 4 "register_operand")]
2006 "TARGET_VECTOR"
2007 {
2008 insn_code icode = code_for_pred (UNSPEC_VCOPYSIGN, <MODE>mode);
2009 rtx ops[] = {operands[0], operands[1], operands[2], operands[3], operands[4],
2010 gen_int_mode (GET_MODE_NUNITS (<MODE>mode), Pmode)};
2011 riscv_vector::expand_cond_len_binop (icode, ops);
2012 DONE;
2013 })
2014
2015 ;; -------------------------------------------------------------------------
2016 ;; ---- [INT] Conditional ternary operations
2017 ;; -------------------------------------------------------------------------
2018 ;; Includes:
2019 ;; - vmacc/...
2020 ;; -------------------------------------------------------------------------
2021
2022 (define_expand "cond_fma<mode>"
2023 [(match_operand:V_VLSI 0 "register_operand")
2024 (match_operand:<VM> 1 "vector_mask_operand")
2025 (match_operand:V_VLSI 2 "register_operand")
2026 (match_operand:V_VLSI 3 "register_operand")
2027 (match_operand:V_VLSI 4 "register_operand")
2028 (match_operand:V_VLSI 5 "autovec_else_operand")]
2029 "TARGET_VECTOR"
2030 {
2031 insn_code icode = code_for_pred_mul_plus (<MODE>mode);
2032 riscv_vector::expand_cond_ternop (icode, operands);
2033 DONE;
2034 })
2035
2036 (define_expand "cond_len_fma<mode>"
2037 [(match_operand:VI 0 "register_operand")
2038 (match_operand:<VM> 1 "vector_mask_operand")
2039 (match_operand:VI 2 "register_operand")
2040 (match_operand:VI 3 "register_operand")
2041 (match_operand:VI 4 "register_operand")
2042 (match_operand:VI 5 "autovec_else_operand")
2043 (match_operand 6 "autovec_length_operand")
2044 (match_operand 7 "const_0_operand")]
2045 "TARGET_VECTOR"
2046 {
2047 insn_code icode = code_for_pred_mul_plus (<MODE>mode);
2048 riscv_vector::expand_cond_len_ternop (icode, operands);
2049 DONE;
2050 })
2051
2052 (define_expand "cond_fnma<mode>"
2053 [(match_operand:V_VLSI 0 "register_operand")
2054 (match_operand:<VM> 1 "vector_mask_operand")
2055 (match_operand:V_VLSI 2 "register_operand")
2056 (match_operand:V_VLSI 3 "register_operand")
2057 (match_operand:V_VLSI 4 "register_operand")
2058 (match_operand:V_VLSI 5 "autovec_else_operand")]
2059 "TARGET_VECTOR"
2060 {
2061 insn_code icode = code_for_pred_minus_mul (<MODE>mode);
2062 riscv_vector::expand_cond_ternop (icode, operands);
2063 DONE;
2064 })
2065
2066 (define_expand "cond_len_fnma<mode>"
2067 [(match_operand:VI 0 "register_operand")
2068 (match_operand:<VM> 1 "vector_mask_operand")
2069 (match_operand:VI 2 "register_operand")
2070 (match_operand:VI 3 "register_operand")
2071 (match_operand:VI 4 "register_operand")
2072 (match_operand:VI 5 "autovec_else_operand")
2073 (match_operand 6 "autovec_length_operand")
2074 (match_operand 7 "const_0_operand")]
2075 "TARGET_VECTOR"
2076 {
2077 insn_code icode = code_for_pred_minus_mul (<MODE>mode);
2078 riscv_vector::expand_cond_len_ternop (icode, operands);
2079 DONE;
2080 })
2081
2082 ;; -------------------------------------------------------------------------
2083 ;; ---- [FP] Conditional ternary operations
2084 ;; -------------------------------------------------------------------------
2085 ;; Includes:
2086 ;; - vfmacc/...
2087 ;; -------------------------------------------------------------------------
2088
2089 (define_expand "cond_fma<mode>"
2090 [(match_operand:V_VLSF 0 "register_operand")
2091 (match_operand:<VM> 1 "vector_mask_operand")
2092 (match_operand:V_VLSF 2 "register_operand")
2093 (match_operand:V_VLSF 3 "register_operand")
2094 (match_operand:V_VLSF 4 "register_operand")
2095 (match_operand:V_VLSF 5 "autovec_else_operand")]
2096 "TARGET_VECTOR"
2097 {
2098 insn_code icode = code_for_pred_mul (PLUS, <MODE>mode);
2099 riscv_vector::expand_cond_ternop (icode, operands);
2100 DONE;
2101 })
2102
2103 (define_expand "cond_len_fma<mode>"
2104 [(match_operand:VF 0 "register_operand")
2105 (match_operand:<VM> 1 "vector_mask_operand")
2106 (match_operand:VF 2 "register_operand")
2107 (match_operand:VF 3 "register_operand")
2108 (match_operand:VF 4 "register_operand")
2109 (match_operand:VF 5 "autovec_else_operand")
2110 (match_operand 6 "autovec_length_operand")
2111 (match_operand 7 "const_0_operand")]
2112 "TARGET_VECTOR"
2113 {
2114 insn_code icode = code_for_pred_mul (PLUS, <MODE>mode);
2115 riscv_vector::expand_cond_len_ternop (icode, operands);
2116 DONE;
2117 })
2118
2119 (define_expand "cond_fnma<mode>"
2120 [(match_operand:V_VLSF 0 "register_operand")
2121 (match_operand:<VM> 1 "vector_mask_operand")
2122 (match_operand:V_VLSF 2 "register_operand")
2123 (match_operand:V_VLSF 3 "register_operand")
2124 (match_operand:V_VLSF 4 "register_operand")
2125 (match_operand:V_VLSF 5 "autovec_else_operand")]
2126 "TARGET_VECTOR"
2127 {
2128 insn_code icode = code_for_pred_mul_neg (PLUS, <MODE>mode);
2129 riscv_vector::expand_cond_ternop (icode, operands);
2130 DONE;
2131 })
2132
2133 (define_expand "cond_len_fnma<mode>"
2134 [(match_operand:VF 0 "register_operand")
2135 (match_operand:<VM> 1 "vector_mask_operand")
2136 (match_operand:VF 2 "register_operand")
2137 (match_operand:VF 3 "register_operand")
2138 (match_operand:VF 4 "register_operand")
2139 (match_operand:VF 5 "autovec_else_operand")
2140 (match_operand 6 "autovec_length_operand")
2141 (match_operand 7 "const_0_operand")]
2142 "TARGET_VECTOR"
2143 {
2144 insn_code icode = code_for_pred_mul_neg (PLUS, <MODE>mode);
2145 riscv_vector::expand_cond_len_ternop (icode, operands);
2146 DONE;
2147 })
2148
2149 (define_expand "cond_fms<mode>"
2150 [(match_operand:V_VLSF 0 "register_operand")
2151 (match_operand:<VM> 1 "vector_mask_operand")
2152 (match_operand:V_VLSF 2 "register_operand")
2153 (match_operand:V_VLSF 3 "register_operand")
2154 (match_operand:V_VLSF 4 "register_operand")
2155 (match_operand:V_VLSF 5 "autovec_else_operand")]
2156 "TARGET_VECTOR"
2157 {
2158 insn_code icode = code_for_pred_mul (MINUS, <MODE>mode);
2159 riscv_vector::expand_cond_ternop (icode, operands);
2160 DONE;
2161 })
2162
2163 (define_expand "cond_len_fms<mode>"
2164 [(match_operand:VF 0 "register_operand")
2165 (match_operand:<VM> 1 "vector_mask_operand")
2166 (match_operand:VF 2 "register_operand")
2167 (match_operand:VF 3 "register_operand")
2168 (match_operand:VF 4 "register_operand")
2169 (match_operand:VF 5 "autovec_else_operand")
2170 (match_operand 6 "autovec_length_operand")
2171 (match_operand 7 "const_0_operand")]
2172 "TARGET_VECTOR"
2173 {
2174 insn_code icode = code_for_pred_mul (MINUS, <MODE>mode);
2175 riscv_vector::expand_cond_len_ternop (icode, operands);
2176 DONE;
2177 })
2178
2179 (define_expand "cond_fnms<mode>"
2180 [(match_operand:V_VLSF 0 "register_operand")
2181 (match_operand:<VM> 1 "vector_mask_operand")
2182 (match_operand:V_VLSF 2 "register_operand")
2183 (match_operand:V_VLSF 3 "register_operand")
2184 (match_operand:V_VLSF 4 "register_operand")
2185 (match_operand:V_VLSF 5 "autovec_else_operand")]
2186 "TARGET_VECTOR"
2187 {
2188 insn_code icode = code_for_pred_mul_neg (MINUS, <MODE>mode);
2189 riscv_vector::expand_cond_ternop (icode, operands);
2190 DONE;
2191 })
2192
2193 (define_expand "cond_len_fnms<mode>"
2194 [(match_operand:VF 0 "register_operand")
2195 (match_operand:<VM> 1 "vector_mask_operand")
2196 (match_operand:VF 2 "register_operand")
2197 (match_operand:VF 3 "register_operand")
2198 (match_operand:VF 4 "register_operand")
2199 (match_operand:VF 5 "autovec_else_operand")
2200 (match_operand 6 "autovec_length_operand")
2201 (match_operand 7 "const_0_operand")]
2202 "TARGET_VECTOR"
2203 {
2204 insn_code icode = code_for_pred_mul_neg (MINUS, <MODE>mode);
2205 riscv_vector::expand_cond_len_ternop (icode, operands);
2206 DONE;
2207 })
2208
2209 ;; =========================================================================
2210 ;; == Reductions
2211 ;; =========================================================================
2212
2213 ;; -------------------------------------------------------------------------
2214 ;; ---- [INT] Tree reductions
2215 ;; -------------------------------------------------------------------------
2216 ;; Includes:
2217 ;; - vredsum.vs
2218 ;; - vredmaxu.vs
2219 ;; - vredmax.vs
2220 ;; - vredminu.vs
2221 ;; - vredmin.vs
2222 ;; - vredand.vs
2223 ;; - vredor.vs
2224 ;; - vredxor.vs
2225 ;; -------------------------------------------------------------------------
2226
2227 (define_insn_and_split "reduc_plus_scal_<mode>"
2228 [(set (match_operand:<VEL> 0 "register_operand")
2229 (unspec:<VEL> [
2230 (match_operand:V_VLSI 1 "register_operand")
2231 ] UNSPEC_REDUC_SUM))]
2232 "TARGET_VECTOR && can_create_pseudo_p ()"
2233 "#"
2234 "&& 1"
2235 [(const_int 0)]
2236 {
2237 riscv_vector::expand_reduction (UNSPEC_REDUC_SUM,
2238 UNSPEC_REDUC_SUM_VL0_SAFE,
2239 riscv_vector::REDUCE_OP,
2240 operands, CONST0_RTX (<VEL>mode));
2241 DONE;
2242 }
2243 [(set_attr "type" "vector")])
2244
2245 (define_expand "reduc_smax_scal_<mode>"
2246 [(match_operand:<VEL> 0 "register_operand")
2247 (match_operand:V_VLSI 1 "register_operand")]
2248 "TARGET_VECTOR"
2249 {
2250 int prec = GET_MODE_PRECISION (<VEL>mode);
2251 rtx min = immed_wide_int_const (wi::min_value (prec, SIGNED), <VEL>mode);
2252 riscv_vector::expand_reduction (UNSPEC_REDUC_MAX,
2253 UNSPEC_REDUC_MAX_VL0_SAFE,
2254 riscv_vector::REDUCE_OP,
2255 operands, min);
2256 DONE;
2257 })
2258
2259 (define_expand "reduc_umax_scal_<mode>"
2260 [(match_operand:<VEL> 0 "register_operand")
2261 (match_operand:V_VLSI 1 "register_operand")]
2262 "TARGET_VECTOR"
2263 {
2264 riscv_vector::expand_reduction (UNSPEC_REDUC_MAXU,
2265 UNSPEC_REDUC_MAXU_VL0_SAFE,
2266 riscv_vector::REDUCE_OP,
2267 operands, CONST0_RTX (<VEL>mode));
2268 DONE;
2269 })
2270
2271 (define_expand "reduc_smin_scal_<mode>"
2272 [(match_operand:<VEL> 0 "register_operand")
2273 (match_operand:V_VLSI 1 "register_operand")]
2274 "TARGET_VECTOR"
2275 {
2276 int prec = GET_MODE_PRECISION (<VEL>mode);
2277 rtx max = immed_wide_int_const (wi::max_value (prec, SIGNED), <VEL>mode);
2278 riscv_vector::expand_reduction (UNSPEC_REDUC_MIN,
2279 UNSPEC_REDUC_MIN_VL0_SAFE,
2280 riscv_vector::REDUCE_OP,
2281 operands, max);
2282 DONE;
2283 })
2284
2285 (define_expand "reduc_umin_scal_<mode>"
2286 [(match_operand:<VEL> 0 "register_operand")
2287 (match_operand:V_VLSI 1 "register_operand")]
2288 "TARGET_VECTOR"
2289 {
2290 int prec = GET_MODE_PRECISION (<VEL>mode);
2291 rtx max = immed_wide_int_const (wi::max_value (prec, UNSIGNED), <VEL>mode);
2292 riscv_vector::expand_reduction (UNSPEC_REDUC_MINU,
2293 UNSPEC_REDUC_MINU_VL0_SAFE,
2294 riscv_vector::REDUCE_OP,
2295 operands, max);
2296 DONE;
2297 })
2298
2299 (define_expand "reduc_and_scal_<mode>"
2300 [(match_operand:<VEL> 0 "register_operand")
2301 (match_operand:V_VLSI 1 "register_operand")]
2302 "TARGET_VECTOR"
2303 {
2304 riscv_vector::expand_reduction (UNSPEC_REDUC_AND,
2305 UNSPEC_REDUC_AND_VL0_SAFE,
2306 riscv_vector::REDUCE_OP,
2307 operands, CONSTM1_RTX (<VEL>mode));
2308 DONE;
2309 })
2310
2311 (define_expand "reduc_ior_scal_<mode>"
2312 [(match_operand:<VEL> 0 "register_operand")
2313 (match_operand:V_VLSI 1 "register_operand")]
2314 "TARGET_VECTOR"
2315 {
2316 riscv_vector::expand_reduction (UNSPEC_REDUC_OR,
2317 UNSPEC_REDUC_OR_VL0_SAFE,
2318 riscv_vector::REDUCE_OP,
2319 operands, CONST0_RTX (<VEL>mode));
2320 DONE;
2321 })
2322
2323 (define_expand "reduc_xor_scal_<mode>"
2324 [(match_operand:<VEL> 0 "register_operand")
2325 (match_operand:V_VLSI 1 "register_operand")]
2326 "TARGET_VECTOR"
2327 {
2328 riscv_vector::expand_reduction (UNSPEC_REDUC_XOR,
2329 UNSPEC_REDUC_XOR_VL0_SAFE,
2330 riscv_vector::REDUCE_OP,
2331 operands, CONST0_RTX (<VEL>mode));
2332 DONE;
2333 })
2334
2335 ;; -------------------------------------------------------------------------
2336 ;; ---- [FP] Tree reductions
2337 ;; -------------------------------------------------------------------------
2338 ;; Includes:
2339 ;; - vfredusum.vs
2340 ;; - vfredmax.vs
2341 ;; - vfredmin.vs
2342 ;; -------------------------------------------------------------------------
2343
2344 (define_insn_and_split "reduc_plus_scal_<mode>"
2345 [(set (match_operand:<VEL> 0 "register_operand")
2346 (unspec:<VEL> [
2347 (match_operand:V_VLSF 1 "register_operand")
2348 ] UNSPEC_REDUC_SUM_UNORDERED))]
2349 "TARGET_VECTOR && can_create_pseudo_p ()"
2350 "#"
2351 "&& 1"
2352 [(const_int 0)]
2353 {
2354 riscv_vector::expand_reduction (UNSPEC_REDUC_SUM_UNORDERED,
2355 UNSPEC_REDUC_SUM_UNORDERED_VL0_SAFE,
2356 riscv_vector::REDUCE_OP_FRM_DYN,
2357 operands, CONST0_RTX (<VEL>mode));
2358 DONE;
2359 }
2360 [(set_attr "type" "vector")])
2361
2362 (define_expand "reduc_smax_scal_<mode>"
2363 [(match_operand:<VEL> 0 "register_operand")
2364 (match_operand:V_VLSF 1 "register_operand")]
2365 "TARGET_VECTOR"
2366 {
2367 REAL_VALUE_TYPE rv;
2368 real_inf (&rv, true);
2369 rtx f = const_double_from_real_value (rv, <VEL>mode);
2370 riscv_vector::expand_reduction (UNSPEC_REDUC_MAX,
2371 UNSPEC_REDUC_MAX_VL0_SAFE,
2372 riscv_vector::REDUCE_OP,
2373 operands, f);
2374 DONE;
2375 })
2376
2377 (define_expand "reduc_smin_scal_<mode>"
2378 [(match_operand:<VEL> 0 "register_operand")
2379 (match_operand:V_VLSF 1 "register_operand")]
2380 "TARGET_VECTOR"
2381 {
2382 REAL_VALUE_TYPE rv;
2383 real_inf (&rv, false);
2384 rtx f = const_double_from_real_value (rv, <VEL>mode);
2385 riscv_vector::expand_reduction (UNSPEC_REDUC_MIN,
2386 UNSPEC_REDUC_MIN_VL0_SAFE,
2387 riscv_vector::REDUCE_OP,
2388 operands, f);
2389 DONE;
2390 })
2391
2392 (define_expand "reduc_fmax_scal_<mode>"
2393 [(match_operand:<VEL> 0 "register_operand")
2394 (match_operand:V_VLSF 1 "register_operand")]
2395 "TARGET_VECTOR && !HONOR_SNANS (<MODE>mode)"
2396 {
2397 REAL_VALUE_TYPE rv;
2398 real_inf (&rv, true);
2399 rtx f = const_double_from_real_value (rv, <VEL>mode);
2400 riscv_vector::expand_reduction (UNSPEC_REDUC_MAX,
2401 UNSPEC_REDUC_MAX_VL0_SAFE,
2402 riscv_vector::REDUCE_OP,
2403 operands, f);
2404 DONE;
2405 })
2406
2407 (define_expand "reduc_fmin_scal_<mode>"
2408 [(match_operand:<VEL> 0 "register_operand")
2409 (match_operand:V_VLSF 1 "register_operand")]
2410 "TARGET_VECTOR && !HONOR_SNANS (<MODE>mode)"
2411 {
2412 REAL_VALUE_TYPE rv;
2413 real_inf (&rv, false);
2414 rtx f = const_double_from_real_value (rv, <VEL>mode);
2415 riscv_vector::expand_reduction (UNSPEC_REDUC_MIN,
2416 UNSPEC_REDUC_MIN_VL0_SAFE,
2417 riscv_vector::REDUCE_OP,
2418 operands, f);
2419 DONE;
2420 })
2421
2422 ;; -------------------------------------------------------------------------
2423 ;; ---- [FP] Left-to-right reductions
2424 ;; -------------------------------------------------------------------------
2425 ;; Includes:
2426 ;; - vfredosum.vs
2427 ;; -------------------------------------------------------------------------
2428
2429 ;; Unpredicated in-order FP reductions.
2430 (define_insn_and_split "fold_left_plus_<mode>"
2431 [(set (match_operand:<VEL> 0 "register_operand")
2432 (unspec:<VEL> [
2433 (match_operand:V_VLSF 2 "register_operand")
2434 (match_operand:<VEL> 1 "register_operand")
2435 ] UNSPEC_REDUC_SUM_ORDERED))]
2436 "TARGET_VECTOR && can_create_pseudo_p ()"
2437 "#"
2438 "&& 1"
2439 [(const_int 0)]
2440 {
2441 rtx ops[] = {operands[0], operands[2]};
2442 riscv_vector::expand_reduction (UNSPEC_REDUC_SUM_ORDERED,
2443 UNSPEC_REDUC_SUM_ORDERED_VL0_SAFE,
2444 riscv_vector::REDUCE_OP_FRM_DYN,
2445 ops, operands[1]);
2446 DONE;
2447 }
2448 [(set_attr "type" "vector")])
2449
2450 ;; Predicated in-order FP reductions.
2451 (define_insn_and_split "mask_len_fold_left_plus_<mode>"
2452 [(set (match_operand:<VEL> 0 "register_operand")
2453 (unspec:<VEL> [
2454 (match_operand:VF 2 "register_operand")
2455 (match_operand:<VEL> 1 "register_operand")
2456 (match_operand:<VM> 3 "vector_mask_operand")
2457 (match_operand 4 "autovec_length_operand")
2458 (match_operand 5 "const_0_operand")
2459 ] UNSPEC_REDUC_SUM_ORDERED))]
2460 "TARGET_VECTOR && can_create_pseudo_p ()"
2461 "#"
2462 "&& 1"
2463 [(const_int 0)]
2464 {
2465 if (rtx_equal_p (operands[4], const0_rtx))
2466 emit_move_insn (operands[0], operands[1]);
2467 else
2468 {
2469 rtx ops[] = {operands[0], operands[2], operands[3], operands[4]};
2470 riscv_vector::expand_reduction (UNSPEC_REDUC_SUM_ORDERED,
2471 UNSPEC_REDUC_SUM_ORDERED_VL0_SAFE,
2472 riscv_vector::REDUCE_OP_M_FRM_DYN,
2473 ops, operands[1]);
2474 }
2475 DONE;
2476 }
2477 [(set_attr "type" "vector")])
2478
2479 ;; -------------------------------------------------------------------------
2480 ;; ---- [INT,FP] Extract active element
2481 ;; -------------------------------------------------------------------------
2482 ;; Includes:
2483 ;; - vcompress.vm
2484 ;; - vcpop.m
2485 ;; - vslidedown.vx
2486 ;; - vmv.x.s
2487 ;; - vfmv.f.s
2488 ;; -------------------------------------------------------------------------
2489
2490 (define_expand "len_fold_extract_last_<mode>"
2491 [(match_operand:<VEL> 0 "register_operand")
2492 (match_operand:<VEL> 1 "register_operand")
2493 (match_operand:<VM> 2 "register_operand")
2494 (match_operand:V 3 "register_operand")
2495 (match_operand 4 "autovec_length_operand")
2496 (match_operand 5 "const_0_operand")]
2497 "TARGET_VECTOR"
2498 {
2499 riscv_vector::expand_fold_extract_last (operands);
2500 DONE;
2501 })
2502
2503 ;; -------------------------------------------------------------------------
2504 ;; ---- [INT] Average.
2505 ;; -------------------------------------------------------------------------
2506 ;; Implements the following "average" patterns:
2507 ;; floor:
2508 ;; op[0] = (narrow) ((wide) op[1] + (wide) op[2]) >> 1;
2509 ;; ceil:
2510 ;; op[0] = (narrow) ((wide) op[1] + (wide) op[2] + 1)) >> 1;
2511 ;; -------------------------------------------------------------------------
2512
2513 (define_expand "avg<v_double_trunc>3_floor"
2514 [(set (match_operand:<V_DOUBLE_TRUNC> 0 "register_operand")
2515 (truncate:<V_DOUBLE_TRUNC>
2516 (ashiftrt:VWEXTI
2517 (plus:VWEXTI
2518 (sign_extend:VWEXTI
2519 (match_operand:<V_DOUBLE_TRUNC> 1 "register_operand"))
2520 (sign_extend:VWEXTI
2521 (match_operand:<V_DOUBLE_TRUNC> 2 "register_operand"))))))]
2522 "TARGET_VECTOR"
2523 {
2524 /* First emit a widening addition. */
2525 rtx tmp1 = gen_reg_rtx (<MODE>mode);
2526 rtx ops1[] = {tmp1, operands[1], operands[2]};
2527 insn_code icode = code_for_pred_dual_widen (PLUS, SIGN_EXTEND, <MODE>mode);
2528 riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, ops1);
2529
2530 /* Then a narrowing shift. */
2531 rtx ops2[] = {operands[0], tmp1, const1_rtx};
2532 icode = code_for_pred_narrow_scalar (ASHIFTRT, <MODE>mode);
2533 riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, ops2);
2534 DONE;
2535 })
2536
2537 (define_expand "avg<v_double_trunc>3_ceil"
2538 [(set (match_operand:<V_DOUBLE_TRUNC> 0 "register_operand")
2539 (truncate:<V_DOUBLE_TRUNC>
2540 (ashiftrt:VWEXTI
2541 (plus:VWEXTI
2542 (plus:VWEXTI
2543 (sign_extend:VWEXTI
2544 (match_operand:<V_DOUBLE_TRUNC> 1 "register_operand"))
2545 (sign_extend:VWEXTI
2546 (match_operand:<V_DOUBLE_TRUNC> 2 "register_operand")))
2547 (const_int 1)))))]
2548 "TARGET_VECTOR"
2549 {
2550 /* First emit a widening addition. */
2551 rtx tmp1 = gen_reg_rtx (<MODE>mode);
2552 rtx ops1[] = {tmp1, operands[1], operands[2]};
2553 insn_code icode = code_for_pred_dual_widen (PLUS, SIGN_EXTEND, <MODE>mode);
2554 riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, ops1);
2555
2556 /* Then add 1. */
2557 rtx tmp2 = gen_reg_rtx (<MODE>mode);
2558 rtx ops2[] = {tmp2, tmp1, const1_rtx};
2559 icode = code_for_pred_scalar (PLUS, <MODE>mode);
2560 riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, ops2);
2561
2562 /* Finally, a narrowing shift. */
2563 rtx ops3[] = {operands[0], tmp2, const1_rtx};
2564 icode = code_for_pred_narrow_scalar (ASHIFTRT, <MODE>mode);
2565 riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, ops3);
2566 DONE;
2567 })
2568
2569 ;; csrwi vxrm, 2
2570 ;; vaaddu.vv vd, vs2, vs1
2571 (define_expand "uavg<mode>3_floor"
2572 [(match_operand:V_VLSI 0 "register_operand")
2573 (match_operand:V_VLSI 1 "register_operand")
2574 (match_operand:V_VLSI 2 "register_operand")]
2575 "TARGET_VECTOR"
2576 {
2577 insn_code icode = code_for_pred (UNSPEC_VAADDU, <MODE>mode);
2578 riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP_VXRM_RDN, operands);
2579 DONE;
2580 })
2581
2582 ;; csrwi vxrm, 0
2583 ;; vaaddu.vv vd, vs2, vs1
2584 (define_expand "uavg<mode>3_ceil"
2585 [(match_operand:V_VLSI 0 "register_operand")
2586 (match_operand:V_VLSI 1 "register_operand")
2587 (match_operand:V_VLSI 2 "register_operand")]
2588 "TARGET_VECTOR"
2589 {
2590 insn_code icode = code_for_pred (UNSPEC_VAADDU, <MODE>mode);
2591 riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP_VXRM_RNU, operands);
2592 DONE;
2593 })
2594
2595 ;; -------------------------------------------------------------------------
2596 ;; ---- [FP] Rounding.
2597 ;; -------------------------------------------------------------------------
2598 ;; Includes:
2599 ;; - ceil/ceilf
2600 ;; - floor/floorf
2601 ;; - nearbyint/nearbyintf
2602 ;; - rint/rintf
2603 ;; - round/roundf
2604 ;; - trunc/truncf
2605 ;; - roundeven/roundevenf
2606 ;; - lrint/lrintf
2607 ;; - irintf
2608 ;; - lceil/lceilf
2609 ;; - lfloor/lfloorf
2610 ;; -------------------------------------------------------------------------
2611 (define_expand "ceil<mode>2"
2612 [(match_operand:V_VLSF 0 "register_operand")
2613 (match_operand:V_VLSF 1 "register_operand")]
2614 "TARGET_VECTOR && !flag_trapping_math && !flag_rounding_math"
2615 {
2616 riscv_vector::expand_vec_ceil (operands[0], operands[1], <MODE>mode, <VCONVERT>mode);
2617 DONE;
2618 }
2619 )
2620
2621 (define_expand "floor<mode>2"
2622 [(match_operand:V_VLSF 0 "register_operand")
2623 (match_operand:V_VLSF 1 "register_operand")]
2624 "TARGET_VECTOR && !flag_trapping_math && !flag_rounding_math"
2625 {
2626 riscv_vector::expand_vec_floor (operands[0], operands[1], <MODE>mode, <VCONVERT>mode);
2627 DONE;
2628 }
2629 )
2630
2631 (define_expand "nearbyint<mode>2"
2632 [(match_operand:V_VLSF 0 "register_operand")
2633 (match_operand:V_VLSF 1 "register_operand")]
2634 "TARGET_VECTOR && !flag_trapping_math && !flag_rounding_math"
2635 {
2636 riscv_vector::expand_vec_nearbyint (operands[0], operands[1], <MODE>mode, <VCONVERT>mode);
2637 DONE;
2638 }
2639 )
2640
2641 (define_expand "rint<mode>2"
2642 [(match_operand:V_VLSF 0 "register_operand")
2643 (match_operand:V_VLSF 1 "register_operand")]
2644 "TARGET_VECTOR && !flag_trapping_math && !flag_rounding_math"
2645 {
2646 riscv_vector::expand_vec_rint (operands[0], operands[1], <MODE>mode, <VCONVERT>mode);
2647 DONE;
2648 }
2649 )
2650
2651 (define_expand "round<mode>2"
2652 [(match_operand:V_VLSF 0 "register_operand")
2653 (match_operand:V_VLSF 1 "register_operand")]
2654 "TARGET_VECTOR && !flag_trapping_math && !flag_rounding_math"
2655 {
2656 riscv_vector::expand_vec_round (operands[0], operands[1], <MODE>mode, <VCONVERT>mode);
2657 DONE;
2658 }
2659 )
2660
2661 (define_expand "btrunc<mode>2"
2662 [(match_operand:V_VLSF 0 "register_operand")
2663 (match_operand:V_VLSF 1 "register_operand")]
2664 "TARGET_VECTOR && !flag_trapping_math && !flag_rounding_math"
2665 {
2666 riscv_vector::expand_vec_trunc (operands[0], operands[1], <MODE>mode, <VCONVERT>mode);
2667 DONE;
2668 }
2669 )
2670
2671 (define_expand "roundeven<mode>2"
2672 [(match_operand:V_VLSF 0 "register_operand")
2673 (match_operand:V_VLSF 1 "register_operand")]
2674 "TARGET_VECTOR && !flag_trapping_math && !flag_rounding_math"
2675 {
2676 riscv_vector::expand_vec_roundeven (operands[0], operands[1], <MODE>mode, <VCONVERT>mode);
2677 DONE;
2678 }
2679 )
2680
2681 (define_expand "lrint<mode><v_f2si_convert>2"
2682 [(match_operand:<V_F2SI_CONVERT> 0 "register_operand")
2683 (match_operand:V_VLS_F_CONVERT_SI 1 "register_operand")]
2684 "TARGET_VECTOR && !flag_trapping_math && !flag_rounding_math"
2685 {
2686 riscv_vector::expand_vec_lrint (operands[0], operands[1], <MODE>mode,
2687 <V_F2SI_CONVERT>mode, VOIDmode);
2688 DONE;
2689 }
2690 )
2691
2692 (define_expand "lrint<mode><v_f2di_convert>2"
2693 [(match_operand:<V_F2DI_CONVERT> 0 "register_operand")
2694 (match_operand:V_VLS_F_CONVERT_DI 1 "register_operand")]
2695 "TARGET_VECTOR && !flag_trapping_math && !flag_rounding_math"
2696 {
2697 riscv_vector::expand_vec_lrint (operands[0], operands[1], <MODE>mode,
2698 <V_F2DI_CONVERT>mode,
2699 <V_F2DI_CONVERT_BRIDGE>mode);
2700 DONE;
2701 }
2702 )
2703
2704 (define_expand "lround<mode><v_f2si_convert>2"
2705 [(match_operand:<V_F2SI_CONVERT> 0 "register_operand")
2706 (match_operand:V_VLS_F_CONVERT_SI 1 "register_operand")]
2707 "TARGET_VECTOR && !flag_trapping_math && !flag_rounding_math"
2708 {
2709 riscv_vector::expand_vec_lround (operands[0], operands[1], <MODE>mode,
2710 <V_F2SI_CONVERT>mode, VOIDmode);
2711 DONE;
2712 }
2713 )
2714
2715 (define_expand "lround<mode><v_f2di_convert>2"
2716 [(match_operand:<V_F2DI_CONVERT> 0 "register_operand")
2717 (match_operand:V_VLS_F_CONVERT_DI 1 "register_operand")]
2718 "TARGET_VECTOR && !flag_trapping_math && !flag_rounding_math"
2719 {
2720 riscv_vector::expand_vec_lround (operands[0], operands[1], <MODE>mode,
2721 <V_F2DI_CONVERT>mode,
2722 <V_F2DI_CONVERT_BRIDGE>mode);
2723
2724 DONE;
2725 }
2726 )
2727
2728 (define_expand "lceil<mode><v_f2si_convert>2"
2729 [(match_operand:<V_F2SI_CONVERT> 0 "register_operand")
2730 (match_operand:V_VLS_F_CONVERT_SI 1 "register_operand")]
2731 "TARGET_VECTOR && !flag_trapping_math && !flag_rounding_math"
2732 {
2733 riscv_vector::expand_vec_lceil (operands[0], operands[1], <MODE>mode, <V_F2SI_CONVERT>mode);
2734 DONE;
2735 }
2736 )
2737
2738 (define_expand "lceil<mode><v_f2di_convert>2"
2739 [(match_operand:<V_F2DI_CONVERT> 0 "register_operand")
2740 (match_operand:V_VLS_F_CONVERT_DI 1 "register_operand")]
2741 "TARGET_VECTOR && !flag_trapping_math && !flag_rounding_math"
2742 {
2743 riscv_vector::expand_vec_lceil (operands[0], operands[1], <MODE>mode, <V_F2DI_CONVERT>mode);
2744 DONE;
2745 }
2746 )
2747
2748 (define_expand "lfloor<mode><v_f2si_convert>2"
2749 [(match_operand:<V_F2SI_CONVERT> 0 "register_operand")
2750 (match_operand:V_VLS_F_CONVERT_SI 1 "register_operand")]
2751 "TARGET_VECTOR && !flag_trapping_math && !flag_rounding_math"
2752 {
2753 riscv_vector::expand_vec_lfloor (operands[0], operands[1], <MODE>mode, <V_F2SI_CONVERT>mode);
2754 DONE;
2755 }
2756 )
2757
2758 (define_expand "lfloor<mode><v_f2di_convert>2"
2759 [(match_operand:<V_F2DI_CONVERT> 0 "register_operand")
2760 (match_operand:V_VLS_F_CONVERT_DI 1 "register_operand")]
2761 "TARGET_VECTOR && !flag_trapping_math && !flag_rounding_math"
2762 {
2763 riscv_vector::expand_vec_lfloor (operands[0], operands[1], <MODE>mode, <V_F2DI_CONVERT>mode);
2764 DONE;
2765 }
2766 )
2767
2768 ;; Implement rawmemchr[qi|si|hi].
2769 (define_expand "rawmemchr<ANYI:mode>"
2770 [(match_operand 0 "register_operand")
2771 (match_operand 1 "memory_operand")
2772 (match_operand:ANYI 2 "const_int_operand")]
2773 "TARGET_VECTOR && !TARGET_XTHEADVECTOR"
2774 {
2775 riscv_vector::expand_rawmemchr(<MODE>mode, operands[0], operands[1],
2776 operands[2]);
2777 DONE;
2778 }
2779 )
2780
2781 ;; =========================================================================
2782 ;; == [INT] Saturation ALU.
2783 ;; =========================================================================
2784 ;; Includes:
2785 ;; - add
2786 ;; - sub
2787 ;; - trunc
2788 ;; =========================================================================
2789 (define_expand "usadd<mode>3"
2790 [(match_operand:V_VLSI 0 "register_operand")
2791 (match_operand:V_VLSI 1 "register_operand")
2792 (match_operand:V_VLSI 2 "register_operand")]
2793 "TARGET_VECTOR"
2794 {
2795 riscv_vector::expand_vec_usadd (operands[0], operands[1], operands[2], <MODE>mode);
2796 DONE;
2797 }
2798 )
2799
2800 (define_expand "ssadd<mode>3"
2801 [(match_operand:V_VLSI 0 "register_operand")
2802 (match_operand:V_VLSI 1 "register_operand")
2803 (match_operand:V_VLSI 2 "register_operand")]
2804 "TARGET_VECTOR"
2805 {
2806 riscv_vector::expand_vec_ssadd (operands[0], operands[1], operands[2], <MODE>mode);
2807 DONE;
2808 }
2809 )
2810
2811 (define_expand "ussub<mode>3"
2812 [(match_operand:V_VLSI 0 "register_operand")
2813 (match_operand:V_VLSI 1 "register_operand")
2814 (match_operand:V_VLSI 2 "register_operand")]
2815 "TARGET_VECTOR"
2816 {
2817 riscv_vector::expand_vec_ussub (operands[0], operands[1], operands[2], <MODE>mode);
2818 DONE;
2819 }
2820 )
2821
2822 (define_expand "sssub<mode>3"
2823 [(match_operand:V_VLSI 0 "register_operand")
2824 (match_operand:V_VLSI 1 "register_operand")
2825 (match_operand:V_VLSI 2 "register_operand")]
2826 "TARGET_VECTOR"
2827 {
2828 riscv_vector::expand_vec_sssub (operands[0], operands[1], operands[2], <MODE>mode);
2829 DONE;
2830 }
2831 )
2832
2833 (define_expand "ustrunc<mode><v_double_trunc>2"
2834 [(match_operand:<V_DOUBLE_TRUNC> 0 "register_operand")
2835 (match_operand:VWEXTI 1 "register_operand")]
2836 "TARGET_VECTOR"
2837 {
2838 riscv_vector::expand_vec_double_ustrunc (operands[0], operands[1],
2839 <MODE>mode);
2840 DONE;
2841 }
2842 )
2843
2844 (define_expand "ustrunc<mode><v_quad_trunc>2"
2845 [(match_operand:<V_QUAD_TRUNC> 0 "register_operand")
2846 (match_operand:VQEXTI 1 "register_operand")]
2847 "TARGET_VECTOR"
2848 {
2849 riscv_vector::expand_vec_quad_ustrunc (operands[0], operands[1], <MODE>mode,
2850 <V_DOUBLE_TRUNC>mode);
2851 DONE;
2852 }
2853 )
2854
2855 (define_expand "ustrunc<mode><v_oct_trunc>2"
2856 [(match_operand:<V_OCT_TRUNC> 0 "register_operand")
2857 (match_operand:VOEXTI 1 "register_operand")]
2858 "TARGET_VECTOR"
2859 {
2860 riscv_vector::expand_vec_oct_ustrunc (operands[0], operands[1], <MODE>mode,
2861 <V_DOUBLE_TRUNC>mode,
2862 <V_QUAD_TRUNC>mode);
2863 DONE;
2864 }
2865 )
2866
2867 (define_expand "sstrunc<mode><v_double_trunc>2"
2868 [(match_operand:<V_DOUBLE_TRUNC> 0 "register_operand")
2869 (match_operand:VWEXTI 1 "register_operand")]
2870 "TARGET_VECTOR"
2871 {
2872 riscv_vector::expand_vec_double_sstrunc (operands[0], operands[1],
2873 <MODE>mode);
2874 DONE;
2875 }
2876 )
2877
2878 (define_expand "sstrunc<mode><v_quad_trunc>2"
2879 [(match_operand:<V_QUAD_TRUNC> 0 "register_operand")
2880 (match_operand:VQEXTI 1 "register_operand")]
2881 "TARGET_VECTOR"
2882 {
2883 riscv_vector::expand_vec_quad_sstrunc (operands[0], operands[1], <MODE>mode,
2884 <V_DOUBLE_TRUNC>mode);
2885 DONE;
2886 }
2887 )
2888
2889 (define_expand "sstrunc<mode><v_oct_trunc>2"
2890 [(match_operand:<V_OCT_TRUNC> 0 "register_operand")
2891 (match_operand:VOEXTI 1 "register_operand")]
2892 "TARGET_VECTOR"
2893 {
2894 riscv_vector::expand_vec_oct_sstrunc (operands[0], operands[1], <MODE>mode,
2895 <V_DOUBLE_TRUNC>mode,
2896 <V_QUAD_TRUNC>mode);
2897 DONE;
2898 }
2899 )
2900
2901 ;; =========================================================================
2902 ;; == Early break auto-vectorization patterns
2903 ;; =========================================================================
2904
2905 ;; vcond_mask_len (mask, 1s, 0s, len, bias)
2906 ;; => mask[i] = mask[i] && i < len ? 1 : 0
2907 (define_insn_and_split "vcond_mask_len_<mode>"
2908 [(set (match_operand:VB 0 "register_operand")
2909 (unspec: VB [
2910 (match_operand:VB 1 "register_operand")
2911 (match_operand:VB 2 "const_1_operand")
2912 (match_operand:VB 3 "const_0_operand")
2913 (match_operand 4 "autovec_length_operand")
2914 (match_operand 5 "const_0_operand")] UNSPEC_SELECT_MASK))]
2915 "TARGET_VECTOR
2916 && can_create_pseudo_p ()
2917 && riscv_vector::get_vector_mode (Pmode, GET_MODE_NUNITS (<MODE>mode)).exists ()"
2918 "#"
2919 "&& 1"
2920 [(const_int 0)]
2921 {
2922 machine_mode mode = riscv_vector::get_vector_mode (Pmode,
2923 GET_MODE_NUNITS (<MODE>mode)).require ();
2924 rtx reg = gen_reg_rtx (mode);
2925 riscv_vector::expand_vec_series (reg, const0_rtx, const1_rtx);
2926 rtx dup_rtx = gen_rtx_VEC_DUPLICATE (mode, operands[4]);
2927 insn_code icode = code_for_pred_cmp_scalar (mode);
2928 rtx cmp = gen_rtx_fmt_ee (LTU, <MODE>mode, reg, dup_rtx);
2929 rtx ops[] = {operands[0], operands[1], operands[1], cmp, reg, operands[4]};
2930 emit_vlmax_insn (icode, riscv_vector::COMPARE_OP_MU, ops);
2931 DONE;
2932 }
2933 [(set_attr "type" "vector")])
2934
2935 ;; cbranch
2936 (define_expand "cbranch<mode>4"
2937 [(set (pc)
2938 (if_then_else
2939 (match_operator 0 "equality_operator"
2940 [(match_operand:VB_VLS 1 "register_operand")
2941 (match_operand:VB_VLS 2 "reg_or_0_operand")])
2942 (label_ref (match_operand 3 ""))
2943 (pc)))]
2944 "TARGET_VECTOR"
2945 {
2946 rtx pred;
2947 if (operands[2] == CONST0_RTX (<MODE>mode))
2948 pred = operands[1];
2949 else
2950 pred = expand_binop (<MODE>mode, xor_optab, operands[1],
2951 operands[2], NULL_RTX, 0,
2952 OPTAB_DIRECT);
2953 rtx reg = gen_reg_rtx (Pmode);
2954 rtx cpop_ops[] = {reg, pred};
2955 emit_vlmax_insn (code_for_pred_popcount (<MODE>mode, Pmode),
2956 riscv_vector::CPOP_OP, cpop_ops);
2957 operands[1] = reg;
2958 operands[2] = const0_rtx;
2959 }
2960 )
2961
2962 ;; -------------------------------------------------------------------------
2963 ;; - vrol.vv vror.vv
2964 ;; -------------------------------------------------------------------------
2965 (define_expand "v<bitmanip_optab><mode>3"
2966 [(set (match_operand:VI 0 "register_operand")
2967 (bitmanip_rotate:VI
2968 (match_operand:VI 1 "register_operand")
2969 (match_operand:VI 2 "register_operand")))]
2970 "TARGET_ZVBB || TARGET_ZVKB"
2971 {
2972 riscv_vector::emit_vlmax_insn (code_for_pred_v (<CODE>, <MODE>mode),
2973 riscv_vector::BINARY_OP, operands);
2974 DONE;
2975 }
2976 )
2977
2978 ;; =========================================================================
2979 ;; == Strided Load/Store
2980 ;; =========================================================================
2981 (define_expand "mask_len_strided_load_<mode>"
2982 [(match_operand:V_VLS 0 "register_operand")
2983 (match_operand 1 "pmode_reg_or_0_operand")
2984 (match_operand 2 "pmode_reg_or_0_operand")
2985 (match_operand:<VM> 3 "vector_mask_operand")
2986 (match_operand 4 "maskload_else_operand")
2987 (match_operand 5 "autovec_length_operand")
2988 (match_operand 6 "const_0_operand")]
2989 "TARGET_VECTOR"
2990 {
2991 riscv_vector::expand_strided_load (<MODE>mode, operands);
2992 DONE;
2993 })
2994
2995 (define_expand "mask_len_strided_store_<mode>"
2996 [(match_operand 0 "pmode_reg_or_0_operand")
2997 (match_operand 1 "pmode_reg_or_0_operand")
2998 (match_operand:V_VLS 2 "register_operand")
2999 (match_operand:<VM> 3 "vector_mask_operand")
3000 (match_operand 4 "autovec_length_operand")
3001 (match_operand 5 "const_0_operand")]
3002 "TARGET_VECTOR"
3003 {
3004 riscv_vector::expand_strided_store (<MODE>mode, operands);
3005 DONE;
3006 })
3007
3008 ; ========
3009 ; == Absolute difference (not including sum)
3010 ; ========
3011 (define_expand "uabd<mode>3"
3012 [(match_operand:V_VLSI 0 "register_operand")
3013 (match_operand:V_VLSI 1 "register_operand")
3014 (match_operand:V_VLSI 2 "register_operand")]
3015 ;; Disabled until PR119224 is resolved
3016 "TARGET_VECTOR && 0"
3017 {
3018 rtx max = gen_reg_rtx (<MODE>mode);
3019 insn_code icode = code_for_pred (UMAX, <MODE>mode);
3020 rtx ops1[] = {max, operands[1], operands[2]};
3021 riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, ops1);
3022
3023 rtx min = gen_reg_rtx (<MODE>mode);
3024 icode = code_for_pred (UMIN, <MODE>mode);
3025 rtx ops2[] = {min, operands[1], operands[2]};
3026 riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, ops2);
3027
3028 icode = code_for_pred (MINUS, <MODE>mode);
3029 rtx ops3[] = {operands[0], max, min};
3030 riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, ops3);
3031
3032 DONE;
3033 });