1;; Predicate definitions for ARM and Thumb 2;; Copyright (C) 2004-2013 Free Software Foundation, Inc. 3;; Contributed by ARM Ltd. 4 5;; This file is part of GCC. 6 7;; GCC is free software; you can redistribute it and/or modify it 8;; under the terms of the GNU General Public License as published 9;; by the Free Software Foundation; either version 3, or (at your 10;; option) any later version. 11 12;; GCC is distributed in the hope that it will be useful, but WITHOUT 13;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 15;; License for more details. 16 17;; You should have received a copy of the GNU General Public License 18;; along with GCC; see the file COPYING3. If not see 19;; <http://www.gnu.org/licenses/>. 20 21(define_predicate "s_register_operand" 22 (match_code "reg,subreg") 23{ 24 if (GET_CODE (op) == SUBREG) 25 op = SUBREG_REG (op); 26 /* We don't consider registers whose class is NO_REGS 27 to be a register operand. */ 28 /* XXX might have to check for lo regs only for thumb ??? */ 29 return (REG_P (op) 30 && (REGNO (op) >= FIRST_PSEUDO_REGISTER 31 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS)); 32}) 33 34;; Any general register. 35(define_predicate "arm_hard_general_register_operand" 36 (match_code "reg") 37{ 38 return REGNO (op) <= LAST_ARM_REGNUM; 39}) 40 41;; A low register. 42(define_predicate "low_register_operand" 43 (and (match_code "reg") 44 (match_test "REGNO (op) <= LAST_LO_REGNUM"))) 45 46;; A low register or const_int. 47(define_predicate "low_reg_or_int_operand" 48 (ior (match_code "const_int") 49 (match_operand 0 "low_register_operand"))) 50 51;; Any core register, or any pseudo. */ 52(define_predicate "arm_general_register_operand" 53 (match_code "reg,subreg") 54{ 55 if (GET_CODE (op) == SUBREG) 56 op = SUBREG_REG (op); 57 58 return (REG_P (op) 59 && (REGNO (op) <= LAST_ARM_REGNUM 60 || REGNO (op) >= FIRST_PSEUDO_REGISTER)); 61}) 62 63(define_predicate "vfp_register_operand" 64 (match_code "reg,subreg") 65{ 66 if (GET_CODE (op) == SUBREG) 67 op = SUBREG_REG (op); 68 69 /* We don't consider registers whose class is NO_REGS 70 to be a register operand. */ 71 return (REG_P (op) 72 && (REGNO (op) >= FIRST_PSEUDO_REGISTER 73 || REGNO_REG_CLASS (REGNO (op)) == VFP_D0_D7_REGS 74 || REGNO_REG_CLASS (REGNO (op)) == VFP_LO_REGS 75 || (TARGET_VFPD32 76 && REGNO_REG_CLASS (REGNO (op)) == VFP_REGS))); 77}) 78 79(define_predicate "vfp_hard_register_operand" 80 (match_code "reg") 81{ 82 return (IS_VFP_REGNUM (REGNO (op))); 83}) 84 85(define_predicate "zero_operand" 86 (and (match_code "const_int,const_double,const_vector") 87 (match_test "op == CONST0_RTX (mode)"))) 88 89;; Match a register, or zero in the appropriate mode. 90(define_predicate "reg_or_zero_operand" 91 (ior (match_operand 0 "s_register_operand") 92 (match_operand 0 "zero_operand"))) 93 94(define_special_predicate "subreg_lowpart_operator" 95 (and (match_code "subreg") 96 (match_test "subreg_lowpart_p (op)"))) 97 98;; Reg, subreg(reg) or const_int. 99(define_predicate "reg_or_int_operand" 100 (ior (match_code "const_int") 101 (match_operand 0 "s_register_operand"))) 102 103(define_predicate "arm_immediate_operand" 104 (and (match_code "const_int") 105 (match_test "const_ok_for_arm (INTVAL (op))"))) 106 107;; A constant value which fits into two instructions, each taking 108;; an arithmetic constant operand for one of the words. 109(define_predicate "arm_immediate_di_operand" 110 (and (match_code "const_int,const_double") 111 (match_test "arm_const_double_by_immediates (op)"))) 112 113(define_predicate "arm_neg_immediate_operand" 114 (and (match_code "const_int") 115 (match_test "const_ok_for_arm (-INTVAL (op))"))) 116 117(define_predicate "arm_not_immediate_operand" 118 (and (match_code "const_int") 119 (match_test "const_ok_for_arm (~INTVAL (op))"))) 120 121(define_predicate "const0_operand" 122 (and (match_code "const_int") 123 (match_test "INTVAL (op) == 0"))) 124 125;; Something valid on the RHS of an ARM data-processing instruction 126(define_predicate "arm_rhs_operand" 127 (ior (match_operand 0 "s_register_operand") 128 (match_operand 0 "arm_immediate_operand"))) 129 130(define_predicate "arm_rhsm_operand" 131 (ior (match_operand 0 "arm_rhs_operand") 132 (match_operand 0 "memory_operand"))) 133 134;; This doesn't have to do much because the constant is already checked 135;; in the shift_operator predicate. 136(define_predicate "shift_amount_operand" 137 (ior (and (match_test "TARGET_ARM") 138 (match_operand 0 "s_register_operand")) 139 (match_operand 0 "const_int_operand"))) 140 141(define_predicate "const_neon_scalar_shift_amount_operand" 142 (and (match_code "const_int") 143 (match_test "((unsigned HOST_WIDE_INT) INTVAL (op)) <= GET_MODE_BITSIZE (mode) 144 && ((unsigned HOST_WIDE_INT) INTVAL (op)) > 0"))) 145 146(define_predicate "ldrd_strd_offset_operand" 147 (and (match_operand 0 "const_int_operand") 148 (match_test "TARGET_LDRD && offset_ok_for_ldrd_strd (INTVAL (op))"))) 149 150(define_predicate "arm_add_operand" 151 (ior (match_operand 0 "arm_rhs_operand") 152 (match_operand 0 "arm_neg_immediate_operand"))) 153 154(define_predicate "arm_adddi_operand" 155 (ior (match_operand 0 "s_register_operand") 156 (and (match_code "const_int") 157 (match_test "const_ok_for_dimode_op (INTVAL (op), PLUS)")))) 158 159(define_predicate "arm_addimm_operand" 160 (ior (match_operand 0 "arm_immediate_operand") 161 (match_operand 0 "arm_neg_immediate_operand"))) 162 163(define_predicate "arm_not_operand" 164 (ior (match_operand 0 "arm_rhs_operand") 165 (match_operand 0 "arm_not_immediate_operand"))) 166 167(define_predicate "arm_di_operand" 168 (ior (match_operand 0 "s_register_operand") 169 (match_operand 0 "arm_immediate_di_operand"))) 170 171;; True if the operand is a memory reference which contains an 172;; offsettable address. 173(define_predicate "offsettable_memory_operand" 174 (and (match_code "mem") 175 (match_test 176 "offsettable_address_p (reload_completed | reload_in_progress, 177 mode, XEXP (op, 0))"))) 178 179;; True if the operand is a memory operand that does not have an 180;; automodified base register (and thus will not generate output reloads). 181(define_predicate "call_memory_operand" 182 (and (match_code "mem") 183 (and (match_test "GET_RTX_CLASS (GET_CODE (XEXP (op, 0))) 184 != RTX_AUTOINC") 185 (match_operand 0 "memory_operand")))) 186 187(define_predicate "arm_reload_memory_operand" 188 (and (match_code "mem,reg,subreg") 189 (match_test "(!CONSTANT_P (op) 190 && (true_regnum(op) == -1 191 || (REG_P (op) 192 && REGNO (op) >= FIRST_PSEUDO_REGISTER)))"))) 193 194(define_predicate "vfp_compare_operand" 195 (ior (match_operand 0 "s_register_operand") 196 (and (match_code "const_double") 197 (match_test "arm_const_double_rtx (op)")))) 198 199(define_predicate "arm_float_compare_operand" 200 (if_then_else (match_test "TARGET_VFP") 201 (match_operand 0 "vfp_compare_operand") 202 (match_operand 0 "s_register_operand"))) 203 204;; True for valid index operands. 205(define_predicate "index_operand" 206 (ior (match_operand 0 "s_register_operand") 207 (and (match_operand 0 "immediate_operand") 208 (match_test "(!CONST_INT_P (op) 209 || (INTVAL (op) < 4096 && INTVAL (op) > -4096))")))) 210 211;; True for operators that can be combined with a shift in ARM state. 212(define_special_predicate "shiftable_operator" 213 (and (match_code "plus,minus,ior,xor,and") 214 (match_test "mode == GET_MODE (op)"))) 215 216;; True for logical binary operators. 217(define_special_predicate "logical_binary_operator" 218 (and (match_code "ior,xor,and") 219 (match_test "mode == GET_MODE (op)"))) 220 221;; True for commutative operators 222(define_special_predicate "commutative_binary_operator" 223 (and (match_code "ior,xor,and,plus") 224 (match_test "mode == GET_MODE (op)"))) 225 226;; True for shift operators. 227;; Notes: 228;; * mult is only permitted with a constant shift amount 229;; * patterns that permit register shift amounts only in ARM mode use 230;; shift_amount_operand, patterns that always allow registers do not, 231;; so we don't have to worry about that sort of thing here. 232(define_special_predicate "shift_operator" 233 (and (ior (ior (and (match_code "mult") 234 (match_test "power_of_two_operand (XEXP (op, 1), mode)")) 235 (and (match_code "rotate") 236 (match_test "CONST_INT_P (XEXP (op, 1)) 237 && ((unsigned HOST_WIDE_INT) INTVAL (XEXP (op, 1))) < 32"))) 238 (and (match_code "ashift,ashiftrt,lshiftrt,rotatert") 239 (match_test "!CONST_INT_P (XEXP (op, 1)) 240 || ((unsigned HOST_WIDE_INT) INTVAL (XEXP (op, 1))) < 32"))) 241 (match_test "mode == GET_MODE (op)"))) 242 243;; True for shift operators which can be used with saturation instructions. 244(define_special_predicate "sat_shift_operator" 245 (and (ior (and (match_code "mult") 246 (match_test "power_of_two_operand (XEXP (op, 1), mode)")) 247 (and (match_code "ashift,ashiftrt") 248 (match_test "CONST_INT_P (XEXP (op, 1)) 249 && ((unsigned HOST_WIDE_INT) INTVAL (XEXP (op, 1)) < 32)"))) 250 (match_test "mode == GET_MODE (op)"))) 251 252;; True for MULT, to identify which variant of shift_operator is in use. 253(define_special_predicate "mult_operator" 254 (match_code "mult")) 255 256;; True for operators that have 16-bit thumb variants. */ 257(define_special_predicate "thumb_16bit_operator" 258 (match_code "plus,minus,and,ior,xor")) 259 260;; True for EQ & NE 261(define_special_predicate "equality_operator" 262 (match_code "eq,ne")) 263 264;; True for integer comparisons and, if FP is active, for comparisons 265;; other than LTGT or UNEQ. 266(define_special_predicate "expandable_comparison_operator" 267 (match_code "eq,ne,le,lt,ge,gt,geu,gtu,leu,ltu, 268 unordered,ordered,unlt,unle,unge,ungt")) 269 270;; Likewise, but only accept comparisons that are directly supported 271;; by ARM condition codes. 272(define_special_predicate "arm_comparison_operator" 273 (and (match_operand 0 "expandable_comparison_operator") 274 (match_test "maybe_get_arm_condition_code (op) != ARM_NV"))) 275 276(define_special_predicate "lt_ge_comparison_operator" 277 (match_code "lt,ge")) 278 279(define_special_predicate "noov_comparison_operator" 280 (match_code "lt,ge,eq,ne")) 281 282(define_special_predicate "minmax_operator" 283 (and (match_code "smin,smax,umin,umax") 284 (match_test "mode == GET_MODE (op)"))) 285 286(define_special_predicate "cc_register" 287 (and (match_code "reg") 288 (and (match_test "REGNO (op) == CC_REGNUM") 289 (ior (match_test "mode == GET_MODE (op)") 290 (match_test "mode == VOIDmode && GET_MODE_CLASS (GET_MODE (op)) == MODE_CC"))))) 291 292(define_special_predicate "dominant_cc_register" 293 (match_code "reg") 294{ 295 if (mode == VOIDmode) 296 { 297 mode = GET_MODE (op); 298 299 if (GET_MODE_CLASS (mode) != MODE_CC) 300 return false; 301 } 302 303 return (cc_register (op, mode) 304 && (mode == CC_DNEmode 305 || mode == CC_DEQmode 306 || mode == CC_DLEmode 307 || mode == CC_DLTmode 308 || mode == CC_DGEmode 309 || mode == CC_DGTmode 310 || mode == CC_DLEUmode 311 || mode == CC_DLTUmode 312 || mode == CC_DGEUmode 313 || mode == CC_DGTUmode)); 314}) 315 316(define_special_predicate "arm_extendqisi_mem_op" 317 (and (match_operand 0 "memory_operand") 318 (match_test "TARGET_ARM ? arm_legitimate_address_outer_p (mode, 319 XEXP (op, 0), 320 SIGN_EXTEND, 321 0) 322 : memory_address_p (QImode, XEXP (op, 0))"))) 323 324(define_special_predicate "arm_reg_or_extendqisi_mem_op" 325 (ior (match_operand 0 "arm_extendqisi_mem_op") 326 (match_operand 0 "s_register_operand"))) 327 328(define_predicate "power_of_two_operand" 329 (match_code "const_int") 330{ 331 unsigned HOST_WIDE_INT value = INTVAL (op) & 0xffffffff; 332 333 return value != 0 && (value & (value - 1)) == 0; 334}) 335 336(define_predicate "nonimmediate_di_operand" 337 (match_code "reg,subreg,mem") 338{ 339 if (s_register_operand (op, mode)) 340 return true; 341 342 if (GET_CODE (op) == SUBREG) 343 op = SUBREG_REG (op); 344 345 return MEM_P (op) && memory_address_p (DImode, XEXP (op, 0)); 346}) 347 348(define_predicate "di_operand" 349 (ior (match_code "const_int,const_double") 350 (and (match_code "reg,subreg,mem") 351 (match_operand 0 "nonimmediate_di_operand")))) 352 353(define_predicate "nonimmediate_soft_df_operand" 354 (match_code "reg,subreg,mem") 355{ 356 if (s_register_operand (op, mode)) 357 return true; 358 359 if (GET_CODE (op) == SUBREG) 360 op = SUBREG_REG (op); 361 362 return MEM_P (op) && memory_address_p (DFmode, XEXP (op, 0)); 363}) 364 365(define_predicate "soft_df_operand" 366 (ior (match_code "const_double") 367 (and (match_code "reg,subreg,mem") 368 (match_operand 0 "nonimmediate_soft_df_operand")))) 369 370(define_special_predicate "load_multiple_operation" 371 (match_code "parallel") 372{ 373 return ldm_stm_operation_p (op, /*load=*/true, SImode, 374 /*consecutive=*/false, 375 /*return_pc=*/false); 376}) 377 378(define_special_predicate "store_multiple_operation" 379 (match_code "parallel") 380{ 381 return ldm_stm_operation_p (op, /*load=*/false, SImode, 382 /*consecutive=*/false, 383 /*return_pc=*/false); 384}) 385 386(define_special_predicate "pop_multiple_return" 387 (match_code "parallel") 388{ 389 return ldm_stm_operation_p (op, /*load=*/true, SImode, 390 /*consecutive=*/false, 391 /*return_pc=*/true); 392}) 393 394(define_special_predicate "pop_multiple_fp" 395 (match_code "parallel") 396{ 397 return ldm_stm_operation_p (op, /*load=*/true, DFmode, 398 /*consecutive=*/true, 399 /*return_pc=*/false); 400}) 401 402(define_special_predicate "multi_register_push" 403 (match_code "parallel") 404{ 405 if ((GET_CODE (XVECEXP (op, 0, 0)) != SET) 406 || (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC) 407 || (XINT (SET_SRC (XVECEXP (op, 0, 0)), 1) != UNSPEC_PUSH_MULT)) 408 return false; 409 410 return true; 411}) 412 413(define_predicate "push_mult_memory_operand" 414 (match_code "mem") 415{ 416 /* ??? Given how PUSH_MULT is generated in the prologues, is there 417 any point in testing for thumb1 specially? All of the variants 418 use the same form. */ 419 if (TARGET_THUMB1) 420 { 421 /* ??? No attempt is made to represent STMIA, or validate that 422 the stack adjustment matches the register count. This is 423 true of the ARM/Thumb2 path as well. */ 424 rtx x = XEXP (op, 0); 425 if (GET_CODE (x) != PRE_MODIFY) 426 return false; 427 if (XEXP (x, 0) != stack_pointer_rtx) 428 return false; 429 x = XEXP (x, 1); 430 if (GET_CODE (x) != PLUS) 431 return false; 432 if (XEXP (x, 0) != stack_pointer_rtx) 433 return false; 434 return CONST_INT_P (XEXP (x, 1)); 435 } 436 437 /* ARM and Thumb2 handle pre-modify in their legitimate_address. */ 438 return memory_operand (op, mode); 439}) 440 441;;------------------------------------------------------------------------- 442;; 443;; Thumb predicates 444;; 445 446(define_predicate "thumb1_cmp_operand" 447 (ior (and (match_code "reg,subreg") 448 (match_operand 0 "s_register_operand")) 449 (and (match_code "const_int") 450 (match_test "((unsigned HOST_WIDE_INT) INTVAL (op)) < 256")))) 451 452(define_predicate "thumb1_cmpneg_operand" 453 (and (match_code "const_int") 454 (match_test "INTVAL (op) < 0 && INTVAL (op) > -256"))) 455 456;; Return TRUE if a result can be stored in OP without clobbering the 457;; condition code register. Prior to reload we only accept a 458;; register. After reload we have to be able to handle memory as 459;; well, since a pseudo may not get a hard reg and reload cannot 460;; handle output-reloads on jump insns. 461 462;; We could possibly handle mem before reload as well, but that might 463;; complicate things with the need to handle increment 464;; side-effects. 465(define_predicate "thumb_cbrch_target_operand" 466 (and (match_code "reg,subreg,mem") 467 (ior (match_operand 0 "s_register_operand") 468 (and (match_test "reload_in_progress || reload_completed") 469 (match_operand 0 "memory_operand"))))) 470 471;;------------------------------------------------------------------------- 472;; 473;; iWMMXt predicates 474;; 475 476(define_predicate "imm_or_reg_operand" 477 (ior (match_operand 0 "immediate_operand") 478 (match_operand 0 "register_operand"))) 479 480;; Neon predicates 481 482(define_predicate "const_multiple_of_8_operand" 483 (match_code "const_int") 484{ 485 unsigned HOST_WIDE_INT val = INTVAL (op); 486 return (val & 7) == 0; 487}) 488 489(define_predicate "imm_for_neon_mov_operand" 490 (match_code "const_vector,const_int") 491{ 492 return neon_immediate_valid_for_move (op, mode, NULL, NULL); 493}) 494 495(define_predicate "imm_for_neon_lshift_operand" 496 (match_code "const_vector") 497{ 498 return neon_immediate_valid_for_shift (op, mode, NULL, NULL, true); 499}) 500 501(define_predicate "imm_for_neon_rshift_operand" 502 (match_code "const_vector") 503{ 504 return neon_immediate_valid_for_shift (op, mode, NULL, NULL, false); 505}) 506 507(define_predicate "imm_lshift_or_reg_neon" 508 (ior (match_operand 0 "s_register_operand") 509 (match_operand 0 "imm_for_neon_lshift_operand"))) 510 511(define_predicate "imm_rshift_or_reg_neon" 512 (ior (match_operand 0 "s_register_operand") 513 (match_operand 0 "imm_for_neon_rshift_operand"))) 514 515(define_predicate "imm_for_neon_logic_operand" 516 (match_code "const_vector") 517{ 518 return (TARGET_NEON 519 && neon_immediate_valid_for_logic (op, mode, 0, NULL, NULL)); 520}) 521 522(define_predicate "imm_for_neon_inv_logic_operand" 523 (match_code "const_vector") 524{ 525 return (TARGET_NEON 526 && neon_immediate_valid_for_logic (op, mode, 1, NULL, NULL)); 527}) 528 529(define_predicate "neon_logic_op2" 530 (ior (match_operand 0 "imm_for_neon_logic_operand") 531 (match_operand 0 "s_register_operand"))) 532 533(define_predicate "neon_inv_logic_op2" 534 (ior (match_operand 0 "imm_for_neon_inv_logic_operand") 535 (match_operand 0 "s_register_operand"))) 536 537;; Predicates for named expanders that overlap multiple ISAs. 538 539(define_predicate "cmpdi_operand" 540 (and (match_test "TARGET_32BIT") 541 (match_operand 0 "arm_di_operand"))) 542 543;; True if the operand is memory reference suitable for a ldrex/strex. 544(define_predicate "arm_sync_memory_operand" 545 (and (match_operand 0 "memory_operand") 546 (match_code "reg" "0"))) 547 548;; Predicates for parallel expanders based on mode. 549(define_special_predicate "vect_par_constant_high" 550 (match_code "parallel") 551{ 552 HOST_WIDE_INT count = XVECLEN (op, 0); 553 int i; 554 int base = GET_MODE_NUNITS (mode); 555 556 if ((count < 1) 557 || (count != base/2)) 558 return false; 559 560 if (!VECTOR_MODE_P (mode)) 561 return false; 562 563 for (i = 0; i < count; i++) 564 { 565 rtx elt = XVECEXP (op, 0, i); 566 int val; 567 568 if (!CONST_INT_P (elt)) 569 return false; 570 571 val = INTVAL (elt); 572 if (val != (base/2) + i) 573 return false; 574 } 575 return true; 576}) 577 578(define_special_predicate "vect_par_constant_low" 579 (match_code "parallel") 580{ 581 HOST_WIDE_INT count = XVECLEN (op, 0); 582 int i; 583 int base = GET_MODE_NUNITS (mode); 584 585 if ((count < 1) 586 || (count != base/2)) 587 return false; 588 589 if (!VECTOR_MODE_P (mode)) 590 return false; 591 592 for (i = 0; i < count; i++) 593 { 594 rtx elt = XVECEXP (op, 0, i); 595 int val; 596 597 if (!CONST_INT_P (elt)) 598 return false; 599 600 val = INTVAL (elt); 601 if (val != i) 602 return false; 603 } 604 return true; 605}) 606 607(define_predicate "const_double_vcvt_power_of_two_reciprocal" 608 (and (match_code "const_double") 609 (match_test "TARGET_32BIT && TARGET_VFP 610 && vfp3_const_double_for_fract_bits (op)"))) 611 612(define_predicate "neon_struct_operand" 613 (and (match_code "mem") 614 (match_test "TARGET_32BIT && neon_vector_mem_operand (op, 2)"))) 615 616(define_predicate "neon_struct_or_register_operand" 617 (ior (match_operand 0 "neon_struct_operand") 618 (match_operand 0 "s_register_operand"))) 619 620(define_special_predicate "add_operator" 621 (match_code "plus")) 622 623(define_predicate "mem_noofs_operand" 624 (and (match_code "mem") 625 (match_code "reg" "0"))) 626