1 ;; Predicate definitions for ARM and Thumb
2 ;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
3 ;; Contributed by ARM Ltd.
5 ;; This file is part of GCC.
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.
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.
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_predicate "s_register_operand"
22 (match_code "reg,subreg")
24 if (GET_CODE (op) == SUBREG)
26 /* We don't consider registers whose class is NO_REGS
27 to be a register operand. */
28 /* XXX might have to check for lo regs only for thumb ??? */
30 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
31 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
35 (define_predicate "arm_hard_register_operand"
38 return REGNO (op) < FIRST_PSEUDO_REGISTER;
42 (define_predicate "low_register_operand"
43 (and (match_code "reg")
44 (match_test "REGNO (op) <= LAST_LO_REGNUM")))
46 ;; A low register or const_int.
47 (define_predicate "low_reg_or_int_operand"
48 (ior (match_code "const_int")
49 (match_operand 0 "low_register_operand")))
51 ;; Any core register, or any pseudo. */
52 (define_predicate "arm_general_register_operand"
53 (match_code "reg,subreg")
55 if (GET_CODE (op) == SUBREG)
59 && (REGNO (op) <= LAST_ARM_REGNUM
60 || REGNO (op) >= FIRST_PSEUDO_REGISTER));
63 (define_predicate "vfp_register_operand"
64 (match_code "reg,subreg")
66 if (GET_CODE (op) == SUBREG)
69 /* We don't consider registers whose class is NO_REGS
70 to be a register operand. */
72 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
73 || REGNO_REG_CLASS (REGNO (op)) == VFP_D0_D7_REGS
74 || REGNO_REG_CLASS (REGNO (op)) == VFP_LO_REGS
76 && REGNO_REG_CLASS (REGNO (op)) == VFP_REGS)));
79 (define_predicate "zero_operand"
80 (and (match_code "const_int,const_double,const_vector")
81 (match_test "op == CONST0_RTX (mode)")))
83 ;; Match a register, or zero in the appropriate mode.
84 (define_predicate "reg_or_zero_operand"
85 (ior (match_operand 0 "s_register_operand")
86 (match_operand 0 "zero_operand")))
88 (define_special_predicate "subreg_lowpart_operator"
89 (and (match_code "subreg")
90 (match_test "subreg_lowpart_p (op)")))
92 ;; Reg, subreg(reg) or const_int.
93 (define_predicate "reg_or_int_operand"
94 (ior (match_code "const_int")
95 (match_operand 0 "s_register_operand")))
97 (define_predicate "arm_immediate_operand"
98 (and (match_code "const_int")
99 (match_test "const_ok_for_arm (INTVAL (op))")))
101 ;; A constant value which fits into two instructions, each taking
102 ;; an arithmetic constant operand for one of the words.
103 (define_predicate "arm_immediate_di_operand"
104 (and (match_code "const_int,const_double")
105 (match_test "arm_const_double_by_immediates (op)")))
107 (define_predicate "arm_neg_immediate_operand"
108 (and (match_code "const_int")
109 (match_test "const_ok_for_arm (-INTVAL (op))")))
111 (define_predicate "arm_not_immediate_operand"
112 (and (match_code "const_int")
113 (match_test "const_ok_for_arm (~INTVAL (op))")))
115 (define_predicate "const0_operand"
116 (and (match_code "const_int")
117 (match_test "INTVAL (op) == 0")))
119 ;; Something valid on the RHS of an ARM data-processing instruction
120 (define_predicate "arm_rhs_operand"
121 (ior (match_operand 0 "s_register_operand")
122 (match_operand 0 "arm_immediate_operand")))
124 (define_predicate "arm_rhsm_operand"
125 (ior (match_operand 0 "arm_rhs_operand")
126 (match_operand 0 "memory_operand")))
128 ;; This doesn't have to do much because the constant is already checked
129 ;; in the shift_operator predicate.
130 (define_predicate "shift_amount_operand"
131 (ior (and (match_test "TARGET_ARM")
132 (match_operand 0 "s_register_operand"))
133 (match_operand 0 "const_int_operand")))
135 (define_predicate "const_neon_scalar_shift_amount_operand"
136 (and (match_code "const_int")
137 (match_test "((unsigned HOST_WIDE_INT) INTVAL (op)) <= GET_MODE_BITSIZE (mode)
138 && ((unsigned HOST_WIDE_INT) INTVAL (op)) > 0")))
140 (define_predicate "ldrd_strd_offset_operand"
141 (and (match_operand 0 "const_int_operand")
142 (match_test "TARGET_LDRD && offset_ok_for_ldrd_strd (INTVAL (op))")))
144 (define_predicate "arm_add_operand"
145 (ior (match_operand 0 "arm_rhs_operand")
146 (match_operand 0 "arm_neg_immediate_operand")))
148 (define_predicate "arm_adddi_operand"
149 (ior (match_operand 0 "s_register_operand")
150 (and (match_code "const_int")
151 (match_test "const_ok_for_dimode_op (INTVAL (op), PLUS)"))))
153 (define_predicate "arm_addimm_operand"
154 (ior (match_operand 0 "arm_immediate_operand")
155 (match_operand 0 "arm_neg_immediate_operand")))
157 (define_predicate "arm_not_operand"
158 (ior (match_operand 0 "arm_rhs_operand")
159 (match_operand 0 "arm_not_immediate_operand")))
161 (define_predicate "arm_di_operand"
162 (ior (match_operand 0 "s_register_operand")
163 (match_operand 0 "arm_immediate_di_operand")))
165 ;; True if the operand is a memory reference which contains an
166 ;; offsettable address.
167 (define_predicate "offsettable_memory_operand"
168 (and (match_code "mem")
170 "offsettable_address_p (reload_completed | reload_in_progress,
171 mode, XEXP (op, 0))")))
173 ;; True if the operand is a memory operand that does not have an
174 ;; automodified base register (and thus will not generate output reloads).
175 (define_predicate "call_memory_operand"
176 (and (match_code "mem")
177 (and (match_test "GET_RTX_CLASS (GET_CODE (XEXP (op, 0)))
179 (match_operand 0 "memory_operand"))))
181 (define_predicate "arm_reload_memory_operand"
182 (and (match_code "mem,reg,subreg")
183 (match_test "(!CONSTANT_P (op)
184 && (true_regnum(op) == -1
186 && REGNO (op) >= FIRST_PSEUDO_REGISTER)))")))
188 (define_predicate "vfp_compare_operand"
189 (ior (match_operand 0 "s_register_operand")
190 (and (match_code "const_double")
191 (match_test "arm_const_double_rtx (op)"))))
193 (define_predicate "arm_float_compare_operand"
194 (if_then_else (match_test "TARGET_VFP")
195 (match_operand 0 "vfp_compare_operand")
196 (match_operand 0 "s_register_operand")))
198 ;; True for valid index operands.
199 (define_predicate "index_operand"
200 (ior (match_operand 0 "s_register_operand")
201 (and (match_operand 0 "immediate_operand")
202 (match_test "(!CONST_INT_P (op)
203 || (INTVAL (op) < 4096 && INTVAL (op) > -4096))"))))
205 ;; True for operators that can be combined with a shift in ARM state.
206 (define_special_predicate "shiftable_operator"
207 (and (match_code "plus,minus,ior,xor,and")
208 (match_test "mode == GET_MODE (op)")))
210 ;; True for logical binary operators.
211 (define_special_predicate "logical_binary_operator"
212 (and (match_code "ior,xor,and")
213 (match_test "mode == GET_MODE (op)")))
215 ;; True for commutative operators
216 (define_special_predicate "commutative_binary_operator"
217 (and (match_code "ior,xor,and,plus")
218 (match_test "mode == GET_MODE (op)")))
220 ;; True for shift operators.
222 ;; * mult is only permitted with a constant shift amount
223 ;; * patterns that permit register shift amounts only in ARM mode use
224 ;; shift_amount_operand, patterns that always allow registers do not,
225 ;; so we don't have to worry about that sort of thing here.
226 (define_special_predicate "shift_operator"
227 (and (ior (ior (and (match_code "mult")
228 (match_test "power_of_two_operand (XEXP (op, 1), mode)"))
229 (and (match_code "rotate")
230 (match_test "CONST_INT_P (XEXP (op, 1))
231 && ((unsigned HOST_WIDE_INT) INTVAL (XEXP (op, 1))) < 32")))
232 (and (match_code "ashift,ashiftrt,lshiftrt,rotatert")
233 (match_test "!CONST_INT_P (XEXP (op, 1))
234 || ((unsigned HOST_WIDE_INT) INTVAL (XEXP (op, 1))) < 32")))
235 (match_test "mode == GET_MODE (op)")))
237 ;; True for shift operators which can be used with saturation instructions.
238 (define_special_predicate "sat_shift_operator"
239 (and (ior (and (match_code "mult")
240 (match_test "power_of_two_operand (XEXP (op, 1), mode)"))
241 (and (match_code "ashift,ashiftrt")
242 (match_test "CONST_INT_P (XEXP (op, 1))
243 && ((unsigned HOST_WIDE_INT) INTVAL (XEXP (op, 1)) < 32)")))
244 (match_test "mode == GET_MODE (op)")))
246 ;; True for MULT, to identify which variant of shift_operator is in use.
247 (define_special_predicate "mult_operator"
250 ;; True for operators that have 16-bit thumb variants. */
251 (define_special_predicate "thumb_16bit_operator"
252 (match_code "plus,minus,and,ior,xor"))
255 (define_special_predicate "equality_operator"
256 (match_code "eq,ne"))
258 ;; True for integer comparisons and, if FP is active, for comparisons
259 ;; other than LTGT or UNEQ.
260 (define_special_predicate "expandable_comparison_operator"
261 (match_code "eq,ne,le,lt,ge,gt,geu,gtu,leu,ltu,
262 unordered,ordered,unlt,unle,unge,ungt"))
264 ;; Likewise, but only accept comparisons that are directly supported
265 ;; by ARM condition codes.
266 (define_special_predicate "arm_comparison_operator"
267 (and (match_operand 0 "expandable_comparison_operator")
268 (match_test "maybe_get_arm_condition_code (op) != ARM_NV")))
270 (define_special_predicate "lt_ge_comparison_operator"
271 (match_code "lt,ge"))
273 (define_special_predicate "noov_comparison_operator"
274 (match_code "lt,ge,eq,ne"))
276 (define_special_predicate "minmax_operator"
277 (and (match_code "smin,smax,umin,umax")
278 (match_test "mode == GET_MODE (op)")))
280 (define_special_predicate "cc_register"
281 (and (match_code "reg")
282 (and (match_test "REGNO (op) == CC_REGNUM")
283 (ior (match_test "mode == GET_MODE (op)")
284 (match_test "mode == VOIDmode && GET_MODE_CLASS (GET_MODE (op)) == MODE_CC")))))
286 (define_special_predicate "dominant_cc_register"
289 if (mode == VOIDmode)
291 mode = GET_MODE (op);
293 if (GET_MODE_CLASS (mode) != MODE_CC)
297 return (cc_register (op, mode)
298 && (mode == CC_DNEmode
299 || mode == CC_DEQmode
300 || mode == CC_DLEmode
301 || mode == CC_DLTmode
302 || mode == CC_DGEmode
303 || mode == CC_DGTmode
304 || mode == CC_DLEUmode
305 || mode == CC_DLTUmode
306 || mode == CC_DGEUmode
307 || mode == CC_DGTUmode));
310 (define_special_predicate "arm_extendqisi_mem_op"
311 (and (match_operand 0 "memory_operand")
312 (match_test "TARGET_ARM ? arm_legitimate_address_outer_p (mode,
316 : memory_address_p (QImode, XEXP (op, 0))")))
318 (define_special_predicate "arm_reg_or_extendqisi_mem_op"
319 (ior (match_operand 0 "arm_extendqisi_mem_op")
320 (match_operand 0 "s_register_operand")))
322 (define_predicate "power_of_two_operand"
323 (match_code "const_int")
325 unsigned HOST_WIDE_INT value = INTVAL (op) & 0xffffffff;
327 return value != 0 && (value & (value - 1)) == 0;
330 (define_predicate "nonimmediate_di_operand"
331 (match_code "reg,subreg,mem")
333 if (s_register_operand (op, mode))
336 if (GET_CODE (op) == SUBREG)
337 op = SUBREG_REG (op);
339 return MEM_P (op) && memory_address_p (DImode, XEXP (op, 0));
342 (define_predicate "di_operand"
343 (ior (match_code "const_int,const_double")
344 (and (match_code "reg,subreg,mem")
345 (match_operand 0 "nonimmediate_di_operand"))))
347 (define_predicate "nonimmediate_soft_df_operand"
348 (match_code "reg,subreg,mem")
350 if (s_register_operand (op, mode))
353 if (GET_CODE (op) == SUBREG)
354 op = SUBREG_REG (op);
356 return MEM_P (op) && memory_address_p (DFmode, XEXP (op, 0));
359 (define_predicate "soft_df_operand"
360 (ior (match_code "const_double")
361 (and (match_code "reg,subreg,mem")
362 (match_operand 0 "nonimmediate_soft_df_operand"))))
364 (define_special_predicate "load_multiple_operation"
365 (match_code "parallel")
367 return ldm_stm_operation_p (op, /*load=*/true, SImode,
368 /*consecutive=*/false,
369 /*return_pc=*/false);
372 (define_special_predicate "store_multiple_operation"
373 (match_code "parallel")
375 return ldm_stm_operation_p (op, /*load=*/false, SImode,
376 /*consecutive=*/false,
377 /*return_pc=*/false);
380 (define_special_predicate "pop_multiple_return"
381 (match_code "parallel")
383 return ldm_stm_operation_p (op, /*load=*/true, SImode,
384 /*consecutive=*/false,
388 (define_special_predicate "pop_multiple_fp"
389 (match_code "parallel")
391 return ldm_stm_operation_p (op, /*load=*/true, DFmode,
392 /*consecutive=*/true,
393 /*return_pc=*/false);
396 (define_special_predicate "multi_register_push"
397 (match_code "parallel")
399 if ((GET_CODE (XVECEXP (op, 0, 0)) != SET)
400 || (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC)
401 || (XINT (SET_SRC (XVECEXP (op, 0, 0)), 1) != UNSPEC_PUSH_MULT))
407 (define_predicate "push_mult_memory_operand"
410 /* ??? Given how PUSH_MULT is generated in the prologues, is there
411 any point in testing for thumb1 specially? All of the variants
412 use the same form. */
415 /* ??? No attempt is made to represent STMIA, or validate that
416 the stack adjustment matches the register count. This is
417 true of the ARM/Thumb2 path as well. */
418 rtx x = XEXP (op, 0);
419 if (GET_CODE (x) != PRE_MODIFY)
421 if (XEXP (x, 0) != stack_pointer_rtx)
424 if (GET_CODE (x) != PLUS)
426 if (XEXP (x, 0) != stack_pointer_rtx)
428 return CONST_INT_P (XEXP (x, 1));
431 /* ARM and Thumb2 handle pre-modify in their legitimate_address. */
432 return memory_operand (op, mode);
435 ;;-------------------------------------------------------------------------
440 (define_predicate "thumb1_cmp_operand"
441 (ior (and (match_code "reg,subreg")
442 (match_operand 0 "s_register_operand"))
443 (and (match_code "const_int")
444 (match_test "((unsigned HOST_WIDE_INT) INTVAL (op)) < 256"))))
446 (define_predicate "thumb1_cmpneg_operand"
447 (and (match_code "const_int")
448 (match_test "INTVAL (op) < 0 && INTVAL (op) > -256")))
450 ;; Return TRUE if a result can be stored in OP without clobbering the
451 ;; condition code register. Prior to reload we only accept a
452 ;; register. After reload we have to be able to handle memory as
453 ;; well, since a pseudo may not get a hard reg and reload cannot
454 ;; handle output-reloads on jump insns.
456 ;; We could possibly handle mem before reload as well, but that might
457 ;; complicate things with the need to handle increment
459 (define_predicate "thumb_cbrch_target_operand"
460 (and (match_code "reg,subreg,mem")
461 (ior (match_operand 0 "s_register_operand")
462 (and (match_test "reload_in_progress || reload_completed")
463 (match_operand 0 "memory_operand")))))
465 ;;-------------------------------------------------------------------------
470 (define_predicate "imm_or_reg_operand"
471 (ior (match_operand 0 "immediate_operand")
472 (match_operand 0 "register_operand")))
476 (define_predicate "const_multiple_of_8_operand"
477 (match_code "const_int")
479 unsigned HOST_WIDE_INT val = INTVAL (op);
480 return (val & 7) == 0;
483 (define_predicate "imm_for_neon_mov_operand"
484 (match_code "const_vector,const_int")
486 return neon_immediate_valid_for_move (op, mode, NULL, NULL);
489 (define_predicate "imm_for_neon_lshift_operand"
490 (match_code "const_vector")
492 return neon_immediate_valid_for_shift (op, mode, NULL, NULL, true);
495 (define_predicate "imm_for_neon_rshift_operand"
496 (match_code "const_vector")
498 return neon_immediate_valid_for_shift (op, mode, NULL, NULL, false);
501 (define_predicate "imm_lshift_or_reg_neon"
502 (ior (match_operand 0 "s_register_operand")
503 (match_operand 0 "imm_for_neon_lshift_operand")))
505 (define_predicate "imm_rshift_or_reg_neon"
506 (ior (match_operand 0 "s_register_operand")
507 (match_operand 0 "imm_for_neon_rshift_operand")))
509 (define_predicate "imm_for_neon_logic_operand"
510 (match_code "const_vector")
513 && neon_immediate_valid_for_logic (op, mode, 0, NULL, NULL));
516 (define_predicate "imm_for_neon_inv_logic_operand"
517 (match_code "const_vector")
520 && neon_immediate_valid_for_logic (op, mode, 1, NULL, NULL));
523 (define_predicate "neon_logic_op2"
524 (ior (match_operand 0 "imm_for_neon_logic_operand")
525 (match_operand 0 "s_register_operand")))
527 (define_predicate "neon_inv_logic_op2"
528 (ior (match_operand 0 "imm_for_neon_inv_logic_operand")
529 (match_operand 0 "s_register_operand")))
531 ;; Predicates for named expanders that overlap multiple ISAs.
533 (define_predicate "cmpdi_operand"
534 (and (match_test "TARGET_32BIT")
535 (match_operand 0 "arm_di_operand")))
537 ;; True if the operand is memory reference suitable for a ldrex/strex.
538 (define_predicate "arm_sync_memory_operand"
539 (and (match_operand 0 "memory_operand")
540 (match_code "reg" "0")))
542 ;; Predicates for parallel expanders based on mode.
543 (define_special_predicate "vect_par_constant_high"
544 (match_code "parallel")
546 HOST_WIDE_INT count = XVECLEN (op, 0);
548 int base = GET_MODE_NUNITS (mode);
551 || (count != base/2))
554 if (!VECTOR_MODE_P (mode))
557 for (i = 0; i < count; i++)
559 rtx elt = XVECEXP (op, 0, i);
562 if (!CONST_INT_P (elt))
566 if (val != (base/2) + i)
572 (define_special_predicate "vect_par_constant_low"
573 (match_code "parallel")
575 HOST_WIDE_INT count = XVECLEN (op, 0);
577 int base = GET_MODE_NUNITS (mode);
580 || (count != base/2))
583 if (!VECTOR_MODE_P (mode))
586 for (i = 0; i < count; i++)
588 rtx elt = XVECEXP (op, 0, i);
591 if (!CONST_INT_P (elt))
601 (define_predicate "const_double_vcvt_power_of_two_reciprocal"
602 (and (match_code "const_double")
603 (match_test "TARGET_32BIT && TARGET_VFP
604 && vfp3_const_double_for_fract_bits (op)")))
606 (define_predicate "neon_struct_operand"
607 (and (match_code "mem")
608 (match_test "TARGET_32BIT && neon_vector_mem_operand (op, 2)")))
610 (define_predicate "neon_struct_or_register_operand"
611 (ior (match_operand 0 "neon_struct_operand")
612 (match_operand 0 "s_register_operand")))
614 (define_special_predicate "add_operator"
617 (define_predicate "mem_noofs_operand"
618 (and (match_code "mem")
619 (match_code "reg" "0")))