xref: /netbsd-src/external/gpl3/gcc/dist/gcc/config/sh/predicates.md (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
1;; Predicate definitions for Renesas / SuperH SH.
2;; Copyright (C) 2005-2013 Free Software Foundation, Inc.
3;;
4;; This file is part of GCC.
5;;
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)
9;; any later version.
10;;
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.
15;;
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/>.
19
20;; TODO: Add a comment here.
21(define_predicate "trapping_target_operand"
22  (match_code "if_then_else")
23{
24  rtx cond, mem, res, tar, and_expr;
25
26  if (GET_MODE (op) != PDImode)
27    return 0;
28  cond = XEXP (op, 0);
29  mem = XEXP (op, 1);
30  res = XEXP (op, 2);
31  if (!MEM_P (mem)
32      || (GET_CODE (res) != SIGN_EXTEND && GET_CODE (res) != TRUNCATE))
33    return 0;
34  tar = XEXP (res, 0);
35  if (!rtx_equal_p (XEXP (mem, 0), tar)
36      || GET_MODE (tar) != Pmode)
37    return 0;
38  if (GET_CODE (cond) == CONST)
39    {
40      cond = XEXP (cond, 0);
41      if (!satisfies_constraint_Csy (tar))
42	return 0;
43      if (GET_CODE (tar) == CONST)
44	tar = XEXP (tar, 0);
45    }
46  else if (!arith_reg_operand (tar, VOIDmode)
47	   && ! satisfies_constraint_Csy (tar))
48    return 0;
49  if (GET_CODE (cond) != EQ)
50    return 0;
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);
58})
59
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")
63{
64  if (logical_operand (op, mode))
65    return 1;
66
67  /* Check mshflo.l / mshflhi.l opportunities.  */
68  if (TARGET_SHMEDIA
69      && mode == DImode
70      && satisfies_constraint_J16 (op))
71    return 1;
72
73  return 0;
74})
75
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")
80{
81  return arith_reg_dest (op, mode);
82})
83
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")
88{
89  return register_operand (op, mode);
90})
91
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")
95{
96  if (arith_reg_operand (op, mode))
97    return 1;
98
99  if (TARGET_SHMEDIA)
100    {
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.  */
106      if (CONST_INT_P (op)
107	  || satisfies_constraint_Css (op))
108	return 1;
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);
118      else
119	return 0;
120    }
121  else if (satisfies_constraint_I08 (op))
122    return 1;
123
124  return 0;
125})
126
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")
132{
133  if (mode == DImode && GET_CODE (op) == SUBREG
134      && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) < 8
135      && TARGET_SHMEDIA)
136    return 0;
137  return arith_reg_operand (op, mode);
138})
139
140;; Returns 1 if OP is a normal arithmetic register.
141(define_predicate "arith_reg_operand"
142  (match_code "subreg,reg,sign_extend")
143{
144  if (register_operand (op, mode))
145    {
146      int regno;
147
148      if (REG_P (op))
149	regno = REGNO (op);
150      else if (GET_CODE (op) == SUBREG && REG_P (SUBREG_REG (op)))
151	regno = REGNO (SUBREG_REG (op));
152      else
153	return 1;
154
155      return (regno != T_REG && regno != PR_REG
156	      && ! TARGET_REGISTER_P (regno)
157	      && (regno != FPUL_REG || TARGET_SH4)
158	      && regno != MACH_REG && regno != MACL_REG);
159    }
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.  */
163  if (TARGET_SHMEDIA
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);
174#endif
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);
182  return 0;
183})
184
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")
188{
189  if (arith_reg_operand (op, mode))
190    return 1;
191
192  if (satisfies_constraint_Z (op))
193    return 1;
194
195  return 0;
196})
197
198;; Returns 1 if OP is a floating point operator with two operands.
199(define_predicate "binary_float_operator"
200  (and (match_code "plus,minus,mult,div")
201       (match_test "GET_MODE (op) == mode")))
202
203;; Returns 1 if OP is a logical operator with two operands.
204(define_predicate "binary_logical_operator"
205  (and (match_code "and,ior,xor")
206       (match_test "GET_MODE (op) == mode")))
207
208;; Return 1 if OP is an address suitable for a cache manipulation operation.
209;; MODE has the meaning as in address_operand.
210(define_special_predicate "cache_address_operand"
211  (match_code "plus,reg")
212{
213  if (GET_CODE (op) == PLUS)
214    {
215      if (!REG_P (XEXP (op, 0)))
216	return 0;
217      if (!CONST_INT_P (XEXP (op, 1))
218	  || (INTVAL (XEXP (op, 1)) & 31))
219	return 0;
220    }
221  else if (!REG_P (op))
222    return 0;
223  return address_operand (op, mode);
224})
225
226;; Returns 1 if OP is a valid source operand for shmedia cmpgt / cmpgtu.
227(define_predicate "cmp_operand"
228  (match_code "subreg,reg,const_int")
229{
230  if (satisfies_constraint_N (op))
231    return 1;
232  if (TARGET_SHMEDIA
233      && mode != DImode && GET_CODE (op) == SUBREG
234      && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) > 4)
235    return 0;
236  return arith_reg_operand (op, mode);
237})
238
239;; Returns true if OP is an operand that can be used as the first operand in
240;; the cstoresi4 expander pattern.
241(define_predicate "cmpsi_operand"
242  (match_code "subreg,reg,const_int")
243{
244  if (REG_P (op) && REGNO (op) == T_REG
245      && GET_MODE (op) == SImode
246      && TARGET_SH1)
247    return 1;
248  return arith_operand (op, mode);
249})
250
251;; Returns true if OP is a comutative float operator.
252;; This predicate is currently unused.
253;;(define_predicate "commutative_float_operator"
254;;  (and (match_code "plus,mult")
255;;       (match_test "GET_MODE (op) == mode")))
256
257;; Returns true if OP is a equal or not equal operator.
258(define_predicate "equality_comparison_operator"
259  (match_code "eq,ne"))
260
261;; Returns true if OP is an arithmetic operand that is zero extended during
262;; an operation.
263(define_predicate "extend_reg_operand"
264  (match_code "subreg,reg,truncate")
265{
266  return (GET_CODE (op) == TRUNCATE
267	  ? arith_operand
268	  : arith_reg_operand) (op, mode);
269})
270
271;; Like extend_reg_operand, but also allow a constant 0.
272(define_predicate "extend_reg_or_0_operand"
273  (match_code "subreg,reg,truncate,const_int")
274{
275  return (GET_CODE (op) == TRUNCATE
276	  ? arith_operand
277	  : arith_reg_or_0_operand) (op, mode);
278})
279
280;; Like arith_reg_operand, but this predicate does not accept SIGN_EXTEND.
281(define_predicate "ext_dest_operand"
282  (match_code "subreg,reg")
283{
284  return arith_reg_operand (op, mode);
285})
286
287;; Returns true if OP can be used as a destination register for shmedia floating
288;; point to integer conversions.
289(define_predicate "fp_arith_reg_dest"
290  (match_code "subreg,reg")
291{
292  if (mode == DImode && GET_CODE (op) == SUBREG
293      && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) < 8)
294    return 0;
295  return fp_arith_reg_operand (op, mode);
296})
297
298;; Returns true if OP is a floating point register that can be used in floating
299;; point arithmetic operations.
300(define_predicate "fp_arith_reg_operand"
301  (match_code "subreg,reg")
302{
303  if (register_operand (op, mode))
304    {
305      int regno;
306
307      if (REG_P (op))
308	regno = REGNO (op);
309      else if (GET_CODE (op) == SUBREG && REG_P (SUBREG_REG (op)))
310	regno = REGNO (SUBREG_REG (op));
311      else
312	return 1;
313
314      return (regno >= FIRST_PSEUDO_REGISTER
315	      || FP_REGISTER_P (regno));
316    }
317  return 0;
318})
319
320;; Returns true if OP is the FPSCR.
321(define_predicate "fpscr_operand"
322  (match_code "reg")
323{
324  return (REG_P (op)
325	  && (REGNO (op) == FPSCR_REG
326	      || (REGNO (op) >= FIRST_PSEUDO_REGISTER
327		  && !(reload_in_progress || reload_completed)))
328	  && GET_MODE (op) == PSImode);
329})
330
331;; Returns true if OP is an operand that is either the fpul hard reg or
332;; a pseudo.  This prevents combine from propagating function arguments
333;; in hard regs into insns that need the operand in fpul.  If it's a pseudo
334;; reload can fix it up.
335(define_predicate "fpul_operand"
336  (match_code "reg")
337{
338  if (TARGET_SHMEDIA)
339    return fp_arith_reg_operand (op, mode);
340
341  return (REG_P (op)
342	  && (REGNO (op) == FPUL_REG || REGNO (op) >= FIRST_PSEUDO_REGISTER)
343	  && GET_MODE (op) == mode);
344})
345
346;; Returns true if OP is a valid fpul input operand for the fsca insn.
347;; The value in fpul is a fixed-point value and its scaling is described
348;; in the fsca insn by a mult:SF.  To allow pre-scaled fixed-point inputs
349;; in fpul we have to permit things like
350;;   (reg:SI)
351;;   (fix:SF (float:SF (reg:SI)))
352(define_predicate "fpul_fsca_operand"
353  (match_code "fix,reg")
354{
355  if (fpul_operand (op, SImode))
356    return true;
357  if (GET_CODE (op) == FIX && GET_MODE (op) == SImode
358      && GET_CODE (XEXP (op, 0)) == FLOAT && GET_MODE (XEXP (op, 0)) == SFmode)
359    return fpul_fsca_operand (XEXP (XEXP (op, 0), 0),
360			      GET_MODE (XEXP (XEXP (op, 0), 0)));
361  return false;
362})
363
364;; Returns true if OP is a valid constant scale factor for the fsca insn.
365(define_predicate "fsca_scale_factor"
366  (and (match_code "const_double")
367       (match_test "op == sh_fsca_int2sf ()")))
368
369;; Returns true if OP is an operand that is zero extended during an operation.
370(define_predicate "general_extend_operand"
371  (match_code "subreg,reg,mem,truncate")
372{
373  return (GET_CODE (op) == TRUNCATE
374	  ? arith_operand
375	  : nonimmediate_operand) (op, mode);
376})
377
378;; Returns 1 if OP is a simple register address.
379(define_predicate "simple_mem_operand"
380  (and (match_code "mem")
381       (match_test "arith_reg_operand (XEXP (op, 0), SImode)")))
382
383;; Returns 1 if OP is a valid displacement address.
384(define_predicate "displacement_mem_operand"
385  (and (match_code "mem")
386       (match_test "GET_CODE (XEXP (op, 0)) == PLUS")
387       (match_test "arith_reg_operand (XEXP (XEXP (op, 0), 0), SImode)")
388       (match_test "sh_legitimate_index_p (GET_MODE (op),
389					   XEXP (XEXP (op, 0), 1),
390					   TARGET_SH2A, true)")))
391
392;; Returns true if OP is a displacement address that can fit into a
393;; 16 bit (non-SH2A) memory load / store insn.
394(define_predicate "short_displacement_mem_operand"
395  (match_test "sh_disp_addr_displacement (op)
396	       <= sh_max_mov_insn_displacement (GET_MODE (op), false)"))
397
398;; Returns 1 if the operand can be used in an SH2A movu.{b|w} insn.
399(define_predicate "zero_extend_movu_operand"
400  (and (match_operand 0 "displacement_mem_operand")
401       (match_test "GET_MODE (op) == QImode || GET_MODE (op) == HImode")))
402
403;; Returns 1 if the operand can be used in a zero_extend.
404(define_predicate "zero_extend_operand"
405  (ior (and (match_test "TARGET_SHMEDIA")
406	    (match_operand 0 "general_extend_operand"))
407       (and (match_test "! TARGET_SHMEDIA")
408	    (match_operand 0 "arith_reg_operand"))
409       (and (match_test "TARGET_SH2A")
410	    (match_operand 0 "zero_extend_movu_operand"))))
411
412;; Returns 1 if OP can be source of a simple move operation. Same as
413;; general_operand, but a LABEL_REF is valid, PRE_DEC is invalid as
414;; are subregs of system registers.
415(define_predicate "general_movsrc_operand"
416  (match_code "subreg,reg,const_int,const_double,mem,symbol_ref,label_ref,
417	       const,const_vector")
418{
419  if (t_reg_operand (op, mode))
420    return 0;
421
422  /* Disallow PC relative QImode loads, since these is no insn to do that
423     and an imm8 load should be used instead.  */
424  if (IS_PC_RELATIVE_LOAD_ADDR_P (op) && GET_MODE (op) == QImode)
425    return false;
426
427  if (MEM_P (op))
428    {
429      rtx inside = XEXP (op, 0);
430
431      /* Disallow mems with GBR address here.  They have to go through
432	 separate special patterns.  */
433      if ((REG_P (inside) && REGNO (inside) == GBR_REG)
434	  || (GET_CODE (inside) == PLUS && REG_P (XEXP (inside, 0))
435	      && REGNO (XEXP (inside, 0)) == GBR_REG))
436	return 0;
437
438      if (GET_CODE (inside) == CONST)
439	inside = XEXP (inside, 0);
440
441      if (GET_CODE (inside) == LABEL_REF)
442	return 1;
443
444      if (GET_CODE (inside) == PLUS
445	  && GET_CODE (XEXP (inside, 0)) == LABEL_REF
446	  && CONST_INT_P (XEXP (inside, 1)))
447	return 1;
448
449      /* Only post inc allowed.  */
450      if (GET_CODE (inside) == PRE_DEC)
451	return 0;
452    }
453
454  if ((mode == QImode || mode == HImode)
455      && mode == GET_MODE (op)
456      && (MEM_P (op)
457	  || (GET_CODE (op) == SUBREG && MEM_P (SUBREG_REG (op)))))
458    {
459      rtx x = XEXP ((MEM_P (op) ? op : SUBREG_REG (op)), 0);
460
461      if (GET_CODE (x) == PLUS
462	  && REG_P (XEXP (x, 0))
463	  && CONST_INT_P (XEXP (x, 1)))
464	return sh_legitimate_index_p (mode, XEXP (x, 1), TARGET_SH2A, false);
465    }
466
467  if (TARGET_SHMEDIA
468      && (GET_CODE (op) == PARALLEL || GET_CODE (op) == CONST_VECTOR)
469      && sh_rep_vec (op, mode))
470    return 1;
471  if (TARGET_SHMEDIA && 1
472      && GET_CODE (op) == SUBREG && GET_MODE (op) == mode
473      && SUBREG_REG (op) == const0_rtx && subreg_lowpart_p (op))
474    /* FIXME */ abort (); /* return 1; */
475  return general_operand (op, mode);
476})
477
478;; Returns 1 if OP is a MEM that does not use displacement addressing.
479(define_predicate "movsrc_no_disp_mem_operand"
480  (match_code "mem")
481{
482  return general_movsrc_operand (op, mode) && satisfies_constraint_Snd (op);
483})
484
485;; Returns 1 if OP can be a destination of a move. Same as
486;; general_operand, but no preinc allowed.
487(define_predicate "general_movdst_operand"
488  (match_code "subreg,reg,mem")
489{
490  if (t_reg_operand (op, mode))
491    return 0;
492
493  if (MEM_P (op))
494    {
495      rtx inside = XEXP (op, 0);
496      /* Disallow mems with GBR address here.  They have to go through
497	 separate special patterns.  */
498      if ((REG_P (inside) && REGNO (inside) == GBR_REG)
499	  || (GET_CODE (inside) == PLUS && REG_P (XEXP (inside, 0))
500	      && REGNO (XEXP (inside, 0)) == GBR_REG))
501	return 0;
502    }
503
504  /* Only pre dec allowed.  */
505  if (MEM_P (op) && GET_CODE (XEXP (op, 0)) == POST_INC)
506    return 0;
507  if (mode == DImode && TARGET_SHMEDIA && GET_CODE (op) == SUBREG
508      && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) < 8
509      && ! (reload_in_progress || reload_completed))
510    return 0;
511
512  if ((mode == QImode || mode == HImode)
513      && mode == GET_MODE (op)
514      && (MEM_P (op)
515	  || (GET_CODE (op) == SUBREG && MEM_P (SUBREG_REG (op)))))
516    {
517      rtx x = XEXP ((MEM_P (op) ? op : SUBREG_REG (op)), 0);
518
519      if (GET_CODE (x) == PLUS
520	  && REG_P (XEXP (x, 0))
521	  && CONST_INT_P (XEXP (x, 1)))
522	return sh_legitimate_index_p (mode, XEXP (x, 1), TARGET_SH2A, false);
523    }
524
525  return general_operand (op, mode);
526})
527
528;; Returns 1 if OP is a POST_INC on stack pointer register.
529(define_predicate "sh_no_delay_pop_operand"
530  (match_code "mem")
531{
532  rtx inside;
533  inside = XEXP (op, 0);
534
535  if (GET_CODE (op) == MEM && GET_MODE (op) == SImode
536      && GET_CODE (inside) == POST_INC
537      && GET_CODE (XEXP (inside, 0)) == REG
538      && REGNO (XEXP (inside, 0)) == SP_REG)
539    return 1;
540
541  return 0;
542})
543
544;; Returns 1 if OP is a MEM that can be source of a simple move operation.
545(define_predicate "unaligned_load_operand"
546  (match_code "mem")
547{
548  rtx inside;
549
550  if (!MEM_P (op) || GET_MODE (op) != mode)
551    return 0;
552
553  inside = XEXP (op, 0);
554
555  if (GET_CODE (inside) == POST_INC)
556    inside = XEXP (inside, 0);
557
558  if (REG_P (inside))
559    return 1;
560
561  return 0;
562})
563
564;; Returns 1 if OP is a MEM that can be used in "index_disp" combiner
565;; patterns.
566(define_predicate "mem_index_disp_operand"
567  (match_code "mem")
568{
569  rtx plus0_rtx, plus1_rtx, mult_rtx;
570
571  plus0_rtx = XEXP (op, 0);
572  if (GET_CODE (plus0_rtx) != PLUS)
573    return 0;
574
575  plus1_rtx = XEXP (plus0_rtx, 0);
576  if (GET_CODE (plus1_rtx) != PLUS)
577    return 0;
578  if (! arith_reg_operand (XEXP (plus1_rtx, 1), GET_MODE (XEXP (plus1_rtx, 1))))
579    return 0;
580
581  mult_rtx = XEXP (plus1_rtx, 0);
582  if (GET_CODE (mult_rtx) != MULT)
583    return 0;
584  if (! arith_reg_operand (XEXP (mult_rtx, 0), GET_MODE (XEXP (mult_rtx, 0)))
585      || ! CONST_INT_P (XEXP (mult_rtx, 1)))
586    return 0;
587
588  return exact_log2 (INTVAL (XEXP (mult_rtx, 1))) > 0
589	 && sh_legitimate_index_p (mode, XEXP (plus0_rtx, 1), TARGET_SH2A, true);
590})
591
592;; Returns true if OP is some kind of greater comparision.
593(define_predicate "greater_comparison_operator"
594  (match_code "gt,ge,gtu,geu"))
595
596;; Returns true if OP is an operand suitable for shmedia reload_inqi and
597;; reload_inhi insns.
598(define_predicate "inqhi_operand"
599  (match_code "truncate")
600{
601  if (GET_CODE (op) != TRUNCATE || mode != GET_MODE (op))
602    return 0;
603  op = XEXP (op, 0);
604  /* Can't use true_regnum here because copy_cost wants to know about
605     SECONDARY_INPUT_RELOAD_CLASS.  */
606  return REG_P (op) && FP_REGISTER_P (REGNO (op));
607})
608
609;; Returns true if OP is a general purpose integer register.
610;; This predicate is currently unused.
611;;(define_special_predicate "int_gpr_dest"
612;;  (match_code "subreg,reg")
613;;{
614;;  enum machine_mode op_mode = GET_MODE (op);
615;;
616;;  if (GET_MODE_CLASS (op_mode) != MODE_INT
617;;      || GET_MODE_SIZE (op_mode) >= UNITS_PER_WORD)
618;;    return 0;
619;;  if (! reload_completed)
620;;    return 0;
621;;  return true_regnum (op) <= LAST_GENERAL_REG;
622;;})
623
624;; Returns true if OP is some kind of less comparison.
625(define_predicate "less_comparison_operator"
626  (match_code "lt,le,ltu,leu"))
627
628;; Returns 1 if OP is a valid source operand for a logical operation.
629(define_predicate "logical_operand"
630  (match_code "subreg,reg,const_int")
631{
632  if (TARGET_SHMEDIA
633      && mode != DImode && GET_CODE (op) == SUBREG
634      && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) > 4)
635    return 0;
636
637  if (arith_reg_operand (op, mode))
638    return 1;
639
640  if (TARGET_SHMEDIA)
641    {
642      if (satisfies_constraint_I10 (op))
643	return 1;
644      else
645	return 0;
646    }
647  else if (satisfies_constraint_K08 (op))
648    return 1;
649
650  return 0;
651})
652
653;; Like logical_operand but allows additional constant values which can be
654;; done with zero extensions.  Used for the second operand of and insns.
655(define_predicate "logical_and_operand"
656  (match_code "subreg,reg,const_int")
657{
658  if (logical_operand (op, mode))
659    return 1;
660
661  if (! TARGET_SHMEDIA
662      && (satisfies_constraint_Jmb (op) || satisfies_constraint_Jmw (op)))
663    return 1;
664
665  return 0;
666})
667
668;; Returns true if OP is a logical operator.
669(define_predicate "logical_operator"
670  (match_code "and,ior,xor"))
671
672;; Like arith_reg_operand, but for register source operands of narrow
673;; logical SHMEDIA operations: forbid subregs of DImode / TImode regs.
674(define_predicate "logical_reg_operand"
675  (match_code "subreg,reg")
676{
677  if (TARGET_SHMEDIA
678      && GET_CODE (op) == SUBREG
679      && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) > 4
680      && mode != DImode)
681    return 0;
682  return arith_reg_operand (op, mode);
683})
684
685;; Returns true if OP is a valid bit offset value for the shmedia mextr insns.
686(define_predicate "mextr_bit_offset"
687  (match_code "const_int")
688{
689  HOST_WIDE_INT i;
690
691  if (!CONST_INT_P (op))
692    return 0;
693  i = INTVAL (op);
694  return i >= 1 * 8 && i <= 7 * 8 && (i & 7) == 0;
695})
696
697;; Returns true if OP is a constant -1, 0 or an zero extended register that
698;; can be used as an operator in the *subsi3_media insn.
699(define_predicate "minuend_operand"
700  (match_code "subreg,reg,truncate,const_int")
701{
702  return op == constm1_rtx || extend_reg_or_0_operand (op, mode);
703})
704
705;; Returns true if OP is a noncommutative floating point operator.
706;; This predicate is currently unused.
707;;(define_predicate "noncommutative_float_operator"
708;;  (and (match_code "minus,div")
709;;       (match_test "GET_MODE (op) == mode")))
710
711;; UNORDERED is only supported on SHMEDIA.
712
713(define_predicate "sh_float_comparison_operator"
714  (ior (match_operand 0 "ordered_comparison_operator")
715       (and (match_test "TARGET_SHMEDIA")
716	    (match_code "unordered"))))
717
718(define_predicate "shmedia_cbranch_comparison_operator"
719  (ior (match_operand 0 "equality_comparison_operator")
720       (match_operand 0 "greater_comparison_operator")))
721
722;; Returns true if OP is a constant vector.
723(define_predicate "sh_const_vec"
724  (match_code "const_vector")
725{
726  int i;
727
728  if (GET_CODE (op) != CONST_VECTOR
729      || (GET_MODE (op) != mode && mode != VOIDmode))
730    return 0;
731  i = XVECLEN (op, 0) - 1;
732  for (; i >= 0; i--)
733    if (!CONST_INT_P (XVECEXP (op, 0, i)))
734      return 0;
735  return 1;
736})
737
738;; Determine if OP is a constant vector matching MODE with only one
739;; element that is not a sign extension.  Two byte-sized elements
740;; count as one.
741(define_predicate "sh_1el_vec"
742  (match_code "const_vector")
743{
744  int unit_size;
745  int i, last, least, sign_ix;
746  rtx sign;
747
748  if (GET_CODE (op) != CONST_VECTOR
749      || (GET_MODE (op) != mode && mode != VOIDmode))
750    return 0;
751  /* Determine numbers of last and of least significant elements.  */
752  last = XVECLEN (op, 0) - 1;
753  least = TARGET_LITTLE_ENDIAN ? 0 : last;
754  if (!CONST_INT_P (XVECEXP (op, 0, least)))
755    return 0;
756  sign_ix = least;
757  if (GET_MODE_UNIT_SIZE (mode) == 1)
758    sign_ix = TARGET_LITTLE_ENDIAN ? 1 : last - 1;
759  if (!CONST_INT_P (XVECEXP (op, 0, sign_ix)))
760    return 0;
761  unit_size = GET_MODE_UNIT_SIZE (GET_MODE (op));
762  sign = (INTVAL (XVECEXP (op, 0, sign_ix)) >> (unit_size * BITS_PER_UNIT - 1)
763	  ? constm1_rtx : const0_rtx);
764  i = XVECLEN (op, 0) - 1;
765  do
766    if (i != least && i != sign_ix && XVECEXP (op, 0, i) != sign)
767      return 0;
768  while (--i);
769  return 1;
770})
771
772;; Like register_operand, but take into account that SHMEDIA can use
773;; the constant zero like a general register.
774(define_predicate "sh_register_operand"
775  (match_code "reg,subreg,const_int,const_double")
776{
777  if (op == CONST0_RTX (mode) && TARGET_SHMEDIA)
778    return 1;
779  return register_operand (op, mode);
780})
781
782;; Returns true if OP is a vector which is composed of one element that is
783;; repeated.
784(define_predicate "sh_rep_vec"
785  (match_code "const_vector,parallel")
786{
787  int i;
788  rtx x, y;
789
790  if ((GET_CODE (op) != CONST_VECTOR && GET_CODE (op) != PARALLEL)
791      || (GET_MODE (op) != mode && mode != VOIDmode))
792    return 0;
793  i = XVECLEN (op, 0) - 2;
794  x = XVECEXP (op, 0, i + 1);
795  if (GET_MODE_UNIT_SIZE (mode) == 1)
796    {
797      y = XVECEXP (op, 0, i);
798      for (i -= 2; i >= 0; i -= 2)
799	if (! rtx_equal_p (XVECEXP (op, 0, i + 1), x)
800	    || ! rtx_equal_p (XVECEXP (op, 0, i), y))
801	  return 0;
802    }
803  else
804    for (; i >= 0; i--)
805      if (XVECEXP (op, 0, i) != x)
806	return 0;
807  return 1;
808})
809
810;; Returns true if OP is a valid shift count operand for shift operations.
811(define_predicate "shift_count_operand"
812  (match_code "const_int,const_double,const,symbol_ref,label_ref,subreg,reg,
813	       zero_extend,sign_extend")
814{
815  /* Allow T_REG as shift count for dynamic shifts, although it is not
816     really possible.  It will then be copied to a general purpose reg.  */
817  if (! TARGET_SHMEDIA)
818    return const_int_operand (op, mode) || arith_reg_operand (op, mode)
819	   || (TARGET_DYNSHIFT && t_reg_operand (op, mode));
820
821  return (CONSTANT_P (op)
822	  ? (CONST_INT_P (op)
823	     ? (unsigned) INTVAL (op) < GET_MODE_BITSIZE (mode)
824	     : nonmemory_operand (op, mode))
825	  : shift_count_reg_operand (op, mode));
826})
827
828;; Returns true if OP is a valid shift count operand in a register which can
829;; be used by shmedia shift insns.
830(define_predicate "shift_count_reg_operand"
831  (match_code "subreg,reg,zero_extend,sign_extend")
832{
833  if ((GET_CODE (op) == ZERO_EXTEND || GET_CODE (op) == SIGN_EXTEND
834       || (GET_CODE (op) == SUBREG && SUBREG_BYTE (op) == 0))
835      && (mode == VOIDmode || mode == GET_MODE (op))
836      && GET_MODE_BITSIZE (GET_MODE (XEXP (op, 0))) >= 6
837      && GET_MODE_CLASS (GET_MODE (XEXP (op, 0))) == MODE_INT)
838    {
839      mode = VOIDmode;
840      do
841	op = XEXP (op, 0);
842      while ((GET_CODE (op) == ZERO_EXTEND || GET_CODE (op) == SIGN_EXTEND
843	      || GET_CODE (op) == TRUNCATE)
844	     && GET_MODE_BITSIZE (GET_MODE (XEXP (op, 0))) >= 6
845	     && GET_MODE_CLASS (GET_MODE (XEXP (op, 0))) == MODE_INT);
846
847    }
848  return arith_reg_operand (op, mode);
849})
850
851;; Predicates for matching operands that are constant shift
852;; amounts 1, 2, 8, 16.
853(define_predicate "p27_shift_count_operand"
854  (and (match_code "const_int")
855       (match_test "satisfies_constraint_P27 (op)")))
856
857(define_predicate "not_p27_shift_count_operand"
858  (and (match_code "const_int")
859       (match_test "! satisfies_constraint_P27 (op)")))
860
861;; For right shifts the constant 1 is a special case because the shlr insn
862;; clobbers the T_REG and is handled by the T_REG clobbering version of the
863;; insn, which is also used for non-P27 shift sequences.
864(define_predicate "p27_rshift_count_operand"
865  (and (match_code "const_int")
866       (match_test "satisfies_constraint_P27 (op)")
867       (match_test "! satisfies_constraint_M (op)")))
868
869(define_predicate "not_p27_rshift_count_operand"
870  (and (match_code "const_int")
871       (ior (match_test "! satisfies_constraint_P27 (op)")
872	    (match_test "satisfies_constraint_M (op)"))))
873
874;; Returns true if OP is some kind of a shift operator.
875(define_predicate "shift_operator"
876  (match_code "ashift,ashiftrt,lshiftrt"))
877
878;; Returns true if OP is a symbol reference.
879(define_predicate "symbol_ref_operand"
880  (match_code "symbol_ref"))
881
882;; Same as target_reg_operand, except that label_refs and symbol_refs
883;; are accepted before reload.
884(define_special_predicate "target_operand"
885  (match_code "subreg,reg,label_ref,symbol_ref,const,unspec")
886{
887  if (mode != VOIDmode && mode != Pmode)
888    return 0;
889
890  if ((GET_MODE (op) == Pmode || GET_MODE (op) == VOIDmode)
891      && satisfies_constraint_Csy (op))
892    return ! reload_completed;
893
894  return target_reg_operand (op, mode);
895})
896
897;; A predicate that accepts pseudos and branch target registers.
898(define_special_predicate "target_reg_operand"
899  (match_code "subreg,reg")
900{
901  if (mode == VOIDmode
902     ? GET_MODE (op) != Pmode && GET_MODE (op) != PDImode
903     : mode != GET_MODE (op))
904    return 0;
905
906  if (GET_CODE (op) == SUBREG)
907    op = XEXP (op, 0);
908
909  if (!REG_P (op))
910    return 0;
911
912  /* We must protect ourselves from matching pseudos that are virtual
913     register, because they will eventually be replaced with hardware
914     registers that aren't branch-target registers.  */
915  if (REGNO (op) > LAST_VIRTUAL_REGISTER
916      || TARGET_REGISTER_P (REGNO (op)))
917    return 1;
918
919  return 0;
920})
921
922;; Returns true if OP is a valid operand for the shmedia mperm.w insn.
923(define_special_predicate "trunc_hi_operand"
924  (match_code "subreg,reg,truncate")
925{
926  enum machine_mode op_mode = GET_MODE (op);
927
928  if (op_mode != SImode && op_mode != DImode
929      && op_mode != V4HImode && op_mode != V2SImode)
930    return 0;
931  return extend_reg_operand (op, mode);
932})
933
934;; Returns true if OP is an address suitable for an unaligned access
935;; instruction.
936(define_special_predicate "ua_address_operand"
937  (match_code "subreg,reg,plus")
938{
939  if (GET_CODE (op) == PLUS
940      && (! satisfies_constraint_I06 (XEXP (op, 1))))
941    return 0;
942  return address_operand (op, QImode);
943})
944
945;; Returns true if OP is a valid offset for an unaligned memory address.
946(define_predicate "ua_offset"
947  (match_code "const_int")
948{
949  return satisfies_constraint_I06 (op);
950})
951
952;; Returns true if OP is a floating point operator with one operand.
953(define_predicate "unary_float_operator"
954  (and (match_code "abs,neg,sqrt")
955       (match_test "GET_MODE (op) == mode")))
956
957;; Return 1 if OP is a valid source operand for xor.
958(define_predicate "xor_operand"
959  (match_code "subreg,reg,const_int")
960{
961  if (CONST_INT_P (op))
962    return (TARGET_SHMEDIA
963	    ? (satisfies_constraint_I06 (op)
964	       || (!can_create_pseudo_p () && INTVAL (op) == 0xff))
965	    : satisfies_constraint_K08 (op));
966  if (TARGET_SHMEDIA
967      && mode != DImode && GET_CODE (op) == SUBREG
968      && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) > 4)
969    return 0;
970  return arith_reg_operand (op, mode);
971})
972
973(define_predicate "bitwise_memory_operand"
974  (match_code "mem")
975{
976  if (MEM_P (op))
977    {
978      if (REG_P (XEXP (op, 0)))
979	return 1;
980
981      if (GET_CODE (XEXP (op, 0)) == PLUS
982	  && REG_P (XEXP (XEXP (op, 0), 0))
983	  && satisfies_constraint_K12 (XEXP (XEXP (op, 0), 1)))
984        return 1;
985    }
986  return 0;
987})
988
989;; The atomic_* operand predicates are used for the atomic patterns.
990;; Depending on the particular pattern some operands can be immediate
991;; values.  Using these predicates avoids the usage of 'force_reg' in the
992;; expanders.
993(define_predicate "atomic_arith_operand"
994  (ior (match_code "subreg,reg")
995       (and (match_test "satisfies_constraint_I08 (op)")
996	    (match_test "mode != QImode")
997	    (match_test "mode != HImode")
998	    (match_test "TARGET_SH4A_ARCH"))))
999
1000(define_predicate "atomic_logical_operand"
1001  (ior (match_code "subreg,reg")
1002       (and (match_test "satisfies_constraint_K08 (op)")
1003	    (match_test "mode != QImode")
1004	    (match_test "mode != HImode")
1005	    (match_test "TARGET_SH4A_ARCH"))))
1006
1007;; A predicate describing the T bit register in any form.
1008(define_predicate "t_reg_operand"
1009  (match_code "reg,subreg,sign_extend,zero_extend")
1010{
1011  switch (GET_CODE (op))
1012    {
1013      case REG:
1014	return REGNO (op) == T_REG;
1015
1016      case SUBREG:
1017	return REG_P (SUBREG_REG (op)) && REGNO (SUBREG_REG (op)) == T_REG;
1018
1019      case ZERO_EXTEND:
1020      case SIGN_EXTEND:
1021	return GET_CODE (XEXP (op, 0)) == SUBREG
1022	       && REG_P (SUBREG_REG (XEXP (op, 0)))
1023	       && REGNO (SUBREG_REG (XEXP (op, 0))) == T_REG;
1024
1025      default:
1026	return 0;
1027    }
1028})
1029
1030;; A predicate describing a negated T bit register.
1031(define_predicate "negt_reg_operand"
1032  (match_code "subreg,xor")
1033{
1034  switch (GET_CODE (op))
1035    {
1036      case XOR:
1037	return t_reg_operand (XEXP (op, 0), GET_MODE (XEXP (op, 0)))
1038	       && satisfies_constraint_M (XEXP (op, 1));
1039
1040      case SUBREG:
1041	return negt_reg_operand (XEXP (op, 0), GET_MODE (XEXP (op, 0)));
1042
1043      default:
1044	return 0;
1045    }
1046})
1047
1048;; A predicate that returns true if OP is a valid construct around the T bit
1049;; that can be used as an operand for conditional branches.
1050(define_predicate "cbranch_treg_value"
1051  (match_code "eq,ne,reg,subreg,xor,sign_extend,zero_extend")
1052{
1053  return sh_eval_treg_value (op) >= 0;
1054})
1055
1056;; Returns true if OP is arith_reg_operand or t_reg_operand.
1057(define_predicate "arith_reg_or_t_reg_operand"
1058  (ior (match_operand 0 "arith_reg_operand")
1059       (match_operand 0 "t_reg_operand")))
1060
1061;; A predicate describing the negated value of the T bit register shifted
1062;; left by 31.
1063(define_predicate "negt_reg_shl31_operand"
1064  (match_code "plus,minus,if_then_else")
1065{
1066  /* (plus:SI (mult:SI (match_operand:SI 1 "t_reg_operand")
1067		       (const_int -2147483648))  ;; 0xffffffff80000000
1068	      (const_int -2147483648))
1069  */
1070  if (GET_CODE (op) == PLUS && satisfies_constraint_Jhb (XEXP (op, 1))
1071      && GET_CODE (XEXP (op, 0)) == MULT
1072      && t_reg_operand (XEXP (XEXP (op, 0), 0), SImode)
1073      && satisfies_constraint_Jhb (XEXP (XEXP (op, 0), 1)))
1074    return true;
1075
1076  /* (minus:SI (const_int -2147483648)  ;; 0xffffffff80000000
1077	       (mult:SI (match_operand:SI 1 "t_reg_operand")
1078			(const_int -2147483648)))
1079  */
1080  if (GET_CODE (op) == MINUS
1081      && satisfies_constraint_Jhb (XEXP (op, 0))
1082      && GET_CODE (XEXP (op, 1)) == MULT
1083      && t_reg_operand (XEXP (XEXP (op, 1), 0), SImode)
1084      && satisfies_constraint_Jhb (XEXP (XEXP (op, 1), 1)))
1085    return true;
1086
1087  /*  (if_then_else:SI (match_operand:SI 1 "t_reg_operand")
1088		       (const_int 0)
1089		       (const_int -2147483648))  ;; 0xffffffff80000000
1090  */
1091  if (GET_CODE (op) == IF_THEN_ELSE && t_reg_operand (XEXP (op, 0), SImode)
1092      && satisfies_constraint_Z (XEXP (op, 1))
1093      && satisfies_constraint_Jhb (XEXP (op, 2)))
1094    return true;
1095
1096  return false;
1097})
1098
1099;; A predicate that determines whether a given constant is a valid
1100;; displacement for a GBR load/store of the specified mode.
1101(define_predicate "gbr_displacement"
1102  (match_code "const_int")
1103{
1104  const int mode_sz = GET_MODE_SIZE (mode);
1105  const int move_sz = mode_sz > GET_MODE_SIZE (SImode)
1106				? GET_MODE_SIZE (SImode)
1107				: mode_sz;
1108  int max_disp = 255 * move_sz;
1109  if (mode_sz > move_sz)
1110    max_disp -= mode_sz - move_sz;
1111
1112  return INTVAL (op) >= 0 && INTVAL (op) <= max_disp;
1113})
1114
1115;; A predicate that determines whether OP is a valid GBR addressing mode
1116;; memory reference.
1117(define_predicate "gbr_address_mem"
1118  (match_code "mem")
1119{
1120  rtx addr = XEXP (op, 0);
1121
1122  if (REG_P (addr) && REGNO (addr) == GBR_REG)
1123    return true;
1124  if (GET_CODE (addr) == PLUS
1125      && REG_P (XEXP (addr, 0)) && REGNO (XEXP (addr, 0)) == GBR_REG
1126      && gbr_displacement (XEXP (addr, 1), mode))
1127    return true;
1128
1129  return false;
1130})
1131