Debian Codegraph @

gcc/config/i386/predicates.md

raw
1 ;; Predicate definitions for IA-32 and x86-64.
2 ;; Copyright (C) 2004-2025 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 ;; True if the operand is a GENERAL class register.
31 (define_predicate "general_reg_operand"
32 (and (match_code "reg")
33 (match_test "GENERAL_REGNO_P (REGNO (op))")))
34
35 ;; True if the operand is an INDEX class register.
36 (define_predicate "index_reg_operand"
37 (and (match_code "reg")
38 (match_test "INDEX_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 ;; True if the operand is a general operand with GENERAL class register.
47 (define_predicate "general_gr_operand"
48 (if_then_else (match_code "reg")
49 (match_test "GENERAL_REGNO_P (REGNO (op))")
50 (match_operand 0 "general_operand")))
51
52 ;; True if the operand is an MMX register.
53 (define_predicate "mmx_reg_operand"
54 (and (match_code "reg")
55 (match_test "MMX_REGNO_P (REGNO (op))")))
56
57 ;; Match register operands, but include memory operands for
58 ;; !TARGET_MMX_WITH_SSE.
59 (define_predicate "register_mmxmem_operand"
60 (ior (match_operand 0 "register_operand")
61 (and (not (match_test "TARGET_MMX_WITH_SSE"))
62 (match_operand 0 "memory_operand"))))
63
64 ;; True if the operand is an SSE register.
65 (define_predicate "sse_reg_operand"
66 (and (match_code "reg")
67 (match_test "SSE_REGNO_P (REGNO (op))")))
68
69 ;; Return true if op is a QImode register.
70 (define_predicate "any_QIreg_operand"
71 (and (match_code "reg")
72 (match_test "ANY_QI_REGNO_P (REGNO (op))")))
73
74 ;; Return true if op is one of QImode registers: %[abcd][hl].
75 (define_predicate "QIreg_operand"
76 (and (match_code "reg")
77 (match_test "QI_REGNO_P (REGNO (op))")))
78
79 ;; Return true if op is a QImode register operand other than %[abcd][hl].
80 (define_predicate "ext_QIreg_operand"
81 (and (match_test "TARGET_64BIT")
82 (match_code "reg")
83 (not (match_test "QI_REGNO_P (REGNO (op))"))))
84
85 ;; Return true if op is the AX register.
86 (define_predicate "ax_reg_operand"
87 (and (match_code "reg")
88 (match_test "REGNO (op) == AX_REG")))
89
90 ;; Return true if op is the flags register.
91 (define_special_predicate "flags_reg_operand"
92 (and (match_code "reg")
93 (match_test "REGNO (op) == FLAGS_REG")))
94
95 ;; True if the operand is a MASK register.
96 (define_predicate "mask_reg_operand"
97 (and (match_code "reg")
98 (match_test "MASK_REGNO_P (REGNO (op))")))
99
100 ;; Match a DI, SI or HImode register operand.
101 (define_special_predicate "int248_register_operand"
102 (and (match_operand 0 "register_operand")
103 (ior (and (match_test "TARGET_64BIT")
104 (match_test "GET_MODE (op) == DImode"))
105 (match_test "GET_MODE (op) == SImode")
106 (match_test "GET_MODE (op) == HImode"))))
107
108 ;; Match a DI, SI, HI or QImode nonimmediate_operand.
109 (define_special_predicate "int_nonimmediate_operand"
110 (and (match_operand 0 "nonimmediate_operand")
111 (ior (and (match_test "TARGET_64BIT")
112 (match_test "GET_MODE (op) == DImode"))
113 (match_test "GET_MODE (op) == SImode")
114 (match_test "GET_MODE (op) == HImode")
115 (match_test "GET_MODE (op) == QImode"))))
116
117 ;; Match register operands, but include memory operands for TARGET_SSE_MATH.
118 (define_predicate "register_ssemem_operand"
119 (if_then_else
120 (match_test "SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH")
121 (match_operand 0 "nonimmediate_operand")
122 (match_operand 0 "register_operand")))
123
124 ;; Match nonimmediate operands, but exclude memory operands
125 ;; for TARGET_SSE_MATH if TARGET_MIX_SSE_I387 is not enabled.
126 (define_predicate "nonimm_ssenomem_operand"
127 (if_then_else
128 (and (match_test "SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH")
129 (not (match_test "TARGET_MIX_SSE_I387")))
130 (match_operand 0 "register_operand")
131 (match_operand 0 "nonimmediate_operand")))
132
133 ;; The above predicate, suitable for x87 arithmetic operators.
134 (define_predicate "x87nonimm_ssenomem_operand"
135 (if_then_else
136 (and (match_test "SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH")
137 (not (match_test "TARGET_MIX_SSE_I387 && X87_ENABLE_ARITH (mode)")))
138 (match_operand 0 "register_operand")
139 (match_operand 0 "nonimmediate_operand")))
140
141 ;; Match register operands, include memory operand for TARGET_SSE4_1.
142 (define_predicate "register_sse4nonimm_operand"
143 (if_then_else (match_test "TARGET_SSE4_1")
144 (match_operand 0 "nonimmediate_operand")
145 (match_operand 0 "register_operand")))
146
147 ;; Return true if VALUE is symbol reference
148 (define_predicate "symbol_operand"
149 (match_code "symbol_ref"))
150
151 ;; Return true if VALUE is an ENDBR opcode in immediate field.
152 (define_predicate "ix86_endbr_immediate_operand"
153 (match_code "const_int")
154 {
155 if (flag_cf_protection & CF_BRANCH)
156 {
157 unsigned HOST_WIDE_INT imm = UINTVAL (op);
158 unsigned HOST_WIDE_INT val = TARGET_64BIT ? 0xfa1e0ff3 : 0xfb1e0ff3;
159
160 if (imm == val)
161 return true;
162
163 /* NB: Encoding is byte based. */
164 if (TARGET_64BIT)
165 for (; imm >= val; imm >>= 8)
166 if (imm == val)
167 return true;
168 }
169
170 return false;
171 })
172
173 ;; Return true if VALUE can be stored in a sign extended immediate field.
174 (define_predicate "x86_64_immediate_operand"
175 (match_code "const_int,symbol_ref,label_ref,const")
176 {
177 if (ix86_endbr_immediate_operand (op, VOIDmode))
178 return false;
179
180 if (!TARGET_64BIT)
181 return immediate_operand (op, mode);
182
183 switch (GET_CODE (op))
184 {
185 case CONST_INT:
186 {
187 HOST_WIDE_INT val = INTVAL (op);
188 return trunc_int_for_mode (val, SImode) == val;
189 }
190 case SYMBOL_REF:
191 /* TLS symbols are not constant. */
192 if (SYMBOL_REF_TLS_MODEL (op))
193 return false;
194
195 /* Load the external function address via the GOT slot. */
196 if (ix86_force_load_from_GOT_p (op))
197 return false;
198
199 /* For certain code models, the symbolic references are known to fit.
200 in CM_SMALL_PIC model we know it fits if it is local to the shared
201 library. Don't count TLS SYMBOL_REFs here, since they should fit
202 only if inside of UNSPEC handled below. */
203 return (ix86_cmodel == CM_SMALL || ix86_cmodel == CM_KERNEL
204 || (ix86_cmodel == CM_MEDIUM && !SYMBOL_REF_FAR_ADDR_P (op)));
205
206 case LABEL_REF:
207 /* For certain code models, the code is near as well. */
208 return (ix86_cmodel == CM_SMALL || ix86_cmodel == CM_MEDIUM
209 || ix86_cmodel == CM_KERNEL);
210
211 case CONST:
212 /* We also may accept the offsetted memory references in certain
213 special cases. */
214 if (GET_CODE (XEXP (op, 0)) == UNSPEC)
215 switch (XINT (XEXP (op, 0), 1))
216 {
217 case UNSPEC_GOTPCREL:
218 case UNSPEC_DTPOFF:
219 case UNSPEC_GOTNTPOFF:
220 case UNSPEC_NTPOFF:
221 return true;
222 default:
223 break;
224 }
225
226 if (GET_CODE (XEXP (op, 0)) == PLUS)
227 {
228 rtx op1 = XEXP (XEXP (op, 0), 0);
229 rtx op2 = XEXP (XEXP (op, 0), 1);
230
231 if (ix86_cmodel == CM_LARGE && GET_CODE (op1) != UNSPEC)
232 return false;
233 if (!CONST_INT_P (op2))
234 return false;
235
236 HOST_WIDE_INT offset = INTVAL (op2);
237 if (trunc_int_for_mode (offset, SImode) != offset)
238 return false;
239
240 switch (GET_CODE (op1))
241 {
242 case SYMBOL_REF:
243 /* TLS symbols are not constant. */
244 if (SYMBOL_REF_TLS_MODEL (op1))
245 return false;
246
247 /* Load the external function address via the GOT slot. */
248 if (ix86_force_load_from_GOT_p (op1))
249 return false;
250
251 /* For CM_SMALL assume that latest object is 16MB before
252 end of 31bits boundary. We may also accept pretty
253 large negative constants knowing that all objects are
254 in the positive half of address space. */
255 if ((ix86_cmodel == CM_SMALL
256 || (ix86_cmodel == CM_MEDIUM
257 && !SYMBOL_REF_FAR_ADDR_P (op1)))
258 && offset < 16*1024*1024)
259 return true;
260 /* For CM_KERNEL we know that all object resist in the
261 negative half of 32bits address space. We may not
262 accept negative offsets, since they may be just off
263 and we may accept pretty large positive ones. */
264 if (ix86_cmodel == CM_KERNEL
265 && offset > 0)
266 return true;
267 break;
268
269 case LABEL_REF:
270 /* These conditions are similar to SYMBOL_REF ones, just the
271 constraints for code models differ. */
272 if ((ix86_cmodel == CM_SMALL || ix86_cmodel == CM_MEDIUM)
273 && offset < 16*1024*1024)
274 return true;
275 if (ix86_cmodel == CM_KERNEL
276 && offset > 0)
277 return true;
278 break;
279
280 case UNSPEC:
281 switch (XINT (op1, 1))
282 {
283 case UNSPEC_DTPOFF:
284 case UNSPEC_NTPOFF:
285 return true;
286 }
287 break;
288
289 default:
290 break;
291 }
292 }
293 break;
294
295 default:
296 gcc_unreachable ();
297 }
298
299 return false;
300 })
301
302 ;; Return true if VALUE can be stored in the zero extended immediate field.
303 (define_predicate "x86_64_zext_immediate_operand"
304 (match_code "const_int,symbol_ref,label_ref,const")
305 {
306 if (ix86_endbr_immediate_operand (op, VOIDmode))
307 return false;
308
309 switch (GET_CODE (op))
310 {
311 case CONST_INT:
312 return !(INTVAL (op) & ~HOST_WIDE_INT_C (0xffffffff));
313
314 case SYMBOL_REF:
315 /* TLS symbols are not constant. */
316 if (SYMBOL_REF_TLS_MODEL (op))
317 return false;
318
319 /* Load the external function address via the GOT slot. */
320 if (ix86_force_load_from_GOT_p (op))
321 return false;
322
323 /* For certain code models, the symbolic references are known to fit. */
324 return (ix86_cmodel == CM_SMALL
325 || (ix86_cmodel == CM_MEDIUM
326 && !SYMBOL_REF_FAR_ADDR_P (op)));
327
328 case LABEL_REF:
329 /* For certain code models, the code is near as well. */
330 return ix86_cmodel == CM_SMALL || ix86_cmodel == CM_MEDIUM;
331
332 case CONST:
333 /* We also may accept the offsetted memory references in certain
334 special cases. */
335 if (GET_CODE (XEXP (op, 0)) == PLUS)
336 {
337 rtx op1 = XEXP (XEXP (op, 0), 0);
338 rtx op2 = XEXP (XEXP (op, 0), 1);
339
340 if (ix86_cmodel == CM_LARGE)
341 return false;
342 if (!CONST_INT_P (op2))
343 return false;
344
345 HOST_WIDE_INT offset = INTVAL (op2);
346 if (trunc_int_for_mode (offset, SImode) != offset)
347 return false;
348
349 switch (GET_CODE (op1))
350 {
351 case SYMBOL_REF:
352 /* TLS symbols are not constant. */
353 if (SYMBOL_REF_TLS_MODEL (op1))
354 return false;
355
356 /* Load the external function address via the GOT slot. */
357 if (ix86_force_load_from_GOT_p (op1))
358 return false;
359
360 /* For small code model we may accept pretty large positive
361 offsets, since one bit is available for free. Negative
362 offsets are limited by the size of NULL pointer area
363 specified by the ABI. */
364 if ((ix86_cmodel == CM_SMALL
365 || (ix86_cmodel == CM_MEDIUM
366 && !SYMBOL_REF_FAR_ADDR_P (op1)))
367 && offset > -0x10000)
368 return true;
369 /* ??? For the kernel, we may accept adjustment of
370 -0x10000000, since we know that it will just convert
371 negative address space to positive, but perhaps this
372 is not worthwhile. */
373 break;
374
375 case LABEL_REF:
376 /* These conditions are similar to SYMBOL_REF ones, just the
377 constraints for code models differ. */
378 if ((ix86_cmodel == CM_SMALL || ix86_cmodel == CM_MEDIUM)
379 && offset > -0x10000)
380 return true;
381 break;
382
383 default:
384 return false;
385 }
386 }
387 break;
388
389 default:
390 gcc_unreachable ();
391 }
392 return false;
393 })
394
395 ;; Return true if VALUE is a constant integer whose low and high words satisfy
396 ;; x86_64_immediate_operand.
397 (define_predicate "x86_64_hilo_int_operand"
398 (match_code "const_int,const_wide_int")
399 {
400 switch (GET_CODE (op))
401 {
402 case CONST_INT:
403 return x86_64_immediate_operand (op, mode);
404
405 case CONST_WIDE_INT:
406 gcc_assert (CONST_WIDE_INT_NUNITS (op) == 2);
407 return (x86_64_immediate_operand (GEN_INT (CONST_WIDE_INT_ELT (op, 0)),
408 DImode)
409 && x86_64_immediate_operand (GEN_INT (CONST_WIDE_INT_ELT (op,
410 1)),
411 DImode));
412
413 default:
414 gcc_unreachable ();
415 }
416 })
417
418 ;; Return true if VALUE is a constant integer whose value is
419 ;; x86_64_immediate_operand value zero extended from word mode to mode.
420 (define_predicate "x86_64_dwzext_immediate_operand"
421 (match_code "const_int,const_wide_int")
422 {
423 if (ix86_endbr_immediate_operand (op, VOIDmode))
424 return false;
425
426 switch (GET_CODE (op))
427 {
428 case CONST_INT:
429 if (!TARGET_64BIT)
430 return UINTVAL (op) <= HOST_WIDE_INT_UC (0xffffffff);
431 return UINTVAL (op) <= HOST_WIDE_INT_UC (0x7fffffff);
432
433 case CONST_WIDE_INT:
434 if (!TARGET_64BIT)
435 return false;
436 return (CONST_WIDE_INT_NUNITS (op) == 2
437 && CONST_WIDE_INT_ELT (op, 1) == 0
438 && (trunc_int_for_mode (CONST_WIDE_INT_ELT (op, 0), SImode)
439 == (HOST_WIDE_INT) CONST_WIDE_INT_ELT (op, 0)));
440
441 default:
442 gcc_unreachable ();
443 }
444 })
445
446 ;; Return true if size of VALUE can be stored in a sign
447 ;; extended immediate field.
448 (define_predicate "x86_64_immediate_size_operand"
449 (and (match_code "symbol_ref")
450 (ior (not (match_test "TARGET_64BIT"))
451 (match_test "ix86_cmodel == CM_SMALL")
452 (match_test "ix86_cmodel == CM_KERNEL"))))
453
454 ;; Return true if OP is general operand representable on x86_64.
455 (define_predicate "x86_64_general_operand"
456 (if_then_else (match_test "TARGET_64BIT")
457 (ior (match_operand 0 "nonimmediate_operand")
458 (match_operand 0 "x86_64_immediate_operand"))
459 (match_operand 0 "general_operand")))
460
461 ;; Return true if OP's both words are general operands representable
462 ;; on x86_64.
463 (define_predicate "x86_64_hilo_general_operand"
464 (if_then_else (match_test "TARGET_64BIT")
465 (ior (match_operand 0 "nonimmediate_operand")
466 (match_operand 0 "x86_64_hilo_int_operand"))
467 (match_operand 0 "general_operand")))
468
469 ;; Return true if OP is non-VOIDmode general operand representable
470 ;; on x86_64. This predicate is used in sign-extending conversion
471 ;; operations that require non-VOIDmode immediate operands.
472 (define_predicate "x86_64_sext_operand"
473 (and (match_test "GET_MODE (op) != VOIDmode")
474 (match_operand 0 "x86_64_general_operand")))
475
476 ;; Return true if OP is non-VOIDmode general operand. This predicate
477 ;; is used in sign-extending conversion operations that require
478 ;; non-VOIDmode immediate operands.
479 (define_predicate "sext_operand"
480 (and (match_test "GET_MODE (op) != VOIDmode")
481 (match_operand 0 "general_operand")))
482
483 ;; Return true if OP is representable on x86_64 as zero-extended operand.
484 ;; This predicate is used in zero-extending conversion operations that
485 ;; require non-VOIDmode immediate operands.
486 (define_predicate "x86_64_zext_operand"
487 (if_then_else (match_test "TARGET_64BIT")
488 (ior (match_operand 0 "nonimmediate_operand")
489 (and (match_operand 0 "x86_64_zext_immediate_operand")
490 (match_test "GET_MODE (op) != VOIDmode")))
491 (match_operand 0 "nonimmediate_operand")))
492
493 ;; Return true if OP is general operand representable on x86_64
494 ;; as either sign extended or zero extended constant.
495 (define_predicate "x86_64_szext_general_operand"
496 (if_then_else (match_test "TARGET_64BIT")
497 (ior (match_operand 0 "nonimmediate_operand")
498 (match_operand 0 "x86_64_immediate_operand")
499 (match_operand 0 "x86_64_zext_immediate_operand"))
500 (match_operand 0 "general_operand")))
501
502 ;; Return true if OP is nonmemory operand representable on x86_64.
503 (define_predicate "x86_64_nonmemory_operand"
504 (if_then_else (match_test "TARGET_64BIT")
505 (ior (match_operand 0 "register_operand")
506 (match_operand 0 "x86_64_immediate_operand"))
507 (match_operand 0 "nonmemory_operand")))
508
509 ;; Return true if OP is nonmemory operand representable on x86_64.
510 (define_predicate "x86_64_szext_nonmemory_operand"
511 (if_then_else (match_test "TARGET_64BIT")
512 (ior (match_operand 0 "register_operand")
513 (match_operand 0 "x86_64_immediate_operand")
514 (match_operand 0 "x86_64_zext_immediate_operand"))
515 (match_operand 0 "nonmemory_operand")))
516
517 ;; Return true when operand is PIC expression that can be computed by lea
518 ;; operation.
519 (define_predicate "pic_32bit_operand"
520 (match_code "const,symbol_ref,label_ref")
521 {
522 if (!flag_pic)
523 return false;
524
525 /* Rule out relocations that translate into 64bit constants. */
526 if (TARGET_64BIT && GET_CODE (op) == CONST)
527 {
528 op = XEXP (op, 0);
529 if (GET_CODE (op) == PLUS && CONST_INT_P (XEXP (op, 1)))
530 op = XEXP (op, 0);
531 if (GET_CODE (op) == UNSPEC
532 && (XINT (op, 1) == UNSPEC_GOTOFF
533 || XINT (op, 1) == UNSPEC_GOT))
534 return false;
535 }
536
537 return symbolic_operand (op, mode);
538 })
539
540 ;; Return true if OP is nonmemory operand acceptable by movabs patterns.
541 (define_predicate "x86_64_movabs_operand"
542 (and (match_operand 0 "nonmemory_operand")
543 (not (match_operand 0 "pic_32bit_operand"))))
544
545 ;; Return true if OP is either a symbol reference or a sum of a symbol
546 ;; reference and a constant.
547 (define_predicate "symbolic_operand"
548 (match_code "symbol_ref,label_ref,const")
549 {
550 switch (GET_CODE (op))
551 {
552 case SYMBOL_REF:
553 case LABEL_REF:
554 return true;
555
556 case CONST:
557 op = XEXP (op, 0);
558 if (GET_CODE (op) == SYMBOL_REF
559 || GET_CODE (op) == LABEL_REF
560 || (GET_CODE (op) == UNSPEC
561 && (XINT (op, 1) == UNSPEC_GOT
562 || XINT (op, 1) == UNSPEC_GOTOFF
563 || XINT (op, 1) == UNSPEC_PCREL
564 || XINT (op, 1) == UNSPEC_GOTPCREL)))
565 return true;
566 if (GET_CODE (op) != PLUS
567 || !CONST_INT_P (XEXP (op, 1)))
568 return false;
569
570 op = XEXP (op, 0);
571 if (GET_CODE (op) == SYMBOL_REF
572 || GET_CODE (op) == LABEL_REF)
573 return true;
574 /* Only @GOTOFF gets offsets. */
575 if (GET_CODE (op) != UNSPEC
576 || XINT (op, 1) != UNSPEC_GOTOFF)
577 return false;
578
579 op = XVECEXP (op, 0, 0);
580 if (GET_CODE (op) == SYMBOL_REF
581 || GET_CODE (op) == LABEL_REF)
582 return true;
583 return false;
584
585 default:
586 gcc_unreachable ();
587 }
588 })
589
590 ;; Return true if OP is a symbolic operand that resolves locally.
591 (define_predicate "local_symbolic_operand"
592 (match_code "const,label_ref,symbol_ref")
593 {
594 if (GET_CODE (op) == CONST
595 && GET_CODE (XEXP (op, 0)) == PLUS
596 && CONST_INT_P (XEXP (XEXP (op, 0), 1)))
597 op = XEXP (XEXP (op, 0), 0);
598
599 if (GET_CODE (op) == LABEL_REF)
600 return true;
601
602 if (GET_CODE (op) != SYMBOL_REF)
603 return false;
604
605 if (SYMBOL_REF_TLS_MODEL (op))
606 return false;
607
608 /* Dll-imported symbols are always external. */
609 if (TARGET_DLLIMPORT_DECL_ATTRIBUTES && SYMBOL_REF_DLLIMPORT_P (op))
610 return false;
611 if (SYMBOL_REF_LOCAL_P (op))
612 return true;
613
614 /* There is, however, a not insubstantial body of code in the rest of
615 the compiler that assumes it can just stick the results of
616 ASM_GENERATE_INTERNAL_LABEL in a symbol_ref and have done. */
617 /* ??? This is a hack. Should update the body of the compiler to
618 always create a DECL an invoke targetm.encode_section_info. */
619 if (strncmp (XSTR (op, 0), internal_label_prefix,
620 internal_label_prefix_len) == 0)
621 return true;
622
623 return false;
624 })
625
626 (define_predicate "local_func_symbolic_operand"
627 (match_operand 0 "local_symbolic_operand")
628 {
629 if (GET_CODE (op) == CONST
630 && GET_CODE (XEXP (op, 0)) == PLUS
631 && CONST_INT_P (XEXP (XEXP (op, 0), 1)))
632 op = XEXP (XEXP (op, 0), 0);
633
634 if (GET_CODE (op) == SYMBOL_REF
635 && !SYMBOL_REF_FUNCTION_P (op))
636 return false;
637
638 return true;
639 })
640
641 ;; Test for a legitimate @GOTOFF operand.
642 ;;
643 ;; VxWorks does not impose a fixed gap between segments; the run-time
644 ;; gap can be different from the object-file gap. We therefore can't
645 ;; use @GOTOFF unless we are absolutely sure that the symbol is in the
646 ;; same segment as the GOT. Unfortunately, the flexibility of linker
647 ;; scripts means that we can't be sure of that in general, so assume
648 ;; @GOTOFF is not valid on VxWorks, except with the large code model.
649 (define_predicate "gotoff_operand"
650 (and (ior (not (match_test "TARGET_VXWORKS_RTP"))
651 (match_test "ix86_cmodel == CM_LARGE")
652 (match_test "ix86_cmodel == CM_LARGE_PIC"))
653 (match_operand 0 "local_symbolic_operand")))
654
655 ;; Test for various thread-local symbols.
656 (define_special_predicate "tls_symbolic_operand"
657 (and (match_code "symbol_ref")
658 (match_test "SYMBOL_REF_TLS_MODEL (op)")))
659
660 (define_special_predicate "tls_modbase_operand"
661 (and (match_code "symbol_ref")
662 (match_test "op == ix86_tls_module_base ()")))
663
664 (define_predicate "tls_address_pattern"
665 (and (match_code "set,parallel,unspec,unspec_volatile")
666 (match_test "ix86_tls_address_pattern_p (op)")))
667
668 ;; Test for a pc-relative call operand
669 (define_predicate "constant_call_address_operand"
670 (match_code "symbol_ref")
671 {
672 if (ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC
673 || flag_force_indirect_call
674 || (TARGET_INDIRECT_BRANCH_REGISTER
675 && ix86_nopic_noplt_attribute_p (op)))
676 return false;
677 if (TARGET_DLLIMPORT_DECL_ATTRIBUTES && SYMBOL_REF_DLLIMPORT_P (op))
678 return false;
679 return true;
680 })
681
682 ;; True for any non-virtual and non-eliminable register. Used in places where
683 ;; instantiation of such a register may cause the pattern to not be recognized.
684 (define_predicate "register_no_elim_operand"
685 (match_operand 0 "register_operand")
686 {
687 if (SUBREG_P (op))
688 op = SUBREG_REG (op);
689
690 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
691 because it is guaranteed to be reloaded into one. */
692 if (MEM_P (op))
693 return true;
694
695 return !(op == arg_pointer_rtx
696 || op == frame_pointer_rtx
697 || VIRTUAL_REGISTER_P (op));
698 })
699
700 ;; Similarly, but include the stack pointer. This is used
701 ;; to prevent esp from being used as an index reg.
702 (define_predicate "register_no_SP_operand"
703 (match_operand 0 "register_operand")
704 {
705 if (SUBREG_P (op))
706 op = SUBREG_REG (op);
707
708 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
709 because it is guaranteed to be reloaded into one. */
710 if (MEM_P (op))
711 return true;
712
713 return !(op == arg_pointer_rtx
714 || op == frame_pointer_rtx
715 || op == stack_pointer_rtx
716 || VIRTUAL_REGISTER_P (op));
717 })
718
719 ;; P6 processors will jump to the address after the decrement when %esp
720 ;; is used as a call operand, so they will execute return address as a code.
721 ;; See Pentium Pro errata 70, Pentium 2 errata A33 and Pentium 3 errata E17.
722
723 (define_predicate "call_register_operand"
724 (if_then_else (match_test "TARGET_64BIT")
725 (match_operand 0 "register_operand")
726 (match_operand 0 "register_no_SP_operand")))
727
728 ;; Return false if this is any eliminable register. Otherwise general_operand.
729 (define_predicate "general_no_elim_operand"
730 (if_then_else (match_code "reg,subreg")
731 (match_operand 0 "register_no_elim_operand")
732 (match_operand 0 "general_operand")))
733
734 ;; Return false if this is any eliminable register. Otherwise
735 ;; register_operand or a constant.
736 (define_predicate "nonmemory_no_elim_operand"
737 (ior (match_operand 0 "register_no_elim_operand")
738 (match_operand 0 "immediate_operand")))
739
740 ;; Test for a valid operand for indirect branch.
741 (define_predicate "indirect_branch_operand"
742 (ior (match_operand 0 "register_operand")
743 (and (not (match_test "TARGET_INDIRECT_BRANCH_REGISTER"))
744 (not (match_test "TARGET_X32"))
745 (match_operand 0 "memory_operand"))))
746
747 ;; Return true if OP is a memory operands that can be used in sibcalls.
748 ;; Since sibcall never returns, we can only use call-clobbered register
749 ;; as GOT base. Allow GOT slot here only with pseudo register as GOT
750 ;; base. Properly handle sibcall over GOT slot with *sibcall_GOT_32
751 ;; and *sibcall_value_GOT_32 patterns.
752 (define_predicate "sibcall_memory_operand"
753 (match_operand 0 "memory_operand")
754 {
755 op = XEXP (op, 0);
756 if (CONSTANT_P (op))
757 return true;
758 if (GET_CODE (op) == PLUS && REG_P (XEXP (op, 0)))
759 {
760 int regno = REGNO (XEXP (op, 0));
761 if (!HARD_REGISTER_NUM_P (regno) || call_used_or_fixed_reg_p (regno))
762 {
763 op = XEXP (op, 1);
764 if (GOT32_symbol_operand (op, VOIDmode))
765 return true;
766 }
767 }
768 return false;
769 })
770
771 ;; Return true if OP is a GOT memory operand.
772 (define_predicate "GOT_memory_operand"
773 (and (match_operand 0 "memory_operand")
774 (match_code "const" "0")
775 (match_code "unspec" "00")
776 (match_test "XINT (XEXP (XEXP (op, 0), 0), 1) == UNSPEC_GOTPCREL")))
777
778 ;; Test for a valid operand for a call instruction.
779 ;; Allow constant call address operands in Pmode only.
780 (define_special_predicate "call_insn_operand"
781 (ior (match_test "constant_call_address_operand
782 (op, mode == VOIDmode ? mode : Pmode)")
783 (match_operand 0 "call_register_operand")
784 (match_test "satisfies_constraint_Bw (op)")))
785
786 ;; Similarly, but for tail calls, in which we cannot allow memory references.
787 (define_special_predicate "sibcall_insn_operand"
788 (ior (match_test "constant_call_address_operand
789 (op, mode == VOIDmode ? mode : Pmode)")
790 (match_operand 0 "register_no_elim_operand")
791 (match_test "satisfies_constraint_Bs (op)")))
792
793 ;; Return true if OP is a 32-bit GOT symbol operand.
794 (define_predicate "GOT32_symbol_operand"
795 (and (match_code "const")
796 (match_code "unspec" "0")
797 (match_test "XINT (XEXP (op, 0), 1) == UNSPEC_GOT")))
798
799 ;; Match exactly zero.
800 (define_predicate "const0_operand"
801 (match_code "const_int,const_double,const_vector")
802 {
803 if (mode == VOIDmode)
804 mode = GET_MODE (op);
805 return op == CONST0_RTX (mode);
806 })
807
808 ;; Match one or a vector with all elements equal to one.
809 (define_predicate "const1_operand"
810 (match_code "const_int,const_double,const_vector")
811 {
812 if (mode == VOIDmode)
813 mode = GET_MODE (op);
814 return op == CONST1_RTX (mode);
815 })
816
817 ;; Match exactly -1.
818 (define_predicate "constm1_operand"
819 (and (match_code "const_int")
820 (match_test "op == constm1_rtx")))
821
822 ;; Match 0 or -1.
823 (define_predicate "const0_or_m1_operand"
824 (ior (match_operand 0 "const0_operand")
825 (match_operand 0 "constm1_operand")))
826
827 ;; Match exactly eight.
828 (define_predicate "const8_operand"
829 (and (match_code "const_int")
830 (match_test "INTVAL (op) == 8")))
831
832 ;; Match exactly 128.
833 (define_predicate "const128_operand"
834 (and (match_code "const_int")
835 (match_test "INTVAL (op) == 128")))
836
837 ;; Match exactly 0x0FFFFFFFF in anddi as a zero-extension operation
838 (define_predicate "const_32bit_mask"
839 (and (match_code "const_int")
840 (match_test "trunc_int_for_mode (INTVAL (op), DImode)
841 == HOST_WIDE_INT_C (0xffffffff)")))
842
843 ;; Match 2, 4, or 8. Used for leal multiplicands.
844 (define_predicate "const248_operand"
845 (match_code "const_int")
846 {
847 HOST_WIDE_INT i = INTVAL (op);
848 return i == 2 || i == 4 || i == 8;
849 })
850
851 ;; Match 1, 2, or 3. Used for lea shift amounts.
852 (define_predicate "const123_operand"
853 (match_code "const_int")
854 {
855 HOST_WIDE_INT i = INTVAL (op);
856 return i == 1 || i == 2 || i == 3;
857 })
858
859 ;; Match 2, 3, 6, or 7
860 (define_predicate "const2367_operand"
861 (match_code "const_int")
862 {
863 HOST_WIDE_INT i = INTVAL (op);
864 return i == 2 || i == 3 || i == 6 || i == 7;
865 })
866
867 ;; Match 1, 2, 4, or 8
868 (define_predicate "const1248_operand"
869 (match_code "const_int")
870 {
871 HOST_WIDE_INT i = INTVAL (op);
872 return i == 1 || i == 2 || i == 4 || i == 8;
873 })
874
875 ;; Match 3, 5, or 9. Used for leal multiplicands.
876 (define_predicate "const359_operand"
877 (match_code "const_int")
878 {
879 HOST_WIDE_INT i = INTVAL (op);
880 return i == 3 || i == 5 || i == 9;
881 })
882
883 ;; Match 4 or 8 to 11. Used for embeded rounding.
884 (define_predicate "const_4_or_8_to_11_operand"
885 (match_code "const_int")
886 {
887 HOST_WIDE_INT i = INTVAL (op);
888 return i == 4 || (i >= 8 && i <= 11);
889 })
890
891 ;; Match 4 or 8. Used for SAE.
892 (define_predicate "const48_operand"
893 (match_code "const_int")
894 {
895 HOST_WIDE_INT i = INTVAL (op);
896 return i == 4 || i == 8;
897 })
898
899 ;; Match 0 or 1.
900 (define_predicate "const_0_to_1_operand"
901 (and (match_code "const_int")
902 (ior (match_test "op == const0_rtx")
903 (match_test "op == const1_rtx"))))
904
905 ;; Match 0 to 3.
906 (define_predicate "const_0_to_3_operand"
907 (and (match_code "const_int")
908 (match_test "IN_RANGE (INTVAL (op), 0, 3)")))
909
910 ;; Match 0 to 4.
911 (define_predicate "const_0_to_4_operand"
912 (and (match_code "const_int")
913 (match_test "IN_RANGE (INTVAL (op), 0, 4)")))
914
915 ;; Match 0 to 5.
916 (define_predicate "const_0_to_5_operand"
917 (and (match_code "const_int")
918 (match_test "IN_RANGE (INTVAL (op), 0, 5)")))
919
920 ;; Match 0 to 7.
921 (define_predicate "const_0_to_7_operand"
922 (and (match_code "const_int")
923 (match_test "IN_RANGE (INTVAL (op), 0, 7)")))
924
925 ;; Match 0 to 15.
926 (define_predicate "const_0_to_15_operand"
927 (and (match_code "const_int")
928 (match_test "IN_RANGE (INTVAL (op), 0, 15)")))
929
930 ;; Match 0 to 31.
931 (define_predicate "const_0_to_31_operand"
932 (and (match_code "const_int")
933 (match_test "IN_RANGE (INTVAL (op), 0, 31)")))
934
935 ;; Match 0 to 63.
936 (define_predicate "const_0_to_63_operand"
937 (and (match_code "const_int")
938 (match_test "IN_RANGE (INTVAL (op), 0, 63)")))
939
940 ;; Match 0 to 127.
941 (define_predicate "const_0_to_127_operand"
942 (and (match_code "const_int")
943 (match_test "IN_RANGE (INTVAL (op), 0, 127)")))
944
945 ;; Match 0 to 255.
946 (define_predicate "const_0_to_255_operand"
947 (and (match_code "const_int")
948 (match_test "IN_RANGE (INTVAL (op), 0, 255)")))
949
950 ;; Match (0 to 255) * 8
951 (define_predicate "const_0_to_255_mul_8_operand"
952 (match_code "const_int")
953 {
954 unsigned HOST_WIDE_INT val = INTVAL (op);
955 return val <= 255*8 && val % 8 == 0;
956 })
957
958 ;; Match 1 to 255 except multiples of 8
959 (define_predicate "const_0_to_255_not_mul_8_operand"
960 (match_code "const_int")
961 {
962 unsigned HOST_WIDE_INT val = INTVAL (op);
963 return val <= 255 && val % 8 != 0;
964 })
965
966 ;; Return true if OP is CONST_INT >= 1 and <= 31 (a valid operand
967 ;; for shift & compare patterns, as shifting by 0 does not change flags).
968 (define_predicate "const_1_to_31_operand"
969 (and (match_code "const_int")
970 (match_test "IN_RANGE (INTVAL (op), 1, 31)")))
971
972 ;; Return true if OP is CONST_INT >= 1 and <= 63 (a valid operand
973 ;; for 64bit shift & compare patterns, as shifting by 0 does not change flags).
974 (define_predicate "const_1_to_63_operand"
975 (and (match_code "const_int")
976 (match_test "IN_RANGE (INTVAL (op), 1, 63)")))
977
978 ;; Match 2 or 3.
979 (define_predicate "const_2_to_3_operand"
980 (and (match_code "const_int")
981 (match_test "IN_RANGE (INTVAL (op), 2, 3)")))
982
983 ;; Match 4 to 5.
984 (define_predicate "const_4_to_5_operand"
985 (and (match_code "const_int")
986 (match_test "IN_RANGE (INTVAL (op), 4, 5)")))
987
988 ;; Match 4 to 7.
989 (define_predicate "const_4_to_7_operand"
990 (and (match_code "const_int")
991 (match_test "IN_RANGE (INTVAL (op), 4, 7)")))
992
993 ;; Match 6 to 7.
994 (define_predicate "const_6_to_7_operand"
995 (and (match_code "const_int")
996 (match_test "IN_RANGE (INTVAL (op), 6, 7)")))
997
998 ;; Match 8 to 9.
999 (define_predicate "const_8_to_9_operand"
1000 (and (match_code "const_int")
1001 (match_test "IN_RANGE (INTVAL (op), 8, 9)")))
1002
1003 ;; Match 8 to 11.
1004 (define_predicate "const_8_to_11_operand"
1005 (and (match_code "const_int")
1006 (match_test "IN_RANGE (INTVAL (op), 8, 11)")))
1007
1008 ;; Match 8 to 15.
1009 (define_predicate "const_8_to_15_operand"
1010 (and (match_code "const_int")
1011 (match_test "IN_RANGE (INTVAL (op), 8, 15)")))
1012
1013 ;; Match 10 to 11.
1014 (define_predicate "const_10_to_11_operand"
1015 (and (match_code "const_int")
1016 (match_test "IN_RANGE (INTVAL (op), 10, 11)")))
1017
1018 ;; Match 12 to 13.
1019 (define_predicate "const_12_to_13_operand"
1020 (and (match_code "const_int")
1021 (match_test "IN_RANGE (INTVAL (op), 12, 13)")))
1022
1023 ;; Match 12 to 15.
1024 (define_predicate "const_12_to_15_operand"
1025 (and (match_code "const_int")
1026 (match_test "IN_RANGE (INTVAL (op), 12, 15)")))
1027
1028 ;; Match 14 to 15.
1029 (define_predicate "const_14_to_15_operand"
1030 (and (match_code "const_int")
1031 (match_test "IN_RANGE (INTVAL (op), 14, 15)")))
1032
1033 ;; Match 16 to 19.
1034 (define_predicate "const_16_to_19_operand"
1035 (and (match_code "const_int")
1036 (match_test "IN_RANGE (INTVAL (op), 16, 19)")))
1037
1038 ;; Match 16 to 31.
1039 (define_predicate "const_16_to_31_operand"
1040 (and (match_code "const_int")
1041 (match_test "IN_RANGE (INTVAL (op), 16, 31)")))
1042
1043 ;; Match 20 to 23.
1044 (define_predicate "const_20_to_23_operand"
1045 (and (match_code "const_int")
1046 (match_test "IN_RANGE (INTVAL (op), 20, 23)")))
1047
1048 ;; Match 24 to 27.
1049 (define_predicate "const_24_to_27_operand"
1050 (and (match_code "const_int")
1051 (match_test "IN_RANGE (INTVAL (op), 24, 27)")))
1052
1053 ;; Match 28 to 31.
1054 (define_predicate "const_28_to_31_operand"
1055 (and (match_code "const_int")
1056 (match_test "IN_RANGE (INTVAL (op), 28, 31)")))
1057
1058 (define_predicate "cmpps_imm_operand"
1059 (ior (match_operand 0 "const_0_to_7_operand")
1060 (and (match_test "TARGET_AVX")
1061 (match_operand 0 "const_0_to_31_operand"))))
1062
1063 ;; True if this is a constant appropriate for an increment or decrement.
1064 (define_predicate "incdec_operand"
1065 (match_code "const_int")
1066 {
1067 /* On Pentium4, the inc and dec operations causes extra dependency on flag
1068 registers, since carry flag is not set. */
1069 if (!TARGET_USE_INCDEC && !optimize_insn_for_size_p ())
1070 return false;
1071 return op == const1_rtx || op == constm1_rtx;
1072 })
1073
1074 ;; True for registers, or const_int_operand, used to vec_setm expander.
1075 (define_predicate "vec_setm_sse41_operand"
1076 (ior (and (match_operand 0 "register_operand")
1077 (match_test "TARGET_SSE4_1"))
1078 (match_code "const_int")))
1079
1080 (define_predicate "vec_setm_avx2_operand"
1081 (ior (and (match_operand 0 "register_operand")
1082 (match_test "TARGET_AVX2"))
1083 (match_code "const_int")))
1084
1085 (define_predicate "vec_setm_mmx_operand"
1086 (ior (and (match_operand 0 "register_operand")
1087 (match_test "TARGET_SSE4_1")
1088 (match_test "TARGET_MMX_WITH_SSE"))
1089 (match_code "const_int")))
1090
1091 ;; True for registers, or 1 or -1. Used to optimize double-word shifts.
1092 (define_predicate "reg_or_pm1_operand"
1093 (ior (match_operand 0 "register_operand")
1094 (and (match_code "const_int")
1095 (ior (match_test "op == const1_rtx")
1096 (match_test "op == constm1_rtx")))))
1097
1098 ;; True for registers, or (not: registers). Used to optimize 3-operand
1099 ;; bitwise operation.
1100 (define_predicate "regmem_or_bitnot_regmem_operand"
1101 (ior (match_operand 0 "nonimmediate_operand")
1102 (and (match_code "not")
1103 (match_test "nonimmediate_operand (XEXP (op, 0), mode)"))))
1104
1105 ;; True for expressions valid for 3-operand ternlog instructions.
1106 (define_predicate "ternlog_operand"
1107 (and (match_code "not,and,ior,xor")
1108 (match_test "ix86_ternlog_operand_p (op)")))
1109
1110 ;; True if OP is acceptable as operand of DImode shift expander.
1111 (define_predicate "shiftdi_operand"
1112 (if_then_else (match_test "TARGET_64BIT")
1113 (match_operand 0 "nonimmediate_operand")
1114 (match_operand 0 "register_operand")))
1115
1116 (define_predicate "ashldi_input_operand"
1117 (if_then_else (match_test "TARGET_64BIT")
1118 (match_operand 0 "nonimmediate_operand")
1119 (match_operand 0 "reg_or_pm1_operand")))
1120
1121 ;; Return true if OP is a vector load from the constant pool with just
1122 ;; the first element nonzero.
1123 (define_predicate "zero_extended_scalar_load_operand"
1124 (match_code "mem")
1125 {
1126 unsigned n_elts;
1127 op = avoid_constant_pool_reference (op);
1128
1129 if (GET_CODE (op) != CONST_VECTOR)
1130 return false;
1131
1132 n_elts = CONST_VECTOR_NUNITS (op);
1133
1134 for (n_elts--; n_elts > 0; n_elts--)
1135 {
1136 rtx elt = CONST_VECTOR_ELT (op, n_elts);
1137 if (elt != CONST0_RTX (GET_MODE_INNER (GET_MODE (op))))
1138 return false;
1139 }
1140 return true;
1141 })
1142
1143 /* Return true if operand is a float vector constant that is all ones. */
1144 (define_predicate "float_vector_all_ones_operand"
1145 (match_code "const_vector,mem")
1146 {
1147 mode = GET_MODE (op);
1148 if (!FLOAT_MODE_P (mode)
1149 || (MEM_P (op)
1150 && (!SYMBOL_REF_P (XEXP (op, 0))
1151 || !CONSTANT_POOL_ADDRESS_P (XEXP (op, 0)))))
1152 return false;
1153
1154 if (MEM_P (op))
1155 {
1156 op = get_pool_constant (XEXP (op, 0));
1157 if (GET_CODE (op) != CONST_VECTOR)
1158 return false;
1159
1160 if (GET_MODE (op) != mode
1161 && INTEGRAL_MODE_P (GET_MODE (op))
1162 && op == CONSTM1_RTX (GET_MODE (op)))
1163 return true;
1164 }
1165
1166 rtx first = XVECEXP (op, 0, 0);
1167 for (int i = 1; i != GET_MODE_NUNITS (GET_MODE (op)); i++)
1168 {
1169 rtx tmp = XVECEXP (op, 0, i);
1170 if (!rtx_equal_p (tmp, first))
1171 return false;
1172 }
1173 if (GET_MODE (first) == E_SFmode)
1174 {
1175 long l;
1176 REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (first), l);
1177 return (l & 0xffffffff) == 0xffffffff;
1178 }
1179 else if (GET_MODE (first) == E_DFmode)
1180 {
1181 long l[2];
1182 REAL_VALUE_TO_TARGET_DOUBLE (*CONST_DOUBLE_REAL_VALUE (first), l);
1183 return ((l[0] & 0xffffffff) == 0xffffffff
1184 && (l[1] & 0xffffffff) == 0xffffffff);
1185 }
1186 else
1187 return false;
1188 })
1189
1190 /* Return true if operand is an integral vector constant that is all ones. */
1191 (define_predicate "vector_all_ones_operand"
1192 (and (match_code "const_vector")
1193 (match_test "INTEGRAL_MODE_P (GET_MODE (op))")
1194 (match_test "op == CONSTM1_RTX (GET_MODE (op))")))
1195
1196 /* Return true if operand is a vector constant that is all ones. */
1197 (define_predicate "int_float_vector_all_ones_operand"
1198 (ior (match_operand 0 "vector_all_ones_operand")
1199 (match_operand 0 "float_vector_all_ones_operand")
1200 (match_test "op == constm1_rtx")))
1201
1202 /* Return true if operand is an 128/256bit all ones vector
1203 that zero-extends to 256/512bit. */
1204 (define_predicate "vector_all_ones_zero_extend_half_operand"
1205 (match_code "const_vector")
1206 {
1207 mode = GET_MODE (op);
1208 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT
1209 || (GET_MODE_SIZE (mode) != 32
1210 && GET_MODE_SIZE (mode) != 64))
1211 return false;
1212
1213 int nelts = CONST_VECTOR_NUNITS (op);
1214 for (int i = 0; i != nelts; i++)
1215 {
1216 rtx elt = CONST_VECTOR_ELT (op, i);
1217 if (i < nelts / 2
1218 && elt != CONSTM1_RTX (GET_MODE_INNER (mode)))
1219 return false;
1220 if (i >= nelts / 2
1221 && elt != CONST0_RTX (GET_MODE_INNER (mode)))
1222 return false;
1223 }
1224 return true;
1225 })
1226
1227 /* Return true if operand is an 128bit all ones vector
1228 that zero extends to 512bit. */
1229 (define_predicate "vector_all_ones_zero_extend_quarter_operand"
1230 (match_code "const_vector")
1231 {
1232 mode = GET_MODE (op);
1233 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT
1234 || GET_MODE_SIZE (mode) != 64)
1235 return false;
1236
1237 int nelts = CONST_VECTOR_NUNITS (op);
1238 for (int i = 0; i != nelts; i++)
1239 {
1240 rtx elt = CONST_VECTOR_ELT (op, i);
1241 if (i < nelts / 4
1242 && elt != CONSTM1_RTX (GET_MODE_INNER (mode)))
1243 return false;
1244 if (i >= nelts / 4
1245 && elt != CONST0_RTX (GET_MODE_INNER (mode)))
1246 return false;
1247 }
1248 return true;
1249 })
1250
1251 ; Return true when OP is operand acceptable for vector memory operand.
1252 ; Only AVX can have misaligned memory operand.
1253 (define_predicate "vector_memory_operand"
1254 (and (match_operand 0 "memory_operand")
1255 (ior (match_test "TARGET_AVX")
1256 (match_test "MEM_ALIGN (op) >= GET_MODE_ALIGNMENT (mode)"))))
1257
1258 ; Return true when OP is register_operand or vector_memory_operand.
1259 (define_predicate "vector_operand"
1260 (ior (match_operand 0 "register_operand")
1261 (match_operand 0 "vector_memory_operand")))
1262
1263 ; Return true when OP is register_operand, vector_memory_operand
1264 ; or const_vector.
1265 (define_predicate "vector_or_const_vector_operand"
1266 (ior (match_operand 0 "register_operand")
1267 (match_operand 0 "vector_memory_operand")
1268 (match_code "const_vector")))
1269
1270 (define_predicate "bcst_mem_operand"
1271 (and (match_code "vec_duplicate")
1272 (and (match_test "TARGET_AVX512F")
1273 (ior (match_test "TARGET_AVX512VL")
1274 (and (match_test "GET_MODE_SIZE (GET_MODE (op)) == 64")
1275 (match_test "TARGET_EVEX512"))))
1276 (match_test "VALID_BCST_MODE_P (GET_MODE_INNER (GET_MODE (op)))")
1277 (match_test "GET_MODE (XEXP (op, 0))
1278 == GET_MODE_INNER (GET_MODE (op))")
1279 (match_test "memory_operand (XEXP (op, 0), GET_MODE (XEXP (op, 0)))")))
1280
1281 ; Return true when OP is bcst_mem_operand or vector_memory_operand.
1282 (define_predicate "bcst_vector_operand"
1283 (ior (match_operand 0 "vector_operand")
1284 (match_operand 0 "bcst_mem_operand")))
1285
1286 ;; Return true when OP is either nonimmediate operand, or any
1287 ;; CONST_VECTOR.
1288 (define_predicate "nonimmediate_or_const_vector_operand"
1289 (ior (match_operand 0 "nonimmediate_operand")
1290 (match_code "const_vector")))
1291
1292 (define_predicate "nonimmediate_or_const_vec_dup_operand"
1293 (ior (match_operand 0 "nonimmediate_operand")
1294 (match_test "const_vec_duplicate_p (op)")))
1295
1296 ;; Return true when OP is either register operand, or any
1297 ;; CONST_VECTOR.
1298 (define_predicate "reg_or_const_vector_operand"
1299 (ior (match_operand 0 "register_operand")
1300 (match_code "const_vector")))
1301
1302 ;; Return true when OP is CONST_VECTOR which can be converted to a
1303 ;; sign extended 32-bit integer.
1304 (define_predicate "x86_64_const_vector_operand"
1305 (match_code "const_vector")
1306 {
1307 if (mode == VOIDmode)
1308 mode = GET_MODE (op);
1309 else if (GET_MODE (op) != mode)
1310 return false;
1311 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
1312 return false;
1313 HOST_WIDE_INT val = ix86_convert_const_vector_to_integer (op, mode);
1314 return trunc_int_for_mode (val, SImode) == val;
1315 })
1316
1317 (define_predicate "nonimmediate_or_x86_64_const_vector_operand"
1318 (ior (match_operand 0 "nonimmediate_operand")
1319 (match_operand 0 "x86_64_const_vector_operand")))
1320
1321 ;; Return true when OP is nonimmediate or standard SSE constant.
1322 (define_predicate "nonimmediate_or_sse_const_operand"
1323 (ior (match_operand 0 "nonimmediate_operand")
1324 (match_test "standard_sse_constant_p (op, mode)")))
1325
1326 ;; Return true if OP is a register or a zero.
1327 (define_predicate "reg_or_0_operand"
1328 (ior (match_operand 0 "register_operand")
1329 (match_operand 0 "const0_operand")))
1330
1331 ; Return true when OP is a nonimmediate or zero.
1332 (define_predicate "nonimm_or_0_operand"
1333 (ior (match_operand 0 "nonimmediate_operand")
1334 (match_operand 0 "const0_operand")))
1335
1336 ;; Return true for RTX codes that force SImode address.
1337 (define_predicate "SImode_address_operand"
1338 (match_code "subreg,zero_extend,and"))
1339
1340 ;; Return true if op is a valid address for LEA, and does not contain
1341 ;; a segment override. Defined as a special predicate to allow
1342 ;; mode-less const_int operands pass to address_operand.
1343 (define_special_predicate "address_no_seg_operand"
1344 (match_test "address_operand (op, VOIDmode)")
1345 {
1346 struct ix86_address parts;
1347 int ok;
1348
1349 if (!CONST_INT_P (op)
1350 && mode != VOIDmode
1351 && GET_MODE (op) != mode)
1352 return false;
1353
1354 ok = ix86_decompose_address (op, &parts);
1355 gcc_assert (ok);
1356 return parts.seg == ADDR_SPACE_GENERIC;
1357 })
1358
1359 ;; Return true if op if a valid base register, displacement or
1360 ;; sum of base register and displacement for VSIB addressing.
1361 (define_predicate "vsib_address_operand"
1362 (match_test "address_operand (op, VOIDmode)")
1363 {
1364 struct ix86_address parts;
1365 int ok;
1366 rtx disp;
1367
1368 ok = ix86_decompose_address (op, &parts);
1369 gcc_assert (ok);
1370 if (parts.index || parts.seg != ADDR_SPACE_GENERIC)
1371 return false;
1372
1373 /* VSIB addressing doesn't support (%rip). */
1374 if (parts.disp)
1375 {
1376 disp = parts.disp;
1377 if (GET_CODE (disp) == CONST)
1378 {
1379 disp = XEXP (disp, 0);
1380 if (GET_CODE (disp) == PLUS)
1381 disp = XEXP (disp, 0);
1382 if (GET_CODE (disp) == UNSPEC)
1383 switch (XINT (disp, 1))
1384 {
1385 case UNSPEC_GOTPCREL:
1386 case UNSPEC_PCREL:
1387 case UNSPEC_GOTNTPOFF:
1388 return false;
1389 }
1390 }
1391 if (TARGET_64BIT
1392 && flag_pic
1393 && (GET_CODE (disp) == SYMBOL_REF
1394 || GET_CODE (disp) == LABEL_REF))
1395 return false;
1396 }
1397
1398 return true;
1399 })
1400
1401 (define_predicate "vsib_mem_operator"
1402 (match_code "mem"))
1403
1404 ;; Return true if the rtx is known to be at least 32 bits aligned.
1405 (define_predicate "aligned_operand"
1406 (match_operand 0 "general_operand")
1407 {
1408 struct ix86_address parts;
1409 int ok;
1410
1411 /* Registers and immediate operands are always "aligned". */
1412 if (!MEM_P (op))
1413 return true;
1414
1415 /* All patterns using aligned_operand on memory operands ends up
1416 in promoting memory operand to 64bit and thus causing memory mismatch. */
1417 if (TARGET_MEMORY_MISMATCH_STALL && !optimize_insn_for_size_p ())
1418 return false;
1419
1420 /* Don't even try to do any aligned optimizations with volatiles. */
1421 if (MEM_VOLATILE_P (op))
1422 return false;
1423
1424 if (MEM_ALIGN (op) >= 32)
1425 return true;
1426
1427 op = XEXP (op, 0);
1428
1429 /* Pushes and pops are only valid on the stack pointer. */
1430 if (GET_CODE (op) == PRE_DEC
1431 || GET_CODE (op) == POST_INC)
1432 return true;
1433
1434 /* Decode the address. */
1435 ok = ix86_decompose_address (op, &parts);
1436 gcc_assert (ok);
1437
1438 if (parts.base && SUBREG_P (parts.base))
1439 parts.base = SUBREG_REG (parts.base);
1440 if (parts.index && SUBREG_P (parts.index))
1441 parts.index = SUBREG_REG (parts.index);
1442
1443 /* Look for some component that isn't known to be aligned. */
1444 if (parts.index)
1445 {
1446 if (REGNO_POINTER_ALIGN (REGNO (parts.index)) * parts.scale < 32)
1447 return false;
1448 }
1449 if (parts.base)
1450 {
1451 if (REGNO_POINTER_ALIGN (REGNO (parts.base)) < 32)
1452 return false;
1453 }
1454 if (parts.disp)
1455 {
1456 if (!CONST_INT_P (parts.disp)
1457 || (INTVAL (parts.disp) & 3))
1458 return false;
1459 }
1460
1461 /* Didn't find one -- this must be an aligned address. */
1462 return true;
1463 })
1464
1465 ;; Return true if OP is memory operand with a displacement.
1466 (define_predicate "memory_displacement_operand"
1467 (match_operand 0 "memory_operand")
1468 {
1469 struct ix86_address parts;
1470 int ok;
1471
1472 ok = ix86_decompose_address (XEXP (op, 0), &parts);
1473 gcc_assert (ok);
1474 return parts.disp != NULL_RTX;
1475 })
1476
1477 ;; Return true if OP is memory operand with a displacement only.
1478 (define_predicate "memory_displacement_only_operand"
1479 (match_operand 0 "memory_operand")
1480 {
1481 struct ix86_address parts;
1482 int ok;
1483
1484 if (TARGET_64BIT)
1485 return false;
1486
1487 ok = ix86_decompose_address (XEXP (op, 0), &parts);
1488 gcc_assert (ok);
1489
1490 if (parts.base || parts.index)
1491 return false;
1492
1493 return parts.disp != NULL_RTX;
1494 })
1495
1496 ;; Return true if OP is memory operand that cannot be represented
1497 ;; by the modRM array.
1498 (define_predicate "long_memory_operand"
1499 (and (match_operand 0 "memory_operand")
1500 (match_test "memory_address_length (op, false)")))
1501
1502 ;; Return true if OP is a comparison operator that can be issued by fcmov.
1503 (define_predicate "fcmov_comparison_operator"
1504 (match_operand 0 "comparison_operator")
1505 {
1506 machine_mode inmode = GET_MODE (XEXP (op, 0));
1507 enum rtx_code code = GET_CODE (op);
1508
1509 if (inmode == CCFPmode)
1510 code = ix86_fp_compare_code_to_integer (code);
1511
1512 /* i387 supports just limited amount of conditional codes. */
1513 switch (code)
1514 {
1515 case GEU: case LTU:
1516 if (inmode == CCCmode || inmode == CCGZmode)
1517 return true;
1518 /* FALLTHRU */
1519 case GTU: case LEU:
1520 if (inmode == CCmode || inmode == CCFPmode)
1521 return true;
1522 return false;
1523 case ORDERED: case UNORDERED:
1524 case EQ: case NE:
1525 return true;
1526 default:
1527 return false;
1528 }
1529 })
1530
1531 ;; Return true if OP is a comparison that can be used in the CMPSS/CMPPS insns.
1532 ;; The first set are supported directly; the second set can't be done with
1533 ;; full IEEE support, i.e. NaNs.
1534
1535 (define_predicate "sse_comparison_operator"
1536 (ior (match_code "eq,ne,lt,le,unordered,unge,ungt,ordered")
1537 (and (match_test "TARGET_AVX")
1538 (match_code "ge,gt,uneq,unle,unlt,ltgt"))))
1539
1540 (define_predicate "ix86_comparison_int_operator"
1541 (match_code "ne,eq,ge,gt,le,lt"))
1542
1543 (define_predicate "ix86_comparison_uns_operator"
1544 (match_code "ne,eq,geu,gtu,leu,ltu"))
1545
1546 (define_predicate "bt_comparison_operator"
1547 (match_code "ne,eq"))
1548
1549 (define_predicate "shr_comparison_operator"
1550 (match_code "gtu,leu"))
1551
1552 (define_predicate "add_comparison_operator"
1553 (match_code "geu,ltu"))
1554
1555 ;; Return true if OP is a valid comparison operator in valid mode.
1556 (define_predicate "ix86_comparison_operator"
1557 (match_operand 0 "comparison_operator")
1558 {
1559 machine_mode inmode = GET_MODE (XEXP (op, 0));
1560 enum rtx_code code = GET_CODE (op);
1561
1562 if (inmode == CCFPmode)
1563 return ix86_trivial_fp_comparison_operator (op, mode);
1564
1565 switch (code)
1566 {
1567 case EQ: case NE:
1568 if (inmode == CCGZmode)
1569 return false;
1570 return true;
1571 case GE: case LT:
1572 if (inmode == CCmode || inmode == CCGCmode
1573 || inmode == CCGOCmode || inmode == CCNOmode || inmode == CCGZmode)
1574 return true;
1575 return false;
1576 case GEU: case LTU:
1577 if (inmode == CCCmode || inmode == CCGZmode)
1578 return true;
1579 /* FALLTHRU */
1580 case GTU: case LEU:
1581 if (inmode == CCmode)
1582 return true;
1583 return false;
1584 case ORDERED: case UNORDERED:
1585 if (inmode == CCmode)
1586 return true;
1587 return false;
1588 case GT: case LE:
1589 if (inmode == CCmode || inmode == CCGCmode || inmode == CCNOmode)
1590 return true;
1591 return false;
1592 default:
1593 return false;
1594 }
1595 })
1596
1597 ;; Return true if OP is a valid comparison operator
1598 ;; testing carry flag to be set.
1599 (define_predicate "ix86_carry_flag_operator"
1600 (match_code "ltu,unlt")
1601 {
1602 machine_mode inmode = GET_MODE (XEXP (op, 0));
1603 enum rtx_code code = GET_CODE (op);
1604
1605 if (inmode == CCFPmode)
1606 code = ix86_fp_compare_code_to_integer (code);
1607 else if (inmode != CCmode && inmode != CCCmode && inmode != CCGZmode)
1608 return false;
1609
1610 return code == LTU;
1611 })
1612
1613 ;; Return true if OP is a valid comparison operator
1614 ;; testing carry flag to be unset.
1615 (define_predicate "ix86_carry_flag_unset_operator"
1616 (match_code "geu,ge")
1617 {
1618 machine_mode inmode = GET_MODE (XEXP (op, 0));
1619 enum rtx_code code = GET_CODE (op);
1620
1621 if (inmode == CCFPmode)
1622 code = ix86_fp_compare_code_to_integer (code);
1623 else if (inmode != CCmode && inmode != CCCmode && inmode != CCGZmode)
1624 return false;
1625
1626 return code == GEU;
1627 })
1628
1629 ;; Return true if this comparison only requires testing one flag bit.
1630 ;; VCOMX/VUCOMX set ZF, SF, OF, differently from COMI/UCOMI.
1631 (define_predicate "ix86_trivial_fp_comparison_operator"
1632 (if_then_else (match_test "TARGET_AVX10_2")
1633 (match_code "gt,ge,unlt,unle,eq,uneq,ne,ltgt,ordered,unordered")
1634 (match_code "gt,ge,unlt,unle,uneq,ltgt,ordered,unordered")))
1635
1636 (define_predicate "ix86_trivial_fp_comparison_operator_xf"
1637 (match_code "gt,ge,unlt,unle,uneq,ltgt,ordered,unordered"))
1638
1639 ;; Return true if we know how to do this comparison. Others require
1640 ;; testing more than one flag bit, and we let the generic middle-end
1641 ;; code do that.
1642 (define_predicate "ix86_fp_comparison_operator"
1643 (if_then_else (match_test "ix86_fp_comparison_strategy (GET_CODE (op))
1644 == IX86_FPCMP_ARITH")
1645 (match_operand 0 "comparison_operator")
1646 (match_operand 0 "ix86_trivial_fp_comparison_operator")))
1647
1648 (define_predicate "ix86_fp_comparison_operator_xf"
1649 (if_then_else (match_test "ix86_fp_comparison_strategy (GET_CODE (op))
1650 == IX86_FPCMP_ARITH")
1651 (match_operand 0 "comparison_operator")
1652 (match_operand 0 "ix86_trivial_fp_comparison_operator_xf")))
1653
1654 ;; Return true if we can perform this comparison on TImode operands.
1655 (define_predicate "ix86_timode_comparison_operator"
1656 (if_then_else (match_test "TARGET_64BIT")
1657 (match_operand 0 "ordered_comparison_operator")
1658 (match_operand 0 "bt_comparison_operator")))
1659
1660 ;; Return true if this is a valid second operand for a TImode comparison.
1661 (define_predicate "ix86_timode_comparison_operand"
1662 (if_then_else (match_test "TARGET_64BIT")
1663 (match_operand 0 "x86_64_general_operand")
1664 (match_operand 0 "nonimmediate_operand")))
1665
1666 ;; Nearly general operand, but accept any const_double, since we wish
1667 ;; to be able to drop them into memory rather than have them get pulled
1668 ;; into registers.
1669 (define_predicate "cmp_fp_expander_operand"
1670 (ior (match_code "const_double")
1671 (match_operand 0 "general_operand")))
1672
1673 ;; Return true if this is a valid binary floating-point operation.
1674 (define_predicate "binary_fp_operator"
1675 (match_code "plus,minus,mult,div"))
1676
1677 ;; Return true if this is a multiply operation.
1678 (define_predicate "mult_operator"
1679 (match_code "mult"))
1680
1681 ;; Return true if this is a division operation.
1682 (define_predicate "div_operator"
1683 (match_code "div"))
1684
1685 ;; Return true if this is an and, ior or xor operation.
1686 (define_predicate "logic_operator"
1687 (match_code "and,ior,xor"))
1688
1689 ;; Return true if this is an and operation.
1690 (define_predicate "and_operator"
1691 (match_code "and"))
1692
1693 ;; Return true if this is a plus, minus, and, ior or xor operation.
1694 (define_predicate "plusminuslogic_operator"
1695 (match_code "plus,minus,and,ior,xor"))
1696
1697 ;; Return true for ARITHMETIC_P.
1698 (define_predicate "arith_or_logical_operator"
1699 (match_code "plus,mult,and,ior,xor,smin,smax,umin,umax,compare,minus,div,
1700 mod,udiv,umod,ashift,rotate,ashiftrt,lshiftrt,rotatert"))
1701
1702 ;; Return true for COMMUTATIVE_P.
1703 (define_predicate "commutative_operator"
1704 (match_code "plus,mult,and,ior,xor,smin,smax,umin,umax"))
1705
1706 ;; Return true if OP is a binary operator that can be promoted to wider mode.
1707 (define_predicate "promotable_binary_operator"
1708 (ior (match_code "plus,minus,and,ior,xor,ashift")
1709 (and (match_code "mult")
1710 (match_test "TARGET_TUNE_PROMOTE_HIMODE_IMUL"))))
1711
1712 (define_predicate "compare_operator"
1713 (match_code "compare"))
1714
1715 (define_predicate "extract_operator"
1716 (match_code "zero_extract,sign_extract"))
1717
1718 ;; Return true if OP is a memory operand, aligned to
1719 ;; less than its natural alignment.
1720 (define_predicate "misaligned_operand"
1721 (and (match_code "mem")
1722 (match_test "MEM_ALIGN (op) < GET_MODE_BITSIZE (mode)")))
1723
1724 ;; Return true if OP is a parallel for an mov{d,q,dqa,ps,pd} vec_select,
1725 ;; where one of the two operands of the vec_concat is const0_operand.
1726 (define_predicate "movq_parallel"
1727 (match_code "parallel")
1728 {
1729 unsigned nelt = XVECLEN (op, 0);
1730 unsigned nelt2 = nelt >> 1;
1731 unsigned i;
1732
1733 if (nelt < 2)
1734 return false;
1735
1736 /* Validate that all of the elements are constants,
1737 lower halves of permute are lower halves of the first operand,
1738 upper halves of permute come from any of the second operand. */
1739 for (i = 0; i < nelt; ++i)
1740 {
1741 rtx er = XVECEXP (op, 0, i);
1742 unsigned HOST_WIDE_INT ei;
1743
1744 if (!CONST_INT_P (er))
1745 return false;
1746 ei = INTVAL (er);
1747 if (i < nelt2 && ei != i)
1748 return false;
1749 if (i >= nelt2 && (ei < nelt || ei >= nelt << 1))
1750 return false;
1751 }
1752
1753 return true;
1754 })
1755
1756 ;; Return true if OP is a vzeroall operation, known to be a PARALLEL.
1757 (define_predicate "vzeroall_operation"
1758 (match_code "parallel")
1759 {
1760 unsigned i, nregs = TARGET_64BIT ? 16 : 8;
1761
1762 if ((unsigned) XVECLEN (op, 0) != 1 + nregs)
1763 return false;
1764
1765 for (i = 0; i < nregs; i++)
1766 {
1767 rtx elt = XVECEXP (op, 0, i+1);
1768
1769 if (GET_CODE (elt) != SET
1770 || GET_CODE (SET_DEST (elt)) != REG
1771 || GET_MODE (SET_DEST (elt)) != V8SImode
1772 || REGNO (SET_DEST (elt)) != GET_SSE_REGNO (i)
1773 || SET_SRC (elt) != CONST0_RTX (V8SImode))
1774 return false;
1775 }
1776 return true;
1777 })
1778
1779 ;; return true if OP is a vzeroall pattern.
1780 (define_predicate "vzeroall_pattern"
1781 (and (match_code "parallel")
1782 (match_code "unspec_volatile" "a")
1783 (match_test "XINT (XVECEXP (op, 0, 0), 1) == UNSPECV_VZEROALL")))
1784
1785 ;; return true if OP is a vzeroupper pattern.
1786 (define_predicate "vzeroupper_pattern"
1787 (and (match_code "parallel")
1788 (match_code "unspec" "b")
1789 (match_test "XINT (XVECEXP (op, 0, 1), 1) == UNSPEC_CALLEE_ABI")
1790 (match_test "INTVAL (XVECEXP (XVECEXP (op, 0, 1), 0, 0)) == ABI_VZEROUPPER")))
1791
1792 ;; Return true if OP is an addsub vec_merge operation
1793 (define_predicate "addsub_vm_operator"
1794 (match_code "vec_merge")
1795 {
1796 rtx op0, op1;
1797 int swapped;
1798 HOST_WIDE_INT mask;
1799 int nunits, elt;
1800
1801 op0 = XEXP (op, 0);
1802 op1 = XEXP (op, 1);
1803
1804 /* Sanity check. */
1805 if (GET_CODE (op0) == MINUS && GET_CODE (op1) == PLUS)
1806 swapped = 0;
1807 else if (GET_CODE (op0) == PLUS && GET_CODE (op1) == MINUS)
1808 swapped = 1;
1809 else
1810 gcc_unreachable ();
1811
1812 mask = INTVAL (XEXP (op, 2));
1813 nunits = GET_MODE_NUNITS (mode);
1814
1815 for (elt = 0; elt < nunits; elt++)
1816 {
1817 /* bit clear: take from op0, set: take from op1 */
1818 int bit = !(mask & (HOST_WIDE_INT_1U << elt));
1819
1820 if (bit != ((elt & 1) ^ swapped))
1821 return false;
1822 }
1823
1824 return true;
1825 })
1826
1827 ;; Return true if OP is an addsub vec_select/vec_concat operation
1828 (define_predicate "addsub_vs_operator"
1829 (and (match_code "vec_select")
1830 (match_code "vec_concat" "0"))
1831 {
1832 rtx op0, op1;
1833 bool swapped;
1834 int nunits, elt;
1835
1836 op0 = XEXP (XEXP (op, 0), 0);
1837 op1 = XEXP (XEXP (op, 0), 1);
1838
1839 /* Sanity check. */
1840 if (GET_CODE (op0) == MINUS && GET_CODE (op1) == PLUS)
1841 swapped = false;
1842 else if (GET_CODE (op0) == PLUS && GET_CODE (op1) == MINUS)
1843 swapped = true;
1844 else
1845 gcc_unreachable ();
1846
1847 nunits = GET_MODE_NUNITS (mode);
1848 if (XVECLEN (XEXP (op, 1), 0) != nunits)
1849 return false;
1850
1851 /* We already checked that permutation is suitable for addsub,
1852 so only look at the first element of the parallel. */
1853 elt = INTVAL (XVECEXP (XEXP (op, 1), 0, 0));
1854
1855 return elt == (swapped ? nunits : 0);
1856 })
1857
1858 ;; Return true if OP is a parallel for an addsub vec_select.
1859 (define_predicate "addsub_vs_parallel"
1860 (and (match_code "parallel")
1861 (match_code "const_int" "a"))
1862 {
1863 int nelt = XVECLEN (op, 0);
1864 int elt, i;
1865
1866 if (nelt < 2)
1867 return false;
1868
1869 /* Check that the permutation is suitable for addsub.
1870 For example, { 0 9 2 11 4 13 6 15 } or { 8 1 10 3 12 5 14 7 }. */
1871 elt = INTVAL (XVECEXP (op, 0, 0));
1872 if (elt == 0)
1873 {
1874 for (i = 1; i < nelt; ++i)
1875 if (INTVAL (XVECEXP (op, 0, i)) != (i + (i & 1) * nelt))
1876 return false;
1877 }
1878 else if (elt == nelt)
1879 {
1880 for (i = 1; i < nelt; ++i)
1881 if (INTVAL (XVECEXP (op, 0, i)) != (elt + i - (i & 1) * nelt))
1882 return false;
1883 }
1884 else
1885 return false;
1886
1887 return true;
1888 })
1889
1890 ;; Return true if OP is a constant pool in perm{w,d,b} which constains index
1891 ;; match pmov{dw,wb,qd}.
1892 (define_predicate "permvar_truncate_operand"
1893 (match_code "mem")
1894 {
1895 int nelt = GET_MODE_NUNITS (mode);
1896 int perm[128];
1897 int id;
1898
1899 if (!INTEGRAL_MODE_P (mode) || !VECTOR_MODE_P (mode))
1900 return false;
1901
1902 if (nelt < 2)
1903 return false;
1904
1905 if (!ix86_extract_perm_from_pool_constant (&perm[0], op))
1906 return false;
1907
1908 id = exact_log2 (nelt);
1909
1910 /* Check that the permutation is suitable for pmovz{bw,wd,dq}.
1911 For example V16HImode to V8HImode
1912 { 0 2 4 6 8 10 12 14 * * * * * * * * }. */
1913 for (int i = 0; i != nelt / 2; i++)
1914 if ((perm[i] & ((1 << id) - 1)) != i * 2)
1915 return false;
1916
1917 return true;
1918 })
1919
1920 ;; Return true if OP is a constant pool in shufb which constains index
1921 ;; match pmovdw.
1922 (define_predicate "pshufb_truncv4siv4hi_operand"
1923 (match_code "mem")
1924 {
1925 int perm[128];
1926
1927 if (mode != E_V16QImode)
1928 return false;
1929
1930 if (!ix86_extract_perm_from_pool_constant (&perm[0], op))
1931 return false;
1932
1933 /* Check that the permutation is suitable for pmovdw.
1934 For example V4SImode to V4HImode
1935 { 0 1 4 5 8 9 12 13 * * * * * * * * }.
1936 index = i % 2 + (i / 2) * 4. */
1937 for (int i = 0; i != 8; i++)
1938 {
1939 /* if (SRC2[(i * 8)+7] = 1) then DEST[(i*8)+7..(i*8)+0] := 0; */
1940 if (perm[i] & 128)
1941 return false;
1942
1943 if ((perm[i] & 15) != ((i & 1) + (i & 0xFE) * 2))
1944 return false;
1945 }
1946
1947 return true;
1948 })
1949
1950 ;; Return true if OP is a constant pool in shufb which constains index
1951 ;; match pmovdw.
1952 (define_predicate "pshufb_truncv8hiv8qi_operand"
1953 (match_code "mem")
1954 {
1955 int perm[128];
1956
1957 if (mode != E_V16QImode)
1958 return false;
1959
1960 if (!ix86_extract_perm_from_pool_constant (&perm[0], op))
1961 return false;
1962
1963 /* Check that the permutation is suitable for pmovwb.
1964 For example V16QImode to V8QImode
1965 { 0 2 4 6 8 10 12 14 * * * * * * * * }.
1966 index = i % 2 + (i / 2) * 4. */
1967 for (int i = 0; i != 8; i++)
1968 {
1969 /* if (SRC2[(i * 8)+7] = 1) then DEST[(i*8)+7..(i*8)+0] := 0; */
1970 if (perm[i] & 128)
1971 return false;
1972
1973 if ((perm[i] & 15) != i * 2)
1974 return false;
1975 }
1976
1977 return true;
1978 })
1979
1980 ;; Return true if OP is a parallel for an pmovz{bw,wd,dq} vec_select,
1981 ;; where one of the two operands of the vec_concat is const0_operand.
1982 (define_predicate "pmovzx_parallel"
1983 (and (match_code "parallel")
1984 (match_code "const_int" "a"))
1985 {
1986 int nelt = XVECLEN (op, 0);
1987 int elt, i;
1988
1989 if (nelt < 2)
1990 return false;
1991
1992 /* Check that the permutation is suitable for pmovz{bw,wd,dq}.
1993 For example { 0 16 1 17 2 18 3 19 4 20 5 21 6 22 7 23 }. */
1994 elt = INTVAL (XVECEXP (op, 0, 0));
1995 if (elt == 0)
1996 {
1997 for (i = 1; i < nelt; ++i)
1998 if ((i & 1) != 0)
1999 {
2000 if (INTVAL (XVECEXP (op, 0, i)) < nelt)
2001 return false;
2002 }
2003 else if (INTVAL (XVECEXP (op, 0, i)) != i / 2)
2004 return false;
2005 }
2006 else
2007 return false;
2008
2009 return true;
2010 })
2011
2012 ;; Return true if OP is a const vector with duplicate value.
2013 (define_predicate "const_vector_duplicate_operand"
2014 (match_code "const_vector")
2015 {
2016 rtx elt = XVECEXP (op, 0, 0);
2017 int i, nelt = XVECLEN (op, 0);
2018
2019 for (i = 1; i < nelt; ++i)
2020 if (!rtx_equal_p (elt, XVECEXP (op, 0, i)))
2021 return false;
2022 return true;
2023 })
2024
2025 ;; Return true if OP is a parallel for a vbroadcast permute.
2026 (define_predicate "avx_vbroadcast_operand"
2027 (and (match_code "parallel")
2028 (match_code "const_int" "a"))
2029 {
2030 rtx elt = XVECEXP (op, 0, 0);
2031 int i, nelt = XVECLEN (op, 0);
2032
2033 /* Don't bother checking there are the right number of operands,
2034 merely that they're all identical. */
2035 for (i = 1; i < nelt; ++i)
2036 if (XVECEXP (op, 0, i) != elt)
2037 return false;
2038 return true;
2039 })
2040
2041 ;; Return true if OP is a parallel for a palignr permute.
2042 (define_predicate "palignr_operand"
2043 (and (match_code "parallel")
2044 (match_code "const_int" "a"))
2045 {
2046 int elt = INTVAL (XVECEXP (op, 0, 0));
2047 int i, nelt = XVECLEN (op, 0);
2048
2049 /* Check that an order in the permutation is suitable for palignr.
2050 For example, {5 6 7 0 1 2 3 4} is "palignr 5, xmm, xmm". */
2051 for (i = 1; i < nelt; ++i)
2052 if (INTVAL (XVECEXP (op, 0, i)) != ((elt + i) % nelt))
2053 return false;
2054 return true;
2055 })
2056
2057 ;; Return true if OP is a proper third operand to vpblendw256.
2058 (define_predicate "avx2_pblendw_operand"
2059 (match_code "const_int")
2060 {
2061 HOST_WIDE_INT val = INTVAL (op);
2062 HOST_WIDE_INT low = val & 0xff;
2063 return val == ((low << 8) | low);
2064 })
2065
2066 ;; Return true if OP is vector_operand or CONST_VECTOR.
2067 (define_predicate "general_vector_operand"
2068 (ior (match_operand 0 "vector_operand")
2069 (match_code "const_vector")))
2070
2071 ;; Return true if OP is either -1 constant or stored in register.
2072 (define_predicate "register_or_constm1_operand"
2073 (ior (match_operand 0 "register_operand")
2074 (and (match_code "const_int")
2075 (match_test "op == constm1_rtx"))))
2076
2077 ;; Return true if the vector ends with between 12 and 18 register saves using
2078 ;; RAX as the base address.
2079 (define_predicate "save_multiple"
2080 (match_code "parallel")
2081 {
2082 const unsigned len = XVECLEN (op, 0);
2083 unsigned i;
2084
2085 /* Starting from end of vector, count register saves. */
2086 for (i = 0; i < len; ++i)
2087 {
2088 rtx src, dest, addr;
2089 rtx e = XVECEXP (op, 0, len - 1 - i);
2090
2091 if (GET_CODE (e) != SET)
2092 break;
2093
2094 src = SET_SRC (e);
2095 dest = SET_DEST (e);
2096
2097 if (!REG_P (src) || !MEM_P (dest))
2098 break;
2099
2100 addr = XEXP (dest, 0);
2101
2102 /* Good if dest address is in RAX. */
2103 if (REG_P (addr) && REGNO (addr) == AX_REG)
2104 continue;
2105
2106 /* Good if dest address is offset of RAX. */
2107 if (GET_CODE (addr) == PLUS
2108 && REG_P (XEXP (addr, 0))
2109 && REGNO (XEXP (addr, 0)) == AX_REG)
2110 continue;
2111
2112 break;
2113 }
2114 return (i >= 12 && i <= 18);
2115 })
2116
2117
2118 ;; Return true if the vector ends with between 12 and 18 register loads using
2119 ;; RSI as the base address.
2120 (define_predicate "restore_multiple"
2121 (match_code "parallel")
2122 {
2123 const unsigned len = XVECLEN (op, 0);
2124 unsigned i;
2125
2126 /* Starting from end of vector, count register restores. */
2127 for (i = 0; i < len; ++i)
2128 {
2129 rtx src, dest, addr;
2130 rtx e = XVECEXP (op, 0, len - 1 - i);
2131
2132 if (GET_CODE (e) != SET)
2133 break;
2134
2135 src = SET_SRC (e);
2136 dest = SET_DEST (e);
2137
2138 if (!MEM_P (src) || !REG_P (dest))
2139 break;
2140
2141 addr = XEXP (src, 0);
2142
2143 /* Good if src address is in RSI. */
2144 if (REG_P (addr) && REGNO (addr) == SI_REG)
2145 continue;
2146
2147 /* Good if src address is offset of RSI. */
2148 if (GET_CODE (addr) == PLUS
2149 && REG_P (XEXP (addr, 0))
2150 && REGNO (XEXP (addr, 0)) == SI_REG)
2151 continue;
2152
2153 break;
2154 }
2155 return (i >= 12 && i <= 18);
2156 })
2157
2158 ;; Keylocker specific predicates
2159 (define_predicate "encodekey128_operation"
2160 (match_code "parallel")
2161 {
2162 unsigned i;
2163 rtx elt;
2164
2165 if (XVECLEN (op, 0) != 8)
2166 return false;
2167
2168 for(i = 0; i < 3; i++)
2169 {
2170 elt = XVECEXP (op, 0, i + 1);
2171 if (GET_CODE (elt) != SET
2172 || GET_CODE (SET_DEST (elt)) != REG
2173 || GET_MODE (SET_DEST (elt)) != V2DImode
2174 || REGNO (SET_DEST (elt)) != GET_SSE_REGNO (i)
2175 || GET_CODE (SET_SRC (elt)) != UNSPEC_VOLATILE
2176 || GET_MODE (SET_SRC (elt)) != V2DImode
2177 || XVECLEN(SET_SRC (elt), 0) != 1
2178 || XVECEXP(SET_SRC (elt), 0, 0) != const0_rtx)
2179 return false;
2180 }
2181
2182 for(i = 4; i < 7; i++)
2183 {
2184 elt = XVECEXP (op, 0, i);
2185 if (GET_CODE (elt) != CLOBBER
2186 || GET_MODE (elt) != VOIDmode
2187 || GET_CODE (XEXP (elt, 0)) != REG
2188 || GET_MODE (XEXP (elt, 0)) != V2DImode
2189 || REGNO (XEXP (elt, 0)) != GET_SSE_REGNO (i))
2190 return false;
2191 }
2192
2193 elt = XVECEXP (op, 0, 7);
2194 if (GET_CODE (elt) != CLOBBER
2195 || GET_MODE (elt) != VOIDmode
2196 || GET_CODE (XEXP (elt, 0)) != REG
2197 || GET_MODE (XEXP (elt, 0)) != CCmode
2198 || REGNO (XEXP (elt, 0)) != FLAGS_REG)
2199 return false;
2200 return true;
2201 })
2202
2203 (define_predicate "encodekey256_operation"
2204 (match_code "parallel")
2205 {
2206 unsigned i;
2207 rtx elt;
2208
2209 if (XVECLEN (op, 0) != 9)
2210 return false;
2211
2212 elt = SET_SRC (XVECEXP (op, 0, 0));
2213 elt = XVECEXP (elt, 0, 2);
2214 if (!REG_P (elt)
2215 || REGNO(elt) != GET_SSE_REGNO (1))
2216 return false;
2217
2218 for(i = 0; i < 4; i++)
2219 {
2220 elt = XVECEXP (op, 0, i + 1);
2221 if (GET_CODE (elt) != SET
2222 || GET_CODE (SET_DEST (elt)) != REG
2223 || GET_MODE (SET_DEST (elt)) != V2DImode
2224 || REGNO (SET_DEST (elt)) != GET_SSE_REGNO (i)
2225 || GET_CODE (SET_SRC (elt)) != UNSPEC_VOLATILE
2226 || GET_MODE (SET_SRC (elt)) != V2DImode
2227 || XVECLEN(SET_SRC (elt), 0) != 1
2228 || XVECEXP(SET_SRC (elt), 0, 0) != const0_rtx)
2229 return false;
2230 }
2231
2232 for(i = 4; i < 7; i++)
2233 {
2234 elt = XVECEXP (op, 0, i + 1);
2235 if (GET_CODE (elt) != CLOBBER
2236 || GET_MODE (elt) != VOIDmode
2237 || GET_CODE (XEXP (elt, 0)) != REG
2238 || GET_MODE (XEXP (elt, 0)) != V2DImode
2239 || REGNO (XEXP (elt, 0)) != GET_SSE_REGNO (i))
2240 return false;
2241 }
2242
2243 elt = XVECEXP (op, 0, 8);
2244 if (GET_CODE (elt) != CLOBBER
2245 || GET_MODE (elt) != VOIDmode
2246 || GET_CODE (XEXP (elt, 0)) != REG
2247 || GET_MODE (XEXP (elt, 0)) != CCmode
2248 || REGNO (XEXP (elt, 0)) != FLAGS_REG)
2249 return false;
2250 return true;
2251 })
2252
2253
2254 (define_predicate "aeswidekl_operation"
2255 (match_code "parallel")
2256 {
2257 unsigned i;
2258 rtx elt;
2259
2260 for (i = 0; i < 8; i++)
2261 {
2262 elt = XVECEXP (op, 0, i + 1);
2263 if (GET_CODE (elt) != SET
2264 || GET_CODE (SET_DEST (elt)) != REG
2265 || GET_MODE (SET_DEST (elt)) != V2DImode
2266 || REGNO (SET_DEST (elt)) != GET_SSE_REGNO (i)
2267 || GET_CODE (SET_SRC (elt)) != UNSPEC_VOLATILE
2268 || GET_MODE (SET_SRC (elt)) != V2DImode
2269 || XVECLEN (SET_SRC (elt), 0) != 1
2270 || !REG_P (XVECEXP (SET_SRC (elt), 0, 0))
2271 || REGNO (XVECEXP (SET_SRC (elt), 0, 0)) != GET_SSE_REGNO (i))
2272 return false;
2273 }
2274 return true;
2275 })
2276
2277 ;; Return true if OP is a memory operand that can be also used in APX
2278 ;; EVEX-encoded patterns (i.e. APX NDD/NF) with immediate operand. With
2279 ;; non-default address space, segment register or address size prefix,
2280 ;; APX EVEX-encoded instruction length can exceed the 15 byte size limit.
2281 (define_predicate "apx_evex_memory_operand"
2282 (match_operand 0 "memory_operand")
2283 {
2284 /* OK if immediate operand size < 4 bytes. */
2285 if (GET_MODE_SIZE (mode) < 4)
2286 return true;
2287
2288 bool default_addr = ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (op));
2289 bool address_size_prefix = TARGET_X32 && Pmode == SImode;
2290
2291 struct ix86_address parts;
2292 int ok;
2293
2294 op = XEXP (op, 0);
2295 ok = ix86_decompose_address (op, &parts);
2296 gcc_assert (ok);
2297
2298 if (default_addr)
2299 {
2300 /* Default address space. */
2301
2302 /* Not OK with address size prefix, index register and disp. */
2303 if (address_size_prefix
2304 && parts.index
2305 && parts.disp
2306 && parts.disp != const0_rtx)
2307 return false;
2308 }
2309 else
2310 {
2311 /* Non-default address space. */
2312
2313 /* Not OK without base register. */
2314 if (!parts.base)
2315 return false;
2316
2317 /* Not OK with disp and address size prefix. */
2318 if (address_size_prefix && parts.disp)
2319 return false;
2320 }
2321
2322 return true;
2323 })
2324
2325 ;; Return true if OP is a memory operand which can be used in APX EVEX-encoded
2326 ;; ADD patterns (i.e. APX NDD/NF) for with register source operand.
2327 ;; UNSPEC_GOTNTPOFF memory operand is allowed with APX EVEX-encoded ADD only if
2328 ;; R_X86_64_CODE_6_GOTTPOFF works.
2329 (define_predicate "apx_evex_add_memory_operand"
2330 (match_operand 0 "memory_operand")
2331 {
2332 /* OK if "add %reg1, name@gottpoff(%rip), %reg2" or
2333 "{nf} add name@gottpoff(%rip), %reg1" are supported. */
2334 if (HAVE_AS_R_X86_64_CODE_6_GOTTPOFF)
2335 return true;
2336
2337 op = XEXP (op, 0);
2338
2339 /* Disallow APX EVEX-encoded ADD with UNSPEC_GOTNTPOFF. */
2340 if (GET_CODE (op) == CONST
2341 && GET_CODE (XEXP (op, 0)) == UNSPEC
2342 && XINT (XEXP (op, 0), 1) == UNSPEC_GOTNTPOFF)
2343 return false;
2344
2345 return true;
2346 })