predicates.md revision 1.10 1 1.1 mrg /* Predicates for TI C6X
2 1.10 mrg Copyright (C) 2010-2022 Free Software Foundation, Inc.
3 1.1 mrg Contributed by Andrew Jenner <andrew (at) codesourcery.com>
4 1.1 mrg Contributed by Bernd Schmidt <bernds (at) codesourcery.com>
5 1.1 mrg
6 1.1 mrg This file is part of GCC.
7 1.1 mrg
8 1.1 mrg GCC is free software; you can redistribute it and/or modify it
9 1.1 mrg under the terms of the GNU General Public License as published
10 1.1 mrg by the Free Software Foundation; either version 3, or (at your
11 1.1 mrg option) any later version.
12 1.1 mrg
13 1.1 mrg GCC is distributed in the hope that it will be useful, but WITHOUT
14 1.1 mrg ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 1.1 mrg or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 1.1 mrg License for more details.
17 1.1 mrg
18 1.1 mrg You should have received a copy of the GNU General Public License
19 1.1 mrg along with GCC; see the file COPYING3. If not see
20 1.1 mrg <http://www.gnu.org/licenses/>. */
21 1.1 mrg
22 1.1 mrg (define_predicate "reg_or_const_int_operand"
23 1.1 mrg (ior (match_operand 0 "register_operand")
24 1.1 mrg (match_operand 0 "const_int_operand")))
25 1.1 mrg
26 1.1 mrg (define_predicate "const_vector_operand"
27 1.1 mrg (match_code "const_vector"))
28 1.1 mrg
29 1.1 mrg (define_predicate "scst5_operand"
30 1.1 mrg (and (match_operand 0 "const_int_operand")
31 1.1 mrg (match_test "satisfies_constraint_Is5 (op)")))
32 1.1 mrg
33 1.1 mrg (define_predicate "reg_or_ucst4_operand"
34 1.1 mrg (ior (match_operand 0 "register_operand")
35 1.1 mrg (and (match_operand 0 "const_int_operand")
36 1.1 mrg (match_test "satisfies_constraint_Iu4 (op)"))))
37 1.1 mrg
38 1.1 mrg (define_predicate "reg_or_scst5_operand"
39 1.1 mrg (ior (match_operand 0 "register_operand")
40 1.1 mrg (match_operand 0 "scst5_operand")))
41 1.1 mrg
42 1.1 mrg (define_predicate "reg_or_ucst5_operand"
43 1.1 mrg (ior (match_operand 0 "register_operand")
44 1.1 mrg (and (match_operand 0 "const_int_operand")
45 1.1 mrg (match_test "satisfies_constraint_Iu5 (op)"))))
46 1.1 mrg
47 1.1 mrg (define_predicate "addsi_operand"
48 1.1 mrg (ior (match_operand 0 "register_operand")
49 1.1 mrg (and (match_operand 0 "const_int_operand")
50 1.1 mrg (match_test "satisfies_constraint_IsB (op)"))))
51 1.1 mrg
52 1.1 mrg (define_predicate "andsi_operand"
53 1.1 mrg (ior (match_operand 0 "reg_or_scst5_operand")
54 1.1 mrg (and (match_operand 0 "const_int_operand")
55 1.1 mrg (match_test "satisfies_constraint_Jc (op)"))))
56 1.1 mrg
57 1.1 mrg (define_predicate "iorsi_operand"
58 1.1 mrg (ior (match_operand 0 "reg_or_scst5_operand")
59 1.1 mrg (and (match_operand 0 "const_int_operand")
60 1.1 mrg (match_test "satisfies_constraint_Js (op)"))))
61 1.1 mrg
62 1.1 mrg (define_predicate "insv_operand"
63 1.1 mrg (and (match_operand 0 "const_int_operand")
64 1.1 mrg (match_test "INTVAL (op) == 0 || INTVAL (op) == -1")))
65 1.1 mrg
66 1.1 mrg (define_predicate "c6x_jump_operand"
67 1.1 mrg (match_code "label_ref,symbol_ref,reg"))
68 1.1 mrg
69 1.1 mrg (define_predicate "c6x_call_operand"
70 1.1 mrg (ior (match_code "symbol_ref,reg")
71 1.1 mrg (and (match_code "subreg")
72 1.1 mrg (match_test "GET_CODE (XEXP (op, 0)) == REG")))
73 1.1 mrg {
74 1.1 mrg /* The linker transforms jumps to undefined weak symbols in a way that
75 1.1 mrg is incompatible with our code generation. */
76 1.1 mrg return (GET_CODE (op) != SYMBOL_REF
77 1.1 mrg || (!SYMBOL_REF_WEAK (op)
78 1.1 mrg && !c6x_long_call_p (op)));
79 1.1 mrg })
80 1.1 mrg
81 1.1 mrg ;; Returns 1 if OP is a symbolic operand, i.e. a symbol_ref or a label_ref,
82 1.1 mrg ;; possibly with an offset.
83 1.1 mrg (define_predicate "symbolic_operand"
84 1.1 mrg (ior (match_code "symbol_ref,label_ref")
85 1.1 mrg (and (match_code "const")
86 1.1 mrg (match_test "GET_CODE (XEXP (op,0)) == PLUS
87 1.1 mrg && (GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
88 1.1 mrg || GET_CODE (XEXP (XEXP (op, 0), 0)) == LABEL_REF)
89 1.1 mrg && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT"))))
90 1.1 mrg
91 1.1 mrg (define_predicate "const_int_or_symbolic_operand"
92 1.1 mrg (ior (match_operand 0 "symbolic_operand")
93 1.1 mrg (match_operand 0 "const_int_operand")))
94 1.1 mrg
95 1.1 mrg ;; Return nonzero iff OP is one of the integer constants 2, 4 or 8.
96 1.1 mrg (define_predicate "adda_scale_operand"
97 1.1 mrg (and (match_code "const_int")
98 1.1 mrg (match_test "INTVAL (op) == 2 || INTVAL (op) == 4
99 1.1 mrg || ((TARGET_INSNS_64 || TARGET_INSNS_67)
100 1.1 mrg && INTVAL (op) == 8)")))
101 1.1 mrg
102 1.1 mrg ;; Return nonzero iff OP is one of the integer constants 2 or 4.
103 1.1 mrg (define_predicate "suba_scale_operand"
104 1.1 mrg (and (match_code "const_int")
105 1.1 mrg (match_test "INTVAL (op) == 2 || INTVAL (op) == 4")))
106 1.1 mrg
107 1.1 mrg ;; True if this operator is valid for predication.
108 1.1 mrg (define_predicate "predicate_operator"
109 1.1 mrg (match_code "eq,ne"))
110 1.1 mrg
111 1.1 mrg (define_predicate "c6x_comparison_operator"
112 1.1 mrg (match_code "eq,ltu,gtu,lt,gt"))
113 1.1 mrg
114 1.1 mrg (define_predicate "non_c6x_comparison_operator"
115 1.1 mrg (match_code "ne,leu,geu,le,ge"))
116 1.1 mrg
117 1.1 mrg ;; FP Comparisons handled by c6x_expand_compare.
118 1.1 mrg (define_predicate "c6x_fp_comparison_operator"
119 1.1 mrg (ior (match_code "eq,lt,gt,le,ge")
120 1.1 mrg (and (match_test "TARGET_FP")
121 1.1 mrg (match_code "ltgt,uneq,unlt,ungt,unle,unge,ordered,unordered"))))
122 1.1 mrg
123 1.1 mrg (define_predicate "c6x_any_comparison_operand"
124 1.1 mrg (match_code "eq,lt,gt,le,ge,ltu,gtu")
125 1.1 mrg {
126 1.1 mrg rtx op0 = XEXP (op, 0);
127 1.1 mrg rtx op1 = XEXP (op, 1);
128 1.1 mrg if (ltugtu_operator (op, SImode)
129 1.1 mrg && register_operand (op0, SImode)
130 1.1 mrg && ((TARGET_INSNS_64 && reg_or_ucst5_operand (op1, SImode))
131 1.1 mrg || (!TARGET_INSNS_64 && reg_or_ucst4_operand (op1, SImode))))
132 1.1 mrg return true;
133 1.1 mrg if (eqltgt_operator (op, SImode)
134 1.1 mrg && register_operand (op0, SImode)
135 1.1 mrg && reg_or_scst5_operand (op1, SImode))
136 1.1 mrg return true;
137 1.1 mrg if (!TARGET_FP)
138 1.1 mrg return false;
139 1.1 mrg if (!eqltgt_operator (op, SFmode) && !eqltgt_operator (op, DFmode))
140 1.1 mrg return false;
141 1.1 mrg if (register_operand (op0, GET_MODE (op))
142 1.1 mrg && register_operand (op1, GET_MODE (op)))
143 1.1 mrg return true;
144 1.1 mrg return false;
145 1.1 mrg })
146 1.1 mrg
147 1.1 mrg (define_predicate "ltugtu_operator"
148 1.1 mrg (match_code "ltu,gtu"))
149 1.1 mrg
150 1.1 mrg (define_predicate "eqltgt_operator"
151 1.1 mrg (match_code "eq,lt,gt"))
152 1.1 mrg
153 1.1 mrg (define_predicate "eqne_operator"
154 1.1 mrg (match_code "eq,ne"))
155 1.1 mrg
156 1.1 mrg (define_predicate "predicate_register"
157 1.1 mrg (and (match_code "reg")
158 1.1 mrg (ior (match_test "REGNO_REG_CLASS (REGNO (op)) == PREDICATE_A_REGS")
159 1.1 mrg (match_test "REGNO_REG_CLASS (REGNO (op)) == PREDICATE_B_REGS"))))
160 1.1 mrg
161 1.1 mrg ;; Allow const_ints for things like the real_mult patterns.
162 1.1 mrg (define_predicate "a_register"
163 1.1 mrg (ior (and (match_code "reg")
164 1.1 mrg (match_test "A_REGNO_P (REGNO (op))"))
165 1.1 mrg (and (match_code "const_int")
166 1.1 mrg (match_test "A_REGNO_P (INTVAL (op))"))))
167 1.1 mrg
168 1.1 mrg (define_predicate "b_register"
169 1.1 mrg (ior (and (match_code "reg")
170 1.1 mrg (match_test "B_REGNO_P (REGNO (op))"))
171 1.1 mrg (and (match_code "const_int")
172 1.1 mrg (match_test "B_REGNO_P (INTVAL (op))"))))
173 1.1 mrg
174 1.1 mrg (define_predicate "pic_register_operand"
175 1.1 mrg (and (match_code "reg")
176 1.1 mrg (match_test "op == pic_offset_table_rtx")))
177 1.1 mrg
178 1.1 mrg ;; True if OP refers to a symbol in the sdata section.
179 1.1 mrg (define_predicate "sdata_symbolic_operand"
180 1.1 mrg (match_code "symbol_ref,const")
181 1.1 mrg {
182 1.1 mrg HOST_WIDE_INT offset = 0, size = 0;
183 1.1 mrg tree t;
184 1.1 mrg
185 1.1 mrg switch (GET_CODE (op))
186 1.1 mrg {
187 1.1 mrg case CONST:
188 1.1 mrg op = XEXP (op, 0);
189 1.1 mrg if (GET_CODE (op) != PLUS
190 1.1 mrg || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
191 1.1 mrg || GET_CODE (XEXP (op, 1)) != CONST_INT)
192 1.1 mrg return false;
193 1.1 mrg offset = INTVAL (XEXP (op, 1));
194 1.1 mrg op = XEXP (op, 0);
195 1.1 mrg /* FALLTHRU */
196 1.1 mrg
197 1.1 mrg case SYMBOL_REF:
198 1.1 mrg /* For shared libraries, only allow symbols we know are local.
199 1.1 mrg For executables, the linker knows to create copy relocs if
200 1.1 mrg necessary so we can use DP-relative addressing for all small
201 1.1 mrg objects. */
202 1.1 mrg if ((c6x_initial_flag_pic && !SYMBOL_REF_LOCAL_P (op))
203 1.1 mrg || !SYMBOL_REF_SMALL_P (op))
204 1.1 mrg return false;
205 1.1 mrg
206 1.1 mrg /* Note that in addition to DECLs, we can get various forms
207 1.1 mrg of constants here. */
208 1.1 mrg t = SYMBOL_REF_DECL (op);
209 1.1 mrg if (DECL_P (t))
210 1.1 mrg t = DECL_SIZE_UNIT (t);
211 1.1 mrg else
212 1.1 mrg t = TYPE_SIZE_UNIT (TREE_TYPE (t));
213 1.3 mrg if (t && tree_fits_shwi_p (t))
214 1.1 mrg {
215 1.3 mrg size = tree_to_shwi (t);
216 1.1 mrg if (size < 0)
217 1.1 mrg size = 0;
218 1.1 mrg }
219 1.1 mrg
220 1.1 mrg /* Don't allow addressing outside the object. */
221 1.1 mrg return (offset >= 0 && offset <= size);
222 1.1 mrg
223 1.1 mrg default:
224 1.1 mrg gcc_unreachable ();
225 1.1 mrg }
226 1.1 mrg })
227