1 ;; Machine description for AArch64 architecture.
2 ;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
3 ;; Contributed by ARM Ltd.
5 ;; This file is part of GCC.
7 ;; GCC is free software; you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3, or (at your option)
12 ;; GCC is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
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/>.
21 (include "../arm/common.md")
23 (define_predicate "aarch64_sysreg_string"
24 (and (match_code "const_string")
25 (match_test "aarch64_valid_sysreg_name_p (XSTR (op, 0))")))
27 (define_special_predicate "cc_register"
28 (and (match_code "reg")
29 (and (match_test "REGNO (op) == CC_REGNUM")
30 (ior (match_test "mode == GET_MODE (op)")
31 (match_test "mode == VOIDmode
32 && GET_MODE_CLASS (GET_MODE (op)) == MODE_CC"))))
35 (define_predicate "aarch64_call_insn_operand"
36 (ior (match_code "symbol_ref")
37 (match_operand 0 "register_operand")))
39 (define_predicate "aarch64_general_reg"
40 (and (match_operand 0 "register_operand")
41 (match_test "REGNO_REG_CLASS (REGNO (op)) == STUB_REGS
42 || REGNO_REG_CLASS (REGNO (op)) == GENERAL_REGS")))
44 ;; Return true if OP a (const_int 0) operand.
45 (define_predicate "const0_operand"
46 (and (match_code "const_int")
47 (match_test "op == CONST0_RTX (mode)")))
49 (define_predicate "const_0_to_7_operand"
50 (and (match_code "const_int")
51 (match_test "IN_RANGE (INTVAL (op), 0, 7)")))
53 (define_predicate "const_0_to_4_step_4_operand"
54 (and (match_code "const_int")
55 (match_test "IN_RANGE (INTVAL (op), 0, 4)")
56 (match_test "(INTVAL (op) & 3) == 0")))
58 (define_predicate "const_0_to_6_step_2_operand"
59 (and (match_code "const_int")
60 (match_test "IN_RANGE (INTVAL (op), 0, 6)")
61 (match_test "(INTVAL (op) & 1) == 0")))
63 (define_predicate "const_0_to_12_step_4_operand"
64 (and (match_code "const_int")
65 (match_test "IN_RANGE (INTVAL (op), 0, 12)")
66 (match_test "(INTVAL (op) & 3) == 0")))
68 (define_predicate "const_0_to_14_step_2_operand"
69 (and (match_code "const_int")
70 (match_test "IN_RANGE (INTVAL (op), 0, 14)")
71 (match_test "(INTVAL (op) & 1) == 0")))
73 (define_predicate "const_1_to_3_operand"
74 (match_code "const_int,const_vector")
76 op = unwrap_const_vec_duplicate (op);
77 return CONST_INT_P (op) && IN_RANGE (INTVAL (op), 1, 3);
80 (define_predicate "subreg_lowpart_operator"
81 (ior (match_code "truncate")
82 (and (match_code "subreg")
83 (match_test "subreg_lowpart_p (op)"))))
85 (define_predicate "aarch64_ccmp_immediate"
86 (and (match_code "const_int")
87 (match_test "IN_RANGE (INTVAL (op), -31, 31)")))
89 (define_predicate "aarch64_ccmp_operand"
90 (ior (match_operand 0 "register_operand")
91 (match_operand 0 "aarch64_ccmp_immediate")))
93 (define_predicate "aarch64_simd_register"
94 (and (match_code "reg")
95 (match_test "FP_REGNUM_P (REGNO (op))")))
97 (define_predicate "aarch64_reg_or_zero"
98 (and (match_code "reg,subreg,const_int,const_double")
99 (ior (match_operand 0 "register_operand")
100 (match_test "op == CONST0_RTX (GET_MODE (op))"))))
102 (define_predicate "aarch64_reg_or_fp_zero"
103 (ior (match_operand 0 "register_operand")
104 (and (match_code "const_double")
105 (match_test "aarch64_float_const_zero_rtx_p (op)"))))
107 (define_predicate "aarch64_reg_zero_or_fp_zero"
108 (ior (match_operand 0 "aarch64_reg_or_fp_zero")
109 (match_operand 0 "aarch64_reg_or_zero")))
111 (define_predicate "aarch64_reg_zero_or_m1_or_1"
112 (and (match_code "reg,subreg,const_int")
113 (ior (match_operand 0 "register_operand")
114 (ior (match_test "op == const0_rtx")
115 (ior (match_test "op == constm1_rtx")
116 (match_test "op == const1_rtx"))))))
118 (define_predicate "aarch64_reg_or_orr_imm"
119 (ior (match_operand 0 "register_operand")
120 (and (match_code "const_vector")
121 (match_test "aarch64_simd_valid_immediate (op, NULL,
122 AARCH64_CHECK_ORR)"))))
124 (define_predicate "aarch64_reg_or_bic_imm"
125 (ior (match_operand 0 "register_operand")
126 (and (match_code "const_vector")
127 (match_test "aarch64_simd_valid_immediate (op, NULL,
128 AARCH64_CHECK_BIC)"))))
130 (define_predicate "aarch64_fp_compare_operand"
131 (ior (match_operand 0 "register_operand")
132 (and (match_code "const_double")
133 (match_test "aarch64_float_const_zero_rtx_p (op)"))))
135 (define_predicate "aarch64_fp_pow2"
136 (and (match_code "const_double")
137 (match_test "aarch64_fpconst_pow_of_2 (op) > 0")))
139 (define_predicate "aarch64_fp_pow2_recip"
140 (and (match_code "const_double")
141 (match_test "aarch64_fpconst_pow2_recip (op) > 0")))
143 (define_predicate "aarch64_fp_vec_pow2"
144 (match_test "aarch64_vec_fpconst_pow_of_2 (op) > 0"))
146 (define_predicate "aarch64_sve_cnt_immediate"
147 (and (match_code "const_poly_int")
148 (match_test "aarch64_sve_cnt_immediate_p (op)")))
150 (define_predicate "aarch64_sub_immediate"
151 (and (match_code "const_int")
152 (match_test "aarch64_uimm12_shift (-UINTVAL (op))")))
154 (define_predicate "aarch64_plus_immediate"
155 (and (match_code "const_int")
156 (ior (match_test "aarch64_uimm12_shift (INTVAL (op))")
157 (match_test "aarch64_uimm12_shift (-UINTVAL (op))"))))
159 (define_predicate "aarch64_plus_operand"
160 (ior (match_operand 0 "register_operand")
161 (match_operand 0 "aarch64_plus_immediate")))
163 (define_predicate "aarch64_plushi_immediate"
164 (match_code "const_int")
166 HOST_WIDE_INT val = INTVAL (op);
167 /* The HImode value must be zero-extendable to an SImode plus_operand. */
168 return ((val & 0xfff) == val || sext_hwi (val & 0xf000, 16) == val);
171 (define_predicate "aarch64_plushi_operand"
172 (ior (match_operand 0 "register_operand")
173 (match_operand 0 "aarch64_plushi_immediate")))
175 (define_predicate "aarch64_pluslong_immediate"
176 (and (match_code "const_int")
177 (match_test "IN_RANGE (INTVAL (op), -0xffffff, 0xffffff)")))
179 (define_predicate "aarch64_sminmax_immediate"
180 (and (match_code "const_int")
181 (match_test "IN_RANGE (INTVAL (op), -128, 127)")))
183 (define_predicate "aarch64_sminmax_operand"
184 (ior (match_operand 0 "register_operand")
185 (match_operand 0 "aarch64_sminmax_immediate")))
187 (define_predicate "aarch64_uminmax_immediate"
188 (and (match_code "const_int")
189 (match_test "IN_RANGE (INTVAL (op), 0, 255)")))
191 (define_predicate "aarch64_uminmax_operand"
192 (ior (match_operand 0 "register_operand")
193 (match_operand 0 "aarch64_uminmax_immediate")))
195 (define_predicate "aarch64_pluslong_strict_immedate"
196 (and (match_operand 0 "aarch64_pluslong_immediate")
197 (not (match_operand 0 "aarch64_plus_immediate"))))
199 (define_predicate "aarch64_sve_scalar_inc_dec_immediate"
200 (and (match_code "const_poly_int")
201 (match_test "aarch64_sve_scalar_inc_dec_immediate_p (op)")))
203 (define_predicate "aarch64_sve_addvl_addpl_immediate"
204 (and (match_code "const_poly_int")
205 (match_test "aarch64_sve_addvl_addpl_immediate_p (op)")))
207 (define_predicate "aarch64_sve_plus_immediate"
208 (ior (match_operand 0 "aarch64_sve_scalar_inc_dec_immediate")
209 (match_operand 0 "aarch64_sve_addvl_addpl_immediate")))
211 (define_predicate "aarch64_split_add_offset_immediate"
212 (and (match_code "const_poly_int")
213 (match_test "aarch64_add_offset_temporaries (op) == 1")))
215 (define_predicate "aarch64_addsvl_addspl_immediate"
216 (and (match_code "const")
217 (match_test "aarch64_addsvl_addspl_immediate_p (op)")))
219 (define_predicate "aarch64_pluslong_operand"
220 (ior (match_operand 0 "register_operand")
221 (match_operand 0 "aarch64_pluslong_immediate")
222 (and (match_test "TARGET_SVE")
223 (match_operand 0 "aarch64_sve_plus_immediate"))
224 (and (match_test "TARGET_SME")
225 (match_operand 0 "aarch64_addsvl_addspl_immediate"))))
227 (define_predicate "aarch64_pluslong_or_poly_operand"
228 (ior (match_operand 0 "aarch64_pluslong_operand")
229 (match_operand 0 "aarch64_split_add_offset_immediate")))
231 (define_predicate "aarch64_logical_immediate"
232 (and (match_code "const_int")
233 (match_test "aarch64_bitmask_imm (INTVAL (op), mode)")))
235 (define_predicate "aarch64_logical_operand"
236 (ior (match_operand 0 "register_operand")
237 (match_operand 0 "aarch64_logical_immediate")))
239 (define_predicate "aarch64_mov_imm_operand"
240 (and (match_code "const_int")
241 (match_test "aarch64_move_imm (INTVAL (op), mode)")))
243 (define_predicate "aarch64_logical_and_immediate"
244 (and (match_code "const_int")
245 (match_test "aarch64_and_bitmask_imm (INTVAL (op), mode)")))
247 (define_predicate "aarch64_shift_imm_si"
248 (and (match_code "const_int")
249 (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) < 32")))
251 (define_predicate "aarch64_shift_imm_di"
252 (and (match_code "const_int")
253 (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) < 64")))
255 (define_predicate "aarch64_shift_imm64_di"
256 (and (match_code "const_int")
257 (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) <= 64")))
259 (define_predicate "aarch64_reg_or_shift_imm_si"
260 (ior (match_operand 0 "register_operand")
261 (match_operand 0 "aarch64_shift_imm_si")))
263 (define_predicate "aarch64_reg_or_shift_imm_di"
264 (ior (match_operand 0 "register_operand")
265 (match_operand 0 "aarch64_shift_imm_di")))
267 ;; The imm3 field is a 3-bit field that only accepts immediates in the
269 (define_predicate "aarch64_imm3"
270 (and (match_code "const_int")
271 (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) <= 4")))
273 ;; The imm2 field is a 2-bit field that only accepts immediates in the
275 (define_predicate "aarch64_imm2"
276 (and (match_code "const_int")
277 (match_test "UINTVAL (op) <= 3")))
279 ;; The imm3 field is a 3-bit field that only accepts immediates in the
281 (define_predicate "aarch64_lane_imm3"
282 (and (match_code "const_int")
283 (match_test "UINTVAL (op) <= 7")))
285 ;; An immediate that fits into 24 bits.
286 (define_predicate "aarch64_imm24"
287 (and (match_code "const_int")
288 (match_test "IN_RANGE (UINTVAL (op), 0, 0xffffff)")))
290 (define_predicate "aarch64_mem_pair_offset"
291 (and (match_code "const_int")
292 (match_test "aarch64_offset_7bit_signed_scaled_p (mode, INTVAL (op))")))
294 (define_special_predicate "aarch64_mem_pair_operator"
297 (match_test "aarch64_ldpstp_operand_mode_p (GET_MODE (op))")
299 (match_test "mode == VOIDmode")
300 (match_test "known_eq (GET_MODE_SIZE (mode),
301 GET_MODE_SIZE (GET_MODE (op)))"))))
303 ;; Like aarch64_mem_pair_operator, but additionally check the
304 ;; address is suitable.
305 (define_special_predicate "aarch64_mem_pair_operand"
306 (and (match_operand 0 "aarch64_mem_pair_operator")
307 (match_test "aarch64_legitimate_address_p (GET_MODE (op), XEXP (op, 0),
308 false, ADDR_QUERY_LDP_STP)")))
310 (define_predicate "pmode_plus_operator"
311 (and (match_code "plus")
312 (match_test "GET_MODE (op) == Pmode")))
314 (define_special_predicate "aarch64_ldp_reg_operand"
319 (match_code "subreg")
320 (match_test "REG_P (SUBREG_REG (op))")))
321 (match_test "aarch64_ldpstp_operand_mode_p (GET_MODE (op))")
323 (match_test "mode == VOIDmode")
324 (match_test "known_eq (GET_MODE_SIZE (mode),
325 GET_MODE_SIZE (GET_MODE (op)))"))))
327 (define_special_predicate "aarch64_stp_reg_operand"
328 (ior (match_operand 0 "aarch64_ldp_reg_operand")
329 (and (match_code "const_int,const,const_vector,const_double")
330 (match_test "aarch64_const_zero_rtx_p (op)")
332 (match_test "GET_MODE (op) == VOIDmode")
334 (match_test "aarch64_ldpstp_operand_mode_p (GET_MODE (op))")
336 (match_test "mode == VOIDmode")
337 (match_test "known_eq (GET_MODE_SIZE (mode),
338 GET_MODE_SIZE (GET_MODE (op)))")))))))
340 ;; Used for storing two 64-bit values in an AdvSIMD register using an STP
341 ;; as a 128-bit vec_concat.
342 (define_predicate "aarch64_mem_pair_lanes_operand"
343 (and (match_code "mem")
344 (match_test "aarch64_legitimate_address_p (GET_MODE (op), XEXP (op, 0),
346 ADDR_QUERY_LDP_STP_N)")))
348 (define_predicate "aarch64_reg_or_mem_pair_operand"
349 (ior (match_operand 0 "register_operand")
350 (match_operand 0 "aarch64_mem_pair_lanes_operand")))
352 (define_predicate "aarch64_prefetch_operand"
353 (match_test "aarch64_address_valid_for_prefetch_p (op, false)"))
355 (define_predicate "aarch64_valid_symref"
356 (match_code "const, symbol_ref, label_ref")
358 return (aarch64_classify_symbolic_expression (op)
359 != SYMBOL_FORCE_TO_MEM);
362 (define_predicate "aarch64_tls_ie_symref"
363 (match_code "const, symbol_ref, label_ref")
365 switch (GET_CODE (op))
369 if (GET_CODE (op) != PLUS
370 || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
371 || GET_CODE (XEXP (op, 1)) != CONST_INT)
377 return SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_INITIAL_EXEC;
384 (define_predicate "aarch64_tls_le_symref"
385 (match_code "const, symbol_ref, label_ref")
387 switch (GET_CODE (op))
391 if (GET_CODE (op) != PLUS
392 || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
393 || GET_CODE (XEXP (op, 1)) != CONST_INT)
399 return SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_EXEC;
406 (define_predicate "aarch64_mov_operand"
407 (and (match_code "reg,subreg,mem,const,const_int,symbol_ref,label_ref,high,
408 const_poly_int,const_vector")
409 (ior (match_operand 0 "register_operand")
410 (ior (match_operand 0 "memory_operand")
411 (match_test "aarch64_mov_operand_p (op, mode)")))))
413 (define_predicate "aarch64_nonmemory_operand"
414 (and (match_code "reg,subreg,const,const_int,symbol_ref,label_ref,high,
415 const_poly_int,const_vector")
416 (ior (match_operand 0 "register_operand")
417 (match_test "aarch64_mov_operand_p (op, mode)"))))
419 (define_predicate "aarch64_movti_operand"
420 (ior (match_operand 0 "register_operand")
421 (match_operand 0 "memory_operand")
422 (and (match_operand 0 "const_scalar_int_operand")
423 (match_test "aarch64_mov128_immediate (op)"))))
425 (define_predicate "aarch64_reg_or_imm"
426 (ior (match_operand 0 "register_operand")
427 (match_operand 0 "const_scalar_int_operand")))
429 ;; True for integer comparisons and for FP comparisons other than LTGT or UNEQ.
430 (define_special_predicate "aarch64_comparison_operator"
431 (match_code "eq,ne,le,lt,ge,gt,geu,gtu,leu,ltu,unordered,
432 ordered,unlt,unle,unge,ungt"))
434 ;; Same as aarch64_comparison_operator but don't ignore the mode.
435 ;; RTL SET operations require their operands source and destination have
436 ;; the same modes, so we can't ignore the modes there. See PR target/69161.
437 (define_predicate "aarch64_comparison_operator_mode"
438 (match_code "eq,ne,le,lt,ge,gt,geu,gtu,leu,ltu,unordered,
439 ordered,unlt,unle,unge,ungt"))
441 (define_special_predicate "aarch64_comparison_operation"
442 (match_code "eq,ne,le,lt,ge,gt,geu,gtu,leu,ltu,unordered,
443 ordered,unlt,unle,unge,ungt")
445 if (XEXP (op, 1) != const0_rtx)
447 rtx op0 = XEXP (op, 0);
448 if (!REG_P (op0) || REGNO (op0) != CC_REGNUM)
450 return aarch64_get_condition_code (op) >= 0;
453 (define_special_predicate "aarch64_equality_operator"
454 (match_code "eq,ne"))
456 (define_special_predicate "aarch64_carry_operation"
457 (match_code "ltu,geu")
459 if (XEXP (op, 1) != const0_rtx)
461 rtx op0 = XEXP (op, 0);
462 if (!REG_P (op0) || REGNO (op0) != CC_REGNUM)
464 machine_mode ccmode = GET_MODE (op0);
465 if (ccmode == CC_Cmode)
466 return GET_CODE (op) == LTU;
467 if (ccmode == CC_ADCmode || ccmode == CCmode)
468 return GET_CODE (op) == GEU;
472 ; borrow is essentially the inverse of carry since the sense of the C flag
473 ; is inverted during subtraction. See the note in aarch64-modes.def.
474 (define_special_predicate "aarch64_borrow_operation"
475 (match_code "geu,ltu")
477 if (XEXP (op, 1) != const0_rtx)
479 rtx op0 = XEXP (op, 0);
480 if (!REG_P (op0) || REGNO (op0) != CC_REGNUM)
482 machine_mode ccmode = GET_MODE (op0);
483 if (ccmode == CC_Cmode)
484 return GET_CODE (op) == GEU;
485 if (ccmode == CC_ADCmode || ccmode == CCmode)
486 return GET_CODE (op) == LTU;
490 ;; True if the operand is memory reference suitable for a load/store exclusive.
491 (define_predicate "aarch64_sync_memory_operand"
492 (and (match_operand 0 "memory_operand")
493 (match_code "reg" "0")))
495 (define_predicate "aarch64_9bit_offset_memory_operand"
496 (and (match_operand 0 "memory_operand")
497 (ior (match_code "reg" "0")
498 (and (match_code "plus" "0")
499 (match_code "reg" "00")
500 (match_code "const_int" "01"))))
502 rtx mem_op = XEXP (op, 0);
505 return GET_MODE (mem_op) == DImode;
507 rtx plus_op0 = XEXP (mem_op, 0);
508 rtx plus_op1 = XEXP (mem_op, 1);
510 if (GET_MODE (plus_op0) != DImode)
514 if (!poly_int_rtx_p (plus_op1, &offset))
517 return aarch64_offset_9bit_signed_unscaled_p (mode, offset);
520 (define_predicate "aarch64_rcpc_memory_operand"
521 (if_then_else (match_test "TARGET_RCPC2")
522 (match_operand 0 "aarch64_9bit_offset_memory_operand")
523 (match_operand 0 "aarch64_sync_memory_operand")))
525 ;; Predicates for parallel expanders based on mode.
526 (define_special_predicate "vect_par_cnst_hi_half"
527 (match_code "parallel")
529 return aarch64_simd_check_vect_par_cnst_half (op, mode, true);
532 (define_special_predicate "vect_par_cnst_lo_half"
533 (match_code "parallel")
535 return aarch64_simd_check_vect_par_cnst_half (op, mode, false);
538 ;; PARALLEL for a vec_select that selects all the even or all the odd
539 ;; elements of a vector of MODE.
540 (define_special_predicate "vect_par_cnst_even_or_odd_half"
541 (match_code "parallel")
543 int nunits = XVECLEN (op, 0);
544 if (!known_eq (GET_MODE_NUNITS (mode), nunits * 2))
546 rtx first = XVECEXP (op, 0, 0);
547 if (!CONST_INT_P (first))
549 return (INTVAL (first) == 0 || INTVAL (first) == 1)
550 && aarch64_stepped_int_parallel_p (op, 2);
553 ;; PARALLEL for a vec_select that selects half the elements in a vector of
554 ;; MODE. Allows any combination of elements, as long as there's no
555 ;; duplicate entries.
556 (define_special_predicate "vect_par_cnst_select_half"
557 (match_code "parallel")
559 return aarch64_parallel_select_half_p (mode, op);
562 (define_predicate "descending_int_parallel"
563 (match_code "parallel")
565 return aarch64_stepped_int_parallel_p (op, -1);
568 (define_predicate "ascending_int_parallel"
569 (match_code "parallel")
571 return aarch64_stepped_int_parallel_p (op, 1);
574 (define_special_predicate "aarch64_simd_lshift_imm"
575 (match_code "const,const_vector")
577 return aarch64_simd_shift_imm_p (op, mode, true);
580 (define_special_predicate "aarch64_simd_rshift_imm"
581 (match_code "const,const_vector")
583 return aarch64_simd_shift_imm_p (op, mode, false);
586 (define_predicate "aarch64_simd_imm_zero"
587 (and (match_code "const,const_vector")
588 (match_test "op == CONST0_RTX (GET_MODE (op))")))
590 (define_predicate "aarch64_simd_imm_one"
591 (and (match_code "const_vector")
592 (match_test "op == CONST1_RTX (GET_MODE (op))")))
594 (define_predicate "aarch64_simd_or_scalar_imm_zero"
595 (and (match_code "const_int,const_double,const,const_vector")
596 (match_test "op == CONST0_RTX (GET_MODE (op))")))
598 (define_predicate "aarch64_simd_imm_minus_one"
599 (and (match_code "const,const_vector")
600 (match_test "op == CONSTM1_RTX (GET_MODE (op))")))
602 (define_predicate "aarch64_simd_reg_or_zero"
603 (and (match_code "reg,subreg,const_int,const_double,const,const_vector")
604 (ior (match_operand 0 "register_operand")
605 (match_test "op == const0_rtx")
606 (match_operand 0 "aarch64_simd_or_scalar_imm_zero"))))
608 (define_predicate "aarch64_simd_reg_or_minus_one"
609 (ior (match_operand 0 "register_operand")
610 (match_operand 0 "aarch64_simd_imm_minus_one")))
612 (define_predicate "aarch64_simd_struct_operand"
613 (and (match_code "mem")
614 (match_test "TARGET_SIMD && aarch64_simd_mem_operand_p (op)")))
616 ;; Like general_operand but allow only valid SIMD addressing modes.
617 (define_predicate "aarch64_simd_general_operand"
618 (and (match_operand 0 "general_operand")
619 (match_test "!MEM_P (op)
620 || GET_CODE (XEXP (op, 0)) == POST_INC
621 || GET_CODE (XEXP (op, 0)) == REG")))
623 ;; Like nonimmediate_operand but allow only valid SIMD addressing modes.
624 (define_predicate "aarch64_simd_nonimmediate_operand"
625 (and (match_operand 0 "nonimmediate_operand")
626 (match_test "!MEM_P (op)
627 || GET_CODE (XEXP (op, 0)) == POST_INC
628 || GET_CODE (XEXP (op, 0)) == REG")))
630 ;; Predicates used by the various SIMD shift operations. These
631 ;; fall in to 3 categories.
632 ;; Shifts with a range 0-(bit_size - 1) (aarch64_simd_shift_imm)
633 ;; Shifts with a range 1-bit_size (aarch64_simd_shift_imm_offset)
634 ;; Shifts with a range 0-bit_size (aarch64_simd_shift_imm_bitsize)
635 (define_predicate "aarch64_simd_shift_imm_qi"
636 (match_operand 0 "const_0_to_7_operand"))
638 (define_predicate "aarch64_simd_shift_imm_hi"
639 (and (match_code "const_int")
640 (match_test "IN_RANGE (INTVAL (op), 0, 15)")))
642 (define_predicate "aarch64_simd_shift_imm_si"
643 (and (match_code "const_int")
644 (match_test "IN_RANGE (INTVAL (op), 0, 31)")))
646 (define_predicate "aarch64_simd_shift_imm_di"
647 (and (match_code "const_int")
648 (match_test "IN_RANGE (INTVAL (op), 0, 63)")))
650 (define_predicate "aarch64_simd_shift_imm_offset_qi"
651 (and (match_code "const_int")
652 (match_test "IN_RANGE (INTVAL (op), 1, 8)")))
654 (define_predicate "aarch64_simd_shift_imm_offset_hi"
655 (and (match_code "const_int")
656 (match_test "IN_RANGE (INTVAL (op), 1, 16)")))
658 (define_predicate "aarch64_simd_shift_imm_offset_si"
659 (and (match_code "const_int")
660 (match_test "IN_RANGE (INTVAL (op), 1, 32)")))
662 (define_predicate "aarch64_simd_shift_imm_offset_di"
663 (and (match_code "const_int")
664 (match_test "IN_RANGE (INTVAL (op), 1, 64)")))
666 (define_predicate "aarch64_simd_shift_imm_vec_exact_top"
667 (and (match_code "const_vector")
668 (match_test "aarch64_const_vec_all_same_in_range_p (op,
669 GET_MODE_UNIT_BITSIZE (GET_MODE (op)) / 2,
670 GET_MODE_UNIT_BITSIZE (GET_MODE (op)) / 2)")))
672 (define_predicate "aarch64_simd_umax_half_mode"
673 (and (match_code "const_vector")
674 (match_test "aarch64_const_vec_all_same_in_range_p (op,
676 << (GET_MODE_UNIT_BITSIZE (mode) / 2)) - 1,
678 << (GET_MODE_UNIT_BITSIZE (mode) / 2)) - 1)")))
680 (define_predicate "aarch64_simd_umax_quarter_mode"
681 (and (match_code "const_vector")
682 (match_test "aarch64_const_vec_all_same_in_range_p (op,
684 << (GET_MODE_UNIT_BITSIZE (mode) / 4)) - 1,
686 << (GET_MODE_UNIT_BITSIZE (mode) / 4)) - 1)")))
687 (define_predicate "aarch64_simd_shift_imm_vec_qi"
688 (and (match_code "const_vector")
689 (match_test "aarch64_const_vec_all_same_in_range_p (op, 1, 8)")))
691 (define_predicate "aarch64_simd_shift_imm_vec_hi"
692 (and (match_code "const_vector")
693 (match_test "aarch64_const_vec_all_same_in_range_p (op, 1, 16)")))
695 (define_predicate "aarch64_simd_shift_imm_vec_si"
696 (and (match_code "const_vector")
697 (match_test "aarch64_const_vec_all_same_in_range_p (op, 1, 32)")))
699 (define_predicate "aarch64_simd_shift_imm_vec_di"
700 (and (match_code "const_vector")
701 (match_test "aarch64_const_vec_all_same_in_range_p (op, 1, 64)")))
703 ;; A constant or vector of constants that represents an integer rounding
704 ;; constant added during fixed-point arithmetic calculations
705 (define_predicate "aarch64_int_rnd_operand"
706 (and (match_code "const_vector,const_int,const_wide_int")
707 (match_test "aarch64_rnd_imm_p (op)")))
709 (define_predicate "aarch64_simd_raddsubhn_imm_vec"
710 (and (match_code "const_vector")
711 (match_test "aarch64_const_vec_all_same_in_range_p (op, 1,
713 << (GET_MODE_UNIT_BITSIZE (mode) / 2 - 1))")))
715 (define_predicate "aarch64_simd_shll_imm_vec"
716 (and (match_code "const_vector")
717 (match_test "aarch64_const_vec_all_same_in_range_p (op, 0,
718 GET_MODE_UNIT_BITSIZE (mode) / 2)")))
720 (define_predicate "aarch64_simd_shift_imm_bitsize_qi"
721 (and (match_code "const_int")
722 (match_test "IN_RANGE (INTVAL (op), 0, 8)")))
724 (define_predicate "aarch64_simd_shift_imm_bitsize_hi"
725 (and (match_code "const_int")
726 (match_test "IN_RANGE (INTVAL (op), 0, 16)")))
728 (define_predicate "aarch64_simd_shift_imm_bitsize_si"
729 (and (match_code "const_int")
730 (match_test "IN_RANGE (INTVAL (op), 0, 32)")))
732 (define_predicate "aarch64_simd_shift_imm_bitsize_di"
733 (and (match_code "const_int")
734 (match_test "IN_RANGE (INTVAL (op), 0, 64)")))
736 (define_predicate "aarch64_constant_pool_symref"
737 (and (match_code "symbol_ref")
738 (match_test "CONSTANT_POOL_ADDRESS_P (op)")))
740 (define_predicate "aarch64_constant_vector_operand"
741 (match_code "const,const_vector"))
743 (define_predicate "aarch64_sve_ld1r_operand"
744 (and (match_operand 0 "memory_operand")
745 (match_test "aarch64_sve_ld1r_operand_p (op)")))
747 (define_predicate "aarch64_sve_ld1rq_operand"
748 (and (match_code "mem")
749 (match_test "aarch64_sve_ld1rq_operand_p (op)")))
751 (define_predicate "aarch64_sve_ld1ro_operand_b"
752 (and (match_code "mem")
753 (match_test "aarch64_sve_ld1ro_operand_p (op, QImode)")))
755 (define_predicate "aarch64_sve_ld1ro_operand_h"
756 (and (match_code "mem")
757 (match_test "aarch64_sve_ld1ro_operand_p (op, HImode)")))
759 (define_predicate "aarch64_sve_ld1ro_operand_w"
760 (and (match_code "mem")
761 (match_test "aarch64_sve_ld1ro_operand_p (op, SImode)")))
763 (define_predicate "aarch64_sve_ld1ro_operand_d"
764 (and (match_code "mem")
765 (match_test "aarch64_sve_ld1ro_operand_p (op, DImode)")))
767 (define_predicate "aarch64_sve_ldff1_operand"
768 (and (match_code "mem")
769 (match_test "aarch64_sve_ldff1_operand_p (op)")))
771 (define_predicate "aarch64_sve_ldnf1_operand"
772 (and (match_code "mem")
773 (match_test "aarch64_sve_ldnf1_operand_p (op)")))
775 ;; Like memory_operand, but restricted to addresses that are valid for
776 ;; SVE LDR and STR instructions.
777 (define_predicate "aarch64_sve_ldr_operand"
778 (and (match_code "mem")
779 (match_test "aarch64_sve_ldr_operand_p (op)")))
781 (define_special_predicate "aarch64_sve_prefetch_operand"
782 (and (match_code "reg, plus")
783 (match_test "aarch64_sve_prefetch_operand_p (op, mode)")))
785 (define_predicate "aarch64_sve_nonimmediate_operand"
786 (ior (match_operand 0 "register_operand")
787 (match_operand 0 "aarch64_sve_ldr_operand")))
789 (define_predicate "aarch64_sve_general_operand"
790 (and (match_code "reg,subreg,mem,const,const_vector")
791 (ior (match_operand 0 "register_operand")
792 (match_operand 0 "aarch64_sve_ldr_operand")
793 (match_test "aarch64_mov_operand_p (op, mode)"))))
795 (define_predicate "aarch64_sve_struct_memory_operand"
796 (and (match_code "mem")
797 (match_test "aarch64_sve_struct_memory_operand_p (op)")))
799 (define_predicate "aarch64_sve_struct_nonimmediate_operand"
800 (ior (match_operand 0 "register_operand")
801 (match_operand 0 "aarch64_sve_struct_memory_operand")))
803 ;; Doesn't include immediates, since those are handled by the move
805 (define_predicate "aarch64_sve_dup_operand"
806 (ior (match_operand 0 "register_operand")
807 (match_operand 0 "aarch64_sve_ld1r_operand")))
809 (define_predicate "aarch64_sve_ptrue_svpattern_immediate"
810 (and (match_code "const")
811 (match_test "aarch64_sve_ptrue_svpattern_p (op, NULL)")))
813 (define_predicate "aarch64_sve_arith_immediate"
814 (and (match_code "const,const_vector")
815 (match_test "aarch64_sve_arith_immediate_p (mode, op, false)")))
817 (define_predicate "aarch64_sve_sub_arith_immediate"
818 (and (match_code "const,const_vector")
819 (match_test "aarch64_sve_arith_immediate_p (mode, op, true)")))
821 (define_predicate "aarch64_sve_qadd_immediate"
822 (and (match_code "const,const_vector")
823 (match_test "aarch64_sve_sqadd_sqsub_immediate_p (mode, op, false)")))
825 (define_predicate "aarch64_sve_qsub_immediate"
826 (and (match_code "const,const_vector")
827 (match_test "aarch64_sve_sqadd_sqsub_immediate_p (mode, op, true)")))
829 (define_predicate "aarch64_sve_vector_inc_dec_immediate"
830 (and (match_code "const,const_vector")
831 (match_test "aarch64_sve_vector_inc_dec_immediate_p (op)")))
833 (define_predicate "aarch64_sve_gather_immediate_b"
834 (and (match_code "const_int")
835 (match_test "IN_RANGE (INTVAL (op), 0, 31)")))
837 (define_predicate "aarch64_sve_gather_immediate_h"
838 (and (match_code "const_int")
839 (match_test "IN_RANGE (INTVAL (op), 0, 62)")
840 (match_test "(INTVAL (op) & 1) == 0")))
842 (define_predicate "aarch64_sve_gather_immediate_w"
843 (and (match_code "const_int")
844 (match_test "IN_RANGE (INTVAL (op), 0, 124)")
845 (match_test "(INTVAL (op) & 3) == 0")))
847 (define_predicate "aarch64_sve_gather_immediate_d"
848 (and (match_code "const_int")
849 (match_test "IN_RANGE (INTVAL (op), 0, 248)")
850 (match_test "(INTVAL (op) & 7) == 0")))
852 (define_predicate "aarch64_sve_uxtb_immediate"
853 (and (match_code "const_vector")
854 (match_test "GET_MODE_UNIT_BITSIZE (GET_MODE (op)) > 8")
855 (match_test "aarch64_const_vec_all_same_int_p (op, 0xff)")))
857 (define_predicate "aarch64_sve_uxth_immediate"
858 (and (match_code "const_vector")
859 (match_test "GET_MODE_UNIT_BITSIZE (GET_MODE (op)) > 16")
860 (match_test "aarch64_const_vec_all_same_int_p (op, 0xffff)")))
862 (define_predicate "aarch64_sve_uxtw_immediate"
863 (and (match_code "const_vector")
864 (match_test "GET_MODE_UNIT_BITSIZE (GET_MODE (op)) > 32")
865 (match_test "aarch64_const_vec_all_same_int_p (op, 0xffffffff)")))
867 (define_predicate "aarch64_sve_uxt_immediate"
868 (ior (match_operand 0 "aarch64_sve_uxtb_immediate")
869 (match_operand 0 "aarch64_sve_uxth_immediate")
870 (match_operand 0 "aarch64_sve_uxtw_immediate")))
872 (define_predicate "aarch64_sve_logical_immediate"
873 (and (match_code "const,const_vector")
874 (match_test "aarch64_sve_bitmask_immediate_p (op)")))
876 ;; Used for SVE UMAX and UMIN.
877 (define_predicate "aarch64_sve_vsb_immediate"
878 (and (match_code "const_vector")
879 (match_test "GET_MODE_INNER (GET_MODE (op)) == QImode
880 ? aarch64_const_vec_all_same_in_range_p (op, -128, 127)
881 : aarch64_const_vec_all_same_in_range_p (op, 0, 255)")))
883 ;; Used for SVE MUL, SMAX and SMIN.
884 (define_predicate "aarch64_sve_vsm_immediate"
885 (and (match_code "const,const_vector")
886 (match_test "aarch64_const_vec_all_same_in_range_p (op, -128, 127)")))
888 (define_predicate "aarch64_sve_dup_immediate"
889 (and (match_code "const,const_vector")
890 (ior (match_test "aarch64_sve_dup_immediate_p (op)")
891 (match_test "aarch64_float_const_representable_p (op)"))))
893 (define_predicate "aarch64_sve_cmp_vsc_immediate"
894 (and (match_code "const_int,const_vector")
895 (match_test "aarch64_sve_cmp_immediate_p (op, true)")))
897 (define_predicate "aarch64_sve_cmp_vsd_immediate"
898 (and (match_code "const_int,const_vector")
899 (match_test "aarch64_sve_cmp_immediate_p (op, false)")))
901 (define_predicate "aarch64_sve_index_immediate"
902 (and (match_code "const_int")
903 (match_test "aarch64_sve_index_immediate_p (op)")))
905 (define_predicate "aarch64_sve_float_arith_immediate"
906 (and (match_code "const,const_vector")
907 (match_test "aarch64_sve_float_arith_immediate_p (op, false)")))
909 (define_predicate "aarch64_sve_float_negated_arith_immediate"
910 (and (match_code "const,const_vector")
911 (match_test "aarch64_sve_float_arith_immediate_p (op, true)")))
913 (define_predicate "aarch64_sve_float_arith_with_sub_immediate"
914 (ior (match_operand 0 "aarch64_sve_float_arith_immediate")
915 (match_operand 0 "aarch64_sve_float_negated_arith_immediate")))
917 (define_predicate "aarch64_sve_float_mul_immediate"
918 (and (match_code "const,const_vector")
919 (match_test "aarch64_sve_float_mul_immediate_p (op)")))
921 (define_predicate "aarch64_sve_float_maxmin_immediate"
922 (and (match_code "const_vector")
923 (ior (match_test "op == CONST0_RTX (GET_MODE (op))")
924 (match_test "op == CONST1_RTX (GET_MODE (op))"))))
926 (define_predicate "aarch64_sve_arith_operand"
927 (ior (match_operand 0 "register_operand")
928 (match_operand 0 "aarch64_sve_arith_immediate")))
930 (define_predicate "aarch64_sve_add_operand"
931 (ior (match_operand 0 "aarch64_sve_arith_operand")
932 (match_operand 0 "aarch64_sve_sub_arith_immediate")
933 (match_operand 0 "aarch64_sve_vector_inc_dec_immediate")))
935 (define_predicate "aarch64_sve_sqadd_operand"
936 (ior (match_operand 0 "register_operand")
937 (match_operand 0 "aarch64_sve_qadd_immediate")
938 (match_operand 0 "aarch64_sve_qsub_immediate")))
940 (define_predicate "aarch64_sve_pred_and_operand"
941 (ior (match_operand 0 "register_operand")
942 (match_operand 0 "aarch64_sve_uxt_immediate")))
944 (define_predicate "aarch64_sve_logical_operand"
945 (ior (match_operand 0 "register_operand")
946 (match_operand 0 "aarch64_sve_logical_immediate")))
948 (define_predicate "aarch64_orr_imm_sve_advsimd"
949 (ior (match_operand 0 "aarch64_reg_or_orr_imm")
950 (and (match_test "TARGET_SVE")
951 (match_operand 0 "aarch64_sve_logical_operand"))))
953 (define_predicate "aarch64_sve_gather_offset_b"
954 (ior (match_operand 0 "register_operand")
955 (match_operand 0 "aarch64_sve_gather_immediate_b")))
957 (define_predicate "aarch64_sve_gather_offset_h"
958 (ior (match_operand 0 "register_operand")
959 (match_operand 0 "aarch64_sve_gather_immediate_h")))
961 (define_predicate "aarch64_sve_gather_offset_w"
962 (ior (match_operand 0 "register_operand")
963 (match_operand 0 "aarch64_sve_gather_immediate_w")))
965 (define_predicate "aarch64_sve_gather_offset_d"
966 (ior (match_operand 0 "register_operand")
967 (match_operand 0 "aarch64_sve_gather_immediate_d")))
969 (define_predicate "aarch64_sve_lshift_operand"
970 (ior (match_operand 0 "register_operand")
971 (match_operand 0 "aarch64_simd_lshift_imm")))
973 (define_predicate "aarch64_sve_rshift_operand"
974 (ior (match_operand 0 "register_operand")
975 (match_operand 0 "aarch64_simd_rshift_imm")))
977 (define_predicate "aarch64_sve_vsb_operand"
978 (ior (match_operand 0 "register_operand")
979 (match_operand 0 "aarch64_sve_vsb_immediate")))
981 (define_predicate "aarch64_sve_vsm_operand"
982 (ior (match_operand 0 "register_operand")
983 (match_operand 0 "aarch64_sve_vsm_immediate")))
985 (define_predicate "aarch64_sve_reg_or_dup_imm"
986 (ior (match_operand 0 "register_operand")
987 (match_operand 0 "aarch64_sve_dup_immediate")))
989 (define_predicate "aarch64_sve_cmp_vsc_operand"
990 (ior (match_operand 0 "register_operand")
991 (match_operand 0 "aarch64_sve_cmp_vsc_immediate")))
993 (define_predicate "aarch64_sve_cmp_vsd_operand"
994 (ior (match_operand 0 "register_operand")
995 (match_operand 0 "aarch64_sve_cmp_vsd_immediate")))
997 (define_predicate "aarch64_sve_index_operand"
998 (ior (match_operand 0 "register_operand")
999 (match_operand 0 "aarch64_sve_index_immediate")))
1001 (define_predicate "aarch64_sve_float_arith_operand"
1002 (ior (match_operand 0 "register_operand")
1003 (match_operand 0 "aarch64_sve_float_arith_immediate")))
1005 (define_predicate "aarch64_sve_float_arith_with_sub_operand"
1006 (ior (match_operand 0 "register_operand")
1007 (match_operand 0 "aarch64_sve_float_arith_with_sub_immediate")))
1009 (define_predicate "aarch64_sve_float_mul_operand"
1010 (ior (match_operand 0 "register_operand")
1011 (match_operand 0 "aarch64_sve_float_mul_immediate")))
1013 (define_predicate "aarch64_sve_float_maxmin_operand"
1014 (ior (match_operand 0 "register_operand")
1015 (match_operand 0 "aarch64_sve_float_maxmin_immediate")))
1017 (define_predicate "aarch64_sve_vec_perm_operand"
1018 (ior (match_operand 0 "register_operand")
1019 (match_operand 0 "aarch64_constant_vector_operand")))
1021 (define_predicate "aarch64_sve_ptrue_flag"
1022 (and (match_code "const_int")
1023 (ior (match_test "INTVAL (op) == SVE_MAYBE_NOT_PTRUE")
1024 (match_test "INTVAL (op) == SVE_KNOWN_PTRUE"))))
1026 (define_predicate "aarch64_sve_gp_strictness"
1027 (and (match_code "const_int")
1028 (ior (match_test "INTVAL (op) == SVE_RELAXED_GP")
1029 (match_test "INTVAL (op) == SVE_STRICT_GP"))))
1031 (define_predicate "aarch64_gather_scale_operand_b"
1032 (and (match_code "const_int")
1033 (match_test "INTVAL (op) == 1")))
1035 (define_predicate "aarch64_gather_scale_operand_h"
1036 (and (match_code "const_int")
1037 (match_test "INTVAL (op) == 1 || INTVAL (op) == 2")))
1039 (define_predicate "aarch64_gather_scale_operand_w"
1040 (and (match_code "const_int")
1041 (match_test "INTVAL (op) == 1 || INTVAL (op) == 4")))
1043 (define_predicate "aarch64_gather_scale_operand_d"
1044 (and (match_code "const_int")
1045 (match_test "INTVAL (op) == 1 || INTVAL (op) == 8")))
1047 ;; A special predicate that doesn't match a particular mode.
1048 (define_special_predicate "aarch64_any_register_operand"
1051 (define_predicate "aarch64_sve_any_binary_operator"
1052 (match_code "plus,minus,mult,div,udiv,smax,umax,smin,umin,and,ior,xor"))
1054 (define_predicate "aarch64_bytes_per_sve_vector_operand"
1055 (and (match_code "const_int,const_poly_int")
1056 (match_test "known_eq (wi::to_poly_wide (op, mode),
1057 BYTES_PER_SVE_VECTOR)")))
1059 (define_predicate "aarch64_memtag_tag_offset"
1060 (and (match_code "const_int")
1061 (match_test "IN_RANGE (INTVAL (op), 0, 15)")))
1063 (define_predicate "aarch64_granule16_uimm6"
1064 (and (match_code "const_int")
1065 (match_test "IN_RANGE (INTVAL (op), 0, 1008)
1066 && !(INTVAL (op) & 0xf)")))
1068 (define_predicate "aarch64_granule16_simm9"
1069 (and (match_code "const_int")
1070 (match_test "IN_RANGE (INTVAL (op), -4096, 4080)
1071 && !(INTVAL (op) & 0xf)")))