Debian Codegraph @

gcc/config/loongarch/predicates.md

raw
1 ;; Predicate definitions for LoongArch target.
2 ;; Copyright (C) 2021-2025 Free Software Foundation, Inc.
3 ;; Contributed by Loongson Ltd.
4 ;; Based on MIPS target for GNU compiler.
5 ;;
6 ;; This file is part of GCC.
7 ;;
8 ;; GCC is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 3, or (at your option)
11 ;; any later version.
12 ;;
13 ;; GCC is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17 ;;
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING3. If not see
20 ;; <http://www.gnu.org/licenses/>.
21
22 (define_predicate "const_uns_arith_operand"
23 (and (match_code "const_int")
24 (match_test "IMM12_OPERAND_UNSIGNED (INTVAL (op))")))
25
26 (define_predicate "uns_arith_operand"
27 (ior (match_operand 0 "const_uns_arith_operand")
28 (match_operand 0 "register_operand")))
29
30 (define_predicate "const_lu32i_operand"
31 (and (match_code "const_int")
32 (match_test "LU32I_OPERAND (INTVAL (op))")))
33
34 (define_predicate "const_lu52i_operand"
35 (and (match_code "const_int")
36 (match_test "LU52I_OPERAND (INTVAL (op))")))
37
38 (define_predicate "const_arith_operand"
39 (and (match_code "const_int")
40 (match_test "IMM12_OPERAND (INTVAL (op))")))
41
42 (define_predicate "const_dual_imm12_operand"
43 (and (match_code "const_int")
44 (match_test "DUAL_IMM12_OPERAND (INTVAL (op))")))
45
46 (define_predicate "const_imm16_operand"
47 (and (match_code "const_int")
48 (match_test "IMM16_OPERAND (INTVAL (op))")))
49
50 (define_predicate "const_addu16i_operand"
51 (and (match_code "const_int")
52 (match_test "ADDU16I_OPERAND (INTVAL (op))")))
53
54 (define_predicate "const_addu16i_imm12_di_operand"
55 (and (match_code "const_int")
56 (match_test "loongarch_addu16i_imm12_operand_p (INTVAL (op), DImode)")))
57
58 (define_predicate "const_addu16i_imm12_si_operand"
59 (and (match_code "const_int")
60 (match_test "loongarch_addu16i_imm12_operand_p (INTVAL (op), SImode)")))
61
62 (define_predicate "const_dual_addu16i_operand"
63 (and (match_code "const_int")
64 (match_test "DUAL_ADDU16I_OPERAND (INTVAL (op))")))
65
66 (define_predicate "arith_operand"
67 (ior (match_operand 0 "const_arith_operand")
68 (match_operand 0 "register_operand")))
69
70 (define_predicate "plus_di_operand"
71 (ior (match_operand 0 "arith_operand")
72 (match_operand 0 "const_dual_imm12_operand")
73 (match_operand 0 "const_addu16i_operand")
74 (match_operand 0 "const_addu16i_imm12_di_operand")
75 (match_operand 0 "const_dual_addu16i_operand")))
76
77 (define_predicate "plus_si_extend_operand"
78 (ior (match_operand 0 "arith_operand")
79 (match_operand 0 "const_dual_imm12_operand")
80 (match_operand 0 "const_addu16i_imm12_si_operand")))
81
82 (define_predicate "plus_si_operand"
83 (ior (match_operand 0 "plus_si_extend_operand")
84 (match_operand 0 "const_addu16i_operand")))
85
86 (define_predicate "const_immalsl_operand"
87 (and (match_code "const_int")
88 (match_test "IN_RANGE (INTVAL (op), 1, 4)")))
89
90 (define_predicate "const_lsx_branch_operand"
91 (and (match_code "const_int")
92 (match_test "IN_RANGE (INTVAL (op), -1024, 1023)")))
93
94 (define_predicate "const_uimm3_operand"
95 (and (match_code "const_int")
96 (match_test "IN_RANGE (INTVAL (op), 0, 7)")))
97
98 (define_predicate "const_8_to_11_operand"
99 (and (match_code "const_int")
100 (match_test "IN_RANGE (INTVAL (op), 8, 11)")))
101
102 (define_predicate "const_12_to_15_operand"
103 (and (match_code "const_int")
104 (match_test "IN_RANGE (INTVAL (op), 12, 15)")))
105
106 (define_predicate "const_uimm4_operand"
107 (and (match_code "const_int")
108 (match_test "IN_RANGE (INTVAL (op), 0, 15)")))
109
110 (define_predicate "const_uimm5_operand"
111 (and (match_code "const_int")
112 (match_test "IN_RANGE (INTVAL (op), 0, 31)")))
113
114 (define_predicate "const_uimm6_operand"
115 (and (match_code "const_int")
116 (match_test "UIMM6_OPERAND (INTVAL (op))")))
117
118 (define_predicate "const_uimm7_operand"
119 (and (match_code "const_int")
120 (match_test "IN_RANGE (INTVAL (op), 0, 127)")))
121
122 (define_predicate "const_uimm8_operand"
123 (and (match_code "const_int")
124 (match_test "IN_RANGE (INTVAL (op), 0, 255)")))
125
126 (define_predicate "const_uimm14_operand"
127 (and (match_code "const_int")
128 (match_test "IN_RANGE (INTVAL (op), 0, 16383)")))
129
130 (define_predicate "const_uimm15_operand"
131 (and (match_code "const_int")
132 (match_test "IN_RANGE (INTVAL (op), 0, 32767)")))
133
134 (define_predicate "const_imm5_operand"
135 (and (match_code "const_int")
136 (match_test "IN_RANGE (INTVAL (op), -16, 15)")))
137
138 (define_predicate "const_imm10_operand"
139 (and (match_code "const_int")
140 (match_test "IMM10_OPERAND (INTVAL (op))")))
141
142 (define_predicate "const_imm12_operand"
143 (and (match_code "const_int")
144 (match_test "IMM12_OPERAND (INTVAL (op))")))
145
146 (define_predicate "const_imm13_operand"
147 (and (match_code "const_int")
148 (match_test "IMM13_OPERAND (INTVAL (op))")))
149
150 (define_predicate "reg_imm10_operand"
151 (ior (match_operand 0 "const_imm10_operand")
152 (match_operand 0 "register_operand")))
153
154 (define_predicate "aq8b_operand"
155 (and (match_code "const_int")
156 (match_test "loongarch_signed_immediate_p (INTVAL (op), 8, 0)")))
157
158 (define_predicate "aq8h_operand"
159 (and (match_code "const_int")
160 (match_test "loongarch_signed_immediate_p (INTVAL (op), 8, 1)")))
161
162 (define_predicate "aq8w_operand"
163 (and (match_code "const_int")
164 (match_test "loongarch_signed_immediate_p (INTVAL (op), 8, 2)")))
165
166 (define_predicate "aq8d_operand"
167 (and (match_code "const_int")
168 (match_test "loongarch_signed_immediate_p (INTVAL (op), 8, 3)")))
169
170 (define_predicate "aq12b_operand"
171 (and (match_code "const_int")
172 (match_test "loongarch_signed_immediate_p (INTVAL (op), 12, 0)")))
173
174 (define_predicate "aq12h_operand"
175 (and (match_code "const_int")
176 (match_test "loongarch_signed_immediate_p (INTVAL (op), 11, 1)")))
177
178 (define_predicate "aq12w_operand"
179 (and (match_code "const_int")
180 (match_test "loongarch_signed_immediate_p (INTVAL (op), 10, 2)")))
181
182 (define_predicate "aq12d_operand"
183 (and (match_code "const_int")
184 (match_test "loongarch_signed_immediate_p (INTVAL (op), 9, 3)")))
185
186 (define_predicate "sle_operand"
187 (and (match_code "const_int")
188 (match_test "IMM12_OPERAND (INTVAL (op) + 1)")))
189
190 (define_predicate "sleu_operand"
191 (and (match_operand 0 "sle_operand")
192 (match_test "INTVAL (op) + 1 != 0")))
193
194 (define_predicate "const_0_operand"
195 (and (match_code "const_int,const_wide_int,const_double,const_vector")
196 (match_test "op == CONST0_RTX (GET_MODE (op))")))
197
198 (define_predicate "const_m1_operand"
199 (and (match_code "const_int,const_wide_int,const_double,const_vector")
200 (match_test "op == CONSTM1_RTX (GET_MODE (op))")))
201
202 (define_predicate "reg_or_m1_operand"
203 (ior (match_operand 0 "const_m1_operand")
204 (match_operand 0 "register_operand")))
205
206 (define_predicate "reg_or_0_operand"
207 (ior (match_operand 0 "const_0_operand")
208 (match_operand 0 "register_operand")))
209
210 (define_predicate "const_1_operand"
211 (and (match_code "const_int,const_wide_int,const_double,const_vector")
212 (match_test "op == CONST1_RTX (GET_MODE (op))")))
213
214 (define_predicate "const_vector_1_operand"
215 (and (match_code "const_vector")
216 (match_test "op == CONST1_RTX (GET_MODE (op))")))
217
218 (define_predicate "reg_or_1_operand"
219 (ior (match_operand 0 "const_1_operand")
220 (match_operand 0 "register_operand")))
221
222 (define_predicate "reg_or_vecotr_1_operand"
223 (ior (match_operand 0 "const_vector_1_operand")
224 (match_operand 0 "register_operand")))
225
226 ;; These are used in vec_merge, hence accept bitmask as const_int.
227 (define_predicate "const_exp_2_operand"
228 (and (match_code "const_int")
229 (match_test "IN_RANGE (exact_log2 (INTVAL (op)), 0, 1)")))
230
231 (define_predicate "const_exp_4_operand"
232 (and (match_code "const_int")
233 (match_test "IN_RANGE (exact_log2 (INTVAL (op)), 0, 3)")))
234
235 (define_predicate "const_exp_8_operand"
236 (and (match_code "const_int")
237 (match_test "IN_RANGE (exact_log2 (INTVAL (op)), 0, 7)")))
238
239 (define_predicate "const_exp_16_operand"
240 (and (match_code "const_int")
241 (match_test "IN_RANGE (exact_log2 (INTVAL (op)), 0, 15)")))
242
243 (define_predicate "const_exp_32_operand"
244 (and (match_code "const_int")
245 (match_test "IN_RANGE (exact_log2 (INTVAL (op)), 0, 31)")))
246
247 ;; This is used for indexing into vectors, and hence only accepts const_int.
248 (define_predicate "const_0_or_1_operand"
249 (and (match_code "const_int")
250 (match_test "IN_RANGE (INTVAL (op), 0, 1)")))
251
252 (define_predicate "const_0_to_3_operand"
253 (and (match_code "const_int")
254 (match_test "IN_RANGE (INTVAL (op), 0, 3)")))
255
256 (define_predicate "const_0_to_7_operand"
257 (and (match_code "const_int")
258 (match_test "IN_RANGE (INTVAL (op), 0, 7)")))
259
260 (define_predicate "const_2_or_3_operand"
261 (and (match_code "const_int")
262 (match_test "IN_RANGE (INTVAL (op), 2, 3)")))
263
264 (define_predicate "const_4_to_7_operand"
265 (and (match_code "const_int")
266 (match_test "IN_RANGE (INTVAL (op), 4, 7)")))
267
268 (define_predicate "const_8_to_15_operand"
269 (and (match_code "const_int")
270 (match_test "IN_RANGE (INTVAL (op), 8, 15)")))
271
272 (define_predicate "const_16_to_31_operand"
273 (and (match_code "const_int")
274 (match_test "IN_RANGE (INTVAL (op), 16, 31)")))
275
276 (define_predicate "qi_mask_operand"
277 (and (match_code "const_int")
278 (match_test "UINTVAL (op) == 0xff")))
279
280 (define_predicate "hi_mask_operand"
281 (and (match_code "const_int")
282 (match_test "UINTVAL (op) == 0xffff")))
283
284 (define_predicate "lu52i_mask_operand"
285 (and (match_code "const_int")
286 (match_test "UINTVAL (op) == 0xfffffffffffff")))
287
288 (define_predicate "si_mask_operand"
289 (and (match_code "const_int")
290 (match_test "UINTVAL (op) == 0xffffffff")))
291
292 (define_predicate "low_bitmask_operand"
293 (and (match_code "const_int")
294 (match_test "low_bitmask_len (mode, INTVAL (op)) > 12")))
295
296 (define_predicate "d_operand"
297 (and (match_code "reg")
298 (match_test "GP_REG_P (REGNO (op))")))
299
300 (define_predicate "db4_operand"
301 (and (match_code "const_int")
302 (match_test "loongarch_unsigned_immediate_p (INTVAL (op) + 1, 4, 0)")))
303
304 (define_predicate "db7_operand"
305 (and (match_code "const_int")
306 (match_test "loongarch_unsigned_immediate_p (INTVAL (op) + 1, 7, 0)")))
307
308 (define_predicate "db8_operand"
309 (and (match_code "const_int")
310 (match_test "loongarch_unsigned_immediate_p (INTVAL (op) + 1, 8, 0)")))
311
312 (define_predicate "ib3_operand"
313 (and (match_code "const_int")
314 (match_test "loongarch_unsigned_immediate_p (INTVAL (op) - 1, 3, 0)")))
315
316 (define_predicate "sb4_operand"
317 (and (match_code "const_int")
318 (match_test "loongarch_signed_immediate_p (INTVAL (op), 4, 0)")))
319
320 (define_predicate "sb5_operand"
321 (and (match_code "const_int")
322 (match_test "loongarch_signed_immediate_p (INTVAL (op), 5, 0)")))
323
324 (define_predicate "sb8_operand"
325 (and (match_code "const_int")
326 (match_test "loongarch_signed_immediate_p (INTVAL (op), 8, 0)")))
327
328 (define_predicate "sd8_operand"
329 (and (match_code "const_int")
330 (match_test "loongarch_signed_immediate_p (INTVAL (op), 8, 3)")))
331
332 (define_predicate "ub4_operand"
333 (and (match_code "const_int")
334 (match_test "loongarch_unsigned_immediate_p (INTVAL (op), 4, 0)")))
335
336 (define_predicate "ub8_operand"
337 (and (match_code "const_int")
338 (match_test "loongarch_unsigned_immediate_p (INTVAL (op), 8, 0)")))
339
340 (define_predicate "uh4_operand"
341 (and (match_code "const_int")
342 (match_test "loongarch_unsigned_immediate_p (INTVAL (op), 4, 1)")))
343
344 (define_predicate "uw4_operand"
345 (and (match_code "const_int")
346 (match_test "loongarch_unsigned_immediate_p (INTVAL (op), 4, 2)")))
347
348 (define_predicate "uw5_operand"
349 (and (match_code "const_int")
350 (match_test "loongarch_unsigned_immediate_p (INTVAL (op), 5, 2)")))
351
352 (define_predicate "uw6_operand"
353 (and (match_code "const_int")
354 (match_test "loongarch_unsigned_immediate_p (INTVAL (op), 6, 2)")))
355
356 (define_predicate "uw8_operand"
357 (and (match_code "const_int")
358 (match_test "loongarch_unsigned_immediate_p (INTVAL (op), 8, 2)")))
359
360 (define_predicate "addiur2_operand"
361 (and (match_code "const_int")
362 (ior (match_test "INTVAL (op) == -1")
363 (match_test "INTVAL (op) == 1")
364 (match_test "INTVAL (op) == 4")
365 (match_test "INTVAL (op) == 8")
366 (match_test "INTVAL (op) == 12")
367 (match_test "INTVAL (op) == 16")
368 (match_test "INTVAL (op) == 20")
369 (match_test "INTVAL (op) == 24"))))
370
371 (define_predicate "addiusp_operand"
372 (and (match_code "const_int")
373 (ior (match_test "(IN_RANGE (INTVAL (op), 2, 257))")
374 (match_test "(IN_RANGE (INTVAL (op), -258, -3))"))))
375
376 (define_predicate "andi16_operand"
377 (and (match_code "const_int")
378 (ior (match_test "IN_RANGE (INTVAL (op), 1, 4)")
379 (match_test "IN_RANGE (INTVAL (op), 7, 8)")
380 (match_test "IN_RANGE (INTVAL (op), 15, 16)")
381 (match_test "IN_RANGE (INTVAL (op), 31, 32)")
382 (match_test "IN_RANGE (INTVAL (op), 63, 64)")
383 (match_test "INTVAL (op) == 255")
384 (match_test "INTVAL (op) == 32768")
385 (match_test "INTVAL (op) == 65535"))))
386
387 (define_predicate "movep_src_register"
388 (and (match_code "reg")
389 (ior (match_test ("IN_RANGE (REGNO (op), 2, 3)"))
390 (match_test ("IN_RANGE (REGNO (op), 16, 20)")))))
391
392 (define_predicate "movep_src_operand"
393 (ior (match_operand 0 "const_0_operand")
394 (match_operand 0 "movep_src_register")))
395
396 (define_predicate "fcc_reload_operand"
397 (and (match_code "reg,subreg")
398 (match_test "FCC_REG_P (true_regnum (op))")))
399
400 (define_predicate "muldiv_target_operand"
401 (match_operand 0 "register_operand"))
402
403 (define_predicate "ins_zero_bitmask_operand"
404 (and (match_code "const_int")
405 (match_test "low_bitmask_len (mode, \
406 ~UINTVAL (op) | (~UINTVAL(op) - 1)) \
407 > 0")
408 (not (match_operand 0 "const_uns_arith_operand"))
409 (not (match_operand 0 "low_bitmask_operand"))))
410
411 (define_predicate "and_operand"
412 (ior (match_operand 0 "uns_arith_operand")
413 (match_operand 0 "low_bitmask_operand")
414 (match_operand 0 "ins_zero_bitmask_operand")))
415
416 (define_predicate "const_call_insn_operand"
417 (match_code "const,symbol_ref,label_ref")
418 {
419 /* Split symbol to high and low if return false.
420 If defined TARGET_CMODEL_EXTREME, all symbol would be splited,
421 else if offset is not zero, the symbol would be splited. */
422
423 enum loongarch_symbol_type symbol_type;
424 loongarch_symbolic_constant_p (op, &symbol_type);
425
426 rtx offset, x = op;
427 split_const (x, &x, &offset);
428
429 if (offset != const0_rtx)
430 return false;
431
432 /* When compiling with '-mcmodel=medium -mexplicit-relocs'
433 symbols are splited in loongarch_legitimize_call_address.
434
435 When compiling with '-mcmodel=medium -mno-explicit-relocs',
436 first obtain the symbolic address or the address of the
437 plt entry, and then perform an indirect jump, so return false. */
438
439 switch (symbol_type)
440 {
441 case SYMBOL_PCREL:
442 if (TARGET_CMODEL_EXTREME
443 || (TARGET_CMODEL_MEDIUM
444 && (la_opt_explicit_relocs == EXPLICIT_RELOCS_NONE)))
445 return false;
446 else
447 return true;
448
449 case SYMBOL_GOT_DISP:
450 if (TARGET_CMODEL_EXTREME
451 || !flag_plt
452 || (flag_plt && TARGET_CMODEL_MEDIUM
453 && (la_opt_explicit_relocs == EXPLICIT_RELOCS_NONE)))
454 return false;
455 else
456 return true;
457
458 default:
459 return false;
460 }
461 })
462
463 (define_predicate "call_insn_operand"
464 (ior (match_operand 0 "const_call_insn_operand")
465 (match_operand 0 "register_operand")))
466
467 (define_predicate "is_const_call_local_symbol"
468 (and (match_operand 0 "const_call_insn_operand")
469 (ior (match_test "loongarch_global_symbol_p (op) == 0")
470 (match_test "loongarch_symbol_binds_local_p (op) != 0"))
471 (match_test "CONSTANT_P (op)")))
472
473 (define_predicate "is_const_call_no_local_symbol"
474 (and (match_operand 0 "const_call_insn_operand")
475 (ior (match_test "loongarch_global_symbol_p (op) != 0")
476 (match_test "loongarch_symbol_binds_local_p (op) == 0")
477 (match_test "loongarch_weak_symbol_p (op) != 0"))
478 (match_test "CONSTANT_P (op)")))
479
480 ;; A legitimate CONST_INT operand that takes more than one instruction
481 ;; to load.
482 (define_predicate "splittable_const_int_operand"
483 (match_code "const_int")
484 {
485 /* Don't handle multi-word moves this way; we don't want to introduce
486 the individual word-mode moves until after reload. */
487 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
488 return false;
489
490 /* Otherwise check whether the constant can be loaded in a single
491 instruction. */
492 return !LU12I_INT (op) && !IMM12_INT (op) && !IMM12_INT_UNSIGNED (op)
493 && !LU52I_INT (op);
494 })
495
496 (define_predicate "move_operand"
497 (match_operand 0 "general_operand")
498 {
499 enum loongarch_symbol_type symbol_type;
500
501 /* The thinking here is as follows:
502
503 (1) The move expanders should split complex load sequences into
504 individual instructions. Those individual instructions can
505 then be optimized by all rtl passes.
506
507 (2) The target of pre-reload load sequences should not be used
508 to store temporary results. If the target register is only
509 assigned one value, reload can rematerialize that value
510 on demand, rather than spill it to the stack.
511
512 (3) If we allowed pre-reload passes like combine and cse to recreate
513 complex load sequences, we would want to be able to split the
514 sequences before reload as well, so that the pre-reload scheduler
515 can see the individual instructions. This falls foul of (2);
516 the splitter would be forced to reuse the target register for
517 intermediate results.
518
519 (4) We want to define complex load splitters for combine. These
520 splitters can request a temporary scratch register, which avoids
521 the problem in (2). They allow things like:
522
523 (set (reg T1) (high SYM))
524 (set (reg T2) (low (reg T1) SYM))
525 (set (reg X) (plus (reg T2) (const_int OFFSET)))
526
527 to be combined into:
528
529 (set (reg T3) (high SYM+OFFSET))
530 (set (reg X) (lo_sum (reg T3) SYM+OFFSET))
531
532 if T2 is only used this once. */
533 switch (GET_CODE (op))
534 {
535 case CONST_INT:
536 return true;
537
538 case CONST:
539 case SYMBOL_REF:
540 case LABEL_REF:
541 return (loongarch_symbolic_constant_p (op, &symbol_type)
542 && (!loongarch_explicit_relocs_p (symbol_type)
543 || !loongarch_split_symbol_type (symbol_type)));
544
545 case HIGH:
546 op = XEXP (op, 0);
547
548 return (loongarch_symbolic_constant_p (op, &symbol_type)
549 && loongarch_explicit_relocs_p (symbol_type)
550 && loongarch_split_symbol_type (symbol_type));
551
552 default:
553 return true;
554 }
555 })
556
557 (define_predicate "symbolic_operand"
558 (match_code "const,symbol_ref,label_ref")
559 {
560 enum loongarch_symbol_type type;
561 return loongarch_symbolic_constant_p (op, &type);
562 })
563
564 (define_predicate "symbolic_pcrel_operand"
565 (match_code "const,symbol_ref,label_ref")
566 {
567 enum loongarch_symbol_type type;
568 return loongarch_symbolic_constant_p (op, &type) && type == SYMBOL_PCREL;
569 })
570
571 (define_predicate "symbolic_pcrel_offset_operand"
572 (and (match_code "plus")
573 (match_operand 0 "symbolic_pcrel_operand")
574 (match_operand 1 "const_int_operand")))
575
576 (define_predicate "mem_simple_ldst_operand"
577 (match_code "mem")
578 {
579 op = XEXP (op, 0);
580 return (symbolic_pcrel_operand (op, Pmode)
581 || symbolic_pcrel_offset_operand (op, Pmode));
582 })
583
584 (define_predicate "symbolic_off64_operand"
585 (match_code "const,symbol_ref,label_ref")
586 {
587 enum loongarch_symbol_type type;
588 return loongarch_symbolic_constant_p (op, &type)
589 && loongarch_symbol_extreme_p (type);
590 })
591
592 (define_predicate "symbolic_off64_or_reg_operand"
593 (ior (match_operand 0 "register_operand")
594 (match_operand 0 "symbolic_off64_operand")))
595
596 ;; Currently stack canary must be the global symbol __stack_chk_guard.
597 (define_predicate "ssp_operand" (match_code "symbol_ref"))
598
599 ;; If the stack canary is within the normal/medium code model.
600 (define_predicate "ssp_normal_operand"
601 (and (match_operand 0 "ssp_operand")
602 (not (match_operand 0 "symbolic_off64_operand"))))
603
604 (define_predicate "equality_operator"
605 (match_code "eq,ne"))
606
607 (define_predicate "order_operator"
608 (match_code "lt,ltu,le,leu,ge,geu,gt,gtu"))
609
610 ;; For NE, cstore uses sltu instructions in which the first operand is $0.
611
612 (define_predicate "loongarch_cstore_operator"
613 (match_code "ne,eq,gt,gtu,ge,geu,lt,ltu,le,leu"))
614
615 (define_predicate "loongarch_fcmp_operator"
616 (match_code
617 "unordered,uneq,unlt,unle,eq,lt,le,ordered,ltgt,ne,ge,gt,unge,ungt"))
618
619 (define_predicate "small_data_pattern"
620 (and (match_code "set,parallel,unspec,unspec_volatile,prefetch")
621 (match_test "loongarch_small_data_pattern_p (op)")))
622
623 ;; Return 1 if the operand is in non-volatile memory.
624 (define_predicate "non_volatile_mem_operand"
625 (and (match_operand 0 "memory_operand")
626 (not (match_test "MEM_VOLATILE_P (op)"))))
627
628 (define_predicate "const_vector_same_val_operand"
629 (match_code "const_vector")
630 {
631 return loongarch_const_vector_same_val_p (op, mode);
632 })
633
634 (define_predicate "const_vector_same_simm5_operand"
635 (match_code "const_vector")
636 {
637 return loongarch_const_vector_same_int_p (op, mode, -16, 15);
638 })
639
640 (define_predicate "const_vector_same_uimm5_operand"
641 (match_code "const_vector")
642 {
643 return loongarch_const_vector_same_int_p (op, mode, 0, 31);
644 })
645
646 (define_predicate "const_vector_same_ximm5_operand"
647 (match_code "const_vector")
648 {
649 return loongarch_const_vector_same_int_p (op, mode, -31, 31);
650 })
651
652 (define_predicate "const_vector_same_uimm_operand"
653 (match_code "const_vector")
654 {
655 return loongarch_const_vector_same_int_p (op, mode);
656 })
657
658 (define_predicate "const_vector_neg_fp_operand"
659 (match_code "const_vector")
660 {
661 machine_mode imode = related_int_vector_mode (mode).require ();
662 rtx mask = loongarch_build_signbit_mask (imode, 1, 0);
663
664 op = gen_lowpart (imode, op);
665 return rtx_equal_p (mask,
666 simplify_const_binary_operation (AND, imode, mask,
667 op));
668 })
669
670 (define_predicate "par_const_vector_shf_set_operand"
671 (match_code "parallel")
672 {
673 return loongarch_const_vector_shuffle_set_p (op, mode);
674 })
675
676 (define_predicate "reg_or_vector_same_val_operand"
677 (ior (match_operand 0 "register_operand")
678 (match_operand 0 "const_vector_same_val_operand")))
679
680 (define_predicate "reg_or_vector_same_simm5_operand"
681 (ior (match_operand 0 "register_operand")
682 (match_operand 0 "const_vector_same_simm5_operand")))
683
684 (define_predicate "reg_or_vector_same_uimm5_operand"
685 (ior (match_operand 0 "register_operand")
686 (match_operand 0 "const_vector_same_uimm5_operand")))
687
688 (define_predicate "reg_or_vector_same_ximm5_operand"
689 (ior (match_operand 0 "register_operand")
690 (match_operand 0 "const_vector_same_ximm5_operand")))
691
692 (define_predicate "reg_or_vector_same_uimm_operand"
693 (ior (match_operand 0 "register_operand")
694 (match_operand 0 "const_vector_same_uimm_operand")))
695
696 (define_predicate "reg_or_vector_neg_fp_operand"
697 (ior (match_operand 0 "register_operand")
698 (match_operand 0 "const_vector_neg_fp_operand")))
699
700 ;; PARALLEL for a vec_select that selects all the even or all the odd
701 ;; elements of a vector of MODE.
702 (define_special_predicate "vect_par_cnst_even_or_odd_half"
703 (match_code "parallel")
704 {
705 int nunits = XVECLEN (op, 0);
706
707 if (!known_eq (GET_MODE_NUNITS (mode), nunits * 2))
708 return false;
709
710 rtx first = XVECEXP (op, 0, 0);
711 if (!CONST_INT_P (first))
712 return false;
713
714 if (INTVAL (first) != 0 && INTVAL (first) != 1)
715 return false;
716
717 for (int i = 1; i < nunits; i++)
718 {
719 rtx elem = XVECEXP (op, 0, i);
720 if (!CONST_INT_P (elem) || INTVAL (elem) != INTVAL (first) + i * 2)
721 return false;
722 }
723
724 return true;
725 })