]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/sh/predicates.md
re PR target/53511 (SH Target: Add support for fma patterns)
[thirdparty/gcc.git] / gcc / config / sh / predicates.md
CommitLineData
5546ac90 1;; Predicate definitions for Renesas / SuperH SH.
1ce35c11 2;; Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2012
c11c09f9 3;; Free Software Foundation, Inc.
5546ac90
KH
4;;
5;; This file is part of GCC.
6;;
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
2f83c7d6 9;; the Free Software Foundation; either version 3, or (at your option)
5546ac90
KH
10;; any later version.
11;;
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.
16;;
17;; You should have received a copy of the GNU General Public License
2f83c7d6
NC
18;; along with GCC; see the file COPYING3. If not see
19;; <http://www.gnu.org/licenses/>.
5546ac90
KH
20
21;; TODO: Add a comment here.
22
73a4d10b
R
23(define_predicate "trapping_target_operand"
24 (match_code "if_then_else")
25{
5a82ecd9 26 rtx cond, mem, res, tar, and_expr;
73a4d10b
R
27
28 if (GET_MODE (op) != PDImode)
29 return 0;
30 cond = XEXP (op, 0);
31 mem = XEXP (op, 1);
32 res = XEXP (op, 2);
f3536097 33 if (!MEM_P (mem)
73a4d10b
R
34 || (GET_CODE (res) != SIGN_EXTEND && GET_CODE (res) != TRUNCATE))
35 return 0;
36 tar = XEXP (res, 0);
37 if (!rtx_equal_p (XEXP (mem, 0), tar)
38 || GET_MODE (tar) != Pmode)
39 return 0;
40 if (GET_CODE (cond) == CONST)
41 {
42 cond = XEXP (cond, 0);
32a7ab3d 43 if (!satisfies_constraint_Csy (tar))
73a4d10b
R
44 return 0;
45 if (GET_CODE (tar) == CONST)
46 tar = XEXP (tar, 0);
47 }
48 else if (!arith_reg_operand (tar, VOIDmode)
32a7ab3d 49 && ! satisfies_constraint_Csy (tar))
73a4d10b
R
50 return 0;
51 if (GET_CODE (cond) != EQ)
52 return 0;
5a82ecd9
ILT
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))
f3536097 57 && CONST_INT_P (XEXP (cond, 1))
5a82ecd9 58 && INTVAL (XEXP (and_expr, 1)) == 3
73a4d10b
R
59 && INTVAL (XEXP (cond, 1)) == 3);
60})
5546ac90
KH
61
62;; TODO: Add a comment here.
63
64(define_predicate "and_operand"
65 (match_code "subreg,reg,const_int")
66{
67 if (logical_operand (op, mode))
68 return 1;
69
70 /* Check mshflo.l / mshflhi.l opportunities. */
71 if (TARGET_SHMEDIA
72 && mode == DImode
32a7ab3d 73 && satisfies_constraint_J16 (op))
5546ac90
KH
74 return 1;
75
76 return 0;
77})
78
c2acaf06
KH
79;; Like arith_reg_dest, but this predicate is defined with
80;; define_special_predicate, not define_predicate.
5546ac90
KH
81
82(define_special_predicate "any_arith_reg_dest"
83 (match_code "subreg,reg")
84{
85 return arith_reg_dest (op, mode);
86})
87
c2acaf06
KH
88;; Like register_operand, but this predicate is defined with
89;; define_special_predicate, not define_predicate.
5546ac90
KH
90
91(define_special_predicate "any_register_operand"
92 (match_code "subreg,reg")
93{
94 return register_operand (op, mode);
95})
96
97;; Returns 1 if OP is a valid source operand for an arithmetic insn.
98
99(define_predicate "arith_operand"
100 (match_code "subreg,reg,const_int,truncate")
101{
102 if (arith_reg_operand (op, mode))
103 return 1;
104
105 if (TARGET_SHMEDIA)
106 {
107 /* FIXME: We should be checking whether the CONST_INT fits in a
32a7ab3d 108 signed 16-bit here, but this causes reload_cse to crash when
5546ac90
KH
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. */
f3536097 112 if (CONST_INT_P (op)
32a7ab3d 113 || satisfies_constraint_Css (op))
5546ac90
KH
114 return 1;
115 else if (GET_CODE (op) == TRUNCATE
f3536097 116 && REG_P (XEXP (op, 0))
5546ac90
KH
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);
124 else
125 return 0;
126 }
32a7ab3d 127 else if (satisfies_constraint_I08 (op))
5546ac90
KH
128 return 1;
129
130 return 0;
131})
132
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.
136
137(define_predicate "arith_reg_dest"
138 (match_code "subreg,reg")
139{
140 if (mode == DImode && GET_CODE (op) == SUBREG
141 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) < 8
142 && TARGET_SHMEDIA)
143 return 0;
144 return arith_reg_operand (op, mode);
145})
146
147;; Returns 1 if OP is a normal arithmetic register.
148
149(define_predicate "arith_reg_operand"
150 (match_code "subreg,reg,sign_extend")
151{
152 if (register_operand (op, mode))
153 {
154 int regno;
155
f3536097 156 if (REG_P (op))
5546ac90 157 regno = REGNO (op);
f3536097 158 else if (GET_CODE (op) == SUBREG && REG_P (SUBREG_REG (op)))
5546ac90
KH
159 regno = REGNO (SUBREG_REG (op));
160 else
161 return 1;
162
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);
167 }
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. */
171 if (TARGET_SHMEDIA
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
f3536097 179 && REG_P (XEXP (op, 0))
5546ac90
KH
180 && REGNO (XEXP (op, 0)) <= LAST_GENERAL_REG)
181 return register_operand (XEXP (op, 0), VOIDmode);
182#endif
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);
190 return 0;
191})
192
193;; Returns 1 if OP is a valid source operand for a compare insn.
194
195(define_predicate "arith_reg_or_0_operand"
196 (match_code "subreg,reg,const_int,const_vector")
197{
198 if (arith_reg_operand (op, mode))
199 return 1;
200
32a7ab3d 201 if (satisfies_constraint_Z (op))
5546ac90
KH
202 return 1;
203
204 return 0;
205})
206
207;; TODO: Add a comment here.
208
209(define_predicate "binary_float_operator"
f289c6a1
KH
210 (and (match_code "plus,minus,mult,div")
211 (match_test "GET_MODE (op) == mode")))
5546ac90
KH
212
213;; TODO: Add a comment here.
214
215(define_predicate "binary_logical_operator"
f289c6a1
KH
216 (and (match_code "and,ior,xor")
217 (match_test "GET_MODE (op) == mode")))
5546ac90 218
f705a9a0
R
219;; Return 1 of OP is an address suitable for a cache manipulation operation.
220;; MODE has the meaning as in address_operand.
5546ac90 221
f705a9a0 222(define_special_predicate "cache_address_operand"
5546ac90
KH
223 (match_code "plus,reg")
224{
225 if (GET_CODE (op) == PLUS)
226 {
f3536097 227 if (!REG_P (XEXP (op, 0)))
5546ac90 228 return 0;
f3536097 229 if (!CONST_INT_P (XEXP (op, 1))
5546ac90
KH
230 || (INTVAL (XEXP (op, 1)) & 31))
231 return 0;
232 }
f3536097 233 else if (!REG_P (op))
5546ac90
KH
234 return 0;
235 return address_operand (op, mode);
236})
237
238;; Return 1 if OP is a valid source operand for shmedia cmpgt / cmpgtu.
239
240(define_predicate "cmp_operand"
241 (match_code "subreg,reg,const_int")
242{
32a7ab3d 243 if (satisfies_constraint_N (op))
5546ac90
KH
244 return 1;
245 if (TARGET_SHMEDIA
246 && mode != DImode && GET_CODE (op) == SUBREG
247 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) > 4)
248 return 0;
249 return arith_reg_operand (op, mode);
250})
251
252;; TODO: Add a comment here.
253
254(define_predicate "cmpsi_operand"
255 (match_code "subreg,reg,const_int")
256{
f3536097 257 if (REG_P (op) && REGNO (op) == T_REG
5546ac90
KH
258 && GET_MODE (op) == SImode
259 && TARGET_SH1)
260 return 1;
261 return arith_operand (op, mode);
262})
263
264;; TODO: Add a comment here.
265
266(define_predicate "commutative_float_operator"
f289c6a1
KH
267 (and (match_code "plus,mult")
268 (match_test "GET_MODE (op) == mode")))
5546ac90
KH
269
270;; TODO: Add a comment here.
271
272(define_predicate "equality_comparison_operator"
f289c6a1 273 (match_code "eq,ne"))
5546ac90
KH
274
275;; TODO: Add a comment here.
276
277(define_predicate "extend_reg_operand"
278 (match_code "subreg,reg,truncate")
279{
280 return (GET_CODE (op) == TRUNCATE
281 ? arith_operand
282 : arith_reg_operand) (op, mode);
283})
284
285;; TODO: Add a comment here.
286
287(define_predicate "extend_reg_or_0_operand"
288 (match_code "subreg,reg,truncate,const_int")
289{
290 return (GET_CODE (op) == TRUNCATE
291 ? arith_operand
292 : arith_reg_or_0_operand) (op, mode);
293})
294
295;; Like arith_reg_operand, but this predicate does not accept SIGN_EXTEND.
296
297(define_predicate "ext_dest_operand"
298 (match_code "subreg,reg")
299{
300 return arith_reg_operand (op, mode);
301})
302
303;; TODO: Add a comment here.
304
305(define_predicate "fp_arith_reg_dest"
306 (match_code "subreg,reg")
307{
308 if (mode == DImode && GET_CODE (op) == SUBREG
309 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) < 8)
310 return 0;
311 return fp_arith_reg_operand (op, mode);
312})
313
314;; TODO: Add a comment here.
315
316(define_predicate "fp_arith_reg_operand"
317 (match_code "subreg,reg")
318{
319 if (register_operand (op, mode))
320 {
321 int regno;
322
f3536097 323 if (REG_P (op))
5546ac90 324 regno = REGNO (op);
f3536097 325 else if (GET_CODE (op) == SUBREG && REG_P (SUBREG_REG (op)))
5546ac90
KH
326 regno = REGNO (SUBREG_REG (op));
327 else
328 return 1;
329
330 return (regno >= FIRST_PSEUDO_REGISTER
331 || FP_REGISTER_P (regno));
332 }
333 return 0;
334})
335
336;; TODO: Add a comment here.
337
338(define_predicate "fpscr_operand"
339 (match_code "reg")
340{
f3536097 341 return (REG_P (op)
5546ac90
KH
342 && (REGNO (op) == FPSCR_REG
343 || (REGNO (op) >= FIRST_PSEUDO_REGISTER
344 && !(reload_in_progress || reload_completed)))
345 && GET_MODE (op) == PSImode);
346})
347
348;; TODO: Add a comment here.
349
350(define_predicate "fpul_operand"
351 (match_code "reg")
352{
353 if (TARGET_SHMEDIA)
354 return fp_arith_reg_operand (op, mode);
355
f3536097 356 return (REG_P (op)
5546ac90
KH
357 && (REGNO (op) == FPUL_REG || REGNO (op) >= FIRST_PSEUDO_REGISTER)
358 && GET_MODE (op) == mode);
359})
360
361;; TODO: Add a comment here.
362
363(define_predicate "general_extend_operand"
364 (match_code "subreg,reg,mem,truncate")
365{
366 return (GET_CODE (op) == TRUNCATE
367 ? arith_operand
368 : nonimmediate_operand) (op, mode);
369})
370
33344a62
OE
371;; Returns 1 if the operand can be used in a zero_extend.
372(define_predicate "zero_extend_operand"
373 (ior (and (match_test "TARGET_SHMEDIA")
374 (match_operand 0 "general_extend_operand"))
375 (and (match_test "! TARGET_SHMEDIA")
376 (match_operand 0 "arith_reg_operand"))))
377
5546ac90
KH
378;; Returns 1 if OP can be source of a simple move operation. Same as
379;; general_operand, but a LABEL_REF is valid, PRE_DEC is invalid as
380;; are subregs of system registers.
381
382(define_predicate "general_movsrc_operand"
383 (match_code "subreg,reg,const_int,const_double,mem,symbol_ref,label_ref,const,const_vector")
384{
f3536097 385 if (MEM_P (op))
5546ac90
KH
386 {
387 rtx inside = XEXP (op, 0);
388 if (GET_CODE (inside) == CONST)
389 inside = XEXP (inside, 0);
390
391 if (GET_CODE (inside) == LABEL_REF)
392 return 1;
393
394 if (GET_CODE (inside) == PLUS
395 && GET_CODE (XEXP (inside, 0)) == LABEL_REF
f3536097 396 && CONST_INT_P (XEXP (inside, 1)))
5546ac90
KH
397 return 1;
398
399 /* Only post inc allowed. */
400 if (GET_CODE (inside) == PRE_DEC)
401 return 0;
402 }
403
a700b5f0 404 if ((mode == QImode || mode == HImode)
409fed48 405 && mode == GET_MODE (op)
a700b5f0
KK
406 && (MEM_P (op)
407 || (GET_CODE (op) == SUBREG && MEM_P (SUBREG_REG (op)))))
408 {
409 rtx x = XEXP ((MEM_P (op) ? op : SUBREG_REG (op)), 0);
410
411 if (GET_CODE (x) == PLUS
412 && REG_P (XEXP (x, 0))
413 && CONST_INT_P (XEXP (x, 1)))
8c2a3f3b 414 return sh_legitimate_index_p (mode, XEXP (x, 1), TARGET_SH2A, false);
a700b5f0
KK
415 }
416
5546ac90
KH
417 if (TARGET_SHMEDIA
418 && (GET_CODE (op) == PARALLEL || GET_CODE (op) == CONST_VECTOR)
419 && sh_rep_vec (op, mode))
420 return 1;
421 if (TARGET_SHMEDIA && 1
422 && GET_CODE (op) == SUBREG && GET_MODE (op) == mode
423 && SUBREG_REG (op) == const0_rtx && subreg_lowpart_p (op))
424 /* FIXME */ abort (); /* return 1; */
425 return general_operand (op, mode);
426})
427
344332e8
OE
428;; Same as movsrc_operand, but rejects displacement addressing.
429
430(define_predicate "movsrc_no_disp_mem_operand"
431 (match_code "subreg,reg,const_int,const_double,mem,symbol_ref,label_ref,const,const_vector")
432{
433 if (!general_movsrc_operand (op, mode))
434 return 0;
435
436 if ((mode == QImode || mode == HImode)
437 && mode == GET_MODE (op)
438 && (MEM_P (op)
439 || (GET_CODE (op) == SUBREG && MEM_P (SUBREG_REG (op)))))
440 {
441 rtx x = XEXP ((MEM_P (op) ? op : SUBREG_REG (op)), 0);
442
443 if (GET_CODE (x) == PLUS
444 && REG_P (XEXP (x, 0))
445 && CONST_INT_P (XEXP (x, 1)))
446 return 0;
447 }
448
449 return 1;
450})
451
5546ac90
KH
452;; Returns 1 if OP can be a destination of a move. Same as
453;; general_operand, but no preinc allowed.
454
455(define_predicate "general_movdst_operand"
456 (match_code "subreg,reg,mem")
457{
458 /* Only pre dec allowed. */
f3536097 459 if (MEM_P (op) && GET_CODE (XEXP (op, 0)) == POST_INC)
5546ac90
KH
460 return 0;
461 if (mode == DImode && TARGET_SHMEDIA && GET_CODE (op) == SUBREG
462 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) < 8
fae61228 463 && ! (reload_in_progress || reload_completed))
5546ac90
KH
464 return 0;
465
a700b5f0 466 if ((mode == QImode || mode == HImode)
409fed48 467 && mode == GET_MODE (op)
a700b5f0
KK
468 && (MEM_P (op)
469 || (GET_CODE (op) == SUBREG && MEM_P (SUBREG_REG (op)))))
470 {
471 rtx x = XEXP ((MEM_P (op) ? op : SUBREG_REG (op)), 0);
472
473 if (GET_CODE (x) == PLUS
474 && REG_P (XEXP (x, 0))
475 && CONST_INT_P (XEXP (x, 1)))
8c2a3f3b 476 return sh_legitimate_index_p (mode, XEXP (x, 1), TARGET_SH2A, false);
a700b5f0
KK
477 }
478
5546ac90
KH
479 return general_operand (op, mode);
480})
481
c11c09f9
KP
482;; Returns 1 if OP is a POST_INC on stack pointer register.
483
484(define_predicate "sh_no_delay_pop_operand"
485 (match_code "mem")
486{
487 rtx inside;
488 inside = XEXP (op, 0);
489
490 if (GET_CODE (op) == MEM && GET_MODE (op) == SImode
491 && GET_CODE (inside) == POST_INC
492 && GET_CODE (XEXP (inside, 0)) == REG
493 && REGNO (XEXP (inside, 0)) == SP_REG)
494 return 1;
495
496 return 0;
497})
498
5546ac90
KH
499;; Returns 1 if OP is a MEM that can be source of a simple move operation.
500
501(define_predicate "unaligned_load_operand"
502 (match_code "mem")
503{
504 rtx inside;
505
f3536097 506 if (!MEM_P (op) || GET_MODE (op) != mode)
5546ac90
KH
507 return 0;
508
509 inside = XEXP (op, 0);
510
511 if (GET_CODE (inside) == POST_INC)
512 inside = XEXP (inside, 0);
513
f3536097 514 if (REG_P (inside))
5546ac90
KH
515 return 1;
516
517 return 0;
518})
519
520;; TODO: Add a comment here.
521
522(define_predicate "greater_comparison_operator"
f289c6a1 523 (match_code "gt,ge,gtu,geu"))
5546ac90
KH
524
525;; TODO: Add a comment here.
526
527(define_predicate "inqhi_operand"
528 (match_code "truncate")
529{
530 if (GET_CODE (op) != TRUNCATE || mode != GET_MODE (op))
531 return 0;
532 op = XEXP (op, 0);
533 /* Can't use true_regnum here because copy_cost wants to know about
534 SECONDARY_INPUT_RELOAD_CLASS. */
f3536097 535 return REG_P (op) && FP_REGISTER_P (REGNO (op));
5546ac90
KH
536})
537
538;; TODO: Add a comment here.
539
540(define_special_predicate "int_gpr_dest"
541 (match_code "subreg,reg")
542{
543 enum machine_mode op_mode = GET_MODE (op);
544
545 if (GET_MODE_CLASS (op_mode) != MODE_INT
546 || GET_MODE_SIZE (op_mode) >= UNITS_PER_WORD)
547 return 0;
548 if (! reload_completed)
549 return 0;
550 return true_regnum (op) <= LAST_GENERAL_REG;
551})
552
553;; TODO: Add a comment here.
554
555(define_predicate "less_comparison_operator"
f289c6a1 556 (match_code "lt,le,ltu,leu"))
5546ac90
KH
557
558;; Returns 1 if OP is a valid source operand for a logical operation.
559
560(define_predicate "logical_operand"
561 (match_code "subreg,reg,const_int")
562{
563 if (TARGET_SHMEDIA
564 && mode != DImode && GET_CODE (op) == SUBREG
565 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) > 4)
566 return 0;
567
568 if (arith_reg_operand (op, mode))
569 return 1;
570
571 if (TARGET_SHMEDIA)
572 {
32a7ab3d 573 if (satisfies_constraint_I10 (op))
5546ac90
KH
574 return 1;
575 else
576 return 0;
577 }
32a7ab3d 578 else if (satisfies_constraint_K08 (op))
5546ac90
KH
579 return 1;
580
581 return 0;
582})
583
5e204a6e
OE
584;; Like logical_operand but allows additional constant values which can be
585;; done with zero extensions. Used for the second operand of and insns.
586(define_predicate "logical_and_operand"
587 (match_code "subreg,reg,const_int")
588{
589 if (logical_operand (op, mode))
590 return 1;
591
592 if (! TARGET_SHMEDIA
593 && (satisfies_constraint_Jmb (op) || satisfies_constraint_Jmw (op)))
594 return 1;
595
596 return 0;
597})
598
5546ac90
KH
599;; TODO: Add a comment here.
600
601(define_predicate "logical_operator"
f289c6a1 602 (match_code "and,ior,xor"))
5546ac90
KH
603
604;; Like arith_reg_operand, but for register source operands of narrow
605;; logical SHMEDIA operations: forbid subregs of DImode / TImode regs.
606
607(define_predicate "logical_reg_operand"
608 (match_code "subreg,reg")
609{
610 if (TARGET_SHMEDIA
611 && GET_CODE (op) == SUBREG
612 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) > 4
613 && mode != DImode)
614 return 0;
615 return arith_reg_operand (op, mode);
616})
617
618;; TODO: Add a comment here.
619
620(define_predicate "mextr_bit_offset"
621 (match_code "const_int")
622{
623 HOST_WIDE_INT i;
624
f3536097 625 if (!CONST_INT_P (op))
5546ac90
KH
626 return 0;
627 i = INTVAL (op);
628 return i >= 1 * 8 && i <= 7 * 8 && (i & 7) == 0;
629})
630
631;; TODO: Add a comment here.
632
633(define_predicate "minuend_operand"
634 (match_code "subreg,reg,truncate,const_int")
635{
636 return op == constm1_rtx || extend_reg_or_0_operand (op, mode);
637})
638
639;; TODO: Add a comment here.
640
641(define_predicate "noncommutative_float_operator"
f289c6a1
KH
642 (and (match_code "minus,div")
643 (match_test "GET_MODE (op) == mode")))
5546ac90 644
f90b7a5a
PB
645;; UNORDERED is only supported on SHMEDIA.
646
647(define_predicate "sh_float_comparison_operator"
648 (ior (match_operand 0 "ordered_comparison_operator")
649 (and (match_test "TARGET_SHMEDIA")
650 (match_code "unordered"))))
651
652(define_predicate "shmedia_cbranch_comparison_operator"
653 (ior (match_operand 0 "equality_comparison_operator")
654 (match_operand 0 "greater_comparison_operator")))
655
5546ac90
KH
656;; TODO: Add a comment here.
657
658(define_predicate "sh_const_vec"
659 (match_code "const_vector")
660{
661 int i;
662
663 if (GET_CODE (op) != CONST_VECTOR
664 || (GET_MODE (op) != mode && mode != VOIDmode))
665 return 0;
666 i = XVECLEN (op, 0) - 1;
667 for (; i >= 0; i--)
f3536097 668 if (!CONST_INT_P (XVECEXP (op, 0, i)))
5546ac90
KH
669 return 0;
670 return 1;
671})
672
673;; Determine if OP is a constant vector matching MODE with only one
674;; element that is not a sign extension. Two byte-sized elements
675;; count as one.
676
677(define_predicate "sh_1el_vec"
678 (match_code "const_vector")
679{
680 int unit_size;
681 int i, last, least, sign_ix;
682 rtx sign;
683
684 if (GET_CODE (op) != CONST_VECTOR
685 || (GET_MODE (op) != mode && mode != VOIDmode))
686 return 0;
687 /* Determine numbers of last and of least significant elements. */
688 last = XVECLEN (op, 0) - 1;
689 least = TARGET_LITTLE_ENDIAN ? 0 : last;
f3536097 690 if (!CONST_INT_P (XVECEXP (op, 0, least)))
5546ac90
KH
691 return 0;
692 sign_ix = least;
693 if (GET_MODE_UNIT_SIZE (mode) == 1)
694 sign_ix = TARGET_LITTLE_ENDIAN ? 1 : last - 1;
f3536097 695 if (!CONST_INT_P (XVECEXP (op, 0, sign_ix)))
5546ac90
KH
696 return 0;
697 unit_size = GET_MODE_UNIT_SIZE (GET_MODE (op));
698 sign = (INTVAL (XVECEXP (op, 0, sign_ix)) >> (unit_size * BITS_PER_UNIT - 1)
699 ? constm1_rtx : const0_rtx);
700 i = XVECLEN (op, 0) - 1;
701 do
702 if (i != least && i != sign_ix && XVECEXP (op, 0, i) != sign)
703 return 0;
704 while (--i);
705 return 1;
706})
707
708;; Like register_operand, but take into account that SHMEDIA can use
709;; the constant zero like a general register.
710
711(define_predicate "sh_register_operand"
ac42ec79 712 (match_code "reg,subreg,const_int,const_double")
5546ac90
KH
713{
714 if (op == CONST0_RTX (mode) && TARGET_SHMEDIA)
715 return 1;
716 return register_operand (op, mode);
717})
718
719;; TODO: Add a comment here.
720
721(define_predicate "sh_rep_vec"
b4060d3f 722 (match_code "const_vector,parallel")
5546ac90
KH
723{
724 int i;
725 rtx x, y;
726
727 if ((GET_CODE (op) != CONST_VECTOR && GET_CODE (op) != PARALLEL)
728 || (GET_MODE (op) != mode && mode != VOIDmode))
729 return 0;
730 i = XVECLEN (op, 0) - 2;
731 x = XVECEXP (op, 0, i + 1);
732 if (GET_MODE_UNIT_SIZE (mode) == 1)
733 {
734 y = XVECEXP (op, 0, i);
735 for (i -= 2; i >= 0; i -= 2)
736 if (! rtx_equal_p (XVECEXP (op, 0, i + 1), x)
737 || ! rtx_equal_p (XVECEXP (op, 0, i), y))
738 return 0;
739 }
740 else
741 for (; i >= 0; i--)
742 if (XVECEXP (op, 0, i) != x)
743 return 0;
744 return 1;
745})
746
747;; TODO: Add a comment here.
748
749(define_predicate "shift_count_operand"
750 (match_code "const_int,const_double,const,symbol_ref,label_ref,subreg,reg,zero_extend,sign_extend")
751{
752 return (CONSTANT_P (op)
f3536097 753 ? (CONST_INT_P (op)
5546ac90
KH
754 ? (unsigned) INTVAL (op) < GET_MODE_BITSIZE (mode)
755 : nonmemory_operand (op, mode))
756 : shift_count_reg_operand (op, mode));
757})
758
759;; TODO: Add a comment here.
760
761(define_predicate "shift_count_reg_operand"
762 (match_code "subreg,reg,zero_extend,sign_extend")
763{
764 if ((GET_CODE (op) == ZERO_EXTEND || GET_CODE (op) == SIGN_EXTEND
765 || (GET_CODE (op) == SUBREG && SUBREG_BYTE (op) == 0))
766 && (mode == VOIDmode || mode == GET_MODE (op))
767 && GET_MODE_BITSIZE (GET_MODE (XEXP (op, 0))) >= 6
768 && GET_MODE_CLASS (GET_MODE (XEXP (op, 0))) == MODE_INT)
769 {
770 mode = VOIDmode;
771 do
772 op = XEXP (op, 0);
773 while ((GET_CODE (op) == ZERO_EXTEND || GET_CODE (op) == SIGN_EXTEND
774 || GET_CODE (op) == TRUNCATE)
775 && GET_MODE_BITSIZE (GET_MODE (XEXP (op, 0))) >= 6
776 && GET_MODE_CLASS (GET_MODE (XEXP (op, 0))) == MODE_INT);
777
778 }
779 return arith_reg_operand (op, mode);
780})
781
782;; TODO: Add a comment here.
783
784(define_predicate "shift_operator"
f289c6a1 785 (match_code "ashift,ashiftrt,lshiftrt"))
5546ac90
KH
786
787;; TODO: Add a comment here.
788
789(define_predicate "symbol_ref_operand"
f289c6a1 790 (match_code "symbol_ref"))
5546ac90
KH
791
792;; Same as target_reg_operand, except that label_refs and symbol_refs
793;; are accepted before reload.
794
795(define_special_predicate "target_operand"
796 (match_code "subreg,reg,label_ref,symbol_ref,const,unspec")
797{
798 if (mode != VOIDmode && mode != Pmode)
799 return 0;
800
801 if ((GET_MODE (op) == Pmode || GET_MODE (op) == VOIDmode)
32a7ab3d 802 && satisfies_constraint_Csy (op))
5546ac90
KH
803 return ! reload_completed;
804
805 return target_reg_operand (op, mode);
806})
807
808;; Accept pseudos and branch target registers.
809
810(define_special_predicate "target_reg_operand"
811 (match_code "subreg,reg")
812{
813 if (mode == VOIDmode
814 ? GET_MODE (op) != Pmode && GET_MODE (op) != PDImode
815 : mode != GET_MODE (op))
816 return 0;
817
818 if (GET_CODE (op) == SUBREG)
819 op = XEXP (op, 0);
820
f3536097 821 if (!REG_P (op))
5546ac90
KH
822 return 0;
823
824 /* We must protect ourselves from matching pseudos that are virtual
825 register, because they will eventually be replaced with hardware
826 registers that aren't branch-target registers. */
827 if (REGNO (op) > LAST_VIRTUAL_REGISTER
828 || TARGET_REGISTER_P (REGNO (op)))
829 return 1;
830
831 return 0;
832})
833
834;; TODO: Add a comment here.
835
836(define_special_predicate "trunc_hi_operand"
837 (match_code "subreg,reg,truncate")
838{
839 enum machine_mode op_mode = GET_MODE (op);
840
841 if (op_mode != SImode && op_mode != DImode
842 && op_mode != V4HImode && op_mode != V2SImode)
843 return 0;
844 return extend_reg_operand (op, mode);
845})
846
f705a9a0 847;; Return 1 of OP is an address suitable for an unaligned access instruction.
5546ac90 848
f705a9a0 849(define_special_predicate "ua_address_operand"
5546ac90
KH
850 (match_code "subreg,reg,plus")
851{
852 if (GET_CODE (op) == PLUS
32a7ab3d 853 && (! satisfies_constraint_I06 (XEXP (op, 1))))
5546ac90
KH
854 return 0;
855 return address_operand (op, QImode);
856})
857
858;; TODO: Add a comment here.
859
860(define_predicate "ua_offset"
861 (match_code "const_int")
862{
32a7ab3d 863 return satisfies_constraint_I06 (op);
5546ac90
KH
864})
865
866;; TODO: Add a comment here.
867
868(define_predicate "unary_float_operator"
f289c6a1
KH
869 (and (match_code "abs,neg,sqrt")
870 (match_test "GET_MODE (op) == mode")))
5546ac90
KH
871
872;; Return 1 if OP is a valid source operand for xor.
873
874(define_predicate "xor_operand"
875 (match_code "subreg,reg,const_int")
876{
f3536097 877 if (CONST_INT_P (op))
5546ac90 878 return (TARGET_SHMEDIA
32a7ab3d 879 ? (satisfies_constraint_I06 (op)
b3a13419 880 || (!can_create_pseudo_p () && INTVAL (op) == 0xff))
32a7ab3d 881 : satisfies_constraint_K08 (op));
5546ac90
KH
882 if (TARGET_SHMEDIA
883 && mode != DImode && GET_CODE (op) == SUBREG
884 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) > 4)
885 return 0;
886 return arith_reg_operand (op, mode);
887})
9eb3a0dd
N
888
889(define_predicate "bitwise_memory_operand"
890 (match_code "mem")
891{
f3536097 892 if (MEM_P (op))
9eb3a0dd
N
893 {
894 if (REG_P (XEXP (op, 0)))
895 return 1;
896
897 if (GET_CODE (XEXP (op, 0)) == PLUS
f3536097 898 && REG_P (XEXP (XEXP (op, 0), 0))
9eb3a0dd
N
899 && satisfies_constraint_K12 (XEXP (XEXP (op, 0), 1)))
900 return 1;
901 }
902 return 0;
903})
c11394f8
OE
904
905;; The atomic_* operand predicates are used for the atomic patterns.
906;; Depending on the particular pattern some operands can be immediate
907;; values. Using these predicates avoids the usage of 'force_reg' in the
908;; expanders.
909(define_predicate "atomic_arith_operand"
910 (ior (match_code "subreg,reg")
911 (and (match_test "satisfies_constraint_I08 (op)")
912 (match_test "mode != QImode")
913 (match_test "mode != HImode")
914 (match_test "TARGET_SH4A_ARCH"))))
915
916(define_predicate "atomic_logical_operand"
917 (ior (match_code "subreg,reg")
918 (and (match_test "satisfies_constraint_K08 (op)")
919 (match_test "mode != QImode")
920 (match_test "mode != HImode")
921 (match_test "TARGET_SH4A_ARCH"))))
922
f031c344
OE
923;; A predicate describing the T bit register in any form.
924(define_predicate "t_reg_operand"
925 (match_code "reg,subreg,sign_extend,zero_extend")
926{
927 switch (GET_CODE (op))
928 {
929 case REG:
930 return REGNO (op) == T_REG;
931
932 case SUBREG:
933 return REGNO (SUBREG_REG (op)) == T_REG;
934
935 case ZERO_EXTEND:
936 case SIGN_EXTEND:
937 return GET_CODE (XEXP (op, 0)) == SUBREG
938 && REGNO (SUBREG_REG (XEXP (op, 0))) == T_REG;
939
940 default:
941 return 0;
942 }
943})
944
945;; A predicate describing a negated T bit register.
946(define_predicate "negt_reg_operand"
947 (match_code "subreg,xor")
948{
949 switch (GET_CODE (op))
950 {
951 case XOR:
952 return t_reg_operand (XEXP (op, 0), GET_MODE (XEXP (op, 0)))
953 && satisfies_constraint_M (XEXP (op, 1));
954
955 case SUBREG:
956 return negt_reg_operand (XEXP (op, 0), GET_MODE (XEXP (op, 0)));
957
958 default:
959 return 0;
960 }
961})