OSDN Git Service

PR target/33151
[pf3gnuchains/gcc-fork.git] / gcc / config / rs6000 / predicates.md
1 ;; Predicate definitions for POWER and PowerPC.
2 ;; Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
3 ;;
4 ;; This file is part of GCC.
5 ;;
6 ;; GCC is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 3, or (at your option)
9 ;; any later version.
10 ;;
11 ;; GCC is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ;; GNU General Public License for more details.
15 ;;
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GCC; see the file COPYING3.  If not see
18 ;; <http://www.gnu.org/licenses/>.
19
20 ;; Return 1 for anything except PARALLEL.
21 (define_predicate "any_operand"
22   (match_code "const_int,const_double,const,symbol_ref,label_ref,subreg,reg,mem"))
23
24 ;; Return 1 for any PARALLEL.
25 (define_predicate "any_parallel_operand"
26   (match_code "parallel"))
27
28 ;; Return 1 if op is COUNT register.
29 (define_predicate "count_register_operand"
30   (and (match_code "reg")
31        (match_test "REGNO (op) == CTR_REGNO
32                     || REGNO (op) > LAST_VIRTUAL_REGISTER")))
33   
34 ;; Return 1 if op is an Altivec register.
35 (define_predicate "altivec_register_operand"
36    (and (match_operand 0 "register_operand")
37         (match_test "GET_CODE (op) != REG
38                      || ALTIVEC_REGNO_P (REGNO (op))
39                      || REGNO (op) > LAST_VIRTUAL_REGISTER")))
40
41 ;; Return 1 if op is XER register.
42 (define_predicate "xer_operand"
43   (and (match_code "reg")
44        (match_test "XER_REGNO_P (REGNO (op))")))
45
46 ;; Return 1 if op is a signed 5-bit constant integer.
47 (define_predicate "s5bit_cint_operand"
48   (and (match_code "const_int")
49        (match_test "INTVAL (op) >= -16 && INTVAL (op) <= 15")))
50
51 ;; Return 1 if op is a unsigned 5-bit constant integer.
52 (define_predicate "u5bit_cint_operand"
53   (and (match_code "const_int")
54        (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 31")))
55
56 ;; Return 1 if op is a signed 8-bit constant integer.
57 ;; Integer multiplication complete more quickly
58 (define_predicate "s8bit_cint_operand"
59   (and (match_code "const_int")
60        (match_test "INTVAL (op) >= -128 && INTVAL (op) <= 127")))
61
62 ;; Return 1 if op is a constant integer that can fit in a D field.
63 (define_predicate "short_cint_operand"
64   (and (match_code "const_int")
65        (match_test "satisfies_constraint_I (op)")))
66
67 ;; Return 1 if op is a constant integer that can fit in an unsigned D field.
68 (define_predicate "u_short_cint_operand"
69   (and (match_code "const_int")
70        (match_test "satisfies_constraint_K (op)")))
71
72 ;; Return 1 if op is a constant integer that cannot fit in a signed D field.
73 (define_predicate "non_short_cint_operand"
74   (and (match_code "const_int")
75        (match_test "(unsigned HOST_WIDE_INT)
76                     (INTVAL (op) + 0x8000) >= 0x10000")))
77
78 ;; Return 1 if op is a positive constant integer that is an exact power of 2.
79 (define_predicate "exact_log2_cint_operand"
80   (and (match_code "const_int")
81        (match_test "INTVAL (op) > 0 && exact_log2 (INTVAL (op)) >= 0")))
82
83 ;; Return 1 if op is a register that is not special.
84 (define_predicate "gpc_reg_operand"
85    (and (match_operand 0 "register_operand")
86         (match_test "(GET_CODE (op) != REG
87                       || (REGNO (op) >= ARG_POINTER_REGNUM
88                           && !XER_REGNO_P (REGNO (op)))
89                       || REGNO (op) < MQ_REGNO)
90                      && !((TARGET_E500_DOUBLE || TARGET_SPE)
91                           && invalid_e500_subreg (op, mode))")))
92
93 ;; Return 1 if op is a register that is a condition register field.
94 (define_predicate "cc_reg_operand"
95    (and (match_operand 0 "register_operand")
96         (match_test "GET_CODE (op) != REG
97                      || REGNO (op) > LAST_VIRTUAL_REGISTER
98                      || CR_REGNO_P (REGNO (op))")))
99
100 ;; Return 1 if op is a register that is a condition register field not cr0.
101 (define_predicate "cc_reg_not_cr0_operand"
102    (and (match_operand 0 "register_operand")
103         (match_test "GET_CODE (op) != REG
104                      || REGNO (op) > LAST_VIRTUAL_REGISTER
105                      || CR_REGNO_NOT_CR0_P (REGNO (op))")))
106
107 ;; Return 1 if op is a constant integer valid for D field
108 ;; or non-special register register.
109 (define_predicate "reg_or_short_operand"
110   (if_then_else (match_code "const_int")
111     (match_operand 0 "short_cint_operand")
112     (match_operand 0 "gpc_reg_operand")))
113
114 ;; Return 1 if op is a constant integer valid whose negation is valid for
115 ;; D field or non-special register register.
116 ;; Do not allow a constant zero because all patterns that call this
117 ;; predicate use "addic r1,r2,-const" to set carry when r2 is greater than
118 ;; or equal to const, which does not work for zero.
119 (define_predicate "reg_or_neg_short_operand"
120   (if_then_else (match_code "const_int")
121     (match_test "satisfies_constraint_P (op)
122                  && INTVAL (op) != 0")
123     (match_operand 0 "gpc_reg_operand")))
124
125 ;; Return 1 if op is a constant integer valid for DS field
126 ;; or non-special register.
127 (define_predicate "reg_or_aligned_short_operand"
128   (if_then_else (match_code "const_int")
129     (and (match_operand 0 "short_cint_operand")
130          (match_test "!(INTVAL (op) & 3)"))
131     (match_operand 0 "gpc_reg_operand")))
132
133 ;; Return 1 if op is a constant integer whose high-order 16 bits are zero
134 ;; or non-special register.
135 (define_predicate "reg_or_u_short_operand"
136   (if_then_else (match_code "const_int")
137     (match_operand 0 "u_short_cint_operand")
138     (match_operand 0 "gpc_reg_operand")))
139
140 ;; Return 1 if op is any constant integer 
141 ;; or non-special register.
142 (define_predicate "reg_or_cint_operand"
143   (ior (match_code "const_int")
144        (match_operand 0 "gpc_reg_operand")))
145
146 ;; Return 1 if op is a constant integer valid for addition
147 ;; or non-special register.
148 (define_predicate "reg_or_add_cint_operand"
149   (if_then_else (match_code "const_int")
150     (match_test "(HOST_BITS_PER_WIDE_INT == 32
151                   && (mode == SImode || INTVAL (op) < 0x7fff8000))
152                  || ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
153                      < (unsigned HOST_WIDE_INT) 0x100000000ll)")
154     (match_operand 0 "gpc_reg_operand")))
155
156 ;; Return 1 if op is a constant integer valid for subtraction
157 ;; or non-special register.
158 (define_predicate "reg_or_sub_cint_operand"
159   (if_then_else (match_code "const_int")
160     (match_test "(HOST_BITS_PER_WIDE_INT == 32
161                   && (mode == SImode || - INTVAL (op) < 0x7fff8000))
162                  || ((unsigned HOST_WIDE_INT) (- INTVAL (op) 
163                                                + (mode == SImode
164                                                   ? 0x80000000 : 0x80008000))
165                      < (unsigned HOST_WIDE_INT) 0x100000000ll)")
166     (match_operand 0 "gpc_reg_operand")))
167
168 ;; Return 1 if op is any 32-bit unsigned constant integer
169 ;; or non-special register.
170 (define_predicate "reg_or_logical_cint_operand"
171   (if_then_else (match_code "const_int")
172     (match_test "(GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT
173                   && INTVAL (op) >= 0)
174                  || ((INTVAL (op) & GET_MODE_MASK (mode)
175                       & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0)")
176     (if_then_else (match_code "const_double")
177       (match_test "GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT
178                    && mode == DImode
179                    && CONST_DOUBLE_HIGH (op) == 0")
180       (match_operand 0 "gpc_reg_operand"))))
181
182 ;; Return 1 if operand is a CONST_DOUBLE that can be set in a register
183 ;; with no more than one instruction per word.
184 (define_predicate "easy_fp_constant"
185   (match_code "const_double")
186 {
187   long k[4];
188   REAL_VALUE_TYPE rv;
189
190   if (GET_MODE (op) != mode
191       || (!SCALAR_FLOAT_MODE_P (mode) && mode != DImode))
192     return 0;
193
194   /* Consider all constants with -msoft-float to be easy.  */
195   if ((TARGET_SOFT_FLOAT || TARGET_E500_SINGLE)
196       && mode != DImode)
197     return 1;
198
199   if (DECIMAL_FLOAT_MODE_P (mode))
200     return 0;
201
202   /* If we are using V.4 style PIC, consider all constants to be hard.  */
203   if (flag_pic && DEFAULT_ABI == ABI_V4)
204     return 0;
205
206 #ifdef TARGET_RELOCATABLE
207   /* Similarly if we are using -mrelocatable, consider all constants
208      to be hard.  */
209   if (TARGET_RELOCATABLE)
210     return 0;
211 #endif
212
213   switch (mode)
214     {
215     case TFmode:
216       REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
217       REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
218
219       return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
220               && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1
221               && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1
222               && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1);
223
224     case DFmode:
225       /* Force constants to memory before reload to utilize
226          compress_float_constant.
227          Avoid this when flag_unsafe_math_optimizations is enabled
228          because RDIV division to reciprocal optimization is not able
229          to regenerate the division.  */
230       if (TARGET_E500_DOUBLE
231           || (!reload_in_progress && !reload_completed
232               && !flag_unsafe_math_optimizations))
233         return 0;
234
235       REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
236       REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
237
238       return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
239               && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
240
241     case SFmode:
242       /* The constant 0.f is easy.  */
243       if (op == CONST0_RTX (SFmode))
244         return 1;
245
246       /* Force constants to memory before reload to utilize
247          compress_float_constant.
248          Avoid this when flag_unsafe_math_optimizations is enabled
249          because RDIV division to reciprocal optimization is not able
250          to regenerate the division.  */
251       if (!reload_in_progress && !reload_completed
252           && !flag_unsafe_math_optimizations)
253         return 0;
254
255       REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
256       REAL_VALUE_TO_TARGET_SINGLE (rv, k[0]);
257
258       return num_insns_constant_wide (k[0]) == 1;
259
260   case DImode:
261     return ((TARGET_POWERPC64
262              && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
263             || (num_insns_constant (op, DImode) <= 2));
264
265   case SImode:
266     return 1;
267
268   default:
269     gcc_unreachable ();
270   }
271 })
272
273 ;; Return 1 if the operand is a CONST_VECTOR and can be loaded into a
274 ;; vector register without using memory.
275 (define_predicate "easy_vector_constant"
276   (match_code "const_vector")
277 {
278   if (ALTIVEC_VECTOR_MODE (mode))
279     {
280       if (zero_constant (op, mode))
281         return true;
282       return easy_altivec_constant (op, mode);
283     }
284
285   if (SPE_VECTOR_MODE (mode))
286     {
287       int cst, cst2;
288       if (zero_constant (op, mode))
289         return true;
290       if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
291         return false;
292
293       /* Limit SPE vectors to 15 bits signed.  These we can generate with:
294            li r0, CONSTANT1
295            evmergelo r0, r0, r0
296            li r0, CONSTANT2
297
298          I don't know how efficient it would be to allow bigger constants,
299          considering we'll have an extra 'ori' for every 'li'.  I doubt 5
300          instructions is better than a 64-bit memory load, but I don't
301          have the e500 timing specs.  */
302       if (mode == V2SImode)
303         {
304           cst  = INTVAL (CONST_VECTOR_ELT (op, 0));
305           cst2 = INTVAL (CONST_VECTOR_ELT (op, 1));
306           return cst  >= -0x7fff && cst <= 0x7fff
307                  && cst2 >= -0x7fff && cst2 <= 0x7fff;
308         }
309     }
310
311   return false;
312 })
313
314 ;; Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF.
315 (define_predicate "easy_vector_constant_add_self"
316   (and (match_code "const_vector")
317        (and (match_test "TARGET_ALTIVEC")
318             (match_test "easy_altivec_constant (op, mode)")))
319 {
320   rtx last = CONST_VECTOR_ELT (op, GET_MODE_NUNITS (mode) - 1);
321   HOST_WIDE_INT val = ((INTVAL (last) & 0xff) ^ 0x80) - 0x80;
322   return EASY_VECTOR_15_ADD_SELF (val);
323 })
324
325 ;; Return 1 if operand is constant zero (scalars and vectors).
326 (define_predicate "zero_constant"
327   (and (match_code "const_int,const_double,const_vector")
328        (match_test "op == CONST0_RTX (mode)")))
329
330 ;; Return 1 if operand is 0.0.
331 ;; or non-special register register field no cr0
332 (define_predicate "zero_fp_constant"
333   (and (match_code "const_double")
334        (match_test "SCALAR_FLOAT_MODE_P (mode)
335                     && op == CONST0_RTX (mode)")))
336
337 ;; Return 1 if the operand is in volatile memory.  Note that during the
338 ;; RTL generation phase, memory_operand does not return TRUE for volatile
339 ;; memory references.  So this function allows us to recognize volatile
340 ;; references where it's safe.
341 (define_predicate "volatile_mem_operand"
342   (and (and (match_code "mem")
343             (match_test "MEM_VOLATILE_P (op)"))
344        (if_then_else (match_test "reload_completed")
345          (match_operand 0 "memory_operand")
346          (if_then_else (match_test "reload_in_progress")
347            (match_test "strict_memory_address_p (mode, XEXP (op, 0))")
348            (match_test "memory_address_p (mode, XEXP (op, 0))")))))
349
350 ;; Return 1 if the operand is an offsettable memory operand.
351 (define_predicate "offsettable_mem_operand"
352   (and (match_operand 0 "memory_operand")
353        (match_test "GET_CODE (XEXP (op, 0)) != PRE_INC
354                     && GET_CODE (XEXP (op, 0)) != PRE_DEC
355                     && GET_CODE (XEXP (op, 0)) != PRE_MODIFY")))
356
357 ;; Return 1 if the operand is a memory operand with an address divisible by 4
358 (define_predicate "word_offset_memref_operand"
359   (and (match_operand 0 "memory_operand")
360        (match_test "GET_CODE (XEXP (op, 0)) != PLUS
361                     || ! REG_P (XEXP (XEXP (op, 0), 0)) 
362                     || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT
363                     || INTVAL (XEXP (XEXP (op, 0), 1)) % 4 == 0")))
364
365 ;; Return 1 if the operand is an indexed or indirect memory operand.
366 (define_predicate "indexed_or_indirect_operand"
367   (match_code "mem")
368 {
369   op = XEXP (op, 0);
370   if (TARGET_ALTIVEC
371       && ALTIVEC_VECTOR_MODE (mode)
372       && GET_CODE (op) == AND
373       && GET_CODE (XEXP (op, 1)) == CONST_INT
374       && INTVAL (XEXP (op, 1)) == -16)
375     op = XEXP (op, 0);
376
377   return indexed_or_indirect_address (op, mode);
378 })
379
380 ;; Return 1 if the operand is an indexed or indirect address.
381 (define_special_predicate "indexed_or_indirect_address"
382   (and (match_test "REG_P (op)
383                     || (GET_CODE (op) == PLUS
384                         /* Omit testing REG_P (XEXP (op, 0)).  */
385                         && REG_P (XEXP (op, 1)))")
386        (match_operand 0 "address_operand")))
387
388 ;; Used for the destination of the fix_truncdfsi2 expander.
389 ;; If stfiwx will be used, the result goes to memory; otherwise,
390 ;; we're going to emit a store and a load of a subreg, so the dest is a
391 ;; register.
392 (define_predicate "fix_trunc_dest_operand"
393   (if_then_else (match_test "! TARGET_E500_DOUBLE && TARGET_PPC_GFXOPT")
394    (match_operand 0 "memory_operand")
395    (match_operand 0 "gpc_reg_operand")))
396
397 ;; Return 1 if the operand is either a non-special register or can be used
398 ;; as the operand of a `mode' add insn.
399 (define_predicate "add_operand"
400   (if_then_else (match_code "const_int")
401     (match_test "satisfies_constraint_I (op)
402                  || satisfies_constraint_L (op)")
403     (match_operand 0 "gpc_reg_operand")))
404
405 ;; Return 1 if OP is a constant but not a valid add_operand.
406 (define_predicate "non_add_cint_operand"
407   (and (match_code "const_int")
408        (match_test "!satisfies_constraint_I (op)
409                     && !satisfies_constraint_L (op)")))
410
411 ;; Return 1 if the operand is a constant that can be used as the operand
412 ;; of an OR or XOR.
413 (define_predicate "logical_const_operand"
414   (match_code "const_int,const_double")
415 {
416   HOST_WIDE_INT opl, oph;
417
418   if (GET_CODE (op) == CONST_INT)
419     {
420       opl = INTVAL (op) & GET_MODE_MASK (mode);
421
422       if (HOST_BITS_PER_WIDE_INT <= 32
423           && GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
424         return 0;
425     }
426   else if (GET_CODE (op) == CONST_DOUBLE)
427     {
428       gcc_assert (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT);
429
430       opl = CONST_DOUBLE_LOW (op);
431       oph = CONST_DOUBLE_HIGH (op);
432       if (oph != 0)
433         return 0;
434     }
435   else
436     return 0;
437
438   return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
439           || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
440 })
441
442 ;; Return 1 if the operand is a non-special register or a constant that
443 ;; can be used as the operand of an OR or XOR.
444 (define_predicate "logical_operand"
445   (ior (match_operand 0 "gpc_reg_operand")
446        (match_operand 0 "logical_const_operand")))
447
448 ;; Return 1 if op is a constant that is not a logical operand, but could
449 ;; be split into one.
450 (define_predicate "non_logical_cint_operand"
451   (and (match_code "const_int,const_double")
452        (and (not (match_operand 0 "logical_operand"))
453             (match_operand 0 "reg_or_logical_cint_operand"))))
454
455 ;; Return 1 if op is a constant that can be encoded in a 32-bit mask,
456 ;; suitable for use with rlwinm (no more than two 1->0 or 0->1
457 ;; transitions).  Reject all ones and all zeros, since these should have
458 ;; been optimized away and confuse the making of MB and ME.
459 (define_predicate "mask_operand"
460   (match_code "const_int")
461 {
462   HOST_WIDE_INT c, lsb;
463
464   c = INTVAL (op);
465
466   if (TARGET_POWERPC64)
467     {
468       /* Fail if the mask is not 32-bit.  */
469       if (mode == DImode && (c & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0)
470         return 0;
471
472       /* Fail if the mask wraps around because the upper 32-bits of the
473          mask will all be 1s, contrary to GCC's internal view.  */
474       if ((c & 0x80000001) == 0x80000001)
475         return 0;
476     }
477
478   /* We don't change the number of transitions by inverting,
479      so make sure we start with the LS bit zero.  */
480   if (c & 1)
481     c = ~c;
482
483   /* Reject all zeros or all ones.  */
484   if (c == 0)
485     return 0;
486
487   /* Find the first transition.  */
488   lsb = c & -c;
489
490   /* Invert to look for a second transition.  */
491   c = ~c;
492
493   /* Erase first transition.  */
494   c &= -lsb;
495
496   /* Find the second transition (if any).  */
497   lsb = c & -c;
498
499   /* Match if all the bits above are 1's (or c is zero).  */
500   return c == -lsb;
501 })
502
503 ;; Return 1 for the PowerPC64 rlwinm corner case.
504 (define_predicate "mask_operand_wrap"
505   (match_code "const_int")
506 {
507   HOST_WIDE_INT c, lsb;
508
509   c = INTVAL (op);
510
511   if ((c & 0x80000001) != 0x80000001)
512     return 0;
513
514   c = ~c;
515   if (c == 0)
516     return 0;
517
518   lsb = c & -c;
519   c = ~c;
520   c &= -lsb;
521   lsb = c & -c;
522   return c == -lsb;
523 })
524
525 ;; Return 1 if the operand is a constant that is a PowerPC64 mask
526 ;; suitable for use with rldicl or rldicr (no more than one 1->0 or 0->1
527 ;; transition).  Reject all zeros, since zero should have been
528 ;; optimized away and confuses the making of MB and ME.
529 (define_predicate "mask64_operand"
530   (match_code "const_int")
531 {
532   HOST_WIDE_INT c, lsb;
533
534   c = INTVAL (op);
535
536   /* Reject all zeros.  */
537   if (c == 0)
538     return 0;
539
540   /* We don't change the number of transitions by inverting,
541      so make sure we start with the LS bit zero.  */
542   if (c & 1)
543     c = ~c;
544
545   /* Find the first transition.  */
546   lsb = c & -c;
547
548   /* Match if all the bits above are 1's (or c is zero).  */
549   return c == -lsb;
550 })
551
552 ;; Like mask64_operand, but allow up to three transitions.  This
553 ;; predicate is used by insn patterns that generate two rldicl or
554 ;; rldicr machine insns.
555 (define_predicate "mask64_2_operand"
556   (match_code "const_int")
557 {
558   HOST_WIDE_INT c, lsb;
559
560   c = INTVAL (op);
561
562   /* Disallow all zeros.  */
563   if (c == 0)
564     return 0;
565
566   /* We don't change the number of transitions by inverting,
567      so make sure we start with the LS bit zero.  */
568   if (c & 1)
569     c = ~c;
570
571   /* Find the first transition.  */
572   lsb = c & -c;
573
574   /* Invert to look for a second transition.  */
575   c = ~c;
576
577   /* Erase first transition.  */
578   c &= -lsb;
579
580   /* Find the second transition.  */
581   lsb = c & -c;
582
583   /* Invert to look for a third transition.  */
584   c = ~c;
585
586   /* Erase second transition.  */
587   c &= -lsb;
588
589   /* Find the third transition (if any).  */
590   lsb = c & -c;
591
592   /* Match if all the bits above are 1's (or c is zero).  */
593   return c == -lsb;
594 })
595
596 ;; Like and_operand, but also match constants that can be implemented
597 ;; with two rldicl or rldicr insns.
598 (define_predicate "and64_2_operand"
599   (ior (match_operand 0 "mask64_2_operand")
600        (if_then_else (match_test "fixed_regs[CR0_REGNO]")
601          (match_operand 0 "gpc_reg_operand")
602          (match_operand 0 "logical_operand"))))
603
604 ;; Return 1 if the operand is either a non-special register or a
605 ;; constant that can be used as the operand of a logical AND.
606 (define_predicate "and_operand"
607   (ior (match_operand 0 "mask_operand")
608        (ior (and (match_test "TARGET_POWERPC64 && mode == DImode")
609                  (match_operand 0 "mask64_operand"))
610             (if_then_else (match_test "fixed_regs[CR0_REGNO]")
611               (match_operand 0 "gpc_reg_operand")
612               (match_operand 0 "logical_operand")))))
613
614 ;; Return 1 if the operand is either a logical operand or a short cint operand.
615 (define_predicate "scc_eq_operand"
616   (ior (match_operand 0 "logical_operand")
617        (match_operand 0 "short_cint_operand")))
618
619 ;; Return 1 if the operand is a general non-special register or memory operand.
620 (define_predicate "reg_or_mem_operand"
621      (ior (match_operand 0 "memory_operand")
622           (ior (and (match_code "mem")
623                     (match_test "macho_lo_sum_memory_operand (op, mode)"))
624                (ior (match_operand 0 "volatile_mem_operand")
625                     (match_operand 0 "gpc_reg_operand")))))
626
627 ;; Return 1 if the operand is either an easy FP constant or memory or reg.
628 (define_predicate "reg_or_none500mem_operand"
629   (if_then_else (match_code "mem")
630      (and (match_test "!TARGET_E500_DOUBLE")
631           (ior (match_operand 0 "memory_operand")
632                (ior (match_test "macho_lo_sum_memory_operand (op, mode)")
633                     (match_operand 0 "volatile_mem_operand"))))
634      (match_operand 0 "gpc_reg_operand")))
635
636 ;; Return 1 if the operand is CONST_DOUBLE 0, register or memory operand.
637 (define_predicate "zero_reg_mem_operand"
638   (ior (match_operand 0 "zero_fp_constant")
639        (match_operand 0 "reg_or_mem_operand")))
640
641 ;; Return 1 if the operand is a general register or memory operand without
642 ;; pre_inc or pre_dec or pre_modify, which produces invalid form of PowerPC
643 ;; lwa instruction.
644 (define_predicate "lwa_operand"
645   (match_code "reg,subreg,mem")
646 {
647   rtx inner = op;
648
649   if (reload_completed && GET_CODE (inner) == SUBREG)
650     inner = SUBREG_REG (inner);
651
652   return gpc_reg_operand (inner, mode)
653     || (memory_operand (inner, mode)
654         && GET_CODE (XEXP (inner, 0)) != PRE_INC
655         && GET_CODE (XEXP (inner, 0)) != PRE_DEC
656         && (GET_CODE (XEXP (inner, 0)) != PRE_MODIFY
657             || legitimate_indexed_address_p (XEXP (XEXP (inner, 0), 1), 0))
658         && (GET_CODE (XEXP (inner, 0)) != PLUS
659             || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT
660             || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0));
661 })
662
663 ;; Return 1 if the operand, used inside a MEM, is a SYMBOL_REF.
664 (define_predicate "symbol_ref_operand"
665   (and (match_code "symbol_ref")
666        (match_test "(mode == VOIDmode || GET_MODE (op) == mode)
667                     && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))")))
668
669 ;; Return 1 if op is an operand that can be loaded via the GOT.
670 ;; or non-special register register field no cr0
671 (define_predicate "got_operand"
672   (match_code "symbol_ref,const,label_ref"))
673
674 ;; Return 1 if op is a simple reference that can be loaded via the GOT,
675 ;; excluding labels involving addition.
676 (define_predicate "got_no_const_operand"
677   (match_code "symbol_ref,label_ref"))
678
679 ;; Return 1 if op is a SYMBOL_REF for a TLS symbol.
680 (define_predicate "rs6000_tls_symbol_ref"
681   (and (match_code "symbol_ref")
682        (match_test "RS6000_SYMBOL_REF_TLS_P (op)")))
683
684 ;; Return 1 if the operand, used inside a MEM, is a valid first argument
685 ;; to CALL.  This is a SYMBOL_REF, a pseudo-register, LR or CTR.
686 (define_predicate "call_operand"
687   (if_then_else (match_code "reg")
688      (match_test "REGNO (op) == LR_REGNO
689                   || REGNO (op) == CTR_REGNO
690                   || REGNO (op) >= FIRST_PSEUDO_REGISTER")
691      (match_code "symbol_ref")))
692
693 ;; Return 1 if the operand is a SYMBOL_REF for a function known to be in
694 ;; this file.
695 (define_predicate "current_file_function_operand"
696   (and (match_code "symbol_ref")
697        (match_test "(DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
698                     && ((SYMBOL_REF_LOCAL_P (op)
699                          && (DEFAULT_ABI != ABI_AIX
700                              || !SYMBOL_REF_EXTERNAL_P (op)))
701                         || (op == XEXP (DECL_RTL (current_function_decl),
702                                                   0)))")))
703
704 ;; Return 1 if this operand is a valid input for a move insn.
705 (define_predicate "input_operand"
706   (match_code "label_ref,symbol_ref,const,high,reg,subreg,mem,
707                const_double,const_vector,const_int,plus")
708 {
709   /* Memory is always valid.  */
710   if (memory_operand (op, mode))
711     return 1;
712
713   /* For floating-point, easy constants are valid.  */
714   if (SCALAR_FLOAT_MODE_P (mode)
715       && CONSTANT_P (op)
716       && easy_fp_constant (op, mode))
717     return 1;
718
719   /* Allow any integer constant.  */
720   if (GET_MODE_CLASS (mode) == MODE_INT
721       && (GET_CODE (op) == CONST_INT
722           || GET_CODE (op) == CONST_DOUBLE))
723     return 1;
724
725   /* Allow easy vector constants.  */
726   if (GET_CODE (op) == CONST_VECTOR
727       && easy_vector_constant (op, mode))
728     return 1;
729
730   /* Do not allow invalid E500 subregs.  */
731   if ((TARGET_E500_DOUBLE || TARGET_SPE)
732       && GET_CODE (op) == SUBREG
733       && invalid_e500_subreg (op, mode))
734     return 0;
735
736   /* For floating-point or multi-word mode, the only remaining valid type
737      is a register.  */
738   if (SCALAR_FLOAT_MODE_P (mode)
739       || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
740     return register_operand (op, mode);
741
742   /* The only cases left are integral modes one word or smaller (we
743      do not get called for MODE_CC values).  These can be in any
744      register.  */
745   if (register_operand (op, mode))
746     return 1;
747
748   /* A SYMBOL_REF referring to the TOC is valid.  */
749   if (legitimate_constant_pool_address_p (op))
750     return 1;
751
752   /* A constant pool expression (relative to the TOC) is valid */
753   if (toc_relative_expr_p (op))
754     return 1;
755
756   /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
757      to be valid.  */
758   if (DEFAULT_ABI == ABI_V4
759       && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
760       && small_data_operand (op, Pmode))
761     return 1;
762
763   return 0;
764 })
765
766 ;; Return true if OP is an invalid SUBREG operation on the e500.
767 (define_predicate "rs6000_nonimmediate_operand"
768   (match_code "reg,subreg,mem")
769 {
770   if ((TARGET_E500_DOUBLE || TARGET_SPE)
771       && GET_CODE (op) == SUBREG
772       && invalid_e500_subreg (op, mode))
773     return 0;
774
775   return nonimmediate_operand (op, mode);
776 })
777
778 ;; Return true if operand is boolean operator.
779 (define_predicate "boolean_operator"
780   (match_code "and,ior,xor"))
781
782 ;; Return true if operand is OR-form of boolean operator.
783 (define_predicate "boolean_or_operator"
784   (match_code "ior,xor"))
785
786 ;; Return true if operand is an equality operator.
787 (define_special_predicate "equality_operator"
788   (match_code "eq,ne"))
789
790 ;; Return true if operand is MIN or MAX operator.
791 (define_predicate "min_max_operator"
792   (match_code "smin,smax,umin,umax"))
793
794 ;; Return 1 if OP is a comparison operation that is valid for a branch
795 ;; instruction.  We check the opcode against the mode of the CC value.
796 ;; validate_condition_mode is an assertion.
797 (define_predicate "branch_comparison_operator"
798    (and (match_operand 0 "comparison_operator")
799         (and (match_test "GET_MODE_CLASS (GET_MODE (XEXP (op, 0))) == MODE_CC")
800              (match_test "validate_condition_mode (GET_CODE (op),
801                                                    GET_MODE (XEXP (op, 0))),
802                           1"))))
803
804 ;; Return 1 if OP is a comparison operation that is valid for an SCC insn --
805 ;; it must be a positive comparison.
806 (define_predicate "scc_comparison_operator"
807   (and (match_operand 0 "branch_comparison_operator")
808        (match_code "eq,lt,gt,ltu,gtu,unordered")))
809
810 ;; Return 1 if OP is a comparison operation that is valid for a branch
811 ;; insn, which is true if the corresponding bit in the CC register is set.
812 (define_predicate "branch_positive_comparison_operator"
813   (and (match_operand 0 "branch_comparison_operator")
814        (match_code "eq,lt,gt,ltu,gtu,unordered")))
815
816 ;; Return 1 is OP is a comparison operation that is valid for a trap insn.
817 (define_predicate "trap_comparison_operator"
818    (and (match_operand 0 "comparison_operator")
819         (match_code "eq,ne,le,lt,ge,gt,leu,ltu,geu,gtu")))
820
821 ;; Return 1 if OP is a load multiple operation, known to be a PARALLEL.
822 (define_predicate "load_multiple_operation"
823   (match_code "parallel")
824 {
825   int count = XVECLEN (op, 0);
826   unsigned int dest_regno;
827   rtx src_addr;
828   int i;
829
830   /* Perform a quick check so we don't blow up below.  */
831   if (count <= 1
832       || GET_CODE (XVECEXP (op, 0, 0)) != SET
833       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
834       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
835     return 0;
836
837   dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
838   src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
839
840   for (i = 1; i < count; i++)
841     {
842       rtx elt = XVECEXP (op, 0, i);
843
844       if (GET_CODE (elt) != SET
845           || GET_CODE (SET_DEST (elt)) != REG
846           || GET_MODE (SET_DEST (elt)) != SImode
847           || REGNO (SET_DEST (elt)) != dest_regno + i
848           || GET_CODE (SET_SRC (elt)) != MEM
849           || GET_MODE (SET_SRC (elt)) != SImode
850           || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
851           || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
852           || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
853           || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
854         return 0;
855     }
856
857   return 1;
858 })
859
860 ;; Return 1 if OP is a store multiple operation, known to be a PARALLEL.
861 ;; The second vector element is a CLOBBER.
862 (define_predicate "store_multiple_operation"
863   (match_code "parallel")
864 {
865   int count = XVECLEN (op, 0) - 1;
866   unsigned int src_regno;
867   rtx dest_addr;
868   int i;
869
870   /* Perform a quick check so we don't blow up below.  */
871   if (count <= 1
872       || GET_CODE (XVECEXP (op, 0, 0)) != SET
873       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
874       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
875     return 0;
876
877   src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
878   dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
879
880   for (i = 1; i < count; i++)
881     {
882       rtx elt = XVECEXP (op, 0, i + 1);
883
884       if (GET_CODE (elt) != SET
885           || GET_CODE (SET_SRC (elt)) != REG
886           || GET_MODE (SET_SRC (elt)) != SImode
887           || REGNO (SET_SRC (elt)) != src_regno + i
888           || GET_CODE (SET_DEST (elt)) != MEM
889           || GET_MODE (SET_DEST (elt)) != SImode
890           || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
891           || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
892           || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
893           || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
894         return 0;
895     }
896
897   return 1;
898 })
899
900 ;; Return 1 if OP is valid for a save_world call in prologue, known to be
901 ;; a PARLLEL.
902 (define_predicate "save_world_operation"
903   (match_code "parallel")
904 {
905   int index;
906   int i;
907   rtx elt;
908   int count = XVECLEN (op, 0);
909
910   if (count != 55)
911     return 0;
912
913   index = 0;
914   if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
915       || GET_CODE (XVECEXP (op, 0, index++)) != USE)
916     return 0;
917
918   for (i=1; i <= 18; i++)
919     {
920       elt = XVECEXP (op, 0, index++);
921       if (GET_CODE (elt) != SET
922           || GET_CODE (SET_DEST (elt)) != MEM
923           || ! memory_operand (SET_DEST (elt), DFmode)
924           || GET_CODE (SET_SRC (elt)) != REG
925           || GET_MODE (SET_SRC (elt)) != DFmode)
926         return 0;
927     }
928
929   for (i=1; i <= 12; i++)
930     {
931       elt = XVECEXP (op, 0, index++);
932       if (GET_CODE (elt) != SET
933           || GET_CODE (SET_DEST (elt)) != MEM
934           || GET_CODE (SET_SRC (elt)) != REG
935           || GET_MODE (SET_SRC (elt)) != V4SImode)
936         return 0;
937     }
938
939   for (i=1; i <= 19; i++)
940     {
941       elt = XVECEXP (op, 0, index++);
942       if (GET_CODE (elt) != SET
943           || GET_CODE (SET_DEST (elt)) != MEM
944           || ! memory_operand (SET_DEST (elt), Pmode)
945           || GET_CODE (SET_SRC (elt)) != REG
946           || GET_MODE (SET_SRC (elt)) != Pmode)
947         return 0;
948     }
949
950   elt = XVECEXP (op, 0, index++);
951   if (GET_CODE (elt) != SET
952       || GET_CODE (SET_DEST (elt)) != MEM
953       || ! memory_operand (SET_DEST (elt), Pmode)
954       || GET_CODE (SET_SRC (elt)) != REG
955       || REGNO (SET_SRC (elt)) != CR2_REGNO
956       || GET_MODE (SET_SRC (elt)) != Pmode)
957     return 0;
958
959   if (GET_CODE (XVECEXP (op, 0, index++)) != USE
960       || GET_CODE (XVECEXP (op, 0, index++)) != USE
961       || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
962     return 0;
963   return 1;
964 })
965
966 ;; Return 1 if OP is valid for a restore_world call in epilogue, known to be
967 ;; a PARLLEL.
968 (define_predicate "restore_world_operation"
969   (match_code "parallel")
970 {
971   int index;
972   int i;
973   rtx elt;
974   int count = XVECLEN (op, 0);
975
976   if (count != 59)
977     return 0;
978
979   index = 0;
980   if (GET_CODE (XVECEXP (op, 0, index++)) != RETURN
981       || GET_CODE (XVECEXP (op, 0, index++)) != USE
982       || GET_CODE (XVECEXP (op, 0, index++)) != USE
983       || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
984     return 0;
985
986   elt = XVECEXP (op, 0, index++);
987   if (GET_CODE (elt) != SET
988       || GET_CODE (SET_SRC (elt)) != MEM
989       || ! memory_operand (SET_SRC (elt), Pmode)
990       || GET_CODE (SET_DEST (elt)) != REG
991       || REGNO (SET_DEST (elt)) != CR2_REGNO
992       || GET_MODE (SET_DEST (elt)) != Pmode)
993     return 0;
994
995   for (i=1; i <= 19; i++)
996     {
997       elt = XVECEXP (op, 0, index++);
998       if (GET_CODE (elt) != SET
999           || GET_CODE (SET_SRC (elt)) != MEM
1000           || ! memory_operand (SET_SRC (elt), Pmode)
1001           || GET_CODE (SET_DEST (elt)) != REG
1002           || GET_MODE (SET_DEST (elt)) != Pmode)
1003         return 0;
1004     }
1005
1006   for (i=1; i <= 12; i++)
1007     {
1008       elt = XVECEXP (op, 0, index++);
1009       if (GET_CODE (elt) != SET
1010           || GET_CODE (SET_SRC (elt)) != MEM
1011           || GET_CODE (SET_DEST (elt)) != REG
1012           || GET_MODE (SET_DEST (elt)) != V4SImode)
1013         return 0;
1014     }
1015
1016   for (i=1; i <= 18; i++)
1017     {
1018       elt = XVECEXP (op, 0, index++);
1019       if (GET_CODE (elt) != SET
1020           || GET_CODE (SET_SRC (elt)) != MEM
1021           || ! memory_operand (SET_SRC (elt), DFmode)
1022           || GET_CODE (SET_DEST (elt)) != REG
1023           || GET_MODE (SET_DEST (elt)) != DFmode)
1024         return 0;
1025     }
1026
1027   if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1028       || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1029       || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1030       || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1031       || GET_CODE (XVECEXP (op, 0, index++)) != USE)
1032     return 0;
1033   return 1;
1034 })
1035
1036 ;; Return 1 if OP is valid for a vrsave call, known to be a PARALLEL.
1037 (define_predicate "vrsave_operation"
1038   (match_code "parallel")
1039 {
1040   int count = XVECLEN (op, 0);
1041   unsigned int dest_regno, src_regno;
1042   int i;
1043
1044   if (count <= 1
1045       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1046       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
1047       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE
1048       || XINT (SET_SRC (XVECEXP (op, 0, 0)), 1) != UNSPECV_SET_VRSAVE)
1049     return 0;
1050
1051   dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1052   src_regno  = REGNO (XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 1));
1053
1054   if (dest_regno != VRSAVE_REGNO || src_regno != VRSAVE_REGNO)
1055     return 0;
1056
1057   for (i = 1; i < count; i++)
1058     {
1059       rtx elt = XVECEXP (op, 0, i);
1060
1061       if (GET_CODE (elt) != CLOBBER
1062           && GET_CODE (elt) != SET)
1063         return 0;
1064     }
1065
1066   return 1;
1067 })
1068
1069 ;; Return 1 if OP is valid for mfcr insn, known to be a PARALLEL.
1070 (define_predicate "mfcr_operation"
1071   (match_code "parallel")
1072 {
1073   int count = XVECLEN (op, 0);
1074   int i;
1075
1076   /* Perform a quick check so we don't blow up below.  */
1077   if (count < 1
1078       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1079       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
1080       || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
1081     return 0;
1082
1083   for (i = 0; i < count; i++)
1084     {
1085       rtx exp = XVECEXP (op, 0, i);
1086       rtx unspec;
1087       int maskval;
1088       rtx src_reg;
1089
1090       src_reg = XVECEXP (SET_SRC (exp), 0, 0);
1091
1092       if (GET_CODE (src_reg) != REG
1093           || GET_MODE (src_reg) != CCmode
1094           || ! CR_REGNO_P (REGNO (src_reg)))
1095         return 0;
1096
1097       if (GET_CODE (exp) != SET
1098           || GET_CODE (SET_DEST (exp)) != REG
1099           || GET_MODE (SET_DEST (exp)) != SImode
1100           || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
1101         return 0;
1102       unspec = SET_SRC (exp);
1103       maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
1104
1105       if (GET_CODE (unspec) != UNSPEC
1106           || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
1107           || XVECLEN (unspec, 0) != 2
1108           || XVECEXP (unspec, 0, 0) != src_reg
1109           || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
1110           || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
1111         return 0;
1112     }
1113   return 1;
1114 })
1115
1116 ;; Return 1 if OP is valid for mtcrf insn, known to be a PARALLEL.
1117 (define_predicate "mtcrf_operation"
1118   (match_code "parallel")
1119 {
1120   int count = XVECLEN (op, 0);
1121   int i;
1122   rtx src_reg;
1123
1124   /* Perform a quick check so we don't blow up below.  */
1125   if (count < 1
1126       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1127       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
1128       || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
1129     return 0;
1130   src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
1131
1132   if (GET_CODE (src_reg) != REG
1133       || GET_MODE (src_reg) != SImode
1134       || ! INT_REGNO_P (REGNO (src_reg)))
1135     return 0;
1136
1137   for (i = 0; i < count; i++)
1138     {
1139       rtx exp = XVECEXP (op, 0, i);
1140       rtx unspec;
1141       int maskval;
1142
1143       if (GET_CODE (exp) != SET
1144           || GET_CODE (SET_DEST (exp)) != REG
1145           || GET_MODE (SET_DEST (exp)) != CCmode
1146           || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
1147         return 0;
1148       unspec = SET_SRC (exp);
1149       maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
1150
1151       if (GET_CODE (unspec) != UNSPEC
1152           || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
1153           || XVECLEN (unspec, 0) != 2
1154           || XVECEXP (unspec, 0, 0) != src_reg
1155           || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
1156           || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
1157         return 0;
1158     }
1159   return 1;
1160 })
1161
1162 ;; Return 1 if OP is valid for lmw insn, known to be a PARALLEL.
1163 (define_predicate "lmw_operation"
1164   (match_code "parallel")
1165 {
1166   int count = XVECLEN (op, 0);
1167   unsigned int dest_regno;
1168   rtx src_addr;
1169   unsigned int base_regno;
1170   HOST_WIDE_INT offset;
1171   int i;
1172
1173   /* Perform a quick check so we don't blow up below.  */
1174   if (count <= 1
1175       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1176       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
1177       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
1178     return 0;
1179
1180   dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1181   src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
1182
1183   if (dest_regno > 31
1184       || count != 32 - (int) dest_regno)
1185     return 0;
1186
1187   if (legitimate_indirect_address_p (src_addr, 0))
1188     {
1189       offset = 0;
1190       base_regno = REGNO (src_addr);
1191       if (base_regno == 0)
1192         return 0;
1193     }
1194   else if (rs6000_legitimate_offset_address_p (SImode, src_addr, 0))
1195     {
1196       offset = INTVAL (XEXP (src_addr, 1));
1197       base_regno = REGNO (XEXP (src_addr, 0));
1198     }
1199   else
1200     return 0;
1201
1202   for (i = 0; i < count; i++)
1203     {
1204       rtx elt = XVECEXP (op, 0, i);
1205       rtx newaddr;
1206       rtx addr_reg;
1207       HOST_WIDE_INT newoffset;
1208
1209       if (GET_CODE (elt) != SET
1210           || GET_CODE (SET_DEST (elt)) != REG
1211           || GET_MODE (SET_DEST (elt)) != SImode
1212           || REGNO (SET_DEST (elt)) != dest_regno + i
1213           || GET_CODE (SET_SRC (elt)) != MEM
1214           || GET_MODE (SET_SRC (elt)) != SImode)
1215         return 0;
1216       newaddr = XEXP (SET_SRC (elt), 0);
1217       if (legitimate_indirect_address_p (newaddr, 0))
1218         {
1219           newoffset = 0;
1220           addr_reg = newaddr;
1221         }
1222       else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0))
1223         {
1224           addr_reg = XEXP (newaddr, 0);
1225           newoffset = INTVAL (XEXP (newaddr, 1));
1226         }
1227       else
1228         return 0;
1229       if (REGNO (addr_reg) != base_regno
1230           || newoffset != offset + 4 * i)
1231         return 0;
1232     }
1233
1234   return 1;
1235 })
1236
1237 ;; Return 1 if OP is valid for stmw insn, known to be a PARALLEL.
1238 (define_predicate "stmw_operation"
1239   (match_code "parallel")
1240 {
1241   int count = XVECLEN (op, 0);
1242   unsigned int src_regno;
1243   rtx dest_addr;
1244   unsigned int base_regno;
1245   HOST_WIDE_INT offset;
1246   int i;
1247
1248   /* Perform a quick check so we don't blow up below.  */
1249   if (count <= 1
1250       || GET_CODE (XVECEXP (op, 0, 0)) != SET
1251       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
1252       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
1253     return 0;
1254
1255   src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
1256   dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
1257
1258   if (src_regno > 31
1259       || count != 32 - (int) src_regno)
1260     return 0;
1261
1262   if (legitimate_indirect_address_p (dest_addr, 0))
1263     {
1264       offset = 0;
1265       base_regno = REGNO (dest_addr);
1266       if (base_regno == 0)
1267         return 0;
1268     }
1269   else if (rs6000_legitimate_offset_address_p (SImode, dest_addr, 0))
1270     {
1271       offset = INTVAL (XEXP (dest_addr, 1));
1272       base_regno = REGNO (XEXP (dest_addr, 0));
1273     }
1274   else
1275     return 0;
1276
1277   for (i = 0; i < count; i++)
1278     {
1279       rtx elt = XVECEXP (op, 0, i);
1280       rtx newaddr;
1281       rtx addr_reg;
1282       HOST_WIDE_INT newoffset;
1283
1284       if (GET_CODE (elt) != SET
1285           || GET_CODE (SET_SRC (elt)) != REG
1286           || GET_MODE (SET_SRC (elt)) != SImode
1287           || REGNO (SET_SRC (elt)) != src_regno + i
1288           || GET_CODE (SET_DEST (elt)) != MEM
1289           || GET_MODE (SET_DEST (elt)) != SImode)
1290         return 0;
1291       newaddr = XEXP (SET_DEST (elt), 0);
1292       if (legitimate_indirect_address_p (newaddr, 0))
1293         {
1294           newoffset = 0;
1295           addr_reg = newaddr;
1296         }
1297       else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0))
1298         {
1299           addr_reg = XEXP (newaddr, 0);
1300           newoffset = INTVAL (XEXP (newaddr, 1));
1301         }
1302       else
1303         return 0;
1304       if (REGNO (addr_reg) != base_regno
1305           || newoffset != offset + 4 * i)
1306         return 0;
1307     }
1308
1309   return 1;
1310 })