OSDN Git Service

2011-05-09 Uros Bizjak <ubizjak@gmail.com>
[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 ;; True if this is a constant appropriate for an increment or decrement.
692 (define_predicate "incdec_operand"
693   (match_code "const_int")
694 {
695   /* On Pentium4, the inc and dec operations causes extra dependency on flag
696      registers, since carry flag is not set.  */
697   if (!TARGET_USE_INCDEC && !optimize_insn_for_size_p ())
698     return false;
699   return op == const1_rtx || op == constm1_rtx;
700 })
701
702 ;; True for registers, or 1 or -1.  Used to optimize double-word shifts.
703 (define_predicate "reg_or_pm1_operand"
704   (ior (match_operand 0 "register_operand")
705        (and (match_code "const_int")
706             (ior (match_test "op == const1_rtx")
707                  (match_test "op == constm1_rtx")))))
708
709 ;; True if OP is acceptable as operand of DImode shift expander.
710 (define_predicate "shiftdi_operand"
711   (if_then_else (match_test "TARGET_64BIT")
712     (match_operand 0 "nonimmediate_operand")
713     (match_operand 0 "register_operand")))
714
715 (define_predicate "ashldi_input_operand"
716   (if_then_else (match_test "TARGET_64BIT")
717     (match_operand 0 "nonimmediate_operand")
718     (match_operand 0 "reg_or_pm1_operand")))
719
720 ;; Return true if OP is a vector load from the constant pool with just
721 ;; the first element nonzero.
722 (define_predicate "zero_extended_scalar_load_operand"
723   (match_code "mem")
724 {
725   unsigned n_elts;
726   op = maybe_get_pool_constant (op);
727
728   if (!(op && GET_CODE (op) == CONST_VECTOR))
729     return false;
730
731   n_elts = CONST_VECTOR_NUNITS (op);
732
733   for (n_elts--; n_elts > 0; n_elts--)
734     {
735       rtx elt = CONST_VECTOR_ELT (op, n_elts);
736       if (elt != CONST0_RTX (GET_MODE_INNER (GET_MODE (op))))
737         return false;
738     }
739   return true;
740 })
741
742 /* Return true if operand is a vector constant that is all ones. */
743 (define_predicate "vector_all_ones_operand"
744   (match_code "const_vector")
745 {
746   int nunits = GET_MODE_NUNITS (mode);
747
748   if (GET_CODE (op) == CONST_VECTOR
749       && CONST_VECTOR_NUNITS (op) == nunits)
750     {
751       int i;
752       for (i = 0; i < nunits; ++i)
753         {
754           rtx x = CONST_VECTOR_ELT (op, i);
755           if (x != constm1_rtx)
756             return false;
757         }
758       return true;
759     }
760
761   return false;
762 })
763
764 ; Return true when OP is operand acceptable for standard SSE move.
765 (define_predicate "vector_move_operand"
766   (ior (match_operand 0 "nonimmediate_operand")
767        (match_operand 0 "const0_operand")))
768
769 ;; Return true when OP is nonimmediate or standard SSE constant.
770 (define_predicate "nonimmediate_or_sse_const_operand"
771   (match_operand 0 "general_operand")
772 {
773   if (nonimmediate_operand (op, mode))
774     return true;
775   if (standard_sse_constant_p (op) > 0)
776     return true;
777   return false;
778 })
779
780 ;; Return true if OP is a register or a zero.
781 (define_predicate "reg_or_0_operand"
782   (ior (match_operand 0 "register_operand")
783        (match_operand 0 "const0_operand")))
784
785 ;; Return true if op if a valid address, and does not contain
786 ;; a segment override.
787 (define_special_predicate "no_seg_address_operand"
788   (match_operand 0 "address_operand")
789 {
790   struct ix86_address parts;
791   int ok;
792
793   ok = ix86_decompose_address (op, &parts);
794   gcc_assert (ok);
795   return parts.seg == SEG_DEFAULT;
796 })
797
798 ;; Return true if the rtx is known to be at least 32 bits aligned.
799 (define_predicate "aligned_operand"
800   (match_operand 0 "general_operand")
801 {
802   struct ix86_address parts;
803   int ok;
804
805   /* Registers and immediate operands are always "aligned".  */
806   if (!MEM_P (op))
807     return true;
808
809   /* All patterns using aligned_operand on memory operands ends up
810      in promoting memory operand to 64bit and thus causing memory mismatch.  */
811   if (TARGET_MEMORY_MISMATCH_STALL && !optimize_insn_for_size_p ())
812     return false;
813
814   /* Don't even try to do any aligned optimizations with volatiles.  */
815   if (MEM_VOLATILE_P (op))
816     return false;
817
818   if (MEM_ALIGN (op) >= 32)
819     return true;
820
821   op = XEXP (op, 0);
822
823   /* Pushes and pops are only valid on the stack pointer.  */
824   if (GET_CODE (op) == PRE_DEC
825       || GET_CODE (op) == POST_INC)
826     return true;
827
828   /* Decode the address.  */
829   ok = ix86_decompose_address (op, &parts);
830   gcc_assert (ok);
831
832   /* Look for some component that isn't known to be aligned.  */
833   if (parts.index)
834     {
835       if (REGNO_POINTER_ALIGN (REGNO (parts.index)) * parts.scale < 32)
836         return false;
837     }
838   if (parts.base)
839     {
840       if (REGNO_POINTER_ALIGN (REGNO (parts.base)) < 32)
841         return false;
842     }
843   if (parts.disp)
844     {
845       if (!CONST_INT_P (parts.disp)
846           || (INTVAL (parts.disp) & 3))
847         return false;
848     }
849
850   /* Didn't find one -- this must be an aligned address.  */
851   return true;
852 })
853
854 ;; Return true if OP is memory operand with a displacement.
855 (define_predicate "memory_displacement_operand"
856   (match_operand 0 "memory_operand")
857 {
858   struct ix86_address parts;
859   int ok;
860
861   ok = ix86_decompose_address (XEXP (op, 0), &parts);
862   gcc_assert (ok);
863   return parts.disp != NULL_RTX;
864 })
865
866 ;; Return true if OP is memory operand with a displacement only.
867 (define_predicate "memory_displacement_only_operand"
868   (match_operand 0 "memory_operand")
869 {
870   struct ix86_address parts;
871   int ok;
872
873   if (TARGET_64BIT)
874     return false;
875
876   ok = ix86_decompose_address (XEXP (op, 0), &parts);
877   gcc_assert (ok);
878
879   if (parts.base || parts.index)
880     return false;
881
882   return parts.disp != NULL_RTX;
883 })
884
885 ;; Return true if OP is memory operand which will need zero or
886 ;; one register at most, not counting stack pointer or frame pointer.
887 (define_predicate "cmpxchg8b_pic_memory_operand"
888   (match_operand 0 "memory_operand")
889 {
890   struct ix86_address parts;
891   int ok;
892
893   ok = ix86_decompose_address (XEXP (op, 0), &parts);
894   gcc_assert (ok);
895   if (parts.base == NULL_RTX
896       || parts.base == arg_pointer_rtx
897       || parts.base == frame_pointer_rtx
898       || parts.base == hard_frame_pointer_rtx
899       || parts.base == stack_pointer_rtx)
900     return true;
901
902   if (parts.index == NULL_RTX
903       || parts.index == arg_pointer_rtx
904       || parts.index == frame_pointer_rtx
905       || parts.index == hard_frame_pointer_rtx
906       || parts.index == stack_pointer_rtx)
907     return true;
908
909   return false;
910 })
911
912
913 ;; Return true if OP is memory operand that cannot be represented
914 ;; by the modRM array.
915 (define_predicate "long_memory_operand"
916   (and (match_operand 0 "memory_operand")
917        (match_test "memory_address_length (op)")))
918
919 ;; Return true if OP is a comparison operator that can be issued by fcmov.
920 (define_predicate "fcmov_comparison_operator"
921   (match_operand 0 "comparison_operator")
922 {
923   enum machine_mode inmode = GET_MODE (XEXP (op, 0));
924   enum rtx_code code = GET_CODE (op);
925
926   if (inmode == CCFPmode || inmode == CCFPUmode)
927     {
928       if (!ix86_trivial_fp_comparison_operator (op, mode))
929         return false;
930       code = ix86_fp_compare_code_to_integer (code);
931     }
932   /* i387 supports just limited amount of conditional codes.  */
933   switch (code)
934     {
935     case LTU: case GTU: case LEU: case GEU:
936       if (inmode == CCmode || inmode == CCFPmode || inmode == CCFPUmode
937           || inmode == CCCmode)
938         return true;
939       return false;
940     case ORDERED: case UNORDERED:
941     case EQ: case NE:
942       return true;
943     default:
944       return false;
945     }
946 })
947
948 ;; Return true if OP is a comparison that can be used in the CMPSS/CMPPS insns.
949 ;; The first set are supported directly; the second set can't be done with
950 ;; full IEEE support, i.e. NaNs.
951
952 (define_predicate "sse_comparison_operator"
953   (ior (match_code "eq,ne,lt,le,unordered,unge,ungt,ordered")
954        (and (match_test "TARGET_AVX")
955             (match_code "ge,gt,uneq,unle,unlt,ltgt"))))
956
957 (define_predicate "ix86_comparison_int_operator"
958   (match_code "ne,eq,ge,gt,le,lt"))
959
960 (define_predicate "ix86_comparison_uns_operator"
961   (match_code "ne,eq,geu,gtu,leu,ltu"))
962
963 (define_predicate "bt_comparison_operator"
964   (match_code "ne,eq"))
965
966 ;; Return true if OP is a valid comparison operator in valid mode.
967 (define_predicate "ix86_comparison_operator"
968   (match_operand 0 "comparison_operator")
969 {
970   enum machine_mode inmode = GET_MODE (XEXP (op, 0));
971   enum rtx_code code = GET_CODE (op);
972
973   if (inmode == CCFPmode || inmode == CCFPUmode)
974     return ix86_trivial_fp_comparison_operator (op, mode);
975
976   switch (code)
977     {
978     case EQ: case NE:
979       return true;
980     case LT: case GE:
981       if (inmode == CCmode || inmode == CCGCmode
982           || inmode == CCGOCmode || inmode == CCNOmode)
983         return true;
984       return false;
985     case LTU: case GTU: case LEU: case GEU:
986       if (inmode == CCmode || inmode == CCCmode)
987         return true;
988       return false;
989     case ORDERED: case UNORDERED:
990       if (inmode == CCmode)
991         return true;
992       return false;
993     case GT: case LE:
994       if (inmode == CCmode || inmode == CCGCmode || inmode == CCNOmode)
995         return true;
996       return false;
997     default:
998       return false;
999     }
1000 })
1001
1002 ;; Return true if OP is a valid comparison operator
1003 ;; testing carry flag to be set.
1004 (define_predicate "ix86_carry_flag_operator"
1005   (match_code "ltu,lt,unlt,gtu,gt,ungt,le,unle,ge,unge,ltgt,uneq")
1006 {
1007   enum machine_mode inmode = GET_MODE (XEXP (op, 0));
1008   enum rtx_code code = GET_CODE (op);
1009
1010   if (inmode == CCFPmode || inmode == CCFPUmode)
1011     {
1012       if (!ix86_trivial_fp_comparison_operator (op, mode))
1013         return false;
1014       code = ix86_fp_compare_code_to_integer (code);
1015     }
1016   else if (inmode == CCCmode)
1017    return code == LTU || code == GTU;
1018   else if (inmode != CCmode)
1019     return false;
1020
1021   return code == LTU;
1022 })
1023
1024 ;; Return true if this comparison only requires testing one flag bit.
1025 (define_predicate "ix86_trivial_fp_comparison_operator"
1026   (match_code "gt,ge,unlt,unle,uneq,ltgt,ordered,unordered"))
1027
1028 ;; Return true if we know how to do this comparison.  Others require
1029 ;; testing more than one flag bit, and we let the generic middle-end
1030 ;; code do that.
1031 (define_predicate "ix86_fp_comparison_operator"
1032   (if_then_else (match_test "ix86_fp_comparison_strategy (GET_CODE (op))
1033                              == IX86_FPCMP_ARITH")
1034                (match_operand 0 "comparison_operator")
1035                (match_operand 0 "ix86_trivial_fp_comparison_operator")))
1036
1037 ;; Same as above, but for swapped comparison used in fp_jcc_4_387.
1038 (define_predicate "ix86_swapped_fp_comparison_operator"
1039   (match_operand 0 "comparison_operator")
1040 {
1041   enum rtx_code code = GET_CODE (op);
1042   bool ret;
1043
1044   PUT_CODE (op, swap_condition (code));
1045   ret = ix86_fp_comparison_operator (op, mode);
1046   PUT_CODE (op, code);
1047   return ret;
1048 })
1049
1050 ;; Nearly general operand, but accept any const_double, since we wish
1051 ;; to be able to drop them into memory rather than have them get pulled
1052 ;; into registers.
1053 (define_predicate "cmp_fp_expander_operand"
1054   (ior (match_code "const_double")
1055        (match_operand 0 "general_operand")))
1056
1057 ;; Return true if this is a valid binary floating-point operation.
1058 (define_predicate "binary_fp_operator"
1059   (match_code "plus,minus,mult,div"))
1060
1061 ;; Return true if this is a multiply operation.
1062 (define_predicate "mult_operator"
1063   (match_code "mult"))
1064
1065 ;; Return true if this is a division operation.
1066 (define_predicate "div_operator"
1067   (match_code "div"))
1068
1069 ;; Return true if this is a float extend operation.
1070 (define_predicate "float_operator"
1071   (match_code "float"))
1072
1073 ;; Return true for ARITHMETIC_P.
1074 (define_predicate "arith_or_logical_operator"
1075   (match_code "plus,mult,and,ior,xor,smin,smax,umin,umax,compare,minus,div,
1076                mod,udiv,umod,ashift,rotate,ashiftrt,lshiftrt,rotatert"))
1077
1078 ;; Return true for COMMUTATIVE_P.
1079 (define_predicate "commutative_operator"
1080   (match_code "plus,mult,and,ior,xor,smin,smax,umin,umax"))
1081
1082 ;; Return true if OP is a binary operator that can be promoted to wider mode.
1083 (define_predicate "promotable_binary_operator"
1084   (ior (match_code "plus,and,ior,xor,ashift")
1085        (and (match_code "mult")
1086             (match_test "TARGET_TUNE_PROMOTE_HIMODE_IMUL"))))
1087
1088 (define_predicate "compare_operator"
1089   (match_code "compare"))
1090
1091 (define_predicate "absneg_operator"
1092   (match_code "abs,neg"))
1093
1094 ;; Return true if OP is misaligned memory operand
1095 (define_predicate "misaligned_operand"
1096   (and (match_code "mem")
1097        (match_test "MEM_ALIGN (op) < GET_MODE_ALIGNMENT (mode)")))
1098
1099 ;; Return true if OP is a emms operation, known to be a PARALLEL.
1100 (define_predicate "emms_operation"
1101   (match_code "parallel")
1102 {
1103   unsigned i;
1104
1105   if (XVECLEN (op, 0) != 17)
1106     return false;
1107
1108   for (i = 0; i < 8; i++)
1109     {
1110       rtx elt = XVECEXP (op, 0, i+1);
1111
1112       if (GET_CODE (elt) != CLOBBER
1113           || GET_CODE (SET_DEST (elt)) != REG
1114           || GET_MODE (SET_DEST (elt)) != XFmode
1115           || REGNO (SET_DEST (elt)) != FIRST_STACK_REG + i)
1116         return false;
1117
1118       elt = XVECEXP (op, 0, i+9);
1119
1120       if (GET_CODE (elt) != CLOBBER
1121           || GET_CODE (SET_DEST (elt)) != REG
1122           || GET_MODE (SET_DEST (elt)) != DImode
1123           || REGNO (SET_DEST (elt)) != FIRST_MMX_REG + i)
1124         return false;
1125     }
1126   return true;
1127 })
1128
1129 ;; Return true if OP is a vzeroall operation, known to be a PARALLEL.
1130 (define_predicate "vzeroall_operation"
1131   (match_code "parallel")
1132 {
1133   unsigned i, nregs = TARGET_64BIT ? 16 : 8;
1134
1135   if ((unsigned) XVECLEN (op, 0) != 1 + nregs)
1136     return false;
1137
1138   for (i = 0; i < nregs; i++)
1139     {
1140       rtx elt = XVECEXP (op, 0, i+1);
1141
1142       if (GET_CODE (elt) != SET
1143           || GET_CODE (SET_DEST (elt)) != REG
1144           || GET_MODE (SET_DEST (elt)) != V8SImode
1145           || REGNO (SET_DEST (elt)) != SSE_REGNO (i)
1146           || SET_SRC (elt) != CONST0_RTX (V8SImode))
1147         return false;
1148     }
1149   return true;
1150 })
1151
1152 ;; Return true if OP is a parallel for a vbroadcast permute.
1153
1154 (define_predicate "avx_vbroadcast_operand"
1155   (and (match_code "parallel")
1156        (match_code "const_int" "a"))
1157 {
1158   rtx elt = XVECEXP (op, 0, 0);
1159   int i, nelt = XVECLEN (op, 0);
1160
1161   /* Don't bother checking there are the right number of operands,
1162      merely that they're all identical.  */
1163   for (i = 1; i < nelt; ++i)
1164     if (XVECEXP (op, 0, i) != elt)
1165       return false;
1166   return true;
1167 })