1 ;; Predicate description for RISC-V target.
2 ;; Copyright (C) 2011-2024 Free Software Foundation, Inc.
3 ;; Contributed by Andrew Waterman (andrew@sifive.com).
4 ;; Based on MIPS target for GNU compiler.
6 ;; This file is part of GCC.
8 ;; GCC is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 3, or (at your option)
13 ;; GCC is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING3. If not see
20 ;; <http://www.gnu.org/licenses/>.
22 (define_predicate "const_arith_operand"
23 (and (match_code "const_int")
24 (match_test "SMALL_OPERAND (INTVAL (op))")))
26 (define_predicate "arith_operand"
27 (ior (match_operand 0 "const_arith_operand")
28 (match_operand 0 "register_operand")))
30 (define_predicate "lui_operand"
31 (and (match_code "const_int")
32 (match_test "LUI_OPERAND (INTVAL (op))")))
34 (define_predicate "sfb_alu_operand"
35 (ior (match_operand 0 "arith_operand")
36 (match_operand 0 "lui_operand")))
38 (define_predicate "movcc_operand"
39 (if_then_else (match_test "TARGET_SFB_ALU || TARGET_XTHEADCONDMOV
40 || TARGET_ZICOND_LIKE")
41 (match_operand 0 "sfb_alu_operand")
42 (match_operand 0 "arith_operand")))
44 (define_predicate "const_csr_operand"
45 (and (match_code "const_int")
46 (match_test "IN_RANGE (INTVAL (op), 0, 31)")))
48 (define_predicate "const_0_3_operand"
49 (and (match_code "const_int")
50 (match_test "IN_RANGE (INTVAL (op), 0, 3)")))
52 (define_predicate "const_0_10_operand"
53 (and (match_code "const_int")
54 (match_test "IN_RANGE (INTVAL (op), 0, 10)")))
56 (define_predicate "csr_operand"
57 (ior (match_operand 0 "const_csr_operand")
58 (match_operand 0 "register_operand")))
60 ;; V has 32-bit unsigned immediates. This happens to be the same constraint as
61 ;; the csr_operand, but it's not CSR related.
62 (define_predicate "vector_scalar_shift_operand"
63 (match_operand 0 "csr_operand"))
65 (define_predicate "sle_operand"
66 (and (match_code "const_int")
67 (match_test "SMALL_OPERAND (INTVAL (op) + 1)")))
69 (define_predicate "sleu_operand"
70 (and (match_operand 0 "sle_operand")
71 (match_test "INTVAL (op) + 1 != 0")))
73 (define_predicate "const_0_operand"
74 (and (match_code "const_int,const_wide_int,const_double,const_vector")
75 (match_test "op == CONST0_RTX (GET_MODE (op))")))
77 (define_predicate "const_1_operand"
78 (and (match_code "const_int,const_wide_int,const_vector")
79 (match_test "op == CONST1_RTX (GET_MODE (op))")))
81 (define_predicate "const_1_or_2_operand"
82 (and (match_code "const_int")
83 (match_test "INTVAL (op) == 1 || INTVAL (op) == 2")))
85 (define_predicate "const_1_or_4_operand"
86 (and (match_code "const_int")
87 (match_test "INTVAL (op) == 1 || INTVAL (op) == 4")))
89 (define_predicate "const_1_or_8_operand"
90 (and (match_code "const_int")
91 (match_test "INTVAL (op) == 1 || INTVAL (op) == 8")))
93 (define_predicate "reg_or_0_operand"
94 (ior (match_operand 0 "const_0_operand")
95 (match_operand 0 "register_operand")))
98 (define_predicate "stack_push_up_to_ra_operand"
99 (and (match_code "const_int")
100 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 1)")))
102 (define_predicate "stack_push_up_to_s0_operand"
103 (and (match_code "const_int")
104 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 2)")))
106 (define_predicate "stack_push_up_to_s1_operand"
107 (and (match_code "const_int")
108 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 3)")))
110 (define_predicate "stack_push_up_to_s2_operand"
111 (and (match_code "const_int")
112 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 4)")))
114 (define_predicate "stack_push_up_to_s3_operand"
115 (and (match_code "const_int")
116 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 5)")))
118 (define_predicate "stack_push_up_to_s4_operand"
119 (and (match_code "const_int")
120 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 6)")))
122 (define_predicate "stack_push_up_to_s5_operand"
123 (and (match_code "const_int")
124 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 7)")))
126 (define_predicate "stack_push_up_to_s6_operand"
127 (and (match_code "const_int")
128 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 8)")))
130 (define_predicate "stack_push_up_to_s7_operand"
131 (and (match_code "const_int")
132 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 9)")))
134 (define_predicate "stack_push_up_to_s8_operand"
135 (and (match_code "const_int")
136 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 10)")))
138 (define_predicate "stack_push_up_to_s9_operand"
139 (and (match_code "const_int")
140 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 11)")))
142 (define_predicate "stack_push_up_to_s11_operand"
143 (and (match_code "const_int")
144 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 13)")))
146 (define_predicate "stack_pop_up_to_ra_operand"
147 (and (match_code "const_int")
148 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 1)")))
150 (define_predicate "stack_pop_up_to_s0_operand"
151 (and (match_code "const_int")
152 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 2)")))
154 (define_predicate "stack_pop_up_to_s1_operand"
155 (and (match_code "const_int")
156 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 3)")))
158 (define_predicate "stack_pop_up_to_s2_operand"
159 (and (match_code "const_int")
160 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 4)")))
162 (define_predicate "stack_pop_up_to_s3_operand"
163 (and (match_code "const_int")
164 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 5)")))
166 (define_predicate "stack_pop_up_to_s4_operand"
167 (and (match_code "const_int")
168 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 6)")))
170 (define_predicate "stack_pop_up_to_s5_operand"
171 (and (match_code "const_int")
172 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 7)")))
174 (define_predicate "stack_pop_up_to_s6_operand"
175 (and (match_code "const_int")
176 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 8)")))
178 (define_predicate "stack_pop_up_to_s7_operand"
179 (and (match_code "const_int")
180 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 9)")))
182 (define_predicate "stack_pop_up_to_s8_operand"
183 (and (match_code "const_int")
184 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 10)")))
186 (define_predicate "stack_pop_up_to_s9_operand"
187 (and (match_code "const_int")
188 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 11)")))
190 (define_predicate "stack_pop_up_to_s11_operand"
191 (and (match_code "const_int")
192 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 13)")))
194 (define_predicate "a0a1_reg_operand"
195 (and (match_code "reg")
196 (match_test "IN_RANGE (REGNO (op), A0_REGNUM, A1_REGNUM)")))
198 (define_predicate "zcmp_mv_sreg_operand"
199 (and (match_code "reg")
200 (match_test "TARGET_RVE ? IN_RANGE (REGNO (op), S0_REGNUM, S1_REGNUM)
201 : IN_RANGE (REGNO (op), S0_REGNUM, S1_REGNUM)
202 || IN_RANGE (REGNO (op), S2_REGNUM, S7_REGNUM)")))
204 ;; Only use branch-on-bit sequences when the mask is not an ANDI immediate.
205 (define_predicate "branch_on_bit_operand"
206 (and (match_code "const_int")
207 (match_test "INTVAL (op) >= IMM_BITS - 1")))
209 ;; A legitimate CONST_INT operand that takes more than one instruction
211 (define_predicate "splittable_const_int_operand"
212 (match_code "const_int")
214 /* Don't handle multi-word moves this way; we don't want to introduce
215 the individual word-mode moves until after reload. */
216 if (GET_MODE_SIZE (mode).to_constant () > UNITS_PER_WORD)
219 /* Check whether the constant can be loaded in a single
220 instruction with zbs extensions. */
221 if (TARGET_ZBS && SINGLE_BIT_MASK_OPERAND (INTVAL (op)))
224 /* Otherwise check whether the constant can be loaded in a single
226 return !LUI_OPERAND (INTVAL (op)) && !SMALL_OPERAND (INTVAL (op));
229 (define_predicate "p2m1_shift_operand"
230 (match_code "const_int")
232 int val = exact_log2 (INTVAL (op) + 1);
238 (define_predicate "high_mask_shift_operand"
239 (match_code "const_int")
241 int val1 = clz_hwi (~ INTVAL (op));
242 int val0 = ctz_hwi (INTVAL (op));
243 if ((val0 + val1 == BITS_PER_WORD)
244 && val0 > 31 && val0 < 64)
249 (define_predicate "move_operand"
250 (match_operand 0 "general_operand")
252 enum riscv_symbol_type symbol_type;
254 /* The thinking here is as follows:
256 (1) The move expanders should split complex load sequences into
257 individual instructions. Those individual instructions can
258 then be optimized by all rtl passes.
260 (2) The target of pre-reload load sequences should not be used
261 to store temporary results. If the target register is only
262 assigned one value, reload can rematerialize that value
263 on demand, rather than spill it to the stack.
265 (3) If we allowed pre-reload passes like combine and cse to recreate
266 complex load sequences, we would want to be able to split the
267 sequences before reload as well, so that the pre-reload scheduler
268 can see the individual instructions. This falls foul of (2);
269 the splitter would be forced to reuse the target register for
270 intermediate results.
272 (4) We want to define complex load splitters for combine. These
273 splitters can request a temporary scratch register, which avoids
274 the problem in (2). They allow things like:
276 (set (reg T1) (high SYM))
277 (set (reg T2) (low (reg T1) SYM))
278 (set (reg X) (plus (reg T2) (const_int OFFSET)))
282 (set (reg T3) (high SYM+OFFSET))
283 (set (reg X) (lo_sum (reg T3) SYM+OFFSET))
285 if T2 is only used this once. */
286 switch (GET_CODE (op))
289 return !splittable_const_int_operand (op, mode);
292 return known_eq (rtx_to_poly_int64 (op), BYTES_PER_RISCV_VECTOR);
297 return riscv_symbolic_constant_p (op, &symbol_type)
298 && !riscv_split_symbol_type (symbol_type)
299 && symbol_type != SYMBOL_FORCE_TO_MEM;
303 return riscv_symbolic_constant_p (op, &symbol_type)
304 && riscv_split_symbol_type (symbol_type)
305 && symbol_type != SYMBOL_PCREL;
312 (define_predicate "symbolic_operand"
313 (match_code "const,symbol_ref,label_ref")
315 enum riscv_symbol_type type;
316 return riscv_symbolic_constant_p (op, &type);
319 (define_predicate "absolute_symbolic_operand"
320 (match_code "const,symbol_ref,label_ref")
322 enum riscv_symbol_type type;
323 return (riscv_symbolic_constant_p (op, &type)
324 && (type == SYMBOL_ABSOLUTE || type == SYMBOL_PCREL));
327 (define_predicate "plt_symbolic_operand"
328 (match_code "const,symbol_ref,label_ref")
330 enum riscv_symbol_type type;
331 return (riscv_symbolic_constant_p (op, &type)
332 && type == SYMBOL_GOT_DISP && !SYMBOL_REF_WEAK (op) && flag_plt);
335 (define_predicate "call_insn_operand"
336 (match_operand 0 "general_operand")
338 if (riscv_cmodel == CM_LARGE)
339 return register_operand (op, mode);
341 return (absolute_symbolic_operand (op, mode)
342 || plt_symbolic_operand (op, mode)
343 || register_operand (op, mode));
346 (define_predicate "modular_operator"
347 (match_code "plus,minus,mult,ashift"))
349 (define_predicate "ne_operator"
352 (define_predicate "equality_operator"
353 (match_code "eq,ne"))
355 (define_predicate "signed_order_operator"
356 (match_code "eq,ne,lt,le,ge,gt"))
358 (define_predicate "subreg_lowpart_operator"
359 (ior (match_code "truncate")
360 (and (match_code "subreg")
361 (match_test "subreg_lowpart_p (op)"))))
363 (define_predicate "fp_native_comparison"
364 (match_code "eq,lt,le,gt,ge"))
366 (define_predicate "fp_scc_comparison"
367 (match_code "unordered,ordered,unlt,unge,unle,ungt,ltgt,ne,eq,lt,le,gt,ge"))
369 (define_predicate "fp_branch_comparison"
370 (match_code "unordered,ordered,unlt,unge,unle,ungt,uneq,ltgt,ne,eq,lt,le,gt,ge"))
372 (define_special_predicate "gpr_save_operation"
373 (match_code "parallel")
375 return riscv_gpr_save_operation_p (op);
378 ;; Predicates for the ZBS extension.
379 (define_predicate "single_bit_mask_operand"
380 (and (match_code "const_int")
381 (match_test "SINGLE_BIT_MASK_OPERAND (UINTVAL (op))")))
383 ;; Register, small constant or single bit constant for use in
385 (define_predicate "arith_or_zbs_operand"
386 (ior (match_operand 0 "const_arith_operand")
387 (match_operand 0 "register_operand")
388 (and (match_test "TARGET_ZBS")
389 (match_operand 0 "single_bit_mask_operand"))))
391 (define_predicate "not_single_bit_mask_operand"
392 (and (match_code "const_int")
393 (match_test "SINGLE_BIT_MASK_OPERAND (~UINTVAL (op))")))
395 (define_predicate "arith_or_mode_mask_or_zbs_operand"
396 (ior (match_operand 0 "arith_operand")
397 (and (match_test "TARGET_ZBS")
398 (match_operand 0 "not_single_bit_mask_operand"))
399 (and (match_code "const_int")
400 (match_test "UINTVAL (op) == GET_MODE_MASK (HImode)
401 || UINTVAL (op) == GET_MODE_MASK (SImode)"))))
403 (define_predicate "const_si_mask_operand"
404 (and (match_code "const_int")
405 (match_test "(INTVAL (op) & (GET_MODE_BITSIZE (SImode) - 1))
406 == GET_MODE_BITSIZE (SImode) - 1")))
408 (define_predicate "const_di_mask_operand"
409 (and (match_code "const_int")
410 (match_test "(INTVAL (op) & (GET_MODE_BITSIZE (DImode) - 1))
411 == GET_MODE_BITSIZE (DImode) - 1")))
413 (define_predicate "imm5_operand"
414 (and (match_code "const_int")
415 (match_test "INTVAL (op) < 5")))
417 ;; A const_int for sh1add/sh2add/sh3add
418 (define_predicate "imm123_operand"
419 (and (match_code "const_int")
420 (match_test "IN_RANGE (INTVAL (op), 1, 3)")))
422 ;; A CONST_INT operand that consists of a single run of consecutive set bits.
423 (define_predicate "consecutive_bits_operand"
424 (match_code "const_int")
426 unsigned HOST_WIDE_INT val = UINTVAL (op);
427 if (exact_log2 ((val >> ctz_hwi (val)) + 1) < 0)
433 (define_predicate "const_two_s12"
434 (match_code "const_int")
436 return SUM_OF_TWO_S12 (INTVAL (op));
439 ;; CORE-V Predicates:
440 (define_predicate "immediate_register_operand"
441 (ior (match_operand 0 "register_operand")
442 (match_code "const_int")))
444 (define_predicate "const_int6s_operand"
445 (and (match_code "const_int")
446 (match_test "IN_RANGE (INTVAL (op), -32, 31)")))
448 (define_predicate "int6s_operand"
449 (ior (match_operand 0 "const_int6s_operand")
450 (match_operand 0 "register_operand")))
452 (define_predicate "const_int2_operand"
453 (and (match_code "const_int")
454 (match_test "IN_RANGE (INTVAL (op), 0, 3)")))
456 (define_predicate "const_int6_operand"
457 (and (match_code "const_int")
458 (match_test "IN_RANGE (INTVAL (op), 0, 63)")))
460 (define_predicate "int6_operand"
461 (ior (match_operand 0 "const_int6_operand")
462 (match_operand 0 "register_operand")))
464 (define_predicate "const_int5s_operand"
465 (and (match_code "const_int")
466 (match_test "IN_RANGE (INTVAL (op), -16, 15)")))
468 ;; Predicates for the V extension.
469 (define_special_predicate "vector_length_operand"
470 (ior (match_operand 0 "pmode_register_operand")
471 (and (ior (match_test "TARGET_XTHEADVECTOR && rtx_equal_p (op, const0_rtx)")
472 (match_test "!TARGET_XTHEADVECTOR"))
473 (match_operand 0 "const_csr_operand"))))
475 (define_special_predicate "autovec_length_operand"
476 (ior (match_operand 0 "pmode_register_operand")
477 (match_code "const_int,const_poly_int")))
479 (define_predicate "reg_or_mem_operand"
480 (ior (match_operand 0 "register_operand")
481 (match_operand 0 "memory_operand")))
483 (define_predicate "reg_or_int_operand"
484 (ior (match_operand 0 "register_operand")
485 (match_operand 0 "const_int_operand")))
487 (define_predicate "vector_const_0_operand"
488 (and (match_code "const_vector")
489 (match_test "satisfies_constraint_Wc0 (op)")))
491 (define_predicate "vector_const_int_or_double_0_operand"
492 (and (match_code "const_vector")
493 (match_test "satisfies_constraint_vi (op)
494 || satisfies_constraint_Wc0 (op)")))
496 (define_predicate "vector_move_operand"
497 (ior (match_operand 0 "nonimmediate_operand")
498 (and (match_code "const_vector")
499 (match_test "reload_completed
500 || satisfies_constraint_vi (op)
501 || satisfies_constraint_Wc0 (op)"))))
503 (define_predicate "vector_all_trues_mask_operand"
504 (and (match_code "const_vector")
505 (match_test "op == CONSTM1_RTX (GET_MODE (op))")))
507 (define_predicate "vector_least_significant_set_mask_operand"
508 (and (match_code "const_vector")
509 (match_test "rtx_equal_p (op, riscv_vector::gen_scalar_move_mask (GET_MODE (op)))")))
511 (define_predicate "vector_mask_operand"
512 (ior (match_operand 0 "register_operand")
513 (match_operand 0 "vector_all_trues_mask_operand")))
515 (define_predicate "vector_broadcast_mask_operand"
516 (ior (match_operand 0 "vector_least_significant_set_mask_operand")
517 (ior (match_operand 0 "register_operand")
518 (match_operand 0 "vector_all_trues_mask_operand"))))
520 (define_predicate "vector_undef_operand"
521 (match_test "rtx_equal_p (op, RVV_VUNDEF (GET_MODE (op)))"))
523 (define_predicate "vector_merge_operand"
524 (ior (match_operand 0 "register_operand")
525 (match_operand 0 "vector_undef_operand")))
527 (define_predicate "autovec_else_operand"
528 (ior (match_operand 0 "register_operand")
529 (match_operand 0 "scratch_operand")))
531 (define_predicate "vector_arith_operand"
532 (ior (match_operand 0 "register_operand")
533 (and (match_code "const_vector")
534 (match_test "riscv_vector::const_vec_all_same_in_range_p (op, -16, 15)"))))
536 (define_predicate "vector_neg_arith_operand"
537 (ior (match_operand 0 "register_operand")
538 (and (match_code "const_vector")
539 (match_test "riscv_vector::const_vec_all_same_in_range_p (op, -15, 16)"))))
541 (define_predicate "vector_shift_operand"
542 (ior (match_operand 0 "register_operand")
543 (and (match_code "const_vector")
544 (match_test "riscv_vector::const_vec_all_same_in_range_p (op, 0, 31)"))))
546 (define_predicate "vector_perm_operand"
547 (ior (match_operand 0 "register_operand")
548 (match_code "const_vector")))
550 (define_predicate "vector_gs_extension_operand"
551 (ior (match_operand 0 "const_1_operand")
552 (and (match_operand 0 "const_0_operand")
553 (match_test "Pmode == SImode"))))
555 (define_predicate "vector_gs_scale_operand_16_rv32"
556 (and (match_code "const_int")
557 (match_test "INTVAL (op) == 1
558 || (INTVAL (op) == 2 && Pmode == SImode)")))
560 (define_predicate "vector_gs_scale_operand_32_rv32"
561 (and (match_code "const_int")
562 (match_test "INTVAL (op) == 1
563 || (INTVAL (op) == 4 && Pmode == SImode)")))
565 (define_predicate "ltge_operator"
566 (match_code "lt,ltu,ge,geu"))
568 (define_predicate "comparison_except_ltge_operator"
569 (match_code "eq,ne,le,leu,gt,gtu"))
571 (define_predicate "comparison_except_ge_operator"
572 (match_code "eq,ne,le,leu,gt,gtu,lt,ltu"))
574 (define_predicate "ge_operator"
575 (match_code "ge,geu"))
577 ;; pmode_reg_or_uimm5_operand can be used by vsll.vx/vsrl.vx/vsra.vx instructions.
578 ;; Since it has the same predicate with vector_length_operand which allows register
579 ;; or immediate (0 ~ 31), we define this predicate same as vector_length_operand here.
580 ;; We don't use vector_length_operand directly to predicate vsll.vx/vsrl.vx/vsra.vx
581 ;; since it may be confusing.
582 (define_special_predicate "pmode_reg_or_uimm5_operand"
583 (match_operand 0 "vector_length_operand"))
585 (define_special_predicate "pmode_reg_or_0_operand"
586 (ior (match_operand 0 "const_0_operand")
587 (match_operand 0 "pmode_register_operand")))
589 ;; [1, 2, 4, 8] means strided load/store with stride == element width
590 (define_special_predicate "vector_eew8_stride_operand"
591 (ior (match_operand 0 "pmode_register_operand")
592 (and (match_code "const_int")
593 (match_test "INTVAL (op) == 1 || INTVAL (op) == 0"))))
594 (define_special_predicate "vector_eew16_stride_operand"
595 (ior (match_operand 0 "pmode_register_operand")
596 (and (match_code "const_int")
597 (match_test "INTVAL (op) == 2 || INTVAL (op) == 0"))))
598 (define_special_predicate "vector_eew32_stride_operand"
599 (ior (match_operand 0 "pmode_register_operand")
600 (and (match_code "const_int")
601 (match_test "INTVAL (op) == 4 || INTVAL (op) == 0"))))
602 (define_special_predicate "vector_eew64_stride_operand"
603 (ior (match_operand 0 "pmode_register_operand")
604 (and (match_code "const_int")
605 (match_test "INTVAL (op) == 8 || INTVAL (op) == 0"))))
607 ;; A special predicate that doesn't match a particular mode.
608 (define_special_predicate "vector_any_register_operand"
611 ;; The scalar operand can be directly broadcast by RVV instructions.
612 (define_predicate "direct_broadcast_operand"
613 (match_test "riscv_vector::can_be_broadcasted_p (op)"))
615 ;; A CONST_INT operand that has exactly two bits cleared.
616 (define_predicate "const_nottwobits_operand"
617 (and (match_code "const_int")
618 (match_test "popcount_hwi (~UINTVAL (op)) == 2")))
620 (define_predicate "const_nottwobits_not_arith_operand"
621 (and (match_code "const_int")
622 (and (not (match_operand 0 "arith_operand"))
623 (match_operand 0 "const_nottwobits_operand"))))
625 ;; A CONST_INT operand that consists of a single run of 32 consecutive
627 (define_predicate "consecutive_bits32_operand"
628 (and (match_operand 0 "consecutive_bits_operand")
629 (match_test "popcount_hwi (UINTVAL (op)) == 32")))
631 ;; A CONST_INT operand that, if shifted down to start with its least
632 ;; significant non-zero bit, is a SMALL_OPERAND (suitable as an
633 ;; immediate to logical and arithmetic instructions).
634 (define_predicate "shifted_const_arith_operand"
635 (and (match_code "const_int")
636 (match_test "ctz_hwi (INTVAL (op)) > 0")
637 (match_test "SMALL_OPERAND (INTVAL (op) >> ctz_hwi (INTVAL (op)))")))
639 ;; A CONST_INT operand that has exactly two bits set.
640 (define_predicate "const_twobits_operand"
641 (and (match_code "const_int")
642 (match_test "popcount_hwi (UINTVAL (op)) == 2")))
644 (define_predicate "const_twobits_not_arith_operand"
645 (and (match_code "const_int")
646 (and (not (match_operand 0 "arith_operand"))
647 (match_operand 0 "const_twobits_operand"))))
649 ;; A CONST_INT operand that fits into the unsigned half of a
650 ;; signed-immediate after the top bit has been cleared
651 (define_predicate "uimm_extra_bit_operand"
652 (and (match_code "const_int")
653 (match_test "UIMM_EXTRA_BIT_OPERAND (UINTVAL (op))")))
655 (define_predicate "uimm_extra_bit_or_twobits"
656 (and (match_code "const_int")
657 (ior (match_operand 0 "uimm_extra_bit_operand")
658 (match_operand 0 "const_twobits_not_arith_operand"))))
660 ;; A CONST_INT operand that fits into the negative half of a
661 ;; signed-immediate after a single cleared top bit has been
662 ;; set: i.e., a bitwise-negated uimm_extra_bit_operand
663 (define_predicate "not_uimm_extra_bit_operand"
664 (and (match_code "const_int")
665 (match_test "UIMM_EXTRA_BIT_OPERAND (~UINTVAL (op))")))
667 (define_predicate "not_uimm_extra_bit_or_nottwobits"
668 (and (match_code "const_int")
669 (ior (match_operand 0 "not_uimm_extra_bit_operand")
670 (match_operand 0 "const_nottwobits_not_arith_operand"))))
672 (define_predicate "pcrel_symbol_operand"
673 (match_code "symbol_ref")
675 enum riscv_symbol_type type;
676 return (riscv_symbolic_constant_p (op, &type)
677 && type == SYMBOL_PCREL);