1 ;; Machine description for AArch64 architecture.
2 ;; Copyright (C) 2009-2025 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 (define_register_constraint "k" "STACK_REG"
22 "@internal The stack register.")
24 (define_register_constraint "Uci" "W8_W11_REGS"
25 "@internal r8-r11, which can be used to index ZA.")
27 (define_register_constraint "Ucj" "W12_W15_REGS"
28 "@internal r12-r15, which can be used to index ZA.")
30 (define_register_constraint "Ucs" "TAILCALL_ADDR_REGS"
31 "@internal Registers suitable for an indirect tail call")
33 (define_register_constraint "Ucr"
34 "aarch64_harden_sls_blr_p () ? STUB_REGS : GENERAL_REGS"
35 "@internal Registers to be used for an indirect call.
36 This is usually the general registers, but when we are hardening against
37 Straight Line Speculation we disallow x16, x17, and x30 so we can use
38 indirection stubs. These indirection stubs cannot use the above registers
39 since they will be reached by a BL that may have to go through a linker
42 (define_register_constraint "w" "FP_REGS"
43 "Floating point and SIMD vector registers.")
45 (define_register_constraint "x" "FP_LO_REGS"
46 "Floating point and SIMD vector registers V0 - V15.")
48 (define_register_constraint "y" "FP_LO8_REGS"
49 "Floating point and SIMD vector registers V0 - V7.")
51 (define_register_constraint "Uw2" "FP_REGS"
52 "Even floating point and SIMD vector registers."
55 (define_register_constraint "Uw4" "FP_REGS"
56 "4-tuple-aligned floating point and SIMD vector registers."
59 (define_register_constraint "Uwd" "FP_REGS"
60 "@internal The first register in a tuple of 2 strided FPRs."
63 (define_register_constraint "Uwt" "FP_REGS"
64 "@internal The first register in a tuple of 4 strided FPRs."
67 (define_register_constraint "Upa" "PR_REGS"
68 "SVE predicate registers p0 - p15.")
70 (define_register_constraint "Up2" "PR_REGS"
71 "An even SVE predicate register, p0 - p14."
74 (define_register_constraint "Upl" "PR_LO_REGS"
75 "SVE predicate registers p0 - p7.")
77 (define_register_constraint "Uph" "PR_HI_REGS"
78 "SVE predicate registers p8 - p15.")
80 (define_register_constraint "Umv" "MOVEABLE_SYSREGS"
81 "@internal System Registers suitable for moving rather than requiring an unspec msr")
83 (define_constraint "c"
84 "@internal The condition code register."
85 (match_operand 0 "cc_register"))
87 (define_constraint "I"
88 "A constant that can be used with an ADD operation."
89 (and (match_code "const_int")
90 (match_test "aarch64_uimm12_shift (ival)")))
92 (define_constraint "Uaa"
93 "@internal A constant that matches two uses of add instructions."
94 (and (match_code "const_int")
95 (match_test "aarch64_pluslong_strict_immedate (op, VOIDmode)")))
97 (define_constraint "Uai"
99 A constraint that matches a VG-based constant that can be added by
100 a single INC or DEC."
101 (match_operand 0 "aarch64_sve_scalar_inc_dec_immediate"))
103 (define_constraint "Uav"
105 A constraint that matches a VG-based constant that can be added by
106 a single ADDVL or ADDPL."
107 (match_operand 0 "aarch64_sve_addvl_addpl_immediate"))
109 (define_constraint "UaV"
111 A constraint that matches a VG-based constant that can be added by
112 a single ADDSVL or ADDSPL."
113 (match_operand 0 "aarch64_addsvl_addspl_immediate"))
115 (define_constraint "Uat"
117 A constraint that matches a VG-based constant that can be added by
118 using multiple instructions, with one temporary register."
119 (match_operand 0 "aarch64_split_add_offset_immediate"))
121 (define_constraint "J"
122 "A constant that can be used with a SUB operation (once negated)."
123 (and (match_code "const_int")
124 (match_test "aarch64_uimm12_shift (- (unsigned HOST_WIDE_INT) ival)")))
126 ;; We can't use the mode of a CONST_INT to determine the context in
127 ;; which it is being used, so we must have a separate constraint for
130 (define_constraint "K"
131 "A constant that can be used with a 32-bit logical operation."
132 (and (match_code "const_int")
133 (match_test "aarch64_bitmask_imm (ival, SImode)")))
135 (define_constraint "L"
136 "A constant that can be used with a 64-bit logical operation."
137 (and (match_code "const_int")
138 (match_test "aarch64_bitmask_imm (ival, DImode)")))
140 (define_constraint "M"
141 "A constant that can be used with a 32-bit MOV immediate operation."
142 (and (match_code "const_int")
143 (match_test "aarch64_move_imm (ival, SImode)")))
145 (define_constraint "N"
146 "A constant that can be used with a 64-bit MOV immediate operation."
147 (and (match_code "const_int")
148 (match_test "aarch64_is_mov_xn_imm (ival)")))
150 (define_constraint "O"
151 "A constant that can be used with a 32 or 64-bit MOV immediate operation."
152 (and (match_code "const_int")
153 (match_test "aarch64_move_imm (ival, DImode)")))
155 (define_constraint "Uti"
156 "A constant that can be used with a 128-bit MOV immediate operation."
157 (and (ior (match_code "const_int")
158 (match_code "const_wide_int"))
159 (match_test "aarch64_mov128_immediate (op)")))
161 (define_constraint "UsO"
162 "A constant that can be used with a 32-bit and operation."
163 (and (match_code "const_int")
164 (match_test "aarch64_and_bitmask_imm (ival, SImode)")))
166 (define_constraint "UsP"
167 "A constant that can be used with a 64-bit and operation."
168 (and (match_code "const_int")
169 (match_test "aarch64_and_bitmask_imm (ival, DImode)")))
171 (define_constraint "S"
172 "A constraint that matches an absolute symbolic address."
173 (and (match_code "const,symbol_ref,label_ref")
174 (match_test "aarch64_symbolic_address_p (op)")))
176 (define_constraint "Y"
177 "Floating point constant zero."
178 (and (match_code "const_double")
179 (match_test "aarch64_float_const_zero_rtx_p (op)")))
181 (define_constraint "Z"
182 "Integer or floating-point constant zero."
183 (match_test "op == CONST0_RTX (GET_MODE (op))"))
185 (define_constraint "Ush"
186 "A constraint that matches an absolute symbolic address high part."
187 (and (match_code "high")
188 (match_test "aarch64_valid_symref (XEXP (op, 0), GET_MODE (XEXP (op, 0)))")))
190 (define_constraint "Usa"
192 A constraint that matches an absolute symbolic address that can be
193 loaded by a single ADR."
194 (and (match_code "const,symbol_ref,label_ref")
195 (match_test "aarch64_symbolic_address_p (op)")
196 (match_test "aarch64_mov_operand_p (op, GET_MODE (op))")))
198 (define_constraint "Usm"
199 "A constant that can be used with the S[MIN/MAX] CSSC instructions."
200 (and (match_code "const_int")
201 (match_test "aarch64_sminmax_immediate (op, VOIDmode)")))
203 ;; const is needed here to support UNSPEC_SALT_ADDR.
204 (define_constraint "Usw"
206 A constraint that matches a small GOT access."
207 (and (match_code "const,symbol_ref")
208 (match_test "aarch64_classify_symbolic_expression (op)
209 == SYMBOL_SMALL_GOT_4G")))
211 (define_constraint "Uss"
213 A constraint that matches an immediate shift constant in SImode."
214 (and (match_code "const_int")
215 (match_test "(unsigned HOST_WIDE_INT) ival < 32")))
217 (define_constraint "Usn"
218 "A constant that can be used with a CCMN operation (once negated)."
219 (and (match_code "const_int")
220 (match_test "IN_RANGE (ival, -31, 0)")))
222 (define_constraint "Usd"
224 A constraint that matches an immediate shift constant in DImode."
225 (and (match_code "const_int")
226 (match_test "(unsigned HOST_WIDE_INT) ival < 64")))
228 (define_constraint "Usf"
229 "@internal Usf is a symbol reference under the context where plt stub allowed."
230 (and (match_code "symbol_ref")
231 (match_test "!(aarch64_is_noplt_call_p (op)
232 || aarch64_is_long_call_p (op))")))
234 (define_constraint "Usg"
236 A constraint that matches an immediate right shift constant in SImode
237 suitable for a SISD instruction."
238 (and (match_code "const_int")
239 (match_test "IN_RANGE (ival, 1, 31)")))
241 (define_constraint "Usj"
243 A constraint that matches an immediate right shift constant in DImode
244 suitable for a SISD instruction."
245 (and (match_code "const_int")
246 (match_test "IN_RANGE (ival, 1, 63)")))
248 (define_constraint "UsM"
250 A constraint that matches the immediate constant -1."
251 (match_test "op == constm1_rtx"))
253 (define_constraint "Ulc"
255 A constraint that matches a constant integer whose bits are consecutive ones
257 (and (match_code "const_int")
258 (match_test "aarch64_high_bits_all_ones_p (ival)")))
260 (define_constraint "Usr"
262 A constraint that matches a value produced by RDVL."
263 (and (match_code "const_poly_int")
264 (match_test "aarch64_sve_rdvl_immediate_p (op)")))
266 (define_constraint "UsR"
268 A constraint that matches a value produced by RDSVL."
269 (and (match_code "const")
270 (match_test "aarch64_rdsvl_immediate_p (op)")))
272 (define_constraint "Usv"
274 A constraint that matches a VG-based constant that can be loaded by
276 (match_operand 0 "aarch64_sve_cnt_immediate"))
278 (define_constraint "Usi"
280 A constraint that matches an immediate operand valid for
281 the SVE INDEX instruction."
282 (match_operand 0 "aarch64_sve_index_immediate"))
284 (define_constraint "Ui1"
286 A constraint that matches the immediate constant +1."
287 (match_test "op == const1_rtx"))
289 (define_constraint "Ui2"
291 A constraint that matches the integers 0...3."
292 (and (match_code "const_int")
293 (match_test "(unsigned HOST_WIDE_INT) ival <= 3")))
295 (define_constraint "Ui3"
297 A constraint that matches the integers 0...4."
298 (and (match_code "const_int")
299 (match_test "(unsigned HOST_WIDE_INT) ival <= 4")))
301 (define_constraint "Ui7"
303 A constraint that matches the integers 0...7."
304 (and (match_code "const_int")
305 (match_test "(unsigned HOST_WIDE_INT) ival <= 7")))
307 (define_constraint "Up3"
309 A constraint that matches the integers 2^(0...4)."
310 (and (match_code "const_int")
311 (match_test "(unsigned) exact_log2 (ival) <= 4")))
313 (define_constraint "Uih"
315 A constraint that matches HImode integers zero extendable to
316 SImode plus_operand."
317 (and (match_code "const_int")
318 (match_test "aarch64_plushi_immediate (op, VOIDmode)")))
320 (define_memory_constraint "Q"
321 "A memory address which uses a single base register with no offset."
322 (and (match_code "mem")
323 (match_test "REG_P (XEXP (op, 0))")))
325 (define_memory_constraint "Ust"
327 A memory address with 9bit unscaled offset."
328 (match_operand 0 "aarch64_9bit_offset_memory_operand"))
330 (define_memory_constraint "Ump"
332 A memory address suitable for a load/store pair operation."
333 (and (match_code "mem")
334 (match_test "aarch64_legitimate_address_p (GET_MODE (op), XEXP (op, 0),
335 true, ADDR_QUERY_LDP_STP)")))
337 ;; Used for storing or loading pairs in an AdvSIMD register using an STP/LDP
338 ;; as a vector-concat. The address mode uses the same constraints as if it
339 ;; were for a single value.
340 (define_relaxed_memory_constraint "Umn"
342 A memory address suitable for a load/store pair operation."
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_address_constraint "UPb"
350 An address valid for SVE PRFB instructions."
351 (match_test "aarch64_sve_prefetch_operand_p (op, VNx16QImode)"))
353 (define_address_constraint "UPd"
355 An address valid for SVE PRFD instructions."
356 (match_test "aarch64_sve_prefetch_operand_p (op, VNx2DImode)"))
358 (define_address_constraint "UPh"
360 An address valid for SVE PRFH instructions."
361 (match_test "aarch64_sve_prefetch_operand_p (op, VNx8HImode)"))
363 (define_address_constraint "UPw"
365 An address valid for SVE PRFW instructions."
366 (match_test "aarch64_sve_prefetch_operand_p (op, VNx4SImode)"))
368 (define_memory_constraint "Utf"
370 An address valid for SVE LDFF1 instructions."
371 (and (match_code "mem")
372 (match_test "aarch64_sve_ldff1_operand_p (op)")))
374 (define_memory_constraint "Utn"
376 An address valid for SVE LDNF1 instructions."
377 (and (match_code "mem")
378 (match_test "aarch64_sve_ldnf1_operand_p (op)")))
380 (define_memory_constraint "Utr"
382 An address valid for SVE LDR and STR instructions (as distinct from
383 LD[1234] and ST[1234] patterns)."
384 (and (match_code "mem")
385 (match_test "aarch64_sve_ldr_operand_p (op)")))
387 (define_memory_constraint "Utv"
389 An address valid for loading/storing opaque structure
390 types wider than TImode."
391 (and (match_code "mem")
392 (match_test "aarch64_simd_mem_operand_p (op)")))
394 (define_relaxed_memory_constraint "Utq"
396 An address valid for loading or storing a 128-bit AdvSIMD register"
397 (and (match_code "mem")
398 (match_test "aarch64_legitimate_address_p (GET_MODE (op),
400 (match_test "aarch64_legitimate_address_p (V2DImode,
403 (define_relaxed_memory_constraint "UtQ"
405 An address valid for SVE LD1RQs."
406 (and (match_code "mem")
407 (match_test "aarch64_sve_ld1rq_operand_p (op)")))
409 (define_relaxed_memory_constraint "UOb"
411 An address valid for SVE LD1ROH."
412 (and (match_code "mem")
413 (match_test "aarch64_sve_ld1ro_operand_p (op, QImode)")))
415 (define_relaxed_memory_constraint "UOh"
417 An address valid for SVE LD1ROH."
418 (and (match_code "mem")
419 (match_test "aarch64_sve_ld1ro_operand_p (op, HImode)")))
422 (define_relaxed_memory_constraint "UOw"
424 An address valid for SVE LD1ROW."
425 (and (match_code "mem")
426 (match_test "aarch64_sve_ld1ro_operand_p (op, SImode)")))
428 (define_relaxed_memory_constraint "UOd"
430 An address valid for SVE LD1ROD."
431 (and (match_code "mem")
432 (match_test "aarch64_sve_ld1ro_operand_p (op, DImode)")))
434 (define_relaxed_memory_constraint "Uty"
436 An address valid for SVE LD1Rs."
437 (and (match_code "mem")
438 (match_test "aarch64_sve_ld1r_operand_p (op)")))
440 (define_memory_constraint "Utx"
442 An address valid for SVE structure mov patterns (as distinct from
443 LD[234] and ST[234] patterns)."
444 (match_operand 0 "aarch64_sve_struct_memory_operand"))
446 (define_constraint "Ufc"
447 "A floating point constant which can be used with an\
448 FMOV immediate operation."
449 (and (match_code "const_double,const_vector")
450 (match_test "aarch64_float_const_representable_p (op)")))
452 (define_constraint "Uum"
453 "A constant that can be used with the U[MIN/MAX] CSSC instructions."
454 (and (match_code "const_int")
455 (match_test "aarch64_uminmax_immediate (op, VOIDmode)")))
457 (define_constraint "Uvi"
458 "A floating point constant which can be used with a\
459 MOVI immediate operation."
460 (and (match_code "const_double")
461 (match_test "aarch64_can_const_movi_rtx_p (op, GET_MODE (op))")))
463 (define_constraint "Do"
465 A constraint that matches vector of immediates for orr."
466 (and (match_code "const_vector")
467 (match_test "aarch64_simd_valid_orr_imm (op)")))
469 (define_constraint "Db"
471 A constraint that matches vector of immediates for and/bic."
472 (and (match_code "const_vector")
473 (match_test "aarch64_simd_valid_and_imm (op)")))
475 (define_constraint "De"
477 A constraint that matches vector of immediates for xor."
478 (and (match_code "const_vector")
479 (match_test "aarch64_simd_valid_xor_imm (op)")))
481 (define_constraint "Dn"
483 A constraint that matches vector of immediates."
484 (and (match_code "const,const_vector")
485 (match_test "aarch64_simd_valid_mov_imm (op)")))
487 (define_constraint "Dh"
489 A constraint that matches an immediate operand valid for\
490 AdvSIMD scalar move in HImode."
491 (and (match_code "const_int")
492 (match_test "aarch64_simd_scalar_immediate_valid_for_move (op,
495 (define_constraint "Dq"
497 A constraint that matches an immediate operand valid for\
498 AdvSIMD scalar move in QImode."
499 (and (match_code "const_int")
500 (match_test "aarch64_simd_scalar_immediate_valid_for_move (op,
503 (define_constraint "Dt"
505 A const_double which is the reciprocal of an exact power of two, can be
506 used in an scvtf with fract bits operation"
507 (and (match_code "const_double")
508 (match_test "aarch64_fpconst_pow2_recip (op) > 0")))
510 (define_constraint "Dl"
512 A constraint that matches vector of immediates for left shifts."
513 (and (match_code "const,const_vector")
514 (match_test "aarch64_simd_shift_imm_p (op, GET_MODE (op),
517 (define_constraint "D1"
519 A constraint that matches vector of immediates that is bits(mode)-1."
520 (and (match_code "const,const_vector")
521 (match_test "aarch64_const_vec_all_same_in_range_p (op,
522 GET_MODE_UNIT_BITSIZE (mode) - 1,
523 GET_MODE_UNIT_BITSIZE (mode) - 1)")))
525 (define_constraint "D2"
527 A constraint that matches vector of immediates that is bits(mode)/2."
528 (and (match_code "const,const_vector")
529 (match_test "aarch64_simd_shift_imm_vec_exact_top (op, mode)")))
531 (define_constraint "DL"
533 A constraint that matches vector of immediates for left shift long.
534 That is immediates between 0 to (bits(mode)/2)-1."
535 (and (match_code "const,const_vector")
536 (match_test "aarch64_const_vec_all_same_in_range_p (op, 0,
537 (GET_MODE_UNIT_BITSIZE (mode) / 2) - 1)")))
539 (define_constraint "Dr"
541 A constraint that matches vector of immediates for right shifts."
542 (and (match_code "const,const_vector")
543 (match_test "aarch64_simd_shift_imm_p (op, GET_MODE (op),
546 (define_constraint "Dx"
548 A constraint that matches a vector of 64-bit immediates which we don't have a
549 single instruction to create but that we can create in creative ways."
550 (and (match_code "const_int,const,const_vector")
551 (match_test "aarch64_simd_special_constant_p (op, DImode)")))
553 (define_constraint "Dz"
555 A constraint that matches a vector of immediate zero."
556 (and (match_code "const,const_vector")
557 (match_test "op == CONST0_RTX (GET_MODE (op))")))
559 (define_constraint "Dm"
561 A constraint that matches a vector of immediate minus one."
562 (and (match_code "const,const_vector")
563 (match_test "op == CONSTM1_RTX (GET_MODE (op))")))
565 (define_constraint "Dd"
567 A constraint that matches an integer immediate operand valid\
568 for AdvSIMD scalar operations in DImode."
569 (and (match_code "const_int")
570 (match_test "aarch64_can_const_movi_rtx_p (op, DImode)")))
572 (define_constraint "Ds"
574 A constraint that matches an integer immediate operand valid\
575 for AdvSIMD scalar operations in SImode."
576 (and (match_code "const_int")
577 (match_test "aarch64_can_const_movi_rtx_p (op, SImode)")))
579 (define_address_constraint "Dp"
581 An address valid for a prefetch instruction."
582 (match_test "aarch64_address_valid_for_prefetch_p (op, true)"))
584 (define_constraint "vgb"
586 A constraint that matches an immediate offset valid for SVE LD1B
587 gather instructions."
588 (match_operand 0 "aarch64_sve_gather_immediate_b"))
590 (define_constraint "vgd"
592 A constraint that matches an immediate offset valid for SVE LD1D
593 gather instructions."
594 (match_operand 0 "aarch64_sve_gather_immediate_d"))
596 (define_constraint "vgh"
598 A constraint that matches an immediate offset valid for SVE LD1H
599 gather instructions."
600 (match_operand 0 "aarch64_sve_gather_immediate_h"))
602 (define_constraint "vgw"
604 A constraint that matches an immediate offset valid for SVE LD1W
605 gather instructions."
606 (match_operand 0 "aarch64_sve_gather_immediate_w"))
608 (define_constraint "vsa"
610 A constraint that matches an immediate operand valid for SVE
611 arithmetic instructions."
612 (match_operand 0 "aarch64_sve_arith_immediate"))
614 (define_constraint "vsb"
616 A constraint that matches an immediate operand valid for SVE UMAX
617 and UMIN operations."
618 (match_operand 0 "aarch64_sve_vsb_immediate"))
620 (define_constraint "vsc"
622 A constraint that matches a signed immediate operand valid for SVE
624 (match_operand 0 "aarch64_sve_cmp_vsc_immediate"))
626 (define_constraint "vss"
628 A constraint that matches a signed immediate operand valid for SVE
630 (match_test "aarch64_sve_dup_immediate_p (op)"))
632 (define_constraint "vsd"
634 A constraint that matches an unsigned immediate operand valid for SVE
636 (match_operand 0 "aarch64_sve_cmp_vsd_immediate"))
638 (define_constraint "vsi"
640 A constraint that matches a vector count operand valid for SVE INC and
642 (match_operand 0 "aarch64_sve_vector_inc_dec_immediate"))
644 (define_constraint "vsn"
646 A constraint that matches an immediate operand whose negative
647 is valid for SVE SUB instructions."
648 (match_operand 0 "aarch64_sve_sub_arith_immediate"))
650 (define_constraint "vsQ"
652 Like vsa, but additionally check that the immediate is nonnegative
653 when interpreted as a signed value."
654 (match_operand 0 "aarch64_sve_qadd_immediate"))
656 (define_constraint "vsS"
658 Like vsn, but additionally check that the immediate is negative
659 when interpreted as a signed value."
660 (match_operand 0 "aarch64_sve_qsub_immediate"))
662 (define_constraint "vsl"
664 A constraint that matches an immediate operand valid for SVE logical
666 (match_operand 0 "aarch64_sve_logical_immediate"))
668 (define_constraint "vsm"
670 A constraint that matches an immediate operand valid for SVE MUL,
671 SMAX and SMIN operations."
672 (match_operand 0 "aarch64_sve_vsm_immediate"))
674 (define_constraint "vs1"
676 A constraint that matches a vector of immediate one."
677 (and (match_code "const,const_vector")
678 (match_test "op == CONST1_RTX (GET_MODE (op))")))
680 (define_constraint "vsA"
682 A constraint that matches an immediate operand valid for SVE FADD
683 and FSUB operations."
684 (match_operand 0 "aarch64_sve_float_arith_immediate"))
687 (define_constraint "vsB"
689 A constraint that matches an immediate operand valid for SVE FMAX
690 and FMIN operations."
691 (match_operand 0 "aarch64_sve_float_maxmin_immediate"))
693 (define_constraint "vsM"
695 A constraint that matches an immediate operand valid for SVE FMUL
697 (match_operand 0 "aarch64_sve_float_mul_immediate"))
699 (define_constraint "vsN"
701 A constraint that matches the negative of vsA"
702 (match_operand 0 "aarch64_sve_float_negated_arith_immediate"))