1169689Skan;; Predicate definitions for MIPS.
2169689Skan;; Copyright (C) 2004 Free Software Foundation, Inc.
3169689Skan;;
4169689Skan;; This file is part of GCC.
5169689Skan;;
6169689Skan;; GCC is free software; you can redistribute it and/or modify
7169689Skan;; it under the terms of the GNU General Public License as published by
8169689Skan;; the Free Software Foundation; either version 2, or (at your option)
9169689Skan;; any later version.
10169689Skan;;
11169689Skan;; GCC is distributed in the hope that it will be useful,
12169689Skan;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13169689Skan;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14169689Skan;; GNU General Public License for more details.
15169689Skan;;
16169689Skan;; You should have received a copy of the GNU General Public License
17169689Skan;; along with GCC; see the file COPYING.  If not, write to
18169689Skan;; the Free Software Foundation, 51 Franklin Street, Fifth Floor,
19169689Skan;; Boston, MA 02110-1301, USA.
20169689Skan
21169689Skan(define_predicate "const_uns_arith_operand"
22169689Skan  (and (match_code "const_int")
23169689Skan       (match_test "SMALL_OPERAND_UNSIGNED (INTVAL (op))")))
24169689Skan
25169689Skan(define_predicate "uns_arith_operand"
26169689Skan  (ior (match_operand 0 "const_uns_arith_operand")
27169689Skan       (match_operand 0 "register_operand")))
28169689Skan
29169689Skan(define_predicate "const_arith_operand"
30169689Skan  (and (match_code "const_int")
31169689Skan       (match_test "SMALL_OPERAND (INTVAL (op))")))
32169689Skan
33169689Skan(define_predicate "arith_operand"
34169689Skan  (ior (match_operand 0 "const_arith_operand")
35169689Skan       (match_operand 0 "register_operand")))
36169689Skan
37169689Skan(define_predicate "const_uimm6_operand"
38169689Skan  (and (match_code "const_int")
39169689Skan       (match_test "UIMM6_OPERAND (INTVAL (op))")))
40169689Skan
41169689Skan(define_predicate "const_imm10_operand"
42169689Skan  (and (match_code "const_int")
43169689Skan       (match_test "IMM10_OPERAND (INTVAL (op))")))
44169689Skan
45169689Skan(define_predicate "reg_imm10_operand"
46169689Skan  (ior (match_operand 0 "const_imm10_operand")
47169689Skan       (match_operand 0 "register_operand")))
48169689Skan
49169689Skan(define_predicate "sle_operand"
50169689Skan  (and (match_code "const_int")
51169689Skan       (match_test "SMALL_OPERAND (INTVAL (op) + 1)")))
52169689Skan
53169689Skan(define_predicate "sleu_operand"
54169689Skan  (and (match_operand 0 "sle_operand")
55169689Skan       (match_test "INTVAL (op) + 1 != 0")))
56169689Skan
57169689Skan(define_predicate "const_0_operand"
58169689Skan  (and (match_code "const_int,const_double,const_vector")
59169689Skan       (match_test "op == CONST0_RTX (GET_MODE (op))")))
60169689Skan
61169689Skan(define_predicate "reg_or_0_operand"
62169689Skan  (ior (and (match_operand 0 "const_0_operand")
63169689Skan	    (match_test "!TARGET_MIPS16"))
64169689Skan       (match_operand 0 "register_operand")))
65169689Skan
66169689Skan(define_predicate "const_1_operand"
67169689Skan  (and (match_code "const_int,const_double,const_vector")
68169689Skan       (match_test "op == CONST1_RTX (GET_MODE (op))")))
69169689Skan
70169689Skan(define_predicate "reg_or_1_operand"
71169689Skan  (ior (match_operand 0 "const_1_operand")
72169689Skan       (match_operand 0 "register_operand")))
73169689Skan
74169689Skan;; This is used for indexing into vectors, and hence only accepts const_int.
75169689Skan(define_predicate "const_0_or_1_operand"
76169689Skan  (and (match_code "const_int")
77169689Skan       (ior (match_test "op == CONST0_RTX (GET_MODE (op))")
78169689Skan	    (match_test "op == CONST1_RTX (GET_MODE (op))"))))
79169689Skan
80169689Skan(define_predicate "fpr_operand"
81169689Skan  (and (match_code "reg")
82169689Skan       (match_test "FP_REG_P (REGNO (op))")))
83169689Skan
84169689Skan(define_predicate "lo_operand"
85169689Skan  (and (match_code "reg")
86169689Skan       (match_test "REGNO (op) == LO_REGNUM")))
87169689Skan
88169689Skan(define_predicate "fcc_reload_operand"
89169689Skan  (and (match_code "reg,subreg")
90169689Skan       (match_test "ST_REG_P (true_regnum (op))")))
91169689Skan
92169689Skan(define_special_predicate "pc_or_label_operand"
93169689Skan  (match_code "pc,label_ref"))
94169689Skan
95169689Skan(define_predicate "const_call_insn_operand"
96169689Skan  (match_code "const,symbol_ref,label_ref")
97169689Skan{
98169689Skan  enum mips_symbol_type symbol_type;
99169689Skan
100169689Skan  if (!mips_symbolic_constant_p (op, &symbol_type))
101169689Skan    return false;
102169689Skan
103169689Skan  switch (symbol_type)
104169689Skan    {
105169689Skan    case SYMBOL_GENERAL:
106169689Skan      /* We can only use direct calls for TARGET_ABSOLUTE_ABICALLS if we
107169689Skan	 are sure that the target function does not need $25 to be live
108169689Skan	 on entry.  This is true for any locally-defined function because
109169689Skan	 any such function will use %hi/%lo accesses to set up $gp.  */
110169689Skan      if (TARGET_ABSOLUTE_ABICALLS
111169689Skan          && !(GET_CODE (op) == SYMBOL_REF
112169689Skan	       && SYMBOL_REF_DECL (op)
113169689Skan	       && !DECL_EXTERNAL (SYMBOL_REF_DECL (op))))
114169689Skan	return false;
115169689Skan
116169689Skan      /* If -mlong-calls, force all calls to use register addressing.  Also,
117169689Skan	 if this function has the long_call attribute, we must use register
118169689Skan	 addressing.  */
119220150Smm      return (!TARGET_LONG_CALLS
120220150Smm	      && !(GET_CODE (op) == SYMBOL_REF
121220150Smm		   && SYMBOL_REF_LONG_CALL_P (op)));
122169689Skan
123169689Skan    case SYMBOL_GOT_GLOBAL:
124169689Skan      /* Without explicit relocs, there is no special syntax for
125169689Skan	 loading the address of a call destination into a register.
126169689Skan	 Using "la $25,foo; jal $25" would prevent the lazy binding
127169689Skan	 of "foo", so keep the address of global symbols with the
128169689Skan	 jal macro.  */
129169689Skan      return !TARGET_EXPLICIT_RELOCS;
130169689Skan
131169689Skan    default:
132169689Skan      return false;
133169689Skan    }
134169689Skan})
135169689Skan
136169689Skan(define_predicate "call_insn_operand"
137169689Skan  (ior (match_operand 0 "const_call_insn_operand")
138169689Skan       (match_operand 0 "register_operand")))
139169689Skan
140169689Skan;; A legitimate CONST_INT operand that takes more than one instruction
141169689Skan;; to load.
142169689Skan(define_predicate "splittable_const_int_operand"
143169689Skan  (match_code "const_int")
144169689Skan{
145169689Skan  /* When generating mips16 code, LEGITIMATE_CONSTANT_P rejects
146169689Skan     CONST_INTs that can't be loaded using simple insns.  */
147169689Skan  if (TARGET_MIPS16)
148169689Skan    return false;
149169689Skan
150169689Skan  /* Don't handle multi-word moves this way; we don't want to introduce
151169689Skan     the individual word-mode moves until after reload.  */
152169689Skan  if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
153169689Skan    return false;
154169689Skan
155169689Skan  /* Otherwise check whether the constant can be loaded in a single
156169689Skan     instruction.  */
157169689Skan  return !LUI_INT (op) && !SMALL_INT (op) && !SMALL_INT_UNSIGNED (op);
158169689Skan})
159169689Skan
160169689Skan;; A legitimate symbolic operand that takes more than one instruction
161169689Skan;; to load.
162169689Skan(define_predicate "splittable_symbolic_operand"
163169689Skan  (match_code "const,symbol_ref,label_ref")
164169689Skan{
165169689Skan  enum mips_symbol_type symbol_type;
166169689Skan  return (mips_symbolic_constant_p (op, &symbol_type)
167169689Skan	  && mips_split_p[symbol_type]);
168169689Skan})
169169689Skan
170169689Skan(define_predicate "move_operand"
171169689Skan  (match_operand 0 "general_operand")
172169689Skan{
173169689Skan  enum mips_symbol_type symbol_type;
174169689Skan
175169689Skan  /* The thinking here is as follows:
176169689Skan
177169689Skan     (1) The move expanders should split complex load sequences into
178169689Skan	 individual instructions.  Those individual instructions can
179169689Skan	 then be optimized by all rtl passes.
180169689Skan
181169689Skan     (2) The target of pre-reload load sequences should not be used
182169689Skan	 to store temporary results.  If the target register is only
183169689Skan	 assigned one value, reload can rematerialize that value
184169689Skan	 on demand, rather than spill it to the stack.
185169689Skan
186169689Skan     (3) If we allowed pre-reload passes like combine and cse to recreate
187169689Skan	 complex load sequences, we would want to be able to split the
188169689Skan	 sequences before reload as well, so that the pre-reload scheduler
189169689Skan	 can see the individual instructions.  This falls foul of (2);
190169689Skan	 the splitter would be forced to reuse the target register for
191169689Skan	 intermediate results.
192169689Skan
193169689Skan     (4) We want to define complex load splitters for combine.  These
194169689Skan	 splitters can request a temporary scratch register, which avoids
195169689Skan	 the problem in (2).  They allow things like:
196169689Skan
197169689Skan	      (set (reg T1) (high SYM))
198169689Skan	      (set (reg T2) (low (reg T1) SYM))
199169689Skan	      (set (reg X) (plus (reg T2) (const_int OFFSET)))
200169689Skan
201169689Skan	 to be combined into:
202169689Skan
203169689Skan	      (set (reg T3) (high SYM+OFFSET))
204169689Skan	      (set (reg X) (lo_sum (reg T3) SYM+OFFSET))
205169689Skan
206169689Skan	 if T2 is only used this once.  */
207169689Skan  switch (GET_CODE (op))
208169689Skan    {
209169689Skan    case CONST_INT:
210169689Skan      return !splittable_const_int_operand (op, mode);
211169689Skan
212169689Skan    case CONST:
213169689Skan    case SYMBOL_REF:
214169689Skan    case LABEL_REF:
215169689Skan      if (CONST_GP_P (op))
216169689Skan	return true;
217169689Skan      return (mips_symbolic_constant_p (op, &symbol_type)
218169689Skan	      && !mips_split_p[symbol_type]);
219169689Skan
220169689Skan    default:
221169689Skan      return true;
222169689Skan    }
223169689Skan})
224169689Skan
225169689Skan(define_predicate "consttable_operand"
226169689Skan  (match_test "CONSTANT_P (op)"))
227169689Skan
228169689Skan(define_predicate "symbolic_operand"
229169689Skan  (match_code "const,symbol_ref,label_ref")
230169689Skan{
231169689Skan  enum mips_symbol_type type;
232169689Skan  return mips_symbolic_constant_p (op, &type);
233169689Skan})
234169689Skan
235169689Skan(define_predicate "general_symbolic_operand"
236169689Skan  (match_code "const,symbol_ref,label_ref")
237169689Skan{
238169689Skan  enum mips_symbol_type type;
239169689Skan  return mips_symbolic_constant_p (op, &type) && type == SYMBOL_GENERAL;
240169689Skan})
241169689Skan
242169689Skan(define_predicate "global_got_operand"
243169689Skan  (match_code "const,symbol_ref,label_ref")
244169689Skan{
245169689Skan  enum mips_symbol_type type;
246169689Skan  return mips_symbolic_constant_p (op, &type) && type == SYMBOL_GOT_GLOBAL;
247169689Skan})
248169689Skan
249169689Skan(define_predicate "local_got_operand"
250169689Skan  (match_code "const,symbol_ref,label_ref")
251169689Skan{
252169689Skan  enum mips_symbol_type type;
253169689Skan  return mips_symbolic_constant_p (op, &type) && type == SYMBOL_GOT_LOCAL;
254169689Skan})
255169689Skan
256169689Skan(define_predicate "stack_operand"
257169689Skan  (and (match_code "mem")
258169689Skan       (match_test "mips_stack_address_p (XEXP (op, 0), GET_MODE (op))")))
259169689Skan
260169689Skan(define_predicate "macc_msac_operand"
261169689Skan  (ior (and (match_code "plus") (match_test "ISA_HAS_MACC"))
262169689Skan       (and (match_code "minus") (match_test "ISA_HAS_MSAC")))
263169689Skan{
264169689Skan  rtx mult = XEXP (op, GET_CODE (op) == PLUS ? 0 : 1);
265169689Skan  rtx accum = XEXP (op, GET_CODE (op) == PLUS ? 1 : 0);
266169689Skan  return (GET_CODE (mult) == MULT
267169689Skan	  && REG_P (XEXP (mult, 0))
268169689Skan	  && REG_P (XEXP (mult, 1))
269169689Skan	  && REG_P (accum));
270169689Skan})
271169689Skan
272169689Skan
273169689Skan(define_predicate "equality_operator"
274169689Skan  (match_code "eq,ne"))
275169689Skan
276169689Skan(define_predicate "extend_operator"
277169689Skan  (match_code "zero_extend,sign_extend"))
278169689Skan
279169689Skan(define_predicate "trap_comparison_operator"
280169689Skan  (match_code "eq,ne,lt,ltu,ge,geu"))
281169689Skan
282169689Skan(define_predicate "order_operator"
283169689Skan  (match_code "lt,ltu,le,leu,ge,geu,gt,gtu"))
284169689Skan
285169689Skan
286169689Skan(define_predicate "small_data_pattern"
287169689Skan  (and (match_code "set,parallel,unspec,unspec_volatile,prefetch")
288169689Skan       (match_test "mips_small_data_pattern_p (op)")))
289