1 ;; Predicate definitions for IA-64.
2 ;; Copyright (C) 2004, 2005, 2007 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 3, 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 COPYING3. If not see
18 ;; <http://www.gnu.org/licenses/>.
20 ;; True if OP is a valid operand for the MEM of a CALL insn.
21 (define_predicate "call_operand"
22 (ior (match_code "symbol_ref")
23 (match_operand 0 "register_operand")))
25 ;; True if OP refers to any kind of symbol.
26 ;; For roughly the same reasons that pmode_register_operand exists, this
27 ;; predicate ignores its mode argument.
28 (define_special_predicate "symbolic_operand"
29 (match_code "symbol_ref,const,label_ref"))
31 ;; True if OP is a SYMBOL_REF which refers to a function.
32 (define_predicate "function_operand"
33 (and (match_code "symbol_ref")
34 (match_test "SYMBOL_REF_FUNCTION_P (op)")))
36 ;; True if OP refers to a symbol in the sdata section.
37 (define_predicate "sdata_symbolic_operand"
38 (match_code "symbol_ref,const")
40 HOST_WIDE_INT offset = 0, size = 0;
42 switch (GET_CODE (op))
46 if (GET_CODE (op) != PLUS
47 || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
48 || GET_CODE (XEXP (op, 1)) != CONST_INT)
50 offset = INTVAL (XEXP (op, 1));
55 if (CONSTANT_POOL_ADDRESS_P (op))
57 size = GET_MODE_SIZE (get_pool_mode (op));
58 if (size > ia64_section_threshold)
65 if (!SYMBOL_REF_LOCAL_P (op) || !SYMBOL_REF_SMALL_P (op))
68 /* Note that in addition to DECLs, we can get various forms
70 t = SYMBOL_REF_DECL (op);
72 t = DECL_SIZE_UNIT (t);
74 t = TYPE_SIZE_UNIT (TREE_TYPE (t));
75 if (t && host_integerp (t, 0))
77 size = tree_low_cst (t, 0);
83 /* Deny the stupid user trick of addressing outside the object. Such
84 things quickly result in GPREL22 relocation overflows. Of course,
85 they're also highly undefined. From a pure pedant's point of view
86 they deserve a slap on the wrist (such as provided by a relocation
87 overflow), but that just leads to bugzilla noise. */
88 return (offset >= 0 && offset <= size);
95 ;; True if OP refers to a symbol in the small address area.
96 (define_predicate "small_addr_symbolic_operand"
97 (match_code "symbol_ref,const")
99 switch (GET_CODE (op))
103 if (GET_CODE (op) != PLUS
104 || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
105 || GET_CODE (XEXP (op, 1)) != CONST_INT)
111 return SYMBOL_REF_SMALL_ADDR_P (op);
118 ;; True if OP refers to a symbol with which we may use any offset.
119 (define_predicate "any_offset_symbol_operand"
120 (match_code "symbol_ref")
122 if (TARGET_NO_PIC || TARGET_AUTO_PIC)
124 if (SYMBOL_REF_SMALL_ADDR_P (op))
126 if (SYMBOL_REF_FUNCTION_P (op))
128 if (sdata_symbolic_operand (op, mode))
133 ;; True if OP refers to a symbol with which we may use 14-bit aligned offsets.
134 ;; False if OP refers to a symbol with which we may not use any offset at any
136 (define_predicate "aligned_offset_symbol_operand"
137 (and (match_code "symbol_ref")
138 (match_test "! SYMBOL_REF_FUNCTION_P (op)")))
140 ;; True if OP refers to a symbol, and is appropriate for a GOT load.
141 (define_predicate "got_symbolic_operand"
142 (match_operand 0 "symbolic_operand" "")
144 HOST_WIDE_INT addend = 0;
146 switch (GET_CODE (op))
152 /* Accept only (plus (symbol_ref) (const_int)). */
154 if (GET_CODE (op) != PLUS
155 || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
156 || GET_CODE (XEXP (op, 1)) != CONST_INT)
159 addend = INTVAL (XEXP (op, 1));
164 /* These symbols shouldn't be used with got loads. */
165 if (SYMBOL_REF_SMALL_ADDR_P (op))
167 if (SYMBOL_REF_TLS_MODEL (op) != 0)
170 if (any_offset_symbol_operand (op, mode))
173 /* The low 14 bits of the constant have been forced to zero
174 so that we do not use up so many GOT entries. Prevent cse
175 from undoing this. */
176 if (aligned_offset_symbol_operand (op, mode))
177 return (addend & 0x3fff) == 0;
186 ;; Return true if OP is a valid thread local storage symbolic operand.
187 (define_predicate "tls_symbolic_operand"
188 (match_code "symbol_ref,const")
190 switch (GET_CODE (op))
193 return SYMBOL_REF_TLS_MODEL (op) != 0;
197 if (GET_CODE (op) != PLUS
198 || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
199 || GET_CODE (XEXP (op, 1)) != CONST_INT)
202 /* We only allow certain offsets for certain tls models. */
203 switch (SYMBOL_REF_TLS_MODEL (XEXP (op, 0)))
205 case TLS_MODEL_GLOBAL_DYNAMIC:
206 case TLS_MODEL_LOCAL_DYNAMIC:
209 case TLS_MODEL_INITIAL_EXEC:
210 return (INTVAL (XEXP (op, 1)) & 0x3fff) == 0;
212 case TLS_MODEL_LOCAL_EXEC:
224 ;; Return true if OP is a local-dynamic thread local storage symbolic operand.
225 (define_predicate "ld_tls_symbolic_operand"
226 (and (match_code "symbol_ref")
227 (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_DYNAMIC")))
229 ;; Return true if OP is an initial-exec thread local storage symbolic operand.
230 (define_predicate "ie_tls_symbolic_operand"
231 (match_code "symbol_ref,const")
233 switch (GET_CODE (op))
237 if (GET_CODE (op) != PLUS
238 || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
239 || GET_CODE (XEXP (op, 1)) != CONST_INT
240 || (INTVAL (XEXP (op, 1)) & 0x3fff) != 0)
246 return SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_INITIAL_EXEC;
253 ;; Return true if OP is a local-exec thread local storage symbolic operand.
254 (define_predicate "le_tls_symbolic_operand"
255 (match_code "symbol_ref,const")
257 switch (GET_CODE (op))
261 if (GET_CODE (op) != PLUS
262 || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
263 || GET_CODE (XEXP (op, 1)) != CONST_INT)
269 return SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_EXEC;
276 ;; Like nonimmediate_operand, but don't allow MEMs that try to use a
277 ;; POST_MODIFY with a REG as displacement.
278 (define_predicate "destination_operand"
279 (and (match_operand 0 "nonimmediate_operand")
280 (match_test "GET_CODE (op) != MEM
281 || GET_CODE (XEXP (op, 0)) != POST_MODIFY
282 || GET_CODE (XEXP (XEXP (XEXP (op, 0), 1), 1)) != REG")))
284 ;; Like memory_operand, but don't allow post-increments.
285 (define_predicate "not_postinc_memory_operand"
286 (and (match_operand 0 "memory_operand")
287 (match_test "GET_RTX_CLASS (GET_CODE (XEXP (op, 0))) != RTX_AUTOINC")))
289 ;; True if OP is a general operand, with some restrictions on symbols.
290 (define_predicate "move_operand"
291 (match_operand 0 "general_operand")
293 switch (GET_CODE (op))
297 HOST_WIDE_INT addend;
299 /* Accept only (plus (symbol_ref) (const_int)). */
301 if (GET_CODE (op) != PLUS
302 || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
303 || GET_CODE (XEXP (op, 1)) != CONST_INT)
306 addend = INTVAL (XEXP (op, 1));
309 /* After reload, we want to allow any offset whatsoever. This
310 allows reload the opportunity to avoid spilling addresses to
311 the stack, and instead simply substitute in the value from a
312 REG_EQUIV. We'll split this up again when splitting the insn. */
313 if (reload_in_progress || reload_completed)
316 /* Some symbol types we allow to use with any offset. */
317 if (any_offset_symbol_operand (op, mode))
320 /* Some symbol types we allow offsets with the low 14 bits of the
321 constant forced to zero so that we do not use up so many GOT
322 entries. We want to prevent cse from undoing this. */
323 if (aligned_offset_symbol_operand (op, mode))
324 return (addend & 0x3fff) == 0;
326 /* The remaining symbol types may never be used with an offset. */
335 ;; True if OP is a register operand that is (or could be) a GR reg.
336 (define_predicate "gr_register_operand"
337 (match_operand 0 "register_operand")
340 if (GET_CODE (op) == SUBREG)
341 op = SUBREG_REG (op);
344 return (regno >= FIRST_PSEUDO_REGISTER || GENERAL_REGNO_P (regno));
347 ;; True if OP is a register operand that is (or could be) an FR reg.
348 (define_predicate "fr_register_operand"
349 (match_operand 0 "register_operand")
352 if (GET_CODE (op) == SUBREG)
353 op = SUBREG_REG (op);
356 return (regno >= FIRST_PSEUDO_REGISTER || FR_REGNO_P (regno));
359 ;; True if OP is a register operand that is (or could be) a GR/FR reg.
360 (define_predicate "grfr_register_operand"
361 (match_operand 0 "register_operand")
364 if (GET_CODE (op) == SUBREG)
365 op = SUBREG_REG (op);
368 return (regno >= FIRST_PSEUDO_REGISTER
369 || GENERAL_REGNO_P (regno)
370 || FR_REGNO_P (regno));
373 ;; True if OP is a nonimmediate operand that is (or could be) a GR reg.
374 (define_predicate "gr_nonimmediate_operand"
375 (match_operand 0 "nonimmediate_operand")
379 if (GET_CODE (op) == MEM)
381 if (GET_CODE (op) == SUBREG)
382 op = SUBREG_REG (op);
385 return (regno >= FIRST_PSEUDO_REGISTER || GENERAL_REGNO_P (regno));
388 ;; True if OP is a nonimmediate operand that is (or could be) a FR reg.
389 (define_predicate "fr_nonimmediate_operand"
390 (match_operand 0 "nonimmediate_operand")
394 if (GET_CODE (op) == MEM)
396 if (GET_CODE (op) == SUBREG)
397 op = SUBREG_REG (op);
400 return (regno >= FIRST_PSEUDO_REGISTER || FR_REGNO_P (regno));
403 ;; True if OP is a nonimmediate operand that is (or could be) a GR/FR reg.
404 (define_predicate "grfr_nonimmediate_operand"
405 (match_operand 0 "nonimmediate_operand")
409 if (GET_CODE (op) == MEM)
411 if (GET_CODE (op) == SUBREG)
412 op = SUBREG_REG (op);
415 return (regno >= FIRST_PSEUDO_REGISTER
416 || GENERAL_REGNO_P (regno)
417 || FR_REGNO_P (regno));
420 ;; True if OP is a GR register operand, or zero.
421 (define_predicate "gr_reg_or_0_operand"
422 (ior (match_operand 0 "gr_register_operand")
423 (and (match_code "const_int,const_double,const_vector")
424 (match_test "op == CONST0_RTX (GET_MODE (op))"))))
426 ;; True if OP is a GR register operand, or a 5-bit immediate operand.
427 (define_predicate "gr_reg_or_5bit_operand"
428 (ior (match_operand 0 "gr_register_operand")
429 (and (match_code "const_int")
430 (match_test "INTVAL (op) >= 0 && INTVAL (op) < 32"))))
432 ;; True if OP is a GR register operand, or a 6-bit immediate operand.
433 (define_predicate "gr_reg_or_6bit_operand"
434 (ior (match_operand 0 "gr_register_operand")
435 (and (match_code "const_int")
436 (match_test "satisfies_constraint_M (op)"))))
438 ;; True if OP is a GR register operand, or an 8-bit immediate operand.
439 (define_predicate "gr_reg_or_8bit_operand"
440 (ior (match_operand 0 "gr_register_operand")
441 (and (match_code "const_int")
442 (match_test "satisfies_constraint_K (op)"))))
444 ;; True if OP is a GR/FR register operand, or an 8-bit immediate operand.
445 (define_predicate "grfr_reg_or_8bit_operand"
446 (ior (match_operand 0 "grfr_register_operand")
447 (and (match_code "const_int")
448 (match_test "satisfies_constraint_K (op)"))))
450 ;; True if OP is a register operand, or an 8-bit adjusted immediate operand.
451 (define_predicate "gr_reg_or_8bit_adjusted_operand"
452 (ior (match_operand 0 "gr_register_operand")
453 (and (match_code "const_int")
454 (match_test "satisfies_constraint_L (op)"))))
456 ;; True if OP is a register operand, or is valid for both an 8-bit
457 ;; immediate and an 8-bit adjusted immediate operand. This is necessary
458 ;; because when we emit a compare, we don't know what the condition will be,
459 ;; so we need the union of the immediates accepted by GT and LT.
460 (define_predicate "gr_reg_or_8bit_and_adjusted_operand"
461 (ior (match_operand 0 "gr_register_operand")
462 (and (match_code "const_int")
463 (match_test "satisfies_constraint_K (op)
464 && satisfies_constraint_L (op)"))))
466 ;; True if OP is a register operand, or a 14-bit immediate operand.
467 (define_predicate "gr_reg_or_14bit_operand"
468 (ior (match_operand 0 "gr_register_operand")
469 (and (match_code "const_int")
470 (match_test "satisfies_constraint_I (op)"))))
472 ;; True if OP is a register operand, or a 22-bit immediate operand.
473 (define_predicate "gr_reg_or_22bit_operand"
474 (ior (match_operand 0 "gr_register_operand")
475 (and (match_code "const_int")
476 (match_test "satisfies_constraint_J (op)"))))
478 ;; True if OP is a 7-bit immediate operand.
479 (define_predicate "dshift_count_operand"
480 (and (match_code "const_int")
481 (match_test "INTVAL (op) >= 0 && INTVAL (op) < 128")))
483 ;; True if OP is a 6-bit immediate operand.
484 (define_predicate "shift_count_operand"
485 (and (match_code "const_int")
486 (match_test "satisfies_constraint_M (op)")))
488 ;; True if OP-1 is a 6-bit immediate operand, used in extr instruction.
489 (define_predicate "extr_len_operand"
490 (and (match_code "const_int")
491 (match_test "satisfies_constraint_M (GEN_INT (INTVAL (op) - 1))")))
493 ;; True if OP is a 5-bit immediate operand.
494 (define_predicate "shift_32bit_count_operand"
495 (and (match_code "const_int")
496 (match_test "INTVAL (op) >= 0 && INTVAL (op) < 32")))
498 ;; True if OP is one of the immediate values 2, 4, 8, or 16.
499 (define_predicate "shladd_operand"
500 (and (match_code "const_int")
501 (match_test "INTVAL (op) == 2 || INTVAL (op) == 4 ||
502 INTVAL (op) == 8 || INTVAL (op) == 16")))
504 ;; True if OP is one of the immediate values 1, 2, 3, or 4.
505 (define_predicate "shladd_log2_operand"
506 (and (match_code "const_int")
507 (match_test "INTVAL (op) >= 1 && INTVAL (op) <= 4")))
509 ;; True if OP is one of the immediate values -16, -8, -4, -1, 1, 4, 8, 16.
510 (define_predicate "fetchadd_operand"
511 (and (match_code "const_int")
512 (match_test "INTVAL (op) == -16 || INTVAL (op) == -8 ||
513 INTVAL (op) == -4 || INTVAL (op) == -1 ||
514 INTVAL (op) == 1 || INTVAL (op) == 4 ||
515 INTVAL (op) == 8 || INTVAL (op) == 16")))
517 ;; True if OP is 0..3.
518 (define_predicate "const_int_2bit_operand"
519 (and (match_code "const_int")
520 (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 3")))
522 ;; True if OP is a floating-point constant zero, one, or a register.
523 (define_predicate "fr_reg_or_fp01_operand"
524 (ior (match_operand 0 "fr_register_operand")
525 (and (match_code "const_double")
526 (match_test "satisfies_constraint_G (op)"))))
528 ;; Like fr_reg_or_fp01_operand, but don't allow any SUBREGs.
529 (define_predicate "xfreg_or_fp01_operand"
530 (and (match_operand 0 "fr_reg_or_fp01_operand")
531 (not (match_code "subreg"))))
533 ;; True if OP is a constant zero, or a register.
534 (define_predicate "fr_reg_or_0_operand"
535 (ior (match_operand 0 "fr_register_operand")
536 (and (match_code "const_double,const_vector")
537 (match_test "op == CONST0_RTX (GET_MODE (op))"))))
539 ;; True if this is a comparison operator, which accepts a normal 8-bit
540 ;; signed immediate operand.
541 (define_predicate "normal_comparison_operator"
542 (match_code "eq,ne,gt,le,gtu,leu"))
544 ;; True if this is a comparison operator, which accepts an adjusted 8-bit
545 ;; signed immediate operand.
546 (define_predicate "adjusted_comparison_operator"
547 (match_code "lt,ge,ltu,geu"))
549 ;; True if this is a signed inequality operator.
550 (define_predicate "signed_inequality_operator"
551 (match_code "ge,gt,le,lt"))
553 ;; True if this operator is valid for predication.
554 (define_predicate "predicate_operator"
555 (match_code "eq,ne"))
557 ;; True if this operator can be used in a conditional operation.
558 (define_predicate "condop_operator"
559 (match_code "plus,minus,ior,xor,and"))
561 ;; These three are hardware registers that can only be addressed in
562 ;; DImode. It's not strictly necessary to test mode == DImode here,
563 ;; but it makes decent insurance against someone writing a
564 ;; match_operand wrong.
566 ;; True if this is the ar.lc register.
567 (define_predicate "ar_lc_reg_operand"
568 (and (match_code "reg")
569 (match_test "mode == DImode && REGNO (op) == AR_LC_REGNUM")))
571 ;; True if this is the ar.ccv register.
572 (define_predicate "ar_ccv_reg_operand"
573 (and (match_code "reg")
574 (match_test "mode == DImode && REGNO (op) == AR_CCV_REGNUM")))
576 ;; True if this is the ar.pfs register.
577 (define_predicate "ar_pfs_reg_operand"
578 (and (match_code "reg")
579 (match_test "mode == DImode && REGNO (op) == AR_PFS_REGNUM")))
581 ;; True if OP is valid as a base register in a reg + offset address.
582 ;; ??? Should I copy the flag_omit_frame_pointer and cse_not_expected
583 ;; checks from pa.c basereg_operand as well? Seems to be OK without them
585 (define_predicate "basereg_operand"
586 (match_operand 0 "register_operand")
588 return REG_P (op) && REG_POINTER (op);