1 ;; Predicate definitions for Renesas / SuperH SH.
2 ;; Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
3 ;; Free Software Foundation, Inc.
5 ;; This file is part of GCC.
7 ;; GCC is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3, or (at your option)
12 ;; GCC is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3. If not see
19 ;; <http://www.gnu.org/licenses/>.
21 ;; TODO: Add a comment here.
23 (define_predicate "trapping_target_operand"
24 (match_code "if_then_else")
26 rtx cond, mem, res, tar, and_expr;
28 if (GET_MODE (op) != PDImode)
34 || (GET_CODE (res) != SIGN_EXTEND && GET_CODE (res) != TRUNCATE))
37 if (!rtx_equal_p (XEXP (mem, 0), tar)
38 || GET_MODE (tar) != Pmode)
40 if (GET_CODE (cond) == CONST)
42 cond = XEXP (cond, 0);
43 if (!satisfies_constraint_Csy (tar))
45 if (GET_CODE (tar) == CONST)
48 else if (!arith_reg_operand (tar, VOIDmode)
49 && ! satisfies_constraint_Csy (tar))
51 if (GET_CODE (cond) != EQ)
53 and_expr = XEXP (cond, 0);
54 return (GET_CODE (and_expr) == AND
55 && rtx_equal_p (XEXP (and_expr, 0), tar)
56 && CONST_INT_P (XEXP (and_expr, 1))
57 && CONST_INT_P (XEXP (cond, 1))
58 && INTVAL (XEXP (and_expr, 1)) == 3
59 && INTVAL (XEXP (cond, 1)) == 3);
62 ;; TODO: Add a comment here.
64 (define_predicate "and_operand"
65 (match_code "subreg,reg,const_int")
67 if (logical_operand (op, mode))
70 /* Check mshflo.l / mshflhi.l opportunities. */
73 && satisfies_constraint_J16 (op))
79 ;; Like arith_reg_dest, but this predicate is defined with
80 ;; define_special_predicate, not define_predicate.
82 (define_special_predicate "any_arith_reg_dest"
83 (match_code "subreg,reg")
85 return arith_reg_dest (op, mode);
88 ;; Like register_operand, but this predicate is defined with
89 ;; define_special_predicate, not define_predicate.
91 (define_special_predicate "any_register_operand"
92 (match_code "subreg,reg")
94 return register_operand (op, mode);
97 ;; Returns 1 if OP is a valid source operand for an arithmetic insn.
99 (define_predicate "arith_operand"
100 (match_code "subreg,reg,const_int,truncate")
102 if (arith_reg_operand (op, mode))
107 /* FIXME: We should be checking whether the CONST_INT fits in a
108 signed 16-bit here, but this causes reload_cse to crash when
109 attempting to transform a sequence of two 64-bit sets of the
110 same register from literal constants into a set and an add,
111 when the difference is too wide for an add. */
113 || satisfies_constraint_Css (op))
115 else if (GET_CODE (op) == TRUNCATE
116 && REG_P (XEXP (op, 0))
117 && ! system_reg_operand (XEXP (op, 0), VOIDmode)
118 && (mode == VOIDmode || mode == GET_MODE (op))
119 && (GET_MODE_SIZE (GET_MODE (op))
120 < GET_MODE_SIZE (GET_MODE (XEXP (op, 0))))
121 && (! FP_REGISTER_P (REGNO (XEXP (op, 0)))
122 || GET_MODE_SIZE (GET_MODE (op)) == 4))
123 return register_operand (XEXP (op, 0), VOIDmode);
127 else if (satisfies_constraint_I08 (op))
133 ;; Like above, but for DImode destinations: forbid paradoxical DImode
134 ;; subregs, because this would lead to missing sign extensions when
135 ;; truncating from DImode to SImode.
137 (define_predicate "arith_reg_dest"
138 (match_code "subreg,reg")
140 if (mode == DImode && GET_CODE (op) == SUBREG
141 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) < 8
144 return arith_reg_operand (op, mode);
147 ;; Returns 1 if OP is a normal arithmetic register.
149 (define_predicate "arith_reg_operand"
150 (match_code "subreg,reg,sign_extend")
152 if (register_operand (op, mode))
158 else if (GET_CODE (op) == SUBREG && REG_P (SUBREG_REG (op)))
159 regno = REGNO (SUBREG_REG (op));
163 return (regno != T_REG && regno != PR_REG
164 && ! TARGET_REGISTER_P (regno)
165 && (regno != FPUL_REG || TARGET_SH4)
166 && regno != MACH_REG && regno != MACL_REG);
168 /* Allow a no-op sign extension - compare LOAD_EXTEND_OP.
169 We allow SImode here, as not using an FP register is just a matter of
170 proper register allocation. */
172 && GET_MODE (op) == DImode && GET_CODE (op) == SIGN_EXTEND
173 && GET_MODE (XEXP (op, 0)) == SImode
174 && GET_CODE (XEXP (op, 0)) != SUBREG)
175 return register_operand (XEXP (op, 0), VOIDmode);
176 #if 0 /* Can't do this because of PROMOTE_MODE for unsigned vars. */
177 if (GET_MODE (op) == SImode && GET_CODE (op) == SIGN_EXTEND
178 && GET_MODE (XEXP (op, 0)) == HImode
179 && REG_P (XEXP (op, 0))
180 && REGNO (XEXP (op, 0)) <= LAST_GENERAL_REG)
181 return register_operand (XEXP (op, 0), VOIDmode);
183 if (GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_INT
184 && GET_CODE (op) == SUBREG
185 && GET_MODE (SUBREG_REG (op)) == DImode
186 && GET_CODE (SUBREG_REG (op)) == SIGN_EXTEND
187 && GET_MODE (XEXP (SUBREG_REG (op), 0)) == SImode
188 && GET_CODE (XEXP (SUBREG_REG (op), 0)) != SUBREG)
189 return register_operand (XEXP (SUBREG_REG (op), 0), VOIDmode);
193 ;; Returns 1 if OP is a valid source operand for a compare insn.
195 (define_predicate "arith_reg_or_0_operand"
196 (match_code "subreg,reg,const_int,const_vector")
198 if (arith_reg_operand (op, mode))
201 if (satisfies_constraint_Z (op))
207 ;; TODO: Add a comment here.
209 (define_predicate "binary_float_operator"
210 (and (match_code "plus,minus,mult,div")
211 (match_test "GET_MODE (op) == mode")))
213 ;; TODO: Add a comment here.
215 (define_predicate "binary_logical_operator"
216 (and (match_code "and,ior,xor")
217 (match_test "GET_MODE (op) == mode")))
219 ;; Return 1 of OP is an address suitable for a cache manipulation operation.
220 ;; MODE has the meaning as in address_operand.
222 (define_special_predicate "cache_address_operand"
223 (match_code "plus,reg")
225 if (GET_CODE (op) == PLUS)
227 if (!REG_P (XEXP (op, 0)))
229 if (!CONST_INT_P (XEXP (op, 1))
230 || (INTVAL (XEXP (op, 1)) & 31))
233 else if (!REG_P (op))
235 return address_operand (op, mode);
238 ;; Return 1 if OP is a valid source operand for shmedia cmpgt / cmpgtu.
240 (define_predicate "cmp_operand"
241 (match_code "subreg,reg,const_int")
243 if (satisfies_constraint_N (op))
246 && mode != DImode && GET_CODE (op) == SUBREG
247 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) > 4)
249 return arith_reg_operand (op, mode);
252 ;; TODO: Add a comment here.
254 (define_predicate "cmpsi_operand"
255 (match_code "subreg,reg,const_int")
257 if (REG_P (op) && REGNO (op) == T_REG
258 && GET_MODE (op) == SImode
261 return arith_operand (op, mode);
264 ;; TODO: Add a comment here.
266 (define_predicate "commutative_float_operator"
267 (and (match_code "plus,mult")
268 (match_test "GET_MODE (op) == mode")))
270 ;; TODO: Add a comment here.
272 (define_predicate "equality_comparison_operator"
273 (match_code "eq,ne"))
275 ;; TODO: Add a comment here.
277 (define_predicate "extend_reg_operand"
278 (match_code "subreg,reg,truncate")
280 return (GET_CODE (op) == TRUNCATE
282 : arith_reg_operand) (op, mode);
285 ;; TODO: Add a comment here.
287 (define_predicate "extend_reg_or_0_operand"
288 (match_code "subreg,reg,truncate,const_int")
290 return (GET_CODE (op) == TRUNCATE
292 : arith_reg_or_0_operand) (op, mode);
295 ;; Like arith_reg_operand, but this predicate does not accept SIGN_EXTEND.
297 (define_predicate "ext_dest_operand"
298 (match_code "subreg,reg")
300 return arith_reg_operand (op, mode);
303 ;; TODO: Add a comment here.
305 (define_predicate "fp_arith_reg_dest"
306 (match_code "subreg,reg")
308 if (mode == DImode && GET_CODE (op) == SUBREG
309 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) < 8)
311 return fp_arith_reg_operand (op, mode);
314 ;; TODO: Add a comment here.
316 (define_predicate "fp_arith_reg_operand"
317 (match_code "subreg,reg")
319 if (register_operand (op, mode))
325 else if (GET_CODE (op) == SUBREG && REG_P (SUBREG_REG (op)))
326 regno = REGNO (SUBREG_REG (op));
330 return (regno >= FIRST_PSEUDO_REGISTER
331 || FP_REGISTER_P (regno));
336 ;; TODO: Add a comment here.
338 (define_predicate "fpscr_operand"
342 && (REGNO (op) == FPSCR_REG
343 || (REGNO (op) >= FIRST_PSEUDO_REGISTER
344 && !(reload_in_progress || reload_completed)))
345 && GET_MODE (op) == PSImode);
348 ;; TODO: Add a comment here.
350 (define_predicate "fpul_operand"
354 return fp_arith_reg_operand (op, mode);
357 && (REGNO (op) == FPUL_REG || REGNO (op) >= FIRST_PSEUDO_REGISTER)
358 && GET_MODE (op) == mode);
361 ;; TODO: Add a comment here.
363 (define_predicate "general_extend_operand"
364 (match_code "subreg,reg,mem,truncate")
366 return (GET_CODE (op) == TRUNCATE
368 : nonimmediate_operand) (op, mode);
371 ;; Returns 1 if OP can be source of a simple move operation. Same as
372 ;; general_operand, but a LABEL_REF is valid, PRE_DEC is invalid as
373 ;; are subregs of system registers.
375 (define_predicate "general_movsrc_operand"
376 (match_code "subreg,reg,const_int,const_double,mem,symbol_ref,label_ref,const,const_vector")
380 rtx inside = XEXP (op, 0);
381 if (GET_CODE (inside) == CONST)
382 inside = XEXP (inside, 0);
384 if (GET_CODE (inside) == LABEL_REF)
387 if (GET_CODE (inside) == PLUS
388 && GET_CODE (XEXP (inside, 0)) == LABEL_REF
389 && CONST_INT_P (XEXP (inside, 1)))
392 /* Only post inc allowed. */
393 if (GET_CODE (inside) == PRE_DEC)
398 && (GET_CODE (op) == PARALLEL || GET_CODE (op) == CONST_VECTOR)
399 && sh_rep_vec (op, mode))
401 if (TARGET_SHMEDIA && 1
402 && GET_CODE (op) == SUBREG && GET_MODE (op) == mode
403 && SUBREG_REG (op) == const0_rtx && subreg_lowpart_p (op))
404 /* FIXME */ abort (); /* return 1; */
405 return general_operand (op, mode);
408 ;; Returns 1 if OP can be a destination of a move. Same as
409 ;; general_operand, but no preinc allowed.
411 (define_predicate "general_movdst_operand"
412 (match_code "subreg,reg,mem")
414 /* Only pre dec allowed. */
415 if (MEM_P (op) && GET_CODE (XEXP (op, 0)) == POST_INC)
417 if (mode == DImode && TARGET_SHMEDIA && GET_CODE (op) == SUBREG
418 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) < 8
419 && ! (high_life_started || reload_completed))
422 return general_operand (op, mode);
426 ;; Returns 1 if OP is a POST_INC on stack pointer register.
428 (define_predicate "sh_no_delay_pop_operand"
432 inside = XEXP (op, 0);
434 if (GET_CODE (op) == MEM && GET_MODE (op) == SImode
435 && GET_CODE (inside) == POST_INC
436 && GET_CODE (XEXP (inside, 0)) == REG
437 && REGNO (XEXP (inside, 0)) == SP_REG)
444 ;; Returns 1 if OP is a MEM that can be source of a simple move operation.
446 (define_predicate "unaligned_load_operand"
451 if (!MEM_P (op) || GET_MODE (op) != mode)
454 inside = XEXP (op, 0);
456 if (GET_CODE (inside) == POST_INC)
457 inside = XEXP (inside, 0);
465 ;; TODO: Add a comment here.
467 (define_predicate "greater_comparison_operator"
468 (match_code "gt,ge,gtu,geu"))
470 ;; TODO: Add a comment here.
472 (define_predicate "inqhi_operand"
473 (match_code "truncate")
475 if (GET_CODE (op) != TRUNCATE || mode != GET_MODE (op))
478 /* Can't use true_regnum here because copy_cost wants to know about
479 SECONDARY_INPUT_RELOAD_CLASS. */
480 return REG_P (op) && FP_REGISTER_P (REGNO (op));
483 ;; TODO: Add a comment here.
485 (define_special_predicate "int_gpr_dest"
486 (match_code "subreg,reg")
488 enum machine_mode op_mode = GET_MODE (op);
490 if (GET_MODE_CLASS (op_mode) != MODE_INT
491 || GET_MODE_SIZE (op_mode) >= UNITS_PER_WORD)
493 if (! reload_completed)
495 return true_regnum (op) <= LAST_GENERAL_REG;
498 ;; TODO: Add a comment here.
500 (define_predicate "less_comparison_operator"
501 (match_code "lt,le,ltu,leu"))
503 ;; Returns 1 if OP is a valid source operand for a logical operation.
505 (define_predicate "logical_operand"
506 (match_code "subreg,reg,const_int")
509 && mode != DImode && GET_CODE (op) == SUBREG
510 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) > 4)
513 if (arith_reg_operand (op, mode))
518 if (satisfies_constraint_I10 (op))
523 else if (satisfies_constraint_K08 (op))
529 ;; TODO: Add a comment here.
531 (define_predicate "logical_operator"
532 (match_code "and,ior,xor"))
534 ;; Like arith_reg_operand, but for register source operands of narrow
535 ;; logical SHMEDIA operations: forbid subregs of DImode / TImode regs.
537 (define_predicate "logical_reg_operand"
538 (match_code "subreg,reg")
541 && GET_CODE (op) == SUBREG
542 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) > 4
545 return arith_reg_operand (op, mode);
548 ;; TODO: Add a comment here.
550 (define_predicate "mextr_bit_offset"
551 (match_code "const_int")
555 if (!CONST_INT_P (op))
558 return i >= 1 * 8 && i <= 7 * 8 && (i & 7) == 0;
561 ;; TODO: Add a comment here.
563 (define_predicate "minuend_operand"
564 (match_code "subreg,reg,truncate,const_int")
566 return op == constm1_rtx || extend_reg_or_0_operand (op, mode);
569 ;; TODO: Add a comment here.
571 (define_predicate "noncommutative_float_operator"
572 (and (match_code "minus,div")
573 (match_test "GET_MODE (op) == mode")))
575 ;; UNORDERED is only supported on SHMEDIA.
577 (define_predicate "sh_float_comparison_operator"
578 (ior (match_operand 0 "ordered_comparison_operator")
579 (and (match_test "TARGET_SHMEDIA")
580 (match_code "unordered"))))
582 (define_predicate "shmedia_cbranch_comparison_operator"
583 (ior (match_operand 0 "equality_comparison_operator")
584 (match_operand 0 "greater_comparison_operator")))
586 ;; TODO: Add a comment here.
588 (define_predicate "sh_const_vec"
589 (match_code "const_vector")
593 if (GET_CODE (op) != CONST_VECTOR
594 || (GET_MODE (op) != mode && mode != VOIDmode))
596 i = XVECLEN (op, 0) - 1;
598 if (!CONST_INT_P (XVECEXP (op, 0, i)))
603 ;; Determine if OP is a constant vector matching MODE with only one
604 ;; element that is not a sign extension. Two byte-sized elements
607 (define_predicate "sh_1el_vec"
608 (match_code "const_vector")
611 int i, last, least, sign_ix;
614 if (GET_CODE (op) != CONST_VECTOR
615 || (GET_MODE (op) != mode && mode != VOIDmode))
617 /* Determine numbers of last and of least significant elements. */
618 last = XVECLEN (op, 0) - 1;
619 least = TARGET_LITTLE_ENDIAN ? 0 : last;
620 if (!CONST_INT_P (XVECEXP (op, 0, least)))
623 if (GET_MODE_UNIT_SIZE (mode) == 1)
624 sign_ix = TARGET_LITTLE_ENDIAN ? 1 : last - 1;
625 if (!CONST_INT_P (XVECEXP (op, 0, sign_ix)))
627 unit_size = GET_MODE_UNIT_SIZE (GET_MODE (op));
628 sign = (INTVAL (XVECEXP (op, 0, sign_ix)) >> (unit_size * BITS_PER_UNIT - 1)
629 ? constm1_rtx : const0_rtx);
630 i = XVECLEN (op, 0) - 1;
632 if (i != least && i != sign_ix && XVECEXP (op, 0, i) != sign)
638 ;; Like register_operand, but take into account that SHMEDIA can use
639 ;; the constant zero like a general register.
641 (define_predicate "sh_register_operand"
642 (match_code "reg,subreg,const_int,const_double")
644 if (op == CONST0_RTX (mode) && TARGET_SHMEDIA)
646 return register_operand (op, mode);
649 ;; TODO: Add a comment here.
651 (define_predicate "sh_rep_vec"
652 (match_code "const_vector,parallel")
657 if ((GET_CODE (op) != CONST_VECTOR && GET_CODE (op) != PARALLEL)
658 || (GET_MODE (op) != mode && mode != VOIDmode))
660 i = XVECLEN (op, 0) - 2;
661 x = XVECEXP (op, 0, i + 1);
662 if (GET_MODE_UNIT_SIZE (mode) == 1)
664 y = XVECEXP (op, 0, i);
665 for (i -= 2; i >= 0; i -= 2)
666 if (! rtx_equal_p (XVECEXP (op, 0, i + 1), x)
667 || ! rtx_equal_p (XVECEXP (op, 0, i), y))
672 if (XVECEXP (op, 0, i) != x)
677 ;; TODO: Add a comment here.
679 (define_predicate "shift_count_operand"
680 (match_code "const_int,const_double,const,symbol_ref,label_ref,subreg,reg,zero_extend,sign_extend")
682 return (CONSTANT_P (op)
684 ? (unsigned) INTVAL (op) < GET_MODE_BITSIZE (mode)
685 : nonmemory_operand (op, mode))
686 : shift_count_reg_operand (op, mode));
689 ;; TODO: Add a comment here.
691 (define_predicate "shift_count_reg_operand"
692 (match_code "subreg,reg,zero_extend,sign_extend")
694 if ((GET_CODE (op) == ZERO_EXTEND || GET_CODE (op) == SIGN_EXTEND
695 || (GET_CODE (op) == SUBREG && SUBREG_BYTE (op) == 0))
696 && (mode == VOIDmode || mode == GET_MODE (op))
697 && GET_MODE_BITSIZE (GET_MODE (XEXP (op, 0))) >= 6
698 && GET_MODE_CLASS (GET_MODE (XEXP (op, 0))) == MODE_INT)
703 while ((GET_CODE (op) == ZERO_EXTEND || GET_CODE (op) == SIGN_EXTEND
704 || GET_CODE (op) == TRUNCATE)
705 && GET_MODE_BITSIZE (GET_MODE (XEXP (op, 0))) >= 6
706 && GET_MODE_CLASS (GET_MODE (XEXP (op, 0))) == MODE_INT);
709 return arith_reg_operand (op, mode);
712 ;; TODO: Add a comment here.
714 (define_predicate "shift_operator"
715 (match_code "ashift,ashiftrt,lshiftrt"))
717 ;; TODO: Add a comment here.
719 (define_predicate "symbol_ref_operand"
720 (match_code "symbol_ref"))
722 ;; Same as target_reg_operand, except that label_refs and symbol_refs
723 ;; are accepted before reload.
725 (define_special_predicate "target_operand"
726 (match_code "subreg,reg,label_ref,symbol_ref,const,unspec")
728 if (mode != VOIDmode && mode != Pmode)
731 if ((GET_MODE (op) == Pmode || GET_MODE (op) == VOIDmode)
732 && satisfies_constraint_Csy (op))
733 return ! reload_completed;
735 return target_reg_operand (op, mode);
738 ;; Accept pseudos and branch target registers.
740 (define_special_predicate "target_reg_operand"
741 (match_code "subreg,reg")
744 ? GET_MODE (op) != Pmode && GET_MODE (op) != PDImode
745 : mode != GET_MODE (op))
748 if (GET_CODE (op) == SUBREG)
754 /* We must protect ourselves from matching pseudos that are virtual
755 register, because they will eventually be replaced with hardware
756 registers that aren't branch-target registers. */
757 if (REGNO (op) > LAST_VIRTUAL_REGISTER
758 || TARGET_REGISTER_P (REGNO (op)))
764 ;; TODO: Add a comment here.
766 (define_special_predicate "trunc_hi_operand"
767 (match_code "subreg,reg,truncate")
769 enum machine_mode op_mode = GET_MODE (op);
771 if (op_mode != SImode && op_mode != DImode
772 && op_mode != V4HImode && op_mode != V2SImode)
774 return extend_reg_operand (op, mode);
777 ;; Return 1 of OP is an address suitable for an unaligned access instruction.
779 (define_special_predicate "ua_address_operand"
780 (match_code "subreg,reg,plus")
782 if (GET_CODE (op) == PLUS
783 && (! satisfies_constraint_I06 (XEXP (op, 1))))
785 return address_operand (op, QImode);
788 ;; TODO: Add a comment here.
790 (define_predicate "ua_offset"
791 (match_code "const_int")
793 return satisfies_constraint_I06 (op);
796 ;; TODO: Add a comment here.
798 (define_predicate "unary_float_operator"
799 (and (match_code "abs,neg,sqrt")
800 (match_test "GET_MODE (op) == mode")))
802 ;; Return 1 if OP is a valid source operand for xor.
804 (define_predicate "xor_operand"
805 (match_code "subreg,reg,const_int")
807 if (CONST_INT_P (op))
808 return (TARGET_SHMEDIA
809 ? (satisfies_constraint_I06 (op)
810 || (!can_create_pseudo_p () && INTVAL (op) == 0xff))
811 : satisfies_constraint_K08 (op));
813 && mode != DImode && GET_CODE (op) == SUBREG
814 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) > 4)
816 return arith_reg_operand (op, mode);
819 (define_predicate "bitwise_memory_operand"
824 if (REG_P (XEXP (op, 0)))
827 if (GET_CODE (XEXP (op, 0)) == PLUS
828 && REG_P (XEXP (XEXP (op, 0), 0))
829 && satisfies_constraint_K12 (XEXP (XEXP (op, 0), 1)))