OSDN Git Service

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