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