1 ;; Predicate definitions for Renesas / SuperH SH.
2 ;; Copyright (C) 2005-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 ;; TODO: Add a comment here.
21 (define_predicate "trapping_target_operand"
22 (match_code "if_then_else")
24 rtx cond, mem, res, tar, and_expr;
26 if (GET_MODE (op) != PDImode)
32 || (GET_CODE (res) != SIGN_EXTEND && GET_CODE (res) != TRUNCATE))
35 if (!rtx_equal_p (XEXP (mem, 0), tar)
36 || GET_MODE (tar) != Pmode)
38 if (GET_CODE (cond) == CONST)
40 cond = XEXP (cond, 0);
41 if (!satisfies_constraint_Csy (tar))
43 if (GET_CODE (tar) == CONST)
46 else if (!arith_reg_operand (tar, VOIDmode)
47 && ! satisfies_constraint_Csy (tar))
49 if (GET_CODE (cond) != EQ)
51 and_expr = XEXP (cond, 0);
52 return (GET_CODE (and_expr) == AND
53 && rtx_equal_p (XEXP (and_expr, 0), tar)
54 && CONST_INT_P (XEXP (and_expr, 1))
55 && CONST_INT_P (XEXP (cond, 1))
56 && INTVAL (XEXP (and_expr, 1)) == 3
57 && INTVAL (XEXP (cond, 1)) == 3);
60 ;; A logical operand that can be used in an shmedia and insn.
61 (define_predicate "and_operand"
62 (match_code "subreg,reg,const_int")
64 if (logical_operand (op, mode))
67 /* Check mshflo.l / mshflhi.l opportunities. */
70 && satisfies_constraint_J16 (op))
76 ;; Like arith_reg_dest, but this predicate is defined with
77 ;; define_special_predicate, not define_predicate.
78 (define_special_predicate "any_arith_reg_dest"
79 (match_code "subreg,reg")
81 return arith_reg_dest (op, mode);
84 ;; Like register_operand, but this predicate is defined with
85 ;; define_special_predicate, not define_predicate.
86 (define_special_predicate "any_register_operand"
87 (match_code "subreg,reg")
89 return register_operand (op, mode);
92 ;; Returns 1 if OP is a valid source operand for an arithmetic insn.
93 (define_predicate "arith_operand"
94 (match_code "subreg,reg,const_int,truncate")
96 if (arith_reg_operand (op, mode))
101 /* FIXME: We should be checking whether the CONST_INT fits in a
102 signed 16-bit here, but this causes reload_cse to crash when
103 attempting to transform a sequence of two 64-bit sets of the
104 same register from literal constants into a set and an add,
105 when the difference is too wide for an add. */
107 || satisfies_constraint_Css (op))
109 else if (GET_CODE (op) == TRUNCATE
110 && REG_P (XEXP (op, 0))
111 && ! system_reg_operand (XEXP (op, 0), VOIDmode)
112 && (mode == VOIDmode || mode == GET_MODE (op))
113 && (GET_MODE_SIZE (GET_MODE (op))
114 < GET_MODE_SIZE (GET_MODE (XEXP (op, 0))))
115 && (! FP_REGISTER_P (REGNO (XEXP (op, 0)))
116 || GET_MODE_SIZE (GET_MODE (op)) == 4))
117 return register_operand (XEXP (op, 0), VOIDmode);
121 else if (satisfies_constraint_I08 (op))
127 ;; Like above, but for DImode destinations: forbid paradoxical DImode
128 ;; subregs, because this would lead to missing sign extensions when
129 ;; truncating from DImode to SImode.
130 (define_predicate "arith_reg_dest"
131 (match_code "subreg,reg")
133 if (mode == DImode && GET_CODE (op) == SUBREG
134 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) < 8
137 return arith_reg_operand (op, mode);
140 ;; Returns 1 if OP is a normal arithmetic register.
141 (define_predicate "arith_reg_operand"
142 (match_code "subreg,reg,sign_extend")
144 if (register_operand (op, mode))
150 else if (GET_CODE (op) == SUBREG && REG_P (SUBREG_REG (op)))
151 regno = REGNO (SUBREG_REG (op));
155 return (regno != T_REG && regno != PR_REG
156 && ! TARGET_REGISTER_P (regno)
158 && regno != MACH_REG && regno != MACL_REG);
160 /* Allow a no-op sign extension - compare LOAD_EXTEND_OP.
161 We allow SImode here, as not using an FP register is just a matter of
162 proper register allocation. */
164 && GET_MODE (op) == DImode && GET_CODE (op) == SIGN_EXTEND
165 && GET_MODE (XEXP (op, 0)) == SImode
166 && GET_CODE (XEXP (op, 0)) != SUBREG)
167 return register_operand (XEXP (op, 0), VOIDmode);
168 #if 0 /* Can't do this because of PROMOTE_MODE for unsigned vars. */
169 if (GET_MODE (op) == SImode && GET_CODE (op) == SIGN_EXTEND
170 && GET_MODE (XEXP (op, 0)) == HImode
171 && REG_P (XEXP (op, 0))
172 && REGNO (XEXP (op, 0)) <= LAST_GENERAL_REG)
173 return register_operand (XEXP (op, 0), VOIDmode);
175 if (GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_INT
176 && GET_CODE (op) == SUBREG
177 && GET_MODE (SUBREG_REG (op)) == DImode
178 && GET_CODE (SUBREG_REG (op)) == SIGN_EXTEND
179 && GET_MODE (XEXP (SUBREG_REG (op), 0)) == SImode
180 && GET_CODE (XEXP (SUBREG_REG (op), 0)) != SUBREG)
181 return register_operand (XEXP (SUBREG_REG (op), 0), VOIDmode);
185 ;; Returns 1 if OP is a valid source operand for a compare insn.
186 (define_predicate "arith_reg_or_0_operand"
187 (match_code "subreg,reg,const_int,const_vector")
189 if (arith_reg_operand (op, mode))
192 if (satisfies_constraint_Z (op))
198 ;; Returns true if OP is either a register or constant 0 or constant 1.
199 (define_predicate "arith_reg_or_0_or_1_operand"
200 (match_code "subreg,reg,const_int,const_vector")
202 return arith_reg_or_0_operand (op, mode) || satisfies_constraint_M (op);
205 ;; Returns true if OP is a suitable constant for the minimum value of a
206 ;; clips.b or clips.w insn.
207 (define_predicate "clips_min_const_int"
208 (and (match_code "const_int")
209 (ior (match_test "INTVAL (op) == -128")
210 (match_test "INTVAL (op) == -32768"))))
212 ;; Returns true if OP is a suitable constant for the maximum value of a
213 ;; clips.b or clips.w insn.
214 (define_predicate "clips_max_const_int"
215 (and (match_code "const_int")
216 (ior (match_test "INTVAL (op) == 127")
217 (match_test "INTVAL (op) == 32767"))))
219 ;; Returns true if OP is a suitable constant for the maximum value of a
220 ;; clipu.b or clipu.w insn.
221 (define_predicate "clipu_max_const_int"
222 (and (match_code "const_int")
223 (ior (match_test "INTVAL (op) == 255")
224 (match_test "INTVAL (op) == 65535"))))
226 ;; Returns 1 if OP is a floating point operator with two operands.
227 (define_predicate "binary_float_operator"
228 (and (match_code "plus,minus,mult,div")
229 (match_test "GET_MODE (op) == mode")))
231 ;; Returns 1 if OP is a logical operator with two operands.
232 (define_predicate "binary_logical_operator"
233 (and (match_code "and,ior,xor")
234 (match_test "GET_MODE (op) == mode")))
236 ;; Return 1 if OP is an address suitable for a cache manipulation operation.
237 ;; MODE has the meaning as in address_operand.
238 (define_special_predicate "cache_address_operand"
239 (match_code "plus,reg")
241 if (GET_CODE (op) == PLUS)
243 if (!REG_P (XEXP (op, 0)))
245 if (!CONST_INT_P (XEXP (op, 1))
246 || (INTVAL (XEXP (op, 1)) & 31))
249 else if (!REG_P (op))
251 return address_operand (op, mode);
254 ;; Returns 1 if OP is a valid source operand for shmedia cmpgt / cmpgtu.
255 (define_predicate "cmp_operand"
256 (match_code "subreg,reg,const_int")
258 if (satisfies_constraint_N (op))
261 && mode != DImode && GET_CODE (op) == SUBREG
262 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) > 4)
264 return arith_reg_operand (op, mode);
267 ;; Returns true if OP is an operand that can be used as the first operand in
268 ;; the cstoresi4 expander pattern.
269 (define_predicate "cmpsi_operand"
270 (match_code "subreg,reg,const_int")
272 if (REG_P (op) && REGNO (op) == T_REG
273 && GET_MODE (op) == SImode
276 return arith_operand (op, mode);
279 ;; Returns true if OP is a comutative float operator.
280 ;; This predicate is currently unused.
281 ;;(define_predicate "commutative_float_operator"
282 ;; (and (match_code "plus,mult")
283 ;; (match_test "GET_MODE (op) == mode")))
285 ;; Returns true if OP is a equal or not equal operator.
286 (define_predicate "equality_comparison_operator"
287 (match_code "eq,ne"))
289 ;; Returns true if OP is an arithmetic operand that is zero extended during
291 (define_predicate "extend_reg_operand"
292 (match_code "subreg,reg,truncate")
294 return (GET_CODE (op) == TRUNCATE
296 : arith_reg_operand) (op, mode);
299 ;; Like extend_reg_operand, but also allow a constant 0.
300 (define_predicate "extend_reg_or_0_operand"
301 (match_code "subreg,reg,truncate,const_int")
303 return (GET_CODE (op) == TRUNCATE
305 : arith_reg_or_0_operand) (op, mode);
308 ;; Like arith_reg_operand, but this predicate does not accept SIGN_EXTEND.
309 (define_predicate "ext_dest_operand"
310 (match_code "subreg,reg")
312 return arith_reg_operand (op, mode);
315 ;; Returns true if OP can be used as a destination register for shmedia floating
316 ;; point to integer conversions.
317 (define_predicate "fp_arith_reg_dest"
318 (match_code "subreg,reg")
320 if (mode == DImode && GET_CODE (op) == SUBREG
321 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) < 8)
323 return fp_arith_reg_operand (op, mode);
326 ;; Returns true if OP is a floating point register that can be used in floating
327 ;; point arithmetic operations.
328 (define_predicate "fp_arith_reg_operand"
329 (match_code "subreg,reg")
331 if (register_operand (op, mode))
337 else if (GET_CODE (op) == SUBREG && REG_P (SUBREG_REG (op)))
338 regno = REGNO (SUBREG_REG (op));
342 return (regno >= FIRST_PSEUDO_REGISTER
343 || FP_REGISTER_P (regno));
348 ;; Returns true if OP is the FPSCR.
349 (define_predicate "fpscr_operand"
353 && (REGNO (op) == FPSCR_REG
354 || (REGNO (op) >= FIRST_PSEUDO_REGISTER
355 && !(reload_in_progress || reload_completed)))
356 && GET_MODE (op) == PSImode);
359 ;; Returns true if OP is an operand that is either the fpul hard reg or
360 ;; a pseudo. This prevents combine from propagating function arguments
361 ;; in hard regs into insns that need the operand in fpul. If it's a pseudo
362 ;; reload can fix it up.
363 (define_predicate "fpul_operand"
367 return fp_arith_reg_operand (op, mode);
370 && (REGNO (op) == FPUL_REG || REGNO (op) >= FIRST_PSEUDO_REGISTER)
371 && GET_MODE (op) == mode);
374 ;; Returns true if OP is a valid fpul input operand for the fsca insn.
375 ;; The value in fpul is a fixed-point value and its scaling is described
376 ;; in the fsca insn by a mult:SF. To allow pre-scaled fixed-point inputs
377 ;; in fpul we have to permit things like
379 ;; (fix:SF (float:SF (reg:SI)))
380 (define_predicate "fpul_fsca_operand"
381 (match_code "fix,reg")
383 if (fpul_operand (op, SImode))
385 if (GET_CODE (op) == FIX && GET_MODE (op) == SImode
386 && GET_CODE (XEXP (op, 0)) == FLOAT && GET_MODE (XEXP (op, 0)) == SFmode)
387 return fpul_fsca_operand (XEXP (XEXP (op, 0), 0),
388 GET_MODE (XEXP (XEXP (op, 0), 0)));
392 ;; Returns true if OP is a valid constant scale factor for the fsca insn.
393 (define_predicate "fsca_scale_factor"
394 (and (match_code "const_double")
395 (match_test "op == sh_fsca_int2sf ()")))
397 ;; Returns true if OP is an operand that is zero extended during an operation.
398 (define_predicate "general_extend_operand"
399 (match_code "subreg,reg,mem,truncate")
401 if (GET_CODE (op) == TRUNCATE)
402 return arith_operand (op, mode);
404 if (MEM_P (op) || (GET_CODE (op) == SUBREG && MEM_P (SUBREG_REG (op))))
405 return general_movsrc_operand (op, mode);
407 return nonimmediate_operand (op, mode);
410 ;; Returns 1 if OP is a simple register address.
411 (define_predicate "simple_mem_operand"
412 (and (match_code "mem")
413 (match_test "arith_reg_operand (XEXP (op, 0), SImode)")))
415 ;; Returns 1 if OP is a valid displacement address.
416 (define_predicate "displacement_mem_operand"
417 (and (match_code "mem")
418 (match_test "GET_CODE (XEXP (op, 0)) == PLUS")
419 (match_test "arith_reg_operand (XEXP (XEXP (op, 0), 0), SImode)")
420 (match_test "sh_legitimate_index_p (GET_MODE (op),
421 XEXP (XEXP (op, 0), 1),
422 TARGET_SH2A, true)")))
424 ;; Returns true if OP is a displacement address that can fit into a
425 ;; 16 bit (non-SH2A) memory load / store insn.
426 (define_predicate "short_displacement_mem_operand"
427 (match_test "sh_disp_addr_displacement (op)
428 <= sh_max_mov_insn_displacement (GET_MODE (op), false)"))
430 ;; Returns 1 if the operand can be used in an SH2A movu.{b|w} insn.
431 (define_predicate "zero_extend_movu_operand"
432 (and (match_operand 0 "displacement_mem_operand")
433 (match_test "GET_MODE (op) == QImode || GET_MODE (op) == HImode")))
435 ;; Returns 1 if the operand can be used in a zero_extend.
436 (define_predicate "zero_extend_operand"
437 (ior (and (match_test "TARGET_SHMEDIA")
438 (match_operand 0 "general_extend_operand"))
439 (and (match_test "! TARGET_SHMEDIA")
440 (match_operand 0 "arith_reg_operand"))
441 (and (match_test "TARGET_SH2A")
442 (match_operand 0 "zero_extend_movu_operand"))))
444 ;; Returns 1 if OP can be source of a simple move operation. Same as
445 ;; general_operand, but a LABEL_REF is valid, PRE_DEC is invalid as
446 ;; are subregs of system registers.
447 (define_predicate "general_movsrc_operand"
448 (match_code "subreg,reg,const_int,const_double,mem,symbol_ref,label_ref,
451 if (t_reg_operand (op, mode))
454 /* Disallow PC relative QImode loads, since these is no insn to do that
455 and an imm8 load should be used instead. */
456 if (IS_PC_RELATIVE_LOAD_ADDR_P (op) && GET_MODE (op) == QImode)
461 rtx inside = XEXP (op, 0);
463 /* Disallow mems with GBR address here. They have to go through
464 separate special patterns. */
465 if ((REG_P (inside) && REGNO (inside) == GBR_REG)
466 || (GET_CODE (inside) == PLUS && REG_P (XEXP (inside, 0))
467 && REGNO (XEXP (inside, 0)) == GBR_REG))
470 if (GET_CODE (inside) == CONST)
471 inside = XEXP (inside, 0);
473 if (GET_CODE (inside) == LABEL_REF)
476 if (GET_CODE (inside) == PLUS
477 && GET_CODE (XEXP (inside, 0)) == LABEL_REF
478 && CONST_INT_P (XEXP (inside, 1)))
481 /* Only post inc allowed. */
482 if (GET_CODE (inside) == PRE_DEC)
486 if (mode == GET_MODE (op)
487 && (MEM_P (op) || (GET_CODE (op) == SUBREG && MEM_P (SUBREG_REG (op)))))
489 rtx mem_rtx = MEM_P (op) ? op : SUBREG_REG (op);
490 rtx x = XEXP (mem_rtx, 0);
492 if ((mode == QImode || mode == HImode)
493 && GET_CODE (x) == PLUS
494 && REG_P (XEXP (x, 0))
495 && CONST_INT_P (XEXP (x, 1)))
496 return sh_legitimate_index_p (mode, XEXP (x, 1), TARGET_SH2A, false);
498 /* Allow reg+reg addressing here without validating the register
499 numbers. Usually one of the regs must be R0 or a pseudo reg.
500 In some cases it can happen that arguments from hard regs are
501 propagated directly into address expressions. In this cases reload
502 will have to fix it up later. However, allow this only for native
503 1, 2 or 4 byte addresses. */
504 if (can_create_pseudo_p () && GET_CODE (x) == PLUS
505 && GET_MODE_SIZE (mode) <= 4
506 && REG_P (XEXP (x, 0)) && REG_P (XEXP (x, 1)))
509 /* 'general_operand' does not allow volatile mems during RTL expansion to
510 avoid matching arithmetic that operates on mems, it seems.
511 On SH this leads to redundant sign extensions for QImode or HImode
512 loads. Thus we mimic the behavior but allow volatile mems. */
513 if (memory_address_addr_space_p (GET_MODE (mem_rtx), x,
514 MEM_ADDR_SPACE (mem_rtx)))
519 && (GET_CODE (op) == PARALLEL || GET_CODE (op) == CONST_VECTOR)
520 && sh_rep_vec (op, mode))
522 if (TARGET_SHMEDIA && 1
523 && GET_CODE (op) == SUBREG && GET_MODE (op) == mode
524 && SUBREG_REG (op) == const0_rtx && subreg_lowpart_p (op))
525 /* FIXME */ abort (); /* return 1; */
527 return general_operand (op, mode);
530 ;; Returns 1 if OP is a MEM that does not use displacement addressing.
531 (define_predicate "movsrc_no_disp_mem_operand"
534 return general_movsrc_operand (op, mode) && satisfies_constraint_Snd (op);
537 ;; Returns 1 if OP can be a destination of a move. Same as
538 ;; general_operand, but no preinc allowed.
539 (define_predicate "general_movdst_operand"
540 (match_code "subreg,reg,mem")
542 if (t_reg_operand (op, mode))
547 rtx inside = XEXP (op, 0);
548 /* Disallow mems with GBR address here. They have to go through
549 separate special patterns. */
550 if ((REG_P (inside) && REGNO (inside) == GBR_REG)
551 || (GET_CODE (inside) == PLUS && REG_P (XEXP (inside, 0))
552 && REGNO (XEXP (inside, 0)) == GBR_REG))
556 /* Only pre dec allowed. */
557 if (MEM_P (op) && GET_CODE (XEXP (op, 0)) == POST_INC)
559 if (mode == DImode && TARGET_SHMEDIA && GET_CODE (op) == SUBREG
560 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) < 8
561 && ! (reload_in_progress || reload_completed))
564 if (mode == GET_MODE (op)
565 && (MEM_P (op) || (GET_CODE (op) == SUBREG && MEM_P (SUBREG_REG (op)))))
567 rtx mem_rtx = MEM_P (op) ? op : SUBREG_REG (op);
568 rtx x = XEXP (mem_rtx, 0);
570 if ((mode == QImode || mode == HImode)
571 && GET_CODE (x) == PLUS
572 && REG_P (XEXP (x, 0))
573 && CONST_INT_P (XEXP (x, 1)))
574 return sh_legitimate_index_p (mode, XEXP (x, 1), TARGET_SH2A, false);
576 /* Allow reg+reg addressing here without validating the register
577 numbers. Usually one of the regs must be R0 or a pseudo reg.
578 In some cases it can happen that arguments from hard regs are
579 propagated directly into address expressions. In this cases reload
580 will have to fix it up later. However, allow this only for native
581 1, 2 or 4 byte addresses. */
582 if (can_create_pseudo_p () && GET_CODE (x) == PLUS
583 && GET_MODE_SIZE (mode) <= 4
584 && REG_P (XEXP (x, 0)) && REG_P (XEXP (x, 1)))
587 /* 'general_operand' does not allow volatile mems during RTL expansion to
588 avoid matching arithmetic that operates on mems, it seems.
589 On SH this leads to redundant sign extensions for QImode or HImode
590 stores. Thus we mimic the behavior but allow volatile mems. */
591 if (memory_address_addr_space_p (GET_MODE (mem_rtx), x,
592 MEM_ADDR_SPACE (mem_rtx)))
596 return general_operand (op, mode);
599 ;; Returns 1 if OP is a POST_INC on stack pointer register.
600 (define_predicate "sh_no_delay_pop_operand"
604 inside = XEXP (op, 0);
606 if (GET_CODE (op) == MEM && GET_MODE (op) == SImode
607 && GET_CODE (inside) == POST_INC
608 && GET_CODE (XEXP (inside, 0)) == REG
609 && REGNO (XEXP (inside, 0)) == SP_REG)
615 ;; Returns 1 if OP is a MEM that can be source of a simple move operation.
616 (define_predicate "unaligned_load_operand"
621 if (!MEM_P (op) || GET_MODE (op) != mode)
624 inside = XEXP (op, 0);
626 if (GET_CODE (inside) == POST_INC)
627 inside = XEXP (inside, 0);
635 ;; Returns 1 if OP is a MEM that can be used in "index_disp" combiner
637 (define_predicate "mem_index_disp_operand"
640 rtx plus0_rtx, plus1_rtx, mult_rtx;
642 plus0_rtx = XEXP (op, 0);
643 if (GET_CODE (plus0_rtx) != PLUS)
646 plus1_rtx = XEXP (plus0_rtx, 0);
647 if (GET_CODE (plus1_rtx) != PLUS)
649 if (! arith_reg_operand (XEXP (plus1_rtx, 1), GET_MODE (XEXP (plus1_rtx, 1))))
652 mult_rtx = XEXP (plus1_rtx, 0);
653 if (GET_CODE (mult_rtx) != MULT)
655 if (! arith_reg_operand (XEXP (mult_rtx, 0), GET_MODE (XEXP (mult_rtx, 0)))
656 || ! CONST_INT_P (XEXP (mult_rtx, 1)))
659 return exact_log2 (INTVAL (XEXP (mult_rtx, 1))) > 0
660 && sh_legitimate_index_p (mode, XEXP (plus0_rtx, 1), TARGET_SH2A, true);
663 ;; Returns true if OP is some kind of greater comparision.
664 (define_predicate "greater_comparison_operator"
665 (match_code "gt,ge,gtu,geu"))
667 ;; Returns true if OP is an operand suitable for shmedia reload_inqi and
668 ;; reload_inhi insns.
669 (define_predicate "inqhi_operand"
670 (match_code "truncate")
672 if (GET_CODE (op) != TRUNCATE || mode != GET_MODE (op))
675 /* Can't use true_regnum here because copy_cost wants to know about
676 SECONDARY_INPUT_RELOAD_CLASS. */
677 return REG_P (op) && FP_REGISTER_P (REGNO (op));
680 ;; Returns true if OP is a general purpose integer register.
681 ;; This predicate is currently unused.
682 ;;(define_special_predicate "int_gpr_dest"
683 ;; (match_code "subreg,reg")
685 ;; enum machine_mode op_mode = GET_MODE (op);
687 ;; if (GET_MODE_CLASS (op_mode) != MODE_INT
688 ;; || GET_MODE_SIZE (op_mode) >= UNITS_PER_WORD)
690 ;; if (! reload_completed)
692 ;; return true_regnum (op) <= LAST_GENERAL_REG;
695 ;; Returns true if OP is some kind of less comparison.
696 (define_predicate "less_comparison_operator"
697 (match_code "lt,le,ltu,leu"))
699 ;; Returns 1 if OP is a valid source operand for a logical operation.
700 (define_predicate "logical_operand"
701 (match_code "subreg,reg,const_int")
704 && mode != DImode && GET_CODE (op) == SUBREG
705 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) > 4)
708 if (arith_reg_operand (op, mode))
713 if (satisfies_constraint_I10 (op))
718 else if (satisfies_constraint_K08 (op))
724 ;; Like logical_operand but allows additional constant values which can be
725 ;; done with zero extensions. Used for the second operand of and insns.
726 (define_predicate "logical_and_operand"
727 (match_code "subreg,reg,const_int")
729 if (logical_operand (op, mode))
733 && (satisfies_constraint_Jmb (op) || satisfies_constraint_Jmw (op)))
739 ;; Returns true if OP is a logical operator.
740 (define_predicate "logical_operator"
741 (match_code "and,ior,xor"))
743 ;; Like arith_reg_operand, but for register source operands of narrow
744 ;; logical SHMEDIA operations: forbid subregs of DImode / TImode regs.
745 (define_predicate "logical_reg_operand"
746 (match_code "subreg,reg")
749 && GET_CODE (op) == SUBREG
750 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) > 4
753 return arith_reg_operand (op, mode);
756 ;; Returns true if OP is a valid bit offset value for the shmedia mextr insns.
757 (define_predicate "mextr_bit_offset"
758 (match_code "const_int")
762 if (!CONST_INT_P (op))
765 return i >= 1 * 8 && i <= 7 * 8 && (i & 7) == 0;
768 ;; Returns true if OP is a constant -1, 0 or an zero extended register that
769 ;; can be used as an operator in the *subsi3_media insn.
770 (define_predicate "minuend_operand"
771 (match_code "subreg,reg,truncate,const_int")
773 return op == constm1_rtx || extend_reg_or_0_operand (op, mode);
776 ;; Returns true if OP is a noncommutative floating point operator.
777 ;; This predicate is currently unused.
778 ;;(define_predicate "noncommutative_float_operator"
779 ;; (and (match_code "minus,div")
780 ;; (match_test "GET_MODE (op) == mode")))
782 ;; UNORDERED is only supported on SHMEDIA.
784 (define_predicate "sh_float_comparison_operator"
785 (ior (match_operand 0 "ordered_comparison_operator")
786 (and (match_test "TARGET_SHMEDIA")
787 (match_code "unordered"))))
789 (define_predicate "shmedia_cbranch_comparison_operator"
790 (ior (match_operand 0 "equality_comparison_operator")
791 (match_operand 0 "greater_comparison_operator")))
793 ;; Returns true if OP is a constant vector.
794 (define_predicate "sh_const_vec"
795 (match_code "const_vector")
799 if (GET_CODE (op) != CONST_VECTOR
800 || (GET_MODE (op) != mode && mode != VOIDmode))
802 i = XVECLEN (op, 0) - 1;
804 if (!CONST_INT_P (XVECEXP (op, 0, i)))
809 ;; Determine if OP is a constant vector matching MODE with only one
810 ;; element that is not a sign extension. Two byte-sized elements
812 (define_predicate "sh_1el_vec"
813 (match_code "const_vector")
816 int i, last, least, sign_ix;
819 if (GET_CODE (op) != CONST_VECTOR
820 || (GET_MODE (op) != mode && mode != VOIDmode))
822 /* Determine numbers of last and of least significant elements. */
823 last = XVECLEN (op, 0) - 1;
824 least = TARGET_LITTLE_ENDIAN ? 0 : last;
825 if (!CONST_INT_P (XVECEXP (op, 0, least)))
828 if (GET_MODE_UNIT_SIZE (mode) == 1)
829 sign_ix = TARGET_LITTLE_ENDIAN ? 1 : last - 1;
830 if (!CONST_INT_P (XVECEXP (op, 0, sign_ix)))
832 unit_size = GET_MODE_UNIT_SIZE (GET_MODE (op));
833 sign = (INTVAL (XVECEXP (op, 0, sign_ix)) >> (unit_size * BITS_PER_UNIT - 1)
834 ? constm1_rtx : const0_rtx);
835 i = XVECLEN (op, 0) - 1;
837 if (i != least && i != sign_ix && XVECEXP (op, 0, i) != sign)
843 ;; Like register_operand, but take into account that SHMEDIA can use
844 ;; the constant zero like a general register.
845 (define_predicate "sh_register_operand"
846 (match_code "reg,subreg,const_int,const_double")
848 if (op == CONST0_RTX (mode) && TARGET_SHMEDIA)
850 return register_operand (op, mode);
853 ;; Returns true if OP is a vector which is composed of one element that is
855 (define_predicate "sh_rep_vec"
856 (match_code "const_vector,parallel")
861 if ((GET_CODE (op) != CONST_VECTOR && GET_CODE (op) != PARALLEL)
862 || (GET_MODE (op) != mode && mode != VOIDmode))
864 i = XVECLEN (op, 0) - 2;
865 x = XVECEXP (op, 0, i + 1);
866 if (GET_MODE_UNIT_SIZE (mode) == 1)
868 y = XVECEXP (op, 0, i);
869 for (i -= 2; i >= 0; i -= 2)
870 if (! rtx_equal_p (XVECEXP (op, 0, i + 1), x)
871 || ! rtx_equal_p (XVECEXP (op, 0, i), y))
876 if (XVECEXP (op, 0, i) != x)
881 ;; Returns true if OP is a valid shift count operand for shift operations.
882 (define_predicate "shift_count_operand"
883 (match_code "const_int,const_double,const,symbol_ref,label_ref,subreg,reg,
884 zero_extend,sign_extend")
886 /* Allow T_REG as shift count for dynamic shifts, although it is not
887 really possible. It will then be copied to a general purpose reg. */
888 if (! TARGET_SHMEDIA)
889 return const_int_operand (op, mode) || arith_reg_operand (op, mode)
890 || (TARGET_DYNSHIFT && t_reg_operand (op, mode));
892 return (CONSTANT_P (op)
894 ? (unsigned) INTVAL (op) < GET_MODE_BITSIZE (mode)
895 : nonmemory_operand (op, mode))
896 : shift_count_reg_operand (op, mode));
899 ;; Returns true if OP is a valid shift count operand in a register which can
900 ;; be used by shmedia shift insns.
901 (define_predicate "shift_count_reg_operand"
902 (match_code "subreg,reg,zero_extend,sign_extend")
904 if ((GET_CODE (op) == ZERO_EXTEND || GET_CODE (op) == SIGN_EXTEND
905 || (GET_CODE (op) == SUBREG && SUBREG_BYTE (op) == 0))
906 && (mode == VOIDmode || mode == GET_MODE (op))
907 && GET_MODE_BITSIZE (GET_MODE (XEXP (op, 0))) >= 6
908 && GET_MODE_CLASS (GET_MODE (XEXP (op, 0))) == MODE_INT)
913 while ((GET_CODE (op) == ZERO_EXTEND || GET_CODE (op) == SIGN_EXTEND
914 || GET_CODE (op) == TRUNCATE)
915 && GET_MODE_BITSIZE (GET_MODE (XEXP (op, 0))) >= 6
916 && GET_MODE_CLASS (GET_MODE (XEXP (op, 0))) == MODE_INT);
919 return arith_reg_operand (op, mode);
922 ;; Predicates for matching operands that are constant shift
923 ;; amounts 1, 2, 8, 16.
924 (define_predicate "p27_shift_count_operand"
925 (and (match_code "const_int")
926 (match_test "satisfies_constraint_P27 (op)")))
928 (define_predicate "not_p27_shift_count_operand"
929 (and (match_code "const_int")
930 (match_test "! satisfies_constraint_P27 (op)")))
932 ;; For right shifts the constant 1 is a special case because the shlr insn
933 ;; clobbers the T_REG and is handled by the T_REG clobbering version of the
934 ;; insn, which is also used for non-P27 shift sequences.
935 (define_predicate "p27_rshift_count_operand"
936 (and (match_code "const_int")
937 (match_test "satisfies_constraint_P27 (op)")
938 (match_test "! satisfies_constraint_M (op)")))
940 (define_predicate "not_p27_rshift_count_operand"
941 (and (match_code "const_int")
942 (ior (match_test "! satisfies_constraint_P27 (op)")
943 (match_test "satisfies_constraint_M (op)"))))
945 ;; Returns true if OP is some kind of a shift operator.
946 (define_predicate "shift_operator"
947 (match_code "ashift,ashiftrt,lshiftrt"))
949 ;; Returns true if OP is a symbol reference.
950 (define_predicate "symbol_ref_operand"
951 (match_code "symbol_ref"))
953 ;; Same as target_reg_operand, except that label_refs and symbol_refs
954 ;; are accepted before reload.
955 (define_special_predicate "target_operand"
956 (match_code "subreg,reg,label_ref,symbol_ref,const,unspec")
958 if (mode != VOIDmode && mode != Pmode)
961 if ((GET_MODE (op) == Pmode || GET_MODE (op) == VOIDmode)
962 && satisfies_constraint_Csy (op))
963 return ! reload_completed;
965 return target_reg_operand (op, mode);
968 ;; A predicate that accepts pseudos and branch target registers.
969 (define_special_predicate "target_reg_operand"
970 (match_code "subreg,reg")
973 ? GET_MODE (op) != Pmode && GET_MODE (op) != PDImode
974 : mode != GET_MODE (op))
977 if (GET_CODE (op) == SUBREG)
983 /* We must protect ourselves from matching pseudos that are virtual
984 register, because they will eventually be replaced with hardware
985 registers that aren't branch-target registers. */
986 if (REGNO (op) > LAST_VIRTUAL_REGISTER
987 || TARGET_REGISTER_P (REGNO (op)))
993 ;; Returns true if OP is a valid operand for the shmedia mperm.w insn.
994 (define_special_predicate "trunc_hi_operand"
995 (match_code "subreg,reg,truncate")
997 enum machine_mode op_mode = GET_MODE (op);
999 if (op_mode != SImode && op_mode != DImode
1000 && op_mode != V4HImode && op_mode != V2SImode)
1002 return extend_reg_operand (op, mode);
1005 ;; Returns true if OP is an address suitable for an unaligned access
1007 (define_special_predicate "ua_address_operand"
1008 (match_code "subreg,reg,plus")
1010 if (GET_CODE (op) == PLUS
1011 && (! satisfies_constraint_I06 (XEXP (op, 1))))
1013 return address_operand (op, QImode);
1016 ;; Returns true if OP is a valid offset for an unaligned memory address.
1017 (define_predicate "ua_offset"
1018 (match_code "const_int")
1020 return satisfies_constraint_I06 (op);
1023 ;; Returns true if OP is a floating point operator with one operand.
1024 (define_predicate "unary_float_operator"
1025 (and (match_code "abs,neg,sqrt")
1026 (match_test "GET_MODE (op) == mode")))
1028 ;; Return 1 if OP is a valid source operand for xor.
1029 (define_predicate "xor_operand"
1030 (match_code "subreg,reg,const_int")
1032 if (CONST_INT_P (op))
1033 return (TARGET_SHMEDIA
1034 ? (satisfies_constraint_I06 (op)
1035 || (!can_create_pseudo_p () && INTVAL (op) == 0xff))
1036 : satisfies_constraint_K08 (op));
1038 && mode != DImode && GET_CODE (op) == SUBREG
1039 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) > 4)
1041 return arith_reg_operand (op, mode);
1044 (define_predicate "bitwise_memory_operand"
1049 if (REG_P (XEXP (op, 0)))
1052 if (GET_CODE (XEXP (op, 0)) == PLUS
1053 && REG_P (XEXP (XEXP (op, 0), 0))
1054 && satisfies_constraint_K12 (XEXP (XEXP (op, 0), 1)))
1060 ;; The atomic_* operand predicates are used for the atomic patterns.
1061 ;; Depending on the particular pattern some operands can be immediate
1062 ;; values. Using these predicates avoids the usage of 'force_reg' in the
1064 (define_predicate "atomic_arith_operand"
1065 (ior (match_code "subreg,reg")
1066 (and (match_test "satisfies_constraint_I08 (op)")
1067 (match_test "mode != QImode")
1068 (match_test "mode != HImode")
1069 (match_test "TARGET_SH4A_ARCH"))))
1071 (define_predicate "atomic_logical_operand"
1072 (ior (match_code "subreg,reg")
1073 (and (match_test "satisfies_constraint_K08 (op)")
1074 (match_test "mode != QImode")
1075 (match_test "mode != HImode")
1076 (match_test "TARGET_SH4A_ARCH"))))
1078 ;; A predicate describing the T bit register in any form.
1079 (define_predicate "t_reg_operand"
1080 (match_code "reg,subreg,sign_extend,zero_extend")
1082 switch (GET_CODE (op))
1085 return REGNO (op) == T_REG;
1088 return REG_P (SUBREG_REG (op)) && REGNO (SUBREG_REG (op)) == T_REG;
1092 return GET_CODE (XEXP (op, 0)) == SUBREG
1093 && REG_P (SUBREG_REG (XEXP (op, 0)))
1094 && REGNO (SUBREG_REG (XEXP (op, 0))) == T_REG;
1101 ;; A predicate describing a negated T bit register.
1102 (define_predicate "negt_reg_operand"
1103 (match_code "subreg,xor")
1105 switch (GET_CODE (op))
1108 return t_reg_operand (XEXP (op, 0), GET_MODE (XEXP (op, 0)))
1109 && satisfies_constraint_M (XEXP (op, 1));
1112 return negt_reg_operand (XEXP (op, 0), GET_MODE (XEXP (op, 0)));
1119 ;; A predicate that returns true if OP is a valid construct around the T bit
1120 ;; that can be used as an operand for conditional branches.
1121 (define_predicate "cbranch_treg_value"
1122 (match_code "eq,ne,reg,subreg,xor,sign_extend,zero_extend")
1124 return sh_eval_treg_value (op) >= 0;
1127 ;; Returns true if OP is arith_reg_operand or t_reg_operand.
1128 (define_predicate "arith_reg_or_t_reg_operand"
1129 (ior (match_operand 0 "arith_reg_operand")
1130 (match_operand 0 "t_reg_operand")))
1132 ;; A predicate describing the negated value of the T bit register shifted
1134 (define_predicate "negt_reg_shl31_operand"
1135 (match_code "plus,minus,if_then_else")
1137 /* (plus:SI (mult:SI (match_operand:SI 1 "t_reg_operand")
1138 (const_int -2147483648)) ;; 0xffffffff80000000
1139 (const_int -2147483648))
1141 if (GET_CODE (op) == PLUS && satisfies_constraint_Jhb (XEXP (op, 1))
1142 && GET_CODE (XEXP (op, 0)) == MULT
1143 && t_reg_operand (XEXP (XEXP (op, 0), 0), SImode)
1144 && satisfies_constraint_Jhb (XEXP (XEXP (op, 0), 1)))
1147 /* (minus:SI (const_int -2147483648) ;; 0xffffffff80000000
1148 (mult:SI (match_operand:SI 1 "t_reg_operand")
1149 (const_int -2147483648)))
1151 if (GET_CODE (op) == MINUS
1152 && satisfies_constraint_Jhb (XEXP (op, 0))
1153 && GET_CODE (XEXP (op, 1)) == MULT
1154 && t_reg_operand (XEXP (XEXP (op, 1), 0), SImode)
1155 && satisfies_constraint_Jhb (XEXP (XEXP (op, 1), 1)))
1158 /* (if_then_else:SI (match_operand:SI 1 "t_reg_operand")
1160 (const_int -2147483648)) ;; 0xffffffff80000000
1162 if (GET_CODE (op) == IF_THEN_ELSE && t_reg_operand (XEXP (op, 0), SImode)
1163 && satisfies_constraint_Z (XEXP (op, 1))
1164 && satisfies_constraint_Jhb (XEXP (op, 2)))
1170 ;; A predicate that determines whether a given constant is a valid
1171 ;; displacement for a GBR load/store of the specified mode.
1172 (define_predicate "gbr_displacement"
1173 (match_code "const_int")
1175 const int mode_sz = GET_MODE_SIZE (mode);
1176 const int move_sz = mode_sz > GET_MODE_SIZE (SImode)
1177 ? GET_MODE_SIZE (SImode)
1179 int max_disp = 255 * move_sz;
1180 if (mode_sz > move_sz)
1181 max_disp -= mode_sz - move_sz;
1183 return INTVAL (op) >= 0 && INTVAL (op) <= max_disp;
1186 ;; A predicate that determines whether OP is a valid GBR addressing mode
1187 ;; memory reference.
1188 (define_predicate "gbr_address_mem"
1191 rtx addr = XEXP (op, 0);
1193 if (REG_P (addr) && REGNO (addr) == GBR_REG)
1195 if (GET_CODE (addr) == PLUS
1196 && REG_P (XEXP (addr, 0)) && REGNO (XEXP (addr, 0)) == GBR_REG
1197 && gbr_displacement (XEXP (addr, 1), mode))