OSDN Git Service

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