]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/arm/predicates.md
Update copyright years.
[thirdparty/gcc.git] / gcc / config / arm / predicates.md
CommitLineData
a657c98a 1;; Predicate definitions for ARM and Thumb
7adcbafe 2;; Copyright (C) 2004-2022 Free Software Foundation, Inc.
a657c98a
RE
3;; Contributed by ARM Ltd.
4
5;; This file is part of GCC.
6
7;; GCC is free software; you can redistribute it and/or modify it
8;; under the terms of the GNU General Public License as published
2f83c7d6 9;; by the Free Software Foundation; either version 3, or (at your
a657c98a
RE
10;; option) any later version.
11
12;; GCC is distributed in the hope that it will be useful, but WITHOUT
13;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15;; 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/>.
a657c98a 20
ae27ce51
QJ
21(include "common.md")
22
a657c98a
RE
23(define_predicate "s_register_operand"
24 (match_code "reg,subreg")
25{
26 if (GET_CODE (op) == SUBREG)
27 op = SUBREG_REG (op);
28 /* We don't consider registers whose class is NO_REGS
29 to be a register operand. */
30 /* XXX might have to check for lo regs only for thumb ??? */
d435a4be 31 return (REG_P (op)
a657c98a
RE
32 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
33 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
34})
35
d91524d5
SP
36(define_predicate "mve_memory_operand"
37 (and (match_code "mem")
38 (match_test "TARGET_32BIT
39 && mve_vector_mem_operand (GET_MODE (op), XEXP (op, 0),
40 false)")))
41
9a810e57
SP
42(define_predicate "mve_scatter_memory"
43 (and (match_code "mem")
44 (match_test "TARGET_HAVE_MVE && REG_P (XEXP (op, 0))
45 && mve_vector_mem_operand (GET_MODE (op), XEXP (op, 0),
46 false)")))
47
4be8cf77
SP
48;; True for immediates in the range of 1 to 16 for MVE.
49(define_predicate "mve_imm_16"
50 (match_test "satisfies_constraint_Rd (op)"))
51
33203b4c
SP
52;; True for immediates in the range of 0 to 7 for MVE.
53(define_predicate "mve_imm_7"
54 (match_test "satisfies_constraint_Ra (op)"))
55
f166a8cd
SP
56;; True for immediates in the range of 1 to 8 for MVE.
57(define_predicate "mve_imm_8"
58 (match_test "satisfies_constraint_Rb (op)"))
59
8165795c
SP
60;; True for immediates in the range of 0 to 15 for MVE.
61(define_predicate "mve_imm_15"
62 (match_test "satisfies_constraint_Rc (op)"))
63
64;; True for immediates in the range of 0 to 31 for MVE.
65(define_predicate "mve_imm_31"
66 (match_test "satisfies_constraint_Re (op)"))
67
f166a8cd
SP
68;; True for immediates in the range of 1 to 32 for MVE.
69(define_predicate "mve_imm_32"
70 (match_test "satisfies_constraint_Rf (op)"))
71
33203b4c
SP
72;; True if the immediate is one among 1, 2, 4 or 8 for MVE.
73(define_predicate "mve_imm_selective_upto_8"
74 (match_test "satisfies_constraint_Rg (op)"))
75
7a5fffa5
SP
76;; True if the immediate is the range +/- 1016 and multiple of 8 for MVE.
77(define_constraint "Ri"
78 "@internal In Thumb-2 state a constant is multiple of 8 and in range
79 of -/+ 1016 for MVE"
80 (and (match_code "const_int")
81 (match_test "TARGET_HAVE_MVE && (-1016 <= ival) && (ival <= 1016)
82 && ((ival % 8) == 0)")))
83
89d75572
TP
84; Predicate for stack protector guard's address in
85; stack_protect_combined_set_insn and stack_protect_combined_test_insn patterns
86(define_predicate "guard_addr_operand"
87 (match_test "true")
88{
89 return (CONSTANT_ADDRESS_P (op)
90 || !targetm.cannot_force_const_mem (mode, op));
91})
92
93; Predicate for stack protector guard in stack_protect_combined_set and
94; stack_protect_combined_test patterns
95(define_predicate "guard_operand"
96 (match_code "mem")
97{
98 return guard_addr_operand (XEXP (op, 0), mode);
99})
100
63c8f7d6
SP
101(define_predicate "vpr_register_operand"
102 (match_code "reg")
103{
104 return REG_P (op)
105 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
106 || IS_VPR_REGNUM (REGNO (op)));
107})
108
1c50eada
KT
109(define_predicate "imm_for_neon_inv_logic_operand"
110 (match_code "const_vector")
111{
11a0beff 112 return ((TARGET_NEON || TARGET_HAVE_MVE)
1c50eada
KT
113 && neon_immediate_valid_for_logic (op, mode, 1, NULL, NULL));
114})
115
116(define_predicate "neon_inv_logic_op2"
117 (ior (match_operand 0 "imm_for_neon_inv_logic_operand")
118 (match_operand 0 "s_register_operand")))
119
b6af05a9
KT
120(define_predicate "imm_for_neon_logic_operand"
121 (match_code "const_vector")
122{
75de6a28 123 return ((TARGET_NEON || TARGET_HAVE_MVE)
b6af05a9
KT
124 && neon_immediate_valid_for_logic (op, mode, 0, NULL, NULL));
125})
126
127(define_predicate "neon_logic_op2"
128 (ior (match_operand 0 "imm_for_neon_logic_operand")
129 (match_operand 0 "s_register_operand")))
130
8b0497de 131;; Any general register.
03158648 132(define_predicate "arm_hard_general_register_operand"
a657c98a
RE
133 (match_code "reg")
134{
03158648 135 return REGNO (op) <= LAST_ARM_REGNUM;
a657c98a
RE
136})
137
5b3e6663
PB
138;; A low register.
139(define_predicate "low_register_operand"
140 (and (match_code "reg")
141 (match_test "REGNO (op) <= LAST_LO_REGNUM")))
142
143;; A low register or const_int.
144(define_predicate "low_reg_or_int_operand"
145 (ior (match_code "const_int")
146 (match_operand 0 "low_register_operand")))
147
a657c98a
RE
148;; Any core register, or any pseudo. */
149(define_predicate "arm_general_register_operand"
150 (match_code "reg,subreg")
151{
152 if (GET_CODE (op) == SUBREG)
153 op = SUBREG_REG (op);
154
d435a4be 155 return (REG_P (op)
a657c98a
RE
156 && (REGNO (op) <= LAST_ARM_REGNUM
157 || REGNO (op) >= FIRST_PSEUDO_REGISTER));
158})
159
6af59870
SP
160;; Low core register, or any pseudo.
161(define_predicate "arm_low_register_operand"
162 (match_code "reg,subreg")
163{
164 if (GET_CODE (op) == SUBREG)
165 op = SUBREG_REG (op);
166
167 return (REG_P (op)
168 && (REGNO (op) <= LAST_LO_REGNUM
169 || REGNO (op) >= FIRST_PSEUDO_REGISTER));
170})
171
fb117b1c
BE
172(define_predicate "arm_general_adddi_operand"
173 (ior (match_operand 0 "arm_general_register_operand")
174 (and (match_code "const_int")
175 (match_test "const_ok_for_dimode_op (INTVAL (op), PLUS)"))))
176
4e6f5666
JZ
177(define_predicate "vfp_register_operand"
178 (match_code "reg,subreg")
179{
180 if (GET_CODE (op) == SUBREG)
181 op = SUBREG_REG (op);
182
183 /* We don't consider registers whose class is NO_REGS
184 to be a register operand. */
d435a4be 185 return (REG_P (op)
4e6f5666 186 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
34db4735 187 || REGNO_REG_CLASS (REGNO (op)) == VFP_D0_D7_REGS
4e6f5666
JZ
188 || REGNO_REG_CLASS (REGNO (op)) == VFP_LO_REGS
189 || (TARGET_VFPD32
635408da 190 && REGNO_REG_CLASS (REGNO (op)) == VFP_HI_REGS)));
4e6f5666
JZ
191})
192
315d7bd4
CL
193(define_predicate "vfp_hard_register_operand"
194 (match_code "reg")
195{
196 return (IS_VFP_REGNUM (REGNO (op)));
197})
198
681676df
RE
199(define_predicate "zero_operand"
200 (and (match_code "const_int,const_double,const_vector")
201 (match_test "op == CONST0_RTX (mode)")))
202
d9937da0
PK
203(define_predicate "minus_one_operand"
204 (and (match_code "const_int,const_double,const_vector")
205 (match_test "op == CONSTM1_RTX (mode)")))
206
681676df
RE
207;; Match a register, or zero in the appropriate mode.
208(define_predicate "reg_or_zero_operand"
209 (ior (match_operand 0 "s_register_operand")
210 (match_operand 0 "zero_operand")))
211
fa01135d
RE
212(define_special_predicate "subreg_lowpart_operator"
213 (and (match_code "subreg")
214 (match_test "subreg_lowpart_p (op)")))
215
a657c98a
RE
216;; Reg, subreg(reg) or const_int.
217(define_predicate "reg_or_int_operand"
218 (ior (match_code "const_int")
219 (match_operand 0 "s_register_operand")))
220
221(define_predicate "arm_immediate_operand"
222 (and (match_code "const_int")
223 (match_test "const_ok_for_arm (INTVAL (op))")))
224
73160ba9
DJ
225;; A constant value which fits into two instructions, each taking
226;; an arithmetic constant operand for one of the words.
227(define_predicate "arm_immediate_di_operand"
228 (and (match_code "const_int,const_double")
229 (match_test "arm_const_double_by_immediates (op)")))
230
a657c98a
RE
231(define_predicate "arm_neg_immediate_operand"
232 (and (match_code "const_int")
233 (match_test "const_ok_for_arm (-INTVAL (op))")))
234
235(define_predicate "arm_not_immediate_operand"
236 (and (match_code "const_int")
237 (match_test "const_ok_for_arm (~INTVAL (op))")))
238
f0c6475a 239(define_predicate "const0_operand"
d1fb6940 240 (match_test "op == CONST0_RTX (mode)"))
f0c6475a 241
a657c98a
RE
242;; Something valid on the RHS of an ARM data-processing instruction
243(define_predicate "arm_rhs_operand"
244 (ior (match_operand 0 "s_register_operand")
245 (match_operand 0 "arm_immediate_operand")))
246
247(define_predicate "arm_rhsm_operand"
248 (ior (match_operand 0 "arm_rhs_operand")
249 (match_operand 0 "memory_operand")))
250
fc02bcca
JL
251(define_predicate "const_int_I_operand"
252 (and (match_operand 0 "const_int_operand")
253 (match_test "satisfies_constraint_I (op)")))
254
255(define_predicate "const_int_M_operand"
256 (and (match_operand 0 "const_int_operand")
257 (match_test "satisfies_constraint_M (op)")))
258
07b9bfd0
DZ
259(define_predicate "const_int_coproc_operand"
260 (and (match_operand 0 "const_int_operand")
261 (match_test "IN_RANGE (UINTVAL (op), 0, ARM_CDE_CONST_COPROC)")
262 (match_test "arm_arch_cde_coproc_bits[UINTVAL (op)] & arm_arch_cde_coproc")))
263
a5f3c89e
MM
264(define_predicate "const_int_ccde1_operand"
265 (and (match_operand 0 "const_int_operand")
266 (match_test "IN_RANGE (UINTVAL (op), 0, ARM_CCDE_CONST_1)")))
267
268(define_predicate "const_int_ccde2_operand"
269 (and (match_operand 0 "const_int_operand")
270 (match_test "IN_RANGE (UINTVAL (op), 0, ARM_CCDE_CONST_2)")))
271
272(define_predicate "const_int_ccde3_operand"
273 (and (match_operand 0 "const_int_operand")
274 (match_test "IN_RANGE (UINTVAL (op), 0, ARM_CCDE_CONST_3)")))
275
07b9bfd0
DZ
276(define_predicate "const_int_vcde1_operand"
277 (and (match_operand 0 "const_int_operand")
278 (match_test "IN_RANGE (UINTVAL (op), 0, ARM_VCDE_CONST_1)")))
279
280(define_predicate "const_int_vcde2_operand"
281 (and (match_operand 0 "const_int_operand")
282 (match_test "IN_RANGE (UINTVAL (op), 0, ARM_VCDE_CONST_2)")))
283
284(define_predicate "const_int_vcde3_operand"
285 (and (match_operand 0 "const_int_operand")
286 (match_test "IN_RANGE (UINTVAL (op), 0, ARM_VCDE_CONST_3)")))
287
78bf9163
MM
288(define_predicate "const_int_mve_cde1_operand"
289 (and (match_operand 0 "const_int_operand")
290 (match_test "IN_RANGE (UINTVAL (op), 0, ARM_MVE_CDE_CONST_1)")))
291
292(define_predicate "const_int_mve_cde2_operand"
293 (and (match_operand 0 "const_int_operand")
294 (match_test "IN_RANGE (UINTVAL (op), 0, ARM_MVE_CDE_CONST_2)")))
295
296(define_predicate "const_int_mve_cde3_operand"
297 (and (match_operand 0 "const_int_operand")
298 (match_test "IN_RANGE (UINTVAL (op), 0, ARM_MVE_CDE_CONST_3)")))
299
55cdadd5
AS
300;; This doesn't have to do much because the constant is already checked
301;; in the shift_operator predicate.
c29e2982
BS
302(define_predicate "shift_amount_operand"
303 (ior (and (match_test "TARGET_ARM")
304 (match_operand 0 "s_register_operand"))
55cdadd5 305 (match_operand 0 "const_int_operand")))
c29e2982 306
36ba4aae
IR
307(define_predicate "const_neon_scalar_shift_amount_operand"
308 (and (match_code "const_int")
dec21bbc 309 (match_test "IN_RANGE (UINTVAL (op), 1, GET_MODE_BITSIZE (mode))")))
36ba4aae 310
0775830a
KT
311(define_predicate "ssat16_imm"
312 (and (match_code "const_int")
313 (match_test "IN_RANGE (INTVAL (op), 1, 16)")))
314
315(define_predicate "usat16_imm"
316 (and (match_code "const_int")
317 (match_test "IN_RANGE (INTVAL (op), 0, 15)")))
318
56289ed2
SD
319(define_predicate "ldrd_strd_offset_operand"
320 (and (match_operand 0 "const_int_operand")
321 (match_test "TARGET_LDRD && offset_ok_for_ldrd_strd (INTVAL (op))")))
322
a657c98a
RE
323(define_predicate "arm_add_operand"
324 (ior (match_operand 0 "arm_rhs_operand")
325 (match_operand 0 "arm_neg_immediate_operand")))
326
44cd6810
WG
327(define_predicate "arm_adddi_operand"
328 (ior (match_operand 0 "s_register_operand")
329 (and (match_code "const_int")
330 (match_test "const_ok_for_dimode_op (INTVAL (op), PLUS)"))))
331
1ea95660
WD
332(define_predicate "arm_anddi_operand"
333 (ior (match_operand 0 "s_register_operand")
334 (and (match_code "const_int")
335 (match_test "const_ok_for_dimode_op (INTVAL (op), AND)"))))
336
337(define_predicate "arm_iordi_operand"
338 (ior (match_operand 0 "s_register_operand")
339 (and (match_code "const_int")
340 (match_test "const_ok_for_dimode_op (INTVAL (op), IOR)"))))
341
342(define_predicate "arm_xordi_operand"
343 (ior (match_operand 0 "s_register_operand")
344 (and (match_code "const_int")
345 (match_test "const_ok_for_dimode_op (INTVAL (op), XOR)"))))
346
a657c98a
RE
347(define_predicate "arm_addimm_operand"
348 (ior (match_operand 0 "arm_immediate_operand")
349 (match_operand 0 "arm_neg_immediate_operand")))
350
351(define_predicate "arm_not_operand"
352 (ior (match_operand 0 "arm_rhs_operand")
353 (match_operand 0 "arm_not_immediate_operand")))
354
8b8ab8f4
RE
355;; A constant that can be used with ADC(SBC) or SBC(ADC) when bit-wise
356;; inverted. Similar to arm_not_operand, but excludes registers.
357(define_predicate "arm_adcimm_operand"
358 (ior (match_operand 0 "arm_immediate_operand")
359 (match_operand 0 "arm_not_immediate_operand")))
360
73160ba9
DJ
361(define_predicate "arm_di_operand"
362 (ior (match_operand 0 "s_register_operand")
363 (match_operand 0 "arm_immediate_di_operand")))
364
a657c98a
RE
365;; True if the operand is a memory reference which contains an
366;; offsettable address.
367(define_predicate "offsettable_memory_operand"
368 (and (match_code "mem")
369 (match_test
370 "offsettable_address_p (reload_completed | reload_in_progress,
371 mode, XEXP (op, 0))")))
372
e6add59b
RS
373;; True if the operand is a memory operand that does not have an
374;; automodified base register (and thus will not generate output reloads).
375(define_predicate "call_memory_operand"
376 (and (match_code "mem")
377 (and (match_test "GET_RTX_CLASS (GET_CODE (XEXP (op, 0)))
378 != RTX_AUTOINC")
379 (match_operand 0 "memory_operand"))))
380
a657c98a 381(define_predicate "arm_reload_memory_operand"
9d2da95b 382 (and (match_code "mem,reg,subreg")
a657c98a
RE
383 (match_test "(!CONSTANT_P (op)
384 && (true_regnum(op) == -1
d435a4be 385 || (REG_P (op)
a657c98a
RE
386 && REGNO (op) >= FIRST_PSEUDO_REGISTER)))")))
387
a657c98a
RE
388(define_predicate "vfp_compare_operand"
389 (ior (match_operand 0 "s_register_operand")
390 (and (match_code "const_double")
391 (match_test "arm_const_double_rtx (op)"))))
392
a657c98a
RE
393;; True for valid index operands.
394(define_predicate "index_operand"
395 (ior (match_operand 0 "s_register_operand")
396 (and (match_operand 0 "immediate_operand")
d435a4be 397 (match_test "(!CONST_INT_P (op)
a657c98a
RE
398 || (INTVAL (op) < 4096 && INTVAL (op) > -4096))"))))
399
400;; True for operators that can be combined with a shift in ARM state.
401(define_special_predicate "shiftable_operator"
402 (and (match_code "plus,minus,ior,xor,and")
403 (match_test "mode == GET_MODE (op)")))
404
95b97fac
KT
405(define_special_predicate "shiftable_operator_strict_it"
406 (and (match_code "plus,and")
407 (match_test "mode == GET_MODE (op)")))
408
c112cf2b 409;; True for logical binary operators.
a657c98a
RE
410(define_special_predicate "logical_binary_operator"
411 (and (match_code "ior,xor,and")
412 (match_test "mode == GET_MODE (op)")))
413
37119410
BS
414;; True for commutative operators
415(define_special_predicate "commutative_binary_operator"
416 (and (match_code "ior,xor,and,plus")
417 (match_test "mode == GET_MODE (op)")))
418
a657c98a 419;; True for shift operators.
55cdadd5
AS
420;; Notes:
421;; * mult is only permitted with a constant shift amount
422;; * patterns that permit register shift amounts only in ARM mode use
423;; shift_amount_operand, patterns that always allow registers do not,
424;; so we don't have to worry about that sort of thing here.
a657c98a
RE
425(define_special_predicate "shift_operator"
426 (and (ior (ior (and (match_code "mult")
427 (match_test "power_of_two_operand (XEXP (op, 1), mode)"))
428 (and (match_code "rotate")
d435a4be 429 (match_test "CONST_INT_P (XEXP (op, 1))
dec21bbc 430 && (UINTVAL (XEXP (op, 1))) < 32")))
004d3809
RE
431 (and (match_code "ashift,ashiftrt,lshiftrt,rotatert")
432 (match_test "!CONST_INT_P (XEXP (op, 1))
dec21bbc 433 || (UINTVAL (XEXP (op, 1))) < 32")))
004d3809
RE
434 (match_test "mode == GET_MODE (op)")))
435
436(define_special_predicate "shift_nomul_operator"
437 (and (ior (and (match_code "rotate")
438 (match_test "CONST_INT_P (XEXP (op, 1))
dec21bbc 439 && (UINTVAL (XEXP (op, 1))) < 32"))
55cdadd5 440 (and (match_code "ashift,ashiftrt,lshiftrt,rotatert")
d435a4be 441 (match_test "!CONST_INT_P (XEXP (op, 1))
dec21bbc 442 || (UINTVAL (XEXP (op, 1))) < 32")))
a657c98a
RE
443 (match_test "mode == GET_MODE (op)")))
444
655b30bf
JB
445;; True for shift operators which can be used with saturation instructions.
446(define_special_predicate "sat_shift_operator"
5d216c70
UW
447 (and (ior (and (match_code "mult")
448 (match_test "power_of_two_operand (XEXP (op, 1), mode)"))
449 (and (match_code "ashift,ashiftrt")
d435a4be 450 (match_test "CONST_INT_P (XEXP (op, 1))
dec21bbc 451 && (UINTVAL (XEXP (op, 1)) < 32)")))
655b30bf
JB
452 (match_test "mode == GET_MODE (op)")))
453
a968a40c
MI
454;; True for Armv8.1-M Mainline long shift instructions.
455(define_predicate "long_shift_imm"
456 (match_test "satisfies_constraint_Pg (op)"))
457
458(define_predicate "arm_reg_or_long_shift_imm"
459 (ior (match_test "TARGET_THUMB2
460 && arm_general_register_operand (op, GET_MODE (op))")
461 (match_test "satisfies_constraint_Pg (op)")))
462
c29e2982
BS
463;; True for MULT, to identify which variant of shift_operator is in use.
464(define_special_predicate "mult_operator"
465 (match_code "mult"))
466
5b3e6663
PB
467;; True for operators that have 16-bit thumb variants. */
468(define_special_predicate "thumb_16bit_operator"
469 (match_code "plus,minus,and,ior,xor"))
470
a657c98a
RE
471;; True for EQ & NE
472(define_special_predicate "equality_operator"
473 (match_code "eq,ne"))
474
f90b7a5a
PB
475;; True for integer comparisons and, if FP is active, for comparisons
476;; other than LTGT or UNEQ.
aa0b3f8f
RS
477(define_special_predicate "expandable_comparison_operator"
478 (match_code "eq,ne,le,lt,ge,gt,geu,gtu,leu,ltu,
479 unordered,ordered,unlt,unle,unge,ungt"))
480
481;; Likewise, but only accept comparisons that are directly supported
482;; by ARM condition codes.
a657c98a 483(define_special_predicate "arm_comparison_operator"
aa0b3f8f 484 (and (match_operand 0 "expandable_comparison_operator")
723d95fe 485 (match_test "maybe_get_arm_condition_code (op) != ARM_NV")))
a657c98a 486
ac4bf407
KT
487;; Likewise, but don't ignore the mode.
488;; RTL SET operations require their operands source and destination have
489;; the same modes, so we can't ignore the modes there. See PR target/69161.
490(define_predicate "arm_comparison_operator_mode"
491 (and (match_operand 0 "expandable_comparison_operator")
492 (match_test "maybe_get_arm_condition_code (op) != ARM_NV")))
493
c2bb84be
SD
494(define_special_predicate "arm_comparison_operation"
495 (match_code "eq,ne,le,lt,ge,gt,geu,gtu,leu,ltu,unordered,
496 ordered,unlt,unle,unge,ungt")
497{
498 if (XEXP (op, 1) != const0_rtx)
499 return false;
500 rtx op0 = XEXP (op, 0);
501 if (!REG_P (op0) || REGNO (op0) != CC_REGNUM)
502 return false;
503 return maybe_get_arm_condition_code (op) != ARM_NV;
504})
505
f0c6475a
BS
506(define_special_predicate "lt_ge_comparison_operator"
507 (match_code "lt,ge"))
508
1e271bee
RE
509(define_special_predicate "arm_carry_operation"
510 (match_code "geu,ltu")
511 {
512 if (XEXP (op, 1) != const0_rtx)
513 return false;
514
515 rtx op0 = XEXP (op, 0);
516
517 if (!REG_P (op0) || REGNO (op0) != CC_REGNUM)
518 return false;
519
520 machine_mode ccmode = GET_MODE (op0);
521 if (ccmode == CC_Cmode)
522 return GET_CODE (op) == LTU;
deb254e0 523 else if (ccmode == CCmode || ccmode == CC_RSBmode || ccmode == CC_ADCmode)
1e271bee
RE
524 return GET_CODE (op) == GEU;
525
526 return false;
527 }
528)
529
24990170
RE
530;; Match a "borrow" operation for use with SBC. The precise code will
531;; depend on the form of the comparison. This is generally the inverse of
532;; a carry operation, since the logic of SBC uses "not borrow" in it's
533;; calculation.
534(define_special_predicate "arm_borrow_operation"
535 (match_code "geu,ltu")
536 {
537 if (XEXP (op, 1) != const0_rtx)
538 return false;
539 rtx op0 = XEXP (op, 0);
540 if (!REG_P (op0) || REGNO (op0) != CC_REGNUM)
541 return false;
542 machine_mode ccmode = GET_MODE (op0);
543 if (ccmode == CC_Cmode)
544 return GET_CODE (op) == GEU;
b747c183 545 else if (ccmode == CCmode || ccmode == CC_RSBmode || ccmode == CC_ADCmode)
24990170
RE
546 return GET_CODE (op) == LTU;
547 return false;
548 }
549)
550
a5a4c20a
KT
551;; The vsel instruction only accepts the ARM condition codes listed below.
552(define_special_predicate "arm_vsel_comparison_operator"
553 (and (match_operand 0 "expandable_comparison_operator")
554 (match_test "maybe_get_arm_condition_code (op) == ARM_GE
555 || maybe_get_arm_condition_code (op) == ARM_GT
556 || maybe_get_arm_condition_code (op) == ARM_EQ
557 || maybe_get_arm_condition_code (op) == ARM_VS
558 || maybe_get_arm_condition_code (op) == ARM_LT
559 || maybe_get_arm_condition_code (op) == ARM_LE
560 || maybe_get_arm_condition_code (op) == ARM_NE
561 || maybe_get_arm_condition_code (op) == ARM_VC")))
562
1572e697
KT
563(define_special_predicate "arm_cond_move_operator"
564 (if_then_else (match_test "arm_restrict_it")
c8d61ab8
TP
565 (and (match_test "TARGET_VFP5")
566 (match_operand 0 "arm_vsel_comparison_operator"))
567 (match_operand 0 "expandable_comparison_operator")))
1572e697 568
54138d95 569(define_special_predicate "nz_comparison_operator"
906668bb
BS
570 (match_code "lt,ge,eq,ne"))
571
a657c98a
RE
572(define_special_predicate "minmax_operator"
573 (and (match_code "smin,smax,umin,umax")
574 (match_test "mode == GET_MODE (op)")))
575
576(define_special_predicate "cc_register"
577 (and (match_code "reg")
578 (and (match_test "REGNO (op) == CC_REGNUM")
579 (ior (match_test "mode == GET_MODE (op)")
580 (match_test "mode == VOIDmode && GET_MODE_CLASS (GET_MODE (op)) == MODE_CC")))))
581
582(define_special_predicate "dominant_cc_register"
583 (match_code "reg")
584{
585 if (mode == VOIDmode)
586 {
587 mode = GET_MODE (op);
588
589 if (GET_MODE_CLASS (mode) != MODE_CC)
590 return false;
591 }
592
593 return (cc_register (op, mode)
594 && (mode == CC_DNEmode
595 || mode == CC_DEQmode
596 || mode == CC_DLEmode
597 || mode == CC_DLTmode
598 || mode == CC_DGEmode
599 || mode == CC_DGTmode
600 || mode == CC_DLEUmode
601 || mode == CC_DLTUmode
602 || mode == CC_DGEUmode
603 || mode == CC_DGTUmode));
604})
605
12286f25
TP
606;; Any register, including CC
607(define_predicate "cc_register_operand"
608 (and (match_code "reg")
609 (ior (match_operand 0 "s_register_operand")
610 (match_operand 0 "cc_register"))))
611
a657c98a
RE
612(define_special_predicate "arm_extendqisi_mem_op"
613 (and (match_operand 0 "memory_operand")
8d4f1548
RR
614 (match_test "TARGET_ARM ? arm_legitimate_address_outer_p (mode,
615 XEXP (op, 0),
616 SIGN_EXTEND,
617 0)
618 : memory_address_p (QImode, XEXP (op, 0))")))
a657c98a 619
01577df7
RE
620(define_special_predicate "arm_reg_or_extendqisi_mem_op"
621 (ior (match_operand 0 "arm_extendqisi_mem_op")
622 (match_operand 0 "s_register_operand")))
623
a657c98a
RE
624(define_predicate "power_of_two_operand"
625 (match_code "const_int")
626{
29b40d79 627 unsigned HOST_WIDE_INT value = INTVAL (op) & 0xffffffff;
a657c98a
RE
628
629 return value != 0 && (value & (value - 1)) == 0;
630})
631
632(define_predicate "nonimmediate_di_operand"
633 (match_code "reg,subreg,mem")
634{
635 if (s_register_operand (op, mode))
636 return true;
637
638 if (GET_CODE (op) == SUBREG)
639 op = SUBREG_REG (op);
640
d435a4be 641 return MEM_P (op) && memory_address_p (DImode, XEXP (op, 0));
a657c98a
RE
642})
643
644(define_predicate "di_operand"
645 (ior (match_code "const_int,const_double")
646 (and (match_code "reg,subreg,mem")
647 (match_operand 0 "nonimmediate_di_operand"))))
648
649(define_predicate "nonimmediate_soft_df_operand"
650 (match_code "reg,subreg,mem")
651{
652 if (s_register_operand (op, mode))
653 return true;
654
655 if (GET_CODE (op) == SUBREG)
656 op = SUBREG_REG (op);
657
d435a4be 658 return MEM_P (op) && memory_address_p (DFmode, XEXP (op, 0));
a657c98a
RE
659})
660
661(define_predicate "soft_df_operand"
662 (ior (match_code "const_double")
663 (and (match_code "reg,subreg,mem")
664 (match_operand 0 "nonimmediate_soft_df_operand"))))
665
8d33eae8
TP
666;; Predicate for thumb2_movsf_vfp. Compared to general_operand, this
667;; forbids constant loaded via literal pool iff literal pools are disabled.
668(define_predicate "hard_sf_operand"
669 (and (match_operand 0 "general_operand")
670 (ior (not (match_code "const_double"))
671 (not (match_test "arm_disable_literal_pool"))
672 (match_test "satisfies_constraint_Dv (op)"))))
673
674;; Predicate for thumb2_movdf_vfp. Compared to soft_df_operand used in
675;; movdf_soft_insn, this forbids constant loaded via literal pool iff
676;; literal pools are disabled.
677(define_predicate "hard_df_operand"
678 (and (match_operand 0 "soft_df_operand")
679 (ior (not (match_code "const_double"))
680 (not (match_test "arm_disable_literal_pool"))
681 (match_test "satisfies_constraint_Dy (op)")
682 (match_test "satisfies_constraint_G (op)"))))
683
9722215a
MI
684(define_special_predicate "clear_multiple_operation"
685 (match_code "parallel")
686{
0b1c7b27
MI
687 return clear_operation_p (op, /*vfp*/false);
688})
689
690(define_special_predicate "clear_vfp_multiple_operation"
691 (match_code "parallel")
692{
693 return clear_operation_p (op, /*vfp*/true);
9722215a
MI
694})
695
a657c98a
RE
696(define_special_predicate "load_multiple_operation"
697 (match_code "parallel")
698{
fb40241d
IB
699 return ldm_stm_operation_p (op, /*load=*/true, SImode,
700 /*consecutive=*/false,
701 /*return_pc=*/false);
a657c98a
RE
702})
703
704(define_special_predicate "store_multiple_operation"
705 (match_code "parallel")
706{
fb40241d
IB
707 return ldm_stm_operation_p (op, /*load=*/false, SImode,
708 /*consecutive=*/false,
709 /*return_pc=*/false);
a657c98a
RE
710})
711
3aee1982
IB
712(define_special_predicate "pop_multiple_return"
713 (match_code "parallel")
714{
715 return ldm_stm_operation_p (op, /*load=*/true, SImode,
716 /*consecutive=*/false,
717 /*return_pc=*/true);
718})
719
4b2678f8
IB
720(define_special_predicate "pop_multiple_fp"
721 (match_code "parallel")
722{
723 return ldm_stm_operation_p (op, /*load=*/true, DFmode,
724 /*consecutive=*/true,
725 /*return_pc=*/false);
726})
727
a657c98a
RE
728(define_special_predicate "multi_register_push"
729 (match_code "parallel")
730{
731 if ((GET_CODE (XVECEXP (op, 0, 0)) != SET)
732 || (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC)
733 || (XINT (SET_SRC (XVECEXP (op, 0, 0)), 1) != UNSPEC_PUSH_MULT))
734 return false;
735
736 return true;
737})
738
d018b46e
RH
739(define_predicate "push_mult_memory_operand"
740 (match_code "mem")
741{
742 /* ??? Given how PUSH_MULT is generated in the prologues, is there
743 any point in testing for thumb1 specially? All of the variants
744 use the same form. */
745 if (TARGET_THUMB1)
746 {
747 /* ??? No attempt is made to represent STMIA, or validate that
748 the stack adjustment matches the register count. This is
749 true of the ARM/Thumb2 path as well. */
750 rtx x = XEXP (op, 0);
751 if (GET_CODE (x) != PRE_MODIFY)
752 return false;
753 if (XEXP (x, 0) != stack_pointer_rtx)
754 return false;
755 x = XEXP (x, 1);
756 if (GET_CODE (x) != PLUS)
757 return false;
758 if (XEXP (x, 0) != stack_pointer_rtx)
759 return false;
760 return CONST_INT_P (XEXP (x, 1));
761 }
762
763 /* ARM and Thumb2 handle pre-modify in their legitimate_address. */
764 return memory_operand (op, mode);
765})
766
a657c98a
RE
767;;-------------------------------------------------------------------------
768;;
769;; Thumb predicates
770;;
771
5b3e6663 772(define_predicate "thumb1_cmp_operand"
a657c98a
RE
773 (ior (and (match_code "reg,subreg")
774 (match_operand 0 "s_register_operand"))
775 (and (match_code "const_int")
dec21bbc 776 (match_test "(UINTVAL (op)) < 256"))))
a657c98a 777
5b3e6663 778(define_predicate "thumb1_cmpneg_operand"
a657c98a
RE
779 (and (match_code "const_int")
780 (match_test "INTVAL (op) < 0 && INTVAL (op) > -256")))
781
782;; Return TRUE if a result can be stored in OP without clobbering the
783;; condition code register. Prior to reload we only accept a
784;; register. After reload we have to be able to handle memory as
785;; well, since a pseudo may not get a hard reg and reload cannot
786;; handle output-reloads on jump insns.
787
788;; We could possibly handle mem before reload as well, but that might
789;; complicate things with the need to handle increment
790;; side-effects.
791(define_predicate "thumb_cbrch_target_operand"
792 (and (match_code "reg,subreg,mem")
793 (ior (match_operand 0 "s_register_operand")
794 (and (match_test "reload_in_progress || reload_completed")
795 (match_operand 0 "memory_operand")))))
796
797;;-------------------------------------------------------------------------
798;;
8fd03515 799;; iWMMXt predicates
dae840fc 800;;
8fd03515
XQ
801
802(define_predicate "imm_or_reg_operand"
803 (ior (match_operand 0 "immediate_operand")
804 (match_operand 0 "register_operand")))
a657c98a 805
88f77cba
JB
806;; Neon predicates
807
808(define_predicate "const_multiple_of_8_operand"
809 (match_code "const_int")
810{
811 unsigned HOST_WIDE_INT val = INTVAL (op);
812 return (val & 7) == 0;
813})
814
815(define_predicate "imm_for_neon_mov_operand"
00a3a76a 816 (match_code "const_vector,const_int")
88f77cba 817{
63c8f7d6 818 return simd_immediate_valid_for_move (op, mode, NULL, NULL);
88f77cba
JB
819})
820
31a0c825
DP
821(define_predicate "imm_for_neon_lshift_operand"
822 (match_code "const_vector")
823{
824 return neon_immediate_valid_for_shift (op, mode, NULL, NULL, true);
825})
826
827(define_predicate "imm_for_neon_rshift_operand"
828 (match_code "const_vector")
829{
830 return neon_immediate_valid_for_shift (op, mode, NULL, NULL, false);
831})
832
833(define_predicate "imm_lshift_or_reg_neon"
834 (ior (match_operand 0 "s_register_operand")
835 (match_operand 0 "imm_for_neon_lshift_operand")))
836
837(define_predicate "imm_rshift_or_reg_neon"
838 (ior (match_operand 0 "s_register_operand")
839 (match_operand 0 "imm_for_neon_rshift_operand")))
840
73160ba9
DJ
841;; Predicates for named expanders that overlap multiple ISAs.
842
843(define_predicate "cmpdi_operand"
dae840fc
RE
844 (and (match_test "TARGET_32BIT")
845 (match_operand 0 "arm_di_operand")))
88f77cba 846
999a9cc5
MS
847;; True if the operand is memory reference suitable for a ldrex/strex.
848(define_predicate "arm_sync_memory_operand"
849 (and (match_operand 0 "memory_operand")
850 (match_code "reg" "0")))
851
46b57af1
TB
852;; Predicates for parallel expanders based on mode.
853(define_special_predicate "vect_par_constant_high"
854 (match_code "parallel")
855{
93c590ee 856 return arm_simd_check_vect_par_cnst_half_p (op, mode, true);
46b57af1
TB
857})
858
859(define_special_predicate "vect_par_constant_low"
860 (match_code "parallel")
861{
93c590ee 862 return arm_simd_check_vect_par_cnst_half_p (op, mode, false);
46b57af1 863})
6308e208 864
7f3d8f56
RR
865(define_predicate "const_double_vcvt_power_of_two_reciprocal"
866 (and (match_code "const_double")
00ea1506
RE
867 (match_test "TARGET_32BIT
868 && vfp3_const_double_for_fract_bits (op)")))
c75d51aa
RL
869
870(define_predicate "const_double_vcvt_power_of_two"
871 (and (match_code "const_double")
00ea1506 872 (match_test "TARGET_32BIT
85f5231d 873 && vfp3_const_double_for_bits (op) > 0")))
7f3d8f56 874
12c4ecb1 875(define_predicate "neon_struct_operand"
6308e208 876 (and (match_code "mem")
33255ae3 877 (match_test "TARGET_32BIT && neon_vector_mem_operand (op, 2, true)")))
9a1ea4b9 878
33255ae3
JB
879(define_predicate "neon_permissive_struct_operand"
880 (and (match_code "mem")
881 (match_test "TARGET_32BIT && neon_vector_mem_operand (op, 2, false)")))
882
883(define_predicate "neon_perm_struct_or_reg_operand"
884 (ior (match_operand 0 "neon_permissive_struct_operand")
12c4ecb1
RS
885 (match_operand 0 "s_register_operand")))
886
9a1ea4b9
RR
887(define_special_predicate "add_operator"
888 (match_code "plus"))
18f0fe6b
RH
889
890(define_predicate "mem_noofs_operand"
891 (and (match_code "mem")
892 (match_code "reg" "0")))
9adcfa3c
RR
893
894(define_predicate "call_insn_operand"
10432733
JW
895 (ior (and (match_code "symbol_ref")
896 (match_test "!arm_is_long_call_p (SYMBOL_REF_DECL (op))"))
9adcfa3c 897 (match_operand 0 "s_register_operand")))
70cdb21e
BE
898
899(define_special_predicate "aligned_operand"
900 (ior (not (match_code "mem"))
901 (match_test "MEM_ALIGN (op) >= GET_MODE_ALIGNMENT (mode)")))