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