xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/config/m32c/predicates.md (revision 8feb0f0b7eaff0608f8350bbfa3098827b4bb91b)
136ac495dSmrg;; Machine Descriptions for R8C/M16C/M32C
2*8feb0f0bSmrg;; Copyright (C) 2005-2020 Free Software Foundation, Inc.
336ac495dSmrg;; Contributed by Red Hat.
436ac495dSmrg;;
536ac495dSmrg;; This file is part of GCC.
636ac495dSmrg;;
736ac495dSmrg;; GCC is free software; you can redistribute it and/or modify it
836ac495dSmrg;; under the terms of the GNU General Public License as published
936ac495dSmrg;; by the Free Software Foundation; either version 3, or (at your
1036ac495dSmrg;; option) any later version.
1136ac495dSmrg;;
1236ac495dSmrg;; GCC is distributed in the hope that it will be useful, but WITHOUT
1336ac495dSmrg;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1436ac495dSmrg;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
1536ac495dSmrg;; License for more details.
1636ac495dSmrg;;
1736ac495dSmrg;; You should have received a copy of the GNU General Public License
1836ac495dSmrg;; along with GCC; see the file COPYING3.  If not see
1936ac495dSmrg;; <http://www.gnu.org/licenses/>.
2036ac495dSmrg
2136ac495dSmrg;; Predicates
2236ac495dSmrg
2336ac495dSmrg; TRUE for any valid operand.  We do this because general_operand
2436ac495dSmrg; refuses to match volatile memory refs.
2536ac495dSmrg
2636ac495dSmrg(define_predicate "m32c_any_operand"
2736ac495dSmrg  (ior (match_operand 0 "general_operand")
2836ac495dSmrg       (match_code "mem,const_int,const_double"))
2936ac495dSmrg  {
3036ac495dSmrg    return ! m32c_illegal_subreg_p (op);
3136ac495dSmrg  }
3236ac495dSmrg)
3336ac495dSmrg
3436ac495dSmrg; Likewise for nonimmediate_operand.
3536ac495dSmrg
3636ac495dSmrg(define_predicate "m32c_nonimmediate_operand"
3736ac495dSmrg  (ior (match_operand 0 "nonimmediate_operand")
3836ac495dSmrg       (match_code "mem"))
3936ac495dSmrg  {
4036ac495dSmrg    return ! m32c_illegal_subreg_p (op);
4136ac495dSmrg  }
4236ac495dSmrg)
4336ac495dSmrg
4436ac495dSmrg; TRUE if the operand is a pseudo-register.
4536ac495dSmrg(define_predicate "m32c_pseudo"
4636ac495dSmrg  (ior (and (match_code "reg")
4736ac495dSmrg	    (match_test "REGNO(op) >= FIRST_PSEUDO_REGISTER"))
4836ac495dSmrg       (and (match_code "subreg")
4936ac495dSmrg	    (and (match_test "GET_CODE (XEXP (op, 0)) == REG")
5036ac495dSmrg		 (match_test "REGNO(XEXP (op,0)) >= FIRST_PSEUDO_REGISTER")))))
5136ac495dSmrg
5236ac495dSmrg
5336ac495dSmrg; Returning true causes many predicates to NOT match.  We allow
5436ac495dSmrg; subregs for type changing, but not for size changing.
5536ac495dSmrg(define_predicate "m32c_wide_subreg"
5636ac495dSmrg  (and (match_code "subreg")
5736ac495dSmrg       (not (match_operand 0 "m32c_pseudo")))
5836ac495dSmrg  {
5936ac495dSmrg    unsigned int sizeo = GET_MODE_SIZE (GET_MODE (op));
6036ac495dSmrg    unsigned int sizei = GET_MODE_SIZE (GET_MODE (XEXP (op, 0)));
6136ac495dSmrg    sizeo = (sizeo + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
6236ac495dSmrg    sizei = (sizei + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
6336ac495dSmrg    return sizeo != sizei;
6436ac495dSmrg  })
6536ac495dSmrg
6636ac495dSmrg; TRUE for r0 through r3, or a pseudo that reload could put in r0
6736ac495dSmrg; through r3 (likewise for the next couple too)
6836ac495dSmrg(define_predicate "r0123_operand"
6936ac495dSmrg  (ior (match_operand 0 "m32c_pseudo" "")
7036ac495dSmrg       (and (match_code "reg")
7136ac495dSmrg	    (match_test "REGNO(op) <= R3_REGNO"))))
7236ac495dSmrg
7336ac495dSmrg; TRUE for r0
7436ac495dSmrg(define_predicate "m32c_r0_operand"
7536ac495dSmrg  (ior (match_operand 0 "m32c_pseudo" "")
7636ac495dSmrg       (and (match_code "reg")
7736ac495dSmrg	    (match_test "REGNO(op) == R0_REGNO"))))
7836ac495dSmrg
7936ac495dSmrg; TRUE for r1
8036ac495dSmrg(define_predicate "m32c_r1_operand"
8136ac495dSmrg  (ior (match_operand 0 "m32c_pseudo" "")
8236ac495dSmrg       (and (match_code "reg")
8336ac495dSmrg	    (match_test "REGNO(op) == R1_REGNO"))))
8436ac495dSmrg
8536ac495dSmrg; TRUE for HL_CLASS (r0 or r1)
8636ac495dSmrg(define_predicate "m32c_hl_operand"
8736ac495dSmrg  (ior (match_operand 0 "m32c_pseudo" "")
8836ac495dSmrg       (and (match_code "reg")
8936ac495dSmrg	    (match_test "REGNO(op) == R0_REGNO || REGNO(op) == R1_REGNO"))))
9036ac495dSmrg
9136ac495dSmrg
9236ac495dSmrg; TRUE for r2
9336ac495dSmrg(define_predicate "m32c_r2_operand"
9436ac495dSmrg  (ior (match_operand 0 "m32c_pseudo" "")
9536ac495dSmrg       (and (match_code "reg")
9636ac495dSmrg	    (match_test "REGNO(op) == R2_REGNO"))))
9736ac495dSmrg
9836ac495dSmrg; TRUE for r3
9936ac495dSmrg(define_predicate "m32c_r3_operand"
10036ac495dSmrg  (ior (match_operand 0 "m32c_pseudo" "")
10136ac495dSmrg       (and (match_code "reg")
10236ac495dSmrg	    (match_test "REGNO(op) == R3_REGNO"))))
10336ac495dSmrg
10436ac495dSmrg; TRUE for any general operand except r2.
10536ac495dSmrg(define_predicate "m32c_notr2_operand"
10636ac495dSmrg  (and (match_operand 0 "general_operand")
10736ac495dSmrg       (ior (not (match_code "reg"))
10836ac495dSmrg	    (match_test "REGNO(op) != R2_REGNO"))))
10936ac495dSmrg
11036ac495dSmrg; TRUE for the stack pointer.
11136ac495dSmrg(define_predicate "m32c_sp_operand"
11236ac495dSmrg  (ior (match_operand 0 "m32c_pseudo" "")
11336ac495dSmrg       (and (match_code "reg")
11436ac495dSmrg	    (match_test "REGNO(op) == SP_REGNO"))))
11536ac495dSmrg
11636ac495dSmrg; TRUE for control registers.
11736ac495dSmrg(define_predicate "cr_operand"
11836ac495dSmrg  (match_code "reg")
11936ac495dSmrg  "return (REGNO (op) >= SB_REGNO
12036ac495dSmrg           && REGNO (op) <= FLG_REGNO);")
12136ac495dSmrg
12236ac495dSmrg; TRUE for $a0 or $a1.
12336ac495dSmrg(define_predicate "a_operand"
12436ac495dSmrg  (and (match_code "reg")
12536ac495dSmrg       (match_test "REGNO (op) == A0_REGNO || REGNO (op) == A1_REGNO")))
12636ac495dSmrg
12736ac495dSmrg; TRUE for $a0 or $a1 or a pseudo
12836ac495dSmrg(define_predicate "ap_operand"
12936ac495dSmrg  (ior (match_operand 0 "m32c_pseudo" "")
13036ac495dSmrg       (and (match_code "reg")
13136ac495dSmrg	    (match_test "REGNO (op) == A0_REGNO || REGNO (op) == A1_REGNO"))))
13236ac495dSmrg
13336ac495dSmrg; TRUE for r0 through r3, or a0 or a1.
13436ac495dSmrg(define_predicate "ra_operand"
13536ac495dSmrg  (and (and (match_operand 0 "register_operand" "")
13636ac495dSmrg	    (not (match_operand 1 "cr_operand" "")))
13736ac495dSmrg       (not (match_operand 2 "m32c_wide_subreg" ""))))
13836ac495dSmrg
13936ac495dSmrg; Likewise, plus TRUE for memory references.
14036ac495dSmrg(define_predicate "mra_operand"
14136ac495dSmrg  (and (and (match_operand 0 "m32c_nonimmediate_operand" "")
14236ac495dSmrg	    (not (match_operand 1 "cr_operand" "")))
14336ac495dSmrg       (not (match_operand 2 "m32c_wide_subreg" ""))))
14436ac495dSmrg
14536ac495dSmrg; Likewise, plus TRUE for subregs.
14636ac495dSmrg(define_predicate "mras_operand"
14736ac495dSmrg  (and (match_operand 0 "nonimmediate_operand" "")
14836ac495dSmrg       (not (match_operand 1 "cr_operand" ""))))
14936ac495dSmrg
15036ac495dSmrg; As above, but no push/pop operations
15136ac495dSmrg(define_predicate "mra_nopp_operand"
15236ac495dSmrg  (match_operand 0 "mra_operand" "")
15336ac495dSmrg{
15436ac495dSmrg  if (GET_CODE (op) == MEM
15536ac495dSmrg      && (GET_CODE (XEXP (op, 0)) == PRE_DEC
15636ac495dSmrg	  || (GET_CODE (XEXP (op, 0)) == POST_INC)))
15736ac495dSmrg    return 0;
15836ac495dSmrg  return 1;
15936ac495dSmrg})
16036ac495dSmrg
16136ac495dSmrg; TRUE for memory, r0..r3, a0..a1, or immediates.
16236ac495dSmrg(define_predicate "mrai_operand"
16336ac495dSmrg  (and (and (match_operand 0 "m32c_any_operand" "")
16436ac495dSmrg	    (not (match_operand 1 "cr_operand" "")))
16536ac495dSmrg       (not (match_operand 2 "m32c_wide_subreg" ""))))
16636ac495dSmrg
16736ac495dSmrg; Likewise, plus true for subregs.
16836ac495dSmrg(define_predicate "mrasi_operand"
16936ac495dSmrg  (and (match_operand 0 "general_operand" "")
17036ac495dSmrg       (not (match_operand 1 "cr_operand" ""))))
17136ac495dSmrg
17236ac495dSmrg; TRUE for r0..r3 or memory.
17336ac495dSmrg(define_predicate "mr_operand"
17436ac495dSmrg  (and (match_operand 0 "mra_operand" "")
17536ac495dSmrg       (not (match_operand 1 "a_operand" ""))))
17636ac495dSmrg
17736ac495dSmrg; TRUE for a0..a1 or memory.
17836ac495dSmrg(define_predicate "ma_operand"
17936ac495dSmrg  (ior (match_operand 0 "a_operand" "")
18036ac495dSmrg       (match_operand 1 "memory_operand" "")))
18136ac495dSmrg
18236ac495dSmrg; TRUE for memory operands that are not indexed
18336ac495dSmrg(define_predicate "memsym_operand"
18436ac495dSmrg  (and (match_operand 0 "memory_operand" "")
18536ac495dSmrg       (match_test "satisfies_constraint_Si (op)")))
18636ac495dSmrg
18736ac495dSmrg; TRUE for memory operands with small integer addresses
18836ac495dSmrg(define_predicate "memimmed_operand"
18936ac495dSmrg  (and (match_operand 0 "memory_operand" "")
19036ac495dSmrg       (match_test "satisfies_constraint_Sp (op)")))
19136ac495dSmrg
19236ac495dSmrg; TRUE for r1h.  This is complicated since r1h isn't a register GCC
19336ac495dSmrg; normally knows about.
19436ac495dSmrg(define_predicate "r1h_operand"
19536ac495dSmrg  (match_code "zero_extract")
19636ac495dSmrg  {
19736ac495dSmrg    rtx reg = XEXP (op, 0);
19836ac495dSmrg    rtx size = XEXP (op, 1);
19936ac495dSmrg    rtx pos = XEXP (op, 2);
20036ac495dSmrg    return (GET_CODE (reg) == REG
20136ac495dSmrg	    && REGNO (reg) == R1_REGNO
20236ac495dSmrg	    && GET_CODE (size) == CONST_INT
20336ac495dSmrg	    && INTVAL (size) == 8
20436ac495dSmrg	    && GET_CODE (pos) == CONST_INT
20536ac495dSmrg	    && INTVAL (pos) == 8);
20636ac495dSmrg  })
20736ac495dSmrg
20836ac495dSmrg; TRUE if we can shift by this amount.  Constant shift counts have a
20936ac495dSmrg; limited range.
21036ac495dSmrg(define_predicate "shiftcount_operand"
21136ac495dSmrg  (ior (match_operand 0 "mra_operand" "")
21236ac495dSmrg       (and (match_operand 2 "const_int_operand" "")
213a2dc1f3fSmrg	    (match_test "INTVAL (op) >= -8 && INTVAL (op) && INTVAL (op) <= 8"))))
21436ac495dSmrg(define_predicate "longshiftcount_operand"
21536ac495dSmrg  (ior (match_operand 0 "mra_operand" "")
21636ac495dSmrg       (and (match_operand 2 "const_int_operand" "")
217a2dc1f3fSmrg	    (match_test "INTVAL (op) >= -32 && INTVAL (op) && INTVAL (op) <= 32"))))
21836ac495dSmrg
21936ac495dSmrg; TRUE for r0..r3, a0..a1, or sp.
22036ac495dSmrg(define_predicate "mra_or_sp_operand"
22136ac495dSmrg  (and (ior (match_operand 0 "mra_operand")
22236ac495dSmrg	    (match_operand 1 "m32c_sp_operand"))
22336ac495dSmrg       (not (match_operand 2 "m32c_wide_subreg" ""))))
22436ac495dSmrg
22536ac495dSmrg
22636ac495dSmrg; TRUE for r2 or r3.
22736ac495dSmrg(define_predicate "m32c_r2r3_operand"
22836ac495dSmrg  (ior (and (match_code "reg")
22936ac495dSmrg	    (ior (match_test "REGNO(op) == R2_REGNO")
23036ac495dSmrg		 (match_test "REGNO(op) == R3_REGNO")))
23136ac495dSmrg       (and (match_code "subreg")
23236ac495dSmrg	    (match_test "GET_CODE (XEXP (op, 0)) == REG && (REGNO (XEXP (op, 0)) == R2_REGNO || REGNO (XEXP (op, 0)) == R3_REGNO)"))))
23336ac495dSmrg
23436ac495dSmrg; Likewise, plus TRUE for a0..a1.
23536ac495dSmrg(define_predicate "m32c_r2r3a_operand"
23636ac495dSmrg  (ior (match_operand 0 "m32c_r2r3_operand" "")
23736ac495dSmrg       (match_operand 0 "a_operand" "")))
23836ac495dSmrg
23936ac495dSmrg; These two are only for movqi - no subreg limit
24036ac495dSmrg(define_predicate "mra_qi_operand"
24136ac495dSmrg  (and (and (match_operand 0 "m32c_nonimmediate_operand" "")
24236ac495dSmrg	    (not (match_operand 1 "cr_operand" "")))
24336ac495dSmrg       (not (match_operand 1 "m32c_r2r3a_operand" ""))))
24436ac495dSmrg
24536ac495dSmrg(define_predicate "mrai_qi_operand"
24636ac495dSmrg  (and (and (match_operand 0 "m32c_any_operand" "")
24736ac495dSmrg	    (not (match_operand 1 "cr_operand" "")))
24836ac495dSmrg       (not (match_operand 1 "m32c_r2r3a_operand" ""))))
24936ac495dSmrg
25036ac495dSmrg(define_predicate "a_qi_operand"
25136ac495dSmrg  (ior (match_operand 0 "m32c_pseudo" "")
25236ac495dSmrg       (match_operand 1 "a_operand" "")))
25336ac495dSmrg
25436ac495dSmrg; TRUE for comparisons we support.
25536ac495dSmrg(define_predicate "m32c_cmp_operator"
25636ac495dSmrg  (match_code "eq,ne,gt,gtu,lt,ltu,ge,geu,le,leu"))
25736ac495dSmrg
25836ac495dSmrg(define_predicate "m32c_eqne_operator"
25936ac495dSmrg  (match_code "eq,ne"))
26036ac495dSmrg
26136ac495dSmrg; TRUE for mem0
26236ac495dSmrg(define_predicate "m32c_mem0_operand"
26336ac495dSmrg  (ior (match_operand 0 "m32c_pseudo" "")
26436ac495dSmrg       (and (match_code "reg")
26536ac495dSmrg	    (match_test "REGNO(op) == MEM0_REGNO"))))
26636ac495dSmrg
26736ac495dSmrg; TRUE for things the call patterns can return.
26836ac495dSmrg(define_predicate "m32c_return_operand"
26936ac495dSmrg  (ior (match_operand 0 "m32c_r0_operand")
27036ac495dSmrg       (ior (match_operand 0 "m32c_mem0_operand")
27136ac495dSmrg	    (match_code "parallel"))))
27236ac495dSmrg
27336ac495dSmrg; TRUE for constants we can multiply pointers by
27436ac495dSmrg(define_predicate "m32c_psi_scale"
27536ac495dSmrg  (and (match_operand 0 "const_int_operand")
27636ac495dSmrg       (match_test "satisfies_constraint_Ilb (op)")))
27736ac495dSmrg
27836ac495dSmrg; TRUE for one bit set (bit) or clear (mask) out of N bits.
27936ac495dSmrg
28036ac495dSmrg(define_predicate "m32c_1bit8_operand"
28136ac495dSmrg  (and (match_operand 0 "const_int_operand")
28236ac495dSmrg       (match_test "satisfies_constraint_Ilb (op)")))
28336ac495dSmrg
28436ac495dSmrg(define_predicate "m32c_1bit16_operand"
28536ac495dSmrg  (and (match_operand 0 "const_int_operand")
28636ac495dSmrg       (match_test "satisfies_constraint_Ilw (op)")))
28736ac495dSmrg
28836ac495dSmrg(define_predicate "m32c_1mask8_operand"
28936ac495dSmrg  (and (match_operand 0 "const_int_operand")
29036ac495dSmrg       (match_test "satisfies_constraint_ImB (op)")))
29136ac495dSmrg
29236ac495dSmrg(define_predicate "m32c_1mask16_operand"
29336ac495dSmrg  (and (match_operand 0 "const_int_operand")
29436ac495dSmrg       (match_test "satisfies_constraint_Imw (op)")))
295