[AArch64] PR target/68129: Define TARGET_SUPPORTS_WIDE_INT
[official-gcc.git] / gcc / config / aarch64 / predicates.md
blobe7f76e048543d27b325f915ced028b7a493b6789
1 ;; Machine description for AArch64 architecture.
2 ;; Copyright (C) 2009-2015 Free Software Foundation, Inc.
3 ;; Contributed by ARM Ltd.
4 ;;
5 ;; This file is part of GCC.
6 ;;
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)
10 ;; any later version.
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_special_predicate "ccmp_cc_register"
47   (and (match_code "reg")
48        (and (match_test "REGNO (op) == CC_REGNUM")
49             (ior (match_test "mode == GET_MODE (op)")
50                  (match_test "mode == VOIDmode
51                               && (GET_MODE (op) == CC_DNEmode
52                                   || GET_MODE (op) == CC_DEQmode
53                                   || GET_MODE (op) == CC_DLEmode
54                                   || GET_MODE (op) == CC_DLTmode
55                                   || GET_MODE (op) == CC_DGEmode
56                                   || GET_MODE (op) == CC_DGTmode
57                                   || GET_MODE (op) == CC_DLEUmode
58                                   || GET_MODE (op) == CC_DLTUmode
59                                   || GET_MODE (op) == CC_DGEUmode
60                                   || GET_MODE (op) == CC_DGTUmode)"))))
63 (define_predicate "aarch64_simd_register"
64   (and (match_code "reg")
65        (ior (match_test "REGNO_REG_CLASS (REGNO (op)) == FP_LO_REGS")
66             (match_test "REGNO_REG_CLASS (REGNO (op)) == FP_REGS"))))
68 (define_predicate "aarch64_reg_or_zero"
69   (and (match_code "reg,subreg,const_int")
70        (ior (match_operand 0 "register_operand")
71             (match_test "op == const0_rtx"))))
73 (define_predicate "aarch64_reg_or_fp_zero"
74   (and (match_code "reg,subreg,const_double")
75        (ior (match_operand 0 "register_operand")
76             (match_test "aarch64_float_const_zero_rtx_p (op)"))))
78 (define_predicate "aarch64_reg_zero_or_m1_or_1"
79   (and (match_code "reg,subreg,const_int")
80        (ior (match_operand 0 "register_operand")
81             (ior (match_test "op == const0_rtx")
82                  (ior (match_test "op == constm1_rtx")
83                       (match_test "op == const1_rtx"))))))
85 (define_predicate "aarch64_fp_compare_operand"
86   (ior (match_operand 0 "register_operand")
87        (and (match_code "const_double")
88             (match_test "aarch64_float_const_zero_rtx_p (op)"))))
90 (define_predicate "aarch64_fp_pow2"
91   (and (match_code "const_double")
92         (match_test "aarch64_fpconst_pow_of_2 (op) > 0")))
94 (define_predicate "aarch64_fp_vec_pow2"
95   (match_test "aarch64_vec_fpconst_pow_of_2 (op) > 0"))
97 (define_predicate "aarch64_plus_immediate"
98   (and (match_code "const_int")
99        (ior (match_test "aarch64_uimm12_shift (INTVAL (op))")
100             (match_test "aarch64_uimm12_shift (-INTVAL (op))"))))
102 (define_predicate "aarch64_plus_operand"
103   (ior (match_operand 0 "register_operand")
104        (match_operand 0 "aarch64_plus_immediate")))
106 (define_predicate "aarch64_pluslong_immediate"
107   (and (match_code "const_int")
108        (match_test "(INTVAL (op) < 0xffffff && INTVAL (op) > -0xffffff)")))
110 (define_predicate "aarch64_pluslong_operand"
111   (ior (match_operand 0 "register_operand")
112        (match_operand 0 "aarch64_pluslong_immediate")))
114 (define_predicate "aarch64_logical_immediate"
115   (and (match_code "const_int")
116        (match_test "aarch64_bitmask_imm (INTVAL (op), mode)")))
118 (define_predicate "aarch64_logical_operand"
119   (ior (match_operand 0 "register_operand")
120        (match_operand 0 "aarch64_logical_immediate")))
122 (define_predicate "aarch64_shift_imm_si"
123   (and (match_code "const_int")
124        (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) < 32")))
126 (define_predicate "aarch64_shift_imm_di"
127   (and (match_code "const_int")
128        (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) < 64")))
130 (define_predicate "aarch64_shift_imm64_di"
131   (and (match_code "const_int")
132        (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) <= 64")))
134 (define_predicate "aarch64_reg_or_shift_imm_si"
135   (ior (match_operand 0 "register_operand")
136        (match_operand 0 "aarch64_shift_imm_si")))
138 (define_predicate "aarch64_reg_or_shift_imm_di"
139   (ior (match_operand 0 "register_operand")
140        (match_operand 0 "aarch64_shift_imm_di")))
142 ;; The imm3 field is a 3-bit field that only accepts immediates in the
143 ;; range 0..4.
144 (define_predicate "aarch64_imm3"
145   (and (match_code "const_int")
146        (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) <= 4")))
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,
170                                                0)")))
172 (define_predicate "aarch64_valid_symref"
173   (match_code "const, symbol_ref, label_ref")
175   return (aarch64_classify_symbolic_expression (op)
176           != SYMBOL_FORCE_TO_MEM);
179 (define_predicate "aarch64_tls_ie_symref"
180   (match_code "const, symbol_ref, label_ref")
182   switch (GET_CODE (op))
183     {
184     case CONST:
185       op = XEXP (op, 0);
186       if (GET_CODE (op) != PLUS
187           || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
188           || GET_CODE (XEXP (op, 1)) != CONST_INT)
189         return false;
190       op = XEXP (op, 0);
192     case SYMBOL_REF:
193       return SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_INITIAL_EXEC;
195     default:
196       gcc_unreachable ();
197     }
200 (define_predicate "aarch64_tls_le_symref"
201   (match_code "const, symbol_ref, label_ref")
203   switch (GET_CODE (op))
204     {
205     case CONST:
206       op = XEXP (op, 0);
207       if (GET_CODE (op) != PLUS
208           || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
209           || GET_CODE (XEXP (op, 1)) != CONST_INT)
210         return false;
211       op = XEXP (op, 0);
213     case SYMBOL_REF:
214       return SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_EXEC;
216     default:
217       gcc_unreachable ();
218     }
221 (define_predicate "aarch64_mov_operand"
222   (and (match_code "reg,subreg,mem,const,const_int,symbol_ref,label_ref,high")
223        (ior (match_operand 0 "register_operand")
224             (ior (match_operand 0 "memory_operand")
225                  (match_test "aarch64_mov_operand_p (op, mode)")))))
227 (define_predicate "aarch64_movti_operand"
228   (and (match_code "reg,subreg,mem,const_int")
229        (ior (match_operand 0 "register_operand")
230             (ior (match_operand 0 "memory_operand")
231                  (match_operand 0 "const_int_operand")))))
233 (define_predicate "aarch64_reg_or_imm"
234   (and (match_code "reg,subreg,const_int")
235        (ior (match_operand 0 "register_operand")
236             (match_operand 0 "const_int_operand"))))
238 ;; True for integer comparisons and for FP comparisons other than LTGT or UNEQ.
239 (define_special_predicate "aarch64_comparison_operator"
240   (match_code "eq,ne,le,lt,ge,gt,geu,gtu,leu,ltu,unordered,ordered,unlt,unle,unge,ungt"))
242 (define_special_predicate "aarch64_comparison_operation"
243   (match_code "eq,ne,le,lt,ge,gt,geu,gtu,leu,ltu,unordered,ordered,unlt,unle,unge,ungt")
245   if (XEXP (op, 1) != const0_rtx)
246     return false;
247   rtx op0 = XEXP (op, 0);
248   if (!REG_P (op0) || REGNO (op0) != CC_REGNUM)
249     return false;
250   return aarch64_get_condition_code (op) >= 0;
254 ;; True if the operand is memory reference suitable for a load/store exclusive.
255 (define_predicate "aarch64_sync_memory_operand"
256   (and (match_operand 0 "memory_operand")
257        (match_code "reg" "0")))
259 ;; Predicates for parallel expanders based on mode.
260 (define_special_predicate "vect_par_cnst_hi_half"
261   (match_code "parallel")
263   return aarch64_simd_check_vect_par_cnst_half (op, mode, true);
266 (define_special_predicate "vect_par_cnst_lo_half"
267   (match_code "parallel")
269   return aarch64_simd_check_vect_par_cnst_half (op, mode, false);
272 (define_special_predicate "aarch64_simd_lshift_imm"
273   (match_code "const_vector")
275   return aarch64_simd_shift_imm_p (op, mode, true);
278 (define_special_predicate "aarch64_simd_rshift_imm"
279   (match_code "const_vector")
281   return aarch64_simd_shift_imm_p (op, mode, false);
284 (define_predicate "aarch64_simd_reg_or_zero"
285   (and (match_code "reg,subreg,const_int,const_vector")
286        (ior (match_operand 0 "register_operand")
287            (ior (match_test "op == const0_rtx")
288                 (match_test "aarch64_simd_imm_zero_p (op, mode)")))))
290 (define_predicate "aarch64_simd_struct_operand"
291   (and (match_code "mem")
292        (match_test "TARGET_SIMD && aarch64_simd_mem_operand_p (op)")))
294 ;; Like general_operand but allow only valid SIMD addressing modes.
295 (define_predicate "aarch64_simd_general_operand"
296   (and (match_operand 0 "general_operand")
297        (match_test "!MEM_P (op)
298                     || GET_CODE (XEXP (op, 0)) == POST_INC
299                     || GET_CODE (XEXP (op, 0)) == REG")))
301 ;; Like nonimmediate_operand but allow only valid SIMD addressing modes.
302 (define_predicate "aarch64_simd_nonimmediate_operand"
303   (and (match_operand 0 "nonimmediate_operand")
304        (match_test "!MEM_P (op)
305                     || GET_CODE (XEXP (op, 0)) == POST_INC
306                     || GET_CODE (XEXP (op, 0)) == REG")))
308 (define_special_predicate "aarch64_simd_imm_zero"
309   (match_code "const_vector")
311   return aarch64_simd_imm_zero_p (op, mode);
314 (define_special_predicate "aarch64_simd_imm_minus_one"
315   (match_code "const_vector")
317   return aarch64_const_vec_all_same_int_p (op, -1);
320 ;; Predicates used by the various SIMD shift operations.  These
321 ;; fall in to 3 categories.
322 ;;   Shifts with a range 0-(bit_size - 1) (aarch64_simd_shift_imm)
323 ;;   Shifts with a range 1-bit_size (aarch64_simd_shift_imm_offset)
324 ;;   Shifts with a range 0-bit_size (aarch64_simd_shift_imm_bitsize)
325 (define_predicate "aarch64_simd_shift_imm_qi"
326   (and (match_code "const_int")
327        (match_test "IN_RANGE (INTVAL (op), 0, 7)")))
329 (define_predicate "aarch64_simd_shift_imm_hi"
330   (and (match_code "const_int")
331        (match_test "IN_RANGE (INTVAL (op), 0, 15)")))
333 (define_predicate "aarch64_simd_shift_imm_si"
334   (and (match_code "const_int")
335        (match_test "IN_RANGE (INTVAL (op), 0, 31)")))
337 (define_predicate "aarch64_simd_shift_imm_di"
338   (and (match_code "const_int")
339        (match_test "IN_RANGE (INTVAL (op), 0, 63)")))
341 (define_predicate "aarch64_simd_shift_imm_offset_qi"
342   (and (match_code "const_int")
343        (match_test "IN_RANGE (INTVAL (op), 1, 8)")))
345 (define_predicate "aarch64_simd_shift_imm_offset_hi"
346   (and (match_code "const_int")
347        (match_test "IN_RANGE (INTVAL (op), 1, 16)")))
349 (define_predicate "aarch64_simd_shift_imm_offset_si"
350   (and (match_code "const_int")
351        (match_test "IN_RANGE (INTVAL (op), 1, 32)")))
353 (define_predicate "aarch64_simd_shift_imm_offset_di"
354   (and (match_code "const_int")
355        (match_test "IN_RANGE (INTVAL (op), 1, 64)")))
357 (define_predicate "aarch64_simd_shift_imm_bitsize_qi"
358   (and (match_code "const_int")
359        (match_test "IN_RANGE (INTVAL (op), 0, 8)")))
361 (define_predicate "aarch64_simd_shift_imm_bitsize_hi"
362   (and (match_code "const_int")
363        (match_test "IN_RANGE (INTVAL (op), 0, 16)")))
365 (define_predicate "aarch64_simd_shift_imm_bitsize_si"
366   (and (match_code "const_int")
367        (match_test "IN_RANGE (INTVAL (op), 0, 32)")))
369 (define_predicate "aarch64_simd_shift_imm_bitsize_di"
370   (and (match_code "const_int")
371        (match_test "IN_RANGE (INTVAL (op), 0, 64)")))
373 (define_predicate "aarch64_constant_pool_symref"
374    (and (match_code "symbol_ref")
375         (match_test "CONSTANT_POOL_ADDRESS_P (op)")))