1 ;; Predicate definitions for Synopsys DesignWare ARC.
2 ;; Copyright (C) 2007-2018 Free Software Foundation, Inc.
4 ;; This file is part of GCC.
6 ;; GCC is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 3, or (at your option)
11 ;; GCC is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;; GNU General Public License for more details.
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GCC; see the file COPYING3. If not see
18 ;; <http://www.gnu.org/licenses/>.
20 (define_predicate "dest_reg_operand"
21 (match_code "reg,subreg")
25 if (GET_CODE (op0) == SUBREG)
26 op0 = SUBREG_REG (op0);
27 if (REG_P (op0) && REGNO (op0) < FIRST_PSEUDO_REGISTER
28 && TEST_HARD_REG_BIT (reg_class_contents[ALL_CORE_REGS],
30 && !TEST_HARD_REG_BIT (reg_class_contents[WRITABLE_CORE_REGS],
33 return register_operand (op, mode);
36 (define_predicate "mpy_dest_reg_operand"
37 (match_code "reg,subreg")
41 if (GET_CODE (op0) == SUBREG)
42 op0 = SUBREG_REG (op0);
43 if (REG_P (op0) && REGNO (op0) < FIRST_PSEUDO_REGISTER
44 && TEST_HARD_REG_BIT (reg_class_contents[ALL_CORE_REGS],
46 /* Make sure the destination register is not LP_COUNT. */
47 && !TEST_HARD_REG_BIT (reg_class_contents[MPY_WRITABLE_CORE_REGS],
50 return register_operand (op, mode);
54 ;; Returns 1 if OP is a symbol reference.
55 (define_predicate "symbolic_operand"
56 (match_code "symbol_ref, label_ref, const")
59 ;; Acceptable arguments to the call insn.
60 (define_predicate "call_address_operand"
61 (ior (match_code "const_int, reg")
62 (match_operand 0 "symbolic_operand")
63 (match_test "CONSTANT_P (op)
64 && arc_legitimate_constant_p (VOIDmode, op)"))
67 (define_predicate "call_operand"
68 (and (match_code "mem")
69 (match_test "call_address_operand (XEXP (op, 0), mode)"))
72 ;; Return true if OP is a unsigned 6-bit immediate (u6) value.
73 (define_predicate "u6_immediate_operand"
74 (and (match_code "const_int")
75 (match_test "UNSIGNED_INT6 (INTVAL (op))"))
78 ;; Return true if OP is a short immediate (shimm) value.
79 (define_predicate "short_immediate_operand"
80 (and (match_code "const_int")
81 (match_test "SMALL_INT (INTVAL (op))"))
84 (define_predicate "p2_immediate_operand"
85 (and (match_code "const_int")
86 (match_test "((INTVAL (op) - 1) & INTVAL (op)) == 0")
87 (match_test "INTVAL (op)"))
90 ;; Return true if OP will require a long immediate (limm) value.
91 ;; This is currently only used when calculating length attributes.
92 (define_predicate "long_immediate_operand"
93 (match_code "symbol_ref, label_ref, const, const_double, const_int")
95 switch (GET_CODE (op))
102 return !SIGNED_INT12 (INTVAL (op));
104 /* These can happen because large unsigned 32 bit constants are
105 represented this way (the multiplication patterns can cause these
106 to be generated). They also occur for SFmode values. */
115 ;; Return true if OP is a MEM that when used as a load or store address will
116 ;; require an 8 byte insn.
117 ;; Load and store instructions don't allow the same possibilities but they're
118 ;; similar enough that this one function will do.
119 ;; This is currently only used when calculating length attributes. */
120 (define_predicate "long_immediate_loadstore_operand"
123 int size = GET_MODE_SIZE (GET_MODE (op));
126 if (TARGET_NPS_CMEM && cmem_address (op, SImode))
128 switch (GET_CODE (op))
135 /* This must be handled as "st c,[limm]". Ditto for load.
136 Technically, the assembler could translate some possibilities to
137 "st c,[limm/2 + limm/2]" if limm/2 will fit in a shimm, but we don't
138 assume that it does. */
141 /* These can happen because large unsigned 32 bit constants are
142 represented this way (the multiplication patterns can cause these
143 to be generated). They also occur for SFmode values. */
149 rtx x = XEXP (op, 1);
151 if ((GET_CODE (XEXP (op, 0)) == MULT)
152 && REG_P (XEXP (XEXP (op, 0), 0))
156 if (GET_CODE (x) == CONST)
159 if (GET_CODE (x) == PLUS)
163 return (!SMALL_INT (INTVAL (x))
164 && (size <= 1 || size > 4
165 || (INTVAL (x) & (size - 1)) != 0
166 || !SMALL_INT (INTVAL (x) / size)));
167 else if (GET_CODE (x) == SYMBOL_REF)
168 return TARGET_NO_SDATA_SET || !SYMBOL_REF_SMALL_P (x);
178 ;; Return true if OP is any of R0-R3,R12-R15 for ARCompact 16-bit
180 (define_predicate "compact_register_operand"
181 (match_code "reg, subreg")
183 if ((GET_MODE (op) != mode) && (mode != VOIDmode))
186 return (GET_CODE (op) == REG)
187 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
188 || COMPACT_GP_REG_P (REGNO (op))) ;
192 (define_predicate "compact_hreg_operand"
193 (match_code "reg, subreg")
195 if ((GET_MODE (op) != mode) && (mode != VOIDmode))
198 return (GET_CODE (op) == REG)
199 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
200 || (TARGET_V2 && REGNO (op) <= 31 && REGNO (op) != 30)
205 ;; Return true if OP is an acceptable memory operand for ARCompact
206 ;; 16-bit store instructions
207 (define_predicate "compact_store_memory_operand"
210 rtx addr, plus0, plus1;
213 if (mode == VOIDmode)
214 mode = GET_MODE (op);
216 /* .di instructions have no 16-bit form. */
217 if (MEM_VOLATILE_P (op) && !TARGET_VOLATILE_CACHE_SET)
220 /* likewise for uncached types. */
221 if (arc_is_uncached_mem_p (op))
224 size = GET_MODE_SIZE (mode);
226 /* dword operations really put out 2 instructions, so eliminate them. */
227 if (size > UNITS_PER_WORD)
230 /* Decode the address now. */
232 switch (GET_CODE (addr))
235 return (REGNO (addr) >= FIRST_PSEUDO_REGISTER
236 || COMPACT_GP_REG_P (REGNO (addr))
237 || (SP_REG_P (REGNO (addr)) && (size != 2)));
238 /* stw_s does not support SP as a parameter. */
240 plus0 = XEXP (addr, 0);
241 plus1 = XEXP (addr, 1);
243 if ((GET_CODE (plus0) == REG)
244 && ((REGNO (plus0) >= FIRST_PSEUDO_REGISTER)
245 || COMPACT_GP_REG_P (REGNO (plus0)))
246 && (GET_CODE (plus1) == CONST_INT))
248 off = INTVAL (plus1);
250 /* Negative offset is not supported in 16-bit load/store insns. */
259 return ((off < 64) && (off % 2 == 0));
261 return ((off < 128) && (off % 4 == 0));
265 if ((GET_CODE (plus0) == REG)
266 && ((REGNO (plus0) >= FIRST_PSEUDO_REGISTER)
267 || SP_REG_P (REGNO (plus0)))
268 && (GET_CODE (plus1) == CONST_INT))
270 off = INTVAL (plus1);
272 return ((size != 2) && (off >= 0 && off < 128) && (off % 4 == 0));
281 ;; Return true if OP is an acceptable argument for a single word
283 (define_predicate "move_src_operand"
284 (match_code "symbol_ref, label_ref, const, const_int, const_double, reg, subreg, mem")
286 switch (GET_CODE (op))
289 if (SYMBOL_REF_TLS_MODEL (op))
295 return arc_legitimate_constant_p (mode, op);
297 return (LARGE_INT (INTVAL (op)));
299 /* We can handle DImode integer constants in SImode if the value
300 (signed or unsigned) will fit in 32 bits. This is needed because
301 large unsigned 32 bit constants are represented as CONST_DOUBLEs. */
303 return arc_double_limm_p (op);
304 /* We can handle 32 bit floating point constants. */
306 return GET_MODE (op) == SFmode;
309 return register_operand (op, mode);
311 /* (subreg (mem ...) ...) can occur here if the inner part was once a
312 pseudo-reg and is now a stack slot. */
313 if (GET_CODE (SUBREG_REG (op)) == MEM)
314 return address_operand (XEXP (SUBREG_REG (op), 0), mode);
316 return register_operand (op, mode);
318 return address_operand (XEXP (op, 0), mode);
325 ;; Return true if OP is an acceptable argument for a double word
327 (define_predicate "move_double_src_operand"
328 (match_code "reg, subreg, mem, const_int, const_double")
330 switch (GET_CODE (op))
333 return register_operand (op, mode);
335 /* (subreg (mem ...) ...) can occur here if the inner part was once a
336 pseudo-reg and is now a stack slot. */
337 if (GET_CODE (SUBREG_REG (op)) == MEM)
338 return address_operand (XEXP (SUBREG_REG (op), 0), mode);
340 return register_operand (op, mode);
342 return address_operand (XEXP (op, 0), mode);
352 ;; Return true if OP is an acceptable argument for a move destination.
353 (define_predicate "move_dest_operand"
354 (match_code "reg, subreg, mem")
356 switch (GET_CODE (op))
359 /* Program Counter register cannot be the target of a move. It is
360 a readonly register. */
361 if (REGNO (op) == PROGRAM_COUNTER_REGNO)
363 else if (TARGET_MULMAC_32BY16_SET
364 && (REGNO (op) == 56 || REGNO(op) == 57))
366 else if (TARGET_MUL64_SET
367 && (REGNO (op) == 57 || REGNO(op) == 58 || REGNO(op) == 59 ))
369 else if (REGNO (op) == LP_COUNT)
372 return dest_reg_operand (op, mode);
374 /* (subreg (mem ...) ...) can occur here if the inner part was once a
375 pseudo-reg and is now a stack slot. */
376 if (GET_CODE (SUBREG_REG (op)) == MEM)
377 return address_operand (XEXP (SUBREG_REG (op), 0), mode);
379 return dest_reg_operand (op, mode);
382 rtx addr = XEXP (op, 0);
384 if (GET_CODE (addr) == PLUS
385 && (GET_CODE (XEXP (addr, 0)) == MULT
386 || (!CONST_INT_P (XEXP (addr, 1))
387 && (TARGET_NO_SDATA_SET
388 || GET_CODE (XEXP (addr, 1)) != SYMBOL_REF
389 || !SYMBOL_REF_SMALL_P (XEXP (addr, 1))))))
391 if ((GET_CODE (addr) == PRE_MODIFY || GET_CODE (addr) == POST_MODIFY)
392 && (GET_CODE (XEXP (addr, 1)) != PLUS
393 || !CONST_INT_P (XEXP (XEXP (addr, 1), 1))))
395 /* CONST_INT / CONST_DOUBLE is fine, but the PIC CONST ([..] UNSPEC))
396 constructs are effectively indexed. */
400 while (GET_CODE (ad0) == PLUS)
402 if (GET_CODE (ad0) == CONST || GET_CODE (ad0) == UNSPEC)
405 return address_operand (addr, mode);
414 ;; Return true if OP is a non-volatile non-immediate operand.
415 ;; Volatile memory refs require a special "cache-bypass" instruction
416 ;; and only the standard movXX patterns are set up to handle them.
417 (define_predicate "nonvol_nonimm_operand"
418 (and (match_code "subreg, reg, mem")
419 (match_test "(GET_CODE (op) != MEM || !MEM_VOLATILE_P (op)) && nonimmediate_operand (op, mode)")
420 (match_test "!arc_is_uncached_mem_p (op)"))
423 ;; Return 1 if OP is a comparison operator valid for the mode of CC.
424 ;; This allows the use of MATCH_OPERATOR to recognize all the branch insns.
426 (define_predicate "proper_comparison_operator"
427 (match_code "eq, ne, le, lt, ge, gt, leu, ltu, geu, gtu, unordered, ordered, uneq, unge, ungt, unle, unlt, ltgt")
429 enum rtx_code code = GET_CODE (op);
431 if (!COMPARISON_P (op))
434 /* After generic flag-setting insns, we can use eq / ne / pl / mi / pnz .
435 There are some creative uses for hi / ls after shifts, but these are
436 hard to understand for the compiler and could be at best the target of
438 switch (GET_MODE (XEXP (op, 0)))
441 return (code == EQ || code == NE || code == GE || code == LT
444 return code == EQ || code == NE;
446 return code == LTU || code == GEU;
448 return code == GT || code == UNLE;
450 return code == GE || code == UNLT;
451 case E_CC_FP_ORDmode:
452 return code == ORDERED || code == UNORDERED;
453 case E_CC_FP_UNEQmode:
454 return code == UNEQ || code == LTGT;
456 return (code == EQ || code == NE || code == UNEQ || code == LTGT
457 || code == ORDERED || code == UNORDERED);
461 case E_CC_FPU_UNEQmode:
465 case E_SImode: /* Used for BRcc. */
468 case E_QImode: case E_HImode: case E_DImode: case E_SFmode: case E_DFmode:
477 (define_predicate "equality_comparison_operator"
478 (match_code "eq, ne"))
480 (define_predicate "ge_lt_comparison_operator"
481 (match_code "ge, lt"))
483 (define_predicate "brcc_nolimm_operator"
484 (ior (match_test "REG_P (XEXP (op, 1))")
485 (and (match_code "eq, ne, lt, ge, ltu, geu")
486 (match_test "CONST_INT_P (XEXP (op, 1))")
487 (match_test "u6_immediate_operand (XEXP (op, 1), SImode)"))
488 (and (match_code "le, gt, leu, gtu")
489 (match_test "CONST_INT_P (XEXP (op, 1))")
490 (match_test "UNSIGNED_INT6 (INTVAL (XEXP (op, 1)) + 1)"))))
492 ;; Return TRUE if this is the condition code register, if we aren't given
493 ;; a mode, accept any CCmode register
494 (define_special_predicate "cc_register"
497 if (mode == VOIDmode)
499 mode = GET_MODE (op);
500 if (GET_MODE_CLASS (mode) != MODE_CC)
504 if (mode == GET_MODE (op) && GET_CODE (op) == REG && REGNO (op) == CC_REG)
510 ;; Return TRUE if this is the condition code register; if we aren't given
511 ;; a mode, accept any CCmode register. If we are given a mode, accept
512 ;; modes that set a subset of flags.
513 (define_special_predicate "cc_set_register"
516 machine_mode rmode = GET_MODE (op);
518 if (mode == VOIDmode)
521 if (GET_MODE_CLASS (mode) != MODE_CC)
525 if (REGNO (op) != CC_REG)
528 || (mode == CC_ZNmode && rmode == CC_Zmode)
529 || (mode == CCmode && rmode == CC_Zmode)
530 || (mode == CCmode && rmode == CC_ZNmode)
531 || (mode == CCmode && rmode == CC_Cmode))
537 ; Accept CC_REG in modes which provide the flags needed for MODE. */
538 (define_special_predicate "cc_use_register"
541 if (REGNO (op) != CC_REG)
543 if (GET_MODE (op) == mode)
548 if (GET_MODE (op) == CC_ZNmode)
551 case E_CC_ZNmode: case E_CC_Cmode:
552 return GET_MODE (op) == CCmode;
558 (define_special_predicate "zn_compare_operator"
559 (match_code "compare")
561 return GET_MODE (op) == CC_ZNmode || GET_MODE (op) == CC_Zmode;
564 ;; Return true if OP is a shift operator.
565 (define_predicate "shift_operator"
566 (match_code "ashiftrt, lshiftrt, ashift")
569 ;; Return true if OP is a left shift operator that can be implemented in
570 ;; four insn words or less without a barrel shifter or multiplier.
571 (define_predicate "shiftl4_operator"
572 (and (match_code "ashift")
573 (match_test "const_int_operand (XEXP (op, 1), VOIDmode) ")
574 (match_test "UINTVAL (XEXP (op, 1)) <= 9U
575 || INTVAL (XEXP (op, 1)) == 29
576 || INTVAL (XEXP (op, 1)) == 30
577 || INTVAL (XEXP (op, 1)) == 31")))
579 ;; Return true if OP is a right shift operator that can be implemented in
580 ;; four insn words or less without a barrel shifter or multiplier.
581 (define_predicate "shiftr4_operator"
582 (and (match_code "ashiftrt, lshiftrt")
583 (match_test "const_int_operand (XEXP (op, 1), VOIDmode) ")
584 (match_test "UINTVAL (XEXP (op, 1)) <= 4U
585 || INTVAL (XEXP (op, 1)) == 30
586 || INTVAL (XEXP (op, 1)) == 31")))
588 ;; Return true if OP is a shift operator that can be implemented in
589 ;; four insn words or less without a barrel shifter or multiplier.
590 (define_predicate "shift4_operator"
591 (ior (match_operand 0 "shiftl4_operator")
592 (match_operand 0 "shiftr4_operator")))
594 (define_predicate "mult_operator"
595 (and (match_code "mult") (match_test "TARGET_MPY"))
598 (define_predicate "commutative_operator"
599 (ior (match_code "plus,ior,xor,and")
600 (match_operand 0 "mult_operator")
601 (and (match_code "ss_plus")
602 (match_test "TARGET_ARC700 || TARGET_EA_SET")))
605 (define_predicate "commutative_operator_sans_mult"
606 (ior (match_code "plus,ior,xor,and")
607 (and (match_code "ss_plus")
608 (match_test "TARGET_ARC700 || TARGET_EA_SET")))
611 (define_predicate "noncommutative_operator"
612 (ior (and (match_code "ashift,ashiftrt,lshiftrt,rotatert")
613 (match_test "TARGET_BARREL_SHIFTER"))
615 (and (match_code "ss_minus")
616 (match_test "TARGET_ARC700 || TARGET_EA_SET")))
619 (define_predicate "unary_operator"
620 (ior (match_code "abs,neg,not,sign_extend,zero_extend")
621 (and (ior (match_code "ss_neg")
622 (and (match_code "ss_truncate")
623 (match_test "GET_MODE (XEXP (op, 0)) == HImode")))
624 (match_test "TARGET_ARC700 || TARGET_EA_SET")))
627 (define_predicate "_1_2_3_operand"
628 (and (match_code "const_int")
629 (match_test "INTVAL (op) == 1 || INTVAL (op) == 2 || INTVAL (op) == 3"))
632 (define_predicate "_2_4_8_operand"
633 (and (match_code "const_int")
634 (match_test "INTVAL (op) == 2 || INTVAL (op) == 4 || INTVAL (op) == 8"))
637 (define_predicate "arc_double_register_operand"
640 if ((GET_MODE (op) != mode) && (mode != VOIDmode))
643 return (GET_CODE (op) == REG
644 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
645 || REGNO_REG_CLASS (REGNO (op)) == DOUBLE_REGS));
648 (define_predicate "shouldbe_register_operand"
649 (match_code "reg,subreg,mem")
651 return ((reload_in_progress || reload_completed)
652 ? general_operand : register_operand) (op, mode);
655 (define_predicate "vector_register_operand"
658 if ((GET_MODE (op) != mode) && (mode != VOIDmode))
661 return (GET_CODE (op) == REG
662 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
663 || REGNO_REG_CLASS (REGNO (op)) == SIMD_VR_REGS));
666 (define_predicate "vector_register_or_memory_operand"
667 ( ior (match_code "reg")
670 if ((GET_MODE (op) != mode) && (mode != VOIDmode))
673 if ((GET_CODE (op) == MEM)
674 && (mode == V8HImode)
675 && GET_CODE (XEXP (op,0)) == REG)
678 return (GET_CODE (op) == REG
679 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
680 || REGNO_REG_CLASS (REGNO (op)) == SIMD_VR_REGS));
683 (define_predicate "arc_dpfp_operator"
684 (match_code "plus, mult,minus")
687 (define_predicate "arc_simd_dma_register_operand"
690 if ((GET_MODE (op) != mode) && (mode != VOIDmode))
693 return (GET_CODE (op) == REG
694 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
695 || REGNO_REG_CLASS (REGNO (op)) == SIMD_DMA_CONFIG_REGS));
698 (define_predicate "acc1_operand"
699 (and (match_code "reg")
700 (match_test "REGNO (op) == (TARGET_BIG_ENDIAN ? 56 : 57)")))
702 (define_predicate "acc2_operand"
703 (and (match_code "reg")
704 (match_test "REGNO (op) == (TARGET_BIG_ENDIAN ? 57 : 56)")))
706 (define_predicate "mlo_operand"
707 (and (match_code "reg")
708 (match_test "REGNO (op) == (TARGET_BIG_ENDIAN ? 59 : 58)")))
710 (define_predicate "mhi_operand"
711 (and (match_code "reg")
712 (match_test "REGNO (op) == (TARGET_BIG_ENDIAN ? 58 : 59)")))
714 (define_predicate "accl_operand"
715 (and (match_code "reg")
716 (match_test "REGNO (op) == (TARGET_BIG_ENDIAN ? 59 : 58)")
717 (match_test "TARGET_V2")))
719 ; Unfortunately, we can not allow a const_int_operand before reload, because
720 ; reload needs a non-void mode to guide it how to reload the inside of a
722 (define_predicate "extend_operand"
723 (ior (match_operand 0 "register_operand")
724 (and (match_operand 0 "immediate_operand")
725 (ior (not (match_operand 0 "const_int_operand"))
726 (match_test "reload_in_progress || reload_completed")))))
728 (define_predicate "millicode_store_operation"
729 (match_code "parallel")
731 return arc_check_millicode (op, 0, 0);
734 (define_predicate "millicode_load_operation"
735 (match_code "parallel")
737 return arc_check_millicode (op, 2, 2);
740 (define_predicate "millicode_load_clob_operation"
741 (match_code "parallel")
743 return arc_check_millicode (op, 0, 1);
746 (define_special_predicate "immediate_usidi_operand"
748 (match_code "const_int")
749 (match_test "INTVAL (op) >= 0")
750 (and (match_test "const_double_operand (op, mode)")
751 (match_test "CONST_DOUBLE_HIGH (op) == 0"))))
753 (define_predicate "short_const_int_operand"
754 (and (match_operand 0 "const_int_operand")
755 (match_test "satisfies_constraint_C16 (op)")))
757 (define_predicate "mem_noofs_operand"
758 (and (match_code "mem")
759 (match_code "reg" "0")))
761 (define_predicate "any_mem_operand"
764 ; Special predicate to match even-odd double register pair
765 (define_predicate "even_register_operand"
768 if ((GET_MODE (op) != mode) && (mode != VOIDmode))
771 return (REG_P (op) && ((REGNO (op) >= FIRST_PSEUDO_REGISTER)
772 || ((REGNO (op) & 1) == 0)));
775 (define_predicate "double_register_operand"
776 (ior (match_test "even_register_operand (op, mode)")
777 (match_test "arc_double_register_operand (op, mode)")))
779 (define_predicate "cmem_address_0"
780 (and (match_code "symbol_ref")
781 (match_test "SYMBOL_REF_FLAGS (op) & SYMBOL_FLAG_CMEM")))
783 (define_predicate "cmem_address_1"
784 (and (match_code "plus")
785 (match_test "cmem_address_0 (XEXP (op, 0), SImode)")))
787 (define_predicate "cmem_address_2"
788 (and (match_code "const")
789 (match_test "cmem_address_1 (XEXP (op, 0), SImode)")))
791 (define_predicate "cmem_address"
792 (ior (match_operand:SI 0 "cmem_address_0")
793 (match_operand:SI 0 "cmem_address_1")
794 (match_operand:SI 0 "cmem_address_2")))
796 (define_predicate "short_unsigned_const_operand"
797 (and (match_code "const_int")
798 (match_test "satisfies_constraint_J16 (op)")))
800 (define_predicate "arc_short_operand"
801 (ior (match_test "register_operand (op, mode)")
802 (match_test "short_unsigned_const_operand (op, mode)")))