1 ;; Predicate definitions for DEC Alpha.
2 ;; Copyright (C) 2004-2014 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 ;; Return 1 if OP is the zero constant for MODE.
21 (define_predicate "const0_operand"
22 (and (match_code "const_int,const_double,const_vector")
23 (match_test "op == CONST0_RTX (mode)")))
25 ;; Returns true if OP is either the constant zero or a register.
26 (define_predicate "reg_or_0_operand"
27 (ior (match_operand 0 "register_operand")
28 (match_operand 0 "const0_operand")))
30 ;; Return 1 if OP is a constant in the range of 0-63 (for a shift) or
32 (define_predicate "reg_or_6bit_operand"
33 (if_then_else (match_code "const_int")
34 (match_test "INTVAL (op) >= 0 && INTVAL (op) < 64")
35 (match_operand 0 "register_operand")))
37 ;; Return 1 if OP is an 8-bit constant.
38 (define_predicate "cint8_operand"
39 (and (match_code "const_int")
40 (match_test "INTVAL (op) >= 0 && INTVAL (op) < 256")))
42 ;; Return 1 if OP is an 8-bit constant or any register.
43 (define_predicate "reg_or_8bit_operand"
44 (if_then_else (match_code "const_int")
45 (match_test "INTVAL (op) >= 0 && INTVAL (op) < 256")
46 (match_operand 0 "register_operand")))
48 ;; Return 1 if OP is a constant or any register.
49 (define_predicate "reg_or_cint_operand"
50 (ior (match_operand 0 "register_operand")
51 (match_operand 0 "const_int_operand")))
53 ;; Return 1 if the operand is a valid second operand to an add insn.
54 (define_predicate "add_operand"
55 (if_then_else (match_code "const_int")
56 (match_test "satisfies_constraint_K (op) || satisfies_constraint_L (op)")
57 (match_operand 0 "register_operand")))
59 ;; Return 1 if the operand is a valid second operand to a
60 ;; sign-extending add insn.
61 (define_predicate "sext_add_operand"
62 (if_then_else (match_code "const_int")
63 (match_test "satisfies_constraint_I (op) || satisfies_constraint_O (op)")
64 (match_operand 0 "register_operand")))
66 ;; Return 1 if the operand is a non-symbolic constant operand that
67 ;; does not satisfy add_operand.
68 (define_predicate "non_add_const_operand"
69 (and (match_code "const_int,const_double,const_vector")
70 (not (match_operand 0 "add_operand"))))
72 ;; Return 1 if the operand is a non-symbolic, nonzero constant operand.
73 (define_predicate "non_zero_const_operand"
74 (and (match_code "const_int,const_double,const_vector")
75 (match_test "op != CONST0_RTX (mode)")))
77 ;; Return 1 if OP is the constant 4 or 8.
78 (define_predicate "const48_operand"
79 (and (match_code "const_int")
80 (match_test "INTVAL (op) == 4 || INTVAL (op) == 8")))
82 ;; Return 1 if OP is a valid first operand to an AND insn.
83 (define_predicate "and_operand"
84 (if_then_else (match_code "const_int")
85 (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) < 0x100
86 || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100
87 || zap_mask (INTVAL (op))")
88 (if_then_else (match_code "const_double")
89 (match_test "GET_MODE (op) == VOIDmode
90 && zap_mask (CONST_DOUBLE_LOW (op))
91 && zap_mask (CONST_DOUBLE_HIGH (op))")
92 (match_operand 0 "register_operand"))))
94 ;; Return 1 if OP is a valid first operand to an IOR or XOR insn.
95 (define_predicate "or_operand"
96 (if_then_else (match_code "const_int")
97 (match_test "(unsigned HOST_WIDE_INT) INTVAL (op) < 0x100
98 || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100")
99 (match_operand 0 "register_operand")))
101 ;; Return 1 if OP is a constant that is the width, in bits, of an integral
102 ;; mode not larger than DImode.
103 (define_predicate "mode_width_operand"
104 (match_code "const_int")
106 HOST_WIDE_INT i = INTVAL (op);
107 return i == 8 || i == 16 || i == 32 || i == 64;
110 ;; Return 1 if OP is a constant that is a mask of ones of width of an
111 ;; integral machine mode not larger than DImode.
112 (define_predicate "mode_mask_operand"
113 (match_code "const_int,const_double")
115 if (CONST_INT_P (op))
117 HOST_WIDE_INT value = INTVAL (op);
123 if (value == 0xffffffff)
128 else if (HOST_BITS_PER_WIDE_INT == 32 && GET_CODE (op) == CONST_DOUBLE)
130 if (CONST_DOUBLE_LOW (op) == 0xffffffff && CONST_DOUBLE_HIGH (op) == 0)
136 ;; Return 1 if OP is a multiple of 8 less than 64.
137 (define_predicate "mul8_operand"
138 (match_code "const_int")
140 unsigned HOST_WIDE_INT i = INTVAL (op);
141 return i < 64 && i % 8 == 0;
144 ;; Return 1 if OP is a hard floating-point register.
145 (define_predicate "hard_fp_register_operand"
146 (match_operand 0 "register_operand")
148 if (GET_CODE (op) == SUBREG)
149 op = SUBREG_REG (op);
150 return REGNO_REG_CLASS (REGNO (op)) == FLOAT_REGS;
153 ;; Return 1 if OP is a hard general register.
154 (define_predicate "hard_int_register_operand"
155 (match_operand 0 "register_operand")
157 if (GET_CODE (op) == SUBREG)
158 op = SUBREG_REG (op);
159 return REGNO_REG_CLASS (REGNO (op)) == GENERAL_REGS;
162 ;; Return 1 if OP is something that can be reloaded into a register;
163 ;; if it is a MEM, it need not be valid.
164 (define_predicate "some_operand"
165 (ior (match_code "reg,mem,const_int,const_double,const_vector,
166 label_ref,symbol_ref,const,high")
167 (and (match_code "subreg")
168 (match_test "some_operand (SUBREG_REG (op), VOIDmode)"))))
170 ;; Likewise, but don't accept constants.
171 (define_predicate "some_ni_operand"
172 (ior (match_code "reg,mem")
173 (and (match_code "subreg")
174 (match_test "some_ni_operand (SUBREG_REG (op), VOIDmode)"))))
176 ;; Return 1 if OP is a valid operand for the source of a move insn.
177 (define_predicate "input_operand"
178 (match_code "label_ref,symbol_ref,const,high,reg,subreg,mem,
179 const_double,const_vector,const_int")
181 switch (GET_CODE (op))
186 if (TARGET_EXPLICIT_RELOCS)
188 /* We don't split symbolic operands into something unintelligable
189 until after reload, but we do not wish non-small, non-global
190 symbolic operands to be reconstructed from their high/lo_sum
192 return (small_symbolic_operand (op, mode)
193 || global_symbolic_operand (op, mode)
194 || gotdtp_symbolic_operand (op, mode)
195 || gottp_symbolic_operand (op, mode));
197 /* VMS still has a 32-bit mode. */
198 return mode == ptr_mode || mode == Pmode;
201 return (TARGET_EXPLICIT_RELOCS
202 && local_symbolic_operand (XEXP (op, 0), mode));
208 if (register_operand (op, mode))
210 /* ... fall through ... */
212 return ((TARGET_BWX || (mode != HImode && mode != QImode))
213 && general_operand (op, mode));
216 return op == CONST0_RTX (mode);
219 if (reload_in_progress || reload_completed)
220 return alpha_legitimate_constant_p (mode, op);
221 return op == CONST0_RTX (mode);
224 if (mode == QImode || mode == HImode)
226 if (reload_in_progress || reload_completed)
227 return alpha_legitimate_constant_p (mode, op);
228 return add_operand (op, mode);
236 ;; Return 1 if OP is a SYMBOL_REF for a function known to be in this
237 ;; file, and in the same section as the current function.
239 (define_predicate "samegp_function_operand"
240 (match_code "symbol_ref")
242 /* Easy test for recursion. */
243 if (op == XEXP (DECL_RTL (current_function_decl), 0))
246 /* Functions that are not local can be overridden, and thus may
247 not share the same gp. */
248 if (! SYMBOL_REF_LOCAL_P (op))
251 /* If -msmall-data is in effect, assume that there is only one GP
252 for the module, and so any local symbol has this property. We
253 need explicit relocations to be able to enforce this for symbols
254 not defined in this unit of translation, however. */
255 if (TARGET_EXPLICIT_RELOCS && TARGET_SMALL_DATA)
258 /* Functions that are not external are defined in this UoT,
259 and thus must share the same gp. */
260 return ! SYMBOL_REF_EXTERNAL_P (op);
263 ;; Return 1 if OP is a SYMBOL_REF for which we can make a call via bsr.
264 (define_predicate "direct_call_operand"
265 (match_operand 0 "samegp_function_operand")
267 /* If profiling is implemented via linker tricks, we can't jump
268 to the nogp alternate entry point. Note that crtl->profile
269 would not be correct, since that doesn't indicate if the target
270 function uses profiling. */
271 /* ??? TARGET_PROFILING_NEEDS_GP isn't really the right test,
272 but is approximately correct for the OSF ABIs. Don't know
273 what to do for VMS, NT, or UMK. */
274 if (!TARGET_PROFILING_NEEDS_GP && profile_flag)
277 /* Must be a function. In some cases folks create thunks in static
278 data structures and then make calls to them. If we allow the
279 direct call, we'll get an error from the linker about !samegp reloc
280 against a symbol without a .prologue directive. */
281 if (!SYMBOL_REF_FUNCTION_P (op))
284 /* Must be "near" so that the branch is assumed to reach. With
285 -msmall-text, this is assumed true of all local symbols. Since
286 we've already checked samegp, locality is already assured. */
287 if (TARGET_SMALL_TEXT)
293 ;; Return 1 if OP is a valid operand for the MEM of a CALL insn.
295 ;; For TARGET_ABI_OSF, we want to restrict to R27 or a pseudo.
297 (define_predicate "call_operand"
298 (ior (match_code "symbol_ref")
299 (and (match_code "reg")
300 (ior (match_test "!TARGET_ABI_OSF")
301 (match_test "!HARD_REGISTER_P (op)")
302 (match_test "REGNO (op) == R27_REG")))))
304 ;; Return true if OP is a LABEL_REF, or SYMBOL_REF or CONST referencing
305 ;; a (non-tls) variable known to be defined in this file.
306 (define_predicate "local_symbolic_operand"
307 (match_code "label_ref,const,symbol_ref")
309 if (GET_CODE (op) == CONST
310 && GET_CODE (XEXP (op, 0)) == PLUS
311 && CONST_INT_P (XEXP (XEXP (op, 0), 1)))
312 op = XEXP (XEXP (op, 0), 0);
314 if (GET_CODE (op) == LABEL_REF)
317 if (GET_CODE (op) != SYMBOL_REF)
320 return (SYMBOL_REF_LOCAL_P (op)
321 && !SYMBOL_REF_WEAK (op)
322 && !SYMBOL_REF_TLS_MODEL (op));
325 ;; Return true if OP is a SYMBOL_REF or CONST referencing a variable
326 ;; known to be defined in this file in the small data area.
327 (define_predicate "small_symbolic_operand"
328 (match_code "const,symbol_ref")
330 HOST_WIDE_INT ofs = 0, max_ofs = 0;
332 if (! TARGET_SMALL_DATA)
335 if (GET_CODE (op) == CONST
336 && GET_CODE (XEXP (op, 0)) == PLUS
337 && CONST_INT_P (XEXP (XEXP (op, 0), 1)))
339 ofs = INTVAL (XEXP (XEXP (op, 0), 1));
340 op = XEXP (XEXP (op, 0), 0);
343 if (GET_CODE (op) != SYMBOL_REF)
346 /* ??? There's no encode_section_info equivalent for the rtl
347 constant pool, so SYMBOL_FLAG_SMALL never gets set. */
348 if (CONSTANT_POOL_ADDRESS_P (op))
350 max_ofs = GET_MODE_SIZE (get_pool_mode (op));
351 if (max_ofs > g_switch_value)
354 else if (SYMBOL_REF_LOCAL_P (op)
355 && SYMBOL_REF_SMALL_P (op)
356 && !SYMBOL_REF_WEAK (op)
357 && !SYMBOL_REF_TLS_MODEL (op))
359 if (SYMBOL_REF_DECL (op))
360 max_ofs = tree_to_uhwi (DECL_SIZE_UNIT (SYMBOL_REF_DECL (op)));
365 /* Given that we know that the GP is always 8 byte aligned, we can
366 always adjust by 7 without overflowing. */
370 /* Since we know this is an object in a small data section, we know the
371 entire section is addressable via GP. We don't know where the section
372 boundaries are, but we know the entire object is within. */
373 return IN_RANGE (ofs, 0, max_ofs - 1);
376 ;; Return true if OP is a SYMBOL_REF or CONST referencing a variable
377 ;; not known (or known not) to be defined in this file.
378 (define_predicate "global_symbolic_operand"
379 (match_code "const,symbol_ref")
381 if (GET_CODE (op) == CONST
382 && GET_CODE (XEXP (op, 0)) == PLUS
383 && CONST_INT_P (XEXP (XEXP (op, 0), 1)))
384 op = XEXP (XEXP (op, 0), 0);
386 if (GET_CODE (op) != SYMBOL_REF)
389 return ((!SYMBOL_REF_LOCAL_P (op) || SYMBOL_REF_WEAK (op))
390 && !SYMBOL_REF_TLS_MODEL (op));
393 ;; Returns 1 if OP is a symbolic operand, i.e. a symbol_ref or a label_ref,
394 ;; possibly with an offset.
395 (define_predicate "symbolic_operand"
396 (ior (match_code "symbol_ref,label_ref")
397 (and (match_code "const")
398 (match_test "GET_CODE (XEXP (op,0)) == PLUS
399 && (GET_CODE (XEXP (XEXP (op,0), 0)) == SYMBOL_REF
400 || GET_CODE (XEXP (XEXP (op,0), 0)) == LABEL_REF)
401 && CONST_INT_P (XEXP (XEXP (op,0), 1))"))))
403 ;; Return true if OP is valid for 16-bit DTP relative relocations.
404 (define_predicate "dtp16_symbolic_operand"
405 (and (match_code "const")
406 (match_test "tls_symbolic_operand_1 (op, 16, UNSPEC_DTPREL)")))
408 ;; Return true if OP is valid for 32-bit DTP relative relocations.
409 (define_predicate "dtp32_symbolic_operand"
410 (and (match_code "const")
411 (match_test "tls_symbolic_operand_1 (op, 32, UNSPEC_DTPREL)")))
413 ;; Return true if OP is valid for 64-bit DTP relative relocations.
414 (define_predicate "gotdtp_symbolic_operand"
415 (and (match_code "const")
416 (match_test "tls_symbolic_operand_1 (op, 64, UNSPEC_DTPREL)")))
418 ;; Return true if OP is valid for 16-bit TP relative relocations.
419 (define_predicate "tp16_symbolic_operand"
420 (and (match_code "const")
421 (match_test "tls_symbolic_operand_1 (op, 16, UNSPEC_TPREL)")))
423 ;; Return true if OP is valid for 32-bit TP relative relocations.
424 (define_predicate "tp32_symbolic_operand"
425 (and (match_code "const")
426 (match_test "tls_symbolic_operand_1 (op, 32, UNSPEC_TPREL)")))
428 ;; Return true if OP is valid for 64-bit TP relative relocations.
429 (define_predicate "gottp_symbolic_operand"
430 (and (match_code "const")
431 (match_test "tls_symbolic_operand_1 (op, 64, UNSPEC_TPREL)")))
433 ;; Return 1 if this memory address is a known aligned register plus
434 ;; a constant. It must be a valid address. This means that we can do
435 ;; this as an aligned reference plus some offset.
437 ;; Take into account what reload will do. Oh god this is awful.
438 ;; The horrible comma-operator construct below is to prevent genrecog
439 ;; from thinking that this predicate accepts REG and SUBREG. We don't
440 ;; use recog during reload, so pretending these codes are accepted
441 ;; pessimizes things a tad.
443 (define_special_predicate "aligned_memory_operand"
444 (ior (match_test "op = resolve_reload_operand (op), 0")
450 if (MEM_ALIGN (op) >= 32)
455 /* LEGITIMIZE_RELOAD_ADDRESS creates (plus (plus reg const_hi) const_lo)
456 sorts of constructs. Dig for the real base register. */
457 if (reload_in_progress
458 && GET_CODE (op) == PLUS
459 && GET_CODE (XEXP (op, 0)) == PLUS)
461 base = XEXP (XEXP (op, 0), 0);
462 offset = INTVAL (XEXP (op, 1));
466 if (! memory_address_p (mode, op))
468 if (GET_CODE (op) == PLUS)
471 offset = INTVAL (XEXP (op, 1));
480 if (offset % GET_MODE_SIZE (mode))
483 return (REG_P (base) && REGNO_POINTER_ALIGN (REGNO (base)) >= 32);
486 ;; Similar, but return 1 if OP is a MEM which is not alignable.
488 (define_special_predicate "unaligned_memory_operand"
489 (ior (match_test "op = resolve_reload_operand (op), 0")
495 if (MEM_ALIGN (op) >= 32)
500 /* LEGITIMIZE_RELOAD_ADDRESS creates (plus (plus reg const_hi) const_lo)
501 sorts of constructs. Dig for the real base register. */
502 if (reload_in_progress
503 && GET_CODE (op) == PLUS
504 && GET_CODE (XEXP (op, 0)) == PLUS)
506 base = XEXP (XEXP (op, 0), 0);
507 offset = INTVAL (XEXP (op, 1));
511 if (! memory_address_p (mode, op))
513 if (GET_CODE (op) == PLUS)
516 offset = INTVAL (XEXP (op, 1));
525 if (offset % GET_MODE_SIZE (mode))
528 return (REG_P (base) && REGNO_POINTER_ALIGN (REGNO (base)) < 32);
531 ;; Return 1 if OP is any memory location. During reload a pseudo matches.
532 (define_special_predicate "any_memory_operand"
533 (match_code "mem,reg,subreg")
535 if (GET_CODE (op) == SUBREG)
536 op = SUBREG_REG (op);
540 if (reload_in_progress && REG_P (op))
542 unsigned regno = REGNO (op);
543 if (HARD_REGISTER_NUM_P (regno))
546 return reg_renumber[regno] < 0;
552 ;; Return 1 is OP is a memory location that is not a reference
553 ;; (using an AND) to an unaligned location. Take into account
554 ;; what reload will do.
555 (define_special_predicate "normal_memory_operand"
556 (ior (match_test "op = resolve_reload_operand (op), 0")
557 (and (match_code "mem")
558 (match_test "GET_CODE (XEXP (op, 0)) != AND"))))
560 ;; Returns 1 if OP is not an eliminable register.
562 ;; This exists to cure a pathological failure in the s8addq (et al) patterns,
564 ;; long foo () { long t; bar(); return (long) &t * 26107; }
566 ;; which run afoul of a hack in reload to cure a (presumably) similar
567 ;; problem with lea-type instructions on other targets. But there is
568 ;; one of us and many of them, so work around the problem by selectively
569 ;; preventing combine from making the optimization.
571 (define_predicate "reg_not_elim_operand"
572 (match_operand 0 "register_operand")
574 if (GET_CODE (op) == SUBREG)
575 op = SUBREG_REG (op);
576 return op != frame_pointer_rtx && op != arg_pointer_rtx;
579 ;; Accept a register, but not a subreg of any kind. This allows us to
580 ;; avoid pathological cases in reload wrt data movement common in
581 ;; int->fp conversion. */
582 (define_predicate "reg_no_subreg_operand"
583 (and (match_code "reg")
584 (match_operand 0 "register_operand")))
586 ;; Return 1 if OP is a valid Alpha comparison operator for "cbranch"
588 (define_predicate "alpha_cbranch_operator"
589 (ior (match_operand 0 "ordered_comparison_operator")
590 (match_code "ordered,unordered")))
592 ;; Return 1 if OP is a valid Alpha comparison operator for "cmp" style
594 (define_predicate "alpha_comparison_operator"
595 (match_code "eq,le,lt,leu,ltu"))
597 ;; Similarly, but with swapped operands.
598 (define_predicate "alpha_swapped_comparison_operator"
599 (match_code "eq,ge,gt,gtu"))
601 ;; Return 1 if OP is a valid Alpha comparison operator against zero
602 ;; for "bcc" style instructions.
603 (define_predicate "alpha_zero_comparison_operator"
604 (match_code "eq,ne,le,lt,leu,ltu"))
606 ;; Return 1 if OP is a signed comparison operation.
607 (define_predicate "signed_comparison_operator"
608 (match_code "eq,ne,le,lt,ge,gt"))
610 ;; Return 1 if OP is a valid Alpha floating point comparison operator.
611 (define_predicate "alpha_fp_comparison_operator"
612 (match_code "eq,le,lt,unordered"))
614 ;; Return 1 if this is a divide or modulus operator.
615 (define_predicate "divmod_operator"
616 (match_code "div,mod,udiv,umod"))
618 ;; Return 1 if this is a float->int conversion operator.
619 (define_predicate "fix_operator"
620 (match_code "fix,unsigned_fix"))
622 ;; Recognize an addition operation that includes a constant. Used to
623 ;; convince reload to canonize (plus (plus reg c1) c2) during register
626 (define_predicate "addition_operation"
627 (and (match_code "plus")
628 (match_test "register_operand (XEXP (op, 0), mode)
629 && satisfies_constraint_K (XEXP (op, 1))")))
631 ;; For TARGET_EXPLICIT_RELOCS, we don't obfuscate a SYMBOL_REF to a
632 ;; small symbolic operand until after reload. At which point we need
633 ;; to replace (mem (symbol_ref)) with (mem (lo_sum $29 symbol_ref))
634 ;; so that sched2 has the proper dependency information. */
635 (define_predicate "some_small_symbolic_operand"
636 (match_code "set,parallel,prefetch,unspec,unspec_volatile")
638 /* Avoid search unless necessary. */
639 if (!TARGET_EXPLICIT_RELOCS || !reload_completed)
641 return for_each_rtx (&op, some_small_symbolic_operand_int, NULL);
644 ;; Accept a register, or a memory if BWX is enabled.
645 (define_predicate "reg_or_bwx_memory_operand"
646 (ior (match_operand 0 "register_operand")
647 (and (match_test "TARGET_BWX")
648 (match_operand 0 "memory_operand"))))
650 ;; Accept a memory whose address is only a register.
651 (define_predicate "mem_noofs_operand"
652 (and (match_code "mem")
653 (match_code "reg" "0")))