Debian Codegraph @

gcc/config/rs6000/predicates.md

raw
1 ;; Predicate definitions for POWER and PowerPC.
2 ;; Copyright (C) 2005-2025 Free Software Foundation, Inc.
3 ;;
4 ;; This file is part of GCC.
5 ;;
6 ;; GCC is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 3, or (at your option)
9 ;; any later version.
10 ;;
11 ;; GCC is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;; GNU General Public License for more details.
15 ;;
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GCC; see the file COPYING3. If not see
18 ;; <http://www.gnu.org/licenses/>.
19
20 ;; Return 1 for anything except PARALLEL.
21 (define_predicate "any_operand"
22 (match_code "const_int,const_double,const_wide_int,const_vector,const,symbol_ref,label_ref,subreg,reg,mem"))
23
24 ;; Return 1 for any PARALLEL.
25 (define_predicate "any_parallel_operand"
26 (match_code "parallel"))
27
28 ;; Return 1 if op is COUNT register.
29 (define_predicate "count_register_operand"
30 (and (match_code "reg")
31 (match_test "REGNO (op) == CTR_REGNO
32 || REGNO (op) > LAST_VIRTUAL_REGISTER")))
33
34 ;; Return 1 if op is a SUBREG that is used to look at a SFmode value as
35 ;; and integer or vice versa.
36 ;;
37 ;; In the normal case where SFmode is in a floating point/vector register, it
38 ;; is stored as a DFmode and has a different format. If we don't transform the
39 ;; value, things that use logical operations on the values will get the wrong
40 ;; value.
41 ;;
42 ;; If we don't have 64-bit and direct move, this conversion will be done by
43 ;; store and load, instead of by fiddling with the bits within the register.
44 (define_predicate "sf_subreg_operand"
45 (match_code "subreg")
46 {
47 rtx inner_reg = SUBREG_REG (op);
48 machine_mode inner_mode = GET_MODE (inner_reg);
49
50 if (TARGET_ALLOW_SF_SUBREG || !REG_P (inner_reg))
51 return 0;
52
53 if ((mode == SFmode && GET_MODE_CLASS (inner_mode) == MODE_INT)
54 || (GET_MODE_CLASS (mode) == MODE_INT && inner_mode == SFmode))
55 {
56 if (INT_REGNO_P (REGNO (inner_reg)))
57 return 0;
58
59 return 1;
60 }
61 return 0;
62 })
63
64 ;; Return 1 if op is an Altivec register.
65 (define_predicate "altivec_register_operand"
66 (match_operand 0 "register_operand")
67 {
68 if (SUBREG_P (op))
69 {
70 if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
71 return 0;
72
73 op = SUBREG_REG (op);
74 }
75
76 if (!REG_P (op))
77 return 0;
78
79 if (!HARD_REGISTER_P (op))
80 return 1;
81
82 return ALTIVEC_REGNO_P (REGNO (op));
83 })
84
85 ;; Return 1 if op is a VSX register.
86 (define_predicate "vsx_register_operand"
87 (match_operand 0 "register_operand")
88 {
89 if (SUBREG_P (op))
90 {
91 if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
92 return 0;
93
94 op = SUBREG_REG (op);
95 }
96
97 if (!REG_P (op))
98 return 0;
99
100 if (!HARD_REGISTER_P (op))
101 return 1;
102
103 return VSX_REGNO_P (REGNO (op));
104 })
105
106 ;; Like vsx_register_operand, but allow SF SUBREGS
107 (define_predicate "vsx_reg_sfsubreg_ok"
108 (match_operand 0 "register_operand")
109 {
110 if (SUBREG_P (op))
111 op = SUBREG_REG (op);
112
113 if (!REG_P (op))
114 return 0;
115
116 if (!HARD_REGISTER_P (op))
117 return 1;
118
119 return VSX_REGNO_P (REGNO (op));
120 })
121
122 ;; Return 1 if op is a vector register that operates on floating point vectors
123 ;; (either altivec or VSX).
124 (define_predicate "vfloat_operand"
125 (match_operand 0 "register_operand")
126 {
127 if (SUBREG_P (op))
128 {
129 if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
130 return 0;
131
132 op = SUBREG_REG (op);
133 }
134
135 if (!REG_P (op))
136 return 0;
137
138 if (!HARD_REGISTER_P (op))
139 return 1;
140
141 return VFLOAT_REGNO_P (REGNO (op));
142 })
143
144 ;; Return 1 if op is a vector register that operates on integer vectors
145 ;; (only altivec, VSX doesn't support integer vectors)
146 (define_predicate "vint_operand"
147 (match_operand 0 "register_operand")
148 {
149 if (SUBREG_P (op))
150 {
151 if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
152 return 0;
153
154 op = SUBREG_REG (op);
155 }
156
157 if (!REG_P (op))
158 return 0;
159
160 if (!HARD_REGISTER_P (op))
161 return 1;
162
163 return VINT_REGNO_P (REGNO (op));
164 })
165
166 ;; Return 1 if op is a vector register to do logical operations on (and, or,
167 ;; xor, etc.)
168 (define_predicate "vlogical_operand"
169 (match_operand 0 "register_operand")
170 {
171 if (SUBREG_P (op))
172 {
173 if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
174 return 0;
175
176 op = SUBREG_REG (op);
177 }
178
179
180 if (!REG_P (op))
181 return 0;
182
183 if (!HARD_REGISTER_P (op))
184 return 1;
185
186 return VLOGICAL_REGNO_P (REGNO (op));
187 })
188
189 ;; Return 1 if op is the carry register.
190 (define_predicate "ca_operand"
191 (match_operand 0 "register_operand")
192 {
193 if (SUBREG_P (op))
194 op = SUBREG_REG (op);
195
196 if (!REG_P (op))
197 return 0;
198
199 return CA_REGNO_P (REGNO (op));
200 })
201
202 ;; Return 1 if operand is constant zero (scalars and vectors).
203 (define_predicate "zero_constant"
204 (and (match_code "const_int,const_double,const_wide_int,const_vector")
205 (match_test "op == CONST0_RTX (mode)")))
206
207 ;; Return 1 if operand is constant -1 (scalars and vectors).
208 (define_predicate "all_ones_constant"
209 (and (match_code "const_int,const_double,const_wide_int,const_vector")
210 (match_test "op == CONSTM1_RTX (mode) && !FLOAT_MODE_P (mode)")))
211
212 ;; Return 1 if op is a signed 5-bit constant integer.
213 (define_predicate "s5bit_cint_operand"
214 (and (match_code "const_int")
215 (match_test "INTVAL (op) >= -16 && INTVAL (op) <= 15")))
216
217 ;; Return 1 if op is an unsigned 1-bit constant integer.
218 (define_predicate "u1bit_cint_operand"
219 (and (match_code "const_int")
220 (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 1")))
221
222 ;; Return 1 if op is a unsigned 3-bit constant integer.
223 (define_predicate "u3bit_cint_operand"
224 (and (match_code "const_int")
225 (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 7")))
226
227 ;; Return 1 if op is a unsigned 5-bit constant integer.
228 (define_predicate "u5bit_cint_operand"
229 (and (match_code "const_int")
230 (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 31")))
231
232 ;; Return 1 if op is a unsigned 6-bit constant integer.
233 (define_predicate "u6bit_cint_operand"
234 (and (match_code "const_int")
235 (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 63")))
236
237 ;; Return 1 if op is an unsigned 7-bit constant integer.
238 (define_predicate "u7bit_cint_operand"
239 (and (match_code "const_int")
240 (match_test "IN_RANGE (INTVAL (op), 0, 127)")))
241
242 ;; Return 1 if op is a unsigned 8-bit constant integer.
243 (define_predicate "u8bit_cint_operand"
244 (and (match_code "const_int")
245 (match_test "IN_RANGE (INTVAL (op), 0, 255)")))
246
247 ;; Return 1 if op is a signed 8-bit constant integer.
248 ;; Integer multiplication complete more quickly
249 (define_predicate "s8bit_cint_operand"
250 (and (match_code "const_int")
251 (match_test "INTVAL (op) >= -128 && INTVAL (op) <= 127")))
252
253 ;; Return 1 if op is a unsigned 10-bit constant integer.
254 (define_predicate "u10bit_cint_operand"
255 (and (match_code "const_int")
256 (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 1023")))
257
258 ;; Return 1 if op is a constant integer that can fit in a D field.
259 (define_predicate "short_cint_operand"
260 (and (match_code "const_int")
261 (match_test "satisfies_constraint_I (op)")))
262
263 ;; Return 1 if op is a constant integer that can fit in an unsigned D field.
264 (define_predicate "u_short_cint_operand"
265 (and (match_code "const_int")
266 (match_test "satisfies_constraint_K (op)")))
267
268 ;; Return 1 if op is a constant integer that is a signed 16-bit constant
269 ;; shifted left 16 bits
270 (define_predicate "upper16_cint_operand"
271 (and (match_code "const_int")
272 (match_test "satisfies_constraint_L (op)")))
273
274 ;; Return 1 if op is a constant integer that cannot fit in a signed D field.
275 (define_predicate "non_short_cint_operand"
276 (and (match_code "const_int")
277 (match_test "(unsigned HOST_WIDE_INT)
278 (INTVAL (op) + 0x8000) >= 0x10000")))
279
280 ;; Return 1 if op is a 32-bit constant signed integer
281 (define_predicate "s32bit_cint_operand"
282 (and (match_code "const_int")
283 (match_test "(0x80000000 + UINTVAL (op)) >> 32 == 0")))
284
285 ;; Return 1 if op is a constant 32-bit unsigned
286 (define_predicate "c32bit_cint_operand"
287 (and (match_code "const_int")
288 (match_test "((UINTVAL (op) >> 32) == 0)")))
289
290 ;; Return 1 if op is a positive constant integer that is an exact power of 2.
291 (define_predicate "exact_log2_cint_operand"
292 (and (match_code "const_int")
293 (match_test "INTVAL (op) > 0 && exact_log2 (INTVAL (op)) >= 0")))
294
295 ;; Match op = 0 or op = 1.
296 (define_predicate "const_0_to_1_operand"
297 (and (match_code "const_int")
298 (match_test "IN_RANGE (INTVAL (op), 0, 1)")))
299
300 ;; Match op = -1, op = 0, or op = 1.
301 (define_predicate "const_m1_to_1_operand"
302 (and (match_code "const_int")
303 (match_test "IN_RANGE (INTVAL (op), -1, 1)")))
304
305 ;; Match op = 0..3.
306 (define_predicate "const_0_to_3_operand"
307 (and (match_code "const_int")
308 (match_test "IN_RANGE (INTVAL (op), 0, 3)")))
309
310 ;; Match op = 2 or op = 3.
311 (define_predicate "const_2_to_3_operand"
312 (and (match_code "const_int")
313 (match_test "IN_RANGE (INTVAL (op), 2, 3)")))
314
315 ;; Match op = 0..7.
316 (define_predicate "const_0_to_7_operand"
317 (and (match_code "const_int")
318 (match_test "IN_RANGE (INTVAL (op), 0, 7)")))
319
320 ;; Match op = 0..11
321 (define_predicate "const_0_to_12_operand"
322 (and (match_code "const_int")
323 (match_test "IN_RANGE (INTVAL (op), 0, 12)")))
324
325 ;; Match op = 0..15
326 (define_predicate "const_0_to_15_operand"
327 (and (match_code "const_int")
328 (match_test "IN_RANGE (INTVAL (op), 0, 15)")))
329
330 ;; Return 1 if op is a 34-bit constant integer.
331 (define_predicate "cint34_operand"
332 (match_code "const_int")
333 {
334 if (!TARGET_PREFIXED)
335 return 0;
336
337 return SIGNED_INTEGER_34BIT_P (INTVAL (op));
338 })
339
340 ;; Return 1 if op is a register that is not special.
341 ;; Disallow (SUBREG:SF (REG:SI)) and (SUBREG:SI (REG:SF)) on VSX systems where
342 ;; you need to be careful in moving a SFmode to SImode and vice versa due to
343 ;; the fact that SFmode is represented as DFmode in the VSX registers.
344 (define_predicate "gpc_reg_operand"
345 (match_operand 0 "register_operand")
346 {
347 if (SUBREG_P (op))
348 {
349 if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
350 return 0;
351
352 op = SUBREG_REG (op);
353 }
354
355 if (!REG_P (op))
356 return 0;
357
358 if (!HARD_REGISTER_P (op))
359 return 1;
360
361 if (TARGET_ALTIVEC && ALTIVEC_REGNO_P (REGNO (op)))
362 return 1;
363
364 if (TARGET_VSX && VSX_REGNO_P (REGNO (op)))
365 return 1;
366
367 return INT_REGNO_P (REGNO (op)) || FP_REGNO_P (REGNO (op));
368 })
369
370 ;; Return 1 if op is a general purpose register. Unlike gpc_reg_operand, don't
371 ;; allow floating point or vector registers. Since vector registers are not
372 ;; allowed, we don't have to reject SFmode/SImode subregs.
373 (define_predicate "int_reg_operand"
374 (match_operand 0 "register_operand")
375 {
376 if (SUBREG_P (op))
377 {
378 if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
379 return 0;
380
381 op = SUBREG_REG (op);
382 }
383
384 if (!REG_P (op))
385 return 0;
386
387 if (!HARD_REGISTER_P (op))
388 return 1;
389
390 return INT_REGNO_P (REGNO (op));
391 })
392
393 ;; Like int_reg_operand, but don't return true for pseudo registers
394 ;; We don't have to check for SF SUBREGS because pseudo registers
395 ;; are not allowed, and SF SUBREGs are ok within GPR registers.
396 (define_predicate "int_reg_operand_not_pseudo"
397 (match_operand 0 "register_operand")
398 {
399 if (SUBREG_P (op))
400 op = SUBREG_REG (op);
401
402 if (!REG_P (op))
403 return 0;
404
405 if (!HARD_REGISTER_P (op))
406 return 0;
407
408 return INT_REGNO_P (REGNO (op));
409 })
410
411 ;; Like int_reg_operand, but only return true for base registers
412 (define_predicate "base_reg_operand"
413 (match_operand 0 "int_reg_operand")
414 {
415 if (SUBREG_P (op))
416 op = SUBREG_REG (op);
417
418 if (!REG_P (op))
419 return 0;
420
421 return (REGNO (op) != FIRST_GPR_REGNO);
422 })
423
424
425 ;; Return true if this is a traditional floating point register
426 (define_predicate "fpr_reg_operand"
427 (match_code "reg,subreg")
428 {
429 HOST_WIDE_INT r;
430
431 if (SUBREG_P (op))
432 op = SUBREG_REG (op);
433
434 if (!REG_P (op))
435 return 0;
436
437 r = REGNO (op);
438 if (!HARD_REGISTER_NUM_P (r))
439 return 1;
440
441 return FP_REGNO_P (r);
442 })
443
444 ;; Return 1 if op is a general purpose register that is an even register
445 ;; which suitable for a load/store quad operation
446 ;; Subregs are not allowed here because when they are combine can
447 ;; create (subreg:PTI (reg:TI pseudo)) which will cause reload to
448 ;; think the innermost reg needs reloading, in TImode instead of
449 ;; PTImode. So reload will choose a reg in TImode which has no
450 ;; requirement that the reg be even.
451 (define_predicate "quad_int_reg_operand"
452 (match_code "reg")
453 {
454 HOST_WIDE_INT r;
455
456 if (!TARGET_QUAD_MEMORY && !TARGET_QUAD_MEMORY_ATOMIC)
457 return 0;
458
459 r = REGNO (op);
460 if (!HARD_REGISTER_NUM_P (r))
461 return 1;
462
463 return (INT_REGNO_P (r) && ((r & 1) == 0));
464 })
465
466 ;; Return 1 if op is a register that is a condition register field.
467 (define_predicate "cc_reg_operand"
468 (match_operand 0 "register_operand")
469 {
470 if (SUBREG_P (op))
471 op = SUBREG_REG (op);
472
473 if (!REG_P (op))
474 return 0;
475
476 if (REGNO (op) > LAST_VIRTUAL_REGISTER)
477 return 1;
478
479 return CR_REGNO_P (REGNO (op));
480 })
481
482 ;; Return 1 if op is a register that is a condition register field not cr0.
483 (define_predicate "cc_reg_not_cr0_operand"
484 (match_operand 0 "register_operand")
485 {
486 if (SUBREG_P (op))
487 op = SUBREG_REG (op);
488
489 if (!REG_P (op))
490 return 0;
491
492 if (REGNO (op) > LAST_VIRTUAL_REGISTER)
493 return 1;
494
495 return CR_REGNO_NOT_CR0_P (REGNO (op));
496 })
497
498 ;; Return 1 if op is a constant integer valid for D field
499 ;; or non-special register.
500 (define_predicate "reg_or_short_operand"
501 (if_then_else (match_code "const_int")
502 (match_operand 0 "short_cint_operand")
503 (match_operand 0 "gpc_reg_operand")))
504
505 ;; Return 1 if op is a constant integer valid for DS field
506 ;; or non-special register.
507 (define_predicate "reg_or_aligned_short_operand"
508 (if_then_else (match_code "const_int")
509 (and (match_operand 0 "short_cint_operand")
510 (match_test "!(INTVAL (op) & 3)"))
511 (match_operand 0 "gpc_reg_operand")))
512
513 ;; Return 1 if op is a constant integer whose high-order 16 bits are zero
514 ;; or non-special register.
515 (define_predicate "reg_or_u_short_operand"
516 (if_then_else (match_code "const_int")
517 (match_operand 0 "u_short_cint_operand")
518 (match_operand 0 "gpc_reg_operand")))
519
520 ;; Return 1 if op is any constant integer or a non-special register.
521 (define_predicate "reg_or_cint_operand"
522 (ior (match_code "const_int")
523 (match_operand 0 "gpc_reg_operand")))
524
525 ;; Return 1 if op is constant zero or a non-special register.
526 (define_predicate "reg_or_zero_operand"
527 (ior (match_operand 0 "zero_constant")
528 (match_operand 0 "gpc_reg_operand")))
529
530 ;; Return 1 if op is a constant integer valid for addition with addis, addi.
531 (define_predicate "add_cint_operand"
532 (and (match_code "const_int")
533 (match_test "((unsigned HOST_WIDE_INT) INTVAL (op)
534 + (mode == SImode ? 0x80000000 : 0x80008000))
535 < (unsigned HOST_WIDE_INT) 0x100000000ll")))
536
537 ;; Return 1 if op is a constant integer valid for addition
538 ;; or non-special register.
539 (define_predicate "reg_or_add_cint_operand"
540 (if_then_else (match_code "const_int")
541 (match_operand 0 "add_cint_operand")
542 (match_operand 0 "gpc_reg_operand")))
543
544 ;; Return 1 if op is a constant integer valid for subtraction
545 ;; or non-special register.
546 (define_predicate "reg_or_sub_cint_operand"
547 (if_then_else (match_code "const_int")
548 (match_test "(unsigned HOST_WIDE_INT)
549 (- UINTVAL (op) + (mode == SImode ? 0x80000000 : 0x80008000))
550 < (unsigned HOST_WIDE_INT) 0x100000000ll")
551 (match_operand 0 "gpc_reg_operand")))
552
553 ;; Return 1 if op is any 32-bit unsigned constant integer
554 ;; or non-special register.
555 (define_predicate "reg_or_logical_cint_operand"
556 (if_then_else (match_code "const_int")
557 (match_test "(GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT
558 && INTVAL (op) >= 0)
559 || ((INTVAL (op) & GET_MODE_MASK (mode)
560 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0)")
561 (match_operand 0 "gpc_reg_operand")))
562
563 ;; Like reg_or_logical_cint_operand, but allow vsx registers
564 (define_predicate "vsx_reg_or_cint_operand"
565 (ior (match_operand 0 "vsx_register_operand")
566 (match_operand 0 "reg_or_logical_cint_operand")))
567
568 ;; Return 1 if operand is a CONST_DOUBLE that can be set in a register
569 ;; with no more than one instruction per word.
570 (define_predicate "easy_fp_constant"
571 (match_code "const_double")
572 {
573 gcc_assert (GET_MODE (op) == mode && SCALAR_FLOAT_MODE_P (mode));
574
575 /* Consider all constants with -msoft-float to be easy when regs are
576 32-bit and thus can be loaded with a maximum of 2 insns. For
577 64-bit avoid long dependent insn sequences. */
578 if (TARGET_SOFT_FLOAT)
579 {
580 if (!TARGET_POWERPC64)
581 return 1;
582
583 int size = GET_MODE_SIZE (mode);
584 if (size < 8)
585 return 1;
586
587 int load_from_mem_insns = 2;
588 if (size > 8)
589 load_from_mem_insns++;
590 if (TARGET_CMODEL != CMODEL_SMALL)
591 load_from_mem_insns++;
592 if (num_insns_constant (op, mode) <= load_from_mem_insns)
593 return 1;
594 }
595
596 /* 0.0D is not all zero bits. */
597 if (DECIMAL_FLOAT_MODE_P (mode))
598 return 0;
599
600 /* The constant 0.0 is easy under VSX. */
601 if (TARGET_VSX && op == CONST0_RTX (mode))
602 return 1;
603
604 /* Constants that can be generated with ISA 3.1 instructions are easy. */
605 vec_const_128bit_type vsx_const;
606 if (TARGET_POWER10 && vec_const_128bit_to_bytes (op, mode, &vsx_const))
607 {
608 if (constant_generates_lxvkq (&vsx_const))
609 return true;
610
611 if (constant_generates_xxspltiw (&vsx_const))
612 return true;
613
614 if (constant_generates_xxspltidp (&vsx_const))
615 return true;
616 }
617
618 /* Otherwise consider floating point constants hard, so that the
619 constant gets pushed to memory during the early RTL phases. This
620 has the advantage that double precision constants that can be
621 represented in single precision without a loss of precision will
622 use single precision loads. */
623 return 0;
624 })
625
626 ;; Return 1 if the operand is a 64-bit floating point scalar constant or a
627 ;; vector constant that can be loaded to a VSX register with one prefixed
628 ;; instruction, such as XXSPLTIDP or XXSPLTIW.
629 ;;
630 ;; In addition regular constants, we also recognize constants formed with the
631 ;; VEC_DUPLICATE insn from scalar constants.
632 ;;
633 ;; We don't handle scalar integer constants here because the assumption is the
634 ;; normal integer constants will be loaded into GPR registers. For the
635 ;; constants that need to be loaded into vector registers, the instructions
636 ;; don't work well with TImode variables assigned a constant. This is because
637 ;; the 64-bit scalar constants are splatted into both halves of the register.
638
639 (define_predicate "vsx_prefixed_constant"
640 (match_code "const_double,const_vector,vec_duplicate")
641 {
642 /* If we can generate the constant with a few Altivec instructions, don't
643 generate a prefixed instruction. */
644 if (CONST_VECTOR_P (op) && easy_altivec_constant (op, mode))
645 return false;
646
647 /* Do we have prefixed instructions and are VSX registers available? Is the
648 constant recognized? */
649 if (!TARGET_PREFIXED || !TARGET_VSX)
650 return false;
651
652 vec_const_128bit_type vsx_const;
653 if (!vec_const_128bit_to_bytes (op, mode, &vsx_const))
654 return false;
655
656 if (constant_generates_xxspltiw (&vsx_const))
657 return true;
658
659 if (constant_generates_xxspltidp (&vsx_const))
660 return true;
661
662 return false;
663 })
664
665 ;; Return 1 if the operand is a special IEEE 128-bit value that can be loaded
666 ;; via the LXVKQ instruction.
667
668 (define_predicate "easy_vector_constant_ieee128"
669 (match_code "const_vector,const_double")
670 {
671 vec_const_128bit_type vsx_const;
672
673 /* Can we generate the LXVKQ instruction? */
674 if (!TARGET_IEEE128_CONSTANT || !TARGET_FLOAT128_HW || !TARGET_POWER10
675 || !TARGET_VSX)
676 return false;
677
678 return (vec_const_128bit_to_bytes (op, mode, &vsx_const)
679 && constant_generates_lxvkq (&vsx_const) != 0);
680 })
681
682 ;; Return 1 if the operand is a constant that can loaded with a XXSPLTIB
683 ;; instruction and then a VUPKHSB, VECSB2W or VECSB2D instruction.
684
685 (define_predicate "xxspltib_constant_split"
686 (match_code "const_vector,vec_duplicate,const_int")
687 {
688 int value = 256;
689 int num_insns = -1;
690
691 if (!xxspltib_constant_p (op, mode, &num_insns, &value))
692 return false;
693
694 return num_insns > 1;
695 })
696
697 ;; Return true if the operand is a constant that can be loaded with a vspltisw
698 ;; instruction and then a vupkhsw instruction.
699
700 (define_predicate "vspltisw_vupkhsw_constant_split"
701 (and (match_code "const_vector")
702 (match_test "vspltisw_vupkhsw_constant_p (op, mode)")))
703
704 ;; Return 1 if the operand is constant that can loaded directly with a XXSPLTIB
705 ;; instruction.
706
707 (define_predicate "xxspltib_constant_nosplit"
708 (match_code "const_vector,vec_duplicate,const_int")
709 {
710 int value = 256;
711 int num_insns = -1;
712
713 if (!xxspltib_constant_p (op, mode, &num_insns, &value))
714 return false;
715
716 return num_insns == 1;
717 })
718
719 ;; Return 1 if the operand is a CONST_VECTOR and can be loaded into a
720 ;; vector register without using memory.
721 (define_predicate "easy_vector_constant"
722 (match_code "const_vector")
723 {
724 if (VECTOR_MEM_ALTIVEC_OR_VSX_P (mode))
725 {
726 int value = 256;
727 int num_insns = -1;
728
729 if (zero_constant (op, mode) || all_ones_constant (op, mode))
730 return true;
731
732 /* Constants that can be generated with ISA 3.1 instructions are
733 easy. */
734 vec_const_128bit_type vsx_const;
735 if (TARGET_POWER10 && vec_const_128bit_to_bytes (op, mode, &vsx_const))
736 {
737 if (constant_generates_lxvkq (&vsx_const))
738 return true;
739
740 if (constant_generates_xxspltiw (&vsx_const))
741 return true;
742
743 if (constant_generates_xxspltidp (&vsx_const))
744 return true;
745 }
746
747 if (TARGET_P9_VECTOR
748 && xxspltib_constant_p (op, mode, &num_insns, &value))
749 return true;
750
751 /* V2DI constant within RANGE (-16, 15) can be synthesized with a
752 vspltisw and a vupkhsw. */
753 if (vspltisw_vupkhsw_constant_p (op, mode, &value))
754 return true;
755
756 return easy_altivec_constant (op, mode);
757 }
758
759 return false;
760 })
761
762 ;; Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF.
763 (define_predicate "easy_vector_constant_add_self"
764 (and (match_code "const_vector")
765 (and (match_test "TARGET_ALTIVEC")
766 (match_test "easy_altivec_constant (op, mode)")))
767 {
768 HOST_WIDE_INT val;
769 int elt;
770 if (mode == V2DImode || mode == V2DFmode)
771 return 0;
772 elt = BYTES_BIG_ENDIAN ? GET_MODE_NUNITS (mode) - 1 : 0;
773 val = const_vector_elt_as_int (op, elt);
774 val = sext_hwi (val, 8);
775 return EASY_VECTOR_15_ADD_SELF (val);
776 })
777
778 ;; Same as easy_vector_constant but only for EASY_VECTOR_MSB.
779 (define_predicate "easy_vector_constant_msb"
780 (and (match_code "const_vector")
781 (and (match_test "TARGET_ALTIVEC")
782 (match_test "easy_altivec_constant (op, mode)")
783 (match_test "vspltis_shifted (op) == 0")))
784 {
785 HOST_WIDE_INT val;
786 int elt, sz = easy_altivec_constant (op, mode);
787 machine_mode inner = GET_MODE_INNER (mode);
788 int isz = GET_MODE_SIZE (inner);
789 if (mode == V2DImode || mode == V2DFmode)
790 return 0;
791 elt = BYTES_BIG_ENDIAN ? GET_MODE_NUNITS (mode) - 1 : 0;
792 if (isz < sz)
793 {
794 if (const_vector_elt_as_int (op, elt) != 0)
795 return 0;
796 elt += (BYTES_BIG_ENDIAN ? -1 : 1) * (sz - isz) / isz;
797 }
798 else if (isz > sz)
799 inner = smallest_int_mode_for_size (sz * BITS_PER_UNIT).require ();
800 val = const_vector_elt_as_int (op, elt);
801 return EASY_VECTOR_MSB (val, inner);
802 })
803
804 ;; Return true if this is an easy altivec constant that we form
805 ;; by using VSLDOI.
806 (define_predicate "easy_vector_constant_vsldoi"
807 (and (match_code "const_vector")
808 (and (match_test "TARGET_ALTIVEC")
809 (and (match_test "easy_altivec_constant (op, mode)")
810 (match_test "vspltis_shifted (op) != 0")))))
811
812 ;; Return true if this is a vector constant and each byte in
813 ;; it is the same.
814 (define_predicate "const_vector_each_byte_same"
815 (match_code "const_vector")
816 {
817 rtx elt;
818 if (!const_vec_duplicate_p (op, &elt))
819 return false;
820
821 machine_mode emode = GET_MODE_INNER (mode);
822 unsigned HOST_WIDE_INT eval;
823 if (CONST_INT_P (elt))
824 eval = INTVAL (elt);
825 else if (CONST_DOUBLE_AS_FLOAT_P (elt))
826 {
827 gcc_assert (emode == SFmode || emode == DFmode);
828 long l[2];
829 real_to_target (l, CONST_DOUBLE_REAL_VALUE (elt), emode);
830 /* real_to_target puts 32-bit pieces in each long. */
831 eval = zext_hwi (l[0], 32);
832 eval |= zext_hwi (l[1], 32) << 32;
833 }
834 else
835 return false;
836
837 unsigned int esize = GET_MODE_SIZE (emode);
838 unsigned char byte0 = eval & 0xff;
839 for (unsigned int i = 1; i < esize; i++)
840 {
841 eval >>= BITS_PER_UNIT;
842 if (byte0 != (eval & 0xff))
843 return false;
844 }
845
846 return true;
847 })
848
849 ;; Return 1 if operand is a vector int register or is either a vector constant
850 ;; of all 0 bits of a vector constant of all 1 bits.
851 (define_predicate "vector_int_reg_or_same_bit"
852 (match_code "reg,subreg,const_vector")
853 {
854 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
855 return 0;
856
857 else if (REG_P (op) || SUBREG_P (op))
858 return vint_operand (op, mode);
859
860 else
861 return op == CONST0_RTX (mode) || op == CONSTM1_RTX (mode);
862 })
863
864 ;; Return 1 if the operand is a V2DI or V4SI const_vector, where each element
865 ;; is the same constant, and the constant can be used for a shift operation.
866 ;; This is to prevent sub-optimal code, that needs to load up the constant and
867 ;; then zero extend it 32 or 64-bit vectors or load up the constant from the
868 ;; literal pool.
869 ;;
870 ;; For V4SImode, we only recognize shifts by 16..31 on ISA 3.0, since shifts by
871 ;; 1..15 can be handled by the normal VSPLTISW and vector shift instruction.
872 ;; For V2DImode, we do this all of the time, since there is no convenient
873 ;; instruction to load up a vector long long splatted constant.
874 ;;
875 ;; If we can use XXSPLTIB, then allow constants up to 63. If not, we restrict
876 ;; the constant to 0..15 that can be loaded with VSPLTISW. V4SI shifts are
877 ;; only optimized for ISA 3.0 when the shift value is >= 16 and <= 31. Values
878 ;; between 0 and 15 can use a normal VSPLTISW to load the value, and it doesn't
879 ;; need this optimization.
880 (define_predicate "vector_shift_constant"
881 (match_code "const_vector,vec_duplicate")
882 {
883 unsigned HOST_WIDE_INT min_value;
884
885 if (mode == V2DImode)
886 {
887 min_value = 0;
888 if (!TARGET_P8_VECTOR)
889 return 0;
890 }
891 else if (mode == V4SImode)
892 {
893 min_value = 16;
894 if (!TARGET_P9_VECTOR)
895 return 0;
896 }
897 else
898 return 0;
899
900 unsigned HOST_WIDE_INT max_value = TARGET_P9_VECTOR ? 63 : 15;
901
902 if (GET_CODE (op) == CONST_VECTOR)
903 {
904 unsigned HOST_WIDE_INT first = UINTVAL (CONST_VECTOR_ELT (op, 0));
905 unsigned nunits = GET_MODE_NUNITS (mode);
906 unsigned i;
907
908 if (!IN_RANGE (first, min_value, max_value))
909 return 0;
910
911 for (i = 1; i < nunits; i++)
912 if (first != UINTVAL (CONST_VECTOR_ELT (op, i)))
913 return 0;
914
915 return 1;
916 }
917 else
918 {
919 rtx op0 = XEXP (op, 0);
920 if (!CONST_INT_P (op0))
921 return 0;
922
923 return IN_RANGE (UINTVAL (op0), min_value, max_value);
924 }
925 })
926
927 ;; Return 1 if operand is 0.0.
928 (define_predicate "zero_fp_constant"
929 (and (match_code "const_double")
930 (match_test "SCALAR_FLOAT_MODE_P (mode)
931 && op == CONST0_RTX (mode)")))
932
933 ;; Return 1 if the operand is in volatile memory. Note that during the
934 ;; RTL generation phase, memory_operand does not return TRUE for volatile
935 ;; memory references. So this function allows us to recognize volatile
936 ;; references where it's safe.
937 (define_predicate "volatile_mem_operand"
938 (and (match_code "mem")
939 (match_test "MEM_VOLATILE_P (op)")
940 (if_then_else (match_test "reload_completed")
941 (match_operand 0 "memory_operand")
942 (match_test "memory_address_p (mode, XEXP (op, 0))"))))
943
944 ;; Return 1 if the operand is a volatile or non-volatile memory operand.
945 (define_predicate "any_memory_operand"
946 (ior (match_operand 0 "memory_operand")
947 (match_operand 0 "volatile_mem_operand")))
948
949 ;; Return 1 if the operand is an offsettable memory operand.
950 (define_predicate "offsettable_mem_operand"
951 (and (match_operand 0 "any_memory_operand")
952 (match_test "offsettable_nonstrict_memref_p (op)")))
953
954 ;; Return 1 if the operand is a simple offsettable memory operand
955 ;; that does not include pre-increment, post-increment, etc.
956 (define_predicate "simple_offsettable_mem_operand"
957 (match_operand 0 "offsettable_mem_operand")
958 {
959 rtx addr = XEXP (op, 0);
960
961 if (GET_CODE (addr) != PLUS && GET_CODE (addr) != LO_SUM)
962 return 0;
963
964 if (!CONSTANT_P (XEXP (addr, 1)))
965 return 0;
966
967 return base_reg_operand (XEXP (addr, 0), Pmode);
968 })
969
970 ;; Return 1 if the operand is suitable for load/store quad memory.
971 ;; This predicate only checks for non-atomic loads/stores (not lqarx/stqcx).
972 (define_predicate "quad_memory_operand"
973 (match_code "mem")
974 {
975 if (!TARGET_QUAD_MEMORY && !TARGET_SYNC_TI)
976 return false;
977
978 if (GET_MODE_SIZE (mode) != 16 || MEM_ALIGN (op) < 128)
979 return false;
980
981 return quad_address_p (XEXP (op, 0), mode, false);
982 })
983
984 ;; Return 1 if the operand is suitable for load/store to vector registers with
985 ;; d-form addressing (register+offset), which was added in ISA 3.0.
986 ;; Unlike quad_memory_operand, we do not have to check for alignment.
987 (define_predicate "vsx_quad_dform_memory_operand"
988 (match_code "mem")
989 {
990 if (!TARGET_P9_VECTOR)
991 return false;
992
993 return quad_address_p (XEXP (op, 0), mode, false);
994 })
995
996 ;; Return 1 if the operand is an indexed or indirect memory operand.
997 (define_predicate "indexed_or_indirect_operand"
998 (match_code "mem")
999 {
1000 op = XEXP (op, 0);
1001 if (VECTOR_MEM_ALTIVEC_P (mode)
1002 && GET_CODE (op) == AND
1003 && CONST_INT_P (XEXP (op, 1))
1004 && INTVAL (XEXP (op, 1)) == -16)
1005 op = XEXP (op, 0);
1006
1007 return indexed_or_indirect_address (op, mode);
1008 })
1009
1010 ;; Like indexed_or_indirect_operand, but also allow a GPR register if direct
1011 ;; moves are supported.
1012 (define_predicate "reg_or_indexed_operand"
1013 (match_code "mem,reg,subreg")
1014 {
1015 if (MEM_P (op))
1016 return indexed_or_indirect_operand (op, mode);
1017 else if (TARGET_DIRECT_MOVE)
1018 return register_operand (op, mode);
1019 return
1020 0;
1021 })
1022
1023 ;; Return 1 if the operand is an indexed or indirect memory operand with an
1024 ;; AND -16 in it, used to recognize when we need to switch to Altivec loads
1025 ;; to realign loops instead of VSX (altivec silently ignores the bottom bits,
1026 ;; while VSX uses the full address and traps)
1027 (define_predicate "altivec_indexed_or_indirect_operand"
1028 (match_code "mem")
1029 {
1030 op = XEXP (op, 0);
1031 if (VECTOR_MEM_ALTIVEC_OR_VSX_P (mode)
1032 && GET_CODE (op) == AND
1033 && CONST_INT_P (XEXP (op, 1))
1034 && INTVAL (XEXP (op, 1)) == -16)
1035 return indexed_or_indirect_address (XEXP (op, 0), mode);
1036
1037 return 0;
1038 })
1039
1040 ;; Return 1 if the operand is an indexed or indirect address.
1041 (define_special_predicate "indexed_or_indirect_address"
1042 (and (match_test "REG_P (op)
1043 || (GET_CODE (op) == PLUS
1044 /* Omit testing REG_P (XEXP (op, 0)). */
1045 && REG_P (XEXP (op, 1)))")
1046 (match_operand 0 "address_operand")))
1047
1048 ;; Return 1 if the operand is an index-form address.
1049 (define_special_predicate "indexed_address"
1050 (match_test "(GET_CODE (op) == PLUS
1051 && REG_P (XEXP (op, 0))
1052 && REG_P (XEXP (op, 1)))"))
1053
1054 ;; Return 1 if the operand is a MEM with an update-form address. This may
1055 ;; also include update-indexed form.
1056 (define_special_predicate "update_address_mem"
1057 (match_test "(MEM_P (op)
1058 && (GET_CODE (XEXP (op, 0)) == PRE_INC
1059 || GET_CODE (XEXP (op, 0)) == PRE_DEC
1060 || GET_CODE (XEXP (op, 0)) == PRE_MODIFY))"))
1061
1062 ;; Anything that matches memory_operand but does not update the address.
1063 (define_predicate "non_update_memory_operand"
1064 (match_code "mem")
1065 {
1066 if (update_address_mem (op, mode))
1067 return 0;
1068 return memory_operand (op, mode);
1069 })
1070
1071 ;; Return 1 if the operand is a MEM with an indexed-form address.
1072 (define_special_predicate "indexed_address_mem"
1073 (match_test "(MEM_P (op)
1074 && (indexed_address (XEXP (op, 0), mode)
1075 || (GET_CODE (XEXP (op, 0)) == PRE_MODIFY
1076 && indexed_address (XEXP (XEXP (op, 0), 1), mode))))"))
1077
1078 ;; Return 1 if the operand is either a non-special register or can be used
1079 ;; as the operand of a `mode' add insn.
1080 (define_predicate "add_operand"
1081 (if_then_else (match_code "const_int")
1082 (match_test "satisfies_constraint_I (op)
1083 || satisfies_constraint_L (op)
1084 || satisfies_constraint_eI (op)")
1085 (match_operand 0 "gpc_reg_operand")))
1086
1087 ;; Return 1 if the operand is either a non-special register, or 0, or -1.
1088 (define_predicate "adde_operand"
1089 (if_then_else (match_code "const_int")
1090 (match_test "INTVAL (op) == 0 || INTVAL (op) == -1")
1091 (match_operand 0 "gpc_reg_operand")))
1092
1093 ;; Return 1 if OP is a constant but not a valid add_operand.
1094 (define_predicate "non_add_cint_operand"
1095 (and (match_code "const_int")
1096 (not (match_operand 0 "add_operand"))))
1097
1098 ;; Return 1 if the operand is a constant that can be used as the operand
1099 ;; of an AND, OR or XOR.
1100 (define_predicate "logical_const_operand"
1101 (match_code "const_int")
1102 {
1103 HOST_WIDE_INT opl;
1104
1105 opl = INTVAL (op) & GET_MODE_MASK (mode);
1106
1107 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
1108 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
1109 })
1110
1111 ;; Return 1 if the operand is a non-special register or a constant that
1112 ;; can be used as the operand of an AND, OR or XOR.
1113 (define_predicate "logical_operand"
1114 (ior (match_operand 0 "gpc_reg_operand")
1115 (match_operand 0 "logical_const_operand")))
1116
1117 ;; Return 1 if op is a constant that is not a logical operand, but could
1118 ;; be split into one.
1119 (define_predicate "non_logical_cint_operand"
1120 (and (match_code "const_int,const_wide_int")
1121 (and (not (match_operand 0 "logical_operand"))
1122 (match_operand 0 "reg_or_logical_cint_operand"))))
1123
1124 ;; Return 1 if the operand is either a non-special register or a
1125 ;; constant that can be used as the operand of a logical AND.
1126 (define_predicate "and_operand"
1127 (ior (and (match_code "const_int")
1128 (match_test "rs6000_is_valid_and_mask (op, mode)"))
1129 (if_then_else (match_test "fixed_regs[CR0_REGNO]")
1130 (match_operand 0 "gpc_reg_operand")
1131 (match_operand 0 "logical_operand"))))
1132
1133 ;; Return 1 if the operand is either a logical operand or a short cint operand.
1134 (define_predicate "scc_eq_operand"
1135 (ior (match_operand 0 "logical_operand")
1136 (match_operand 0 "short_cint_operand")))
1137
1138 ;; Return 1 if the operand is a general non-special register or memory operand.
1139 (define_predicate "reg_or_mem_operand"
1140 (ior (match_operand 0 "gpc_reg_operand")
1141 (match_operand 0 "any_memory_operand")
1142 (and (match_code "mem")
1143 (match_test "macho_lo_sum_memory_operand (op, mode)"))))
1144
1145 ;; Return 1 if the operand is CONST_DOUBLE 0, register or memory operand.
1146 (define_predicate "zero_reg_mem_operand"
1147 (ior (and (match_test "TARGET_VSX")
1148 (match_operand 0 "zero_fp_constant"))
1149 (match_operand 0 "reg_or_mem_operand")))
1150
1151 ;; Return 1 if the operand is a CONST_INT and it is the element for 64-bit
1152 ;; data types inside of a vector that scalar instructions operate on
1153 (define_predicate "vsx_scalar_64bit"
1154 (match_code "const_int")
1155 {
1156 return (INTVAL (op) == VECTOR_ELEMENT_SCALAR_64BIT);
1157 })
1158
1159 ;; Return 1 if the operand is a general register or memory operand without
1160 ;; pre_inc or pre_dec or pre_modify, which produces invalid form of PowerPC
1161 ;; lwa instruction.
1162 (define_predicate "lwa_operand"
1163 (match_code "reg,subreg,mem")
1164 {
1165 rtx inner, addr, offset;
1166
1167 inner = op;
1168 if (reload_completed && SUBREG_P (inner))
1169 inner = SUBREG_REG (inner);
1170
1171 if (gpc_reg_operand (inner, mode))
1172 return true;
1173 if (!any_memory_operand (inner, mode))
1174 return false;
1175
1176 addr = XEXP (inner, 0);
1177
1178 /* The LWA instruction uses the DS-form instruction format which requires
1179 that the bottom two bits of the offset must be 0. The prefixed PLWA does
1180 not have this restriction. While the actual load from memory is 32-bits,
1181 we pass in DImode here to test for using a DS instruction. */
1182 if (address_is_prefixed (addr, DImode, NON_PREFIXED_DS))
1183 return true;
1184
1185 if (GET_CODE (addr) == PRE_INC
1186 || GET_CODE (addr) == PRE_DEC
1187 || (GET_CODE (addr) == PRE_MODIFY
1188 && !legitimate_indexed_address_p (XEXP (addr, 1), 0)))
1189 return false;
1190 if (GET_CODE (addr) == LO_SUM
1191 && REG_P (XEXP (addr, 0))
1192 && GET_CODE (XEXP (addr, 1)) == CONST)
1193 addr = XEXP (XEXP (addr, 1), 0);
1194 if (GET_CODE (addr) != PLUS)
1195 return true;
1196 offset = XEXP (addr, 1);
1197 if (!CONST_INT_P (offset))
1198 return true;
1199 return INTVAL (offset) % 4 == 0;
1200 })
1201
1202 ;; Return 1 if the operand, used inside a MEM, is a SYMBOL_REF.
1203 (define_predicate "symbol_ref_operand"
1204 (and (match_code "symbol_ref")
1205 (match_test "(mode == VOIDmode || GET_MODE (op) == mode)
1206 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))")))
1207
1208 ;; Return 1 if op is an operand that can be loaded via the GOT.
1209 ;; or non-special register field no cr0
1210 (define_predicate "got_operand"
1211 (match_code "symbol_ref,const,label_ref"))
1212
1213 ;; Return 1 if op is a simple reference that can be loaded via the GOT,
1214 ;; excluding labels involving addition.
1215 (define_predicate "got_no_const_operand"
1216 (match_code "symbol_ref,label_ref"))
1217
1218 ;; Return 1 if op is a SYMBOL_REF for a TLS symbol.
1219 (define_predicate "rs6000_tls_symbol_ref"
1220 (and (match_code "symbol_ref")
1221 (match_test "RS6000_SYMBOL_REF_TLS_P (op)")))
1222
1223 ;; Return 1 for the CONST_INT or UNSPEC second CALL operand.
1224 ;; Prevents unwanted substitution of the unspec got_reg arg.
1225 (define_predicate "unspec_tls"
1226 (match_code "const_int,unspec")
1227 {
1228 if (CONST_INT_P (op))
1229 return 1;
1230 if (XINT (op, 1) == UNSPEC_TLSGD)
1231 return REG_P (XVECEXP (op, 0, 1)) || XVECEXP (op, 0, 1) == const0_rtx;
1232 if (XINT (op, 1) == UNSPEC_TLSLD)
1233 return REG_P (XVECEXP (op, 0, 0)) || XVECEXP (op, 0, 0) == const0_rtx;
1234 return 0;
1235 })
1236
1237 ;; Return 1 if the operand, used inside a MEM, is a valid first argument
1238 ;; to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR.
1239 (define_predicate "call_operand"
1240 (if_then_else (match_code "reg")
1241 (match_test "REGNO (op) == LR_REGNO
1242 || REGNO (op) == CTR_REGNO
1243 || !HARD_REGISTER_P (op)")
1244 (match_code "symbol_ref")))
1245
1246 ;; Return 1 if the operand, used inside a MEM, is a valid first argument
1247 ;; to an indirect CALL. This is LR, CTR, or a PLTSEQ unspec using CTR.
1248 (define_predicate "indirect_call_operand"
1249 (match_code "reg,unspec")
1250 {
1251 if (REG_P (op))
1252 return (REGNO (op) == LR_REGNO
1253 || REGNO (op) == CTR_REGNO);
1254 if (GET_CODE (op) == UNSPEC)
1255 {
1256 if (XINT (op, 1) != UNSPEC_PLTSEQ)
1257 return false;
1258 op = XVECEXP (op, 0, 0);
1259 return REG_P (op) && REGNO (op) == CTR_REGNO;
1260 }
1261 return false;
1262 })
1263
1264 ;; Return 1 if the operand is a SYMBOL_REF for a function known to be in
1265 ;; this file.
1266 (define_predicate "current_file_function_operand"
1267 (and (match_code "symbol_ref")
1268 (match_test "(DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
1269 && (SYMBOL_REF_LOCAL_P (op)
1270 || (op == XEXP (DECL_RTL (current_function_decl), 0)
1271 && !decl_replaceable_p (current_function_decl,
1272 opt_for_fn (current_function_decl,
1273 flag_semantic_interposition))))
1274 && !((DEFAULT_ABI == ABI_AIX
1275 || DEFAULT_ABI == ABI_ELFv2)
1276 && (SYMBOL_REF_EXTERNAL_P (op)
1277 || SYMBOL_REF_WEAK (op)))
1278 && !(DEFAULT_ABI == ABI_ELFv2
1279 && SYMBOL_REF_DECL (op) != NULL
1280 && TREE_CODE (SYMBOL_REF_DECL (op)) == FUNCTION_DECL
1281 && (rs6000_fndecl_pcrel_p (SYMBOL_REF_DECL (op))
1282 != rs6000_pcrel_p ()))")))
1283
1284 ;; Return 1 if this operand is a valid input for a move insn.
1285 (define_predicate "input_operand"
1286 (match_code "symbol_ref,const,reg,subreg,mem,
1287 const_double,const_wide_int,const_vector,const_int")
1288 {
1289 /* Memory is always valid. */
1290 if (any_memory_operand (op, mode))
1291 return 1;
1292
1293 /* For floating-point, easy constants are valid. */
1294 if (SCALAR_FLOAT_MODE_P (mode)
1295 && easy_fp_constant (op, mode))
1296 return 1;
1297
1298 /* Allow any integer constant. */
1299 if (SCALAR_INT_MODE_P (mode) && CONST_SCALAR_INT_P (op))
1300 return 1;
1301
1302 /* Allow easy vector constants. */
1303 if (GET_CODE (op) == CONST_VECTOR
1304 && easy_vector_constant (op, mode))
1305 return 1;
1306
1307 /* For floating-point or multi-word mode, the only remaining valid type
1308 is a register. */
1309 if (SCALAR_FLOAT_MODE_P (mode)
1310 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
1311 return register_operand (op, mode);
1312
1313 /* We don't allow moving the carry bit around. */
1314 if (ca_operand (op, mode))
1315 return 0;
1316
1317 /* The only cases left are integral modes one word or smaller (we
1318 do not get called for MODE_CC values). These can be in any
1319 register. */
1320 if (register_operand (op, mode))
1321 return 1;
1322
1323 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
1324 to be valid. */
1325 if (DEFAULT_ABI == ABI_V4
1326 && (SYMBOL_REF_P (op) || GET_CODE (op) == CONST)
1327 && small_data_operand (op, Pmode))
1328 return 1;
1329
1330 return 0;
1331 })
1332
1333 ;; Return 1 if this operand is a valid input for a vsx_splat insn.
1334 (define_predicate "splat_input_operand"
1335 (match_code "reg,subreg,mem")
1336 {
1337 machine_mode vmode;
1338
1339 if (mode == DFmode)
1340 vmode = V2DFmode;
1341 else if (mode == DImode)
1342 vmode = V2DImode;
1343 else if (mode == SImode && TARGET_P9_VECTOR)
1344 vmode = V4SImode;
1345 else if (mode == SFmode && TARGET_P9_VECTOR)
1346 vmode = V4SFmode;
1347 else
1348 return false;
1349
1350 if (MEM_P (op))
1351 {
1352 rtx addr = XEXP (op, 0);
1353
1354 if (! volatile_ok && MEM_VOLATILE_P (op))
1355 return 0;
1356
1357 if (lra_in_progress || reload_completed)
1358 return indexed_or_indirect_address (addr, vmode);
1359 else
1360 return memory_address_addr_space_p (vmode, addr, MEM_ADDR_SPACE (op));
1361 }
1362 return gpc_reg_operand (op, mode);
1363 })
1364
1365 ;; Return 1 if this operand is valid for a MMA assemble accumulator insn.
1366 (define_special_predicate "mma_assemble_input_operand"
1367 (match_test "(mode == V16QImode
1368 && (vsx_register_operand (op, mode)
1369 || (MEM_P (op)
1370 && (indexed_or_indirect_address (XEXP (op, 0), mode)
1371 || quad_address_p (XEXP (op, 0), mode, false)))))"))
1372
1373 ;; Return 1 if this operand is valid for an MMA disassemble insn.
1374 (define_predicate "mma_disassemble_output_operand"
1375 (match_code "reg,subreg,mem")
1376 {
1377 if (MEM_P (op))
1378 {
1379 rtx addr = XEXP (op, 0);
1380 return indexed_or_indirect_address (addr, mode)
1381 || quad_address_p (addr, mode, false);
1382 }
1383
1384 if (SUBREG_P (op))
1385 op = SUBREG_REG (op);
1386
1387 return vsx_register_operand (op, mode);
1388 })
1389
1390 ;; Return true if operand is an operator used in rotate-and-mask instructions.
1391 (define_predicate "rotate_mask_operator"
1392 (match_code "rotate,ashift,lshiftrt"))
1393
1394 ;; Return true if operand is boolean operator.
1395 (define_predicate "boolean_operator"
1396 (match_code "and,ior,xor"))
1397
1398 ;; Return true if operand is OR-form of boolean operator.
1399 (define_predicate "boolean_or_operator"
1400 (match_code "ior,xor"))
1401
1402 ;; Return true if operand is an equality operator.
1403 (define_special_predicate "equality_operator"
1404 (match_code "eq,ne"))
1405
1406 ;; Return 1 if OP is a comparison operation that is valid for a branch
1407 ;; instruction. We check the opcode against the mode of the CC value.
1408 ;; validate_condition_mode is an assertion.
1409 (define_predicate "branch_comparison_operator"
1410 (and (match_operand 0 "comparison_operator")
1411 (match_test "GET_MODE_CLASS (GET_MODE (XEXP (op, 0))) == MODE_CC")
1412 (if_then_else (match_test "GET_MODE (XEXP (op, 0)) == CCFPmode")
1413 (if_then_else (match_test "flag_finite_math_only")
1414 (match_code "lt,le,gt,ge,eq,ne,unordered,ordered")
1415 (match_code "lt,gt,eq,unordered,unge,unle,ne,ordered"))
1416 (match_code "lt,ltu,le,leu,gt,gtu,ge,geu,eq,ne"))
1417 (match_test "validate_condition_mode (GET_CODE (op),
1418 GET_MODE (XEXP (op, 0))),
1419 1")))
1420
1421 ;; Return 1 if OP is a comparison that needs an extra instruction to do (a
1422 ;; crlogical or an extra branch).
1423 (define_predicate "extra_insn_branch_comparison_operator"
1424 (and (match_operand 0 "comparison_operator")
1425 (match_test "GET_MODE (XEXP (op, 0)) == CCFPmode")
1426 (match_code "ltgt,le,ge,unlt,ungt,uneq")
1427 (match_test "validate_condition_mode (GET_CODE (op),
1428 GET_MODE (XEXP (op, 0))),
1429 1")))
1430
1431 ;; Return 1 if OP is an unsigned comparison operator.
1432 (define_predicate "unsigned_comparison_operator"
1433 (match_code "ltu,gtu,leu,geu"))
1434
1435 ;; Return 1 if OP is a signed comparison operator.
1436 (define_predicate "signed_comparison_operator"
1437 (match_code "lt,gt,le,ge"))
1438
1439 ;; Return 1 if OP is a signed comparison or an equality operator.
1440 (define_predicate "signed_or_equality_comparison_operator"
1441 (ior (match_operand 0 "equality_operator")
1442 (match_operand 0 "signed_comparison_operator")))
1443
1444 ;; Return 1 if OP is an unsigned comparison or an equality operator.
1445 (define_predicate "unsigned_or_equality_comparison_operator"
1446 (ior (match_operand 0 "equality_operator")
1447 (match_operand 0 "unsigned_comparison_operator")))
1448
1449 ;; Return 1 if OP is a comparison operation that is valid for an SCC insn --
1450 ;; it must be a positive comparison.
1451 (define_predicate "scc_comparison_operator"
1452 (and (match_operand 0 "branch_comparison_operator")
1453 (match_code "eq,lt,gt,ltu,gtu,unordered")))
1454
1455 ;; Return 1 if OP is a comparison operation whose inverse would be valid for
1456 ;; an SCC insn.
1457 (define_predicate "scc_rev_comparison_operator"
1458 (and (match_operand 0 "branch_comparison_operator")
1459 (match_code "ne,le,ge,leu,geu,ordered")))
1460
1461 ;; Return 1 if OP is a comparison operator suitable for floating point
1462 ;; vector/scalar comparisons that generate a -1/0 mask.
1463 (define_predicate "fpmask_comparison_operator"
1464 (match_code "eq,gt,ge"))
1465
1466 ;; Return 1 if OP is a comparison operator suitable for vector/scalar
1467 ;; comparisons that generate a 0/-1 mask (i.e. the inverse of
1468 ;; fpmask_comparison_operator).
1469 (define_predicate "invert_fpmask_comparison_operator"
1470 (match_code "ne,unlt,unle"))
1471
1472 ;; Return 1 if OP is a comparison operation suitable for integer vector/scalar
1473 ;; comparisons that generate a -1/0 mask.
1474 (define_predicate "vecint_comparison_operator"
1475 (match_code "eq,gt,gtu"))
1476
1477 ;; Return 1 if OP is a comparison operation that is valid for a branch
1478 ;; insn, which is true if the corresponding bit in the CC register is set.
1479 (define_predicate "branch_positive_comparison_operator"
1480 (and (match_operand 0 "branch_comparison_operator")
1481 (match_code "eq,lt,gt,ltu,gtu,unordered")))
1482
1483 ;; Return 1 if OP is valid for a save_world call in prologue, known to be
1484 ;; a PARLLEL.
1485 (define_predicate "save_world_operation"
1486 (match_code "parallel")
1487 {
1488 int index;
1489 int i;
1490 rtx elt;
1491 int count = XVECLEN (op, 0);
1492
1493 if (count != 54)
1494 return 0;
1495
1496 index = 0;
1497 if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1498 || GET_CODE (XVECEXP (op, 0, index++)) != USE)
1499 return 0;
1500
1501 for (i=1; i <= 18; i++)
1502 {
1503 elt = XVECEXP (op, 0, index++);
1504 if (GET_CODE (elt) != SET
1505 || !MEM_P (SET_DEST (elt))
1506 || !memory_operand (SET_DEST (elt), DFmode)
1507 || !REG_P (SET_SRC (elt))
1508 || GET_MODE (SET_SRC (elt)) != DFmode)
1509 return 0;
1510 }
1511
1512 for (i=1; i <= 12; i++)
1513 {
1514 elt = XVECEXP (op, 0, index++);
1515 if (GET_CODE (elt) != SET
1516 || !MEM_P (SET_DEST (elt))
1517 || !REG_P (SET_SRC (elt))
1518 || GET_MODE (SET_SRC (elt)) != V4SImode)
1519 return 0;
1520 }
1521
1522 for (i=1; i <= 19; i++)
1523 {
1524 elt = XVECEXP (op, 0, index++);
1525 if (GET_CODE (elt) != SET
1526 || !MEM_P (SET_DEST (elt))
1527 || !memory_operand (SET_DEST (elt), Pmode)
1528 || !REG_P (SET_SRC (elt))
1529 || GET_MODE (SET_SRC (elt)) != Pmode)
1530 return 0;
1531 }
1532
1533 elt = XVECEXP (op, 0, index++);
1534 if (GET_CODE (elt) != SET
1535 || !MEM_P (SET_DEST (elt))
1536 || !memory_operand (SET_DEST (elt), Pmode)
1537 || !REG_P (SET_SRC (elt))
1538 || REGNO (SET_SRC (elt)) != CR2_REGNO
1539 || GET_MODE (SET_SRC (elt)) != Pmode)
1540 return 0;
1541
1542 if (GET_CODE (XVECEXP (op, 0, index++)) != SET
1543 || GET_CODE (XVECEXP (op, 0, index++)) != SET)
1544 return 0;
1545 return 1;
1546 })
1547
1548 ;; Return 1 if OP is valid for a restore_world call in epilogue, known to be
1549 ;; a PARLLEL.
1550 (define_predicate "restore_world_operation"
1551 (match_code "parallel")
1552 {
1553 int index;
1554 int i;
1555 rtx elt;
1556 int count = XVECLEN (op, 0);
1557
1558 if (count != 58)
1559 return 0;
1560
1561 index = 0;
1562 if (GET_CODE (XVECEXP (op, 0, index++)) != RETURN
1563 || GET_CODE (XVECEXP (op, 0, index++)) != USE
1564 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
1565 return 0;
1566
1567 elt = XVECEXP (op, 0, index++);
1568 if (GET_CODE (elt) != SET
1569 || !MEM_P (SET_SRC (elt))
1570 || !memory_operand (SET_SRC (elt), Pmode)
1571 || !REG_P (SET_DEST (elt))
1572 || REGNO (SET_DEST (elt)) != CR2_REGNO
1573 || GET_MODE (SET_DEST (elt)) != Pmode)
1574 return 0;
1575
1576 for (i=1; i <= 19; i++)
1577 {
1578 elt = XVECEXP (op, 0, index++);
1579 if (GET_CODE (elt) != SET
1580 || !MEM_P (SET_SRC (elt))
1581 || !memory_operand (SET_SRC (elt), Pmode)
1582 || !REG_P (SET_DEST (elt))
1583 || GET_MODE (SET_DEST (elt)) != Pmode)
1584 return 0;
1585 }
1586
1587 for (i=1; i <= 12; i++)
1588 {
1589 elt = XVECEXP (op, 0, index++);
1590 if (GET_CODE (elt) != SET
1591 || !MEM_P (SET_SRC (elt))
1592 || !REG_P (SET_DEST (elt))
1593 || GET_MODE (SET_DEST (elt)) != V4SImode)
1594 return 0;
1595 }
1596
1597 for (i=1; i <= 18; i++)
1598 {
1599 elt = XVECEXP (op, 0, index++);
1600 if (GET_CODE (elt) != SET
1601 || !MEM_P (SET_SRC (elt))
1602 || !memory_operand (SET_SRC (elt), DFmode)
1603 || !REG_P (SET_DEST (elt))
1604 || GET_MODE (SET_DEST (elt)) != DFmode)
1605 return 0;
1606 }
1607
1608 if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1609 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1610 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1611 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1612 || GET_CODE (XVECEXP (op, 0, index++)) != USE)
1613 return 0;
1614 return 1;
1615 })
1616
1617 ;; Return 1 if OP is valid for a vrsave call, known to be a PARALLEL.
1618 (define_predicate "vrsave_operation"
1619 (match_code "parallel")
1620 {
1621 int count = XVECLEN (op, 0);
1622 unsigned int dest_regno, src_regno;
1623 int i;
1624
1625 if (count <= 1
1626 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1627 || !REG_P (SET_DEST (XVECEXP (op, 0, 0)))
1628 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE
1629 || XINT (SET_SRC (XVECEXP (op, 0, 0)), 1) != UNSPECV_SET_VRSAVE)
1630 return 0;
1631
1632 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1633 src_regno = REGNO (XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 1));
1634
1635 if (dest_regno != VRSAVE_REGNO || src_regno != VRSAVE_REGNO)
1636 return 0;
1637
1638 for (i = 1; i < count; i++)
1639 {
1640 rtx elt = XVECEXP (op, 0, i);
1641
1642 if (GET_CODE (elt) != CLOBBER
1643 && GET_CODE (elt) != SET)
1644 return 0;
1645 }
1646
1647 return 1;
1648 })
1649
1650 ;; Return 1 if OP is valid for mfcr insn, known to be a PARALLEL.
1651 (define_predicate "mfcr_operation"
1652 (match_code "parallel")
1653 {
1654 int count = XVECLEN (op, 0);
1655 int i;
1656
1657 /* Perform a quick check so we don't blow up below. */
1658 if (count < 1
1659 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1660 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
1661 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
1662 return 0;
1663
1664 for (i = 0; i < count; i++)
1665 {
1666 rtx exp = XVECEXP (op, 0, i);
1667 rtx unspec;
1668 int maskval;
1669 rtx src_reg;
1670
1671 src_reg = XVECEXP (SET_SRC (exp), 0, 0);
1672
1673 if (!REG_P (src_reg)
1674 || GET_MODE (src_reg) != CCmode
1675 || ! CR_REGNO_P (REGNO (src_reg)))
1676 return 0;
1677
1678 if (GET_CODE (exp) != SET
1679 || !REG_P (SET_DEST (exp))
1680 || GET_MODE (SET_DEST (exp)) != SImode
1681 || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
1682 return 0;
1683 unspec = SET_SRC (exp);
1684 maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
1685
1686 if (GET_CODE (unspec) != UNSPEC
1687 || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
1688 || XVECLEN (unspec, 0) != 2
1689 || XVECEXP (unspec, 0, 0) != src_reg
1690 || !CONST_INT_P (XVECEXP (unspec, 0, 1))
1691 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
1692 return 0;
1693 }
1694 return 1;
1695 })
1696
1697 ;; Return 1 if OP is valid for mtcrf insn, known to be a PARALLEL.
1698 (define_predicate "mtcrf_operation"
1699 (match_code "parallel")
1700 {
1701 int count = XVECLEN (op, 0);
1702 int i;
1703 rtx src_reg;
1704
1705 /* Perform a quick check so we don't blow up below. */
1706 if (count < 1
1707 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1708 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
1709 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
1710 return 0;
1711 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
1712
1713 if (!REG_P (src_reg)
1714 || GET_MODE (src_reg) != SImode
1715 || ! INT_REGNO_P (REGNO (src_reg)))
1716 return 0;
1717
1718 for (i = 0; i < count; i++)
1719 {
1720 rtx exp = XVECEXP (op, 0, i);
1721 rtx unspec;
1722 int maskval;
1723
1724 if (GET_CODE (exp) != SET
1725 || !REG_P (SET_DEST (exp))
1726 || GET_MODE (SET_DEST (exp)) != CCmode
1727 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
1728 return 0;
1729 unspec = SET_SRC (exp);
1730 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
1731
1732 if (GET_CODE (unspec) != UNSPEC
1733 || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
1734 || XVECLEN (unspec, 0) != 2
1735 || XVECEXP (unspec, 0, 0) != src_reg
1736 || !CONST_INT_P (XVECEXP (unspec, 0, 1))
1737 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
1738 return 0;
1739 }
1740 return 1;
1741 })
1742
1743 ;; Return 1 if OP is valid for crsave insn, known to be a PARALLEL.
1744 (define_predicate "crsave_operation"
1745 (match_code "parallel")
1746 {
1747 int count = XVECLEN (op, 0);
1748 int i;
1749
1750 for (i = 1; i < count; i++)
1751 {
1752 rtx exp = XVECEXP (op, 0, i);
1753
1754 if (GET_CODE (exp) != USE
1755 || !REG_P (XEXP (exp, 0))
1756 || GET_MODE (XEXP (exp, 0)) != CCmode
1757 || ! CR_REGNO_P (REGNO (XEXP (exp, 0))))
1758 return 0;
1759 }
1760 return 1;
1761 })
1762
1763 ;; Return 1 if OP is valid for lmw insn, known to be a PARALLEL.
1764 (define_predicate "lmw_operation"
1765 (match_code "parallel")
1766 {
1767 int count = XVECLEN (op, 0);
1768 unsigned int dest_regno;
1769 rtx src_addr;
1770 unsigned int base_regno;
1771 HOST_WIDE_INT offset;
1772 int i;
1773
1774 /* Perform a quick check so we don't blow up below. */
1775 if (count <= 1
1776 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1777 || !REG_P (SET_DEST (XVECEXP (op, 0, 0)))
1778 || !MEM_P (SET_SRC (XVECEXP (op, 0, 0))))
1779 return 0;
1780
1781 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1782 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
1783
1784 if (dest_regno > 31
1785 || count != 32 - (int) dest_regno)
1786 return 0;
1787
1788 if (legitimate_indirect_address_p (src_addr, 0))
1789 {
1790 offset = 0;
1791 base_regno = REGNO (src_addr);
1792 if (base_regno == 0)
1793 return 0;
1794 }
1795 else if (rs6000_legitimate_offset_address_p (SImode, src_addr, false, false))
1796 {
1797 offset = INTVAL (XEXP (src_addr, 1));
1798 base_regno = REGNO (XEXP (src_addr, 0));
1799 }
1800 else
1801 return 0;
1802
1803 for (i = 0; i < count; i++)
1804 {
1805 rtx elt = XVECEXP (op, 0, i);
1806 rtx newaddr;
1807 rtx addr_reg;
1808 HOST_WIDE_INT newoffset;
1809
1810 if (GET_CODE (elt) != SET
1811 || !REG_P (SET_DEST (elt))
1812 || GET_MODE (SET_DEST (elt)) != SImode
1813 || REGNO (SET_DEST (elt)) != dest_regno + i
1814 || !MEM_P (SET_SRC (elt))
1815 || GET_MODE (SET_SRC (elt)) != SImode)
1816 return 0;
1817 newaddr = XEXP (SET_SRC (elt), 0);
1818 if (legitimate_indirect_address_p (newaddr, 0))
1819 {
1820 newoffset = 0;
1821 addr_reg = newaddr;
1822 }
1823 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, false, false))
1824 {
1825 addr_reg = XEXP (newaddr, 0);
1826 newoffset = INTVAL (XEXP (newaddr, 1));
1827 }
1828 else
1829 return 0;
1830 if (REGNO (addr_reg) != base_regno
1831 || newoffset != offset + 4 * i)
1832 return 0;
1833 }
1834
1835 return 1;
1836 })
1837
1838 ;; Return 1 if OP is valid for stmw insn, known to be a PARALLEL.
1839 (define_predicate "stmw_operation"
1840 (match_code "parallel")
1841 {
1842 int count = XVECLEN (op, 0);
1843 unsigned int src_regno;
1844 rtx dest_addr;
1845 unsigned int base_regno;
1846 HOST_WIDE_INT offset;
1847 int i;
1848
1849 /* Perform a quick check so we don't blow up below. */
1850 if (count <= 1
1851 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1852 || !MEM_P (SET_DEST (XVECEXP (op, 0, 0)))
1853 || !REG_P (SET_SRC (XVECEXP (op, 0, 0))))
1854 return 0;
1855
1856 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
1857 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
1858
1859 if (src_regno > 31
1860 || count != 32 - (int) src_regno)
1861 return 0;
1862
1863 if (legitimate_indirect_address_p (dest_addr, 0))
1864 {
1865 offset = 0;
1866 base_regno = REGNO (dest_addr);
1867 if (base_regno == 0)
1868 return 0;
1869 }
1870 else if (rs6000_legitimate_offset_address_p (SImode, dest_addr, false, false))
1871 {
1872 offset = INTVAL (XEXP (dest_addr, 1));
1873 base_regno = REGNO (XEXP (dest_addr, 0));
1874 }
1875 else
1876 return 0;
1877
1878 for (i = 0; i < count; i++)
1879 {
1880 rtx elt = XVECEXP (op, 0, i);
1881 rtx newaddr;
1882 rtx addr_reg;
1883 HOST_WIDE_INT newoffset;
1884
1885 if (GET_CODE (elt) != SET
1886 || !REG_P (SET_SRC (elt))
1887 || GET_MODE (SET_SRC (elt)) != SImode
1888 || REGNO (SET_SRC (elt)) != src_regno + i
1889 || !MEM_P (SET_DEST (elt))
1890 || GET_MODE (SET_DEST (elt)) != SImode)
1891 return 0;
1892 newaddr = XEXP (SET_DEST (elt), 0);
1893 if (legitimate_indirect_address_p (newaddr, 0))
1894 {
1895 newoffset = 0;
1896 addr_reg = newaddr;
1897 }
1898 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, false, false))
1899 {
1900 addr_reg = XEXP (newaddr, 0);
1901 newoffset = INTVAL (XEXP (newaddr, 1));
1902 }
1903 else
1904 return 0;
1905 if (REGNO (addr_reg) != base_regno
1906 || newoffset != offset + 4 * i)
1907 return 0;
1908 }
1909
1910 return 1;
1911 })
1912
1913 ;; Return 1 if OP is a stack tie operand.
1914 (define_predicate "tie_operand"
1915 (match_code "parallel")
1916 {
1917 return (GET_CODE (XVECEXP (op, 0, 0)) == SET
1918 && MEM_P (XEXP (XVECEXP (op, 0, 0), 0))
1919 && GET_MODE (XEXP (XVECEXP (op, 0, 0), 0)) == BLKmode
1920 && XEXP (XVECEXP (op, 0, 0), 1) == const0_rtx);
1921 })
1922
1923 ;; Match a small code model toc reference (or medium and large
1924 ;; model toc references before reload).
1925 (define_predicate "small_toc_ref"
1926 (match_code "unspec,plus")
1927 {
1928 if (GET_CODE (op) == PLUS && add_cint_operand (XEXP (op, 1), mode))
1929 op = XEXP (op, 0);
1930
1931 return GET_CODE (op) == UNSPEC && XINT (op, 1) == UNSPEC_TOCREL;
1932 })
1933
1934
1935 ;; Match the first insn (addis) in fusing the combination of addis and loads to
1936 ;; GPR registers on power8.
1937 (define_predicate "fusion_gpr_addis"
1938 (match_code "const_int,high,plus")
1939 {
1940 HOST_WIDE_INT value;
1941 rtx int_const;
1942
1943 if (GET_CODE (op) == HIGH)
1944 return 1;
1945
1946 if (CONST_INT_P (op))
1947 int_const = op;
1948
1949 else if (GET_CODE (op) == PLUS
1950 && base_reg_operand (XEXP (op, 0), Pmode)
1951 && CONST_INT_P (XEXP (op, 1)))
1952 int_const = XEXP (op, 1);
1953
1954 else
1955 return 0;
1956
1957 value = INTVAL (int_const);
1958 if ((value & (HOST_WIDE_INT)0xffff) != 0)
1959 return 0;
1960
1961 if ((value & (HOST_WIDE_INT)0xffff0000) == 0)
1962 return 0;
1963
1964 /* Power8 only does the fusion if the top 12 bits of the addis value are all
1965 1's or 0's. */
1966 return (IN_RANGE (value >> 16, -16, 15));
1967 })
1968
1969 ;; Match the second insn (lbz, lhz, lwz, ld) in fusing the combination of addis
1970 ;; and loads to GPR registers on power8.
1971 (define_predicate "fusion_gpr_mem_load"
1972 (match_code "mem,sign_extend,zero_extend")
1973 {
1974 rtx addr, base, offset;
1975
1976 /* Handle sign/zero extend. */
1977 if (GET_CODE (op) == ZERO_EXTEND
1978 || (TARGET_P8_FUSION_SIGN && GET_CODE (op) == SIGN_EXTEND))
1979 {
1980 op = XEXP (op, 0);
1981 mode = GET_MODE (op);
1982 }
1983
1984 if (!MEM_P (op))
1985 return 0;
1986
1987 switch (mode)
1988 {
1989 case E_QImode:
1990 case E_HImode:
1991 case E_SImode:
1992 break;
1993
1994 case E_DImode:
1995 if (!TARGET_POWERPC64)
1996 return 0;
1997 break;
1998
1999 /* Do not allow SF/DFmode in GPR fusion. While the loads do occur, they
2000 are not common. */
2001 default:
2002 return 0;
2003 }
2004
2005 addr = XEXP (op, 0);
2006 if (GET_CODE (addr) != PLUS && GET_CODE (addr) != LO_SUM)
2007 return 0;
2008
2009 base = XEXP (addr, 0);
2010 if (!base_reg_operand (base, GET_MODE (base)))
2011 return 0;
2012
2013 offset = XEXP (addr, 1);
2014
2015 if (GET_CODE (addr) == PLUS)
2016 return satisfies_constraint_I (offset);
2017
2018 else if (GET_CODE (addr) == LO_SUM)
2019 {
2020 if (TARGET_XCOFF || (TARGET_ELF && TARGET_POWERPC64))
2021 return small_toc_ref (offset, GET_MODE (offset));
2022
2023 else if (TARGET_ELF && !TARGET_POWERPC64)
2024 return CONSTANT_P (offset);
2025 }
2026
2027 return 0;
2028 })
2029
2030 ;; Match a GPR load (lbz, lhz, lwz, ld) that uses a combined address in the
2031 ;; memory field with both the addis and the memory offset. Sign extension
2032 ;; is not handled here, since lha and lwa are not fused.
2033 (define_predicate "fusion_addis_mem_combo_load"
2034 (match_code "mem,zero_extend")
2035 {
2036 rtx addr, base, offset;
2037
2038 /* Handle zero extend. */
2039 if (GET_CODE (op) == ZERO_EXTEND)
2040 {
2041 op = XEXP (op, 0);
2042 mode = GET_MODE (op);
2043 }
2044
2045 if (!MEM_P (op))
2046 return 0;
2047
2048 switch (mode)
2049 {
2050 case E_QImode:
2051 case E_HImode:
2052 case E_SImode:
2053 break;
2054
2055 /* Do not fuse 64-bit DImode in 32-bit since it splits into two
2056 separate instructions. */
2057 case E_DImode:
2058 if (!TARGET_POWERPC64)
2059 return 0;
2060 break;
2061
2062 /* Do not allow SF/DFmode in GPR fusion. While the loads do occur, they
2063 are not common. */
2064 default:
2065 return 0;
2066 }
2067
2068 addr = XEXP (op, 0);
2069 if (GET_CODE (addr) != PLUS && GET_CODE (addr) != LO_SUM)
2070 return 0;
2071
2072 base = XEXP (addr, 0);
2073 if (!fusion_gpr_addis (base, GET_MODE (base)))
2074 return 0;
2075
2076 offset = XEXP (addr, 1);
2077 if (GET_CODE (addr) == PLUS)
2078 return satisfies_constraint_I (offset);
2079
2080 else if (GET_CODE (addr) == LO_SUM)
2081 {
2082 if (TARGET_XCOFF || (TARGET_ELF && TARGET_POWERPC64))
2083 return small_toc_ref (offset, GET_MODE (offset));
2084
2085 else if (TARGET_ELF && !TARGET_POWERPC64)
2086 return CONSTANT_P (offset);
2087 }
2088
2089 return 0;
2090 })
2091
2092
2093 ;; Return true if the operand is a PC-relative address of a local symbol or a
2094 ;; label that can be used directly in a memory operation.
2095 (define_predicate "pcrel_local_address"
2096 (match_code "label_ref,symbol_ref,const")
2097 {
2098 enum insn_form iform = address_to_insn_form (op, mode, NON_PREFIXED_DEFAULT);
2099 return iform == INSN_FORM_PCREL_LOCAL;
2100 })
2101
2102 ;; Return true if the operand is a PC-relative external symbol whose address
2103 ;; can be loaded into a register.
2104 (define_predicate "pcrel_external_address"
2105 (match_code "symbol_ref,const")
2106 {
2107 enum insn_form iform = address_to_insn_form (op, mode, NON_PREFIXED_DEFAULT);
2108 return iform == INSN_FORM_PCREL_EXTERNAL;
2109 })
2110
2111 ;; Return true if the address is PC-relative and the symbol is either local or
2112 ;; external.
2113 (define_predicate "pcrel_local_or_external_address"
2114 (ior (match_operand 0 "pcrel_local_address")
2115 (match_operand 0 "pcrel_external_address")))
2116
2117 ;; Return true if the operand is a memory address that uses a prefixed address.
2118 (define_predicate "prefixed_memory"
2119 (match_code "mem")
2120 {
2121 return address_is_prefixed (XEXP (op, 0), mode, NON_PREFIXED_DEFAULT);
2122 })
2123
2124 ;; Return true if the operand is a valid memory operand with a D-form
2125 ;; address that could be merged with the load of a PC-relative external address
2126 ;; with the PCREL_OPT optimization. We don't check here whether or not the
2127 ;; offset needs to be used in a DS-FORM (bottom 2 bits 0) or DQ-FORM (bottom 4
2128 ;; bits 0) instruction.
2129 (define_predicate "d_form_memory"
2130 (match_code "mem")
2131 {
2132 if (!memory_operand (op, mode))
2133 return false;
2134
2135 rtx addr = XEXP (op, 0);
2136
2137 if (REG_P (addr))
2138 return true;
2139 if (SUBREG_P (addr) && REG_P (SUBREG_REG (addr)))
2140 return true;
2141
2142 return !indexed_address (addr, mode);
2143 })
2144
2145 ;; Return 1 if this operand is valid as the index for vec_set.
2146 (define_predicate "vec_set_index_operand"
2147 (if_then_else (match_test "TARGET_VSX")
2148 (match_operand 0 "reg_or_cint_operand")
2149 (match_operand 0 "const_int_operand")))
2150
2151 ;; Return true if the operand is a valid Mach-O pic address.
2152 ;;
2153 (define_predicate "macho_pic_address"
2154 (match_code "const,unspec")
2155 {
2156 if (GET_CODE (op) == CONST)
2157 op = XEXP (op, 0);
2158
2159 if (GET_CODE (op) == UNSPEC && XINT (op, 1) == UNSPEC_MACHOPIC_OFFSET)
2160 return CONSTANT_P (XVECEXP (op, 0, 0));
2161 else
2162 return false;
2163 })
2164
2165 (define_predicate "lowpart_subreg_operator"
2166 (and (match_code "subreg")
2167 (match_test "subreg_lowpart_offset (mode, GET_MODE (SUBREG_REG (op)))
2168 == SUBREG_BYTE (op)")))