OSDN Git Service

89dcb29a25086d511b138c9fc934d7fc8ec1b0d6
[pf3gnuchains/gcc-fork.git] / gcc / config / arm / predicates.md
1 ;; Predicate definitions for ARM and Thumb
2 ;; Copyright (C) 2004, 2007, 2008 Free Software Foundation, Inc.
3 ;; Contributed by ARM Ltd.
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 (define_predicate "s_register_operand"
22   (match_code "reg,subreg")
23 {
24   if (GET_CODE (op) == SUBREG)
25     op = SUBREG_REG (op);
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 ??? */
29   return (GET_CODE (op) == REG
30           && (REGNO (op) >= FIRST_PSEUDO_REGISTER
31               || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
32 })
33
34 ;; Any hard register.
35 (define_predicate "arm_hard_register_operand"
36   (match_code "reg")
37 {
38   return REGNO (op) < FIRST_PSEUDO_REGISTER;
39 })
40
41 ;; A low register.
42 (define_predicate "low_register_operand"
43   (and (match_code "reg")
44        (match_test "REGNO (op) <= LAST_LO_REGNUM")))
45
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")))
50
51 ;; Any core register, or any pseudo.  */ 
52 (define_predicate "arm_general_register_operand"
53   (match_code "reg,subreg")
54 {
55   if (GET_CODE (op) == SUBREG)
56     op = SUBREG_REG (op);
57
58   return (GET_CODE (op) == REG
59           && (REGNO (op) <= LAST_ARM_REGNUM
60               || REGNO (op) >= FIRST_PSEUDO_REGISTER));
61 })
62
63 (define_predicate "f_register_operand"
64   (match_code "reg,subreg")
65 {
66   if (GET_CODE (op) == SUBREG)
67     op = SUBREG_REG (op);
68
69   /* We don't consider registers whose class is NO_REGS
70      to be a register operand.  */
71   return (GET_CODE (op) == REG
72           && (REGNO (op) >= FIRST_PSEUDO_REGISTER
73               || REGNO_REG_CLASS (REGNO (op)) == FPA_REGS));
74 })
75
76 (define_predicate "vfp_register_operand"
77   (match_code "reg,subreg")
78 {
79   if (GET_CODE (op) == SUBREG)
80     op = SUBREG_REG (op);
81
82   /* We don't consider registers whose class is NO_REGS
83      to be a register operand.  */
84   return (GET_CODE (op) == REG
85           && (REGNO (op) >= FIRST_PSEUDO_REGISTER
86               || REGNO_REG_CLASS (REGNO (op)) == VFP_LO_REGS
87               || (TARGET_VFPD32
88                   && REGNO_REG_CLASS (REGNO (op)) == VFP_REGS)));
89 })
90
91 (define_special_predicate "subreg_lowpart_operator"
92   (and (match_code "subreg")
93        (match_test "subreg_lowpart_p (op)")))
94
95 ;; Reg, subreg(reg) or const_int.
96 (define_predicate "reg_or_int_operand"
97   (ior (match_code "const_int")
98        (match_operand 0 "s_register_operand")))
99
100 (define_predicate "arm_immediate_operand"
101   (and (match_code "const_int")
102        (match_test "const_ok_for_arm (INTVAL (op))")))
103
104 ;; A constant value which fits into two instructions, each taking
105 ;; an arithmetic constant operand for one of the words.
106 (define_predicate "arm_immediate_di_operand"
107   (and (match_code "const_int,const_double")
108        (match_test "arm_const_double_by_immediates (op)")))
109
110 (define_predicate "arm_neg_immediate_operand"
111   (and (match_code "const_int")
112        (match_test "const_ok_for_arm (-INTVAL (op))")))
113
114 (define_predicate "arm_not_immediate_operand"
115   (and (match_code "const_int")
116        (match_test "const_ok_for_arm (~INTVAL (op))")))
117
118 (define_predicate "const0_operand"
119   (and (match_code "const_int")
120        (match_test "INTVAL (op) == 0")))
121
122 ;; Something valid on the RHS of an ARM data-processing instruction
123 (define_predicate "arm_rhs_operand"
124   (ior (match_operand 0 "s_register_operand")
125        (match_operand 0 "arm_immediate_operand")))
126
127 (define_predicate "arm_rhsm_operand"
128   (ior (match_operand 0 "arm_rhs_operand")
129        (match_operand 0 "memory_operand")))
130
131 (define_predicate "arm_add_operand"
132   (ior (match_operand 0 "arm_rhs_operand")
133        (match_operand 0 "arm_neg_immediate_operand")))
134
135 (define_predicate "arm_addimm_operand"
136   (ior (match_operand 0 "arm_immediate_operand")
137        (match_operand 0 "arm_neg_immediate_operand")))
138
139 (define_predicate "arm_not_operand"
140   (ior (match_operand 0 "arm_rhs_operand")
141        (match_operand 0 "arm_not_immediate_operand")))
142
143 (define_predicate "arm_di_operand"
144   (ior (match_operand 0 "s_register_operand")
145        (match_operand 0 "arm_immediate_di_operand")))
146
147 ;; True if the operand is a memory reference which contains an
148 ;; offsettable address.
149 (define_predicate "offsettable_memory_operand"
150   (and (match_code "mem")
151        (match_test
152         "offsettable_address_p (reload_completed | reload_in_progress,
153                                 mode, XEXP (op, 0))")))
154
155 ;; True if the operand is a memory operand that does not have an
156 ;; automodified base register (and thus will not generate output reloads).
157 (define_predicate "call_memory_operand"
158   (and (match_code "mem")
159        (and (match_test "GET_RTX_CLASS (GET_CODE (XEXP (op, 0)))
160                          != RTX_AUTOINC")
161             (match_operand 0 "memory_operand"))))
162
163 (define_predicate "arm_reload_memory_operand"
164   (and (match_code "mem,reg,subreg")
165        (match_test "(!CONSTANT_P (op)
166                      && (true_regnum(op) == -1
167                          || (GET_CODE (op) == REG
168                              && REGNO (op) >= FIRST_PSEUDO_REGISTER)))")))
169
170 ;; True for valid operands for the rhs of an floating point insns.
171 ;;   Allows regs or certain consts on FPA, just regs for everything else.
172 (define_predicate "arm_float_rhs_operand"
173   (ior (match_operand 0 "s_register_operand")
174        (and (match_code "const_double")
175             (match_test "TARGET_FPA && arm_const_double_rtx (op)"))))
176
177 (define_predicate "arm_float_add_operand"
178   (ior (match_operand 0 "arm_float_rhs_operand")
179        (and (match_code "const_double")
180             (match_test "TARGET_FPA && neg_const_double_rtx_ok_for_fpa (op)"))))
181
182 (define_predicate "vfp_compare_operand"
183   (ior (match_operand 0 "s_register_operand")
184        (and (match_code "const_double")
185             (match_test "arm_const_double_rtx (op)"))))
186
187 (define_predicate "arm_float_compare_operand"
188   (if_then_else (match_test "TARGET_VFP")
189                 (match_operand 0 "vfp_compare_operand")
190                 (match_operand 0 "arm_float_rhs_operand")))
191
192 ;; True for valid index operands.
193 (define_predicate "index_operand"
194   (ior (match_operand 0 "s_register_operand")
195        (and (match_operand 0 "immediate_operand")
196             (match_test "(GET_CODE (op) != CONST_INT
197                           || (INTVAL (op) < 4096 && INTVAL (op) > -4096))"))))
198
199 ;; True for operators that can be combined with a shift in ARM state.
200 (define_special_predicate "shiftable_operator"
201   (and (match_code "plus,minus,ior,xor,and")
202        (match_test "mode == GET_MODE (op)")))
203
204 ;; True for logical binary operators.
205 (define_special_predicate "logical_binary_operator"
206   (and (match_code "ior,xor,and")
207        (match_test "mode == GET_MODE (op)")))
208
209 ;; True for shift operators.
210 (define_special_predicate "shift_operator"
211   (and (ior (ior (and (match_code "mult")
212                       (match_test "power_of_two_operand (XEXP (op, 1), mode)"))
213                  (and (match_code "rotate")
214                       (match_test "GET_CODE (XEXP (op, 1)) == CONST_INT
215                                    && ((unsigned HOST_WIDE_INT) INTVAL (XEXP (op, 1))) < 32")))
216             (match_code "ashift,ashiftrt,lshiftrt,rotatert"))
217        (match_test "mode == GET_MODE (op)")))
218
219 ;; True for operators that have 16-bit thumb variants.  */
220 (define_special_predicate "thumb_16bit_operator"
221   (match_code "plus,minus,and,ior,xor"))
222
223 ;; True for EQ & NE
224 (define_special_predicate "equality_operator"
225   (match_code "eq,ne"))
226
227 ;; True for integer comparisons and, if FP is active, for comparisons
228 ;; other than LTGT or UNEQ.
229 (define_special_predicate "arm_comparison_operator"
230   (ior (match_code "eq,ne,le,lt,ge,gt,geu,gtu,leu,ltu")
231        (and (match_test "TARGET_32BIT && TARGET_HARD_FLOAT
232                          && (TARGET_FPA || TARGET_VFP)")
233             (match_code "unordered,ordered,unlt,unle,unge,ungt"))))
234
235 (define_special_predicate "lt_ge_comparison_operator"
236   (match_code "lt,ge"))
237
238 (define_special_predicate "noov_comparison_operator"
239   (match_code "lt,ge,eq,ne"))
240
241 (define_special_predicate "minmax_operator"
242   (and (match_code "smin,smax,umin,umax")
243        (match_test "mode == GET_MODE (op)")))
244
245 (define_special_predicate "cc_register"
246   (and (match_code "reg")
247        (and (match_test "REGNO (op) == CC_REGNUM")
248             (ior (match_test "mode == GET_MODE (op)")
249                  (match_test "mode == VOIDmode && GET_MODE_CLASS (GET_MODE (op)) == MODE_CC")))))
250
251 (define_special_predicate "dominant_cc_register"
252   (match_code "reg")
253 {
254   if (mode == VOIDmode)
255     {
256       mode = GET_MODE (op);
257       
258       if (GET_MODE_CLASS (mode) != MODE_CC)
259         return false;
260     }
261
262   return (cc_register (op, mode)
263           && (mode == CC_DNEmode
264              || mode == CC_DEQmode
265              || mode == CC_DLEmode
266              || mode == CC_DLTmode
267              || mode == CC_DGEmode
268              || mode == CC_DGTmode
269              || mode == CC_DLEUmode
270              || mode == CC_DLTUmode
271              || mode == CC_DGEUmode
272              || mode == CC_DGTUmode));
273 })
274
275 (define_special_predicate "arm_extendqisi_mem_op"
276   (and (match_operand 0 "memory_operand")
277        (match_test "arm_legitimate_address_outer_p (mode, XEXP (op, 0),
278                                                     SIGN_EXTEND, 0)")))
279
280 (define_special_predicate "arm_reg_or_extendqisi_mem_op"
281   (ior (match_operand 0 "arm_extendqisi_mem_op")
282        (match_operand 0 "s_register_operand")))
283
284 (define_predicate "power_of_two_operand"
285   (match_code "const_int")
286 {
287   HOST_WIDE_INT value = INTVAL (op);
288
289   return value != 0 && (value & (value - 1)) == 0;
290 })
291
292 (define_predicate "nonimmediate_di_operand"
293   (match_code "reg,subreg,mem")
294 {
295    if (s_register_operand (op, mode))
296      return true;
297
298    if (GET_CODE (op) == SUBREG)
299      op = SUBREG_REG (op);
300
301    return GET_CODE (op) == MEM && memory_address_p (DImode, XEXP (op, 0));
302 })
303
304 (define_predicate "di_operand"
305   (ior (match_code "const_int,const_double")
306        (and (match_code "reg,subreg,mem")
307             (match_operand 0 "nonimmediate_di_operand"))))
308
309 (define_predicate "nonimmediate_soft_df_operand"
310   (match_code "reg,subreg,mem")
311 {
312   if (s_register_operand (op, mode))
313     return true;
314
315   if (GET_CODE (op) == SUBREG)
316     op = SUBREG_REG (op);
317
318   return GET_CODE (op) == MEM && memory_address_p (DFmode, XEXP (op, 0));
319 })
320
321 (define_predicate "soft_df_operand"
322   (ior (match_code "const_double")
323        (and (match_code "reg,subreg,mem")
324             (match_operand 0 "nonimmediate_soft_df_operand"))))
325
326 (define_predicate "const_shift_operand"
327   (and (match_code "const_int")
328        (ior (match_operand 0 "power_of_two_operand")
329             (match_test "((unsigned HOST_WIDE_INT) INTVAL (op)) < 32"))))
330
331
332 (define_special_predicate "load_multiple_operation"
333   (match_code "parallel")
334 {
335   HOST_WIDE_INT count = XVECLEN (op, 0);
336   int dest_regno;
337   rtx src_addr;
338   HOST_WIDE_INT i = 1, base = 0;
339   rtx elt;
340
341   if (count <= 1
342       || GET_CODE (XVECEXP (op, 0, 0)) != SET)
343     return false;
344
345   /* Check to see if this might be a write-back.  */
346   if (GET_CODE (SET_SRC (elt = XVECEXP (op, 0, 0))) == PLUS)
347     {
348       i++;
349       base = 1;
350
351       /* Now check it more carefully.  */
352       if (GET_CODE (SET_DEST (elt)) != REG
353           || GET_CODE (XEXP (SET_SRC (elt), 0)) != REG
354           || GET_CODE (XEXP (SET_SRC (elt), 1)) != CONST_INT
355           || INTVAL (XEXP (SET_SRC (elt), 1)) != (count - 1) * 4)
356         return false;
357     }
358
359   /* Perform a quick check so we don't blow up below.  */
360   if (count <= i
361       || GET_CODE (XVECEXP (op, 0, i - 1)) != SET
362       || GET_CODE (SET_DEST (XVECEXP (op, 0, i - 1))) != REG
363       || GET_CODE (SET_SRC (XVECEXP (op, 0, i - 1))) != MEM)
364     return false;
365
366   dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, i - 1)));
367   src_addr = XEXP (SET_SRC (XVECEXP (op, 0, i - 1)), 0);
368
369   for (; i < count; i++)
370     {
371       elt = XVECEXP (op, 0, i);
372
373       if (GET_CODE (elt) != SET
374           || GET_CODE (SET_DEST (elt)) != REG
375           || GET_MODE (SET_DEST (elt)) != SImode
376           || REGNO (SET_DEST (elt)) != (unsigned int)(dest_regno + i - base)
377           || GET_CODE (SET_SRC (elt)) != MEM
378           || GET_MODE (SET_SRC (elt)) != SImode
379           || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
380           || !rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
381           || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
382           || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != (i - base) * 4)
383         return false;
384     }
385
386   return true;
387 })
388
389 (define_special_predicate "store_multiple_operation"
390   (match_code "parallel")
391 {
392   HOST_WIDE_INT count = XVECLEN (op, 0);
393   int src_regno;
394   rtx dest_addr;
395   HOST_WIDE_INT i = 1, base = 0;
396   rtx elt;
397
398   if (count <= 1
399       || GET_CODE (XVECEXP (op, 0, 0)) != SET)
400     return false;
401
402   /* Check to see if this might be a write-back.  */
403   if (GET_CODE (SET_SRC (elt = XVECEXP (op, 0, 0))) == PLUS)
404     {
405       i++;
406       base = 1;
407
408       /* Now check it more carefully.  */
409       if (GET_CODE (SET_DEST (elt)) != REG
410           || GET_CODE (XEXP (SET_SRC (elt), 0)) != REG
411           || GET_CODE (XEXP (SET_SRC (elt), 1)) != CONST_INT
412           || INTVAL (XEXP (SET_SRC (elt), 1)) != (count - 1) * 4)
413         return false;
414     }
415
416   /* Perform a quick check so we don't blow up below.  */
417   if (count <= i
418       || GET_CODE (XVECEXP (op, 0, i - 1)) != SET
419       || GET_CODE (SET_DEST (XVECEXP (op, 0, i - 1))) != MEM
420       || GET_CODE (SET_SRC (XVECEXP (op, 0, i - 1))) != REG)
421     return false;
422
423   src_regno = REGNO (SET_SRC (XVECEXP (op, 0, i - 1)));
424   dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, i - 1)), 0);
425
426   for (; i < count; i++)
427     {
428       elt = XVECEXP (op, 0, i);
429
430       if (GET_CODE (elt) != SET
431           || GET_CODE (SET_SRC (elt)) != REG
432           || GET_MODE (SET_SRC (elt)) != SImode
433           || REGNO (SET_SRC (elt)) != (unsigned int)(src_regno + i - base)
434           || GET_CODE (SET_DEST (elt)) != MEM
435           || GET_MODE (SET_DEST (elt)) != SImode
436           || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
437           || !rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
438           || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
439           || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != (i - base) * 4)
440         return false;
441     }
442
443   return true;
444 })
445
446 (define_special_predicate "multi_register_push"
447   (match_code "parallel")
448 {
449   if ((GET_CODE (XVECEXP (op, 0, 0)) != SET)
450       || (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC)
451       || (XINT (SET_SRC (XVECEXP (op, 0, 0)), 1) != UNSPEC_PUSH_MULT))
452     return false;
453
454   return true;
455 })
456
457 ;;-------------------------------------------------------------------------
458 ;;
459 ;; Thumb predicates
460 ;;
461
462 (define_predicate "thumb1_cmp_operand"
463   (ior (and (match_code "reg,subreg")
464             (match_operand 0 "s_register_operand"))
465        (and (match_code "const_int")
466             (match_test "((unsigned HOST_WIDE_INT) INTVAL (op)) < 256"))))
467
468 (define_predicate "thumb1_cmpneg_operand"
469   (and (match_code "const_int")
470        (match_test "INTVAL (op) < 0 && INTVAL (op) > -256")))
471
472 ;; Return TRUE if a result can be stored in OP without clobbering the
473 ;; condition code register.  Prior to reload we only accept a
474 ;; register.  After reload we have to be able to handle memory as
475 ;; well, since a pseudo may not get a hard reg and reload cannot
476 ;; handle output-reloads on jump insns.
477
478 ;; We could possibly handle mem before reload as well, but that might
479 ;; complicate things with the need to handle increment
480 ;; side-effects.
481 (define_predicate "thumb_cbrch_target_operand"
482   (and (match_code "reg,subreg,mem")
483        (ior (match_operand 0 "s_register_operand")
484             (and (match_test "reload_in_progress || reload_completed")
485                  (match_operand 0 "memory_operand")))))
486
487 ;;-------------------------------------------------------------------------
488 ;;
489 ;; MAVERICK predicates
490 ;;
491
492 (define_predicate "cirrus_register_operand"
493   (match_code "reg,subreg")
494 {
495   if (GET_CODE (op) == SUBREG)
496     op = SUBREG_REG (op);
497
498   return (GET_CODE (op) == REG
499           && (REGNO_REG_CLASS (REGNO (op)) == CIRRUS_REGS
500               || REGNO_REG_CLASS (REGNO (op)) == GENERAL_REGS));
501 })
502
503 (define_predicate "cirrus_fp_register"
504   (match_code "reg,subreg")
505 {
506   if (GET_CODE (op) == SUBREG)
507     op = SUBREG_REG (op);
508
509   return (GET_CODE (op) == REG
510           && (REGNO (op) >= FIRST_PSEUDO_REGISTER
511               || REGNO_REG_CLASS (REGNO (op)) == CIRRUS_REGS));
512 })
513
514 (define_predicate "cirrus_shift_const"
515   (and (match_code "const_int")
516        (match_test "((unsigned HOST_WIDE_INT) INTVAL (op)) < 64")))
517
518
519 ;; Neon predicates
520
521 (define_predicate "const_multiple_of_8_operand"
522   (match_code "const_int")
523 {
524   unsigned HOST_WIDE_INT val = INTVAL (op);
525   return (val & 7) == 0;
526 })
527
528 (define_predicate "imm_for_neon_mov_operand"
529   (match_code "const_vector")
530 {
531   return neon_immediate_valid_for_move (op, mode, NULL, NULL);
532 })
533
534 (define_predicate "imm_for_neon_logic_operand"
535   (match_code "const_vector")
536 {
537   return (TARGET_NEON
538           && neon_immediate_valid_for_logic (op, mode, 0, NULL, NULL));
539 })
540
541 (define_predicate "imm_for_neon_inv_logic_operand"
542   (match_code "const_vector")
543 {
544   return (TARGET_NEON
545           && neon_immediate_valid_for_logic (op, mode, 1, NULL, NULL));
546 })
547
548 (define_predicate "neon_logic_op2"
549   (ior (match_operand 0 "imm_for_neon_logic_operand")
550        (match_operand 0 "s_register_operand")))
551
552 (define_predicate "neon_inv_logic_op2"
553   (ior (match_operand 0 "imm_for_neon_inv_logic_operand")
554        (match_operand 0 "s_register_operand")))
555
556 ;; TODO: We could check lane numbers more precisely based on the mode.
557 (define_predicate "neon_lane_number"
558   (and (match_code "const_int")
559        (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 7")))
560 ;; Predicates for named expanders that overlap multiple ISAs.
561
562 (define_predicate "cmpdi_operand"
563   (if_then_else (match_test "TARGET_HARD_FLOAT && TARGET_MAVERICK")
564                 (and (match_test "TARGET_ARM")
565                      (match_operand 0 "cirrus_fp_register"))
566                 (and (match_test "TARGET_32BIT")
567                      (match_operand 0 "arm_di_operand"))))
568