1 ;; Predicate definitions for POWER and PowerPC.
2 ;; Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
4 ;; This file is part of GCC.
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)
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 (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")))
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))")))
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")))
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")))
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")))
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)")))
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)")))
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")))
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")))
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))")))
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))")))
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))")))
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")))
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")))
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")))
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")))
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")))
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")))
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)
164 ? 0x80000000 : 0x80008000))
165 < (unsigned HOST_WIDE_INT) 0x100000000ll)")
166 (match_operand 0 "gpc_reg_operand")))
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
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
179 && CONST_DOUBLE_HIGH (op) == 0")
180 (match_operand 0 "gpc_reg_operand"))))
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")
190 if (GET_MODE (op) != mode
191 || (!SCALAR_FLOAT_MODE_P (mode) && mode != DImode))
194 /* Consider all constants with -msoft-float to be easy. */
195 if ((TARGET_SOFT_FLOAT || TARGET_E500_SINGLE)
199 if (DECIMAL_FLOAT_MODE_P (mode))
202 /* If we are using V.4 style PIC, consider all constants to be hard. */
203 if (flag_pic && DEFAULT_ABI == ABI_V4)
206 #ifdef TARGET_RELOCATABLE
207 /* Similarly if we are using -mrelocatable, consider all constants
209 if (TARGET_RELOCATABLE)
216 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
217 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
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);
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))
235 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
236 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
238 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
239 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
242 /* The constant 0.f is easy. */
243 if (op == CONST0_RTX (SFmode))
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)
255 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
256 REAL_VALUE_TO_TARGET_SINGLE (rv, k[0]);
258 return num_insns_constant_wide (k[0]) == 1;
261 return ((TARGET_POWERPC64
262 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
263 || (num_insns_constant (op, DImode) <= 2));
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")
278 if (ALTIVEC_VECTOR_MODE (mode))
280 if (zero_constant (op, mode))
282 return easy_altivec_constant (op, mode);
285 if (SPE_VECTOR_MODE (mode))
288 if (zero_constant (op, mode))
290 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
293 /* Limit SPE vectors to 15 bits signed. These we can generate with:
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)
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;
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)")))
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);
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)")))
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)")))
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))")))))
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")))
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")))
365 ;; Return 1 if the operand is an indexed or indirect memory operand.
366 (define_predicate "indexed_or_indirect_operand"
371 && ALTIVEC_VECTOR_MODE (mode)
372 && GET_CODE (op) == AND
373 && GET_CODE (XEXP (op, 1)) == CONST_INT
374 && INTVAL (XEXP (op, 1)) == -16)
377 return indexed_or_indirect_address (op, mode);
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")))
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
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")))
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")))
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)")))
411 ;; Return 1 if the operand is a constant that can be used as the operand
413 (define_predicate "logical_const_operand"
414 (match_code "const_int,const_double")
416 HOST_WIDE_INT opl, oph;
418 if (GET_CODE (op) == CONST_INT)
420 opl = INTVAL (op) & GET_MODE_MASK (mode);
422 if (HOST_BITS_PER_WIDE_INT <= 32
423 && GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
426 else if (GET_CODE (op) == CONST_DOUBLE)
428 gcc_assert (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT);
430 opl = CONST_DOUBLE_LOW (op);
431 oph = CONST_DOUBLE_HIGH (op);
438 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
439 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
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")))
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"))))
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")
462 HOST_WIDE_INT c, lsb;
466 if (TARGET_POWERPC64)
468 /* Fail if the mask is not 32-bit. */
469 if (mode == DImode && (c & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0)
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)
478 /* We don't change the number of transitions by inverting,
479 so make sure we start with the LS bit zero. */
483 /* Reject all zeros or all ones. */
487 /* Find the first transition. */
490 /* Invert to look for a second transition. */
493 /* Erase first transition. */
496 /* Find the second transition (if any). */
499 /* Match if all the bits above are 1's (or c is zero). */
503 ;; Return 1 for the PowerPC64 rlwinm corner case.
504 (define_predicate "mask_operand_wrap"
505 (match_code "const_int")
507 HOST_WIDE_INT c, lsb;
511 if ((c & 0x80000001) != 0x80000001)
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")
532 HOST_WIDE_INT c, lsb;
536 /* Reject all zeros. */
540 /* We don't change the number of transitions by inverting,
541 so make sure we start with the LS bit zero. */
545 /* Find the first transition. */
548 /* Match if all the bits above are 1's (or c is zero). */
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")
558 HOST_WIDE_INT c, lsb;
562 /* Disallow all zeros. */
566 /* We don't change the number of transitions by inverting,
567 so make sure we start with the LS bit zero. */
571 /* Find the first transition. */
574 /* Invert to look for a second transition. */
577 /* Erase first transition. */
580 /* Find the second transition. */
583 /* Invert to look for a third transition. */
586 /* Erase second transition. */
589 /* Find the third transition (if any). */
592 /* Match if all the bits above are 1's (or c is zero). */
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"))))
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")))))
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")))
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")))))
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")))
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")))
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
644 (define_predicate "lwa_operand"
645 (match_code "reg,subreg,mem")
649 if (reload_completed && GET_CODE (inner) == SUBREG)
650 inner = SUBREG_REG (inner);
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));
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))")))
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"))
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"))
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)")))
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")))
693 ;; Return 1 if the operand is a SYMBOL_REF for a function known to be in
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),
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")
709 /* Memory is always valid. */
710 if (memory_operand (op, mode))
713 /* For floating-point, easy constants are valid. */
714 if (SCALAR_FLOAT_MODE_P (mode)
716 && easy_fp_constant (op, mode))
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))
725 /* Allow easy vector constants. */
726 if (GET_CODE (op) == CONST_VECTOR
727 && easy_vector_constant (op, mode))
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))
736 /* For floating-point or multi-word mode, the only remaining valid type
738 if (SCALAR_FLOAT_MODE_P (mode)
739 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
740 return register_operand (op, mode);
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
745 if (register_operand (op, mode))
748 /* A SYMBOL_REF referring to the TOC is valid. */
749 if (legitimate_constant_pool_address_p (op))
752 /* A constant pool expression (relative to the TOC) is valid */
753 if (toc_relative_expr_p (op))
756 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
758 if (DEFAULT_ABI == ABI_V4
759 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
760 && small_data_operand (op, Pmode))
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")
770 if ((TARGET_E500_DOUBLE || TARGET_SPE)
771 && GET_CODE (op) == SUBREG
772 && invalid_e500_subreg (op, mode))
775 return nonimmediate_operand (op, mode);
778 ;; Return true if operand is boolean operator.
779 (define_predicate "boolean_operator"
780 (match_code "and,ior,xor"))
782 ;; Return true if operand is OR-form of boolean operator.
783 (define_predicate "boolean_or_operator"
784 (match_code "ior,xor"))
786 ;; Return true if operand is an equality operator.
787 (define_special_predicate "equality_operator"
788 (match_code "eq,ne"))
790 ;; Return true if operand is MIN or MAX operator.
791 (define_predicate "min_max_operator"
792 (match_code "smin,smax,umin,umax"))
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))),
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")))
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")))
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")))
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")
825 int count = XVECLEN (op, 0);
826 unsigned int dest_regno;
830 /* Perform a quick check so we don't blow up below. */
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)
837 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
838 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
840 for (i = 1; i < count; i++)
842 rtx elt = XVECEXP (op, 0, i);
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)
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")
865 int count = XVECLEN (op, 0) - 1;
866 unsigned int src_regno;
870 /* Perform a quick check so we don't blow up below. */
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)
877 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
878 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
880 for (i = 1; i < count; i++)
882 rtx elt = XVECEXP (op, 0, i + 1);
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)
900 ;; Return 1 if OP is valid for a save_world call in prologue, known to be
902 (define_predicate "save_world_operation"
903 (match_code "parallel")
908 int count = XVECLEN (op, 0);
914 if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
915 || GET_CODE (XVECEXP (op, 0, index++)) != USE)
918 for (i=1; i <= 18; i++)
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)
929 for (i=1; i <= 12; i++)
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)
939 for (i=1; i <= 19; i++)
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)
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)
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)
966 ;; Return 1 if OP is valid for a restore_world call in epilogue, known to be
968 (define_predicate "restore_world_operation"
969 (match_code "parallel")
974 int count = XVECLEN (op, 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)
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)
995 for (i=1; i <= 19; i++)
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)
1006 for (i=1; i <= 12; i++)
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)
1016 for (i=1; i <= 18; i++)
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)
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)
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")
1040 int count = XVECLEN (op, 0);
1041 unsigned int dest_regno, src_regno;
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)
1051 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1052 src_regno = REGNO (XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 1));
1054 if (dest_regno != VRSAVE_REGNO || src_regno != VRSAVE_REGNO)
1057 for (i = 1; i < count; i++)
1059 rtx elt = XVECEXP (op, 0, i);
1061 if (GET_CODE (elt) != CLOBBER
1062 && GET_CODE (elt) != SET)
1069 ;; Return 1 if OP is valid for mfcr insn, known to be a PARALLEL.
1070 (define_predicate "mfcr_operation"
1071 (match_code "parallel")
1073 int count = XVECLEN (op, 0);
1076 /* Perform a quick check so we don't blow up below. */
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)
1083 for (i = 0; i < count; i++)
1085 rtx exp = XVECEXP (op, 0, i);
1090 src_reg = XVECEXP (SET_SRC (exp), 0, 0);
1092 if (GET_CODE (src_reg) != REG
1093 || GET_MODE (src_reg) != CCmode
1094 || ! CR_REGNO_P (REGNO (src_reg)))
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))))
1102 unspec = SET_SRC (exp);
1103 maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
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)
1116 ;; Return 1 if OP is valid for mtcrf insn, known to be a PARALLEL.
1117 (define_predicate "mtcrf_operation"
1118 (match_code "parallel")
1120 int count = XVECLEN (op, 0);
1124 /* Perform a quick check so we don't blow up below. */
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)
1130 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
1132 if (GET_CODE (src_reg) != REG
1133 || GET_MODE (src_reg) != SImode
1134 || ! INT_REGNO_P (REGNO (src_reg)))
1137 for (i = 0; i < count; i++)
1139 rtx exp = XVECEXP (op, 0, i);
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))))
1148 unspec = SET_SRC (exp);
1149 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
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)
1162 ;; Return 1 if OP is valid for lmw insn, known to be a PARALLEL.
1163 (define_predicate "lmw_operation"
1164 (match_code "parallel")
1166 int count = XVECLEN (op, 0);
1167 unsigned int dest_regno;
1169 unsigned int base_regno;
1170 HOST_WIDE_INT offset;
1173 /* Perform a quick check so we don't blow up below. */
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)
1180 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1181 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
1184 || count != 32 - (int) dest_regno)
1187 if (legitimate_indirect_address_p (src_addr, 0))
1190 base_regno = REGNO (src_addr);
1191 if (base_regno == 0)
1194 else if (rs6000_legitimate_offset_address_p (SImode, src_addr, 0))
1196 offset = INTVAL (XEXP (src_addr, 1));
1197 base_regno = REGNO (XEXP (src_addr, 0));
1202 for (i = 0; i < count; i++)
1204 rtx elt = XVECEXP (op, 0, i);
1207 HOST_WIDE_INT newoffset;
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)
1216 newaddr = XEXP (SET_SRC (elt), 0);
1217 if (legitimate_indirect_address_p (newaddr, 0))
1222 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0))
1224 addr_reg = XEXP (newaddr, 0);
1225 newoffset = INTVAL (XEXP (newaddr, 1));
1229 if (REGNO (addr_reg) != base_regno
1230 || newoffset != offset + 4 * i)
1237 ;; Return 1 if OP is valid for stmw insn, known to be a PARALLEL.
1238 (define_predicate "stmw_operation"
1239 (match_code "parallel")
1241 int count = XVECLEN (op, 0);
1242 unsigned int src_regno;
1244 unsigned int base_regno;
1245 HOST_WIDE_INT offset;
1248 /* Perform a quick check so we don't blow up below. */
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)
1255 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
1256 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
1259 || count != 32 - (int) src_regno)
1262 if (legitimate_indirect_address_p (dest_addr, 0))
1265 base_regno = REGNO (dest_addr);
1266 if (base_regno == 0)
1269 else if (rs6000_legitimate_offset_address_p (SImode, dest_addr, 0))
1271 offset = INTVAL (XEXP (dest_addr, 1));
1272 base_regno = REGNO (XEXP (dest_addr, 0));
1277 for (i = 0; i < count; i++)
1279 rtx elt = XVECEXP (op, 0, i);
1282 HOST_WIDE_INT newoffset;
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)
1291 newaddr = XEXP (SET_DEST (elt), 0);
1292 if (legitimate_indirect_address_p (newaddr, 0))
1297 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0))
1299 addr_reg = XEXP (newaddr, 0);
1300 newoffset = INTVAL (XEXP (newaddr, 1));
1304 if (REGNO (addr_reg) != base_regno
1305 || newoffset != offset + 4 * i)