comparison gcc/config/rs6000/predicates.md @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 ;; Predicate definitions for POWER and PowerPC. 1 ;; Predicate definitions for POWER and PowerPC.
2 ;; Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 2 ;; Copyright (C) 2005-2017 Free Software Foundation, Inc.
3 ;; Free Software Foundation, Inc.
4 ;; 3 ;;
5 ;; This file is part of GCC. 4 ;; This file is part of GCC.
6 ;; 5 ;;
7 ;; GCC is free software; you can redistribute it and/or modify 6 ;; GCC is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by 7 ;; it under the terms of the GNU General Public License as published by
18 ;; along with GCC; see the file COPYING3. If not see 17 ;; along with GCC; see the file COPYING3. If not see
19 ;; <http://www.gnu.org/licenses/>. 18 ;; <http://www.gnu.org/licenses/>.
20 19
21 ;; Return 1 for anything except PARALLEL. 20 ;; Return 1 for anything except PARALLEL.
22 (define_predicate "any_operand" 21 (define_predicate "any_operand"
23 (match_code "const_int,const_double,const,symbol_ref,label_ref,subreg,reg,mem")) 22 (match_code "const_int,const_double,const_wide_int,const,symbol_ref,label_ref,subreg,reg,mem"))
24 23
25 ;; Return 1 for any PARALLEL. 24 ;; Return 1 for any PARALLEL.
26 (define_predicate "any_parallel_operand" 25 (define_predicate "any_parallel_operand"
27 (match_code "parallel")) 26 (match_code "parallel"))
28 27
29 ;; Return 1 if op is COUNT register. 28 ;; Return 1 if op is COUNT register.
30 (define_predicate "count_register_operand" 29 (define_predicate "count_register_operand"
31 (and (match_code "reg") 30 (and (match_code "reg")
32 (match_test "REGNO (op) == CTR_REGNO 31 (match_test "REGNO (op) == CTR_REGNO
33 || REGNO (op) > LAST_VIRTUAL_REGISTER"))) 32 || REGNO (op) > LAST_VIRTUAL_REGISTER")))
34 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
35 ;; Return 1 if op is an Altivec register. 64 ;; Return 1 if op is an Altivec register.
36 (define_predicate "altivec_register_operand" 65 (define_predicate "altivec_register_operand"
37 (and (match_operand 0 "register_operand") 66 (match_operand 0 "register_operand")
38 (match_test "GET_CODE (op) != REG 67 {
39 || ALTIVEC_REGNO_P (REGNO (op)) 68 if (GET_CODE (op) == SUBREG)
40 || REGNO (op) > LAST_VIRTUAL_REGISTER"))) 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 (REGNO (op) >= FIRST_PSEUDO_REGISTER)
80 return 1;
81
82 return ALTIVEC_REGNO_P (REGNO (op));
83 })
41 84
42 ;; Return 1 if op is a VSX register. 85 ;; Return 1 if op is a VSX register.
43 (define_predicate "vsx_register_operand" 86 (define_predicate "vsx_register_operand"
44 (and (match_operand 0 "register_operand") 87 (match_operand 0 "register_operand")
45 (match_test "GET_CODE (op) != REG 88 {
46 || VSX_REGNO_P (REGNO (op)) 89 if (GET_CODE (op) == SUBREG)
47 || REGNO (op) > LAST_VIRTUAL_REGISTER"))) 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 (REGNO (op) >= FIRST_PSEUDO_REGISTER)
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 (GET_CODE (op) == SUBREG)
111 op = SUBREG_REG (op);
112
113 if (!REG_P (op))
114 return 0;
115
116 if (REGNO (op) >= FIRST_PSEUDO_REGISTER)
117 return 1;
118
119 return VSX_REGNO_P (REGNO (op));
120 })
48 121
49 ;; Return 1 if op is a vector register that operates on floating point vectors 122 ;; Return 1 if op is a vector register that operates on floating point vectors
50 ;; (either altivec or VSX). 123 ;; (either altivec or VSX).
51 (define_predicate "vfloat_operand" 124 (define_predicate "vfloat_operand"
52 (and (match_operand 0 "register_operand") 125 (match_operand 0 "register_operand")
53 (match_test "GET_CODE (op) != REG 126 {
54 || VFLOAT_REGNO_P (REGNO (op)) 127 if (GET_CODE (op) == SUBREG)
55 || REGNO (op) > LAST_VIRTUAL_REGISTER"))) 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 (REGNO (op) >= FIRST_PSEUDO_REGISTER)
139 return 1;
140
141 return VFLOAT_REGNO_P (REGNO (op));
142 })
56 143
57 ;; Return 1 if op is a vector register that operates on integer vectors 144 ;; Return 1 if op is a vector register that operates on integer vectors
58 ;; (only altivec, VSX doesn't support integer vectors) 145 ;; (only altivec, VSX doesn't support integer vectors)
59 (define_predicate "vint_operand" 146 (define_predicate "vint_operand"
60 (and (match_operand 0 "register_operand") 147 (match_operand 0 "register_operand")
61 (match_test "GET_CODE (op) != REG 148 {
62 || VINT_REGNO_P (REGNO (op)) 149 if (GET_CODE (op) == SUBREG)
63 || REGNO (op) > LAST_VIRTUAL_REGISTER"))) 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 (REGNO (op) >= FIRST_PSEUDO_REGISTER)
161 return 1;
162
163 return VINT_REGNO_P (REGNO (op));
164 })
64 165
65 ;; Return 1 if op is a vector register to do logical operations on (and, or, 166 ;; Return 1 if op is a vector register to do logical operations on (and, or,
66 ;; xor, etc.) 167 ;; xor, etc.)
67 (define_predicate "vlogical_operand" 168 (define_predicate "vlogical_operand"
68 (and (match_operand 0 "register_operand") 169 (match_operand 0 "register_operand")
69 (match_test "GET_CODE (op) != REG 170 {
70 || VLOGICAL_REGNO_P (REGNO (op)) 171 if (GET_CODE (op) == SUBREG)
71 || REGNO (op) > LAST_VIRTUAL_REGISTER"))) 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 (REGNO (op) >= FIRST_PSEUDO_REGISTER)
184 return 1;
185
186 return VLOGICAL_REGNO_P (REGNO (op));
187 })
72 188
73 ;; Return 1 if op is the carry register. 189 ;; Return 1 if op is the carry register.
74 (define_predicate "ca_operand" 190 (define_predicate "ca_operand"
75 (and (match_code "reg") 191 (match_operand 0 "register_operand")
76 (match_test "CA_REGNO_P (REGNO (op))"))) 192 {
193 if (GET_CODE (op) == SUBREG)
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)")))
77 211
78 ;; Return 1 if op is a signed 5-bit constant integer. 212 ;; Return 1 if op is a signed 5-bit constant integer.
79 (define_predicate "s5bit_cint_operand" 213 (define_predicate "s5bit_cint_operand"
80 (and (match_code "const_int") 214 (and (match_code "const_int")
81 (match_test "INTVAL (op) >= -16 && INTVAL (op) <= 15"))) 215 (match_test "INTVAL (op) >= -16 && INTVAL (op) <= 15")))
82 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
83 ;; Return 1 if op is a unsigned 5-bit constant integer. 222 ;; Return 1 if op is a unsigned 5-bit constant integer.
84 (define_predicate "u5bit_cint_operand" 223 (define_predicate "u5bit_cint_operand"
85 (and (match_code "const_int") 224 (and (match_code "const_int")
86 (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 31"))) 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)")))
87 236
88 ;; Return 1 if op is a signed 8-bit constant integer. 237 ;; Return 1 if op is a signed 8-bit constant integer.
89 ;; Integer multiplication complete more quickly 238 ;; Integer multiplication complete more quickly
90 (define_predicate "s8bit_cint_operand" 239 (define_predicate "s8bit_cint_operand"
91 (and (match_code "const_int") 240 (and (match_code "const_int")
92 (match_test "INTVAL (op) >= -128 && INTVAL (op) <= 127"))) 241 (match_test "INTVAL (op) >= -128 && INTVAL (op) <= 127")))
93 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
94 ;; Return 1 if op is a constant integer that can fit in a D field. 248 ;; Return 1 if op is a constant integer that can fit in a D field.
95 (define_predicate "short_cint_operand" 249 (define_predicate "short_cint_operand"
96 (and (match_code "const_int") 250 (and (match_code "const_int")
97 (match_test "satisfies_constraint_I (op)"))) 251 (match_test "satisfies_constraint_I (op)")))
98 252
99 ;; Return 1 if op is a constant integer that can fit in an unsigned D field. 253 ;; Return 1 if op is a constant integer that can fit in an unsigned D field.
100 (define_predicate "u_short_cint_operand" 254 (define_predicate "u_short_cint_operand"
101 (and (match_code "const_int") 255 (and (match_code "const_int")
102 (match_test "satisfies_constraint_K (op)"))) 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)")))
103 263
104 ;; Return 1 if op is a constant integer that cannot fit in a signed D field. 264 ;; Return 1 if op is a constant integer that cannot fit in a signed D field.
105 (define_predicate "non_short_cint_operand" 265 (define_predicate "non_short_cint_operand"
106 (and (match_code "const_int") 266 (and (match_code "const_int")
107 (match_test "(unsigned HOST_WIDE_INT) 267 (match_test "(unsigned HOST_WIDE_INT)
110 ;; Return 1 if op is a positive constant integer that is an exact power of 2. 270 ;; Return 1 if op is a positive constant integer that is an exact power of 2.
111 (define_predicate "exact_log2_cint_operand" 271 (define_predicate "exact_log2_cint_operand"
112 (and (match_code "const_int") 272 (and (match_code "const_int")
113 (match_test "INTVAL (op) > 0 && exact_log2 (INTVAL (op)) >= 0"))) 273 (match_test "INTVAL (op) > 0 && exact_log2 (INTVAL (op)) >= 0")))
114 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
115 ;; Return 1 if op is a register that is not special. 305 ;; Return 1 if op is a register that is not special.
306 ;; Disallow (SUBREG:SF (REG:SI)) and (SUBREG:SI (REG:SF)) on VSX systems where
307 ;; you need to be careful in moving a SFmode to SImode and vice versa due to
308 ;; the fact that SFmode is represented as DFmode in the VSX registers.
116 (define_predicate "gpc_reg_operand" 309 (define_predicate "gpc_reg_operand"
117 (and (match_operand 0 "register_operand") 310 (match_operand 0 "register_operand")
118 (match_test "(GET_CODE (op) != REG 311 {
119 || (REGNO (op) >= ARG_POINTER_REGNUM 312 if (GET_CODE (op) == SUBREG)
120 && !CA_REGNO_P (REGNO (op))) 313 {
121 || REGNO (op) < MQ_REGNO) 314 if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
122 && !((TARGET_E500_DOUBLE || TARGET_SPE) 315 return 0;
123 && invalid_e500_subreg (op, mode))"))) 316
317 op = SUBREG_REG (op);
318 }
319
320 if (!REG_P (op))
321 return 0;
322
323 if (REGNO (op) >= FIRST_PSEUDO_REGISTER)
324 return 1;
325
326 if (TARGET_ALTIVEC && ALTIVEC_REGNO_P (REGNO (op)))
327 return 1;
328
329 if (TARGET_VSX && VSX_REGNO_P (REGNO (op)))
330 return 1;
331
332 return INT_REGNO_P (REGNO (op)) || FP_REGNO_P (REGNO (op));
333 })
334
335 ;; Return 1 if op is a general purpose register. Unlike gpc_reg_operand, don't
336 ;; allow floating point or vector registers. Since vector registers are not
337 ;; allowed, we don't have to reject SFmode/SImode subregs.
338 (define_predicate "int_reg_operand"
339 (match_operand 0 "register_operand")
340 {
341 if (GET_CODE (op) == SUBREG)
342 {
343 if (TARGET_NO_SF_SUBREG && sf_subreg_operand (op, mode))
344 return 0;
345
346 op = SUBREG_REG (op);
347 }
348
349 if (!REG_P (op))
350 return 0;
351
352 if (REGNO (op) >= FIRST_PSEUDO_REGISTER)
353 return 1;
354
355 return INT_REGNO_P (REGNO (op));
356 })
357
358 ;; Like int_reg_operand, but don't return true for pseudo registers
359 ;; We don't have to check for SF SUBREGS because pseudo registers
360 ;; are not allowed, and SF SUBREGs are ok within GPR registers.
361 (define_predicate "int_reg_operand_not_pseudo"
362 (match_operand 0 "register_operand")
363 {
364 if (GET_CODE (op) == SUBREG)
365 op = SUBREG_REG (op);
366
367 if (!REG_P (op))
368 return 0;
369
370 if (REGNO (op) >= FIRST_PSEUDO_REGISTER)
371 return 0;
372
373 return INT_REGNO_P (REGNO (op));
374 })
375
376 ;; Like int_reg_operand, but only return true for base registers
377 (define_predicate "base_reg_operand"
378 (match_operand 0 "int_reg_operand")
379 {
380 if (GET_CODE (op) == SUBREG)
381 op = SUBREG_REG (op);
382
383 if (!REG_P (op))
384 return 0;
385
386 return (REGNO (op) != FIRST_GPR_REGNO);
387 })
388
389
390 ;; Return true if this is a traditional floating point register
391 (define_predicate "fpr_reg_operand"
392 (match_code "reg,subreg")
393 {
394 HOST_WIDE_INT r;
395
396 if (GET_CODE (op) == SUBREG)
397 op = SUBREG_REG (op);
398
399 if (!REG_P (op))
400 return 0;
401
402 r = REGNO (op);
403 if (r >= FIRST_PSEUDO_REGISTER)
404 return 1;
405
406 return FP_REGNO_P (r);
407 })
408
409 ;; Return true if this is a register that can has D-form addressing (GPR and
410 ;; traditional FPR registers for scalars). ISA 3.0 (power9) adds D-form
411 ;; addressing for scalars in Altivec registers.
412 ;;
413 ;; If this is a pseudo only allow for GPR fusion in power8. If we have the
414 ;; power9 fusion allow the floating point types.
415 (define_predicate "toc_fusion_or_p9_reg_operand"
416 (match_code "reg,subreg")
417 {
418 HOST_WIDE_INT r;
419 bool gpr_p = (mode == QImode || mode == HImode || mode == SImode
420 || mode == SFmode
421 || (TARGET_POWERPC64 && (mode == DImode || mode == DFmode)));
422 bool fpr_p = (TARGET_P9_FUSION
423 && (mode == DFmode || mode == SFmode
424 || (TARGET_POWERPC64 && mode == DImode)));
425 bool vmx_p = (TARGET_P9_FUSION && TARGET_P9_VECTOR
426 && (mode == DFmode || mode == SFmode));
427
428 if (!TARGET_P8_FUSION)
429 return 0;
430
431 if (GET_CODE (op) == SUBREG)
432 op = SUBREG_REG (op);
433
434 if (!REG_P (op))
435 return 0;
436
437 r = REGNO (op);
438 if (r >= FIRST_PSEUDO_REGISTER)
439 return (gpr_p || fpr_p || vmx_p);
440
441 if (INT_REGNO_P (r))
442 return gpr_p;
443
444 if (FP_REGNO_P (r))
445 return fpr_p;
446
447 if (ALTIVEC_REGNO_P (r))
448 return vmx_p;
449
450 return 0;
451 })
452
453 ;; Return 1 if op is a HTM specific SPR register.
454 (define_predicate "htm_spr_reg_operand"
455 (match_operand 0 "register_operand")
456 {
457 if (!TARGET_HTM)
458 return 0;
459
460 if (GET_CODE (op) == SUBREG)
461 op = SUBREG_REG (op);
462
463 if (!REG_P (op))
464 return 0;
465
466 switch (REGNO (op))
467 {
468 case TFHAR_REGNO:
469 case TFIAR_REGNO:
470 case TEXASR_REGNO:
471 return 1;
472 default:
473 break;
474 }
475
476 /* Unknown SPR. */
477 return 0;
478 })
479
480 ;; Return 1 if op is a general purpose register that is an even register
481 ;; which suitable for a load/store quad operation
482 ;; Subregs are not allowed here because when they are combine can
483 ;; create (subreg:PTI (reg:TI pseudo)) which will cause reload to
484 ;; think the innermost reg needs reloading, in TImode instead of
485 ;; PTImode. So reload will choose a reg in TImode which has no
486 ;; requirement that the reg be even.
487 (define_predicate "quad_int_reg_operand"
488 (match_code "reg")
489 {
490 HOST_WIDE_INT r;
491
492 if (!TARGET_QUAD_MEMORY && !TARGET_QUAD_MEMORY_ATOMIC)
493 return 0;
494
495 r = REGNO (op);
496 if (r >= FIRST_PSEUDO_REGISTER)
497 return 1;
498
499 return (INT_REGNO_P (r) && ((r & 1) == 0));
500 })
124 501
125 ;; Return 1 if op is a register that is a condition register field. 502 ;; Return 1 if op is a register that is a condition register field.
126 (define_predicate "cc_reg_operand" 503 (define_predicate "cc_reg_operand"
127 (and (match_operand 0 "register_operand") 504 (match_operand 0 "register_operand")
128 (match_test "GET_CODE (op) != REG 505 {
129 || REGNO (op) > LAST_VIRTUAL_REGISTER 506 if (GET_CODE (op) == SUBREG)
130 || CR_REGNO_P (REGNO (op))"))) 507 op = SUBREG_REG (op);
508
509 if (!REG_P (op))
510 return 0;
511
512 if (REGNO (op) > LAST_VIRTUAL_REGISTER)
513 return 1;
514
515 return CR_REGNO_P (REGNO (op));
516 })
131 517
132 ;; Return 1 if op is a register that is a condition register field not cr0. 518 ;; Return 1 if op is a register that is a condition register field not cr0.
133 (define_predicate "cc_reg_not_cr0_operand" 519 (define_predicate "cc_reg_not_cr0_operand"
134 (and (match_operand 0 "register_operand") 520 (match_operand 0 "register_operand")
135 (match_test "GET_CODE (op) != REG 521 {
136 || REGNO (op) > LAST_VIRTUAL_REGISTER 522 if (GET_CODE (op) == SUBREG)
137 || CR_REGNO_NOT_CR0_P (REGNO (op))"))) 523 op = SUBREG_REG (op);
138 524
139 ;; Return 1 if op is a register that is a condition register field and if generating microcode, not cr0. 525 if (!REG_P (op))
140 (define_predicate "cc_reg_not_micro_cr0_operand" 526 return 0;
141 (and (match_operand 0 "register_operand") 527
142 (match_test "GET_CODE (op) != REG 528 if (REGNO (op) > LAST_VIRTUAL_REGISTER)
143 || REGNO (op) > LAST_VIRTUAL_REGISTER 529 return 1;
144 || (rs6000_gen_cell_microcode && CR_REGNO_NOT_CR0_P (REGNO (op))) 530
145 || (!rs6000_gen_cell_microcode && CR_REGNO_P (REGNO (op)))"))) 531 return CR_REGNO_NOT_CR0_P (REGNO (op));
532 })
146 533
147 ;; Return 1 if op is a constant integer valid for D field 534 ;; Return 1 if op is a constant integer valid for D field
148 ;; or non-special register register. 535 ;; or non-special register register.
149 (define_predicate "reg_or_short_operand" 536 (define_predicate "reg_or_short_operand"
150 (if_then_else (match_code "const_int") 537 (if_then_else (match_code "const_int")
151 (match_operand 0 "short_cint_operand") 538 (match_operand 0 "short_cint_operand")
152 (match_operand 0 "gpc_reg_operand")))
153
154 ;; Return 1 if op is a constant integer valid whose negation is valid for
155 ;; D field or non-special register register.
156 ;; Do not allow a constant zero because all patterns that call this
157 ;; predicate use "addic r1,r2,-const" to set carry when r2 is greater than
158 ;; or equal to const, which does not work for zero.
159 (define_predicate "reg_or_neg_short_operand"
160 (if_then_else (match_code "const_int")
161 (match_test "satisfies_constraint_P (op)
162 && INTVAL (op) != 0")
163 (match_operand 0 "gpc_reg_operand"))) 539 (match_operand 0 "gpc_reg_operand")))
164 540
165 ;; Return 1 if op is a constant integer valid for DS field 541 ;; Return 1 if op is a constant integer valid for DS field
166 ;; or non-special register. 542 ;; or non-special register.
167 (define_predicate "reg_or_aligned_short_operand" 543 (define_predicate "reg_or_aligned_short_operand"
175 (define_predicate "reg_or_u_short_operand" 551 (define_predicate "reg_or_u_short_operand"
176 (if_then_else (match_code "const_int") 552 (if_then_else (match_code "const_int")
177 (match_operand 0 "u_short_cint_operand") 553 (match_operand 0 "u_short_cint_operand")
178 (match_operand 0 "gpc_reg_operand"))) 554 (match_operand 0 "gpc_reg_operand")))
179 555
180 ;; Return 1 if op is any constant integer 556 ;; Return 1 if op is any constant integer or a non-special register.
181 ;; or non-special register.
182 (define_predicate "reg_or_cint_operand" 557 (define_predicate "reg_or_cint_operand"
183 (ior (match_code "const_int") 558 (ior (match_code "const_int")
184 (match_operand 0 "gpc_reg_operand"))) 559 (match_operand 0 "gpc_reg_operand")))
560
561 ;; Return 1 if op is constant zero or a non-special register.
562 (define_predicate "reg_or_zero_operand"
563 (ior (match_operand 0 "zero_constant")
564 (match_operand 0 "gpc_reg_operand")))
565
566 ;; Return 1 if op is a constant integer valid for addition with addis, addi.
567 (define_predicate "add_cint_operand"
568 (and (match_code "const_int")
569 (match_test "((unsigned HOST_WIDE_INT) INTVAL (op)
570 + (mode == SImode ? 0x80000000 : 0x80008000))
571 < (unsigned HOST_WIDE_INT) 0x100000000ll")))
185 572
186 ;; Return 1 if op is a constant integer valid for addition 573 ;; Return 1 if op is a constant integer valid for addition
187 ;; or non-special register. 574 ;; or non-special register.
188 (define_predicate "reg_or_add_cint_operand" 575 (define_predicate "reg_or_add_cint_operand"
189 (if_then_else (match_code "const_int") 576 (if_then_else (match_code "const_int")
190 (match_test "(HOST_BITS_PER_WIDE_INT == 32 577 (match_operand 0 "add_cint_operand")
191 && (mode == SImode || INTVAL (op) < 0x7fff8000))
192 || ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
193 < (unsigned HOST_WIDE_INT) 0x100000000ll)")
194 (match_operand 0 "gpc_reg_operand"))) 578 (match_operand 0 "gpc_reg_operand")))
195 579
196 ;; Return 1 if op is a constant integer valid for subtraction 580 ;; Return 1 if op is a constant integer valid for subtraction
197 ;; or non-special register. 581 ;; or non-special register.
198 (define_predicate "reg_or_sub_cint_operand" 582 (define_predicate "reg_or_sub_cint_operand"
199 (if_then_else (match_code "const_int") 583 (if_then_else (match_code "const_int")
200 (match_test "(HOST_BITS_PER_WIDE_INT == 32 584 (match_test "(unsigned HOST_WIDE_INT)
201 && (mode == SImode || - INTVAL (op) < 0x7fff8000)) 585 (- UINTVAL (op) + (mode == SImode ? 0x80000000 : 0x80008000))
202 || ((unsigned HOST_WIDE_INT) (- INTVAL (op) 586 < (unsigned HOST_WIDE_INT) 0x100000000ll")
203 + (mode == SImode
204 ? 0x80000000 : 0x80008000))
205 < (unsigned HOST_WIDE_INT) 0x100000000ll)")
206 (match_operand 0 "gpc_reg_operand"))) 587 (match_operand 0 "gpc_reg_operand")))
207 588
208 ;; Return 1 if op is any 32-bit unsigned constant integer 589 ;; Return 1 if op is any 32-bit unsigned constant integer
209 ;; or non-special register. 590 ;; or non-special register.
210 (define_predicate "reg_or_logical_cint_operand" 591 (define_predicate "reg_or_logical_cint_operand"
211 (if_then_else (match_code "const_int") 592 (if_then_else (match_code "const_int")
212 (match_test "(GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT 593 (match_test "(GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT
213 && INTVAL (op) >= 0) 594 && INTVAL (op) >= 0)
214 || ((INTVAL (op) & GET_MODE_MASK (mode) 595 || ((INTVAL (op) & GET_MODE_MASK (mode)
215 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0)") 596 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0)")
216 (if_then_else (match_code "const_double") 597 (match_operand 0 "gpc_reg_operand")))
217 (match_test "GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT 598
218 && mode == DImode 599 ;; Like reg_or_logical_cint_operand, but allow vsx registers
219 && CONST_DOUBLE_HIGH (op) == 0") 600 (define_predicate "vsx_reg_or_cint_operand"
220 (match_operand 0 "gpc_reg_operand")))) 601 (ior (match_operand 0 "vsx_register_operand")
602 (match_operand 0 "reg_or_logical_cint_operand")))
221 603
222 ;; Return 1 if operand is a CONST_DOUBLE that can be set in a register 604 ;; Return 1 if operand is a CONST_DOUBLE that can be set in a register
223 ;; with no more than one instruction per word. 605 ;; with no more than one instruction per word.
224 (define_predicate "easy_fp_constant" 606 (define_predicate "easy_fp_constant"
225 (match_code "const_double") 607 (match_code "const_double")
226 { 608 {
227 long k[4];
228 REAL_VALUE_TYPE rv;
229
230 if (GET_MODE (op) != mode 609 if (GET_MODE (op) != mode
231 || (!SCALAR_FLOAT_MODE_P (mode) && mode != DImode)) 610 || (!SCALAR_FLOAT_MODE_P (mode) && mode != DImode))
232 return 0; 611 return 0;
233 612
234 /* Consider all constants with -msoft-float to be easy. */ 613 /* Consider all constants with -msoft-float to be easy. */
235 if ((TARGET_SOFT_FLOAT || TARGET_E500_SINGLE 614 if ((TARGET_SOFT_FLOAT
236 || (TARGET_HARD_FLOAT && (TARGET_SINGLE_FLOAT && ! TARGET_DOUBLE_FLOAT))) 615 || (TARGET_HARD_FLOAT && (TARGET_SINGLE_FLOAT && ! TARGET_DOUBLE_FLOAT)))
237 && mode != DImode) 616 && mode != DImode)
238 return 1; 617 return 1;
239 618
619 /* 0.0D is not all zero bits. */
240 if (DECIMAL_FLOAT_MODE_P (mode)) 620 if (DECIMAL_FLOAT_MODE_P (mode))
241 return 0; 621 return 0;
622
623 /* The constant 0.0 is easy under VSX. */
624 if (TARGET_VSX && SCALAR_FLOAT_MODE_P (mode) && op == CONST0_RTX (mode))
625 return 1;
242 626
243 /* If we are using V.4 style PIC, consider all constants to be hard. */ 627 /* If we are using V.4 style PIC, consider all constants to be hard. */
244 if (flag_pic && DEFAULT_ABI == ABI_V4) 628 if (flag_pic && DEFAULT_ABI == ABI_V4)
245 return 0; 629 return 0;
246 630
247 #ifdef TARGET_RELOCATABLE 631 /* If we have real FPRs, consider floating point constants hard (other than
248 /* Similarly if we are using -mrelocatable, consider all constants 632 0.0 under VSX), so that the constant gets pushed to memory during the
249 to be hard. */ 633 early RTL phases. This has the advantage that double precision constants
250 if (TARGET_RELOCATABLE) 634 that can be represented in single precision without a loss of precision
251 return 0; 635 will use single precision loads. */
252 #endif
253 636
254 switch (mode) 637 switch (mode)
255 { 638 {
256 case TFmode: 639 case E_KFmode:
257 if (TARGET_E500_DOUBLE) 640 case E_IFmode:
258 return 0; 641 case E_TFmode:
259 642 case E_DFmode:
260 REAL_VALUE_FROM_CONST_DOUBLE (rv, op); 643 case E_SFmode:
261 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k); 644 return 0;
262 645
263 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1 646 case E_DImode:
264 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1 647 return (num_insns_constant (op, DImode) <= 2);
265 && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1 648
266 && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1); 649 case E_SImode:
267 650 return 1;
268 case DFmode: 651
269 /* The constant 0.f is easy under VSX. */ 652 default:
270 if (op == CONST0_RTX (DFmode) && VECTOR_UNIT_VSX_P (DFmode)) 653 gcc_unreachable ();
271 return 1; 654 }
272 655 })
273 /* Force constants to memory before reload to utilize 656
274 compress_float_constant. 657 ;; Return 1 if the operand is a constant that can loaded with a XXSPLTIB
275 Avoid this when flag_unsafe_math_optimizations is enabled 658 ;; instruction and then a VUPKHSB, VECSB2W or VECSB2D instruction.
276 because RDIV division to reciprocal optimization is not able 659
277 to regenerate the division. */ 660 (define_predicate "xxspltib_constant_split"
278 if (TARGET_E500_DOUBLE 661 (match_code "const_vector,vec_duplicate,const_int")
279 || (!reload_in_progress && !reload_completed 662 {
280 && !flag_unsafe_math_optimizations)) 663 int value = 256;
281 return 0; 664 int num_insns = -1;
282 665
283 REAL_VALUE_FROM_CONST_DOUBLE (rv, op); 666 if (!xxspltib_constant_p (op, mode, &num_insns, &value))
284 REAL_VALUE_TO_TARGET_DOUBLE (rv, k); 667 return false;
285 668
286 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1 669 return num_insns > 1;
287 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1); 670 })
288 671
289 case SFmode: 672
290 /* The constant 0.f is easy. */ 673 ;; Return 1 if the operand is constant that can loaded directly with a XXSPLTIB
291 if (op == CONST0_RTX (SFmode)) 674 ;; instruction.
292 return 1; 675
293 676 (define_predicate "xxspltib_constant_nosplit"
294 /* Force constants to memory before reload to utilize 677 (match_code "const_vector,vec_duplicate,const_int")
295 compress_float_constant. 678 {
296 Avoid this when flag_unsafe_math_optimizations is enabled 679 int value = 256;
297 because RDIV division to reciprocal optimization is not able 680 int num_insns = -1;
298 to regenerate the division. */ 681
299 if (!reload_in_progress && !reload_completed 682 if (!xxspltib_constant_p (op, mode, &num_insns, &value))
300 && !flag_unsafe_math_optimizations) 683 return false;
301 return 0; 684
302 685 return num_insns == 1;
303 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
304 REAL_VALUE_TO_TARGET_SINGLE (rv, k[0]);
305
306 return num_insns_constant_wide (k[0]) == 1;
307
308 case DImode:
309 return ((TARGET_POWERPC64
310 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
311 || (num_insns_constant (op, DImode) <= 2));
312
313 case SImode:
314 return 1;
315
316 default:
317 gcc_unreachable ();
318 }
319 }) 686 })
320 687
321 ;; Return 1 if the operand is a CONST_VECTOR and can be loaded into a 688 ;; Return 1 if the operand is a CONST_VECTOR and can be loaded into a
322 ;; vector register without using memory. 689 ;; vector register without using memory.
323 (define_predicate "easy_vector_constant" 690 (define_predicate "easy_vector_constant"
326 /* As the paired vectors are actually FPRs it seems that there is 693 /* As the paired vectors are actually FPRs it seems that there is
327 no easy way to load a CONST_VECTOR without using memory. */ 694 no easy way to load a CONST_VECTOR without using memory. */
328 if (TARGET_PAIRED_FLOAT) 695 if (TARGET_PAIRED_FLOAT)
329 return false; 696 return false;
330 697
698 /* Because IEEE 128-bit floating point is considered a vector type
699 in order to pass it in VSX registers, it might use this function
700 instead of easy_fp_constant. */
701 if (FLOAT128_VECTOR_P (mode))
702 return easy_fp_constant (op, mode);
703
331 if (VECTOR_MEM_ALTIVEC_OR_VSX_P (mode)) 704 if (VECTOR_MEM_ALTIVEC_OR_VSX_P (mode))
332 { 705 {
333 if (zero_constant (op, mode)) 706 int value = 256;
707 int num_insns = -1;
708
709 if (zero_constant (op, mode) || all_ones_constant (op, mode))
334 return true; 710 return true;
335 711
712 if (TARGET_P9_VECTOR
713 && xxspltib_constant_p (op, mode, &num_insns, &value))
714 return true;
715
336 return easy_altivec_constant (op, mode); 716 return easy_altivec_constant (op, mode);
337 }
338
339 if (SPE_VECTOR_MODE (mode))
340 {
341 int cst, cst2;
342 if (zero_constant (op, mode))
343 return true;
344 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
345 return false;
346
347 /* Limit SPE vectors to 15 bits signed. These we can generate with:
348 li r0, CONSTANT1
349 evmergelo r0, r0, r0
350 li r0, CONSTANT2
351
352 I don't know how efficient it would be to allow bigger constants,
353 considering we'll have an extra 'ori' for every 'li'. I doubt 5
354 instructions is better than a 64-bit memory load, but I don't
355 have the e500 timing specs. */
356 if (mode == V2SImode)
357 {
358 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
359 cst2 = INTVAL (CONST_VECTOR_ELT (op, 1));
360 return cst >= -0x7fff && cst <= 0x7fff
361 && cst2 >= -0x7fff && cst2 <= 0x7fff;
362 }
363 } 717 }
364 718
365 return false; 719 return false;
366 }) 720 })
367 721
370 (and (match_code "const_vector") 724 (and (match_code "const_vector")
371 (and (match_test "TARGET_ALTIVEC") 725 (and (match_test "TARGET_ALTIVEC")
372 (match_test "easy_altivec_constant (op, mode)"))) 726 (match_test "easy_altivec_constant (op, mode)")))
373 { 727 {
374 HOST_WIDE_INT val; 728 HOST_WIDE_INT val;
729 int elt;
375 if (mode == V2DImode || mode == V2DFmode) 730 if (mode == V2DImode || mode == V2DFmode)
376 return 0; 731 return 0;
377 val = const_vector_elt_as_int (op, GET_MODE_NUNITS (mode) - 1); 732 elt = BYTES_BIG_ENDIAN ? GET_MODE_NUNITS (mode) - 1 : 0;
733 val = const_vector_elt_as_int (op, elt);
378 val = ((val & 0xff) ^ 0x80) - 0x80; 734 val = ((val & 0xff) ^ 0x80) - 0x80;
379 return EASY_VECTOR_15_ADD_SELF (val); 735 return EASY_VECTOR_15_ADD_SELF (val);
380 }) 736 })
381 737
382 ;; Same as easy_vector_constant but only for EASY_VECTOR_MSB. 738 ;; Same as easy_vector_constant but only for EASY_VECTOR_MSB.
384 (and (match_code "const_vector") 740 (and (match_code "const_vector")
385 (and (match_test "TARGET_ALTIVEC") 741 (and (match_test "TARGET_ALTIVEC")
386 (match_test "easy_altivec_constant (op, mode)"))) 742 (match_test "easy_altivec_constant (op, mode)")))
387 { 743 {
388 HOST_WIDE_INT val; 744 HOST_WIDE_INT val;
745 int elt;
389 if (mode == V2DImode || mode == V2DFmode) 746 if (mode == V2DImode || mode == V2DFmode)
390 return 0; 747 return 0;
391 val = const_vector_elt_as_int (op, GET_MODE_NUNITS (mode) - 1); 748 elt = BYTES_BIG_ENDIAN ? GET_MODE_NUNITS (mode) - 1 : 0;
749 val = const_vector_elt_as_int (op, elt);
392 return EASY_VECTOR_MSB (val, GET_MODE_INNER (mode)); 750 return EASY_VECTOR_MSB (val, GET_MODE_INNER (mode));
393 }) 751 })
394 752
395 ;; Return 1 if operand is constant zero (scalars and vectors). 753 ;; Return true if this is an easy altivec constant that we form
396 (define_predicate "zero_constant" 754 ;; by using VSLDOI.
397 (and (match_code "const_int,const_double,const_vector") 755 (define_predicate "easy_vector_constant_vsldoi"
398 (match_test "op == CONST0_RTX (mode)"))) 756 (and (match_code "const_vector")
757 (and (match_test "TARGET_ALTIVEC")
758 (and (match_test "easy_altivec_constant (op, mode)")
759 (match_test "vspltis_shifted (op) != 0")))))
760
761 ;; Return 1 if operand is a vector int register or is either a vector constant
762 ;; of all 0 bits of a vector constant of all 1 bits.
763 (define_predicate "vector_int_reg_or_same_bit"
764 (match_code "reg,subreg,const_vector")
765 {
766 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
767 return 0;
768
769 else if (REG_P (op) || SUBREG_P (op))
770 return vint_operand (op, mode);
771
772 else
773 return op == CONST0_RTX (mode) || op == CONSTM1_RTX (mode);
774 })
399 775
400 ;; Return 1 if operand is 0.0. 776 ;; Return 1 if operand is 0.0.
401 ;; or non-special register register field no cr0
402 (define_predicate "zero_fp_constant" 777 (define_predicate "zero_fp_constant"
403 (and (match_code "const_double") 778 (and (match_code "const_double")
404 (match_test "SCALAR_FLOAT_MODE_P (mode) 779 (match_test "SCALAR_FLOAT_MODE_P (mode)
405 && op == CONST0_RTX (mode)"))) 780 && op == CONST0_RTX (mode)")))
406 781
410 ;; references where it's safe. 785 ;; references where it's safe.
411 (define_predicate "volatile_mem_operand" 786 (define_predicate "volatile_mem_operand"
412 (and (and (match_code "mem") 787 (and (and (match_code "mem")
413 (match_test "MEM_VOLATILE_P (op)")) 788 (match_test "MEM_VOLATILE_P (op)"))
414 (if_then_else (match_test "reload_completed") 789 (if_then_else (match_test "reload_completed")
415 (match_operand 0 "memory_operand") 790 (match_operand 0 "memory_operand")
416 (if_then_else (match_test "reload_in_progress") 791 (match_test "memory_address_p (mode, XEXP (op, 0))"))))
417 (match_test "strict_memory_address_p (mode, XEXP (op, 0))")
418 (match_test "memory_address_p (mode, XEXP (op, 0))")))))
419 792
420 ;; Return 1 if the operand is an offsettable memory operand. 793 ;; Return 1 if the operand is an offsettable memory operand.
421 (define_predicate "offsettable_mem_operand" 794 (define_predicate "offsettable_mem_operand"
422 (and (match_operand 0 "memory_operand") 795 (and (match_operand 0 "memory_operand")
423 (match_test "offsettable_nonstrict_memref_p (op)"))) 796 (match_test "offsettable_nonstrict_memref_p (op)")))
424 797
425 ;; Return 1 if the operand is a memory operand with an address divisible by 4 798 ;; Return 1 if the operand is a simple offsettable memory operand
426 (define_predicate "word_offset_memref_operand" 799 ;; that does not include pre-increment, post-increment, etc.
427 (match_operand 0 "memory_operand") 800 (define_predicate "simple_offsettable_mem_operand"
428 { 801 (match_operand 0 "offsettable_mem_operand")
429 /* Address inside MEM. */ 802 {
430 op = XEXP (op, 0); 803 rtx addr = XEXP (op, 0);
431 804
432 /* Extract address from auto-inc/dec. */ 805 if (GET_CODE (addr) != PLUS && GET_CODE (addr) != LO_SUM)
433 if (GET_CODE (op) == PRE_INC 806 return 0;
434 || GET_CODE (op) == PRE_DEC) 807
435 op = XEXP (op, 0); 808 if (!CONSTANT_P (XEXP (addr, 1)))
436 else if (GET_CODE (op) == PRE_MODIFY) 809 return 0;
437 op = XEXP (op, 1); 810
438 811 return base_reg_operand (XEXP (addr, 0), Pmode);
439 return (GET_CODE (op) != PLUS 812 })
440 || ! REG_P (XEXP (op, 0)) 813
441 || GET_CODE (XEXP (op, 1)) != CONST_INT 814 ;; Return 1 if the operand is suitable for load/store quad memory.
442 || INTVAL (XEXP (op, 1)) % 4 == 0); 815 ;; This predicate only checks for non-atomic loads/stores (not lqarx/stqcx).
816 (define_predicate "quad_memory_operand"
817 (match_code "mem")
818 {
819 if (!TARGET_QUAD_MEMORY && !TARGET_SYNC_TI)
820 return false;
821
822 if (GET_MODE_SIZE (mode) != 16 || !MEM_P (op) || MEM_ALIGN (op) < 128)
823 return false;
824
825 return quad_address_p (XEXP (op, 0), mode, false);
826 })
827
828 ;; Return 1 if the operand is suitable for load/store to vector registers with
829 ;; d-form addressing (register+offset), which was added in ISA 3.0.
830 ;; Unlike quad_memory_operand, we do not have to check for alignment.
831 (define_predicate "vsx_quad_dform_memory_operand"
832 (match_code "mem")
833 {
834 if (!TARGET_P9_VECTOR || !MEM_P (op) || GET_MODE_SIZE (mode) != 16)
835 return false;
836
837 return quad_address_p (XEXP (op, 0), mode, false);
443 }) 838 })
444 839
445 ;; Return 1 if the operand is an indexed or indirect memory operand. 840 ;; Return 1 if the operand is an indexed or indirect memory operand.
446 (define_predicate "indexed_or_indirect_operand" 841 (define_predicate "indexed_or_indirect_operand"
447 (match_code "mem") 842 (match_code "mem")
452 && GET_CODE (XEXP (op, 1)) == CONST_INT 847 && GET_CODE (XEXP (op, 1)) == CONST_INT
453 && INTVAL (XEXP (op, 1)) == -16) 848 && INTVAL (XEXP (op, 1)) == -16)
454 op = XEXP (op, 0); 849 op = XEXP (op, 0);
455 850
456 return indexed_or_indirect_address (op, mode); 851 return indexed_or_indirect_address (op, mode);
852 })
853
854 ;; Like indexed_or_indirect_operand, but also allow a GPR register if direct
855 ;; moves are supported.
856 (define_predicate "reg_or_indexed_operand"
857 (match_code "mem,reg,subreg")
858 {
859 if (MEM_P (op))
860 return indexed_or_indirect_operand (op, mode);
861 else if (TARGET_DIRECT_MOVE)
862 return register_operand (op, mode);
863 return
864 0;
457 }) 865 })
458 866
459 ;; Return 1 if the operand is an indexed or indirect memory operand with an 867 ;; Return 1 if the operand is an indexed or indirect memory operand with an
460 ;; AND -16 in it, used to recognize when we need to switch to Altivec loads 868 ;; AND -16 in it, used to recognize when we need to switch to Altivec loads
461 ;; to realign loops instead of VSX (altivec silently ignores the bottom bits, 869 ;; to realign loops instead of VSX (altivec silently ignores the bottom bits,
479 || (GET_CODE (op) == PLUS 887 || (GET_CODE (op) == PLUS
480 /* Omit testing REG_P (XEXP (op, 0)). */ 888 /* Omit testing REG_P (XEXP (op, 0)). */
481 && REG_P (XEXP (op, 1)))") 889 && REG_P (XEXP (op, 1)))")
482 (match_operand 0 "address_operand"))) 890 (match_operand 0 "address_operand")))
483 891
484 ;; Used for the destination of the fix_truncdfsi2 expander. 892 ;; Return 1 if the operand is an index-form address.
485 ;; If stfiwx will be used, the result goes to memory; otherwise, 893 (define_special_predicate "indexed_address"
486 ;; we're going to emit a store and a load of a subreg, so the dest is a 894 (match_test "(GET_CODE (op) == PLUS
487 ;; register. 895 && REG_P (XEXP (op, 0))
488 (define_predicate "fix_trunc_dest_operand" 896 && REG_P (XEXP (op, 1)))"))
489 (if_then_else (match_test "! TARGET_E500_DOUBLE && TARGET_PPC_GFXOPT") 897
490 (match_operand 0 "memory_operand") 898 ;; Return 1 if the operand is a MEM with an update-form address. This may
491 (match_operand 0 "gpc_reg_operand"))) 899 ;; also include update-indexed form.
900 (define_special_predicate "update_address_mem"
901 (match_test "(MEM_P (op)
902 && (GET_CODE (XEXP (op, 0)) == PRE_INC
903 || GET_CODE (XEXP (op, 0)) == PRE_DEC
904 || GET_CODE (XEXP (op, 0)) == PRE_MODIFY))"))
905
906 ;; Return 1 if the operand is a MEM with an indexed-form address.
907 (define_special_predicate "indexed_address_mem"
908 (match_test "(MEM_P (op)
909 && (indexed_address (XEXP (op, 0), mode)
910 || (GET_CODE (XEXP (op, 0)) == PRE_MODIFY
911 && indexed_address (XEXP (XEXP (op, 0), 1), mode))))"))
492 912
493 ;; Return 1 if the operand is either a non-special register or can be used 913 ;; Return 1 if the operand is either a non-special register or can be used
494 ;; as the operand of a `mode' add insn. 914 ;; as the operand of a `mode' add insn.
495 (define_predicate "add_operand" 915 (define_predicate "add_operand"
496 (if_then_else (match_code "const_int") 916 (if_then_else (match_code "const_int")
497 (match_test "satisfies_constraint_I (op) 917 (match_test "satisfies_constraint_I (op)
498 || satisfies_constraint_L (op)") 918 || satisfies_constraint_L (op)")
499 (match_operand 0 "gpc_reg_operand"))) 919 (match_operand 0 "gpc_reg_operand")))
500 920
921 ;; Return 1 if the operand is either a non-special register, or 0, or -1.
922 (define_predicate "adde_operand"
923 (if_then_else (match_code "const_int")
924 (match_test "INTVAL (op) == 0 || INTVAL (op) == -1")
925 (match_operand 0 "gpc_reg_operand")))
926
501 ;; Return 1 if OP is a constant but not a valid add_operand. 927 ;; Return 1 if OP is a constant but not a valid add_operand.
502 (define_predicate "non_add_cint_operand" 928 (define_predicate "non_add_cint_operand"
503 (and (match_code "const_int") 929 (and (match_code "const_int")
504 (match_test "!satisfies_constraint_I (op) 930 (match_test "!satisfies_constraint_I (op)
505 && !satisfies_constraint_L (op)"))) 931 && !satisfies_constraint_L (op)")))
506 932
507 ;; Return 1 if the operand is a constant that can be used as the operand 933 ;; Return 1 if the operand is a constant that can be used as the operand
508 ;; of an OR or XOR. 934 ;; of an OR or XOR.
509 (define_predicate "logical_const_operand" 935 (define_predicate "logical_const_operand"
510 (match_code "const_int,const_double") 936 (match_code "const_int")
511 { 937 {
512 HOST_WIDE_INT opl, oph; 938 HOST_WIDE_INT opl;
513 939
514 if (GET_CODE (op) == CONST_INT) 940 opl = INTVAL (op) & GET_MODE_MASK (mode);
515 {
516 opl = INTVAL (op) & GET_MODE_MASK (mode);
517
518 if (HOST_BITS_PER_WIDE_INT <= 32
519 && GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
520 return 0;
521 }
522 else if (GET_CODE (op) == CONST_DOUBLE)
523 {
524 gcc_assert (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT);
525
526 opl = CONST_DOUBLE_LOW (op);
527 oph = CONST_DOUBLE_HIGH (op);
528 if (oph != 0)
529 return 0;
530 }
531 else
532 return 0;
533 941
534 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0 942 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
535 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0); 943 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
536 }) 944 })
537 945
542 (match_operand 0 "logical_const_operand"))) 950 (match_operand 0 "logical_const_operand")))
543 951
544 ;; Return 1 if op is a constant that is not a logical operand, but could 952 ;; Return 1 if op is a constant that is not a logical operand, but could
545 ;; be split into one. 953 ;; be split into one.
546 (define_predicate "non_logical_cint_operand" 954 (define_predicate "non_logical_cint_operand"
547 (and (match_code "const_int,const_double") 955 (and (match_code "const_int,const_wide_int")
548 (and (not (match_operand 0 "logical_operand")) 956 (and (not (match_operand 0 "logical_operand"))
549 (match_operand 0 "reg_or_logical_cint_operand")))) 957 (match_operand 0 "reg_or_logical_cint_operand"))))
550 958
551 ;; Return 1 if op is a constant that can be encoded in a 32-bit mask, 959 ;; Return 1 if the operand is either a non-special register or a
552 ;; suitable for use with rlwinm (no more than two 1->0 or 0->1 960 ;; constant that can be used as the operand of a logical AND.
553 ;; transitions). Reject all ones and all zeros, since these should have 961 (define_predicate "and_operand"
554 ;; been optimized away and confuse the making of MB and ME. 962 (ior (and (match_code "const_int")
555 (define_predicate "mask_operand" 963 (match_test "rs6000_is_valid_and_mask (op, mode)"))
556 (match_code "const_int")
557 {
558 HOST_WIDE_INT c, lsb;
559
560 c = INTVAL (op);
561
562 if (TARGET_POWERPC64)
563 {
564 /* Fail if the mask is not 32-bit. */
565 if (mode == DImode && (c & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0)
566 return 0;
567
568 /* Fail if the mask wraps around because the upper 32-bits of the
569 mask will all be 1s, contrary to GCC's internal view. */
570 if ((c & 0x80000001) == 0x80000001)
571 return 0;
572 }
573
574 /* We don't change the number of transitions by inverting,
575 so make sure we start with the LS bit zero. */
576 if (c & 1)
577 c = ~c;
578
579 /* Reject all zeros or all ones. */
580 if (c == 0)
581 return 0;
582
583 /* Find the first transition. */
584 lsb = c & -c;
585
586 /* Invert to look for a second transition. */
587 c = ~c;
588
589 /* Erase first transition. */
590 c &= -lsb;
591
592 /* Find the second transition (if any). */
593 lsb = c & -c;
594
595 /* Match if all the bits above are 1's (or c is zero). */
596 return c == -lsb;
597 })
598
599 ;; Return 1 for the PowerPC64 rlwinm corner case.
600 (define_predicate "mask_operand_wrap"
601 (match_code "const_int")
602 {
603 HOST_WIDE_INT c, lsb;
604
605 c = INTVAL (op);
606
607 if ((c & 0x80000001) != 0x80000001)
608 return 0;
609
610 c = ~c;
611 if (c == 0)
612 return 0;
613
614 lsb = c & -c;
615 c = ~c;
616 c &= -lsb;
617 lsb = c & -c;
618 return c == -lsb;
619 })
620
621 ;; Return 1 if the operand is a constant that is a PowerPC64 mask
622 ;; suitable for use with rldicl or rldicr (no more than one 1->0 or 0->1
623 ;; transition). Reject all zeros, since zero should have been
624 ;; optimized away and confuses the making of MB and ME.
625 (define_predicate "mask64_operand"
626 (match_code "const_int")
627 {
628 HOST_WIDE_INT c, lsb;
629
630 c = INTVAL (op);
631
632 /* Reject all zeros. */
633 if (c == 0)
634 return 0;
635
636 /* We don't change the number of transitions by inverting,
637 so make sure we start with the LS bit zero. */
638 if (c & 1)
639 c = ~c;
640
641 /* Find the first transition. */
642 lsb = c & -c;
643
644 /* Match if all the bits above are 1's (or c is zero). */
645 return c == -lsb;
646 })
647
648 ;; Like mask64_operand, but allow up to three transitions. This
649 ;; predicate is used by insn patterns that generate two rldicl or
650 ;; rldicr machine insns.
651 (define_predicate "mask64_2_operand"
652 (match_code "const_int")
653 {
654 HOST_WIDE_INT c, lsb;
655
656 c = INTVAL (op);
657
658 /* Disallow all zeros. */
659 if (c == 0)
660 return 0;
661
662 /* We don't change the number of transitions by inverting,
663 so make sure we start with the LS bit zero. */
664 if (c & 1)
665 c = ~c;
666
667 /* Find the first transition. */
668 lsb = c & -c;
669
670 /* Invert to look for a second transition. */
671 c = ~c;
672
673 /* Erase first transition. */
674 c &= -lsb;
675
676 /* Find the second transition. */
677 lsb = c & -c;
678
679 /* Invert to look for a third transition. */
680 c = ~c;
681
682 /* Erase second transition. */
683 c &= -lsb;
684
685 /* Find the third transition (if any). */
686 lsb = c & -c;
687
688 /* Match if all the bits above are 1's (or c is zero). */
689 return c == -lsb;
690 })
691
692 ;; Like and_operand, but also match constants that can be implemented
693 ;; with two rldicl or rldicr insns.
694 (define_predicate "and64_2_operand"
695 (ior (match_operand 0 "mask64_2_operand")
696 (if_then_else (match_test "fixed_regs[CR0_REGNO]") 964 (if_then_else (match_test "fixed_regs[CR0_REGNO]")
697 (match_operand 0 "gpc_reg_operand") 965 (match_operand 0 "gpc_reg_operand")
698 (match_operand 0 "logical_operand")))) 966 (match_operand 0 "logical_operand"))))
699
700 ;; Return 1 if the operand is either a non-special register or a
701 ;; constant that can be used as the operand of a logical AND.
702 (define_predicate "and_operand"
703 (ior (match_operand 0 "mask_operand")
704 (ior (and (match_test "TARGET_POWERPC64 && mode == DImode")
705 (match_operand 0 "mask64_operand"))
706 (if_then_else (match_test "fixed_regs[CR0_REGNO]")
707 (match_operand 0 "gpc_reg_operand")
708 (match_operand 0 "logical_operand")))))
709 967
710 ;; Return 1 if the operand is either a logical operand or a short cint operand. 968 ;; Return 1 if the operand is either a logical operand or a short cint operand.
711 (define_predicate "scc_eq_operand" 969 (define_predicate "scc_eq_operand"
712 (ior (match_operand 0 "logical_operand") 970 (ior (match_operand 0 "logical_operand")
713 (match_operand 0 "short_cint_operand"))) 971 (match_operand 0 "short_cint_operand")))
714 972
715 ;; Return 1 if the operand is a general non-special register or memory operand. 973 ;; Return 1 if the operand is a general non-special register or memory operand.
716 (define_predicate "reg_or_mem_operand" 974 (define_predicate "reg_or_mem_operand"
717 (ior (match_operand 0 "memory_operand") 975 (ior (match_operand 0 "memory_operand")
718 (ior (and (match_code "mem") 976 (and (match_code "mem")
719 (match_test "macho_lo_sum_memory_operand (op, mode)")) 977 (match_test "macho_lo_sum_memory_operand (op, mode)"))
720 (ior (match_operand 0 "volatile_mem_operand") 978 (match_operand 0 "volatile_mem_operand")
721 (match_operand 0 "gpc_reg_operand"))))) 979 (match_operand 0 "gpc_reg_operand")))
722
723 ;; Return 1 if the operand is either an easy FP constant or memory or reg.
724 (define_predicate "reg_or_none500mem_operand"
725 (if_then_else (match_code "mem")
726 (and (match_test "!TARGET_E500_DOUBLE")
727 (ior (match_operand 0 "memory_operand")
728 (ior (match_test "macho_lo_sum_memory_operand (op, mode)")
729 (match_operand 0 "volatile_mem_operand"))))
730 (match_operand 0 "gpc_reg_operand")))
731 980
732 ;; Return 1 if the operand is CONST_DOUBLE 0, register or memory operand. 981 ;; Return 1 if the operand is CONST_DOUBLE 0, register or memory operand.
733 (define_predicate "zero_reg_mem_operand" 982 (define_predicate "zero_reg_mem_operand"
734 (ior (match_operand 0 "zero_fp_constant") 983 (ior (and (match_test "TARGET_VSX")
984 (match_operand 0 "zero_fp_constant"))
735 (match_operand 0 "reg_or_mem_operand"))) 985 (match_operand 0 "reg_or_mem_operand")))
986
987 ;; Return 1 if the operand is a CONST_INT and it is the element for 64-bit
988 ;; data types inside of a vector that scalar instructions operate on
989 (define_predicate "vsx_scalar_64bit"
990 (match_code "const_int")
991 {
992 return (INTVAL (op) == VECTOR_ELEMENT_SCALAR_64BIT);
993 })
736 994
737 ;; Return 1 if the operand is a general register or memory operand without 995 ;; Return 1 if the operand is a general register or memory operand without
738 ;; pre_inc or pre_dec or pre_modify, which produces invalid form of PowerPC 996 ;; pre_inc or pre_dec or pre_modify, which produces invalid form of PowerPC
739 ;; lwa instruction. 997 ;; lwa instruction.
740 (define_predicate "lwa_operand" 998 (define_predicate "lwa_operand"
748 1006
749 if (gpc_reg_operand (inner, mode)) 1007 if (gpc_reg_operand (inner, mode))
750 return true; 1008 return true;
751 if (!memory_operand (inner, mode)) 1009 if (!memory_operand (inner, mode))
752 return false; 1010 return false;
1011
753 addr = XEXP (inner, 0); 1012 addr = XEXP (inner, 0);
754 if (GET_CODE (addr) == PRE_INC 1013 if (GET_CODE (addr) == PRE_INC
755 || GET_CODE (addr) == PRE_DEC 1014 || GET_CODE (addr) == PRE_DEC
756 || (GET_CODE (addr) == PRE_MODIFY 1015 || (GET_CODE (addr) == PRE_MODIFY
757 && !legitimate_indexed_address_p (XEXP (addr, 1), 0))) 1016 && !legitimate_indexed_address_p (XEXP (addr, 1), 0)))
801 ;; Return 1 if the operand is a SYMBOL_REF for a function known to be in 1060 ;; Return 1 if the operand is a SYMBOL_REF for a function known to be in
802 ;; this file. 1061 ;; this file.
803 (define_predicate "current_file_function_operand" 1062 (define_predicate "current_file_function_operand"
804 (and (match_code "symbol_ref") 1063 (and (match_code "symbol_ref")
805 (match_test "(DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op)) 1064 (match_test "(DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
806 && ((SYMBOL_REF_LOCAL_P (op) 1065 && (SYMBOL_REF_LOCAL_P (op)
807 && (DEFAULT_ABI != ABI_AIX 1066 || (op == XEXP (DECL_RTL (current_function_decl), 0)
808 || !SYMBOL_REF_EXTERNAL_P (op))) 1067 && !decl_replaceable_p (current_function_decl)))
809 || (op == XEXP (DECL_RTL (current_function_decl), 1068 && !((DEFAULT_ABI == ABI_AIX
810 0)))"))) 1069 || DEFAULT_ABI == ABI_ELFv2)
1070 && (SYMBOL_REF_EXTERNAL_P (op)
1071 || SYMBOL_REF_WEAK (op)))")))
811 1072
812 ;; Return 1 if this operand is a valid input for a move insn. 1073 ;; Return 1 if this operand is a valid input for a move insn.
813 (define_predicate "input_operand" 1074 (define_predicate "input_operand"
814 (match_code "label_ref,symbol_ref,const,high,reg,subreg,mem, 1075 (match_code "symbol_ref,const,reg,subreg,mem,
815 const_double,const_vector,const_int,plus") 1076 const_double,const_wide_int,const_vector,const_int")
816 { 1077 {
817 /* Memory is always valid. */ 1078 /* Memory is always valid. */
818 if (memory_operand (op, mode)) 1079 if (memory_operand (op, mode))
819 return 1; 1080 return 1;
820 1081
821 /* For floating-point, easy constants are valid. */ 1082 /* For floating-point, easy constants are valid. */
822 if (SCALAR_FLOAT_MODE_P (mode) 1083 if (SCALAR_FLOAT_MODE_P (mode)
823 && CONSTANT_P (op)
824 && easy_fp_constant (op, mode)) 1084 && easy_fp_constant (op, mode))
825 return 1; 1085 return 1;
826 1086
827 /* Allow any integer constant. */ 1087 /* Allow any integer constant. */
828 if (GET_MODE_CLASS (mode) == MODE_INT 1088 if (GET_MODE_CLASS (mode) == MODE_INT
829 && (GET_CODE (op) == CONST_INT 1089 && CONST_SCALAR_INT_P (op))
830 || GET_CODE (op) == CONST_DOUBLE))
831 return 1; 1090 return 1;
832 1091
833 /* Allow easy vector constants. */ 1092 /* Allow easy vector constants. */
834 if (GET_CODE (op) == CONST_VECTOR 1093 if (GET_CODE (op) == CONST_VECTOR
835 && easy_vector_constant (op, mode)) 1094 && easy_vector_constant (op, mode))
836 return 1; 1095 return 1;
837
838 /* Do not allow invalid E500 subregs. */
839 if ((TARGET_E500_DOUBLE || TARGET_SPE)
840 && GET_CODE (op) == SUBREG
841 && invalid_e500_subreg (op, mode))
842 return 0;
843 1096
844 /* For floating-point or multi-word mode, the only remaining valid type 1097 /* For floating-point or multi-word mode, the only remaining valid type
845 is a register. */ 1098 is a register. */
846 if (SCALAR_FLOAT_MODE_P (mode) 1099 if (SCALAR_FLOAT_MODE_P (mode)
847 || GET_MODE_SIZE (mode) > UNITS_PER_WORD) 1100 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
848 return register_operand (op, mode); 1101 return register_operand (op, mode);
849 1102
1103 /* We don't allow moving the carry bit around. */
1104 if (ca_operand (op, mode))
1105 return 0;
1106
850 /* The only cases left are integral modes one word or smaller (we 1107 /* The only cases left are integral modes one word or smaller (we
851 do not get called for MODE_CC values). These can be in any 1108 do not get called for MODE_CC values). These can be in any
852 register. */ 1109 register. */
853 if (register_operand (op, mode)) 1110 if (register_operand (op, mode))
854 return 1;
855
856 /* A SYMBOL_REF referring to the TOC is valid. */
857 if (legitimate_constant_pool_address_p (op, mode, false))
858 return 1;
859
860 /* A constant pool expression (relative to the TOC) is valid */
861 if (toc_relative_expr_p (op))
862 return 1; 1111 return 1;
863 1112
864 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region 1113 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
865 to be valid. */ 1114 to be valid. */
866 if (DEFAULT_ABI == ABI_V4 1115 if (DEFAULT_ABI == ABI_V4
869 return 1; 1118 return 1;
870 1119
871 return 0; 1120 return 0;
872 }) 1121 })
873 1122
874 ;; Return true if OP is an invalid SUBREG operation on the e500. 1123 ;; Return 1 if this operand is a valid input for a vsx_splat insn.
875 (define_predicate "rs6000_nonimmediate_operand" 1124 (define_predicate "splat_input_operand"
876 (match_code "reg,subreg,mem") 1125 (match_code "reg,subreg,mem")
877 { 1126 {
878 if ((TARGET_E500_DOUBLE || TARGET_SPE) 1127 machine_mode vmode;
879 && GET_CODE (op) == SUBREG 1128
880 && invalid_e500_subreg (op, mode)) 1129 if (mode == DFmode)
881 return 0; 1130 vmode = V2DFmode;
882 1131 else if (mode == DImode)
883 return nonimmediate_operand (op, mode); 1132 vmode = V2DImode;
884 }) 1133 else if (mode == SImode && TARGET_P9_VECTOR)
1134 vmode = V4SImode;
1135 else if (mode == SFmode && TARGET_P9_VECTOR)
1136 vmode = V4SFmode;
1137 else
1138 return false;
1139
1140 if (MEM_P (op))
1141 {
1142 rtx addr = XEXP (op, 0);
1143
1144 if (! volatile_ok && MEM_VOLATILE_P (op))
1145 return 0;
1146
1147 if (lra_in_progress || reload_completed)
1148 return indexed_or_indirect_address (addr, vmode);
1149 else
1150 return memory_address_addr_space_p (vmode, addr, MEM_ADDR_SPACE (op));
1151 }
1152 return gpc_reg_operand (op, mode);
1153 })
1154
1155 ;; Return true if operand is an operator used in rotate-and-mask instructions.
1156 (define_predicate "rotate_mask_operator"
1157 (match_code "rotate,ashift,lshiftrt"))
885 1158
886 ;; Return true if operand is boolean operator. 1159 ;; Return true if operand is boolean operator.
887 (define_predicate "boolean_operator" 1160 (define_predicate "boolean_operator"
888 (match_code "and,ior,xor")) 1161 (match_code "and,ior,xor"))
889 1162
892 (match_code "ior,xor")) 1165 (match_code "ior,xor"))
893 1166
894 ;; Return true if operand is an equality operator. 1167 ;; Return true if operand is an equality operator.
895 (define_special_predicate "equality_operator" 1168 (define_special_predicate "equality_operator"
896 (match_code "eq,ne")) 1169 (match_code "eq,ne"))
897
898 ;; Return true if operand is MIN or MAX operator.
899 (define_predicate "min_max_operator"
900 (match_code "smin,smax,umin,umax"))
901 1170
902 ;; Return 1 if OP is a comparison operation that is valid for a branch 1171 ;; Return 1 if OP is a comparison operation that is valid for a branch
903 ;; instruction. We check the opcode against the mode of the CC value. 1172 ;; instruction. We check the opcode against the mode of the CC value.
904 ;; validate_condition_mode is an assertion. 1173 ;; validate_condition_mode is an assertion.
905 (define_predicate "branch_comparison_operator" 1174 (define_predicate "branch_comparison_operator"
907 (and (match_test "GET_MODE_CLASS (GET_MODE (XEXP (op, 0))) == MODE_CC") 1176 (and (match_test "GET_MODE_CLASS (GET_MODE (XEXP (op, 0))) == MODE_CC")
908 (match_test "validate_condition_mode (GET_CODE (op), 1177 (match_test "validate_condition_mode (GET_CODE (op),
909 GET_MODE (XEXP (op, 0))), 1178 GET_MODE (XEXP (op, 0))),
910 1")))) 1179 1"))))
911 1180
912 (define_predicate "rs6000_cbranch_operator" 1181 ;; Return 1 if OP is an unsigned comparison operator.
913 (if_then_else (match_test "TARGET_HARD_FLOAT && !TARGET_FPRS") 1182 (define_predicate "unsigned_comparison_operator"
914 (match_operand 0 "ordered_comparison_operator") 1183 (match_code "ltu,gtu,leu,geu"))
915 (match_operand 0 "comparison_operator"))) 1184
1185 ;; Return 1 if OP is a signed comparison operator.
1186 (define_predicate "signed_comparison_operator"
1187 (match_code "lt,gt,le,ge"))
916 1188
917 ;; Return 1 if OP is a comparison operation that is valid for an SCC insn -- 1189 ;; Return 1 if OP is a comparison operation that is valid for an SCC insn --
918 ;; it must be a positive comparison. 1190 ;; it must be a positive comparison.
919 (define_predicate "scc_comparison_operator" 1191 (define_predicate "scc_comparison_operator"
920 (and (match_operand 0 "branch_comparison_operator") 1192 (and (match_operand 0 "branch_comparison_operator")
923 ;; Return 1 if OP is a comparison operation whose inverse would be valid for 1195 ;; Return 1 if OP is a comparison operation whose inverse would be valid for
924 ;; an SCC insn. 1196 ;; an SCC insn.
925 (define_predicate "scc_rev_comparison_operator" 1197 (define_predicate "scc_rev_comparison_operator"
926 (and (match_operand 0 "branch_comparison_operator") 1198 (and (match_operand 0 "branch_comparison_operator")
927 (match_code "ne,le,ge,leu,geu,ordered"))) 1199 (match_code "ne,le,ge,leu,geu,ordered")))
1200
1201 ;; Return 1 if OP is a comparison operator suitable for floating point
1202 ;; vector/scalar comparisons that generate a -1/0 mask.
1203 (define_predicate "fpmask_comparison_operator"
1204 (match_code "eq,gt,ge"))
1205
1206 ;; Return 1 if OP is a comparison operator suitable for vector/scalar
1207 ;; comparisons that generate a 0/-1 mask (i.e. the inverse of
1208 ;; fpmask_comparison_operator).
1209 (define_predicate "invert_fpmask_comparison_operator"
1210 (match_code "ne,unlt,unle"))
1211
1212 ;; Return 1 if OP is a comparison operation suitable for integer vector/scalar
1213 ;; comparisons that generate a -1/0 mask.
1214 (define_predicate "vecint_comparison_operator"
1215 (match_code "eq,gt,gtu"))
928 1216
929 ;; Return 1 if OP is a comparison operation that is valid for a branch 1217 ;; Return 1 if OP is a comparison operation that is valid for a branch
930 ;; insn, which is true if the corresponding bit in the CC register is set. 1218 ;; insn, which is true if the corresponding bit in the CC register is set.
931 (define_predicate "branch_positive_comparison_operator" 1219 (define_predicate "branch_positive_comparison_operator"
932 (and (match_operand 0 "branch_comparison_operator") 1220 (and (match_operand 0 "branch_comparison_operator")
1270 return 0; 1558 return 0;
1271 } 1559 }
1272 return 1; 1560 return 1;
1273 }) 1561 })
1274 1562
1563 ;; Return 1 if OP is valid for crsave insn, known to be a PARALLEL.
1564 (define_predicate "crsave_operation"
1565 (match_code "parallel")
1566 {
1567 int count = XVECLEN (op, 0);
1568 int i;
1569
1570 for (i = 1; i < count; i++)
1571 {
1572 rtx exp = XVECEXP (op, 0, i);
1573
1574 if (GET_CODE (exp) != USE
1575 || GET_CODE (XEXP (exp, 0)) != REG
1576 || GET_MODE (XEXP (exp, 0)) != CCmode
1577 || ! CR_REGNO_P (REGNO (XEXP (exp, 0))))
1578 return 0;
1579 }
1580 return 1;
1581 })
1582
1275 ;; Return 1 if OP is valid for lmw insn, known to be a PARALLEL. 1583 ;; Return 1 if OP is valid for lmw insn, known to be a PARALLEL.
1276 (define_predicate "lmw_operation" 1584 (define_predicate "lmw_operation"
1277 (match_code "parallel") 1585 (match_code "parallel")
1278 { 1586 {
1279 int count = XVECLEN (op, 0); 1587 int count = XVECLEN (op, 0);
1302 offset = 0; 1610 offset = 0;
1303 base_regno = REGNO (src_addr); 1611 base_regno = REGNO (src_addr);
1304 if (base_regno == 0) 1612 if (base_regno == 0)
1305 return 0; 1613 return 0;
1306 } 1614 }
1307 else if (rs6000_legitimate_offset_address_p (SImode, src_addr, 0)) 1615 else if (rs6000_legitimate_offset_address_p (SImode, src_addr, false, false))
1308 { 1616 {
1309 offset = INTVAL (XEXP (src_addr, 1)); 1617 offset = INTVAL (XEXP (src_addr, 1));
1310 base_regno = REGNO (XEXP (src_addr, 0)); 1618 base_regno = REGNO (XEXP (src_addr, 0));
1311 } 1619 }
1312 else 1620 else
1330 if (legitimate_indirect_address_p (newaddr, 0)) 1638 if (legitimate_indirect_address_p (newaddr, 0))
1331 { 1639 {
1332 newoffset = 0; 1640 newoffset = 0;
1333 addr_reg = newaddr; 1641 addr_reg = newaddr;
1334 } 1642 }
1335 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0)) 1643 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, false, false))
1336 { 1644 {
1337 addr_reg = XEXP (newaddr, 0); 1645 addr_reg = XEXP (newaddr, 0);
1338 newoffset = INTVAL (XEXP (newaddr, 1)); 1646 newoffset = INTVAL (XEXP (newaddr, 1));
1339 } 1647 }
1340 else 1648 else
1377 offset = 0; 1685 offset = 0;
1378 base_regno = REGNO (dest_addr); 1686 base_regno = REGNO (dest_addr);
1379 if (base_regno == 0) 1687 if (base_regno == 0)
1380 return 0; 1688 return 0;
1381 } 1689 }
1382 else if (rs6000_legitimate_offset_address_p (SImode, dest_addr, 0)) 1690 else if (rs6000_legitimate_offset_address_p (SImode, dest_addr, false, false))
1383 { 1691 {
1384 offset = INTVAL (XEXP (dest_addr, 1)); 1692 offset = INTVAL (XEXP (dest_addr, 1));
1385 base_regno = REGNO (XEXP (dest_addr, 0)); 1693 base_regno = REGNO (XEXP (dest_addr, 0));
1386 } 1694 }
1387 else 1695 else
1405 if (legitimate_indirect_address_p (newaddr, 0)) 1713 if (legitimate_indirect_address_p (newaddr, 0))
1406 { 1714 {
1407 newoffset = 0; 1715 newoffset = 0;
1408 addr_reg = newaddr; 1716 addr_reg = newaddr;
1409 } 1717 }
1410 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0)) 1718 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, false, false))
1411 { 1719 {
1412 addr_reg = XEXP (newaddr, 0); 1720 addr_reg = XEXP (newaddr, 0);
1413 newoffset = INTVAL (XEXP (newaddr, 1)); 1721 newoffset = INTVAL (XEXP (newaddr, 1));
1414 } 1722 }
1415 else 1723 else
1419 return 0; 1727 return 0;
1420 } 1728 }
1421 1729
1422 return 1; 1730 return 1;
1423 }) 1731 })
1732
1733 ;; Return 1 if OP is a stack tie operand.
1734 (define_predicate "tie_operand"
1735 (match_code "parallel")
1736 {
1737 return (GET_CODE (XVECEXP (op, 0, 0)) == SET
1738 && GET_CODE (XEXP (XVECEXP (op, 0, 0), 0)) == MEM
1739 && GET_MODE (XEXP (XVECEXP (op, 0, 0), 0)) == BLKmode
1740 && XEXP (XVECEXP (op, 0, 0), 1) == const0_rtx);
1741 })
1742
1743 ;; Match a small code model toc reference (or medium and large
1744 ;; model toc references before reload).
1745 (define_predicate "small_toc_ref"
1746 (match_code "unspec,plus")
1747 {
1748 if (GET_CODE (op) == PLUS && add_cint_operand (XEXP (op, 1), mode))
1749 op = XEXP (op, 0);
1750
1751 return GET_CODE (op) == UNSPEC && XINT (op, 1) == UNSPEC_TOCREL;
1752 })
1753
1754 ;; Match the TOC memory operand that can be fused with an addis instruction.
1755 ;; This is used in matching a potential fused address before register
1756 ;; allocation.
1757 (define_predicate "toc_fusion_mem_raw"
1758 (match_code "mem")
1759 {
1760 if (!TARGET_TOC_FUSION_INT || !can_create_pseudo_p ())
1761 return false;
1762
1763 return small_toc_ref (XEXP (op, 0), Pmode);
1764 })
1765
1766 ;; Match the memory operand that has been fused with an addis instruction and
1767 ;; wrapped inside of an (unspec [...] UNSPEC_FUSION_ADDIS) wrapper.
1768 (define_predicate "toc_fusion_mem_wrapped"
1769 (match_code "mem")
1770 {
1771 rtx addr;
1772
1773 if (!TARGET_TOC_FUSION_INT)
1774 return false;
1775
1776 if (!MEM_P (op))
1777 return false;
1778
1779 addr = XEXP (op, 0);
1780 return (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_FUSION_ADDIS);
1781 })
1782
1783 ;; Match the first insn (addis) in fusing the combination of addis and loads to
1784 ;; GPR registers on power8.
1785 (define_predicate "fusion_gpr_addis"
1786 (match_code "const_int,high,plus")
1787 {
1788 HOST_WIDE_INT value;
1789 rtx int_const;
1790
1791 if (GET_CODE (op) == HIGH)
1792 return 1;
1793
1794 if (CONST_INT_P (op))
1795 int_const = op;
1796
1797 else if (GET_CODE (op) == PLUS
1798 && base_reg_operand (XEXP (op, 0), Pmode)
1799 && CONST_INT_P (XEXP (op, 1)))
1800 int_const = XEXP (op, 1);
1801
1802 else
1803 return 0;
1804
1805 value = INTVAL (int_const);
1806 if ((value & (HOST_WIDE_INT)0xffff) != 0)
1807 return 0;
1808
1809 if ((value & (HOST_WIDE_INT)0xffff0000) == 0)
1810 return 0;
1811
1812 /* Power8 currently will only do the fusion if the top 11 bits of the addis
1813 value are all 1's or 0's. Ignore this restriction if we are testing
1814 advanced fusion. */
1815 if (TARGET_P9_FUSION)
1816 return 1;
1817
1818 return (IN_RANGE (value >> 16, -32, 31));
1819 })
1820
1821 ;; Match the second insn (lbz, lhz, lwz, ld) in fusing the combination of addis
1822 ;; and loads to GPR registers on power8.
1823 (define_predicate "fusion_gpr_mem_load"
1824 (match_code "mem,sign_extend,zero_extend")
1825 {
1826 rtx addr, base, offset;
1827
1828 /* Handle sign/zero extend. */
1829 if (GET_CODE (op) == ZERO_EXTEND
1830 || (TARGET_P8_FUSION_SIGN && GET_CODE (op) == SIGN_EXTEND))
1831 {
1832 op = XEXP (op, 0);
1833 mode = GET_MODE (op);
1834 }
1835
1836 if (!MEM_P (op))
1837 return 0;
1838
1839 switch (mode)
1840 {
1841 case E_QImode:
1842 case E_HImode:
1843 case E_SImode:
1844 break;
1845
1846 case E_DImode:
1847 if (!TARGET_POWERPC64)
1848 return 0;
1849 break;
1850
1851 default:
1852 return 0;
1853 }
1854
1855 addr = XEXP (op, 0);
1856 if (GET_CODE (addr) != PLUS && GET_CODE (addr) != LO_SUM)
1857 return 0;
1858
1859 base = XEXP (addr, 0);
1860 if (!base_reg_operand (base, GET_MODE (base)))
1861 return 0;
1862
1863 offset = XEXP (addr, 1);
1864
1865 if (GET_CODE (addr) == PLUS)
1866 return satisfies_constraint_I (offset);
1867
1868 else if (GET_CODE (addr) == LO_SUM)
1869 {
1870 if (TARGET_XCOFF || (TARGET_ELF && TARGET_POWERPC64))
1871 return small_toc_ref (offset, GET_MODE (offset));
1872
1873 else if (TARGET_ELF && !TARGET_POWERPC64)
1874 return CONSTANT_P (offset);
1875 }
1876
1877 return 0;
1878 })
1879
1880 ;; Match a GPR load (lbz, lhz, lwz, ld) that uses a combined address in the
1881 ;; memory field with both the addis and the memory offset. Sign extension
1882 ;; is not handled here, since lha and lwa are not fused.
1883 ;; With P9 fusion, also match a fpr/vector load and float_extend
1884 (define_predicate "fusion_addis_mem_combo_load"
1885 (match_code "mem,zero_extend,float_extend")
1886 {
1887 rtx addr, base, offset;
1888
1889 /* Handle zero/float extend. */
1890 if (GET_CODE (op) == ZERO_EXTEND || GET_CODE (op) == FLOAT_EXTEND)
1891 {
1892 op = XEXP (op, 0);
1893 mode = GET_MODE (op);
1894 }
1895
1896 if (!MEM_P (op))
1897 return 0;
1898
1899 switch (mode)
1900 {
1901 case E_QImode:
1902 case E_HImode:
1903 case E_SImode:
1904 break;
1905
1906 /* Do not fuse 64-bit DImode in 32-bit since it splits into two
1907 separate instructions. */
1908 case E_DImode:
1909 if (!TARGET_POWERPC64)
1910 return 0;
1911 break;
1912
1913 /* ISA 2.08/power8 only had fusion of GPR loads. */
1914 case E_SFmode:
1915 if (!TARGET_P9_FUSION)
1916 return 0;
1917 break;
1918
1919 /* ISA 2.08/power8 only had fusion of GPR loads. Do not allow 64-bit
1920 DFmode in 32-bit if -msoft-float since it splits into two separate
1921 instructions. */
1922 case E_DFmode:
1923 if ((!TARGET_POWERPC64 && !TARGET_DF_FPR) || !TARGET_P9_FUSION)
1924 return 0;
1925 break;
1926
1927 default:
1928 return 0;
1929 }
1930
1931 addr = XEXP (op, 0);
1932 if (GET_CODE (addr) != PLUS && GET_CODE (addr) != LO_SUM)
1933 return 0;
1934
1935 base = XEXP (addr, 0);
1936 if (!fusion_gpr_addis (base, GET_MODE (base)))
1937 return 0;
1938
1939 offset = XEXP (addr, 1);
1940 if (GET_CODE (addr) == PLUS)
1941 return satisfies_constraint_I (offset);
1942
1943 else if (GET_CODE (addr) == LO_SUM)
1944 {
1945 if (TARGET_XCOFF || (TARGET_ELF && TARGET_POWERPC64))
1946 return small_toc_ref (offset, GET_MODE (offset));
1947
1948 else if (TARGET_ELF && !TARGET_POWERPC64)
1949 return CONSTANT_P (offset);
1950 }
1951
1952 return 0;
1953 })
1954
1955 ;; Like fusion_addis_mem_combo_load, but for stores
1956 (define_predicate "fusion_addis_mem_combo_store"
1957 (match_code "mem")
1958 {
1959 rtx addr, base, offset;
1960
1961 if (!MEM_P (op) || !TARGET_P9_FUSION)
1962 return 0;
1963
1964 switch (mode)
1965 {
1966 case E_QImode:
1967 case E_HImode:
1968 case E_SImode:
1969 case E_SFmode:
1970 break;
1971
1972 /* Do not fuse 64-bit DImode in 32-bit since it splits into two
1973 separate instructions. */
1974 case E_DImode:
1975 if (!TARGET_POWERPC64)
1976 return 0;
1977 break;
1978
1979 /* Do not allow 64-bit DFmode in 32-bit if -msoft-float since it splits
1980 into two separate instructions. Do allow fusion if we have hardware
1981 floating point. */
1982 case E_DFmode:
1983 if (!TARGET_POWERPC64 && !TARGET_DF_FPR)
1984 return 0;
1985 break;
1986
1987 default:
1988 return 0;
1989 }
1990
1991 addr = XEXP (op, 0);
1992 if (GET_CODE (addr) != PLUS && GET_CODE (addr) != LO_SUM)
1993 return 0;
1994
1995 base = XEXP (addr, 0);
1996 if (!fusion_gpr_addis (base, GET_MODE (base)))
1997 return 0;
1998
1999 offset = XEXP (addr, 1);
2000 if (GET_CODE (addr) == PLUS)
2001 return satisfies_constraint_I (offset);
2002
2003 else if (GET_CODE (addr) == LO_SUM)
2004 {
2005 if (TARGET_XCOFF || (TARGET_ELF && TARGET_POWERPC64))
2006 return small_toc_ref (offset, GET_MODE (offset));
2007
2008 else if (TARGET_ELF && !TARGET_POWERPC64)
2009 return CONSTANT_P (offset);
2010 }
2011
2012 return 0;
2013 })
2014
2015 ;; Return true if the operand is a float_extend or zero extend of an
2016 ;; offsettable memory operand suitable for use in fusion
2017 (define_predicate "fusion_offsettable_mem_operand"
2018 (match_code "mem,zero_extend,float_extend")
2019 {
2020 if (GET_CODE (op) == ZERO_EXTEND || GET_CODE (op) == FLOAT_EXTEND)
2021 {
2022 op = XEXP (op, 0);
2023 mode = GET_MODE (op);
2024 }
2025
2026 if (!memory_operand (op, mode))
2027 return 0;
2028
2029 return offsettable_nonstrict_memref_p (op);
2030 })