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