OSDN Git Service

* real.c: Update copyright date.
[pf3gnuchains/gcc-fork.git] / gcc / config / rs6000 / rs6000.md
1 ;; Machine description for IBM RISC System 6000 (POWER) for GNU C compiler
2 ;; Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 ;; 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4 ;; Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
5
6 ;; This file is part of GCC.
7
8 ;; GCC is free software; you can redistribute it and/or modify it
9 ;; under the terms of the GNU General Public License as published
10 ;; by the Free Software Foundation; either version 2, or (at your
11 ;; option) any later version.
12
13 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
14 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16 ;; License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING.  If not, write to the
20 ;; Free Software Foundation, 59 Temple Place - Suite 330, Boston,
21 ;; MA 02111-1307, USA.
22
23 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
24
25 ;;
26 ;; UNSPEC usage
27 ;;
28
29 (define_constants
30   [(UNSPEC_FRSP                 0)      ; frsp for POWER machines
31    (UNSPEC_TIE                  5)      ; tie stack contents and stack pointer
32    (UNSPEC_TOCPTR               6)      ; address of a word pointing to the TOC
33    (UNSPEC_TOC                  7)      ; address of the TOC (more-or-less)
34    (UNSPEC_MOVSI_GOT            8)
35    (UNSPEC_MV_CR_OV             9)      ; move_from_CR_ov_bit
36    (UNSPEC_FCTIWZ               10)
37    (UNSPEC_LD_MPIC              15)     ; load_macho_picbase
38    (UNSPEC_MPIC_CORRECT         16)     ; macho_correct_pic
39    (UNSPEC_TLSGD                17)
40    (UNSPEC_TLSLD                18)
41    (UNSPEC_MOVESI_FROM_CR       19)
42    (UNSPEC_MOVESI_TO_CR         20)
43    (UNSPEC_TLSDTPREL            21)
44    (UNSPEC_TLSDTPRELHA          22)
45    (UNSPEC_TLSDTPRELLO          23)
46    (UNSPEC_TLSGOTDTPREL         24)
47    (UNSPEC_TLSTPREL             25)
48    (UNSPEC_TLSTPRELHA           26)
49    (UNSPEC_TLSTPRELLO           27)
50    (UNSPEC_TLSGOTTPREL          28)
51    (UNSPEC_TLSTLS               29)
52    (UNSPEC_FIX_TRUNC_TF         30)     ; fadd, rounding towards zero
53   ])
54
55 ;;
56 ;; UNSPEC_VOLATILE usage
57 ;;
58
59 (define_constants
60   [(UNSPECV_BLOCK               0)
61    (UNSPECV_EH_RR               9)      ; eh_reg_restore
62   ])
63 \f
64 ;; Define an insn type attribute.  This is used in function unit delay
65 ;; computations.
66 (define_attr "type" "integer,load,load_ext,load_ext_u,load_ext_ux,load_ux,load_u,store,store_ux,store_u,fpload,fpload_ux,fpload_u,fpstore,fpstore_ux,fpstore_u,vecload,vecstore,imul,imul2,imul3,lmul,idiv,ldiv,insert_word,branch,cmp,fast_compare,compare,delayed_compare,imul_compare,lmul_compare,fpcompare,cr_logical,delayed_cr,mfcr,mfcrf,mtcr,mfjmpr,mtjmpr,fp,fpsimple,dmul,sdiv,ddiv,ssqrt,dsqrt,jmpreg,brinc,vecsimple,veccomplex,vecdiv,veccmp,veccmpsimple,vecperm,vecfloat,vecfdiv"
67   (const_string "integer"))
68
69 ;; Length (in bytes).
70 ; '(pc)' in the following doesn't include the instruction itself; it is 
71 ; calculated as if the instruction had zero size.
72 (define_attr "length" ""
73   (if_then_else (eq_attr "type" "branch")
74                 (if_then_else (and (ge (minus (match_dup 0) (pc))
75                                        (const_int -32768))
76                                    (lt (minus (match_dup 0) (pc))
77                                        (const_int 32764)))
78                               (const_int 4)
79                               (const_int 8))
80                 (const_int 4)))
81
82 ;; Processor type -- this attribute must exactly match the processor_type
83 ;; enumeration in rs6000.h.
84
85 (define_attr "cpu" "rios1,rios2,rs64a,mpccore,ppc403,ppc405,ppc440,ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630,ppc750,ppc7400,ppc7450,ppc8540,power4"
86   (const (symbol_ref "rs6000_cpu_attr")))
87
88 (automata_option "ndfa")
89
90 (include "rios1.md")
91 (include "rios2.md")
92 (include "rs64.md")
93 (include "mpc.md")
94 (include "40x.md")
95 (include "440.md")
96 (include "603.md")
97 (include "6xx.md")
98 (include "7xx.md")
99 (include "7450.md")
100 (include "8540.md")
101 (include "power4.md")
102
103 \f
104 ;; Start with fixed-point load and store insns.  Here we put only the more
105 ;; complex forms.  Basic data transfer is done later.
106
107 (define_expand "zero_extendqidi2"
108   [(set (match_operand:DI 0 "gpc_reg_operand" "")
109         (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "")))]
110   "TARGET_POWERPC64"
111   "")
112
113 (define_insn ""
114   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
115         (zero_extend:DI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
116   "TARGET_POWERPC64"
117   "@
118    lbz%U1%X1 %0,%1
119    rldicl %0,%1,0,56"
120   [(set_attr "type" "load,*")])
121
122 (define_insn ""
123   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
124         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
125                     (const_int 0)))
126    (clobber (match_scratch:DI 2 "=r,r"))]
127   "TARGET_64BIT"
128   "@
129    rldicl. %2,%1,0,56
130    #"
131   [(set_attr "type" "compare")
132    (set_attr "length" "4,8")])
133
134 (define_split
135   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
136         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
137                     (const_int 0)))
138    (clobber (match_scratch:DI 2 ""))]
139   "TARGET_POWERPC64 && reload_completed"
140   [(set (match_dup 2)
141         (zero_extend:DI (match_dup 1)))
142    (set (match_dup 0)
143         (compare:CC (match_dup 2)
144                     (const_int 0)))]
145   "")
146
147 (define_insn ""
148   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
149         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
150                     (const_int 0)))
151    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
152         (zero_extend:DI (match_dup 1)))]
153   "TARGET_64BIT"
154   "@
155    rldicl. %0,%1,0,56
156    #"
157   [(set_attr "type" "compare")
158    (set_attr "length" "4,8")])
159
160 (define_split
161   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
162         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
163                     (const_int 0)))
164    (set (match_operand:DI 0 "gpc_reg_operand" "")
165         (zero_extend:DI (match_dup 1)))]
166   "TARGET_POWERPC64 && reload_completed"
167   [(set (match_dup 0)
168         (zero_extend:DI (match_dup 1)))
169    (set (match_dup 2)
170         (compare:CC (match_dup 0)
171                     (const_int 0)))]
172   "")
173
174 (define_insn "extendqidi2"
175   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
176         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
177   "TARGET_POWERPC64"
178   "extsb %0,%1")
179
180 (define_insn ""
181   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
182         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
183                     (const_int 0)))
184    (clobber (match_scratch:DI 2 "=r,r"))]
185   "TARGET_64BIT"
186   "@
187    extsb. %2,%1
188    #"
189   [(set_attr "type" "compare")
190    (set_attr "length" "4,8")])
191
192 (define_split
193   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
194         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
195                     (const_int 0)))
196    (clobber (match_scratch:DI 2 ""))]
197   "TARGET_POWERPC64 && reload_completed"
198   [(set (match_dup 2)
199         (sign_extend:DI (match_dup 1)))
200    (set (match_dup 0)
201         (compare:CC (match_dup 2)
202                     (const_int 0)))]
203   "")
204
205 (define_insn ""
206   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
207         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
208                     (const_int 0)))
209    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
210         (sign_extend:DI (match_dup 1)))]
211   "TARGET_64BIT"
212   "@
213    extsb. %0,%1
214    #"
215   [(set_attr "type" "compare")
216    (set_attr "length" "4,8")])
217
218 (define_split
219   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
220         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
221                     (const_int 0)))
222    (set (match_operand:DI 0 "gpc_reg_operand" "")
223         (sign_extend:DI (match_dup 1)))]
224   "TARGET_POWERPC64 && reload_completed"
225   [(set (match_dup 0)
226         (sign_extend:DI (match_dup 1)))
227    (set (match_dup 2)
228         (compare:CC (match_dup 0)
229                     (const_int 0)))]
230   "")
231
232 (define_expand "zero_extendhidi2"
233   [(set (match_operand:DI 0 "gpc_reg_operand" "")
234         (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
235   "TARGET_POWERPC64"
236   "")
237
238 (define_insn ""
239   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
240         (zero_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
241   "TARGET_POWERPC64"
242   "@
243    lhz%U1%X1 %0,%1
244    rldicl %0,%1,0,48"
245   [(set_attr "type" "load,*")])
246
247 (define_insn ""
248   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
249         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
250                     (const_int 0)))
251    (clobber (match_scratch:DI 2 "=r,r"))]
252   "TARGET_64BIT"
253   "@
254    rldicl. %2,%1,0,48
255    #"
256   [(set_attr "type" "compare")
257    (set_attr "length" "4,8")])
258
259 (define_split
260   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
261         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
262                     (const_int 0)))
263    (clobber (match_scratch:DI 2 ""))]
264   "TARGET_POWERPC64 && reload_completed"
265   [(set (match_dup 2)
266         (zero_extend:DI (match_dup 1)))
267    (set (match_dup 0)
268         (compare:CC (match_dup 2)
269                     (const_int 0)))]
270   "")
271
272 (define_insn ""
273   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
274         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
275                     (const_int 0)))
276    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
277         (zero_extend:DI (match_dup 1)))]
278   "TARGET_64BIT"
279   "@
280    rldicl. %0,%1,0,48
281    #"
282   [(set_attr "type" "compare")
283    (set_attr "length" "4,8")])
284
285 (define_split
286   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
287         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
288                     (const_int 0)))
289    (set (match_operand:DI 0 "gpc_reg_operand" "")
290         (zero_extend:DI (match_dup 1)))]
291   "TARGET_POWERPC64 && reload_completed"
292   [(set (match_dup 0)
293         (zero_extend:DI (match_dup 1)))
294    (set (match_dup 2)
295         (compare:CC (match_dup 0)
296                     (const_int 0)))]
297   "")
298
299 (define_expand "extendhidi2"
300   [(set (match_operand:DI 0 "gpc_reg_operand" "")
301         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
302   "TARGET_POWERPC64"
303   "")
304
305 (define_insn ""
306   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
307         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
308   "TARGET_POWERPC64"
309   "@
310    lha%U1%X1 %0,%1
311    extsh %0,%1"
312   [(set_attr "type" "load_ext,*")])
313
314 (define_insn ""
315   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
316         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
317                     (const_int 0)))
318    (clobber (match_scratch:DI 2 "=r,r"))]
319   "TARGET_64BIT"
320   "@
321    extsh. %2,%1
322    #"
323   [(set_attr "type" "compare")
324    (set_attr "length" "4,8")])
325
326 (define_split
327   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
328         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
329                     (const_int 0)))
330    (clobber (match_scratch:DI 2 ""))]
331   "TARGET_POWERPC64 && reload_completed"
332   [(set (match_dup 2)
333         (sign_extend:DI (match_dup 1)))
334    (set (match_dup 0)
335         (compare:CC (match_dup 2)
336                     (const_int 0)))]
337   "")
338
339 (define_insn ""
340   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
341         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
342                     (const_int 0)))
343    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
344         (sign_extend:DI (match_dup 1)))]
345   "TARGET_64BIT"
346   "@
347    extsh. %0,%1
348    #"
349   [(set_attr "type" "compare")
350    (set_attr "length" "4,8")])
351
352 (define_split
353   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
354         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
355                     (const_int 0)))
356    (set (match_operand:DI 0 "gpc_reg_operand" "")
357         (sign_extend:DI (match_dup 1)))]
358   "TARGET_POWERPC64 && reload_completed"
359   [(set (match_dup 0)
360         (sign_extend:DI (match_dup 1)))
361    (set (match_dup 2)
362         (compare:CC (match_dup 0)
363                     (const_int 0)))]
364   "")
365
366 (define_expand "zero_extendsidi2"
367   [(set (match_operand:DI 0 "gpc_reg_operand" "")
368         (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
369   "TARGET_POWERPC64"
370   "")
371
372 (define_insn ""
373   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
374         (zero_extend:DI (match_operand:SI 1 "reg_or_mem_operand" "m,r")))]
375   "TARGET_POWERPC64"
376   "@
377    lwz%U1%X1 %0,%1
378    rldicl %0,%1,0,32"
379   [(set_attr "type" "load,*")])
380
381 (define_insn ""
382   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
383         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
384                     (const_int 0)))
385    (clobber (match_scratch:DI 2 "=r,r"))]
386   "TARGET_64BIT"
387   "@
388    rldicl. %2,%1,0,32
389    #"
390   [(set_attr "type" "compare")
391    (set_attr "length" "4,8")])
392
393 (define_split
394   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
395         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
396                     (const_int 0)))
397    (clobber (match_scratch:DI 2 ""))]
398   "TARGET_POWERPC64 && reload_completed"
399   [(set (match_dup 2)
400         (zero_extend:DI (match_dup 1)))
401    (set (match_dup 0)
402         (compare:CC (match_dup 2)
403                     (const_int 0)))]
404   "")
405
406 (define_insn ""
407   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
408         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
409                     (const_int 0)))
410    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
411         (zero_extend:DI (match_dup 1)))]
412   "TARGET_64BIT"
413   "@
414    rldicl. %0,%1,0,32
415    #"
416   [(set_attr "type" "compare")
417    (set_attr "length" "4,8")])
418
419 (define_split
420   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
421         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
422                     (const_int 0)))
423    (set (match_operand:DI 0 "gpc_reg_operand" "")
424         (zero_extend:DI (match_dup 1)))]
425   "TARGET_POWERPC64 && reload_completed"
426   [(set (match_dup 0)
427         (zero_extend:DI (match_dup 1)))
428    (set (match_dup 2)
429         (compare:CC (match_dup 0)
430                     (const_int 0)))]
431   "")
432
433 (define_expand "extendsidi2"
434   [(set (match_operand:DI 0 "gpc_reg_operand" "")
435         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
436   "TARGET_POWERPC64"
437   "")
438
439 (define_insn ""
440   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
441         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
442   "TARGET_POWERPC64"
443   "@
444    lwa%U1%X1 %0,%1
445    extsw %0,%1"
446   [(set_attr "type" "load_ext,*")])
447
448 (define_insn ""
449   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
450         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
451                     (const_int 0)))
452    (clobber (match_scratch:DI 2 "=r,r"))]
453   "TARGET_64BIT"
454   "@
455    extsw. %2,%1
456    #"
457   [(set_attr "type" "compare")
458    (set_attr "length" "4,8")])
459
460 (define_split
461   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
462         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
463                     (const_int 0)))
464    (clobber (match_scratch:DI 2 ""))]
465   "TARGET_POWERPC64 && reload_completed"
466   [(set (match_dup 2)
467         (sign_extend:DI (match_dup 1)))
468    (set (match_dup 0)
469         (compare:CC (match_dup 2)
470                     (const_int 0)))]
471   "")
472
473 (define_insn ""
474   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
475         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
476                     (const_int 0)))
477    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
478         (sign_extend:DI (match_dup 1)))]
479   "TARGET_64BIT"
480   "@
481    extsw. %0,%1
482    #"
483   [(set_attr "type" "compare")
484    (set_attr "length" "4,8")])
485
486 (define_split
487   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
488         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
489                     (const_int 0)))
490    (set (match_operand:DI 0 "gpc_reg_operand" "")
491         (sign_extend:DI (match_dup 1)))]
492   "TARGET_POWERPC64 && reload_completed"
493   [(set (match_dup 0)
494         (sign_extend:DI (match_dup 1)))
495    (set (match_dup 2)
496         (compare:CC (match_dup 0)
497                     (const_int 0)))]
498   "")
499
500 (define_expand "zero_extendqisi2"
501   [(set (match_operand:SI 0 "gpc_reg_operand" "")
502         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
503   ""
504   "")
505
506 (define_insn ""
507   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
508         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
509   ""
510   "@
511    lbz%U1%X1 %0,%1
512    {rlinm|rlwinm} %0,%1,0,0xff"
513   [(set_attr "type" "load,*")])
514
515 (define_insn ""
516   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
517         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
518                     (const_int 0)))
519    (clobber (match_scratch:SI 2 "=r,r"))]
520   ""
521   "@
522    {andil.|andi.} %2,%1,0xff
523    #"
524   [(set_attr "type" "compare")
525    (set_attr "length" "4,8")])
526
527 (define_split
528   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
529         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
530                     (const_int 0)))
531    (clobber (match_scratch:SI 2 ""))]
532   "reload_completed"
533   [(set (match_dup 2)
534         (zero_extend:SI (match_dup 1)))
535    (set (match_dup 0)
536         (compare:CC (match_dup 2)
537                     (const_int 0)))]
538   "")
539
540 (define_insn ""
541   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
542         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
543                     (const_int 0)))
544    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
545         (zero_extend:SI (match_dup 1)))]
546   ""
547   "@
548    {andil.|andi.} %0,%1,0xff
549    #"
550   [(set_attr "type" "compare")
551    (set_attr "length" "4,8")])
552
553 (define_split
554   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
555         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
556                     (const_int 0)))
557    (set (match_operand:SI 0 "gpc_reg_operand" "")
558         (zero_extend:SI (match_dup 1)))]
559   "reload_completed"
560   [(set (match_dup 0)
561         (zero_extend:SI (match_dup 1)))
562    (set (match_dup 2)
563         (compare:CC (match_dup 0)
564                     (const_int 0)))]
565   "")
566
567 (define_expand "extendqisi2"
568   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
569    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
570   ""
571   "
572 {
573   if (TARGET_POWERPC)
574     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
575   else if (TARGET_POWER)
576     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
577   else
578     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
579   DONE;
580 }")
581
582 (define_insn "extendqisi2_ppc"
583   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
584         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
585   "TARGET_POWERPC"
586   "extsb %0,%1")
587
588 (define_insn ""
589   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
590         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
591                     (const_int 0)))
592    (clobber (match_scratch:SI 2 "=r,r"))]
593   "TARGET_POWERPC"
594   "@
595    extsb. %2,%1
596    #"
597   [(set_attr "type" "compare")
598    (set_attr "length" "4,8")])
599
600 (define_split
601   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
602         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
603                     (const_int 0)))
604    (clobber (match_scratch:SI 2 ""))]
605   "TARGET_POWERPC && reload_completed"
606   [(set (match_dup 2)
607         (sign_extend:SI (match_dup 1)))
608    (set (match_dup 0)
609         (compare:CC (match_dup 2)
610                     (const_int 0)))]
611   "")
612
613 (define_insn ""
614   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
615         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
616                     (const_int 0)))
617    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
618         (sign_extend:SI (match_dup 1)))]
619   "TARGET_POWERPC"
620   "@
621    extsb. %0,%1
622    #"
623   [(set_attr "type" "compare")
624    (set_attr "length" "4,8")])
625
626 (define_split
627   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
628         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
629                     (const_int 0)))
630    (set (match_operand:SI 0 "gpc_reg_operand" "")
631         (sign_extend:SI (match_dup 1)))]
632   "TARGET_POWERPC && reload_completed"
633   [(set (match_dup 0)
634         (sign_extend:SI (match_dup 1)))
635    (set (match_dup 2)
636         (compare:CC (match_dup 0)
637                     (const_int 0)))]
638   "")
639
640 (define_expand "extendqisi2_power"
641   [(parallel [(set (match_dup 2)
642                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
643                               (const_int 24)))
644               (clobber (scratch:SI))])
645    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
646                    (ashiftrt:SI (match_dup 2)
647                                 (const_int 24)))
648               (clobber (scratch:SI))])]
649   "TARGET_POWER"
650   "
651 { operands[1] = gen_lowpart (SImode, operands[1]);
652   operands[2] = gen_reg_rtx (SImode); }")
653
654 (define_expand "extendqisi2_no_power"
655   [(set (match_dup 2)
656         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
657                    (const_int 24)))
658    (set (match_operand:SI 0 "gpc_reg_operand" "")
659         (ashiftrt:SI (match_dup 2)
660                      (const_int 24)))]
661   "! TARGET_POWER && ! TARGET_POWERPC"
662   "
663 { operands[1] = gen_lowpart (SImode, operands[1]);
664   operands[2] = gen_reg_rtx (SImode); }")
665
666 (define_expand "zero_extendqihi2"
667   [(set (match_operand:HI 0 "gpc_reg_operand" "")
668         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
669   ""
670   "")
671
672 (define_insn ""
673   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
674         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
675   ""
676   "@
677    lbz%U1%X1 %0,%1
678    {rlinm|rlwinm} %0,%1,0,0xff"
679   [(set_attr "type" "load,*")])
680
681 (define_insn ""
682   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
683         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
684                     (const_int 0)))
685    (clobber (match_scratch:HI 2 "=r,r"))]
686   ""
687   "@
688    {andil.|andi.} %2,%1,0xff
689    #"
690   [(set_attr "type" "compare")
691    (set_attr "length" "4,8")])
692
693 (define_split
694   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
695         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
696                     (const_int 0)))
697    (clobber (match_scratch:HI 2 ""))]
698   "reload_completed"
699   [(set (match_dup 2)
700         (zero_extend:HI (match_dup 1)))
701    (set (match_dup 0)
702         (compare:CC (match_dup 2)
703                     (const_int 0)))]
704   "")
705
706 (define_insn ""
707   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
708         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
709                     (const_int 0)))
710    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
711         (zero_extend:HI (match_dup 1)))]
712   ""
713   "@
714    {andil.|andi.} %0,%1,0xff
715    #"
716   [(set_attr "type" "compare")
717    (set_attr "length" "4,8")])
718
719 (define_split
720   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
721         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
722                     (const_int 0)))
723    (set (match_operand:HI 0 "gpc_reg_operand" "")
724         (zero_extend:HI (match_dup 1)))]
725   "reload_completed"
726   [(set (match_dup 0)
727         (zero_extend:HI (match_dup 1)))
728    (set (match_dup 2)
729         (compare:CC (match_dup 0)
730                     (const_int 0)))]
731   "")
732
733 (define_expand "extendqihi2"
734   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
735    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
736   ""
737   "
738 {
739   if (TARGET_POWERPC)
740     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
741   else if (TARGET_POWER)
742     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
743   else
744     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
745   DONE;
746 }")
747
748 (define_insn "extendqihi2_ppc"
749   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
750         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
751   "TARGET_POWERPC"
752   "extsb %0,%1")
753
754 (define_insn ""
755   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
756         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
757                     (const_int 0)))
758    (clobber (match_scratch:HI 2 "=r,r"))]
759   "TARGET_POWERPC"
760   "@
761    extsb. %2,%1
762    #"
763   [(set_attr "type" "compare")
764    (set_attr "length" "4,8")])
765
766 (define_split
767   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
768         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
769                     (const_int 0)))
770    (clobber (match_scratch:HI 2 ""))]
771   "TARGET_POWERPC && reload_completed"
772   [(set (match_dup 2)
773         (sign_extend:HI (match_dup 1)))
774    (set (match_dup 0)
775         (compare:CC (match_dup 2)
776                     (const_int 0)))]
777   "")
778
779 (define_insn ""
780   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
781         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
782                     (const_int 0)))
783    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
784         (sign_extend:HI (match_dup 1)))]
785   "TARGET_POWERPC"
786   "@
787    extsb. %0,%1
788    #"
789   [(set_attr "type" "compare")
790    (set_attr "length" "4,8")])
791
792 (define_split
793   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
794         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
795                     (const_int 0)))
796    (set (match_operand:HI 0 "gpc_reg_operand" "")
797         (sign_extend:HI (match_dup 1)))]
798   "TARGET_POWERPC && reload_completed"
799   [(set (match_dup 0)
800         (sign_extend:HI (match_dup 1)))
801    (set (match_dup 2)
802         (compare:CC (match_dup 0)
803                     (const_int 0)))]
804   "")
805
806 (define_expand "extendqihi2_power"
807   [(parallel [(set (match_dup 2)
808                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
809                               (const_int 24)))
810               (clobber (scratch:SI))])
811    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
812                    (ashiftrt:SI (match_dup 2)
813                                 (const_int 24)))
814               (clobber (scratch:SI))])]
815   "TARGET_POWER"
816   "
817 { operands[0] = gen_lowpart (SImode, operands[0]);
818   operands[1] = gen_lowpart (SImode, operands[1]);
819   operands[2] = gen_reg_rtx (SImode); }")
820
821 (define_expand "extendqihi2_no_power"
822   [(set (match_dup 2)
823         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
824                    (const_int 24)))
825    (set (match_operand:HI 0 "gpc_reg_operand" "")
826         (ashiftrt:SI (match_dup 2)
827                      (const_int 24)))]
828   "! TARGET_POWER && ! TARGET_POWERPC"
829   "
830 { operands[0] = gen_lowpart (SImode, operands[0]);
831   operands[1] = gen_lowpart (SImode, operands[1]);
832   operands[2] = gen_reg_rtx (SImode); }")
833
834 (define_expand "zero_extendhisi2"
835   [(set (match_operand:SI 0 "gpc_reg_operand" "")
836         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
837   ""
838   "")
839
840 (define_insn ""
841   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
842         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
843   ""
844   "@
845    lhz%U1%X1 %0,%1
846    {rlinm|rlwinm} %0,%1,0,0xffff"
847   [(set_attr "type" "load,*")])
848
849 (define_insn ""
850   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
851         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
852                     (const_int 0)))
853    (clobber (match_scratch:SI 2 "=r,r"))]
854   ""
855   "@
856    {andil.|andi.} %2,%1,0xffff
857    #"
858   [(set_attr "type" "compare")
859    (set_attr "length" "4,8")])
860
861 (define_split
862   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
863         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
864                     (const_int 0)))
865    (clobber (match_scratch:SI 2 ""))]
866   "reload_completed"
867   [(set (match_dup 2)
868         (zero_extend:SI (match_dup 1)))
869    (set (match_dup 0)
870         (compare:CC (match_dup 2)
871                     (const_int 0)))]
872   "")
873
874 (define_insn ""
875   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
876         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
877                     (const_int 0)))
878    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
879         (zero_extend:SI (match_dup 1)))]
880   ""
881   "@
882    {andil.|andi.} %0,%1,0xffff
883    #"
884   [(set_attr "type" "compare")
885    (set_attr "length" "4,8")])
886
887 (define_split
888   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
889         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
890                     (const_int 0)))
891    (set (match_operand:SI 0 "gpc_reg_operand" "")
892         (zero_extend:SI (match_dup 1)))]
893   "reload_completed"
894   [(set (match_dup 0)
895         (zero_extend:SI (match_dup 1)))
896    (set (match_dup 2)
897         (compare:CC (match_dup 0)
898                     (const_int 0)))]
899   "")
900
901 (define_expand "extendhisi2"
902   [(set (match_operand:SI 0 "gpc_reg_operand" "")
903         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
904   ""
905   "")
906
907 (define_insn ""
908   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
909         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
910   ""
911   "@
912    lha%U1%X1 %0,%1
913    {exts|extsh} %0,%1"
914   [(set_attr "type" "load_ext,*")])
915
916 (define_insn ""
917   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
918         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
919                     (const_int 0)))
920    (clobber (match_scratch:SI 2 "=r,r"))]
921   ""
922   "@
923    {exts.|extsh.} %2,%1
924    #"
925   [(set_attr "type" "compare")
926    (set_attr "length" "4,8")])
927
928 (define_split
929   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
930         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
931                     (const_int 0)))
932    (clobber (match_scratch:SI 2 ""))]
933   "reload_completed"
934   [(set (match_dup 2)
935         (sign_extend:SI (match_dup 1)))
936    (set (match_dup 0)
937         (compare:CC (match_dup 2)
938                     (const_int 0)))]
939   "")
940
941 (define_insn ""
942   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
943         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
944                     (const_int 0)))
945    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
946         (sign_extend:SI (match_dup 1)))]
947   ""
948   "@
949    {exts.|extsh.} %0,%1
950    #"
951   [(set_attr "type" "compare")
952    (set_attr "length" "4,8")])
953 \f
954 (define_split
955   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
956         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
957                     (const_int 0)))
958    (set (match_operand:SI 0 "gpc_reg_operand" "")
959         (sign_extend:SI (match_dup 1)))]
960   "reload_completed"
961   [(set (match_dup 0)
962         (sign_extend:SI (match_dup 1)))
963    (set (match_dup 2)
964         (compare:CC (match_dup 0)
965                     (const_int 0)))]
966   "")
967
968 ;; Fixed-point arithmetic insns.
969
970 ;; Discourage ai/addic because of carry but provide it in an alternative
971 ;; allowing register zero as source.
972 (define_expand "addsi3"
973   [(set (match_operand:SI 0 "gpc_reg_operand" "")
974         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
975                  (match_operand:SI 2 "reg_or_arith_cint_operand" "")))]
976   ""
977   "
978 {
979   if (GET_CODE (operands[2]) == CONST_INT
980                 && ! add_operand (operands[2], SImode))
981     {
982       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
983                  ? operands[0] : gen_reg_rtx (SImode));
984
985       HOST_WIDE_INT val = INTVAL (operands[2]);
986       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
987       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, SImode);
988
989       /* The ordering here is important for the prolog expander.
990          When space is allocated from the stack, adding 'low' first may
991          produce a temporary deallocation (which would be bad).  */
992       emit_insn (gen_addsi3 (tmp, operands[1], GEN_INT (rest)));
993       emit_insn (gen_addsi3 (operands[0], tmp, GEN_INT (low)));
994       DONE;
995     }
996 }")
997
998 (define_insn "*addsi3_internal1"
999   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,?r,r")
1000         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,b,r,b")
1001                  (match_operand:SI 2 "add_operand" "r,I,I,L")))]
1002   ""
1003   "@
1004    {cax|add} %0,%1,%2
1005    {cal %0,%2(%1)|addi %0,%1,%2}
1006    {ai|addic} %0,%1,%2
1007    {cau|addis} %0,%1,%v2"
1008   [(set_attr "length" "4,4,4,4")])
1009
1010 (define_insn "addsi3_high"
1011   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1012         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1013                  (high:SI (match_operand 2 "" ""))))]
1014   "TARGET_MACHO && !TARGET_64BIT"
1015   "{cau|addis} %0,%1,ha16(%2)"
1016   [(set_attr "length" "4")])
1017
1018 (define_insn "*addsi3_internal2"
1019   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1020         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1021                              (match_operand:SI 2 "reg_or_short_operand" "r,I,r,I"))
1022                     (const_int 0)))
1023    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
1024   "TARGET_32BIT"
1025   "@
1026    {cax.|add.} %3,%1,%2
1027    {ai.|addic.} %3,%1,%2
1028    #
1029    #"
1030   [(set_attr "type" "fast_compare,compare,compare,compare")
1031    (set_attr "length" "4,4,8,8")])
1032
1033 (define_split
1034   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1035         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1036                              (match_operand:SI 2 "reg_or_short_operand" ""))
1037                     (const_int 0)))
1038    (clobber (match_scratch:SI 3 ""))]
1039   "TARGET_32BIT && reload_completed"
1040   [(set (match_dup 3)
1041         (plus:SI (match_dup 1)
1042                  (match_dup 2)))
1043    (set (match_dup 0)
1044         (compare:CC (match_dup 3)
1045                     (const_int 0)))]
1046   "")
1047
1048 (define_insn "*addsi3_internal3"
1049   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1050         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1051                              (match_operand:SI 2 "reg_or_short_operand" "r,I,r,I"))
1052                     (const_int 0)))
1053    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
1054         (plus:SI (match_dup 1)
1055                  (match_dup 2)))]
1056   "TARGET_32BIT"
1057   "@
1058    {cax.|add.} %0,%1,%2
1059    {ai.|addic.} %0,%1,%2
1060    #
1061    #"
1062   [(set_attr "type" "fast_compare,compare,compare,compare")
1063    (set_attr "length" "4,4,8,8")])
1064
1065 (define_split
1066   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1067         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1068                              (match_operand:SI 2 "reg_or_short_operand" ""))
1069                     (const_int 0)))
1070    (set (match_operand:SI 0 "gpc_reg_operand" "")
1071         (plus:SI (match_dup 1) (match_dup 2)))]
1072   "TARGET_32BIT && reload_completed"
1073   [(set (match_dup 0)
1074         (plus:SI (match_dup 1)
1075                  (match_dup 2)))
1076    (set (match_dup 3)
1077         (compare:CC (match_dup 0)
1078                     (const_int 0)))]
1079   "")
1080
1081 ;; Split an add that we can't do in one insn into two insns, each of which
1082 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1083 ;; add should be last in case the result gets used in an address.
1084
1085 (define_split
1086   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1087         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1088                  (match_operand:SI 2 "non_add_cint_operand" "")))]
1089   ""
1090   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 3)))
1091    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 4)))]
1092 "
1093 {
1094   HOST_WIDE_INT val = INTVAL (operands[2]);
1095   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1096   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, SImode);
1097
1098   operands[3] = GEN_INT (rest);
1099   operands[4] = GEN_INT (low);
1100 }")
1101
1102 (define_insn "one_cmplsi2"
1103   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1104         (not:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1105   ""
1106   "nor %0,%1,%1")
1107
1108 (define_insn ""
1109   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1110         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1111                     (const_int 0)))
1112    (clobber (match_scratch:SI 2 "=r,r"))]
1113   "TARGET_32BIT"
1114   "@
1115    nor. %2,%1,%1
1116    #"
1117   [(set_attr "type" "compare")
1118    (set_attr "length" "4,8")])
1119
1120 (define_split
1121   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1122         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1123                     (const_int 0)))
1124    (clobber (match_scratch:SI 2 ""))]
1125   "TARGET_32BIT && reload_completed"
1126   [(set (match_dup 2)
1127         (not:SI (match_dup 1)))
1128    (set (match_dup 0)
1129         (compare:CC (match_dup 2)
1130                     (const_int 0)))]
1131   "")
1132
1133 (define_insn ""
1134   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1135         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1136                     (const_int 0)))
1137    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1138         (not:SI (match_dup 1)))]
1139   "TARGET_32BIT"
1140   "@
1141    nor. %0,%1,%1
1142    #"
1143   [(set_attr "type" "compare")
1144    (set_attr "length" "4,8")])
1145
1146 (define_split
1147   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1148         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1149                     (const_int 0)))
1150    (set (match_operand:SI 0 "gpc_reg_operand" "")
1151         (not:SI (match_dup 1)))]
1152   "TARGET_32BIT && reload_completed"
1153   [(set (match_dup 0)
1154         (not:SI (match_dup 1)))
1155    (set (match_dup 2)
1156         (compare:CC (match_dup 0)
1157                     (const_int 0)))]
1158   "")
1159
1160 (define_insn ""
1161   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1162         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
1163                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
1164   "! TARGET_POWERPC"
1165   "{sf%I1|subf%I1c} %0,%2,%1")
1166
1167 (define_insn ""
1168   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1169         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "r,I")
1170                   (match_operand:SI 2 "gpc_reg_operand" "r,r")))]
1171   "TARGET_POWERPC"
1172   "@
1173    subf %0,%2,%1
1174    subfic %0,%2,%1")
1175
1176 (define_insn ""
1177   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1178         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1179                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1180                     (const_int 0)))
1181    (clobber (match_scratch:SI 3 "=r,r"))]
1182   "! TARGET_POWERPC"
1183   "@
1184    {sf.|subfc.} %3,%2,%1
1185    #"
1186   [(set_attr "type" "compare")
1187    (set_attr "length" "4,8")])
1188
1189 (define_insn ""
1190   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1191         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1192                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1193                     (const_int 0)))
1194    (clobber (match_scratch:SI 3 "=r,r"))]
1195   "TARGET_POWERPC && TARGET_32BIT"
1196   "@
1197    subf. %3,%2,%1
1198    #"
1199   [(set_attr "type" "fast_compare")
1200    (set_attr "length" "4,8")])
1201
1202 (define_split
1203   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1204         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1205                               (match_operand:SI 2 "gpc_reg_operand" ""))
1206                     (const_int 0)))
1207    (clobber (match_scratch:SI 3 ""))]
1208   "TARGET_32BIT && reload_completed"
1209   [(set (match_dup 3)
1210         (minus:SI (match_dup 1)
1211                   (match_dup 2)))
1212    (set (match_dup 0)
1213         (compare:CC (match_dup 3)
1214                     (const_int 0)))]
1215   "")
1216
1217 (define_insn ""
1218   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1219         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1220                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1221                     (const_int 0)))
1222    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1223         (minus:SI (match_dup 1) (match_dup 2)))]
1224   "! TARGET_POWERPC"
1225   "@
1226    {sf.|subfc.} %0,%2,%1
1227    #"
1228   [(set_attr "type" "compare")
1229    (set_attr "length" "4,8")])
1230
1231 (define_insn ""
1232   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1233         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1234                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1235                     (const_int 0)))
1236    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1237         (minus:SI (match_dup 1)
1238                   (match_dup 2)))]
1239   "TARGET_POWERPC && TARGET_32BIT"
1240   "@
1241    subf. %0,%2,%1
1242    #"
1243   [(set_attr "type" "fast_compare")
1244    (set_attr "length" "4,8")])
1245
1246 (define_split
1247   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1248         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1249                               (match_operand:SI 2 "gpc_reg_operand" ""))
1250                     (const_int 0)))
1251    (set (match_operand:SI 0 "gpc_reg_operand" "")
1252         (minus:SI (match_dup 1)
1253                   (match_dup 2)))]
1254   "TARGET_32BIT && reload_completed"
1255   [(set (match_dup 0)
1256         (minus:SI (match_dup 1)
1257                   (match_dup 2)))
1258    (set (match_dup 3)
1259         (compare:CC (match_dup 0)
1260                     (const_int 0)))]
1261   "")
1262
1263 (define_expand "subsi3"
1264   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1265         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "")
1266                   (match_operand:SI 2 "reg_or_arith_cint_operand" "")))]
1267   ""
1268   "
1269 {
1270   if (GET_CODE (operands[2]) == CONST_INT)
1271     {
1272       emit_insn (gen_addsi3 (operands[0], operands[1],
1273                              negate_rtx (SImode, operands[2])));
1274       DONE;
1275     }
1276 }")
1277
1278 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1279 ;; instruction and some auxiliary computations.  Then we just have a single
1280 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1281 ;; combine.
1282
1283 (define_expand "sminsi3"
1284   [(set (match_dup 3)
1285         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1286                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1287                          (const_int 0)
1288                          (minus:SI (match_dup 2) (match_dup 1))))
1289    (set (match_operand:SI 0 "gpc_reg_operand" "")
1290         (minus:SI (match_dup 2) (match_dup 3)))]
1291   "TARGET_POWER || TARGET_ISEL"
1292   "
1293 {
1294   if (TARGET_ISEL)
1295     {
1296       operands[2] = force_reg (SImode, operands[2]);
1297       rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
1298       DONE;
1299     }
1300
1301   operands[3] = gen_reg_rtx (SImode);
1302 }")
1303
1304 (define_split
1305   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1306         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1307                  (match_operand:SI 2 "reg_or_short_operand" "")))
1308    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1309   "TARGET_POWER"
1310   [(set (match_dup 3)
1311         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1312                          (const_int 0)
1313                          (minus:SI (match_dup 2) (match_dup 1))))
1314    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1315   "")
1316
1317 (define_expand "smaxsi3"
1318   [(set (match_dup 3)
1319         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1320                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1321                          (const_int 0)
1322                          (minus:SI (match_dup 2) (match_dup 1))))
1323    (set (match_operand:SI 0 "gpc_reg_operand" "")
1324         (plus:SI (match_dup 3) (match_dup 1)))]
1325   "TARGET_POWER || TARGET_ISEL"
1326   "
1327 {
1328   if (TARGET_ISEL)
1329     {
1330       operands[2] = force_reg (SImode, operands[2]);
1331       rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
1332       DONE;
1333     }
1334   operands[3] = gen_reg_rtx (SImode);
1335 }")
1336
1337 (define_split
1338   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1339         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1340                  (match_operand:SI 2 "reg_or_short_operand" "")))
1341    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1342   "TARGET_POWER"
1343   [(set (match_dup 3)
1344         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1345                          (const_int 0)
1346                          (minus:SI (match_dup 2) (match_dup 1))))
1347    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1348   "")
1349
1350 (define_expand "uminsi3"
1351   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1352                               (match_dup 5)))
1353    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1354                               (match_dup 5)))
1355    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1356                                        (const_int 0)
1357                                        (minus:SI (match_dup 4) (match_dup 3))))
1358    (set (match_operand:SI 0 "gpc_reg_operand" "")
1359         (minus:SI (match_dup 2) (match_dup 3)))]
1360   "TARGET_POWER || TARGET_ISEL"
1361   "
1362 {
1363   if (TARGET_ISEL)
1364     {
1365       rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
1366       DONE;
1367     }
1368   operands[3] = gen_reg_rtx (SImode);
1369   operands[4] = gen_reg_rtx (SImode);
1370   operands[5] = GEN_INT (-2147483647 - 1);
1371 }")
1372
1373 (define_expand "umaxsi3"
1374   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1375                               (match_dup 5)))
1376    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1377                               (match_dup 5)))
1378    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1379                                        (const_int 0)
1380                                        (minus:SI (match_dup 4) (match_dup 3))))
1381    (set (match_operand:SI 0 "gpc_reg_operand" "")
1382         (plus:SI (match_dup 3) (match_dup 1)))]
1383   "TARGET_POWER || TARGET_ISEL"
1384   "
1385 {
1386   if (TARGET_ISEL)
1387     {
1388       rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
1389       DONE;
1390     }
1391   operands[3] = gen_reg_rtx (SImode);
1392   operands[4] = gen_reg_rtx (SImode);
1393   operands[5] = GEN_INT (-2147483647 - 1);
1394 }")
1395
1396 (define_insn ""
1397   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1398         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1399                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
1400                          (const_int 0)
1401                          (minus:SI (match_dup 2) (match_dup 1))))]
1402   "TARGET_POWER"
1403   "doz%I2 %0,%1,%2")
1404
1405 (define_insn ""
1406   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1407         (compare:CC
1408          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1409                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1410                           (const_int 0)
1411                           (minus:SI (match_dup 2) (match_dup 1)))
1412          (const_int 0)))
1413    (clobber (match_scratch:SI 3 "=r,r"))]
1414   "TARGET_POWER"
1415   "@
1416    doz%I2. %3,%1,%2
1417    #"
1418   [(set_attr "type" "delayed_compare")
1419    (set_attr "length" "4,8")])
1420
1421 (define_split
1422   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1423         (compare:CC
1424          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1425                               (match_operand:SI 2 "reg_or_short_operand" ""))
1426                           (const_int 0)
1427                           (minus:SI (match_dup 2) (match_dup 1)))
1428          (const_int 0)))
1429    (clobber (match_scratch:SI 3 ""))]
1430   "TARGET_POWER && reload_completed"
1431   [(set (match_dup 3)
1432         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1433                           (const_int 0)
1434                           (minus:SI (match_dup 2) (match_dup 1))))
1435    (set (match_dup 0)
1436         (compare:CC (match_dup 3)
1437                     (const_int 0)))]
1438   "")
1439
1440 (define_insn ""
1441   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1442         (compare:CC
1443          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1444                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1445                           (const_int 0)
1446                           (minus:SI (match_dup 2) (match_dup 1)))
1447          (const_int 0)))
1448    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1449         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1450                          (const_int 0)
1451                          (minus:SI (match_dup 2) (match_dup 1))))]
1452   "TARGET_POWER"
1453   "@
1454    doz%I2. %0,%1,%2
1455    #"
1456   [(set_attr "type" "delayed_compare")
1457    (set_attr "length" "4,8")])
1458
1459 (define_split
1460   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1461         (compare:CC
1462          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1463                               (match_operand:SI 2 "reg_or_short_operand" ""))
1464                           (const_int 0)
1465                           (minus:SI (match_dup 2) (match_dup 1)))
1466          (const_int 0)))
1467    (set (match_operand:SI 0 "gpc_reg_operand" "")
1468         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1469                          (const_int 0)
1470                          (minus:SI (match_dup 2) (match_dup 1))))]
1471   "TARGET_POWER && reload_completed"
1472   [(set (match_dup 0)
1473         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1474                          (const_int 0)
1475                          (minus:SI (match_dup 2) (match_dup 1))))
1476    (set (match_dup 3)
1477         (compare:CC (match_dup 0)
1478                     (const_int 0)))]
1479   "")
1480
1481 ;; We don't need abs with condition code because such comparisons should
1482 ;; never be done.
1483 (define_expand "abssi2"
1484   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1485         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
1486   ""
1487   "
1488 {
1489   if (TARGET_ISEL)
1490     {
1491       emit_insn (gen_abssi2_isel (operands[0], operands[1]));
1492       DONE;
1493     }
1494   else if (! TARGET_POWER)
1495     {
1496       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
1497       DONE;
1498     }
1499 }")
1500
1501 (define_insn "*abssi2_power"
1502   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1503         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1504   "TARGET_POWER"
1505   "abs %0,%1")
1506
1507 (define_insn_and_split "abssi2_isel"
1508   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1509         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
1510    (clobber (match_scratch:SI 2 "=&b"))
1511    (clobber (match_scratch:CC 3 "=y"))]
1512   "TARGET_ISEL"
1513   "#"
1514   "&& reload_completed"
1515   [(set (match_dup 2) (neg:SI (match_dup 1)))
1516    (set (match_dup 3)
1517         (compare:CC (match_dup 1)
1518                     (const_int 0)))
1519    (set (match_dup 0)
1520         (if_then_else:SI (ge (match_dup 3)
1521                              (const_int 0))
1522                          (match_dup 1)
1523                          (match_dup 2)))]
1524   "")
1525
1526 (define_insn_and_split "abssi2_nopower"
1527   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1528         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
1529    (clobber (match_scratch:SI 2 "=&r,&r"))]
1530   "! TARGET_POWER && ! TARGET_ISEL"
1531   "#"
1532   "&& reload_completed"
1533   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1534    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1535    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
1536   "")
1537
1538 (define_insn "*nabs_power"
1539   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1540         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
1541   "TARGET_POWER"
1542   "nabs %0,%1")
1543
1544 (define_insn_and_split "*nabs_nopower"
1545   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1546         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
1547    (clobber (match_scratch:SI 2 "=&r,&r"))]
1548   "! TARGET_POWER"
1549   "#"
1550   "&& reload_completed"
1551   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1552    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1553    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
1554   "")
1555
1556 (define_insn "negsi2"
1557   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1558         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1559   ""
1560   "neg %0,%1")
1561
1562 (define_insn ""
1563   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1564         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1565                     (const_int 0)))
1566    (clobber (match_scratch:SI 2 "=r,r"))]
1567   "TARGET_32BIT"
1568   "@
1569    neg. %2,%1
1570    #"
1571   [(set_attr "type" "fast_compare")
1572    (set_attr "length" "4,8")])
1573
1574 (define_split
1575   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1576         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1577                     (const_int 0)))
1578    (clobber (match_scratch:SI 2 ""))]
1579   "TARGET_32BIT && reload_completed"
1580   [(set (match_dup 2)
1581         (neg:SI (match_dup 1)))
1582    (set (match_dup 0)
1583         (compare:CC (match_dup 2)
1584                     (const_int 0)))]
1585   "")
1586
1587 (define_insn ""
1588   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1589         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1590                     (const_int 0)))
1591    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1592         (neg:SI (match_dup 1)))]
1593   "TARGET_32BIT"
1594   "@
1595    neg. %0,%1
1596    #"
1597   [(set_attr "type" "fast_compare")
1598    (set_attr "length" "4,8")])
1599
1600 (define_split
1601   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1602         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1603                     (const_int 0)))
1604    (set (match_operand:SI 0 "gpc_reg_operand" "")
1605         (neg:SI (match_dup 1)))]
1606   "TARGET_32BIT && reload_completed"
1607   [(set (match_dup 0)
1608         (neg:SI (match_dup 1)))
1609    (set (match_dup 2)
1610         (compare:CC (match_dup 0)
1611                     (const_int 0)))]
1612   "")
1613
1614 (define_insn "clzsi2"
1615   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1616         (clz:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1617   ""
1618   "{cntlz|cntlzw} %0,%1")
1619
1620 (define_expand "ctzsi2"
1621   [(set (match_dup 2)
1622         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
1623    (parallel [(set (match_dup 3) (and:SI (match_dup 1)
1624                                          (match_dup 2)))
1625               (clobber (scratch:CC))])
1626    (set (match_dup 4) (clz:SI (match_dup 3)))
1627    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1628         (minus:SI (const_int 31) (match_dup 4)))]
1629   ""
1630   {
1631      operands[2] = gen_reg_rtx (SImode);
1632      operands[3] = gen_reg_rtx (SImode);
1633      operands[4] = gen_reg_rtx (SImode);
1634   })
1635   
1636 (define_expand "ffssi2"
1637   [(set (match_dup 2)
1638         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
1639    (parallel [(set (match_dup 3) (and:SI (match_dup 1)
1640                                          (match_dup 2)))
1641               (clobber (scratch:CC))])
1642    (set (match_dup 4) (clz:SI (match_dup 3)))
1643    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1644         (minus:SI (const_int 32) (match_dup 4)))]
1645   ""
1646   {
1647      operands[2] = gen_reg_rtx (SImode);
1648      operands[3] = gen_reg_rtx (SImode);
1649      operands[4] = gen_reg_rtx (SImode);
1650   })
1651   
1652 (define_expand "mulsi3"
1653   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1654    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1655    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
1656   ""
1657   "
1658 {
1659   if (TARGET_POWER)
1660     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
1661   else
1662     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
1663   DONE;
1664 }")
1665
1666 (define_insn "mulsi3_mq"
1667   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1668         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1669                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
1670    (clobber (match_scratch:SI 3 "=q,q"))]
1671   "TARGET_POWER"
1672   "@
1673    {muls|mullw} %0,%1,%2
1674    {muli|mulli} %0,%1,%2"
1675    [(set (attr "type") 
1676       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
1677                 (const_string "imul3")
1678              (match_operand:SI 2 "short_cint_operand" "") 
1679                 (const_string "imul2")]
1680         (const_string "imul")))])
1681
1682 (define_insn "mulsi3_no_mq"
1683   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1684         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1685                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
1686   "! TARGET_POWER"
1687   "@
1688    {muls|mullw} %0,%1,%2
1689    {muli|mulli} %0,%1,%2"
1690    [(set (attr "type") 
1691       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
1692                 (const_string "imul3")
1693              (match_operand:SI 2 "short_cint_operand" "") 
1694                 (const_string "imul2")]
1695         (const_string "imul")))])
1696
1697 (define_insn "*mulsi3_mq_internal1"
1698   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1699         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1700                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1701                     (const_int 0)))
1702    (clobber (match_scratch:SI 3 "=r,r"))
1703    (clobber (match_scratch:SI 4 "=q,q"))]
1704   "TARGET_POWER"
1705   "@
1706    {muls.|mullw.} %3,%1,%2
1707    #"
1708   [(set_attr "type" "imul_compare")
1709    (set_attr "length" "4,8")])
1710
1711 (define_split
1712   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1713         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1714                              (match_operand:SI 2 "gpc_reg_operand" ""))
1715                     (const_int 0)))
1716    (clobber (match_scratch:SI 3 ""))
1717    (clobber (match_scratch:SI 4 ""))]
1718   "TARGET_POWER && reload_completed"
1719   [(parallel [(set (match_dup 3)
1720         (mult:SI (match_dup 1) (match_dup 2)))
1721    (clobber (match_dup 4))])
1722    (set (match_dup 0)
1723         (compare:CC (match_dup 3)
1724                     (const_int 0)))]
1725   "")
1726
1727 (define_insn "*mulsi3_no_mq_internal1"
1728   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1729         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1730                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1731                     (const_int 0)))
1732    (clobber (match_scratch:SI 3 "=r,r"))]
1733   "! TARGET_POWER"
1734   "@
1735    {muls.|mullw.} %3,%1,%2
1736    #"
1737   [(set_attr "type" "imul_compare")
1738    (set_attr "length" "4,8")])
1739
1740 (define_split
1741   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1742         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1743                              (match_operand:SI 2 "gpc_reg_operand" ""))
1744                     (const_int 0)))
1745    (clobber (match_scratch:SI 3 ""))]
1746   "! TARGET_POWER && reload_completed"
1747   [(set (match_dup 3)
1748         (mult:SI (match_dup 1) (match_dup 2)))
1749    (set (match_dup 0)
1750         (compare:CC (match_dup 3)
1751                     (const_int 0)))]
1752   "")
1753
1754 (define_insn "*mulsi3_mq_internal2"
1755   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1756         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1757                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1758                     (const_int 0)))
1759    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1760         (mult:SI (match_dup 1) (match_dup 2)))
1761    (clobber (match_scratch:SI 4 "=q,q"))]
1762   "TARGET_POWER"
1763   "@
1764    {muls.|mullw.} %0,%1,%2
1765    #"
1766   [(set_attr "type" "imul_compare")
1767    (set_attr "length" "4,8")])
1768
1769 (define_split
1770   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1771         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1772                              (match_operand:SI 2 "gpc_reg_operand" ""))
1773                     (const_int 0)))
1774    (set (match_operand:SI 0 "gpc_reg_operand" "")
1775         (mult:SI (match_dup 1) (match_dup 2)))
1776    (clobber (match_scratch:SI 4 ""))]
1777   "TARGET_POWER && reload_completed"
1778   [(parallel [(set (match_dup 0)
1779         (mult:SI (match_dup 1) (match_dup 2)))
1780    (clobber (match_dup 4))])
1781    (set (match_dup 3)
1782         (compare:CC (match_dup 0)
1783                     (const_int 0)))]
1784   "")
1785
1786 (define_insn "*mulsi3_no_mq_internal2"
1787   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1788         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1789                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1790                     (const_int 0)))
1791    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1792         (mult:SI (match_dup 1) (match_dup 2)))]
1793   "! TARGET_POWER"
1794   "@
1795    {muls.|mullw.} %0,%1,%2
1796    #"
1797   [(set_attr "type" "imul_compare")
1798    (set_attr "length" "4,8")])
1799
1800 (define_split
1801   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1802         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1803                              (match_operand:SI 2 "gpc_reg_operand" ""))
1804                     (const_int 0)))
1805    (set (match_operand:SI 0 "gpc_reg_operand" "")
1806         (mult:SI (match_dup 1) (match_dup 2)))]
1807   "! TARGET_POWER && reload_completed"
1808   [(set (match_dup 0)
1809         (mult:SI (match_dup 1) (match_dup 2)))
1810    (set (match_dup 3)
1811         (compare:CC (match_dup 0)
1812                     (const_int 0)))]
1813   "")
1814
1815 ;; Operand 1 is divided by operand 2; quotient goes to operand
1816 ;; 0 and remainder to operand 3.
1817 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
1818
1819 (define_expand "divmodsi4"
1820   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
1821                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1822                            (match_operand:SI 2 "gpc_reg_operand" "")))
1823               (set (match_operand:SI 3 "register_operand" "")
1824                    (mod:SI (match_dup 1) (match_dup 2)))])]
1825   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
1826   "
1827 {
1828   if (! TARGET_POWER && ! TARGET_POWERPC)
1829     {
1830       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
1831       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
1832       emit_insn (gen_divss_call ());
1833       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
1834       emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
1835       DONE;
1836     }
1837 }")
1838
1839 (define_insn "*divmodsi4_internal"
1840   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1841         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1842                 (match_operand:SI 2 "gpc_reg_operand" "r")))
1843    (set (match_operand:SI 3 "register_operand" "=q")
1844         (mod:SI (match_dup 1) (match_dup 2)))]
1845   "TARGET_POWER"
1846   "divs %0,%1,%2"
1847   [(set_attr "type" "idiv")])
1848
1849 (define_expand "udivsi3"
1850   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1851         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
1852                  (match_operand:SI 2 "gpc_reg_operand" "")))]
1853   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
1854   "
1855 {
1856   if (! TARGET_POWER && ! TARGET_POWERPC)
1857     {
1858       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
1859       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
1860       emit_insn (gen_quous_call ());
1861       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
1862       DONE;
1863     }
1864   else if (TARGET_POWER)
1865     {
1866       emit_insn (gen_udivsi3_mq (operands[0], operands[1], operands[2]));
1867       DONE;
1868     }
1869 }")
1870
1871 (define_insn "udivsi3_mq"
1872   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1873         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1874                  (match_operand:SI 2 "gpc_reg_operand" "r")))
1875    (clobber (match_scratch:SI 3 "=q"))]
1876   "TARGET_POWERPC && TARGET_POWER"
1877   "divwu %0,%1,%2"
1878   [(set_attr "type" "idiv")])
1879
1880 (define_insn "*udivsi3_no_mq"
1881   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1882         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1883                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
1884   "TARGET_POWERPC && ! TARGET_POWER"
1885   "divwu %0,%1,%2"
1886   [(set_attr "type" "idiv")])
1887
1888 ;; For powers of two we can do srai/aze for divide and then adjust for
1889 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
1890 ;; used; for PowerPC, force operands into register and do a normal divide;
1891 ;; for AIX common-mode, use quoss call on register operands.
1892 (define_expand "divsi3"
1893   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1894         (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1895                 (match_operand:SI 2 "reg_or_cint_operand" "")))]
1896   ""
1897   "
1898 {
1899   if (GET_CODE (operands[2]) == CONST_INT
1900       && INTVAL (operands[2]) > 0
1901       && exact_log2 (INTVAL (operands[2])) >= 0)
1902     ;
1903   else if (TARGET_POWERPC)
1904     {
1905       operands[2] = force_reg (SImode, operands[2]);
1906       if (TARGET_POWER)
1907         {
1908           emit_insn (gen_divsi3_mq (operands[0], operands[1], operands[2]));
1909           DONE;
1910         }
1911     }
1912   else if (TARGET_POWER)
1913     FAIL;
1914   else
1915     {
1916       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
1917       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
1918       emit_insn (gen_quoss_call ());
1919       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
1920       DONE;
1921     }
1922 }")
1923
1924 (define_insn "divsi3_mq"
1925   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1926         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1927                 (match_operand:SI 2 "gpc_reg_operand" "r")))
1928    (clobber (match_scratch:SI 3 "=q"))]
1929   "TARGET_POWERPC && TARGET_POWER"
1930   "divw %0,%1,%2"
1931   [(set_attr "type" "idiv")])
1932
1933 (define_insn "*divsi3_no_mq"
1934   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1935         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1936                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
1937   "TARGET_POWERPC && ! TARGET_POWER"
1938   "divw %0,%1,%2"
1939   [(set_attr "type" "idiv")])
1940
1941 (define_expand "modsi3"
1942   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1943    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1944    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
1945   ""
1946   "
1947 {
1948   int i;
1949   rtx temp1;
1950   rtx temp2;
1951
1952   if (GET_CODE (operands[2]) != CONST_INT
1953       || INTVAL (operands[2]) <= 0
1954       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
1955     FAIL;
1956
1957   temp1 = gen_reg_rtx (SImode);
1958   temp2 = gen_reg_rtx (SImode);
1959
1960   emit_insn (gen_divsi3 (temp1, operands[1], operands[2]));
1961   emit_insn (gen_ashlsi3 (temp2, temp1, GEN_INT (i)));
1962   emit_insn (gen_subsi3 (operands[0], operands[1], temp2));
1963   DONE;
1964 }")
1965
1966 (define_insn ""
1967   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1968         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1969                 (match_operand:SI 2 "exact_log2_cint_operand" "N")))]
1970   ""
1971   "{srai|srawi} %0,%1,%p2\;{aze|addze} %0,%0"
1972   [(set_attr "length" "8")])
1973
1974 (define_insn ""
1975   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1976         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1977                             (match_operand:SI 2 "exact_log2_cint_operand" "N,N"))
1978                     (const_int 0)))
1979    (clobber (match_scratch:SI 3 "=r,r"))]
1980   ""
1981   "@
1982    {srai|srawi} %3,%1,%p2\;{aze.|addze.} %3,%3
1983    #"
1984   [(set_attr "type" "compare")
1985    (set_attr "length" "8,12")])
1986
1987 (define_split
1988   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1989         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1990                             (match_operand:SI 2 "exact_log2_cint_operand" ""))
1991                     (const_int 0)))
1992    (clobber (match_scratch:SI 3 ""))]
1993   "reload_completed"
1994   [(set (match_dup 3)
1995         (div:SI (match_dup 1) (match_dup 2)))
1996    (set (match_dup 0)
1997         (compare:CC (match_dup 3)
1998                     (const_int 0)))]
1999   "")
2000
2001 (define_insn ""
2002   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2003         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2004                             (match_operand:SI 2 "exact_log2_cint_operand" "N,N"))
2005                     (const_int 0)))
2006    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2007         (div:SI (match_dup 1) (match_dup 2)))]
2008   ""
2009   "@
2010    {srai|srawi} %0,%1,%p2\;{aze.|addze.} %0,%0
2011    #"
2012   [(set_attr "type" "compare")
2013    (set_attr "length" "8,12")])
2014
2015 (define_split
2016   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2017         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2018                             (match_operand:SI 2 "exact_log2_cint_operand" ""))
2019                     (const_int 0)))
2020    (set (match_operand:SI 0 "gpc_reg_operand" "")
2021         (div:SI (match_dup 1) (match_dup 2)))]
2022   "reload_completed"
2023   [(set (match_dup 0)
2024         (div:SI (match_dup 1) (match_dup 2)))
2025    (set (match_dup 3)
2026         (compare:CC (match_dup 0)
2027                     (const_int 0)))]
2028   "")
2029
2030 (define_insn ""
2031   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2032         (udiv:SI
2033          (plus:DI (ashift:DI
2034                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
2035                    (const_int 32))
2036                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
2037          (match_operand:SI 3 "gpc_reg_operand" "r")))
2038    (set (match_operand:SI 2 "register_operand" "=*q")
2039         (umod:SI
2040          (plus:DI (ashift:DI
2041                    (zero_extend:DI (match_dup 1)) (const_int 32))
2042                   (zero_extend:DI (match_dup 4)))
2043          (match_dup 3)))]
2044   "TARGET_POWER"
2045   "div %0,%1,%3"
2046   [(set_attr "type" "idiv")])
2047
2048 ;; To do unsigned divide we handle the cases of the divisor looking like a
2049 ;; negative number.  If it is a constant that is less than 2**31, we don't
2050 ;; have to worry about the branches.  So make a few subroutines here.
2051 ;;
2052 ;; First comes the normal case.
2053 (define_expand "udivmodsi4_normal"
2054   [(set (match_dup 4) (const_int 0))
2055    (parallel [(set (match_operand:SI 0 "" "")
2056                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2057                                                 (const_int 32))
2058                                      (zero_extend:DI (match_operand:SI 1 "" "")))
2059                             (match_operand:SI 2 "" "")))
2060               (set (match_operand:SI 3 "" "")
2061                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2062                                                 (const_int 32))
2063                                      (zero_extend:DI (match_dup 1)))
2064                             (match_dup 2)))])]
2065   "TARGET_POWER"
2066   "
2067 { operands[4] = gen_reg_rtx (SImode); }")
2068
2069 ;; This handles the branches.
2070 (define_expand "udivmodsi4_tests"
2071   [(set (match_operand:SI 0 "" "") (const_int 0))
2072    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
2073    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
2074    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
2075                            (label_ref (match_operand:SI 4 "" "")) (pc)))
2076    (set (match_dup 0) (const_int 1))
2077    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
2078    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
2079    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
2080                            (label_ref (match_dup 4)) (pc)))]
2081   "TARGET_POWER"
2082   "
2083 { operands[5] = gen_reg_rtx (CCUNSmode);
2084   operands[6] = gen_reg_rtx (CCmode);
2085 }")
2086
2087 (define_expand "udivmodsi4"
2088   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2089                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
2090                             (match_operand:SI 2 "reg_or_cint_operand" "")))
2091               (set (match_operand:SI 3 "gpc_reg_operand" "")
2092                    (umod:SI (match_dup 1) (match_dup 2)))])]
2093   ""
2094   "
2095 {
2096   rtx label = 0;
2097
2098   if (! TARGET_POWER)
2099     {
2100       if (! TARGET_POWERPC)
2101         {
2102           emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2103           emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2104           emit_insn (gen_divus_call ());
2105           emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2106           emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2107           DONE;
2108         }
2109       else
2110         FAIL;
2111     }
2112
2113   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
2114     {
2115       operands[2] = force_reg (SImode, operands[2]);
2116       label = gen_label_rtx ();
2117       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
2118                                   operands[3], label));
2119     }
2120   else
2121     operands[2] = force_reg (SImode, operands[2]);
2122
2123   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
2124                                operands[3]));
2125   if (label)
2126     emit_label (label);
2127
2128   DONE;
2129 }")
2130
2131 ;; AIX architecture-independent common-mode multiply (DImode),
2132 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
2133 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
2134 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
2135 ;; assumed unused if generating common-mode, so ignore.
2136 (define_insn "mulh_call"
2137   [(set (reg:SI 3)
2138         (truncate:SI
2139          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
2140                                (sign_extend:DI (reg:SI 4)))
2141                       (const_int 32))))
2142    (clobber (match_scratch:SI 0 "=l"))]
2143   "! TARGET_POWER && ! TARGET_POWERPC"
2144   "bla __mulh"
2145   [(set_attr "type" "imul")])
2146
2147 (define_insn "mull_call"
2148   [(set (reg:DI 3)
2149         (mult:DI (sign_extend:DI (reg:SI 3))
2150                  (sign_extend:DI (reg:SI 4))))
2151    (clobber (match_scratch:SI 0 "=l"))
2152    (clobber (reg:SI 0))]
2153   "! TARGET_POWER && ! TARGET_POWERPC"
2154   "bla __mull"
2155   [(set_attr "type" "imul")])
2156
2157 (define_insn "divss_call"
2158   [(set (reg:SI 3)
2159         (div:SI (reg:SI 3) (reg:SI 4)))
2160    (set (reg:SI 4)
2161         (mod:SI (reg:SI 3) (reg:SI 4)))
2162    (clobber (match_scratch:SI 0 "=l"))
2163    (clobber (reg:SI 0))]
2164   "! TARGET_POWER && ! TARGET_POWERPC"
2165   "bla __divss"
2166   [(set_attr "type" "idiv")])
2167
2168 (define_insn "divus_call"
2169   [(set (reg:SI 3)
2170         (udiv:SI (reg:SI 3) (reg:SI 4)))
2171    (set (reg:SI 4)
2172         (umod:SI (reg:SI 3) (reg:SI 4)))
2173    (clobber (match_scratch:SI 0 "=l"))
2174    (clobber (reg:SI 0))
2175    (clobber (match_scratch:CC 1 "=x"))
2176    (clobber (reg:CC 69))]
2177   "! TARGET_POWER && ! TARGET_POWERPC"
2178   "bla __divus"
2179   [(set_attr "type" "idiv")])
2180
2181 (define_insn "quoss_call"
2182   [(set (reg:SI 3)
2183         (div:SI (reg:SI 3) (reg:SI 4)))
2184    (clobber (match_scratch:SI 0 "=l"))]
2185   "! TARGET_POWER && ! TARGET_POWERPC"
2186   "bla __quoss"
2187   [(set_attr "type" "idiv")])
2188
2189 (define_insn "quous_call"
2190   [(set (reg:SI 3)
2191         (udiv:SI (reg:SI 3) (reg:SI 4)))
2192    (clobber (match_scratch:SI 0 "=l"))
2193    (clobber (reg:SI 0))
2194    (clobber (match_scratch:CC 1 "=x"))
2195    (clobber (reg:CC 69))]
2196   "! TARGET_POWER && ! TARGET_POWERPC"
2197   "bla __quous"
2198   [(set_attr "type" "idiv")])
2199 \f
2200 ;; Logical instructions
2201 ;; The logical instructions are mostly combined by using match_operator,
2202 ;; but the plain AND insns are somewhat different because there is no
2203 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2204 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2205
2206 (define_insn "andsi3"
2207   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2208         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2209                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2210    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2211   ""
2212   "@
2213    and %0,%1,%2
2214    {rlinm|rlwinm} %0,%1,0,%m2,%M2
2215    {andil.|andi.} %0,%1,%b2
2216    {andiu.|andis.} %0,%1,%u2")
2217
2218 ;; Note to set cr's other than cr0 we do the and immediate and then
2219 ;; the test again -- this avoids a mfcr which on the higher end
2220 ;; machines causes an execution serialization
2221
2222 (define_insn "*andsi3_internal2"
2223   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2224         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2225                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2226                     (const_int 0)))
2227    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2228    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2229   "TARGET_32BIT"
2230   "@
2231    and. %3,%1,%2
2232    {andil.|andi.} %3,%1,%b2
2233    {andiu.|andis.} %3,%1,%u2
2234    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2235    #
2236    #
2237    #
2238    #"
2239   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2240    (set_attr "length" "4,4,4,4,8,8,8,8")])
2241
2242 (define_insn "*andsi3_internal3"
2243   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2244         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2245                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2246                     (const_int 0)))
2247    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2248    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2249   "TARGET_64BIT"
2250   "@
2251    #
2252    {andil.|andi.} %3,%1,%b2
2253    {andiu.|andis.} %3,%1,%u2
2254    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2255    #
2256    #
2257    #
2258    #"
2259   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2260    (set_attr "length" "8,4,4,4,8,8,8,8")])
2261
2262 (define_split
2263   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2264         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2265                             (match_operand:SI 2 "and_operand" ""))
2266                     (const_int 0)))
2267    (clobber (match_scratch:SI 3 ""))
2268    (clobber (match_scratch:CC 4 ""))]
2269   "reload_completed"
2270   [(parallel [(set (match_dup 3)
2271                    (and:SI (match_dup 1)
2272                            (match_dup 2)))
2273               (clobber (match_dup 4))])
2274    (set (match_dup 0)
2275         (compare:CC (match_dup 3)
2276                     (const_int 0)))]
2277   "")
2278
2279 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
2280 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
2281
2282 (define_split
2283   [(set (match_operand:CC 0 "cc_reg_operand" "")
2284         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2285                             (match_operand:SI 2 "gpc_reg_operand" ""))
2286                     (const_int 0)))
2287    (clobber (match_scratch:SI 3 ""))
2288    (clobber (match_scratch:CC 4 ""))]
2289   "TARGET_POWERPC64 && reload_completed"
2290   [(parallel [(set (match_dup 3)
2291                    (and:SI (match_dup 1)
2292                            (match_dup 2)))
2293               (clobber (match_dup 4))])
2294    (set (match_dup 0)
2295         (compare:CC (match_dup 3)
2296                     (const_int 0)))]
2297   "")
2298
2299 (define_insn "*andsi3_internal4"
2300   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2301         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2302                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2303                     (const_int 0)))
2304    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2305         (and:SI (match_dup 1)
2306                 (match_dup 2)))
2307    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2308   "TARGET_32BIT"
2309   "@
2310    and. %0,%1,%2
2311    {andil.|andi.} %0,%1,%b2
2312    {andiu.|andis.} %0,%1,%u2
2313    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2314    #
2315    #
2316    #
2317    #"
2318   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2319    (set_attr "length" "4,4,4,4,8,8,8,8")])
2320
2321 (define_insn "*andsi3_internal5"
2322   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2323         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2324                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2325                     (const_int 0)))
2326    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2327         (and:SI (match_dup 1)
2328                 (match_dup 2)))
2329    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2330   "TARGET_64BIT"
2331   "@
2332    #
2333    {andil.|andi.} %0,%1,%b2
2334    {andiu.|andis.} %0,%1,%u2
2335    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2336    #
2337    #
2338    #
2339    #"
2340   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2341    (set_attr "length" "8,4,4,4,8,8,8,8")])
2342
2343 (define_split
2344   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2345         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2346                             (match_operand:SI 2 "and_operand" ""))
2347                     (const_int 0)))
2348    (set (match_operand:SI 0 "gpc_reg_operand" "")
2349         (and:SI (match_dup 1)
2350                 (match_dup 2)))
2351    (clobber (match_scratch:CC 4 ""))]
2352   "reload_completed"
2353   [(parallel [(set (match_dup 0)
2354                    (and:SI (match_dup 1)
2355                            (match_dup 2)))
2356               (clobber (match_dup 4))])
2357    (set (match_dup 3)
2358         (compare:CC (match_dup 0)
2359                     (const_int 0)))]
2360   "")
2361
2362 (define_split
2363   [(set (match_operand:CC 3 "cc_reg_operand" "")
2364         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2365                             (match_operand:SI 2 "gpc_reg_operand" ""))
2366                     (const_int 0)))
2367    (set (match_operand:SI 0 "gpc_reg_operand" "")
2368         (and:SI (match_dup 1)
2369                 (match_dup 2)))
2370    (clobber (match_scratch:CC 4 ""))]
2371   "TARGET_POWERPC64 && reload_completed"
2372   [(parallel [(set (match_dup 0)
2373                    (and:SI (match_dup 1)
2374                            (match_dup 2)))
2375               (clobber (match_dup 4))])
2376    (set (match_dup 3)
2377         (compare:CC (match_dup 0)
2378                     (const_int 0)))]
2379   "")
2380
2381 ;; Handle the PowerPC64 rlwinm corner case
2382
2383 (define_insn_and_split "*andsi3_internal6"
2384   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2385         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2386                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
2387   "TARGET_POWERPC64"
2388   "#"
2389   "TARGET_POWERPC64"
2390   [(set (match_dup 0)
2391         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
2392                 (match_dup 4)))
2393    (set (match_dup 0)
2394         (rotate:SI (match_dup 0) (match_dup 5)))]
2395   "
2396 {
2397   int mb = extract_MB (operands[2]);
2398   int me = extract_ME (operands[2]);
2399   operands[3] = GEN_INT (me + 1);
2400   operands[5] = GEN_INT (32 - (me + 1));
2401   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2402 }"
2403   [(set_attr "length" "8")])
2404
2405 (define_insn_and_split "*andsi3_internal7"
2406   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2407         (compare:CC (and:SI (match_operand:SI 0 "gpc_reg_operand" "r,r")
2408                             (match_operand:SI 1 "mask_operand_wrap" "i,i"))
2409                     (const_int 0)))
2410    (clobber (match_scratch:SI 3 "=r,r"))]
2411   "TARGET_POWERPC64"
2412   "#"
2413   "TARGET_POWERPC64"
2414   [(parallel [(set (match_dup 2)
2415                    (compare:CC (and:SI (rotate:SI (match_dup 0) (match_dup 4))
2416                                        (match_dup 5))
2417                                (const_int 0)))
2418               (clobber (match_dup 3))])]
2419   "
2420 {
2421   int mb = extract_MB (operands[1]);
2422   int me = extract_ME (operands[1]);
2423   operands[4] = GEN_INT (me + 1);
2424   operands[5] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2425 }"
2426   [(set_attr "type" "delayed_compare,compare")
2427    (set_attr "length" "4,8")])
2428
2429 (define_insn_and_split "*andsi3_internal8"
2430   [(set (match_operand:CC 3 "cc_reg_operand" "=x,??y")
2431         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2432                             (match_operand:SI 2 "mask_operand_wrap" "i,i"))
2433                     (const_int 0)))
2434    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2435         (and:SI (match_dup 1)
2436                 (match_dup 2)))]
2437   "TARGET_POWERPC64"
2438   "#"
2439   "TARGET_POWERPC64"
2440   [(parallel [(set (match_dup 3)
2441                    (compare:CC (and:SI (rotate:SI (match_dup 1) (match_dup 4))
2442                                        (match_dup 5))
2443                                (const_int 0)))
2444               (set (match_dup 0)
2445                    (and:SI (rotate:SI (match_dup 1) (match_dup 4))
2446                            (match_dup 5)))])
2447    (set (match_dup 0)
2448         (rotate:SI (match_dup 0) (match_dup 6)))]
2449   "
2450 {
2451   int mb = extract_MB (operands[2]);
2452   int me = extract_ME (operands[2]);
2453   operands[4] = GEN_INT (me + 1);
2454   operands[6] = GEN_INT (32 - (me + 1));
2455   operands[5] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2456 }"
2457   [(set_attr "type" "delayed_compare,compare")
2458    (set_attr "length" "8,12")])
2459
2460 (define_expand "iorsi3"
2461   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2462         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
2463                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2464   ""
2465   "
2466 {
2467   if (GET_CODE (operands[2]) == CONST_INT
2468       && ! logical_operand (operands[2], SImode))
2469     {
2470       HOST_WIDE_INT value = INTVAL (operands[2]);
2471       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2472                  ? operands[0] : gen_reg_rtx (SImode));
2473
2474       emit_insn (gen_iorsi3 (tmp, operands[1],
2475                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2476       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2477       DONE;
2478     }
2479 }")
2480
2481 (define_expand "xorsi3"
2482   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2483         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
2484                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2485   ""
2486   "
2487 {
2488   if (GET_CODE (operands[2]) == CONST_INT
2489       && ! logical_operand (operands[2], SImode))
2490     {
2491       HOST_WIDE_INT value = INTVAL (operands[2]);
2492       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2493                  ? operands[0] : gen_reg_rtx (SImode));
2494
2495       emit_insn (gen_xorsi3 (tmp, operands[1],
2496                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2497       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2498       DONE;
2499     }
2500 }")
2501
2502 (define_insn "*boolsi3_internal1"
2503   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
2504         (match_operator:SI 3 "boolean_or_operator"
2505          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
2506           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
2507   ""
2508   "@
2509    %q3 %0,%1,%2
2510    {%q3il|%q3i} %0,%1,%b2
2511    {%q3iu|%q3is} %0,%1,%u2")
2512
2513 (define_insn "*boolsi3_internal2"
2514   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2515         (compare:CC (match_operator:SI 4 "boolean_or_operator"
2516          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2517           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2518          (const_int 0)))
2519    (clobber (match_scratch:SI 3 "=r,r"))]
2520   "TARGET_32BIT"
2521   "@
2522    %q4. %3,%1,%2
2523    #"
2524   [(set_attr "type" "compare")
2525    (set_attr "length" "4,8")])
2526
2527 (define_split
2528   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2529         (compare:CC (match_operator:SI 4 "boolean_operator"
2530          [(match_operand:SI 1 "gpc_reg_operand" "")
2531           (match_operand:SI 2 "gpc_reg_operand" "")])
2532          (const_int 0)))
2533    (clobber (match_scratch:SI 3 ""))]
2534   "TARGET_32BIT && reload_completed"
2535   [(set (match_dup 3) (match_dup 4))
2536    (set (match_dup 0)
2537         (compare:CC (match_dup 3)
2538                     (const_int 0)))]
2539   "")
2540
2541 (define_insn "*boolsi3_internal3"
2542   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2543         (compare:CC (match_operator:SI 4 "boolean_operator"
2544          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2545           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2546          (const_int 0)))
2547    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2548         (match_dup 4))]
2549   "TARGET_32BIT"
2550   "@
2551    %q4. %0,%1,%2
2552    #"
2553   [(set_attr "type" "compare")
2554    (set_attr "length" "4,8")])
2555
2556 (define_split
2557   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2558         (compare:CC (match_operator:SI 4 "boolean_operator"
2559          [(match_operand:SI 1 "gpc_reg_operand" "")
2560           (match_operand:SI 2 "gpc_reg_operand" "")])
2561          (const_int 0)))
2562    (set (match_operand:SI 0 "gpc_reg_operand" "")
2563         (match_dup 4))]
2564   "TARGET_32BIT && reload_completed"
2565   [(set (match_dup 0) (match_dup 4))
2566    (set (match_dup 3)
2567         (compare:CC (match_dup 0)
2568                     (const_int 0)))]
2569   "")
2570
2571 ;; Split a logical operation that we can't do in one insn into two insns, 
2572 ;; each of which does one 16-bit part.  This is used by combine.
2573
2574 (define_split
2575   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2576         (match_operator:SI 3 "boolean_or_operator"
2577          [(match_operand:SI 1 "gpc_reg_operand" "")
2578           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
2579   ""
2580   [(set (match_dup 0) (match_dup 4))
2581    (set (match_dup 0) (match_dup 5))]
2582 "
2583 {
2584   rtx i;
2585   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
2586   operands[4] = gen_rtx (GET_CODE (operands[3]), SImode,
2587                          operands[1], i);
2588   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
2589   operands[5] = gen_rtx (GET_CODE (operands[3]), SImode,
2590                          operands[0], i);
2591 }")
2592
2593 (define_insn "*boolcsi3_internal1"
2594   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2595         (match_operator:SI 3 "boolean_operator"
2596          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
2597           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
2598   ""
2599   "%q3 %0,%2,%1")
2600
2601 (define_insn "*boolcsi3_internal2"
2602   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2603         (compare:CC (match_operator:SI 4 "boolean_operator"
2604          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2605           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2606          (const_int 0)))
2607    (clobber (match_scratch:SI 3 "=r,r"))]
2608   "TARGET_32BIT"
2609   "@
2610    %q4. %3,%2,%1
2611    #"
2612   [(set_attr "type" "compare")
2613    (set_attr "length" "4,8")])
2614
2615 (define_split
2616   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2617         (compare:CC (match_operator:SI 4 "boolean_operator"
2618          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2619           (match_operand:SI 2 "gpc_reg_operand" "")])
2620          (const_int 0)))
2621    (clobber (match_scratch:SI 3 ""))]
2622   "TARGET_32BIT && reload_completed"
2623   [(set (match_dup 3) (match_dup 4))
2624    (set (match_dup 0)
2625         (compare:CC (match_dup 3)
2626                     (const_int 0)))]
2627   "")
2628
2629 (define_insn "*boolcsi3_internal3"
2630   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2631         (compare:CC (match_operator:SI 4 "boolean_operator"
2632          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
2633           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2634          (const_int 0)))
2635    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2636         (match_dup 4))]
2637   "TARGET_32BIT"
2638   "@
2639    %q4. %0,%2,%1
2640    #"
2641   [(set_attr "type" "compare")
2642    (set_attr "length" "4,8")])
2643
2644 (define_split
2645   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2646         (compare:CC (match_operator:SI 4 "boolean_operator"
2647          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2648           (match_operand:SI 2 "gpc_reg_operand" "")])
2649          (const_int 0)))
2650    (set (match_operand:SI 0 "gpc_reg_operand" "")
2651         (match_dup 4))]
2652   "TARGET_32BIT && reload_completed"
2653   [(set (match_dup 0) (match_dup 4))
2654    (set (match_dup 3)
2655         (compare:CC (match_dup 0)
2656                     (const_int 0)))]
2657   "")
2658
2659 (define_insn "*boolccsi3_internal1"
2660   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2661         (match_operator:SI 3 "boolean_operator"
2662          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
2663           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
2664   ""
2665   "%q3 %0,%1,%2")
2666
2667 (define_insn "*boolccsi3_internal2"
2668   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2669         (compare:CC (match_operator:SI 4 "boolean_operator"
2670          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2671           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
2672          (const_int 0)))
2673    (clobber (match_scratch:SI 3 "=r,r"))]
2674   "TARGET_32BIT"
2675   "@
2676    %q4. %3,%1,%2
2677    #"
2678   [(set_attr "type" "compare")
2679    (set_attr "length" "4,8")])
2680
2681 (define_split
2682   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2683         (compare:CC (match_operator:SI 4 "boolean_operator"
2684          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2685           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
2686          (const_int 0)))
2687    (clobber (match_scratch:SI 3 ""))]
2688   "TARGET_32BIT && reload_completed"
2689   [(set (match_dup 3) (match_dup 4))
2690    (set (match_dup 0)
2691         (compare:CC (match_dup 3)
2692                     (const_int 0)))]
2693   "")
2694
2695 (define_insn "*boolccsi3_internal3"
2696   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2697         (compare:CC (match_operator:SI 4 "boolean_operator"
2698          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
2699           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
2700          (const_int 0)))
2701    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2702         (match_dup 4))]
2703   "TARGET_32BIT"
2704   "@
2705    %q4. %0,%1,%2
2706    #"
2707   [(set_attr "type" "compare")
2708    (set_attr "length" "4,8")])
2709
2710 (define_split
2711   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2712         (compare:CC (match_operator:SI 4 "boolean_operator"
2713          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2714           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
2715          (const_int 0)))
2716    (set (match_operand:SI 0 "gpc_reg_operand" "")
2717         (match_dup 4))]
2718   "TARGET_32BIT && reload_completed"
2719   [(set (match_dup 0) (match_dup 4))
2720    (set (match_dup 3)
2721         (compare:CC (match_dup 0)
2722                     (const_int 0)))]
2723   "")
2724
2725 ;; maskir insn.  We need four forms because things might be in arbitrary
2726 ;; orders.  Don't define forms that only set CR fields because these
2727 ;; would modify an input register.
2728
2729 (define_insn "*maskir_internal1"
2730   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2731         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
2732                         (match_operand:SI 1 "gpc_reg_operand" "0"))
2733                 (and:SI (match_dup 2)
2734                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
2735   "TARGET_POWER"
2736   "maskir %0,%3,%2")
2737
2738 (define_insn "*maskir_internal2"
2739   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2740         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
2741                         (match_operand:SI 1 "gpc_reg_operand" "0"))
2742                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2743                         (match_dup 2))))]
2744   "TARGET_POWER"
2745   "maskir %0,%3,%2")
2746
2747 (define_insn "*maskir_internal3"
2748   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2749         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2750                         (match_operand:SI 3 "gpc_reg_operand" "r"))
2751                 (and:SI (not:SI (match_dup 2))
2752                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
2753   "TARGET_POWER"
2754   "maskir %0,%3,%2")
2755
2756 (define_insn "*maskir_internal4"
2757   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2758         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2759                         (match_operand:SI 2 "gpc_reg_operand" "r"))
2760                 (and:SI (not:SI (match_dup 2))
2761                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
2762   "TARGET_POWER"
2763   "maskir %0,%3,%2")
2764
2765 (define_insn "*maskir_internal5"
2766   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2767         (compare:CC
2768          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2769                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
2770                  (and:SI (match_dup 2)
2771                          (match_operand:SI 3 "gpc_reg_operand" "r,r")))
2772          (const_int 0)))
2773    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2774         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2775                 (and:SI (match_dup 2) (match_dup 3))))]
2776   "TARGET_POWER"
2777   "@
2778    maskir. %0,%3,%2
2779    #"
2780   [(set_attr "type" "compare")
2781    (set_attr "length" "4,8")])
2782
2783 (define_split
2784   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2785         (compare:CC
2786          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
2787                          (match_operand:SI 1 "gpc_reg_operand" ""))
2788                  (and:SI (match_dup 2)
2789                          (match_operand:SI 3 "gpc_reg_operand" "")))
2790          (const_int 0)))
2791    (set (match_operand:SI 0 "gpc_reg_operand" "")
2792         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2793                 (and:SI (match_dup 2) (match_dup 3))))]
2794   "TARGET_POWER && reload_completed"
2795   [(set (match_dup 0)
2796         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2797                 (and:SI (match_dup 2) (match_dup 3))))
2798    (set (match_dup 4)
2799         (compare:CC (match_dup 0)
2800                     (const_int 0)))]
2801   "")
2802
2803 (define_insn "*maskir_internal6"
2804   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2805         (compare:CC
2806          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2807                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
2808                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
2809                          (match_dup 2)))
2810          (const_int 0)))
2811    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2812         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2813                 (and:SI (match_dup 3) (match_dup 2))))]
2814   "TARGET_POWER"
2815   "@
2816    maskir. %0,%3,%2
2817    #"
2818   [(set_attr "type" "compare")
2819    (set_attr "length" "4,8")])
2820
2821 (define_split
2822   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2823         (compare:CC
2824          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
2825                          (match_operand:SI 1 "gpc_reg_operand" ""))
2826                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
2827                          (match_dup 2)))
2828          (const_int 0)))
2829    (set (match_operand:SI 0 "gpc_reg_operand" "")
2830         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2831                 (and:SI (match_dup 3) (match_dup 2))))]
2832   "TARGET_POWER && reload_completed"
2833   [(set (match_dup 0)
2834         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2835                 (and:SI (match_dup 3) (match_dup 2))))
2836    (set (match_dup 4)
2837         (compare:CC (match_dup 0)
2838                     (const_int 0)))]
2839   "")
2840
2841 (define_insn "*maskir_internal7"
2842   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2843         (compare:CC
2844          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r,r")
2845                          (match_operand:SI 3 "gpc_reg_operand" "r,r"))
2846                  (and:SI (not:SI (match_dup 2))
2847                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
2848          (const_int 0)))
2849    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2850         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2851                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2852   "TARGET_POWER"
2853   "@
2854    maskir. %0,%3,%2
2855    #"
2856   [(set_attr "type" "compare")
2857    (set_attr "length" "4,8")])
2858
2859 (define_split
2860   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2861         (compare:CC
2862          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "")
2863                          (match_operand:SI 3 "gpc_reg_operand" ""))
2864                  (and:SI (not:SI (match_dup 2))
2865                          (match_operand:SI 1 "gpc_reg_operand" "")))
2866          (const_int 0)))
2867    (set (match_operand:SI 0 "gpc_reg_operand" "")
2868         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2869                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2870   "TARGET_POWER && reload_completed"
2871   [(set (match_dup 0)
2872         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2873                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
2874    (set (match_dup 4)
2875         (compare:CC (match_dup 0)
2876                     (const_int 0)))]
2877   "")
2878
2879 (define_insn "*maskir_internal8"
2880   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2881         (compare:CC
2882          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
2883                          (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2884                  (and:SI (not:SI (match_dup 2))
2885                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
2886          (const_int 0)))
2887    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2888         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2889                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2890   "TARGET_POWER"
2891   "@
2892    maskir. %0,%3,%2
2893    #"
2894   [(set_attr "type" "compare")
2895    (set_attr "length" "4,8")])
2896
2897 (define_split
2898   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2899         (compare:CC
2900          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
2901                          (match_operand:SI 2 "gpc_reg_operand" ""))
2902                  (and:SI (not:SI (match_dup 2))
2903                          (match_operand:SI 1 "gpc_reg_operand" "")))
2904          (const_int 0)))
2905    (set (match_operand:SI 0 "gpc_reg_operand" "")
2906         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2907                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2908   "TARGET_POWER && reload_completed"
2909   [(set (match_dup 0)
2910         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2911                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
2912    (set (match_dup 4)
2913         (compare:CC (match_dup 0)
2914                     (const_int 0)))]
2915   "")
2916 \f
2917 ;; Rotate and shift insns, in all their variants.  These support shifts,
2918 ;; field inserts and extracts, and various combinations thereof.
2919 (define_expand "insv"
2920   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
2921                        (match_operand:SI 1 "const_int_operand" "")
2922                        (match_operand:SI 2 "const_int_operand" ""))
2923         (match_operand 3 "gpc_reg_operand" ""))]
2924   ""
2925   "
2926 {
2927   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
2928      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
2929      compiler if the address of the structure is taken later.  */
2930   if (GET_CODE (operands[0]) == SUBREG
2931       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
2932     FAIL;
2933
2934   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
2935     emit_insn (gen_insvdi (operands[0], operands[1], operands[2], operands[3]));
2936   else
2937     emit_insn (gen_insvsi (operands[0], operands[1], operands[2], operands[3]));
2938   DONE;
2939 }")
2940
2941 (define_insn "insvsi"
2942   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2943                          (match_operand:SI 1 "const_int_operand" "i")
2944                          (match_operand:SI 2 "const_int_operand" "i"))
2945         (match_operand:SI 3 "gpc_reg_operand" "r"))]
2946   ""
2947   "*
2948 {
2949   int start = INTVAL (operands[2]) & 31;
2950   int size = INTVAL (operands[1]) & 31;
2951
2952   operands[4] = GEN_INT (32 - start - size);
2953   operands[1] = GEN_INT (start + size - 1);
2954   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2955 }"
2956   [(set_attr "type" "insert_word")])
2957
2958 (define_insn "*insvsi_internal1"
2959   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2960                          (match_operand:SI 1 "const_int_operand" "i")
2961                          (match_operand:SI 2 "const_int_operand" "i"))
2962         (ashift:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2963                    (match_operand:SI 4 "const_int_operand" "i")))]
2964   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
2965   "*
2966 {
2967   int shift = INTVAL (operands[4]) & 31;
2968   int start = INTVAL (operands[2]) & 31;
2969   int size = INTVAL (operands[1]) & 31;
2970
2971   operands[4] = GEN_INT (shift - start - size);
2972   operands[1] = GEN_INT (start + size - 1);
2973   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2974 }"
2975   [(set_attr "type" "insert_word")])
2976
2977 (define_insn "*insvsi_internal2"
2978   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2979                          (match_operand:SI 1 "const_int_operand" "i")
2980                          (match_operand:SI 2 "const_int_operand" "i"))
2981         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2982                      (match_operand:SI 4 "const_int_operand" "i")))]
2983   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
2984   "*
2985 {
2986   int shift = INTVAL (operands[4]) & 31;
2987   int start = INTVAL (operands[2]) & 31;
2988   int size = INTVAL (operands[1]) & 31;
2989
2990   operands[4] = GEN_INT (32 - shift - start - size);
2991   operands[1] = GEN_INT (start + size - 1);
2992   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2993 }"
2994   [(set_attr "type" "insert_word")])
2995
2996 (define_insn "*insvsi_internal3"
2997   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2998                          (match_operand:SI 1 "const_int_operand" "i")
2999                          (match_operand:SI 2 "const_int_operand" "i"))
3000         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3001                      (match_operand:SI 4 "const_int_operand" "i")))]
3002   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3003   "*
3004 {
3005   int shift = INTVAL (operands[4]) & 31;
3006   int start = INTVAL (operands[2]) & 31;
3007   int size = INTVAL (operands[1]) & 31;
3008
3009   operands[4] = GEN_INT (32 - shift - start - size);
3010   operands[1] = GEN_INT (start + size - 1);
3011   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3012 }"
3013   [(set_attr "type" "insert_word")])
3014
3015 (define_insn "*insvsi_internal4"
3016   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3017                          (match_operand:SI 1 "const_int_operand" "i")
3018                          (match_operand:SI 2 "const_int_operand" "i"))
3019         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3020                          (match_operand:SI 4 "const_int_operand" "i")
3021                          (match_operand:SI 5 "const_int_operand" "i")))]
3022   "INTVAL (operands[4]) >= INTVAL (operands[1])"
3023   "*
3024 {
3025   int extract_start = INTVAL (operands[5]) & 31;
3026   int extract_size = INTVAL (operands[4]) & 31;
3027   int insert_start = INTVAL (operands[2]) & 31;
3028   int insert_size = INTVAL (operands[1]) & 31;
3029
3030 /* Align extract field with insert field */
3031   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
3032   operands[1] = GEN_INT (insert_start + insert_size - 1);
3033   return \"{rlimi|rlwimi} %0,%3,%h5,%h2,%h1\";
3034 }"
3035   [(set_attr "type" "insert_word")])
3036
3037 (define_insn "insvdi"
3038   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3039                          (match_operand:SI 1 "const_int_operand" "i")
3040                          (match_operand:SI 2 "const_int_operand" "i"))
3041         (match_operand:DI 3 "gpc_reg_operand" "r"))]
3042   "TARGET_POWERPC64"
3043   "*
3044 {
3045   int start = INTVAL (operands[2]) & 63;
3046   int size = INTVAL (operands[1]) & 63;
3047
3048   operands[1] = GEN_INT (64 - start - size);
3049   return \"rldimi %0,%3,%H1,%H2\";
3050 }")
3051
3052 (define_expand "extzv"
3053   [(set (match_operand 0 "gpc_reg_operand" "")
3054         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3055                        (match_operand:SI 2 "const_int_operand" "")
3056                        (match_operand:SI 3 "const_int_operand" "")))]
3057   ""
3058   "
3059 {
3060   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3061      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3062      compiler if the address of the structure is taken later.  */
3063   if (GET_CODE (operands[0]) == SUBREG
3064       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3065     FAIL;
3066
3067   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3068     emit_insn (gen_extzvdi (operands[0], operands[1], operands[2], operands[3]));
3069   else
3070     emit_insn (gen_extzvsi (operands[0], operands[1], operands[2], operands[3]));
3071   DONE;
3072 }")
3073
3074 (define_insn "extzvsi"
3075   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3076         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3077                          (match_operand:SI 2 "const_int_operand" "i")
3078                          (match_operand:SI 3 "const_int_operand" "i")))]
3079   ""
3080   "*
3081 {
3082   int start = INTVAL (operands[3]) & 31;
3083   int size = INTVAL (operands[2]) & 31;
3084
3085   if (start + size >= 32)
3086     operands[3] = const0_rtx;
3087   else
3088     operands[3] = GEN_INT (start + size);
3089   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
3090 }")
3091
3092 (define_insn "*extzvsi_internal1"
3093   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3094         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3095                          (match_operand:SI 2 "const_int_operand" "i,i")
3096                          (match_operand:SI 3 "const_int_operand" "i,i"))
3097                     (const_int 0)))
3098    (clobber (match_scratch:SI 4 "=r,r"))]
3099   ""
3100   "*
3101 {
3102   int start = INTVAL (operands[3]) & 31;
3103   int size = INTVAL (operands[2]) & 31;
3104
3105   /* Force split for non-cc0 compare.  */
3106   if (which_alternative == 1)
3107      return \"#\";
3108
3109   /* If the bit-field being tested fits in the upper or lower half of a
3110      word, it is possible to use andiu. or andil. to test it.  This is
3111      useful because the condition register set-use delay is smaller for
3112      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3113      position is 0 because the LT and GT bits may be set wrong.  */
3114
3115   if ((start > 0 && start + size <= 16) || start >= 16)
3116     {
3117       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3118                               - (1 << (16 - (start & 15) - size))));
3119       if (start < 16)
3120         return \"{andiu.|andis.} %4,%1,%3\";
3121       else
3122         return \"{andil.|andi.} %4,%1,%3\";
3123     }
3124
3125   if (start + size >= 32)
3126     operands[3] = const0_rtx;
3127   else
3128     operands[3] = GEN_INT (start + size);
3129   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
3130 }"
3131   [(set_attr "type" "compare")
3132    (set_attr "length" "4,8")])
3133
3134 (define_split
3135   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3136         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3137                          (match_operand:SI 2 "const_int_operand" "")
3138                          (match_operand:SI 3 "const_int_operand" ""))
3139                     (const_int 0)))
3140    (clobber (match_scratch:SI 4 ""))]
3141   "reload_completed"
3142   [(set (match_dup 4)
3143         (zero_extract:SI (match_dup 1) (match_dup 2)
3144                          (match_dup 3)))
3145    (set (match_dup 0)
3146         (compare:CC (match_dup 4)
3147                     (const_int 0)))]
3148   "")
3149
3150 (define_insn "*extzvsi_internal2"
3151   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3152         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3153                          (match_operand:SI 2 "const_int_operand" "i,i")
3154                          (match_operand:SI 3 "const_int_operand" "i,i"))
3155                     (const_int 0)))
3156    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3157         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3158   ""
3159   "*
3160 {
3161   int start = INTVAL (operands[3]) & 31;
3162   int size = INTVAL (operands[2]) & 31;
3163
3164   /* Force split for non-cc0 compare.  */
3165   if (which_alternative == 1)
3166      return \"#\";
3167
3168   /* Since we are using the output value, we can't ignore any need for
3169      a shift.  The bit-field must end at the LSB.  */
3170   if (start >= 16 && start + size == 32)
3171     {
3172       operands[3] = GEN_INT ((1 << size) - 1);
3173       return \"{andil.|andi.} %0,%1,%3\";
3174     }
3175
3176   if (start + size >= 32)
3177     operands[3] = const0_rtx;
3178   else
3179     operands[3] = GEN_INT (start + size);
3180   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
3181 }"
3182   [(set_attr "type" "compare")
3183    (set_attr "length" "4,8")])
3184
3185 (define_split
3186   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3187         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3188                          (match_operand:SI 2 "const_int_operand" "")
3189                          (match_operand:SI 3 "const_int_operand" ""))
3190                     (const_int 0)))
3191    (set (match_operand:SI 0 "gpc_reg_operand" "")
3192         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3193   "reload_completed"
3194   [(set (match_dup 0)
3195         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3196    (set (match_dup 4)
3197         (compare:CC (match_dup 0)
3198                     (const_int 0)))]
3199   "")
3200
3201 (define_insn "extzvdi"
3202   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3203         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3204                          (match_operand:SI 2 "const_int_operand" "i")
3205                          (match_operand:SI 3 "const_int_operand" "i")))]
3206   "TARGET_POWERPC64"
3207   "*
3208 {
3209   int start = INTVAL (operands[3]) & 63;
3210   int size = INTVAL (operands[2]) & 63;
3211
3212   if (start + size >= 64)
3213     operands[3] = const0_rtx;
3214   else
3215     operands[3] = GEN_INT (start + size);
3216   operands[2] = GEN_INT (64 - size);
3217   return \"rldicl %0,%1,%3,%2\";
3218 }")
3219
3220 (define_insn "*extzvdi_internal1"
3221   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3222         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3223                          (match_operand:SI 2 "const_int_operand" "i")
3224                          (match_operand:SI 3 "const_int_operand" "i"))
3225                     (const_int 0)))
3226    (clobber (match_scratch:DI 4 "=r"))]
3227   "TARGET_64BIT"
3228   "*
3229 {
3230   int start = INTVAL (operands[3]) & 63;
3231   int size = INTVAL (operands[2]) & 63;
3232
3233   if (start + size >= 64)
3234     operands[3] = const0_rtx;
3235   else
3236     operands[3] = GEN_INT (start + size);
3237   operands[2] = GEN_INT (64 - size);
3238   return \"rldicl. %4,%1,%3,%2\";
3239 }")
3240
3241 (define_insn "*extzvdi_internal2"
3242   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3243         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3244                          (match_operand:SI 2 "const_int_operand" "i")
3245                          (match_operand:SI 3 "const_int_operand" "i"))
3246                     (const_int 0)))
3247    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3248         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3249   "TARGET_64BIT"
3250   "*
3251 {
3252   int start = INTVAL (operands[3]) & 63;
3253   int size = INTVAL (operands[2]) & 63;
3254
3255   if (start + size >= 64)
3256     operands[3] = const0_rtx;
3257   else
3258     operands[3] = GEN_INT (start + size);
3259   operands[2] = GEN_INT (64 - size);
3260   return \"rldicl. %0,%1,%3,%2\";
3261 }")
3262
3263 (define_insn "rotlsi3"
3264   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3265         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3266                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3267   ""
3268   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffffffff")
3269
3270 (define_insn "*rotlsi3_internal2"
3271   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3272         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3273                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3274                     (const_int 0)))
3275    (clobber (match_scratch:SI 3 "=r,r"))]
3276   ""
3277   "@
3278    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffffffff
3279    #"
3280   [(set_attr "type" "delayed_compare")
3281    (set_attr "length" "4,8")])
3282
3283 (define_split
3284   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3285         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3286                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3287                     (const_int 0)))
3288    (clobber (match_scratch:SI 3 ""))]
3289   "reload_completed"
3290   [(set (match_dup 3)
3291         (rotate:SI (match_dup 1) (match_dup 2)))
3292    (set (match_dup 0)
3293         (compare:CC (match_dup 3)
3294                     (const_int 0)))]
3295   "")
3296
3297 (define_insn "*rotlsi3_internal3"
3298   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3299         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3300                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3301                     (const_int 0)))
3302    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3303         (rotate:SI (match_dup 1) (match_dup 2)))]
3304   ""
3305   "@
3306    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffffffff
3307    #"
3308   [(set_attr "type" "delayed_compare")
3309    (set_attr "length" "4,8")])
3310
3311 (define_split
3312   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3313         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3314                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3315                     (const_int 0)))
3316    (set (match_operand:SI 0 "gpc_reg_operand" "")
3317         (rotate:SI (match_dup 1) (match_dup 2)))]
3318   "reload_completed"
3319   [(set (match_dup 0)
3320         (rotate:SI (match_dup 1) (match_dup 2)))
3321    (set (match_dup 3)
3322         (compare:CC (match_dup 0)
3323                     (const_int 0)))]
3324   "")
3325
3326 (define_insn "*rotlsi3_internal4"
3327   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3328         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3329                            (match_operand:SI 2 "reg_or_cint_operand" "ri"))
3330                 (match_operand:SI 3 "mask_operand" "n")))]
3331   ""
3332   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,%m3,%M3")
3333
3334 (define_insn "*rotlsi3_internal5"
3335   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3336         (compare:CC (and:SI
3337                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3338                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3339                      (match_operand:SI 3 "mask_operand" "n,n"))
3340                     (const_int 0)))
3341    (clobber (match_scratch:SI 4 "=r,r"))]
3342   ""
3343   "@
3344    {rl%I2nm.|rlw%I2nm.} %4,%1,%h2,%m3,%M3
3345    #"
3346   [(set_attr "type" "delayed_compare")
3347    (set_attr "length" "4,8")])
3348
3349 (define_split
3350   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3351         (compare:CC (and:SI
3352                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3353                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3354                      (match_operand:SI 3 "mask_operand" ""))
3355                     (const_int 0)))
3356    (clobber (match_scratch:SI 4 ""))]
3357   "reload_completed"
3358   [(set (match_dup 4)
3359         (and:SI (rotate:SI (match_dup 1)
3360                                 (match_dup 2))
3361                      (match_dup 3)))
3362    (set (match_dup 0)
3363         (compare:CC (match_dup 4)
3364                     (const_int 0)))]
3365   "")
3366
3367 (define_insn "*rotlsi3_internal6"
3368   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3369         (compare:CC (and:SI
3370                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3371                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3372                      (match_operand:SI 3 "mask_operand" "n,n"))
3373                     (const_int 0)))
3374    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3375         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3376   ""
3377   "@
3378    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,%m3,%M3
3379    #"
3380   [(set_attr "type" "delayed_compare")
3381    (set_attr "length" "4,8")])
3382
3383 (define_split
3384   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3385         (compare:CC (and:SI
3386                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3387                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3388                      (match_operand:SI 3 "mask_operand" ""))
3389                     (const_int 0)))
3390    (set (match_operand:SI 0 "gpc_reg_operand" "")
3391         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3392   "reload_completed"
3393   [(set (match_dup 0)
3394         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3395    (set (match_dup 4)
3396         (compare:CC (match_dup 0)
3397                     (const_int 0)))]
3398   "")
3399
3400 (define_insn "*rotlsi3_internal7"
3401   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3402         (zero_extend:SI
3403          (subreg:QI
3404           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3405                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3406   ""
3407   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff")
3408
3409 (define_insn "*rotlsi3_internal8"
3410   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3411         (compare:CC (zero_extend:SI
3412                      (subreg:QI
3413                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3414                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3415                     (const_int 0)))
3416    (clobber (match_scratch:SI 3 "=r,r"))]
3417   ""
3418   "@
3419    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xff
3420    #"
3421   [(set_attr "type" "delayed_compare")
3422    (set_attr "length" "4,8")])
3423
3424 (define_split
3425   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3426         (compare:CC (zero_extend:SI
3427                      (subreg:QI
3428                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3429                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3430                     (const_int 0)))
3431    (clobber (match_scratch:SI 3 ""))]
3432   "reload_completed"
3433   [(set (match_dup 3)
3434         (zero_extend:SI (subreg:QI
3435                       (rotate:SI (match_dup 1)
3436                                  (match_dup 2)) 0)))
3437    (set (match_dup 0)
3438         (compare:CC (match_dup 3)
3439                     (const_int 0)))]
3440   "")
3441
3442 (define_insn "*rotlsi3_internal9"
3443   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3444         (compare:CC (zero_extend:SI
3445                      (subreg:QI
3446                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3447                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3448                     (const_int 0)))
3449    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3450         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3451   ""
3452   "@
3453    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xff
3454    #"
3455   [(set_attr "type" "delayed_compare")
3456    (set_attr "length" "4,8")])
3457
3458 (define_split
3459   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3460         (compare:CC (zero_extend:SI
3461                      (subreg:QI
3462                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3463                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3464                     (const_int 0)))
3465    (set (match_operand:SI 0 "gpc_reg_operand" "")
3466         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3467   "reload_completed"
3468   [(set (match_dup 0)
3469         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3470    (set (match_dup 3)
3471         (compare:CC (match_dup 0)
3472                     (const_int 0)))]
3473   "")
3474
3475 (define_insn "*rotlsi3_internal10"
3476   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3477         (zero_extend:SI
3478          (subreg:HI
3479           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3480                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3481   ""
3482   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffff")
3483
3484 (define_insn "*rotlsi3_internal11"
3485   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3486         (compare:CC (zero_extend:SI
3487                      (subreg:HI
3488                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3489                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3490                     (const_int 0)))
3491    (clobber (match_scratch:SI 3 "=r,r"))]
3492   ""
3493   "@
3494    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffff
3495    #"
3496   [(set_attr "type" "delayed_compare")
3497    (set_attr "length" "4,8")])
3498
3499 (define_split
3500   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3501         (compare:CC (zero_extend:SI
3502                      (subreg:HI
3503                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3504                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3505                     (const_int 0)))
3506    (clobber (match_scratch:SI 3 ""))]
3507   "reload_completed"
3508   [(set (match_dup 3)
3509         (zero_extend:SI (subreg:HI
3510                       (rotate:SI (match_dup 1)
3511                                  (match_dup 2)) 0)))
3512    (set (match_dup 0)
3513         (compare:CC (match_dup 3)
3514                     (const_int 0)))]
3515   "")
3516
3517 (define_insn "*rotlsi3_internal12"
3518   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3519         (compare:CC (zero_extend:SI
3520                      (subreg:HI
3521                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3522                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3523                     (const_int 0)))
3524    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3525         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3526   ""
3527   "@
3528    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffff
3529    #"
3530   [(set_attr "type" "delayed_compare")
3531    (set_attr "length" "4,8")])
3532
3533 (define_split
3534   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3535         (compare:CC (zero_extend:SI
3536                      (subreg:HI
3537                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3538                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3539                     (const_int 0)))
3540    (set (match_operand:SI 0 "gpc_reg_operand" "")
3541         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3542   "reload_completed"
3543   [(set (match_dup 0)
3544         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3545    (set (match_dup 3)
3546         (compare:CC (match_dup 0)
3547                     (const_int 0)))]
3548   "")
3549
3550 ;; Note that we use "sle." instead of "sl." so that we can set
3551 ;; SHIFT_COUNT_TRUNCATED.
3552
3553 (define_expand "ashlsi3"
3554   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
3555    (use (match_operand:SI 1 "gpc_reg_operand" ""))
3556    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
3557   ""
3558   "
3559 {
3560   if (TARGET_POWER)
3561     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
3562   else
3563     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
3564   DONE;
3565 }")
3566
3567 (define_insn "ashlsi3_power"
3568   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3569         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3570                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
3571    (clobber (match_scratch:SI 3 "=q,X"))]
3572   "TARGET_POWER"
3573   "@
3574    sle %0,%1,%2
3575    {sli|slwi} %0,%1,%h2")
3576
3577 (define_insn "ashlsi3_no_power"
3578   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3579         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3580                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3581   "! TARGET_POWER"
3582   "{sl|slw}%I2 %0,%1,%h2")
3583
3584 (define_insn ""
3585   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3586         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3587                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3588                     (const_int 0)))
3589    (clobber (match_scratch:SI 3 "=r,r,r,r"))
3590    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
3591   "TARGET_POWER"
3592   "@
3593    sle. %3,%1,%2
3594    {sli.|slwi.} %3,%1,%h2
3595    #
3596    #"
3597   [(set_attr "type" "delayed_compare")
3598    (set_attr "length" "4,4,8,8")])
3599
3600 (define_split
3601   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3602         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3603                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3604                     (const_int 0)))
3605    (clobber (match_scratch:SI 3 ""))
3606    (clobber (match_scratch:SI 4 ""))]
3607   "TARGET_POWER && reload_completed"
3608   [(parallel [(set (match_dup 3)
3609         (ashift:SI (match_dup 1) (match_dup 2)))
3610    (clobber (match_dup 4))])
3611    (set (match_dup 0)
3612         (compare:CC (match_dup 3)
3613                     (const_int 0)))]
3614   "")
3615
3616 (define_insn ""
3617   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3618         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3619                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3620                     (const_int 0)))
3621    (clobber (match_scratch:SI 3 "=r,r"))]
3622   "! TARGET_POWER && TARGET_32BIT"
3623   "@
3624    {sl|slw}%I2. %3,%1,%h2
3625    #"
3626   [(set_attr "type" "delayed_compare")
3627    (set_attr "length" "4,8")])
3628
3629 (define_split
3630   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3631         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3632                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3633                     (const_int 0)))
3634    (clobber (match_scratch:SI 3 ""))]
3635   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3636   [(set (match_dup 3)
3637         (ashift:SI (match_dup 1) (match_dup 2)))
3638    (set (match_dup 0)
3639         (compare:CC (match_dup 3)
3640                     (const_int 0)))]
3641   "")
3642
3643 (define_insn ""
3644   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3645         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3646                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3647                     (const_int 0)))
3648    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3649         (ashift:SI (match_dup 1) (match_dup 2)))
3650    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
3651   "TARGET_POWER"
3652   "@
3653    sle. %0,%1,%2
3654    {sli.|slwi.} %0,%1,%h2
3655    #
3656    #"
3657   [(set_attr "type" "delayed_compare")
3658    (set_attr "length" "4,4,8,8")])
3659
3660 (define_split
3661   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3662         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3663                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3664                     (const_int 0)))
3665    (set (match_operand:SI 0 "gpc_reg_operand" "")
3666         (ashift:SI (match_dup 1) (match_dup 2)))
3667    (clobber (match_scratch:SI 4 ""))]
3668   "TARGET_POWER && reload_completed"
3669   [(parallel [(set (match_dup 0)
3670         (ashift:SI (match_dup 1) (match_dup 2)))
3671    (clobber (match_dup 4))])
3672    (set (match_dup 3)
3673         (compare:CC (match_dup 0)
3674                     (const_int 0)))]
3675   "")
3676
3677 (define_insn ""
3678   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3679         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3680                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3681                     (const_int 0)))
3682    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3683         (ashift:SI (match_dup 1) (match_dup 2)))]
3684   "! TARGET_POWER && TARGET_32BIT"
3685   "@
3686    {sl|slw}%I2. %0,%1,%h2
3687    #"
3688   [(set_attr "type" "delayed_compare")
3689    (set_attr "length" "4,8")])
3690
3691 (define_split
3692   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3693         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3694                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3695                     (const_int 0)))
3696    (set (match_operand:SI 0 "gpc_reg_operand" "")
3697         (ashift:SI (match_dup 1) (match_dup 2)))]
3698   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3699   [(set (match_dup 0)
3700         (ashift:SI (match_dup 1) (match_dup 2)))
3701    (set (match_dup 3)
3702         (compare:CC (match_dup 0)
3703                     (const_int 0)))]
3704   "")
3705
3706 (define_insn ""
3707   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3708         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3709                            (match_operand:SI 2 "const_int_operand" "i"))
3710                 (match_operand:SI 3 "mask_operand" "n")))]
3711   "includes_lshift_p (operands[2], operands[3])"
3712   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
3713
3714 (define_insn ""
3715   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3716         (compare:CC
3717          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3718                             (match_operand:SI 2 "const_int_operand" "i,i"))
3719                  (match_operand:SI 3 "mask_operand" "n,n"))
3720          (const_int 0)))
3721    (clobber (match_scratch:SI 4 "=r,r"))]
3722   "includes_lshift_p (operands[2], operands[3])"
3723   "@
3724    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
3725    #"
3726   [(set_attr "type" "delayed_compare")
3727    (set_attr "length" "4,8")])
3728
3729 (define_split
3730   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3731         (compare:CC
3732          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3733                             (match_operand:SI 2 "const_int_operand" ""))
3734                  (match_operand:SI 3 "mask_operand" ""))
3735          (const_int 0)))
3736    (clobber (match_scratch:SI 4 ""))]
3737   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
3738   [(set (match_dup 4)
3739         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
3740                  (match_dup 3)))
3741    (set (match_dup 0)
3742         (compare:CC (match_dup 4)
3743                     (const_int 0)))]
3744   "")
3745
3746 (define_insn ""
3747   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3748         (compare:CC
3749          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3750                             (match_operand:SI 2 "const_int_operand" "i,i"))
3751                  (match_operand:SI 3 "mask_operand" "n,n"))
3752          (const_int 0)))
3753    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3754         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3755   "includes_lshift_p (operands[2], operands[3])"
3756   "@
3757    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
3758    #"
3759   [(set_attr "type" "delayed_compare")
3760    (set_attr "length" "4,8")])
3761
3762 (define_split
3763   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3764         (compare:CC
3765          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3766                             (match_operand:SI 2 "const_int_operand" ""))
3767                  (match_operand:SI 3 "mask_operand" ""))
3768          (const_int 0)))
3769    (set (match_operand:SI 0 "gpc_reg_operand" "")
3770         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3771   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
3772   [(set (match_dup 0)
3773         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3774    (set (match_dup 4)
3775         (compare:CC (match_dup 0)
3776                     (const_int 0)))]
3777   "")
3778
3779 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
3780 ;; "sli x,x,0".
3781 (define_expand "lshrsi3"
3782   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
3783    (use (match_operand:SI 1 "gpc_reg_operand" ""))
3784    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
3785   ""
3786   "
3787 {
3788   if (TARGET_POWER)
3789     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
3790   else
3791     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
3792   DONE;
3793 }")
3794
3795 (define_insn "lshrsi3_power"
3796   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
3797         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
3798                      (match_operand:SI 2 "reg_or_cint_operand" "r,O,i")))
3799    (clobber (match_scratch:SI 3 "=q,X,X"))]
3800   "TARGET_POWER"
3801   "@
3802   sre %0,%1,%2
3803   mr %0,%1
3804   {s%A2i|s%A2wi} %0,%1,%h2")
3805
3806 (define_insn "lshrsi3_no_power"
3807   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3808         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3809                      (match_operand:SI 2 "reg_or_cint_operand" "O,ri")))]
3810   "! TARGET_POWER"
3811   "@
3812   mr %0,%1
3813   {sr|srw}%I2 %0,%1,%h2")
3814
3815 (define_insn ""
3816   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
3817         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
3818                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
3819                     (const_int 0)))
3820    (clobber (match_scratch:SI 3 "=r,X,r,r,X,r"))
3821    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
3822   "TARGET_POWER"
3823   "@
3824   sre. %3,%1,%2
3825   mr. %1,%1
3826   {s%A2i.|s%A2wi.} %3,%1,%h2
3827   #
3828   #
3829   #"
3830   [(set_attr "type" "delayed_compare")
3831    (set_attr "length" "4,4,4,8,8,8")])
3832
3833 (define_split
3834   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3835         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3836                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3837                     (const_int 0)))
3838    (clobber (match_scratch:SI 3 ""))
3839    (clobber (match_scratch:SI 4 ""))]
3840   "TARGET_POWER && reload_completed"
3841   [(parallel [(set (match_dup 3)
3842         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3843    (clobber (match_dup 4))])
3844    (set (match_dup 0)
3845         (compare:CC (match_dup 3)
3846                     (const_int 0)))]
3847   "")
3848
3849 (define_insn ""
3850   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3851         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3852                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
3853                     (const_int 0)))
3854    (clobber (match_scratch:SI 3 "=X,r,X,r"))]
3855   "! TARGET_POWER && TARGET_32BIT"
3856   "@
3857    mr. %1,%1
3858    {sr|srw}%I2. %3,%1,%h2
3859    #
3860    #"
3861   [(set_attr "type" "delayed_compare")
3862    (set_attr "length" "4,4,8,8")])
3863
3864 (define_split
3865   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3866         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3867                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3868                     (const_int 0)))
3869    (clobber (match_scratch:SI 3 ""))]
3870   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3871   [(set (match_dup 3)
3872         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3873    (set (match_dup 0)
3874         (compare:CC (match_dup 3)
3875                     (const_int 0)))]
3876   "")
3877
3878 (define_insn ""
3879   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
3880         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
3881                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
3882                     (const_int 0)))
3883    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
3884         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3885    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
3886   "TARGET_POWER"
3887   "@
3888   sre. %0,%1,%2
3889   mr. %0,%1
3890   {s%A2i.|s%A2wi.} %0,%1,%h2
3891   #
3892   #
3893   #"
3894   [(set_attr "type" "delayed_compare")
3895    (set_attr "length" "4,4,4,8,8,8")])
3896
3897 (define_split
3898   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3899         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3900                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3901                     (const_int 0)))
3902    (set (match_operand:SI 0 "gpc_reg_operand" "")
3903         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3904    (clobber (match_scratch:SI 4 ""))]
3905   "TARGET_POWER && reload_completed"
3906   [(parallel [(set (match_dup 0)
3907         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3908    (clobber (match_dup 4))])
3909    (set (match_dup 3)
3910         (compare:CC (match_dup 0)
3911                     (const_int 0)))]
3912   "")
3913
3914 (define_insn ""
3915   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3916         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3917                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
3918                     (const_int 0)))
3919    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3920         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
3921   "! TARGET_POWER && TARGET_32BIT"
3922   "@
3923    mr. %0,%1
3924    {sr|srw}%I2. %0,%1,%h2
3925    #
3926    #"
3927   [(set_attr "type" "delayed_compare")
3928    (set_attr "length" "4,4,8,8")])
3929
3930 (define_split
3931   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3932         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3933                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3934                     (const_int 0)))
3935    (set (match_operand:SI 0 "gpc_reg_operand" "")
3936         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
3937   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3938   [(set (match_dup 0)
3939         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3940    (set (match_dup 3)
3941         (compare:CC (match_dup 0)
3942                     (const_int 0)))]
3943   "")
3944
3945 (define_insn ""
3946   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3947         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3948                              (match_operand:SI 2 "const_int_operand" "i"))
3949                 (match_operand:SI 3 "mask_operand" "n")))]
3950   "includes_rshift_p (operands[2], operands[3])"
3951   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
3952
3953 (define_insn ""
3954   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3955         (compare:CC
3956          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3957                               (match_operand:SI 2 "const_int_operand" "i,i"))
3958                  (match_operand:SI 3 "mask_operand" "n,n"))
3959          (const_int 0)))
3960    (clobber (match_scratch:SI 4 "=r,r"))]
3961   "includes_rshift_p (operands[2], operands[3])"
3962   "@
3963    {rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3
3964    #"
3965   [(set_attr "type" "delayed_compare")
3966    (set_attr "length" "4,8")])
3967
3968 (define_split
3969   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3970         (compare:CC
3971          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3972                               (match_operand:SI 2 "const_int_operand" ""))
3973                  (match_operand:SI 3 "mask_operand" ""))
3974          (const_int 0)))
3975    (clobber (match_scratch:SI 4 ""))]
3976   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
3977   [(set (match_dup 4)
3978         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
3979                  (match_dup 3)))
3980    (set (match_dup 0)
3981         (compare:CC (match_dup 4)
3982                     (const_int 0)))]
3983   "")
3984
3985 (define_insn ""
3986   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3987         (compare:CC
3988          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3989                               (match_operand:SI 2 "const_int_operand" "i,i"))
3990                  (match_operand:SI 3 "mask_operand" "n,n"))
3991          (const_int 0)))
3992    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3993         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3994   "includes_rshift_p (operands[2], operands[3])"
3995   "@
3996    {rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3
3997    #"
3998   [(set_attr "type" "delayed_compare")
3999    (set_attr "length" "4,8")])
4000
4001 (define_split
4002   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4003         (compare:CC
4004          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4005                               (match_operand:SI 2 "const_int_operand" ""))
4006                  (match_operand:SI 3 "mask_operand" ""))
4007          (const_int 0)))
4008    (set (match_operand:SI 0 "gpc_reg_operand" "")
4009         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4010   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4011   [(set (match_dup 0)
4012         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4013    (set (match_dup 4)
4014         (compare:CC (match_dup 0)
4015                     (const_int 0)))]
4016   "")
4017
4018 (define_insn ""
4019   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4020         (zero_extend:SI
4021          (subreg:QI
4022           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4023                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4024   "includes_rshift_p (operands[2], GEN_INT (255))"
4025   "{rlinm|rlwinm} %0,%1,%s2,0xff")
4026
4027 (define_insn ""
4028   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4029         (compare:CC
4030          (zero_extend:SI
4031           (subreg:QI
4032            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4033                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4034          (const_int 0)))
4035    (clobber (match_scratch:SI 3 "=r,r"))]
4036   "includes_rshift_p (operands[2], GEN_INT (255))"
4037   "@
4038    {rlinm.|rlwinm.} %3,%1,%s2,0xff
4039    #"
4040   [(set_attr "type" "delayed_compare")
4041    (set_attr "length" "4,8")])
4042
4043 (define_split
4044   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4045         (compare:CC
4046          (zero_extend:SI
4047           (subreg:QI
4048            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4049                         (match_operand:SI 2 "const_int_operand" "")) 0))
4050          (const_int 0)))
4051    (clobber (match_scratch:SI 3 ""))]
4052   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4053   [(set (match_dup 3)
4054         (zero_extend:SI (subreg:QI
4055            (lshiftrt:SI (match_dup 1)
4056                         (match_dup 2)) 0)))
4057    (set (match_dup 0)
4058         (compare:CC (match_dup 3)
4059                     (const_int 0)))]
4060   "")
4061
4062 (define_insn ""
4063   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4064         (compare:CC
4065          (zero_extend:SI
4066           (subreg:QI
4067            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4068                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4069          (const_int 0)))
4070    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4071         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4072   "includes_rshift_p (operands[2], GEN_INT (255))"
4073   "@
4074    {rlinm.|rlwinm.} %0,%1,%s2,0xff
4075    #"
4076   [(set_attr "type" "delayed_compare")
4077    (set_attr "length" "4,8")])
4078
4079 (define_split
4080   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4081         (compare:CC
4082          (zero_extend:SI
4083           (subreg:QI
4084            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4085                         (match_operand:SI 2 "const_int_operand" "")) 0))
4086          (const_int 0)))
4087    (set (match_operand:SI 0 "gpc_reg_operand" "")
4088         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4089   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4090   [(set (match_dup 0)
4091         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4092    (set (match_dup 3)
4093         (compare:CC (match_dup 0)
4094                     (const_int 0)))]
4095   "")
4096
4097 (define_insn ""
4098   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4099         (zero_extend:SI
4100          (subreg:HI
4101           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4102                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4103   "includes_rshift_p (operands[2], GEN_INT (65535))"
4104   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
4105
4106 (define_insn ""
4107   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4108         (compare:CC
4109          (zero_extend:SI
4110           (subreg:HI
4111            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4112                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4113          (const_int 0)))
4114    (clobber (match_scratch:SI 3 "=r,r"))]
4115   "includes_rshift_p (operands[2], GEN_INT (65535))"
4116   "@
4117    {rlinm.|rlwinm.} %3,%1,%s2,0xffff
4118    #"
4119   [(set_attr "type" "delayed_compare")
4120    (set_attr "length" "4,8")])
4121
4122 (define_split
4123   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4124         (compare:CC
4125          (zero_extend:SI
4126           (subreg:HI
4127            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4128                         (match_operand:SI 2 "const_int_operand" "")) 0))
4129          (const_int 0)))
4130    (clobber (match_scratch:SI 3 ""))]
4131   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4132   [(set (match_dup 3)
4133         (zero_extend:SI (subreg:HI
4134            (lshiftrt:SI (match_dup 1)
4135                         (match_dup 2)) 0)))
4136    (set (match_dup 0)
4137         (compare:CC (match_dup 3)
4138                     (const_int 0)))]
4139   "")
4140
4141 (define_insn ""
4142   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4143         (compare:CC
4144          (zero_extend:SI
4145           (subreg:HI
4146            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4147                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4148          (const_int 0)))
4149    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4150         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4151   "includes_rshift_p (operands[2], GEN_INT (65535))"
4152   "@
4153    {rlinm.|rlwinm.} %0,%1,%s2,0xffff
4154    #"
4155   [(set_attr "type" "delayed_compare")
4156    (set_attr "length" "4,8")])
4157
4158 (define_split
4159   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4160         (compare:CC
4161          (zero_extend:SI
4162           (subreg:HI
4163            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4164                         (match_operand:SI 2 "const_int_operand" "")) 0))
4165          (const_int 0)))
4166    (set (match_operand:SI 0 "gpc_reg_operand" "")
4167         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4168   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4169   [(set (match_dup 0)
4170         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4171    (set (match_dup 3)
4172         (compare:CC (match_dup 0)
4173                     (const_int 0)))]
4174   "")
4175
4176 (define_insn ""
4177   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4178                          (const_int 1)
4179                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4180         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4181                      (const_int 31)))]
4182   "TARGET_POWER"
4183   "rrib %0,%1,%2")
4184
4185 (define_insn ""
4186   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4187                          (const_int 1)
4188                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4189         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4190                      (const_int 31)))]
4191   "TARGET_POWER"
4192   "rrib %0,%1,%2")
4193
4194 (define_insn ""
4195   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4196                          (const_int 1)
4197                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4198         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4199                          (const_int 1)
4200                          (const_int 0)))]
4201   "TARGET_POWER"
4202   "rrib %0,%1,%2")
4203
4204 (define_expand "ashrsi3"
4205   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4206         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4207                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
4208   ""
4209   "
4210 {
4211   if (TARGET_POWER)
4212     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
4213   else
4214     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
4215   DONE;
4216 }")
4217
4218 (define_insn "ashrsi3_power"
4219   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4220         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4221                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4222    (clobber (match_scratch:SI 3 "=q,X"))]
4223   "TARGET_POWER"
4224   "@
4225    srea %0,%1,%2
4226    {srai|srawi} %0,%1,%h2")
4227
4228 (define_insn "ashrsi3_no_power"
4229   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4230         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4231                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4232   "! TARGET_POWER"
4233   "{sra|sraw}%I2 %0,%1,%h2")
4234
4235 (define_insn ""
4236   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4237         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4238                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4239                     (const_int 0)))
4240    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4241    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4242   "TARGET_POWER"
4243   "@
4244    srea. %3,%1,%2
4245    {srai.|srawi.} %3,%1,%h2
4246    #
4247    #"
4248   [(set_attr "type" "delayed_compare")
4249    (set_attr "length" "4,4,8,8")])
4250
4251 (define_split
4252   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4253         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4254                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4255                     (const_int 0)))
4256    (clobber (match_scratch:SI 3 ""))
4257    (clobber (match_scratch:SI 4 ""))]
4258   "TARGET_POWER && reload_completed"
4259   [(parallel [(set (match_dup 3)
4260         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4261    (clobber (match_dup 4))])
4262    (set (match_dup 0)
4263         (compare:CC (match_dup 3)
4264                     (const_int 0)))]
4265   "")
4266
4267 (define_insn ""
4268   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4269         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4270                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4271                     (const_int 0)))
4272    (clobber (match_scratch:SI 3 "=r,r"))]
4273   "! TARGET_POWER"
4274   "@
4275    {sra|sraw}%I2. %3,%1,%h2
4276    #"
4277   [(set_attr "type" "delayed_compare")
4278    (set_attr "length" "4,8")])
4279
4280 (define_split
4281   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4282         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4283                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4284                     (const_int 0)))
4285    (clobber (match_scratch:SI 3 ""))]
4286   "! TARGET_POWER && reload_completed"
4287   [(set (match_dup 3)
4288         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4289    (set (match_dup 0)
4290         (compare:CC (match_dup 3)
4291                     (const_int 0)))]
4292   "")
4293
4294 (define_insn ""
4295   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4296         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4297                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4298                     (const_int 0)))
4299    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4300         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4301    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4302   "TARGET_POWER"
4303   "@
4304    srea. %0,%1,%2
4305    {srai.|srawi.} %0,%1,%h2
4306    #
4307    #"
4308   [(set_attr "type" "delayed_compare")
4309    (set_attr "length" "4,4,8,8")])
4310
4311 (define_split
4312   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4313         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4314                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4315                     (const_int 0)))
4316    (set (match_operand:SI 0 "gpc_reg_operand" "")
4317         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4318    (clobber (match_scratch:SI 4 ""))]
4319   "TARGET_POWER && reload_completed"
4320   [(parallel [(set (match_dup 0)
4321         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4322    (clobber (match_dup 4))])
4323    (set (match_dup 3)
4324         (compare:CC (match_dup 0)
4325                     (const_int 0)))]
4326   "")
4327
4328 (define_insn ""
4329   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4330         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4331                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4332                     (const_int 0)))
4333    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4334         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4335   "! TARGET_POWER"
4336   "@
4337    {sra|sraw}%I2. %0,%1,%h2
4338    #"
4339   [(set_attr "type" "delayed_compare")
4340    (set_attr "length" "4,8")])
4341 \f
4342 (define_split
4343   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4344         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4345                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4346                     (const_int 0)))
4347    (set (match_operand:SI 0 "gpc_reg_operand" "")
4348         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4349   "! TARGET_POWER && reload_completed"
4350   [(set (match_dup 0)
4351         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4352    (set (match_dup 3)
4353         (compare:CC (match_dup 0)
4354                     (const_int 0)))]
4355   "")
4356
4357 ;; Floating-point insns, excluding normal data motion.
4358 ;;
4359 ;; PowerPC has a full set of single-precision floating point instructions.
4360 ;;
4361 ;; For the POWER architecture, we pretend that we have both SFmode and
4362 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
4363 ;; The only conversions we will do will be when storing to memory.  In that
4364 ;; case, we will use the "frsp" instruction before storing.
4365 ;;
4366 ;; Note that when we store into a single-precision memory location, we need to
4367 ;; use the frsp insn first.  If the register being stored isn't dead, we
4368 ;; need a scratch register for the frsp.  But this is difficult when the store
4369 ;; is done by reload.  It is not incorrect to do the frsp on the register in
4370 ;; this case, we just lose precision that we would have otherwise gotten but
4371 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
4372
4373 (define_insn "extendsfdf2"
4374   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4375         (float_extend:DF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4376   "TARGET_HARD_FLOAT && TARGET_FPRS"
4377   "*
4378 {
4379   if (REGNO (operands[0]) == REGNO (operands[1]))
4380     return \"\";
4381   else
4382     return \"fmr %0,%1\";
4383 }"
4384   [(set_attr "type" "fp")])
4385
4386 (define_insn "truncdfsf2"
4387   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4388         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4389   "TARGET_HARD_FLOAT && TARGET_FPRS"
4390   "frsp %0,%1"
4391   [(set_attr "type" "fp")])
4392
4393 (define_insn "aux_truncdfsf2"
4394   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4395         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRSP))]
4396   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4397   "frsp %0,%1"
4398   [(set_attr "type" "fp")])
4399
4400 (define_expand "negsf2"
4401   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4402         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4403   "TARGET_HARD_FLOAT"
4404   "")
4405
4406 (define_insn "*negsf2"
4407   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4408         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4409   "TARGET_HARD_FLOAT && TARGET_FPRS"
4410   "fneg %0,%1"
4411   [(set_attr "type" "fp")])
4412
4413 (define_expand "abssf2"
4414   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4415         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4416   "TARGET_HARD_FLOAT"
4417   "")
4418
4419 (define_insn "*abssf2"
4420   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4421         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4422   "TARGET_HARD_FLOAT && TARGET_FPRS"
4423   "fabs %0,%1"
4424   [(set_attr "type" "fp")])
4425
4426 (define_insn ""
4427   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4428         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
4429   "TARGET_HARD_FLOAT && TARGET_FPRS"
4430   "fnabs %0,%1"
4431   [(set_attr "type" "fp")])
4432
4433 (define_expand "addsf3"
4434   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4435         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4436                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4437   "TARGET_HARD_FLOAT"
4438   "")
4439
4440 (define_insn ""
4441   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4442         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4443                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4444   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4445   "fadds %0,%1,%2"
4446   [(set_attr "type" "fp")])
4447
4448 (define_insn ""
4449   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4450         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4451                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4452   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4453   "{fa|fadd} %0,%1,%2"
4454   [(set_attr "type" "fp")])
4455
4456 (define_expand "subsf3"
4457   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4458         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4459                   (match_operand:SF 2 "gpc_reg_operand" "")))]
4460   "TARGET_HARD_FLOAT"
4461   "")
4462
4463 (define_insn ""
4464   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4465         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4466                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
4467   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4468   "fsubs %0,%1,%2"
4469   [(set_attr "type" "fp")])
4470
4471 (define_insn ""
4472   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4473         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4474                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
4475   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4476   "{fs|fsub} %0,%1,%2"
4477   [(set_attr "type" "fp")])
4478
4479 (define_expand "mulsf3"
4480   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4481         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
4482                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4483   "TARGET_HARD_FLOAT"
4484   "")
4485
4486 (define_insn ""
4487   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4488         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4489                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4490   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4491   "fmuls %0,%1,%2"
4492   [(set_attr "type" "fp")])
4493
4494 (define_insn ""
4495   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4496         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4497                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4498   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4499   "{fm|fmul} %0,%1,%2"
4500   [(set_attr "type" "dmul")])
4501
4502 (define_expand "divsf3"
4503   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4504         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
4505                 (match_operand:SF 2 "gpc_reg_operand" "")))]
4506   "TARGET_HARD_FLOAT"
4507   "")
4508
4509 (define_insn ""
4510   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4511         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4512                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
4513   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4514   "fdivs %0,%1,%2"
4515   [(set_attr "type" "sdiv")])
4516
4517 (define_insn ""
4518   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4519         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4520                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
4521   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4522   "{fd|fdiv} %0,%1,%2"
4523   [(set_attr "type" "ddiv")])
4524
4525 (define_insn ""
4526   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4527         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4528                           (match_operand:SF 2 "gpc_reg_operand" "f"))
4529                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
4530   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4531   "fmadds %0,%1,%2,%3"
4532   [(set_attr "type" "fp")])
4533
4534 (define_insn ""
4535   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4536         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4537                           (match_operand:SF 2 "gpc_reg_operand" "f"))
4538                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
4539   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4540   "{fma|fmadd} %0,%1,%2,%3"
4541   [(set_attr "type" "dmul")])
4542
4543 (define_insn ""
4544   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4545         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4546                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4547                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
4548   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4549   "fmsubs %0,%1,%2,%3"
4550   [(set_attr "type" "fp")])
4551
4552 (define_insn ""
4553   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4554         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4555                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4556                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
4557   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4558   "{fms|fmsub} %0,%1,%2,%3"
4559   [(set_attr "type" "dmul")])
4560
4561 (define_insn ""
4562   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4563         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4564                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
4565                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4566   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4567    && HONOR_SIGNED_ZEROS (SFmode)"
4568   "fnmadds %0,%1,%2,%3"
4569   [(set_attr "type" "fp")])
4570
4571 (define_insn ""
4572   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4573         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
4574                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4575                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4576   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4577    && ! HONOR_SIGNED_ZEROS (SFmode)"
4578   "fnmadds %0,%1,%2,%3"
4579   [(set_attr "type" "fp")])
4580
4581 (define_insn ""
4582   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4583         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4584                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
4585                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4586   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4587   "{fnma|fnmadd} %0,%1,%2,%3"
4588   [(set_attr "type" "dmul")])
4589
4590 (define_insn ""
4591   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4592         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
4593                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4594                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4595   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4596    && ! HONOR_SIGNED_ZEROS (SFmode)"
4597   "{fnma|fnmadd} %0,%1,%2,%3"
4598   [(set_attr "type" "dmul")])
4599
4600 (define_insn ""
4601   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4602         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4603                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
4604                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4605   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4606    && HONOR_SIGNED_ZEROS (SFmode)"
4607   "fnmsubs %0,%1,%2,%3"
4608   [(set_attr "type" "fp")])
4609
4610 (define_insn ""
4611   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4612         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
4613                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4614                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
4615   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4616    && ! HONOR_SIGNED_ZEROS (SFmode)"
4617   "fnmsubs %0,%1,%2,%3"
4618   [(set_attr "type" "fp")])
4619
4620 (define_insn ""
4621   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4622         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4623                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
4624                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4625   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4626   "{fnms|fnmsub} %0,%1,%2,%3"
4627   [(set_attr "type" "dmul")])
4628
4629 (define_insn ""
4630   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4631         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
4632                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4633                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
4634   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4635    && ! HONOR_SIGNED_ZEROS (SFmode)"
4636   "{fnms|fnmsub} %0,%1,%2,%3"
4637   [(set_attr "type" "fp")])
4638
4639 (define_expand "sqrtsf2"
4640   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4641         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4642   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
4643   "")
4644
4645 (define_insn ""
4646   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4647         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4648   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4649   "fsqrts %0,%1"
4650   [(set_attr "type" "ssqrt")])
4651
4652 (define_insn ""
4653   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4654         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4655   "TARGET_POWER2 && TARGET_HARD_FLOAT && TARGET_FPRS"
4656   "fsqrt %0,%1"
4657   [(set_attr "type" "dsqrt")])
4658
4659 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
4660 ;; fsel instruction and some auxiliary computations.  Then we just have a
4661 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
4662 ;; combine.
4663 (define_expand "maxsf3"
4664   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4665         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
4666                              (match_operand:SF 2 "gpc_reg_operand" ""))
4667                          (match_dup 1)
4668                          (match_dup 2)))]
4669   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4670   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
4671
4672 (define_expand "minsf3"
4673   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4674         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
4675                              (match_operand:SF 2 "gpc_reg_operand" ""))
4676                          (match_dup 2)
4677                          (match_dup 1)))]
4678   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4679   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
4680
4681 (define_split
4682   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4683         (match_operator:SF 3 "min_max_operator"
4684          [(match_operand:SF 1 "gpc_reg_operand" "")
4685           (match_operand:SF 2 "gpc_reg_operand" "")]))]
4686   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4687   [(const_int 0)]
4688   "
4689 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]), 
4690                       operands[1], operands[2]);
4691   DONE;
4692 }")
4693
4694 (define_expand "movsicc"
4695    [(set (match_operand:SI 0 "gpc_reg_operand" "")
4696          (if_then_else:SI (match_operand 1 "comparison_operator" "")
4697                           (match_operand:SI 2 "gpc_reg_operand" "")
4698                           (match_operand:SI 3 "gpc_reg_operand" "")))]
4699   "TARGET_ISEL"
4700   "
4701 {
4702   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4703     DONE;
4704   else
4705     FAIL;
4706 }")
4707
4708 ;; We use the BASE_REGS for the isel input operands because, if rA is
4709 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
4710 ;; because we may switch the operands and rB may end up being rA.
4711 ;;
4712 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
4713 ;; leave out the mode in operand 4 and use one pattern, but reload can
4714 ;; change the mode underneath our feet and then gets confused trying
4715 ;; to reload the value.
4716 (define_insn "isel_signed"
4717   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4718         (if_then_else:SI
4719          (match_operator 1 "comparison_operator"
4720                          [(match_operand:CC 4 "cc_reg_operand" "y")
4721                           (const_int 0)])
4722          (match_operand:SI 2 "gpc_reg_operand" "b")
4723          (match_operand:SI 3 "gpc_reg_operand" "b")))]
4724   "TARGET_ISEL"
4725   "*
4726 { return output_isel (operands); }"
4727   [(set_attr "length" "4")])
4728
4729 (define_insn "isel_unsigned"
4730   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4731         (if_then_else:SI
4732          (match_operator 1 "comparison_operator"
4733                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
4734                           (const_int 0)])
4735          (match_operand:SI 2 "gpc_reg_operand" "b")
4736          (match_operand:SI 3 "gpc_reg_operand" "b")))]
4737   "TARGET_ISEL"
4738   "*
4739 { return output_isel (operands); }"
4740   [(set_attr "length" "4")])
4741
4742 (define_expand "movsfcc"
4743    [(set (match_operand:SF 0 "gpc_reg_operand" "")
4744          (if_then_else:SF (match_operand 1 "comparison_operator" "")
4745                           (match_operand:SF 2 "gpc_reg_operand" "")
4746                           (match_operand:SF 3 "gpc_reg_operand" "")))]
4747   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4748   "
4749 {
4750   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4751     DONE;
4752   else
4753     FAIL;
4754 }")
4755
4756 (define_insn "*fselsfsf4"
4757   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4758         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
4759                              (match_operand:SF 4 "zero_fp_constant" "F"))
4760                          (match_operand:SF 2 "gpc_reg_operand" "f")
4761                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4762   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4763   "fsel %0,%1,%2,%3"
4764   [(set_attr "type" "fp")])
4765
4766 (define_insn "*fseldfsf4"
4767   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4768         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
4769                              (match_operand:DF 4 "zero_fp_constant" "F"))
4770                          (match_operand:SF 2 "gpc_reg_operand" "f")
4771                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4772   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4773   "fsel %0,%1,%2,%3"
4774   [(set_attr "type" "fp")])
4775
4776 (define_insn "negdf2"
4777   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4778         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4779   "TARGET_HARD_FLOAT && TARGET_FPRS"
4780   "fneg %0,%1"
4781   [(set_attr "type" "fp")])
4782
4783 (define_insn "absdf2"
4784   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4785         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4786   "TARGET_HARD_FLOAT && TARGET_FPRS"
4787   "fabs %0,%1"
4788   [(set_attr "type" "fp")])
4789
4790 (define_insn ""
4791   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4792         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f"))))]
4793   "TARGET_HARD_FLOAT && TARGET_FPRS"
4794   "fnabs %0,%1"
4795   [(set_attr "type" "fp")])
4796
4797 (define_insn "adddf3"
4798   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4799         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4800                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
4801   "TARGET_HARD_FLOAT && TARGET_FPRS"
4802   "{fa|fadd} %0,%1,%2"
4803   [(set_attr "type" "fp")])
4804
4805 (define_insn "subdf3"
4806   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4807         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "f")
4808                   (match_operand:DF 2 "gpc_reg_operand" "f")))]
4809   "TARGET_HARD_FLOAT && TARGET_FPRS"
4810   "{fs|fsub} %0,%1,%2"
4811   [(set_attr "type" "fp")])
4812
4813 (define_insn "muldf3"
4814   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4815         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4816                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
4817   "TARGET_HARD_FLOAT && TARGET_FPRS"
4818   "{fm|fmul} %0,%1,%2"
4819   [(set_attr "type" "dmul")])
4820
4821 (define_insn "divdf3"
4822   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4823         (div:DF (match_operand:DF 1 "gpc_reg_operand" "f")
4824                 (match_operand:DF 2 "gpc_reg_operand" "f")))]
4825   "TARGET_HARD_FLOAT && TARGET_FPRS"
4826   "{fd|fdiv} %0,%1,%2"
4827   [(set_attr "type" "ddiv")])
4828
4829 (define_insn ""
4830   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4831         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4832                           (match_operand:DF 2 "gpc_reg_operand" "f"))
4833                  (match_operand:DF 3 "gpc_reg_operand" "f")))]
4834   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4835   "{fma|fmadd} %0,%1,%2,%3"
4836   [(set_attr "type" "dmul")])
4837
4838 (define_insn ""
4839   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4840         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4841                            (match_operand:DF 2 "gpc_reg_operand" "f"))
4842                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
4843   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4844   "{fms|fmsub} %0,%1,%2,%3"
4845   [(set_attr "type" "dmul")])
4846
4847 (define_insn ""
4848   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4849         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4850                                   (match_operand:DF 2 "gpc_reg_operand" "f"))
4851                          (match_operand:DF 3 "gpc_reg_operand" "f"))))]
4852   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4853    && HONOR_SIGNED_ZEROS (DFmode)"
4854   "{fnma|fnmadd} %0,%1,%2,%3"
4855   [(set_attr "type" "dmul")])
4856
4857 (define_insn ""
4858   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4859         (minus:DF (mult:DF (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f"))
4860                            (match_operand:DF 2 "gpc_reg_operand" "f"))
4861                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
4862   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4863    && ! HONOR_SIGNED_ZEROS (DFmode)"
4864   "{fnma|fnmadd} %0,%1,%2,%3"
4865   [(set_attr "type" "dmul")])
4866
4867 (define_insn ""
4868   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4869         (neg:DF (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4870                                    (match_operand:DF 2 "gpc_reg_operand" "f"))
4871                           (match_operand:DF 3 "gpc_reg_operand" "f"))))]
4872   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4873    && HONOR_SIGNED_ZEROS (DFmode)"
4874   "{fnms|fnmsub} %0,%1,%2,%3"
4875   [(set_attr "type" "dmul")])
4876
4877 (define_insn ""
4878   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4879         (minus:DF (match_operand:DF 3 "gpc_reg_operand" "f")
4880                   (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4881                            (match_operand:DF 2 "gpc_reg_operand" "f"))))]
4882   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD 
4883    && ! HONOR_SIGNED_ZEROS (DFmode)"
4884   "{fnms|fnmsub} %0,%1,%2,%3"
4885   [(set_attr "type" "dmul")])
4886
4887 (define_insn "sqrtdf2"
4888   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4889         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4890   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
4891   "fsqrt %0,%1"
4892   [(set_attr "type" "dsqrt")])
4893
4894 ;; The conditional move instructions allow us to perform max and min
4895 ;; operations even when 
4896
4897 (define_expand "maxdf3"
4898   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4899         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
4900                              (match_operand:DF 2 "gpc_reg_operand" ""))
4901                          (match_dup 1)
4902                          (match_dup 2)))]
4903   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4904   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
4905
4906 (define_expand "mindf3"
4907   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4908         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
4909                              (match_operand:DF 2 "gpc_reg_operand" ""))
4910                          (match_dup 2)
4911                          (match_dup 1)))]
4912   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4913   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
4914
4915 (define_split
4916   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4917         (match_operator:DF 3 "min_max_operator"
4918          [(match_operand:DF 1 "gpc_reg_operand" "")
4919           (match_operand:DF 2 "gpc_reg_operand" "")]))]
4920   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4921   [(const_int 0)]
4922   "
4923 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]), 
4924                       operands[1], operands[2]);
4925   DONE;
4926 }")
4927
4928 (define_expand "movdfcc"
4929    [(set (match_operand:DF 0 "gpc_reg_operand" "")
4930          (if_then_else:DF (match_operand 1 "comparison_operator" "")
4931                           (match_operand:DF 2 "gpc_reg_operand" "")
4932                           (match_operand:DF 3 "gpc_reg_operand" "")))]
4933   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4934   "
4935 {
4936   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4937     DONE;
4938   else
4939     FAIL;
4940 }")
4941
4942 (define_insn "*fseldfdf4"
4943   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4944         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
4945                              (match_operand:DF 4 "zero_fp_constant" "F"))
4946                          (match_operand:DF 2 "gpc_reg_operand" "f")
4947                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
4948   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4949   "fsel %0,%1,%2,%3"
4950   [(set_attr "type" "fp")])
4951
4952 (define_insn "*fselsfdf4"
4953   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4954         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
4955                              (match_operand:SF 4 "zero_fp_constant" "F"))
4956                          (match_operand:DF 2 "gpc_reg_operand" "f")
4957                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
4958   "TARGET_PPC_GFXOPT"
4959   "fsel %0,%1,%2,%3"
4960   [(set_attr "type" "fp")])
4961 \f
4962 ;; Conversions to and from floating-point.
4963
4964 (define_expand "fixunssfsi2"
4965   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4966         (unsigned_fix:SI (fix:SF (match_operand:SF 1 "gpc_reg_operand" ""))))]
4967   "TARGET_HARD_FLOAT && !TARGET_FPRS"
4968   "")
4969
4970 (define_expand "fix_truncsfsi2"
4971   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4972         (fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
4973   "TARGET_HARD_FLOAT && !TARGET_FPRS"
4974   "")
4975
4976 ; For each of these conversions, there is a define_expand, a define_insn
4977 ; with a '#' template, and a define_split (with C code).  The idea is
4978 ; to allow constant folding with the template of the define_insn,
4979 ; then to have the insns split later (between sched1 and final).
4980
4981 (define_expand "floatsidf2"
4982   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
4983                    (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
4984               (use (match_dup 2))
4985               (use (match_dup 3))
4986               (clobber (match_dup 4))
4987               (clobber (match_dup 5))
4988               (clobber (match_dup 6))])]
4989   "TARGET_HARD_FLOAT && TARGET_FPRS"
4990   "
4991 {
4992   if (TARGET_POWERPC64)
4993     {
4994       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
4995       rtx t1 = gen_reg_rtx (DImode);
4996       rtx t2 = gen_reg_rtx (DImode);
4997       emit_insn (gen_floatsidf_ppc64 (operands[0], operands[1], mem, t1, t2));
4998       DONE;
4999     }
5000
5001   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5002   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
5003   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5004   operands[5] = gen_reg_rtx (DFmode);
5005   operands[6] = gen_reg_rtx (SImode);
5006 }")
5007
5008 (define_insn "*floatsidf2_internal"
5009   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5010         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5011    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5012    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5013    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5014    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))
5015    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
5016   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5017   "#"
5018   [(set_attr "length" "24")])
5019
5020 (define_split
5021   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5022         (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5023    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5024    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5025    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5026    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))
5027    (clobber (match_operand:SI 6 "gpc_reg_operand" ""))]
5028   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5029   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5030         (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5031    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5032    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5033    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5034    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))
5035    (clobber (match_operand:SI 6 "gpc_reg_operand" ""))]
5036   "
5037 {
5038   rtx lowword, highword;
5039   if (GET_CODE (operands[4]) != MEM)
5040     abort();
5041   highword = XEXP (operands[4], 0);
5042   lowword = plus_constant (highword, 4);
5043   if (! WORDS_BIG_ENDIAN)
5044     {
5045       rtx tmp;
5046       tmp = highword; highword = lowword; lowword = tmp;
5047     }
5048
5049   emit_insn (gen_xorsi3 (operands[6], operands[1], 
5050                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
5051   emit_move_insn (gen_rtx_MEM (SImode, lowword), operands[6]);
5052   emit_move_insn (gen_rtx_MEM (SImode, highword), operands[2]);
5053   emit_move_insn (operands[5], operands[4]);
5054   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5055   DONE;
5056 }")
5057
5058 (define_expand "floatunssisf2"
5059   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5060         (unsigned_float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5061   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5062   "")
5063
5064 (define_expand "floatunssidf2"
5065   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5066                    (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5067               (use (match_dup 2))
5068               (use (match_dup 3))
5069               (clobber (match_dup 4))
5070               (clobber (match_dup 5))])]
5071   "TARGET_HARD_FLOAT && TARGET_FPRS"
5072   "
5073 {
5074   if (TARGET_POWERPC64)
5075     {
5076       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5077       rtx t1 = gen_reg_rtx (DImode);
5078       rtx t2 = gen_reg_rtx (DImode);
5079       emit_insn (gen_floatunssidf_ppc64 (operands[0], operands[1], mem,
5080                                          t1, t2));
5081       DONE;
5082     }
5083
5084   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5085   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
5086   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5087   operands[5] = gen_reg_rtx (DFmode);
5088 }")
5089
5090 (define_insn "*floatunssidf2_internal"
5091   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5092         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5093    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5094    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5095    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5096    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))]
5097   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5098   "#"
5099   [(set_attr "length" "20")])
5100
5101 (define_split
5102   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5103         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5104    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5105    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5106    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5107    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))]
5108   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5109   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5110         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5111    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5112    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5113    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5114    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))]
5115   "
5116 {
5117   rtx lowword, highword;
5118   if (GET_CODE (operands[4]) != MEM)
5119     abort();
5120   highword = XEXP (operands[4], 0);
5121   lowword = plus_constant (highword, 4);
5122   if (! WORDS_BIG_ENDIAN)
5123     {
5124       rtx tmp;
5125       tmp = highword; highword = lowword; lowword = tmp;
5126     }
5127
5128   emit_move_insn (gen_rtx_MEM (SImode, lowword), operands[1]);
5129   emit_move_insn (gen_rtx_MEM (SImode, highword), operands[2]);
5130   emit_move_insn (operands[5], operands[4]);
5131   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5132   DONE;
5133 }")
5134
5135 (define_expand "fix_truncdfsi2"
5136   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
5137                    (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5138               (clobber (match_dup 2))
5139               (clobber (match_dup 3))])]
5140   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5141   "
5142 {
5143   operands[2] = gen_reg_rtx (DImode);
5144   operands[3] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5145 }")
5146
5147 (define_insn "*fix_truncdfsi2_internal"
5148   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5149         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5150    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))
5151    (clobber (match_operand:DI 3 "memory_operand" "=o"))]
5152   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5153   "#"
5154   [(set_attr "length" "16")])
5155
5156 (define_split
5157   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5158         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5159    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
5160    (clobber (match_operand:DI 3 "offsettable_mem_operand" ""))]
5161   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5162   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5163         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5164    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
5165    (clobber (match_operand:DI 3 "offsettable_mem_operand" ""))]
5166   "
5167 {
5168   rtx lowword;
5169   if (GET_CODE (operands[3]) != MEM)
5170     abort();
5171   lowword = XEXP (operands[3], 0);
5172   if (WORDS_BIG_ENDIAN)
5173     lowword = plus_constant (lowword, 4);
5174
5175   emit_insn (gen_fctiwz (operands[2], operands[1]));
5176   emit_move_insn (operands[3], operands[2]);
5177   emit_move_insn (operands[0], gen_rtx_MEM (SImode, lowword));
5178   DONE;
5179 }")
5180
5181 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
5182 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
5183 ; because the first makes it clear that operand 0 is not live
5184 ; before the instruction.
5185 (define_insn "fctiwz"
5186   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
5187         (unspec:DI [(fix:SI (match_operand:DF 1 "gpc_reg_operand" "f"))]
5188                    UNSPEC_FCTIWZ))]
5189   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5190   "{fcirz|fctiwz} %0,%1"
5191   [(set_attr "type" "fp")])
5192
5193 (define_expand "floatsisf2"
5194   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5195         (float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5196   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5197   "")
5198
5199 (define_insn "floatdidf2"
5200   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5201         (float:DF (match_operand:DI 1 "gpc_reg_operand" "*f")))]
5202   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5203   "fcfid %0,%1"
5204   [(set_attr "type" "fp")])
5205
5206 (define_insn_and_split "floatsidf_ppc64"
5207   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5208         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5209    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5210    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5211    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5212   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5213   "#"
5214   "&& 1"
5215   [(set (match_dup 3) (sign_extend:DI (match_dup 1)))
5216    (set (match_dup 2) (match_dup 3))
5217    (set (match_dup 4) (match_dup 2))
5218    (set (match_dup 0) (float:DF (match_dup 4)))]
5219   "")
5220
5221 (define_insn_and_split "floatunssidf_ppc64"
5222   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5223         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5224    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5225    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5226    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5227   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5228   "#"
5229   "&& 1"
5230   [(set (match_dup 3) (zero_extend:DI (match_dup 1)))
5231    (set (match_dup 2) (match_dup 3))
5232    (set (match_dup 4) (match_dup 2))
5233    (set (match_dup 0) (float:DF (match_dup 4)))]
5234   "")
5235
5236 (define_insn "fix_truncdfdi2"
5237   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
5238         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "f")))]
5239   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5240   "fctidz %0,%1"
5241   [(set_attr "type" "fp")])
5242
5243 (define_expand "floatdisf2"
5244   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5245         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
5246   "TARGET_64BIT && TARGET_HARD_FLOAT && TARGET_FPRS"
5247   "
5248 {
5249   if (!flag_unsafe_math_optimizations)
5250     {
5251       rtx label = gen_label_rtx ();
5252       emit_insn (gen_floatdisf2_internal2 (operands[1], label));
5253       emit_label (label);
5254     }
5255   emit_insn (gen_floatdisf2_internal1 (operands[0], operands[1]));
5256   DONE;
5257 }")
5258
5259 ;; This is not IEEE compliant if rounding mode is "round to nearest".
5260 ;; If the DI->DF conversion is inexact, then it's possible to suffer
5261 ;; from double rounding.
5262 (define_insn_and_split "floatdisf2_internal1"
5263   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5264         (float:SF (match_operand:DI 1 "gpc_reg_operand" "*f")))
5265    (clobber (match_scratch:DF 2 "=f"))]
5266   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5267   "#"
5268   "&& reload_completed"
5269   [(set (match_dup 2)
5270         (float:DF (match_dup 1)))
5271    (set (match_dup 0)
5272         (float_truncate:SF (match_dup 2)))]
5273   "")
5274
5275 ;; Twiddles bits to avoid double rounding.
5276 ;; Bits that might be truncated when converting to DFmode are replaced
5277 ;; by a bit that won't be lost at that stage, but is below the SFmode
5278 ;; rounding position.
5279 (define_expand "floatdisf2_internal2"
5280   [(parallel [(set (match_dup 4)
5281                    (compare:CC (and:DI (match_operand:DI 0 "" "")
5282                                        (const_int 2047))
5283                                (const_int 0)))
5284               (set (match_dup 2) (and:DI (match_dup 0) (const_int 2047)))
5285               (clobber (match_scratch:CC 7 ""))])
5286    (set (match_dup 3) (ashiftrt:DI (match_dup 0) (const_int 53)))
5287    (set (match_dup 3) (plus:DI (match_dup 3) (const_int 1)))
5288    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
5289                            (label_ref (match_operand:DI 1 "" ""))
5290                            (pc)))
5291    (set (match_dup 5) (compare:CCUNS (match_dup 3) (const_int 2)))
5292    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
5293                            (label_ref (match_dup 1))
5294                            (pc)))
5295    (set (match_dup 0) (xor:DI (match_dup 0) (match_dup 2)))
5296    (set (match_dup 0) (ior:DI (match_dup 0) (const_int 2048)))]
5297   "TARGET_64BIT && TARGET_HARD_FLOAT && TARGET_FPRS"
5298   "
5299 {
5300   operands[2] = gen_reg_rtx (DImode);
5301   operands[3] = gen_reg_rtx (DImode);
5302   operands[4] = gen_reg_rtx (CCmode);
5303   operands[5] = gen_reg_rtx (CCUNSmode);
5304 }")
5305 \f
5306 ;; Define the DImode operations that can be done in a small number
5307 ;; of instructions.  The & constraints are to prevent the register
5308 ;; allocator from allocating registers that overlap with the inputs
5309 ;; (for example, having an input in 7,8 and an output in 6,7).  We
5310 ;; also allow for the output being the same as one of the inputs.
5311
5312 (define_insn "*adddi3_noppc64"
5313   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
5314         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
5315                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
5316   "! TARGET_POWERPC64"
5317   "*
5318 {
5319   if (WORDS_BIG_ENDIAN)
5320     return (GET_CODE (operands[2])) != CONST_INT
5321             ? \"{a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2\"
5322             : \"{ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1\";
5323   else
5324     return (GET_CODE (operands[2])) != CONST_INT
5325             ? \"{a|addc} %0,%1,%2\;{ae|adde} %L0,%L1,%L2\"
5326             : \"{ai|addic} %0,%1,%2\;{a%G2e|add%G2e} %L0,%L1\";
5327 }"
5328   [(set_attr "length" "8")])
5329
5330 (define_insn "*subdi3_noppc64"
5331   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
5332         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
5333                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
5334   "! TARGET_POWERPC64"
5335   "*
5336 {
5337   if (WORDS_BIG_ENDIAN)
5338     return (GET_CODE (operands[1]) != CONST_INT)
5339             ? \"{sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1\"
5340             : \"{sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2\";
5341   else
5342     return (GET_CODE (operands[1]) != CONST_INT)
5343             ? \"{sf|subfc} %0,%2,%1\;{sfe|subfe} %L0,%L2,%L1\"
5344             : \"{sfi|subfic} %0,%2,%1\;{sf%G1e|subf%G1e} %L0,%L2\";
5345 }"
5346   [(set_attr "length" "8")])
5347
5348 (define_insn "*negdi2_noppc64"
5349   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5350         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
5351   "! TARGET_POWERPC64"
5352   "*
5353 {
5354   return (WORDS_BIG_ENDIAN)
5355     ? \"{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1\"
5356     : \"{sfi|subfic} %0,%1,0\;{sfze|subfze} %L0,%L1\";
5357 }"
5358   [(set_attr "length" "8")])
5359
5360 (define_expand "mulsidi3"
5361   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5362         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5363                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5364   "! TARGET_POWERPC64"
5365   "
5366 {
5367   if (! TARGET_POWER && ! TARGET_POWERPC)
5368     {
5369       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
5370       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
5371       emit_insn (gen_mull_call ());
5372       if (WORDS_BIG_ENDIAN)
5373         emit_move_insn (operands[0], gen_rtx_REG (DImode, 3));
5374       else
5375         {
5376           emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
5377                           gen_rtx_REG (SImode, 3));
5378           emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
5379                           gen_rtx_REG (SImode, 4));
5380         }
5381       DONE;
5382     }
5383   else if (TARGET_POWER)
5384     {
5385       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
5386       DONE;
5387     }
5388 }")
5389
5390 (define_insn "mulsidi3_mq"
5391   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5392         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5393                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
5394    (clobber (match_scratch:SI 3 "=q"))]
5395   "TARGET_POWER"
5396   "mul %0,%1,%2\;mfmq %L0"
5397   [(set_attr "type" "imul")
5398    (set_attr "length" "8")])
5399
5400 (define_insn "*mulsidi3_no_mq"
5401   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5402         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5403                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
5404   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
5405   "*
5406 {
5407   return (WORDS_BIG_ENDIAN)
5408     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
5409     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
5410 }"
5411   [(set_attr "type" "imul")
5412    (set_attr "length" "8")])
5413
5414 (define_split
5415   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5416         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5417                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5418   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
5419   [(set (match_dup 3)
5420         (truncate:SI
5421          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
5422                                (sign_extend:DI (match_dup 2)))
5423                       (const_int 32))))
5424    (set (match_dup 4)
5425         (mult:SI (match_dup 1)
5426                  (match_dup 2)))]
5427   "
5428 {
5429   int endian = (WORDS_BIG_ENDIAN == 0);
5430   operands[3] = operand_subword (operands[0], endian, 0, DImode);
5431   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
5432 }")
5433
5434 (define_expand "umulsidi3"
5435   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5436         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5437                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5438   "TARGET_POWERPC && ! TARGET_POWERPC64"
5439   "
5440 {
5441   if (TARGET_POWER)
5442     {
5443       emit_insn (gen_umulsidi3_mq (operands[0], operands[1], operands[2]));
5444       DONE;
5445     }
5446 }")
5447
5448 (define_insn "umulsidi3_mq"
5449   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5450         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5451                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
5452    (clobber (match_scratch:SI 3 "=q"))]
5453   "TARGET_POWERPC && TARGET_POWER"
5454   "*
5455 {
5456   return (WORDS_BIG_ENDIAN)
5457     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
5458     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
5459 }"
5460   [(set_attr "type" "imul")
5461    (set_attr "length" "8")])
5462
5463 (define_insn "*umulsidi3_no_mq"
5464   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5465         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5466                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
5467   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
5468   "*
5469 {
5470   return (WORDS_BIG_ENDIAN)
5471     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
5472     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
5473 }"
5474   [(set_attr "type" "imul")
5475    (set_attr "length" "8")])
5476
5477 (define_split
5478   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5479         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5480                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5481   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
5482   [(set (match_dup 3)
5483         (truncate:SI
5484          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
5485                                (zero_extend:DI (match_dup 2)))
5486                       (const_int 32))))
5487    (set (match_dup 4)
5488         (mult:SI (match_dup 1)
5489                  (match_dup 2)))]
5490   "
5491 {
5492   int endian = (WORDS_BIG_ENDIAN == 0);
5493   operands[3] = operand_subword (operands[0], endian, 0, DImode);
5494   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
5495 }")
5496
5497 (define_expand "smulsi3_highpart"
5498   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5499         (truncate:SI
5500          (lshiftrt:DI (mult:DI (sign_extend:DI
5501                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5502                                (sign_extend:DI
5503                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5504                       (const_int 32))))]
5505   ""
5506   "
5507 {
5508   if (! TARGET_POWER && ! TARGET_POWERPC)
5509     {
5510       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
5511       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
5512       emit_insn (gen_mulh_call ());
5513       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
5514       DONE;
5515     }
5516   else if (TARGET_POWER)
5517     {
5518       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
5519       DONE;
5520     }
5521 }")
5522
5523 (define_insn "smulsi3_highpart_mq"
5524   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5525         (truncate:SI
5526          (lshiftrt:DI (mult:DI (sign_extend:DI
5527                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5528                                (sign_extend:DI
5529                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5530                       (const_int 32))))
5531    (clobber (match_scratch:SI 3 "=q"))]
5532   "TARGET_POWER"
5533   "mul %0,%1,%2"
5534   [(set_attr "type" "imul")])
5535
5536 (define_insn "*smulsi3_highpart_no_mq"
5537   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5538         (truncate:SI
5539          (lshiftrt:DI (mult:DI (sign_extend:DI
5540                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5541                                (sign_extend:DI
5542                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5543                       (const_int 32))))]
5544   "TARGET_POWERPC && ! TARGET_POWER"
5545   "mulhw %0,%1,%2"
5546   [(set_attr "type" "imul")])
5547
5548 (define_expand "umulsi3_highpart"
5549   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5550         (truncate:SI
5551          (lshiftrt:DI (mult:DI (zero_extend:DI
5552                                 (match_operand:SI 1 "gpc_reg_operand" ""))
5553                                (zero_extend:DI
5554                                 (match_operand:SI 2 "gpc_reg_operand" "")))
5555                       (const_int 32))))]
5556   "TARGET_POWERPC"
5557   "
5558 {
5559   if (TARGET_POWER)
5560     {
5561       emit_insn (gen_umulsi3_highpart_mq (operands[0], operands[1], operands[2]));
5562       DONE;
5563     }
5564 }")
5565
5566 (define_insn "umulsi3_highpart_mq"
5567   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5568         (truncate:SI
5569          (lshiftrt:DI (mult:DI (zero_extend:DI
5570                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5571                                (zero_extend:DI
5572                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5573                       (const_int 32))))
5574    (clobber (match_scratch:SI 3 "=q"))]
5575   "TARGET_POWERPC && TARGET_POWER"
5576   "mulhwu %0,%1,%2"
5577   [(set_attr "type" "imul")])
5578
5579 (define_insn "*umulsi3_highpart_no_mq"
5580   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5581         (truncate:SI
5582          (lshiftrt:DI (mult:DI (zero_extend:DI
5583                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5584                                (zero_extend:DI
5585                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5586                       (const_int 32))))]
5587   "TARGET_POWERPC && ! TARGET_POWER"
5588   "mulhwu %0,%1,%2"
5589   [(set_attr "type" "imul")])
5590
5591 ;; If operands 0 and 2 are in the same register, we have a problem.  But
5592 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
5593 ;; why we have the strange constraints below.
5594 (define_insn "ashldi3_power"
5595   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
5596         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
5597                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
5598    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
5599   "TARGET_POWER"
5600   "@
5601    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
5602    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
5603    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
5604    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
5605   [(set_attr "length" "8")])
5606
5607 (define_insn "lshrdi3_power"
5608   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
5609         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
5610                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
5611    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
5612   "TARGET_POWER"
5613   "@
5614    {s%A2i|s%A2wi} %L0,%1,%h2\;{cal %0,0(0)|li %0,0}
5615    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
5616    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
5617    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
5618   [(set_attr "length" "8")])
5619
5620 ;; Shift by a variable amount is too complex to be worth open-coding.  We
5621 ;; just handle shifts by constants.
5622 (define_insn "ashrdi3_power"
5623   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5624         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5625                      (match_operand:SI 2 "const_int_operand" "M,i")))
5626    (clobber (match_scratch:SI 3 "=X,q"))]
5627   "TARGET_POWER"
5628   "@
5629    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
5630    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
5631   [(set_attr "length" "8")])
5632
5633 (define_insn "ashrdi3_no_power"
5634   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
5635         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5636                      (match_operand:SI 2 "const_int_operand" "M,i")))]
5637   "TARGET_32BIT && !TARGET_POWERPC64 && !TARGET_POWER"
5638   "@
5639    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
5640    {sri|srwi} %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;{srai|srawi} %0,%1,%h2"
5641   [(set_attr "length" "8,12")])
5642
5643 (define_insn "*ashrdisi3_noppc64"
5644   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5645         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")    
5646                                 (const_int 32)) 4))]
5647   "TARGET_32BIT && !TARGET_POWERPC64"
5648   "*
5649 {
5650   if (REGNO (operands[0]) == REGNO (operands[1]))
5651     return \"\";
5652   else
5653     return \"mr %0,%1\";
5654 }"
5655    [(set_attr "length" "4")])      
5656
5657 \f
5658 ;; PowerPC64 DImode operations.
5659
5660 (define_expand "adddi3"
5661   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5662         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5663                  (match_operand:DI 2 "reg_or_add_cint64_operand" "")))]
5664   ""
5665   "
5666 {
5667   if (! TARGET_POWERPC64)
5668     {
5669       if (non_short_cint_operand (operands[2], DImode))
5670         FAIL;
5671     }
5672   else
5673     if (GET_CODE (operands[2]) == CONST_INT
5674         && ! add_operand (operands[2], DImode))
5675       {
5676         rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
5677                    ? operands[0] : gen_reg_rtx (DImode));
5678
5679         HOST_WIDE_INT val = INTVAL (operands[2]);
5680         HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
5681         HOST_WIDE_INT rest = trunc_int_for_mode (val - low, DImode);
5682
5683         if (!CONST_OK_FOR_LETTER_P (rest, 'L'))
5684           FAIL;
5685
5686         /* The ordering here is important for the prolog expander.
5687            When space is allocated from the stack, adding 'low' first may
5688            produce a temporary deallocation (which would be bad).  */
5689         emit_insn (gen_adddi3 (tmp, operands[1], GEN_INT (rest)));
5690         emit_insn (gen_adddi3 (operands[0], tmp, GEN_INT (low)));
5691         DONE;
5692       }
5693 }")
5694
5695 ;; Discourage ai/addic because of carry but provide it in an alternative
5696 ;; allowing register zero as source.
5697
5698 (define_insn "*adddi3_internal1"
5699   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,?r,r")
5700         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,b,r,b")
5701                  (match_operand:DI 2 "add_operand" "r,I,I,L")))]
5702   "TARGET_POWERPC64"
5703   "@
5704    add %0,%1,%2
5705    addi %0,%1,%2
5706    addic %0,%1,%2
5707    addis %0,%1,%v2")
5708
5709 (define_insn "*adddi3_internal2"
5710   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
5711         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
5712                              (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I"))
5713                     (const_int 0)))
5714    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
5715   "TARGET_64BIT"
5716   "@
5717    add. %3,%1,%2
5718    addic. %3,%1,%2
5719    #
5720    #"
5721   [(set_attr "type" "fast_compare,compare,compare,compare")
5722    (set_attr "length" "4,4,8,8")])
5723
5724 (define_split
5725   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5726         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5727                              (match_operand:DI 2 "reg_or_short_operand" ""))
5728                     (const_int 0)))
5729    (clobber (match_scratch:DI 3 ""))]
5730   "TARGET_POWERPC64 && reload_completed"
5731   [(set (match_dup 3)
5732         (plus:DI (match_dup 1) (match_dup 2)))
5733    (set (match_dup 0)
5734         (compare:CC (match_dup 3)
5735                     (const_int 0)))]
5736   "")
5737
5738 (define_insn "*adddi3_internal3"
5739   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
5740         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
5741                              (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I"))
5742                     (const_int 0)))
5743    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
5744         (plus:DI (match_dup 1) (match_dup 2)))]
5745   "TARGET_64BIT"
5746   "@
5747    add. %0,%1,%2
5748    addic. %0,%1,%2
5749    #
5750    #"
5751   [(set_attr "type" "fast_compare,compare,compare,compare")
5752    (set_attr "length" "4,4,8,8")])
5753
5754 (define_split
5755   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5756         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5757                              (match_operand:DI 2 "reg_or_short_operand" ""))
5758                     (const_int 0)))
5759    (set (match_operand:DI 0 "gpc_reg_operand" "")
5760         (plus:DI (match_dup 1) (match_dup 2)))]
5761   "TARGET_POWERPC64 && reload_completed"
5762   [(set (match_dup 0)
5763         (plus:DI (match_dup 1) (match_dup 2)))
5764    (set (match_dup 3)
5765         (compare:CC (match_dup 0)
5766                     (const_int 0)))]
5767   "")
5768
5769 ;; Split an add that we can't do in one insn into two insns, each of which
5770 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
5771 ;; add should be last in case the result gets used in an address.
5772
5773 (define_split
5774   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5775         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5776                  (match_operand:DI 2 "non_add_cint_operand" "")))]
5777   "TARGET_POWERPC64"
5778   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 3)))
5779    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 4)))]
5780 "
5781 {
5782   HOST_WIDE_INT val = INTVAL (operands[2]);
5783   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
5784   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, DImode);
5785
5786   operands[4] = GEN_INT (low);
5787   if (CONST_OK_FOR_LETTER_P (rest, 'L'))
5788     operands[3] = GEN_INT (rest);
5789   else if (! no_new_pseudos)
5790     {
5791       operands[3] = gen_reg_rtx (DImode);
5792       emit_move_insn (operands[3], operands[2]);
5793       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
5794       DONE;
5795     }
5796   else
5797     FAIL;
5798 }")
5799
5800 (define_insn "one_cmpldi2"
5801   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5802         (not:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
5803   "TARGET_POWERPC64"
5804   "nor %0,%1,%1")
5805
5806 (define_insn ""
5807   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5808         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
5809                     (const_int 0)))
5810    (clobber (match_scratch:DI 2 "=r,r"))]
5811   "TARGET_64BIT"
5812   "@
5813    nor. %2,%1,%1
5814    #"
5815   [(set_attr "type" "compare")
5816    (set_attr "length" "4,8")])
5817
5818 (define_split
5819   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5820         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
5821                     (const_int 0)))
5822    (clobber (match_scratch:DI 2 ""))]
5823   "TARGET_POWERPC64 && reload_completed"
5824   [(set (match_dup 2)
5825         (not:DI (match_dup 1)))
5826    (set (match_dup 0)
5827         (compare:CC (match_dup 2)
5828                     (const_int 0)))]
5829   "")
5830
5831 (define_insn ""
5832   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
5833         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
5834                     (const_int 0)))
5835    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5836         (not:DI (match_dup 1)))]
5837   "TARGET_64BIT"
5838   "@
5839    nor. %0,%1,%1
5840    #"
5841   [(set_attr "type" "compare")
5842    (set_attr "length" "4,8")])
5843
5844 (define_split
5845   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
5846         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
5847                     (const_int 0)))
5848    (set (match_operand:DI 0 "gpc_reg_operand" "")
5849         (not:DI (match_dup 1)))]
5850   "TARGET_POWERPC64 && reload_completed"
5851   [(set (match_dup 0)
5852         (not:DI (match_dup 1)))
5853    (set (match_dup 2)
5854         (compare:CC (match_dup 0)
5855                     (const_int 0)))]
5856   "")
5857
5858 (define_insn ""
5859   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5860         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I")
5861                   (match_operand:DI 2 "gpc_reg_operand" "r,r")))]
5862   "TARGET_POWERPC64"
5863   "@
5864    subf %0,%2,%1
5865    subfic %0,%2,%1")
5866
5867 (define_insn ""
5868   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5869         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5870                               (match_operand:DI 2 "gpc_reg_operand" "r,r"))
5871                     (const_int 0)))
5872    (clobber (match_scratch:DI 3 "=r,r"))]
5873   "TARGET_64BIT"
5874   "@
5875    subf. %3,%2,%1
5876    #"
5877   [(set_attr "type" "fast_compare")
5878    (set_attr "length" "4,8")])
5879
5880 (define_split
5881   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5882         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5883                               (match_operand:DI 2 "gpc_reg_operand" ""))
5884                     (const_int 0)))
5885    (clobber (match_scratch:DI 3 ""))]
5886   "TARGET_POWERPC64 && reload_completed"
5887   [(set (match_dup 3)
5888         (minus:DI (match_dup 1) (match_dup 2)))
5889    (set (match_dup 0)
5890         (compare:CC (match_dup 3)
5891                     (const_int 0)))]
5892   "")
5893
5894 (define_insn ""
5895   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
5896         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5897                               (match_operand:DI 2 "gpc_reg_operand" "r,r"))
5898                     (const_int 0)))
5899    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5900         (minus:DI (match_dup 1) (match_dup 2)))]
5901   "TARGET_64BIT"
5902   "@
5903    subf. %0,%2,%1
5904    #"
5905   [(set_attr "type" "fast_compare")
5906    (set_attr "length" "4,8")])
5907
5908 (define_split
5909   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5910         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5911                               (match_operand:DI 2 "gpc_reg_operand" ""))
5912                     (const_int 0)))
5913    (set (match_operand:DI 0 "gpc_reg_operand" "")
5914         (minus:DI (match_dup 1) (match_dup 2)))]
5915   "TARGET_POWERPC64 && reload_completed"
5916   [(set (match_dup 0)
5917         (minus:DI (match_dup 1) (match_dup 2)))
5918    (set (match_dup 3)
5919         (compare:CC (match_dup 0)
5920                     (const_int 0)))]
5921   "")
5922
5923 (define_expand "subdi3"
5924   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5925         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "")
5926                   (match_operand:DI 2 "reg_or_sub_cint64_operand" "")))]
5927   ""
5928   "
5929 {
5930   if (GET_CODE (operands[2]) == CONST_INT)
5931     {
5932       emit_insn (gen_adddi3 (operands[0], operands[1],
5933                              negate_rtx (DImode, operands[2])));
5934       DONE;
5935     }
5936 }")
5937
5938 (define_insn_and_split "absdi2"
5939   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5940         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
5941    (clobber (match_scratch:DI 2 "=&r,&r"))]
5942   "TARGET_POWERPC64"
5943   "#"
5944   "&& reload_completed"
5945   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
5946    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
5947    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
5948   "")
5949
5950 (define_insn_and_split "*nabsdi2"
5951   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5952         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
5953    (clobber (match_scratch:DI 2 "=&r,&r"))]
5954   "TARGET_POWERPC64"
5955   "#"
5956   "&& reload_completed"
5957   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
5958    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
5959    (set (match_dup 0) (minus:DI (match_dup 2) (match_dup 0)))]
5960   "")
5961
5962 (define_expand "negdi2"
5963   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5964         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "")))]
5965   ""
5966   "")
5967
5968 (define_insn ""
5969   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5970         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
5971   "TARGET_POWERPC64"
5972   "neg %0,%1")
5973
5974 (define_insn ""
5975   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5976         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
5977                     (const_int 0)))
5978    (clobber (match_scratch:DI 2 "=r,r"))]
5979   "TARGET_64BIT"
5980   "@
5981    neg. %2,%1
5982    #"
5983   [(set_attr "type" "fast_compare")
5984    (set_attr "length" "4,8")])
5985
5986 (define_split
5987   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5988         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" ""))
5989                     (const_int 0)))
5990    (clobber (match_scratch:DI 2 ""))]
5991   "TARGET_POWERPC64 && reload_completed"
5992   [(set (match_dup 2)
5993         (neg:DI (match_dup 1)))
5994    (set (match_dup 0)
5995         (compare:CC (match_dup 2)
5996                     (const_int 0)))]
5997   "")
5998
5999 (define_insn ""
6000   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
6001         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
6002                     (const_int 0)))
6003    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6004         (neg:DI (match_dup 1)))]
6005   "TARGET_64BIT"
6006   "@
6007    neg. %0,%1
6008    #"
6009   [(set_attr "type" "fast_compare")
6010    (set_attr "length" "4,8")])
6011
6012 (define_split
6013   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
6014         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" ""))
6015                     (const_int 0)))
6016    (set (match_operand:DI 0 "gpc_reg_operand" "")
6017         (neg:DI (match_dup 1)))]
6018   "TARGET_POWERPC64 && reload_completed"
6019   [(set (match_dup 0)
6020         (neg:DI (match_dup 1)))
6021    (set (match_dup 2)
6022         (compare:CC (match_dup 0)
6023                     (const_int 0)))]
6024   "")
6025
6026 (define_insn "clzdi2"
6027   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6028         (clz:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
6029   "TARGET_POWERPC64"
6030   "cntlzd %0,%1")
6031
6032 (define_expand "ctzdi2"
6033   [(set (match_dup 2)
6034         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
6035    (parallel [(set (match_dup 3) (and:DI (match_dup 1)      
6036                                          (match_dup 2)))   
6037               (clobber (scratch:CC))])
6038    (set (match_dup 4) (clz:DI (match_dup 3)))
6039    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
6040         (minus:DI (const_int 63) (match_dup 4)))]
6041   "TARGET_POWERPC64"
6042   {
6043      operands[2] = gen_reg_rtx (DImode); 
6044      operands[3] = gen_reg_rtx (DImode);
6045      operands[4] = gen_reg_rtx (DImode);
6046   })
6047
6048 (define_expand "ffsdi2"
6049   [(set (match_dup 2)
6050         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
6051    (parallel [(set (match_dup 3) (and:DI (match_dup 1)      
6052                                          (match_dup 2)))   
6053               (clobber (scratch:CC))])
6054    (set (match_dup 4) (clz:DI (match_dup 3)))
6055    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
6056         (minus:DI (const_int 64) (match_dup 4)))]
6057   "TARGET_POWERPC64"
6058   {
6059      operands[2] = gen_reg_rtx (DImode); 
6060      operands[3] = gen_reg_rtx (DImode);
6061      operands[4] = gen_reg_rtx (DImode);
6062   })
6063
6064 (define_insn "muldi3"
6065   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6066         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
6067                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
6068   "TARGET_POWERPC64"
6069   "mulld %0,%1,%2"
6070    [(set_attr "type" "lmul")])
6071
6072 (define_insn "*muldi3_internal1"
6073   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6074         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6075                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6076                     (const_int 0)))
6077    (clobber (match_scratch:DI 3 "=r,r"))]
6078   "TARGET_POWERPC64"
6079   "@
6080    mulld. %3,%1,%2
6081    #"
6082   [(set_attr "type" "lmul_compare")
6083    (set_attr "length" "4,8")])
6084
6085 (define_split
6086   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6087         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6088                              (match_operand:DI 2 "gpc_reg_operand" ""))
6089                     (const_int 0)))
6090    (clobber (match_scratch:DI 3 ""))]
6091   "TARGET_POWERPC64 && reload_completed"
6092   [(set (match_dup 3)
6093         (mult:DI (match_dup 1) (match_dup 2)))
6094    (set (match_dup 0)
6095         (compare:CC (match_dup 3)
6096                     (const_int 0)))]
6097   "")
6098
6099 (define_insn "*muldi3_internal2"
6100   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6101         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6102                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6103                     (const_int 0)))
6104    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6105         (mult:DI (match_dup 1) (match_dup 2)))]
6106   "TARGET_POWERPC64"
6107   "@
6108    mulld. %0,%1,%2
6109    #"
6110   [(set_attr "type" "lmul_compare")
6111    (set_attr "length" "4,8")])
6112
6113 (define_split
6114   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6115         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6116                              (match_operand:DI 2 "gpc_reg_operand" ""))
6117                     (const_int 0)))
6118    (set (match_operand:DI 0 "gpc_reg_operand" "")
6119         (mult:DI (match_dup 1) (match_dup 2)))]
6120   "TARGET_POWERPC64 && reload_completed"
6121   [(set (match_dup 0)
6122         (mult:DI (match_dup 1) (match_dup 2)))
6123    (set (match_dup 3)
6124         (compare:CC (match_dup 0)
6125                     (const_int 0)))]
6126   "")
6127
6128 (define_insn "smuldi3_highpart"
6129   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6130         (truncate:DI
6131          (lshiftrt:TI (mult:TI (sign_extend:TI
6132                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6133                                (sign_extend:TI
6134                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6135                       (const_int 64))))]
6136   "TARGET_POWERPC64"
6137   "mulhd %0,%1,%2"
6138   [(set_attr "type" "lmul")])
6139
6140 (define_insn "umuldi3_highpart"
6141   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6142         (truncate:DI
6143          (lshiftrt:TI (mult:TI (zero_extend:TI
6144                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6145                                (zero_extend:TI
6146                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6147                       (const_int 64))))]
6148   "TARGET_POWERPC64"
6149   "mulhdu %0,%1,%2"
6150   [(set_attr "type" "lmul")])
6151
6152 (define_expand "divdi3"
6153   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6154         (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6155                 (match_operand:DI 2 "reg_or_cint_operand" "")))]
6156   "TARGET_POWERPC64"
6157   "
6158 {
6159   if (GET_CODE (operands[2]) == CONST_INT
6160       && INTVAL (operands[2]) > 0
6161       && exact_log2 (INTVAL (operands[2])) >= 0)
6162     ;
6163   else
6164     operands[2] = force_reg (DImode, operands[2]);
6165 }")
6166
6167 (define_expand "moddi3"
6168   [(use (match_operand:DI 0 "gpc_reg_operand" ""))
6169    (use (match_operand:DI 1 "gpc_reg_operand" ""))
6170    (use (match_operand:DI 2 "reg_or_cint_operand" ""))]
6171   "TARGET_POWERPC64"
6172   "
6173 {
6174   int i;
6175   rtx temp1;
6176   rtx temp2;
6177
6178   if (GET_CODE (operands[2]) != CONST_INT
6179       || INTVAL (operands[2]) <= 0
6180       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
6181     FAIL;
6182
6183   temp1 = gen_reg_rtx (DImode);
6184   temp2 = gen_reg_rtx (DImode);
6185
6186   emit_insn (gen_divdi3 (temp1, operands[1], operands[2]));
6187   emit_insn (gen_ashldi3 (temp2, temp1, GEN_INT (i)));
6188   emit_insn (gen_subdi3 (operands[0], operands[1], temp2));
6189   DONE;
6190 }")
6191
6192 (define_insn ""
6193   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6194         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6195                 (match_operand:DI 2 "exact_log2_cint_operand" "N")))]
6196   "TARGET_POWERPC64"
6197   "sradi %0,%1,%p2\;addze %0,%0"
6198   [(set_attr "length" "8")])
6199
6200 (define_insn ""
6201   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6202         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6203                             (match_operand:DI 2 "exact_log2_cint_operand" "N,N"))
6204                     (const_int 0)))
6205    (clobber (match_scratch:DI 3 "=r,r"))]
6206   "TARGET_64BIT"
6207   "@
6208    sradi %3,%1,%p2\;addze. %3,%3
6209    #"
6210   [(set_attr "type" "compare")
6211    (set_attr "length" "8,12")])
6212
6213 (define_split
6214   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6215         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6216                             (match_operand:DI 2 "exact_log2_cint_operand" ""))
6217                     (const_int 0)))
6218    (clobber (match_scratch:DI 3 ""))]
6219   "TARGET_POWERPC64 && reload_completed"
6220   [(set (match_dup 3)
6221         (div:DI (match_dup 1) (match_dup 2)))
6222    (set (match_dup 0)
6223         (compare:CC (match_dup 3)
6224                     (const_int 0)))]
6225   "")
6226
6227 (define_insn ""
6228   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6229         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6230                             (match_operand:DI 2 "exact_log2_cint_operand" "N,N"))
6231                     (const_int 0)))
6232    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6233         (div:DI (match_dup 1) (match_dup 2)))]
6234   "TARGET_64BIT"
6235   "@
6236    sradi %0,%1,%p2\;addze. %0,%0
6237    #"
6238   [(set_attr "type" "compare")
6239    (set_attr "length" "8,12")])
6240
6241 (define_split
6242   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6243         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6244                             (match_operand:DI 2 "exact_log2_cint_operand" ""))
6245                     (const_int 0)))
6246    (set (match_operand:DI 0 "gpc_reg_operand" "")
6247         (div:DI (match_dup 1) (match_dup 2)))]
6248   "TARGET_POWERPC64 && reload_completed"
6249   [(set (match_dup 0)
6250         (div:DI (match_dup 1) (match_dup 2)))
6251    (set (match_dup 3)
6252         (compare:CC (match_dup 0)
6253                     (const_int 0)))]
6254   "")
6255
6256 (define_insn ""
6257   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6258         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6259                 (match_operand:DI 2 "gpc_reg_operand" "r")))]
6260   "TARGET_POWERPC64"
6261   "divd %0,%1,%2"
6262   [(set_attr "type" "ldiv")])
6263
6264 (define_insn "udivdi3"
6265   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6266         (udiv:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6267                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
6268   "TARGET_POWERPC64"
6269   "divdu %0,%1,%2"
6270   [(set_attr "type" "ldiv")])
6271
6272 (define_insn "rotldi3"
6273   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6274         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6275                    (match_operand:DI 2 "reg_or_cint_operand" "ri")))]
6276   "TARGET_POWERPC64"
6277   "rld%I2cl %0,%1,%H2,0")
6278
6279 (define_insn "*rotldi3_internal2"
6280   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6281         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6282                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6283                     (const_int 0)))
6284    (clobber (match_scratch:DI 3 "=r,r"))]
6285   "TARGET_64BIT"
6286   "@
6287    rld%I2cl. %3,%1,%H2,0
6288    #"
6289   [(set_attr "type" "delayed_compare")
6290    (set_attr "length" "4,8")])
6291
6292 (define_split
6293   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6294         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6295                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6296                     (const_int 0)))
6297    (clobber (match_scratch:DI 3 ""))]
6298   "TARGET_POWERPC64 && reload_completed"
6299   [(set (match_dup 3)
6300         (rotate:DI (match_dup 1) (match_dup 2)))
6301    (set (match_dup 0)
6302         (compare:CC (match_dup 3)
6303                     (const_int 0)))]
6304   "")
6305
6306 (define_insn "*rotldi3_internal3"
6307   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6308         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6309                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6310                     (const_int 0)))
6311    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6312         (rotate:DI (match_dup 1) (match_dup 2)))]
6313   "TARGET_64BIT"
6314   "@
6315    rld%I2cl. %0,%1,%H2,0
6316    #"
6317   [(set_attr "type" "delayed_compare")
6318    (set_attr "length" "4,8")])
6319
6320 (define_split
6321   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6322         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6323                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6324                     (const_int 0)))
6325    (set (match_operand:DI 0 "gpc_reg_operand" "")
6326         (rotate:DI (match_dup 1) (match_dup 2)))]
6327   "TARGET_POWERPC64 && reload_completed"
6328   [(set (match_dup 0)
6329         (rotate:DI (match_dup 1) (match_dup 2)))
6330    (set (match_dup 3)
6331         (compare:CC (match_dup 0)
6332                     (const_int 0)))]
6333   "")
6334
6335 (define_insn "*rotldi3_internal4"
6336   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6337         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6338                            (match_operand:DI 2 "reg_or_cint_operand" "ri"))
6339                 (match_operand:DI 3 "mask64_operand" "n")))]
6340   "TARGET_POWERPC64"
6341   "rld%I2c%B3 %0,%1,%H2,%S3")
6342
6343 (define_insn "*rotldi3_internal5"
6344   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6345         (compare:CC (and:DI
6346                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6347                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6348                      (match_operand:DI 3 "mask64_operand" "n,n"))
6349                     (const_int 0)))
6350    (clobber (match_scratch:DI 4 "=r,r"))]
6351   "TARGET_64BIT"
6352   "@
6353    rld%I2c%B3. %4,%1,%H2,%S3
6354    #"
6355   [(set_attr "type" "delayed_compare")
6356    (set_attr "length" "4,8")])
6357
6358 (define_split
6359   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6360         (compare:CC (and:DI
6361                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6362                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6363                      (match_operand:DI 3 "mask64_operand" ""))
6364                     (const_int 0)))
6365    (clobber (match_scratch:DI 4 ""))]
6366   "TARGET_POWERPC64 && reload_completed"
6367   [(set (match_dup 4)
6368         (and:DI (rotate:DI (match_dup 1)
6369                                 (match_dup 2))
6370                      (match_dup 3)))
6371    (set (match_dup 0)
6372         (compare:CC (match_dup 4)
6373                     (const_int 0)))]
6374   "")
6375
6376 (define_insn "*rotldi3_internal6"
6377   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6378         (compare:CC (and:DI
6379                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6380                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6381                      (match_operand:DI 3 "mask64_operand" "n,n"))
6382                     (const_int 0)))
6383    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6384         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6385   "TARGET_64BIT"
6386   "@
6387    rld%I2c%B3. %0,%1,%H2,%S3
6388    #"
6389   [(set_attr "type" "delayed_compare")
6390    (set_attr "length" "4,8")])
6391
6392 (define_split
6393   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6394         (compare:CC (and:DI
6395                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6396                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6397                      (match_operand:DI 3 "mask64_operand" ""))
6398                     (const_int 0)))
6399    (set (match_operand:DI 0 "gpc_reg_operand" "")
6400         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6401   "TARGET_POWERPC64 && reload_completed"
6402   [(set (match_dup 0)
6403         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
6404    (set (match_dup 4)
6405         (compare:CC (match_dup 0)
6406                     (const_int 0)))]
6407   "")
6408
6409 (define_insn "*rotldi3_internal7"
6410   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6411         (zero_extend:DI
6412          (subreg:QI
6413           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6414                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6415   "TARGET_POWERPC64"
6416   "rld%I2cl %0,%1,%H2,56")
6417
6418 (define_insn "*rotldi3_internal8"
6419   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6420         (compare:CC (zero_extend:DI
6421                      (subreg:QI
6422                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6423                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6424                     (const_int 0)))
6425    (clobber (match_scratch:DI 3 "=r,r"))]
6426   "TARGET_64BIT"
6427   "@
6428    rld%I2cl. %3,%1,%H2,56
6429    #"
6430   [(set_attr "type" "delayed_compare")
6431    (set_attr "length" "4,8")])
6432
6433 (define_split
6434   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6435         (compare:CC (zero_extend:DI
6436                      (subreg:QI
6437                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6438                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6439                     (const_int 0)))
6440    (clobber (match_scratch:DI 3 ""))]
6441   "TARGET_POWERPC64 && reload_completed"
6442   [(set (match_dup 3)
6443         (zero_extend:DI (subreg:QI
6444                       (rotate:DI (match_dup 1)
6445                                  (match_dup 2)) 0)))
6446    (set (match_dup 0)
6447         (compare:CC (match_dup 3)
6448                     (const_int 0)))]
6449   "")
6450
6451 (define_insn "*rotldi3_internal9"
6452   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6453         (compare:CC (zero_extend:DI
6454                      (subreg:QI
6455                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6456                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6457                     (const_int 0)))
6458    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6459         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6460   "TARGET_64BIT"
6461   "@
6462    rld%I2cl. %0,%1,%H2,56
6463    #"
6464   [(set_attr "type" "delayed_compare")
6465    (set_attr "length" "4,8")])
6466
6467 (define_split
6468   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6469         (compare:CC (zero_extend:DI
6470                      (subreg:QI
6471                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6472                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6473                     (const_int 0)))
6474    (set (match_operand:DI 0 "gpc_reg_operand" "")
6475         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6476   "TARGET_POWERPC64 && reload_completed"
6477   [(set (match_dup 0)
6478         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6479    (set (match_dup 3)
6480         (compare:CC (match_dup 0)
6481                     (const_int 0)))]
6482   "")
6483
6484 (define_insn "*rotldi3_internal10"
6485   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6486         (zero_extend:DI
6487          (subreg:HI
6488           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6489                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6490   "TARGET_POWERPC64"
6491   "rld%I2cl %0,%1,%H2,48")
6492
6493 (define_insn "*rotldi3_internal11"
6494   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6495         (compare:CC (zero_extend:DI
6496                      (subreg:HI
6497                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6498                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6499                     (const_int 0)))
6500    (clobber (match_scratch:DI 3 "=r,r"))]
6501   "TARGET_64BIT"
6502   "@
6503    rld%I2cl. %3,%1,%H2,48
6504    #"
6505   [(set_attr "type" "delayed_compare")
6506    (set_attr "length" "4,8")])
6507
6508 (define_split
6509   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6510         (compare:CC (zero_extend:DI
6511                      (subreg:HI
6512                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6513                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6514                     (const_int 0)))
6515    (clobber (match_scratch:DI 3 ""))]
6516   "TARGET_POWERPC64 && reload_completed"
6517   [(set (match_dup 3)
6518         (zero_extend:DI (subreg:HI
6519                       (rotate:DI (match_dup 1)
6520                                  (match_dup 2)) 0)))
6521    (set (match_dup 0)
6522         (compare:CC (match_dup 3)
6523                     (const_int 0)))]
6524   "")
6525
6526 (define_insn "*rotldi3_internal12"
6527   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6528         (compare:CC (zero_extend:DI
6529                      (subreg:HI
6530                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6531                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6532                     (const_int 0)))
6533    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6534         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6535   "TARGET_64BIT"
6536   "@
6537    rld%I2cl. %0,%1,%H2,48
6538    #"
6539   [(set_attr "type" "delayed_compare")
6540    (set_attr "length" "4,8")])
6541
6542 (define_split
6543   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6544         (compare:CC (zero_extend:DI
6545                      (subreg:HI
6546                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6547                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6548                     (const_int 0)))
6549    (set (match_operand:DI 0 "gpc_reg_operand" "")
6550         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6551   "TARGET_POWERPC64 && reload_completed"
6552   [(set (match_dup 0)
6553         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6554    (set (match_dup 3)
6555         (compare:CC (match_dup 0)
6556                     (const_int 0)))]
6557   "")
6558
6559 (define_insn "*rotldi3_internal13"
6560   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6561         (zero_extend:DI
6562          (subreg:SI
6563           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6564                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6565   "TARGET_POWERPC64"
6566   "rld%I2cl %0,%1,%H2,32")
6567
6568 (define_insn "*rotldi3_internal14"
6569   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6570         (compare:CC (zero_extend:DI
6571                      (subreg:SI
6572                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6573                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6574                     (const_int 0)))
6575    (clobber (match_scratch:DI 3 "=r,r"))]
6576   "TARGET_64BIT"
6577   "@
6578    rld%I2cl. %3,%1,%H2,32
6579    #"
6580   [(set_attr "type" "delayed_compare")
6581    (set_attr "length" "4,8")])
6582
6583 (define_split
6584   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6585         (compare:CC (zero_extend:DI
6586                      (subreg:SI
6587                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6588                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6589                     (const_int 0)))
6590    (clobber (match_scratch:DI 3 ""))]
6591   "TARGET_POWERPC64 && reload_completed"
6592   [(set (match_dup 3)
6593         (zero_extend:DI (subreg:SI
6594                       (rotate:DI (match_dup 1)
6595                                  (match_dup 2)) 0)))
6596    (set (match_dup 0)
6597         (compare:CC (match_dup 3)
6598                     (const_int 0)))]
6599   "")
6600
6601 (define_insn "*rotldi3_internal15"
6602   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6603         (compare:CC (zero_extend:DI
6604                      (subreg:SI
6605                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6606                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6607                     (const_int 0)))
6608    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6609         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6610   "TARGET_64BIT"
6611   "@
6612    rld%I2cl. %0,%1,%H2,32
6613    #"
6614   [(set_attr "type" "delayed_compare")
6615    (set_attr "length" "4,8")])
6616
6617 (define_split
6618   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6619         (compare:CC (zero_extend:DI
6620                      (subreg:SI
6621                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6622                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6623                     (const_int 0)))
6624    (set (match_operand:DI 0 "gpc_reg_operand" "")
6625         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6626   "TARGET_POWERPC64 && reload_completed"
6627   [(set (match_dup 0)
6628         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6629    (set (match_dup 3)
6630         (compare:CC (match_dup 0)
6631                     (const_int 0)))]
6632   "")
6633
6634 (define_expand "ashldi3"
6635   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6636         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6637                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
6638   "TARGET_POWERPC64 || TARGET_POWER"
6639   "
6640 {
6641   if (TARGET_POWERPC64)
6642     ;
6643   else if (TARGET_POWER)
6644     {
6645       emit_insn (gen_ashldi3_power (operands[0], operands[1], operands[2]));
6646       DONE;
6647     }
6648   else
6649     FAIL;
6650 }")
6651
6652 (define_insn "*ashldi3_internal1"
6653   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6654         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6655                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6656   "TARGET_POWERPC64"
6657   "sld%I2 %0,%1,%H2"
6658   [(set_attr "length" "8")])
6659   
6660 (define_insn "*ashldi3_internal2"
6661   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6662         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6663                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6664                     (const_int 0)))
6665    (clobber (match_scratch:DI 3 "=r,r"))]
6666   "TARGET_64BIT"
6667   "@
6668    sld%I2. %3,%1,%H2
6669    #"
6670   [(set_attr "type" "delayed_compare")
6671    (set_attr "length" "4,8")])
6672   
6673 (define_split
6674   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6675         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6676                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6677                     (const_int 0)))
6678    (clobber (match_scratch:DI 3 ""))]
6679   "TARGET_POWERPC64 && reload_completed"
6680   [(set (match_dup 3)
6681         (ashift:DI (match_dup 1) (match_dup 2)))
6682    (set (match_dup 0)
6683         (compare:CC (match_dup 3)
6684                     (const_int 0)))]
6685   "")
6686
6687 (define_insn "*ashldi3_internal3"
6688   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6689         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6690                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6691                     (const_int 0)))
6692    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6693         (ashift:DI (match_dup 1) (match_dup 2)))]
6694   "TARGET_64BIT"
6695   "@
6696    sld%I2. %0,%1,%H2
6697    #"
6698   [(set_attr "type" "delayed_compare")
6699    (set_attr "length" "4,8")])
6700
6701 (define_split
6702   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6703         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6704                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6705                     (const_int 0)))
6706    (set (match_operand:DI 0 "gpc_reg_operand" "")
6707         (ashift:DI (match_dup 1) (match_dup 2)))]
6708   "TARGET_POWERPC64 && reload_completed"
6709   [(set (match_dup 0)
6710         (ashift:DI (match_dup 1) (match_dup 2)))
6711    (set (match_dup 3)
6712         (compare:CC (match_dup 0)
6713                     (const_int 0)))]
6714   "")
6715
6716 (define_insn "*ashldi3_internal4"
6717   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6718         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6719                            (match_operand:SI 2 "const_int_operand" "i"))
6720                 (match_operand:DI 3 "const_int_operand" "n")))]
6721   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
6722   "rldic %0,%1,%H2,%W3")
6723
6724 (define_insn "ashldi3_internal5"
6725   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6726         (compare:CC
6727          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6728                             (match_operand:SI 2 "const_int_operand" "i,i"))
6729                  (match_operand:DI 3 "const_int_operand" "n,n"))
6730          (const_int 0)))
6731    (clobber (match_scratch:DI 4 "=r,r"))]
6732   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6733   "@
6734    rldic. %4,%1,%H2,%W3
6735    #"
6736   [(set_attr "type" "delayed_compare")
6737    (set_attr "length" "4,8")])
6738
6739 (define_split
6740   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6741         (compare:CC
6742          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6743                             (match_operand:SI 2 "const_int_operand" ""))
6744                  (match_operand:DI 3 "const_int_operand" ""))
6745          (const_int 0)))
6746    (clobber (match_scratch:DI 4 ""))]
6747   "TARGET_POWERPC64 && reload_completed
6748    && includes_rldic_lshift_p (operands[2], operands[3])"
6749   [(set (match_dup 4)
6750         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6751                 (match_dup 3)))
6752    (set (match_dup 0)
6753         (compare:CC (match_dup 4)
6754                     (const_int 0)))]
6755   "")
6756
6757 (define_insn "*ashldi3_internal6"
6758   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6759         (compare:CC
6760          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6761                             (match_operand:SI 2 "const_int_operand" "i,i"))
6762                     (match_operand:DI 3 "const_int_operand" "n,n"))
6763          (const_int 0)))
6764    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6765         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6766   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6767   "@
6768    rldic. %0,%1,%H2,%W3
6769    #"
6770   [(set_attr "type" "delayed_compare")
6771    (set_attr "length" "4,8")])
6772
6773 (define_split
6774   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6775         (compare:CC
6776          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6777                             (match_operand:SI 2 "const_int_operand" ""))
6778                  (match_operand:DI 3 "const_int_operand" ""))
6779          (const_int 0)))
6780    (set (match_operand:DI 0 "gpc_reg_operand" "")
6781         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6782   "TARGET_POWERPC64 && reload_completed
6783    && includes_rldic_lshift_p (operands[2], operands[3])"
6784   [(set (match_dup 0)
6785         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6786                 (match_dup 3)))
6787    (set (match_dup 4)
6788         (compare:CC (match_dup 0)
6789                     (const_int 0)))]
6790   "")
6791
6792 (define_insn "*ashldi3_internal7"
6793   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6794         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6795                            (match_operand:SI 2 "const_int_operand" "i"))
6796                 (match_operand:DI 3 "mask64_operand" "n")))]
6797   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
6798   "rldicr %0,%1,%H2,%S3")
6799
6800 (define_insn "ashldi3_internal8"
6801   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6802         (compare:CC
6803          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6804                             (match_operand:SI 2 "const_int_operand" "i,i"))
6805                  (match_operand:DI 3 "mask64_operand" "n,n"))
6806          (const_int 0)))
6807    (clobber (match_scratch:DI 4 "=r,r"))]
6808   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
6809   "@
6810    rldicr. %4,%1,%H2,%S3
6811    #"
6812   [(set_attr "type" "delayed_compare")
6813    (set_attr "length" "4,8")])
6814
6815 (define_split
6816   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6817         (compare:CC
6818          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6819                             (match_operand:SI 2 "const_int_operand" ""))
6820                  (match_operand:DI 3 "mask64_operand" ""))
6821          (const_int 0)))
6822    (clobber (match_scratch:DI 4 ""))]
6823   "TARGET_POWERPC64 && reload_completed
6824    && includes_rldicr_lshift_p (operands[2], operands[3])"
6825   [(set (match_dup 4)
6826         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6827                 (match_dup 3)))
6828    (set (match_dup 0)
6829         (compare:CC (match_dup 4)
6830                     (const_int 0)))]
6831   "")
6832
6833 (define_insn "*ashldi3_internal9"
6834   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6835         (compare:CC
6836          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6837                             (match_operand:SI 2 "const_int_operand" "i,i"))
6838                     (match_operand:DI 3 "mask64_operand" "n,n"))
6839          (const_int 0)))
6840    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6841         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6842   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
6843   "@
6844    rldicr. %0,%1,%H2,%S3
6845    #"
6846   [(set_attr "type" "delayed_compare")
6847    (set_attr "length" "4,8")])
6848
6849 (define_split
6850   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6851         (compare:CC
6852          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6853                             (match_operand:SI 2 "const_int_operand" ""))
6854                  (match_operand:DI 3 "mask64_operand" ""))
6855          (const_int 0)))
6856    (set (match_operand:DI 0 "gpc_reg_operand" "")
6857         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6858   "TARGET_POWERPC64 && reload_completed
6859    && includes_rldicr_lshift_p (operands[2], operands[3])"
6860   [(set (match_dup 0)
6861         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6862                 (match_dup 3)))
6863    (set (match_dup 4)
6864         (compare:CC (match_dup 0)
6865                     (const_int 0)))]
6866   "")
6867
6868 (define_expand "lshrdi3"
6869   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6870         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6871                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
6872   "TARGET_POWERPC64 || TARGET_POWER"
6873   "
6874 {
6875   if (TARGET_POWERPC64)
6876     ;
6877   else if (TARGET_POWER)
6878     {
6879       emit_insn (gen_lshrdi3_power (operands[0], operands[1], operands[2]));
6880       DONE;
6881     }
6882   else
6883     FAIL;
6884 }")
6885
6886 (define_insn "*lshrdi3_internal1"
6887   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6888         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6889                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6890   "TARGET_POWERPC64"
6891   "srd%I2 %0,%1,%H2")
6892
6893 (define_insn "*lshrdi3_internal2"
6894   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6895         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6896                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6897                     (const_int 0)))
6898    (clobber (match_scratch:DI 3 "=r,r"))]
6899   "TARGET_64BIT "
6900   "@
6901    srd%I2. %3,%1,%H2
6902    #"
6903   [(set_attr "type" "delayed_compare")
6904    (set_attr "length" "4,8")])
6905
6906 (define_split
6907   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6908         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6909                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6910                     (const_int 0)))
6911    (clobber (match_scratch:DI 3 ""))]
6912   "TARGET_POWERPC64 && reload_completed"
6913   [(set (match_dup 3)
6914         (lshiftrt:DI (match_dup 1) (match_dup 2)))
6915    (set (match_dup 0)
6916         (compare:CC (match_dup 3)
6917                     (const_int 0)))]
6918   "")
6919
6920 (define_insn "*lshrdi3_internal3"
6921   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6922         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6923                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6924                     (const_int 0)))
6925    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6926         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
6927   "TARGET_64BIT"
6928   "@
6929    srd%I2. %0,%1,%H2
6930    #"
6931   [(set_attr "type" "delayed_compare")
6932    (set_attr "length" "4,8")])
6933
6934 (define_split
6935   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6936         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6937                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6938                     (const_int 0)))
6939    (set (match_operand:DI 0 "gpc_reg_operand" "")
6940         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
6941   "TARGET_POWERPC64 && reload_completed"
6942   [(set (match_dup 0)
6943         (lshiftrt:DI (match_dup 1) (match_dup 2)))
6944    (set (match_dup 3)
6945         (compare:CC (match_dup 0)
6946                     (const_int 0)))]
6947   "")
6948
6949 (define_expand "ashrdi3"
6950   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6951         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6952                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
6953   ""
6954   "
6955 {
6956   if (TARGET_POWERPC64)
6957     ;
6958   else if (TARGET_POWER && GET_CODE (operands[2]) == CONST_INT)
6959     {
6960       emit_insn (gen_ashrdi3_power (operands[0], operands[1], operands[2]));
6961       DONE;
6962     }
6963   else if (TARGET_32BIT && GET_CODE (operands[2]) == CONST_INT)
6964     {
6965       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
6966       DONE;
6967     }
6968   else
6969     FAIL;
6970 }")
6971
6972 (define_insn "*ashrdi3_internal1"
6973   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6974         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6975                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6976   "TARGET_POWERPC64"
6977   "srad%I2 %0,%1,%H2")
6978
6979 (define_insn "*ashrdi3_internal2"
6980   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6981         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6982                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6983                     (const_int 0)))
6984    (clobber (match_scratch:DI 3 "=r,r"))]
6985   "TARGET_64BIT"
6986   "@
6987    srad%I2. %3,%1,%H2
6988    #"
6989   [(set_attr "type" "delayed_compare")
6990    (set_attr "length" "4,8")])
6991
6992 (define_split
6993   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6994         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6995                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6996                     (const_int 0)))
6997    (clobber (match_scratch:DI 3 ""))]
6998   "TARGET_POWERPC64 && reload_completed"
6999   [(set (match_dup 3)
7000         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7001    (set (match_dup 0)
7002         (compare:CC (match_dup 3)
7003                     (const_int 0)))]
7004   "")
7005
7006 (define_insn "*ashrdi3_internal3"
7007   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7008         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7009                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7010                     (const_int 0)))
7011    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7012         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7013   "TARGET_64BIT"
7014   "@
7015    srad%I2. %0,%1,%H2
7016    #"
7017   [(set_attr "type" "delayed_compare")
7018    (set_attr "length" "4,8")])
7019
7020 (define_split
7021   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7022         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7023                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7024                     (const_int 0)))
7025    (set (match_operand:DI 0 "gpc_reg_operand" "")
7026         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7027   "TARGET_POWERPC64 && reload_completed"
7028   [(set (match_dup 0)
7029         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7030    (set (match_dup 3)
7031         (compare:CC (match_dup 0)
7032                     (const_int 0)))]
7033   "")
7034
7035 (define_insn "anddi3"
7036   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r")
7037         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r")
7038                 (match_operand:DI 2 "and64_2_operand" "?r,S,K,J,t")))
7039    (clobber (match_scratch:CC 3 "=X,X,x,x,X"))]
7040   "TARGET_POWERPC64"
7041   "@
7042    and %0,%1,%2
7043    rldic%B2 %0,%1,0,%S2
7044    andi. %0,%1,%b2
7045    andis. %0,%1,%u2
7046    #"
7047   [(set_attr "length" "4,4,4,4,8")])
7048
7049 (define_split
7050   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7051         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7052                 (match_operand:DI 2 "mask64_2_operand" "")))
7053    (clobber (match_scratch:CC 3 ""))]
7054   "TARGET_POWERPC64
7055     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7056     && !mask64_operand (operands[2], DImode)"
7057   [(set (match_dup 0)
7058         (and:DI (rotate:DI (match_dup 1)
7059                            (match_dup 4))
7060                 (match_dup 5)))
7061    (set (match_dup 0)
7062         (and:DI (rotate:DI (match_dup 0)
7063                            (match_dup 6))
7064                 (match_dup 7)))]
7065   "
7066 {
7067   build_mask64_2_operands (operands[2], &operands[4]);
7068 }")
7069
7070 (define_insn "*anddi3_internal2"
7071   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,??y,??y,?y")
7072         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
7073                             (match_operand:DI 2 "and64_2_operand" "r,S,K,J,t,r,S,K,J,t"))
7074                     (const_int 0)))
7075    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r"))
7076    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,x,x,X"))]
7077   "TARGET_64BIT"
7078   "@
7079    and. %3,%1,%2
7080    rldic%B2. %3,%1,0,%S2
7081    andi. %3,%1,%b2
7082    andis. %3,%1,%u2
7083    #
7084    #
7085    #
7086    #
7087    #
7088    #"
7089   [(set_attr "type" "compare,delayed_compare,compare,compare,delayed_compare,compare,compare,compare,compare,compare")
7090    (set_attr "length" "4,4,4,4,8,8,8,8,8,12")])
7091
7092 (define_split
7093   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7094         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7095                             (match_operand:DI 2 "and64_operand" ""))
7096                     (const_int 0)))
7097    (clobber (match_scratch:DI 3 ""))
7098    (clobber (match_scratch:CC 4 ""))]
7099   "TARGET_POWERPC64 && reload_completed"
7100   [(parallel [(set (match_dup 3)
7101                    (and:DI (match_dup 1)
7102                            (match_dup 2)))
7103               (clobber (match_dup 4))])
7104    (set (match_dup 0)
7105         (compare:CC (match_dup 3)
7106                     (const_int 0)))]
7107   "")
7108
7109 (define_split
7110   [(set (match_operand:CC 0 "cc_reg_operand" "")
7111         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7112                             (match_operand:DI 2 "mask64_2_operand" ""))
7113                     (const_int 0)))
7114    (clobber (match_scratch:DI 3 ""))
7115    (clobber (match_scratch:CC 4 ""))]
7116   "TARGET_POWERPC64 && reload_completed
7117     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7118     && !mask64_operand (operands[2], DImode)"
7119   [(set (match_dup 3)
7120         (and:DI (rotate:DI (match_dup 1)
7121                            (match_dup 5))
7122                 (match_dup 6)))
7123    (parallel [(set (match_dup 0)
7124                    (compare:CC (and:DI (rotate:DI (match_dup 3)
7125                                                   (match_dup 7))
7126                                        (match_dup 8))
7127                                (const_int 0)))
7128               (clobber (match_dup 3))])]
7129   "
7130 {
7131   build_mask64_2_operands (operands[2], &operands[5]);
7132 }")
7133
7134 (define_insn "*anddi3_internal3"
7135   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,?y,?y,??y,??y,?y")
7136         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
7137                             (match_operand:DI 2 "and64_2_operand" "r,S,K,J,t,r,S,K,J,t"))
7138                     (const_int 0)))
7139    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
7140         (and:DI (match_dup 1) (match_dup 2)))
7141    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,x,x,X"))]
7142   "TARGET_64BIT"
7143   "@
7144    and. %0,%1,%2
7145    rldic%B2. %0,%1,0,%S2
7146    andi. %0,%1,%b2
7147    andis. %0,%1,%u2
7148    #
7149    #
7150    #
7151    #
7152    #
7153    #"
7154   [(set_attr "type" "compare,delayed_compare,compare,compare,delayed_compare,compare,compare,compare,compare,compare")
7155    (set_attr "length" "4,4,4,4,8,8,8,8,8,12")])
7156
7157 (define_split
7158   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7159         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7160                             (match_operand:DI 2 "and64_operand" ""))
7161                     (const_int 0)))
7162    (set (match_operand:DI 0 "gpc_reg_operand" "")
7163         (and:DI (match_dup 1) (match_dup 2)))
7164    (clobber (match_scratch:CC 4 ""))]
7165   "TARGET_POWERPC64 && reload_completed"
7166   [(parallel [(set (match_dup 0)
7167                     (and:DI (match_dup 1) (match_dup 2)))
7168                (clobber (match_dup 4))])
7169    (set (match_dup 3)
7170         (compare:CC (match_dup 0)
7171                     (const_int 0)))]
7172   "")
7173
7174 (define_split
7175   [(set (match_operand:CC 3 "cc_reg_operand" "")
7176         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7177                             (match_operand:DI 2 "mask64_2_operand" ""))
7178                     (const_int 0)))
7179    (set (match_operand:DI 0 "gpc_reg_operand" "")
7180         (and:DI (match_dup 1) (match_dup 2)))
7181    (clobber (match_scratch:CC 4 ""))]
7182   "TARGET_POWERPC64 && reload_completed
7183     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7184     && !mask64_operand (operands[2], DImode)"
7185   [(set (match_dup 0)
7186         (and:DI (rotate:DI (match_dup 1)
7187                            (match_dup 5))
7188                 (match_dup 6)))
7189    (parallel [(set (match_dup 3)
7190                    (compare:CC (and:DI (rotate:DI (match_dup 0)
7191                                                   (match_dup 7))
7192                                        (match_dup 8))
7193                                (const_int 0)))
7194               (set (match_dup 0)
7195                    (and:DI (rotate:DI (match_dup 0)
7196                                       (match_dup 7))
7197                            (match_dup 8)))])]
7198   "
7199 {
7200   build_mask64_2_operands (operands[2], &operands[5]);
7201 }")
7202
7203 (define_expand "iordi3"
7204   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7205         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
7206                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7207   "TARGET_POWERPC64"
7208   "
7209 {
7210   if (non_logical_cint_operand (operands[2], DImode))
7211     {
7212       HOST_WIDE_INT value;
7213       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7214                  ? operands[0] : gen_reg_rtx (DImode));
7215
7216       if (GET_CODE (operands[2]) == CONST_INT)
7217         {
7218           value = INTVAL (operands[2]);
7219           emit_insn (gen_iordi3 (tmp, operands[1],
7220                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7221         }
7222       else
7223         {
7224           value = CONST_DOUBLE_LOW (operands[2]);
7225           emit_insn (gen_iordi3 (tmp, operands[1],
7226                                  immed_double_const (value
7227                                                      & (~ (HOST_WIDE_INT) 0xffff),
7228                                                      0, DImode)));
7229         }
7230
7231       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7232       DONE;
7233     }
7234 }")
7235
7236 (define_expand "xordi3"
7237   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7238         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
7239                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7240   "TARGET_POWERPC64"
7241   "
7242 {
7243   if (non_logical_cint_operand (operands[2], DImode))
7244     {
7245       HOST_WIDE_INT value;
7246       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7247                  ? operands[0] : gen_reg_rtx (DImode));
7248
7249       if (GET_CODE (operands[2]) == CONST_INT)
7250         {
7251           value = INTVAL (operands[2]);
7252           emit_insn (gen_xordi3 (tmp, operands[1],
7253                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7254         }
7255       else
7256         {
7257           value = CONST_DOUBLE_LOW (operands[2]);
7258           emit_insn (gen_xordi3 (tmp, operands[1],
7259                                  immed_double_const (value
7260                                                      & (~ (HOST_WIDE_INT) 0xffff),
7261                                                      0, DImode)));
7262         }
7263
7264       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7265       DONE;
7266     }
7267 }")
7268
7269 (define_insn "*booldi3_internal1"
7270   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
7271         (match_operator:DI 3 "boolean_or_operator"
7272          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
7273           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
7274   "TARGET_POWERPC64"
7275   "@
7276    %q3 %0,%1,%2
7277    %q3i %0,%1,%b2
7278    %q3is %0,%1,%u2")
7279
7280 (define_insn "*booldi3_internal2"
7281   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7282         (compare:CC (match_operator:DI 4 "boolean_or_operator"
7283          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7284           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7285          (const_int 0)))
7286    (clobber (match_scratch:DI 3 "=r,r"))]
7287   "TARGET_64BIT"
7288   "@
7289    %q4. %3,%1,%2
7290    #"
7291   [(set_attr "type" "compare")
7292    (set_attr "length" "4,8")])
7293
7294 (define_split
7295   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7296         (compare:CC (match_operator:DI 4 "boolean_operator"
7297          [(match_operand:DI 1 "gpc_reg_operand" "")
7298           (match_operand:DI 2 "gpc_reg_operand" "")])
7299          (const_int 0)))
7300    (clobber (match_scratch:DI 3 ""))]
7301   "TARGET_POWERPC64 && reload_completed"
7302   [(set (match_dup 3) (match_dup 4))
7303    (set (match_dup 0)
7304         (compare:CC (match_dup 3)
7305                     (const_int 0)))]
7306   "")
7307
7308 (define_insn "*booldi3_internal3"
7309   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7310         (compare:CC (match_operator:DI 4 "boolean_operator"
7311          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7312           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7313          (const_int 0)))
7314    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7315         (match_dup 4))]
7316   "TARGET_64BIT"
7317   "@
7318    %q4. %0,%1,%2
7319    #"
7320   [(set_attr "type" "compare")
7321    (set_attr "length" "4,8")])
7322
7323 (define_split
7324   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7325         (compare:CC (match_operator:DI 4 "boolean_operator"
7326          [(match_operand:DI 1 "gpc_reg_operand" "")
7327           (match_operand:DI 2 "gpc_reg_operand" "")])
7328          (const_int 0)))
7329    (set (match_operand:DI 0 "gpc_reg_operand" "")
7330         (match_dup 4))]
7331   "TARGET_POWERPC64 && reload_completed"
7332   [(set (match_dup 0) (match_dup 4))
7333    (set (match_dup 3)
7334         (compare:CC (match_dup 0)
7335                     (const_int 0)))]
7336   "")
7337
7338 ;; Split a logical operation that we can't do in one insn into two insns, 
7339 ;; each of which does one 16-bit part.  This is used by combine.
7340
7341 (define_split
7342   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7343         (match_operator:DI 3 "boolean_or_operator"
7344          [(match_operand:DI 1 "gpc_reg_operand" "")
7345           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
7346   "TARGET_POWERPC64"
7347   [(set (match_dup 0) (match_dup 4))
7348    (set (match_dup 0) (match_dup 5))]
7349 "
7350 {
7351   rtx i3,i4;
7352   
7353   if (GET_CODE (operands[2]) == CONST_DOUBLE)
7354     {
7355       HOST_WIDE_INT value = CONST_DOUBLE_LOW (operands[2]);
7356       i3 = immed_double_const (value & (~ (HOST_WIDE_INT) 0xffff),
7357                                         0, DImode);
7358       i4 = GEN_INT (value & 0xffff);
7359     }
7360   else
7361     {
7362       i3 = GEN_INT (INTVAL (operands[2])
7363                              & (~ (HOST_WIDE_INT) 0xffff));
7364       i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
7365     }
7366   operands[4] = gen_rtx (GET_CODE (operands[3]), DImode,
7367                          operands[1], i3);
7368   operands[5] = gen_rtx (GET_CODE (operands[3]), DImode,
7369                          operands[0], i4);
7370 }")
7371
7372 (define_insn "*boolcdi3_internal1"
7373   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7374         (match_operator:DI 3 "boolean_operator"
7375          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7376           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
7377   "TARGET_POWERPC64"
7378   "%q3 %0,%2,%1")
7379
7380 (define_insn "*boolcdi3_internal2"
7381   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7382         (compare:CC (match_operator:DI 4 "boolean_operator"
7383          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7384           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7385          (const_int 0)))
7386    (clobber (match_scratch:DI 3 "=r,r"))]
7387   "TARGET_64BIT"
7388   "@
7389    %q4. %3,%2,%1
7390    #"
7391   [(set_attr "type" "compare")
7392    (set_attr "length" "4,8")])
7393
7394 (define_split
7395   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7396         (compare:CC (match_operator:DI 4 "boolean_operator"
7397          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7398           (match_operand:DI 2 "gpc_reg_operand" "")])
7399          (const_int 0)))
7400    (clobber (match_scratch:DI 3 ""))]
7401   "TARGET_POWERPC64 && reload_completed"
7402   [(set (match_dup 3) (match_dup 4))
7403    (set (match_dup 0)
7404         (compare:CC (match_dup 3)
7405                     (const_int 0)))]
7406   "")
7407
7408 (define_insn "*boolcdi3_internal3"
7409   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7410         (compare:CC (match_operator:DI 4 "boolean_operator"
7411          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7412           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7413          (const_int 0)))
7414    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7415         (match_dup 4))]
7416   "TARGET_64BIT"
7417   "@
7418    %q4. %0,%2,%1
7419    #"
7420   [(set_attr "type" "compare")
7421    (set_attr "length" "4,8")])
7422
7423 (define_split
7424   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7425         (compare:CC (match_operator:DI 4 "boolean_operator"
7426          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7427           (match_operand:DI 2 "gpc_reg_operand" "")])
7428          (const_int 0)))
7429    (set (match_operand:DI 0 "gpc_reg_operand" "")
7430         (match_dup 4))]
7431   "TARGET_POWERPC64 && reload_completed"
7432   [(set (match_dup 0) (match_dup 4))
7433    (set (match_dup 3)
7434         (compare:CC (match_dup 0)
7435                     (const_int 0)))]
7436   "")
7437
7438 (define_insn "*boolccdi3_internal1"
7439   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7440         (match_operator:DI 3 "boolean_operator"
7441          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7442           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
7443   "TARGET_POWERPC64"
7444   "%q3 %0,%1,%2")
7445
7446 (define_insn "*boolccdi3_internal2"
7447   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7448         (compare:CC (match_operator:DI 4 "boolean_operator"
7449          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7450           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7451          (const_int 0)))
7452    (clobber (match_scratch:DI 3 "=r,r"))]
7453   "TARGET_64BIT"
7454   "@
7455    %q4. %3,%1,%2
7456    #"
7457   [(set_attr "type" "compare")
7458    (set_attr "length" "4,8")])
7459
7460 (define_split
7461   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7462         (compare:CC (match_operator:DI 4 "boolean_operator"
7463          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7464           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7465          (const_int 0)))
7466    (clobber (match_scratch:DI 3 ""))]
7467   "TARGET_POWERPC64 && reload_completed"
7468   [(set (match_dup 3) (match_dup 4))
7469    (set (match_dup 0)
7470         (compare:CC (match_dup 3)
7471                     (const_int 0)))]
7472   "")
7473
7474 (define_insn "*boolccdi3_internal3"
7475   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7476         (compare:CC (match_operator:DI 4 "boolean_operator"
7477          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7478           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7479          (const_int 0)))
7480    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7481         (match_dup 4))]
7482   "TARGET_64BIT"
7483   "@
7484    %q4. %0,%1,%2
7485    #"
7486   [(set_attr "type" "compare")
7487    (set_attr "length" "4,8")])
7488
7489 (define_split
7490   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7491         (compare:CC (match_operator:DI 4 "boolean_operator"
7492          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7493           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7494          (const_int 0)))
7495    (set (match_operand:DI 0 "gpc_reg_operand" "")
7496         (match_dup 4))]
7497   "TARGET_POWERPC64 && reload_completed"
7498   [(set (match_dup 0) (match_dup 4))
7499    (set (match_dup 3)
7500         (compare:CC (match_dup 0)
7501                     (const_int 0)))]
7502   "")
7503 \f
7504 ;; Now define ways of moving data around.
7505
7506 ;; Elf specific ways of loading addresses for non-PIC code.
7507 ;; The output of this could be r0, but we make a very strong
7508 ;; preference for a base register because it will usually
7509 ;; be needed there.
7510 (define_insn "elf_high"
7511   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
7512         (high:SI (match_operand 1 "" "")))]
7513   "TARGET_ELF && ! TARGET_64BIT"
7514   "{liu|lis} %0,%1@ha")
7515
7516 (define_insn "elf_low"
7517   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
7518         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
7519                    (match_operand 2 "" "")))]
7520    "TARGET_ELF && ! TARGET_64BIT"
7521    "@
7522     {cal|la} %0,%2@l(%1)
7523     {ai|addic} %0,%1,%K2")
7524
7525 ;; Mach-O PIC trickery.
7526 (define_insn "macho_high"
7527   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
7528         (high:SI (match_operand 1 "" "")))]
7529   "TARGET_MACHO && ! TARGET_64BIT"
7530   "{liu|lis} %0,ha16(%1)")
7531
7532 (define_insn "macho_low"
7533   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
7534         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
7535                    (match_operand 2 "" "")))]
7536    "TARGET_MACHO && ! TARGET_64BIT"
7537    "@
7538     {cal %0,%a2@l(%1)|la %0,lo16(%2)(%1)}
7539     {cal %0,%a2@l(%1)|addic %0,%1,lo16(%2)}")
7540
7541 ;; Set up a register with a value from the GOT table
7542
7543 (define_expand "movsi_got"
7544   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7545         (unspec:SI [(match_operand:SI 1 "got_operand" "")
7546                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
7547   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7548   "
7549 {
7550   if (GET_CODE (operands[1]) == CONST)
7551     {
7552       rtx offset = const0_rtx;
7553       HOST_WIDE_INT value;
7554
7555       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
7556       value = INTVAL (offset);
7557       if (value != 0)
7558         {
7559           rtx tmp = (no_new_pseudos ? operands[0] : gen_reg_rtx (Pmode));
7560           emit_insn (gen_movsi_got (tmp, operands[1]));
7561           emit_insn (gen_addsi3 (operands[0], tmp, offset));
7562           DONE;
7563         }
7564     }
7565
7566   operands[2] = rs6000_got_register (operands[1]);
7567 }")
7568
7569 (define_insn "*movsi_got_internal"
7570   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7571         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7572                     (match_operand:SI 2 "gpc_reg_operand" "b")]
7573                    UNSPEC_MOVSI_GOT))]
7574   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7575   "{l|lwz} %0,%a1@got(%2)"
7576   [(set_attr "type" "load")])
7577
7578 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
7579 ;; didn't get allocated to a hard register.
7580 (define_split 
7581   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7582         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7583                     (match_operand:SI 2 "memory_operand" "")]
7584                    UNSPEC_MOVSI_GOT))]
7585   "DEFAULT_ABI == ABI_V4
7586     && flag_pic == 1
7587     && (reload_in_progress || reload_completed)"
7588   [(set (match_dup 0) (match_dup 2))
7589    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
7590                                  UNSPEC_MOVSI_GOT))]
7591   "")
7592
7593 ;; For SI, we special-case integers that can't be loaded in one insn.  We
7594 ;; do the load 16-bits at a time.  We could do this by loading from memory,
7595 ;; and this is even supposed to be faster, but it is simpler not to get
7596 ;; integers in the TOC.
7597 (define_expand "movsi"
7598   [(set (match_operand:SI 0 "general_operand" "")
7599         (match_operand:SI 1 "any_operand" ""))]
7600   ""
7601   "{ rs6000_emit_move (operands[0], operands[1], SImode); DONE; }")
7602
7603 (define_insn "movsi_low"
7604   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7605         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7606                            (match_operand 2 "" ""))))]
7607   "TARGET_MACHO && ! TARGET_64BIT"
7608   "{l|lwz} %0,lo16(%2)(%1)"
7609   [(set_attr "type" "load")
7610    (set_attr "length" "4")])
7611
7612 (define_insn "movsi_low_st"
7613   [(set (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7614                            (match_operand 2 "" "")))
7615         (match_operand:SI 0 "gpc_reg_operand" "r"))]
7616   "TARGET_MACHO && ! TARGET_64BIT"
7617   "{st|stw} %0,lo16(%2)(%1)"
7618   [(set_attr "type" "store")
7619    (set_attr "length" "4")])
7620
7621 (define_insn "movdf_low"
7622   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,!r")
7623         (mem:DF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
7624                            (match_operand 2 "" ""))))]
7625   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
7626   "*
7627 {
7628   switch (which_alternative)
7629     {
7630       case 0:
7631         return \"lfd %0,lo16(%2)(%1)\";
7632       case 1:
7633         {
7634           rtx operands2[4];
7635           operands2[0] = operands[0];
7636           operands2[1] = operands[1];
7637           operands2[2] = operands[2];
7638           if (TARGET_POWERPC64 && TARGET_32BIT)
7639             /* Note, old assemblers didn't support relocation here.  */
7640             return \"ld %0,lo16(%2)(%1)\";
7641           else
7642           {
7643             operands2[3] = gen_rtx_REG (SImode, RS6000_PIC_OFFSET_TABLE_REGNUM);     
7644             output_asm_insn (\"{l|lwz} %0,lo16(%2)(%1)\", operands);
7645 #if TARGET_MACHO
7646             if (MACHO_DYNAMIC_NO_PIC_P)
7647               output_asm_insn (\"{liu|lis} %L0,ha16(%2+4)\", operands);
7648             else     
7649             /* We cannot rely on ha16(low half)==ha16(high half), alas,
7650                although in practice it almost always is.  */
7651             output_asm_insn (\"{cau|addis} %L0,%3,ha16(%2+4)\", operands2);
7652 #endif
7653             return (\"{l|lwz} %L0,lo16(%2+4)(%L0)\");
7654           }
7655         }
7656       default:
7657         abort();
7658     }
7659 }"
7660   [(set_attr "type" "load")
7661    (set_attr "length" "4,12")])
7662
7663 (define_insn "movdf_low_st"
7664   [(set (mem:DF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7665                            (match_operand 2 "" "")))
7666         (match_operand:DF 0 "gpc_reg_operand" "f"))]
7667   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
7668   "stfd %0,lo16(%2)(%1)"
7669   [(set_attr "type" "store")
7670    (set_attr "length" "4")])
7671
7672 (define_insn "movsf_low"
7673   [(set (match_operand:SF 0 "gpc_reg_operand" "=f,!r")
7674         (mem:SF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
7675                            (match_operand 2 "" ""))))]
7676   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
7677   "@
7678    lfs %0,lo16(%2)(%1)
7679    {l|lwz} %0,lo16(%2)(%1)"
7680   [(set_attr "type" "load")
7681    (set_attr "length" "4")])
7682
7683 (define_insn "movsf_low_st"
7684   [(set (mem:SF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
7685                            (match_operand 2 "" "")))
7686         (match_operand:SF 0 "gpc_reg_operand" "f,!r"))]
7687   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
7688   "@
7689    stfs %0,lo16(%2)(%1)
7690    {st|stw} %0,lo16(%2)(%1)"
7691   [(set_attr "type" "store")
7692    (set_attr "length" "4")])
7693
7694 (define_insn "*movsi_internal1"
7695   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h")
7696         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0"))]
7697   "gpc_reg_operand (operands[0], SImode)
7698    || gpc_reg_operand (operands[1], SImode)"
7699   "@
7700    mr %0,%1
7701    {cal|la} %0,%a1
7702    {l%U1%X1|lwz%U1%X1} %0,%1
7703    {st%U0%X0|stw%U0%X0} %1,%0
7704    {lil|li} %0,%1
7705    {liu|lis} %0,%v1
7706    #
7707    {cal|la} %0,%a1
7708    mf%1 %0
7709    mt%0 %1
7710    mt%0 %1
7711    mt%0 %1
7712    {cror 0,0,0|nop}"
7713   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*")
7714    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
7715
7716 ;; Split a load of a large constant into the appropriate two-insn
7717 ;; sequence.
7718
7719 (define_split
7720   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7721         (match_operand:SI 1 "const_int_operand" ""))]
7722   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
7723    && (INTVAL (operands[1]) & 0xffff) != 0"
7724   [(set (match_dup 0)
7725         (match_dup 2))
7726    (set (match_dup 0)
7727         (ior:SI (match_dup 0)
7728                 (match_dup 3)))]
7729   "
7730 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
7731
7732   if (tem == operands[0])
7733     DONE;
7734   else
7735     FAIL;
7736 }")
7737
7738 (define_insn "*movsi_internal2"
7739   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
7740         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "0,r,r")
7741                     (const_int 0)))
7742    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
7743   "TARGET_32BIT"
7744   "@
7745    {cmpi|cmpwi} %2,%0,0
7746    mr. %0,%1
7747    #"
7748   [(set_attr "type" "cmp,compare,cmp")
7749    (set_attr "length" "4,4,8")])
7750
7751 (define_split
7752   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
7753         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
7754                     (const_int 0)))
7755    (set (match_operand:SI 0 "gpc_reg_operand" "") (match_dup 1))]
7756   "TARGET_32BIT && reload_completed"
7757   [(set (match_dup 0) (match_dup 1))
7758    (set (match_dup 2)
7759         (compare:CC (match_dup 0)
7760                     (const_int 0)))]
7761   "")
7762 \f
7763 (define_expand "movhi"
7764   [(set (match_operand:HI 0 "general_operand" "")
7765         (match_operand:HI 1 "any_operand" ""))]
7766   ""
7767   "{ rs6000_emit_move (operands[0], operands[1], HImode); DONE; }")
7768
7769 (define_insn "*movhi_internal"
7770   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7771         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7772   "gpc_reg_operand (operands[0], HImode)
7773    || gpc_reg_operand (operands[1], HImode)"
7774   "@
7775    mr %0,%1
7776    lhz%U1%X1 %0,%1
7777    sth%U0%X0 %1,%0
7778    {lil|li} %0,%w1
7779    mf%1 %0
7780    mt%0 %1
7781    mt%0 %1
7782    {cror 0,0,0|nop}"
7783   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7784
7785 (define_expand "movqi"
7786   [(set (match_operand:QI 0 "general_operand" "")
7787         (match_operand:QI 1 "any_operand" ""))]
7788   ""
7789   "{ rs6000_emit_move (operands[0], operands[1], QImode); DONE; }")
7790
7791 (define_insn "*movqi_internal"
7792   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7793         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7794   "gpc_reg_operand (operands[0], QImode)
7795    || gpc_reg_operand (operands[1], QImode)"
7796   "@
7797    mr %0,%1
7798    lbz%U1%X1 %0,%1
7799    stb%U0%X0 %1,%0
7800    {lil|li} %0,%1
7801    mf%1 %0
7802    mt%0 %1
7803    mt%0 %1
7804    {cror 0,0,0|nop}"
7805   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7806 \f
7807 ;; Here is how to move condition codes around.  When we store CC data in
7808 ;; an integer register or memory, we store just the high-order 4 bits.
7809 ;; This lets us not shift in the most common case of CR0.
7810 (define_expand "movcc"
7811   [(set (match_operand:CC 0 "nonimmediate_operand" "")
7812         (match_operand:CC 1 "nonimmediate_operand" ""))]
7813   ""
7814   "")
7815
7816 (define_insn "*movcc_internal1"
7817   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,r,r,r,r,q,cl,r,m")
7818         (match_operand:CC 1 "nonimmediate_operand" "y,r,r,x,y,r,h,r,r,m,r"))]
7819   "register_operand (operands[0], CCmode)
7820    || register_operand (operands[1], CCmode)"
7821   "@
7822    mcrf %0,%1
7823    mtcrf 128,%1
7824    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
7825    mfcr %0%Q1
7826    mfcr %0%Q1\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
7827    mr %0,%1
7828    mf%1 %0
7829    mt%0 %1
7830    mt%0 %1
7831    {l%U1%X1|lwz%U1%X1} %0,%1
7832    {st%U0%U1|stw%U0%U1} %1,%0"
7833   [(set (attr "type")
7834      (cond [(eq_attr "alternative" "0")
7835                 (const_string "cr_logical")
7836             (eq_attr "alternative" "1,2")
7837                 (const_string "mtcr")
7838             (eq_attr "alternative" "5,7")
7839                 (const_string "integer")
7840             (eq_attr "alternative" "6")
7841                 (const_string "mfjmpr")
7842             (eq_attr "alternative" "8")
7843                 (const_string "mtjmpr")
7844             (eq_attr "alternative" "9")
7845                 (const_string "load")
7846             (eq_attr "alternative" "10")
7847                 (const_string "store")
7848             (ne (symbol_ref "TARGET_MFCRF") (const_int 0))
7849                 (const_string "mfcrf")
7850            ]
7851         (const_string "mfcr")))
7852    (set_attr "length" "4,4,12,4,8,4,4,4,4,4,4")])
7853 \f
7854 ;; For floating-point, we normally deal with the floating-point registers
7855 ;; unless -msoft-float is used.  The sole exception is that parameter passing
7856 ;; can produce floating-point values in fixed-point registers.  Unless the
7857 ;; value is a simple constant or already in memory, we deal with this by
7858 ;; allocating memory and copying the value explicitly via that memory location.
7859 (define_expand "movsf"
7860   [(set (match_operand:SF 0 "nonimmediate_operand" "")
7861         (match_operand:SF 1 "any_operand" ""))]
7862   ""
7863   "{ rs6000_emit_move (operands[0], operands[1], SFmode); DONE; }")
7864
7865 (define_split
7866   [(set (match_operand:SF 0 "gpc_reg_operand" "")
7867         (match_operand:SF 1 "const_double_operand" ""))]
7868   "reload_completed
7869    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7870        || (GET_CODE (operands[0]) == SUBREG
7871            && GET_CODE (SUBREG_REG (operands[0])) == REG
7872            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7873   [(set (match_dup 2) (match_dup 3))]
7874   "
7875 {
7876   long l;
7877   REAL_VALUE_TYPE rv;
7878
7879   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7880   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
7881
7882   if (! TARGET_POWERPC64)
7883     operands[2] = operand_subword (operands[0], 0, 0, SFmode);
7884   else
7885     operands[2] = gen_lowpart (SImode, operands[0]);
7886
7887   operands[3] = gen_int_mode (l, SImode);
7888 }")
7889
7890 (define_insn "*movsf_hardfloat"
7891   [(set (match_operand:SF 0 "nonimmediate_operand" "=!r,!r,m,f,f,m,!cl,!q,!r,!r,!r")
7892         (match_operand:SF 1 "input_operand" "r,m,r,f,m,f,r,r,h,G,Fn"))]
7893   "(gpc_reg_operand (operands[0], SFmode)
7894    || gpc_reg_operand (operands[1], SFmode))
7895    && (TARGET_HARD_FLOAT && TARGET_FPRS)"
7896   "@
7897    mr %0,%1
7898    {l%U1%X1|lwz%U1%X1} %0,%1
7899    {st%U0%X0|stw%U0%X0} %1,%0
7900    fmr %0,%1
7901    lfs%U1%X1 %0,%1
7902    stfs%U0%X0 %1,%0
7903    mt%0 %1
7904    mt%0 %1
7905    mf%1 %0
7906    #
7907    #"
7908   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,mtjmpr,*,*,*")
7909    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8")])
7910
7911 (define_insn "*movsf_softfloat"
7912   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,cl,q,r,r,m,r,r,r,r,r,*h")
7913         (match_operand:SF 1 "input_operand" "r,r,r,h,m,r,I,L,R,G,Fn,0"))]
7914   "(gpc_reg_operand (operands[0], SFmode)
7915    || gpc_reg_operand (operands[1], SFmode))
7916    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
7917   "@
7918    mr %0,%1
7919    mt%0 %1
7920    mt%0 %1
7921    mf%1 %0
7922    {l%U1%X1|lwz%U1%X1} %0,%1
7923    {st%U0%X0|stw%U0%X0} %1,%0
7924    {lil|li} %0,%1
7925    {liu|lis} %0,%v1
7926    {cal|la} %0,%a1
7927    #
7928    #
7929    {cror 0,0,0|nop}"
7930   [(set_attr "type" "*,mtjmpr,*,*,load,store,*,*,*,*,*,*")
7931    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,4")])
7932
7933 \f
7934 (define_expand "movdf"
7935   [(set (match_operand:DF 0 "nonimmediate_operand" "")
7936         (match_operand:DF 1 "any_operand" ""))]
7937   ""
7938   "{ rs6000_emit_move (operands[0], operands[1], DFmode); DONE; }")
7939
7940 (define_split
7941   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7942         (match_operand:DF 1 "const_int_operand" ""))]
7943   "! TARGET_POWERPC64 && reload_completed
7944    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7945        || (GET_CODE (operands[0]) == SUBREG
7946            && GET_CODE (SUBREG_REG (operands[0])) == REG
7947            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7948   [(set (match_dup 2) (match_dup 4))
7949    (set (match_dup 3) (match_dup 1))]
7950   "
7951 {
7952   int endian = (WORDS_BIG_ENDIAN == 0);
7953   HOST_WIDE_INT value = INTVAL (operands[1]);
7954
7955   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
7956   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
7957 #if HOST_BITS_PER_WIDE_INT == 32
7958   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
7959 #else
7960   operands[4] = GEN_INT (value >> 32);
7961   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
7962 #endif
7963 }")
7964
7965 (define_split
7966   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7967         (match_operand:DF 1 "const_double_operand" ""))]
7968   "! TARGET_POWERPC64 && reload_completed
7969    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7970        || (GET_CODE (operands[0]) == SUBREG
7971            && GET_CODE (SUBREG_REG (operands[0])) == REG
7972            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7973   [(set (match_dup 2) (match_dup 4))
7974    (set (match_dup 3) (match_dup 5))]
7975   "
7976 {
7977   int endian = (WORDS_BIG_ENDIAN == 0);
7978   long l[2];
7979   REAL_VALUE_TYPE rv;
7980
7981   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7982   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
7983
7984   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
7985   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
7986   operands[4] = gen_int_mode (l[endian], SImode);
7987   operands[5] = gen_int_mode (l[1 - endian], SImode);
7988 }")
7989
7990 (define_split
7991   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7992         (match_operand:DF 1 "easy_fp_constant" ""))]
7993   "TARGET_POWERPC64 && reload_completed
7994    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7995        || (GET_CODE (operands[0]) == SUBREG
7996            && GET_CODE (SUBREG_REG (operands[0])) == REG
7997            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7998   [(set (match_dup 2) (match_dup 3))]
7999   "
8000 {
8001   int endian = (WORDS_BIG_ENDIAN == 0);
8002   long l[2];
8003   REAL_VALUE_TYPE rv;
8004 #if HOST_BITS_PER_WIDE_INT >= 64
8005   HOST_WIDE_INT val;
8006 #endif
8007
8008   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8009   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8010
8011   operands[2] = gen_lowpart (DImode, operands[0]);
8012   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
8013 #if HOST_BITS_PER_WIDE_INT >= 64
8014   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
8015          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
8016
8017   operands[3] = gen_int_mode (val, DImode);
8018 #else
8019   operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
8020 #endif
8021 }")
8022
8023 ;; Don't have reload use general registers to load a constant.  First,
8024 ;; it might not work if the output operand is the equivalent of
8025 ;; a non-offsettable memref, but also it is less efficient than loading
8026 ;; the constant into an FP register, since it will probably be used there.
8027 ;; The "??" is a kludge until we can figure out a more reasonable way
8028 ;; of handling these non-offsettable values.
8029 (define_insn "*movdf_hardfloat32"
8030   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,m,f,f,m,!r,!r,!r")
8031         (match_operand:DF 1 "input_operand" "r,m,r,f,m,f,G,H,F"))]
8032   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8033    && (gpc_reg_operand (operands[0], DFmode)
8034        || gpc_reg_operand (operands[1], DFmode))"
8035   "*
8036 {
8037   switch (which_alternative)
8038     {
8039     default:
8040       abort ();
8041     case 0:
8042       /* We normally copy the low-numbered register first.  However, if
8043          the first register operand 0 is the same as the second register
8044          of operand 1, we must copy in the opposite order.  */
8045       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8046         return \"mr %L0,%L1\;mr %0,%1\";
8047       else
8048         return \"mr %0,%1\;mr %L0,%L1\";
8049     case 1:
8050       if (offsettable_memref_p (operands[1])
8051           || (GET_CODE (operands[1]) == MEM
8052               && (GET_CODE (XEXP (operands[1], 0)) == LO_SUM
8053                   || GET_CODE (XEXP (operands[1], 0)) == PRE_INC
8054                   || GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)))
8055         {
8056           /* If the low-address word is used in the address, we must load
8057              it last.  Otherwise, load it first.  Note that we cannot have
8058              auto-increment in that case since the address register is
8059              known to be dead.  */
8060           if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8061                                  operands[1], 0))
8062             return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8063           else
8064             return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8065         }
8066       else
8067         {
8068           rtx addreg;
8069
8070           addreg = find_addr_reg (XEXP (operands[1], 0));
8071           if (refers_to_regno_p (REGNO (operands[0]),
8072                                  REGNO (operands[0]) + 1,
8073                                  operands[1], 0))
8074             {
8075               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8076               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
8077               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8078               return \"{lx|lwzx} %0,%1\";
8079             }
8080           else
8081             {
8082               output_asm_insn (\"{lx|lwzx} %0,%1\", operands);
8083               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8084               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
8085               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8086               return \"\";
8087             }
8088         }
8089     case 2:
8090       if (offsettable_memref_p (operands[0])
8091           || (GET_CODE (operands[0]) == MEM
8092               && (GET_CODE (XEXP (operands[0], 0)) == LO_SUM
8093                   || GET_CODE (XEXP (operands[0], 0)) == PRE_INC
8094                   || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)))
8095         return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8096       else
8097         {
8098           rtx addreg;
8099
8100           addreg = find_addr_reg (XEXP (operands[0], 0));
8101           output_asm_insn (\"{stx|stwx} %1,%0\", operands);
8102           output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8103           output_asm_insn (\"{stx|stwx} %L1,%0\", operands);
8104           output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8105           return \"\";
8106         }
8107     case 3:
8108       return \"fmr %0,%1\";
8109     case 4:
8110       return \"lfd%U1%X1 %0,%1\";
8111     case 5:
8112       return \"stfd%U0%X0 %1,%0\";
8113     case 6:
8114     case 7:
8115     case 8:
8116       return \"#\";
8117     }
8118 }"
8119   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,*,*")
8120    (set_attr "length" "8,16,16,4,4,4,8,12,16")])
8121
8122 (define_insn "*movdf_softfloat32"
8123   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
8124         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F"))]
8125   "! TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8126    && (gpc_reg_operand (operands[0], DFmode)
8127        || gpc_reg_operand (operands[1], DFmode))"
8128   "*
8129 {
8130   switch (which_alternative)
8131     {
8132     default:
8133       abort ();
8134     case 0:
8135       /* We normally copy the low-numbered register first.  However, if
8136          the first register operand 0 is the same as the second register of
8137          operand 1, we must copy in the opposite order.  */
8138       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8139         return \"mr %L0,%L1\;mr %0,%1\";
8140       else
8141         return \"mr %0,%1\;mr %L0,%L1\";
8142     case 1:
8143       /* If the low-address word is used in the address, we must load
8144          it last.  Otherwise, load it first.  Note that we cannot have
8145          auto-increment in that case since the address register is
8146          known to be dead.  */
8147       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8148                              operands[1], 0))
8149         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8150       else
8151         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8152     case 2:
8153       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8154     case 3:
8155     case 4:
8156     case 5:
8157       return \"#\";
8158     }
8159 }"
8160   [(set_attr "type" "*,load,store,*,*,*")
8161    (set_attr "length" "8,8,8,8,12,16")])
8162
8163 ; ld/std require word-aligned displacements -> 'Y' constraint.
8164 ; List Y->r and r->Y before r->r for reload.
8165 (define_insn "*movdf_hardfloat64"
8166   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,??r,!r,f,f,m,!cl,!r,!r,!r,!r")
8167         (match_operand:DF 1 "input_operand" "r,Y,r,f,m,f,r,h,G,H,F"))]
8168   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8169    && (gpc_reg_operand (operands[0], DFmode)
8170        || gpc_reg_operand (operands[1], DFmode))"
8171   "@
8172    std%U0%X0 %1,%0
8173    ld%U1%X1 %0,%1
8174    mr %0,%1
8175    fmr %0,%1
8176    lfd%U1%X1 %0,%1
8177    stfd%U0%X0 %1,%0
8178    mt%0 %1
8179    mf%1 %0
8180    #
8181    #
8182    #"
8183   [(set_attr "type" "*,load,store,fp,fpload,fpstore,mtjmpr,*,*,*,*")
8184    (set_attr "length" "4,4,4,4,4,4,4,4,8,12,16")])
8185
8186 (define_insn "*movdf_softfloat64"
8187   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,Y,r,cl,r,r,r,r,*h")
8188         (match_operand:DF 1 "input_operand" "Y,r,r,r,h,G,H,F,0"))]
8189   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8190    && (gpc_reg_operand (operands[0], DFmode)
8191        || gpc_reg_operand (operands[1], DFmode))"
8192   "@
8193    ld%U1%X1 %0,%1
8194    std%U0%X0 %1,%0
8195    mr %0,%1
8196    mt%0 %1
8197    mf%1 %0
8198    #
8199    #
8200    #
8201    nop"
8202   [(set_attr "type" "load,store,*,*,*,*,*,*,*")
8203    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
8204 \f
8205 (define_expand "movtf"
8206   [(set (match_operand:TF 0 "general_operand" "")
8207         (match_operand:TF 1 "any_operand" ""))]
8208   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8209    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8210   "{ rs6000_emit_move (operands[0], operands[1], TFmode); DONE; }")
8211
8212 ; It's important to list the o->f and f->o moves before f->f because
8213 ; otherwise reload, given m->f, will try to pick f->f and reload it,
8214 ; which doesn't make progress.
8215 (define_insn_and_split "*movtf_internal"
8216   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,f,rm,r")
8217         (match_operand:TF 1 "input_operand"         "f,o,f,r,mGHF"))]
8218   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8219    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
8220    && (gpc_reg_operand (operands[0], TFmode)
8221        || gpc_reg_operand (operands[1], TFmode))"
8222   "#"
8223   "&& reload_completed"
8224   [(pc)]
8225 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
8226   [(set_attr "length" "8,8,8,20,20")])
8227
8228 (define_expand "extenddftf2"
8229   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
8230                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
8231               (use (match_dup 2))])]
8232   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8233    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8234 {
8235   operands[2] = CONST0_RTX (DFmode);
8236 })
8237
8238 (define_insn_and_split "*extenddftf2_internal"
8239   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,&f,r")
8240        (float_extend:TF (match_operand:DF 1 "input_operand" "fr,mf,mf,rmGHF")))
8241    (use (match_operand:DF 2 "input_operand" "rf,m,f,n"))]
8242   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8243    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8244   "#"
8245   "&& reload_completed"
8246   [(pc)]
8247 {
8248   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8249   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8250   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
8251                   operands[1]);
8252   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
8253                   operands[2]);
8254   DONE;
8255 })  
8256
8257 (define_expand "extendsftf2"
8258   [(set (match_operand:TF 0 "nonimmediate_operand" "")
8259         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
8260   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8261    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8262 {
8263   rtx tmp = gen_reg_rtx (DFmode);
8264   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
8265   emit_insn (gen_extenddftf2 (operands[0], tmp));
8266   DONE;
8267 })
8268
8269 (define_insn "trunctfdf2"
8270   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8271         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8272   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8273    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8274   "fadd %0,%1,%L1"
8275   [(set_attr "type" "fp")
8276    (set_attr "length" "4")])
8277
8278 (define_insn_and_split "trunctfsf2"
8279   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
8280         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "f")))
8281    (clobber (match_scratch:DF 2 "=f"))]
8282   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8283    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8284   "#"
8285   "&& reload_completed"
8286   [(set (match_dup 2)
8287         (float_truncate:DF (match_dup 1)))
8288    (set (match_dup 0)
8289         (float_truncate:SF (match_dup 2)))]
8290   "")
8291
8292 (define_expand "floatsitf2"
8293   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8294         (float:TF (match_operand:SI 1 "gpc_reg_operand" "r")))]
8295   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8296    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8297 {
8298   rtx tmp = gen_reg_rtx (DFmode);
8299   expand_float (tmp, operands[1], false);
8300   emit_insn (gen_extenddftf2 (operands[0], tmp));
8301   DONE;
8302 })
8303
8304 ; fadd, but rounding towards zero.
8305 ; This is probably not the optimal code sequence.
8306 (define_insn "fix_trunc_helper"
8307   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8308         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "f")]
8309                    UNSPEC_FIX_TRUNC_TF))
8310    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&f"))]
8311   "TARGET_HARD_FLOAT && TARGET_FPRS"
8312   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
8313   [(set_attr "type" "fp")
8314    (set_attr "length" "20")])
8315
8316 (define_expand "fix_trunctfsi2"
8317   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
8318                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
8319               (clobber (match_dup 2))
8320               (clobber (match_dup 3))
8321               (clobber (match_dup 4))
8322               (clobber (match_dup 5))])]
8323   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8324    && (TARGET_POWER2 || TARGET_POWERPC)
8325    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8326 {
8327   operands[2] = gen_reg_rtx (DFmode);
8328   operands[3] = gen_reg_rtx (DFmode);
8329   operands[4] = gen_reg_rtx (DImode);
8330   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
8331 })
8332
8333 (define_insn_and_split "*fix_trunctfsi2_internal"
8334   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8335         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "f")))
8336    (clobber (match_operand:DF 2 "gpc_reg_operand" "=f"))
8337    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&f"))
8338    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))
8339    (clobber (match_operand:DI 5 "memory_operand" "=o"))]
8340   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8341    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8342   "#"
8343   "&& reload_completed"
8344   [(pc)]
8345 {
8346   rtx lowword;
8347   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
8348
8349   if (GET_CODE (operands[5]) != MEM)
8350     abort();
8351   lowword = XEXP (operands[5], 0);
8352   if (WORDS_BIG_ENDIAN)
8353     lowword = plus_constant (lowword, 4);
8354
8355   emit_insn (gen_fctiwz (operands[4], operands[2]));
8356   emit_move_insn (operands[5], operands[4]);
8357   emit_move_insn (operands[0], gen_rtx_MEM (SImode, lowword));
8358   DONE;
8359 })
8360
8361 (define_insn "negtf2"
8362   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8363         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8364   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8365    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8366   "*
8367 {
8368   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8369     return \"fneg %L0,%L1\;fneg %0,%1\";
8370   else
8371     return \"fneg %0,%1\;fneg %L0,%L1\";
8372 }"
8373   [(set_attr "type" "fp")
8374    (set_attr "length" "8")])
8375
8376 (define_insn "abstf2"
8377   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8378         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8379   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8380    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8381   "*
8382 {
8383   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8384     return \"fabs %L0,%L1\;fabs %0,%1\";
8385   else
8386     return \"fabs %0,%1\;fabs %L0,%L1\";
8387 }"
8388   [(set_attr "type" "fp")
8389    (set_attr "length" "8")])
8390
8391 (define_insn ""
8392   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8393         (neg:TF (abs:TF (match_operand:TF 1 "gpc_reg_operand" "f"))))]
8394   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8395    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8396   "*
8397 {
8398   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8399     return \"fnabs %L0,%L1\;fnabs %0,%1\";
8400   else
8401     return \"fnabs %0,%1\;fnabs %L0,%L1\";
8402 }"
8403   [(set_attr "type" "fp")
8404    (set_attr "length" "8")])
8405 \f
8406 ;; Next come the multi-word integer load and store and the load and store
8407 ;; multiple insns.
8408 (define_expand "movdi"
8409   [(set (match_operand:DI 0 "general_operand" "")
8410         (match_operand:DI 1 "any_operand" ""))]
8411   ""
8412   "{ rs6000_emit_move (operands[0], operands[1], DImode); DONE; }")
8413
8414 (define_insn "*movdi_internal32"
8415   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,f,f,m,r,r,r,r,r")
8416         (match_operand:DI 1 "input_operand" "r,m,r,f,m,f,IJK,n,G,H,F"))]
8417   "! TARGET_POWERPC64
8418    && (gpc_reg_operand (operands[0], DImode)
8419        || gpc_reg_operand (operands[1], DImode))"
8420   "*
8421 {
8422   switch (which_alternative)
8423     {
8424     default:
8425       abort ();
8426     case 0:
8427     case 1:
8428     case 2:
8429       return \"#\";
8430     case 3:
8431       return \"fmr %0,%1\";
8432     case 4:
8433       return \"lfd%U1%X1 %0,%1\";
8434     case 5:
8435       return \"stfd%U0%X0 %1,%0\";
8436     case 6:
8437     case 7:
8438     case 8:
8439     case 9:
8440     case 10:
8441       return \"#\";
8442     }
8443 }"
8444   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,*,*,*,*")])
8445
8446 (define_split
8447   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8448         (match_operand:DI 1 "const_int_operand" ""))]
8449   "! TARGET_POWERPC64 && reload_completed"
8450   [(set (match_dup 2) (match_dup 4))
8451    (set (match_dup 3) (match_dup 1))]
8452   "
8453 {
8454   HOST_WIDE_INT value = INTVAL (operands[1]);
8455   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8456                                        DImode);
8457   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8458                                        DImode);
8459 #if HOST_BITS_PER_WIDE_INT == 32
8460   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8461 #else
8462   operands[4] = GEN_INT (value >> 32);
8463   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8464 #endif
8465 }")
8466
8467 (define_split
8468   [(set (match_operand:DI 0 "nonimmediate_operand" "")
8469         (match_operand:DI 1 "input_operand" ""))]
8470   "reload_completed && !TARGET_POWERPC64 
8471    && gpr_or_gpr_p (operands[0], operands[1])"
8472   [(pc)]
8473 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8474
8475 (define_split
8476   [(set (match_operand:TI 0 "gpc_reg_operand" "")
8477         (match_operand:TI 1 "const_double_operand" ""))]
8478   "TARGET_POWERPC64"
8479   [(set (match_dup 2) (match_dup 4))
8480    (set (match_dup 3) (match_dup 5))]
8481   "
8482 {
8483   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8484                                        TImode);
8485   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8486                                        TImode);
8487   if (GET_CODE (operands[1]) == CONST_DOUBLE)
8488     {
8489       operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
8490       operands[5] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
8491     }
8492   else if (GET_CODE (operands[1]) == CONST_INT)
8493     {
8494       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
8495       operands[5] = operands[1];
8496     }
8497   else
8498     FAIL;
8499 }")
8500
8501 (define_insn "*movdi_internal64"
8502   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,?f,f,m,r,*h,*h")
8503         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,f,m,f,*h,r,0"))]
8504   "TARGET_POWERPC64
8505    && (gpc_reg_operand (operands[0], DImode)
8506        || gpc_reg_operand (operands[1], DImode))"
8507   "@
8508    mr %0,%1
8509    ld%U1%X1 %0,%1
8510    std%U0%X0 %1,%0
8511    li %0,%1
8512    lis %0,%v1
8513    #
8514    {cal|la} %0,%a1
8515    fmr %0,%1
8516    lfd%U1%X1 %0,%1
8517    stfd%U0%X0 %1,%0
8518    mf%1 %0
8519    mt%0 %1
8520    {cror 0,0,0|nop}"
8521   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*")
8522    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4")])
8523
8524 ;; immediate value valid for a single instruction hiding in a const_double
8525 (define_insn ""
8526   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8527         (match_operand:DI 1 "const_double_operand" "F"))]
8528   "HOST_BITS_PER_WIDE_INT == 32 && TARGET_POWERPC64
8529    && GET_CODE (operands[1]) == CONST_DOUBLE
8530    && num_insns_constant (operands[1], DImode) == 1"
8531   "*
8532 {
8533   return ((unsigned HOST_WIDE_INT)
8534           (CONST_DOUBLE_LOW (operands[1]) + 0x8000) < 0x10000)
8535          ? \"li %0,%1\" : \"lis %0,%v1\";
8536 }")
8537
8538 ;; Generate all one-bits and clear left or right.
8539 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
8540 (define_split
8541   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8542         (match_operand:DI 1 "mask64_operand" ""))]
8543   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8544   [(set (match_dup 0) (const_int -1))
8545    (set (match_dup 0)
8546         (and:DI (rotate:DI (match_dup 0)
8547                            (const_int 0))
8548                 (match_dup 1)))]
8549   "")
8550
8551 ;; Split a load of a large constant into the appropriate five-instruction
8552 ;; sequence.  Handle anything in a constant number of insns.
8553 ;; When non-easy constants can go in the TOC, this should use
8554 ;; easy_fp_constant predicate.
8555 (define_split
8556   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8557         (match_operand:DI 1 "const_int_operand" ""))]
8558   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8559   [(set (match_dup 0) (match_dup 2))
8560    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8561   "
8562 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8563
8564   if (tem == operands[0])
8565     DONE;
8566   else
8567     FAIL;
8568 }")
8569
8570 (define_split
8571   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8572         (match_operand:DI 1 "const_double_operand" ""))]
8573   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8574   [(set (match_dup 0) (match_dup 2))
8575    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8576   "
8577 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8578
8579   if (tem == operands[0])
8580     DONE;
8581   else
8582     FAIL;
8583 }")
8584
8585 (define_insn "*movdi_internal2"
8586   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
8587         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "0,r,r")
8588                     (const_int 0)))
8589    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
8590   "TARGET_64BIT"
8591   "@
8592    cmpdi %2,%0,0
8593    mr. %0,%1
8594    #"
8595   [(set_attr "type" "cmp,compare,cmp")
8596    (set_attr "length" "4,4,8")])
8597
8598 (define_split
8599   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
8600         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "")
8601                     (const_int 0)))
8602    (set (match_operand:DI 0 "gpc_reg_operand" "") (match_dup 1))]
8603   "TARGET_POWERPC64 && reload_completed"
8604   [(set (match_dup 0) (match_dup 1))
8605    (set (match_dup 2)
8606         (compare:CC (match_dup 0)
8607                     (const_int 0)))]
8608   "")
8609 \f
8610 ;; TImode is similar, except that we usually want to compute the address into
8611 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
8612 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
8613 (define_expand "movti"
8614   [(parallel [(set (match_operand:TI 0 "general_operand" "")
8615                    (match_operand:TI 1 "general_operand" ""))
8616               (clobber (scratch:SI))])]
8617   ""
8618   "{ rs6000_emit_move (operands[0], operands[1], TImode); DONE; }")
8619
8620 ;; We say that MQ is clobbered in the last alternative because the first
8621 ;; alternative would never get used otherwise since it would need a reload
8622 ;; while the 2nd alternative would not.  We put memory cases first so they
8623 ;; are preferred.  Otherwise, we'd try to reload the output instead of
8624 ;; giving the SCRATCH mq.
8625
8626 (define_insn "*movti_power"
8627   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r")
8628         (match_operand:TI 1 "reg_or_mem_operand" "r,r,r,Q,m"))
8629    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X"))]
8630   "TARGET_POWER && ! TARGET_POWERPC64 
8631    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8632   "*
8633 {
8634   switch (which_alternative)
8635     {
8636     default:
8637       abort ();
8638
8639     case 0:
8640       if (TARGET_STRING)
8641         return \"{stsi|stswi} %1,%P0,16\";
8642     case 1:
8643     case 2:
8644       return \"#\";
8645     case 3:
8646       /* If the address is not used in the output, we can use lsi.  Otherwise,
8647          fall through to generating four loads.  */
8648       if (TARGET_STRING
8649           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8650         return \"{lsi|lswi} %0,%P1,16\";
8651       /* ... fall through ...  */
8652     case 4:
8653       return \"#\";
8654     }
8655 }"
8656   [(set_attr "type" "store,store,*,load,load")])
8657
8658 (define_insn "*movti_string"
8659   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r")
8660         (match_operand:TI 1 "reg_or_mem_operand" "r,r,r,Q,m"))]
8661   "! TARGET_POWER && ! TARGET_POWERPC64
8662    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8663   "*
8664 {
8665   switch (which_alternative)
8666     {
8667     default:
8668       abort ();
8669     case 0:
8670       if (TARGET_STRING)
8671         return \"{stsi|stswi} %1,%P0,16\";
8672     case 1:
8673     case 2:
8674       return \"#\";
8675     case 3:
8676       /* If the address is not used in the output, we can use lsi.  Otherwise,
8677          fall through to generating four loads.  */
8678       if (TARGET_STRING  
8679           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8680         return \"{lsi|lswi} %0,%P1,16\";
8681       /* ... fall through ...  */
8682     case 4:
8683       return \"#\";
8684     }
8685 }"
8686   [(set_attr "type" "store,store,*,load,load")])
8687
8688 (define_insn "*movti_ppc64"
8689   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,m,r")
8690         (match_operand:TI 1 "input_operand" "r,r,o"))]
8691   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
8692    || gpc_reg_operand (operands[1], TImode))"
8693   "@
8694    #    
8695    #    
8696    #"
8697   [(set_attr "type" "*,load,store")])
8698
8699 (define_split
8700   [(set (match_operand:TI 0 "nonimmediate_operand" "")
8701         (match_operand:TI 1 "input_operand" ""))]
8702   "reload_completed
8703    && gpr_or_gpr_p (operands[0], operands[1])"
8704   [(pc)]
8705 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8706 \f
8707 (define_expand "load_multiple"
8708   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8709                           (match_operand:SI 1 "" ""))
8710                      (use (match_operand:SI 2 "" ""))])]
8711   "TARGET_STRING && !TARGET_POWERPC64"
8712   "
8713 {
8714   int regno;
8715   int count;
8716   rtx op1;
8717   int i;
8718
8719   /* Support only loading a constant number of fixed-point registers from
8720      memory and only bother with this if more than two; the machine
8721      doesn't support more than eight.  */
8722   if (GET_CODE (operands[2]) != CONST_INT
8723       || INTVAL (operands[2]) <= 2
8724       || INTVAL (operands[2]) > 8
8725       || GET_CODE (operands[1]) != MEM
8726       || GET_CODE (operands[0]) != REG
8727       || REGNO (operands[0]) >= 32)
8728     FAIL;
8729
8730   count = INTVAL (operands[2]);
8731   regno = REGNO (operands[0]);
8732
8733   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
8734   op1 = replace_equiv_address (operands[1],
8735                                force_reg (SImode, XEXP (operands[1], 0)));
8736
8737   for (i = 0; i < count; i++)
8738     XVECEXP (operands[3], 0, i)
8739       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
8740                      adjust_address_nv (op1, SImode, i * 4));
8741 }")
8742
8743 (define_insn "*ldmsi8"
8744   [(match_parallel 0 "load_multiple_operation"
8745     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8746           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8747      (set (match_operand:SI 3 "gpc_reg_operand" "")
8748           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8749      (set (match_operand:SI 4 "gpc_reg_operand" "")
8750           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8751      (set (match_operand:SI 5 "gpc_reg_operand" "")
8752           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8753      (set (match_operand:SI 6 "gpc_reg_operand" "")
8754           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8755      (set (match_operand:SI 7 "gpc_reg_operand" "")
8756           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8757      (set (match_operand:SI 8 "gpc_reg_operand" "")
8758           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
8759      (set (match_operand:SI 9 "gpc_reg_operand" "")
8760           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
8761   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
8762   "*
8763 { return rs6000_output_load_multiple (operands); }"
8764   [(set_attr "type" "load")
8765    (set_attr "length" "32")])
8766
8767 (define_insn "*ldmsi7"
8768   [(match_parallel 0 "load_multiple_operation"
8769     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8770           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8771      (set (match_operand:SI 3 "gpc_reg_operand" "")
8772           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8773      (set (match_operand:SI 4 "gpc_reg_operand" "")
8774           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8775      (set (match_operand:SI 5 "gpc_reg_operand" "")
8776           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8777      (set (match_operand:SI 6 "gpc_reg_operand" "")
8778           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8779      (set (match_operand:SI 7 "gpc_reg_operand" "")
8780           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8781      (set (match_operand:SI 8 "gpc_reg_operand" "")
8782           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
8783   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
8784   "*
8785 { return rs6000_output_load_multiple (operands); }"
8786   [(set_attr "type" "load")
8787    (set_attr "length" "32")])
8788
8789 (define_insn "*ldmsi6"
8790   [(match_parallel 0 "load_multiple_operation"
8791     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8792           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8793      (set (match_operand:SI 3 "gpc_reg_operand" "")
8794           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8795      (set (match_operand:SI 4 "gpc_reg_operand" "")
8796           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8797      (set (match_operand:SI 5 "gpc_reg_operand" "")
8798           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8799      (set (match_operand:SI 6 "gpc_reg_operand" "")
8800           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8801      (set (match_operand:SI 7 "gpc_reg_operand" "")
8802           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
8803   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
8804   "*
8805 { return rs6000_output_load_multiple (operands); }"
8806   [(set_attr "type" "load")
8807    (set_attr "length" "32")])
8808
8809 (define_insn "*ldmsi5"
8810   [(match_parallel 0 "load_multiple_operation"
8811     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8812           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8813      (set (match_operand:SI 3 "gpc_reg_operand" "")
8814           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8815      (set (match_operand:SI 4 "gpc_reg_operand" "")
8816           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8817      (set (match_operand:SI 5 "gpc_reg_operand" "")
8818           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8819      (set (match_operand:SI 6 "gpc_reg_operand" "")
8820           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
8821   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
8822   "*
8823 { return rs6000_output_load_multiple (operands); }"
8824   [(set_attr "type" "load")
8825    (set_attr "length" "32")])
8826
8827 (define_insn "*ldmsi4"
8828   [(match_parallel 0 "load_multiple_operation"
8829     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8830           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8831      (set (match_operand:SI 3 "gpc_reg_operand" "")
8832           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8833      (set (match_operand:SI 4 "gpc_reg_operand" "")
8834           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8835      (set (match_operand:SI 5 "gpc_reg_operand" "")
8836           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
8837   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
8838   "*
8839 { return rs6000_output_load_multiple (operands); }"
8840   [(set_attr "type" "load")
8841    (set_attr "length" "32")])
8842
8843 (define_insn "*ldmsi3"
8844   [(match_parallel 0 "load_multiple_operation"
8845     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8846           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8847      (set (match_operand:SI 3 "gpc_reg_operand" "")
8848           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8849      (set (match_operand:SI 4 "gpc_reg_operand" "")
8850           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
8851   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
8852   "*
8853 { return rs6000_output_load_multiple (operands); }"
8854   [(set_attr "type" "load")
8855    (set_attr "length" "32")])
8856
8857 (define_expand "store_multiple"
8858   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8859                           (match_operand:SI 1 "" ""))
8860                      (clobber (scratch:SI))
8861                      (use (match_operand:SI 2 "" ""))])]
8862   "TARGET_STRING && !TARGET_POWERPC64"
8863   "
8864 {
8865   int regno;
8866   int count;
8867   rtx to;
8868   rtx op0;
8869   int i;
8870
8871   /* Support only storing a constant number of fixed-point registers to
8872      memory and only bother with this if more than two; the machine
8873      doesn't support more than eight.  */
8874   if (GET_CODE (operands[2]) != CONST_INT
8875       || INTVAL (operands[2]) <= 2
8876       || INTVAL (operands[2]) > 8
8877       || GET_CODE (operands[0]) != MEM
8878       || GET_CODE (operands[1]) != REG
8879       || REGNO (operands[1]) >= 32)
8880     FAIL;
8881
8882   count = INTVAL (operands[2]);
8883   regno = REGNO (operands[1]);
8884
8885   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
8886   to = force_reg (SImode, XEXP (operands[0], 0));
8887   op0 = replace_equiv_address (operands[0], to);
8888
8889   XVECEXP (operands[3], 0, 0)
8890     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
8891   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
8892                                                  gen_rtx_SCRATCH (SImode));
8893
8894   for (i = 1; i < count; i++)
8895     XVECEXP (operands[3], 0, i + 1)
8896       = gen_rtx_SET (VOIDmode,
8897                      adjust_address_nv (op0, SImode, i * 4),
8898                      gen_rtx_REG (SImode, regno + i));
8899 }")
8900
8901 (define_insn "*store_multiple_power"
8902   [(match_parallel 0 "store_multiple_operation"
8903                    [(set (match_operand:SI 1 "indirect_operand" "=Q")
8904                          (match_operand:SI 2 "gpc_reg_operand" "r"))
8905                     (clobber (match_scratch:SI 3 "=q"))])]
8906   "TARGET_STRING && TARGET_POWER"
8907   "{stsi|stswi} %2,%P1,%O0"
8908   [(set_attr "type" "store")])
8909
8910 (define_insn "*stmsi8"
8911   [(match_parallel 0 "store_multiple_operation"
8912     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8913           (match_operand:SI 2 "gpc_reg_operand" "r"))
8914      (clobber (match_scratch:SI 3 "X"))
8915      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8916           (match_operand:SI 4 "gpc_reg_operand" "r"))
8917      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8918           (match_operand:SI 5 "gpc_reg_operand" "r"))
8919      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8920           (match_operand:SI 6 "gpc_reg_operand" "r"))
8921      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8922           (match_operand:SI 7 "gpc_reg_operand" "r"))
8923      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8924           (match_operand:SI 8 "gpc_reg_operand" "r"))
8925      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
8926           (match_operand:SI 9 "gpc_reg_operand" "r"))
8927      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
8928           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
8929   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 9"
8930   "{stsi|stswi} %2,%1,%O0"
8931   [(set_attr "type" "store")])
8932
8933 (define_insn "*stmsi7"
8934   [(match_parallel 0 "store_multiple_operation"
8935     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8936           (match_operand:SI 2 "gpc_reg_operand" "r"))
8937      (clobber (match_scratch:SI 3 "X"))
8938      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8939           (match_operand:SI 4 "gpc_reg_operand" "r"))
8940      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8941           (match_operand:SI 5 "gpc_reg_operand" "r"))
8942      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8943           (match_operand:SI 6 "gpc_reg_operand" "r"))
8944      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8945           (match_operand:SI 7 "gpc_reg_operand" "r"))
8946      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8947           (match_operand:SI 8 "gpc_reg_operand" "r"))
8948      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
8949           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
8950   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 8"
8951   "{stsi|stswi} %2,%1,%O0"
8952   [(set_attr "type" "store")])
8953
8954 (define_insn "*stmsi6"
8955   [(match_parallel 0 "store_multiple_operation"
8956     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8957           (match_operand:SI 2 "gpc_reg_operand" "r"))
8958      (clobber (match_scratch:SI 3 "X"))
8959      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8960           (match_operand:SI 4 "gpc_reg_operand" "r"))
8961      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8962           (match_operand:SI 5 "gpc_reg_operand" "r"))
8963      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8964           (match_operand:SI 6 "gpc_reg_operand" "r"))
8965      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8966           (match_operand:SI 7 "gpc_reg_operand" "r"))
8967      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8968           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
8969   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 7"
8970   "{stsi|stswi} %2,%1,%O0"
8971   [(set_attr "type" "store")])
8972
8973 (define_insn "*stmsi5"
8974   [(match_parallel 0 "store_multiple_operation"
8975     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8976           (match_operand:SI 2 "gpc_reg_operand" "r"))
8977      (clobber (match_scratch:SI 3 "X"))
8978      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8979           (match_operand:SI 4 "gpc_reg_operand" "r"))
8980      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8981           (match_operand:SI 5 "gpc_reg_operand" "r"))
8982      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8983           (match_operand:SI 6 "gpc_reg_operand" "r"))
8984      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8985           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
8986   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 6"
8987   "{stsi|stswi} %2,%1,%O0"
8988   [(set_attr "type" "store")])
8989
8990 (define_insn "*stmsi4"
8991   [(match_parallel 0 "store_multiple_operation"
8992     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8993           (match_operand:SI 2 "gpc_reg_operand" "r"))
8994      (clobber (match_scratch:SI 3 "X"))
8995      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8996           (match_operand:SI 4 "gpc_reg_operand" "r"))
8997      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8998           (match_operand:SI 5 "gpc_reg_operand" "r"))
8999      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9000           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
9001   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 5"
9002   "{stsi|stswi} %2,%1,%O0"
9003   [(set_attr "type" "store")])
9004
9005 (define_insn "*stmsi3"
9006   [(match_parallel 0 "store_multiple_operation"
9007     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9008           (match_operand:SI 2 "gpc_reg_operand" "r"))
9009      (clobber (match_scratch:SI 3 "X"))
9010      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9011           (match_operand:SI 4 "gpc_reg_operand" "r"))
9012      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9013           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
9014   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 4"
9015   "{stsi|stswi} %2,%1,%O0"
9016   [(set_attr "type" "store")])
9017 \f
9018 ;; String/block move insn.
9019 ;; Argument 0 is the destination
9020 ;; Argument 1 is the source
9021 ;; Argument 2 is the length
9022 ;; Argument 3 is the alignment
9023
9024 (define_expand "movstrsi"
9025   [(parallel [(set (match_operand:BLK 0 "" "")
9026                    (match_operand:BLK 1 "" ""))
9027               (use (match_operand:SI 2 "" ""))
9028               (use (match_operand:SI 3 "" ""))])]
9029   ""
9030   "
9031 {
9032   if (expand_block_move (operands))
9033     DONE;
9034   else
9035     FAIL;
9036 }")
9037
9038 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
9039 ;; register allocator doesn't have a clue about allocating 8 word registers.
9040 ;; rD/rS = r5 is preferred, efficient form.
9041 (define_expand "movstrsi_8reg"
9042   [(parallel [(set (match_operand 0 "" "")
9043                    (match_operand 1 "" ""))
9044               (use (match_operand 2 "" ""))
9045               (use (match_operand 3 "" ""))
9046               (clobber (reg:SI  5))
9047               (clobber (reg:SI  6))
9048               (clobber (reg:SI  7))
9049               (clobber (reg:SI  8))
9050               (clobber (reg:SI  9))
9051               (clobber (reg:SI 10))
9052               (clobber (reg:SI 11))
9053               (clobber (reg:SI 12))
9054               (clobber (match_scratch:SI 4 ""))])]
9055   "TARGET_STRING"
9056   "")
9057
9058 (define_insn ""
9059   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9060         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9061    (use (match_operand:SI 2 "immediate_operand" "i"))
9062    (use (match_operand:SI 3 "immediate_operand" "i"))
9063    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9064    (clobber (reg:SI  6))
9065    (clobber (reg:SI  7))
9066    (clobber (reg:SI  8))
9067    (clobber (reg:SI  9))
9068    (clobber (reg:SI 10))
9069    (clobber (reg:SI 11))
9070    (clobber (reg:SI 12))
9071    (clobber (match_scratch:SI 5 "=q"))]
9072   "TARGET_STRING && TARGET_POWER
9073    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9074        || INTVAL (operands[2]) == 0)
9075    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9076    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9077    && REGNO (operands[4]) == 5"
9078   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9079   [(set_attr "type" "load")
9080    (set_attr "length" "8")])
9081
9082 (define_insn ""
9083   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9084         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9085    (use (match_operand:SI 2 "immediate_operand" "i"))
9086    (use (match_operand:SI 3 "immediate_operand" "i"))
9087    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9088    (clobber (reg:SI  6))
9089    (clobber (reg:SI  7))
9090    (clobber (reg:SI  8))
9091    (clobber (reg:SI  9))
9092    (clobber (reg:SI 10))
9093    (clobber (reg:SI 11))
9094    (clobber (reg:SI 12))
9095    (clobber (match_scratch:SI 5 "X"))]
9096   "TARGET_STRING && ! TARGET_POWER
9097    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9098        || INTVAL (operands[2]) == 0)
9099    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9100    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9101    && REGNO (operands[4]) == 5"
9102   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9103   [(set_attr "type" "load")
9104    (set_attr "length" "8")])
9105
9106 (define_insn ""
9107   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9108         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9109    (use (match_operand:SI 2 "immediate_operand" "i"))
9110    (use (match_operand:SI 3 "immediate_operand" "i"))
9111    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9112    (clobber (reg:SI  6))
9113    (clobber (reg:SI  7))
9114    (clobber (reg:SI  8))
9115    (clobber (reg:SI  9))
9116    (clobber (reg:SI 10))
9117    (clobber (reg:SI 11))
9118    (clobber (reg:SI 12))
9119    (clobber (match_scratch:SI 5 "X"))]
9120   "TARGET_STRING && TARGET_POWERPC64
9121    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9122        || INTVAL (operands[2]) == 0)
9123    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9124    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9125    && REGNO (operands[4]) == 5"
9126   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9127   [(set_attr "type" "load")
9128    (set_attr "length" "8")])
9129
9130 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
9131 ;; register allocator doesn't have a clue about allocating 6 word registers.
9132 ;; rD/rS = r5 is preferred, efficient form.
9133 (define_expand "movstrsi_6reg"
9134   [(parallel [(set (match_operand 0 "" "")
9135                    (match_operand 1 "" ""))
9136               (use (match_operand 2 "" ""))
9137               (use (match_operand 3 "" ""))
9138               (clobber (reg:SI  5))
9139               (clobber (reg:SI  6))
9140               (clobber (reg:SI  7))
9141               (clobber (reg:SI  8))
9142               (clobber (reg:SI  9))
9143               (clobber (reg:SI 10))
9144               (clobber (match_scratch:SI 4 ""))])]
9145   "TARGET_STRING"
9146   "")
9147
9148 (define_insn ""
9149   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9150         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9151    (use (match_operand:SI 2 "immediate_operand" "i"))
9152    (use (match_operand:SI 3 "immediate_operand" "i"))
9153    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9154    (clobber (reg:SI  6))
9155    (clobber (reg:SI  7))
9156    (clobber (reg:SI  8))
9157    (clobber (reg:SI  9))
9158    (clobber (reg:SI 10))
9159    (clobber (match_scratch:SI 5 "=q"))]
9160   "TARGET_STRING && TARGET_POWER
9161    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
9162    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9163    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9164    && REGNO (operands[4]) == 5"
9165   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9166   [(set_attr "type" "load")
9167    (set_attr "length" "8")])
9168
9169 (define_insn ""
9170   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9171         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9172    (use (match_operand:SI 2 "immediate_operand" "i"))
9173    (use (match_operand:SI 3 "immediate_operand" "i"))
9174    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9175    (clobber (reg:SI  6))
9176    (clobber (reg:SI  7))
9177    (clobber (reg:SI  8))
9178    (clobber (reg:SI  9))
9179    (clobber (reg:SI 10))
9180    (clobber (match_scratch:SI 5 "X"))]
9181   "TARGET_STRING && ! TARGET_POWER
9182    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9183    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9184    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9185    && REGNO (operands[4]) == 5"
9186   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9187   [(set_attr "type" "load")
9188    (set_attr "length" "8")])
9189
9190 (define_insn ""
9191   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9192         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9193    (use (match_operand:SI 2 "immediate_operand" "i"))
9194    (use (match_operand:SI 3 "immediate_operand" "i"))
9195    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9196    (clobber (reg:SI  6))
9197    (clobber (reg:SI  7))
9198    (clobber (reg:SI  8))
9199    (clobber (reg:SI  9))
9200    (clobber (reg:SI 10))
9201    (clobber (match_scratch:SI 5 "X"))]
9202   "TARGET_STRING && TARGET_POWERPC64
9203    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9204    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9205    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9206    && REGNO (operands[4]) == 5"
9207   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9208   [(set_attr "type" "load")
9209    (set_attr "length" "8")])
9210
9211 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
9212 ;; problems with TImode.
9213 ;; rD/rS = r5 is preferred, efficient form.
9214 (define_expand "movstrsi_4reg"
9215   [(parallel [(set (match_operand 0 "" "")
9216                    (match_operand 1 "" ""))
9217               (use (match_operand 2 "" ""))
9218               (use (match_operand 3 "" ""))
9219               (clobber (reg:SI 5))
9220               (clobber (reg:SI 6))
9221               (clobber (reg:SI 7))
9222               (clobber (reg:SI 8))
9223               (clobber (match_scratch:SI 4 ""))])]
9224   "TARGET_STRING"
9225   "")
9226
9227 (define_insn ""
9228   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9229         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9230    (use (match_operand:SI 2 "immediate_operand" "i"))
9231    (use (match_operand:SI 3 "immediate_operand" "i"))
9232    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9233    (clobber (reg:SI 6))
9234    (clobber (reg:SI 7))
9235    (clobber (reg:SI 8))
9236    (clobber (match_scratch:SI 5 "=q"))]
9237   "TARGET_STRING && TARGET_POWER
9238    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9239    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9240    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9241    && REGNO (operands[4]) == 5"
9242   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9243   [(set_attr "type" "load")
9244    (set_attr "length" "8")])
9245
9246 (define_insn ""
9247   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9248         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9249    (use (match_operand:SI 2 "immediate_operand" "i"))
9250    (use (match_operand:SI 3 "immediate_operand" "i"))
9251    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9252    (clobber (reg:SI 6))
9253    (clobber (reg:SI 7))
9254    (clobber (reg:SI 8))
9255    (clobber (match_scratch:SI 5 "X"))]
9256   "TARGET_STRING && ! TARGET_POWER
9257    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9258    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9259    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9260    && REGNO (operands[4]) == 5"
9261   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9262   [(set_attr "type" "load")
9263    (set_attr "length" "8")])
9264
9265 (define_insn ""
9266   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9267         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9268    (use (match_operand:SI 2 "immediate_operand" "i"))
9269    (use (match_operand:SI 3 "immediate_operand" "i"))
9270    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9271    (clobber (reg:SI 6))
9272    (clobber (reg:SI 7))
9273    (clobber (reg:SI 8))
9274    (clobber (match_scratch:SI 5 "X"))]
9275   "TARGET_STRING && TARGET_POWERPC64
9276    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9277    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9278    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9279    && REGNO (operands[4]) == 5"
9280   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9281   [(set_attr "type" "load")
9282    (set_attr "length" "8")])
9283
9284 ;; Move up to 8 bytes at a time.
9285 (define_expand "movstrsi_2reg"
9286   [(parallel [(set (match_operand 0 "" "")
9287                    (match_operand 1 "" ""))
9288               (use (match_operand 2 "" ""))
9289               (use (match_operand 3 "" ""))
9290               (clobber (match_scratch:DI 4 ""))
9291               (clobber (match_scratch:SI 5 ""))])]
9292   "TARGET_STRING && ! TARGET_POWERPC64"
9293   "")
9294
9295 (define_insn ""
9296   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9297         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9298    (use (match_operand:SI 2 "immediate_operand" "i"))
9299    (use (match_operand:SI 3 "immediate_operand" "i"))
9300    (clobber (match_scratch:DI 4 "=&r"))
9301    (clobber (match_scratch:SI 5 "=q"))]
9302   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
9303    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9304   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9305   [(set_attr "type" "load")
9306    (set_attr "length" "8")])
9307
9308 (define_insn ""
9309   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9310         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9311    (use (match_operand:SI 2 "immediate_operand" "i"))
9312    (use (match_operand:SI 3 "immediate_operand" "i"))
9313    (clobber (match_scratch:DI 4 "=&r"))
9314    (clobber (match_scratch:SI 5 "X"))]
9315   "TARGET_STRING && ! TARGET_POWER && ! TARGET_POWERPC64
9316    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9317   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9318   [(set_attr "type" "load")
9319    (set_attr "length" "8")])
9320
9321 ;; Move up to 4 bytes at a time.
9322 (define_expand "movstrsi_1reg"
9323   [(parallel [(set (match_operand 0 "" "")
9324                    (match_operand 1 "" ""))
9325               (use (match_operand 2 "" ""))
9326               (use (match_operand 3 "" ""))
9327               (clobber (match_scratch:SI 4 ""))
9328               (clobber (match_scratch:SI 5 ""))])]
9329   "TARGET_STRING"
9330   "")
9331
9332 (define_insn ""
9333   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9334         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9335    (use (match_operand:SI 2 "immediate_operand" "i"))
9336    (use (match_operand:SI 3 "immediate_operand" "i"))
9337    (clobber (match_scratch:SI 4 "=&r"))
9338    (clobber (match_scratch:SI 5 "=q"))]
9339   "TARGET_STRING && TARGET_POWER
9340    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9341   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9342   [(set_attr "type" "load")
9343    (set_attr "length" "8")])
9344
9345 (define_insn ""
9346   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9347         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9348    (use (match_operand:SI 2 "immediate_operand" "i"))
9349    (use (match_operand:SI 3 "immediate_operand" "i"))
9350    (clobber (match_scratch:SI 4 "=&r"))
9351    (clobber (match_scratch:SI 5 "X"))]
9352   "TARGET_STRING && ! TARGET_POWER
9353    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9354   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9355   [(set_attr "type" "load")
9356    (set_attr "length" "8")])
9357
9358 (define_insn ""
9359   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9360         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9361    (use (match_operand:SI 2 "immediate_operand" "i"))
9362    (use (match_operand:SI 3 "immediate_operand" "i"))
9363    (clobber (match_scratch:SI 4 "=&r"))
9364    (clobber (match_scratch:SI 5 "X"))]
9365   "TARGET_STRING && TARGET_POWERPC64
9366    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9367   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9368   [(set_attr "type" "load")
9369    (set_attr "length" "8")])
9370
9371 \f
9372 ;; Define insns that do load or store with update.  Some of these we can
9373 ;; get by using pre-decrement or pre-increment, but the hardware can also
9374 ;; do cases where the increment is not the size of the object.
9375 ;;
9376 ;; In all these cases, we use operands 0 and 1 for the register being
9377 ;; incremented because those are the operands that local-alloc will
9378 ;; tie and these are the pair most likely to be tieable (and the ones
9379 ;; that will benefit the most).
9380
9381 (define_insn "*movdi_update1"
9382   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
9383         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9384                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
9385    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9386         (plus:DI (match_dup 1) (match_dup 2)))]
9387   "TARGET_POWERPC64 && TARGET_UPDATE"
9388   "@
9389    ldux %3,%0,%2
9390    ldu %3,%2(%0)"
9391   [(set_attr "type" "load_ux,load_u")])
9392
9393 (define_insn "movdi_update"
9394   [(set (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9395                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I")))
9396         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
9397    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9398         (plus:DI (match_dup 1) (match_dup 2)))]
9399   "TARGET_POWERPC64 && TARGET_UPDATE"
9400   "@
9401    stdux %3,%0,%2
9402    stdu %3,%2(%0)"
9403   [(set_attr "type" "store_ux,store_u")])
9404
9405 (define_insn "*movsi_update1"
9406   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9407         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9408                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9409    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9410         (plus:SI (match_dup 1) (match_dup 2)))]
9411   "TARGET_UPDATE"
9412   "@
9413    {lux|lwzux} %3,%0,%2
9414    {lu|lwzu} %3,%2(%0)"
9415   [(set_attr "type" "load_ux,load_u")])
9416
9417 (define_insn "*movsi_update2"
9418   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
9419         (sign_extend:DI
9420          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
9421                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
9422    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
9423         (plus:DI (match_dup 1) (match_dup 2)))]
9424   "TARGET_POWERPC64"
9425   "lwaux %3,%0,%2"
9426   [(set_attr "type" "load_ext_ux")])
9427
9428 (define_insn "movsi_update"
9429   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9430                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9431         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
9432    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9433         (plus:SI (match_dup 1) (match_dup 2)))]
9434   "TARGET_UPDATE"
9435   "@
9436    {stux|stwux} %3,%0,%2
9437    {stu|stwu} %3,%2(%0)"
9438   [(set_attr "type" "store_ux,store_u")])
9439
9440 (define_insn "*movhi_update1"
9441   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
9442         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9443                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9444    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9445         (plus:SI (match_dup 1) (match_dup 2)))]
9446   "TARGET_UPDATE"
9447   "@
9448    lhzux %3,%0,%2
9449    lhzu %3,%2(%0)"
9450   [(set_attr "type" "load_ux,load_u")])
9451
9452 (define_insn "*movhi_update2"
9453   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9454         (zero_extend:SI
9455          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9456                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9457    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9458         (plus:SI (match_dup 1) (match_dup 2)))]
9459   "TARGET_UPDATE"
9460   "@
9461    lhzux %3,%0,%2
9462    lhzu %3,%2(%0)"
9463   [(set_attr "type" "load_ux,load_u")])
9464
9465 (define_insn "*movhi_update3"
9466   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9467         (sign_extend:SI
9468          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9469                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9470    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9471         (plus:SI (match_dup 1) (match_dup 2)))]
9472   "TARGET_UPDATE"
9473   "@
9474    lhaux %3,%0,%2
9475    lhau %3,%2(%0)"
9476   [(set_attr "type" "load_ext_ux,load_ext_u")])
9477
9478 (define_insn "*movhi_update4"
9479   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9480                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9481         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
9482    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9483         (plus:SI (match_dup 1) (match_dup 2)))]
9484   "TARGET_UPDATE"
9485   "@
9486    sthux %3,%0,%2
9487    sthu %3,%2(%0)"
9488   [(set_attr "type" "store_ux,store_u")])
9489
9490 (define_insn "*movqi_update1"
9491   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
9492         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9493                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9494    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9495         (plus:SI (match_dup 1) (match_dup 2)))]
9496   "TARGET_UPDATE"
9497   "@
9498    lbzux %3,%0,%2
9499    lbzu %3,%2(%0)"
9500   [(set_attr "type" "load_ux,load_u")])
9501
9502 (define_insn "*movqi_update2"
9503   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9504         (zero_extend:SI
9505          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9506                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9507    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9508         (plus:SI (match_dup 1) (match_dup 2)))]
9509   "TARGET_UPDATE"
9510   "@
9511    lbzux %3,%0,%2
9512    lbzu %3,%2(%0)"
9513   [(set_attr "type" "load_ux,load_u")])
9514
9515 (define_insn "*movqi_update3"
9516   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9517                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9518         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
9519    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9520         (plus:SI (match_dup 1) (match_dup 2)))]
9521   "TARGET_UPDATE"
9522   "@
9523    stbux %3,%0,%2
9524    stbu %3,%2(%0)"
9525   [(set_attr "type" "store_ux,store_u")])
9526
9527 (define_insn "*movsf_update1"
9528   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
9529         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9530                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9531    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9532         (plus:SI (match_dup 1) (match_dup 2)))]
9533   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9534   "@
9535    lfsux %3,%0,%2
9536    lfsu %3,%2(%0)"
9537   [(set_attr "type" "fpload_ux,fpload_u")])
9538
9539 (define_insn "*movsf_update2"
9540   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9541                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9542         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
9543    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9544         (plus:SI (match_dup 1) (match_dup 2)))]
9545   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9546   "@
9547    stfsux %3,%0,%2
9548    stfsu %3,%2(%0)"
9549   [(set_attr "type" "fpstore_ux,fpstore_u")])
9550
9551 (define_insn "*movsf_update3"
9552   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
9553         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9554                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9555    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9556         (plus:SI (match_dup 1) (match_dup 2)))]
9557   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9558   "@
9559    {lux|lwzux} %3,%0,%2
9560    {lu|lwzu} %3,%2(%0)"
9561   [(set_attr "type" "load_ux,load_u")])
9562
9563 (define_insn "*movsf_update4"
9564   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9565                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9566         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
9567    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9568         (plus:SI (match_dup 1) (match_dup 2)))]
9569   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9570   "@
9571    {stux|stwux} %3,%0,%2
9572    {stu|stwu} %3,%2(%0)"
9573   [(set_attr "type" "store_ux,store_u")])
9574
9575 (define_insn "*movdf_update1"
9576   [(set (match_operand:DF 3 "gpc_reg_operand" "=f,f")
9577         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9578                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9579    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9580         (plus:SI (match_dup 1) (match_dup 2)))]
9581   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9582   "@
9583    lfdux %3,%0,%2
9584    lfdu %3,%2(%0)"
9585   [(set_attr "type" "fpload_ux,fpload_u")])
9586
9587 (define_insn "*movdf_update2"
9588   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9589                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9590         (match_operand:DF 3 "gpc_reg_operand" "f,f"))
9591    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9592         (plus:SI (match_dup 1) (match_dup 2)))]
9593   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9594   "@
9595    stfdux %3,%0,%2
9596    stfdu %3,%2(%0)"
9597   [(set_attr "type" "fpstore_ux,fpstore_u")])
9598
9599 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
9600
9601 (define_peephole
9602   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
9603         (match_operand:DF 1 "memory_operand" ""))
9604    (set (match_operand:DF 2 "gpc_reg_operand" "=f")
9605         (match_operand:DF 3 "memory_operand" ""))]
9606   "TARGET_POWER2
9607    && TARGET_HARD_FLOAT && TARGET_FPRS
9608    && registers_ok_for_quad_peep (operands[0], operands[2])
9609    && ! MEM_VOLATILE_P (operands[1]) && ! MEM_VOLATILE_P (operands[3])
9610    && addrs_ok_for_quad_peep (XEXP (operands[1], 0), XEXP (operands[3], 0))"
9611   "lfq%U1%X1 %0,%1")
9612
9613 (define_peephole
9614   [(set (match_operand:DF 0 "memory_operand" "")
9615         (match_operand:DF 1 "gpc_reg_operand" "f"))
9616    (set (match_operand:DF 2 "memory_operand" "")
9617         (match_operand:DF 3 "gpc_reg_operand" "f"))]
9618   "TARGET_POWER2
9619    && TARGET_HARD_FLOAT && TARGET_FPRS
9620    && registers_ok_for_quad_peep (operands[1], operands[3])
9621    && ! MEM_VOLATILE_P (operands[0]) && ! MEM_VOLATILE_P (operands[2])
9622    && addrs_ok_for_quad_peep (XEXP (operands[0], 0), XEXP (operands[2], 0))"
9623   "stfq%U0%X0 %1,%0")
9624 \f
9625 ;; TLS support.
9626
9627 ;; "b" output constraint here and on tls_ld to support tls linker optimization.
9628 (define_insn "tls_gd_32"
9629   [(set (match_operand:SI 0 "register_operand" "=b")
9630         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9631                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9632                    UNSPEC_TLSGD))]
9633   "HAVE_AS_TLS && !TARGET_64BIT"
9634   "addi %0,%1,%2@got@tlsgd")
9635
9636 (define_insn "tls_gd_64"
9637   [(set (match_operand:DI 0 "register_operand" "=b")
9638         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9639                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9640                    UNSPEC_TLSGD))]
9641   "HAVE_AS_TLS && TARGET_64BIT"
9642   "addi %0,%1,%2@got@tlsgd")
9643
9644 (define_insn "tls_ld_32"
9645   [(set (match_operand:SI 0 "register_operand" "=b")
9646         (unspec:SI [(match_operand:SI 1 "register_operand" "b")]
9647                    UNSPEC_TLSLD))]
9648   "HAVE_AS_TLS && !TARGET_64BIT"
9649   "addi %0,%1,%&@got@tlsld")
9650
9651 (define_insn "tls_ld_64"
9652   [(set (match_operand:DI 0 "register_operand" "=b")
9653         (unspec:DI [(match_operand:DI 1 "register_operand" "b")]
9654                    UNSPEC_TLSLD))]
9655   "HAVE_AS_TLS && TARGET_64BIT"
9656   "addi %0,%1,%&@got@tlsld")
9657
9658 (define_insn "tls_dtprel_32"
9659   [(set (match_operand:SI 0 "register_operand" "=r")
9660         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9661                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9662                    UNSPEC_TLSDTPREL))]
9663   "HAVE_AS_TLS && !TARGET_64BIT"
9664   "addi %0,%1,%2@dtprel")
9665
9666 (define_insn "tls_dtprel_64"
9667   [(set (match_operand:DI 0 "register_operand" "=r")
9668         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9669                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9670                    UNSPEC_TLSDTPREL))]
9671   "HAVE_AS_TLS && TARGET_64BIT"
9672   "addi %0,%1,%2@dtprel")
9673
9674 (define_insn "tls_dtprel_ha_32"
9675   [(set (match_operand:SI 0 "register_operand" "=r")
9676         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9677                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9678                    UNSPEC_TLSDTPRELHA))]
9679   "HAVE_AS_TLS && !TARGET_64BIT"
9680   "addis %0,%1,%2@dtprel@ha")
9681
9682 (define_insn "tls_dtprel_ha_64"
9683   [(set (match_operand:DI 0 "register_operand" "=r")
9684         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9685                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9686                    UNSPEC_TLSDTPRELHA))]
9687   "HAVE_AS_TLS && TARGET_64BIT"
9688   "addis %0,%1,%2@dtprel@ha")
9689
9690 (define_insn "tls_dtprel_lo_32"
9691   [(set (match_operand:SI 0 "register_operand" "=r")
9692         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9693                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9694                    UNSPEC_TLSDTPRELLO))]
9695   "HAVE_AS_TLS && !TARGET_64BIT"
9696   "addi %0,%1,%2@dtprel@l")
9697
9698 (define_insn "tls_dtprel_lo_64"
9699   [(set (match_operand:DI 0 "register_operand" "=r")
9700         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9701                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9702                    UNSPEC_TLSDTPRELLO))]
9703   "HAVE_AS_TLS && TARGET_64BIT"
9704   "addi %0,%1,%2@dtprel@l")
9705
9706 (define_insn "tls_got_dtprel_32"
9707   [(set (match_operand:SI 0 "register_operand" "=r")
9708         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9709                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9710                    UNSPEC_TLSGOTDTPREL))]
9711   "HAVE_AS_TLS && !TARGET_64BIT"
9712   "lwz %0,%2@got@dtprel(%1)")
9713
9714 (define_insn "tls_got_dtprel_64"
9715   [(set (match_operand:DI 0 "register_operand" "=r")
9716         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9717                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9718                    UNSPEC_TLSGOTDTPREL))]
9719   "HAVE_AS_TLS && TARGET_64BIT"
9720   "ld %0,%2@got@dtprel(%1)")
9721
9722 (define_insn "tls_tprel_32"
9723   [(set (match_operand:SI 0 "register_operand" "=r")
9724         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9725                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9726                    UNSPEC_TLSTPREL))]
9727   "HAVE_AS_TLS && !TARGET_64BIT"
9728   "addi %0,%1,%2@tprel")
9729
9730 (define_insn "tls_tprel_64"
9731   [(set (match_operand:DI 0 "register_operand" "=r")
9732         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9733                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9734                    UNSPEC_TLSTPREL))]
9735   "HAVE_AS_TLS && TARGET_64BIT"
9736   "addi %0,%1,%2@tprel")
9737
9738 (define_insn "tls_tprel_ha_32"
9739   [(set (match_operand:SI 0 "register_operand" "=r")
9740         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9741                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9742                    UNSPEC_TLSTPRELHA))]
9743   "HAVE_AS_TLS && !TARGET_64BIT"
9744   "addis %0,%1,%2@tprel@ha")
9745
9746 (define_insn "tls_tprel_ha_64"
9747   [(set (match_operand:DI 0 "register_operand" "=r")
9748         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9749                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9750                    UNSPEC_TLSTPRELHA))]
9751   "HAVE_AS_TLS && TARGET_64BIT"
9752   "addis %0,%1,%2@tprel@ha")
9753
9754 (define_insn "tls_tprel_lo_32"
9755   [(set (match_operand:SI 0 "register_operand" "=r")
9756         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9757                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9758                    UNSPEC_TLSTPRELLO))]
9759   "HAVE_AS_TLS && !TARGET_64BIT"
9760   "addi %0,%1,%2@tprel@l")
9761
9762 (define_insn "tls_tprel_lo_64"
9763   [(set (match_operand:DI 0 "register_operand" "=r")
9764         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9765                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9766                    UNSPEC_TLSTPRELLO))]
9767   "HAVE_AS_TLS && TARGET_64BIT"
9768   "addi %0,%1,%2@tprel@l")
9769
9770 ;; "b" output constraint here and on tls_tls input to support linker tls
9771 ;; optimization.  The linker may edit the instructions emitted by a
9772 ;; tls_got_tprel/tls_tls pair to addis,addi.
9773 (define_insn "tls_got_tprel_32"
9774   [(set (match_operand:SI 0 "register_operand" "=b")
9775         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9776                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9777                    UNSPEC_TLSGOTTPREL))]
9778   "HAVE_AS_TLS && !TARGET_64BIT"
9779   "lwz %0,%2@got@tprel(%1)")
9780
9781 (define_insn "tls_got_tprel_64"
9782   [(set (match_operand:DI 0 "register_operand" "=b")
9783         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9784                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9785                    UNSPEC_TLSGOTTPREL))]
9786   "HAVE_AS_TLS && TARGET_64BIT"
9787   "ld %0,%2@got@tprel(%1)")
9788
9789 (define_insn "tls_tls_32"
9790   [(set (match_operand:SI 0 "register_operand" "=r")
9791         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9792                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9793                    UNSPEC_TLSTLS))]
9794   "HAVE_AS_TLS && !TARGET_64BIT"
9795   "add %0,%1,%2@tls")
9796
9797 (define_insn "tls_tls_64"
9798   [(set (match_operand:DI 0 "register_operand" "=r")
9799         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9800                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9801                    UNSPEC_TLSTLS))]
9802   "HAVE_AS_TLS && TARGET_64BIT"
9803   "add %0,%1,%2@tls")
9804 \f
9805 ;; Next come insns related to the calling sequence.
9806 ;;
9807 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
9808 ;; We move the back-chain and decrement the stack pointer.
9809
9810 (define_expand "allocate_stack"
9811   [(set (match_operand 0 "gpc_reg_operand" "=r")
9812         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
9813    (set (reg 1)
9814         (minus (reg 1) (match_dup 1)))]
9815   ""
9816   "
9817 { rtx chain = gen_reg_rtx (Pmode);
9818   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
9819   rtx neg_op0;
9820
9821   emit_move_insn (chain, stack_bot);
9822
9823   /* Check stack bounds if necessary.  */
9824   if (current_function_limit_stack)
9825     {
9826       rtx available;
9827       available = expand_binop (Pmode, sub_optab, 
9828                                 stack_pointer_rtx, stack_limit_rtx,
9829                                 NULL_RTX, 1, OPTAB_WIDEN);
9830       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
9831     }
9832
9833   if (GET_CODE (operands[1]) != CONST_INT
9834       || INTVAL (operands[1]) < -32767
9835       || INTVAL (operands[1]) > 32768)
9836     {
9837       neg_op0 = gen_reg_rtx (Pmode);
9838       if (TARGET_32BIT)
9839         emit_insn (gen_negsi2 (neg_op0, operands[1]));
9840       else
9841         emit_insn (gen_negdi2 (neg_op0, operands[1]));
9842     }
9843   else
9844     neg_op0 = GEN_INT (- INTVAL (operands[1]));
9845
9846   if (TARGET_UPDATE)
9847     emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update : gen_movdi_update))
9848                 (stack_pointer_rtx, stack_pointer_rtx, neg_op0, chain));
9849
9850   else
9851     {
9852       emit_insn ((* ((TARGET_32BIT) ? gen_addsi3 : gen_adddi3))
9853                  (stack_pointer_rtx, stack_pointer_rtx, neg_op0));
9854       emit_move_insn (gen_rtx_MEM (Pmode, stack_pointer_rtx), chain);
9855     }
9856
9857   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
9858   DONE;
9859 }")
9860
9861 ;; These patterns say how to save and restore the stack pointer.  We need not
9862 ;; save the stack pointer at function level since we are careful to
9863 ;; preserve the backchain.  At block level, we have to restore the backchain
9864 ;; when we restore the stack pointer.
9865 ;;
9866 ;; For nonlocal gotos, we must save both the stack pointer and its
9867 ;; backchain and restore both.  Note that in the nonlocal case, the
9868 ;; save area is a memory location.
9869
9870 (define_expand "save_stack_function"
9871   [(match_operand 0 "any_operand" "")
9872    (match_operand 1 "any_operand" "")]
9873   ""
9874   "DONE;")
9875
9876 (define_expand "restore_stack_function"
9877   [(match_operand 0 "any_operand" "")
9878    (match_operand 1 "any_operand" "")]
9879   ""
9880   "DONE;")
9881
9882 (define_expand "restore_stack_block"
9883   [(use (match_operand 0 "register_operand" ""))
9884    (set (match_dup 2) (match_dup 3))
9885    (set (match_dup 0) (match_operand 1 "register_operand" ""))
9886    (set (match_dup 3) (match_dup 2))]
9887   ""
9888   "
9889 {
9890   operands[2] = gen_reg_rtx (Pmode);
9891   operands[3] = gen_rtx_MEM (Pmode, operands[0]);
9892 }")
9893
9894 (define_expand "save_stack_nonlocal"
9895   [(match_operand 0 "memory_operand" "")
9896    (match_operand 1 "register_operand" "")]
9897   ""
9898   "
9899 {
9900   rtx temp = gen_reg_rtx (Pmode);
9901
9902   /* Copy the backchain to the first word, sp to the second.  */
9903   emit_move_insn (temp, gen_rtx_MEM (Pmode, operands[1]));
9904   emit_move_insn (operand_subword (operands[0], 0, 0,
9905                                    (TARGET_32BIT ? DImode : TImode)),
9906                   temp);
9907   emit_move_insn (operand_subword (operands[0], 1, 0, (TARGET_32BIT ? DImode : TImode)),
9908                   operands[1]);
9909   DONE;
9910 }")
9911
9912 (define_expand "restore_stack_nonlocal"
9913   [(match_operand 0 "register_operand" "")
9914    (match_operand 1 "memory_operand" "")]
9915   ""
9916   "
9917 {
9918   rtx temp = gen_reg_rtx (Pmode);
9919
9920   /* Restore the backchain from the first word, sp from the second.  */
9921   emit_move_insn (temp,
9922                   operand_subword (operands[1], 0, 0, (TARGET_32BIT ? DImode : TImode)));
9923   emit_move_insn (operands[0],
9924                   operand_subword (operands[1], 1, 0,
9925                                    (TARGET_32BIT ? DImode : TImode)));
9926   emit_move_insn (gen_rtx_MEM (Pmode, operands[0]), temp);
9927   DONE;
9928 }")
9929 \f
9930 ;; TOC register handling.
9931
9932 ;; Code to initialize the TOC register...
9933
9934 (define_insn "load_toc_aix_si"
9935   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9936                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
9937               (use (reg:SI 2))])]
9938   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
9939   "*
9940 {
9941   char buf[30];
9942   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
9943   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9944   operands[2] = gen_rtx_REG (Pmode, 2);
9945   return \"{l|lwz} %0,%1(%2)\";
9946 }"
9947   [(set_attr "type" "load")])
9948
9949 (define_insn "load_toc_aix_di"
9950   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9951                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
9952               (use (reg:DI 2))])]
9953   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
9954   "*
9955 {
9956   char buf[30];
9957 #ifdef TARGET_RELOCATABLE
9958   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
9959                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
9960 #else
9961   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
9962 #endif
9963   if (TARGET_ELF)
9964     strcat (buf, \"@toc\");
9965   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9966   operands[2] = gen_rtx_REG (Pmode, 2);
9967   return \"ld %0,%1(%2)\";
9968 }"
9969   [(set_attr "type" "load")])
9970
9971 (define_insn "load_toc_v4_pic_si"
9972   [(set (match_operand:SI 0 "register_operand" "=l")
9973         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
9974   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
9975   "bl _GLOBAL_OFFSET_TABLE_@local-4"
9976   [(set_attr "type" "branch")
9977    (set_attr "length" "4")])
9978
9979 (define_insn "load_toc_v4_PIC_1"
9980   [(set (match_operand:SI 0 "register_operand" "=l")
9981         (match_operand:SI 1 "immediate_operand" "s"))
9982    (use (unspec [(match_dup 1)] UNSPEC_TOC))]
9983   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
9984   "bcl 20,31,%1\\n%1:"
9985   [(set_attr "type" "branch")
9986    (set_attr "length" "4")])
9987
9988 (define_insn "load_toc_v4_PIC_1b"
9989   [(set (match_operand:SI 0 "register_operand" "=l")
9990         (match_operand:SI 1 "immediate_operand" "s"))
9991    (use (unspec [(match_dup 1) (match_operand 2 "immediate_operand" "s")]
9992                 UNSPEC_TOCPTR))]
9993   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
9994   "bcl 20,31,%1+4\\n%1:\\n\\t.long %2-%1"
9995   [(set_attr "type" "branch")
9996    (set_attr "length" "8")])
9997
9998 (define_insn "load_toc_v4_PIC_2"
9999   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10000         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10001                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
10002                              (match_operand:SI 3 "immediate_operand" "s")))))]
10003   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10004   "{l|lwz} %0,%2-%3(%1)"
10005   [(set_attr "type" "load")])
10006
10007 (define_insn "load_macho_picbase"
10008   [(set (match_operand:SI 0 "register_operand" "=l")
10009         (unspec:SI [(match_operand:SI 1 "immediate_operand" "s")]
10010                    UNSPEC_LD_MPIC))]
10011   "(DEFAULT_ABI == ABI_DARWIN) && flag_pic"
10012   "bcl 20,31,%1\\n%1:"
10013   [(set_attr "type" "branch")
10014    (set_attr "length" "4")])
10015
10016 (define_insn "macho_correct_pic"
10017   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10018         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
10019                  (unspec:SI [(match_operand:SI 2 "immediate_operand" "s")
10020                              (match_operand:SI 3 "immediate_operand" "s")]
10021                             UNSPEC_MPIC_CORRECT)))]
10022   "DEFAULT_ABI == ABI_DARWIN"
10023   "addis %0,%1,ha16(%2-%3)\n\taddi %0,%0,lo16(%2-%3)"
10024   [(set_attr "length" "8")])
10025
10026 ;; If the TOC is shared over a translation unit, as happens with all
10027 ;; the kinds of PIC that we support, we need to restore the TOC
10028 ;; pointer only when jumping over units of translation.
10029 ;; On Darwin, we need to reload the picbase.
10030
10031 (define_expand "builtin_setjmp_receiver"
10032   [(use (label_ref (match_operand 0 "" "")))]
10033   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
10034    || (TARGET_TOC && TARGET_MINIMAL_TOC)
10035    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
10036   "
10037 {
10038 #if TARGET_MACHO
10039   if (DEFAULT_ABI == ABI_DARWIN)
10040     {
10041       const char *picbase = machopic_function_base_name ();
10042       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (picbase));
10043       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
10044       rtx tmplabrtx;
10045       char tmplab[20];
10046
10047       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
10048                                   CODE_LABEL_NUMBER (operands[0]));
10049       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
10050
10051       emit_insn (gen_load_macho_picbase (picreg, tmplabrtx));
10052       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
10053     }
10054   else
10055 #endif
10056     rs6000_emit_load_toc_table (FALSE);
10057   DONE;
10058 }")
10059 \f
10060 ;; A function pointer under AIX is a pointer to a data area whose first word
10061 ;; contains the actual address of the function, whose second word contains a
10062 ;; pointer to its TOC, and whose third word contains a value to place in the
10063 ;; static chain register (r11).  Note that if we load the static chain, our
10064 ;; "trampoline" need not have any executable code.
10065
10066 (define_expand "call_indirect_aix32"
10067   [(set (match_dup 2)
10068         (mem:SI (match_operand:SI 0 "gpc_reg_operand" "")))
10069    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10070         (reg:SI 2))
10071    (set (reg:SI 2)
10072         (mem:SI (plus:SI (match_dup 0)
10073                          (const_int 4))))
10074    (set (reg:SI 11)
10075         (mem:SI (plus:SI (match_dup 0)
10076                          (const_int 8))))
10077    (parallel [(call (mem:SI (match_dup 2))
10078                     (match_operand 1 "" ""))
10079               (use (reg:SI 2))
10080               (use (reg:SI 11))
10081               (set (reg:SI 2)
10082                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10083               (clobber (scratch:SI))])]
10084   "TARGET_32BIT"
10085   "
10086 { operands[2] = gen_reg_rtx (SImode); }")
10087
10088 (define_expand "call_indirect_aix64"
10089   [(set (match_dup 2)
10090         (mem:DI (match_operand:DI 0 "gpc_reg_operand" "")))
10091    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10092         (reg:DI 2))
10093    (set (reg:DI 2)
10094         (mem:DI (plus:DI (match_dup 0)
10095                          (const_int 8))))
10096    (set (reg:DI 11)
10097         (mem:DI (plus:DI (match_dup 0)
10098                          (const_int 16))))
10099    (parallel [(call (mem:SI (match_dup 2))
10100                     (match_operand 1 "" ""))
10101               (use (reg:DI 2))
10102               (use (reg:DI 11))
10103               (set (reg:DI 2)
10104                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10105               (clobber (scratch:SI))])]
10106   "TARGET_64BIT"
10107   "
10108 { operands[2] = gen_reg_rtx (DImode); }")
10109
10110 (define_expand "call_value_indirect_aix32"
10111   [(set (match_dup 3)
10112         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
10113    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10114         (reg:SI 2))
10115    (set (reg:SI 2)
10116         (mem:SI (plus:SI (match_dup 1)
10117                          (const_int 4))))
10118    (set (reg:SI 11)
10119         (mem:SI (plus:SI (match_dup 1)
10120                          (const_int 8))))
10121    (parallel [(set (match_operand 0 "" "")
10122                    (call (mem:SI (match_dup 3))
10123                          (match_operand 2 "" "")))
10124               (use (reg:SI 2))
10125               (use (reg:SI 11))
10126               (set (reg:SI 2)
10127                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10128               (clobber (scratch:SI))])]
10129   "TARGET_32BIT"
10130   "
10131 { operands[3] = gen_reg_rtx (SImode); }")
10132
10133 (define_expand "call_value_indirect_aix64"
10134   [(set (match_dup 3)
10135         (mem:DI (match_operand:DI 1 "gpc_reg_operand" "")))
10136    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10137         (reg:DI 2))
10138    (set (reg:DI 2)
10139         (mem:DI (plus:DI (match_dup 1)
10140                          (const_int 8))))
10141    (set (reg:DI 11)
10142         (mem:DI (plus:DI (match_dup 1)
10143                          (const_int 16))))
10144    (parallel [(set (match_operand 0 "" "")
10145                    (call (mem:SI (match_dup 3))
10146                          (match_operand 2 "" "")))
10147               (use (reg:DI 2))
10148               (use (reg:DI 11))
10149               (set (reg:DI 2)
10150                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10151               (clobber (scratch:SI))])]
10152   "TARGET_64BIT"
10153   "
10154 { operands[3] = gen_reg_rtx (DImode); }")
10155
10156 ;; Now the definitions for the call and call_value insns
10157 (define_expand "call"
10158   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10159                     (match_operand 1 "" ""))
10160               (use (match_operand 2 "" ""))
10161               (clobber (scratch:SI))])]
10162   ""
10163   "
10164 {
10165 #if TARGET_MACHO
10166   if (MACHOPIC_INDIRECT)
10167     operands[0] = machopic_indirect_call_target (operands[0]);
10168 #endif
10169
10170   if (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != CONST_INT)
10171     abort ();
10172
10173   operands[0] = XEXP (operands[0], 0);
10174
10175   if (GET_CODE (operands[0]) != SYMBOL_REF
10176       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
10177       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
10178     {
10179       if (INTVAL (operands[2]) & CALL_LONG)
10180         operands[0] = rs6000_longcall_ref (operands[0]);
10181
10182       if (DEFAULT_ABI == ABI_V4
10183           || DEFAULT_ABI == ABI_DARWIN)
10184         operands[0] = force_reg (Pmode, operands[0]);
10185
10186       else if (DEFAULT_ABI == ABI_AIX)
10187         {
10188           /* AIX function pointers are really pointers to a three word
10189              area.  */
10190           emit_call_insn (TARGET_32BIT
10191                           ? gen_call_indirect_aix32 (force_reg (SImode,
10192                                                                 operands[0]),
10193                                                      operands[1])
10194                           : gen_call_indirect_aix64 (force_reg (DImode,
10195                                                                 operands[0]),
10196                                                      operands[1]));
10197           DONE;
10198         }
10199       else
10200         abort ();
10201     }
10202 }")
10203
10204 (define_expand "call_value"
10205   [(parallel [(set (match_operand 0 "" "")
10206                    (call (mem:SI (match_operand 1 "address_operand" ""))
10207                          (match_operand 2 "" "")))
10208               (use (match_operand 3 "" ""))
10209               (clobber (scratch:SI))])]
10210   ""
10211   "
10212 {
10213 #if TARGET_MACHO
10214   if (MACHOPIC_INDIRECT)
10215     operands[1] = machopic_indirect_call_target (operands[1]);
10216 #endif
10217
10218   if (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != CONST_INT)
10219     abort ();
10220
10221   operands[1] = XEXP (operands[1], 0);
10222
10223   if (GET_CODE (operands[1]) != SYMBOL_REF
10224       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
10225       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
10226     {
10227       if (INTVAL (operands[3]) & CALL_LONG)
10228         operands[1] = rs6000_longcall_ref (operands[1]);
10229
10230       if (DEFAULT_ABI == ABI_V4
10231           || DEFAULT_ABI == ABI_DARWIN)
10232         operands[0] = force_reg (Pmode, operands[0]);
10233
10234       else if (DEFAULT_ABI == ABI_AIX)
10235         {
10236           /* AIX function pointers are really pointers to a three word
10237              area.  */
10238           emit_call_insn (TARGET_32BIT
10239                           ? gen_call_value_indirect_aix32 (operands[0],
10240                                                            force_reg (SImode,
10241                                                                       operands[1]),
10242                                                            operands[2])
10243                           : gen_call_value_indirect_aix64 (operands[0],
10244                                                            force_reg (DImode,
10245                                                                       operands[1]),
10246                                                            operands[2]));
10247           DONE;
10248         }
10249       else
10250         abort ();
10251     }
10252 }")
10253
10254 ;; Call to function in current module.  No TOC pointer reload needed.
10255 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10256 ;; either the function was not prototyped, or it was prototyped as a
10257 ;; variable argument function.  It is > 0 if FP registers were passed
10258 ;; and < 0 if they were not.
10259
10260 (define_insn "*call_local32"
10261   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10262          (match_operand 1 "" "g,g"))
10263    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10264    (clobber (match_scratch:SI 3 "=l,l"))]
10265   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10266   "*
10267 {
10268   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10269     output_asm_insn (\"crxor 6,6,6\", operands);
10270
10271   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10272     output_asm_insn (\"creqv 6,6,6\", operands);
10273
10274   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10275 }"
10276   [(set_attr "type" "branch")
10277    (set_attr "length" "4,8")])
10278
10279 (define_insn "*call_local64"
10280   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10281          (match_operand 1 "" "g,g"))
10282    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10283    (clobber (match_scratch:SI 3 "=l,l"))]
10284   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10285   "*
10286 {
10287   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10288     output_asm_insn (\"crxor 6,6,6\", operands);
10289
10290   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10291     output_asm_insn (\"creqv 6,6,6\", operands);
10292
10293   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10294 }"
10295   [(set_attr "type" "branch")
10296    (set_attr "length" "4,8")])
10297
10298 (define_insn "*call_value_local32"
10299   [(set (match_operand 0 "" "")
10300         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10301               (match_operand 2 "" "g,g")))
10302    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10303    (clobber (match_scratch:SI 4 "=l,l"))]
10304   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10305   "*
10306 {
10307   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10308     output_asm_insn (\"crxor 6,6,6\", operands);
10309
10310   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10311     output_asm_insn (\"creqv 6,6,6\", operands);
10312
10313   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10314 }"
10315   [(set_attr "type" "branch")
10316    (set_attr "length" "4,8")])
10317
10318
10319 (define_insn "*call_value_local64"
10320   [(set (match_operand 0 "" "")
10321         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10322               (match_operand 2 "" "g,g")))
10323    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10324    (clobber (match_scratch:SI 4 "=l,l"))]
10325   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10326   "*
10327 {
10328   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10329     output_asm_insn (\"crxor 6,6,6\", operands);
10330
10331   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10332     output_asm_insn (\"creqv 6,6,6\", operands);
10333
10334   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10335 }"
10336   [(set_attr "type" "branch")
10337    (set_attr "length" "4,8")])
10338
10339 ;; Call to function which may be in another module.  Restore the TOC
10340 ;; pointer (r2) after the call unless this is System V.
10341 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10342 ;; either the function was not prototyped, or it was prototyped as a
10343 ;; variable argument function.  It is > 0 if FP registers were passed
10344 ;; and < 0 if they were not.
10345
10346 (define_insn "*call_indirect_nonlocal_aix32"
10347   [(call (mem:SI (match_operand:SI 0 "register_operand" "cl"))
10348          (match_operand 1 "" "g"))
10349    (use (reg:SI 2))
10350    (use (reg:SI 11))
10351    (set (reg:SI 2)
10352         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10353    (clobber (match_scratch:SI 2 "=l"))]
10354   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10355   "b%T0l\;{l|lwz} 2,20(1)"
10356   [(set_attr "type" "jmpreg")
10357    (set_attr "length" "8")])
10358
10359 (define_insn "*call_nonlocal_aix32"
10360   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10361          (match_operand 1 "" "g"))
10362    (use (match_operand:SI 2 "immediate_operand" "O"))
10363    (clobber (match_scratch:SI 3 "=l"))]
10364   "TARGET_32BIT
10365    && DEFAULT_ABI == ABI_AIX
10366    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10367   "bl %z0\;%."
10368   [(set_attr "type" "branch")
10369    (set_attr "length" "8")])
10370
10371 (define_insn "*call_indirect_nonlocal_aix64"
10372   [(call (mem:SI (match_operand:DI 0 "register_operand" "cl"))
10373          (match_operand 1 "" "g"))
10374    (use (reg:DI 2))
10375    (use (reg:DI 11))
10376    (set (reg:DI 2)
10377         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10378    (clobber (match_scratch:SI 2 "=l"))]
10379   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10380   "b%T0l\;ld 2,40(1)"
10381   [(set_attr "type" "jmpreg")
10382    (set_attr "length" "8")])
10383
10384 (define_insn "*call_nonlocal_aix64"
10385   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10386          (match_operand 1 "" "g"))
10387    (use (match_operand:SI 2 "immediate_operand" "O"))
10388    (clobber (match_scratch:SI 3 "=l"))]
10389   "TARGET_64BIT 
10390    && DEFAULT_ABI == ABI_AIX
10391    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10392   "bl %z0\;%."
10393   [(set_attr "type" "branch")
10394    (set_attr "length" "8")])
10395
10396 (define_insn "*call_value_indirect_nonlocal_aix32"
10397   [(set (match_operand 0 "" "")
10398         (call (mem:SI (match_operand:SI 1 "register_operand" "cl"))
10399               (match_operand 2 "" "g")))
10400    (use (reg:SI 2))
10401    (use (reg:SI 11))
10402    (set (reg:SI 2)
10403         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10404    (clobber (match_scratch:SI 3 "=l"))]
10405   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10406   "b%T1l\;{l|lwz} 2,20(1)"
10407   [(set_attr "type" "jmpreg")
10408    (set_attr "length" "8")])
10409
10410 (define_insn "*call_value_nonlocal_aix32"
10411   [(set (match_operand 0 "" "")
10412         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10413               (match_operand 2 "" "g")))
10414    (use (match_operand:SI 3 "immediate_operand" "O"))
10415    (clobber (match_scratch:SI 4 "=l"))]
10416   "TARGET_32BIT
10417    && DEFAULT_ABI == ABI_AIX
10418    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10419   "bl %z1\;%."
10420   [(set_attr "type" "branch")
10421    (set_attr "length" "8")])
10422
10423 (define_insn "*call_value_indirect_nonlocal_aix64"
10424   [(set (match_operand 0 "" "")
10425         (call (mem:SI (match_operand:DI 1 "register_operand" "cl"))
10426               (match_operand 2 "" "g")))
10427    (use (reg:DI 2))
10428    (use (reg:DI 11))
10429    (set (reg:DI 2)
10430         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10431    (clobber (match_scratch:SI 3 "=l"))]
10432   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10433   "b%T1l\;ld 2,40(1)"
10434   [(set_attr "type" "jmpreg")
10435    (set_attr "length" "8")])
10436
10437 (define_insn "*call_value_nonlocal_aix64"
10438   [(set (match_operand 0 "" "")
10439         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10440               (match_operand 2 "" "g")))
10441    (use (match_operand:SI 3 "immediate_operand" "O"))
10442    (clobber (match_scratch:SI 4 "=l"))]
10443   "TARGET_64BIT 
10444    && DEFAULT_ABI == ABI_AIX
10445    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10446   "bl %z1\;%."
10447   [(set_attr "type" "branch")
10448    (set_attr "length" "8")])
10449
10450 ;; A function pointer under System V is just a normal pointer
10451 ;; operands[0] is the function pointer
10452 ;; operands[1] is the stack size to clean up
10453 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
10454 ;; which indicates how to set cr1
10455
10456 (define_insn "*call_indirect_nonlocal_sysv"
10457   [(call (mem:SI (match_operand:SI 0 "register_operand" "cl,cl"))
10458          (match_operand 1 "" "g,g"))
10459    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10460    (clobber (match_scratch:SI 3 "=l,l"))]
10461   "DEFAULT_ABI == ABI_V4
10462    || DEFAULT_ABI == ABI_DARWIN"
10463 {
10464   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10465     output_asm_insn ("crxor 6,6,6", operands);
10466
10467   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10468     output_asm_insn ("creqv 6,6,6", operands);
10469
10470   return "b%T0l";
10471 }
10472   [(set_attr "type" "jmpreg,jmpreg")
10473    (set_attr "length" "4,8")])
10474
10475 (define_insn "*call_nonlocal_sysv"
10476   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s,s"))
10477          (match_operand 1 "" "g,g"))
10478    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10479    (clobber (match_scratch:SI 3 "=l,l"))]
10480   "(DEFAULT_ABI == ABI_DARWIN
10481    || (DEFAULT_ABI == ABI_V4
10482        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
10483 {
10484   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10485     output_asm_insn ("crxor 6,6,6", operands);
10486
10487   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10488     output_asm_insn ("creqv 6,6,6", operands);
10489
10490 #if TARGET_MACHO
10491   return output_call(insn, operands, 0, 2);
10492 #else
10493   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z0@plt" : "bl %z0";
10494 #endif     
10495 }
10496   [(set_attr "type" "branch,branch")
10497    (set_attr "length" "4,8")])
10498
10499 (define_insn "*call_value_indirect_nonlocal_sysv"
10500   [(set (match_operand 0 "" "")
10501         (call (mem:SI (match_operand:SI 1 "register_operand" "cl,cl"))
10502               (match_operand 2 "" "g,g")))
10503    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10504    (clobber (match_scratch:SI 4 "=l,l"))]
10505   "DEFAULT_ABI == ABI_V4
10506    || DEFAULT_ABI == ABI_DARWIN"
10507 {
10508   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10509     output_asm_insn ("crxor 6,6,6", operands);
10510
10511   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10512     output_asm_insn ("creqv 6,6,6", operands);
10513
10514   return "b%T1l";
10515 }
10516   [(set_attr "type" "jmpreg,jmpreg")
10517    (set_attr "length" "4,8")])
10518
10519 (define_insn "*call_value_nonlocal_sysv"
10520   [(set (match_operand 0 "" "")
10521         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s,s"))
10522               (match_operand 2 "" "g,g")))
10523    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10524    (clobber (match_scratch:SI 4 "=l,l"))]
10525   "(DEFAULT_ABI == ABI_DARWIN
10526    || (DEFAULT_ABI == ABI_V4
10527        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
10528 {
10529   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10530     output_asm_insn ("crxor 6,6,6", operands);
10531
10532   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10533     output_asm_insn ("creqv 6,6,6", operands);
10534
10535 #if TARGET_MACHO
10536   return output_call(insn, operands, 1, 3);
10537 #else
10538   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z1@plt" : "bl %z1";
10539 #endif     
10540 }
10541   [(set_attr "type" "branch,branch")
10542    (set_attr "length" "4,8")])
10543
10544 ;; Call subroutine returning any type.
10545 (define_expand "untyped_call"
10546   [(parallel [(call (match_operand 0 "" "")
10547                     (const_int 0))
10548               (match_operand 1 "" "")
10549               (match_operand 2 "" "")])]
10550   ""
10551   "
10552 {
10553   int i;
10554
10555   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
10556
10557   for (i = 0; i < XVECLEN (operands[2], 0); i++)
10558     {
10559       rtx set = XVECEXP (operands[2], 0, i);
10560       emit_move_insn (SET_DEST (set), SET_SRC (set));
10561     }
10562
10563   /* The optimizer does not know that the call sets the function value
10564      registers we stored in the result block.  We avoid problems by
10565      claiming that all hard registers are used and clobbered at this
10566      point.  */
10567   emit_insn (gen_blockage ());
10568
10569   DONE;
10570 }")
10571
10572 ;; sibling call patterns
10573 (define_expand "sibcall"
10574   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10575                     (match_operand 1 "" ""))
10576               (use (match_operand 2 "" ""))
10577               (use (match_operand 3 "" ""))
10578               (return)])]
10579   ""
10580   "
10581 {
10582 #if TARGET_MACHO
10583   if (MACHOPIC_INDIRECT)
10584     operands[0] = machopic_indirect_call_target (operands[0]);
10585 #endif
10586
10587   if (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != CONST_INT)
10588     abort ();
10589
10590   operands[0] = XEXP (operands[0], 0);
10591   operands[3] = gen_reg_rtx (SImode);
10592
10593 }")
10594
10595 ;; this and similar patterns must be marked as using LR, otherwise
10596 ;; dataflow will try to delete the store into it.  This is true
10597 ;; even when the actual reg to jump to is in CTR, when LR was
10598 ;; saved and restored around the PIC-setting BCL.
10599 (define_insn "*sibcall_local32"
10600   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10601          (match_operand 1 "" "g,g"))
10602    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10603    (use (match_operand:SI 3 "register_operand" "l,l"))
10604    (return)]
10605   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10606   "*
10607 {
10608   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10609     output_asm_insn (\"crxor 6,6,6\", operands);
10610
10611   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10612     output_asm_insn (\"creqv 6,6,6\", operands);
10613
10614   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
10615 }"
10616   [(set_attr "type" "branch")
10617    (set_attr "length" "4,8")])
10618
10619 (define_insn "*sibcall_local64"
10620   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10621          (match_operand 1 "" "g,g"))
10622    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10623    (use (match_operand:SI 3 "register_operand" "l,l"))
10624    (return)]
10625   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10626   "*
10627 {
10628   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10629     output_asm_insn (\"crxor 6,6,6\", operands);
10630
10631   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10632     output_asm_insn (\"creqv 6,6,6\", operands);
10633
10634   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
10635 }"
10636   [(set_attr "type" "branch")
10637    (set_attr "length" "4,8")])
10638
10639 (define_insn "*sibcall_value_local32"
10640   [(set (match_operand 0 "" "")
10641         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10642               (match_operand 2 "" "g,g")))
10643    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10644    (use (match_operand:SI 4 "register_operand" "l,l"))
10645    (return)]
10646   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10647   "*
10648 {
10649   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10650     output_asm_insn (\"crxor 6,6,6\", operands);
10651
10652   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10653     output_asm_insn (\"creqv 6,6,6\", operands);
10654
10655   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
10656 }"
10657   [(set_attr "type" "branch")
10658    (set_attr "length" "4,8")])
10659
10660
10661 (define_insn "*sibcall_value_local64"
10662   [(set (match_operand 0 "" "")
10663         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10664               (match_operand 2 "" "g,g")))
10665    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10666    (use (match_operand:SI 4 "register_operand" "l,l"))
10667    (return)]
10668   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10669   "*
10670 {
10671   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10672     output_asm_insn (\"crxor 6,6,6\", operands);
10673
10674   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10675     output_asm_insn (\"creqv 6,6,6\", operands);
10676
10677   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
10678 }"
10679   [(set_attr "type" "branch")
10680    (set_attr "length" "4,8")])
10681
10682 (define_insn "*sibcall_nonlocal_aix32"
10683   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10684          (match_operand 1 "" "g"))
10685    (use (match_operand:SI 2 "immediate_operand" "O"))
10686    (use (match_operand:SI 3 "register_operand" "l"))
10687    (return)]
10688   "TARGET_32BIT
10689    && DEFAULT_ABI == ABI_AIX
10690    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10691   "b %z0"
10692   [(set_attr "type" "branch")
10693    (set_attr "length" "4")])
10694
10695 (define_insn "*sibcall_nonlocal_aix64"
10696   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10697          (match_operand 1 "" "g"))
10698    (use (match_operand:SI 2 "immediate_operand" "O"))
10699    (use (match_operand:SI 3 "register_operand" "l"))
10700    (return)]
10701   "TARGET_64BIT 
10702    && DEFAULT_ABI == ABI_AIX
10703    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10704   "b %z0"
10705   [(set_attr "type" "branch")
10706    (set_attr "length" "4")])
10707
10708 (define_insn "*sibcall_value_nonlocal_aix32"
10709   [(set (match_operand 0 "" "")
10710         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10711               (match_operand 2 "" "g")))
10712    (use (match_operand:SI 3 "immediate_operand" "O"))
10713    (use (match_operand:SI 4 "register_operand" "l"))
10714    (return)]
10715   "TARGET_32BIT
10716    && DEFAULT_ABI == ABI_AIX
10717    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10718   "b %z1"
10719   [(set_attr "type" "branch")
10720    (set_attr "length" "4")])
10721
10722 (define_insn "*sibcall_value_nonlocal_aix64"
10723   [(set (match_operand 0 "" "")
10724         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10725               (match_operand 2 "" "g")))
10726    (use (match_operand:SI 3 "immediate_operand" "O"))
10727    (use (match_operand:SI 4 "register_operand" "l"))
10728    (return)]
10729   "TARGET_64BIT 
10730    && DEFAULT_ABI == ABI_AIX
10731    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10732   "b %z1"
10733   [(set_attr "type" "branch")
10734    (set_attr "length" "4")])
10735
10736 (define_insn "*sibcall_nonlocal_sysv"
10737   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s,s"))
10738          (match_operand 1 "" ""))
10739    (use (match_operand 2 "immediate_operand" "O,n"))
10740    (use (match_operand:SI 3 "register_operand" "l,l"))
10741    (return)]
10742   "(DEFAULT_ABI == ABI_DARWIN
10743      || DEFAULT_ABI == ABI_V4)
10744    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10745   "*
10746 {
10747   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10748     output_asm_insn (\"crxor 6,6,6\", operands);
10749
10750   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10751     output_asm_insn (\"creqv 6,6,6\", operands);
10752
10753   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@plt\" : \"b %z0\";
10754 }"
10755   [(set_attr "type" "branch,branch")
10756    (set_attr "length" "4,8")])
10757
10758 (define_expand "sibcall_value"
10759   [(parallel [(set (match_operand 0 "register_operand" "")
10760                 (call (mem:SI (match_operand 1 "address_operand" ""))
10761                       (match_operand 2 "" "")))
10762               (use (match_operand 3 "" ""))
10763               (use (match_operand 4 "" ""))
10764               (return)])]
10765   ""
10766   "
10767 {
10768 #if TARGET_MACHO
10769   if (MACHOPIC_INDIRECT)
10770     operands[1] = machopic_indirect_call_target (operands[1]);
10771 #endif
10772
10773   if (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != CONST_INT)
10774     abort ();
10775
10776   operands[1] = XEXP (operands[1], 0);
10777   operands[4] = gen_reg_rtx (SImode);
10778
10779 }")
10780
10781 (define_insn "*sibcall_value_nonlocal_sysv"
10782   [(set (match_operand 0 "" "")
10783         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s,s"))
10784               (match_operand 2 "" "")))
10785    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10786    (use (match_operand:SI 4 "register_operand" "l,l"))
10787    (return)]
10788   "(DEFAULT_ABI == ABI_DARWIN
10789        || DEFAULT_ABI == ABI_V4)
10790    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10791   "*
10792 {
10793   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10794     output_asm_insn (\"crxor 6,6,6\", operands);
10795
10796   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10797     output_asm_insn (\"creqv 6,6,6\", operands);
10798
10799   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@plt\" : \"b %z1\";
10800 }"
10801   [(set_attr "type" "branch,branch")
10802    (set_attr "length" "4,8")])
10803
10804 (define_expand "sibcall_epilogue"
10805   [(use (const_int 0))]
10806   "TARGET_SCHED_PROLOG"
10807   "
10808 {
10809       rs6000_emit_epilogue (TRUE);
10810       DONE;
10811 }")
10812
10813 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
10814 ;; all of memory.  This blocks insns from being moved across this point.
10815
10816 (define_insn "blockage"
10817   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
10818   ""
10819   "")
10820 \f
10821 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
10822 ;; signed & unsigned, and one type of branch.
10823 ;;
10824 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
10825 ;; insns, and branches.  We store the operands of compares until we see
10826 ;; how it is used.
10827 (define_expand "cmpsi"
10828   [(set (cc0)
10829         (compare (match_operand:SI 0 "gpc_reg_operand" "")
10830                  (match_operand:SI 1 "reg_or_short_operand" "")))]
10831   ""
10832   "
10833 {
10834   /* Take care of the possibility that operands[1] might be negative but
10835      this might be a logical operation.  That insn doesn't exist.  */
10836   if (GET_CODE (operands[1]) == CONST_INT
10837       && INTVAL (operands[1]) < 0)
10838     operands[1] = force_reg (SImode, operands[1]);
10839
10840   rs6000_compare_op0 = operands[0];
10841   rs6000_compare_op1 = operands[1];
10842   rs6000_compare_fp_p = 0;
10843   DONE;
10844 }")
10845
10846 (define_expand "cmpdi"
10847   [(set (cc0)
10848         (compare (match_operand:DI 0 "gpc_reg_operand" "")
10849                  (match_operand:DI 1 "reg_or_short_operand" "")))]
10850   "TARGET_POWERPC64"
10851   "
10852 {
10853   /* Take care of the possibility that operands[1] might be negative but
10854      this might be a logical operation.  That insn doesn't exist.  */
10855   if (GET_CODE (operands[1]) == CONST_INT
10856       && INTVAL (operands[1]) < 0)
10857     operands[1] = force_reg (DImode, operands[1]);
10858
10859   rs6000_compare_op0 = operands[0];
10860   rs6000_compare_op1 = operands[1];
10861   rs6000_compare_fp_p = 0;
10862   DONE;
10863 }")
10864
10865 (define_expand "cmpsf"
10866   [(set (cc0) (compare (match_operand:SF 0 "gpc_reg_operand" "")
10867                        (match_operand:SF 1 "gpc_reg_operand" "")))]
10868   "TARGET_HARD_FLOAT"
10869   "
10870 {
10871   rs6000_compare_op0 = operands[0];
10872   rs6000_compare_op1 = operands[1];
10873   rs6000_compare_fp_p = 1;
10874   DONE;
10875 }")
10876
10877 (define_expand "cmpdf"
10878   [(set (cc0) (compare (match_operand:DF 0 "gpc_reg_operand" "")
10879                        (match_operand:DF 1 "gpc_reg_operand" "")))]
10880   "TARGET_HARD_FLOAT && TARGET_FPRS"
10881   "
10882 {
10883   rs6000_compare_op0 = operands[0];
10884   rs6000_compare_op1 = operands[1];
10885   rs6000_compare_fp_p = 1;
10886   DONE;
10887 }")
10888
10889 (define_expand "cmptf"
10890   [(set (cc0) (compare (match_operand:TF 0 "gpc_reg_operand" "")
10891                        (match_operand:TF 1 "gpc_reg_operand" "")))]
10892   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
10893    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
10894   "
10895 {
10896   rs6000_compare_op0 = operands[0];
10897   rs6000_compare_op1 = operands[1];
10898   rs6000_compare_fp_p = 1;
10899   DONE;
10900 }")
10901
10902 (define_expand "beq"
10903   [(use (match_operand 0 "" ""))]
10904   ""
10905   "{ rs6000_emit_cbranch (EQ, operands[0]); DONE; }")
10906
10907 (define_expand "bne"
10908   [(use (match_operand 0 "" ""))]
10909   ""
10910   "{ rs6000_emit_cbranch (NE, operands[0]); DONE; }")
10911
10912 (define_expand "bge"
10913   [(use (match_operand 0 "" ""))]
10914   ""
10915   "{ rs6000_emit_cbranch (GE, operands[0]); DONE; }")
10916
10917 (define_expand "bgt"
10918   [(use (match_operand 0 "" ""))]
10919   ""
10920   "{ rs6000_emit_cbranch (GT, operands[0]); DONE; }")
10921
10922 (define_expand "ble"
10923   [(use (match_operand 0 "" ""))]
10924   ""
10925   "{ rs6000_emit_cbranch (LE, operands[0]); DONE; }")
10926
10927 (define_expand "blt"
10928   [(use (match_operand 0 "" ""))]
10929   ""
10930   "{ rs6000_emit_cbranch (LT, operands[0]); DONE; }")
10931
10932 (define_expand "bgeu"
10933   [(use (match_operand 0 "" ""))]
10934   ""
10935   "{ rs6000_emit_cbranch (GEU, operands[0]); DONE; }")
10936
10937 (define_expand "bgtu"
10938   [(use (match_operand 0 "" ""))]
10939   ""
10940   "{ rs6000_emit_cbranch (GTU, operands[0]); DONE; }")
10941
10942 (define_expand "bleu"
10943   [(use (match_operand 0 "" ""))]
10944   ""
10945   "{ rs6000_emit_cbranch (LEU, operands[0]); DONE; }")
10946
10947 (define_expand "bltu"
10948   [(use (match_operand 0 "" ""))]
10949   ""
10950   "{ rs6000_emit_cbranch (LTU, operands[0]); DONE; }")
10951
10952 (define_expand "bunordered"
10953   [(use (match_operand 0 "" ""))]
10954   ""
10955   "{ rs6000_emit_cbranch (UNORDERED, operands[0]); DONE; }")
10956
10957 (define_expand "bordered"
10958   [(use (match_operand 0 "" ""))]
10959   ""
10960   "{ rs6000_emit_cbranch (ORDERED, operands[0]); DONE; }")
10961
10962 (define_expand "buneq"
10963   [(use (match_operand 0 "" ""))]
10964   ""
10965   "{ rs6000_emit_cbranch (UNEQ, operands[0]); DONE; }")
10966
10967 (define_expand "bunge"
10968   [(use (match_operand 0 "" ""))]
10969   ""
10970   "{ rs6000_emit_cbranch (UNGE, operands[0]); DONE; }")
10971
10972 (define_expand "bungt"
10973   [(use (match_operand 0 "" ""))]
10974   ""
10975   "{ rs6000_emit_cbranch (UNGT, operands[0]); DONE; }")
10976
10977 (define_expand "bunle"
10978   [(use (match_operand 0 "" ""))]
10979   ""
10980   "{ rs6000_emit_cbranch (UNLE, operands[0]); DONE; }")
10981
10982 (define_expand "bunlt"
10983   [(use (match_operand 0 "" ""))]
10984   ""
10985   "{ rs6000_emit_cbranch (UNLT, operands[0]); DONE; }")
10986
10987 (define_expand "bltgt"
10988   [(use (match_operand 0 "" ""))]
10989   ""
10990   "{ rs6000_emit_cbranch (LTGT, operands[0]); DONE; }")
10991
10992 ;; For SNE, we would prefer that the xor/abs sequence be used for integers.
10993 ;; For SEQ, likewise, except that comparisons with zero should be done
10994 ;; with an scc insns.  However, due to the order that combine see the
10995 ;; resulting insns, we must, in fact, allow SEQ for integers.  Fail in
10996 ;; the cases we don't want to handle.
10997 (define_expand "seq"
10998   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10999   ""
11000   "{ rs6000_emit_sCOND (EQ, operands[0]); DONE; }")
11001
11002 (define_expand "sne"
11003   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11004   ""
11005   "
11006
11007   if (! rs6000_compare_fp_p)
11008     FAIL;
11009
11010   rs6000_emit_sCOND (NE, operands[0]); 
11011   DONE;
11012 }")
11013
11014 ;; A >= 0 is best done the portable way for A an integer.
11015 (define_expand "sge"
11016   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11017   ""
11018   "
11019 {
11020   if (! rs6000_compare_fp_p
11021       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
11022     FAIL;
11023
11024   rs6000_emit_sCOND (GE, operands[0]);
11025   DONE;
11026 }")
11027
11028 ;; A > 0 is best done using the portable sequence, so fail in that case.
11029 (define_expand "sgt"
11030   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11031   ""
11032   "
11033 {
11034   if (! rs6000_compare_fp_p
11035       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
11036     FAIL;
11037
11038   rs6000_emit_sCOND (GT, operands[0]); 
11039   DONE;
11040 }")
11041
11042 ;; A <= 0 is best done the portable way for A an integer.
11043 (define_expand "sle"
11044   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11045   ""
11046   "
11047 {
11048   if (! rs6000_compare_fp_p
11049       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
11050     FAIL;
11051
11052   rs6000_emit_sCOND (LE, operands[0]); 
11053   DONE;
11054 }")
11055
11056 ;; A < 0 is best done in the portable way for A an integer.
11057 (define_expand "slt"
11058   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11059   ""
11060   "
11061 {
11062   if (! rs6000_compare_fp_p 
11063       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
11064     FAIL;
11065
11066   rs6000_emit_sCOND (LT, operands[0]); 
11067   DONE;
11068 }")
11069
11070 (define_expand "sgeu"
11071   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11072   ""
11073   "{ rs6000_emit_sCOND (GEU, operands[0]); DONE; }")
11074
11075 (define_expand "sgtu"
11076   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11077   ""
11078   "{ rs6000_emit_sCOND (GTU, operands[0]); DONE; }")
11079
11080 (define_expand "sleu"
11081   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11082   ""
11083   "{ rs6000_emit_sCOND (LEU, operands[0]); DONE; }")
11084
11085 (define_expand "sltu"
11086   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11087   ""
11088   "{ rs6000_emit_sCOND (LTU, operands[0]); DONE; }")
11089
11090 (define_expand "sunordered"
11091   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11092   ""
11093   "{ rs6000_emit_sCOND (UNORDERED, operands[0]); DONE; }")
11094
11095 (define_expand "sordered"
11096   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11097   ""
11098   "{ rs6000_emit_sCOND (ORDERED, operands[0]); DONE; }")
11099
11100 (define_expand "suneq"
11101   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11102   ""
11103   "{ rs6000_emit_sCOND (UNEQ, operands[0]); DONE; }")
11104
11105 (define_expand "sunge"
11106   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11107   ""
11108   "{ rs6000_emit_sCOND (UNGE, operands[0]); DONE; }")
11109
11110 (define_expand "sungt"
11111   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11112   ""
11113   "{ rs6000_emit_sCOND (UNGT, operands[0]); DONE; }")
11114
11115 (define_expand "sunle"
11116   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11117   ""
11118   "{ rs6000_emit_sCOND (UNLE, operands[0]); DONE; }")
11119
11120 (define_expand "sunlt"
11121   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11122   ""
11123   "{ rs6000_emit_sCOND (UNLT, operands[0]); DONE; }")
11124
11125 (define_expand "sltgt"
11126   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11127   ""
11128   "{ rs6000_emit_sCOND (LTGT, operands[0]); DONE; }")
11129
11130 \f
11131 ;; Here are the actual compare insns.
11132 (define_insn "*cmpsi_internal1"
11133   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11134         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11135                     (match_operand:SI 2 "reg_or_short_operand" "rI")))]
11136   ""
11137   "{cmp%I2|cmpw%I2} %0,%1,%2"
11138   [(set_attr "type" "cmp")])
11139
11140 (define_insn "*cmpdi_internal1"
11141   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11142         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "r")
11143                     (match_operand:DI 2 "reg_or_short_operand" "rI")))]
11144   "TARGET_POWERPC64"
11145   "cmpd%I2 %0,%1,%2"
11146   [(set_attr "type" "cmp")])
11147
11148 ;; If we are comparing a register for equality with a large constant,
11149 ;; we can do this with an XOR followed by a compare.  But we need a scratch
11150 ;; register for the result of the XOR.
11151
11152 (define_split
11153   [(set (match_operand:CC 0 "cc_reg_operand" "")
11154         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11155                     (match_operand:SI 2 "non_short_cint_operand" "")))
11156    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
11157   "find_single_use (operands[0], insn, 0)
11158    && (GET_CODE (*find_single_use (operands[0], insn, 0)) == EQ
11159        || GET_CODE (*find_single_use (operands[0], insn, 0)) == NE)"
11160   [(set (match_dup 3) (xor:SI (match_dup 1) (match_dup 4)))
11161    (set (match_dup 0) (compare:CC (match_dup 3) (match_dup 5)))]
11162   "
11163 {
11164   /* Get the constant we are comparing against, C,  and see what it looks like
11165      sign-extended to 16 bits.  Then see what constant could be XOR'ed
11166      with C to get the sign-extended value.  */
11167
11168   HOST_WIDE_INT c = INTVAL (operands[2]);
11169   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
11170   HOST_WIDE_INT xorv = c ^ sextc;
11171
11172   operands[4] = GEN_INT (xorv);
11173   operands[5] = GEN_INT (sextc);
11174 }")
11175
11176 (define_insn "*cmpsi_internal2"
11177   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11178         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11179                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
11180   ""
11181   "{cmpl%I2|cmplw%I2} %0,%1,%b2"
11182   [(set_attr "type" "cmp")])
11183
11184 (define_insn "*cmpdi_internal2"
11185   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11186         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
11187                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
11188   ""
11189   "cmpld%I2 %0,%1,%b2"
11190   [(set_attr "type" "cmp")])
11191
11192 ;; The following two insns don't exist as single insns, but if we provide
11193 ;; them, we can swap an add and compare, which will enable us to overlap more
11194 ;; of the required delay between a compare and branch.  We generate code for
11195 ;; them by splitting.
11196
11197 (define_insn ""
11198   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
11199         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11200                     (match_operand:SI 2 "short_cint_operand" "i")))
11201    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11202         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11203   ""
11204   "#"
11205   [(set_attr "length" "8")])
11206
11207 (define_insn ""
11208   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
11209         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11210                        (match_operand:SI 2 "u_short_cint_operand" "i")))
11211    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11212         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11213   ""
11214   "#"
11215   [(set_attr "length" "8")])
11216
11217 (define_split
11218   [(set (match_operand:CC 3 "cc_reg_operand" "")
11219         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11220                     (match_operand:SI 2 "short_cint_operand" "")))
11221    (set (match_operand:SI 0 "gpc_reg_operand" "")
11222         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11223   ""
11224   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
11225    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11226
11227 (define_split
11228   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
11229         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
11230                        (match_operand:SI 2 "u_short_cint_operand" "")))
11231    (set (match_operand:SI 0 "gpc_reg_operand" "")
11232         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11233   ""
11234   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
11235    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11236
11237 (define_insn "*cmpsf_internal1"
11238   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11239         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
11240                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
11241   "TARGET_HARD_FLOAT && TARGET_FPRS"
11242   "fcmpu %0,%1,%2"
11243   [(set_attr "type" "fpcompare")])
11244
11245 (define_insn "*cmpdf_internal1"
11246   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11247         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "f")
11248                       (match_operand:DF 2 "gpc_reg_operand" "f")))]
11249   "TARGET_HARD_FLOAT && TARGET_FPRS"
11250   "fcmpu %0,%1,%2"
11251   [(set_attr "type" "fpcompare")])
11252
11253 ;; Only need to compare second words if first words equal
11254 (define_insn "*cmptf_internal1"
11255   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11256         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11257                       (match_operand:TF 2 "gpc_reg_operand" "f")))]
11258   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
11259    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
11260   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
11261   [(set_attr "type" "fpcompare")
11262    (set_attr "length" "12")])
11263 \f
11264 ;; Now we have the scc insns.  We can do some combinations because of the
11265 ;; way the machine works.
11266 ;;
11267 ;; Note that this is probably faster if we can put an insn between the
11268 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
11269 ;; cases the insns below which don't use an intermediate CR field will
11270 ;; be used instead.
11271 (define_insn ""
11272   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11273         (match_operator:SI 1 "scc_comparison_operator"
11274                            [(match_operand 2 "cc_reg_operand" "y")
11275                             (const_int 0)]))]
11276   ""
11277   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11278   [(set (attr "type")
11279      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11280                 (const_string "mfcrf")
11281            ]
11282         (const_string "mfcr")))
11283    (set_attr "length" "12")])
11284
11285 ;; Same as above, but get the OV/ORDERED bit.
11286 (define_insn "move_from_CR_ov_bit"
11287   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11288         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_OV))]
11289   "TARGET_ISEL"
11290   "mfcr %0\;{rlinm|rlwinm} %0,%0,%t1,1"
11291   [(set_attr "type" "mfcr")
11292    (set_attr "length" "12")])
11293
11294 (define_insn ""
11295   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11296         (match_operator:DI 1 "scc_comparison_operator"
11297                            [(match_operand 2 "cc_reg_operand" "y")
11298                             (const_int 0)]))]
11299   "TARGET_POWERPC64"
11300   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11301   [(set (attr "type")
11302      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11303                 (const_string "mfcrf")
11304            ]
11305         (const_string "mfcr")))
11306    (set_attr "length" "12")])
11307
11308 (define_insn ""
11309   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11310         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11311                                        [(match_operand 2 "cc_reg_operand" "y,y")
11312                                         (const_int 0)])
11313                     (const_int 0)))
11314    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11315         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11316   "TARGET_32BIT"
11317   "@
11318    mfcr %3%Q2\;{rlinm.|rlwinm.} %3,%3,%J1,1
11319    #"
11320   [(set_attr "type" "delayed_compare")
11321    (set_attr "length" "12,16")])
11322
11323 (define_split
11324   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11325         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11326                                        [(match_operand 2 "cc_reg_operand" "")
11327                                         (const_int 0)])
11328                     (const_int 0)))
11329    (set (match_operand:SI 3 "gpc_reg_operand" "")
11330         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11331   "TARGET_32BIT && reload_completed"
11332   [(set (match_dup 3)
11333         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
11334    (set (match_dup 0)
11335         (compare:CC (match_dup 3)
11336                     (const_int 0)))]
11337   "")
11338
11339 (define_insn ""
11340   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11341         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11342                                       [(match_operand 2 "cc_reg_operand" "y")
11343                                        (const_int 0)])
11344                    (match_operand:SI 3 "const_int_operand" "n")))]
11345   ""
11346   "*
11347 {
11348   int is_bit = ccr_bit (operands[1], 1);
11349   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11350   int count;
11351
11352   if (is_bit >= put_bit)
11353     count = is_bit - put_bit;
11354   else
11355     count = 32 - (put_bit - is_bit);
11356
11357   operands[4] = GEN_INT (count);
11358   operands[5] = GEN_INT (put_bit);
11359
11360   return \"mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
11361 }"
11362   [(set (attr "type")
11363      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11364                 (const_string "mfcrf")
11365            ]
11366         (const_string "mfcr")))
11367    (set_attr "length" "12")])
11368
11369 (define_insn ""
11370   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11371         (compare:CC
11372          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11373                                        [(match_operand 2 "cc_reg_operand" "y,y")
11374                                         (const_int 0)])
11375                     (match_operand:SI 3 "const_int_operand" "n,n"))
11376          (const_int 0)))
11377    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
11378         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11379                    (match_dup 3)))]
11380   ""
11381   "*
11382 {
11383   int is_bit = ccr_bit (operands[1], 1);
11384   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11385   int count;
11386
11387   /* Force split for non-cc0 compare.  */
11388   if (which_alternative == 1)
11389      return \"#\";
11390
11391   if (is_bit >= put_bit)
11392     count = is_bit - put_bit;
11393   else
11394     count = 32 - (put_bit - is_bit);
11395
11396   operands[5] = GEN_INT (count);
11397   operands[6] = GEN_INT (put_bit);
11398
11399   return \"mfcr %4%Q2\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
11400 }"
11401   [(set_attr "type" "delayed_compare")
11402    (set_attr "length" "12,16")])
11403
11404 (define_split
11405   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11406         (compare:CC
11407          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11408                                        [(match_operand 2 "cc_reg_operand" "")
11409                                         (const_int 0)])
11410                     (match_operand:SI 3 "const_int_operand" ""))
11411          (const_int 0)))
11412    (set (match_operand:SI 4 "gpc_reg_operand" "")
11413         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11414                    (match_dup 3)))]
11415   "reload_completed"
11416   [(set (match_dup 4)
11417         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11418                    (match_dup 3)))
11419    (set (match_dup 0)
11420         (compare:CC (match_dup 4)
11421                     (const_int 0)))]
11422   "")
11423
11424 ;; There is a 3 cycle delay between consecutive mfcr instructions
11425 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
11426
11427 (define_peephole
11428   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11429         (match_operator:SI 1 "scc_comparison_operator"
11430                            [(match_operand 2 "cc_reg_operand" "y")
11431                             (const_int 0)]))
11432    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
11433         (match_operator:SI 4 "scc_comparison_operator"
11434                            [(match_operand 5 "cc_reg_operand" "y")
11435                             (const_int 0)]))]
11436   "REGNO (operands[2]) != REGNO (operands[5])"
11437   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11438   [(set_attr "type" "mfcr")
11439    (set_attr "length" "20")])
11440
11441 (define_peephole
11442   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11443         (match_operator:DI 1 "scc_comparison_operator"
11444                            [(match_operand 2 "cc_reg_operand" "y")
11445                             (const_int 0)]))
11446    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
11447         (match_operator:DI 4 "scc_comparison_operator"
11448                            [(match_operand 5 "cc_reg_operand" "y")
11449                             (const_int 0)]))]
11450   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
11451   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11452   [(set_attr "type" "mfcr")
11453    (set_attr "length" "20")])
11454
11455 ;; There are some scc insns that can be done directly, without a compare.
11456 ;; These are faster because they don't involve the communications between
11457 ;; the FXU and branch units.   In fact, we will be replacing all of the
11458 ;; integer scc insns here or in the portable methods in emit_store_flag.
11459 ;;
11460 ;; Also support (neg (scc ..)) since that construct is used to replace
11461 ;; branches, (plus (scc ..) ..) since that construct is common and
11462 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
11463 ;; cases where it is no more expensive than (neg (scc ..)).
11464
11465 ;; Have reload force a constant into a register for the simple insns that
11466 ;; otherwise won't accept constants.  We do this because it is faster than
11467 ;; the cmp/mfcr sequence we would otherwise generate.
11468
11469 (define_insn ""
11470   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
11471         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11472                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I")))
11473    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
11474   "TARGET_32BIT"
11475   "@
11476    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11477    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
11478    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11479    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11480    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
11481   [(set_attr "length" "12,8,12,12,12")])
11482
11483 (define_insn ""
11484   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r")
11485         (eq:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r")
11486                (match_operand:DI 2 "reg_or_cint_operand" "r,O,K,J,I")))
11487    (clobber (match_scratch:DI 3 "=r,&r,r,r,r"))]
11488   "TARGET_64BIT"
11489   "@
11490    xor %0,%1,%2\;subfic %3,%0,0\;adde %0,%3,%0
11491    subfic %3,%1,0\;adde %0,%3,%1
11492    xori %0,%1,%b2\;subfic %3,%0,0\;adde %0,%3,%0
11493    xoris %0,%1,%u2\;subfic %3,%0,0\;adde %0,%3,%0
11494    subfic %0,%1,%2\;subfic %3,%0,0\;adde %0,%3,%0"
11495   [(set_attr "length" "12,8,12,12,12")])
11496
11497 (define_insn ""
11498   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11499         (compare:CC
11500          (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11501                 (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11502          (const_int 0)))
11503    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
11504         (eq:SI (match_dup 1) (match_dup 2)))
11505    (clobber (match_scratch:SI 3 "=r,&r,r,r,r,r,&r,r,r,r"))]
11506   "TARGET_32BIT"
11507   "@
11508    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11509    {sfi|subfic} %3,%1,0\;{ae.|adde.} %0,%3,%1
11510    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11511    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11512    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11513    #
11514    #
11515    #
11516    #
11517    #"
11518   [(set_attr "type" "compare")
11519    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11520
11521 (define_split
11522   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11523         (compare:CC
11524          (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11525                 (match_operand:SI 2 "reg_or_cint_operand" ""))
11526          (const_int 0)))
11527    (set (match_operand:SI 0 "gpc_reg_operand" "")
11528         (eq:SI (match_dup 1) (match_dup 2)))
11529    (clobber (match_scratch:SI 3 ""))]
11530   "TARGET_32BIT && reload_completed"
11531   [(parallel [(set (match_dup 0)
11532         (eq:SI (match_dup 1) (match_dup 2)))
11533    (clobber (match_dup 3))])
11534    (set (match_dup 4)
11535         (compare:CC (match_dup 0)
11536                     (const_int 0)))]
11537   "")
11538
11539 (define_insn ""
11540   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11541         (compare:CC
11542          (eq:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11543                 (match_operand:DI 2 "reg_or_cint_operand" "r,O,K,J,I,r,O,K,J,I"))
11544          (const_int 0)))
11545    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
11546         (eq:DI (match_dup 1) (match_dup 2)))
11547    (clobber (match_scratch:DI 3 "=r,&r,r,r,r,r,&r,r,r,r"))]
11548   "TARGET_64BIT"
11549   "@
11550    xor %0,%1,%2\;subfic %3,%0,0\;adde. %0,%3,%0
11551    subfic %3,%1,0\;adde. %0,%3,%1
11552    xori %0,%1,%b2\;subfic %3,%0,0\;adde. %0,%3,%0
11553    xoris %0,%1,%u2\;subfic %3,%0,0\;adde. %0,%3,%0
11554    subfic %0,%1,%2\;subfic %3,%0,0\;adde. %0,%3,%0
11555    #
11556    #
11557    #
11558    #
11559    #"
11560   [(set_attr "type" "compare")
11561    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11562
11563 (define_split
11564   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11565         (compare:CC
11566          (eq:DI (match_operand:DI 1 "gpc_reg_operand" "")
11567                 (match_operand:DI 2 "reg_or_cint_operand" ""))
11568          (const_int 0)))
11569    (set (match_operand:DI 0 "gpc_reg_operand" "")
11570         (eq:DI (match_dup 1) (match_dup 2)))
11571    (clobber (match_scratch:DI 3 ""))]
11572   "TARGET_64BIT && reload_completed"
11573   [(parallel [(set (match_dup 0)
11574         (eq:DI (match_dup 1) (match_dup 2)))
11575    (clobber (match_dup 3))])
11576    (set (match_dup 4)
11577         (compare:CC (match_dup 0)
11578                     (const_int 0)))]
11579   "")
11580
11581 ;; We have insns of the form shown by the first define_insn below.  If
11582 ;; there is something inside the comparison operation, we must split it.
11583 (define_split
11584   [(set (match_operand:SI 0 "gpc_reg_operand" "")
11585         (plus:SI (match_operator 1 "comparison_operator"
11586                                  [(match_operand:SI 2 "" "")
11587                                   (match_operand:SI 3
11588                                                     "reg_or_cint_operand" "")])
11589                  (match_operand:SI 4 "gpc_reg_operand" "")))
11590    (clobber (match_operand:SI 5 "register_operand" ""))]
11591   "! gpc_reg_operand (operands[2], SImode)"
11592   [(set (match_dup 5) (match_dup 2))
11593    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
11594                                (match_dup 4)))])
11595
11596 (define_insn ""
11597   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
11598         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11599                         (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I"))
11600                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
11601   "TARGET_32BIT"
11602   "@
11603    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11604    {sfi|subfic} %0,%1,0\;{aze|addze} %0,%3
11605    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11606    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11607    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
11608   [(set_attr "length" "12,8,12,12,12")])
11609
11610 (define_insn ""
11611   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11612         (compare:CC
11613          (plus:SI
11614           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11615                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11616           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11617          (const_int 0)))
11618    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
11619   "TARGET_32BIT"
11620   "@
11621    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11622    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
11623    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11624    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11625    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11626    #
11627    #
11628    #
11629    #
11630    #"
11631   [(set_attr "type" "compare")
11632    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11633
11634 (define_split
11635   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11636         (compare:CC
11637          (plus:SI
11638           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11639                  (match_operand:SI 2 "reg_or_cint_operand" ""))
11640           (match_operand:SI 3 "gpc_reg_operand" ""))
11641          (const_int 0)))
11642    (clobber (match_scratch:SI 4 ""))]
11643   "TARGET_32BIT && reload_completed"
11644   [(set (match_dup 4)
11645         (plus:SI (eq:SI (match_dup 1)
11646                  (match_dup 2))
11647           (match_dup 3)))
11648    (set (match_dup 0)
11649         (compare:CC (match_dup 4)
11650                     (const_int 0)))]
11651   "")
11652
11653 (define_insn ""
11654   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11655         (compare:CC
11656          (plus:SI
11657           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11658                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11659           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11660          (const_int 0)))
11661    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
11662         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11663   "TARGET_32BIT"
11664   "@
11665    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11666    {sfi|subfic} %0,%1,0\;{aze.|addze.} %0,%3
11667    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11668    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11669    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11670    #
11671    #
11672    #
11673    #
11674    #"
11675   [(set_attr "type" "compare")
11676    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11677
11678 (define_split
11679   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11680         (compare:CC
11681          (plus:SI
11682           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11683                  (match_operand:SI 2 "reg_or_cint_operand" ""))
11684           (match_operand:SI 3 "gpc_reg_operand" ""))
11685          (const_int 0)))
11686    (set (match_operand:SI 0 "gpc_reg_operand" "")
11687         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11688   "TARGET_32BIT && reload_completed"
11689   [(set (match_dup 0)
11690         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
11691    (set (match_dup 4)
11692         (compare:CC (match_dup 0)
11693                     (const_int 0)))]
11694   "")
11695
11696 (define_insn ""
11697   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
11698         (neg:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11699                        (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I"))))]
11700   "TARGET_32BIT"
11701   "@
11702    xor %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11703    {ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0
11704    {xoril|xori} %0,%1,%b2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11705    {xoriu|xoris} %0,%1,%u2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11706    {sfi|subfic} %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
11707    [(set_attr "length" "12,8,12,12,12")])
11708
11709 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
11710 ;; since it nabs/sr is just as fast.
11711 (define_insn "*ne0"
11712   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
11713         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
11714                      (const_int 31)))
11715    (clobber (match_scratch:SI 2 "=&r"))]
11716   "! TARGET_POWER && TARGET_32BIT && !TARGET_ISEL"
11717   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
11718   [(set_attr "length" "8")])
11719
11720 (define_insn ""
11721   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11722         (lshiftrt:DI (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
11723                      (const_int 63)))
11724    (clobber (match_scratch:DI 2 "=&r"))]
11725   "TARGET_64BIT"
11726   "addic %2,%1,-1\;subfe %0,%2,%1"
11727   [(set_attr "length" "8")])
11728
11729 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
11730 (define_insn ""
11731   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11732         (plus:SI (lshiftrt:SI
11733                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
11734                   (const_int 31))
11735                  (match_operand:SI 2 "gpc_reg_operand" "r")))
11736    (clobber (match_scratch:SI 3 "=&r"))]
11737   "TARGET_32BIT"
11738   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
11739   [(set_attr "length" "8")])
11740
11741 (define_insn ""
11742   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11743         (plus:DI (lshiftrt:DI
11744                   (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
11745                   (const_int 63))
11746                  (match_operand:DI 2 "gpc_reg_operand" "r")))
11747    (clobber (match_scratch:DI 3 "=&r"))]
11748   "TARGET_64BIT"
11749   "addic %3,%1,-1\;addze %0,%2"
11750   [(set_attr "length" "8")])
11751
11752 (define_insn ""
11753   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11754         (compare:CC
11755          (plus:SI (lshiftrt:SI
11756                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
11757                    (const_int 31))
11758                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
11759          (const_int 0)))
11760    (clobber (match_scratch:SI 3 "=&r,&r"))
11761    (clobber (match_scratch:SI 4 "=X,&r"))]
11762   "TARGET_32BIT"
11763   "@
11764    {ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2
11765    #"
11766   [(set_attr "type" "compare")
11767    (set_attr "length" "8,12")])
11768
11769 (define_split
11770   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11771         (compare:CC
11772          (plus:SI (lshiftrt:SI
11773                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11774                    (const_int 31))
11775                   (match_operand:SI 2 "gpc_reg_operand" ""))
11776          (const_int 0)))
11777    (clobber (match_scratch:SI 3 ""))
11778    (clobber (match_scratch:SI 4 ""))]
11779   "TARGET_32BIT && reload_completed"
11780   [(parallel [(set (match_dup 3)
11781                    (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1)))
11782                                          (const_int 31))
11783                             (match_dup 2)))
11784               (clobber (match_dup 4))])
11785    (set (match_dup 0)
11786         (compare:CC (match_dup 3)
11787                     (const_int 0)))]
11788   "")
11789
11790 (define_insn ""
11791   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11792         (compare:CC
11793          (plus:DI (lshiftrt:DI
11794                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
11795                    (const_int 63))
11796                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
11797          (const_int 0)))
11798    (clobber (match_scratch:DI 3 "=&r,&r"))]
11799   "TARGET_64BIT"
11800   "@
11801    addic %3,%1,-1\;addze. %3,%2
11802    #"
11803   [(set_attr "type" "compare")
11804    (set_attr "length" "8,12")])
11805
11806 (define_split
11807   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11808         (compare:CC
11809          (plus:DI (lshiftrt:DI
11810                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
11811                    (const_int 63))
11812                   (match_operand:DI 2 "gpc_reg_operand" ""))
11813          (const_int 0)))
11814    (clobber (match_scratch:DI 3 ""))]
11815   "TARGET_64BIT && reload_completed"
11816   [(set (match_dup 3)
11817         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1)))
11818                    (const_int 63))
11819                   (match_dup 2)))
11820    (set (match_dup 0)
11821         (compare:CC (match_dup 3)
11822                     (const_int 0)))]
11823   "")
11824
11825 (define_insn ""
11826   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
11827         (compare:CC
11828          (plus:SI (lshiftrt:SI
11829                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
11830                    (const_int 31))
11831                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
11832          (const_int 0)))
11833    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11834         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11835                  (match_dup 2)))
11836    (clobber (match_scratch:SI 3 "=&r,&r"))]
11837   "TARGET_32BIT"
11838   "@
11839    {ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2
11840    #"
11841   [(set_attr "type" "compare")
11842    (set_attr "length" "8,12")])
11843
11844 (define_split
11845   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11846         (compare:CC
11847          (plus:SI (lshiftrt:SI
11848                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11849                    (const_int 31))
11850                   (match_operand:SI 2 "gpc_reg_operand" ""))
11851          (const_int 0)))
11852    (set (match_operand:SI 0 "gpc_reg_operand" "")
11853         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11854                  (match_dup 2)))
11855    (clobber (match_scratch:SI 3 ""))]
11856   "TARGET_32BIT && reload_completed"
11857   [(parallel [(set (match_dup 0)
11858         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11859                  (match_dup 2)))
11860    (clobber (match_dup 3))])
11861    (set (match_dup 4)
11862         (compare:CC (match_dup 0)
11863                     (const_int 0)))]
11864   "")
11865
11866 (define_insn ""
11867   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
11868         (compare:CC
11869          (plus:DI (lshiftrt:DI
11870                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
11871                    (const_int 63))
11872                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
11873          (const_int 0)))
11874    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
11875         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11876                  (match_dup 2)))
11877    (clobber (match_scratch:DI 3 "=&r,&r"))]
11878   "TARGET_64BIT"
11879   "@
11880    addic %3,%1,-1\;addze. %0,%2
11881    #"
11882   [(set_attr "type" "compare")
11883    (set_attr "length" "8,12")])
11884
11885 (define_split
11886   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11887         (compare:CC
11888          (plus:DI (lshiftrt:DI
11889                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
11890                    (const_int 63))
11891                   (match_operand:DI 2 "gpc_reg_operand" ""))
11892          (const_int 0)))
11893    (set (match_operand:DI 0 "gpc_reg_operand" "")
11894         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11895                  (match_dup 2)))
11896    (clobber (match_scratch:DI 3 ""))]
11897   "TARGET_64BIT && reload_completed"
11898   [(parallel [(set (match_dup 0)
11899         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11900                  (match_dup 2)))
11901    (clobber (match_dup 3))])
11902    (set (match_dup 4)
11903         (compare:CC (match_dup 0)
11904                     (const_int 0)))]
11905   "")
11906
11907 (define_insn ""
11908   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11909         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
11910                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
11911    (clobber (match_scratch:SI 3 "=r,X"))]
11912   "TARGET_POWER"
11913   "@
11914    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
11915    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
11916   [(set_attr "length" "12")])
11917
11918 (define_insn ""
11919   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
11920         (compare:CC
11921          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
11922                 (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
11923          (const_int 0)))
11924    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
11925         (le:SI (match_dup 1) (match_dup 2)))
11926    (clobber (match_scratch:SI 3 "=r,X,r,X"))]
11927   "TARGET_POWER"
11928   "@
11929    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
11930    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31
11931    #
11932    #"
11933   [(set_attr "type" "compare,delayed_compare,compare,delayed_compare")
11934    (set_attr "length" "12,12,16,16")])
11935
11936 (define_split
11937   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11938         (compare:CC
11939          (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
11940                 (match_operand:SI 2 "reg_or_short_operand" ""))
11941          (const_int 0)))
11942    (set (match_operand:SI 0 "gpc_reg_operand" "")
11943         (le:SI (match_dup 1) (match_dup 2)))
11944    (clobber (match_scratch:SI 3 ""))]
11945   "TARGET_POWER && reload_completed"
11946   [(parallel [(set (match_dup 0)
11947         (le:SI (match_dup 1) (match_dup 2)))
11948    (clobber (match_dup 3))])
11949    (set (match_dup 4)
11950         (compare:CC (match_dup 0)
11951                     (const_int 0)))]
11952   "")
11953
11954 (define_insn ""
11955   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
11956         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
11957                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
11958                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
11959   "TARGET_POWER"
11960   "@
11961    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11962    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze|addze} %0,%3"
11963   [(set_attr "length" "12")])
11964
11965 (define_insn ""
11966   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
11967         (compare:CC
11968          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
11969                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
11970                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
11971          (const_int 0)))
11972    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
11973   "TARGET_POWER"
11974   "@
11975    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11976    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3
11977    #
11978    #"
11979   [(set_attr "type" "compare")
11980    (set_attr "length" "12,12,16,16")])
11981
11982 (define_split
11983   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11984         (compare:CC
11985          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
11986                          (match_operand:SI 2 "reg_or_short_operand" ""))
11987                   (match_operand:SI 3 "gpc_reg_operand" ""))
11988          (const_int 0)))
11989    (clobber (match_scratch:SI 4 ""))]
11990   "TARGET_POWER && reload_completed"
11991   [(set (match_dup 4)
11992         (plus:SI (le:SI (match_dup 1) (match_dup 2))
11993                  (match_dup 3)))
11994    (set (match_dup 0)
11995         (compare:CC (match_dup 4)
11996                     (const_int 0)))]
11997   "")
11998
11999 (define_insn ""
12000   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12001         (compare:CC
12002          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12003                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12004                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12005          (const_int 0)))
12006    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12007         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12008   "TARGET_POWER"
12009   "@
12010    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12011    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze.|addze.} %0,%3
12012    #
12013    #"
12014   [(set_attr "type" "compare")
12015    (set_attr "length" "12,12,16,16")])
12016
12017 (define_split
12018   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12019         (compare:CC
12020          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12021                          (match_operand:SI 2 "reg_or_short_operand" ""))
12022                   (match_operand:SI 3 "gpc_reg_operand" ""))
12023          (const_int 0)))
12024    (set (match_operand:SI 0 "gpc_reg_operand" "")
12025         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12026   "TARGET_POWER && reload_completed"
12027   [(set (match_dup 0)
12028         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12029    (set (match_dup 4)
12030         (compare:CC (match_dup 0)
12031                     (const_int 0)))]
12032   "")
12033
12034 (define_insn ""
12035   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12036         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12037                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
12038   "TARGET_POWER"
12039   "@
12040    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
12041    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
12042   [(set_attr "length" "12")])
12043
12044 (define_insn ""
12045   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12046         (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12047                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12048   "TARGET_32BIT"
12049   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12050   [(set_attr "length" "12")])
12051
12052 (define_insn ""
12053   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12054         (leu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
12055                 (match_operand:DI 2 "reg_or_short_operand" "rI")))]
12056   "TARGET_64BIT"
12057   "subf%I2c %0,%1,%2\;li %0,0\;adde %0,%0,%0"
12058   [(set_attr "length" "12")])
12059
12060 (define_insn ""
12061   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12062         (compare:CC
12063          (leu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12064                  (match_operand:DI 2 "reg_or_short_operand" "rI,rI"))
12065          (const_int 0)))
12066    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12067         (leu:DI (match_dup 1) (match_dup 2)))]
12068   "TARGET_64BIT"
12069   "@
12070    subf%I2c %0,%1,%2\;li %0,0\;adde. %0,%0,%0
12071    #"
12072   [(set_attr "type" "compare")
12073    (set_attr "length" "12,16")])
12074
12075 (define_split
12076   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12077         (compare:CC
12078          (leu:DI (match_operand:DI 1 "gpc_reg_operand" "")
12079                  (match_operand:DI 2 "reg_or_short_operand" ""))
12080          (const_int 0)))
12081    (set (match_operand:DI 0 "gpc_reg_operand" "")
12082         (leu:DI (match_dup 1) (match_dup 2)))]
12083   "TARGET_64BIT && reload_completed"
12084   [(set (match_dup 0)
12085         (leu:DI (match_dup 1) (match_dup 2)))
12086    (set (match_dup 3)
12087         (compare:CC (match_dup 0)
12088                     (const_int 0)))]
12089   "")
12090
12091 (define_insn ""
12092   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12093         (compare:CC
12094          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12095                  (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12096          (const_int 0)))
12097    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12098         (leu:SI (match_dup 1) (match_dup 2)))]
12099   "TARGET_32BIT"
12100   "@
12101    {sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12102    #"
12103   [(set_attr "type" "compare")
12104    (set_attr "length" "12,16")])
12105
12106 (define_split
12107   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12108         (compare:CC
12109          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12110                  (match_operand:SI 2 "reg_or_short_operand" ""))
12111          (const_int 0)))
12112    (set (match_operand:SI 0 "gpc_reg_operand" "")
12113         (leu:SI (match_dup 1) (match_dup 2)))]
12114   "TARGET_32BIT && reload_completed"
12115   [(set (match_dup 0)
12116         (leu:SI (match_dup 1) (match_dup 2)))
12117    (set (match_dup 3)
12118         (compare:CC (match_dup 0)
12119                     (const_int 0)))]
12120   "")
12121
12122 (define_insn ""
12123   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12124         (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12125                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
12126                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12127   "TARGET_32BIT"
12128   "{sf%I2|subf%I2c} %0,%1,%2\;{aze|addze} %0,%3"
12129   [(set_attr "length" "8")])
12130
12131 (define_insn ""
12132   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12133         (compare:CC
12134          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12135                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12136                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12137          (const_int 0)))
12138    (clobber (match_scratch:SI 4 "=&r,&r"))]
12139   "TARGET_32BIT"
12140   "@
12141    {sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3
12142    #"
12143   [(set_attr "type" "compare")
12144    (set_attr "length" "8,12")])
12145
12146 (define_split
12147   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12148         (compare:CC
12149          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12150                           (match_operand:SI 2 "reg_or_short_operand" ""))
12151                   (match_operand:SI 3 "gpc_reg_operand" ""))
12152          (const_int 0)))
12153    (clobber (match_scratch:SI 4 ""))]
12154   "TARGET_32BIT && reload_completed"
12155   [(set (match_dup 4)
12156         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
12157                   (match_dup 3)))
12158    (set (match_dup 0)
12159         (compare:CC (match_dup 4)
12160                     (const_int 0)))]
12161   "")
12162
12163 (define_insn ""
12164   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12165         (compare:CC
12166          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12167                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12168                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12169          (const_int 0)))
12170    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12171         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12172   "TARGET_32BIT"
12173   "@
12174    {sf%I2|subf%I2c} %0,%1,%2\;{aze.|addze.} %0,%3
12175    #"
12176   [(set_attr "type" "compare")
12177    (set_attr "length" "8,12")])
12178
12179 (define_split
12180   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12181         (compare:CC
12182          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12183                           (match_operand:SI 2 "reg_or_short_operand" ""))
12184                   (match_operand:SI 3 "gpc_reg_operand" ""))
12185          (const_int 0)))
12186    (set (match_operand:SI 0 "gpc_reg_operand" "")
12187         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12188   "TARGET_32BIT && reload_completed"
12189   [(set (match_dup 0)
12190         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12191    (set (match_dup 4)
12192         (compare:CC (match_dup 0)
12193                     (const_int 0)))]
12194   "")
12195
12196 (define_insn ""
12197   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12198         (neg:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12199                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12200   "TARGET_32BIT"
12201   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
12202    [(set_attr "length" "12")])
12203
12204 (define_insn ""
12205   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12206         (and:SI (neg:SI
12207                  (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12208                          (match_operand:SI 2 "reg_or_short_operand" "rI")))
12209                 (match_operand:SI 3 "gpc_reg_operand" "r")))]
12210   "TARGET_32BIT"
12211   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12212   [(set_attr "length" "12")])
12213
12214 (define_insn ""
12215   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12216         (compare:CC
12217          (and:SI (neg:SI
12218                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12219                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12220                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12221          (const_int 0)))
12222    (clobber (match_scratch:SI 4 "=&r,&r"))]
12223   "TARGET_32BIT"
12224   "@
12225    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12226    #"
12227   [(set_attr "type" "compare")
12228    (set_attr "length" "12,16")])
12229
12230 (define_split
12231   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12232         (compare:CC
12233          (and:SI (neg:SI
12234                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12235                           (match_operand:SI 2 "reg_or_short_operand" "")))
12236                  (match_operand:SI 3 "gpc_reg_operand" ""))
12237          (const_int 0)))
12238    (clobber (match_scratch:SI 4 ""))]
12239   "TARGET_32BIT && reload_completed"
12240   [(set (match_dup 4)
12241         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12242                 (match_dup 3)))
12243    (set (match_dup 0)
12244         (compare:CC (match_dup 4)
12245                     (const_int 0)))]
12246   "")
12247
12248 (define_insn ""
12249   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12250         (compare:CC
12251          (and:SI (neg:SI
12252                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12253                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12254                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12255          (const_int 0)))
12256    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12257         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12258   "TARGET_32BIT"
12259   "@
12260    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12261    #"
12262   [(set_attr "type" "compare")
12263    (set_attr "length" "12,16")])
12264
12265 (define_split
12266   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12267         (compare:CC
12268          (and:SI (neg:SI
12269                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12270                           (match_operand:SI 2 "reg_or_short_operand" "")))
12271                  (match_operand:SI 3 "gpc_reg_operand" ""))
12272          (const_int 0)))
12273    (set (match_operand:SI 0 "gpc_reg_operand" "")
12274         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12275   "TARGET_32BIT && reload_completed"
12276   [(set (match_dup 0)
12277         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12278                 (match_dup 3)))
12279    (set (match_dup 4)
12280         (compare:CC (match_dup 0)
12281                     (const_int 0)))]
12282   "")
12283
12284 (define_insn ""
12285   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12286         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12287                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12288   "TARGET_POWER"
12289   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
12290    [(set_attr "length" "12")])
12291
12292 (define_insn ""
12293   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12294         (compare:CC
12295          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12296                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12297          (const_int 0)))
12298    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12299         (lt:SI (match_dup 1) (match_dup 2)))]
12300   "TARGET_POWER"
12301   "@
12302    doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
12303    #"
12304   [(set_attr "type" "delayed_compare")
12305    (set_attr "length" "12,16")])
12306
12307 (define_split
12308   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12309         (compare:CC
12310          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12311                 (match_operand:SI 2 "reg_or_short_operand" ""))
12312          (const_int 0)))
12313    (set (match_operand:SI 0 "gpc_reg_operand" "")
12314         (lt:SI (match_dup 1) (match_dup 2)))]
12315   "TARGET_POWER && reload_completed"
12316   [(set (match_dup 0)
12317         (lt:SI (match_dup 1) (match_dup 2)))
12318    (set (match_dup 3)
12319         (compare:CC (match_dup 0)
12320                     (const_int 0)))]
12321   "")
12322
12323 (define_insn ""
12324   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12325         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12326                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12327                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12328   "TARGET_POWER"
12329   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
12330   [(set_attr "length" "12")])
12331
12332 (define_insn ""
12333   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12334         (compare:CC
12335          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12336                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12337                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12338          (const_int 0)))
12339    (clobber (match_scratch:SI 4 "=&r,&r"))]
12340   "TARGET_POWER"
12341   "@
12342    doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
12343    #"
12344   [(set_attr "type" "compare")
12345    (set_attr "length" "12,16")])
12346
12347 (define_split
12348   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12349         (compare:CC
12350          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12351                          (match_operand:SI 2 "reg_or_short_operand" ""))
12352                   (match_operand:SI 3 "gpc_reg_operand" ""))
12353          (const_int 0)))
12354    (clobber (match_scratch:SI 4 ""))]
12355   "TARGET_POWER && reload_completed"
12356   [(set (match_dup 4)
12357         (plus:SI (lt:SI (match_dup 1) (match_dup 2))
12358                  (match_dup 3)))
12359    (set (match_dup 0)
12360         (compare:CC (match_dup 4)
12361                     (const_int 0)))]
12362   "")
12363
12364 (define_insn ""
12365   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12366         (compare:CC
12367          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12368                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12369                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12370          (const_int 0)))
12371    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12372         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12373   "TARGET_POWER"
12374   "@
12375    doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
12376    #"
12377   [(set_attr "type" "compare")
12378    (set_attr "length" "12,16")])
12379
12380 (define_split
12381   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12382         (compare:CC
12383          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12384                          (match_operand:SI 2 "reg_or_short_operand" ""))
12385                   (match_operand:SI 3 "gpc_reg_operand" ""))
12386          (const_int 0)))
12387    (set (match_operand:SI 0 "gpc_reg_operand" "")
12388         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12389   "TARGET_POWER && reload_completed"
12390   [(set (match_dup 0)
12391         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12392    (set (match_dup 4)
12393         (compare:CC (match_dup 0)
12394                     (const_int 0)))]
12395   "")
12396
12397 (define_insn ""
12398   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12399         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12400                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12401   "TARGET_POWER"
12402   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
12403   [(set_attr "length" "12")])
12404
12405 (define_insn ""
12406   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12407         (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12408                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
12409   "TARGET_32BIT"
12410   "@
12411    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg %0,%0
12412    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg %0,%0"
12413   [(set_attr "length" "12")])
12414
12415 (define_insn ""
12416   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12417         (compare:CC
12418          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12419                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12420          (const_int 0)))
12421    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12422         (ltu:SI (match_dup 1) (match_dup 2)))]
12423   "TARGET_32BIT"
12424   "@
12425    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
12426    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
12427    #
12428    #"
12429   [(set_attr "type" "compare")
12430    (set_attr "length" "12,12,16,16")])
12431
12432 (define_split
12433   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12434         (compare:CC
12435          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12436                  (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12437          (const_int 0)))
12438    (set (match_operand:SI 0 "gpc_reg_operand" "")
12439         (ltu:SI (match_dup 1) (match_dup 2)))]
12440   "TARGET_32BIT && reload_completed"
12441   [(set (match_dup 0)
12442         (ltu:SI (match_dup 1) (match_dup 2)))
12443    (set (match_dup 3)
12444         (compare:CC (match_dup 0)
12445                     (const_int 0)))]
12446   "")
12447
12448 (define_insn ""
12449   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12450         (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12451                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
12452                  (match_operand:SI 3 "reg_or_short_operand" "rI,rI")))]
12453   "TARGET_32BIT"
12454   "@
12455   {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;{sf%I3|subf%I3c} %0,%0,%3
12456   {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;{sf%I3|subf%I3c} %0,%0,%3"
12457  [(set_attr "length" "12")])
12458
12459 (define_insn ""
12460   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12461         (compare:CC
12462          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12463                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12464                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12465          (const_int 0)))
12466    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12467   "TARGET_32BIT"
12468   "@
12469    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
12470    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
12471    #
12472    #"
12473   [(set_attr "type" "compare")
12474    (set_attr "length" "12,12,16,16")])
12475
12476 (define_split
12477   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12478         (compare:CC
12479          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12480                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12481                   (match_operand:SI 3 "gpc_reg_operand" ""))
12482          (const_int 0)))
12483    (clobber (match_scratch:SI 4 ""))]
12484   "TARGET_32BIT && reload_completed"
12485   [(set (match_dup 4)
12486         (plus:SI (ltu:SI (match_dup 1) (match_dup 2))
12487                  (match_dup 3)))
12488    (set (match_dup 0)
12489         (compare:CC (match_dup 4)
12490                     (const_int 0)))]
12491   "")
12492
12493 (define_insn ""
12494   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12495         (compare:CC
12496          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12497                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12498                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12499          (const_int 0)))
12500    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12501         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12502   "TARGET_32BIT"
12503   "@
12504    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;{sf.|subfc.} %0,%0,%3
12505    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;{sf.|subfc.} %0,%0,%3
12506    #
12507    #"
12508   [(set_attr "type" "compare")
12509    (set_attr "length" "12,12,16,16")])
12510
12511 (define_split
12512   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12513         (compare:CC
12514          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12515                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12516                   (match_operand:SI 3 "gpc_reg_operand" ""))
12517          (const_int 0)))
12518    (set (match_operand:SI 0 "gpc_reg_operand" "")
12519         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12520   "TARGET_32BIT && reload_completed"
12521   [(set (match_dup 0)
12522         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12523    (set (match_dup 4)
12524         (compare:CC (match_dup 0)
12525                     (const_int 0)))]
12526   "")
12527
12528 (define_insn ""
12529   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12530         (neg:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12531                         (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))))]
12532   "TARGET_32BIT"
12533   "@
12534    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
12535    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
12536   [(set_attr "length" "8")])
12537
12538 (define_insn ""
12539   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12540         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12541                (match_operand:SI 2 "reg_or_short_operand" "rI")))
12542    (clobber (match_scratch:SI 3 "=r"))]
12543   "TARGET_POWER"
12544   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
12545    [(set_attr "length" "12")])
12546
12547 (define_insn ""
12548   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12549         (compare:CC
12550          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12551                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12552          (const_int 0)))
12553    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12554         (ge:SI (match_dup 1) (match_dup 2)))
12555    (clobber (match_scratch:SI 3 "=r,r"))]
12556   "TARGET_POWER"
12557   "@
12558    doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
12559    #"
12560   [(set_attr "type" "compare")
12561    (set_attr "length" "12,16")])
12562
12563 (define_split
12564   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12565         (compare:CC
12566          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12567                 (match_operand:SI 2 "reg_or_short_operand" ""))
12568          (const_int 0)))
12569    (set (match_operand:SI 0 "gpc_reg_operand" "")
12570         (ge:SI (match_dup 1) (match_dup 2)))
12571    (clobber (match_scratch:SI 3 ""))]
12572   "TARGET_POWER && reload_completed"
12573   [(parallel [(set (match_dup 0)
12574                    (ge:SI (match_dup 1) (match_dup 2)))
12575               (clobber (match_dup 3))])
12576    (set (match_dup 4)
12577         (compare:CC (match_dup 0)
12578                     (const_int 0)))]
12579   "")
12580
12581 (define_insn ""
12582   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12583         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12584                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12585                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12586   "TARGET_POWER"
12587   "doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
12588   [(set_attr "length" "12")])
12589
12590 (define_insn ""
12591   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12592         (compare:CC
12593          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12594                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12595                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12596          (const_int 0)))
12597    (clobber (match_scratch:SI 4 "=&r,&r"))]
12598   "TARGET_POWER"
12599   "@
12600    doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12601    #"
12602   [(set_attr "type" "compare")
12603    (set_attr "length" "12,16")])
12604
12605 (define_split
12606   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12607         (compare:CC
12608          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12609                          (match_operand:SI 2 "reg_or_short_operand" ""))
12610                   (match_operand:SI 3 "gpc_reg_operand" ""))
12611          (const_int 0)))
12612    (clobber (match_scratch:SI 4 ""))]
12613   "TARGET_POWER && reload_completed"
12614   [(set (match_dup 4)
12615         (plus:SI (ge:SI (match_dup 1) (match_dup 2))
12616                  (match_dup 3)))
12617    (set (match_dup 0)
12618         (compare:CC (match_dup 4)
12619                     (const_int 0)))]
12620   "")
12621
12622 (define_insn ""
12623   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12624         (compare:CC
12625          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12626                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12627                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12628          (const_int 0)))
12629    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12630         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12631   "TARGET_POWER"
12632   "@
12633    doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12634    #"
12635   [(set_attr "type" "compare")
12636    (set_attr "length" "12,16")])
12637
12638 (define_split
12639   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12640         (compare:CC
12641          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12642                          (match_operand:SI 2 "reg_or_short_operand" ""))
12643                   (match_operand:SI 3 "gpc_reg_operand" ""))
12644          (const_int 0)))
12645    (set (match_operand:SI 0 "gpc_reg_operand" "")
12646         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12647   "TARGET_POWER && reload_completed"
12648   [(set (match_dup 0)
12649         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12650    (set (match_dup 4)
12651         (compare:CC (match_dup 0)
12652                     (const_int 0)))]
12653   "")
12654
12655 (define_insn ""
12656   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12657         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12658                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12659   "TARGET_POWER"
12660   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
12661   [(set_attr "length" "12")])
12662
12663 (define_insn ""
12664   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12665         (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12666                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
12667   "TARGET_32BIT"
12668   "@
12669    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
12670    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12671   [(set_attr "length" "12")])
12672
12673 (define_insn ""
12674   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12675         (geu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12676                 (match_operand:DI 2 "reg_or_neg_short_operand" "r,P")))]
12677   "TARGET_64BIT"
12678   "@
12679    subfc %0,%2,%1\;li %0,0\;adde %0,%0,%0
12680    addic %0,%1,%n2\;li %0,0\;adde %0,%0,%0"
12681   [(set_attr "length" "12")])
12682
12683 (define_insn ""
12684   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12685         (compare:CC
12686          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12687                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12688          (const_int 0)))
12689    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12690         (geu:SI (match_dup 1) (match_dup 2)))]
12691   "TARGET_32BIT"
12692   "@
12693    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12694    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12695    #
12696    #"
12697   [(set_attr "type" "compare")
12698    (set_attr "length" "12,12,16,16")])
12699
12700 (define_split
12701   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12702         (compare:CC
12703          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12704                  (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12705          (const_int 0)))
12706    (set (match_operand:SI 0 "gpc_reg_operand" "")
12707         (geu:SI (match_dup 1) (match_dup 2)))]
12708   "TARGET_32BIT && reload_completed"
12709   [(set (match_dup 0)
12710         (geu:SI (match_dup 1) (match_dup 2)))
12711    (set (match_dup 3)
12712         (compare:CC (match_dup 0)
12713                     (const_int 0)))]
12714   "")
12715
12716 (define_insn ""
12717   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12718         (compare:CC
12719          (geu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
12720                  (match_operand:DI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12721          (const_int 0)))
12722    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
12723         (geu:DI (match_dup 1) (match_dup 2)))]
12724   "TARGET_64BIT"
12725   "@
12726    subfc %0,%2,%1\;li %0,0\;adde. %0,%0,%0
12727    addic %0,%1,%n2\;li %0,0\;adde. %0,%0,%0
12728    #
12729    #"
12730   [(set_attr "type" "compare")
12731    (set_attr "length" "12,12,16,16")])
12732
12733 (define_split
12734   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12735         (compare:CC
12736          (geu:DI (match_operand:DI 1 "gpc_reg_operand" "")
12737                  (match_operand:DI 2 "reg_or_neg_short_operand" ""))
12738          (const_int 0)))
12739    (set (match_operand:DI 0 "gpc_reg_operand" "")
12740         (geu:DI (match_dup 1) (match_dup 2)))]
12741   "TARGET_64BIT && reload_completed"
12742   [(set (match_dup 0)
12743         (geu:DI (match_dup 1) (match_dup 2)))
12744    (set (match_dup 3)
12745         (compare:CC (match_dup 0)
12746                     (const_int 0)))]
12747   "")
12748
12749 (define_insn ""
12750   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12751         (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12752                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
12753                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12754   "TARGET_32BIT"
12755   "@
12756    {sf|subfc} %0,%2,%1\;{aze|addze} %0,%3
12757    {ai|addic} %0,%1,%n2\;{aze|addze} %0,%3"
12758   [(set_attr "length" "8")])
12759
12760 (define_insn ""
12761   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12762         (compare:CC
12763          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12764                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12765                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12766          (const_int 0)))
12767    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12768   "TARGET_32BIT"
12769   "@
12770    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
12771    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3
12772    #
12773    #"
12774   [(set_attr "type" "compare")
12775    (set_attr "length" "8,8,12,12")])
12776
12777 (define_split
12778   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12779         (compare:CC
12780          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12781                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12782                   (match_operand:SI 3 "gpc_reg_operand" ""))
12783          (const_int 0)))
12784    (clobber (match_scratch:SI 4 ""))]
12785   "TARGET_32BIT && reload_completed"
12786   [(set (match_dup 4)
12787         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
12788                   (match_dup 3)))
12789    (set (match_dup 0)
12790         (compare:CC (match_dup 4)
12791                     (const_int 0)))]
12792   "")
12793
12794 (define_insn ""
12795   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12796         (compare:CC
12797          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12798                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12799                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12800          (const_int 0)))
12801    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12802         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12803   "TARGET_32BIT"
12804   "@
12805    {sf|subfc} %0,%2,%1\;{aze.|addze.} %0,%3
12806    {ai|addic} %0,%1,%n2\;{aze.|addze.} %0,%3
12807    #
12808    #"
12809   [(set_attr "type" "compare")
12810    (set_attr "length" "8,8,12,12")])
12811
12812 (define_split
12813   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12814         (compare:CC
12815          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12816                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12817                   (match_operand:SI 3 "gpc_reg_operand" ""))
12818          (const_int 0)))
12819    (set (match_operand:SI 0 "gpc_reg_operand" "")
12820         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12821   "TARGET_32BIT && reload_completed"
12822   [(set (match_dup 0)
12823         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12824    (set (match_dup 4)
12825         (compare:CC (match_dup 0)
12826                     (const_int 0)))]
12827   "")
12828
12829 (define_insn ""
12830   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12831         (neg:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12832                         (match_operand:SI 2 "reg_or_short_operand" "r,I"))))]
12833   "TARGET_32BIT"
12834   "@
12835    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
12836    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
12837   [(set_attr "length" "12")])
12838
12839 (define_insn ""
12840   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12841         (and:SI (neg:SI
12842                  (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12843                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
12844                 (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12845   "TARGET_32BIT"
12846   "@
12847    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0
12848    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12849   [(set_attr "length" "12")])
12850
12851 (define_insn ""
12852   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12853         (compare:CC
12854          (and:SI (neg:SI
12855                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12856                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
12857                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12858          (const_int 0)))
12859    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12860   "TARGET_32BIT"
12861   "@
12862    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12863    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12864    #
12865    #"
12866   [(set_attr "type" "compare")
12867    (set_attr "length" "12,12,16,16")])
12868
12869 (define_split
12870   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12871         (compare:CC
12872          (and:SI (neg:SI
12873                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12874                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
12875                  (match_operand:SI 3 "gpc_reg_operand" ""))
12876          (const_int 0)))
12877    (clobber (match_scratch:SI 4 ""))]
12878   "TARGET_32BIT && reload_completed"
12879   [(set (match_dup 4)
12880         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
12881                 (match_dup 3)))
12882    (set (match_dup 0)
12883         (compare:CC (match_dup 4)
12884                     (const_int 0)))]
12885   "")
12886
12887 (define_insn ""
12888   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12889         (compare:CC
12890          (and:SI (neg:SI
12891                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12892                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
12893                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12894          (const_int 0)))
12895    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12896         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12897   "TARGET_32BIT"
12898   "@
12899    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12900    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12901    #
12902    #"
12903   [(set_attr "type" "compare")
12904    (set_attr "length" "12,12,16,16")])
12905
12906 (define_split
12907   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12908         (compare:CC
12909          (and:SI (neg:SI
12910                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12911                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
12912                  (match_operand:SI 3 "gpc_reg_operand" ""))
12913          (const_int 0)))
12914    (set (match_operand:SI 0 "gpc_reg_operand" "")
12915         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12916   "TARGET_32BIT && reload_completed"
12917   [(set (match_dup 0)
12918         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
12919    (set (match_dup 4)
12920         (compare:CC (match_dup 0)
12921                     (const_int 0)))]
12922   "")
12923
12924 (define_insn ""
12925   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12926         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12927                (const_int 0)))]
12928   "TARGET_32BIT"
12929   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri|srwi} %0,%0,31"
12930   [(set_attr "length" "12")])
12931
12932 (define_insn ""
12933   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12934         (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
12935                (const_int 0)))]
12936   "TARGET_64BIT"
12937   "subfic %0,%1,0\;addme %0,%0\;srdi %0,%0,63"
12938   [(set_attr "length" "12")])
12939
12940 (define_insn ""
12941   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
12942         (compare:CC
12943          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12944                 (const_int 0))
12945          (const_int 0)))
12946    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12947         (gt:SI (match_dup 1) (const_int 0)))]
12948   "TARGET_32BIT"
12949   "@
12950    {sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri.|srwi.} %0,%0,31
12951    #"
12952   [(set_attr "type" "delayed_compare")
12953    (set_attr "length" "12,16")])
12954
12955 (define_split
12956   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
12957         (compare:CC
12958          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12959                 (const_int 0))
12960          (const_int 0)))
12961    (set (match_operand:SI 0 "gpc_reg_operand" "")
12962         (gt:SI (match_dup 1) (const_int 0)))]
12963   "TARGET_32BIT && reload_completed"
12964   [(set (match_dup 0)
12965         (gt:SI (match_dup 1) (const_int 0)))
12966    (set (match_dup 2)
12967         (compare:CC (match_dup 0)
12968                     (const_int 0)))]
12969   "")
12970
12971 (define_insn ""
12972   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
12973         (compare:CC
12974          (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12975                 (const_int 0))
12976          (const_int 0)))
12977    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12978         (gt:DI (match_dup 1) (const_int 0)))]
12979   "TARGET_64BIT"
12980   "@
12981    subfic %0,%1,0\;addme %0,%0\;srdi. %0,%0,63
12982    #"
12983   [(set_attr "type" "delayed_compare")
12984    (set_attr "length" "12,16")])
12985
12986 (define_split
12987   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
12988         (compare:CC
12989          (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
12990                 (const_int 0))
12991          (const_int 0)))
12992    (set (match_operand:DI 0 "gpc_reg_operand" "")
12993         (gt:DI (match_dup 1) (const_int 0)))]
12994   "TARGET_64BIT && reload_completed"
12995   [(set (match_dup 0)
12996         (gt:DI (match_dup 1) (const_int 0)))
12997    (set (match_dup 2)
12998         (compare:CC (match_dup 0)
12999                     (const_int 0)))]
13000   "")
13001
13002 (define_insn ""
13003   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13004         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13005                (match_operand:SI 2 "reg_or_short_operand" "r")))]
13006   "TARGET_POWER"
13007   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
13008   [(set_attr "length" "12")])
13009
13010 (define_insn ""
13011   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13012         (compare:CC
13013          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13014                 (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13015          (const_int 0)))
13016    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13017         (gt:SI (match_dup 1) (match_dup 2)))]
13018   "TARGET_POWER"
13019   "@
13020    doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
13021    #"
13022   [(set_attr "type" "delayed_compare")
13023    (set_attr "length" "12,16")])
13024
13025 (define_split
13026   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13027         (compare:CC
13028          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13029                 (match_operand:SI 2 "reg_or_short_operand" ""))
13030          (const_int 0)))
13031    (set (match_operand:SI 0 "gpc_reg_operand" "")
13032         (gt:SI (match_dup 1) (match_dup 2)))]
13033   "TARGET_POWER && reload_completed"
13034   [(set (match_dup 0)
13035         (gt:SI (match_dup 1) (match_dup 2)))
13036    (set (match_dup 3)
13037         (compare:CC (match_dup 0)
13038                     (const_int 0)))]
13039   "")
13040
13041 (define_insn ""
13042   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13043         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13044                         (const_int 0))
13045                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
13046   "TARGET_32BIT"
13047   "{a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze|addze} %0,%2"
13048   [(set_attr "length" "12")])
13049
13050 (define_insn ""
13051   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
13052         (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13053                         (const_int 0))
13054                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
13055   "TARGET_64BIT"
13056   "addc %0,%1,%1\;subfe %0,%1,%0\;addze %0,%2"
13057   [(set_attr "length" "12")])
13058
13059 (define_insn ""
13060   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13061         (compare:CC
13062          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13063                          (const_int 0))
13064                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13065          (const_int 0)))
13066    (clobber (match_scratch:SI 3 "=&r,&r"))]
13067   "TARGET_32BIT"
13068   "@
13069    {a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2
13070    #"
13071   [(set_attr "type" "compare")
13072    (set_attr "length" "12,16")])
13073
13074 (define_split
13075   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13076         (compare:CC
13077          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13078                          (const_int 0))
13079                   (match_operand:SI 2 "gpc_reg_operand" ""))
13080          (const_int 0)))
13081    (clobber (match_scratch:SI 3 ""))]
13082   "TARGET_32BIT && reload_completed"
13083   [(set (match_dup 3)
13084         (plus:SI (gt:SI (match_dup 1) (const_int 0))
13085                   (match_dup 2)))
13086    (set (match_dup 0)
13087         (compare:CC (match_dup 3)
13088                     (const_int 0)))]
13089   "")
13090
13091 (define_insn ""
13092   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13093         (compare:CC
13094          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13095                          (const_int 0))
13096                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13097          (const_int 0)))
13098    (clobber (match_scratch:DI 3 "=&r,&r"))]
13099   "TARGET_64BIT"
13100   "@
13101    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
13102    #"
13103   [(set_attr "type" "compare")
13104    (set_attr "length" "12,16")])
13105
13106 (define_split
13107   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13108         (compare:CC
13109          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13110                          (const_int 0))
13111                   (match_operand:DI 2 "gpc_reg_operand" ""))
13112          (const_int 0)))
13113    (clobber (match_scratch:DI 3 ""))]
13114   "TARGET_64BIT && reload_completed"
13115   [(set (match_dup 3)
13116         (plus:DI (gt:DI (match_dup 1) (const_int 0))
13117                  (match_dup 2)))
13118    (set (match_dup 0)
13119         (compare:CC (match_dup 3)
13120                     (const_int 0)))]
13121   "")
13122
13123 (define_insn ""
13124   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13125         (compare:CC
13126          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13127                          (const_int 0))
13128                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13129          (const_int 0)))
13130    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13131         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13132   "TARGET_32BIT"
13133   "@
13134    {a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze.|addze.} %0,%2
13135    #"
13136   [(set_attr "type" "compare")
13137    (set_attr "length" "12,16")])
13138
13139 (define_split
13140   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13141         (compare:CC
13142          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13143                          (const_int 0))
13144                   (match_operand:SI 2 "gpc_reg_operand" ""))
13145          (const_int 0)))
13146    (set (match_operand:SI 0 "gpc_reg_operand" "")
13147         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13148   "TARGET_32BIT && reload_completed"
13149   [(set (match_dup 0)
13150         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
13151    (set (match_dup 3)
13152         (compare:CC (match_dup 0)
13153                     (const_int 0)))]
13154   "")
13155
13156 (define_insn ""
13157   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13158         (compare:CC
13159          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13160                          (const_int 0))
13161                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13162          (const_int 0)))
13163    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
13164         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13165   "TARGET_64BIT"
13166   "@
13167    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
13168    #"
13169   [(set_attr "type" "compare")
13170    (set_attr "length" "12,16")])
13171
13172 (define_split
13173   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13174         (compare:CC
13175          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13176                          (const_int 0))
13177                   (match_operand:DI 2 "gpc_reg_operand" ""))
13178          (const_int 0)))
13179    (set (match_operand:DI 0 "gpc_reg_operand" "")
13180         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13181   "TARGET_64BIT && reload_completed"
13182   [(set (match_dup 0)
13183         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
13184    (set (match_dup 3)
13185         (compare:CC (match_dup 0)
13186                     (const_int 0)))]
13187   "")
13188
13189 (define_insn ""
13190   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13191         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13192                         (match_operand:SI 2 "reg_or_short_operand" "r"))
13193                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
13194   "TARGET_POWER"
13195   "doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
13196   [(set_attr "length" "12")])
13197
13198 (define_insn ""
13199   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13200         (compare:CC
13201          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13202                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13203                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13204          (const_int 0)))
13205    (clobber (match_scratch:SI 4 "=&r,&r"))]
13206   "TARGET_POWER"
13207   "@
13208    doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
13209    #"
13210   [(set_attr "type" "compare")
13211    (set_attr "length" "12,16")])
13212
13213 (define_split
13214   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13215         (compare:CC
13216          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13217                          (match_operand:SI 2 "reg_or_short_operand" ""))
13218                   (match_operand:SI 3 "gpc_reg_operand" ""))
13219          (const_int 0)))
13220    (clobber (match_scratch:SI 4 ""))]
13221   "TARGET_POWER && reload_completed"
13222   [(set (match_dup 4)
13223         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13224    (set (match_dup 0)
13225         (compare:CC (match_dup 4)
13226                     (const_int 0)))]
13227   "")
13228
13229 (define_insn ""
13230   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13231         (compare:CC
13232          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13233                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13234                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13235          (const_int 0)))
13236    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13237         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13238   "TARGET_POWER"
13239   "@
13240    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
13241    #"
13242   [(set_attr "type" "compare")
13243    (set_attr "length" "12,16")])
13244
13245 (define_split
13246   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13247         (compare:CC
13248          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13249                          (match_operand:SI 2 "reg_or_short_operand" ""))
13250                   (match_operand:SI 3 "gpc_reg_operand" ""))
13251          (const_int 0)))
13252    (set (match_operand:SI 0 "gpc_reg_operand" "")
13253         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13254   "TARGET_POWER && reload_completed"
13255   [(set (match_dup 0)
13256         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13257    (set (match_dup 4)
13258         (compare:CC (match_dup 0)
13259                     (const_int 0)))]
13260   "")
13261
13262 (define_insn ""
13263   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13264         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13265                        (const_int 0))))]
13266   "TARGET_32BIT"
13267   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{srai|srawi} %0,%0,31"
13268   [(set_attr "length" "12")])
13269
13270 (define_insn ""
13271   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13272         (neg:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13273                        (const_int 0))))]
13274   "TARGET_64BIT"
13275   "subfic %0,%1,0\;addme %0,%0\;sradi %0,%0,63"
13276   [(set_attr "length" "12")])
13277
13278 (define_insn ""
13279   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13280         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13281                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
13282   "TARGET_POWER"
13283   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
13284   [(set_attr "length" "12")])
13285
13286 (define_insn ""
13287   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13288         (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13289                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
13290   "TARGET_32BIT"
13291   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg %0,%0"
13292   [(set_attr "length" "12")])
13293
13294 (define_insn ""
13295   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13296         (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13297                 (match_operand:DI 2 "reg_or_short_operand" "rI")))]
13298   "TARGET_64BIT"
13299   "subf%I2c %0,%1,%2\;subfe %0,%0,%0\;neg %0,%0"
13300   [(set_attr "length" "12")])
13301
13302 (define_insn ""
13303   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13304         (compare:CC
13305          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13306                  (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13307          (const_int 0)))
13308    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13309         (gtu:SI (match_dup 1) (match_dup 2)))]
13310   "TARGET_32BIT"
13311   "@
13312    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
13313    #"
13314   [(set_attr "type" "compare")
13315    (set_attr "length" "12,16")])
13316
13317 (define_split
13318   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13319         (compare:CC
13320          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13321                  (match_operand:SI 2 "reg_or_short_operand" ""))
13322          (const_int 0)))
13323    (set (match_operand:SI 0 "gpc_reg_operand" "")
13324         (gtu:SI (match_dup 1) (match_dup 2)))]
13325   "TARGET_32BIT && reload_completed"
13326   [(set (match_dup 0)
13327         (gtu:SI (match_dup 1) (match_dup 2)))
13328    (set (match_dup 3)
13329         (compare:CC (match_dup 0)
13330                     (const_int 0)))]
13331   "")
13332
13333 (define_insn ""
13334   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13335         (compare:CC
13336          (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13337                  (match_operand:DI 2 "reg_or_short_operand" "rI,rI"))
13338          (const_int 0)))
13339    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
13340         (gtu:DI (match_dup 1) (match_dup 2)))]
13341   "TARGET_64BIT"
13342   "@
13343    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;neg. %0,%0
13344    #"
13345   [(set_attr "type" "compare")
13346    (set_attr "length" "12,16")])
13347
13348 (define_split
13349   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13350         (compare:CC
13351          (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13352                  (match_operand:DI 2 "reg_or_short_operand" ""))
13353          (const_int 0)))
13354    (set (match_operand:DI 0 "gpc_reg_operand" "")
13355         (gtu:DI (match_dup 1) (match_dup 2)))]
13356   "TARGET_64BIT && reload_completed"
13357   [(set (match_dup 0)
13358         (gtu:DI (match_dup 1) (match_dup 2)))
13359    (set (match_dup 3)
13360         (compare:CC (match_dup 0)
13361                     (const_int 0)))]
13362   "")
13363
13364 (define_insn ""
13365   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13366         (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13367                          (match_operand:SI 2 "reg_or_short_operand" "I,rI"))
13368                  (match_operand:SI 3 "reg_or_short_operand" "r,rI")))]
13369   "TARGET_32BIT"
13370   "@
13371    {ai|addic} %0,%1,%k2\;{aze|addze} %0,%3
13372    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;{sf%I3|subf%I3c} %0,%0,%3"
13373   [(set_attr "length" "8,12")])
13374
13375 (define_insn ""
13376   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
13377         (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13378                          (match_operand:DI 2 "reg_or_short_operand" "I,rI"))
13379                  (match_operand:DI 3 "reg_or_short_operand" "r,rI")))]
13380   "TARGET_64BIT"
13381   "@
13382    addic %0,%1,%k2\;addze %0,%3
13383    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;subf%I3c %0,%0,%3"
13384   [(set_attr "length" "8,12")])
13385
13386 (define_insn ""
13387   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13388         (compare:CC
13389          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13390                           (match_operand:SI 2 "reg_or_short_operand" "I,r,I,r"))
13391                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13392          (const_int 0)))
13393    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13394   "TARGET_32BIT"
13395   "@
13396    {ai|addic} %4,%1,%k2\;{aze.|addze.} %4,%3
13397    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
13398    #
13399    #"
13400   [(set_attr "type" "compare")
13401    (set_attr "length" "8,12,12,16")])
13402
13403 (define_split
13404   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13405         (compare:CC
13406          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13407                           (match_operand:SI 2 "reg_or_short_operand" ""))
13408                   (match_operand:SI 3 "gpc_reg_operand" ""))
13409          (const_int 0)))
13410    (clobber (match_scratch:SI 4 ""))]
13411   "TARGET_32BIT && reload_completed"
13412   [(set (match_dup 4)
13413         (plus:SI (gtu:SI (match_dup 1) (match_dup 2))
13414                  (match_dup 3)))
13415    (set (match_dup 0)
13416         (compare:CC (match_dup 4)
13417                     (const_int 0)))]
13418   "")
13419
13420 (define_insn ""
13421   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13422         (compare:CC
13423          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
13424                           (match_operand:DI 2 "reg_or_short_operand" "I,r,I,r"))
13425                   (match_operand:DI 3 "gpc_reg_operand" "r,r,r,r"))
13426          (const_int 0)))
13427    (clobber (match_scratch:DI 4 "=&r,&r,&r,&r"))]
13428   "TARGET_64BIT"
13429   "@
13430    addic %4,%1,%k2\;addze. %4,%3
13431    subf%I2c %4,%1,%2\;subfe %4,%4,%4\;subfc. %4,%4,%3
13432    #
13433    #"
13434   [(set_attr "type" "compare")
13435    (set_attr "length" "8,12,12,16")])
13436
13437 (define_split
13438   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13439         (compare:CC
13440          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13441                           (match_operand:DI 2 "reg_or_short_operand" ""))
13442                   (match_operand:DI 3 "gpc_reg_operand" ""))
13443          (const_int 0)))
13444    (clobber (match_scratch:DI 4 ""))]
13445   "TARGET_64BIT && reload_completed"
13446   [(set (match_dup 4)
13447         (plus:DI (gtu:DI (match_dup 1) (match_dup 2))
13448                   (match_dup 3)))
13449    (set (match_dup 0)
13450         (compare:CC (match_dup 4)
13451                     (const_int 0)))]
13452   "")
13453
13454 (define_insn ""
13455   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13456         (compare:CC
13457          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13458                           (match_operand:SI 2 "reg_or_short_operand" "I,r,I,r"))
13459                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13460          (const_int 0)))
13461    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13462         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13463   "TARGET_32BIT"
13464   "@
13465    {ai|addic} %0,%1,%k2\;{aze.|addze.} %0,%3
13466    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;{sf.|subfc.} %0,%0,%3
13467    #
13468    #"
13469   [(set_attr "type" "compare")
13470    (set_attr "length" "8,12,12,16")])
13471
13472 (define_split
13473   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13474         (compare:CC
13475          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13476                           (match_operand:SI 2 "reg_or_short_operand" ""))
13477                   (match_operand:SI 3 "gpc_reg_operand" ""))
13478          (const_int 0)))
13479    (set (match_operand:SI 0 "gpc_reg_operand" "")
13480         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13481   "TARGET_32BIT && reload_completed"
13482   [(set (match_dup 0)
13483         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13484    (set (match_dup 4)
13485         (compare:CC (match_dup 0)
13486                     (const_int 0)))]
13487   "")
13488
13489 (define_insn ""
13490   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13491         (compare:CC
13492          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
13493                           (match_operand:DI 2 "reg_or_short_operand" "I,r,I,r"))
13494                   (match_operand:DI 3 "gpc_reg_operand" "r,r,r,r"))
13495          (const_int 0)))
13496    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13497         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13498   "TARGET_64BIT"
13499   "@
13500    addic %0,%1,%k2\;addze. %0,%3
13501    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;subfc. %0,%0,%3
13502    #
13503    #"
13504   [(set_attr "type" "compare")
13505    (set_attr "length" "8,12,12,16")])
13506
13507 (define_split
13508   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13509         (compare:CC
13510          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13511                           (match_operand:DI 2 "reg_or_short_operand" ""))
13512                   (match_operand:DI 3 "gpc_reg_operand" ""))
13513          (const_int 0)))
13514    (set (match_operand:DI 0 "gpc_reg_operand" "")
13515         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13516   "TARGET_64BIT && reload_completed"
13517   [(set (match_dup 0)
13518         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
13519    (set (match_dup 4)
13520         (compare:CC (match_dup 0)
13521                     (const_int 0)))]
13522   "")
13523
13524 (define_insn ""
13525   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13526         (neg:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13527                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
13528   "TARGET_32BIT"
13529   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
13530   [(set_attr "length" "8")])
13531
13532 (define_insn ""
13533   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13534         (neg:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13535                         (match_operand:DI 2 "reg_or_short_operand" "rI"))))]
13536   "TARGET_64BIT"
13537   "subf%I2c %0,%1,%2\;subfe %0,%0,%0"
13538   [(set_attr "length" "8")])
13539 \f
13540 ;; Define both directions of branch and return.  If we need a reload
13541 ;; register, we'd rather use CR0 since it is much easier to copy a
13542 ;; register CC value to there.
13543
13544 (define_insn ""
13545   [(set (pc)
13546         (if_then_else (match_operator 1 "branch_comparison_operator"
13547                                       [(match_operand 2
13548                                                       "cc_reg_operand" "y")
13549                                        (const_int 0)])
13550                       (label_ref (match_operand 0 "" ""))
13551                       (pc)))]
13552   ""
13553   "*
13554 {
13555   return output_cbranch (operands[1], \"%l0\", 0, insn);
13556 }"
13557   [(set_attr "type" "branch")])
13558
13559 (define_insn ""
13560   [(set (pc)
13561         (if_then_else (match_operator 0 "branch_comparison_operator"
13562                                       [(match_operand 1
13563                                                       "cc_reg_operand" "y")
13564                                        (const_int 0)])
13565                       (return)
13566                       (pc)))]
13567   "direct_return ()"
13568   "*
13569 {
13570   return output_cbranch (operands[0], NULL, 0, insn);
13571 }"
13572   [(set_attr "type" "branch")
13573    (set_attr "length" "4")])
13574
13575 (define_insn ""
13576   [(set (pc)
13577         (if_then_else (match_operator 1 "branch_comparison_operator"
13578                                       [(match_operand 2
13579                                                       "cc_reg_operand" "y")
13580                                        (const_int 0)])
13581                       (pc)
13582                       (label_ref (match_operand 0 "" ""))))]
13583   ""
13584   "*
13585 {
13586   return output_cbranch (operands[1], \"%l0\", 1, insn);
13587 }"
13588   [(set_attr "type" "branch")])
13589
13590 (define_insn ""
13591   [(set (pc)
13592         (if_then_else (match_operator 0 "branch_comparison_operator"
13593                                       [(match_operand 1
13594                                                       "cc_reg_operand" "y")
13595                                        (const_int 0)])
13596                       (pc)
13597                       (return)))]
13598   "direct_return ()"
13599   "*
13600 {
13601   return output_cbranch (operands[0], NULL, 1, insn);
13602 }"
13603   [(set_attr "type" "branch")
13604    (set_attr "length" "4")])
13605
13606 ;; Logic on condition register values.
13607
13608 ; This pattern matches things like
13609 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
13610 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
13611 ;                                  (const_int 1)))
13612 ; which are generated by the branch logic.
13613 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
13614
13615 (define_insn ""
13616   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13617         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
13618                         [(match_operator:SI 2
13619                                       "branch_positive_comparison_operator"
13620                                       [(match_operand 3
13621                                                       "cc_reg_operand" "y,y")
13622                                        (const_int 0)])
13623                          (match_operator:SI 4
13624                                       "branch_positive_comparison_operator"
13625                                       [(match_operand 5
13626                                                       "cc_reg_operand" "0,y")
13627                                        (const_int 0)])])
13628                       (const_int 1)))]
13629   ""
13630   "cr%q1 %E0,%j2,%j4"
13631   [(set_attr "type" "cr_logical,delayed_cr")])
13632
13633 ; Why is the constant -1 here, but 1 in the previous pattern?
13634 ; Because ~1 has all but the low bit set.
13635 (define_insn ""
13636   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13637         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
13638                         [(not:SI (match_operator:SI 2
13639                                       "branch_positive_comparison_operator"
13640                                       [(match_operand 3
13641                                                       "cc_reg_operand" "y,y")
13642                                        (const_int 0)]))
13643                          (match_operator:SI 4
13644                                 "branch_positive_comparison_operator"
13645                                 [(match_operand 5
13646                                                 "cc_reg_operand" "0,y")
13647                                  (const_int 0)])])
13648                       (const_int -1)))]
13649   ""
13650   "cr%q1 %E0,%j2,%j4"
13651   [(set_attr "type" "cr_logical,delayed_cr")])
13652
13653 (define_insn ""
13654   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13655         (compare:CCEQ (match_operator:SI 1
13656                                       "branch_positive_comparison_operator"
13657                                       [(match_operand 2
13658                                                       "cc_reg_operand" "0,y")
13659                                        (const_int 0)])
13660                       (const_int 0)))]
13661   "!TARGET_SPE"
13662   "{crnor %E0,%j1,%j1|crnot %E0,%j1}"
13663   [(set_attr "type" "cr_logical,delayed_cr")])
13664
13665 ;; If we are comparing the result of two comparisons, this can be done
13666 ;; using creqv or crxor.
13667
13668 (define_insn_and_split ""
13669   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
13670         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
13671                               [(match_operand 2 "cc_reg_operand" "y")
13672                                (const_int 0)])
13673                       (match_operator 3 "branch_comparison_operator"
13674                               [(match_operand 4 "cc_reg_operand" "y")
13675                                (const_int 0)])))]
13676   ""
13677   "#"
13678   ""
13679   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
13680                                     (match_dup 5)))]
13681   "
13682 {
13683   int positive_1, positive_2;
13684
13685   positive_1 = branch_positive_comparison_operator (operands[1], CCEQmode);
13686   positive_2 = branch_positive_comparison_operator (operands[3], CCEQmode);
13687
13688   if (! positive_1)
13689     operands[1] = gen_rtx (rs6000_reverse_condition (GET_MODE (operands[2]),
13690                                                      GET_CODE (operands[1])),
13691                            SImode,
13692                            operands[2], const0_rtx);
13693   else if (GET_MODE (operands[1]) != SImode)
13694     operands[1] = gen_rtx (GET_CODE (operands[1]),
13695                            SImode,
13696                            operands[2], const0_rtx);
13697
13698   if (! positive_2)
13699     operands[3] = gen_rtx (rs6000_reverse_condition (GET_MODE (operands[4]),
13700                                                      GET_CODE (operands[3])),
13701                            SImode,
13702                            operands[4], const0_rtx);
13703   else if (GET_MODE (operands[3]) != SImode)
13704     operands[3] = gen_rtx (GET_CODE (operands[3]),
13705                            SImode,
13706                            operands[4], const0_rtx);
13707
13708   if (positive_1 == positive_2)
13709     {
13710       operands[1] = gen_rtx_NOT (SImode, operands[1]);
13711       operands[5] = constm1_rtx;
13712     }
13713   else
13714     {
13715       operands[5] = const1_rtx;
13716     }
13717 }")
13718
13719 ;; Unconditional branch and return.
13720
13721 (define_insn "jump"
13722   [(set (pc)
13723         (label_ref (match_operand 0 "" "")))]
13724   ""
13725   "b %l0"
13726   [(set_attr "type" "branch")])
13727
13728 (define_insn "return"
13729   [(return)]
13730   "direct_return ()"
13731   "{br|blr}"
13732   [(set_attr "type" "jmpreg")])
13733
13734 (define_expand "indirect_jump"
13735   [(set (pc) (match_operand 0 "register_operand" ""))]
13736   ""
13737   "
13738 {
13739   if (TARGET_32BIT)
13740     emit_jump_insn (gen_indirect_jumpsi (operands[0]));
13741   else
13742     emit_jump_insn (gen_indirect_jumpdi (operands[0]));
13743   DONE;
13744 }")
13745
13746 (define_insn "indirect_jumpsi"
13747   [(set (pc) (match_operand:SI 0 "register_operand" "c,*l"))]
13748   "TARGET_32BIT"
13749   "@
13750    bctr
13751    {br|blr}"
13752   [(set_attr "type" "jmpreg")])
13753
13754 (define_insn "indirect_jumpdi"
13755   [(set (pc) (match_operand:DI 0 "register_operand" "c,*l"))]
13756   "TARGET_64BIT"
13757   "@
13758    bctr
13759    blr"
13760   [(set_attr "type" "jmpreg")])
13761
13762 ;; Table jump for switch statements:
13763 (define_expand "tablejump"
13764   [(use (match_operand 0 "" ""))
13765    (use (label_ref (match_operand 1 "" "")))]
13766   ""
13767   "
13768 {
13769   if (TARGET_32BIT)
13770     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
13771   else
13772     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
13773   DONE;
13774 }")
13775
13776 (define_expand "tablejumpsi"
13777   [(set (match_dup 3)
13778         (plus:SI (match_operand:SI 0 "" "")
13779                  (match_dup 2)))
13780    (parallel [(set (pc) (match_dup 3))
13781               (use (label_ref (match_operand 1 "" "")))])]
13782   "TARGET_32BIT"
13783   "
13784 { operands[0] = force_reg (SImode, operands[0]);
13785   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
13786   operands[3] = gen_reg_rtx (SImode);
13787 }")
13788
13789 (define_expand "tablejumpdi"
13790   [(set (match_dup 4) 
13791         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "rm")))
13792    (set (match_dup 3)
13793         (plus:DI (match_dup 4)
13794                  (match_dup 2)))
13795    (parallel [(set (pc) (match_dup 3))
13796               (use (label_ref (match_operand 1 "" "")))])]
13797   "TARGET_64BIT"
13798   "
13799 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
13800   operands[3] = gen_reg_rtx (DImode);
13801   operands[4] = gen_reg_rtx (DImode);
13802 }")
13803
13804 (define_insn ""
13805   [(set (pc)
13806         (match_operand:SI 0 "register_operand" "c,*l"))
13807    (use (label_ref (match_operand 1 "" "")))]
13808   "TARGET_32BIT"
13809   "@
13810    bctr
13811    {br|blr}"
13812   [(set_attr "type" "jmpreg")])
13813
13814 (define_insn ""
13815   [(set (pc)
13816         (match_operand:DI 0 "register_operand" "c,*l"))
13817    (use (label_ref (match_operand 1 "" "")))]
13818   "TARGET_64BIT"
13819   "@
13820    bctr
13821    blr"
13822   [(set_attr "type" "jmpreg")])
13823
13824 (define_insn "nop"
13825   [(const_int 0)]
13826   ""
13827   "{cror 0,0,0|nop}")
13828 \f
13829 ;; Define the subtract-one-and-jump insns, starting with the template
13830 ;; so loop.c knows what to generate.
13831
13832 (define_expand "doloop_end"
13833   [(use (match_operand 0 "" ""))        ; loop pseudo
13834    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
13835    (use (match_operand 2 "" ""))        ; max iterations
13836    (use (match_operand 3 "" ""))        ; loop level
13837    (use (match_operand 4 "" ""))]       ; label
13838   ""
13839   "
13840 {
13841   /* Only use this on innermost loops.  */
13842   if (INTVAL (operands[3]) > 1)
13843     FAIL;
13844   if (TARGET_64BIT)
13845     {
13846       if (GET_MODE (operands[0]) != DImode)
13847         FAIL;
13848       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
13849     }
13850   else
13851     {
13852       if (GET_MODE (operands[0]) != SImode)
13853         FAIL;
13854       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
13855     }
13856   DONE;
13857 }")
13858
13859 (define_expand "ctrsi"
13860   [(parallel [(set (pc)
13861                    (if_then_else (ne (match_operand:SI 0 "register_operand" "")
13862                                      (const_int 1))
13863                                  (label_ref (match_operand 1 "" ""))
13864                                  (pc)))
13865               (set (match_dup 0)
13866                    (plus:SI (match_dup 0)
13867                             (const_int -1)))
13868               (clobber (match_scratch:CC 2 ""))
13869               (clobber (match_scratch:SI 3 ""))])]
13870   "TARGET_32BIT"
13871   "")
13872
13873 (define_expand "ctrdi"
13874   [(parallel [(set (pc)
13875                    (if_then_else (ne (match_operand:DI 0 "register_operand" "")
13876                                      (const_int 1))
13877                                  (label_ref (match_operand 1 "" ""))
13878                                  (pc)))
13879               (set (match_dup 0)
13880                    (plus:DI (match_dup 0)
13881                             (const_int -1)))
13882               (clobber (match_scratch:CC 2 ""))
13883               (clobber (match_scratch:DI 3 ""))])]
13884   "TARGET_64BIT"
13885   "")
13886
13887 ;; We need to be able to do this for any operand, including MEM, or we
13888 ;; will cause reload to blow up since we don't allow output reloads on
13889 ;; JUMP_INSNs.
13890 ;; For the length attribute to be calculated correctly, the
13891 ;; label MUST be operand 0.
13892
13893 (define_insn "*ctrsi_internal1"
13894   [(set (pc)
13895         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
13896                           (const_int 1))
13897                       (label_ref (match_operand 0 "" ""))
13898                       (pc)))
13899    (set (match_operand:SI 2 "register_operand" "=1,*r,m,*q*c*l")
13900         (plus:SI (match_dup 1)
13901                  (const_int -1)))
13902    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13903    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
13904   "TARGET_32BIT"
13905   "*
13906 {
13907   if (which_alternative != 0)
13908     return \"#\";
13909   else if (get_attr_length (insn) == 4)
13910     return \"{bdn|bdnz} %l0\";
13911   else
13912     return \"bdz $+8\;b %l0\";
13913 }"
13914   [(set_attr "type" "branch")
13915    (set_attr "length" "*,12,16,16")])
13916
13917 (define_insn "*ctrsi_internal2"
13918   [(set (pc)
13919         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
13920                           (const_int 1))
13921                       (pc)
13922                       (label_ref (match_operand 0 "" ""))))
13923    (set (match_operand:SI 2 "register_operand" "=1,*r,m,*q*c*l")
13924         (plus:SI (match_dup 1)
13925                  (const_int -1)))
13926    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13927    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
13928   "TARGET_32BIT"
13929   "*
13930 {
13931   if (which_alternative != 0)
13932     return \"#\";
13933   else if (get_attr_length (insn) == 4)
13934     return \"bdz %l0\";
13935   else
13936     return \"{bdn|bdnz} $+8\;b %l0\";
13937 }"
13938   [(set_attr "type" "branch")
13939    (set_attr "length" "*,12,16,16")])
13940
13941 (define_insn "*ctrdi_internal1"
13942   [(set (pc)
13943         (if_then_else (ne (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
13944                           (const_int 1))
13945                       (label_ref (match_operand 0 "" ""))
13946                       (pc)))
13947    (set (match_operand:DI 2 "register_operand" "=1,*r,m,*c*l")
13948         (plus:DI (match_dup 1)
13949                  (const_int -1)))
13950    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13951    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
13952   "TARGET_64BIT"
13953   "*
13954 {
13955   if (which_alternative != 0)
13956     return \"#\";
13957   else if (get_attr_length (insn) == 4)
13958     return \"{bdn|bdnz} %l0\";
13959   else
13960     return \"bdz $+8\;b %l0\";
13961 }"
13962   [(set_attr "type" "branch")
13963    (set_attr "length" "*,12,16,16")])
13964
13965 (define_insn "*ctrdi_internal2"
13966   [(set (pc)
13967         (if_then_else (ne (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
13968                           (const_int 1))
13969                       (pc)
13970                       (label_ref (match_operand 0 "" ""))))
13971    (set (match_operand:DI 2 "register_operand" "=1,*r,m,*c*l")
13972         (plus:DI (match_dup 1)
13973                  (const_int -1)))
13974    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13975    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
13976   "TARGET_64BIT"
13977   "*
13978 {
13979   if (which_alternative != 0)
13980     return \"#\";
13981   else if (get_attr_length (insn) == 4)
13982     return \"bdz %l0\";
13983   else
13984     return \"{bdn|bdnz} $+8\;b %l0\";
13985 }"
13986   [(set_attr "type" "branch")
13987    (set_attr "length" "*,12,16,16")])
13988
13989 ;; Similar, but we can use GE since we have a REG_NONNEG.
13990
13991 (define_insn "*ctrsi_internal3"
13992   [(set (pc)
13993         (if_then_else (ge (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
13994                           (const_int 0))
13995                       (label_ref (match_operand 0 "" ""))
13996                       (pc)))
13997    (set (match_operand:SI 2 "register_operand" "=1,*r,m,*q*c*l")
13998         (plus:SI (match_dup 1)
13999                  (const_int -1)))
14000    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14001    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14002   "TARGET_32BIT && find_reg_note (insn, REG_NONNEG, 0)"
14003   "*
14004 {
14005   if (which_alternative != 0)
14006     return \"#\";
14007   else if (get_attr_length (insn) == 4)
14008     return \"{bdn|bdnz} %l0\";
14009   else
14010     return \"bdz $+8\;b %l0\";
14011 }"
14012   [(set_attr "type" "branch")
14013    (set_attr "length" "*,12,16,16")])
14014
14015 (define_insn "*ctrsi_internal4"
14016   [(set (pc)
14017         (if_then_else (ge (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14018                           (const_int 0))
14019                       (pc)
14020                       (label_ref (match_operand 0 "" ""))))
14021    (set (match_operand:SI 2 "register_operand" "=1,*r,m,*q*c*l")
14022         (plus:SI (match_dup 1)
14023                  (const_int -1)))
14024    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14025    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14026   "TARGET_32BIT && find_reg_note (insn, REG_NONNEG, 0)"
14027   "*
14028 {
14029   if (which_alternative != 0)
14030     return \"#\";
14031   else if (get_attr_length (insn) == 4)
14032     return \"bdz %l0\";
14033   else
14034     return \"{bdn|bdnz} $+8\;b %l0\";
14035 }"
14036   [(set_attr "type" "branch")
14037    (set_attr "length" "*,12,16,16")])
14038
14039 (define_insn "*ctrdi_internal3"
14040   [(set (pc)
14041         (if_then_else (ge (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14042                           (const_int 0))
14043                       (label_ref (match_operand 0 "" ""))
14044                       (pc)))
14045    (set (match_operand:DI 2 "register_operand" "=1,*r,m,*c*l")
14046         (plus:DI (match_dup 1)
14047                  (const_int -1)))
14048    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14049    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14050   "TARGET_64BIT && find_reg_note (insn, REG_NONNEG, 0)"
14051   "*
14052 {
14053   if (which_alternative != 0)
14054     return \"#\";
14055   else if (get_attr_length (insn) == 4)
14056     return \"{bdn|bdnz} %l0\";
14057   else
14058     return \"bdz $+8\;b %l0\";
14059 }"
14060   [(set_attr "type" "branch")
14061    (set_attr "length" "*,12,16,16")])
14062
14063 (define_insn "*ctrdi_internal4"
14064   [(set (pc)
14065         (if_then_else (ge (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14066                           (const_int 0))
14067                       (pc)
14068                       (label_ref (match_operand 0 "" ""))))
14069    (set (match_operand:DI 2 "register_operand" "=1,*r,m,*c*l")
14070         (plus:DI (match_dup 1)
14071                  (const_int -1)))
14072    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14073    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14074   "TARGET_64BIT && find_reg_note (insn, REG_NONNEG, 0)"
14075   "*
14076 {
14077   if (which_alternative != 0)
14078     return \"#\";
14079   else if (get_attr_length (insn) == 4)
14080     return \"bdz %l0\";
14081   else
14082     return \"{bdn|bdnz} $+8\;b %l0\";
14083 }"
14084   [(set_attr "type" "branch")
14085    (set_attr "length" "*,12,16,16")])
14086
14087 ;; Similar but use EQ
14088
14089 (define_insn "*ctrsi_internal5"
14090   [(set (pc)
14091         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14092                           (const_int 1))
14093                       (label_ref (match_operand 0 "" ""))
14094                       (pc)))
14095    (set (match_operand:SI 2 "register_operand" "=1,*r,m,*q*c*l")
14096         (plus:SI (match_dup 1)
14097                  (const_int -1)))
14098    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14099    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14100   "TARGET_32BIT"
14101   "*
14102 {
14103   if (which_alternative != 0)
14104     return \"#\";
14105   else if (get_attr_length (insn) == 4)
14106     return \"bdz %l0\";
14107   else
14108     return \"{bdn|bdnz} $+8\;b %l0\";
14109 }"
14110   [(set_attr "type" "branch")
14111    (set_attr "length" "*,12,16,16")])
14112
14113 (define_insn "*ctrsi_internal6"
14114   [(set (pc)
14115         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14116                           (const_int 1))
14117                       (pc)
14118                       (label_ref (match_operand 0 "" ""))))
14119    (set (match_operand:SI 2 "register_operand" "=1,*r,m,*q*c*l")
14120         (plus:SI (match_dup 1)
14121                  (const_int -1)))
14122    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14123    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14124   "TARGET_32BIT"
14125   "*
14126 {
14127   if (which_alternative != 0)
14128     return \"#\";
14129   else if (get_attr_length (insn) == 4)
14130     return \"{bdn|bdnz} %l0\";
14131   else
14132     return \"bdz $+8\;b %l0\";
14133 }"
14134   [(set_attr "type" "branch")
14135    (set_attr "length" "*,12,16,16")])
14136
14137 (define_insn "*ctrdi_internal5"
14138   [(set (pc)
14139         (if_then_else (eq (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14140                           (const_int 1))
14141                       (label_ref (match_operand 0 "" ""))
14142                       (pc)))
14143    (set (match_operand:DI 2 "register_operand" "=1,*r,m,*c*l")
14144         (plus:DI (match_dup 1)
14145                  (const_int -1)))
14146    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14147    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14148   "TARGET_64BIT"
14149   "*
14150 {
14151   if (which_alternative != 0)
14152     return \"#\";
14153   else if (get_attr_length (insn) == 4)
14154     return \"bdz %l0\";
14155   else
14156     return \"{bdn|bdnz} $+8\;b %l0\";
14157 }"
14158   [(set_attr "type" "branch")
14159    (set_attr "length" "*,12,16,16")])
14160
14161 (define_insn "*ctrdi_internal6"
14162   [(set (pc)
14163         (if_then_else (eq (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14164                           (const_int 1))
14165                       (pc)
14166                       (label_ref (match_operand 0 "" ""))))
14167    (set (match_operand:DI 2 "register_operand" "=1,*r,m,*c*l")
14168         (plus:DI (match_dup 1)
14169                  (const_int -1)))
14170    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14171    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14172   "TARGET_64BIT"
14173   "*
14174 {
14175   if (which_alternative != 0)
14176     return \"#\";
14177   else if (get_attr_length (insn) == 4)
14178     return \"{bdn|bdnz} %l0\";
14179   else
14180     return \"bdz $+8\;b %l0\";
14181 }"
14182   [(set_attr "type" "branch")
14183    (set_attr "length" "*,12,16,16")])
14184
14185 ;; Now the splitters if we could not allocate the CTR register
14186
14187 (define_split
14188   [(set (pc)
14189         (if_then_else (match_operator 2 "comparison_operator"
14190                                       [(match_operand:SI 1 "gpc_reg_operand" "")
14191                                        (const_int 1)])
14192                       (match_operand 5 "" "")
14193                       (match_operand 6 "" "")))
14194    (set (match_operand:SI 0 "gpc_reg_operand" "")
14195         (plus:SI (match_dup 1)
14196                  (const_int -1)))
14197    (clobber (match_scratch:CC 3 ""))
14198    (clobber (match_scratch:SI 4 ""))]
14199   "TARGET_32BIT && reload_completed"
14200   [(parallel [(set (match_dup 3)
14201                    (compare:CC (plus:SI (match_dup 1)
14202                                         (const_int -1))
14203                                (const_int 0)))
14204               (set (match_dup 0)
14205                    (plus:SI (match_dup 1)
14206                             (const_int -1)))])
14207    (set (pc) (if_then_else (match_dup 7)
14208                            (match_dup 5)
14209                            (match_dup 6)))]
14210   "
14211 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
14212                          const0_rtx); }")
14213
14214 (define_split
14215   [(set (pc)
14216         (if_then_else (match_operator 2 "comparison_operator"
14217                                       [(match_operand:SI 1 "gpc_reg_operand" "")
14218                                        (const_int 1)])
14219                       (match_operand 5 "" "")
14220                       (match_operand 6 "" "")))
14221    (set (match_operand:SI 0 "nonimmediate_operand" "")
14222         (plus:SI (match_dup 1) (const_int -1)))
14223    (clobber (match_scratch:CC 3 ""))
14224    (clobber (match_scratch:SI 4 ""))]
14225   "TARGET_32BIT && reload_completed
14226    && ! gpc_reg_operand (operands[0], SImode)"
14227   [(parallel [(set (match_dup 3)
14228                    (compare:CC (plus:SI (match_dup 1)
14229                                         (const_int -1))
14230                                (const_int 0)))
14231               (set (match_dup 4)
14232                    (plus:SI (match_dup 1)
14233                             (const_int -1)))])
14234    (set (match_dup 0)
14235         (match_dup 4))
14236    (set (pc) (if_then_else (match_dup 7)
14237                            (match_dup 5)
14238                            (match_dup 6)))]
14239   "
14240 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
14241                          const0_rtx); }")
14242 (define_split
14243   [(set (pc)
14244         (if_then_else (match_operator 2 "comparison_operator"
14245                                       [(match_operand:DI 1 "gpc_reg_operand" "")
14246                                        (const_int 1)])
14247                       (match_operand 5 "" "")
14248                       (match_operand 6 "" "")))
14249    (set (match_operand:DI 0 "gpc_reg_operand" "")
14250         (plus:DI (match_dup 1)
14251                  (const_int -1)))
14252    (clobber (match_scratch:CC 3 ""))
14253    (clobber (match_scratch:DI 4 ""))]
14254   "TARGET_64BIT && reload_completed"
14255   [(parallel [(set (match_dup 3)
14256                    (compare:CC (plus:DI (match_dup 1)
14257                                         (const_int -1))
14258                                (const_int 0)))
14259               (set (match_dup 0)
14260                    (plus:DI (match_dup 1)
14261                             (const_int -1)))])
14262    (set (pc) (if_then_else (match_dup 7)
14263                            (match_dup 5)
14264                            (match_dup 6)))]
14265   "
14266 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
14267                          const0_rtx); }")
14268
14269 (define_split
14270   [(set (pc)
14271         (if_then_else (match_operator 2 "comparison_operator"
14272                                       [(match_operand:DI 1 "gpc_reg_operand" "")
14273                                        (const_int 1)])
14274                       (match_operand 5 "" "")
14275                       (match_operand 6 "" "")))
14276    (set (match_operand:DI 0 "nonimmediate_operand" "")
14277         (plus:DI (match_dup 1) (const_int -1)))
14278    (clobber (match_scratch:CC 3 ""))
14279    (clobber (match_scratch:DI 4 ""))]
14280   "TARGET_64BIT && reload_completed
14281    && ! gpc_reg_operand (operands[0], DImode)"
14282   [(parallel [(set (match_dup 3)
14283                    (compare:CC (plus:DI (match_dup 1)
14284                                         (const_int -1))
14285                                (const_int 0)))
14286               (set (match_dup 4)
14287                    (plus:DI (match_dup 1)
14288                             (const_int -1)))])
14289    (set (match_dup 0)
14290         (match_dup 4))
14291    (set (pc) (if_then_else (match_dup 7)
14292                            (match_dup 5)
14293                            (match_dup 6)))]
14294   "
14295 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
14296                          const0_rtx); }")
14297 \f
14298 (define_insn "trap"
14299   [(trap_if (const_int 1) (const_int 0))]
14300   ""
14301   "{t 31,0,0|trap}")
14302
14303 (define_expand "conditional_trap"
14304   [(trap_if (match_operator 0 "trap_comparison_operator"
14305                             [(match_dup 2) (match_dup 3)])
14306             (match_operand 1 "const_int_operand" ""))]
14307   ""
14308   "if (rs6000_compare_fp_p || operands[1] != const0_rtx) FAIL;
14309    operands[2] = rs6000_compare_op0;
14310    operands[3] = rs6000_compare_op1;")
14311
14312 (define_insn ""
14313   [(trap_if (match_operator 0 "trap_comparison_operator"
14314                             [(match_operand:SI 1 "register_operand" "r")
14315                              (match_operand:SI 2 "reg_or_short_operand" "rI")])
14316             (const_int 0))]
14317   ""
14318   "{t|tw}%V0%I2 %1,%2")
14319
14320 (define_insn ""
14321   [(trap_if (match_operator 0 "trap_comparison_operator"
14322                             [(match_operand:DI 1 "register_operand" "r")
14323                              (match_operand:DI 2 "reg_or_short_operand" "rI")])
14324             (const_int 0))]
14325   "TARGET_POWERPC64"
14326   "td%V0%I2 %1,%2")
14327 \f
14328 ;; Insns related to generating the function prologue and epilogue.
14329
14330 (define_expand "prologue"
14331   [(use (const_int 0))]
14332   "TARGET_SCHED_PROLOG"
14333   "
14334 {
14335       rs6000_emit_prologue ();
14336       DONE;
14337 }")
14338
14339 (define_insn "*movesi_from_cr_one"
14340   [(match_parallel 0 "mfcr_operation"
14341                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14342                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
14343                                      (match_operand 3 "immediate_operand" "n")]
14344                           UNSPEC_MOVESI_FROM_CR))])]
14345   "TARGET_MFCRF"
14346   "*
14347 {
14348   int mask = 0;
14349   int i;
14350   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14351   {
14352     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14353     operands[4] = GEN_INT (mask);
14354     output_asm_insn (\"mfcr %1,%4\", operands);
14355   }
14356   return \"\";
14357 }"
14358   [(set_attr "type" "mfcrf")])
14359
14360 (define_insn "movesi_from_cr"
14361   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14362         (unspec:SI [(reg:CC 68) (reg:CC 69) (reg:CC 70) (reg:CC 71) 
14363                     (reg:CC 72) (reg:CC 73) (reg:CC 74) (reg:CC 75)]
14364                    UNSPEC_MOVESI_FROM_CR))]
14365   ""
14366   "mfcr %0"
14367   [(set_attr "type" "mfcr")])
14368
14369 (define_insn "*stmw"
14370   [(match_parallel 0 "stmw_operation"
14371                    [(set (match_operand:SI 1 "memory_operand" "=m")
14372                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
14373   "TARGET_MULTIPLE"
14374   "{stm|stmw} %2,%1")
14375  
14376 (define_insn "*save_fpregs_si"
14377   [(match_parallel 0 "any_operand"
14378                    [(clobber (match_operand:SI 1 "register_operand" "=l"))
14379                     (use (match_operand:SI 2 "call_operand" "s"))
14380                     (set (match_operand:DF 3 "memory_operand" "=m")
14381                          (match_operand:DF 4 "gpc_reg_operand" "f"))])]
14382   "TARGET_32BIT"
14383   "bl %z2"
14384   [(set_attr "type" "branch")
14385    (set_attr "length" "4")])
14386
14387 (define_insn "*save_fpregs_di"
14388   [(match_parallel 0 "any_operand"
14389                    [(clobber (match_operand:DI 1 "register_operand" "=l"))
14390                     (use (match_operand:DI 2 "call_operand" "s"))
14391                     (set (match_operand:DF 3 "memory_operand" "=m")
14392                          (match_operand:DF 4 "gpc_reg_operand" "f"))])]
14393   "TARGET_64BIT"
14394   "bl %z2"
14395   [(set_attr "type" "branch")
14396    (set_attr "length" "4")])
14397
14398 ; These are to explain that changes to the stack pointer should
14399 ; not be moved over stores to stack memory.
14400 (define_insn "stack_tie"
14401   [(set (match_operand:BLK 0 "memory_operand" "+m")
14402         (unspec:BLK [(match_dup 0)] UNSPEC_TIE))]
14403   ""
14404   ""
14405   [(set_attr "length" "0")])
14406
14407
14408 (define_expand "epilogue"
14409   [(use (const_int 0))]
14410   "TARGET_SCHED_PROLOG"
14411   "
14412 {
14413       rs6000_emit_epilogue (FALSE);
14414       DONE;
14415 }")
14416
14417 ; On some processors, doing the mtcrf one CC register at a time is
14418 ; faster (like on the 604e).  On others, doing them all at once is
14419 ; faster; for instance, on the 601 and 750.
14420
14421 (define_expand "movsi_to_cr_one"
14422   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14423         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14424                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
14425   ""
14426   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
14427
14428 (define_insn "*movsi_to_cr"
14429   [(match_parallel 0 "mtcrf_operation"
14430                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
14431                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
14432                                      (match_operand 3 "immediate_operand" "n")]
14433                                     UNSPEC_MOVESI_TO_CR))])]
14434  ""
14435  "*
14436 {
14437   int mask = 0;
14438   int i;
14439   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14440     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14441   operands[4] = GEN_INT (mask);
14442   return \"mtcrf %4,%2\";
14443 }"
14444   [(set_attr "type" "mtcr")])
14445
14446 (define_insn "*mtcrfsi"
14447   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14448         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14449                     (match_operand 2 "immediate_operand" "n")]
14450                    UNSPEC_MOVESI_TO_CR))]
14451   "GET_CODE (operands[0]) == REG 
14452    && CR_REGNO_P (REGNO (operands[0]))
14453    && GET_CODE (operands[2]) == CONST_INT
14454    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
14455   "mtcrf %R0,%1"
14456   [(set_attr "type" "mtcr")])
14457
14458 ; The load-multiple instructions have similar properties.
14459 ; Note that "load_multiple" is a name known to the machine-independent
14460 ; code that actually corresponds to the powerpc load-string.
14461
14462 (define_insn "*lmw"
14463   [(match_parallel 0 "lmw_operation"
14464                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14465                          (match_operand:SI 2 "memory_operand" "m"))])]
14466   "TARGET_MULTIPLE"
14467   "{lm|lmw} %1,%2")
14468  
14469 (define_insn "*return_internal_si"
14470   [(return)
14471    (use (match_operand:SI 0 "register_operand" "lc"))]
14472   "TARGET_32BIT"
14473   "b%T0"
14474   [(set_attr "type" "jmpreg")])
14475
14476 (define_insn "*return_internal_di"
14477   [(return)
14478    (use (match_operand:DI 0 "register_operand" "lc"))]
14479   "TARGET_64BIT"
14480   "b%T0"
14481   [(set_attr "type" "jmpreg")])
14482
14483 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
14484 ; stuff was in GCC.  Oh, and "any_operand" is a bit flexible...
14485
14486 (define_insn "*return_and_restore_fpregs_si"
14487  [(match_parallel 0 "any_operand"
14488                   [(return)
14489                    (use (match_operand:SI 1 "register_operand" "l"))
14490                    (use (match_operand:SI 2 "call_operand" "s"))
14491                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
14492                         (match_operand:DF 4 "memory_operand" "m"))])]
14493  "TARGET_32BIT"
14494  "b %z2")
14495
14496 (define_insn "*return_and_restore_fpregs_di"
14497  [(match_parallel 0 "any_operand"
14498                   [(return)
14499                    (use (match_operand:DI 1 "register_operand" "l"))
14500                    (use (match_operand:DI 2 "call_operand" "s"))
14501                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
14502                         (match_operand:DF 4 "memory_operand" "m"))])]
14503  "TARGET_64BIT"
14504  "b %z2")
14505
14506 ; This is used in compiling the unwind routines.
14507 (define_expand "eh_return"
14508   [(use (match_operand 0 "general_operand" ""))]
14509   ""
14510   "
14511 {
14512   if (TARGET_32BIT)
14513     emit_insn (gen_eh_set_lr_si (operands[0]));
14514   else
14515     emit_insn (gen_eh_set_lr_di (operands[0]));
14516   DONE;
14517 }")
14518
14519 ; We can't expand this before we know where the link register is stored.
14520 (define_insn "eh_set_lr_si"
14521   [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
14522                     UNSPECV_EH_RR)
14523    (clobber (match_scratch:SI 1 "=&b"))]
14524   "TARGET_32BIT"
14525   "#")
14526
14527 (define_insn "eh_set_lr_di"
14528   [(unspec_volatile [(match_operand:DI 0 "register_operand" "r")]
14529                     UNSPECV_EH_RR)
14530    (clobber (match_scratch:DI 1 "=&b"))]
14531   "TARGET_64BIT"
14532   "#")
14533
14534 (define_split
14535   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
14536    (clobber (match_scratch 1 ""))]
14537   "reload_completed"
14538   [(const_int 0)]
14539   "
14540 {
14541   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
14542   DONE;
14543 }")
14544
14545 (define_insn "prefetch"
14546   [(prefetch (match_operand:V4SI 0 "address_operand" "p")
14547              (match_operand:SI 1 "const_int_operand" "n")
14548              (match_operand:SI 2 "const_int_operand" "n"))]
14549   "TARGET_POWERPC"
14550   "*
14551 {
14552   if (GET_CODE (operands[0]) == REG)
14553     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
14554   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
14555 }"
14556   [(set_attr "type" "load")])
14557
14558 (include "altivec.md")
14559 (include "spe.md")