1 ;; Predicate definitions for S/390 and zSeries.
2 ;; Copyright (C) 2005 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 2, 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 COPYING. If not, write to
20 ;; the Free Software Foundation, 51 Franklin Street, Fifth Floor,
21 ;; Boston, MA 02110-1301, USA.
23 ;; OP is the current operation.
24 ;; MODE is the current operation mode.
26 ;; operands --------------------------------------------------------------
28 ;; Return true if OP a (const_int 0) operand.
30 (define_predicate "const0_operand"
31 (and (match_code "const_int, const_double")
32 (match_test "op == CONST0_RTX (mode)")))
34 ;; Return true if OP is constant.
36 (define_special_predicate "consttable_operand"
37 (and (match_code "symbol_ref, label_ref, const, const_int, const_double")
38 (match_test "CONSTANT_P (op)")))
40 ;; Return true if OP is a valid S-type operand.
42 (define_predicate "s_operand"
43 (and (match_code "subreg, mem")
44 (match_operand 0 "general_operand"))
46 /* Just like memory_operand, allow (subreg (mem ...))
49 && GET_CODE (op) == SUBREG
50 && GET_CODE (SUBREG_REG (op)) == MEM)
53 if (GET_CODE (op) != MEM)
55 if (!s390_legitimate_address_without_index_p (op))
61 ;; Return true if OP is a valid operand for the BRAS instruction.
62 ;; Allow SYMBOL_REFs and @PLT stubs.
64 (define_special_predicate "bras_sym_operand"
65 (ior (and (match_code "symbol_ref")
66 (match_test "!flag_pic || SYMBOL_REF_LOCAL_P (op)"))
67 (and (match_code "const")
68 (and (match_test "GET_CODE (XEXP (op, 0)) == UNSPEC")
69 (match_test "XINT (XEXP (op, 0), 1) == UNSPEC_PLT")))))
71 ;; Return true if OP is a PLUS that is not a legitimate
72 ;; operand for the LA instruction.
74 (define_predicate "s390_plus_operand"
75 (and (match_code "plus")
76 (and (match_test "mode == Pmode")
77 (match_test "!legitimate_la_operand_p (op)"))))
79 ;; Return true if OP is a valid operand as shift count or setmem.
81 (define_predicate "shift_count_or_setmem_operand"
82 (match_code "reg, subreg, plus, const_int")
87 /* Extract base register and offset. */
88 if (!s390_decompose_shift_count (op, &base, &offset))
91 /* Don't allow any non-base hard registers. Doing so without
92 confusing reload and/or regrename would be tricky, and doesn't
93 buy us much anyway. */
94 if (base && REGNO (base) < FIRST_PSEUDO_REGISTER && !ADDR_REG_P (base))
97 /* Unfortunately we have to reject constants that are invalid
98 for an address, or else reload will get confused. */
99 if (!DISP_IN_RANGE (offset))
105 ;; Return true if OP a valid operand for the LARL instruction.
107 (define_predicate "larl_operand"
108 (match_code "label_ref, symbol_ref, const, const_int, const_double")
110 /* Allow labels and local symbols. */
111 if (GET_CODE (op) == LABEL_REF)
113 if (GET_CODE (op) == SYMBOL_REF)
114 return ((SYMBOL_REF_FLAGS (op) & SYMBOL_FLAG_ALIGN1) == 0
115 && SYMBOL_REF_TLS_MODEL (op) == 0
116 && (!flag_pic || SYMBOL_REF_LOCAL_P (op)));
118 /* Everything else must have a CONST, so strip it. */
119 if (GET_CODE (op) != CONST)
123 /* Allow adding *even* in-range constants. */
124 if (GET_CODE (op) == PLUS)
126 if (GET_CODE (XEXP (op, 1)) != CONST_INT
127 || (INTVAL (XEXP (op, 1)) & 1) != 0)
129 if (INTVAL (XEXP (op, 1)) >= (HOST_WIDE_INT)1 << 31
130 || INTVAL (XEXP (op, 1)) < -((HOST_WIDE_INT)1 << 31))
135 /* Labels and local symbols allowed here as well. */
136 if (GET_CODE (op) == LABEL_REF)
138 if (GET_CODE (op) == SYMBOL_REF)
139 return ((SYMBOL_REF_FLAGS (op) & SYMBOL_FLAG_ALIGN1) == 0
140 && SYMBOL_REF_TLS_MODEL (op) == 0
141 && (!flag_pic || SYMBOL_REF_LOCAL_P (op)));
143 /* Now we must have a @GOTENT offset or @PLT stub
144 or an @INDNTPOFF TLS offset. */
145 if (GET_CODE (op) == UNSPEC
146 && XINT (op, 1) == UNSPEC_GOTENT)
148 if (GET_CODE (op) == UNSPEC
149 && XINT (op, 1) == UNSPEC_PLT)
151 if (GET_CODE (op) == UNSPEC
152 && XINT (op, 1) == UNSPEC_INDNTPOFF)
158 ;; operators --------------------------------------------------------------
160 ;; Return nonzero if OP is a valid comparison operator
161 ;; for a branch condition.
163 (define_predicate "s390_comparison"
164 (match_code "eq, ne, lt, gt, le, ge, ltu, gtu, leu, geu,
165 uneq, unlt, ungt, unle, unge, ltgt,
168 if (GET_CODE (XEXP (op, 0)) != REG
169 || REGNO (XEXP (op, 0)) != CC_REGNUM
170 || XEXP (op, 1) != const0_rtx)
173 return (s390_branch_condition_mask (op) >= 0);
176 ;; Return nonzero if OP is a valid comparison operator
177 ;; for an ALC condition.
179 (define_predicate "s390_alc_comparison"
180 (match_code "zero_extend, sign_extend, ltu, gtu, leu, geu")
182 while (GET_CODE (op) == ZERO_EXTEND || GET_CODE (op) == SIGN_EXTEND)
185 if (!COMPARISON_P (op))
188 if (GET_CODE (XEXP (op, 0)) != REG
189 || REGNO (XEXP (op, 0)) != CC_REGNUM
190 || XEXP (op, 1) != const0_rtx)
193 switch (GET_MODE (XEXP (op, 0)))
196 return GET_CODE (op) == LTU;
199 return GET_CODE (op) == LEU;
202 return GET_CODE (op) == GEU;
205 return GET_CODE (op) == GTU;
208 return GET_CODE (op) == LTU;
211 return GET_CODE (op) == UNGT;
214 return GET_CODE (op) == UNLT;
221 ;; Return nonzero if OP is a valid comparison operator
222 ;; for an SLB condition.
224 (define_predicate "s390_slb_comparison"
225 (match_code "zero_extend, sign_extend, ltu, gtu, leu, geu")
227 while (GET_CODE (op) == ZERO_EXTEND || GET_CODE (op) == SIGN_EXTEND)
230 if (!COMPARISON_P (op))
233 if (GET_CODE (XEXP (op, 0)) != REG
234 || REGNO (XEXP (op, 0)) != CC_REGNUM
235 || XEXP (op, 1) != const0_rtx)
238 switch (GET_MODE (XEXP (op, 0)))
241 return GET_CODE (op) == GEU;
244 return GET_CODE (op) == GTU;
247 return GET_CODE (op) == LTU;
250 return GET_CODE (op) == LEU;
253 return GET_CODE (op) == GEU;
256 return GET_CODE (op) == LE;
259 return GET_CODE (op) == GE;
266 ;; Return true if OP is a load multiple operation. It is known to be a
267 ;; PARALLEL and the first section will be tested.
269 (define_special_predicate "load_multiple_operation"
270 (match_code "parallel")
272 enum machine_mode elt_mode;
273 int count = XVECLEN (op, 0);
274 unsigned int dest_regno;
278 /* Perform a quick check so we don't blow up below. */
280 || GET_CODE (XVECEXP (op, 0, 0)) != SET
281 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
282 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
285 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
286 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
287 elt_mode = GET_MODE (SET_DEST (XVECEXP (op, 0, 0)));
289 /* Check, is base, or base + displacement. */
291 if (GET_CODE (src_addr) == REG)
293 else if (GET_CODE (src_addr) == PLUS
294 && GET_CODE (XEXP (src_addr, 0)) == REG
295 && GET_CODE (XEXP (src_addr, 1)) == CONST_INT)
297 off = INTVAL (XEXP (src_addr, 1));
298 src_addr = XEXP (src_addr, 0);
303 for (i = 1; i < count; i++)
305 rtx elt = XVECEXP (op, 0, i);
307 if (GET_CODE (elt) != SET
308 || GET_CODE (SET_DEST (elt)) != REG
309 || GET_MODE (SET_DEST (elt)) != elt_mode
310 || REGNO (SET_DEST (elt)) != dest_regno + i
311 || GET_CODE (SET_SRC (elt)) != MEM
312 || GET_MODE (SET_SRC (elt)) != elt_mode
313 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
314 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
315 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
316 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1))
317 != off + i * GET_MODE_SIZE (elt_mode))
324 ;; Return true if OP is a store multiple operation. It is known to be a
325 ;; PARALLEL and the first section will be tested.
327 (define_special_predicate "store_multiple_operation"
328 (match_code "parallel")
330 enum machine_mode elt_mode;
331 int count = XVECLEN (op, 0);
332 unsigned int src_regno;
336 /* Perform a quick check so we don't blow up below. */
338 || GET_CODE (XVECEXP (op, 0, 0)) != SET
339 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
340 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
343 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
344 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
345 elt_mode = GET_MODE (SET_SRC (XVECEXP (op, 0, 0)));
347 /* Check, is base, or base + displacement. */
349 if (GET_CODE (dest_addr) == REG)
351 else if (GET_CODE (dest_addr) == PLUS
352 && GET_CODE (XEXP (dest_addr, 0)) == REG
353 && GET_CODE (XEXP (dest_addr, 1)) == CONST_INT)
355 off = INTVAL (XEXP (dest_addr, 1));
356 dest_addr = XEXP (dest_addr, 0);
361 for (i = 1; i < count; i++)
363 rtx elt = XVECEXP (op, 0, i);
365 if (GET_CODE (elt) != SET
366 || GET_CODE (SET_SRC (elt)) != REG
367 || GET_MODE (SET_SRC (elt)) != elt_mode
368 || REGNO (SET_SRC (elt)) != src_regno + i
369 || GET_CODE (SET_DEST (elt)) != MEM
370 || GET_MODE (SET_DEST (elt)) != elt_mode
371 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
372 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
373 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
374 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1))
375 != off + i * GET_MODE_SIZE (elt_mode))