OSDN Git Service

* config/freebsd-spec.h, config/arc/arc-protos.h,
[pf3gnuchains/gcc-fork.git] / gcc / config / cris / cris.md
1 ;; GCC machine description for CRIS cpu cores.
2 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 ;; Free Software Foundation, Inc.
4 ;; Contributed by Axis Communications.
5
6 ;; This file is part of GCC.
7 ;;
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)
11 ;; any later version.
12 ;;
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.
17 ;;
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, 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
22
23 ;; The original PO technology requires these to be ordered by speed,
24 ;; so that assigner will pick the fastest.
25
26 ;; See files "md.texi" and "rtl.def" for documentation on define_insn,
27 ;; match_*, et. al.
28 ;;
29 ;; The function cris_notice_update_cc in cris.c handles condition code
30 ;; updates for most instructions, helped by the "cc" attribute.
31
32 ;; There are several instructions that are orthogonal in size, and seems
33 ;; they could be matched by a single pattern without a specified size
34 ;; for the operand that is orthogonal.  However, this did not work on
35 ;; gcc-2.7.2 (and probably not on gcc-2.8.1), relating to that when a
36 ;; constant is substituted into an operand, the actual mode must be
37 ;; deduced from the pattern.  There is reasonable hope that that has been
38 ;; fixed, so FIXME: try again.
39
40 ;; You will notice that three-operand alternatives ("=r", "r", "!To")
41 ;; are marked with a "!" constraint modifier to avoid being reloaded
42 ;; into.  This is because gcc would otherwise prefer to use the constant
43 ;; pool and its offsettable address instead of reloading to an
44 ;; ("=r", "0", "i") alternative.  Also, the constant-pool support was not
45 ;; only suboptimal but also buggy in 2.7.2, ??? maybe only in 2.6.3.
46
47 ;; All insns that look like (set (...) (plus (...) (reg:SI 8)))
48 ;; get problems when reloading r8 (frame pointer) to r14 + offs (stack
49 ;; pointer).  Thus the instructions that get into trouble have specific
50 ;; checks against matching frame_pointer_rtx.
51 ;; ??? But it should be re-checked for gcc > 2.7.2
52 ;; FIXME: This changed some time ago (from 2000-03-16) for gcc-2.9x.
53
54 ;; FIXME: When PIC, all [rX=rY+S] could be enabled to match
55 ;; [rX=gotless_symbol].
56 ;; The movsi for a gotless symbol could be split (post reload).
57 \f
58 ;; UNSPEC Usage:
59 ;; 0 PLT reference from call expansion: operand 0 is the address,
60 ;;   the mode is VOIDmode.  Always wrapped in CONST.
61
62 ;; We need an attribute to define whether an instruction can be put in
63 ;; a branch-delay slot or not, and whether it has a delay slot.
64 ;;
65 ;; Branches and return instructions have a delay slot, and cannot
66 ;; themselves be put in a delay slot.  This has changed *for short
67 ;; branches only* between architecture variants, but the possible win
68 ;; is presumed negligible compared to the added complexity of the machine
69 ;; description: one would have to add always-correct infrastructure to
70 ;; distinguish short branches.
71 ;;
72 ;; Whether an instruction can be put in a delay slot depends on the
73 ;; instruction (all short instructions except jumps and branches)
74 ;; and the addressing mode (must not be prefixed or referring to pc).
75 ;; In short, any "slottable" instruction must be 16 bit and not refer
76 ;; to pc, or alter it.
77 ;;
78 ;; The possible values are "yes", "no" and "has_slot".  Yes/no means if
79 ;; the insn is slottable or not.  Has_slot means that the insn is a
80 ;; return insn or branch insn (which are not considered slottable since
81 ;; that is generally true).  Having the seemingly illogical value
82 ;; "has_slot" means we do not have to add another attribute just to say
83 ;; that an insn has a delay-slot, since it also infers that it is not
84 ;; slottable.  Better names for the attribute were found to be longer and
85 ;; not add readability to the machine description.
86 ;;
87 ;; The default that is defined here for this attribute is "no", not
88 ;; slottable, not having a delay-slot, so there's no need to worry about
89 ;; it being wrong for non-branch and return instructions.
90 ;;  The default could depend on the kind of insn and the addressing
91 ;; mode, but that would need more attributes and hairier, more error
92 ;; prone code.
93 ;;
94 ;;  There is an extra constraint, 'Q', which recognizes indirect reg,
95 ;; except when the reg is pc.  The constraints 'Q' and '>' together match
96 ;; all possible memory operands that are slottable.
97 ;;  For other operands, you need to check if it has a valid "slottable"
98 ;; quick-immediate operand, where the particular signedness-variation
99 ;; may match the constraints 'I' or 'J'.), and include it in the
100 ;; constraint pattern for the slottable pattern.  An alternative using
101 ;; only "r" constraints is most often slottable.
102
103 (define_attr "slottable" "no,yes,has_slot" (const_string "no"))
104
105 ;; We also need attributes to sanely determine the condition code
106 ;; state.  See cris_notice_update_cc for how this is used.
107
108 (define_attr "cc" "none,clobber,normal" (const_string "normal"))
109
110 ;; A branch or return has one delay-slot.  The instruction in the
111 ;; delay-slot is always executed, independent of whether the branch is
112 ;; taken or not.  Note that besides setting "slottable" to "has_slot",
113 ;; there also has to be a "%#" at the end of a "delayed" instruction
114 ;; output pattern (for "jump" this means "ba %l0%#"), so print_operand can
115 ;; catch it and print a "nop" if necessary.  This method was stolen from
116 ;; sparc.md.
117
118 (define_delay (eq_attr "slottable" "has_slot")
119   [(eq_attr "slottable" "yes") (nil) (nil)])
120 \f
121 ;; Test insns.
122
123 ;; DImode
124 ;;
125 ;; Allow register and offsettable mem operands only; post-increment is
126 ;; not worth the trouble.
127
128 (define_insn "tstdi"
129   [(set (cc0)
130         (match_operand:DI 0 "nonimmediate_operand" "r,o"))]
131   ""
132   "test.d %M0\;ax\;test.d %H0")
133
134 ;; No test insns with side-effect on the mem addressing.
135 ;;
136 ;; See note on cmp-insns with side-effects (or lack of them)
137
138 ;; Normal named test patterns from SI on.
139 ;; FIXME: Seems they should change to be in order smallest..largest.
140
141 (define_insn "tstsi"
142   [(set (cc0)
143         (match_operand:SI 0 "nonimmediate_operand" "r,Q>,m"))]
144   ""
145   "test.d %0"
146   [(set_attr "slottable" "yes,yes,no")])
147
148 (define_insn "tsthi"
149   [(set (cc0)
150         (match_operand:HI 0 "nonimmediate_operand" "r,Q>,m"))]
151   ""
152   "test.w %0"
153   [(set_attr "slottable" "yes,yes,no")])
154
155 (define_insn "tstqi"
156   [(set (cc0)
157         (match_operand:QI 0 "nonimmediate_operand" "r,Q>,m"))]
158   ""
159   "test.b %0"
160   [(set_attr "slottable" "yes,yes,no")])
161
162 ;; It seems that the position of the sign-bit and the fact that 0.0 is
163 ;; all 0-bits would make "tstsf" a straight-forward implementation;
164 ;; either "test.d" it for positive/negative or "btstq 30,r" it for
165 ;; zeroness.
166 ;;
167 ;; FIXME: Do that some time; check next_cc0_user to determine if
168 ;; zero or negative is tested for.
169 \f
170 ;; Compare insns.
171
172 ;; We could optimize the sizes of the immediate operands for various
173 ;; cases, but that is not worth it because of the very little usage of
174 ;; DImode for anything else but a structure/block-mode.  Just do the
175 ;; obvious stuff for the straight-forward constraint letters.
176
177 (define_insn "cmpdi"
178   [(set (cc0)
179         (compare (match_operand:DI 0 "nonimmediate_operand" "r,r,r,r,r,r,o")
180                  (match_operand:DI 1 "general_operand" "K,I,P,n,r,o,r")))]
181   ""
182   "@
183    cmpq %1,%M0\;ax\;cmpq 0,%H0
184    cmpq %1,%M0\;ax\;cmpq -1,%H0
185    cmp%e1.%z1 %1,%M0\;ax\;cmpq %H1,%H0
186    cmp.d %M1,%M0\;ax\;cmp.d %H1,%H0
187    cmp.d %M1,%M0\;ax\;cmp.d %H1,%H0
188    cmp.d %M1,%M0\;ax\;cmp.d %H1,%H0
189    cmp.d %M0,%M1\;ax\;cmp.d %H0,%H1")
190
191 ;; Note that compare insns with side effect addressing mode (e.g.):
192 ;;
193 ;; cmp.S [rx=ry+i],rz;
194 ;; cmp.S [%3=%1+%2],%0
195 ;;
196 ;; are *not* usable for gcc since the reloader *does not accept*
197 ;; cc0-changing insns with side-effects other than setting the condition
198 ;; codes.  The reason is that the reload stage *may* cause another insn to
199 ;; be output after the main instruction, in turn invalidating cc0 for the
200 ;; insn using the test.  (This does not apply to the CRIS case, since a
201 ;; reload for output -- move to memory -- does not change the condition
202 ;; code.  Unfortunately we have no way to describe that at the moment.  I
203 ;; think code would improve being in the order of one percent faster.
204 \f
205 ;; We have cmps and cmpu (compare reg w. sign/zero extended mem).
206 ;; These are mostly useful for compares in SImode, using 8 or 16-bit
207 ;; constants, but sometimes gcc will find its way to use it for other
208 ;; (memory) operands.  Avoid side-effect patterns, though (see above).
209 ;;
210 ;; FIXME: These could have an anonymous mode for operand 1.
211
212 ;; QImode
213
214 (define_insn "*cmp_extsi"
215   [(set (cc0)
216         (compare
217          (match_operand:SI 0 "register_operand" "r,r")
218          (match_operator:SI 2 "cris_extend_operator"
219                          [(match_operand:QI 1 "memory_operand" "Q>,m")])))]
220   ""
221   "cmp%e2.%s1 %1,%0"
222   [(set_attr "slottable" "yes,no")])
223
224 ;; HImode
225 (define_insn "*cmp_exthi"
226   [(set (cc0)
227         (compare
228          (match_operand:SI 0 "register_operand" "r,r")
229          (match_operator:SI 2 "cris_extend_operator"
230                          [(match_operand:HI 1 "memory_operand" "Q>,m")])))]
231   ""
232   "cmp%e2.%s1 %1,%0"
233   [(set_attr "slottable" "yes,no")])
234
235 ;; Swap operands; it seems the canonical look (if any) is not enforced.
236 ;;
237 ;; FIXME: Investigate that.
238 ;; FIXME: These could have an anonymous mode for operand 1.
239
240 ;; QImode
241
242 (define_insn "*cmp_swapextqi"
243   [(set (cc0)
244         (compare
245          (match_operator:SI 2 "cris_extend_operator"
246                             [(match_operand:QI 0 "memory_operand" "Q>,m")])
247          (match_operand:SI 1 "register_operand" "r,r")))]
248   ""
249   "cmp%e2.%s0 %0,%1" ; The function cris_notice_update_cc knows about
250                      ; swapped operands to compares.
251   [(set_attr "slottable" "yes,no")])
252
253 ;; HImode
254
255 (define_insn "*cmp_swapexthi"
256   [(set (cc0)
257         (compare
258          (match_operator:SI 2 "cris_extend_operator"
259                             [(match_operand:HI 0 "memory_operand" "Q>,m")])
260          (match_operand:SI 1 "register_operand" "r,r")))]
261   ""
262   "cmp%e2.%s0 %0,%1" ; The function cris_notice_update_cc knows about
263                      ; swapped operands to compares.
264   [(set_attr "slottable" "yes,no")])
265 \f
266 ;; The "normal" compare patterns, from SI on.
267
268 (define_insn "cmpsi"
269   [(set (cc0)
270         (compare
271          (match_operand:SI 0 "nonimmediate_operand" "r,r,r,r,Q>,Q>,r,r,m,m")
272          (match_operand:SI 1 "general_operand" "I,r,Q>,M,M,r,P,g,M,r")))]
273   ""
274   "@
275    cmpq %1,%0
276    cmp.d %1,%0
277    cmp.d %1,%0
278    test.d %0
279    test.d %0
280    cmp.d %0,%1
281    cmp%e1.%z1 %1,%0
282    cmp.d %1,%0
283    test.d %0
284    cmp.d %0,%1"
285   [(set_attr "slottable" "yes,yes,yes,yes,yes,yes,no,no,no,no")])
286
287 (define_insn "cmphi"
288   [(set (cc0)
289         (compare (match_operand:HI 0 "nonimmediate_operand" "r,r,Q>,Q>,r,m,m")
290                  (match_operand:HI 1 "general_operand" "r,Q>,M,r,g,M,r")))]
291   ""
292   "@
293    cmp.w %1,%0
294    cmp.w %1,%0
295    test.w %0
296    cmp.w %0,%1
297    cmp.w %1,%0
298    test.w %0
299    cmp.w %0,%1"
300   [(set_attr "slottable" "yes,yes,yes,yes,no,no,no")])
301
302 (define_insn "cmpqi"
303   [(set (cc0)
304         (compare
305          (match_operand:QI 0 "nonimmediate_operand" "r,r,r,Q>,Q>,r,m,m")
306          (match_operand:QI 1 "general_operand" "r,Q>,M,M,r,g,M,r")))]
307   ""
308   "@
309    cmp.b %1,%0
310    cmp.b %1,%0
311    test.b %0
312    test.b %0
313    cmp.b %0,%1
314    cmp.b %1,%0
315    test.b %0
316    cmp.b %0,%1"
317   [(set_attr "slottable" "yes,yes,yes,yes,yes,no,no,no")])
318 \f
319 ;; Pattern matching the BTST insn.
320 ;; It is useful for "if (i & val)" constructs, where val is an exact
321 ;; power of 2, or if val + 1 is a power of two, where we check for a bunch
322 ;; of zeros starting at bit 0).
323
324 ;; SImode.  This mode is the only one needed, since gcc automatically
325 ;; extends subregs for lower-size modes.  FIXME: Add testcase.
326 (define_insn "*btst"
327   [(set (cc0)
328         (zero_extract
329          (match_operand:SI 0 "nonmemory_operand" "r,r,r,r,r,r,n")
330          (match_operand:SI 1 "const_int_operand" "K,n,K,n,K,n,n")
331          (match_operand:SI 2 "nonmemory_operand" "M,M,K,n,r,r,r")))]
332   ;; Either it is a single bit, or consecutive ones starting at 0.
333   "GET_CODE (operands[1]) == CONST_INT
334    && (operands[1] == const1_rtx || operands[2] == const0_rtx)
335    && (REG_S_P (operands[0])
336        || (operands[1] == const1_rtx
337            && REG_S_P (operands[2])
338            && GET_CODE (operands[0]) == CONST_INT
339            && exact_log2 (INTVAL (operands[0])) >= 0))"
340
341 ;; The last "&&" condition above should be caught by some kind of
342 ;; canonicalization in gcc, but we can easily help with it here.
343 ;;  It results from expressions of the type
344 ;; "power_of_2_value & (1 << y)".
345 ;;
346 ;; Since there may be codes with tests in on bits (in constant position)
347 ;; beyond the size of a word, handle that by assuming those bits are 0.
348 ;; GCC should handle that, but it's a matter of easily-added belts while
349 ;; having suspenders.
350
351   "@
352    btstq (%1-1),%0
353    test.d %0
354    btstq %2,%0
355    clearf nz
356    btst %2,%0
357    clearf nz
358    cmpq %p0,%2"
359  [(set_attr "slottable" "yes")])
360 \f
361 ;; Move insns.
362
363 ;; The whole mandatory movdi family is here; expander, "anonymous"
364 ;; recognizer and splitter.  We're forced to have a movdi pattern,
365 ;; although GCC should be able to split it up itself.  Normally it can,
366 ;; but if other insns have DI operands (as is the case here), reload
367 ;; must be able to generate or match a movdi.  many testcases fail at
368 ;; -O3 or -fssa if we don't have this.  FIXME: Fix GCC...  See
369 ;; <URL:http://gcc.gnu.org/ml/gcc-patches/2000-04/msg00104.html>.
370 ;; However, a patch from Richard Kenner (similar to the cause of
371 ;; discussion at the URL above), indicates otherwise.  See
372 ;; <URL:http://gcc.gnu.org/ml/gcc-patches/2000-04/msg00554.html>.
373 ;; The truth has IMO is not been decided yet, so check from time to
374 ;; time by disabling the movdi patterns.
375
376 (define_expand "movdi"
377   [(set (match_operand:DI 0 "nonimmediate_operand" "")
378         (match_operand:DI 1 "general_operand" ""))]
379   ""
380   "
381 {
382   if (GET_CODE (operands[0]) == MEM && operands[1] != const0_rtx)
383     operands[1] = copy_to_mode_reg (DImode, operands[1]);
384
385   /* Some other ports (as of 2001-09-10 for example mcore and romp) also
386      prefer to split up constants early, like this.  The testcase in
387      gcc.c-torture/execute/961213-1.c shows that CSE2 gets confused by the
388      resulting subreg sets when using the construct from mcore (as of FSF
389      CVS, version -r 1.5), and it believes that the high part (the last one
390      emitted) is the final value.  This construct from romp seems more
391      robust, especially considering the head comments from
392      emit_no_conflict_block.  */
393   if ((GET_CODE (operands[1]) == CONST_INT
394        || GET_CODE (operands[1]) == CONST_DOUBLE)
395       && ! reload_completed
396       && ! reload_in_progress)
397     {
398       rtx insns;
399       rtx op0 = operands[0];
400       rtx op1 = operands[1];
401
402       start_sequence ();
403       emit_move_insn (operand_subword (op0, 0, 1, DImode),
404                       operand_subword (op1, 0, 1, DImode));
405       emit_move_insn (operand_subword (op0, 1, 1, DImode),
406                       operand_subword (op1, 1, 1, DImode));
407       insns = get_insns ();
408       end_sequence ();
409
410       emit_no_conflict_block (insns, op0, op1, 0, op1);
411       DONE;
412     }
413 }")
414
415 (define_insn "*movdi_insn"
416   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m")
417         (match_operand:DI 1 "general_operand" "r,g,rM"))]
418   "register_operand (operands[0], DImode)
419    || register_operand (operands[1], DImode)
420    || operands[1] == const0_rtx"
421   "#")
422
423 (define_split
424   [(set (match_operand:DI 0 "nonimmediate_operand" "")
425         (match_operand:DI 1 "general_operand" ""))]
426   "reload_completed"
427   [(match_dup 2)]
428   "operands[2] = cris_split_movdx (operands);")
429 \f
430 ;; Side-effect patterns for move.S1 [rx=ry+rx.S2],rw
431 ;; and move.S1 [rx=ry+i],rz
432 ;;  Then movs.S1 and movu.S1 for both modes.
433 ;;
434 ;; move.S1 [rx=ry+rz.S],rw avoiding when rx is ry, or rw is rx
435 ;; FIXME: These could have anonymous mode for operand 0.
436
437 ;; QImode
438
439 (define_insn "*mov_sideqi_biap"
440   [(set (match_operand:QI 0 "register_operand" "=r,r")
441         (mem:QI (plus:SI
442                  (mult:SI (match_operand:SI 1 "register_operand" "r,r")
443                           (match_operand:SI 2 "const_int_operand" "n,n"))
444                  (match_operand:SI 3 "register_operand" "r,r"))))
445    (set (match_operand:SI 4 "register_operand" "=*3,r")
446         (plus:SI (mult:SI (match_dup 1)
447                           (match_dup 2))
448                  (match_dup 3)))]
449   "cris_side_effect_mode_ok (MULT, operands, 4, 3, 1, 2, 0)"
450   "@
451    #
452    move.%s0 [%4=%3+%1%T2],%0")
453
454 ;; HImode
455
456 (define_insn "*mov_sidehi_biap"
457   [(set (match_operand:HI 0 "register_operand" "=r,r")
458         (mem:HI (plus:SI
459                  (mult:SI (match_operand:SI 1 "register_operand" "r,r")
460                           (match_operand:SI 2 "const_int_operand" "n,n"))
461                  (match_operand:SI 3 "register_operand" "r,r"))))
462    (set (match_operand:SI 4 "register_operand" "=*3,r")
463         (plus:SI (mult:SI (match_dup 1)
464                           (match_dup 2))
465                  (match_dup 3)))]
466   "cris_side_effect_mode_ok (MULT, operands, 4, 3, 1, 2, 0)"
467   "@
468    #
469    move.%s0 [%4=%3+%1%T2],%0")
470
471 ;; SImode
472
473 (define_insn "*mov_sidesi_biap"
474   [(set (match_operand:SI 0 "register_operand" "=r,r")
475         (mem:SI (plus:SI
476                  (mult:SI (match_operand:SI 1 "register_operand" "r,r")
477                           (match_operand:SI 2 "const_int_operand" "n,n"))
478                  (match_operand:SI 3 "register_operand" "r,r"))))
479    (set (match_operand:SI 4 "register_operand" "=*3,r")
480         (plus:SI (mult:SI (match_dup 1)
481                           (match_dup 2))
482                  (match_dup 3)))]
483   "cris_side_effect_mode_ok (MULT, operands, 4, 3, 1, 2, 0)"
484   "@
485    #
486    move.%s0 [%4=%3+%1%T2],%0")
487 \f
488 ;; move.S1 [rx=ry+i],rz
489 ;; avoiding move.S1 [ry=ry+i],rz
490 ;; and      move.S1 [rz=ry+i],rz
491 ;; Note that "i" is allowed to be a register.
492 ;; FIXME: These could have anonymous mode for operand 0.
493
494 ;; QImode
495
496 (define_insn "*mov_sideqi"
497   [(set (match_operand:QI 0 "register_operand" "=r,r,r")
498         (mem:QI
499          (plus:SI (match_operand:SI 1 "cris_bdap_operand" "%r,r,r")
500                   (match_operand:SI 2 "cris_bdap_operand" "r>Rn,r,>Rn"))))
501    (set (match_operand:SI 3 "register_operand" "=*1,r,r")
502         (plus:SI (match_dup 1)
503                  (match_dup 2)))]
504   "cris_side_effect_mode_ok (PLUS, operands, 3, 1, 2, -1, 0)"
505   "*
506 {
507   if (which_alternative == 0
508       && (GET_CODE (operands[2]) != CONST_INT
509           || INTVAL (operands[2]) > 127
510           || INTVAL (operands[2]) < -128
511           || CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'N')
512           || CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'J')))
513     return \"#\";
514   return \"move.%s0 [%3=%1%S2],%0\";
515 }")
516
517 ;; HImode
518
519 (define_insn "*mov_sidehi"
520   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
521         (mem:HI
522          (plus:SI (match_operand:SI 1 "cris_bdap_operand" "%r,r,r")
523                   (match_operand:SI 2 "cris_bdap_operand" "r>Rn,r,>Rn"))))
524    (set (match_operand:SI 3 "register_operand" "=*1,r,r")
525         (plus:SI (match_dup 1)
526                  (match_dup 2)))]
527   "cris_side_effect_mode_ok (PLUS, operands, 3, 1, 2, -1, 0)"
528   "*
529 {
530   if (which_alternative == 0
531       && (GET_CODE (operands[2]) != CONST_INT
532           || INTVAL (operands[2]) > 127
533           || INTVAL (operands[2]) < -128
534           || CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'N')
535           || CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'J')))
536     return \"#\";
537   return \"move.%s0 [%3=%1%S2],%0\";
538 }")
539
540 ;; SImode
541
542 (define_insn "*mov_sidesi"
543   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
544         (mem:SI
545          (plus:SI (match_operand:SI 1 "cris_bdap_operand" "%r,r,r")
546                   (match_operand:SI 2 "cris_bdap_operand" "r>Rn,r,>Rn"))))
547    (set (match_operand:SI 3 "register_operand" "=*1,r,r")
548         (plus:SI (match_dup 1)
549                  (match_dup 2)))]
550   "cris_side_effect_mode_ok (PLUS, operands, 3, 1, 2, -1, 0)"
551   "*
552 {
553   if (which_alternative == 0
554       && (GET_CODE (operands[2]) != CONST_INT
555           || INTVAL (operands[2]) > 127
556           || INTVAL (operands[2]) < -128
557           || CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'N')
558           || CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'J')))
559     return \"#\";
560   return \"move.%s0 [%3=%1%S2],%0\";
561 }")
562 \f
563 ;; Other way around; move to memory.
564
565 ;; Note that the condition (which for side-effect patterns is usually a
566 ;; call to cris_side_effect_mode_ok), isn't consulted for register
567 ;; allocation preferences -- constraints is the method for that.  The
568 ;; drawback is that we can't exclude register allocation to cause
569 ;; "move.s rw,[rx=ry+rz.S]" when rw==rx without also excluding rx==ry or
570 ;; rx==rz if we use an earlyclobber modifier for the constraint for rx.
571 ;; Instead of that, we recognize and split the cases where dangerous
572 ;; register combinations are spotted: where a register is set in the
573 ;; side-effect, and used in the main insn.  We don't handle the case where
574 ;; the set in the main insn overlaps the set in the side-effect; that case
575 ;; must be handled in gcc.  We handle just the case where the set in the
576 ;; side-effect overlaps the input operand of the main insn (i.e. just
577 ;; moves to memory).
578
579 ;;
580 ;; move.s rz,[ry=rx+rw.S]
581 ;; FIXME: These could have anonymous mode for operand 3.
582
583 ;; QImode
584
585 (define_insn "*mov_sideqi_biap_mem"
586   [(set (mem:QI (plus:SI
587                  (mult:SI (match_operand:SI 0 "register_operand" "r,r,r")
588                           (match_operand:SI 1 "const_int_operand" "n,n,n"))
589                  (match_operand:SI 2 "register_operand" "r,r,r")))
590         (match_operand:QI 3 "register_operand" "r,r,r"))
591    (set (match_operand:SI 4 "register_operand" "=*2,!3,r")
592         (plus:SI (mult:SI (match_dup 0)
593                           (match_dup 1))
594                  (match_dup 2)))]
595   "cris_side_effect_mode_ok (MULT, operands, 4, 2, 0, 1, 3)"
596   "@
597    #
598    #
599    move.%s3 %3,[%4=%2+%0%T1]")
600
601 ;; HImode
602
603 (define_insn "*mov_sidehi_biap_mem"
604   [(set (mem:HI (plus:SI
605                  (mult:SI (match_operand:SI 0 "register_operand" "r,r,r")
606                           (match_operand:SI 1 "const_int_operand" "n,n,n"))
607                  (match_operand:SI 2 "register_operand" "r,r,r")))
608         (match_operand:HI 3 "register_operand" "r,r,r"))
609    (set (match_operand:SI 4 "register_operand" "=*2,!3,r")
610         (plus:SI (mult:SI (match_dup 0)
611                           (match_dup 1))
612                  (match_dup 2)))]
613   "cris_side_effect_mode_ok (MULT, operands, 4, 2, 0, 1, 3)"
614   "@
615    #
616    #
617    move.%s3 %3,[%4=%2+%0%T1]")
618
619 ;; SImode
620
621 (define_insn "*mov_sidesi_biap_mem"
622   [(set (mem:SI (plus:SI
623                  (mult:SI (match_operand:SI 0 "register_operand" "r,r,r")
624                           (match_operand:SI 1 "const_int_operand" "n,n,n"))
625                  (match_operand:SI 2 "register_operand" "r,r,r")))
626         (match_operand:SI 3 "register_operand" "r,r,r"))
627    (set (match_operand:SI 4 "register_operand" "=*2,!3,r")
628         (plus:SI (mult:SI (match_dup 0)
629                           (match_dup 1))
630                  (match_dup 2)))]
631   "cris_side_effect_mode_ok (MULT, operands, 4, 2, 0, 1, 3)"
632   "@
633    #
634    #
635    move.%s3 %3,[%4=%2+%0%T1]")
636
637 ;; Split for the case above where we're out of luck with register
638 ;; allocation (again, the condition isn't checked for that), and we end up
639 ;; with the set in the side-effect getting the same register as the input
640 ;; register.
641
642 (define_split
643   [(parallel
644     [(set (match_operator
645            6 "cris_mem_op"
646            [(plus:SI
647              (mult:SI (match_operand:SI 0 "register_operand" "")
648                       (match_operand:SI 1 "const_int_operand" ""))
649              (match_operand:SI 2 "register_operand" ""))])
650           (match_operand 3 "register_operand" ""))
651      (set (match_operand:SI 4 "register_operand" "")
652           (plus:SI (mult:SI (match_dup 0)
653                             (match_dup 1))
654                    (match_dup 2)))])]
655   "reload_completed && reg_overlap_mentioned_p (operands[4], operands[3])"
656   [(set (match_dup 5) (match_dup 3))
657    (set (match_dup 4) (match_dup 2))
658    (set (match_dup 4)
659         (plus:SI (mult:SI (match_dup 0)
660                           (match_dup 1))
661                  (match_dup 4)))]
662   "operands[5]
663      = replace_equiv_address (operands[6],
664                               gen_rtx_PLUS (SImode,
665                                             gen_rtx_MULT (SImode,
666                                                           operands[0],
667                                                           operands[1]),
668                                             operands[2]));")
669 \f
670 ;; move.s rx,[ry=rz+i]
671 ;; FIXME: These could have anonymous mode for operand 2.
672
673 ;; QImode
674
675 (define_insn "*mov_sideqi_mem"
676   [(set (mem:QI
677          (plus:SI (match_operand:SI 0 "cris_bdap_operand" "%r,r,r,r")
678                   (match_operand:SI 1 "cris_bdap_operand" "r>Rn,r>Rn,r,>Rn")))
679         (match_operand:QI 2 "register_operand" "r,r,r,r"))
680    (set (match_operand:SI 3 "register_operand" "=*0,!2,r,r")
681         (plus:SI (match_dup 0)
682                  (match_dup 1)))]
683   "cris_side_effect_mode_ok (PLUS, operands, 3, 0, 1, -1, 2)"
684   "*
685 {
686   if (which_alternative == 0
687       && (GET_CODE (operands[1]) != CONST_INT
688           || INTVAL (operands[1]) > 127
689           || INTVAL (operands[1]) < -128
690           || CONST_OK_FOR_LETTER_P (INTVAL (operands[1]), 'N')
691           || CONST_OK_FOR_LETTER_P (INTVAL (operands[1]), 'J')))
692     return \"#\";
693   if (which_alternative == 1)
694     return \"#\";
695   return \"move.%s2 %2,[%3=%0%S1]\";
696 }")
697
698 ;; HImode
699
700 (define_insn "*mov_sidehi_mem"
701   [(set (mem:HI
702          (plus:SI (match_operand:SI 0 "cris_bdap_operand" "%r,r,r,r")
703                   (match_operand:SI 1 "cris_bdap_operand" "r>Rn,r>Rn,r,>Rn")))
704         (match_operand:HI 2 "register_operand" "r,r,r,r"))
705    (set (match_operand:SI 3 "register_operand" "=*0,!2,r,r")
706         (plus:SI (match_dup 0)
707                  (match_dup 1)))]
708   "cris_side_effect_mode_ok (PLUS, operands, 3, 0, 1, -1, 2)"
709   "*
710 {
711   if (which_alternative == 0
712       && (GET_CODE (operands[1]) != CONST_INT
713           || INTVAL (operands[1]) > 127
714           || INTVAL (operands[1]) < -128
715           || CONST_OK_FOR_LETTER_P (INTVAL (operands[1]), 'N')
716           || CONST_OK_FOR_LETTER_P (INTVAL (operands[1]), 'J')))
717     return \"#\";
718   if (which_alternative == 1)
719     return \"#\";
720   return \"move.%s2 %2,[%3=%0%S1]\";
721 }")
722
723 ;; SImode
724
725 (define_insn "*mov_sidesi_mem"
726   [(set (mem:SI
727          (plus:SI (match_operand:SI 0 "cris_bdap_operand" "%r,r,r,r")
728                   (match_operand:SI 1 "cris_bdap_operand" "r>Rn,r>Rn,r,>Rn")))
729         (match_operand:SI 2 "register_operand" "r,r,r,r"))
730    (set (match_operand:SI 3 "register_operand" "=*0,!2,r,r")
731         (plus:SI (match_dup 0)
732                  (match_dup 1)))]
733   "cris_side_effect_mode_ok (PLUS, operands, 3, 0, 1, -1, 2)"
734   "*
735 {
736   if (which_alternative == 0
737       && (GET_CODE (operands[1]) != CONST_INT
738           || INTVAL (operands[1]) > 127
739           || INTVAL (operands[1]) < -128
740           || CONST_OK_FOR_LETTER_P (INTVAL (operands[1]), 'N')
741           || CONST_OK_FOR_LETTER_P (INTVAL (operands[1]), 'J')))
742     return \"#\";
743   if (which_alternative == 1)
744     return \"#\";
745   return \"move.%s2 %2,[%3=%0%S1]\";
746 }")
747
748 ;; Like the biap case, a split where the set in the side-effect gets the
749 ;; same register as the input register to the main insn, since the
750 ;; condition isn't checked at register allocation.
751
752 (define_split
753   [(parallel
754     [(set (match_operator
755            4 "cris_mem_op"
756            [(plus:SI
757              (match_operand:SI 0 "cris_bdap_operand" "")
758              (match_operand:SI 1 "cris_bdap_operand" ""))])
759           (match_operand 2 "register_operand" ""))
760      (set (match_operand:SI 3 "register_operand" "")
761           (plus:SI (match_dup 0) (match_dup 1)))])]
762   "reload_completed && reg_overlap_mentioned_p (operands[3], operands[2])"
763   [(set (match_dup 4) (match_dup 2))
764    (set (match_dup 3) (match_dup 0))
765    (set (match_dup 3) (plus:SI (match_dup 3) (match_dup 1)))]
766   "")
767 \f
768 ;; Clear memory side-effect patterns.  It is hard to get to the mode if
769 ;; the MEM was anonymous, so there will be one for each mode.
770
771 ;; clear.d [ry=rx+rw.s2]
772
773 (define_insn "*clear_sidesi_biap"
774   [(set (mem:SI (plus:SI
775                  (mult:SI (match_operand:SI 0 "register_operand" "r,r")
776                           (match_operand:SI 1 "const_int_operand" "n,n"))
777                  (match_operand:SI 2 "register_operand" "r,r")))
778         (const_int 0))
779    (set (match_operand:SI 3 "register_operand" "=*2,r")
780         (plus:SI (mult:SI (match_dup 0)
781                           (match_dup 1))
782                  (match_dup 2)))]
783   "cris_side_effect_mode_ok (MULT, operands, 3, 2, 0, 1, -1)"
784   "@
785    #
786    clear.d [%3=%2+%0%T1]")
787
788 ;; clear.d [ry=rz+i]
789
790 (define_insn "*clear_sidesi"
791   [(set (mem:SI
792          (plus:SI (match_operand:SI 0 "cris_bdap_operand" "%r,r,r")
793                   (match_operand:SI 1 "cris_bdap_operand" "r>Rn,r,>Rn")))
794         (const_int 0))
795    (set (match_operand:SI 2 "register_operand" "=*0,r,r")
796         (plus:SI (match_dup 0)
797                  (match_dup 1)))]
798   "cris_side_effect_mode_ok (PLUS, operands, 2, 0, 1, -1, -1)"
799   "*
800 {
801   if (which_alternative == 0
802       && (GET_CODE (operands[1]) != CONST_INT
803           || INTVAL (operands[1]) > 127
804           || INTVAL (operands[1]) < -128
805           || CONST_OK_FOR_LETTER_P (INTVAL (operands[1]), 'N')
806           || CONST_OK_FOR_LETTER_P (INTVAL (operands[1]), 'J')))
807     return \"#\";
808   return \"clear.d [%2=%0%S1]\";
809 }")
810
811 ;;  clear.w [ry=rx+rw.s2]
812
813 (define_insn "*clear_sidehi_biap"
814   [(set (mem:HI (plus:SI
815                  (mult:SI (match_operand:SI 0 "register_operand" "r,r")
816                           (match_operand:SI 1 "const_int_operand" "n,n"))
817                  (match_operand:SI 2 "register_operand" "r,r")))
818         (const_int 0))
819    (set (match_operand:SI 3 "register_operand" "=*2,r")
820         (plus:SI (mult:SI (match_dup 0)
821                           (match_dup 1))
822                  (match_dup 2)))]
823   "cris_side_effect_mode_ok (MULT, operands, 3, 2, 0, 1, -1)"
824   "@
825    #
826    clear.w [%3=%2+%0%T1]")
827
828 ;; clear.w [ry=rz+i]
829
830 (define_insn "*clear_sidehi"
831   [(set (mem:HI
832          (plus:SI (match_operand:SI 0 "cris_bdap_operand" "%r,r,r")
833                   (match_operand:SI 1 "cris_bdap_operand" "r>Rn,r,>Rn")))
834         (const_int 0))
835    (set (match_operand:SI 2 "register_operand" "=*0,r,r")
836         (plus:SI (match_dup 0)
837                  (match_dup 1)))]
838   "cris_side_effect_mode_ok (PLUS, operands, 2, 0, 1, -1, -1)"
839   "*
840 {
841   if (which_alternative == 0
842       && (GET_CODE (operands[1]) != CONST_INT
843           || INTVAL (operands[1]) > 127
844           || INTVAL (operands[1]) < -128
845           || CONST_OK_FOR_LETTER_P (INTVAL (operands[1]), 'N')
846           || CONST_OK_FOR_LETTER_P (INTVAL (operands[1]), 'J')))
847     return \"#\";
848   return \"clear.w [%2=%0%S1]\";
849 }")
850
851 ;;  clear.b [ry=rx+rw.s2]
852
853 (define_insn "*clear_sideqi_biap"
854   [(set (mem:QI (plus:SI
855                  (mult:SI (match_operand:SI 0 "register_operand" "r,r")
856                           (match_operand:SI 1 "const_int_operand" "n,n"))
857                  (match_operand:SI 2 "register_operand" "r,r")))
858         (const_int 0))
859    (set (match_operand:SI 3 "register_operand" "=*2,r")
860         (plus:SI (mult:SI (match_dup 0)
861                           (match_dup 1))
862                  (match_dup 2)))]
863   "cris_side_effect_mode_ok (MULT, operands, 3, 2, 0, 1, -1)"
864   "@
865    #
866    clear.b [%3=%2+%0%T1]")
867
868 ;; clear.b [ry=rz+i]
869
870 (define_insn "*clear_sideqi"
871   [(set (mem:QI
872          (plus:SI (match_operand:SI 0 "cris_bdap_operand" "%r,r,r")
873                   (match_operand:SI 1 "cris_bdap_operand" "r>Rn,r,>Rn")))
874         (const_int 0))
875    (set (match_operand:SI 2 "register_operand" "=*0,r,r")
876         (plus:SI (match_dup 0)
877                  (match_dup 1)))]
878   "cris_side_effect_mode_ok (PLUS, operands, 2, 0, 1, -1, -1)"
879   "*
880 {
881   if (which_alternative == 0
882       && (GET_CODE (operands[1]) != CONST_INT
883           || INTVAL (operands[1]) > 127
884           || INTVAL (operands[1]) < -128
885           || CONST_OK_FOR_LETTER_P (INTVAL (operands[1]), 'N')
886           || CONST_OK_FOR_LETTER_P (INTVAL (operands[1]), 'J')))
887     return \"#\";
888   return \"clear.b [%2=%0%S1]\";
889 }")
890 \f
891 ;; To appease testcase gcc.c-torture/execute/920501-2.c (and others) at
892 ;; -O0, we need a movdi as a temporary measure.  Here's how things fail:
893 ;;  A cmpdi RTX needs reloading (global):
894 ;;    (insn 185 326 186 (set (cc0)
895 ;;          (compare (mem/f:DI (reg/v:SI 22) 0)
896 ;;              (const_int 1 [0x1]))) 4 {cmpdi} (nil)
897 ;;      (nil))
898 ;; Now, reg 22 is reloaded for input address, and the mem is also moved
899 ;; out of the instruction (into a register), since one of the operands
900 ;; must be a register.  Reg 22 is reloaded (into reg 10), and the mem is
901 ;; moved out and synthesized in SImode parts (reg 9, reg 10 - should be ok
902 ;; wrt. overlap).  The bad things happen with the synthesis in
903 ;; emit_move_insn_1; the location where to substitute reg 10 is lost into
904 ;; two new RTX:es, both still having reg 22.  Later on, the left-over reg
905 ;; 22 is recognized to have an equivalent in memory which is substituted
906 ;; straight in, and we end up with an unrecognizable insn:
907 ;;    (insn 325 324 326 (set (reg:SI 9 r9)
908 ;;            (mem/f:SI (mem:SI (plus:SI (reg:SI 8 r8)
909 ;;                        (const_int -84 [0xffffffac])) 0) 0)) -1 (nil)
910 ;;        (nil))
911 ;; which is the first part of the reloaded synthesized "movdi".
912 ;;  The right thing would be to add equivalent replacement locations for
913 ;; insn with pseudos that need more reloading.  The question is where.
914
915 ;; Normal move patterns from SI on.
916
917 (define_expand "movsi"
918   [(set
919     (match_operand:SI 0 "nonimmediate_operand" "")
920     (match_operand:SI 1 "cris_general_operand_or_symbol" ""))]
921   ""
922   "
923 {
924   /* If the output goes to a MEM, make sure we have zero or a register as
925      input.  */
926   if (GET_CODE (operands[0]) == MEM
927       && ! REG_S_P (operands[1])
928       && operands[1] != const0_rtx
929       && ! no_new_pseudos)
930     operands[1] = force_reg (SImode, operands[1]);
931
932   /* If we're generating PIC and have an incoming symbol, validize it to a
933      general operand or something that will match a special pattern.
934
935      FIXME: Do we *have* to recognize anything that would normally be a
936      valid symbol?  Can we exclude global PIC addresses with an added
937      offset?  */
938   if (flag_pic
939       && CONSTANT_ADDRESS_P (operands[1])
940       && cris_symbol (operands[1]))
941     {
942       /* We must have a register as destination for what we're about to
943          do, and for the patterns we generate.  */
944       if (! REG_S_P (operands[0]))
945         {
946           if (no_new_pseudos)
947             abort ();
948           operands[1] = force_reg (SImode, operands[1]);
949         }
950       else
951         {
952           /* Mark a needed PIC setup for a LABEL_REF:s coming in here:
953              they are so rare not-being-branch-targets that we don't mark
954              a function as needing PIC setup just because we have
955              inspected LABEL_REF:s as operands.  It is only in
956              __builtin_setjmp and such that we can get a LABEL_REF
957              assigned to a register.  */
958           if (GET_CODE (operands[1]) == LABEL_REF)
959             current_function_uses_pic_offset_table = 1;
960
961           /* We don't have to do anything for global PIC operands; they
962              look just like ``[rPIC+sym]''.  */
963           if (! cris_got_symbol (operands[1])
964               /* We don't do anything for local PIC operands; we match
965                  that with a special alternative.  */
966               && ! cris_gotless_symbol (operands[1]))
967             {
968               /* We get here when we have to change something that would
969                  be recognizable if it wasn't PIC.  A ``sym'' is ok for
970                  PIC symbols both with and without a GOT entry.  And ``sym
971                  + offset'' is ok for local symbols, so the only thing it
972                  could be, is a global symbol with an offset.  Check and
973                  abort if not.  */
974               rtx sym = get_related_value (operands[1]);
975               HOST_WIDE_INT offs = get_integer_term (operands[1]);
976
977               if (sym == NULL_RTX || offs == 0)
978                 abort ();
979               emit_move_insn (operands[0], sym);
980               if (expand_binop (SImode, add_optab, operands[0],
981                                 GEN_INT (offs), operands[0], 0,
982                                 OPTAB_LIB_WIDEN) != operands[0])
983                 abort ();
984               DONE;
985             }
986         }
987     }
988 }")
989
990 (define_insn "*movsi_internal"
991   [(set
992     (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,Q>,r,Q>,g,r,r,r,g")
993     (match_operand:SI 1
994     ;; FIXME: We want to put S last, but apparently g matches S.
995     ;; It's a bug: an S is not a general_operand and shouldn't match g.
996      "cris_general_operand_or_gotless_symbol" "r,Q>,M,M,I,r,M,n,!S,g,r"))]
997   ""
998   "*
999 {
1000   /* Better to have c-switch here; it is worth it to optimize the size of
1001      move insns.  The alternative would be to try to find more constraint
1002      letters.  FIXME: Check again.  It seems this could shrink a bit.  */
1003   switch (which_alternative)
1004     {
1005     case 0:
1006     case 1:
1007     case 5:
1008     case 9:
1009     case 10:
1010       return \"move.d %1,%0\";
1011
1012     case 2:
1013     case 3:
1014     case 6:
1015       return \"clear.d %0\";
1016
1017       /* Constants -32..31 except 0.  */
1018     case 4:
1019       return \"moveq %1,%0\";
1020
1021       /* We can win a little on constants -32768..-33, 32..65535.  */
1022     case 7:
1023       if (INTVAL (operands[1]) > 0 && INTVAL (operands[1]) < 65536)
1024         {
1025           if (INTVAL (operands[1]) < 256)
1026             return \"movu.b %1,%0\";
1027           return \"movu.w %1,%0\";
1028         }
1029       else if (INTVAL (operands[1]) >= -32768 && INTVAL (operands[1]) < 32768)
1030         {
1031           if (INTVAL (operands[1]) >= -128 && INTVAL (operands[1]) < 128)
1032             return \"movs.b %1,%0\";
1033           return \"movs.w %1,%0\";
1034         }
1035       return \"move.d %1,%0\";
1036
1037       case 8:
1038         /* FIXME: Try and split this into pieces GCC makes better code of,
1039            than this multi-insn pattern.  Synopsis: wrap the GOT-relative
1040            symbol into an unspec, and when PIC, recognize the unspec
1041            everywhere a symbol is normally recognized.  (The PIC register
1042            should be recognized by GCC as pic_offset_table_rtx when needed
1043            and similar for PC.)  Each component can then be optimized with
1044            the rest of the code; it should be possible to have a constant
1045            term added on an unspec.  Don't forget to add a REG_EQUAL (or
1046            is it REG_EQUIV) note to the destination.  It might not be
1047            worth it.  Measure.
1048
1049            Note that the 'v' modifier makes PLT references be output as
1050            sym:PLT rather than [rPIC+sym:GOTPLT].  */
1051         return \"move.d %v1,%0\;add.d %P1,%0\";
1052
1053     default:
1054       return \"BOGUS: %1 to %0\";
1055     }
1056 }"
1057   [(set_attr "slottable" "yes,yes,yes,yes,yes,yes,no,no,no,no,no")])
1058 \f
1059 ;; Extend operations with side-effect from mem to register, using
1060 ;; MOVS/MOVU.  These are from mem to register only.
1061 ;;
1062 ;; [rx=ry+rz.S]
1063 ;;
1064 ;; QImode to HImode
1065 ;;
1066 ;; FIXME: Can we omit extend to HImode, since GCC should truncate for
1067 ;; HImode by itself?  Perhaps use only anonymous modes?
1068
1069 (define_insn "*ext_sideqihi_biap"
1070   [(set (match_operand:HI 0 "register_operand" "=r,r")
1071         (match_operator:HI
1072          5 "cris_extend_operator"
1073          [(mem:QI (plus:SI
1074                    (mult:SI (match_operand:SI 1 "register_operand" "r,r")
1075                             (match_operand:SI 2 "const_int_operand" "n,n"))
1076                    (match_operand:SI 3 "register_operand" "r,r")))]))
1077    (set (match_operand:SI 4 "register_operand" "=*3,r")
1078         (plus:SI (mult:SI (match_dup 1)
1079                           (match_dup 2))
1080                  (match_dup 3)))]
1081   "cris_side_effect_mode_ok (MULT, operands, 4, 3, 1, 2, 0)"
1082   "@
1083    #
1084    mov%e5.%m5 [%4=%3+%1%T2],%0")
1085
1086 ;; QImode to SImode
1087
1088 (define_insn "*ext_sideqisi_biap"
1089   [(set (match_operand:SI 0 "register_operand" "=r,r")
1090         (match_operator:SI
1091          5 "cris_extend_operator"
1092          [(mem:QI (plus:SI
1093                    (mult:SI (match_operand:SI 1 "register_operand" "r,r")
1094                             (match_operand:SI 2 "const_int_operand" "n,n"))
1095                    (match_operand:SI 3 "register_operand" "r,r")))]))
1096    (set (match_operand:SI 4 "register_operand" "=*3,r")
1097         (plus:SI (mult:SI (match_dup 1)
1098                           (match_dup 2))
1099                  (match_dup 3)))]
1100   "cris_side_effect_mode_ok (MULT, operands, 4, 3, 1, 2, 0)"
1101   "@
1102    #
1103    mov%e5.%m5 [%4=%3+%1%T2],%0")
1104
1105 ;; HImode to SImode
1106
1107 (define_insn "*ext_sidehisi_biap"
1108   [(set (match_operand:SI 0 "register_operand" "=r,r")
1109         (match_operator:SI
1110          5 "cris_extend_operator"
1111          [(mem:HI (plus:SI
1112                    (mult:SI (match_operand:SI 1 "register_operand" "r,r")
1113                             (match_operand:SI 2 "const_int_operand" "n,n"))
1114                    (match_operand:SI 3 "register_operand" "r,r")))]))
1115    (set (match_operand:SI 4 "register_operand" "=*3,r")
1116         (plus:SI (mult:SI (match_dup 1)
1117                           (match_dup 2))
1118                  (match_dup 3)))]
1119   "cris_side_effect_mode_ok (MULT, operands, 4, 3, 1, 2, 0)"
1120   "@
1121    #
1122    mov%e5.%m5 [%4=%3+%1%T2],%0")
1123 \f
1124 ;; Same but [rx=ry+i]
1125
1126 ;; QImode to HImode
1127
1128 (define_insn "*ext_sideqihi"
1129   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
1130         (match_operator:HI
1131          4 "cris_extend_operator"
1132          [(mem:QI (plus:SI
1133                    (match_operand:SI 1 "cris_bdap_operand" "%r,r,r")
1134                    (match_operand:SI 2 "cris_bdap_operand" "r>Rn,r,>Rn")))]))
1135    (set (match_operand:SI 3 "register_operand" "=*1,r,r")
1136         (plus:SI (match_dup 1)
1137                  (match_dup 2)))]
1138   "cris_side_effect_mode_ok (PLUS, operands, 3, 1, 2, -1, 0)"
1139   "*
1140 {
1141   if (which_alternative == 0
1142       && (GET_CODE (operands[2]) != CONST_INT
1143           || INTVAL (operands[2]) > 127
1144           || INTVAL (operands[2]) < -128
1145           || CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'N')
1146           || CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'J')))
1147     return \"#\";
1148   return \"mov%e4.%m4 [%3=%1%S2],%0\";
1149 }")
1150
1151 ;; QImode to SImode
1152
1153 (define_insn "*ext_sideqisi"
1154   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1155         (match_operator:SI
1156          4 "cris_extend_operator"
1157          [(mem:QI (plus:SI
1158                    (match_operand:SI 1 "cris_bdap_operand" "%r,r,r")
1159                    (match_operand:SI 2 "cris_bdap_operand" "r>Rn,r,>Rn")))]))
1160    (set (match_operand:SI 3 "register_operand" "=*1,r,r")
1161         (plus:SI (match_dup 1)
1162                  (match_dup 2)))]
1163   "cris_side_effect_mode_ok (PLUS, operands, 3, 1, 2, -1, 0)"
1164   "*
1165 {
1166   if (which_alternative == 0
1167       && (GET_CODE (operands[2]) != CONST_INT
1168           || INTVAL (operands[2]) > 127
1169           || INTVAL (operands[2]) < -128
1170           || CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'N')
1171           || CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'J')))
1172     return \"#\";
1173   return \"mov%e4.%m4 [%3=%1%S2],%0\";
1174 }")
1175
1176 ;; HImode to SImode
1177
1178 (define_insn "*ext_sidehisi"
1179   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1180         (match_operator:SI
1181          4 "cris_extend_operator"
1182          [(mem:HI (plus:SI
1183                    (match_operand:SI 1 "cris_bdap_operand" "%r,r,r")
1184                    (match_operand:SI 2 "cris_bdap_operand" "r>Rn,r,>Rn")))]))
1185    (set (match_operand:SI 3 "register_operand" "=*1,r,r")
1186         (plus:SI (match_dup 1)
1187                  (match_dup 2)))]
1188   "cris_side_effect_mode_ok (PLUS, operands, 3, 1, 2, -1, 0)"
1189   "*
1190 {
1191   if (which_alternative == 0
1192       && (GET_CODE (operands[2]) != CONST_INT
1193           || INTVAL (operands[2]) > 127
1194           || INTVAL (operands[2]) < -128
1195           || CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'N')
1196           || CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'J')))
1197     return \"#\";
1198   return \"mov%e4.%m4 [%3=%1%S2],%0\";
1199 }")
1200 \f
1201 ;; FIXME: See movsi.
1202
1203 (define_insn "movhi"
1204   [(set
1205     (match_operand:HI 0 "nonimmediate_operand" "=r,r,r,Q>,r,Q>,r,r,r,g,g,r")
1206     (match_operand:HI 1 "general_operand" "r,Q>,M,M,I,r,L,O,n,M,r,g"))]
1207   ""
1208   "*
1209 {
1210   switch (which_alternative)
1211     {
1212     case 0:
1213     case 1:
1214     case 5:
1215     case 10:
1216     case 11:
1217       return \"move.w %1,%0\";
1218     case 2:
1219     case 3:
1220     case 9:
1221       return \"clear.w %0\";
1222     case 4:
1223       return \"moveq %1,%0\";
1224     case 6:
1225     case 8:
1226       if (INTVAL (operands[1]) < 256 && INTVAL (operands[1]) >= -128)
1227         {
1228           if (INTVAL (operands[1]) > 0)
1229             return \"movu.b %1,%0\";
1230           return \"movs.b %1,%0\";
1231         }
1232       return \"move.w %1,%0\";
1233     case 7:
1234       return \"movEq %b1,%0\";
1235     default:
1236       return \"BOGUS: %1 to %0\";
1237   }
1238 }"
1239   [(set_attr "slottable" "yes,yes,yes,yes,yes,yes,no,yes,no,no,no,no")
1240    (set (attr "cc")
1241         (if_then_else (eq_attr "alternative" "7")
1242                       (const_string "clobber")
1243                       (const_string "normal")))])
1244
1245 (define_insn "movstricthi"
1246   [(set
1247     (strict_low_part
1248      (match_operand:HI 0 "nonimmediate_operand" "+r,r,r,Q>,Q>,g,r,g"))
1249     (match_operand:HI 1 "general_operand" "r,Q>,M,M,r,M,g,r"))]
1250   ""
1251   "@
1252    move.w %1,%0
1253    move.w %1,%0
1254    clear.w %0
1255    clear.w %0
1256    move.w %1,%0
1257    clear.w %0
1258    move.w %1,%0
1259    move.w %1,%0"
1260   [(set_attr "slottable" "yes,yes,yes,yes,yes,no,no,no")])
1261 \f
1262 (define_insn "movqi"
1263   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,Q>,r,r,Q>,r,g,g,r,r")
1264         (match_operand:QI 1 "general_operand" "r,r,Q>,M,M,I,M,r,O,g"))]
1265   ""
1266   "@
1267    move.b %1,%0
1268    move.b %1,%0
1269    move.b %1,%0
1270    clear.b %0
1271    clear.b %0
1272    moveq %1,%0
1273    clear.b %0
1274    move.b %1,%0
1275    moveq %b1,%0
1276    move.b %1,%0"
1277   [(set_attr "slottable" "yes,yes,yes,yes,yes,yes,no,no,yes,no")
1278    (set (attr "cc")
1279         (if_then_else (eq_attr "alternative" "8")
1280                       (const_string "clobber")
1281                       (const_string "normal")))])
1282
1283 (define_insn "movstrictqi"
1284   [(set (strict_low_part
1285          (match_operand:QI 0 "nonimmediate_operand" "+r,Q>,r,r,Q>,g,g,r"))
1286         (match_operand:QI 1 "general_operand" "r,r,Q>,M,M,M,r,g"))]
1287   ""
1288   "@
1289    move.b %1,%0
1290    move.b %1,%0
1291    move.b %1,%0
1292    clear.b %0
1293    clear.b %0
1294    clear.b %0
1295    move.b %1,%0
1296    move.b %1,%0"
1297   [(set_attr "slottable" "yes,yes,yes,yes,yes,no,no,no")])
1298
1299 ;; The valid "quick" bit-patterns are, except for 0.0, denormalized
1300 ;; values REALLY close to 0, and some NaN:s (I think; their exponent is
1301 ;; all ones); the worthwhile one is "0.0".
1302 ;; It will use clear, so we know ALL types of immediate 0 never change cc.
1303
1304 (define_insn "movsf"
1305   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,Q>,r,r,Q>,g,g,r")
1306         (match_operand:SF 1 "general_operand" "r,r,Q>,G,G,G,r,g"))]
1307   ""
1308   "@
1309    move.d %1,%0
1310    move.d %1,%0
1311    move.d %1,%0
1312    clear.d %0
1313    clear.d %0
1314    clear.d %0
1315    move.d %1,%0
1316    move.d %1,%0"
1317   [(set_attr "slottable" "yes,yes,yes,yes,yes,no,no,no")])
1318 \f
1319
1320 ;; Sign- and zero-extend insns with standard names.
1321 ;;  Those for integer source operand are ordered with the widest source
1322 ;; type first.
1323
1324 ;; Sign-extend.
1325
1326 (define_insn "extendsidi2"
1327   [(set (match_operand:DI 0 "register_operand" "=r")
1328         (sign_extend:DI (match_operand:SI 1 "general_operand" "g")))]
1329   ""
1330   "move.d %1,%M0\;smi %H0\;neg.d %H0,%H0")
1331
1332 (define_insn "extendhidi2"
1333   [(set (match_operand:DI 0 "register_operand" "=r")
1334         (sign_extend:DI (match_operand:HI 1 "general_operand" "g")))]
1335   ""
1336   "movs.w %1,%M0\;smi %H0\;neg.d %H0,%H0")
1337
1338 (define_insn "extendhisi2"
1339   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1340         (sign_extend:SI (match_operand:HI 1 "general_operand" "r,Q>,g")))]
1341   ""
1342   "movs.w %1,%0"
1343   [(set_attr "slottable" "yes,yes,no")])
1344
1345 (define_insn "extendqidi2"
1346   [(set (match_operand:DI 0 "register_operand" "=r")
1347         (sign_extend:DI (match_operand:QI 1 "general_operand" "g")))]
1348   ""
1349   "movs.b %1,%M0\;smi %H0\;neg.d %H0,%H0")
1350
1351 (define_insn "extendqisi2"
1352   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1353         (sign_extend:SI (match_operand:QI 1 "general_operand" "r,Q>,g")))]
1354   ""
1355   "movs.b %1,%0"
1356   [(set_attr "slottable" "yes,yes,no")])
1357
1358 ;; To do a byte->word extension, extend to dword, exept that the top half
1359 ;; of the register will be clobbered.  FIXME: Perhaps this is not needed.
1360
1361 (define_insn "extendqihi2"
1362   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
1363         (sign_extend:HI (match_operand:QI 1 "general_operand" "r,Q>,g")))]
1364   ""
1365   "movs.b %1,%0"
1366   [(set_attr "slottable" "yes,yes,no")])
1367 \f
1368
1369 ;; Zero-extend.  The DImode ones are synthesized by gcc, so we don't
1370 ;; specify them here.
1371
1372 (define_insn "zero_extendhisi2"
1373   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1374         (zero_extend:SI
1375          (match_operand:HI 1 "nonimmediate_operand" "r,Q>,m")))]
1376   ""
1377   "movu.w %1,%0"
1378   [(set_attr "slottable" "yes,yes,no")])
1379
1380 (define_insn "zero_extendqisi2"
1381   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1382         (zero_extend:SI
1383          (match_operand:QI 1 "nonimmediate_operand" "r,Q>,m")))]
1384   ""
1385   "movu.b %1,%0"
1386   [(set_attr "slottable" "yes,yes,no")])
1387
1388 ;; Same comment as sign-extend QImode to HImode above applies.
1389
1390 (define_insn "zero_extendqihi2"
1391   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
1392         (zero_extend:HI
1393          (match_operand:QI 1 "nonimmediate_operand" "r,Q>,m")))]
1394   ""
1395   "movu.b %1,%0"
1396   [(set_attr "slottable" "yes,yes,no")])
1397 \f
1398 ;; All kinds of arithmetic and logical instructions.
1399 ;;
1400 ;; First, anonymous patterns to match addressing modes with
1401 ;; side-effects.
1402 ;;
1403 ;; op.S [rx=ry+I],rz; (add, sub, or, and, bound).
1404 ;;
1405 ;; [rx=ry+rz.S]
1406 ;; FIXME: These could have anonymous mode for operand 0.
1407
1408 ;; QImode
1409
1410 (define_insn "*op_sideqi_biap"
1411   [(set (match_operand:QI 0 "register_operand" "=r,r")
1412         (match_operator:QI
1413          6 "cris_orthogonal_operator"
1414          [(match_operand:QI 1 "register_operand" "0,0")
1415           (mem:QI (plus:SI
1416                    (mult:SI (match_operand:SI 2 "register_operand" "r,r")
1417                             (match_operand:SI 3 "const_int_operand" "n,n"))
1418                    (match_operand:SI 4 "register_operand" "r,r")))]))
1419    (set (match_operand:SI 5 "register_operand" "=*4,r")
1420         (plus:SI (mult:SI (match_dup 2)
1421                           (match_dup 3))
1422                  (match_dup 4)))]
1423   "cris_side_effect_mode_ok (MULT, operands, 5, 4, 2, 3, 0)"
1424   "@
1425    #
1426    %x6.%s0 [%5=%4+%2%T3],%0")
1427
1428 ;; HImode
1429
1430 (define_insn "*op_sidehi_biap"
1431   [(set (match_operand:HI 0 "register_operand" "=r,r")
1432         (match_operator:HI
1433          6 "cris_orthogonal_operator"
1434          [(match_operand:HI 1 "register_operand" "0,0")
1435           (mem:HI (plus:SI
1436                    (mult:SI (match_operand:SI 2 "register_operand" "r,r")
1437                             (match_operand:SI 3 "const_int_operand" "n,n"))
1438                    (match_operand:SI 4 "register_operand" "r,r")))]))
1439    (set (match_operand:SI 5 "register_operand" "=*4,r")
1440         (plus:SI (mult:SI (match_dup 2)
1441                           (match_dup 3))
1442                  (match_dup 4)))]
1443   "cris_side_effect_mode_ok (MULT, operands, 5, 4, 2, 3, 0)"
1444   "@
1445    #
1446    %x6.%s0 [%5=%4+%2%T3],%0")
1447
1448 ;; SImode
1449
1450 (define_insn "*op_sidesi_biap"
1451   [(set (match_operand:SI 0 "register_operand" "=r,r")
1452         (match_operator:SI
1453          6 "cris_orthogonal_operator"
1454          [(match_operand:SI 1 "register_operand" "0,0")
1455           (mem:SI (plus:SI
1456                    (mult:SI (match_operand:SI 2 "register_operand" "r,r")
1457                             (match_operand:SI 3 "const_int_operand" "n,n"))
1458                    (match_operand:SI 4 "register_operand" "r,r")))]))
1459    (set (match_operand:SI 5 "register_operand" "=*4,r")
1460         (plus:SI (mult:SI (match_dup 2)
1461                           (match_dup 3))
1462                  (match_dup 4)))]
1463   "cris_side_effect_mode_ok (MULT, operands, 5, 4, 2, 3, 0)"
1464   "@
1465    #
1466    %x6.%s0 [%5=%4+%2%T3],%0")
1467 \f
1468 ;; [rx=ry+i] ([%4=%2+%3])
1469 ;; FIXME: These could have anonymous mode for operand 0.
1470
1471 ;; QImode
1472
1473 (define_insn "*op_sideqi"
1474   [(set (match_operand:QI 0 "register_operand" "=r,r,r")
1475         (match_operator:QI
1476          5 "cris_orthogonal_operator"
1477          [(match_operand:QI 1 "register_operand" "0,0,0")
1478           (mem:QI (plus:SI
1479                    (match_operand:SI 2 "cris_bdap_operand" "%r,r,r")
1480                    (match_operand:SI 3 "cris_bdap_operand" "r>Rn,r,>Rn")))]))
1481    (set (match_operand:SI 4 "register_operand" "=*2,r,r")
1482         (plus:SI (match_dup 2)
1483                  (match_dup 3)))]
1484   "cris_side_effect_mode_ok (PLUS, operands, 4, 2, 3, -1, 0)"
1485   "*
1486 {
1487   if (which_alternative == 0
1488       && (GET_CODE (operands[3]) != CONST_INT
1489           || INTVAL (operands[3]) > 127
1490           || INTVAL (operands[3]) < -128
1491           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'N')
1492           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'J')))
1493     return \"#\";
1494   return \"%x5.%s0 [%4=%2%S3],%0\";
1495 }")
1496
1497 ;; HImode
1498
1499 (define_insn "*op_sidehi"
1500   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
1501         (match_operator:HI
1502          5 "cris_orthogonal_operator"
1503          [(match_operand:HI 1 "register_operand" "0,0,0")
1504           (mem:HI (plus:SI
1505                    (match_operand:SI 2 "cris_bdap_operand" "%r,r,r")
1506                    (match_operand:SI 3 "cris_bdap_operand" "r>Rn,r,>Rn")))]))
1507    (set (match_operand:SI 4 "register_operand" "=*2,r,r")
1508         (plus:SI (match_dup 2)
1509                  (match_dup 3)))]
1510   "cris_side_effect_mode_ok (PLUS, operands, 4, 2, 3, -1, 0)"
1511   "*
1512 {
1513   if (which_alternative == 0
1514       && (GET_CODE (operands[3]) != CONST_INT
1515           || INTVAL (operands[3]) > 127
1516           || INTVAL (operands[3]) < -128
1517           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'N')
1518           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'J')))
1519     return \"#\";
1520   return \"%x5.%s0 [%4=%2%S3],%0\";
1521 }")
1522
1523 ;; SImode
1524
1525 (define_insn "*op_sidesi"
1526   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1527         (match_operator:SI
1528          5 "cris_orthogonal_operator"
1529          [(match_operand:SI 1 "register_operand" "0,0,0")
1530           (mem:SI (plus:SI
1531                    (match_operand:SI 2 "cris_bdap_operand" "%r,r,r")
1532                    (match_operand:SI 3 "cris_bdap_operand" "r>Rn,r,>Rn")))]))
1533    (set (match_operand:SI 4 "register_operand" "=*2,r,r")
1534         (plus:SI (match_dup 2)
1535                  (match_dup 3)))]
1536   "cris_side_effect_mode_ok (PLUS, operands, 4, 2, 3, -1, 0)"
1537   "*
1538 {
1539   if (which_alternative == 0
1540       && (GET_CODE (operands[3]) != CONST_INT
1541           || INTVAL (operands[3]) > 127
1542           || INTVAL (operands[3]) < -128
1543           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'N')
1544           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'J')))
1545     return \"#\";
1546   return \"%x5.%s0 [%4=%2%S3],%0\";
1547 }")
1548 \f
1549 ;; To match all cases for commutative operations we may have to have the
1550 ;; following pattern for add, or & and.  I do not know really, but it does
1551 ;; not break anything.
1552 ;;
1553 ;; FIXME: This really ought to be checked.
1554 ;;
1555 ;; op.S [rx=ry+I],rz;
1556 ;;
1557 ;; [rx=ry+rz.S]
1558 ;; FIXME: These could have anonymous mode for operand 0.
1559
1560 ;; QImode
1561
1562 (define_insn "*op_swap_sideqi_biap"
1563   [(set (match_operand:QI 0 "register_operand" "=r,r")
1564         (match_operator:QI
1565          6 "cris_commutative_orth_op"
1566          [(mem:QI (plus:SI
1567                    (mult:SI (match_operand:SI 2 "register_operand" "r,r")
1568                             (match_operand:SI 3 "const_int_operand" "n,n"))
1569                    (match_operand:SI 4 "register_operand" "r,r")))
1570           (match_operand:QI 1 "register_operand" "0,0")]))
1571    (set (match_operand:SI 5 "register_operand" "=*4,r")
1572         (plus:SI (mult:SI (match_dup 2)
1573                           (match_dup 3))
1574                  (match_dup 4)))]
1575   "cris_side_effect_mode_ok (MULT, operands, 5, 4, 2, 3, 0)"
1576   "@
1577    #
1578    %x6.%s0 [%5=%4+%2%T3],%0")
1579
1580 ;; HImode
1581
1582 (define_insn "*op_swap_sidehi_biap"
1583   [(set (match_operand:HI 0 "register_operand" "=r,r")
1584         (match_operator:HI
1585          6 "cris_commutative_orth_op"
1586          [(mem:HI (plus:SI
1587                    (mult:SI (match_operand:SI 2 "register_operand" "r,r")
1588                             (match_operand:SI 3 "const_int_operand" "n,n"))
1589                    (match_operand:SI 4 "register_operand" "r,r")))
1590           (match_operand:HI 1 "register_operand" "0,0")]))
1591    (set (match_operand:SI 5 "register_operand" "=*4,r")
1592         (plus:SI (mult:SI (match_dup 2)
1593                           (match_dup 3))
1594                  (match_dup 4)))]
1595   "cris_side_effect_mode_ok (MULT, operands, 5, 4, 2, 3, 0)"
1596   "@
1597    #
1598    %x6.%s0 [%5=%4+%2%T3],%0")
1599
1600 ;; SImode
1601
1602 (define_insn "*op_swap_sidesi_biap"
1603   [(set (match_operand:SI 0 "register_operand" "=r,r")
1604         (match_operator:SI
1605          6 "cris_commutative_orth_op"
1606          [(mem:SI (plus:SI
1607                    (mult:SI (match_operand:SI 2 "register_operand" "r,r")
1608                             (match_operand:SI 3 "const_int_operand" "n,n"))
1609                    (match_operand:SI 4 "register_operand" "r,r")))
1610           (match_operand:SI 1 "register_operand" "0,0")]))
1611    (set (match_operand:SI 5 "register_operand" "=*4,r")
1612         (plus:SI (mult:SI (match_dup 2)
1613                           (match_dup 3))
1614                  (match_dup 4)))]
1615   "cris_side_effect_mode_ok (MULT, operands, 5, 4, 2, 3, 0)"
1616   "@
1617    #
1618    %x6.%s0 [%5=%4+%2%T3],%0")
1619 \f
1620 ;; [rx=ry+i] ([%4=%2+%3])
1621 ;; FIXME: These could have anonymous mode for operand 0.
1622
1623 ;; QImode
1624
1625 (define_insn "*op_swap_sideqi"
1626   [(set (match_operand:QI 0 "register_operand" "=r,r,r")
1627         (match_operator:QI
1628          5 "cris_commutative_orth_op"
1629          [(mem:QI
1630            (plus:SI (match_operand:SI 2 "cris_bdap_operand" "%r,r,r")
1631                     (match_operand:SI 3 "cris_bdap_operand" "r>Rn,r,>Rn")))
1632           (match_operand:QI 1 "register_operand" "0,0,0")]))
1633    (set (match_operand:SI 4 "register_operand" "=*2,r,r")
1634         (plus:SI (match_dup 2)
1635                  (match_dup 3)))]
1636   "cris_side_effect_mode_ok (PLUS, operands, 4, 2, 3, -1, 0)"
1637   "*
1638 {
1639   if (which_alternative == 0
1640       && (GET_CODE (operands[3]) != CONST_INT
1641           || INTVAL (operands[3]) > 127
1642           || INTVAL (operands[3]) < -128
1643           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'N')
1644           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'J')))
1645     return \"#\";
1646   return \"%x5.%s0 [%4=%2%S3],%0\";
1647 }")
1648
1649 ;; HImode
1650
1651 (define_insn "*op_swap_sidehi"
1652   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
1653         (match_operator:HI
1654          5 "cris_commutative_orth_op"
1655          [(mem:HI
1656            (plus:SI (match_operand:SI 2 "cris_bdap_operand" "%r,r,r")
1657                     (match_operand:SI 3 "cris_bdap_operand" "r>Rn,r,>Rn")))
1658           (match_operand:HI 1 "register_operand" "0,0,0")]))
1659    (set (match_operand:SI 4 "register_operand" "=*2,r,r")
1660         (plus:SI (match_dup 2)
1661                  (match_dup 3)))]
1662   "cris_side_effect_mode_ok (PLUS, operands, 4, 2, 3, -1, 0)"
1663   "*
1664 {
1665   if (which_alternative == 0
1666       && (GET_CODE (operands[3]) != CONST_INT
1667           || INTVAL (operands[3]) > 127
1668           || INTVAL (operands[3]) < -128
1669           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'N')
1670           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'J')))
1671     return \"#\";
1672   return \"%x5.%s0 [%4=%2%S3],%0\";
1673 }")
1674
1675 ;; SImode
1676
1677 (define_insn "*op_swap_sidesi"
1678   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1679         (match_operator:SI
1680          5 "cris_commutative_orth_op"
1681          [(mem:SI
1682            (plus:SI (match_operand:SI 2 "cris_bdap_operand" "%r,r,r")
1683                     (match_operand:SI 3 "cris_bdap_operand" "r>Rn,r,>Rn")))
1684           (match_operand:SI 1 "register_operand" "0,0,0")]))
1685    (set (match_operand:SI 4 "register_operand" "=*2,r,r")
1686         (plus:SI (match_dup 2)
1687                  (match_dup 3)))]
1688   "cris_side_effect_mode_ok (PLUS, operands, 4, 2, 3, -1, 0)"
1689   "*
1690 {
1691   if (which_alternative == 0
1692       && (GET_CODE (operands[3]) != CONST_INT
1693           || INTVAL (operands[3]) > 127
1694           || INTVAL (operands[3]) < -128
1695           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'N')
1696           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'J')))
1697     return \"#\";
1698   return \"%x5.%s0 [%4=%2%S3],%0\";
1699 }")
1700 \f
1701 ;; Add operations, standard names.
1702
1703 ;; Note that for the 'P' constraint, the high part can be -1 or 0.  We
1704 ;; output the insn through the 'A' output modifier as "adds.w" and "addq",
1705 ;; respectively.
1706 (define_insn "adddi3"
1707   [(set (match_operand:DI 0 "register_operand" "=r,r,r,&r,&r")
1708         (plus:DI (match_operand:DI 1 "register_operand" "%0,0,0,0,r")
1709                  (match_operand:DI 2 "general_operand" "J,N,P,g,!To")))]
1710   ""
1711   "@
1712    addq %2,%M0\;ax\;addq 0,%H0
1713    subq %n2,%M0\;ax\;subq 0,%H0
1714    add%e2.%z2 %2,%M0\;ax\;%A2 %H2,%H0
1715    add.d %M2,%M0\;ax\;add.d %H2,%H0
1716    add.d %M2,%M1,%M0\;ax\;add.d %H2,%H1,%H0")
1717
1718 (define_insn "addsi3"
1719   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r,r,r,r,r")
1720         (plus:SI
1721          (match_operand:SI 1 "register_operand" "%0,0,0,0,0,0,r,r")
1722          (match_operand:SI 2 "general_operand" "r,Q>,J,N,n,g,!To,0")))]
1723
1724 ;; The last constraint is due to that after reload, the '%' is not
1725 ;; honored, and canonicalization doesn't care about keeping the same
1726 ;; register as in destination.  This will happen after insn splitting.
1727 ;; gcc <= 2.7.2.  FIXME: Check for gcc-2.9x
1728
1729  ""
1730  "*
1731 {
1732   switch (which_alternative)
1733     {
1734     case 0:
1735     case 1:
1736       return \"add.d %2,%0\";
1737     case 2:
1738       return \"addq %2,%0\";
1739     case 3:
1740       return \"subq %n2,%0\";
1741     case 4:
1742       /* 'Known value', but not in -63..63.
1743          Check if addu/subu may be used.  */
1744       if (INTVAL (operands[2]) > 0)
1745         {
1746           if (INTVAL (operands[2]) < 256)
1747             return \"addu.b %2,%0\";
1748           if (INTVAL (operands[2]) < 65536)
1749             return \"addu.w %2,%0\";
1750         }
1751       else
1752         {
1753           if (INTVAL (operands[2]) >= -255)
1754             return \"subu.b %n2,%0\";
1755           if (INTVAL (operands[2]) >= -65535)
1756             return \"subu.w %n2,%0\";
1757         }
1758       return \"add.d %2,%0\";
1759     case 6:
1760       return \"add.d %2,%1,%0\";
1761     case 5:
1762       return \"add.d %2,%0\";
1763     case 7:
1764       return \"add.d %1,%0\";
1765     default:
1766       return \"BOGUS addsi %2+%1 to %0\";
1767     }
1768 }"
1769  [(set_attr "slottable" "yes,yes,yes,yes,no,no,no,yes")])
1770 \f
1771 (define_insn "addhi3"
1772   [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r,r")
1773         (plus:HI (match_operand:HI 1 "register_operand" "%0,0,0,0,0,r")
1774                  (match_operand:HI 2 "general_operand" "r,Q>,J,N,g,!To")))]
1775   ""
1776   "@
1777    add.w %2,%0
1778    add.w %2,%0
1779    addq %2,%0
1780    subq %n2,%0
1781    add.w %2,%0
1782    add.w %2,%1,%0"
1783   [(set_attr "slottable" "yes,yes,yes,yes,no,no")
1784    (set_attr "cc" "normal,normal,clobber,clobber,normal,normal")])
1785
1786 (define_insn "addqi3"
1787   [(set (match_operand:QI 0 "register_operand" "=r,r,r,r,r,r,r")
1788         (plus:QI (match_operand:QI 1 "register_operand" "%0,0,0,0,0,0,r")
1789                  (match_operand:QI 2 "general_operand" "r,Q>,J,N,O,g,!To")))]
1790   ""
1791   "@
1792    add.b %2,%0
1793    add.b %2,%0
1794    addq %2,%0
1795    subq %n2,%0
1796    subQ -%b2,%0
1797    add.b %2,%0
1798    add.b %2,%1,%0"
1799   [(set_attr "slottable" "yes,yes,yes,yes,yes,no,no")
1800    (set_attr "cc" "normal,normal,clobber,clobber,clobber,normal,normal")])
1801 \f
1802 ;; Subtract.
1803 ;;
1804 ;; Note that because of insn canonicalization these will *seldom* but
1805 ;; rarely be used with a known constant as an operand.
1806
1807 ;; Note that for the 'P' constraint, the high part can be -1 or 0.  We
1808 ;; output the insn through the 'D' output modifier as "subs.w" and "subq",
1809 ;; respectively.
1810 (define_insn "subdi3"
1811   [(set (match_operand:DI 0 "register_operand" "=r,r,r,&r,&r")
1812         (minus:DI (match_operand:DI 1 "register_operand" "0,0,0,0,r")
1813                   (match_operand:DI 2 "general_operand" "J,N,P,g,!To")))]
1814   ""
1815   "@
1816    subq %2,%M0\;ax\;subq 0,%H0
1817    addq %n2,%M0\;ax\;addq 0,%H0
1818    sub%e2.%z2 %2,%M0\;ax\;%D2 %H2,%H0
1819    sub.d %M2,%M0\;ax\;sub.d %H2,%H0
1820    sub.d %M2,%M1,%M0\;ax\;sub.d %H2,%H1,%H0")
1821
1822 (define_insn "subsi3"
1823   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r,r,r,r,r")
1824         (minus:SI
1825          (match_operand:SI 1 "register_operand" "0,0,0,0,0,0,0,r")
1826          (match_operand:SI 2 "general_operand" "r,Q>,J,N,P,n,g,!To")))]
1827   ""
1828
1829 ;; This does not do the optimal: "addu.w 65535,r0" when %2 is negative.
1830 ;; But then again, %2 should not be negative.
1831
1832   "@
1833    sub.d %2,%0
1834    sub.d %2,%0
1835    subq %2,%0
1836    addq %n2,%0
1837    sub%e2.%z2 %2,%0
1838    sub.d %2,%0
1839    sub.d %2,%0
1840    sub.d %2,%1,%0"
1841   [(set_attr "slottable" "yes,yes,yes,yes,no,no,no,no")])
1842 \f
1843 (define_insn "subhi3"
1844   [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r,r")
1845         (minus:HI (match_operand:HI 1 "register_operand" "0,0,0,0,0,r")
1846                   (match_operand:HI 2 "general_operand" "r,Q>,J,N,g,!To")))]
1847   ""
1848   "@
1849    sub.w %2,%0
1850    sub.w %2,%0
1851    subq %2,%0
1852    addq %n2,%0
1853    sub.w %2,%0
1854    sub.w %2,%1,%0"
1855   [(set_attr "slottable" "yes,yes,yes,yes,no,no")
1856    (set_attr "cc" "normal,normal,clobber,clobber,normal,normal")])
1857
1858 (define_insn "subqi3"
1859   [(set (match_operand:QI 0 "register_operand" "=r,r,r,r,r,r")
1860         (minus:QI (match_operand:QI 1 "register_operand" "0,0,0,0,0,r")
1861                   (match_operand:QI 2 "general_operand" "r,Q>,J,N,g,!To")))]
1862   ""
1863   "@
1864    sub.b %2,%0
1865    sub.b %2,%0
1866    subq %2,%0
1867    addq %2,%0
1868    sub.b %2,%0
1869    sub.b %2,%1,%0"
1870   [(set_attr "slottable" "yes,yes,yes,yes,no,no")
1871    (set_attr "cc" "normal,normal,clobber,clobber,normal,normal")])
1872 \f
1873 ;; CRIS has some add/sub-with-sign/zero-extend instructions.
1874 ;;  Although these perform sign/zero-extension to SImode, they are
1875 ;; equally applicable for the HImode case.
1876 ;; FIXME: Check; GCC should handle the widening.
1877 ;;  Note that these must be located after the normal add/sub patterns,
1878 ;; so not to get constants into any less specific operands.
1879 ;;
1880 ;; Extend with add/sub and side-effect.
1881 ;;
1882 ;; ADDS/SUBS/ADDU/SUBU and BOUND, which needs a check for zero_extend
1883 ;;
1884 ;; adds/subs/addu/subu bound [rx=ry+rz.S]
1885 ;; FIXME: These could have anonymous mode for operand 0.
1886
1887 ;; QImode to HImode
1888 ;; FIXME: GCC should widen.
1889
1890 (define_insn "*extopqihi_side_biap"
1891   [(set (match_operand:HI 0 "register_operand" "=r,r")
1892         (match_operator:HI
1893          6 "cris_additive_operand_extend_operator"
1894          [(match_operand:HI 1 "register_operand" "0,0")
1895           (match_operator:HI
1896            7 "cris_extend_operator"
1897            [(mem:QI (plus:SI
1898                      (mult:SI (match_operand:SI 2 "register_operand" "r,r")
1899                               (match_operand:SI 3 "const_int_operand" "n,n"))
1900                      (match_operand:SI 4 "register_operand" "r,r")))])]))
1901    (set (match_operand:SI 5 "register_operand" "=*4,r")
1902         (plus:SI (mult:SI (match_dup 2)
1903                           (match_dup 3))
1904                  (match_dup 4)))]
1905   "cris_side_effect_mode_ok (MULT, operands, 5, 4, 2, 3, 0)"
1906   "@
1907    #
1908    %x6%e7.%m7 [%5=%4+%2%T3],%0")
1909
1910 ;; QImode to SImode
1911
1912 (define_insn "*extopqisi_side_biap"
1913   [(set (match_operand:SI 0 "register_operand" "=r,r")
1914         (match_operator:SI
1915          6 "cris_operand_extend_operator"
1916          [(match_operand:SI 1 "register_operand" "0,0")
1917           (match_operator:SI
1918            7 "cris_extend_operator"
1919            [(mem:QI (plus:SI
1920                      (mult:SI (match_operand:SI 2 "register_operand" "r,r")
1921                               (match_operand:SI 3 "const_int_operand" "n,n"))
1922                      (match_operand:SI 4 "register_operand" "r,r")))])]))
1923    (set (match_operand:SI 5 "register_operand" "=*4,r")
1924         (plus:SI (mult:SI (match_dup 2)
1925                           (match_dup 3))
1926                  (match_dup 4)))]
1927   "(GET_CODE (operands[6]) != UMIN || GET_CODE (operands[7]) == ZERO_EXTEND)
1928    && cris_side_effect_mode_ok (MULT, operands, 5, 4, 2, 3, 0)"
1929   "@
1930    #
1931    %x6%e7.%m7 [%5=%4+%2%T3],%0")
1932
1933 ;; HImode to SImode
1934
1935 (define_insn "*extophisi_side_biap"
1936   [(set (match_operand:SI 0 "register_operand" "=r,r")
1937         (match_operator:SI
1938          6 "cris_operand_extend_operator"
1939          [(match_operand:SI 1 "register_operand" "0,0")
1940           (match_operator:SI
1941            7 "cris_extend_operator"
1942            [(mem:HI (plus:SI
1943                      (mult:SI (match_operand:SI 2 "register_operand" "r,r")
1944                               (match_operand:SI 3 "const_int_operand" "n,n"))
1945                      (match_operand:SI 4 "register_operand" "r,r")))])]))
1946    (set (match_operand:SI 5 "register_operand" "=*4,r")
1947         (plus:SI (mult:SI (match_dup 2)
1948                           (match_dup 3))
1949                  (match_dup 4)))]
1950   "(GET_CODE (operands[6]) != UMIN || GET_CODE (operands[7]) == ZERO_EXTEND)
1951    && cris_side_effect_mode_ok (MULT, operands, 5, 4, 2, 3, 0)"
1952   "@
1953    #
1954    %x6%e7.%m7 [%5=%4+%2%T3],%0")
1955 \f
1956
1957 ;; [rx=ry+i]
1958 ;; FIXME: These could have anonymous mode for operand 0.
1959
1960 ;; QImode to HImode
1961
1962 (define_insn "*extopqihi_side"
1963   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
1964         (match_operator:HI
1965          5 "cris_additive_operand_extend_operator"
1966          [(match_operand:HI 1 "register_operand" "0,0,0")
1967           (match_operator:HI
1968            6 "cris_extend_operator"
1969            [(mem:QI
1970              (plus:SI (match_operand:SI 2 "cris_bdap_operand" "%r,r,r")
1971                       (match_operand:SI 3 "cris_bdap_operand" "r>Rn,r,>Rn")
1972                       ))])]))
1973    (set (match_operand:SI 4 "register_operand" "=*2,r,r")
1974         (plus:SI (match_dup 2)
1975                  (match_dup 3)))]
1976   "cris_side_effect_mode_ok (PLUS, operands, 4, 2, 3, -1, 0)"
1977   "*
1978 {
1979   if (which_alternative == 0
1980       && (GET_CODE (operands[3]) != CONST_INT
1981           || INTVAL (operands[3]) > 127
1982           || INTVAL (operands[3]) < -128
1983           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'N')
1984           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'J')))
1985     return \"#\";
1986   return \"%x5%e6.%m6 [%4=%2%S3],%0\";
1987 }")
1988
1989 ;; QImode to SImode
1990
1991 (define_insn "*extopqisi_side"
1992   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1993         (match_operator:SI
1994          5 "cris_operand_extend_operator"
1995          [(match_operand:SI 1 "register_operand" "0,0,0")
1996           (match_operator:SI
1997            6 "cris_extend_operator"
1998            [(mem:QI
1999              (plus:SI (match_operand:SI 2 "cris_bdap_operand" "%r,r,r")
2000                       (match_operand:SI 3 "cris_bdap_operand" "r>Rn,r,>Rn")
2001                       ))])]))
2002    (set (match_operand:SI 4 "register_operand" "=*2,r,r")
2003         (plus:SI (match_dup 2)
2004                  (match_dup 3)))]
2005
2006   "(GET_CODE (operands[5]) != UMIN || GET_CODE (operands[6]) == ZERO_EXTEND)
2007    && cris_side_effect_mode_ok (PLUS, operands, 4, 2, 3, -1, 0)"
2008   "*
2009 {
2010   if (which_alternative == 0
2011       && (GET_CODE (operands[3]) != CONST_INT
2012           || INTVAL (operands[3]) > 127
2013           || INTVAL (operands[3]) < -128
2014           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'N')
2015           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'J')))
2016     return \"#\";
2017   return \"%x5%e6.%m6 [%4=%2%S3],%0\";
2018 }")
2019
2020 ;; HImode to SImode
2021
2022 (define_insn "*extophisi_side"
2023   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
2024         (match_operator:SI
2025          5 "cris_operand_extend_operator"
2026          [(match_operand:SI 1 "register_operand" "0,0,0")
2027           (match_operator:SI
2028            6 "cris_extend_operator"
2029            [(mem:HI
2030              (plus:SI (match_operand:SI 2 "cris_bdap_operand" "%r,r,r")
2031                       (match_operand:SI 3 "cris_bdap_operand" "r>Rn,r,>Rn")
2032                       ))])]))
2033    (set (match_operand:SI 4 "register_operand" "=*2,r,r")
2034         (plus:SI (match_dup 2)
2035                  (match_dup 3)))]
2036   "(GET_CODE (operands[5]) != UMIN || GET_CODE (operands[6]) == ZERO_EXTEND)
2037    && cris_side_effect_mode_ok (PLUS, operands, 4, 2, 3, -1, 0)"
2038   "*
2039 {
2040   if (which_alternative == 0
2041       && (GET_CODE (operands[3]) != CONST_INT
2042           || INTVAL (operands[3]) > 127
2043           || INTVAL (operands[3]) < -128
2044           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'N')
2045           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'J')))
2046     return \"#\";
2047   return \"%x5%e6.%m6 [%4=%2%S3],%0\";
2048 }")
2049 \f
2050
2051 ;; As with op.S we may have to add special pattern to match commuted
2052 ;; operands to adds/addu  and bound
2053 ;;
2054 ;; adds/addu/bound [rx=ry+rz.S]
2055
2056 ;; QImode to HImode
2057 ;; FIXME: GCC should widen.
2058
2059 (define_insn "*extopqihi_swap_side_biap"
2060   [(set (match_operand:HI 0 "register_operand" "=r,r")
2061         (plus:HI
2062          (match_operator:HI
2063           6 "cris_extend_operator"
2064           [(mem:QI (plus:SI
2065                     (mult:SI (match_operand:SI 2 "register_operand" "r,r")
2066                              (match_operand:SI 3 "const_int_operand" "n,n"))
2067                     (match_operand:SI 4 "register_operand" "r,r")))])
2068          (match_operand:HI 1 "register_operand" "0,0")))
2069    (set (match_operand:SI 5 "register_operand" "=*4,r")
2070         (plus:SI (mult:SI (match_dup 2)
2071                           (match_dup 3))
2072                  (match_dup 4)))]
2073   "cris_side_effect_mode_ok (MULT, operands, 5, 4, 2, 3, 0)"
2074   "@
2075    #
2076    add%e6.b [%5=%4+%2%T3],%0")
2077
2078 ;; QImode to SImode
2079
2080 (define_insn "*extopqisi_swap_side_biap"
2081   [(set (match_operand:SI 0 "register_operand" "=r,r")
2082         (match_operator:SI
2083          7 "cris_plus_or_bound_operator"
2084          [(match_operator:SI
2085            6 "cris_extend_operator"
2086            [(mem:QI (plus:SI
2087                      (mult:SI (match_operand:SI 2 "register_operand" "r,r")
2088                               (match_operand:SI 3 "const_int_operand" "n,n"))
2089                      (match_operand:SI 4 "register_operand" "r,r")))])
2090           (match_operand:SI 1 "register_operand" "0,0")]))
2091    (set (match_operand:SI 5 "register_operand" "=*4,r")
2092         (plus:SI (mult:SI (match_dup 2)
2093                           (match_dup 3))
2094                  (match_dup 4)))]
2095   "(GET_CODE (operands[7]) != UMIN || GET_CODE (operands[6]) == ZERO_EXTEND)
2096    && cris_side_effect_mode_ok (MULT, operands, 5, 4, 2, 3, 0)"
2097   "@
2098    #
2099    %x7%e6.%m6 [%5=%4+%2%T3],%0")
2100
2101 ;; HImode to SImode
2102 (define_insn "*extophisi_swap_side_biap"
2103   [(set (match_operand:SI 0 "register_operand" "=r,r")
2104         (match_operator:SI
2105          7 "cris_plus_or_bound_operator"
2106          [(match_operator:SI
2107            6 "cris_extend_operator"
2108            [(mem:HI (plus:SI
2109                      (mult:SI (match_operand:SI 2 "register_operand" "r,r")
2110                               (match_operand:SI 3 "const_int_operand" "n,n"))
2111                      (match_operand:SI 4 "register_operand" "r,r")))])
2112           (match_operand:SI 1 "register_operand" "0,0")]))
2113    (set (match_operand:SI 5 "register_operand" "=*4,r")
2114         (plus:SI (mult:SI (match_dup 2)
2115                           (match_dup 3))
2116                  (match_dup 4)))]
2117   "(GET_CODE (operands[7]) != UMIN || GET_CODE (operands[6]) == ZERO_EXTEND)
2118    && cris_side_effect_mode_ok (MULT, operands, 5, 4, 2, 3, 0)"
2119   "@
2120    #
2121    %x7%e6.%m6 [%5=%4+%2%T3],%0")
2122 \f
2123 ;; [rx=ry+i]
2124 ;; FIXME: These could have anonymous mode for operand 0.
2125 ;; FIXME: GCC should widen.
2126
2127 ;; QImode to HImode
2128
2129 (define_insn "*extopqihi_swap_side"
2130   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
2131         (plus:HI
2132          (match_operator:HI
2133           5 "cris_extend_operator"
2134           [(mem:QI (plus:SI
2135                     (match_operand:SI 2 "cris_bdap_operand" "%r,r,r")
2136                     (match_operand:SI 3 "cris_bdap_operand" "r>Rn,r,>Rn")))])
2137          (match_operand:HI 1 "register_operand" "0,0,0")))
2138    (set (match_operand:SI 4 "register_operand" "=*2,r,r")
2139         (plus:SI (match_dup 2)
2140                  (match_dup 3)))]
2141   "cris_side_effect_mode_ok (PLUS, operands, 4, 2, 3, -1, 0)"
2142   "*
2143 {
2144   if (which_alternative == 0
2145       && (GET_CODE (operands[3]) != CONST_INT
2146           || INTVAL (operands[3]) > 127
2147           || INTVAL (operands[3]) < -128
2148           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'N')
2149           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'J')))
2150     return \"#\";
2151   return \"add%e5.b [%4=%2%S3],%0\";
2152 }")
2153
2154 ;; QImode to SImode
2155
2156 (define_insn "*extopqisi_swap_side"
2157   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
2158         (match_operator:SI
2159          6 "cris_plus_or_bound_operator"
2160          [(match_operator:SI
2161            5 "cris_extend_operator"
2162            [(mem:QI (plus:SI
2163                      (match_operand:SI 2 "cris_bdap_operand" "%r,r,r")
2164                      (match_operand:SI 3 "cris_bdap_operand" "r>Rn,r,>Rn")))])
2165           (match_operand:SI 1 "register_operand" "0,0,0")]))
2166    (set (match_operand:SI 4 "register_operand" "=*2,r,r")
2167         (plus:SI (match_dup 2)
2168                  (match_dup 3)))]
2169   "(GET_CODE (operands[6]) != UMIN || GET_CODE (operands[5]) == ZERO_EXTEND)
2170    && cris_side_effect_mode_ok (PLUS, operands, 4, 2, 3, -1, 0)"
2171   "*
2172 {
2173   if (which_alternative == 0
2174       && (GET_CODE (operands[3]) != CONST_INT
2175           || INTVAL (operands[3]) > 127
2176           || INTVAL (operands[3]) < -128
2177           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'N')
2178           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'J')))
2179     return \"#\";
2180   return \"%x6%e5.%m5 [%4=%2%S3],%0\";
2181 }")
2182
2183 ;; HImode to SImode
2184
2185 (define_insn "*extophisi_swap_side"
2186   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
2187         (match_operator:SI
2188          6 "cris_plus_or_bound_operator"
2189          [(match_operator:SI
2190            5 "cris_extend_operator"
2191            [(mem:HI (plus:SI
2192                      (match_operand:SI 2 "cris_bdap_operand" "%r,r,r")
2193                      (match_operand:SI 3 "cris_bdap_operand" "r>Rn,r,>Rn")))])
2194           (match_operand:SI 1 "register_operand" "0,0,0")]))
2195    (set (match_operand:SI 4 "register_operand" "=*2,r,r")
2196         (plus:SI (match_dup 2)
2197                  (match_dup 3)))]
2198   "(GET_CODE (operands[6]) != UMIN || GET_CODE (operands[5]) == ZERO_EXTEND)
2199    && cris_side_effect_mode_ok (PLUS, operands, 4, 2, 3, -1, 0)"
2200   "*
2201 {
2202   if (which_alternative == 0
2203       && (GET_CODE (operands[3]) != CONST_INT
2204           || INTVAL (operands[3]) > 127
2205           || INTVAL (operands[3]) < -128
2206           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'N')
2207           || CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'J')))
2208     return \"#\";
2209   return \"%x6%e5.%m5 [%4=%2%S3],%0\";
2210 }")
2211 \f
2212 ;; Extend versions (zero/sign) of normal add/sub (no side-effects).
2213 ;; FIXME: These could have anonymous mode for operand 0.
2214
2215 ;; QImode to HImode
2216 ;; FIXME: GCC should widen.
2217
2218 (define_insn "*extopqihi"
2219   [(set (match_operand:HI 0 "register_operand" "=r,r,r,r")
2220         (match_operator:HI
2221          3 "cris_additive_operand_extend_operator"
2222          [(match_operand:HI 1 "register_operand" "0,0,0,r")
2223           (match_operator:HI
2224            4 "cris_extend_operator"
2225            [(match_operand:QI 2 "nonimmediate_operand" "r,Q>,m,!To")])]))]
2226   "GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
2227    && (operands[1] != frame_pointer_rtx || GET_CODE (operands[3]) != PLUS)"
2228   "@
2229    %x3%e4.%m4 %2,%0
2230    %x3%e4.%m4 %2,%0
2231    %x3%e4.%m4 %2,%0
2232    %x3%e4.%m4 %2,%1,%0"
2233   [(set_attr "slottable" "yes,yes,no,no")
2234    (set_attr "cc" "clobber")])
2235
2236 ;; QImode to SImode
2237
2238 (define_insn "*extopqisi"
2239   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
2240         (match_operator:SI
2241          3 "cris_operand_extend_operator"
2242          [(match_operand:SI 1 "register_operand" "0,0,0,r")
2243           (match_operator:SI
2244            4 "cris_extend_operator"
2245            [(match_operand:QI 2 "nonimmediate_operand" "r,Q>,m,!To")])]))]
2246   "(GET_CODE (operands[3]) != UMIN || GET_CODE (operands[4]) == ZERO_EXTEND)
2247    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
2248    && (operands[1] != frame_pointer_rtx || GET_CODE (operands[3]) != PLUS)"
2249   "@
2250    %x3%e4.%m4 %2,%0
2251    %x3%e4.%m4 %2,%0
2252    %x3%e4.%m4 %2,%0
2253    %x3%e4.%m4 %2,%1,%0"
2254   [(set_attr "slottable" "yes,yes,no,no")])
2255
2256 ;; HImode to SImode
2257
2258 (define_insn "*extophisi"
2259   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
2260         (match_operator:SI
2261          3 "cris_operand_extend_operator"
2262          [(match_operand:SI 1 "register_operand" "0,0,0,r")
2263           (match_operator:SI
2264            4 "cris_extend_operator"
2265            [(match_operand:HI 2 "nonimmediate_operand" "r,Q>,m,!To")])]))]
2266   "(GET_CODE (operands[3]) != UMIN || GET_CODE (operands[4]) == ZERO_EXTEND)
2267    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
2268    && (operands[1] != frame_pointer_rtx || GET_CODE (operands[3]) != PLUS)"
2269   "@
2270    %x3%e4.%m4 %2,%0
2271    %x3%e4.%m4 %2,%0
2272    %x3%e4.%m4 %2,%0
2273    %x3%e4.%m4 %2,%1,%0"
2274   [(set_attr "slottable" "yes,yes,no,no")])
2275 \f
2276
2277 ;; As with the side-effect patterns, may have to have swapped operands for add.
2278 ;; FIXME: *should* be redundant to gcc.
2279
2280 ;; QImode to HImode
2281
2282 (define_insn "*extopqihi_swap"
2283   [(set (match_operand:HI 0 "register_operand" "=r,r,r,r")
2284         (plus:HI
2285          (match_operator:HI
2286           3 "cris_extend_operator"
2287           [(match_operand:QI 2 "nonimmediate_operand" "r,Q>,m,!To")])
2288          (match_operand:HI 1 "register_operand" "0,0,0,r")))]
2289   "operands[1] != frame_pointer_rtx"
2290   "@
2291    add%e3.b %2,%0
2292    add%e3.b %2,%0
2293    add%e3.b %2,%0
2294    add%e3.b %2,%1,%0"
2295   [(set_attr "slottable" "yes,yes,no,no")
2296    (set_attr "cc" "clobber")])
2297
2298 ;; QImode to SImode
2299
2300 (define_insn "*extopqisi_swap"
2301   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
2302         (match_operator:SI
2303          4 "cris_plus_or_bound_operator"
2304          [(match_operator:SI
2305            3 "cris_extend_operator"
2306            [(match_operand:QI 2 "nonimmediate_operand" "r,Q>,m,!To")])
2307           (match_operand:SI 1 "register_operand" "0,0,0,r")]))]
2308   "(GET_CODE (operands[4]) != UMIN || GET_CODE (operands[3]) == ZERO_EXTEND)
2309    && operands[1] != frame_pointer_rtx"
2310   "@
2311    %x4%e3.%m3 %2,%0
2312    %x4%e3.%m3 %2,%0
2313    %x4%e3.%m3 %2,%0
2314    %x4%e3.%m3 %2,%1,%0"
2315   [(set_attr "slottable" "yes,yes,no,no")])
2316
2317 ;; HImode to SImode
2318
2319 (define_insn "*extophisi_swap"
2320   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
2321         (match_operator:SI
2322          4 "cris_plus_or_bound_operator"
2323          [(match_operator:SI
2324            3 "cris_extend_operator"
2325            [(match_operand:HI 2 "nonimmediate_operand" "r,Q>,m,!To")])
2326           (match_operand:SI 1 "register_operand" "0,0,0,r")]))]
2327   "(GET_CODE (operands[4]) != UMIN || GET_CODE (operands[3]) == ZERO_EXTEND)
2328    && operands[1] != frame_pointer_rtx"
2329   "@
2330    %x4%e3.%m3 %2,%0
2331    %x4%e3.%m3 %2,%0
2332    %x4%e3.%m3 %2,%0
2333    %x4%e3.%m3 %2,%1,%0"
2334   [(set_attr "slottable" "yes,yes,no,no")])
2335 \f
2336 ;; This is the special case when we use what corresponds to the
2337 ;; instruction above in "casesi".  Do *not* change it to use the generic
2338 ;; pattern and "REG 15" as pc; I did that and it led to madness and
2339 ;; maintenance problems: Instead of (as imagined) recognizing and removing
2340 ;; or replacing this pattern with something simpler, other variant
2341 ;; patterns were recognized or combined, including some prefix variants
2342 ;; where the value in pc is not that of the next instruction (which means
2343 ;; this instruction actually *is* special and *should* be marked as such).
2344 ;; When switching from the "generic pattern match" approach to this simpler
2345 ;; approach, there were insignificant differences in gcc, ipps and
2346 ;; product code, somehow due to scratching reload behind the ear or
2347 ;; something.  Testcase "gcc" looked .01% slower and 4 bytes bigger;
2348 ;; product code became .001% smaller but "looked better".  The testcase
2349 ;; "ipps" was just different at register allocation).
2350 ;;
2351 ;; Assumptions in the jump optimizer forces us to use IF_THEN_ELSE in this
2352 ;; pattern with the default-label as the else, with the "if" being
2353 ;; index-is-less-than the max number of cases plus one.  The default-label
2354 ;; is attached to the end of the case-table at time of output.
2355
2356 (define_insn "*casesi_adds_w"
2357   [(set (pc)
2358         (if_then_else
2359          (ltu (match_operand:SI 0 "register_operand" "r")
2360               (match_operand:SI 1 "const_int_operand" "n"))
2361          (plus:SI (sign_extend:SI
2362                    (mem:HI
2363                     (plus:SI (mult:SI (match_dup 0) (const_int 2))
2364                              (pc))))
2365                   (pc))
2366          (label_ref (match_operand 2 "" ""))))
2367    (use (label_ref (match_operand 3 "" "")))]
2368
2369   "operands[0] != frame_pointer_rtx"
2370
2371   "adds.w [$pc+%0.w],$pc"
2372   [(set_attr "cc" "clobber")])
2373 \f
2374 ;; Multiply instructions.
2375
2376 ;; Sometimes powers of 2 (which are normally canonicalized to a
2377 ;; left-shift) appear here, as a result of address reloading.
2378 ;; As a special, for values 3 and 5, we can match with an addi, so add those.
2379 ;;
2380 ;; FIXME: This may be unnecessary now.
2381 ;; Explicitly named for convenience of having a gen_... function.
2382
2383 (define_insn "addi_mul"
2384   [(set (match_operand:SI 0 "register_operand" "=r")
2385         (mult:SI
2386          (match_operand:SI 1 "register_operand" "%0")
2387          (match_operand:SI 2 "const_int_operand" "n")))]
2388   "operands[0] != frame_pointer_rtx
2389    && operands[1] != frame_pointer_rtx
2390    && GET_CODE (operands[2]) == CONST_INT
2391    && (INTVAL (operands[2]) == 2
2392        || INTVAL (operands[2]) == 4 || INTVAL (operands[2]) == 3
2393        || INTVAL (operands[2]) == 5)"
2394   "*
2395 {
2396   if (INTVAL (operands[2]) == 2)
2397     return \"lslq 1,%0\";
2398   else if (INTVAL (operands[2]) == 4)
2399     return \"lslq 2,%0\";
2400   else if (INTVAL (operands[2]) == 3)
2401     return \"addi %0.w,%0\";
2402   else if (INTVAL (operands[2]) == 5)
2403     return \"addi %0.d,%0\";
2404   return \"BAD: adr_mulsi: %0=%1*%2\";
2405 }"
2406 [(set_attr "slottable" "yes")
2407  ;; No flags are changed if this insn is "addi", but it does not seem
2408  ;; worth the trouble to distinguish that to the lslq cases.
2409  (set_attr "cc" "clobber")])
2410
2411 ;; The addi insn as it is normally used.
2412
2413 (define_insn "*addi"
2414   [(set (match_operand:SI 0 "register_operand" "=r")
2415         (plus:SI
2416          (mult:SI (match_operand:SI 2 "register_operand" "r")
2417                   (match_operand:SI 3 "const_int_operand" "n"))
2418          (match_operand:SI 1 "register_operand" "0")))]
2419   "operands[0] != frame_pointer_rtx
2420    && operands[1] != frame_pointer_rtx
2421    && GET_CODE (operands[3]) == CONST_INT
2422    && (INTVAL (operands[3]) == 1
2423        || INTVAL (operands[3]) == 2 || INTVAL (operands[3]) == 4)"
2424   "addi %2%T3,%0"
2425   [(set_attr "slottable" "yes")
2426    (set_attr "cc" "none")])
2427
2428 ;; The mstep instruction.  Probably not useful by itself; it's to
2429 ;; non-linear wrt. the other insns.  We used to expand to it, so at least
2430 ;; it's correct.
2431
2432 (define_insn "mstep_shift"
2433   [(set (match_operand:SI 0 "register_operand" "=r")
2434         (if_then_else:SI
2435          (lt:SI (cc0) (const_int 0))
2436          (plus:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
2437                              (const_int 1))
2438                   (match_operand:SI 2 "register_operand" "r"))
2439          (ashift:SI (match_operand:SI 3 "register_operand" "0")
2440                     (const_int 1))))]
2441   ""
2442   "mstep %2,%0"
2443   [(set_attr "slottable" "yes")])
2444
2445 ;; When illegitimate addresses are legitimized, sometimes gcc forgets
2446 ;; to canonicalize the multiplications.
2447 ;;
2448 ;; FIXME: Check gcc > 2.7.2, remove and possibly fix in gcc.
2449
2450 (define_insn "mstep_mul"
2451   [(set (match_operand:SI 0 "register_operand" "=r")
2452         (if_then_else:SI
2453          (lt:SI (cc0) (const_int 0))
2454          (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "0")
2455                            (const_int 2))
2456                   (match_operand:SI 2 "register_operand" "r"))
2457          (mult:SI (match_operand:SI 3 "register_operand" "0")
2458                   (const_int 2))))]
2459   "operands[0] != frame_pointer_rtx
2460    && operands[1] != frame_pointer_rtx
2461    && operands[2] != frame_pointer_rtx
2462    && operands[3] != frame_pointer_rtx"
2463   "mstep %2,%0"
2464   [(set_attr "slottable" "yes")])
2465
2466 (define_insn "umulhisi3"
2467   [(set (match_operand:SI 0 "register_operand" "=r")
2468         (mult:SI
2469          (zero_extend:SI (match_operand:HI 1 "register_operand" "0"))
2470          (zero_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
2471   "TARGET_HAS_MUL_INSNS"
2472   "%!mulu.w %2,%0"
2473   [(set (attr "slottable")
2474         (if_then_else (ne (symbol_ref "TARGET_MUL_BUG") (const_int 0))
2475                       (const_string "no")
2476                       (const_string "yes")))
2477    ;; Just N unusable here, but let's be safe.
2478    (set_attr "cc" "clobber")])
2479
2480 (define_insn "umulqihi3"
2481   [(set (match_operand:HI 0 "register_operand" "=r")
2482         (mult:HI
2483          (zero_extend:HI (match_operand:QI 1 "register_operand" "0"))
2484          (zero_extend:HI (match_operand:QI 2 "register_operand" "r"))))]
2485   "TARGET_HAS_MUL_INSNS"
2486   "%!mulu.b %2,%0"
2487   [(set (attr "slottable")
2488         (if_then_else (ne (symbol_ref "TARGET_MUL_BUG") (const_int 0))
2489                       (const_string "no")
2490                       (const_string "yes")))
2491    ;; Not exactly sure, but let's be safe.
2492    (set_attr "cc" "clobber")])
2493
2494 ;; Note that gcc does not make use of such a thing as umulqisi3.  It gets
2495 ;; confused and will erroneously use it instead of umulhisi3, failing (at
2496 ;; least) gcc.c-torture/execute/arith-rand.c at all optimization levels.
2497 ;; Inspection of optab code shows that there must be only one widening
2498 ;; multiplication per mode widened to.
2499
2500 (define_insn "mulsi3"
2501   [(set (match_operand:SI 0 "register_operand" "=r")
2502         (mult:SI (match_operand:SI 1 "register_operand" "0")
2503                  (match_operand:SI 2 "register_operand" "r")))]
2504   "TARGET_HAS_MUL_INSNS"
2505   "%!muls.d %2,%0"
2506   [(set (attr "slottable")
2507         (if_then_else (ne (symbol_ref "TARGET_MUL_BUG") (const_int 0))
2508                       (const_string "no")
2509                       (const_string "yes")))
2510    ;; Just N unusable here, but let's be safe.
2511    (set_attr "cc" "clobber")])
2512 \f
2513 ;; A few multiply variations.
2514
2515 ;; This really extends to SImode, so cc should be considered clobbered.
2516
2517 (define_insn "mulqihi3"
2518   [(set (match_operand:HI 0 "register_operand" "=r")
2519         (mult:HI
2520          (sign_extend:HI (match_operand:QI 1 "register_operand" "0"))
2521          (sign_extend:HI (match_operand:QI 2 "register_operand" "r"))))]
2522   "TARGET_HAS_MUL_INSNS"
2523   "%!muls.b %2,%0"
2524   [(set (attr "slottable")
2525         (if_then_else (ne (symbol_ref "TARGET_MUL_BUG") (const_int 0))
2526                       (const_string "no")
2527                       (const_string "yes")))
2528    (set_attr "cc" "clobber")])
2529
2530 (define_insn "mulhisi3"
2531   [(set (match_operand:SI 0 "register_operand" "=r")
2532         (mult:SI
2533          (sign_extend:SI (match_operand:HI 1 "register_operand" "0"))
2534          (sign_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
2535   "TARGET_HAS_MUL_INSNS"
2536   "%!muls.w %2,%0"
2537   [(set (attr "slottable")
2538         (if_then_else (ne (symbol_ref "TARGET_MUL_BUG") (const_int 0))
2539                       (const_string "no")
2540                       (const_string "yes")))
2541    ;; Just N unusable here, but let's be safe.
2542    (set_attr "cc" "clobber")])
2543
2544 ;; When needed, we can get the high 32 bits from the overflow
2545 ;; register.  We don't care to split and optimize these.
2546 ;;
2547 ;; Note that cc0 is still valid after the move-from-overflow-register
2548 ;; insn; no special precaution need to be taken in cris_notice_update_cc.
2549
2550 (define_insn "mulsidi3"
2551   [(set (match_operand:DI 0 "register_operand" "=r")
2552         (mult:DI
2553          (sign_extend:DI (match_operand:SI 1 "register_operand" "0"))
2554          (sign_extend:DI (match_operand:SI 2 "register_operand" "r"))))]
2555   "TARGET_HAS_MUL_INSNS"
2556   "%!muls.d %2,%M0\;move $mof,%H0")
2557
2558 (define_insn "umulsidi3"
2559   [(set (match_operand:DI 0 "register_operand" "=r")
2560         (mult:DI
2561          (zero_extend:DI (match_operand:SI 1 "register_operand" "0"))
2562          (zero_extend:DI (match_operand:SI 2 "register_operand" "r"))))]
2563   "TARGET_HAS_MUL_INSNS"
2564   "%!mulu.d %2,%M0\;move $mof,%H0")
2565
2566 ;; This pattern would probably not be needed if we add "mof" in its own
2567 ;; register class (and open a can of worms about /not/ pairing it with a
2568 ;; "normal" register).  Having multiple register classes here, and
2569 ;; applicable to the v10 variant only, seems worse than having these two
2570 ;; patterns with multi-insn contents for now (may change; having a free
2571 ;; call-clobbered register is worth some trouble).
2572
2573 (define_insn "smulsi3_highpart"
2574   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,m")
2575         (truncate:SI
2576          (lshiftrt:DI
2577           (mult:DI
2578            (sign_extend:DI (match_operand:SI 1 "register_operand" "%0,r,r"))
2579            (sign_extend:DI (match_operand:SI 2 "register_operand" "r,r,r")))
2580           (const_int 32))))
2581    (clobber (match_scratch:SI 3 "=X,1,1"))]
2582   "TARGET_HAS_MUL_INSNS"
2583   "%!muls.d %2,%1\;move $mof,%0"
2584   [(set_attr "cc" "clobber")])
2585
2586 (define_insn "umulsi3_highpart"
2587   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,m")
2588         (truncate:SI
2589          (lshiftrt:DI
2590           (mult:DI
2591            (zero_extend:DI (match_operand:SI 1 "register_operand" "%0,r,r"))
2592            (zero_extend:DI (match_operand:SI 2 "register_operand" "r,r,r")))
2593           (const_int 32))))
2594    (clobber (match_scratch:SI 3 "=X,1,1"))]
2595   "TARGET_HAS_MUL_INSNS"
2596   "%!mulu.d %2,%1\;move $mof,%0"
2597   [(set_attr "cc" "clobber")])
2598 \f
2599 ;; Divide and modulus instructions.  CRIS only has a step instruction.
2600
2601 (define_insn "dstep_shift"
2602   [(set (match_operand:SI 0 "register_operand" "=r")
2603         (if_then_else:SI
2604          (geu:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
2605                             (const_int 1))
2606               (match_operand:SI 2 "register_operand" "r"))
2607          (minus:SI (ashift:SI (match_operand:SI 3 "register_operand" "0")
2608                         (const_int 1))
2609                    (match_operand:SI 4 "register_operand" "2"))
2610          (ashift:SI (match_operand:SI 5 "register_operand" "0")
2611                         (const_int 1))))]
2612   ""
2613   "dstep %2,%0"
2614   [(set_attr "slottable" "yes")])
2615
2616 ;; Here's a variant with mult instead of ashift.
2617 ;;
2618 ;; FIXME: This should be investigated.  Which one matches through combination?
2619
2620 (define_insn "dstep_mul"
2621   [(set (match_operand:SI 0 "register_operand" "=r")
2622         (if_then_else:SI
2623          (geu:SI (mult:SI (match_operand:SI 1 "register_operand" "0")
2624                           (const_int 2))
2625               (match_operand:SI 2 "register_operand" "r"))
2626          (minus:SI (mult:SI (match_operand:SI 3 "register_operand" "0")
2627                             (const_int 2))
2628                    (match_operand:SI 4 "register_operand" "2"))
2629          (mult:SI (match_operand:SI 5 "register_operand" "0")
2630                   (const_int 2))))]
2631   "operands[0] != frame_pointer_rtx
2632    && operands[1] != frame_pointer_rtx
2633    && operands[2] != frame_pointer_rtx
2634    && operands[3] != frame_pointer_rtx"
2635   "dstep %2,%0"
2636   [(set_attr "slottable" "yes")])
2637 \f
2638 ;; Logical operators.
2639
2640 ;; Bitwise "and".
2641
2642 ;; There is no use in defining "anddi3", because gcc can expand this by
2643 ;; itself, and make reasonable code without interference.
2644
2645 ;; If the first operand is memory or a register and is the same as the
2646 ;; second operand, and the third operand is -256 or -65536, we can use
2647 ;; CLEAR instead.  Or, if the first operand is a register, and the third
2648 ;; operand is 255 or 65535, we can zero_extend.
2649 ;; GCC isn't smart enough to recognize these cases (yet), and they seem
2650 ;; to be common enough to be worthwhile.
2651 ;; FIXME: This should be made obsolete.
2652
2653 (define_expand "andsi3"
2654   [(set (match_operand:SI 0 "nonimmediate_operand"         "")
2655         (and:SI (match_operand:SI 1 "nonimmediate_operand" "")
2656                 (match_operand:SI 2 "general_operand"    "")))]
2657   ""
2658   "
2659 {
2660   if (! (GET_CODE (operands[2]) == CONST_INT
2661          && (((INTVAL (operands[2]) == -256
2662                || INTVAL (operands[2]) == -65536)
2663               && rtx_equal_p (operands[1], operands[0]))
2664              || ((INTVAL (operands[2]) == 255
2665                   || INTVAL (operands[2]) == 65535)
2666                  && REG_P (operands[0])))))
2667     {
2668       /* Make intermediate steps if operand0 is not a register or
2669          operand1 is not a register, and hope that the reload pass will
2670          make something useful out of it.  Note that the operands are
2671          *not* canonicalized.  For the moment, I chicken out on this,
2672          because all or most ports do not describe 'and' with
2673          canonicalized operands, and I seem to remember magic in reload,
2674          checking that operand1 has constraint '%0', in which case
2675          operand0 and operand1 must have similar predicates.
2676          FIXME: Investigate.  */
2677       rtx reg0 = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (SImode);
2678       rtx reg1 = operands[1];
2679
2680       if (! REG_P (reg1))
2681         {
2682           emit_move_insn (reg0, reg1);
2683           reg1 = reg0;
2684         }
2685
2686       emit_insn (gen_rtx_SET (SImode, reg0,
2687                           gen_rtx_AND (SImode, reg1, operands[2])));
2688
2689       /* Make sure we get the right *final* destination.  */
2690       if (! REG_P (operands[0]))
2691         emit_move_insn (operands[0], reg0);
2692
2693       DONE;
2694     }
2695 }")
2696
2697 ;; Some special cases of andsi3.
2698
2699 (define_insn "*andsi_movu"
2700   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
2701         (and:SI (match_operand:SI 1 "nonimmediate_operand" "%r,Q,To")
2702                 (match_operand:SI 2 "const_int_operand" "n,n,n")))]
2703   "(INTVAL (operands[2]) == 255 || INTVAL (operands[2]) == 65535)
2704    && (GET_CODE (operands[1]) != MEM || ! MEM_VOLATILE_P (operands[1]))"
2705   "movu.%z2 %1,%0"
2706   [(set_attr "slottable" "yes,yes,no")])
2707
2708 (define_insn "*andsi_clear"
2709   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,Q,Q,To,To")
2710         (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,0,0,0,0")
2711                 (match_operand:SI 2 "const_int_operand" "P,n,P,n,P,n")))]
2712   "(INTVAL (operands[2]) == -65536 || INTVAL (operands[2]) == -256)
2713    && (GET_CODE (operands[0]) != MEM || ! MEM_VOLATILE_P (operands[0]))"
2714   "@
2715    cLear.b %0
2716    cLear.w %0
2717    cLear.b %0
2718    cLear.w %0
2719    cLear.b %0
2720    cLear.w %0"
2721   [(set_attr "slottable" "yes,yes,yes,yes,no,no")
2722    (set_attr "cc" "none")])
2723
2724 ;; This is a catch-all pattern, taking care of everything that was not
2725 ;; matched in the insns above.
2726 ;;
2727 ;; Sidenote: the tightening from "nonimmediate_operand" to
2728 ;; "register_operand" for operand 1 actually increased the register
2729 ;; pressure (worse code).  That will hopefully change with an
2730 ;; improved reload pass.
2731
2732 (define_insn "*expanded_andsi"
2733   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r,r")
2734         (and:SI (match_operand:SI 1 "register_operand" "%0,0,0,0,r")
2735                 (match_operand:SI 2 "general_operand" "I,r,Q>,g,!To")))]
2736   ""
2737   "@
2738    andq %2,%0
2739    and.d %2,%0
2740    and.d %2,%0
2741    and.d %2,%0
2742    and.d %2,%1,%0"
2743   [(set_attr "slottable" "yes,yes,yes,no,no")])
2744 \f
2745 ;; For both QI and HI we may use the quick patterns.  This results in
2746 ;; useless condition codes, but that is used rarely enough for it to
2747 ;; normally be a win (could check ahead for use of cc0, but seems to be
2748 ;; more pain than win).
2749
2750 ;; FIXME: See note for andsi3
2751
2752 (define_expand "andhi3"
2753   [(set (match_operand:HI 0 "nonimmediate_operand" "")
2754         (and:HI (match_operand:HI 1 "nonimmediate_operand" "")
2755                 (match_operand:HI 2 "general_operand"  "")))]
2756   ""
2757   "
2758 {
2759   if (! (GET_CODE (operands[2]) == CONST_INT
2760          && (((INTVAL (operands[2]) == -256
2761                || INTVAL (operands[2]) == 65280)
2762               && rtx_equal_p (operands[1], operands[0]))
2763              || (INTVAL (operands[2]) == 255
2764                  && REG_P (operands[0])))))
2765     {
2766       /* See comment for andsi3.  */
2767       rtx reg0 = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (HImode);
2768       rtx reg1 = operands[1];
2769
2770       if (! REG_P (reg1))
2771         {
2772           emit_move_insn (reg0, reg1);
2773           reg1 = reg0;
2774         }
2775
2776       emit_insn (gen_rtx_SET (HImode, reg0,
2777                           gen_rtx_AND (HImode, reg1, operands[2])));
2778
2779       /* Make sure we get the right destination.  */
2780       if (! REG_P (operands[0]))
2781         emit_move_insn (operands[0], reg0);
2782
2783       DONE;
2784     }
2785 }")
2786
2787 ;; Some fast andhi3 special cases.
2788
2789 (define_insn "*andhi_movu"
2790   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
2791         (and:HI (match_operand:HI 1 "nonimmediate_operand" "r,Q,To")
2792                 (const_int 255)))]
2793   "GET_CODE (operands[1]) != MEM || ! MEM_VOLATILE_P (operands[1])"
2794   "mOvu.b %1,%0"
2795   [(set_attr "slottable" "yes,yes,no")])
2796
2797 (define_insn "*andhi_clear"
2798   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,Q,To")
2799         (and:HI (match_operand:HI 1 "nonimmediate_operand" "0,0,0")
2800                 (const_int -256)))]
2801   "GET_CODE (operands[0]) != MEM || ! MEM_VOLATILE_P (operands[0])"
2802   "cLear.b %0"
2803   [(set_attr "slottable" "yes,yes,no")
2804    (set_attr "cc" "none")])
2805
2806 ;; Catch-all andhi3 pattern.
2807
2808 (define_insn "*expanded_andhi"
2809   [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r,r,r")
2810         (and:HI (match_operand:HI 1 "register_operand" "%0,0,0,0,0,0,r")
2811                 (match_operand:HI 2 "general_operand" "I,r,Q>,L,O,g,!To")))]
2812
2813 ;; Sidenote: the tightening from "general_operand" to
2814 ;; "register_operand" for operand 1 actually increased the register
2815 ;; pressure (worse code).  That will hopefully change with an
2816 ;; improved reload pass.
2817
2818   ""
2819   "@
2820    andq %2,%0
2821    and.w %2,%0
2822    and.w %2,%0
2823    and.w %2,%0
2824    anDq %b2,%0
2825    and.w %2,%0
2826    and.w %2,%1,%0"
2827   [(set_attr "slottable" "yes,yes,yes,no,yes,no,no")
2828    (set_attr "cc" "clobber,normal,normal,normal,clobber,normal,normal")])
2829
2830 ;; A strict_low_part pattern.
2831
2832 (define_insn "*andhi_lowpart"
2833   [(set (strict_low_part
2834          (match_operand:HI 0 "register_operand" "=r,r,r,r,r,r"))
2835         (and:HI (match_operand:HI 1 "register_operand" "%0,0,0,0,0,r")
2836                 (match_operand:HI 2 "general_operand" "r,Q>,L,O,g,!To")))]
2837   ""
2838   "@
2839    and.w %2,%0
2840    and.w %2,%0
2841    and.w %2,%0
2842    anDq %b2,%0
2843    and.w %2,%0
2844    and.w %2,%1,%0"
2845   [(set_attr "slottable" "yes,yes,no,yes,no,no")
2846    (set_attr "cc" "normal,normal,normal,clobber,normal,normal")])
2847 \f
2848 (define_insn "andqi3"
2849   [(set (match_operand:QI 0 "register_operand" "=r,r,r,r,r,r")
2850         (and:QI (match_operand:QI 1 "register_operand" "%0,0,0,0,0,r")
2851                 (match_operand:QI 2 "general_operand" "I,r,Q>,O,g,!To")))]
2852   ""
2853   "@
2854    andq %2,%0
2855    and.b %2,%0
2856    and.b %2,%0
2857    andQ %b2,%0
2858    and.b %2,%0
2859    and.b %2,%1,%0"
2860   [(set_attr "slottable" "yes,yes,yes,yes,no,no")
2861    (set_attr "cc" "clobber,normal,normal,clobber,normal,normal")])
2862
2863 (define_insn "*andqi_lowpart"
2864   [(set (strict_low_part
2865          (match_operand:QI 0 "register_operand" "=r,r,r,r,r"))
2866         (and:QI (match_operand:QI 1 "register_operand" "%0,0,0,0,r")
2867                 (match_operand:QI 2 "general_operand" "r,Q>,O,g,!To")))]
2868   ""
2869   "@
2870    and.b %2,%0
2871    and.b %2,%0
2872    andQ %b2,%0
2873    and.b %2,%0
2874    and.b %2,%1,%0"
2875   [(set_attr "slottable" "yes,yes,yes,no,no")
2876    (set_attr "cc" "normal,normal,clobber,normal,normal")])
2877 \f
2878 ;; Bitwise or.
2879
2880 ;; Same comment as anddi3 applies here - no need for such a pattern.
2881
2882 ;; It seems there's no need to jump through hoops to get good code such as
2883 ;; with andsi3.
2884
2885 (define_insn "iorsi3"
2886   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r,r,r")
2887         (ior:SI (match_operand:SI 1 "register_operand" "%0,0,0,0,0,r")
2888                 (match_operand:SI 2 "general_operand" "I,r,Q>,n,g,!To")))]
2889   ""
2890   "@
2891    orq %2,%0
2892    or.d %2,%0
2893    or.d %2,%0
2894    oR.%s2 %2,%0
2895    or.d %2,%0
2896    or.d %2,%1,%0"
2897   [(set_attr "slottable" "yes,yes,yes,no,no,no")
2898    (set_attr "cc" "normal,normal,normal,clobber,normal,normal")])
2899
2900 (define_insn "iorhi3"
2901   [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r,r,r")
2902         (ior:HI (match_operand:HI 1 "register_operand" "%0,0,0,0,0,0,r")
2903                 (match_operand:HI 2 "general_operand" "I,r,Q>,L,O,g,!To")))]
2904   ""
2905   "@
2906    orq %2,%0
2907    or.w %2,%0
2908    or.w %2,%0
2909    or.w %2,%0
2910    oRq %b2,%0
2911    or.w %2,%0
2912    or.w %2,%1,%0"
2913   [(set_attr "slottable" "yes,yes,yes,no,yes,no,no")
2914    (set_attr "cc" "clobber,normal,normal,normal,clobber,normal,normal")])
2915
2916 (define_insn "iorqi3"
2917   [(set (match_operand:QI 0 "register_operand" "=r,r,r,r,r,r")
2918         (ior:QI (match_operand:QI 1 "register_operand" "%0,0,0,0,0,r")
2919                 (match_operand:QI 2 "general_operand" "I,r,Q>,O,g,!To")))]
2920   ""
2921   "@
2922    orq %2,%0
2923    or.b %2,%0
2924    or.b %2,%0
2925    orQ %b2,%0
2926    or.b %2,%0
2927    or.b %2,%1,%0"
2928   [(set_attr "slottable" "yes,yes,yes,yes,no,no")
2929    (set_attr "cc" "clobber,normal,normal,clobber,normal,normal")])
2930 \f
2931 ;; Exclusive-or
2932
2933 ;; See comment about "anddi3" for xordi3 - no need for such a pattern.
2934
2935 (define_insn "xorsi3"
2936   [(set (match_operand:SI 0 "register_operand" "=r")
2937         (xor:SI (match_operand:SI 1 "register_operand" "%0")
2938                 (match_operand:SI 2 "register_operand" "r")))]
2939   ""
2940   "xor %2,%0"
2941   [(set_attr "slottable" "yes")])
2942
2943 (define_insn "xorhi3"
2944   [(set (match_operand:HI 0 "register_operand" "=r")
2945         (xor:HI (match_operand:HI 1 "register_operand" "%0")
2946                 (match_operand:HI 2 "register_operand" "r")))]
2947   ""
2948   "xor %2,%0"
2949   [(set_attr "slottable" "yes")
2950    (set_attr "cc" "clobber")])
2951
2952 (define_insn "xorqi3"
2953   [(set (match_operand:QI 0 "register_operand" "=r")
2954         (xor:QI (match_operand:QI 1 "register_operand" "%0")
2955                 (match_operand:QI 2 "register_operand" "r")))]
2956   ""
2957   "xor %2,%0"
2958   [(set_attr "slottable" "yes")
2959    (set_attr "cc" "clobber")])
2960 \f
2961 ;; Negation insns.
2962
2963 ;; Questionable use, here mostly as a (slightly usable) define_expand
2964 ;; example.
2965
2966 (define_expand "negsf2"
2967   [(set (match_dup 2)
2968         (match_dup 3))
2969    (parallel [(set (match_operand:SF 0 "register_operand" "=r")
2970                    (neg:SF (match_operand:SF 1
2971                             "register_operand" "0")))
2972               (use (match_dup 2))])]
2973   ""
2974   "
2975 {
2976   operands[2] = gen_reg_rtx (SImode);
2977   operands[3] = GEN_INT (1 << 31);
2978 }")
2979
2980 (define_insn "*expanded_negsf2"
2981   [(set (match_operand:SF 0 "register_operand" "=r")
2982         (neg:SF (match_operand:SF 1 "register_operand" "0")))
2983    (use (match_operand:SI 2 "register_operand" "r"))]
2984   ""
2985   "xor %2,%0"
2986   [(set_attr "slottable" "yes")])
2987
2988 ;; No "negdi2" although we could make one up that may be faster than
2989 ;; the one in libgcc.
2990
2991 (define_insn "negsi2"
2992   [(set (match_operand:SI 0 "register_operand" "=r")
2993         (neg:SI (match_operand:SI 1 "register_operand" "r")))]
2994   ""
2995   "neg.d %1,%0"
2996   [(set_attr "slottable" "yes")])
2997
2998 (define_insn "neghi2"
2999   [(set (match_operand:HI 0 "register_operand" "=r")
3000         (neg:HI (match_operand:HI 1 "register_operand" "r")))]
3001   ""
3002   "neg.w %1,%0"
3003   [(set_attr "slottable" "yes")])
3004
3005 (define_insn "negqi2"
3006   [(set (match_operand:QI 0 "register_operand" "=r")
3007         (neg:QI (match_operand:QI 1 "register_operand" "r")))]
3008   ""
3009   "neg.b %1,%0"
3010   [(set_attr "slottable" "yes")])
3011 \f
3012 ;; One-complements.
3013
3014 ;; See comment on anddi3 - no need for a DImode pattern.
3015
3016 (define_insn "one_cmplsi2"
3017   [(set (match_operand:SI 0 "register_operand" "=r")
3018         (not:SI (match_operand:SI 1 "register_operand" "0")))]
3019   ""
3020   "not %0"
3021   [(set_attr "slottable" "yes")])
3022
3023 (define_insn "one_cmplhi2"
3024   [(set (match_operand:HI 0 "register_operand" "=r")
3025         (not:HI (match_operand:HI 1 "register_operand" "0")))]
3026   ""
3027   "not %0"
3028   [(set_attr "slottable" "yes")
3029    (set_attr "cc" "clobber")])
3030
3031 (define_insn "one_cmplqi2"
3032   [(set (match_operand:QI 0 "register_operand" "=r")
3033         (not:QI (match_operand:QI 1 "register_operand" "0")))]
3034   ""
3035   "not %0"
3036   [(set_attr "slottable" "yes")
3037    (set_attr "cc" "clobber")])
3038 \f
3039 ;; Arithmetic shift right.
3040
3041 (define_insn "ashrsi3"
3042   [(set (match_operand:SI 0 "register_operand" "=r")
3043         (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
3044                      (match_operand:SI 2 "nonmemory_operand" "Kr")))]
3045   ""
3046   "*
3047 {
3048   if (REG_S_P (operands[2]))
3049     return \"asr.d %2,%0\";
3050
3051   return \"asrq %2,%0\";
3052 }"
3053   [(set_attr "slottable" "yes")])
3054
3055 ;; Since gcc gets lost, and forgets to zero-extend the source (or mask
3056 ;; the destination) when it changes shifts of lower modes into SImode,
3057 ;; it is better to make these expands an anonymous patterns instead of
3058 ;; the more correct define_insns.  This occurs when gcc thinks that is
3059 ;; is better to widen to SImode and use immediate shift count.
3060
3061 ;; FIXME: Is this legacy or still true for gcc >= 2.7.2?
3062
3063 (define_expand "ashrhi3"
3064   [(set (match_dup 3)
3065         (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "rm")))
3066    (set (match_dup 4)
3067         (zero_extend:SI (match_operand:HI 2 "nonimmediate_operand" "rm")))
3068    (set (match_dup 5) (ashiftrt:SI (match_dup 3) (match_dup 4)))
3069    (set (match_operand:HI 0 "general_operand" "=g")
3070         (subreg:HI (match_dup 5) 0))]
3071   ""
3072   "
3073 {
3074   int i;
3075
3076   for (i = 3; i < 6; i++)
3077     operands[i] = gen_reg_rtx (SImode);
3078 }")
3079
3080 (define_insn "*expanded_ashrhi"
3081   [(set (match_operand:HI 0 "register_operand" "=r")
3082         (ashiftrt:HI (match_operand:HI 1 "register_operand" "0")
3083                      (match_operand:HI 2 "register_operand" "r")))]
3084   ""
3085   "asr.w %2,%0"
3086   [(set_attr "slottable" "yes")])
3087
3088 (define_insn "*ashrhi_lowpart"
3089   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+r"))
3090         (ashiftrt:HI (match_dup 0)
3091                      (match_operand:HI 1 "register_operand" "r")))]
3092   ""
3093   "asr.w %1,%0"
3094   [(set_attr "slottable" "yes")])
3095
3096 ;; Same comment goes as for "ashrhi3".
3097
3098 (define_expand "ashrqi3"
3099   [(set (match_dup 3)
3100         (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "g")))
3101    (set (match_dup 4)
3102         (zero_extend:SI (match_operand:QI 2 "nonimmediate_operand" "g")))
3103    (set (match_dup 5) (ashiftrt:SI (match_dup 3) (match_dup 4)))
3104    (set (match_operand:QI 0 "general_operand" "=g")
3105         (subreg:QI (match_dup 5) 0))]
3106   ""
3107   "
3108 {
3109   int i;
3110
3111   for (i = 3; i < 6; i++)
3112     operands[i] = gen_reg_rtx (SImode);
3113 }")
3114
3115 (define_insn "*expanded_ashrqi"
3116   [(set (match_operand:QI 0 "register_operand" "=r")
3117         (ashiftrt:QI (match_operand:QI 1 "register_operand" "0")
3118                      (match_operand:QI 2 "register_operand" "r")))]
3119   ""
3120   "asr.b %2,%0"
3121   [(set_attr "slottable" "yes")])
3122
3123 ;; A strict_low_part matcher.
3124
3125 (define_insn "*ashrqi_lowpart"
3126   [(set (strict_low_part (match_operand:QI 0 "register_operand" "+r"))
3127         (ashiftrt:QI (match_dup 0)
3128                      (match_operand:QI 1 "register_operand" "r")))]
3129   ""
3130   "asr.b %1,%0"
3131   [(set_attr "slottable" "yes")])
3132 \f
3133 ;; Logical shift right.
3134
3135 (define_insn "lshrsi3"
3136   [(set (match_operand:SI 0 "register_operand" "=r")
3137         (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
3138                      (match_operand:SI 2 "nonmemory_operand" "Kr")))]
3139   ""
3140   "*
3141 {
3142   if (REG_S_P (operands[2]))
3143     return \"lsr.d %2,%0\";
3144
3145   return \"lsrq %2,%0\";
3146 }"
3147   [(set_attr "slottable" "yes")])
3148
3149 ;; Same comments as for ashrhi3.
3150
3151 (define_expand "lshrhi3"
3152   [(set (match_dup 3)
3153         (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "g")))
3154    (set (match_dup 4)
3155         (zero_extend:SI (match_operand:HI 2 "nonimmediate_operand" "g")))
3156    (set (match_dup 5) (lshiftrt:SI (match_dup 3) (match_dup 4)))
3157    (set (match_operand:HI 0 "general_operand" "=g")
3158         (subreg:HI (match_dup 5) 0))]
3159   ""
3160   "
3161 {
3162   int i;
3163
3164   for (i = 3; i < 6; i++)
3165     operands[i] = gen_reg_rtx (SImode);
3166 }")
3167
3168 (define_insn "*expanded_lshrhi"
3169   [(set (match_operand:HI 0 "register_operand" "=r")
3170         (lshiftrt:HI (match_operand:HI 1 "register_operand" "0")
3171                      (match_operand:HI 2 "register_operand" "r")))]
3172   ""
3173   "lsr.w %2,%0"
3174   [(set_attr "slottable" "yes")])
3175
3176 ;; A strict_low_part matcher.
3177
3178 (define_insn "*lshrhi_lowpart"
3179   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+r"))
3180         (lshiftrt:HI (match_dup 0)
3181                      (match_operand:HI 1 "register_operand" "r")))]
3182   ""
3183   "lsr.w %1,%0"
3184   [(set_attr "slottable" "yes")])
3185
3186 ;; Same comments as for ashrhi3.
3187
3188 (define_expand "lshrqi3"
3189   [(set (match_dup 3)
3190         (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "g")))
3191    (set (match_dup 4)
3192         (zero_extend:SI (match_operand:QI 2 "nonimmediate_operand" "g")))
3193    (set (match_dup 5) (lshiftrt:SI (match_dup 3) (match_dup 4)))
3194    (set (match_operand:QI 0 "general_operand" "=g")
3195         (subreg:QI (match_dup 5) 0))]
3196   ""
3197   "
3198 {
3199   int i;
3200
3201   for (i = 3; i < 6; i++)
3202     operands[i] = gen_reg_rtx (SImode);
3203 }")
3204
3205 (define_insn "*expanded_lshrqi"
3206   [(set (match_operand:QI 0 "register_operand" "=r")
3207         (lshiftrt:QI (match_operand:QI 1 "register_operand" "0")
3208                      (match_operand:QI 2 "register_operand" "r")))]
3209   ""
3210   "lsr.b %2,%0"
3211   [(set_attr "slottable" "yes")])
3212
3213 ;; A strict_low_part matcher.
3214
3215 (define_insn "*lshrqi_lowpart"
3216   [(set (strict_low_part (match_operand:QI 0 "register_operand" "+r"))
3217         (lshiftrt:QI (match_dup 0)
3218                      (match_operand:QI 1 "register_operand" "r")))]
3219   ""
3220   "lsr.b %1,%0"
3221   [(set_attr "slottable" "yes")])
3222 \f
3223 ;; Arithmetic/logical shift left.
3224
3225 (define_insn "ashlsi3"
3226   [(set (match_operand:SI 0 "register_operand" "=r")
3227         (ashift:SI (match_operand:SI 1 "register_operand" "0")
3228                    (match_operand:SI 2 "nonmemory_operand" "Kr")))]
3229   ""
3230   "*
3231 {
3232   if (REG_S_P (operands[2]))
3233     return \"lsl.d %2,%0\";
3234
3235   return \"lslq %2,%0\";
3236 }"
3237   [(set_attr "slottable" "yes")])
3238
3239 ;; For narrower modes than SI, we can use lslq although it makes cc
3240 ;; unusable.  The win is that we do not have to reload the shift-count
3241 ;; into a register.
3242
3243 (define_insn "ashlhi3"
3244   [(set (match_operand:HI 0 "register_operand" "=r,r")
3245         (ashift:HI (match_operand:HI 1 "register_operand" "0,0")
3246                    (match_operand:HI 2 "nonmemory_operand" "r,K")))]
3247   ""
3248   "*
3249 {
3250   return
3251     (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) > 15)
3252     ? \"moveq 0,%0\"
3253     : (CONSTANT_P (operands[2])
3254        ? \"lslq %2,%0\" : \"lsl.w %2,%0\");
3255 }"
3256   [(set_attr "slottable" "yes")
3257    (set_attr "cc" "normal,clobber")])
3258
3259 ;; A strict_low_part matcher.
3260
3261 (define_insn "*ashlhi_lowpart"
3262   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+r"))
3263         (ashift:HI (match_dup 0)
3264                    (match_operand:HI 1 "register_operand" "r")))]
3265   ""
3266   "lsl.w %1,%0"
3267   [(set_attr "slottable" "yes")])
3268
3269 (define_insn "ashlqi3"
3270   [(set (match_operand:QI 0 "register_operand" "=r,r")
3271         (ashift:QI (match_operand:QI 1 "register_operand" "0,0")
3272                    (match_operand:QI 2 "nonmemory_operand" "r,K")))]
3273   ""
3274   "*
3275 {
3276   return
3277     (GET_CODE (operands[2]) == CONST_INT
3278      && INTVAL (operands[2]) > 7)
3279     ? \"moveq 0,%0\"
3280     : (CONSTANT_P (operands[2])
3281        ? \"lslq %2,%0\" : \"lsl.b %2,%0\");
3282 }"
3283   [(set_attr "slottable" "yes")
3284    (set_attr "cc" "normal,clobber")])
3285
3286 ;; A strict_low_part matcher.
3287
3288 (define_insn "*ashlqi_lowpart"
3289   [(set (strict_low_part (match_operand:QI 0 "register_operand" "+r"))
3290         (ashift:QI (match_dup 0)
3291                    (match_operand:QI 1 "register_operand" "r")))]
3292   ""
3293   "lsl.b %1,%0"
3294   [(set_attr "slottable" "yes")])
3295 \f
3296 ;; Various strange insns that gcc likes.
3297
3298 ;; Fortunately, it is simple to construct an abssf (although it may not
3299 ;; be very much used in practice).
3300
3301 (define_insn "abssf2"
3302   [(set (match_operand:SF 0 "register_operand" "=r")
3303         (abs:SF (match_operand:SF 1 "register_operand" "0")))]
3304   ""
3305   "lslq 1,%0\;lsrq 1,%0")
3306
3307 (define_insn "abssi2"
3308   [(set (match_operand:SI 0 "register_operand" "=r")
3309         (abs:SI (match_operand:SI 1 "register_operand" "r")))]
3310   ""
3311   "abs %1,%0"
3312   [(set_attr "slottable" "yes")])
3313
3314 ;; FIXME: GCC should be able to do these expansions itself.
3315
3316 (define_expand "abshi2"
3317   [(set (match_dup 2)
3318         (sign_extend:SI (match_operand:HI 1 "general_operand" "g")))
3319    (set (match_dup 3) (abs:SI (match_dup 2)))
3320    (set (match_operand:HI 0 "register_operand" "=r")
3321         (subreg:HI (match_dup 3) 0))]
3322   ""
3323   "operands[2] = gen_reg_rtx (SImode); operands[3] = gen_reg_rtx (SImode);")
3324
3325 (define_expand "absqi2"
3326   [(set (match_dup 2)
3327         (sign_extend:SI (match_operand:QI 1 "general_operand" "g")))
3328    (set (match_dup 3) (abs:SI (match_dup 2)))
3329    (set (match_operand:QI 0 "register_operand" "=r")
3330         (subreg:QI (match_dup 3) 0))]
3331   ""
3332   "operands[2] = gen_reg_rtx (SImode); operands[3] = gen_reg_rtx (SImode);")
3333 \f
3334 ;; Bound-insn.  Defined to be the same as an unsigned minimum, which is an
3335 ;; operation supported by gcc.  Used in casesi, but used now and then in
3336 ;; normal code too.
3337
3338 (define_insn "uminsi3"
3339   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
3340         (umin:SI  (match_operand:SI 1 "register_operand" "%0,0,0,r")
3341                   (match_operand:SI 2 "general_operand" "r,Q>,g,!STo")))]
3342   ""
3343   "*
3344 {
3345   if (GET_CODE (operands[2]) == CONST_INT)
3346     {
3347       if (INTVAL (operands[2]) < 256)
3348         return \"bound.b %2,%0\";
3349
3350       if (INTVAL (operands[2]) < 65536)
3351         return \"bound.w %2,%0\";
3352     }
3353   else if (which_alternative == 3)
3354     return \"bound.d %2,%1,%0\";
3355
3356   return \"bound.d %2,%0\";
3357 }"
3358  [(set_attr "slottable" "yes,yes,no,no")])
3359 \f
3360 ;; Jump and branch insns.
3361
3362 (define_insn "jump"
3363   [(set (pc)
3364         (label_ref (match_operand 0 "" "")))]
3365   ""
3366   "ba %l0%#"
3367   [(set_attr "slottable" "has_slot")])
3368
3369 ;; Testcase gcc.c-torture/compile/991213-3.c fails if we allow a constant
3370 ;; here, since the insn is not recognized as an indirect jump by
3371 ;; jmp_uses_reg_or_mem used by computed_jump_p.  Perhaps it is a kludge to
3372 ;; change from general_operand to nonimmediate_operand (at least the docs
3373 ;; should be changed), but then again the pattern is called indirect_jump.
3374 (define_insn "indirect_jump"
3375   [(set (pc) (match_operand:SI 0 "nonimmediate_operand" "rm"))]
3376   ""
3377   "jump %0")
3378
3379 ;; Return insn.  Used whenever the epilogue is very simple; if it is only
3380 ;; a single ret or jump [sp+] or a contiguous sequence of movem:able saved
3381 ;; registers.  No allocated stack space is allowed.
3382 ;; Note that for this pattern, although named, it is ok to check the
3383 ;; context of the insn in the test, not only compiler switches.
3384
3385 (define_insn "return"
3386   [(return)]
3387   "cris_simple_epilogue ()"
3388   "*
3389 {
3390   int i;
3391
3392   /* Just needs to hold a 'movem [sp+],rN'.  */
3393   char rd[sizeof (\"movem [$sp+],$r99\")];
3394
3395   /* Try to avoid reorg.c surprises; avoid emitting invalid code, prefer
3396      crashing.  This test would have avoided invalid code for target/7042.  */
3397   if (current_function_epilogue_delay_list != NULL)
3398     abort ();
3399
3400   *rd = 0;
3401
3402   /* Start from the last call-saved register.  We know that we have a
3403      simple epilogue, so we just have to find the last register in the
3404      movem sequence.  */
3405   for (i = 8; i >= 0; i--)
3406     if (regs_ever_live[i]
3407         || (i == PIC_OFFSET_TABLE_REGNUM
3408             && current_function_uses_pic_offset_table))
3409       break;
3410
3411   if (i >= 0)
3412     sprintf (rd, \"movem [$sp+],$%s\", reg_names [i]);
3413
3414   if (regs_ever_live[CRIS_SRP_REGNUM])
3415     {
3416       if (*rd)
3417         output_asm_insn (rd, operands);
3418       return \"jump [$sp+]\";
3419     }
3420
3421   if (*rd)
3422     {
3423       output_asm_insn (\"reT\", operands);
3424       output_asm_insn (rd, operands);
3425       return \"\";
3426     }
3427
3428   return \"ret%#\";
3429 }"
3430   [(set (attr "slottable")
3431         (if_then_else
3432          (ne (symbol_ref "regs_ever_live[CRIS_SRP_REGNUM]") (const_int 0))
3433          (const_string "no")         ; If jump then not slottable.
3434          (if_then_else
3435           (ne (symbol_ref
3436                "(regs_ever_live[0]
3437                  || (flag_pic != 0 && regs_ever_live[1])
3438                  || (PIC_OFFSET_TABLE_REGNUM == 0
3439                      && cris_cfun_uses_pic_table ()))")
3440               (const_int 0))
3441           (const_string "no") ; ret+movem [sp+],rx: slot already filled.
3442           (const_string "has_slot")))) ; If ret then need to fill a slot.
3443    (set_attr "cc" "none")])
3444 \f
3445 ;; Conditional branches.
3446
3447 ;; We suffer from the same overflow-bit-gets-in-the-way problem as
3448 ;; e.g. m68k, so we have to check if overflow bit is set on all "signed"
3449 ;; conditions.
3450
3451 (define_insn "beq"
3452   [(set (pc)
3453         (if_then_else (eq (cc0)
3454                           (const_int 0))
3455                       (label_ref (match_operand 0 "" ""))
3456                       (pc)))]
3457   ""
3458   "beq %l0%#"
3459   [(set_attr "slottable" "has_slot")])
3460
3461 (define_insn "bne"
3462   [(set (pc)
3463         (if_then_else (ne (cc0)
3464                           (const_int 0))
3465                       (label_ref (match_operand 0 "" ""))
3466                       (pc)))]
3467   ""
3468   "bne %l0%#"
3469   [(set_attr "slottable" "has_slot")])
3470
3471 (define_insn "bgt"
3472   [(set (pc)
3473         (if_then_else (gt (cc0)
3474                           (const_int 0))
3475                       (label_ref (match_operand 0 "" ""))
3476                       (pc)))]
3477   ""
3478   "*
3479 {
3480   return
3481     (cc_prev_status.flags & CC_NO_OVERFLOW)
3482     ? 0 : \"bgt %l0%#\";
3483 }"
3484   [(set_attr "slottable" "has_slot")])
3485
3486 (define_insn "bgtu"
3487   [(set (pc)
3488         (if_then_else (gtu (cc0)
3489                            (const_int 0))
3490                       (label_ref (match_operand 0 "" ""))
3491                       (pc)))]
3492   ""
3493   "bhi %l0%#"
3494   [(set_attr "slottable" "has_slot")])
3495
3496 (define_insn "blt"
3497   [(set (pc)
3498         (if_then_else (lt (cc0)
3499                           (const_int 0))
3500                       (label_ref (match_operand 0 "" ""))
3501                       (pc)))]
3502   ""
3503   "*
3504 {
3505   return
3506     (cc_prev_status.flags & CC_NO_OVERFLOW)
3507     ? \"bmi %l0%#\" : \"blt %l0%#\";
3508 }"
3509   [(set_attr "slottable" "has_slot")])
3510
3511 (define_insn "bltu"
3512   [(set (pc)
3513         (if_then_else (ltu (cc0)
3514                            (const_int 0))
3515                       (label_ref (match_operand 0 "" ""))
3516                       (pc)))]
3517   ""
3518   "blo %l0%#"
3519   [(set_attr "slottable" "has_slot")])
3520
3521 (define_insn "bge"
3522   [(set (pc)
3523         (if_then_else (ge (cc0)
3524                           (const_int 0))
3525                       (label_ref (match_operand 0 "" ""))
3526                       (pc)))]
3527   ""
3528   "*
3529 {
3530   return
3531     (cc_prev_status.flags & CC_NO_OVERFLOW)
3532     ? \"bpl %l0%#\" : \"bge %l0%#\";
3533 }"
3534   [(set_attr "slottable" "has_slot")])
3535
3536 (define_insn "bgeu"
3537   [(set (pc)
3538         (if_then_else (geu (cc0)
3539                            (const_int 0))
3540                       (label_ref (match_operand 0 "" ""))
3541                       (pc)))]
3542   ""
3543   "bhs %l0%#"
3544   [(set_attr "slottable" "has_slot")])
3545
3546 (define_insn "ble"
3547   [(set (pc)
3548         (if_then_else (le (cc0)
3549                           (const_int 0))
3550                       (label_ref (match_operand 0 "" ""))
3551                       (pc)))]
3552   ""
3553   "*
3554 {
3555   return
3556     (cc_prev_status.flags & CC_NO_OVERFLOW)
3557     ? 0 : \"ble %l0%#\";
3558 }"
3559   [(set_attr "slottable" "has_slot")])
3560
3561 (define_insn "bleu"
3562   [(set (pc)
3563         (if_then_else (leu (cc0)
3564                            (const_int 0))
3565                       (label_ref (match_operand 0 "" ""))
3566                       (pc)))]
3567   ""
3568   "bls %l0%#"
3569   [(set_attr "slottable" "has_slot")])
3570 \f
3571 ;; Reversed anonymous patterns to the ones above, as mandated.
3572
3573 (define_insn "*beq_reversed"
3574   [(set (pc)
3575         (if_then_else (eq (cc0)
3576                           (const_int 0))
3577                       (pc)
3578                       (label_ref (match_operand 0 "" ""))))]
3579   ""
3580   "bne %l0%#"
3581   [(set_attr "slottable" "has_slot")])
3582
3583 (define_insn "*bne_reversed"
3584   [(set (pc)
3585         (if_then_else (ne (cc0)
3586                           (const_int 0))
3587                       (pc)
3588                       (label_ref (match_operand 0 "" ""))))]
3589   ""
3590   "beq %l0%#"
3591   [(set_attr "slottable" "has_slot")])
3592
3593 (define_insn "*bgt_reversed"
3594   [(set (pc)
3595         (if_then_else (gt (cc0)
3596                           (const_int 0))
3597                       (pc)
3598                       (label_ref (match_operand 0 "" ""))))]
3599   ""
3600   "*
3601 {
3602   return
3603     (cc_prev_status.flags & CC_NO_OVERFLOW)
3604     ? 0 : \"ble %l0%#\";
3605 }"
3606   [(set_attr "slottable" "has_slot")])
3607
3608 (define_insn "*bgtu_reversed"
3609   [(set (pc)
3610         (if_then_else (gtu (cc0)
3611                            (const_int 0))
3612                       (pc)
3613                       (label_ref (match_operand 0 "" ""))))]
3614   ""
3615   "bls %l0%#"
3616   [(set_attr "slottable" "has_slot")])
3617
3618 (define_insn "*blt_reversed"
3619   [(set (pc)
3620         (if_then_else (lt (cc0)
3621                           (const_int 0))
3622                       (pc)
3623                       (label_ref (match_operand 0 "" ""))))]
3624   ""
3625   "*
3626 {
3627   return
3628     (cc_prev_status.flags & CC_NO_OVERFLOW)
3629     ? \"bpl %l0%#\" : \"bge %l0%#\";
3630 }"
3631   [(set_attr "slottable" "has_slot")])
3632
3633 (define_insn "*bltu_reversed"
3634   [(set (pc)
3635         (if_then_else (ltu (cc0)
3636                            (const_int 0))
3637                       (pc)
3638                       (label_ref (match_operand 0 "" ""))))]
3639   ""
3640   "bhs %l0%#"
3641   [(set_attr "slottable" "has_slot")])
3642
3643 (define_insn "*bge_reversed"
3644   [(set (pc)
3645         (if_then_else (ge (cc0)
3646                           (const_int 0))
3647                       (pc)
3648                       (label_ref (match_operand 0 "" ""))))]
3649   ""
3650   "*
3651 {
3652   return
3653     (cc_prev_status.flags & CC_NO_OVERFLOW)
3654     ? \"bmi %l0%#\" : \"blt %l0%#\";
3655 }"
3656   [(set_attr "slottable" "has_slot")])
3657
3658 (define_insn "*bgeu_reversed"
3659   [(set (pc)
3660         (if_then_else (geu (cc0)
3661                            (const_int 0))
3662                       (pc)
3663                       (label_ref (match_operand 0 "" ""))))]
3664   ""
3665   "blo %l0%#"
3666   [(set_attr "slottable" "has_slot")])
3667
3668 (define_insn "*ble_reversed"
3669   [(set (pc)
3670         (if_then_else (le (cc0)
3671                           (const_int 0))
3672                       (pc)
3673                       (label_ref (match_operand 0 "" ""))))]
3674   ""
3675   "*
3676 {
3677   return
3678     (cc_prev_status.flags & CC_NO_OVERFLOW)
3679     ? 0 : \"bgt %l0%#\";
3680 }"
3681   [(set_attr "slottable" "has_slot")])
3682
3683 (define_insn "*bleu_reversed"
3684   [(set (pc)
3685         (if_then_else (leu (cc0)
3686                            (const_int 0))
3687                       (pc)
3688                       (label_ref (match_operand 0 "" ""))))]
3689   ""
3690   "bhi %l0%#"
3691   [(set_attr "slottable" "has_slot")])
3692 \f
3693 ;; Set on condition: sCC.
3694
3695 ;; Like bCC, we have to check the overflow bit for
3696 ;; signed conditions.
3697
3698 (define_insn "sgeu"
3699   [(set (match_operand:SI 0 "register_operand" "=r")
3700         (geu:SI (cc0) (const_int 0)))]
3701   ""
3702   "shs %0"
3703   [(set_attr "slottable" "yes")
3704    (set_attr "cc" "none")])
3705
3706 (define_insn "sltu"
3707   [(set (match_operand:SI 0 "register_operand" "=r")
3708         (ltu:SI (cc0) (const_int 0)))]
3709   ""
3710   "slo %0"
3711   [(set_attr "slottable" "yes")
3712    (set_attr "cc" "none")])
3713
3714 (define_insn "seq"
3715   [(set (match_operand:SI 0 "register_operand" "=r")
3716         (eq:SI (cc0) (const_int 0)))]
3717   ""
3718   "seq %0"
3719   [(set_attr "slottable" "yes")
3720    (set_attr "cc" "none")])
3721
3722 (define_insn "sge"
3723   [(set (match_operand:SI 0 "register_operand" "=r")
3724         (ge:SI (cc0) (const_int 0)))]
3725   ""
3726   "*
3727 {
3728   return
3729     (cc_prev_status.flags & CC_NO_OVERFLOW)
3730     ? \"spl %0\" : \"sge %0\";
3731 }"
3732   [(set_attr "slottable" "yes")
3733    (set_attr "cc" "none")])
3734
3735 (define_insn "sgt"
3736   [(set (match_operand:SI 0 "register_operand" "=r")
3737         (gt:SI (cc0) (const_int 0)))]
3738   ""
3739   "*
3740 {
3741   return
3742     (cc_prev_status.flags & CC_NO_OVERFLOW)
3743     ? 0 : \"sgt %0\";
3744 }"
3745   [(set_attr "slottable" "yes")
3746    (set_attr "cc" "none")])
3747
3748 (define_insn "sgtu"
3749   [(set (match_operand:SI 0 "register_operand" "=r")
3750         (gtu:SI (cc0) (const_int 0)))]
3751   ""
3752   "shi %0"
3753   [(set_attr "slottable" "yes")
3754    (set_attr "cc" "none")])
3755
3756 (define_insn "sle"
3757   [(set (match_operand:SI 0 "register_operand" "=r")
3758         (le:SI (cc0) (const_int 0)))]
3759   ""
3760   "*
3761 {
3762   return
3763     (cc_prev_status.flags & CC_NO_OVERFLOW)
3764     ? 0 : \"sle %0\";
3765 }"
3766   [(set_attr "slottable" "yes")
3767    (set_attr "cc" "none")])
3768
3769 (define_insn "sleu"
3770   [(set (match_operand:SI 0 "register_operand" "=r")
3771         (leu:SI (cc0) (const_int 0)))]
3772   ""
3773   "sls %0"
3774   [(set_attr "slottable" "yes")
3775    (set_attr "cc" "none")])
3776
3777 (define_insn "slt"
3778   [(set (match_operand:SI 0 "register_operand" "=r")
3779         (lt:SI (cc0) (const_int 0)))]
3780   ""
3781   "*
3782 {
3783   return
3784     (cc_prev_status.flags & CC_NO_OVERFLOW)
3785     ? \"smi %0\" : \"slt %0\";
3786 }"
3787   [(set_attr "slottable" "yes")
3788    (set_attr "cc" "none")])
3789
3790 (define_insn "sne"
3791   [(set (match_operand:SI 0 "register_operand" "=r")
3792         (ne:SI (cc0) (const_int 0)))]
3793   ""
3794   "sne %0"
3795   [(set_attr "slottable" "yes")
3796    (set_attr "cc" "none")])
3797 \f
3798 ;; Call insns.
3799
3800 ;; We need to make these patterns "expand", since the real operand is
3801 ;; hidden in a (mem:QI ) inside operand[0] (call_value: operand[1]),
3802 ;; and cannot be checked if it were a "normal" pattern.
3803 ;;  Note that "call" and "call_value" are *always* called with a
3804 ;; mem-operand for operand 0 and 1 respective.  What happens for combined
3805 ;; instructions is a different issue.
3806
3807 (define_expand "call"
3808   [(parallel [(call (match_operand:QI 0 "cris_mem_call_operand" "")
3809                     (match_operand 1 "general_operand" ""))
3810               ;; 16 is the srp (can't use the symbolic name here)
3811               (clobber (reg:SI 16))])]
3812   ""
3813   "
3814 {
3815   rtx op0;
3816
3817   if (GET_CODE (operands[0]) != MEM)
3818     abort ();
3819
3820   if (flag_pic)
3821     {
3822       op0 = XEXP (operands[0], 0);
3823
3824       /* It might be that code can be generated that jumps to 0 (or to a
3825          specific address).  Don't abort on that.  At least there's a
3826          testcase.  */
3827       if (CONSTANT_ADDRESS_P (op0) && GET_CODE (op0) != CONST_INT)
3828         {
3829           if (no_new_pseudos)
3830             abort ();
3831
3832           /* For local symbols (non-PLT), get the plain symbol reference
3833              into a register.  For symbols that can be PLT, make them PLT.  */
3834           if (cris_gotless_symbol (op0) || GET_CODE (op0) != SYMBOL_REF)
3835             op0 = force_reg (Pmode, op0);
3836           else if (cris_symbol (op0))
3837             /* FIXME: Would hanging a REG_EQUIV/EQUAL on that register
3838                for the symbol cause bad recombinatorial effects?  */
3839             op0 = force_reg (Pmode,
3840                              gen_rtx_CONST
3841                              (VOIDmode,
3842                               gen_rtx_UNSPEC (VOIDmode,
3843                                               gen_rtvec (1, op0), 0)));
3844           else
3845             abort ();
3846
3847           operands[0] = replace_equiv_address (operands[0], op0);
3848         }
3849     }
3850 }")
3851
3852 ;; Accept *anything* as operand 1.  Accept operands for operand 0 in
3853 ;; order of preference (Q includes r, but r is shorter, faster)
3854
3855 (define_insn "*expanded_call"
3856   [(call (mem:QI (match_operand:SI
3857                   0 "cris_general_operand_or_plt_symbol" "r,Q>,g,S"))
3858          (match_operand 1 "" ""))
3859    (clobber (reg:SI 16))] ;; 16 is the srp (can't use symbolic name)
3860   "! TARGET_AVOID_GOTPLT"
3861   "jsr %0")
3862
3863 ;; Same as above, since can't afford wasting a constraint letter to mean
3864 ;; "S unless TARGET_AVOID_GOTPLT".
3865 (define_insn "*expanded_call_no_gotplt"
3866   [(call (mem:QI (match_operand:SI
3867                   0 "cris_general_operand_or_plt_symbol" "r,Q>,g"))
3868          (match_operand 1 "" ""))
3869    (clobber (reg:SI 16))] ;; 16 is the srp (can't use symbolic name)
3870   "TARGET_AVOID_GOTPLT"
3871   "jsr %0")
3872
3873 (define_expand "call_value"
3874   [(parallel [(set (match_operand 0 "" "")
3875                    (call (match_operand:QI 1 "cris_mem_call_operand" "")
3876                          (match_operand 2 "" "")))
3877               ;; 16 is the srp (can't use symbolic name)
3878               (clobber (reg:SI 16))])]
3879   ""
3880   "
3881 {
3882   rtx op1;
3883
3884   if (GET_CODE (operands[1]) != MEM)
3885     abort ();
3886
3887   if (flag_pic)
3888     {
3889       op1 = XEXP (operands[1], 0);
3890
3891       /* It might be that code can be generated that jumps to 0 (or to a
3892          specific address).  Don't abort on that.  At least there's a
3893          testcase.  */
3894       if (CONSTANT_ADDRESS_P (op1) && GET_CODE (op1) != CONST_INT)
3895         {
3896           if (no_new_pseudos)
3897             abort ();
3898
3899           if (cris_gotless_symbol (op1))
3900             op1 = force_reg (Pmode, op1);
3901           else if (cris_symbol (op1))
3902             /* FIXME: Would hanging a REG_EQUIV/EQUAL on that register
3903                for the symbol cause bad recombinatorial effects?  */
3904             op1 = force_reg (Pmode,
3905                              gen_rtx_CONST
3906                              (VOIDmode,
3907                               gen_rtx_UNSPEC (VOIDmode,
3908                                               gen_rtvec (1, op1), 0)));
3909           else
3910             abort ();
3911
3912           operands[1] = replace_equiv_address (operands[1], op1);
3913         }
3914     }
3915 }")
3916
3917 ;; Accept *anything* as operand 2.  The validity other than "general" of
3918 ;; operand 0 will be checked elsewhere.  Accept operands for operand 1 in
3919 ;; order of preference (Q includes r, but r is shorter, faster).
3920 ;;  We also accept a PLT symbol.  We output it as [rPIC+sym:GOTPLT] rather
3921 ;; than requiring getting rPIC + sym:PLT into a register.
3922
3923 (define_insn "*expanded_call_value"
3924   [(set (match_operand 0 "nonimmediate_operand" "=g,g,g,g")
3925         (call (mem:QI (match_operand:SI
3926                        1 "cris_general_operand_or_plt_symbol" "r,Q>,g,S"))
3927               (match_operand 2 "" "")))
3928    (clobber (reg:SI 16))]
3929   "! TARGET_AVOID_GOTPLT"
3930   "Jsr %1"
3931   [(set_attr "cc" "clobber")])
3932
3933 ;; Same as above, since can't afford wasting a constraint letter to mean
3934 ;; "S unless TARGET_AVOID_GOTPLT".
3935 (define_insn "*expanded_call_value_no_gotplt"
3936   [(set (match_operand 0 "nonimmediate_operand" "=g,g,g")
3937         (call (mem:QI (match_operand:SI
3938                        1 "cris_general_operand_or_plt_symbol" "r,Q>,g"))
3939               (match_operand 2 "" "")))
3940    (clobber (reg:SI 16))]
3941   "TARGET_AVOID_GOTPLT"
3942   "Jsr %1"
3943   [(set_attr "cc" "clobber")])
3944
3945 ;; Used in debugging.  No use for the direct pattern; unfilled
3946 ;; delayed-branches are taken care of by other means.
3947
3948 (define_insn "nop"
3949   [(const_int 0)]
3950   ""
3951   "nop"
3952   [(set_attr "cc" "none")])
3953 \f
3954 ;; We expand on casesi so we can use "bound" and "add offset fetched from
3955 ;; a table to pc" (adds.w [pc+%0.w],pc).
3956
3957 ;; Note: if you change the "parallel" (or add anything after it) in
3958 ;; this expansion, you must change the macro ASM_OUTPUT_CASE_END
3959 ;; accordingly, to add the default case at the end of the jump-table.
3960
3961 (define_expand "casesi"
3962   [(set (match_dup 5) (match_operand:SI 0 "general_operand" ""))
3963    (set (match_dup 6)
3964         (minus:SI (match_dup 5)
3965                   (match_operand:SI 1 "const_int_operand" "n")))
3966    (set (match_dup 7)
3967         (umin:SI (match_dup 6)
3968                  (match_operand:SI 2 "const_int_operand" "n")))
3969    (parallel
3970     [(set (pc)
3971           (if_then_else
3972            (ltu (match_dup 7) (match_dup 2))
3973            (plus:SI (sign_extend:SI
3974                      (mem:HI
3975                       (plus:SI (mult:SI (match_dup 7) (const_int 2))
3976                                (pc))))
3977                     (pc))
3978            (label_ref (match_operand 4 "" ""))))
3979      (use (label_ref (match_operand 3 "" "")))])]
3980   ""
3981   "
3982 {
3983   operands[2] = plus_constant (operands[2], 1);
3984   operands[5] = gen_reg_rtx (SImode);
3985   operands[6] = gen_reg_rtx (SImode);
3986   operands[7] = gen_reg_rtx (SImode);
3987 }")
3988 \f
3989 ;; Split-patterns.  Some of them have modes unspecified.  This
3990 ;; should always be ok; if for no other reason sparc.md has it as
3991 ;; well.
3992 ;;
3993 ;; When register_operand is specified for an operand, we can get a
3994 ;; subreg as well (Axis-990331), so don't just assume that REG_P is true
3995 ;; for a register_operand and that REGNO can be used as is.  It is best to
3996 ;; guard with REG_P, unless it is worth it to adjust for the subreg case.
3997
3998 ;; op [rx + 0],ry,rz
3999 ;; The index to rx is optimized into zero, and gone.
4000
4001 ;; First, recognize bound [rx],ry,rz; where [rx] is zero-extended,
4002 ;; and add/sub [rx],ry,rz, with zero or sign-extend on [rx].
4003 ;; Split this into:
4004 ;;  move ry,rz
4005 ;;  op [rx],rz
4006 ;; Lose if rz=ry or rx=rz.
4007 ;; Call this op-extend-split
4008
4009 (define_split
4010   [(set (match_operand 0 "register_operand" "")
4011         (match_operator
4012          4 "cris_operand_extend_operator"
4013          [(match_operand 1 "register_operand" "")
4014           (match_operator
4015            3 "cris_extend_operator"
4016            [(match_operand 2 "memory_operand" "")])]))]
4017   "REG_P (operands[0])
4018    && REG_P (operands[1])
4019    && REGNO (operands[1]) != REGNO (operands[0])
4020    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
4021    && REG_P (XEXP (operands[2], 0))
4022    && REGNO (XEXP (operands[2], 0)) != REGNO (operands[0])"
4023   [(set (match_dup 0)
4024         (match_dup 1))
4025    (set (match_dup 0)
4026         (match_op_dup
4027          4 [(match_dup 0)
4028             (match_op_dup 3 [(match_dup 2)])]))]
4029   "")
4030
4031 ;; As op-extend-split, but recognize and split op [rz],ry,rz into
4032 ;;  ext [rz],rz
4033 ;;  op ry,rz
4034 ;; Do this for plus or bound only, being commutative operations, since we
4035 ;; have swapped the operands.
4036 ;; Call this op-extend-split-rx=rz
4037
4038 (define_split
4039   [(set (match_operand 0 "register_operand" "")
4040         (match_operator
4041          4 "cris_plus_or_bound_operator"
4042          [(match_operand 1 "register_operand" "")
4043           (match_operator
4044            3 "cris_extend_operator"
4045            [(match_operand 2 "memory_operand" "")])]))]
4046   "REG_P (operands[0])
4047    && REG_P (operands[1])
4048    && REGNO (operands[1]) != REGNO (operands[0])
4049    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
4050    && REG_P (XEXP (operands[2], 0))
4051    && REGNO (XEXP (operands[2], 0)) == REGNO (operands[0])"
4052   [(set (match_dup 0)
4053         (match_op_dup 3 [(match_dup 2)]))
4054    (set (match_dup 0)
4055         (match_op_dup
4056          4 [(match_dup 0)
4057             (match_dup 1)]))]
4058   "")
4059
4060 ;; As the op-extend-split, but swapped operands, and only for
4061 ;; plus or bound, being the commutative extend-operators.  FIXME: Why is
4062 ;; this needed?  Is it?
4063 ;; Call this op-extend-split-swapped
4064
4065 (define_split
4066   [(set (match_operand 0 "register_operand" "")
4067         (match_operator
4068          4 "cris_plus_or_bound_operator"
4069          [(match_operator
4070            3 "cris_extend_operator"
4071            [(match_operand 2 "memory_operand" "")])
4072           (match_operand 1 "register_operand" "")]))]
4073   "REG_P (operands[0])
4074    && REG_P (operands[1])
4075    && REGNO (operands[1]) != REGNO (operands[0])
4076    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
4077    && REG_P (XEXP (operands[2], 0))
4078    && REGNO (XEXP (operands[2], 0)) != REGNO (operands[0])"
4079   [(set (match_dup 0)
4080         (match_dup 1))
4081    (set (match_dup 0)
4082         (match_op_dup
4083          4 [(match_dup 0)
4084             (match_op_dup 3 [(match_dup 2)])]))]
4085   "")
4086
4087 ;; As op-extend-split-rx=rz, but swapped operands, only for plus or
4088 ;; bound.  Call this op-extend-split-swapped-rx=rz.
4089
4090 (define_split
4091   [(set (match_operand 0 "register_operand" "")
4092         (match_operator
4093          4 "cris_plus_or_bound_operator"
4094          [(match_operator
4095            3 "cris_extend_operator"
4096            [(match_operand 2 "memory_operand" "")])
4097           (match_operand 1 "register_operand" "")]))]
4098   "REG_P (operands[0])
4099    && REG_P (operands[1])
4100    && REGNO (operands[1]) != REGNO (operands[0])
4101    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
4102    && REG_P (XEXP (operands[2], 0))
4103    && REGNO (XEXP (operands[2], 0)) == REGNO (operands[0])"
4104   [(set (match_dup 0)
4105         (match_op_dup 3 [(match_dup 2)]))
4106    (set (match_dup 0)
4107         (match_op_dup
4108          4 [(match_dup 0)
4109             (match_dup 1)]))]
4110   "")
4111
4112 ;; As op-extend-split, but the mem operand is not extended.
4113 ;;
4114 ;; op [rx],ry,rz changed into
4115 ;;  move ry,rz
4116 ;;  op [rx],rz
4117 ;; lose if ry=rz or rx=rz
4118 ;; Call this op-extend.
4119
4120 (define_split
4121   [(set (match_operand 0 "register_operand" "")
4122         (match_operator
4123          3 "cris_orthogonal_operator"
4124          [(match_operand 1 "register_operand" "")
4125           (match_operand 2 "memory_operand" "")]))]
4126   "REG_P (operands[0])
4127    && REG_P (operands[1])
4128    && REGNO (operands[1]) != REGNO (operands[0])
4129    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
4130    && REG_P (XEXP (operands[2], 0))
4131    && REGNO (XEXP (operands[2], 0)) != REGNO (operands[0])"
4132   [(set (match_dup 0)
4133         (match_dup 1))
4134    (set (match_dup 0)
4135         (match_op_dup
4136          3 [(match_dup 0)
4137             (match_dup 2)]))]
4138   "")
4139
4140 ;; As op-extend-split-rx=rz, non-extended.
4141 ;; Call this op-split-rx=rz
4142
4143 (define_split
4144   [(set (match_operand 0 "register_operand" "")
4145         (match_operator
4146          3 "cris_commutative_orth_op"
4147          [(match_operand 2 "memory_operand" "")
4148           (match_operand 1 "register_operand" "")]))]
4149   "REG_P (operands[0])
4150    && REG_P (operands[1])
4151    && REGNO (operands[1]) != REGNO (operands[0])
4152    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
4153    && REG_P (XEXP (operands[2], 0))
4154    && REGNO (XEXP (operands[2], 0)) != REGNO (operands[0])"
4155   [(set (match_dup 0)
4156         (match_dup 1))
4157    (set (match_dup 0)
4158         (match_op_dup
4159          3 [(match_dup 0)
4160             (match_dup 2)]))]
4161   "")
4162
4163 ;; As op-extend-split-swapped, nonextended.
4164 ;; Call this op-split-swapped.
4165
4166 (define_split
4167   [(set (match_operand 0 "register_operand" "")
4168         (match_operator
4169          3 "cris_commutative_orth_op"
4170          [(match_operand 1 "register_operand" "")
4171           (match_operand 2 "memory_operand" "")]))]
4172   "REG_P (operands[0]) && REG_P (operands[1])
4173    && REGNO (operands[1]) != REGNO (operands[0])
4174    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
4175    && REG_P (XEXP (operands[2], 0))
4176    && REGNO (XEXP (operands[2], 0)) == REGNO (operands[0])"
4177   [(set (match_dup 0)
4178         (match_dup 2))
4179    (set (match_dup 0)
4180         (match_op_dup
4181          3 [(match_dup 0)
4182             (match_dup 1)]))]
4183   "")
4184
4185 ;; As op-extend-split-swapped-rx=rz, non-extended.
4186 ;; Call this op-split-swapped-rx=rz.
4187
4188 (define_split
4189   [(set (match_operand 0 "register_operand" "")
4190         (match_operator
4191          3 "cris_orthogonal_operator"
4192          [(match_operand 2 "memory_operand" "")
4193           (match_operand 1 "register_operand" "")]))]
4194   "REG_P (operands[0]) && REG_P (operands[1])
4195    && REGNO (operands[1]) != REGNO (operands[0])
4196    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
4197    && REG_P (XEXP (operands[2], 0))
4198    && REGNO (XEXP (operands[2], 0)) == REGNO (operands[0])"
4199   [(set (match_dup 0)
4200         (match_dup 2))
4201    (set (match_dup 0)
4202         (match_op_dup
4203          3 [(match_dup 0)
4204             (match_dup 1)]))]
4205   "")
4206 \f
4207 ;; Splits for all cases in side-effect insns where (possibly after reload
4208 ;; and register allocation) rx and ry in [rx=ry+i] are equal.
4209
4210 ;; move.S1 [rx=rx+rz.S2],ry
4211
4212 (define_split
4213   [(parallel
4214     [(set (match_operand 0 "register_operand" "")
4215           (match_operator
4216            6 "cris_mem_op"
4217            [(plus:SI
4218              (mult:SI (match_operand:SI 1 "register_operand" "")
4219                       (match_operand:SI 2 "const_int_operand" ""))
4220              (match_operand:SI 3 "register_operand" ""))]))
4221      (set (match_operand:SI 4 "register_operand" "")
4222            (plus:SI (mult:SI (match_dup 1)
4223                              (match_dup 2))
4224                     (match_dup 3)))])]
4225   "REG_P (operands[3]) && REG_P (operands[4])
4226    && REGNO (operands[3]) == REGNO (operands[4])"
4227   [(set (match_dup 4) (plus:SI (mult:SI (match_dup 1) (match_dup 2))
4228                                 (match_dup 3)))
4229    (set (match_dup 0) (match_dup 5))]
4230   "operands[5] = replace_equiv_address (operands[6], operands[3]);")
4231
4232 ;; move.S1 [rx=rx+i],ry
4233
4234 (define_split
4235   [(parallel
4236     [(set (match_operand 0 "register_operand" "")
4237           (match_operator
4238            5 "cris_mem_op"
4239            [(plus:SI (match_operand:SI 1 "cris_bdap_operand" "")
4240                      (match_operand:SI 2 "cris_bdap_operand" ""))]))
4241      (set (match_operand:SI 3 "register_operand" "")
4242            (plus:SI (match_dup 1)
4243                     (match_dup 2)))])]
4244   "(rtx_equal_p (operands[3], operands[1])
4245     || rtx_equal_p (operands[3], operands[2]))"
4246   [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))
4247    (set (match_dup 0) (match_dup 4))]
4248   "operands[4] = replace_equiv_address (operands[5], operands[3]);")
4249
4250 ;; move.S1 ry,[rx=rx+rz.S2]
4251
4252 (define_split
4253   [(parallel
4254     [(set (match_operator
4255            6 "cris_mem_op"
4256            [(plus:SI
4257              (mult:SI (match_operand:SI 0 "register_operand" "")
4258                       (match_operand:SI 1 "const_int_operand" ""))
4259              (match_operand:SI 2 "register_operand" ""))])
4260           (match_operand 3 "register_operand" ""))
4261      (set (match_operand:SI 4 "register_operand" "")
4262            (plus:SI (mult:SI (match_dup 0)
4263                              (match_dup 1))
4264                     (match_dup 2)))])]
4265   "REG_P (operands[2]) && REG_P (operands[4])
4266    && REGNO (operands[4]) == REGNO (operands[2])"
4267   [(set (match_dup 4) (plus:SI (mult:SI (match_dup 0) (match_dup 1))
4268                                 (match_dup 2)))
4269    (set (match_dup 5) (match_dup 3))]
4270   "operands[5] = replace_equiv_address (operands[6], operands[4]);")
4271
4272 ;; move.S1 ry,[rx=rx+i]
4273
4274 (define_split
4275   [(parallel
4276     [(set (match_operator
4277            6 "cris_mem_op"
4278            [(plus:SI (match_operand:SI 0 "cris_bdap_operand" "")
4279                      (match_operand:SI 1 "cris_bdap_operand" ""))])
4280           (match_operand 2 "register_operand" ""))
4281      (set (match_operand:SI 3 "register_operand" "")
4282            (plus:SI (match_dup 0)
4283                    (match_dup 1)))])]
4284   "(rtx_equal_p (operands[3], operands[0])
4285     || rtx_equal_p (operands[3], operands[1]))"
4286   [(set (match_dup 3) (plus:SI (match_dup 0) (match_dup 1)))
4287    (set (match_dup 5) (match_dup 2))]
4288   "operands[5] = replace_equiv_address (operands[6], operands[3]);")
4289
4290 ;; clear.d [rx=rx+rz.S2]
4291
4292 (define_split
4293   [(parallel
4294     [(set (mem:SI (plus:SI
4295                     (mult:SI (match_operand:SI 0 "register_operand" "")
4296                              (match_operand:SI 1 "const_int_operand" ""))
4297                     (match_operand:SI 2 "register_operand" "")))
4298            (const_int 0))
4299      (set (match_operand:SI 3 "register_operand" "")
4300            (plus:SI (mult:SI (match_dup 0)
4301                              (match_dup 1))
4302                     (match_dup 2)))])]
4303   "REG_P (operands[2]) && REG_P (operands[3])
4304    && REGNO (operands[3]) == REGNO (operands[2])"
4305   [(set (match_dup 3) (plus:SI (mult:SI (match_dup 0) (match_dup 1))
4306                                 (match_dup 2)))
4307    (set (mem:SI (match_dup 3)) (const_int 0))]
4308   "")
4309
4310 ;; clear.w [rx=rx+rz.S2]
4311
4312 (define_split
4313   [(parallel
4314     [(set (mem:HI (plus:SI
4315                     (mult:SI (match_operand:SI 0 "register_operand" "")
4316                              (match_operand:SI 1 "const_int_operand" ""))
4317                     (match_operand:SI 2 "register_operand" "")))
4318            (const_int 0))
4319      (set (match_operand:SI 3 "register_operand" "")
4320            (plus:SI (mult:SI (match_dup 0)
4321                              (match_dup 1))
4322                     (match_dup 2)))])]
4323   "REG_P (operands[2]) && REG_P (operands[3])
4324    && REGNO (operands[3]) == REGNO (operands[2])"
4325   [(set (match_dup 3) (plus:SI (mult:SI (match_dup 0) (match_dup 1))
4326                                 (match_dup 2)))
4327    (set (mem:HI (match_dup 3)) (const_int 0))]
4328   "")
4329
4330 ;; clear.b [rx=rx+rz.S2]
4331
4332 (define_split
4333   [(parallel
4334     [(set (mem:QI (plus:SI
4335                     (mult:SI (match_operand:SI 0 "register_operand" "")
4336                              (match_operand:SI 1 "const_int_operand" ""))
4337                     (match_operand:SI 2 "register_operand" "")))
4338            (const_int 0))
4339      (set (match_operand:SI 3 "register_operand" "")
4340            (plus:SI (mult:SI (match_dup 0)
4341                              (match_dup 1))
4342                     (match_dup 2)))])]
4343   "REG_P (operands[2]) && REG_P (operands[3])
4344    && REGNO (operands[3]) == REGNO (operands[2])"
4345   [(set (match_dup 3) (plus:SI (mult:SI (match_dup 0) (match_dup 1))
4346                                 (match_dup 2)))
4347    (set (mem:QI (match_dup 3)) (const_int 0))]
4348   "")
4349
4350 ;; clear.d [rx=rx+i]
4351
4352 (define_split
4353   [(parallel
4354     [(set (mem:SI
4355            (plus:SI (match_operand:SI 0 "cris_bdap_operand" "")
4356                     (match_operand:SI 1 "cris_bdap_operand" "")))
4357            (const_int 0))
4358      (set (match_operand:SI 2 "register_operand" "")
4359            (plus:SI (match_dup 0)
4360                     (match_dup 1)))])]
4361   "(rtx_equal_p (operands[0], operands[2])
4362     || rtx_equal_p (operands[2], operands[1]))"
4363   [(set (match_dup 2) (plus:SI (match_dup 0) (match_dup 1)))
4364    (set (mem:SI (match_dup 2)) (const_int 0))]
4365   "")
4366
4367 ;; clear.w [rx=rx+i]
4368
4369 (define_split
4370   [(parallel
4371     [(set (mem:HI
4372            (plus:SI (match_operand:SI 0 "cris_bdap_operand" "")
4373                     (match_operand:SI 1 "cris_bdap_operand" "")))
4374            (const_int 0))
4375      (set (match_operand:SI 2 "register_operand" "")
4376            (plus:SI (match_dup 0)
4377                     (match_dup 1)))])]
4378   "(rtx_equal_p (operands[0], operands[2])
4379     || rtx_equal_p (operands[2], operands[1]))"
4380   [(set (match_dup 2) (plus:SI (match_dup 0) (match_dup 1)))
4381    (set (mem:HI (match_dup 2)) (const_int 0))]
4382   "")
4383
4384 ;; clear.b [rx=rx+i]
4385
4386 (define_split
4387   [(parallel
4388     [(set (mem:QI
4389            (plus:SI (match_operand:SI 0 "cris_bdap_operand" "")
4390                     (match_operand:SI 1 "cris_bdap_operand" "")))
4391            (const_int 0))
4392      (set (match_operand:SI 2 "register_operand" "")
4393            (plus:SI (match_dup 0)
4394                     (match_dup 1)))])]
4395   "(rtx_equal_p (operands[0], operands[2])
4396     || rtx_equal_p (operands[2], operands[1]))"
4397   [(set (match_dup 2) (plus:SI (match_dup 0) (match_dup 1)))
4398    (set (mem:QI (match_dup 2)) (const_int 0))]
4399   "")
4400
4401 ;; mov(s|u).S1 [rx=rx+rz.S2],ry
4402
4403 (define_split
4404   [(parallel
4405     [(set (match_operand 0 "register_operand" "")
4406           (match_operator
4407             5 "cris_extend_operator"
4408             [(mem (plus:SI
4409                    (mult:SI (match_operand:SI 1 "register_operand" "")
4410                             (match_operand:SI 2 "const_int_operand" ""))
4411                    (match_operand:SI 3 "register_operand" "")))]))
4412      (set (match_operand:SI 4 "register_operand" "")
4413            (plus:SI (mult:SI (match_dup 1)
4414                              (match_dup 2))
4415                     (match_dup 3)))])]
4416   "REG_P (operands[3])
4417    && REG_P (operands[4])
4418    && REGNO (operands[3]) == REGNO (operands[4])"
4419   [(set (match_dup 4) (plus:SI (mult:SI (match_dup 1) (match_dup 2))
4420                                 (match_dup 3)))
4421    (set (match_dup 0) (match_op_dup 5 [(match_dup 6)]))]
4422   "operands[6] = replace_equiv_address (XEXP (operands[5], 0), operands[4]);")
4423
4424 ;; mov(s|u).S1 [rx=rx+i],ry
4425
4426 (define_split
4427   [(parallel
4428     [(set (match_operand 0 "register_operand" "")
4429           (match_operator
4430             4 "cris_extend_operator"
4431             [(mem (plus:SI
4432                    (match_operand:SI 1 "cris_bdap_operand" "")
4433                    (match_operand:SI 2 "cris_bdap_operand" "")))]))
4434      (set (match_operand:SI 3 "register_operand" "")
4435            (plus:SI (match_dup 1)
4436                     (match_dup 2)))])]
4437   "(rtx_equal_p (operands[1], operands[3])
4438     || rtx_equal_p (operands[2], operands[3]))"
4439   [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))
4440    (set (match_dup 0) (match_op_dup 4 [(match_dup 5)]))]
4441   "operands[5] = replace_equiv_address (XEXP (operands[4], 0), operands[3]);")
4442
4443 ;; op.S1 [rx=rx+i],ry
4444
4445 (define_split
4446   [(parallel
4447     [(set (match_operand 0 "register_operand" "")
4448           (match_operator
4449             5 "cris_orthogonal_operator"
4450             [(match_operand 1 "register_operand" "")
4451              (mem (plus:SI
4452                    (match_operand:SI 2 "cris_bdap_operand" "")
4453                    (match_operand:SI 3 "cris_bdap_operand" "")))]))
4454      (set (match_operand:SI 4 "register_operand" "")
4455            (plus:SI (match_dup 2)
4456                     (match_dup 3)))])]
4457   "(rtx_equal_p (operands[4], operands[2])
4458     || rtx_equal_p (operands[4], operands[3]))"
4459   [(set (match_dup 4) (plus:SI (match_dup 2) (match_dup 3)))
4460    (set (match_dup 0) (match_op_dup 5 [(match_dup 1) (match_dup 6)]))]
4461   "operands[6] = replace_equiv_address (XEXP (operands[5], 1), operands[4]);")
4462
4463 ;; op.S1 [rx=rx+rz.S2],ry
4464
4465 (define_split
4466   [(parallel
4467     [(set (match_operand 0 "register_operand" "")
4468           (match_operator
4469             6 "cris_orthogonal_operator"
4470             [(match_operand 1 "register_operand" "")
4471              (mem (plus:SI
4472                    (mult:SI (match_operand:SI 2 "register_operand" "")
4473                             (match_operand:SI 3 "const_int_operand" ""))
4474                    (match_operand:SI 4 "register_operand" "")))]))
4475      (set (match_operand:SI 5 "register_operand" "")
4476            (plus:SI (mult:SI (match_dup 2)
4477                              (match_dup 3))
4478                    (match_dup 4)))])]
4479   "REG_P (operands[4])
4480    && REG_P (operands[5])
4481    && REGNO (operands[5]) == REGNO (operands[4])"
4482   [(set (match_dup 5) (plus:SI (mult:SI (match_dup 2) (match_dup 3))
4483                                 (match_dup 4)))
4484    (set (match_dup 0) (match_op_dup 6 [(match_dup 1) (match_dup 7)]))]
4485   "operands[7] = replace_equiv_address (XEXP (operands[6], 1), operands[5]);")
4486
4487 ;; op.S1 [rx=rx+rz.S2],ry (swapped)
4488
4489 (define_split
4490   [(parallel
4491     [(set (match_operand 0 "register_operand" "")
4492           (match_operator
4493             6 "cris_commutative_orth_op"
4494             [(mem (plus:SI
4495                    (mult:SI (match_operand:SI 2 "register_operand" "")
4496                             (match_operand:SI 3 "const_int_operand" ""))
4497                    (match_operand:SI 4 "register_operand" "")))
4498              (match_operand 1 "register_operand" "")]))
4499      (set (match_operand:SI 5 "register_operand" "")
4500            (plus:SI (mult:SI (match_dup 2)
4501                              (match_dup 3))
4502                     (match_dup 4)))])]
4503   "REG_P (operands[4])
4504    && REG_P (operands[5])
4505    && REGNO (operands[5]) == REGNO (operands[4])"
4506   [(set (match_dup 5) (plus:SI (mult:SI (match_dup 2) (match_dup 3))
4507                                (match_dup 4)))
4508    (set (match_dup 0) (match_op_dup 6 [(match_dup 7) (match_dup 1)]))]
4509   "operands[7] = replace_equiv_address (XEXP (operands[6], 0), operands[5]);")
4510
4511 ;; op.S1 [rx=rx+i],ry (swapped)
4512
4513 (define_split
4514   [(parallel
4515     [(set (match_operand 0 "register_operand" "")
4516           (match_operator
4517             5 "cris_commutative_orth_op"
4518             [(mem
4519               (plus:SI (match_operand:SI 2 "cris_bdap_operand" "")
4520                        (match_operand:SI 3 "cris_bdap_operand" "")))
4521              (match_operand 1 "register_operand" "")]))
4522      (set (match_operand:SI 4 "register_operand" "")
4523           (plus:SI (match_dup 2)
4524                     (match_dup 3)))])]
4525   "(rtx_equal_p (operands[4], operands[2])
4526     || rtx_equal_p (operands[4], operands[3]))"
4527   [(set (match_dup 4) (plus:SI (match_dup 2) (match_dup 3)))
4528    (set (match_dup 0) (match_op_dup 5 [(match_dup 6) (match_dup 1)]))]
4529   "operands[6] = replace_equiv_address (XEXP (operands[5], 0), operands[4]);")
4530
4531 ;; op(s|u).S1 [rx=rx+rz.S2],ry
4532
4533 (define_split
4534   [(parallel
4535     [(set (match_operand 0 "register_operand" "")
4536           (match_operator
4537             6 "cris_operand_extend_operator"
4538             [(match_operand 1 "register_operand" "")
4539              (match_operator
4540               7 "cris_extend_operator"
4541               [(mem (plus:SI
4542                      (mult:SI (match_operand:SI 2 "register_operand" "")
4543                               (match_operand:SI 3 "const_int_operand" ""))
4544                      (match_operand:SI 4 "register_operand" "")))])]))
4545      (set (match_operand:SI 5 "register_operand" "")
4546            (plus:SI (mult:SI (match_dup 2)
4547                              (match_dup 3))
4548                     (match_dup 4)))])]
4549   "REG_P (operands[4])
4550    && REG_P (operands[5])
4551    && REGNO (operands[5]) == REGNO (operands[4])"
4552   [(set (match_dup 5) (plus:SI (mult:SI (match_dup 2) (match_dup 3))
4553                                (match_dup 4)))
4554    (set (match_dup 0) (match_op_dup 6 [(match_dup 1) (match_dup 8)]))]
4555   "operands[8] = gen_rtx_fmt_e (GET_CODE (operands[7]), GET_MODE (operands[7]),
4556                                 replace_equiv_address (XEXP (operands[7], 0),
4557                                                        operands[5]));")
4558
4559 ;; op(s|u).S1 [rx=rx+i],ry
4560
4561 (define_split
4562   [(parallel
4563     [(set (match_operand 0 "register_operand" "")
4564           (match_operator
4565             5 "cris_operand_extend_operator"
4566             [(match_operand 1 "register_operand" "")
4567              (match_operator
4568               6 "cris_extend_operator"
4569               [(mem
4570                 (plus:SI (match_operand:SI 2 "cris_bdap_operand" "")
4571                          (match_operand:SI 3 "cris_bdap_operand" "")
4572                          ))])]))
4573      (set (match_operand:SI 4 "register_operand" "")
4574            (plus:SI (match_dup 2)
4575                     (match_dup 3)))])]
4576   "(rtx_equal_p (operands[4], operands[2])
4577     || rtx_equal_p (operands[4], operands[3]))"
4578   [(set (match_dup 4) (plus:SI (match_dup 2) (match_dup 3)))
4579    (set (match_dup 0) (match_op_dup 5 [(match_dup 1) (match_dup 7)]))]
4580   "operands[7] = gen_rtx_fmt_e (GET_CODE (operands[6]), GET_MODE (operands[6]),
4581                                 replace_equiv_address (XEXP (operands[6], 0),
4582                                                        operands[4]));")
4583
4584 ;; op(s|u).S1 [rx=rx+rz.S2],ry (swapped, plus or bound)
4585
4586 (define_split
4587   [(parallel
4588     [(set (match_operand 0 "register_operand" "")
4589           (match_operator
4590             7 "cris_plus_or_bound_operator"
4591             [(match_operator
4592               6 "cris_extend_operator"
4593               [(mem (plus:SI
4594                      (mult:SI (match_operand:SI 2 "register_operand" "")
4595                               (match_operand:SI 3 "const_int_operand" ""))
4596                      (match_operand:SI 4 "register_operand" "")))])
4597              (match_operand 1 "register_operand" "")]))
4598      (set (match_operand:SI 5 "register_operand" "")
4599            (plus:SI (mult:SI (match_dup 2)
4600                              (match_dup 3))
4601                     (match_dup 4)))])]
4602   "REG_P (operands[4]) && REG_P (operands[5])
4603    && REGNO (operands[5]) == REGNO (operands[4])"
4604   [(set (match_dup 5) (plus:SI (mult:SI (match_dup 2) (match_dup 3))
4605                                (match_dup 4)))
4606    (set (match_dup 0) (match_op_dup 6 [(match_dup 8) (match_dup 1)]))]
4607   "operands[8] = gen_rtx_fmt_e (GET_CODE (operands[6]), GET_MODE (operands[6]),
4608                                 replace_equiv_address (XEXP (operands[6], 0),
4609                                                        operands[5]));")
4610
4611 ;; op(s|u).S1 [rx=rx+i],ry (swapped, plus or bound)
4612
4613 (define_split
4614   [(parallel
4615     [(set (match_operand 0 "register_operand" "")
4616           (match_operator
4617             6 "cris_plus_or_bound_operator"
4618             [(match_operator
4619               5 "cris_extend_operator"
4620              [(mem (plus:SI
4621                     (match_operand:SI 2 "cris_bdap_operand" "")
4622                     (match_operand:SI 3 "cris_bdap_operand" "")))])
4623              (match_operand 1 "register_operand" "")]))
4624      (set (match_operand:SI 4 "register_operand" "")
4625            (plus:SI (match_dup 2)
4626                     (match_dup 3)))])]
4627   "(rtx_equal_p (operands[4], operands[2])
4628     || rtx_equal_p (operands[4], operands[3]))"
4629   [(set (match_dup 4) (plus:SI (match_dup 2) (match_dup 3)))
4630    (set (match_dup 0) (match_op_dup 6 [(match_dup 7) (match_dup 1)]))]
4631   "operands[7] = gen_rtx_fmt_e (GET_CODE (operands[5]), GET_MODE (operands[5]),
4632                                 replace_equiv_address (XEXP (operands[5], 0),
4633                                                        operands[4]));")
4634 \f
4635 ;; Splits for addressing prefixes that have no side-effects, so we can
4636 ;; fill a delay slot.  Never split if we lose something, though.
4637
4638 ;; If we have a
4639 ;;  move [indirect_ref],rx
4640 ;; where indirect ref = {const, [r+], [r]}, it costs as much as
4641 ;;  move indirect_ref,rx
4642 ;;  move [rx],rx
4643 ;; Take care not to allow indirect_ref = register.
4644
4645 ;; We're not allowed to generate copies of registers with different mode
4646 ;; until after reload; copying pseudos upsets reload.  CVS as of
4647 ;; 2001-08-24, unwind-dw2-fde.c, _Unwind_Find_FDE ICE in
4648 ;; cselib_invalidate_regno.
4649
4650 (define_split
4651   [(set (match_operand 0 "register_operand" "")
4652         (match_operand 1 "indirect_operand" ""))]
4653   "reload_completed
4654    && REG_P (operands[0])
4655    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
4656    && (GET_CODE (XEXP (operands[1], 0)) == MEM
4657        || CONSTANT_P (XEXP (operands[1], 0)))"
4658   [(set (match_dup 2) (match_dup 4))
4659    (set (match_dup 0) (match_dup 3))]
4660   "operands[2] = gen_rtx_REG (Pmode, REGNO (operands[0]));
4661    operands[3] = replace_equiv_address (operands[1], operands[2]);
4662    operands[4] = XEXP (operands[1], 0);")
4663
4664 ;; As the above, but MOVS and MOVU.
4665
4666 (define_split
4667   [(set (match_operand 0 "register_operand" "")
4668         (match_operator
4669          4 "cris_extend_operator"
4670          [(match_operand 1 "indirect_operand" "")]))]
4671   "reload_completed
4672    && REG_P (operands[0])
4673    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
4674    && (GET_CODE (XEXP (operands[1], 0)) == MEM
4675        || CONSTANT_P (XEXP (operands[1], 0)))"
4676   [(set (match_dup 2) (match_dup 5))
4677    (set (match_dup 0) (match_op_dup 4 [(match_dup 3)]))]
4678   "operands[2] = gen_rtx_REG (Pmode, REGNO (operands[0]));
4679    operands[3] = replace_equiv_address (XEXP (operands[4], 0), operands[2]);
4680    operands[5] = XEXP (operands[1], 0);")
4681 \f
4682 ;; Various peephole optimizations.
4683 ;;
4684 ;; Watch out: when you exchange one set of instructions for another, the
4685 ;; condition codes setting must be the same, or you have to CC_INIT or
4686 ;; whatever is appropriate, in the pattern before you emit the
4687 ;; assembly text.  This is best done here, not in cris_notice_update_cc,
4688 ;; to keep changes local to their cause.
4689 ;;
4690 ;; Do not add patterns that you do not know will be matched.
4691 ;; Please also add a self-contained testcase.
4692
4693 ;; We have trouble with and:s and shifts.  Maybe something is broken in
4694 ;; gcc?  Or it could just be that bit-field insn expansion is a bit
4695 ;; suboptimal when not having extzv insns.
4696
4697 (define_peephole
4698   [(set (match_operand 0 "register_operand" "=r")
4699         (ashiftrt:SI (match_dup 0)
4700                      (match_operand:SI 1 "const_int_operand" "n")))
4701    (set (match_dup 0)
4702         (and:SI (match_dup 0)
4703                 (match_operand 2 "const_int_operand" "n")))]
4704   "INTVAL (operands[2]) > 31
4705    && INTVAL (operands[2]) < 255
4706    && INTVAL (operands[1]) > 23"
4707
4708 ;; The m flag should be ignored, because this will be a *byte* "and"
4709 ;; operation.
4710
4711   "*
4712 {
4713   cc_status.flags |= CC_NOT_NEGATIVE;
4714
4715   return \"lsrq %1,%0\;and.b %2,%0\";
4716 }")
4717
4718 (define_peephole
4719   [(set (match_operand 0 "register_operand" "=r")
4720         (ashiftrt:SI (match_dup 0)
4721                      (match_operand:SI 1 "const_int_operand" "n")))
4722    (set (match_dup 0)
4723         (and:SI (match_dup 0)
4724                 (match_operand 2 "const_int_operand" "n")))]
4725   "INTVAL (operands[2]) > 31
4726    && INTVAL (operands[2]) < 65535
4727    && INTVAL (operands[2]) != 255
4728    && INTVAL (operands[1]) > 15"
4729
4730 ;; The m flag should be ignored, because this will be a *word* "and"
4731 ;; operation.
4732
4733   "*
4734 {
4735   cc_status.flags |= CC_NOT_NEGATIVE;
4736
4737   return \"lsrq %1,%0\;and.w %2,%0\";
4738 }")
4739
4740 (define_peephole
4741   [(set (match_operand 0 "register_operand" "=r")
4742         (lshiftrt:SI (match_dup 0)
4743                      (match_operand:SI 1 "const_int_operand" "n")))
4744    (set (match_dup 0)
4745         (and:SI (match_dup 0)
4746                 (match_operand 2 "const_int_operand" "n")))]
4747   "INTVAL (operands[2]) > 31
4748    && INTVAL (operands[2]) < 255
4749    && INTVAL (operands[1]) > 23"
4750
4751 ;; The m flag should be ignored, because this will be a *byte* "and"
4752 ;; operation.
4753
4754   "*
4755 {
4756   cc_status.flags |= CC_NOT_NEGATIVE;
4757
4758   return \"lsrq %1,%0\;and.b %2,%0\";
4759 }")
4760
4761 (define_peephole
4762   [(set (match_operand 0 "register_operand" "=r")
4763         (lshiftrt:SI (match_dup 0)
4764                      (match_operand:SI 1 "const_int_operand" "n")))
4765    (set (match_dup 0)
4766         (and:SI (match_dup 0)
4767                 (match_operand 2 "const_int_operand" "n")))]
4768   "INTVAL (operands[2]) > 31 && INTVAL (operands[2]) < 65535
4769    && INTVAL (operands[2]) != 255
4770    && INTVAL (operands[1]) > 15"
4771
4772 ;; The m flag should be ignored, because this will be a *word* "and"
4773 ;; operation.
4774
4775   "*
4776 {
4777   cc_status.flags |= CC_NOT_NEGATIVE;
4778
4779   return \"lsrq %1,%0\;and.w %2,%0\";
4780 }")
4781 \f
4782
4783 ;; Change
4784 ;;  add.d n,rx
4785 ;;  move [rx],ry
4786 ;; into
4787 ;;  move [rx=rx+n],ry
4788 ;; when -128 <= n <= 127.
4789 ;; This will reduce the size of the assembler code for n = [-128..127],
4790 ;; and speed up accordingly.
4791
4792 (define_peephole
4793   [(set (match_operand:SI 0 "register_operand" "=r")
4794         (plus:SI (match_operand:SI 1 "register_operand" "0")
4795                  (match_operand:SI 2 "const_int_operand" "n")))
4796    (set (match_operand 3 "register_operand" "=r")
4797         (mem (match_dup 0)))]
4798   "GET_MODE (operands[3]) != DImode
4799     && REGNO (operands[3]) != REGNO (operands[0])
4800     && (BASE_P (operands[1]) || BASE_P (operands[2]))
4801     && ! CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'J')
4802     && ! CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'N')
4803     && (INTVAL (operands[2]) >= -128 && INTVAL (operands[2]) < 128)"
4804   "move.%s3 [%0=%1%S2],%3")
4805
4806 ;; Vice versa: move ry,[rx=rx+n]
4807
4808 (define_peephole
4809   [(set (match_operand:SI 0 "register_operand" "=r")
4810         (plus:SI (match_operand:SI 1 "register_operand" "0")
4811                  (match_operand:SI 2 "const_int_operand" "n")))
4812    (set (mem (match_dup 0))
4813         (match_operand 3 "register_operand" "=r"))]
4814   "GET_MODE (operands[3]) != DImode
4815     && REGNO (operands[3]) != REGNO (operands[0])
4816     && (BASE_P (operands[1]) || BASE_P (operands[2]))
4817     && ! CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'J')
4818     && ! CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'N')
4819     && (INTVAL (operands[2]) >= -128 && INTVAL (operands[2]) < 128)"
4820   "move.%s3 %3,[%0=%1%S2]"
4821   [(set_attr "cc" "none")])
4822 \f
4823 ;; As above, change:
4824 ;;  add.d n,rx
4825 ;;  op.d [rx],ry
4826 ;; into:
4827 ;;  op.d [rx=rx+n],ry
4828 ;; Saves when n = [-128..127].
4829 ;;
4830 ;; Splitting and joining combinations for side-effect modes are slightly
4831 ;; out of hand.  They probably will not save the time they take typing in,
4832 ;; not to mention the bugs that creep in.  FIXME: Get rid of as many of
4833 ;; the splits and peepholes as possible.
4834
4835 (define_peephole
4836   [(set (match_operand:SI 0 "register_operand" "=r")
4837         (plus:SI (match_operand:SI 1 "register_operand" "0")
4838                  (match_operand:SI 2 "const_int_operand" "n")))
4839    (set (match_operand 3 "register_operand" "=r")
4840         (match_operator 4 "cris_orthogonal_operator"
4841                            [(match_dup 3)
4842                             (mem (match_dup 0))]))]
4843   "GET_MODE (operands[3]) != DImode
4844     && REGNO (operands[0]) != REGNO (operands[3])
4845     && ! CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'J')
4846     && ! CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'N')
4847     && INTVAL (operands[2]) >= -128
4848     && INTVAL (operands[2]) <= 127"
4849   "%x4.%s3 [%0=%1%S2],%3")
4850
4851 ;; Sometimes, for some reason the pattern
4852 ;;  move x,rx
4853 ;;  add y,rx
4854 ;;  move [rx],rz
4855 ;; will occur.  Solve this, and likewise for to-memory.
4856
4857 (define_peephole
4858   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
4859         (match_operand:SI 1 "cris_bdap_biap_operand" "r,>Rn,r,>Rn"))
4860    (set (match_dup 0)
4861         (plus:SI (match_operand:SI 2 "cris_bdap_biap_operand" "0,0,r>Rn,r")
4862                  (match_operand:SI 3 "cris_bdap_biap_operand" "r>Rn,r,0,0")))
4863    (set (match_operand 4 "register_operand" "=r,r,r,r")
4864         (mem (match_dup 0)))]
4865   "(rtx_equal_p (operands[2], operands[0])
4866     || rtx_equal_p (operands[3], operands[0]))
4867    && cris_side_effect_mode_ok (PLUS, operands, 0,
4868                                 (REG_S_P (operands[1])
4869                                  ? 1
4870                                  : (rtx_equal_p (operands[2], operands[0])
4871                                     ? 3 : 2)),
4872                                 (! REG_S_P (operands[1])
4873                                  ? 1
4874                                  : (rtx_equal_p (operands[2], operands[0])
4875                                     ? 3 : 2)),
4876                                 -1, 4)"
4877   "@
4878    move.%s4 [%0=%1%S3],%4
4879    move.%s4 [%0=%3%S1],%4
4880    move.%s4 [%0=%1%S2],%4
4881    move.%s4 [%0=%2%S1],%4")
4882
4883 ;; As above but to memory.
4884
4885 (define_peephole
4886   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
4887         (match_operand:SI 1 "cris_bdap_biap_operand" "r,>Rn,r,>Rn"))
4888    (set (match_dup 0)
4889         (plus:SI (match_operand:SI 2 "cris_bdap_biap_operand" "0,0,r>Rn,r")
4890                  (match_operand:SI 3 "cris_bdap_biap_operand" "r>Rn,r,0,0")))
4891    (set (mem (match_dup 0))
4892         (match_operand 4 "register_operand" "=r,r,r,r"))]
4893   "(rtx_equal_p (operands[2], operands[0])
4894     || rtx_equal_p (operands[3], operands[0]))
4895    && cris_side_effect_mode_ok (PLUS, operands, 0,
4896                                 (REG_S_P (operands[1])
4897                                  ? 1
4898                                  : (rtx_equal_p (operands[2], operands[0])
4899                                     ? 3 : 2)),
4900                                 (! REG_S_P (operands[1])
4901                                    ? 1
4902                                  : (rtx_equal_p (operands[2], operands[0])
4903                                     ? 3 : 2)),
4904                                 -1, 4)"
4905   "@
4906    move.%s4 %4,[%0=%1%S3]
4907    move.%s4 %4,[%0=%3%S1]
4908    move.%s4 %4,[%0=%1%S2]
4909    move.%s4 %4,[%0=%2%S1]"
4910   [(set_attr "cc" "none")])
4911
4912
4913 ;; As the move from-memory above, but with an operation.
4914
4915 (define_peephole
4916   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
4917         (match_operand:SI 1 "cris_bdap_biap_operand" "r,>Rn,r,>Rn"))
4918    (set (match_dup 0)
4919         (plus:SI (match_operand:SI 2 "cris_bdap_biap_operand" "0,0,r>Rn,r")
4920                  (match_operand:SI 3 "cris_bdap_biap_operand" "r>Rn,r,0,0")))
4921    (set (match_operand 4 "register_operand" "=r,r,r,r")
4922         (match_operator 5 "cris_orthogonal_operator"
4923                         [(match_dup 3)
4924                          (mem (match_dup 0))]))]
4925   "(rtx_equal_p (operands[2], operands[0])
4926     || rtx_equal_p (operands[3], operands[0]))
4927    && cris_side_effect_mode_ok (PLUS, operands, 0,
4928                                 (REG_S_P (operands[1])
4929                                  ? 1
4930                                  : (rtx_equal_p (operands[2], operands[0])
4931                                     ? 3 : 2)),
4932                                 (! REG_S_P (operands[1])
4933                                  ? 1
4934                                  : (rtx_equal_p (operands[2], operands[0])
4935                                     ? 3 : 2)),
4936                                 -1, 4)"
4937   "@
4938    %x5.%s4 [%0=%1%S3],%4
4939    %x5.%s4 [%0=%3%S1],%4
4940    %x5.%s4 [%0=%1%S2],%4
4941    %x5.%s4 [%0=%2%S1],%4")
4942
4943 ;; Same, but with swapped operands (and commutative operation).
4944
4945 (define_peephole
4946   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
4947         (match_operand:SI 1 "cris_bdap_biap_operand" "r,>Rn,r,>Rn"))
4948    (set (match_dup 0)
4949         (plus:SI (match_operand:SI 2 "cris_bdap_biap_operand" "0,0,r>Rn,r")
4950                  (match_operand:SI 3 "cris_bdap_biap_operand" "r>Rn,r,0,0")))
4951    (set (match_operand 4 "register_operand" "=r,r,r,r")
4952         (match_operator 5 "cris_commutative_orth_op"
4953                         [(mem (match_dup 0))
4954                          (match_dup 3)]))]
4955   "(rtx_equal_p (operands[2], operands[0])
4956     || rtx_equal_p (operands[3], operands[0]))
4957    && cris_side_effect_mode_ok (PLUS, operands, 0,
4958                            (REG_S_P (operands[1])
4959                             ? 1
4960                             : (rtx_equal_p (operands[2], operands[0])
4961                                ? 3 : 2)),
4962                            (! REG_S_P (operands[1])
4963                             ? 1
4964                             : (rtx_equal_p (operands[2], operands[0])
4965                                ? 3 : 2)),
4966                            -1, 4)"
4967   "@
4968    %x5.%s4 [%0=%1%S3],%4
4969    %x5.%s4 [%0=%3%S1],%4
4970    %x5.%s4 [%0=%1%S2],%4
4971    %x5.%s4 [%0=%2%S1],%4")
4972
4973 ;; Another spotted bad code:
4974 ;;   move rx,ry
4975 ;;   move [ry],ry
4976
4977 (define_peephole
4978   [(set (match_operand:SI 0 "register_operand" "=r")
4979         (match_operand:SI 1 "register_operand" "r"))
4980    (set (match_operand 2 "register_operand" "=r")
4981         (mem (match_dup 0)))]
4982   "REGNO (operands[0]) == REGNO (operands[2])
4983    && GET_MODE_SIZE (GET_MODE (operands[2])) <= UNITS_PER_WORD"
4984   "move.%s2 [%1],%0"
4985   [(set_attr "slottable" "yes")])
4986
4987 ;; And a simple variant with extended operand.
4988
4989 (define_peephole
4990   [(set (match_operand:SI 0 "register_operand" "=r")
4991         (match_operand:SI 1 "register_operand" "r"))
4992    (set (match_operand 2 "register_operand" "=r")
4993         (match_operator 3 "cris_extend_operator" [(mem (match_dup 0))]))]
4994   "REGNO (operands[0]) == REGNO (operands[2])
4995    && GET_MODE_SIZE (GET_MODE (operands[2])) <= UNITS_PER_WORD"
4996   "mov%e3.%m3 [%1],%0"
4997   [(set_attr "slottable" "yes")])
4998 \f
4999 ;; Here are all peepholes that have a saved testcase.
5000 ;; Do not add new peepholes without testcases.
5001
5002 ;; peep-1:
5003 ;;   move.d [r10+16],r9
5004 ;;   and.d r12,r9
5005 ;; change to
5006 ;;   and.d [r10+16],r12,r9
5007 ;; With generalization of the operation, the size and the addressing mode.
5008 ;;  This seems to be the result of a quirk in register allocation
5009 ;; missing the three-operand cases when having different predicates.
5010 ;; Maybe that it matters that it is a commutative operation.
5011 ;;  This pattern helps that situation, but there's still the increased
5012 ;; register pressure.
5013 ;;  Note that adding the noncommutative variant did not show any matches
5014 ;; in ipps and cc1, so it's not here.
5015
5016 (define_peephole
5017   [(set (match_operand 0 "register_operand" "=r,r,r,r")
5018         (mem (plus:SI
5019               (match_operand:SI 1 "cris_bdap_biap_operand" "r,r>Rn,r,r>Rn")
5020               (match_operand:SI 2 "cris_bdap_biap_operand" "r>Rn,r,r>Rn,r"))))
5021    (set (match_dup 0)
5022         (match_operator 5 "cris_commutative_orth_op"
5023                         [(match_operand 3 "register_operand" "0,0,r,r")
5024                          (match_operand 4 "register_operand" "r,r,0,0")]))]
5025   "(rtx_equal_p (operands[3], operands[0])
5026     || rtx_equal_p (operands[4], operands[0]))
5027    && ! rtx_equal_p (operands[3], operands[4])
5028    && (REG_S_P (operands[1]) || REG_S_P (operands[2]))
5029    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD"
5030   "@
5031    %x5.%s0 [%1%S2],%4,%0
5032    %x5.%s0 [%2%S1],%4,%0
5033    %x5.%s0 [%1%S2],%3,%0
5034    %x5.%s0 [%2%S1],%3,%0")
5035
5036 ;; peep-2:
5037 ;;  I cannot tell GCC (2.1, 2.7.2) how to correctly reload an instruction
5038 ;; that looks like
5039 ;;   and.b some_byte,const,reg_32
5040 ;; where reg_32 is the destination of the "three-address" code optimally.
5041 ;; It should be:
5042 ;;   movu.b some_byte,reg_32
5043 ;;   and.b const,reg_32
5044 ;; but is turns into:
5045 ;;   move.b some_byte,reg_32
5046 ;;   and.d const,reg_32
5047 ;; Fix it here.
5048
5049 (define_peephole
5050   [(set (match_operand:SI 0 "register_operand" "=r")
5051         (match_operand:SI 1 "nonimmediate_operand" "rm"))
5052    (set (match_operand:SI 2 "register_operand" "=0")
5053         (and:SI (match_dup 0)
5054                 (match_operand:SI 3 "const_int_operand" "n")))]
5055
5056    ;; Since the size of the memory access could be made different here,
5057    ;; don't do this for a mem-volatile access.
5058
5059   "REGNO (operands[2]) == REGNO (operands[0])
5060    && INTVAL (operands[3]) <= 65535 && INTVAL (operands[3]) >= 0
5061    && ! CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'I')
5062    && (GET_CODE (operands[1]) != MEM || ! MEM_VOLATILE_P (operands[1]))"
5063   "*
5064 {
5065   if (CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'O'))
5066     return \"movu.%z3 %1,%0\;andq %b3,%0\";
5067
5068   cc_status.flags |= CC_NOT_NEGATIVE;
5069
5070   return \"movu.%z3 %1,%0\;and.%z3 %3,%0\";
5071 }")
5072
5073 ;; peep-3
5074
5075 (define_peephole
5076   [(set (match_operand 0 "register_operand" "=r")
5077         (match_operand 1 "nonimmediate_operand" "rm"))
5078    (set (match_operand:SI 2 "register_operand" "=r")
5079         (and:SI (subreg:SI (match_dup 0) 0)
5080                 (match_operand 3 "const_int_operand" "n")))]
5081
5082    ;; Since the size of the memory access could be made different here,
5083    ;; don't do this for a mem-volatile access.
5084
5085   "REGNO (operands[0]) == REGNO (operands[2])
5086    && INTVAL (operands[3]) > 0
5087    && INTVAL (operands[3]) <= 65535
5088    && ! CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'I')
5089    && (GET_CODE (operands[1]) != MEM || ! MEM_VOLATILE_P (operands[1]))"
5090   "*
5091 {
5092   if (CONST_OK_FOR_LETTER_P (INTVAL (operands[3]), 'O'))
5093     return \"movu.%z3 %1,%0\;andq %b3,%0\";
5094
5095   cc_status.flags |= CC_NOT_NEGATIVE;
5096
5097   return \"movu.%z3 %1,%0\;and.%z3 %3,%0\";
5098 }")
5099 \f
5100 ;; Local variables:
5101 ;; mode:emacs-lisp
5102 ;; comment-start: ";; "
5103 ;; eval: (set-syntax-table (copy-sequence (syntax-table)))
5104 ;; eval: (modify-syntax-entry ?[ "(]")
5105 ;; eval: (modify-syntax-entry ?] ")[")
5106 ;; eval: (modify-syntax-entry ?{ "(}")
5107 ;; eval: (modify-syntax-entry ?} "){")
5108 ;; eval: (setq indent-tabs-mode t)
5109 ;; End: