gcc/
[official-gcc.git] / gcc / config / cris / cris.md
blob04104d9ea81f1f28dfeac2006b4e84b8f78b5cee
1 ;; GCC machine description for CRIS cpu cores.
2 ;; Copyright (C) 1998-2015 Free Software Foundation, Inc.
3 ;; Contributed by Axis Communications.
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 3, or (at your option)
10 ;; any later version.
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.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3.  If not see
19 ;; <http://www.gnu.org/licenses/>.
21 ;; The original PO technology requires these to be ordered by speed,
22 ;; so that assigner will pick the fastest.
24 ;; See files "md.texi" and "rtl.def" for documentation on define_insn,
25 ;; match_*, et. al.
27 ;; The function cris_notice_update_cc in cris.c handles condition code
28 ;; updates for most instructions, helped by the "cc" attribute.
30 ;; There are several instructions that are orthogonal in size, and seems
31 ;; they could be matched by a single pattern without a specified size
32 ;; for the operand that is orthogonal.  However, this did not work on
33 ;; gcc-2.7.2 (and probably not on gcc-2.8.1), relating to that when a
34 ;; constant is substituted into an operand, the actual mode must be
35 ;; deduced from the pattern.  There is reasonable hope that that has been
36 ;; fixed, so FIXME: try again.
38 ;; You will notice that three-operand alternatives ("=r", "r", "!To")
39 ;; are marked with a "!" constraint modifier to avoid being reloaded
40 ;; into.  This is because gcc would otherwise prefer to use the constant
41 ;; pool and its offsettable address instead of reloading to an
42 ;; ("=r", "0", "i") alternative.  Also, the constant-pool support was not
43 ;; only suboptimal but also buggy in 2.7.2, ??? maybe only in 2.6.3.
45 ;; All insns that look like (set (...) (plus (...) (reg:SI 8)))
46 ;; get problems when reloading r8 (frame pointer) to r14 + offs (stack
47 ;; pointer).  Thus the instructions that get into trouble have specific
48 ;; checks against matching frame_pointer_rtx.
49 ;; ??? But it should be re-checked for gcc > 2.7.2
50 ;; FIXME: This changed some time ago (from 2000-03-16) for gcc-2.9x.
52 ;; FIXME: When PIC, all [rX=rY+S] could be enabled to match
53 ;; [rX=gotless_symbol].
54 ;; The movsi for a gotless symbol could be split (post reload).
57 (define_c_enum ""
58   [
59    ;; PLT reference from call expansion: operand 0 is the address,
60    ;; the mode is VOIDmode.  Always wrapped in CONST.
61    ;; The value is relative to the GOT.
62    CRIS_UNSPEC_PLT_GOTREL
64    ;; PLT reference from call expansion: operand 0 is the address,
65    ;; the mode is VOIDmode.  Always wrapped in CONST.
66    ;; The value is relative to the PC.  It's arch-dependent whether
67    ;; the offset counts from the start or the end of the current item.
68    CRIS_UNSPEC_PLT_PCREL
70    ;; The address of the global offset table as a source operand.
71    CRIS_UNSPEC_GOT
73    ;; The offset from the global offset table to the operand.
74    CRIS_UNSPEC_GOTREL
76    ;; The PC-relative offset to the operand.  It's arch-dependent whether
77    ;; the offset counts from the start or the end of the current item.
78    CRIS_UNSPEC_PCREL
80    ;; The index into the global offset table of a symbol, while
81    ;; also generating a GOT entry for the symbol.
82    CRIS_UNSPEC_GOTREAD
84    ;; Similar to CRIS_UNSPEC_GOTREAD, but also generating a PLT entry.
85    CRIS_UNSPEC_PLTGOTREAD
87    ;; Condition for v32 casesi jump, since it needs to have if_then_else
88    ;; form with register as one branch and default label as other.
89    ;; Operand 0 is const_int 0.
90    CRIS_UNSPEC_CASESI
92    ;; Stack frame deallocation barrier.
93    CRIS_UNSPEC_FRAME_DEALLOC
95    ;; Swap all 32 bits of the operand; 31 <=> 0, 30 <=> 1...
96    CRIS_UNSPEC_SWAP_BITS
97   ])
99 ;; Register numbers.
100 (define_constants
101   [(CRIS_GOT_REGNUM 0)
102    (CRIS_STATIC_CHAIN_REGNUM 7)
103    (CRIS_FP_REGNUM 8)
104    (CRIS_SP_REGNUM 14)
105    (CRIS_ACR_REGNUM 15)
106    (CRIS_SRP_REGNUM 16)
107    (CRIS_MOF_REGNUM 17)
108    (CRIS_AP_REGNUM 18)
109    (CRIS_CC0_REGNUM 19)]
112 ;; We need an attribute to define whether an instruction can be put in
113 ;; a branch-delay slot or not, and whether it has a delay slot.
115 ;; Branches and return instructions have a delay slot, and cannot
116 ;; themselves be put in a delay slot.  This has changed *for short
117 ;; branches only* between architecture variants, but the possible win
118 ;; is presumed negligible compared to the added complexity of the machine
119 ;; description: one would have to add always-correct infrastructure to
120 ;; distinguish short branches.
122 ;; Whether an instruction can be put in a delay slot depends on the
123 ;; instruction (all short instructions except jumps and branches)
124 ;; and the addressing mode (must not be prefixed or referring to pc).
125 ;; In short, any "slottable" instruction must be 16 bit and not refer
126 ;; to pc, or alter it.
128 ;; The possible values are "yes", "no", "has_slot", "has_return_slot"
129 ;; and "has_call_slot".
130 ;; Yes/no tells whether the insn is slottable or not.  Has_call_slot means
131 ;; that the insn is a call insn, which for CRIS v32 has a delay-slot.
132 ;; Of special concern is that no RTX_FRAME_RELATED insn must go in that
133 ;; call delay slot, as it's located in the address *after* the call insn,
134 ;; and the unwind machinery doesn't know about delay slots.
135 ;; Has_slot means that the insn is a branch insn (which are
136 ;; not considered slottable since that is generally true).  Having the
137 ;; seemingly illogical value "has_slot" means we do not have to add
138 ;; another attribute just to say that an insn has a delay-slot, since it
139 ;; also infers that it is not slottable.  Better names for the attribute
140 ;; were found to be longer and not add readability to the machine
141 ;; description.
142 ;; Has_return_slot is similar, for the return insn.
144 ;; The default that is defined here for this attribute is "no", not
145 ;; slottable, not having a delay-slot, so there's no need to worry about
146 ;; it being wrong for non-branch and return instructions.
147 ;;  The default could depend on the kind of insn and the addressing
148 ;; mode, but that would need more attributes and hairier, more error
149 ;; prone code.
151 ;;  There is an extra memory constraint, 'Q', which recognizes an indirect
152 ;; register.  The constraints 'Q' and '>' together match all possible
153 ;; memory operands that are slottable.
154 ;;  For other operands, you need to check if it has a valid "slottable"
155 ;; quick-immediate operand, where the particular signedness-variation
156 ;; may match the constraints 'I' or 'J'.), and include it in the
157 ;; constraint pattern for the slottable pattern.  An alternative using
158 ;; only "r" constraints is most often slottable.
160 (define_attr "slottable" "no,yes,has_slot,has_return_slot,has_call_slot"
161   (const_string "no"))
163 ;; We also need attributes to sanely determine the condition code
164 ;; state.  See cris_notice_update_cc for how this is used.
166 (define_attr "cc" "none,clobber,normal,noov32,rev" (const_string "normal"))
168 ;; At the moment, this attribute is just used to help bb-reorder do its
169 ;; work; the default 0 doesn't help it.  Many insns have other lengths,
170 ;; though none are shorter.
171 (define_attr "length" "" (const_int 2))
173 ;; A branch has one delay-slot.  The instruction in the
174 ;; delay-slot is always executed, independent of whether the branch is
175 ;; taken or not.  Note that besides setting "slottable" to "has_slot",
176 ;; there also has to be a "%#" at the end of a "delayed" instruction
177 ;; output pattern (for "jump" this means "ba %l0%#"), so print_operand can
178 ;; catch it and print a "nop" if necessary.  This method was stolen from
179 ;; sparc.md.
181 (define_delay (eq_attr "slottable" "has_slot")
182   [(eq_attr "slottable" "yes") (nil) (nil)])
184 ;; We can't put prologue insns in call-insn delay-slots when
185 ;; DWARF2 unwind info is emitted, because the unwinder matches the
186 ;; address after the insn.  It must see the return address of a call at
187 ;; a position at least *one byte after* the insn, or it'll think that
188 ;; the insn hasn't been executed.  If the insn is in a delay-slot of a
189 ;; call, it's just *exactly* after the insn.
191 (define_delay (eq_attr "slottable" "has_call_slot")
192   [(and (eq_attr "slottable" "yes")
193         (ior (not (match_test "RTX_FRAME_RELATED_P (insn)"))
194              (not (match_test "flag_exceptions"))))
195    (nil) (nil)])
197 ;; The insn in the return insn slot must not be the
198 ;; return-address-register restore.  FIXME: Use has_slot and express
199 ;; as a parallel with a use of the return-address-register (currently
200 ;; only SRP).  However, this requires an amount of fixing tests for
201 ;; naked RETURN in middle-end.
202 (define_delay (eq_attr "slottable" "has_return_slot")
203   [(and (eq_attr "slottable" "yes")
204         (not (match_test "dead_or_set_regno_p (insn, CRIS_SRP_REGNUM)")))
205    (nil) (nil)])
208 ;; Iterator definitions.
210 ;; For the "usual" pattern size alternatives.
211 (define_mode_iterator BWD [SI HI QI])
212 (define_mode_iterator WD [SI HI])
213 (define_mode_iterator BW [HI QI])
214 (define_mode_attr S [(SI "HI") (HI "QI")])
215 (define_mode_attr s [(SI "hi") (HI "qi")])
216 (define_mode_attr m [(SI ".d") (HI ".w") (QI ".b")])
217 (define_mode_attr mm [(SI ".w") (HI ".b")])
218 (define_mode_attr nbitsm1 [(SI "31") (HI "15") (QI "7")])
220 ;; For the sign_extend+zero_extend variants.
221 (define_code_iterator szext [sign_extend zero_extend])
222 (define_code_attr u [(sign_extend "") (zero_extend "u")])
223 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
225 ;; For the shift variants.
226 (define_code_iterator shift [ashiftrt lshiftrt ashift])
227 (define_code_iterator shiftrt [ashiftrt lshiftrt])
228 (define_code_attr shlr [(ashiftrt "ashr") (lshiftrt "lshr") (ashift "ashl")])
229 (define_code_attr slr [(ashiftrt "asr") (lshiftrt "lsr") (ashift "lsl")])
231 (define_code_iterator ncond [eq ne gtu ltu geu leu])
232 (define_code_iterator ocond [gt le])
233 (define_code_iterator rcond [lt ge])
234 (define_code_attr CC [(eq "eq") (ne "ne") (gt "gt") (gtu "hi") (lt "lt")
235                       (ltu "lo") (ge "ge") (geu "hs") (le "le") (leu "ls")])
236 (define_code_attr rCC [(eq "ne") (ne "eq") (gt "le") (gtu "ls") (lt "ge")
237                        (ltu "hs") (ge "lt") (geu "lo") (le "gt") (leu "hi")])
238 (define_code_attr oCC [(lt "mi") (ge "pl")])
239 (define_code_attr roCC [(lt "pl") (ge "mi")])
241 ;; Operand and operator predicates.
243 (include "predicates.md")
244 (include "constraints.md")
246 ;; Test insns.
248 ;; No test insns with side-effect on the mem addressing.
250 ;; See note on cmp-insns with side-effects (or lack of them)
252 ;; Normal named test patterns from SI on.
254 (define_insn "*tstsi"
255   [(set (cc0)
256         (compare (match_operand:SI 0 "nonimmediate_operand" "r,Q>,m")
257                  (const_int 0)))]
258   ""
260   if (which_alternative == 0 && TARGET_V32)
261     return "cmpq 0,%0";
262   return "test.d %0";
264   [(set_attr "slottable" "yes,yes,no")])
266 (define_insn "*tst<mode>_cmp"
267   [(set (cc0)
268         (compare (match_operand:BW 0 "nonimmediate_operand" "r,Q>,m")
269                  (const_int 0)))]
270   "cris_cc0_user_requires_cmp (insn)"
271   "@
272    cmp<m> 0,%0
273    test<m> %0
274    test<m> %0"
275   [(set_attr "slottable" "no,yes,no")])
277 (define_insn "*tst<mode>_non_cmp"
278   [(set (cc0)
279         (compare (match_operand:BW 0 "nonimmediate_operand" "r,Q>,m")
280                  (const_int 0)))]
281   "!cris_cc0_user_requires_cmp (insn)"
282   "@
283    move<m> %0,%0
284    test<m> %0
285    test<m> %0"
286   [(set_attr "slottable" "yes,yes,no")
287    (set_attr "cc" "noov32,*,*")])
289 ;; It seems that the position of the sign-bit and the fact that 0.0 is
290 ;; all 0-bits would make "tstsf" a straight-forward implementation;
291 ;; either "test.d" it for positive/negative or "btstq 30,r" it for
292 ;; zeroness.
294 ;; FIXME: Do that some time; check next_cc0_user to determine if
295 ;; zero or negative is tested for.
297 ;; Compare insns.
299 ;; We could optimize the sizes of the immediate operands for various
300 ;; cases, but that is not worth it because of the very little usage of
301 ;; DImode for anything else but a structure/block-mode.  Just do the
302 ;; obvious stuff for the straight-forward constraint letters.
304 (define_insn "*cmpdi_non_v32"
305   [(set (cc0)
306         (compare (match_operand:DI 0 "nonimmediate_operand" "rm,r,r,r,r,r,r,o")
307                  (match_operand:DI 1 "general_operand" "M,Kc,I,P,n,r,o,r")))]
308   "!TARGET_V32"
309   "@
310    test.d %M0\;ax\;test.d %H0
311    cmpq %1,%M0\;ax\;cmpq 0,%H0
312    cmpq %1,%M0\;ax\;cmpq -1,%H0
313    cmp%e1.%z1 %1,%M0\;ax\;cmpq %H1,%H0
314    cmp.d %M1,%M0\;ax\;cmp.d %H1,%H0
315    cmp.d %M1,%M0\;ax\;cmp.d %H1,%H0
316    cmp.d %M1,%M0\;ax\;cmp.d %H1,%H0
317    cmp.d %M0,%M1\;ax\;cmp.d %H0,%H1")
319 (define_insn "*cmpdi_v32"
320   [(set (cc0)
321         (compare (match_operand:DI 0 "register_operand"  "r,r,r,r,r")
322                  (match_operand:DI 1 "nonmemory_operand" "Kc,I,P,n,r")))]
323   "TARGET_V32"
324   "@
325    cmpq %1,%M0\;ax\;cmpq 0,%H0
326    cmpq %1,%M0\;ax\;cmpq -1,%H0
327    cmp%e1.%z1 %1,%M0\;ax\;cmpq %H1,%H0
328    cmp.d %M1,%M0\;ax\;cmp.d %H1,%H0
329    cmp.d %M1,%M0\;ax\;cmp.d %H1,%H0")
331 ;; Note that compare insns with side effect addressing mode (e.g.):
333 ;; cmp.S [rx=ry+i],rz;
334 ;; cmp.S [%3=%1+%2],%0
336 ;; are *not* usable for gcc since the reloader *does not accept*
337 ;; cc0-changing insns with side-effects other than setting the condition
338 ;; codes.  The reason is that the reload stage *may* cause another insn to
339 ;; be output after the main instruction, in turn invalidating cc0 for the
340 ;; insn using the test.  (This does not apply to the CRIS case, since a
341 ;; reload for output -- move to memory -- does not change the condition
342 ;; code.  Unfortunately we have no way to describe that at the moment.  I
343 ;; think code would improve being in the order of one percent faster.
345 ;; We have cmps and cmpu (compare reg w. sign/zero extended mem).
346 ;; These are mostly useful for compares in SImode, using 8 or 16-bit
347 ;; constants, but sometimes gcc will find its way to use it for other
348 ;; (memory) operands.  Avoid side-effect patterns, though (see above).
350 (define_insn "*cmp_ext<mode>"
351   [(set (cc0)
352         (compare
353          (match_operand:SI 0 "register_operand" "r,r")
354          (match_operator:SI 2 "cris_extend_operator"
355                          [(match_operand:BW 1 "memory_operand" "Q>,m")])))]
356   ""
357   "cmp%e2<m> %1,%0"
358   [(set_attr "slottable" "yes,no")])
360 ;; Swap operands; it seems the canonical look (if any) is not enforced.
362 ;; FIXME: Investigate that.
364 (define_insn "*cmp_swapext<mode>"
365   [(set (cc0)
366         (compare
367          (match_operator:SI 2 "cris_extend_operator"
368                             [(match_operand:BW 0 "memory_operand" "Q>,m")])
369          (match_operand:SI 1 "register_operand" "r,r")))]
370   ""
371   "cmp%e2<m> %0,%1"
372   [(set_attr "slottable" "yes,no")
373    (set_attr "cc" "rev")])
375 ;; The "normal" compare patterns, from SI on.  Special-cases with zero
376 ;; are covered above.
378 (define_insn "*cmpsi"
379   [(set (cc0)
380         (compare
381          (match_operand:SI 0 "nonimmediate_operand" "r,r,r, Q>,r,r,m")
382          (match_operand:SI 1 "general_operand"      "I,r,Q>,r, P,g,r")))]
383   ""
384   "@
385    cmpq %1,%0
386    cmp.d %1,%0
387    cmp.d %1,%0
388    cmp.d %0,%1
389    cmp%e1.%z1 %1,%0
390    cmp.d %1,%0
391    cmp.d %0,%1"
392   [(set_attr "slottable" "yes,yes,yes,yes,no,no,no")
393    (set_attr "cc" "normal,normal,normal,rev,normal,normal,rev")])
395 (define_insn "*cmp<mode>"
396   [(set (cc0)
397         (compare (match_operand:BW 0 "nonimmediate_operand" "r,r, Q>,r,m")
398                  (match_operand:BW 1 "general_operand"      "r,Q>,r, g,r")))]
399   ""
400   "@
401    cmp<m> %1,%0
402    cmp<m> %1,%0
403    cmp<m> %0,%1
404    cmp<m> %1,%0
405    cmp<m> %0,%1"
406   [(set_attr "slottable" "yes,yes,yes,no,no")
407    (set_attr "cc" "normal,normal,rev,normal,rev")])
409 ;; Pattern matching the BTST insn.
410 ;; It is useful for "if (i & val)" constructs, where val is an exact
411 ;; power of 2, or if val + 1 is a power of two, where we check for a bunch
412 ;; of zeros starting at bit 0).
414 ;; SImode.  This mode is the only one needed, since gcc automatically
415 ;; extends subregs for lower-size modes.  FIXME: Add testcase.
416 (define_insn "*btst"
417   [(set (cc0)
418         (compare
419          (zero_extract:SI
420           (match_operand:SI 0 "nonmemory_operand" "r, r,r, r,r, r,Kp")
421           (match_operand:SI 1 "const_int_operand" "Kc,n,Kc,n,Kc,n,n")
422           (match_operand:SI 2 "nonmemory_operand" "M, M,Kc,n,r, r,r"))
423          (const_int 0)))]
424   ;; Either it is a single bit, or consecutive ones starting at 0.
425   ;; The btst ones depend on stuff in NOTICE_UPDATE_CC.
426   "CONST_INT_P (operands[1])
427    && (operands[1] == const1_rtx || operands[2] == const0_rtx)
428    && (REG_S_P (operands[0])
429        || (operands[1] == const1_rtx
430            && REG_S_P (operands[2])
431            && CONST_INT_P (operands[0])
432            && exact_log2 (INTVAL (operands[0])) >= 0))
433    && !TARGET_CCINIT"
435 ;; The next-to-last "&&" condition above should be caught by some kind of
436 ;; canonicalization in gcc, but we can easily help with it here.
437 ;;  It results from expressions of the type
438 ;; "power_of_2_value & (1 << y)".
440 ;; Since there may be codes with tests in on bits (in constant position)
441 ;; beyond the size of a word, handle that by assuming those bits are 0.
442 ;; GCC should handle that, but it's a matter of easily-added belts while
443 ;; having suspenders.
445   "@
446    btstq (%1-1),%0
447    cmpq 0,%0
448    btstq %2,%0
449    clearf nz
450    btst %2,%0
451    clearf nz
452    cmpq %p0,%2"
453  [(set_attr "slottable" "yes")
454   (set_attr "cc" "noov32")])
456 ;; Move insns.
458 ;; The whole mandatory movdi family is here; expander, "anonymous"
459 ;; recognizer and splitter.  We're forced to have a movdi pattern,
460 ;; although GCC should be able to split it up itself.  Normally it can,
461 ;; but if other insns have DI operands (as is the case here), reload
462 ;; must be able to generate or match a movdi.  many testcases fail at
463 ;; -O3 or -fssa if we don't have this.  FIXME: Fix GCC...  See
464 ;; <URL:http://gcc.gnu.org/ml/gcc-patches/2000-04/msg00104.html>.
465 ;; However, a patch from Richard Kenner (similar to the cause of
466 ;; discussion at the URL above), indicates otherwise.  See
467 ;; <URL:http://gcc.gnu.org/ml/gcc-patches/2000-04/msg00554.html>.
468 ;; The truth has IMO is not been decided yet, so check from time to
469 ;; time by disabling the movdi patterns.
471 ;; To appease testcase gcc.c-torture/execute/920501-2.c (and others) at
472 ;; -O0, we need a movdi as a temporary measure.  Here's how things fail:
473 ;;  A cmpdi RTX needs reloading (global):
474 ;;    (insn 185 326 186 (set (cc0)
475 ;;          (compare (mem/f:DI (reg/v:SI 22) 0)
476 ;;              (const_int 1 [0x1]))) 4 {cmpdi} (nil)
477 ;;      (nil))
478 ;; Now, reg 22 is reloaded for input address, and the mem is also moved
479 ;; out of the instruction (into a register), since one of the operands
480 ;; must be a register.  Reg 22 is reloaded (into reg 10), and the mem is
481 ;; moved out and synthesized in SImode parts (reg 9, reg 10 - should be ok
482 ;; wrt. overlap).  The bad things happen with the synthesis in
483 ;; emit_move_insn_1; the location where to substitute reg 10 is lost into
484 ;; two new RTX:es, both still having reg 22.  Later on, the left-over reg
485 ;; 22 is recognized to have an equivalent in memory which is substituted
486 ;; straight in, and we end up with an unrecognizable insn:
487 ;;    (insn 325 324 326 (set (reg:SI 9 r9)
488 ;;            (mem/f:SI (mem:SI (plus:SI (reg:SI 8 r8)
489 ;;                        (const_int -84 [0xffffffac])) 0) 0)) -1 (nil)
490 ;;        (nil))
491 ;; which is the first part of the reloaded synthesized "movdi".
492 ;;  The right thing would be to add equivalent replacement locations for
493 ;; insn with pseudos that need more reloading.  The question is where.
495 (define_expand "movdi"
496   [(set (match_operand:DI 0 "nonimmediate_operand" "")
497         (match_operand:DI 1 "general_operand" ""))]
498   ""
500   if (MEM_P (operands[0])
501       && operands[1] != const0_rtx
502       && (!TARGET_V32 || (!REG_P (operands[1]) && can_create_pseudo_p ())))
503     operands[1] = copy_to_mode_reg (DImode, operands[1]);
505   /* Some other ports (as of 2001-09-10 for example mcore and romp) also
506      prefer to split up constants early, like this.  The testcase in
507      gcc.c-torture/execute/961213-1.c shows that CSE2 gets confused by the
508      resulting subreg sets when using the construct from mcore (as of FSF
509      CVS, version -r 1.5), and it believes that the high part (the last one
510      emitted) is the final value.  */
511   if ((CONST_INT_P (operands[1]) || GET_CODE (operands[1]) == CONST_DOUBLE)
512       && ! reload_completed
513       && ! reload_in_progress)
514     {
515       rtx insns;
516       rtx op0 = operands[0];
517       rtx op1 = operands[1];
519       start_sequence ();
520       emit_move_insn (operand_subword (op0, 0, 1, DImode),
521                       operand_subword (op1, 0, 1, DImode));
522       emit_move_insn (operand_subword (op0, 1, 1, DImode),
523                       operand_subword (op1, 1, 1, DImode));
524       insns = get_insns ();
525       end_sequence ();
527       emit_insn (insns);
528       DONE;
529     }
532 (define_insn_and_split "*movdi_insn_non_v32"
533   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,rx,m")
534         (match_operand:DI 1 "general_operand"      "rx,g,rxM"))]
535   "(register_operand (operands[0], DImode)
536     || register_operand (operands[1], DImode)
537     || operands[1] == const0_rtx)
538    && !TARGET_V32"
539   "#"
540   "&& reload_completed"
541   [(match_dup 2)]
542   "operands[2] = cris_split_movdx (operands);")
544 ;; Overlapping (but non-identical) source memory address and destination
545 ;; register would be a compiler bug, so we don't have to specify that.
546 (define_insn "*movdi_v32"
547   [(set
548     (match_operand:DI 0 "nonimmediate_operand" "=r,rx,&r,>, m,r,x,m")
549     (match_operand:DI 1 "general_operand"     "rxi,r>,m, rx,r,m,m,x"))]
550   "TARGET_V32"
552   switch (which_alternative)
553     {
554       /* FIXME: 1) Use autoincrement where possible.  2) Have peephole2,
555          particularly for cases where the address register is dead.  */
556     case 5:
557       if (REGNO (operands[0]) == REGNO (XEXP (operands[1], 0)))
558         return "addq 4,%L1\;move.d %1,%H0\;subq 4,%L1\;move.d %1,%M0";
559       gcc_assert (REGNO (operands[0]) + 1 == REGNO (XEXP (operands[1], 0)));
560       return "move.d [%L1+],%M0\;move.d [%L1],%H0";
561     case 2:
562       /* We could do away with the addq if we knew the address-register
563          isn't ACR.  If we knew the address-register is dead, we could do
564          away with the subq too.  */
565       return "move.d [%L1],%M0\;addq 4,%L1\;move.d [%L1],%H0\;subq 4,%L1";
566     case 4:
567       return "move.d %M1,[%L0]\;addq 4,%L0\;move.d %H1,[%L0]\;subq 4,%L0";
568     case 6:
569       return "move [%L1],%M0\;addq 4,%L1\;move [%L1],%H0\;subq 4,%L1";
570     case 7:
571       return "move %M1,[%L0]\;addq 4,%L0\;move %H1,[%L0]\;subq 4,%L0";
573     default:
574       return "#";
575     }
577   ;; The non-split cases clobber cc0 because of their adds and subs.
578   ;; Beware that NOTICE_UPDATE_CC is called before the forced split happens.
579   [(set_attr "cc" "*,*,clobber,*,clobber,clobber,*,*")])
581 ;; Much like "*movdi_insn_non_v32".  Overlapping registers and constants
582 ;; is handled so much better in cris_split_movdx.
583 (define_split
584   [(set (match_operand:DI 0 "nonimmediate_operand" "")
585         (match_operand:DI 1 "general_operand" ""))]
586   "TARGET_V32
587    && reload_completed
588    && (!MEM_P (operands[0]) || !REG_P (XEXP (operands[0], 0)))
589    && (!MEM_P (operands[1]) || !REG_P (XEXP (operands[1], 0)))"
590   [(match_dup 2)]
591   "operands[2] = cris_split_movdx (operands);")
593 ;; Side-effect patterns for move.S1 [rx=ry+rx.S2],rw
594 ;; and move.S1 [rx=ry+i],rz
595 ;;  Then movs.S1 and movu.S1 for both modes.
597 ;; move.S1 [rx=ry+rz.S],rw avoiding when rx is ry, or rw is rx
598 ;; FIXME: These could have anonymous mode for operand 0.
599 ;; FIXME: Special registers' alternatives too.
601 (define_insn "*mov_side<mode>_biap"
602   [(set (match_operand:BW 0 "register_operand" "=r,r")
603         (mem:BW (plus:SI
604                  (mult:SI (match_operand:SI 1 "register_operand" "r,r")
605                           (match_operand:SI 2 "const_int_operand" "n,n"))
606                  (match_operand:SI 3 "register_operand" "r,r"))))
607    (set (match_operand:SI 4 "register_operand" "=*3,r")
608         (plus:SI (mult:SI (match_dup 1)
609                           (match_dup 2))
610                  (match_dup 3)))]
611   "cris_side_effect_mode_ok (MULT, operands, 4, 3, 1, 2, 0)"
612   "@
613    #
614    move<m> [%4=%3+%1%T2],%0")
616 (define_insn "*mov_sidesisf_biap"
617   [(set (match_operand 0 "register_operand" "=r,r,x,x")
618         (mem (plus:SI
619               (mult:SI (match_operand:SI 1 "register_operand" "r,r,r,r")
620                        (match_operand:SI 2 "const_int_operand" "n,n,n,n"))
621               (match_operand:SI 3 "register_operand" "r,r,r,r"))))
622    (set (match_operand:SI 4 "register_operand" "=*3,r,*3,r")
623         (plus:SI (mult:SI (match_dup 1)
624                           (match_dup 2))
625                  (match_dup 3)))]
626   "GET_MODE_SIZE (GET_MODE (operands[0])) == UNITS_PER_WORD
627    && cris_side_effect_mode_ok (MULT, operands, 4, 3, 1, 2, 0)"
628   "@
629    #
630    move.%s0 [%4=%3+%1%T2],%0
631    #
632    move [%4=%3+%1%T2],%0")
634 ;; move.S1 [rx=ry+i],rz
635 ;; avoiding move.S1 [ry=ry+i],rz
636 ;; and      move.S1 [rz=ry+i],rz
637 ;; Note that "i" is allowed to be a register.
639 (define_insn "*mov_side<mode>"
640   [(set (match_operand:BW 0 "register_operand" "=r,r,r,r,r")
641         (mem:BW
642          (plus:SI (match_operand:SI 1 "cris_bdap_operand" "%r,r,r,R,R")
643                   (match_operand:SI 2 "cris_bdap_operand" "r>Rn,r,>Rn,r,r"))))
644    (set (match_operand:SI 3 "register_operand" "=*1,r,r,*2,r")
645         (plus:SI (match_dup 1)
646                  (match_dup 2)))]
647   "cris_side_effect_mode_ok (PLUS, operands, 3, 1, 2, -1, 0)"
649   if ((which_alternative == 0 || which_alternative == 3)
650       && (!CONST_INT_P (operands[2])
651           || INTVAL (operands[2]) > 127
652           || INTVAL (operands[2]) < -128
653           || satisfies_constraint_N (operands[2])
654           || satisfies_constraint_J (operands[2])))
655     return "#";
656   if (which_alternative == 4)
657     return "move<m> [%3=%2%S1],%0";
658   return "move<m> [%3=%1%S2],%0";
661 (define_insn "*mov_sidesisf"
662   [(set (match_operand 0 "register_operand" "=r,r,r,x,x,x,r,r,x,x")
663         (mem
664          (plus:SI
665           (match_operand:SI 1 "cris_bdap_operand" "%r,r,r,r,r,r,R,R,R,R")
666           (match_operand:SI 2 "cris_bdap_operand" "r>Rn,r,>Rn,r>Rn,r,>Rn,r,r,r,r"))))
667    (set (match_operand:SI 3 "register_operand" "=*1,r,r,*1,r,r,*2,r,*2,r")
668         (plus:SI (match_dup 1)
669                  (match_dup 2)))]
670   "GET_MODE_SIZE (GET_MODE (operands[0])) == UNITS_PER_WORD
671    && cris_side_effect_mode_ok (PLUS, operands, 3, 1, 2, -1, 0)"
673   if ((which_alternative == 0
674        || which_alternative == 3
675        || which_alternative == 6
676        || which_alternative == 8)
677       && (!CONST_INT_P (operands[2])
678           || INTVAL (operands[2]) > 127
679           || INTVAL (operands[2]) < -128
680           || satisfies_constraint_N (operands[2])
681           || satisfies_constraint_J (operands[2])))
682     return "#";
683   if (which_alternative < 3)
684     return "move.%s0 [%3=%1%S2],%0";
685   if (which_alternative == 7)
686     return "move.%s0 [%3=%2%S1],%0";
687   if (which_alternative == 9)
688     return "move [%3=%2%S1],%0";
689   return "move [%3=%1%S2],%0";
692 ;; Other way around; move to memory.
694 ;; Note that the condition (which for side-effect patterns is usually a
695 ;; call to cris_side_effect_mode_ok), isn't consulted for register
696 ;; allocation preferences -- constraints is the method for that.  The
697 ;; drawback is that we can't exclude register allocation to cause
698 ;; "move.s rw,[rx=ry+rz.S]" when rw==rx without also excluding rx==ry or
699 ;; rx==rz if we use an earlyclobber modifier for the constraint for rx.
700 ;; Instead of that, we recognize and split the cases where dangerous
701 ;; register combinations are spotted: where a register is set in the
702 ;; side-effect, and used in the main insn.  We don't handle the case where
703 ;; the set in the main insn overlaps the set in the side-effect; that case
704 ;; must be handled in gcc.  We handle just the case where the set in the
705 ;; side-effect overlaps the input operand of the main insn (i.e. just
706 ;; moves to memory).
709 ;; move.s rz,[ry=rx+rw.S]
711 (define_insn "*mov_side<mode>_biap_mem"
712   [(set (mem:BW (plus:SI
713                  (mult:SI (match_operand:SI 0 "register_operand" "r,r,r")
714                           (match_operand:SI 1 "const_int_operand" "n,n,n"))
715                  (match_operand:SI 2 "register_operand" "r,r,r")))
716         (match_operand:BW 3 "register_operand" "r,r,r"))
717    (set (match_operand:SI 4 "register_operand" "=*2,!3,r")
718         (plus:SI (mult:SI (match_dup 0)
719                           (match_dup 1))
720                  (match_dup 2)))]
721   "cris_side_effect_mode_ok (MULT, operands, 4, 2, 0, 1, 3)"
722   "@
723    #
724    #
725    move<m> %3,[%4=%2+%0%T1]")
727 (define_insn "*mov_sidesisf_biap_mem"
728   [(set (mem (plus:SI
729               (mult:SI (match_operand:SI 0 "register_operand" "r,r,r,r,r,r")
730                        (match_operand:SI 1 "const_int_operand" "n,n,n,n,n,n"))
731               (match_operand:SI 2 "register_operand" "r,r,r,r,r,r")))
732         (match_operand 3 "register_operand" "r,r,r,x,x,x"))
733    (set (match_operand:SI 4 "register_operand" "=*2,!3,r,*2,!3,r")
734         (plus:SI (mult:SI (match_dup 0)
735                           (match_dup 1))
736                  (match_dup 2)))]
737   "GET_MODE_SIZE (GET_MODE (operands[3])) == UNITS_PER_WORD
738    && cris_side_effect_mode_ok (MULT, operands, 4, 2, 0, 1, 3)"
739   "@
740    #
741    #
742    move.%s3 %3,[%4=%2+%0%T1]
743    #
744    #
745    move %3,[%4=%2+%0%T1]")
747 ;; Split for the case above where we're out of luck with register
748 ;; allocation (again, the condition isn't checked for that), and we end up
749 ;; with the set in the side-effect getting the same register as the input
750 ;; register.
752 (define_split
753   [(parallel
754     [(set (match_operator
755            6 "cris_mem_op"
756            [(plus:SI
757              (mult:SI (match_operand:SI 0 "register_operand" "")
758                       (match_operand:SI 1 "const_int_operand" ""))
759              (match_operand:SI 2 "register_operand" ""))])
760           (match_operand 3 "register_operand" ""))
761      (set (match_operand:SI 4 "cris_nonsp_register_operand" "")
762           (plus:SI (mult:SI (match_dup 0)
763                             (match_dup 1))
764                    (match_dup 2)))])]
765   "reload_completed && reg_overlap_mentioned_p (operands[4], operands[3])"
766   [(set (match_dup 5) (match_dup 3))
767    (set (match_dup 4) (match_dup 2))
768    (set (match_dup 4)
769         (plus:SI (mult:SI (match_dup 0)
770                           (match_dup 1))
771                  (match_dup 4)))]
772   "operands[5]
773      = replace_equiv_address (operands[6],
774                               gen_rtx_PLUS (SImode,
775                                             gen_rtx_MULT (SImode,
776                                                           operands[0],
777                                                           operands[1]),
778                                             operands[2]));")
780 ;; move.s rx,[ry=rz+i]
781 ;; FIXME: These could have anonymous mode for operand 2.
783 ;; QImode
785 (define_insn "*mov_side<mode>_mem"
786   [(set (mem:BW
787          (plus:SI (match_operand:SI 0 "cris_bdap_operand" "%r,r,r,r,R,R,R")
788                   (match_operand:SI 1 "cris_bdap_operand" "r>Rn,r>Rn,r,>Rn,r,r,r")))
789         (match_operand:BW 2 "register_operand" "r,r,r,r,r,r,r"))
790    (set (match_operand:SI 3 "register_operand" "=*0,!*2,r,r,*1,!*2,r")
791         (plus:SI (match_dup 0)
792                  (match_dup 1)))]
793   "cris_side_effect_mode_ok (PLUS, operands, 3, 0, 1, -1, 2)"
795   if ((which_alternative == 0 || which_alternative == 4)
796       && (!CONST_INT_P (operands[1])
797           || INTVAL (operands[1]) > 127
798           || INTVAL (operands[1]) < -128
799           || satisfies_constraint_N (operands[1])
800           || satisfies_constraint_J (operands[1])))
801     return "#";
802   if (which_alternative == 1 || which_alternative == 5)
803     return "#";
804   if (which_alternative == 6)
805     return "move.%s2 %2,[%3=%1%S0]";
806   return "move<m> %2,[%3=%0%S1]";
809 ;; SImode
811 (define_insn "*mov_sidesisf_mem"
812   [(set (mem
813          (plus:SI
814           (match_operand:SI
815            0 "cris_bdap_operand"
816                                 "%r,  r,   r,r,  r,   r,r,  R,R,  R,R, R")
817           (match_operand:SI
818            1 "cris_bdap_operand"
819                                 "r>Rn,r>Rn,r,>Rn,r>Rn,r,>Rn,r,r,  r,r, r")))
820         (match_operand 2 "register_operand"
821                                 "r,   r,   r,r,  x,   x,x,  r,r,  r,x, x"))
822    (set (match_operand:SI 3 "register_operand"
823                                 "=*0,!2,   r,r,  *0,  r,r, *1,!*2,r,*1,r")
824         (plus:SI (match_dup 0)
825                  (match_dup 1)))]
826   "GET_MODE_SIZE (GET_MODE (operands[2])) == UNITS_PER_WORD
827    && cris_side_effect_mode_ok (PLUS, operands, 3, 0, 1, -1, 2)"
829   if ((which_alternative == 0 || which_alternative == 4)
830       && (!CONST_INT_P (operands[1])
831           || INTVAL (operands[1]) > 127
832           || INTVAL (operands[1]) < -128
833           || satisfies_constraint_N (operands[1])
834           || satisfies_constraint_J (operands[1])))
835     return "#";
836   if (which_alternative == 1
837       || which_alternative == 7
838       || which_alternative == 8
839       || which_alternative == 10)
840     return "#";
841   if (which_alternative < 4)
842     return "move.%s2 %2,[%3=%0%S1]";
843   if (which_alternative == 9)
844     return "move.%s2 %2,[%3=%1%S0]";
845   if (which_alternative == 11)
846     return "move %2,[%3=%1%S0]";
847   return "move %2,[%3=%0%S1]";
850 ;; Like the biap case, a split where the set in the side-effect gets the
851 ;; same register as the input register to the main insn, since the
852 ;; condition isn't checked at register allocation.
854 (define_split
855   [(parallel
856     [(set (match_operator
857            4 "cris_mem_op"
858            [(plus:SI
859              (match_operand:SI 0 "cris_bdap_operand" "")
860              (match_operand:SI 1 "cris_bdap_operand" ""))])
861           (match_operand 2 "register_operand" ""))
862      (set (match_operand:SI 3 "cris_nonsp_register_operand" "")
863           (plus:SI (match_dup 0) (match_dup 1)))])]
864   "reload_completed && reg_overlap_mentioned_p (operands[3], operands[2])"
865   [(set (match_dup 4) (match_dup 2))
866    (set (match_dup 3) (match_dup 0))
867    (set (match_dup 3) (plus:SI (match_dup 3) (match_dup 1)))]
868   "")
870 ;; Clear memory side-effect patterns.  It is hard to get to the mode if
871 ;; the MEM was anonymous, so there will be one for each mode.
873 ;;  clear.[bwd] [ry=rx+rw.s2]
875 (define_insn "*clear_side<mode>_biap"
876   [(set (mem:BWD (plus:SI
877                   (mult:SI (match_operand:SI 0 "register_operand" "r,r")
878                            (match_operand:SI 1 "const_int_operand" "n,n"))
879                   (match_operand:SI 2 "register_operand" "r,r")))
880         (const_int 0))
881    (set (match_operand:SI 3 "register_operand" "=*2,r")
882         (plus:SI (mult:SI (match_dup 0)
883                           (match_dup 1))
884                  (match_dup 2)))]
885   "cris_side_effect_mode_ok (MULT, operands, 3, 2, 0, 1, -1)"
886   "@
887    #
888    clear<m> [%3=%2+%0%T1]")
890 ;; clear.[bwd] [ry=rz+i]
892 (define_insn "*clear_side<mode>"
893   [(set (mem:BWD
894          (plus:SI (match_operand:SI 0 "cris_bdap_operand" "%r,r,r,R,R")
895                   (match_operand:SI 1 "cris_bdap_operand" "r>Rn,r,>Rn,r,r")))
896         (const_int 0))
897    (set (match_operand:SI 2 "register_operand" "=*0,r,r,*1,r")
898         (plus:SI (match_dup 0)
899                  (match_dup 1)))]
900   "cris_side_effect_mode_ok (PLUS, operands, 2, 0, 1, -1, -1)"
902   if ((which_alternative == 0 || which_alternative == 3)
903       && (!CONST_INT_P (operands[1])
904           || INTVAL (operands[1]) > 127
905           || INTVAL (operands[1]) < -128
906           || satisfies_constraint_N (operands[1])
907           || satisfies_constraint_J (operands[1])))
908     return "#";
909   if (which_alternative == 4)
910     return "clear<m> [%2=%1%S0]";
911   return "clear<m> [%2=%0%S1]";
914 ;; Normal move patterns from SI on.
916 (define_expand "movsi"
917   [(set
918     (match_operand:SI 0 "nonimmediate_operand" "")
919     (match_operand:SI 1 "cris_general_operand_or_symbol" ""))]
920   ""
922   enum cris_symbol_type t;
924   /* If the output goes to a MEM, make sure we have zero or a register as
925      input.  */
926   if (MEM_P (operands[0])
927       && ! REG_S_P (operands[1])
928       && operands[1] != const0_rtx
929       && can_create_pseudo_p ())
930     operands[1] = force_reg (SImode, operands[1]);
932   /* If we're generating PIC and have an incoming symbol, validize it to a
933      general operand or something that will match a special pattern.
935      FIXME: Do we *have* to recognize anything that would normally be a
936      valid symbol?  Can we exclude global PIC addresses with an added
937      offset?  */
938     if (flag_pic
939         && CONSTANT_P (operands[1])
940         && !cris_valid_pic_const (operands[1], false))
941       {
942         t = cris_symbol_type_of (operands[1]);
944         gcc_assert (t != cris_no_symbol && t != cris_offsettable_symbol);
946         if (! REG_S_P (operands[0]))
947           {
948             /* We must have a register as destination for what we're about to
949                do, and for the patterns we generate.  */
950             CRIS_ASSERT (can_create_pseudo_p ());
951             operands[1] = force_reg (SImode, operands[1]);
952           }
953         else
954           {
955             /* FIXME: add a REG_EQUAL (or is it REG_EQUIV) note to the
956                destination register for the symbol.  It might not be
957                worth it.  Measure.  */
958             crtl->uses_pic_offset_table = 1;
959             if (t == cris_rel_symbol)
960               {
961                 /* Change a "move.d sym(+offs),rN" into (allocate register rM)
962                    for pre-v32:
963                    "move.d (const (plus (unspec [sym]
964                     CRIS_UNSPEC_GOTREL) offs)),rM" "add.d rPIC,rM,rN"
965                    and for v32:
966                    "move.d (const (plus (unspec [sym]
967                     CRIS_UNSPEC_PCREL) offs)),rN".  */
968                 rtx tem, rm, rn = operands[0];
969                 rtx sym = GET_CODE (operands[1]) != CONST
970                   ? operands[1] : get_related_value (operands[1]);
971                 HOST_WIDE_INT offs = get_integer_term (operands[1]);
973                 gcc_assert (can_create_pseudo_p ());
975                 if (TARGET_V32)
976                   {
977                     tem = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, sym),
978                                           CRIS_UNSPEC_PCREL);
979                     if (offs != 0)
980                       tem = plus_constant (Pmode, tem, offs);
981                     rm = rn;
982                     emit_move_insn (rm, gen_rtx_CONST (Pmode, tem));
983                   }
984                 else
985                   {
986                     /* We still uses GOT-relative addressing for
987                        pre-v32.  */
988                     crtl->uses_pic_offset_table = 1;
989                     tem = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, sym),
990                                           CRIS_UNSPEC_GOTREL);
991                     if (offs != 0)
992                       tem = plus_constant (Pmode, tem, offs);
993                     rm = gen_reg_rtx (Pmode);
994                     emit_move_insn (rm, gen_rtx_CONST (Pmode, tem));
995                     if (expand_binop (Pmode, add_optab, rm, pic_offset_table_rtx,
996                                       rn, 0, OPTAB_LIB_WIDEN) != rn)
997                       internal_error ("expand_binop failed in movsi gotrel");
998                   }
999                 DONE;
1000               }
1001             else if (t == cris_got_symbol)
1002               {
1003                 /* Change a "move.d sym,rN" into (allocate register rM, rO)
1004                    "move.d (const (unspec [sym] CRIS_UNSPEC_GOTREAD)),rM"
1005                    "add.d rPIC,rM,rO", "move.d [rO],rN" with
1006                    the memory access marked as read-only.  */
1007                 rtx tem, mem, rm, ro, rn = operands[0];
1008                 gcc_assert (can_create_pseudo_p ());
1009                 tem = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, operands[1]),
1010                                       CRIS_UNSPEC_GOTREAD);
1011                 rm = gen_reg_rtx (Pmode);
1012                 emit_move_insn (rm, gen_rtx_CONST (Pmode, tem));
1013                 ro = gen_reg_rtx (Pmode);
1014                 if (expand_binop (Pmode, add_optab, rm, pic_offset_table_rtx,
1015                                   ro, 0, OPTAB_LIB_WIDEN) != ro)
1016                   internal_error ("expand_binop failed in movsi got");
1017                 mem = gen_rtx_MEM (Pmode, ro);
1019                 /* This MEM doesn't alias anything.  Whether it
1020                    aliases other same symbols is unimportant.  */
1021                 set_mem_alias_set (mem, new_alias_set ());
1022                 MEM_NOTRAP_P (mem) = 1;
1024                 /* We can set the GOT memory read of a non-called symbol
1025                    to readonly, but not that of a call symbol, as those
1026                    are subject to lazy evaluation and usually have the value
1027                    changed from the first call to the second (but
1028                    constant thereafter).  */
1029                 MEM_READONLY_P (mem) = 1;
1030                 emit_move_insn (rn, mem);
1031                 DONE;
1032               }
1033             else
1034               {
1035                 /* We get here when we have to change something that would
1036                    be recognizable if it wasn't PIC.  A ``sym'' is ok for
1037                    PIC symbols both with and without a GOT entry.  And ``sym
1038                    + offset'' is ok for local symbols, so the only thing it
1039                    could be, is a global symbol with an offset.  Check and
1040                    abort if not.  */
1041                 rtx reg = gen_reg_rtx (Pmode);
1042                 rtx sym = get_related_value (operands[1]);
1043                 HOST_WIDE_INT offs = get_integer_term (operands[1]);
1045                 gcc_assert (can_create_pseudo_p ()
1046                             && t == cris_got_symbol_needing_fixup
1047                             && sym != NULL_RTX && offs != 0);
1049                 emit_move_insn (reg, sym);
1050                 if (expand_binop (SImode, add_optab, reg,
1051                                   GEN_INT (offs), operands[0], 0,
1052                                   OPTAB_LIB_WIDEN) != operands[0])
1053                   internal_error ("expand_binop failed in movsi got+offs");
1054                 DONE;
1055               }
1056           }
1057       }
1060 (define_insn "*movsi_got_load"
1061   [(set (reg:SI CRIS_GOT_REGNUM) (unspec:SI [(const_int 0)] CRIS_UNSPEC_GOT))]
1062   "flag_pic"
1064   return TARGET_V32
1065     ? "lapc _GLOBAL_OFFSET_TABLE_,%:"
1066     : "move.d $pc,%:\;sub.d .:GOTOFF,%:";
1068   [(set_attr "cc" "clobber")])
1070 (define_insn "*movsi_internal"
1071   [(set
1072     (match_operand:SI 0 "nonimmediate_operand"
1073                       "=r,r, r,Q>,r,Q>,g,r,r, r,g,rQ>,x,  m,x")
1074     (match_operand:SI 1 "cris_general_operand_or_pic_source"
1075                        "r,Q>,M,M, I,r, M,n,!S,g,r,x,  rQ>,x,gi"))]
1076     ;; Note that we prefer not to use the S alternative (if for some reason
1077     ;; it competes with others) above, but g matches S.
1078   ""
1080   /* Better to have c-switch here; it is worth it to optimize the size of
1081      move insns.  The alternative would be to try to find more constraint
1082      letters.  FIXME: Check again.  It seems this could shrink a bit.  */
1083   switch (which_alternative)
1084     {
1085     case 9:
1086       if (TARGET_V32)
1087        {
1088          if (!flag_pic
1089              && (GET_CODE (operands[1]) == SYMBOL_REF
1090                  || GET_CODE (operands[1]) == LABEL_REF
1091                  || (GET_CODE (operands[1]) == CONST
1092                      && (GET_CODE (XEXP (operands[1], 0)) != UNSPEC
1093                          || (XINT (XEXP (operands[1], 0), 1)
1094                              == CRIS_UNSPEC_PLT_PCREL)
1095                          || (XINT (XEXP (operands[1], 0), 1)
1096                              == CRIS_UNSPEC_PCREL)))))
1097            {
1098              /* FIXME: Express this through (set_attr cc none) instead,
1099                 since we can't express the ``none'' at this point.  FIXME:
1100                 Use lapc for everything except const_int and when next cc0
1101                 user would want the flag setting.  */
1102              CC_STATUS_INIT;
1103              return "lapc %1,%0";
1104            }
1105          if (flag_pic == 1
1106              && GET_CODE (operands[1]) == CONST
1107              && GET_CODE (XEXP (operands[1], 0)) == UNSPEC
1108              && XINT (XEXP (operands[1], 0), 1) == CRIS_UNSPEC_GOTREAD)
1109            return "movu.w %1,%0";
1110        }
1111        /* FALLTHROUGH */
1112     case 0:
1113     case 1:
1114     case 5:
1115     case 10:
1116       return "move.d %1,%0";
1118     case 11:
1119     case 12:
1120     case 13:
1121     case 14:
1122       return "move %d1,%0";
1124     case 2:
1125     case 3:
1126     case 6:
1127       return "clear.d %0";
1129       /* Constants -32..31 except 0.  */
1130     case 4:
1131       return "moveq %1,%0";
1133       /* We can win a little on constants -32768..-33, 32..65535.  */
1134     case 7:
1135       if (INTVAL (operands[1]) > 0 && INTVAL (operands[1]) < 65536)
1136         {
1137           if (INTVAL (operands[1]) < 256)
1138             return "movu.b %1,%0";
1139           return "movu.w %1,%0";
1140         }
1141       else if (INTVAL (operands[1]) >= -32768 && INTVAL (operands[1]) < 32768)
1142         {
1143           if (INTVAL (operands[1]) >= -128 && INTVAL (operands[1]) < 128)
1144             return "movs.b %1,%0";
1145           return "movs.w %1,%0";
1146         }
1147       return "move.d %1,%0";
1149     case 8:
1150       {
1151         rtx tem = operands[1];
1152         gcc_assert (GET_CODE (tem) == CONST);
1153         tem = XEXP (tem, 0);
1154         if (GET_CODE (tem) == PLUS
1155             && GET_CODE (XEXP (tem, 0)) == UNSPEC
1156             && (XINT (XEXP (tem, 0), 1) == CRIS_UNSPEC_GOTREL
1157                 || XINT (XEXP (tem, 0), 1) == CRIS_UNSPEC_PCREL)
1158             && CONST_INT_P (XEXP (tem, 1)))
1159           tem = XEXP (tem, 0);
1160         gcc_assert (GET_CODE (tem) == UNSPEC);
1161         switch (XINT (tem, 1))
1162           {
1163           case CRIS_UNSPEC_GOTREAD:
1164           case CRIS_UNSPEC_PLTGOTREAD:
1165             /* Using sign-extend mostly to be consistent with the
1166                indexed addressing mode.  */
1167             if (flag_pic == 1)
1168               return "movs.w %1,%0";
1169             return "move.d %1,%0";
1171           case CRIS_UNSPEC_GOTREL:
1172           case CRIS_UNSPEC_PLT_GOTREL:
1173             gcc_assert (!TARGET_V32);
1174             return "move.d %1,%0";
1176           case CRIS_UNSPEC_PCREL:
1177           case CRIS_UNSPEC_PLT_PCREL:
1178             gcc_assert (TARGET_V32);
1179             /* LAPC doesn't set condition codes; clear them to make the
1180                (equivalence-marked) result of this insn not presumed
1181                present.  This instruction can be a PIC symbol load (for
1182                a hidden symbol) which for weak symbols will be followed
1183                by a test for NULL.  */
1184             CC_STATUS_INIT;
1185             return "lapc %1,%0";
1187           default:
1188             gcc_unreachable ();
1189           }
1190       }
1191     default:
1192       return "BOGUS: %1 to %0";
1193     }
1195   [(set_attr "slottable" "yes,yes,yes,yes,yes,yes,no,no,no,no,no,yes,yes,no,no")
1196    (set_attr "cc" "*,*,*,*,*,*,*,*,*,*,*,none,none,none,none")])
1198 ;; Extend operations with side-effect from mem to register, using
1199 ;; MOVS/MOVU.  These are from mem to register only.
1201 ;; [rx=ry+rz.S]
1203 ;; QImode to HImode
1205 ;; FIXME: Can we omit extend to HImode, since GCC should truncate for
1206 ;; HImode by itself?  Perhaps use only anonymous modes?
1208 (define_insn "*ext_sideqihi_biap"
1209   [(set (match_operand:HI 0 "register_operand" "=r,r")
1210         (match_operator:HI
1211          5 "cris_extend_operator"
1212          [(mem:QI (plus:SI
1213                    (mult:SI (match_operand:SI 1 "register_operand" "r,r")
1214                             (match_operand:SI 2 "const_int_operand" "n,n"))
1215                    (match_operand:SI 3 "register_operand" "r,r")))]))
1216    (set (match_operand:SI 4 "register_operand" "=*3,r")
1217         (plus:SI (mult:SI (match_dup 1)
1218                           (match_dup 2))
1219                  (match_dup 3)))]
1220   "cris_side_effect_mode_ok (MULT, operands, 4, 3, 1, 2, 0)"
1221   "@
1222    #
1223    mov%e5.%m5 [%4=%3+%1%T2],%0")
1225 (define_insn "*ext_side<mode>si_biap"
1226   [(set (match_operand:SI 0 "register_operand" "=r,r")
1227         (match_operator:SI
1228          5 "cris_extend_operator"
1229          [(mem:BW (plus:SI
1230                    (mult:SI (match_operand:SI 1 "register_operand" "r,r")
1231                             (match_operand:SI 2 "const_int_operand" "n,n"))
1232                    (match_operand:SI 3 "register_operand" "r,r")))]))
1233    (set (match_operand:SI 4 "register_operand" "=*3,r")
1234         (plus:SI (mult:SI (match_dup 1)
1235                           (match_dup 2))
1236                  (match_dup 3)))]
1237   "cris_side_effect_mode_ok (MULT, operands, 4, 3, 1, 2, 0)"
1238   "@
1239    #
1240    mov%e5<m> [%4=%3+%1%T2],%0")
1242 ;; Same but [rx=ry+i]
1244 ;; QImode to HImode
1246 (define_insn "*ext_sideqihi"
1247   [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r")
1248         (match_operator:HI
1249          4 "cris_extend_operator"
1250          [(mem:QI (plus:SI
1251                    (match_operand:SI 1 "cris_bdap_operand" "%r,r,r,R,R")
1252                    (match_operand:SI 2 "cris_bdap_operand" "r>Rn,r,>Rn,r,r")))]))
1253    (set (match_operand:SI 3 "register_operand" "=*1,r,r,*2,r")
1254         (plus:SI (match_dup 1)
1255                  (match_dup 2)))]
1256   "cris_side_effect_mode_ok (PLUS, operands, 3, 1, 2, -1, 0)"
1258   if ((which_alternative == 0 || which_alternative == 3)
1259       && (!CONST_INT_P (operands[2])
1260           || INTVAL (operands[2]) > 127
1261           || INTVAL (operands[2]) < -128
1262           || satisfies_constraint_N (operands[2])
1263           || satisfies_constraint_J (operands[2])))
1264     return "#";
1265   if (which_alternative == 4)
1266     return "mov%e4.%m4 [%3=%2%S1],%0";
1267   return "mov%e4.%m4 [%3=%1%S2],%0";
1270 (define_insn "*ext_side<mode>si"
1271   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r,r")
1272         (match_operator:SI
1273          4 "cris_extend_operator"
1274          [(mem:BW (plus:SI
1275                    (match_operand:SI 1 "cris_bdap_operand" "%r,r,r,R,R")
1276                    (match_operand:SI 2 "cris_bdap_operand" "r>Rn,r,>Rn,r,r")))]))
1277    (set (match_operand:SI 3 "register_operand" "=*1,r,r,*2,r")
1278         (plus:SI (match_dup 1)
1279                  (match_dup 2)))]
1280   "cris_side_effect_mode_ok (PLUS, operands, 3, 1, 2, -1, 0)"
1282   if ((which_alternative == 0 || which_alternative == 3)
1283       && (!CONST_INT_P (operands[2])
1284           || INTVAL (operands[2]) > 127
1285           || INTVAL (operands[2]) < -128
1286           || satisfies_constraint_N (operands[2])
1287           || satisfies_constraint_J (operands[2])))
1288     return "#";
1289   if (which_alternative == 4)
1290     return "mov%e4<m> [%3=%2%S1],%0";
1291   return "mov%e4<m> [%3=%1%S2],%0";
1294 ;; FIXME: See movsi.
1296 (define_insn "movhi"
1297   [(set
1298     (match_operand:HI 0 "nonimmediate_operand" "=r,r, r,Q>,r,Q>,r,r,r,g,g,r,r,x")
1299     (match_operand:HI 1 "general_operand"       "r,Q>,M,M, I,r, L,O,n,M,r,g,x,r"))]
1300   ""
1302   switch (which_alternative)
1303     {
1304     case 0:
1305     case 1:
1306     case 5:
1307     case 10:
1308     case 11:
1309       return "move.w %1,%0";
1310     case 12:
1311     case 13:
1312       return "move %1,%0";
1313     case 2:
1314     case 3:
1315     case 9:
1316       return "clear.w %0";
1317     case 4:
1318       return "moveq %1,%0";
1319     case 6:
1320     case 8:
1321       if (INTVAL (operands[1]) < 256 && INTVAL (operands[1]) >= -128)
1322         {
1323           if (INTVAL (operands[1]) > 0)
1324             return "movu.b %1,%0";
1325           return "movs.b %1,%0";
1326         }
1327       return "move.w %1,%0";
1328     case 7:
1329       return "movEq %b1,%0";
1330     default:
1331       return "BOGUS: %1 to %0";
1332   }
1334   [(set_attr "slottable" "yes,yes,yes,yes,yes,yes,no,yes,no,no,no,no,yes,yes")
1335    (set_attr "cc" "*,*,none,none,*,none,*,clobber,*,none,none,*,none,none")])
1337 (define_insn "movstricthi"
1338   [(set
1339     (strict_low_part
1340      (match_operand:HI 0 "nonimmediate_operand" "+r,r, r,Q>,Q>,g,r,g"))
1341     (match_operand:HI 1 "general_operand"        "r,Q>,M,M, r, M,g,r"))]
1342   ""
1343   "@
1344    move.w %1,%0
1345    move.w %1,%0
1346    clear.w %0
1347    clear.w %0
1348    move.w %1,%0
1349    clear.w %0
1350    move.w %1,%0
1351    move.w %1,%0"
1352   [(set_attr "slottable" "yes,yes,yes,yes,yes,no,no,no")])
1354 (define_expand "reload_in<mode>"
1355   [(set (match_operand:BW 2 "register_operand" "=r")
1356         (match_operand:BW 1 "memory_operand" "m"))
1357    (set (match_operand:BW 0 "register_operand" "=x")
1358         (match_dup 2))]
1359   ""
1360   "")
1362 (define_expand "reload_out<mode>"
1363   [(set (match_operand:BW 2 "register_operand" "=&r")
1364         (match_operand:BW 1 "register_operand" "x"))
1365    (set (match_operand:BW 0 "memory_operand" "=m")
1366         (match_dup 2))]
1367   ""
1368   "")
1370 (define_insn "movqi"
1371   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,Q>,r, r,Q>,r,g,g,r,r,r,x")
1372         (match_operand:QI 1 "general_operand"       "r,r, Q>,M,M, I,M,r,O,g,x,r"))]
1373   ""
1374   "@
1375    move.b %1,%0
1376    move.b %1,%0
1377    move.b %1,%0
1378    clear.b %0
1379    clear.b %0
1380    moveq %1,%0
1381    clear.b %0
1382    move.b %1,%0
1383    moveq %b1,%0
1384    move.b %1,%0
1385    move %1,%0
1386    move %1,%0"
1387   [(set_attr "slottable" "yes,yes,yes,yes,yes,yes,no,no,yes,no,yes,yes")
1388    (set_attr "cc" "*,*,*,*,*,*,*,*,clobber,*,none,none")])
1390 (define_insn "movstrictqi"
1391   [(set (strict_low_part
1392          (match_operand:QI 0 "nonimmediate_operand" "+r,Q>,r, r,Q>,g,g,r"))
1393         (match_operand:QI 1 "general_operand"        "r,r, Q>,M,M, M,r,g"))]
1394   ""
1395   "@
1396    move.b %1,%0
1397    move.b %1,%0
1398    move.b %1,%0
1399    clear.b %0
1400    clear.b %0
1401    clear.b %0
1402    move.b %1,%0
1403    move.b %1,%0"
1404   [(set_attr "slottable" "yes,yes,yes,yes,yes,no,no,no")])
1406 ;; The valid "quick" bit-patterns are, except for 0.0, denormalized
1407 ;; values REALLY close to 0, and some NaN:s (I think; their exponent is
1408 ;; all ones); the worthwhile one is "0.0".
1409 ;; It will use clear, so we know ALL types of immediate 0 never change cc.
1411 (define_insn "movsf"
1412   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,Q>,r, r,Q>,g,g,r,r,x,Q>,m,x, x")
1413         (match_operand:SF 1 "general_operand"       "r,r, Q>,G,G, G,r,g,x,r,x, x,Q>,g"))]
1414   ""
1415   "@
1416    move.d %1,%0
1417    move.d %1,%0
1418    move.d %1,%0
1419    clear.d %0
1420    clear.d %0
1421    clear.d %0
1422    move.d %1,%0
1423    move.d %1,%0
1424    move %1,%0
1425    move %1,%0
1426    move %1,%0
1427    move %1,%0
1428    move %1,%0
1429    move %1,%0"
1430   [(set_attr "slottable" "yes,yes,yes,yes,yes,no,no,no,yes,yes,yes,no,yes,no")])
1432 ;; Movem patterns.  Primarily for use in function prologue and epilogue.
1433 ;; The V32 variants have an ordering matching the expectations of the
1434 ;; standard names "load_multiple" and "store_multiple"; pre-v32 movem
1435 ;; store R0 in the highest memory location.
1437 (define_expand "load_multiple"
1438   [(match_operand:SI 0 "register_operand" "")
1439    (match_operand:SI 1 "memory_operand" "")
1440    (match_operand:SI 2 "const_int_operand" "")]
1441   "TARGET_V32"
1443   rtx indreg;
1445   /* Apparently the predicate isn't checked, so we need to do so
1446      manually.  Once happened for libstdc++-v3 locale_facets.tcc.  */
1447   if (!MEM_P (operands[1]))
1448     FAIL;
1450   indreg = XEXP (operands[1], 0);
1452   if (GET_CODE (indreg) == POST_INC)
1453     indreg = XEXP (indreg, 0);
1454   if (!REG_P (indreg)
1455       || GET_CODE (operands[2]) != CONST_INT
1456       || !REG_P (operands[0])
1457       || REGNO (operands[0]) != 0
1458       || INTVAL (operands[2]) > CRIS_SP_REGNUM
1459       || (int) REGNO (indreg) < INTVAL (operands[2]))
1460     FAIL;
1461   gcc_unreachable ();
1462   emit_insn (cris_gen_movem_load (operands[1], operands[2], 0));
1463   DONE;
1466 (define_expand "store_multiple"
1467   [(match_operand:SI 0 "memory_operand" "")
1468    (match_operand:SI 1 "register_operand" "")
1469    (match_operand:SI 2 "const_int_operand" "")]
1470   "TARGET_V32"
1472   rtx indreg;
1474   /* See load_multiple.  */
1475   if (!MEM_P (operands[0]))
1476     FAIL;
1478   indreg = XEXP (operands[0], 0);
1480   if (GET_CODE (indreg) == POST_INC)
1481     indreg = XEXP (indreg, 0);
1482   if (!REG_P (indreg)
1483       || GET_CODE (operands[2]) != CONST_INT
1484       || !REG_P (operands[1])
1485       || REGNO (operands[1]) != 0
1486       || INTVAL (operands[2]) > CRIS_SP_REGNUM
1487       || (int) REGNO (indreg) < INTVAL (operands[2]))
1488     FAIL;
1489   gcc_unreachable ();
1490   cris_emit_movem_store (operands[0], operands[2], 0, false);
1491   DONE;
1494 (define_insn "*cris_load_multiple"
1495   [(match_parallel 0 "cris_load_multiple_op"
1496                    [(set (match_operand:SI 1 "register_operand" "=r,r")
1497                          (match_operand:SI 2 "memory_operand" "Q,m"))])]
1498   ""
1499   "movem %O0,%o0"
1500   [(set_attr "cc" "none")
1501    (set_attr "slottable" "yes,no")
1502    ;; Not true, but setting the length to 0 causes return sequences (ret
1503    ;; movem) to have the cost they had when (return) included the movem
1504    ;; and reduces the performance penalty taken for needing to emit an
1505    ;; epilogue (in turn copied by bb-reorder) instead of return patterns.
1506    ;; FIXME: temporary change until all insn lengths are correctly
1507    ;; described.  FIXME: have better target control over bb-reorder.
1508    (set_attr "length" "0")])
1510 (define_insn "*cris_store_multiple"
1511   [(match_parallel 0 "cris_store_multiple_op"
1512                    [(set (match_operand:SI 2 "memory_operand" "=Q,m")
1513                          (match_operand:SI 1 "register_operand" "r,r"))])]
1514   ""
1515   "movem %o0,%O0"
1516   [(set_attr "cc" "none")
1517    (set_attr "slottable" "yes,no")])
1520 ;; Sign- and zero-extend insns with standard names.
1521 ;;  Those for integer source operand are ordered with the widest source
1522 ;; type first.
1524 ;; Sign-extend.
1526 (define_insn "extendsidi2"
1527   [(set (match_operand:DI 0 "register_operand" "=r")
1528         (sign_extend:DI (match_operand:SI 1 "general_operand" "g")))]
1529   ""
1530   "move.d %1,%M0\;smi %H0\;neg.d %H0,%H0")
1532 (define_insn "extend<mode>di2"
1533   [(set (match_operand:DI 0 "register_operand" "=r")
1534         (sign_extend:DI (match_operand:BW 1 "general_operand" "g")))]
1535   ""
1536   "movs<m> %1,%M0\;smi %H0\;neg.d %H0,%H0")
1538 (define_insn "extend<mode>si2"
1539   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1540         (sign_extend:SI (match_operand:BW 1 "general_operand" "r,Q>,g")))]
1541   ""
1542   "movs<m> %1,%0"
1543   [(set_attr "slottable" "yes,yes,no")])
1545 ;; To do a byte->word extension, extend to dword, except that the top half
1546 ;; of the register will be clobbered.  FIXME: Perhaps this is not needed.
1548 (define_insn "extendqihi2"
1549   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
1550         (sign_extend:HI (match_operand:QI 1 "general_operand" "r,Q>,g")))]
1551   ""
1552   "movs.b %1,%0"
1553   [(set_attr "slottable" "yes,yes,no")])
1556 ;; Zero-extend.  The DImode ones are synthesized by gcc, so we don't
1557 ;; specify them here.
1559 (define_insn "zero_extend<mode>si2"
1560   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1561         (zero_extend:SI
1562          (match_operand:BW 1 "nonimmediate_operand" "r,Q>,m")))]
1563   ""
1564   "movu<m> %1,%0"
1565   [(set_attr "slottable" "yes,yes,no")])
1567 ;; Same comment as sign-extend QImode to HImode above applies.
1569 (define_insn "zero_extendqihi2"
1570   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
1571         (zero_extend:HI
1572          (match_operand:QI 1 "nonimmediate_operand" "r,Q>,m")))]
1573   ""
1574   "movu.b %1,%0"
1575   [(set_attr "slottable" "yes,yes,no")])
1577 ;; All kinds of arithmetic and logical instructions.
1579 ;; First, anonymous patterns to match addressing modes with
1580 ;; side-effects.
1582 ;; op.S [rx=ry+I],rz; (add, sub, or, and, bound).
1584 ;; [rx=ry+rz.S]
1586 (define_insn "*op_side<mode>_biap"
1587   [(set (match_operand:BWD 0 "register_operand" "=r,r")
1588         (match_operator:BWD
1589          6 "cris_orthogonal_operator"
1590          [(match_operand:BWD 1 "register_operand" "0,0")
1591           (mem:BWD (plus:SI
1592                     (mult:SI (match_operand:SI 2 "register_operand" "r,r")
1593                              (match_operand:SI 3 "const_int_operand" "n,n"))
1594                     (match_operand:SI 4 "register_operand" "r,r")))]))
1595    (set (match_operand:SI 5 "register_operand" "=*4,r")
1596         (plus:SI (mult:SI (match_dup 2)
1597                           (match_dup 3))
1598                  (match_dup 4)))]
1599   "cris_side_effect_mode_ok (MULT, operands, 5, 4, 2, 3, 0)"
1600   "@
1601    #
1602    %x6<m> [%5=%4+%2%T3],%0")
1604 ;; [rx=ry+i] ([%4=%2+%3])
1606 (define_insn "*op_side<mode>"
1607   [(set (match_operand:BWD 0 "register_operand" "=r,r,r,r,r")
1608         (match_operator:BWD
1609          5 "cris_orthogonal_operator"
1610          [(match_operand:BWD 1 "register_operand" "0,0,0,0,0")
1611           (mem:BWD (plus:SI
1612                    (match_operand:SI 2 "cris_bdap_operand" "%r,r,r,R,R")
1613                    (match_operand:SI 3 "cris_bdap_operand" "r>Rn,r,>Rn,r,r")))]))
1614    (set (match_operand:SI 4 "register_operand" "=*2,r,r,*3,r")
1615         (plus:SI (match_dup 2)
1616                  (match_dup 3)))]
1617   "cris_side_effect_mode_ok (PLUS, operands, 4, 2, 3, -1, 0)"
1619   if ((which_alternative == 0 || which_alternative == 3)
1620       && (!CONST_INT_P (operands[3])
1621           || INTVAL (operands[3]) > 127
1622           || INTVAL (operands[3]) < -128
1623           || satisfies_constraint_N (operands[3])
1624           || satisfies_constraint_J (operands[3])))
1625     return "#";
1626   if (which_alternative == 4)
1627     return "%x5.%s0 [%4=%3%S2],%0";
1628   return "%x5<m> [%4=%2%S3],%0";
1631 ;; To match all cases for commutative operations we may have to have the
1632 ;; following pattern for add, or & and.  I do not know really, but it does
1633 ;; not break anything.
1635 ;; FIXME: This really ought to be checked.
1637 ;; op.S [rx=ry+I],rz;
1639 ;; [rx=ry+rz.S]
1641 (define_insn "*op_swap_side<mode>_biap"
1642   [(set (match_operand:BWD 0 "register_operand" "=r,r")
1643         (match_operator:BWD
1644          6 "cris_commutative_orth_op"
1645          [(mem:BWD (plus:SI
1646                    (mult:SI (match_operand:SI 2 "register_operand" "r,r")
1647                             (match_operand:SI 3 "const_int_operand" "n,n"))
1648                    (match_operand:SI 4 "register_operand" "r,r")))
1649           (match_operand:BWD 1 "register_operand" "0,0")]))
1650    (set (match_operand:SI 5 "register_operand" "=*4,r")
1651         (plus:SI (mult:SI (match_dup 2)
1652                           (match_dup 3))
1653                  (match_dup 4)))]
1654   "cris_side_effect_mode_ok (MULT, operands, 5, 4, 2, 3, 0)"
1655   "@
1656    #
1657    %x6<m> [%5=%4+%2%T3],%0")
1659 ;; [rx=ry+i] ([%4=%2+%3])
1660 ;; FIXME: These could have anonymous mode for operand 0.
1662 ;; QImode
1664 (define_insn "*op_swap_side<mode>"
1665   [(set (match_operand:BWD 0 "register_operand" "=r,r,r,r,r")
1666         (match_operator:BWD
1667          5 "cris_commutative_orth_op"
1668          [(mem:BWD
1669            (plus:SI (match_operand:SI 2 "cris_bdap_operand" "%r,r,r,R,R")
1670                     (match_operand:SI 3 "cris_bdap_operand" "r>Rn,r,>Rn,r,r")))
1671           (match_operand:BWD 1 "register_operand" "0,0,0,0,0")]))
1672    (set (match_operand:SI 4 "register_operand" "=*2,r,r,*3,r")
1673         (plus:SI (match_dup 2)
1674                  (match_dup 3)))]
1675   "cris_side_effect_mode_ok (PLUS, operands, 4, 2, 3, -1, 0)"
1677   if ((which_alternative == 0 || which_alternative == 3)
1678       && (!CONST_INT_P (operands[3])
1679           || INTVAL (operands[3]) > 127
1680           || INTVAL (operands[3]) < -128
1681           || satisfies_constraint_N (operands[3])
1682           || satisfies_constraint_J (operands[3])))
1683     return "#";
1684   if (which_alternative == 4)
1685     return "%x5<m> [%4=%3%S2],%0";
1686   return "%x5<m> [%4=%2%S3],%0";
1689 ;; Add operations, standard names.
1691 ;; Note that for the 'P' constraint, the high part can be -1 or 0.  We
1692 ;; output the insn through the 'A' output modifier as "adds.w" and "addq",
1693 ;; respectively.
1694 (define_expand "adddi3"
1695   [(set (match_operand:DI 0 "register_operand")
1696         (plus:DI (match_operand:DI 1 "register_operand")
1697                  (match_operand:DI 2 "general_operand")))]
1698   ""
1700   if (MEM_P (operands[2]) && TARGET_V32)
1701     operands[2] = force_reg (DImode, operands[2]);
1704 (define_insn "*adddi3_non_v32"
1705   [(set (match_operand:DI 0 "register_operand" "=r,r,r,&r,&r")
1706         (plus:DI (match_operand:DI 1 "register_operand" "%0,0,0,0,r")
1707                  (match_operand:DI 2 "general_operand" "J,N,P,g,!To")))]
1708   "!TARGET_V32"
1709   "@
1710    addq %2,%M0\;ax\;addq 0,%H0
1711    subq %n2,%M0\;ax\;subq 0,%H0
1712    add%e2.%z2 %2,%M0\;ax\;%A2 %H2,%H0
1713    add.d %M2,%M0\;ax\;add.d %H2,%H0
1714    add.d %M2,%M1,%M0\;ax\;add.d %H2,%H1,%H0")
1716 ; It seems no use allowing a memory operand for this one, because we'd
1717 ; need a scratch register for incrementing the address.
1718 (define_insn "*adddi3_v32"
1719   [(set (match_operand:DI 0 "register_operand" "=r,r,r,r,r")
1720        (plus:DI (match_operand:DI 1 "register_operand" "%0,0,0,0,0")
1721                 (match_operand:DI 2 "nonmemory_operand" "J,N,P,r,n")))]
1722   "TARGET_V32"
1723   "@
1724    addq %2,%M0\;addc 0,%H0
1725    subq %n2,%M0\;ax\;subq 0,%H0
1726    add%e2.%z2 %2,%M0\;addc %H2,%H0
1727    add.d %M2,%M0\;addc %H2,%H0
1728    add.d %M2,%M0\;addc %H2,%H0")
1730 (define_expand "add<mode>3"
1731   [(set (match_operand:BWD 0 "register_operand")
1732         (plus:BWD
1733          (match_operand:BWD 1 "register_operand")
1734          (match_operand:BWD 2 "general_operand")))]
1735   ""
1736   "")
1738 (define_insn "*addsi3_non_v32"
1739   [(set (match_operand:SI 0 "register_operand"  "=r,r, r,r,r,r, r,r,  r")
1740         (plus:SI
1741          (match_operand:SI 1 "register_operand" "%0,0, 0,0,0,0, 0,r,  r")
1742          (match_operand:SI 2 "general_operand"   "r,Q>,J,N,n,!S,g,!To,0")))]
1744 ;; The last constraint is due to that after reload, the '%' is not
1745 ;; honored, and canonicalization doesn't care about keeping the same
1746 ;; register as in destination.  This will happen after insn splitting.
1747 ;; gcc <= 2.7.2.  FIXME: Check for gcc-2.9x
1749  "!TARGET_V32"
1751   switch (which_alternative)
1752     {
1753     case 0:
1754     case 1:
1755       return "add.d %2,%0";
1756     case 2:
1757       return "addq %2,%0";
1758     case 3:
1759       return "subq %n2,%0";
1760     case 4:
1761       /* 'Known value', but not in -63..63.
1762          Check if addu/subu may be used.  */
1763       if (INTVAL (operands[2]) > 0)
1764         {
1765           if (INTVAL (operands[2]) < 256)
1766             return "addu.b %2,%0";
1767           if (INTVAL (operands[2]) < 65536)
1768             return "addu.w %2,%0";
1769         }
1770       else
1771         {
1772           if (INTVAL (operands[2]) >= -255)
1773             return "subu.b %n2,%0";
1774           if (INTVAL (operands[2]) >= -65535)
1775             return "subu.w %n2,%0";
1776         }
1777       return "add.d %2,%0";
1778     case 5:
1779       {
1780         rtx tem = operands[2];
1781         gcc_assert (GET_CODE (tem) == CONST);
1782         tem = XEXP (tem, 0);
1783         if (GET_CODE (tem) == PLUS
1784             && GET_CODE (XEXP (tem, 0)) == UNSPEC
1785             /* We don't allow CRIS_UNSPEC_PCREL here; we can't have a
1786                pc-relative operand in an add insn.  */
1787             && XINT (XEXP (tem, 0), 1) == CRIS_UNSPEC_GOTREL
1788             && CONST_INT_P (XEXP (tem, 1)))
1789           tem = XEXP (tem, 0);
1790         gcc_assert (GET_CODE (tem) == UNSPEC);
1791         switch (XINT (tem, 1))
1792           {
1793           case CRIS_UNSPEC_GOTREAD:
1794           case CRIS_UNSPEC_PLTGOTREAD:
1795             /* Using sign-extend mostly to be consistent with the
1796                indexed addressing mode.  */
1797             if (flag_pic == 1)
1798               return "adds.w %2,%0";
1799             return "add.d %2,%0";
1801           case CRIS_UNSPEC_PLT_GOTREL:
1802           case CRIS_UNSPEC_GOTREL:
1803             return "add.d %2,%0";
1804           default:
1805             gcc_unreachable ();
1806           }
1807       }
1808     case 6:
1809       return "add%u2 %2,%0";
1810     case 7:
1811       return "add.d %2,%1,%0";
1812     case 8:
1813       return "add.d %1,%0";
1814     default:
1815       return "BOGUS addsi %2+%1 to %0";
1816     }
1818  [(set_attr "slottable" "yes,yes,yes,yes,no,no,no,no,yes")])
1820 ; FIXME: Check what's best: having the three-operand ACR alternative
1821 ; before or after the corresponding-operand2 alternative.  Check for
1822 ; *all* insns.  FIXME: constant constraint letter for -128..127.
1823 (define_insn "*addsi3_v32"
1824   [(set (match_operand:SI 0 "register_operand"  "=r,!a,r,!a, r,r,!a,r,!a,r,r,r,!a")
1825         (plus:SI
1826          (match_operand:SI 1 "register_operand" "%0,r, 0, r, 0,0,r, 0,r, 0,0,0,r")
1827          (match_operand:SI 2 "general_operand"  "r, r, Q>,Q>,J,N,NJ,L,L, P,n,g,g")))]
1828   "TARGET_V32"
1829   "@
1830    add.d %2,%0
1831    addi %2.b,%1,%0
1832    add.d %2,%0
1833    addo.d %2,%1,%0
1834    addq %2,%0
1835    subq %n2,%0
1836    addoq %2,%1,%0
1837    adds.w %2,%0
1838    addo %2,%1,%0
1839    addu.w %2,%0
1840    add.d %2,%0
1841    add%u2 %2,%0
1842    addo.%Z2 %2,%1,%0"
1843   [(set_attr "slottable" "yes,yes,yes,yes,yes,yes,yes,no,no,no,no,no,no")
1844    (set_attr "cc" "*,none,*,none,*,*,none,*,none,*,*,*,none")])
1846 (define_insn "*addhi3_non_v32"
1847   [(set (match_operand:HI 0 "register_operand"          "=r,r, r,r,r,r")
1848         (plus:HI (match_operand:HI 1 "register_operand" "%0,0, 0,0,0,r")
1849                  (match_operand:HI 2 "general_operand"   "r,Q>,J,N,g,!To")))]
1850   "!TARGET_V32"
1851   "@
1852    add.w %2,%0
1853    add.w %2,%0
1854    addq %2,%0
1855    subq %n2,%0
1856    add.w %2,%0
1857    add.w %2,%1,%0"
1858   [(set_attr "slottable" "yes,yes,yes,yes,no,no")
1859    (set_attr "cc" "normal,normal,clobber,clobber,normal,normal")])
1861 (define_insn "*addhi3_v32"
1862   [(set (match_operand:HI 0 "register_operand" "=r, !a,r,!a, r,r,!a,r,!a")
1863         (plus:HI
1864          (match_operand:HI 1 "register_operand" "%0,r, 0, r, 0,0,r, 0,r")
1865          (match_operand:HI 2 "general_operand"  "r, r, Q>,Q>,J,N,NJ,g,g")))]
1866   "TARGET_V32"
1867   "@
1868    add.w %2,%0
1869    addi %2.b,%1,%0
1870    add.w %2,%0
1871    addo.w %2,%1,%0
1872    addq %2,%0
1873    subq %n2,%0
1874    addoq %2,%1,%0
1875    add.w %2,%0
1876    addo.w %2,%1,%0"
1877   [(set_attr "slottable" "yes,yes,yes,yes,yes,yes,yes,no,no")
1878    (set_attr "cc" "*,none,*,none,clobber,clobber,none,*,none")])
1880 (define_insn "*addqi3_non_v32"
1881   [(set (match_operand:QI 0 "register_operand"          "=r,r, r,r,r,r,r")
1882         (plus:QI (match_operand:QI 1 "register_operand" "%0,0, 0,0,0,0,r")
1883                  (match_operand:QI 2 "general_operand"   "r,Q>,J,N,O,g,!To")))]
1884   "!TARGET_V32"
1885   "@
1886    add.b %2,%0
1887    add.b %2,%0
1888    addq %2,%0
1889    subq %n2,%0
1890    subQ -%b2,%0
1891    add.b %2,%0
1892    add.b %2,%1,%0"
1893   [(set_attr "slottable" "yes,yes,yes,yes,yes,no,no")
1894    (set_attr "cc" "normal,normal,clobber,clobber,clobber,normal,normal")])
1896 (define_insn "*addqi3_v32"
1897   [(set (match_operand:QI 0 "register_operand"  "=r,!a,r,!a, r,r,!a,r,r,!a")
1898         (plus:QI
1899          (match_operand:QI 1 "register_operand" "%0,r, 0, r, 0,0,r, 0,0,r")
1900          (match_operand:QI 2 "general_operand"   "r,r, Q>,Q>,J,N,NJ,O,g,g")))]
1901   "TARGET_V32"
1902   "@
1903    add.b %2,%0
1904    addi %2.b,%1,%0
1905    add.b %2,%0
1906    addo.b %2,%1,%0
1907    addq %2,%0
1908    subq %n2,%0
1909    addoq %2,%1,%0
1910    subQ -%b2,%0
1911    add.b %2,%0
1912    addo.b %2,%1,%0"
1913   [(set_attr "slottable" "yes,yes,yes,yes,yes,yes,yes,yes,no,no")
1914    (set_attr "cc" "*,none,*,none,clobber,clobber,none,clobber,*,none")])
1916 ;; Subtract.
1918 ;; Note that because of insn canonicalization these will *seldom* but
1919 ;; rarely be used with a known constant as an operand.
1921 ;; Note that for the 'P' constraint, the high part can be -1 or 0.  We
1922 ;; output the insn through the 'D' output modifier as "subs.w" and "subq",
1923 ;; respectively.
1924 (define_expand "subdi3"
1925   [(set (match_operand:DI 0 "register_operand")
1926         (minus:DI (match_operand:DI 1 "register_operand")
1927                   (match_operand:DI 2 "general_operand")))]
1928   ""
1930   if (TARGET_V32 && MEM_P (operands[2]))
1931     operands[2] = force_reg (DImode, operands[2]);
1934 (define_insn "*subdi3_non_v32"
1935   [(set (match_operand:DI 0 "register_operand" "=r,r,r,&r,&r")
1936         (minus:DI (match_operand:DI 1 "register_operand" "0,0,0,0,r")
1937                   (match_operand:DI 2 "general_operand" "J,N,P,g,!To")))]
1938   "!TARGET_V32"
1939   "@
1940    subq %2,%M0\;ax\;subq 0,%H0
1941    addq %n2,%M0\;ax\;addq 0,%H0
1942    sub%e2.%z2 %2,%M0\;ax\;%D2 %H2,%H0
1943    sub.d %M2,%M0\;ax\;sub.d %H2,%H0
1944    sub.d %M2,%M1,%M0\;ax\;sub.d %H2,%H1,%H0")
1946 (define_insn "*subdi3_v32"
1947   [(set (match_operand:DI 0 "register_operand" "=r,r,r,&r")
1948         (minus:DI (match_operand:DI 1 "register_operand" "0,0,0,0")
1949                   (match_operand:DI 2 "nonmemory_operand" "J,N,P,r")))]
1950   "TARGET_V32"
1951   "@
1952    subq %2,%M0\;ax\;subq 0,%H0
1953    addq %n2,%M0\;ax\;addq 0,%H0
1954    sub%e2.%z2 %2,%M0\;ax\;%D2 %H2,%H0
1955    sub.d %M2,%M0\;ax\;sub.d %H2,%H0")
1957 (define_expand "sub<mode>3"
1958   [(set (match_operand:BWD 0 "register_operand")
1959         (minus:BWD
1960          (match_operand:BWD 1 "register_operand")
1961          (match_operand:BWD 2 "general_operand")))]
1962   ""
1963   "")
1965 (define_insn "*subsi3_non_v32"
1966   [(set (match_operand:SI 0 "register_operand" "=r,r, r,r,r,r,r,r")
1967         (minus:SI
1968          (match_operand:SI 1 "register_operand" "0,0, 0,0,0,0,0,r")
1969          (match_operand:SI 2 "general_operand"  "r,Q>,J,N,P,n,g,!To")))]
1970   "!TARGET_V32"
1972 ;; This does not do the optimal: "addu.w 65535,r0" when %2 is negative.
1973 ;; But then again, %2 should not be negative.
1975   "@
1976    sub.d %2,%0
1977    sub.d %2,%0
1978    subq %2,%0
1979    addq %n2,%0
1980    sub%e2.%z2 %2,%0
1981    sub.d %2,%0
1982    sub.d %2,%0
1983    sub.d %2,%1,%0"
1984   [(set_attr "slottable" "yes,yes,yes,yes,no,no,no,no")])
1986 (define_insn "*subsi3_v32"
1987   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r,r,r,r")
1988        (minus:SI
1989         (match_operand:SI 1 "register_operand" "0,0,0,0,0,0,0")
1990         (match_operand:SI 2 "general_operand" "r,Q>,J,N,P,n,g")))]
1991   "TARGET_V32"
1992   "@
1993    sub.d %2,%0
1994    sub.d %2,%0
1995    subq %2,%0
1996    addq %n2,%0
1997    sub%e2.%z2 %2,%0
1998    sub.d %2,%0
1999    sub.d %2,%0"
2000   [(set_attr "slottable" "yes,yes,yes,yes,no,no,no")])
2002 (define_insn "*sub<mode>3_nonv32"
2003   [(set (match_operand:BW 0 "register_operand"          "=r,r, r,r,r,r")
2004         (minus:BW (match_operand:BW 1 "register_operand" "0,0, 0,0,0,r")
2005                   (match_operand:BW 2 "general_operand"  "r,Q>,J,N,g,!To")))]
2006   "!TARGET_V32"
2007   "@
2008    sub<m> %2,%0
2009    sub<m> %2,%0
2010    subq %2,%0
2011    addq %n2,%0
2012    sub<m> %2,%0
2013    sub<m> %2,%1,%0"
2014   [(set_attr "slottable" "yes,yes,yes,yes,no,no")
2015    (set_attr "cc" "normal,normal,clobber,clobber,normal,normal")])
2017 (define_insn "*sub<mode>3_v32"
2018   [(set (match_operand:BW 0 "register_operand" "=r,r,r,r,r")
2019         (minus:BW (match_operand:BW 1 "register_operand" "0,0,0,0,0")
2020                   (match_operand:BW 2 "general_operand" "r,Q>,J,N,g")))]
2021   "TARGET_V32"
2022   "@
2023    sub<m> %2,%0
2024    sub<m> %2,%0
2025    subq %2,%0
2026    addq %n2,%0
2027    sub<m> %2,%0"
2028   [(set_attr "slottable" "yes,yes,yes,yes,no")
2029    (set_attr "cc" "normal,normal,clobber,clobber,normal")])
2031 ;; CRIS has some add/sub-with-sign/zero-extend instructions.
2032 ;;  Although these perform sign/zero-extension to SImode, they are
2033 ;; equally applicable for the HImode case.
2034 ;; FIXME: Check; GCC should handle the widening.
2035 ;;  Note that these must be located after the normal add/sub patterns,
2036 ;; so not to get constants into any less specific operands.
2038 ;; Extend with add/sub and side-effect.
2040 ;; ADDS/SUBS/ADDU/SUBU and BOUND, which needs a check for zero_extend
2042 ;; adds/subs/addu/subu bound [rx=ry+rz.S]
2044 ;; QImode to HImode
2045 ;; FIXME: GCC should widen.
2047 (define_insn "*extopqihi_side_biap"
2048   [(set (match_operand:HI 0 "register_operand" "=r,r")
2049         (match_operator:HI
2050          6 "cris_additive_operand_extend_operator"
2051          [(match_operand:HI 1 "register_operand" "0,0")
2052           (match_operator:HI
2053            7 "cris_extend_operator"
2054            [(mem:QI (plus:SI
2055                      (mult:SI (match_operand:SI 2 "register_operand" "r,r")
2056                               (match_operand:SI 3 "const_int_operand" "n,n"))
2057                      (match_operand:SI 4 "register_operand" "r,r")))])]))
2058    (set (match_operand:SI 5 "register_operand" "=*4,r")
2059         (plus:SI (mult:SI (match_dup 2)
2060                           (match_dup 3))
2061                  (match_dup 4)))]
2062   "cris_side_effect_mode_ok (MULT, operands, 5, 4, 2, 3, 0)"
2063   "@
2064    #
2065    %x6%e7.%m7 [%5=%4+%2%T3],%0")
2067 (define_insn "*extop<mode>si_side_biap"
2068   [(set (match_operand:SI 0 "register_operand" "=r,r")
2069         (match_operator:SI
2070          6 "cris_operand_extend_operator"
2071          [(match_operand:SI 1 "register_operand" "0,0")
2072           (match_operator:SI
2073            7 "cris_extend_operator"
2074            [(mem:BW (plus:SI
2075                      (mult:SI (match_operand:SI 2 "register_operand" "r,r")
2076                               (match_operand:SI 3 "const_int_operand" "n,n"))
2077                      (match_operand:SI 4 "register_operand" "r,r")))])]))
2078    (set (match_operand:SI 5 "register_operand" "=*4,r")
2079         (plus:SI (mult:SI (match_dup 2)
2080                           (match_dup 3))
2081                  (match_dup 4)))]
2082   "(GET_CODE (operands[6]) != UMIN || GET_CODE (operands[7]) == ZERO_EXTEND)
2083    && cris_side_effect_mode_ok (MULT, operands, 5, 4, 2, 3, 0)"
2084   "@
2085    #
2086    %x6%e7<m> [%5=%4+%2%T3],%0")
2089 ;; [rx=ry+i]
2091 ;; QImode to HImode
2093 (define_insn "*extopqihi_side"
2094   [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r")
2095         (match_operator:HI
2096          5 "cris_additive_operand_extend_operator"
2097          [(match_operand:HI 1 "register_operand" "0,0,0,0,0")
2098           (match_operator:HI
2099            6 "cris_extend_operator"
2100            [(mem:QI
2101              (plus:SI (match_operand:SI 2 "cris_bdap_operand" "%r,r,r,R,R")
2102                       (match_operand:SI 3 "cris_bdap_operand" "r>Rn,r,>Rn,r,r")
2103                       ))])]))
2104    (set (match_operand:SI 4 "register_operand" "=*2,r,r,*3,r")
2105         (plus:SI (match_dup 2)
2106                  (match_dup 3)))]
2107   "cris_side_effect_mode_ok (PLUS, operands, 4, 2, 3, -1, 0)"
2109   if ((which_alternative == 0 || which_alternative == 3)
2110       && (!CONST_INT_P (operands[3])
2111           || INTVAL (operands[3]) > 127
2112           || INTVAL (operands[3]) < -128
2113           || satisfies_constraint_N (operands[3])
2114           || satisfies_constraint_J (operands[3])))
2115     return "#";
2116   if (which_alternative == 4)
2117     return "%x5%E6.%m6 [%4=%3%S2],%0";
2118   return "%x5%E6.%m6 [%4=%2%S3],%0";
2121 (define_insn "*extop<mode>si_side"
2122   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r,r")
2123         (match_operator:SI
2124          5 "cris_operand_extend_operator"
2125          [(match_operand:SI 1 "register_operand" "0,0,0,0,0")
2126           (match_operator:SI
2127            6 "cris_extend_operator"
2128            [(mem:BW
2129              (plus:SI (match_operand:SI 2 "cris_bdap_operand" "%r,r,r,R,R")
2130                       (match_operand:SI 3 "cris_bdap_operand" "r>Rn,r,>Rn,r,r")
2131                       ))])]))
2132    (set (match_operand:SI 4 "register_operand" "=*2,r,r,*3,r")
2133         (plus:SI (match_dup 2)
2134                  (match_dup 3)))]
2135   "(GET_CODE (operands[5]) != UMIN || GET_CODE (operands[6]) == ZERO_EXTEND)
2136    && cris_side_effect_mode_ok (PLUS, operands, 4, 2, 3, -1, 0)"
2138   if ((which_alternative == 0 || which_alternative == 3)
2139       && (!CONST_INT_P (operands[3])
2140           || INTVAL (operands[3]) > 127
2141           || INTVAL (operands[3]) < -128
2142           || satisfies_constraint_N (operands[3])
2143           || satisfies_constraint_J (operands[3])))
2144     return "#";
2145   if (which_alternative == 4)
2146     return "%x5%E6<m> [%4=%3%S2],%0";
2147   return "%x5%E6<m> [%4=%2%S3],%0";
2151 ;; As with op.S we may have to add special pattern to match commuted
2152 ;; operands to adds/addu and bound
2154 ;; adds/addu/bound [rx=ry+rz.S]
2156 ;; QImode to HImode
2157 ;; FIXME: GCC should widen.
2159 (define_insn "*extopqihi_swap_side_biap"
2160   [(set (match_operand:HI 0 "register_operand" "=r,r")
2161         (plus:HI
2162          (match_operator:HI
2163           6 "cris_extend_operator"
2164           [(mem:QI (plus:SI
2165                     (mult:SI (match_operand:SI 2 "register_operand" "r,r")
2166                              (match_operand:SI 3 "const_int_operand" "n,n"))
2167                     (match_operand:SI 4 "register_operand" "r,r")))])
2168          (match_operand:HI 1 "register_operand" "0,0")))
2169    (set (match_operand:SI 5 "register_operand" "=*4,r")
2170         (plus:SI (mult:SI (match_dup 2)
2171                           (match_dup 3))
2172                  (match_dup 4)))]
2173   "cris_side_effect_mode_ok (MULT, operands, 5, 4, 2, 3, 0)"
2174   "@
2175    #
2176    add%e6.b [%5=%4+%2%T3],%0")
2178 (define_insn "*extop<mode>si_swap_side_biap"
2179   [(set (match_operand:SI 0 "register_operand" "=r,r")
2180         (match_operator:SI
2181          7 "cris_plus_or_bound_operator"
2182          [(match_operator:SI
2183            6 "cris_extend_operator"
2184            [(mem:BW (plus:SI
2185                      (mult:SI (match_operand:SI 2 "register_operand" "r,r")
2186                               (match_operand:SI 3 "const_int_operand" "n,n"))
2187                      (match_operand:SI 4 "register_operand" "r,r")))])
2188           (match_operand:SI 1 "register_operand" "0,0")]))
2189    (set (match_operand:SI 5 "register_operand" "=*4,r")
2190         (plus:SI (mult:SI (match_dup 2)
2191                           (match_dup 3))
2192                  (match_dup 4)))]
2193   "(GET_CODE (operands[7]) != UMIN || GET_CODE (operands[6]) == ZERO_EXTEND)
2194    && cris_side_effect_mode_ok (MULT, operands, 5, 4, 2, 3, 0)"
2195   "@
2196    #
2197    %x7%E6<m> [%5=%4+%2%T3],%0")
2199 ;; [rx=ry+i]
2200 ;; FIXME: GCC should widen.
2202 ;; QImode to HImode
2204 (define_insn "*extopqihi_swap_side"
2205   [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r")
2206         (plus:HI
2207          (match_operator:HI
2208           5 "cris_extend_operator"
2209           [(mem:QI (plus:SI
2210                     (match_operand:SI 2 "cris_bdap_operand" "%r,r,r,R,R")
2211                     (match_operand:SI 3 "cris_bdap_operand" "r>Rn,r,>Rn,r,r")))])
2212          (match_operand:HI 1 "register_operand" "0,0,0,0,0")))
2213    (set (match_operand:SI 4 "register_operand" "=*2,r,r,*3,r")
2214         (plus:SI (match_dup 2)
2215                  (match_dup 3)))]
2216   "cris_side_effect_mode_ok (PLUS, operands, 4, 2, 3, -1, 0)"
2218   if ((which_alternative == 0 || which_alternative == 3)
2219       && (!CONST_INT_P (operands[3])
2220           || INTVAL (operands[3]) > 127
2221           || INTVAL (operands[3]) < -128
2222           || satisfies_constraint_N (operands[3])
2223           || satisfies_constraint_J (operands[3])))
2224     return "#";
2225   if (which_alternative == 4)
2226     return "add%e5.b [%4=%3%S2],%0";
2227   return "add%e5.b [%4=%2%S3],%0";
2230 (define_insn "*extop<mode>si_swap_side"
2231   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r,r")
2232         (match_operator:SI
2233          6 "cris_plus_or_bound_operator"
2234          [(match_operator:SI
2235            5 "cris_extend_operator"
2236            [(mem:BW (plus:SI
2237                      (match_operand:SI 2 "cris_bdap_operand" "%r,r,r,R,R")
2238                      (match_operand:SI 3 "cris_bdap_operand" "r>Rn,r,>Rn,r,r")))])
2239           (match_operand:SI 1 "register_operand" "0,0,0,0,0")]))
2240    (set (match_operand:SI 4 "register_operand" "=*2,r,r,*3,r")
2241         (plus:SI (match_dup 2)
2242                  (match_dup 3)))]
2243   "(GET_CODE (operands[6]) != UMIN || GET_CODE (operands[5]) == ZERO_EXTEND)
2244    && cris_side_effect_mode_ok (PLUS, operands, 4, 2, 3, -1, 0)"
2246   if ((which_alternative == 0 || which_alternative == 3)
2247       && (!CONST_INT_P (operands[3])
2248           || INTVAL (operands[3]) > 127
2249           || INTVAL (operands[3]) < -128
2250           || satisfies_constraint_N (operands[3])
2251           || satisfies_constraint_J (operands[3])))
2252     return "#";
2253   if (which_alternative == 4)
2254     return \"%x6%E5.%m5 [%4=%3%S2],%0\";
2255   return "%x6%E5<m> [%4=%2%S3],%0";
2258 ;; Extend versions (zero/sign) of normal add/sub (no side-effects).
2260 ;; QImode to HImode
2261 ;; FIXME: GCC should widen.
2263 (define_insn "*extopqihi_non_v32"
2264   [(set (match_operand:HI 0 "register_operand" "=r,r,r,r")
2265         (match_operator:HI
2266          3 "cris_additive_operand_extend_operator"
2267          [(match_operand:HI 1 "register_operand" "0,0,0,r")
2268           (match_operator:HI
2269            4 "cris_extend_operator"
2270            [(match_operand:QI 2 "nonimmediate_operand" "r,Q>,m,!To")])]))]
2271   "!TARGET_V32 && 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    (set_attr "cc" "clobber")])
2281 (define_insn "*extopqihi_v32"
2282   [(set (match_operand:HI 0 "register_operand" "=r,r")
2283         (match_operator:HI
2284          3 "cris_additive_operand_extend_operator"
2285          [(match_operand:HI 1 "register_operand" "0,0")
2286           (match_operator:HI
2287            4 "cris_extend_operator"
2288            [(match_operand:QI 2 "nonimmediate_operand" "r,m")])]))]
2289   "TARGET_V32"
2290   "%x3%e4.%m4 %2,%0"
2291   [(set_attr "slottable" "yes")
2292    (set_attr "cc" "clobber")])
2294 ;; QImode to SImode
2296 (define_insn "*extop<mode>si_non_v32"
2297   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
2298         (match_operator:SI
2299          3 "cris_operand_extend_operator"
2300          [(match_operand:SI 1 "register_operand" "0,0,0,r")
2301           (match_operator:SI
2302            4 "cris_extend_operator"
2303            [(match_operand:BW 2 "nonimmediate_operand" "r,Q>,m,!To")])]))]
2304   "!TARGET_V32
2305    && (GET_CODE (operands[3]) != UMIN || GET_CODE (operands[4]) == ZERO_EXTEND)
2306    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
2307    && (operands[1] != frame_pointer_rtx || GET_CODE (operands[3]) != PLUS)"
2308   "@
2309    %x3%E4<m> %2,%0
2310    %x3%E4<m> %2,%0
2311    %x3%E4<m> %2,%0
2312    %x3%E4<m> %2,%1,%0"
2313   [(set_attr "slottable" "yes,yes,no,no")])
2315 (define_insn "*extop<mode>si_v32"
2316   [(set (match_operand:SI 0 "register_operand" "=r,r")
2317         (match_operator:SI
2318          3 "cris_additive_operand_extend_operator"
2319          [(match_operand:SI 1 "register_operand" "0,0")
2320           (match_operator:SI
2321            4 "cris_extend_operator"
2322            [(match_operand:BW 2 "nonimmediate_operand" "r,m")])]))]
2323   "TARGET_V32"
2324   "%x3%e4.%m4 %2,%0"
2325   [(set_attr "slottable" "yes")])
2327 ;; As with the side-effect patterns, may have to have swapped operands for add.
2328 ;; For commutative operands, these are the canonical forms.
2330 ;; QImode to HImode
2332 (define_insn "*addxqihi_swap_non_v32"
2333   [(set (match_operand:HI 0 "register_operand" "=r,r,r,r")
2334         (plus:HI
2335          (match_operator:HI
2336           3 "cris_extend_operator"
2337           [(match_operand:QI 2 "nonimmediate_operand" "r,Q>,m,!To")])
2338          (match_operand:HI 1 "register_operand" "0,0,0,r")))]
2339   "!TARGET_V32 && operands[1] != frame_pointer_rtx"
2340   "@
2341    add%e3.b %2,%0
2342    add%e3.b %2,%0
2343    add%e3.b %2,%0
2344    add%e3.b %2,%1,%0"
2345   [(set_attr "slottable" "yes,yes,no,no")
2346    (set_attr "cc" "clobber")])
2348 ;; A case for v32, to catch the "addo" insn in addition to "adds".  We
2349 ;; only care to match the canonical form; there should be no other.
2351 (define_insn "*addsbw_v32"
2352   [(set (match_operand:HI 0 "register_operand" "=r,r,!a")
2353         (plus:HI
2354          (sign_extend:HI
2355           (match_operand:QI 2 "nonimmediate_operand" "r,m,m"))
2356          (match_operand:HI 1 "register_operand" "0,0,r")))]
2357   "TARGET_V32"
2358   "@
2359    adds.b %2,%0
2360    adds.b %2,%0
2361    addo.b %2,%1,%0"
2362   [(set_attr "slottable" "yes")
2363    (set_attr "cc" "clobber,clobber,none")])
2365 (define_insn "*addubw_v32"
2366   [(set (match_operand:HI 0 "register_operand" "=r,r")
2367         (plus:HI
2368          (zero_extend:HI
2369           (match_operand:QI 2 "nonimmediate_operand" "r,m"))
2370          (match_operand:HI 1 "register_operand" "0,0")))]
2371   "TARGET_V32"
2372   "addu.b %2,%0"
2373   [(set_attr "slottable" "yes")
2374    (set_attr "cc" "clobber")])
2376 (define_insn "*extop<mode>si_swap_non_v32"
2377   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
2378         (match_operator:SI
2379          4 "cris_plus_or_bound_operator"
2380          [(match_operator:SI
2381            3 "cris_extend_operator"
2382            [(match_operand:BW 2 "nonimmediate_operand" "r,Q>,m,!To")])
2383           (match_operand:SI 1 "register_operand" "0,0,0,r")]))]
2384   "!TARGET_V32
2385    && (GET_CODE (operands[4]) != UMIN || GET_CODE (operands[3]) == ZERO_EXTEND)
2386    && operands[1] != frame_pointer_rtx"
2387   "@
2388    %x4%E3<m> %2,%0
2389    %x4%E3<m> %2,%0
2390    %x4%E3<m> %2,%0
2391    %x4%E3<m> %2,%1,%0"
2392   [(set_attr "slottable" "yes,yes,no,no")])
2394 (define_insn "*adds<mode>_v32"
2395   [(set (match_operand:SI 0 "register_operand" "=r,r,!a")
2396         (plus:SI
2397          (sign_extend:SI
2398           (match_operand:BW 2 "nonimmediate_operand" "r,m,m"))
2399          (match_operand:SI 1 "register_operand" "0,0,r")))]
2400   "TARGET_V32"
2401   "@
2402    adds<m> %2,%0
2403    adds<m> %2,%0
2404    addo<m> %2,%1,%0"
2405   [(set_attr "slottable" "yes")
2406    (set_attr "cc" "*,*,none")])
2408 (define_insn "*addu<mode>_v32"
2409   [(set (match_operand:SI 0 "register_operand" "=r,r")
2410        (plus:SI
2411         (zero_extend:SI
2412           (match_operand:BW 2 "nonimmediate_operand" "r,m"))
2413         (match_operand:SI 1 "register_operand" "0,0")))]
2414   "TARGET_V32 && operands[1] != frame_pointer_rtx"
2415   "addu<m> %2,%0"
2416   [(set_attr "slottable" "yes")])
2418 (define_insn "*bound<mode>_v32"
2419   [(set (match_operand:SI 0 "register_operand" "=r")
2420        (umin:SI
2421         (zero_extend:SI
2422          (match_operand:BW 2 "register_operand" "r"))
2423         (match_operand:SI 1 "register_operand" "0")))]
2424   "TARGET_V32 && operands[1] != frame_pointer_rtx"
2425   "bound<m> %2,%0"
2426   [(set_attr "slottable" "yes")])
2428 ;; This is the special case when we use what corresponds to the
2429 ;; instruction above in "casesi".  Do *not* change it to use the generic
2430 ;; pattern and "REG 15" as pc; I did that and it led to madness and
2431 ;; maintenance problems: Instead of (as imagined) recognizing and removing
2432 ;; or replacing this pattern with something simpler, other variant
2433 ;; patterns were recognized or combined, including some prefix variants
2434 ;; where the value in pc is not that of the next instruction (which means
2435 ;; this instruction actually *is* special and *should* be marked as such).
2436 ;; When switching from the "generic pattern match" approach to this simpler
2437 ;; approach, there were insignificant differences in gcc, ipps and
2438 ;; product code, somehow due to scratching reload behind the ear or
2439 ;; something.  Testcase "gcc" looked .01% slower and 4 bytes bigger;
2440 ;; product code became .001% smaller but "looked better".  The testcase
2441 ;; "ipps" was just different at register allocation).
2443 ;; Assumptions in the jump optimizer forces us to use IF_THEN_ELSE in this
2444 ;; pattern with the default-label as the else, with the "if" being
2445 ;; index-is-less-than the max number of cases plus one.  The default-label
2446 ;; is attached to the end of the case-table at time of output.
2448 (define_insn "*casesi_adds_w"
2449   [(set (pc)
2450         (if_then_else
2451          (ltu (match_operand:SI 0 "register_operand" "r")
2452               (match_operand:SI 1 "const_int_operand" "n"))
2453          (plus:SI (sign_extend:SI
2454                    (mem:HI
2455                     (plus:SI (mult:SI (match_dup 0) (const_int 2))
2456                              (pc))))
2457                   (pc))
2458          (label_ref (match_operand 2 "" ""))))
2459    (use (label_ref (match_operand 3 "" "")))]
2460   "!TARGET_V32 && operands[0] != frame_pointer_rtx"
2461   "adds.w [$pc+%0.w],$pc"
2462   [(set_attr "cc" "clobber")])
2464 ;; For V32, we just have a jump, but we need to mark the table as used,
2465 ;; and the jump insn must have the if_then_else form expected by core
2466 ;; GCC.  Since we don't want to prolong the lifetime of the original
2467 ;; index value, we compare against "unspec 0".  It's a pity we have to
2468 ;; jump through to get the default label in place and to keep the jump
2469 ;; table around.  FIXME: Look into it some time.
2471 (define_insn "*casesi_jump_v32"
2472   [(set (pc)
2473         (if_then_else
2474          (ltu (unspec [(const_int 0)] CRIS_UNSPEC_CASESI)
2475               (match_operand:SI 0 "const_int_operand" "n"))
2476          (match_operand:SI 1 "register_operand" "r")
2477          (label_ref (match_operand 2 "" ""))))
2478    (use (label_ref (match_operand 3 "" "")))]
2479   "TARGET_V32"
2480   "jump %1%#"
2481   [(set_attr "cc" "clobber")
2482    (set_attr "slottable" "has_slot")])
2484 ;; Multiply instructions.
2486 ;; Sometimes powers of 2 (which are normally canonicalized to a
2487 ;; left-shift) appear here, as a result of address reloading.
2488 ;; As a special, for values 3 and 5, we can match with an addi, so add those.
2490 ;; FIXME: This may be unnecessary now.
2491 ;; Explicitly named for convenience of having a gen_... function.
2493 (define_insn "addi_mul"
2494   [(set (match_operand:SI 0 "register_operand" "=r")
2495         (mult:SI
2496          (match_operand:SI 1 "register_operand" "%0")
2497          (match_operand:SI 2 "const_int_operand" "n")))]
2498   "operands[0] != frame_pointer_rtx
2499    && operands[1] != frame_pointer_rtx
2500    && CONST_INT_P (operands[2])
2501    && (INTVAL (operands[2]) == 2
2502        || INTVAL (operands[2]) == 4 || INTVAL (operands[2]) == 3
2503        || INTVAL (operands[2]) == 5)"
2505   if (INTVAL (operands[2]) == 2)
2506     return "lslq 1,%0";
2507   else if (INTVAL (operands[2]) == 4)
2508     return "lslq 2,%0";
2509   else if (INTVAL (operands[2]) == 3)
2510     return "addi %0.w,%0";
2511   else if (INTVAL (operands[2]) == 5)
2512     return "addi %0.d,%0";
2513   return "BAD: adr_mulsi: %0=%1*%2";
2515 [(set_attr "slottable" "yes")
2516  ;; No flags are changed if this insn is "addi", but it does not seem
2517  ;; worth the trouble to distinguish that to the lslq cases.
2518  (set_attr "cc" "clobber")])
2520 ;; The addi insn as it is normally used.
2522 ;; Make the ACR alternative taste bad enough to not choose it as a
2523 ;; preference to avoid spilling problems (unwind-dw2-fde.c at build).
2524 ;; FIXME: Revisit for new register allocator.
2526 (define_insn "*addi"
2527   [(set (match_operand:SI 0 "register_operand" "=r,!a")
2528         (plus:SI
2529          (mult:SI (match_operand:SI 2 "register_operand" "r,r")
2530                   (match_operand:SI 3 "const_int_operand" "n,n"))
2531          (match_operand:SI 1 "register_operand" "0,r")))]
2532   "operands[0] != frame_pointer_rtx
2533    && operands[1] != frame_pointer_rtx
2534    && CONST_INT_P (operands[3])
2535    && (INTVAL (operands[3]) == 1
2536        || INTVAL (operands[3]) == 2 || INTVAL (operands[3]) == 4)"
2537   "@
2538    addi %2%T3,%0
2539    addi %2%T3,%1,%0"
2540   [(set_attr "slottable" "yes")
2541    (set_attr "cc" "none")])
2543 ;; The mstep instruction.  Probably not useful by itself; it's to
2544 ;; non-linear wrt. the other insns.  We used to expand to it, so at least
2545 ;; it's correct.
2547 (define_insn "mstep_shift"
2548   [(set (match_operand:SI 0 "register_operand" "=r")
2549         (if_then_else:SI
2550          (lt:SI (cc0) (const_int 0))
2551          (plus:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
2552                              (const_int 1))
2553                   (match_operand:SI 2 "register_operand" "r"))
2554          (ashift:SI (match_operand:SI 3 "register_operand" "0")
2555                     (const_int 1))))]
2556   "!TARGET_V32"
2557   "mstep %2,%0"
2558   [(set_attr "slottable" "yes")])
2560 ;; When illegitimate addresses are legitimized, sometimes gcc forgets
2561 ;; to canonicalize the multiplications.
2563 ;; FIXME: Check gcc > 2.7.2, remove and possibly fix in gcc.
2565 (define_insn "mstep_mul"
2566   [(set (match_operand:SI 0 "register_operand" "=r")
2567         (if_then_else:SI
2568          (lt:SI (cc0) (const_int 0))
2569          (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "0")
2570                            (const_int 2))
2571                   (match_operand:SI 2 "register_operand" "r"))
2572          (mult:SI (match_operand:SI 3 "register_operand" "0")
2573                   (const_int 2))))]
2574   "!TARGET_V32
2575    && operands[0] != frame_pointer_rtx
2576    && operands[1] != frame_pointer_rtx
2577    && operands[2] != frame_pointer_rtx
2578    && operands[3] != frame_pointer_rtx"
2579   "mstep %2,%0"
2580   [(set_attr "slottable" "yes")])
2582 (define_insn "<u>mul<s><mode>3"
2583   [(set (match_operand:WD 0 "register_operand" "=r")
2584         (mult:WD
2585          (szext:WD (match_operand:<S> 1 "register_operand" "%0"))
2586          (szext:WD (match_operand:<S> 2 "register_operand" "r"))))
2587    (clobber (match_scratch:SI 3 "=h"))]
2588   "TARGET_HAS_MUL_INSNS"
2589   "%!mul<su><mm> %2,%0"
2590   [(set (attr "slottable")
2591         (if_then_else (match_test "TARGET_MUL_BUG")
2592                       (const_string "no")
2593                       (const_string "yes")))
2594    ;; For umuls.[bwd] it's just N unusable here, but let's be safe.
2595    ;; For muls.b, this really extends to SImode, so cc should be
2596    ;; considered clobbered.
2597    ;; For muls.w, it's just N unusable here, but let's be safe.
2598    (set_attr "cc" "clobber")])
2600 ;; Note that gcc does not make use of such a thing as umulqisi3.  It gets
2601 ;; confused and will erroneously use it instead of umulhisi3, failing (at
2602 ;; least) gcc.c-torture/execute/arith-rand.c at all optimization levels.
2603 ;; Inspection of optab code shows that there must be only one widening
2604 ;; multiplication per mode widened to.
2606 (define_insn "mulsi3"
2607   [(set (match_operand:SI 0 "register_operand" "=r")
2608         (mult:SI (match_operand:SI 1 "register_operand" "%0")
2609                  (match_operand:SI 2 "register_operand" "r")))
2610    (clobber (match_scratch:SI 3 "=h"))]
2611   "TARGET_HAS_MUL_INSNS"
2612   "%!muls.d %2,%0"
2613   [(set (attr "slottable")
2614         (if_then_else (match_test "TARGET_MUL_BUG")
2615                       (const_string "no")
2616                       (const_string "yes")))
2617    ;; Just N unusable here, but let's be safe.
2618    (set_attr "cc" "clobber")])
2620 ;; A few multiply variations.
2622 ;; When needed, we can get the high 32 bits from the overflow
2623 ;; register.  We don't care to split and optimize these.
2625 ;; Note that cc0 is still valid after the move-from-overflow-register
2626 ;; insn; no special precaution need to be taken in cris_notice_update_cc.
2628 (define_insn "<u>mulsidi3"
2629   [(set (match_operand:DI 0 "register_operand" "=r")
2630         (mult:DI
2631          (szext:DI (match_operand:SI 1 "register_operand" "%0"))
2632          (szext:DI (match_operand:SI 2 "register_operand" "r"))))
2633    (clobber (match_scratch:SI 3 "=h"))]
2634   "TARGET_HAS_MUL_INSNS"
2635   "%!mul<su>.d %2,%M0\;move $mof,%H0")
2637 ;; These two patterns may be expressible by other means, perhaps by making
2638 ;; [u]?mulsidi3 a define_expand.
2640 ;; Due to register allocation braindamage, the clobber 1,2 alternatives
2641 ;; cause a move into the clobbered register *before* the insn, then
2642 ;; after the insn, mof is moved too, rather than the clobber assigned
2643 ;; the last mof target.  This became apparent when making MOF and SRP
2644 ;; visible registers, with the necessary tweak to smulsi3_highpart.
2645 ;; Because these patterns are used in division by constants, that damage
2646 ;; is visible (ipps regression tests).  Therefore the last two
2647 ;; alternatives, "helping" reload to avoid an unnecessary move, but
2648 ;; punished by force of one "?".  Check code from "int d (int a) {return
2649 ;; a / 1000;}" and unsigned.  FIXME: Comment above was for 3.2, revisit.
2651 (define_insn "<su>mulsi3_highpart"
2652   [(set (match_operand:SI 0 "register_operand" "=h,h,?r,?r")
2653         (truncate:SI
2654          (lshiftrt:DI
2655           (mult:DI
2656            (szext:DI (match_operand:SI 1 "register_operand" "r,r,0,r"))
2657            (szext:DI (match_operand:SI 2 "register_operand" "r,r,r,0")))
2658           (const_int 32))))
2659    (clobber (match_scratch:SI 3 "=1,2,h,h"))]
2660   "TARGET_HAS_MUL_INSNS"
2661   "@
2662    %!mul<su>.d %2,%1
2663    %!mul<su>.d %1,%2
2664    %!mul<su>.d %2,%1\;move $mof,%0
2665    %!mul<su>.d %1,%2\;move $mof,%0"
2666   [(set_attr "slottable" "yes,yes,no,no")
2667    (set_attr "cc" "clobber")])
2669 ;; Divide and modulus instructions.  CRIS only has a step instruction.
2671 (define_insn "dstep_shift"
2672   [(set (match_operand:SI 0 "register_operand" "=r")
2673         (if_then_else:SI
2674          (geu:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
2675                             (const_int 1))
2676               (match_operand:SI 2 "register_operand" "r"))
2677          (minus:SI (ashift:SI (match_operand:SI 3 "register_operand" "0")
2678                         (const_int 1))
2679                    (match_operand:SI 4 "register_operand" "2"))
2680          (ashift:SI (match_operand:SI 5 "register_operand" "0")
2681                         (const_int 1))))]
2682   ""
2683   "dstep %2,%0"
2684   [(set_attr "slottable" "yes")
2685    (set_attr "cc" "noov32")])
2687 ;; Here's a variant with mult instead of ashift.
2689 ;; FIXME: This should be investigated.  Which one matches through combination?
2691 (define_insn "dstep_mul"
2692   [(set (match_operand:SI 0 "register_operand" "=r")
2693         (if_then_else:SI
2694          (geu:SI (mult:SI (match_operand:SI 1 "register_operand" "0")
2695                           (const_int 2))
2696               (match_operand:SI 2 "register_operand" "r"))
2697          (minus:SI (mult:SI (match_operand:SI 3 "register_operand" "0")
2698                             (const_int 2))
2699                    (match_operand:SI 4 "register_operand" "2"))
2700          (mult:SI (match_operand:SI 5 "register_operand" "0")
2701                   (const_int 2))))]
2702   "operands[0] != frame_pointer_rtx
2703    && operands[1] != frame_pointer_rtx
2704    && operands[2] != frame_pointer_rtx
2705    && operands[3] != frame_pointer_rtx"
2706   "dstep %2,%0"
2707   [(set_attr "slottable" "yes")
2708    (set_attr "cc" "noov32")])
2710 ;; Logical operators.
2712 ;; Bitwise "and".
2714 ;; There is no use in defining "anddi3", because gcc can expand this by
2715 ;; itself, and make reasonable code without interference.
2717 ;; If the first operand is memory or a register and is the same as the
2718 ;; second operand, and the third operand is -256 or -65536, we can use
2719 ;; CLEAR instead.  Or, if the first operand is a register, and the third
2720 ;; operand is 255 or 65535, we can zero_extend.
2721 ;; GCC isn't smart enough to recognize these cases (yet), and they seem
2722 ;; to be common enough to be worthwhile.
2723 ;; FIXME: This should be made obsolete.
2725 (define_expand "andsi3"
2726   [(set (match_operand:SI 0 "nonimmediate_operand"         "")
2727         (and:SI (match_operand:SI 1 "nonimmediate_operand" "")
2728                 (match_operand:SI 2 "general_operand"    "")))]
2729   ""
2731   if (! (CONST_INT_P (operands[2])
2732          && (((INTVAL (operands[2]) == -256
2733                || INTVAL (operands[2]) == -65536)
2734               && rtx_equal_p (operands[1], operands[0]))
2735              || ((INTVAL (operands[2]) == 255
2736                   || INTVAL (operands[2]) == 65535)
2737                  && REG_P (operands[0])))))
2738     {
2739       /* Make intermediate steps if operand0 is not a register or
2740          operand1 is not a register, and hope that the reload pass will
2741          make something useful out of it.  Note that the operands are
2742          *not* canonicalized.  For the moment, I chicken out on this,
2743          because all or most ports do not describe 'and' with
2744          canonicalized operands, and I seem to remember magic in reload,
2745          checking that operand1 has constraint '%0', in which case
2746          operand0 and operand1 must have similar predicates.
2747          FIXME: Investigate.  */
2748       rtx reg0 = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (SImode);
2749       rtx reg1 = operands[1];
2751       if (! REG_P (reg1))
2752         {
2753           emit_move_insn (reg0, reg1);
2754           reg1 = reg0;
2755         }
2757       emit_insn (gen_rtx_SET (reg0, gen_rtx_AND (SImode, reg1, operands[2])));
2759       /* Make sure we get the right *final* destination.  */
2760       if (! REG_P (operands[0]))
2761         emit_move_insn (operands[0], reg0);
2763       DONE;
2764     }
2767 ;; Some special cases of andsi3.
2769 (define_insn "*andsi_movu"
2770   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
2771         (and:SI (match_operand:SI 1 "nonimmediate_operand" "%r,Q,To")
2772                 (match_operand:SI 2 "const_int_operand" "n,n,n")))]
2773   "(INTVAL (operands[2]) == 255 || INTVAL (operands[2]) == 65535)
2774    && !side_effects_p (operands[1])"
2775   "movu.%z2 %1,%0"
2776   [(set_attr "slottable" "yes,yes,no")])
2778 (define_insn "*andsi_clear"
2779   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,Q,Q,To,To")
2780         (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,0,0,0,0")
2781                 (match_operand:SI 2 "const_int_operand" "P,n,P,n,P,n")))]
2782   "(INTVAL (operands[2]) == -65536 || INTVAL (operands[2]) == -256)
2783    && !side_effects_p (operands[0])"
2784   "@
2785    cLear.b %0
2786    cLear.w %0
2787    cLear.b %0
2788    cLear.w %0
2789    cLear.b %0
2790    cLear.w %0"
2791   [(set_attr "slottable" "yes,yes,yes,yes,no,no")
2792    (set_attr "cc" "none")])
2794 ;; This is a catch-all pattern, taking care of everything that was not
2795 ;; matched in the insns above.
2797 ;; Sidenote: the tightening from "nonimmediate_operand" to
2798 ;; "register_operand" for operand 1 actually increased the register
2799 ;; pressure (worse code).  That will hopefully change with an
2800 ;; improved reload pass.
2802 (define_insn "*expanded_andsi_non_v32"
2803   [(set (match_operand:SI 0 "register_operand"         "=r,r,r, r,r")
2804         (and:SI (match_operand:SI 1 "register_operand" "%0,0,0, 0,r")
2805                 (match_operand:SI 2 "general_operand"   "I,r,Q>,g,!To")))]
2806   "!TARGET_V32"
2807   "@
2808    andq %2,%0
2809    and.d %2,%0
2810    and.d %2,%0
2811    and.d %2,%0
2812    and.d %2,%1,%0"
2813   [(set_attr "slottable" "yes,yes,yes,no,no")])
2815 (define_insn "*expanded_andsi_v32"
2816   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
2817         (and:SI (match_operand:SI 1 "register_operand" "%0,0,0,0")
2818                 (match_operand:SI 2 "general_operand" "I,r,Q>,g")))]
2819   "TARGET_V32"
2820   "@
2821    andq %2,%0
2822    and.d %2,%0
2823    and.d %2,%0
2824    and.d %2,%0"
2825   [(set_attr "slottable" "yes,yes,yes,no")
2826    (set_attr "cc" "noov32")])
2828 ;; For both QI and HI we may use the quick patterns.  This results in
2829 ;; useless condition codes, but that is used rarely enough for it to
2830 ;; normally be a win (could check ahead for use of cc0, but seems to be
2831 ;; more pain than win).
2833 ;; FIXME: See note for andsi3
2835 (define_expand "andhi3"
2836   [(set (match_operand:HI 0 "nonimmediate_operand" "")
2837         (and:HI (match_operand:HI 1 "nonimmediate_operand" "")
2838                 (match_operand:HI 2 "general_operand"  "")))]
2839   ""
2841   if (! (CONST_INT_P (operands[2])
2842          && (((INTVAL (operands[2]) == -256
2843                || INTVAL (operands[2]) == 65280)
2844               && rtx_equal_p (operands[1], operands[0]))
2845              || (INTVAL (operands[2]) == 255
2846                  && REG_P (operands[0])))))
2847     {
2848       /* See comment for andsi3.  */
2849       rtx reg0 = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (HImode);
2850       rtx reg1 = operands[1];
2852       if (! REG_P (reg1))
2853         {
2854           emit_move_insn (reg0, reg1);
2855           reg1 = reg0;
2856         }
2858       emit_insn (gen_rtx_SET (reg0, gen_rtx_AND (HImode, reg1, operands[2])));
2860       /* Make sure we get the right destination.  */
2861       if (! REG_P (operands[0]))
2862         emit_move_insn (operands[0], reg0);
2864       DONE;
2865     }
2868 ;; Some fast andhi3 special cases.
2870 (define_insn "*andhi_movu"
2871   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
2872         (and:HI (match_operand:HI 1 "nonimmediate_operand" "r,Q,To")
2873                 (const_int 255)))]
2874   "!side_effects_p (operands[1])"
2875   "mOvu.b %1,%0"
2876   [(set_attr "slottable" "yes,yes,no")])
2878 (define_insn "*andhi_clear"
2879   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,Q,To")
2880         (and:HI (match_operand:HI 1 "nonimmediate_operand" "0,0,0")
2881                 (const_int -256)))]
2882   "!side_effects_p (operands[0])"
2883   "cLear.b %0"
2884   [(set_attr "slottable" "yes,yes,no")
2885    (set_attr "cc" "none")])
2887 ;; Catch-all andhi3 pattern.
2889 (define_insn "*expanded_andhi_non_v32"
2890   [(set (match_operand:HI 0 "register_operand"         "=r,r,r, r,r,r,r")
2891         (and:HI (match_operand:HI 1 "register_operand" "%0,0,0, 0,0,0,r")
2892                 (match_operand:HI 2 "general_operand"   "I,r,Q>,L,O,g,!To")))]
2894 ;; Sidenote: the tightening from "general_operand" to
2895 ;; "register_operand" for operand 1 actually increased the register
2896 ;; pressure (worse code).  That will hopefully change with an
2897 ;; improved reload pass.
2899   "!TARGET_V32"
2900   "@
2901    andq %2,%0
2902    and.w %2,%0
2903    and.w %2,%0
2904    and.w %2,%0
2905    anDq %b2,%0
2906    and.w %2,%0
2907    and.w %2,%1,%0"
2908   [(set_attr "slottable" "yes,yes,yes,no,yes,no,no")
2909    (set_attr "cc" "clobber,normal,normal,normal,clobber,normal,normal")])
2911 (define_insn "*expanded_andhi_v32"
2912   [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r,r")
2913        (and:HI (match_operand:HI 1 "register_operand" "%0,0,0,0,0,0")
2914                (match_operand:HI 2 "general_operand" "I,r,Q>,L,O,g")))]
2915   "TARGET_V32"
2916   "@
2917    andq %2,%0
2918    and.w %2,%0
2919    and.w %2,%0
2920    and.w %2,%0
2921    anDq %b2,%0
2922    and.w %2,%0"
2923   [(set_attr "slottable" "yes,yes,yes,no,yes,no")
2924    (set_attr "cc" "clobber,noov32,noov32,noov32,clobber,noov32")])
2926 ;; A strict_low_part pattern.
2928 ;; Note the use of (match_dup 0) for the first operand of the operation
2929 ;; here.  Reload can't handle an operand pair where one is read-write
2930 ;; and must match a read, like in:
2931 ;; (insn 80 79 81 4
2932 ;;  (set (strict_low_part
2933 ;;        (subreg:QI (reg/v:SI 0 r0 [orig:36 data ] [36]) 0))
2934 ;;       (and:QI
2935 ;;        (subreg:QI (reg:SI 15 acr [orig:27 D.7531 ] [27]) 0)
2936 ;;        (const_int -64 [0xf..fc0]))) x.c:126 147 {*andqi_lowpart_v32}
2937 ;;  (nil))
2938 ;; In theory, it could reload this as a movstrictqi of the register
2939 ;; operand at the and:QI to the destination register and change the
2940 ;; and:QI operand to the same as the read-write output operand and the
2941 ;; result would be recognized, but it doesn't recognize that's a valid
2942 ;; reload for a strict_low_part-destination; it just sees a "+" at the
2943 ;; destination constraints.  Better than adding complexity to reload is
2944 ;; to follow the lead of m68k (see comment that begins with "These insns
2945 ;; must use MATCH_DUP") since prehistoric times and make it just a
2946 ;; match_dup.  FIXME: a sanity-check in gen* to refuse an insn with
2947 ;; input-constraints matching input-output-constraints, e.g. "+r" <- "0".
2949 (define_insn "*andhi_lowpart_non_v32"
2950   [(set (strict_low_part
2951          (match_operand:HI 0 "register_operand"        "+r,r,r"))
2952         (and:HI (match_dup 0)
2953                 (match_operand:HI 1 "general_operand"   "r,Q>,g")))]
2954   "!TARGET_V32"
2955   "@
2956    and.w %1,%0
2957    and.w %1,%0
2958    and.w %1,%0"
2959   [(set_attr "slottable" "yes,yes,no")])
2961 (define_insn "*andhi_lowpart_v32"
2962   [(set (strict_low_part
2963          (match_operand:HI 0 "register_operand" "+r,r,r"))
2964         (and:HI (match_dup 0)
2965                 (match_operand:HI 1 "general_operand" "r,Q>,g")))]
2966   "TARGET_V32"
2967   "@
2968    and.w %1,%0
2969    and.w %1,%0
2970    and.w %1,%0"
2971   [(set_attr "slottable" "yes,yes,no")
2972    (set_attr "cc" "noov32")])
2974 (define_expand "andqi3"
2975   [(set (match_operand:QI 0 "register_operand")
2976         (and:QI (match_operand:QI 1 "register_operand")
2977                (match_operand:QI 2 "general_operand")))]
2978   ""
2979   "")
2981 (define_insn "*andqi3_non_v32"
2982   [(set (match_operand:QI 0 "register_operand"         "=r,r,r, r,r,r")
2983         (and:QI (match_operand:QI 1 "register_operand" "%0,0,0, 0,0,r")
2984                 (match_operand:QI 2 "general_operand"   "I,r,Q>,O,g,!To")))]
2985   "!TARGET_V32"
2986   "@
2987    andq %2,%0
2988    and.b %2,%0
2989    and.b %2,%0
2990    andQ %b2,%0
2991    and.b %2,%0
2992    and.b %2,%1,%0"
2993   [(set_attr "slottable" "yes,yes,yes,yes,no,no")
2994    (set_attr "cc" "clobber,normal,normal,clobber,normal,normal")])
2996 (define_insn "*andqi3_v32"
2997   [(set (match_operand:QI 0 "register_operand" "=r,r,r,r,r")
2998         (and:QI (match_operand:QI 1 "register_operand" "%0,0,0,0,0")
2999                 (match_operand:QI 2 "general_operand" "I,r,Q>,O,g")))]
3000   "TARGET_V32"
3001   "@
3002    andq %2,%0
3003    and.b %2,%0
3004    and.b %2,%0
3005    andQ %b2,%0
3006    and.b %2,%0"
3007   [(set_attr "slottable" "yes,yes,yes,yes,no")
3008    (set_attr "cc" "clobber,noov32,noov32,clobber,noov32")])
3010 (define_insn "*andqi_lowpart_non_v32"
3011   [(set (strict_low_part
3012          (match_operand:QI 0 "register_operand"        "+r,r,r"))
3013         (and:QI (match_dup 0)
3014                 (match_operand:QI 1 "general_operand"   "r,Q>,g")))]
3015   "!TARGET_V32"
3016   "@
3017    and.b %1,%0
3018    and.b %1,%0
3019    and.b %1,%0"
3020   [(set_attr "slottable" "yes,yes,no")])
3022 (define_insn "*andqi_lowpart_v32"
3023   [(set (strict_low_part
3024          (match_operand:QI 0 "register_operand" "+r,r,r"))
3025         (and:QI (match_dup 0)
3026                 (match_operand:QI 1 "general_operand" "r,Q>,g")))]
3027   "TARGET_V32"
3028   "@
3029    and.b %1,%0
3030    and.b %1,%0
3031    and.b %1,%0"
3032   [(set_attr "slottable" "yes,yes,no")
3033    (set_attr "cc" "noov32")])
3035 ;; Bitwise or.
3037 ;; Same comment as anddi3 applies here - no need for such a pattern.
3039 ;; It seems there's no need to jump through hoops to get good code such as
3040 ;; with andsi3.
3042 (define_expand "ior<mode>3"
3043   [(set (match_operand:BWD 0 "register_operand")
3044         (ior:BWD (match_operand:BWD 1 "register_operand")
3045                  (match_operand:BWD 2 "general_operand")))]
3046   ""
3047   "")
3049 (define_insn "*iorsi3_non_v32"
3050   [(set (match_operand:SI 0 "register_operand"         "=r,r,r, r,r,r")
3051         (ior:SI (match_operand:SI 1 "register_operand" "%0,0,0, 0,0,r")
3052                 (match_operand:SI 2 "general_operand"  "I, r,Q>,n,g,!To")))]
3053   "!TARGET_V32"
3054   "@
3055    orq %2,%0
3056    or.d %2,%0
3057    or.d %2,%0
3058    oR.%s2 %2,%0
3059    or.d %2,%0
3060    or.d %2,%1,%0"
3061   [(set_attr "slottable" "yes,yes,yes,no,no,no")
3062    (set_attr "cc" "normal,normal,normal,clobber,normal,normal")])
3064 (define_insn "*iorsi3_v32"
3065   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r,r")
3066         (ior:SI (match_operand:SI 1 "register_operand" "%0,0,0,0,0")
3067                 (match_operand:SI 2 "general_operand" "I,r,Q>,n,g")))]
3068   "TARGET_V32"
3069   "@
3070    orq %2,%0
3071    or.d %2,%0
3072    or.d %2,%0
3073    oR.%s2 %2,%0
3074    or.d %2,%0"
3075   [(set_attr "slottable" "yes,yes,yes,no,no")
3076    (set_attr "cc" "noov32,noov32,noov32,clobber,noov32")])
3078 (define_insn "*iorhi3_non_v32"
3079   [(set (match_operand:HI 0 "register_operand"         "=r,r,r, r,r,r,r")
3080         (ior:HI (match_operand:HI 1 "register_operand" "%0,0,0, 0,0,0,r")
3081                 (match_operand:HI 2 "general_operand"   "I,r,Q>,L,O,g,!To")))]
3082   "!TARGET_V32"
3083   "@
3084    orq %2,%0
3085    or.w %2,%0
3086    or.w %2,%0
3087    or.w %2,%0
3088    oRq %b2,%0
3089    or.w %2,%0
3090    or.w %2,%1,%0"
3091   [(set_attr "slottable" "yes,yes,yes,no,yes,no,no")
3092    (set_attr "cc" "clobber,normal,normal,normal,clobber,normal,normal")])
3094 (define_insn "*iorhi3_v32"
3095   [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r,r")
3096         (ior:HI (match_operand:HI 1 "register_operand" "%0,0,0,0,0,0")
3097                 (match_operand:HI 2 "general_operand" "I,r,Q>,L,O,g")))]
3098   "TARGET_V32"
3099   "@
3100    orq %2,%0
3101    or.w %2,%0
3102    or.w %2,%0
3103    or.w %2,%0
3104    oRq %b2,%0
3105    or.w %2,%0"
3106   [(set_attr "slottable" "yes,yes,yes,no,yes,no")
3107    (set_attr "cc" "clobber,noov32,noov32,noov32,clobber,noov32")])
3109 (define_insn "*iorqi3_non_v32"
3110   [(set (match_operand:QI 0 "register_operand"         "=r,r,r, r,r,r")
3111         (ior:QI (match_operand:QI 1 "register_operand" "%0,0,0, 0,0,r")
3112                 (match_operand:QI 2 "general_operand"   "I,r,Q>,O,g,!To")))]
3113   "!TARGET_V32"
3114   "@
3115    orq %2,%0
3116    or.b %2,%0
3117    or.b %2,%0
3118    orQ %b2,%0
3119    or.b %2,%0
3120    or.b %2,%1,%0"
3121   [(set_attr "slottable" "yes,yes,yes,yes,no,no")
3122    (set_attr "cc" "clobber,normal,normal,clobber,normal,normal")])
3124 (define_insn "*iorqi3_v32"
3125   [(set (match_operand:QI 0 "register_operand" "=r,r,r,r,r")
3126         (ior:QI (match_operand:QI 1 "register_operand" "%0,0,0,0,0")
3127                 (match_operand:QI 2 "general_operand" "I,r,Q>,O,g")))]
3128   "TARGET_V32"
3129   "@
3130    orq %2,%0
3131    or.b %2,%0
3132    or.b %2,%0
3133    orQ %b2,%0
3134    or.b %2,%0"
3135   [(set_attr "slottable" "yes,yes,yes,yes,no")
3136    (set_attr "cc" "clobber,noov32,noov32,clobber,noov32")])
3138 ;; Exclusive-or
3140 ;; See comment about "anddi3" for xordi3 - no need for such a pattern.
3141 ;; FIXME: Do we really need the shorter variants?
3143 (define_insn "xorsi3"
3144   [(set (match_operand:SI 0 "register_operand" "=r")
3145         (xor:SI (match_operand:SI 1 "register_operand" "%0")
3146                 (match_operand:SI 2 "register_operand" "r")))]
3147   ""
3148   "xor %2,%0"
3149   [(set_attr "slottable" "yes")
3150    (set_attr "cc" "noov32")])
3152 (define_insn "xor<mode>3"
3153   [(set (match_operand:BW 0 "register_operand" "=r")
3154         (xor:BW (match_operand:BW 1 "register_operand" "%0")
3155                 (match_operand:BW 2 "register_operand" "r")))]
3156   ""
3157   "xor %2,%0"
3158   [(set_attr "slottable" "yes")
3159    (set_attr "cc" "clobber")])
3161 ;; Negation insns.
3163 ;; Questionable use, here mostly as a (slightly usable) define_expand
3164 ;; example.
3166 (define_expand "negsf2"
3167   [(set (match_dup 2)
3168         (match_dup 3))
3169    (parallel [(set (match_operand:SF 0 "register_operand" "=r")
3170                    (neg:SF (match_operand:SF 1
3171                             "register_operand" "0")))
3172               (use (match_dup 2))])]
3173   ""
3175   operands[2] = gen_reg_rtx (SImode);
3176   operands[3] = GEN_INT (1 << 31);
3179 (define_insn "*expanded_negsf2"
3180   [(set (match_operand:SF 0 "register_operand" "=r")
3181         (neg:SF (match_operand:SF 1 "register_operand" "0")))
3182    (use (match_operand:SI 2 "register_operand" "r"))]
3183   ""
3184   "xor %2,%0"
3185   [(set_attr "slottable" "yes")])
3187 ;; No "negdi2" although we could make one up that may be faster than
3188 ;; the one in libgcc.
3190 (define_insn "neg<mode>2"
3191   [(set (match_operand:BWD 0 "register_operand" "=r")
3192         (neg:BWD (match_operand:BWD 1 "register_operand" "r")))]
3193   ""
3194   "neg<m> %1,%0"
3195   [(set_attr "slottable" "yes")])
3197 ;; One-complements.
3199 ;; See comment on anddi3 - no need for a DImode pattern.
3200 ;; See also xor comment.
3202 (define_insn "one_cmplsi2"
3203   [(set (match_operand:SI 0 "register_operand" "=r")
3204         (not:SI (match_operand:SI 1 "register_operand" "0")))]
3205   ""
3206   "not %0"
3207   [(set_attr "slottable" "yes")
3208    (set_attr "cc" "noov32")])
3210 (define_insn "one_cmpl<mode>2"
3211   [(set (match_operand:BW 0 "register_operand" "=r")
3212         (not:BW (match_operand:BW 1 "register_operand" "0")))]
3213   ""
3214   "not %0"
3215   [(set_attr "slottable" "yes")
3216    (set_attr "cc" "clobber")])
3218 ;; Arithmetic/Logical shift right (and SI left).
3220 (define_insn "<shlr>si3"
3221   [(set (match_operand:SI 0 "register_operand" "=r")
3222         (shift:SI (match_operand:SI 1 "register_operand" "0")
3223                   (match_operand:SI 2 "nonmemory_operand" "Kcr")))]
3224   ""
3226   if (REG_S_P (operands[2]))
3227     return "<slr>.d %2,%0";
3229   return "<slr>q %2,%0";
3231   [(set_attr "slottable" "yes")
3232    (set_attr "cc" "noov32")])
3234 ;; Since gcc gets lost, and forgets to zero-extend the source (or mask
3235 ;; the destination) when it changes shifts of lower modes into SImode,
3236 ;; it is better to make these expands an anonymous patterns instead of
3237 ;; the more correct define_insns.  This occurs when gcc thinks that is
3238 ;; is better to widen to SImode and use immediate shift count.
3240 ;; FIXME: Is this legacy or still true for gcc >= 2.7.2?
3242 ;; FIXME: Can't parametrize sign_extend and zero_extend (before
3243 ;; mentioning "shiftrt"), so we need two patterns.
3244 (define_expand "ashr<mode>3"
3245   [(set (match_dup 3)
3246         (sign_extend:SI (match_operand:BW 1 "nonimmediate_operand" "")))
3247    (set (match_dup 4)
3248         (zero_extend:SI (match_operand:BW 2 "nonimmediate_operand" "")))
3249    (set (match_dup 5) (ashiftrt:SI (match_dup 3) (match_dup 4)))
3250    (set (match_operand:BW 0 "general_operand" "")
3251         (subreg:BW (match_dup 5) 0))]
3252   ""
3254   int i;
3256   for (i = 3; i < 6; i++)
3257     operands[i] = gen_reg_rtx (SImode);
3260 (define_expand "lshr<mode>3"
3261   [(set (match_dup 3)
3262         (zero_extend:SI (match_operand:BW 1 "nonimmediate_operand" "")))
3263    (set (match_dup 4)
3264         (zero_extend:SI (match_operand:BW 2 "nonimmediate_operand" "")))
3265    (set (match_dup 5) (lshiftrt:SI (match_dup 3) (match_dup 4)))
3266    (set (match_operand:BW 0 "general_operand" "")
3267         (subreg:BW (match_dup 5) 0))]
3268   ""
3270   int i;
3272   for (i = 3; i < 6; i++)
3273     operands[i] = gen_reg_rtx (SImode);
3276 (define_insn "*expanded_<shlr><mode>"
3277   [(set (match_operand:BW 0 "register_operand" "=r")
3278         (shiftrt:BW (match_operand:BW 1 "register_operand" "0")
3279                     (match_operand:BW 2 "register_operand" "r")))]
3280   ""
3281   "<slr><m> %2,%0"
3282   [(set_attr "slottable" "yes")
3283    (set_attr "cc" "noov32")])
3285 (define_insn "*<shlr><mode>_lowpart"
3286   [(set (strict_low_part (match_operand:BW 0 "register_operand" "+r"))
3287         (shiftrt:BW (match_dup 0)
3288                     (match_operand:BW 1 "register_operand" "r")))]
3289   ""
3290   "<slr><m> %1,%0"
3291   [(set_attr "slottable" "yes")
3292    (set_attr "cc" "noov32")])
3294 ;; Arithmetic/logical shift left.
3296 ;; For narrower modes than SI, we can use lslq although it makes cc
3297 ;; unusable.  The win is that we do not have to reload the shift-count
3298 ;; into a register.
3300 (define_insn "ashl<mode>3"
3301   [(set (match_operand:BW 0 "register_operand" "=r,r")
3302         (ashift:BW (match_operand:BW 1 "register_operand" "0,0")
3303                    (match_operand:BW 2 "nonmemory_operand" "r,Kc")))]
3304   ""
3306   return
3307     (CONST_INT_P (operands[2]) && INTVAL (operands[2]) > <nbitsm1>)
3308     ? "moveq 0,%0"
3309     : (CONSTANT_P (operands[2])
3310        ? "lslq %2,%0" : "lsl<m> %2,%0");
3312   [(set_attr "slottable" "yes")
3313    (set_attr "cc" "noov32,clobber")])
3315 ;; A strict_low_part matcher.
3317 (define_insn "*ashl<mode>_lowpart"
3318   [(set (strict_low_part (match_operand:BW 0 "register_operand" "+r"))
3319         (ashift:BW (match_dup 0)
3320                    (match_operand:HI 1 "register_operand" "r")))]
3321   ""
3322   "lsl<m> %1,%0"
3323   [(set_attr "slottable" "yes")
3324    (set_attr "cc" "noov32")])
3326 ;; Various strange insns that gcc likes.
3328 ;; Fortunately, it is simple to construct an abssf (although it may not
3329 ;; be very much used in practice).
3331 (define_insn "abssf2"
3332   [(set (match_operand:SF 0 "register_operand" "=r")
3333         (abs:SF (match_operand:SF 1 "register_operand" "0")))]
3334   ""
3335   "lslq 1,%0\;lsrq 1,%0")
3337 (define_insn "abssi2"
3338   [(set (match_operand:SI 0 "register_operand" "=r")
3339         (abs:SI (match_operand:SI 1 "register_operand" "r")))]
3340   ""
3341   "abs %1,%0"
3342   [(set_attr "slottable" "yes")
3343    (set_attr "cc" "noov32")])
3345 ;; FIXME: GCC should be able to do these expansions itself.
3347 (define_expand "abs<mode>2"
3348   [(set (match_dup 2)
3349         (sign_extend:SI (match_operand:BW 1 "general_operand" "")))
3350    (set (match_dup 3) (abs:SI (match_dup 2)))
3351    (set (match_operand:BW 0 "register_operand" "")
3352         (subreg:BW (match_dup 3) 0))]
3353   ""
3354   "operands[2] = gen_reg_rtx (SImode); operands[3] = gen_reg_rtx (SImode);")
3356 (define_insn "clzsi2"
3357   [(set (match_operand:SI 0 "register_operand" "=r")
3358         (clz:SI (match_operand:SI 1 "register_operand" "r")))]
3359   "TARGET_HAS_LZ"
3360   "lz %1,%0"
3361   [(set_attr "slottable" "yes")
3362    (set_attr "cc" "noov32")])
3364 (define_insn "bswapsi2"
3365   [(set (match_operand:SI 0 "register_operand" "=r")
3366         (bswap:SI (match_operand:SI 1 "register_operand" "0")))]
3367   "TARGET_HAS_SWAP"
3368   "swapwb %0"
3369   [(set_attr "slottable" "yes")
3370    (set_attr "cc" "noov32")])
3372 ;; This instruction swaps all bits in a register.
3373 ;; That means that the most significant bit is put in the place
3374 ;; of the least significant bit, and so on.
3376 (define_insn "cris_swap_bits"
3377   [(set (match_operand:SI 0 "register_operand" "=r")
3378         (unspec:SI [(match_operand:SI 1 "register_operand" "0")]
3379                    CRIS_UNSPEC_SWAP_BITS))]
3380   "TARGET_HAS_SWAP"
3381   "swapwbr %0"
3382   [(set_attr "slottable" "yes")
3383    (set_attr "cc" "noov32")])
3385 ;; Implement ctz using two instructions, one for bit swap and one for clz.
3386 ;; Defines a scratch register to avoid clobbering input.
3388 (define_expand "ctzsi2"
3389   [(set (match_dup 2)
3390         (match_operand:SI 1 "register_operand"))
3391    (set (match_dup 2)
3392         (unspec:SI [(match_dup 2)] CRIS_UNSPEC_SWAP_BITS))
3393    (set (match_operand:SI 0 "register_operand")
3394         (clz:SI (match_dup 2)))]
3395   "TARGET_HAS_LZ && TARGET_HAS_SWAP"
3396   "operands[2] = gen_reg_rtx (SImode);")
3398 ;; Bound-insn.  Defined to be the same as an unsigned minimum, which is an
3399 ;; operation supported by gcc.  Used in casesi, but used now and then in
3400 ;; normal code too.
3402 (define_expand "uminsi3"
3403   [(set (match_operand:SI 0 "register_operand" "")
3404         (umin:SI  (match_operand:SI 1 "register_operand" "")
3405                   (match_operand:SI 2 "general_operand" "")))]
3406   ""
3408   if (MEM_P (operands[2]) && TARGET_V32)
3409     operands[2] = force_reg (SImode, operands[2]);
3412 (define_insn "*uminsi3_non_v32"
3413   [(set (match_operand:SI 0 "register_operand"           "=r,r, r,r")
3414         (umin:SI  (match_operand:SI 1 "register_operand" "%0,0, 0,r")
3415                   (match_operand:SI 2 "general_operand"   "r,Q>,g,!To")))]
3416   "!TARGET_V32"
3418   if (CONST_INT_P (operands[2]))
3419     {
3420       /* Constant operands are zero-extended, so only 32-bit operands
3421          may be negative.  */
3422       if (INTVAL (operands[2]) >= 0)
3423         {
3424           if (INTVAL (operands[2]) < 256)
3425             return "bound.b %2,%0";
3427           if (INTVAL (operands[2]) < 65536)
3428             return "bound.w %2,%0";
3429         }
3430     }
3431   else if (which_alternative == 3)
3432     return "bound.d %2,%1,%0";
3434   return "bound.d %2,%0";
3436  [(set_attr "slottable" "yes,yes,no,no")])
3438 (define_insn "*uminsi3_v32"
3439   [(set (match_operand:SI 0 "register_operand" "=r,r")
3440         (umin:SI  (match_operand:SI 1 "register_operand" "%0,0")
3441                   (match_operand:SI 2 "nonmemory_operand" "r,i")))]
3442   "TARGET_V32"
3444   if (GET_CODE (operands[2]) == CONST_INT)
3445     {
3446       /* Constant operands are zero-extended, so only 32-bit operands
3447          may be negative.  */
3448       if (INTVAL (operands[2]) >= 0)
3449         {
3450           if (INTVAL (operands[2]) < 256)
3451             return "bound.b %2,%0";
3453           if (INTVAL (operands[2]) < 65536)
3454             return "bound.w %2,%0";
3455         }
3456     }
3458   return "bound.d %2,%0";
3460  [(set_attr "slottable" "yes,no")])
3462 ;; Jump and branch insns.
3464 (define_insn "jump"
3465   [(set (pc)
3466         (label_ref (match_operand 0 "" "")))]
3467   ""
3468   "ba %l0%#"
3469   [(set_attr "slottable" "has_slot")])
3471 ;; Testcase gcc.c-torture/compile/991213-3.c fails if we allow a constant
3472 ;; here, since the insn is not recognized as an indirect jump by
3473 ;; jmp_uses_reg_or_mem used by computed_jump_p.  Perhaps it is a kludge to
3474 ;; change from general_operand to nonimmediate_operand (at least the docs
3475 ;; should be changed), but then again the pattern is called indirect_jump.
3476 (define_expand "indirect_jump"
3477   [(set (pc) (match_operand:SI 0 "nonimmediate_operand"))]
3478   ""
3480   if (TARGET_V32 && MEM_P (operands[0]))
3481     operands[0] = force_reg (SImode, operands[0]);
3484 (define_insn "*indirect_jump_non_v32"
3485   [(set (pc) (match_operand:SI 0 "nonimmediate_operand" "rm"))]
3486   "!TARGET_V32"
3487   "jump %0")
3489 (define_insn "*indirect_jump_v32"
3490   [(set (pc) (match_operand:SI 0 "register_operand" "r"))]
3491   "TARGET_V32"
3492   "jump %0%#"
3493   [(set_attr "slottable" "has_slot")])
3495 ;; Return insn.  Used whenever the epilogue is very simple; if it is only
3496 ;; a single ret or jump [sp+].  No allocated stack space or saved
3497 ;; registers are allowed.
3498 ;; Note that for this pattern, although named, it is ok to check the
3499 ;; context of the insn in the test, not only compiler switches.
3501 (define_expand "return"
3502   [(return)]
3503   "cris_simple_epilogue ()"
3504   "cris_expand_return (cris_return_address_on_stack ()); DONE;")
3506 (define_insn "*return_expanded"
3507   [(return)]
3508   ""
3510   return cris_return_address_on_stack_for_return ()
3511     ? "jump [$sp+]" : "ret%#";
3513   [(set (attr "slottable")
3514         (if_then_else
3515          (match_test "cris_return_address_on_stack_for_return ()")
3516          (const_string "no")
3517          (const_string "has_return_slot")))])
3519 (define_expand "prologue"
3520   [(const_int 0)]
3521   "TARGET_PROLOGUE_EPILOGUE"
3522   "cris_expand_prologue (); DONE;")
3524 ;; Note that the (return) from the expander itself is always the last
3525 ;; insn in the epilogue.
3526 (define_expand "epilogue"
3527   [(const_int 0)]
3528   "TARGET_PROLOGUE_EPILOGUE"
3529   "cris_expand_epilogue (); DONE;")
3531 ;; Conditional branches.
3533 (define_expand "cbranch<mode>4"
3534   [(set (cc0) (compare
3535                (match_operand:BWD 1 "nonimmediate_operand")
3536                (match_operand:BWD 2 "general_operand")))
3537    (set (pc)
3538         (if_then_else (match_operator 0 "ordered_comparison_operator"
3539                        [(cc0) (const_int 0)])
3540                       (label_ref (match_operand 3 "" ""))
3541                       (pc)))]
3542   ""
3543   "")
3545 (define_expand "cbranchdi4"
3546   [(set (cc0)
3547         (compare (match_operand:DI 1 "nonimmediate_operand" "")
3548                  (match_operand:DI 2 "general_operand" "")))
3549    (set (pc)
3550         (if_then_else (match_operator 0 "ordered_comparison_operator"
3551                        [(cc0) (const_int 0)])
3552                       (label_ref (match_operand 3 "" ""))
3553                       (pc)))]
3554   ""
3556   if (TARGET_V32 && !REG_P (operands[1]))
3557     operands[1] = force_reg (DImode, operands[1]);
3558   if (TARGET_V32 && MEM_P (operands[2]))
3559     operands[2] = force_reg (DImode, operands[2]);
3563 ;; We suffer from the same overflow-bit-gets-in-the-way problem as
3564 ;; e.g. m68k, so we have to check if overflow bit is set on all "signed"
3565 ;; conditions.
3567 (define_insn "b<ncond:code>"
3568   [(set (pc)
3569         (if_then_else (ncond (cc0)
3570                              (const_int 0))
3571                       (label_ref (match_operand 0 "" ""))
3572                       (pc)))]
3573   ""
3574   "b<CC> %l0%#"
3575   [(set_attr "slottable" "has_slot")])
3577 (define_insn "b<ocond:code>"
3578   [(set (pc)
3579         (if_then_else (ocond (cc0)
3580                              (const_int 0))
3581                       (label_ref (match_operand 0 "" ""))
3582                       (pc)))]
3583   ""
3585   return
3586     (cc_prev_status.flags & CC_NO_OVERFLOW)
3587     ? 0 : "b<CC> %l0%#";
3589   [(set_attr "slottable" "has_slot")])
3591 (define_insn "b<rcond:code>"
3592   [(set (pc)
3593         (if_then_else (rcond (cc0)
3594                              (const_int 0))
3595                       (label_ref (match_operand 0 "" ""))
3596                       (pc)))]
3597   ""
3599   return
3600     (cc_prev_status.flags & CC_NO_OVERFLOW)
3601     ? "b<oCC> %l0%#" : "b<CC> %l0%#";
3603   [(set_attr "slottable" "has_slot")])
3605 ;; Reversed anonymous patterns to the ones above, as mandated.
3607 (define_insn "*b<ncond:code>_reversed"
3608   [(set (pc)
3609         (if_then_else (ncond (cc0)
3610                              (const_int 0))
3611                       (pc)
3612                       (label_ref (match_operand 0 "" ""))))]
3613   ""
3614   "b<rCC> %l0%#"
3615   [(set_attr "slottable" "has_slot")])
3617 (define_insn "*b<ocond:code>_reversed"
3618   [(set (pc)
3619         (if_then_else (ocond (cc0)
3620                              (const_int 0))
3621                       (pc)
3622                       (label_ref (match_operand 0 "" ""))))]
3623   ""
3625   return
3626     (cc_prev_status.flags & CC_NO_OVERFLOW)
3627     ? 0 : "b<rCC> %l0%#";
3629   [(set_attr "slottable" "has_slot")])
3631 (define_insn "*b<rcond:code>_reversed"
3632   [(set (pc)
3633         (if_then_else (rcond (cc0)
3634                              (const_int 0))
3635                       (pc)
3636                       (label_ref (match_operand 0 "" ""))))]
3637   ""
3639   return
3640     (cc_prev_status.flags & CC_NO_OVERFLOW)
3641     ? "b<roCC> %l0%#" : "b<rCC> %l0%#";
3643   [(set_attr "slottable" "has_slot")])
3645 ;; Set on condition: sCC.
3647 (define_expand "cstoredi4"
3648   [(set (cc0) (compare
3649                (match_operand:DI 2 "nonimmediate_operand")
3650                (match_operand:DI 3 "general_operand")))
3651    (set (match_operand:SI 0 "register_operand")
3652         (match_operator:SI 1 "ordered_comparison_operator"
3653          [(cc0) (const_int 0)]))]
3654   ""
3656   if (TARGET_V32 && !REG_P (operands[2]))
3657     operands[2] = force_reg (DImode, operands[2]);
3658   if (TARGET_V32 && MEM_P (operands[3]))
3659     operands[3] = force_reg (DImode, operands[3]);
3662 (define_expand "cstore<mode>4"
3663   [(set (cc0) (compare
3664                (match_operand:BWD 2 "nonimmediate_operand")
3665                (match_operand:BWD 3 "general_operand")))
3666    (set (match_operand:SI 0 "register_operand")
3667         (match_operator:SI 1 "ordered_comparison_operator"
3668          [(cc0) (const_int 0)]))]
3669   ""
3670   "")
3672 ;; Like bCC, we have to check the overflow bit for
3673 ;; signed conditions.
3675 (define_insn "s<ncond:code>"
3676   [(set (match_operand:SI 0 "register_operand" "=r")
3677         (ncond:SI (cc0) (const_int 0)))]
3678   ""
3679   "s<CC> %0"
3680   [(set_attr "slottable" "yes")
3681    (set_attr "cc" "none")])
3683 (define_insn "s<rcond:code>"
3684   [(set (match_operand:SI 0 "register_operand" "=r")
3685         (rcond:SI (cc0) (const_int 0)))]
3686   ""
3688   return
3689     (cc_prev_status.flags & CC_NO_OVERFLOW)
3690     ? "s<oCC> %0" : "s<CC> %0";
3692   [(set_attr "slottable" "yes")
3693    (set_attr "cc" "none")])
3695 (define_insn "s<ocond:code>"
3696   [(set (match_operand:SI 0 "register_operand" "=r")
3697         (ocond:SI (cc0) (const_int 0)))]
3698   ""
3700   return
3701     (cc_prev_status.flags & CC_NO_OVERFLOW)
3702     ? 0 : "s<CC> %0";
3704   [(set_attr "slottable" "yes")
3705    (set_attr "cc" "none")])
3707 ;; Call insns.
3709 ;; We need to make these patterns "expand", since the real operand is
3710 ;; hidden in a (mem:QI ) inside operand[0] (call_value: operand[1]),
3711 ;; and cannot be checked if it were a "normal" pattern.
3712 ;;  Note that "call" and "call_value" are *always* called with a
3713 ;; mem-operand for operand 0 and 1 respective.  What happens for combined
3714 ;; instructions is a different issue.
3716 (define_expand "call"
3717   [(parallel [(call (match_operand:QI 0 "cris_mem_call_operand" "")
3718                     (match_operand 1 "general_operand" ""))
3719               (clobber (reg:SI CRIS_SRP_REGNUM))])]
3720   ""
3722   gcc_assert (MEM_P (operands[0]));
3723   if (flag_pic)
3724     cris_expand_pic_call_address (&operands[0], &operands[1]);
3725   else
3726     operands[1] = const0_rtx;
3729 ;; Accept operands for operand 0 in order of preference.
3731 (define_insn "*expanded_call_non_v32"
3732   [(call (mem:QI (match_operand:SI 0 "general_operand" "r,Q>,g"))
3733          (match_operand:SI 1 "cris_call_type_marker" "rM,rM,rM"))
3734    (clobber (reg:SI CRIS_SRP_REGNUM))]
3735   "!TARGET_V32"
3736   "jsr %0")
3738 (define_insn "*expanded_call_v32"
3739   [(call
3740     (mem:QI
3741      (match_operand:SI 0 "cris_nonmemory_operand_or_callable_symbol" "n,r,U,i"))
3742     (match_operand:SI 1 "cris_call_type_marker" "rM,rM,rM,rM"))
3743    (clobber (reg:SI CRIS_SRP_REGNUM))]
3744   "TARGET_V32"
3745   "@
3746    jsr %0%#
3747    jsr %0%#
3748    bsr %0%#
3749    bsr %0%#"
3750   [(set_attr "slottable" "has_call_slot")])
3752 ;; Parallel when calculating and reusing address of indirect pointer
3753 ;; with simple offset.  (Makes most sense with PIC.)  It looks a bit
3754 ;; wrong not to have the clobber last, but that's the way combine
3755 ;; generates it (except it doesn't look into the *inner* mem, so this
3756 ;; just matches a peephole2).  FIXME: investigate that.
3757 (define_insn "*expanded_call_side"
3758   [(call (mem:QI
3759           (mem:SI
3760            (plus:SI (match_operand:SI 0 "cris_bdap_operand" "%r,  r,r")
3761                     (match_operand:SI 1 "cris_bdap_operand" "r>Rn,r,>Rn"))))
3762          (match_operand:SI 2 "cris_call_type_marker" "rM,rM,rM"))
3763    (clobber (reg:SI CRIS_SRP_REGNUM))
3764    (set (match_operand:SI 3 "register_operand" "=*0,r,r")
3765         (plus:SI (match_dup 0)
3766                  (match_dup 1)))]
3767   ;; Disabled until after reload until we can avoid an output reload for
3768   ;; operand 3 (being forbidden for call insns).
3769   "reload_completed && !TARGET_AVOID_GOTPLT && !TARGET_V32"
3770   "jsr [%3=%0%S1]")
3772 (define_expand "call_value"
3773   [(parallel [(set (match_operand 0 "" "")
3774                    (call (match_operand:QI 1 "cris_mem_call_operand" "")
3775                          (match_operand 2 "" "")))
3776               (clobber (reg:SI CRIS_SRP_REGNUM))])]
3777   ""
3779   gcc_assert (MEM_P (operands[1]));
3780   if (flag_pic)
3781     cris_expand_pic_call_address (&operands[1], &operands[2]);
3782   else
3783     operands[2] = const0_rtx;
3786 ;; The validity other than "general" of
3787 ;; operand 0 will be checked elsewhere.  Accept operands for operand 1 in
3788 ;; order of preference (Q includes r, but r is shorter, faster).
3789 ;;  We also accept a PLT symbol.  We output it as [rPIC+sym:GOTPLT] rather
3790 ;; than requiring getting rPIC + sym:PLT into a register.
3792 (define_insn "*expanded_call_value_non_v32"
3793   [(set (match_operand 0 "nonimmediate_operand" "=g,g,g")
3794         (call (mem:QI (match_operand:SI 1 "general_operand" "r,Q>,g"))
3795               (match_operand:SI 2 "cris_call_type_marker" "rM,rM,rM")))
3796    (clobber (reg:SI CRIS_SRP_REGNUM))]
3797   "!TARGET_V32"
3798   "Jsr %1"
3799   [(set_attr "cc" "clobber")])
3801 ;; See similar call special-case.
3802 (define_insn "*expanded_call_value_side"
3803   [(set (match_operand 0 "nonimmediate_operand" "=g,g,g")
3804         (call
3805          (mem:QI
3806           (mem:SI
3807            (plus:SI (match_operand:SI 1 "cris_bdap_operand" "%r,  r,r")
3808                     (match_operand:SI 2 "cris_bdap_operand" "r>Rn,r,>Rn"))))
3809          (match_operand:SI 3 "cris_call_type_marker" "rM,rM,rM")))
3810    (clobber (reg:SI CRIS_SRP_REGNUM))
3811    (set (match_operand:SI 4 "register_operand" "=*1,r,r")
3812         (plus:SI (match_dup 1)
3813                  (match_dup 2)))]
3814   ;; Disabled until after reload until we can avoid an output reload for
3815   ;; operand 4 (being forbidden for call insns).
3816   "reload_completed && !TARGET_AVOID_GOTPLT && !TARGET_V32"
3817   "Jsr [%4=%1%S2]"
3818   [(set_attr "cc" "clobber")])
3820 (define_insn "*expanded_call_value_v32"
3821   [(set
3822     (match_operand 0 "nonimmediate_operand" "=g,g,g,g")
3823     (call
3824      (mem:QI
3825       (match_operand:SI 1 "cris_nonmemory_operand_or_callable_symbol" "n,r,U,i"))
3826      (match_operand:SI 2 "cris_call_type_marker" "rM,rM,rM,rM")))
3827    (clobber (reg:SI 16))]
3828   "TARGET_V32"
3829   "@
3830    Jsr %1%#
3831    Jsr %1%#
3832    Bsr %1%#
3833    Bsr %1%#"
3834   [(set_attr "cc" "clobber")
3835    (set_attr "slottable" "has_call_slot")])
3837 ;; Used in debugging.  No use for the direct pattern; unfilled
3838 ;; delayed-branches are taken care of by other means.
3840 (define_insn "nop"
3841   [(const_int 0)]
3842   ""
3843   "nop"
3844   [(set_attr "cc" "none")])
3846 ;; Same as the gdb trap breakpoint, will cause a SIGTRAP for
3847 ;; cris-linux* and crisv32-linux*, as intended.  Will work in
3848 ;; freestanding environments with sufficient framework.
3849 (define_insn "trap"
3850   [(trap_if (const_int 1) (const_int 8))]
3851   "TARGET_TRAP_USING_BREAK8"
3852   "break 8")
3854 ;; We need to stop accesses to the stack after the memory is
3855 ;; deallocated.  Unfortunately, reorg doesn't look at naked clobbers,
3856 ;; e.g. (insn ... (clobber (mem:BLK (stack_pointer_rtx)))) and we don't
3857 ;; want to use a naked (unspec_volatile) as that would stop any
3858 ;; scheduling in the epilogue.  Hence we model it as a "real" insn that
3859 ;; sets the memory in an unspecified manner.  FIXME: Unfortunately it
3860 ;; still has the effect of an unspec_volatile.
3861 (define_insn "cris_frame_deallocated_barrier"
3862   [(set (mem:BLK (reg:SI CRIS_SP_REGNUM))
3863         (unspec:BLK [(const_int 0)] CRIS_UNSPEC_FRAME_DEALLOC))]
3864   ""
3865   ""
3866   [(set_attr "length" "0")])
3868 ;; We expand on casesi so we can use "bound" and "add offset fetched from
3869 ;; a table to pc" (adds.w [pc+%0.w],pc).
3871 ;; Note: if you change the "parallel" (or add anything after it) in
3872 ;; this expansion, you must change the macro ASM_OUTPUT_CASE_END
3873 ;; accordingly, to add the default case at the end of the jump-table.
3875 (define_expand "cris_casesi_non_v32"
3876   [(set (match_dup 5) (match_operand:SI 0 "general_operand" ""))
3877    (set (match_dup 6)
3878         (minus:SI (match_dup 5)
3879                   (match_operand:SI 1 "const_int_operand" "n")))
3880    (set (match_dup 7)
3881         (umin:SI (match_dup 6)
3882                  (match_operand:SI 2 "const_int_operand" "n")))
3883    (parallel
3884     [(set (pc)
3885           (if_then_else
3886            (ltu (match_dup 7) (match_dup 2))
3887            (plus:SI (sign_extend:SI
3888                      (mem:HI
3889                       (plus:SI (mult:SI (match_dup 7) (const_int 2))
3890                                (pc))))
3891                     (pc))
3892            (label_ref (match_operand 4 "" ""))))
3893      (use (label_ref (match_operand 3 "" "")))])]
3894   ""
3896   operands[2] = plus_constant (SImode, operands[2], 1);
3897   operands[5] = gen_reg_rtx (SImode);
3898   operands[6] = gen_reg_rtx (SImode);
3899   operands[7] = gen_reg_rtx (SImode);
3902 ;; FIXME: Check effect of not JUMP_TABLES_IN_TEXT_SECTION.
3903 (define_expand "cris_casesi_v32"
3904   [(set (match_dup 5) (match_operand:SI 0 "general_operand"))
3905    (set (match_dup 6)
3906        (minus:SI (match_dup 5)
3907                  (match_operand:SI 1 "const_int_operand")))
3908    (set (match_dup 7)
3909        (umin:SI (match_dup 6)
3910                 (match_operand:SI 2 "const_int_operand")))
3911    (set (match_dup 8) (match_dup 11))
3912    (set (match_dup 9)
3913        (plus:SI (mult:SI (match_dup 7) (const_int 2))
3914                 (match_dup 8)))
3915    (set (match_dup 10)
3916        (plus:SI (sign_extend:SI (mem:HI (match_dup 9)))
3917                 (match_dup 9)))
3918    (parallel
3919     [(set (pc)
3920          (if_then_else
3921           (ltu (unspec [(const_int 0)] CRIS_UNSPEC_CASESI) (match_dup 2))
3922           (match_dup 10)
3923           (label_ref (match_operand 4 "" ""))))
3924      (use (label_ref (match_dup 3)))])]
3925   "TARGET_V32"
3927   int i;
3928   rtx xlabel = gen_rtx_LABEL_REF (VOIDmode, operands[3]);
3929   for (i = 5; i <= 10; i++)
3930     operands[i] = gen_reg_rtx (SImode);
3931   operands[2] = plus_constant (SImode, operands[2], 1);
3933   /* Don't forget to decorate labels too, for PIC.  */
3934   operands[11] = flag_pic
3935     ? gen_rtx_CONST (Pmode,
3936                     gen_rtx_UNSPEC (Pmode, gen_rtvec (1, xlabel),
3937                                     CRIS_UNSPEC_PCREL))
3938     : xlabel;
3941 (define_expand "casesi"
3942   [(match_operand:SI 0 "general_operand")
3943    (match_operand:SI 1 "const_int_operand")
3944    (match_operand:SI 2 "const_int_operand")
3945    (match_operand 3 "" "")
3946    (match_operand 4 "" "")]
3947   ""
3949   if (TARGET_V32)
3950     emit_insn (gen_cris_casesi_v32 (operands[0], operands[1], operands[2],
3951                                     operands[3], operands[4]));
3952   else
3953     emit_insn (gen_cris_casesi_non_v32 (operands[0], operands[1], operands[2],
3954                                         operands[3], operands[4]));
3955   DONE;
3958 ;; Split-patterns.  Some of them have modes unspecified.  This
3959 ;; should always be ok; if for no other reason sparc.md has it as
3960 ;; well.
3962 ;; When register_operand is specified for an operand, we can get a
3963 ;; subreg as well (Axis-990331), so don't just assume that REG_P is true
3964 ;; for a register_operand and that REGNO can be used as is.  It is best to
3965 ;; guard with REG_P, unless it is worth it to adjust for the subreg case.
3967 ;; op [rx + 0],ry,rz
3968 ;; The index to rx is optimized into zero, and gone.
3970 ;; First, recognize bound [rx],ry,rz; where [rx] is zero-extended,
3971 ;; and add/sub [rx],ry,rz, with zero or sign-extend on [rx].
3972 ;; Split this into:
3973 ;;  move ry,rz
3974 ;;  op [rx],rz
3975 ;; Lose if rz=ry or rx=rz.
3976 ;; Call this op-extend-split.
3977 ;; Do not match for V32; the addo and addi shouldn't be split
3978 ;; up.
3980 (define_split
3981   [(set (match_operand 0 "cris_nonsp_register_operand" "")
3982         (match_operator
3983          4 "cris_operand_extend_operator"
3984          [(match_operand 1 "register_operand" "")
3985           (match_operator
3986            3 "cris_extend_operator"
3987            [(match_operand 2 "memory_operand" "")])]))]
3988   "!TARGET_V32
3989    && REG_P (operands[0])
3990    && REG_P (operands[1])
3991    && REGNO (operands[1]) != REGNO (operands[0])
3992    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
3993    && REG_P (XEXP (operands[2], 0))
3994    && REGNO (XEXP (operands[2], 0)) != REGNO (operands[0])"
3995   [(set (match_dup 0)
3996         (match_dup 1))
3997    (set (match_dup 0)
3998         (match_op_dup
3999          4 [(match_dup 0)
4000             (match_op_dup 3 [(match_dup 2)])]))]
4001   "")
4003 ;; As op-extend-split, but recognize and split op [rz],ry,rz into
4004 ;;  ext [rz],rz
4005 ;;  op ry,rz
4006 ;; Do this for plus or bound only, being commutative operations, since we
4007 ;; have swapped the operands.
4008 ;; Call this op-extend-split-rx=rz
4010 (define_split
4011   [(set (match_operand 0 "cris_nonsp_register_operand" "")
4012         (match_operator
4013          4 "cris_plus_or_bound_operator"
4014          [(match_operand 1 "register_operand" "")
4015           (match_operator
4016            3 "cris_extend_operator"
4017            [(match_operand 2 "memory_operand" "")])]))]
4018   "!TARGET_V32
4019    && REG_P (operands[0])
4020    && REG_P (operands[1])
4021    && REGNO (operands[1]) != REGNO (operands[0])
4022    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
4023    && REG_P (XEXP (operands[2], 0))
4024    && REGNO (XEXP (operands[2], 0)) == REGNO (operands[0])"
4025   [(set (match_dup 0)
4026         (match_op_dup 3 [(match_dup 2)]))
4027    (set (match_dup 0)
4028         (match_op_dup
4029          4 [(match_dup 0)
4030             (match_dup 1)]))]
4031   "")
4033 ;; As the op-extend-split, but swapped operands, and only for
4034 ;; plus or bound, being the commutative extend-operators.  FIXME: Why is
4035 ;; this needed?  Is it?
4036 ;; Call this op-extend-split-swapped
4038 (define_split
4039   [(set (match_operand 0 "cris_nonsp_register_operand" "")
4040         (match_operator
4041          4 "cris_plus_or_bound_operator"
4042          [(match_operator
4043            3 "cris_extend_operator"
4044            [(match_operand 2 "memory_operand" "")])
4045           (match_operand 1 "register_operand" "")]))]
4046   "!TARGET_V32
4047    && REG_P (operands[0])
4048    && REG_P (operands[1])
4049    && REGNO (operands[1]) != REGNO (operands[0])
4050    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
4051    && REG_P (XEXP (operands[2], 0))
4052    && REGNO (XEXP (operands[2], 0)) != REGNO (operands[0])"
4053   [(set (match_dup 0)
4054         (match_dup 1))
4055    (set (match_dup 0)
4056         (match_op_dup
4057          4 [(match_dup 0)
4058             (match_op_dup 3 [(match_dup 2)])]))]
4059   "")
4061 ;; As op-extend-split-rx=rz, but swapped operands, only for plus or
4062 ;; bound.  Call this op-extend-split-swapped-rx=rz.
4064 (define_split
4065   [(set (match_operand 0 "cris_nonsp_register_operand" "")
4066         (match_operator
4067          4 "cris_plus_or_bound_operator"
4068          [(match_operator
4069            3 "cris_extend_operator"
4070            [(match_operand 2 "memory_operand" "")])
4071           (match_operand 1 "register_operand" "")]))]
4072   "!TARGET_V32
4073    && REG_P (operands[0])
4074    && REG_P (operands[1])
4075    && REGNO (operands[1]) != REGNO (operands[0])
4076    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
4077    && REG_P (XEXP (operands[2], 0))
4078    && REGNO (XEXP (operands[2], 0)) == REGNO (operands[0])"
4079   [(set (match_dup 0)
4080         (match_op_dup 3 [(match_dup 2)]))
4081    (set (match_dup 0)
4082         (match_op_dup
4083          4 [(match_dup 0)
4084             (match_dup 1)]))]
4085   "")
4087 ;; As op-extend-split, but the mem operand is not extended.
4089 ;; op [rx],ry,rz changed into
4090 ;;  move ry,rz
4091 ;;  op [rx],rz
4092 ;; lose if ry=rz or rx=rz
4093 ;; Call this op-extend.
4095 (define_split
4096   [(set (match_operand 0 "cris_nonsp_register_operand" "")
4097         (match_operator
4098          3 "cris_orthogonal_operator"
4099          [(match_operand 1 "register_operand" "")
4100           (match_operand 2 "memory_operand" "")]))]
4101   "!TARGET_V32
4102    && REG_P (operands[0])
4103    && REG_P (operands[1])
4104    && REGNO (operands[1]) != REGNO (operands[0])
4105    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
4106    && REG_P (XEXP (operands[2], 0))
4107    && REGNO (XEXP (operands[2], 0)) != REGNO (operands[0])"
4108   [(set (match_dup 0)
4109         (match_dup 1))
4110    (set (match_dup 0)
4111         (match_op_dup
4112          3 [(match_dup 0)
4113             (match_dup 2)]))]
4114   "")
4116 ;; As op-extend-split-rx=rz, non-extended.
4117 ;; Call this op-split-rx=rz
4119 (define_split
4120   [(set (match_operand 0 "cris_nonsp_register_operand" "")
4121         (match_operator
4122          3 "cris_commutative_orth_op"
4123          [(match_operand 2 "memory_operand" "")
4124           (match_operand 1 "register_operand" "")]))]
4125   "!TARGET_V32
4126    && REG_P (operands[0])
4127    && REG_P (operands[1])
4128    && REGNO (operands[1]) != REGNO (operands[0])
4129    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
4130    && REG_P (XEXP (operands[2], 0))
4131    && REGNO (XEXP (operands[2], 0)) != REGNO (operands[0])"
4132   [(set (match_dup 0)
4133         (match_dup 1))
4134    (set (match_dup 0)
4135         (match_op_dup
4136          3 [(match_dup 0)
4137             (match_dup 2)]))]
4138   "")
4140 ;; As op-extend-split-swapped, nonextended.
4141 ;; Call this op-split-swapped.
4143 (define_split
4144   [(set (match_operand 0 "cris_nonsp_register_operand" "")
4145         (match_operator
4146          3 "cris_commutative_orth_op"
4147          [(match_operand 1 "register_operand" "")
4148           (match_operand 2 "memory_operand" "")]))]
4149   "!TARGET_V32
4150    && REG_P (operands[0]) && REG_P (operands[1])
4151    && REGNO (operands[1]) != REGNO (operands[0])
4152    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
4153    && REG_P (XEXP (operands[2], 0))
4154    && REGNO (XEXP (operands[2], 0)) == REGNO (operands[0])"
4155   [(set (match_dup 0)
4156         (match_dup 2))
4157    (set (match_dup 0)
4158         (match_op_dup
4159          3 [(match_dup 0)
4160             (match_dup 1)]))]
4161   "")
4163 ;; As op-extend-split-swapped-rx=rz, non-extended.
4164 ;; Call this op-split-swapped-rx=rz.
4166 (define_split
4167   [(set (match_operand 0 "cris_nonsp_register_operand" "")
4168         (match_operator
4169          3 "cris_orthogonal_operator"
4170          [(match_operand 2 "memory_operand" "")
4171           (match_operand 1 "register_operand" "")]))]
4172   "!TARGET_V32
4173    && REG_P (operands[0]) && REG_P (operands[1])
4174    && REGNO (operands[1]) != REGNO (operands[0])
4175    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
4176    && REG_P (XEXP (operands[2], 0))
4177    && REGNO (XEXP (operands[2], 0)) == REGNO (operands[0])"
4178   [(set (match_dup 0)
4179         (match_dup 2))
4180    (set (match_dup 0)
4181         (match_op_dup
4182          3 [(match_dup 0)
4183             (match_dup 1)]))]
4184   "")
4186 (include "sync.md")
4188 ;; Splits for all cases in side-effect insns where (possibly after reload
4189 ;; and register allocation) rx and ry in [rx=ry+i] are equal.
4191 ;; move.S1 [rx=rx+rz.S2],ry
4193 (define_split
4194   [(parallel
4195     [(set (match_operand 0 "register_operand" "")
4196           (match_operator
4197            6 "cris_mem_op"
4198            [(plus:SI
4199              (mult:SI (match_operand:SI 1 "register_operand" "")
4200                       (match_operand:SI 2 "const_int_operand" ""))
4201              (match_operand:SI 3 "register_operand" ""))]))
4202      (set (match_operand:SI 4 "register_operand" "")
4203           (plus:SI (mult:SI (match_dup 1)
4204                             (match_dup 2))
4205                     (match_dup 3)))])]
4206   "REG_P (operands[3]) && REG_P (operands[4])
4207    && REGNO (operands[3]) == REGNO (operands[4])"
4208   [(set (match_dup 4) (plus:SI (mult:SI (match_dup 1) (match_dup 2))
4209                                (match_dup 3)))
4210    (set (match_dup 0) (match_dup 5))]
4211   "operands[5] = replace_equiv_address (operands[6], operands[3]);")
4213 ;; move.S1 [rx=rx+i],ry
4215 (define_split
4216   [(parallel
4217     [(set (match_operand 0 "register_operand" "")
4218           (match_operator
4219            5 "cris_mem_op"
4220            [(plus:SI (match_operand:SI 1 "cris_bdap_operand" "")
4221                      (match_operand:SI 2 "cris_bdap_operand" ""))]))
4222      (set (match_operand:SI 3 "register_operand" "")
4223            (plus:SI (match_dup 1)
4224                     (match_dup 2)))])]
4225   "(rtx_equal_p (operands[3], operands[1])
4226     || rtx_equal_p (operands[3], operands[2]))"
4227   [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))
4228    (set (match_dup 0) (match_dup 4))]
4230   operands[4] = replace_equiv_address (operands[5], operands[3]);
4231   cris_order_for_addsi3 (operands, 1);
4234 ;; move.S1 ry,[rx=rx+rz.S2]
4236 (define_split
4237   [(parallel
4238     [(set (match_operator
4239            6 "cris_mem_op"
4240            [(plus:SI
4241              (mult:SI (match_operand:SI 0 "register_operand" "")
4242                       (match_operand:SI 1 "const_int_operand" ""))
4243              (match_operand:SI 2 "register_operand" ""))])
4244           (match_operand 3 "register_operand" ""))
4245      (set (match_operand:SI 4 "register_operand" "")
4246            (plus:SI (mult:SI (match_dup 0)
4247                              (match_dup 1))
4248                     (match_dup 2)))])]
4249   "REG_P (operands[2]) && REG_P (operands[4])
4250    && REGNO (operands[4]) == REGNO (operands[2])"
4251   [(set (match_dup 4) (plus:SI (mult:SI (match_dup 0) (match_dup 1))
4252                                 (match_dup 2)))
4253    (set (match_dup 5) (match_dup 3))]
4254   "operands[5] = replace_equiv_address (operands[6], operands[4]);")
4256 ;; move.S1 ry,[rx=rx+i]
4258 (define_split
4259   [(parallel
4260     [(set (match_operator
4261            6 "cris_mem_op"
4262            [(plus:SI (match_operand:SI 0 "cris_bdap_operand" "")
4263                      (match_operand:SI 1 "cris_bdap_operand" ""))])
4264           (match_operand 2 "register_operand" ""))
4265      (set (match_operand:SI 3 "register_operand" "")
4266            (plus:SI (match_dup 0)
4267                    (match_dup 1)))])]
4268   "(rtx_equal_p (operands[3], operands[0])
4269     || rtx_equal_p (operands[3], operands[1]))"
4270   [(set (match_dup 3) (plus:SI (match_dup 0) (match_dup 1)))
4271    (set (match_dup 5) (match_dup 2))]
4273   operands[5] = replace_equiv_address (operands[6], operands[3]);
4274   cris_order_for_addsi3 (operands, 0);
4277 ;; clear.[bwd] [rx=rx+rz.S2]
4279 (define_split
4280   [(parallel
4281     [(set (mem:BWD (plus:SI
4282                     (mult:SI (match_operand:SI 0 "register_operand" "")
4283                              (match_operand:SI 1 "const_int_operand" ""))
4284                     (match_operand:SI 2 "register_operand" "")))
4285            (const_int 0))
4286      (set (match_operand:SI 3 "register_operand" "")
4287            (plus:SI (mult:SI (match_dup 0)
4288                              (match_dup 1))
4289                     (match_dup 2)))])]
4290   "REG_P (operands[2]) && REG_P (operands[3])
4291    && REGNO (operands[3]) == REGNO (operands[2])"
4292   [(set (match_dup 3) (plus:SI (mult:SI (match_dup 0) (match_dup 1))
4293                                 (match_dup 2)))
4294    (set (mem:BWD (match_dup 3)) (const_int 0))]
4295   "")
4297 ;; clear.[bwd] [rx=rx+i]
4299 (define_split
4300   [(parallel
4301     [(set (mem:BWD
4302            (plus:SI (match_operand:SI 0 "cris_bdap_operand" "")
4303                     (match_operand:SI 1 "cris_bdap_operand" "")))
4304            (const_int 0))
4305      (set (match_operand:SI 2 "register_operand" "")
4306            (plus:SI (match_dup 0)
4307                     (match_dup 1)))])]
4308   "(rtx_equal_p (operands[0], operands[2])
4309     || rtx_equal_p (operands[2], operands[1]))"
4310   [(set (match_dup 2) (plus:SI (match_dup 0) (match_dup 1)))
4311    (set (mem:BWD (match_dup 2)) (const_int 0))]
4312   "cris_order_for_addsi3 (operands, 0);")
4314 ;; mov(s|u).S1 [rx=rx+rz.S2],ry
4316 (define_split
4317   [(parallel
4318     [(set (match_operand 0 "register_operand" "")
4319           (match_operator
4320             5 "cris_extend_operator"
4321             [(mem (plus:SI
4322                    (mult:SI (match_operand:SI 1 "register_operand" "")
4323                             (match_operand:SI 2 "const_int_operand" ""))
4324                    (match_operand:SI 3 "register_operand" "")))]))
4325      (set (match_operand:SI 4 "register_operand" "")
4326            (plus:SI (mult:SI (match_dup 1)
4327                              (match_dup 2))
4328                     (match_dup 3)))])]
4329   "REG_P (operands[3])
4330    && REG_P (operands[4])
4331    && REGNO (operands[3]) == REGNO (operands[4])"
4332   [(set (match_dup 4) (plus:SI (mult:SI (match_dup 1) (match_dup 2))
4333                                 (match_dup 3)))
4334    (set (match_dup 0) (match_op_dup 5 [(match_dup 6)]))]
4335   "operands[6] = replace_equiv_address (XEXP (operands[5], 0), operands[4]);")
4337 ;; mov(s|u).S1 [rx=rx+i],ry
4339 (define_split
4340   [(parallel
4341     [(set (match_operand 0 "register_operand" "")
4342           (match_operator
4343             4 "cris_extend_operator"
4344             [(mem (plus:SI
4345                    (match_operand:SI 1 "cris_bdap_operand" "")
4346                    (match_operand:SI 2 "cris_bdap_operand" "")))]))
4347      (set (match_operand:SI 3 "register_operand" "")
4348            (plus:SI (match_dup 1)
4349                     (match_dup 2)))])]
4350   "(rtx_equal_p (operands[1], operands[3])
4351     || rtx_equal_p (operands[2], operands[3]))"
4352   [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))
4353    (set (match_dup 0) (match_op_dup 4 [(match_dup 5)]))]
4355   operands[5] = replace_equiv_address (XEXP (operands[4], 0), operands[3]);
4356   cris_order_for_addsi3 (operands, 1);
4359 ;; op.S1 [rx=rx+i],ry
4361 (define_split
4362   [(parallel
4363     [(set (match_operand 0 "register_operand" "")
4364           (match_operator
4365             5 "cris_orthogonal_operator"
4366             [(match_operand 1 "register_operand" "")
4367              (mem (plus:SI
4368                    (match_operand:SI 2 "cris_bdap_operand" "")
4369                    (match_operand:SI 3 "cris_bdap_operand" "")))]))
4370      (set (match_operand:SI 4 "register_operand" "")
4371            (plus:SI (match_dup 2)
4372                     (match_dup 3)))])]
4373   "(rtx_equal_p (operands[4], operands[2])
4374     || rtx_equal_p (operands[4], operands[3]))"
4375   [(set (match_dup 4) (plus:SI (match_dup 2) (match_dup 3)))
4376    (set (match_dup 0) (match_op_dup 5 [(match_dup 1) (match_dup 6)]))]
4378   operands[6] = replace_equiv_address (XEXP (operands[5], 1), operands[4]);
4379   cris_order_for_addsi3 (operands, 2);
4382 ;; op.S1 [rx=rx+rz.S2],ry
4384 (define_split
4385   [(parallel
4386     [(set (match_operand 0 "register_operand" "")
4387           (match_operator
4388             6 "cris_orthogonal_operator"
4389             [(match_operand 1 "register_operand" "")
4390              (mem (plus:SI
4391                    (mult:SI (match_operand:SI 2 "register_operand" "")
4392                             (match_operand:SI 3 "const_int_operand" ""))
4393                    (match_operand:SI 4 "register_operand" "")))]))
4394      (set (match_operand:SI 5 "register_operand" "")
4395            (plus:SI (mult:SI (match_dup 2)
4396                              (match_dup 3))
4397                    (match_dup 4)))])]
4398   "REG_P (operands[4])
4399    && REG_P (operands[5])
4400    && REGNO (operands[5]) == REGNO (operands[4])"
4401   [(set (match_dup 5) (plus:SI (mult:SI (match_dup 2) (match_dup 3))
4402                                 (match_dup 4)))
4403    (set (match_dup 0) (match_op_dup 6 [(match_dup 1) (match_dup 7)]))]
4404   "operands[7] = replace_equiv_address (XEXP (operands[6], 1), operands[5]);")
4406 ;; op.S1 [rx=rx+rz.S2],ry (swapped)
4408 (define_split
4409   [(parallel
4410     [(set (match_operand 0 "register_operand" "")
4411           (match_operator
4412             6 "cris_commutative_orth_op"
4413             [(mem (plus:SI
4414                    (mult:SI (match_operand:SI 2 "register_operand" "")
4415                             (match_operand:SI 3 "const_int_operand" ""))
4416                    (match_operand:SI 4 "register_operand" "")))
4417              (match_operand 1 "register_operand" "")]))
4418      (set (match_operand:SI 5 "register_operand" "")
4419            (plus:SI (mult:SI (match_dup 2)
4420                              (match_dup 3))
4421                     (match_dup 4)))])]
4422   "REG_P (operands[4])
4423    && REG_P (operands[5])
4424    && REGNO (operands[5]) == REGNO (operands[4])"
4425   [(set (match_dup 5) (plus:SI (mult:SI (match_dup 2) (match_dup 3))
4426                                (match_dup 4)))
4427    (set (match_dup 0) (match_op_dup 6 [(match_dup 7) (match_dup 1)]))]
4428   "operands[7] = replace_equiv_address (XEXP (operands[6], 0), operands[5]);")
4430 ;; op.S1 [rx=rx+i],ry (swapped)
4432 (define_split
4433   [(parallel
4434     [(set (match_operand 0 "register_operand" "")
4435           (match_operator
4436             5 "cris_commutative_orth_op"
4437             [(mem
4438               (plus:SI (match_operand:SI 2 "cris_bdap_operand" "")
4439                        (match_operand:SI 3 "cris_bdap_operand" "")))
4440              (match_operand 1 "register_operand" "")]))
4441      (set (match_operand:SI 4 "register_operand" "")
4442           (plus:SI (match_dup 2)
4443                     (match_dup 3)))])]
4444   "(rtx_equal_p (operands[4], operands[2])
4445     || rtx_equal_p (operands[4], operands[3]))"
4446   [(set (match_dup 4) (plus:SI (match_dup 2) (match_dup 3)))
4447    (set (match_dup 0) (match_op_dup 5 [(match_dup 6) (match_dup 1)]))]
4449   operands[6] = replace_equiv_address (XEXP (operands[5], 0), operands[4]);
4450   cris_order_for_addsi3 (operands, 2);
4453 ;; op(s|u).S1 [rx=rx+rz.S2],ry
4455 (define_split
4456   [(parallel
4457     [(set (match_operand 0 "register_operand" "")
4458           (match_operator
4459             6 "cris_operand_extend_operator"
4460             [(match_operand 1 "register_operand" "")
4461              (match_operator
4462               7 "cris_extend_operator"
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 8)]))]
4477   "operands[8] = gen_rtx_fmt_e (GET_CODE (operands[7]), GET_MODE (operands[7]),
4478                                 replace_equiv_address (XEXP (operands[7], 0),
4479                                                        operands[5]));")
4481 ;; op(s|u).S1 [rx=rx+i],ry
4483 (define_split
4484   [(parallel
4485     [(set (match_operand 0 "register_operand" "")
4486           (match_operator
4487             5 "cris_operand_extend_operator"
4488             [(match_operand 1 "register_operand" "")
4489              (match_operator
4490               6 "cris_extend_operator"
4491               [(mem
4492                 (plus:SI (match_operand:SI 2 "cris_bdap_operand" "")
4493                          (match_operand:SI 3 "cris_bdap_operand" "")
4494                          ))])]))
4495      (set (match_operand:SI 4 "register_operand" "")
4496            (plus:SI (match_dup 2)
4497                     (match_dup 3)))])]
4498   "(rtx_equal_p (operands[4], operands[2])
4499     || rtx_equal_p (operands[4], operands[3]))"
4500   [(set (match_dup 4) (plus:SI (match_dup 2) (match_dup 3)))
4501    (set (match_dup 0) (match_op_dup 5 [(match_dup 1) (match_dup 7)]))]
4503   operands[7] = gen_rtx_fmt_e (GET_CODE (operands[6]), GET_MODE (operands[6]),
4504                                replace_equiv_address (XEXP (operands[6], 0),
4505                                                       operands[4]));
4506   cris_order_for_addsi3 (operands, 2);
4509 ;; op(s|u).S1 [rx=rx+rz.S2],ry (swapped, plus or bound)
4511 (define_split
4512   [(parallel
4513     [(set (match_operand 0 "register_operand" "")
4514           (match_operator
4515             7 "cris_plus_or_bound_operator"
4516             [(match_operator
4517               6 "cris_extend_operator"
4518               [(mem (plus:SI
4519                      (mult:SI (match_operand:SI 2 "register_operand" "")
4520                               (match_operand:SI 3 "const_int_operand" ""))
4521                      (match_operand:SI 4 "register_operand" "")))])
4522              (match_operand 1 "register_operand" "")]))
4523      (set (match_operand:SI 5 "register_operand" "")
4524            (plus:SI (mult:SI (match_dup 2)
4525                              (match_dup 3))
4526                     (match_dup 4)))])]
4527   "REG_P (operands[4]) && REG_P (operands[5])
4528    && REGNO (operands[5]) == REGNO (operands[4])"
4529   [(set (match_dup 5) (plus:SI (mult:SI (match_dup 2) (match_dup 3))
4530                                (match_dup 4)))
4531    (set (match_dup 0) (match_op_dup 6 [(match_dup 8) (match_dup 1)]))]
4532   "operands[8] = gen_rtx_fmt_e (GET_CODE (operands[6]), GET_MODE (operands[6]),
4533                                 replace_equiv_address (XEXP (operands[6], 0),
4534                                                        operands[5]));")
4536 ;; op(s|u).S1 [rx=rx+i],ry (swapped, plus or bound)
4538 (define_split
4539   [(parallel
4540     [(set (match_operand 0 "register_operand" "")
4541           (match_operator
4542             6 "cris_plus_or_bound_operator"
4543             [(match_operator
4544               5 "cris_extend_operator"
4545              [(mem (plus:SI
4546                     (match_operand:SI 2 "cris_bdap_operand" "")
4547                     (match_operand:SI 3 "cris_bdap_operand" "")))])
4548              (match_operand 1 "register_operand" "")]))
4549      (set (match_operand:SI 4 "register_operand" "")
4550            (plus:SI (match_dup 2)
4551                     (match_dup 3)))])]
4552   "(rtx_equal_p (operands[4], operands[2])
4553     || rtx_equal_p (operands[4], operands[3]))"
4554   [(set (match_dup 4) (plus:SI (match_dup 2) (match_dup 3)))
4555    (set (match_dup 0) (match_op_dup 6 [(match_dup 7) (match_dup 1)]))]
4557   operands[7] = gen_rtx_fmt_e (GET_CODE (operands[5]), GET_MODE (operands[5]),
4558                                replace_equiv_address (XEXP (operands[5], 0),
4559                                                       operands[4]));
4560   cris_order_for_addsi3 (operands, 2);
4563 ;; Splits for addressing prefixes that have no side-effects, so we can
4564 ;; fill a delay slot.  Never split if we lose something, though.
4566 ;; If we have a
4567 ;;  move [indirect_ref],rx
4568 ;; where indirect ref = {const, [r+], [r]}, it costs as much as
4569 ;;  move indirect_ref,rx
4570 ;;  move [rx],rx
4571 ;; Take care not to allow indirect_ref = register.
4573 ;; We're not allowed to generate copies of registers with different mode
4574 ;; until after reload; copying pseudos upsets reload.  CVS as of
4575 ;; 2001-08-24, unwind-dw2-fde.c, _Unwind_Find_FDE ICE in
4576 ;; cselib_invalidate_regno.  Also, don't do this for the stack-pointer,
4577 ;; as we don't want it set temporarily to an invalid value.
4579 (define_split ; indir_to_reg_split
4580   [(set (match_operand 0 "cris_nonsp_register_operand" "")
4581         (match_operand 1 "indirect_operand" ""))]
4582   "reload_completed
4583    && REG_P (operands[0])
4584    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
4585    && (MEM_P (XEXP (operands[1], 0)) || CONSTANT_P (XEXP (operands[1], 0)))
4586    && REGNO (operands[0]) < CRIS_LAST_GENERAL_REGISTER"
4587   [(set (match_dup 2) (match_dup 4))
4588    (set (match_dup 0) (match_dup 3))]
4589   "operands[2] = gen_rtx_REG (Pmode, REGNO (operands[0]));
4590    operands[3] = replace_equiv_address (operands[1], operands[2]);
4591    operands[4] = XEXP (operands[1], 0);")
4593 ;; As the above, but MOVS and MOVU.
4595 (define_split
4596   [(set (match_operand 0 "cris_nonsp_register_operand" "")
4597         (match_operator
4598          4 "cris_extend_operator"
4599          [(match_operand 1 "indirect_operand" "")]))]
4600   "reload_completed
4601    && REG_P (operands[0])
4602    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
4603    && (MEM_P (XEXP (operands[1], 0))
4604        || CONSTANT_P (XEXP (operands[1], 0)))"
4605   [(set (match_dup 2) (match_dup 5))
4606    (set (match_dup 0) (match_op_dup 4 [(match_dup 3)]))]
4607   "operands[2] = gen_rtx_REG (Pmode, REGNO (operands[0]));
4608    operands[3] = replace_equiv_address (XEXP (operands[4], 0), operands[2]);
4609    operands[5] = XEXP (operands[1], 0);")
4611 ;; Various peephole optimizations.
4613 ;; Watch out: when you exchange one set of instructions for another, the
4614 ;; condition codes setting must be the same, or you have to CC_INIT or
4615 ;; whatever is appropriate, in the pattern before you emit the
4616 ;; assembly text.  This is best done here, not in cris_notice_update_cc,
4617 ;; to keep changes local to their cause.
4619 ;; Do not add patterns that you do not know will be matched.
4620 ;; Please also add a self-contained testcase.
4622 ;; We have trouble with and:s and shifts.  Maybe something is broken in
4623 ;; gcc?  Or it could just be that bit-field insn expansion is a bit
4624 ;; suboptimal when not having extzv insns.
4625 ;; Testcase for the following four peepholes: gcc.dg/cris-peep2-xsrand.c
4627 (define_peephole2 ; asrandb (peephole casesi+31)
4628   [(set (match_operand:SI 0 "register_operand" "")
4629         (ashiftrt:SI (match_dup 0)
4630                      (match_operand:SI 1 "const_int_operand" "")))
4631    (set (match_dup 0)
4632         (and:SI (match_dup 0)
4633                 (match_operand 2 "const_int_operand" "")))]
4634   "INTVAL (operands[2]) > 31
4635    && INTVAL (operands[2]) < 255
4636    && INTVAL (operands[1]) > 23
4637    /* Check that the and-operation enables us to use logical-shift.  */
4638    && (INTVAL (operands[2])
4639           & ((HOST_WIDE_INT) -1 << (32 - INTVAL (operands[1])))) == 0"
4640   [(set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 1)))
4641    (set (match_dup 3) (and:QI (match_dup 3) (match_dup 4)))]
4642   ;; FIXME: CC0 is valid except for the M bit.
4644   operands[3] = gen_rtx_REG (QImode, REGNO (operands[0]));
4645   operands[4] = GEN_INT (trunc_int_for_mode (INTVAL (operands[2]), QImode));
4648 (define_peephole2 ; asrandw (peephole casesi+32)
4649   [(set (match_operand:SI 0 "register_operand" "")
4650         (ashiftrt:SI (match_dup 0)
4651                      (match_operand:SI 1 "const_int_operand" "")))
4652    (set (match_dup 0)
4653         (and:SI (match_dup 0) (match_operand 2 "const_int_operand" "")))]
4654   "INTVAL (operands[2]) > 31
4655    && INTVAL (operands[2]) < 65535
4656    && INTVAL (operands[2]) != 255
4657    && INTVAL (operands[1]) > 15
4658    /* Check that the and-operation enables us to use logical-shift.  */
4659    && (INTVAL (operands[2])
4660        & ((HOST_WIDE_INT) -1 << (32 - INTVAL (operands[1])))) == 0"
4661   [(set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 1)))
4662    (set (match_dup 3) (and:HI (match_dup 3) (match_dup 4)))]
4663   ;; FIXME: CC0 is valid except for the M bit.
4665   operands[3] = gen_rtx_REG (HImode, REGNO (operands[0]));
4666   operands[4] = GEN_INT (trunc_int_for_mode (INTVAL (operands[2]), HImode));
4669 (define_peephole2 ; lsrandb (peephole casesi+33)
4670   [(set (match_operand:SI 0 "register_operand" "")
4671         (lshiftrt:SI (match_dup 0)
4672                      (match_operand:SI 1 "const_int_operand" "")))
4673    (set (match_dup 0)
4674         (and:SI (match_dup 0) (match_operand 2 "const_int_operand" "")))]
4675   "INTVAL (operands[2]) > 31
4676    && INTVAL (operands[2]) < 255
4677    && INTVAL (operands[1]) > 23"
4678   [(set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 1)))
4679    (set (match_dup 3) (and:QI (match_dup 3) (match_dup 4)))]
4680   ;; FIXME: CC0 is valid except for the M bit.
4682   operands[3] = gen_rtx_REG (QImode, REGNO (operands[0]));
4683   operands[4] = GEN_INT (trunc_int_for_mode (INTVAL (operands[2]), QImode));
4686 (define_peephole2 ; lsrandw (peephole casesi+34)
4687   [(set (match_operand:SI 0 "register_operand" "")
4688         (lshiftrt:SI (match_dup 0)
4689                      (match_operand:SI 1 "const_int_operand" "")))
4690    (set (match_dup 0)
4691         (and:SI (match_dup 0) (match_operand 2 "const_int_operand" "")))]
4692   "INTVAL (operands[2]) > 31 && INTVAL (operands[2]) < 65535
4693    && INTVAL (operands[2]) != 255
4694    && INTVAL (operands[1]) > 15"
4695   [(set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 1)))
4696    (set (match_dup 3) (and:HI (match_dup 3) (match_dup 4)))]
4697   ;; FIXME: CC0 is valid except for the M bit.
4699   operands[3] = gen_rtx_REG (HImode, REGNO (operands[0]));
4700   operands[4] = GEN_INT (trunc_int_for_mode (INTVAL (operands[2]), HImode));
4704 ;; Change
4705 ;;  add.d n,rx
4706 ;;  move [rx],ry
4707 ;; into
4708 ;;  move [rx=rx+n],ry
4709 ;; when -128 <= n <= 127.
4710 ;; This will reduce the size of the assembler code for n = [-128..127],
4711 ;; and speed up accordingly.  Don't match if the previous insn is
4712 ;; (set rx rz) because that combination is matched by another peephole.
4713 ;; No stable test-case.
4715 (define_peephole2 ; moversideqi (peephole casesi+35)
4716   [(set (match_operand:SI 0 "register_operand" "")
4717         (plus:SI (match_operand:SI 1 "register_operand" "")
4718                  (match_operand:SI 2 "const_int_operand" "")))
4719    (set (match_operand 3 "register_operand" "")
4720         (match_operator 4 "cris_mem_op" [(match_dup 0)]))]
4721   "GET_MODE_SIZE (GET_MODE (operands[4])) <= UNITS_PER_WORD
4722    && REGNO (operands[3]) != REGNO (operands[0])
4723    && (cris_base_p (operands[1], true) || cris_base_p (operands[2], true))
4724    && !satisfies_constraint_J (operands[2])
4725    && !satisfies_constraint_N (operands[2])
4726    && (INTVAL (operands[2]) >= -128 && INTVAL (operands[2]) < 128)
4727    && TARGET_SIDE_EFFECT_PREFIXES"
4728   [(parallel
4729     [(set (match_dup 3) (match_dup 5))
4730      (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))])]
4731   ;; Checking the previous insn is a bit too awkward for the condition.
4733   rtx_insn *prev = prev_nonnote_insn (curr_insn);
4734   if (prev != NULL_RTX)
4735     {
4736       rtx set = single_set (prev);
4737       if (set != NULL_RTX
4738           && REG_S_P (SET_DEST (set))
4739           && REGNO (SET_DEST (set)) == REGNO (operands[0])
4740           && REG_S_P (SET_SRC (set)))
4741         FAIL;
4742     }
4743   operands[5]
4744     = replace_equiv_address (operands[4],
4745                              gen_rtx_PLUS (SImode,
4746                                            operands[1], operands[2]));
4749 ;; Vice versa: move ry,[rx=rx+n]
4751 (define_peephole2 ; movemsideqi (peephole casesi+36)
4752   [(set (match_operand:SI 0 "register_operand" "")
4753         (plus:SI (match_operand:SI 1 "register_operand" "")
4754                  (match_operand:SI 2 "const_int_operand" "")))
4755    (set (match_operator 3 "cris_mem_op" [(match_dup 0)])
4756         (match_operand 4 "register_operand" ""))]
4757   "GET_MODE_SIZE (GET_MODE (operands[4])) <= UNITS_PER_WORD
4758    && REGNO (operands[4]) != REGNO (operands[0])
4759    && (cris_base_p (operands[1], true) || cris_base_p (operands[2], true))
4760    && !satisfies_constraint_J (operands[2])
4761    && !satisfies_constraint_N (operands[2])
4762    && (INTVAL (operands[2]) >= -128 && INTVAL (operands[2]) < 128)
4763    && TARGET_SIDE_EFFECT_PREFIXES"
4764   [(parallel
4765     [(set (match_dup 5) (match_dup 4))
4766      (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))])]
4767   "operands[5]
4768      = replace_equiv_address (operands[3],
4769                               gen_rtx_PLUS (SImode,
4770                                             operands[1], operands[2]));")
4772 ;; As above, change:
4773 ;;  add.d n,rx
4774 ;;  op.d [rx],ry
4775 ;; into:
4776 ;;  op.d [rx=rx+n],ry
4777 ;; Saves when n = [-128..127].
4779 ;; Splitting and joining combinations for side-effect modes are slightly
4780 ;; out of hand.  They probably will not save the time they take typing in,
4781 ;; not to mention the bugs that creep in.  FIXME: Get rid of as many of
4782 ;; the splits and peepholes as possible.
4783 ;; No stable test-case.
4785 (define_peephole2 ; mover2side (peephole casesi+37)
4786   [(set (match_operand:SI 0 "register_operand" "")
4787         (plus:SI (match_operand:SI 1 "register_operand" "")
4788                  (match_operand:SI 2 "const_int_operand" "")))
4789    (set (match_operand 3 "register_operand" "")
4790           (match_operator 4 "cris_orthogonal_operator"
4791                           [(match_dup 3)
4792                            (match_operator
4793                             5 "cris_mem_op" [(match_dup 0)])]))]
4794   ;; FIXME: What about DFmode?
4795   ;; Change to GET_MODE_SIZE (GET_MODE (operands[3])) <= UNITS_PER_WORD?
4796   "GET_MODE (operands[3]) != DImode
4797    && REGNO (operands[0]) != REGNO (operands[3])
4798    && !satisfies_constraint_J (operands[2])
4799    && !satisfies_constraint_N (operands[2])
4800    && INTVAL (operands[2]) >= -128
4801    && INTVAL (operands[2]) <= 127
4802    && TARGET_SIDE_EFFECT_PREFIXES"
4803   [(parallel
4804     [(set (match_dup 3) (match_op_dup 4 [(match_dup 3) (match_dup 6)]))
4805      (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))])]
4806   "operands[6]
4807      = replace_equiv_address (operands[5],
4808                               gen_rtx_PLUS (SImode,
4809                                             operands[1], operands[2]));")
4811 ;; Sometimes, for some reason the pattern
4812 ;;  move x,rx
4813 ;;  add y,rx
4814 ;;  move [rx],rz
4815 ;; will occur.  Solve this, and likewise for to-memory.
4816 ;; No stable test-case.
4818 (define_peephole2 ; moverside (peephole casesi+38)
4819   [(set (match_operand:SI 0 "register_operand" "")
4820         (match_operand:SI 1 "cris_bdap_biap_operand" ""))
4821    (set (match_dup 0)
4822         (plus:SI (match_operand:SI 2 "cris_bdap_biap_operand" "")
4823                  (match_operand:SI 3 "cris_bdap_biap_operand" "")))
4824    (set (match_operand 4 "register_operand" "")
4825         (match_operator 5 "cris_mem_op" [(match_dup 0)]))]
4826   "(rtx_equal_p (operands[2], operands[0])
4827     || rtx_equal_p (operands[3], operands[0]))
4828    && cris_side_effect_mode_ok (PLUS, operands, 0,
4829                                 (REG_S_P (operands[1])
4830                                  ? 1
4831                                  : (rtx_equal_p (operands[2], operands[0])
4832                                     ? 3 : 2)),
4833                                 (! REG_S_P (operands[1])
4834                                  ? 1
4835                                  : (rtx_equal_p (operands[2], operands[0])
4836                                     ? 3 : 2)),
4837                                 -1, 4)"
4838   [(parallel
4839     [(set (match_dup 4) (match_dup 6))
4840      (set (match_dup 0) (plus:SI (match_dup 7) (match_dup 8)))])]
4842   rtx otherop
4843     = rtx_equal_p (operands[2], operands[0]) ? operands[3] : operands[2];
4845   /* Make sure we have canonical RTX so we match the insn pattern -
4846      not a constant in the first operand.  We also require the order
4847      (plus reg mem) to match the final pattern.  */
4848   if (CRIS_CONSTANT_P (otherop) || MEM_P (otherop))
4849     {
4850       operands[7] = operands[1];
4851       operands[8] = otherop;
4852     }
4853   else
4854     {
4855       operands[7] = otherop;
4856       operands[8] = operands[1];
4857     }
4858   operands[6]
4859     = replace_equiv_address (operands[5],
4860                              gen_rtx_PLUS (SImode,
4861                                            operands[7], operands[8]));
4864 ;; As above but to memory.
4865 ;; FIXME: Split movemside and moverside into variants and prune
4866 ;; the ones that don't trig.
4867 ;; No stable test-case.
4869 (define_peephole2 ; movemside (peephole casesi+39)
4870   [(set (match_operand:SI 0 "register_operand" "")
4871         (match_operand:SI 1 "cris_bdap_biap_operand" ""))
4872    (set (match_dup 0)
4873         (plus:SI (match_operand:SI 2 "cris_bdap_biap_operand" "")
4874                  (match_operand:SI 3 "cris_bdap_biap_operand" "")))
4875    (set (match_operator 4 "cris_mem_op" [(match_dup 0)])
4876         (match_operand 5 "register_operand" ""))]
4877   "(rtx_equal_p (operands[2], operands[0])
4878     || rtx_equal_p (operands[3], operands[0]))
4879    && cris_side_effect_mode_ok (PLUS, operands, 0,
4880                                 (REG_S_P (operands[1])
4881                                  ? 1
4882                                  : (rtx_equal_p (operands[2], operands[0])
4883                                     ? 3 : 2)),
4884                                 (! REG_S_P (operands[1])
4885                                    ? 1
4886                                  : (rtx_equal_p (operands[2], operands[0])
4887                                     ? 3 : 2)),
4888                                 -1, 5)"
4889   [(parallel
4890     [(set (match_dup 6) (match_dup 5))
4891      (set (match_dup 0) (plus:SI (match_dup 7) (match_dup 8)))])]
4893   rtx otherop
4894     = rtx_equal_p (operands[2], operands[0]) ? operands[3] : operands[2];
4896   /* Make sure we have canonical RTX so we match the insn pattern -
4897      not a constant in the first operand.  We also require the order
4898      (plus reg mem) to match the final pattern.  */
4899   if (CRIS_CONSTANT_P (otherop) || MEM_P (otherop))
4900     {
4901       operands[7] = operands[1];
4902       operands[8] = otherop;
4903     }
4904   else
4905     {
4906       operands[7] = otherop;
4907       operands[8] = operands[1];
4908     }
4909   operands[6]
4910     = replace_equiv_address (operands[4],
4911                              gen_rtx_PLUS (SImode,
4912                                            operands[7], operands[8]));
4915 ;; Another spotted bad code:
4916 ;;   move rx,ry
4917 ;;   move [ry],ry
4918 ;; No stable test-case.
4920 (define_peephole2 ; movei (peephole casesi+42)
4921   [(set (match_operand:SI 0 "register_operand" "")
4922         (match_operand:SI 1 "register_operand" ""))
4923    (set (match_operand 2 "register_operand" "")
4924         (match_operator 3 "cris_mem_op" [(match_dup 0)]))]
4925   "REGNO (operands[0]) == REGNO (operands[2])
4926    && (REGNO_REG_CLASS (REGNO (operands[0]))
4927        == REGNO_REG_CLASS (REGNO (operands[1])))
4928    && GET_MODE_SIZE (GET_MODE (operands[2])) <= UNITS_PER_WORD"
4929   [(set (match_dup 2) (match_dup 4))]
4930   "operands[4] = replace_equiv_address (operands[3], operands[1]);")
4932 ;;   move.d [r10+16],r9
4933 ;;   and.d r12,r9
4934 ;; change to
4935 ;;   and.d [r10+16],r12,r9
4936 ;; With generalization of the operation, the size and the addressing mode.
4937 ;;  This seems to be the result of a quirk in register allocation
4938 ;; missing the three-operand cases when having different predicates.
4939 ;; Maybe that it matters that it is a commutative operation.
4940 ;;  This pattern helps that situation, but there's still the increased
4941 ;; register pressure.
4942 ;;  Note that adding the noncommutative variant did not show any matches
4943 ;; in ipps and cc1, so it's not here.
4944 ;; No stable test-case.
4946 (define_peephole2 ; op3 (peephole casesi+44)
4947   [(set (match_operand 0 "register_operand" "")
4948         (match_operator
4949          6 "cris_mem_op"
4950          [(plus:SI
4951            (match_operand:SI 1 "cris_bdap_biap_operand" "")
4952            (match_operand:SI 2 "cris_bdap_biap_operand" ""))]))
4953    (set (match_dup 0)
4954         (match_operator
4955          5 "cris_commutative_orth_op"
4956          [(match_operand 3 "register_operand" "")
4957           (match_operand 4 "register_operand" "")]))]
4958   "(rtx_equal_p (operands[3], operands[0])
4959     || rtx_equal_p (operands[4], operands[0]))
4960    && ! rtx_equal_p (operands[3], operands[4])
4961    && (REG_S_P (operands[1]) || REG_S_P (operands[2]))
4962    && GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD"
4963   [(set (match_dup 0) (match_op_dup 5 [(match_dup 7) (match_dup 6)]))]
4964   "operands[7]
4965      = rtx_equal_p (operands[3], operands[0]) ? operands[4] : operands[3];")
4967 ;; There seems to be no other way to make GCC (including 4.8/trunk at
4968 ;; r186932) optimally reload an instruction that looks like
4969 ;;   and.d reg_or_mem,const_32__65535,other_reg
4970 ;; where other_reg is the destination.
4971 ;; It should be:
4972 ;;   movu.[bw] reg_or_mem,reg_32
4973 ;;   and.[bw] trunc_int_for_mode([bw], const_32__65535),reg_32 ;; or andq
4974 ;; but it turns into:
4975 ;;   move.d reg_or_mem,reg_32
4976 ;;   and.d const_32__65535,reg_32
4977 ;; Fix it with these two peephole2's.
4978 ;; Testcases: gcc.dg/cris-peep2-andu1.c gcc.dg/cris-peep2-andu2.c
4980 (define_peephole2 ; andu (casesi+45)
4981   [(set (match_operand:SI 0 "register_operand" "")
4982         (match_operand:SI 1 "nonimmediate_operand" ""))
4983    (set (match_operand:SI 2 "register_operand" "")
4984         (and:SI (match_dup 0)
4985                 (match_operand:SI 3 "const_int_operand" "")))]
4986    ;; Since the size of the memory access could be made different here,
4987    ;; don't do this for a mem-volatile access.
4988   "REGNO (operands[2]) == REGNO (operands[0])
4989    && INTVAL (operands[3]) <= 65535 && INTVAL (operands[3]) >= 0
4990    && !satisfies_constraint_I (operands[3])
4991    && !side_effects_p (operands[1])
4992    && (!REG_P (operands[1])
4993        || REGNO (operands[1]) <= CRIS_LAST_GENERAL_REGISTER)"
4994   ;; FIXME: CC0 valid except for M (i.e. CC_NOT_NEGATIVE).
4995   [(set (match_dup 0) (match_dup 4))
4996    (set (match_dup 5) (match_dup 6))]
4998   machine_mode zmode = INTVAL (operands[3]) <= 255 ? QImode : HImode;
4999   machine_mode amode
5000     = satisfies_constraint_O (operands[3]) ? SImode : zmode;
5001   rtx op1
5002     = (REG_S_P (operands[1])
5003        ? gen_rtx_REG (zmode, REGNO (operands[1]))
5004        : adjust_address (operands[1], zmode, 0));
5005   operands[4]
5006     = gen_rtx_ZERO_EXTEND (SImode, op1);
5007   operands[5] = gen_rtx_REG (amode, REGNO (operands[0]));
5008   operands[6]
5009     = gen_rtx_AND (amode, gen_rtx_REG (amode, REGNO (operands[0])),
5010                    GEN_INT (trunc_int_for_mode (INTVAL (operands[3]),
5011                                                 amode == SImode
5012                                                 ? QImode : amode)));
5015 ;; Since r186861, gcc.dg/cris-peep2-andu2.c trigs this pattern, with which
5016 ;; we fix up e.g.:
5017 ;;  movu.b 254,$r9.
5018 ;;  and.d $r10,$r9
5019 ;; into:
5020 ;;  movu.b $r10,$r9
5021 ;;  andq -2,$r9.
5022 ;; Only do this for values fitting the quick immediate operand.
5023 (define_peephole2 ; andqu (casesi+46)
5024   [(set (match_operand:SI 0 "register_operand")
5025         (match_operand:SI 1 "const_int_operand"))
5026    (set (match_dup 0)
5027         (and:SI (match_dup 0) (match_operand:SI 2 "nonimmediate_operand")))]
5028    ;; Since the size of the memory access will be made different here,
5029    ;; don't do this for a volatile access or a post-incremented address.
5030   "satisfies_constraint_O (operands[1])
5031    && !side_effects_p (operands[2])
5032    && !reg_overlap_mentioned_p (operands[0], operands[2])"
5033   [(set (match_dup 0) (match_dup 3))
5034    (set (match_dup 0) (and:SI (match_dup 0) (match_dup 4)))]
5036   machine_mode zmode = INTVAL (operands[2]) <= 255 ? QImode : HImode;
5037   rtx op1
5038     = (REG_S_P (operands[2])
5039        ? gen_rtx_REG (zmode, REGNO (operands[2]))
5040        : adjust_address (operands[2], zmode, 0));
5041   operands[3] = gen_rtx_ZERO_EXTEND (SImode, op1);
5042   operands[4] = GEN_INT (trunc_int_for_mode (INTVAL (operands[1]), QImode));
5045 ;; Try and avoid GOTPLT reads escaping a call: transform them into
5046 ;; PLT.  Curiously (but thankfully), peepholes for instructions
5047 ;; *without side-effects* that just feed a call (or call_value) are
5048 ;; not matched neither in a build or test-suite, so those patterns are
5049 ;; omitted.
5051 ;; A "normal" move where we don't check the consumer.
5053 (define_peephole2 ; gotplt-to-plt
5054   [(set
5055     (match_operand:SI 0 "register_operand" "")
5056     (match_operator:SI
5057      1 "cris_mem_op"
5058      [(plus:SI
5059        (reg:SI CRIS_GOT_REGNUM)
5060        (const:SI
5061         (unspec:SI [(match_operand:SI 2 "cris_general_operand_or_symbol" "")]
5062                    CRIS_UNSPEC_PLTGOTREAD)))]))]
5063   "flag_pic
5064    && cris_valid_pic_const (XEXP (XEXP (operands[1], 0), 1), true)
5065    && REGNO_REG_CLASS (REGNO (operands[0])) == REGNO_REG_CLASS (0)"
5066   [(set (match_dup 0) (const:SI (unspec:SI [(match_dup 2)] CRIS_UNSPEC_PLT_GOTREL)))
5067    (set (match_dup 0) (plus:SI (match_dup 0) (reg:SI CRIS_GOT_REGNUM)))]
5068   "")
5070 ;; And one set with a side-effect getting the PLTGOT offset.
5071 ;; First call and call_value variants.
5073 (define_peephole2 ; gotplt-to-plt-side-call
5074   [(parallel
5075     [(set
5076       (match_operand:SI 0 "register_operand" "")
5077       (match_operator:SI
5078        1 "cris_mem_op"
5079        [(plus:SI
5080          (reg:SI CRIS_GOT_REGNUM)
5081          (const:SI
5082           (unspec:SI [(match_operand:SI
5083                        2 "cris_general_operand_or_symbol" "")]
5084                      CRIS_UNSPEC_PLTGOTREAD)))]))
5085      (set (match_operand:SI 3 "register_operand" "")
5086           (plus:SI (reg:SI CRIS_GOT_REGNUM)
5087                    (const:SI
5088                     (unspec:SI [(match_dup 2)] CRIS_UNSPEC_PLTGOTREAD))))])
5089   (parallel [(call (mem:QI (match_dup 0))
5090                     (match_operand 4 "" ""))
5091               (clobber (reg:SI CRIS_SRP_REGNUM))])]
5092   "flag_pic
5093    && cris_valid_pic_const (XEXP (XEXP (operands[1], 0), 1), true)
5094    && peep2_reg_dead_p (2, operands[0])"
5095   [(parallel [(call (mem:QI (match_dup 1))
5096                     (match_dup 4))
5097               (clobber (reg:SI CRIS_SRP_REGNUM))
5098               (set (match_dup 3)
5099                    (plus:SI (reg:SI CRIS_GOT_REGNUM)
5100                             (const:SI
5101                              (unspec:SI [(match_dup 2)]
5102                                         CRIS_UNSPEC_PLTGOTREAD))))])]
5103   "")
5105 (define_peephole2 ; gotplt-to-plt-side-call-value
5106   [(parallel
5107     [(set
5108       (match_operand:SI 0 "register_operand" "")
5109       (match_operator:SI
5110        1 "cris_mem_op"
5111        [(plus:SI
5112          (reg:SI CRIS_GOT_REGNUM)
5113          (const:SI
5114           (unspec:SI [(match_operand:SI
5115                        2 "cris_general_operand_or_symbol" "")]
5116                      CRIS_UNSPEC_PLTGOTREAD)))]))
5117      (set (match_operand:SI 3 "register_operand" "")
5118           (plus:SI (reg:SI CRIS_GOT_REGNUM)
5119                    (const:SI
5120                     (unspec:SI [(match_dup 2)] CRIS_UNSPEC_PLTGOTREAD))))])
5121    (parallel [(set (match_operand 5 "" "")
5122                    (call (mem:QI (match_dup 0))
5123                          (match_operand 4 "" "")))
5124               (clobber (reg:SI CRIS_SRP_REGNUM))])]
5125   "flag_pic
5126    && cris_valid_pic_const (XEXP (XEXP (operands[1], 0), 1), true)
5127    && peep2_reg_dead_p (2, operands[0])"
5128   [(parallel [(set (match_dup 5)
5129                    (call (mem:QI (match_dup 1))
5130                          (match_dup 4)))
5131               (clobber (reg:SI CRIS_SRP_REGNUM))
5132               (set (match_dup 3)
5133                    (plus:SI (reg:SI CRIS_GOT_REGNUM)
5134                             (const:SI
5135                              (unspec:SI [(match_dup 2)]
5136                                         CRIS_UNSPEC_PLTGOTREAD))))])]
5137   "")
5139 (define_peephole2 ; gotplt-to-plt-side
5140   [(parallel
5141     [(set
5142       (match_operand:SI 0 "register_operand" "")
5143       (match_operator:SI
5144        1 "cris_mem_op"
5145        [(plus:SI
5146          (reg:SI CRIS_GOT_REGNUM)
5147          (const:SI
5148           (unspec:SI [(match_operand:SI
5149                        2 "cris_general_operand_or_symbol" "")]
5150                      CRIS_UNSPEC_PLTGOTREAD)))]))
5151      (set (match_operand:SI 3 "register_operand" "")
5152           (plus:SI (reg:SI CRIS_GOT_REGNUM)
5153                    (const:SI
5154                     (unspec:SI [(match_dup 2)] CRIS_UNSPEC_PLTGOTREAD))))])]
5155   "flag_pic
5156    && cris_valid_pic_const (XEXP (XEXP (operands[1], 0), 1), true)
5157    && REGNO_REG_CLASS (REGNO (operands[0])) == REGNO_REG_CLASS (0)"
5158   [(set (match_dup 3)
5159         (const:SI (unspec:SI [(match_dup 2)] CRIS_UNSPEC_PLTGOTREAD)))
5160    (set (match_dup 3) (plus:SI (match_dup 3) (reg:SI CRIS_GOT_REGNUM)))
5161    (set (match_dup 0)
5162         (const:SI (unspec:SI [(match_dup 2)] CRIS_UNSPEC_PLT_GOTREL)))
5163    (set (match_dup 0) (plus:SI (match_dup 0) (reg:SI CRIS_GOT_REGNUM)))]
5164   "")
5166 ;; Local variables:
5167 ;; mode:emacs-lisp
5168 ;; comment-start: ";; "
5169 ;; eval: (set-syntax-table (copy-sequence (syntax-table)))
5170 ;; eval: (modify-syntax-entry ?[ "(]")
5171 ;; eval: (modify-syntax-entry ?] ")[")
5172 ;; eval: (modify-syntax-entry ?{ "(}")
5173 ;; eval: (modify-syntax-entry ?} "){")
5174 ;; eval: (setq indent-tabs-mode t)
5175 ;; End: