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_orr_imm (op)"))))
123 (define_predicate "aarch64_reg_or_and_imm"
124 (ior (match_operand 0 "register_operand")
125 (and (match_code "const_vector")
126 (match_test "aarch64_simd_valid_and_imm (op)"))))
128 (define_predicate "aarch64_reg_or_xor_imm"
129 (ior (match_operand 0 "register_operand")
130 (and (match_code "const_vector")
131 (match_test "aarch64_simd_valid_xor_imm (op)"))))
133 (define_predicate "aarch64_fp_compare_operand"
134 (ior (match_operand 0 "register_operand")
135 (and (match_code "const_double")
136 (match_test "aarch64_float_const_zero_rtx_p (op)"))))
138 (define_predicate "aarch64_fp_pow2"
139 (and (match_code "const_double")
140 (match_test "aarch64_fpconst_pow_of_2 (op) > 0")))
142 (define_predicate "aarch64_fp_pow2_recip"
143 (and (match_code "const_double")
144 (match_test "aarch64_fpconst_pow2_recip (op) > 0")))
146 (define_predicate "aarch64_fp_vec_pow2"
147 (match_test "aarch64_vec_fpconst_pow_of_2 (op) > 0"))
149 (define_predicate "aarch64_sve_cnt_immediate"
150 (and (match_code "const_poly_int")
151 (match_test "aarch64_sve_cnt_immediate_p (op)")))
153 (define_predicate "aarch64_sub_immediate"
154 (and (match_code "const_int")
155 (match_test "aarch64_uimm12_shift (-UINTVAL (op))")))
157 (define_predicate "aarch64_plus_immediate"
158 (and (match_code "const_int")
159 (ior (match_test "aarch64_uimm12_shift (INTVAL (op))")
160 (match_test "aarch64_uimm12_shift (-UINTVAL (op))"))))
162 (define_predicate "aarch64_plus_operand"
163 (ior (match_operand 0 "register_operand")
164 (match_operand 0 "aarch64_plus_immediate")))
166 (define_predicate "aarch64_plushi_immediate"
167 (match_code "const_int")
169 HOST_WIDE_INT val = INTVAL (op);
170 /* The HImode value must be zero-extendable to an SImode plus_operand. */
171 return ((val & 0xfff) == val || sext_hwi (val & 0xf000, 16) == val);
174 (define_predicate "aarch64_plushi_operand"
175 (ior (match_operand 0 "register_operand")
176 (match_operand 0 "aarch64_plushi_immediate")))
178 (define_predicate "aarch64_pluslong_immediate"
179 (and (match_code "const_int")
180 (match_test "IN_RANGE (INTVAL (op), -0xffffff, 0xffffff)")))
182 (define_predicate "aarch64_sminmax_immediate"
183 (and (match_code "const_int")
184 (match_test "IN_RANGE (INTVAL (op), -128, 127)")))
186 (define_predicate "aarch64_sminmax_operand"
187 (ior (match_operand 0 "register_operand")
188 (match_operand 0 "aarch64_sminmax_immediate")))
190 (define_predicate "aarch64_uminmax_immediate"
191 (and (match_code "const_int")
192 (match_test "IN_RANGE (INTVAL (op), 0, 255)")))
194 (define_predicate "aarch64_uminmax_operand"
195 (ior (match_operand 0 "register_operand")
196 (match_operand 0 "aarch64_uminmax_immediate")))
198 (define_predicate "aarch64_pluslong_strict_immedate"
199 (and (match_operand 0 "aarch64_pluslong_immediate")
200 (not (match_operand 0 "aarch64_plus_immediate"))))
202 (define_predicate "aarch64_sve_scalar_inc_dec_immediate"
203 (and (match_code "const_poly_int")
204 (match_test "aarch64_sve_scalar_inc_dec_immediate_p (op)")))
206 (define_predicate "aarch64_sve_addvl_addpl_immediate"
207 (and (match_code "const_poly_int")
208 (match_test "aarch64_sve_addvl_addpl_immediate_p (op)")))
210 (define_predicate "aarch64_sve_plus_immediate"
211 (ior (match_operand 0 "aarch64_sve_scalar_inc_dec_immediate")
212 (match_operand 0 "aarch64_sve_addvl_addpl_immediate")))
214 (define_predicate "aarch64_split_add_offset_immediate"
215 (and (match_code "const_poly_int")
216 (match_test "aarch64_add_offset_temporaries (op) == 1")))
218 (define_predicate "aarch64_addsvl_addspl_immediate"
219 (and (match_code "const")
220 (match_test "aarch64_addsvl_addspl_immediate_p (op)")))
222 (define_predicate "aarch64_pluslong_operand"
223 (ior (match_operand 0 "register_operand")
224 (match_operand 0 "aarch64_pluslong_immediate")
225 (and (match_test "TARGET_SVE")
226 (match_operand 0 "aarch64_sve_plus_immediate"))
227 (and (match_test "TARGET_SME")
228 (match_operand 0 "aarch64_addsvl_addspl_immediate"))))
230 (define_predicate "aarch64_pluslong_or_poly_operand"
231 (ior (match_operand 0 "aarch64_pluslong_operand")
232 (match_operand 0 "aarch64_split_add_offset_immediate")))
234 (define_predicate "aarch64_logical_immediate"
235 (and (match_code "const_int")
236 (match_test "aarch64_bitmask_imm (INTVAL (op), mode)")))
238 (define_predicate "aarch64_logical_operand"
239 (ior (match_operand 0 "register_operand")
240 (match_operand 0 "aarch64_logical_immediate")))
242 (define_predicate "aarch64_mov_imm_operand"
243 (and (match_code "const_int")
244 (match_test "aarch64_move_imm (INTVAL (op), mode)")))
246 (define_predicate "aarch64_logical_and_immediate"
247 (and (match_code "const_int")
248 (match_test "aarch64_and_bitmask_imm (INTVAL (op), mode)")))
250 (define_predicate "aarch64_shift_imm_si"
251 (and (match_code "const_int")
252 (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) < 32")))
254 (define_predicate "aarch64_shift_imm_di"
255 (and (match_code "const_int")
256 (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) < 64")))
258 (define_predicate "aarch64_shift_imm64_di"
259 (and (match_code "const_int")
260 (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) <= 64")))
262 (define_predicate "aarch64_reg_or_shift_imm_si"
263 (ior (match_operand 0 "register_operand")
264 (match_operand 0 "aarch64_shift_imm_si")))
266 (define_predicate "aarch64_reg_or_shift_imm_di"
267 (ior (match_operand 0 "register_operand")
268 (match_operand 0 "aarch64_shift_imm_di")))
270 ;; The imm3 field is a 3-bit field that only accepts immediates in the
272 (define_predicate "aarch64_imm3"
273 (and (match_code "const_int")
274 (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) <= 4")))
276 ;; The imm2 field is a 2-bit field that only accepts immediates in the
278 (define_predicate "aarch64_imm2"
279 (and (match_code "const_int")
280 (match_test "UINTVAL (op) <= 3")))
282 ;; The imm3 field is a 3-bit field that only accepts immediates in the
284 (define_predicate "aarch64_lane_imm3"
285 (and (match_code "const_int")
286 (match_test "UINTVAL (op) <= 7")))
288 ;; An immediate that fits into 24 bits.
289 (define_predicate "aarch64_imm24"
290 (and (match_code "const_int")
291 (match_test "IN_RANGE (UINTVAL (op), 0, 0xffffff)")))
293 (define_predicate "aarch64_mem_pair_offset"
294 (and (match_code "const_int")
295 (match_test "aarch64_offset_7bit_signed_scaled_p (mode, INTVAL (op))")))
297 (define_special_predicate "aarch64_mem_pair_operator"
300 (match_test "aarch64_ldpstp_operand_mode_p (GET_MODE (op))")
302 (match_test "mode == VOIDmode")
303 (match_test "known_eq (GET_MODE_SIZE (mode),
304 GET_MODE_SIZE (GET_MODE (op)))"))))
306 ;; Like aarch64_mem_pair_operator, but additionally check the
307 ;; address is suitable.
308 (define_special_predicate "aarch64_mem_pair_operand"
309 (and (match_operand 0 "aarch64_mem_pair_operator")
310 (match_test "aarch64_legitimate_address_p (GET_MODE (op), XEXP (op, 0),
311 false, ADDR_QUERY_LDP_STP)")))
313 (define_predicate "pmode_plus_operator"
314 (and (match_code "plus")
315 (match_test "GET_MODE (op) == Pmode")))
317 (define_special_predicate "aarch64_ldp_reg_operand"
322 (match_code "subreg")
323 (match_test "REG_P (SUBREG_REG (op))")))
324 (match_test "aarch64_ldpstp_operand_mode_p (GET_MODE (op))")
326 (match_test "mode == VOIDmode")
327 (match_test "known_eq (GET_MODE_SIZE (mode),
328 GET_MODE_SIZE (GET_MODE (op)))"))))
330 (define_special_predicate "aarch64_stp_reg_operand"
331 (ior (match_operand 0 "aarch64_ldp_reg_operand")
332 (and (match_code "const_int,const,const_vector,const_double")
333 (match_test "aarch64_const_zero_rtx_p (op)")
335 (match_test "GET_MODE (op) == VOIDmode")
337 (match_test "aarch64_ldpstp_operand_mode_p (GET_MODE (op))")
339 (match_test "mode == VOIDmode")
340 (match_test "known_eq (GET_MODE_SIZE (mode),
341 GET_MODE_SIZE (GET_MODE (op)))")))))))
343 ;; Used for storing two 64-bit values in an AdvSIMD register using an STP
344 ;; as a 128-bit vec_concat.
345 (define_predicate "aarch64_mem_pair_lanes_operand"
346 (and (match_code "mem")
347 (match_test "aarch64_legitimate_address_p (GET_MODE (op), XEXP (op, 0),
349 ADDR_QUERY_LDP_STP_N)")))
351 (define_predicate "aarch64_reg_or_mem_pair_operand"
352 (ior (match_operand 0 "register_operand")
353 (match_operand 0 "aarch64_mem_pair_lanes_operand")))
355 (define_predicate "aarch64_prefetch_operand"
356 (match_test "aarch64_address_valid_for_prefetch_p (op, false)"))
358 (define_predicate "aarch64_valid_symref"
359 (match_code "const, symbol_ref, label_ref")
361 return (aarch64_classify_symbolic_expression (op)
362 != SYMBOL_FORCE_TO_MEM);
365 (define_predicate "aarch64_tls_ie_symref"
366 (match_code "const, symbol_ref, label_ref")
368 switch (GET_CODE (op))
372 if (GET_CODE (op) != PLUS
373 || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
374 || GET_CODE (XEXP (op, 1)) != CONST_INT)
380 return SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_INITIAL_EXEC;
387 (define_predicate "aarch64_tls_le_symref"
388 (match_code "const, symbol_ref, label_ref")
390 switch (GET_CODE (op))
394 if (GET_CODE (op) != PLUS
395 || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
396 || GET_CODE (XEXP (op, 1)) != CONST_INT)
402 return SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_EXEC;
409 (define_predicate "aarch64_mov_operand"
410 (and (match_code "reg,subreg,mem,const,const_int,symbol_ref,label_ref,high,
411 const_poly_int,const_vector")
412 (ior (match_operand 0 "register_operand")
413 (ior (match_operand 0 "memory_operand")
414 (match_test "aarch64_mov_operand_p (op, mode)")))))
416 (define_predicate "aarch64_nonmemory_operand"
417 (and (match_code "reg,subreg,const,const_int,symbol_ref,label_ref,high,
418 const_poly_int,const_vector")
419 (ior (match_operand 0 "register_operand")
420 (match_test "aarch64_mov_operand_p (op, mode)"))))
422 (define_predicate "aarch64_movti_operand"
423 (ior (match_operand 0 "register_operand")
424 (match_operand 0 "memory_operand")
425 (and (match_operand 0 "const_scalar_int_operand")
426 (match_test "aarch64_mov128_immediate (op)"))))
428 (define_predicate "aarch64_reg_or_imm"
429 (ior (match_operand 0 "register_operand")
430 (match_operand 0 "const_scalar_int_operand")))
432 ;; True for integer comparisons and for FP comparisons other than LTGT or UNEQ.
433 (define_special_predicate "aarch64_comparison_operator"
434 (match_code "eq,ne,le,lt,ge,gt,geu,gtu,leu,ltu,unordered,
435 ordered,unlt,unle,unge,ungt"))
437 ;; Same as aarch64_comparison_operator but don't ignore the mode.
438 ;; RTL SET operations require their operands source and destination have
439 ;; the same modes, so we can't ignore the modes there. See PR target/69161.
440 (define_predicate "aarch64_comparison_operator_mode"
441 (match_code "eq,ne,le,lt,ge,gt,geu,gtu,leu,ltu,unordered,
442 ordered,unlt,unle,unge,ungt"))
444 (define_special_predicate "aarch64_comparison_operation"
445 (match_code "eq,ne,le,lt,ge,gt,geu,gtu,leu,ltu,unordered,
446 ordered,unlt,unle,unge,ungt")
448 if (XEXP (op, 1) != const0_rtx)
450 rtx op0 = XEXP (op, 0);
451 if (!REG_P (op0) || REGNO (op0) != CC_REGNUM)
453 return aarch64_get_condition_code (op) >= 0;
456 (define_special_predicate "aarch64_equality_operator"
457 (match_code "eq,ne"))
459 (define_special_predicate "aarch64_carry_operation"
460 (match_code "ltu,geu")
462 if (XEXP (op, 1) != const0_rtx)
464 rtx op0 = XEXP (op, 0);
465 if (!REG_P (op0) || REGNO (op0) != CC_REGNUM)
467 machine_mode ccmode = GET_MODE (op0);
468 if (ccmode == CC_Cmode)
469 return GET_CODE (op) == LTU;
470 if (ccmode == CC_ADCmode || ccmode == CCmode)
471 return GET_CODE (op) == GEU;
475 ; borrow is essentially the inverse of carry since the sense of the C flag
476 ; is inverted during subtraction. See the note in aarch64-modes.def.
477 (define_special_predicate "aarch64_borrow_operation"
478 (match_code "geu,ltu")
480 if (XEXP (op, 1) != const0_rtx)
482 rtx op0 = XEXP (op, 0);
483 if (!REG_P (op0) || REGNO (op0) != CC_REGNUM)
485 machine_mode ccmode = GET_MODE (op0);
486 if (ccmode == CC_Cmode)
487 return GET_CODE (op) == GEU;
488 if (ccmode == CC_ADCmode || ccmode == CCmode)
489 return GET_CODE (op) == LTU;
493 ;; True if the operand is memory reference suitable for a load/store exclusive.
494 (define_predicate "aarch64_sync_memory_operand"
495 (and (match_operand 0 "memory_operand")
496 (match_code "reg" "0")))
498 (define_predicate "aarch64_9bit_offset_memory_operand"
499 (and (match_operand 0 "memory_operand")
500 (ior (match_code "reg" "0")
501 (and (match_code "plus" "0")
502 (match_code "reg" "00")
503 (match_code "const_int" "01"))))
505 rtx mem_op = XEXP (op, 0);
508 return GET_MODE (mem_op) == DImode;
510 rtx plus_op0 = XEXP (mem_op, 0);
511 rtx plus_op1 = XEXP (mem_op, 1);
513 if (GET_MODE (plus_op0) != DImode)
517 if (!poly_int_rtx_p (plus_op1, &offset))
520 return aarch64_offset_9bit_signed_unscaled_p (mode, offset);
523 (define_predicate "aarch64_rcpc_memory_operand"
524 (if_then_else (match_test "TARGET_RCPC2")
525 (match_operand 0 "aarch64_9bit_offset_memory_operand")
526 (match_operand 0 "aarch64_sync_memory_operand")))
528 ;; Predicates for parallel expanders based on mode.
529 (define_special_predicate "vect_par_cnst_hi_half"
530 (match_code "parallel")
532 return aarch64_simd_check_vect_par_cnst_half (op, mode, true);
535 (define_special_predicate "vect_par_cnst_lo_half"
536 (match_code "parallel")
538 return aarch64_simd_check_vect_par_cnst_half (op, mode, false);
541 ;; PARALLEL for a vec_select that selects all the even or all the odd
542 ;; elements of a vector of MODE.
543 (define_special_predicate "vect_par_cnst_even_or_odd_half"
544 (match_code "parallel")
546 int nunits = XVECLEN (op, 0);
547 if (!known_eq (GET_MODE_NUNITS (mode), nunits * 2))
549 rtx first = XVECEXP (op, 0, 0);
550 if (!CONST_INT_P (first))
552 return (INTVAL (first) == 0 || INTVAL (first) == 1)
553 && aarch64_stepped_int_parallel_p (op, 2);
556 ;; PARALLEL for a vec_select that selects half the elements in a vector of
557 ;; MODE. Allows any combination of elements, as long as there's no
558 ;; duplicate entries.
559 (define_special_predicate "vect_par_cnst_select_half"
560 (match_code "parallel")
562 return aarch64_parallel_select_half_p (mode, op);
565 (define_predicate "descending_int_parallel"
566 (match_code "parallel")
568 return aarch64_stepped_int_parallel_p (op, -1);
571 (define_predicate "ascending_int_parallel"
572 (match_code "parallel")
574 return aarch64_stepped_int_parallel_p (op, 1);
577 (define_special_predicate "aarch64_simd_lshift_imm"
578 (match_code "const,const_vector")
580 return aarch64_simd_shift_imm_p (op, mode, true);
583 (define_special_predicate "aarch64_simd_rshift_imm"
584 (match_code "const,const_vector")
586 return aarch64_simd_shift_imm_p (op, mode, false);
589 (define_predicate "aarch64_simd_imm_zero"
590 (and (match_code "const,const_vector")
591 (match_test "op == CONST0_RTX (GET_MODE (op))")))
593 (define_predicate "aarch64_simd_imm_one"
594 (and (match_code "const_vector")
595 (match_test "op == CONST1_RTX (GET_MODE (op))")))
597 (define_predicate "aarch64_simd_or_scalar_imm_zero"
598 (and (match_code "const_int,const_double,const,const_vector")
599 (match_test "op == CONST0_RTX (GET_MODE (op))")))
601 (define_predicate "aarch64_simd_imm_minus_one"
602 (and (match_code "const,const_vector")
603 (match_test "op == CONSTM1_RTX (GET_MODE (op))")))
605 (define_predicate "aarch64_simd_reg_or_zero"
606 (and (match_code "reg,subreg,const_int,const_double,const,const_vector")
607 (ior (match_operand 0 "register_operand")
608 (match_test "op == const0_rtx")
609 (match_operand 0 "aarch64_simd_or_scalar_imm_zero"))))
611 (define_predicate "aarch64_simd_reg_or_minus_one"
612 (ior (match_operand 0 "register_operand")
613 (match_operand 0 "aarch64_simd_imm_minus_one")))
615 (define_predicate "aarch64_simd_struct_operand"
616 (and (match_code "mem")
617 (match_test "TARGET_SIMD && aarch64_simd_mem_operand_p (op)")))
619 ;; Like general_operand but allow only valid SIMD addressing modes.
620 (define_predicate "aarch64_simd_general_operand"
621 (and (match_operand 0 "general_operand")
622 (match_test "!MEM_P (op)
623 || GET_CODE (XEXP (op, 0)) == POST_INC
624 || GET_CODE (XEXP (op, 0)) == REG")))
626 ;; Like nonimmediate_operand but allow only valid SIMD addressing modes.
627 (define_predicate "aarch64_simd_nonimmediate_operand"
628 (and (match_operand 0 "nonimmediate_operand")
629 (match_test "!MEM_P (op)
630 || GET_CODE (XEXP (op, 0)) == POST_INC
631 || GET_CODE (XEXP (op, 0)) == REG")))
633 ;; Predicates used by the various SIMD shift operations. These
634 ;; fall in to 3 categories.
635 ;; Shifts with a range 0-(bit_size - 1) (aarch64_simd_shift_imm)
636 ;; Shifts with a range 1-bit_size (aarch64_simd_shift_imm_offset)
637 ;; Shifts with a range 0-bit_size (aarch64_simd_shift_imm_bitsize)
638 (define_predicate "aarch64_simd_shift_imm_qi"
639 (match_operand 0 "const_0_to_7_operand"))
641 (define_predicate "aarch64_simd_shift_imm_hi"
642 (and (match_code "const_int")
643 (match_test "IN_RANGE (INTVAL (op), 0, 15)")))
645 (define_predicate "aarch64_simd_shift_imm_si"
646 (and (match_code "const_int")
647 (match_test "IN_RANGE (INTVAL (op), 0, 31)")))
649 (define_predicate "aarch64_simd_shift_imm_di"
650 (and (match_code "const_int")
651 (match_test "IN_RANGE (INTVAL (op), 0, 63)")))
653 (define_predicate "aarch64_simd_shift_imm_offset_qi"
654 (and (match_code "const_int")
655 (match_test "IN_RANGE (INTVAL (op), 1, 8)")))
657 (define_predicate "aarch64_simd_shift_imm_offset_hi"
658 (and (match_code "const_int")
659 (match_test "IN_RANGE (INTVAL (op), 1, 16)")))
661 (define_predicate "aarch64_simd_shift_imm_offset_si"
662 (and (match_code "const_int")
663 (match_test "IN_RANGE (INTVAL (op), 1, 32)")))
665 (define_predicate "aarch64_simd_shift_imm_offset_di"
666 (and (match_code "const_int")
667 (match_test "IN_RANGE (INTVAL (op), 1, 64)")))
669 (define_predicate "aarch64_simd_shift_imm_vec_exact_top"
670 (and (match_code "const_vector")
671 (match_test "aarch64_const_vec_all_same_in_range_p (op,
672 GET_MODE_UNIT_BITSIZE (GET_MODE (op)) / 2,
673 GET_MODE_UNIT_BITSIZE (GET_MODE (op)) / 2)")))
675 (define_predicate "aarch64_simd_umax_half_mode"
676 (and (match_code "const_vector")
677 (match_test "aarch64_const_vec_all_same_in_range_p (op,
679 << (GET_MODE_UNIT_BITSIZE (mode) / 2)) - 1,
681 << (GET_MODE_UNIT_BITSIZE (mode) / 2)) - 1)")))
683 (define_predicate "aarch64_simd_umax_quarter_mode"
684 (and (match_code "const_vector")
685 (match_test "aarch64_const_vec_all_same_in_range_p (op,
687 << (GET_MODE_UNIT_BITSIZE (mode) / 4)) - 1,
689 << (GET_MODE_UNIT_BITSIZE (mode) / 4)) - 1)")))
690 (define_predicate "aarch64_simd_shift_imm_vec_qi"
691 (and (match_code "const_vector")
692 (match_test "aarch64_const_vec_all_same_in_range_p (op, 1, 8)")))
694 (define_predicate "aarch64_simd_shift_imm_vec_hi"
695 (and (match_code "const_vector")
696 (match_test "aarch64_const_vec_all_same_in_range_p (op, 1, 16)")))
698 (define_predicate "aarch64_simd_shift_imm_vec_si"
699 (and (match_code "const_vector")
700 (match_test "aarch64_const_vec_all_same_in_range_p (op, 1, 32)")))
702 (define_predicate "aarch64_simd_shift_imm_vec_di"
703 (and (match_code "const_vector")
704 (match_test "aarch64_const_vec_all_same_in_range_p (op, 1, 64)")))
706 ;; A constant or vector of constants that represents an integer rounding
707 ;; constant added during fixed-point arithmetic calculations
708 (define_predicate "aarch64_int_rnd_operand"
709 (and (match_code "const_vector,const_int,const_wide_int")
710 (match_test "aarch64_rnd_imm_p (op)")))
712 (define_predicate "aarch64_simd_raddsubhn_imm_vec"
713 (and (match_code "const_vector")
714 (match_test "aarch64_const_vec_all_same_in_range_p (op, 1,
716 << (GET_MODE_UNIT_BITSIZE (mode) / 2 - 1))")))
718 (define_predicate "aarch64_simd_shll_imm_vec"
719 (and (match_code "const_vector")
720 (match_test "aarch64_const_vec_all_same_in_range_p (op, 0,
721 GET_MODE_UNIT_BITSIZE (mode) / 2)")))
723 (define_predicate "aarch64_simd_shift_imm_bitsize_qi"
724 (and (match_code "const_int")
725 (match_test "IN_RANGE (INTVAL (op), 0, 8)")))
727 (define_predicate "aarch64_simd_shift_imm_bitsize_hi"
728 (and (match_code "const_int")
729 (match_test "IN_RANGE (INTVAL (op), 0, 16)")))
731 (define_predicate "aarch64_simd_shift_imm_bitsize_si"
732 (and (match_code "const_int")
733 (match_test "IN_RANGE (INTVAL (op), 0, 32)")))
735 (define_predicate "aarch64_simd_shift_imm_bitsize_di"
736 (and (match_code "const_int")
737 (match_test "IN_RANGE (INTVAL (op), 0, 64)")))
739 (define_predicate "aarch64_constant_pool_symref"
740 (and (match_code "symbol_ref")
741 (match_test "CONSTANT_POOL_ADDRESS_P (op)")))
743 (define_predicate "aarch64_constant_vector_operand"
744 (match_code "const,const_vector"))
746 (define_predicate "aarch64_sve_ld1r_operand"
747 (and (match_operand 0 "memory_operand")
748 (match_test "aarch64_sve_ld1r_operand_p (op)")))
750 (define_predicate "aarch64_sve_ld1rq_operand"
751 (and (match_code "mem")
752 (match_test "aarch64_sve_ld1rq_operand_p (op)")))
754 (define_predicate "aarch64_sve_ld1ro_operand_b"
755 (and (match_code "mem")
756 (match_test "aarch64_sve_ld1ro_operand_p (op, QImode)")))
758 (define_predicate "aarch64_sve_ld1ro_operand_h"
759 (and (match_code "mem")
760 (match_test "aarch64_sve_ld1ro_operand_p (op, HImode)")))
762 (define_predicate "aarch64_sve_ld1ro_operand_w"
763 (and (match_code "mem")
764 (match_test "aarch64_sve_ld1ro_operand_p (op, SImode)")))
766 (define_predicate "aarch64_sve_ld1ro_operand_d"
767 (and (match_code "mem")
768 (match_test "aarch64_sve_ld1ro_operand_p (op, DImode)")))
770 (define_predicate "aarch64_sve_ldff1_operand"
771 (and (match_code "mem")
772 (match_test "aarch64_sve_ldff1_operand_p (op)")))
774 (define_predicate "aarch64_sve_ldnf1_operand"
775 (and (match_code "mem")
776 (match_test "aarch64_sve_ldnf1_operand_p (op)")))
778 ;; Like memory_operand, but restricted to addresses that are valid for
779 ;; SVE LDR and STR instructions.
780 (define_predicate "aarch64_sve_ldr_operand"
781 (and (match_code "mem")
782 (match_test "aarch64_sve_ldr_operand_p (op)")))
784 (define_special_predicate "aarch64_sve_prefetch_operand"
785 (and (match_code "reg, plus")
786 (match_test "aarch64_sve_prefetch_operand_p (op, mode)")))
788 (define_predicate "aarch64_sve_nonimmediate_operand"
789 (ior (match_operand 0 "register_operand")
790 (match_operand 0 "aarch64_sve_ldr_operand")))
792 (define_predicate "aarch64_sve_general_operand"
793 (and (match_code "reg,subreg,mem,const,const_vector")
794 (ior (match_operand 0 "register_operand")
795 (match_operand 0 "aarch64_sve_ldr_operand")
796 (match_test "aarch64_mov_operand_p (op, mode)"))))
798 (define_predicate "aarch64_sve_struct_memory_operand"
799 (and (match_code "mem")
800 (match_test "aarch64_sve_struct_memory_operand_p (op)")))
802 (define_predicate "aarch64_sve_struct_nonimmediate_operand"
803 (ior (match_operand 0 "register_operand")
804 (match_operand 0 "aarch64_sve_struct_memory_operand")))
806 ;; Doesn't include immediates, since those are handled by the move
808 (define_predicate "aarch64_sve_dup_operand"
809 (ior (match_operand 0 "register_operand")
810 (match_operand 0 "aarch64_sve_ld1r_operand")))
812 (define_predicate "aarch64_sve_ptrue_svpattern_immediate"
813 (and (match_code "const")
814 (match_test "aarch64_sve_ptrue_svpattern_p (op, NULL)")))
816 (define_predicate "aarch64_sve_arith_immediate"
817 (and (match_code "const,const_vector")
818 (match_test "aarch64_sve_arith_immediate_p (mode, op, false)")))
820 (define_predicate "aarch64_sve_sub_arith_immediate"
821 (and (match_code "const,const_vector")
822 (match_test "aarch64_sve_arith_immediate_p (mode, op, true)")))
824 (define_predicate "aarch64_sve_qadd_immediate"
825 (and (match_code "const,const_vector")
826 (match_test "aarch64_sve_sqadd_sqsub_immediate_p (mode, op, false)")))
828 (define_predicate "aarch64_sve_qsub_immediate"
829 (and (match_code "const,const_vector")
830 (match_test "aarch64_sve_sqadd_sqsub_immediate_p (mode, op, true)")))
832 (define_predicate "aarch64_sve_vector_inc_dec_immediate"
833 (and (match_code "const,const_vector")
834 (match_test "aarch64_sve_vector_inc_dec_immediate_p (op)")))
836 (define_predicate "aarch64_sve_gather_immediate_b"
837 (and (match_code "const_int")
838 (match_test "IN_RANGE (INTVAL (op), 0, 31)")))
840 (define_predicate "aarch64_sve_gather_immediate_h"
841 (and (match_code "const_int")
842 (match_test "IN_RANGE (INTVAL (op), 0, 62)")
843 (match_test "(INTVAL (op) & 1) == 0")))
845 (define_predicate "aarch64_sve_gather_immediate_w"
846 (and (match_code "const_int")
847 (match_test "IN_RANGE (INTVAL (op), 0, 124)")
848 (match_test "(INTVAL (op) & 3) == 0")))
850 (define_predicate "aarch64_sve_gather_immediate_d"
851 (and (match_code "const_int")
852 (match_test "IN_RANGE (INTVAL (op), 0, 248)")
853 (match_test "(INTVAL (op) & 7) == 0")))
855 (define_predicate "aarch64_sve_uxtb_immediate"
856 (and (match_code "const_vector")
857 (match_test "GET_MODE_UNIT_BITSIZE (GET_MODE (op)) > 8")
858 (match_test "aarch64_const_vec_all_same_int_p (op, 0xff)")))
860 (define_predicate "aarch64_sve_uxth_immediate"
861 (and (match_code "const_vector")
862 (match_test "GET_MODE_UNIT_BITSIZE (GET_MODE (op)) > 16")
863 (match_test "aarch64_const_vec_all_same_int_p (op, 0xffff)")))
865 (define_predicate "aarch64_sve_uxtw_immediate"
866 (and (match_code "const_vector")
867 (match_test "GET_MODE_UNIT_BITSIZE (GET_MODE (op)) > 32")
868 (match_test "aarch64_const_vec_all_same_int_p (op, 0xffffffff)")))
870 (define_predicate "aarch64_sve_uxt_immediate"
871 (ior (match_operand 0 "aarch64_sve_uxtb_immediate")
872 (match_operand 0 "aarch64_sve_uxth_immediate")
873 (match_operand 0 "aarch64_sve_uxtw_immediate")))
875 (define_predicate "aarch64_sve_logical_immediate"
876 (and (match_code "const,const_vector")
877 (match_test "aarch64_sve_bitmask_immediate_p (op)")))
879 ;; Used for SVE UMAX and UMIN.
880 (define_predicate "aarch64_sve_vsb_immediate"
881 (and (match_code "const_vector")
882 (match_test "GET_MODE_INNER (GET_MODE (op)) == QImode
883 ? aarch64_const_vec_all_same_in_range_p (op, -128, 127)
884 : aarch64_const_vec_all_same_in_range_p (op, 0, 255)")))
886 ;; Used for SVE MUL, SMAX and SMIN.
887 (define_predicate "aarch64_sve_vsm_immediate"
888 (and (match_code "const,const_vector")
889 (match_test "aarch64_const_vec_all_same_in_range_p (op, -128, 127)")))
891 (define_predicate "aarch64_sve_dup_immediate"
892 (and (match_code "const,const_vector")
893 (ior (match_test "aarch64_sve_dup_immediate_p (op)")
894 (match_test "aarch64_float_const_representable_p (op)"))))
896 (define_predicate "aarch64_sve_cmp_vsc_immediate"
897 (and (match_code "const_int,const_vector")
898 (match_test "aarch64_sve_cmp_immediate_p (op, true)")))
900 (define_predicate "aarch64_sve_cmp_vsd_immediate"
901 (and (match_code "const_int,const_vector")
902 (match_test "aarch64_sve_cmp_immediate_p (op, false)")))
904 (define_predicate "aarch64_sve_index_immediate"
905 (and (match_code "const_int")
906 (match_test "aarch64_sve_index_immediate_p (op)")))
908 (define_predicate "aarch64_sve_float_arith_immediate"
909 (and (match_code "const,const_vector")
910 (match_test "aarch64_sve_float_arith_immediate_p (op, false)")))
912 (define_predicate "aarch64_sve_float_negated_arith_immediate"
913 (and (match_code "const,const_vector")
914 (match_test "aarch64_sve_float_arith_immediate_p (op, true)")))
916 (define_predicate "aarch64_sve_float_arith_with_sub_immediate"
917 (ior (match_operand 0 "aarch64_sve_float_arith_immediate")
918 (match_operand 0 "aarch64_sve_float_negated_arith_immediate")))
920 (define_predicate "aarch64_sve_float_mul_immediate"
921 (and (match_code "const,const_vector")
922 (match_test "aarch64_sve_float_mul_immediate_p (op)")))
924 (define_predicate "aarch64_sve_float_maxmin_immediate"
925 (and (match_code "const_vector")
926 (ior (match_test "op == CONST0_RTX (GET_MODE (op))")
927 (match_test "op == CONST1_RTX (GET_MODE (op))"))))
929 (define_predicate "aarch64_sve_arith_operand"
930 (ior (match_operand 0 "register_operand")
931 (match_operand 0 "aarch64_sve_arith_immediate")))
933 (define_predicate "aarch64_sve_add_operand"
934 (ior (match_operand 0 "aarch64_sve_arith_operand")
935 (match_operand 0 "aarch64_sve_sub_arith_immediate")
936 (match_operand 0 "aarch64_sve_vector_inc_dec_immediate")))
938 (define_predicate "aarch64_sve_sqadd_operand"
939 (ior (match_operand 0 "register_operand")
940 (match_operand 0 "aarch64_sve_qadd_immediate")
941 (match_operand 0 "aarch64_sve_qsub_immediate")))
943 (define_predicate "aarch64_sve_pred_and_operand"
944 (ior (match_operand 0 "register_operand")
945 (match_operand 0 "aarch64_sve_uxt_immediate")))
947 (define_predicate "aarch64_sve_logical_operand"
948 (ior (match_operand 0 "register_operand")
949 (match_operand 0 "aarch64_sve_logical_immediate")))
951 (define_predicate "aarch64_sve_gather_offset_b"
952 (ior (match_operand 0 "register_operand")
953 (match_operand 0 "aarch64_sve_gather_immediate_b")))
955 (define_predicate "aarch64_sve_gather_offset_h"
956 (ior (match_operand 0 "register_operand")
957 (match_operand 0 "aarch64_sve_gather_immediate_h")))
959 (define_predicate "aarch64_sve_gather_offset_w"
960 (ior (match_operand 0 "register_operand")
961 (match_operand 0 "aarch64_sve_gather_immediate_w")))
963 (define_predicate "aarch64_sve_gather_offset_d"
964 (ior (match_operand 0 "register_operand")
965 (match_operand 0 "aarch64_sve_gather_immediate_d")))
967 (define_predicate "aarch64_sve_lshift_operand"
968 (ior (match_operand 0 "register_operand")
969 (match_operand 0 "aarch64_simd_lshift_imm")))
971 (define_predicate "aarch64_sve_rshift_operand"
972 (ior (match_operand 0 "register_operand")
973 (match_operand 0 "aarch64_simd_rshift_imm")))
975 (define_predicate "aarch64_sve_vsb_operand"
976 (ior (match_operand 0 "register_operand")
977 (match_operand 0 "aarch64_sve_vsb_immediate")))
979 (define_predicate "aarch64_sve_vsm_operand"
980 (ior (match_operand 0 "register_operand")
981 (match_operand 0 "aarch64_sve_vsm_immediate")))
983 (define_predicate "aarch64_sve_reg_or_dup_imm"
984 (ior (match_operand 0 "register_operand")
985 (match_operand 0 "aarch64_sve_dup_immediate")))
987 (define_predicate "aarch64_sve_cmp_vsc_operand"
988 (ior (match_operand 0 "register_operand")
989 (match_operand 0 "aarch64_sve_cmp_vsc_immediate")))
991 (define_predicate "aarch64_sve_cmp_vsd_operand"
992 (ior (match_operand 0 "register_operand")
993 (match_operand 0 "aarch64_sve_cmp_vsd_immediate")))
995 (define_predicate "aarch64_sve_index_operand"
996 (ior (match_operand 0 "register_operand")
997 (match_operand 0 "aarch64_sve_index_immediate")))
999 (define_predicate "aarch64_sve_float_arith_operand"
1000 (ior (match_operand 0 "register_operand")
1001 (match_operand 0 "aarch64_sve_float_arith_immediate")))
1003 (define_predicate "aarch64_sve_float_arith_with_sub_operand"
1004 (ior (match_operand 0 "register_operand")
1005 (match_operand 0 "aarch64_sve_float_arith_with_sub_immediate")))
1007 (define_predicate "aarch64_sve_float_mul_operand"
1008 (ior (match_operand 0 "register_operand")
1009 (match_operand 0 "aarch64_sve_float_mul_immediate")))
1011 (define_predicate "aarch64_sve_float_maxmin_operand"
1012 (ior (match_operand 0 "register_operand")
1013 (match_operand 0 "aarch64_sve_float_maxmin_immediate")))
1015 (define_predicate "aarch64_sve_vec_perm_operand"
1016 (ior (match_operand 0 "register_operand")
1017 (match_operand 0 "aarch64_constant_vector_operand")))
1019 (define_predicate "aarch64_sve_ptrue_flag"
1020 (and (match_code "const_int")
1021 (ior (match_test "INTVAL (op) == SVE_MAYBE_NOT_PTRUE")
1022 (match_test "INTVAL (op) == SVE_KNOWN_PTRUE"))))
1024 (define_predicate "aarch64_sve_gp_strictness"
1025 (and (match_code "const_int")
1026 (ior (match_test "INTVAL (op) == SVE_RELAXED_GP")
1027 (match_test "INTVAL (op) == SVE_STRICT_GP"))))
1029 (define_predicate "aarch64_gather_scale_operand_b"
1030 (and (match_code "const_int")
1031 (match_test "INTVAL (op) == 1")))
1033 (define_predicate "aarch64_gather_scale_operand_h"
1034 (and (match_code "const_int")
1035 (match_test "INTVAL (op) == 1 || INTVAL (op) == 2")))
1037 (define_predicate "aarch64_gather_scale_operand_w"
1038 (and (match_code "const_int")
1039 (match_test "INTVAL (op) == 1 || INTVAL (op) == 4")))
1041 (define_predicate "aarch64_gather_scale_operand_d"
1042 (and (match_code "const_int")
1043 (match_test "INTVAL (op) == 1 || INTVAL (op) == 8")))
1045 ;; A special predicate that doesn't match a particular mode.
1046 (define_special_predicate "aarch64_any_register_operand"
1049 (define_predicate "aarch64_sve_any_binary_operator"
1050 (match_code "plus,minus,mult,div,udiv,smax,umax,smin,umin,and,ior,xor"))
1052 (define_predicate "aarch64_bytes_per_sve_vector_operand"
1053 (and (match_code "const_int,const_poly_int")
1054 (match_test "known_eq (wi::to_poly_wide (op, mode),
1055 BYTES_PER_SVE_VECTOR)")))
1057 (define_predicate "aarch64_memtag_tag_offset"
1058 (and (match_code "const_int")
1059 (match_test "IN_RANGE (INTVAL (op), 0, 15)")))
1061 (define_predicate "aarch64_granule16_uimm6"
1062 (and (match_code "const_int")
1063 (match_test "IN_RANGE (INTVAL (op), 0, 1008)
1064 && !(INTVAL (op) & 0xf)")))
1066 (define_predicate "aarch64_granule16_simm9"
1067 (and (match_code "const_int")
1068 (match_test "IN_RANGE (INTVAL (op), -4096, 4080)
1069 && !(INTVAL (op) & 0xf)")))