OSDN Git Service

* config/alpha/alpha.md (sibcall_osf_1_er): New.
[pf3gnuchains/gcc-fork.git] / gcc / config / alpha / alpha.md
1 ;; Machine description for DEC Alpha for GNU C compiler
2 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 ;; 2000, 2001 Free Software Foundation, Inc.
4 ;; Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
5 ;;
6 ;; This file is part of GNU CC.
7 ;;
8 ;; GNU CC is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; any later version.
12 ;;
13 ;; GNU CC 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 GNU CC; see the file COPYING.  If not, write to
20 ;; the Free Software Foundation, 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
22
23 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
24
25 ;; Uses of UNSPEC in this file:
26
27 (define_constants
28   [(UNSPEC_ARG_HOME     0)
29    (UNSPEC_CTTZ         1)
30    (UNSPEC_INSXH        2)
31    (UNSPEC_MSKXH        3)
32    (UNSPEC_CVTQL        4)
33    (UNSPEC_NT_LDA       5)
34    (UNSPEC_UMK_LAUM     6)
35    (UNSPEC_UMK_LALM     7)
36    (UNSPEC_UMK_LAL      8)
37    (UNSPEC_UMK_LOAD_CIW 9)
38    (UNSPEC_LDGP2        10)
39    (UNSPEC_LITERAL      11)
40    (UNSPEC_LITUSE       12)
41   ])
42
43 ;; UNSPEC_VOLATILE:
44
45 (define_constants
46   [(UNSPECV_IMB         0)
47    (UNSPECV_BLOCKAGE    1)
48    (UNSPECV_SETJMPR     2)      ; builtin_setjmp_receiver
49    (UNSPECV_LONGJMP     3)      ; builtin_longjmp
50    (UNSPECV_TRAPB       4)
51    (UNSPECV_PSPL        5)      ; prologue_stack_probe_loop
52    (UNSPECV_REALIGN     6)
53    (UNSPECV_EHR         7)      ; exception_receiver
54    (UNSPECV_MCOUNT      8)
55    (UNSPECV_FORCE_MOV   9)
56    (UNSPECV_LDGP1       10)
57    (UNSPECV_PLDGP2      11)     ; prologue ldgp
58   ])
59
60 ;; Where necessary, the suffixes _le and _be are used to distinguish between
61 ;; little-endian and big-endian patterns.
62 ;;
63 ;; Note that the Unicos/Mk assembler does not support the following
64 ;; opcodes: mov, fmov, nop, fnop, unop.
65 \f
66 ;; Processor type -- this attribute must exactly match the processor_type
67 ;; enumeration in alpha.h.
68
69 (define_attr "cpu" "ev4,ev5,ev6"
70   (const (symbol_ref "alpha_cpu")))
71
72 ;; Define an insn type attribute.  This is used in function unit delay
73 ;; computations, among other purposes.  For the most part, we use the names
74 ;; defined in the EV4 documentation, but add a few that we have to know about
75 ;; separately.
76
77 (define_attr "type"
78   "ild,fld,ldsym,ist,fst,ibr,fbr,jsr,iadd,ilog,shift,icmov,fcmov,icmp,imul,\
79 fadd,fmul,fcpys,fdiv,fsqrt,misc,mvi,ftoi,itof,multi"
80   (const_string "iadd"))
81
82 ;; Describe a user's asm statement.
83 (define_asm_attributes
84   [(set_attr "type" "multi")])
85
86 ;; Define the operand size an insn operates on.  Used primarily by mul
87 ;; and div operations that have size dependent timings.
88
89 (define_attr "opsize" "si,di,udi"
90   (const_string "di"))
91
92 ;; The TRAP attribute marks instructions that may generate traps
93 ;; (which are imprecise and may need a trapb if software completion
94 ;; is desired).
95
96 (define_attr "trap" "no,yes"
97   (const_string "no"))
98
99 ;; The ROUND_SUFFIX attribute marks which instructions require a
100 ;; rounding-mode suffix.  The value NONE indicates no suffix,
101 ;; the value NORMAL indicates a suffix controled by alpha_fprm.
102
103 (define_attr "round_suffix" "none,normal,c"
104   (const_string "none"))
105
106 ;; The TRAP_SUFFIX attribute marks instructions requiring a trap-mode suffix:
107 ;;   NONE       no suffix
108 ;;   SU         accepts only /su (cmpt et al)
109 ;;   SUI        accepts only /sui (cvtqt and cvtqs)
110 ;;   V_SV       accepts /v and /sv (cvtql only)
111 ;;   V_SV_SVI   accepts /v, /sv and /svi (cvttq only)
112 ;;   U_SU_SUI   accepts /u, /su and /sui (most fp instructions)
113 ;;
114 ;; The actual suffix emitted is controled by alpha_fptm.
115
116 (define_attr "trap_suffix" "none,su,sui,v_sv,v_sv_svi,u_su_sui"
117   (const_string "none"))
118
119 ;; The length of an instruction sequence in bytes.
120
121 (define_attr "length" ""
122   (const_int 4))
123 \f
124 ;; On EV4 there are two classes of resources to consider: resources needed
125 ;; to issue, and resources needed to execute.  IBUS[01] are in the first
126 ;; category.  ABOX, BBOX, EBOX, FBOX, IMUL & FDIV make up the second.
127 ;; (There are a few other register-like resources, but ...)
128
129 ; First, describe all of the issue constraints with single cycle delays.
130 ; All insns need a bus, but all except loads require one or the other.
131 (define_function_unit "ev4_ibus0" 1 0
132   (and (eq_attr "cpu" "ev4")
133        (eq_attr "type" "fst,fbr,iadd,imul,ilog,shift,icmov,icmp"))
134   1 1)
135
136 (define_function_unit "ev4_ibus1" 1 0
137   (and (eq_attr "cpu" "ev4")
138        (eq_attr "type" "ist,ibr,jsr,fadd,fcmov,fcpys,fmul,fdiv,misc"))
139   1 1)
140
141 ; Memory delivers its result in three cycles.  Actually return one and
142 ; take care of this in adjust_cost, since we want to handle user-defined
143 ; memory latencies.
144 (define_function_unit "ev4_abox" 1 0
145   (and (eq_attr "cpu" "ev4")
146        (eq_attr "type" "ild,fld,ldsym,ist,fst"))
147   1 1)
148
149 ; Branches have no delay cost, but do tie up the unit for two cycles.
150 (define_function_unit "ev4_bbox" 1 1
151   (and (eq_attr "cpu" "ev4")
152        (eq_attr "type" "ibr,fbr,jsr"))
153   2 2)
154
155 ; Arithmetic insns are normally have their results available after
156 ; two cycles.  There are a number of exceptions.  They are encoded in
157 ; ADJUST_COST.  Some of the other insns have similar exceptions.
158 (define_function_unit "ev4_ebox" 1 0
159   (and (eq_attr "cpu" "ev4")
160        (eq_attr "type" "iadd,ilog,shift,icmov,icmp,misc"))
161   2 1)
162
163 (define_function_unit "imul" 1 0
164   (and (eq_attr "cpu" "ev4")
165        (and (eq_attr "type" "imul")
166             (eq_attr "opsize" "si")))
167   21 19)
168
169 (define_function_unit "imul" 1 0
170   (and (eq_attr "cpu" "ev4")
171        (and (eq_attr "type" "imul")
172             (eq_attr "opsize" "!si")))
173   23 21)
174
175 (define_function_unit "ev4_fbox" 1 0
176   (and (eq_attr "cpu" "ev4")
177        (eq_attr "type" "fadd,fmul,fcpys,fcmov"))
178   6 1)
179
180 (define_function_unit "fdiv" 1 0
181   (and (eq_attr "cpu" "ev4")
182        (and (eq_attr "type" "fdiv")
183             (eq_attr "opsize" "si")))
184   34 30)
185
186 (define_function_unit "fdiv" 1 0
187   (and (eq_attr "cpu" "ev4")
188        (and (eq_attr "type" "fdiv")
189             (eq_attr "opsize" "di")))
190   63 59)
191 \f
192 ;; EV5 scheduling.  EV5 can issue 4 insns per clock.
193 ;;
194 ;; EV5 has two asymetric integer units.  Model this with E0 & E1 along
195 ;; with the combined resource EBOX.
196
197 (define_function_unit "ev5_ebox" 2 0
198   (and (eq_attr "cpu" "ev5")
199        (eq_attr "type" "!fbr,fcmov,fadd,fmul,fcpys,fdiv"))
200   1 1)
201
202 ; Memory takes at least 2 clocks.  Return one from here and fix up with
203 ; user-defined latencies in adjust_cost.
204 (define_function_unit "ev5_ebox" 2 0
205   (and (eq_attr "cpu" "ev5")
206        (eq_attr "type" "ild,fld,ldsym"))
207   1 1)
208
209 ; Loads can dual issue with one another, but loads and stores do not mix.
210 (define_function_unit "ev5_e0" 1 0
211   (and (eq_attr "cpu" "ev5")
212        (eq_attr "type" "ild,fld,ldsym"))
213   1 1
214   [(eq_attr "type" "ist,fst")])
215
216 ; Stores, shifts, multiplies can only issue to E0
217 (define_function_unit "ev5_e0" 1 0
218   (and (eq_attr "cpu" "ev5")
219        (eq_attr "type" "ist,fst,shift,imul"))
220   1 1)
221
222 ; Motion video insns also issue only to E0, and take two ticks.
223 (define_function_unit "ev5_e0" 1 0
224   (and (eq_attr "cpu" "ev5")
225        (eq_attr "type" "mvi"))
226   2 1)
227
228 ; Conditional moves always take 2 ticks.
229 (define_function_unit "ev5_ebox" 2 0
230   (and (eq_attr "cpu" "ev5")
231        (eq_attr "type" "icmov"))
232   2 1)
233
234 ; Branches can only issue to E1
235 (define_function_unit "ev5_e1" 1 0
236   (and (eq_attr "cpu" "ev5")
237        (eq_attr "type" "ibr,jsr"))
238   1 1)
239
240 ; Multiplies also use the integer multiplier.
241 ; ??? How to: "No instruction can be issued to pipe E0 exactly two
242 ; cycles before an integer multiplication completes."
243 (define_function_unit "imul" 1 0
244   (and (eq_attr "cpu" "ev5")
245        (and (eq_attr "type" "imul")
246             (eq_attr "opsize" "si")))
247   8 4)
248
249 (define_function_unit "imul" 1 0
250   (and (eq_attr "cpu" "ev5")
251        (and (eq_attr "type" "imul")
252             (eq_attr "opsize" "di")))
253   12 8)
254
255 (define_function_unit "imul" 1 0
256   (and (eq_attr "cpu" "ev5")
257        (and (eq_attr "type" "imul")
258             (eq_attr "opsize" "udi")))
259   14 8)
260
261 ;; Similarly for the FPU we have two asymetric units.  But fcpys can issue
262 ;; on either so we have to play the game again.
263
264 (define_function_unit "ev5_fbox" 2 0
265   (and (eq_attr "cpu" "ev5")
266        (eq_attr "type" "fadd,fcmov,fmul,fcpys,fbr,fdiv"))
267   4 1)
268
269 (define_function_unit "ev5_fm" 1 0
270   (and (eq_attr "cpu" "ev5")
271        (eq_attr "type" "fmul"))
272   4 1)
273
274 ; Add and cmov as you would expect; fbr never produces a result;
275 ; fdiv issues through fa to the divider,
276 (define_function_unit "ev5_fa" 1 0
277   (and (eq_attr "cpu" "ev5")
278        (eq_attr "type" "fadd,fcmov,fbr,fdiv"))
279   4 1)
280
281 ; ??? How to: "No instruction can be issued to pipe FA exactly five
282 ; cycles before a floating point divide completes."
283 (define_function_unit "fdiv" 1 0
284   (and (eq_attr "cpu" "ev5")
285        (and (eq_attr "type" "fdiv")
286             (eq_attr "opsize" "si")))
287   15 15)                                ; 15 to 31 data dependent
288
289 (define_function_unit "fdiv" 1 0
290   (and (eq_attr "cpu" "ev5")
291        (and (eq_attr "type" "fdiv")
292             (eq_attr "opsize" "di")))
293   22 22)                                ; 22 to 60 data dependent
294 \f
295 ;; EV6 scheduling.  EV6 can issue 4 insns per clock.
296 ;;
297 ;; EV6 has two symmetric pairs ("clusters") of two asymetric integer units
298 ;; ("upper" and "lower"), yielding pipe names U0, U1, L0, L1.
299
300 ;; Conditional moves decompose into two independent primitives, each
301 ;; taking one cycle.  Since ev6 is out-of-order, we can't see anything
302 ;; but two cycles.
303 (define_function_unit "ev6_ebox" 4 0
304   (and (eq_attr "cpu" "ev6")
305        (eq_attr "type" "icmov"))
306   2 1)
307
308 (define_function_unit "ev6_ebox" 4 0
309   (and (eq_attr "cpu" "ev6")
310        (eq_attr "type" "!fbr,fcmov,fadd,fmul,fcpys,fdiv,fsqrt"))
311   1 1)
312
313 ;; Integer loads take at least 3 clocks, and only issue to lower units.
314 ;; Return one from here and fix up with user-defined latencies in adjust_cost.
315 (define_function_unit "ev6_l" 2 0
316   (and (eq_attr "cpu" "ev6")
317        (eq_attr "type" "ild,ldsym,ist,fst"))
318   1 1)
319
320 ;; FP loads take at least 4 clocks.  Return two from here...
321 (define_function_unit "ev6_l" 2 0
322   (and (eq_attr "cpu" "ev6")
323        (eq_attr "type" "fld"))
324   2 1)
325
326 ;; Motion video insns also issue only to U0, and take three ticks.
327 (define_function_unit "ev6_u0" 1 0
328   (and (eq_attr "cpu" "ev6")
329        (eq_attr "type" "mvi"))
330   3 1)
331
332 (define_function_unit "ev6_u" 2 0
333   (and (eq_attr "cpu" "ev6")
334        (eq_attr "type" "mvi"))
335   3 1)
336
337 ;; Shifts issue to either upper pipe.
338 (define_function_unit "ev6_u" 2 0
339   (and (eq_attr "cpu" "ev6")
340        (eq_attr "type" "shift"))
341   1 1)
342
343 ;; Multiplies issue only to U1, and all take 7 ticks.
344 ;; Rather than create a new function unit just for U1, reuse IMUL
345 (define_function_unit "imul" 1 0
346   (and (eq_attr "cpu" "ev6")
347        (eq_attr "type" "imul"))
348   7 1)
349
350 (define_function_unit "ev6_u" 2 0
351   (and (eq_attr "cpu" "ev6")
352        (eq_attr "type" "imul"))
353   7 1)
354
355 ;; Branches issue to either upper pipe
356 (define_function_unit "ev6_u" 2 0
357   (and (eq_attr "cpu" "ev6")
358        (eq_attr "type" "ibr"))
359   3 1)
360
361 ;; Calls only issue to L0.
362 (define_function_unit "ev6_l0" 1 0
363   (and (eq_attr "cpu" "ev6")
364        (eq_attr "type" "jsr"))
365   1 1)
366
367 (define_function_unit "ev6_l" 2 0
368   (and (eq_attr "cpu" "ev6")
369        (eq_attr "type" "jsr"))
370   1 1)
371
372 ;; Ftoi/itof only issue to lower pipes
373 (define_function_unit "ev6_l" 2 0
374   (and (eq_attr "cpu" "ev6")
375        (eq_attr "type" "ftoi"))
376   3 1)
377
378 (define_function_unit "ev6_l" 2 0
379   (and (eq_attr "cpu" "ev6")
380        (eq_attr "type" "itof"))
381   4 1)
382
383 ;; For the FPU we are very similar to EV5, except there's no insn that
384 ;; can issue to fm & fa, so we get to leave that out.
385
386 (define_function_unit "ev6_fm" 1 0
387   (and (eq_attr "cpu" "ev6")
388        (eq_attr "type" "fmul"))
389   4 1)
390
391 (define_function_unit "ev6_fa" 1 0
392   (and (eq_attr "cpu" "ev6")
393        (eq_attr "type" "fadd,fcpys,fbr,fdiv,fsqrt"))
394   4 1)
395
396 (define_function_unit "ev6_fa" 1 0
397   (and (eq_attr "cpu" "ev6")
398        (eq_attr "type" "fcmov"))
399   8 1)
400
401 (define_function_unit "fdiv" 1 0
402   (and (eq_attr "cpu" "ev6")
403        (and (eq_attr "type" "fdiv")
404             (eq_attr "opsize" "si")))
405   12 10)
406
407 (define_function_unit "fdiv" 1 0
408   (and (eq_attr "cpu" "ev6")
409        (and (eq_attr "type" "fdiv")
410             (eq_attr "opsize" "di")))
411   15 13)
412
413 (define_function_unit "fsqrt" 1 0
414   (and (eq_attr "cpu" "ev6")
415        (and (eq_attr "type" "fsqrt")
416             (eq_attr "opsize" "si")))
417   16 14)
418
419 (define_function_unit "fsqrt" 1 0
420   (and (eq_attr "cpu" "ev6")
421        (and (eq_attr "type" "fsqrt")
422             (eq_attr "opsize" "di")))
423   32 30)
424
425 ; ??? The FPU communicates with memory and the integer register file
426 ; via two fp store units.  We need a slot in the fst immediately, and
427 ; a slot in LOW after the operand data is ready.  At which point the
428 ; data may be moved either to the store queue or the integer register
429 ; file and the insn retired.
430
431 \f
432 ;; First define the arithmetic insns.  Note that the 32-bit forms also
433 ;; sign-extend.
434
435 ;; Handle 32-64 bit extension from memory to a floating point register
436 ;; specially, since this occurs frequently in int->double conversions.
437 ;;
438 ;; Note that while we must retain the =f case in the insn for reload's
439 ;; benefit, it should be eliminated after reload, so we should never emit
440 ;; code for that case.  But we don't reject the possibility.
441
442 (define_expand "extendsidi2"
443   [(set (match_operand:DI 0 "register_operand" "")
444         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "")))]
445   ""
446   "")
447
448 (define_insn "*extendsidi2_nofix"
449   [(set (match_operand:DI 0 "register_operand" "=r,r,*f,?*f")
450         (sign_extend:DI
451           (match_operand:SI 1 "nonimmediate_operand" "r,m,*f,m")))]
452   "! TARGET_FIX"
453   "@
454    addl %1,$31,%0
455    ldl %0,%1
456    cvtlq %1,%0
457    lds %0,%1\;cvtlq %0,%0"
458   [(set_attr "type" "iadd,ild,fadd,fld")
459    (set_attr "length" "*,*,*,8")])
460
461 (define_insn "*extendsidi2_fix"
462   [(set (match_operand:DI 0 "register_operand" "=r,r,r,*f,?*f")
463         (sign_extend:DI
464           (match_operand:SI 1 "nonimmediate_operand" "r,m,*f,*f,m")))]
465   "TARGET_FIX"
466   "@
467    addl %1,$31,%0
468    ldl %0,%1
469    ftois %1,%0
470    cvtlq %1,%0
471    lds %0,%1\;cvtlq %0,%0"
472   [(set_attr "type" "iadd,ild,ftoi,fadd,fld")
473    (set_attr "length" "*,*,*,*,8")])
474
475 ;; Due to issues with CLASS_CANNOT_CHANGE_SIZE, we cannot use a subreg here.
476 (define_split
477   [(set (match_operand:DI 0 "hard_fp_register_operand" "")
478         (sign_extend:DI (match_operand:SI 1 "memory_operand" "")))]
479   "reload_completed"
480   [(set (match_dup 2) (match_dup 1))
481    (set (match_dup 0) (sign_extend:DI (match_dup 2)))]
482   "operands[2] = gen_rtx_REG (SImode, REGNO (operands[0]));")
483
484 ;; Optimize sign-extension of SImode loads.  This shows up in the wake of
485 ;; reload when converting fp->int.
486
487 (define_peephole2
488   [(set (match_operand:SI 0 "hard_int_register_operand" "")
489         (match_operand:SI 1 "memory_operand" ""))
490    (set (match_operand:DI 2 "hard_int_register_operand" "")
491         (sign_extend:DI (match_dup 0)))]
492   "true_regnum (operands[0]) == true_regnum (operands[2])
493    || peep2_reg_dead_p (2, operands[0])"
494   [(set (match_dup 2)
495         (sign_extend:DI (match_dup 1)))]
496   "")
497
498 (define_peephole2
499   [(set (match_operand:SI 0 "hard_int_register_operand" "")
500         (match_operand:SI 1 "hard_fp_register_operand" ""))
501    (set (match_operand:DI 2 "hard_int_register_operand" "")
502         (sign_extend:DI (match_dup 0)))]
503   "TARGET_FIX
504    && (true_regnum (operands[0]) == true_regnum (operands[2])
505        || peep2_reg_dead_p (2, operands[0]))"
506   [(set (match_dup 2)
507         (sign_extend:DI (match_dup 1)))]
508   "")
509
510 (define_peephole2
511   [(set (match_operand:DI 0 "hard_fp_register_operand" "")
512         (sign_extend:DI (match_operand:SI 1 "hard_fp_register_operand" "")))
513    (set (match_operand:DI 2 "hard_int_register_operand" "")
514         (match_dup 0))]
515   "TARGET_FIX && peep2_reg_dead_p (2, operands[0])"
516   [(set (match_dup 2)
517         (sign_extend:DI (match_dup 1)))]
518   "")
519
520 ;; Do addsi3 the way expand_binop would do if we didn't have one.  This
521 ;; generates better code.  We have the anonymous addsi3 pattern below in
522 ;; case combine wants to make it.
523 (define_expand "addsi3"
524   [(set (match_operand:SI 0 "register_operand" "")
525         (plus:SI (match_operand:SI 1 "reg_or_0_operand" "")
526                  (match_operand:SI 2 "add_operand" "")))]
527   ""
528 {
529   if (optimize)
530     {
531       rtx op1 = gen_lowpart (DImode, operands[1]);
532       rtx op2 = gen_lowpart (DImode, operands[2]);
533
534       if (! cse_not_expected)
535         {
536           rtx tmp = gen_reg_rtx (DImode);
537           emit_insn (gen_adddi3 (tmp, op1, op2));
538           emit_move_insn (gen_lowpart (DImode, operands[0]), tmp);
539         }
540       else
541         emit_insn (gen_adddi3 (gen_lowpart (DImode, operands[0]), op1, op2));
542       DONE;
543     }
544 })
545
546 (define_insn "*addsi_internal"
547   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
548         (plus:SI (match_operand:SI 1 "reg_or_0_operand" "%rJ,rJ,rJ,rJ")
549                  (match_operand:SI 2 "add_operand" "rI,O,K,L")))]
550   ""
551   "@
552    addl %r1,%2,%0
553    subl %r1,%n2,%0
554    lda %0,%2(%r1)
555    ldah %0,%h2(%r1)")
556
557 (define_split
558   [(set (match_operand:SI 0 "register_operand" "")
559         (plus:SI (match_operand:SI 1 "register_operand" "")
560                  (match_operand:SI 2 "const_int_operand" "")))]
561   "! add_operand (operands[2], SImode)"
562   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 3)))
563    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 4)))]
564 {
565   HOST_WIDE_INT val = INTVAL (operands[2]);
566   HOST_WIDE_INT low = (val & 0xffff) - 2 * (val & 0x8000);
567   HOST_WIDE_INT rest = val - low;
568
569   operands[3] = GEN_INT (rest);
570   operands[4] = GEN_INT (low);
571 })
572
573 (define_insn "*addsi_se"
574   [(set (match_operand:DI 0 "register_operand" "=r,r")
575         (sign_extend:DI
576          (plus:SI (match_operand:SI 1 "reg_or_0_operand" "%rJ,rJ")
577                   (match_operand:SI 2 "sext_add_operand" "rI,O"))))]
578   ""
579   "@
580    addl %r1,%2,%0
581    subl %r1,%n2,%0")
582
583 (define_split
584   [(set (match_operand:DI 0 "register_operand" "")
585         (sign_extend:DI
586          (plus:SI (match_operand:SI 1 "reg_not_elim_operand" "")
587                   (match_operand:SI 2 "const_int_operand" ""))))
588    (clobber (match_operand:SI 3 "reg_not_elim_operand" ""))]
589   "! sext_add_operand (operands[2], SImode) && INTVAL (operands[2]) > 0
590    && INTVAL (operands[2]) % 4 == 0"
591   [(set (match_dup 3) (match_dup 4))
592    (set (match_dup 0) (sign_extend:DI (plus:SI (mult:SI (match_dup 3)
593                                                         (match_dup 5))
594                                                (match_dup 1))))]
595 {
596   HOST_WIDE_INT val = INTVAL (operands[2]) / 4;
597   int mult = 4;
598
599   if (val % 2 == 0)
600     val /= 2, mult = 8;
601
602   operands[4] = GEN_INT (val);
603   operands[5] = GEN_INT (mult);
604 })
605
606 (define_split
607   [(set (match_operand:DI 0 "register_operand" "")
608         (sign_extend:DI
609          (plus:SI (match_operator:SI 1 "comparison_operator"
610                                      [(match_operand 2 "" "")
611                                       (match_operand 3 "" "")])
612                   (match_operand:SI 4 "add_operand" ""))))
613    (clobber (match_operand:DI 5 "register_operand" ""))]
614   ""
615   [(set (match_dup 5) (match_dup 6))
616    (set (match_dup 0) (sign_extend:DI (plus:SI (match_dup 7) (match_dup 4))))]
617 {
618   operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[1]), DImode,
619                                 operands[2], operands[3]);
620   operands[7] = gen_lowpart (SImode, operands[5]);
621 })
622
623 (define_insn "addvsi3"
624   [(set (match_operand:SI 0 "register_operand" "=r,r")
625         (plus:SI (match_operand:SI 1 "reg_or_0_operand" "%rJ,rJ")
626                  (match_operand:SI 2 "sext_add_operand" "rI,O")))
627    (trap_if (ne (plus:DI (sign_extend:DI (match_dup 1))
628                          (sign_extend:DI (match_dup 2)))
629                 (sign_extend:DI (plus:SI (match_dup 1)
630                                          (match_dup 2))))
631             (const_int 0))]
632   ""
633   "@
634    addlv %r1,%2,%0
635    sublv %r1,%n2,%0")
636
637 (define_expand "adddi3"
638   [(set (match_operand:DI 0 "register_operand" "")
639         (plus:DI (match_operand:DI 1 "register_operand" "")
640                  (match_operand:DI 2 "add_operand" "")))]
641   ""
642   "")
643
644 (define_insn "*adddi_er_high_l"
645   [(set (match_operand:DI 0 "register_operand" "=r")
646         (plus:DI (match_operand:DI 1 "register_operand" "r")
647                  (high:DI (match_operand:DI 2 "local_symbolic_operand" ""))))]
648   "TARGET_EXPLICIT_RELOCS"
649   "ldah %0,%2(%1)\t\t!gprelhigh")
650
651 ;; We used to expend quite a lot of effort choosing addq/subq/lda.
652 ;; With complications like
653 ;;
654 ;;   The NT stack unwind code can't handle a subq to adjust the stack
655 ;;   (that's a bug, but not one we can do anything about).  As of NT4.0 SP3,
656 ;;   the exception handling code will loop if a subq is used and an
657 ;;   exception occurs.
658 ;;
659 ;;   The 19980616 change to emit prologues as RTL also confused some
660 ;;   versions of GDB, which also interprets prologues.  This has been
661 ;;   fixed as of GDB 4.18, but it does not harm to unconditionally
662 ;;   use lda here.
663 ;;
664 ;; and the fact that the three insns schedule exactly the same, it's
665 ;; just not worth the effort.
666
667 (define_insn "*adddi_internal"
668   [(set (match_operand:DI 0 "register_operand" "=r,r,r")
669         (plus:DI (match_operand:DI 1 "register_operand" "%r,r,r")
670                  (match_operand:DI 2 "add_operand" "r,K,L")))]
671   ""
672   "@
673    addq %1,%2,%0
674    lda %0,%2(%1)
675    ldah %0,%h2(%1)")
676
677 ;; ??? Allow large constants when basing off the frame pointer or some
678 ;; virtual register that may eliminate to the frame pointer.  This is
679 ;; done because register elimination offsets will change the hi/lo split,
680 ;; and if we split before reload, we will require additional instructions.
681
682 (define_insn "*adddi_fp_hack"
683   [(set (match_operand:DI 0 "register_operand" "=r")
684         (plus:DI (match_operand:DI 1 "reg_no_subreg_operand" "r")
685                  (match_operand:DI 2 "const_int_operand" "n")))]
686   "NONSTRICT_REG_OK_FP_BASE_P (operands[1])
687    && INTVAL (operands[2]) >= 0
688    /* This is the largest constant an lda+ldah pair can add, minus
689       an upper bound on the displacement between SP and AP during
690       register elimination.  See INITIAL_ELIMINATION_OFFSET.  */
691    && INTVAL (operands[2])
692         < (0x7fff8000
693            - FIRST_PSEUDO_REGISTER * UNITS_PER_WORD
694            - ALPHA_ROUND(current_function_outgoing_args_size)
695            - (ALPHA_ROUND (get_frame_size ()
696                            + max_reg_num () * UNITS_PER_WORD
697                            + current_function_pretend_args_size)
698               - current_function_pretend_args_size))"
699   "#")
700
701 ;; Don't do this if we are adjusting SP since we don't want to do it
702 ;; in two steps.  Don't split FP sources for the reason listed above.
703 (define_split
704   [(set (match_operand:DI 0 "register_operand" "")
705         (plus:DI (match_operand:DI 1 "register_operand" "")
706                  (match_operand:DI 2 "const_int_operand" "")))]
707   "! add_operand (operands[2], DImode)
708    && operands[0] != stack_pointer_rtx
709    && operands[1] != frame_pointer_rtx
710    && operands[1] != arg_pointer_rtx"
711   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 3)))
712    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 4)))]
713 {
714   HOST_WIDE_INT val = INTVAL (operands[2]);
715   HOST_WIDE_INT low = (val & 0xffff) - 2 * (val & 0x8000);
716   HOST_WIDE_INT rest = val - low;
717
718   operands[4] = GEN_INT (low);
719   if (CONST_OK_FOR_LETTER_P (rest, 'L'))
720     operands[3] = GEN_INT (rest);
721   else if (! no_new_pseudos)
722     {
723       operands[3] = gen_reg_rtx (DImode);
724       emit_move_insn (operands[3], operands[2]);
725       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
726       DONE;
727     }
728   else
729     FAIL;
730 })
731
732 (define_insn "*saddl"
733   [(set (match_operand:SI 0 "register_operand" "=r,r")
734         (plus:SI (mult:SI (match_operand:SI 1 "reg_not_elim_operand" "r,r")
735                           (match_operand:SI 2 "const48_operand" "I,I"))
736                  (match_operand:SI 3 "sext_add_operand" "rI,O")))]
737   ""
738   "@
739    s%2addl %1,%3,%0
740    s%2subl %1,%n3,%0")
741
742 (define_insn "*saddl_se"
743   [(set (match_operand:DI 0 "register_operand" "=r,r")
744         (sign_extend:DI
745          (plus:SI (mult:SI (match_operand:SI 1 "reg_not_elim_operand" "r,r")
746                            (match_operand:SI 2 "const48_operand" "I,I"))
747                   (match_operand:SI 3 "sext_add_operand" "rI,O"))))]
748   ""
749   "@
750    s%2addl %1,%3,%0
751    s%2subl %1,%n3,%0")
752
753 (define_split
754   [(set (match_operand:DI 0 "register_operand" "")
755         (sign_extend:DI
756          (plus:SI (mult:SI (match_operator:SI 1 "comparison_operator"
757                                               [(match_operand 2 "" "")
758                                                (match_operand 3 "" "")])
759                            (match_operand:SI 4 "const48_operand" ""))
760                   (match_operand:SI 5 "sext_add_operand" ""))))
761    (clobber (match_operand:DI 6 "reg_not_elim_operand" ""))]
762   ""
763   [(set (match_dup 6) (match_dup 7))
764    (set (match_dup 0)
765         (sign_extend:DI (plus:SI (mult:SI (match_dup 8) (match_dup 4))
766                                  (match_dup 5))))]
767 {
768   operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[1]), DImode,
769                                 operands[2], operands[3]);
770   operands[8] = gen_lowpart (SImode, operands[6]);
771 })
772
773 (define_insn "*saddq"
774   [(set (match_operand:DI 0 "register_operand" "=r,r")
775         (plus:DI (mult:DI (match_operand:DI 1 "reg_not_elim_operand" "r,r")
776                           (match_operand:DI 2 "const48_operand" "I,I"))
777                  (match_operand:DI 3 "sext_add_operand" "rI,O")))]
778   ""
779   "@
780    s%2addq %1,%3,%0
781    s%2subq %1,%n3,%0")
782
783 (define_insn "addvdi3"
784   [(set (match_operand:DI 0 "register_operand" "=r,r")
785         (plus:DI (match_operand:DI 1 "reg_or_0_operand" "%rJ,rJ")
786                  (match_operand:DI 2 "sext_add_operand" "rI,O")))
787    (trap_if (ne (plus:TI (sign_extend:TI (match_dup 1))
788                          (sign_extend:TI (match_dup 2)))
789                 (sign_extend:TI (plus:DI (match_dup 1)
790                                          (match_dup 2))))
791             (const_int 0))]
792   ""
793   "@
794    addqv %r1,%2,%0
795    subqv %r1,%n2,%0")
796
797 (define_insn "negsi2"
798   [(set (match_operand:SI 0 "register_operand" "=r")
799         (neg:SI (match_operand:SI 1 "reg_or_8bit_operand" "rI")))]
800   ""
801   "subl $31,%1,%0")
802
803 (define_insn "*negsi_se"
804   [(set (match_operand:DI 0 "register_operand" "=r")
805         (sign_extend:DI (neg:SI
806                          (match_operand:SI 1 "reg_or_8bit_operand" "rI"))))]
807   ""
808   "subl $31,%1,%0")
809
810 (define_insn "negvsi2"
811   [(set (match_operand:SI 0 "register_operand" "=r")
812         (neg:SI (match_operand:SI 1 "register_operand" "r")))
813    (trap_if (ne (neg:DI (sign_extend:DI (match_dup 1)))
814                 (sign_extend:DI (neg:SI (match_dup 1))))
815             (const_int 0))]
816   ""
817   "sublv $31,%1,%0")
818
819 (define_insn "negdi2"
820   [(set (match_operand:DI 0 "register_operand" "=r")
821         (neg:DI (match_operand:DI 1 "reg_or_8bit_operand" "rI")))]
822   ""
823   "subq $31,%1,%0")
824
825 (define_insn "negvdi2"
826   [(set (match_operand:DI 0 "register_operand" "=r")
827         (neg:DI (match_operand:DI 1 "register_operand" "r")))
828    (trap_if (ne (neg:TI (sign_extend:TI (match_dup 1)))
829                 (sign_extend:TI (neg:DI (match_dup 1))))
830             (const_int 0))]
831   ""
832   "subqv $31,%1,%0")
833
834 (define_expand "subsi3"
835   [(set (match_operand:SI 0 "register_operand" "")
836         (minus:SI (match_operand:SI 1 "reg_or_0_operand" "")
837                   (match_operand:SI 2 "reg_or_8bit_operand" "")))]
838   ""
839 {
840   if (optimize)
841     {
842       rtx op1 = gen_lowpart (DImode, operands[1]);
843       rtx op2 = gen_lowpart (DImode, operands[2]);
844
845       if (! cse_not_expected)
846         {
847           rtx tmp = gen_reg_rtx (DImode);
848           emit_insn (gen_subdi3 (tmp, op1, op2));
849           emit_move_insn (gen_lowpart (DImode, operands[0]), tmp);
850         }
851       else
852         emit_insn (gen_subdi3 (gen_lowpart (DImode, operands[0]), op1, op2));
853       DONE;
854     }
855 })
856
857 (define_insn "*subsi_internal"
858   [(set (match_operand:SI 0 "register_operand" "=r")
859         (minus:SI (match_operand:SI 1 "reg_or_0_operand" "rJ")
860                   (match_operand:SI 2 "reg_or_8bit_operand" "rI")))]
861   ""
862   "subl %r1,%2,%0")
863
864 (define_insn "*subsi_se"
865   [(set (match_operand:DI 0 "register_operand" "=r")
866         (sign_extend:DI (minus:SI (match_operand:SI 1 "reg_or_0_operand" "rJ")
867                                   (match_operand:SI 2 "reg_or_8bit_operand" "rI"))))]
868   ""
869   "subl %r1,%2,%0")
870
871 (define_insn "subvsi3"
872   [(set (match_operand:SI 0 "register_operand" "=r")
873         (minus:SI (match_operand:SI 1 "reg_or_0_operand" "rJ")
874                   (match_operand:SI 2 "reg_or_8bit_operand" "rI")))
875    (trap_if (ne (minus:DI (sign_extend:DI (match_dup 1))
876                           (sign_extend:DI (match_dup 2)))
877                 (sign_extend:DI (minus:SI (match_dup 1)
878                                           (match_dup 2))))
879             (const_int 0))]
880   ""
881   "sublv %r1,%2,%0")
882
883 (define_insn "subdi3"
884   [(set (match_operand:DI 0 "register_operand" "=r")
885         (minus:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
886                   (match_operand:DI 2 "reg_or_8bit_operand" "rI")))]
887   ""
888   "subq %r1,%2,%0")
889
890 (define_insn "*ssubl"
891   [(set (match_operand:SI 0 "register_operand" "=r")
892         (minus:SI (mult:SI (match_operand:SI 1 "reg_not_elim_operand" "r")
893                            (match_operand:SI 2 "const48_operand" "I"))
894                   (match_operand:SI 3 "reg_or_8bit_operand" "rI")))]
895   ""
896   "s%2subl %1,%3,%0")
897
898 (define_insn "*ssubl_se"
899   [(set (match_operand:DI 0 "register_operand" "=r")
900         (sign_extend:DI
901          (minus:SI (mult:SI (match_operand:SI 1 "reg_not_elim_operand" "r")
902                             (match_operand:SI 2 "const48_operand" "I"))
903                    (match_operand:SI 3 "reg_or_8bit_operand" "rI"))))]
904   ""
905   "s%2subl %1,%3,%0")
906
907 (define_insn "*ssubq"
908   [(set (match_operand:DI 0 "register_operand" "=r")
909         (minus:DI (mult:DI (match_operand:DI 1 "reg_not_elim_operand" "r")
910                            (match_operand:DI 2 "const48_operand" "I"))
911                   (match_operand:DI 3 "reg_or_8bit_operand" "rI")))]
912   ""
913   "s%2subq %1,%3,%0")
914
915 (define_insn "subvdi3"
916   [(set (match_operand:DI 0 "register_operand" "=r")
917         (minus:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
918                   (match_operand:DI 2 "reg_or_8bit_operand" "rI")))
919    (trap_if (ne (minus:TI (sign_extend:TI (match_dup 1))
920                           (sign_extend:TI (match_dup 2)))
921                 (sign_extend:TI (minus:DI (match_dup 1)
922                                           (match_dup 2))))
923             (const_int 0))]
924   ""
925   "subqv %r1,%2,%0")
926
927 ;; The Unicos/Mk assembler doesn't support mull.
928
929 (define_insn "mulsi3"
930   [(set (match_operand:SI 0 "register_operand" "=r")
931         (mult:SI (match_operand:SI 1 "reg_or_0_operand" "%rJ")
932                  (match_operand:SI 2 "reg_or_8bit_operand" "rI")))]
933   "!TARGET_ABI_UNICOSMK"
934   "mull %r1,%2,%0"
935   [(set_attr "type" "imul")
936    (set_attr "opsize" "si")])
937
938 (define_insn "*mulsi_se"
939   [(set (match_operand:DI 0 "register_operand" "=r")
940         (sign_extend:DI
941           (mult:SI (match_operand:SI 1 "reg_or_0_operand" "%rJ")
942                    (match_operand:SI 2 "reg_or_8bit_operand" "rI"))))]
943   "!TARGET_ABI_UNICOSMK"
944   "mull %r1,%2,%0"
945   [(set_attr "type" "imul")
946    (set_attr "opsize" "si")])
947
948 (define_insn "mulvsi3"
949   [(set (match_operand:SI 0 "register_operand" "=r")
950         (mult:SI (match_operand:SI 1 "reg_or_0_operand" "%rJ")
951                  (match_operand:SI 2 "reg_or_8bit_operand" "rI")))
952    (trap_if (ne (mult:DI (sign_extend:DI (match_dup 1))
953                          (sign_extend:DI (match_dup 2)))
954                 (sign_extend:DI (mult:SI (match_dup 1)
955                                          (match_dup 2))))
956             (const_int 0))]
957   "!TARGET_ABI_UNICOSMK"
958   "mullv %r1,%2,%0"
959   [(set_attr "type" "imul")
960    (set_attr "opsize" "si")])
961
962 (define_insn "muldi3"
963   [(set (match_operand:DI 0 "register_operand" "=r")
964         (mult:DI (match_operand:DI 1 "reg_or_0_operand" "%rJ")
965                  (match_operand:DI 2 "reg_or_8bit_operand" "rI")))]
966   ""
967   "mulq %r1,%2,%0"
968   [(set_attr "type" "imul")])
969
970 (define_insn "mulvdi3"
971   [(set (match_operand:DI 0 "register_operand" "=r")
972         (mult:DI (match_operand:DI 1 "reg_or_0_operand" "%rJ")
973                  (match_operand:DI 2 "reg_or_8bit_operand" "rI")))
974    (trap_if (ne (mult:TI (sign_extend:TI (match_dup 1))
975                          (sign_extend:TI (match_dup 2)))
976                 (sign_extend:TI (mult:DI (match_dup 1)
977                                          (match_dup 2))))
978             (const_int 0))]
979   ""
980   "mulqv %r1,%2,%0"
981   [(set_attr "type" "imul")])
982
983 (define_insn "umuldi3_highpart"
984   [(set (match_operand:DI 0 "register_operand" "=r")
985         (truncate:DI
986          (lshiftrt:TI
987           (mult:TI (zero_extend:TI
988                      (match_operand:DI 1 "reg_or_0_operand" "%rJ"))
989                    (zero_extend:TI
990                      (match_operand:DI 2 "reg_or_8bit_operand" "rI")))
991           (const_int 64))))]
992   ""
993   "umulh %r1,%2,%0"
994   [(set_attr "type" "imul")
995    (set_attr "opsize" "udi")])
996
997 (define_insn "*umuldi3_highpart_const"
998   [(set (match_operand:DI 0 "register_operand" "=r")
999         (truncate:DI
1000          (lshiftrt:TI
1001           (mult:TI (zero_extend:TI (match_operand:DI 1 "register_operand" "r"))
1002                    (match_operand:TI 2 "cint8_operand" "I"))
1003           (const_int 64))))]
1004   ""
1005   "umulh %1,%2,%0"
1006   [(set_attr "type" "imul")
1007    (set_attr "opsize" "udi")])
1008 \f
1009 ;; The divide and remainder operations take their inputs from r24 and
1010 ;; r25, put their output in r27, and clobber r23 and r28 on all
1011 ;; systems except Unicos/Mk. On Unicos, the standard library provides
1012 ;; subroutines which use the standard calling convention and work on
1013 ;; DImode operands.
1014
1015 ;; ??? Force sign-extension here because some versions of OSF/1 and
1016 ;; Interix/NT don't do the right thing if the inputs are not properly
1017 ;; sign-extended.  But Linux, for instance, does not have this
1018 ;; problem.  Is it worth the complication here to eliminate the sign
1019 ;; extension?
1020
1021 (define_expand "divsi3"
1022   [(set (match_dup 3)
1023         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "")))
1024    (set (match_dup 4)
1025         (sign_extend:DI (match_operand:SI 2 "nonimmediate_operand" "")))
1026    (parallel [(set (match_dup 5)
1027                    (sign_extend:DI (div:SI (match_dup 3) (match_dup 4))))
1028               (clobber (reg:DI 23))
1029               (clobber (reg:DI 28))])
1030    (set (match_operand:SI 0 "nonimmediate_operand" "")
1031         (subreg:SI (match_dup 5) 0))]
1032   "! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK"
1033 {
1034   operands[3] = gen_reg_rtx (DImode);
1035   operands[4] = gen_reg_rtx (DImode);
1036   operands[5] = gen_reg_rtx (DImode);
1037 })
1038
1039 (define_expand "udivsi3"
1040   [(set (match_dup 3)
1041         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "")))
1042    (set (match_dup 4)
1043         (sign_extend:DI (match_operand:SI 2 "nonimmediate_operand" "")))
1044    (parallel [(set (match_dup 5)
1045                    (sign_extend:DI (udiv:SI (match_dup 3) (match_dup 4))))
1046               (clobber (reg:DI 23))
1047               (clobber (reg:DI 28))])
1048    (set (match_operand:SI 0 "nonimmediate_operand" "")
1049         (subreg:SI (match_dup 5) 0))]
1050   "! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK"
1051 {
1052   operands[3] = gen_reg_rtx (DImode);
1053   operands[4] = gen_reg_rtx (DImode);
1054   operands[5] = gen_reg_rtx (DImode);
1055 })
1056
1057 (define_expand "modsi3"
1058   [(set (match_dup 3)
1059         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "")))
1060    (set (match_dup 4)
1061         (sign_extend:DI (match_operand:SI 2 "nonimmediate_operand" "")))
1062    (parallel [(set (match_dup 5)
1063                    (sign_extend:DI (mod:SI (match_dup 3) (match_dup 4))))
1064               (clobber (reg:DI 23))
1065               (clobber (reg:DI 28))])
1066    (set (match_operand:SI 0 "nonimmediate_operand" "")
1067         (subreg:SI (match_dup 5) 0))]
1068   "! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK"
1069 {
1070   operands[3] = gen_reg_rtx (DImode);
1071   operands[4] = gen_reg_rtx (DImode);
1072   operands[5] = gen_reg_rtx (DImode);
1073 })
1074
1075 (define_expand "umodsi3"
1076   [(set (match_dup 3)
1077         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "")))
1078    (set (match_dup 4)
1079         (sign_extend:DI (match_operand:SI 2 "nonimmediate_operand" "")))
1080    (parallel [(set (match_dup 5)
1081                    (sign_extend:DI (umod:SI (match_dup 3) (match_dup 4))))
1082               (clobber (reg:DI 23))
1083               (clobber (reg:DI 28))])
1084    (set (match_operand:SI 0 "nonimmediate_operand" "")
1085         (subreg:SI (match_dup 5) 0))]
1086   "! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK"
1087 {
1088   operands[3] = gen_reg_rtx (DImode);
1089   operands[4] = gen_reg_rtx (DImode);
1090   operands[5] = gen_reg_rtx (DImode);
1091 })
1092
1093 (define_expand "divdi3"
1094   [(parallel [(set (match_operand:DI 0 "register_operand" "")
1095                    (div:DI (match_operand:DI 1 "register_operand" "")
1096                            (match_operand:DI 2 "register_operand" "")))
1097               (clobber (reg:DI 23))
1098               (clobber (reg:DI 28))])]
1099   "! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK"
1100   "")
1101
1102 (define_expand "udivdi3"
1103   [(parallel [(set (match_operand:DI 0 "register_operand" "")
1104                    (udiv:DI (match_operand:DI 1 "register_operand" "")
1105                             (match_operand:DI 2 "register_operand" "")))
1106               (clobber (reg:DI 23))
1107               (clobber (reg:DI 28))])]
1108   "! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK"
1109   "")
1110
1111 (define_expand "moddi3"
1112   [(use (match_operand:DI 0 "register_operand" ""))
1113    (use (match_operand:DI 1 "register_operand" ""))
1114    (use (match_operand:DI 2 "register_operand" ""))]
1115   "!TARGET_ABI_OPEN_VMS"
1116 {
1117   if (TARGET_ABI_UNICOSMK)
1118     emit_insn (gen_moddi3_umk (operands[0], operands[1], operands[2]));
1119   else
1120     emit_insn (gen_moddi3_dft (operands[0], operands[1], operands[2]));
1121   DONE;
1122 })
1123
1124 (define_expand "moddi3_dft"
1125   [(parallel [(set (match_operand:DI 0 "register_operand" "")
1126                    (mod:DI (match_operand:DI 1 "register_operand" "")
1127                            (match_operand:DI 2 "register_operand" "")))
1128               (clobber (reg:DI 23))
1129               (clobber (reg:DI 28))])]
1130   "! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK"
1131   "")
1132
1133 ;; On Unicos/Mk, we do as the system's C compiler does:
1134 ;; compute the quotient, multiply and subtract.
1135
1136 (define_expand "moddi3_umk"
1137   [(use (match_operand:DI 0 "register_operand" ""))
1138    (use (match_operand:DI 1 "register_operand" ""))
1139    (use (match_operand:DI 2 "register_operand" ""))]
1140   "TARGET_ABI_UNICOSMK"
1141 {
1142   rtx div, mul = gen_reg_rtx (DImode);
1143
1144   div = expand_binop (DImode, sdiv_optab, operands[1], operands[2],
1145                       NULL_RTX, 0, OPTAB_LIB);
1146   div = force_reg (DImode, div);
1147   emit_insn (gen_muldi3 (mul, operands[2], div));
1148   emit_insn (gen_subdi3 (operands[0], operands[1], mul));
1149   DONE;
1150 })
1151
1152 (define_expand "umoddi3"
1153   [(use (match_operand:DI 0 "register_operand" ""))
1154    (use (match_operand:DI 1 "register_operand" ""))
1155    (use (match_operand:DI 2 "register_operand" ""))]
1156   "! TARGET_ABI_OPEN_VMS"
1157 {
1158   if (TARGET_ABI_UNICOSMK)
1159     emit_insn (gen_umoddi3_umk (operands[0], operands[1], operands[2]));
1160   else
1161     emit_insn (gen_umoddi3_dft (operands[0], operands[1], operands[2]));
1162   DONE;
1163 })
1164
1165 (define_expand "umoddi3_dft"
1166   [(parallel [(set (match_operand:DI 0 "register_operand" "")
1167                    (umod:DI (match_operand:DI 1 "register_operand" "")
1168                             (match_operand:DI 2 "register_operand" "")))
1169               (clobber (reg:DI 23))
1170               (clobber (reg:DI 28))])]
1171   "! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK"
1172   "")
1173
1174 (define_expand "umoddi3_umk"
1175   [(use (match_operand:DI 0 "register_operand" ""))
1176    (use (match_operand:DI 1 "register_operand" ""))
1177    (use (match_operand:DI 2 "register_operand" ""))]
1178   "TARGET_ABI_UNICOSMK"
1179 {
1180   rtx div, mul = gen_reg_rtx (DImode);
1181
1182   div = expand_binop (DImode, udiv_optab, operands[1], operands[2],
1183                       NULL_RTX, 1, OPTAB_LIB);
1184   div = force_reg (DImode, div);
1185   emit_insn (gen_muldi3 (mul, operands[2], div));
1186   emit_insn (gen_subdi3 (operands[0], operands[1], mul));
1187   DONE;
1188 })
1189
1190 ;; Lengths of 8 for ldq $t12,__divq($gp); jsr $t9,($t12),__divq as
1191 ;; expanded by the assembler.
1192
1193 (define_insn_and_split "*divmodsi_internal_er"
1194   [(set (match_operand:DI 0 "register_operand" "=c")
1195         (sign_extend:DI (match_operator:SI 3 "divmod_operator"
1196                         [(match_operand:DI 1 "register_operand" "a")
1197                          (match_operand:DI 2 "register_operand" "b")])))
1198    (clobber (reg:DI 23))
1199    (clobber (reg:DI 28))]
1200   "TARGET_EXPLICIT_RELOCS && ! TARGET_ABI_OPEN_VMS"
1201   "ldq $27,__%E3($29)\t\t!literal!%#\;jsr $23,($27),__%E3\t\t!lituse_jsr!%#"
1202   "&& reload_completed"
1203   [(parallel [(set (match_dup 0)
1204                    (sign_extend:DI (match_dup 3)))
1205               (use (match_dup 0))
1206               (clobber (reg:DI 23))
1207               (clobber (reg:DI 28))])]
1208 {
1209   const char *str;
1210   switch (GET_CODE (operands[3]))
1211     {
1212     case DIV: 
1213       str = "__divl";
1214       break; 
1215     case UDIV:
1216       str = "__divlu";
1217       break;
1218     case MOD:
1219       str = "__reml";
1220       break;
1221     case UMOD:
1222       str = "__remlu";
1223       break;
1224     default:
1225       abort ();
1226     }
1227   emit_insn (gen_movdi_er_high_g (operands[0], pic_offset_table_rtx,
1228                                   gen_rtx_SYMBOL_REF (DImode, str),
1229                                   const0_rtx));
1230 }
1231   [(set_attr "type" "jsr")
1232    (set_attr "length" "8")])
1233
1234 (define_insn "*divmodsi_internal_er_1"
1235   [(set (match_operand:DI 0 "register_operand" "=c")
1236         (sign_extend:DI (match_operator:SI 3 "divmod_operator"
1237                         [(match_operand:DI 1 "register_operand" "a")
1238                          (match_operand:DI 2 "register_operand" "b")])))
1239    (use (match_operand:DI 4 "register_operand" "c"))
1240    (clobber (reg:DI 23))
1241    (clobber (reg:DI 28))]
1242   "TARGET_EXPLICIT_RELOCS && ! TARGET_ABI_OPEN_VMS"
1243   "jsr $23,($27),__%E3"
1244   [(set_attr "type" "jsr")
1245    (set_attr "length" "4")])
1246
1247 (define_insn "*divmodsi_internal"
1248   [(set (match_operand:DI 0 "register_operand" "=c")
1249         (sign_extend:DI (match_operator:SI 3 "divmod_operator"
1250                         [(match_operand:DI 1 "register_operand" "a")
1251                          (match_operand:DI 2 "register_operand" "b")])))
1252    (clobber (reg:DI 23))
1253    (clobber (reg:DI 28))]
1254   "! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK"
1255   "%E3 %1,%2,%0"
1256   [(set_attr "type" "jsr")
1257    (set_attr "length" "8")])
1258
1259 (define_insn_and_split "*divmoddi_internal_er"
1260   [(set (match_operand:DI 0 "register_operand" "=c")
1261         (match_operator:DI 3 "divmod_operator"
1262                         [(match_operand:DI 1 "register_operand" "a")
1263                          (match_operand:DI 2 "register_operand" "b")]))
1264    (clobber (reg:DI 23))
1265    (clobber (reg:DI 28))]
1266   "TARGET_EXPLICIT_RELOCS && ! TARGET_ABI_OPEN_VMS"
1267   "ldq $27,__%E3($29)\t\t!literal!%#\;jsr $23,($27),__%E3\t\t!lituse_jsr!%#"
1268   "&& reload_completed"
1269   [(parallel [(set (match_dup 0) (match_dup 3))
1270               (use (match_dup 0))
1271               (clobber (reg:DI 23))
1272               (clobber (reg:DI 28))])]
1273 {
1274   const char *str;
1275   switch (GET_CODE (operands[3]))
1276     {
1277     case DIV: 
1278       str = "__divq";
1279       break; 
1280     case UDIV:
1281       str = "__divqu";
1282       break;
1283     case MOD:
1284       str = "__remq";
1285       break;
1286     case UMOD:
1287       str = "__remqu";
1288       break;
1289     default:
1290       abort ();
1291     }
1292   emit_insn (gen_movdi_er_high_g (operands[0], pic_offset_table_rtx,
1293                                   gen_rtx_SYMBOL_REF (DImode, str),
1294                                   const0_rtx));
1295 }
1296   [(set_attr "type" "jsr")
1297    (set_attr "length" "8")])
1298
1299 (define_insn "*divmoddi_internal_er_1"
1300   [(set (match_operand:DI 0 "register_operand" "=c")
1301         (match_operator:DI 3 "divmod_operator"
1302                         [(match_operand:DI 1 "register_operand" "a")
1303                          (match_operand:DI 2 "register_operand" "b")]))
1304    (use (match_operand:DI 4 "register_operand" "c"))
1305    (clobber (reg:DI 23))
1306    (clobber (reg:DI 28))]
1307   "TARGET_EXPLICIT_RELOCS && ! TARGET_ABI_OPEN_VMS"
1308   "jsr $23,($27),__%E3"
1309   [(set_attr "type" "jsr")
1310    (set_attr "length" "4")])
1311
1312 (define_insn "*divmoddi_internal"
1313   [(set (match_operand:DI 0 "register_operand" "=c")
1314         (match_operator:DI 3 "divmod_operator"
1315                         [(match_operand:DI 1 "register_operand" "a")
1316                          (match_operand:DI 2 "register_operand" "b")]))
1317    (clobber (reg:DI 23))
1318    (clobber (reg:DI 28))]
1319   "! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK"
1320   "%E3 %1,%2,%0"
1321   [(set_attr "type" "jsr")
1322    (set_attr "length" "8")])
1323 \f
1324 ;; Next are the basic logical operations.  These only exist in DImode.
1325
1326 (define_insn "anddi3"
1327   [(set (match_operand:DI 0 "register_operand" "=r,r,r")
1328         (and:DI (match_operand:DI 1 "reg_or_0_operand" "%rJ,rJ,rJ")
1329                 (match_operand:DI 2 "and_operand" "rI,N,MH")))]
1330   ""
1331   "@
1332    and %r1,%2,%0
1333    bic %r1,%N2,%0
1334    zapnot %r1,%m2,%0"
1335   [(set_attr "type" "ilog,ilog,shift")])
1336
1337 ;; There are times when we can split an AND into two AND insns.  This occurs
1338 ;; when we can first clear any bytes and then clear anything else.  For
1339 ;; example "I & 0xffff07" is "(I & 0xffffff) & 0xffffffffffffff07".
1340 ;; Only do this when running on 64-bit host since the computations are
1341 ;; too messy otherwise.
1342
1343 (define_split
1344   [(set (match_operand:DI 0 "register_operand" "")
1345         (and:DI (match_operand:DI 1 "register_operand" "")
1346                 (match_operand:DI 2 "const_int_operand" "")))]
1347   "HOST_BITS_PER_WIDE_INT == 64 && ! and_operand (operands[2], DImode)"
1348   [(set (match_dup 0) (and:DI (match_dup 1) (match_dup 3)))
1349    (set (match_dup 0) (and:DI (match_dup 0) (match_dup 4)))]
1350 {
1351   unsigned HOST_WIDE_INT mask1 = INTVAL (operands[2]);
1352   unsigned HOST_WIDE_INT mask2 = mask1;
1353   int i;
1354
1355   /* For each byte that isn't all zeros, make it all ones.  */
1356   for (i = 0; i < 64; i += 8)
1357     if ((mask1 & ((HOST_WIDE_INT) 0xff << i)) != 0)
1358       mask1 |= (HOST_WIDE_INT) 0xff << i;
1359
1360   /* Now turn on any bits we've just turned off.  */
1361   mask2 |= ~ mask1;
1362
1363   operands[3] = GEN_INT (mask1);
1364   operands[4] = GEN_INT (mask2);
1365 })
1366
1367 (define_expand "zero_extendqihi2"
1368   [(set (match_operand:HI 0 "register_operand" "")
1369         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "")))]
1370   ""
1371 {
1372   if (! TARGET_BWX)
1373     operands[1] = force_reg (QImode, operands[1]);
1374 })
1375
1376 (define_insn "*zero_extendqihi2_bwx"
1377   [(set (match_operand:HI 0 "register_operand" "=r,r")
1378         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
1379   "TARGET_BWX"
1380   "@
1381    and %1,0xff,%0
1382    ldbu %0,%1"
1383   [(set_attr "type" "ilog,ild")])
1384
1385 (define_insn "*zero_extendqihi2_nobwx"
1386   [(set (match_operand:HI 0 "register_operand" "=r")
1387         (zero_extend:HI (match_operand:QI 1 "register_operand" "r")))]
1388   "! TARGET_BWX"
1389   "and %1,0xff,%0"
1390   [(set_attr "type" "ilog")])
1391
1392 (define_expand "zero_extendqisi2"
1393   [(set (match_operand:SI 0 "register_operand" "")
1394         (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "")))]
1395   ""
1396 {
1397   if (! TARGET_BWX)
1398     operands[1] = force_reg (QImode, operands[1]);
1399 })
1400
1401 (define_insn "*zero_extendqisi2_bwx"
1402   [(set (match_operand:SI 0 "register_operand" "=r,r")
1403         (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
1404   "TARGET_BWX"
1405   "@
1406    and %1,0xff,%0
1407    ldbu %0,%1"
1408   [(set_attr "type" "ilog,ild")])
1409
1410 (define_insn "*zero_extendqisi2_nobwx"
1411   [(set (match_operand:SI 0 "register_operand" "=r")
1412         (zero_extend:SI (match_operand:QI 1 "register_operand" "r")))]
1413   "! TARGET_BWX"
1414   "and %1,0xff,%0"
1415   [(set_attr "type" "ilog")])
1416
1417 (define_expand "zero_extendqidi2"
1418   [(set (match_operand:DI 0 "register_operand" "")
1419         (zero_extend:DI (match_operand:QI 1 "nonimmediate_operand" "")))]
1420   ""
1421 {
1422   if (! TARGET_BWX)
1423     operands[1] = force_reg (QImode, operands[1]);
1424 })
1425
1426 (define_insn "*zero_extendqidi2_bwx"
1427   [(set (match_operand:DI 0 "register_operand" "=r,r")
1428         (zero_extend:DI (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
1429   "TARGET_BWX"
1430   "@
1431    and %1,0xff,%0
1432    ldbu %0,%1"
1433   [(set_attr "type" "ilog,ild")])
1434
1435 (define_insn "*zero_extendqidi2_nobwx"
1436   [(set (match_operand:DI 0 "register_operand" "=r")
1437         (zero_extend:DI (match_operand:QI 1 "register_operand" "r")))]
1438   "! TARGET_BWX"
1439   "and %1,0xff,%0"
1440   [(set_attr "type" "ilog")])
1441
1442 (define_expand "zero_extendhisi2"
1443   [(set (match_operand:SI 0 "register_operand" "")
1444         (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "")))]
1445   ""
1446 {
1447   if (! TARGET_BWX)
1448     operands[1] = force_reg (HImode, operands[1]);
1449 })
1450
1451 (define_insn "*zero_extendhisi2_bwx"
1452   [(set (match_operand:SI 0 "register_operand" "=r,r")
1453         (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
1454   "TARGET_BWX"
1455   "@
1456    zapnot %1,3,%0
1457    ldwu %0,%1"
1458   [(set_attr "type" "shift,ild")])
1459
1460 (define_insn "*zero_extendhisi2_nobwx"
1461   [(set (match_operand:SI 0 "register_operand" "=r")
1462         (zero_extend:SI (match_operand:HI 1 "register_operand" "r")))]
1463   "! TARGET_BWX"
1464   "zapnot %1,3,%0"
1465   [(set_attr "type" "shift")])
1466
1467 (define_expand "zero_extendhidi2"
1468   [(set (match_operand:DI 0 "register_operand" "")
1469         (zero_extend:DI (match_operand:HI 1 "nonimmediate_operand" "")))]
1470   ""
1471 {
1472   if (! TARGET_BWX)
1473     operands[1] = force_reg (HImode, operands[1]);
1474 })
1475
1476 (define_insn "*zero_extendhidi2_bwx"
1477   [(set (match_operand:DI 0 "register_operand" "=r,r")
1478         (zero_extend:DI (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
1479   "TARGET_BWX"
1480   "@
1481    zapnot %1,3,%0
1482    ldwu %0,%1"
1483   [(set_attr "type" "shift,ild")])
1484
1485 (define_insn "*zero_extendhidi2_nobwx"
1486   [(set (match_operand:DI 0 "register_operand" "=r")
1487         (zero_extend:DI (match_operand:HI 1 "register_operand" "r")))]
1488   ""
1489   "zapnot %1,3,%0"
1490   [(set_attr "type" "shift")])
1491
1492 (define_insn "zero_extendsidi2"
1493   [(set (match_operand:DI 0 "register_operand" "=r")
1494         (zero_extend:DI (match_operand:SI 1 "register_operand" "r")))]
1495   ""
1496   "zapnot %1,15,%0"
1497   [(set_attr "type" "shift")])
1498
1499 (define_insn "andnotdi3"
1500   [(set (match_operand:DI 0 "register_operand" "=r")
1501         (and:DI (not:DI (match_operand:DI 1 "reg_or_8bit_operand" "rI"))
1502                 (match_operand:DI 2 "reg_or_0_operand" "rJ")))]
1503   ""
1504   "bic %r2,%1,%0"
1505   [(set_attr "type" "ilog")])
1506
1507 (define_insn "iordi3"
1508   [(set (match_operand:DI 0 "register_operand" "=r,r")
1509         (ior:DI (match_operand:DI 1 "reg_or_0_operand" "%rJ,rJ")
1510                 (match_operand:DI 2 "or_operand" "rI,N")))]
1511   ""
1512   "@
1513    bis %r1,%2,%0
1514    ornot %r1,%N2,%0"
1515   [(set_attr "type" "ilog")])
1516
1517 (define_insn "one_cmpldi2"
1518   [(set (match_operand:DI 0 "register_operand" "=r")
1519         (not:DI (match_operand:DI 1 "reg_or_8bit_operand" "rI")))]
1520   ""
1521   "ornot $31,%1,%0"
1522   [(set_attr "type" "ilog")])
1523
1524 (define_insn "*iornot"
1525   [(set (match_operand:DI 0 "register_operand" "=r")
1526         (ior:DI (not:DI (match_operand:DI 1 "reg_or_8bit_operand" "rI"))
1527                 (match_operand:DI 2 "reg_or_0_operand" "rJ")))]
1528   ""
1529   "ornot %r2,%1,%0"
1530   [(set_attr "type" "ilog")])
1531
1532 (define_insn "xordi3"
1533   [(set (match_operand:DI 0 "register_operand" "=r,r")
1534         (xor:DI (match_operand:DI 1 "reg_or_0_operand" "%rJ,rJ")
1535                 (match_operand:DI 2 "or_operand" "rI,N")))]
1536   ""
1537   "@
1538    xor %r1,%2,%0
1539    eqv %r1,%N2,%0"
1540   [(set_attr "type" "ilog")])
1541
1542 (define_insn "*xornot"
1543   [(set (match_operand:DI 0 "register_operand" "=r")
1544         (not:DI (xor:DI (match_operand:DI 1 "register_operand" "%rJ")
1545                         (match_operand:DI 2 "register_operand" "rI"))))]
1546   ""
1547   "eqv %r1,%2,%0"
1548   [(set_attr "type" "ilog")])
1549 \f
1550 ;; Handle the FFS insn iff we support CIX.
1551
1552 (define_expand "ffsdi2"
1553   [(set (match_dup 2)
1554         (unspec:DI [(match_operand:DI 1 "register_operand" "")] UNSPEC_CTTZ))
1555    (set (match_dup 3)
1556         (plus:DI (match_dup 2) (const_int 1)))
1557    (set (match_operand:DI 0 "register_operand" "")
1558         (if_then_else:DI (eq (match_dup 1) (const_int 0))
1559                          (const_int 0) (match_dup 3)))]
1560   "TARGET_CIX"
1561 {
1562   operands[2] = gen_reg_rtx (DImode);
1563   operands[3] = gen_reg_rtx (DImode);
1564 })
1565
1566 (define_insn "*cttz"
1567   [(set (match_operand:DI 0 "register_operand" "=r")
1568         (unspec:DI [(match_operand:DI 1 "register_operand" "r")] UNSPEC_CTTZ))]
1569   "TARGET_CIX"
1570   "cttz %1,%0"
1571   ; EV6 calls all mvi and cttz/ctlz/popc class imisc, so just
1572   ; reuse the existing type name.
1573   [(set_attr "type" "mvi")])
1574 \f
1575 ;; Next come the shifts and the various extract and insert operations.
1576
1577 (define_insn "ashldi3"
1578   [(set (match_operand:DI 0 "register_operand" "=r,r")
1579         (ashift:DI (match_operand:DI 1 "reg_or_0_operand" "rJ,rJ")
1580                    (match_operand:DI 2 "reg_or_6bit_operand" "P,rS")))]
1581   ""
1582 {
1583   switch (which_alternative)
1584     {
1585     case 0:
1586       if (operands[2] == const1_rtx)
1587         return "addq %r1,%r1,%0";
1588       else
1589         return "s%P2addq %r1,0,%0";
1590     case 1:
1591       return "sll %r1,%2,%0";
1592     default:
1593       abort();
1594     }
1595 }
1596   [(set_attr "type" "iadd,shift")])
1597
1598 ;; ??? The following pattern is made by combine, but earlier phases
1599 ;; (specifically flow) can't handle it.  This occurs in jump.c.  Deal
1600 ;; with this in a better way at some point.
1601 ;;(define_insn ""
1602 ;;  [(set (match_operand:DI 0 "register_operand" "=r")
1603 ;;      (sign_extend:DI
1604 ;;       (subreg:SI (ashift:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1605 ;;                             (match_operand:DI 2 "const_int_operand" "P"))
1606 ;;                  0)))]
1607 ;;  "INTVAL (operands[2]) >= 1 && INTVAL (operands[2]) <= 3"
1608 ;;{
1609 ;;  if (operands[2] == const1_rtx)
1610 ;;    return "addl %r1,%r1,%0";
1611 ;;  else
1612 ;;    return "s%P2addl %r1,0,%0";
1613 ;;}
1614 ;;  [(set_attr "type" "iadd")])
1615
1616 (define_insn "lshrdi3"
1617   [(set (match_operand:DI 0 "register_operand" "=r")
1618         (lshiftrt:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1619                      (match_operand:DI 2 "reg_or_6bit_operand" "rS")))]
1620   ""
1621   "srl %r1,%2,%0"
1622   [(set_attr "type" "shift")])
1623
1624 (define_insn "ashrdi3"
1625   [(set (match_operand:DI 0 "register_operand" "=r")
1626         (ashiftrt:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1627                      (match_operand:DI 2 "reg_or_6bit_operand" "rS")))]
1628   ""
1629   "sra %r1,%2,%0"
1630   [(set_attr "type" "shift")])
1631
1632 (define_expand "extendqihi2"
1633   [(set (match_dup 2)
1634         (ashift:DI (match_operand:QI 1 "some_operand" "")
1635                    (const_int 56)))
1636    (set (match_operand:HI 0 "register_operand" "")
1637         (ashiftrt:DI (match_dup 2)
1638                      (const_int 56)))]
1639   ""
1640 {
1641   if (TARGET_BWX)
1642     {
1643       emit_insn (gen_extendqihi2x (operands[0],
1644                                    force_reg (QImode, operands[1])));
1645       DONE;
1646     }
1647
1648  /* If we have an unaligned MEM, extend to DImode (which we do
1649      specially) and then copy to the result.  */
1650   if (unaligned_memory_operand (operands[1], HImode))
1651     {
1652       rtx temp = gen_reg_rtx (DImode);
1653
1654       emit_insn (gen_extendqidi2 (temp, operands[1]));
1655       emit_move_insn (operands[0], gen_lowpart (HImode, temp));
1656       DONE;
1657     }
1658
1659   operands[0] = gen_lowpart (DImode, operands[0]);
1660   operands[1] = gen_lowpart (DImode, force_reg (QImode, operands[1]));
1661   operands[2] = gen_reg_rtx (DImode);
1662 })
1663
1664 (define_insn "extendqidi2x"
1665   [(set (match_operand:DI 0 "register_operand" "=r")
1666         (sign_extend:DI (match_operand:QI 1 "register_operand" "r")))]
1667   "TARGET_BWX"
1668   "sextb %1,%0"
1669   [(set_attr "type" "shift")])
1670
1671 (define_insn "extendhidi2x"
1672   [(set (match_operand:DI 0 "register_operand" "=r")
1673         (sign_extend:DI (match_operand:HI 1 "register_operand" "r")))]
1674   "TARGET_BWX"
1675   "sextw %1,%0"
1676   [(set_attr "type" "shift")])
1677
1678 (define_insn "extendqisi2x"
1679   [(set (match_operand:SI 0 "register_operand" "=r")
1680         (sign_extend:SI (match_operand:QI 1 "register_operand" "r")))]
1681   "TARGET_BWX"
1682   "sextb %1,%0"
1683   [(set_attr "type" "shift")])
1684
1685 (define_insn "extendhisi2x"
1686   [(set (match_operand:SI 0 "register_operand" "=r")
1687         (sign_extend:SI (match_operand:HI 1 "register_operand" "r")))]
1688   "TARGET_BWX"
1689   "sextw %1,%0"
1690   [(set_attr "type" "shift")])
1691
1692 (define_insn "extendqihi2x"
1693   [(set (match_operand:HI 0 "register_operand" "=r")
1694         (sign_extend:HI (match_operand:QI 1 "register_operand" "r")))]
1695   "TARGET_BWX"
1696   "sextb %1,%0"
1697   [(set_attr "type" "shift")])
1698
1699 (define_expand "extendqisi2"
1700   [(set (match_dup 2)
1701         (ashift:DI (match_operand:QI 1 "some_operand" "")
1702                    (const_int 56)))
1703    (set (match_operand:SI 0 "register_operand" "")
1704         (ashiftrt:DI (match_dup 2)
1705                      (const_int 56)))]
1706   ""
1707 {
1708   if (TARGET_BWX)
1709     {
1710       emit_insn (gen_extendqisi2x (operands[0],
1711                                    force_reg (QImode, operands[1])));
1712       DONE;
1713     }
1714
1715   /* If we have an unaligned MEM, extend to a DImode form of
1716      the result (which we do specially).  */
1717   if (unaligned_memory_operand (operands[1], QImode))
1718     {
1719       rtx temp = gen_reg_rtx (DImode);
1720
1721       emit_insn (gen_extendqidi2 (temp, operands[1]));
1722       emit_move_insn (operands[0], gen_lowpart (SImode, temp));
1723       DONE;
1724     }
1725
1726   operands[0] = gen_lowpart (DImode, operands[0]);
1727   operands[1] = gen_lowpart (DImode, force_reg (QImode, operands[1]));
1728   operands[2] = gen_reg_rtx (DImode);
1729 })
1730
1731 (define_expand "extendqidi2"
1732   [(set (match_dup 2)
1733         (ashift:DI (match_operand:QI 1 "some_operand" "")
1734                    (const_int 56)))
1735    (set (match_operand:DI 0 "register_operand" "")
1736         (ashiftrt:DI (match_dup 2)
1737                      (const_int 56)))]
1738   ""
1739 {
1740   if (TARGET_BWX)
1741     {
1742       emit_insn (gen_extendqidi2x (operands[0],
1743                                    force_reg (QImode, operands[1])));
1744       DONE;
1745     }
1746
1747   if (unaligned_memory_operand (operands[1], QImode))
1748     {
1749       rtx seq
1750         = gen_unaligned_extendqidi (operands[0],
1751                                     get_unaligned_address (operands[1], 1));
1752
1753       alpha_set_memflags (seq, operands[1]);
1754       emit_insn (seq);
1755       DONE;
1756     }
1757
1758   operands[1] = gen_lowpart (DImode, force_reg (QImode, operands[1]));
1759   operands[2] = gen_reg_rtx (DImode);
1760 })
1761
1762 (define_expand "extendhisi2"
1763   [(set (match_dup 2)
1764         (ashift:DI (match_operand:HI 1 "some_operand" "")
1765                    (const_int 48)))
1766    (set (match_operand:SI 0 "register_operand" "")
1767         (ashiftrt:DI (match_dup 2)
1768                      (const_int 48)))]
1769   ""
1770 {
1771   if (TARGET_BWX)
1772     {
1773       emit_insn (gen_extendhisi2x (operands[0],
1774                                    force_reg (HImode, operands[1])));
1775       DONE;
1776     }
1777
1778   /* If we have an unaligned MEM, extend to a DImode form of
1779      the result (which we do specially).  */
1780   if (unaligned_memory_operand (operands[1], HImode))
1781     {
1782       rtx temp = gen_reg_rtx (DImode);
1783
1784       emit_insn (gen_extendhidi2 (temp, operands[1]));
1785       emit_move_insn (operands[0], gen_lowpart (SImode, temp));
1786       DONE;
1787     }
1788
1789   operands[0] = gen_lowpart (DImode, operands[0]);
1790   operands[1] = gen_lowpart (DImode, force_reg (HImode, operands[1]));
1791   operands[2] = gen_reg_rtx (DImode);
1792 })
1793
1794 (define_expand "extendhidi2"
1795   [(set (match_dup 2)
1796         (ashift:DI (match_operand:HI 1 "some_operand" "")
1797                    (const_int 48)))
1798    (set (match_operand:DI 0 "register_operand" "")
1799         (ashiftrt:DI (match_dup 2)
1800                      (const_int 48)))]
1801   ""
1802 {
1803   if (TARGET_BWX)
1804     {
1805       emit_insn (gen_extendhidi2x (operands[0],
1806                                    force_reg (HImode, operands[1])));
1807       DONE;
1808     }
1809
1810   if (unaligned_memory_operand (operands[1], HImode))
1811     {
1812       rtx seq
1813         = gen_unaligned_extendhidi (operands[0],
1814                                     get_unaligned_address (operands[1], 2));
1815
1816       alpha_set_memflags (seq, operands[1]);
1817       emit_insn (seq);
1818       DONE;
1819     }
1820
1821   operands[1] = gen_lowpart (DImode, force_reg (HImode, operands[1]));
1822   operands[2] = gen_reg_rtx (DImode);
1823 })
1824
1825 ;; Here's how we sign extend an unaligned byte and halfword.  Doing this
1826 ;; as a pattern saves one instruction.  The code is similar to that for
1827 ;; the unaligned loads (see below).
1828 ;;
1829 ;; Operand 1 is the address + 1 (+2 for HI), operand 0 is the result.
1830 (define_expand "unaligned_extendqidi"
1831   [(use (match_operand:QI 0 "register_operand" ""))
1832    (use (match_operand:DI 1 "address_operand" ""))]
1833   ""
1834 {
1835   if (WORDS_BIG_ENDIAN)
1836     emit_insn (gen_unaligned_extendqidi_be (operands[0], operands[1]));
1837   else
1838     emit_insn (gen_unaligned_extendqidi_le (operands[0], operands[1]));
1839   DONE;
1840 })
1841
1842 (define_expand "unaligned_extendqidi_le"
1843   [(set (match_dup 2) (match_operand:DI 1 "address_operand" ""))
1844    (set (match_dup 3)
1845         (mem:DI (and:DI (plus:DI (match_dup 2) (const_int -1))
1846                         (const_int -8))))
1847    (set (match_dup 4)
1848         (ashift:DI (match_dup 3)
1849                    (minus:DI (const_int 64)
1850                              (ashift:DI
1851                               (and:DI (match_dup 2) (const_int 7))
1852                               (const_int 3)))))
1853    (set (subreg:DI (match_operand:QI 0 "register_operand" "") 0)
1854         (ashiftrt:DI (match_dup 4) (const_int 56)))]
1855   "! WORDS_BIG_ENDIAN"
1856 {
1857   operands[2] = gen_reg_rtx (DImode);
1858   operands[3] = gen_reg_rtx (DImode);
1859   operands[4] = gen_reg_rtx (DImode);
1860 })
1861
1862 (define_expand "unaligned_extendqidi_be"
1863   [(set (match_dup 2) (match_operand:DI 1 "address_operand" ""))
1864    (set (match_dup 3) (plus:DI (match_dup 2) (const_int -1)))
1865    (set (match_dup 4)
1866         (mem:DI (and:DI (match_dup 3)
1867                         (const_int -8))))
1868    (set (match_dup 5) (plus:DI (match_dup 2) (const_int -2)))
1869    (set (match_dup 6)
1870         (ashift:DI (match_dup 4)
1871                    (ashift:DI
1872                      (and:DI
1873                        (plus:DI (match_dup 5) (const_int 1))
1874                        (const_int 7))
1875                      (const_int 3))))
1876    (set (subreg:DI (match_operand:QI 0 "register_operand" "") 0)
1877         (ashiftrt:DI (match_dup 6) (const_int 56)))]
1878   "WORDS_BIG_ENDIAN"
1879 {
1880   operands[2] = gen_reg_rtx (DImode);
1881   operands[3] = gen_reg_rtx (DImode);
1882   operands[4] = gen_reg_rtx (DImode);
1883   operands[5] = gen_reg_rtx (DImode);
1884   operands[6] = gen_reg_rtx (DImode);
1885 })
1886
1887 (define_expand "unaligned_extendhidi"
1888   [(use (match_operand:QI 0 "register_operand" ""))
1889    (use (match_operand:DI 1 "address_operand" ""))]
1890   ""
1891 {
1892   operands[0] = gen_lowpart (DImode, operands[0]);
1893   emit_insn ((WORDS_BIG_ENDIAN
1894               ? gen_unaligned_extendhidi_be
1895               : gen_unaligned_extendhidi_le) (operands[0], operands[1]));
1896   DONE;
1897 })
1898
1899 (define_expand "unaligned_extendhidi_le"
1900   [(set (match_dup 2) (match_operand:DI 1 "address_operand" ""))
1901    (set (match_dup 3)
1902         (mem:DI (and:DI (plus:DI (match_dup 2) (const_int -2))
1903                         (const_int -8))))
1904    (set (match_dup 4)
1905         (ashift:DI (match_dup 3)
1906                    (minus:DI (const_int 64)
1907                              (ashift:DI
1908                               (and:DI (match_dup 2) (const_int 7))
1909                               (const_int 3)))))
1910    (set (match_operand:DI 0 "register_operand" "")
1911         (ashiftrt:DI (match_dup 4) (const_int 48)))]
1912   "! WORDS_BIG_ENDIAN"
1913 {
1914   operands[2] = gen_reg_rtx (DImode);
1915   operands[3] = gen_reg_rtx (DImode);
1916   operands[4] = gen_reg_rtx (DImode);
1917 })
1918
1919 (define_expand "unaligned_extendhidi_be"
1920   [(set (match_dup 2) (match_operand:DI 1 "address_operand" ""))
1921    (set (match_dup 3) (plus:DI (match_dup 2) (const_int -2)))
1922    (set (match_dup 4)
1923         (mem:DI (and:DI (match_dup 3)
1924                         (const_int -8))))
1925    (set (match_dup 5) (plus:DI (match_dup 2) (const_int -3)))
1926    (set (match_dup 6)
1927         (ashift:DI (match_dup 4)
1928                    (ashift:DI
1929                      (and:DI
1930                        (plus:DI (match_dup 5) (const_int 1))
1931                        (const_int 7))
1932                      (const_int 3))))
1933    (set (match_operand:DI 0 "register_operand" "")
1934         (ashiftrt:DI (match_dup 6) (const_int 48)))]
1935   "WORDS_BIG_ENDIAN"
1936 {
1937   operands[2] = gen_reg_rtx (DImode);
1938   operands[3] = gen_reg_rtx (DImode);
1939   operands[4] = gen_reg_rtx (DImode);
1940   operands[5] = gen_reg_rtx (DImode);
1941   operands[6] = gen_reg_rtx (DImode);
1942 })
1943
1944 (define_insn "*extxl_const"
1945   [(set (match_operand:DI 0 "register_operand" "=r")
1946         (zero_extract:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1947                          (match_operand:DI 2 "mode_width_operand" "n")
1948                          (match_operand:DI 3 "mul8_operand" "I")))]
1949   ""
1950   "ext%M2l %r1,%s3,%0"
1951   [(set_attr "type" "shift")])
1952
1953 (define_insn "extxl_le"
1954   [(set (match_operand:DI 0 "register_operand" "=r")
1955         (zero_extract:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1956                          (match_operand:DI 2 "mode_width_operand" "n")
1957                          (ashift:DI (match_operand:DI 3 "reg_or_8bit_operand" "rI")
1958                                     (const_int 3))))]
1959   "! WORDS_BIG_ENDIAN"
1960   "ext%M2l %r1,%3,%0"
1961   [(set_attr "type" "shift")])
1962
1963 (define_insn "extxl_be"
1964   [(set (match_operand:DI 0 "register_operand" "=r")
1965         (zero_extract:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1966                          (match_operand:DI 2 "mode_width_operand" "n")
1967                          (minus:DI
1968                            (const_int 56)
1969                            (ashift:DI
1970                              (match_operand:DI 3 "reg_or_8bit_operand" "rI")
1971                              (const_int 3)))))]
1972   "WORDS_BIG_ENDIAN"
1973   "ext%M2l %r1,%3,%0"
1974   [(set_attr "type" "shift")])
1975
1976 ;; Combine has some strange notion of preserving existing undefined behaviour
1977 ;; in shifts larger than a word size.  So capture these patterns that it
1978 ;; should have turned into zero_extracts.
1979
1980 (define_insn "*extxl_1_le"
1981   [(set (match_operand:DI 0 "register_operand" "=r")
1982         (and:DI (lshiftrt:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
1983                   (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
1984                              (const_int 3)))
1985              (match_operand:DI 3 "mode_mask_operand" "n")))]
1986   "! WORDS_BIG_ENDIAN"
1987   "ext%U3l %1,%2,%0"
1988   [(set_attr "type" "shift")])
1989
1990 (define_insn "*extxl_1_be"
1991   [(set (match_operand:DI 0 "register_operand" "=r")
1992         (and:DI (lshiftrt:DI
1993                   (match_operand:DI 1 "reg_or_0_operand" "rJ")
1994                   (minus:DI (const_int 56)
1995                     (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
1996                                (const_int 3))))
1997                 (match_operand:DI 3 "mode_mask_operand" "n")))]
1998   "WORDS_BIG_ENDIAN"
1999   "ext%U3l %1,%2,%0"
2000   [(set_attr "type" "shift")])
2001
2002 (define_insn "*extql_2_le"
2003   [(set (match_operand:DI 0 "register_operand" "=r")
2004         (lshiftrt:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
2005           (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2006                      (const_int 3))))]
2007   "! WORDS_BIG_ENDIAN"
2008   "extql %1,%2,%0"
2009   [(set_attr "type" "shift")])
2010
2011 (define_insn "*extql_2_be"
2012   [(set (match_operand:DI 0 "register_operand" "=r")
2013         (lshiftrt:DI
2014           (match_operand:DI 1 "reg_or_0_operand" "rJ")
2015           (minus:DI (const_int 56)
2016                     (ashift:DI
2017                       (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2018                       (const_int 3)))))]
2019   "WORDS_BIG_ENDIAN"
2020   "extql %1,%2,%0"
2021   [(set_attr "type" "shift")])
2022
2023 (define_insn "extqh_le"
2024   [(set (match_operand:DI 0 "register_operand" "=r")
2025         (ashift:DI
2026          (match_operand:DI 1 "reg_or_0_operand" "rJ")
2027           (minus:DI (const_int 64)
2028                     (ashift:DI
2029                      (and:DI
2030                       (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2031                       (const_int 7))
2032                      (const_int 3)))))]
2033   "! WORDS_BIG_ENDIAN"
2034   "extqh %r1,%2,%0"
2035   [(set_attr "type" "shift")])
2036
2037 (define_insn "extqh_be"
2038   [(set (match_operand:DI 0 "register_operand" "=r")
2039         (ashift:DI
2040           (match_operand:DI 1 "reg_or_0_operand" "rJ")
2041           (ashift:DI
2042             (and:DI
2043               (plus:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2044                        (const_int 1))
2045               (const_int 7))
2046             (const_int 3))))]
2047   "WORDS_BIG_ENDIAN"
2048   "extqh %r1,%2,%0"
2049   [(set_attr "type" "shift")])
2050
2051 (define_insn "extlh_le"
2052   [(set (match_operand:DI 0 "register_operand" "=r")
2053         (ashift:DI
2054          (and:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
2055                  (const_int 2147483647))
2056          (minus:DI (const_int 64)
2057                     (ashift:DI
2058                      (and:DI
2059                       (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2060                       (const_int 7))
2061                      (const_int 3)))))]
2062   "! WORDS_BIG_ENDIAN"
2063   "extlh %r1,%2,%0"
2064   [(set_attr "type" "shift")])
2065
2066 (define_insn "extlh_be"
2067   [(set (match_operand:DI 0 "register_operand" "=r")
2068         (and:DI
2069           (ashift:DI
2070             (match_operand:DI 1 "reg_or_0_operand" "rJ")
2071             (ashift:DI
2072               (and:DI
2073                 (plus:DI
2074                   (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2075                   (const_int 1))
2076                 (const_int 7))
2077               (const_int 3)))
2078           (const_int 2147483647)))]
2079   "WORDS_BIG_ENDIAN"
2080   "extlh %r1,%2,%0"
2081   [(set_attr "type" "shift")])
2082
2083 (define_insn "extwh_le"
2084   [(set (match_operand:DI 0 "register_operand" "=r")
2085         (ashift:DI
2086          (and:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
2087                  (const_int 65535))
2088          (minus:DI (const_int 64)
2089                     (ashift:DI
2090                      (and:DI
2091                       (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2092                       (const_int 7))
2093                      (const_int 3)))))]
2094   "! WORDS_BIG_ENDIAN"
2095   "extwh %r1,%2,%0"
2096   [(set_attr "type" "shift")])
2097
2098 (define_insn "extwh_be"
2099   [(set (match_operand:DI 0 "register_operand" "=r")
2100         (and:DI
2101           (ashift:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
2102                      (ashift:DI
2103                        (and:DI
2104                          (plus:DI
2105                            (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2106                            (const_int 1))
2107                          (const_int 7))
2108                        (const_int 3)))
2109           (const_int 65535)))]
2110   "WORDS_BIG_ENDIAN"
2111   "extwh %r1,%2,%0"
2112   [(set_attr "type" "shift")])
2113
2114 ;; This converts an extXl into an extXh with an appropriate adjustment
2115 ;; to the address calculation.
2116
2117 ;;(define_split
2118 ;;  [(set (match_operand:DI 0 "register_operand" "")
2119 ;;      (ashift:DI (zero_extract:DI (match_operand:DI 1 "register_operand" "")
2120 ;;                                  (match_operand:DI 2 "mode_width_operand" "")
2121 ;;                                  (ashift:DI (match_operand:DI 3 "" "")
2122 ;;                                             (const_int 3)))
2123 ;;                 (match_operand:DI 4 "const_int_operand" "")))
2124 ;;   (clobber (match_operand:DI 5 "register_operand" ""))]
2125 ;;  "INTVAL (operands[4]) == 64 - INTVAL (operands[2])"
2126 ;;  [(set (match_dup 5) (match_dup 6))
2127 ;;   (set (match_dup 0)
2128 ;;      (ashift:DI (zero_extract:DI (match_dup 1) (match_dup 2)
2129 ;;                                  (ashift:DI (plus:DI (match_dup 5)
2130 ;;                                                      (match_dup 7))
2131 ;;                                             (const_int 3)))
2132 ;;                 (match_dup 4)))]
2133 ;;  "
2134 ;;{
2135 ;;  operands[6] = plus_constant (operands[3],
2136 ;;                             INTVAL (operands[2]) / BITS_PER_UNIT);
2137 ;;  operands[7] = GEN_INT (- INTVAL (operands[2]) / BITS_PER_UNIT);
2138 ;;}")
2139
2140 (define_insn "*insbl_const"
2141   [(set (match_operand:DI 0 "register_operand" "=r")
2142         (ashift:DI (zero_extend:DI (match_operand:QI 1 "register_operand" "r"))
2143                    (match_operand:DI 2 "mul8_operand" "I")))]
2144   ""
2145   "insbl %1,%s2,%0"
2146   [(set_attr "type" "shift")])
2147
2148 (define_insn "*inswl_const"
2149   [(set (match_operand:DI 0 "register_operand" "=r")
2150         (ashift:DI (zero_extend:DI (match_operand:HI 1 "register_operand" "r"))
2151                    (match_operand:DI 2 "mul8_operand" "I")))]
2152   ""
2153   "inswl %1,%s2,%0"
2154   [(set_attr "type" "shift")])
2155
2156 (define_insn "*insll_const"
2157   [(set (match_operand:DI 0 "register_operand" "=r")
2158         (ashift:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "r"))
2159                    (match_operand:DI 2 "mul8_operand" "I")))]
2160   ""
2161   "insll %1,%s2,%0"
2162   [(set_attr "type" "shift")])
2163
2164 (define_insn "insbl_le"
2165   [(set (match_operand:DI 0 "register_operand" "=r")
2166         (ashift:DI (zero_extend:DI (match_operand:QI 1 "register_operand" "r"))
2167                    (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2168                               (const_int 3))))]
2169   "! WORDS_BIG_ENDIAN"
2170   "insbl %1,%2,%0"
2171   [(set_attr "type" "shift")])
2172
2173 (define_insn "insbl_be"
2174  [(set (match_operand:DI 0 "register_operand" "=r")
2175        (ashift:DI (zero_extend:DI (match_operand:QI 1 "register_operand" "r"))
2176          (minus:DI (const_int 56)
2177            (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2178                       (const_int 3)))))]
2179   "WORDS_BIG_ENDIAN"
2180   "insbl %1,%2,%0"
2181   [(set_attr "type" "shift")])
2182
2183 (define_insn "inswl_le"
2184   [(set (match_operand:DI 0 "register_operand" "=r")
2185         (ashift:DI (zero_extend:DI (match_operand:HI 1 "register_operand" "r"))
2186                    (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2187                               (const_int 3))))]
2188   "! WORDS_BIG_ENDIAN"
2189   "inswl %1,%2,%0"
2190   [(set_attr "type" "shift")])
2191
2192 (define_insn "inswl_be"
2193   [(set (match_operand:DI 0 "register_operand" "=r")
2194         (ashift:DI (zero_extend:DI (match_operand:HI 1 "register_operand" "r"))
2195           (minus:DI (const_int 56)
2196             (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2197                        (const_int 3)))))]
2198   "WORDS_BIG_ENDIAN"
2199   "inswl %1,%2,%0"
2200   [(set_attr "type" "shift")])
2201
2202 (define_insn "insll_le"
2203   [(set (match_operand:DI 0 "register_operand" "=r")
2204         (ashift:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "r"))
2205                    (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2206                               (const_int 3))))]
2207   "! WORDS_BIG_ENDIAN"
2208   "insll %1,%2,%0"
2209   [(set_attr "type" "shift")])
2210
2211 (define_insn "insll_be"
2212   [(set (match_operand:DI 0 "register_operand" "=r")
2213         (ashift:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "r"))
2214           (minus:DI (const_int 56)
2215             (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2216                        (const_int 3)))))]
2217   "WORDS_BIG_ENDIAN"
2218   "insll %1,%2,%0"
2219   [(set_attr "type" "shift")])
2220
2221 (define_insn "insql_le"
2222   [(set (match_operand:DI 0 "register_operand" "=r")
2223         (ashift:DI (match_operand:DI 1 "register_operand" "r")
2224                    (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2225                               (const_int 3))))]
2226   "! WORDS_BIG_ENDIAN"
2227   "insql %1,%2,%0"
2228   [(set_attr "type" "shift")])
2229
2230 (define_insn "insql_be"
2231   [(set (match_operand:DI 0 "register_operand" "=r")
2232         (ashift:DI (match_operand:DI 1 "register_operand" "r")
2233           (minus:DI (const_int 56)
2234             (ashift:DI (match_operand:DI 2 "reg_or_8bit_operand" "rI")
2235                        (const_int 3)))))]
2236   "WORDS_BIG_ENDIAN"
2237   "insql %1,%2,%0"
2238   [(set_attr "type" "shift")])
2239
2240 ;; Combine has this sometimes habit of moving the and outside of the
2241 ;; shift, making life more interesting.
2242
2243 (define_insn "*insxl"
2244   [(set (match_operand:DI 0 "register_operand" "=r")
2245         (and:DI (ashift:DI (match_operand:DI 1 "register_operand" "r")
2246                            (match_operand:DI 2 "mul8_operand" "I"))
2247                 (match_operand:DI 3 "immediate_operand" "i")))]
2248   "HOST_BITS_PER_WIDE_INT == 64
2249    && GET_CODE (operands[3]) == CONST_INT
2250    && (((unsigned HOST_WIDE_INT) 0xff << INTVAL (operands[2])
2251         == (unsigned HOST_WIDE_INT) INTVAL (operands[3]))
2252        || ((unsigned HOST_WIDE_INT) 0xffff << INTVAL (operands[2])
2253         == (unsigned HOST_WIDE_INT) INTVAL (operands[3]))
2254        || ((unsigned HOST_WIDE_INT) 0xffffffff << INTVAL (operands[2])
2255         == (unsigned HOST_WIDE_INT) INTVAL (operands[3])))"
2256 {
2257 #if HOST_BITS_PER_WIDE_INT == 64
2258   if ((unsigned HOST_WIDE_INT) 0xff << INTVAL (operands[2])
2259       == (unsigned HOST_WIDE_INT) INTVAL (operands[3]))
2260     return "insbl %1,%s2,%0";
2261   if ((unsigned HOST_WIDE_INT) 0xffff << INTVAL (operands[2])
2262       == (unsigned HOST_WIDE_INT) INTVAL (operands[3]))
2263     return "inswl %1,%s2,%0";
2264   if ((unsigned HOST_WIDE_INT) 0xffffffff << INTVAL (operands[2])
2265       == (unsigned HOST_WIDE_INT) INTVAL (operands[3]))
2266     return "insll %1,%s2,%0";
2267 #endif
2268   abort();
2269 }
2270   [(set_attr "type" "shift")])
2271
2272 ;; We do not include the insXh insns because they are complex to express
2273 ;; and it does not appear that we would ever want to generate them.
2274 ;;
2275 ;; Since we need them for block moves, though, cop out and use unspec.
2276
2277 (define_insn "insxh"
2278   [(set (match_operand:DI 0 "register_operand" "=r")
2279         (unspec:DI [(match_operand:DI 1 "register_operand" "r")
2280                     (match_operand:DI 2 "mode_width_operand" "n")
2281                     (match_operand:DI 3 "reg_or_8bit_operand" "rI")]
2282                    UNSPEC_INSXH))]
2283   ""
2284   "ins%M2h %1,%3,%0"
2285   [(set_attr "type" "shift")])
2286
2287 (define_insn "mskxl_le"
2288   [(set (match_operand:DI 0 "register_operand" "=r")
2289         (and:DI (not:DI (ashift:DI
2290                          (match_operand:DI 2 "mode_mask_operand" "n")
2291                          (ashift:DI
2292                           (match_operand:DI 3 "reg_or_8bit_operand" "rI")
2293                           (const_int 3))))
2294                 (match_operand:DI 1 "reg_or_0_operand" "rJ")))]
2295   "! WORDS_BIG_ENDIAN"
2296   "msk%U2l %r1,%3,%0"
2297   [(set_attr "type" "shift")])
2298
2299 (define_insn "mskxl_be"
2300   [(set (match_operand:DI 0 "register_operand" "=r")
2301         (and:DI (not:DI (ashift:DI
2302                           (match_operand:DI 2 "mode_mask_operand" "n")
2303                           (minus:DI (const_int 56)
2304                             (ashift:DI
2305                               (match_operand:DI 3 "reg_or_8bit_operand" "rI")
2306                               (const_int 3)))))
2307                 (match_operand:DI 1 "reg_or_0_operand" "rJ")))]
2308   "WORDS_BIG_ENDIAN"
2309   "msk%U2l %r1,%3,%0"
2310   [(set_attr "type" "shift")])
2311
2312 ;; We do not include the mskXh insns because it does not appear we would
2313 ;; ever generate one.
2314 ;;
2315 ;; Again, we do for block moves and we use unspec again.
2316
2317 (define_insn "mskxh"
2318   [(set (match_operand:DI 0 "register_operand" "=r")
2319         (unspec:DI [(match_operand:DI 1 "register_operand" "r")
2320                     (match_operand:DI 2 "mode_width_operand" "n")
2321                     (match_operand:DI 3 "reg_or_8bit_operand" "rI")]
2322                    UNSPEC_MSKXH))]
2323   ""
2324   "msk%M2h %1,%3,%0"
2325   [(set_attr "type" "shift")])
2326
2327 ;; Prefer AND + NE over LSHIFTRT + AND.
2328
2329 (define_insn_and_split "*ze_and_ne"
2330   [(set (match_operand:DI 0 "register_operand" "=r")
2331         (zero_extract:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
2332                          (const_int 1)
2333                          (match_operand 2 "const_int_operand" "I")))]
2334   "(unsigned HOST_WIDE_INT) INTVAL (operands[2]) < 8"
2335   "#"
2336   "(unsigned HOST_WIDE_INT) INTVAL (operands[2]) < 8"
2337   [(set (match_dup 0)
2338         (and:DI (match_dup 1) (match_dup 3)))
2339    (set (match_dup 0)
2340         (ne:DI (match_dup 0) (const_int 0)))]
2341   "operands[3] = GEN_INT (1 << INTVAL (operands[2]));")
2342 \f
2343 ;; Floating-point operations.  All the double-precision insns can extend
2344 ;; from single, so indicate that.  The exception are the ones that simply
2345 ;; play with the sign bits; it's not clear what to do there.
2346
2347 (define_insn "abssf2"
2348   [(set (match_operand:SF 0 "register_operand" "=f")
2349         (abs:SF (match_operand:SF 1 "reg_or_fp0_operand" "fG")))]
2350   "TARGET_FP"
2351   "cpys $f31,%R1,%0"
2352   [(set_attr "type" "fcpys")])
2353
2354 (define_insn "*nabssf2"
2355   [(set (match_operand:SF 0 "register_operand" "=f")
2356         (neg:SF (abs:SF (match_operand:SF 1 "reg_or_fp0_operand" "fG"))))]
2357   "TARGET_FP"
2358   "cpysn $f31,%R1,%0"
2359   [(set_attr "type" "fadd")])
2360
2361 (define_insn "absdf2"
2362   [(set (match_operand:DF 0 "register_operand" "=f")
2363         (abs:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG")))]
2364   "TARGET_FP"
2365   "cpys $f31,%R1,%0"
2366   [(set_attr "type" "fcpys")])
2367
2368 (define_insn "*nabsdf2"
2369   [(set (match_operand:DF 0 "register_operand" "=f")
2370         (neg:DF (abs:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG"))))]
2371   "TARGET_FP"
2372   "cpysn $f31,%R1,%0"
2373   [(set_attr "type" "fadd")])
2374
2375 (define_expand "abstf2"
2376   [(parallel [(set (match_operand:TF 0 "register_operand" "")
2377                    (neg:TF (match_operand:TF 1 "reg_or_fp0_operand" "")))
2378               (use (match_dup 2))])]
2379   "TARGET_HAS_XFLOATING_LIBS"
2380 {
2381 #if HOST_BITS_PER_WIDE_INT >= 64
2382   operands[2] = force_reg (DImode, GEN_INT ((HOST_WIDE_INT) 1 << 63));
2383 #else
2384   operands[2] = force_reg (DImode, immed_double_const (0, 0x80000000, DImode));
2385 #endif
2386 })
2387
2388 (define_insn_and_split "*abstf_internal"
2389   [(set (match_operand:TF 0 "register_operand" "=r")
2390         (abs:TF (match_operand:TF 1 "reg_or_fp0_operand" "rG")))
2391    (use (match_operand:DI 2 "register_operand" "r"))]
2392   "TARGET_HAS_XFLOATING_LIBS"
2393   "#"
2394   "&& reload_completed"
2395   [(const_int 0)]
2396   "alpha_split_tfmode_frobsign (operands, gen_andnotdi3); DONE;")
2397
2398 (define_insn "negsf2"
2399   [(set (match_operand:SF 0 "register_operand" "=f")
2400         (neg:SF (match_operand:SF 1 "reg_or_fp0_operand" "fG")))]
2401   "TARGET_FP"
2402   "cpysn %R1,%R1,%0"
2403   [(set_attr "type" "fadd")])
2404
2405 (define_insn "negdf2"
2406   [(set (match_operand:DF 0 "register_operand" "=f")
2407         (neg:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG")))]
2408   "TARGET_FP"
2409   "cpysn %R1,%R1,%0"
2410   [(set_attr "type" "fadd")])
2411
2412 (define_expand "negtf2"
2413   [(parallel [(set (match_operand:TF 0 "register_operand" "")
2414                    (neg:TF (match_operand:TF 1 "reg_or_fp0_operand" "")))
2415               (use (match_dup 2))])]
2416   "TARGET_HAS_XFLOATING_LIBS"
2417 {
2418 #if HOST_BITS_PER_WIDE_INT >= 64
2419   operands[2] = force_reg (DImode, GEN_INT ((HOST_WIDE_INT) 1 << 63));
2420 #else
2421   operands[2] = force_reg (DImode, immed_double_const (0, 0x80000000, DImode));
2422 #endif
2423 })
2424
2425 (define_insn_and_split "*negtf_internal"
2426   [(set (match_operand:TF 0 "register_operand" "=r")
2427         (neg:TF (match_operand:TF 1 "reg_or_fp0_operand" "rG")))
2428    (use (match_operand:DI 2 "register_operand" "r"))]
2429   "TARGET_HAS_XFLOATING_LIBS"
2430   "#"
2431   "&& reload_completed"
2432   [(const_int 0)]
2433   "alpha_split_tfmode_frobsign (operands, gen_xordi3); DONE;")
2434
2435 (define_insn "*addsf_ieee"
2436   [(set (match_operand:SF 0 "register_operand" "=&f")
2437         (plus:SF (match_operand:SF 1 "reg_or_fp0_operand" "%fG")
2438                  (match_operand:SF 2 "reg_or_fp0_operand" "fG")))]
2439   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2440   "add%,%/ %R1,%R2,%0"
2441   [(set_attr "type" "fadd")
2442    (set_attr "trap" "yes")
2443    (set_attr "round_suffix" "normal")
2444    (set_attr "trap_suffix" "u_su_sui")])
2445
2446 (define_insn "addsf3"
2447   [(set (match_operand:SF 0 "register_operand" "=f")
2448         (plus:SF (match_operand:SF 1 "reg_or_fp0_operand" "%fG")
2449                  (match_operand:SF 2 "reg_or_fp0_operand" "fG")))]
2450   "TARGET_FP"
2451   "add%,%/ %R1,%R2,%0"
2452   [(set_attr "type" "fadd")
2453    (set_attr "trap" "yes")
2454    (set_attr "round_suffix" "normal")
2455    (set_attr "trap_suffix" "u_su_sui")])
2456
2457 (define_insn "*adddf_ieee"
2458   [(set (match_operand:DF 0 "register_operand" "=&f")
2459         (plus:DF (match_operand:DF 1 "reg_or_fp0_operand" "%fG")
2460                  (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
2461   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2462   "add%-%/ %R1,%R2,%0"
2463   [(set_attr "type" "fadd")
2464    (set_attr "trap" "yes")
2465    (set_attr "round_suffix" "normal")
2466    (set_attr "trap_suffix" "u_su_sui")])
2467
2468 (define_insn "adddf3"
2469   [(set (match_operand:DF 0 "register_operand" "=f")
2470         (plus:DF (match_operand:DF 1 "reg_or_fp0_operand" "%fG")
2471                  (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
2472   "TARGET_FP"
2473   "add%-%/ %R1,%R2,%0"
2474   [(set_attr "type" "fadd")
2475    (set_attr "trap" "yes")
2476    (set_attr "round_suffix" "normal")
2477    (set_attr "trap_suffix" "u_su_sui")])
2478
2479 (define_insn "*adddf_ext1"
2480   [(set (match_operand:DF 0 "register_operand" "=f")
2481         (plus:DF (float_extend:DF
2482                   (match_operand:SF 1 "reg_or_fp0_operand" "fG"))
2483                  (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
2484   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
2485   "add%-%/ %R1,%R2,%0"
2486   [(set_attr "type" "fadd")
2487    (set_attr "trap" "yes")
2488    (set_attr "round_suffix" "normal")
2489    (set_attr "trap_suffix" "u_su_sui")])
2490
2491 (define_insn "*adddf_ext2"
2492   [(set (match_operand:DF 0 "register_operand" "=f")
2493         (plus:DF (float_extend:DF
2494                   (match_operand:SF 1 "reg_or_fp0_operand" "%fG"))
2495                  (float_extend:DF
2496                   (match_operand:SF 2 "reg_or_fp0_operand" "fG"))))]
2497   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
2498   "add%-%/ %R1,%R2,%0"
2499   [(set_attr "type" "fadd")
2500    (set_attr "trap" "yes")
2501    (set_attr "round_suffix" "normal")
2502    (set_attr "trap_suffix" "u_su_sui")])
2503
2504 (define_expand "addtf3"
2505   [(use (match_operand 0 "register_operand" ""))
2506    (use (match_operand 1 "general_operand" ""))
2507    (use (match_operand 2 "general_operand" ""))]
2508   "TARGET_HAS_XFLOATING_LIBS"
2509   "alpha_emit_xfloating_arith (PLUS, operands); DONE;")
2510
2511 ;; Define conversion operators between DFmode and SImode, using the cvtql
2512 ;; instruction.  To allow combine et al to do useful things, we keep the
2513 ;; operation as a unit until after reload, at which point we split the
2514 ;; instructions.
2515 ;;
2516 ;; Note that we (attempt to) only consider this optimization when the
2517 ;; ultimate destination is memory.  If we will be doing further integer
2518 ;; processing, it is cheaper to do the truncation in the int regs.
2519
2520 (define_insn "*cvtql"
2521   [(set (match_operand:SI 0 "register_operand" "=f")
2522         (unspec:SI [(match_operand:DI 1 "reg_or_fp0_operand" "fG")]
2523                    UNSPEC_CVTQL))]
2524   "TARGET_FP"
2525   "cvtql%/ %R1,%0"
2526   [(set_attr "type" "fadd")
2527    (set_attr "trap" "yes")
2528    (set_attr "trap_suffix" "v_sv")])
2529
2530 (define_insn_and_split "*fix_truncdfsi_ieee"
2531   [(set (match_operand:SI 0 "memory_operand" "=m")
2532         (subreg:SI (fix:DI (match_operand:DF 1 "reg_or_fp0_operand" "fG")) 0))
2533    (clobber (match_scratch:DI 2 "=&f"))
2534    (clobber (match_scratch:SI 3 "=&f"))]
2535   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2536   "#"
2537   "&& reload_completed"
2538   [(set (match_dup 2) (fix:DI (match_dup 1)))
2539    (set (match_dup 3) (unspec:SI [(match_dup 2)] UNSPEC_CVTQL))
2540    (set (match_dup 0) (match_dup 3))]
2541   ""
2542   [(set_attr "type" "fadd")
2543    (set_attr "trap" "yes")])
2544
2545 (define_insn_and_split "*fix_truncdfsi_internal"
2546   [(set (match_operand:SI 0 "memory_operand" "=m")
2547         (subreg:SI (fix:DI (match_operand:DF 1 "reg_or_fp0_operand" "fG")) 0))
2548    (clobber (match_scratch:DI 2 "=f"))]
2549   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
2550   "#"
2551   "&& reload_completed"
2552   [(set (match_dup 2) (fix:DI (match_dup 1)))
2553    (set (match_dup 3) (unspec:SI [(match_dup 2)] UNSPEC_CVTQL))
2554    (set (match_dup 0) (match_dup 3))]
2555   ;; Due to REG_CANNOT_CHANGE_SIZE issues, we cannot simply use SUBREG.
2556   "operands[3] = gen_rtx_REG (SImode, REGNO (operands[2]));"
2557   [(set_attr "type" "fadd")
2558    (set_attr "trap" "yes")])
2559
2560 (define_insn "*fix_truncdfdi_ieee"
2561   [(set (match_operand:DI 0 "reg_no_subreg_operand" "=&f")
2562         (fix:DI (match_operand:DF 1 "reg_or_fp0_operand" "fG")))]
2563   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2564   "cvt%-q%/ %R1,%0"
2565   [(set_attr "type" "fadd")
2566    (set_attr "trap" "yes")
2567    (set_attr "round_suffix" "c")
2568    (set_attr "trap_suffix" "v_sv_svi")])
2569
2570 (define_insn "fix_truncdfdi2"
2571   [(set (match_operand:DI 0 "reg_no_subreg_operand" "=f")
2572         (fix:DI (match_operand:DF 1 "reg_or_fp0_operand" "fG")))]
2573   "TARGET_FP"
2574   "cvt%-q%/ %R1,%0"
2575   [(set_attr "type" "fadd")
2576    (set_attr "trap" "yes")
2577    (set_attr "round_suffix" "c")
2578    (set_attr "trap_suffix" "v_sv_svi")])
2579
2580 ;; Likewise between SFmode and SImode.
2581
2582 (define_insn_and_split "*fix_truncsfsi_ieee"
2583   [(set (match_operand:SI 0 "memory_operand" "=m")
2584         (subreg:SI (fix:DI (float_extend:DF
2585                  (match_operand:SF 1 "reg_or_fp0_operand" "fG"))) 0))
2586    (clobber (match_scratch:DI 2 "=&f"))
2587    (clobber (match_scratch:SI 3 "=&f"))]
2588   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2589   "#"
2590   "&& reload_completed"
2591   [(set (match_dup 2) (fix:DI (float_extend:DF (match_dup 1))))
2592    (set (match_dup 3) (unspec:SI [(match_dup 2)] UNSPEC_CVTQL))
2593    (set (match_dup 0) (match_dup 3))]
2594   ""
2595   [(set_attr "type" "fadd")
2596    (set_attr "trap" "yes")])
2597
2598 (define_insn_and_split "*fix_truncsfsi_internal"
2599   [(set (match_operand:SI 0 "memory_operand" "=m")
2600         (subreg:SI (fix:DI (float_extend:DF
2601                  (match_operand:SF 1 "reg_or_fp0_operand" "fG"))) 0))
2602    (clobber (match_scratch:DI 2 "=f"))]
2603   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
2604   "#"
2605   "&& reload_completed"
2606   [(set (match_dup 2) (fix:DI (float_extend:DF (match_dup 1))))
2607    (set (match_dup 3) (unspec:SI [(match_dup 2)] UNSPEC_CVTQL))
2608    (set (match_dup 0) (match_dup 3))]
2609   ;; Due to REG_CANNOT_CHANGE_SIZE issues, we cannot simply use SUBREG.
2610   "operands[3] = gen_rtx_REG (SImode, REGNO (operands[2]));"
2611   [(set_attr "type" "fadd")
2612    (set_attr "trap" "yes")])
2613
2614 (define_insn "*fix_truncsfdi_ieee"
2615   [(set (match_operand:DI 0 "reg_no_subreg_operand" "=&f")
2616         (fix:DI (float_extend:DF
2617                  (match_operand:SF 1 "reg_or_fp0_operand" "fG"))))]
2618   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2619   "cvt%-q%/ %R1,%0"
2620   [(set_attr "type" "fadd")
2621    (set_attr "trap" "yes")
2622    (set_attr "round_suffix" "c")
2623    (set_attr "trap_suffix" "v_sv_svi")])
2624
2625 (define_insn "fix_truncsfdi2"
2626   [(set (match_operand:DI 0 "reg_no_subreg_operand" "=f")
2627         (fix:DI (float_extend:DF
2628                  (match_operand:SF 1 "reg_or_fp0_operand" "fG"))))]
2629   "TARGET_FP"
2630   "cvt%-q%/ %R1,%0"
2631   [(set_attr "type" "fadd")
2632    (set_attr "trap" "yes")
2633    (set_attr "round_suffix" "c")
2634    (set_attr "trap_suffix" "v_sv_svi")])
2635
2636 (define_expand "fix_trunctfdi2"
2637   [(use (match_operand:DI 0 "register_operand" ""))
2638    (use (match_operand:TF 1 "general_operand" ""))]
2639   "TARGET_HAS_XFLOATING_LIBS"
2640   "alpha_emit_xfloating_cvt (FIX, operands); DONE;")
2641
2642 (define_insn "*floatdisf_ieee"
2643   [(set (match_operand:SF 0 "register_operand" "=&f")
2644         (float:SF (match_operand:DI 1 "reg_no_subreg_operand" "f")))]
2645   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2646   "cvtq%,%/ %1,%0"
2647   [(set_attr "type" "fadd")
2648    (set_attr "trap" "yes")
2649    (set_attr "round_suffix" "normal")
2650    (set_attr "trap_suffix" "sui")])
2651
2652 (define_insn "floatdisf2"
2653   [(set (match_operand:SF 0 "register_operand" "=f")
2654         (float:SF (match_operand:DI 1 "reg_no_subreg_operand" "f")))]
2655   "TARGET_FP"
2656   "cvtq%,%/ %1,%0"
2657   [(set_attr "type" "fadd")
2658    (set_attr "trap" "yes")
2659    (set_attr "round_suffix" "normal")
2660    (set_attr "trap_suffix" "sui")])
2661
2662 (define_insn "*floatdidf_ieee"
2663   [(set (match_operand:DF 0 "register_operand" "=&f")
2664         (float:DF (match_operand:DI 1 "reg_no_subreg_operand" "f")))]
2665   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2666   "cvtq%-%/ %1,%0"
2667   [(set_attr "type" "fadd")
2668    (set_attr "trap" "yes")
2669    (set_attr "round_suffix" "normal")
2670    (set_attr "trap_suffix" "sui")])
2671
2672 (define_insn "floatdidf2"
2673   [(set (match_operand:DF 0 "register_operand" "=f")
2674         (float:DF (match_operand:DI 1 "reg_no_subreg_operand" "f")))]
2675   "TARGET_FP"
2676   "cvtq%-%/ %1,%0"
2677   [(set_attr "type" "fadd")
2678    (set_attr "trap" "yes")
2679    (set_attr "round_suffix" "normal")
2680    (set_attr "trap_suffix" "sui")])
2681
2682 (define_expand "floatditf2"
2683   [(use (match_operand:TF 0 "register_operand" ""))
2684    (use (match_operand:DI 1 "general_operand" ""))]
2685   "TARGET_HAS_XFLOATING_LIBS"
2686   "alpha_emit_xfloating_cvt (FLOAT, operands); DONE;")
2687
2688 (define_expand "floatunsdisf2"
2689   [(use (match_operand:SF 0 "register_operand" ""))
2690    (use (match_operand:DI 1 "register_operand" ""))]
2691   "TARGET_FP"
2692   "alpha_emit_floatuns (operands); DONE;")
2693
2694 (define_expand "floatunsdidf2"
2695   [(use (match_operand:DF 0 "register_operand" ""))
2696    (use (match_operand:DI 1 "register_operand" ""))]
2697   "TARGET_FP"
2698   "alpha_emit_floatuns (operands); DONE;")
2699
2700 (define_expand "floatunsditf2"
2701   [(use (match_operand:TF 0 "register_operand" ""))
2702    (use (match_operand:DI 1 "general_operand" ""))]
2703   "TARGET_HAS_XFLOATING_LIBS"
2704   "alpha_emit_xfloating_cvt (UNSIGNED_FLOAT, operands); DONE;")
2705
2706 (define_expand "extendsfdf2"
2707   [(set (match_operand:DF 0 "register_operand" "")
2708         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "")))]
2709   "TARGET_FP"
2710 {
2711   if (alpha_fptm >= ALPHA_FPTM_SU)
2712     operands[1] = force_reg (SFmode, operands[1]);
2713 })
2714
2715 ;; The Unicos/Mk assembler doesn't support cvtst, but we've already
2716 ;; asserted that alpha_fptm == ALPHA_FPTM_N.
2717
2718 (define_insn "*extendsfdf2_ieee"
2719   [(set (match_operand:DF 0 "register_operand" "=&f")
2720         (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
2721   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2722   "cvtsts %1,%0"
2723   [(set_attr "type" "fadd")
2724    (set_attr "trap" "yes")])
2725
2726 (define_insn "*extendsfdf2_internal"
2727   [(set (match_operand:DF 0 "register_operand" "=f,f,m")
2728         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "f,m,f")))]
2729   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
2730   "@
2731    cpys %1,%1,%0
2732    ld%, %0,%1
2733    st%- %1,%0"
2734   [(set_attr "type" "fcpys,fld,fst")])
2735
2736 (define_expand "extendsftf2"
2737   [(use (match_operand:TF 0 "register_operand" ""))
2738    (use (match_operand:SF 1 "general_operand" ""))]
2739   "TARGET_HAS_XFLOATING_LIBS"
2740 {
2741   rtx tmp = gen_reg_rtx (DFmode);
2742   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
2743   emit_insn (gen_extenddftf2 (operands[0], tmp));
2744   DONE;
2745 })
2746
2747 (define_expand "extenddftf2"
2748   [(use (match_operand:TF 0 "register_operand" ""))
2749    (use (match_operand:DF 1 "general_operand" ""))]
2750   "TARGET_HAS_XFLOATING_LIBS"
2751   "alpha_emit_xfloating_cvt (FLOAT_EXTEND, operands); DONE;")
2752
2753 (define_insn "*truncdfsf2_ieee"
2754   [(set (match_operand:SF 0 "register_operand" "=&f")
2755         (float_truncate:SF (match_operand:DF 1 "reg_or_fp0_operand" "fG")))]
2756   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2757   "cvt%-%,%/ %R1,%0"
2758   [(set_attr "type" "fadd")
2759    (set_attr "trap" "yes")
2760    (set_attr "round_suffix" "normal")
2761    (set_attr "trap_suffix" "u_su_sui")])
2762
2763 (define_insn "truncdfsf2"
2764   [(set (match_operand:SF 0 "register_operand" "=f")
2765         (float_truncate:SF (match_operand:DF 1 "reg_or_fp0_operand" "fG")))]
2766   "TARGET_FP"
2767   "cvt%-%,%/ %R1,%0"
2768   [(set_attr "type" "fadd")
2769    (set_attr "trap" "yes")
2770    (set_attr "round_suffix" "normal")
2771    (set_attr "trap_suffix" "u_su_sui")])
2772
2773 (define_expand "trunctfdf2"
2774   [(use (match_operand:DF 0 "register_operand" ""))
2775    (use (match_operand:TF 1 "general_operand" ""))]
2776   "TARGET_HAS_XFLOATING_LIBS"
2777   "alpha_emit_xfloating_cvt (FLOAT_TRUNCATE, operands); DONE;")
2778
2779 (define_expand "trunctfsf2"
2780   [(use (match_operand:SF 0 "register_operand" ""))
2781    (use (match_operand:TF 1 "general_operand" ""))]
2782   "TARGET_FP && TARGET_HAS_XFLOATING_LIBS"
2783 {
2784   rtx tmpf, sticky, arg, lo, hi;
2785
2786   tmpf = gen_reg_rtx (DFmode);
2787   sticky = gen_reg_rtx (DImode);
2788   arg = copy_to_mode_reg (TFmode, operands[1]);
2789   lo = gen_lowpart (DImode, arg);
2790   hi = gen_highpart (DImode, arg);
2791
2792   /* Convert the low word of the TFmode value into a sticky rounding bit,
2793      then or it into the low bit of the high word.  This leaves the sticky
2794      bit at bit 48 of the fraction, which is representable in DFmode,
2795      which prevents rounding error in the final conversion to SFmode.  */
2796
2797   emit_insn (gen_rtx_SET (VOIDmode, sticky,
2798                           gen_rtx_NE (DImode, lo, const0_rtx)));
2799   emit_insn (gen_iordi3 (hi, hi, sticky));
2800   emit_insn (gen_trunctfdf2 (tmpf, arg));
2801   emit_insn (gen_truncdfsf2 (operands[0], tmpf));
2802   DONE;
2803 })
2804
2805 (define_insn "*divsf3_ieee"
2806   [(set (match_operand:SF 0 "register_operand" "=&f")
2807         (div:SF (match_operand:SF 1 "reg_or_fp0_operand" "fG")
2808                 (match_operand:SF 2 "reg_or_fp0_operand" "fG")))]
2809   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2810   "div%,%/ %R1,%R2,%0"
2811   [(set_attr "type" "fdiv")
2812    (set_attr "opsize" "si")
2813    (set_attr "trap" "yes")
2814    (set_attr "round_suffix" "normal")
2815    (set_attr "trap_suffix" "u_su_sui")])
2816
2817 (define_insn "divsf3"
2818   [(set (match_operand:SF 0 "register_operand" "=f")
2819         (div:SF (match_operand:SF 1 "reg_or_fp0_operand" "fG")
2820                 (match_operand:SF 2 "reg_or_fp0_operand" "fG")))]
2821   "TARGET_FP"
2822   "div%,%/ %R1,%R2,%0"
2823   [(set_attr "type" "fdiv")
2824    (set_attr "opsize" "si")
2825    (set_attr "trap" "yes")
2826    (set_attr "round_suffix" "normal")
2827    (set_attr "trap_suffix" "u_su_sui")])
2828
2829 (define_insn "*divdf3_ieee"
2830   [(set (match_operand:DF 0 "register_operand" "=&f")
2831         (div:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG")
2832                 (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
2833   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2834   "div%-%/ %R1,%R2,%0"
2835   [(set_attr "type" "fdiv")
2836    (set_attr "trap" "yes")
2837    (set_attr "round_suffix" "normal")
2838    (set_attr "trap_suffix" "u_su_sui")])
2839
2840 (define_insn "divdf3"
2841   [(set (match_operand:DF 0 "register_operand" "=f")
2842         (div:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG")
2843                 (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
2844   "TARGET_FP"
2845   "div%-%/ %R1,%R2,%0"
2846   [(set_attr "type" "fdiv")
2847    (set_attr "trap" "yes")
2848    (set_attr "round_suffix" "normal")
2849    (set_attr "trap_suffix" "u_su_sui")])
2850
2851 (define_insn "*divdf_ext1"
2852   [(set (match_operand:DF 0 "register_operand" "=f")
2853         (div:DF (float_extend:DF (match_operand:SF 1 "reg_or_fp0_operand" "fG"))
2854                 (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
2855   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
2856   "div%-%/ %R1,%R2,%0"
2857   [(set_attr "type" "fdiv")
2858    (set_attr "trap" "yes")
2859    (set_attr "round_suffix" "normal")
2860    (set_attr "trap_suffix" "u_su_sui")])
2861
2862 (define_insn "*divdf_ext2"
2863   [(set (match_operand:DF 0 "register_operand" "=f")
2864         (div:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG")
2865                 (float_extend:DF
2866                  (match_operand:SF 2 "reg_or_fp0_operand" "fG"))))]
2867   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
2868   "div%-%/ %R1,%R2,%0"
2869   [(set_attr "type" "fdiv")
2870    (set_attr "trap" "yes")
2871    (set_attr "round_suffix" "normal")
2872    (set_attr "trap_suffix" "u_su_sui")])
2873
2874 (define_insn "*divdf_ext3"
2875   [(set (match_operand:DF 0 "register_operand" "=f")
2876         (div:DF (float_extend:DF (match_operand:SF 1 "reg_or_fp0_operand" "fG"))
2877                 (float_extend:DF (match_operand:SF 2 "reg_or_fp0_operand" "fG"))))]
2878   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
2879   "div%-%/ %R1,%R2,%0"
2880   [(set_attr "type" "fdiv")
2881    (set_attr "trap" "yes")
2882    (set_attr "round_suffix" "normal")
2883    (set_attr "trap_suffix" "u_su_sui")])
2884
2885 (define_expand "divtf3"
2886   [(use (match_operand 0 "register_operand" ""))
2887    (use (match_operand 1 "general_operand" ""))
2888    (use (match_operand 2 "general_operand" ""))]
2889   "TARGET_HAS_XFLOATING_LIBS"
2890   "alpha_emit_xfloating_arith (DIV, operands); DONE;")
2891
2892 (define_insn "*mulsf3_ieee"
2893   [(set (match_operand:SF 0 "register_operand" "=&f")
2894         (mult:SF (match_operand:SF 1 "reg_or_fp0_operand" "%fG")
2895                  (match_operand:SF 2 "reg_or_fp0_operand" "fG")))]
2896   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2897   "mul%,%/ %R1,%R2,%0"
2898   [(set_attr "type" "fmul")
2899    (set_attr "trap" "yes")
2900    (set_attr "round_suffix" "normal")
2901    (set_attr "trap_suffix" "u_su_sui")])
2902
2903 (define_insn "mulsf3"
2904   [(set (match_operand:SF 0 "register_operand" "=f")
2905         (mult:SF (match_operand:SF 1 "reg_or_fp0_operand" "%fG")
2906                  (match_operand:SF 2 "reg_or_fp0_operand" "fG")))]
2907   "TARGET_FP"
2908   "mul%,%/ %R1,%R2,%0"
2909   [(set_attr "type" "fmul")
2910    (set_attr "trap" "yes")
2911    (set_attr "round_suffix" "normal")
2912    (set_attr "trap_suffix" "u_su_sui")])
2913
2914 (define_insn "*muldf3_ieee"
2915   [(set (match_operand:DF 0 "register_operand" "=&f")
2916         (mult:DF (match_operand:DF 1 "reg_or_fp0_operand" "%fG")
2917                  (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
2918   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2919   "mul%-%/ %R1,%R2,%0"
2920   [(set_attr "type" "fmul")
2921    (set_attr "trap" "yes")
2922    (set_attr "round_suffix" "normal")
2923    (set_attr "trap_suffix" "u_su_sui")])
2924
2925 (define_insn "muldf3"
2926   [(set (match_operand:DF 0 "register_operand" "=f")
2927         (mult:DF (match_operand:DF 1 "reg_or_fp0_operand" "%fG")
2928                  (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
2929   "TARGET_FP"
2930   "mul%-%/ %R1,%R2,%0"
2931   [(set_attr "type" "fmul")
2932    (set_attr "trap" "yes")
2933    (set_attr "round_suffix" "normal")
2934    (set_attr "trap_suffix" "u_su_sui")])
2935
2936 (define_insn "*muldf_ext1"
2937   [(set (match_operand:DF 0 "register_operand" "=f")
2938         (mult:DF (float_extend:DF
2939                   (match_operand:SF 1 "reg_or_fp0_operand" "fG"))
2940                  (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
2941   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
2942   "mul%-%/ %R1,%R2,%0"
2943   [(set_attr "type" "fmul")
2944    (set_attr "trap" "yes")
2945    (set_attr "round_suffix" "normal")
2946    (set_attr "trap_suffix" "u_su_sui")])
2947
2948 (define_insn "*muldf_ext2"
2949   [(set (match_operand:DF 0 "register_operand" "=f")
2950         (mult:DF (float_extend:DF
2951                   (match_operand:SF 1 "reg_or_fp0_operand" "%fG"))
2952                  (float_extend:DF
2953                   (match_operand:SF 2 "reg_or_fp0_operand" "fG"))))]
2954   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
2955   "mul%-%/ %R1,%R2,%0"
2956   [(set_attr "type" "fmul")
2957    (set_attr "trap" "yes")
2958    (set_attr "round_suffix" "normal")
2959    (set_attr "trap_suffix" "u_su_sui")])
2960
2961 (define_expand "multf3"
2962   [(use (match_operand 0 "register_operand" ""))
2963    (use (match_operand 1 "general_operand" ""))
2964    (use (match_operand 2 "general_operand" ""))]
2965   "TARGET_HAS_XFLOATING_LIBS"
2966   "alpha_emit_xfloating_arith (MULT, operands); DONE;")
2967
2968 (define_insn "*subsf3_ieee"
2969   [(set (match_operand:SF 0 "register_operand" "=&f")
2970         (minus:SF (match_operand:SF 1 "reg_or_fp0_operand" "fG")
2971                   (match_operand:SF 2 "reg_or_fp0_operand" "fG")))]
2972   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2973   "sub%,%/ %R1,%R2,%0"
2974   [(set_attr "type" "fadd")
2975    (set_attr "trap" "yes")
2976    (set_attr "round_suffix" "normal")
2977    (set_attr "trap_suffix" "u_su_sui")])
2978
2979 (define_insn "subsf3"
2980   [(set (match_operand:SF 0 "register_operand" "=f")
2981         (minus:SF (match_operand:SF 1 "reg_or_fp0_operand" "fG")
2982                   (match_operand:SF 2 "reg_or_fp0_operand" "fG")))]
2983   "TARGET_FP"
2984   "sub%,%/ %R1,%R2,%0"
2985   [(set_attr "type" "fadd")
2986    (set_attr "trap" "yes")
2987    (set_attr "round_suffix" "normal")
2988    (set_attr "trap_suffix" "u_su_sui")])
2989
2990 (define_insn "*subdf3_ieee"
2991   [(set (match_operand:DF 0 "register_operand" "=&f")
2992         (minus:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG")
2993                   (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
2994   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
2995   "sub%-%/ %R1,%R2,%0"
2996   [(set_attr "type" "fadd")
2997    (set_attr "trap" "yes")
2998    (set_attr "round_suffix" "normal")
2999    (set_attr "trap_suffix" "u_su_sui")])
3000
3001 (define_insn "subdf3"
3002   [(set (match_operand:DF 0 "register_operand" "=f")
3003         (minus:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG")
3004                   (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
3005   "TARGET_FP"
3006   "sub%-%/ %R1,%R2,%0"
3007   [(set_attr "type" "fadd")
3008    (set_attr "trap" "yes")
3009    (set_attr "round_suffix" "normal")
3010    (set_attr "trap_suffix" "u_su_sui")])
3011
3012 (define_insn "*subdf_ext1"
3013   [(set (match_operand:DF 0 "register_operand" "=f")
3014         (minus:DF (float_extend:DF
3015                    (match_operand:SF 1 "reg_or_fp0_operand" "fG"))
3016                   (match_operand:DF 2 "reg_or_fp0_operand" "fG")))]
3017   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
3018   "sub%-%/ %R1,%R2,%0"
3019   [(set_attr "type" "fadd")
3020    (set_attr "trap" "yes")
3021    (set_attr "round_suffix" "normal")
3022    (set_attr "trap_suffix" "u_su_sui")])
3023
3024 (define_insn "*subdf_ext2"
3025   [(set (match_operand:DF 0 "register_operand" "=f")
3026         (minus:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG")
3027                   (float_extend:DF
3028                    (match_operand:SF 2 "reg_or_fp0_operand" "fG"))))]
3029   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
3030   "sub%-%/ %R1,%R2,%0"
3031   [(set_attr "type" "fadd")
3032    (set_attr "trap" "yes")
3033    (set_attr "round_suffix" "normal")
3034    (set_attr "trap_suffix" "u_su_sui")])
3035
3036 (define_insn "*subdf_ext3"
3037   [(set (match_operand:DF 0 "register_operand" "=f")
3038         (minus:DF (float_extend:DF
3039                    (match_operand:SF 1 "reg_or_fp0_operand" "fG"))
3040                   (float_extend:DF
3041                    (match_operand:SF 2 "reg_or_fp0_operand" "fG"))))]
3042   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
3043   "sub%-%/ %R1,%R2,%0"
3044   [(set_attr "type" "fadd")
3045    (set_attr "trap" "yes")
3046    (set_attr "round_suffix" "normal")
3047    (set_attr "trap_suffix" "u_su_sui")])
3048
3049 (define_expand "subtf3"
3050   [(use (match_operand 0 "register_operand" ""))
3051    (use (match_operand 1 "general_operand" ""))
3052    (use (match_operand 2 "general_operand" ""))]
3053   "TARGET_HAS_XFLOATING_LIBS"
3054   "alpha_emit_xfloating_arith (MINUS, operands); DONE;")
3055
3056 (define_insn "*sqrtsf2_ieee"
3057   [(set (match_operand:SF 0 "register_operand" "=&f")
3058         (sqrt:SF (match_operand:SF 1 "reg_or_fp0_operand" "fG")))]
3059   "TARGET_FP && TARGET_FIX && alpha_fptm >= ALPHA_FPTM_SU"
3060   "sqrt%,%/ %R1,%0"
3061   [(set_attr "type" "fsqrt")
3062    (set_attr "opsize" "si")
3063    (set_attr "trap" "yes")
3064    (set_attr "round_suffix" "normal")
3065    (set_attr "trap_suffix" "u_su_sui")])
3066
3067 (define_insn "sqrtsf2"
3068   [(set (match_operand:SF 0 "register_operand" "=f")
3069         (sqrt:SF (match_operand:SF 1 "reg_or_fp0_operand" "fG")))]
3070   "TARGET_FP && TARGET_FIX"
3071   "sqrt%,%/ %R1,%0"
3072   [(set_attr "type" "fsqrt")
3073    (set_attr "opsize" "si")
3074    (set_attr "trap" "yes")
3075    (set_attr "round_suffix" "normal")
3076    (set_attr "trap_suffix" "u_su_sui")])
3077
3078 (define_insn "*sqrtdf2_ieee"
3079   [(set (match_operand:DF 0 "register_operand" "=&f")
3080         (sqrt:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG")))]
3081   "TARGET_FP && TARGET_FIX && alpha_fptm >= ALPHA_FPTM_SU"
3082   "sqrt%-%/ %R1,%0"
3083   [(set_attr "type" "fsqrt")
3084    (set_attr "trap" "yes")
3085    (set_attr "round_suffix" "normal")
3086    (set_attr "trap_suffix" "u_su_sui")])
3087
3088 (define_insn "sqrtdf2"
3089   [(set (match_operand:DF 0 "register_operand" "=f")
3090         (sqrt:DF (match_operand:DF 1 "reg_or_fp0_operand" "fG")))]
3091   "TARGET_FP && TARGET_FIX"
3092   "sqrt%-%/ %1,%0"
3093   [(set_attr "type" "fsqrt")
3094    (set_attr "trap" "yes")
3095    (set_attr "round_suffix" "normal")
3096    (set_attr "trap_suffix" "u_su_sui")])
3097 \f
3098 ;; Next are all the integer comparisons, and conditional moves and branches
3099 ;; and some of the related define_expand's and define_split's.
3100
3101 (define_insn "*setcc_internal"
3102   [(set (match_operand 0 "register_operand" "=r")
3103         (match_operator 1 "alpha_comparison_operator"
3104                            [(match_operand:DI 2 "register_operand" "r")
3105                             (match_operand:DI 3 "reg_or_8bit_operand" "rI")]))]
3106   "GET_MODE_CLASS (GET_MODE (operands[0])) == MODE_INT
3107    && GET_MODE_SIZE (GET_MODE (operands[0])) <= 8
3108    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
3109   "cmp%C1 %2,%3,%0"
3110   [(set_attr "type" "icmp")])
3111
3112 ;; Yes, we can technically support reg_or_8bit_operand in operand 2,
3113 ;; but that's non-canonical rtl and allowing that causes inefficiencies
3114 ;; from cse on.
3115 (define_insn "*setcc_swapped_internal"
3116   [(set (match_operand 0 "register_operand" "=r")
3117         (match_operator 1 "alpha_swapped_comparison_operator"
3118                            [(match_operand:DI 2 "register_operand" "r")
3119                             (match_operand:DI 3 "reg_or_0_operand" "rJ")]))]
3120   "GET_MODE_CLASS (GET_MODE (operands[0])) == MODE_INT
3121    && GET_MODE_SIZE (GET_MODE (operands[0])) <= 8
3122    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
3123   "cmp%c1 %r3,%2,%0"
3124   [(set_attr "type" "icmp")])
3125
3126 ;; Use match_operator rather than ne directly so that we can match
3127 ;; multiple integer modes.
3128 (define_insn "*setne_internal"
3129   [(set (match_operand 0 "register_operand" "=r")
3130         (match_operator 1 "signed_comparison_operator"
3131                           [(match_operand:DI 2 "register_operand" "r")
3132                            (const_int 0)]))]
3133   "GET_MODE_CLASS (GET_MODE (operands[0])) == MODE_INT
3134    && GET_MODE_SIZE (GET_MODE (operands[0])) <= 8
3135    && GET_CODE (operands[1]) == NE
3136    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
3137   "cmpult $31,%2,%0"
3138   [(set_attr "type" "icmp")])
3139
3140 ;; The mode folding trick can't be used with const_int operands, since
3141 ;; reload needs to know the proper mode.
3142 ;;
3143 ;; Use add_operand instead of the more seemingly natural reg_or_8bit_operand
3144 ;; in order to create more pairs of constants.  As long as we're allowing
3145 ;; two constants at the same time, and will have to reload one of them...
3146
3147 (define_insn "*movqicc_internal"
3148   [(set (match_operand:QI 0 "register_operand" "=r,r,r,r")
3149         (if_then_else:QI
3150          (match_operator 2 "signed_comparison_operator"
3151                          [(match_operand:DI 3 "reg_or_0_operand" "rJ,rJ,J,J")
3152                           (match_operand:DI 4 "reg_or_0_operand" "J,J,rJ,rJ")])
3153          (match_operand:QI 1 "add_operand" "rI,0,rI,0")
3154          (match_operand:QI 5 "add_operand" "0,rI,0,rI")))]
3155   "(operands[3] == const0_rtx || operands[4] == const0_rtx)"
3156   "@
3157    cmov%C2 %r3,%1,%0
3158    cmov%D2 %r3,%5,%0
3159    cmov%c2 %r4,%1,%0
3160    cmov%d2 %r4,%5,%0"
3161   [(set_attr "type" "icmov")])
3162
3163 (define_insn "*movhicc_internal"
3164   [(set (match_operand:HI 0 "register_operand" "=r,r,r,r")
3165         (if_then_else:HI
3166          (match_operator 2 "signed_comparison_operator"
3167                          [(match_operand:DI 3 "reg_or_0_operand" "rJ,rJ,J,J")
3168                           (match_operand:DI 4 "reg_or_0_operand" "J,J,rJ,rJ")])
3169          (match_operand:HI 1 "add_operand" "rI,0,rI,0")
3170          (match_operand:HI 5 "add_operand" "0,rI,0,rI")))]
3171   "(operands[3] == const0_rtx || operands[4] == const0_rtx)"
3172   "@
3173    cmov%C2 %r3,%1,%0
3174    cmov%D2 %r3,%5,%0
3175    cmov%c2 %r4,%1,%0
3176    cmov%d2 %r4,%5,%0"
3177   [(set_attr "type" "icmov")])
3178
3179 (define_insn "*movsicc_internal"
3180   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
3181         (if_then_else:SI
3182          (match_operator 2 "signed_comparison_operator"
3183                          [(match_operand:DI 3 "reg_or_0_operand" "rJ,rJ,J,J")
3184                           (match_operand:DI 4 "reg_or_0_operand" "J,J,rJ,rJ")])
3185          (match_operand:SI 1 "add_operand" "rI,0,rI,0")
3186          (match_operand:SI 5 "add_operand" "0,rI,0,rI")))]
3187   "(operands[3] == const0_rtx || operands[4] == const0_rtx)"
3188   "@
3189    cmov%C2 %r3,%1,%0
3190    cmov%D2 %r3,%5,%0
3191    cmov%c2 %r4,%1,%0
3192    cmov%d2 %r4,%5,%0"
3193   [(set_attr "type" "icmov")])
3194
3195 (define_insn "*movdicc_internal"
3196   [(set (match_operand:DI 0 "register_operand" "=r,r,r,r")
3197         (if_then_else:DI
3198          (match_operator 2 "signed_comparison_operator"
3199                          [(match_operand:DI 3 "reg_or_0_operand" "rJ,rJ,J,J")
3200                           (match_operand:DI 4 "reg_or_0_operand" "J,J,rJ,rJ")])
3201          (match_operand:DI 1 "add_operand" "rI,0,rI,0")
3202          (match_operand:DI 5 "add_operand" "0,rI,0,rI")))]
3203   "(operands[3] == const0_rtx || operands[4] == const0_rtx)"
3204   "@
3205    cmov%C2 %r3,%1,%0
3206    cmov%D2 %r3,%5,%0
3207    cmov%c2 %r4,%1,%0
3208    cmov%d2 %r4,%5,%0"
3209   [(set_attr "type" "icmov")])
3210
3211 (define_insn "*movqicc_lbc"
3212   [(set (match_operand:QI 0 "register_operand" "=r,r")
3213         (if_then_else:QI
3214          (eq (zero_extract:DI (match_operand:DI 2 "reg_or_0_operand" "rJ,rJ")
3215                               (const_int 1)
3216                               (const_int 0))
3217              (const_int 0))
3218          (match_operand:QI 1 "reg_or_8bit_operand" "rI,0")
3219          (match_operand:QI 3 "reg_or_8bit_operand" "0,rI")))]
3220   ""
3221   "@
3222    cmovlbc %r2,%1,%0
3223    cmovlbs %r2,%3,%0"
3224   [(set_attr "type" "icmov")])
3225
3226 (define_insn "*movhicc_lbc"
3227   [(set (match_operand:HI 0 "register_operand" "=r,r")
3228         (if_then_else:HI
3229          (eq (zero_extract:DI (match_operand:DI 2 "reg_or_0_operand" "rJ,rJ")
3230                               (const_int 1)
3231                               (const_int 0))
3232              (const_int 0))
3233          (match_operand:HI 1 "reg_or_8bit_operand" "rI,0")
3234          (match_operand:HI 3 "reg_or_8bit_operand" "0,rI")))]
3235   ""
3236   "@
3237    cmovlbc %r2,%1,%0
3238    cmovlbs %r2,%3,%0"
3239   [(set_attr "type" "icmov")])
3240
3241 (define_insn "*movsicc_lbc"
3242   [(set (match_operand:SI 0 "register_operand" "=r,r")
3243         (if_then_else:SI
3244          (eq (zero_extract:DI (match_operand:DI 2 "reg_or_0_operand" "rJ,rJ")
3245                               (const_int 1)
3246                               (const_int 0))
3247              (const_int 0))
3248          (match_operand:SI 1 "reg_or_8bit_operand" "rI,0")
3249          (match_operand:SI 3 "reg_or_8bit_operand" "0,rI")))]
3250   ""
3251   "@
3252    cmovlbc %r2,%1,%0
3253    cmovlbs %r2,%3,%0"
3254   [(set_attr "type" "icmov")])
3255
3256 (define_insn "*movdicc_lbc"
3257   [(set (match_operand:DI 0 "register_operand" "=r,r")
3258         (if_then_else:DI
3259          (eq (zero_extract:DI (match_operand:DI 2 "reg_or_0_operand" "rJ,rJ")
3260                               (const_int 1)
3261                               (const_int 0))
3262              (const_int 0))
3263          (match_operand:DI 1 "reg_or_8bit_operand" "rI,0")
3264          (match_operand:DI 3 "reg_or_8bit_operand" "0,rI")))]
3265   ""
3266   "@
3267    cmovlbc %r2,%1,%0
3268    cmovlbs %r2,%3,%0"
3269   [(set_attr "type" "icmov")])
3270
3271 (define_insn "*movqicc_lbs"
3272   [(set (match_operand:QI 0 "register_operand" "=r,r")
3273         (if_then_else:QI
3274          (ne (zero_extract:DI (match_operand:DI 2 "reg_or_0_operand" "rJ,rJ")
3275                               (const_int 1)
3276                               (const_int 0))
3277              (const_int 0))
3278          (match_operand:QI 1 "reg_or_8bit_operand" "rI,0")
3279          (match_operand:QI 3 "reg_or_8bit_operand" "0,rI")))]
3280   ""
3281   "@
3282    cmovlbs %r2,%1,%0
3283    cmovlbc %r2,%3,%0"
3284   [(set_attr "type" "icmov")])
3285
3286 (define_insn "*movhicc_lbs"
3287   [(set (match_operand:HI 0 "register_operand" "=r,r")
3288         (if_then_else:HI
3289          (ne (zero_extract:DI (match_operand:DI 2 "reg_or_0_operand" "rJ,rJ")
3290                               (const_int 1)
3291                               (const_int 0))
3292              (const_int 0))
3293          (match_operand:HI 1 "reg_or_8bit_operand" "rI,0")
3294          (match_operand:HI 3 "reg_or_8bit_operand" "0,rI")))]
3295   ""
3296   "@
3297    cmovlbs %r2,%1,%0
3298    cmovlbc %r2,%3,%0"
3299   [(set_attr "type" "icmov")])
3300
3301 (define_insn "*movsicc_lbs"
3302   [(set (match_operand:SI 0 "register_operand" "=r,r")
3303         (if_then_else:SI
3304          (ne (zero_extract:DI (match_operand:DI 2 "reg_or_0_operand" "rJ,rJ")
3305                               (const_int 1)
3306                               (const_int 0))
3307              (const_int 0))
3308          (match_operand:SI 1 "reg_or_8bit_operand" "rI,0")
3309          (match_operand:SI 3 "reg_or_8bit_operand" "0,rI")))]
3310   ""
3311   "@
3312    cmovlbs %r2,%1,%0
3313    cmovlbc %r2,%3,%0"
3314   [(set_attr "type" "icmov")])
3315
3316 (define_insn "*movdicc_lbs"
3317   [(set (match_operand:DI 0 "register_operand" "=r,r")
3318         (if_then_else:DI
3319          (ne (zero_extract:DI (match_operand:DI 2 "reg_or_0_operand" "rJ,rJ")
3320                               (const_int 1)
3321                               (const_int 0))
3322              (const_int 0))
3323          (match_operand:DI 1 "reg_or_8bit_operand" "rI,0")
3324          (match_operand:DI 3 "reg_or_8bit_operand" "0,rI")))]
3325   ""
3326   "@
3327    cmovlbs %r2,%1,%0
3328    cmovlbc %r2,%3,%0"
3329   [(set_attr "type" "icmov")])
3330
3331 ;; For ABS, we have two choices, depending on whether the input and output
3332 ;; registers are the same or not.
3333 (define_expand "absdi2"
3334   [(set (match_operand:DI 0 "register_operand" "")
3335         (abs:DI (match_operand:DI 1 "register_operand" "")))]
3336   ""
3337 {
3338   if (rtx_equal_p (operands[0], operands[1]))
3339     emit_insn (gen_absdi2_same (operands[0], gen_reg_rtx (DImode)));
3340   else
3341     emit_insn (gen_absdi2_diff (operands[0], operands[1]));
3342   DONE;
3343 })
3344
3345 (define_expand "absdi2_same"
3346   [(set (match_operand:DI 1 "register_operand" "")
3347         (neg:DI (match_operand:DI 0 "register_operand" "")))
3348    (set (match_dup 0)
3349         (if_then_else:DI (ge (match_dup 0) (const_int 0))
3350                          (match_dup 0)
3351                          (match_dup 1)))]
3352   ""
3353   "")
3354
3355 (define_expand "absdi2_diff"
3356   [(set (match_operand:DI 0 "register_operand" "")
3357         (neg:DI (match_operand:DI 1 "register_operand" "")))
3358    (set (match_dup 0)
3359         (if_then_else:DI (lt (match_dup 1) (const_int 0))
3360                          (match_dup 0)
3361                          (match_dup 1)))]
3362   ""
3363   "")
3364
3365 (define_split
3366   [(set (match_operand:DI 0 "register_operand" "")
3367         (abs:DI (match_dup 0)))
3368    (clobber (match_operand:DI 1 "register_operand" ""))]
3369   ""
3370   [(set (match_dup 1) (neg:DI (match_dup 0)))
3371    (set (match_dup 0) (if_then_else:DI (ge (match_dup 0) (const_int 0))
3372                                        (match_dup 0) (match_dup 1)))]
3373   "")
3374
3375 (define_split
3376   [(set (match_operand:DI 0 "register_operand" "")
3377         (abs:DI (match_operand:DI 1 "register_operand" "")))]
3378   "! rtx_equal_p (operands[0], operands[1])"
3379   [(set (match_dup 0) (neg:DI (match_dup 1)))
3380    (set (match_dup 0) (if_then_else:DI (lt (match_dup 1) (const_int 0))
3381                                        (match_dup 0) (match_dup 1)))]
3382   "")
3383
3384 (define_split
3385   [(set (match_operand:DI 0 "register_operand" "")
3386         (neg:DI (abs:DI (match_dup 0))))
3387    (clobber (match_operand:DI 1 "register_operand" ""))]
3388   ""
3389   [(set (match_dup 1) (neg:DI (match_dup 0)))
3390    (set (match_dup 0) (if_then_else:DI (le (match_dup 0) (const_int 0))
3391                                        (match_dup 0) (match_dup 1)))]
3392   "")
3393
3394 (define_split
3395   [(set (match_operand:DI 0 "register_operand" "")
3396         (neg:DI (abs:DI (match_operand:DI 1 "register_operand" ""))))]
3397   "! rtx_equal_p (operands[0], operands[1])"
3398   [(set (match_dup 0) (neg:DI (match_dup 1)))
3399    (set (match_dup 0) (if_then_else:DI (gt (match_dup 1) (const_int 0))
3400                                        (match_dup 0) (match_dup 1)))]
3401   "")
3402
3403 (define_insn "sminqi3"
3404   [(set (match_operand:QI 0 "register_operand" "=r")
3405         (smin:QI (match_operand:QI 1 "reg_or_0_operand" "%rJ")
3406                  (match_operand:QI 2 "reg_or_8bit_operand" "rI")))]
3407   "TARGET_MAX"
3408   "minsb8 %r1,%2,%0"
3409   [(set_attr "type" "mvi")])
3410
3411 (define_insn "uminqi3"
3412   [(set (match_operand:QI 0 "register_operand" "=r")
3413         (umin:QI (match_operand:QI 1 "reg_or_0_operand" "%rJ")
3414                  (match_operand:QI 2 "reg_or_8bit_operand" "rI")))]
3415   "TARGET_MAX"
3416   "minub8 %r1,%2,%0"
3417   [(set_attr "type" "mvi")])
3418
3419 (define_insn "smaxqi3"
3420   [(set (match_operand:QI 0 "register_operand" "=r")
3421         (smax:QI (match_operand:QI 1 "reg_or_0_operand" "%rJ")
3422                  (match_operand:QI 2 "reg_or_8bit_operand" "rI")))]
3423   "TARGET_MAX"
3424   "maxsb8 %r1,%2,%0"
3425   [(set_attr "type" "mvi")])
3426
3427 (define_insn "umaxqi3"
3428   [(set (match_operand:QI 0 "register_operand" "=r")
3429         (umax:QI (match_operand:QI 1 "reg_or_0_operand" "%rJ")
3430                  (match_operand:QI 2 "reg_or_8bit_operand" "rI")))]
3431   "TARGET_MAX"
3432   "maxub8 %r1,%2,%0"
3433   [(set_attr "type" "mvi")])
3434
3435 (define_insn "sminhi3"
3436   [(set (match_operand:HI 0 "register_operand" "=r")
3437         (smin:HI (match_operand:HI 1 "reg_or_0_operand" "%rJ")
3438                  (match_operand:HI 2 "reg_or_8bit_operand" "rI")))]
3439   "TARGET_MAX"
3440   "minsw4 %r1,%2,%0"
3441   [(set_attr "type" "mvi")])
3442
3443 (define_insn "uminhi3"
3444   [(set (match_operand:HI 0 "register_operand" "=r")
3445         (umin:HI (match_operand:HI 1 "reg_or_0_operand" "%rJ")
3446                  (match_operand:HI 2 "reg_or_8bit_operand" "rI")))]
3447   "TARGET_MAX"
3448   "minuw4 %r1,%2,%0"
3449   [(set_attr "type" "mvi")])
3450
3451 (define_insn "smaxhi3"
3452   [(set (match_operand:HI 0 "register_operand" "=r")
3453         (smax:HI (match_operand:HI 1 "reg_or_0_operand" "%rJ")
3454                  (match_operand:HI 2 "reg_or_8bit_operand" "rI")))]
3455   "TARGET_MAX"
3456   "maxsw4 %r1,%2,%0"
3457   [(set_attr "type" "mvi")])
3458
3459 (define_insn "umaxhi3"
3460   [(set (match_operand:HI 0 "register_operand" "=r")
3461         (umax:HI (match_operand:HI 1 "reg_or_0_operand" "%rJ")
3462                  (match_operand:HI 2 "reg_or_8bit_operand" "rI")))]
3463   "TARGET_MAX"
3464   "maxuw4 %r1,%2,%0"
3465   [(set_attr "type" "shift")])
3466
3467 (define_expand "smaxdi3"
3468   [(set (match_dup 3)
3469         (le:DI (match_operand:DI 1 "reg_or_0_operand" "")
3470                (match_operand:DI 2 "reg_or_8bit_operand" "")))
3471    (set (match_operand:DI 0 "register_operand" "")
3472         (if_then_else:DI (eq (match_dup 3) (const_int 0))
3473                          (match_dup 1) (match_dup 2)))]
3474   ""
3475   { operands[3] = gen_reg_rtx (DImode); })
3476
3477 (define_split
3478   [(set (match_operand:DI 0 "register_operand" "")
3479         (smax:DI (match_operand:DI 1 "reg_or_0_operand" "")
3480                  (match_operand:DI 2 "reg_or_8bit_operand" "")))
3481    (clobber (match_operand:DI 3 "register_operand" ""))]
3482   "operands[2] != const0_rtx"
3483   [(set (match_dup 3) (le:DI (match_dup 1) (match_dup 2)))
3484    (set (match_dup 0) (if_then_else:DI (eq (match_dup 3) (const_int 0))
3485                                        (match_dup 1) (match_dup 2)))]
3486   "")
3487
3488 (define_insn "*smax_const0"
3489   [(set (match_operand:DI 0 "register_operand" "=r")
3490         (smax:DI (match_operand:DI 1 "register_operand" "0")
3491                  (const_int 0)))]
3492   ""
3493   "cmovlt %0,0,%0"
3494   [(set_attr "type" "icmov")])
3495
3496 (define_expand "smindi3"
3497   [(set (match_dup 3)
3498         (lt:DI (match_operand:DI 1 "reg_or_0_operand" "")
3499                (match_operand:DI 2 "reg_or_8bit_operand" "")))
3500    (set (match_operand:DI 0 "register_operand" "")
3501         (if_then_else:DI (ne (match_dup 3) (const_int 0))
3502                          (match_dup 1) (match_dup 2)))]
3503   ""
3504   { operands[3] = gen_reg_rtx (DImode); })
3505
3506 (define_split
3507   [(set (match_operand:DI 0 "register_operand" "")
3508         (smin:DI (match_operand:DI 1 "reg_or_0_operand" "")
3509                  (match_operand:DI 2 "reg_or_8bit_operand" "")))
3510    (clobber (match_operand:DI 3 "register_operand" ""))]
3511   "operands[2] != const0_rtx"
3512   [(set (match_dup 3) (lt:DI (match_dup 1) (match_dup 2)))
3513    (set (match_dup 0) (if_then_else:DI (ne (match_dup 3) (const_int 0))
3514                                        (match_dup 1) (match_dup 2)))]
3515   "")
3516
3517 (define_insn "*smin_const0"
3518   [(set (match_operand:DI 0 "register_operand" "=r")
3519         (smin:DI (match_operand:DI 1 "register_operand" "0")
3520                  (const_int 0)))]
3521   ""
3522   "cmovgt %0,0,%0"
3523   [(set_attr "type" "icmov")])
3524
3525 (define_expand "umaxdi3"
3526   [(set (match_dup 3)
3527         (leu:DI (match_operand:DI 1 "reg_or_0_operand" "")
3528                 (match_operand:DI 2 "reg_or_8bit_operand" "")))
3529    (set (match_operand:DI 0 "register_operand" "")
3530         (if_then_else:DI (eq (match_dup 3) (const_int 0))
3531                          (match_dup 1) (match_dup 2)))]
3532   ""
3533   "operands[3] = gen_reg_rtx (DImode);")
3534
3535 (define_split
3536   [(set (match_operand:DI 0 "register_operand" "")
3537         (umax:DI (match_operand:DI 1 "reg_or_0_operand" "")
3538                  (match_operand:DI 2 "reg_or_8bit_operand" "")))
3539    (clobber (match_operand:DI 3 "register_operand" ""))]
3540   "operands[2] != const0_rtx"
3541   [(set (match_dup 3) (leu:DI (match_dup 1) (match_dup 2)))
3542    (set (match_dup 0) (if_then_else:DI (eq (match_dup 3) (const_int 0))
3543                                        (match_dup 1) (match_dup 2)))]
3544   "")
3545
3546 (define_expand "umindi3"
3547   [(set (match_dup 3)
3548         (ltu:DI (match_operand:DI 1 "reg_or_0_operand" "")
3549                 (match_operand:DI 2 "reg_or_8bit_operand" "")))
3550    (set (match_operand:DI 0 "register_operand" "")
3551         (if_then_else:DI (ne (match_dup 3) (const_int 0))
3552                          (match_dup 1) (match_dup 2)))]
3553   ""
3554   "operands[3] = gen_reg_rtx (DImode);")
3555
3556 (define_split
3557   [(set (match_operand:DI 0 "register_operand" "")
3558         (umin:DI (match_operand:DI 1 "reg_or_0_operand" "")
3559                  (match_operand:DI 2 "reg_or_8bit_operand" "")))
3560    (clobber (match_operand:DI 3 "register_operand" ""))]
3561   "operands[2] != const0_rtx"
3562   [(set (match_dup 3) (ltu:DI (match_dup 1) (match_dup 2)))
3563    (set (match_dup 0) (if_then_else:DI (ne (match_dup 3) (const_int 0))
3564                                        (match_dup 1) (match_dup 2)))]
3565   "")
3566
3567 (define_insn "*bcc_normal"
3568   [(set (pc)
3569         (if_then_else
3570          (match_operator 1 "signed_comparison_operator"
3571                          [(match_operand:DI 2 "reg_or_0_operand" "rJ")
3572                           (const_int 0)])
3573          (label_ref (match_operand 0 "" ""))
3574          (pc)))]
3575   ""
3576   "b%C1 %r2,%0"
3577   [(set_attr "type" "ibr")])
3578
3579 (define_insn "*bcc_reverse"
3580   [(set (pc)
3581         (if_then_else
3582          (match_operator 1 "signed_comparison_operator"
3583                          [(match_operand:DI 2 "register_operand" "r")
3584                           (const_int 0)])
3585
3586          (pc)
3587          (label_ref (match_operand 0 "" ""))))]
3588   ""
3589   "b%c1 %2,%0"
3590   [(set_attr "type" "ibr")])
3591
3592 (define_insn "*blbs_normal"
3593   [(set (pc)
3594         (if_then_else
3595          (ne (zero_extract:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
3596                               (const_int 1)
3597                               (const_int 0))
3598              (const_int 0))
3599          (label_ref (match_operand 0 "" ""))
3600          (pc)))]
3601   ""
3602   "blbs %r1,%0"
3603   [(set_attr "type" "ibr")])
3604
3605 (define_insn "*blbc_normal"
3606   [(set (pc)
3607         (if_then_else
3608          (eq (zero_extract:DI (match_operand:DI 1 "reg_or_0_operand" "rJ")
3609                               (const_int 1)
3610                               (const_int 0))
3611              (const_int 0))
3612          (label_ref (match_operand 0 "" ""))
3613          (pc)))]
3614   ""
3615   "blbc %r1,%0"
3616   [(set_attr "type" "ibr")])
3617
3618 (define_split
3619   [(parallel
3620     [(set (pc)
3621           (if_then_else
3622            (match_operator 1 "comparison_operator"
3623                            [(zero_extract:DI (match_operand:DI 2 "register_operand" "")
3624                                              (const_int 1)
3625                                              (match_operand:DI 3 "const_int_operand" ""))
3626                             (const_int 0)])
3627            (label_ref (match_operand 0 "" ""))
3628            (pc)))
3629      (clobber (match_operand:DI 4 "register_operand" ""))])]
3630   "INTVAL (operands[3]) != 0"
3631   [(set (match_dup 4)
3632         (lshiftrt:DI (match_dup 2) (match_dup 3)))
3633    (set (pc)
3634         (if_then_else (match_op_dup 1
3635                                     [(zero_extract:DI (match_dup 4)
3636                                                       (const_int 1)
3637                                                       (const_int 0))
3638                                      (const_int 0)])
3639                       (label_ref (match_dup 0))
3640                       (pc)))]
3641   "")
3642 \f
3643 ;; The following are the corresponding floating-point insns.  Recall
3644 ;; we need to have variants that expand the arguments from SFmode
3645 ;; to DFmode.
3646
3647 (define_insn "*cmpdf_ieee"
3648   [(set (match_operand:DF 0 "register_operand" "=&f")
3649         (match_operator:DF 1 "alpha_fp_comparison_operator"
3650                            [(match_operand:DF 2 "reg_or_fp0_operand" "fG")
3651                             (match_operand:DF 3 "reg_or_fp0_operand" "fG")]))]
3652   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
3653   "cmp%-%C1%/ %R2,%R3,%0"
3654   [(set_attr "type" "fadd")
3655    (set_attr "trap" "yes")
3656    (set_attr "trap_suffix" "su")])
3657
3658 (define_insn "*cmpdf_internal"
3659   [(set (match_operand:DF 0 "register_operand" "=f")
3660         (match_operator:DF 1 "alpha_fp_comparison_operator"
3661                            [(match_operand:DF 2 "reg_or_fp0_operand" "fG")
3662                             (match_operand:DF 3 "reg_or_fp0_operand" "fG")]))]
3663   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
3664   "cmp%-%C1%/ %R2,%R3,%0"
3665   [(set_attr "type" "fadd")
3666    (set_attr "trap" "yes")
3667    (set_attr "trap_suffix" "su")])
3668
3669 (define_insn "*cmpdf_ieee_ext1"
3670   [(set (match_operand:DF 0 "register_operand" "=&f")
3671         (match_operator:DF 1 "alpha_fp_comparison_operator"
3672                            [(float_extend:DF
3673                              (match_operand:SF 2 "reg_or_fp0_operand" "fG"))
3674                             (match_operand:DF 3 "reg_or_fp0_operand" "fG")]))]
3675   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
3676   "cmp%-%C1%/ %R2,%R3,%0"
3677   [(set_attr "type" "fadd")
3678    (set_attr "trap" "yes")
3679    (set_attr "trap_suffix" "su")])
3680
3681 (define_insn "*cmpdf_ext1"
3682   [(set (match_operand:DF 0 "register_operand" "=f")
3683         (match_operator:DF 1 "alpha_fp_comparison_operator"
3684                            [(float_extend:DF
3685                              (match_operand:SF 2 "reg_or_fp0_operand" "fG"))
3686                             (match_operand:DF 3 "reg_or_fp0_operand" "fG")]))]
3687   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
3688   "cmp%-%C1%/ %R2,%R3,%0"
3689   [(set_attr "type" "fadd")
3690    (set_attr "trap" "yes")
3691    (set_attr "trap_suffix" "su")])
3692
3693 (define_insn "*cmpdf_ieee_ext2"
3694   [(set (match_operand:DF 0 "register_operand" "=&f")
3695         (match_operator:DF 1 "alpha_fp_comparison_operator"
3696                            [(match_operand:DF 2 "reg_or_fp0_operand" "fG")
3697                             (float_extend:DF
3698                              (match_operand:SF 3 "reg_or_fp0_operand" "fG"))]))]
3699   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
3700   "cmp%-%C1%/ %R2,%R3,%0"
3701   [(set_attr "type" "fadd")
3702    (set_attr "trap" "yes")
3703    (set_attr "trap_suffix" "su")])
3704
3705 (define_insn "*cmpdf_ext2"
3706   [(set (match_operand:DF 0 "register_operand" "=f")
3707         (match_operator:DF 1 "alpha_fp_comparison_operator"
3708                            [(match_operand:DF 2 "reg_or_fp0_operand" "fG")
3709                             (float_extend:DF
3710                              (match_operand:SF 3 "reg_or_fp0_operand" "fG"))]))]
3711   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
3712   "cmp%-%C1%/ %R2,%R3,%0"
3713   [(set_attr "type" "fadd")
3714    (set_attr "trap" "yes")
3715    (set_attr "trap_suffix" "su")])
3716
3717 (define_insn "*cmpdf_ieee_ext3"
3718   [(set (match_operand:DF 0 "register_operand" "=&f")
3719         (match_operator:DF 1 "alpha_fp_comparison_operator"
3720                            [(float_extend:DF
3721                              (match_operand:SF 2 "reg_or_fp0_operand" "fG"))
3722                             (float_extend:DF
3723                              (match_operand:SF 3 "reg_or_fp0_operand" "fG"))]))]
3724   "TARGET_FP && alpha_fptm >= ALPHA_FPTM_SU"
3725   "cmp%-%C1%/ %R2,%R3,%0"
3726   [(set_attr "type" "fadd")
3727    (set_attr "trap" "yes")
3728    (set_attr "trap_suffix" "su")])
3729
3730 (define_insn "*cmpdf_ext3"
3731   [(set (match_operand:DF 0 "register_operand" "=f")
3732         (match_operator:DF 1 "alpha_fp_comparison_operator"
3733                            [(float_extend:DF
3734                              (match_operand:SF 2 "reg_or_fp0_operand" "fG"))
3735                             (float_extend:DF
3736                              (match_operand:SF 3 "reg_or_fp0_operand" "fG"))]))]
3737   "TARGET_FP && alpha_fptm < ALPHA_FPTM_SU"
3738   "cmp%-%C1%/ %R2,%R3,%0"
3739   [(set_attr "type" "fadd")
3740    (set_attr "trap" "yes")
3741    (set_attr "trap_suffix" "su")])
3742
3743 (define_insn "*movdfcc_internal"
3744   [(set (match_operand:DF 0 "register_operand" "=f,f")
3745         (if_then_else:DF
3746          (match_operator 3 "signed_comparison_operator"
3747                          [(match_operand:DF 4 "reg_or_fp0_operand" "fG,fG")
3748                           (match_operand:DF 2 "fp0_operand" "G,G")])
3749          (match_operand:DF 1 "reg_or_fp0_operand" "fG,0")
3750          (match_operand:DF 5 "reg_or_fp0_operand" "0,fG")))]
3751   "TARGET_FP"
3752   "@
3753    fcmov%C3 %R4,%R1,%0
3754    fcmov%D3 %R4,%R5,%0"
3755   [(set_attr "type" "fcmov")])
3756
3757 (define_insn "*movsfcc_internal"
3758   [(set (match_operand:SF 0 "register_operand" "=f,f")
3759         (if_then_else:SF
3760          (match_operator 3 "signed_comparison_operator"
3761                          [(match_operand:DF 4 "reg_or_fp0_operand" "fG,fG")
3762                           (match_operand:DF 2 "fp0_operand" "G,G")])
3763          (match_operand:SF 1 "reg_or_fp0_operand" "fG,0")
3764          (match_operand:SF 5 "reg_or_fp0_operand" "0,fG")))]
3765   "TARGET_FP"
3766   "@
3767    fcmov%C3 %R4,%R1,%0
3768    fcmov%D3 %R4,%R5,%0"
3769   [(set_attr "type" "fcmov")])
3770
3771 (define_insn "*movdfcc_ext1"
3772   [(set (match_operand:DF 0 "register_operand" "=f,f")
3773         (if_then_else:DF
3774          (match_operator 3 "signed_comparison_operator"
3775                          [(match_operand:DF 4 "reg_or_fp0_operand" "fG,fG")
3776                           (match_operand:DF 2 "fp0_operand" "G,G")])
3777          (float_extend:DF (match_operand:SF 1 "reg_or_fp0_operand" "fG,0"))
3778          (match_operand:DF 5 "reg_or_fp0_operand" "0,fG")))]
3779   "TARGET_FP"
3780   "@
3781    fcmov%C3 %R4,%R1,%0
3782    fcmov%D3 %R4,%R5,%0"
3783   [(set_attr "type" "fcmov")])
3784
3785 (define_insn "*movdfcc_ext2"
3786   [(set (match_operand:DF 0 "register_operand" "=f,f")
3787         (if_then_else:DF
3788          (match_operator 3 "signed_comparison_operator"
3789                          [(float_extend:DF
3790                            (match_operand:SF 4 "reg_or_fp0_operand" "fG,fG"))
3791                           (match_operand:DF 2 "fp0_operand" "G,G")])
3792          (match_operand:DF 1 "reg_or_fp0_operand" "fG,0")
3793          (match_operand:DF 5 "reg_or_fp0_operand" "0,fG")))]
3794   "TARGET_FP"
3795   "@
3796    fcmov%C3 %R4,%R1,%0
3797    fcmov%D3 %R4,%R5,%0"
3798   [(set_attr "type" "fcmov")])
3799
3800 (define_insn "*movdfcc_ext3"
3801   [(set (match_operand:SF 0 "register_operand" "=f,f")
3802         (if_then_else:SF
3803          (match_operator 3 "signed_comparison_operator"
3804                          [(float_extend:DF
3805                            (match_operand:SF 4 "reg_or_fp0_operand" "fG,fG"))
3806                           (match_operand:DF 2 "fp0_operand" "G,G")])
3807          (match_operand:SF 1 "reg_or_fp0_operand" "fG,0")
3808          (match_operand:SF 5 "reg_or_fp0_operand" "0,fG")))]
3809   "TARGET_FP"
3810   "@
3811    fcmov%C3 %R4,%R1,%0
3812    fcmov%D3 %R4,%R5,%0"
3813   [(set_attr "type" "fcmov")])
3814
3815 (define_insn "*movdfcc_ext4"
3816   [(set (match_operand:DF 0 "register_operand" "=f,f")
3817         (if_then_else:DF
3818          (match_operator 3 "signed_comparison_operator"
3819                          [(float_extend:DF
3820                            (match_operand:SF 4 "reg_or_fp0_operand" "fG,fG"))
3821                           (match_operand:DF 2 "fp0_operand" "G,G")])
3822          (float_extend:DF (match_operand:SF 1 "reg_or_fp0_operand" "fG,0"))
3823          (match_operand:DF 5 "reg_or_fp0_operand" "0,fG")))]
3824   "TARGET_FP"
3825   "@
3826    fcmov%C3 %R4,%R1,%0
3827    fcmov%D3 %R4,%R5,%0"
3828   [(set_attr "type" "fcmov")])
3829
3830 (define_expand "maxdf3"
3831   [(set (match_dup 3)
3832         (le:DF (match_operand:DF 1 "reg_or_fp0_operand" "")
3833                (match_operand:DF 2 "reg_or_fp0_operand" "")))
3834    (set (match_operand:DF 0 "register_operand" "")
3835         (if_then_else:DF (eq (match_dup 3) (match_dup 4))
3836                          (match_dup 1) (match_dup 2)))]
3837   "TARGET_FP"
3838 {
3839   operands[3] = gen_reg_rtx (DFmode);
3840   operands[4] = CONST0_RTX (DFmode);
3841 })
3842
3843 (define_expand "mindf3"
3844   [(set (match_dup 3)
3845         (lt:DF (match_operand:DF 1 "reg_or_fp0_operand" "")
3846                (match_operand:DF 2 "reg_or_fp0_operand" "")))
3847    (set (match_operand:DF 0 "register_operand" "")
3848         (if_then_else:DF (ne (match_dup 3) (match_dup 4))
3849                          (match_dup 1) (match_dup 2)))]
3850   "TARGET_FP"
3851 {
3852   operands[3] = gen_reg_rtx (DFmode);
3853   operands[4] = CONST0_RTX (DFmode);
3854 })
3855
3856 (define_expand "maxsf3"
3857   [(set (match_dup 3)
3858         (le:DF (float_extend:DF (match_operand:SF 1 "reg_or_fp0_operand" ""))
3859                (float_extend:DF (match_operand:SF 2 "reg_or_fp0_operand" ""))))
3860    (set (match_operand:SF 0 "register_operand" "")
3861         (if_then_else:SF (eq (match_dup 3) (match_dup 4))
3862                          (match_dup 1) (match_dup 2)))]
3863   "TARGET_FP"
3864 {
3865   operands[3] = gen_reg_rtx (DFmode);
3866   operands[4] = CONST0_RTX (DFmode);
3867 })
3868
3869 (define_expand "minsf3"
3870   [(set (match_dup 3)
3871         (lt:DF (float_extend:DF (match_operand:SF 1 "reg_or_fp0_operand" ""))
3872                (float_extend:DF (match_operand:SF 2 "reg_or_fp0_operand" ""))))
3873    (set (match_operand:SF 0 "register_operand" "")
3874         (if_then_else:SF (ne (match_dup 3) (match_dup 4))
3875                       (match_dup 1) (match_dup 2)))]
3876   "TARGET_FP"
3877 {
3878   operands[3] = gen_reg_rtx (DFmode);
3879   operands[4] = CONST0_RTX (DFmode);
3880 })
3881
3882 (define_insn "*fbcc_normal"
3883   [(set (pc)
3884         (if_then_else
3885          (match_operator 1 "signed_comparison_operator"
3886                          [(match_operand:DF 2 "reg_or_fp0_operand" "fG")
3887                           (match_operand:DF 3 "fp0_operand" "G")])
3888          (label_ref (match_operand 0 "" ""))
3889          (pc)))]
3890   "TARGET_FP"
3891   "fb%C1 %R2,%0"
3892   [(set_attr "type" "fbr")])
3893
3894 (define_insn "*fbcc_ext_normal"
3895   [(set (pc)
3896         (if_then_else
3897          (match_operator 1 "signed_comparison_operator"
3898                          [(float_extend:DF
3899                            (match_operand:SF 2 "reg_or_fp0_operand" "fG"))
3900                           (match_operand:DF 3 "fp0_operand" "G")])
3901          (label_ref (match_operand 0 "" ""))
3902          (pc)))]
3903   "TARGET_FP"
3904   "fb%C1 %R2,%0"
3905   [(set_attr "type" "fbr")])
3906 \f
3907 ;; These are the main define_expand's used to make conditional branches
3908 ;; and compares.
3909
3910 (define_expand "cmpdf"
3911   [(set (cc0) (compare (match_operand:DF 0 "reg_or_fp0_operand" "")
3912                        (match_operand:DF 1 "reg_or_fp0_operand" "")))]
3913   "TARGET_FP"
3914 {
3915   alpha_compare.op0 = operands[0];
3916   alpha_compare.op1 = operands[1];
3917   alpha_compare.fp_p = 1;
3918   DONE;
3919 })
3920
3921 (define_expand "cmptf"
3922   [(set (cc0) (compare (match_operand:TF 0 "general_operand" "")
3923                        (match_operand:TF 1 "general_operand" "")))]
3924   "TARGET_HAS_XFLOATING_LIBS"
3925 {
3926   alpha_compare.op0 = operands[0];
3927   alpha_compare.op1 = operands[1];
3928   alpha_compare.fp_p = 1;
3929   DONE;
3930 })
3931
3932 (define_expand "cmpdi"
3933   [(set (cc0) (compare (match_operand:DI 0 "general_operand" "")
3934                        (match_operand:DI 1 "general_operand" "")))]
3935   ""
3936 {
3937   alpha_compare.op0 = operands[0];
3938   alpha_compare.op1 = operands[1];
3939   alpha_compare.fp_p = 0;
3940   DONE;
3941 })
3942
3943 (define_expand "beq"
3944   [(set (pc)
3945         (if_then_else (match_dup 1)
3946                       (label_ref (match_operand 0 "" ""))
3947                       (pc)))]
3948   ""
3949   "{ operands[1] = alpha_emit_conditional_branch (EQ); }")
3950
3951 (define_expand "bne"
3952   [(set (pc)
3953         (if_then_else (match_dup 1)
3954                       (label_ref (match_operand 0 "" ""))
3955                       (pc)))]
3956   ""
3957   "{ operands[1] = alpha_emit_conditional_branch (NE); }")
3958
3959 (define_expand "blt"
3960   [(set (pc)
3961         (if_then_else (match_dup 1)
3962                       (label_ref (match_operand 0 "" ""))
3963                       (pc)))]
3964   ""
3965   "{ operands[1] = alpha_emit_conditional_branch (LT); }")
3966
3967 (define_expand "ble"
3968   [(set (pc)
3969         (if_then_else (match_dup 1)
3970                       (label_ref (match_operand 0 "" ""))
3971                       (pc)))]
3972   ""
3973   "{ operands[1] = alpha_emit_conditional_branch (LE); }")
3974
3975 (define_expand "bgt"
3976   [(set (pc)
3977         (if_then_else (match_dup 1)
3978                       (label_ref (match_operand 0 "" ""))
3979                       (pc)))]
3980   ""
3981   "{ operands[1] = alpha_emit_conditional_branch (GT); }")
3982
3983 (define_expand "bge"
3984   [(set (pc)
3985         (if_then_else (match_dup 1)
3986                       (label_ref (match_operand 0 "" ""))
3987                       (pc)))]
3988   ""
3989   "{ operands[1] = alpha_emit_conditional_branch (GE); }")
3990
3991 (define_expand "bltu"
3992   [(set (pc)
3993         (if_then_else (match_dup 1)
3994                       (label_ref (match_operand 0 "" ""))
3995                       (pc)))]
3996   ""
3997   "{ operands[1] = alpha_emit_conditional_branch (LTU); }")
3998
3999 (define_expand "bleu"
4000   [(set (pc)
4001         (if_then_else (match_dup 1)
4002                       (label_ref (match_operand 0 "" ""))
4003                       (pc)))]
4004   ""
4005   "{ operands[1] = alpha_emit_conditional_branch (LEU); }")
4006
4007 (define_expand "bgtu"
4008   [(set (pc)
4009         (if_then_else (match_dup 1)
4010                       (label_ref (match_operand 0 "" ""))
4011                       (pc)))]
4012   ""
4013   "{ operands[1] = alpha_emit_conditional_branch (GTU); }")
4014
4015 (define_expand "bgeu"
4016   [(set (pc)
4017         (if_then_else (match_dup 1)
4018                       (label_ref (match_operand 0 "" ""))
4019                       (pc)))]
4020   ""
4021   "{ operands[1] = alpha_emit_conditional_branch (GEU); }")
4022
4023 (define_expand "bunordered"
4024   [(set (pc)
4025         (if_then_else (match_dup 1)
4026                       (label_ref (match_operand 0 "" ""))
4027                       (pc)))]
4028   ""
4029   "{ operands[1] = alpha_emit_conditional_branch (UNORDERED); }")
4030
4031 (define_expand "bordered"
4032   [(set (pc)
4033         (if_then_else (match_dup 1)
4034                       (label_ref (match_operand 0 "" ""))
4035                       (pc)))]
4036   ""
4037   "{ operands[1] = alpha_emit_conditional_branch (ORDERED); }")
4038
4039 (define_expand "seq"
4040   [(set (match_operand:DI 0 "register_operand" "")
4041         (match_dup 1))]
4042   ""
4043   "{ if ((operands[1] = alpha_emit_setcc (EQ)) == NULL_RTX) FAIL; }")
4044
4045 (define_expand "sne"
4046   [(set (match_operand:DI 0 "register_operand" "")
4047         (match_dup 1))]
4048   ""
4049   "{ if ((operands[1] = alpha_emit_setcc (NE)) == NULL_RTX) FAIL; }")
4050
4051 (define_expand "slt"
4052   [(set (match_operand:DI 0 "register_operand" "")
4053         (match_dup 1))]
4054   ""
4055   "{ if ((operands[1] = alpha_emit_setcc (LT)) == NULL_RTX) FAIL; }")
4056
4057 (define_expand "sle"
4058   [(set (match_operand:DI 0 "register_operand" "")
4059         (match_dup 1))]
4060   ""
4061   "{ if ((operands[1] = alpha_emit_setcc (LE)) == NULL_RTX) FAIL; }")
4062
4063 (define_expand "sgt"
4064   [(set (match_operand:DI 0 "register_operand" "")
4065         (match_dup 1))]
4066   ""
4067   "{ if ((operands[1] = alpha_emit_setcc (GT)) == NULL_RTX) FAIL; }")
4068
4069 (define_expand "sge"
4070   [(set (match_operand:DI 0 "register_operand" "")
4071         (match_dup 1))]
4072   ""
4073   "{ if ((operands[1] = alpha_emit_setcc (GE)) == NULL_RTX) FAIL; }")
4074
4075 (define_expand "sltu"
4076   [(set (match_operand:DI 0 "register_operand" "")
4077         (match_dup 1))]
4078   ""
4079   "{ if ((operands[1] = alpha_emit_setcc (LTU)) == NULL_RTX) FAIL; }")
4080
4081 (define_expand "sleu"
4082   [(set (match_operand:DI 0 "register_operand" "")
4083         (match_dup 1))]
4084   ""
4085   "{ if ((operands[1] = alpha_emit_setcc (LEU)) == NULL_RTX) FAIL; }")
4086
4087 (define_expand "sgtu"
4088   [(set (match_operand:DI 0 "register_operand" "")
4089         (match_dup 1))]
4090   ""
4091   "{ if ((operands[1] = alpha_emit_setcc (GTU)) == NULL_RTX) FAIL; }")
4092
4093 (define_expand "sgeu"
4094   [(set (match_operand:DI 0 "register_operand" "")
4095         (match_dup 1))]
4096   ""
4097   "{ if ((operands[1] = alpha_emit_setcc (GEU)) == NULL_RTX) FAIL; }")
4098
4099 (define_expand "sunordered"
4100   [(set (match_operand:DI 0 "register_operand" "")
4101         (match_dup 1))]
4102   ""
4103   "{ if ((operands[1] = alpha_emit_setcc (UNORDERED)) == NULL_RTX) FAIL; }")
4104
4105 (define_expand "sordered"
4106   [(set (match_operand:DI 0 "register_operand" "")
4107         (match_dup 1))]
4108   ""
4109   "{ if ((operands[1] = alpha_emit_setcc (ORDERED)) == NULL_RTX) FAIL; }")
4110 \f
4111 ;; These are the main define_expand's used to make conditional moves.
4112
4113 (define_expand "movsicc"
4114   [(set (match_operand:SI 0 "register_operand" "")
4115         (if_then_else:SI (match_operand 1 "comparison_operator" "")
4116                          (match_operand:SI 2 "reg_or_8bit_operand" "")
4117                          (match_operand:SI 3 "reg_or_8bit_operand" "")))]
4118   ""
4119 {
4120   if ((operands[1] = alpha_emit_conditional_move (operands[1], SImode)) == 0)
4121     FAIL;
4122 })
4123
4124 (define_expand "movdicc"
4125   [(set (match_operand:DI 0 "register_operand" "")
4126         (if_then_else:DI (match_operand 1 "comparison_operator" "")
4127                          (match_operand:DI 2 "reg_or_8bit_operand" "")
4128                          (match_operand:DI 3 "reg_or_8bit_operand" "")))]
4129   ""
4130 {
4131   if ((operands[1] = alpha_emit_conditional_move (operands[1], DImode)) == 0)
4132     FAIL;
4133 })
4134
4135 (define_expand "movsfcc"
4136   [(set (match_operand:SF 0 "register_operand" "")
4137         (if_then_else:SF (match_operand 1 "comparison_operator" "")
4138                          (match_operand:SF 2 "reg_or_8bit_operand" "")
4139                          (match_operand:SF 3 "reg_or_8bit_operand" "")))]
4140   ""
4141 {
4142   if ((operands[1] = alpha_emit_conditional_move (operands[1], SFmode)) == 0)
4143     FAIL;
4144 })
4145
4146 (define_expand "movdfcc"
4147   [(set (match_operand:DF 0 "register_operand" "")
4148         (if_then_else:DF (match_operand 1 "comparison_operator" "")
4149                          (match_operand:DF 2 "reg_or_8bit_operand" "")
4150                          (match_operand:DF 3 "reg_or_8bit_operand" "")))]
4151   ""
4152 {
4153   if ((operands[1] = alpha_emit_conditional_move (operands[1], DFmode)) == 0)
4154     FAIL;
4155 })
4156 \f
4157 ;; These define_split definitions are used in cases when comparisons have
4158 ;; not be stated in the correct way and we need to reverse the second
4159 ;; comparison.  For example, x >= 7 has to be done as x < 6 with the
4160 ;; comparison that tests the result being reversed.  We have one define_split
4161 ;; for each use of a comparison.  They do not match valid insns and need
4162 ;; not generate valid insns.
4163 ;;
4164 ;; We can also handle equality comparisons (and inequality comparisons in
4165 ;; cases where the resulting add cannot overflow) by doing an add followed by
4166 ;; a comparison with zero.  This is faster since the addition takes one
4167 ;; less cycle than a compare when feeding into a conditional move.
4168 ;; For this case, we also have an SImode pattern since we can merge the add
4169 ;; and sign extend and the order doesn't matter.
4170 ;;
4171 ;; We do not do this for floating-point, since it isn't clear how the "wrong"
4172 ;; operation could have been generated.
4173
4174 (define_split
4175   [(set (match_operand:DI 0 "register_operand" "")
4176         (if_then_else:DI
4177          (match_operator 1 "comparison_operator"
4178                          [(match_operand:DI 2 "reg_or_0_operand" "")
4179                           (match_operand:DI 3 "reg_or_cint_operand" "")])
4180          (match_operand:DI 4 "reg_or_cint_operand" "")
4181          (match_operand:DI 5 "reg_or_cint_operand" "")))
4182    (clobber (match_operand:DI 6 "register_operand" ""))]
4183   "operands[3] != const0_rtx"
4184   [(set (match_dup 6) (match_dup 7))
4185    (set (match_dup 0)
4186         (if_then_else:DI (match_dup 8) (match_dup 4) (match_dup 5)))]
4187 {
4188   enum rtx_code code = GET_CODE (operands[1]);
4189   int unsignedp = (code == GEU || code == LEU || code == GTU || code == LTU);
4190
4191   /* If we are comparing for equality with a constant and that constant
4192      appears in the arm when the register equals the constant, use the
4193      register since that is more likely to match (and to produce better code
4194      if both would).  */
4195
4196   if (code == EQ && GET_CODE (operands[3]) == CONST_INT
4197       && rtx_equal_p (operands[4], operands[3]))
4198     operands[4] = operands[2];
4199
4200   else if (code == NE && GET_CODE (operands[3]) == CONST_INT
4201            && rtx_equal_p (operands[5], operands[3]))
4202     operands[5] = operands[2];
4203
4204   if (code == NE || code == EQ
4205       || (extended_count (operands[2], DImode, unsignedp) >= 1
4206           && extended_count (operands[3], DImode, unsignedp) >= 1))
4207     {
4208       if (GET_CODE (operands[3]) == CONST_INT)
4209         operands[7] = gen_rtx_PLUS (DImode, operands[2],
4210                                     GEN_INT (- INTVAL (operands[3])));
4211       else
4212         operands[7] = gen_rtx_MINUS (DImode, operands[2], operands[3]);
4213
4214       operands[8] = gen_rtx_fmt_ee (code, VOIDmode, operands[6], const0_rtx);
4215     }
4216
4217   else if (code == EQ || code == LE || code == LT
4218            || code == LEU || code == LTU)
4219     {
4220       operands[7] = gen_rtx_fmt_ee (code, DImode, operands[2], operands[3]);
4221       operands[8] = gen_rtx_NE (VOIDmode, operands[6], const0_rtx);
4222     }
4223   else
4224     {
4225       operands[7] = gen_rtx_fmt_ee (reverse_condition (code), DImode,
4226                                     operands[2], operands[3]);
4227       operands[8] = gen_rtx_EQ (VOIDmode, operands[6], const0_rtx);
4228     }
4229 })
4230
4231 (define_split
4232   [(set (match_operand:DI 0 "register_operand" "")
4233         (if_then_else:DI
4234          (match_operator 1 "comparison_operator"
4235                          [(match_operand:SI 2 "reg_or_0_operand" "")
4236                           (match_operand:SI 3 "reg_or_cint_operand" "")])
4237          (match_operand:DI 4 "reg_or_8bit_operand" "")
4238          (match_operand:DI 5 "reg_or_8bit_operand" "")))
4239    (clobber (match_operand:DI 6 "register_operand" ""))]
4240   "operands[3] != const0_rtx
4241    && (GET_CODE (operands[1]) == EQ || GET_CODE (operands[1]) == NE)"
4242   [(set (match_dup 6) (match_dup 7))
4243    (set (match_dup 0)
4244         (if_then_else:DI (match_dup 8) (match_dup 4) (match_dup 5)))]
4245 {
4246   enum rtx_code code = GET_CODE (operands[1]);
4247   int unsignedp = (code == GEU || code == LEU || code == GTU || code == LTU);
4248   rtx tem;
4249
4250   if ((code != NE && code != EQ
4251        && ! (extended_count (operands[2], DImode, unsignedp) >= 1
4252              && extended_count (operands[3], DImode, unsignedp) >= 1)))
4253     FAIL;
4254
4255   if (GET_CODE (operands[3]) == CONST_INT)
4256     tem = gen_rtx_PLUS (SImode, operands[2],
4257                         GEN_INT (- INTVAL (operands[3])));
4258   else
4259     tem = gen_rtx_MINUS (SImode, operands[2], operands[3]);
4260
4261   operands[7] = gen_rtx_SIGN_EXTEND (DImode, tem);
4262   operands[8] = gen_rtx_fmt_ee (GET_CODE (operands[1]), VOIDmode,
4263                                 operands[6], const0_rtx);
4264 })
4265
4266 (define_split
4267   [(set (pc)
4268         (if_then_else
4269          (match_operator 1 "comparison_operator"
4270                          [(match_operand:DI 2 "reg_or_0_operand" "")
4271                           (match_operand:DI 3 "reg_or_cint_operand" "")])
4272          (label_ref (match_operand 0 "" ""))
4273          (pc)))
4274    (clobber (match_operand:DI 4 "register_operand" ""))]
4275   "operands[3] != const0_rtx"
4276   [(set (match_dup 4) (match_dup 5))
4277    (set (pc) (if_then_else (match_dup 6) (label_ref (match_dup 0)) (pc)))]
4278 {
4279   enum rtx_code code = GET_CODE (operands[1]);
4280   int unsignedp = (code == GEU || code == LEU || code == GTU || code == LTU);
4281
4282   if (code == NE || code == EQ
4283       || (extended_count (operands[2], DImode, unsignedp) >= 1
4284           && extended_count (operands[3], DImode, unsignedp) >= 1))
4285     {
4286       if (GET_CODE (operands[3]) == CONST_INT)
4287         operands[5] = gen_rtx_PLUS (DImode, operands[2],
4288                                     GEN_INT (- INTVAL (operands[3])));
4289       else
4290         operands[5] = gen_rtx_MINUS (DImode, operands[2], operands[3]);
4291
4292       operands[6] = gen_rtx_fmt_ee (code, VOIDmode, operands[4], const0_rtx);
4293     }
4294
4295   else if (code == EQ || code == LE || code == LT
4296            || code == LEU || code == LTU)
4297     {
4298       operands[5] = gen_rtx_fmt_ee (code, DImode, operands[2], operands[3]);
4299       operands[6] = gen_rtx_NE (VOIDmode, operands[4], const0_rtx);
4300     }
4301   else
4302     {
4303       operands[5] = gen_rtx_fmt_ee (reverse_condition (code), DImode,
4304                                     operands[2], operands[3]);
4305       operands[6] = gen_rtx_EQ (VOIDmode, operands[4], const0_rtx);
4306     }
4307 })
4308
4309 (define_split
4310   [(set (pc)
4311         (if_then_else
4312          (match_operator 1 "comparison_operator"
4313                          [(match_operand:SI 2 "reg_or_0_operand" "")
4314                           (match_operand:SI 3 "const_int_operand" "")])
4315          (label_ref (match_operand 0 "" ""))
4316          (pc)))
4317    (clobber (match_operand:DI 4 "register_operand" ""))]
4318   "operands[3] != const0_rtx
4319    && (GET_CODE (operands[1]) == EQ || GET_CODE (operands[1]) == NE)"
4320   [(set (match_dup 4) (match_dup 5))
4321    (set (pc) (if_then_else (match_dup 6) (label_ref (match_dup 0)) (pc)))]
4322 {
4323   rtx tem;
4324
4325   if (GET_CODE (operands[3]) == CONST_INT)
4326     tem = gen_rtx_PLUS (SImode, operands[2],
4327                         GEN_INT (- INTVAL (operands[3])));
4328   else
4329     tem = gen_rtx_MINUS (SImode, operands[2], operands[3]);
4330
4331   operands[5] = gen_rtx_SIGN_EXTEND (DImode, tem);
4332   operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[1]), VOIDmode,
4333                                 operands[4], const0_rtx);
4334 })
4335
4336 ;; We can convert such things as "a > 0xffff" to "t = a & ~ 0xffff; t != 0".
4337 ;; This eliminates one, and sometimes two, insns when the AND can be done
4338 ;; with a ZAP.
4339 (define_split
4340   [(set (match_operand:DI 0 "register_operand" "")
4341         (match_operator:DI 1 "comparison_operator"
4342                         [(match_operand:DI 2 "register_operand" "")
4343                          (match_operand:DI 3 "const_int_operand" "")]))
4344    (clobber (match_operand:DI 4 "register_operand" ""))]
4345   "exact_log2 (INTVAL (operands[3]) + 1) >= 0
4346    && (GET_CODE (operands[1]) == GTU
4347        || GET_CODE (operands[1]) == LEU
4348        || ((GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == LE)
4349            && extended_count (operands[2], DImode, 1) > 0))"
4350   [(set (match_dup 4) (and:DI (match_dup 2) (match_dup 5)))
4351    (set (match_dup 0) (match_dup 6))]
4352 {
4353   operands[5] = GEN_INT (~ INTVAL (operands[3]));
4354   operands[6] = gen_rtx_fmt_ee (((GET_CODE (operands[1]) == GTU
4355                                   || GET_CODE (operands[1]) == GT)
4356                                  ? NE : EQ),
4357                                 DImode, operands[4], const0_rtx);
4358 })
4359
4360 ;; Prefer to use cmp and arithmetic when possible instead of a cmove.
4361
4362 (define_split
4363   [(set (match_operand 0 "register_operand" "")
4364         (if_then_else (match_operator 1 "signed_comparison_operator"
4365                            [(match_operand:DI 2 "reg_or_0_operand" "")
4366                             (const_int 0)])
4367           (match_operand 3 "const_int_operand" "")
4368           (match_operand 4 "const_int_operand" "")))]
4369   ""
4370   [(const_int 0)]
4371 {
4372   if (alpha_split_conditional_move (GET_CODE (operands[1]), operands[0],
4373                                     operands[2], operands[3], operands[4]))
4374     DONE;
4375   else
4376     FAIL;
4377 })
4378
4379 ;; ??? Why combine is allowed to create such non-canonical rtl, I don't know.
4380 ;; Oh well, we match it in movcc, so it must be partially our fault.
4381 (define_split
4382   [(set (match_operand 0 "register_operand" "")
4383         (if_then_else (match_operator 1 "signed_comparison_operator"
4384                            [(const_int 0)
4385                             (match_operand:DI 2 "reg_or_0_operand" "")])
4386           (match_operand 3 "const_int_operand" "")
4387           (match_operand 4 "const_int_operand" "")))]
4388   ""
4389   [(const_int 0)]
4390 {
4391   if (alpha_split_conditional_move (swap_condition (GET_CODE (operands[1])),
4392                                     operands[0], operands[2], operands[3],
4393                                     operands[4]))
4394     DONE;
4395   else
4396     FAIL;
4397 })
4398
4399 (define_insn_and_split "*cmp_sadd_di"
4400   [(set (match_operand:DI 0 "register_operand" "=r")
4401         (plus:DI (if_then_else:DI
4402                    (match_operator 1 "alpha_zero_comparison_operator"
4403                      [(match_operand:DI 2 "reg_or_0_operand" "rJ")
4404                       (const_int 0)])
4405                    (match_operand:DI 3 "const48_operand" "I")
4406                    (const_int 0))
4407                  (match_operand:DI 4 "sext_add_operand" "rIO")))
4408    (clobber (match_scratch:DI 5 "=r"))]
4409   ""
4410   "#"
4411   "! no_new_pseudos || reload_completed"
4412   [(set (match_dup 5)
4413         (match_op_dup:DI 1 [(match_dup 2) (const_int 0)]))
4414    (set (match_dup 0)
4415         (plus:DI (mult:DI (match_dup 5) (match_dup 3))
4416                  (match_dup 4)))]
4417 {
4418   if (! no_new_pseudos)
4419     operands[5] = gen_reg_rtx (DImode);
4420   else if (reg_overlap_mentioned_p (operands[5], operands[4]))
4421     operands[5] = operands[0];
4422 })
4423
4424 (define_insn_and_split "*cmp_sadd_si"
4425   [(set (match_operand:SI 0 "register_operand" "=r")
4426         (plus:SI (if_then_else:SI
4427                    (match_operator 1 "alpha_zero_comparison_operator"
4428                      [(match_operand:DI 2 "reg_or_0_operand" "rJ")
4429                       (const_int 0)])
4430                    (match_operand:SI 3 "const48_operand" "I")
4431                    (const_int 0))
4432                  (match_operand:SI 4 "sext_add_operand" "rIO")))
4433    (clobber (match_scratch:SI 5 "=r"))]
4434   ""
4435   "#"
4436   "! no_new_pseudos || reload_completed"
4437   [(set (match_dup 5)
4438         (match_op_dup:SI 1 [(match_dup 2) (const_int 0)]))
4439    (set (match_dup 0)
4440         (plus:SI (mult:SI (match_dup 5) (match_dup 3))
4441                  (match_dup 4)))]
4442 {
4443   if (! no_new_pseudos)
4444     operands[5] = gen_reg_rtx (DImode);
4445   else if (reg_overlap_mentioned_p (operands[5], operands[4]))
4446     operands[5] = operands[0];
4447 })
4448
4449 (define_insn_and_split "*cmp_sadd_sidi"
4450   [(set (match_operand:DI 0 "register_operand" "=r")
4451         (sign_extend:DI
4452           (plus:SI (if_then_else:SI
4453                      (match_operator 1 "alpha_zero_comparison_operator"
4454                        [(match_operand:DI 2 "reg_or_0_operand" "rJ")
4455                         (const_int 0)])
4456                      (match_operand:SI 3 "const48_operand" "I")
4457                      (const_int 0))
4458                    (match_operand:SI 4 "sext_add_operand" "rIO"))))
4459    (clobber (match_scratch:SI 5 "=r"))]
4460   ""
4461   "#"
4462   "! no_new_pseudos || reload_completed"
4463   [(set (match_dup 5)
4464         (match_op_dup:SI 1 [(match_dup 2) (const_int 0)]))
4465    (set (match_dup 0)
4466         (sign_extend:DI (plus:SI (mult:SI (match_dup 5) (match_dup 3))
4467                                  (match_dup 4))))]
4468 {
4469   if (! no_new_pseudos)
4470     operands[5] = gen_reg_rtx (DImode);
4471   else if (reg_overlap_mentioned_p (operands[5], operands[4]))
4472     operands[5] = operands[0];
4473 })
4474
4475 (define_insn_and_split "*cmp_ssub_di"
4476   [(set (match_operand:DI 0 "register_operand" "=r")
4477         (minus:DI (if_then_else:DI
4478                     (match_operator 1 "alpha_zero_comparison_operator"
4479                       [(match_operand:DI 2 "reg_or_0_operand" "rJ")
4480                        (const_int 0)])
4481                     (match_operand:DI 3 "const48_operand" "I")
4482                     (const_int 0))
4483                   (match_operand:DI 4 "reg_or_8bit_operand" "rI")))
4484    (clobber (match_scratch:DI 5 "=r"))]
4485   ""
4486   "#"
4487   "! no_new_pseudos || reload_completed"
4488   [(set (match_dup 5)
4489         (match_op_dup:DI 1 [(match_dup 2) (const_int 0)]))
4490    (set (match_dup 0)
4491         (minus:DI (mult:DI (match_dup 5) (match_dup 3))
4492                   (match_dup 4)))]
4493 {
4494   if (! no_new_pseudos)
4495     operands[5] = gen_reg_rtx (DImode);
4496   else if (reg_overlap_mentioned_p (operands[5], operands[4]))
4497     operands[5] = operands[0];
4498 })
4499
4500 (define_insn_and_split "*cmp_ssub_si"
4501   [(set (match_operand:SI 0 "register_operand" "=r")
4502         (minus:SI (if_then_else:SI
4503                     (match_operator 1 "alpha_zero_comparison_operator"
4504                       [(match_operand:DI 2 "reg_or_0_operand" "rJ")
4505                        (const_int 0)])
4506                     (match_operand:SI 3 "const48_operand" "I")
4507                     (const_int 0))
4508                   (match_operand:SI 4 "reg_or_8bit_operand" "rI")))
4509    (clobber (match_scratch:SI 5 "=r"))]
4510   ""
4511   "#"
4512   "! no_new_pseudos || reload_completed"
4513   [(set (match_dup 5)
4514         (match_op_dup:SI 1 [(match_dup 2) (const_int 0)]))
4515    (set (match_dup 0)
4516         (minus:SI (mult:SI (match_dup 5) (match_dup 3))
4517                  (match_dup 4)))]
4518 {
4519   if (! no_new_pseudos)
4520     operands[5] = gen_reg_rtx (DImode);
4521   else if (reg_overlap_mentioned_p (operands[5], operands[4]))
4522     operands[5] = operands[0];
4523 })
4524
4525 (define_insn_and_split "*cmp_ssub_sidi"
4526   [(set (match_operand:DI 0 "register_operand" "=r")
4527         (sign_extend:DI
4528           (minus:SI (if_then_else:SI
4529                       (match_operator 1 "alpha_zero_comparison_operator"
4530                         [(match_operand:DI 2 "reg_or_0_operand" "rJ")
4531                          (const_int 0)])
4532                       (match_operand:SI 3 "const48_operand" "I")
4533                       (const_int 0))
4534                     (match_operand:SI 4 "reg_or_8bit_operand" "rI"))))
4535    (clobber (match_scratch:SI 5 "=r"))]
4536   ""
4537   "#"
4538   "! no_new_pseudos || reload_completed"
4539   [(set (match_dup 5)
4540         (match_op_dup:SI 1 [(match_dup 2) (const_int 0)]))
4541    (set (match_dup 0)
4542         (sign_extend:DI (minus:SI (mult:SI (match_dup 5) (match_dup 3))
4543                                   (match_dup 4))))]
4544 {
4545   if (! no_new_pseudos)
4546     operands[5] = gen_reg_rtx (DImode);
4547   else if (reg_overlap_mentioned_p (operands[5], operands[4]))
4548     operands[5] = operands[0];
4549 })
4550 \f
4551 ;; Here are the CALL and unconditional branch insns.  Calls on NT and OSF
4552 ;; work differently, so we have different patterns for each.
4553
4554 ;; On Unicos/Mk a call information word (CIW) must be generated for each
4555 ;; call. The CIW contains information about arguments passed in registers
4556 ;; and is stored in the caller's SSIB. Its offset relative to the beginning
4557 ;; of the SSIB is passed in $25. Handling this properly is quite complicated
4558 ;; in the presence of inlining since the CIWs for calls performed by the
4559 ;; inlined function must be stored in the SSIB of the function it is inlined
4560 ;; into as well. We encode the CIW in an unspec and append it to the list
4561 ;; of the CIWs for the current function only when the instruction for loading
4562 ;; $25 is generated.
4563
4564 (define_expand "call"
4565   [(use (match_operand:DI 0 "" ""))
4566    (use (match_operand 1 "" ""))
4567    (use (match_operand 2 "" ""))
4568    (use (match_operand 3 "" ""))]
4569   ""
4570 {
4571   if (TARGET_ABI_WINDOWS_NT)
4572     emit_call_insn (gen_call_nt (operands[0], operands[1]));
4573   else if (TARGET_ABI_OPEN_VMS)
4574     emit_call_insn (gen_call_vms (operands[0], operands[2]));
4575   else if (TARGET_ABI_UNICOSMK)
4576     emit_call_insn (gen_call_umk (operands[0], operands[2]));
4577   else
4578     emit_call_insn (gen_call_osf (operands[0], operands[1]));
4579   DONE;
4580 })
4581
4582 (define_expand "sibcall"
4583   [(parallel [(call (mem:DI (match_operand 0 "" ""))
4584                             (match_operand 1 "" ""))
4585               (use (reg:DI 29))])]
4586   "TARGET_ABI_OSF"
4587 {
4588   if (GET_CODE (operands[0]) != MEM)
4589     abort ();
4590   operands[0] = XEXP (operands[0], 0);
4591 })
4592
4593 (define_expand "call_osf"
4594   [(parallel [(call (mem:DI (match_operand 0 "" ""))
4595                     (match_operand 1 "" ""))
4596               (use (reg:DI 29))
4597               (clobber (reg:DI 26))])]
4598   ""
4599 {
4600   if (GET_CODE (operands[0]) != MEM)
4601     abort ();
4602
4603   operands[0] = XEXP (operands[0], 0);
4604   if (! call_operand (operands[0], Pmode))
4605     {
4606       rtx pv = gen_rtx_REG (Pmode, 27);
4607       emit_move_insn (pv, operands[0]);
4608       operands[0] = pv;
4609     }
4610 })
4611
4612 (define_expand "call_nt"
4613   [(parallel [(call (mem:DI (match_operand 0 "" ""))
4614                     (match_operand 1 "" ""))
4615               (clobber (reg:DI 26))])]
4616   ""
4617 {
4618   if (GET_CODE (operands[0]) != MEM)
4619     abort ();
4620
4621   operands[0] = XEXP (operands[0], 0);
4622   if (GET_CODE (operands[0]) != SYMBOL_REF && GET_CODE (operands[0]) != REG)
4623     operands[0] = force_reg (DImode, operands[0]);
4624 })
4625
4626 ;; Calls on Unicos/Mk are always indirect.
4627 ;; op 0: symbol ref for called function
4628 ;; op 1: CIW for $25 represented by an unspec
4629
4630 (define_expand "call_umk"
4631    [(parallel [(call (mem:DI (match_operand 0 "" ""))
4632                      (match_operand 1 "" ""))
4633                (use (reg:DI 25))
4634                (clobber (reg:DI 26))])]
4635    ""
4636 {
4637   if (GET_CODE (operands[0]) != MEM)
4638     abort ();
4639
4640   /* Always load the address of the called function into a register;
4641      load the CIW in $25.  */
4642
4643   operands[0] = XEXP (operands[0], 0);
4644   if (GET_CODE (operands[0]) != REG)
4645     operands[0] = force_reg (DImode, operands[0]);
4646
4647   emit_move_insn (gen_rtx_REG (DImode, 25), operands[1]);
4648 })
4649
4650 ;;
4651 ;; call openvms/alpha
4652 ;; op 0: symbol ref for called function
4653 ;; op 1: next_arg_reg (argument information value for R25)
4654 ;;
4655 (define_expand "call_vms"
4656   [(parallel [(call (mem:DI (match_operand 0 "" ""))
4657                     (match_operand 1 "" ""))
4658               (use (match_dup 2))
4659               (use (reg:DI 25))
4660               (use (reg:DI 26))
4661               (clobber (reg:DI 27))])]
4662   ""
4663 {
4664   if (GET_CODE (operands[0]) != MEM)
4665     abort ();
4666
4667   operands[0] = XEXP (operands[0], 0);
4668
4669   /* Always load AI with argument information, then handle symbolic and
4670      indirect call differently.  Load RA and set operands[2] to PV in
4671      both cases.  */
4672
4673   emit_move_insn (gen_rtx_REG (DImode, 25), operands[1]);
4674   if (GET_CODE (operands[0]) == SYMBOL_REF)
4675     {
4676       rtx linkage = alpha_need_linkage (XSTR (operands[0], 0), 0);
4677
4678       emit_move_insn (gen_rtx_REG (Pmode, 26), gen_rtx_MEM (Pmode, linkage));
4679       operands[2]
4680         = validize_mem (gen_rtx_MEM (Pmode, plus_constant (linkage, 8)));
4681     }
4682   else
4683     {
4684       emit_move_insn (gen_rtx_REG (Pmode, 26),
4685                       gen_rtx_MEM (Pmode, plus_constant (operands[0], 8)));
4686       operands[2] = operands[0];
4687     }
4688
4689 })
4690
4691 (define_expand "call_value"
4692   [(use (match_operand 0 "" ""))
4693    (use (match_operand:DI 1 "" ""))
4694    (use (match_operand 2 "" ""))
4695    (use (match_operand 3 "" ""))
4696    (use (match_operand 4 "" ""))]
4697   ""
4698 {
4699   if (TARGET_ABI_WINDOWS_NT)
4700     emit_call_insn (gen_call_value_nt (operands[0], operands[1], operands[2]));
4701   else if (TARGET_ABI_OPEN_VMS)
4702     emit_call_insn (gen_call_value_vms (operands[0], operands[1],
4703                                         operands[3]));
4704   else if (TARGET_ABI_UNICOSMK)
4705     emit_call_insn (gen_call_value_umk (operands[0], operands[1],
4706                                         operands[3]));
4707   else
4708     emit_call_insn (gen_call_value_osf (operands[0], operands[1],
4709                                         operands[2]));
4710   DONE;
4711 })
4712
4713 (define_expand "sibcall_value"
4714   [(parallel [(set (match_operand 0 "" "")
4715                    (call (mem:DI (match_operand 1 "" ""))
4716                          (match_operand 2 "" "")))
4717               (use (reg:DI 29))])]
4718   "TARGET_ABI_OSF"
4719 {
4720   if (GET_CODE (operands[1]) != MEM)
4721     abort ();
4722   operands[1] = XEXP (operands[1], 0);
4723 })
4724
4725 (define_expand "call_value_osf"
4726   [(parallel [(set (match_operand 0 "" "")
4727                    (call (mem:DI (match_operand 1 "" ""))
4728                          (match_operand 2 "" "")))
4729               (use (reg:DI 29))
4730               (clobber (reg:DI 26))])]
4731   ""
4732 {
4733   if (GET_CODE (operands[1]) != MEM)
4734     abort ();
4735
4736   operands[1] = XEXP (operands[1], 0);
4737   if (! call_operand (operands[1], Pmode))
4738     {
4739       rtx pv = gen_rtx_REG (Pmode, 27);
4740       emit_move_insn (pv, operands[1]);
4741       operands[1] = pv;
4742     }
4743 })
4744
4745 (define_expand "call_value_nt"
4746   [(parallel [(set (match_operand 0 "" "")
4747                    (call (mem:DI (match_operand 1 "" ""))
4748                          (match_operand 2 "" "")))
4749               (clobber (reg:DI 26))])]
4750   ""
4751 {
4752   if (GET_CODE (operands[1]) != MEM)
4753     abort ();
4754
4755   operands[1] = XEXP (operands[1], 0);
4756   if (GET_CODE (operands[1]) != SYMBOL_REF && GET_CODE (operands[1]) != REG)
4757     operands[1] = force_reg (DImode, operands[1]);
4758 })
4759
4760 (define_expand "call_value_vms"
4761   [(parallel [(set (match_operand 0 "" "")
4762                    (call (mem:DI (match_operand:DI 1 "" ""))
4763                          (match_operand 2 "" "")))
4764               (use (match_dup 3))
4765               (use (reg:DI 25))
4766               (use (reg:DI 26))
4767               (clobber (reg:DI 27))])]
4768   ""
4769 {
4770   if (GET_CODE (operands[1]) != MEM)
4771     abort ();
4772
4773   operands[1] = XEXP (operands[1], 0);
4774
4775   /* Always load AI with argument information, then handle symbolic and
4776      indirect call differently.  Load RA and set operands[3] to PV in
4777      both cases.  */
4778
4779   emit_move_insn (gen_rtx_REG (DImode, 25), operands[2]);
4780   if (GET_CODE (operands[1]) == SYMBOL_REF)
4781     {
4782       rtx linkage = alpha_need_linkage (XSTR (operands[1], 0), 0);
4783
4784       emit_move_insn (gen_rtx_REG (Pmode, 26), gen_rtx_MEM (Pmode, linkage));
4785       operands[3]
4786         = validize_mem (gen_rtx_MEM (Pmode, plus_constant (linkage, 8)));
4787     }
4788   else
4789     {
4790       emit_move_insn (gen_rtx_REG (Pmode, 26),
4791                       gen_rtx_MEM (Pmode, plus_constant (operands[1], 8)));
4792       operands[3] = operands[1];
4793     }
4794 })
4795
4796 (define_expand "call_value_umk"
4797   [(parallel [(set (match_operand 0 "" "")
4798                    (call (mem:DI (match_operand 1 "" ""))
4799                          (match_operand 2 "" "")))
4800               (use (reg:DI 25))
4801               (clobber (reg:DI 26))])]
4802   ""
4803 {
4804   if (GET_CODE (operands[1]) != MEM)
4805     abort ();
4806
4807   operands[1] = XEXP (operands[1], 0);
4808   if (GET_CODE (operands[1]) != REG)
4809     operands[1] = force_reg (DImode, operands[1]);
4810
4811   emit_move_insn (gen_rtx_REG (DImode, 25), operands[2]);
4812 })
4813
4814 (define_insn "*call_osf_1_er"
4815   [(call (mem:DI (match_operand:DI 0 "call_operand" "c,R,s"))
4816          (match_operand 1 "" ""))
4817    (use (reg:DI 29))
4818    (clobber (reg:DI 26))]
4819   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
4820   "@
4821    jsr $26,(%0),0\;ldah $29,0($26)\t\t!gpdisp!%*\;lda $29,0($29)\t\t!gpdisp!%*
4822    bsr $26,$%0..ng
4823    ldq $27,%0($29)\t\t!literal!%#\;jsr $26,($27),%0\t\t!lituse_jsr!%#\;ldah $29,0($26)\t\t!gpdisp!%*\;lda $29,0($29)\t\t!gpdisp!%*"
4824   [(set_attr "type" "jsr")
4825    (set_attr "length" "12,*,16")])
4826
4827 ;; We must use peep2 instead of a split because we need accurate life
4828 ;; information for $gp.  Consider the case of { bar(); while (1); }.
4829 (define_peephole2
4830   [(parallel [(call (mem:DI (match_operand:DI 0 "call_operand" ""))
4831                     (match_operand 1 "" ""))
4832               (use (reg:DI 29))
4833               (clobber (reg:DI 26))])]
4834   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF && reload_completed
4835    && ! current_file_function_operand (operands[0], Pmode)
4836    && peep2_regno_dead_p (1, 29)"
4837   [(parallel [(call (mem:DI (match_dup 2))
4838                     (match_dup 1))
4839               (set (reg:DI 26) (plus:DI (pc) (const_int 4)))
4840               (unspec_volatile [(reg:DI 29)] UNSPECV_BLOCKAGE)
4841               (use (match_dup 0))])]
4842 {
4843   if (CONSTANT_P (operands[0]))
4844     {
4845       operands[2] = gen_rtx_REG (Pmode, 27);
4846       emit_move_insn (operands[2], operands[0]);
4847     }
4848   else
4849     {
4850       operands[2] = operands[0];
4851       operands[0] = const0_rtx;
4852     }
4853 })
4854
4855 (define_peephole2
4856   [(parallel [(call (mem:DI (match_operand:DI 0 "call_operand" ""))
4857                     (match_operand 1 "" ""))
4858               (use (reg:DI 29))
4859               (clobber (reg:DI 26))])]
4860   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF && reload_completed
4861    && ! current_file_function_operand (operands[0], Pmode)
4862    && ! peep2_regno_dead_p (1, 29)"
4863   [(parallel [(call (mem:DI (match_dup 2))
4864                     (match_dup 1))
4865               (set (reg:DI 26) (plus:DI (pc) (const_int 4)))
4866               (unspec_volatile [(reg:DI 29)] UNSPECV_BLOCKAGE)
4867               (use (match_dup 0))])
4868    (set (reg:DI 29)
4869         (unspec_volatile:DI [(reg:DI 26) (match_dup 3)] UNSPECV_LDGP1))
4870    (set (reg:DI 29)
4871         (unspec:DI [(reg:DI 29) (match_dup 3)] UNSPEC_LDGP2))]
4872 {
4873   if (CONSTANT_P (operands[0]))
4874     {
4875       operands[2] = gen_rtx_REG (Pmode, 27);
4876       emit_move_insn (operands[2], operands[0]);
4877     }
4878   else
4879     {
4880       operands[2] = operands[0];
4881       operands[0] = const0_rtx;
4882     }
4883   operands[3] = GEN_INT (alpha_next_sequence_number++);
4884 })
4885
4886 ;; We add a blockage unspec_volatile to prevent insns from moving down
4887 ;; from above the call to in between the call and the ldah gpdisp.
4888
4889 (define_insn "*call_osf_2_er"
4890   [(call (mem:DI (match_operand:DI 0 "register_operand" "c"))
4891          (match_operand 1 "" ""))
4892    (set (reg:DI 26) (plus:DI (pc) (const_int 4)))
4893    (unspec_volatile [(reg:DI 29)] UNSPECV_BLOCKAGE)
4894    (use (match_operand 2 "" ""))]
4895   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
4896   "jsr $26,(%0),%2"
4897   [(set_attr "type" "jsr")])
4898
4899 (define_insn "*call_osf_1_noreturn"
4900   [(call (mem:DI (match_operand:DI 0 "call_operand" "c,R,s"))
4901          (match_operand 1 "" ""))
4902    (use (reg:DI 29))
4903    (clobber (reg:DI 26))]
4904   "! TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF
4905    && find_reg_note (insn, REG_NORETURN, NULL_RTX)"
4906   "@
4907    jsr $26,($27),0
4908    bsr $26,$%0..ng
4909    jsr $26,%0"
4910   [(set_attr "type" "jsr")
4911    (set_attr "length" "*,*,8")])
4912
4913 (define_insn "*call_osf_1"
4914   [(call (mem:DI (match_operand:DI 0 "call_operand" "c,R,s"))
4915          (match_operand 1 "" ""))
4916    (use (reg:DI 29))
4917    (clobber (reg:DI 26))]
4918   "! TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
4919   "@
4920    jsr $26,($27),0\;ldgp $29,0($26)
4921    bsr $26,$%0..ng
4922    jsr $26,%0\;ldgp $29,0($26)"
4923   [(set_attr "type" "jsr")
4924    (set_attr "length" "12,*,16")])
4925
4926 ;; Note that the DEC assembler expands "jmp foo" with $at, which
4927 ;; doesn't do what we want.
4928 (define_insn "*sibcall_osf_1_er"
4929   [(call (mem:DI (match_operand:DI 0 "symbolic_operand" "R,s"))
4930          (match_operand 1 "" ""))
4931    (use (reg:DI 29))]
4932   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
4933   "@
4934    br $31,$%0..ng
4935    ldq $27,%0($29)\t\t!literal!%#\;jmp $31,($27),%0\t\t!lituse_jsr!%#"
4936   [(set_attr "type" "jsr")
4937    (set_attr "length" "*,8")])
4938
4939 (define_insn "*sibcall_osf_1"
4940   [(call (mem:DI (match_operand:DI 0 "symbolic_operand" "R,s"))
4941          (match_operand 1 "" ""))
4942    (use (reg:DI 29))]
4943   "! TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
4944   "@
4945    br $31,$%0..ng
4946    lda $27,%0\;jmp $31,($27),%0"
4947   [(set_attr "type" "jsr")
4948    (set_attr "length" "*,8")])
4949
4950 (define_insn "*call_nt_1"
4951   [(call (mem:DI (match_operand:DI 0 "call_operand" "r,R,s"))
4952          (match_operand 1 "" ""))
4953    (clobber (reg:DI 26))]
4954   "TARGET_ABI_WINDOWS_NT"
4955   "@
4956    jsr $26,(%0)
4957    bsr $26,%0
4958    jsr $26,%0"
4959   [(set_attr "type" "jsr")
4960    (set_attr "length" "*,*,12")])
4961
4962 (define_insn "*call_vms_1"
4963   [(call (mem:DI (match_operand:DI 0 "call_operand" "r,s"))
4964          (match_operand 1 "" ""))
4965    (use (match_operand:DI 2 "nonimmediate_operand" "r,m"))
4966    (use (reg:DI 25))
4967    (use (reg:DI 26))
4968    (clobber (reg:DI 27))]
4969   "TARGET_ABI_OPEN_VMS"
4970   "@
4971    mov %2,$27\;jsr $26,0\;ldq $27,0($29)
4972    ldq $27,%2\;jsr $26,%0\;ldq $27,0($29)"
4973   [(set_attr "type" "jsr")
4974    (set_attr "length" "12,16")])
4975
4976 (define_insn "*call_umk_1"
4977   [(call (mem:DI (match_operand:DI 0 "call_operand" "r"))
4978          (match_operand 1 "" ""))
4979    (use (reg:DI 25))
4980    (clobber (reg:DI 26))]
4981   "TARGET_ABI_UNICOSMK"
4982   "jsr $26,(%0)"
4983   [(set_attr "type" "jsr")])
4984
4985 ;; Call subroutine returning any type.
4986
4987 (define_expand "untyped_call"
4988   [(parallel [(call (match_operand 0 "" "")
4989                     (const_int 0))
4990               (match_operand 1 "" "")
4991               (match_operand 2 "" "")])]
4992   ""
4993 {
4994   int i;
4995
4996   emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
4997
4998   for (i = 0; i < XVECLEN (operands[2], 0); i++)
4999     {
5000       rtx set = XVECEXP (operands[2], 0, i);
5001       emit_move_insn (SET_DEST (set), SET_SRC (set));
5002     }
5003
5004   /* The optimizer does not know that the call sets the function value
5005      registers we stored in the result block.  We avoid problems by
5006      claiming that all hard registers are used and clobbered at this
5007      point.  */
5008   emit_insn (gen_blockage ());
5009
5010   DONE;
5011 })
5012
5013 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
5014 ;; all of memory.  This blocks insns from being moved across this point.
5015
5016 (define_insn "blockage"
5017   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)]
5018   ""
5019   ""
5020   [(set_attr "length" "0")])
5021
5022 (define_insn "jump"
5023   [(set (pc)
5024         (label_ref (match_operand 0 "" "")))]
5025   ""
5026   "br $31,%l0"
5027   [(set_attr "type" "ibr")])
5028
5029 (define_expand "return"
5030   [(return)]
5031   "direct_return ()"
5032   "")
5033
5034 (define_insn "*return_internal"
5035   [(return)]
5036   "reload_completed"
5037   "ret $31,($26),1"
5038   [(set_attr "type" "ibr")])
5039
5040 (define_insn "indirect_jump"
5041   [(set (pc) (match_operand:DI 0 "register_operand" "r"))]
5042   ""
5043   "jmp $31,(%0),0"
5044   [(set_attr "type" "ibr")])
5045
5046 (define_expand "tablejump"
5047   [(parallel [(set (pc)
5048                    (match_operand 0 "register_operand" ""))
5049               (use (label_ref:DI (match_operand 1 "" "")))])]
5050   ""
5051 {
5052   if (TARGET_ABI_WINDOWS_NT)
5053     {
5054       rtx dest = gen_reg_rtx (DImode);
5055       emit_insn (gen_extendsidi2 (dest, operands[0]));
5056       operands[0] = dest;
5057     }
5058   else if (TARGET_ABI_OSF)
5059     {
5060       rtx dest = gen_reg_rtx (DImode);
5061       emit_insn (gen_extendsidi2 (dest, operands[0]));
5062       emit_insn (gen_adddi3 (dest, pic_offset_table_rtx, dest));        
5063       operands[0] = dest;
5064     }
5065 })
5066
5067 (define_insn "*tablejump_osf_nt_internal"
5068   [(set (pc)
5069         (match_operand:DI 0 "register_operand" "r"))
5070    (use (label_ref:DI (match_operand 1 "" "")))]
5071   "(TARGET_ABI_OSF || TARGET_ABI_WINDOWS_NT)
5072    && alpha_tablejump_addr_vec (insn)"
5073 {
5074   operands[2] = alpha_tablejump_best_label (insn);
5075   return "jmp $31,(%0),%2";
5076 }
5077   [(set_attr "type" "ibr")])
5078
5079 (define_insn "*tablejump_internal"
5080   [(set (pc)
5081         (match_operand:DI 0 "register_operand" "r"))
5082    (use (label_ref (match_operand 1 "" "")))]
5083   ""
5084   "jmp $31,(%0),0"
5085   [(set_attr "type" "ibr")])
5086
5087 ;; Cache flush.  Used by INITIALIZE_TRAMPOLINE.  0x86 is PAL_imb, but we don't
5088 ;; want to have to include pal.h in our .s file.
5089 ;;
5090 ;; Technically the type for call_pal is jsr, but we use that for determining
5091 ;; if we need a GP.  Use ibr instead since it has the same EV5 scheduling
5092 ;; characteristics.
5093 (define_insn "imb"
5094   [(unspec_volatile [(const_int 0)] UNSPECV_IMB)]
5095   ""
5096   "call_pal 0x86"
5097   [(set_attr "type" "ibr")])
5098 \f
5099 ;; Finally, we have the basic data motion insns.  The byte and word insns
5100 ;; are done via define_expand.  Start with the floating-point insns, since
5101 ;; they are simpler.
5102
5103 (define_insn "*movsf_nofix"
5104   [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,*r,*r,m,m")
5105         (match_operand:SF 1 "input_operand" "fG,m,*rG,m,fG,*r"))]
5106   "TARGET_FPREGS && ! TARGET_FIX
5107    && (register_operand (operands[0], SFmode)
5108        || reg_or_fp0_operand (operands[1], SFmode))"
5109   "@
5110    cpys %R1,%R1,%0
5111    ld%, %0,%1
5112    bis $31,%r1,%0
5113    ldl %0,%1
5114    st%, %R1,%0
5115    stl %r1,%0"
5116   [(set_attr "type" "fcpys,fld,ilog,ild,fst,ist")])
5117
5118 (define_insn "*movsf_fix"
5119   [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,*r,*r,m,m,f,*r")
5120         (match_operand:SF 1 "input_operand" "fG,m,*rG,m,fG,*r,*r,f"))]
5121   "TARGET_FPREGS && TARGET_FIX
5122    && (register_operand (operands[0], SFmode)
5123        || reg_or_fp0_operand (operands[1], SFmode))"
5124   "@
5125    cpys %R1,%R1,%0
5126    ld%, %0,%1
5127    bis $31,%r1,%0
5128    ldl %0,%1
5129    st%, %R1,%0
5130    stl %r1,%0
5131    itofs %1,%0
5132    ftois %1,%0"
5133   [(set_attr "type" "fcpys,fld,ilog,ild,fst,ist,itof,ftoi")])
5134
5135 (define_insn "*movsf_nofp"
5136   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,r,m")
5137         (match_operand:SF 1 "input_operand" "rG,m,r"))]
5138   "! TARGET_FPREGS
5139    && (register_operand (operands[0], SFmode)
5140        || reg_or_fp0_operand (operands[1], SFmode))"
5141   "@
5142    bis $31,%r1,%0
5143    ldl %0,%1
5144    stl %r1,%0"
5145   [(set_attr "type" "ilog,ild,ist")])
5146
5147 (define_insn "*movdf_nofix"
5148   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,*r,*r,m,m")
5149         (match_operand:DF 1 "input_operand" "fG,m,*rG,m,fG,*r"))]
5150   "TARGET_FPREGS && ! TARGET_FIX
5151    && (register_operand (operands[0], DFmode)
5152        || reg_or_fp0_operand (operands[1], DFmode))"
5153   "@
5154    cpys %R1,%R1,%0
5155    ld%- %0,%1
5156    bis $31,%r1,%0
5157    ldq %0,%1
5158    st%- %R1,%0
5159    stq %r1,%0"
5160   [(set_attr "type" "fcpys,fld,ilog,ild,fst,ist")])
5161
5162 (define_insn "*movdf_fix"
5163   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,*r,*r,m,m,f,*r")
5164         (match_operand:DF 1 "input_operand" "fG,m,*rG,m,fG,*r,*r,f"))]
5165   "TARGET_FPREGS && TARGET_FIX
5166    && (register_operand (operands[0], DFmode)
5167        || reg_or_fp0_operand (operands[1], DFmode))"
5168   "@
5169    cpys %R1,%R1,%0
5170    ld%- %0,%1
5171    bis $31,%r1,%0
5172    ldq %0,%1
5173    st%- %R1,%0
5174    stq %r1,%0
5175    itoft %1,%0
5176    ftoit %1,%0"
5177   [(set_attr "type" "fcpys,fld,ilog,ild,fst,ist,itof,ftoi")])
5178
5179 (define_insn "*movdf_nofp"
5180   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m")
5181         (match_operand:DF 1 "input_operand" "rG,m,r"))]
5182   "! TARGET_FPREGS
5183    && (register_operand (operands[0], DFmode)
5184        || reg_or_fp0_operand (operands[1], DFmode))"
5185   "@
5186    bis $31,%r1,%0
5187    ldq %0,%1
5188    stq %r1,%0"
5189   [(set_attr "type" "ilog,ild,ist")])
5190
5191 ;; Subregs suck for register allocation.  Pretend we can move TFmode
5192 ;; data between general registers until after reload.
5193
5194 (define_insn_and_split "*movtf_internal"
5195   [(set (match_operand:TF 0 "nonimmediate_operand" "=r,o")
5196         (match_operand:TF 1 "input_operand" "roG,rG"))]
5197   "register_operand (operands[0], TFmode)
5198    || reg_or_fp0_operand (operands[1], TFmode)"
5199   "#"
5200   "reload_completed"
5201   [(set (match_dup 0) (match_dup 2))
5202    (set (match_dup 1) (match_dup 3))]
5203 {
5204   alpha_split_tfmode_pair (operands);
5205   if (reg_overlap_mentioned_p (operands[0], operands[3]))
5206     {
5207       rtx tmp;
5208       tmp = operands[0], operands[0] = operands[1], operands[1] = tmp;
5209       tmp = operands[2], operands[2] = operands[3], operands[3] = tmp;
5210     }
5211 })
5212
5213 (define_expand "movsf"
5214   [(set (match_operand:SF 0 "nonimmediate_operand" "")
5215         (match_operand:SF 1 "general_operand" ""))]
5216   ""
5217 {
5218   if (GET_CODE (operands[0]) == MEM
5219       && ! reg_or_fp0_operand (operands[1], SFmode))
5220     operands[1] = force_reg (SFmode, operands[1]);
5221 })
5222
5223 (define_expand "movdf"
5224   [(set (match_operand:DF 0 "nonimmediate_operand" "")
5225         (match_operand:DF 1 "general_operand" ""))]
5226   ""
5227 {
5228   if (GET_CODE (operands[0]) == MEM
5229       && ! reg_or_fp0_operand (operands[1], DFmode))
5230     operands[1] = force_reg (DFmode, operands[1]);
5231 })
5232
5233 (define_expand "movtf"
5234   [(set (match_operand:TF 0 "nonimmediate_operand" "")
5235         (match_operand:TF 1 "general_operand" ""))]
5236   ""
5237 {
5238   if (GET_CODE (operands[0]) == MEM
5239       && ! reg_or_fp0_operand (operands[1], TFmode))
5240     operands[1] = force_reg (TFmode, operands[1]);
5241 })
5242
5243 (define_insn "*movsi_nofix"
5244   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,r,m,*f,*f,m")
5245         (match_operand:SI 1 "input_operand" "rJ,K,L,m,rJ,*fJ,m,*f"))]
5246   "(TARGET_ABI_OSF || TARGET_ABI_UNICOSMK) && ! TARGET_FIX
5247    && (register_operand (operands[0], SImode)
5248        || reg_or_0_operand (operands[1], SImode))"
5249   "@
5250    bis $31,%r1,%0
5251    lda %0,%1($31)
5252    ldah %0,%h1($31)
5253    ldl %0,%1
5254    stl %r1,%0
5255    cpys %R1,%R1,%0
5256    ld%, %0,%1
5257    st%, %R1,%0"
5258   [(set_attr "type" "ilog,iadd,iadd,ild,ist,fcpys,fld,fst")])
5259
5260 (define_insn "*movsi_fix"
5261   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,r,m,*f,*f,m,r,*f")
5262         (match_operand:SI 1 "input_operand" "rJ,K,L,m,rJ,*fJ,m,*f,*f,r"))]
5263   "TARGET_ABI_OSF && TARGET_FIX
5264    && (register_operand (operands[0], SImode)
5265        || reg_or_0_operand (operands[1], SImode))"
5266   "@
5267    bis $31,%r1,%0
5268    lda %0,%1($31)
5269    ldah %0,%h1($31)
5270    ldl %0,%1
5271    stl %r1,%0
5272    cpys %R1,%R1,%0
5273    ld%, %0,%1
5274    st%, %R1,%0
5275    ftois %1,%0
5276    itofs %1,%0"
5277   [(set_attr "type" "ilog,iadd,iadd,ild,ist,fcpys,fld,fst,ftoi,itof")])
5278
5279 (define_insn "*movsi_nt_vms"
5280   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,r,r,m,*f,*f,m")
5281         (match_operand:SI 1 "input_operand" "rJ,K,L,s,m,rJ,*fJ,m,*f"))]
5282   "(TARGET_ABI_WINDOWS_NT || TARGET_ABI_OPEN_VMS)
5283     && (register_operand (operands[0], SImode)
5284         || reg_or_0_operand (operands[1], SImode))"
5285   "@
5286    bis $31,%1,%0
5287    lda %0,%1
5288    ldah %0,%h1
5289    lda %0,%1
5290    ldl %0,%1
5291    stl %r1,%0
5292    cpys %R1,%R1,%0
5293    ld%, %0,%1
5294    st%, %R1,%0"
5295   [(set_attr "type" "ilog,iadd,iadd,ldsym,ild,ist,fcpys,fld,fst")])
5296
5297 (define_insn "*movhi_nobwx"
5298   [(set (match_operand:HI 0 "register_operand" "=r,r")
5299         (match_operand:HI 1 "input_operand" "rJ,n"))]
5300   "! TARGET_BWX
5301    && (register_operand (operands[0], HImode)
5302        || register_operand (operands[1], HImode))"
5303   "@
5304    bis $31,%r1,%0
5305    lda %0,%L1($31)"
5306   [(set_attr "type" "ilog,iadd")])
5307
5308 (define_insn "*movhi_bwx"
5309   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,r,m")
5310         (match_operand:HI 1 "input_operand" "rJ,n,m,rJ"))]
5311   "TARGET_BWX
5312    && (register_operand (operands[0], HImode)
5313        || reg_or_0_operand (operands[1], HImode))"
5314   "@
5315    bis $31,%r1,%0
5316    lda %0,%L1($31)
5317    ldwu %0,%1
5318    stw %r1,%0"
5319   [(set_attr "type" "ilog,iadd,ild,ist")])
5320
5321 (define_insn "*movqi_nobwx"
5322   [(set (match_operand:QI 0 "register_operand" "=r,r")
5323         (match_operand:QI 1 "input_operand" "rJ,n"))]
5324   "! TARGET_BWX
5325    && (register_operand (operands[0], QImode)
5326        || register_operand (operands[1], QImode))"
5327   "@
5328    bis $31,%r1,%0
5329    lda %0,%L1($31)"
5330   [(set_attr "type" "ilog,iadd")])
5331
5332 (define_insn "*movqi_bwx"
5333   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,r,m")
5334         (match_operand:QI 1 "input_operand" "rJ,n,m,rJ"))]
5335   "TARGET_BWX
5336    && (register_operand (operands[0], QImode)
5337        || reg_or_0_operand (operands[1], QImode))"
5338   "@
5339    bis $31,%r1,%0
5340    lda %0,%L1($31)
5341    ldbu %0,%1
5342    stb %r1,%0"
5343   [(set_attr "type" "ilog,iadd,ild,ist")])
5344
5345 ;; We do two major things here: handle mem->mem and construct long
5346 ;; constants.
5347
5348 (define_expand "movsi"
5349   [(set (match_operand:SI 0 "nonimmediate_operand" "")
5350         (match_operand:SI 1 "general_operand" ""))]
5351   ""
5352 {
5353   if (alpha_expand_mov (SImode, operands))
5354     DONE;
5355 })
5356
5357 ;; Split a load of a large constant into the appropriate two-insn
5358 ;; sequence.
5359
5360 (define_split
5361   [(set (match_operand:SI 0 "register_operand" "")
5362         (match_operand:SI 1 "const_int_operand" ""))]
5363   "! add_operand (operands[1], SImode)"
5364   [(set (match_dup 0) (match_dup 2))
5365    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
5366 {
5367   rtx tem
5368     = alpha_emit_set_const (operands[0], SImode, INTVAL (operands[1]), 2);
5369
5370   if (tem == operands[0])
5371     DONE;
5372   else
5373     FAIL;
5374 })
5375
5376 ;; Split the load of an address into a four-insn sequence on Unicos/Mk.
5377 ;; Always generate a REG_EQUAL note for the last instruction to facilitate
5378 ;; optimisations. If the symbolic operand is a label_ref, generate REG_LABEL
5379 ;; notes and update LABEL_NUSES because this is not done automatically.
5380 ;; Labels may be incorrectly deleted if we don't do this.
5381 ;;
5382 ;; Describing what the individual instructions do correctly is too complicated
5383 ;; so use UNSPECs for each of the three parts of an address.
5384
5385 (define_split
5386   [(set (match_operand:DI 0 "register_operand" "")
5387         (match_operand:DI 1 "symbolic_operand" ""))]
5388   "TARGET_ABI_UNICOSMK && reload_completed"
5389   [(const_int 0)]
5390 {
5391   rtx insn1, insn2, insn3;
5392
5393   insn1 = emit_insn (gen_umk_laum (operands[0], operands[1]));
5394   emit_insn (gen_ashldi3 (operands[0], operands[0], GEN_INT (32)));
5395   insn2 = emit_insn (gen_umk_lalm (operands[0], operands[0], operands[1]));
5396   insn3 = emit_insn (gen_umk_lal (operands[0], operands[0], operands[1]));
5397   REG_NOTES (insn3) = gen_rtx_EXPR_LIST (REG_EQUAL, operands[1],
5398                                          REG_NOTES (insn3));
5399   if (GET_CODE (operands[1]) == LABEL_REF)
5400     {
5401       rtx label;
5402
5403       label = XEXP (operands[1], 0);
5404       REG_NOTES (insn1) = gen_rtx_EXPR_LIST (REG_LABEL, label,
5405                                              REG_NOTES (insn1));
5406       REG_NOTES (insn2) = gen_rtx_EXPR_LIST (REG_LABEL, label,
5407                                              REG_NOTES (insn2));
5408       REG_NOTES (insn3) = gen_rtx_EXPR_LIST (REG_LABEL, label,
5409                                              REG_NOTES (insn3));
5410       LABEL_NUSES (label) += 3;
5411     }
5412   DONE;
5413 })
5414
5415 ;; Instructions for loading the three parts of an address on Unicos/Mk.
5416
5417 (define_insn "umk_laum"
5418   [(set (match_operand:DI 0 "register_operand" "=r")
5419         (unspec:DI [(match_operand:DI 1 "symbolic_operand" "")]
5420                    UNSPEC_UMK_LAUM))]
5421   "TARGET_ABI_UNICOSMK"
5422   "laum %r0,%t1($31)"
5423   [(set_attr "type" "iadd")])
5424
5425 (define_insn "umk_lalm"
5426   [(set (match_operand:DI 0 "register_operand" "=r")
5427         (plus:DI (match_operand:DI 1 "register_operand" "r")
5428                  (unspec:DI [(match_operand:DI 2 "symbolic_operand" "")]
5429                             UNSPEC_UMK_LALM)))] 
5430   "TARGET_ABI_UNICOSMK"
5431   "lalm %r0,%t2(%r1)"
5432   [(set_attr "type" "iadd")])
5433
5434 (define_insn "umk_lal"
5435   [(set (match_operand:DI 0 "register_operand" "=r")
5436         (plus:DI (match_operand:DI 1 "register_operand" "r")
5437                  (unspec:DI [(match_operand:DI 2 "symbolic_operand" "")]
5438                             UNSPEC_UMK_LAL)))]
5439   "TARGET_ABI_UNICOSMK"
5440   "lal %r0,%t2(%r1)"
5441   [(set_attr "type" "iadd")])
5442
5443 ;; Add a new call information word to the current function's list of CIWs
5444 ;; and load its index into $25. Doing it here ensures that the CIW will be
5445 ;; associated with the correct function even in the presence of inlining.
5446
5447 (define_insn "*umk_load_ciw"
5448   [(set (reg:DI 25)
5449         (unspec:DI [(match_operand 0 "" "")] UNSPEC_UMK_LOAD_CIW))]
5450   "TARGET_ABI_UNICOSMK"
5451 {
5452   operands[0] = unicosmk_add_call_info_word (operands[0]);
5453   return "lda $25,%0";
5454 }
5455   [(set_attr "type" "iadd")])
5456
5457 (define_insn "*movdi_er_low_l"
5458   [(set (match_operand:DI 0 "register_operand" "=r")
5459         (lo_sum:DI (match_operand:DI 1 "register_operand" "r")
5460                    (match_operand:DI 2 "local_symbolic_operand" "")))]
5461   "TARGET_EXPLICIT_RELOCS"
5462 {
5463   if (true_regnum (operands[1]) == 29)
5464     return "lda %0,%2(%1)\t\t!gprel";
5465   else
5466     return "lda %0,%2(%1)\t\t!gprellow";
5467 })
5468
5469 (define_insn "movdi_er_high_g"
5470   [(set (match_operand:DI 0 "register_operand" "=r")
5471         (unspec:DI [(match_operand:DI 1 "register_operand" "r")
5472                     (match_operand:DI 2 "global_symbolic_operand" "")
5473                     (match_operand 3 "const_int_operand" "")]
5474                    UNSPEC_LITERAL))]
5475   "TARGET_EXPLICIT_RELOCS"
5476   "ldq %0,%2(%1)\t\t!literal"
5477   [(set_attr "type" "ldsym")])
5478
5479 (define_insn "*movdi_er_nofix"
5480   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,r,r,r,m,*f,*f,Q")
5481         (match_operand:DI 1 "input_operand" "rJ,K,L,T,m,rJ,*fJ,Q,*f"))]
5482   "TARGET_EXPLICIT_RELOCS && ! TARGET_FIX
5483    && (register_operand (operands[0], DImode)
5484        || reg_or_0_operand (operands[1], DImode))"
5485   "@
5486    mov %r1,%0
5487    lda %0,%1($31)
5488    ldah %0,%h1($31)
5489    ldah %0,%H1
5490    ldq%A1 %0,%1
5491    stq%A0 %r1,%0
5492    fmov %R1,%0
5493    ldt %0,%1
5494    stt %R1,%0"
5495   [(set_attr "type" "ilog,iadd,iadd,iadd,ild,ist,fcpys,fld,fst")])
5496
5497 ;; The 'U' constraint matches symbolic operands on Unicos/Mk. Those should
5498 ;; have been split up by the rules above but we shouldn't reject the
5499 ;; possibility of them getting through.
5500
5501 (define_insn "*movdi_nofix"
5502   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,r,r,r,r,m,*f,*f,Q")
5503         (match_operand:DI 1 "input_operand" "rJ,K,L,U,s,m,rJ,*fJ,Q,*f"))]
5504   "! TARGET_FIX
5505    && (register_operand (operands[0], DImode)
5506        || reg_or_0_operand (operands[1], DImode))"
5507   "@
5508    bis $31,%r1,%0
5509    lda %0,%1($31)
5510    ldah %0,%h1($31)
5511    laum %0,%t1($31)\;sll %0,32,%0\;lalm %0,%t1(%0)\;lal %0,%t1(%0)
5512    lda %0,%1
5513    ldq%A1 %0,%1
5514    stq%A0 %r1,%0
5515    cpys %R1,%R1,%0
5516    ldt %0,%1
5517    stt %R1,%0"
5518   [(set_attr "type" "ilog,iadd,iadd,ldsym,ldsym,ild,ist,fcpys,fld,fst")
5519    (set_attr "length" "*,*,*,16,*,*,*,*,*,*")])
5520
5521 (define_insn "*movdi_er_fix"
5522   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,r,r,r,m,*f,*f,Q,r,*f")
5523         (match_operand:DI 1 "input_operand" "rJ,K,L,T,m,rJ,*fJ,Q,*f,*f,r"))]
5524   "TARGET_EXPLICIT_RELOCS && TARGET_FIX
5525    && (register_operand (operands[0], DImode)
5526        || reg_or_0_operand (operands[1], DImode))"
5527   "@
5528    mov %r1,%0
5529    lda %0,%1($31)
5530    ldah %0,%h1($31)
5531    ldah %0,%H1
5532    ldq%A1 %0,%1
5533    stq%A0 %r1,%0
5534    fmov %R1,%0
5535    ldt %0,%1
5536    stt %R1,%0
5537    ftoit %1,%0
5538    itoft %1,%0"
5539   [(set_attr "type" "ilog,iadd,iadd,iadd,ild,ist,fcpys,fld,fst,ftoi,itof")])
5540
5541 (define_insn "*movdi_fix"
5542   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,r,r,r,m,*f,*f,Q,r,*f")
5543         (match_operand:DI 1 "input_operand" "rJ,K,L,s,m,rJ,*fJ,Q,*f,*f,r"))]
5544   "! TARGET_EXPLICIT_RELOCS && TARGET_FIX
5545    && (register_operand (operands[0], DImode)
5546        || reg_or_0_operand (operands[1], DImode))"
5547   "@
5548    bis $31,%r1,%0
5549    lda %0,%1($31)
5550    ldah %0,%h1($31)
5551    lda %0,%1
5552    ldq%A1 %0,%1
5553    stq%A0 %r1,%0
5554    cpys %R1,%R1,%0
5555    ldt %0,%1
5556    stt %R1,%0
5557    ftoit %1,%0
5558    itoft %1,%0"
5559   [(set_attr "type" "ilog,iadd,iadd,ldsym,ild,ist,fcpys,fld,fst,ftoi,itof")])
5560
5561 ;; VMS needs to set up "vms_base_regno" for unwinding.  This move
5562 ;; often appears dead to the life analysis code, at which point we
5563 ;; abort for emitting dead prologue instructions.  Force this live.
5564
5565 (define_insn "force_movdi"
5566   [(set (match_operand:DI 0 "register_operand" "=r")
5567         (unspec_volatile:DI [(match_operand:DI 1 "register_operand" "r")]
5568                             UNSPECV_FORCE_MOV))]
5569   ""
5570   "mov %1,%0"
5571   [(set_attr "type" "ilog")])
5572
5573 ;; We do three major things here: handle mem->mem, put 64-bit constants in
5574 ;; memory, and construct long 32-bit constants.
5575
5576 (define_expand "movdi"
5577   [(set (match_operand:DI 0 "nonimmediate_operand" "")
5578         (match_operand:DI 1 "general_operand" ""))]
5579   ""
5580 {
5581   if (alpha_expand_mov (DImode, operands))
5582     DONE;
5583 })
5584
5585 ;; Split a load of a large constant into the appropriate two-insn
5586 ;; sequence.
5587
5588 (define_split
5589   [(set (match_operand:DI 0 "register_operand" "")
5590         (match_operand:DI 1 "const_int_operand" ""))]
5591   "! add_operand (operands[1], DImode)"
5592   [(set (match_dup 0) (match_dup 2))
5593    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
5594 {
5595   rtx tem
5596     = alpha_emit_set_const (operands[0], DImode, INTVAL (operands[1]), 2);
5597
5598   if (tem == operands[0])
5599     DONE;
5600   else
5601     FAIL;
5602 })
5603
5604 ;; These are the partial-word cases.
5605 ;;
5606 ;; First we have the code to load an aligned word.  Operand 0 is the register
5607 ;; in which to place the result.  It's mode is QImode or HImode.  Operand 1
5608 ;; is an SImode MEM at the low-order byte of the proper word.  Operand 2 is the
5609 ;; number of bits within the word that the value is.  Operand 3 is an SImode
5610 ;; scratch register.  If operand 0 is a hard register, operand 3 may be the
5611 ;; same register.  It is allowed to conflict with operand 1 as well.
5612
5613 (define_expand "aligned_loadqi"
5614   [(set (match_operand:SI 3 "register_operand" "")
5615         (match_operand:SI 1 "memory_operand" ""))
5616    (set (subreg:DI (match_operand:QI 0 "register_operand" "") 0)
5617         (zero_extract:DI (subreg:DI (match_dup 3) 0)
5618                          (const_int 8)
5619                          (match_operand:DI 2 "const_int_operand" "")))]
5620
5621   ""
5622   "")
5623
5624 (define_expand "aligned_loadhi"
5625   [(set (match_operand:SI 3 "register_operand" "")
5626         (match_operand:SI 1 "memory_operand" ""))
5627    (set (subreg:DI (match_operand:HI 0 "register_operand" "") 0)
5628         (zero_extract:DI (subreg:DI (match_dup 3) 0)
5629                          (const_int 16)
5630                          (match_operand:DI 2 "const_int_operand" "")))]
5631
5632   ""
5633   "")
5634
5635 ;; Similar for unaligned loads, where we use the sequence from the
5636 ;; Alpha Architecture manual. We have to distinguish between little-endian
5637 ;; and big-endian systems as the sequences are different.
5638 ;;
5639 ;; Operand 1 is the address.  Operands 2 and 3 are temporaries, where
5640 ;; operand 3 can overlap the input and output registers.
5641
5642 (define_expand "unaligned_loadqi"
5643   [(use (match_operand:QI 0 "register_operand" ""))
5644    (use (match_operand:DI 1 "address_operand" ""))
5645    (use (match_operand:DI 2 "register_operand" ""))
5646    (use (match_operand:DI 3 "register_operand" ""))]
5647   ""
5648 {
5649   if (WORDS_BIG_ENDIAN)
5650     emit_insn (gen_unaligned_loadqi_be (operands[0], operands[1],
5651                                         operands[2], operands[3]));
5652   else
5653     emit_insn (gen_unaligned_loadqi_le (operands[0], operands[1],
5654                                         operands[2], operands[3]));
5655   DONE;
5656 })
5657
5658 (define_expand "unaligned_loadqi_le"
5659   [(set (match_operand:DI 2 "register_operand" "")
5660         (mem:DI (and:DI (match_operand:DI 1 "address_operand" "")
5661                         (const_int -8))))
5662    (set (match_operand:DI 3 "register_operand" "")
5663         (match_dup 1))
5664    (set (subreg:DI (match_operand:QI 0 "register_operand" "") 0)
5665         (zero_extract:DI (match_dup 2)
5666                          (const_int 8)
5667                          (ashift:DI (match_dup 3) (const_int 3))))]
5668   "! WORDS_BIG_ENDIAN"
5669   "")
5670
5671 (define_expand "unaligned_loadqi_be"
5672   [(set (match_operand:DI 2 "register_operand" "")
5673         (mem:DI (and:DI (match_operand:DI 1 "address_operand" "")
5674                         (const_int -8))))
5675    (set (match_operand:DI 3 "register_operand" "")
5676         (match_dup 1))
5677    (set (subreg:DI (match_operand:QI 0 "register_operand" "") 0)
5678         (zero_extract:DI (match_dup 2)
5679                          (const_int 8)
5680                          (minus:DI
5681                            (const_int 56)
5682                            (ashift:DI (match_dup 3) (const_int 3)))))]
5683   "WORDS_BIG_ENDIAN"
5684   "")
5685
5686 (define_expand "unaligned_loadhi"
5687   [(use (match_operand:QI 0 "register_operand" ""))
5688    (use (match_operand:DI 1 "address_operand" ""))
5689    (use (match_operand:DI 2 "register_operand" ""))
5690    (use (match_operand:DI 3 "register_operand" ""))]
5691   ""
5692 {
5693   if (WORDS_BIG_ENDIAN)
5694     emit_insn (gen_unaligned_loadhi_be (operands[0], operands[1],
5695                                         operands[2], operands[3]));
5696   else
5697     emit_insn (gen_unaligned_loadhi_le (operands[0], operands[1],
5698                                         operands[2], operands[3]));
5699   DONE;
5700 })
5701
5702 (define_expand "unaligned_loadhi_le"
5703   [(set (match_operand:DI 2 "register_operand" "")
5704         (mem:DI (and:DI (match_operand:DI 1 "address_operand" "")
5705                         (const_int -8))))
5706    (set (match_operand:DI 3 "register_operand" "")
5707         (match_dup 1))
5708    (set (subreg:DI (match_operand:QI 0 "register_operand" "") 0)
5709         (zero_extract:DI (match_dup 2)
5710                          (const_int 16)
5711                          (ashift:DI (match_dup 3) (const_int 3))))]
5712   "! WORDS_BIG_ENDIAN"
5713   "")
5714
5715 (define_expand "unaligned_loadhi_be"
5716   [(set (match_operand:DI 2 "register_operand" "")
5717         (mem:DI (and:DI (match_operand:DI 1 "address_operand" "")
5718                         (const_int -8))))
5719    (set (match_operand:DI 3 "register_operand" "")
5720         (plus:DI (match_dup 1) (const_int 1)))
5721    (set (subreg:DI (match_operand:QI 0 "register_operand" "") 0)
5722         (zero_extract:DI (match_dup 2)
5723                          (const_int 16)
5724                          (minus:DI
5725                            (const_int 56)
5726                            (ashift:DI (match_dup 3) (const_int 3)))))]
5727   "WORDS_BIG_ENDIAN"
5728   "")
5729
5730 ;; Storing an aligned byte or word requires two temporaries.  Operand 0 is the
5731 ;; aligned SImode MEM.  Operand 1 is the register containing the
5732 ;; byte or word to store.  Operand 2 is the number of bits within the word that
5733 ;; the value should be placed.  Operands 3 and 4 are SImode temporaries.
5734
5735 (define_expand "aligned_store"
5736   [(set (match_operand:SI 3 "register_operand" "")
5737         (match_operand:SI 0 "memory_operand" ""))
5738    (set (subreg:DI (match_dup 3) 0)
5739         (and:DI (subreg:DI (match_dup 3) 0) (match_dup 5)))
5740    (set (subreg:DI (match_operand:SI 4 "register_operand" "") 0)
5741         (ashift:DI (zero_extend:DI (match_operand 1 "register_operand" ""))
5742                    (match_operand:DI 2 "const_int_operand" "")))
5743    (set (subreg:DI (match_dup 4) 0)
5744         (ior:DI (subreg:DI (match_dup 4) 0) (subreg:DI (match_dup 3) 0)))
5745    (set (match_dup 0) (match_dup 4))]
5746   ""
5747 {
5748   operands[5] = GEN_INT (~ (GET_MODE_MASK (GET_MODE (operands[1]))
5749                             << INTVAL (operands[2])));
5750 })
5751
5752 ;; For the unaligned byte and halfword cases, we use code similar to that
5753 ;; in the ;; Architecture book, but reordered to lower the number of registers
5754 ;; required.  Operand 0 is the address.  Operand 1 is the data to store.
5755 ;; Operands 2, 3, and 4 are DImode temporaries, where operands 2 and 4 may
5756 ;; be the same temporary, if desired.  If the address is in a register,
5757 ;; operand 2 can be that register.
5758
5759 (define_expand "unaligned_storeqi"
5760   [(use (match_operand:DI 0 "address_operand" ""))
5761    (use (match_operand:QI 1 "register_operand" ""))
5762    (use (match_operand:DI 2 "register_operand" ""))
5763    (use (match_operand:DI 3 "register_operand" ""))
5764    (use (match_operand:DI 4 "register_operand" ""))]
5765   ""
5766 {
5767   if (WORDS_BIG_ENDIAN)
5768     emit_insn (gen_unaligned_storeqi_be (operands[0], operands[1],
5769                                          operands[2], operands[3],
5770                                          operands[4]));
5771   else
5772     emit_insn (gen_unaligned_storeqi_le (operands[0], operands[1],
5773                                          operands[2], operands[3],
5774                                          operands[4]));
5775   DONE;
5776 })
5777
5778 (define_expand "unaligned_storeqi_le"
5779   [(set (match_operand:DI 3 "register_operand" "")
5780         (mem:DI (and:DI (match_operand:DI 0 "address_operand" "")
5781                         (const_int -8))))
5782    (set (match_operand:DI 2 "register_operand" "")
5783         (match_dup 0))
5784    (set (match_dup 3)
5785         (and:DI (not:DI (ashift:DI (const_int 255)
5786                                    (ashift:DI (match_dup 2) (const_int 3))))
5787                 (match_dup 3)))
5788    (set (match_operand:DI 4 "register_operand" "")
5789         (ashift:DI (zero_extend:DI (match_operand:QI 1 "register_operand" ""))
5790                    (ashift:DI (match_dup 2) (const_int 3))))
5791    (set (match_dup 4) (ior:DI (match_dup 4) (match_dup 3)))
5792    (set (mem:DI (and:DI (match_dup 0) (const_int -8)))
5793         (match_dup 4))]
5794   "! WORDS_BIG_ENDIAN"
5795   "")
5796
5797 (define_expand "unaligned_storeqi_be"
5798   [(set (match_operand:DI 3 "register_operand" "")
5799         (mem:DI (and:DI (match_operand:DI 0 "address_operand" "")
5800                         (const_int -8))))
5801    (set (match_operand:DI 2 "register_operand" "")
5802         (match_dup 0))
5803    (set (match_dup 3)
5804         (and:DI (not:DI (ashift:DI (const_int 255)
5805                           (minus:DI (const_int 56)
5806                                     (ashift:DI (match_dup 2) (const_int 3)))))
5807                 (match_dup 3)))
5808    (set (match_operand:DI 4 "register_operand" "")
5809         (ashift:DI (zero_extend:DI (match_operand:QI 1 "register_operand" ""))
5810                    (minus:DI (const_int 56)
5811                      (ashift:DI (match_dup 2) (const_int 3)))))
5812    (set (match_dup 4) (ior:DI (match_dup 4) (match_dup 3)))
5813    (set (mem:DI (and:DI (match_dup 0) (const_int -8)))
5814         (match_dup 4))]
5815   "WORDS_BIG_ENDIAN"
5816   "")
5817
5818 (define_expand "unaligned_storehi"
5819   [(use (match_operand:DI 0 "address_operand" ""))
5820    (use (match_operand:HI 1 "register_operand" ""))
5821    (use (match_operand:DI 2 "register_operand" ""))
5822    (use (match_operand:DI 3 "register_operand" ""))
5823    (use (match_operand:DI 4 "register_operand" ""))]
5824   ""
5825 {
5826   if (WORDS_BIG_ENDIAN)
5827     emit_insn (gen_unaligned_storehi_be (operands[0], operands[1],
5828                                          operands[2], operands[3],
5829                                          operands[4]));
5830   else
5831     emit_insn (gen_unaligned_storehi_le (operands[0], operands[1],
5832                                          operands[2], operands[3],
5833                                          operands[4]));
5834   DONE;
5835 })
5836
5837 (define_expand "unaligned_storehi_le"
5838   [(set (match_operand:DI 3 "register_operand" "")
5839         (mem:DI (and:DI (match_operand:DI 0 "address_operand" "")
5840                         (const_int -8))))
5841    (set (match_operand:DI 2 "register_operand" "")
5842         (match_dup 0))
5843    (set (match_dup 3)
5844         (and:DI (not:DI (ashift:DI (const_int 65535)
5845                                    (ashift:DI (match_dup 2) (const_int 3))))
5846                 (match_dup 3)))
5847    (set (match_operand:DI 4 "register_operand" "")
5848         (ashift:DI (zero_extend:DI (match_operand:HI 1 "register_operand" ""))
5849                    (ashift:DI (match_dup 2) (const_int 3))))
5850    (set (match_dup 4) (ior:DI (match_dup 4) (match_dup 3)))
5851    (set (mem:DI (and:DI (match_dup 0) (const_int -8)))
5852         (match_dup 4))]
5853   "! WORDS_BIG_ENDIAN"
5854   "")
5855
5856 (define_expand "unaligned_storehi_be"
5857   [(set (match_operand:DI 3 "register_operand" "")
5858         (mem:DI (and:DI (match_operand:DI 0 "address_operand" "")
5859                         (const_int -8))))
5860    (set (match_operand:DI 2 "register_operand" "")
5861         (plus:DI (match_dup 0) (const_int 1)))
5862    (set (match_dup 3)
5863         (and:DI (not:DI (ashift:DI
5864                           (const_int 65535)
5865                           (minus:DI (const_int 56)
5866                                     (ashift:DI (match_dup 2) (const_int 3)))))
5867                 (match_dup 3)))
5868    (set (match_operand:DI 4 "register_operand" "")
5869         (ashift:DI (zero_extend:DI (match_operand:HI 1 "register_operand" ""))
5870                    (minus:DI (const_int 56)
5871                              (ashift:DI (match_dup 2) (const_int 3)))))
5872    (set (match_dup 4) (ior:DI (match_dup 4) (match_dup 3)))
5873    (set (mem:DI (and:DI (match_dup 0) (const_int -8)))
5874         (match_dup 4))]
5875   "WORDS_BIG_ENDIAN"
5876   "")
5877 \f
5878 ;; Here are the define_expand's for QI and HI moves that use the above
5879 ;; patterns.  We have the normal sets, plus the ones that need scratch
5880 ;; registers for reload.
5881
5882 (define_expand "movqi"
5883   [(set (match_operand:QI 0 "nonimmediate_operand" "")
5884         (match_operand:QI 1 "general_operand" ""))]
5885   ""
5886 {
5887   if (TARGET_BWX
5888       ? alpha_expand_mov (QImode, operands)
5889       : alpha_expand_mov_nobwx (QImode, operands))
5890     DONE;
5891 })
5892
5893 (define_expand "movhi"
5894   [(set (match_operand:HI 0 "nonimmediate_operand" "")
5895         (match_operand:HI 1 "general_operand" ""))]
5896   ""
5897 {
5898   if (TARGET_BWX
5899       ? alpha_expand_mov (HImode, operands)
5900       : alpha_expand_mov_nobwx (HImode, operands))
5901     DONE;
5902 })
5903
5904 ;; Here are the versions for reload.  Note that in the unaligned cases
5905 ;; we know that the operand must not be a pseudo-register because stack
5906 ;; slots are always aligned references.
5907
5908 (define_expand "reload_inqi"
5909   [(parallel [(match_operand:QI 0 "register_operand" "=r")
5910               (match_operand:QI 1 "any_memory_operand" "m")
5911               (match_operand:TI 2 "register_operand" "=&r")])]
5912   "! TARGET_BWX"
5913 {
5914   rtx scratch, seq;
5915
5916   if (GET_CODE (operands[1]) != MEM)
5917     abort ();
5918
5919   if (aligned_memory_operand (operands[1], QImode))
5920     {
5921       seq = gen_reload_inqi_help (operands[0], operands[1],
5922                                   gen_rtx_REG (SImode, REGNO (operands[2])));
5923     }
5924   else
5925     {
5926       rtx addr;
5927
5928       /* It is possible that one of the registers we got for operands[2]
5929          might coincide with that of operands[0] (which is why we made
5930          it TImode).  Pick the other one to use as our scratch.  */
5931       if (REGNO (operands[0]) == REGNO (operands[2]))
5932         scratch = gen_rtx_REG (DImode, REGNO (operands[2]) + 1);
5933       else
5934         scratch = gen_rtx_REG (DImode, REGNO (operands[2]));
5935
5936       addr = get_unaligned_address (operands[1], 0);
5937       seq = gen_unaligned_loadqi (operands[0], addr, scratch,
5938                           gen_rtx_REG (DImode, REGNO (operands[0])));
5939       alpha_set_memflags (seq, operands[1]);
5940     }
5941   emit_insn (seq);
5942   DONE;
5943 })
5944
5945 (define_expand "reload_inhi"
5946   [(parallel [(match_operand:HI 0 "register_operand" "=r")
5947               (match_operand:HI 1 "any_memory_operand" "m")
5948               (match_operand:TI 2 "register_operand" "=&r")])]
5949   "! TARGET_BWX"
5950 {
5951   rtx scratch, seq;
5952
5953   if (GET_CODE (operands[1]) != MEM)
5954     abort ();
5955
5956   if (aligned_memory_operand (operands[1], HImode))
5957     {
5958       seq = gen_reload_inhi_help (operands[0], operands[1],
5959                                   gen_rtx_REG (SImode, REGNO (operands[2])));
5960     }
5961   else
5962     {
5963       rtx addr;
5964
5965       /* It is possible that one of the registers we got for operands[2]
5966          might coincide with that of operands[0] (which is why we made
5967          it TImode).  Pick the other one to use as our scratch.  */
5968       if (REGNO (operands[0]) == REGNO (operands[2]))
5969         scratch = gen_rtx_REG (DImode, REGNO (operands[2]) + 1);
5970       else
5971         scratch = gen_rtx_REG (DImode, REGNO (operands[2]));
5972
5973       addr = get_unaligned_address (operands[1], 0);
5974       seq = gen_unaligned_loadhi (operands[0], addr, scratch,
5975                           gen_rtx_REG (DImode, REGNO (operands[0])));
5976       alpha_set_memflags (seq, operands[1]);
5977     }
5978   emit_insn (seq);
5979   DONE;
5980 })
5981
5982 (define_expand "reload_outqi"
5983   [(parallel [(match_operand:QI 0 "any_memory_operand" "=m")
5984               (match_operand:QI 1 "register_operand" "r")
5985               (match_operand:TI 2 "register_operand" "=&r")])]
5986   "! TARGET_BWX"
5987 {
5988   if (GET_CODE (operands[0]) != MEM)
5989     abort ();
5990
5991   if (aligned_memory_operand (operands[0], QImode))
5992     {
5993       emit_insn (gen_reload_outqi_help
5994                  (operands[0], operands[1],
5995                   gen_rtx_REG (SImode, REGNO (operands[2])),
5996                   gen_rtx_REG (SImode, REGNO (operands[2]) + 1)));
5997     }
5998   else
5999     {
6000       rtx addr = get_unaligned_address (operands[0], 0);
6001       rtx scratch1 = gen_rtx_REG (DImode, REGNO (operands[2]));
6002       rtx scratch2 = gen_rtx_REG (DImode, REGNO (operands[2]) + 1);
6003       rtx scratch3 = scratch1;
6004       rtx seq;
6005
6006       if (GET_CODE (addr) == REG)
6007         scratch1 = addr;
6008
6009       seq = gen_unaligned_storeqi (addr, operands[1], scratch1,
6010                                    scratch2, scratch3);
6011       alpha_set_memflags (seq, operands[0]);
6012       emit_insn (seq);
6013     }
6014   DONE;
6015 })
6016
6017 (define_expand "reload_outhi"
6018   [(parallel [(match_operand:HI 0 "any_memory_operand" "=m")
6019               (match_operand:HI 1 "register_operand" "r")
6020               (match_operand:TI 2 "register_operand" "=&r")])]
6021   "! TARGET_BWX"
6022 {
6023   if (GET_CODE (operands[0]) != MEM)
6024     abort ();
6025
6026   if (aligned_memory_operand (operands[0], HImode))
6027     {
6028       emit_insn (gen_reload_outhi_help
6029                  (operands[0], operands[1],
6030                   gen_rtx_REG (SImode, REGNO (operands[2])),
6031                   gen_rtx_REG (SImode, REGNO (operands[2]) + 1)));
6032     }
6033   else
6034     {
6035       rtx addr = get_unaligned_address (operands[0], 0);
6036       rtx scratch1 = gen_rtx_REG (DImode, REGNO (operands[2]));
6037       rtx scratch2 = gen_rtx_REG (DImode, REGNO (operands[2]) + 1);
6038       rtx scratch3 = scratch1;
6039       rtx seq;
6040
6041       if (GET_CODE (addr) == REG)
6042         scratch1 = addr;
6043
6044       seq = gen_unaligned_storehi (addr, operands[1], scratch1,
6045                                    scratch2, scratch3);
6046       alpha_set_memflags (seq, operands[0]);
6047       emit_insn (seq);
6048     }
6049   DONE;
6050 })
6051
6052 ;; Helpers for the above.  The way reload is structured, we can't
6053 ;; always get a proper address for a stack slot during reload_foo
6054 ;; expansion, so we must delay our address manipulations until after.
6055
6056 (define_insn "reload_inqi_help"
6057   [(set (match_operand:QI 0 "register_operand" "=r")
6058         (match_operand:QI 1 "memory_operand" "m"))
6059    (clobber (match_operand:SI 2 "register_operand" "=r"))]
6060   "! TARGET_BWX && (reload_in_progress || reload_completed)"
6061   "#")
6062
6063 (define_insn "reload_inhi_help"
6064   [(set (match_operand:HI 0 "register_operand" "=r")
6065         (match_operand:HI 1 "memory_operand" "m"))
6066    (clobber (match_operand:SI 2 "register_operand" "=r"))]
6067   "! TARGET_BWX && (reload_in_progress || reload_completed)"
6068   "#")
6069
6070 (define_insn "reload_outqi_help"
6071   [(set (match_operand:QI 0 "memory_operand" "=m")
6072         (match_operand:QI 1 "register_operand" "r"))
6073    (clobber (match_operand:SI 2 "register_operand" "=r"))
6074    (clobber (match_operand:SI 3 "register_operand" "=r"))]
6075   "! TARGET_BWX && (reload_in_progress || reload_completed)"
6076   "#")
6077
6078 (define_insn "reload_outhi_help"
6079   [(set (match_operand:HI 0 "memory_operand" "=m")
6080         (match_operand:HI 1 "register_operand" "r"))
6081    (clobber (match_operand:SI 2 "register_operand" "=r"))
6082    (clobber (match_operand:SI 3 "register_operand" "=r"))]
6083   "! TARGET_BWX && (reload_in_progress || reload_completed)"
6084   "#")
6085
6086 (define_split
6087   [(set (match_operand:QI 0 "register_operand" "")
6088         (match_operand:QI 1 "memory_operand" ""))
6089    (clobber (match_operand:SI 2 "register_operand" ""))]
6090   "! TARGET_BWX && reload_completed"
6091   [(const_int 0)]
6092 {
6093   rtx aligned_mem, bitnum;
6094   get_aligned_mem (operands[1], &aligned_mem, &bitnum);
6095
6096   emit_insn (gen_aligned_loadqi (operands[0], aligned_mem, bitnum,
6097                                  operands[2]));
6098   DONE;
6099 })
6100
6101 (define_split
6102   [(set (match_operand:HI 0 "register_operand" "")
6103         (match_operand:HI 1 "memory_operand" ""))
6104    (clobber (match_operand:SI 2 "register_operand" ""))]
6105   "! TARGET_BWX && reload_completed"
6106   [(const_int 0)]
6107 {
6108   rtx aligned_mem, bitnum;
6109   get_aligned_mem (operands[1], &aligned_mem, &bitnum);
6110
6111   emit_insn (gen_aligned_loadhi (operands[0], aligned_mem, bitnum,
6112                                  operands[2]));
6113   DONE;
6114 })
6115
6116 (define_split
6117   [(set (match_operand:QI 0 "memory_operand" "")
6118         (match_operand:QI 1 "register_operand" ""))
6119    (clobber (match_operand:SI 2 "register_operand" ""))
6120    (clobber (match_operand:SI 3 "register_operand" ""))]
6121   "! TARGET_BWX && reload_completed"
6122   [(const_int 0)]
6123 {
6124   rtx aligned_mem, bitnum;
6125   get_aligned_mem (operands[0], &aligned_mem, &bitnum);
6126   emit_insn (gen_aligned_store (aligned_mem, operands[1], bitnum,
6127                                 operands[2], operands[3]));
6128   DONE;
6129 })
6130
6131 (define_split
6132   [(set (match_operand:HI 0 "memory_operand" "")
6133         (match_operand:HI 1 "register_operand" ""))
6134    (clobber (match_operand:SI 2 "register_operand" ""))
6135    (clobber (match_operand:SI 3 "register_operand" ""))]
6136   "! TARGET_BWX && reload_completed"
6137   [(const_int 0)]
6138 {
6139   rtx aligned_mem, bitnum;
6140   get_aligned_mem (operands[0], &aligned_mem, &bitnum);
6141   emit_insn (gen_aligned_store (aligned_mem, operands[1], bitnum,
6142                                 operands[2], operands[3]));
6143   DONE;
6144 })
6145 \f
6146 ;; Bit field extract patterns which use ext[wlq][lh]
6147
6148 (define_expand "extv"
6149   [(set (match_operand:DI 0 "register_operand" "")
6150         (sign_extract:DI (match_operand:QI 1 "memory_operand" "")
6151                          (match_operand:DI 2 "immediate_operand" "")
6152                          (match_operand:DI 3 "immediate_operand" "")))]
6153   ""
6154 {
6155   int ofs;
6156
6157   /* We can do 16, 32 and 64 bit fields, if aligned on byte boundaries.  */
6158   if (INTVAL (operands[3]) % 8 != 0
6159       || (INTVAL (operands[2]) != 16
6160           && INTVAL (operands[2]) != 32
6161           && INTVAL (operands[2]) != 64))
6162     FAIL;
6163
6164   /* From mips.md: extract_bit_field doesn't verify that our source
6165      matches the predicate, so we force it to be a MEM here.  */
6166   if (GET_CODE (operands[1]) != MEM)
6167     FAIL;
6168
6169   /* The bit number is relative to the mode of operand 1 which is
6170      usually QImode (this might actually be a bug in expmed.c). Note 
6171      that the bit number is negative in big-endian mode in this case.
6172      We have to convert that to the offset.  */
6173   if (WORDS_BIG_ENDIAN)
6174     ofs = GET_MODE_BITSIZE (GET_MODE (operands[1]))
6175           - INTVAL (operands[2]) - INTVAL (operands[3]);
6176   else
6177     ofs = INTVAL (operands[3]);
6178
6179   ofs = ofs / 8;
6180
6181   alpha_expand_unaligned_load (operands[0], operands[1],
6182                                INTVAL (operands[2]) / 8,
6183                                ofs, 1);
6184   DONE;
6185 })
6186
6187 (define_expand "extzv"
6188   [(set (match_operand:DI 0 "register_operand" "")
6189         (zero_extract:DI (match_operand:DI 1 "nonimmediate_operand" "")
6190                          (match_operand:DI 2 "immediate_operand" "")
6191                          (match_operand:DI 3 "immediate_operand" "")))]
6192   ""
6193 {
6194   /* We can do 8, 16, 32 and 64 bit fields, if aligned on byte boundaries.  */
6195   if (INTVAL (operands[3]) % 8 != 0
6196       || (INTVAL (operands[2]) != 8
6197           && INTVAL (operands[2]) != 16
6198           && INTVAL (operands[2]) != 32
6199           && INTVAL (operands[2]) != 64))
6200     FAIL;
6201
6202   if (GET_CODE (operands[1]) == MEM)
6203     {
6204       int ofs;
6205
6206       /* Fail 8 bit fields, falling back on a simple byte load.  */
6207       if (INTVAL (operands[2]) == 8)
6208         FAIL;
6209
6210       /* The bit number is relative to the mode of operand 1 which is
6211          usually QImode (this might actually be a bug in expmed.c). Note 
6212          that the bit number is negative in big-endian mode in this case.
6213          We have to convert that to the offset.  */
6214       if (WORDS_BIG_ENDIAN)
6215         ofs = GET_MODE_BITSIZE (GET_MODE (operands[1]))
6216               - INTVAL (operands[2]) - INTVAL (operands[3]);
6217       else
6218         ofs = INTVAL (operands[3]);
6219
6220       ofs = ofs / 8;
6221
6222       alpha_expand_unaligned_load (operands[0], operands[1],
6223                                    INTVAL (operands[2]) / 8,
6224                                    ofs, 0);
6225       DONE;
6226     }
6227 })
6228
6229 (define_expand "insv"
6230   [(set (zero_extract:DI (match_operand:QI 0 "memory_operand" "")
6231                          (match_operand:DI 1 "immediate_operand" "")
6232                          (match_operand:DI 2 "immediate_operand" ""))
6233         (match_operand:DI 3 "register_operand" ""))]
6234   ""
6235 {
6236   int ofs;
6237
6238   /* We can do 16, 32 and 64 bit fields, if aligned on byte boundaries.  */
6239   if (INTVAL (operands[2]) % 8 != 0
6240       || (INTVAL (operands[1]) != 16
6241           && INTVAL (operands[1]) != 32
6242           && INTVAL (operands[1]) != 64))
6243     FAIL;
6244
6245   /* From mips.md: store_bit_field doesn't verify that our source
6246      matches the predicate, so we force it to be a MEM here.  */
6247   if (GET_CODE (operands[0]) != MEM)
6248     FAIL;
6249
6250   /* The bit number is relative to the mode of operand 1 which is
6251      usually QImode (this might actually be a bug in expmed.c). Note 
6252      that the bit number is negative in big-endian mode in this case.
6253      We have to convert that to the offset.  */
6254   if (WORDS_BIG_ENDIAN)
6255     ofs = GET_MODE_BITSIZE (GET_MODE (operands[0]))
6256           - INTVAL (operands[1]) - INTVAL (operands[2]);
6257   else
6258     ofs = INTVAL (operands[2]);
6259
6260   ofs = ofs / 8;
6261
6262   alpha_expand_unaligned_store (operands[0], operands[3],
6263                                 INTVAL (operands[1]) / 8, ofs);
6264   DONE;
6265 })
6266
6267 ;; Block move/clear, see alpha.c for more details.
6268 ;; Argument 0 is the destination
6269 ;; Argument 1 is the source
6270 ;; Argument 2 is the length
6271 ;; Argument 3 is the alignment
6272
6273 (define_expand "movstrqi"
6274   [(parallel [(set (match_operand:BLK 0 "memory_operand" "")
6275                    (match_operand:BLK 1 "memory_operand" ""))
6276               (use (match_operand:DI 2 "immediate_operand" ""))
6277               (use (match_operand:DI 3 "immediate_operand" ""))])]
6278   ""
6279 {
6280   if (alpha_expand_block_move (operands))
6281     DONE;
6282   else
6283     FAIL;
6284 })
6285
6286 (define_expand "clrstrqi"
6287   [(parallel [(set (match_operand:BLK 0 "memory_operand" "")
6288                    (const_int 0))
6289               (use (match_operand:DI 1 "immediate_operand" ""))
6290               (use (match_operand:DI 2 "immediate_operand" ""))])]
6291   ""
6292 {
6293   if (alpha_expand_block_clear (operands))
6294     DONE;
6295   else
6296     FAIL;
6297 })
6298 \f
6299 ;; Subroutine of stack space allocation.  Perform a stack probe.
6300 (define_expand "probe_stack"
6301   [(set (match_dup 1) (match_operand:DI 0 "const_int_operand" ""))]
6302   ""
6303 {
6304   operands[1] = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx,
6305                                                     INTVAL (operands[0])));
6306   MEM_VOLATILE_P (operands[1]) = 1;
6307
6308   operands[0] = const0_rtx;
6309 })
6310
6311 ;; This is how we allocate stack space.  If we are allocating a
6312 ;; constant amount of space and we know it is less than 4096
6313 ;; bytes, we need do nothing.
6314 ;;
6315 ;; If it is more than 4096 bytes, we need to probe the stack
6316 ;; periodically.
6317 (define_expand "allocate_stack"
6318   [(set (reg:DI 30)
6319         (plus:DI (reg:DI 30)
6320                  (match_operand:DI 1 "reg_or_cint_operand" "")))
6321    (set (match_operand:DI 0 "register_operand" "=r")
6322         (match_dup 2))]
6323   ""
6324 {
6325   if (GET_CODE (operands[1]) == CONST_INT
6326       && INTVAL (operands[1]) < 32768)
6327     {
6328       if (INTVAL (operands[1]) >= 4096)
6329         {
6330           /* We do this the same way as in the prologue and generate explicit
6331              probes.  Then we update the stack by the constant.  */
6332
6333           int probed = 4096;
6334
6335           emit_insn (gen_probe_stack (GEN_INT (- probed)));
6336           while (probed + 8192 < INTVAL (operands[1]))
6337             emit_insn (gen_probe_stack (GEN_INT (- (probed += 8192))));
6338
6339           if (probed + 4096 < INTVAL (operands[1]))
6340             emit_insn (gen_probe_stack (GEN_INT (- INTVAL(operands[1]))));
6341         }
6342
6343       operands[1] = GEN_INT (- INTVAL (operands[1]));
6344       operands[2] = virtual_stack_dynamic_rtx;
6345     }
6346   else
6347     {
6348       rtx out_label = 0;
6349       rtx loop_label = gen_label_rtx ();
6350       rtx want = gen_reg_rtx (Pmode);
6351       rtx tmp = gen_reg_rtx (Pmode);
6352       rtx memref;
6353
6354       emit_insn (gen_subdi3 (want, stack_pointer_rtx,
6355                              force_reg (Pmode, operands[1])));
6356       emit_insn (gen_adddi3 (tmp, stack_pointer_rtx, GEN_INT (-4096)));
6357
6358       if (GET_CODE (operands[1]) != CONST_INT)
6359         {
6360           out_label = gen_label_rtx ();
6361           emit_insn (gen_cmpdi (want, tmp));
6362           emit_jump_insn (gen_bgeu (out_label));
6363         }
6364
6365       emit_label (loop_label);
6366       memref = gen_rtx_MEM (DImode, tmp);
6367       MEM_VOLATILE_P (memref) = 1;
6368       emit_move_insn (memref, const0_rtx);
6369       emit_insn (gen_adddi3 (tmp, tmp, GEN_INT(-8192)));
6370       emit_insn (gen_cmpdi (tmp, want));
6371       emit_jump_insn (gen_bgtu (loop_label));
6372
6373       memref = gen_rtx_MEM (DImode, want);
6374       MEM_VOLATILE_P (memref) = 1;
6375       emit_move_insn (memref, const0_rtx);
6376
6377       if (out_label)
6378         emit_label (out_label);
6379
6380       emit_move_insn (stack_pointer_rtx, want);
6381       emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
6382       DONE;
6383     }
6384 })
6385
6386 ;; This is used by alpha_expand_prolog to do the same thing as above,
6387 ;; except we cannot at that time generate new basic blocks, so we hide
6388 ;; the loop in this one insn.
6389
6390 (define_insn "prologue_stack_probe_loop"
6391   [(unspec_volatile [(match_operand:DI 0 "register_operand" "r")
6392                      (match_operand:DI 1 "register_operand" "r")]
6393                     UNSPECV_PSPL)]
6394   ""
6395 {
6396   operands[2] = gen_label_rtx ();
6397   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L",
6398                              CODE_LABEL_NUMBER (operands[2]));
6399
6400   return "stq $31,-8192(%1)\;subq %0,1,%0\;lda %1,-8192(%1)\;bne %0,%l2";
6401 }
6402   [(set_attr "length" "16")
6403    (set_attr "type" "multi")])
6404
6405 (define_expand "prologue"
6406   [(clobber (const_int 0))]
6407   ""
6408 {
6409   alpha_expand_prologue ();
6410   DONE;
6411 })
6412
6413 ;; These take care of emitting the ldgp insn in the prologue. This will be
6414 ;; an lda/ldah pair and we want to align them properly.  So we have two
6415 ;; unspec_volatile insns, the first of which emits the ldgp assembler macro
6416 ;; and the second of which emits nothing.  However, both are marked as type
6417 ;; IADD (the default) so the alignment code in alpha.c does the right thing
6418 ;; with them.
6419
6420 (define_expand "prologue_ldgp"
6421   [(set (match_dup 0)
6422         (unspec_volatile:DI [(match_dup 1) (match_dup 2)] UNSPECV_LDGP1))
6423    (set (match_dup 0)
6424         (unspec_volatile:DI [(match_dup 0) (match_dup 2)] UNSPECV_PLDGP2))]
6425   ""
6426 {
6427   operands[0] = pic_offset_table_rtx;
6428   operands[1] = gen_rtx_REG (Pmode, 27);
6429   operands[2] = (TARGET_EXPLICIT_RELOCS
6430                  ? GEN_INT (alpha_next_sequence_number++)
6431                  : const0_rtx);
6432 })
6433
6434 (define_insn "*ldgp_er_1"
6435   [(set (match_operand:DI 0 "register_operand" "=r")
6436         (unspec_volatile:DI [(match_operand:DI 1 "register_operand" "r")
6437                              (match_operand 2 "const_int_operand" "")]
6438                             UNSPECV_LDGP1))]
6439   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
6440   "ldah %0,0(%1)\t\t!gpdisp!%2")
6441
6442 (define_insn "*ldgp_er_2"
6443   [(set (match_operand:DI 0 "register_operand" "=r")
6444         (unspec:DI [(match_operand:DI 1 "register_operand" "r")
6445                     (match_operand 2 "const_int_operand" "")]
6446                    UNSPEC_LDGP2))]
6447   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
6448   "lda %0,0(%1)\t\t!gpdisp!%2")
6449
6450 (define_insn "*prologue_ldgp_er_2"
6451   [(set (match_operand:DI 0 "register_operand" "=r")
6452         (unspec_volatile:DI [(match_operand:DI 1 "register_operand" "r")
6453                              (match_operand 2 "const_int_operand" "")]
6454                             UNSPECV_PLDGP2))]
6455   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
6456   "lda %0,0(%1)\t\t!gpdisp!%2\n$%~..ng:")
6457
6458 (define_insn "*prologue_ldgp_1"
6459   [(set (match_operand:DI 0 "register_operand" "=r")
6460         (unspec_volatile:DI [(match_operand:DI 1 "register_operand" "r")
6461                              (match_operand 2 "const_int_operand" "")]
6462                             UNSPECV_LDGP1))]
6463   ""
6464   "ldgp %0,0(%1)\n$%~..ng:")
6465
6466 (define_insn "*prologue_ldgp_2"
6467   [(set (match_operand:DI 0 "register_operand" "=r")
6468         (unspec_volatile:DI [(match_operand:DI 1 "register_operand" "r")
6469                              (match_operand 2 "const_int_operand" "")]
6470                             UNSPECV_PLDGP2))]
6471   ""
6472   "")
6473
6474 ;; The _mcount profiling hook has special calling conventions, and
6475 ;; does not clobber all the registers that a normal call would.  So
6476 ;; hide the fact this is a call at all.
6477
6478 (define_insn "prologue_mcount"
6479   [(unspec_volatile [(const_int 0)] UNSPECV_MCOUNT)]
6480   ""
6481   "lda $28,_mcount\;jsr $28,($28),_mcount"
6482   [(set_attr "type" "multi")
6483    (set_attr "length" "8")])
6484
6485 (define_insn "init_fp"
6486   [(set (match_operand:DI 0 "register_operand" "=r")
6487         (match_operand:DI 1 "register_operand" "r"))
6488    (clobber (mem:BLK (match_operand:DI 2 "register_operand" "=r")))]
6489   ""
6490   "bis $31,%1,%0")
6491
6492 (define_expand "epilogue"
6493   [(return)]
6494   ""
6495 {
6496   alpha_expand_epilogue ();
6497 })
6498
6499 (define_expand "sibcall_epilogue"
6500   [(return)]
6501   "TARGET_ABI_OSF"
6502 {
6503   alpha_expand_epilogue ();
6504   DONE;
6505 })
6506
6507 ;; In creating a large stack frame, NT _must_ use ldah+lda to load
6508 ;; the frame size into a register.  We use this pattern to ensure
6509 ;; we get lda instead of addq.
6510 (define_insn "nt_lda"
6511   [(set (match_operand:DI 0 "register_operand" "=r")
6512         (unspec:DI [(match_dup 0)
6513                     (match_operand:DI 1 "const_int_operand" "n")]
6514                    UNSPEC_NT_LDA))]
6515   ""
6516   "lda %0,%1(%0)")
6517
6518 (define_expand "builtin_longjmp"
6519   [(use (match_operand:DI 0 "register_operand" "r"))]
6520   "TARGET_ABI_OSF"
6521 {
6522   /* The elements of the buffer are, in order:  */
6523   rtx fp = gen_rtx_MEM (Pmode, operands[0]);
6524   rtx lab = gen_rtx_MEM (Pmode, plus_constant (operands[0], 8));
6525   rtx stack = gen_rtx_MEM (Pmode, plus_constant (operands[0], 16));
6526   rtx pv = gen_rtx_REG (Pmode, 27);
6527
6528   /* This bit is the same as expand_builtin_longjmp.  */
6529   emit_move_insn (hard_frame_pointer_rtx, fp);
6530   emit_move_insn (pv, lab);
6531   emit_stack_restore (SAVE_NONLOCAL, stack, NULL_RTX);
6532   emit_insn (gen_rtx_USE (VOIDmode, hard_frame_pointer_rtx));
6533   emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
6534
6535   /* Load the label we are jumping through into $27 so that we know
6536      where to look for it when we get back to setjmp's function for
6537      restoring the gp.  */
6538   emit_jump_insn (gen_builtin_longjmp_internal (pv));
6539   emit_barrier ();
6540   DONE;
6541 })
6542
6543 ;; This is effectively a copy of indirect_jump, but constrained such
6544 ;; that register renaming cannot foil our cunning plan with $27.
6545 (define_insn "builtin_longjmp_internal"
6546   [(set (pc)
6547         (unspec_volatile [(match_operand:DI 0 "register_operand" "c")]
6548                          UNSPECV_LONGJMP))]
6549   ""
6550   "jmp $31,(%0),0"
6551   [(set_attr "type" "ibr")])
6552
6553 (define_insn "*builtin_setjmp_receiver_er_sl_1"
6554   [(unspec_volatile [(label_ref (match_operand 0 "" ""))] UNSPECV_SETJMPR)]
6555   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF && TARGET_AS_CAN_SUBTRACT_LABELS"
6556   "lda $27,$LSJ%=-%l0($27)\n$LSJ%=:")
6557   
6558 (define_insn "*builtin_setjmp_receiver_er_1"
6559   [(unspec_volatile [(label_ref (match_operand 0 "" ""))] UNSPECV_SETJMPR)]
6560   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
6561   "br $27,$LSJ%=\n$LSJ%=:"
6562   [(set_attr "type" "ibr")])
6563
6564 (define_split
6565   [(unspec_volatile [(label_ref (match_operand 0 "" ""))] UNSPECV_SETJMPR)]
6566   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF
6567    && prev_nonnote_insn (insn) == operands[0]"
6568   [(const_int 0)]
6569   "DONE;")
6570
6571 (define_insn "*builtin_setjmp_receiver_1"
6572   [(unspec_volatile [(label_ref (match_operand 0 "" ""))] UNSPECV_SETJMPR)]
6573   "TARGET_ABI_OSF"
6574   "br $27,$LSJ%=\n$LSJ%=:\;ldgp $29,0($27)"
6575   [(set_attr "length" "12")
6576    (set_attr "type" "multi")])
6577
6578 (define_expand "builtin_setjmp_receiver_er"
6579   [(unspec_volatile [(label_ref (match_operand 0 "" ""))] UNSPECV_SETJMPR)
6580    (set (match_dup 1)
6581         (unspec_volatile:DI [(match_dup 2) (match_dup 3)] UNSPECV_LDGP1))
6582    (set (match_dup 1)
6583         (unspec:DI [(match_dup 1) (match_dup 3)] UNSPEC_LDGP2))]
6584   ""
6585 {
6586   operands[1] = pic_offset_table_rtx;
6587   operands[2] = gen_rtx_REG (Pmode, 27);
6588   operands[3] = GEN_INT (alpha_next_sequence_number++);
6589 })
6590
6591 (define_expand "builtin_setjmp_receiver"
6592   [(unspec_volatile [(label_ref (match_operand 0 "" ""))] UNSPECV_SETJMPR)]
6593   "TARGET_ABI_OSF"
6594 {
6595   if (TARGET_EXPLICIT_RELOCS)
6596     {
6597       emit_insn (gen_builtin_setjmp_receiver_er (operands[0]));
6598       DONE;
6599     }
6600 })
6601
6602 (define_expand "exception_receiver_er"
6603   [(set (match_dup 0)
6604         (unspec_volatile:DI [(match_dup 1) (match_dup 2)] UNSPECV_LDGP1))
6605    (set (match_dup 0)
6606         (unspec:DI [(match_dup 0) (match_dup 2)] UNSPEC_LDGP2))]
6607   ""
6608 {
6609   operands[0] = pic_offset_table_rtx;
6610   operands[1] = gen_rtx_REG (Pmode, 26);
6611   operands[2] = GEN_INT (alpha_next_sequence_number++);
6612 })
6613
6614 (define_expand "exception_receiver"
6615   [(unspec_volatile [(match_dup 0)] UNSPECV_EHR)]
6616   "TARGET_ABI_OSF"
6617 {
6618   if (TARGET_LD_BUGGY_LDGP)
6619     operands[0] = alpha_gp_save_rtx ();
6620   else if (TARGET_EXPLICIT_RELOCS)
6621     {
6622       emit_insn (gen_exception_receiver_er ());
6623       DONE;
6624     }
6625   else
6626     operands[0] = const0_rtx;
6627 })
6628
6629 (define_insn "*exception_receiver_1"
6630   [(unspec_volatile [(const_int 0)] UNSPECV_EHR)]
6631   "! TARGET_LD_BUGGY_LDGP"
6632   "ldgp $29,0($26)"
6633   [(set_attr "length" "8")
6634    (set_attr "type" "multi")])
6635
6636 (define_insn "*exception_receiver_2"
6637   [(unspec_volatile [(match_operand:DI 0 "nonimmediate_operand" "r,m")]
6638                     UNSPECV_EHR)]
6639   "TARGET_LD_BUGGY_LDGP"
6640   "@
6641    bis $31,%0,$29
6642    ldq $29,%0"
6643   [(set_attr "type" "ilog,ild")])
6644
6645 (define_expand "nonlocal_goto_receiver"
6646   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
6647    (set (reg:DI 27) (mem:DI (reg:DI 29)))
6648    (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
6649    (use (reg:DI 27))]
6650   "TARGET_ABI_OPEN_VMS"
6651   "")
6652
6653 (define_insn "arg_home"
6654   [(unspec [(const_int 0)] UNSPEC_ARG_HOME)
6655    (use (reg:DI 1))
6656    (use (reg:DI 25))
6657    (use (reg:DI 16))
6658    (use (reg:DI 17))
6659    (use (reg:DI 18))
6660    (use (reg:DI 19))
6661    (use (reg:DI 20))
6662    (use (reg:DI 21))
6663    (use (reg:DI 48))
6664    (use (reg:DI 49))
6665    (use (reg:DI 50))
6666    (use (reg:DI 51))
6667    (use (reg:DI 52))
6668    (use (reg:DI 53))
6669    (clobber (mem:BLK (const_int 0)))
6670    (clobber (reg:DI 24))
6671    (clobber (reg:DI 25))
6672    (clobber (reg:DI 0))]
6673   "TARGET_ABI_OPEN_VMS"
6674   "lda $0,OTS$HOME_ARGS\;ldq $0,8($0)\;jsr $0,OTS$HOME_ARGS"
6675   [(set_attr "length" "16")
6676    (set_attr "type" "multi")])
6677
6678 ;; Load the CIW into r2 for calling __T3E_MISMATCH
6679
6680 (define_expand "umk_mismatch_args"
6681   [(set:DI (match_dup 1) (mem:DI (plus:DI (reg:DI 15) (const_int -16))))
6682    (set:DI (match_dup 2) (mem:DI (plus:DI (match_dup 1) (const_int -32))))
6683    (set:DI (reg:DI 1) (match_operand:DI 0 "const_int_operand" ""))
6684    (set:DI (match_dup 3) (plus:DI (mult:DI (reg:DI 25)
6685                                            (const_int 8))
6686                                   (match_dup 2)))
6687    (set:DI (reg:DI 2) (mem:DI (match_dup 3)))]
6688   "TARGET_ABI_UNICOSMK"
6689 {
6690   operands[1] = gen_reg_rtx (DImode);
6691   operands[2] = gen_reg_rtx (DImode);
6692   operands[3] = gen_reg_rtx (DImode);
6693 })
6694
6695 (define_insn "arg_home_umk"
6696   [(unspec [(const_int 0)] UNSPEC_ARG_HOME)
6697    (use (reg:DI 1))
6698    (use (reg:DI 2))
6699    (use (reg:DI 16))
6700    (use (reg:DI 17))
6701    (use (reg:DI 18))
6702    (use (reg:DI 19))
6703    (use (reg:DI 20))
6704    (use (reg:DI 21))
6705    (use (reg:DI 48))
6706    (use (reg:DI 49))
6707    (use (reg:DI 50))
6708    (use (reg:DI 51))
6709    (use (reg:DI 52))
6710    (use (reg:DI 53))
6711    (clobber (mem:BLK (const_int 0)))
6712    (parallel [
6713    (clobber (reg:DI 22))
6714    (clobber (reg:DI 23))
6715    (clobber (reg:DI 24))
6716    (clobber (reg:DI 0))
6717    (clobber (reg:DI 1))
6718    (clobber (reg:DI 2))
6719    (clobber (reg:DI 3))
6720    (clobber (reg:DI 4))
6721    (clobber (reg:DI 5))
6722    (clobber (reg:DI 6))
6723    (clobber (reg:DI 7))
6724    (clobber (reg:DI 8))])]
6725   "TARGET_ABI_UNICOSMK"
6726   "laum $4,__T3E_MISMATCH($31)\;sll $4,32,$4\;lalm $4,__T3E_MISMATCH($4)\;lal $4,__T3E_MISMATCH($4)\;jsr $3,($4)"
6727   [(set_attr "length" "16")
6728    (set_attr "type" "multi")])
6729
6730 ;; Prefetch data.  
6731 ;;
6732 ;; On EV4, these instructions are nops -- no load occurs.
6733 ;;
6734 ;; On EV5, these instructions act as a normal load, and thus can trap
6735 ;; if the address is invalid.  The OS may (or may not) handle this in
6736 ;; the entMM fault handler and suppress the fault.  If so, then this
6737 ;; has the effect of a read prefetch instruction.
6738 ;;
6739 ;; On EV6, these become official prefetch instructions.
6740
6741 (define_insn "prefetch"
6742   [(prefetch (match_operand:DI 0 "address_operand" "p")
6743              (match_operand:DI 1 "const_int_operand" "n")
6744              (match_operand:DI 2 "const_int_operand" "n"))]
6745   "TARGET_FIXUP_EV5_PREFETCH || TARGET_CPU_EV6"
6746 {
6747   /* Interpret "no temporal locality" as this data should be evicted once
6748      it is used.  The "evict next" alternatives load the data into the cache
6749      and leave the LRU eviction counter pointing to that block.  */
6750   static const char * const alt[2][2] = {
6751     { 
6752       "lds $f31,%a0",           /* read, evict next */
6753       "ldl $31,%a0",            /* read, evict last */
6754     },
6755     {
6756       "ldt $f31,%a0",           /* write, evict next */
6757       "ldq $31,%a0",            /* write, evict last */
6758     }
6759   };
6760
6761   bool write = INTVAL (operands[1]) != 0;
6762   bool lru = INTVAL (operands[2]) != 0;
6763
6764   return alt[write][lru];
6765 }
6766   [(set_attr "type" "ild")])
6767
6768 ;; Close the trap shadow of preceding instructions.  This is generated
6769 ;; by alpha_reorg.
6770
6771 (define_insn "trapb"
6772   [(unspec_volatile [(const_int 0)] UNSPECV_TRAPB)]
6773   ""
6774   "trapb"
6775   [(set_attr "type" "misc")])
6776
6777 ;; No-op instructions used by machine-dependent reorg to preserve
6778 ;; alignment for instruction issue.
6779 ;; The Unicos/Mk assembler does not support these opcodes.
6780
6781 (define_insn "nop"
6782   [(const_int 0)]
6783   ""
6784   "bis $31,$31,$31"
6785   [(set_attr "type" "ilog")])
6786
6787 (define_insn "fnop"
6788   [(const_int 1)]
6789   "TARGET_FP"
6790   "cpys $f31,$f31,$f31"
6791   [(set_attr "type" "fcpys")])
6792
6793 (define_insn "unop"
6794   [(const_int 2)]
6795   ""
6796   "ldq_u $31,0($31)")
6797
6798 ;; On Unicos/Mk we use a macro for aligning code.
6799
6800 (define_insn "realign"
6801   [(unspec_volatile [(match_operand 0 "immediate_operand" "i")]
6802                     UNSPECV_REALIGN)]
6803   ""
6804 {
6805   if (TARGET_ABI_UNICOSMK)
6806     return "gcc@code@align %0";
6807   else
6808     return ".align %0 #realign";
6809 })
6810
6811 ;; The call patterns are at the end of the file because their
6812 ;; wildcard operand0 interferes with nice recognition.
6813
6814 (define_insn "*call_value_osf_1_er"
6815   [(set (match_operand 0 "" "")
6816         (call (mem:DI (match_operand:DI 1 "call_operand" "c,R,s"))
6817               (match_operand 2 "" "")))
6818    (use (reg:DI 29))
6819    (clobber (reg:DI 26))]
6820   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
6821   "@
6822    jsr $26,(%1),0\;ldah $29,0($26)\t\t!gpdisp!%*\;lda $29,0($29)\t\t!gpdisp!%*
6823    bsr $26,$%1..ng
6824    ldq $27,%1($29)\t\t!literal!%#\;jsr $26,($27),0\t\t!lituse_jsr!%#\;ldah $29,0($26)\t\t!gpdisp!%*\;lda $29,0($29)\t\t!gpdisp!%*"
6825   [(set_attr "type" "jsr")
6826    (set_attr "length" "12,*,16")])
6827
6828 ;; We must use peep2 instead of a split because we need accurate life
6829 ;; information for $gp.  Consider the case of { bar(); while (1); }.
6830 (define_peephole2
6831   [(parallel [(set (match_operand 0 "" "")
6832                    (call (mem:DI (match_operand:DI 1 "call_operand" ""))
6833                          (match_operand 2 "" "")))
6834               (use (reg:DI 29))
6835               (clobber (reg:DI 26))])]
6836   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF  && reload_completed
6837    && ! current_file_function_operand (operands[0], Pmode)
6838    && peep2_regno_dead_p (1, 29)"
6839   [(parallel [(set (match_dup 0)
6840                    (call (mem:DI (match_dup 3))
6841                          (match_dup 2)))
6842               (set (reg:DI 26) (plus:DI (pc) (const_int 4)))
6843               (unspec_volatile [(reg:DI 29)] UNSPECV_BLOCKAGE)
6844               (use (match_dup 1))])]
6845 {
6846   if (CONSTANT_P (operands[1]))
6847     {
6848       operands[3] = gen_rtx_REG (Pmode, 27);
6849       emit_move_insn (operands[3], operands[1]);
6850     }
6851   else
6852     {
6853       operands[3] = operands[1];
6854       operands[1] = const0_rtx;
6855     }
6856 })
6857
6858 (define_peephole2
6859   [(parallel [(set (match_operand 0 "" "")
6860                    (call (mem:DI (match_operand:DI 1 "call_operand" ""))
6861                          (match_operand 2 "" "")))
6862               (use (reg:DI 29))
6863               (clobber (reg:DI 26))])]
6864   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF  && reload_completed
6865    && ! current_file_function_operand (operands[0], Pmode)
6866    && ! peep2_regno_dead_p (1, 29)"
6867   [(parallel [(set (match_dup 0)
6868                    (call (mem:DI (match_dup 3))
6869                          (match_dup 2)))
6870               (set (reg:DI 26) (plus:DI (pc) (const_int 4)))
6871               (unspec_volatile [(reg:DI 29)] UNSPECV_BLOCKAGE)
6872               (use (match_dup 1))])
6873    (set (reg:DI 29)
6874         (unspec_volatile:DI [(reg:DI 26) (match_dup 4)] UNSPECV_LDGP1))
6875    (set (reg:DI 29)
6876         (unspec:DI [(reg:DI 29) (match_dup 4)] UNSPEC_LDGP2))]
6877 {
6878   if (CONSTANT_P (operands[1]))
6879     {
6880       operands[3] = gen_rtx_REG (Pmode, 27);
6881       emit_move_insn (operands[3], operands[1]);
6882     }
6883   else
6884     {
6885       operands[3] = operands[1];
6886       operands[1] = const0_rtx;
6887     }
6888   operands[4] = GEN_INT (alpha_next_sequence_number++);
6889 })
6890
6891 ;; We add a blockage unspec_volatile to prevent insns from moving down
6892 ;; from above the call to in between the call and the ldah gpdisp.
6893 (define_insn "*call_value_osf_2_er"
6894   [(set (match_operand 0 "" "")
6895         (call (mem:DI (match_operand:DI 1 "register_operand" "c"))
6896               (match_operand 2 "" "")))
6897    (set (reg:DI 26)
6898         (plus:DI (pc) (const_int 4)))
6899    (unspec_volatile [(reg:DI 29)] UNSPECV_BLOCKAGE)
6900    (use (match_operand 3 "" ""))]
6901   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
6902   "jsr $26,(%1),%3"
6903   [(set_attr "type" "jsr")])
6904
6905 (define_insn "*call_value_osf_1_noreturn"
6906   [(set (match_operand 0 "" "")
6907         (call (mem:DI (match_operand:DI 1 "call_operand" "c,R,s"))
6908               (match_operand 2 "" "")))
6909    (use (reg:DI 29))
6910    (clobber (reg:DI 26))]
6911   "! TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF
6912    && find_reg_note (insn, REG_NORETURN, NULL_RTX)"
6913   "@
6914    jsr $26,($27),0
6915    bsr $26,$%1..ng
6916    jsr $26,%1"
6917   [(set_attr "type" "jsr")
6918    (set_attr "length" "*,*,8")])
6919
6920 (define_insn "*call_value_osf_1"
6921   [(set (match_operand 0 "" "")
6922         (call (mem:DI (match_operand:DI 1 "call_operand" "c,R,s"))
6923               (match_operand 2 "" "")))
6924    (use (reg:DI 29))
6925    (clobber (reg:DI 26))]
6926   "! TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
6927   "@
6928    jsr $26,($27),0\;ldgp $29,0($26)
6929    bsr $26,$%1..ng
6930    jsr $26,%1\;ldgp $29,0($26)"
6931   [(set_attr "type" "jsr")
6932    (set_attr "length" "12,*,16")])
6933
6934 (define_insn "*sibcall_value_osf_1_er"
6935   [(set (match_operand 0 "" "")
6936         (call (mem:DI (match_operand:DI 1 "symbolic_operand" "R,s"))
6937               (match_operand 2 "" "")))
6938    (use (reg:DI 29))]
6939   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
6940   "@
6941    br $31,$%1..ng
6942    ldq $27,%1($29)\t\t!literal!%#\;jmp $31,($27),%1\t\t!lituse_jsr!%#"
6943   [(set_attr "type" "jsr")
6944    (set_attr "length" "*,8")])
6945
6946 (define_insn "*sibcall_value_osf_1"
6947   [(set (match_operand 0 "" "")
6948         (call (mem:DI (match_operand:DI 1 "symbolic_operand" "R,s"))
6949               (match_operand 2 "" "")))
6950    (use (reg:DI 29))]
6951   "! TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
6952   "@
6953    br $31,$%1..ng
6954    lda $27,%1\;jmp $31,($27),%1"
6955   [(set_attr "type" "jsr")
6956    (set_attr "length" "*,8")])
6957
6958 (define_insn "*call_value_nt_1"
6959   [(set (match_operand 0 "" "")
6960         (call (mem:DI (match_operand:DI 1 "call_operand" "r,R,s"))
6961               (match_operand 2 "" "")))
6962    (clobber (reg:DI 26))]
6963   "TARGET_ABI_WINDOWS_NT"
6964   "@
6965    jsr $26,(%1)
6966    bsr $26,%1
6967    jsr $26,%1"
6968   [(set_attr "type" "jsr")
6969    (set_attr "length" "*,*,12")])
6970
6971 (define_insn "*call_value_vms_1"
6972   [(set (match_operand 0 "" "")
6973         (call (mem:DI (match_operand:DI 1 "call_operand" "r,s"))
6974               (match_operand 2 "" "")))
6975    (use (match_operand:DI 3 "nonimmediate_operand" "r,m"))
6976    (use (reg:DI 25))
6977    (use (reg:DI 26))
6978    (clobber (reg:DI 27))]
6979   "TARGET_ABI_OPEN_VMS"
6980   "@
6981    mov %3,$27\;jsr $26,0\;ldq $27,0($29)
6982    ldq $27,%3\;jsr $26,%1\;ldq $27,0($29)"
6983   [(set_attr "type" "jsr")
6984    (set_attr "length" "12,16")])
6985
6986 (define_insn "*call_value_umk"
6987   [(set (match_operand 0 "" "")
6988         (call (mem:DI (match_operand:DI 1 "call_operand" "r"))
6989               (match_operand 2 "" "")))
6990    (use (reg:DI 25))
6991    (clobber (reg:DI 26))]
6992   "TARGET_ABI_UNICOSMK"
6993   "jsr $26,(%1)"
6994   [(set_attr "type" "jsr")])
6995