Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / gcc / config / v850 / predicates.md
blob275eca7e23163f346da76747e2170cc47ec270a3
1 ;; Predicate definitions for NEC V850.
2 ;; Copyright (C) 2005 Free Software Foundation, Inc.
3 ;;
4 ;; This file is part of GCC.
5 ;;
6 ;; GCC is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 2, or (at your option)
9 ;; any later version.
11 ;; GCC is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ;; GNU General Public License for more details.
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GCC; see the file COPYING.  If not, write to
18 ;; the Free Software Foundation, 51 Franklin Street, Fifth Floor,
19 ;; Boston, MA 02110-1301, USA.
21 ;; Return true if OP is either a register or 0.
23 (define_predicate "reg_or_0_operand"
24   (match_code "reg,subreg,const_int,const_double")
26   if (GET_CODE (op) == CONST_INT)
27     return INTVAL (op) == 0;
29   else if (GET_CODE (op) == CONST_DOUBLE)
30     return CONST_DOUBLE_OK_FOR_G (op);
32   else
33     return register_operand (op, mode);
36 ;; Return true if OP is either a register or a signed five bit
37 ;; integer.
39 (define_predicate "reg_or_int5_operand"
40   (match_code "reg,subreg,const_int")
42   if (GET_CODE (op) == CONST_INT)
43     return CONST_OK_FOR_J (INTVAL (op));
45   else
46     return register_operand (op, mode);
49 ;; Return true if OP is either a register or a signed nine bit
50 ;; integer.
52 (define_predicate "reg_or_int9_operand"
53   (match_code "reg,subreg,const_int")
55   if (GET_CODE (op) == CONST_INT)
56     return CONST_OK_FOR_O (INTVAL (op));
58   return register_operand (op, mode);
61 ;; Return true if OP is either a register or a const integer.
63 (define_predicate "reg_or_const_operand"
64   (match_code "reg,const_int")
66   if (GET_CODE (op) == CONST_INT)
67     return TRUE;
69   return register_operand (op, mode);
72 ;; Return true if OP is a valid call operand.
74 (define_predicate "call_address_operand"
75   (match_code "reg,symbol_ref")
77   /* Only registers are valid call operands if TARGET_LONG_CALLS.  */
78   if (TARGET_LONG_CALLS)
79     return GET_CODE (op) == REG;
80   return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == REG);
83 ;; TODO: Add a comment here.
85 (define_predicate "movsi_source_operand"
86   (match_code "label_ref,symbol_ref,const_int,const_double,const,high,mem,reg,subreg")
88   /* Some constants, as well as symbolic operands
89      must be done with HIGH & LO_SUM patterns.  */
90   if (CONSTANT_P (op)
91       && GET_CODE (op) != HIGH
92       && !(GET_CODE (op) == CONST_INT
93            && (CONST_OK_FOR_J (INTVAL (op))
94                || CONST_OK_FOR_K (INTVAL (op))
95                || CONST_OK_FOR_L (INTVAL (op)))))
96     return special_symbolref_operand (op, mode);
97   else
98     return general_operand (op, mode);
101 ;; TODO: Add a comment here.
103 (define_predicate "special_symbolref_operand"
104   (match_code "symbol_ref")
106   if (GET_CODE (op) == CONST
107       && GET_CODE (XEXP (op, 0)) == PLUS
108       && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
109       && CONST_OK_FOR_K (INTVAL (XEXP (XEXP (op, 0), 1))))
110     op = XEXP (XEXP (op, 0), 0);
112   if (GET_CODE (op) == SYMBOL_REF)
113     return (SYMBOL_REF_FLAGS (op)
114             & (SYMBOL_FLAG_ZDA | SYMBOL_FLAG_TDA | SYMBOL_FLAG_SDA)) != 0;
116   return FALSE;
119 ;; TODO: Add a comment here.
121 (define_predicate "power_of_two_operand"
122   (match_code "const_int")
124   if (GET_CODE (op) != CONST_INT)
125     return 0;
127   if (exact_log2 (INTVAL (op)) == -1)
128     return 0;
129   return 1;
132 ;; Return nonzero if the given RTX is suitable for collapsing into a
133 ;; jump to a function prologue.
135 (define_predicate "pattern_is_ok_for_prologue"
136   (match_code "parallel")
138   int count = XVECLEN (op, 0);
139   int i;
140   rtx vector_element;
142   /* If there are no registers to save then the function prologue
143      is not suitable.  */
144   if (count <= 2)
145     return 0;
147   /* The pattern matching has already established that we are adjusting the
148      stack and pushing at least one register.  We must now check that the
149      remaining entries in the vector to make sure that they are also register
150      pushes, except for the last entry which should be a CLOBBER of r10.
152      The test below performs the C equivalent of this machine description
153      pattern match:
155      (set (mem:SI (plus:SI (reg:SI 3)
156       (match_operand:SI 2 "immediate_operand" "i")))
157       (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
159      */
161   for (i = 2; i < count - (TARGET_LONG_CALLS ? 2: 1); i++)
162     {
163       rtx dest;
164       rtx src;
165       rtx plus;
167       vector_element = XVECEXP (op, 0, i);
169       if (GET_CODE (vector_element) != SET)
170         return 0;
172       dest = SET_DEST (vector_element);
173       src = SET_SRC (vector_element);
175       if (GET_CODE (dest) != MEM
176           || GET_MODE (dest) != SImode
177           || GET_CODE (src) != REG
178           || GET_MODE (src) != SImode
179           || ! register_is_ok_for_epilogue (src, SImode))
180         return 0;
182       plus = XEXP (dest, 0);
184       if ( GET_CODE (plus) != PLUS
185           || GET_CODE (XEXP (plus, 0)) != REG
186           || GET_MODE (XEXP (plus, 0)) != SImode
187           || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
188           || GET_CODE (XEXP (plus, 1)) != CONST_INT)
189         return 0;
191       /* If the register is being pushed somewhere other than the stack
192          space just acquired by the first operand then abandon this quest.
193          Note: the test is <= because both values are negative.  */
194       if (INTVAL (XEXP (plus, 1))
195           <= INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)))
196         {
197           return 0;
198         }
199     }
201   /* Make sure that the last entries in the vector are clobbers.  */
202   for (; i < count; i++)
203     {
204       vector_element = XVECEXP (op, 0, i);
206       if (GET_CODE (vector_element) != CLOBBER
207           || GET_CODE (XEXP (vector_element, 0)) != REG
208           || !(REGNO (XEXP (vector_element, 0)) == 10
209                || (TARGET_LONG_CALLS ? (REGNO (XEXP (vector_element, 0)) == 11) : 0 )))
210         return 0;
211     }
213   return 1;
216 ;; Return nonzero if the given RTX is suitable for collapsing into
217 ;; jump to a function epilogue.
219 (define_predicate "pattern_is_ok_for_epilogue"
220   (match_code "parallel")
222   int count = XVECLEN (op, 0);
223   int i;
225   /* If there are no registers to restore then the function epilogue
226      is not suitable.  */
227   if (count <= 2)
228     return 0;
230   /* The pattern matching has already established that we are performing a
231      function epilogue and that we are popping at least one register.  We must
232      now check the remaining entries in the vector to make sure that they are
233      also register pops.  There is no good reason why there should ever be
234      anything else in this vector, but being paranoid always helps...
236      The test below performs the C equivalent of this machine description
237      pattern match:
239         (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
240           (mem:SI (plus:SI (reg:SI 3) (match_operand:SI n "immediate_operand" "i"))))
241      */
243   for (i = 3; i < count; i++)
244     {
245       rtx vector_element = XVECEXP (op, 0, i);
246       rtx dest;
247       rtx src;
248       rtx plus;
250       if (GET_CODE (vector_element) != SET)
251         return 0;
253       dest = SET_DEST (vector_element);
254       src = SET_SRC (vector_element);
256       if (GET_CODE (dest) != REG
257           || GET_MODE (dest) != SImode
258           || ! register_is_ok_for_epilogue (dest, SImode)
259           || GET_CODE (src) != MEM
260           || GET_MODE (src) != SImode)
261         return 0;
263       plus = XEXP (src, 0);
265       if (GET_CODE (plus) != PLUS
266           || GET_CODE (XEXP (plus, 0)) != REG
267           || GET_MODE (XEXP (plus, 0)) != SImode
268           || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
269           || GET_CODE (XEXP (plus, 1)) != CONST_INT)
270         return 0;
271     }
273   return 1;
276 ;; Return true if the given RTX is a register which can be restored by
277 ;; a function epilogue.
279 (define_predicate "register_is_ok_for_epilogue"
280   (match_code "reg")
282   /* The save/restore routines can only cope with registers 20 - 31.  */
283   return ((GET_CODE (op) == REG)
284           && (((REGNO (op) >= 20) && REGNO (op) <= 31)));
287 ;; Return nonzero if the given RTX is suitable for collapsing into a
288 ;; DISPOSE instruction.
290 (define_predicate "pattern_is_ok_for_dispose"
291   (match_code "parallel")
293   int count = XVECLEN (op, 0);
294   int i;
296   /* If there are no registers to restore then
297      the dispose instruction is not suitable.  */
298   if (count <= 2)
299     return 0;
301   /* The pattern matching has already established that we are performing a
302      function epilogue and that we are popping at least one register.  We must
303      now check the remaining entries in the vector to make sure that they are
304      also register pops.  There is no good reason why there should ever be
305      anything else in this vector, but being paranoid always helps...
307      The test below performs the C equivalent of this machine description
308      pattern match:
310         (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
311           (mem:SI (plus:SI (reg:SI 3)
312             (match_operand:SI n "immediate_operand" "i"))))
313      */
315   for (i = 3; i < count; i++)
316     {
317       rtx vector_element = XVECEXP (op, 0, i);
318       rtx dest;
319       rtx src;
320       rtx plus;
322       if (GET_CODE (vector_element) != SET)
323         return 0;
325       dest = SET_DEST (vector_element);
326       src  = SET_SRC (vector_element);
328       if (   GET_CODE (dest) != REG
329           || GET_MODE (dest) != SImode
330           || ! register_is_ok_for_epilogue (dest, SImode)
331           || GET_CODE (src) != MEM
332           || GET_MODE (src) != SImode)
333         return 0;
335       plus = XEXP (src, 0);
337       if (   GET_CODE (plus) != PLUS
338           || GET_CODE (XEXP (plus, 0)) != REG
339           || GET_MODE (XEXP (plus, 0)) != SImode
340           || REGNO    (XEXP (plus, 0)) != STACK_POINTER_REGNUM
341           || GET_CODE (XEXP (plus, 1)) != CONST_INT)
342         return 0;
343     }
345   return 1;
348 ;; Return nonzero if the given RTX is suitable for collapsing into a
349 ;; PREPARE instruction.
351 (define_predicate "pattern_is_ok_for_prepare"
352   (match_code "parallel")
354   int count = XVECLEN (op, 0);
355   int i;
357   /* If there are no registers to restore then the prepare instruction
358      is not suitable.  */
359   if (count <= 1)
360     return 0;
362   /* The pattern matching has already established that we are adjusting the
363      stack and pushing at least one register.  We must now check that the
364      remaining entries in the vector to make sure that they are also register
365      pushes.
367      The test below performs the C equivalent of this machine description
368      pattern match:
370      (set (mem:SI (plus:SI (reg:SI 3)
371        (match_operand:SI 2 "immediate_operand" "i")))
372          (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
374      */
376   for (i = 2; i < count; i++)
377     {
378       rtx vector_element = XVECEXP (op, 0, i);
379       rtx dest;
380       rtx src;
381       rtx plus;
383       if (GET_CODE (vector_element) != SET)
384         return 0;
386       dest = SET_DEST (vector_element);
387       src  = SET_SRC (vector_element);
389       if (   GET_CODE (dest) != MEM
390           || GET_MODE (dest) != SImode
391           || GET_CODE (src) != REG
392           || GET_MODE (src) != SImode
393           || ! register_is_ok_for_epilogue (src, SImode)
394              )
395         return 0;
397       plus = XEXP (dest, 0);
399       if (   GET_CODE (plus) != PLUS
400           || GET_CODE (XEXP (plus, 0)) != REG
401           || GET_MODE (XEXP (plus, 0)) != SImode
402           || REGNO    (XEXP (plus, 0)) != STACK_POINTER_REGNUM
403           || GET_CODE (XEXP (plus, 1)) != CONST_INT)
404         return 0;
406       /* If the register is being pushed somewhere other than the stack
407          space just acquired by the first operand then abandon this quest.
408          Note: the test is <= because both values are negative.  */
409       if (INTVAL (XEXP (plus, 1))
410           <= INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)))
411         return 0;
412     }
414   return 1;
417 ;; TODO: Add a comment here.
419 (define_predicate "not_power_of_two_operand"
420   (match_code "const_int")
422   unsigned int mask;
424   if (mode == QImode)
425     mask = 0xff;
426   else if (mode == HImode)
427     mask = 0xffff;
428   else if (mode == SImode)
429     mask = 0xffffffff;
430   else
431     return 0;
433   if (GET_CODE (op) != CONST_INT)
434     return 0;
436   if (exact_log2 (~INTVAL (op) & mask) == -1)
437     return 0;
438   return 1;