* varasm.c (bss_initializer_p): Remove static.
[official-gcc.git] / gcc / config / rs6000 / predicates.md
blobfc20a5e5761520abb9da4a3ac620588fd03c0e78
1 ;; Predicate definitions for POWER and PowerPC.
2 ;; Copyright (C) 2005-2012 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,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 5-bit constant integer.
128 (define_predicate "u5bit_cint_operand"
129   (and (match_code "const_int")
130        (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 31")))
132 ;; Return 1 if op is a signed 8-bit constant integer.
133 ;; Integer multiplication complete more quickly
134 (define_predicate "s8bit_cint_operand"
135   (and (match_code "const_int")
136        (match_test "INTVAL (op) >= -128 && INTVAL (op) <= 127")))
138 ;; Return 1 if op is a constant integer that can fit in a D field.
139 (define_predicate "short_cint_operand"
140   (and (match_code "const_int")
141        (match_test "satisfies_constraint_I (op)")))
143 ;; Return 1 if op is a constant integer that can fit in an unsigned D field.
144 (define_predicate "u_short_cint_operand"
145   (and (match_code "const_int")
146        (match_test "satisfies_constraint_K (op)")))
148 ;; Return 1 if op is a constant integer that cannot fit in a signed D field.
149 (define_predicate "non_short_cint_operand"
150   (and (match_code "const_int")
151        (match_test "(unsigned HOST_WIDE_INT)
152                     (INTVAL (op) + 0x8000) >= 0x10000")))
154 ;; Return 1 if op is a positive constant integer that is an exact power of 2.
155 (define_predicate "exact_log2_cint_operand"
156   (and (match_code "const_int")
157        (match_test "INTVAL (op) > 0 && exact_log2 (INTVAL (op)) >= 0")))
159 ;; Match op = 0 or op = 1.
160 (define_predicate "const_0_to_1_operand"
161   (and (match_code "const_int")
162        (match_test "IN_RANGE (INTVAL (op), 0, 1)")))
164 ;; Match op = 2 or op = 3.
165 (define_predicate "const_2_to_3_operand"
166   (and (match_code "const_int")
167        (match_test "IN_RANGE (INTVAL (op), 2, 3)")))
169 ;; Return 1 if op is a register that is not special.
170 (define_predicate "gpc_reg_operand"
171   (match_operand 0 "register_operand")
173   if ((TARGET_E500_DOUBLE || TARGET_SPE) && invalid_e500_subreg (op, mode))
174     return 0;
176   if (GET_CODE (op) == SUBREG)
177     op = SUBREG_REG (op);
179   if (!REG_P (op))
180     return 0;
182   if (REGNO (op) >= ARG_POINTER_REGNUM && !CA_REGNO_P (REGNO (op)))
183     return 1;
185   return INT_REGNO_P (REGNO (op)) || FP_REGNO_P (REGNO (op));
188 ;; Return 1 if op is a register that is a condition register field.
189 (define_predicate "cc_reg_operand"
190   (match_operand 0 "register_operand")
192   if (GET_CODE (op) == SUBREG)
193     op = SUBREG_REG (op);
195   if (!REG_P (op))
196     return 0;
198   if (REGNO (op) > LAST_VIRTUAL_REGISTER)
199     return 1;
201   return CR_REGNO_P (REGNO (op));
204 ;; Return 1 if op is a register that is a condition register field not cr0.
205 (define_predicate "cc_reg_not_cr0_operand"
206   (match_operand 0 "register_operand")
208   if (GET_CODE (op) == SUBREG)
209     op = SUBREG_REG (op);
211   if (!REG_P (op))
212     return 0;
214   if (REGNO (op) > LAST_VIRTUAL_REGISTER)
215     return 1;
217   return CR_REGNO_NOT_CR0_P (REGNO (op));
220 ;; Return 1 if op is a register that is a condition register field and if generating microcode, not cr0.
221 (define_predicate "cc_reg_not_micro_cr0_operand"
222   (match_operand 0 "register_operand")
224   if (GET_CODE (op) == SUBREG)
225     op = SUBREG_REG (op);
227   if (!REG_P (op))
228     return 0;
230   if (REGNO (op) > LAST_VIRTUAL_REGISTER)
231     return 1;
233   if (rs6000_gen_cell_microcode)
234     return CR_REGNO_NOT_CR0_P (REGNO (op));
235   else
236     return CR_REGNO_P (REGNO (op));
239 ;; Return 1 if op is a constant integer valid for D field
240 ;; or non-special register register.
241 (define_predicate "reg_or_short_operand"
242   (if_then_else (match_code "const_int")
243     (match_operand 0 "short_cint_operand")
244     (match_operand 0 "gpc_reg_operand")))
246 ;; Return 1 if op is a constant integer valid whose negation is valid for
247 ;; D field or non-special register register.
248 ;; Do not allow a constant zero because all patterns that call this
249 ;; predicate use "addic r1,r2,-const" to set carry when r2 is greater than
250 ;; or equal to const, which does not work for zero.
251 (define_predicate "reg_or_neg_short_operand"
252   (if_then_else (match_code "const_int")
253     (match_test "satisfies_constraint_P (op)
254                  && INTVAL (op) != 0")
255     (match_operand 0 "gpc_reg_operand")))
257 ;; Return 1 if op is a constant integer valid for DS field
258 ;; or non-special register.
259 (define_predicate "reg_or_aligned_short_operand"
260   (if_then_else (match_code "const_int")
261     (and (match_operand 0 "short_cint_operand")
262          (match_test "!(INTVAL (op) & 3)"))
263     (match_operand 0 "gpc_reg_operand")))
265 ;; Return 1 if op is a constant integer whose high-order 16 bits are zero
266 ;; or non-special register.
267 (define_predicate "reg_or_u_short_operand"
268   (if_then_else (match_code "const_int")
269     (match_operand 0 "u_short_cint_operand")
270     (match_operand 0 "gpc_reg_operand")))
272 ;; Return 1 if op is any constant integer 
273 ;; or non-special register.
274 (define_predicate "reg_or_cint_operand"
275   (ior (match_code "const_int")
276        (match_operand 0 "gpc_reg_operand")))
278 ;; Return 1 if op is a constant integer valid for addition
279 ;; or non-special register.
280 (define_predicate "reg_or_add_cint_operand"
281   (if_then_else (match_code "const_int")
282     (match_test "(HOST_BITS_PER_WIDE_INT == 32
283                   && (mode == SImode || INTVAL (op) < 0x7fff8000))
284                  || ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
285                      < (unsigned HOST_WIDE_INT) 0x100000000ll)")
286     (match_operand 0 "gpc_reg_operand")))
288 ;; Return 1 if op is a constant integer valid for subtraction
289 ;; or non-special register.
290 (define_predicate "reg_or_sub_cint_operand"
291   (if_then_else (match_code "const_int")
292     (match_test "(HOST_BITS_PER_WIDE_INT == 32
293                   && (mode == SImode || - INTVAL (op) < 0x7fff8000))
294                  || ((unsigned HOST_WIDE_INT) (- INTVAL (op) 
295                                                + (mode == SImode
296                                                   ? 0x80000000 : 0x80008000))
297                      < (unsigned HOST_WIDE_INT) 0x100000000ll)")
298     (match_operand 0 "gpc_reg_operand")))
300 ;; Return 1 if op is any 32-bit unsigned constant integer
301 ;; or non-special register.
302 (define_predicate "reg_or_logical_cint_operand"
303   (if_then_else (match_code "const_int")
304     (match_test "(GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT
305                   && INTVAL (op) >= 0)
306                  || ((INTVAL (op) & GET_MODE_MASK (mode)
307                       & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0)")
308     (if_then_else (match_code "const_double")
309       (match_test "GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT
310                    && mode == DImode
311                    && CONST_DOUBLE_HIGH (op) == 0")
312       (match_operand 0 "gpc_reg_operand"))))
314 ;; Return 1 if operand is a CONST_DOUBLE that can be set in a register
315 ;; with no more than one instruction per word.
316 (define_predicate "easy_fp_constant"
317   (match_code "const_double")
319   long k[4];
320   REAL_VALUE_TYPE rv;
322   if (GET_MODE (op) != mode
323       || (!SCALAR_FLOAT_MODE_P (mode) && mode != DImode))
324     return 0;
326   /* Consider all constants with -msoft-float to be easy.  */
327   if ((TARGET_SOFT_FLOAT || TARGET_E500_SINGLE 
328       || (TARGET_HARD_FLOAT && (TARGET_SINGLE_FLOAT && ! TARGET_DOUBLE_FLOAT)))
329       && mode != DImode)
330     return 1;
332   if (DECIMAL_FLOAT_MODE_P (mode))
333     return 0;
335   /* If we are using V.4 style PIC, consider all constants to be hard.  */
336   if (flag_pic && DEFAULT_ABI == ABI_V4)
337     return 0;
339 #ifdef TARGET_RELOCATABLE
340   /* Similarly if we are using -mrelocatable, consider all constants
341      to be hard.  */
342   if (TARGET_RELOCATABLE)
343     return 0;
344 #endif
346   switch (mode)
347     {
348     case TFmode:
349       if (TARGET_E500_DOUBLE)
350         return 0;
352       REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
353       REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
355       return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
356               && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1
357               && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1
358               && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1);
360     case DFmode:
361       /* The constant 0.f is easy under VSX.  */
362       if (op == CONST0_RTX (DFmode) && VECTOR_UNIT_VSX_P (DFmode))
363         return 1;
365       /* Force constants to memory before reload to utilize
366          compress_float_constant.
367          Avoid this when flag_unsafe_math_optimizations is enabled
368          because RDIV division to reciprocal optimization is not able
369          to regenerate the division.  */
370       if (TARGET_E500_DOUBLE
371           || (!reload_in_progress && !reload_completed
372               && !flag_unsafe_math_optimizations))
373         return 0;
375       REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
376       REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
378       return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
379               && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
381     case SFmode:
382       /* The constant 0.f is easy.  */
383       if (op == CONST0_RTX (SFmode))
384         return 1;
386       /* Force constants to memory before reload to utilize
387          compress_float_constant.
388          Avoid this when flag_unsafe_math_optimizations is enabled
389          because RDIV division to reciprocal optimization is not able
390          to regenerate the division.  */
391       if (!reload_in_progress && !reload_completed
392           && !flag_unsafe_math_optimizations)
393         return 0;
395       REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
396       REAL_VALUE_TO_TARGET_SINGLE (rv, k[0]);
398       return num_insns_constant_wide (k[0]) == 1;
400   case DImode:
401     return ((TARGET_POWERPC64
402              && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
403             || (num_insns_constant (op, DImode) <= 2));
405   case SImode:
406     return 1;
408   default:
409     gcc_unreachable ();
410   }
413 ;; Return 1 if the operand is a CONST_VECTOR and can be loaded into a
414 ;; vector register without using memory.
415 (define_predicate "easy_vector_constant"
416   (match_code "const_vector")
418   /* As the paired vectors are actually FPRs it seems that there is
419      no easy way to load a CONST_VECTOR without using memory.  */
420   if (TARGET_PAIRED_FLOAT)
421     return false;
423   if (VECTOR_MEM_ALTIVEC_OR_VSX_P (mode))
424     {
425       if (zero_constant (op, mode))
426         return true;
428       return easy_altivec_constant (op, mode);
429     }
431   if (SPE_VECTOR_MODE (mode))
432     {
433       int cst, cst2;
434       if (zero_constant (op, mode))
435         return true;
436       if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
437         return false;
439       /* Limit SPE vectors to 15 bits signed.  These we can generate with:
440            li r0, CONSTANT1
441            evmergelo r0, r0, r0
442            li r0, CONSTANT2
444          I don't know how efficient it would be to allow bigger constants,
445          considering we'll have an extra 'ori' for every 'li'.  I doubt 5
446          instructions is better than a 64-bit memory load, but I don't
447          have the e500 timing specs.  */
448       if (mode == V2SImode)
449         {
450           cst  = INTVAL (CONST_VECTOR_ELT (op, 0));
451           cst2 = INTVAL (CONST_VECTOR_ELT (op, 1));
452           return cst  >= -0x7fff && cst <= 0x7fff
453                  && cst2 >= -0x7fff && cst2 <= 0x7fff;
454         }
455     }
457   return false;
460 ;; Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF.
461 (define_predicate "easy_vector_constant_add_self"
462   (and (match_code "const_vector")
463        (and (match_test "TARGET_ALTIVEC")
464             (match_test "easy_altivec_constant (op, mode)")))
466   HOST_WIDE_INT val;
467   if (mode == V2DImode || mode == V2DFmode)
468     return 0;
469   val = const_vector_elt_as_int (op, GET_MODE_NUNITS (mode) - 1);
470   val = ((val & 0xff) ^ 0x80) - 0x80;
471   return EASY_VECTOR_15_ADD_SELF (val);
474 ;; Same as easy_vector_constant but only for EASY_VECTOR_MSB.
475 (define_predicate "easy_vector_constant_msb"
476   (and (match_code "const_vector")
477        (and (match_test "TARGET_ALTIVEC")
478             (match_test "easy_altivec_constant (op, mode)")))
480   HOST_WIDE_INT val;
481   if (mode == V2DImode || mode == V2DFmode)
482     return 0;
483   val = const_vector_elt_as_int (op, GET_MODE_NUNITS (mode) - 1);
484   return EASY_VECTOR_MSB (val, GET_MODE_INNER (mode));
487 ;; Return 1 if operand is constant zero (scalars and vectors).
488 (define_predicate "zero_constant"
489   (and (match_code "const_int,const_double,const_vector")
490        (match_test "op == CONST0_RTX (mode)")))
492 ;; Return 1 if operand is 0.0.
493 (define_predicate "zero_fp_constant"
494   (and (match_code "const_double")
495        (match_test "SCALAR_FLOAT_MODE_P (mode)
496                     && op == CONST0_RTX (mode)")))
498 ;; Return 1 if the operand is in volatile memory.  Note that during the
499 ;; RTL generation phase, memory_operand does not return TRUE for volatile
500 ;; memory references.  So this function allows us to recognize volatile
501 ;; references where it's safe.
502 (define_predicate "volatile_mem_operand"
503   (and (and (match_code "mem")
504             (match_test "MEM_VOLATILE_P (op)"))
505        (if_then_else (match_test "reload_completed")
506          (match_operand 0 "memory_operand")
507          (if_then_else (match_test "reload_in_progress")
508            (match_test "strict_memory_address_p (mode, XEXP (op, 0))")
509            (match_test "memory_address_p (mode, XEXP (op, 0))")))))
511 ;; Return 1 if the operand is an offsettable memory operand.
512 (define_predicate "offsettable_mem_operand"
513   (and (match_operand 0 "memory_operand")
514        (match_test "offsettable_nonstrict_memref_p (op)")))
516 ;; Return 1 if the operand is an indexed or indirect memory operand.
517 (define_predicate "indexed_or_indirect_operand"
518   (match_code "mem")
520   op = XEXP (op, 0);
521   if (VECTOR_MEM_ALTIVEC_P (mode)
522       && GET_CODE (op) == AND
523       && GET_CODE (XEXP (op, 1)) == CONST_INT
524       && INTVAL (XEXP (op, 1)) == -16)
525     op = XEXP (op, 0);
527   return indexed_or_indirect_address (op, mode);
530 ;; Return 1 if the operand is an indexed or indirect memory operand with an
531 ;; AND -16 in it, used to recognize when we need to switch to Altivec loads
532 ;; to realign loops instead of VSX (altivec silently ignores the bottom bits,
533 ;; while VSX uses the full address and traps)
534 (define_predicate "altivec_indexed_or_indirect_operand"
535   (match_code "mem")
537   op = XEXP (op, 0);
538   if (VECTOR_MEM_ALTIVEC_OR_VSX_P (mode)
539       && GET_CODE (op) == AND
540       && GET_CODE (XEXP (op, 1)) == CONST_INT
541       && INTVAL (XEXP (op, 1)) == -16)
542     return indexed_or_indirect_address (XEXP (op, 0), mode);
544   return 0;
547 ;; Return 1 if the operand is an indexed or indirect address.
548 (define_special_predicate "indexed_or_indirect_address"
549   (and (match_test "REG_P (op)
550                     || (GET_CODE (op) == PLUS
551                         /* Omit testing REG_P (XEXP (op, 0)).  */
552                         && REG_P (XEXP (op, 1)))")
553        (match_operand 0 "address_operand")))
555 ;; Used for the destination of the fix_truncdfsi2 expander.
556 ;; If stfiwx will be used, the result goes to memory; otherwise,
557 ;; we're going to emit a store and a load of a subreg, so the dest is a
558 ;; register.
559 (define_predicate "fix_trunc_dest_operand"
560   (if_then_else (match_test "! TARGET_E500_DOUBLE && TARGET_PPC_GFXOPT")
561    (match_operand 0 "memory_operand")
562    (match_operand 0 "gpc_reg_operand")))
564 ;; Return 1 if the operand is either a non-special register or can be used
565 ;; as the operand of a `mode' add insn.
566 (define_predicate "add_operand"
567   (if_then_else (match_code "const_int")
568     (match_test "satisfies_constraint_I (op)
569                  || satisfies_constraint_L (op)")
570     (match_operand 0 "gpc_reg_operand")))
572 ;; Return 1 if OP is a constant but not a valid add_operand.
573 (define_predicate "non_add_cint_operand"
574   (and (match_code "const_int")
575        (match_test "!satisfies_constraint_I (op)
576                     && !satisfies_constraint_L (op)")))
578 ;; Return 1 if the operand is a constant that can be used as the operand
579 ;; of an OR or XOR.
580 (define_predicate "logical_const_operand"
581   (match_code "const_int,const_double")
583   HOST_WIDE_INT opl, oph;
585   if (GET_CODE (op) == CONST_INT)
586     {
587       opl = INTVAL (op) & GET_MODE_MASK (mode);
589       if (HOST_BITS_PER_WIDE_INT <= 32
590           && GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
591         return 0;
592     }
593   else if (GET_CODE (op) == CONST_DOUBLE)
594     {
595       gcc_assert (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT);
597       opl = CONST_DOUBLE_LOW (op);
598       oph = CONST_DOUBLE_HIGH (op);
599       if (oph != 0)
600         return 0;
601     }
602   else
603     return 0;
605   return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
606           || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
609 ;; Return 1 if the operand is a non-special register or a constant that
610 ;; can be used as the operand of an OR or XOR.
611 (define_predicate "logical_operand"
612   (ior (match_operand 0 "gpc_reg_operand")
613        (match_operand 0 "logical_const_operand")))
615 ;; Return 1 if op is a constant that is not a logical operand, but could
616 ;; be split into one.
617 (define_predicate "non_logical_cint_operand"
618   (and (match_code "const_int,const_double")
619        (and (not (match_operand 0 "logical_operand"))
620             (match_operand 0 "reg_or_logical_cint_operand"))))
622 ;; Return 1 if op is a constant that can be encoded in a 32-bit mask,
623 ;; suitable for use with rlwinm (no more than two 1->0 or 0->1
624 ;; transitions).  Reject all ones and all zeros, since these should have
625 ;; been optimized away and confuse the making of MB and ME.
626 (define_predicate "mask_operand"
627   (match_code "const_int")
629   HOST_WIDE_INT c, lsb;
631   c = INTVAL (op);
633   if (TARGET_POWERPC64)
634     {
635       /* Fail if the mask is not 32-bit.  */
636       if (mode == DImode && (c & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0)
637         return 0;
639       /* Fail if the mask wraps around because the upper 32-bits of the
640          mask will all be 1s, contrary to GCC's internal view.  */
641       if ((c & 0x80000001) == 0x80000001)
642         return 0;
643     }
645   /* We don't change the number of transitions by inverting,
646      so make sure we start with the LS bit zero.  */
647   if (c & 1)
648     c = ~c;
650   /* Reject all zeros or all ones.  */
651   if (c == 0)
652     return 0;
654   /* Find the first transition.  */
655   lsb = c & -c;
657   /* Invert to look for a second transition.  */
658   c = ~c;
660   /* Erase first transition.  */
661   c &= -lsb;
663   /* Find the second transition (if any).  */
664   lsb = c & -c;
666   /* Match if all the bits above are 1's (or c is zero).  */
667   return c == -lsb;
670 ;; Return 1 for the PowerPC64 rlwinm corner case.
671 (define_predicate "mask_operand_wrap"
672   (match_code "const_int")
674   HOST_WIDE_INT c, lsb;
676   c = INTVAL (op);
678   if ((c & 0x80000001) != 0x80000001)
679     return 0;
681   c = ~c;
682   if (c == 0)
683     return 0;
685   lsb = c & -c;
686   c = ~c;
687   c &= -lsb;
688   lsb = c & -c;
689   return c == -lsb;
692 ;; Return 1 if the operand is a constant that is a PowerPC64 mask
693 ;; suitable for use with rldicl or rldicr (no more than one 1->0 or 0->1
694 ;; transition).  Reject all zeros, since zero should have been
695 ;; optimized away and confuses the making of MB and ME.
696 (define_predicate "mask64_operand"
697   (match_code "const_int")
699   HOST_WIDE_INT c, lsb;
701   c = INTVAL (op);
703   /* Reject all zeros.  */
704   if (c == 0)
705     return 0;
707   /* We don't change the number of transitions by inverting,
708      so make sure we start with the LS bit zero.  */
709   if (c & 1)
710     c = ~c;
712   /* Find the first transition.  */
713   lsb = c & -c;
715   /* Match if all the bits above are 1's (or c is zero).  */
716   return c == -lsb;
719 ;; Like mask64_operand, but allow up to three transitions.  This
720 ;; predicate is used by insn patterns that generate two rldicl or
721 ;; rldicr machine insns.
722 (define_predicate "mask64_2_operand"
723   (match_code "const_int")
725   HOST_WIDE_INT c, lsb;
727   c = INTVAL (op);
729   /* Disallow all zeros.  */
730   if (c == 0)
731     return 0;
733   /* We don't change the number of transitions by inverting,
734      so make sure we start with the LS bit zero.  */
735   if (c & 1)
736     c = ~c;
738   /* Find the first transition.  */
739   lsb = c & -c;
741   /* Invert to look for a second transition.  */
742   c = ~c;
744   /* Erase first transition.  */
745   c &= -lsb;
747   /* Find the second transition.  */
748   lsb = c & -c;
750   /* Invert to look for a third transition.  */
751   c = ~c;
753   /* Erase second transition.  */
754   c &= -lsb;
756   /* Find the third transition (if any).  */
757   lsb = c & -c;
759   /* Match if all the bits above are 1's (or c is zero).  */
760   return c == -lsb;
763 ;; Like and_operand, but also match constants that can be implemented
764 ;; with two rldicl or rldicr insns.
765 (define_predicate "and64_2_operand"
766   (ior (match_operand 0 "mask64_2_operand")
767        (if_then_else (match_test "fixed_regs[CR0_REGNO]")
768          (match_operand 0 "gpc_reg_operand")
769          (match_operand 0 "logical_operand"))))
771 ;; Return 1 if the operand is either a non-special register or a
772 ;; constant that can be used as the operand of a logical AND.
773 (define_predicate "and_operand"
774   (ior (match_operand 0 "mask_operand")
775        (ior (and (match_test "TARGET_POWERPC64 && mode == DImode")
776                  (match_operand 0 "mask64_operand"))
777             (if_then_else (match_test "fixed_regs[CR0_REGNO]")
778               (match_operand 0 "gpc_reg_operand")
779               (match_operand 0 "logical_operand")))))
781 ;; Return 1 if the operand is either a logical operand or a short cint operand.
782 (define_predicate "scc_eq_operand"
783   (ior (match_operand 0 "logical_operand")
784        (match_operand 0 "short_cint_operand")))
786 ;; Return 1 if the operand is a general non-special register or memory operand.
787 (define_predicate "reg_or_mem_operand"
788      (ior (match_operand 0 "memory_operand")
789           (ior (and (match_code "mem")
790                     (match_test "macho_lo_sum_memory_operand (op, mode)"))
791                (ior (match_operand 0 "volatile_mem_operand")
792                     (match_operand 0 "gpc_reg_operand")))))
794 ;; Return 1 if the operand is either an easy FP constant or memory or reg.
795 (define_predicate "reg_or_none500mem_operand"
796   (if_then_else (match_code "mem")
797      (and (match_test "!TARGET_E500_DOUBLE")
798           (ior (match_operand 0 "memory_operand")
799                (ior (match_test "macho_lo_sum_memory_operand (op, mode)")
800                     (match_operand 0 "volatile_mem_operand"))))
801      (match_operand 0 "gpc_reg_operand")))
803 ;; Return 1 if the operand is CONST_DOUBLE 0, register or memory operand.
804 (define_predicate "zero_reg_mem_operand"
805   (ior (match_operand 0 "zero_fp_constant")
806        (match_operand 0 "reg_or_mem_operand")))
808 ;; Return 1 if the operand is a general register or memory operand without
809 ;; pre_inc or pre_dec or pre_modify, which produces invalid form of PowerPC
810 ;; lwa instruction.
811 (define_predicate "lwa_operand"
812   (match_code "reg,subreg,mem")
814   rtx inner, addr, offset;
816   inner = op;
817   if (reload_completed && GET_CODE (inner) == SUBREG)
818     inner = SUBREG_REG (inner);
820   if (gpc_reg_operand (inner, mode))
821     return true;
822   if (!memory_operand (inner, mode))
823     return false;
824   addr = XEXP (inner, 0);
825   if (GET_CODE (addr) == PRE_INC
826       || GET_CODE (addr) == PRE_DEC
827       || (GET_CODE (addr) == PRE_MODIFY
828           && !legitimate_indexed_address_p (XEXP (addr, 1), 0)))
829     return false;
830   if (GET_CODE (addr) == LO_SUM
831       && GET_CODE (XEXP (addr, 0)) == REG
832       && GET_CODE (XEXP (addr, 1)) == CONST)
833     addr = XEXP (XEXP (addr, 1), 0);
834   if (GET_CODE (addr) != PLUS)
835     return true;
836   offset = XEXP (addr, 1);
837   if (GET_CODE (offset) != CONST_INT)
838     return true;
839   return INTVAL (offset) % 4 == 0;
842 ;; Return 1 if the operand, used inside a MEM, is a SYMBOL_REF.
843 (define_predicate "symbol_ref_operand"
844   (and (match_code "symbol_ref")
845        (match_test "(mode == VOIDmode || GET_MODE (op) == mode)
846                     && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))")))
848 ;; Return 1 if op is an operand that can be loaded via the GOT.
849 ;; or non-special register register field no cr0
850 (define_predicate "got_operand"
851   (match_code "symbol_ref,const,label_ref"))
853 ;; Return 1 if op is a simple reference that can be loaded via the GOT,
854 ;; excluding labels involving addition.
855 (define_predicate "got_no_const_operand"
856   (match_code "symbol_ref,label_ref"))
858 ;; Return 1 if op is a SYMBOL_REF for a TLS symbol.
859 (define_predicate "rs6000_tls_symbol_ref"
860   (and (match_code "symbol_ref")
861        (match_test "RS6000_SYMBOL_REF_TLS_P (op)")))
863 ;; Return 1 if the operand, used inside a MEM, is a valid first argument
864 ;; to CALL.  This is a SYMBOL_REF, a pseudo-register, LR or CTR.
865 (define_predicate "call_operand"
866   (if_then_else (match_code "reg")
867      (match_test "REGNO (op) == LR_REGNO
868                   || REGNO (op) == CTR_REGNO
869                   || REGNO (op) >= FIRST_PSEUDO_REGISTER")
870      (match_code "symbol_ref")))
872 ;; Return 1 if the operand is a SYMBOL_REF for a function known to be in
873 ;; this file.
874 (define_predicate "current_file_function_operand"
875   (and (match_code "symbol_ref")
876        (match_test "(DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
877                     && ((SYMBOL_REF_LOCAL_P (op)
878                          && (DEFAULT_ABI != ABI_AIX
879                              || !SYMBOL_REF_EXTERNAL_P (op)))
880                         || (op == XEXP (DECL_RTL (current_function_decl),
881                                                   0)))")))
883 ;; Return 1 if this operand is a valid input for a move insn.
884 (define_predicate "input_operand"
885   (match_code "symbol_ref,const,reg,subreg,mem,
886                const_double,const_vector,const_int")
888   /* Memory is always valid.  */
889   if (memory_operand (op, mode))
890     return 1;
892   /* For floating-point, easy constants are valid.  */
893   if (SCALAR_FLOAT_MODE_P (mode)
894       && easy_fp_constant (op, mode))
895     return 1;
897   /* Allow any integer constant.  */
898   if (GET_MODE_CLASS (mode) == MODE_INT
899       && (GET_CODE (op) == CONST_INT
900           || GET_CODE (op) == CONST_DOUBLE))
901     return 1;
903   /* Allow easy vector constants.  */
904   if (GET_CODE (op) == CONST_VECTOR
905       && easy_vector_constant (op, mode))
906     return 1;
908   /* Do not allow invalid E500 subregs.  */
909   if ((TARGET_E500_DOUBLE || TARGET_SPE)
910       && GET_CODE (op) == SUBREG
911       && invalid_e500_subreg (op, mode))
912     return 0;
914   /* For floating-point or multi-word mode, the only remaining valid type
915      is a register.  */
916   if (SCALAR_FLOAT_MODE_P (mode)
917       || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
918     return register_operand (op, mode);
920   /* The only cases left are integral modes one word or smaller (we
921      do not get called for MODE_CC values).  These can be in any
922      register.  */
923   if (register_operand (op, mode))
924     return 1;
926   /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
927      to be valid.  */
928   if (DEFAULT_ABI == ABI_V4
929       && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
930       && small_data_operand (op, Pmode))
931     return 1;
933   return 0;
936 ;; Return 1 if this operand is a valid input for a vsx_splat insn.
937 (define_predicate "splat_input_operand"
938   (match_code "symbol_ref,const,reg,subreg,mem,
939                const_double,const_vector,const_int")
941   if (MEM_P (op))
942     {
943       if (! volatile_ok && MEM_VOLATILE_P (op))
944         return 0;
945       if (mode == DFmode)
946         mode = V2DFmode;
947       else if (mode == DImode)
948         mode = V2DImode;
949       else
950         gcc_unreachable ();
951       return memory_address_addr_space_p (mode, XEXP (op, 0),
952                                           MEM_ADDR_SPACE (op));
953     }
954   return input_operand (op, mode);
957 ;; Return true if OP is a non-immediate operand and not an invalid
958 ;; SUBREG operation on the e500.
959 (define_predicate "rs6000_nonimmediate_operand"
960   (match_code "reg,subreg,mem")
962   if ((TARGET_E500_DOUBLE || TARGET_SPE)
963       && GET_CODE (op) == SUBREG
964       && invalid_e500_subreg (op, mode))
965     return 0;
967   return nonimmediate_operand (op, mode);
970 ;; Return true if operand is boolean operator.
971 (define_predicate "boolean_operator"
972   (match_code "and,ior,xor"))
974 ;; Return true if operand is OR-form of boolean operator.
975 (define_predicate "boolean_or_operator"
976   (match_code "ior,xor"))
978 ;; Return true if operand is an equality operator.
979 (define_special_predicate "equality_operator"
980   (match_code "eq,ne"))
982 ;; Return true if operand is MIN or MAX operator.
983 (define_predicate "min_max_operator"
984   (match_code "smin,smax,umin,umax"))
986 ;; Return 1 if OP is a comparison operation that is valid for a branch
987 ;; instruction.  We check the opcode against the mode of the CC value.
988 ;; validate_condition_mode is an assertion.
989 (define_predicate "branch_comparison_operator"
990    (and (match_operand 0 "comparison_operator")
991         (and (match_test "GET_MODE_CLASS (GET_MODE (XEXP (op, 0))) == MODE_CC")
992              (match_test "validate_condition_mode (GET_CODE (op),
993                                                    GET_MODE (XEXP (op, 0))),
994                           1"))))
996 (define_predicate "rs6000_cbranch_operator"
997   (if_then_else (match_test "TARGET_HARD_FLOAT && !TARGET_FPRS")
998                 (match_operand 0 "ordered_comparison_operator")
999                 (match_operand 0 "comparison_operator")))
1001 ;; Return 1 if OP is a comparison operation that is valid for an SCC insn --
1002 ;; it must be a positive comparison.
1003 (define_predicate "scc_comparison_operator"
1004   (and (match_operand 0 "branch_comparison_operator")
1005        (match_code "eq,lt,gt,ltu,gtu,unordered")))
1007 ;; Return 1 if OP is a comparison operation whose inverse would be valid for
1008 ;; an SCC insn.
1009 (define_predicate "scc_rev_comparison_operator"
1010   (and (match_operand 0 "branch_comparison_operator")
1011        (match_code "ne,le,ge,leu,geu,ordered")))
1013 ;; Return 1 if OP is a comparison operation that is valid for a branch
1014 ;; insn, which is true if the corresponding bit in the CC register is set.
1015 (define_predicate "branch_positive_comparison_operator"
1016   (and (match_operand 0 "branch_comparison_operator")
1017        (match_code "eq,lt,gt,ltu,gtu,unordered")))
1019 ;; Return 1 if OP is a load multiple operation, known to be a PARALLEL.
1020 (define_predicate "load_multiple_operation"
1021   (match_code "parallel")
1023   int count = XVECLEN (op, 0);
1024   unsigned int dest_regno;
1025   rtx src_addr;
1026   int i;
1028   /* Perform a quick check so we don't blow up below.  */
1029   if (count <= 1
1030       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1031       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
1032       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
1033     return 0;
1035   dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1036   src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
1038   for (i = 1; i < count; i++)
1039     {
1040       rtx elt = XVECEXP (op, 0, i);
1042       if (GET_CODE (elt) != SET
1043           || GET_CODE (SET_DEST (elt)) != REG
1044           || GET_MODE (SET_DEST (elt)) != SImode
1045           || REGNO (SET_DEST (elt)) != dest_regno + i
1046           || GET_CODE (SET_SRC (elt)) != MEM
1047           || GET_MODE (SET_SRC (elt)) != SImode
1048           || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
1049           || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
1050           || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
1051           || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
1052         return 0;
1053     }
1055   return 1;
1058 ;; Return 1 if OP is a store multiple operation, known to be a PARALLEL.
1059 ;; The second vector element is a CLOBBER.
1060 (define_predicate "store_multiple_operation"
1061   (match_code "parallel")
1063   int count = XVECLEN (op, 0) - 1;
1064   unsigned int src_regno;
1065   rtx dest_addr;
1066   int i;
1068   /* Perform a quick check so we don't blow up below.  */
1069   if (count <= 1
1070       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1071       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
1072       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
1073     return 0;
1075   src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
1076   dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
1078   for (i = 1; i < count; i++)
1079     {
1080       rtx elt = XVECEXP (op, 0, i + 1);
1082       if (GET_CODE (elt) != SET
1083           || GET_CODE (SET_SRC (elt)) != REG
1084           || GET_MODE (SET_SRC (elt)) != SImode
1085           || REGNO (SET_SRC (elt)) != src_regno + i
1086           || GET_CODE (SET_DEST (elt)) != MEM
1087           || GET_MODE (SET_DEST (elt)) != SImode
1088           || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
1089           || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
1090           || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
1091           || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
1092         return 0;
1093     }
1095   return 1;
1098 ;; Return 1 if OP is valid for a save_world call in prologue, known to be
1099 ;; a PARLLEL.
1100 (define_predicate "save_world_operation"
1101   (match_code "parallel")
1103   int index;
1104   int i;
1105   rtx elt;
1106   int count = XVECLEN (op, 0);
1108   if (count != 54)
1109     return 0;
1111   index = 0;
1112   if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1113       || GET_CODE (XVECEXP (op, 0, index++)) != USE)
1114     return 0;
1116   for (i=1; i <= 18; i++)
1117     {
1118       elt = XVECEXP (op, 0, index++);
1119       if (GET_CODE (elt) != SET
1120           || GET_CODE (SET_DEST (elt)) != MEM
1121           || ! memory_operand (SET_DEST (elt), DFmode)
1122           || GET_CODE (SET_SRC (elt)) != REG
1123           || GET_MODE (SET_SRC (elt)) != DFmode)
1124         return 0;
1125     }
1127   for (i=1; i <= 12; i++)
1128     {
1129       elt = XVECEXP (op, 0, index++);
1130       if (GET_CODE (elt) != SET
1131           || GET_CODE (SET_DEST (elt)) != MEM
1132           || GET_CODE (SET_SRC (elt)) != REG
1133           || GET_MODE (SET_SRC (elt)) != V4SImode)
1134         return 0;
1135     }
1137   for (i=1; i <= 19; i++)
1138     {
1139       elt = XVECEXP (op, 0, index++);
1140       if (GET_CODE (elt) != SET
1141           || GET_CODE (SET_DEST (elt)) != MEM
1142           || ! memory_operand (SET_DEST (elt), Pmode)
1143           || GET_CODE (SET_SRC (elt)) != REG
1144           || GET_MODE (SET_SRC (elt)) != Pmode)
1145         return 0;
1146     }
1148   elt = XVECEXP (op, 0, index++);
1149   if (GET_CODE (elt) != SET
1150       || GET_CODE (SET_DEST (elt)) != MEM
1151       || ! memory_operand (SET_DEST (elt), Pmode)
1152       || GET_CODE (SET_SRC (elt)) != REG
1153       || REGNO (SET_SRC (elt)) != CR2_REGNO
1154       || GET_MODE (SET_SRC (elt)) != Pmode)
1155     return 0;
1157   if (GET_CODE (XVECEXP (op, 0, index++)) != SET
1158       || GET_CODE (XVECEXP (op, 0, index++)) != SET)
1159     return 0;
1160   return 1;
1163 ;; Return 1 if OP is valid for a restore_world call in epilogue, known to be
1164 ;; a PARLLEL.
1165 (define_predicate "restore_world_operation"
1166   (match_code "parallel")
1168   int index;
1169   int i;
1170   rtx elt;
1171   int count = XVECLEN (op, 0);
1173   if (count != 59)
1174     return 0;
1176   index = 0;
1177   if (GET_CODE (XVECEXP (op, 0, index++)) != RETURN
1178       || GET_CODE (XVECEXP (op, 0, index++)) != USE
1179       || GET_CODE (XVECEXP (op, 0, index++)) != USE
1180       || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
1181     return 0;
1183   elt = XVECEXP (op, 0, index++);
1184   if (GET_CODE (elt) != SET
1185       || GET_CODE (SET_SRC (elt)) != MEM
1186       || ! memory_operand (SET_SRC (elt), Pmode)
1187       || GET_CODE (SET_DEST (elt)) != REG
1188       || REGNO (SET_DEST (elt)) != CR2_REGNO
1189       || GET_MODE (SET_DEST (elt)) != Pmode)
1190     return 0;
1192   for (i=1; i <= 19; i++)
1193     {
1194       elt = XVECEXP (op, 0, index++);
1195       if (GET_CODE (elt) != SET
1196           || GET_CODE (SET_SRC (elt)) != MEM
1197           || ! memory_operand (SET_SRC (elt), Pmode)
1198           || GET_CODE (SET_DEST (elt)) != REG
1199           || GET_MODE (SET_DEST (elt)) != Pmode)
1200         return 0;
1201     }
1203   for (i=1; i <= 12; i++)
1204     {
1205       elt = XVECEXP (op, 0, index++);
1206       if (GET_CODE (elt) != SET
1207           || GET_CODE (SET_SRC (elt)) != MEM
1208           || GET_CODE (SET_DEST (elt)) != REG
1209           || GET_MODE (SET_DEST (elt)) != V4SImode)
1210         return 0;
1211     }
1213   for (i=1; i <= 18; i++)
1214     {
1215       elt = XVECEXP (op, 0, index++);
1216       if (GET_CODE (elt) != SET
1217           || GET_CODE (SET_SRC (elt)) != MEM
1218           || ! memory_operand (SET_SRC (elt), DFmode)
1219           || GET_CODE (SET_DEST (elt)) != REG
1220           || GET_MODE (SET_DEST (elt)) != DFmode)
1221         return 0;
1222     }
1224   if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1225       || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1226       || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1227       || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1228       || GET_CODE (XVECEXP (op, 0, index++)) != USE)
1229     return 0;
1230   return 1;
1233 ;; Return 1 if OP is valid for a vrsave call, known to be a PARALLEL.
1234 (define_predicate "vrsave_operation"
1235   (match_code "parallel")
1237   int count = XVECLEN (op, 0);
1238   unsigned int dest_regno, src_regno;
1239   int i;
1241   if (count <= 1
1242       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1243       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
1244       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE
1245       || XINT (SET_SRC (XVECEXP (op, 0, 0)), 1) != UNSPECV_SET_VRSAVE)
1246     return 0;
1248   dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1249   src_regno  = REGNO (XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 1));
1251   if (dest_regno != VRSAVE_REGNO || src_regno != VRSAVE_REGNO)
1252     return 0;
1254   for (i = 1; i < count; i++)
1255     {
1256       rtx elt = XVECEXP (op, 0, i);
1258       if (GET_CODE (elt) != CLOBBER
1259           && GET_CODE (elt) != SET)
1260         return 0;
1261     }
1263   return 1;
1266 ;; Return 1 if OP is valid for mfcr insn, known to be a PARALLEL.
1267 (define_predicate "mfcr_operation"
1268   (match_code "parallel")
1270   int count = XVECLEN (op, 0);
1271   int i;
1273   /* Perform a quick check so we don't blow up below.  */
1274   if (count < 1
1275       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1276       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
1277       || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
1278     return 0;
1280   for (i = 0; i < count; i++)
1281     {
1282       rtx exp = XVECEXP (op, 0, i);
1283       rtx unspec;
1284       int maskval;
1285       rtx src_reg;
1287       src_reg = XVECEXP (SET_SRC (exp), 0, 0);
1289       if (GET_CODE (src_reg) != REG
1290           || GET_MODE (src_reg) != CCmode
1291           || ! CR_REGNO_P (REGNO (src_reg)))
1292         return 0;
1294       if (GET_CODE (exp) != SET
1295           || GET_CODE (SET_DEST (exp)) != REG
1296           || GET_MODE (SET_DEST (exp)) != SImode
1297           || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
1298         return 0;
1299       unspec = SET_SRC (exp);
1300       maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
1302       if (GET_CODE (unspec) != UNSPEC
1303           || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
1304           || XVECLEN (unspec, 0) != 2
1305           || XVECEXP (unspec, 0, 0) != src_reg
1306           || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
1307           || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
1308         return 0;
1309     }
1310   return 1;
1313 ;; Return 1 if OP is valid for mtcrf insn, known to be a PARALLEL.
1314 (define_predicate "mtcrf_operation"
1315   (match_code "parallel")
1317   int count = XVECLEN (op, 0);
1318   int i;
1319   rtx src_reg;
1321   /* Perform a quick check so we don't blow up below.  */
1322   if (count < 1
1323       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1324       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
1325       || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
1326     return 0;
1327   src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
1329   if (GET_CODE (src_reg) != REG
1330       || GET_MODE (src_reg) != SImode
1331       || ! INT_REGNO_P (REGNO (src_reg)))
1332     return 0;
1334   for (i = 0; i < count; i++)
1335     {
1336       rtx exp = XVECEXP (op, 0, i);
1337       rtx unspec;
1338       int maskval;
1340       if (GET_CODE (exp) != SET
1341           || GET_CODE (SET_DEST (exp)) != REG
1342           || GET_MODE (SET_DEST (exp)) != CCmode
1343           || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
1344         return 0;
1345       unspec = SET_SRC (exp);
1346       maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
1348       if (GET_CODE (unspec) != UNSPEC
1349           || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
1350           || XVECLEN (unspec, 0) != 2
1351           || XVECEXP (unspec, 0, 0) != src_reg
1352           || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
1353           || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
1354         return 0;
1355     }
1356   return 1;
1359 ;; Return 1 if OP is valid for lmw insn, known to be a PARALLEL.
1360 (define_predicate "lmw_operation"
1361   (match_code "parallel")
1363   int count = XVECLEN (op, 0);
1364   unsigned int dest_regno;
1365   rtx src_addr;
1366   unsigned int base_regno;
1367   HOST_WIDE_INT offset;
1368   int i;
1370   /* Perform a quick check so we don't blow up below.  */
1371   if (count <= 1
1372       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1373       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
1374       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
1375     return 0;
1377   dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1378   src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
1380   if (dest_regno > 31
1381       || count != 32 - (int) dest_regno)
1382     return 0;
1384   if (legitimate_indirect_address_p (src_addr, 0))
1385     {
1386       offset = 0;
1387       base_regno = REGNO (src_addr);
1388       if (base_regno == 0)
1389         return 0;
1390     }
1391   else if (rs6000_legitimate_offset_address_p (SImode, src_addr, false, false))
1392     {
1393       offset = INTVAL (XEXP (src_addr, 1));
1394       base_regno = REGNO (XEXP (src_addr, 0));
1395     }
1396   else
1397     return 0;
1399   for (i = 0; i < count; i++)
1400     {
1401       rtx elt = XVECEXP (op, 0, i);
1402       rtx newaddr;
1403       rtx addr_reg;
1404       HOST_WIDE_INT newoffset;
1406       if (GET_CODE (elt) != SET
1407           || GET_CODE (SET_DEST (elt)) != REG
1408           || GET_MODE (SET_DEST (elt)) != SImode
1409           || REGNO (SET_DEST (elt)) != dest_regno + i
1410           || GET_CODE (SET_SRC (elt)) != MEM
1411           || GET_MODE (SET_SRC (elt)) != SImode)
1412         return 0;
1413       newaddr = XEXP (SET_SRC (elt), 0);
1414       if (legitimate_indirect_address_p (newaddr, 0))
1415         {
1416           newoffset = 0;
1417           addr_reg = newaddr;
1418         }
1419       else if (rs6000_legitimate_offset_address_p (SImode, newaddr, false, false))
1420         {
1421           addr_reg = XEXP (newaddr, 0);
1422           newoffset = INTVAL (XEXP (newaddr, 1));
1423         }
1424       else
1425         return 0;
1426       if (REGNO (addr_reg) != base_regno
1427           || newoffset != offset + 4 * i)
1428         return 0;
1429     }
1431   return 1;
1434 ;; Return 1 if OP is valid for stmw insn, known to be a PARALLEL.
1435 (define_predicate "stmw_operation"
1436   (match_code "parallel")
1438   int count = XVECLEN (op, 0);
1439   unsigned int src_regno;
1440   rtx dest_addr;
1441   unsigned int base_regno;
1442   HOST_WIDE_INT offset;
1443   int i;
1445   /* Perform a quick check so we don't blow up below.  */
1446   if (count <= 1
1447       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1448       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
1449       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
1450     return 0;
1452   src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
1453   dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
1455   if (src_regno > 31
1456       || count != 32 - (int) src_regno)
1457     return 0;
1459   if (legitimate_indirect_address_p (dest_addr, 0))
1460     {
1461       offset = 0;
1462       base_regno = REGNO (dest_addr);
1463       if (base_regno == 0)
1464         return 0;
1465     }
1466   else if (rs6000_legitimate_offset_address_p (SImode, dest_addr, false, false))
1467     {
1468       offset = INTVAL (XEXP (dest_addr, 1));
1469       base_regno = REGNO (XEXP (dest_addr, 0));
1470     }
1471   else
1472     return 0;
1474   for (i = 0; i < count; i++)
1475     {
1476       rtx elt = XVECEXP (op, 0, i);
1477       rtx newaddr;
1478       rtx addr_reg;
1479       HOST_WIDE_INT newoffset;
1481       if (GET_CODE (elt) != SET
1482           || GET_CODE (SET_SRC (elt)) != REG
1483           || GET_MODE (SET_SRC (elt)) != SImode
1484           || REGNO (SET_SRC (elt)) != src_regno + i
1485           || GET_CODE (SET_DEST (elt)) != MEM
1486           || GET_MODE (SET_DEST (elt)) != SImode)
1487         return 0;
1488       newaddr = XEXP (SET_DEST (elt), 0);
1489       if (legitimate_indirect_address_p (newaddr, 0))
1490         {
1491           newoffset = 0;
1492           addr_reg = newaddr;
1493         }
1494       else if (rs6000_legitimate_offset_address_p (SImode, newaddr, false, false))
1495         {
1496           addr_reg = XEXP (newaddr, 0);
1497           newoffset = INTVAL (XEXP (newaddr, 1));
1498         }
1499       else
1500         return 0;
1501       if (REGNO (addr_reg) != base_regno
1502           || newoffset != offset + 4 * i)
1503         return 0;
1504     }
1506   return 1;
1509 ;; Return 1 if OP is a stack tie operand.
1510 (define_predicate "tie_operand"
1511   (match_code "parallel")
1513   return (GET_CODE (XVECEXP (op, 0, 0)) == SET
1514           && GET_CODE (XEXP (XVECEXP (op, 0, 0), 0)) == MEM
1515           && GET_MODE (XEXP (XVECEXP (op, 0, 0), 0)) == BLKmode
1516           && XEXP (XVECEXP (op, 0, 0), 1) == const0_rtx);
1519 ;; Match a small code model toc reference (or medium and large
1520 ;; model toc references before reload).
1521 (define_predicate "small_toc_ref"
1522   (match_code "unspec,plus")
1524   if (GET_CODE (op) == PLUS && CONST_INT_P (XEXP (op, 1)))
1525     op = XEXP (op, 0);
1527   return GET_CODE (op) == UNSPEC && XINT (op, 1) == UNSPEC_TOCREL;