Merged with mainline at revision 128810.
[official-gcc.git] / gcc / config / pa / predicates.md
blob1fc921e9b1bc14c5360e4c2c43ff41558f713cb8
1 ;; Predicate definitions for HP PA-RISC.
2 ;; Copyright (C) 2005, 2007 Free Software Foundation, Inc.
3 ;;
4 ;; This file is part of GCC.
5 ;;
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)
9 ;; any later version.
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 ;; Return nonzero only if OP is a register of mode MODE, or
21 ;; CONST0_RTX.
23 (define_predicate "reg_or_0_operand"
24   (match_code "subreg,reg,const_int,const_double")
26   return (op == CONST0_RTX (mode) || register_operand (op, mode));
29 ;; Return nonzero if OP is suitable for use in a call to a named
30 ;; function.
32 ;; For 2.5 try to eliminate either call_operand_address or
33 ;; function_label_operand, they perform very similar functions.
35 (define_predicate "call_operand_address"
36   (match_code "label_ref,symbol_ref,const_int,const_double,const,high")
38   return (GET_MODE (op) == word_mode
39           && CONSTANT_P (op) && ! TARGET_PORTABLE_RUNTIME);
42 ;; Return 1 iff OP is an indexed memory operand.
44 (define_predicate "indexed_memory_operand"
45   (match_code "subreg,mem")
47   if (GET_MODE (op) != mode)
48     return 0;
50   /* Before reload, a (SUBREG (MEM...)) forces reloading into a register.  */
51   if (reload_completed && GET_CODE (op) == SUBREG)
52     op = SUBREG_REG (op);
54   if (GET_CODE (op) != MEM || symbolic_memory_operand (op, mode))
55     return 0;
57   op = XEXP (op, 0);
59   return (memory_address_p (mode, op) && IS_INDEX_ADDR_P (op));
62 ;; Return 1 iff OP is a symbolic operand.
63 ;; Note: an inline copy of this code is present in pa_secondary_reload.
65 (define_predicate "symbolic_operand"
66   (match_code "symbol_ref,label_ref,const")
68   switch (GET_CODE (op))
69     {
70     case SYMBOL_REF:
71       return !SYMBOL_REF_TLS_MODEL (op);
72     case LABEL_REF:
73       return 1;
74     case CONST:
75       op = XEXP (op, 0);
76       return (((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
77                 && !SYMBOL_REF_TLS_MODEL (XEXP (op, 0)))
78                || GET_CODE (XEXP (op, 0)) == LABEL_REF)
79               && GET_CODE (XEXP (op, 1)) == CONST_INT);
80     default:
81       return 0;
82     }
85 ;; Return truth value of statement that OP is a symbolic memory
86 ;; operand of mode MODE.
88 (define_predicate "symbolic_memory_operand"
89   (match_code "subreg,mem")
91   if (GET_CODE (op) == SUBREG)
92     op = SUBREG_REG (op);
93   if (GET_CODE (op) != MEM)
94     return 0;
95   op = XEXP (op, 0);
96   return ((GET_CODE (op) == SYMBOL_REF && !SYMBOL_REF_TLS_MODEL (op))
97          || GET_CODE (op) == CONST || GET_CODE (op) == HIGH 
98          || GET_CODE (op) == LABEL_REF);
101 ;; Return true if OP is a symbolic operand for the TLS Global Dynamic model.
102 (define_predicate "tgd_symbolic_operand"
103   (and (match_code "symbol_ref")
104        (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_GLOBAL_DYNAMIC")))
106 ;; Return true if OP is a symbolic operand for the TLS Local Dynamic model.
107 (define_predicate "tld_symbolic_operand"
108   (and (match_code "symbol_ref")
109        (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_DYNAMIC")))
111 ;; Return true if OP is a symbolic operand for the TLS Initial Exec model.
112 (define_predicate "tie_symbolic_operand"
113   (and (match_code "symbol_ref")
114        (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_INITIAL_EXEC")))
116 ;; Return true if OP is a symbolic operand for the TLS Local Exec model.
117 (define_predicate "tle_symbolic_operand"
118   (and (match_code "symbol_ref")
119        (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_EXEC")))
122 ;; Return 1 if the operand is a register operand or a non-symbolic
123 ;; memory operand after reload.  This predicate is used for branch
124 ;; patterns that internally handle register reloading.  We need to
125 ;; accept non-symbolic memory operands after reload to ensure that the
126 ;; pattern is still valid if reload didn't find a hard register for
127 ;; the operand.
129 (define_predicate "reg_before_reload_operand"
130   (match_code "reg,mem")
132   /* Don't accept a SUBREG since it will need a reload.  */
133   if (GET_CODE (op) == SUBREG)
134     return 0;
136   if (register_operand (op, mode))
137     return 1;
139   if (reload_completed
140       && memory_operand (op, mode)
141       && !symbolic_memory_operand (op, mode))
142     return 1;
144   return 0;
147 ;; Return 1 if the operand is either a register, zero, or a memory
148 ;; operand that is not symbolic.
150 (define_predicate "reg_or_0_or_nonsymb_mem_operand"
151   (match_code "subreg,reg,mem,const_int,const_double")
153   if (register_operand (op, mode))
154     return 1;
156   if (op == CONST0_RTX (mode))
157     return 1;
159   if (GET_CODE (op) == SUBREG)
160     op = SUBREG_REG (op);
162   if (GET_CODE (op) != MEM)
163     return 0;
165   /* Until problems with management of the REG_POINTER flag are resolved,
166      we need to delay creating move insns with unscaled indexed addresses
167      until CSE is not expected.  */
168   if (!TARGET_NO_SPACE_REGS
169       && !cse_not_expected
170       && GET_CODE (XEXP (op, 0)) == PLUS
171       && REG_P (XEXP (XEXP (op, 0), 0))
172       && REG_P (XEXP (XEXP (op, 0), 1)))
173     return 0;
175   return (!symbolic_memory_operand (op, mode)
176           && memory_address_p (mode, XEXP (op, 0)));
179 ;; Accept anything that can be used as a destination operand for a
180 ;; move instruction.  We don't accept indexed memory operands since
181 ;; they are supported only for floating point stores.
183 (define_predicate "move_dest_operand"
184   (match_code "subreg,reg,mem")
186   if (register_operand (op, mode))
187     return 1;
189   if (GET_MODE (op) != mode)
190     return 0;
192   if (GET_CODE (op) == SUBREG)
193     op = SUBREG_REG (op);
195   if (GET_CODE (op) != MEM || symbolic_memory_operand (op, mode))
196     return 0;
198   op = XEXP (op, 0);
200   return (memory_address_p (mode, op)
201           && !IS_INDEX_ADDR_P (op)
202           && !IS_LO_SUM_DLT_ADDR_P (op));
205 ;; Accept anything that can be used as a source operand for a move
206 ;; instruction.
208 (define_predicate "move_src_operand"
209   (match_code "subreg,reg,const_int,const_double,mem")
211   if (register_operand (op, mode))
212     return 1;
214   if (op == CONST0_RTX (mode))
215     return 1;
217   if (GET_CODE (op) == CONST_INT)
218     return cint_ok_for_move (INTVAL (op));
220   if (GET_MODE (op) != mode)
221     return 0;
223   if (GET_CODE (op) == SUBREG)
224     op = SUBREG_REG (op);
226   if (GET_CODE (op) != MEM)
227     return 0;
229   /* Until problems with management of the REG_POINTER flag are resolved,
230      we need to delay creating move insns with unscaled indexed addresses
231      until CSE is not expected.  */
232   if (!TARGET_NO_SPACE_REGS
233       && !cse_not_expected
234       && GET_CODE (XEXP (op, 0)) == PLUS
235       && REG_P (XEXP (XEXP (op, 0), 0))
236       && REG_P (XEXP (XEXP (op, 0), 1)))
237     return 0;
239   return memory_address_p (mode, XEXP (op, 0));
242 ;; Accept anything that can be used as the source operand for a
243 ;; prefetch instruction with a cache-control completer.
245 (define_predicate "prefetch_cc_operand"
246   (match_code "mem")
248   if (GET_CODE (op) != MEM)
249     return 0;
251   op = XEXP (op, 0);
253   /* We must reject virtual registers as we don't allow REG+D.  */
254   if (op == virtual_incoming_args_rtx
255       || op == virtual_stack_vars_rtx
256       || op == virtual_stack_dynamic_rtx
257       || op == virtual_outgoing_args_rtx
258       || op == virtual_cfa_rtx)
259     return 0;
261   if (!REG_P (op) && !IS_INDEX_ADDR_P (op))
262     return 0;
264   /* Until problems with management of the REG_POINTER flag are resolved,
265      we need to delay creating prefetch insns with unscaled indexed addresses
266      until CSE is not expected.  */
267   if (!TARGET_NO_SPACE_REGS
268       && !cse_not_expected
269       && GET_CODE (op) == PLUS
270       && REG_P (XEXP (op, 0)))
271     return 0;
273   return memory_address_p (mode, op);
276 ;; Accept anything that can be used as the source operand for a
277 ;; prefetch instruction with no cache-control completer.
279 (define_predicate "prefetch_nocc_operand"
280   (match_code "mem")
282   if (GET_CODE (op) != MEM)
283     return 0;
285   op = XEXP (op, 0);
287   /* Until problems with management of the REG_POINTER flag are resolved,
288      we need to delay creating prefetch insns with unscaled indexed addresses
289      until CSE is not expected.  */
290   if (!TARGET_NO_SPACE_REGS
291       && !cse_not_expected
292       && GET_CODE (op) == PLUS
293       && REG_P (XEXP (op, 0))
294       && REG_P (XEXP (op, 1)))
295     return 0;
297   return memory_address_p (mode, op);
300 ;; Accept REG and any CONST_INT that can be moved in one instruction
301 ;; into a general register.
303 (define_predicate "reg_or_cint_move_operand"
304   (match_code "subreg,reg,const_int")
306   if (register_operand (op, mode))
307     return 1;
309   return (GET_CODE (op) == CONST_INT && cint_ok_for_move (INTVAL (op)));
312 ;; TODO: Add a comment here.
314 (define_predicate "pic_label_operand"
315   (match_code "label_ref,const")
317   if (!flag_pic)
318     return 0;
320   switch (GET_CODE (op))
321     {
322     case LABEL_REF:
323       return 1;
324     case CONST:
325       op = XEXP (op, 0);
326       return (GET_CODE (XEXP (op, 0)) == LABEL_REF
327               && GET_CODE (XEXP (op, 1)) == CONST_INT);
328     default:
329       return 0;
330     }
333 ;; TODO: Add a comment here.
335 (define_predicate "fp_reg_operand"
336   (match_code "reg")
338   return reg_renumber && FP_REG_P (op);
341 ;; Return truth value of whether OP can be used as an operand in a
342 ;; three operand arithmetic insn that accepts registers of mode MODE
343 ;; or 14-bit signed integers.
345 (define_predicate "arith_operand"
346   (match_code "subreg,reg,const_int")
348   return (register_operand (op, mode)
349           || (GET_CODE (op) == CONST_INT && INT_14_BITS (op)));
352 ;; Return truth value of whether OP can be used as an operand in a
353 ;; three operand arithmetic insn that accepts registers of mode MODE
354 ;; or 11-bit signed integers.
356 (define_predicate "arith11_operand"
357   (match_code "subreg,reg,const_int")
359   return (register_operand (op, mode)
360           || (GET_CODE (op) == CONST_INT && INT_11_BITS (op)));
363 ;; A constant integer suitable for use in a PRE_MODIFY memory
364 ;; reference.
366 (define_predicate "pre_cint_operand"
367   (match_code "const_int")
369   return (GET_CODE (op) == CONST_INT
370           && INTVAL (op) >= -0x2000 && INTVAL (op) < 0x10);
373 ;; A constant integer suitable for use in a POST_MODIFY memory
374 ;; reference.
376 (define_predicate "post_cint_operand"
377   (match_code "const_int")
379   return (GET_CODE (op) == CONST_INT
380           && INTVAL (op) < 0x2000 && INTVAL (op) >= -0x10);
383 ;; TODO: Add a comment here.
385 (define_predicate "arith_double_operand"
386   (match_code "subreg,reg,const_double")
388   return (register_operand (op, mode)
389           || (GET_CODE (op) == CONST_DOUBLE
390               && GET_MODE (op) == mode
391               && VAL_14_BITS_P (CONST_DOUBLE_LOW (op))
392               && ((CONST_DOUBLE_HIGH (op) >= 0)
393                   == ((CONST_DOUBLE_LOW (op) & 0x1000) == 0))));
396 ;; Return truth value of whether OP is an integer which fits the range
397 ;; constraining immediate operands in three-address insns, or is an
398 ;; integer register.
400 (define_predicate "ireg_or_int5_operand"
401   (match_code "const_int,reg")
403   return ((GET_CODE (op) == CONST_INT && INT_5_BITS (op))
404           || (GET_CODE (op) == REG && REGNO (op) > 0 && REGNO (op) < 32));
407 ;; Return truth value of whether OP is an integer which fits the range
408 ;; constraining immediate operands in three-address insns.
410 (define_predicate "int5_operand"
411   (match_code "const_int")
413   return (GET_CODE (op) == CONST_INT && INT_5_BITS (op));
416 ;; Return truth value of whether OP is an integer which fits the range
417 ;; constraining immediate operands in three-address insns.
419 (define_predicate "uint5_operand"
420   (match_code "const_int")
422   return (GET_CODE (op) == CONST_INT && INT_U5_BITS (op));
425 ;; Return truth value of whether OP is an integer which fits the range
426 ;; constraining immediate operands in three-address insns.
428 (define_predicate "int11_operand"
429   (match_code "const_int")
431   return (GET_CODE (op) == CONST_INT && INT_11_BITS (op));
434 ;; Return truth value of whether OP is an integer which fits the range
435 ;; constraining immediate operands in three-address insns.
437 (define_predicate "uint32_operand"
438   (match_code "const_int,const_double")
440 #if HOST_BITS_PER_WIDE_INT > 32
441   /* All allowed constants will fit a CONST_INT.  */
442   return (GET_CODE (op) == CONST_INT
443           && (INTVAL (op) >= 0 && INTVAL (op) < (HOST_WIDE_INT) 1 << 32));
444 #else
445   return (GET_CODE (op) == CONST_INT
446           || (GET_CODE (op) == CONST_DOUBLE
447               && CONST_DOUBLE_HIGH (op) == 0));
448 #endif
451 ;; Return truth value of whether OP is an integer which fits the range
452 ;; constraining immediate operands in three-address insns.
454 (define_predicate "arith5_operand"
455   (match_code "subreg,reg,const_int")
457   return register_operand (op, mode) || int5_operand (op, mode);
460 ;; True iff depi or extru can be used to compute (reg & OP).
462 (define_predicate "and_operand"
463   (match_code "subreg,reg,const_int")
465   return (register_operand (op, mode)
466           || (GET_CODE (op) == CONST_INT && and_mask_p (INTVAL (op))));
469 ;; True iff depi can be used to compute (reg | OP).
471 (define_predicate "ior_operand"
472   (match_code "const_int")
474   return (GET_CODE (op) == CONST_INT && ior_mask_p (INTVAL (op)));
477 ;; True iff OP is a CONST_INT of the forms 0...0xxxx or
478 ;; 0...01...1xxxx. Such values can be the left hand side x in (x <<
479 ;; r), using the zvdepi instruction.
481 (define_predicate "lhs_lshift_cint_operand"
482   (match_code "const_int")
484   unsigned HOST_WIDE_INT x;
485   if (GET_CODE (op) != CONST_INT)
486     return 0;
487   x = INTVAL (op) >> 4;
488   return (x & (x + 1)) == 0;
491 ;; TODO: Add a comment here.
493 (define_predicate "lhs_lshift_operand"
494   (match_code "subreg,reg,const_int")
496   return register_operand (op, mode) || lhs_lshift_cint_operand (op, mode);
499 ;; TODO: Add a comment here.
501 (define_predicate "arith32_operand"
502   (match_code "subreg,reg,const_int")
504   return register_operand (op, mode) || GET_CODE (op) == CONST_INT;
507 ;; TODO: Add a comment here.
509 (define_predicate "pc_or_label_operand"
510   (match_code "pc,label_ref")
512   return (GET_CODE (op) == PC || GET_CODE (op) == LABEL_REF);
515 ;; TODO: Add a comment here.
517 (define_predicate "plus_xor_ior_operator"
518   (match_code "plus,xor,ior")
520   return (GET_CODE (op) == PLUS || GET_CODE (op) == XOR
521           || GET_CODE (op) == IOR);
524 ;; Return 1 if OP is a CONST_INT with the value 2, 4, or 8.  These are
525 ;; the valid constant for shadd instructions.
527 (define_predicate "shadd_operand"
528   (match_code "const_int")
530   return (GET_CODE (op) == CONST_INT && shadd_constant_p (INTVAL (op)));
533 ;; TODO: Add a comment here.
535 (define_predicate "div_operand"
536   (match_code "reg,const_int")
538   return (mode == SImode
539           && ((GET_CODE (op) == REG && REGNO (op) == 25)
540               || (GET_CODE (op) == CONST_INT && INTVAL (op) > 0
541                   && INTVAL (op) < 16 && magic_milli[INTVAL (op)])));
544 ;; Return nonzero if OP is an integer register, else return zero.
546 (define_predicate "ireg_operand"
547   (match_code "reg")
549   return (GET_CODE (op) == REG && REGNO (op) > 0 && REGNO (op) < 32);
552 ;; Return 1 if this is a comparison operator.  This allows the use of
553 ;; MATCH_OPERATOR to recognize all the branch insns.
555 (define_predicate "cmpib_comparison_operator"
556   (match_code "eq,ne,lt,le,leu,gt,gtu,ge")
558   return ((mode == VOIDmode || GET_MODE (op) == mode)
559           && (GET_CODE (op) == EQ
560               || GET_CODE (op) == NE
561               || GET_CODE (op) == GT
562               || GET_CODE (op) == GTU
563               || GET_CODE (op) == GE
564               || GET_CODE (op) == LT
565               || GET_CODE (op) == LE
566               || GET_CODE (op) == LEU));
569 ;; Return 1 if OP is an operator suitable for use in a movb
570 ;; instruction.
572 (define_predicate "movb_comparison_operator"
573   (match_code "eq,ne,lt,ge")
575   return (GET_CODE (op) == EQ || GET_CODE (op) == NE
576           || GET_CODE (op) == LT || GET_CODE (op) == GE);