Merged revisions 143552,143554,143557,143560,143562,143564-143567,143570-143573,14357...
[official-gcc.git] / gcc / config / i386 / predicates.md
blobb2bef6470be9a7f1ea46782cedbf18c59abb8d82
1 ;; Predicate definitions for IA-32 and x86-64.
2 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
3 ;; Free Software Foundation, Inc.
4 ;;
5 ;; This file is part of GCC.
6 ;;
7 ;; GCC is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3, or (at your option)
10 ;; any later version.
12 ;; GCC is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3.  If not see
19 ;; <http://www.gnu.org/licenses/>.
21 ;; Return nonzero if OP is either a i387 or SSE fp register.
22 (define_predicate "any_fp_register_operand"
23   (and (match_code "reg")
24        (match_test "ANY_FP_REGNO_P (REGNO (op))")))
26 ;; Return nonzero if OP is an i387 fp register.
27 (define_predicate "fp_register_operand"
28   (and (match_code "reg")
29        (match_test "FP_REGNO_P (REGNO (op))")))
31 ;; Return nonzero if OP is a non-fp register_operand.
32 (define_predicate "register_and_not_any_fp_reg_operand"
33   (and (match_code "reg")
34        (not (match_test "ANY_FP_REGNO_P (REGNO (op))"))))
36 ;; Return nonzero if OP is a register operand other than an i387 fp register.
37 (define_predicate "register_and_not_fp_reg_operand"
38   (and (match_code "reg")
39        (not (match_test "FP_REGNO_P (REGNO (op))"))))
41 ;; True if the operand is an MMX register.
42 (define_predicate "mmx_reg_operand"
43   (and (match_code "reg")
44        (match_test "MMX_REGNO_P (REGNO (op))")))
46 ;; True if the operand is a Q_REGS class register.
47 (define_predicate "q_regs_operand"
48   (match_operand 0 "register_operand")
50   if (GET_CODE (op) == SUBREG)
51     op = SUBREG_REG (op);
52   return ANY_QI_REG_P (op);
55 ;; Match an SI or HImode register for a zero_extract.
56 (define_special_predicate "ext_register_operand"
57   (match_operand 0 "register_operand")
59   if ((!TARGET_64BIT || GET_MODE (op) != DImode)
60       && GET_MODE (op) != SImode && GET_MODE (op) != HImode)
61     return 0;
62   if (GET_CODE (op) == SUBREG)
63     op = SUBREG_REG (op);
65   /* Be careful to accept only registers having upper parts.  */
66   return REGNO (op) > LAST_VIRTUAL_REGISTER || REGNO (op) < 4;
69 ;; Return true if op is the AX register.
70 (define_predicate "ax_reg_operand"
71   (and (match_code "reg")
72        (match_test "REGNO (op) == 0")))
74 ;; Return true if op is the flags register.
75 (define_predicate "flags_reg_operand"
76   (and (match_code "reg")
77        (match_test "REGNO (op) == FLAGS_REG")))
79 ;; Return true if op is not xmm0 register.
80 (define_predicate "reg_not_xmm0_operand"
81    (and (match_operand 0 "register_operand")
82         (match_test "GET_CODE (op) != REG
83                      || REGNO (op) != FIRST_SSE_REG")))
85 ;; As above, but allow nonimmediate operands.
86 (define_predicate "nonimm_not_xmm0_operand"
87    (and (match_operand 0 "nonimmediate_operand")
88         (match_test "GET_CODE (op) != REG
89                      || REGNO (op) != FIRST_SSE_REG")))
91 ;; Return 1 if VALUE can be stored in a sign extended immediate field.
92 (define_predicate "x86_64_immediate_operand"
93   (match_code "const_int,symbol_ref,label_ref,const")
95   if (!TARGET_64BIT)
96     return immediate_operand (op, mode);
98   switch (GET_CODE (op))
99     {
100     case CONST_INT:
101       /* CONST_DOUBLES never match, since HOST_BITS_PER_WIDE_INT is known
102          to be at least 32 and this all acceptable constants are
103          represented as CONST_INT.  */
104       if (HOST_BITS_PER_WIDE_INT == 32)
105         return 1;
106       else
107         {
108           HOST_WIDE_INT val = trunc_int_for_mode (INTVAL (op), DImode);
109           return trunc_int_for_mode (val, SImode) == val;
110         }
111       break;
113     case SYMBOL_REF:
114       /* For certain code models, the symbolic references are known to fit.
115          in CM_SMALL_PIC model we know it fits if it is local to the shared
116          library.  Don't count TLS SYMBOL_REFs here, since they should fit
117          only if inside of UNSPEC handled below.  */
118       /* TLS symbols are not constant.  */
119       if (SYMBOL_REF_TLS_MODEL (op))
120         return false;
121       return (ix86_cmodel == CM_SMALL || ix86_cmodel == CM_KERNEL
122               || (ix86_cmodel == CM_MEDIUM && !SYMBOL_REF_FAR_ADDR_P (op)));
124     case LABEL_REF:
125       /* For certain code models, the code is near as well.  */
126       return (ix86_cmodel == CM_SMALL || ix86_cmodel == CM_MEDIUM
127               || ix86_cmodel == CM_KERNEL);
129     case CONST:
130       /* We also may accept the offsetted memory references in certain
131          special cases.  */
132       if (GET_CODE (XEXP (op, 0)) == UNSPEC)
133         switch (XINT (XEXP (op, 0), 1))
134           {
135           case UNSPEC_GOTPCREL:
136           case UNSPEC_DTPOFF:
137           case UNSPEC_GOTNTPOFF:
138           case UNSPEC_NTPOFF:
139             return 1;
140           default:
141             break;
142           }
144       if (GET_CODE (XEXP (op, 0)) == PLUS)
145         {
146           rtx op1 = XEXP (XEXP (op, 0), 0);
147           rtx op2 = XEXP (XEXP (op, 0), 1);
148           HOST_WIDE_INT offset;
150           if (ix86_cmodel == CM_LARGE)
151             return 0;
152           if (!CONST_INT_P (op2))
153             return 0;
154           offset = trunc_int_for_mode (INTVAL (op2), DImode);
155           switch (GET_CODE (op1))
156             {
157             case SYMBOL_REF:
158               /* TLS symbols are not constant.  */
159               if (SYMBOL_REF_TLS_MODEL (op1))
160                 return 0;
161               /* For CM_SMALL assume that latest object is 16MB before
162                  end of 31bits boundary.  We may also accept pretty
163                  large negative constants knowing that all objects are
164                  in the positive half of address space.  */
165               if ((ix86_cmodel == CM_SMALL
166                    || (ix86_cmodel == CM_MEDIUM
167                        && !SYMBOL_REF_FAR_ADDR_P (op1)))
168                   && offset < 16*1024*1024
169                   && trunc_int_for_mode (offset, SImode) == offset)
170                 return 1;
171               /* For CM_KERNEL we know that all object resist in the
172                  negative half of 32bits address space.  We may not
173                  accept negative offsets, since they may be just off
174                  and we may accept pretty large positive ones.  */
175               if (ix86_cmodel == CM_KERNEL
176                   && offset > 0
177                   && trunc_int_for_mode (offset, SImode) == offset)
178                 return 1;
179               break;
181             case LABEL_REF:
182               /* These conditions are similar to SYMBOL_REF ones, just the
183                  constraints for code models differ.  */
184               if ((ix86_cmodel == CM_SMALL || ix86_cmodel == CM_MEDIUM)
185                   && offset < 16*1024*1024
186                   && trunc_int_for_mode (offset, SImode) == offset)
187                 return 1;
188               if (ix86_cmodel == CM_KERNEL
189                   && offset > 0
190                   && trunc_int_for_mode (offset, SImode) == offset)
191                 return 1;
192               break;
194             case UNSPEC:
195               switch (XINT (op1, 1))
196                 {
197                 case UNSPEC_DTPOFF:
198                 case UNSPEC_NTPOFF:
199                   if (offset > 0
200                       && trunc_int_for_mode (offset, SImode) == offset)
201                     return 1;
202                 }
203               break;
205             default:
206               break;
207             }
208         }
209       break;
211       default:
212         gcc_unreachable ();
213     }
215   return 0;
218 ;; Return 1 if VALUE can be stored in the zero extended immediate field.
219 (define_predicate "x86_64_zext_immediate_operand"
220   (match_code "const_double,const_int,symbol_ref,label_ref,const")
222   switch (GET_CODE (op))
223     {
224     case CONST_DOUBLE:
225       if (HOST_BITS_PER_WIDE_INT == 32)
226         return (GET_MODE (op) == VOIDmode && !CONST_DOUBLE_HIGH (op));
227       else
228         return 0;
230     case CONST_INT:
231       if (HOST_BITS_PER_WIDE_INT == 32)
232         return INTVAL (op) >= 0;
233       else
234         return !(INTVAL (op) & ~(HOST_WIDE_INT) 0xffffffff);
236     case SYMBOL_REF:
237       /* For certain code models, the symbolic references are known to fit.  */
238       /* TLS symbols are not constant.  */
239       if (SYMBOL_REF_TLS_MODEL (op))
240         return false;
241       return (ix86_cmodel == CM_SMALL
242               || (ix86_cmodel == CM_MEDIUM
243                   && !SYMBOL_REF_FAR_ADDR_P (op)));
245     case LABEL_REF:
246       /* For certain code models, the code is near as well.  */
247       return ix86_cmodel == CM_SMALL || ix86_cmodel == CM_MEDIUM;
249     case CONST:
250       /* We also may accept the offsetted memory references in certain
251          special cases.  */
252       if (GET_CODE (XEXP (op, 0)) == PLUS)
253         {
254           rtx op1 = XEXP (XEXP (op, 0), 0);
255           rtx op2 = XEXP (XEXP (op, 0), 1);
257           if (ix86_cmodel == CM_LARGE)
258             return 0;
259           switch (GET_CODE (op1))
260             {
261             case SYMBOL_REF:
262               /* TLS symbols are not constant.  */
263               if (SYMBOL_REF_TLS_MODEL (op1))
264                 return 0;
265               /* For small code model we may accept pretty large positive
266                  offsets, since one bit is available for free.  Negative
267                  offsets are limited by the size of NULL pointer area
268                  specified by the ABI.  */
269               if ((ix86_cmodel == CM_SMALL
270                    || (ix86_cmodel == CM_MEDIUM
271                        && !SYMBOL_REF_FAR_ADDR_P (op1)))
272                   && CONST_INT_P (op2)
273                   && trunc_int_for_mode (INTVAL (op2), DImode) > -0x10000
274                   && trunc_int_for_mode (INTVAL (op2), SImode) == INTVAL (op2))
275                 return 1;
276               /* ??? For the kernel, we may accept adjustment of
277                  -0x10000000, since we know that it will just convert
278                  negative address space to positive, but perhaps this
279                  is not worthwhile.  */
280               break;
282             case LABEL_REF:
283               /* These conditions are similar to SYMBOL_REF ones, just the
284                  constraints for code models differ.  */
285               if ((ix86_cmodel == CM_SMALL || ix86_cmodel == CM_MEDIUM)
286                   && CONST_INT_P (op2)
287                   && trunc_int_for_mode (INTVAL (op2), DImode) > -0x10000
288                   && trunc_int_for_mode (INTVAL (op2), SImode) == INTVAL (op2))
289                 return 1;
290               break;
292             default:
293               return 0;
294             }
295         }
296       break;
298     default:
299       gcc_unreachable ();
300     }
301   return 0;
304 ;; Return nonzero if OP is general operand representable on x86_64.
305 (define_predicate "x86_64_general_operand"
306   (if_then_else (match_test "TARGET_64BIT")
307     (ior (match_operand 0 "nonimmediate_operand")
308          (match_operand 0 "x86_64_immediate_operand"))
309     (match_operand 0 "general_operand")))
311 ;; Return nonzero if OP is general operand representable on x86_64
312 ;; as either sign extended or zero extended constant.
313 (define_predicate "x86_64_szext_general_operand"
314   (if_then_else (match_test "TARGET_64BIT")
315     (ior (match_operand 0 "nonimmediate_operand")
316          (ior (match_operand 0 "x86_64_immediate_operand")
317               (match_operand 0 "x86_64_zext_immediate_operand")))
318     (match_operand 0 "general_operand")))
320 ;; Return nonzero if OP is nonmemory operand representable on x86_64.
321 (define_predicate "x86_64_nonmemory_operand"
322   (if_then_else (match_test "TARGET_64BIT")
323     (ior (match_operand 0 "register_operand")
324          (match_operand 0 "x86_64_immediate_operand"))
325     (match_operand 0 "nonmemory_operand")))
327 ;; Return nonzero if OP is nonmemory operand representable on x86_64.
328 (define_predicate "x86_64_szext_nonmemory_operand"
329   (if_then_else (match_test "TARGET_64BIT")
330     (ior (match_operand 0 "register_operand")
331          (ior (match_operand 0 "x86_64_immediate_operand")
332               (match_operand 0 "x86_64_zext_immediate_operand")))
333     (match_operand 0 "nonmemory_operand")))
335 ;; Return true when operand is PIC expression that can be computed by lea
336 ;; operation.
337 (define_predicate "pic_32bit_operand"
338   (match_code "const,symbol_ref,label_ref")
340   if (!flag_pic)
341     return 0;
342   /* Rule out relocations that translate into 64bit constants.  */
343   if (TARGET_64BIT && GET_CODE (op) == CONST)
344     {
345       op = XEXP (op, 0);
346       if (GET_CODE (op) == PLUS && CONST_INT_P (XEXP (op, 1)))
347         op = XEXP (op, 0);
348       if (GET_CODE (op) == UNSPEC
349           && (XINT (op, 1) == UNSPEC_GOTOFF
350               || XINT (op, 1) == UNSPEC_GOT))
351         return 0;
352     }
353   return symbolic_operand (op, mode);
357 ;; Return nonzero if OP is nonmemory operand acceptable by movabs patterns.
358 (define_predicate "x86_64_movabs_operand"
359   (if_then_else (match_test "!TARGET_64BIT || !flag_pic")
360     (match_operand 0 "nonmemory_operand")
361     (ior (match_operand 0 "register_operand")
362          (and (match_operand 0 "const_double_operand")
363               (match_test "GET_MODE_SIZE (mode) <= 8")))))
365 ;; Returns nonzero if OP is either a symbol reference or a sum of a symbol
366 ;; reference and a constant.
367 (define_predicate "symbolic_operand"
368   (match_code "symbol_ref,label_ref,const")
370   switch (GET_CODE (op))
371     {
372     case SYMBOL_REF:
373     case LABEL_REF:
374       return 1;
376     case CONST:
377       op = XEXP (op, 0);
378       if (GET_CODE (op) == SYMBOL_REF
379           || GET_CODE (op) == LABEL_REF
380           || (GET_CODE (op) == UNSPEC
381               && (XINT (op, 1) == UNSPEC_GOT
382                   || XINT (op, 1) == UNSPEC_GOTOFF
383                   || XINT (op, 1) == UNSPEC_GOTPCREL)))
384         return 1;
385       if (GET_CODE (op) != PLUS
386           || !CONST_INT_P (XEXP (op, 1)))
387         return 0;
389       op = XEXP (op, 0);
390       if (GET_CODE (op) == SYMBOL_REF
391           || GET_CODE (op) == LABEL_REF)
392         return 1;
393       /* Only @GOTOFF gets offsets.  */
394       if (GET_CODE (op) != UNSPEC
395           || XINT (op, 1) != UNSPEC_GOTOFF)
396         return 0;
398       op = XVECEXP (op, 0, 0);
399       if (GET_CODE (op) == SYMBOL_REF
400           || GET_CODE (op) == LABEL_REF)
401         return 1;
402       return 0;
404     default:
405       gcc_unreachable ();
406     }
409 ;; Return true if the operand contains a @GOT or @GOTOFF reference.
410 (define_predicate "pic_symbolic_operand"
411   (match_code "const")
413   op = XEXP (op, 0);
414   if (TARGET_64BIT)
415     {
416       if (GET_CODE (op) == UNSPEC
417           && XINT (op, 1) == UNSPEC_GOTPCREL)
418         return 1;
419       if (GET_CODE (op) == PLUS
420           && GET_CODE (XEXP (op, 0)) == UNSPEC
421           && XINT (XEXP (op, 0), 1) == UNSPEC_GOTPCREL)
422         return 1;
423     }
424   else
425     {
426       if (GET_CODE (op) == UNSPEC)
427         return 1;
428       if (GET_CODE (op) != PLUS
429           || !CONST_INT_P (XEXP (op, 1)))
430         return 0;
431       op = XEXP (op, 0);
432       if (GET_CODE (op) == UNSPEC
433           && XINT (op, 1) != UNSPEC_MACHOPIC_OFFSET)
434         return 1;
435     }
436   return 0;
439 ;; Return true if OP is a symbolic operand that resolves locally.
440 (define_predicate "local_symbolic_operand"
441   (match_code "const,label_ref,symbol_ref")
443   if (GET_CODE (op) == CONST
444       && GET_CODE (XEXP (op, 0)) == PLUS
445       && CONST_INT_P (XEXP (XEXP (op, 0), 1)))
446     op = XEXP (XEXP (op, 0), 0);
448   if (GET_CODE (op) == LABEL_REF)
449     return 1;
451   if (GET_CODE (op) != SYMBOL_REF)
452     return 0;
454   if (SYMBOL_REF_TLS_MODEL (op) != 0)
455     return 0;
457   if (SYMBOL_REF_LOCAL_P (op))
458     return 1;
460   /* There is, however, a not insubstantial body of code in the rest of
461      the compiler that assumes it can just stick the results of
462      ASM_GENERATE_INTERNAL_LABEL in a symbol_ref and have done.  */
463   /* ??? This is a hack.  Should update the body of the compiler to
464      always create a DECL an invoke targetm.encode_section_info.  */
465   if (strncmp (XSTR (op, 0), internal_label_prefix,
466                internal_label_prefix_len) == 0)
467     return 1;
469   return 0;
472 ;; Test for a legitimate @GOTOFF operand.
474 ;; VxWorks does not impose a fixed gap between segments; the run-time
475 ;; gap can be different from the object-file gap.  We therefore can't
476 ;; use @GOTOFF unless we are absolutely sure that the symbol is in the
477 ;; same segment as the GOT.  Unfortunately, the flexibility of linker
478 ;; scripts means that we can't be sure of that in general, so assume
479 ;; that @GOTOFF is never valid on VxWorks.
480 (define_predicate "gotoff_operand"
481   (and (match_test "!TARGET_VXWORKS_RTP")
482        (match_operand 0 "local_symbolic_operand")))
484 ;; Test for various thread-local symbols.
485 (define_predicate "tls_symbolic_operand"
486   (and (match_code "symbol_ref")
487        (match_test "SYMBOL_REF_TLS_MODEL (op) != 0")))
489 (define_predicate "tls_modbase_operand"
490   (and (match_code "symbol_ref")
491        (match_test "op == ix86_tls_module_base ()")))
493 (define_predicate "tp_or_register_operand"
494   (ior (match_operand 0 "register_operand")
495        (and (match_code "unspec")
496             (match_test "XINT (op, 1) == UNSPEC_TP"))))
498 ;; Test for a pc-relative call operand
499 (define_predicate "constant_call_address_operand"
500   (match_code "symbol_ref")
502   if (ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
503     return false;
504   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES && SYMBOL_REF_DLLIMPORT_P (op))
505     return false;
506   return true;
509 ;; True for any non-virtual or eliminable register.  Used in places where
510 ;; instantiation of such a register may cause the pattern to not be recognized.
511 (define_predicate "register_no_elim_operand"
512   (match_operand 0 "register_operand")
514   if (GET_CODE (op) == SUBREG)
515     op = SUBREG_REG (op);
516   return !(op == arg_pointer_rtx
517            || op == frame_pointer_rtx
518            || IN_RANGE (REGNO (op),
519                         FIRST_PSEUDO_REGISTER, LAST_VIRTUAL_REGISTER));
522 ;; Similarly, but include the stack pointer.  This is used to prevent esp
523 ;; from being used as an index reg.
524 (define_predicate "index_register_operand"
525   (match_operand 0 "register_operand")
527   if (GET_CODE (op) == SUBREG)
528     op = SUBREG_REG (op);
529   if (reload_in_progress || reload_completed)
530     return REG_OK_FOR_INDEX_STRICT_P (op);
531   else
532     return REG_OK_FOR_INDEX_NONSTRICT_P (op);
535 ;; Return false if this is any eliminable register.  Otherwise general_operand.
536 (define_predicate "general_no_elim_operand"
537   (if_then_else (match_code "reg,subreg")
538     (match_operand 0 "register_no_elim_operand")
539     (match_operand 0 "general_operand")))
541 ;; Return false if this is any eliminable register.  Otherwise
542 ;; register_operand or a constant.
543 (define_predicate "nonmemory_no_elim_operand"
544   (ior (match_operand 0 "register_no_elim_operand")
545        (match_operand 0 "immediate_operand")))
547 ;; Test for a valid operand for a call instruction.
548 (define_predicate "call_insn_operand"
549   (ior (match_operand 0 "constant_call_address_operand")
550        (ior (match_operand 0 "register_no_elim_operand")
551             (match_operand 0 "memory_operand"))))
553 ;; Similarly, but for tail calls, in which we cannot allow memory references.
554 (define_predicate "sibcall_insn_operand"
555   (ior (match_operand 0 "constant_call_address_operand")
556        (match_operand 0 "register_no_elim_operand")))
558 ;; Match exactly zero.
559 (define_predicate "const0_operand"
560   (match_code "const_int,const_double,const_vector")
562   if (mode == VOIDmode)
563     mode = GET_MODE (op);
564   return op == CONST0_RTX (mode);
567 ;; Match exactly one.
568 (define_predicate "const1_operand"
569   (and (match_code "const_int")
570        (match_test "op == const1_rtx")))
572 ;; Match exactly eight.
573 (define_predicate "const8_operand"
574   (and (match_code "const_int")
575        (match_test "INTVAL (op) == 8")))
577 ;; Match 2, 4, or 8.  Used for leal multiplicands.
578 (define_predicate "const248_operand"
579   (match_code "const_int")
581   HOST_WIDE_INT i = INTVAL (op);
582   return i == 2 || i == 4 || i == 8;
585 ;; Match 0 or 1.
586 (define_predicate "const_0_to_1_operand"
587   (and (match_code "const_int")
588        (match_test "op == const0_rtx || op == const1_rtx")))
590 ;; Match 0 to 3.
591 (define_predicate "const_0_to_3_operand"
592   (and (match_code "const_int")
593        (match_test "IN_RANGE (INTVAL (op), 0, 3)")))
595 ;; Match 0 to 7.
596 (define_predicate "const_0_to_7_operand"
597   (and (match_code "const_int")
598        (match_test "IN_RANGE (INTVAL (op), 0, 7)")))
600 ;; Match 0 to 15.
601 (define_predicate "const_0_to_15_operand"
602   (and (match_code "const_int")
603        (match_test "IN_RANGE (INTVAL (op), 0, 15)")))
605 ;; Match 0 to 31.
606 (define_predicate "const_0_to_31_operand"
607   (and (match_code "const_int")
608        (match_test "IN_RANGE (INTVAL (op), 0, 31)")))
610 ;; Match 0 to 63.
611 (define_predicate "const_0_to_63_operand"
612   (and (match_code "const_int")
613        (match_test "IN_RANGE (INTVAL (op), 0, 63)")))
615 ;; Match 0 to 255.
616 (define_predicate "const_0_to_255_operand"
617   (and (match_code "const_int")
618        (match_test "IN_RANGE (INTVAL (op), 0, 255)")))
620 ;; Match (0 to 255) * 8
621 (define_predicate "const_0_to_255_mul_8_operand"
622   (match_code "const_int")
624   unsigned HOST_WIDE_INT val = INTVAL (op);
625   return val <= 255*8 && val % 8 == 0;
628 ;; Return nonzero if OP is CONST_INT >= 1 and <= 31 (a valid operand
629 ;; for shift & compare patterns, as shifting by 0 does not change flags).
630 (define_predicate "const_1_to_31_operand"
631   (and (match_code "const_int")
632        (match_test "IN_RANGE (INTVAL (op), 1, 31)")))
634 ;; Return nonzero if OP is CONST_INT >= 1 and <= 63 (a valid operand
635 ;; for 64bit shift & compare patterns, as shifting by 0 does not change flags).
636 (define_predicate "const_1_to_63_operand"
637   (and (match_code "const_int")
638        (match_test "IN_RANGE (INTVAL (op), 1, 63)")))
640 ;; Match 2 or 3.
641 (define_predicate "const_2_to_3_operand"
642   (and (match_code "const_int")
643        (match_test "IN_RANGE (INTVAL (op), 2, 3)")))
645 ;; Match 4 to 5.
646 (define_predicate "const_4_to_5_operand"
647   (and (match_code "const_int")
648        (match_test "IN_RANGE (INTVAL (op), 4, 5)")))
650 ;; Match 4 to 7.
651 (define_predicate "const_4_to_7_operand"
652   (and (match_code "const_int")
653        (match_test "IN_RANGE (INTVAL (op), 4, 7)")))
655 ;; Match 6 to 7.
656 (define_predicate "const_6_to_7_operand"
657   (and (match_code "const_int")
658        (match_test "IN_RANGE (INTVAL (op), 6, 7)")))
660 ;; Match 8 to 11.
661 (define_predicate "const_8_to_11_operand"
662   (and (match_code "const_int")
663        (match_test "IN_RANGE (INTVAL (op), 8, 11)")))
665 ;; Match 12 to 15.
666 (define_predicate "const_12_to_15_operand"
667   (and (match_code "const_int")
668        (match_test "IN_RANGE (INTVAL (op), 12, 15)")))
670 ;; Match exactly one bit in 2-bit mask.
671 (define_predicate "const_pow2_1_to_2_operand"
672   (and (match_code "const_int")
673        (match_test "INTVAL (op) == 1 || INTVAL (op) == 2")))
675 ;; Match exactly one bit in 4-bit mask.
676 (define_predicate "const_pow2_1_to_8_operand"
677   (match_code "const_int")
679   unsigned int log = exact_log2 (INTVAL (op));
680   return log <= 3;
683 ;; Match exactly one bit in 8-bit mask.
684 (define_predicate "const_pow2_1_to_128_operand"
685   (match_code "const_int")
687   unsigned int log = exact_log2 (INTVAL (op));
688   return log <= 7;
691 ;; Match exactly one bit in 16-bit mask.
692 (define_predicate "const_pow2_1_to_32768_operand"
693   (match_code "const_int")
695   unsigned int log = exact_log2 (INTVAL (op));
696   return log <= 15;
699 ;; True if this is a constant appropriate for an increment or decrement.
700 (define_predicate "incdec_operand"
701   (match_code "const_int")
703   /* On Pentium4, the inc and dec operations causes extra dependency on flag
704      registers, since carry flag is not set.  */
705   if (!TARGET_USE_INCDEC && !optimize_size)
706     return 0;
707   return op == const1_rtx || op == constm1_rtx;
710 ;; True for registers, or 1 or -1.  Used to optimize double-word shifts.
711 (define_predicate "reg_or_pm1_operand"
712   (ior (match_operand 0 "register_operand")
713        (and (match_code "const_int")
714             (match_test "op == const1_rtx || op == constm1_rtx"))))
716 ;; True if OP is acceptable as operand of DImode shift expander.
717 (define_predicate "shiftdi_operand"
718   (if_then_else (match_test "TARGET_64BIT")
719     (match_operand 0 "nonimmediate_operand")
720     (match_operand 0 "register_operand")))
722 (define_predicate "ashldi_input_operand"
723   (if_then_else (match_test "TARGET_64BIT")
724     (match_operand 0 "nonimmediate_operand")
725     (match_operand 0 "reg_or_pm1_operand")))
727 ;; Return true if OP is a vector load from the constant pool with just
728 ;; the first element nonzero.
729 (define_predicate "zero_extended_scalar_load_operand"
730   (match_code "mem")
732   unsigned n_elts;
733   op = maybe_get_pool_constant (op);
734   if (!op)
735     return 0;
736   if (GET_CODE (op) != CONST_VECTOR)
737     return 0;
738   n_elts =
739     (GET_MODE_SIZE (GET_MODE (op)) /
740      GET_MODE_SIZE (GET_MODE_INNER (GET_MODE (op))));
741   for (n_elts--; n_elts > 0; n_elts--)
742     {
743       rtx elt = CONST_VECTOR_ELT (op, n_elts);
744       if (elt != CONST0_RTX (GET_MODE_INNER (GET_MODE (op))))
745         return 0;
746     }
747   return 1;
750 /* Return true if operand is a vector constant that is all ones. */
751 (define_predicate "vector_all_ones_operand"
752   (match_code "const_vector")
754   int nunits = GET_MODE_NUNITS (mode);
756   if (GET_CODE (op) == CONST_VECTOR
757       && CONST_VECTOR_NUNITS (op) == nunits)
758     {
759       int i;
760       for (i = 0; i < nunits; ++i)
761         {
762           rtx x = CONST_VECTOR_ELT (op, i);
763           if (x != constm1_rtx)
764             return 0;
765         }
766       return 1;
767     }
769   return 0;
772 ; Return 1 when OP is operand acceptable for standard SSE move.
773 (define_predicate "vector_move_operand"
774   (ior (match_operand 0 "nonimmediate_operand")
775        (match_operand 0 "const0_operand")))
777 ;; Return 1 when OP is nonimmediate or standard SSE constant.
778 (define_predicate "nonimmediate_or_sse_const_operand"
779   (match_operand 0 "general_operand")
781   if (nonimmediate_operand (op, mode))
782     return 1;
783   if (standard_sse_constant_p (op) > 0)
784     return 1;
785   return 0;
788 ;; Return true if OP is a register or a zero.
789 (define_predicate "reg_or_0_operand"
790   (ior (match_operand 0 "register_operand")
791        (match_operand 0 "const0_operand")))
793 ;; Return true if op if a valid address, and does not contain
794 ;; a segment override.
795 (define_special_predicate "no_seg_address_operand"
796   (match_operand 0 "address_operand")
798   struct ix86_address parts;
799   int ok;
801   ok = ix86_decompose_address (op, &parts);
802   gcc_assert (ok);
803   return parts.seg == SEG_DEFAULT;
806 ;; Return nonzero if the rtx is known to be at least 32 bits aligned.
807 (define_predicate "aligned_operand"
808   (match_operand 0 "general_operand")
810   struct ix86_address parts;
811   int ok;
813   /* Registers and immediate operands are always "aligned".  */
814   if (GET_CODE (op) != MEM)
815     return 1;
817   /* All patterns using aligned_operand on memory operands ends up
818      in promoting memory operand to 64bit and thus causing memory mismatch.  */
819   if (TARGET_MEMORY_MISMATCH_STALL && !optimize_size)
820     return 0;
822   /* Don't even try to do any aligned optimizations with volatiles.  */
823   if (MEM_VOLATILE_P (op))
824     return 0;
826   if (MEM_ALIGN (op) >= 32)
827     return 1;
829   op = XEXP (op, 0);
831   /* Pushes and pops are only valid on the stack pointer.  */
832   if (GET_CODE (op) == PRE_DEC
833       || GET_CODE (op) == POST_INC)
834     return 1;
836   /* Decode the address.  */
837   ok = ix86_decompose_address (op, &parts);
838   gcc_assert (ok);
840   /* Look for some component that isn't known to be aligned.  */
841   if (parts.index)
842     {
843       if (REGNO_POINTER_ALIGN (REGNO (parts.index)) * parts.scale < 32)
844         return 0;
845     }
846   if (parts.base)
847     {
848       if (REGNO_POINTER_ALIGN (REGNO (parts.base)) < 32)
849         return 0;
850     }
851   if (parts.disp)
852     {
853       if (!CONST_INT_P (parts.disp)
854           || (INTVAL (parts.disp) & 3) != 0)
855         return 0;
856     }
858   /* Didn't find one -- this must be an aligned address.  */
859   return 1;
862 ;; Returns 1 if OP is memory operand with a displacement.
863 (define_predicate "memory_displacement_operand"
864   (match_operand 0 "memory_operand")
866   struct ix86_address parts;
867   int ok;
869   ok = ix86_decompose_address (XEXP (op, 0), &parts);
870   gcc_assert (ok);
871   return parts.disp != NULL_RTX;
874 ;; Returns 1 if OP is memory operand with a displacement only.
875 (define_predicate "memory_displacement_only_operand"
876   (match_operand 0 "memory_operand")
878   struct ix86_address parts;
879   int ok;
881   ok = ix86_decompose_address (XEXP (op, 0), &parts);
882   gcc_assert (ok);
884   if (parts.base || parts.index)
885     return 0;
887   return parts.disp != NULL_RTX;
890 ;; Returns 1 if OP is memory operand that cannot be represented
891 ;; by the modRM array.
892 (define_predicate "long_memory_operand"
893   (and (match_operand 0 "memory_operand")
894        (match_test "memory_address_length (op) != 0")))
896 ;; Return 1 if OP is a comparison operator that can be issued by fcmov.
897 (define_predicate "fcmov_comparison_operator"
898   (match_operand 0 "comparison_operator")
900   enum machine_mode inmode = GET_MODE (XEXP (op, 0));
901   enum rtx_code code = GET_CODE (op);
903   if (inmode == CCFPmode || inmode == CCFPUmode)
904     {
905       enum rtx_code second_code, bypass_code;
906       ix86_fp_comparison_codes (code, &bypass_code, &code, &second_code);
907       if (bypass_code != UNKNOWN || second_code != UNKNOWN)
908         return 0;
909       code = ix86_fp_compare_code_to_integer (code);
910     }
911   /* i387 supports just limited amount of conditional codes.  */
912   switch (code)
913     {
914     case LTU: case GTU: case LEU: case GEU:
915       if (inmode == CCmode || inmode == CCFPmode || inmode == CCFPUmode
916           || inmode == CCCmode)
917         return 1;
918       return 0;
919     case ORDERED: case UNORDERED:
920     case EQ: case NE:
921       return 1;
922     default:
923       return 0;
924     }
927 ;; Return 1 if OP is a comparison that can be used in the CMPSS/CMPPS insns.
928 ;; The first set are supported directly; the second set can't be done with
929 ;; full IEEE support, i.e. NaNs.
931 ;; ??? It would seem that we have a lot of uses of this predicate that pass
932 ;; it the wrong mode.  We got away with this because the old function didn't
933 ;; check the mode at all.  Mirror that for now by calling this a special
934 ;; predicate.
936 (define_special_predicate "sse_comparison_operator"
937   (match_code "eq,lt,le,unordered,ne,unge,ungt,ordered"))
939 ;; Return 1 if OP is a comparison operator that can be issued by
940 ;; avx predicate generation instructions
941 (define_predicate "avx_comparison_float_operator"
942   (match_code "ne,eq,ge,gt,le,lt,unordered,ordered,uneq,unge,ungt,unle,unlt,ltgt"))
944 ;; Return 1 if OP is a comparison operator that can be issued by sse predicate
945 ;; generation instructions
946 (define_predicate "sse5_comparison_float_operator"
947   (and (match_test "TARGET_SSE5")
948        (match_code "ne,eq,ge,gt,le,lt,unordered,ordered,uneq,unge,ungt,unle,unlt,ltgt")))
950 (define_predicate "ix86_comparison_int_operator"
951   (match_code "ne,eq,ge,gt,le,lt"))
953 (define_predicate "ix86_comparison_uns_operator"
954   (match_code "ne,eq,geu,gtu,leu,ltu"))
956 (define_predicate "bt_comparison_operator"
957   (match_code "ne,eq"))
959 ;; Return 1 if OP is a valid comparison operator in valid mode.
960 (define_predicate "ix86_comparison_operator"
961   (match_operand 0 "comparison_operator")
963   enum machine_mode inmode = GET_MODE (XEXP (op, 0));
964   enum rtx_code code = GET_CODE (op);
966   if (inmode == CCFPmode || inmode == CCFPUmode)
967     {
968       enum rtx_code second_code, bypass_code;
969       ix86_fp_comparison_codes (code, &bypass_code, &code, &second_code);
970       return (bypass_code == UNKNOWN && second_code == UNKNOWN);
971     }
972   switch (code)
973     {
974     case EQ: case NE:
975       return 1;
976     case LT: case GE:
977       if (inmode == CCmode || inmode == CCGCmode
978           || inmode == CCGOCmode || inmode == CCNOmode)
979         return 1;
980       return 0;
981     case LTU: case GTU: case LEU: case GEU:
982       if (inmode == CCmode || inmode == CCCmode)
983         return 1;
984       return 0;
985     case ORDERED: case UNORDERED:
986       if (inmode == CCmode)
987         return 1;
988       return 0;
989     case GT: case LE:
990       if (inmode == CCmode || inmode == CCGCmode || inmode == CCNOmode)
991         return 1;
992       return 0;
993     default:
994       return 0;
995     }
998 ;; Return 1 if OP is a valid comparison operator testing carry flag to be set.
999 (define_predicate "ix86_carry_flag_operator"
1000   (match_code "ltu,lt,unlt,gtu,gt,ungt,le,unle,ge,unge,ltgt,uneq")
1002   enum machine_mode inmode = GET_MODE (XEXP (op, 0));
1003   enum rtx_code code = GET_CODE (op);
1005   if (!REG_P (XEXP (op, 0))
1006       || REGNO (XEXP (op, 0)) != FLAGS_REG
1007       || XEXP (op, 1) != const0_rtx)
1008     return 0;
1010   if (inmode == CCFPmode || inmode == CCFPUmode)
1011     {
1012       enum rtx_code second_code, bypass_code;
1013       ix86_fp_comparison_codes (code, &bypass_code, &code, &second_code);
1014       if (bypass_code != UNKNOWN || second_code != UNKNOWN)
1015         return 0;
1016       code = ix86_fp_compare_code_to_integer (code);
1017     }
1018   else if (inmode == CCCmode)
1019    return code == LTU || code == GTU;
1020   else if (inmode != CCmode)
1021     return 0;
1023   return code == LTU;
1026 ;; Nearly general operand, but accept any const_double, since we wish
1027 ;; to be able to drop them into memory rather than have them get pulled
1028 ;; into registers.
1029 (define_predicate "cmp_fp_expander_operand"
1030   (ior (match_code "const_double")
1031        (match_operand 0 "general_operand")))
1033 ;; Return true if this is a valid binary floating-point operation.
1034 (define_predicate "binary_fp_operator"
1035   (match_code "plus,minus,mult,div"))
1037 ;; Return true if this is a multiply operation.
1038 (define_predicate "mult_operator"
1039   (match_code "mult"))
1041 ;; Return true if this is a division operation.
1042 (define_predicate "div_operator"
1043   (match_code "div"))
1045 ;; Return true if this is a float extend operation.
1046 (define_predicate "float_operator"
1047   (match_code "float"))
1049 ;; Return true for ARITHMETIC_P.
1050 (define_predicate "arith_or_logical_operator"
1051   (match_code "plus,mult,and,ior,xor,smin,smax,umin,umax,compare,minus,div,
1052                mod,udiv,umod,ashift,rotate,ashiftrt,lshiftrt,rotatert"))
1054 ;; Return true for COMMUTATIVE_P.
1055 (define_predicate "commutative_operator"
1056   (match_code "plus,mult,and,ior,xor,smin,smax,umin,umax"))
1058 ;; Return 1 if OP is a binary operator that can be promoted to wider mode.
1059 (define_predicate "promotable_binary_operator"
1060   (ior (match_code "plus,and,ior,xor,ashift")
1061        (and (match_code "mult")
1062             (match_test "TARGET_TUNE_PROMOTE_HIMODE_IMUL"))))
1064 ;; To avoid problems when jump re-emits comparisons like testqi_ext_ccno_0,
1065 ;; re-recognize the operand to avoid a copy_to_mode_reg that will fail.
1067 ;; ??? It seems likely that this will only work because cmpsi is an
1068 ;; expander, and no actual insns use this.
1070 (define_predicate "cmpsi_operand"
1071   (ior (match_operand 0 "nonimmediate_operand")
1072        (and (match_code "and")
1073             (match_code "zero_extract" "0")
1074             (match_code "const_int"    "1")
1075             (match_code "const_int"    "01")
1076             (match_code "const_int"    "02")
1077             (match_test "INTVAL (XEXP (XEXP (op, 0), 1)) == 8")
1078             (match_test "INTVAL (XEXP (XEXP (op, 0), 2)) == 8")
1079        )))
1081 (define_predicate "compare_operator"
1082   (match_code "compare"))
1084 (define_predicate "absneg_operator"
1085   (match_code "abs,neg"))
1087 ;; Return 1 if OP is misaligned memory operand
1088 (define_predicate "misaligned_operand"
1089   (and (match_code "mem")
1090        (match_test "MEM_ALIGN (op) < GET_MODE_ALIGNMENT (mode)")))
1092 ;; Return 1 if OP is a vzeroall operation, known to be a PARALLEL.
1093 (define_predicate "vzeroall_operation"
1094   (match_code "parallel")
1096   int nregs = TARGET_64BIT ? 16 : 8;
1098   if (XVECLEN (op, 0) != nregs + 1)
1099     return 0;
1101   return 1;