OSDN Git Service

* Makefile.in (insn-preds.o): Depend on TREE_H.
[pf3gnuchains/gcc-fork.git] / gcc / config / alpha / predicates.md
1 ;; Predicate definitions for DEC Alpha.
2 ;; Copyright (C) 2004 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 2, 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 COPYING.  If not, write to
18 ;; the Free Software Foundation, 59 Temple Place - Suite 330,
19 ;; Boston, MA 02111-1307, USA.
20
21 ;; Return 1 if OP is the zero constant for MODE.
22 (define_predicate "const0_operand"
23   (and (match_code "const_int,const_double,const_vector")
24        (match_test "op == CONST0_RTX (mode)")))
25
26 ;; Returns true if OP is either the constant zero or a register.
27 (define_predicate "reg_or_0_operand"
28   (ior (match_operand 0 "register_operand")
29        (match_operand 0 "const0_operand")))
30
31 ;; Return 1 if OP is a constant in the range of 0-63 (for a shift) or
32 ;; any register.
33 (define_predicate "reg_or_6bit_operand"
34   (if_then_else (match_code "const_int")
35     (match_test "INTVAL (op) >= 0 && INTVAL (op) < 64")
36     (match_operand 0 "register_operand")))
37
38 ;; Return 1 if OP is an 8-bit constant.
39 (define_predicate "cint8_operand"
40   (and (match_code "const_int")
41        (match_test "INTVAL (op) >= 0 && INTVAL (op) < 256")))
42
43 ;; Return 1 if OP is an 8-bit constant or any register.
44 (define_predicate "reg_or_8bit_operand"
45   (if_then_else (match_code "const_int")
46     (match_test "INTVAL (op) >= 0 && INTVAL (op) < 256")
47     (match_operand 0 "register_operand")))
48
49 ;; Return 1 if OP is a constant or any register.
50 (define_predicate "reg_or_cint_operand"
51   (ior (match_operand 0 "register_operand")
52        (match_operand 0 "const_int_operand")))
53
54 ;; Return 1 if the operand is a valid second operand to an add insn.
55 (define_predicate "add_operand"
56   (if_then_else (match_code "const_int")
57     (match_test "CONST_OK_FOR_LETTER_P (INTVAL (op), 'K')
58                  || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L')")
59     (match_operand 0 "register_operand")))
60
61 ;; Return 1 if the operand is a valid second operand to a
62 ;; sign-extending add insn.
63 (define_predicate "sext_add_operand"
64   (if_then_else (match_code "const_int")
65     (match_test "CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
66                  || CONST_OK_FOR_LETTER_P (INTVAL (op), 'O')")
67     (match_operand 0 "register_operand")))
68
69 ;; Return 1 if OP is the constant 4 or 8.
70 (define_predicate "const48_operand"
71   (and (match_code "const_int")
72        (match_test "INTVAL (op) == 4 || INTVAL (op) == 8")))
73
74 ;; Return 1 if OP is a valid first operand to an AND insn.
75 (define_predicate "and_operand"
76   (if_then_else (match_code "const_int")
77     (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) < 0x100
78                  || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100
79                  || zap_mask (INTVAL (op))")
80     (if_then_else (match_code "const_double")
81       (match_test "zap_mask (CONST_DOUBLE_LOW (op))
82                    && zap_mask (CONST_DOUBLE_HIGH (op))")
83       (match_operand 0 "register_operand"))))
84
85 ;; Return 1 if OP is a valid first operand to an IOR or XOR insn.
86 (define_predicate "or_operand"
87   (if_then_else (match_code "const_int")
88     (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) < 0x100
89                  || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100")
90     (match_operand 0 "register_operand")))
91
92 ;; Return 1 if OP is a constant that is the width, in bits, of an integral
93 ;; mode not larger than DImode.
94 (define_predicate "mode_width_operand"
95   (match_code "const_int")
96 {
97   HOST_WIDE_INT i = INTVAL (op);
98   return i == 8 || i == 16 || i == 32 || i == 64;
99 })
100
101 ;; Return 1 if OP is a constant that is a mask of ones of width of an
102 ;; integral machine mode not larger than DImode.
103 (define_predicate "mode_mask_operand"
104   (match_code "const_int,const_double")
105 {
106   if (GET_CODE (op) == CONST_INT)
107     {
108       HOST_WIDE_INT value = INTVAL (op);
109
110       if (value == 0xff)
111         return 1;
112       if (value == 0xffff)
113         return 1;
114       if (value == 0xffffffff)
115         return 1;
116       if (value == -1)
117         return 1;
118     }
119   else if (HOST_BITS_PER_WIDE_INT == 32 && GET_CODE (op) == CONST_DOUBLE)
120     {
121       if (CONST_DOUBLE_LOW (op) == 0xffffffff && CONST_DOUBLE_HIGH (op) == 0)
122         return 1;
123     }
124   return 0;
125 })
126
127 ;; Return 1 if OP is a multiple of 8 less than 64.
128 (define_predicate "mul8_operand"
129   (match_code "const_int")
130 {
131   unsigned HOST_WIDE_INT i = INTVAL (op);
132   return i < 64 && i % 8 == 0;
133 })
134
135 ;; Return 1 if OP is a hard floating-point register.
136 (define_predicate "hard_fp_register_operand"
137   (match_operand 0 "register_operand")
138 {
139   if (GET_CODE (op) == SUBREG)
140     op = SUBREG_REG (op);
141   return REGNO_REG_CLASS (REGNO (op)) == FLOAT_REGS;
142 })
143
144 ;; Return 1 if OP is a hard general register.
145 (define_predicate "hard_int_register_operand"
146   (match_operand 0 "register_operand")
147 {
148   if (GET_CODE (op) == SUBREG)
149     op = SUBREG_REG (op);
150   return REGNO_REG_CLASS (REGNO (op)) == GENERAL_REGS;
151 })
152
153 ;; Return 1 if OP is something that can be reloaded into a register;
154 ;; if it is a MEM, it need not be valid.
155 (define_predicate "some_operand"
156   (ior (match_code "reg,mem,const_int,const_double,const_vector,
157                     label_ref,symbol_ref,const,high")
158        (and (match_code "subreg")
159             (match_test "some_operand (SUBREG_REG (op), VOIDmode)"))))
160
161 ;; Likewise, but don't accept constants.
162 (define_predicate "some_ni_operand"
163   (ior (match_code "reg,mem")
164        (and (match_code "subreg")
165             (match_test "some_ni_operand (SUBREG_REG (op), VOIDmode)"))))
166
167 ;; Return 1 if OP is a valid operand for the source of a move insn.
168 (define_predicate "input_operand"
169   (match_code "label_ref,symbol_ref,const,high,reg,subreg,mem,
170                const_double,const_vector,const_int")
171 {
172   switch (GET_CODE (op))
173     {
174     case LABEL_REF:
175     case SYMBOL_REF:
176     case CONST:
177       if (TARGET_EXPLICIT_RELOCS)
178         {
179           /* We don't split symbolic operands into something unintelligable
180              until after reload, but we do not wish non-small, non-global
181              symbolic operands to be reconstructed from their high/lo_sum
182              form.  */
183           return (small_symbolic_operand (op, mode)
184                   || global_symbolic_operand (op, mode)
185                   || gotdtp_symbolic_operand (op, mode)
186                   || gottp_symbolic_operand (op, mode));
187         }
188
189       /* This handles both the Windows/NT and OSF cases.  */
190       return mode == ptr_mode || mode == DImode;
191
192     case HIGH:
193       return (TARGET_EXPLICIT_RELOCS
194               && local_symbolic_operand (XEXP (op, 0), mode));
195
196     case REG:
197       return 1;
198
199     case SUBREG:
200       if (register_operand (op, mode))
201         return 1;
202       /* ... fall through ...  */
203     case MEM:
204       return ((TARGET_BWX || (mode != HImode && mode != QImode))
205               && general_operand (op, mode));
206
207     case CONST_DOUBLE:
208     case CONST_VECTOR:
209       return op == CONST0_RTX (mode);
210
211     case CONST_INT:
212       return mode == QImode || mode == HImode || add_operand (op, mode);
213
214     default:
215       abort ();
216     }
217   return 0;
218 })
219
220 ;; Return 1 if OP is a SYMBOL_REF for a function known to be in this
221 ;; file, and in the same section as the current function.
222
223 (define_predicate "samegp_function_operand"
224   (match_code "symbol_ref")
225 {
226   /* Easy test for recursion.  */
227   if (op == XEXP (DECL_RTL (current_function_decl), 0))
228     return true;
229
230   /* Functions that are not local can be overridden, and thus may
231      not share the same gp.  */
232   if (! SYMBOL_REF_LOCAL_P (op))
233     return false;
234
235   /* If -msmall-data is in effect, assume that there is only one GP
236      for the module, and so any local symbol has this property.  We
237      need explicit relocations to be able to enforce this for symbols
238      not defined in this unit of translation, however.  */
239   if (TARGET_EXPLICIT_RELOCS && TARGET_SMALL_DATA)
240     return true;
241
242   /* Functions that are not external are defined in this UoT,
243      and thus must share the same gp.  */
244   return ! SYMBOL_REF_EXTERNAL_P (op);
245 })
246
247 ;; Return 1 if OP is a SYMBOL_REF for which we can make a call via bsr.
248 (define_predicate "direct_call_operand"
249   (match_operand 0 "samegp_function_operand")
250 {
251   tree op_decl, cfun_sec, op_sec;
252
253   /* If profiling is implemented via linker tricks, we can't jump
254      to the nogp alternate entry point.  Note that current_function_profile
255      would not be correct, since that doesn't indicate if the target
256      function uses profiling.  */
257   /* ??? TARGET_PROFILING_NEEDS_GP isn't really the right test,
258      but is approximately correct for the OSF ABIs.  Don't know
259      what to do for VMS, NT, or UMK.  */
260   if (!TARGET_PROFILING_NEEDS_GP && profile_flag)
261     return false;
262
263   /* Must be a function.  In some cases folks create thunks in static
264      data structures and then make calls to them.  If we allow the
265      direct call, we'll get an error from the linker about !samegp reloc
266      against a symbol without a .prologue directive.  */
267   if (!SYMBOL_REF_FUNCTION_P (op))
268     return false;
269   
270   /* Must be "near" so that the branch is assumed to reach.  With
271      -msmall-text, this is assumed true of all local symbols.  Since
272      we've already checked samegp, locality is already assured.  */
273   if (TARGET_SMALL_TEXT)
274     return true;
275
276   /* Otherwise, a decl is "near" if it is defined in the same section.  */
277   if (flag_function_sections)
278     return false;
279
280   op_decl = SYMBOL_REF_DECL (op);
281   if (DECL_ONE_ONLY (current_function_decl)
282       || (op_decl && DECL_ONE_ONLY (op_decl)))
283     return false;
284
285   cfun_sec = DECL_SECTION_NAME (current_function_decl);
286   op_sec = op_decl ? DECL_SECTION_NAME (op_decl) : NULL;
287   return ((!cfun_sec && !op_sec)
288           || (cfun_sec && op_sec
289               && strcmp (TREE_STRING_POINTER (cfun_sec),
290                          TREE_STRING_POINTER (op_sec)) == 0));
291 })
292
293 ;; Return 1 if OP is a valid operand for the MEM of a CALL insn.
294 ;;
295 ;; For TARGET_ABI_OSF, we want to restrict to R27 or a pseudo.
296 ;; For TARGET_ABI_UNICOSMK, we want to restrict to registers.
297
298 (define_predicate "call_operand"
299   (if_then_else (match_code "reg")
300     (match_test "!TARGET_ABI_OSF
301                  || REGNO (op) == 27 || REGNO (op) > LAST_VIRTUAL_REGISTER")
302     (and (match_test "!TARGET_ABI_UNICOSMK")
303          (match_code "symbol_ref"))))
304
305 ;; Return true if OP is a LABEL_REF, or SYMBOL_REF or CONST referencing
306 ;; a (non-tls) variable known to be defined in this file.
307 (define_predicate "local_symbolic_operand"
308   (match_code "label_ref,const,symbol_ref")
309 {
310   if (GET_CODE (op) == LABEL_REF)
311     return 1;
312
313   if (GET_CODE (op) == CONST
314       && GET_CODE (XEXP (op, 0)) == PLUS
315       && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT)
316     op = XEXP (XEXP (op, 0), 0);
317
318   if (GET_CODE (op) != SYMBOL_REF)
319     return 0;
320
321   return SYMBOL_REF_LOCAL_P (op) && !SYMBOL_REF_TLS_MODEL (op);
322 })
323
324 ;; Return true if OP is a SYMBOL_REF or CONST referencing a variable
325 ;; known to be defined in this file in the small data area.
326 (define_predicate "small_symbolic_operand"
327   (match_code "const,symbol_ref")
328 {
329   if (! TARGET_SMALL_DATA)
330     return 0;
331
332   if (GET_CODE (op) == CONST
333       && GET_CODE (XEXP (op, 0)) == PLUS
334       && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT)
335     op = XEXP (XEXP (op, 0), 0);
336
337   if (GET_CODE (op) != SYMBOL_REF)
338     return 0;
339
340   /* ??? There's no encode_section_info equivalent for the rtl
341      constant pool, so SYMBOL_FLAG_SMALL never gets set.  */
342   if (CONSTANT_POOL_ADDRESS_P (op))
343     return GET_MODE_SIZE (get_pool_mode (op)) <= g_switch_value;
344
345   return (SYMBOL_REF_LOCAL_P (op)
346           && SYMBOL_REF_SMALL_P (op)
347           && SYMBOL_REF_TLS_MODEL (op) == 0);
348 })
349
350 ;; Return true if OP is a SYMBOL_REF or CONST referencing a variable
351 ;; not known (or known not) to be defined in this file.
352 (define_predicate "global_symbolic_operand"
353   (match_code "const,symbol_ref")
354 {
355   if (GET_CODE (op) == CONST
356       && GET_CODE (XEXP (op, 0)) == PLUS
357       && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT)
358     op = XEXP (XEXP (op, 0), 0);
359
360   if (GET_CODE (op) != SYMBOL_REF)
361     return 0;
362
363   return !SYMBOL_REF_LOCAL_P (op) && !SYMBOL_REF_TLS_MODEL (op);
364 })
365
366 ;; Returns 1 if OP is a symbolic operand, i.e. a symbol_ref or a label_ref,
367 ;; possibly with an offset.
368 (define_predicate "symbolic_operand"
369   (ior (match_code "symbol_ref,label_ref")
370        (and (match_code "const")
371             (match_test "GET_CODE (XEXP (op,0)) == PLUS
372                          && GET_CODE (XEXP (XEXP (op,0), 0)) == SYMBOL_REF
373                          && GET_CODE (XEXP (XEXP (op,0), 1)) == CONST_INT"))))
374
375 ;; Return true if OP is valid for 16-bit DTP relative relocations.
376 (define_predicate "dtp16_symbolic_operand"
377   (and (match_code "const")
378        (match_test "tls_symbolic_operand_1 (op, 16, UNSPEC_DTPREL)")))
379
380 ;; Return true if OP is valid for 32-bit DTP relative relocations.
381 (define_predicate "dtp32_symbolic_operand"
382   (and (match_code "const")
383        (match_test "tls_symbolic_operand_1 (op, 32, UNSPEC_DTPREL)")))
384
385 ;; Return true if OP is valid for 64-bit DTP relative relocations.
386 (define_predicate "gotdtp_symbolic_operand"
387   (and (match_code "const")
388        (match_test "tls_symbolic_operand_1 (op, 64, UNSPEC_DTPREL)")))
389
390 ;; Return true if OP is valid for 16-bit TP relative relocations.
391 (define_predicate "tp16_symbolic_operand"
392   (and (match_code "const")
393        (match_test "tls_symbolic_operand_1 (op, 16, UNSPEC_TPREL)")))
394
395 ;; Return true if OP is valid for 32-bit TP relative relocations.
396 (define_predicate "tp32_symbolic_operand"
397   (and (match_code "const")
398        (match_test "tls_symbolic_operand_1 (op, 32, UNSPEC_TPREL)")))
399
400 ;; Return true if OP is valid for 64-bit TP relative relocations.
401 (define_predicate "gottp_symbolic_operand"
402   (and (match_code "const")
403        (match_test "tls_symbolic_operand_1 (op, 64, UNSPEC_TPREL)")))
404
405 ;; Return 1 if this memory address is a known aligned register plus
406 ;; a constant.  It must be a valid address.  This means that we can do
407 ;; this as an aligned reference plus some offset.
408 ;;
409 ;; Take into account what reload will do.  Oh god this is awful.
410 ;; The horrible comma-operator construct below is to prevent genrecog
411 ;; from thinking that this predicate accepts REG and SUBREG.  We don't
412 ;; use recog during reload, so pretending these codes are accepted 
413 ;; pessimizes things a tad.
414
415 (define_predicate "aligned_memory_operand"
416   (ior (match_test "op = resolve_reload_operand (op), 0")
417        (match_code "mem"))
418 {
419   rtx base;
420
421   if (MEM_ALIGN (op) >= 32)
422     return 1;
423   op = XEXP (op, 0);
424
425   /* LEGITIMIZE_RELOAD_ADDRESS creates (plus (plus reg const_hi) const_lo)
426      sorts of constructs.  Dig for the real base register.  */
427   if (reload_in_progress
428       && GET_CODE (op) == PLUS
429       && GET_CODE (XEXP (op, 0)) == PLUS)
430     base = XEXP (XEXP (op, 0), 0);
431   else
432     {
433       if (! memory_address_p (mode, op))
434         return 0;
435       base = (GET_CODE (op) == PLUS ? XEXP (op, 0) : op);
436     }
437
438   return (GET_CODE (base) == REG && REGNO_POINTER_ALIGN (REGNO (base)) >= 32);
439 })
440
441 ;; Similar, but return 1 if OP is a MEM which is not alignable.
442
443 (define_predicate "unaligned_memory_operand"
444   (ior (match_test "op = resolve_reload_operand (op), 0")
445        (match_code "mem"))
446 {
447   rtx base;
448
449   if (MEM_ALIGN (op) >= 32)
450     return 0;
451   op = XEXP (op, 0);
452
453   /* LEGITIMIZE_RELOAD_ADDRESS creates (plus (plus reg const_hi) const_lo)
454      sorts of constructs.  Dig for the real base register.  */
455   if (reload_in_progress
456       && GET_CODE (op) == PLUS
457       && GET_CODE (XEXP (op, 0)) == PLUS)
458     base = XEXP (XEXP (op, 0), 0);
459   else
460     {
461       if (! memory_address_p (mode, op))
462         return 0;
463       base = (GET_CODE (op) == PLUS ? XEXP (op, 0) : op);
464     }
465
466   return (GET_CODE (base) == REG && REGNO_POINTER_ALIGN (REGNO (base)) < 32);
467 })
468
469 ;; Return 1 if OP is any memory location.  During reload a pseudo matches.
470 (define_predicate "any_memory_operand"
471   (ior (match_code "mem,reg")
472        (and (match_code "subreg")
473             (match_test "GET_CODE (SUBREG_REG (op)) == REG"))))
474
475 ;; Return 1 if OP is either a register or an unaligned memory location.
476 (define_predicate "reg_or_unaligned_mem_operand"
477   (ior (match_operand 0 "register_operand")
478        (match_operand 0 "unaligned_memory_operand")))
479
480 ;; Return 1 is OP is a memory location that is not a reference
481 ;; (using an AND) to an unaligned location.  Take into account
482 ;; what reload will do.
483 (define_predicate "normal_memory_operand"
484   (ior (match_test "op = resolve_reload_operand (op), 0")
485        (and (match_code "mem")
486             (match_test "GET_CODE (XEXP (op, 0)) != AND"))))
487
488 ;; Returns 1 if OP is not an eliminable register.
489 ;;
490 ;; This exists to cure a pathological abort in the s8addq (et al) patterns,
491 ;;
492 ;;      long foo () { long t; bar(); return (long) &t * 26107; }
493 ;;
494 ;; which run afoul of a hack in reload to cure a (presumably) similar
495 ;; problem with lea-type instructions on other targets.  But there is
496 ;; one of us and many of them, so work around the problem by selectively
497 ;; preventing combine from making the optimization.
498
499 (define_predicate "reg_not_elim_operand"
500   (match_operand 0 "register_operand")
501 {
502   if (GET_CODE (op) == SUBREG)
503     op = SUBREG_REG (op);
504   return op != frame_pointer_rtx && op != arg_pointer_rtx;
505 })
506
507 ;; Accept a register, but not a subreg of any kind.  This allows us to
508 ;; avoid pathological cases in reload wrt data movement common in 
509 ;; int->fp conversion.  */
510 (define_predicate "reg_no_subreg_operand"
511   (and (match_code "reg")
512        (match_operand 0 "register_operand")))
513
514 ;; Return 1 if OP is a valid Alpha comparison operator for "cmp" style
515 ;; instructions.
516 (define_predicate "alpha_comparison_operator"
517   (match_code "eq,le,lt,leu,ltu"))
518
519 ;; Similarly, but with swapped operands.
520 (define_predicate "alpha_swapped_comparison_operator"
521   (match_code "eq,ge,gt,gtu,gtu"))
522
523 ;; Return 1 if OP is a valid Alpha comparison operator against zero
524 ;; for "bcc" style instructions.
525 (define_predicate "alpha_zero_comparison_operator"
526   (match_code "eq,ne,le,lt,leu,ltu"))
527
528 ;; Return 1 if OP is a signed comparison operation.
529 (define_predicate "signed_comparison_operator"
530   (match_code "eq,ne,le,lt,ge,gt"))
531
532 ;; Return 1 if OP is a valid Alpha floating point comparison operator.
533 (define_predicate "alpha_fp_comparison_operator"
534   (match_code "eq,le,lt,unordered"))
535
536 ;; Return 1 if this is a divide or modulus operator.
537 (define_predicate "divmod_operator"
538   (match_code "div,mod,udiv,umod"))
539
540 ;; Return 1 if this is a float->int conversion operator.
541 (define_predicate "fix_operator"
542   (match_code "fix,unsigned_fix"))
543
544 ;; Recognize an addition operation that includes a constant.  Used to
545 ;; convince reload to canonize (plus (plus reg c1) c2) during register
546 ;; elimination.
547
548 (define_predicate "addition_operation"
549   (and (match_code "plus")
550        (match_test "register_operand (XEXP (op, 0), mode)
551                     && GET_CODE (XEXP (op, 1)) == CONST_INT
552                     && CONST_OK_FOR_LETTER_P (INTVAL (XEXP (op, 1)), 'K')")))