5fa93fa05b95a935b4eaf6523ba0a627ebd8d4b7
[gcc.git] / gcc / config / i386 / predicates.md
1 ;; Predicate definitions for IA-32 and x86-64.
2 ;; Copyright (C) 2004 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 2, 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 COPYING. If not, write to
18 ;; the Free Software Foundation, 59 Temple Place - Suite 330,
19 ;; Boston, MA 02111-1307, USA.
20
21 ;; Return nonzero if OP is either a i387 or SSE fp register.
22 (define_predicate "any_fp_register_operand"
23 (and (match_code "reg")
24 (match_test "ANY_FP_REGNO_P (REGNO (op))")))
25
26 ;; Return nonzero if OP is an i387 fp register.
27 (define_predicate "fp_register_operand"
28 (and (match_code "reg")
29 (match_test "FP_REGNO_P (REGNO (op))")))
30
31 ;; Return nonzero if OP is a non-fp register_operand.
32 (define_predicate "register_and_not_any_fp_reg_operand"
33 (and (match_code "reg")
34 (not (match_test "ANY_FP_REGNO_P (REGNO (op))"))))
35
36 ;; Return nonzero if OP is a register operand other than an i387 fp register.
37 (define_predicate "register_and_not_fp_reg_operand"
38 (and (match_code "reg")
39 (not (match_test "FP_REGNO_P (REGNO (op))"))))
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 a Q_REGS class register.
47 (define_predicate "q_regs_operand"
48 (match_operand 0 "register_operand")
49 {
50 if (GET_CODE (op) == SUBREG)
51 op = SUBREG_REG (op);
52 return ANY_QI_REG_P (op);
53 })
54
55 ;; Return true if op is a NON_Q_REGS class register.
56 (define_predicate "non_q_regs_operand"
57 (match_operand 0 "register_operand")
58 {
59 if (GET_CODE (op) == SUBREG)
60 op = SUBREG_REG (op);
61 return NON_QI_REG_P (op);
62 })
63
64 ;; Match an SI or HImode register for a zero_extract.
65 (define_special_predicate "ext_register_operand"
66 (match_operand 0 "register_operand")
67 {
68 if ((!TARGET_64BIT || GET_MODE (op) != DImode)
69 && GET_MODE (op) != SImode && GET_MODE (op) != HImode)
70 return 0;
71 if (GET_CODE (op) == SUBREG)
72 op = SUBREG_REG (op);
73
74 /* Be careful to accept only registers having upper parts. */
75 return REGNO (op) > LAST_VIRTUAL_REGISTER || REGNO (op) < 4;
76 })
77
78 ;; Return true if op is the flags register.
79 (define_predicate "flags_reg_operand"
80 (and (match_code "reg")
81 (match_test "REGNO (op) == FLAGS_REG")))
82
83 ;; Return 1 if VALUE can be stored in a sign extended immediate field.
84 (define_predicate "x86_64_immediate_operand"
85 (match_code "const_int,symbol_ref,label_ref,const")
86 {
87 if (!TARGET_64BIT)
88 return immediate_operand (op, mode);
89
90 switch (GET_CODE (op))
91 {
92 case CONST_INT:
93 /* CONST_DOUBLES never match, since HOST_BITS_PER_WIDE_INT is known
94 to be at least 32 and this all acceptable constants are
95 represented as CONST_INT. */
96 if (HOST_BITS_PER_WIDE_INT == 32)
97 return 1;
98 else
99 {
100 HOST_WIDE_INT val = trunc_int_for_mode (INTVAL (op), DImode);
101 return trunc_int_for_mode (val, SImode) == val;
102 }
103 break;
104
105 case SYMBOL_REF:
106 /* For certain code models, the symbolic references are known to fit.
107 in CM_SMALL_PIC model we know it fits if it is local to the shared
108 library. Don't count TLS SYMBOL_REFs here, since they should fit
109 only if inside of UNSPEC handled below. */
110 /* TLS symbols are not constant. */
111 if (tls_symbolic_operand (op, Pmode))
112 return false;
113 return (ix86_cmodel == CM_SMALL || ix86_cmodel == CM_KERNEL);
114
115 case LABEL_REF:
116 /* For certain code models, the code is near as well. */
117 return (ix86_cmodel == CM_SMALL || ix86_cmodel == CM_MEDIUM
118 || ix86_cmodel == CM_KERNEL);
119
120 case CONST:
121 /* We also may accept the offsetted memory references in certain
122 special cases. */
123 if (GET_CODE (XEXP (op, 0)) == UNSPEC)
124 switch (XINT (XEXP (op, 0), 1))
125 {
126 case UNSPEC_GOTPCREL:
127 case UNSPEC_DTPOFF:
128 case UNSPEC_GOTNTPOFF:
129 case UNSPEC_NTPOFF:
130 return 1;
131 default:
132 break;
133 }
134
135 if (GET_CODE (XEXP (op, 0)) == PLUS)
136 {
137 rtx op1 = XEXP (XEXP (op, 0), 0);
138 rtx op2 = XEXP (XEXP (op, 0), 1);
139 HOST_WIDE_INT offset;
140
141 if (ix86_cmodel == CM_LARGE)
142 return 0;
143 if (GET_CODE (op2) != CONST_INT)
144 return 0;
145 offset = trunc_int_for_mode (INTVAL (op2), DImode);
146 switch (GET_CODE (op1))
147 {
148 case SYMBOL_REF:
149 /* For CM_SMALL assume that latest object is 16MB before
150 end of 31bits boundary. We may also accept pretty
151 large negative constants knowing that all objects are
152 in the positive half of address space. */
153 if (ix86_cmodel == CM_SMALL
154 && offset < 16*1024*1024
155 && trunc_int_for_mode (offset, SImode) == offset)
156 return 1;
157 /* For CM_KERNEL we know that all object resist in the
158 negative half of 32bits address space. We may not
159 accept negative offsets, since they may be just off
160 and we may accept pretty large positive ones. */
161 if (ix86_cmodel == CM_KERNEL
162 && offset > 0
163 && trunc_int_for_mode (offset, SImode) == offset)
164 return 1;
165 break;
166
167 case LABEL_REF:
168 /* These conditions are similar to SYMBOL_REF ones, just the
169 constraints for code models differ. */
170 if ((ix86_cmodel == CM_SMALL || ix86_cmodel == CM_MEDIUM)
171 && offset < 16*1024*1024
172 && trunc_int_for_mode (offset, SImode) == offset)
173 return 1;
174 if (ix86_cmodel == CM_KERNEL
175 && offset > 0
176 && trunc_int_for_mode (offset, SImode) == offset)
177 return 1;
178 break;
179
180 case UNSPEC:
181 switch (XINT (op1, 1))
182 {
183 case UNSPEC_DTPOFF:
184 case UNSPEC_NTPOFF:
185 if (offset > 0
186 && trunc_int_for_mode (offset, SImode) == offset)
187 return 1;
188 }
189 break;
190
191 default:
192 break;
193 }
194 }
195 break;
196
197 default:
198 abort ();
199 }
200
201 return 0;
202 })
203
204 ;; Return 1 if VALUE can be stored in the zero extended immediate field.
205 (define_predicate "x86_64_zext_immediate_operand"
206 (match_code "const_double,const_int,symbol_ref,label_ref,const")
207 {
208 switch (GET_CODE (op))
209 {
210 case CONST_DOUBLE:
211 if (HOST_BITS_PER_WIDE_INT == 32)
212 return (GET_MODE (op) == VOIDmode && !CONST_DOUBLE_HIGH (op));
213 else
214 return 0;
215
216 case CONST_INT:
217 if (HOST_BITS_PER_WIDE_INT == 32)
218 return INTVAL (op) >= 0;
219 else
220 return !(INTVAL (op) & ~(HOST_WIDE_INT) 0xffffffff);
221
222 case SYMBOL_REF:
223 /* For certain code models, the symbolic references are known to fit. */
224 /* TLS symbols are not constant. */
225 if (tls_symbolic_operand (op, Pmode))
226 return false;
227 return ix86_cmodel == CM_SMALL;
228
229 case LABEL_REF:
230 /* For certain code models, the code is near as well. */
231 return ix86_cmodel == CM_SMALL || ix86_cmodel == CM_MEDIUM;
232
233 case CONST:
234 /* We also may accept the offsetted memory references in certain
235 special cases. */
236 if (GET_CODE (XEXP (op, 0)) == PLUS)
237 {
238 rtx op1 = XEXP (XEXP (op, 0), 0);
239 rtx op2 = XEXP (XEXP (op, 0), 1);
240
241 if (ix86_cmodel == CM_LARGE)
242 return 0;
243 switch (GET_CODE (op1))
244 {
245 case SYMBOL_REF:
246 /* For small code model we may accept pretty large positive
247 offsets, since one bit is available for free. Negative
248 offsets are limited by the size of NULL pointer area
249 specified by the ABI. */
250 if (ix86_cmodel == CM_SMALL
251 && GET_CODE (op2) == CONST_INT
252 && trunc_int_for_mode (INTVAL (op2), DImode) > -0x10000
253 && trunc_int_for_mode (INTVAL (op2), SImode) == INTVAL (op2))
254 return 1;
255 /* ??? For the kernel, we may accept adjustment of
256 -0x10000000, since we know that it will just convert
257 negative address space to positive, but perhaps this
258 is not worthwhile. */
259 break;
260
261 case LABEL_REF:
262 /* These conditions are similar to SYMBOL_REF ones, just the
263 constraints for code models differ. */
264 if ((ix86_cmodel == CM_SMALL || ix86_cmodel == CM_MEDIUM)
265 && GET_CODE (op2) == CONST_INT
266 && trunc_int_for_mode (INTVAL (op2), DImode) > -0x10000
267 && trunc_int_for_mode (INTVAL (op2), SImode) == INTVAL (op2))
268 return 1;
269 break;
270
271 default:
272 return 0;
273 }
274 }
275 break;
276
277 default:
278 abort ();
279 }
280 return 0;
281 })
282
283 ;; Return nonzero if OP is general operand representable on x86_64.
284 (define_predicate "x86_64_general_operand"
285 (if_then_else (match_test "TARGET_64BIT")
286 (ior (match_operand 0 "nonimmediate_operand")
287 (match_operand 0 "x86_64_immediate_operand"))
288 (match_operand 0 "general_operand")))
289
290 ;; Return nonzero if OP is general operand representable on x86_64
291 ;; as either sign extended or zero extended constant.
292 (define_predicate "x86_64_szext_general_operand"
293 (if_then_else (match_test "TARGET_64BIT")
294 (ior (match_operand 0 "nonimmediate_operand")
295 (ior (match_operand 0 "x86_64_immediate_operand")
296 (match_operand 0 "x86_64_zext_immediate_operand")))
297 (match_operand 0 "general_operand")))
298
299 ;; Return nonzero if OP is nonmemory operand representable on x86_64.
300 (define_predicate "x86_64_nonmemory_operand"
301 (if_then_else (match_test "TARGET_64BIT")
302 (ior (match_operand 0 "register_operand")
303 (match_operand 0 "x86_64_immediate_operand"))
304 (match_operand 0 "nonmemory_operand")))
305
306 ;; Return nonzero if OP is nonmemory operand representable on x86_64.
307 (define_predicate "x86_64_szext_nonmemory_operand"
308 (if_then_else (match_test "TARGET_64BIT")
309 (ior (match_operand 0 "register_operand")
310 (ior (match_operand 0 "x86_64_immediate_operand")
311 (match_operand 0 "x86_64_zext_immediate_operand")))
312 (match_operand 0 "nonmemory_operand")))
313
314 ;; Return nonzero if OP is nonmemory operand acceptable by movabs patterns.
315 (define_predicate "x86_64_movabs_operand"
316 (if_then_else (match_test "!TARGET_64BIT || !flag_pic")
317 (match_operand 0 "nonmemory_operand")
318 (ior (match_operand 0 "register_operand")
319 (and (match_operand 0 "const_double_operand")
320 (match_test "GET_MODE_SIZE (mode) <= 8")))))
321
322 ;; Return nonzero if OP is CONST_INT >= 1 and <= 31 (a valid operand
323 ;; for shift & compare patterns, as shifting by 0 does not change flags).
324 (define_predicate "const_int_1_31_operand"
325 (and (match_code "const_int")
326 (match_test "INTVAL (op) >= 1 && INTVAL (op) <= 31")))
327
328 ;; Returns nonzero if OP is either a symbol reference or a sum of a symbol
329 ;; reference and a constant.
330 (define_predicate "symbolic_operand"
331 (match_code "symbol_ref,label_ref,const")
332 {
333 switch (GET_CODE (op))
334 {
335 case SYMBOL_REF:
336 case LABEL_REF:
337 return 1;
338
339 case CONST:
340 op = XEXP (op, 0);
341 if (GET_CODE (op) == SYMBOL_REF
342 || GET_CODE (op) == LABEL_REF
343 || (GET_CODE (op) == UNSPEC
344 && (XINT (op, 1) == UNSPEC_GOT
345 || XINT (op, 1) == UNSPEC_GOTOFF
346 || XINT (op, 1) == UNSPEC_GOTPCREL)))
347 return 1;
348 if (GET_CODE (op) != PLUS
349 || GET_CODE (XEXP (op, 1)) != CONST_INT)
350 return 0;
351
352 op = XEXP (op, 0);
353 if (GET_CODE (op) == SYMBOL_REF
354 || GET_CODE (op) == LABEL_REF)
355 return 1;
356 /* Only @GOTOFF gets offsets. */
357 if (GET_CODE (op) != UNSPEC
358 || XINT (op, 1) != UNSPEC_GOTOFF)
359 return 0;
360
361 op = XVECEXP (op, 0, 0);
362 if (GET_CODE (op) == SYMBOL_REF
363 || GET_CODE (op) == LABEL_REF)
364 return 1;
365 return 0;
366
367 default:
368 abort ();
369 }
370 })
371
372 ;; Return true if the operand contains a @GOT or @GOTOFF reference.
373 (define_predicate "pic_symbolic_operand"
374 (match_code "const")
375 {
376 op = XEXP (op, 0);
377 if (TARGET_64BIT)
378 {
379 if (GET_CODE (op) == UNSPEC
380 && XINT (op, 1) == UNSPEC_GOTPCREL)
381 return 1;
382 if (GET_CODE (op) == PLUS
383 && GET_CODE (XEXP (op, 0)) == UNSPEC
384 && XINT (XEXP (op, 0), 1) == UNSPEC_GOTPCREL)
385 return 1;
386 }
387 else
388 {
389 if (GET_CODE (op) == UNSPEC)
390 return 1;
391 if (GET_CODE (op) != PLUS
392 || GET_CODE (XEXP (op, 1)) != CONST_INT)
393 return 0;
394 op = XEXP (op, 0);
395 if (GET_CODE (op) == UNSPEC)
396 return 1;
397 }
398 return 0;
399 })
400
401 ;; Return true if OP is a symbolic operand that resolves locally.
402 (define_predicate "local_symbolic_operand"
403 (match_code "const,label_ref,symbol_ref")
404 {
405 if (GET_CODE (op) == CONST
406 && GET_CODE (XEXP (op, 0)) == PLUS
407 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT)
408 op = XEXP (XEXP (op, 0), 0);
409
410 if (GET_CODE (op) == LABEL_REF)
411 return 1;
412
413 if (GET_CODE (op) != SYMBOL_REF)
414 return 0;
415
416 if (SYMBOL_REF_LOCAL_P (op))
417 return 1;
418
419 /* There is, however, a not insubstantial body of code in the rest of
420 the compiler that assumes it can just stick the results of
421 ASM_GENERATE_INTERNAL_LABEL in a symbol_ref and have done. */
422 /* ??? This is a hack. Should update the body of the compiler to
423 always create a DECL an invoke targetm.encode_section_info. */
424 if (strncmp (XSTR (op, 0), internal_label_prefix,
425 internal_label_prefix_len) == 0)
426 return 1;
427
428 return 0;
429 })
430
431 ;; Test for various thread-local symbols.
432 (define_predicate "tls_symbolic_operand"
433 (and (match_code "symbol_ref")
434 (match_test "SYMBOL_REF_TLS_MODEL (op) != 0")))
435
436 (define_predicate "global_dynamic_symbolic_operand"
437 (and (match_code "symbol_ref")
438 (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_GLOBAL_DYNAMIC")))
439
440 (define_predicate "local_dynamic_symbolic_operand"
441 (and (match_code "symbol_ref")
442 (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_DYNAMIC")))
443
444 (define_predicate "initial_exec_symbolic_operand"
445 (and (match_code "symbol_ref")
446 (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_INITIAL_EXEC")))
447
448 (define_predicate "local_exec_symbolic_operand"
449 (and (match_code "symbol_ref")
450 (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_EXEC")))
451
452 ;; Test for a pc-relative call operand
453 (define_predicate "constant_call_address_operand"
454 (ior (match_code "symbol_ref")
455 (match_operand 0 "local_symbolic_operand")))
456
457 ;; True for any non-virtual or eliminable register. Used in places where
458 ;; instantiation of such a register may cause the pattern to not be recognized.
459 (define_predicate "register_no_elim_operand"
460 (match_operand 0 "register_operand")
461 {
462 if (GET_CODE (op) == SUBREG)
463 op = SUBREG_REG (op);
464 return !(op == arg_pointer_rtx
465 || op == frame_pointer_rtx
466 || (REGNO (op) >= FIRST_PSEUDO_REGISTER
467 && REGNO (op) <= LAST_VIRTUAL_REGISTER));
468 })
469
470 ;; Similarly, but include the stack pointer. This is used to prevent esp
471 ;; from being used as an index reg.
472 (define_predicate "index_register_operand"
473 (match_operand 0 "register_operand")
474 {
475 if (GET_CODE (op) == SUBREG)
476 op = SUBREG_REG (op);
477 if (reload_in_progress || reload_completed)
478 return REG_OK_FOR_INDEX_STRICT_P (op);
479 else
480 return REG_OK_FOR_INDEX_NONSTRICT_P (op);
481 })
482
483 ;; Return false if this is any eliminable register. Otherwise general_operand.
484 (define_predicate "general_no_elim_operand"
485 (if_then_else (match_code "reg,subreg")
486 (match_operand 0 "register_no_elim_operand")
487 (match_operand 0 "general_operand")))
488
489 ;; Return false if this is any eliminable register. Otherwise
490 ;; register_operand or a constant.
491 (define_predicate "nonmemory_no_elim_operand"
492 (ior (match_operand 0 "register_no_elim_operand")
493 (match_operand 0 "immediate_operand")))
494
495 ;; Test for a valid operand for a call instruction.
496 (define_predicate "call_insn_operand"
497 (ior (match_operand 0 "constant_call_address_operand")
498 (ior (match_operand 0 "register_no_elim_operand")
499 (match_operand 0 "memory_operand"))))
500
501 ;; Simiarly, but for tail calls, in which we cannot allow memory references.
502 (define_predicate "sibcall_insn_operand"
503 (ior (match_operand 0 "constant_call_address_operand")
504 (match_operand 0 "register_no_elim_operand")))
505
506 ;; Match exactly zero.
507 (define_predicate "const0_operand"
508 (and (match_code "const_int,const_double,const_vector")
509 (match_test "op == CONST0_RTX (mode)")))
510
511 ;; Match exactly one.
512 (define_predicate "const1_operand"
513 (and (match_code "const_int")
514 (match_test "op == const1_rtx")))
515
516 ;; Match 2, 4, or 8. Used for leal multiplicands.
517 (define_predicate "const248_operand"
518 (match_code "const_int")
519 {
520 HOST_WIDE_INT i = INTVAL (op);
521 return i == 2 || i == 4 || i == 8;
522 })
523
524 ;; Match 0 to 3.
525 (define_predicate "const_0_to_3_operand"
526 (and (match_code "const_int")
527 (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 3")))
528
529 ;; Match 0 to 7.
530 (define_predicate "const_0_to_7_operand"
531 (and (match_code "const_int")
532 (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 7")))
533
534 ;; Match 0 to 15.
535 (define_predicate "const_0_to_15_operand"
536 (and (match_code "const_int")
537 (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 15")))
538
539 ;; Match 0 to 63.
540 (define_predicate "const_0_to_63_operand"
541 (and (match_code "const_int")
542 (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 63")))
543
544 ;; Match 0 to 255.
545 (define_predicate "const_0_to_255_operand"
546 (and (match_code "const_int")
547 (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 255")))
548
549 ;; Match exactly one bit in 4-bit mask.
550 (define_predicate "const_pow2_1_to_8_operand"
551 (match_code "const_int")
552 {
553 unsigned int log = exact_log2 (INTVAL (op));
554 return log <= 3;
555 })
556
557 ;; Match exactly one bit in 8-bit mask.
558 (define_predicate "const_pow2_1_to_128_operand"
559 (match_code "const_int")
560 {
561 unsigned int log = exact_log2 (INTVAL (op));
562 return log <= 7;
563 })
564
565 ;; True if this is a constant appropriate for an increment or decrement.
566 (define_predicate "incdec_operand"
567 (match_code "const_int")
568 {
569 /* On Pentium4, the inc and dec operations causes extra dependency on flag
570 registers, since carry flag is not set. */
571 if ((TARGET_PENTIUM4 || TARGET_NOCONA) && !optimize_size)
572 return 0;
573 return op == const1_rtx || op == constm1_rtx;
574 })
575
576 ;; True for registers, or 1 or -1. Used to optimize double-word shifts.
577 (define_predicate "reg_or_pm1_operand"
578 (ior (match_operand 0 "register_operand")
579 (and (match_code "const_int")
580 (match_test "op == const1_rtx || op == constm1_rtx"))))
581
582 ;; True if OP is acceptable as operand of DImode shift expander.
583 (define_predicate "shiftdi_operand"
584 (if_then_else (match_test "TARGET_64BIT")
585 (match_operand 0 "nonimmediate_operand")
586 (match_operand 0 "register_operand")))
587
588 (define_predicate "ashldi_input_operand"
589 (if_then_else (match_test "TARGET_64BIT")
590 (match_operand 0 "nonimmediate_operand")
591 (match_operand 0 "reg_or_pm1_operand")))
592
593 ;; Return true if OP is a vector load from the constant pool with just
594 ;; the first element nonzero.
595 (define_predicate "zero_extended_scalar_load_operand"
596 (match_code "mem")
597 {
598 unsigned n_elts;
599 op = maybe_get_pool_constant (op);
600 if (!op)
601 return 0;
602 if (GET_CODE (op) != CONST_VECTOR)
603 return 0;
604 n_elts =
605 (GET_MODE_SIZE (GET_MODE (op)) /
606 GET_MODE_SIZE (GET_MODE_INNER (GET_MODE (op))));
607 for (n_elts--; n_elts > 0; n_elts--)
608 {
609 rtx elt = CONST_VECTOR_ELT (op, n_elts);
610 if (elt != CONST0_RTX (GET_MODE_INNER (GET_MODE (op))))
611 return 0;
612 }
613 return 1;
614 })
615
616 ;; Return 1 when OP is operand acceptable for standard SSE move.
617 (define_predicate "vector_move_operand"
618 (ior (match_operand 0 "nonimmediate_operand")
619 (match_operand 0 "const0_operand")))
620
621 ;; Return true if op if a valid address, and does not contain
622 ;; a segment override.
623 (define_special_predicate "no_seg_address_operand"
624 (match_operand 0 "address_operand")
625 {
626 struct ix86_address parts;
627 if (! ix86_decompose_address (op, &parts))
628 abort ();
629 return parts.seg == SEG_DEFAULT;
630 })
631
632 ;; Return nonzero if the rtx is known aligned.
633 (define_predicate "aligned_operand"
634 (match_operand 0 "general_operand")
635 {
636 struct ix86_address parts;
637
638 /* Registers and immediate operands are always "aligned". */
639 if (GET_CODE (op) != MEM)
640 return 1;
641
642 /* Don't even try to do any aligned optimizations with volatiles. */
643 if (MEM_VOLATILE_P (op))
644 return 0;
645 op = XEXP (op, 0);
646
647 /* Pushes and pops are only valid on the stack pointer. */
648 if (GET_CODE (op) == PRE_DEC
649 || GET_CODE (op) == POST_INC)
650 return 1;
651
652 /* Decode the address. */
653 if (!ix86_decompose_address (op, &parts))
654 abort ();
655
656 /* Look for some component that isn't known to be aligned. */
657 if (parts.index)
658 {
659 if (REGNO_POINTER_ALIGN (REGNO (parts.index)) * parts.scale < 32)
660 return 0;
661 }
662 if (parts.base)
663 {
664 if (REGNO_POINTER_ALIGN (REGNO (parts.base)) < 32)
665 return 0;
666 }
667 if (parts.disp)
668 {
669 if (GET_CODE (parts.disp) != CONST_INT
670 || (INTVAL (parts.disp) & 3) != 0)
671 return 0;
672 }
673
674 /* Didn't find one -- this must be an aligned address. */
675 return 1;
676 })
677
678 ;; Returns 1 if OP is memory operand with a displacement.
679 (define_predicate "memory_displacement_operand"
680 (match_operand 0 "memory_operand")
681 {
682 struct ix86_address parts;
683 if (!ix86_decompose_address (XEXP (op, 0), &parts))
684 abort ();
685 return parts.disp != NULL_RTX;
686 })
687
688 ;; Returns 1 if OP is memory operand that cannot be represented
689 ;; by the modRM array.
690 (define_predicate "long_memory_operand"
691 (and (match_operand 0 "memory_operand")
692 (match_test "memory_address_length (op) != 0")))
693
694 ;; Return 1 if OP is a comparison operator that can be issued by fcmov.
695 (define_predicate "fcmov_comparison_operator"
696 (match_operand 0 "comparison_operator")
697 {
698 enum machine_mode inmode = GET_MODE (XEXP (op, 0));
699 enum rtx_code code = GET_CODE (op);
700
701 if (inmode == CCFPmode || inmode == CCFPUmode)
702 {
703 enum rtx_code second_code, bypass_code;
704 ix86_fp_comparison_codes (code, &bypass_code, &code, &second_code);
705 if (bypass_code != UNKNOWN || second_code != UNKNOWN)
706 return 0;
707 code = ix86_fp_compare_code_to_integer (code);
708 }
709 /* i387 supports just limited amount of conditional codes. */
710 switch (code)
711 {
712 case LTU: case GTU: case LEU: case GEU:
713 if (inmode == CCmode || inmode == CCFPmode || inmode == CCFPUmode)
714 return 1;
715 return 0;
716 case ORDERED: case UNORDERED:
717 case EQ: case NE:
718 return 1;
719 default:
720 return 0;
721 }
722 })
723
724 ;; Return 1 if OP is a comparison that can be used in the CMPSS/CMPPS insns.
725 ;; The first set are supported directly; the second set can't be done with
726 ;; full IEEE support, i.e. NaNs.
727 ;;
728 ;; ??? It would seem that we have a lot of uses of this predicate that pass
729 ;; it the wrong mode. We got away with this because the old function didn't
730 ;; check the mode at all. Mirror that for now by calling this a special
731 ;; predicate.
732
733 (define_special_predicate "sse_comparison_operator"
734 (ior (match_code "eq,lt,le,unordered,ne,unge,ungt,ordered")
735 (and (match_code "uneq,unlt,unle,ltgt,ge,gt")
736 (match_test "!TARGET_IEEE_FP"))))
737
738 ;; Return 1 if OP is a valid comparison operator in valid mode.
739 (define_predicate "ix86_comparison_operator"
740 (match_operand 0 "comparison_operator")
741 {
742 enum machine_mode inmode = GET_MODE (XEXP (op, 0));
743 enum rtx_code code = GET_CODE (op);
744
745 if (inmode == CCFPmode || inmode == CCFPUmode)
746 {
747 enum rtx_code second_code, bypass_code;
748 ix86_fp_comparison_codes (code, &bypass_code, &code, &second_code);
749 return (bypass_code == UNKNOWN && second_code == UNKNOWN);
750 }
751 switch (code)
752 {
753 case EQ: case NE:
754 return 1;
755 case LT: case GE:
756 if (inmode == CCmode || inmode == CCGCmode
757 || inmode == CCGOCmode || inmode == CCNOmode)
758 return 1;
759 return 0;
760 case LTU: case GTU: case LEU: case ORDERED: case UNORDERED: case GEU:
761 if (inmode == CCmode)
762 return 1;
763 return 0;
764 case GT: case LE:
765 if (inmode == CCmode || inmode == CCGCmode || inmode == CCNOmode)
766 return 1;
767 return 0;
768 default:
769 return 0;
770 }
771 })
772
773 ;; Return 1 if OP is a valid comparison operator testing carry flag to be set.
774 (define_predicate "ix86_carry_flag_operator"
775 (match_code "ltu,lt,unlt,gt,ungt,le,unle,ge,unge,ltgt,uneq")
776 {
777 enum machine_mode inmode = GET_MODE (XEXP (op, 0));
778 enum rtx_code code = GET_CODE (op);
779
780 if (GET_CODE (XEXP (op, 0)) != REG
781 || REGNO (XEXP (op, 0)) != FLAGS_REG
782 || XEXP (op, 1) != const0_rtx)
783 return 0;
784
785 if (inmode == CCFPmode || inmode == CCFPUmode)
786 {
787 enum rtx_code second_code, bypass_code;
788 ix86_fp_comparison_codes (code, &bypass_code, &code, &second_code);
789 if (bypass_code != UNKNOWN || second_code != UNKNOWN)
790 return 0;
791 code = ix86_fp_compare_code_to_integer (code);
792 }
793 else if (inmode != CCmode)
794 return 0;
795
796 return code == LTU;
797 })
798
799 ;; Nearly general operand, but accept any const_double, since we wish
800 ;; to be able to drop them into memory rather than have them get pulled
801 ;; into registers.
802 (define_predicate "cmp_fp_expander_operand"
803 (ior (match_code "const_double")
804 (match_operand 0 "general_operand")))
805
806 ;; Return true if this is a valid binary floating-point operation.
807 (define_predicate "binary_fp_operator"
808 (match_code "plus,minus,mult,div"))
809
810 ;; Return true if this is a multiply operation.
811 (define_predicate "mult_operator"
812 (match_code "mult"))
813
814 ;; Return true if this is a division operation.
815 (define_predicate "div_operator"
816 (match_code "div"))
817
818 ;; Return true if this is a float extend operation.
819 (define_predicate "float_operator"
820 (match_code "float"))
821
822 ;; Return true for ARITHMETIC_P.
823 (define_predicate "arith_or_logical_operator"
824 (match_code "plus,mult,and,ior,xor,smin,smax,umin,umax,compare,minus,div,
825 mod,udiv,umod,ashift,rotate,ashiftrt,lshiftrt,rotatert"))
826
827 ;; Return 1 if OP is a binary operator that can be promoted to wider mode.
828 ;; Modern CPUs have same latency for HImode and SImode multiply,
829 ;; but 386 and 486 do HImode multiply faster. */
830 (define_predicate "promotable_binary_operator"
831 (ior (match_code "plus,and,ior,xor,ashift")
832 (and (match_code "mult")
833 (match_test "ix86_tune > PROCESSOR_I486"))))
834
835 ;; To avoid problems when jump re-emits comparisons like testqi_ext_ccno_0,
836 ;; re-recognize the operand to avoid a copy_to_mode_reg that will fail.
837 ;;
838 ;; ??? It seems likely that this will only work because cmpsi is an
839 ;; expander, and no actual insns use this.
840
841 (define_predicate "cmpsi_operand_1"
842 (match_code "and")
843 {
844 return (GET_MODE (op) == SImode
845 && GET_CODE (XEXP (op, 0)) == ZERO_EXTRACT
846 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
847 && GET_CODE (XEXP (XEXP (op, 0), 2)) == CONST_INT
848 && INTVAL (XEXP (XEXP (op, 0), 1)) == 8
849 && INTVAL (XEXP (XEXP (op, 0), 2)) == 8
850 && GET_CODE (XEXP (op, 1)) == CONST_INT);
851 })
852
853 (define_predicate "cmpsi_operand"
854 (ior (match_operand 0 "nonimmediate_operand")
855 (match_operand 0 "cmpsi_operand_1")))
856
857 (define_predicate "compare_operator"
858 (match_code "compare"))
859
860 (define_predicate "absneg_operator"
861 (match_code "abs,neg"))