OSDN Git Service

PR target/50617
[pf3gnuchains/gcc-fork.git] / gcc / config / pa / predicates.md
1 ;; Predicate definitions for HP PA-RISC.
2 ;; Copyright (C) 2005, 2007, 2010, 2011 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.
10 ;;
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.
15 ;;
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/>.
19
20 ;; Return truth value of whether OP is an integer which fits the range
21 ;; constraining 5-bit signed immediate operands in three-address insns.
22
23 (define_predicate "int5_operand"
24   (and (match_code "const_int")
25        (match_test "INT_5_BITS (op)")))
26
27 ;; Return truth value of whether OP is an integer which fits the range
28 ;; constraining 5-bit unsigned immediate operands in three-address insns.
29
30 (define_predicate "uint5_operand"
31   (and (match_code "const_int")
32        (match_test "INT_U5_BITS (op)")))
33
34 ;; Return truth value of whether OP is an integer which fits the range
35 ;; constraining 11-bit signed immediate operands in three-address insns.
36
37 (define_predicate "int11_operand"
38   (and (match_code "const_int")
39        (match_test "INT_11_BITS (op)")))
40
41 ;; Return truth value of whether OP is an integer which fits the range
42 ;; constraining 14-bit signed immediate operands in three-address insns.
43
44 (define_predicate "int14_operand"
45   (and (match_code "const_int")
46        (match_test "INT_14_BITS (op)")))
47
48 ;; True iff OP is a const_int or const_double that will fit in 32 bits.
49
50 (define_predicate "uint32_operand"
51   (if_then_else (match_test "HOST_BITS_PER_WIDE_INT > 32")
52     (and (match_code "const_int")
53          (match_test "INTVAL (op) >= 0
54                       && INTVAL (op) < (HOST_WIDE_INT) 1 << 32"))
55     (and (match_code "const_int,const_double")
56          (match_test "CONST_INT_P (op) || CONST_DOUBLE_HIGH (op) == 0"))))
57
58 ;; True iff depi can be used to compute (reg | OP).
59
60 (define_predicate "cint_ior_operand"
61   (and (match_code "const_int")
62        (match_test "pa_ior_mask_p (INTVAL (op))")))
63
64 ;; True iff OP is CONST_INT that can be moved in one instruction
65 ;; into a general register.
66
67 (define_predicate "cint_move_operand"
68   (and (match_code "const_int")
69        (match_test "pa_cint_ok_for_move (INTVAL (op))")))
70
71 ;; True iff OP is a CONST0_RTX for MODE.
72
73 (define_predicate "const_0_operand"
74   (and (match_code "const_int,const_double")
75        (match_test "op == CONST0_RTX (mode)")))
76
77 ;; A constant integer suitable for use in a PRE_MODIFY memory reference.
78
79 (define_predicate "pre_cint_operand"
80   (and (match_code "const_int")
81        (match_test "INTVAL (op) >= -0x2000 && INTVAL (op) < 0x10")))
82
83 ;; A constant integer suitable for use in a POST_MODIFY memory reference.
84
85 (define_predicate "post_cint_operand"
86   (and (match_code "const_int")
87        (match_test "INTVAL (op) < 0x2000 && INTVAL (op) >= -0x10")))
88
89 ;; True iff depi or extru can be used to compute (reg & OP).
90
91 (define_predicate "and_operand"
92   (ior (match_operand 0 "register_operand")
93        (and (match_code "const_int")
94             (match_test "pa_and_mask_p (INTVAL (op))"))))
95
96 ;; Return truth value of whether OP can be used as an operand in a
97 ;; three operand arithmetic insn that accepts registers of mode MODE
98 ;; or 5-bit signed integers.
99
100 (define_predicate "arith5_operand"
101   (ior (match_operand 0 "register_operand")
102        (match_operand 0 "int5_operand")))
103
104 ;; Return truth value of whether OP can be used as an operand in a
105 ;; three operand arithmetic insn that accepts registers of mode MODE
106 ;; or 11-bit signed integers.
107
108 (define_predicate "arith11_operand"
109   (ior (match_operand 0 "register_operand")
110        (match_operand 0 "int11_operand")))
111
112 ;; Return truth value of whether OP can be used as an operand in a
113 ;; three operand arithmetic insn that accepts registers of mode MODE
114 ;; or 14-bit signed integers.
115
116 (define_predicate "arith14_operand"
117   (ior (match_operand 0 "register_operand")
118        (match_operand 0 "int14_operand")))
119
120 ;; Return truth value of whether OP can be used as an operand in a
121 ;; three operand arithmetic insn that accepts registers of mode MODE
122 ;; or 32-bit signed integers.
123
124 (define_predicate "arith32_operand"
125   (ior (match_operand 0 "register_operand")
126        (match_code "const_int")))
127
128 ;; True iff OP can be used as an operand in an adddi3 insn.
129
130 (define_predicate "adddi3_operand"
131   (if_then_else (match_test "TARGET_64BIT")
132     (match_operand 0 "arith14_operand")
133     (match_operand 0 "arith11_operand")))
134
135 ;; True iff OP is valid as a base or index register in a REG+REG address.
136
137 (define_predicate "borx_reg_operand"
138   (match_code "reg")
139 {
140   /* We must reject virtual registers as the only expressions that
141      can be instantiated are REG and REG+CONST.  */
142   if (op == virtual_incoming_args_rtx
143       || op == virtual_stack_vars_rtx
144       || op == virtual_stack_dynamic_rtx
145       || op == virtual_outgoing_args_rtx
146       || op == virtual_cfa_rtx)
147     return false;
148
149   /* While it's always safe to index off the frame pointer, it's not
150      profitable to do so when the frame pointer is being eliminated.  */
151   if (!reload_completed
152       && flag_omit_frame_pointer
153       && !cfun->calls_alloca
154       && op == frame_pointer_rtx)
155     return false;
156
157   return register_operand (op, mode);
158 })
159
160 ;; Return nonzero if OP is suitable for use in a call to a named
161 ;; function.
162 ;;
163 ;; For 2.5 try to eliminate either call_operand_address or
164 ;; function_label_operand, they perform very similar functions.
165
166 (define_predicate "call_operand_address"
167   (match_code "label_ref,symbol_ref,const_int,const_double,const,high")
168 {
169   return (GET_MODE (op) == word_mode
170           && CONSTANT_P (op) && ! TARGET_PORTABLE_RUNTIME);
171 })
172
173 ;; True iff OP can be used as the divisor in a div millicode call.
174
175 (define_predicate "div_operand"
176   (match_code "reg,const_int")
177 {
178   return (mode == SImode
179           && ((REG_P (op) && REGNO (op) == 25)
180               || (CONST_INT_P (op)
181                   && INTVAL (op) > 0 && INTVAL (op) < 16
182                   && pa_magic_milli[INTVAL (op)])));
183 })
184
185 ;; True iff OP is a reloading floating point register
186
187 (define_predicate "fp_reg_operand"
188   (and (match_code "reg")
189        (match_test "reg_renumber && FP_REG_P (op)")))
190
191 ;; True iff OP is a function label operand.
192
193 (define_special_predicate "function_label_operand"
194   (and (match_code "symbol_ref")
195        (match_test "FUNCTION_NAME_P (XSTR (op, 0))")))
196
197 ;; True iff OP is an indexed memory operand.
198
199 (define_predicate "indexed_memory_operand"
200   (match_code "subreg,mem")
201 {
202   if (GET_MODE (op) != mode)
203     return false;
204
205   /* Before reload, a (SUBREG (MEM...)) forces reloading into a register.  */
206   if (reload_completed && GET_CODE (op) == SUBREG)
207     op = SUBREG_REG (op);
208
209   if (! MEM_P (op))
210     return false;
211
212   op = XEXP (op, 0);
213   return IS_INDEX_ADDR_P (op) && memory_address_p (mode, op);
214 })
215
216 ;; True iff the operand OP can be used as the destination operand of
217 ;; an integer store.  This also implies the operand could be used as
218 ;; the source operand of an integer load.  Symbolic, lo_sum and indexed
219 ;; memory operands are not allowed.  We accept reloading pseudos and
220 ;; other memory operands.
221
222 (define_predicate "integer_store_memory_operand"
223   (match_code "reg,mem")
224 {
225   return ((reload_in_progress
226            && REG_P (op)
227            && REGNO (op) >= FIRST_PSEUDO_REGISTER
228            && reg_renumber [REGNO (op)] < 0)
229           || (MEM_P (op)
230               && (reload_in_progress || memory_address_p (mode, XEXP (op, 0)))
231               && !symbolic_memory_operand (op, VOIDmode)
232               && !IS_LO_SUM_DLT_ADDR_P (XEXP (op, 0))
233               && !IS_INDEX_ADDR_P (XEXP (op, 0))));
234 })
235
236 ;; Return true iff OP is an integer register.
237
238 (define_predicate "ireg_operand"
239   (and (match_code "reg")
240        (match_test "REGNO (op) > 0 && REGNO (op) < 32")))
241
242 ;; Return truth value of whether OP is an integer which fits the range
243 ;; constraining immediate operands in three-address insns, or is an
244 ;; integer register.
245
246 (define_predicate "ireg_or_int5_operand"
247   (ior (match_operand 0 "ireg_operand")
248        (match_operand 0 "int5_operand")))
249
250 ;; True iff OP is a CONST_INT of the forms 0...0xxxx or
251 ;; 0...01...1xxxx. Such values can be the left hand side x in (x <<
252 ;; r), using the zvdepi instruction.
253
254 (define_predicate "lhs_lshift_cint_operand"
255   (match_code "const_int")
256 {
257   unsigned HOST_WIDE_INT x;
258   x = INTVAL (op) >> 4;
259   return (x & (x + 1)) == 0;
260 })
261
262 ;; True iff OP can be used in a zvdep instruction.
263
264 (define_predicate "lhs_lshift_operand"
265   (ior (match_operand 0 "register_operand")
266        (match_operand 0 "lhs_lshift_cint_operand")))
267
268 ;; Accept anything that can be used as a destination operand for a
269 ;; move instruction.  We don't accept indexed memory operands since
270 ;; they are supported only for floating point stores.
271
272 (define_predicate "move_dest_operand"
273   (match_code "subreg,reg,mem")
274 {
275   if (register_operand (op, mode))
276     return true;
277
278   if (GET_MODE (op) != mode)
279     return false;
280
281   if (GET_CODE (op) == SUBREG)
282     op = SUBREG_REG (op);
283
284   if (GET_CODE (op) != MEM || symbolic_memory_operand (op, mode))
285     return false;
286
287   op = XEXP (op, 0);
288
289   return (memory_address_p (mode, op)
290           && !IS_INDEX_ADDR_P (op)
291           && !IS_LO_SUM_DLT_ADDR_P (op));
292 })
293
294 ;; Accept anything that can be used as a source operand for a move
295 ;; instruction.
296
297 (define_predicate "move_src_operand"
298   (match_code "subreg,reg,const_int,const_double,mem")
299 {
300   if (register_operand (op, mode))
301     return true;
302
303   if (op == CONST0_RTX (mode))
304     return true;
305
306   if (CONST_INT_P (op))
307     return pa_cint_ok_for_move (INTVAL (op));
308
309   if (GET_MODE (op) != mode)
310     return false;
311
312   if (GET_CODE (op) == SUBREG)
313     op = SUBREG_REG (op);
314
315   if (! MEM_P (op))
316     return false;
317
318   /* Until problems with management of the REG_POINTER flag are resolved,
319      we need to delay creating move insns with unscaled indexed addresses
320      until CSE is not expected.  */
321   if (!TARGET_NO_SPACE_REGS
322       && !cse_not_expected
323       && GET_CODE (XEXP (op, 0)) == PLUS
324       && REG_P (XEXP (XEXP (op, 0), 0))
325       && REG_P (XEXP (XEXP (op, 0), 1)))
326     return false;
327
328   return memory_address_p (mode, XEXP (op, 0));
329 })
330
331 ;; True iff OP is not a symbolic memory operand. 
332
333 (define_predicate "nonsymb_mem_operand"
334   (match_code "subreg,mem")
335 {
336   if (GET_CODE (op) == SUBREG)
337     op = SUBREG_REG (op);
338
339   if (! MEM_P (op))
340     return false;
341
342   /* Until problems with management of the REG_POINTER flag are resolved,
343      we need to delay creating move insns with unscaled indexed addresses
344      until CSE is not expected.  */
345   if (!TARGET_NO_SPACE_REGS
346       && !cse_not_expected
347       && GET_CODE (XEXP (op, 0)) == PLUS
348       && REG_P (XEXP (XEXP (op, 0), 0))
349       && REG_P (XEXP (XEXP (op, 0), 1)))
350     return false;
351
352   return (!symbolic_memory_operand (op, mode)
353           && memory_address_p (mode, XEXP (op, 0)));
354 })
355
356 ;; True iff OP is anything other than a hard register.
357
358 (define_predicate "non_hard_reg_operand"
359   (match_test "! (REG_P (op) && REGNO (op) < FIRST_PSEUDO_REGISTER)"))
360
361 ;; True iff OP is a reference to a label whose address can be loaded
362 ;; while generating PIC code.
363
364 (define_predicate "pic_label_operand"
365   (match_code "label_ref,const")
366 {
367   if (!flag_pic)
368     return false;
369
370   switch (GET_CODE (op))
371     {
372     case LABEL_REF:
373       return true;
374     case CONST:
375       op = XEXP (op, 0);
376       return (GET_CODE (XEXP (op, 0)) == LABEL_REF
377               && CONST_INT_P (XEXP (op, 1)));
378     default:
379       gcc_unreachable ();
380     }
381   return false;
382 })
383
384 ;; True iff the operand OP lives in text space.  OP is a symbolic operand.
385 ;; If so, SYMBOL_REF_FLAG, which is set by pa_encode_section_info, is true.
386
387 (define_special_predicate "read_only_operand"
388   (match_test "true")
389 {
390   if (GET_CODE (op) == CONST)
391     op = XEXP (XEXP (op, 0), 0);
392   if (GET_CODE (op) == SYMBOL_REF)
393     {
394       if (flag_pic)
395         return SYMBOL_REF_FLAG (op) && !CONSTANT_POOL_ADDRESS_P (op);
396       else
397         return SYMBOL_REF_FLAG (op) || CONSTANT_POOL_ADDRESS_P (op);
398     }
399   return true;
400 })
401
402 ;; True iff the operand is a register operand, or a non-symbolic
403 ;; memory operand after reload.  A SUBREG is not accepted since it
404 ;; will need a reload.
405 ;;
406 ;; This predicate is used for branch patterns that internally handle
407 ;; register reloading.  We need to accept non-symbolic memory operands
408 ;; after reload to ensure that the pattern is still valid if reload
409 ;; didn't find a hard register for the operand.
410
411 (define_predicate "reg_before_reload_operand"
412   (match_code "reg,mem")
413 {
414   if (register_operand (op, mode))
415     return true;
416
417   if (reload_completed
418       && memory_operand (op, mode)
419       && !symbolic_memory_operand (op, mode))
420     return true;
421
422   return false;
423 })
424
425 ;; True iff OP is a register or const_0 operand for MODE.
426
427 (define_predicate "reg_or_0_operand"
428   (ior (match_operand 0 "register_operand")
429        (match_operand 0 "const_0_operand")))
430
431 ;; True iff OP is either a register, zero, or a non-symbolic memory operand.
432
433 (define_predicate "reg_or_0_or_nonsymb_mem_operand"
434   (ior (match_operand 0 "reg_or_0_operand")
435        (match_operand 0 "nonsymb_mem_operand")))
436
437 ;; Accept REG and any CONST_INT that can be moved in one instruction
438 ;; into a general register.
439
440 (define_predicate "reg_or_cint_move_operand"
441   (ior (match_operand 0 "register_operand")
442        (match_operand 0 "cint_move_operand")))
443
444 ;; True iff OP can be used to compute (reg | OP).
445
446 (define_predicate "reg_or_cint_ior_operand"
447   (ior (match_operand 0 "register_operand")
448        (match_operand 0 "cint_ior_operand")))
449
450 ;; Return 1 if OP is a CONST_INT with the value 2, 4, or 8.  These are
451 ;; the valid constants for shadd instructions.
452
453 (define_predicate "shadd_operand"
454   (and (match_code "const_int")
455        (match_test "pa_shadd_constant_p (INTVAL (op))")))
456
457 ;; Return truth value of statement that OP is a symbolic memory operand.
458
459 (define_predicate "symbolic_memory_operand"
460   (match_code "subreg,mem")
461 {
462   if (GET_CODE (op) == SUBREG)
463     op = SUBREG_REG (op);
464   if (!MEM_P (op))
465     return false;
466   return pa_symbolic_expression_p (XEXP (op, 0));
467 })
468
469 ;; True iff OP is a symbolic operand.
470 ;; Note: an inline copy of this code is present in pa_secondary_reload.
471
472 (define_predicate "symbolic_operand"
473   (match_code "symbol_ref,label_ref,const")
474 {
475   switch (GET_CODE (op))
476     {
477     case SYMBOL_REF:
478       return !SYMBOL_REF_TLS_MODEL (op);
479     case LABEL_REF:
480       return true;
481     case CONST:
482       op = XEXP (op, 0);
483       return (GET_CODE (op) == PLUS
484               && ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
485                    && !SYMBOL_REF_TLS_MODEL (XEXP (op, 0)))
486                   || GET_CODE (XEXP (op, 0)) == LABEL_REF)
487               && GET_CODE (XEXP (op, 1)) == CONST_INT);
488     default:
489       gcc_unreachable ();
490     }
491   return true;
492 })
493
494 ;; Return true if OP is a symbolic operand for the TLS Global Dynamic model.
495
496 (define_predicate "tgd_symbolic_operand"
497   (and (match_code "symbol_ref")
498        (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_GLOBAL_DYNAMIC")))
499
500 ;; Return true if OP is a symbolic operand for the TLS Local Dynamic model.
501
502 (define_predicate "tld_symbolic_operand"
503   (and (match_code "symbol_ref")
504        (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_DYNAMIC")))
505
506 ;; Return true if OP is a symbolic operand for the TLS Initial Exec model.
507
508 (define_predicate "tie_symbolic_operand"
509   (and (match_code "symbol_ref")
510        (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_INITIAL_EXEC")))
511
512 ;; Return true if OP is a symbolic operand for the TLS Local Exec model.
513
514 (define_predicate "tle_symbolic_operand"
515   (and (match_code "symbol_ref")
516        (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_EXEC")))
517
518 ;; True iff this is a comparison operator.  This allows the use of
519 ;; MATCH_OPERATOR to recognize all the branch insns.
520
521 (define_predicate "cmpib_comparison_operator"
522   (match_code "eq,ne,lt,le,leu,gt,gtu,ge"))
523
524 ;; True iff OP is an operator suitable for use in a movb instruction.
525
526 (define_predicate "movb_comparison_operator"
527   (match_code "eq,ne,lt,ge"))
528
529 ;; True iff OP is a PLUS, XOR or IOR operator.
530
531 (define_predicate "plus_xor_ior_operator"
532   (match_code "plus,xor,ior"))