Debian Codegraph @

gcc/config/riscv/predicates.md

raw
1 ;; Predicate description for RISC-V target.
2 ;; Copyright (C) 2011-2025 Free Software Foundation, Inc.
3 ;; Contributed by Andrew Waterman ([email protected]).
4 ;; Based on MIPS target for GNU compiler.
5 ;;
6 ;; This file is part of GCC.
7 ;;
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)
11 ;; any later version.
12 ;;
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.
17 ;;
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/>.
21
22 (define_predicate "const_arith_operand"
23 (and (match_code "const_int")
24 (match_test "SMALL_OPERAND (INTVAL (op))")))
25
26 (define_predicate "arith_operand"
27 (ior (match_operand 0 "const_arith_operand")
28 (match_operand 0 "register_operand")))
29
30 ;; REG or REG+D where D fits in a simm12 and has the low 5 bits
31 ;; off. The REG+D form can be reloaded into a temporary if needed
32 ;; after FP elimination if that exposes an invalid offset.
33 (define_predicate "prefetch_operand"
34 (ior (match_operand 0 "register_operand")
35 (and (match_test "const_arith_operand (op, VOIDmode)")
36 (match_test "(INTVAL (op) & 0x1f) == 0"))
37 (and (match_code "plus")
38 (match_test "register_operand (XEXP (op, 0), word_mode)")
39 (match_test "const_arith_operand (XEXP (op, 1), VOIDmode)")
40 (match_test "(INTVAL (XEXP (op, 1)) & 0x1f) == 0"))))
41
42 (define_predicate "lui_operand"
43 (and (match_code "const_int")
44 (match_test "LUI_OPERAND (INTVAL (op))")))
45
46 (define_predicate "sfb_alu_operand"
47 (ior (match_operand 0 "arith_operand")
48 (match_operand 0 "lui_operand")))
49
50 (define_predicate "movcc_operand"
51 (if_then_else (match_test "TARGET_SFB_ALU || TARGET_XTHEADCONDMOV
52 || TARGET_ZICOND_LIKE")
53 (match_operand 0 "sfb_alu_operand")
54 (match_operand 0 "arith_operand")))
55
56 (define_predicate "const_csr_operand"
57 (and (match_code "const_int")
58 (match_test "IN_RANGE (INTVAL (op), 0, 31)")))
59
60 (define_predicate "const_0_3_operand"
61 (and (match_code "const_int")
62 (match_test "IN_RANGE (INTVAL (op), 0, 3)")))
63
64 (define_predicate "const_0_10_operand"
65 (and (match_code "const_int")
66 (match_test "IN_RANGE (INTVAL (op), 0, 10)")))
67
68 (define_predicate "csr_operand"
69 (ior (match_operand 0 "const_csr_operand")
70 (match_operand 0 "register_operand")))
71
72 ;; V has 32-bit unsigned immediates. This happens to be the same constraint as
73 ;; the csr_operand, but it's not CSR related.
74 (define_predicate "vector_scalar_shift_operand"
75 (match_operand 0 "csr_operand"))
76
77 (define_predicate "sle_operand"
78 (and (match_code "const_int")
79 (match_test "SMALL_OPERAND (INTVAL (op) + 1)")))
80
81 (define_predicate "sleu_operand"
82 (and (match_operand 0 "sle_operand")
83 (match_test "INTVAL (op) + 1 != 0")))
84
85 (define_predicate "const_0_operand"
86 (and (match_code "const_int,const_wide_int,const_double,const_vector")
87 (match_test "op == CONST0_RTX (GET_MODE (op))")))
88
89 (define_predicate "const_1_operand"
90 (and (match_code "const_int,const_wide_int,const_vector")
91 (match_test "op == CONST1_RTX (GET_MODE (op))")))
92
93 (define_predicate "const_1_or_2_operand"
94 (and (match_code "const_int")
95 (match_test "INTVAL (op) == 1 || INTVAL (op) == 2")))
96
97 (define_predicate "const_1_or_4_operand"
98 (and (match_code "const_int")
99 (match_test "INTVAL (op) == 1 || INTVAL (op) == 4")))
100
101 (define_predicate "const_1_or_8_operand"
102 (and (match_code "const_int")
103 (match_test "INTVAL (op) == 1 || INTVAL (op) == 8")))
104
105 (define_predicate "reg_or_0_operand"
106 (ior (match_operand 0 "const_0_operand")
107 (match_operand 0 "register_operand")))
108
109 ;; ZCMP predicates
110 (define_predicate "stack_push_up_to_ra_operand"
111 (and (match_code "const_int")
112 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 1)")))
113
114 (define_predicate "stack_push_up_to_s0_operand"
115 (and (match_code "const_int")
116 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 2)")))
117
118 (define_predicate "stack_push_up_to_s1_operand"
119 (and (match_code "const_int")
120 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 3)")))
121
122 (define_predicate "stack_push_up_to_s2_operand"
123 (and (match_code "const_int")
124 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 4)")))
125
126 (define_predicate "stack_push_up_to_s3_operand"
127 (and (match_code "const_int")
128 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 5)")))
129
130 (define_predicate "stack_push_up_to_s4_operand"
131 (and (match_code "const_int")
132 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 6)")))
133
134 (define_predicate "stack_push_up_to_s5_operand"
135 (and (match_code "const_int")
136 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 7)")))
137
138 (define_predicate "stack_push_up_to_s6_operand"
139 (and (match_code "const_int")
140 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 8)")))
141
142 (define_predicate "stack_push_up_to_s7_operand"
143 (and (match_code "const_int")
144 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 9)")))
145
146 (define_predicate "stack_push_up_to_s8_operand"
147 (and (match_code "const_int")
148 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 10)")))
149
150 (define_predicate "stack_push_up_to_s9_operand"
151 (and (match_code "const_int")
152 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 11)")))
153
154 (define_predicate "stack_push_up_to_s11_operand"
155 (and (match_code "const_int")
156 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op) * -1, 13)")))
157
158 (define_predicate "stack_pop_up_to_ra_operand"
159 (and (match_code "const_int")
160 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 1)")))
161
162 (define_predicate "stack_pop_up_to_s0_operand"
163 (and (match_code "const_int")
164 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 2)")))
165
166 (define_predicate "stack_pop_up_to_s1_operand"
167 (and (match_code "const_int")
168 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 3)")))
169
170 (define_predicate "stack_pop_up_to_s2_operand"
171 (and (match_code "const_int")
172 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 4)")))
173
174 (define_predicate "stack_pop_up_to_s3_operand"
175 (and (match_code "const_int")
176 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 5)")))
177
178 (define_predicate "stack_pop_up_to_s4_operand"
179 (and (match_code "const_int")
180 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 6)")))
181
182 (define_predicate "stack_pop_up_to_s5_operand"
183 (and (match_code "const_int")
184 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 7)")))
185
186 (define_predicate "stack_pop_up_to_s6_operand"
187 (and (match_code "const_int")
188 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 8)")))
189
190 (define_predicate "stack_pop_up_to_s7_operand"
191 (and (match_code "const_int")
192 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 9)")))
193
194 (define_predicate "stack_pop_up_to_s8_operand"
195 (and (match_code "const_int")
196 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 10)")))
197
198 (define_predicate "stack_pop_up_to_s9_operand"
199 (and (match_code "const_int")
200 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 11)")))
201
202 (define_predicate "stack_pop_up_to_s11_operand"
203 (and (match_code "const_int")
204 (match_test "riscv_zcmp_valid_stack_adj_bytes_p (INTVAL (op), 13)")))
205
206 (define_predicate "a0a1_reg_operand"
207 (and (match_code "reg")
208 (match_test "IN_RANGE (REGNO (op), A0_REGNUM, A1_REGNUM)")))
209
210 (define_predicate "zcmp_mv_sreg_operand"
211 (and (match_code "reg")
212 (match_test "TARGET_RVE ? IN_RANGE (REGNO (op), S0_REGNUM, S1_REGNUM)
213 : IN_RANGE (REGNO (op), S0_REGNUM, S1_REGNUM)
214 || IN_RANGE (REGNO (op), S2_REGNUM, S7_REGNUM)")))
215
216 ;; Only use branch-on-bit sequences when the mask is not an ANDI immediate.
217 (define_predicate "branch_on_bit_operand"
218 (and (match_code "const_int")
219 (match_test "INTVAL (op) >= IMM_BITS - 1")))
220
221 ;; A legitimate CONST_INT operand that takes more than one instruction
222 ;; to load.
223 (define_predicate "splittable_const_int_operand"
224 (match_code "const_int")
225 {
226 /* Don't handle multi-word moves this way; we don't want to introduce
227 the individual word-mode moves until after reload. */
228 if (GET_MODE_SIZE (mode).to_constant () > UNITS_PER_WORD)
229 return false;
230
231 /* Check whether the constant can be loaded in a single
232 instruction with zbs extensions. */
233 if (TARGET_ZBS && SINGLE_BIT_MASK_OPERAND (INTVAL (op)))
234 return false;
235
236 /* Otherwise check whether the constant can be loaded in a single
237 instruction. */
238 return !LUI_OPERAND (INTVAL (op)) && !SMALL_OPERAND (INTVAL (op));
239 })
240
241 (define_predicate "p2m1_shift_operand"
242 (match_code "const_int")
243 {
244 int val = exact_log2 (INTVAL (op) + 1);
245 if (val < 12)
246 return false;
247 return true;
248 })
249
250 (define_predicate "high_mask_shift_operand"
251 (match_code "const_int")
252 {
253 int val1 = clz_hwi (~ INTVAL (op));
254 int val0 = ctz_hwi (INTVAL (op));
255 if ((val0 + val1 == BITS_PER_WORD)
256 && val0 > 31 && val0 < 64)
257 return true;
258 return false;
259 })
260
261 (define_predicate "move_operand"
262 (match_operand 0 "general_operand")
263 {
264 enum riscv_symbol_type symbol_type;
265
266 /* The thinking here is as follows:
267
268 (1) The move expanders should split complex load sequences into
269 individual instructions. Those individual instructions can
270 then be optimized by all rtl passes.
271
272 (2) The target of pre-reload load sequences should not be used
273 to store temporary results. If the target register is only
274 assigned one value, reload can rematerialize that value
275 on demand, rather than spill it to the stack.
276
277 (3) If we allowed pre-reload passes like combine and cse to recreate
278 complex load sequences, we would want to be able to split the
279 sequences before reload as well, so that the pre-reload scheduler
280 can see the individual instructions. This falls foul of (2);
281 the splitter would be forced to reuse the target register for
282 intermediate results.
283
284 (4) We want to define complex load splitters for combine. These
285 splitters can request a temporary scratch register, which avoids
286 the problem in (2). They allow things like:
287
288 (set (reg T1) (high SYM))
289 (set (reg T2) (low (reg T1) SYM))
290 (set (reg X) (plus (reg T2) (const_int OFFSET)))
291
292 to be combined into:
293
294 (set (reg T3) (high SYM+OFFSET))
295 (set (reg X) (lo_sum (reg T3) SYM+OFFSET))
296
297 if T2 is only used this once. */
298 switch (GET_CODE (op))
299 {
300 case CONST_INT:
301 return !splittable_const_int_operand (op, mode);
302
303 case CONST_POLY_INT:
304 return known_eq (rtx_to_poly_int64 (op), BYTES_PER_RISCV_VECTOR);
305
306 case CONST:
307 case SYMBOL_REF:
308 case LABEL_REF:
309 return riscv_symbolic_constant_p (op, &symbol_type)
310 && !riscv_split_symbol_type (symbol_type)
311 && symbol_type != SYMBOL_FORCE_TO_MEM;
312
313 case HIGH:
314 op = XEXP (op, 0);
315 return riscv_symbolic_constant_p (op, &symbol_type)
316 && riscv_split_symbol_type (symbol_type)
317 && symbol_type != SYMBOL_PCREL;
318
319 default:
320 return true;
321 }
322 })
323
324 (define_predicate "symbolic_operand"
325 (match_code "const,symbol_ref,label_ref")
326 {
327 enum riscv_symbol_type type;
328 return riscv_symbolic_constant_p (op, &type);
329 })
330
331 (define_predicate "absolute_symbolic_operand"
332 (match_code "const,symbol_ref,label_ref")
333 {
334 enum riscv_symbol_type type;
335 return (riscv_symbolic_constant_p (op, &type)
336 && (type == SYMBOL_ABSOLUTE || type == SYMBOL_PCREL));
337 })
338
339 (define_predicate "plt_symbolic_operand"
340 (match_code "const,symbol_ref,label_ref")
341 {
342 enum riscv_symbol_type type;
343 return (riscv_symbolic_constant_p (op, &type)
344 && type == SYMBOL_GOT_DISP && !SYMBOL_REF_WEAK (op) && flag_plt);
345 })
346
347 (define_predicate "call_insn_operand"
348 (match_operand 0 "general_operand")
349 {
350 if (riscv_cmodel == CM_LARGE)
351 return register_operand (op, mode);
352 else
353 return (absolute_symbolic_operand (op, mode)
354 || plt_symbolic_operand (op, mode)
355 || register_operand (op, mode));
356 })
357
358 (define_predicate "modular_operator"
359 (match_code "plus,minus,mult,ashift"))
360
361 (define_predicate "ne_operator"
362 (match_code "ne"))
363
364 (define_predicate "equality_operator"
365 (match_code "eq,ne"))
366
367 (define_predicate "signed_order_operator"
368 (match_code "eq,ne,lt,le,ge,gt"))
369
370 (define_predicate "subreg_lowpart_operator"
371 (ior (match_code "truncate")
372 (and (match_code "subreg")
373 (match_test "subreg_lowpart_p (op)"))))
374
375 (define_predicate "fp_native_comparison"
376 (match_code "eq,lt,le,gt,ge"))
377
378 (define_predicate "fp_scc_comparison"
379 (match_code "unordered,ordered,unlt,unge,unle,ungt,ltgt,ne,eq,lt,le,gt,ge"))
380
381 (define_predicate "fp_branch_comparison"
382 (match_code "unordered,ordered,unlt,unge,unle,ungt,uneq,ltgt,ne,eq,lt,le,gt,ge"))
383
384 (define_special_predicate "gpr_save_operation"
385 (match_code "parallel")
386 {
387 return riscv_gpr_save_operation_p (op);
388 })
389
390 ;; Predicates for the ZBS extension.
391 (define_predicate "single_bit_mask_operand"
392 (and (match_code "const_int")
393 (match_test "SINGLE_BIT_MASK_OPERAND (UINTVAL (op))")))
394
395 ;; Register, small constant or single bit constant for use in
396 ;; bseti/binvi.
397 (define_predicate "arith_or_zbs_operand"
398 (ior (match_operand 0 "const_arith_operand")
399 (match_operand 0 "register_operand")
400 (and (match_test "TARGET_ZBS")
401 (match_operand 0 "single_bit_mask_operand"))))
402
403 (define_predicate "not_single_bit_mask_operand"
404 (and (match_code "const_int")
405 (match_test "SINGLE_BIT_MASK_OPERAND (~UINTVAL (op))")))
406
407 (define_predicate "arith_or_mode_mask_or_zbs_operand"
408 (ior (match_operand 0 "arith_operand")
409 (and (match_test "TARGET_ZBS")
410 (match_operand 0 "not_single_bit_mask_operand"))
411 (and (match_code "const_int")
412 (match_test "UINTVAL (op) == GET_MODE_MASK (HImode)
413 || UINTVAL (op) == GET_MODE_MASK (SImode)"))))
414
415 (define_predicate "const_si_mask_operand"
416 (and (match_code "const_int")
417 (match_test "(INTVAL (op) & (GET_MODE_BITSIZE (SImode) - 1))
418 == GET_MODE_BITSIZE (SImode) - 1")))
419
420 (define_predicate "const_di_mask_operand"
421 (and (match_code "const_int")
422 (match_test "(INTVAL (op) & (GET_MODE_BITSIZE (DImode) - 1))
423 == GET_MODE_BITSIZE (DImode) - 1")))
424
425 (define_predicate "imm5_operand"
426 (and (match_code "const_int")
427 (match_test "INTVAL (op) < 5")))
428
429 ;; A const_int for sh1add/sh2add/sh3add
430 (define_predicate "imm123_operand"
431 (and (match_code "const_int")
432 (match_test "IN_RANGE (INTVAL (op), 1, 3)")))
433
434 ;; A CONST_INT operand that consists of a single run of consecutive set bits.
435 (define_predicate "consecutive_bits_operand"
436 (match_code "const_int")
437 {
438 unsigned HOST_WIDE_INT val = UINTVAL (op);
439 if (exact_log2 ((val >> ctz_hwi (val)) + 1) <= 0)
440 return false;
441
442 return true;
443 })
444
445 (define_predicate "const_two_s12"
446 (match_code "const_int")
447 {
448 return SUM_OF_TWO_S12 (INTVAL (op));
449 })
450
451 ;; CORE-V Predicates:
452 (define_predicate "immediate_register_operand"
453 (ior (match_operand 0 "register_operand")
454 (match_code "const_int")))
455
456 (define_predicate "const_int6s_operand"
457 (and (match_code "const_int")
458 (match_test "IN_RANGE (INTVAL (op), -32, 31)")))
459
460 (define_predicate "int6s_operand"
461 (ior (match_operand 0 "const_int6s_operand")
462 (match_operand 0 "register_operand")))
463
464 (define_predicate "const_int2_operand"
465 (and (match_code "const_int")
466 (match_test "IN_RANGE (INTVAL (op), 0, 3)")))
467
468 (define_predicate "const_int6_operand"
469 (and (match_code "const_int")
470 (match_test "IN_RANGE (INTVAL (op), 0, 63)")))
471
472 (define_predicate "int6_operand"
473 (ior (match_operand 0 "const_int6_operand")
474 (match_operand 0 "register_operand")))
475
476 (define_predicate "const_int5s_operand"
477 (and (match_code "const_int")
478 (match_test "IN_RANGE (INTVAL (op), -16, 15)")))
479
480 ;; Predicates for the V extension.
481 (define_special_predicate "vector_length_operand"
482 (ior (match_operand 0 "pmode_register_operand")
483 (and (ior (match_test "TARGET_XTHEADVECTOR && rtx_equal_p (op, const0_rtx)")
484 (match_test "!TARGET_XTHEADVECTOR"))
485 (match_operand 0 "const_csr_operand"))))
486
487 (define_special_predicate "autovec_length_operand"
488 (ior (match_operand 0 "pmode_register_operand")
489 (match_code "const_int,const_poly_int")))
490
491 (define_predicate "reg_or_mem_operand"
492 (ior (match_operand 0 "register_operand")
493 (match_operand 0 "memory_operand")))
494
495 (define_predicate "reg_or_int_operand"
496 (ior (match_operand 0 "register_operand")
497 (match_operand 0 "const_int_operand")))
498
499 (define_predicate "vector_const_0_operand"
500 (and (match_code "const_vector")
501 (match_test "satisfies_constraint_Wc0 (op)")))
502
503 (define_predicate "vector_const_int_or_double_0_operand"
504 (and (match_code "const_vector")
505 (match_test "satisfies_constraint_vi (op)
506 || satisfies_constraint_Wc0 (op)")))
507
508 (define_predicate "vector_move_operand"
509 (ior (match_operand 0 "nonimmediate_operand")
510 (and (match_code "const_vector")
511 (match_test "reload_completed
512 || satisfies_constraint_vi (op)
513 || satisfies_constraint_Wc0 (op)"))))
514
515 (define_predicate "vector_all_trues_mask_operand"
516 (and (match_code "const_vector")
517 (match_test "op == CONSTM1_RTX (GET_MODE (op))")))
518
519 (define_predicate "vector_least_significant_set_mask_operand"
520 (and (match_code "const_vector")
521 (match_test "rtx_equal_p (op, riscv_vector::gen_scalar_move_mask (GET_MODE (op)))")))
522
523 (define_predicate "vector_mask_operand"
524 (ior (match_operand 0 "register_operand")
525 (match_operand 0 "vector_all_trues_mask_operand")))
526
527 (define_predicate "vector_broadcast_mask_operand"
528 (ior (match_operand 0 "vector_least_significant_set_mask_operand")
529 (ior (match_operand 0 "register_operand")
530 (match_operand 0 "vector_all_trues_mask_operand"))))
531
532 (define_predicate "vector_undef_operand"
533 (match_test "rtx_equal_p (op, RVV_VUNDEF (GET_MODE (op)))"))
534
535 (define_predicate "vector_merge_operand"
536 (ior (match_operand 0 "register_operand")
537 (match_operand 0 "vector_undef_operand")))
538
539 (define_predicate "autovec_else_operand"
540 (ior (match_operand 0 "register_operand")
541 (match_operand 0 "scratch_operand")))
542
543 (define_predicate "maskload_else_operand"
544 (match_operand 0 "scratch_operand"))
545
546 (define_predicate "vector_arith_operand"
547 (ior (match_operand 0 "register_operand")
548 (and (match_code "const_vector")
549 (match_test "riscv_vector::const_vec_all_same_in_range_p (op, -16, 15)"))))
550
551 (define_predicate "vector_neg_arith_operand"
552 (ior (match_operand 0 "register_operand")
553 (and (match_code "const_vector")
554 (match_test "riscv_vector::const_vec_all_same_in_range_p (op, -15, 16)"))))
555
556 (define_predicate "vector_shift_operand"
557 (ior (match_operand 0 "register_operand")
558 (and (match_code "const_vector")
559 (match_test "riscv_vector::const_vec_all_same_in_range_p (op, 0, 31)"))))
560
561 (define_predicate "vector_perm_operand"
562 (ior (match_operand 0 "register_operand")
563 (match_code "const_vector")))
564
565 (define_predicate "vector_gs_extension_operand"
566 (ior (match_operand 0 "const_1_operand")
567 (and (match_operand 0 "const_0_operand")
568 (match_test "Pmode == SImode"))))
569
570 (define_predicate "vector_gs_scale_operand_16_rv32"
571 (and (match_code "const_int")
572 (match_test "INTVAL (op) == 1
573 || (INTVAL (op) == 2 && Pmode == SImode)")))
574
575 (define_predicate "vector_gs_scale_operand_32_rv32"
576 (and (match_code "const_int")
577 (match_test "INTVAL (op) == 1
578 || (INTVAL (op) == 4 && Pmode == SImode)")))
579
580 (define_predicate "ltge_operator"
581 (match_code "lt,ltu,ge,geu"))
582
583 (define_predicate "comparison_except_ltge_operator"
584 (match_code "eq,ne,le,leu,gt,gtu"))
585
586 (define_predicate "comparison_except_ge_operator"
587 (match_code "eq,ne,le,leu,gt,gtu,lt,ltu"))
588
589 (define_predicate "ge_operator"
590 (match_code "ge,geu"))
591
592 ;; pmode_reg_or_uimm5_operand can be used by vsll.vx/vsrl.vx/vsra.vx instructions
593 ;; It is *not* equivalent to vector_length_operand due to the vector_length_operand
594 ;; needing to conditionalize some behavior on XTHEADVECTOR.
595 (define_special_predicate "pmode_reg_or_uimm5_operand"
596 (ior (match_operand 0 "pmode_register_operand")
597 (match_operand 0 "const_csr_operand")))
598
599 (define_special_predicate "pmode_reg_or_0_operand"
600 (ior (match_operand 0 "const_0_operand")
601 (match_operand 0 "pmode_register_operand")))
602
603 ;; [1, 2, 4, 8] means strided load/store with stride == element width
604 (define_special_predicate "vector_eew8_stride_operand"
605 (ior (match_operand 0 "pmode_register_operand")
606 (and (match_code "const_int")
607 (match_test "INTVAL (op) == 1 || INTVAL (op) == 0"))))
608 (define_special_predicate "vector_eew16_stride_operand"
609 (ior (match_operand 0 "pmode_register_operand")
610 (and (match_code "const_int")
611 (match_test "INTVAL (op) == 2 || INTVAL (op) == 0"))))
612 (define_special_predicate "vector_eew32_stride_operand"
613 (ior (match_operand 0 "pmode_register_operand")
614 (and (match_code "const_int")
615 (match_test "INTVAL (op) == 4 || INTVAL (op) == 0"))))
616 (define_special_predicate "vector_eew64_stride_operand"
617 (ior (match_operand 0 "pmode_register_operand")
618 (and (match_code "const_int")
619 (match_test "INTVAL (op) == 8 || INTVAL (op) == 0"))))
620
621 ;; A special predicate that doesn't match a particular mode.
622 (define_special_predicate "vector_any_register_operand"
623 (match_code "reg"))
624
625 ;; The scalar operand can be directly broadcast by RVV instructions.
626 (define_predicate "direct_broadcast_operand"
627 (match_test "riscv_vector::can_be_broadcasted_p (op)"))
628
629 ;; A CONST_INT operand that has exactly two bits cleared.
630 (define_predicate "const_nottwobits_operand"
631 (and (match_code "const_int")
632 (match_test "popcount_hwi (~UINTVAL (op)) == 2")))
633
634 (define_predicate "const_nottwobits_not_arith_operand"
635 (and (match_code "const_int")
636 (and (not (match_operand 0 "arith_operand"))
637 (match_operand 0 "const_nottwobits_operand"))))
638
639 ;; A CONST_INT operand that consists of a single run of 32 consecutive
640 ;; set bits.
641 (define_predicate "consecutive_bits32_operand"
642 (and (match_operand 0 "consecutive_bits_operand")
643 (match_test "popcount_hwi (UINTVAL (op)) == 32")))
644
645 ;; A CONST_INT operand that, if shifted down to start with its least
646 ;; significant non-zero bit, is a SMALL_OPERAND (suitable as an
647 ;; immediate to logical and arithmetic instructions).
648 (define_predicate "shifted_const_arith_operand"
649 (and (match_code "const_int")
650 (match_test "ctz_hwi (INTVAL (op)) > 0")
651 (match_test "SMALL_OPERAND (INTVAL (op) >> ctz_hwi (INTVAL (op)))")))
652
653 ;; A CONST_INT operand that has exactly two bits set.
654 (define_predicate "const_twobits_operand"
655 (and (match_code "const_int")
656 (match_test "popcount_hwi (UINTVAL (op)) == 2")))
657
658 (define_predicate "const_twobits_not_arith_operand"
659 (and (match_code "const_int")
660 (and (not (match_operand 0 "arith_operand"))
661 (match_operand 0 "const_twobits_operand"))))
662
663 ;; A CONST_INT operand that fits into the unsigned half of a
664 ;; signed-immediate after the top bit has been cleared
665 (define_predicate "uimm_extra_bit_operand"
666 (and (match_code "const_int")
667 (match_test "UIMM_EXTRA_BIT_OPERAND (UINTVAL (op))")))
668
669 (define_predicate "uimm_extra_bit_or_twobits"
670 (and (match_code "const_int")
671 (ior (match_operand 0 "uimm_extra_bit_operand")
672 (match_operand 0 "const_twobits_not_arith_operand"))))
673
674 ;; A CONST_INT operand that fits into the negative half of a
675 ;; signed-immediate after a single cleared top bit has been
676 ;; set: i.e., a bitwise-negated uimm_extra_bit_operand
677 (define_predicate "not_uimm_extra_bit_operand"
678 (and (match_code "const_int")
679 (match_test "UIMM_EXTRA_BIT_OPERAND (~UINTVAL (op))")))
680
681 (define_predicate "not_uimm_extra_bit_or_nottwobits"
682 (and (match_code "const_int")
683 (ior (match_operand 0 "not_uimm_extra_bit_operand")
684 (match_operand 0 "const_nottwobits_not_arith_operand"))))
685
686 (define_predicate "pcrel_symbol_operand"
687 (match_code "symbol_ref")
688 {
689 enum riscv_symbol_type type;
690 return (riscv_symbolic_constant_p (op, &type)
691 && type == SYMBOL_PCREL);
692 })
693
694 ;; Shadow stack operands only allow x1, x5 registers
695 (define_predicate "x1x5_operand"
696 (and (match_operand 0 "register_operand")
697 (match_test "REGNO (op) == RETURN_ADDR_REGNUM
698 || REGNO (op) == T0_REGNUM")))