[AArch64] Remove aarch64_symbolic_constant_p.
[official-gcc.git] / gcc / config / aarch64 / predicates.md
blob3e2b6b34357337aa94f8e55ecb77abaf1e95771d
1 ;; Machine description for AArch64 architecture.
2 ;; Copyright (C) 2009-2013 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_reg_or_zero"
30   (and (match_code "reg,subreg,const_int")
31        (ior (match_operand 0 "register_operand")
32             (match_test "op == const0_rtx"))))
34 (define_predicate "aarch64_reg_or_fp_zero"
35   (and (match_code "reg,subreg,const_double")
36        (ior (match_operand 0 "register_operand")
37             (match_test "aarch64_float_const_zero_rtx_p (op)"))))
39 (define_predicate "aarch64_reg_zero_or_m1_or_1"
40   (and (match_code "reg,subreg,const_int")
41        (ior (match_operand 0 "register_operand")
42             (ior (match_test "op == const0_rtx")
43                  (ior (match_test "op == constm1_rtx")
44                       (match_test "op == const1_rtx"))))))
46 (define_predicate "aarch64_fp_compare_operand"
47   (ior (match_operand 0 "register_operand")
48        (and (match_code "const_double")
49             (match_test "aarch64_float_const_zero_rtx_p (op)"))))
51 (define_predicate "aarch64_plus_immediate"
52   (and (match_code "const_int")
53        (ior (match_test "aarch64_uimm12_shift (INTVAL (op))")
54             (match_test "aarch64_uimm12_shift (-INTVAL (op))"))))
56 (define_predicate "aarch64_plus_operand"
57   (ior (match_operand 0 "register_operand")
58        (match_operand 0 "aarch64_plus_immediate")))
60 (define_predicate "aarch64_pluslong_immediate"
61   (and (match_code "const_int")
62        (match_test "(INTVAL (op) < 0xffffff && INTVAL (op) > -0xffffff)")))
64 (define_predicate "aarch64_pluslong_operand"
65   (ior (match_operand 0 "register_operand")
66        (match_operand 0 "aarch64_pluslong_immediate")))
68 (define_predicate "aarch64_logical_immediate"
69   (and (match_code "const_int")
70        (match_test "aarch64_bitmask_imm (INTVAL (op), mode)")))
72 (define_predicate "aarch64_logical_operand"
73   (ior (match_operand 0 "register_operand")
74        (match_operand 0 "aarch64_logical_immediate")))
76 (define_predicate "aarch64_shift_imm_si"
77   (and (match_code "const_int")
78        (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) < 32")))
80 (define_predicate "aarch64_shift_imm_di"
81   (and (match_code "const_int")
82        (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) < 64")))
84 (define_predicate "aarch64_reg_or_shift_imm_si"
85   (ior (match_operand 0 "register_operand")
86        (match_operand 0 "aarch64_shift_imm_si")))
88 (define_predicate "aarch64_reg_or_shift_imm_di"
89   (ior (match_operand 0 "register_operand")
90        (match_operand 0 "aarch64_shift_imm_di")))
92 ;; The imm3 field is a 3-bit field that only accepts immediates in the
93 ;; range 0..4.
94 (define_predicate "aarch64_imm3"
95   (and (match_code "const_int")
96        (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) <= 4")))
98 (define_predicate "aarch64_pwr_imm3"
99   (and (match_code "const_int")
100        (match_test "INTVAL (op) != 0
101                     && (unsigned) exact_log2 (INTVAL (op)) <= 4")))
103 (define_predicate "aarch64_pwr_2_si"
104   (and (match_code "const_int")
105        (match_test "INTVAL (op) != 0
106                     && (unsigned) exact_log2 (INTVAL (op)) < 32")))
108 (define_predicate "aarch64_pwr_2_di"
109   (and (match_code "const_int")
110        (match_test "INTVAL (op) != 0
111                     && (unsigned) exact_log2 (INTVAL (op)) < 64")))
113 (define_predicate "aarch64_mem_pair_operand"
114   (and (match_code "mem")
115        (match_test "aarch64_legitimate_address_p (mode, XEXP (op, 0), PARALLEL,
116                                                0)")))
118 (define_predicate "aarch64_valid_symref"
119   (match_code "const, symbol_ref, label_ref")
121   return (aarch64_classify_symbolic_expression (op, SYMBOL_CONTEXT_ADR)
122           != SYMBOL_FORCE_TO_MEM);
125 (define_predicate "aarch64_tls_ie_symref"
126   (match_code "const, symbol_ref, label_ref")
128   switch (GET_CODE (op))
129     {
130     case CONST:
131       op = XEXP (op, 0);
132       if (GET_CODE (op) != PLUS
133           || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
134           || GET_CODE (XEXP (op, 1)) != CONST_INT)
135         return false;
136       op = XEXP (op, 0);
138     case SYMBOL_REF:
139       return SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_INITIAL_EXEC;
141     default:
142       gcc_unreachable ();
143     }
146 (define_predicate "aarch64_tls_le_symref"
147   (match_code "const, symbol_ref, label_ref")
149   switch (GET_CODE (op))
150     {
151     case CONST:
152       op = XEXP (op, 0);
153       if (GET_CODE (op) != PLUS
154           || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
155           || GET_CODE (XEXP (op, 1)) != CONST_INT)
156         return false;
157       op = XEXP (op, 0);
159     case SYMBOL_REF:
160       return SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_EXEC;
162     default:
163       gcc_unreachable ();
164     }
167 (define_predicate "aarch64_mov_operand"
168   (and (match_code "reg,subreg,mem,const,const_int,symbol_ref,label_ref,high")
169        (ior (match_operand 0 "register_operand")
170             (ior (match_operand 0 "memory_operand")
171                  (match_test "aarch64_mov_operand_p (op, SYMBOL_CONTEXT_ADR, mode)")))))
173 (define_predicate "aarch64_movti_operand"
174   (and (match_code "reg,subreg,mem,const_int")
175        (ior (match_operand 0 "register_operand")
176             (ior (match_operand 0 "memory_operand")
177                  (match_operand 0 "const_int_operand")))))
179 (define_predicate "aarch64_reg_or_imm"
180   (and (match_code "reg,subreg,const_int")
181        (ior (match_operand 0 "register_operand")
182             (match_operand 0 "const_int_operand"))))
184 ;; True for integer comparisons and for FP comparisons other than LTGT or UNEQ.
185 (define_special_predicate "aarch64_comparison_operator"
186   (match_code "eq,ne,le,lt,ge,gt,geu,gtu,leu,ltu,unordered,ordered,unlt,unle,unge,ungt"))
188 ;; True if the operand is memory reference suitable for a load/store exclusive.
189 (define_predicate "aarch64_sync_memory_operand"
190   (and (match_operand 0 "memory_operand")
191        (match_code "reg" "0")))
193 ;; Predicates for parallel expanders based on mode.
194 (define_special_predicate "vect_par_cnst_hi_half"
195   (match_code "parallel")
197   HOST_WIDE_INT count = XVECLEN (op, 0);
198   int nunits = GET_MODE_NUNITS (mode);
199   int i;
201   if (count < 1
202       || count != nunits / 2)
203     return false;
205   if (!VECTOR_MODE_P (mode))
206     return false;
208   for (i = 0; i < count; i++)
209    {
210      rtx elt = XVECEXP (op, 0, i);
211      int val;
213      if (GET_CODE (elt) != CONST_INT)
214        return false;
216      val = INTVAL (elt);
217      if (val != (nunits / 2) + i)
218        return false;
219    }
220   return true;
223 (define_special_predicate "vect_par_cnst_lo_half"
224   (match_code "parallel")
226   HOST_WIDE_INT count = XVECLEN (op, 0);
227   int nunits = GET_MODE_NUNITS (mode);
228   int i;
230   if (count < 1
231       || count != nunits / 2)
232     return false;
234   if (!VECTOR_MODE_P (mode))
235     return false;
237   for (i = 0; i < count; i++)
238    {
239      rtx elt = XVECEXP (op, 0, i);
240      int val;
242      if (GET_CODE (elt) != CONST_INT)
243        return false;
245      val = INTVAL (elt);
246      if (val != i)
247        return false;
248    }
249   return true;
253 (define_special_predicate "aarch64_simd_lshift_imm"
254   (match_code "const_vector")
256   return aarch64_simd_shift_imm_p (op, mode, true);
259 (define_special_predicate "aarch64_simd_rshift_imm"
260   (match_code "const_vector")
262   return aarch64_simd_shift_imm_p (op, mode, false);
265 (define_predicate "aarch64_simd_reg_or_zero"
266   (and (match_code "reg,subreg,const_int,const_vector")
267        (ior (match_operand 0 "register_operand")
268            (ior (match_test "op == const0_rtx")
269                 (match_test "aarch64_simd_imm_zero_p (op, mode)")))))
271 (define_predicate "aarch64_simd_struct_operand"
272   (and (match_code "mem")
273        (match_test "TARGET_SIMD && aarch64_simd_mem_operand_p (op)")))
275 ;; Like general_operand but allow only valid SIMD addressing modes.
276 (define_predicate "aarch64_simd_general_operand"
277   (and (match_operand 0 "general_operand")
278        (match_test "!MEM_P (op)
279                     || GET_CODE (XEXP (op, 0)) == POST_INC
280                     || GET_CODE (XEXP (op, 0)) == REG")))
282 ;; Like nonimmediate_operand but allow only valid SIMD addressing modes.
283 (define_predicate "aarch64_simd_nonimmediate_operand"
284   (and (match_operand 0 "nonimmediate_operand")
285        (match_test "!MEM_P (op)
286                     || GET_CODE (XEXP (op, 0)) == POST_INC
287                     || GET_CODE (XEXP (op, 0)) == REG")))
289 (define_special_predicate "aarch64_simd_imm_zero"
290   (match_code "const_vector")
292   return aarch64_simd_imm_zero_p (op, mode);