1 ;; Predicate definitions for S/390 and zSeries.
2 ;; Copyright (C) 2005, 2007, 2008 Free Software Foundation, Inc.
3 ;; Contributed by Hartmut Penner (hpenner@de.ibm.com) and
4 ;; Ulrich Weigand (uweigand@de.ibm.com).
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 ;; OP is the current operation.
23 ;; MODE is the current operation mode.
25 ;; operands --------------------------------------------------------------
27 ;; Return true if OP a (const_int 0) operand.
29 (define_predicate "const0_operand"
30 (and (match_code "const_int, const_double")
31 (match_test "op == CONST0_RTX (mode)")))
33 ;; Return true if OP is constant.
35 (define_special_predicate "consttable_operand"
36 (and (match_code "symbol_ref, label_ref, const, const_int, const_double")
37 (match_test "CONSTANT_P (op)")))
39 ;; Return true if OP is a valid S-type operand.
41 (define_predicate "s_operand"
42 (and (match_code "subreg, mem")
43 (match_operand 0 "general_operand"))
45 /* Just like memory_operand, allow (subreg (mem ...))
48 && GET_CODE (op) == SUBREG
49 && GET_CODE (SUBREG_REG (op)) == MEM)
52 if (GET_CODE (op) != MEM)
54 if (!s390_legitimate_address_without_index_p (op))
60 ;; Return true if OP is a valid operand for the BRAS instruction.
61 ;; Allow SYMBOL_REFs and @PLT stubs.
63 (define_special_predicate "bras_sym_operand"
64 (ior (and (match_code "symbol_ref")
65 (match_test "!flag_pic || SYMBOL_REF_LOCAL_P (op)"))
66 (and (match_code "const")
67 (and (match_test "GET_CODE (XEXP (op, 0)) == UNSPEC")
68 (match_test "XINT (XEXP (op, 0), 1) == UNSPEC_PLT")))))
70 ;; Return true if OP is a PLUS that is not a legitimate
71 ;; operand for the LA instruction.
73 (define_predicate "s390_plus_operand"
74 (and (match_code "plus")
75 (and (match_test "mode == Pmode")
76 (match_test "!legitimate_la_operand_p (op)"))))
78 ;; Return true if OP is a valid operand as shift count or setmem.
80 (define_predicate "shift_count_or_setmem_operand"
81 (match_code "reg, subreg, plus, const_int")
86 /* Extract base register and offset. */
87 if (!s390_decompose_shift_count (op, &base, &offset))
90 /* Don't allow any non-base hard registers. Doing so without
91 confusing reload and/or regrename would be tricky, and doesn't
92 buy us much anyway. */
93 if (base && REGNO (base) < FIRST_PSEUDO_REGISTER && !ADDR_REG_P (base))
96 /* Unfortunately we have to reject constants that are invalid
97 for an address, or else reload will get confused. */
98 if (!DISP_IN_RANGE (offset))
104 ;; Return true if OP a valid operand for the LARL instruction.
106 (define_predicate "larl_operand"
107 (match_code "label_ref, symbol_ref, const, const_int, const_double")
109 /* Allow labels and local symbols. */
110 if (GET_CODE (op) == LABEL_REF)
112 if (GET_CODE (op) == SYMBOL_REF)
113 return (!SYMBOL_REF_ALIGN1_P (op)
114 && SYMBOL_REF_TLS_MODEL (op) == 0
115 && (!flag_pic || SYMBOL_REF_LOCAL_P (op)));
117 /* Everything else must have a CONST, so strip it. */
118 if (GET_CODE (op) != CONST)
122 /* Allow adding *even* in-range constants. */
123 if (GET_CODE (op) == PLUS)
125 if (GET_CODE (XEXP (op, 1)) != CONST_INT
126 || (INTVAL (XEXP (op, 1)) & 1) != 0)
128 if (INTVAL (XEXP (op, 1)) >= (HOST_WIDE_INT)1 << 31
129 || INTVAL (XEXP (op, 1)) < -((HOST_WIDE_INT)1 << 31))
134 /* Labels and local symbols allowed here as well. */
135 if (GET_CODE (op) == LABEL_REF)
137 if (GET_CODE (op) == SYMBOL_REF)
138 return ((SYMBOL_REF_FLAGS (op) & SYMBOL_FLAG_ALIGN1) == 0
139 && SYMBOL_REF_TLS_MODEL (op) == 0
140 && (!flag_pic || SYMBOL_REF_LOCAL_P (op)));
142 /* Now we must have a @GOTENT offset or @PLT stub
143 or an @INDNTPOFF TLS offset. */
144 if (GET_CODE (op) == UNSPEC
145 && XINT (op, 1) == UNSPEC_GOTENT)
147 if (GET_CODE (op) == UNSPEC
148 && XINT (op, 1) == UNSPEC_PLT)
150 if (GET_CODE (op) == UNSPEC
151 && XINT (op, 1) == UNSPEC_INDNTPOFF)
157 ;; operators --------------------------------------------------------------
159 ;; Return nonzero if OP is a valid comparison operator
160 ;; for a branch condition.
162 (define_predicate "s390_comparison"
163 (match_code "eq, ne, lt, gt, le, ge, ltu, gtu, leu, geu,
164 uneq, unlt, ungt, unle, unge, ltgt,
167 if (GET_CODE (XEXP (op, 0)) != REG
168 || REGNO (XEXP (op, 0)) != CC_REGNUM
169 || XEXP (op, 1) != const0_rtx)
172 return (s390_branch_condition_mask (op) >= 0);
175 ;; Return true if op is the cc register.
176 (define_predicate "cc_reg_operand"
177 (and (match_code "reg")
178 (match_test "REGNO (op) == CC_REGNUM")))
180 (define_predicate "s390_signed_integer_comparison"
181 (match_code "eq, ne, lt, gt, le, ge")
183 return (s390_compare_and_branch_condition_mask (op) >= 0);
186 (define_predicate "s390_unsigned_integer_comparison"
187 (match_code "eq, ne, ltu, gtu, leu, geu")
189 return (s390_compare_and_branch_condition_mask (op) >= 0);
192 ;; Return nonzero if OP is a valid comparison operator for the
193 ;; cstore expanders -- respectively cstorecc4 and integer cstore.
194 (define_predicate "s390_eqne_operator"
195 (match_code "eq, ne"))
197 (define_predicate "s390_scond_operator"
198 (match_code "ltu, gtu, leu, geu"))
200 (define_predicate "s390_brx_operator"
201 (match_code "le, gt"))
203 ;; Return nonzero if OP is a valid comparison operator
204 ;; for an ALC condition.
206 (define_predicate "s390_alc_comparison"
207 (match_code "zero_extend, sign_extend, ltu, gtu, leu, geu")
209 while (GET_CODE (op) == ZERO_EXTEND || GET_CODE (op) == SIGN_EXTEND)
212 if (!COMPARISON_P (op))
215 if (GET_CODE (XEXP (op, 0)) != REG
216 || REGNO (XEXP (op, 0)) != CC_REGNUM
217 || XEXP (op, 1) != const0_rtx)
220 switch (GET_MODE (XEXP (op, 0)))
223 return GET_CODE (op) == LTU;
226 return GET_CODE (op) == LEU;
229 return GET_CODE (op) == GEU;
232 return GET_CODE (op) == GTU;
235 return GET_CODE (op) == LTU;
238 return GET_CODE (op) == UNGT;
241 return GET_CODE (op) == UNLT;
248 ;; Return nonzero if OP is a valid comparison operator
249 ;; for an SLB condition.
251 (define_predicate "s390_slb_comparison"
252 (match_code "zero_extend, sign_extend, ltu, gtu, leu, geu")
254 while (GET_CODE (op) == ZERO_EXTEND || GET_CODE (op) == SIGN_EXTEND)
257 if (!COMPARISON_P (op))
260 if (GET_CODE (XEXP (op, 0)) != REG
261 || REGNO (XEXP (op, 0)) != CC_REGNUM
262 || XEXP (op, 1) != const0_rtx)
265 switch (GET_MODE (XEXP (op, 0)))
268 return GET_CODE (op) == GEU;
271 return GET_CODE (op) == GTU;
274 return GET_CODE (op) == LTU;
277 return GET_CODE (op) == LEU;
280 return GET_CODE (op) == GEU;
283 return GET_CODE (op) == LE;
286 return GET_CODE (op) == GE;
293 ;; Return true if OP is a load multiple operation. It is known to be a
294 ;; PARALLEL and the first section will be tested.
296 (define_special_predicate "load_multiple_operation"
297 (match_code "parallel")
299 enum machine_mode elt_mode;
300 int count = XVECLEN (op, 0);
301 unsigned int dest_regno;
305 /* Perform a quick check so we don't blow up below. */
307 || GET_CODE (XVECEXP (op, 0, 0)) != SET
308 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
309 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
312 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
313 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
314 elt_mode = GET_MODE (SET_DEST (XVECEXP (op, 0, 0)));
316 /* Check, is base, or base + displacement. */
318 if (GET_CODE (src_addr) == REG)
320 else if (GET_CODE (src_addr) == PLUS
321 && GET_CODE (XEXP (src_addr, 0)) == REG
322 && GET_CODE (XEXP (src_addr, 1)) == CONST_INT)
324 off = INTVAL (XEXP (src_addr, 1));
325 src_addr = XEXP (src_addr, 0);
330 for (i = 1; i < count; i++)
332 rtx elt = XVECEXP (op, 0, i);
334 if (GET_CODE (elt) != SET
335 || GET_CODE (SET_DEST (elt)) != REG
336 || GET_MODE (SET_DEST (elt)) != elt_mode
337 || REGNO (SET_DEST (elt)) != dest_regno + i
338 || GET_CODE (SET_SRC (elt)) != MEM
339 || GET_MODE (SET_SRC (elt)) != elt_mode
340 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
341 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
342 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
343 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1))
344 != off + i * GET_MODE_SIZE (elt_mode))
351 ;; Return true if OP is a store multiple operation. It is known to be a
352 ;; PARALLEL and the first section will be tested.
354 (define_special_predicate "store_multiple_operation"
355 (match_code "parallel")
357 enum machine_mode elt_mode;
358 int count = XVECLEN (op, 0);
359 unsigned int src_regno;
363 /* Perform a quick check so we don't blow up below. */
365 || GET_CODE (XVECEXP (op, 0, 0)) != SET
366 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
367 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
370 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
371 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
372 elt_mode = GET_MODE (SET_SRC (XVECEXP (op, 0, 0)));
374 /* Check, is base, or base + displacement. */
376 if (GET_CODE (dest_addr) == REG)
378 else if (GET_CODE (dest_addr) == PLUS
379 && GET_CODE (XEXP (dest_addr, 0)) == REG
380 && GET_CODE (XEXP (dest_addr, 1)) == CONST_INT)
382 off = INTVAL (XEXP (dest_addr, 1));
383 dest_addr = XEXP (dest_addr, 0);
388 for (i = 1; i < count; i++)
390 rtx elt = XVECEXP (op, 0, i);
392 if (GET_CODE (elt) != SET
393 || GET_CODE (SET_SRC (elt)) != REG
394 || GET_MODE (SET_SRC (elt)) != elt_mode
395 || REGNO (SET_SRC (elt)) != src_regno + i
396 || GET_CODE (SET_DEST (elt)) != MEM
397 || GET_MODE (SET_DEST (elt)) != elt_mode
398 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
399 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
400 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
401 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1))
402 != off + i * GET_MODE_SIZE (elt_mode))