* gimplify.c (nonlocal_vlas): Delete.
[official-gcc.git] / gcc / config / rs6000 / predicates.md
blob018b5f95f6bf424312380dcf84246b6bfc9cd55a
1 ;; Predicate definitions for POWER and PowerPC.
2 ;; Copyright (C) 2005-2018 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.
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.
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/>.
20 ;; Return 1 for anything except PARALLEL.
21 (define_predicate "any_operand"
22   (match_code "const_int,const_double,const_wide_int,const,symbol_ref,label_ref,subreg,reg,mem"))
24 ;; Return 1 for any PARALLEL.
25 (define_predicate "any_parallel_operand"
26   (match_code "parallel"))
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")))
34 ;; Return 1 if op is a SUBREG that is used to look at a SFmode value as
35 ;; and integer or vice versa.
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.
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")
47   rtx inner_reg = SUBREG_REG (op);
48   machine_mode inner_mode = GET_MODE (inner_reg);
50   if (TARGET_ALLOW_SF_SUBREG || !REG_P (inner_reg))
51     return 0;
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;
59       return 1;
60     }
61   return 0;
64 ;; Return 1 if op is an Altivec register.
65 (define_predicate "altivec_register_operand"
66   (match_operand 0 "register_operand")
68   if (GET_CODE (op) == SUBREG)
69     {
70       if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
71         return 0;
73       op = SUBREG_REG (op);
74     }
76   if (!REG_P (op))
77     return 0;
79   if (REGNO (op) >= FIRST_PSEUDO_REGISTER)
80     return 1;
82   return ALTIVEC_REGNO_P (REGNO (op));
85 ;; Return 1 if op is a VSX register.
86 (define_predicate "vsx_register_operand"
87   (match_operand 0 "register_operand")
89   if (GET_CODE (op) == SUBREG)
90     {
91       if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
92         return 0;
94       op = SUBREG_REG (op);
95     }
97   if (!REG_P (op))
98     return 0;
100   if (REGNO (op) >= FIRST_PSEUDO_REGISTER)
101     return 1;
103   return VSX_REGNO_P (REGNO (op));
106 ;; Like vsx_register_operand, but allow SF SUBREGS
107 (define_predicate "vsx_reg_sfsubreg_ok"
108   (match_operand 0 "register_operand")
110   if (GET_CODE (op) == SUBREG)
111     op = SUBREG_REG (op);
113   if (!REG_P (op))
114     return 0;
116   if (REGNO (op) >= FIRST_PSEUDO_REGISTER)
117     return 1;
119   return VSX_REGNO_P (REGNO (op));
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")
127   if (GET_CODE (op) == SUBREG)
128     {
129       if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
130         return 0;
132       op = SUBREG_REG (op);
133     }
135   if (!REG_P (op))
136     return 0;
138   if (REGNO (op) >= FIRST_PSEUDO_REGISTER)
139     return 1;
141   return VFLOAT_REGNO_P (REGNO (op));
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")
149   if (GET_CODE (op) == SUBREG)
150     {
151       if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
152         return 0;
154       op = SUBREG_REG (op);
155     }
157   if (!REG_P (op))
158     return 0;
160   if (REGNO (op) >= FIRST_PSEUDO_REGISTER)
161     return 1;
163   return VINT_REGNO_P (REGNO (op));
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")
171   if (GET_CODE (op) == SUBREG)
172     {
173       if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
174         return 0;
176       op = SUBREG_REG (op);
177     }
180   if (!REG_P (op))
181     return 0;
183   if (REGNO (op) >= FIRST_PSEUDO_REGISTER)
184     return 1;
186   return VLOGICAL_REGNO_P (REGNO (op));
189 ;; Return 1 if op is the carry register.
190 (define_predicate "ca_operand"
191   (match_operand 0 "register_operand")
193   if (GET_CODE (op) == SUBREG)
194     op = SUBREG_REG (op);
196   if (!REG_P (op))
197     return 0;
199   return CA_REGNO_P (REGNO (op));
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)")))
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)")))
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")))
217 ;; Return 1 if op is a unsigned 3-bit constant integer.
218 (define_predicate "u3bit_cint_operand"
219   (and (match_code "const_int")
220        (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 7")))
222 ;; Return 1 if op is a unsigned 5-bit constant integer.
223 (define_predicate "u5bit_cint_operand"
224   (and (match_code "const_int")
225        (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 31")))
227 ;; Return 1 if op is a unsigned 6-bit constant integer.
228 (define_predicate "u6bit_cint_operand"
229   (and (match_code "const_int")
230        (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 63")))
232 ;; Return 1 if op is an unsigned 7-bit constant integer.
233 (define_predicate "u7bit_cint_operand"
234   (and (match_code "const_int")
235        (match_test "IN_RANGE (INTVAL (op), 0, 127)")))
237 ;; Return 1 if op is a signed 8-bit constant integer.
238 ;; Integer multiplication complete more quickly
239 (define_predicate "s8bit_cint_operand"
240   (and (match_code "const_int")
241        (match_test "INTVAL (op) >= -128 && INTVAL (op) <= 127")))
243 ;; Return 1 if op is a unsigned 10-bit constant integer.
244 (define_predicate "u10bit_cint_operand"
245   (and (match_code "const_int")
246        (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 1023")))
248 ;; Return 1 if op is a constant integer that can fit in a D field.
249 (define_predicate "short_cint_operand"
250   (and (match_code "const_int")
251        (match_test "satisfies_constraint_I (op)")))
253 ;; Return 1 if op is a constant integer that can fit in an unsigned D field.
254 (define_predicate "u_short_cint_operand"
255   (and (match_code "const_int")
256        (match_test "satisfies_constraint_K (op)")))
258 ;; Return 1 if op is a constant integer that is a signed 16-bit constant
259 ;; shifted left 16 bits
260 (define_predicate "upper16_cint_operand"
261   (and (match_code "const_int")
262        (match_test "satisfies_constraint_L (op)")))
264 ;; Return 1 if op is a constant integer that cannot fit in a signed D field.
265 (define_predicate "non_short_cint_operand"
266   (and (match_code "const_int")
267        (match_test "(unsigned HOST_WIDE_INT)
268                     (INTVAL (op) + 0x8000) >= 0x10000")))
270 ;; Return 1 if op is a positive constant integer that is an exact power of 2.
271 (define_predicate "exact_log2_cint_operand"
272   (and (match_code "const_int")
273        (match_test "INTVAL (op) > 0 && exact_log2 (INTVAL (op)) >= 0")))
275 ;; Match op = 0 or op = 1.
276 (define_predicate "const_0_to_1_operand"
277   (and (match_code "const_int")
278        (match_test "IN_RANGE (INTVAL (op), 0, 1)")))
280 ;; Match op = 0..3.
281 (define_predicate "const_0_to_3_operand"
282   (and (match_code "const_int")
283        (match_test "IN_RANGE (INTVAL (op), 0, 3)")))
285 ;; Match op = 2 or op = 3.
286 (define_predicate "const_2_to_3_operand"
287   (and (match_code "const_int")
288        (match_test "IN_RANGE (INTVAL (op), 2, 3)")))
290 ;; Match op = 0..7.
291 (define_predicate "const_0_to_7_operand"
292   (and (match_code "const_int")
293        (match_test "IN_RANGE (INTVAL (op), 0, 7)")))
295 ;; Match op = 0..11
296 (define_predicate "const_0_to_12_operand"
297   (and (match_code "const_int")
298        (match_test "IN_RANGE (INTVAL (op), 0, 12)")))
300 ;; Match op = 0..15
301 (define_predicate "const_0_to_15_operand"
302   (and (match_code "const_int")
303        (match_test "IN_RANGE (INTVAL (op), 0, 15)")))
305 ;; Return 1 if op is a register that is not special.
306 ;; Disallow (SUBREG:SF (REG:SI)) and (SUBREG:SI (REG:SF)) on VSX systems where
307 ;; you need to be careful in moving a SFmode to SImode and vice versa due to
308 ;; the fact that SFmode is represented as DFmode in the VSX registers.
309 (define_predicate "gpc_reg_operand"
310   (match_operand 0 "register_operand")
312   if (GET_CODE (op) == SUBREG)
313     {
314       if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
315         return 0;
317       op = SUBREG_REG (op);
318     }
320   if (!REG_P (op))
321     return 0;
323   if (REGNO (op) >= FIRST_PSEUDO_REGISTER)
324     return 1;
326   if (TARGET_ALTIVEC && ALTIVEC_REGNO_P (REGNO (op)))
327     return 1;
329   if (TARGET_VSX && VSX_REGNO_P (REGNO (op)))
330     return 1;
332   return INT_REGNO_P (REGNO (op)) || FP_REGNO_P (REGNO (op));
335 ;; Return 1 if op is a general purpose register.  Unlike gpc_reg_operand, don't
336 ;; allow floating point or vector registers.  Since vector registers are not
337 ;; allowed, we don't have to reject SFmode/SImode subregs.
338 (define_predicate "int_reg_operand"
339   (match_operand 0 "register_operand")
341   if (GET_CODE (op) == SUBREG)
342     {
343       if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
344         return 0;
346       op = SUBREG_REG (op);
347     }
349   if (!REG_P (op))
350     return 0;
352   if (REGNO (op) >= FIRST_PSEUDO_REGISTER)
353     return 1;
355   return INT_REGNO_P (REGNO (op));
358 ;; Like int_reg_operand, but don't return true for pseudo registers
359 ;; We don't have to check for SF SUBREGS because pseudo registers
360 ;; are not allowed, and SF SUBREGs are ok within GPR registers.
361 (define_predicate "int_reg_operand_not_pseudo"
362   (match_operand 0 "register_operand")
364   if (GET_CODE (op) == SUBREG)
365     op = SUBREG_REG (op);
367   if (!REG_P (op))
368     return 0;
370   if (REGNO (op) >= FIRST_PSEUDO_REGISTER)
371     return 0;
373   return INT_REGNO_P (REGNO (op));
376 ;; Like int_reg_operand, but only return true for base registers
377 (define_predicate "base_reg_operand"
378   (match_operand 0 "int_reg_operand")
380   if (GET_CODE (op) == SUBREG)
381     op = SUBREG_REG (op);
383   if (!REG_P (op))
384     return 0;
386   return (REGNO (op) != FIRST_GPR_REGNO);
390 ;; Return true if this is a traditional floating point register
391 (define_predicate "fpr_reg_operand"
392   (match_code "reg,subreg")
394   HOST_WIDE_INT r;
396   if (GET_CODE (op) == SUBREG)
397     op = SUBREG_REG (op);
399   if (!REG_P (op))
400     return 0;
402   r = REGNO (op);
403   if (r >= FIRST_PSEUDO_REGISTER)
404     return 1;
406   return FP_REGNO_P (r);
409 ;; Return true if this is a register that can has D-form addressing (GPR and
410 ;; traditional FPR registers for scalars).  ISA 3.0 (power9) adds D-form
411 ;; addressing for scalars in Altivec registers.
413 ;; If this is a pseudo only allow for GPR fusion in power8.  If we have the
414 ;; power9 fusion allow the floating point types.
415 (define_predicate "toc_fusion_or_p9_reg_operand"
416   (match_code "reg,subreg")
418   HOST_WIDE_INT r;
419   bool gpr_p = (mode == QImode || mode == HImode || mode == SImode
420                 || mode == SFmode
421                 || (TARGET_POWERPC64 && (mode == DImode || mode == DFmode)));
422   bool fpr_p = (TARGET_P9_FUSION
423                 && (mode == DFmode || mode == SFmode
424                     || (TARGET_POWERPC64 && mode == DImode)));
425   bool vmx_p = (TARGET_P9_FUSION && TARGET_P9_VECTOR
426                 && (mode == DFmode || mode == SFmode));
428   if (!TARGET_P8_FUSION)
429     return 0;
431   if (GET_CODE (op) == SUBREG)
432     op = SUBREG_REG (op);
434   if (!REG_P (op))
435     return 0;
437   r = REGNO (op);
438   if (r >= FIRST_PSEUDO_REGISTER)
439     return (gpr_p || fpr_p || vmx_p);
441   if (INT_REGNO_P (r))
442     return gpr_p;
444   if (FP_REGNO_P (r))
445     return fpr_p;
447   if (ALTIVEC_REGNO_P (r))
448     return vmx_p;
450   return 0;
453 ;; Return 1 if op is a HTM specific SPR register.
454 (define_predicate "htm_spr_reg_operand"
455   (match_operand 0 "register_operand")
457   if (!TARGET_HTM)
458     return 0;
460   if (GET_CODE (op) == SUBREG)
461     op = SUBREG_REG (op);
463   if (!REG_P (op))
464     return 0;
466   switch (REGNO (op))
467     {
468       case TFHAR_REGNO:
469       case TFIAR_REGNO:
470       case TEXASR_REGNO:
471         return 1;
472       default:
473         break;
474     }
475   
476   /* Unknown SPR.  */
477   return 0;
480 ;; Return 1 if op is a general purpose register that is an even register
481 ;; which suitable for a load/store quad operation
482 ;; Subregs are not allowed here because when they are combine can
483 ;; create (subreg:PTI (reg:TI pseudo)) which will cause reload to
484 ;; think the innermost reg needs reloading, in TImode instead of
485 ;; PTImode.  So reload will choose a reg in TImode which has no
486 ;; requirement that the reg be even.
487 (define_predicate "quad_int_reg_operand"
488   (match_code "reg")
490   HOST_WIDE_INT r;
492   if (!TARGET_QUAD_MEMORY && !TARGET_QUAD_MEMORY_ATOMIC)
493     return 0;
495   r = REGNO (op);
496   if (r >= FIRST_PSEUDO_REGISTER)
497     return 1;
499   return (INT_REGNO_P (r) && ((r & 1) == 0));
502 ;; Return 1 if op is a register that is a condition register field.
503 (define_predicate "cc_reg_operand"
504   (match_operand 0 "register_operand")
506   if (GET_CODE (op) == SUBREG)
507     op = SUBREG_REG (op);
509   if (!REG_P (op))
510     return 0;
512   if (REGNO (op) > LAST_VIRTUAL_REGISTER)
513     return 1;
515   return CR_REGNO_P (REGNO (op));
518 ;; Return 1 if op is a register that is a condition register field not cr0.
519 (define_predicate "cc_reg_not_cr0_operand"
520   (match_operand 0 "register_operand")
522   if (GET_CODE (op) == SUBREG)
523     op = SUBREG_REG (op);
525   if (!REG_P (op))
526     return 0;
528   if (REGNO (op) > LAST_VIRTUAL_REGISTER)
529     return 1;
531   return CR_REGNO_NOT_CR0_P (REGNO (op));
534 ;; Return 1 if op is a constant integer valid for D field
535 ;; or non-special register register.
536 (define_predicate "reg_or_short_operand"
537   (if_then_else (match_code "const_int")
538     (match_operand 0 "short_cint_operand")
539     (match_operand 0 "gpc_reg_operand")))
541 ;; Return 1 if op is a constant integer valid for DS field
542 ;; or non-special register.
543 (define_predicate "reg_or_aligned_short_operand"
544   (if_then_else (match_code "const_int")
545     (and (match_operand 0 "short_cint_operand")
546          (match_test "!(INTVAL (op) & 3)"))
547     (match_operand 0 "gpc_reg_operand")))
549 ;; Return 1 if op is a constant integer whose high-order 16 bits are zero
550 ;; or non-special register.
551 (define_predicate "reg_or_u_short_operand"
552   (if_then_else (match_code "const_int")
553     (match_operand 0 "u_short_cint_operand")
554     (match_operand 0 "gpc_reg_operand")))
556 ;; Return 1 if op is any constant integer or a non-special register.
557 (define_predicate "reg_or_cint_operand"
558   (ior (match_code "const_int")
559        (match_operand 0 "gpc_reg_operand")))
561 ;; Return 1 if op is constant zero or a non-special register.
562 (define_predicate "reg_or_zero_operand"
563   (ior (match_operand 0 "zero_constant")
564        (match_operand 0 "gpc_reg_operand")))
566 ;; Return 1 if op is a constant integer valid for addition with addis, addi.
567 (define_predicate "add_cint_operand"
568   (and (match_code "const_int")
569        (match_test "((unsigned HOST_WIDE_INT) INTVAL (op)
570                        + (mode == SImode ? 0x80000000 : 0x80008000))
571                     < (unsigned HOST_WIDE_INT) 0x100000000ll")))
573 ;; Return 1 if op is a constant integer valid for addition
574 ;; or non-special register.
575 (define_predicate "reg_or_add_cint_operand"
576   (if_then_else (match_code "const_int")
577     (match_operand 0 "add_cint_operand")
578     (match_operand 0 "gpc_reg_operand")))
580 ;; Return 1 if op is a constant integer valid for subtraction
581 ;; or non-special register.
582 (define_predicate "reg_or_sub_cint_operand"
583   (if_then_else (match_code "const_int")
584     (match_test "(unsigned HOST_WIDE_INT)
585                    (- UINTVAL (op) + (mode == SImode ? 0x80000000 : 0x80008000))
586                  < (unsigned HOST_WIDE_INT) 0x100000000ll")
587     (match_operand 0 "gpc_reg_operand")))
589 ;; Return 1 if op is any 32-bit unsigned constant integer
590 ;; or non-special register.
591 (define_predicate "reg_or_logical_cint_operand"
592   (if_then_else (match_code "const_int")
593     (match_test "(GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT
594                   && INTVAL (op) >= 0)
595                  || ((INTVAL (op) & GET_MODE_MASK (mode)
596                       & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0)")
597     (match_operand 0 "gpc_reg_operand")))
599 ;; Like reg_or_logical_cint_operand, but allow vsx registers
600 (define_predicate "vsx_reg_or_cint_operand"
601   (ior (match_operand 0 "vsx_register_operand")
602        (match_operand 0 "reg_or_logical_cint_operand")))
604 ;; Return 1 if operand is a CONST_DOUBLE that can be set in a register
605 ;; with no more than one instruction per word.
606 (define_predicate "easy_fp_constant"
607   (match_code "const_double")
609   if (GET_MODE (op) != mode
610       || (!SCALAR_FLOAT_MODE_P (mode) && mode != DImode))
611     return 0;
613   /* Consider all constants with -msoft-float to be easy.  */
614   if (TARGET_SOFT_FLOAT && mode != DImode)
615     return 1;
617   /* 0.0D is not all zero bits.  */
618   if (DECIMAL_FLOAT_MODE_P (mode))
619     return 0;
621   /* The constant 0.0 is easy under VSX.  */
622   if (TARGET_VSX && SCALAR_FLOAT_MODE_P (mode) && op == CONST0_RTX (mode))
623     return 1;
625   /* If we are using V.4 style PIC, consider all constants to be hard.  */
626   if (flag_pic && DEFAULT_ABI == ABI_V4)
627     return 0;
629   /* If we have real FPRs, consider floating point constants hard (other than
630      0.0 under VSX), so that the constant gets pushed to memory during the
631      early RTL phases.  This has the advantage that double precision constants
632      that can be represented in single precision without a loss of precision
633      will use single precision loads.  */
635   switch (mode)
636     {
637     case E_KFmode:
638     case E_IFmode:
639     case E_TFmode:
640     case E_DFmode:
641     case E_SFmode:
642       return 0;
644     case E_DImode:
645       return (num_insns_constant (op, DImode) <= 2);
647     case E_SImode:
648       return 1;
650     default:
651       gcc_unreachable ();
652     }
655 ;; Return 1 if the operand is a constant that can loaded with a XXSPLTIB
656 ;; instruction and then a VUPKHSB, VECSB2W or VECSB2D instruction.
658 (define_predicate "xxspltib_constant_split"
659   (match_code "const_vector,vec_duplicate,const_int")
661   int value = 256;
662   int num_insns = -1;
664   if (!xxspltib_constant_p (op, mode, &num_insns, &value))
665     return false;
667   return num_insns > 1;
671 ;; Return 1 if the operand is constant that can loaded directly with a XXSPLTIB
672 ;; instruction.
674 (define_predicate "xxspltib_constant_nosplit"
675   (match_code "const_vector,vec_duplicate,const_int")
677   int value = 256;
678   int num_insns = -1;
680   if (!xxspltib_constant_p (op, mode, &num_insns, &value))
681     return false;
683   return num_insns == 1;
686 ;; Return 1 if the operand is a CONST_VECTOR and can be loaded into a
687 ;; vector register without using memory.
688 (define_predicate "easy_vector_constant"
689   (match_code "const_vector")
691   /* Because IEEE 128-bit floating point is considered a vector type
692      in order to pass it in VSX registers, it might use this function
693      instead of easy_fp_constant.  */
694   if (FLOAT128_VECTOR_P (mode))
695     return easy_fp_constant (op, mode);
697   if (VECTOR_MEM_ALTIVEC_OR_VSX_P (mode))
698     {
699       int value = 256;
700       int num_insns = -1;
702       if (zero_constant (op, mode) || all_ones_constant (op, mode))
703         return true;
705       if (TARGET_P9_VECTOR
706           && xxspltib_constant_p (op, mode, &num_insns, &value))
707         return true;
709       return easy_altivec_constant (op, mode);
710     }
712   return false;
715 ;; Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF.
716 (define_predicate "easy_vector_constant_add_self"
717   (and (match_code "const_vector")
718        (and (match_test "TARGET_ALTIVEC")
719             (match_test "easy_altivec_constant (op, mode)")))
721   HOST_WIDE_INT val;
722   int elt;
723   if (mode == V2DImode || mode == V2DFmode)
724     return 0;
725   elt = BYTES_BIG_ENDIAN ? GET_MODE_NUNITS (mode) - 1 : 0;
726   val = const_vector_elt_as_int (op, elt);
727   val = ((val & 0xff) ^ 0x80) - 0x80;
728   return EASY_VECTOR_15_ADD_SELF (val);
731 ;; Same as easy_vector_constant but only for EASY_VECTOR_MSB.
732 (define_predicate "easy_vector_constant_msb"
733   (and (match_code "const_vector")
734        (and (match_test "TARGET_ALTIVEC")
735             (match_test "easy_altivec_constant (op, mode)")))
737   HOST_WIDE_INT val;
738   int elt;
739   if (mode == V2DImode || mode == V2DFmode)
740     return 0;
741   elt = BYTES_BIG_ENDIAN ? GET_MODE_NUNITS (mode) - 1 : 0;
742   val = const_vector_elt_as_int (op, elt);
743   return EASY_VECTOR_MSB (val, GET_MODE_INNER (mode));
746 ;; Return true if this is an easy altivec constant that we form
747 ;; by using VSLDOI.
748 (define_predicate "easy_vector_constant_vsldoi"
749   (and (match_code "const_vector")
750        (and (match_test "TARGET_ALTIVEC")
751             (and (match_test "easy_altivec_constant (op, mode)")
752                  (match_test "vspltis_shifted (op) != 0")))))
754 ;; Return 1 if operand is a vector int register or is either a vector constant
755 ;; of all 0 bits of a vector constant of all 1 bits.
756 (define_predicate "vector_int_reg_or_same_bit"
757   (match_code "reg,subreg,const_vector")
759   if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
760     return 0;
762   else if (REG_P (op) || SUBREG_P (op))
763     return vint_operand (op, mode);
765   else
766     return op == CONST0_RTX (mode) || op == CONSTM1_RTX (mode);
769 ;; Return 1 if operand is 0.0.
770 (define_predicate "zero_fp_constant"
771   (and (match_code "const_double")
772        (match_test "SCALAR_FLOAT_MODE_P (mode)
773                     && op == CONST0_RTX (mode)")))
775 ;; Return 1 if the operand is in volatile memory.  Note that during the
776 ;; RTL generation phase, memory_operand does not return TRUE for volatile
777 ;; memory references.  So this function allows us to recognize volatile
778 ;; references where it's safe.
779 (define_predicate "volatile_mem_operand"
780   (and (and (match_code "mem")
781             (match_test "MEM_VOLATILE_P (op)"))
782        (if_then_else (match_test "reload_completed")
783          (match_operand 0 "memory_operand")
784          (match_test "memory_address_p (mode, XEXP (op, 0))"))))
786 ;; Return 1 if the operand is an offsettable memory operand.
787 (define_predicate "offsettable_mem_operand"
788   (and (match_operand 0 "memory_operand")
789        (match_test "offsettable_nonstrict_memref_p (op)")))
791 ;; Return 1 if the operand is a simple offsettable memory operand
792 ;; that does not include pre-increment, post-increment, etc.
793 (define_predicate "simple_offsettable_mem_operand"
794   (match_operand 0 "offsettable_mem_operand")
796   rtx addr = XEXP (op, 0);
798   if (GET_CODE (addr) != PLUS && GET_CODE (addr) != LO_SUM)
799     return 0;
801   if (!CONSTANT_P (XEXP (addr, 1)))
802     return 0;
804   return base_reg_operand (XEXP (addr, 0), Pmode);
807 ;; Return 1 if the operand is suitable for load/store quad memory.
808 ;; This predicate only checks for non-atomic loads/stores (not lqarx/stqcx).
809 (define_predicate "quad_memory_operand"
810   (match_code "mem")
812   if (!TARGET_QUAD_MEMORY && !TARGET_SYNC_TI)
813     return false;
815   if (GET_MODE_SIZE (mode) != 16 || !MEM_P (op) || MEM_ALIGN (op) < 128)
816     return false;
818   return quad_address_p (XEXP (op, 0), mode, false);
821 ;; Return 1 if the operand is suitable for load/store to vector registers with
822 ;; d-form addressing (register+offset), which was added in ISA 3.0.
823 ;; Unlike quad_memory_operand, we do not have to check for alignment.
824 (define_predicate "vsx_quad_dform_memory_operand"
825   (match_code "mem")
827   if (!TARGET_P9_VECTOR || !MEM_P (op) || GET_MODE_SIZE (mode) != 16)
828     return false;
830   return quad_address_p (XEXP (op, 0), mode, false);
833 ;; Return 1 if the operand is an indexed or indirect memory operand.
834 (define_predicate "indexed_or_indirect_operand"
835   (match_code "mem")
837   op = XEXP (op, 0);
838   if (VECTOR_MEM_ALTIVEC_P (mode)
839       && GET_CODE (op) == AND
840       && GET_CODE (XEXP (op, 1)) == CONST_INT
841       && INTVAL (XEXP (op, 1)) == -16)
842     op = XEXP (op, 0);
844   return indexed_or_indirect_address (op, mode);
847 ;; Like indexed_or_indirect_operand, but also allow a GPR register if direct
848 ;; moves are supported.
849 (define_predicate "reg_or_indexed_operand"
850   (match_code "mem,reg,subreg")
852   if (MEM_P (op))
853     return indexed_or_indirect_operand (op, mode);
854   else if (TARGET_DIRECT_MOVE)
855     return register_operand (op, mode);
856   return
857     0;
860 ;; Return 1 if the operand is an indexed or indirect memory operand with an
861 ;; AND -16 in it, used to recognize when we need to switch to Altivec loads
862 ;; to realign loops instead of VSX (altivec silently ignores the bottom bits,
863 ;; while VSX uses the full address and traps)
864 (define_predicate "altivec_indexed_or_indirect_operand"
865   (match_code "mem")
867   op = XEXP (op, 0);
868   if (VECTOR_MEM_ALTIVEC_OR_VSX_P (mode)
869       && GET_CODE (op) == AND
870       && GET_CODE (XEXP (op, 1)) == CONST_INT
871       && INTVAL (XEXP (op, 1)) == -16)
872     return indexed_or_indirect_address (XEXP (op, 0), mode);
874   return 0;
877 ;; Return 1 if the operand is an indexed or indirect address.
878 (define_special_predicate "indexed_or_indirect_address"
879   (and (match_test "REG_P (op)
880                     || (GET_CODE (op) == PLUS
881                         /* Omit testing REG_P (XEXP (op, 0)).  */
882                         && REG_P (XEXP (op, 1)))")
883        (match_operand 0 "address_operand")))
885 ;; Return 1 if the operand is an index-form address.
886 (define_special_predicate "indexed_address"
887   (match_test "(GET_CODE (op) == PLUS
888                 && REG_P (XEXP (op, 0))
889                 && REG_P (XEXP (op, 1)))"))
891 ;; Return 1 if the operand is a MEM with an update-form address. This may
892 ;; also include update-indexed form.
893 (define_special_predicate "update_address_mem"
894   (match_test "(MEM_P (op)
895                 && (GET_CODE (XEXP (op, 0)) == PRE_INC
896                     || GET_CODE (XEXP (op, 0)) == PRE_DEC
897                     || GET_CODE (XEXP (op, 0)) == PRE_MODIFY))"))
899 ;; Return 1 if the operand is a MEM with an indexed-form address.
900 (define_special_predicate "indexed_address_mem"
901   (match_test "(MEM_P (op)
902                 && (indexed_address (XEXP (op, 0), mode)
903                     || (GET_CODE (XEXP (op, 0)) == PRE_MODIFY
904                         && indexed_address (XEXP (XEXP (op, 0), 1), mode))))"))
906 ;; Return 1 if the operand is either a non-special register or can be used
907 ;; as the operand of a `mode' add insn.
908 (define_predicate "add_operand"
909   (if_then_else (match_code "const_int")
910     (match_test "satisfies_constraint_I (op)
911                  || satisfies_constraint_L (op)")
912     (match_operand 0 "gpc_reg_operand")))
914 ;; Return 1 if the operand is either a non-special register, or 0, or -1.
915 (define_predicate "adde_operand"
916   (if_then_else (match_code "const_int")
917     (match_test "INTVAL (op) == 0 || INTVAL (op) == -1")
918     (match_operand 0 "gpc_reg_operand")))
920 ;; Return 1 if OP is a constant but not a valid add_operand.
921 (define_predicate "non_add_cint_operand"
922   (and (match_code "const_int")
923        (match_test "!satisfies_constraint_I (op)
924                     && !satisfies_constraint_L (op)")))
926 ;; Return 1 if the operand is a constant that can be used as the operand
927 ;; of an OR or XOR.
928 (define_predicate "logical_const_operand"
929   (match_code "const_int")
931   HOST_WIDE_INT opl;
933   opl = INTVAL (op) & GET_MODE_MASK (mode);
935   return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
936           || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
939 ;; Return 1 if the operand is a non-special register or a constant that
940 ;; can be used as the operand of an OR or XOR.
941 (define_predicate "logical_operand"
942   (ior (match_operand 0 "gpc_reg_operand")
943        (match_operand 0 "logical_const_operand")))
945 ;; Return 1 if op is a constant that is not a logical operand, but could
946 ;; be split into one.
947 (define_predicate "non_logical_cint_operand"
948   (and (match_code "const_int,const_wide_int")
949        (and (not (match_operand 0 "logical_operand"))
950             (match_operand 0 "reg_or_logical_cint_operand"))))
952 ;; Return 1 if the operand is either a non-special register or a
953 ;; constant that can be used as the operand of a logical AND.
954 (define_predicate "and_operand"
955   (ior (and (match_code "const_int")
956             (match_test "rs6000_is_valid_and_mask (op, mode)"))
957        (if_then_else (match_test "fixed_regs[CR0_REGNO]")
958          (match_operand 0 "gpc_reg_operand")
959          (match_operand 0 "logical_operand"))))
961 ;; Return 1 if the operand is either a logical operand or a short cint operand.
962 (define_predicate "scc_eq_operand"
963   (ior (match_operand 0 "logical_operand")
964        (match_operand 0 "short_cint_operand")))
966 ;; Return 1 if the operand is a general non-special register or memory operand.
967 (define_predicate "reg_or_mem_operand"
968   (ior (match_operand 0 "memory_operand")
969        (and (match_code "mem")
970             (match_test "macho_lo_sum_memory_operand (op, mode)"))
971        (match_operand 0 "volatile_mem_operand")
972        (match_operand 0 "gpc_reg_operand")))
974 ;; Return 1 if the operand is CONST_DOUBLE 0, register or memory operand.
975 (define_predicate "zero_reg_mem_operand"
976   (ior (and (match_test "TARGET_VSX")
977             (match_operand 0 "zero_fp_constant"))
978        (match_operand 0 "reg_or_mem_operand")))
980 ;; Return 1 if the operand is a CONST_INT and it is the element for 64-bit
981 ;; data types inside of a vector that scalar instructions operate on
982 (define_predicate "vsx_scalar_64bit"
983   (match_code "const_int")
985   return (INTVAL (op) == VECTOR_ELEMENT_SCALAR_64BIT);
988 ;; Return 1 if the operand is a general register or memory operand without
989 ;; pre_inc or pre_dec or pre_modify, which produces invalid form of PowerPC
990 ;; lwa instruction.
991 (define_predicate "lwa_operand"
992   (match_code "reg,subreg,mem")
994   rtx inner, addr, offset;
996   inner = op;
997   if (reload_completed && GET_CODE (inner) == SUBREG)
998     inner = SUBREG_REG (inner);
1000   if (gpc_reg_operand (inner, mode))
1001     return true;
1002   if (!memory_operand (inner, mode))
1003     return false;
1005   addr = XEXP (inner, 0);
1006   if (GET_CODE (addr) == PRE_INC
1007       || GET_CODE (addr) == PRE_DEC
1008       || (GET_CODE (addr) == PRE_MODIFY
1009           && !legitimate_indexed_address_p (XEXP (addr, 1), 0)))
1010     return false;
1011   if (GET_CODE (addr) == LO_SUM
1012       && GET_CODE (XEXP (addr, 0)) == REG
1013       && GET_CODE (XEXP (addr, 1)) == CONST)
1014     addr = XEXP (XEXP (addr, 1), 0);
1015   if (GET_CODE (addr) != PLUS)
1016     return true;
1017   offset = XEXP (addr, 1);
1018   if (GET_CODE (offset) != CONST_INT)
1019     return true;
1020   return INTVAL (offset) % 4 == 0;
1023 ;; Return 1 if the operand, used inside a MEM, is a SYMBOL_REF.
1024 (define_predicate "symbol_ref_operand"
1025   (and (match_code "symbol_ref")
1026        (match_test "(mode == VOIDmode || GET_MODE (op) == mode)
1027                     && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))")))
1029 ;; Return 1 if op is an operand that can be loaded via the GOT.
1030 ;; or non-special register register field no cr0
1031 (define_predicate "got_operand"
1032   (match_code "symbol_ref,const,label_ref"))
1034 ;; Return 1 if op is a simple reference that can be loaded via the GOT,
1035 ;; excluding labels involving addition.
1036 (define_predicate "got_no_const_operand"
1037   (match_code "symbol_ref,label_ref"))
1039 ;; Return 1 if op is a SYMBOL_REF for a TLS symbol.
1040 (define_predicate "rs6000_tls_symbol_ref"
1041   (and (match_code "symbol_ref")
1042        (match_test "RS6000_SYMBOL_REF_TLS_P (op)")))
1044 ;; Return 1 if the operand, used inside a MEM, is a valid first argument
1045 ;; to CALL.  This is a SYMBOL_REF, a pseudo-register, LR or CTR.
1046 (define_predicate "call_operand"
1047   (if_then_else (match_code "reg")
1048      (match_test "REGNO (op) == LR_REGNO
1049                   || REGNO (op) == CTR_REGNO
1050                   || REGNO (op) >= FIRST_PSEUDO_REGISTER")
1051      (match_code "symbol_ref")))
1053 ;; Return 1 if the operand is a SYMBOL_REF for a function known to be in
1054 ;; this file.
1055 (define_predicate "current_file_function_operand"
1056   (and (match_code "symbol_ref")
1057        (match_test "(DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
1058                     && (SYMBOL_REF_LOCAL_P (op)
1059                         || (op == XEXP (DECL_RTL (current_function_decl), 0)
1060                             && !decl_replaceable_p (current_function_decl)))
1061                     && !((DEFAULT_ABI == ABI_AIX
1062                           || DEFAULT_ABI == ABI_ELFv2)
1063                          && (SYMBOL_REF_EXTERNAL_P (op)
1064                              || SYMBOL_REF_WEAK (op)))")))
1066 ;; Return 1 if this operand is a valid input for a move insn.
1067 (define_predicate "input_operand"
1068   (match_code "symbol_ref,const,reg,subreg,mem,
1069                const_double,const_wide_int,const_vector,const_int")
1071   /* Memory is always valid.  */
1072   if (memory_operand (op, mode))
1073     return 1;
1075   /* For floating-point, easy constants are valid.  */
1076   if (SCALAR_FLOAT_MODE_P (mode)
1077       && easy_fp_constant (op, mode))
1078     return 1;
1080   /* Allow any integer constant.  */
1081   if (GET_MODE_CLASS (mode) == MODE_INT
1082       && CONST_SCALAR_INT_P (op))
1083     return 1;
1085   /* Allow easy vector constants.  */
1086   if (GET_CODE (op) == CONST_VECTOR
1087       && easy_vector_constant (op, mode))
1088     return 1;
1090   /* For floating-point or multi-word mode, the only remaining valid type
1091      is a register.  */
1092   if (SCALAR_FLOAT_MODE_P (mode)
1093       || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
1094     return register_operand (op, mode);
1096   /* We don't allow moving the carry bit around.  */
1097   if (ca_operand (op, mode))
1098     return 0;
1100   /* The only cases left are integral modes one word or smaller (we
1101      do not get called for MODE_CC values).  These can be in any
1102      register.  */
1103   if (register_operand (op, mode))
1104     return 1;
1106   /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
1107      to be valid.  */
1108   if (DEFAULT_ABI == ABI_V4
1109       && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
1110       && small_data_operand (op, Pmode))
1111     return 1;
1113   return 0;
1116 ;; Return 1 if this operand is a valid input for a vsx_splat insn.
1117 (define_predicate "splat_input_operand"
1118   (match_code "reg,subreg,mem")
1120   machine_mode vmode;
1122   if (mode == DFmode)
1123     vmode = V2DFmode;
1124   else if (mode == DImode)
1125     vmode = V2DImode;
1126   else if (mode == SImode && TARGET_P9_VECTOR)
1127     vmode = V4SImode;
1128   else if (mode == SFmode && TARGET_P9_VECTOR)
1129     vmode = V4SFmode;
1130   else
1131     return false;
1133   if (MEM_P (op))
1134     {
1135       rtx addr = XEXP (op, 0);
1137       if (! volatile_ok && MEM_VOLATILE_P (op))
1138         return 0;
1140       if (lra_in_progress || reload_completed)
1141         return indexed_or_indirect_address (addr, vmode);
1142       else
1143         return memory_address_addr_space_p (vmode, addr, MEM_ADDR_SPACE (op));
1144     }
1145   return gpc_reg_operand (op, mode);
1148 ;; Return true if operand is an operator used in rotate-and-mask instructions.
1149 (define_predicate "rotate_mask_operator"
1150   (match_code "rotate,ashift,lshiftrt"))
1152 ;; Return true if operand is boolean operator.
1153 (define_predicate "boolean_operator"
1154   (match_code "and,ior,xor"))
1156 ;; Return true if operand is OR-form of boolean operator.
1157 (define_predicate "boolean_or_operator"
1158   (match_code "ior,xor"))
1160 ;; Return true if operand is an equality operator.
1161 (define_special_predicate "equality_operator"
1162   (match_code "eq,ne"))
1164 ;; Return 1 if OP is a comparison operation that is valid for a branch
1165 ;; instruction.  We check the opcode against the mode of the CC value.
1166 ;; validate_condition_mode is an assertion.
1167 (define_predicate "branch_comparison_operator"
1168    (and (match_operand 0 "comparison_operator")
1169         (and (match_test "GET_MODE_CLASS (GET_MODE (XEXP (op, 0))) == MODE_CC")
1170              (match_test "validate_condition_mode (GET_CODE (op),
1171                                                    GET_MODE (XEXP (op, 0))),
1172                           1"))))
1174 ;; Return 1 if OP is an unsigned comparison operator.
1175 (define_predicate "unsigned_comparison_operator"
1176   (match_code "ltu,gtu,leu,geu"))
1178 ;; Return 1 if OP is a signed comparison operator.
1179 (define_predicate "signed_comparison_operator"
1180   (match_code "lt,gt,le,ge"))
1182 ;; Return 1 if OP is a comparison operation that is valid for an SCC insn --
1183 ;; it must be a positive comparison.
1184 (define_predicate "scc_comparison_operator"
1185   (and (match_operand 0 "branch_comparison_operator")
1186        (match_code "eq,lt,gt,ltu,gtu,unordered")))
1188 ;; Return 1 if OP is a comparison operation whose inverse would be valid for
1189 ;; an SCC insn.
1190 (define_predicate "scc_rev_comparison_operator"
1191   (and (match_operand 0 "branch_comparison_operator")
1192        (match_code "ne,le,ge,leu,geu,ordered")))
1194 ;; Return 1 if OP is a comparison operator suitable for floating point
1195 ;; vector/scalar comparisons that generate a -1/0 mask.
1196 (define_predicate "fpmask_comparison_operator"
1197   (match_code "eq,gt,ge"))
1199 ;; Return 1 if OP is a comparison operator suitable for vector/scalar
1200 ;; comparisons that generate a 0/-1 mask (i.e. the inverse of
1201 ;; fpmask_comparison_operator).
1202 (define_predicate "invert_fpmask_comparison_operator"
1203   (match_code "ne,unlt,unle"))
1205 ;; Return 1 if OP is a comparison operation suitable for integer vector/scalar
1206 ;; comparisons that generate a -1/0 mask.
1207 (define_predicate "vecint_comparison_operator"
1208   (match_code "eq,gt,gtu"))
1210 ;; Return 1 if OP is a comparison operation that is valid for a branch
1211 ;; insn, which is true if the corresponding bit in the CC register is set.
1212 (define_predicate "branch_positive_comparison_operator"
1213   (and (match_operand 0 "branch_comparison_operator")
1214        (match_code "eq,lt,gt,ltu,gtu,unordered")))
1216 ;; Return 1 if OP is valid for a save_world call in prologue, known to be
1217 ;; a PARLLEL.
1218 (define_predicate "save_world_operation"
1219   (match_code "parallel")
1221   int index;
1222   int i;
1223   rtx elt;
1224   int count = XVECLEN (op, 0);
1226   if (count != 54)
1227     return 0;
1229   index = 0;
1230   if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1231       || GET_CODE (XVECEXP (op, 0, index++)) != USE)
1232     return 0;
1234   for (i=1; i <= 18; i++)
1235     {
1236       elt = XVECEXP (op, 0, index++);
1237       if (GET_CODE (elt) != SET
1238           || GET_CODE (SET_DEST (elt)) != MEM
1239           || ! memory_operand (SET_DEST (elt), DFmode)
1240           || GET_CODE (SET_SRC (elt)) != REG
1241           || GET_MODE (SET_SRC (elt)) != DFmode)
1242         return 0;
1243     }
1245   for (i=1; i <= 12; i++)
1246     {
1247       elt = XVECEXP (op, 0, index++);
1248       if (GET_CODE (elt) != SET
1249           || GET_CODE (SET_DEST (elt)) != MEM
1250           || GET_CODE (SET_SRC (elt)) != REG
1251           || GET_MODE (SET_SRC (elt)) != V4SImode)
1252         return 0;
1253     }
1255   for (i=1; i <= 19; i++)
1256     {
1257       elt = XVECEXP (op, 0, index++);
1258       if (GET_CODE (elt) != SET
1259           || GET_CODE (SET_DEST (elt)) != MEM
1260           || ! memory_operand (SET_DEST (elt), Pmode)
1261           || GET_CODE (SET_SRC (elt)) != REG
1262           || GET_MODE (SET_SRC (elt)) != Pmode)
1263         return 0;
1264     }
1266   elt = XVECEXP (op, 0, index++);
1267   if (GET_CODE (elt) != SET
1268       || GET_CODE (SET_DEST (elt)) != MEM
1269       || ! memory_operand (SET_DEST (elt), Pmode)
1270       || GET_CODE (SET_SRC (elt)) != REG
1271       || REGNO (SET_SRC (elt)) != CR2_REGNO
1272       || GET_MODE (SET_SRC (elt)) != Pmode)
1273     return 0;
1275   if (GET_CODE (XVECEXP (op, 0, index++)) != SET
1276       || GET_CODE (XVECEXP (op, 0, index++)) != SET)
1277     return 0;
1278   return 1;
1281 ;; Return 1 if OP is valid for a restore_world call in epilogue, known to be
1282 ;; a PARLLEL.
1283 (define_predicate "restore_world_operation"
1284   (match_code "parallel")
1286   int index;
1287   int i;
1288   rtx elt;
1289   int count = XVECLEN (op, 0);
1291   if (count != 58)
1292     return 0;
1294   index = 0;
1295   if (GET_CODE (XVECEXP (op, 0, index++)) != RETURN
1296       || GET_CODE (XVECEXP (op, 0, index++)) != USE
1297       || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
1298     return 0;
1300   elt = XVECEXP (op, 0, index++);
1301   if (GET_CODE (elt) != SET
1302       || GET_CODE (SET_SRC (elt)) != MEM
1303       || ! memory_operand (SET_SRC (elt), Pmode)
1304       || GET_CODE (SET_DEST (elt)) != REG
1305       || REGNO (SET_DEST (elt)) != CR2_REGNO
1306       || GET_MODE (SET_DEST (elt)) != Pmode)
1307     return 0;
1309   for (i=1; i <= 19; i++)
1310     {
1311       elt = XVECEXP (op, 0, index++);
1312       if (GET_CODE (elt) != SET
1313           || GET_CODE (SET_SRC (elt)) != MEM
1314           || ! memory_operand (SET_SRC (elt), Pmode)
1315           || GET_CODE (SET_DEST (elt)) != REG
1316           || GET_MODE (SET_DEST (elt)) != Pmode)
1317         return 0;
1318     }
1320   for (i=1; i <= 12; i++)
1321     {
1322       elt = XVECEXP (op, 0, index++);
1323       if (GET_CODE (elt) != SET
1324           || GET_CODE (SET_SRC (elt)) != MEM
1325           || GET_CODE (SET_DEST (elt)) != REG
1326           || GET_MODE (SET_DEST (elt)) != V4SImode)
1327         return 0;
1328     }
1330   for (i=1; i <= 18; i++)
1331     {
1332       elt = XVECEXP (op, 0, index++);
1333       if (GET_CODE (elt) != SET
1334           || GET_CODE (SET_SRC (elt)) != MEM
1335           || ! memory_operand (SET_SRC (elt), DFmode)
1336           || GET_CODE (SET_DEST (elt)) != REG
1337           || GET_MODE (SET_DEST (elt)) != DFmode)
1338         return 0;
1339     }
1341   if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1342       || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1343       || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1344       || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1345       || GET_CODE (XVECEXP (op, 0, index++)) != USE)
1346     return 0;
1347   return 1;
1350 ;; Return 1 if OP is valid for a vrsave call, known to be a PARALLEL.
1351 (define_predicate "vrsave_operation"
1352   (match_code "parallel")
1354   int count = XVECLEN (op, 0);
1355   unsigned int dest_regno, src_regno;
1356   int i;
1358   if (count <= 1
1359       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1360       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
1361       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE
1362       || XINT (SET_SRC (XVECEXP (op, 0, 0)), 1) != UNSPECV_SET_VRSAVE)
1363     return 0;
1365   dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1366   src_regno  = REGNO (XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 1));
1368   if (dest_regno != VRSAVE_REGNO || src_regno != VRSAVE_REGNO)
1369     return 0;
1371   for (i = 1; i < count; i++)
1372     {
1373       rtx elt = XVECEXP (op, 0, i);
1375       if (GET_CODE (elt) != CLOBBER
1376           && GET_CODE (elt) != SET)
1377         return 0;
1378     }
1380   return 1;
1383 ;; Return 1 if OP is valid for mfcr insn, known to be a PARALLEL.
1384 (define_predicate "mfcr_operation"
1385   (match_code "parallel")
1387   int count = XVECLEN (op, 0);
1388   int i;
1390   /* Perform a quick check so we don't blow up below.  */
1391   if (count < 1
1392       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1393       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
1394       || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
1395     return 0;
1397   for (i = 0; i < count; i++)
1398     {
1399       rtx exp = XVECEXP (op, 0, i);
1400       rtx unspec;
1401       int maskval;
1402       rtx src_reg;
1404       src_reg = XVECEXP (SET_SRC (exp), 0, 0);
1406       if (GET_CODE (src_reg) != REG
1407           || GET_MODE (src_reg) != CCmode
1408           || ! CR_REGNO_P (REGNO (src_reg)))
1409         return 0;
1411       if (GET_CODE (exp) != SET
1412           || GET_CODE (SET_DEST (exp)) != REG
1413           || GET_MODE (SET_DEST (exp)) != SImode
1414           || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
1415         return 0;
1416       unspec = SET_SRC (exp);
1417       maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
1419       if (GET_CODE (unspec) != UNSPEC
1420           || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
1421           || XVECLEN (unspec, 0) != 2
1422           || XVECEXP (unspec, 0, 0) != src_reg
1423           || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
1424           || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
1425         return 0;
1426     }
1427   return 1;
1430 ;; Return 1 if OP is valid for mtcrf insn, known to be a PARALLEL.
1431 (define_predicate "mtcrf_operation"
1432   (match_code "parallel")
1434   int count = XVECLEN (op, 0);
1435   int i;
1436   rtx src_reg;
1438   /* Perform a quick check so we don't blow up below.  */
1439   if (count < 1
1440       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1441       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
1442       || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
1443     return 0;
1444   src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
1446   if (GET_CODE (src_reg) != REG
1447       || GET_MODE (src_reg) != SImode
1448       || ! INT_REGNO_P (REGNO (src_reg)))
1449     return 0;
1451   for (i = 0; i < count; i++)
1452     {
1453       rtx exp = XVECEXP (op, 0, i);
1454       rtx unspec;
1455       int maskval;
1457       if (GET_CODE (exp) != SET
1458           || GET_CODE (SET_DEST (exp)) != REG
1459           || GET_MODE (SET_DEST (exp)) != CCmode
1460           || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
1461         return 0;
1462       unspec = SET_SRC (exp);
1463       maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
1465       if (GET_CODE (unspec) != UNSPEC
1466           || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
1467           || XVECLEN (unspec, 0) != 2
1468           || XVECEXP (unspec, 0, 0) != src_reg
1469           || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
1470           || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
1471         return 0;
1472     }
1473   return 1;
1476 ;; Return 1 if OP is valid for crsave insn, known to be a PARALLEL.
1477 (define_predicate "crsave_operation"
1478   (match_code "parallel")
1480   int count = XVECLEN (op, 0);
1481   int i;
1483   for (i = 1; i < count; i++)
1484     {
1485       rtx exp = XVECEXP (op, 0, i);
1487       if (GET_CODE (exp) != USE
1488           || GET_CODE (XEXP (exp, 0)) != REG
1489           || GET_MODE (XEXP (exp, 0)) != CCmode
1490           || ! CR_REGNO_P (REGNO (XEXP (exp, 0))))
1491         return 0;
1492     }
1493   return 1;
1496 ;; Return 1 if OP is valid for lmw insn, known to be a PARALLEL.
1497 (define_predicate "lmw_operation"
1498   (match_code "parallel")
1500   int count = XVECLEN (op, 0);
1501   unsigned int dest_regno;
1502   rtx src_addr;
1503   unsigned int base_regno;
1504   HOST_WIDE_INT offset;
1505   int i;
1507   /* Perform a quick check so we don't blow up below.  */
1508   if (count <= 1
1509       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1510       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
1511       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
1512     return 0;
1514   dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1515   src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
1517   if (dest_regno > 31
1518       || count != 32 - (int) dest_regno)
1519     return 0;
1521   if (legitimate_indirect_address_p (src_addr, 0))
1522     {
1523       offset = 0;
1524       base_regno = REGNO (src_addr);
1525       if (base_regno == 0)
1526         return 0;
1527     }
1528   else if (rs6000_legitimate_offset_address_p (SImode, src_addr, false, false))
1529     {
1530       offset = INTVAL (XEXP (src_addr, 1));
1531       base_regno = REGNO (XEXP (src_addr, 0));
1532     }
1533   else
1534     return 0;
1536   for (i = 0; i < count; i++)
1537     {
1538       rtx elt = XVECEXP (op, 0, i);
1539       rtx newaddr;
1540       rtx addr_reg;
1541       HOST_WIDE_INT newoffset;
1543       if (GET_CODE (elt) != SET
1544           || GET_CODE (SET_DEST (elt)) != REG
1545           || GET_MODE (SET_DEST (elt)) != SImode
1546           || REGNO (SET_DEST (elt)) != dest_regno + i
1547           || GET_CODE (SET_SRC (elt)) != MEM
1548           || GET_MODE (SET_SRC (elt)) != SImode)
1549         return 0;
1550       newaddr = XEXP (SET_SRC (elt), 0);
1551       if (legitimate_indirect_address_p (newaddr, 0))
1552         {
1553           newoffset = 0;
1554           addr_reg = newaddr;
1555         }
1556       else if (rs6000_legitimate_offset_address_p (SImode, newaddr, false, false))
1557         {
1558           addr_reg = XEXP (newaddr, 0);
1559           newoffset = INTVAL (XEXP (newaddr, 1));
1560         }
1561       else
1562         return 0;
1563       if (REGNO (addr_reg) != base_regno
1564           || newoffset != offset + 4 * i)
1565         return 0;
1566     }
1568   return 1;
1571 ;; Return 1 if OP is valid for stmw insn, known to be a PARALLEL.
1572 (define_predicate "stmw_operation"
1573   (match_code "parallel")
1575   int count = XVECLEN (op, 0);
1576   unsigned int src_regno;
1577   rtx dest_addr;
1578   unsigned int base_regno;
1579   HOST_WIDE_INT offset;
1580   int i;
1582   /* Perform a quick check so we don't blow up below.  */
1583   if (count <= 1
1584       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1585       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
1586       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
1587     return 0;
1589   src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
1590   dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
1592   if (src_regno > 31
1593       || count != 32 - (int) src_regno)
1594     return 0;
1596   if (legitimate_indirect_address_p (dest_addr, 0))
1597     {
1598       offset = 0;
1599       base_regno = REGNO (dest_addr);
1600       if (base_regno == 0)
1601         return 0;
1602     }
1603   else if (rs6000_legitimate_offset_address_p (SImode, dest_addr, false, false))
1604     {
1605       offset = INTVAL (XEXP (dest_addr, 1));
1606       base_regno = REGNO (XEXP (dest_addr, 0));
1607     }
1608   else
1609     return 0;
1611   for (i = 0; i < count; i++)
1612     {
1613       rtx elt = XVECEXP (op, 0, i);
1614       rtx newaddr;
1615       rtx addr_reg;
1616       HOST_WIDE_INT newoffset;
1618       if (GET_CODE (elt) != SET
1619           || GET_CODE (SET_SRC (elt)) != REG
1620           || GET_MODE (SET_SRC (elt)) != SImode
1621           || REGNO (SET_SRC (elt)) != src_regno + i
1622           || GET_CODE (SET_DEST (elt)) != MEM
1623           || GET_MODE (SET_DEST (elt)) != SImode)
1624         return 0;
1625       newaddr = XEXP (SET_DEST (elt), 0);
1626       if (legitimate_indirect_address_p (newaddr, 0))
1627         {
1628           newoffset = 0;
1629           addr_reg = newaddr;
1630         }
1631       else if (rs6000_legitimate_offset_address_p (SImode, newaddr, false, false))
1632         {
1633           addr_reg = XEXP (newaddr, 0);
1634           newoffset = INTVAL (XEXP (newaddr, 1));
1635         }
1636       else
1637         return 0;
1638       if (REGNO (addr_reg) != base_regno
1639           || newoffset != offset + 4 * i)
1640         return 0;
1641     }
1643   return 1;
1646 ;; Return 1 if OP is a stack tie operand.
1647 (define_predicate "tie_operand"
1648   (match_code "parallel")
1650   return (GET_CODE (XVECEXP (op, 0, 0)) == SET
1651           && GET_CODE (XEXP (XVECEXP (op, 0, 0), 0)) == MEM
1652           && GET_MODE (XEXP (XVECEXP (op, 0, 0), 0)) == BLKmode
1653           && XEXP (XVECEXP (op, 0, 0), 1) == const0_rtx);
1656 ;; Match a small code model toc reference (or medium and large
1657 ;; model toc references before reload).
1658 (define_predicate "small_toc_ref"
1659   (match_code "unspec,plus")
1661   if (GET_CODE (op) == PLUS && add_cint_operand (XEXP (op, 1), mode))
1662     op = XEXP (op, 0);
1664   return GET_CODE (op) == UNSPEC && XINT (op, 1) == UNSPEC_TOCREL;
1667 ;; Match the TOC memory operand that can be fused with an addis instruction.
1668 ;; This is used in matching a potential fused address before register
1669 ;; allocation.
1670 (define_predicate "toc_fusion_mem_raw"
1671   (match_code "mem")
1673   if (!TARGET_TOC_FUSION_INT || !can_create_pseudo_p ())
1674     return false;
1676   return small_toc_ref (XEXP (op, 0), Pmode);
1679 ;; Match the memory operand that has been fused with an addis instruction and
1680 ;; wrapped inside of an (unspec [...] UNSPEC_FUSION_ADDIS) wrapper.
1681 (define_predicate "toc_fusion_mem_wrapped"
1682   (match_code "mem")
1684   rtx addr;
1686   if (!TARGET_TOC_FUSION_INT)
1687     return false;
1689   if (!MEM_P (op))
1690     return false;
1692   addr = XEXP (op, 0);
1693   return (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_FUSION_ADDIS);
1696 ;; Match the first insn (addis) in fusing the combination of addis and loads to
1697 ;; GPR registers on power8.
1698 (define_predicate "fusion_gpr_addis"
1699   (match_code "const_int,high,plus")
1701   HOST_WIDE_INT value;
1702   rtx int_const;
1704   if (GET_CODE (op) == HIGH)
1705     return 1;
1707   if (CONST_INT_P (op))
1708     int_const = op;
1710   else if (GET_CODE (op) == PLUS
1711            && base_reg_operand (XEXP (op, 0), Pmode)
1712            && CONST_INT_P (XEXP (op, 1)))
1713     int_const = XEXP (op, 1);
1715   else
1716     return 0;
1718   value = INTVAL (int_const);
1719   if ((value & (HOST_WIDE_INT)0xffff) != 0)
1720     return 0;
1722   if ((value & (HOST_WIDE_INT)0xffff0000) == 0)
1723     return 0;
1725   /* Power8 currently will only do the fusion if the top 11 bits of the addis
1726      value are all 1's or 0's.  Ignore this restriction if we are testing
1727      advanced fusion.  */
1728   if (TARGET_P9_FUSION)
1729     return 1;
1731   return (IN_RANGE (value >> 16, -32, 31));
1734 ;; Match the second insn (lbz, lhz, lwz, ld) in fusing the combination of addis
1735 ;; and loads to GPR registers on power8.
1736 (define_predicate "fusion_gpr_mem_load"
1737   (match_code "mem,sign_extend,zero_extend")
1739   rtx addr, base, offset;
1741   /* Handle sign/zero extend.  */
1742   if (GET_CODE (op) == ZERO_EXTEND
1743       || (TARGET_P8_FUSION_SIGN && GET_CODE (op) == SIGN_EXTEND))
1744     {
1745       op = XEXP (op, 0);
1746       mode = GET_MODE (op);
1747     }
1749   if (!MEM_P (op))
1750     return 0;
1752   switch (mode)
1753     {
1754     case E_QImode:
1755     case E_HImode:
1756     case E_SImode:
1757       break;
1759     case E_DImode:
1760       if (!TARGET_POWERPC64)
1761         return 0;
1762       break;
1764     default:
1765       return 0;
1766     }
1768   addr = XEXP (op, 0);
1769   if (GET_CODE (addr) != PLUS && GET_CODE (addr) != LO_SUM)
1770     return 0;
1772   base = XEXP (addr, 0);
1773   if (!base_reg_operand (base, GET_MODE (base)))
1774     return 0;
1776   offset = XEXP (addr, 1);
1778   if (GET_CODE (addr) == PLUS)
1779     return satisfies_constraint_I (offset);
1781   else if (GET_CODE (addr) == LO_SUM)
1782     {
1783       if (TARGET_XCOFF || (TARGET_ELF && TARGET_POWERPC64))
1784         return small_toc_ref (offset, GET_MODE (offset));
1786       else if (TARGET_ELF && !TARGET_POWERPC64)
1787         return CONSTANT_P (offset);
1788     }
1790   return 0;
1793 ;; Match a GPR load (lbz, lhz, lwz, ld) that uses a combined address in the
1794 ;; memory field with both the addis and the memory offset.  Sign extension
1795 ;; is not handled here, since lha and lwa are not fused.
1796 ;; With P9 fusion, also match a fpr/vector load and float_extend
1797 (define_predicate "fusion_addis_mem_combo_load"
1798   (match_code "mem,zero_extend,float_extend")
1800   rtx addr, base, offset;
1802   /* Handle zero/float extend.  */
1803   if (GET_CODE (op) == ZERO_EXTEND || GET_CODE (op) == FLOAT_EXTEND)
1804     {
1805       op = XEXP (op, 0);
1806       mode = GET_MODE (op);
1807     }
1809   if (!MEM_P (op))
1810     return 0;
1812   switch (mode)
1813     {
1814     case E_QImode:
1815     case E_HImode:
1816     case E_SImode:
1817       break;
1819     /* Do not fuse 64-bit DImode in 32-bit since it splits into two
1820        separate instructions.  */
1821     case E_DImode:
1822       if (!TARGET_POWERPC64)
1823         return 0;
1824       break;
1826     /* ISA 2.08/power8 only had fusion of GPR loads.  */
1827     case E_SFmode:
1828       if (!TARGET_P9_FUSION)
1829         return 0;
1830       break;
1832     /* ISA 2.08/power8 only had fusion of GPR loads.  Do not allow 64-bit
1833        DFmode in 32-bit if -msoft-float since it splits into two separate
1834        instructions.  */
1835     case E_DFmode:
1836       if ((!TARGET_POWERPC64 && !TARGET_HARD_FLOAT) || !TARGET_P9_FUSION)
1837         return 0;
1838       break;
1840     default:
1841       return 0;
1842     }
1844   addr = XEXP (op, 0);
1845   if (GET_CODE (addr) != PLUS && GET_CODE (addr) != LO_SUM)
1846     return 0;
1848   base = XEXP (addr, 0);
1849   if (!fusion_gpr_addis (base, GET_MODE (base)))
1850     return 0;
1852   offset = XEXP (addr, 1);
1853   if (GET_CODE (addr) == PLUS)
1854     return satisfies_constraint_I (offset);
1856   else if (GET_CODE (addr) == LO_SUM)
1857     {
1858       if (TARGET_XCOFF || (TARGET_ELF && TARGET_POWERPC64))
1859         return small_toc_ref (offset, GET_MODE (offset));
1861       else if (TARGET_ELF && !TARGET_POWERPC64)
1862         return CONSTANT_P (offset);
1863     }
1865   return 0;
1868 ;; Like fusion_addis_mem_combo_load, but for stores
1869 (define_predicate "fusion_addis_mem_combo_store"
1870   (match_code "mem")
1872   rtx addr, base, offset;
1874   if (!MEM_P (op) || !TARGET_P9_FUSION)
1875     return 0;
1877   switch (mode)
1878     {
1879     case E_QImode:
1880     case E_HImode:
1881     case E_SImode:
1882     case E_SFmode:
1883       break;
1885     /* Do not fuse 64-bit DImode in 32-bit since it splits into two
1886        separate instructions.  */
1887     case E_DImode:
1888       if (!TARGET_POWERPC64)
1889         return 0;
1890       break;
1892     /* Do not allow 64-bit DFmode in 32-bit if -msoft-float since it splits
1893        into two separate instructions.  Do allow fusion if we have hardware
1894        floating point.  */
1895     case E_DFmode:
1896       if (!TARGET_POWERPC64 && !TARGET_HARD_FLOAT)
1897         return 0;
1898       break;
1900     default:
1901       return 0;
1902     }
1904   addr = XEXP (op, 0);
1905   if (GET_CODE (addr) != PLUS && GET_CODE (addr) != LO_SUM)
1906     return 0;
1908   base = XEXP (addr, 0);
1909   if (!fusion_gpr_addis (base, GET_MODE (base)))
1910     return 0;
1912   offset = XEXP (addr, 1);
1913   if (GET_CODE (addr) == PLUS)
1914     return satisfies_constraint_I (offset);
1916   else if (GET_CODE (addr) == LO_SUM)
1917     {
1918       if (TARGET_XCOFF || (TARGET_ELF && TARGET_POWERPC64))
1919         return small_toc_ref (offset, GET_MODE (offset));
1921       else if (TARGET_ELF && !TARGET_POWERPC64)
1922         return CONSTANT_P (offset);
1923     }
1925   return 0;
1928 ;; Return true if the operand is a float_extend or zero extend of an
1929 ;; offsettable memory operand suitable for use in fusion
1930 (define_predicate "fusion_offsettable_mem_operand"
1931   (match_code "mem,zero_extend,float_extend")
1933   if (GET_CODE (op) == ZERO_EXTEND || GET_CODE (op) == FLOAT_EXTEND)
1934     {
1935       op = XEXP (op, 0);
1936       mode = GET_MODE (op);
1937     }
1939   if (!memory_operand (op, mode))
1940     return 0;
1942   return offsettable_nonstrict_memref_p (op);