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