| 1 |
;; Constraint definitions for LoongArch. |
| 2 |
;; Copyright (C) 2021-2025 Free Software Foundation, Inc. |
| 3 |
;; Contributed by Loongson Ltd. |
| 4 |
;; |
| 5 |
;; This file is part of GCC. |
| 6 |
;; |
| 7 |
;; 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 |
| 9 |
;; the Free Software Foundation; either version 3, or (at your option) |
| 10 |
;; any later version. |
| 11 |
;; |
| 12 |
;; GCC is distributed in the hope that it will be useful, |
| 13 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
;; GNU General Public 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 |
;; Register constraints |
| 22 |
|
| 23 |
;; "a" <-----unused |
| 24 |
;; "b" "A constant call not local address." |
| 25 |
;; "c" "A constant call local address." |
| 26 |
;; "d" <-----unused |
| 27 |
;; "e" JIRL_REGS |
| 28 |
;; "f" FP_REGS |
| 29 |
;; "g" <-----unused |
| 30 |
;; "h" <-----unused |
| 31 |
;; "i" "Matches a general integer constant." (Global non-architectural) |
| 32 |
;; "j" SIBCALL_REGS |
| 33 |
;; "k" "A memory operand whose address is formed by a base register and |
| 34 |
;; (optionally scaled) index register." |
| 35 |
;; "l" "A signed 16-bit constant." |
| 36 |
;; "m" "A memory operand whose address is formed by a base register and offset |
| 37 |
;; that is suitable for use in instructions with the same addressing mode |
| 38 |
;; as @code{st.w} and @code{ld.w}." |
| 39 |
;; "n" "Matches a non-symbolic integer constant." (Global non-architectural) |
| 40 |
;; "o" "Matches an offsettable memory reference." (Global non-architectural) |
| 41 |
;; "p" "Matches a general address." (Global non-architectural) |
| 42 |
;; "q" CSR_REGS |
| 43 |
;; "r" GENERAL_REGS (Global non-architectural) |
| 44 |
;; "s" "Matches a symbolic integer constant." (Global non-architectural) |
| 45 |
;; "t" <-----unused |
| 46 |
;; "u" "A signed 52bit constant and low 32-bit is zero (for logic instructions)" |
| 47 |
;; "v" "A signed 64-bit constant and low 44-bit is zero (for logic instructions)." |
| 48 |
;; "w" "Matches any valid memory." |
| 49 |
;; "x" <-----unused |
| 50 |
;; "y" <-----unused |
| 51 |
;; "z" FCC_REGS |
| 52 |
;; "A" <-----unused |
| 53 |
;; "B" <-----unused |
| 54 |
;; "C" <-----unused |
| 55 |
;; "D" <-----unused |
| 56 |
;; "E" "Matches a floating-point constant." (Global non-architectural) |
| 57 |
;; "F" "Matches a floating-point constant." (Global non-architectural) |
| 58 |
;; "G" "Floating-point zero." |
| 59 |
;; "H" <-----unused |
| 60 |
;; "I" "A signed 12-bit constant (for arithmetic instructions)." |
| 61 |
;; "J" "Integer zero." |
| 62 |
;; "K" "An unsigned 12-bit constant (for logic instructions)." |
| 63 |
;; "L" - |
| 64 |
;; "La" |
| 65 |
;; "A signed constant in [-4096, 2048) or (2047, 4094]." |
| 66 |
;; "Lb" |
| 67 |
;; "A signed 32-bit constant and low 16-bit is zero, which can be |
| 68 |
;; added onto a register with addu16i.d. It matches nothing if |
| 69 |
;; the addu16i.d instruction is not available." |
| 70 |
;; "Lc" |
| 71 |
;; "A signed 64-bit constant can be expressed as Lb + I, but not a |
| 72 |
;; single Lb or I." |
| 73 |
;; "Ld" |
| 74 |
;; "A signed 64-bit constant can be expressed as Lb + Lb, but not a |
| 75 |
;; single Lb." |
| 76 |
;; "Le" |
| 77 |
;; "A signed 32-bit constant can be expressed as Lb + I, but not a |
| 78 |
;; single Lb or I." |
| 79 |
;; "M" "A constant that cannot be loaded using @code{lui}, @code{addiu} |
| 80 |
;; or @code{ori}." |
| 81 |
;; "N" "A constant in the range -65535 to -1 (inclusive)." |
| 82 |
;; "O" "A signed 15-bit constant." |
| 83 |
;; "P" "A constant in the range 1 to 65535 (inclusive)." |
| 84 |
;; "Q" <-----unused |
| 85 |
;; "R" "An address that can be used in a non-macro load or store." |
| 86 |
;; "S" <-----unused |
| 87 |
;; "T" <-----unused |
| 88 |
;; "U" <-----unused |
| 89 |
;; "V" "Matches a non-offsettable memory reference." (Global non-architectural) |
| 90 |
;; "W" <-----unused |
| 91 |
;; "X" "Matches anything." (Global non-architectural) |
| 92 |
;; "Y" - |
| 93 |
;; "Yd" |
| 94 |
;; "A constant @code{move_operand} that can be safely loaded using |
| 95 |
;; @code{la}." |
| 96 |
;; "Yx" |
| 97 |
;; "Yy" |
| 98 |
;; "Z" - |
| 99 |
;; "ZC" |
| 100 |
;; "A memory operand whose address is formed by a base register and offset |
| 101 |
;; that is suitable for use in instructions with the same addressing mode |
| 102 |
;; as @code{ll.w} and @code{sc.w}." |
| 103 |
;; "ZB" |
| 104 |
;; "An address that is held in a general-purpose register. |
| 105 |
;; The offset is zero" |
| 106 |
;; "ZD" |
| 107 |
;; "An address operand whose address is formed by a base register |
| 108 |
;; and offset that is suitable for use in instructions with the same |
| 109 |
;; addressing mode as @code{preld}." |
| 110 |
;; "<" "Matches a pre-dec or post-dec operand." (Global non-architectural) |
| 111 |
;; ">" "Matches a pre-inc or post-inc operand." (Global non-architectural) |
| 112 |
|
| 113 |
(define_constraint "b" |
| 114 |
"@internal |
| 115 |
A constant call no local address." |
| 116 |
(match_operand 0 "is_const_call_no_local_symbol")) |
| 117 |
|
| 118 |
(define_constraint "c" |
| 119 |
"@internal |
| 120 |
A constant call local address." |
| 121 |
(match_operand 0 "is_const_call_local_symbol")) |
| 122 |
|
| 123 |
(define_register_constraint "e" "JIRL_REGS" |
| 124 |
"@internal") |
| 125 |
|
| 126 |
(define_register_constraint "f" "TARGET_HARD_FLOAT ? FP_REGS : NO_REGS" |
| 127 |
"A floating-point register (if available).") |
| 128 |
|
| 129 |
(define_register_constraint "j" "SIBCALL_REGS" |
| 130 |
"@internal") |
| 131 |
|
| 132 |
(define_memory_constraint "k" |
| 133 |
"A memory operand whose address is formed by a base register and (optionally scaled) |
| 134 |
index register." |
| 135 |
(and (match_code "mem") |
| 136 |
(match_test "loongarch_base_index_address_p (XEXP (op, 0), mode)"))) |
| 137 |
|
| 138 |
(define_constraint "l" |
| 139 |
"A signed 16-bit constant." |
| 140 |
(and (match_code "const_int") |
| 141 |
(match_test "IMM16_OPERAND (ival)"))) |
| 142 |
|
| 143 |
(define_memory_constraint "m" |
| 144 |
"A memory operand whose address is formed by a base register and offset |
| 145 |
that is suitable for use in instructions with the same addressing mode |
| 146 |
as @code{st.w} and @code{ld.w}." |
| 147 |
(and (match_code "mem") |
| 148 |
(match_test "loongarch_12bit_offset_address_p (XEXP (op, 0), mode)"))) |
| 149 |
|
| 150 |
(define_register_constraint "q" "CSR_REGS" |
| 151 |
"A general-purpose register except for $r0 and $r1 for lcsr.") |
| 152 |
|
| 153 |
(define_constraint "u" |
| 154 |
"A signed 52bit constant and low 32-bit is zero (for logic instructions)." |
| 155 |
(and (match_code "const_int") |
| 156 |
(match_test "LU32I_OPERAND (ival)"))) |
| 157 |
|
| 158 |
(define_constraint "v" |
| 159 |
"A signed 64-bit constant and low 44-bit is zero (for logic instructions)." |
| 160 |
(and (match_code "const_int") |
| 161 |
(match_test "LU52I_OPERAND (ival)"))) |
| 162 |
|
| 163 |
(define_register_constraint "z" "FCC_REGS" |
| 164 |
"A floating-point condition code register.") |
| 165 |
|
| 166 |
;; Floating-point constraints |
| 167 |
|
| 168 |
(define_constraint "G" |
| 169 |
"Floating-point zero." |
| 170 |
(and (match_code "const_double") |
| 171 |
(match_test "op == CONST0_RTX (mode)"))) |
| 172 |
|
| 173 |
;; Integer constraints |
| 174 |
|
| 175 |
(define_constraint "I" |
| 176 |
"A signed 12-bit constant (for arithmetic instructions)." |
| 177 |
(and (match_code "const_int") |
| 178 |
(match_test "IMM12_OPERAND (ival)"))) |
| 179 |
|
| 180 |
(define_constraint "J" |
| 181 |
"Integer zero." |
| 182 |
(and (match_code "const_int") |
| 183 |
(match_test "ival == 0"))) |
| 184 |
|
| 185 |
(define_constraint "K" |
| 186 |
"An unsigned 12-bit constant (for logic instructions)." |
| 187 |
(and (match_code "const_int") |
| 188 |
(match_test "IMM12_OPERAND_UNSIGNED (ival)"))) |
| 189 |
|
| 190 |
(define_constraint "La" |
| 191 |
"A signed constant in [-4096, 2048) or (2047, 4094]." |
| 192 |
(and (match_code "const_int") |
| 193 |
(match_test "DUAL_IMM12_OPERAND (ival)"))) |
| 194 |
|
| 195 |
(define_constraint "Lb" |
| 196 |
"A signed 32-bit constant and low 16-bit is zero, which can be added |
| 197 |
onto a register with addu16i.d." |
| 198 |
(and (match_code "const_int") |
| 199 |
(match_test "ADDU16I_OPERAND (ival)"))) |
| 200 |
|
| 201 |
(define_constraint "Lc" |
| 202 |
"A signed 64-bit constant can be expressed as Lb + I, but not a single Lb |
| 203 |
or I." |
| 204 |
(and (match_code "const_int") |
| 205 |
(match_test "loongarch_addu16i_imm12_operand_p (ival, DImode)"))) |
| 206 |
|
| 207 |
(define_constraint "Ld" |
| 208 |
"A signed 64-bit constant can be expressed as Lb + Lb, but not a single |
| 209 |
Lb." |
| 210 |
(and (match_code "const_int") |
| 211 |
(match_test "DUAL_ADDU16I_OPERAND (ival)"))) |
| 212 |
|
| 213 |
(define_constraint "Le" |
| 214 |
"A signed 32-bit constant can be expressed as Lb + I, but not a single Lb |
| 215 |
or I." |
| 216 |
(and (match_code "const_int") |
| 217 |
(match_test "loongarch_addu16i_imm12_operand_p (ival, SImode)"))) |
| 218 |
|
| 219 |
(define_constraint "M" |
| 220 |
"A constant that cannot be loaded using @code{lui}, @code{addiu} |
| 221 |
or @code{ori}." |
| 222 |
(and (match_code "const_int") |
| 223 |
(not (match_test "IMM12_OPERAND (ival)")) |
| 224 |
(not (match_test "IMM12_OPERAND_UNSIGNED (ival)")) |
| 225 |
(not (match_test "LU12I_OPERAND (ival)")))) |
| 226 |
|
| 227 |
(define_constraint "N" |
| 228 |
"A constant in the range -65535 to -1 (inclusive)." |
| 229 |
(and (match_code "const_int") |
| 230 |
(match_test "ival >= -0xffff && ival < 0"))) |
| 231 |
|
| 232 |
(define_constraint "O" |
| 233 |
"A signed 15-bit constant." |
| 234 |
(and (match_code "const_int") |
| 235 |
(match_test "ival >= -0x4000 && ival < 0x4000"))) |
| 236 |
|
| 237 |
(define_constraint "P" |
| 238 |
"A constant in the range 1 to 65535 (inclusive)." |
| 239 |
(and (match_code "const_int") |
| 240 |
(match_test "ival > 0 && ival < 0x10000"))) |
| 241 |
|
| 242 |
;; General constraints |
| 243 |
|
| 244 |
(define_memory_constraint "R" |
| 245 |
"An address that can be used in a non-macro load or store." |
| 246 |
(and (match_code "mem") |
| 247 |
(match_test "loongarch_address_insns (XEXP (op, 0), mode, false) == 1"))) |
| 248 |
(define_constraint "S" |
| 249 |
"@internal |
| 250 |
A constant call address." |
| 251 |
(and (match_operand 0 "call_insn_operand") |
| 252 |
(match_test "CONSTANT_P (op)"))) |
| 253 |
|
| 254 |
(define_constraint "YG" |
| 255 |
"@internal |
| 256 |
A vector zero." |
| 257 |
(and (match_code "const_vector") |
| 258 |
(match_test "op == CONST0_RTX (mode)"))) |
| 259 |
|
| 260 |
(define_constraint "YA" |
| 261 |
"@internal |
| 262 |
An unsigned 6-bit constant." |
| 263 |
(and (match_code "const_int") |
| 264 |
(match_test "UIMM6_OPERAND (ival)"))) |
| 265 |
|
| 266 |
(define_constraint "YB" |
| 267 |
"@internal |
| 268 |
A signed 10-bit constant." |
| 269 |
(and (match_code "const_int") |
| 270 |
(match_test "IMM10_OPERAND (ival)"))) |
| 271 |
|
| 272 |
(define_constraint "Yb" |
| 273 |
"@internal" |
| 274 |
(match_operand 0 "qi_mask_operand")) |
| 275 |
|
| 276 |
(define_constraint "Yd" |
| 277 |
"@internal |
| 278 |
A constant @code{move_operand} that can be safely loaded using |
| 279 |
@code{la}." |
| 280 |
(and (match_operand 0 "move_operand") |
| 281 |
(match_test "CONSTANT_P (op)"))) |
| 282 |
|
| 283 |
(define_constraint "Yh" |
| 284 |
"@internal" |
| 285 |
(match_operand 0 "hi_mask_operand")) |
| 286 |
|
| 287 |
(define_constraint "Yw" |
| 288 |
"@internal" |
| 289 |
(match_operand 0 "si_mask_operand")) |
| 290 |
|
| 291 |
(define_constraint "Yx" |
| 292 |
"@internal" |
| 293 |
(match_operand 0 "low_bitmask_operand")) |
| 294 |
|
| 295 |
(define_constraint "Yy" |
| 296 |
"@internal" |
| 297 |
(match_operand 0 "ins_zero_bitmask_operand")) |
| 298 |
|
| 299 |
(define_constraint "YI" |
| 300 |
"@internal |
| 301 |
A replicated vector const in which the replicated value is in the range |
| 302 |
[-512,511]." |
| 303 |
(and (match_code "const_vector") |
| 304 |
(match_test "loongarch_const_vector_vrepli (op, mode)"))) |
| 305 |
|
| 306 |
(define_constraint "YC" |
| 307 |
"@internal |
| 308 |
A replicated vector const in which the replicated value has a single |
| 309 |
bit set." |
| 310 |
(and (match_code "const_vector") |
| 311 |
(match_test "loongarch_const_vector_bitimm_set_p (op, mode)"))) |
| 312 |
|
| 313 |
(define_constraint "YZ" |
| 314 |
"@internal |
| 315 |
A replicated vector const in which the replicated value has a single |
| 316 |
bit clear." |
| 317 |
(and (match_code "const_vector") |
| 318 |
(match_test "loongarch_const_vector_bitimm_clr_p (op, mode)"))) |
| 319 |
|
| 320 |
(define_constraint "Unv5" |
| 321 |
"@internal |
| 322 |
A replicated vector const in which the replicated value is in the range |
| 323 |
[-31,0]." |
| 324 |
(and (match_code "const_vector") |
| 325 |
(match_test "loongarch_const_vector_same_int_p (op, mode, -31, 0)"))) |
| 326 |
|
| 327 |
(define_constraint "Uuv5" |
| 328 |
"@internal |
| 329 |
A replicated vector const in which the replicated value is in the range |
| 330 |
[0,31]." |
| 331 |
(and (match_code "const_vector") |
| 332 |
(match_test "loongarch_const_vector_same_int_p (op, mode, 0, 31)"))) |
| 333 |
|
| 334 |
(define_constraint "Usv5" |
| 335 |
"@internal |
| 336 |
A replicated vector const in which the replicated value is in the range |
| 337 |
[-16,15]." |
| 338 |
(and (match_code "const_vector") |
| 339 |
(match_test "loongarch_const_vector_same_int_p (op, mode, -16, 15)"))) |
| 340 |
|
| 341 |
(define_constraint "Urv8" |
| 342 |
"@internal |
| 343 |
A replicated vector const with replicated byte values as well as elements" |
| 344 |
(and (match_code "const_vector") |
| 345 |
(match_test "loongarch_const_vector_same_bytes_p (op, mode)"))) |
| 346 |
|
| 347 |
(define_constraint "Uuvx" |
| 348 |
"@internal |
| 349 |
A replicated vector const in which the replicated value is in the unsigned |
| 350 |
range [0,umax]." |
| 351 |
(and (match_code "const_vector") |
| 352 |
(match_test "loongarch_const_vector_same_int_p (op, mode)"))) |
| 353 |
|
| 354 |
(define_memory_constraint "ZC" |
| 355 |
"A memory operand whose address is formed by a base register and offset |
| 356 |
that is suitable for use in instructions with the same addressing mode |
| 357 |
as @code{ll.w} and @code{sc.w}." |
| 358 |
(and (match_code "mem") |
| 359 |
(match_test "loongarch_14bit_shifted_offset_address_p (XEXP (op, 0), mode)"))) |
| 360 |
|
| 361 |
(define_memory_constraint "ZB" |
| 362 |
"@internal |
| 363 |
An address that is held in a general-purpose register. |
| 364 |
The offset is zero" |
| 365 |
(and (match_code "mem") |
| 366 |
(match_test "REG_P (XEXP (op, 0))"))) |
| 367 |
|
| 368 |
(define_address_constraint "ZD" |
| 369 |
"An address operand whose address is formed by a base register |
| 370 |
and offset that is suitable for use in instructions with the same |
| 371 |
addressing mode as @code{preld}." |
| 372 |
(match_test "loongarch_12bit_offset_address_p (op, mode)")) |
| 373 |
|
| 374 |
(define_constraint "ZE" |
| 375 |
"A symbolic suitable as stack canary in the normal/medium code model." |
| 376 |
(match_operand 0 "ssp_normal_operand")) |
| 377 |
|
| 378 |
(define_constraint "ZF" |
| 379 |
"A symbolic suitable as stack canary, but in the extreme code model." |
| 380 |
(and (match_operand 0 "ssp_operand") |
| 381 |
(not (match_operand 0 "ssp_normal_operand")))) |