1 ;; Constraint definitions for RISC-V target.
2 ;; Copyright (C) 2011-2024 Free Software Foundation, Inc.
3 ;; Contributed by Andrew Waterman (andrew@sifive.com).
4 ;; Based on MIPS target for GNU compiler.
6 ;; This file is part of GCC.
8 ;; GCC is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 3, or (at your option)
13 ;; GCC is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING3. If not see
20 ;; <http://www.gnu.org/licenses/>.
22 ;; Register constraints
24 (define_register_constraint "f" "TARGET_HARD_FLOAT ? FP_REGS :
25 (TARGET_ZFINX ? GR_REGS : NO_REGS)"
26 "A floating-point register (if available, reuse GPR as FPR when use zfinx).")
28 (define_register_constraint "j" "SIBCALL_REGS"
31 ;; Avoid using register t0 for JALR's argument, because for some
32 ;; microarchitectures that is a return-address stack hint.
33 (define_register_constraint "l" "JALR_REGS"
36 ;; General constraints
38 (define_constraint "I"
39 "An I-type 12-bit signed immediate."
40 (and (match_code "const_int")
41 (match_test "SMALL_OPERAND (ival)")))
43 (define_constraint "J"
45 (and (match_code "const_int")
46 (match_test "ival == 0")))
48 (define_constraint "c01"
50 (and (match_code "const_int")
51 (match_test "ival == 1")))
53 (define_constraint "c02"
55 (and (match_code "const_int")
56 (match_test "ival == 2")))
58 (define_constraint "c03"
60 (and (match_code "const_int")
61 (match_test "ival == 3")))
63 (define_constraint "c04"
65 (and (match_code "const_int")
66 (match_test "ival == 4")))
68 (define_constraint "c08"
70 (and (match_code "const_int")
71 (match_test "ival == 8")))
73 (define_constraint "K"
74 "A 5-bit unsigned immediate for CSR access instructions."
75 (and (match_code "const_int")
76 (match_test "IN_RANGE (ival, 0, 31)")))
78 (define_constraint "L"
79 "A U-type 20-bit signed immediate."
80 (and (match_code "const_int")
81 (match_test "LUI_OPERAND (ival)")))
83 (define_constraint "Ds3"
86 (and (match_code "const_int")
87 (match_test "IN_RANGE (ival, 1, 3)")))
89 (define_constraint "DsS"
92 (and (match_code "const_int")
93 (match_test "(ival & 31) == 31")))
95 (define_constraint "DsD"
98 (and (match_code "const_int")
99 (match_test "(ival & 63) == 63")))
101 (define_constraint "DbS"
103 (and (match_code "const_int")
104 (match_test "SINGLE_BIT_MASK_OPERAND (ival)")))
106 (define_constraint "DnS"
108 (and (match_code "const_int")
109 (match_test "SINGLE_BIT_MASK_OPERAND (~ival)")))
111 ;; Floating-point constant +0.0, used for FCVT-based moves when FMV is
112 ;; not available in RV32.
113 (define_constraint "G"
115 (and (match_code "const_double")
116 (match_test "op == CONST0_RTX (mode)")))
118 (define_memory_constraint "A"
119 "An address that is held in a general-purpose register."
120 (and (match_code "mem")
121 (match_test "GET_CODE(XEXP(op,0)) == REG")))
123 (define_constraint "S"
124 "A constraint that matches an absolute symbolic address."
125 (match_operand 0 "absolute_symbolic_operand"))
127 (define_constraint "U"
129 A PLT-indirect call address."
130 (match_operand 0 "plt_symbolic_operand"))
132 (define_constraint "T"
134 A constant @code{move_operand}."
135 (and (match_operand 0 "move_operand")
136 (match_test "CONSTANT_P (op)")))
140 (define_constraint "zfli"
141 "A floating point number that can be loaded using instruction `fli` in zfa."
142 (and (match_code "const_double")
143 (match_test "TARGET_ZFA && (riscv_float_const_rtx_index_for_fli (op) != -1)")))
145 (define_register_constraint "zmvf" "(TARGET_ZFA || TARGET_XTHEADFMV) ? FP_REGS : NO_REGS"
146 "A floating-point register for ZFA or XTheadFmv.")
148 (define_register_constraint "zmvr" "(TARGET_ZFA || TARGET_XTHEADFMV) ? GR_REGS : NO_REGS"
149 "An integer register for ZFA or XTheadFmv.")
151 ;; Vector constraints.
153 (define_register_constraint "vr" "TARGET_VECTOR ? V_REGS : NO_REGS"
154 "A vector register (if available).")
156 (define_register_constraint "vd" "TARGET_VECTOR ? VD_REGS : NO_REGS"
157 "A vector register except mask register (if available).")
159 (define_register_constraint "vm" "TARGET_VECTOR ? VM_REGS : NO_REGS"
160 "A vector mask register (if available).")
162 ;; These following constraints are used by RVV instructions with dest EEW > src EEW.
163 ;; RISC-V 'V' Spec 5.2. Vector Operands:
164 ;; The destination EEW is greater than the source EEW, the source EMUL is at least 1,
165 ;; and the overlap is in the highest-numbered part of the destination register group.
166 ;; (e.g., when LMUL=8, vzext.vf4 v0, v6 is legal, but a source of v0, v2, or v4 is not).
167 (define_register_constraint "W21" "TARGET_VECTOR ? V_REGS : NO_REGS"
168 "A vector register has register number % 2 == 1." "regno % 2 == 1")
170 (define_register_constraint "W42" "TARGET_VECTOR ? V_REGS : NO_REGS"
171 "A vector register has register number % 4 == 2." "regno % 4 == 2")
173 (define_register_constraint "W84" "TARGET_VECTOR ? V_REGS : NO_REGS"
174 "A vector register has register number % 8 == 4." "regno % 8 == 4")
176 (define_register_constraint "W43" "TARGET_VECTOR ? V_REGS : NO_REGS"
177 "A vector register has register number % 4 == 3." "regno % 4 == 3")
179 (define_register_constraint "W86" "TARGET_VECTOR ? V_REGS : NO_REGS"
180 "A vector register has register number % 8 == 6." "regno % 8 == 6")
182 (define_register_constraint "W87" "TARGET_VECTOR ? V_REGS : NO_REGS"
183 "A vector register has register number % 8 == 7." "regno % 8 == 7")
185 ;; This constraint is used to match instruction "csrr %0, vlenb" which is generated in "mov<mode>".
186 ;; VLENB is a run-time constant which represent the vector register length in bytes.
187 ;; BYTES_PER_RISCV_VECTOR represent runtime invariant of vector register length in bytes.
188 ;; We should only allow the poly equal to BYTES_PER_RISCV_VECTOR.
189 (define_constraint "vp"
191 (and (match_code "const_poly_int")
192 (match_test "known_eq (rtx_to_poly_int64 (op), BYTES_PER_RISCV_VECTOR)")))
194 (define_constraint "vu"
195 "A undefined vector value."
196 (and (match_code "unspec")
197 (match_test "XINT (op, 1) == UNSPEC_VUNDEF")))
199 (define_constraint "vi"
200 "A vector 5-bit signed immediate."
201 (and (match_code "const_vector")
202 (match_test "riscv_vector::const_vec_all_same_in_range_p (op, -16, 15)")))
204 (define_constraint "vj"
205 "A vector negated 5-bit signed immediate."
206 (and (match_code "const_vector")
207 (match_test "riscv_vector::const_vec_all_same_in_range_p (op, -15, 16)")))
209 (define_constraint "vk"
210 "A vector 5-bit unsigned immediate."
211 (and (match_code "const_vector")
212 (match_test "riscv_vector::const_vec_all_same_in_range_p (op, 0, 31)")))
214 (define_constraint "Wc0"
216 A constraint that matches a vector of immediate all zeros."
217 (and (match_code "const_vector")
218 (match_test "op == CONST0_RTX (GET_MODE (op))")))
220 (define_constraint "Wc1"
222 A constraint that matches a vector of immediate all ones."
223 (and (match_code "const_vector")
224 (match_test "op == CONSTM1_RTX (GET_MODE (op))")))
226 (define_constraint "Wb1"
228 A constraint that matches a BOOL vector of {...,0,...0,1}"
229 (and (match_code "const_vector")
230 (match_test "rtx_equal_p (op, riscv_vector::gen_scalar_move_mask (GET_MODE (op)))")))
232 (define_memory_constraint "Wdm"
233 "Vector duplicate memory operand"
234 (and (match_code "mem")
235 (match_code "reg" "0")))
237 ;; Vendor ISA extension constraints.
239 (define_memory_constraint "th_m_mia"
241 A MEM with a valid address for th.[l|s]*ia instructions."
242 (and (match_code "mem")
243 (match_test "th_memidx_legitimate_modify_p (op, true)")))
245 (define_memory_constraint "th_m_mib"
247 A MEM with a valid address for th.[l|s]*ib instructions."
248 (and (match_code "mem")
249 (match_test "th_memidx_legitimate_modify_p (op, false)")))
251 (define_memory_constraint "th_m_mir"
253 A MEM with a valid address for th.[l|s]*r* instructions."
254 (and (match_code "mem")
255 (match_test "th_memidx_legitimate_index_p (op, false)")))
257 (define_memory_constraint "th_m_miu"
259 A MEM with a valid address for th.[l|s]*ur* instructions."
260 (and (match_code "mem")
261 (match_test "th_memidx_legitimate_index_p (op, true)")))
263 ;; CORE-V Constraints
264 (define_constraint "CV_alu_pow2"
266 Checking for CORE-V ALU clip if ival plus 1 is a power of 2"
267 (and (match_code "const_int")
268 (and (match_test "IN_RANGE (ival, 0, 1073741823)")
269 (match_test "exact_log2 (ival + 1) != -1"))))
271 (define_constraint "CV_simd_si6"
272 "A 6-bit signed immediate for SIMD."
273 (and (match_code "const_int")
274 (match_test "IN_RANGE (ival, -32, 31)")))
276 (define_constraint "CV_simd_un6"
277 "A 6-bit unsigned immediate for SIMD."
278 (and (match_code "const_int")
279 (match_test "IN_RANGE (ival, 0, 63)")))
281 (define_constraint "CV_simd_i01"
282 "Shifting immediate for SIMD shufflei1."
283 (and (match_code "const_int")
284 (match_test "IN_RANGE (ival, 64, 127)")))
286 (define_constraint "CV_simd_i02"
287 "Shifting immediate for SIMD shufflei2."
288 (and (match_code "const_int")
289 (match_test "IN_RANGE (ival, -128, -65)")))
291 (define_constraint "CV_simd_i03"
292 "Shifting immediate for SIMD shufflei3."
293 (and (match_code "const_int")
294 (match_test "IN_RANGE (ival, -64, -1)")))