1 ;; GCC machine description for CRIS cpu cores.
2 ;; Copyright (C) 1998-2024 Free Software Foundation, Inc.
3 ;; Contributed by Axis Communications.
5 ;; This file is part of GCC.
7 ;; GCC is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3, or (at your option)
12 ;; GCC is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3. If not see
19 ;; <http://www.gnu.org/licenses/>.
21 ;; The original PO technology requires these to be ordered by speed,
22 ;; so that assigner will pick the fastest.
24 ;; See files "md.texi" and "rtl.def" for documentation on define_insn,
27 ;; There are several instructions that are orthogonal in size, and seems
28 ;; they could be matched by a single pattern without a specified size
29 ;; for the operand that is orthogonal. However, this did not work on
30 ;; gcc-2.7.2 (and probably not on gcc-2.8.1), relating to that when a
31 ;; constant is substituted into an operand, the actual mode must be
32 ;; deduced from the pattern. There is reasonable hope that that has been
33 ;; fixed, so FIXME: try again.
35 ;; You will notice that three-operand alternatives ("=r", "r", "!To")
36 ;; are marked with a "!" constraint modifier to avoid being reloaded
37 ;; into. This is because gcc would otherwise prefer to use the constant
38 ;; pool and its offsettable address instead of reloading to an
39 ;; ("=r", "0", "i") alternative. Also, the constant-pool support was not
40 ;; only suboptimal but also buggy in 2.7.2, ??? maybe only in 2.6.3.
42 ;; All insns that look like (set (...) (plus (...) (reg:SI 8)))
43 ;; get problems when reloading r8 (frame pointer) to r14 + offs (stack
44 ;; pointer). Thus the instructions that get into trouble have specific
45 ;; checks against matching frame_pointer_rtx.
46 ;; ??? But it should be re-checked for gcc > 2.7.2
47 ;; FIXME: This changed some time ago (from 2000-03-16) for gcc-2.9x.
51 ;; Stack frame deallocation barrier.
52 CRIS_UNSPEC_FRAME_DEALLOC
57 [(CRIS_STATIC_CHAIN_REGNUM 7)
58 (CRIS_REAL_FP_REGNUM 8)
67 ;; We need an attribute to define whether an instruction can be put in
68 ;; a branch-delay slot or not, and whether it has a delay slot.
70 ;; Branches and return instructions have a delay slot, and cannot
71 ;; themselves be put in a delay slot. This has changed *for short
72 ;; branches only* between architecture variants, but the possible win
73 ;; is presumed negligible compared to the added complexity of the machine
74 ;; description: one would have to add always-correct infrastructure to
75 ;; distinguish short branches.
77 ;; Whether an instruction can be put in a delay slot depends on the
78 ;; instruction (all short instructions except jumps and branches)
79 ;; and the addressing mode (must not be prefixed or referring to pc).
80 ;; In short, any "slottable" instruction must be 16 bit and not refer
81 ;; to pc, or alter it.
83 ;; The possible values are "yes", "no", "has_slot", and "has_return_slot".
84 ;; Yes/no tells whether the insn is slottable or not.
85 ;; Of special concern is that no RTX_FRAME_RELATED insn must go in that
86 ;; call delay slot, as it's located in the address *after* the call insn,
87 ;; and the unwind machinery doesn't know about delay slots.
88 ;; Has_slot means that the insn is a branch insn (which are
89 ;; not considered slottable since that is generally true). Having the
90 ;; seemingly illogical value "has_slot" means we do not have to add
91 ;; another attribute just to say that an insn has a delay-slot, since it
92 ;; also infers that it is not slottable. Better names for the attribute
93 ;; were found to be longer and not add readability to the machine
95 ;; Has_return_slot is similar, for the return insn.
97 ;; The default that is defined here for this attribute is "no", not
98 ;; slottable, not having a delay-slot, so there's no need to worry about
99 ;; it being wrong for non-branch and return instructions.
100 ;; The default could depend on the kind of insn and the addressing
101 ;; mode, but that would need more attributes and hairier, more error
104 ;; There is an extra memory constraint, 'Q', which recognizes an indirect
105 ;; register. The constraints 'Q' and '>' together match all possible
106 ;; memory operands that are slottable.
107 ;; For other operands, you need to check if it has a valid "slottable"
108 ;; quick-immediate operand, where the particular signedness-variation
109 ;; may match the constraints 'I' or 'J'.), and include it in the
110 ;; constraint pattern for the slottable pattern. An alternative using
111 ;; only "r" constraints is most often slottable.
113 (define_attr "slottable" "no,yes,has_slot,has_return_slot"
116 ;; We also need attributes to sanely determine the condition code
117 ;; state. This attribute isn't used as-is, just as a template,
118 ;; effectively a dummy except in a substitution setting CRIS_CC0_REGNUM
119 ;; to a specific value.
120 (define_attr "cc" "none,clobber,normal" (const_string "normal"))
122 ;; The attribute "_enabled" is appended to "cc", forming "cc_enabled" to
123 ;; pick out certain alternatives when generating a useful
124 ;; condition-code-setting. See the "enabled" attribute.
125 (define_attr "cc_enabled" "none,clobber,normal" (const_string "normal"))
127 ;; At the moment, this attribute is just used to help bb-reorder do its
128 ;; work; the default 0 doesn't help it. Many insns have other lengths,
129 ;; though none are shorter.
130 (define_attr "length" "" (const_int 2))
132 ;; A branch has one delay-slot. The instruction in the
133 ;; delay-slot is always executed, independent of whether the branch is
134 ;; taken or not. Note that besides setting "slottable" to "has_slot",
135 ;; there also has to be a "%#" at the end of a "delayed" instruction
136 ;; output pattern (for "jump" this means "ba %l0%#"), so print_operand can
137 ;; catch it and print a "nop" if necessary. This method was stolen from
140 (define_delay (eq_attr "slottable" "has_slot")
141 [(eq_attr "slottable" "yes") (nil) (nil)])
143 ;; The insn in the return insn slot must not be the
144 ;; return-address-register restore. FIXME: Use has_slot and express
145 ;; as a parallel with a use of the return-address-register (currently
146 ;; only SRP). However, this requires an amount of fixing tests for
147 ;; naked RETURN in middle-end.
148 (define_delay (eq_attr "slottable" "has_return_slot")
149 [(and (eq_attr "slottable" "yes")
150 (not (match_test "dead_or_set_regno_p (insn, CRIS_SRP_REGNUM)")))
153 ;; Enable choosing particular instructions. The discriminator choice
154 ;; "v0" stands for "pre-v10", for brevity.
155 (define_attr "cpu_variant" "default,v0,v10" (const_string "default"))
157 (define_attr "enabled" "no,yes"
160 (eq_attr "cc_enabled" "normal")
162 (eq_attr "cpu_variant" "default")
163 (and (eq_attr "cpu_variant" "v10")
164 (match_test "TARGET_HAS_MUL_INSNS"))
165 (and (eq_attr "cpu_variant" "v0")
166 (not (match_test "TARGET_HAS_MUL_INSNS")))))
168 (const_string "no")))
170 ;; Iterator definitions.
172 ;; For the "usual" pattern size alternatives.
173 (define_mode_iterator BWD [SI HI QI])
174 (define_mode_iterator BWDD [DI SI HI QI])
176 ;; To be able to refer to the same mode_attr for both a multi-mode
177 ;; and a mode-specific pattern, we use some singleton iterators.
178 (define_mode_iterator DI_ [DI])
179 (define_mode_iterator SI_ [SI])
181 (define_mode_iterator WD [SI HI])
182 (define_mode_iterator BW [HI QI])
184 ; Another "BW" for use where an independent iteration is needed.
185 (define_mode_iterator BW2 [HI QI])
187 (define_mode_attr S [(SI "HI") (HI "QI")])
188 (define_mode_attr s [(SI "hi") (HI "qi")])
189 (define_mode_attr m [(SI ".d") (HI ".w") (QI ".b")])
190 (define_mode_attr mm [(SI ".w") (HI ".b")])
191 (define_mode_attr nbitsm1 [(SI "31") (HI "15") (QI "7")])
193 ;; For the sign_extend+zero_extend variants.
194 (define_code_iterator szext [sign_extend zero_extend])
195 (define_code_attr u [(sign_extend "") (zero_extend "u")])
196 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
198 ;; For extended-operand variants.
199 (define_code_iterator plusminus [plus minus])
200 (define_code_attr addsub [(plus "add") (minus "sub")])
202 ;; Similar, other cases also matching bound/umin.
203 (define_code_iterator plusminusumin [plus minus umin])
205 ;; Ditto, commutative operators (i.e. not minus).
206 (define_code_iterator plusumin [plus umin])
209 (define_code_iterator splitop [and plus])
211 ;; The addsubbo and nd code-attributes form a hack. We need to output
212 ;; "addu.b", "subu.b" but "bound.b" (no "u"-suffix) which means we'd
213 ;; need to refer to one iterator from the next. But, that can't be
214 ;; done. Instead output the "u" for unsigned as the "u" in "bound",
215 ;; i.e. the mnemonic as three parts including the extend-letter, and
216 ;; with an empty third part for "add" and "sub".
217 (define_code_attr addsubbo [(plus "add") (minus "sub") (umin "bo")])
218 (define_code_attr nd [(plus "") (minus "") (umin "nd")])
220 ;; For the shift variants.
221 (define_code_iterator shift [ashiftrt lshiftrt ashift])
222 (define_code_iterator shiftrt [ashiftrt lshiftrt])
223 (define_code_attr shlr [(ashiftrt "ashr") (lshiftrt "lshr") (ashift "ashl")])
224 (define_code_attr slr [(ashiftrt "asr") (lshiftrt "lsr") (ashift "lsl")])
226 ;; Compares, branches, cbranch, cstore. Conditions gt and le are CC_NZVC.
227 ;; Others start out as CCmode and can degenerate to CC_NZmode.
228 ;; Incidental setters are either CC_NZVCmode or CC_NZmode. See also
230 (define_mode_iterator NZSET [CC_NZ])
231 (define_mode_iterator NZUSE [CC CC_NZ CC_NZVC])
232 (define_mode_iterator NZVCSET [CC CC_NZVC CC_NZ])
233 (define_mode_iterator NZVCUSE [CC_NZVC])
234 (define_mode_iterator ZnNNZSET [CC_ZnN CC_NZ])
235 (define_mode_iterator ZnNNZUSE [CC CC_ZnN CC_NZ CC_NZVC])
238 (define_code_iterator cond [eq ne gtu ltu geu leu gt le lt ge])
240 ;; Just equal and not equal.
241 (define_code_iterator zcond [eq ne])
243 ;; Conditions that look only at Z and/or N (or can do with that).
244 (define_code_iterator nzcond [eq ne gtu leu lt ge])
246 ;; The complement of nzcond within cond; conditions that look (also) on V
248 (define_code_iterator nzvccond [geu ltu gt le])
250 ;; Within nzcond, those that give different opcodes when operands are
251 ;; reversed or that can ignore V or C. Also, the complement of zcond
253 (define_code_iterator rnzcond [gtu leu lt ge])
255 ;; CRIS condition mnemonic.
256 (define_code_attr CC [(eq "eq") (ne "ne") (gt "gt") (gtu "hi") (lt "lt")
257 (ltu "lo") (ge "ge") (geu "hs") (le "le") (leu "ls")])
259 ;; CRIS reverse condition mnemonic.
260 (define_code_attr rCC [(eq "ne") (ne "eq") (gt "le") (gtu "ls") (lt "ge")
261 (ltu "hs") (ge "lt") (geu "lo") (le "gt") (leu "hi")])
263 ;; Mnemomic for the CRIS condition when V or C can be ignored.
264 (define_code_attr oCC [(lt "mi") (ge "pl") (gtu "eq") (ltu "ne")])
267 (define_code_attr roCC [(lt "pl") (ge "mi") (gtu "eq") (ltu "ne")])
269 ;; CC_Z_IN_NOT_N, a.k.a. CC_ZnNmode.
270 (define_code_attr znnCC [(eq "pl") (ne "mi")])
272 ;;; ...and the reverse
273 (define_code_attr rznnCC [(eq "mi") (ne "pl")])
275 ;; Required unoptimized CCmode, different for nzcond and nzvccond.
276 (define_code_attr xCC [(eq "CC") (ne "CC") (gtu "CC") (ltu "CC_NZVC")
277 (geu "CC_NZVC") (leu "CC") (lt "CC") (ge "CC")
278 (gt "CC_NZVC") (le "CC_NZVC")])
280 ;; Substitutions to describe condition-code settings.
282 (define_subst_attr "setnz" "setnz_subst" "" "_setnz")
283 (define_subst_attr "ccnz" "setnz_subst" "" "_enabled")
284 (define_subst_attr "anz" "setnz_subst" "" "*")
286 (define_subst "setnz_subst"
287 [(set (match_operand 0)
289 (clobber (reg:CC CRIS_CC0_REGNUM))]
291 [(set (reg:CC_NZ CRIS_CC0_REGNUM)
292 (compare:CC_NZ (match_dup 1) (const_int 0)))
293 (set (match_dup 0) (match_dup 1))])
295 (define_subst_attr "setnzvc" "setnzvc_subst" "" "_setnzvc")
296 (define_subst_attr "ccnzvc" "setnzvc_subst" "" "_enabled")
297 (define_subst_attr "anzvc" "setnzvc_subst" "" "*")
299 (define_subst "setnzvc_subst"
300 [(set (match_operand 0)
302 (clobber (reg:CC CRIS_CC0_REGNUM))]
304 [(set (reg:CC_NZVC CRIS_CC0_REGNUM)
305 (compare:CC_NZVC (match_dup 1) (const_int 0)))
306 (set (match_dup 0) (match_dup 1))])
308 (define_subst_attr "setcc" "setcc_subst" "" "_setcc")
309 (define_subst_attr "cccc" "setcc_subst" "" "_enabled")
310 (define_subst_attr "acc" "setcc_subst" "" "*")
312 (define_subst "setcc_subst"
313 [(set (match_operand 0)
315 (clobber (reg:CC CRIS_CC0_REGNUM))]
317 [(set (reg:CC CRIS_CC0_REGNUM)
318 (compare:CC (match_dup 1) (const_int 0)))
319 (set (match_dup 0) (match_dup 1))])
321 ;; Operand and operator predicates.
323 (include "predicates.md")
324 (include "constraints.md")
326 ;; It seems that the position of the sign-bit and the fact that 0.0 is
327 ;; all 0-bits would make "tstsf" a straight-forward implementation;
328 ;; either "test.d" it for positive/negative or "btstq 30,r" it for
331 ;; FIXME: Do that some time.
335 ;; These are used for compare insn, cbranch and cstore.
336 ;; FIXME: Port-local reversing of operands is not done. Still needed?
337 ;; (It shouldn't be; it should be done as part of register allocation.)
338 (define_mode_attr sCC_destc
339 [(DI "r, r,r,r,r,r,r") (SI "r,r, r, r,r,r") (HI "r, r, r,r") (QI "r, r, r,r")])
340 (define_mode_attr cmp_op0c
341 [(DI "rm,r,r,r,r,r,r") (SI "r,r, rQ>,r,r,m") (HI "r, rQ>,r,m") (QI "r, rQ>,r,m")])
342 (define_mode_attr cmp_op1c
343 [(DI "M,Kc,I,P,n,r,o") (SI "I,rQ>,M, P,g,M") (HI "rQ>,M, g,M") (QI "rQ>,M, g,M")])
345 ;; We could optimize the sizes of the immediate operands for various
346 ;; cases, but that is not worth it because of the very little usage of
347 ;; DImode for anything else but a structure/block-mode. Just do the
348 ;; obvious stuff for the straight-forward constraint letters.
350 (define_insn "*cmpdi<NZVCSET:mode>"
351 [(set (reg:NZVCSET CRIS_CC0_REGNUM)
353 (match_operand:DI_ 0 "nonimmediate_operand" "<cmp_op0c>")
354 (match_operand:DI_ 1 "general_operand" "<cmp_op1c>")))]
357 test.d %M0\;ax\;test.d %H0
358 cmpq %1,%M0\;ax\;cmpq 0,%H0
359 cmpq %1,%M0\;ax\;cmpq -1,%H0
360 cmp%e1.%z1 %1,%M0\;ax\;cmpq %H1,%H0
361 cmp.d %M1,%M0\;ax\;cmp.d %H1,%H0
362 cmp.d %M1,%M0\;ax\;cmp.d %H1,%H0
363 cmp.d %M1,%M0\;ax\;cmp.d %H1,%H0")
365 ;; Note that compare insns with side effect addressing mode (e.g.):
367 ;; cmp.S [rx=ry+i],rz;
368 ;; cmp.S [%3=%1+%2],%0
370 ;; are *not* usable for gcc since the reloader *does not accept*
371 ;; cc0-changing insns with side-effects other than setting the condition
372 ;; codes. The reason is that the reload stage *may* cause another insn to
373 ;; be output after the main instruction, in turn invalidating cc0 for the
374 ;; insn using the test. (This does not apply to the CRIS case, since a
375 ;; reload for output -- move to memory -- does not change the condition
376 ;; code. Unfortunately we have no way to describe that at the moment. I
377 ;; think code would improve being in the order of one percent faster.
379 ;; We have cmps and cmpu (compare reg w. sign/zero extended mem).
380 ;; These are mostly useful for compares in SImode, using 8 or 16-bit
381 ;; constants, but sometimes gcc will find its way to use it for other
382 ;; (memory) operands. Avoid side-effect patterns, though (see above).
384 (define_insn "*cmp_ext<BW:mode><NZVCSET:mode>"
385 [(set (reg:NZVCSET CRIS_CC0_REGNUM)
387 (match_operand:SI 0 "register_operand" "r,r")
388 (match_operator:SI 2 "cris_extend_operator"
389 [(match_operand:BW 1 "memory_operand" "Q>,m")])))]
392 [(set_attr "slottable" "yes,no")])
394 ;; The "normal" compare patterns, from SI on. Special-cases with zero
395 ;; are covered above.
397 (define_insn "*cmpsi<NZVCSET:mode>"
398 [(set (reg:NZVCSET CRIS_CC0_REGNUM)
400 (match_operand:SI_ 0 "nonimmediate_operand" "<cmp_op0c>")
401 (match_operand:SI_ 1 "general_operand" "<cmp_op1c>")))]
410 [(set_attr "slottable" "yes,yes,yes,no,no,no")])
412 (define_insn "*cmp<BW:mode><NZVCSET:mode>"
413 [(set (reg:NZVCSET CRIS_CC0_REGNUM)
415 (match_operand:BW 0 "nonimmediate_operand" "<cmp_op0c>")
416 (match_operand:BW 1 "general_operand" "<cmp_op1c>")))]
423 [(set_attr "slottable" "yes,yes,no,no")])
425 ;; Pattern matching the BTST insn.
426 ;; It is useful for "if (i & val)" constructs, where val is an exact
427 ;; power of 2, or if val + 1 is a power of two, where we check for a bunch
428 ;; of zeros starting at bit 0).
430 ;; SImode. This mode is the only one needed, since gcc automatically
431 ;; extends subregs for lower-size modes.
432 (define_insn "*btst<mode>"
433 [(set (reg:ZnNNZSET CRIS_CC0_REGNUM)
436 (match_operand:SI 0 "nonmemory_operand" "r, r,r, r,r, r,Kp")
437 (match_operand:SI 1 "const_int_operand" "Kc,n,Kc,n,Kc,n,n")
438 (match_operand:SI 2 "nonmemory_operand" "M, M,Kc,n,r, r,r"))
440 ;; Either it is a single bit, or consecutive ones starting at 0.
442 && CONST_INT_P (operands[1])
443 && ((operands[1] == const1_rtx && <MODE>mode == CC_ZnNmode)
444 || (operands[2] == const0_rtx && <MODE>mode == CC_NZmode))
445 && (REG_S_P (operands[0])
446 || (operands[1] == const1_rtx
447 && REG_S_P (operands[2])
448 && CONST_INT_P (operands[0])
449 && exact_log2 (INTVAL (operands[0])) >= 0))
452 ;; The next-to-last "&&" condition above should be caught by some kind of
453 ;; canonicalization in gcc, but we can easily help with it here.
454 ;; It results from expressions of the type
455 ;; "power_of_2_value & (1 << y)". FIXME: Add testcase.
457 ;; Since there may be codes with tests in on bits (in constant position)
458 ;; beyond the size of a word, handle that by assuming those bits are 0.
459 ;; GCC should handle that, but it's a matter of easily-added belts while
460 ;; having suspenders.
470 [(set_attr "slottable" "yes")])
474 ;; The whole mandatory movdi family is here; expander, "anonymous"
475 ;; recognizer and splitter. We're forced to have a movdi pattern,
476 ;; although GCC should be able to split it up itself. Normally it can,
477 ;; but if other insns have DI operands (as is the case here), reload
478 ;; must be able to generate or match a movdi. many testcases fail at
479 ;; -O3 or -fssa if we don't have this. FIXME: Fix GCC... See
480 ;; <URL:http://gcc.gnu.org/ml/gcc-patches/2000-04/msg00104.html>.
481 ;; However, a patch from Richard Kenner (similar to the cause of
482 ;; discussion at the URL above), indicates otherwise. See
483 ;; <URL:http://gcc.gnu.org/ml/gcc-patches/2000-04/msg00554.html>.
484 ;; The truth has IMO is not been decided yet, so check from time to
485 ;; time by disabling the movdi patterns.
487 ;; To appease testcase gcc.c-torture/execute/920501-2.c (and others) at
488 ;; -O0, we need a movdi as a temporary measure. Here's how things fail:
489 ;; A cmpdi RTX needs reloading (global):
490 ;; (insn 185 326 186 (set (cc0)
491 ;; (compare (mem/f:DI (reg/v:SI 22) 0)
492 ;; (const_int 1 [0x1]))) 4 {cmpdi} (nil)
494 ;; Now, reg 22 is reloaded for input address, and the mem is also moved
495 ;; out of the instruction (into a register), since one of the operands
496 ;; must be a register. Reg 22 is reloaded (into reg 10), and the mem is
497 ;; moved out and synthesized in SImode parts (reg 9, reg 10 - should be ok
498 ;; wrt. overlap). The bad things happen with the synthesis in
499 ;; emit_move_insn_1; the location where to substitute reg 10 is lost into
500 ;; two new RTX:es, both still having reg 22. Later on, the left-over reg
501 ;; 22 is recognized to have an equivalent in memory which is substituted
502 ;; straight in, and we end up with an unrecognizable insn:
503 ;; (insn 325 324 326 (set (reg:SI 9 r9)
504 ;; (mem/f:SI (mem:SI (plus:SI (reg:SI 8 r8)
505 ;; (const_int -84 [0xffffffac])) 0) 0)) -1 (nil)
507 ;; which is the first part of the reloaded synthesized "movdi".
508 ;; The right thing would be to add equivalent replacement locations for
509 ;; insn with pseudos that need more reloading. The question is where.
511 (define_expand "movdi"
513 [(set (match_operand:DI 0 "nonimmediate_operand")
514 (match_operand:DI 1 "general_operand"))
515 (clobber (reg:CC CRIS_CC0_REGNUM))])]
518 if (MEM_P (operands[0])
519 && operands[1] != const0_rtx
520 && can_create_pseudo_p ())
521 operands[1] = copy_to_mode_reg (DImode, operands[1]);
523 /* Some other ports (as of 2001-09-10 for example mcore and romp) also
524 prefer to split up constants early, like this. The testcase in
525 gcc.c-torture/execute/961213-1.c shows that CSE2 gets confused by the
526 resulting subreg sets when using the construct from mcore (as of FSF
527 CVS, version -r 1.5), and it believes that the high part (the last one
528 emitted) is the final value. */
529 if ((CONST_INT_P (operands[1]) || GET_CODE (operands[1]) == CONST_DOUBLE)
530 && ! reload_completed
531 && ! lra_in_progress)
534 rtx op0 = operands[0];
535 rtx op1 = operands[1];
538 emit_move_insn (operand_subword (op0, 0, 1, DImode),
539 operand_subword (op1, 0, 1, DImode));
540 emit_move_insn (operand_subword (op0, 1, 1, DImode),
541 operand_subword (op1, 1, 1, DImode));
542 insns = get_insns ();
550 (define_insn_and_split "*movdi_insn"
551 [(set (match_operand:DI 0 "nonimmediate_operand" "=r,rx,m")
552 (match_operand:DI 1 "general_operand" "rx,g,rxM"))
553 (clobber (reg:CC CRIS_CC0_REGNUM))]
554 "(register_operand (operands[0], DImode)
555 || register_operand (operands[1], DImode)
556 || operands[1] == const0_rtx)"
558 "&& reload_completed"
560 "operands[2] = cris_split_movdx (operands);")
562 ;; Normal move patterns from SI on.
564 (define_expand "movsi"
567 (match_operand:SI 0 "nonimmediate_operand")
568 (match_operand:SI 1 "general_operand"))
569 (clobber (reg:CC CRIS_CC0_REGNUM))])]
572 /* If the output goes to a MEM, make sure we have zero or a register as
574 if (MEM_P (operands[0])
575 && ! REG_S_P (operands[1])
576 && operands[1] != const0_rtx
577 && can_create_pseudo_p ())
578 operands[1] = force_reg (SImode, operands[1]);
580 /* At post-reload time, we'll get here for e.g. split multi-mode insns
581 with a memory destination. Go directly to the clobber-less variant.
582 FIXME: Also applies to special-register source or destination. */
584 && (MEM_P (operands[0]) || operands[1] == const0_rtx))
586 emit_insn (gen_rtx_SET (operands[0], operands[1]));
591 ;; We provide CC, CC_NZ and CC_NZVC variants, as moves clear V and C
592 ;; and the result is thus usable in a compare against 0.
593 (define_insn "*movsi_internal<setcc><setnz><setnzvc>"
595 (match_operand:SI 0 "nonimmediate_operand"
596 "=r,r, r,Q>,r,Q>,g,r,r,g,rQ>,x, m,x, Q>,r,g")
597 (match_operand:SI 1 "general_operand"
598 "r,Q>,M,M, I,r, M,n,g,r,x, rQ>,x,gi,r, g,r"))
599 (clobber (reg:CC CRIS_CC0_REGNUM))]
600 ;; Avoid matching insns we know must be reloaded. Without one
601 ;; operand being a (pseudo-)register, reload chooses
602 ;; reload-registers suboptimally.
603 "REG_S_P (operands[0]) || REG_S_P (operands[1]) || operands[1] == const0_rtx"
605 /* Better to have c-switch here; it is worth it to optimize the size of
606 move insns. The alternative would be to try to find more constraint
607 letters. FIXME: Check again. It seems this could shrink a bit. */
608 switch (which_alternative)
618 return "move.d %1,%0";
631 /* Constants -32..31 except 0. */
633 return "moveq %1,%0";
635 /* We can win a little on constants -32768..-33, 32..65535. */
637 if (INTVAL (operands[1]) > 0 && INTVAL (operands[1]) < 65536)
639 if (INTVAL (operands[1]) < 256)
640 return "movu.b %1,%0";
641 return "movu.w %1,%0";
643 else if (INTVAL (operands[1]) >= -32768 && INTVAL (operands[1]) < 32768)
645 if (INTVAL (operands[1]) >= -128 && INTVAL (operands[1]) < 128)
646 return "movs.b %1,%0";
647 return "movs.w %1,%0";
649 return "move.d %1,%0";
655 [(set_attr "cpu_variant" "*,*,*,*,*,v0,*,*,v0,v0,*,*,*,*,v10,v10,v10")
656 (set_attr "slottable" "yes,yes,yes,yes,yes,yes,no,no,no,no,yes,yes,no,no,yes,no,no")
657 (set_attr "cc<cccc><ccnz><ccnzvc>"
658 "*,*,none,none,*,none,none,*,*,none,none,none,none,none,none,*,none")])
662 (define_insn "<acc><anz><anzvc>movhi<setcc><setnz><setnzvc>"
664 (match_operand:HI 0 "nonimmediate_operand" "=r,r, r,Q>,r,Q>,r,r,r,g,g,r,r,x")
665 (match_operand:HI 1 "general_operand" "r,Q>,M,M, I,r, L,O,n,M,r,g,x,r"))
666 (clobber (reg:CC CRIS_CC0_REGNUM))]
669 switch (which_alternative)
676 return "move.w %1,%0";
685 return "moveq %1,%0";
688 if (INTVAL (operands[1]) < 256 && INTVAL (operands[1]) >= -128)
690 if (INTVAL (operands[1]) > 0)
691 return "movu.b %1,%0";
692 return "movs.b %1,%0";
694 return "move.w %1,%0";
696 return "movEq %b1,%0";
698 return "BOGUS: %1 to %0";
701 [(set_attr "slottable" "yes,yes,yes,yes,yes,yes,no,yes,no,no,no,no,yes,yes")
702 (set_attr "cc<cccc><ccnz><ccnzvc>" "*,*,none,none,*,none,*,clobber,*,none,none,*,none,none")])
704 (define_insn "movstricthi"
707 (match_operand:HI 0 "nonimmediate_operand" "+r,r, r,Q>,Q>,g,r,g"))
708 (match_operand:HI 1 "general_operand" "r,Q>,M,M, r, M,g,r"))
709 (clobber (reg:CC CRIS_CC0_REGNUM))]
720 [(set_attr "slottable" "yes,yes,yes,yes,yes,no,no,no")])
722 (define_expand "reload_in<mode>"
723 [(set (match_operand:BW 2 "register_operand" "=r")
724 (match_operand:BW 1 "memory_operand" "m"))
725 (set (match_operand:BW 0 "register_operand" "=x")
730 (define_expand "reload_out<mode>"
731 [(set (match_operand:BW 2 "register_operand" "=&r")
732 (match_operand:BW 1 "register_operand" "x"))
733 (set (match_operand:BW 0 "memory_operand" "=m")
738 (define_insn "<acc><anz><anzvc>movqi<setcc><setnz><setnzvc>"
739 [(set (match_operand:QI 0 "nonimmediate_operand" "=r,Q>,r, r,Q>,r,g,g,r,r,r,x")
740 (match_operand:QI 1 "general_operand" "r,r, Q>,M,M, I,M,r,O,g,x,r"))
741 (clobber (reg:CC CRIS_CC0_REGNUM))]
756 [(set_attr "slottable" "yes,yes,yes,yes,yes,yes,no,no,yes,no,yes,yes")
757 (set_attr "cc<cccc><ccnz><ccnzvc>"
758 "*,none,*,none,none,*,none,none,clobber,*,none,none")])
760 (define_insn "movstrictqi"
761 [(set (strict_low_part
762 (match_operand:QI 0 "nonimmediate_operand" "+r,Q>,r, r,Q>,g,g,r"))
763 (match_operand:QI 1 "general_operand" "r,r, Q>,M,M, M,r,g"))
764 (clobber (reg:CC CRIS_CC0_REGNUM))]
775 [(set_attr "slottable" "yes,yes,yes,yes,yes,no,no,no")])
777 ;; The valid "quick" bit-patterns are, except for 0.0, denormalized
778 ;; values REALLY close to 0, and some NaN:s (I think; their exponent is
779 ;; all ones); the worthwhile one is "0.0".
780 ;; It will use clear, so we know ALL types of immediate 0 never change cc.
783 [(set (match_operand:SF 0 "nonimmediate_operand" "=r,Q>,r, r,Q>,g,g,r,r,x,Q>,m,x, x")
784 (match_operand:SF 1 "general_operand" "r,r, Q>,G,G, G,r,g,x,r,x, x,Q>,g"))
785 (clobber (reg:CC CRIS_CC0_REGNUM))]
802 [(set_attr "slottable" "yes,yes,yes,yes,yes,no,no,no,yes,yes,yes,no,yes,no")])
804 ;; Post-reload, for memory destinations, split the clobber-variant and
805 ;; get rid of the clobber.
807 (define_split ;; "*mov_tomem<mode>_split"
808 [(set (match_operand:BWD 0 "memory_operand")
809 (match_operand:BWD 1 "nonmemory_operand"))
810 (clobber (reg:CC CRIS_CC0_REGNUM))]
812 [(set (match_dup 0) (match_dup 1))]
815 ;; Exclude moving special-registers to memory from matching for
816 ;; less-than-SImode, as they are SImode only (or actually, the size of
817 ;; the register, but the ones free for "x" are naturally SImode; see
818 ;; special measures taken for reload).
819 ;; This might be a belt-and-suspenders thing, as a move from special
820 ;; register to memory in less-than-SImode should not have made it here.
822 (define_mode_attr mov_tomem_enabled
823 [(SI "yes,yes,yes,yes,yes,yes")
824 (HI "yes,yes,no,yes,yes,no")
825 (QI "yes,yes,no,yes,yes,no")])
827 (define_insn "*mov_tomem<mode>"
828 [(set (match_operand:BWD 0 "memory_operand" "=Q>,Q>,Q>,m,m,m")
829 (match_operand:BWD 1 "nonmemory_operand" "M, r, x, M,r,x"))]
838 [(set_attr "slottable" "yes,yes,yes,no,no,no")
839 (set_attr "enabled" "<mov_tomem_enabled>")])
841 (define_split ;; "*mov_fromzero<mode>_split"
842 [(set (match_operand:BWD 0 "register_operand") (const_int 0))
843 (clobber (reg:CC CRIS_CC0_REGNUM))]
845 && REGNO(operands[0]) <= CRIS_LAST_GENERAL_REGISTER"
846 [(set (match_dup 0) (const_int 0))]
849 (define_insn "*mov_fromzero<mode>"
850 [(set (match_operand:BWD 0 "register_operand" "=r") (const_int 0))]
853 [(set_attr "slottable" "yes")])
855 ;; Movem patterns. Primarily for use in function prologue and epilogue.
856 ;; Unfortunately, movem stores R0 in the highest memory location, thus
857 ;; the opposite of the expectation for the standard names "load_multiple"
858 ;; and "store_multiple".
860 (define_insn "*cris_load_multiple"
861 [(match_parallel 0 "cris_load_multiple_op"
862 [(set (match_operand:SI 1 "register_operand" "=r,r")
863 (match_operand:SI 2 "memory_operand" "Q,m"))])]
866 [(set_attr "cc" "none")
867 (set_attr "slottable" "yes,no")
868 ;; Not true, but setting the length to 0 causes return sequences (ret
869 ;; movem) to have the cost they had when (return) included the movem
870 ;; and reduces the performance penalty taken for needing to emit an
871 ;; epilogue (in turn copied by bb-reorder) instead of return patterns.
872 ;; FIXME: temporary change until all insn lengths are correctly
873 ;; described. FIXME: have better target control over bb-reorder.
874 (set_attr "length" "0")])
876 (define_insn "*cris_store_multiple"
877 [(match_parallel 0 "cris_store_multiple_op"
878 [(set (match_operand:SI 2 "memory_operand" "=Q,m")
879 (match_operand:SI 1 "register_operand" "r,r"))])]
882 [(set_attr "cc" "none")
883 (set_attr "slottable" "yes,no")])
886 ;; Sign- and zero-extend insns with standard names.
887 ;; Those for integer source operand are ordered with the widest source
892 (define_insn "extendsidi2"
893 [(set (match_operand:DI 0 "register_operand" "=r")
894 (sign_extend:DI (match_operand:SI 1 "general_operand" "g")))
895 (clobber (reg:CC CRIS_CC0_REGNUM))]
897 "move.d %1,%M0\;smi %H0\;neg.d %H0,%H0")
899 (define_insn "extend<mode>di2"
900 [(set (match_operand:DI 0 "register_operand" "=r")
901 (sign_extend:DI (match_operand:BW 1 "general_operand" "g")))
902 (clobber (reg:CC CRIS_CC0_REGNUM))]
904 "movs<m> %1,%M0\;smi %H0\;neg.d %H0,%H0")
906 (define_insn "<acc><anz><anzvc>extend<mode>si2<setcc><setnz><setnzvc>"
907 [(set (match_operand:SI 0 "register_operand" "=r,r,r")
908 (sign_extend:SI (match_operand:BW 1 "general_operand" "r,Q>,g")))
909 (clobber (reg:CC CRIS_CC0_REGNUM))]
912 [(set_attr "slottable" "yes,yes,no")])
914 ;; To do a byte->word extension, extend to dword, except that the top half
915 ;; of the register will be clobbered. FIXME: Perhaps this is not needed.
917 (define_insn "extendqihi2"
918 [(set (match_operand:HI 0 "register_operand" "=r,r,r")
919 (sign_extend:HI (match_operand:QI 1 "general_operand" "r,Q>,g")))
920 (clobber (reg:CC CRIS_CC0_REGNUM))]
923 [(set_attr "slottable" "yes,yes,no")])
926 ;; Zero-extend. The DImode ones are synthesized by gcc, so we don't
927 ;; specify them here.
929 (define_insn "<acc><anz><anzvc>zero_extend<mode>si2<setcc><setnz><setnzvc>"
930 [(set (match_operand:SI 0 "register_operand" "=r,r,r")
932 (match_operand:BW 1 "nonimmediate_operand" "r,Q>,m")))
933 (clobber (reg:CC CRIS_CC0_REGNUM))]
936 [(set_attr "slottable" "yes,yes,no")])
938 ;; Same comment as sign-extend QImode to HImode above applies.
940 (define_insn "zero_extendqihi2"
941 [(set (match_operand:HI 0 "register_operand" "=r,r,r")
943 (match_operand:QI 1 "nonimmediate_operand" "r,Q>,m")))
944 (clobber (reg:CC CRIS_CC0_REGNUM))]
947 [(set_attr "slottable" "yes,yes,no")])
949 ;; Add operations, standard names.
951 ;; Note that for the 'P' constraint, the high part can be -1 or 0. We
952 ;; output the insn through the 'A' output modifier as "adds.w" and "addq",
954 (define_expand "adddi3"
956 [(set (match_operand:DI 0 "register_operand")
957 (plus:DI (match_operand:DI 1 "register_operand")
958 (match_operand:DI 2 "general_operand")))
959 (clobber (reg:CC CRIS_CC0_REGNUM))])]
963 (define_insn "*adddi3<setnz>"
964 [(set (match_operand:DI 0 "register_operand" "=r,r,r,&r,&r")
965 (plus:DI (match_operand:DI 1 "register_operand" "%0,0,0,0,r")
966 (match_operand:DI 2 "general_operand" "J,N,P,g,!To")))
967 (clobber (reg:CC CRIS_CC0_REGNUM))]
970 addq %2,%M0\;ax\;addq 0,%H0
971 subq %n2,%M0\;ax\;subq 0,%H0
972 add%e2.%z2 %2,%M0\;ax\;%A2 %H2,%H0
973 add.d %M2,%M0\;ax\;add.d %H2,%H0
974 add.d %M2,%M1,%M0\;ax\;add.d %H2,%H1,%H0")
976 (define_expand "add<mode>3"
978 [(set (match_operand:BWD 0 "register_operand")
980 (match_operand:BWD 1 "register_operand")
981 (match_operand:BWD 2 "general_operand")))
982 (clobber (reg:CC CRIS_CC0_REGNUM))])]
986 (define_insn "*addsi3<setnz>"
987 [(set (match_operand:SI 0 "register_operand" "=r,r, r,r,r,r,r, r")
989 (match_operand:SI 1 "register_operand" "%0,0, 0,0,0,0,r, r")
990 (match_operand:SI 2 "general_operand" "r,Q>,J,N,n,g,!To,0")))
991 (clobber (reg:CC CRIS_CC0_REGNUM))]
993 ;; The last constraint is due to that after reload, the '%' is not
994 ;; honored, and canonicalization doesn't care about keeping the same
995 ;; register as in destination. This will happen after insn splitting.
999 switch (which_alternative)
1003 return "add.d %2,%0";
1005 return "addq %2,%0";
1007 return "subq %n2,%0";
1009 /* 'Known value', but not in -63..63.
1010 Check if addu/subu may be used. */
1011 if (INTVAL (operands[2]) > 0)
1013 if (INTVAL (operands[2]) < 256)
1014 return "addu.b %2,%0";
1015 if (INTVAL (operands[2]) < 65536)
1016 return "addu.w %2,%0";
1020 if (INTVAL (operands[2]) >= -255)
1021 return "subu.b %n2,%0";
1022 if (INTVAL (operands[2]) >= -65535)
1023 return "subu.w %n2,%0";
1025 return "add.d %2,%0";
1027 return "add.d %2,%0";
1029 return "add.d %2,%1,%0";
1031 return "add.d %1,%0";
1033 return "BOGUS addsi %2+%1 to %0";
1036 [(set_attr "slottable" "yes,yes,yes,yes,no,no,no,yes")])
1038 (define_insn "*addhi3<setnz>"
1039 [(set (match_operand:HI 0 "register_operand" "=r,r, r,r,r,r")
1040 (plus:HI (match_operand:HI 1 "register_operand" "%0,0, 0,0,0,r")
1041 (match_operand:HI 2 "general_operand" "r,Q>,J,N,g,!To")))
1042 (clobber (reg:CC CRIS_CC0_REGNUM))]
1051 [(set_attr "slottable" "yes,yes,yes,yes,no,no")
1052 (set_attr "cc<ccnz>" "normal,normal,clobber,clobber,normal,normal")])
1054 (define_insn "*addqi3<setnz>"
1055 [(set (match_operand:QI 0 "register_operand" "=r,r, r,r,r,r,r")
1056 (plus:QI (match_operand:QI 1 "register_operand" "%0,0, 0,0,0,0,r")
1057 (match_operand:QI 2 "general_operand" "r,Q>,J,N,O,g,!To")))
1058 (clobber (reg:CC CRIS_CC0_REGNUM))]
1068 [(set_attr "slottable" "yes,yes,yes,yes,yes,no,no")
1069 (set_attr "cc<ccnz>" "normal,normal,clobber,clobber,clobber,normal,normal")])
1073 ;; Note that because of insn canonicalization these will *seldom* but
1074 ;; rarely be used with a known constant as an operand.
1076 ;; Note that for the 'P' constraint, the high part can be -1 or 0. We
1077 ;; output the insn through the 'D' output modifier as "subs.w" and "subq",
1079 (define_expand "subdi3"
1081 [(set (match_operand:DI 0 "register_operand")
1082 (minus:DI (match_operand:DI 1 "register_operand")
1083 (match_operand:DI 2 "general_operand")))
1084 (clobber (reg:CC CRIS_CC0_REGNUM))])]
1088 (define_insn "*subdi3<setnz>"
1089 [(set (match_operand:DI 0 "register_operand" "=r,r,r,&r,&r")
1090 (minus:DI (match_operand:DI 1 "register_operand" "0,0,0,0,r")
1091 (match_operand:DI 2 "general_operand" "J,N,P,g,!To")))
1092 (clobber (reg:CC CRIS_CC0_REGNUM))]
1095 subq %2,%M0\;ax\;subq 0,%H0
1096 addq %n2,%M0\;ax\;addq 0,%H0
1097 sub%e2.%z2 %2,%M0\;ax\;%D2 %H2,%H0
1098 sub.d %M2,%M0\;ax\;sub.d %H2,%H0
1099 sub.d %M2,%M1,%M0\;ax\;sub.d %H2,%H1,%H0")
1101 (define_expand "sub<mode>3"
1103 [(set (match_operand:BWD 0 "register_operand")
1105 (match_operand:BWD 1 "register_operand")
1106 (match_operand:BWD 2 "general_operand")))
1107 (clobber (reg:CC CRIS_CC0_REGNUM))])]
1111 (define_insn "*subsi3<setnz>"
1112 [(set (match_operand:SI 0 "register_operand" "=r,r, r,r,r,r,r,r")
1114 (match_operand:SI 1 "register_operand" "0,0, 0,0,0,0,0,r")
1115 (match_operand:SI 2 "general_operand" "r,Q>,J,N,P,n,g,!To")))
1116 (clobber (reg:CC CRIS_CC0_REGNUM))]
1119 ;; This does not do the optimal: "addu.w 65535,r0" when %2 is negative.
1120 ;; But then again, %2 should not be negative.
1131 [(set_attr "slottable" "yes,yes,yes,yes,no,no,no,no")])
1133 (define_insn "*sub<mode>3<setnz>"
1134 [(set (match_operand:BW 0 "register_operand" "=r,r, r,r,r,r")
1135 (minus:BW (match_operand:BW 1 "register_operand" "0,0, 0,0,0,r")
1136 (match_operand:BW 2 "general_operand" "r,Q>,J,N,g,!To")))
1137 (clobber (reg:CC CRIS_CC0_REGNUM))]
1146 [(set_attr "slottable" "yes,yes,yes,yes,no,no")
1147 (set_attr "cc<ccnz>" "normal,normal,clobber,clobber,normal,normal")])
1149 ;; Extend versions (zero/sign) of normal add/sub (no side-effects).
1152 ;; FIXME: GCC should widen.
1154 (define_insn "*<addsub><su>qihi"
1155 [(set (match_operand:HI 0 "register_operand" "=r,r,r,r")
1157 (match_operand:HI 1 "register_operand" "0,0,0,r")
1158 (szext:HI (match_operand:QI 2 "nonimmediate_operand" "r,Q>,m,!To"))))
1159 (clobber (reg:CC CRIS_CC0_REGNUM))]
1160 "GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
1161 && (operands[1] != frame_pointer_rtx || <plusminus:CODE> != PLUS)"
1163 <addsub><su>.b %2,%0
1164 <addsub><su>.b %2,%0
1165 <addsub><su>.b %2,%0
1166 <addsub><su>.b %2,%1,%0"
1167 [(set_attr "slottable" "yes,yes,no,no")
1168 (set_attr "cc" "clobber")])
1170 ;; FIXME: bound is actually also <setnzvc>, but is so rarely used in this
1171 ;; form that it's not worthwhile to make that distinction.
1172 (define_insn "*<addsubbo><su><nd><mode>si<setnz>"
1173 [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
1175 (match_operand:SI 1 "register_operand" "0,0,0,r")
1176 (szext:SI (match_operand:BW 2 "nonimmediate_operand" "r,Q>,m,!To"))))
1177 (clobber (reg:CC CRIS_CC0_REGNUM))]
1178 "(<plusminusumin:CODE> != UMIN || <szext:CODE> == ZERO_EXTEND)
1179 && (operands[1] != frame_pointer_rtx || <plusminusumin:CODE> != PLUS)"
1181 <addsubbo><su><nd><m> %2,%0
1182 <addsubbo><su><nd><m> %2,%0
1183 <addsubbo><su><nd><m> %2,%0
1184 <addsubbo><su><nd><m> %2,%1,%0"
1185 [(set_attr "slottable" "yes,yes,no,no")])
1187 ;; We may have swapped operands for add or bound.
1188 ;; For commutative operands, these are the canonical forms.
1192 (define_insn "*add<su>qihi_swap"
1193 [(set (match_operand:HI 0 "register_operand" "=r,r,r,r")
1195 (szext:HI (match_operand:QI 2 "nonimmediate_operand" "r,Q>,m,!To"))
1196 (match_operand:HI 1 "register_operand" "0,0,0,r")))
1197 (clobber (reg:CC CRIS_CC0_REGNUM))]
1198 "operands[1] != frame_pointer_rtx"
1204 [(set_attr "slottable" "yes,yes,no,no")
1205 (set_attr "cc" "clobber")])
1207 (define_insn "*<addsubbo><su><nd><mode>si<setnz>_swap"
1208 [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
1210 (szext:SI (match_operand:BW 2 "nonimmediate_operand" "r,Q>,m,!To"))
1211 (match_operand:SI 1 "register_operand" "0,0,0,r")))
1212 (clobber (reg:CC CRIS_CC0_REGNUM))]
1213 "(<plusumin:CODE> != UMIN || <szext:CODE> == ZERO_EXTEND)
1214 && operands[1] != frame_pointer_rtx"
1216 <addsubbo><su><nd><m> %2,%0
1217 <addsubbo><su><nd><m> %2,%0
1218 <addsubbo><su><nd><m> %2,%0
1219 <addsubbo><su><nd><m> %2,%1,%0"
1220 [(set_attr "slottable" "yes,yes,no,no")])
1222 ;; This is the special case when we use what corresponds to the
1223 ;; instruction above in "casesi". Do *not* change it to use the generic
1224 ;; pattern and "REG 15" as pc; I did that and it led to madness and
1225 ;; maintenance problems: Instead of (as imagined) recognizing and removing
1226 ;; or replacing this pattern with something simpler, other variant
1227 ;; patterns were recognized or combined, including some prefix variants
1228 ;; where the value in pc is not that of the next instruction (which means
1229 ;; this instruction actually *is* special and *should* be marked as such).
1230 ;; When switching from the "generic pattern match" approach to this simpler
1231 ;; approach, there were insignificant differences in gcc, ipps and
1232 ;; product code, somehow due to scratching reload behind the ear or
1233 ;; something. Testcase "gcc" looked .01% slower and 4 bytes bigger;
1234 ;; product code became .001% smaller but "looked better". The testcase
1235 ;; "ipps" was just different at register allocation).
1237 ;; Assumptions in the jump optimizer forces us to use IF_THEN_ELSE in this
1238 ;; pattern with the default-label as the else, with the "if" being
1239 ;; index-is-less-than the max number of cases plus one. The default-label
1240 ;; is attached to the end of the case-table at time of output.
1242 (define_insn "*casesi_adds_w"
1245 (ltu (match_operand:SI 0 "register_operand" "r")
1246 (match_operand:SI 1 "const_int_operand" "n"))
1247 (plus:SI (sign_extend:SI
1249 (plus:SI (mult:SI (match_dup 0) (const_int 2))
1252 (label_ref (match_operand 2 "" ""))))
1253 (use (label_ref (match_operand 3 "" "")))
1254 (clobber (reg:CC CRIS_CC0_REGNUM))]
1255 "operands[0] != frame_pointer_rtx"
1256 "adds.w [$pc+%0.w],$pc"
1257 [(set_attr "cc" "clobber")])
1259 ;; Multiply instructions.
1261 ;; Sometimes powers of 2 (which are normally canonicalized to a
1262 ;; left-shift) appear here, as a result of address reloading.
1263 ;; As a special, for values 3 and 5, we can match with an addi, so add those.
1265 ;; FIXME: This may be unnecessary now.
1266 ;; Explicitly named for convenience of having a gen_... function.
1268 (define_insn "addi_mul"
1269 [(set (match_operand:SI 0 "register_operand" "=r")
1271 (match_operand:SI 1 "register_operand" "%0")
1272 (match_operand:SI 2 "const_int_operand" "n")))
1273 (clobber (reg:CC CRIS_CC0_REGNUM))]
1274 "operands[0] != frame_pointer_rtx
1275 && operands[1] != frame_pointer_rtx
1276 && CONST_INT_P (operands[2])
1277 && (INTVAL (operands[2]) == 2
1278 || INTVAL (operands[2]) == 4 || INTVAL (operands[2]) == 3
1279 || INTVAL (operands[2]) == 5)"
1281 if (INTVAL (operands[2]) == 2)
1283 else if (INTVAL (operands[2]) == 4)
1285 else if (INTVAL (operands[2]) == 3)
1286 return "addi %0.w,%0";
1287 else if (INTVAL (operands[2]) == 5)
1288 return "addi %0.d,%0";
1289 return "BAD: adr_mulsi: %0=%1*%2";
1291 [(set_attr "slottable" "yes")
1292 ;; No flags are changed if this insn is "addi", but it does not seem
1293 ;; worth the trouble to distinguish that to the lslq cases.
1294 (set_attr "cc" "clobber")])
1296 ;; The addi insn as it is normally used.
1298 (define_insn "*addi"
1299 [(set (match_operand:SI 0 "register_operand" "=r")
1301 (ashift:SI (match_operand:SI 2 "register_operand" "r")
1302 (match_operand:SI 3 "const_int_operand" "n"))
1303 (match_operand:SI 1 "register_operand" "0")))]
1304 "operands[0] != frame_pointer_rtx
1305 && operands[1] != frame_pointer_rtx
1306 && CONST_INT_P (operands[3])
1307 && (INTVAL (operands[3]) == 1 || INTVAL (operands[3]) == 2)"
1309 [(set_attr "slottable" "yes")
1310 (set_attr "cc" "none")])
1312 ;; The mult-vs-ashift canonicalization-cleanup plagues us: nothing in
1313 ;; reload transforms a "scaled multiplication" into an ashift in a
1314 ;; reloaded address; it's passed as-is and expected to be recognized,
1315 ;; or else we get a tell-tale "unrecognizable insn".
1316 ;; On top of that, we *should* match the bare insn, as a *matching
1317 ;; pattern* (as opposed to e.g. a reload_load_address expander
1318 ;; changing the mul into an ashift), so can_reload_into will re-use
1319 ;; registers in the reloaded expression instead of allocating a new
1321 (define_insn_and_split "*addi_reload"
1322 [(set (match_operand:SI 0 "register_operand" "=r")
1324 (mult:SI (match_operand:SI 2 "register_operand" "r")
1325 (match_operand:SI 3 "const_int_operand" "n"))
1326 (match_operand:SI 1 "register_operand" "0")))]
1327 "operands[0] != frame_pointer_rtx
1328 && operands[1] != frame_pointer_rtx
1329 && CONST_INT_P (operands[3])
1330 && (INTVAL (operands[3]) == 2 || INTVAL (operands[3]) == 4)
1331 && (lra_in_progress || reload_completed)"
1335 (plus:SI (ashift:SI (match_dup 2) (match_dup 3)) (match_dup 1)))]
1336 "operands[3] = operands[3] == const2_rtx ? const1_rtx : const2_rtx;")
1338 ;; This pattern is usually generated after reload, so a '%' is
1339 ;; ineffective; use explicit combinations.
1340 (define_insn "*addi_b_<mode>"
1341 [(set (match_operand:BWD 0 "register_operand" "=r,r")
1343 (match_operand:BWD 1 "register_operand" "0,r")
1344 (match_operand:BWD 2 "register_operand" "r,0")))]
1349 [(set_attr "slottable" "yes")])
1351 ;; Strip the dccr clobber from addM3 with register operands, if the
1352 ;; next instruction isn't using it.
1353 ;; Not clobbering dccr may let cmpelim match a later compare with a
1354 ;; previous operation of interest. This has to run before cmpelim so it
1355 ;; can't be a peephole2. See gcc.target/cris/pr93372-45.c for a
1357 (define_split ;; "*add<mode>3_addi"
1359 [(set (match_operand:BWD 0 "register_operand")
1361 (match_operand:BWD 1 "register_operand")
1362 (match_operand:BWD 2 "register_operand")))
1363 (clobber (reg:CC CRIS_CC0_REGNUM))])]
1365 [(set (match_dup 0) (plus:BWD (match_dup 1) (match_dup 2)))]
1367 rtx reg = operands[0];
1368 rtx_insn *i = next_nonnote_nondebug_insn_bb (curr_insn);
1371 while (i != NULL_RTX && (!INSN_P (i) || DEBUG_INSN_P (i)))
1372 i = next_nonnote_nondebug_insn_bb (i);
1374 /* We don't want to strip the clobber if the next insn possibly uses the
1375 zeroness of the result. Preferably fail only if we see a compare insn
1376 that looks eliminable and with the register "reg" compared. With some
1377 effort we could also check for an equality test (EQ, NE) in the post-split
1378 user, just not for now. */
1384 /* We explicitly need to bail on a BARRIER, but that's implied by a failing
1390 dest = SET_DEST (x);
1392 /* Bail on (post-split) eliminable compares. */
1393 if (REG_P (dest) && REGNO (dest) == CRIS_CC0_REGNUM
1394 && GET_CODE (src) == COMPARE)
1396 rtx cop0 = XEXP (src, 0);
1398 if (REG_P (cop0) && REGNO (cop0) == REGNO (reg)
1399 && XEXP (src, 1) == const0_rtx)
1403 /* Bail out if we see a (pre-split) cbranch or cstore where the comparison
1404 looks eliminable and uses the destination register in this addition. We
1405 don't need to look very deep: a single_set which is a parallel clobbers
1406 something, and (one of) that something, is always CRIS_CC0_REGNUM here.
1407 Also, the entities we're looking for are two-element parallels. A
1408 split-up cbranch or cstore doesn't clobber CRIS_CC0_REGNUM. A cbranch has
1409 if_then_else as its source with a comparison operator as the condition,
1410 and a cstore has a source with the comparison operator directly. That
1411 also matches dstep, so look for pc as destination for the if_then_else.
1412 We error on the safe side if we happen to catch other conditional entities
1413 and FAIL, that just means the split won't happen. */
1414 if (GET_CODE (PATTERN (i)) == PARALLEL && XVECLEN (PATTERN (i), 0) == 2)
1417 = (GET_CODE (src) == IF_THEN_ELSE && dest == pc_rtx
1419 : (COMPARISON_P (src) ? src : NULL_RTX));
1420 gcc_assert (cmp == NULL_RTX || COMPARISON_P (cmp));
1422 if (cmp && REG_P (XEXP (cmp, 0)) && XEXP (cmp, 1) == const0_rtx
1423 && REGNO (XEXP (cmp, 0)) == REGNO (reg))
1428 (define_insn "<u>mul<s><mode>3"
1429 [(set (match_operand:WD 0 "register_operand" "=r")
1431 (szext:WD (match_operand:<S> 1 "register_operand" "%0"))
1432 (szext:WD (match_operand:<S> 2 "register_operand" "r"))))
1433 (clobber (match_scratch:SI 3 "=h"))
1434 (clobber (reg:CC CRIS_CC0_REGNUM))]
1435 "TARGET_HAS_MUL_INSNS"
1436 "%!mul<su><mm> %2,%0"
1437 [(set (attr "slottable")
1438 (if_then_else (match_test "TARGET_MUL_BUG")
1440 (const_string "yes")))
1441 ;; For umuls.[bwd] it's just N unusable here, but let's be safe.
1442 ;; For muls.b, this really extends to SImode, so cc should be
1443 ;; considered clobbered.
1444 ;; For muls.w, it's just N unusable here, but let's be safe.
1445 (set_attr "cc" "clobber")])
1447 ;; Note that gcc does not make use of such a thing as umulqisi3. It gets
1448 ;; confused and will erroneously use it instead of umulhisi3, failing (at
1449 ;; least) gcc.c-torture/execute/arith-rand.c at all optimization levels.
1450 ;; Inspection of optab code shows that there must be only one widening
1451 ;; multiplication per mode widened to.
1453 (define_insn "mulsi3"
1454 [(set (match_operand:SI 0 "register_operand" "=r")
1455 (mult:SI (match_operand:SI 1 "register_operand" "%0")
1456 (match_operand:SI 2 "register_operand" "r")))
1457 (clobber (match_scratch:SI 3 "=h"))
1458 (clobber (reg:CC CRIS_CC0_REGNUM))]
1459 "TARGET_HAS_MUL_INSNS"
1461 [(set (attr "slottable")
1462 (if_then_else (match_test "TARGET_MUL_BUG")
1464 (const_string "yes")))
1465 ;; Just N unusable here, but let's be safe.
1466 (set_attr "cc" "clobber")])
1468 ;; A few multiply variations.
1470 ;; When needed, we can get the high 32 bits from the overflow
1471 ;; register. We don't care to split and optimize these.
1473 (define_insn "<u>mulsidi3"
1474 [(set (match_operand:DI 0 "register_operand" "=r")
1476 (szext:DI (match_operand:SI 1 "register_operand" "%0"))
1477 (szext:DI (match_operand:SI 2 "register_operand" "r"))))
1478 (clobber (match_scratch:SI 3 "=h"))
1479 (clobber (reg:CC CRIS_CC0_REGNUM))]
1480 "TARGET_HAS_MUL_INSNS"
1481 "%!mul<su>.d %2,%M0\;move $mof,%H0")
1483 ;; These two patterns may be expressible by other means, perhaps by making
1484 ;; [u]?mulsidi3 a define_expand.
1486 ;; Due to register allocation braindamage, the clobber 1,2 alternatives
1487 ;; cause a move into the clobbered register *before* the insn, then
1488 ;; after the insn, mof is moved too, rather than the clobber assigned
1489 ;; the last mof target. This became apparent when making MOF and SRP
1490 ;; visible registers, with the necessary tweak to smulsi3_highpart.
1491 ;; Because these patterns are used in division by constants, that damage
1492 ;; is visible (ipps regression tests). Therefore the last two
1493 ;; alternatives, "helping" reload to avoid an unnecessary move, but
1494 ;; punished by force of one "?". Check code from "int d (int a) {return
1495 ;; a / 1000;}" and unsigned. FIXME: Comment above was for 3.2, revisit.
1497 (define_insn "<su>mulsi3_highpart"
1498 [(set (match_operand:SI 0 "register_operand" "=h,h,?r,?r")
1502 (szext:DI (match_operand:SI 1 "register_operand" "r,r,0,r"))
1503 (szext:DI (match_operand:SI 2 "register_operand" "r,r,r,0")))
1505 (clobber (match_scratch:SI 3 "=1,2,h,h"))
1506 (clobber (reg:CC CRIS_CC0_REGNUM))]
1507 "TARGET_HAS_MUL_INSNS"
1511 %!mul<su>.d %2,%1\;move $mof,%0
1512 %!mul<su>.d %1,%2\;move $mof,%0"
1513 [(set_attr "slottable" "yes,yes,no,no")
1514 (set_attr "cc" "clobber")])
1516 ;; Divide and modulus instructions. CRIS only has a step instruction.
1518 (define_insn "dstep_shift"
1519 [(set (match_operand:SI 0 "register_operand" "=r")
1521 (geu:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
1523 (match_operand:SI 2 "register_operand" "r"))
1524 (minus:SI (ashift:SI (match_operand:SI 3 "register_operand" "0")
1526 (match_operand:SI 4 "register_operand" "2"))
1527 (ashift:SI (match_operand:SI 5 "register_operand" "0")
1529 (clobber (reg:CC CRIS_CC0_REGNUM))]
1532 [(set_attr "slottable" "yes")])
1534 ;; Here's a variant with mult instead of ashift.
1536 ;; FIXME: This should be investigated. Which one matches through combination?
1538 (define_insn "dstep_mul"
1539 [(set (match_operand:SI 0 "register_operand" "=r")
1541 (geu:SI (mult:SI (match_operand:SI 1 "register_operand" "0")
1543 (match_operand:SI 2 "register_operand" "r"))
1544 (minus:SI (mult:SI (match_operand:SI 3 "register_operand" "0")
1546 (match_operand:SI 4 "register_operand" "2"))
1547 (mult:SI (match_operand:SI 5 "register_operand" "0")
1549 (clobber (reg:CC CRIS_CC0_REGNUM))]
1550 "operands[0] != frame_pointer_rtx
1551 && operands[1] != frame_pointer_rtx
1552 && operands[2] != frame_pointer_rtx
1553 && operands[3] != frame_pointer_rtx"
1555 [(set_attr "slottable" "yes")])
1557 ;; Logical operators.
1561 ;; There is no use in defining "anddi3", because gcc can expand this by
1562 ;; itself, and make reasonable code without interference.
1564 ;; If the first operand is memory or a register and is the same as the
1565 ;; second operand, and the third operand is -256 or -65536, we can use
1566 ;; CLEAR instead. Or, if the first operand is a register, and the third
1567 ;; operand is 255 or 65535, we can zero_extend.
1568 ;; GCC isn't smart enough to recognize these cases (yet), and they seem
1569 ;; to be common enough to be worthwhile.
1570 ;; FIXME: This should be made obsolete.
1572 (define_expand "andsi3"
1574 [(set (match_operand:SI 0 "nonimmediate_operand")
1575 (and:SI (match_operand:SI 1 "nonimmediate_operand")
1576 (match_operand:SI 2 "general_operand")))
1577 (clobber (reg:CC CRIS_CC0_REGNUM))])]
1580 if (! (CONST_INT_P (operands[2])
1581 && (((INTVAL (operands[2]) == -256
1582 || INTVAL (operands[2]) == -65536)
1583 && rtx_equal_p (operands[1], operands[0]))
1584 || ((INTVAL (operands[2]) == 255
1585 || INTVAL (operands[2]) == 65535)
1586 && REG_P (operands[0])))))
1588 /* Make intermediate steps if operand0 is not a register or
1589 operand1 is not a register, and hope that the reload pass will
1590 make something useful out of it. Note that the operands are
1591 *not* canonicalized. For the moment, I chicken out on this,
1592 because all or most ports do not describe 'and' with
1593 canonicalized operands, and I seem to remember magic in reload,
1594 checking that operand1 has constraint '%0', in which case
1595 operand0 and operand1 must have similar predicates.
1596 FIXME: Investigate. */
1597 rtx reg0 = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (SImode);
1598 rtx reg1 = operands[1];
1602 emit_move_insn (reg0, reg1);
1606 cris_emit_insn (gen_rtx_SET (reg0, gen_rtx_AND (SImode, reg1,
1609 /* Make sure we get the right *final* destination. */
1610 if (! REG_P (operands[0]))
1611 emit_move_insn (operands[0], reg0);
1617 ;; Some special cases of andsi3.
1619 (define_insn "*andsi_movu"
1620 [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1621 (and:SI (match_operand:SI 1 "nonimmediate_operand" "%r,Q,To")
1622 (match_operand:SI 2 "const_int_operand" "n,n,n")))
1623 (clobber (reg:CC CRIS_CC0_REGNUM))]
1624 "(INTVAL (operands[2]) == 255 || INTVAL (operands[2]) == 65535)
1625 && !side_effects_p (operands[1])"
1627 [(set_attr "slottable" "yes,yes,no")])
1629 ;; FIXME: Remember, this does *not* actually affect condition codes;
1630 ;; get rid of the clobber.
1631 (define_insn "*andsi_clear"
1632 [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,Q,Q,To,To")
1633 (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,0,0,0,0")
1634 (match_operand:SI 2 "const_int_operand" "P,n,P,n,P,n")))
1635 (clobber (reg:CC CRIS_CC0_REGNUM))]
1636 "(INTVAL (operands[2]) == -65536 || INTVAL (operands[2]) == -256)
1637 && !side_effects_p (operands[0])"
1645 [(set_attr "slottable" "yes,yes,yes,yes,no,no")
1646 (set_attr "cc" "none")])
1648 ;; This is a catch-all pattern, taking care of everything that was not
1649 ;; matched in the insns above.
1651 ;; Sidenote: the tightening from "nonimmediate_operand" to
1652 ;; "register_operand" for operand 1 actually increased the register
1653 ;; pressure (worse code). That will hopefully change with an
1654 ;; improved reload pass.
1656 (define_insn "*expanded_andsi<setcc><setnz><setnzvc>"
1657 [(set (match_operand:SI 0 "register_operand" "=r,r,r, r,r")
1658 (and:SI (match_operand:SI 1 "register_operand" "%0,0,0, 0,r")
1659 (match_operand:SI 2 "general_operand" "I,r,Q>,g,!To")))
1660 (clobber (reg:CC CRIS_CC0_REGNUM))]
1668 [(set_attr "slottable" "yes,yes,yes,no,no")])
1670 ;; For both QI and HI we may use the quick patterns. This results in
1671 ;; useless condition codes, but that is used rarely enough for it to
1672 ;; normally be a win (could check ahead for use of CRIS_CC0_REGNUM, but
1673 ;; seems to be more pain than win).
1675 ;; FIXME: See note for andsi3
1677 (define_expand "andhi3"
1679 [(set (match_operand:HI 0 "nonimmediate_operand")
1680 (and:HI (match_operand:HI 1 "nonimmediate_operand")
1681 (match_operand:HI 2 "general_operand")))
1682 (clobber (reg:CC CRIS_CC0_REGNUM))])]
1685 if (! (CONST_INT_P (operands[2])
1686 && (((INTVAL (operands[2]) == -256
1687 || INTVAL (operands[2]) == 65280)
1688 && rtx_equal_p (operands[1], operands[0]))
1689 || (INTVAL (operands[2]) == 255
1690 && REG_P (operands[0])))))
1692 /* See comment for andsi3. */
1693 rtx reg0 = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (HImode);
1694 rtx reg1 = operands[1];
1698 emit_move_insn (reg0, reg1);
1702 cris_emit_insn (gen_rtx_SET (reg0, gen_rtx_AND (HImode, reg1,
1705 /* Make sure we get the right destination. */
1706 if (! REG_P (operands[0]))
1707 emit_move_insn (operands[0], reg0);
1713 ;; Some fast andhi3 special cases.
1715 (define_insn "*andhi_movu"
1716 [(set (match_operand:HI 0 "register_operand" "=r,r,r")
1717 (and:HI (match_operand:HI 1 "nonimmediate_operand" "r,Q,To")
1719 (clobber (reg:CC CRIS_CC0_REGNUM))]
1720 "!side_effects_p (operands[1])"
1722 [(set_attr "slottable" "yes,yes,no")])
1724 (define_insn "*andhi_clear"
1725 [(set (match_operand:HI 0 "nonimmediate_operand" "=r,Q,To")
1726 (and:HI (match_operand:HI 1 "nonimmediate_operand" "0,0,0")
1728 (clobber (reg:CC CRIS_CC0_REGNUM))]
1729 "!side_effects_p (operands[0])"
1731 [(set_attr "slottable" "yes,yes,no")
1732 (set_attr "cc" "none")])
1734 ;; Catch-all andhi3 pattern.
1736 (define_insn "*expanded_andhi<setcc><setnz><setnzvc>"
1737 [(set (match_operand:HI 0 "register_operand" "=r,r, r,r, r,r,r,r")
1738 (and:HI (match_operand:HI 1 "register_operand" "%0,0, 0,0, 0,0,0,r")
1739 (match_operand:HI 2 "general_operand" "I,Kc,r,Q>,L,O,g,!To")))
1740 ;; The "Kc" alternative above, is there to match for cmpelim;
1741 ;; it will be dominated by the "I" alternative at other times.
1742 (clobber (reg:CC CRIS_CC0_REGNUM))]
1744 ;; Sidenote: the tightening from "general_operand" to
1745 ;; "register_operand" for operand 1 actually increased the register
1746 ;; pressure (worse code). That will hopefully change with an
1747 ;; improved reload pass.
1759 [(set_attr "slottable" "yes,yes,yes,yes,no,yes,no,no")
1760 (set_attr "cc<cccc><ccnz><ccnzvc>"
1761 "clobber,normal,normal,normal,normal,clobber,normal,normal")])
1763 ;; A strict_low_part pattern.
1765 ;; Note the use of (match_dup 0) for the first operand of the operation
1766 ;; here. Reload can't handle an operand pair where one is read-write
1767 ;; and must match a read, like in:
1769 ;; (set (strict_low_part
1770 ;; (subreg:QI (reg/v:SI 0 r0 [orig:36 data ] [36]) 0))
1772 ;; (subreg:QI (reg:SI 15 acr [orig:27 D.7531 ] [27]) 0)
1773 ;; (const_int -64 [0xf..fc0]))) x.c:126 147 {*andqi_lowpart_v32}
1775 ;; (Note: the example is obsolete.)
1776 ;; In theory, it could reload this as a movstrictqi of the register
1777 ;; operand at the and:QI to the destination register and change the
1778 ;; and:QI operand to the same as the read-write output operand and the
1779 ;; result would be recognized, but it doesn't recognize that's a valid
1780 ;; reload for a strict_low_part-destination; it just sees a "+" at the
1781 ;; destination constraints. Better than adding complexity to reload is
1782 ;; to follow the lead of m68k (see comment that begins with "These insns
1783 ;; must use MATCH_DUP") since prehistoric times and make it just a
1784 ;; match_dup. FIXME: a sanity-check in gen* to refuse an insn with
1785 ;; input-constraints matching input-output-constraints, e.g. "+r" <- "0".
1787 (define_insn "*andhi_lowpart"
1788 [(set (strict_low_part
1789 (match_operand:HI 0 "register_operand" "+r,r,r"))
1790 (and:HI (match_dup 0)
1791 (match_operand:HI 1 "general_operand" "r,Q>,g")))
1792 (clobber (reg:CC CRIS_CC0_REGNUM))]
1798 [(set_attr "slottable" "yes,yes,no")])
1800 (define_expand "andqi3"
1802 [(set (match_operand:QI 0 "register_operand")
1803 (and:QI (match_operand:QI 1 "register_operand")
1804 (match_operand:QI 2 "general_operand")))
1805 (clobber (reg:CC CRIS_CC0_REGNUM))])]
1809 (define_insn "*andqi3<setcc><setnz><setnzvc>"
1810 [(set (match_operand:QI 0 "register_operand" "=r,r, r,r, r,r,r")
1811 (and:QI (match_operand:QI 1 "register_operand" "%0,0, 0,0, 0,0,r")
1812 (match_operand:QI 2 "general_operand" "I,Kc,r,Q>,O,g,!To")))
1813 (clobber (reg:CC CRIS_CC0_REGNUM))]
1823 [(set_attr "slottable" "yes,yes,yes,yes,yes,no,no")
1824 (set_attr "cc<cccc><ccnz><ccnzvc>"
1825 "clobber,normal,normal,normal,clobber,normal,normal")])
1827 (define_insn "*andqi_lowpart"
1828 [(set (strict_low_part
1829 (match_operand:QI 0 "register_operand" "+r,r,r"))
1830 (and:QI (match_dup 0)
1831 (match_operand:QI 1 "general_operand" "r,Q>,g")))
1832 (clobber (reg:CC CRIS_CC0_REGNUM))]
1838 [(set_attr "slottable" "yes,yes,no")])
1842 ;; Same comment as anddi3 applies here - no need for such a pattern.
1844 ;; It seems there's no need to jump through hoops to get good code such as
1847 (define_expand "ior<mode>3"
1849 [(set (match_operand:BWD 0 "register_operand")
1850 (ior:BWD (match_operand:BWD 1 "register_operand")
1851 (match_operand:BWD 2 "general_operand")))
1852 (clobber (reg:CC CRIS_CC0_REGNUM))])]
1856 (define_insn "*iorsi3<setcc><setnz><setnzvc>"
1857 [(set (match_operand:SI 0 "register_operand" "=r,r,r, r,r,r")
1858 (ior:SI (match_operand:SI 1 "register_operand" "%0,0,0, 0,0,r")
1859 (match_operand:SI 2 "general_operand" "I, r,Q>,n,g,!To")))
1860 (clobber (reg:CC CRIS_CC0_REGNUM))]
1869 [(set_attr "slottable" "yes,yes,yes,no,no,no")
1870 (set_attr "cc<cccc><ccnz><ccnzvc>"
1871 "normal,normal,normal,clobber,normal,normal")])
1873 (define_insn "*iorhi3<setcc><setnz><setnzvc>"
1874 [(set (match_operand:HI 0 "register_operand" "=r,r,r, r,r,r,r")
1875 (ior:HI (match_operand:HI 1 "register_operand" "%0,0,0, 0,0,0,r")
1876 (match_operand:HI 2 "general_operand" "I,r,Q>,L,O,g,!To")))
1877 (clobber (reg:CC CRIS_CC0_REGNUM))]
1887 [(set_attr "slottable" "yes,yes,yes,no,yes,no,no")
1888 (set_attr "cc<cccc><ccnz><ccnzvc>"
1889 "clobber,normal,normal,normal,clobber,normal,normal")])
1891 (define_insn "*iorqi3<setcc><setnz><setnzvc>"
1892 [(set (match_operand:QI 0 "register_operand" "=r,r,r, r,r,r")
1893 (ior:QI (match_operand:QI 1 "register_operand" "%0,0,0, 0,0,r")
1894 (match_operand:QI 2 "general_operand" "I,r,Q>,O,g,!To")))
1895 (clobber (reg:CC CRIS_CC0_REGNUM))]
1904 [(set_attr "slottable" "yes,yes,yes,yes,no,no")
1905 (set_attr "cc<cccc><ccnz><ccnzvc>"
1906 "clobber,normal,normal,clobber,normal,normal")])
1910 ;; See comment about "anddi3" for xordi3 - no need for such a pattern.
1911 ;; FIXME: Do we really need the shorter variants?
1913 (define_insn "<acc><anz><anzvc>xorsi3<setcc><setnz><setnzvc>"
1914 [(set (match_operand:SI 0 "register_operand" "=r")
1915 (xor:SI (match_operand:SI 1 "register_operand" "%0")
1916 (match_operand:SI 2 "register_operand" "r")))
1917 (clobber (reg:CC CRIS_CC0_REGNUM))]
1920 [(set_attr "slottable" "yes")])
1922 (define_insn "xor<mode>3"
1923 [(set (match_operand:BW 0 "register_operand" "=r")
1924 (xor:BW (match_operand:BW 1 "register_operand" "%0")
1925 (match_operand:BW 2 "register_operand" "r")))
1926 (clobber (reg:CC CRIS_CC0_REGNUM))]
1929 [(set_attr "slottable" "yes")
1930 (set_attr "cc" "clobber")])
1934 ;; Questionable use, here mostly as a (slightly usable) define_expand
1937 (define_expand "negsf2"
1939 [(set (match_dup 2) (match_dup 3))
1940 (clobber (reg:CC CRIS_CC0_REGNUM))])
1941 (parallel [(set (match_operand:SF 0 "register_operand")
1942 (neg:SF (match_operand:SF 1 "register_operand")))
1944 (clobber (reg:CC CRIS_CC0_REGNUM))])]
1947 operands[2] = gen_reg_rtx (SImode);
1948 operands[3] = GEN_INT (1 << 31);
1951 (define_insn "*expanded_negsf2"
1952 [(set (match_operand:SF 0 "register_operand" "=r")
1953 (neg:SF (match_operand:SF 1 "register_operand" "0")))
1954 (use (match_operand:SI 2 "register_operand" "r"))
1955 (clobber (reg:CC CRIS_CC0_REGNUM))]
1958 [(set_attr "slottable" "yes")])
1960 ;; No "negdi2" although we could make one up that may be faster than
1961 ;; the one in libgcc.
1963 (define_insn "<anz>neg<mode>2<setnz>"
1964 [(set (match_operand:BWD 0 "register_operand" "=r")
1965 (neg:BWD (match_operand:BWD 1 "register_operand" "r")))
1966 (clobber (reg:CC CRIS_CC0_REGNUM))]
1969 [(set_attr "slottable" "yes")])
1973 ;; See comment on anddi3 - no need for a DImode pattern.
1974 ;; See also xor comment.
1976 (define_insn "<acc><anz><anzvc>one_cmplsi2<setcc><setnz><setnzvc>"
1977 [(set (match_operand:SI 0 "register_operand" "=r")
1978 (not:SI (match_operand:SI 1 "register_operand" "0")))
1979 (clobber (reg:CC CRIS_CC0_REGNUM))]
1982 [(set_attr "slottable" "yes")])
1984 (define_insn "one_cmpl<mode>2"
1985 [(set (match_operand:BW 0 "register_operand" "=r")
1986 (not:BW (match_operand:BW 1 "register_operand" "0")))
1987 (clobber (reg:CC CRIS_CC0_REGNUM))]
1990 [(set_attr "slottable" "yes")
1991 (set_attr "cc" "clobber")])
1993 ;; Arithmetic/Logical shift right (and SI left).
1995 (define_insn "<acc><anz><anzvc><shlr>si3<setcc><setnz><setnzvc>"
1996 [(set (match_operand:SI 0 "register_operand" "=r")
1997 (shift:SI (match_operand:SI 1 "register_operand" "0")
1998 (match_operand:SI 2 "nonmemory_operand" "Kcr")))
1999 (clobber (reg:CC CRIS_CC0_REGNUM))]
2002 if (REG_S_P (operands[2]))
2003 return "<slr>.d %2,%0";
2005 return "<slr>q %2,%0";
2007 [(set_attr "slottable" "yes")])
2009 ;; Since gcc gets lost, and forgets to zero-extend the source (or mask
2010 ;; the destination) when it changes shifts of lower modes into SImode,
2011 ;; it is better to make these expands an anonymous patterns instead of
2012 ;; the more correct define_insns. This occurs when gcc thinks that is
2013 ;; is better to widen to SImode and use immediate shift count.
2015 ;; FIXME: Is this legacy or still true for gcc >= 2.7.2?
2017 ;; FIXME: Can't parametrize sign_extend and zero_extend (before
2018 ;; mentioning "shiftrt"), so we need two patterns.
2019 (define_expand "ashr<mode>3"
2022 (sign_extend:SI (match_operand:BW 1 "nonimmediate_operand")))
2023 (clobber (reg:CC CRIS_CC0_REGNUM))])
2026 (zero_extend:SI (match_operand:BW 2 "nonimmediate_operand")))
2027 (clobber (reg:CC CRIS_CC0_REGNUM))])
2029 [(set (match_dup 5) (ashiftrt:SI (match_dup 3) (match_dup 4)))
2030 (clobber (reg:CC CRIS_CC0_REGNUM))])
2032 [(set (match_operand:BW 0 "general_operand")
2033 (subreg:BW (match_dup 5) 0))
2034 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2039 for (i = 3; i < 6; i++)
2040 operands[i] = gen_reg_rtx (SImode);
2043 (define_expand "lshr<mode>3"
2046 (zero_extend:SI (match_operand:BW 1 "nonimmediate_operand")))
2047 (clobber (reg:CC CRIS_CC0_REGNUM))])
2050 (zero_extend:SI (match_operand:BW 2 "nonimmediate_operand")))
2051 (clobber (reg:CC CRIS_CC0_REGNUM))])
2053 [(set (match_dup 5) (lshiftrt:SI (match_dup 3) (match_dup 4)))
2054 (clobber (reg:CC CRIS_CC0_REGNUM))])
2056 [(set (match_operand:BW 0 "general_operand")
2057 (subreg:BW (match_dup 5) 0))
2058 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2063 for (i = 3; i < 6; i++)
2064 operands[i] = gen_reg_rtx (SImode);
2067 (define_insn "*expanded_<shlr><mode>"
2068 [(set (match_operand:BW 0 "register_operand" "=r")
2069 (shiftrt:BW (match_operand:BW 1 "register_operand" "0")
2070 (match_operand:BW 2 "register_operand" "r")))
2071 (clobber (reg:CC CRIS_CC0_REGNUM))]
2074 [(set_attr "slottable" "yes")])
2076 (define_insn "*<shlr><mode>_lowpart"
2077 [(set (strict_low_part (match_operand:BW 0 "register_operand" "+r"))
2078 (shiftrt:BW (match_dup 0)
2079 (match_operand:BW 1 "register_operand" "r")))
2080 (clobber (reg:CC CRIS_CC0_REGNUM))]
2083 [(set_attr "slottable" "yes")])
2085 ;; Arithmetic/logical shift left.
2087 ;; For narrower modes than SI, we can use lslq although it makes cc
2088 ;; unusable. The win is that we do not have to reload the shift-count
2091 (define_insn "ashl<mode>3"
2092 [(set (match_operand:BW 0 "register_operand" "=r,r")
2093 (ashift:BW (match_operand:BW 1 "register_operand" "0,0")
2094 (match_operand:BW 2 "nonmemory_operand" "r,Kc")))
2095 (clobber (reg:CC CRIS_CC0_REGNUM))]
2099 (CONST_INT_P (operands[2]) && INTVAL (operands[2]) > <nbitsm1>)
2101 : (CONSTANT_P (operands[2])
2102 ? "lslq %2,%0" : "lsl<m> %2,%0");
2104 [(set_attr "slottable" "yes")
2105 (set_attr "cc" "*,clobber")])
2107 ;; A strict_low_part matcher.
2109 (define_insn "*ashl<mode>_lowpart"
2110 [(set (strict_low_part (match_operand:BW 0 "register_operand" "+r"))
2111 (ashift:BW (match_dup 0)
2112 (match_operand:HI 1 "register_operand" "r")))
2113 (clobber (reg:CC CRIS_CC0_REGNUM))]
2116 [(set_attr "slottable" "yes")])
2118 ;; Various strange insns that gcc likes.
2120 ;; Fortunately, it is simple to construct an abssf (although it may not
2121 ;; be very much used in practice).
2123 (define_insn "abssf2"
2124 [(set (match_operand:SF 0 "register_operand" "=r")
2125 (abs:SF (match_operand:SF 1 "register_operand" "0")))
2126 (clobber (reg:CC CRIS_CC0_REGNUM))]
2128 "lslq 1,%0\;lsrq 1,%0")
2130 (define_insn "abssi2"
2131 [(set (match_operand:SI 0 "register_operand" "=r")
2132 (abs:SI (match_operand:SI 1 "register_operand" "r")))
2133 (clobber (reg:CC CRIS_CC0_REGNUM))]
2136 [(set_attr "slottable" "yes")])
2138 ;; FIXME: GCC should be able to do these expansions itself.
2140 (define_expand "abs<mode>2"
2143 (sign_extend:SI (match_operand:BW 1 "general_operand")))
2144 (clobber (reg:CC CRIS_CC0_REGNUM))])
2146 [(set (match_dup 3) (abs:SI (match_dup 2)))
2147 (clobber (reg:CC CRIS_CC0_REGNUM))])
2149 [(set (match_operand:BW 0 "register_operand")
2150 (subreg:BW (match_dup 3) 0))
2151 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2153 "operands[2] = gen_reg_rtx (SImode); operands[3] = gen_reg_rtx (SImode);")
2155 (define_insn "<acc><anz><anzvc>clzsi2<setcc><setnz><setnzvc>"
2156 [(set (match_operand:SI 0 "register_operand" "=r")
2157 (clz:SI (match_operand:SI 1 "register_operand" "r")))
2158 (clobber (reg:CC CRIS_CC0_REGNUM))]
2161 [(set_attr "slottable" "yes")])
2163 (define_insn "<acc><anz><anzvc>bswapsi2<setcc><setnz><setnzvc>"
2164 [(set (match_operand:SI 0 "register_operand" "=r")
2165 (bswap:SI (match_operand:SI 1 "register_operand" "0")))
2166 (clobber (reg:CC CRIS_CC0_REGNUM))]
2169 [(set_attr "slottable" "yes")])
2171 ;; This instruction swaps all bits in a register.
2172 ;; That means that the most significant bit is put in the place
2173 ;; of the least significant bit, and so on.
2175 (define_insn "cris_swap_bits"
2176 [(set (match_operand:SI 0 "register_operand" "=r")
2177 (bitreverse:SI (match_operand:SI 1 "register_operand" "0")))
2178 (clobber (reg:CC CRIS_CC0_REGNUM))]
2181 [(set_attr "slottable" "yes")])
2183 ;; Implement ctz using two instructions, one for bit swap and one for clz.
2184 ;; Defines a scratch register to avoid clobbering input.
2186 (define_expand "ctzsi2"
2189 (match_operand:SI 1 "register_operand"))
2190 (clobber (reg:CC CRIS_CC0_REGNUM))])
2192 [(set (match_dup 2) (bitreverse:SI (match_dup 2)))
2193 (clobber (reg:CC CRIS_CC0_REGNUM))])
2195 [(set (match_operand:SI 0 "register_operand")
2196 (clz:SI (match_dup 2)))
2197 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2198 "TARGET_HAS_LZ && TARGET_HAS_SWAP"
2199 "operands[2] = gen_reg_rtx (SImode);")
2201 ;; Bound-insn. Defined to be the same as an unsigned minimum, which is an
2202 ;; operation supported by gcc. Used in casesi, but used now and then in
2205 (define_expand "uminsi3"
2207 [(set (match_operand:SI 0 "register_operand")
2208 (umin:SI (match_operand:SI 1 "register_operand")
2209 (match_operand:SI 2 "general_operand")))
2210 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2214 (define_insn "*uminsi3<setcc><setnz><setnzvc>"
2215 [(set (match_operand:SI 0 "register_operand" "=r,r, r,r")
2216 (umin:SI (match_operand:SI 1 "register_operand" "%0,0, 0,r")
2217 (match_operand:SI 2 "general_operand" "r,Q>,g,!To")))
2218 (clobber (reg:CC CRIS_CC0_REGNUM))]
2221 if (CONST_INT_P (operands[2]))
2223 /* Constant operands are zero-extended, so only 32-bit operands
2225 if (INTVAL (operands[2]) >= 0)
2227 if (INTVAL (operands[2]) < 256)
2228 return "bound.b %2,%0";
2230 if (INTVAL (operands[2]) < 65536)
2231 return "bound.w %2,%0";
2234 else if (which_alternative == 3)
2235 return "bound.d %2,%1,%0";
2237 return "bound.d %2,%0";
2239 [(set_attr "slottable" "yes,yes,no,no")])
2241 ;; Jump and branch insns.
2245 (label_ref (match_operand 0 "" "")))]
2248 [(set_attr "slottable" "has_slot")])
2250 ;; Testcase gcc.c-torture/compile/991213-3.c fails if we allow a constant
2251 ;; here, since the insn is not recognized as an indirect jump by
2252 ;; jmp_uses_reg_or_mem used by computed_jump_p. Perhaps it is a kludge to
2253 ;; change from general_operand to nonimmediate_operand (at least the docs
2254 ;; should be changed), but then again the pattern is called indirect_jump.
2255 (define_expand "indirect_jump"
2256 [(set (pc) (match_operand:SI 0 "nonimmediate_operand"))]
2260 (define_insn "*indirect_jump"
2261 [(set (pc) (match_operand:SI 0 "nonimmediate_operand" "rm"))]
2265 ;; Return insn. Used whenever the epilogue is very simple; if it is only
2266 ;; a single ret or jump [sp+]. No allocated stack space or saved
2267 ;; registers are allowed.
2268 ;; Note that for this pattern, although named, it is ok to check the
2269 ;; context of the insn in the test, not only compiler switches.
2271 (define_expand "return"
2273 "cris_simple_epilogue ()"
2274 "cris_expand_return (cris_return_address_on_stack ()); DONE;")
2276 (define_insn "*return_expanded"
2280 return cris_return_address_on_stack_for_return ()
2281 ? "jump [$sp+]" : "ret%#";
2283 [(set (attr "slottable")
2285 (match_test "cris_return_address_on_stack_for_return ()")
2287 (const_string "has_return_slot")))])
2289 (define_expand "prologue"
2292 "cris_expand_prologue (); DONE;")
2294 (define_expand "epilogue"
2297 "cris_expand_epilogue (); DONE;")
2299 ;; Conditional branches.
2301 (define_expand "cbranch<mode>4"
2305 (match_operator 0 "ordered_comparison_operator"
2306 [(match_operand:BWDD 1 "nonimmediate_operand")
2307 (match_operand:BWDD 2 "general_operand")])
2308 (label_ref (match_operand 3 ""))
2310 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2312 "cris_reduce_compare (&operands[0], &operands[1], &operands[2]);")
2314 (define_insn_and_split "*cbranch<mode><code>4"
2318 (match_operand:BWDD 0 "nonimmediate_operand" "<cmp_op0c>")
2319 (match_operand:BWDD 1 "general_operand" "<cmp_op1c>"))
2320 (label_ref (match_operand 2 ""))
2322 (clobber (reg:CC CRIS_CC0_REGNUM))]
2325 "&& reload_completed"
2326 [(set (reg:<xCC> CRIS_CC0_REGNUM)
2327 (compare:<xCC> (match_dup 0) (match_dup 1)))
2329 (if_then_else (cond (reg:<xCC> CRIS_CC0_REGNUM) (const_int 0))
2330 (label_ref (match_dup 2))
2334 ;; Test a single bit at operand[0] against 0/non-0.
2335 (define_insn_and_split "*cbranch<mode>4_btstrq1_<CC>"
2340 (match_operand:BWD 0 "register_operand" "r,r")
2342 (match_operand:SI 1 "nonmemory_operand" "Kc,r"))
2344 (label_ref (match_operand 2 ""))
2346 (clobber (reg:CC CRIS_CC0_REGNUM))]
2349 "&& reload_completed"
2350 [(set (reg:CC_ZnN CRIS_CC0_REGNUM)
2352 (zero_extract:SI (match_dup 0) (const_int 1) (match_dup 1))
2355 (if_then_else (zcond (reg:CC_ZnN CRIS_CC0_REGNUM) (const_int 0))
2356 (label_ref (match_dup 2))
2360 ;; Test a field of bits starting at bit 0 against 0/non-0.
2361 (define_insn_and_split "*cbranch<mode>4_btstqb0_<CC>"
2366 (match_operand:BWD 0 "register_operand" "r")
2367 (match_operand 1 "const_int_operand" "Kc")
2370 (label_ref (match_operand 2 ""))
2372 (clobber (reg:CC CRIS_CC0_REGNUM))]
2375 "&& reload_completed"
2376 [(set (reg:CC_NZ CRIS_CC0_REGNUM)
2378 (zero_extract:SI (match_dup 0) (match_dup 1) (const_int 0))
2381 (if_then_else (zcond (reg:CC_NZ CRIS_CC0_REGNUM) (const_int 0))
2382 (label_ref (match_dup 2))
2387 ;; We suffer from the same overflow-bit-gets-in-the-way problem as
2388 ;; e.g. m68k, so we have to check if overflow bit is set on all "signed"
2391 (define_insn "*b<zcond:code><mode>"
2393 (if_then_else (zcond (reg:ZnNNZUSE CRIS_CC0_REGNUM)
2395 (label_ref (match_operand 0 "" ""))
2399 return <MODE>mode == CC_ZnNmode ? "b<znnCC> %l0%#" : "b<CC> %l0%#";
2401 [(set_attr "slottable" "has_slot")])
2403 (define_insn "*b<nzvccond:code><mode>"
2405 (if_then_else (nzvccond (reg:NZVCUSE CRIS_CC0_REGNUM)
2407 (label_ref (match_operand 0 "" ""))
2411 [(set_attr "slottable" "has_slot")])
2413 (define_insn "*b<rnzcond:code><mode>"
2415 (if_then_else (rnzcond (reg:NZUSE CRIS_CC0_REGNUM)
2417 (label_ref (match_operand 0 "" ""))
2421 return <MODE>mode == CC_NZmode ? "b<oCC> %l0%#": "b<CC> %l0%#";
2423 [(set_attr "slottable" "has_slot")])
2425 ;; Reversed anonymous patterns to the ones above, as mandated.
2427 (define_insn "*b<nzcond:code>_reversed<mode>"
2429 (if_then_else (nzcond (reg:ZnNNZUSE CRIS_CC0_REGNUM)
2432 (label_ref (match_operand 0 "" ""))))]
2435 return <MODE>mode == CC_ZnNmode ? "b<rznnCC> %l0%#" : "b<rCC> %l0%#";
2437 [(set_attr "slottable" "has_slot")])
2439 (define_insn "*b<nzvccond:code>_reversed<mode>"
2441 (if_then_else (nzvccond (reg:NZVCUSE CRIS_CC0_REGNUM)
2444 (label_ref (match_operand 0 "" ""))))]
2447 [(set_attr "slottable" "has_slot")])
2449 (define_insn "*b<rnzcond:code>_reversed<mode>"
2451 (if_then_else (rnzcond (reg:NZUSE CRIS_CC0_REGNUM)
2454 (label_ref (match_operand 0 "" ""))))]
2457 return <MODE>mode == CC_NZmode ? "b<roCC> %l0%#" : "b<rCC> %l0%#";
2459 [(set_attr "slottable" "has_slot")])
2461 ;; Set on condition: sCC.
2463 (define_expand "cstore<mode>4"
2465 [(set (match_operand:SI 0 "register_operand")
2466 (match_operator:SI 1 "ordered_comparison_operator"
2467 [(match_operand:BWDD 2 "nonimmediate_operand")
2468 (match_operand:BWDD 3 "general_operand")]))
2469 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2471 "cris_reduce_compare (&operands[1], &operands[2], &operands[3]);")
2473 (define_insn_and_split "*cstore<mode><code>4"
2474 [(set (match_operand:SI 0 "register_operand" "=<sCC_destc>")
2476 (match_operand:BWDD 1 "nonimmediate_operand" "<cmp_op0c>")
2477 (match_operand:BWDD 2 "general_operand" "<cmp_op1c>")))
2478 (clobber (reg:CC CRIS_CC0_REGNUM))]
2481 "&& reload_completed"
2482 [(set (reg:<xCC> CRIS_CC0_REGNUM)
2483 (compare:<xCC> (match_dup 1) (match_dup 2)))
2485 (cond:SI (reg:<xCC> CRIS_CC0_REGNUM) (const_int 0)))]
2488 ;; Like bCC, we have to check the overflow bit for
2489 ;; signed conditions.
2491 (define_insn "*s<nzcond:code><mode>"
2492 [(set (match_operand:SI 0 "register_operand" "=r")
2493 (nzcond:SI (reg:NZUSE CRIS_CC0_REGNUM) (const_int 0)))]
2496 [(set_attr "slottable" "yes")
2497 (set_attr "cc" "none")])
2499 (define_insn "*s<rnzcond:code><mode>"
2500 [(set (match_operand:SI 0 "register_operand" "=r")
2501 (rnzcond:SI (reg:NZUSE CRIS_CC0_REGNUM) (const_int 0)))]
2504 return <MODE>mode == CC_NZmode ? "s<oCC> %0" : "s<CC> %0";
2506 [(set_attr "slottable" "yes")
2507 (set_attr "cc" "none")])
2509 (define_insn "*s<nzvccond:code><mode>"
2510 [(set (match_operand:SI 0 "register_operand" "=r")
2511 (nzvccond:SI (reg:NZVCUSE CRIS_CC0_REGNUM) (const_int 0)))]
2514 [(set_attr "slottable" "yes")
2515 (set_attr "cc" "none")])
2519 ;; We need to make these patterns "expand", since the real operand is
2520 ;; hidden in a (mem:QI ) inside operand[0] (call_value: operand[1]),
2521 ;; and cannot be checked if it were a "normal" pattern.
2522 ;; Note that "call" and "call_value" are *always* called with a
2523 ;; mem-operand for operand 0 and 1 respective. What happens for combined
2524 ;; instructions is a different issue.
2526 (define_expand "call"
2527 [(parallel [(call (match_operand:SI 0 "indirect_operand")
2528 (match_operand 1 "general_operand"))
2529 (clobber (reg:SI CRIS_SRP_REGNUM))])]
2532 operands[1] = const0_rtx;
2535 ;; Accept operands for operand 0 in order of preference.
2537 (define_insn "*expanded_call"
2538 [(call (mem:QI (match_operand:SI 0 "general_operand" "r,Q>,g"))
2540 (clobber (reg:SI CRIS_SRP_REGNUM))]
2544 (define_expand "call_value"
2545 [(parallel [(set (match_operand 0 "")
2546 (call (match_operand:SI 1 "indirect_operand")
2547 (match_operand 2 "")))
2548 (clobber (reg:SI CRIS_SRP_REGNUM))])]
2551 operands[2] = const0_rtx;
2554 ;; The validity other than "general" of
2555 ;; operand 0 will be checked elsewhere. Accept operands for operand 1 in
2556 ;; order of preference (Q includes r, but r is shorter, faster).
2557 ;; We also accept a PLT symbol. We output it as [rPIC+sym:GOTPLT] rather
2558 ;; than requiring getting rPIC + sym:PLT into a register.
2560 (define_insn "*expanded_call_value"
2561 [(set (match_operand 0 "nonimmediate_operand" "=g,g,g")
2562 (call (mem:QI (match_operand:SI 1 "general_operand" "r,Q>,g"))
2564 (clobber (reg:SI CRIS_SRP_REGNUM))]
2567 [(set_attr "cc" "clobber")])
2569 ;; Used in debugging. No use for the direct pattern; unfilled
2570 ;; delayed-branches are taken care of by other means.
2576 [(set_attr "cc" "none")])
2578 ;; Same as the gdb trap breakpoint: would cause a SIGTRAP for
2579 ;; cris-linux* and will work in freestanding environments with
2580 ;; sufficient framework.
2582 [(trap_if (const_int 1) (const_int 8))]
2583 "TARGET_TRAP_USING_BREAK8"
2586 ;; We need to stop accesses to the stack after the memory is
2587 ;; deallocated. Unfortunately, reorg doesn't look at naked clobbers,
2588 ;; e.g. (insn ... (clobber (mem:BLK (stack_pointer_rtx)))) and we don't
2589 ;; want to use a naked (unspec_volatile) as that would stop any
2590 ;; scheduling in the epilogue. Hence we model it as a "real" insn that
2591 ;; sets the memory in an unspecified manner. FIXME: Unfortunately it
2592 ;; still has the effect of an unspec_volatile.
2593 (define_insn "cris_frame_deallocated_barrier"
2594 [(set (mem:BLK (reg:SI CRIS_SP_REGNUM))
2595 (unspec:BLK [(const_int 0)] CRIS_UNSPEC_FRAME_DEALLOC))]
2598 [(set_attr "length" "0")])
2600 ;; We expand on casesi so we can use "bound" and "add offset fetched from
2601 ;; a table to pc" (adds.w [pc+%0.w],pc).
2603 ;; Note: if you change the "parallel" (or add anything after it) in
2604 ;; this expansion, you must change the macro ASM_OUTPUT_CASE_END
2605 ;; accordingly, to add the default case at the end of the jump-table.
2607 (define_expand "casesi"
2609 [(set (match_dup 5) (match_operand:SI 0 "general_operand"))
2610 (clobber (reg:CC CRIS_CC0_REGNUM))])
2613 (minus:SI (match_dup 5)
2614 (match_operand:SI 1 "const_int_operand")))
2615 (clobber (reg:CC CRIS_CC0_REGNUM))])
2618 (umin:SI (match_dup 6)
2619 (match_operand:SI 2 "const_int_operand")))
2620 (clobber (reg:CC CRIS_CC0_REGNUM))])
2624 (ltu (match_dup 7) (match_dup 2))
2625 (plus:SI (sign_extend:SI
2627 (plus:SI (mult:SI (match_dup 7) (const_int 2))
2630 (label_ref (match_operand 4 ""))))
2631 (use (label_ref (match_operand 3 "")))
2632 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2635 operands[2] = plus_constant (SImode, operands[2], 1);
2636 operands[5] = gen_reg_rtx (SImode);
2637 operands[6] = gen_reg_rtx (SImode);
2638 operands[7] = gen_reg_rtx (SImode);
2643 ;; Various peephole optimizations.
2645 ;; Do not add patterns that you do not know will be matched.
2646 ;; Please also add a self-contained testcase.
2648 ;; We have trouble with and:s and shifts. Maybe something is broken in
2649 ;; gcc? Or it could just be that bit-field insn expansion is a bit
2650 ;; suboptimal when not having extzv insns. Or combine being over-eager
2651 ;; to canonicalize to "and", and ignorant on the benefits of the right
2652 ;; mixture of "and" and "zero-extend".
2654 ;; Testcase for the following peephole: gcc.target/cris/peep2-movulsr.c
2656 ;; Where equivalent and where the "and" argument doesn't fit "andq" but
2657 ;; is 16 bits or smaller, replace the "and" with a zero-extend preceding
2658 ;; the shift. A zero-extend is shorter and faster than "and" with a
2661 (define_peephole2 ; movulsr
2663 [(set (match_operand:SI 0 "register_operand")
2664 (lshiftrt:SI (match_dup 0)
2665 (match_operand:SI 1 "const_int_operand")))
2666 (clobber (reg:CC CRIS_CC0_REGNUM))])
2669 (and:SI (match_dup 0)
2670 (match_operand 2 "const_int_operand")))
2671 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2672 "INTVAL (operands[2]) > 31 && INTVAL (operands[2]) <= 0xffff
2673 && (((INTVAL (operands[2]) <= 0xff ? 0xff : 0xffff) >> INTVAL (operands[1]))
2674 == INTVAL (operands[2]))"
2676 ;; The zero-extend is expressed as an "and", only because that's easier
2677 ;; than messing with zero-extend of a subreg.
2678 [(set (match_dup 0) (and:SI (match_dup 0) (match_dup 3)))
2679 (clobber (reg:CC CRIS_CC0_REGNUM))])
2681 [(set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 1)))
2682 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2685 = INTVAL (operands[2]) <= 0xff ? GEN_INT (0xff) : GEN_INT (0xffff);
2688 ;; Avoid, after opsplit1 with AND (below), sequences of:
2692 ;; (N < M), where we can fold the first lsrq into the lslq-lsrq, like:
2695 ;; We have to match this before opsplit1 below and before other peephole2s of
2696 ;; lesser value, since peephole2 matching resumes at the first generated insn,
2697 ;; and thus wouldn't match a pattern of the three shifts after opsplit1/AND.
2698 ;; Note that this lsrandsplit1 is in turn of lesser value than movulsr, since
2699 ;; that one doesn't require the same operand for source and destination, but
2700 ;; they happen to be the same hard-register at peephole2 time even if
2701 ;; naturally separated like in peep2-movulsr2.c, thus this placement. (Source
2702 ;; and destination will be re-separated and the move optimized out in
2703 ;; cprop_hardreg at time of this writing.)
2704 ;; Testcase: gcc.target/cris/peep2-lsrandsplit1.c
2705 (define_peephole2 ; lsrandsplit1
2707 [(set (match_operand:SI 0 "register_operand")
2709 (match_operand:SI 1 "register_operand")
2710 (match_operand:SI 2 "const_int_operand")))
2711 (clobber (reg:CC CRIS_CC0_REGNUM))])
2713 [(set (match_operand 3 "register_operand")
2715 (match_operand 4 "register_operand")
2716 (match_operand 5 "const_int_operand")))
2717 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2718 "REGNO (operands[0]) == REGNO (operands[1])
2719 && REGNO (operands[0]) == REGNO (operands[3])
2720 && REGNO (operands[0]) == REGNO (operands[4])
2721 && (INTVAL (operands[2])
2722 < (clz_hwi (INTVAL (operands[5])) - (HOST_BITS_PER_WIDE_INT - 32)))
2723 && cris_splittable_constant_p (INTVAL (operands[5]), AND, SImode,
2724 optimize_function_for_speed_p (cfun)) == 2"
2725 ;; We're guaranteed by the above hw_clz test (certainly non-zero) and the
2726 ;; test for a two-insn return-value from cris_splittable_constant_p, that
2727 ;; the cris_splittable_constant_p AND-replacement would be lslq-lsrq.
2729 [(set (match_dup 0) (ashift:SI (match_dup 0) (match_dup 9)))
2730 (clobber (reg:CC CRIS_CC0_REGNUM))])
2732 [(set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 10)))
2733 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2735 HOST_WIDE_INT shiftval
2736 = clz_hwi (INTVAL (operands[5])) - (HOST_BITS_PER_WIDE_INT - 32);
2737 operands[9] = GEN_INT (shiftval - INTVAL (operands[2]));
2738 operands[10] = GEN_INT (shiftval);
2741 ;; Testcase for the following four peepholes: gcc.target/cris/peep2-xsrand.c
2743 (define_peephole2 ; asrandb
2745 [(set (match_operand:SI 0 "register_operand")
2746 (ashiftrt:SI (match_dup 0)
2747 (match_operand:SI 1 "const_int_operand")))
2748 (clobber (reg:CC CRIS_CC0_REGNUM))])
2751 (and:SI (match_dup 0)
2752 (match_operand 2 "const_int_operand")))
2753 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2754 "INTVAL (operands[2]) > 31
2755 && INTVAL (operands[2]) < 255
2756 && INTVAL (operands[1]) > 23
2757 /* Check that the and-operation enables us to use logical-shift. */
2758 && (INTVAL (operands[2])
2759 & ((HOST_WIDE_INT) (HOST_WIDE_INT_M1U
2760 << (32 - INTVAL (operands[1]))))) == 0"
2762 [(set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 1)))
2763 (clobber (reg:CC CRIS_CC0_REGNUM))])
2765 [(set (match_dup 3) (and:QI (match_dup 3) (match_dup 4)))
2766 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2768 operands[3] = gen_rtx_REG (QImode, REGNO (operands[0]));
2769 operands[4] = GEN_INT (trunc_int_for_mode (INTVAL (operands[2]), QImode));
2772 (define_peephole2 ; asrandw
2774 [(set (match_operand:SI 0 "register_operand")
2775 (ashiftrt:SI (match_dup 0)
2776 (match_operand:SI 1 "const_int_operand")))
2777 (clobber (reg:CC CRIS_CC0_REGNUM))])
2780 (and:SI (match_dup 0) (match_operand 2 "const_int_operand")))
2781 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2782 "INTVAL (operands[2]) > 31
2783 && INTVAL (operands[2]) < 65535
2784 && INTVAL (operands[2]) != 255
2785 && INTVAL (operands[1]) > 15
2786 /* Check that the and-operation enables us to use logical-shift. */
2787 && (INTVAL (operands[2])
2788 & ((HOST_WIDE_INT) (HOST_WIDE_INT_M1U
2789 << (32 - INTVAL (operands[1]))))) == 0"
2791 [(set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 1)))
2792 (clobber (reg:CC CRIS_CC0_REGNUM))])
2794 [(set (match_dup 3) (and:HI (match_dup 3) (match_dup 4)))
2795 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2797 operands[3] = gen_rtx_REG (HImode, REGNO (operands[0]));
2798 operands[4] = GEN_INT (trunc_int_for_mode (INTVAL (operands[2]), HImode));
2801 (define_peephole2 ; lsrandb
2803 [(set (match_operand:SI 0 "register_operand")
2804 (lshiftrt:SI (match_dup 0)
2805 (match_operand:SI 1 "const_int_operand")))
2806 (clobber (reg:CC CRIS_CC0_REGNUM))])
2809 (and:SI (match_dup 0) (match_operand 2 "const_int_operand")))
2810 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2811 "INTVAL (operands[2]) > 31
2812 && INTVAL (operands[2]) < 255
2813 && INTVAL (operands[1]) > 23"
2815 [(set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 1)))
2816 (clobber (reg:CC CRIS_CC0_REGNUM))])
2818 [(set (match_dup 3) (and:QI (match_dup 3) (match_dup 4)))
2819 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2821 operands[3] = gen_rtx_REG (QImode, REGNO (operands[0]));
2822 operands[4] = GEN_INT (trunc_int_for_mode (INTVAL (operands[2]), QImode));
2825 (define_peephole2 ; lsrandw
2827 [(set (match_operand:SI 0 "register_operand")
2828 (lshiftrt:SI (match_dup 0)
2829 (match_operand:SI 1 "const_int_operand")))
2830 (clobber (reg:CC CRIS_CC0_REGNUM))])
2833 (and:SI (match_dup 0) (match_operand 2 "const_int_operand")))
2834 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2835 "INTVAL (operands[2]) > 31 && INTVAL (operands[2]) < 65535
2836 && INTVAL (operands[2]) != 255
2837 && INTVAL (operands[1]) > 15"
2839 [(set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 1)))
2840 (clobber (reg:CC CRIS_CC0_REGNUM))])
2842 [(set (match_dup 3) (and:HI (match_dup 3) (match_dup 4)))
2843 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2845 operands[3] = gen_rtx_REG (HImode, REGNO (operands[0]));
2846 operands[4] = GEN_INT (trunc_int_for_mode (INTVAL (operands[2]), HImode));
2849 ;; There seems to be no other way to make GCC (including 4.8/trunk at
2850 ;; r186932) optimally reload an instruction that looks like
2851 ;; and.d reg_or_mem,const_32__65535,other_reg
2852 ;; where other_reg is the destination.
2854 ;; movu.[bw] reg_or_mem,reg_32
2855 ;; and.[bw] trunc_int_for_mode([bw], const_32__65535),reg_32 ;; or andq
2856 ;; but it turns into:
2857 ;; move.d reg_or_mem,reg_32
2858 ;; and.d const_32__65535,reg_32
2859 ;; Fix it with these two peephole2's.
2860 ;; Testcases: gcc.target/cris/peep2-andu1.c gcc.target/cris/peep2-andu2.c
2862 (define_peephole2 ; andu
2864 [(set (match_operand:SI 0 "register_operand")
2865 (match_operand:SI 1 "nonimmediate_operand"))
2866 (clobber (reg:CC CRIS_CC0_REGNUM))])
2868 [(set (match_operand:SI 2 "register_operand")
2869 (and:SI (match_dup 0)
2870 (match_operand:SI 3 "const_int_operand")))
2871 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2872 ;; Since the size of the memory access could be made different here,
2873 ;; don't do this for a mem-volatile access.
2874 "REGNO (operands[2]) == REGNO (operands[0])
2875 && INTVAL (operands[3]) <= 65535 && INTVAL (operands[3]) >= 0
2876 && !satisfies_constraint_I (operands[3])
2877 && !side_effects_p (operands[1])
2878 && (!REG_P (operands[1])
2879 || REGNO (operands[1]) <= CRIS_LAST_GENERAL_REGISTER)"
2881 [(set (match_dup 0) (match_dup 4))
2882 (clobber (reg:CC CRIS_CC0_REGNUM))])
2884 [(set (match_dup 5) (match_dup 6))
2885 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2887 machine_mode zmode = INTVAL (operands[3]) <= 255 ? QImode : HImode;
2889 = satisfies_constraint_O (operands[3]) ? SImode : zmode;
2891 = (REG_S_P (operands[1])
2892 ? gen_rtx_REG (zmode, REGNO (operands[1]))
2893 : adjust_address (operands[1], zmode, 0));
2895 = gen_rtx_ZERO_EXTEND (SImode, op1);
2896 operands[5] = gen_rtx_REG (amode, REGNO (operands[0]));
2898 = gen_rtx_AND (amode, gen_rtx_REG (amode, REGNO (operands[0])),
2899 GEN_INT (trunc_int_for_mode (INTVAL (operands[3]),
2901 ? QImode : amode)));
2904 ;; Since r186861, gcc.target/cris/peep2-andu2.c trigs this pattern, with which
2911 ;; Only do this for values fitting the quick immediate operand.
2912 (define_peephole2 ; andqu
2914 [(set (match_operand:SI 0 "register_operand")
2915 (match_operand:SI 1 "const_int_operand"))
2916 (clobber (reg:CC CRIS_CC0_REGNUM))])
2919 (and:SI (match_dup 0) (match_operand:SI 2 "nonimmediate_operand")))
2920 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2921 ;; Since the size of the memory access will be made different here,
2922 ;; don't do this for a volatile access or a post-incremented address.
2923 "satisfies_constraint_O (operands[1])
2924 && !side_effects_p (operands[2])
2925 && !reg_overlap_mentioned_p (operands[0], operands[2])"
2927 [(set (match_dup 0) (match_dup 3))
2928 (clobber (reg:CC CRIS_CC0_REGNUM))])
2930 [(set (match_dup 0) (and:SI (match_dup 0) (match_dup 4)))
2931 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2933 machine_mode zmode = INTVAL (operands[1]) <= 255 ? QImode : HImode;
2935 = (REG_S_P (operands[2])
2936 ? gen_rtx_REG (zmode, REGNO (operands[2]))
2937 : adjust_address (operands[2], zmode, 0));
2938 operands[3] = gen_rtx_ZERO_EXTEND (SImode, op1);
2939 operands[4] = GEN_INT (trunc_int_for_mode (INTVAL (operands[1]), QImode));
2942 ;; Somewhat similar to andqu, but a different range and expansion,
2943 ;; intended to feed the output into opsplit1 with AND:
2944 ;; move.d 0x7ffff,$r10
2948 ;; and.d 0x7ffff,$r10
2949 ;; which opsplit1/AND will change into:
2950 ;; move.d $r11,$r10 (unaffected by opsplit1/AND; shown only for context)
2953 ;; thereby winning in space, but in time only if the 0x7ffff happened to
2954 ;; be unaligned in the code.
2955 (define_peephole2 ; movandsplit1
2957 [(set (match_operand 0 "register_operand")
2958 (match_operand 1 "const_int_operand"))
2959 (clobber (reg:CC CRIS_CC0_REGNUM))])
2961 [(set (match_operand 2 "register_operand")
2962 (and (match_operand 3 "register_operand")
2963 (match_operand 4 "register_operand")))
2964 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2965 "REGNO (operands[0]) == REGNO (operands[2])
2966 && REGNO (operands[0]) == REGNO (operands[3])
2967 && cris_splittable_constant_p (INTVAL (operands[1]), AND,
2968 GET_MODE (operands[2]),
2969 optimize_function_for_speed_p (cfun))"
2971 [(set (match_dup 2) (match_dup 4))
2972 (clobber (reg:CC CRIS_CC0_REGNUM))])
2974 [(set (match_dup 2) (match_dup 5))
2975 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2977 operands[5] = gen_rtx_AND (GET_MODE (operands[2]), operands[2], operands[1]);
2980 ;; Large (read: non-quick) numbers can sometimes be AND:ed by other means.
2981 ;; Testcase: gcc.target/cris/peep2-andsplit1.c
2983 ;; Another case is add<ext> N,rx with -126..-64,64..126: it has the same
2984 ;; size and execution time as two addq or subq, but addq and subq can fill
2986 (define_peephole2 ; opsplit1
2988 [(set (match_operand 0 "register_operand")
2990 (match_operand 1 "register_operand")
2991 (match_operand 2 "const_int_operand")))
2992 (clobber (reg:CC CRIS_CC0_REGNUM))])]
2993 ;; Operands 0 and 1 can be separate identical objects, at least
2994 ;; after matching peepholes above. */
2995 "REGNO (operands[0]) == REGNO (operands[1])
2996 && cris_splittable_constant_p (INTVAL (operands[2]), <CODE>,
2997 GET_MODE (operands[0]),
2998 optimize_function_for_speed_p (cfun))"
3001 cris_split_constant (INTVAL (operands[2]), <CODE>, GET_MODE (operands[0]),
3002 optimize_function_for_speed_p (cfun),
3003 true, operands[0], operands[0]);
3007 ;; Fix a decomposed szext: fuse it with the memory operand of the
3008 ;; load. This is typically the sign-extension part of a decomposed
3009 ;; "indirect offset" address.
3010 (define_peephole2 ; lra_szext_decomposed
3012 [(set (match_operand:BW 0 "register_operand")
3013 (match_operand:BW 1 "memory_operand"))
3014 (clobber (reg:CC CRIS_CC0_REGNUM))])
3016 [(set (match_operand:SI 2 "register_operand") (szext:SI (match_dup 0)))
3017 (clobber (reg:CC CRIS_CC0_REGNUM))])]
3018 "REGNO (operands[0]) == REGNO (operands[2])
3019 || peep2_reg_dead_p (2, operands[0])"
3021 [(set (match_dup 2) (szext:SI (match_dup 1)))
3022 (clobber (reg:CC CRIS_CC0_REGNUM))])])
3024 ;; Re-compose a decomposed "indirect offset" address for a szext
3025 ;; operation. The non-clobbering "addi" is generated by LRA.
3026 ;; This and lra_szext_decomposed is covered by cris/rld-legit1.c.
3027 (define_peephole2 ; lra_szext_decomposed_indirect_with_offset
3029 [(set (match_operand:SI 0 "register_operand")
3030 (sign_extend:SI (mem:BW (match_operand:SI 1 "register_operand"))))
3031 (clobber (reg:CC CRIS_CC0_REGNUM))])
3033 (plus:SI (match_dup 0) (match_operand:SI 2 "register_operand")))
3035 [(set (match_operand:SI 3 "register_operand")
3036 (szext:SI (mem:BW2 (match_dup 0))))
3037 (clobber (reg:CC CRIS_CC0_REGNUM))])]
3038 "(REGNO (operands[0]) == REGNO (operands[3])
3039 || peep2_reg_dead_p (3, operands[0]))
3040 && (REGNO (operands[0]) == REGNO (operands[1])
3041 || peep2_reg_dead_p (3, operands[0]))"
3046 (mem:BW2 (plus:SI (szext:SI (mem:BW (match_dup 1))) (match_dup 2)))))
3047 (clobber (reg:CC CRIS_CC0_REGNUM))])])
3049 ;; Add operations with similar or same decomposed addresses here, when
3050 ;; encountered - but only when covered by mentioned test-cases for at
3051 ;; least one of the cases generalized in the pattern.
3055 ;; comment-start: ";; "
3056 ;; eval: (set-syntax-table (copy-sequence (syntax-table)))
3057 ;; eval: (modify-syntax-entry ?[ "(]")
3058 ;; eval: (modify-syntax-entry ?] ")[")
3059 ;; eval: (modify-syntax-entry ?{ "(}")
3060 ;; eval: (modify-syntax-entry ?} "){")
3061 ;; eval: (setq indent-tabs-mode t)