xref: /dflybsd-src/contrib/gcc-4.7/gcc/config/i386/predicates.md (revision 0a8dc9fc45f4d0b236341a473fac4a486375f60c)
1e4b17023SJohn Marino;; Predicate definitions for IA-32 and x86-64.
2e4b17023SJohn Marino;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
3e4b17023SJohn Marino;; Free Software Foundation, Inc.
4e4b17023SJohn Marino;;
5e4b17023SJohn Marino;; This file is part of GCC.
6e4b17023SJohn Marino;;
7e4b17023SJohn Marino;; GCC is free software; you can redistribute it and/or modify
8e4b17023SJohn Marino;; it under the terms of the GNU General Public License as published by
9e4b17023SJohn Marino;; the Free Software Foundation; either version 3, or (at your option)
10e4b17023SJohn Marino;; any later version.
11e4b17023SJohn Marino;;
12e4b17023SJohn Marino;; GCC is distributed in the hope that it will be useful,
13e4b17023SJohn Marino;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14e4b17023SJohn Marino;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15e4b17023SJohn Marino;; GNU General Public License for more details.
16e4b17023SJohn Marino;;
17e4b17023SJohn Marino;; You should have received a copy of the GNU General Public License
18e4b17023SJohn Marino;; along with GCC; see the file COPYING3.  If not see
19e4b17023SJohn Marino;; <http://www.gnu.org/licenses/>.
20e4b17023SJohn Marino
21e4b17023SJohn Marino;; Return true if OP is either a i387 or SSE fp register.
22e4b17023SJohn Marino(define_predicate "any_fp_register_operand"
23e4b17023SJohn Marino  (and (match_code "reg")
24e4b17023SJohn Marino       (match_test "ANY_FP_REGNO_P (REGNO (op))")))
25e4b17023SJohn Marino
26e4b17023SJohn Marino;; Return true if OP is an i387 fp register.
27e4b17023SJohn Marino(define_predicate "fp_register_operand"
28e4b17023SJohn Marino  (and (match_code "reg")
29e4b17023SJohn Marino       (match_test "FP_REGNO_P (REGNO (op))")))
30e4b17023SJohn Marino
31e4b17023SJohn Marino;; Return true if OP is a non-fp register_operand.
32e4b17023SJohn Marino(define_predicate "register_and_not_any_fp_reg_operand"
33e4b17023SJohn Marino  (and (match_code "reg")
34e4b17023SJohn Marino       (not (match_test "ANY_FP_REGNO_P (REGNO (op))"))))
35e4b17023SJohn Marino
36e4b17023SJohn Marino;; Return true if OP is a register operand other than an i387 fp register.
37e4b17023SJohn Marino(define_predicate "register_and_not_fp_reg_operand"
38e4b17023SJohn Marino  (and (match_code "reg")
39e4b17023SJohn Marino       (not (match_test "FP_REGNO_P (REGNO (op))"))))
40e4b17023SJohn Marino
41e4b17023SJohn Marino;; True if the operand is an MMX register.
42e4b17023SJohn Marino(define_predicate "mmx_reg_operand"
43e4b17023SJohn Marino  (and (match_code "reg")
44e4b17023SJohn Marino       (match_test "MMX_REGNO_P (REGNO (op))")))
45e4b17023SJohn Marino
46e4b17023SJohn Marino;; True if the operand is an SSE register.
47e4b17023SJohn Marino(define_predicate "sse_reg_operand"
48e4b17023SJohn Marino  (and (match_code "reg")
49e4b17023SJohn Marino       (match_test "SSE_REGNO_P (REGNO (op))")))
50e4b17023SJohn Marino
51e4b17023SJohn Marino;; True if the operand is a Q_REGS class register.
52e4b17023SJohn Marino(define_predicate "q_regs_operand"
53e4b17023SJohn Marino  (match_operand 0 "register_operand")
54e4b17023SJohn Marino{
55e4b17023SJohn Marino  if (GET_CODE (op) == SUBREG)
56e4b17023SJohn Marino    op = SUBREG_REG (op);
57e4b17023SJohn Marino  return ANY_QI_REG_P (op);
58e4b17023SJohn Marino})
59e4b17023SJohn Marino
60e4b17023SJohn Marino;; Match an SI or HImode register for a zero_extract.
61e4b17023SJohn Marino(define_special_predicate "ext_register_operand"
62e4b17023SJohn Marino  (match_operand 0 "register_operand")
63e4b17023SJohn Marino{
64e4b17023SJohn Marino  if ((!TARGET_64BIT || GET_MODE (op) != DImode)
65e4b17023SJohn Marino      && GET_MODE (op) != SImode && GET_MODE (op) != HImode)
66e4b17023SJohn Marino    return false;
67e4b17023SJohn Marino  if (GET_CODE (op) == SUBREG)
68e4b17023SJohn Marino    op = SUBREG_REG (op);
69e4b17023SJohn Marino
70e4b17023SJohn Marino  /* Be careful to accept only registers having upper parts.  */
71e4b17023SJohn Marino  return (REG_P (op)
72e4b17023SJohn Marino	  && (REGNO (op) > LAST_VIRTUAL_REGISTER || REGNO (op) <= BX_REG));
73e4b17023SJohn Marino})
74e4b17023SJohn Marino
75e4b17023SJohn Marino;; Return true if op is the AX register.
76e4b17023SJohn Marino(define_predicate "ax_reg_operand"
77e4b17023SJohn Marino  (and (match_code "reg")
78e4b17023SJohn Marino       (match_test "REGNO (op) == AX_REG")))
79e4b17023SJohn Marino
80e4b17023SJohn Marino;; Return true if op is the flags register.
81e4b17023SJohn Marino(define_predicate "flags_reg_operand"
82e4b17023SJohn Marino  (and (match_code "reg")
83e4b17023SJohn Marino       (match_test "REGNO (op) == FLAGS_REG")))
84e4b17023SJohn Marino
85e4b17023SJohn Marino;; Return true if op is one of QImode registers: %[abcd][hl].
86e4b17023SJohn Marino(define_predicate "QIreg_operand"
87e4b17023SJohn Marino  (match_test "QI_REG_P (op)"))
88e4b17023SJohn Marino
89e4b17023SJohn Marino;; Return true if op is a QImode register operand other than
90e4b17023SJohn Marino;; %[abcd][hl].
91e4b17023SJohn Marino(define_predicate "ext_QIreg_operand"
92e4b17023SJohn Marino  (and (match_code "reg")
93e4b17023SJohn Marino       (match_test "TARGET_64BIT")
94e4b17023SJohn Marino       (match_test "REGNO (op) > BX_REG")))
95e4b17023SJohn Marino
96e4b17023SJohn Marino;; Return true if op is not xmm0 register.
97e4b17023SJohn Marino(define_predicate "reg_not_xmm0_operand"
98e4b17023SJohn Marino  (match_operand 0 "register_operand")
99e4b17023SJohn Marino{
100e4b17023SJohn Marino  if (GET_CODE (op) == SUBREG)
101e4b17023SJohn Marino    op = SUBREG_REG (op);
102e4b17023SJohn Marino
103e4b17023SJohn Marino  return !REG_P (op) || REGNO (op) != FIRST_SSE_REG;
104e4b17023SJohn Marino})
105e4b17023SJohn Marino
106e4b17023SJohn Marino;; As above, but also allow memory operands.
107e4b17023SJohn Marino(define_predicate "nonimm_not_xmm0_operand"
108e4b17023SJohn Marino  (ior (match_operand 0 "memory_operand")
109e4b17023SJohn Marino       (match_operand 0 "reg_not_xmm0_operand")))
110e4b17023SJohn Marino
111e4b17023SJohn Marino;; Return true if op is not xmm0 register, but only for non-AVX targets.
112e4b17023SJohn Marino(define_predicate "reg_not_xmm0_operand_maybe_avx"
113e4b17023SJohn Marino  (if_then_else (match_test "TARGET_AVX")
114e4b17023SJohn Marino    (match_operand 0 "register_operand")
115e4b17023SJohn Marino    (match_operand 0 "reg_not_xmm0_operand")))
116e4b17023SJohn Marino
117e4b17023SJohn Marino;; As above, but also allow memory operands.
118e4b17023SJohn Marino(define_predicate "nonimm_not_xmm0_operand_maybe_avx"
119e4b17023SJohn Marino  (if_then_else (match_test "TARGET_AVX")
120e4b17023SJohn Marino    (match_operand 0 "nonimmediate_operand")
121e4b17023SJohn Marino    (match_operand 0 "nonimm_not_xmm0_operand")))
122e4b17023SJohn Marino
123e4b17023SJohn Marino;; Return true if VALUE can be stored in a sign extended immediate field.
124e4b17023SJohn Marino(define_predicate "x86_64_immediate_operand"
125e4b17023SJohn Marino  (match_code "const_int,symbol_ref,label_ref,const")
126e4b17023SJohn Marino{
127e4b17023SJohn Marino  if (!TARGET_64BIT)
128e4b17023SJohn Marino    return immediate_operand (op, mode);
129e4b17023SJohn Marino
130e4b17023SJohn Marino  switch (GET_CODE (op))
131e4b17023SJohn Marino    {
132e4b17023SJohn Marino    case CONST_INT:
133e4b17023SJohn Marino      /* CONST_DOUBLES never match, since HOST_BITS_PER_WIDE_INT is known
134e4b17023SJohn Marino         to be at least 32 and this all acceptable constants are
135e4b17023SJohn Marino	 represented as CONST_INT.  */
136e4b17023SJohn Marino      if (HOST_BITS_PER_WIDE_INT == 32)
137e4b17023SJohn Marino	return true;
138e4b17023SJohn Marino      else
139e4b17023SJohn Marino	{
140e4b17023SJohn Marino	  HOST_WIDE_INT val = trunc_int_for_mode (INTVAL (op), DImode);
141e4b17023SJohn Marino	  return trunc_int_for_mode (val, SImode) == val;
142e4b17023SJohn Marino	}
143e4b17023SJohn Marino      break;
144e4b17023SJohn Marino
145e4b17023SJohn Marino    case SYMBOL_REF:
146e4b17023SJohn Marino      /* For certain code models, the symbolic references are known to fit.
147e4b17023SJohn Marino	 in CM_SMALL_PIC model we know it fits if it is local to the shared
148e4b17023SJohn Marino	 library.  Don't count TLS SYMBOL_REFs here, since they should fit
149e4b17023SJohn Marino	 only if inside of UNSPEC handled below.  */
150e4b17023SJohn Marino      /* TLS symbols are not constant.  */
151e4b17023SJohn Marino      if (SYMBOL_REF_TLS_MODEL (op))
152e4b17023SJohn Marino	return false;
153e4b17023SJohn Marino      return (ix86_cmodel == CM_SMALL || ix86_cmodel == CM_KERNEL
154e4b17023SJohn Marino	      || (ix86_cmodel == CM_MEDIUM && !SYMBOL_REF_FAR_ADDR_P (op)));
155e4b17023SJohn Marino
156e4b17023SJohn Marino    case LABEL_REF:
157e4b17023SJohn Marino      /* For certain code models, the code is near as well.  */
158e4b17023SJohn Marino      return (ix86_cmodel == CM_SMALL || ix86_cmodel == CM_MEDIUM
159e4b17023SJohn Marino	      || ix86_cmodel == CM_KERNEL);
160e4b17023SJohn Marino
161e4b17023SJohn Marino    case CONST:
162e4b17023SJohn Marino      /* We also may accept the offsetted memory references in certain
163e4b17023SJohn Marino	 special cases.  */
164e4b17023SJohn Marino      if (GET_CODE (XEXP (op, 0)) == UNSPEC)
165e4b17023SJohn Marino	switch (XINT (XEXP (op, 0), 1))
166e4b17023SJohn Marino	  {
167e4b17023SJohn Marino	  case UNSPEC_GOTPCREL:
168e4b17023SJohn Marino	  case UNSPEC_DTPOFF:
169e4b17023SJohn Marino	  case UNSPEC_GOTNTPOFF:
170e4b17023SJohn Marino	  case UNSPEC_NTPOFF:
171e4b17023SJohn Marino	    return true;
172e4b17023SJohn Marino	  default:
173e4b17023SJohn Marino	    break;
174e4b17023SJohn Marino	  }
175e4b17023SJohn Marino
176e4b17023SJohn Marino      if (GET_CODE (XEXP (op, 0)) == PLUS)
177e4b17023SJohn Marino	{
178e4b17023SJohn Marino	  rtx op1 = XEXP (XEXP (op, 0), 0);
179e4b17023SJohn Marino	  rtx op2 = XEXP (XEXP (op, 0), 1);
180e4b17023SJohn Marino	  HOST_WIDE_INT offset;
181e4b17023SJohn Marino
182e4b17023SJohn Marino	  if (ix86_cmodel == CM_LARGE)
183e4b17023SJohn Marino	    return false;
184e4b17023SJohn Marino	  if (!CONST_INT_P (op2))
185e4b17023SJohn Marino	    return false;
186e4b17023SJohn Marino	  offset = trunc_int_for_mode (INTVAL (op2), DImode);
187e4b17023SJohn Marino	  switch (GET_CODE (op1))
188e4b17023SJohn Marino	    {
189e4b17023SJohn Marino	    case SYMBOL_REF:
190e4b17023SJohn Marino	      /* TLS symbols are not constant.  */
191e4b17023SJohn Marino	      if (SYMBOL_REF_TLS_MODEL (op1))
192e4b17023SJohn Marino		return false;
193e4b17023SJohn Marino	      /* For CM_SMALL assume that latest object is 16MB before
194e4b17023SJohn Marino		 end of 31bits boundary.  We may also accept pretty
195e4b17023SJohn Marino		 large negative constants knowing that all objects are
196e4b17023SJohn Marino		 in the positive half of address space.  */
197e4b17023SJohn Marino	      if ((ix86_cmodel == CM_SMALL
198e4b17023SJohn Marino		   || (ix86_cmodel == CM_MEDIUM
199e4b17023SJohn Marino		       && !SYMBOL_REF_FAR_ADDR_P (op1)))
200e4b17023SJohn Marino		  && offset < 16*1024*1024
201e4b17023SJohn Marino		  && trunc_int_for_mode (offset, SImode) == offset)
202e4b17023SJohn Marino		return true;
203e4b17023SJohn Marino	      /* For CM_KERNEL we know that all object resist in the
204e4b17023SJohn Marino		 negative half of 32bits address space.  We may not
205e4b17023SJohn Marino		 accept negative offsets, since they may be just off
206e4b17023SJohn Marino		 and we may accept pretty large positive ones.  */
207e4b17023SJohn Marino	      if (ix86_cmodel == CM_KERNEL
208e4b17023SJohn Marino		  && offset > 0
209e4b17023SJohn Marino		  && trunc_int_for_mode (offset, SImode) == offset)
210e4b17023SJohn Marino		return true;
211e4b17023SJohn Marino	      break;
212e4b17023SJohn Marino
213e4b17023SJohn Marino	    case LABEL_REF:
214e4b17023SJohn Marino	      /* These conditions are similar to SYMBOL_REF ones, just the
215e4b17023SJohn Marino		 constraints for code models differ.  */
216e4b17023SJohn Marino	      if ((ix86_cmodel == CM_SMALL || ix86_cmodel == CM_MEDIUM)
217e4b17023SJohn Marino		  && offset < 16*1024*1024
218e4b17023SJohn Marino		  && trunc_int_for_mode (offset, SImode) == offset)
219e4b17023SJohn Marino		return true;
220e4b17023SJohn Marino	      if (ix86_cmodel == CM_KERNEL
221e4b17023SJohn Marino		  && offset > 0
222e4b17023SJohn Marino		  && trunc_int_for_mode (offset, SImode) == offset)
223e4b17023SJohn Marino		return true;
224e4b17023SJohn Marino	      break;
225e4b17023SJohn Marino
226e4b17023SJohn Marino	    case UNSPEC:
227e4b17023SJohn Marino	      switch (XINT (op1, 1))
228e4b17023SJohn Marino		{
229e4b17023SJohn Marino		case UNSPEC_DTPOFF:
230e4b17023SJohn Marino		case UNSPEC_NTPOFF:
231e4b17023SJohn Marino		  if (offset > 0
232e4b17023SJohn Marino		      && trunc_int_for_mode (offset, SImode) == offset)
233e4b17023SJohn Marino		    return true;
234e4b17023SJohn Marino		}
235e4b17023SJohn Marino	      break;
236e4b17023SJohn Marino
237e4b17023SJohn Marino	    default:
238e4b17023SJohn Marino	      break;
239e4b17023SJohn Marino	    }
240e4b17023SJohn Marino	}
241e4b17023SJohn Marino      break;
242e4b17023SJohn Marino
243e4b17023SJohn Marino      default:
244e4b17023SJohn Marino	gcc_unreachable ();
245e4b17023SJohn Marino    }
246e4b17023SJohn Marino
247e4b17023SJohn Marino  return false;
248e4b17023SJohn Marino})
249e4b17023SJohn Marino
250e4b17023SJohn Marino;; Return true if VALUE can be stored in the zero extended immediate field.
251e4b17023SJohn Marino(define_predicate "x86_64_zext_immediate_operand"
252e4b17023SJohn Marino  (match_code "const_double,const_int,symbol_ref,label_ref,const")
253e4b17023SJohn Marino{
254e4b17023SJohn Marino  switch (GET_CODE (op))
255e4b17023SJohn Marino    {
256e4b17023SJohn Marino    case CONST_DOUBLE:
257e4b17023SJohn Marino      if (HOST_BITS_PER_WIDE_INT == 32)
258e4b17023SJohn Marino	return (GET_MODE (op) == VOIDmode && !CONST_DOUBLE_HIGH (op));
259e4b17023SJohn Marino      else
260e4b17023SJohn Marino	return false;
261e4b17023SJohn Marino
262e4b17023SJohn Marino    case CONST_INT:
263e4b17023SJohn Marino      if (HOST_BITS_PER_WIDE_INT == 32)
264e4b17023SJohn Marino	return INTVAL (op) >= 0;
265e4b17023SJohn Marino      else
266e4b17023SJohn Marino	return !(INTVAL (op) & ~(HOST_WIDE_INT) 0xffffffff);
267e4b17023SJohn Marino
268e4b17023SJohn Marino    case SYMBOL_REF:
269e4b17023SJohn Marino      /* For certain code models, the symbolic references are known to fit.  */
270e4b17023SJohn Marino      /* TLS symbols are not constant.  */
271e4b17023SJohn Marino      if (SYMBOL_REF_TLS_MODEL (op))
272e4b17023SJohn Marino	return false;
273e4b17023SJohn Marino      return (ix86_cmodel == CM_SMALL
274e4b17023SJohn Marino	      || (ix86_cmodel == CM_MEDIUM
275e4b17023SJohn Marino		  && !SYMBOL_REF_FAR_ADDR_P (op)));
276e4b17023SJohn Marino
277e4b17023SJohn Marino    case LABEL_REF:
278e4b17023SJohn Marino      /* For certain code models, the code is near as well.  */
279e4b17023SJohn Marino      return ix86_cmodel == CM_SMALL || ix86_cmodel == CM_MEDIUM;
280e4b17023SJohn Marino
281e4b17023SJohn Marino    case CONST:
282e4b17023SJohn Marino      /* We also may accept the offsetted memory references in certain
283e4b17023SJohn Marino	 special cases.  */
284e4b17023SJohn Marino      if (GET_CODE (XEXP (op, 0)) == PLUS)
285e4b17023SJohn Marino	{
286e4b17023SJohn Marino	  rtx op1 = XEXP (XEXP (op, 0), 0);
287e4b17023SJohn Marino	  rtx op2 = XEXP (XEXP (op, 0), 1);
288e4b17023SJohn Marino
289e4b17023SJohn Marino	  if (ix86_cmodel == CM_LARGE)
290e4b17023SJohn Marino	    return false;
291e4b17023SJohn Marino	  switch (GET_CODE (op1))
292e4b17023SJohn Marino	    {
293e4b17023SJohn Marino	    case SYMBOL_REF:
294e4b17023SJohn Marino	      /* TLS symbols are not constant.  */
295e4b17023SJohn Marino	      if (SYMBOL_REF_TLS_MODEL (op1))
296e4b17023SJohn Marino		return false;
297e4b17023SJohn Marino	      /* For small code model we may accept pretty large positive
298e4b17023SJohn Marino		 offsets, since one bit is available for free.  Negative
299e4b17023SJohn Marino		 offsets are limited by the size of NULL pointer area
300e4b17023SJohn Marino		 specified by the ABI.  */
301e4b17023SJohn Marino	      if ((ix86_cmodel == CM_SMALL
302e4b17023SJohn Marino		   || (ix86_cmodel == CM_MEDIUM
303e4b17023SJohn Marino		       && !SYMBOL_REF_FAR_ADDR_P (op1)))
304e4b17023SJohn Marino		  && CONST_INT_P (op2)
305e4b17023SJohn Marino		  && trunc_int_for_mode (INTVAL (op2), DImode) > -0x10000
306e4b17023SJohn Marino		  && trunc_int_for_mode (INTVAL (op2), SImode) == INTVAL (op2))
307e4b17023SJohn Marino		return true;
308e4b17023SJohn Marino	      /* ??? For the kernel, we may accept adjustment of
309e4b17023SJohn Marino		 -0x10000000, since we know that it will just convert
310e4b17023SJohn Marino		 negative address space to positive, but perhaps this
311e4b17023SJohn Marino		 is not worthwhile.  */
312e4b17023SJohn Marino	      break;
313e4b17023SJohn Marino
314e4b17023SJohn Marino	    case LABEL_REF:
315e4b17023SJohn Marino	      /* These conditions are similar to SYMBOL_REF ones, just the
316e4b17023SJohn Marino		 constraints for code models differ.  */
317e4b17023SJohn Marino	      if ((ix86_cmodel == CM_SMALL || ix86_cmodel == CM_MEDIUM)
318e4b17023SJohn Marino		  && CONST_INT_P (op2)
319e4b17023SJohn Marino		  && trunc_int_for_mode (INTVAL (op2), DImode) > -0x10000
320e4b17023SJohn Marino		  && trunc_int_for_mode (INTVAL (op2), SImode) == INTVAL (op2))
321e4b17023SJohn Marino		return true;
322e4b17023SJohn Marino	      break;
323e4b17023SJohn Marino
324e4b17023SJohn Marino	    default:
325e4b17023SJohn Marino	      return false;
326e4b17023SJohn Marino	    }
327e4b17023SJohn Marino	}
328e4b17023SJohn Marino      break;
329e4b17023SJohn Marino
330e4b17023SJohn Marino    default:
331e4b17023SJohn Marino      gcc_unreachable ();
332e4b17023SJohn Marino    }
333e4b17023SJohn Marino  return false;
334e4b17023SJohn Marino})
335e4b17023SJohn Marino
336e4b17023SJohn Marino;; Return true if OP is general operand representable on x86_64.
337e4b17023SJohn Marino(define_predicate "x86_64_general_operand"
338e4b17023SJohn Marino  (if_then_else (match_test "TARGET_64BIT")
339e4b17023SJohn Marino    (ior (match_operand 0 "nonimmediate_operand")
340e4b17023SJohn Marino	 (match_operand 0 "x86_64_immediate_operand"))
341e4b17023SJohn Marino    (match_operand 0 "general_operand")))
342e4b17023SJohn Marino
343e4b17023SJohn Marino;; Return true if OP is general operand representable on x86_64
344e4b17023SJohn Marino;; as either sign extended or zero extended constant.
345e4b17023SJohn Marino(define_predicate "x86_64_szext_general_operand"
346e4b17023SJohn Marino  (if_then_else (match_test "TARGET_64BIT")
347e4b17023SJohn Marino    (ior (match_operand 0 "nonimmediate_operand")
348e4b17023SJohn Marino	 (match_operand 0 "x86_64_immediate_operand")
349e4b17023SJohn Marino	 (match_operand 0 "x86_64_zext_immediate_operand"))
350e4b17023SJohn Marino    (match_operand 0 "general_operand")))
351e4b17023SJohn Marino
352e4b17023SJohn Marino;; Return true if OP is nonmemory operand representable on x86_64.
353e4b17023SJohn Marino(define_predicate "x86_64_nonmemory_operand"
354e4b17023SJohn Marino  (if_then_else (match_test "TARGET_64BIT")
355e4b17023SJohn Marino    (ior (match_operand 0 "register_operand")
356e4b17023SJohn Marino	 (match_operand 0 "x86_64_immediate_operand"))
357e4b17023SJohn Marino    (match_operand 0 "nonmemory_operand")))
358e4b17023SJohn Marino
359e4b17023SJohn Marino;; Return true if OP is nonmemory operand representable on x86_64.
360e4b17023SJohn Marino(define_predicate "x86_64_szext_nonmemory_operand"
361e4b17023SJohn Marino  (if_then_else (match_test "TARGET_64BIT")
362e4b17023SJohn Marino    (ior (match_operand 0 "register_operand")
363e4b17023SJohn Marino	 (match_operand 0 "x86_64_immediate_operand")
364e4b17023SJohn Marino	 (match_operand 0 "x86_64_zext_immediate_operand"))
365e4b17023SJohn Marino    (match_operand 0 "nonmemory_operand")))
366e4b17023SJohn Marino
367e4b17023SJohn Marino;; Return true when operand is PIC expression that can be computed by lea
368e4b17023SJohn Marino;; operation.
369e4b17023SJohn Marino(define_predicate "pic_32bit_operand"
370e4b17023SJohn Marino  (match_code "const,symbol_ref,label_ref")
371e4b17023SJohn Marino{
372e4b17023SJohn Marino  if (!flag_pic)
373e4b17023SJohn Marino    return false;
374e4b17023SJohn Marino
375e4b17023SJohn Marino  /* Rule out relocations that translate into 64bit constants.  */
376e4b17023SJohn Marino  if (TARGET_64BIT && GET_CODE (op) == CONST)
377e4b17023SJohn Marino    {
378e4b17023SJohn Marino      op = XEXP (op, 0);
379e4b17023SJohn Marino      if (GET_CODE (op) == PLUS && CONST_INT_P (XEXP (op, 1)))
380e4b17023SJohn Marino	op = XEXP (op, 0);
381e4b17023SJohn Marino      if (GET_CODE (op) == UNSPEC
382e4b17023SJohn Marino	  && (XINT (op, 1) == UNSPEC_GOTOFF
383e4b17023SJohn Marino	      || XINT (op, 1) == UNSPEC_GOT))
384e4b17023SJohn Marino	return false;
385e4b17023SJohn Marino    }
386e4b17023SJohn Marino
387e4b17023SJohn Marino  return symbolic_operand (op, mode);
388e4b17023SJohn Marino})
389e4b17023SJohn Marino
390e4b17023SJohn Marino;; Return true if OP is nonmemory operand acceptable by movabs patterns.
391e4b17023SJohn Marino(define_predicate "x86_64_movabs_operand"
392e4b17023SJohn Marino  (and (match_operand 0 "nonmemory_operand")
393e4b17023SJohn Marino       (not (match_operand 0 "pic_32bit_operand"))))
394e4b17023SJohn Marino
395e4b17023SJohn Marino;; Return true if OP is either a symbol reference or a sum of a symbol
396e4b17023SJohn Marino;; reference and a constant.
397e4b17023SJohn Marino(define_predicate "symbolic_operand"
398e4b17023SJohn Marino  (match_code "symbol_ref,label_ref,const")
399e4b17023SJohn Marino{
400e4b17023SJohn Marino  switch (GET_CODE (op))
401e4b17023SJohn Marino    {
402e4b17023SJohn Marino    case SYMBOL_REF:
403e4b17023SJohn Marino    case LABEL_REF:
404e4b17023SJohn Marino      return true;
405e4b17023SJohn Marino
406e4b17023SJohn Marino    case CONST:
407e4b17023SJohn Marino      op = XEXP (op, 0);
408e4b17023SJohn Marino      if (GET_CODE (op) == SYMBOL_REF
409e4b17023SJohn Marino	  || GET_CODE (op) == LABEL_REF
410e4b17023SJohn Marino	  || (GET_CODE (op) == UNSPEC
411e4b17023SJohn Marino	      && (XINT (op, 1) == UNSPEC_GOT
412e4b17023SJohn Marino		  || XINT (op, 1) == UNSPEC_GOTOFF
413e4b17023SJohn Marino		  || XINT (op, 1) == UNSPEC_PCREL
414e4b17023SJohn Marino		  || XINT (op, 1) == UNSPEC_GOTPCREL)))
415e4b17023SJohn Marino	return true;
416e4b17023SJohn Marino      if (GET_CODE (op) != PLUS
417e4b17023SJohn Marino	  || !CONST_INT_P (XEXP (op, 1)))
418e4b17023SJohn Marino	return false;
419e4b17023SJohn Marino
420e4b17023SJohn Marino      op = XEXP (op, 0);
421e4b17023SJohn Marino      if (GET_CODE (op) == SYMBOL_REF
422e4b17023SJohn Marino	  || GET_CODE (op) == LABEL_REF)
423e4b17023SJohn Marino	return true;
424e4b17023SJohn Marino      /* Only @GOTOFF gets offsets.  */
425e4b17023SJohn Marino      if (GET_CODE (op) != UNSPEC
426e4b17023SJohn Marino	  || XINT (op, 1) != UNSPEC_GOTOFF)
427e4b17023SJohn Marino	return false;
428e4b17023SJohn Marino
429e4b17023SJohn Marino      op = XVECEXP (op, 0, 0);
430e4b17023SJohn Marino      if (GET_CODE (op) == SYMBOL_REF
431e4b17023SJohn Marino	  || GET_CODE (op) == LABEL_REF)
432e4b17023SJohn Marino	return true;
433e4b17023SJohn Marino      return false;
434e4b17023SJohn Marino
435e4b17023SJohn Marino    default:
436e4b17023SJohn Marino      gcc_unreachable ();
437e4b17023SJohn Marino    }
438e4b17023SJohn Marino})
439e4b17023SJohn Marino
440e4b17023SJohn Marino;; Return true if OP is a symbolic operand that resolves locally.
441e4b17023SJohn Marino(define_predicate "local_symbolic_operand"
442e4b17023SJohn Marino  (match_code "const,label_ref,symbol_ref")
443e4b17023SJohn Marino{
444e4b17023SJohn Marino  if (GET_CODE (op) == CONST
445e4b17023SJohn Marino      && GET_CODE (XEXP (op, 0)) == PLUS
446e4b17023SJohn Marino      && CONST_INT_P (XEXP (XEXP (op, 0), 1)))
447e4b17023SJohn Marino    op = XEXP (XEXP (op, 0), 0);
448e4b17023SJohn Marino
449e4b17023SJohn Marino  if (GET_CODE (op) == LABEL_REF)
450e4b17023SJohn Marino    return true;
451e4b17023SJohn Marino
452e4b17023SJohn Marino  if (GET_CODE (op) != SYMBOL_REF)
453e4b17023SJohn Marino    return false;
454e4b17023SJohn Marino
455e4b17023SJohn Marino  if (SYMBOL_REF_TLS_MODEL (op))
456e4b17023SJohn Marino    return false;
457e4b17023SJohn Marino
458e4b17023SJohn Marino  if (SYMBOL_REF_LOCAL_P (op))
459e4b17023SJohn Marino    return true;
460e4b17023SJohn Marino
461e4b17023SJohn Marino  /* There is, however, a not insubstantial body of code in the rest of
462e4b17023SJohn Marino     the compiler that assumes it can just stick the results of
463e4b17023SJohn Marino     ASM_GENERATE_INTERNAL_LABEL in a symbol_ref and have done.  */
464e4b17023SJohn Marino  /* ??? This is a hack.  Should update the body of the compiler to
465e4b17023SJohn Marino     always create a DECL an invoke targetm.encode_section_info.  */
466e4b17023SJohn Marino  if (strncmp (XSTR (op, 0), internal_label_prefix,
467e4b17023SJohn Marino	       internal_label_prefix_len) == 0)
468e4b17023SJohn Marino    return true;
469e4b17023SJohn Marino
470e4b17023SJohn Marino  return false;
471e4b17023SJohn Marino})
472e4b17023SJohn Marino
473e4b17023SJohn Marino;; Test for a legitimate @GOTOFF operand.
474e4b17023SJohn Marino;;
475e4b17023SJohn Marino;; VxWorks does not impose a fixed gap between segments; the run-time
476e4b17023SJohn Marino;; gap can be different from the object-file gap.  We therefore can't
477e4b17023SJohn Marino;; use @GOTOFF unless we are absolutely sure that the symbol is in the
478e4b17023SJohn Marino;; same segment as the GOT.  Unfortunately, the flexibility of linker
479e4b17023SJohn Marino;; scripts means that we can't be sure of that in general, so assume
480e4b17023SJohn Marino;; that @GOTOFF is never valid on VxWorks.
481e4b17023SJohn Marino(define_predicate "gotoff_operand"
482e4b17023SJohn Marino  (and (not (match_test "TARGET_VXWORKS_RTP"))
483e4b17023SJohn Marino       (match_operand 0 "local_symbolic_operand")))
484e4b17023SJohn Marino
485e4b17023SJohn Marino;; Test for various thread-local symbols.
486e4b17023SJohn Marino(define_predicate "tls_symbolic_operand"
487e4b17023SJohn Marino  (and (match_code "symbol_ref")
488e4b17023SJohn Marino       (match_test "SYMBOL_REF_TLS_MODEL (op)")))
489e4b17023SJohn Marino
490e4b17023SJohn Marino(define_predicate "tls_modbase_operand"
491e4b17023SJohn Marino  (and (match_code "symbol_ref")
492e4b17023SJohn Marino       (match_test "op == ix86_tls_module_base ()")))
493e4b17023SJohn Marino
494e4b17023SJohn Marino;; Test for a pc-relative call operand
495e4b17023SJohn Marino(define_predicate "constant_call_address_operand"
496e4b17023SJohn Marino  (match_code "symbol_ref")
497e4b17023SJohn Marino{
498e4b17023SJohn Marino  if (ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
499e4b17023SJohn Marino    return false;
500e4b17023SJohn Marino  if (TARGET_DLLIMPORT_DECL_ATTRIBUTES && SYMBOL_REF_DLLIMPORT_P (op))
501e4b17023SJohn Marino    return false;
502e4b17023SJohn Marino  return true;
503e4b17023SJohn Marino})
504e4b17023SJohn Marino
505e4b17023SJohn Marino;; P6 processors will jump to the address after the decrement when %esp
506e4b17023SJohn Marino;; is used as a call operand, so they will execute return address as a code.
507e4b17023SJohn Marino;; See Pentium Pro errata 70, Pentium 2 errata A33 and Pentium 3 errata E17.
508e4b17023SJohn Marino
509e4b17023SJohn Marino(define_predicate "call_register_no_elim_operand"
510e4b17023SJohn Marino  (match_operand 0 "register_operand")
511e4b17023SJohn Marino{
512e4b17023SJohn Marino  if (GET_CODE (op) == SUBREG)
513e4b17023SJohn Marino    op = SUBREG_REG (op);
514e4b17023SJohn Marino
515e4b17023SJohn Marino  if (!TARGET_64BIT && op == stack_pointer_rtx)
516e4b17023SJohn Marino    return false;
517e4b17023SJohn Marino
518e4b17023SJohn Marino  return register_no_elim_operand (op, mode);
519e4b17023SJohn Marino})
520e4b17023SJohn Marino
521e4b17023SJohn Marino;; True for any non-virtual or eliminable register.  Used in places where
522e4b17023SJohn Marino;; instantiation of such a register may cause the pattern to not be recognized.
523e4b17023SJohn Marino(define_predicate "register_no_elim_operand"
524e4b17023SJohn Marino  (match_operand 0 "register_operand")
525e4b17023SJohn Marino{
526e4b17023SJohn Marino  if (GET_CODE (op) == SUBREG)
527e4b17023SJohn Marino    op = SUBREG_REG (op);
528e4b17023SJohn Marino  return !(op == arg_pointer_rtx
529e4b17023SJohn Marino	   || op == frame_pointer_rtx
530e4b17023SJohn Marino	   || IN_RANGE (REGNO (op),
531e4b17023SJohn Marino			FIRST_PSEUDO_REGISTER, LAST_VIRTUAL_REGISTER));
532e4b17023SJohn Marino})
533e4b17023SJohn Marino
534e4b17023SJohn Marino;; Similarly, but include the stack pointer.  This is used to prevent esp
535e4b17023SJohn Marino;; from being used as an index reg.
536e4b17023SJohn Marino(define_predicate "index_register_operand"
537e4b17023SJohn Marino  (match_operand 0 "register_operand")
538e4b17023SJohn Marino{
539e4b17023SJohn Marino  if (GET_CODE (op) == SUBREG)
540e4b17023SJohn Marino    op = SUBREG_REG (op);
541e4b17023SJohn Marino  if (reload_in_progress || reload_completed)
542e4b17023SJohn Marino    return REG_OK_FOR_INDEX_STRICT_P (op);
543e4b17023SJohn Marino  else
544e4b17023SJohn Marino    return REG_OK_FOR_INDEX_NONSTRICT_P (op);
545e4b17023SJohn Marino})
546e4b17023SJohn Marino
547e4b17023SJohn Marino;; Return false if this is any eliminable register.  Otherwise general_operand.
548e4b17023SJohn Marino(define_predicate "general_no_elim_operand"
549e4b17023SJohn Marino  (if_then_else (match_code "reg,subreg")
550e4b17023SJohn Marino    (match_operand 0 "register_no_elim_operand")
551e4b17023SJohn Marino    (match_operand 0 "general_operand")))
552e4b17023SJohn Marino
553e4b17023SJohn Marino;; Return false if this is any eliminable register.  Otherwise
554e4b17023SJohn Marino;; register_operand or a constant.
555e4b17023SJohn Marino(define_predicate "nonmemory_no_elim_operand"
556e4b17023SJohn Marino  (ior (match_operand 0 "register_no_elim_operand")
557e4b17023SJohn Marino       (match_operand 0 "immediate_operand")))
558e4b17023SJohn Marino
559e4b17023SJohn Marino;; Test for a valid operand for indirect branch.
560e4b17023SJohn Marino(define_predicate "indirect_branch_operand"
561e4b17023SJohn Marino  (if_then_else (match_test "TARGET_X32")
562e4b17023SJohn Marino    (match_operand 0 "register_operand")
563e4b17023SJohn Marino    (match_operand 0 "nonimmediate_operand")))
564e4b17023SJohn Marino
565e4b17023SJohn Marino;; Test for a valid operand for a call instruction.
566e4b17023SJohn Marino(define_predicate "call_insn_operand"
567e4b17023SJohn Marino  (ior (match_operand 0 "constant_call_address_operand")
568e4b17023SJohn Marino       (match_operand 0 "call_register_no_elim_operand")
569e4b17023SJohn Marino       (and (not (match_test "TARGET_X32"))
570e4b17023SJohn Marino	    (match_operand 0 "memory_operand"))))
571e4b17023SJohn Marino
572e4b17023SJohn Marino;; Similarly, but for tail calls, in which we cannot allow memory references.
573e4b17023SJohn Marino(define_predicate "sibcall_insn_operand"
574e4b17023SJohn Marino  (ior (match_operand 0 "constant_call_address_operand")
575e4b17023SJohn Marino       (match_operand 0 "register_no_elim_operand")))
576e4b17023SJohn Marino
577e4b17023SJohn Marino;; Match exactly zero.
578e4b17023SJohn Marino(define_predicate "const0_operand"
579e4b17023SJohn Marino  (match_code "const_int,const_double,const_vector")
580e4b17023SJohn Marino{
581e4b17023SJohn Marino  if (mode == VOIDmode)
582e4b17023SJohn Marino    mode = GET_MODE (op);
583e4b17023SJohn Marino  return op == CONST0_RTX (mode);
584e4b17023SJohn Marino})
585e4b17023SJohn Marino
586e4b17023SJohn Marino;; Match exactly one.
587e4b17023SJohn Marino(define_predicate "const1_operand"
588e4b17023SJohn Marino  (and (match_code "const_int")
589e4b17023SJohn Marino       (match_test "op == const1_rtx")))
590e4b17023SJohn Marino
591e4b17023SJohn Marino;; Match exactly eight.
592e4b17023SJohn Marino(define_predicate "const8_operand"
593e4b17023SJohn Marino  (and (match_code "const_int")
594e4b17023SJohn Marino       (match_test "INTVAL (op) == 8")))
595e4b17023SJohn Marino
596e4b17023SJohn Marino;; Match exactly 128.
597e4b17023SJohn Marino(define_predicate "const128_operand"
598e4b17023SJohn Marino  (and (match_code "const_int")
599e4b17023SJohn Marino       (match_test "INTVAL (op) == 128")))
600e4b17023SJohn Marino
601e4b17023SJohn Marino;; Match exactly 0x0FFFFFFFF in anddi as a zero-extension operation
602e4b17023SJohn Marino(define_predicate "const_32bit_mask"
603e4b17023SJohn Marino  (and (match_code "const_int")
604e4b17023SJohn Marino       (match_test "trunc_int_for_mode (INTVAL (op), DImode)
605e4b17023SJohn Marino		    == (HOST_WIDE_INT) 0xffffffff")))
606e4b17023SJohn Marino
607e4b17023SJohn Marino;; Match 2, 4, or 8.  Used for leal multiplicands.
608e4b17023SJohn Marino(define_predicate "const248_operand"
609e4b17023SJohn Marino  (match_code "const_int")
610e4b17023SJohn Marino{
611e4b17023SJohn Marino  HOST_WIDE_INT i = INTVAL (op);
612e4b17023SJohn Marino  return i == 2 || i == 4 || i == 8;
613e4b17023SJohn Marino})
614e4b17023SJohn Marino
615e4b17023SJohn Marino;; Match 1, 2, 4, or 8
616e4b17023SJohn Marino(define_predicate "const1248_operand"
617e4b17023SJohn Marino  (match_code "const_int")
618e4b17023SJohn Marino{
619e4b17023SJohn Marino  HOST_WIDE_INT i = INTVAL (op);
620e4b17023SJohn Marino  return i == 1 || i == 2 || i == 4 || i == 8;
621e4b17023SJohn Marino})
622e4b17023SJohn Marino
623e4b17023SJohn Marino;; Match 3, 5, or 9.  Used for leal multiplicands.
624e4b17023SJohn Marino(define_predicate "const359_operand"
625e4b17023SJohn Marino  (match_code "const_int")
626e4b17023SJohn Marino{
627e4b17023SJohn Marino  HOST_WIDE_INT i = INTVAL (op);
628e4b17023SJohn Marino  return i == 3 || i == 5 || i == 9;
629e4b17023SJohn Marino})
630e4b17023SJohn Marino
631e4b17023SJohn Marino;; Match 0 or 1.
632e4b17023SJohn Marino(define_predicate "const_0_to_1_operand"
633e4b17023SJohn Marino  (and (match_code "const_int")
634e4b17023SJohn Marino       (ior (match_test "op == const0_rtx")
635e4b17023SJohn Marino	    (match_test "op == const1_rtx"))))
636e4b17023SJohn Marino
637e4b17023SJohn Marino;; Match 0 to 3.
638e4b17023SJohn Marino(define_predicate "const_0_to_3_operand"
639e4b17023SJohn Marino  (and (match_code "const_int")
640e4b17023SJohn Marino       (match_test "IN_RANGE (INTVAL (op), 0, 3)")))
641e4b17023SJohn Marino
642e4b17023SJohn Marino;; Match 0 to 7.
643e4b17023SJohn Marino(define_predicate "const_0_to_7_operand"
644e4b17023SJohn Marino  (and (match_code "const_int")
645e4b17023SJohn Marino       (match_test "IN_RANGE (INTVAL (op), 0, 7)")))
646e4b17023SJohn Marino
647e4b17023SJohn Marino;; Match 0 to 15.
648e4b17023SJohn Marino(define_predicate "const_0_to_15_operand"
649e4b17023SJohn Marino  (and (match_code "const_int")
650e4b17023SJohn Marino       (match_test "IN_RANGE (INTVAL (op), 0, 15)")))
651e4b17023SJohn Marino
652e4b17023SJohn Marino;; Match 0 to 31.
653e4b17023SJohn Marino(define_predicate "const_0_to_31_operand"
654e4b17023SJohn Marino  (and (match_code "const_int")
655e4b17023SJohn Marino       (match_test "IN_RANGE (INTVAL (op), 0, 31)")))
656e4b17023SJohn Marino
657e4b17023SJohn Marino;; Match 0 to 63.
658e4b17023SJohn Marino(define_predicate "const_0_to_63_operand"
659e4b17023SJohn Marino  (and (match_code "const_int")
660e4b17023SJohn Marino       (match_test "IN_RANGE (INTVAL (op), 0, 63)")))
661e4b17023SJohn Marino
662e4b17023SJohn Marino;; Match 0 to 255.
663e4b17023SJohn Marino(define_predicate "const_0_to_255_operand"
664e4b17023SJohn Marino  (and (match_code "const_int")
665e4b17023SJohn Marino       (match_test "IN_RANGE (INTVAL (op), 0, 255)")))
666e4b17023SJohn Marino
667e4b17023SJohn Marino;; Match (0 to 255) * 8
668e4b17023SJohn Marino(define_predicate "const_0_to_255_mul_8_operand"
669e4b17023SJohn Marino  (match_code "const_int")
670e4b17023SJohn Marino{
671e4b17023SJohn Marino  unsigned HOST_WIDE_INT val = INTVAL (op);
672e4b17023SJohn Marino  return val <= 255*8 && val % 8 == 0;
673e4b17023SJohn Marino})
674e4b17023SJohn Marino
675e4b17023SJohn Marino;; Return true if OP is CONST_INT >= 1 and <= 31 (a valid operand
676e4b17023SJohn Marino;; for shift & compare patterns, as shifting by 0 does not change flags).
677e4b17023SJohn Marino(define_predicate "const_1_to_31_operand"
678e4b17023SJohn Marino  (and (match_code "const_int")
679e4b17023SJohn Marino       (match_test "IN_RANGE (INTVAL (op), 1, 31)")))
680e4b17023SJohn Marino
681e4b17023SJohn Marino;; Return true if OP is CONST_INT >= 1 and <= 63 (a valid operand
682e4b17023SJohn Marino;; for 64bit shift & compare patterns, as shifting by 0 does not change flags).
683e4b17023SJohn Marino(define_predicate "const_1_to_63_operand"
684e4b17023SJohn Marino  (and (match_code "const_int")
685e4b17023SJohn Marino       (match_test "IN_RANGE (INTVAL (op), 1, 63)")))
686e4b17023SJohn Marino
687e4b17023SJohn Marino;; Match 2 or 3.
688e4b17023SJohn Marino(define_predicate "const_2_to_3_operand"
689e4b17023SJohn Marino  (and (match_code "const_int")
690e4b17023SJohn Marino       (match_test "IN_RANGE (INTVAL (op), 2, 3)")))
691e4b17023SJohn Marino
692e4b17023SJohn Marino;; Match 4 to 5.
693e4b17023SJohn Marino(define_predicate "const_4_to_5_operand"
694e4b17023SJohn Marino  (and (match_code "const_int")
695e4b17023SJohn Marino       (match_test "IN_RANGE (INTVAL (op), 4, 5)")))
696e4b17023SJohn Marino
697e4b17023SJohn Marino;; Match 4 to 7.
698e4b17023SJohn Marino(define_predicate "const_4_to_7_operand"
699e4b17023SJohn Marino  (and (match_code "const_int")
700e4b17023SJohn Marino       (match_test "IN_RANGE (INTVAL (op), 4, 7)")))
701e4b17023SJohn Marino
702e4b17023SJohn Marino;; Match 6 to 7.
703e4b17023SJohn Marino(define_predicate "const_6_to_7_operand"
704e4b17023SJohn Marino  (and (match_code "const_int")
705e4b17023SJohn Marino       (match_test "IN_RANGE (INTVAL (op), 6, 7)")))
706e4b17023SJohn Marino
707e4b17023SJohn Marino;; Match 8 to 11.
708e4b17023SJohn Marino(define_predicate "const_8_to_11_operand"
709e4b17023SJohn Marino  (and (match_code "const_int")
710e4b17023SJohn Marino       (match_test "IN_RANGE (INTVAL (op), 8, 11)")))
711e4b17023SJohn Marino
712e4b17023SJohn Marino;; Match 12 to 15.
713e4b17023SJohn Marino(define_predicate "const_12_to_15_operand"
714e4b17023SJohn Marino  (and (match_code "const_int")
715e4b17023SJohn Marino       (match_test "IN_RANGE (INTVAL (op), 12, 15)")))
716e4b17023SJohn Marino
717e4b17023SJohn Marino;; True if this is a constant appropriate for an increment or decrement.
718e4b17023SJohn Marino(define_predicate "incdec_operand"
719e4b17023SJohn Marino  (match_code "const_int")
720e4b17023SJohn Marino{
721e4b17023SJohn Marino  /* On Pentium4, the inc and dec operations causes extra dependency on flag
722e4b17023SJohn Marino     registers, since carry flag is not set.  */
723e4b17023SJohn Marino  if (!TARGET_USE_INCDEC && !optimize_insn_for_size_p ())
724e4b17023SJohn Marino    return false;
725e4b17023SJohn Marino  return op == const1_rtx || op == constm1_rtx;
726e4b17023SJohn Marino})
727e4b17023SJohn Marino
728e4b17023SJohn Marino;; True for registers, or 1 or -1.  Used to optimize double-word shifts.
729e4b17023SJohn Marino(define_predicate "reg_or_pm1_operand"
730e4b17023SJohn Marino  (ior (match_operand 0 "register_operand")
731e4b17023SJohn Marino       (and (match_code "const_int")
732e4b17023SJohn Marino	    (ior (match_test "op == const1_rtx")
733e4b17023SJohn Marino		 (match_test "op == constm1_rtx")))))
734e4b17023SJohn Marino
735e4b17023SJohn Marino;; True if OP is acceptable as operand of DImode shift expander.
736e4b17023SJohn Marino(define_predicate "shiftdi_operand"
737e4b17023SJohn Marino  (if_then_else (match_test "TARGET_64BIT")
738e4b17023SJohn Marino    (match_operand 0 "nonimmediate_operand")
739e4b17023SJohn Marino    (match_operand 0 "register_operand")))
740e4b17023SJohn Marino
741e4b17023SJohn Marino(define_predicate "ashldi_input_operand"
742e4b17023SJohn Marino  (if_then_else (match_test "TARGET_64BIT")
743e4b17023SJohn Marino    (match_operand 0 "nonimmediate_operand")
744e4b17023SJohn Marino    (match_operand 0 "reg_or_pm1_operand")))
745e4b17023SJohn Marino
746e4b17023SJohn Marino;; Return true if OP is a vector load from the constant pool with just
747e4b17023SJohn Marino;; the first element nonzero.
748e4b17023SJohn Marino(define_predicate "zero_extended_scalar_load_operand"
749e4b17023SJohn Marino  (match_code "mem")
750e4b17023SJohn Marino{
751e4b17023SJohn Marino  unsigned n_elts;
752e4b17023SJohn Marino  op = maybe_get_pool_constant (op);
753e4b17023SJohn Marino
754e4b17023SJohn Marino  if (!(op && GET_CODE (op) == CONST_VECTOR))
755e4b17023SJohn Marino    return false;
756e4b17023SJohn Marino
757e4b17023SJohn Marino  n_elts = CONST_VECTOR_NUNITS (op);
758e4b17023SJohn Marino
759e4b17023SJohn Marino  for (n_elts--; n_elts > 0; n_elts--)
760e4b17023SJohn Marino    {
761e4b17023SJohn Marino      rtx elt = CONST_VECTOR_ELT (op, n_elts);
762e4b17023SJohn Marino      if (elt != CONST0_RTX (GET_MODE_INNER (GET_MODE (op))))
763e4b17023SJohn Marino	return false;
764e4b17023SJohn Marino    }
765e4b17023SJohn Marino  return true;
766e4b17023SJohn Marino})
767e4b17023SJohn Marino
768e4b17023SJohn Marino/* Return true if operand is a vector constant that is all ones. */
769e4b17023SJohn Marino(define_predicate "vector_all_ones_operand"
770e4b17023SJohn Marino  (match_code "const_vector")
771e4b17023SJohn Marino{
772e4b17023SJohn Marino  int nunits = GET_MODE_NUNITS (mode);
773e4b17023SJohn Marino
774e4b17023SJohn Marino  if (GET_CODE (op) == CONST_VECTOR
775e4b17023SJohn Marino      && CONST_VECTOR_NUNITS (op) == nunits)
776e4b17023SJohn Marino    {
777e4b17023SJohn Marino      int i;
778e4b17023SJohn Marino      for (i = 0; i < nunits; ++i)
779e4b17023SJohn Marino        {
780e4b17023SJohn Marino          rtx x = CONST_VECTOR_ELT (op, i);
781e4b17023SJohn Marino          if (x != constm1_rtx)
782e4b17023SJohn Marino            return false;
783e4b17023SJohn Marino        }
784e4b17023SJohn Marino      return true;
785e4b17023SJohn Marino    }
786e4b17023SJohn Marino
787e4b17023SJohn Marino  return false;
788e4b17023SJohn Marino})
789e4b17023SJohn Marino
790e4b17023SJohn Marino; Return true when OP is operand acceptable for standard SSE move.
791e4b17023SJohn Marino(define_predicate "vector_move_operand"
792e4b17023SJohn Marino  (ior (match_operand 0 "nonimmediate_operand")
793e4b17023SJohn Marino       (match_operand 0 "const0_operand")))
794e4b17023SJohn Marino
795e4b17023SJohn Marino;; Return true when OP is nonimmediate or standard SSE constant.
796e4b17023SJohn Marino(define_predicate "nonimmediate_or_sse_const_operand"
797e4b17023SJohn Marino  (match_operand 0 "general_operand")
798e4b17023SJohn Marino{
799e4b17023SJohn Marino  if (nonimmediate_operand (op, mode))
800e4b17023SJohn Marino    return true;
801e4b17023SJohn Marino  if (standard_sse_constant_p (op) > 0)
802e4b17023SJohn Marino    return true;
803e4b17023SJohn Marino  return false;
804e4b17023SJohn Marino})
805e4b17023SJohn Marino
806e4b17023SJohn Marino;; Return true if OP is a register or a zero.
807e4b17023SJohn Marino(define_predicate "reg_or_0_operand"
808e4b17023SJohn Marino  (ior (match_operand 0 "register_operand")
809e4b17023SJohn Marino       (match_operand 0 "const0_operand")))
810e4b17023SJohn Marino
811e4b17023SJohn Marino;; Return true if op if a valid address for LEA, and does not contain
812e4b17023SJohn Marino;; a segment override.  Defined as a special predicate to allow
813e4b17023SJohn Marino;; mode-less const_int operands pass to address_operand.
814e4b17023SJohn Marino(define_special_predicate "lea_address_operand"
815e4b17023SJohn Marino  (match_operand 0 "address_operand")
816e4b17023SJohn Marino{
817e4b17023SJohn Marino  struct ix86_address parts;
818e4b17023SJohn Marino  int ok;
819e4b17023SJohn Marino
820e4b17023SJohn Marino  ok = ix86_decompose_address (op, &parts);
821e4b17023SJohn Marino  gcc_assert (ok);
822e4b17023SJohn Marino  return parts.seg == SEG_DEFAULT;
823e4b17023SJohn Marino})
824e4b17023SJohn Marino
8255ce9237cSJohn Marino;; Return true for RTX codes that force SImode address.
8265ce9237cSJohn Marino(define_predicate "SImode_address_operand"
8275ce9237cSJohn Marino  (match_code "subreg,zero_extend,and"))
8285ce9237cSJohn Marino
829e4b17023SJohn Marino;; Return true if op if a valid base register, displacement or
830e4b17023SJohn Marino;; sum of base register and displacement for VSIB addressing.
831e4b17023SJohn Marino(define_predicate "vsib_address_operand"
832e4b17023SJohn Marino  (match_operand 0 "address_operand")
833e4b17023SJohn Marino{
834e4b17023SJohn Marino  struct ix86_address parts;
835e4b17023SJohn Marino  int ok;
836e4b17023SJohn Marino  rtx disp;
837e4b17023SJohn Marino
838e4b17023SJohn Marino  ok = ix86_decompose_address (op, &parts);
839e4b17023SJohn Marino  gcc_assert (ok);
840e4b17023SJohn Marino  if (parts.index || parts.seg != SEG_DEFAULT)
841e4b17023SJohn Marino    return false;
842e4b17023SJohn Marino
843e4b17023SJohn Marino  /* VSIB addressing doesn't support (%rip).  */
844*95d28233SJohn Marino  if (parts.disp)
845e4b17023SJohn Marino    {
846*95d28233SJohn Marino      disp = parts.disp;
847*95d28233SJohn Marino      if (GET_CODE (disp) == CONST)
848*95d28233SJohn Marino	{
849*95d28233SJohn Marino	  disp = XEXP (disp, 0);
850e4b17023SJohn Marino	  if (GET_CODE (disp) == PLUS)
851e4b17023SJohn Marino	    disp = XEXP (disp, 0);
852e4b17023SJohn Marino	  if (GET_CODE (disp) == UNSPEC)
853e4b17023SJohn Marino	    switch (XINT (disp, 1))
854e4b17023SJohn Marino	      {
855e4b17023SJohn Marino	      case UNSPEC_GOTPCREL:
856e4b17023SJohn Marino	      case UNSPEC_PCREL:
857e4b17023SJohn Marino	      case UNSPEC_GOTNTPOFF:
858e4b17023SJohn Marino		return false;
859e4b17023SJohn Marino	      }
860e4b17023SJohn Marino	}
861*95d28233SJohn Marino      if (TARGET_64BIT
862*95d28233SJohn Marino	  && flag_pic
863*95d28233SJohn Marino	  && (GET_CODE (disp) == SYMBOL_REF
864*95d28233SJohn Marino	      || GET_CODE (disp) == LABEL_REF))
865*95d28233SJohn Marino	return false;
866*95d28233SJohn Marino    }
867e4b17023SJohn Marino
868e4b17023SJohn Marino  return true;
869e4b17023SJohn Marino})
870e4b17023SJohn Marino
871e4b17023SJohn Marino(define_predicate "vsib_mem_operator"
872e4b17023SJohn Marino  (match_code "mem"))
873e4b17023SJohn Marino
874e4b17023SJohn Marino;; Return true if the rtx is known to be at least 32 bits aligned.
875e4b17023SJohn Marino(define_predicate "aligned_operand"
876e4b17023SJohn Marino  (match_operand 0 "general_operand")
877e4b17023SJohn Marino{
878e4b17023SJohn Marino  struct ix86_address parts;
879e4b17023SJohn Marino  int ok;
880e4b17023SJohn Marino
881e4b17023SJohn Marino  /* Registers and immediate operands are always "aligned".  */
882e4b17023SJohn Marino  if (!MEM_P (op))
883e4b17023SJohn Marino    return true;
884e4b17023SJohn Marino
885e4b17023SJohn Marino  /* All patterns using aligned_operand on memory operands ends up
886e4b17023SJohn Marino     in promoting memory operand to 64bit and thus causing memory mismatch.  */
887e4b17023SJohn Marino  if (TARGET_MEMORY_MISMATCH_STALL && !optimize_insn_for_size_p ())
888e4b17023SJohn Marino    return false;
889e4b17023SJohn Marino
890e4b17023SJohn Marino  /* Don't even try to do any aligned optimizations with volatiles.  */
891e4b17023SJohn Marino  if (MEM_VOLATILE_P (op))
892e4b17023SJohn Marino    return false;
893e4b17023SJohn Marino
894e4b17023SJohn Marino  if (MEM_ALIGN (op) >= 32)
895e4b17023SJohn Marino    return true;
896e4b17023SJohn Marino
897e4b17023SJohn Marino  op = XEXP (op, 0);
898e4b17023SJohn Marino
899e4b17023SJohn Marino  /* Pushes and pops are only valid on the stack pointer.  */
900e4b17023SJohn Marino  if (GET_CODE (op) == PRE_DEC
901e4b17023SJohn Marino      || GET_CODE (op) == POST_INC)
902e4b17023SJohn Marino    return true;
903e4b17023SJohn Marino
904e4b17023SJohn Marino  /* Decode the address.  */
905e4b17023SJohn Marino  ok = ix86_decompose_address (op, &parts);
906e4b17023SJohn Marino  gcc_assert (ok);
907e4b17023SJohn Marino
908e4b17023SJohn Marino  if (parts.base && GET_CODE (parts.base) == SUBREG)
909e4b17023SJohn Marino    parts.base = SUBREG_REG (parts.base);
910e4b17023SJohn Marino  if (parts.index && GET_CODE (parts.index) == SUBREG)
911e4b17023SJohn Marino    parts.index = SUBREG_REG (parts.index);
912e4b17023SJohn Marino
913e4b17023SJohn Marino  /* Look for some component that isn't known to be aligned.  */
914e4b17023SJohn Marino  if (parts.index)
915e4b17023SJohn Marino    {
916e4b17023SJohn Marino      if (REGNO_POINTER_ALIGN (REGNO (parts.index)) * parts.scale < 32)
917e4b17023SJohn Marino	return false;
918e4b17023SJohn Marino    }
919e4b17023SJohn Marino  if (parts.base)
920e4b17023SJohn Marino    {
921e4b17023SJohn Marino      if (REGNO_POINTER_ALIGN (REGNO (parts.base)) < 32)
922e4b17023SJohn Marino	return false;
923e4b17023SJohn Marino    }
924e4b17023SJohn Marino  if (parts.disp)
925e4b17023SJohn Marino    {
926e4b17023SJohn Marino      if (!CONST_INT_P (parts.disp)
927e4b17023SJohn Marino	  || (INTVAL (parts.disp) & 3))
928e4b17023SJohn Marino	return false;
929e4b17023SJohn Marino    }
930e4b17023SJohn Marino
931e4b17023SJohn Marino  /* Didn't find one -- this must be an aligned address.  */
932e4b17023SJohn Marino  return true;
933e4b17023SJohn Marino})
934e4b17023SJohn Marino
935e4b17023SJohn Marino;; Return true if OP is memory operand with a displacement.
936e4b17023SJohn Marino(define_predicate "memory_displacement_operand"
937e4b17023SJohn Marino  (match_operand 0 "memory_operand")
938e4b17023SJohn Marino{
939e4b17023SJohn Marino  struct ix86_address parts;
940e4b17023SJohn Marino  int ok;
941e4b17023SJohn Marino
942e4b17023SJohn Marino  ok = ix86_decompose_address (XEXP (op, 0), &parts);
943e4b17023SJohn Marino  gcc_assert (ok);
944e4b17023SJohn Marino  return parts.disp != NULL_RTX;
945e4b17023SJohn Marino})
946e4b17023SJohn Marino
947e4b17023SJohn Marino;; Return true if OP is memory operand with a displacement only.
948e4b17023SJohn Marino(define_predicate "memory_displacement_only_operand"
949e4b17023SJohn Marino  (match_operand 0 "memory_operand")
950e4b17023SJohn Marino{
951e4b17023SJohn Marino  struct ix86_address parts;
952e4b17023SJohn Marino  int ok;
953e4b17023SJohn Marino
954e4b17023SJohn Marino  if (TARGET_64BIT)
955e4b17023SJohn Marino    return false;
956e4b17023SJohn Marino
957e4b17023SJohn Marino  ok = ix86_decompose_address (XEXP (op, 0), &parts);
958e4b17023SJohn Marino  gcc_assert (ok);
959e4b17023SJohn Marino
960e4b17023SJohn Marino  if (parts.base || parts.index)
961e4b17023SJohn Marino    return false;
962e4b17023SJohn Marino
963e4b17023SJohn Marino  return parts.disp != NULL_RTX;
964e4b17023SJohn Marino})
965e4b17023SJohn Marino
966e4b17023SJohn Marino;; Return true if OP is memory operand which will need zero or
967e4b17023SJohn Marino;; one register at most, not counting stack pointer or frame pointer.
968e4b17023SJohn Marino(define_predicate "cmpxchg8b_pic_memory_operand"
969e4b17023SJohn Marino  (match_operand 0 "memory_operand")
970e4b17023SJohn Marino{
971e4b17023SJohn Marino  struct ix86_address parts;
972e4b17023SJohn Marino  int ok;
973e4b17023SJohn Marino
974e4b17023SJohn Marino  if (TARGET_64BIT || !flag_pic)
975e4b17023SJohn Marino    return true;
976e4b17023SJohn Marino
977e4b17023SJohn Marino  ok = ix86_decompose_address (XEXP (op, 0), &parts);
978e4b17023SJohn Marino  gcc_assert (ok);
979e4b17023SJohn Marino
980e4b17023SJohn Marino  if (parts.base && GET_CODE (parts.base) == SUBREG)
981e4b17023SJohn Marino    parts.base = SUBREG_REG (parts.base);
982e4b17023SJohn Marino  if (parts.index && GET_CODE (parts.index) == SUBREG)
983e4b17023SJohn Marino    parts.index = SUBREG_REG (parts.index);
984e4b17023SJohn Marino
985e4b17023SJohn Marino  if (parts.base == NULL_RTX
986e4b17023SJohn Marino      || parts.base == arg_pointer_rtx
987e4b17023SJohn Marino      || parts.base == frame_pointer_rtx
988e4b17023SJohn Marino      || parts.base == hard_frame_pointer_rtx
989e4b17023SJohn Marino      || parts.base == stack_pointer_rtx)
990e4b17023SJohn Marino    return true;
991e4b17023SJohn Marino
992e4b17023SJohn Marino  if (parts.index == NULL_RTX
993e4b17023SJohn Marino      || parts.index == arg_pointer_rtx
994e4b17023SJohn Marino      || parts.index == frame_pointer_rtx
995e4b17023SJohn Marino      || parts.index == hard_frame_pointer_rtx
996e4b17023SJohn Marino      || parts.index == stack_pointer_rtx)
997e4b17023SJohn Marino    return true;
998e4b17023SJohn Marino
999e4b17023SJohn Marino  return false;
1000e4b17023SJohn Marino})
1001e4b17023SJohn Marino
1002e4b17023SJohn Marino
1003e4b17023SJohn Marino;; Return true if OP is memory operand that cannot be represented
1004e4b17023SJohn Marino;; by the modRM array.
1005e4b17023SJohn Marino(define_predicate "long_memory_operand"
1006e4b17023SJohn Marino  (and (match_operand 0 "memory_operand")
10075ce9237cSJohn Marino       (match_test "memory_address_length (op, false)")))
1008e4b17023SJohn Marino
1009e4b17023SJohn Marino;; Return true if OP is a comparison operator that can be issued by fcmov.
1010e4b17023SJohn Marino(define_predicate "fcmov_comparison_operator"
1011e4b17023SJohn Marino  (match_operand 0 "comparison_operator")
1012e4b17023SJohn Marino{
1013e4b17023SJohn Marino  enum machine_mode inmode = GET_MODE (XEXP (op, 0));
1014e4b17023SJohn Marino  enum rtx_code code = GET_CODE (op);
1015e4b17023SJohn Marino
1016e4b17023SJohn Marino  if (inmode == CCFPmode || inmode == CCFPUmode)
1017e4b17023SJohn Marino    {
1018e4b17023SJohn Marino      if (!ix86_trivial_fp_comparison_operator (op, mode))
1019e4b17023SJohn Marino	return false;
1020e4b17023SJohn Marino      code = ix86_fp_compare_code_to_integer (code);
1021e4b17023SJohn Marino    }
1022e4b17023SJohn Marino  /* i387 supports just limited amount of conditional codes.  */
1023e4b17023SJohn Marino  switch (code)
1024e4b17023SJohn Marino    {
1025e4b17023SJohn Marino    case LTU: case GTU: case LEU: case GEU:
1026e4b17023SJohn Marino      if (inmode == CCmode || inmode == CCFPmode || inmode == CCFPUmode
1027e4b17023SJohn Marino	  || inmode == CCCmode)
1028e4b17023SJohn Marino	return true;
1029e4b17023SJohn Marino      return false;
1030e4b17023SJohn Marino    case ORDERED: case UNORDERED:
1031e4b17023SJohn Marino    case EQ: case NE:
1032e4b17023SJohn Marino      return true;
1033e4b17023SJohn Marino    default:
1034e4b17023SJohn Marino      return false;
1035e4b17023SJohn Marino    }
1036e4b17023SJohn Marino})
1037e4b17023SJohn Marino
1038e4b17023SJohn Marino;; Return true if OP is a comparison that can be used in the CMPSS/CMPPS insns.
1039e4b17023SJohn Marino;; The first set are supported directly; the second set can't be done with
1040e4b17023SJohn Marino;; full IEEE support, i.e. NaNs.
1041e4b17023SJohn Marino
1042e4b17023SJohn Marino(define_predicate "sse_comparison_operator"
1043e4b17023SJohn Marino  (ior (match_code "eq,ne,lt,le,unordered,unge,ungt,ordered")
1044e4b17023SJohn Marino       (and (match_test "TARGET_AVX")
1045e4b17023SJohn Marino	    (match_code "ge,gt,uneq,unle,unlt,ltgt"))))
1046e4b17023SJohn Marino
1047e4b17023SJohn Marino(define_predicate "ix86_comparison_int_operator"
1048e4b17023SJohn Marino  (match_code "ne,eq,ge,gt,le,lt"))
1049e4b17023SJohn Marino
1050e4b17023SJohn Marino(define_predicate "ix86_comparison_uns_operator"
1051e4b17023SJohn Marino  (match_code "ne,eq,geu,gtu,leu,ltu"))
1052e4b17023SJohn Marino
1053e4b17023SJohn Marino(define_predicate "bt_comparison_operator"
1054e4b17023SJohn Marino  (match_code "ne,eq"))
1055e4b17023SJohn Marino
1056e4b17023SJohn Marino;; Return true if OP is a valid comparison operator in valid mode.
1057e4b17023SJohn Marino(define_predicate "ix86_comparison_operator"
1058e4b17023SJohn Marino  (match_operand 0 "comparison_operator")
1059e4b17023SJohn Marino{
1060e4b17023SJohn Marino  enum machine_mode inmode = GET_MODE (XEXP (op, 0));
1061e4b17023SJohn Marino  enum rtx_code code = GET_CODE (op);
1062e4b17023SJohn Marino
1063e4b17023SJohn Marino  if (inmode == CCFPmode || inmode == CCFPUmode)
1064e4b17023SJohn Marino    return ix86_trivial_fp_comparison_operator (op, mode);
1065e4b17023SJohn Marino
1066e4b17023SJohn Marino  switch (code)
1067e4b17023SJohn Marino    {
1068e4b17023SJohn Marino    case EQ: case NE:
1069e4b17023SJohn Marino      return true;
1070e4b17023SJohn Marino    case LT: case GE:
1071e4b17023SJohn Marino      if (inmode == CCmode || inmode == CCGCmode
1072e4b17023SJohn Marino	  || inmode == CCGOCmode || inmode == CCNOmode)
1073e4b17023SJohn Marino	return true;
1074e4b17023SJohn Marino      return false;
1075e4b17023SJohn Marino    case LTU: case GTU: case LEU: case GEU:
1076e4b17023SJohn Marino      if (inmode == CCmode || inmode == CCCmode)
1077e4b17023SJohn Marino	return true;
1078e4b17023SJohn Marino      return false;
1079e4b17023SJohn Marino    case ORDERED: case UNORDERED:
1080e4b17023SJohn Marino      if (inmode == CCmode)
1081e4b17023SJohn Marino	return true;
1082e4b17023SJohn Marino      return false;
1083e4b17023SJohn Marino    case GT: case LE:
1084e4b17023SJohn Marino      if (inmode == CCmode || inmode == CCGCmode || inmode == CCNOmode)
1085e4b17023SJohn Marino	return true;
1086e4b17023SJohn Marino      return false;
1087e4b17023SJohn Marino    default:
1088e4b17023SJohn Marino      return false;
1089e4b17023SJohn Marino    }
1090e4b17023SJohn Marino})
1091e4b17023SJohn Marino
1092e4b17023SJohn Marino;; Return true if OP is a valid comparison operator
1093e4b17023SJohn Marino;; testing carry flag to be set.
1094e4b17023SJohn Marino(define_predicate "ix86_carry_flag_operator"
1095e4b17023SJohn Marino  (match_code "ltu,lt,unlt,gtu,gt,ungt,le,unle,ge,unge,ltgt,uneq")
1096e4b17023SJohn Marino{
1097e4b17023SJohn Marino  enum machine_mode inmode = GET_MODE (XEXP (op, 0));
1098e4b17023SJohn Marino  enum rtx_code code = GET_CODE (op);
1099e4b17023SJohn Marino
1100e4b17023SJohn Marino  if (inmode == CCFPmode || inmode == CCFPUmode)
1101e4b17023SJohn Marino    {
1102e4b17023SJohn Marino      if (!ix86_trivial_fp_comparison_operator (op, mode))
1103e4b17023SJohn Marino	return false;
1104e4b17023SJohn Marino      code = ix86_fp_compare_code_to_integer (code);
1105e4b17023SJohn Marino    }
1106e4b17023SJohn Marino  else if (inmode == CCCmode)
1107e4b17023SJohn Marino   return code == LTU || code == GTU;
1108e4b17023SJohn Marino  else if (inmode != CCmode)
1109e4b17023SJohn Marino    return false;
1110e4b17023SJohn Marino
1111e4b17023SJohn Marino  return code == LTU;
1112e4b17023SJohn Marino})
1113e4b17023SJohn Marino
1114e4b17023SJohn Marino;; Return true if this comparison only requires testing one flag bit.
1115e4b17023SJohn Marino(define_predicate "ix86_trivial_fp_comparison_operator"
1116e4b17023SJohn Marino  (match_code "gt,ge,unlt,unle,uneq,ltgt,ordered,unordered"))
1117e4b17023SJohn Marino
1118e4b17023SJohn Marino;; Return true if we know how to do this comparison.  Others require
1119e4b17023SJohn Marino;; testing more than one flag bit, and we let the generic middle-end
1120e4b17023SJohn Marino;; code do that.
1121e4b17023SJohn Marino(define_predicate "ix86_fp_comparison_operator"
1122e4b17023SJohn Marino  (if_then_else (match_test "ix86_fp_comparison_strategy (GET_CODE (op))
1123e4b17023SJohn Marino                             == IX86_FPCMP_ARITH")
1124e4b17023SJohn Marino               (match_operand 0 "comparison_operator")
1125e4b17023SJohn Marino               (match_operand 0 "ix86_trivial_fp_comparison_operator")))
1126e4b17023SJohn Marino
1127e4b17023SJohn Marino;; Same as above, but for swapped comparison used in fp_jcc_4_387.
1128e4b17023SJohn Marino(define_predicate "ix86_swapped_fp_comparison_operator"
1129e4b17023SJohn Marino  (match_operand 0 "comparison_operator")
1130e4b17023SJohn Marino{
1131e4b17023SJohn Marino  enum rtx_code code = GET_CODE (op);
1132e4b17023SJohn Marino  bool ret;
1133e4b17023SJohn Marino
1134e4b17023SJohn Marino  PUT_CODE (op, swap_condition (code));
1135e4b17023SJohn Marino  ret = ix86_fp_comparison_operator (op, mode);
1136e4b17023SJohn Marino  PUT_CODE (op, code);
1137e4b17023SJohn Marino  return ret;
1138e4b17023SJohn Marino})
1139e4b17023SJohn Marino
1140e4b17023SJohn Marino;; Nearly general operand, but accept any const_double, since we wish
1141e4b17023SJohn Marino;; to be able to drop them into memory rather than have them get pulled
1142e4b17023SJohn Marino;; into registers.
1143e4b17023SJohn Marino(define_predicate "cmp_fp_expander_operand"
1144e4b17023SJohn Marino  (ior (match_code "const_double")
1145e4b17023SJohn Marino       (match_operand 0 "general_operand")))
1146e4b17023SJohn Marino
1147e4b17023SJohn Marino;; Return true if this is a valid binary floating-point operation.
1148e4b17023SJohn Marino(define_predicate "binary_fp_operator"
1149e4b17023SJohn Marino  (match_code "plus,minus,mult,div"))
1150e4b17023SJohn Marino
1151e4b17023SJohn Marino;; Return true if this is a multiply operation.
1152e4b17023SJohn Marino(define_predicate "mult_operator"
1153e4b17023SJohn Marino  (match_code "mult"))
1154e4b17023SJohn Marino
1155e4b17023SJohn Marino;; Return true if this is a division operation.
1156e4b17023SJohn Marino(define_predicate "div_operator"
1157e4b17023SJohn Marino  (match_code "div"))
1158e4b17023SJohn Marino
1159e4b17023SJohn Marino;; Return true if this is a plus, minus, and, ior or xor operation.
1160e4b17023SJohn Marino(define_predicate "plusminuslogic_operator"
1161e4b17023SJohn Marino  (match_code "plus,minus,and,ior,xor"))
1162e4b17023SJohn Marino
1163e4b17023SJohn Marino;; Return true if this is a float extend operation.
1164e4b17023SJohn Marino(define_predicate "float_operator"
1165e4b17023SJohn Marino  (match_code "float"))
1166e4b17023SJohn Marino
1167e4b17023SJohn Marino;; Return true for ARITHMETIC_P.
1168e4b17023SJohn Marino(define_predicate "arith_or_logical_operator"
1169e4b17023SJohn Marino  (match_code "plus,mult,and,ior,xor,smin,smax,umin,umax,compare,minus,div,
1170e4b17023SJohn Marino	       mod,udiv,umod,ashift,rotate,ashiftrt,lshiftrt,rotatert"))
1171e4b17023SJohn Marino
1172e4b17023SJohn Marino;; Return true for COMMUTATIVE_P.
1173e4b17023SJohn Marino(define_predicate "commutative_operator"
1174e4b17023SJohn Marino  (match_code "plus,mult,and,ior,xor,smin,smax,umin,umax"))
1175e4b17023SJohn Marino
1176e4b17023SJohn Marino;; Return true if OP is a binary operator that can be promoted to wider mode.
1177e4b17023SJohn Marino(define_predicate "promotable_binary_operator"
1178e4b17023SJohn Marino  (ior (match_code "plus,minus,and,ior,xor,ashift")
1179e4b17023SJohn Marino       (and (match_code "mult")
1180e4b17023SJohn Marino	    (match_test "TARGET_TUNE_PROMOTE_HIMODE_IMUL"))))
1181e4b17023SJohn Marino
1182e4b17023SJohn Marino(define_predicate "compare_operator"
1183e4b17023SJohn Marino  (match_code "compare"))
1184e4b17023SJohn Marino
1185e4b17023SJohn Marino(define_predicate "absneg_operator"
1186e4b17023SJohn Marino  (match_code "abs,neg"))
1187e4b17023SJohn Marino
1188e4b17023SJohn Marino;; Return true if OP is misaligned memory operand
1189e4b17023SJohn Marino(define_predicate "misaligned_operand"
1190e4b17023SJohn Marino  (and (match_code "mem")
1191e4b17023SJohn Marino       (match_test "MEM_ALIGN (op) < GET_MODE_ALIGNMENT (mode)")))
1192e4b17023SJohn Marino
1193e4b17023SJohn Marino;; Return true if OP is a emms operation, known to be a PARALLEL.
1194e4b17023SJohn Marino(define_predicate "emms_operation"
1195e4b17023SJohn Marino  (match_code "parallel")
1196e4b17023SJohn Marino{
1197e4b17023SJohn Marino  unsigned i;
1198e4b17023SJohn Marino
1199e4b17023SJohn Marino  if (XVECLEN (op, 0) != 17)
1200e4b17023SJohn Marino    return false;
1201e4b17023SJohn Marino
1202e4b17023SJohn Marino  for (i = 0; i < 8; i++)
1203e4b17023SJohn Marino    {
1204e4b17023SJohn Marino      rtx elt = XVECEXP (op, 0, i+1);
1205e4b17023SJohn Marino
1206e4b17023SJohn Marino      if (GET_CODE (elt) != CLOBBER
1207e4b17023SJohn Marino	  || GET_CODE (SET_DEST (elt)) != REG
1208e4b17023SJohn Marino	  || GET_MODE (SET_DEST (elt)) != XFmode
1209e4b17023SJohn Marino	  || REGNO (SET_DEST (elt)) != FIRST_STACK_REG + i)
1210e4b17023SJohn Marino        return false;
1211e4b17023SJohn Marino
1212e4b17023SJohn Marino      elt = XVECEXP (op, 0, i+9);
1213e4b17023SJohn Marino
1214e4b17023SJohn Marino      if (GET_CODE (elt) != CLOBBER
1215e4b17023SJohn Marino	  || GET_CODE (SET_DEST (elt)) != REG
1216e4b17023SJohn Marino	  || GET_MODE (SET_DEST (elt)) != DImode
1217e4b17023SJohn Marino	  || REGNO (SET_DEST (elt)) != FIRST_MMX_REG + i)
1218e4b17023SJohn Marino	return false;
1219e4b17023SJohn Marino    }
1220e4b17023SJohn Marino  return true;
1221e4b17023SJohn Marino})
1222e4b17023SJohn Marino
1223e4b17023SJohn Marino;; Return true if OP is a vzeroall operation, known to be a PARALLEL.
1224e4b17023SJohn Marino(define_predicate "vzeroall_operation"
1225e4b17023SJohn Marino  (match_code "parallel")
1226e4b17023SJohn Marino{
1227e4b17023SJohn Marino  unsigned i, nregs = TARGET_64BIT ? 16 : 8;
1228e4b17023SJohn Marino
1229e4b17023SJohn Marino  if ((unsigned) XVECLEN (op, 0) != 1 + nregs)
1230e4b17023SJohn Marino    return false;
1231e4b17023SJohn Marino
1232e4b17023SJohn Marino  for (i = 0; i < nregs; i++)
1233e4b17023SJohn Marino    {
1234e4b17023SJohn Marino      rtx elt = XVECEXP (op, 0, i+1);
1235e4b17023SJohn Marino
1236e4b17023SJohn Marino      if (GET_CODE (elt) != SET
1237e4b17023SJohn Marino	  || GET_CODE (SET_DEST (elt)) != REG
1238e4b17023SJohn Marino	  || GET_MODE (SET_DEST (elt)) != V8SImode
1239e4b17023SJohn Marino	  || REGNO (SET_DEST (elt)) != SSE_REGNO (i)
1240e4b17023SJohn Marino	  || SET_SRC (elt) != CONST0_RTX (V8SImode))
1241e4b17023SJohn Marino	return false;
1242e4b17023SJohn Marino    }
1243e4b17023SJohn Marino  return true;
1244e4b17023SJohn Marino})
1245e4b17023SJohn Marino
1246e4b17023SJohn Marino;; Return true if OP is a parallel for a vbroadcast permute.
1247e4b17023SJohn Marino
1248e4b17023SJohn Marino(define_predicate "avx_vbroadcast_operand"
1249e4b17023SJohn Marino  (and (match_code "parallel")
1250e4b17023SJohn Marino       (match_code "const_int" "a"))
1251e4b17023SJohn Marino{
1252e4b17023SJohn Marino  rtx elt = XVECEXP (op, 0, 0);
1253e4b17023SJohn Marino  int i, nelt = XVECLEN (op, 0);
1254e4b17023SJohn Marino
1255e4b17023SJohn Marino  /* Don't bother checking there are the right number of operands,
1256e4b17023SJohn Marino     merely that they're all identical.  */
1257e4b17023SJohn Marino  for (i = 1; i < nelt; ++i)
1258e4b17023SJohn Marino    if (XVECEXP (op, 0, i) != elt)
1259e4b17023SJohn Marino      return false;
1260e4b17023SJohn Marino  return true;
1261e4b17023SJohn Marino})
1262e4b17023SJohn Marino
1263e4b17023SJohn Marino;; Return true if OP is a proper third operand to vpblendw256.
1264e4b17023SJohn Marino(define_predicate "avx2_pblendw_operand"
1265e4b17023SJohn Marino  (match_code "const_int")
1266e4b17023SJohn Marino{
1267e4b17023SJohn Marino  HOST_WIDE_INT val = INTVAL (op);
1268e4b17023SJohn Marino  HOST_WIDE_INT low = val & 0xff;
1269e4b17023SJohn Marino  return val == ((low << 8) | low);
1270e4b17023SJohn Marino})
1271