2014-09-19 Michael Meissner <meissner@linux.vnet.ibm.com>
[official-gcc.git] / gcc / config / rs6000 / predicates.md
blob379e0a25dbf3dd1990fe5a1acd50be0e12f2f2e1
1 ;; Predicate definitions for POWER and PowerPC.
2 ;; Copyright (C) 2005-2014 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 an Altivec register.
35 (define_predicate "altivec_register_operand"
36   (match_operand 0 "register_operand")
38   if (GET_CODE (op) == SUBREG)
39     op = SUBREG_REG (op);
41   if (!REG_P (op))
42     return 0;
44   if (REGNO (op) > LAST_VIRTUAL_REGISTER)
45     return 1;
47   return ALTIVEC_REGNO_P (REGNO (op));
50 ;; Return 1 if op is a VSX register.
51 (define_predicate "vsx_register_operand"
52   (match_operand 0 "register_operand")
54   if (GET_CODE (op) == SUBREG)
55     op = SUBREG_REG (op);
57   if (!REG_P (op))
58     return 0;
60   if (REGNO (op) > LAST_VIRTUAL_REGISTER)
61     return 1;
63   return VSX_REGNO_P (REGNO (op));
66 ;; Return 1 if op is a vector register that operates on floating point vectors
67 ;; (either altivec or VSX).
68 (define_predicate "vfloat_operand"
69   (match_operand 0 "register_operand")
71   if (GET_CODE (op) == SUBREG)
72     op = SUBREG_REG (op);
74   if (!REG_P (op))
75     return 0;
77   if (REGNO (op) > LAST_VIRTUAL_REGISTER)
78     return 1;
80   return VFLOAT_REGNO_P (REGNO (op));
83 ;; Return 1 if op is a vector register that operates on integer vectors
84 ;; (only altivec, VSX doesn't support integer vectors)
85 (define_predicate "vint_operand"
86   (match_operand 0 "register_operand")
88   if (GET_CODE (op) == SUBREG)
89     op = SUBREG_REG (op);
91   if (!REG_P (op))
92     return 0;
94   if (REGNO (op) > LAST_VIRTUAL_REGISTER)
95     return 1;
97   return VINT_REGNO_P (REGNO (op));
100 ;; Return 1 if op is a vector register to do logical operations on (and, or,
101 ;; xor, etc.)
102 (define_predicate "vlogical_operand"
103   (match_operand 0 "register_operand")
105   if (GET_CODE (op) == SUBREG)
106     op = SUBREG_REG (op);
108   if (!REG_P (op))
109     return 0;
111   if (REGNO (op) > LAST_VIRTUAL_REGISTER)
112     return 1;
114   return VLOGICAL_REGNO_P (REGNO (op));
117 ;; Return 1 if op is the carry register.
118 (define_predicate "ca_operand"
119   (and (match_code "reg")
120        (match_test "CA_REGNO_P (REGNO (op))")))
122 ;; Return 1 if op is a signed 5-bit constant integer.
123 (define_predicate "s5bit_cint_operand"
124   (and (match_code "const_int")
125        (match_test "INTVAL (op) >= -16 && INTVAL (op) <= 15")))
127 ;; Return 1 if op is a unsigned 3-bit constant integer.
128 (define_predicate "u3bit_cint_operand"
129   (and (match_code "const_int")
130        (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 7")))
132 ;; Return 1 if op is a unsigned 5-bit constant integer.
133 (define_predicate "u5bit_cint_operand"
134   (and (match_code "const_int")
135        (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 31")))
137 ;; Return 1 if op is a signed 8-bit constant integer.
138 ;; Integer multiplication complete more quickly
139 (define_predicate "s8bit_cint_operand"
140   (and (match_code "const_int")
141        (match_test "INTVAL (op) >= -128 && INTVAL (op) <= 127")))
143 ;; Return 1 if op is a unsigned 10-bit constant integer.
144 (define_predicate "u10bit_cint_operand"
145   (and (match_code "const_int")
146        (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 1023")))
148 ;; Return 1 if op is a constant integer that can fit in a D field.
149 (define_predicate "short_cint_operand"
150   (and (match_code "const_int")
151        (match_test "satisfies_constraint_I (op)")))
153 ;; Return 1 if op is a constant integer that can fit in an unsigned D field.
154 (define_predicate "u_short_cint_operand"
155   (and (match_code "const_int")
156        (match_test "satisfies_constraint_K (op)")))
158 ;; Return 1 if op is a constant integer that cannot fit in a signed D field.
159 (define_predicate "non_short_cint_operand"
160   (and (match_code "const_int")
161        (match_test "(unsigned HOST_WIDE_INT)
162                     (INTVAL (op) + 0x8000) >= 0x10000")))
164 ;; Return 1 if op is a positive constant integer that is an exact power of 2.
165 (define_predicate "exact_log2_cint_operand"
166   (and (match_code "const_int")
167        (match_test "INTVAL (op) > 0 && exact_log2 (INTVAL (op)) >= 0")))
169 ;; Match op = 0 or op = 1.
170 (define_predicate "const_0_to_1_operand"
171   (and (match_code "const_int")
172        (match_test "IN_RANGE (INTVAL (op), 0, 1)")))
174 ;; Match op = 0..3.
175 (define_predicate "const_0_to_3_operand"
176   (and (match_code "const_int")
177        (match_test "IN_RANGE (INTVAL (op), 0, 3)")))
179 ;; Match op = 2 or op = 3.
180 (define_predicate "const_2_to_3_operand"
181   (and (match_code "const_int")
182        (match_test "IN_RANGE (INTVAL (op), 2, 3)")))
184 ;; Match op = 0..15
185 (define_predicate "const_0_to_15_operand"
186   (and (match_code "const_int")
187        (match_test "IN_RANGE (INTVAL (op), 0, 15)")))
189 ;; Return 1 if op is a register that is not special.
190 (define_predicate "gpc_reg_operand"
191   (match_operand 0 "register_operand")
193   if ((TARGET_E500_DOUBLE || TARGET_SPE) && invalid_e500_subreg (op, mode))
194     return 0;
196   if (GET_CODE (op) == SUBREG)
197     op = SUBREG_REG (op);
199   if (!REG_P (op))
200     return 0;
202   if (REGNO (op) >= ARG_POINTER_REGNUM && !CA_REGNO_P (REGNO (op)))
203     return 1;
205   if (TARGET_VSX && VSX_REGNO_P (REGNO (op)))
206     return 1;
208   return INT_REGNO_P (REGNO (op)) || FP_REGNO_P (REGNO (op));
211 ;; Return 1 if op is a general purpose register.  Unlike gpc_reg_operand, don't
212 ;; allow floating point or vector registers.
213 (define_predicate "int_reg_operand"
214   (match_operand 0 "register_operand")
216   if ((TARGET_E500_DOUBLE || TARGET_SPE) && invalid_e500_subreg (op, mode))
217     return 0;
219   if (GET_CODE (op) == SUBREG)
220     op = SUBREG_REG (op);
222   if (!REG_P (op))
223     return 0;
225   if (REGNO (op) >= FIRST_PSEUDO_REGISTER)
226     return 1;
228   return INT_REGNO_P (REGNO (op));
231 ;; Like int_reg_operand, but only return true for base registers
232 (define_predicate "base_reg_operand"
233   (match_operand 0 "int_reg_operand")
235   if (GET_CODE (op) == SUBREG)
236     op = SUBREG_REG (op);
238   if (!REG_P (op))
239     return 0;
241   return (REGNO (op) != FIRST_GPR_REGNO);
244 ;; Return 1 if op is a HTM specific SPR register.
245 (define_predicate "htm_spr_reg_operand"
246   (match_operand 0 "register_operand")
248   if (!TARGET_HTM)
249     return 0;
251   if (GET_CODE (op) == SUBREG)
252     op = SUBREG_REG (op);
254   if (!REG_P (op))
255     return 0;
257   switch (REGNO (op))
258     {
259       case TFHAR_REGNO:
260       case TFIAR_REGNO:
261       case TEXASR_REGNO:
262         return 1;
263       default:
264         break;
265     }
266   
267   /* Unknown SPR.  */
268   return 0;
271 ;; Return 1 if op is a general purpose register that is an even register
272 ;; which suitable for a load/store quad operation
273 (define_predicate "quad_int_reg_operand"
274   (match_operand 0 "register_operand")
276   HOST_WIDE_INT r;
278   if (!TARGET_QUAD_MEMORY && !TARGET_QUAD_MEMORY_ATOMIC)
279     return 0;
281   if (GET_CODE (op) == SUBREG)
282     op = SUBREG_REG (op);
284   if (!REG_P (op))
285     return 0;
287   r = REGNO (op);
288   if (r >= FIRST_PSEUDO_REGISTER)
289     return 1;
291   return (INT_REGNO_P (r) && ((r & 1) == 0));
294 ;; Return 1 if op is a register that is a condition register field.
295 (define_predicate "cc_reg_operand"
296   (match_operand 0 "register_operand")
298   if (GET_CODE (op) == SUBREG)
299     op = SUBREG_REG (op);
301   if (!REG_P (op))
302     return 0;
304   if (REGNO (op) > LAST_VIRTUAL_REGISTER)
305     return 1;
307   return CR_REGNO_P (REGNO (op));
310 ;; Return 1 if op is a register that is a condition register field not cr0.
311 (define_predicate "cc_reg_not_cr0_operand"
312   (match_operand 0 "register_operand")
314   if (GET_CODE (op) == SUBREG)
315     op = SUBREG_REG (op);
317   if (!REG_P (op))
318     return 0;
320   if (REGNO (op) > LAST_VIRTUAL_REGISTER)
321     return 1;
323   return CR_REGNO_NOT_CR0_P (REGNO (op));
326 ;; Return 1 if op is a register that is a condition register field and if generating microcode, not cr0.
327 (define_predicate "cc_reg_not_micro_cr0_operand"
328   (match_operand 0 "register_operand")
330   if (GET_CODE (op) == SUBREG)
331     op = SUBREG_REG (op);
333   if (!REG_P (op))
334     return 0;
336   if (REGNO (op) > LAST_VIRTUAL_REGISTER)
337     return 1;
339   if (rs6000_gen_cell_microcode)
340     return CR_REGNO_NOT_CR0_P (REGNO (op));
341   else
342     return CR_REGNO_P (REGNO (op));
345 ;; Return 1 if op is a constant integer valid for D field
346 ;; or non-special register register.
347 (define_predicate "reg_or_short_operand"
348   (if_then_else (match_code "const_int")
349     (match_operand 0 "short_cint_operand")
350     (match_operand 0 "gpc_reg_operand")))
352 ;; Return 1 if op is a constant integer valid whose negation is valid for
353 ;; D field or non-special register register.
354 ;; Do not allow a constant zero because all patterns that call this
355 ;; predicate use "addic r1,r2,-const" to set carry when r2 is greater than
356 ;; or equal to const, which does not work for zero.
357 (define_predicate "reg_or_neg_short_operand"
358   (if_then_else (match_code "const_int")
359     (match_test "satisfies_constraint_P (op)
360                  && INTVAL (op) != 0")
361     (match_operand 0 "gpc_reg_operand")))
363 ;; Return 1 if op is a constant integer valid for DS field
364 ;; or non-special register.
365 (define_predicate "reg_or_aligned_short_operand"
366   (if_then_else (match_code "const_int")
367     (and (match_operand 0 "short_cint_operand")
368          (match_test "!(INTVAL (op) & 3)"))
369     (match_operand 0 "gpc_reg_operand")))
371 ;; Return 1 if op is a constant integer whose high-order 16 bits are zero
372 ;; or non-special register.
373 (define_predicate "reg_or_u_short_operand"
374   (if_then_else (match_code "const_int")
375     (match_operand 0 "u_short_cint_operand")
376     (match_operand 0 "gpc_reg_operand")))
378 ;; Return 1 if op is any constant integer 
379 ;; or non-special register.
380 (define_predicate "reg_or_cint_operand"
381   (ior (match_code "const_int")
382        (match_operand 0 "gpc_reg_operand")))
384 ;; Return 1 if op is a constant integer valid for addition with addis, addi.
385 (define_predicate "add_cint_operand"
386   (and (match_code "const_int")
387        (match_test "(unsigned HOST_WIDE_INT)
388                       (INTVAL (op) + (mode == SImode ? 0x80000000 : 0x80008000))
389                     < (unsigned HOST_WIDE_INT) 0x100000000ll")))
391 ;; Return 1 if op is a constant integer valid for addition
392 ;; or non-special register.
393 (define_predicate "reg_or_add_cint_operand"
394   (if_then_else (match_code "const_int")
395     (match_operand 0 "add_cint_operand")
396     (match_operand 0 "gpc_reg_operand")))
398 ;; Return 1 if op is a constant integer valid for subtraction
399 ;; or non-special register.
400 (define_predicate "reg_or_sub_cint_operand"
401   (if_then_else (match_code "const_int")
402     (match_test "(unsigned HOST_WIDE_INT)
403                    (- INTVAL (op) + (mode == SImode ? 0x80000000 : 0x80008000))
404                  < (unsigned HOST_WIDE_INT) 0x100000000ll")
405     (match_operand 0 "gpc_reg_operand")))
407 ;; Return 1 if op is any 32-bit unsigned constant integer
408 ;; or non-special register.
409 (define_predicate "reg_or_logical_cint_operand"
410   (if_then_else (match_code "const_int")
411     (match_test "(GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT
412                   && INTVAL (op) >= 0)
413                  || ((INTVAL (op) & GET_MODE_MASK (mode)
414                       & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0)")
415     (match_operand 0 "gpc_reg_operand")))
417 ;; Like reg_or_logical_cint_operand, but allow vsx registers
418 (define_predicate "vsx_reg_or_cint_operand"
419   (ior (match_operand 0 "vsx_register_operand")
420        (match_operand 0 "reg_or_logical_cint_operand")))
422 ;; Return 1 if operand is a CONST_DOUBLE that can be set in a register
423 ;; with no more than one instruction per word.
424 (define_predicate "easy_fp_constant"
425   (match_code "const_double")
427   long k[4];
428   REAL_VALUE_TYPE rv;
430   if (GET_MODE (op) != mode
431       || (!SCALAR_FLOAT_MODE_P (mode) && mode != DImode))
432     return 0;
434   /* Consider all constants with -msoft-float to be easy.  */
435   if ((TARGET_SOFT_FLOAT || TARGET_E500_SINGLE 
436       || (TARGET_HARD_FLOAT && (TARGET_SINGLE_FLOAT && ! TARGET_DOUBLE_FLOAT)))
437       && mode != DImode)
438     return 1;
440   /* The constant 0.0 is easy under VSX.  */
441   if ((mode == SFmode || mode == DFmode || mode == SDmode || mode == DDmode)
442       && VECTOR_UNIT_VSX_P (DFmode) && op == CONST0_RTX (mode))
443     return 1;
445   if (DECIMAL_FLOAT_MODE_P (mode))
446     return 0;
448   /* If we are using V.4 style PIC, consider all constants to be hard.  */
449   if (flag_pic && DEFAULT_ABI == ABI_V4)
450     return 0;
452 #ifdef TARGET_RELOCATABLE
453   /* Similarly if we are using -mrelocatable, consider all constants
454      to be hard.  */
455   if (TARGET_RELOCATABLE)
456     return 0;
457 #endif
459   switch (mode)
460     {
461     case TFmode:
462       if (TARGET_E500_DOUBLE)
463         return 0;
465       REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
466       REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
468       return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
469               && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1
470               && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1
471               && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1);
473     case DFmode:
474       /* The constant 0.f is easy under VSX.  */
475       if (op == CONST0_RTX (DFmode) && VECTOR_UNIT_VSX_P (DFmode))
476         return 1;
478       /* Force constants to memory before reload to utilize
479          compress_float_constant.
480          Avoid this when flag_unsafe_math_optimizations is enabled
481          because RDIV division to reciprocal optimization is not able
482          to regenerate the division.  */
483       if (TARGET_E500_DOUBLE
484           || (!reload_in_progress && !reload_completed
485               && !flag_unsafe_math_optimizations))
486         return 0;
488       REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
489       REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
491       return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
492               && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
494     case SFmode:
495       /* The constant 0.f is easy.  */
496       if (op == CONST0_RTX (SFmode))
497         return 1;
499       /* Force constants to memory before reload to utilize
500          compress_float_constant.
501          Avoid this when flag_unsafe_math_optimizations is enabled
502          because RDIV division to reciprocal optimization is not able
503          to regenerate the division.  */
504       if (!reload_in_progress && !reload_completed
505           && !flag_unsafe_math_optimizations)
506         return 0;
508       REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
509       REAL_VALUE_TO_TARGET_SINGLE (rv, k[0]);
511       return num_insns_constant_wide (k[0]) == 1;
513   case DImode:
514     return (num_insns_constant (op, DImode) <= 2);
516   case SImode:
517     return 1;
519   default:
520     gcc_unreachable ();
521   }
524 ;; Return 1 if the operand is a CONST_VECTOR and can be loaded into a
525 ;; vector register without using memory.
526 (define_predicate "easy_vector_constant"
527   (match_code "const_vector")
529   /* As the paired vectors are actually FPRs it seems that there is
530      no easy way to load a CONST_VECTOR without using memory.  */
531   if (TARGET_PAIRED_FLOAT)
532     return false;
534   if (VECTOR_MEM_ALTIVEC_OR_VSX_P (mode))
535     {
536       if (zero_constant (op, mode))
537         return true;
539       return easy_altivec_constant (op, mode);
540     }
542   if (SPE_VECTOR_MODE (mode))
543     {
544       int cst, cst2;
545       if (zero_constant (op, mode))
546         return true;
547       if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
548         return false;
550       /* Limit SPE vectors to 15 bits signed.  These we can generate with:
551            li r0, CONSTANT1
552            evmergelo r0, r0, r0
553            li r0, CONSTANT2
555          I don't know how efficient it would be to allow bigger constants,
556          considering we'll have an extra 'ori' for every 'li'.  I doubt 5
557          instructions is better than a 64-bit memory load, but I don't
558          have the e500 timing specs.  */
559       if (mode == V2SImode)
560         {
561           cst  = INTVAL (CONST_VECTOR_ELT (op, 0));
562           cst2 = INTVAL (CONST_VECTOR_ELT (op, 1));
563           return cst  >= -0x7fff && cst <= 0x7fff
564                  && cst2 >= -0x7fff && cst2 <= 0x7fff;
565         }
566     }
568   return false;
571 ;; Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF.
572 (define_predicate "easy_vector_constant_add_self"
573   (and (match_code "const_vector")
574        (and (match_test "TARGET_ALTIVEC")
575             (match_test "easy_altivec_constant (op, mode)")))
577   HOST_WIDE_INT val;
578   int elt;
579   if (mode == V2DImode || mode == V2DFmode)
580     return 0;
581   elt = BYTES_BIG_ENDIAN ? GET_MODE_NUNITS (mode) - 1 : 0;
582   val = const_vector_elt_as_int (op, elt);
583   val = ((val & 0xff) ^ 0x80) - 0x80;
584   return EASY_VECTOR_15_ADD_SELF (val);
587 ;; Same as easy_vector_constant but only for EASY_VECTOR_MSB.
588 (define_predicate "easy_vector_constant_msb"
589   (and (match_code "const_vector")
590        (and (match_test "TARGET_ALTIVEC")
591             (match_test "easy_altivec_constant (op, mode)")))
593   HOST_WIDE_INT val;
594   int elt;
595   if (mode == V2DImode || mode == V2DFmode)
596     return 0;
597   elt = BYTES_BIG_ENDIAN ? GET_MODE_NUNITS (mode) - 1 : 0;
598   val = const_vector_elt_as_int (op, elt);
599   return EASY_VECTOR_MSB (val, GET_MODE_INNER (mode));
602 ;; Return 1 if operand is constant zero (scalars and vectors).
603 (define_predicate "zero_constant"
604   (and (match_code "const_int,const_double,const_wide_int,const_vector")
605        (match_test "op == CONST0_RTX (mode)")))
607 ;; Return 1 if operand is 0.0.
608 (define_predicate "zero_fp_constant"
609   (and (match_code "const_double")
610        (match_test "SCALAR_FLOAT_MODE_P (mode)
611                     && op == CONST0_RTX (mode)")))
613 ;; Return 1 if the operand is in volatile memory.  Note that during the
614 ;; RTL generation phase, memory_operand does not return TRUE for volatile
615 ;; memory references.  So this function allows us to recognize volatile
616 ;; references where it's safe.
617 (define_predicate "volatile_mem_operand"
618   (and (and (match_code "mem")
619             (match_test "MEM_VOLATILE_P (op)"))
620        (if_then_else (match_test "reload_completed")
621          (match_operand 0 "memory_operand")
622          (if_then_else (match_test "reload_in_progress")
623            (match_test "strict_memory_address_p (mode, XEXP (op, 0))")
624            (match_test "memory_address_p (mode, XEXP (op, 0))")))))
626 ;; Return 1 if the operand is an offsettable memory operand.
627 (define_predicate "offsettable_mem_operand"
628   (and (match_operand 0 "memory_operand")
629        (match_test "offsettable_nonstrict_memref_p (op)")))
631 ;; Return 1 if the operand is suitable for load/store quad memory.
632 ;; This predicate only checks for non-atomic loads/stores (not lqarx/stqcx).
633 (define_predicate "quad_memory_operand"
634   (match_code "mem")
636   rtx addr, op0, op1;
637   int ret;
639   if (!TARGET_QUAD_MEMORY && !TARGET_SYNC_TI)
640     ret = 0;
642   else if (!memory_operand (op, mode))
643     ret = 0;
645   else if (GET_MODE_SIZE (GET_MODE (op)) != 16)
646     ret = 0;
648   else if (MEM_ALIGN (op) < 128)
649     ret = 0;
651   else
652     {
653       addr = XEXP (op, 0);
654       if (int_reg_operand (addr, Pmode))
655         ret = 1;
657       else if (GET_CODE (addr) != PLUS)
658         ret = 0;
660       else
661         {
662           op0 = XEXP (addr, 0);
663           op1 = XEXP (addr, 1);
664           ret = (int_reg_operand (op0, Pmode)
665                  && GET_CODE (op1) == CONST_INT
666                  && IN_RANGE (INTVAL (op1), -32768, 32767)
667                  && (INTVAL (op1) & 15) == 0);
668         }
669     }
671   if (TARGET_DEBUG_ADDR)
672     {
673       fprintf (stderr, "\nquad_memory_operand, ret = %s\n", ret ? "true" : "false");
674       debug_rtx (op);
675     }
677   return ret;
680 ;; Return 1 if the operand is an indexed or indirect memory operand.
681 (define_predicate "indexed_or_indirect_operand"
682   (match_code "mem")
684   op = XEXP (op, 0);
685   if (VECTOR_MEM_ALTIVEC_P (mode)
686       && GET_CODE (op) == AND
687       && GET_CODE (XEXP (op, 1)) == CONST_INT
688       && INTVAL (XEXP (op, 1)) == -16)
689     op = XEXP (op, 0);
691   return indexed_or_indirect_address (op, mode);
694 ;; Like indexed_or_indirect_operand, but also allow a GPR register if direct
695 ;; moves are supported.
696 (define_predicate "reg_or_indexed_operand"
697   (match_code "mem,reg")
699   if (MEM_P (op))
700     return indexed_or_indirect_operand (op, mode);
701   else if (TARGET_DIRECT_MOVE)
702     return register_operand (op, mode);
703   return
704     0;
707 ;; Return 1 if the operand is an indexed or indirect memory operand with an
708 ;; AND -16 in it, used to recognize when we need to switch to Altivec loads
709 ;; to realign loops instead of VSX (altivec silently ignores the bottom bits,
710 ;; while VSX uses the full address and traps)
711 (define_predicate "altivec_indexed_or_indirect_operand"
712   (match_code "mem")
714   op = XEXP (op, 0);
715   if (VECTOR_MEM_ALTIVEC_OR_VSX_P (mode)
716       && GET_CODE (op) == AND
717       && GET_CODE (XEXP (op, 1)) == CONST_INT
718       && INTVAL (XEXP (op, 1)) == -16)
719     return indexed_or_indirect_address (XEXP (op, 0), mode);
721   return 0;
724 ;; Return 1 if the operand is an indexed or indirect address.
725 (define_special_predicate "indexed_or_indirect_address"
726   (and (match_test "REG_P (op)
727                     || (GET_CODE (op) == PLUS
728                         /* Omit testing REG_P (XEXP (op, 0)).  */
729                         && REG_P (XEXP (op, 1)))")
730        (match_operand 0 "address_operand")))
732 ;; Return 1 if the operand is an index-form address.
733 (define_special_predicate "indexed_address"
734   (match_test "(GET_CODE (op) == PLUS
735                 && REG_P (XEXP (op, 0))
736                 && REG_P (XEXP (op, 1)))"))
738 ;; Return 1 if the operand is a MEM with an update-form address. This may
739 ;; also include update-indexed form.
740 (define_special_predicate "update_address_mem"
741   (match_test "(MEM_P (op)
742                 && (GET_CODE (XEXP (op, 0)) == PRE_INC
743                     || GET_CODE (XEXP (op, 0)) == PRE_DEC
744                     || GET_CODE (XEXP (op, 0)) == PRE_MODIFY))"))
746 ;; Return 1 if the operand is a MEM with an indexed-form address.
747 (define_special_predicate "indexed_address_mem"
748   (match_test "(MEM_P (op)
749                 && (indexed_address (XEXP (op, 0), mode)
750                     || (GET_CODE (XEXP (op, 0)) == PRE_MODIFY
751                         && indexed_address (XEXP (XEXP (op, 0), 1), mode))))"))
753 ;; Used for the destination of the fix_truncdfsi2 expander.
754 ;; If stfiwx will be used, the result goes to memory; otherwise,
755 ;; we're going to emit a store and a load of a subreg, so the dest is a
756 ;; register.
757 (define_predicate "fix_trunc_dest_operand"
758   (if_then_else (match_test "! TARGET_E500_DOUBLE && TARGET_PPC_GFXOPT")
759    (match_operand 0 "memory_operand")
760    (match_operand 0 "gpc_reg_operand")))
762 ;; Return 1 if the operand is either a non-special register or can be used
763 ;; as the operand of a `mode' add insn.
764 (define_predicate "add_operand"
765   (if_then_else (match_code "const_int")
766     (match_test "satisfies_constraint_I (op)
767                  || satisfies_constraint_L (op)")
768     (match_operand 0 "gpc_reg_operand")))
770 ;; Return 1 if OP is a constant but not a valid add_operand.
771 (define_predicate "non_add_cint_operand"
772   (and (match_code "const_int")
773        (match_test "!satisfies_constraint_I (op)
774                     && !satisfies_constraint_L (op)")))
776 ;; Return 1 if the operand is a constant that can be used as the operand
777 ;; of an OR or XOR.
778 (define_predicate "logical_const_operand"
779   (match_code "const_int")
781   HOST_WIDE_INT opl;
783   opl = INTVAL (op) & GET_MODE_MASK (mode);
785   return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
786           || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
789 ;; Return 1 if the operand is a non-special register or a constant that
790 ;; can be used as the operand of an OR or XOR.
791 (define_predicate "logical_operand"
792   (ior (match_operand 0 "gpc_reg_operand")
793        (match_operand 0 "logical_const_operand")))
795 ;; Return 1 if op is a constant that is not a logical operand, but could
796 ;; be split into one.
797 (define_predicate "non_logical_cint_operand"
798   (and (match_code "const_int,const_wide_int")
799        (and (not (match_operand 0 "logical_operand"))
800             (match_operand 0 "reg_or_logical_cint_operand"))))
802 ;; Return 1 if op is a constant that can be encoded in a 32-bit mask,
803 ;; suitable for use with rlwinm (no more than two 1->0 or 0->1
804 ;; transitions).  Reject all ones and all zeros, since these should have
805 ;; been optimized away and confuse the making of MB and ME.
806 (define_predicate "mask_operand"
807   (match_code "const_int")
809   HOST_WIDE_INT c, lsb;
811   c = INTVAL (op);
813   if (TARGET_POWERPC64)
814     {
815       /* Fail if the mask is not 32-bit.  */
816       if (mode == DImode && (c & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0)
817         return 0;
819       /* Fail if the mask wraps around because the upper 32-bits of the
820          mask will all be 1s, contrary to GCC's internal view.  */
821       if ((c & 0x80000001) == 0x80000001)
822         return 0;
823     }
825   /* We don't change the number of transitions by inverting,
826      so make sure we start with the LS bit zero.  */
827   if (c & 1)
828     c = ~c;
830   /* Reject all zeros or all ones.  */
831   if (c == 0)
832     return 0;
834   /* Find the first transition.  */
835   lsb = c & -c;
837   /* Invert to look for a second transition.  */
838   c = ~c;
840   /* Erase first transition.  */
841   c &= -lsb;
843   /* Find the second transition (if any).  */
844   lsb = c & -c;
846   /* Match if all the bits above are 1's (or c is zero).  */
847   return c == -lsb;
850 ;; Return 1 for the PowerPC64 rlwinm corner case.
851 (define_predicate "mask_operand_wrap"
852   (match_code "const_int")
854   HOST_WIDE_INT c, lsb;
856   c = INTVAL (op);
858   if ((c & 0x80000001) != 0x80000001)
859     return 0;
861   c = ~c;
862   if (c == 0)
863     return 0;
865   lsb = c & -c;
866   c = ~c;
867   c &= -lsb;
868   lsb = c & -c;
869   return c == -lsb;
872 ;; Return 1 if the operand is a constant that is a PowerPC64 mask
873 ;; suitable for use with rldicl or rldicr (no more than one 1->0 or 0->1
874 ;; transition).  Reject all zeros, since zero should have been
875 ;; optimized away and confuses the making of MB and ME.
876 (define_predicate "mask64_operand"
877   (match_code "const_int")
879   HOST_WIDE_INT c, lsb;
881   c = INTVAL (op);
883   /* Reject all zeros.  */
884   if (c == 0)
885     return 0;
887   /* We don't change the number of transitions by inverting,
888      so make sure we start with the LS bit zero.  */
889   if (c & 1)
890     c = ~c;
892   /* Find the first transition.  */
893   lsb = c & -c;
895   /* Match if all the bits above are 1's (or c is zero).  */
896   return c == -lsb;
899 ;; Like mask64_operand, but allow up to three transitions.  This
900 ;; predicate is used by insn patterns that generate two rldicl or
901 ;; rldicr machine insns.
902 (define_predicate "mask64_2_operand"
903   (match_code "const_int")
905   HOST_WIDE_INT c, lsb;
907   c = INTVAL (op);
909   /* Disallow all zeros.  */
910   if (c == 0)
911     return 0;
913   /* We don't change the number of transitions by inverting,
914      so make sure we start with the LS bit zero.  */
915   if (c & 1)
916     c = ~c;
918   /* Find the first transition.  */
919   lsb = c & -c;
921   /* Invert to look for a second transition.  */
922   c = ~c;
924   /* Erase first transition.  */
925   c &= -lsb;
927   /* Find the second transition.  */
928   lsb = c & -c;
930   /* Invert to look for a third transition.  */
931   c = ~c;
933   /* Erase second transition.  */
934   c &= -lsb;
936   /* Find the third transition (if any).  */
937   lsb = c & -c;
939   /* Match if all the bits above are 1's (or c is zero).  */
940   return c == -lsb;
943 ;; Match a mask_operand or a mask64_operand.
944 (define_predicate "any_mask_operand"
945   (ior (match_operand 0 "mask_operand")
946        (and (match_test "TARGET_POWERPC64 && mode == DImode")
947             (match_operand 0 "mask64_operand"))))
949 ;; Like and_operand, but also match constants that can be implemented
950 ;; with two rldicl or rldicr insns.
951 (define_predicate "and64_2_operand"
952   (ior (match_operand 0 "mask64_2_operand")
953        (if_then_else (match_test "fixed_regs[CR0_REGNO]")
954          (match_operand 0 "gpc_reg_operand")
955          (match_operand 0 "logical_operand"))))
957 ;; Return 1 if the operand is either a non-special register or a
958 ;; constant that can be used as the operand of a logical AND.
959 (define_predicate "and_operand"
960   (ior (match_operand 0 "mask_operand")
961        (and (match_test "TARGET_POWERPC64 && mode == DImode")
962             (match_operand 0 "mask64_operand"))
963        (if_then_else (match_test "fixed_regs[CR0_REGNO]")
964          (match_operand 0 "gpc_reg_operand")
965          (match_operand 0 "logical_operand"))))
967 ;; Return 1 if the operand is a constant that can be used as the operand
968 ;; of a logical AND, implemented with two rld* insns, and it cannot be done
969 ;; using just one insn.
970 (define_predicate "and_2rld_operand"
971   (and (match_operand 0 "and64_2_operand")
972        (not (match_operand 0 "and_operand"))))
974 ;; Return 1 if the operand is either a logical operand or a short cint operand.
975 (define_predicate "scc_eq_operand"
976   (ior (match_operand 0 "logical_operand")
977        (match_operand 0 "short_cint_operand")))
979 ;; Return 1 if the operand is a general non-special register or memory operand.
980 (define_predicate "reg_or_mem_operand"
981      (ior (match_operand 0 "memory_operand")
982           (ior (and (match_code "mem")
983                     (match_test "macho_lo_sum_memory_operand (op, mode)"))
984                (ior (match_operand 0 "volatile_mem_operand")
985                     (match_operand 0 "gpc_reg_operand")))))
987 ;; Return 1 if the operand is either an easy FP constant or memory or reg.
988 (define_predicate "reg_or_none500mem_operand"
989   (if_then_else (match_code "mem")
990      (and (match_test "!TARGET_E500_DOUBLE")
991           (ior (match_operand 0 "memory_operand")
992                (ior (match_test "macho_lo_sum_memory_operand (op, mode)")
993                     (match_operand 0 "volatile_mem_operand"))))
994      (match_operand 0 "gpc_reg_operand")))
996 ;; Return 1 if the operand is CONST_DOUBLE 0, register or memory operand.
997 (define_predicate "zero_reg_mem_operand"
998   (ior (match_operand 0 "zero_fp_constant")
999        (match_operand 0 "reg_or_mem_operand")))
1001 ;; Return 1 if the operand is a CONST_INT and it is the element for 64-bit
1002 ;; data types inside of a vector that scalar instructions operate on
1003 (define_predicate "vsx_scalar_64bit"
1004   (match_code "const_int")
1006   return (INTVAL (op) == VECTOR_ELEMENT_SCALAR_64BIT);
1009 ;; Return 1 if the operand is a general register or memory operand without
1010 ;; pre_inc or pre_dec or pre_modify, which produces invalid form of PowerPC
1011 ;; lwa instruction.
1012 (define_predicate "lwa_operand"
1013   (match_code "reg,subreg,mem")
1015   rtx inner, addr, offset;
1017   inner = op;
1018   if (reload_completed && GET_CODE (inner) == SUBREG)
1019     inner = SUBREG_REG (inner);
1021   if (gpc_reg_operand (inner, mode))
1022     return true;
1023   if (!memory_operand (inner, mode))
1024     return false;
1025   if (!rs6000_gen_cell_microcode)
1026     return false;
1028   addr = XEXP (inner, 0);
1029   if (GET_CODE (addr) == PRE_INC
1030       || GET_CODE (addr) == PRE_DEC
1031       || (GET_CODE (addr) == PRE_MODIFY
1032           && !legitimate_indexed_address_p (XEXP (addr, 1), 0)))
1033     return false;
1034   if (GET_CODE (addr) == LO_SUM
1035       && GET_CODE (XEXP (addr, 0)) == REG
1036       && GET_CODE (XEXP (addr, 1)) == CONST)
1037     addr = XEXP (XEXP (addr, 1), 0);
1038   if (GET_CODE (addr) != PLUS)
1039     return true;
1040   offset = XEXP (addr, 1);
1041   if (GET_CODE (offset) != CONST_INT)
1042     return true;
1043   return INTVAL (offset) % 4 == 0;
1046 ;; Return 1 if the operand, used inside a MEM, is a SYMBOL_REF.
1047 (define_predicate "symbol_ref_operand"
1048   (and (match_code "symbol_ref")
1049        (match_test "(mode == VOIDmode || GET_MODE (op) == mode)
1050                     && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))")))
1052 ;; Return 1 if op is an operand that can be loaded via the GOT.
1053 ;; or non-special register register field no cr0
1054 (define_predicate "got_operand"
1055   (match_code "symbol_ref,const,label_ref"))
1057 ;; Return 1 if op is a simple reference that can be loaded via the GOT,
1058 ;; excluding labels involving addition.
1059 (define_predicate "got_no_const_operand"
1060   (match_code "symbol_ref,label_ref"))
1062 ;; Return 1 if op is a SYMBOL_REF for a TLS symbol.
1063 (define_predicate "rs6000_tls_symbol_ref"
1064   (and (match_code "symbol_ref")
1065        (match_test "RS6000_SYMBOL_REF_TLS_P (op)")))
1067 ;; Return 1 if the operand, used inside a MEM, is a valid first argument
1068 ;; to CALL.  This is a SYMBOL_REF, a pseudo-register, LR or CTR.
1069 (define_predicate "call_operand"
1070   (if_then_else (match_code "reg")
1071      (match_test "REGNO (op) == LR_REGNO
1072                   || REGNO (op) == CTR_REGNO
1073                   || REGNO (op) >= FIRST_PSEUDO_REGISTER")
1074      (match_code "symbol_ref")))
1076 ;; Return 1 if the operand is a SYMBOL_REF for a function known to be in
1077 ;; this file.
1078 (define_predicate "current_file_function_operand"
1079   (and (match_code "symbol_ref")
1080        (match_test "(DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
1081                     && ((SYMBOL_REF_LOCAL_P (op)
1082                          && ((DEFAULT_ABI != ABI_AIX
1083                               && DEFAULT_ABI != ABI_ELFv2)
1084                              || !SYMBOL_REF_EXTERNAL_P (op)))
1085                         || (op == XEXP (DECL_RTL (current_function_decl),
1086                                                   0)))")))
1088 ;; Return 1 if this operand is a valid input for a move insn.
1089 (define_predicate "input_operand"
1090   (match_code "symbol_ref,const,reg,subreg,mem,
1091                const_double,const_wide_int,const_vector,const_int")
1093   /* Memory is always valid.  */
1094   if (memory_operand (op, mode))
1095     return 1;
1097   /* For floating-point, easy constants are valid.  */
1098   if (SCALAR_FLOAT_MODE_P (mode)
1099       && easy_fp_constant (op, mode))
1100     return 1;
1102   /* Allow any integer constant.  */
1103   if (GET_MODE_CLASS (mode) == MODE_INT
1104       && CONST_SCALAR_INT_P (op))
1105     return 1;
1107   /* Allow easy vector constants.  */
1108   if (GET_CODE (op) == CONST_VECTOR
1109       && easy_vector_constant (op, mode))
1110     return 1;
1112   /* Do not allow invalid E500 subregs.  */
1113   if ((TARGET_E500_DOUBLE || TARGET_SPE)
1114       && GET_CODE (op) == SUBREG
1115       && invalid_e500_subreg (op, mode))
1116     return 0;
1118   /* For floating-point or multi-word mode, the only remaining valid type
1119      is a register.  */
1120   if (SCALAR_FLOAT_MODE_P (mode)
1121       || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
1122     return register_operand (op, mode);
1124   /* The only cases left are integral modes one word or smaller (we
1125      do not get called for MODE_CC values).  These can be in any
1126      register.  */
1127   if (register_operand (op, mode))
1128     return 1;
1130   /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
1131      to be valid.  */
1132   if (DEFAULT_ABI == ABI_V4
1133       && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
1134       && small_data_operand (op, Pmode))
1135     return 1;
1137   return 0;
1140 ;; Return 1 if this operand is a valid input for a vsx_splat insn.
1141 (define_predicate "splat_input_operand"
1142   (match_code "symbol_ref,const,reg,subreg,mem,
1143                const_double,const_wide_int,const_vector,const_int")
1145   if (MEM_P (op))
1146     {
1147       if (! volatile_ok && MEM_VOLATILE_P (op))
1148         return 0;
1149       if (mode == DFmode)
1150         mode = V2DFmode;
1151       else if (mode == DImode)
1152         mode = V2DImode;
1153       else
1154         gcc_unreachable ();
1155       return memory_address_addr_space_p (mode, XEXP (op, 0),
1156                                           MEM_ADDR_SPACE (op));
1157     }
1158   return input_operand (op, mode);
1161 ;; Return true if OP is a non-immediate operand and not an invalid
1162 ;; SUBREG operation on the e500.
1163 (define_predicate "rs6000_nonimmediate_operand"
1164   (match_code "reg,subreg,mem")
1166   if ((TARGET_E500_DOUBLE || TARGET_SPE)
1167       && GET_CODE (op) == SUBREG
1168       && invalid_e500_subreg (op, mode))
1169     return 0;
1171   return nonimmediate_operand (op, mode);
1174 ;; Return true if operand is boolean operator.
1175 (define_predicate "boolean_operator"
1176   (match_code "and,ior,xor"))
1178 ;; Return true if operand is OR-form of boolean operator.
1179 (define_predicate "boolean_or_operator"
1180   (match_code "ior,xor"))
1182 ;; Return true if operand is an equality operator.
1183 (define_special_predicate "equality_operator"
1184   (match_code "eq,ne"))
1186 ;; Return true if operand is MIN or MAX operator.
1187 (define_predicate "min_max_operator"
1188   (match_code "smin,smax,umin,umax"))
1190 ;; Return 1 if OP is a comparison operation that is valid for a branch
1191 ;; instruction.  We check the opcode against the mode of the CC value.
1192 ;; validate_condition_mode is an assertion.
1193 (define_predicate "branch_comparison_operator"
1194    (and (match_operand 0 "comparison_operator")
1195         (and (match_test "GET_MODE_CLASS (GET_MODE (XEXP (op, 0))) == MODE_CC")
1196              (match_test "validate_condition_mode (GET_CODE (op),
1197                                                    GET_MODE (XEXP (op, 0))),
1198                           1"))))
1200 ;; Return 1 if OP is a valid comparison operator for "cbranch" instructions.
1201 ;; If we're assuming that FP operations cannot generate user-visible traps,
1202 ;; then on e500 we can use the ordered-signaling instructions to implement
1203 ;; the unordered-quiet FP comparison predicates modulo a reversal.
1204 (define_predicate "rs6000_cbranch_operator"
1205   (if_then_else (match_test "TARGET_HARD_FLOAT && !TARGET_FPRS")
1206                 (if_then_else (match_test "flag_trapping_math")
1207                               (match_operand 0 "ordered_comparison_operator")
1208                               (ior (match_operand 0 "ordered_comparison_operator")
1209                                    (match_code ("unlt,unle,ungt,unge"))))
1210                 (match_operand 0 "comparison_operator")))
1212 ;; Return 1 if OP is a comparison operation that is valid for an SCC insn --
1213 ;; it must be a positive comparison.
1214 (define_predicate "scc_comparison_operator"
1215   (and (match_operand 0 "branch_comparison_operator")
1216        (match_code "eq,lt,gt,ltu,gtu,unordered")))
1218 ;; Return 1 if OP is a comparison operation whose inverse would be valid for
1219 ;; an SCC insn.
1220 (define_predicate "scc_rev_comparison_operator"
1221   (and (match_operand 0 "branch_comparison_operator")
1222        (match_code "ne,le,ge,leu,geu,ordered")))
1224 ;; Return 1 if OP is a comparison operation that is valid for a branch
1225 ;; insn, which is true if the corresponding bit in the CC register is set.
1226 (define_predicate "branch_positive_comparison_operator"
1227   (and (match_operand 0 "branch_comparison_operator")
1228        (match_code "eq,lt,gt,ltu,gtu,unordered")))
1230 ;; Return 1 if OP is a load multiple operation, known to be a PARALLEL.
1231 (define_predicate "load_multiple_operation"
1232   (match_code "parallel")
1234   int count = XVECLEN (op, 0);
1235   unsigned int dest_regno;
1236   rtx src_addr;
1237   int i;
1239   /* Perform a quick check so we don't blow up below.  */
1240   if (count <= 1
1241       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1242       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
1243       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
1244     return 0;
1246   dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1247   src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
1249   for (i = 1; i < count; i++)
1250     {
1251       rtx elt = XVECEXP (op, 0, i);
1253       if (GET_CODE (elt) != SET
1254           || GET_CODE (SET_DEST (elt)) != REG
1255           || GET_MODE (SET_DEST (elt)) != SImode
1256           || REGNO (SET_DEST (elt)) != dest_regno + i
1257           || GET_CODE (SET_SRC (elt)) != MEM
1258           || GET_MODE (SET_SRC (elt)) != SImode
1259           || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
1260           || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
1261           || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
1262           || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
1263         return 0;
1264     }
1266   return 1;
1269 ;; Return 1 if OP is a store multiple operation, known to be a PARALLEL.
1270 ;; The second vector element is a CLOBBER.
1271 (define_predicate "store_multiple_operation"
1272   (match_code "parallel")
1274   int count = XVECLEN (op, 0) - 1;
1275   unsigned int src_regno;
1276   rtx dest_addr;
1277   int i;
1279   /* Perform a quick check so we don't blow up below.  */
1280   if (count <= 1
1281       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1282       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
1283       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
1284     return 0;
1286   src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
1287   dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
1289   for (i = 1; i < count; i++)
1290     {
1291       rtx elt = XVECEXP (op, 0, i + 1);
1293       if (GET_CODE (elt) != SET
1294           || GET_CODE (SET_SRC (elt)) != REG
1295           || GET_MODE (SET_SRC (elt)) != SImode
1296           || REGNO (SET_SRC (elt)) != src_regno + i
1297           || GET_CODE (SET_DEST (elt)) != MEM
1298           || GET_MODE (SET_DEST (elt)) != SImode
1299           || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
1300           || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
1301           || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
1302           || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
1303         return 0;
1304     }
1306   return 1;
1309 ;; Return 1 if OP is valid for a save_world call in prologue, known to be
1310 ;; a PARLLEL.
1311 (define_predicate "save_world_operation"
1312   (match_code "parallel")
1314   int index;
1315   int i;
1316   rtx elt;
1317   int count = XVECLEN (op, 0);
1319   if (count != 54)
1320     return 0;
1322   index = 0;
1323   if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1324       || GET_CODE (XVECEXP (op, 0, index++)) != USE)
1325     return 0;
1327   for (i=1; i <= 18; i++)
1328     {
1329       elt = XVECEXP (op, 0, index++);
1330       if (GET_CODE (elt) != SET
1331           || GET_CODE (SET_DEST (elt)) != MEM
1332           || ! memory_operand (SET_DEST (elt), DFmode)
1333           || GET_CODE (SET_SRC (elt)) != REG
1334           || GET_MODE (SET_SRC (elt)) != DFmode)
1335         return 0;
1336     }
1338   for (i=1; i <= 12; i++)
1339     {
1340       elt = XVECEXP (op, 0, index++);
1341       if (GET_CODE (elt) != SET
1342           || GET_CODE (SET_DEST (elt)) != MEM
1343           || GET_CODE (SET_SRC (elt)) != REG
1344           || GET_MODE (SET_SRC (elt)) != V4SImode)
1345         return 0;
1346     }
1348   for (i=1; i <= 19; i++)
1349     {
1350       elt = XVECEXP (op, 0, index++);
1351       if (GET_CODE (elt) != SET
1352           || GET_CODE (SET_DEST (elt)) != MEM
1353           || ! memory_operand (SET_DEST (elt), Pmode)
1354           || GET_CODE (SET_SRC (elt)) != REG
1355           || GET_MODE (SET_SRC (elt)) != Pmode)
1356         return 0;
1357     }
1359   elt = XVECEXP (op, 0, index++);
1360   if (GET_CODE (elt) != SET
1361       || GET_CODE (SET_DEST (elt)) != MEM
1362       || ! memory_operand (SET_DEST (elt), Pmode)
1363       || GET_CODE (SET_SRC (elt)) != REG
1364       || REGNO (SET_SRC (elt)) != CR2_REGNO
1365       || GET_MODE (SET_SRC (elt)) != Pmode)
1366     return 0;
1368   if (GET_CODE (XVECEXP (op, 0, index++)) != SET
1369       || GET_CODE (XVECEXP (op, 0, index++)) != SET)
1370     return 0;
1371   return 1;
1374 ;; Return 1 if OP is valid for a restore_world call in epilogue, known to be
1375 ;; a PARLLEL.
1376 (define_predicate "restore_world_operation"
1377   (match_code "parallel")
1379   int index;
1380   int i;
1381   rtx elt;
1382   int count = XVECLEN (op, 0);
1384   if (count != 59)
1385     return 0;
1387   index = 0;
1388   if (GET_CODE (XVECEXP (op, 0, index++)) != RETURN
1389       || GET_CODE (XVECEXP (op, 0, index++)) != USE
1390       || GET_CODE (XVECEXP (op, 0, index++)) != USE
1391       || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
1392     return 0;
1394   elt = XVECEXP (op, 0, index++);
1395   if (GET_CODE (elt) != SET
1396       || GET_CODE (SET_SRC (elt)) != MEM
1397       || ! memory_operand (SET_SRC (elt), Pmode)
1398       || GET_CODE (SET_DEST (elt)) != REG
1399       || REGNO (SET_DEST (elt)) != CR2_REGNO
1400       || GET_MODE (SET_DEST (elt)) != Pmode)
1401     return 0;
1403   for (i=1; i <= 19; i++)
1404     {
1405       elt = XVECEXP (op, 0, index++);
1406       if (GET_CODE (elt) != SET
1407           || GET_CODE (SET_SRC (elt)) != MEM
1408           || ! memory_operand (SET_SRC (elt), Pmode)
1409           || GET_CODE (SET_DEST (elt)) != REG
1410           || GET_MODE (SET_DEST (elt)) != Pmode)
1411         return 0;
1412     }
1414   for (i=1; i <= 12; i++)
1415     {
1416       elt = XVECEXP (op, 0, index++);
1417       if (GET_CODE (elt) != SET
1418           || GET_CODE (SET_SRC (elt)) != MEM
1419           || GET_CODE (SET_DEST (elt)) != REG
1420           || GET_MODE (SET_DEST (elt)) != V4SImode)
1421         return 0;
1422     }
1424   for (i=1; i <= 18; i++)
1425     {
1426       elt = XVECEXP (op, 0, index++);
1427       if (GET_CODE (elt) != SET
1428           || GET_CODE (SET_SRC (elt)) != MEM
1429           || ! memory_operand (SET_SRC (elt), DFmode)
1430           || GET_CODE (SET_DEST (elt)) != REG
1431           || GET_MODE (SET_DEST (elt)) != DFmode)
1432         return 0;
1433     }
1435   if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1436       || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1437       || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1438       || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1439       || GET_CODE (XVECEXP (op, 0, index++)) != USE)
1440     return 0;
1441   return 1;
1444 ;; Return 1 if OP is valid for a vrsave call, known to be a PARALLEL.
1445 (define_predicate "vrsave_operation"
1446   (match_code "parallel")
1448   int count = XVECLEN (op, 0);
1449   unsigned int dest_regno, src_regno;
1450   int i;
1452   if (count <= 1
1453       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1454       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
1455       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE
1456       || XINT (SET_SRC (XVECEXP (op, 0, 0)), 1) != UNSPECV_SET_VRSAVE)
1457     return 0;
1459   dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1460   src_regno  = REGNO (XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 1));
1462   if (dest_regno != VRSAVE_REGNO || src_regno != VRSAVE_REGNO)
1463     return 0;
1465   for (i = 1; i < count; i++)
1466     {
1467       rtx elt = XVECEXP (op, 0, i);
1469       if (GET_CODE (elt) != CLOBBER
1470           && GET_CODE (elt) != SET)
1471         return 0;
1472     }
1474   return 1;
1477 ;; Return 1 if OP is valid for mfcr insn, known to be a PARALLEL.
1478 (define_predicate "mfcr_operation"
1479   (match_code "parallel")
1481   int count = XVECLEN (op, 0);
1482   int i;
1484   /* Perform a quick check so we don't blow up below.  */
1485   if (count < 1
1486       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1487       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
1488       || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
1489     return 0;
1491   for (i = 0; i < count; i++)
1492     {
1493       rtx exp = XVECEXP (op, 0, i);
1494       rtx unspec;
1495       int maskval;
1496       rtx src_reg;
1498       src_reg = XVECEXP (SET_SRC (exp), 0, 0);
1500       if (GET_CODE (src_reg) != REG
1501           || GET_MODE (src_reg) != CCmode
1502           || ! CR_REGNO_P (REGNO (src_reg)))
1503         return 0;
1505       if (GET_CODE (exp) != SET
1506           || GET_CODE (SET_DEST (exp)) != REG
1507           || GET_MODE (SET_DEST (exp)) != SImode
1508           || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
1509         return 0;
1510       unspec = SET_SRC (exp);
1511       maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
1513       if (GET_CODE (unspec) != UNSPEC
1514           || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
1515           || XVECLEN (unspec, 0) != 2
1516           || XVECEXP (unspec, 0, 0) != src_reg
1517           || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
1518           || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
1519         return 0;
1520     }
1521   return 1;
1524 ;; Return 1 if OP is valid for mtcrf insn, known to be a PARALLEL.
1525 (define_predicate "mtcrf_operation"
1526   (match_code "parallel")
1528   int count = XVECLEN (op, 0);
1529   int i;
1530   rtx src_reg;
1532   /* Perform a quick check so we don't blow up below.  */
1533   if (count < 1
1534       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1535       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
1536       || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
1537     return 0;
1538   src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
1540   if (GET_CODE (src_reg) != REG
1541       || GET_MODE (src_reg) != SImode
1542       || ! INT_REGNO_P (REGNO (src_reg)))
1543     return 0;
1545   for (i = 0; i < count; i++)
1546     {
1547       rtx exp = XVECEXP (op, 0, i);
1548       rtx unspec;
1549       int maskval;
1551       if (GET_CODE (exp) != SET
1552           || GET_CODE (SET_DEST (exp)) != REG
1553           || GET_MODE (SET_DEST (exp)) != CCmode
1554           || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
1555         return 0;
1556       unspec = SET_SRC (exp);
1557       maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
1559       if (GET_CODE (unspec) != UNSPEC
1560           || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
1561           || XVECLEN (unspec, 0) != 2
1562           || XVECEXP (unspec, 0, 0) != src_reg
1563           || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
1564           || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
1565         return 0;
1566     }
1567   return 1;
1570 ;; Return 1 if OP is valid for crsave insn, known to be a PARALLEL.
1571 (define_predicate "crsave_operation"
1572   (match_code "parallel")
1574   int count = XVECLEN (op, 0);
1575   int i;
1577   for (i = 1; i < count; i++)
1578     {
1579       rtx exp = XVECEXP (op, 0, i);
1581       if (GET_CODE (exp) != USE
1582           || GET_CODE (XEXP (exp, 0)) != REG
1583           || GET_MODE (XEXP (exp, 0)) != CCmode
1584           || ! CR_REGNO_P (REGNO (XEXP (exp, 0))))
1585         return 0;
1586     }
1587   return 1;
1590 ;; Return 1 if OP is valid for lmw insn, known to be a PARALLEL.
1591 (define_predicate "lmw_operation"
1592   (match_code "parallel")
1594   int count = XVECLEN (op, 0);
1595   unsigned int dest_regno;
1596   rtx src_addr;
1597   unsigned int base_regno;
1598   HOST_WIDE_INT offset;
1599   int i;
1601   /* Perform a quick check so we don't blow up below.  */
1602   if (count <= 1
1603       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1604       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
1605       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
1606     return 0;
1608   dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1609   src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
1611   if (dest_regno > 31
1612       || count != 32 - (int) dest_regno)
1613     return 0;
1615   if (legitimate_indirect_address_p (src_addr, 0))
1616     {
1617       offset = 0;
1618       base_regno = REGNO (src_addr);
1619       if (base_regno == 0)
1620         return 0;
1621     }
1622   else if (rs6000_legitimate_offset_address_p (SImode, src_addr, false, false))
1623     {
1624       offset = INTVAL (XEXP (src_addr, 1));
1625       base_regno = REGNO (XEXP (src_addr, 0));
1626     }
1627   else
1628     return 0;
1630   for (i = 0; i < count; i++)
1631     {
1632       rtx elt = XVECEXP (op, 0, i);
1633       rtx newaddr;
1634       rtx addr_reg;
1635       HOST_WIDE_INT newoffset;
1637       if (GET_CODE (elt) != SET
1638           || GET_CODE (SET_DEST (elt)) != REG
1639           || GET_MODE (SET_DEST (elt)) != SImode
1640           || REGNO (SET_DEST (elt)) != dest_regno + i
1641           || GET_CODE (SET_SRC (elt)) != MEM
1642           || GET_MODE (SET_SRC (elt)) != SImode)
1643         return 0;
1644       newaddr = XEXP (SET_SRC (elt), 0);
1645       if (legitimate_indirect_address_p (newaddr, 0))
1646         {
1647           newoffset = 0;
1648           addr_reg = newaddr;
1649         }
1650       else if (rs6000_legitimate_offset_address_p (SImode, newaddr, false, false))
1651         {
1652           addr_reg = XEXP (newaddr, 0);
1653           newoffset = INTVAL (XEXP (newaddr, 1));
1654         }
1655       else
1656         return 0;
1657       if (REGNO (addr_reg) != base_regno
1658           || newoffset != offset + 4 * i)
1659         return 0;
1660     }
1662   return 1;
1665 ;; Return 1 if OP is valid for stmw insn, known to be a PARALLEL.
1666 (define_predicate "stmw_operation"
1667   (match_code "parallel")
1669   int count = XVECLEN (op, 0);
1670   unsigned int src_regno;
1671   rtx dest_addr;
1672   unsigned int base_regno;
1673   HOST_WIDE_INT offset;
1674   int i;
1676   /* Perform a quick check so we don't blow up below.  */
1677   if (count <= 1
1678       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1679       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
1680       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
1681     return 0;
1683   src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
1684   dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
1686   if (src_regno > 31
1687       || count != 32 - (int) src_regno)
1688     return 0;
1690   if (legitimate_indirect_address_p (dest_addr, 0))
1691     {
1692       offset = 0;
1693       base_regno = REGNO (dest_addr);
1694       if (base_regno == 0)
1695         return 0;
1696     }
1697   else if (rs6000_legitimate_offset_address_p (SImode, dest_addr, false, false))
1698     {
1699       offset = INTVAL (XEXP (dest_addr, 1));
1700       base_regno = REGNO (XEXP (dest_addr, 0));
1701     }
1702   else
1703     return 0;
1705   for (i = 0; i < count; i++)
1706     {
1707       rtx elt = XVECEXP (op, 0, i);
1708       rtx newaddr;
1709       rtx addr_reg;
1710       HOST_WIDE_INT newoffset;
1712       if (GET_CODE (elt) != SET
1713           || GET_CODE (SET_SRC (elt)) != REG
1714           || GET_MODE (SET_SRC (elt)) != SImode
1715           || REGNO (SET_SRC (elt)) != src_regno + i
1716           || GET_CODE (SET_DEST (elt)) != MEM
1717           || GET_MODE (SET_DEST (elt)) != SImode)
1718         return 0;
1719       newaddr = XEXP (SET_DEST (elt), 0);
1720       if (legitimate_indirect_address_p (newaddr, 0))
1721         {
1722           newoffset = 0;
1723           addr_reg = newaddr;
1724         }
1725       else if (rs6000_legitimate_offset_address_p (SImode, newaddr, false, false))
1726         {
1727           addr_reg = XEXP (newaddr, 0);
1728           newoffset = INTVAL (XEXP (newaddr, 1));
1729         }
1730       else
1731         return 0;
1732       if (REGNO (addr_reg) != base_regno
1733           || newoffset != offset + 4 * i)
1734         return 0;
1735     }
1737   return 1;
1740 ;; Return 1 if OP is a stack tie operand.
1741 (define_predicate "tie_operand"
1742   (match_code "parallel")
1744   return (GET_CODE (XVECEXP (op, 0, 0)) == SET
1745           && GET_CODE (XEXP (XVECEXP (op, 0, 0), 0)) == MEM
1746           && GET_MODE (XEXP (XVECEXP (op, 0, 0), 0)) == BLKmode
1747           && XEXP (XVECEXP (op, 0, 0), 1) == const0_rtx);
1750 ;; Match a small code model toc reference (or medium and large
1751 ;; model toc references before reload).
1752 (define_predicate "small_toc_ref"
1753   (match_code "unspec,plus")
1755   if (GET_CODE (op) == PLUS && add_cint_operand (XEXP (op, 1), mode))
1756     op = XEXP (op, 0);
1758   return GET_CODE (op) == UNSPEC && XINT (op, 1) == UNSPEC_TOCREL;
1761 ;; Match the first insn (addis) in fusing the combination of addis and loads to
1762 ;; GPR registers on power8.
1763 (define_predicate "fusion_gpr_addis"
1764   (match_code "const_int,high,plus")
1766   HOST_WIDE_INT value;
1767   rtx int_const;
1769   if (GET_CODE (op) == HIGH)
1770     return 1;
1772   if (CONST_INT_P (op))
1773     int_const = op;
1775   else if (GET_CODE (op) == PLUS
1776            && base_reg_operand (XEXP (op, 0), Pmode)
1777            && CONST_INT_P (XEXP (op, 1)))
1778     int_const = XEXP (op, 1);
1780   else
1781     return 0;
1783   /* Power8 currently will only do the fusion if the top 11 bits of the addis
1784      value are all 1's or 0's.  */
1785   value = INTVAL (int_const);
1786   if ((value & (HOST_WIDE_INT)0xffff) != 0)
1787     return 0;
1789   if ((value & (HOST_WIDE_INT)0xffff0000) == 0)
1790     return 0;
1792   return (IN_RANGE (value >> 16, -32, 31));
1795 ;; Match the second insn (lbz, lhz, lwz, ld) in fusing the combination of addis
1796 ;; and loads to GPR registers on power8.
1797 (define_predicate "fusion_gpr_mem_load"
1798   (match_code "mem,sign_extend,zero_extend")
1800   rtx addr, base, offset;
1802   /* Handle sign/zero extend.  */
1803   if (GET_CODE (op) == ZERO_EXTEND
1804       || (TARGET_P8_FUSION_SIGN && GET_CODE (op) == SIGN_EXTEND))
1805     {
1806       op = XEXP (op, 0);
1807       mode = GET_MODE (op);
1808     }
1810   if (!MEM_P (op))
1811     return 0;
1813   switch (mode)
1814     {
1815     case QImode:
1816     case HImode:
1817     case SImode:
1818       break;
1820     case DImode:
1821       if (!TARGET_POWERPC64)
1822         return 0;
1823       break;
1825     default:
1826       return 0;
1827     }
1829   addr = XEXP (op, 0);
1830   if (GET_CODE (addr) != PLUS && GET_CODE (addr) != LO_SUM)
1831     return 0;
1833   base = XEXP (addr, 0);
1834   if (!base_reg_operand (base, GET_MODE (base)))
1835     return 0;
1837   offset = XEXP (addr, 1);
1839   if (GET_CODE (addr) == PLUS)
1840     return satisfies_constraint_I (offset);
1842   else if (GET_CODE (addr) == LO_SUM)
1843     {
1844       if (TARGET_XCOFF || (TARGET_ELF && TARGET_POWERPC64))
1845         return small_toc_ref (offset, GET_MODE (offset));
1847       else if (TARGET_ELF && !TARGET_POWERPC64)
1848         return CONSTANT_P (offset);
1849     }
1851   return 0;
1854 ;; Match a GPR load (lbz, lhz, lwz, ld) that uses a combined address in the
1855 ;; memory field with both the addis and the memory offset.  Sign extension
1856 ;; is not handled here, since lha and lwa are not fused.
1857 (define_predicate "fusion_gpr_mem_combo"
1858   (match_code "mem,zero_extend")
1860   rtx addr, base, offset;
1862   /* Handle zero extend.  */
1863   if (GET_CODE (op) == ZERO_EXTEND)
1864     {
1865       op = XEXP (op, 0);
1866       mode = GET_MODE (op);
1867     }
1869   if (!MEM_P (op))
1870     return 0;
1872   switch (mode)
1873     {
1874     case QImode:
1875     case HImode:
1876     case SImode:
1877       break;
1879     case DImode:
1880       if (!TARGET_POWERPC64)
1881         return 0;
1882       break;
1884     default:
1885       return 0;
1886     }
1888   addr = XEXP (op, 0);
1889   if (GET_CODE (addr) != PLUS && GET_CODE (addr) != LO_SUM)
1890     return 0;
1892   base = XEXP (addr, 0);
1893   if (!fusion_gpr_addis (base, GET_MODE (base)))
1894     return 0;
1896   offset = XEXP (addr, 1);
1897   if (GET_CODE (addr) == PLUS)
1898     return satisfies_constraint_I (offset);
1900   else if (GET_CODE (addr) == LO_SUM)
1901     {
1902       if (TARGET_XCOFF || (TARGET_ELF && TARGET_POWERPC64))
1903         return small_toc_ref (offset, GET_MODE (offset));
1905       else if (TARGET_ELF && !TARGET_POWERPC64)
1906         return CONSTANT_P (offset);
1907     }
1909   return 0;