Debian Codegraph @

gcc/config/arm/predicates.md

raw
1 ;; Predicate definitions for ARM and Thumb
2 ;; Copyright (C) 2004-2025 Free Software Foundation, Inc.
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
9 ;; by the Free Software Foundation; either version 3, or (at your
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
18 ;; along with GCC; see the file COPYING3. If not see
19 ;; <http://www.gnu.org/licenses/>.
20
21 (include "common.md")
22
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 ??? */
31 return (REG_P (op)
32 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
33 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
34 })
35
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
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
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
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
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
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
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
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
76 ;; True if the immediate is multiple of 8 and in range of -/+ 1016 for MVE.
77 (define_predicate "mve_vldrd_immediate"
78 (match_test "satisfies_constraint_Ri (op)"))
79
80 ;; True if the immediate is multiple of 2 and in range of -/+ 252 for MVE.
81 (define_predicate "mve_vstrw_immediate"
82 (match_test "satisfies_constraint_Rl (op)"))
83
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
101 (define_predicate "vpr_register_operand"
102 (match_code "reg,subreg")
103 {
104 if (SUBREG_P (op))
105 {
106 /* Only allow subregs if they are strictly type punning. */
107 if ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (op)))
108 != GET_MODE_SIZE (GET_MODE (op)))
109 || SUBREG_BYTE (op) != 0)
110 return false;
111 op = SUBREG_REG (op);
112 }
113
114 return (REG_P (op)
115 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
116 || IS_VPR_REGNUM (REGNO (op))));
117 })
118
119 (define_predicate "imm_for_neon_inv_logic_operand"
120 (match_code "const_vector")
121 {
122 return ((TARGET_NEON || TARGET_HAVE_MVE)
123 && neon_immediate_valid_for_logic (op, mode, 1, NULL, NULL));
124 })
125
126 (define_predicate "neon_inv_logic_op2"
127 (ior (match_operand 0 "imm_for_neon_inv_logic_operand")
128 (match_operand 0 "s_register_operand")))
129
130 (define_predicate "imm_for_neon_logic_operand"
131 (match_code "const_vector")
132 {
133 return ((TARGET_NEON || TARGET_HAVE_MVE)
134 && neon_immediate_valid_for_logic (op, mode, 0, NULL, NULL));
135 })
136
137 (define_predicate "neon_logic_op2"
138 (ior (match_operand 0 "imm_for_neon_logic_operand")
139 (match_operand 0 "s_register_operand")))
140
141 ;; Any general register.
142 (define_predicate "arm_hard_general_register_operand"
143 (match_code "reg")
144 {
145 return REGNO (op) <= LAST_ARM_REGNUM;
146 })
147
148 ;; A low register.
149 (define_predicate "low_register_operand"
150 (and (match_code "reg")
151 (match_test "REGNO (op) <= LAST_LO_REGNUM")))
152
153 ;; A low register or const_int.
154 (define_predicate "low_reg_or_int_operand"
155 (ior (match_code "const_int")
156 (match_operand 0 "low_register_operand")))
157
158 ;; Any core register, or any pseudo. */
159 (define_predicate "arm_general_register_operand"
160 (match_code "reg,subreg")
161 {
162 if (GET_CODE (op) == SUBREG)
163 op = SUBREG_REG (op);
164
165 return (REG_P (op)
166 && (REGNO (op) <= LAST_ARM_REGNUM
167 || REGNO (op) >= FIRST_PSEUDO_REGISTER));
168 })
169
170 ;; Low core register, or any pseudo.
171 (define_predicate "arm_low_register_operand"
172 (match_code "reg,subreg")
173 {
174 if (GET_CODE (op) == SUBREG)
175 op = SUBREG_REG (op);
176
177 return (REG_P (op)
178 && (REGNO (op) <= LAST_LO_REGNUM
179 || REGNO (op) >= FIRST_PSEUDO_REGISTER));
180 })
181
182 (define_predicate "arm_general_adddi_operand"
183 (ior (match_operand 0 "arm_general_register_operand")
184 (and (match_code "const_int")
185 (match_test "const_ok_for_dimode_op (INTVAL (op), PLUS)"))))
186
187 (define_predicate "vfp_register_operand"
188 (match_code "reg,subreg")
189 {
190 if (GET_CODE (op) == SUBREG)
191 op = SUBREG_REG (op);
192
193 /* We don't consider registers whose class is NO_REGS
194 to be a register operand. */
195 return (REG_P (op)
196 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
197 || REGNO_REG_CLASS (REGNO (op)) == VFP_D0_D7_REGS
198 || REGNO_REG_CLASS (REGNO (op)) == VFP_LO_REGS
199 || (TARGET_VFPD32
200 && REGNO_REG_CLASS (REGNO (op)) == VFP_HI_REGS)));
201 })
202
203 (define_predicate "vfp_hard_register_operand"
204 (match_code "reg")
205 {
206 return (IS_VFP_REGNUM (REGNO (op)));
207 })
208
209 (define_predicate "zero_operand"
210 (and (match_code "const_int,const_double,const_vector")
211 (match_test "op == CONST0_RTX (mode)")))
212
213 (define_predicate "minus_one_operand"
214 (and (match_code "const_int,const_double,const_vector")
215 (match_test "op == CONSTM1_RTX (mode)")))
216
217 ;; Match a register, or zero in the appropriate mode.
218 (define_predicate "reg_or_zero_operand"
219 (ior (match_operand 0 "s_register_operand")
220 (match_operand 0 "zero_operand")))
221
222 (define_special_predicate "subreg_lowpart_operator"
223 (and (match_code "subreg")
224 (match_test "subreg_lowpart_p (op)")))
225
226 ;; Reg, subreg(reg) or const_int.
227 (define_predicate "reg_or_int_operand"
228 (ior (match_code "const_int")
229 (match_operand 0 "s_register_operand")))
230
231 (define_predicate "arm_immediate_operand"
232 (and (match_code "const_int")
233 (match_test "const_ok_for_arm (INTVAL (op))")))
234
235 ;; A constant value which fits into two instructions, each taking
236 ;; an arithmetic constant operand for one of the words.
237 (define_predicate "arm_immediate_di_operand"
238 (and (match_code "const_int,const_double")
239 (match_test "arm_const_double_by_immediates (op)")))
240
241 (define_predicate "arm_neg_immediate_operand"
242 (and (match_code "const_int")
243 (match_test "const_ok_for_arm (-INTVAL (op))")))
244
245 (define_predicate "arm_not_immediate_operand"
246 (and (match_code "const_int")
247 (match_test "const_ok_for_arm (~INTVAL (op))")))
248
249 (define_predicate "const0_operand"
250 (match_test "op == CONST0_RTX (mode)"))
251
252 ;; Something valid on the RHS of an ARM data-processing instruction
253 (define_predicate "arm_rhs_operand"
254 (ior (match_operand 0 "s_register_operand")
255 (match_operand 0 "arm_immediate_operand")))
256
257 (define_predicate "arm_rhsm_operand"
258 (ior (match_operand 0 "arm_rhs_operand")
259 (match_operand 0 "memory_operand")))
260
261 (define_predicate "const_int_I_operand"
262 (and (match_operand 0 "const_int_operand")
263 (match_test "satisfies_constraint_I (op)")))
264
265 (define_predicate "const_int_M_operand"
266 (and (match_operand 0 "const_int_operand")
267 (match_test "satisfies_constraint_M (op)")))
268
269 (define_predicate "const_int_coproc_operand"
270 (and (match_operand 0 "const_int_operand")
271 (match_test "IN_RANGE (UINTVAL (op), 0, ARM_CDE_CONST_COPROC)")
272 (match_test "arm_arch_cde_coproc_bits[UINTVAL (op)] & arm_arch_cde_coproc")))
273
274 (define_predicate "const_int_ccde1_operand"
275 (and (match_operand 0 "const_int_operand")
276 (match_test "IN_RANGE (UINTVAL (op), 0, ARM_CCDE_CONST_1)")))
277
278 (define_predicate "const_int_ccde2_operand"
279 (and (match_operand 0 "const_int_operand")
280 (match_test "IN_RANGE (UINTVAL (op), 0, ARM_CCDE_CONST_2)")))
281
282 (define_predicate "const_int_ccde3_operand"
283 (and (match_operand 0 "const_int_operand")
284 (match_test "IN_RANGE (UINTVAL (op), 0, ARM_CCDE_CONST_3)")))
285
286 (define_predicate "const_int_vcde1_operand"
287 (and (match_operand 0 "const_int_operand")
288 (match_test "IN_RANGE (UINTVAL (op), 0, ARM_VCDE_CONST_1)")))
289
290 (define_predicate "const_int_vcde2_operand"
291 (and (match_operand 0 "const_int_operand")
292 (match_test "IN_RANGE (UINTVAL (op), 0, ARM_VCDE_CONST_2)")))
293
294 (define_predicate "const_int_vcde3_operand"
295 (and (match_operand 0 "const_int_operand")
296 (match_test "IN_RANGE (UINTVAL (op), 0, ARM_VCDE_CONST_3)")))
297
298 (define_predicate "const_int_mve_cde1_operand"
299 (and (match_operand 0 "const_int_operand")
300 (match_test "IN_RANGE (UINTVAL (op), 0, ARM_MVE_CDE_CONST_1)")))
301
302 (define_predicate "const_int_mve_cde2_operand"
303 (and (match_operand 0 "const_int_operand")
304 (match_test "IN_RANGE (UINTVAL (op), 0, ARM_MVE_CDE_CONST_2)")))
305
306 (define_predicate "const_int_mve_cde3_operand"
307 (and (match_operand 0 "const_int_operand")
308 (match_test "IN_RANGE (UINTVAL (op), 0, ARM_MVE_CDE_CONST_3)")))
309
310 ;; This doesn't have to do much because the constant is already checked
311 ;; in the shift_operator predicate.
312 (define_predicate "shift_amount_operand"
313 (ior (and (match_test "TARGET_ARM")
314 (match_operand 0 "s_register_operand"))
315 (match_operand 0 "const_int_operand")))
316
317 (define_predicate "const_neon_scalar_shift_amount_operand"
318 (and (match_code "const_int")
319 (match_test "IN_RANGE (UINTVAL (op), 1, GET_MODE_BITSIZE (mode))")))
320
321 (define_predicate "ssat16_imm"
322 (and (match_code "const_int")
323 (match_test "IN_RANGE (INTVAL (op), 1, 16)")))
324
325 (define_predicate "usat16_imm"
326 (and (match_code "const_int")
327 (match_test "IN_RANGE (INTVAL (op), 0, 15)")))
328
329 (define_predicate "ldrd_strd_offset_operand"
330 (and (match_operand 0 "const_int_operand")
331 (match_test "TARGET_LDRD && offset_ok_for_ldrd_strd (INTVAL (op))")))
332
333 (define_predicate "arm_add_operand"
334 (ior (match_operand 0 "arm_rhs_operand")
335 (match_operand 0 "arm_neg_immediate_operand")))
336
337 (define_predicate "arm_adddi_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), PLUS)"))))
341
342 (define_predicate "arm_anddi_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), AND)"))))
346
347 (define_predicate "arm_iordi_operand"
348 (ior (match_operand 0 "s_register_operand")
349 (and (match_code "const_int")
350 (match_test "const_ok_for_dimode_op (INTVAL (op), IOR)"))))
351
352 (define_predicate "arm_xordi_operand"
353 (ior (match_operand 0 "s_register_operand")
354 (and (match_code "const_int")
355 (match_test "const_ok_for_dimode_op (INTVAL (op), XOR)"))))
356
357 (define_predicate "arm_addimm_operand"
358 (ior (match_operand 0 "arm_immediate_operand")
359 (match_operand 0 "arm_neg_immediate_operand")))
360
361 (define_predicate "arm_not_operand"
362 (ior (match_operand 0 "arm_rhs_operand")
363 (match_operand 0 "arm_not_immediate_operand")))
364
365 ;; A constant that can be used with ADC(SBC) or SBC(ADC) when bit-wise
366 ;; inverted. Similar to arm_not_operand, but excludes registers.
367 (define_predicate "arm_adcimm_operand"
368 (ior (match_operand 0 "arm_immediate_operand")
369 (match_operand 0 "arm_not_immediate_operand")))
370
371 (define_predicate "arm_di_operand"
372 (ior (match_operand 0 "s_register_operand")
373 (match_operand 0 "arm_immediate_di_operand")))
374
375 ;; True if the operand is a memory reference which contains an
376 ;; offsettable address.
377 (define_predicate "offsettable_memory_operand"
378 (and (match_code "mem")
379 (match_test
380 "offsettable_address_p (reload_completed | reload_in_progress,
381 mode, XEXP (op, 0))")))
382
383 ;; True if the operand is a memory operand that does not have an
384 ;; automodified base register (and thus will not generate output reloads).
385 (define_predicate "call_memory_operand"
386 (and (match_code "mem")
387 (and (match_test "GET_RTX_CLASS (GET_CODE (XEXP (op, 0)))
388 != RTX_AUTOINC")
389 (match_operand 0 "memory_operand"))))
390
391 (define_predicate "arm_reload_memory_operand"
392 (and (match_code "mem,reg,subreg")
393 (match_test "(!CONSTANT_P (op)
394 && (true_regnum(op) == -1
395 || (REG_P (op)
396 && REGNO (op) >= FIRST_PSEUDO_REGISTER)))")))
397
398 (define_predicate "vfp_compare_operand"
399 (ior (match_operand 0 "s_register_operand")
400 (and (match_code "const_double")
401 (match_test "arm_const_double_rtx (op)"))))
402
403 ;; True for valid index operands.
404 (define_predicate "index_operand"
405 (ior (match_operand 0 "s_register_operand")
406 (and (match_operand 0 "immediate_operand")
407 (match_test "(!CONST_INT_P (op)
408 || (INTVAL (op) < 4096 && INTVAL (op) > -4096))"))))
409
410 ;; True for operators that can be combined with a shift in ARM state.
411 (define_special_predicate "shiftable_operator"
412 (and (match_code "plus,minus,ior,xor,and")
413 (match_test "mode == GET_MODE (op)")))
414
415 (define_special_predicate "shiftable_operator_strict_it"
416 (and (match_code "plus,and")
417 (match_test "mode == GET_MODE (op)")))
418
419 ;; True for logical binary operators.
420 (define_special_predicate "logical_binary_operator"
421 (and (match_code "ior,xor,and")
422 (match_test "mode == GET_MODE (op)")))
423
424 ;; True for commutative operators
425 (define_special_predicate "commutative_binary_operator"
426 (and (match_code "ior,xor,and,plus")
427 (match_test "mode == GET_MODE (op)")))
428
429 ;; True for shift operators.
430 ;; Notes:
431 ;; * mult is only permitted with a constant shift amount
432 ;; * patterns that permit register shift amounts only in ARM mode use
433 ;; shift_amount_operand, patterns that always allow registers do not,
434 ;; so we don't have to worry about that sort of thing here.
435 (define_special_predicate "shift_operator"
436 (and (ior (ior (and (match_code "mult")
437 (match_test "power_of_two_operand (XEXP (op, 1), mode)"))
438 (and (match_code "rotate")
439 (match_test "CONST_INT_P (XEXP (op, 1))
440 && (UINTVAL (XEXP (op, 1))) < 32")))
441 (and (match_code "ashift,ashiftrt,lshiftrt,rotatert")
442 (match_test "!CONST_INT_P (XEXP (op, 1))
443 || (UINTVAL (XEXP (op, 1))) < 32")))
444 (match_test "mode == GET_MODE (op)")))
445
446 (define_special_predicate "shift_nomul_operator"
447 (and (ior (and (match_code "rotate")
448 (match_test "CONST_INT_P (XEXP (op, 1))
449 && (UINTVAL (XEXP (op, 1))) < 32"))
450 (and (match_code "ashift,ashiftrt,lshiftrt,rotatert")
451 (match_test "!CONST_INT_P (XEXP (op, 1))
452 || (UINTVAL (XEXP (op, 1))) < 32")))
453 (match_test "mode == GET_MODE (op)")))
454
455 ;; True for shift operators which can be used with saturation instructions.
456 (define_special_predicate "sat_shift_operator"
457 (and (ior (and (match_code "mult")
458 (match_test "power_of_two_operand (XEXP (op, 1), mode)"))
459 (and (match_code "ashift,ashiftrt")
460 (match_test "CONST_INT_P (XEXP (op, 1))
461 && (UINTVAL (XEXP (op, 1)) < 32)")))
462 (match_test "mode == GET_MODE (op)")))
463
464 ;; True for Armv8.1-M Mainline long shift instructions.
465 (define_predicate "long_shift_imm"
466 (match_test "satisfies_constraint_Pg (op)"))
467
468 (define_predicate "arm_reg_or_long_shift_imm"
469 (ior (match_test "TARGET_THUMB2
470 && arm_general_register_operand (op, GET_MODE (op))")
471 (match_test "satisfies_constraint_Pg (op)")))
472
473 ;; True for MULT, to identify which variant of shift_operator is in use.
474 (define_special_predicate "mult_operator"
475 (match_code "mult"))
476
477 ;; True for operators that have 16-bit thumb variants. */
478 (define_special_predicate "thumb_16bit_operator"
479 (match_code "plus,minus,and,ior,xor"))
480
481 ;; True for EQ & NE
482 (define_special_predicate "equality_operator"
483 (match_code "eq,ne"))
484
485 ;; True for integer comparisons and, if FP is active, for comparisons
486 ;; other than LTGT or UNEQ.
487 (define_special_predicate "expandable_comparison_operator"
488 (match_code "eq,ne,le,lt,ge,gt,geu,gtu,leu,ltu,
489 unordered,ordered,unlt,unle,unge,ungt"))
490
491 ;; Likewise, but only accept comparisons that are directly supported
492 ;; by ARM condition codes.
493 (define_special_predicate "arm_comparison_operator"
494 (and (match_operand 0 "expandable_comparison_operator")
495 (match_test "maybe_get_arm_condition_code (op) != ARM_NV")))
496
497 ;; Likewise, but don't ignore the mode.
498 ;; RTL SET operations require their operands source and destination have
499 ;; the same modes, so we can't ignore the modes there. See PR target/69161.
500 (define_predicate "arm_comparison_operator_mode"
501 (and (match_operand 0 "expandable_comparison_operator")
502 (match_test "maybe_get_arm_condition_code (op) != ARM_NV")))
503
504 (define_special_predicate "arm_comparison_operation"
505 (match_code "eq,ne,le,lt,ge,gt,geu,gtu,leu,ltu,unordered,
506 ordered,unlt,unle,unge,ungt")
507 {
508 if (XEXP (op, 1) != const0_rtx)
509 return false;
510 rtx op0 = XEXP (op, 0);
511 if (!REG_P (op0) || REGNO (op0) != CC_REGNUM)
512 return false;
513 return maybe_get_arm_condition_code (op) != ARM_NV;
514 })
515
516 (define_special_predicate "lt_ge_comparison_operator"
517 (match_code "lt,ge"))
518
519 (define_special_predicate "arm_carry_operation"
520 (match_code "geu,ltu")
521 {
522 if (XEXP (op, 1) != const0_rtx)
523 return false;
524
525 rtx op0 = XEXP (op, 0);
526
527 if (!REG_P (op0) || REGNO (op0) != CC_REGNUM)
528 return false;
529
530 machine_mode ccmode = GET_MODE (op0);
531 if (ccmode == CC_Cmode)
532 return GET_CODE (op) == LTU;
533 else if (ccmode == CCmode || ccmode == CC_RSBmode || ccmode == CC_ADCmode)
534 return GET_CODE (op) == GEU;
535
536 return false;
537 }
538 )
539
540 ;; Match a "borrow" operation for use with SBC. The precise code will
541 ;; depend on the form of the comparison. This is generally the inverse of
542 ;; a carry operation, since the logic of SBC uses "not borrow" in it's
543 ;; calculation.
544 (define_special_predicate "arm_borrow_operation"
545 (match_code "geu,ltu")
546 {
547 if (XEXP (op, 1) != const0_rtx)
548 return false;
549 rtx op0 = XEXP (op, 0);
550 if (!REG_P (op0) || REGNO (op0) != CC_REGNUM)
551 return false;
552 machine_mode ccmode = GET_MODE (op0);
553 if (ccmode == CC_Cmode)
554 return GET_CODE (op) == GEU;
555 else if (ccmode == CCmode || ccmode == CC_RSBmode || ccmode == CC_ADCmode)
556 return GET_CODE (op) == LTU;
557 return false;
558 }
559 )
560
561 ;; The vsel instruction only accepts the ARM condition codes listed below.
562 (define_special_predicate "arm_vsel_comparison_operator"
563 (and (match_operand 0 "expandable_comparison_operator")
564 (match_test "maybe_get_arm_condition_code (op) == ARM_GE
565 || maybe_get_arm_condition_code (op) == ARM_GT
566 || maybe_get_arm_condition_code (op) == ARM_EQ
567 || maybe_get_arm_condition_code (op) == ARM_VS
568 || maybe_get_arm_condition_code (op) == ARM_LT
569 || maybe_get_arm_condition_code (op) == ARM_LE
570 || maybe_get_arm_condition_code (op) == ARM_NE
571 || maybe_get_arm_condition_code (op) == ARM_VC")))
572
573 (define_special_predicate "arm_cond_move_operator"
574 (if_then_else (match_test "arm_restrict_it")
575 (and (match_test "TARGET_VFP5")
576 (match_operand 0 "arm_vsel_comparison_operator"))
577 (match_operand 0 "expandable_comparison_operator")))
578
579 (define_special_predicate "nz_comparison_operator"
580 (match_code "lt,ge,eq,ne"))
581
582 (define_special_predicate "minmax_operator"
583 (and (match_code "smin,smax,umin,umax")
584 (match_test "mode == GET_MODE (op)")))
585
586 (define_special_predicate "cc_register"
587 (and (match_code "reg")
588 (and (match_test "REGNO (op) == CC_REGNUM")
589 (ior (match_test "mode == GET_MODE (op)")
590 (match_test "mode == VOIDmode && GET_MODE_CLASS (GET_MODE (op)) == MODE_CC")))))
591
592 (define_special_predicate "dominant_cc_register"
593 (match_code "reg")
594 {
595 if (mode == VOIDmode)
596 {
597 mode = GET_MODE (op);
598
599 if (GET_MODE_CLASS (mode) != MODE_CC)
600 return false;
601 }
602
603 return (cc_register (op, mode)
604 && (mode == CC_DNEmode
605 || mode == CC_DEQmode
606 || mode == CC_DLEmode
607 || mode == CC_DLTmode
608 || mode == CC_DGEmode
609 || mode == CC_DGTmode
610 || mode == CC_DLEUmode
611 || mode == CC_DLTUmode
612 || mode == CC_DGEUmode
613 || mode == CC_DGTUmode));
614 })
615
616 ;; Any register, including CC
617 (define_predicate "cc_register_operand"
618 (and (match_code "reg")
619 (ior (match_operand 0 "s_register_operand")
620 (match_operand 0 "cc_register"))))
621
622 (define_special_predicate "arm_extendqisi_mem_op"
623 (and (match_operand 0 "memory_operand")
624 (match_test "TARGET_ARM ? arm_legitimate_address_outer_p (mode,
625 XEXP (op, 0),
626 SIGN_EXTEND,
627 0)
628 : memory_address_p (QImode, XEXP (op, 0))")))
629
630 (define_special_predicate "arm_reg_or_extendqisi_mem_op"
631 (ior (match_operand 0 "arm_extendqisi_mem_op")
632 (match_operand 0 "s_register_operand")))
633
634 (define_predicate "power_of_two_operand"
635 (match_code "const_int")
636 {
637 unsigned HOST_WIDE_INT value = INTVAL (op) & 0xffffffff;
638
639 return value != 0 && (value & (value - 1)) == 0;
640 })
641
642 (define_predicate "nonimmediate_di_operand"
643 (match_code "reg,subreg,mem")
644 {
645 if (s_register_operand (op, mode))
646 return true;
647
648 if (GET_CODE (op) == SUBREG)
649 op = SUBREG_REG (op);
650
651 return MEM_P (op) && memory_address_p (DImode, XEXP (op, 0));
652 })
653
654 (define_predicate "di_operand"
655 (ior (match_code "const_int,const_double")
656 (and (match_code "reg,subreg,mem")
657 (match_operand 0 "nonimmediate_di_operand"))))
658
659 (define_predicate "nonimmediate_soft_df_operand"
660 (match_code "reg,subreg,mem")
661 {
662 if (s_register_operand (op, mode))
663 return true;
664
665 if (GET_CODE (op) == SUBREG)
666 op = SUBREG_REG (op);
667
668 return MEM_P (op) && memory_address_p (DFmode, XEXP (op, 0));
669 })
670
671 (define_predicate "soft_df_operand"
672 (ior (match_code "const_double")
673 (and (match_code "reg,subreg,mem")
674 (match_operand 0 "nonimmediate_soft_df_operand"))))
675
676 ;; Predicate for thumb2_movsf_vfp. Compared to general_operand, this
677 ;; forbids constant loaded via literal pool iff literal pools are disabled.
678 (define_predicate "hard_sf_operand"
679 (and (match_operand 0 "general_operand")
680 (ior (not (match_code "const_double"))
681 (not (match_test "arm_disable_literal_pool"))
682 (match_test "satisfies_constraint_Dv (op)"))))
683
684 ;; Predicate for thumb2_movdf_vfp. Compared to soft_df_operand used in
685 ;; movdf_soft_insn, this forbids constant loaded via literal pool iff
686 ;; literal pools are disabled.
687 (define_predicate "hard_df_operand"
688 (and (match_operand 0 "soft_df_operand")
689 (ior (not (match_code "const_double"))
690 (not (match_test "arm_disable_literal_pool"))
691 (match_test "satisfies_constraint_Dy (op)")
692 (match_test "satisfies_constraint_G (op)"))))
693
694 (define_special_predicate "clear_multiple_operation"
695 (match_code "parallel")
696 {
697 return clear_operation_p (op, /*vfp*/false);
698 })
699
700 (define_special_predicate "clear_vfp_multiple_operation"
701 (match_code "parallel")
702 {
703 return clear_operation_p (op, /*vfp*/true);
704 })
705
706 (define_special_predicate "load_multiple_operation"
707 (match_code "parallel")
708 {
709 return ldm_stm_operation_p (op, /*load=*/true, SImode,
710 /*consecutive=*/false,
711 /*return_pc=*/false);
712 })
713
714 (define_special_predicate "store_multiple_operation"
715 (match_code "parallel")
716 {
717 return ldm_stm_operation_p (op, /*load=*/false, SImode,
718 /*consecutive=*/false,
719 /*return_pc=*/false);
720 })
721
722 (define_special_predicate "pop_multiple_return"
723 (match_code "parallel")
724 {
725 return ldm_stm_operation_p (op, /*load=*/true, SImode,
726 /*consecutive=*/false,
727 /*return_pc=*/true);
728 })
729
730 (define_special_predicate "pop_multiple_fp"
731 (match_code "parallel")
732 {
733 return ldm_stm_operation_p (op, /*load=*/true, DFmode,
734 /*consecutive=*/true,
735 /*return_pc=*/false);
736 })
737
738 (define_special_predicate "multi_register_push"
739 (match_code "parallel")
740 {
741 if ((GET_CODE (XVECEXP (op, 0, 0)) != SET)
742 || (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC)
743 || (XINT (SET_SRC (XVECEXP (op, 0, 0)), 1) != UNSPEC_PUSH_MULT))
744 return false;
745
746 return true;
747 })
748
749 (define_predicate "push_mult_memory_operand"
750 (match_code "mem")
751 {
752 /* ??? Given how PUSH_MULT is generated in the prologues, is there
753 any point in testing for thumb1 specially? All of the variants
754 use the same form. */
755 if (TARGET_THUMB1)
756 {
757 /* ??? No attempt is made to represent STMIA, or validate that
758 the stack adjustment matches the register count. This is
759 true of the ARM/Thumb2 path as well. */
760 rtx x = XEXP (op, 0);
761 if (GET_CODE (x) != PRE_MODIFY)
762 return false;
763 if (XEXP (x, 0) != stack_pointer_rtx)
764 return false;
765 x = XEXP (x, 1);
766 if (GET_CODE (x) != PLUS)
767 return false;
768 if (XEXP (x, 0) != stack_pointer_rtx)
769 return false;
770 return CONST_INT_P (XEXP (x, 1));
771 }
772
773 /* ARM and Thumb2 handle pre-modify in their legitimate_address. */
774 return memory_operand (op, mode);
775 })
776
777 ;;-------------------------------------------------------------------------
778 ;;
779 ;; Thumb predicates
780 ;;
781
782 (define_predicate "thumb1_cmp_operand"
783 (ior (and (match_code "reg,subreg")
784 (match_operand 0 "s_register_operand"))
785 (and (match_code "const_int")
786 (match_test "(UINTVAL (op)) < 256"))))
787
788 (define_predicate "thumb1_cmpneg_operand"
789 (and (match_code "const_int")
790 (match_test "INTVAL (op) < 0 && INTVAL (op) > -256")))
791
792 ;; Return TRUE if a result can be stored in OP without clobbering the
793 ;; condition code register. Prior to reload we only accept a
794 ;; register. After reload we have to be able to handle memory as
795 ;; well, since a pseudo may not get a hard reg and reload cannot
796 ;; handle output-reloads on jump insns.
797
798 ;; We could possibly handle mem before reload as well, but that might
799 ;; complicate things with the need to handle increment
800 ;; side-effects.
801 (define_predicate "thumb_cbrch_target_operand"
802 (and (match_code "reg,subreg,mem")
803 (ior (match_operand 0 "s_register_operand")
804 (and (match_test "reload_in_progress || reload_completed")
805 (match_operand 0 "memory_operand")))))
806
807 ;;-------------------------------------------------------------------------
808 ;;
809 ;; iWMMXt predicates
810 ;;
811
812 (define_predicate "imm_or_reg_operand"
813 (ior (match_operand 0 "immediate_operand")
814 (match_operand 0 "register_operand")))
815
816 ;; Neon predicates
817
818 (define_predicate "const_multiple_of_8_operand"
819 (match_code "const_int")
820 {
821 unsigned HOST_WIDE_INT val = INTVAL (op);
822 return (val & 7) == 0;
823 })
824
825 (define_predicate "imm_for_neon_mov_operand"
826 (match_code "const_vector,const_int")
827 {
828 return simd_immediate_valid_for_move (op, mode, NULL, NULL);
829 })
830
831 (define_predicate "imm_for_neon_lshift_operand"
832 (match_code "const_vector")
833 {
834 return neon_immediate_valid_for_shift (op, mode, NULL, NULL, true);
835 })
836
837 (define_predicate "imm_for_neon_rshift_operand"
838 (match_code "const_vector")
839 {
840 return neon_immediate_valid_for_shift (op, mode, NULL, NULL, false);
841 })
842
843 (define_predicate "imm_lshift_or_reg_neon"
844 (ior (match_operand 0 "s_register_operand")
845 (match_operand 0 "imm_for_neon_lshift_operand")))
846
847 (define_predicate "imm_rshift_or_reg_neon"
848 (ior (match_operand 0 "s_register_operand")
849 (match_operand 0 "imm_for_neon_rshift_operand")))
850
851 ;; Predicates for named expanders that overlap multiple ISAs.
852
853 (define_predicate "cmpdi_operand"
854 (and (match_test "TARGET_32BIT")
855 (match_operand 0 "arm_di_operand")))
856
857 ;; True if the operand is memory reference suitable for a ldrex/strex.
858 (define_predicate "arm_sync_memory_operand"
859 (and (match_operand 0 "memory_operand")
860 (match_code "reg" "0")))
861
862 ;; True if the operand is memory reference suitable for a ldrd/strd.
863 (define_predicate "arm_ldrd_memory_operand"
864 (match_test "arm_ldrd_legitimate_address (op)"))
865
866 ;; Predicates for parallel expanders based on mode.
867 (define_special_predicate "vect_par_constant_high"
868 (match_code "parallel")
869 {
870 return arm_simd_check_vect_par_cnst_half_p (op, mode, true);
871 })
872
873 (define_special_predicate "vect_par_constant_low"
874 (match_code "parallel")
875 {
876 return arm_simd_check_vect_par_cnst_half_p (op, mode, false);
877 })
878
879 (define_predicate "const_double_vcvt_power_of_two_reciprocal"
880 (and (match_code "const_double")
881 (match_test "TARGET_32BIT
882 && vfp3_const_double_for_fract_bits (op)")))
883
884 (define_predicate "const_double_vcvt_power_of_two"
885 (and (match_code "const_double")
886 (match_test "TARGET_32BIT
887 && vfp3_const_double_for_bits (op) > 0")))
888
889 (define_predicate "neon_struct_operand"
890 (and (match_code "mem")
891 (match_test "TARGET_32BIT && neon_vector_mem_operand (op, 2, true)")))
892
893 (define_predicate "mve_struct_operand"
894 (and (match_code "mem")
895 (match_test "TARGET_HAVE_MVE && mve_struct_mem_operand (op)")))
896
897 (define_predicate "neon_permissive_struct_operand"
898 (and (match_code "mem")
899 (match_test "TARGET_32BIT && neon_vector_mem_operand (op, 2, false)")))
900
901 (define_predicate "neon_perm_struct_or_reg_operand"
902 (ior (match_operand 0 "neon_permissive_struct_operand")
903 (match_operand 0 "s_register_operand")))
904
905 (define_special_predicate "add_operator"
906 (match_code "plus"))
907
908 (define_predicate "mem_noofs_operand"
909 (and (match_code "mem")
910 (match_code "reg" "0")
911 (match_operand 0 "memory_operand")))
912
913 (define_predicate "call_insn_operand"
914 (ior (and (match_code "symbol_ref")
915 (match_test "!arm_is_long_call_p (SYMBOL_REF_DECL (op))"))
916 (match_operand 0 "s_register_operand")))
917
918 (define_special_predicate "aligned_operand"
919 (ior (not (match_code "mem"))
920 (match_test "MEM_ALIGN (op) >= GET_MODE_ALIGNMENT (mode)")))
921
922 ;; A special predicate that doesn't match a particular mode.
923 (define_special_predicate "arm_any_register_operand"
924 (match_code "reg"))
925
926 ;; General memory operand that disallows Thumb-1 POST_INC.
927 (define_predicate "mem_and_no_t1_wback_op"
928 (and (match_operand 0 "memory_operand")
929 (match_test "!(TARGET_THUMB1 && GET_CODE (XEXP (op, 0)) == POST_INC)")))