predicates.md revision 169689
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.  */
119169689Skan      return !TARGET_LONG_CALLS && !SYMBOL_REF_LONG_CALL_P (op);
120169689Skan
121169689Skan    case SYMBOL_GOT_GLOBAL:
122169689Skan      /* Without explicit relocs, there is no special syntax for
123169689Skan	 loading the address of a call destination into a register.
124169689Skan	 Using "la $25,foo; jal $25" would prevent the lazy binding
125169689Skan	 of "foo", so keep the address of global symbols with the
126169689Skan	 jal macro.  */
127169689Skan      return !TARGET_EXPLICIT_RELOCS;
128169689Skan
129169689Skan    default:
130169689Skan      return false;
131169689Skan    }
132169689Skan})
133169689Skan
134169689Skan(define_predicate "call_insn_operand"
135169689Skan  (ior (match_operand 0 "const_call_insn_operand")
136169689Skan       (match_operand 0 "register_operand")))
137169689Skan
138169689Skan;; A legitimate CONST_INT operand that takes more than one instruction
139169689Skan;; to load.
140169689Skan(define_predicate "splittable_const_int_operand"
141169689Skan  (match_code "const_int")
142169689Skan{
143169689Skan  /* When generating mips16 code, LEGITIMATE_CONSTANT_P rejects
144169689Skan     CONST_INTs that can't be loaded using simple insns.  */
145169689Skan  if (TARGET_MIPS16)
146169689Skan    return false;
147169689Skan
148169689Skan  /* Don't handle multi-word moves this way; we don't want to introduce
149169689Skan     the individual word-mode moves until after reload.  */
150169689Skan  if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
151169689Skan    return false;
152169689Skan
153169689Skan  /* Otherwise check whether the constant can be loaded in a single
154169689Skan     instruction.  */
155169689Skan  return !LUI_INT (op) && !SMALL_INT (op) && !SMALL_INT_UNSIGNED (op);
156169689Skan})
157169689Skan
158169689Skan;; A legitimate symbolic operand that takes more than one instruction
159169689Skan;; to load.
160169689Skan(define_predicate "splittable_symbolic_operand"
161169689Skan  (match_code "const,symbol_ref,label_ref")
162169689Skan{
163169689Skan  enum mips_symbol_type symbol_type;
164169689Skan  return (mips_symbolic_constant_p (op, &symbol_type)
165169689Skan	  && mips_split_p[symbol_type]);
166169689Skan})
167169689Skan
168169689Skan(define_predicate "move_operand"
169169689Skan  (match_operand 0 "general_operand")
170169689Skan{
171169689Skan  enum mips_symbol_type symbol_type;
172169689Skan
173169689Skan  /* The thinking here is as follows:
174169689Skan
175169689Skan     (1) The move expanders should split complex load sequences into
176169689Skan	 individual instructions.  Those individual instructions can
177169689Skan	 then be optimized by all rtl passes.
178169689Skan
179169689Skan     (2) The target of pre-reload load sequences should not be used
180169689Skan	 to store temporary results.  If the target register is only
181169689Skan	 assigned one value, reload can rematerialize that value
182169689Skan	 on demand, rather than spill it to the stack.
183169689Skan
184169689Skan     (3) If we allowed pre-reload passes like combine and cse to recreate
185169689Skan	 complex load sequences, we would want to be able to split the
186169689Skan	 sequences before reload as well, so that the pre-reload scheduler
187169689Skan	 can see the individual instructions.  This falls foul of (2);
188169689Skan	 the splitter would be forced to reuse the target register for
189169689Skan	 intermediate results.
190169689Skan
191169689Skan     (4) We want to define complex load splitters for combine.  These
192169689Skan	 splitters can request a temporary scratch register, which avoids
193169689Skan	 the problem in (2).  They allow things like:
194169689Skan
195169689Skan	      (set (reg T1) (high SYM))
196169689Skan	      (set (reg T2) (low (reg T1) SYM))
197169689Skan	      (set (reg X) (plus (reg T2) (const_int OFFSET)))
198169689Skan
199169689Skan	 to be combined into:
200169689Skan
201169689Skan	      (set (reg T3) (high SYM+OFFSET))
202169689Skan	      (set (reg X) (lo_sum (reg T3) SYM+OFFSET))
203169689Skan
204169689Skan	 if T2 is only used this once.  */
205169689Skan  switch (GET_CODE (op))
206169689Skan    {
207169689Skan    case CONST_INT:
208169689Skan      return !splittable_const_int_operand (op, mode);
209169689Skan
210169689Skan    case CONST:
211169689Skan    case SYMBOL_REF:
212169689Skan    case LABEL_REF:
213169689Skan      if (CONST_GP_P (op))
214169689Skan	return true;
215169689Skan      return (mips_symbolic_constant_p (op, &symbol_type)
216169689Skan	      && !mips_split_p[symbol_type]);
217169689Skan
218169689Skan    default:
219169689Skan      return true;
220169689Skan    }
221169689Skan})
222169689Skan
223169689Skan(define_predicate "consttable_operand"
224169689Skan  (match_test "CONSTANT_P (op)"))
225169689Skan
226169689Skan(define_predicate "symbolic_operand"
227169689Skan  (match_code "const,symbol_ref,label_ref")
228169689Skan{
229169689Skan  enum mips_symbol_type type;
230169689Skan  return mips_symbolic_constant_p (op, &type);
231169689Skan})
232169689Skan
233169689Skan(define_predicate "general_symbolic_operand"
234169689Skan  (match_code "const,symbol_ref,label_ref")
235169689Skan{
236169689Skan  enum mips_symbol_type type;
237169689Skan  return mips_symbolic_constant_p (op, &type) && type == SYMBOL_GENERAL;
238169689Skan})
239169689Skan
240169689Skan(define_predicate "global_got_operand"
241169689Skan  (match_code "const,symbol_ref,label_ref")
242169689Skan{
243169689Skan  enum mips_symbol_type type;
244169689Skan  return mips_symbolic_constant_p (op, &type) && type == SYMBOL_GOT_GLOBAL;
245169689Skan})
246169689Skan
247169689Skan(define_predicate "local_got_operand"
248169689Skan  (match_code "const,symbol_ref,label_ref")
249169689Skan{
250169689Skan  enum mips_symbol_type type;
251169689Skan  return mips_symbolic_constant_p (op, &type) && type == SYMBOL_GOT_LOCAL;
252169689Skan})
253169689Skan
254169689Skan(define_predicate "stack_operand"
255169689Skan  (and (match_code "mem")
256169689Skan       (match_test "mips_stack_address_p (XEXP (op, 0), GET_MODE (op))")))
257169689Skan
258169689Skan(define_predicate "macc_msac_operand"
259169689Skan  (ior (and (match_code "plus") (match_test "ISA_HAS_MACC"))
260169689Skan       (and (match_code "minus") (match_test "ISA_HAS_MSAC")))
261169689Skan{
262169689Skan  rtx mult = XEXP (op, GET_CODE (op) == PLUS ? 0 : 1);
263169689Skan  rtx accum = XEXP (op, GET_CODE (op) == PLUS ? 1 : 0);
264169689Skan  return (GET_CODE (mult) == MULT
265169689Skan	  && REG_P (XEXP (mult, 0))
266169689Skan	  && REG_P (XEXP (mult, 1))
267169689Skan	  && REG_P (accum));
268169689Skan})
269169689Skan
270169689Skan
271169689Skan(define_predicate "equality_operator"
272169689Skan  (match_code "eq,ne"))
273169689Skan
274169689Skan(define_predicate "extend_operator"
275169689Skan  (match_code "zero_extend,sign_extend"))
276169689Skan
277169689Skan(define_predicate "trap_comparison_operator"
278169689Skan  (match_code "eq,ne,lt,ltu,ge,geu"))
279169689Skan
280169689Skan(define_predicate "order_operator"
281169689Skan  (match_code "lt,ltu,le,leu,ge,geu,gt,gtu"))
282169689Skan
283169689Skan
284169689Skan(define_predicate "small_data_pattern"
285169689Skan  (and (match_code "set,parallel,unspec,unspec_volatile,prefetch")
286169689Skan       (match_test "mips_small_data_pattern_p (op)")))
287