]> gcc.gnu.org Git - gcc.git/blob - gcc/config/rs6000/predicates.md
constraints.md (eI): New constraint.
[gcc.git] / gcc / config / rs6000 / predicates.md
1 ;; Predicate definitions for POWER and PowerPC.
2 ;; Copyright (C) 2005-2019 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 1 for anything except PARALLEL.
21 (define_predicate "any_operand"
22 (match_code "const_int,const_double,const_wide_int,const,symbol_ref,label_ref,subreg,reg,mem"))
23
24 ;; Return 1 for any PARALLEL.
25 (define_predicate "any_parallel_operand"
26 (match_code "parallel"))
27
28 ;; Return 1 if op is COUNT register.
29 (define_predicate "count_register_operand"
30 (and (match_code "reg")
31 (match_test "REGNO (op) == CTR_REGNO
32 || REGNO (op) > LAST_VIRTUAL_REGISTER")))
33
34 ;; Return 1 if op is a SUBREG that is used to look at a SFmode value as
35 ;; and integer or vice versa.
36 ;;
37 ;; In the normal case where SFmode is in a floating point/vector register, it
38 ;; is stored as a DFmode and has a different format. If we don't transform the
39 ;; value, things that use logical operations on the values will get the wrong
40 ;; value.
41 ;;
42 ;; If we don't have 64-bit and direct move, this conversion will be done by
43 ;; store and load, instead of by fiddling with the bits within the register.
44 (define_predicate "sf_subreg_operand"
45 (match_code "subreg")
46 {
47 rtx inner_reg = SUBREG_REG (op);
48 machine_mode inner_mode = GET_MODE (inner_reg);
49
50 if (TARGET_ALLOW_SF_SUBREG || !REG_P (inner_reg))
51 return 0;
52
53 if ((mode == SFmode && GET_MODE_CLASS (inner_mode) == MODE_INT)
54 || (GET_MODE_CLASS (mode) == MODE_INT && inner_mode == SFmode))
55 {
56 if (INT_REGNO_P (REGNO (inner_reg)))
57 return 0;
58
59 return 1;
60 }
61 return 0;
62 })
63
64 ;; Return 1 if op is an Altivec register.
65 (define_predicate "altivec_register_operand"
66 (match_operand 0 "register_operand")
67 {
68 if (SUBREG_P (op))
69 {
70 if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
71 return 0;
72
73 op = SUBREG_REG (op);
74 }
75
76 if (!REG_P (op))
77 return 0;
78
79 if (!HARD_REGISTER_P (op))
80 return 1;
81
82 return ALTIVEC_REGNO_P (REGNO (op));
83 })
84
85 ;; Return 1 if op is a VSX register.
86 (define_predicate "vsx_register_operand"
87 (match_operand 0 "register_operand")
88 {
89 if (SUBREG_P (op))
90 {
91 if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
92 return 0;
93
94 op = SUBREG_REG (op);
95 }
96
97 if (!REG_P (op))
98 return 0;
99
100 if (!HARD_REGISTER_P (op))
101 return 1;
102
103 return VSX_REGNO_P (REGNO (op));
104 })
105
106 ;; Like vsx_register_operand, but allow SF SUBREGS
107 (define_predicate "vsx_reg_sfsubreg_ok"
108 (match_operand 0 "register_operand")
109 {
110 if (SUBREG_P (op))
111 op = SUBREG_REG (op);
112
113 if (!REG_P (op))
114 return 0;
115
116 if (!HARD_REGISTER_P (op))
117 return 1;
118
119 return VSX_REGNO_P (REGNO (op));
120 })
121
122 ;; Return 1 if op is a vector register that operates on floating point vectors
123 ;; (either altivec or VSX).
124 (define_predicate "vfloat_operand"
125 (match_operand 0 "register_operand")
126 {
127 if (SUBREG_P (op))
128 {
129 if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
130 return 0;
131
132 op = SUBREG_REG (op);
133 }
134
135 if (!REG_P (op))
136 return 0;
137
138 if (!HARD_REGISTER_P (op))
139 return 1;
140
141 return VFLOAT_REGNO_P (REGNO (op));
142 })
143
144 ;; Return 1 if op is a vector register that operates on integer vectors
145 ;; (only altivec, VSX doesn't support integer vectors)
146 (define_predicate "vint_operand"
147 (match_operand 0 "register_operand")
148 {
149 if (SUBREG_P (op))
150 {
151 if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
152 return 0;
153
154 op = SUBREG_REG (op);
155 }
156
157 if (!REG_P (op))
158 return 0;
159
160 if (!HARD_REGISTER_P (op))
161 return 1;
162
163 return VINT_REGNO_P (REGNO (op));
164 })
165
166 ;; Return 1 if op is a vector register to do logical operations on (and, or,
167 ;; xor, etc.)
168 (define_predicate "vlogical_operand"
169 (match_operand 0 "register_operand")
170 {
171 if (SUBREG_P (op))
172 {
173 if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
174 return 0;
175
176 op = SUBREG_REG (op);
177 }
178
179
180 if (!REG_P (op))
181 return 0;
182
183 if (!HARD_REGISTER_P (op))
184 return 1;
185
186 return VLOGICAL_REGNO_P (REGNO (op));
187 })
188
189 ;; Return 1 if op is the carry register.
190 (define_predicate "ca_operand"
191 (match_operand 0 "register_operand")
192 {
193 if (SUBREG_P (op))
194 op = SUBREG_REG (op);
195
196 if (!REG_P (op))
197 return 0;
198
199 return CA_REGNO_P (REGNO (op));
200 })
201
202 ;; Return 1 if operand is constant zero (scalars and vectors).
203 (define_predicate "zero_constant"
204 (and (match_code "const_int,const_double,const_wide_int,const_vector")
205 (match_test "op == CONST0_RTX (mode)")))
206
207 ;; Return 1 if operand is constant -1 (scalars and vectors).
208 (define_predicate "all_ones_constant"
209 (and (match_code "const_int,const_double,const_wide_int,const_vector")
210 (match_test "op == CONSTM1_RTX (mode) && !FLOAT_MODE_P (mode)")))
211
212 ;; Return 1 if op is a signed 5-bit constant integer.
213 (define_predicate "s5bit_cint_operand"
214 (and (match_code "const_int")
215 (match_test "INTVAL (op) >= -16 && INTVAL (op) <= 15")))
216
217 ;; Return 1 if op is a unsigned 3-bit constant integer.
218 (define_predicate "u3bit_cint_operand"
219 (and (match_code "const_int")
220 (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 7")))
221
222 ;; Return 1 if op is a unsigned 5-bit constant integer.
223 (define_predicate "u5bit_cint_operand"
224 (and (match_code "const_int")
225 (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 31")))
226
227 ;; Return 1 if op is a unsigned 6-bit constant integer.
228 (define_predicate "u6bit_cint_operand"
229 (and (match_code "const_int")
230 (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 63")))
231
232 ;; Return 1 if op is an unsigned 7-bit constant integer.
233 (define_predicate "u7bit_cint_operand"
234 (and (match_code "const_int")
235 (match_test "IN_RANGE (INTVAL (op), 0, 127)")))
236
237 ;; Return 1 if op is a signed 8-bit constant integer.
238 ;; Integer multiplication complete more quickly
239 (define_predicate "s8bit_cint_operand"
240 (and (match_code "const_int")
241 (match_test "INTVAL (op) >= -128 && INTVAL (op) <= 127")))
242
243 ;; Return 1 if op is a unsigned 10-bit constant integer.
244 (define_predicate "u10bit_cint_operand"
245 (and (match_code "const_int")
246 (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 1023")))
247
248 ;; Return 1 if op is a constant integer that can fit in a D field.
249 (define_predicate "short_cint_operand"
250 (and (match_code "const_int")
251 (match_test "satisfies_constraint_I (op)")))
252
253 ;; Return 1 if op is a constant integer that can fit in an unsigned D field.
254 (define_predicate "u_short_cint_operand"
255 (and (match_code "const_int")
256 (match_test "satisfies_constraint_K (op)")))
257
258 ;; Return 1 if op is a constant integer that is a signed 16-bit constant
259 ;; shifted left 16 bits
260 (define_predicate "upper16_cint_operand"
261 (and (match_code "const_int")
262 (match_test "satisfies_constraint_L (op)")))
263
264 ;; Return 1 if op is a constant integer that cannot fit in a signed D field.
265 (define_predicate "non_short_cint_operand"
266 (and (match_code "const_int")
267 (match_test "(unsigned HOST_WIDE_INT)
268 (INTVAL (op) + 0x8000) >= 0x10000")))
269
270 ;; Return 1 if op is a positive constant integer that is an exact power of 2.
271 (define_predicate "exact_log2_cint_operand"
272 (and (match_code "const_int")
273 (match_test "INTVAL (op) > 0 && exact_log2 (INTVAL (op)) >= 0")))
274
275 ;; Match op = 0 or op = 1.
276 (define_predicate "const_0_to_1_operand"
277 (and (match_code "const_int")
278 (match_test "IN_RANGE (INTVAL (op), 0, 1)")))
279
280 ;; Match op = 0..3.
281 (define_predicate "const_0_to_3_operand"
282 (and (match_code "const_int")
283 (match_test "IN_RANGE (INTVAL (op), 0, 3)")))
284
285 ;; Match op = 2 or op = 3.
286 (define_predicate "const_2_to_3_operand"
287 (and (match_code "const_int")
288 (match_test "IN_RANGE (INTVAL (op), 2, 3)")))
289
290 ;; Match op = 0..7.
291 (define_predicate "const_0_to_7_operand"
292 (and (match_code "const_int")
293 (match_test "IN_RANGE (INTVAL (op), 0, 7)")))
294
295 ;; Match op = 0..11
296 (define_predicate "const_0_to_12_operand"
297 (and (match_code "const_int")
298 (match_test "IN_RANGE (INTVAL (op), 0, 12)")))
299
300 ;; Match op = 0..15
301 (define_predicate "const_0_to_15_operand"
302 (and (match_code "const_int")
303 (match_test "IN_RANGE (INTVAL (op), 0, 15)")))
304
305 ;; Return 1 if op is a 34-bit constant integer.
306 (define_predicate "cint34_operand"
307 (match_code "const_int")
308 {
309 if (!TARGET_PREFIXED_ADDR)
310 return 0;
311
312 return SIGNED_34BIT_OFFSET_P (INTVAL (op), 0);
313 })
314
315 ;; Return 1 if op is a register that is not special.
316 ;; Disallow (SUBREG:SF (REG:SI)) and (SUBREG:SI (REG:SF)) on VSX systems where
317 ;; you need to be careful in moving a SFmode to SImode and vice versa due to
318 ;; the fact that SFmode is represented as DFmode in the VSX registers.
319 (define_predicate "gpc_reg_operand"
320 (match_operand 0 "register_operand")
321 {
322 if (SUBREG_P (op))
323 {
324 if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
325 return 0;
326
327 op = SUBREG_REG (op);
328 }
329
330 if (!REG_P (op))
331 return 0;
332
333 if (!HARD_REGISTER_P (op))
334 return 1;
335
336 if (TARGET_ALTIVEC && ALTIVEC_REGNO_P (REGNO (op)))
337 return 1;
338
339 if (TARGET_VSX && VSX_REGNO_P (REGNO (op)))
340 return 1;
341
342 return INT_REGNO_P (REGNO (op)) || FP_REGNO_P (REGNO (op));
343 })
344
345 ;; Return 1 if op is a general purpose register. Unlike gpc_reg_operand, don't
346 ;; allow floating point or vector registers. Since vector registers are not
347 ;; allowed, we don't have to reject SFmode/SImode subregs.
348 (define_predicate "int_reg_operand"
349 (match_operand 0 "register_operand")
350 {
351 if (SUBREG_P (op))
352 {
353 if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
354 return 0;
355
356 op = SUBREG_REG (op);
357 }
358
359 if (!REG_P (op))
360 return 0;
361
362 if (!HARD_REGISTER_P (op))
363 return 1;
364
365 return INT_REGNO_P (REGNO (op));
366 })
367
368 ;; Like int_reg_operand, but don't return true for pseudo registers
369 ;; We don't have to check for SF SUBREGS because pseudo registers
370 ;; are not allowed, and SF SUBREGs are ok within GPR registers.
371 (define_predicate "int_reg_operand_not_pseudo"
372 (match_operand 0 "register_operand")
373 {
374 if (SUBREG_P (op))
375 op = SUBREG_REG (op);
376
377 if (!REG_P (op))
378 return 0;
379
380 if (!HARD_REGISTER_P (op))
381 return 0;
382
383 return INT_REGNO_P (REGNO (op));
384 })
385
386 ;; Like int_reg_operand, but only return true for base registers
387 (define_predicate "base_reg_operand"
388 (match_operand 0 "int_reg_operand")
389 {
390 if (SUBREG_P (op))
391 op = SUBREG_REG (op);
392
393 if (!REG_P (op))
394 return 0;
395
396 return (REGNO (op) != FIRST_GPR_REGNO);
397 })
398
399
400 ;; Return true if this is a traditional floating point register
401 (define_predicate "fpr_reg_operand"
402 (match_code "reg,subreg")
403 {
404 HOST_WIDE_INT r;
405
406 if (SUBREG_P (op))
407 op = SUBREG_REG (op);
408
409 if (!REG_P (op))
410 return 0;
411
412 r = REGNO (op);
413 if (!HARD_REGISTER_NUM_P (r))
414 return 1;
415
416 return FP_REGNO_P (r);
417 })
418
419 ;; Return 1 if op is a general purpose register that is an even register
420 ;; which suitable for a load/store quad operation
421 ;; Subregs are not allowed here because when they are combine can
422 ;; create (subreg:PTI (reg:TI pseudo)) which will cause reload to
423 ;; think the innermost reg needs reloading, in TImode instead of
424 ;; PTImode. So reload will choose a reg in TImode which has no
425 ;; requirement that the reg be even.
426 (define_predicate "quad_int_reg_operand"
427 (match_code "reg")
428 {
429 HOST_WIDE_INT r;
430
431 if (!TARGET_QUAD_MEMORY && !TARGET_QUAD_MEMORY_ATOMIC)
432 return 0;
433
434 r = REGNO (op);
435 if (!HARD_REGISTER_NUM_P (r))
436 return 1;
437
438 return (INT_REGNO_P (r) && ((r & 1) == 0));
439 })
440
441 ;; Return 1 if op is a register that is a condition register field.
442 (define_predicate "cc_reg_operand"
443 (match_operand 0 "register_operand")
444 {
445 if (SUBREG_P (op))
446 op = SUBREG_REG (op);
447
448 if (!REG_P (op))
449 return 0;
450
451 if (REGNO (op) > LAST_VIRTUAL_REGISTER)
452 return 1;
453
454 return CR_REGNO_P (REGNO (op));
455 })
456
457 ;; Return 1 if op is a register that is a condition register field not cr0.
458 (define_predicate "cc_reg_not_cr0_operand"
459 (match_operand 0 "register_operand")
460 {
461 if (SUBREG_P (op))
462 op = SUBREG_REG (op);
463
464 if (!REG_P (op))
465 return 0;
466
467 if (REGNO (op) > LAST_VIRTUAL_REGISTER)
468 return 1;
469
470 return CR_REGNO_NOT_CR0_P (REGNO (op));
471 })
472
473 ;; Return 1 if op is a constant integer valid for D field
474 ;; or non-special register register.
475 (define_predicate "reg_or_short_operand"
476 (if_then_else (match_code "const_int")
477 (match_operand 0 "short_cint_operand")
478 (match_operand 0 "gpc_reg_operand")))
479
480 ;; Return 1 if op is a constant integer valid for DS field
481 ;; or non-special register.
482 (define_predicate "reg_or_aligned_short_operand"
483 (if_then_else (match_code "const_int")
484 (and (match_operand 0 "short_cint_operand")
485 (match_test "!(INTVAL (op) & 3)"))
486 (match_operand 0 "gpc_reg_operand")))
487
488 ;; Return 1 if op is a constant integer whose high-order 16 bits are zero
489 ;; or non-special register.
490 (define_predicate "reg_or_u_short_operand"
491 (if_then_else (match_code "const_int")
492 (match_operand 0 "u_short_cint_operand")
493 (match_operand 0 "gpc_reg_operand")))
494
495 ;; Return 1 if op is any constant integer or a non-special register.
496 (define_predicate "reg_or_cint_operand"
497 (ior (match_code "const_int")
498 (match_operand 0 "gpc_reg_operand")))
499
500 ;; Return 1 if op is constant zero or a non-special register.
501 (define_predicate "reg_or_zero_operand"
502 (ior (match_operand 0 "zero_constant")
503 (match_operand 0 "gpc_reg_operand")))
504
505 ;; Return 1 if op is a constant integer valid for addition with addis, addi.
506 (define_predicate "add_cint_operand"
507 (and (match_code "const_int")
508 (match_test "((unsigned HOST_WIDE_INT) INTVAL (op)
509 + (mode == SImode ? 0x80000000 : 0x80008000))
510 < (unsigned HOST_WIDE_INT) 0x100000000ll")))
511
512 ;; Return 1 if op is a constant integer valid for addition
513 ;; or non-special register.
514 (define_predicate "reg_or_add_cint_operand"
515 (if_then_else (match_code "const_int")
516 (match_operand 0 "add_cint_operand")
517 (match_operand 0 "gpc_reg_operand")))
518
519 ;; Return 1 if op is a constant integer valid for subtraction
520 ;; or non-special register.
521 (define_predicate "reg_or_sub_cint_operand"
522 (if_then_else (match_code "const_int")
523 (match_test "(unsigned HOST_WIDE_INT)
524 (- UINTVAL (op) + (mode == SImode ? 0x80000000 : 0x80008000))
525 < (unsigned HOST_WIDE_INT) 0x100000000ll")
526 (match_operand 0 "gpc_reg_operand")))
527
528 ;; Return 1 if op is any 32-bit unsigned constant integer
529 ;; or non-special register.
530 (define_predicate "reg_or_logical_cint_operand"
531 (if_then_else (match_code "const_int")
532 (match_test "(GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT
533 && INTVAL (op) >= 0)
534 || ((INTVAL (op) & GET_MODE_MASK (mode)
535 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0)")
536 (match_operand 0 "gpc_reg_operand")))
537
538 ;; Like reg_or_logical_cint_operand, but allow vsx registers
539 (define_predicate "vsx_reg_or_cint_operand"
540 (ior (match_operand 0 "vsx_register_operand")
541 (match_operand 0 "reg_or_logical_cint_operand")))
542
543 ;; Return 1 if operand is a CONST_DOUBLE that can be set in a register
544 ;; with no more than one instruction per word.
545 (define_predicate "easy_fp_constant"
546 (match_code "const_double")
547 {
548 gcc_assert (GET_MODE (op) == mode && SCALAR_FLOAT_MODE_P (mode));
549
550 /* Consider all constants with -msoft-float to be easy when regs are
551 32-bit and thus can be loaded with a maximum of 2 insns. For
552 64-bit avoid long dependent insn sequences. */
553 if (TARGET_SOFT_FLOAT)
554 {
555 if (!TARGET_POWERPC64)
556 return 1;
557
558 int size = GET_MODE_SIZE (mode);
559 if (size < 8)
560 return 1;
561
562 int load_from_mem_insns = 2;
563 if (size > 8)
564 load_from_mem_insns++;
565 if (TARGET_CMODEL != CMODEL_SMALL)
566 load_from_mem_insns++;
567 if (num_insns_constant (op, mode) <= load_from_mem_insns)
568 return 1;
569 }
570
571 /* 0.0D is not all zero bits. */
572 if (DECIMAL_FLOAT_MODE_P (mode))
573 return 0;
574
575 /* The constant 0.0 is easy under VSX. */
576 if (TARGET_VSX && op == CONST0_RTX (mode))
577 return 1;
578
579 /* Otherwise consider floating point constants hard, so that the
580 constant gets pushed to memory during the early RTL phases. This
581 has the advantage that double precision constants that can be
582 represented in single precision without a loss of precision will
583 use single precision loads. */
584 return 0;
585 })
586
587 ;; Return 1 if the operand is a constant that can loaded with a XXSPLTIB
588 ;; instruction and then a VUPKHSB, VECSB2W or VECSB2D instruction.
589
590 (define_predicate "xxspltib_constant_split"
591 (match_code "const_vector,vec_duplicate,const_int")
592 {
593 int value = 256;
594 int num_insns = -1;
595
596 if (!xxspltib_constant_p (op, mode, &num_insns, &value))
597 return false;
598
599 return num_insns > 1;
600 })
601
602
603 ;; Return 1 if the operand is constant that can loaded directly with a XXSPLTIB
604 ;; instruction.
605
606 (define_predicate "xxspltib_constant_nosplit"
607 (match_code "const_vector,vec_duplicate,const_int")
608 {
609 int value = 256;
610 int num_insns = -1;
611
612 if (!xxspltib_constant_p (op, mode, &num_insns, &value))
613 return false;
614
615 return num_insns == 1;
616 })
617
618 ;; Return 1 if the operand is a CONST_VECTOR and can be loaded into a
619 ;; vector register without using memory.
620 (define_predicate "easy_vector_constant"
621 (match_code "const_vector")
622 {
623 if (VECTOR_MEM_ALTIVEC_OR_VSX_P (mode))
624 {
625 int value = 256;
626 int num_insns = -1;
627
628 if (zero_constant (op, mode) || all_ones_constant (op, mode))
629 return true;
630
631 if (TARGET_P9_VECTOR
632 && xxspltib_constant_p (op, mode, &num_insns, &value))
633 return true;
634
635 return easy_altivec_constant (op, mode);
636 }
637
638 return false;
639 })
640
641 ;; Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF.
642 (define_predicate "easy_vector_constant_add_self"
643 (and (match_code "const_vector")
644 (and (match_test "TARGET_ALTIVEC")
645 (match_test "easy_altivec_constant (op, mode)")))
646 {
647 HOST_WIDE_INT val;
648 int elt;
649 if (mode == V2DImode || mode == V2DFmode)
650 return 0;
651 elt = BYTES_BIG_ENDIAN ? GET_MODE_NUNITS (mode) - 1 : 0;
652 val = const_vector_elt_as_int (op, elt);
653 val = ((val & 0xff) ^ 0x80) - 0x80;
654 return EASY_VECTOR_15_ADD_SELF (val);
655 })
656
657 ;; Same as easy_vector_constant but only for EASY_VECTOR_MSB.
658 (define_predicate "easy_vector_constant_msb"
659 (and (match_code "const_vector")
660 (and (match_test "TARGET_ALTIVEC")
661 (match_test "easy_altivec_constant (op, mode)")))
662 {
663 HOST_WIDE_INT val;
664 int elt;
665 if (mode == V2DImode || mode == V2DFmode)
666 return 0;
667 elt = BYTES_BIG_ENDIAN ? GET_MODE_NUNITS (mode) - 1 : 0;
668 val = const_vector_elt_as_int (op, elt);
669 return EASY_VECTOR_MSB (val, GET_MODE_INNER (mode));
670 })
671
672 ;; Return true if this is an easy altivec constant that we form
673 ;; by using VSLDOI.
674 (define_predicate "easy_vector_constant_vsldoi"
675 (and (match_code "const_vector")
676 (and (match_test "TARGET_ALTIVEC")
677 (and (match_test "easy_altivec_constant (op, mode)")
678 (match_test "vspltis_shifted (op) != 0")))))
679
680 ;; Return 1 if operand is a vector int register or is either a vector constant
681 ;; of all 0 bits of a vector constant of all 1 bits.
682 (define_predicate "vector_int_reg_or_same_bit"
683 (match_code "reg,subreg,const_vector")
684 {
685 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
686 return 0;
687
688 else if (REG_P (op) || SUBREG_P (op))
689 return vint_operand (op, mode);
690
691 else
692 return op == CONST0_RTX (mode) || op == CONSTM1_RTX (mode);
693 })
694
695 ;; Return 1 if operand is 0.0.
696 (define_predicate "zero_fp_constant"
697 (and (match_code "const_double")
698 (match_test "SCALAR_FLOAT_MODE_P (mode)
699 && op == CONST0_RTX (mode)")))
700
701 ;; Return 1 if the operand is in volatile memory. Note that during the
702 ;; RTL generation phase, memory_operand does not return TRUE for volatile
703 ;; memory references. So this function allows us to recognize volatile
704 ;; references where it's safe.
705 (define_predicate "volatile_mem_operand"
706 (and (and (match_code "mem")
707 (match_test "MEM_VOLATILE_P (op)"))
708 (if_then_else (match_test "reload_completed")
709 (match_operand 0 "memory_operand")
710 (match_test "memory_address_p (mode, XEXP (op, 0))"))))
711
712 ;; Return 1 if the operand is an offsettable memory operand.
713 (define_predicate "offsettable_mem_operand"
714 (and (match_operand 0 "memory_operand")
715 (match_test "offsettable_nonstrict_memref_p (op)")))
716
717 ;; Return 1 if the operand is a simple offsettable memory operand
718 ;; that does not include pre-increment, post-increment, etc.
719 (define_predicate "simple_offsettable_mem_operand"
720 (match_operand 0 "offsettable_mem_operand")
721 {
722 rtx addr = XEXP (op, 0);
723
724 if (GET_CODE (addr) != PLUS && GET_CODE (addr) != LO_SUM)
725 return 0;
726
727 if (!CONSTANT_P (XEXP (addr, 1)))
728 return 0;
729
730 return base_reg_operand (XEXP (addr, 0), Pmode);
731 })
732
733 ;; Return 1 if the operand is suitable for load/store quad memory.
734 ;; This predicate only checks for non-atomic loads/stores (not lqarx/stqcx).
735 (define_predicate "quad_memory_operand"
736 (match_code "mem")
737 {
738 if (!TARGET_QUAD_MEMORY && !TARGET_SYNC_TI)
739 return false;
740
741 if (GET_MODE_SIZE (mode) != 16 || !MEM_P (op) || MEM_ALIGN (op) < 128)
742 return false;
743
744 return quad_address_p (XEXP (op, 0), mode, false);
745 })
746
747 ;; Return 1 if the operand is suitable for load/store to vector registers with
748 ;; d-form addressing (register+offset), which was added in ISA 3.0.
749 ;; Unlike quad_memory_operand, we do not have to check for alignment.
750 (define_predicate "vsx_quad_dform_memory_operand"
751 (match_code "mem")
752 {
753 if (!TARGET_P9_VECTOR || !MEM_P (op) || GET_MODE_SIZE (mode) != 16)
754 return false;
755
756 return quad_address_p (XEXP (op, 0), mode, false);
757 })
758
759 ;; Return 1 if the operand is an indexed or indirect memory operand.
760 (define_predicate "indexed_or_indirect_operand"
761 (match_code "mem")
762 {
763 op = XEXP (op, 0);
764 if (VECTOR_MEM_ALTIVEC_P (mode)
765 && GET_CODE (op) == AND
766 && CONST_INT_P (XEXP (op, 1))
767 && INTVAL (XEXP (op, 1)) == -16)
768 op = XEXP (op, 0);
769
770 return indexed_or_indirect_address (op, mode);
771 })
772
773 ;; Like indexed_or_indirect_operand, but also allow a GPR register if direct
774 ;; moves are supported.
775 (define_predicate "reg_or_indexed_operand"
776 (match_code "mem,reg,subreg")
777 {
778 if (MEM_P (op))
779 return indexed_or_indirect_operand (op, mode);
780 else if (TARGET_DIRECT_MOVE)
781 return register_operand (op, mode);
782 return
783 0;
784 })
785
786 ;; Return 1 if the operand is an indexed or indirect memory operand with an
787 ;; AND -16 in it, used to recognize when we need to switch to Altivec loads
788 ;; to realign loops instead of VSX (altivec silently ignores the bottom bits,
789 ;; while VSX uses the full address and traps)
790 (define_predicate "altivec_indexed_or_indirect_operand"
791 (match_code "mem")
792 {
793 op = XEXP (op, 0);
794 if (VECTOR_MEM_ALTIVEC_OR_VSX_P (mode)
795 && GET_CODE (op) == AND
796 && CONST_INT_P (XEXP (op, 1))
797 && INTVAL (XEXP (op, 1)) == -16)
798 return indexed_or_indirect_address (XEXP (op, 0), mode);
799
800 return 0;
801 })
802
803 ;; Return 1 if the operand is an indexed or indirect address.
804 (define_special_predicate "indexed_or_indirect_address"
805 (and (match_test "REG_P (op)
806 || (GET_CODE (op) == PLUS
807 /* Omit testing REG_P (XEXP (op, 0)). */
808 && REG_P (XEXP (op, 1)))")
809 (match_operand 0 "address_operand")))
810
811 ;; Return 1 if the operand is an index-form address.
812 (define_special_predicate "indexed_address"
813 (match_test "(GET_CODE (op) == PLUS
814 && REG_P (XEXP (op, 0))
815 && REG_P (XEXP (op, 1)))"))
816
817 ;; Return 1 if the operand is a MEM with an update-form address. This may
818 ;; also include update-indexed form.
819 (define_special_predicate "update_address_mem"
820 (match_test "(MEM_P (op)
821 && (GET_CODE (XEXP (op, 0)) == PRE_INC
822 || GET_CODE (XEXP (op, 0)) == PRE_DEC
823 || GET_CODE (XEXP (op, 0)) == PRE_MODIFY))"))
824
825 ;; Return 1 if the operand is a MEM with an indexed-form address.
826 (define_special_predicate "indexed_address_mem"
827 (match_test "(MEM_P (op)
828 && (indexed_address (XEXP (op, 0), mode)
829 || (GET_CODE (XEXP (op, 0)) == PRE_MODIFY
830 && indexed_address (XEXP (XEXP (op, 0), 1), mode))))"))
831
832 ;; Return 1 if the operand is either a non-special register or can be used
833 ;; as the operand of a `mode' add insn.
834 (define_predicate "add_operand"
835 (if_then_else (match_code "const_int")
836 (match_test "satisfies_constraint_I (op)
837 || satisfies_constraint_L (op)")
838 (match_operand 0 "gpc_reg_operand")))
839
840 ;; Return 1 if the operand is either a non-special register, or 0, or -1.
841 (define_predicate "adde_operand"
842 (if_then_else (match_code "const_int")
843 (match_test "INTVAL (op) == 0 || INTVAL (op) == -1")
844 (match_operand 0 "gpc_reg_operand")))
845
846 ;; Return 1 if OP is a constant but not a valid add_operand.
847 (define_predicate "non_add_cint_operand"
848 (and (match_code "const_int")
849 (match_test "!satisfies_constraint_I (op)
850 && !satisfies_constraint_L (op)")))
851
852 ;; Return 1 if the operand is a constant that can be used as the operand
853 ;; of an AND, OR or XOR.
854 (define_predicate "logical_const_operand"
855 (match_code "const_int")
856 {
857 HOST_WIDE_INT opl;
858
859 opl = INTVAL (op) & GET_MODE_MASK (mode);
860
861 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
862 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
863 })
864
865 ;; Return 1 if the operand is a non-special register or a constant that
866 ;; can be used as the operand of an AND, OR or XOR.
867 (define_predicate "logical_operand"
868 (ior (match_operand 0 "gpc_reg_operand")
869 (match_operand 0 "logical_const_operand")))
870
871 ;; Return 1 if op is a constant that is not a logical operand, but could
872 ;; be split into one.
873 (define_predicate "non_logical_cint_operand"
874 (and (match_code "const_int,const_wide_int")
875 (and (not (match_operand 0 "logical_operand"))
876 (match_operand 0 "reg_or_logical_cint_operand"))))
877
878 ;; Return 1 if the operand is either a non-special register or a
879 ;; constant that can be used as the operand of a logical AND.
880 (define_predicate "and_operand"
881 (ior (and (match_code "const_int")
882 (match_test "rs6000_is_valid_and_mask (op, mode)"))
883 (if_then_else (match_test "fixed_regs[CR0_REGNO]")
884 (match_operand 0 "gpc_reg_operand")
885 (match_operand 0 "logical_operand"))))
886
887 ;; Return 1 if the operand is either a logical operand or a short cint operand.
888 (define_predicate "scc_eq_operand"
889 (ior (match_operand 0 "logical_operand")
890 (match_operand 0 "short_cint_operand")))
891
892 ;; Return 1 if the operand is a general non-special register or memory operand.
893 (define_predicate "reg_or_mem_operand"
894 (ior (match_operand 0 "memory_operand")
895 (and (match_code "mem")
896 (match_test "macho_lo_sum_memory_operand (op, mode)"))
897 (match_operand 0 "volatile_mem_operand")
898 (match_operand 0 "gpc_reg_operand")))
899
900 ;; Return 1 if the operand is CONST_DOUBLE 0, register or memory operand.
901 (define_predicate "zero_reg_mem_operand"
902 (ior (and (match_test "TARGET_VSX")
903 (match_operand 0 "zero_fp_constant"))
904 (match_operand 0 "reg_or_mem_operand")))
905
906 ;; Return 1 if the operand is a CONST_INT and it is the element for 64-bit
907 ;; data types inside of a vector that scalar instructions operate on
908 (define_predicate "vsx_scalar_64bit"
909 (match_code "const_int")
910 {
911 return (INTVAL (op) == VECTOR_ELEMENT_SCALAR_64BIT);
912 })
913
914 ;; Return 1 if the operand is a general register or memory operand without
915 ;; pre_inc or pre_dec or pre_modify, which produces invalid form of PowerPC
916 ;; lwa instruction.
917 (define_predicate "lwa_operand"
918 (match_code "reg,subreg,mem")
919 {
920 rtx inner, addr, offset;
921
922 inner = op;
923 if (reload_completed && SUBREG_P (inner))
924 inner = SUBREG_REG (inner);
925
926 if (gpc_reg_operand (inner, mode))
927 return true;
928 if (!memory_operand (inner, mode))
929 return false;
930
931 addr = XEXP (inner, 0);
932 if (GET_CODE (addr) == PRE_INC
933 || GET_CODE (addr) == PRE_DEC
934 || (GET_CODE (addr) == PRE_MODIFY
935 && !legitimate_indexed_address_p (XEXP (addr, 1), 0)))
936 return false;
937 if (GET_CODE (addr) == LO_SUM
938 && REG_P (XEXP (addr, 0))
939 && GET_CODE (XEXP (addr, 1)) == CONST)
940 addr = XEXP (XEXP (addr, 1), 0);
941 if (GET_CODE (addr) != PLUS)
942 return true;
943 offset = XEXP (addr, 1);
944 if (!CONST_INT_P (offset))
945 return true;
946 return INTVAL (offset) % 4 == 0;
947 })
948
949 ;; Return 1 if the operand, used inside a MEM, is a SYMBOL_REF.
950 (define_predicate "symbol_ref_operand"
951 (and (match_code "symbol_ref")
952 (match_test "(mode == VOIDmode || GET_MODE (op) == mode)
953 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))")))
954
955 ;; Return 1 if op is an operand that can be loaded via the GOT.
956 ;; or non-special register register field no cr0
957 (define_predicate "got_operand"
958 (match_code "symbol_ref,const,label_ref"))
959
960 ;; Return 1 if op is a simple reference that can be loaded via the GOT,
961 ;; excluding labels involving addition.
962 (define_predicate "got_no_const_operand"
963 (match_code "symbol_ref,label_ref"))
964
965 ;; Return 1 if op is a SYMBOL_REF for a TLS symbol.
966 (define_predicate "rs6000_tls_symbol_ref"
967 (and (match_code "symbol_ref")
968 (match_test "RS6000_SYMBOL_REF_TLS_P (op)")))
969
970 ;; Return 1 for the CONST_INT or UNSPEC second CALL operand.
971 ;; Prevents unwanted substitution of the unspec got_reg arg.
972 (define_predicate "unspec_tls"
973 (match_code "const_int,unspec")
974 {
975 if (CONST_INT_P (op))
976 return 1;
977 if (XINT (op, 1) == UNSPEC_TLSGD)
978 return REG_P (XVECEXP (op, 0, 1));
979 if (XINT (op, 1) == UNSPEC_TLSLD)
980 return REG_P (XVECEXP (op, 0, 0));
981 return 0;
982 })
983
984 ;; Return 1 if the operand, used inside a MEM, is a valid first argument
985 ;; to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR.
986 (define_predicate "call_operand"
987 (if_then_else (match_code "reg")
988 (match_test "REGNO (op) == LR_REGNO
989 || REGNO (op) == CTR_REGNO
990 || !HARD_REGISTER_P (op)")
991 (match_code "symbol_ref")))
992
993 ;; Return 1 if the operand, used inside a MEM, is a valid first argument
994 ;; to an indirect CALL. This is LR, CTR, or a PLTSEQ unspec using CTR.
995 (define_predicate "indirect_call_operand"
996 (match_code "reg,unspec")
997 {
998 if (REG_P (op))
999 return (REGNO (op) == LR_REGNO
1000 || REGNO (op) == CTR_REGNO);
1001 if (GET_CODE (op) == UNSPEC)
1002 {
1003 if (XINT (op, 1) != UNSPEC_PLTSEQ)
1004 return false;
1005 op = XVECEXP (op, 0, 0);
1006 return REG_P (op) && REGNO (op) == CTR_REGNO;
1007 }
1008 return false;
1009 })
1010
1011 ;; Return 1 if the operand is a SYMBOL_REF for a function known to be in
1012 ;; this file.
1013 (define_predicate "current_file_function_operand"
1014 (and (match_code "symbol_ref")
1015 (match_test "(DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
1016 && (SYMBOL_REF_LOCAL_P (op)
1017 || (op == XEXP (DECL_RTL (current_function_decl), 0)
1018 && !decl_replaceable_p (current_function_decl)))
1019 && !((DEFAULT_ABI == ABI_AIX
1020 || DEFAULT_ABI == ABI_ELFv2)
1021 && (SYMBOL_REF_EXTERNAL_P (op)
1022 || SYMBOL_REF_WEAK (op)))")))
1023
1024 ;; Return 1 if this operand is a valid input for a move insn.
1025 (define_predicate "input_operand"
1026 (match_code "symbol_ref,const,reg,subreg,mem,
1027 const_double,const_wide_int,const_vector,const_int")
1028 {
1029 /* Memory is always valid. */
1030 if (memory_operand (op, mode))
1031 return 1;
1032
1033 /* For floating-point, easy constants are valid. */
1034 if (SCALAR_FLOAT_MODE_P (mode)
1035 && easy_fp_constant (op, mode))
1036 return 1;
1037
1038 /* Allow any integer constant. */
1039 if (GET_MODE_CLASS (mode) == MODE_INT
1040 && CONST_SCALAR_INT_P (op))
1041 return 1;
1042
1043 /* Allow easy vector constants. */
1044 if (GET_CODE (op) == CONST_VECTOR
1045 && easy_vector_constant (op, mode))
1046 return 1;
1047
1048 /* For floating-point or multi-word mode, the only remaining valid type
1049 is a register. */
1050 if (SCALAR_FLOAT_MODE_P (mode)
1051 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
1052 return register_operand (op, mode);
1053
1054 /* We don't allow moving the carry bit around. */
1055 if (ca_operand (op, mode))
1056 return 0;
1057
1058 /* The only cases left are integral modes one word or smaller (we
1059 do not get called for MODE_CC values). These can be in any
1060 register. */
1061 if (register_operand (op, mode))
1062 return 1;
1063
1064 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
1065 to be valid. */
1066 if (DEFAULT_ABI == ABI_V4
1067 && (SYMBOL_REF_P (op) || GET_CODE (op) == CONST)
1068 && small_data_operand (op, Pmode))
1069 return 1;
1070
1071 return 0;
1072 })
1073
1074 ;; Return 1 if this operand is a valid input for a vsx_splat insn.
1075 (define_predicate "splat_input_operand"
1076 (match_code "reg,subreg,mem")
1077 {
1078 machine_mode vmode;
1079
1080 if (mode == DFmode)
1081 vmode = V2DFmode;
1082 else if (mode == DImode)
1083 vmode = V2DImode;
1084 else if (mode == SImode && TARGET_P9_VECTOR)
1085 vmode = V4SImode;
1086 else if (mode == SFmode && TARGET_P9_VECTOR)
1087 vmode = V4SFmode;
1088 else
1089 return false;
1090
1091 if (MEM_P (op))
1092 {
1093 rtx addr = XEXP (op, 0);
1094
1095 if (! volatile_ok && MEM_VOLATILE_P (op))
1096 return 0;
1097
1098 if (lra_in_progress || reload_completed)
1099 return indexed_or_indirect_address (addr, vmode);
1100 else
1101 return memory_address_addr_space_p (vmode, addr, MEM_ADDR_SPACE (op));
1102 }
1103 return gpc_reg_operand (op, mode);
1104 })
1105
1106 ;; Return true if operand is an operator used in rotate-and-mask instructions.
1107 (define_predicate "rotate_mask_operator"
1108 (match_code "rotate,ashift,lshiftrt"))
1109
1110 ;; Return true if operand is boolean operator.
1111 (define_predicate "boolean_operator"
1112 (match_code "and,ior,xor"))
1113
1114 ;; Return true if operand is OR-form of boolean operator.
1115 (define_predicate "boolean_or_operator"
1116 (match_code "ior,xor"))
1117
1118 ;; Return true if operand is an equality operator.
1119 (define_special_predicate "equality_operator"
1120 (match_code "eq,ne"))
1121
1122 ;; Return 1 if OP is a comparison operation that is valid for a branch
1123 ;; instruction. We check the opcode against the mode of the CC value.
1124 ;; validate_condition_mode is an assertion.
1125 (define_predicate "branch_comparison_operator"
1126 (and (match_operand 0 "comparison_operator")
1127 (and (match_test "GET_MODE_CLASS (GET_MODE (XEXP (op, 0))) == MODE_CC")
1128 (match_test "validate_condition_mode (GET_CODE (op),
1129 GET_MODE (XEXP (op, 0))),
1130 1"))))
1131
1132 ;; Return 1 if OP is an unsigned comparison operator.
1133 (define_predicate "unsigned_comparison_operator"
1134 (match_code "ltu,gtu,leu,geu"))
1135
1136 ;; Return 1 if OP is a signed comparison operator.
1137 (define_predicate "signed_comparison_operator"
1138 (match_code "lt,gt,le,ge"))
1139
1140 ;; Return 1 if OP is a comparison operation that is valid for an SCC insn --
1141 ;; it must be a positive comparison.
1142 (define_predicate "scc_comparison_operator"
1143 (and (match_operand 0 "branch_comparison_operator")
1144 (match_code "eq,lt,gt,ltu,gtu,unordered")))
1145
1146 ;; Return 1 if OP is a comparison operation whose inverse would be valid for
1147 ;; an SCC insn.
1148 (define_predicate "scc_rev_comparison_operator"
1149 (and (match_operand 0 "branch_comparison_operator")
1150 (match_code "ne,le,ge,leu,geu,ordered")))
1151
1152 ;; Return 1 if OP is a comparison operator suitable for floating point
1153 ;; vector/scalar comparisons that generate a -1/0 mask.
1154 (define_predicate "fpmask_comparison_operator"
1155 (match_code "eq,gt,ge"))
1156
1157 ;; Return 1 if OP is a comparison operator suitable for vector/scalar
1158 ;; comparisons that generate a 0/-1 mask (i.e. the inverse of
1159 ;; fpmask_comparison_operator).
1160 (define_predicate "invert_fpmask_comparison_operator"
1161 (match_code "ne,unlt,unle"))
1162
1163 ;; Return 1 if OP is a comparison operation suitable for integer vector/scalar
1164 ;; comparisons that generate a -1/0 mask.
1165 (define_predicate "vecint_comparison_operator"
1166 (match_code "eq,gt,gtu"))
1167
1168 ;; Return 1 if OP is a comparison operation that is valid for a branch
1169 ;; insn, which is true if the corresponding bit in the CC register is set.
1170 (define_predicate "branch_positive_comparison_operator"
1171 (and (match_operand 0 "branch_comparison_operator")
1172 (match_code "eq,lt,gt,ltu,gtu,unordered")))
1173
1174 ;; Return 1 if OP is valid for a save_world call in prologue, known to be
1175 ;; a PARLLEL.
1176 (define_predicate "save_world_operation"
1177 (match_code "parallel")
1178 {
1179 int index;
1180 int i;
1181 rtx elt;
1182 int count = XVECLEN (op, 0);
1183
1184 if (count != 54)
1185 return 0;
1186
1187 index = 0;
1188 if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1189 || GET_CODE (XVECEXP (op, 0, index++)) != USE)
1190 return 0;
1191
1192 for (i=1; i <= 18; i++)
1193 {
1194 elt = XVECEXP (op, 0, index++);
1195 if (GET_CODE (elt) != SET
1196 || !MEM_P (SET_DEST (elt))
1197 || !memory_operand (SET_DEST (elt), DFmode)
1198 || !REG_P (SET_SRC (elt))
1199 || GET_MODE (SET_SRC (elt)) != DFmode)
1200 return 0;
1201 }
1202
1203 for (i=1; i <= 12; i++)
1204 {
1205 elt = XVECEXP (op, 0, index++);
1206 if (GET_CODE (elt) != SET
1207 || !MEM_P (SET_DEST (elt))
1208 || !REG_P (SET_SRC (elt))
1209 || GET_MODE (SET_SRC (elt)) != V4SImode)
1210 return 0;
1211 }
1212
1213 for (i=1; i <= 19; i++)
1214 {
1215 elt = XVECEXP (op, 0, index++);
1216 if (GET_CODE (elt) != SET
1217 || !MEM_P (SET_DEST (elt))
1218 || !memory_operand (SET_DEST (elt), Pmode)
1219 || !REG_P (SET_SRC (elt))
1220 || GET_MODE (SET_SRC (elt)) != Pmode)
1221 return 0;
1222 }
1223
1224 elt = XVECEXP (op, 0, index++);
1225 if (GET_CODE (elt) != SET
1226 || !MEM_P (SET_DEST (elt))
1227 || !memory_operand (SET_DEST (elt), Pmode)
1228 || !REG_P (SET_SRC (elt))
1229 || REGNO (SET_SRC (elt)) != CR2_REGNO
1230 || GET_MODE (SET_SRC (elt)) != Pmode)
1231 return 0;
1232
1233 if (GET_CODE (XVECEXP (op, 0, index++)) != SET
1234 || GET_CODE (XVECEXP (op, 0, index++)) != SET)
1235 return 0;
1236 return 1;
1237 })
1238
1239 ;; Return 1 if OP is valid for a restore_world call in epilogue, known to be
1240 ;; a PARLLEL.
1241 (define_predicate "restore_world_operation"
1242 (match_code "parallel")
1243 {
1244 int index;
1245 int i;
1246 rtx elt;
1247 int count = XVECLEN (op, 0);
1248
1249 if (count != 58)
1250 return 0;
1251
1252 index = 0;
1253 if (GET_CODE (XVECEXP (op, 0, index++)) != RETURN
1254 || GET_CODE (XVECEXP (op, 0, index++)) != USE
1255 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
1256 return 0;
1257
1258 elt = XVECEXP (op, 0, index++);
1259 if (GET_CODE (elt) != SET
1260 || !MEM_P (SET_SRC (elt))
1261 || !memory_operand (SET_SRC (elt), Pmode)
1262 || !REG_P (SET_DEST (elt))
1263 || REGNO (SET_DEST (elt)) != CR2_REGNO
1264 || GET_MODE (SET_DEST (elt)) != Pmode)
1265 return 0;
1266
1267 for (i=1; i <= 19; i++)
1268 {
1269 elt = XVECEXP (op, 0, index++);
1270 if (GET_CODE (elt) != SET
1271 || !MEM_P (SET_SRC (elt))
1272 || !memory_operand (SET_SRC (elt), Pmode)
1273 || !REG_P (SET_DEST (elt))
1274 || GET_MODE (SET_DEST (elt)) != Pmode)
1275 return 0;
1276 }
1277
1278 for (i=1; i <= 12; i++)
1279 {
1280 elt = XVECEXP (op, 0, index++);
1281 if (GET_CODE (elt) != SET
1282 || !MEM_P (SET_SRC (elt))
1283 || !REG_P (SET_DEST (elt))
1284 || GET_MODE (SET_DEST (elt)) != V4SImode)
1285 return 0;
1286 }
1287
1288 for (i=1; i <= 18; i++)
1289 {
1290 elt = XVECEXP (op, 0, index++);
1291 if (GET_CODE (elt) != SET
1292 || !MEM_P (SET_SRC (elt))
1293 || !memory_operand (SET_SRC (elt), DFmode)
1294 || !REG_P (SET_DEST (elt))
1295 || GET_MODE (SET_DEST (elt)) != DFmode)
1296 return 0;
1297 }
1298
1299 if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1300 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1301 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1302 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1303 || GET_CODE (XVECEXP (op, 0, index++)) != USE)
1304 return 0;
1305 return 1;
1306 })
1307
1308 ;; Return 1 if OP is valid for a vrsave call, known to be a PARALLEL.
1309 (define_predicate "vrsave_operation"
1310 (match_code "parallel")
1311 {
1312 int count = XVECLEN (op, 0);
1313 unsigned int dest_regno, src_regno;
1314 int i;
1315
1316 if (count <= 1
1317 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1318 || !REG_P (SET_DEST (XVECEXP (op, 0, 0)))
1319 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE
1320 || XINT (SET_SRC (XVECEXP (op, 0, 0)), 1) != UNSPECV_SET_VRSAVE)
1321 return 0;
1322
1323 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1324 src_regno = REGNO (XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 1));
1325
1326 if (dest_regno != VRSAVE_REGNO || src_regno != VRSAVE_REGNO)
1327 return 0;
1328
1329 for (i = 1; i < count; i++)
1330 {
1331 rtx elt = XVECEXP (op, 0, i);
1332
1333 if (GET_CODE (elt) != CLOBBER
1334 && GET_CODE (elt) != SET)
1335 return 0;
1336 }
1337
1338 return 1;
1339 })
1340
1341 ;; Return 1 if OP is valid for mfcr insn, known to be a PARALLEL.
1342 (define_predicate "mfcr_operation"
1343 (match_code "parallel")
1344 {
1345 int count = XVECLEN (op, 0);
1346 int i;
1347
1348 /* Perform a quick check so we don't blow up below. */
1349 if (count < 1
1350 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1351 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
1352 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
1353 return 0;
1354
1355 for (i = 0; i < count; i++)
1356 {
1357 rtx exp = XVECEXP (op, 0, i);
1358 rtx unspec;
1359 int maskval;
1360 rtx src_reg;
1361
1362 src_reg = XVECEXP (SET_SRC (exp), 0, 0);
1363
1364 if (!REG_P (src_reg)
1365 || GET_MODE (src_reg) != CCmode
1366 || ! CR_REGNO_P (REGNO (src_reg)))
1367 return 0;
1368
1369 if (GET_CODE (exp) != SET
1370 || !REG_P (SET_DEST (exp))
1371 || GET_MODE (SET_DEST (exp)) != SImode
1372 || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
1373 return 0;
1374 unspec = SET_SRC (exp);
1375 maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
1376
1377 if (GET_CODE (unspec) != UNSPEC
1378 || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
1379 || XVECLEN (unspec, 0) != 2
1380 || XVECEXP (unspec, 0, 0) != src_reg
1381 || !CONST_INT_P (XVECEXP (unspec, 0, 1))
1382 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
1383 return 0;
1384 }
1385 return 1;
1386 })
1387
1388 ;; Return 1 if OP is valid for mtcrf insn, known to be a PARALLEL.
1389 (define_predicate "mtcrf_operation"
1390 (match_code "parallel")
1391 {
1392 int count = XVECLEN (op, 0);
1393 int i;
1394 rtx src_reg;
1395
1396 /* Perform a quick check so we don't blow up below. */
1397 if (count < 1
1398 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1399 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
1400 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
1401 return 0;
1402 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
1403
1404 if (!REG_P (src_reg)
1405 || GET_MODE (src_reg) != SImode
1406 || ! INT_REGNO_P (REGNO (src_reg)))
1407 return 0;
1408
1409 for (i = 0; i < count; i++)
1410 {
1411 rtx exp = XVECEXP (op, 0, i);
1412 rtx unspec;
1413 int maskval;
1414
1415 if (GET_CODE (exp) != SET
1416 || !REG_P (SET_DEST (exp))
1417 || GET_MODE (SET_DEST (exp)) != CCmode
1418 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
1419 return 0;
1420 unspec = SET_SRC (exp);
1421 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
1422
1423 if (GET_CODE (unspec) != UNSPEC
1424 || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
1425 || XVECLEN (unspec, 0) != 2
1426 || XVECEXP (unspec, 0, 0) != src_reg
1427 || !CONST_INT_P (XVECEXP (unspec, 0, 1))
1428 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
1429 return 0;
1430 }
1431 return 1;
1432 })
1433
1434 ;; Return 1 if OP is valid for crsave insn, known to be a PARALLEL.
1435 (define_predicate "crsave_operation"
1436 (match_code "parallel")
1437 {
1438 int count = XVECLEN (op, 0);
1439 int i;
1440
1441 for (i = 1; i < count; i++)
1442 {
1443 rtx exp = XVECEXP (op, 0, i);
1444
1445 if (GET_CODE (exp) != USE
1446 || !REG_P (XEXP (exp, 0))
1447 || GET_MODE (XEXP (exp, 0)) != CCmode
1448 || ! CR_REGNO_P (REGNO (XEXP (exp, 0))))
1449 return 0;
1450 }
1451 return 1;
1452 })
1453
1454 ;; Return 1 if OP is valid for lmw insn, known to be a PARALLEL.
1455 (define_predicate "lmw_operation"
1456 (match_code "parallel")
1457 {
1458 int count = XVECLEN (op, 0);
1459 unsigned int dest_regno;
1460 rtx src_addr;
1461 unsigned int base_regno;
1462 HOST_WIDE_INT offset;
1463 int i;
1464
1465 /* Perform a quick check so we don't blow up below. */
1466 if (count <= 1
1467 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1468 || !REG_P (SET_DEST (XVECEXP (op, 0, 0)))
1469 || !MEM_P (SET_SRC (XVECEXP (op, 0, 0))))
1470 return 0;
1471
1472 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1473 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
1474
1475 if (dest_regno > 31
1476 || count != 32 - (int) dest_regno)
1477 return 0;
1478
1479 if (legitimate_indirect_address_p (src_addr, 0))
1480 {
1481 offset = 0;
1482 base_regno = REGNO (src_addr);
1483 if (base_regno == 0)
1484 return 0;
1485 }
1486 else if (rs6000_legitimate_offset_address_p (SImode, src_addr, false, false))
1487 {
1488 offset = INTVAL (XEXP (src_addr, 1));
1489 base_regno = REGNO (XEXP (src_addr, 0));
1490 }
1491 else
1492 return 0;
1493
1494 for (i = 0; i < count; i++)
1495 {
1496 rtx elt = XVECEXP (op, 0, i);
1497 rtx newaddr;
1498 rtx addr_reg;
1499 HOST_WIDE_INT newoffset;
1500
1501 if (GET_CODE (elt) != SET
1502 || !REG_P (SET_DEST (elt))
1503 || GET_MODE (SET_DEST (elt)) != SImode
1504 || REGNO (SET_DEST (elt)) != dest_regno + i
1505 || !MEM_P (SET_SRC (elt))
1506 || GET_MODE (SET_SRC (elt)) != SImode)
1507 return 0;
1508 newaddr = XEXP (SET_SRC (elt), 0);
1509 if (legitimate_indirect_address_p (newaddr, 0))
1510 {
1511 newoffset = 0;
1512 addr_reg = newaddr;
1513 }
1514 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, false, false))
1515 {
1516 addr_reg = XEXP (newaddr, 0);
1517 newoffset = INTVAL (XEXP (newaddr, 1));
1518 }
1519 else
1520 return 0;
1521 if (REGNO (addr_reg) != base_regno
1522 || newoffset != offset + 4 * i)
1523 return 0;
1524 }
1525
1526 return 1;
1527 })
1528
1529 ;; Return 1 if OP is valid for stmw insn, known to be a PARALLEL.
1530 (define_predicate "stmw_operation"
1531 (match_code "parallel")
1532 {
1533 int count = XVECLEN (op, 0);
1534 unsigned int src_regno;
1535 rtx dest_addr;
1536 unsigned int base_regno;
1537 HOST_WIDE_INT offset;
1538 int i;
1539
1540 /* Perform a quick check so we don't blow up below. */
1541 if (count <= 1
1542 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1543 || !MEM_P (SET_DEST (XVECEXP (op, 0, 0)))
1544 || !REG_P (SET_SRC (XVECEXP (op, 0, 0))))
1545 return 0;
1546
1547 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
1548 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
1549
1550 if (src_regno > 31
1551 || count != 32 - (int) src_regno)
1552 return 0;
1553
1554 if (legitimate_indirect_address_p (dest_addr, 0))
1555 {
1556 offset = 0;
1557 base_regno = REGNO (dest_addr);
1558 if (base_regno == 0)
1559 return 0;
1560 }
1561 else if (rs6000_legitimate_offset_address_p (SImode, dest_addr, false, false))
1562 {
1563 offset = INTVAL (XEXP (dest_addr, 1));
1564 base_regno = REGNO (XEXP (dest_addr, 0));
1565 }
1566 else
1567 return 0;
1568
1569 for (i = 0; i < count; i++)
1570 {
1571 rtx elt = XVECEXP (op, 0, i);
1572 rtx newaddr;
1573 rtx addr_reg;
1574 HOST_WIDE_INT newoffset;
1575
1576 if (GET_CODE (elt) != SET
1577 || !REG_P (SET_SRC (elt))
1578 || GET_MODE (SET_SRC (elt)) != SImode
1579 || REGNO (SET_SRC (elt)) != src_regno + i
1580 || !MEM_P (SET_DEST (elt))
1581 || GET_MODE (SET_DEST (elt)) != SImode)
1582 return 0;
1583 newaddr = XEXP (SET_DEST (elt), 0);
1584 if (legitimate_indirect_address_p (newaddr, 0))
1585 {
1586 newoffset = 0;
1587 addr_reg = newaddr;
1588 }
1589 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, false, false))
1590 {
1591 addr_reg = XEXP (newaddr, 0);
1592 newoffset = INTVAL (XEXP (newaddr, 1));
1593 }
1594 else
1595 return 0;
1596 if (REGNO (addr_reg) != base_regno
1597 || newoffset != offset + 4 * i)
1598 return 0;
1599 }
1600
1601 return 1;
1602 })
1603
1604 ;; Return 1 if OP is a stack tie operand.
1605 (define_predicate "tie_operand"
1606 (match_code "parallel")
1607 {
1608 return (GET_CODE (XVECEXP (op, 0, 0)) == SET
1609 && MEM_P (XEXP (XVECEXP (op, 0, 0), 0))
1610 && GET_MODE (XEXP (XVECEXP (op, 0, 0), 0)) == BLKmode
1611 && XEXP (XVECEXP (op, 0, 0), 1) == const0_rtx);
1612 })
1613
1614 ;; Match a small code model toc reference (or medium and large
1615 ;; model toc references before reload).
1616 (define_predicate "small_toc_ref"
1617 (match_code "unspec,plus")
1618 {
1619 if (GET_CODE (op) == PLUS && add_cint_operand (XEXP (op, 1), mode))
1620 op = XEXP (op, 0);
1621
1622 return GET_CODE (op) == UNSPEC && XINT (op, 1) == UNSPEC_TOCREL;
1623 })
1624
1625 ;; Match the first insn (addis) in fusing the combination of addis and loads to
1626 ;; GPR registers on power8.
1627 (define_predicate "fusion_gpr_addis"
1628 (match_code "const_int,high,plus")
1629 {
1630 HOST_WIDE_INT value;
1631 rtx int_const;
1632
1633 if (GET_CODE (op) == HIGH)
1634 return 1;
1635
1636 if (CONST_INT_P (op))
1637 int_const = op;
1638
1639 else if (GET_CODE (op) == PLUS
1640 && base_reg_operand (XEXP (op, 0), Pmode)
1641 && CONST_INT_P (XEXP (op, 1)))
1642 int_const = XEXP (op, 1);
1643
1644 else
1645 return 0;
1646
1647 value = INTVAL (int_const);
1648 if ((value & (HOST_WIDE_INT)0xffff) != 0)
1649 return 0;
1650
1651 if ((value & (HOST_WIDE_INT)0xffff0000) == 0)
1652 return 0;
1653
1654 /* Power8 only does the fusion if the top 12 bits of the addis value are all
1655 1's or 0's. */
1656 return (IN_RANGE (value >> 16, -16, 15));
1657 })
1658
1659 ;; Match the second insn (lbz, lhz, lwz, ld) in fusing the combination of addis
1660 ;; and loads to GPR registers on power8.
1661 (define_predicate "fusion_gpr_mem_load"
1662 (match_code "mem,sign_extend,zero_extend")
1663 {
1664 rtx addr, base, offset;
1665
1666 /* Handle sign/zero extend. */
1667 if (GET_CODE (op) == ZERO_EXTEND
1668 || (TARGET_P8_FUSION_SIGN && GET_CODE (op) == SIGN_EXTEND))
1669 {
1670 op = XEXP (op, 0);
1671 mode = GET_MODE (op);
1672 }
1673
1674 if (!MEM_P (op))
1675 return 0;
1676
1677 switch (mode)
1678 {
1679 case E_QImode:
1680 case E_HImode:
1681 case E_SImode:
1682 break;
1683
1684 case E_DImode:
1685 if (!TARGET_POWERPC64)
1686 return 0;
1687 break;
1688
1689 /* Do not allow SF/DFmode in GPR fusion. While the loads do occur, they
1690 are not common. */
1691 default:
1692 return 0;
1693 }
1694
1695 addr = XEXP (op, 0);
1696 if (GET_CODE (addr) != PLUS && GET_CODE (addr) != LO_SUM)
1697 return 0;
1698
1699 base = XEXP (addr, 0);
1700 if (!base_reg_operand (base, GET_MODE (base)))
1701 return 0;
1702
1703 offset = XEXP (addr, 1);
1704
1705 if (GET_CODE (addr) == PLUS)
1706 return satisfies_constraint_I (offset);
1707
1708 else if (GET_CODE (addr) == LO_SUM)
1709 {
1710 if (TARGET_XCOFF || (TARGET_ELF && TARGET_POWERPC64))
1711 return small_toc_ref (offset, GET_MODE (offset));
1712
1713 else if (TARGET_ELF && !TARGET_POWERPC64)
1714 return CONSTANT_P (offset);
1715 }
1716
1717 return 0;
1718 })
1719
1720 ;; Match a GPR load (lbz, lhz, lwz, ld) that uses a combined address in the
1721 ;; memory field with both the addis and the memory offset. Sign extension
1722 ;; is not handled here, since lha and lwa are not fused.
1723 (define_predicate "fusion_addis_mem_combo_load"
1724 (match_code "mem,zero_extend")
1725 {
1726 rtx addr, base, offset;
1727
1728 /* Handle zero extend. */
1729 if (GET_CODE (op) == ZERO_EXTEND)
1730 {
1731 op = XEXP (op, 0);
1732 mode = GET_MODE (op);
1733 }
1734
1735 if (!MEM_P (op))
1736 return 0;
1737
1738 switch (mode)
1739 {
1740 case E_QImode:
1741 case E_HImode:
1742 case E_SImode:
1743 break;
1744
1745 /* Do not fuse 64-bit DImode in 32-bit since it splits into two
1746 separate instructions. */
1747 case E_DImode:
1748 if (!TARGET_POWERPC64)
1749 return 0;
1750 break;
1751
1752 /* Do not allow SF/DFmode in GPR fusion. While the loads do occur, they
1753 are not common. */
1754 default:
1755 return 0;
1756 }
1757
1758 addr = XEXP (op, 0);
1759 if (GET_CODE (addr) != PLUS && GET_CODE (addr) != LO_SUM)
1760 return 0;
1761
1762 base = XEXP (addr, 0);
1763 if (!fusion_gpr_addis (base, GET_MODE (base)))
1764 return 0;
1765
1766 offset = XEXP (addr, 1);
1767 if (GET_CODE (addr) == PLUS)
1768 return satisfies_constraint_I (offset);
1769
1770 else if (GET_CODE (addr) == LO_SUM)
1771 {
1772 if (TARGET_XCOFF || (TARGET_ELF && TARGET_POWERPC64))
1773 return small_toc_ref (offset, GET_MODE (offset));
1774
1775 else if (TARGET_ELF && !TARGET_POWERPC64)
1776 return CONSTANT_P (offset);
1777 }
1778
1779 return 0;
1780 })
This page took 0.1143 seconds and 6 git commands to generate.