1 ;; Machine description for AArch64 architecture.
2 ;; Copyright (C) 2009-2017 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_special_predicate "cc_register"
22 (and (match_code "reg")
23 (and (match_test "REGNO (op) == CC_REGNUM")
24 (ior (match_test "mode == GET_MODE (op)")
25 (match_test "mode == VOIDmode
26 && GET_MODE_CLASS (GET_MODE (op)) == MODE_CC"))))
29 (define_predicate "aarch64_call_insn_operand"
30 (ior (match_code "symbol_ref")
31 (match_operand 0 "register_operand")))
33 ;; Return true if OP a (const_int 0) operand.
34 (define_predicate "const0_operand"
35 (and (match_code "const_int")
36 (match_test "op == CONST0_RTX (mode)")))
38 (define_predicate "aarch64_ccmp_immediate"
39 (and (match_code "const_int")
40 (match_test "IN_RANGE (INTVAL (op), -31, 31)")))
42 (define_predicate "aarch64_ccmp_operand"
43 (ior (match_operand 0 "register_operand")
44 (match_operand 0 "aarch64_ccmp_immediate")))
46 (define_predicate "aarch64_simd_register"
47 (and (match_code "reg")
48 (ior (match_test "REGNO_REG_CLASS (REGNO (op)) == FP_LO_REGS")
49 (match_test "REGNO_REG_CLASS (REGNO (op)) == FP_REGS"))))
51 (define_predicate "aarch64_reg_or_zero"
52 (and (match_code "reg,subreg,const_int")
53 (ior (match_operand 0 "register_operand")
54 (match_test "op == const0_rtx"))))
56 (define_predicate "aarch64_reg_or_fp_zero"
57 (ior (match_operand 0 "register_operand")
58 (and (match_code "const_double")
59 (match_test "aarch64_float_const_zero_rtx_p (op)"))))
61 (define_predicate "aarch64_reg_zero_or_m1_or_1"
62 (and (match_code "reg,subreg,const_int")
63 (ior (match_operand 0 "register_operand")
64 (ior (match_test "op == const0_rtx")
65 (ior (match_test "op == constm1_rtx")
66 (match_test "op == const1_rtx"))))))
68 (define_predicate "aarch64_fp_compare_operand"
69 (ior (match_operand 0 "register_operand")
70 (and (match_code "const_double")
71 (match_test "aarch64_float_const_zero_rtx_p (op)"))))
73 (define_predicate "aarch64_fp_pow2"
74 (and (match_code "const_double")
75 (match_test "aarch64_fpconst_pow_of_2 (op) > 0")))
77 (define_predicate "aarch64_fp_vec_pow2"
78 (match_test "aarch64_vec_fpconst_pow_of_2 (op) > 0"))
80 (define_predicate "aarch64_sub_immediate"
81 (and (match_code "const_int")
82 (match_test "aarch64_uimm12_shift (-INTVAL (op))")))
84 (define_predicate "aarch64_plus_immediate"
85 (and (match_code "const_int")
86 (ior (match_test "aarch64_uimm12_shift (INTVAL (op))")
87 (match_test "aarch64_uimm12_shift (-INTVAL (op))"))))
89 (define_predicate "aarch64_plus_operand"
90 (ior (match_operand 0 "register_operand")
91 (match_operand 0 "aarch64_plus_immediate")))
93 (define_predicate "aarch64_pluslong_immediate"
94 (and (match_code "const_int")
95 (match_test "(INTVAL (op) < 0xffffff && INTVAL (op) > -0xffffff)")))
97 (define_predicate "aarch64_pluslong_strict_immedate"
98 (and (match_operand 0 "aarch64_pluslong_immediate")
99 (not (match_operand 0 "aarch64_plus_immediate"))))
101 (define_predicate "aarch64_pluslong_operand"
102 (ior (match_operand 0 "register_operand")
103 (match_operand 0 "aarch64_pluslong_immediate")))
105 (define_predicate "aarch64_logical_immediate"
106 (and (match_code "const_int")
107 (match_test "aarch64_bitmask_imm (INTVAL (op), mode)")))
109 (define_predicate "aarch64_logical_operand"
110 (ior (match_operand 0 "register_operand")
111 (match_operand 0 "aarch64_logical_immediate")))
113 (define_predicate "aarch64_logical_and_immediate"
114 (and (match_code "const_int")
115 (match_test "aarch64_and_bitmask_imm (INTVAL (op), mode)")))
117 (define_predicate "aarch64_shift_imm_si"
118 (and (match_code "const_int")
119 (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) < 32")))
121 (define_predicate "aarch64_shift_imm_di"
122 (and (match_code "const_int")
123 (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) < 64")))
125 (define_predicate "aarch64_shift_imm64_di"
126 (and (match_code "const_int")
127 (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) <= 64")))
129 (define_predicate "aarch64_reg_or_shift_imm_si"
130 (ior (match_operand 0 "register_operand")
131 (match_operand 0 "aarch64_shift_imm_si")))
133 (define_predicate "aarch64_reg_or_shift_imm_di"
134 (ior (match_operand 0 "register_operand")
135 (match_operand 0 "aarch64_shift_imm_di")))
137 ;; The imm3 field is a 3-bit field that only accepts immediates in the
139 (define_predicate "aarch64_imm3"
140 (and (match_code "const_int")
141 (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) <= 4")))
143 ;; An immediate that fits into 24 bits.
144 (define_predicate "aarch64_imm24"
145 (and (match_code "const_int")
146 (match_test "IN_RANGE (UINTVAL (op), 0, 0xffffff)")))
148 (define_predicate "aarch64_pwr_imm3"
149 (and (match_code "const_int")
150 (match_test "INTVAL (op) != 0
151 && (unsigned) exact_log2 (INTVAL (op)) <= 4")))
153 (define_predicate "aarch64_pwr_2_si"
154 (and (match_code "const_int")
155 (match_test "INTVAL (op) != 0
156 && (unsigned) exact_log2 (INTVAL (op)) < 32")))
158 (define_predicate "aarch64_pwr_2_di"
159 (and (match_code "const_int")
160 (match_test "INTVAL (op) != 0
161 && (unsigned) exact_log2 (INTVAL (op)) < 64")))
163 (define_predicate "aarch64_mem_pair_offset"
164 (and (match_code "const_int")
165 (match_test "aarch64_offset_7bit_signed_scaled_p (mode, INTVAL (op))")))
167 (define_predicate "aarch64_mem_pair_operand"
168 (and (match_code "mem")
169 (match_test "aarch64_legitimate_address_p (mode, XEXP (op, 0), PARALLEL,
172 (define_predicate "aarch64_prefetch_operand"
173 (match_test "aarch64_address_valid_for_prefetch_p (op, false)"))
175 (define_predicate "aarch64_valid_symref"
176 (match_code "const, symbol_ref, label_ref")
178 return (aarch64_classify_symbolic_expression (op)
179 != SYMBOL_FORCE_TO_MEM);
182 (define_predicate "aarch64_tls_ie_symref"
183 (match_code "const, symbol_ref, label_ref")
185 switch (GET_CODE (op))
189 if (GET_CODE (op) != PLUS
190 || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
191 || GET_CODE (XEXP (op, 1)) != CONST_INT)
197 return SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_INITIAL_EXEC;
204 (define_predicate "aarch64_tls_le_symref"
205 (match_code "const, symbol_ref, label_ref")
207 switch (GET_CODE (op))
211 if (GET_CODE (op) != PLUS
212 || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
213 || GET_CODE (XEXP (op, 1)) != CONST_INT)
219 return SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_EXEC;
226 (define_predicate "aarch64_mov_operand"
227 (and (match_code "reg,subreg,mem,const,const_int,symbol_ref,label_ref,high")
228 (ior (match_operand 0 "register_operand")
229 (ior (match_operand 0 "memory_operand")
230 (match_test "aarch64_mov_operand_p (op, mode)")))))
232 (define_predicate "aarch64_movti_operand"
233 (and (match_code "reg,subreg,mem,const_int")
234 (ior (match_operand 0 "register_operand")
235 (ior (match_operand 0 "memory_operand")
236 (match_operand 0 "const_int_operand")))))
238 (define_predicate "aarch64_reg_or_imm"
239 (and (match_code "reg,subreg,const_int")
240 (ior (match_operand 0 "register_operand")
241 (match_operand 0 "const_int_operand"))))
243 ;; True for integer comparisons and for FP comparisons other than LTGT or UNEQ.
244 (define_special_predicate "aarch64_comparison_operator"
245 (match_code "eq,ne,le,lt,ge,gt,geu,gtu,leu,ltu,unordered,
246 ordered,unlt,unle,unge,ungt"))
248 ;; Same as aarch64_comparison_operator but don't ignore the mode.
249 ;; RTL SET operations require their operands source and destination have
250 ;; the same modes, so we can't ignore the modes there. See PR target/69161.
251 (define_predicate "aarch64_comparison_operator_mode"
252 (match_code "eq,ne,le,lt,ge,gt,geu,gtu,leu,ltu,unordered,
253 ordered,unlt,unle,unge,ungt"))
255 (define_special_predicate "aarch64_comparison_operation"
256 (match_code "eq,ne,le,lt,ge,gt,geu,gtu,leu,ltu,unordered,
257 ordered,unlt,unle,unge,ungt")
259 if (XEXP (op, 1) != const0_rtx)
261 rtx op0 = XEXP (op, 0);
262 if (!REG_P (op0) || REGNO (op0) != CC_REGNUM)
264 return aarch64_get_condition_code (op) >= 0;
267 (define_special_predicate "aarch64_carry_operation"
268 (match_code "ne,geu")
270 if (XEXP (op, 1) != const0_rtx)
272 machine_mode ccmode = (GET_CODE (op) == NE ? CC_Cmode : CCmode);
273 rtx op0 = XEXP (op, 0);
274 return REG_P (op0) && REGNO (op0) == CC_REGNUM && GET_MODE (op0) == ccmode;
277 (define_special_predicate "aarch64_borrow_operation"
278 (match_code "eq,ltu")
280 if (XEXP (op, 1) != const0_rtx)
282 machine_mode ccmode = (GET_CODE (op) == EQ ? CC_Cmode : CCmode);
283 rtx op0 = XEXP (op, 0);
284 return REG_P (op0) && REGNO (op0) == CC_REGNUM && GET_MODE (op0) == ccmode;
287 ;; True if the operand is memory reference suitable for a load/store exclusive.
288 (define_predicate "aarch64_sync_memory_operand"
289 (and (match_operand 0 "memory_operand")
290 (match_code "reg" "0")))
292 ;; Predicates for parallel expanders based on mode.
293 (define_special_predicate "vect_par_cnst_hi_half"
294 (match_code "parallel")
296 return aarch64_simd_check_vect_par_cnst_half (op, mode, true);
299 (define_special_predicate "vect_par_cnst_lo_half"
300 (match_code "parallel")
302 return aarch64_simd_check_vect_par_cnst_half (op, mode, false);
305 (define_special_predicate "aarch64_simd_lshift_imm"
306 (match_code "const_vector")
308 return aarch64_simd_shift_imm_p (op, mode, true);
311 (define_special_predicate "aarch64_simd_rshift_imm"
312 (match_code "const_vector")
314 return aarch64_simd_shift_imm_p (op, mode, false);
317 (define_predicate "aarch64_simd_reg_or_zero"
318 (and (match_code "reg,subreg,const_int,const_double,const_vector")
319 (ior (match_operand 0 "register_operand")
320 (ior (match_test "op == const0_rtx")
321 (match_test "aarch64_simd_imm_zero_p (op, mode)")))))
323 (define_predicate "aarch64_simd_struct_operand"
324 (and (match_code "mem")
325 (match_test "TARGET_SIMD && aarch64_simd_mem_operand_p (op)")))
327 ;; Like general_operand but allow only valid SIMD addressing modes.
328 (define_predicate "aarch64_simd_general_operand"
329 (and (match_operand 0 "general_operand")
330 (match_test "!MEM_P (op)
331 || GET_CODE (XEXP (op, 0)) == POST_INC
332 || GET_CODE (XEXP (op, 0)) == REG")))
334 ;; Like nonimmediate_operand but allow only valid SIMD addressing modes.
335 (define_predicate "aarch64_simd_nonimmediate_operand"
336 (and (match_operand 0 "nonimmediate_operand")
337 (match_test "!MEM_P (op)
338 || GET_CODE (XEXP (op, 0)) == POST_INC
339 || GET_CODE (XEXP (op, 0)) == REG")))
341 (define_special_predicate "aarch64_simd_imm_zero"
342 (match_code "const_vector")
344 return aarch64_simd_imm_zero_p (op, mode);
347 (define_special_predicate "aarch64_simd_imm_minus_one"
348 (match_code "const_vector")
350 return aarch64_const_vec_all_same_int_p (op, -1);
353 ;; Predicates used by the various SIMD shift operations. These
354 ;; fall in to 3 categories.
355 ;; Shifts with a range 0-(bit_size - 1) (aarch64_simd_shift_imm)
356 ;; Shifts with a range 1-bit_size (aarch64_simd_shift_imm_offset)
357 ;; Shifts with a range 0-bit_size (aarch64_simd_shift_imm_bitsize)
358 (define_predicate "aarch64_simd_shift_imm_qi"
359 (and (match_code "const_int")
360 (match_test "IN_RANGE (INTVAL (op), 0, 7)")))
362 (define_predicate "aarch64_simd_shift_imm_hi"
363 (and (match_code "const_int")
364 (match_test "IN_RANGE (INTVAL (op), 0, 15)")))
366 (define_predicate "aarch64_simd_shift_imm_si"
367 (and (match_code "const_int")
368 (match_test "IN_RANGE (INTVAL (op), 0, 31)")))
370 (define_predicate "aarch64_simd_shift_imm_di"
371 (and (match_code "const_int")
372 (match_test "IN_RANGE (INTVAL (op), 0, 63)")))
374 (define_predicate "aarch64_simd_shift_imm_offset_qi"
375 (and (match_code "const_int")
376 (match_test "IN_RANGE (INTVAL (op), 1, 8)")))
378 (define_predicate "aarch64_simd_shift_imm_offset_hi"
379 (and (match_code "const_int")
380 (match_test "IN_RANGE (INTVAL (op), 1, 16)")))
382 (define_predicate "aarch64_simd_shift_imm_offset_si"
383 (and (match_code "const_int")
384 (match_test "IN_RANGE (INTVAL (op), 1, 32)")))
386 (define_predicate "aarch64_simd_shift_imm_offset_di"
387 (and (match_code "const_int")
388 (match_test "IN_RANGE (INTVAL (op), 1, 64)")))
390 (define_predicate "aarch64_simd_shift_imm_bitsize_qi"
391 (and (match_code "const_int")
392 (match_test "IN_RANGE (INTVAL (op), 0, 8)")))
394 (define_predicate "aarch64_simd_shift_imm_bitsize_hi"
395 (and (match_code "const_int")
396 (match_test "IN_RANGE (INTVAL (op), 0, 16)")))
398 (define_predicate "aarch64_simd_shift_imm_bitsize_si"
399 (and (match_code "const_int")
400 (match_test "IN_RANGE (INTVAL (op), 0, 32)")))
402 (define_predicate "aarch64_simd_shift_imm_bitsize_di"
403 (and (match_code "const_int")
404 (match_test "IN_RANGE (INTVAL (op), 0, 64)")))
406 (define_predicate "aarch64_constant_pool_symref"
407 (and (match_code "symbol_ref")
408 (match_test "CONSTANT_POOL_ADDRESS_P (op)")))