OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [gcc/] [config/] [cris/] [cris.md] - Blame information for rev 154

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.