1 ;; Predicate definitions for IA-64.
2 ;; Copyright (C) 2004, 2005 Free Software Foundation, Inc.
4 ;; This file is part of GCC.
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)
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 COPYING. If not, write to
18 ;; the Free Software Foundation, 51 Franklin Street, Fifth Floor,
19 ;; Boston, MA 02110-1301, USA.
21 ;; True if OP is a valid operand for the MEM of a CALL insn.
22 (define_predicate "call_operand"
23 (ior (match_code "symbol_ref")
24 (match_operand 0 "register_operand")))
26 ;; True if OP refers to any kind of symbol.
27 ;; For roughly the same reasons that pmode_register_operand exists, this
28 ;; predicate ignores its mode argument.
29 (define_special_predicate "symbolic_operand"
30 (match_code "symbol_ref,const,label_ref"))
32 ;; True if OP is a SYMBOL_REF which refers to a function.
33 (define_predicate "function_operand"
34 (and (match_code "symbol_ref")
35 (match_test "SYMBOL_REF_FUNCTION_P (op)")))
37 ;; True if OP refers to a symbol in the sdata section.
38 (define_predicate "sdata_symbolic_operand"
39 (match_code "symbol_ref,const")
41 HOST_WIDE_INT offset = 0, size = 0;
43 switch (GET_CODE (op))
47 if (GET_CODE (op) != PLUS
48 || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
49 || GET_CODE (XEXP (op, 1)) != CONST_INT)
51 offset = INTVAL (XEXP (op, 1));
56 if (CONSTANT_POOL_ADDRESS_P (op))
58 size = GET_MODE_SIZE (get_pool_mode (op));
59 if (size > ia64_section_threshold)
66 if (!SYMBOL_REF_LOCAL_P (op) || !SYMBOL_REF_SMALL_P (op))
69 /* Note that in addition to DECLs, we can get various forms
71 t = SYMBOL_REF_DECL (op);
73 t = DECL_SIZE_UNIT (t);
75 t = TYPE_SIZE_UNIT (TREE_TYPE (t));
76 if (t && host_integerp (t, 0))
78 size = tree_low_cst (t, 0);
84 /* Deny the stupid user trick of addressing outside the object. Such
85 things quickly result in GPREL22 relocation overflows. Of course,
86 they're also highly undefined. From a pure pedant's point of view
87 they deserve a slap on the wrist (such as provided by a relocation
88 overflow), but that just leads to bugzilla noise. */
89 return (offset >= 0 && offset <= size);
96 ;; True if OP refers to a symbol in the small address area.
97 (define_predicate "small_addr_symbolic_operand"
98 (match_code "symbol_ref,const")
100 switch (GET_CODE (op))
104 if (GET_CODE (op) != PLUS
105 || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
106 || GET_CODE (XEXP (op, 1)) != CONST_INT)
112 return SYMBOL_REF_SMALL_ADDR_P (op);
119 ;; True if OP refers to a symbol with which we may use any offset.
120 (define_predicate "any_offset_symbol_operand"
121 (match_code "symbol_ref")
123 if (TARGET_NO_PIC || TARGET_AUTO_PIC)
125 if (SYMBOL_REF_SMALL_ADDR_P (op))
127 if (SYMBOL_REF_FUNCTION_P (op))
129 if (sdata_symbolic_operand (op, mode))
134 ;; True if OP refers to a symbol with which we may use 14-bit aligned offsets.
135 ;; False if OP refers to a symbol with which we may not use any offset at any
137 (define_predicate "aligned_offset_symbol_operand"
138 (and (match_code "symbol_ref")
139 (match_test "! SYMBOL_REF_FUNCTION_P (op)")))
141 ;; True if OP refers to a symbol, and is appropriate for a GOT load.
142 (define_predicate "got_symbolic_operand"
143 (match_operand 0 "symbolic_operand" "")
145 HOST_WIDE_INT addend = 0;
147 switch (GET_CODE (op))
153 /* Accept only (plus (symbol_ref) (const_int)). */
155 if (GET_CODE (op) != PLUS
156 || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
157 || GET_CODE (XEXP (op, 1)) != CONST_INT)
160 addend = INTVAL (XEXP (op, 1));
165 /* These symbols shouldn't be used with got loads. */
166 if (SYMBOL_REF_SMALL_ADDR_P (op))
168 if (SYMBOL_REF_TLS_MODEL (op) != 0)
171 if (any_offset_symbol_operand (op, mode))
174 /* The low 14 bits of the constant have been forced to zero
175 so that we do not use up so many GOT entries. Prevent cse
176 from undoing this. */
177 if (aligned_offset_symbol_operand (op, mode))
178 return (addend & 0x3fff) == 0;
187 ;; Return true if OP is a valid thread local storage symbolic operand.
188 (define_predicate "tls_symbolic_operand"
189 (match_code "symbol_ref,const")
191 switch (GET_CODE (op))
194 return SYMBOL_REF_TLS_MODEL (op) != 0;
198 if (GET_CODE (op) != PLUS
199 || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
200 || GET_CODE (XEXP (op, 1)) != CONST_INT)
203 /* We only allow certain offsets for certain tls models. */
204 switch (SYMBOL_REF_TLS_MODEL (XEXP (op, 0)))
206 case TLS_MODEL_GLOBAL_DYNAMIC:
207 case TLS_MODEL_LOCAL_DYNAMIC:
210 case TLS_MODEL_INITIAL_EXEC:
211 return (INTVAL (XEXP (op, 1)) & 0x3fff) == 0;
213 case TLS_MODEL_LOCAL_EXEC:
225 ;; Return true if OP is a local-dynamic thread local storage symbolic operand.
226 (define_predicate "ld_tls_symbolic_operand"
227 (and (match_code "symbol_ref")
228 (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_DYNAMIC")))
230 ;; Return true if OP is an initial-exec thread local storage symbolic operand.
231 (define_predicate "ie_tls_symbolic_operand"
232 (match_code "symbol_ref,const")
234 switch (GET_CODE (op))
238 if (GET_CODE (op) != PLUS
239 || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
240 || GET_CODE (XEXP (op, 1)) != CONST_INT
241 || (INTVAL (XEXP (op, 1)) & 0x3fff) != 0)
247 return SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_INITIAL_EXEC;
254 ;; Return true if OP is a local-exec thread local storage symbolic operand.
255 (define_predicate "le_tls_symbolic_operand"
256 (match_code "symbol_ref,const")
258 switch (GET_CODE (op))
262 if (GET_CODE (op) != PLUS
263 || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
264 || GET_CODE (XEXP (op, 1)) != CONST_INT)
270 return SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_EXEC;
277 ;; Like nonimmediate_operand, but don't allow MEMs that try to use a
278 ;; POST_MODIFY with a REG as displacement.
279 (define_predicate "destination_operand"
280 (and (match_operand 0 "nonimmediate_operand")
281 (match_test "GET_CODE (op) != MEM
282 || GET_CODE (XEXP (op, 0)) != POST_MODIFY
283 || GET_CODE (XEXP (XEXP (XEXP (op, 0), 1), 1)) != REG")))
285 ;; Like memory_operand, but don't allow post-increments.
286 (define_predicate "not_postinc_memory_operand"
287 (and (match_operand 0 "memory_operand")
288 (match_test "GET_RTX_CLASS (GET_CODE (XEXP (op, 0))) != RTX_AUTOINC")))
290 ;; True if OP is a general operand, with some restrictions on symbols.
291 (define_predicate "move_operand"
292 (match_operand 0 "general_operand")
294 switch (GET_CODE (op))
298 HOST_WIDE_INT addend;
300 /* Accept only (plus (symbol_ref) (const_int)). */
302 if (GET_CODE (op) != PLUS
303 || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
304 || GET_CODE (XEXP (op, 1)) != CONST_INT)
307 addend = INTVAL (XEXP (op, 1));
310 /* After reload, we want to allow any offset whatsoever. This
311 allows reload the opportunity to avoid spilling addresses to
312 the stack, and instead simply substitute in the value from a
313 REG_EQUIV. We'll split this up again when splitting the insn. */
314 if (reload_in_progress || reload_completed)
317 /* Some symbol types we allow to use with any offset. */
318 if (any_offset_symbol_operand (op, mode))
321 /* Some symbol types we allow offsets with the low 14 bits of the
322 constant forced to zero so that we do not use up so many GOT
323 entries. We want to prevent cse from undoing this. */
324 if (aligned_offset_symbol_operand (op, mode))
325 return (addend & 0x3fff) == 0;
327 /* The remaining symbol types may never be used with an offset. */
336 ;; True if OP is a register operand that is (or could be) a GR reg.
337 (define_predicate "gr_register_operand"
338 (match_operand 0 "register_operand")
341 if (GET_CODE (op) == SUBREG)
342 op = SUBREG_REG (op);
345 return (regno >= FIRST_PSEUDO_REGISTER || GENERAL_REGNO_P (regno));
348 ;; True if OP is a register operand that is (or could be) an FR reg.
349 (define_predicate "fr_register_operand"
350 (match_operand 0 "register_operand")
353 if (GET_CODE (op) == SUBREG)
354 op = SUBREG_REG (op);
357 return (regno >= FIRST_PSEUDO_REGISTER || FR_REGNO_P (regno));
360 ;; True if OP is a register operand that is (or could be) a GR/FR reg.
361 (define_predicate "grfr_register_operand"
362 (match_operand 0 "register_operand")
365 if (GET_CODE (op) == SUBREG)
366 op = SUBREG_REG (op);
369 return (regno >= FIRST_PSEUDO_REGISTER
370 || GENERAL_REGNO_P (regno)
371 || FR_REGNO_P (regno));
374 ;; True if OP is a nonimmediate operand that is (or could be) a GR reg.
375 (define_predicate "gr_nonimmediate_operand"
376 (match_operand 0 "nonimmediate_operand")
380 if (GET_CODE (op) == MEM)
382 if (GET_CODE (op) == SUBREG)
383 op = SUBREG_REG (op);
386 return (regno >= FIRST_PSEUDO_REGISTER || GENERAL_REGNO_P (regno));
389 ;; True if OP is a nonimmediate operand that is (or could be) a FR reg.
390 (define_predicate "fr_nonimmediate_operand"
391 (match_operand 0 "nonimmediate_operand")
395 if (GET_CODE (op) == MEM)
397 if (GET_CODE (op) == SUBREG)
398 op = SUBREG_REG (op);
401 return (regno >= FIRST_PSEUDO_REGISTER || FR_REGNO_P (regno));
404 ;; True if OP is a nonimmediate operand that is (or could be) a GR/FR reg.
405 (define_predicate "grfr_nonimmediate_operand"
406 (match_operand 0 "nonimmediate_operand")
410 if (GET_CODE (op) == MEM)
412 if (GET_CODE (op) == SUBREG)
413 op = SUBREG_REG (op);
416 return (regno >= FIRST_PSEUDO_REGISTER
417 || GENERAL_REGNO_P (regno)
418 || FR_REGNO_P (regno));
421 ;; True if OP is a GR register operand, or zero.
422 (define_predicate "gr_reg_or_0_operand"
423 (ior (match_operand 0 "gr_register_operand")
424 (and (match_code "const_int,const_double,const_vector")
425 (match_test "op == CONST0_RTX (GET_MODE (op))"))))
427 ;; True if OP is a GR register operand, or a 5 bit immediate operand.
428 (define_predicate "gr_reg_or_5bit_operand"
429 (ior (match_operand 0 "gr_register_operand")
430 (and (match_code "const_int")
431 (match_test "INTVAL (op) >= 0 && INTVAL (op) < 32"))))
433 ;; True if OP is a GR register operand, or a 6 bit immediate operand.
434 (define_predicate "gr_reg_or_6bit_operand"
435 (ior (match_operand 0 "gr_register_operand")
436 (and (match_code "const_int")
437 (match_test "CONST_OK_FOR_M (INTVAL (op))"))))
439 ;; True if OP is a GR register operand, or an 8 bit immediate operand.
440 (define_predicate "gr_reg_or_8bit_operand"
441 (ior (match_operand 0 "gr_register_operand")
442 (and (match_code "const_int")
443 (match_test "CONST_OK_FOR_K (INTVAL (op))"))))
445 ;; True if OP is a GR/FR register operand, or an 8 bit immediate operand.
446 (define_predicate "grfr_reg_or_8bit_operand"
447 (ior (match_operand 0 "grfr_register_operand")
448 (and (match_code "const_int")
449 (match_test "CONST_OK_FOR_K (INTVAL (op))"))))
451 ;; True if OP is a register operand, or an 8 bit adjusted immediate operand.
452 (define_predicate "gr_reg_or_8bit_adjusted_operand"
453 (ior (match_operand 0 "gr_register_operand")
454 (and (match_code "const_int")
455 (match_test "CONST_OK_FOR_L (INTVAL (op))"))))
457 ;; True if OP is a register operand, or is valid for both an 8 bit
458 ;; immediate and an 8 bit adjusted immediate operand. This is necessary
459 ;; because when we emit a compare, we don't know what the condition will be,
460 ;; so we need the union of the immediates accepted by GT and LT.
461 (define_predicate "gr_reg_or_8bit_and_adjusted_operand"
462 (ior (match_operand 0 "gr_register_operand")
463 (and (match_code "const_int")
464 (match_test "CONST_OK_FOR_K (INTVAL (op))
465 && CONST_OK_FOR_L (INTVAL (op))"))))
467 ;; True if OP is a register operand, or a 14 bit immediate operand.
468 (define_predicate "gr_reg_or_14bit_operand"
469 (ior (match_operand 0 "gr_register_operand")
470 (and (match_code "const_int")
471 (match_test "CONST_OK_FOR_I (INTVAL (op))"))))
473 ;; True if OP is a register operand, or a 22 bit immediate operand.
474 (define_predicate "gr_reg_or_22bit_operand"
475 (ior (match_operand 0 "gr_register_operand")
476 (and (match_code "const_int")
477 (match_test "CONST_OK_FOR_J (INTVAL (op))"))))
479 ;; True if OP is a 7 bit immediate operand.
480 (define_predicate "dshift_count_operand"
481 (and (match_code "const_int")
482 (match_test "INTVAL (op) >= 0 && INTVAL (op) < 128")))
484 ;; True if OP is a 6 bit immediate operand.
485 (define_predicate "shift_count_operand"
486 (and (match_code "const_int")
487 (match_test "CONST_OK_FOR_M (INTVAL (op))")))
489 ;; True if OP-1 is a 6 bit immediate operand, used in extr instruction.
490 (define_predicate "extr_len_operand"
491 (and (match_code "const_int")
492 (match_test "CONST_OK_FOR_M (INTVAL (op) - 1)")))
494 ;; True if OP is a 5 bit immediate operand.
495 (define_predicate "shift_32bit_count_operand"
496 (and (match_code "const_int")
497 (match_test "INTVAL (op) >= 0 && INTVAL (op) < 32")))
499 ;; True if OP is one of the immediate values 2, 4, 8, or 16.
500 (define_predicate "shladd_operand"
501 (and (match_code "const_int")
502 (match_test "INTVAL (op) == 2 || INTVAL (op) == 4 ||
503 INTVAL (op) == 8 || INTVAL (op) == 16")))
505 ;; True if OP is one of the immediate values 1, 2, 3, or 4.
506 (define_predicate "shladd_log2_operand"
507 (and (match_code "const_int")
508 (match_test "INTVAL (op) >= 1 && INTVAL (op) <= 4")))
510 ;; True if OP is one of the immediate values -16, -8, -4, -1, 1, 4, 8, 16.
511 (define_predicate "fetchadd_operand"
512 (and (match_code "const_int")
513 (match_test "INTVAL (op) == -16 || INTVAL (op) == -8 ||
514 INTVAL (op) == -4 || INTVAL (op) == -1 ||
515 INTVAL (op) == 1 || INTVAL (op) == 4 ||
516 INTVAL (op) == 8 || INTVAL (op) == 16")))
518 ;; True if OP is 0..3.
519 (define_predicate "const_int_2bit_operand"
520 (and (match_code "const_int")
521 (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 3")))
523 ;; True if OP is a floating-point constant zero, one, or a register.
524 (define_predicate "fr_reg_or_fp01_operand"
525 (ior (match_operand 0 "fr_register_operand")
526 (and (match_code "const_double")
527 (match_test "CONST_DOUBLE_OK_FOR_G (op)"))))
529 ;; Like fr_reg_or_fp01_operand, but don't allow any SUBREGs.
530 (define_predicate "xfreg_or_fp01_operand"
531 (and (match_operand 0 "fr_reg_or_fp01_operand")
532 (not (match_code "subreg"))))
534 ;; True if OP is a constant zero, or a register.
535 (define_predicate "fr_reg_or_0_operand"
536 (ior (match_operand 0 "fr_register_operand")
537 (and (match_code "const_double,const_vector")
538 (match_test "op == CONST0_RTX (GET_MODE (op))"))))
540 ;; True if this is a comparison operator, which accepts a normal 8-bit
541 ;; signed immediate operand.
542 (define_predicate "normal_comparison_operator"
543 (match_code "eq,ne,gt,le,gtu,leu"))
545 ;; True if this is a comparison operator, which accepts an adjusted 8-bit
546 ;; signed immediate operand.
547 (define_predicate "adjusted_comparison_operator"
548 (match_code "lt,ge,ltu,geu"))
550 ;; True if this is a signed inequality operator.
551 (define_predicate "signed_inequality_operator"
552 (match_code "ge,gt,le,lt"))
554 ;; True if this operator is valid for predication.
555 (define_predicate "predicate_operator"
556 (match_code "eq,ne"))
558 ;; True if this operator can be used in a conditional operation.
559 (define_predicate "condop_operator"
560 (match_code "plus,minus,ior,xor,and"))
562 ;; These three are hardware registers that can only be addressed in
563 ;; DImode. It's not strictly necessary to test mode == DImode here,
564 ;; but it makes decent insurance against someone writing a
565 ;; match_operand wrong.
567 ;; True if this is the ar.lc register.
568 (define_predicate "ar_lc_reg_operand"
569 (and (match_code "reg")
570 (match_test "mode == DImode && REGNO (op) == AR_LC_REGNUM")))
572 ;; True if this is the ar.ccv register.
573 (define_predicate "ar_ccv_reg_operand"
574 (and (match_code "reg")
575 (match_test "mode == DImode && REGNO (op) == AR_CCV_REGNUM")))
577 ;; True if this is the ar.pfs register.
578 (define_predicate "ar_pfs_reg_operand"
579 (and (match_code "reg")
580 (match_test "mode == DImode && REGNO (op) == AR_PFS_REGNUM")))
582 ;; True if OP is valid as a base register in a reg + offset address.
583 ;; ??? Should I copy the flag_omit_frame_pointer and cse_not_expected
584 ;; checks from pa.c basereg_operand as well? Seems to be OK without them
586 (define_predicate "basereg_operand"
587 (match_operand 0 "register_operand")
589 return REG_P (op) && REG_POINTER (op);