1 ;; Predicate definitions for MIPS.
2 ;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
4 ;; This file is part of GCC.
6 ;; GCC is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 3, or (at your option)
11 ;; GCC is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;; GNU General Public License for more details.
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GCC; see the file COPYING3. If not see
18 ;; <http://www.gnu.org/licenses/>.
20 (define_predicate "const_uns_arith_operand"
21 (and (match_code "const_int")
22 (match_test "SMALL_OPERAND_UNSIGNED (INTVAL (op))")))
24 (define_predicate "uns_arith_operand"
25 (ior (match_operand 0 "const_uns_arith_operand")
26 (match_operand 0 "register_operand")))
28 (define_predicate "const_arith_operand"
29 (and (match_code "const_int")
30 (match_test "SMALL_OPERAND (INTVAL (op))")))
32 (define_predicate "arith_operand"
33 (ior (match_operand 0 "const_arith_operand")
34 (match_operand 0 "register_operand")))
36 (define_predicate "const_uimm6_operand"
37 (and (match_code "const_int")
38 (match_test "UIMM6_OPERAND (INTVAL (op))")))
40 (define_predicate "const_imm10_operand"
41 (and (match_code "const_int")
42 (match_test "IMM10_OPERAND (INTVAL (op))")))
44 (define_predicate "reg_imm10_operand"
45 (ior (match_operand 0 "const_imm10_operand")
46 (match_operand 0 "register_operand")))
48 (define_predicate "sle_operand"
49 (and (match_code "const_int")
50 (match_test "SMALL_OPERAND (INTVAL (op) + 1)")))
52 (define_predicate "sleu_operand"
53 (and (match_operand 0 "sle_operand")
54 (match_test "INTVAL (op) + 1 != 0")))
56 (define_predicate "const_0_operand"
57 (and (match_code "const_int,const_double,const_vector")
58 (match_test "op == CONST0_RTX (GET_MODE (op))")))
60 (define_predicate "reg_or_0_operand"
61 (ior (and (match_operand 0 "const_0_operand")
62 (not (match_test "TARGET_MIPS16")))
63 (match_operand 0 "register_operand")))
65 (define_predicate "const_1_operand"
66 (and (match_code "const_int,const_double,const_vector")
67 (match_test "op == CONST1_RTX (GET_MODE (op))")))
69 (define_predicate "reg_or_1_operand"
70 (ior (match_operand 0 "const_1_operand")
71 (match_operand 0 "register_operand")))
73 ;; This is used for indexing into vectors, and hence only accepts const_int.
74 (define_predicate "const_0_or_1_operand"
75 (and (match_code "const_int")
76 (match_test "IN_RANGE (INTVAL (op), 0, 1)")))
78 (define_predicate "const_2_or_3_operand"
79 (and (match_code "const_int")
80 (match_test "IN_RANGE (INTVAL (op), 2, 3)")))
82 (define_predicate "const_0_to_3_operand"
83 (and (match_code "const_int")
84 (match_test "IN_RANGE (INTVAL (op), 0, 3)")))
86 (define_predicate "qi_mask_operand"
87 (and (match_code "const_int")
88 (match_test "UINTVAL (op) == 0xff")))
90 (define_predicate "hi_mask_operand"
91 (and (match_code "const_int")
92 (match_test "UINTVAL (op) == 0xffff")))
94 (define_predicate "si_mask_operand"
95 (and (match_code "const_int")
96 (match_test "UINTVAL (op) == 0xffffffff")))
98 (define_predicate "and_load_operand"
99 (ior (match_operand 0 "qi_mask_operand")
100 (match_operand 0 "hi_mask_operand")
101 (match_operand 0 "si_mask_operand")))
103 (define_predicate "low_bitmask_operand"
104 (and (match_test "ISA_HAS_EXT_INS")
105 (match_code "const_int")
106 (match_test "low_bitmask_len (mode, INTVAL (op)) > 16")))
108 (define_predicate "and_reg_operand"
109 (ior (match_operand 0 "register_operand")
110 (and (not (match_test "TARGET_MIPS16"))
111 (match_operand 0 "const_uns_arith_operand"))
112 (match_operand 0 "low_bitmask_operand")
113 (match_operand 0 "si_mask_operand")))
115 (define_predicate "and_operand"
116 (ior (match_operand 0 "and_load_operand")
117 (match_operand 0 "and_reg_operand")))
119 (define_predicate "d_operand"
120 (and (match_code "reg")
121 (match_test "TARGET_MIPS16
122 ? M16_REG_P (REGNO (op))
123 : GP_REG_P (REGNO (op))")))
125 (define_predicate "lwsp_swsp_operand"
126 (and (match_code "mem")
127 (match_test "lwsp_swsp_address_p (XEXP (op, 0), mode)")))
129 (define_predicate "lw16_sw16_operand"
130 (and (match_code "mem")
131 (match_test "m16_based_address_p (XEXP (op, 0), mode, uw4_operand)")))
133 (define_predicate "lhu16_sh16_operand"
134 (and (match_code "mem")
135 (match_test "m16_based_address_p (XEXP (op, 0), mode, uh4_operand)")))
137 (define_predicate "lbu16_operand"
138 (and (match_code "mem")
139 (match_test "m16_based_address_p (XEXP (op, 0), mode, db4_operand)")))
141 (define_predicate "sb16_operand"
142 (and (match_code "mem")
143 (match_test "m16_based_address_p (XEXP (op, 0), mode, ub4_operand)")))
145 (define_predicate "db4_operand"
146 (and (match_code "const_int")
147 (match_test "mips_unsigned_immediate_p (INTVAL (op) + 1, 4, 0)")))
149 (define_predicate "db7_operand"
150 (and (match_code "const_int")
151 (match_test "mips_unsigned_immediate_p (INTVAL (op) + 1, 7, 0)")))
153 (define_predicate "db8_operand"
154 (and (match_code "const_int")
155 (match_test "mips_unsigned_immediate_p (INTVAL (op) + 1, 8, 0)")))
157 (define_predicate "ib3_operand"
158 (and (match_code "const_int")
159 (match_test "mips_unsigned_immediate_p (INTVAL (op) - 1, 3, 0)")))
161 (define_predicate "sb4_operand"
162 (and (match_code "const_int")
163 (match_test "mips_signed_immediate_p (INTVAL (op), 4, 0)")))
165 (define_predicate "sb5_operand"
166 (and (match_code "const_int")
167 (match_test "mips_signed_immediate_p (INTVAL (op), 5, 0)")))
169 (define_predicate "sb8_operand"
170 (and (match_code "const_int")
171 (match_test "mips_signed_immediate_p (INTVAL (op), 8, 0)")))
173 (define_predicate "sd8_operand"
174 (and (match_code "const_int")
175 (match_test "mips_signed_immediate_p (INTVAL (op), 8, 3)")))
177 (define_predicate "ub4_operand"
178 (and (match_code "const_int")
179 (match_test "mips_unsigned_immediate_p (INTVAL (op), 4, 0)")))
181 (define_predicate "ub8_operand"
182 (and (match_code "const_int")
183 (match_test "mips_unsigned_immediate_p (INTVAL (op), 8, 0)")))
185 (define_predicate "uh4_operand"
186 (and (match_code "const_int")
187 (match_test "mips_unsigned_immediate_p (INTVAL (op), 4, 1)")))
189 (define_predicate "uw4_operand"
190 (and (match_code "const_int")
191 (match_test "mips_unsigned_immediate_p (INTVAL (op), 4, 2)")))
193 (define_predicate "uw5_operand"
194 (and (match_code "const_int")
195 (match_test "mips_unsigned_immediate_p (INTVAL (op), 5, 2)")))
197 (define_predicate "uw6_operand"
198 (and (match_code "const_int")
199 (match_test "mips_unsigned_immediate_p (INTVAL (op), 6, 2)")))
201 (define_predicate "uw8_operand"
202 (and (match_code "const_int")
203 (match_test "mips_unsigned_immediate_p (INTVAL (op), 8, 2)")))
205 (define_predicate "addiur2_operand"
206 (and (match_code "const_int")
207 (ior (match_test "INTVAL (op) == -1")
208 (match_test "INTVAL (op) == 1")
209 (match_test "INTVAL (op) == 4")
210 (match_test "INTVAL (op) == 8")
211 (match_test "INTVAL (op) == 12")
212 (match_test "INTVAL (op) == 16")
213 (match_test "INTVAL (op) == 20")
214 (match_test "INTVAL (op) == 24"))))
216 (define_predicate "addiusp_operand"
217 (and (match_code "const_int")
218 (ior (match_test "(IN_RANGE (INTVAL (op), 2, 257))")
219 (match_test "(IN_RANGE (INTVAL (op), -258, -3))"))))
221 (define_predicate "andi16_operand"
222 (and (match_code "const_int")
223 (ior (match_test "IN_RANGE (INTVAL (op), 1, 4)")
224 (match_test "IN_RANGE (INTVAL (op), 7, 8)")
225 (match_test "IN_RANGE (INTVAL (op), 15, 16)")
226 (match_test "IN_RANGE (INTVAL (op), 31, 32)")
227 (match_test "IN_RANGE (INTVAL (op), 63, 64)")
228 (match_test "INTVAL (op) == 255")
229 (match_test "INTVAL (op) == 32768")
230 (match_test "INTVAL (op) == 65535"))))
232 (define_predicate "movep_src_register"
233 (and (match_code "reg")
234 (ior (match_test ("IN_RANGE (REGNO (op), 2, 3)"))
235 (match_test ("IN_RANGE (REGNO (op), 16, 20)")))))
237 (define_predicate "movep_src_operand"
238 (ior (match_operand 0 "const_0_operand")
239 (match_operand 0 "movep_src_register")))
241 (define_predicate "lo_operand"
242 (and (match_code "reg")
243 (match_test "REGNO (op) == LO_REGNUM")))
245 (define_predicate "hilo_operand"
246 (and (match_code "reg")
247 (match_test "MD_REG_P (REGNO (op))")))
249 (define_predicate "fcc_reload_operand"
250 (and (match_code "reg,subreg")
251 (match_test "ST_REG_P (true_regnum (op))")))
253 (define_predicate "muldiv_target_operand"
254 (if_then_else (match_test "TARGET_MIPS16")
255 (match_operand 0 "hilo_operand")
256 (match_operand 0 "register_operand")))
258 (define_predicate "const_call_insn_operand"
259 (match_code "const,symbol_ref,label_ref")
261 enum mips_symbol_type symbol_type;
263 if (!mips_symbolic_constant_p (op, SYMBOL_CONTEXT_CALL, &symbol_type))
268 case SYMBOL_ABSOLUTE:
269 /* We can only use direct calls if we're sure that the target
270 function does not need $25 to be valid on entry. */
271 if (mips_use_pic_fn_addr_reg_p (op))
274 /* If -mlong-calls or if this function has an explicit long_call
275 attribute, we must use register addressing. The
276 SYMBOL_FLAG_LONG_CALL bit is set by mips_encode_section_info. */
277 return !(GET_CODE (op) == SYMBOL_REF && SYMBOL_REF_LONG_CALL_P (op));
279 case SYMBOL_GOT_DISP:
280 /* Without explicit relocs, there is no special syntax for
281 loading the address of a call destination into a register.
282 Using "la $25,foo; jal $25" would prevent the lazy binding
283 of "foo", so keep the address of global symbols with the
285 return !TARGET_EXPLICIT_RELOCS;
292 (define_predicate "call_insn_operand"
293 (ior (match_operand 0 "const_call_insn_operand")
294 (match_operand 0 "register_operand")))
296 ;; A legitimate CONST_INT operand that takes more than one instruction
298 (define_predicate "splittable_const_int_operand"
299 (match_code "const_int")
301 /* When generating mips16 code, TARGET_LEGITIMATE_CONSTANT_P rejects
302 CONST_INTs that can't be loaded using simple insns. */
306 /* Don't handle multi-word moves this way; we don't want to introduce
307 the individual word-mode moves until after reload. */
308 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
311 /* Otherwise check whether the constant can be loaded in a single
313 return !LUI_INT (op) && !SMALL_INT (op) && !SMALL_INT_UNSIGNED (op);
316 (define_predicate "move_operand"
317 ;; Allow HI and LO to be used as the source of a MIPS16 move.
318 (ior (match_operand 0 "general_operand")
319 (match_operand 0 "hilo_operand"))
321 enum mips_symbol_type symbol_type;
323 /* The thinking here is as follows:
325 (1) The move expanders should split complex load sequences into
326 individual instructions. Those individual instructions can
327 then be optimized by all rtl passes.
329 (2) The target of pre-reload load sequences should not be used
330 to store temporary results. If the target register is only
331 assigned one value, reload can rematerialize that value
332 on demand, rather than spill it to the stack.
334 (3) If we allowed pre-reload passes like combine and cse to recreate
335 complex load sequences, we would want to be able to split the
336 sequences before reload as well, so that the pre-reload scheduler
337 can see the individual instructions. This falls foul of (2);
338 the splitter would be forced to reuse the target register for
339 intermediate results.
341 (4) We want to define complex load splitters for combine. These
342 splitters can request a temporary scratch register, which avoids
343 the problem in (2). They allow things like:
345 (set (reg T1) (high SYM))
346 (set (reg T2) (low (reg T1) SYM))
347 (set (reg X) (plus (reg T2) (const_int OFFSET)))
351 (set (reg T3) (high SYM+OFFSET))
352 (set (reg X) (lo_sum (reg T3) SYM+OFFSET))
354 if T2 is only used this once. */
355 switch (GET_CODE (op))
358 return !splittable_const_int_operand (op, mode);
365 return (mips_symbolic_constant_p (op, SYMBOL_CONTEXT_LEA, &symbol_type)
366 && !mips_split_p[symbol_type]);
370 return (mips_symbolic_constant_p (op, SYMBOL_CONTEXT_LEA, &symbol_type)
371 && !mips_split_hi_p[symbol_type]);
378 (define_predicate "cprestore_save_slot_operand"
379 (and (match_code "mem")
380 (match_test "mips_cprestore_address_p (XEXP (op, 0), false)")))
382 (define_predicate "cprestore_load_slot_operand"
383 (and (match_code "mem")
384 (match_test "mips_cprestore_address_p (XEXP (op, 0), true)")))
386 (define_predicate "consttable_operand"
387 (match_test "CONSTANT_P (op)"))
389 (define_predicate "symbolic_operand"
390 (match_code "const,symbol_ref,label_ref")
392 enum mips_symbol_type type;
393 return mips_symbolic_constant_p (op, SYMBOL_CONTEXT_LEA, &type);
396 (define_predicate "absolute_symbolic_operand"
397 (match_code "const,symbol_ref,label_ref")
399 enum mips_symbol_type type;
400 return (mips_symbolic_constant_p (op, SYMBOL_CONTEXT_LEA, &type)
401 && type == SYMBOL_ABSOLUTE);
404 (define_predicate "symbolic_operand_with_high"
405 (match_code "const,symbol_ref,label_ref")
407 enum mips_symbol_type type;
408 return (mips_symbolic_constant_p (op, SYMBOL_CONTEXT_LEA, &type)
409 && mips_hi_relocs[(int) type]);
412 (define_predicate "force_to_mem_operand"
413 (match_code "const,symbol_ref,label_ref")
415 enum mips_symbol_type symbol_type;
416 return (mips_symbolic_constant_p (op, SYMBOL_CONTEXT_LEA, &symbol_type)
417 && mips_use_pcrel_pool_p[(int) symbol_type]);
420 (define_predicate "got_disp_operand"
421 (match_code "const,symbol_ref,label_ref")
423 enum mips_symbol_type type;
424 return (mips_symbolic_constant_p (op, SYMBOL_CONTEXT_LEA, &type)
425 && type == SYMBOL_GOT_DISP);
428 (define_predicate "got_page_ofst_operand"
429 (match_code "const,symbol_ref,label_ref")
431 enum mips_symbol_type type;
432 return (mips_symbolic_constant_p (op, SYMBOL_CONTEXT_LEA, &type)
433 && type == SYMBOL_GOT_PAGE_OFST);
436 (define_predicate "tls_reloc_operand"
437 (match_code "const,symbol_ref,label_ref")
439 enum mips_symbol_type type;
440 return (mips_symbolic_constant_p (op, SYMBOL_CONTEXT_LEA, &type)
441 && (type == SYMBOL_DTPREL || type == SYMBOL_TPREL));
444 (define_predicate "symbol_ref_operand"
445 (match_code "symbol_ref"))
447 (define_predicate "stack_operand"
448 (and (match_code "mem")
449 (match_test "mips_stack_address_p (XEXP (op, 0), GET_MODE (op))")))
451 (define_predicate "macc_msac_operand"
452 (ior (and (match_code "plus") (match_test "ISA_HAS_MACC"))
453 (and (match_code "minus") (match_test "ISA_HAS_MSAC")))
455 rtx mult = XEXP (op, GET_CODE (op) == PLUS ? 0 : 1);
456 rtx accum = XEXP (op, GET_CODE (op) == PLUS ? 1 : 0);
457 return (GET_CODE (mult) == MULT
458 && REG_P (XEXP (mult, 0))
459 && REG_P (XEXP (mult, 1))
464 (define_predicate "equality_operator"
465 (match_code "eq,ne"))
467 (define_predicate "extend_operator"
468 (match_code "zero_extend,sign_extend"))
470 (define_predicate "trap_comparison_operator"
471 (match_code "eq,ne,lt,ltu,ge,geu"))
473 (define_predicate "order_operator"
474 (match_code "lt,ltu,le,leu,ge,geu,gt,gtu"))
476 ;; For NE, cstore uses sltu instructions in which the first operand is $0.
477 ;; This isn't possible in mips16 code.
479 (define_predicate "mips_cstore_operator"
480 (ior (match_code "eq,gt,gtu,ge,geu,lt,ltu,le,leu")
481 (and (match_code "ne") (not (match_test "TARGET_MIPS16")))))
483 (define_predicate "small_data_pattern"
484 (and (match_code "set,parallel,unspec,unspec_volatile,prefetch")
485 (match_test "mips_small_data_pattern_p (op)")))
487 (define_predicate "mem_noofs_operand"
488 (and (match_code "mem")
489 (match_code "reg" "0")))
491 ;; Return 1 if the operand is in non-volatile memory.
492 (define_predicate "non_volatile_mem_operand"
493 (and (match_operand 0 "memory_operand")
494 (not (match_test "MEM_VOLATILE_P (op)"))))