]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/sh/predicates.md
Daily bump.
[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
24c18ad8
OE
371;; Returns 1 if OP is a simple register address.
372(define_predicate "simple_mem_operand"
373 (and (match_code "mem")
374 (match_test "arith_reg_operand (XEXP (op, 0), SImode)")))
375
376;; Returns 1 if OP is a valid displacement address.
377(define_predicate "displacement_mem_operand"
378 (and (match_code "mem")
379 (match_test "GET_CODE (XEXP (op, 0)) == PLUS")
380 (match_test "arith_reg_operand (XEXP (XEXP (op, 0), 0), SImode)")
381 (match_test "sh_legitimate_index_p (GET_MODE (op),
382 XEXP (XEXP (op, 0), 1),
383 TARGET_SH2A, true)")))
384
385;; Returns 1 if the operand can be used in an SH2A movu.{b|w} insn.
386(define_predicate "zero_extend_movu_operand"
387 (and (match_operand 0 "displacement_mem_operand")
388 (match_test "GET_MODE (op) == QImode || GET_MODE (op) == HImode")))
389
33344a62
OE
390;; Returns 1 if the operand can be used in a zero_extend.
391(define_predicate "zero_extend_operand"
392 (ior (and (match_test "TARGET_SHMEDIA")
393 (match_operand 0 "general_extend_operand"))
394 (and (match_test "! TARGET_SHMEDIA")
24c18ad8
OE
395 (match_operand 0 "arith_reg_operand"))
396 (and (match_test "TARGET_SH2A")
397 (match_operand 0 "zero_extend_movu_operand"))))
33344a62 398
5546ac90
KH
399;; Returns 1 if OP can be source of a simple move operation. Same as
400;; general_operand, but a LABEL_REF is valid, PRE_DEC is invalid as
401;; are subregs of system registers.
402
403(define_predicate "general_movsrc_operand"
404 (match_code "subreg,reg,const_int,const_double,mem,symbol_ref,label_ref,const,const_vector")
405{
ef812306
OE
406 if (t_reg_operand (op, mode))
407 return 0;
408
f3536097 409 if (MEM_P (op))
5546ac90
KH
410 {
411 rtx inside = XEXP (op, 0);
fce1e5fb
OE
412
413 /* Disallow mems with GBR address here. They have to go through
414 separate special patterns. */
415 if ((REG_P (inside) && REGNO (inside) == GBR_REG)
416 || (GET_CODE (inside) == PLUS && REG_P (XEXP (inside, 0))
417 && REGNO (XEXP (inside, 0)) == GBR_REG))
418 return 0;
419
5546ac90
KH
420 if (GET_CODE (inside) == CONST)
421 inside = XEXP (inside, 0);
422
423 if (GET_CODE (inside) == LABEL_REF)
424 return 1;
425
426 if (GET_CODE (inside) == PLUS
427 && GET_CODE (XEXP (inside, 0)) == LABEL_REF
f3536097 428 && CONST_INT_P (XEXP (inside, 1)))
5546ac90
KH
429 return 1;
430
431 /* Only post inc allowed. */
432 if (GET_CODE (inside) == PRE_DEC)
433 return 0;
434 }
435
a700b5f0 436 if ((mode == QImode || mode == HImode)
409fed48 437 && mode == GET_MODE (op)
a700b5f0
KK
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)))
8c2a3f3b 446 return sh_legitimate_index_p (mode, XEXP (x, 1), TARGET_SH2A, false);
a700b5f0
KK
447 }
448
5546ac90
KH
449 if (TARGET_SHMEDIA
450 && (GET_CODE (op) == PARALLEL || GET_CODE (op) == CONST_VECTOR)
451 && sh_rep_vec (op, mode))
452 return 1;
453 if (TARGET_SHMEDIA && 1
454 && GET_CODE (op) == SUBREG && GET_MODE (op) == mode
455 && SUBREG_REG (op) == const0_rtx && subreg_lowpart_p (op))
456 /* FIXME */ abort (); /* return 1; */
457 return general_operand (op, mode);
458})
459
284c32cf 460;; Returns 1 if OP is a MEM that does not use displacement addressing.
344332e8
OE
461
462(define_predicate "movsrc_no_disp_mem_operand"
284c32cf 463 (match_code "mem")
344332e8 464{
284c32cf 465 return general_movsrc_operand (op, mode) && satisfies_constraint_Snd (op);
344332e8
OE
466})
467
5546ac90
KH
468;; Returns 1 if OP can be a destination of a move. Same as
469;; general_operand, but no preinc allowed.
470
471(define_predicate "general_movdst_operand"
472 (match_code "subreg,reg,mem")
473{
ef812306
OE
474 if (t_reg_operand (op, mode))
475 return 0;
476
fce1e5fb
OE
477 if (MEM_P (op))
478 {
479 rtx inside = XEXP (op, 0);
480 /* Disallow mems with GBR address here. They have to go through
481 separate special patterns. */
482 if ((REG_P (inside) && REGNO (inside) == GBR_REG)
483 || (GET_CODE (inside) == PLUS && REG_P (XEXP (inside, 0))
484 && REGNO (XEXP (inside, 0)) == GBR_REG))
485 return 0;
486 }
487
5546ac90 488 /* Only pre dec allowed. */
f3536097 489 if (MEM_P (op) && GET_CODE (XEXP (op, 0)) == POST_INC)
5546ac90
KH
490 return 0;
491 if (mode == DImode && TARGET_SHMEDIA && GET_CODE (op) == SUBREG
492 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) < 8
fae61228 493 && ! (reload_in_progress || reload_completed))
5546ac90
KH
494 return 0;
495
a700b5f0 496 if ((mode == QImode || mode == HImode)
409fed48 497 && mode == GET_MODE (op)
a700b5f0
KK
498 && (MEM_P (op)
499 || (GET_CODE (op) == SUBREG && MEM_P (SUBREG_REG (op)))))
500 {
501 rtx x = XEXP ((MEM_P (op) ? op : SUBREG_REG (op)), 0);
502
503 if (GET_CODE (x) == PLUS
504 && REG_P (XEXP (x, 0))
505 && CONST_INT_P (XEXP (x, 1)))
8c2a3f3b 506 return sh_legitimate_index_p (mode, XEXP (x, 1), TARGET_SH2A, false);
a700b5f0
KK
507 }
508
5546ac90
KH
509 return general_operand (op, mode);
510})
511
c11c09f9
KP
512;; Returns 1 if OP is a POST_INC on stack pointer register.
513
514(define_predicate "sh_no_delay_pop_operand"
515 (match_code "mem")
516{
517 rtx inside;
518 inside = XEXP (op, 0);
519
520 if (GET_CODE (op) == MEM && GET_MODE (op) == SImode
521 && GET_CODE (inside) == POST_INC
522 && GET_CODE (XEXP (inside, 0)) == REG
523 && REGNO (XEXP (inside, 0)) == SP_REG)
524 return 1;
525
526 return 0;
527})
528
5546ac90
KH
529;; Returns 1 if OP is a MEM that can be source of a simple move operation.
530
531(define_predicate "unaligned_load_operand"
532 (match_code "mem")
533{
534 rtx inside;
535
f3536097 536 if (!MEM_P (op) || GET_MODE (op) != mode)
5546ac90
KH
537 return 0;
538
539 inside = XEXP (op, 0);
540
541 if (GET_CODE (inside) == POST_INC)
542 inside = XEXP (inside, 0);
543
f3536097 544 if (REG_P (inside))
5546ac90
KH
545 return 1;
546
547 return 0;
548})
549
b67b3838
OE
550;; Returns 1 if OP is a MEM that can be used in "index_disp" combiner
551;; patterns.
552(define_predicate "mem_index_disp_operand"
553 (match_code "mem")
554{
555 rtx plus0_rtx, plus1_rtx, mult_rtx;
556
557 plus0_rtx = XEXP (op, 0);
558 if (GET_CODE (plus0_rtx) != PLUS)
559 return 0;
560
561 plus1_rtx = XEXP (plus0_rtx, 0);
562 if (GET_CODE (plus1_rtx) != PLUS)
563 return 0;
05852a5f
OE
564 if (! arith_reg_operand (XEXP (plus1_rtx, 1), GET_MODE (XEXP (plus1_rtx, 1))))
565 return 0;
b67b3838
OE
566
567 mult_rtx = XEXP (plus1_rtx, 0);
568 if (GET_CODE (mult_rtx) != MULT)
569 return 0;
05852a5f
OE
570 if (! arith_reg_operand (XEXP (mult_rtx, 0), GET_MODE (XEXP (mult_rtx, 0)))
571 || ! CONST_INT_P (XEXP (mult_rtx, 1)))
572 return 0;
573
574 return exact_log2 (INTVAL (XEXP (mult_rtx, 1))) > 0
b67b3838
OE
575 && sh_legitimate_index_p (mode, XEXP (plus0_rtx, 1), TARGET_SH2A, true);
576})
577
5546ac90
KH
578;; TODO: Add a comment here.
579
580(define_predicate "greater_comparison_operator"
f289c6a1 581 (match_code "gt,ge,gtu,geu"))
5546ac90
KH
582
583;; TODO: Add a comment here.
584
585(define_predicate "inqhi_operand"
586 (match_code "truncate")
587{
588 if (GET_CODE (op) != TRUNCATE || mode != GET_MODE (op))
589 return 0;
590 op = XEXP (op, 0);
591 /* Can't use true_regnum here because copy_cost wants to know about
592 SECONDARY_INPUT_RELOAD_CLASS. */
f3536097 593 return REG_P (op) && FP_REGISTER_P (REGNO (op));
5546ac90
KH
594})
595
596;; TODO: Add a comment here.
597
598(define_special_predicate "int_gpr_dest"
599 (match_code "subreg,reg")
600{
601 enum machine_mode op_mode = GET_MODE (op);
602
603 if (GET_MODE_CLASS (op_mode) != MODE_INT
604 || GET_MODE_SIZE (op_mode) >= UNITS_PER_WORD)
605 return 0;
606 if (! reload_completed)
607 return 0;
608 return true_regnum (op) <= LAST_GENERAL_REG;
609})
610
611;; TODO: Add a comment here.
612
613(define_predicate "less_comparison_operator"
f289c6a1 614 (match_code "lt,le,ltu,leu"))
5546ac90
KH
615
616;; Returns 1 if OP is a valid source operand for a logical operation.
617
618(define_predicate "logical_operand"
619 (match_code "subreg,reg,const_int")
620{
621 if (TARGET_SHMEDIA
622 && mode != DImode && GET_CODE (op) == SUBREG
623 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) > 4)
624 return 0;
625
626 if (arith_reg_operand (op, mode))
627 return 1;
628
629 if (TARGET_SHMEDIA)
630 {
32a7ab3d 631 if (satisfies_constraint_I10 (op))
5546ac90
KH
632 return 1;
633 else
634 return 0;
635 }
32a7ab3d 636 else if (satisfies_constraint_K08 (op))
5546ac90
KH
637 return 1;
638
639 return 0;
640})
641
5e204a6e
OE
642;; Like logical_operand but allows additional constant values which can be
643;; done with zero extensions. Used for the second operand of and insns.
644(define_predicate "logical_and_operand"
645 (match_code "subreg,reg,const_int")
646{
647 if (logical_operand (op, mode))
648 return 1;
649
650 if (! TARGET_SHMEDIA
651 && (satisfies_constraint_Jmb (op) || satisfies_constraint_Jmw (op)))
652 return 1;
653
654 return 0;
655})
656
5546ac90
KH
657;; TODO: Add a comment here.
658
659(define_predicate "logical_operator"
f289c6a1 660 (match_code "and,ior,xor"))
5546ac90
KH
661
662;; Like arith_reg_operand, but for register source operands of narrow
663;; logical SHMEDIA operations: forbid subregs of DImode / TImode regs.
664
665(define_predicate "logical_reg_operand"
666 (match_code "subreg,reg")
667{
668 if (TARGET_SHMEDIA
669 && GET_CODE (op) == SUBREG
670 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) > 4
671 && mode != DImode)
672 return 0;
673 return arith_reg_operand (op, mode);
674})
675
676;; TODO: Add a comment here.
677
678(define_predicate "mextr_bit_offset"
679 (match_code "const_int")
680{
681 HOST_WIDE_INT i;
682
f3536097 683 if (!CONST_INT_P (op))
5546ac90
KH
684 return 0;
685 i = INTVAL (op);
686 return i >= 1 * 8 && i <= 7 * 8 && (i & 7) == 0;
687})
688
689;; TODO: Add a comment here.
690
691(define_predicate "minuend_operand"
692 (match_code "subreg,reg,truncate,const_int")
693{
694 return op == constm1_rtx || extend_reg_or_0_operand (op, mode);
695})
696
697;; TODO: Add a comment here.
698
699(define_predicate "noncommutative_float_operator"
f289c6a1
KH
700 (and (match_code "minus,div")
701 (match_test "GET_MODE (op) == mode")))
5546ac90 702
f90b7a5a
PB
703;; UNORDERED is only supported on SHMEDIA.
704
705(define_predicate "sh_float_comparison_operator"
706 (ior (match_operand 0 "ordered_comparison_operator")
707 (and (match_test "TARGET_SHMEDIA")
708 (match_code "unordered"))))
709
710(define_predicate "shmedia_cbranch_comparison_operator"
711 (ior (match_operand 0 "equality_comparison_operator")
712 (match_operand 0 "greater_comparison_operator")))
713
5546ac90
KH
714;; TODO: Add a comment here.
715
716(define_predicate "sh_const_vec"
717 (match_code "const_vector")
718{
719 int i;
720
721 if (GET_CODE (op) != CONST_VECTOR
722 || (GET_MODE (op) != mode && mode != VOIDmode))
723 return 0;
724 i = XVECLEN (op, 0) - 1;
725 for (; i >= 0; i--)
f3536097 726 if (!CONST_INT_P (XVECEXP (op, 0, i)))
5546ac90
KH
727 return 0;
728 return 1;
729})
730
731;; Determine if OP is a constant vector matching MODE with only one
732;; element that is not a sign extension. Two byte-sized elements
733;; count as one.
734
735(define_predicate "sh_1el_vec"
736 (match_code "const_vector")
737{
738 int unit_size;
739 int i, last, least, sign_ix;
740 rtx sign;
741
742 if (GET_CODE (op) != CONST_VECTOR
743 || (GET_MODE (op) != mode && mode != VOIDmode))
744 return 0;
745 /* Determine numbers of last and of least significant elements. */
746 last = XVECLEN (op, 0) - 1;
747 least = TARGET_LITTLE_ENDIAN ? 0 : last;
f3536097 748 if (!CONST_INT_P (XVECEXP (op, 0, least)))
5546ac90
KH
749 return 0;
750 sign_ix = least;
751 if (GET_MODE_UNIT_SIZE (mode) == 1)
752 sign_ix = TARGET_LITTLE_ENDIAN ? 1 : last - 1;
f3536097 753 if (!CONST_INT_P (XVECEXP (op, 0, sign_ix)))
5546ac90
KH
754 return 0;
755 unit_size = GET_MODE_UNIT_SIZE (GET_MODE (op));
756 sign = (INTVAL (XVECEXP (op, 0, sign_ix)) >> (unit_size * BITS_PER_UNIT - 1)
757 ? constm1_rtx : const0_rtx);
758 i = XVECLEN (op, 0) - 1;
759 do
760 if (i != least && i != sign_ix && XVECEXP (op, 0, i) != sign)
761 return 0;
762 while (--i);
763 return 1;
764})
765
766;; Like register_operand, but take into account that SHMEDIA can use
767;; the constant zero like a general register.
768
769(define_predicate "sh_register_operand"
ac42ec79 770 (match_code "reg,subreg,const_int,const_double")
5546ac90
KH
771{
772 if (op == CONST0_RTX (mode) && TARGET_SHMEDIA)
773 return 1;
774 return register_operand (op, mode);
775})
776
777;; TODO: Add a comment here.
778
779(define_predicate "sh_rep_vec"
b4060d3f 780 (match_code "const_vector,parallel")
5546ac90
KH
781{
782 int i;
783 rtx x, y;
784
785 if ((GET_CODE (op) != CONST_VECTOR && GET_CODE (op) != PARALLEL)
786 || (GET_MODE (op) != mode && mode != VOIDmode))
787 return 0;
788 i = XVECLEN (op, 0) - 2;
789 x = XVECEXP (op, 0, i + 1);
790 if (GET_MODE_UNIT_SIZE (mode) == 1)
791 {
792 y = XVECEXP (op, 0, i);
793 for (i -= 2; i >= 0; i -= 2)
794 if (! rtx_equal_p (XVECEXP (op, 0, i + 1), x)
795 || ! rtx_equal_p (XVECEXP (op, 0, i), y))
796 return 0;
797 }
798 else
799 for (; i >= 0; i--)
800 if (XVECEXP (op, 0, i) != x)
801 return 0;
802 return 1;
803})
804
805;; TODO: Add a comment here.
806
807(define_predicate "shift_count_operand"
808 (match_code "const_int,const_double,const,symbol_ref,label_ref,subreg,reg,zero_extend,sign_extend")
809{
d8a48c21
OE
810 /* Allow T_REG as shift count for dynamic shifts, although it is not
811 really possible. It will then be copied to a general purpose reg. */
812 if (! TARGET_SHMEDIA)
aadb5b43
OE
813 return const_int_operand (op, mode) || arith_reg_operand (op, mode)
814 || (TARGET_DYNSHIFT && t_reg_operand (op, mode));
d8a48c21 815
5546ac90 816 return (CONSTANT_P (op)
f3536097 817 ? (CONST_INT_P (op)
5546ac90
KH
818 ? (unsigned) INTVAL (op) < GET_MODE_BITSIZE (mode)
819 : nonmemory_operand (op, mode))
820 : shift_count_reg_operand (op, mode));
821})
822
823;; TODO: Add a comment here.
824
825(define_predicate "shift_count_reg_operand"
826 (match_code "subreg,reg,zero_extend,sign_extend")
827{
828 if ((GET_CODE (op) == ZERO_EXTEND || GET_CODE (op) == SIGN_EXTEND
829 || (GET_CODE (op) == SUBREG && SUBREG_BYTE (op) == 0))
830 && (mode == VOIDmode || mode == GET_MODE (op))
831 && GET_MODE_BITSIZE (GET_MODE (XEXP (op, 0))) >= 6
832 && GET_MODE_CLASS (GET_MODE (XEXP (op, 0))) == MODE_INT)
833 {
834 mode = VOIDmode;
835 do
836 op = XEXP (op, 0);
837 while ((GET_CODE (op) == ZERO_EXTEND || GET_CODE (op) == SIGN_EXTEND
838 || GET_CODE (op) == TRUNCATE)
839 && GET_MODE_BITSIZE (GET_MODE (XEXP (op, 0))) >= 6
840 && GET_MODE_CLASS (GET_MODE (XEXP (op, 0))) == MODE_INT);
841
842 }
843 return arith_reg_operand (op, mode);
844})
845
6e01d526
OE
846;; Predicates for matching operands that are constant shift
847;; amounts 1, 2, 8, 16.
d8a48c21
OE
848(define_predicate "p27_shift_count_operand"
849 (and (match_code "const_int")
850 (match_test "satisfies_constraint_P27 (op)")))
851
852(define_predicate "not_p27_shift_count_operand"
853 (and (match_code "const_int")
854 (match_test "! satisfies_constraint_P27 (op)")))
855
6e01d526
OE
856;; For right shifts the constant 1 is a special case because the shlr insn
857;; clobbers the T_REG and is handled by the T_REG clobbering version of the
858;; insn, which is also used for non-P27 shift sequences.
859(define_predicate "p27_rshift_count_operand"
860 (and (match_code "const_int")
861 (match_test "satisfies_constraint_P27 (op)")
862 (match_test "! satisfies_constraint_M (op)")))
863
864(define_predicate "not_p27_rshift_count_operand"
865 (and (match_code "const_int")
866 (ior (match_test "! satisfies_constraint_P27 (op)")
867 (match_test "satisfies_constraint_M (op)"))))
868
5546ac90
KH
869;; TODO: Add a comment here.
870
871(define_predicate "shift_operator"
f289c6a1 872 (match_code "ashift,ashiftrt,lshiftrt"))
5546ac90
KH
873
874;; TODO: Add a comment here.
875
876(define_predicate "symbol_ref_operand"
f289c6a1 877 (match_code "symbol_ref"))
5546ac90
KH
878
879;; Same as target_reg_operand, except that label_refs and symbol_refs
880;; are accepted before reload.
881
882(define_special_predicate "target_operand"
883 (match_code "subreg,reg,label_ref,symbol_ref,const,unspec")
884{
885 if (mode != VOIDmode && mode != Pmode)
886 return 0;
887
888 if ((GET_MODE (op) == Pmode || GET_MODE (op) == VOIDmode)
32a7ab3d 889 && satisfies_constraint_Csy (op))
5546ac90
KH
890 return ! reload_completed;
891
892 return target_reg_operand (op, mode);
893})
894
895;; Accept pseudos and branch target registers.
896
897(define_special_predicate "target_reg_operand"
898 (match_code "subreg,reg")
899{
900 if (mode == VOIDmode
901 ? GET_MODE (op) != Pmode && GET_MODE (op) != PDImode
902 : mode != GET_MODE (op))
903 return 0;
904
905 if (GET_CODE (op) == SUBREG)
906 op = XEXP (op, 0);
907
f3536097 908 if (!REG_P (op))
5546ac90
KH
909 return 0;
910
911 /* We must protect ourselves from matching pseudos that are virtual
912 register, because they will eventually be replaced with hardware
913 registers that aren't branch-target registers. */
914 if (REGNO (op) > LAST_VIRTUAL_REGISTER
915 || TARGET_REGISTER_P (REGNO (op)))
916 return 1;
917
918 return 0;
919})
920
921;; TODO: Add a comment here.
922
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
f705a9a0 934;; Return 1 of OP is an address suitable for an unaligned access instruction.
5546ac90 935
f705a9a0 936(define_special_predicate "ua_address_operand"
5546ac90
KH
937 (match_code "subreg,reg,plus")
938{
939 if (GET_CODE (op) == PLUS
32a7ab3d 940 && (! satisfies_constraint_I06 (XEXP (op, 1))))
5546ac90
KH
941 return 0;
942 return address_operand (op, QImode);
943})
944
945;; TODO: Add a comment here.
946
947(define_predicate "ua_offset"
948 (match_code "const_int")
949{
32a7ab3d 950 return satisfies_constraint_I06 (op);
5546ac90
KH
951})
952
953;; TODO: Add a comment here.
954
955(define_predicate "unary_float_operator"
f289c6a1
KH
956 (and (match_code "abs,neg,sqrt")
957 (match_test "GET_MODE (op) == mode")))
5546ac90
KH
958
959;; Return 1 if OP is a valid source operand for xor.
960
961(define_predicate "xor_operand"
962 (match_code "subreg,reg,const_int")
963{
f3536097 964 if (CONST_INT_P (op))
5546ac90 965 return (TARGET_SHMEDIA
32a7ab3d 966 ? (satisfies_constraint_I06 (op)
b3a13419 967 || (!can_create_pseudo_p () && INTVAL (op) == 0xff))
32a7ab3d 968 : satisfies_constraint_K08 (op));
5546ac90
KH
969 if (TARGET_SHMEDIA
970 && mode != DImode && GET_CODE (op) == SUBREG
971 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))) > 4)
972 return 0;
973 return arith_reg_operand (op, mode);
974})
9eb3a0dd
N
975
976(define_predicate "bitwise_memory_operand"
977 (match_code "mem")
978{
f3536097 979 if (MEM_P (op))
9eb3a0dd
N
980 {
981 if (REG_P (XEXP (op, 0)))
982 return 1;
983
984 if (GET_CODE (XEXP (op, 0)) == PLUS
f3536097 985 && REG_P (XEXP (XEXP (op, 0), 0))
9eb3a0dd
N
986 && satisfies_constraint_K12 (XEXP (XEXP (op, 0), 1)))
987 return 1;
988 }
989 return 0;
990})
c11394f8
OE
991
992;; The atomic_* operand predicates are used for the atomic patterns.
993;; Depending on the particular pattern some operands can be immediate
994;; values. Using these predicates avoids the usage of 'force_reg' in the
995;; expanders.
996(define_predicate "atomic_arith_operand"
997 (ior (match_code "subreg,reg")
998 (and (match_test "satisfies_constraint_I08 (op)")
999 (match_test "mode != QImode")
1000 (match_test "mode != HImode")
1001 (match_test "TARGET_SH4A_ARCH"))))
1002
1003(define_predicate "atomic_logical_operand"
1004 (ior (match_code "subreg,reg")
1005 (and (match_test "satisfies_constraint_K08 (op)")
1006 (match_test "mode != QImode")
1007 (match_test "mode != HImode")
1008 (match_test "TARGET_SH4A_ARCH"))))
1009
f031c344
OE
1010;; A predicate describing the T bit register in any form.
1011(define_predicate "t_reg_operand"
1012 (match_code "reg,subreg,sign_extend,zero_extend")
1013{
1014 switch (GET_CODE (op))
1015 {
1016 case REG:
1017 return REGNO (op) == T_REG;
1018
1019 case SUBREG:
312f9b9d 1020 return REG_P (SUBREG_REG (op)) && REGNO (SUBREG_REG (op)) == T_REG;
f031c344
OE
1021
1022 case ZERO_EXTEND:
1023 case SIGN_EXTEND:
1024 return GET_CODE (XEXP (op, 0)) == SUBREG
312f9b9d 1025 && REG_P (SUBREG_REG (XEXP (op, 0)))
f031c344
OE
1026 && REGNO (SUBREG_REG (XEXP (op, 0))) == T_REG;
1027
1028 default:
1029 return 0;
1030 }
1031})
1032
1033;; A predicate describing a negated T bit register.
1034(define_predicate "negt_reg_operand"
1035 (match_code "subreg,xor")
1036{
1037 switch (GET_CODE (op))
1038 {
1039 case XOR:
1040 return t_reg_operand (XEXP (op, 0), GET_MODE (XEXP (op, 0)))
1041 && satisfies_constraint_M (XEXP (op, 1));
1042
1043 case SUBREG:
1044 return negt_reg_operand (XEXP (op, 0), GET_MODE (XEXP (op, 0)));
1045
1046 default:
1047 return 0;
1048 }
1049})
4eddc42b
OE
1050
1051;; Returns true of OP is arith_reg_operand or t_reg_operand.
1052(define_predicate "arith_reg_or_t_reg_operand"
1053 (ior (match_operand 0 "arith_reg_operand")
1054 (match_operand 0 "t_reg_operand")))
78040535
OE
1055
1056;; A predicate describing the negated value of the T bit register shifted
1057;; left by 31.
1058(define_predicate "negt_reg_shl31_operand"
1059 (match_code "plus,minus,if_then_else")
1060{
1061 /* (plus:SI (mult:SI (match_operand:SI 1 "t_reg_operand")
1062 (const_int -2147483648)) ;; 0xffffffff80000000
1063 (const_int -2147483648))
1064 */
1065 if (GET_CODE (op) == PLUS && satisfies_constraint_Jhb (XEXP (op, 1))
1066 && GET_CODE (XEXP (op, 0)) == MULT
1067 && t_reg_operand (XEXP (XEXP (op, 0), 0), SImode)
1068 && satisfies_constraint_Jhb (XEXP (XEXP (op, 0), 1)))
1069 return true;
1070
1071 /* (minus:SI (const_int -2147483648) ;; 0xffffffff80000000
1072 (mult:SI (match_operand:SI 1 "t_reg_operand")
1073 (const_int -2147483648)))
1074 */
1075 if (GET_CODE (op) == MINUS
1076 && satisfies_constraint_Jhb (XEXP (op, 0))
1077 && GET_CODE (XEXP (op, 1)) == MULT
1078 && t_reg_operand (XEXP (XEXP (op, 1), 0), SImode)
1079 && satisfies_constraint_Jhb (XEXP (XEXP (op, 1), 1)))
1080 return true;
1081
1082 /* (if_then_else:SI (match_operand:SI 1 "t_reg_operand")
1083 (const_int 0)
1084 (const_int -2147483648)) ;; 0xffffffff80000000
1085 */
1086 if (GET_CODE (op) == IF_THEN_ELSE && t_reg_operand (XEXP (op, 0), SImode)
1087 && satisfies_constraint_Z (XEXP (op, 1))
1088 && satisfies_constraint_Jhb (XEXP (op, 2)))
1089 return true;
1090
1091 return false;
1092})
7bd76b9c
OE
1093
1094;; A predicate that determines whether a given constant is a valid
1095;; displacement for a gbr load/store of the specified mode.
1096(define_predicate "gbr_displacement"
1097 (match_code "const_int")
1098{
1099 const int mode_sz = GET_MODE_SIZE (mode);
1100 const int move_sz = mode_sz > GET_MODE_SIZE (SImode)
1101 ? GET_MODE_SIZE (SImode)
1102 : mode_sz;
1103 int max_disp = 255 * move_sz;
1104 if (mode_sz > move_sz)
1105 max_disp -= mode_sz - move_sz;
1106
1107 return INTVAL (op) >= 0 && INTVAL (op) <= max_disp;
1108})