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