1;; Predicate definitions for Tilera TILEPro chip.
2;; Copyright (C) 2011-2020 Free Software Foundation, Inc.
3;; Contributed by Walter Lee (walt@tilera.com)
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
9;; by the Free Software Foundation; either version 3, or (at your
10;; option) any later version.
11;;
12;; GCC is distributed in the hope that it will be useful, but WITHOUT
13;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15;; License for more details.
16;;
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/>.
20
21;; Return true if OP is the zero constant for MODE.
22(define_predicate "const_zero_operand"
23  (and (match_code "const_int,const_double,const_vector")
24       (match_test "op == CONST0_RTX (mode)")))
25
26;; Returns true if OP is either the constant zero or a register.
27(define_predicate "reg_or_0_operand"
28  (and (ior (match_operand 0 "register_operand")
29	    (match_operand 0 "const_zero_operand"))
30       (match_test "GET_MODE_SIZE (mode) <= UNITS_PER_WORD")))
31
32; Return 1 if OP is a network register identifier.
33(define_predicate "netreg_operand"
34  (and (match_code "const_int")
35       (match_test "IN_RANGE (INTVAL (op), 0, 6)")))
36
37; Return 1 if OP is an unsigned 5-bit constant.
38(define_predicate "u5bit_cint_operand"
39  (and (match_code "const_int")
40       (match_test "INTVAL (op) == (INTVAL (op) & 0x1F)")))
41
42;; Return 1 if OP is an unsigned 16-bit constant.
43(define_predicate "u16bit_cint_operand"
44  (and (match_code "const_int")
45       (match_test "(unsigned HOST_WIDE_INT)INTVAL (op) < (1U << 16)")))
46
47;; Return 1 if OP is a signed 8-bit constant.
48(define_predicate "s8bit_cint_operand"
49  (and (match_code "const_int")
50       (match_test "satisfies_constraint_I (op)")))
51
52;; Return 1 if OP is a signed 16-bit constant.
53(define_predicate "s16bit_cint_operand"
54  (and (match_code "const_int")
55       (match_test "satisfies_constraint_J (op)")))
56
57;; Return 1 if OP is a nonzero integer constant whose low 16 bits are zero.
58(define_predicate "auli_cint_operand"
59  (and (match_code "const_int")
60       (match_test "satisfies_constraint_K (op)")))
61
62;; Return 1 if OP is an unsigned 15-bit constant.
63(define_predicate "u15bit_cint_operand"
64  (and (match_code "const_int")
65       (match_test "(unsigned HOST_WIDE_INT)INTVAL (op) < (1U << 15)")))
66
67;; Return 1 if OP is a constant or any register.
68(define_predicate "reg_or_cint_operand"
69  (ior (match_operand 0 "register_operand")
70       (match_operand 0 "const_int_operand")))
71
72;; Return 1 if OP is a 4-element vector constant with identical signed
73;; 8-bit elements or any register.
74(define_predicate "reg_or_v4s8bit_operand"
75  (ior (match_operand 0 "register_operand")
76       (and (match_code "const_vector")
77	    (match_test "CONST_VECTOR_NUNITS (op) == 4
78                         && (satisfies_constraint_I
79			     (unwrap_const_vec_duplicate (op)))"))))
80
81;; Return 1 if OP is a 2-element vector constant with identical signed
82;; 8-bit elements or any register.
83(define_predicate "reg_or_v2s8bit_operand"
84  (ior (match_operand 0 "register_operand")
85       (and (match_code "const_vector")
86	    (match_test "CONST_VECTOR_NUNITS (op) == 2
87                         && (satisfies_constraint_I
88			     (unwrap_const_vec_duplicate (op)))"))))
89
90;; Return 1 if the operand is a valid second operand to an add insn.
91(define_predicate "add_operand"
92  (if_then_else (match_code "const_int")
93    (match_test "satisfies_constraint_J (op) || satisfies_constraint_K (op)")
94    (match_operand 0 "register_operand")))
95
96;; Return 1 if the operand is a register or signed 8-bit immediate operand.
97(define_predicate "reg_or_s8bit_operand"
98  (if_then_else (match_code "const_int")
99    (match_test "satisfies_constraint_I (op)")
100    (match_operand 0 "register_operand")))
101
102;; Return 1 for an operand suitable for ANDing with a register.
103(define_predicate "and_operand"
104  (if_then_else (match_code "const_int")
105    (match_test "satisfies_constraint_I (op) || satisfies_constraint_M (op)")
106    (match_operand 0 "register_operand")))
107
108;; Return 1 if the operand is a register or unsigned 5-bit immediate operand.
109(define_predicate "reg_or_u5bit_operand"
110  (if_then_else (match_code "const_int")
111    (match_test "INTVAL (op) == (INTVAL (op) & 0x1F)")
112    (match_operand 0 "register_operand")))
113
114; Return 1 if the operand is 2, 4 or 8.
115(define_predicate "cint_248_operand"
116  (and (match_code "const_int")
117       (match_test
118        "INTVAL (op) == 2 || INTVAL (op) == 4 || INTVAL (op) == 8")))
119
120
121;; Return true if OP is a TLS symbolic operand.
122(define_predicate "tls_symbolic_operand"
123  (and (match_code "symbol_ref")
124       (match_test "SYMBOL_REF_TLS_MODEL (op) !=  TLS_MODEL_NONE")))
125
126;; Return true if OP is a symbolic operand for the TLS Global Dynamic model.
127(define_predicate "tls_gd_symbolic_operand"
128  (and (match_code "symbol_ref")
129       (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_GLOBAL_DYNAMIC")))
130
131;; Return true if OP is a symbolic operand for the TLS Local Dynamic model.
132(define_predicate "tls_ld_symbolic_operand"
133  (and (match_code "symbol_ref")
134       (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_DYNAMIC")))
135
136;; Return true if OP is a symbolic operand that can be used for the
137;; TLS Initial Exec model.
138(define_predicate "tls_ie_symbolic_operand"
139  (and (match_code "symbol_ref")
140       (ior (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_INITIAL_EXEC")
141            (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_EXEC"))))
142
143;; Return true if OP is a symbolic operand for the TLS Local Exec model.
144(define_predicate "tls_le_symbolic_operand"
145  (and (match_code "symbol_ref")
146       (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_EXEC")))
147
148;; Returns true if OP is any general operand except for an
149;; auto-incrementing address operand.
150(define_predicate "nonautoinc_operand"
151  (and (match_operand 0 "general_operand")
152       (not (ior (match_code "pre_dec") (match_code "pre_inc")
153		 (match_code "post_dec") (match_code "post_inc")
154		 (match_code "post_modify") (match_code "pre_modify")))))
155
156;; Returns true if OP is a non-auto-incrementing memory operand.
157(define_predicate "nonautoincmem_operand"
158  (match_operand 0 "memory_operand")
159{
160  return nonautoinc_operand (XEXP (op, 0), GET_MODE (XEXP (op, 0)));
161})
162
163;; Returns true if OP is a non-auto-incrementing memory, general
164;; operand.
165(define_predicate "nonautoincmem_general_operand"
166  (match_operand 0 "general_operand")
167{
168  if (memory_operand (op, mode))
169    return nonautoinc_operand (XEXP (op, 0), GET_MODE (XEXP (op, 0)));
170  else
171    return true;
172})
173
174;; Returns true if OP is a non-auto-incrementing memory, non-immediate
175;; operand.
176(define_predicate "nonautoincmem_nonimmediate_operand"
177  (match_operand 0 "nonimmediate_operand")
178{
179  if (memory_operand (op, mode))
180    return nonautoinc_operand (XEXP (op, 0), GET_MODE (XEXP (op, 0)));
181  else
182    return true;
183})
184
185;; Return true if OP is a valid operand for the source of a move insn.
186(define_predicate "move_operand"
187  (match_operand 0 "general_operand")
188{
189  /* If both modes are non-void they must be the same.  */
190  if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
191    return false;
192
193  if (GET_MODE_SIZE (mode) > 4)
194    return false;
195
196  switch (GET_CODE (op))
197    {
198    case CONST_INT:
199      return (satisfies_constraint_J (op)
200              || satisfies_constraint_K (op)
201              || satisfies_constraint_N (op)
202              || satisfies_constraint_P (op));
203
204    case HIGH:
205      return true;
206
207    case MEM:
208      return memory_address_p (mode, XEXP (op, 0));
209
210    default:
211      return register_operand (op, mode);
212    }
213})
214
215;; Returns 1 if OP is a symbolic operand, i.e. a symbol_ref or a label_ref,
216;; possibly with an offset.
217(define_predicate "symbolic_operand"
218  (ior (match_code "symbol_ref,label_ref")
219       (and (match_code "const")
220	    (match_test "GET_CODE (XEXP (op,0)) == PLUS
221			 && (GET_CODE (XEXP (XEXP (op,0), 0)) == SYMBOL_REF
222			     || GET_CODE (XEXP (XEXP (op,0), 0)) == LABEL_REF)
223			 && CONST_INT_P (XEXP (XEXP (op,0), 1))"))))
224
225;; Returns 1 if OP is a symbolic operand, or a const unspec wrapper
226;; representing a got reference, a tls reference, or pc-relative
227;; reference.
228(define_predicate "const_symbolic_operand"
229  (ior (match_operand 0 "symbolic_operand")
230       (and (match_code "const")
231	    (match_test "GET_CODE (XEXP (op,0)) == UNSPEC")
232	    (ior (match_test "XINT (XEXP (op,0), 1) == UNSPEC_GOT16_SYM")
233		 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_GOT32_SYM")
234		 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_PCREL_SYM")
235		 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_TLS_GD")
236		 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_TLS_IE")
237		 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_TLS_LE")))))
238
239;; Return true if OP is an address suitable for a call insn.
240;; Call insn on TILE can take a PC-relative constant address
241;; or any regular memory address.
242(define_predicate "call_address_operand"
243  (ior (match_operand 0 "symbolic_operand")
244       (match_test "memory_address_p (Pmode, op)")))
245
246;; Return true if OP is an operand suitable for a call insn.
247(define_predicate "call_operand"
248  (and (match_code "mem")
249       (match_test "call_address_operand (XEXP (op, 0), mode)")))
250
251;; Return 1 if OP is a signed comparison operation.
252;; We can use these directly in compares against zero.
253(define_predicate "signed_comparison_operator"
254  (match_code "eq,ne,le,lt,ge,gt"))
255
256;; Return 1 if OP is a equal or not-equal operation.
257(define_predicate "eqne_operator"
258  (match_code "eq,ne"))
259