1 ;; Predicate definitions for POWER and PowerPC.
2 ;; Copyright (C) 2005 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 2, 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 COPYING. If not, write to
18 ;; the Free Software Foundation, 51 Franklin Street, Fifth Floor,
19 ;; Boston, MA 02110-1301, USA.
21 ;; Return 1 for anything except PARALLEL.
22 (define_predicate "any_operand"
23 (match_code "const_int,const_double,const,symbol_ref,label_ref,subreg,reg,mem"))
25 ;; Return 1 for any PARALLEL.
26 (define_predicate "any_parallel_operand"
27 (match_code "parallel"))
29 ;; Return 1 if op is COUNT register.
30 (define_predicate "count_register_operand"
31 (and (match_code "reg")
32 (match_test "REGNO (op) == COUNT_REGISTER_REGNUM
33 || REGNO (op) > LAST_VIRTUAL_REGISTER")))
35 ;; Return 1 if op is an Altivec register.
36 (define_predicate "altivec_register_operand"
37 (and (match_operand 0 "register_operand")
38 (match_test "GET_CODE (op) != REG
39 || ALTIVEC_REGNO_P (REGNO (op))
40 || REGNO (op) > LAST_VIRTUAL_REGISTER")))
42 ;; Return 1 if op is XER register.
43 (define_predicate "xer_operand"
44 (and (match_code "reg")
45 (match_test "XER_REGNO_P (REGNO (op))")))
47 ;; Return 1 if op is a signed 5-bit constant integer.
48 (define_predicate "s5bit_cint_operand"
49 (and (match_code "const_int")
50 (match_test "INTVAL (op) >= -16 && INTVAL (op) <= 15")))
52 ;; Return 1 if op is a unsigned 5-bit constant integer.
53 (define_predicate "u5bit_cint_operand"
54 (and (match_code "const_int")
55 (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 31")))
57 ;; Return 1 if op is a signed 8-bit constant integer.
58 ;; Integer multiplication complete more quickly
59 (define_predicate "s8bit_cint_operand"
60 (and (match_code "const_int")
61 (match_test "INTVAL (op) >= -128 && INTVAL (op) <= 127")))
63 ;; Return 1 if op is a constant integer that can fit in a D field.
64 (define_predicate "short_cint_operand"
65 (and (match_code "const_int")
66 (match_test "CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')")))
68 ;; Return 1 if op is a constant integer that can fit in an unsigned D field.
69 (define_predicate "u_short_cint_operand"
70 (and (match_code "const_int")
71 (match_test "CONST_OK_FOR_LETTER_P (INTVAL (op), 'K')")))
73 ;; Return 1 if op is a constant integer that cannot fit in a signed D field.
74 (define_predicate "non_short_cint_operand"
75 (and (match_code "const_int")
76 (match_test "(unsigned HOST_WIDE_INT)
77 (INTVAL (op) + 0x8000) >= 0x10000")))
79 ;; Return 1 if op is a positive constant integer that is an exact power of 2.
80 (define_predicate "exact_log2_cint_operand"
81 (and (match_code "const_int")
82 (match_test "INTVAL (op) > 0 && exact_log2 (INTVAL (op)) >= 0")))
84 ;; Return 1 if op is a register that is not special.
85 (define_predicate "gpc_reg_operand"
86 (and (match_operand 0 "register_operand")
87 (match_test "(GET_CODE (op) != REG
88 || (REGNO (op) >= ARG_POINTER_REGNUM
89 && !XER_REGNO_P (REGNO (op)))
90 || REGNO (op) < MQ_REGNO)
91 && !((TARGET_E500_DOUBLE || TARGET_SPE)
92 && invalid_e500_subreg (op, mode))")))
94 ;; Return 1 if op is a register that is a condition register field.
95 (define_predicate "cc_reg_operand"
96 (and (match_operand 0 "register_operand")
97 (match_test "GET_CODE (op) != REG
98 || REGNO (op) > LAST_VIRTUAL_REGISTER
99 || CR_REGNO_P (REGNO (op))")))
101 ;; Return 1 if op is a register that is a condition register field not cr0.
102 (define_predicate "cc_reg_not_cr0_operand"
103 (and (match_operand 0 "register_operand")
104 (match_test "GET_CODE (op) != REG
105 || REGNO (op) > LAST_VIRTUAL_REGISTER
106 || CR_REGNO_NOT_CR0_P (REGNO (op))")))
108 ;; Return 1 if op is a constant integer valid for D field
109 ;; or non-special register register.
110 (define_predicate "reg_or_short_operand"
111 (if_then_else (match_code "const_int")
112 (match_operand 0 "short_cint_operand")
113 (match_operand 0 "gpc_reg_operand")))
115 ;; Return 1 if op is a constant integer valid whose negation is valid for
116 ;; D field or non-special register register.
117 ;; Do not allow a constant zero because all patterns that call this
118 ;; predicate use "addic r1,r2,-const" to set carry when r2 is greater than
119 ;; or equal to const, which does not work for zero.
120 (define_predicate "reg_or_neg_short_operand"
121 (if_then_else (match_code "const_int")
122 (match_test "CONST_OK_FOR_LETTER_P (INTVAL (op), 'P')
123 && INTVAL (op) != 0")
124 (match_operand 0 "gpc_reg_operand")))
126 ;; Return 1 if op is a constant integer valid for DS field
127 ;; or non-special register.
128 (define_predicate "reg_or_aligned_short_operand"
129 (if_then_else (match_code "const_int")
130 (and (match_operand 0 "short_cint_operand")
131 (match_test "!(INTVAL (op) & 3)"))
132 (match_operand 0 "gpc_reg_operand")))
134 ;; Return 1 if op is a constant integer whose high-order 16 bits are zero
135 ;; or non-special register.
136 (define_predicate "reg_or_u_short_operand"
137 (if_then_else (match_code "const_int")
138 (match_operand 0 "u_short_cint_operand")
139 (match_operand 0 "gpc_reg_operand")))
141 ;; Return 1 if op is any constant integer
142 ;; or non-special register.
143 (define_predicate "reg_or_cint_operand"
144 (ior (match_code "const_int")
145 (match_operand 0 "gpc_reg_operand")))
147 ;; Return 1 if op is a constant integer valid for addition
148 ;; or non-special register.
149 (define_predicate "reg_or_add_cint_operand"
150 (if_then_else (match_code "const_int")
151 (match_test "(HOST_BITS_PER_WIDE_INT == 32
152 && (mode == SImode || INTVAL (op) < 0x7fff8000))
153 || ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
154 < (unsigned HOST_WIDE_INT) 0x100000000ll)")
155 (match_operand 0 "gpc_reg_operand")))
157 ;; Return 1 if op is a constant integer valid for subtraction
158 ;; or non-special register.
159 (define_predicate "reg_or_sub_cint_operand"
160 (if_then_else (match_code "const_int")
161 (match_test "(HOST_BITS_PER_WIDE_INT == 32
162 && (mode == SImode || - INTVAL (op) < 0x7fff8000))
163 || ((unsigned HOST_WIDE_INT) (- INTVAL (op)
165 ? 0x80000000 : 0x80008000))
166 < (unsigned HOST_WIDE_INT) 0x100000000ll)")
167 (match_operand 0 "gpc_reg_operand")))
169 ;; Return 1 if op is any 32-bit unsigned constant integer
170 ;; or non-special register.
171 (define_predicate "reg_or_logical_cint_operand"
172 (if_then_else (match_code "const_int")
173 (match_test "(GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT
175 || ((INTVAL (op) & GET_MODE_MASK (mode)
176 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0)")
177 (if_then_else (match_code "const_double")
178 (match_test "GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT
180 && CONST_DOUBLE_HIGH (op) == 0")
181 (match_operand 0 "gpc_reg_operand"))))
183 ;; Return 1 if operand is a CONST_DOUBLE that can be set in a register
184 ;; with no more than one instruction per word.
185 (define_predicate "easy_fp_constant"
186 (match_code "const_double")
191 if (GET_MODE (op) != mode
192 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
195 /* Consider all constants with -msoft-float to be easy. */
196 if ((TARGET_SOFT_FLOAT || TARGET_E500_SINGLE)
200 /* If we are using V.4 style PIC, consider all constants to be hard. */
201 if (flag_pic && DEFAULT_ABI == ABI_V4)
204 #ifdef TARGET_RELOCATABLE
205 /* Similarly if we are using -mrelocatable, consider all constants
207 if (TARGET_RELOCATABLE)
214 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
215 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
217 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
218 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1
219 && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1
220 && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1);
223 /* Force constants to memory before reload to utilize
224 compress_float_constant.
225 Avoid this when flag_unsafe_math_optimizations is enabled
226 because RDIV division to reciprocal optimization is not able
227 to regenerate the division. */
228 if (TARGET_E500_DOUBLE
229 || (!reload_in_progress && !reload_completed
230 && !flag_unsafe_math_optimizations))
233 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
234 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
236 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
237 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
240 /* The constant 0.f is easy. */
241 if (op == CONST0_RTX (SFmode))
244 /* Force constants to memory before reload to utilize
245 compress_float_constant.
246 Avoid this when flag_unsafe_math_optimizations is enabled
247 because RDIV division to reciprocal optimization is not able
248 to regenerate the division. */
249 if (!reload_in_progress && !reload_completed
250 && !flag_unsafe_math_optimizations)
253 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
254 REAL_VALUE_TO_TARGET_SINGLE (rv, k[0]);
256 return num_insns_constant_wide (k[0]) == 1;
259 return ((TARGET_POWERPC64
260 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
261 || (num_insns_constant (op, DImode) <= 2));
271 ;; Return 1 if the operand is a CONST_VECTOR and can be loaded into a
272 ;; vector register without using memory.
273 (define_predicate "easy_vector_constant"
274 (match_code "const_vector")
276 if (ALTIVEC_VECTOR_MODE (mode))
278 if (zero_constant (op, mode))
280 return easy_altivec_constant (op, mode);
283 if (SPE_VECTOR_MODE (mode))
286 if (zero_constant (op, mode))
288 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
291 /* Limit SPE vectors to 15 bits signed. These we can generate with:
296 I don't know how efficient it would be to allow bigger constants,
297 considering we'll have an extra 'ori' for every 'li'. I doubt 5
298 instructions is better than a 64-bit memory load, but I don't
299 have the e500 timing specs. */
300 if (mode == V2SImode)
302 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
303 cst2 = INTVAL (CONST_VECTOR_ELT (op, 1));
304 return cst >= -0x7fff && cst <= 0x7fff
305 && cst2 >= -0x7fff && cst2 <= 0x7fff;
312 ;; Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF.
313 (define_predicate "easy_vector_constant_add_self"
314 (and (match_code "const_vector")
315 (and (match_test "TARGET_ALTIVEC")
316 (match_test "easy_altivec_constant (op, mode)")))
318 rtx last = CONST_VECTOR_ELT (op, GET_MODE_NUNITS (mode) - 1);
319 HOST_WIDE_INT val = ((INTVAL (last) & 0xff) ^ 0x80) - 0x80;
320 return EASY_VECTOR_15_ADD_SELF (val);
323 ;; Return 1 if operand is constant zero (scalars and vectors).
324 (define_predicate "zero_constant"
325 (and (match_code "const_int,const_double,const_vector")
326 (match_test "op == CONST0_RTX (mode)")))
328 ;; Return 1 if operand is 0.0.
329 ;; or non-special register register field no cr0
330 (define_predicate "zero_fp_constant"
331 (and (match_code "const_double")
332 (match_test "GET_MODE_CLASS (mode) == MODE_FLOAT
333 && op == CONST0_RTX (mode)")))
335 ;; Return 1 if the operand is in volatile memory. Note that during the
336 ;; RTL generation phase, memory_operand does not return TRUE for volatile
337 ;; memory references. So this function allows us to recognize volatile
338 ;; references where it's safe.
339 (define_predicate "volatile_mem_operand"
340 (and (and (match_code "mem")
341 (match_test "MEM_VOLATILE_P (op)"))
342 (if_then_else (match_test "reload_completed")
343 (match_operand 0 "memory_operand")
344 (if_then_else (match_test "reload_in_progress")
345 (match_test "strict_memory_address_p (mode, XEXP (op, 0))")
346 (match_test "memory_address_p (mode, XEXP (op, 0))")))))
348 ;; Return 1 if the operand is an offsettable memory operand.
349 (define_predicate "offsettable_mem_operand"
350 (and (match_code "mem")
351 (match_test "offsettable_address_p (reload_completed
352 || reload_in_progress,
353 mode, XEXP (op, 0))")))
355 ;; Return 1 if the operand is a memory operand with an address divisible by 4
356 (define_predicate "word_offset_memref_operand"
357 (and (match_operand 0 "memory_operand")
358 (match_test "GET_CODE (XEXP (op, 0)) != PLUS
359 || ! REG_P (XEXP (XEXP (op, 0), 0))
360 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT
361 || INTVAL (XEXP (XEXP (op, 0), 1)) % 4 == 0")))
363 ;; Return 1 if the operand is an indexed or indirect memory operand.
364 (define_predicate "indexed_or_indirect_operand"
369 && ALTIVEC_VECTOR_MODE (mode)
370 && GET_CODE (op) == AND
371 && GET_CODE (XEXP (op, 1)) == CONST_INT
372 && INTVAL (XEXP (op, 1)) == -16)
375 return indexed_or_indirect_address (op, mode);
378 ;; Return 1 if the operand is an indexed or indirect address.
379 (define_special_predicate "indexed_or_indirect_address"
380 (and (match_test "REG_P (op)
381 || (GET_CODE (op) == PLUS
382 /* Omit testing REG_P (XEXP (op, 0)). */
383 && REG_P (XEXP (op, 1)))")
384 (match_operand 0 "address_operand")))
386 ;; Used for the destination of the fix_truncdfsi2 expander.
387 ;; If stfiwx will be used, the result goes to memory; otherwise,
388 ;; we're going to emit a store and a load of a subreg, so the dest is a
390 (define_predicate "fix_trunc_dest_operand"
391 (if_then_else (match_test "! TARGET_E500_DOUBLE && TARGET_PPC_GFXOPT")
392 (match_operand 0 "memory_operand")
393 (match_operand 0 "gpc_reg_operand")))
395 ;; Return 1 if the operand is either a non-special register or can be used
396 ;; as the operand of a `mode' add insn.
397 (define_predicate "add_operand"
398 (if_then_else (match_code "const_int")
399 (match_test "CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
400 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L')")
401 (match_operand 0 "gpc_reg_operand")))
403 ;; Return 1 if OP is a constant but not a valid add_operand.
404 (define_predicate "non_add_cint_operand"
405 (and (match_code "const_int")
406 (match_test "!CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
407 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L')")))
409 ;; Return 1 if the operand is a constant that can be used as the operand
411 (define_predicate "logical_const_operand"
412 (match_code "const_int,const_double")
414 HOST_WIDE_INT opl, oph;
416 if (GET_CODE (op) == CONST_INT)
418 opl = INTVAL (op) & GET_MODE_MASK (mode);
420 if (HOST_BITS_PER_WIDE_INT <= 32
421 && GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
424 else if (GET_CODE (op) == CONST_DOUBLE)
426 gcc_assert (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT);
428 opl = CONST_DOUBLE_LOW (op);
429 oph = CONST_DOUBLE_HIGH (op);
436 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
437 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
440 ;; Return 1 if the operand is a non-special register or a constant that
441 ;; can be used as the operand of an OR or XOR.
442 (define_predicate "logical_operand"
443 (ior (match_operand 0 "gpc_reg_operand")
444 (match_operand 0 "logical_const_operand")))
446 ;; Return 1 if op is a constant that is not a logical operand, but could
447 ;; be split into one.
448 (define_predicate "non_logical_cint_operand"
449 (and (match_code "const_int,const_double")
450 (and (not (match_operand 0 "logical_operand"))
451 (match_operand 0 "reg_or_logical_cint_operand"))))
453 ;; Return 1 if op is a constant that can be encoded in a 32-bit mask,
454 ;; suitable for use with rlwinm (no more than two 1->0 or 0->1
455 ;; transitions). Reject all ones and all zeros, since these should have
456 ;; been optimized away and confuse the making of MB and ME.
457 (define_predicate "mask_operand"
458 (match_code "const_int")
460 HOST_WIDE_INT c, lsb;
464 if (TARGET_POWERPC64)
466 /* Fail if the mask is not 32-bit. */
467 if (mode == DImode && (c & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0)
470 /* Fail if the mask wraps around because the upper 32-bits of the
471 mask will all be 1s, contrary to GCC's internal view. */
472 if ((c & 0x80000001) == 0x80000001)
476 /* We don't change the number of transitions by inverting,
477 so make sure we start with the LS bit zero. */
481 /* Reject all zeros or all ones. */
485 /* Find the first transition. */
488 /* Invert to look for a second transition. */
491 /* Erase first transition. */
494 /* Find the second transition (if any). */
497 /* Match if all the bits above are 1's (or c is zero). */
501 ;; Return 1 for the PowerPC64 rlwinm corner case.
502 (define_predicate "mask_operand_wrap"
503 (match_code "const_int")
505 HOST_WIDE_INT c, lsb;
509 if ((c & 0x80000001) != 0x80000001)
523 ;; Return 1 if the operand is a constant that is a PowerPC64 mask
524 ;; suitable for use with rldicl or rldicr (no more than one 1->0 or 0->1
525 ;; transition). Reject all zeros, since zero should have been
526 ;; optimized away and confuses the making of MB and ME.
527 (define_predicate "mask64_operand"
528 (match_code "const_int")
530 HOST_WIDE_INT c, lsb;
534 /* Reject all zeros. */
538 /* We don't change the number of transitions by inverting,
539 so make sure we start with the LS bit zero. */
543 /* Find the first transition. */
546 /* Match if all the bits above are 1's (or c is zero). */
550 ;; Like mask64_operand, but allow up to three transitions. This
551 ;; predicate is used by insn patterns that generate two rldicl or
552 ;; rldicr machine insns.
553 (define_predicate "mask64_2_operand"
554 (match_code "const_int")
556 HOST_WIDE_INT c, lsb;
560 /* Disallow all zeros. */
564 /* We don't change the number of transitions by inverting,
565 so make sure we start with the LS bit zero. */
569 /* Find the first transition. */
572 /* Invert to look for a second transition. */
575 /* Erase first transition. */
578 /* Find the second transition. */
581 /* Invert to look for a third transition. */
584 /* Erase second transition. */
587 /* Find the third transition (if any). */
590 /* Match if all the bits above are 1's (or c is zero). */
594 ;; Like and_operand, but also match constants that can be implemented
595 ;; with two rldicl or rldicr insns.
596 (define_predicate "and64_2_operand"
597 (ior (match_operand 0 "mask64_2_operand")
598 (if_then_else (match_test "fixed_regs[CR0_REGNO]")
599 (match_operand 0 "gpc_reg_operand")
600 (match_operand 0 "logical_operand"))))
602 ;; Return 1 if the operand is either a non-special register or a
603 ;; constant that can be used as the operand of a logical AND.
604 (define_predicate "and_operand"
605 (ior (match_operand 0 "mask_operand")
606 (ior (and (match_test "TARGET_POWERPC64 && mode == DImode")
607 (match_operand 0 "mask64_operand"))
608 (if_then_else (match_test "fixed_regs[CR0_REGNO]")
609 (match_operand 0 "gpc_reg_operand")
610 (match_operand 0 "logical_operand")))))
612 ;; Return 1 if the operand is either a logical operand or a short cint operand.
613 (define_predicate "scc_eq_operand"
614 (ior (match_operand 0 "logical_operand")
615 (match_operand 0 "short_cint_operand")))
617 ;; Return 1 if the operand is a general non-special register or memory operand.
618 (define_predicate "reg_or_mem_operand"
619 (if_then_else (match_code "mem")
620 (ior (match_operand 0 "memory_operand")
621 (ior (match_test "macho_lo_sum_memory_operand (op, mode)")
622 (match_operand 0 "volatile_mem_operand")))
623 (match_operand 0 "gpc_reg_operand")))
625 ;; Return 1 if the operand is either an easy FP constant or memory or reg.
626 (define_predicate "reg_or_none500mem_operand"
627 (if_then_else (match_code "mem")
628 (and (match_test "!TARGET_E500_DOUBLE")
629 (ior (match_operand 0 "memory_operand")
630 (ior (match_test "macho_lo_sum_memory_operand (op, mode)")
631 (match_operand 0 "volatile_mem_operand"))))
632 (match_operand 0 "gpc_reg_operand")))
634 ;; Return 1 if the operand is CONST_DOUBLE 0, register or memory operand.
635 (define_predicate "zero_reg_mem_operand"
636 (ior (match_operand 0 "zero_fp_constant")
637 (match_operand 0 "reg_or_mem_operand")))
639 ;; Return 1 if the operand is a general register or memory operand without
640 ;; pre_inc or pre_dec, which produces invalid form of PowerPC lwa
642 (define_predicate "lwa_operand"
643 (match_code "reg,subreg,mem")
647 if (reload_completed && GET_CODE (inner) == SUBREG)
648 inner = SUBREG_REG (inner);
650 return gpc_reg_operand (inner, mode)
651 || (memory_operand (inner, mode)
652 && GET_CODE (XEXP (inner, 0)) != PRE_INC
653 && GET_CODE (XEXP (inner, 0)) != PRE_DEC
654 && (GET_CODE (XEXP (inner, 0)) != PLUS
655 || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT
656 || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0));
659 ;; Return 1 if the operand, used inside a MEM, is a SYMBOL_REF.
660 (define_predicate "symbol_ref_operand"
661 (and (match_code "symbol_ref")
662 (match_test "(mode == VOIDmode || GET_MODE (op) == mode)
663 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))")))
665 ;; Return 1 if op is an operand that can be loaded via the GOT.
666 ;; or non-special register register field no cr0
667 (define_predicate "got_operand"
668 (match_code "symbol_ref,const,label_ref"))
670 ;; Return 1 if op is a simple reference that can be loaded via the GOT,
671 ;; excluding labels involving addition.
672 (define_predicate "got_no_const_operand"
673 (match_code "symbol_ref,label_ref"))
675 ;; Return 1 if op is a SYMBOL_REF for a TLS symbol.
676 (define_predicate "rs6000_tls_symbol_ref"
677 (and (match_code "symbol_ref")
678 (match_test "RS6000_SYMBOL_REF_TLS_P (op)")))
680 ;; Return 1 if the operand, used inside a MEM, is a valid first argument
681 ;; to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR.
682 (define_predicate "call_operand"
683 (if_then_else (match_code "reg")
684 (match_test "REGNO (op) == LINK_REGISTER_REGNUM
685 || REGNO (op) == COUNT_REGISTER_REGNUM
686 || REGNO (op) >= FIRST_PSEUDO_REGISTER")
687 (match_code "symbol_ref")))
689 ;; Return 1 if the operand is a SYMBOL_REF for a function known to be in
691 (define_predicate "current_file_function_operand"
692 (and (match_code "symbol_ref")
693 (match_test "(DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
694 && ((SYMBOL_REF_LOCAL_P (op)
695 && (DEFAULT_ABI != ABI_AIX
696 || !SYMBOL_REF_EXTERNAL_P (op)))
697 || (op == XEXP (DECL_RTL (current_function_decl),
700 ;; Return 1 if this operand is a valid input for a move insn.
701 (define_predicate "input_operand"
702 (match_code "label_ref,symbol_ref,const,high,reg,subreg,mem,
703 const_double,const_vector,const_int,plus")
705 /* Memory is always valid. */
706 if (memory_operand (op, mode))
709 /* For floating-point, easy constants are valid. */
710 if (GET_MODE_CLASS (mode) == MODE_FLOAT
712 && easy_fp_constant (op, mode))
715 /* Allow any integer constant. */
716 if (GET_MODE_CLASS (mode) == MODE_INT
717 && (GET_CODE (op) == CONST_INT
718 || GET_CODE (op) == CONST_DOUBLE))
721 /* Allow easy vector constants. */
722 if (GET_CODE (op) == CONST_VECTOR
723 && easy_vector_constant (op, mode))
726 /* Do not allow invalid E500 subregs. */
727 if ((TARGET_E500_DOUBLE || TARGET_SPE)
728 && GET_CODE (op) == SUBREG
729 && invalid_e500_subreg (op, mode))
732 /* For floating-point or multi-word mode, the only remaining valid type
734 if (GET_MODE_CLASS (mode) == MODE_FLOAT
735 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
736 return register_operand (op, mode);
738 /* The only cases left are integral modes one word or smaller (we
739 do not get called for MODE_CC values). These can be in any
741 if (register_operand (op, mode))
744 /* A SYMBOL_REF referring to the TOC is valid. */
745 if (legitimate_constant_pool_address_p (op))
748 /* A constant pool expression (relative to the TOC) is valid */
749 if (toc_relative_expr_p (op))
752 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
754 if (DEFAULT_ABI == ABI_V4
755 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
756 && small_data_operand (op, Pmode))
762 ;; Return true if OP is an invalid SUBREG operation on the e500.
763 (define_predicate "rs6000_nonimmediate_operand"
764 (match_code "reg,subreg,mem")
766 if ((TARGET_E500_DOUBLE || TARGET_SPE)
767 && GET_CODE (op) == SUBREG
768 && invalid_e500_subreg (op, mode))
771 return nonimmediate_operand (op, mode);
774 ;; Return true if operand is boolean operator.
775 (define_predicate "boolean_operator"
776 (match_code "and,ior,xor"))
778 ;; Return true if operand is OR-form of boolean operator.
779 (define_predicate "boolean_or_operator"
780 (match_code "ior,xor"))
782 ;; Return true if operand is an equality operator.
783 (define_special_predicate "equality_operator"
784 (match_code "eq,ne"))
786 ;; Return true if operand is MIN or MAX operator.
787 (define_predicate "min_max_operator"
788 (match_code "smin,smax,umin,umax"))
790 ;; Return 1 if OP is a comparison operation that is valid for a branch
791 ;; instruction. We check the opcode against the mode of the CC value.
792 ;; validate_condition_mode is an assertion.
793 (define_predicate "branch_comparison_operator"
794 (and (match_operand 0 "comparison_operator")
795 (and (match_test "GET_MODE_CLASS (GET_MODE (XEXP (op, 0))) == MODE_CC")
796 (match_test "validate_condition_mode (GET_CODE (op),
797 GET_MODE (XEXP (op, 0))),
800 ;; Return 1 if OP is a comparison operation that is valid for an SCC insn --
801 ;; it must be a positive comparison.
802 (define_predicate "scc_comparison_operator"
803 (and (match_operand 0 "branch_comparison_operator")
804 (match_code "eq,lt,gt,ltu,gtu,unordered")))
806 ;; Return 1 if OP is a comparison operation that is valid for a branch
807 ;; insn, which is true if the corresponding bit in the CC register is set.
808 (define_predicate "branch_positive_comparison_operator"
809 (and (match_operand 0 "branch_comparison_operator")
810 (match_code "eq,lt,gt,ltu,gtu,unordered")))
812 ;; Return 1 is OP is a comparison operation that is valid for a trap insn.
813 (define_predicate "trap_comparison_operator"
814 (and (match_operand 0 "comparison_operator")
815 (match_code "eq,ne,le,lt,ge,gt,leu,ltu,geu,gtu")))
817 ;; Return 1 if OP is a load multiple operation, known to be a PARALLEL.
818 (define_predicate "load_multiple_operation"
819 (match_code "parallel")
821 int count = XVECLEN (op, 0);
822 unsigned int dest_regno;
826 /* Perform a quick check so we don't blow up below. */
828 || GET_CODE (XVECEXP (op, 0, 0)) != SET
829 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
830 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
833 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
834 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
836 for (i = 1; i < count; i++)
838 rtx elt = XVECEXP (op, 0, i);
840 if (GET_CODE (elt) != SET
841 || GET_CODE (SET_DEST (elt)) != REG
842 || GET_MODE (SET_DEST (elt)) != SImode
843 || REGNO (SET_DEST (elt)) != dest_regno + i
844 || GET_CODE (SET_SRC (elt)) != MEM
845 || GET_MODE (SET_SRC (elt)) != SImode
846 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
847 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
848 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
849 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
856 ;; Return 1 if OP is a store multiple operation, known to be a PARALLEL.
857 ;; The second vector element is a CLOBBER.
858 (define_predicate "store_multiple_operation"
859 (match_code "parallel")
861 int count = XVECLEN (op, 0) - 1;
862 unsigned int src_regno;
866 /* Perform a quick check so we don't blow up below. */
868 || GET_CODE (XVECEXP (op, 0, 0)) != SET
869 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
870 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
873 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
874 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
876 for (i = 1; i < count; i++)
878 rtx elt = XVECEXP (op, 0, i + 1);
880 if (GET_CODE (elt) != SET
881 || GET_CODE (SET_SRC (elt)) != REG
882 || GET_MODE (SET_SRC (elt)) != SImode
883 || REGNO (SET_SRC (elt)) != src_regno + i
884 || GET_CODE (SET_DEST (elt)) != MEM
885 || GET_MODE (SET_DEST (elt)) != SImode
886 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
887 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
888 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
889 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
896 ;; Return 1 if OP is valid for a save_world call in prologue, known to be
898 (define_predicate "save_world_operation"
899 (match_code "parallel")
904 int count = XVECLEN (op, 0);
910 if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
911 || GET_CODE (XVECEXP (op, 0, index++)) != USE)
914 for (i=1; i <= 18; i++)
916 elt = XVECEXP (op, 0, index++);
917 if (GET_CODE (elt) != SET
918 || GET_CODE (SET_DEST (elt)) != MEM
919 || ! memory_operand (SET_DEST (elt), DFmode)
920 || GET_CODE (SET_SRC (elt)) != REG
921 || GET_MODE (SET_SRC (elt)) != DFmode)
925 for (i=1; i <= 12; i++)
927 elt = XVECEXP (op, 0, index++);
928 if (GET_CODE (elt) != SET
929 || GET_CODE (SET_DEST (elt)) != MEM
930 || GET_CODE (SET_SRC (elt)) != REG
931 || GET_MODE (SET_SRC (elt)) != V4SImode)
935 for (i=1; i <= 19; i++)
937 elt = XVECEXP (op, 0, index++);
938 if (GET_CODE (elt) != SET
939 || GET_CODE (SET_DEST (elt)) != MEM
940 || ! memory_operand (SET_DEST (elt), Pmode)
941 || GET_CODE (SET_SRC (elt)) != REG
942 || GET_MODE (SET_SRC (elt)) != Pmode)
946 elt = XVECEXP (op, 0, index++);
947 if (GET_CODE (elt) != SET
948 || GET_CODE (SET_DEST (elt)) != MEM
949 || ! memory_operand (SET_DEST (elt), Pmode)
950 || GET_CODE (SET_SRC (elt)) != REG
951 || REGNO (SET_SRC (elt)) != CR2_REGNO
952 || GET_MODE (SET_SRC (elt)) != Pmode)
955 if (GET_CODE (XVECEXP (op, 0, index++)) != USE
956 || GET_CODE (XVECEXP (op, 0, index++)) != USE
957 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
962 ;; Return 1 if OP is valid for a restore_world call in epilogue, known to be
964 (define_predicate "restore_world_operation"
965 (match_code "parallel")
970 int count = XVECLEN (op, 0);
976 if (GET_CODE (XVECEXP (op, 0, index++)) != RETURN
977 || GET_CODE (XVECEXP (op, 0, index++)) != USE
978 || GET_CODE (XVECEXP (op, 0, index++)) != USE
979 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
982 elt = XVECEXP (op, 0, index++);
983 if (GET_CODE (elt) != SET
984 || GET_CODE (SET_SRC (elt)) != MEM
985 || ! memory_operand (SET_SRC (elt), Pmode)
986 || GET_CODE (SET_DEST (elt)) != REG
987 || REGNO (SET_DEST (elt)) != CR2_REGNO
988 || GET_MODE (SET_DEST (elt)) != Pmode)
991 for (i=1; i <= 19; i++)
993 elt = XVECEXP (op, 0, index++);
994 if (GET_CODE (elt) != SET
995 || GET_CODE (SET_SRC (elt)) != MEM
996 || ! memory_operand (SET_SRC (elt), Pmode)
997 || GET_CODE (SET_DEST (elt)) != REG
998 || GET_MODE (SET_DEST (elt)) != Pmode)
1002 for (i=1; i <= 12; i++)
1004 elt = XVECEXP (op, 0, index++);
1005 if (GET_CODE (elt) != SET
1006 || GET_CODE (SET_SRC (elt)) != MEM
1007 || GET_CODE (SET_DEST (elt)) != REG
1008 || GET_MODE (SET_DEST (elt)) != V4SImode)
1012 for (i=1; i <= 18; i++)
1014 elt = XVECEXP (op, 0, index++);
1015 if (GET_CODE (elt) != SET
1016 || GET_CODE (SET_SRC (elt)) != MEM
1017 || ! memory_operand (SET_SRC (elt), DFmode)
1018 || GET_CODE (SET_DEST (elt)) != REG
1019 || GET_MODE (SET_DEST (elt)) != DFmode)
1023 if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1024 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1025 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1026 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1027 || GET_CODE (XVECEXP (op, 0, index++)) != USE)
1032 ;; Return 1 if OP is valid for a vrsave call, known to be a PARALLEL.
1033 (define_predicate "vrsave_operation"
1034 (match_code "parallel")
1036 int count = XVECLEN (op, 0);
1037 unsigned int dest_regno, src_regno;
1041 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1042 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
1043 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE
1044 || XINT (SET_SRC (XVECEXP (op, 0, 0)), 1) != UNSPECV_SET_VRSAVE)
1047 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1048 src_regno = REGNO (XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 1));
1050 if (dest_regno != VRSAVE_REGNO || src_regno != VRSAVE_REGNO)
1053 for (i = 1; i < count; i++)
1055 rtx elt = XVECEXP (op, 0, i);
1057 if (GET_CODE (elt) != CLOBBER
1058 && GET_CODE (elt) != SET)
1065 ;; Return 1 if OP is valid for mfcr insn, known to be a PARALLEL.
1066 (define_predicate "mfcr_operation"
1067 (match_code "parallel")
1069 int count = XVECLEN (op, 0);
1072 /* Perform a quick check so we don't blow up below. */
1074 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1075 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
1076 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
1079 for (i = 0; i < count; i++)
1081 rtx exp = XVECEXP (op, 0, i);
1086 src_reg = XVECEXP (SET_SRC (exp), 0, 0);
1088 if (GET_CODE (src_reg) != REG
1089 || GET_MODE (src_reg) != CCmode
1090 || ! CR_REGNO_P (REGNO (src_reg)))
1093 if (GET_CODE (exp) != SET
1094 || GET_CODE (SET_DEST (exp)) != REG
1095 || GET_MODE (SET_DEST (exp)) != SImode
1096 || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
1098 unspec = SET_SRC (exp);
1099 maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
1101 if (GET_CODE (unspec) != UNSPEC
1102 || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
1103 || XVECLEN (unspec, 0) != 2
1104 || XVECEXP (unspec, 0, 0) != src_reg
1105 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
1106 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
1112 ;; Return 1 if OP is valid for mtcrf insn, known to be a PARALLEL.
1113 (define_predicate "mtcrf_operation"
1114 (match_code "parallel")
1116 int count = XVECLEN (op, 0);
1120 /* Perform a quick check so we don't blow up below. */
1122 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1123 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
1124 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
1126 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
1128 if (GET_CODE (src_reg) != REG
1129 || GET_MODE (src_reg) != SImode
1130 || ! INT_REGNO_P (REGNO (src_reg)))
1133 for (i = 0; i < count; i++)
1135 rtx exp = XVECEXP (op, 0, i);
1139 if (GET_CODE (exp) != SET
1140 || GET_CODE (SET_DEST (exp)) != REG
1141 || GET_MODE (SET_DEST (exp)) != CCmode
1142 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
1144 unspec = SET_SRC (exp);
1145 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
1147 if (GET_CODE (unspec) != UNSPEC
1148 || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
1149 || XVECLEN (unspec, 0) != 2
1150 || XVECEXP (unspec, 0, 0) != src_reg
1151 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
1152 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
1158 ;; Return 1 if OP is valid for lmw insn, known to be a PARALLEL.
1159 (define_predicate "lmw_operation"
1160 (match_code "parallel")
1162 int count = XVECLEN (op, 0);
1163 unsigned int dest_regno;
1165 unsigned int base_regno;
1166 HOST_WIDE_INT offset;
1169 /* Perform a quick check so we don't blow up below. */
1171 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1172 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
1173 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
1176 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1177 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
1180 || count != 32 - (int) dest_regno)
1183 if (legitimate_indirect_address_p (src_addr, 0))
1186 base_regno = REGNO (src_addr);
1187 if (base_regno == 0)
1190 else if (rs6000_legitimate_offset_address_p (SImode, src_addr, 0))
1192 offset = INTVAL (XEXP (src_addr, 1));
1193 base_regno = REGNO (XEXP (src_addr, 0));
1198 for (i = 0; i < count; i++)
1200 rtx elt = XVECEXP (op, 0, i);
1203 HOST_WIDE_INT newoffset;
1205 if (GET_CODE (elt) != SET
1206 || GET_CODE (SET_DEST (elt)) != REG
1207 || GET_MODE (SET_DEST (elt)) != SImode
1208 || REGNO (SET_DEST (elt)) != dest_regno + i
1209 || GET_CODE (SET_SRC (elt)) != MEM
1210 || GET_MODE (SET_SRC (elt)) != SImode)
1212 newaddr = XEXP (SET_SRC (elt), 0);
1213 if (legitimate_indirect_address_p (newaddr, 0))
1218 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0))
1220 addr_reg = XEXP (newaddr, 0);
1221 newoffset = INTVAL (XEXP (newaddr, 1));
1225 if (REGNO (addr_reg) != base_regno
1226 || newoffset != offset + 4 * i)
1233 ;; Return 1 if OP is valid for stmw insn, known to be a PARALLEL.
1234 (define_predicate "stmw_operation"
1235 (match_code "parallel")
1237 int count = XVECLEN (op, 0);
1238 unsigned int src_regno;
1240 unsigned int base_regno;
1241 HOST_WIDE_INT offset;
1244 /* Perform a quick check so we don't blow up below. */
1246 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1247 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
1248 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
1251 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
1252 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
1255 || count != 32 - (int) src_regno)
1258 if (legitimate_indirect_address_p (dest_addr, 0))
1261 base_regno = REGNO (dest_addr);
1262 if (base_regno == 0)
1265 else if (rs6000_legitimate_offset_address_p (SImode, dest_addr, 0))
1267 offset = INTVAL (XEXP (dest_addr, 1));
1268 base_regno = REGNO (XEXP (dest_addr, 0));
1273 for (i = 0; i < count; i++)
1275 rtx elt = XVECEXP (op, 0, i);
1278 HOST_WIDE_INT newoffset;
1280 if (GET_CODE (elt) != SET
1281 || GET_CODE (SET_SRC (elt)) != REG
1282 || GET_MODE (SET_SRC (elt)) != SImode
1283 || REGNO (SET_SRC (elt)) != src_regno + i
1284 || GET_CODE (SET_DEST (elt)) != MEM
1285 || GET_MODE (SET_DEST (elt)) != SImode)
1287 newaddr = XEXP (SET_DEST (elt), 0);
1288 if (legitimate_indirect_address_p (newaddr, 0))
1293 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0))
1295 addr_reg = XEXP (newaddr, 0);
1296 newoffset = INTVAL (XEXP (newaddr, 1));
1300 if (REGNO (addr_reg) != base_regno
1301 || newoffset != offset + 4 * i)