]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/gcc/config/rs6000/rs6000.md
This commit was generated by cvs2svn to compensate for changes in r157181,
[FreeBSD/FreeBSD.git] / contrib / 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, 2005 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    (UNSPEC_MV_CR_EQ            31)     ; move_from_CR_eq_bit
54   ])
55
56 ;;
57 ;; UNSPEC_VOLATILE usage
58 ;;
59
60 (define_constants
61   [(UNSPECV_BLOCK               0)
62    (UNSPECV_EH_RR               9)      ; eh_reg_restore
63   ])
64 \f
65 ;; Define an insn type attribute.  This is used in function unit delay
66 ;; computations.
67 (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"
68   (const_string "integer"))
69
70 ;; Length (in bytes).
71 ; '(pc)' in the following doesn't include the instruction itself; it is 
72 ; calculated as if the instruction had zero size.
73 (define_attr "length" ""
74   (if_then_else (eq_attr "type" "branch")
75                 (if_then_else (and (ge (minus (match_dup 0) (pc))
76                                        (const_int -32768))
77                                    (lt (minus (match_dup 0) (pc))
78                                        (const_int 32764)))
79                               (const_int 4)
80                               (const_int 8))
81                 (const_int 4)))
82
83 ;; Processor type -- this attribute must exactly match the processor_type
84 ;; enumeration in rs6000.h.
85
86 (define_attr "cpu" "rios1,rios2,rs64a,mpccore,ppc403,ppc405,ppc440,ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630,ppc750,ppc7400,ppc7450,ppc8540,power4,power5"
87   (const (symbol_ref "rs6000_cpu_attr")))
88
89 (automata_option "ndfa")
90
91 (include "rios1.md")
92 (include "rios2.md")
93 (include "rs64.md")
94 (include "mpc.md")
95 (include "40x.md")
96 (include "440.md")
97 (include "603.md")
98 (include "6xx.md")
99 (include "7xx.md")
100 (include "7450.md")
101 (include "8540.md")
102 (include "power4.md")
103 (include "power5.md")
104
105 \f
106 ;; Start with fixed-point load and store insns.  Here we put only the more
107 ;; complex forms.  Basic data transfer is done later.
108
109 (define_expand "zero_extendqidi2"
110   [(set (match_operand:DI 0 "gpc_reg_operand" "")
111         (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "")))]
112   "TARGET_POWERPC64"
113   "")
114
115 (define_insn ""
116   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
117         (zero_extend:DI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
118   "TARGET_POWERPC64"
119   "@
120    lbz%U1%X1 %0,%1
121    rldicl %0,%1,0,56"
122   [(set_attr "type" "load,*")])
123
124 (define_insn ""
125   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
126         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
127                     (const_int 0)))
128    (clobber (match_scratch:DI 2 "=r,r"))]
129   "TARGET_64BIT"
130   "@
131    rldicl. %2,%1,0,56
132    #"
133   [(set_attr "type" "compare")
134    (set_attr "length" "4,8")])
135
136 (define_split
137   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
138         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
139                     (const_int 0)))
140    (clobber (match_scratch:DI 2 ""))]
141   "TARGET_POWERPC64 && reload_completed"
142   [(set (match_dup 2)
143         (zero_extend:DI (match_dup 1)))
144    (set (match_dup 0)
145         (compare:CC (match_dup 2)
146                     (const_int 0)))]
147   "")
148
149 (define_insn ""
150   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
151         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
152                     (const_int 0)))
153    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
154         (zero_extend:DI (match_dup 1)))]
155   "TARGET_64BIT"
156   "@
157    rldicl. %0,%1,0,56
158    #"
159   [(set_attr "type" "compare")
160    (set_attr "length" "4,8")])
161
162 (define_split
163   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
164         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
165                     (const_int 0)))
166    (set (match_operand:DI 0 "gpc_reg_operand" "")
167         (zero_extend:DI (match_dup 1)))]
168   "TARGET_POWERPC64 && reload_completed"
169   [(set (match_dup 0)
170         (zero_extend:DI (match_dup 1)))
171    (set (match_dup 2)
172         (compare:CC (match_dup 0)
173                     (const_int 0)))]
174   "")
175
176 (define_insn "extendqidi2"
177   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
178         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
179   "TARGET_POWERPC64"
180   "extsb %0,%1")
181
182 (define_insn ""
183   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
184         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
185                     (const_int 0)))
186    (clobber (match_scratch:DI 2 "=r,r"))]
187   "TARGET_64BIT"
188   "@
189    extsb. %2,%1
190    #"
191   [(set_attr "type" "compare")
192    (set_attr "length" "4,8")])
193
194 (define_split
195   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
196         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
197                     (const_int 0)))
198    (clobber (match_scratch:DI 2 ""))]
199   "TARGET_POWERPC64 && reload_completed"
200   [(set (match_dup 2)
201         (sign_extend:DI (match_dup 1)))
202    (set (match_dup 0)
203         (compare:CC (match_dup 2)
204                     (const_int 0)))]
205   "")
206
207 (define_insn ""
208   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
209         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
210                     (const_int 0)))
211    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
212         (sign_extend:DI (match_dup 1)))]
213   "TARGET_64BIT"
214   "@
215    extsb. %0,%1
216    #"
217   [(set_attr "type" "compare")
218    (set_attr "length" "4,8")])
219
220 (define_split
221   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
222         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
223                     (const_int 0)))
224    (set (match_operand:DI 0 "gpc_reg_operand" "")
225         (sign_extend:DI (match_dup 1)))]
226   "TARGET_POWERPC64 && reload_completed"
227   [(set (match_dup 0)
228         (sign_extend:DI (match_dup 1)))
229    (set (match_dup 2)
230         (compare:CC (match_dup 0)
231                     (const_int 0)))]
232   "")
233
234 (define_expand "zero_extendhidi2"
235   [(set (match_operand:DI 0 "gpc_reg_operand" "")
236         (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
237   "TARGET_POWERPC64"
238   "")
239
240 (define_insn ""
241   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
242         (zero_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
243   "TARGET_POWERPC64"
244   "@
245    lhz%U1%X1 %0,%1
246    rldicl %0,%1,0,48"
247   [(set_attr "type" "load,*")])
248
249 (define_insn ""
250   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
251         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
252                     (const_int 0)))
253    (clobber (match_scratch:DI 2 "=r,r"))]
254   "TARGET_64BIT"
255   "@
256    rldicl. %2,%1,0,48
257    #"
258   [(set_attr "type" "compare")
259    (set_attr "length" "4,8")])
260
261 (define_split
262   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
263         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
264                     (const_int 0)))
265    (clobber (match_scratch:DI 2 ""))]
266   "TARGET_POWERPC64 && reload_completed"
267   [(set (match_dup 2)
268         (zero_extend:DI (match_dup 1)))
269    (set (match_dup 0)
270         (compare:CC (match_dup 2)
271                     (const_int 0)))]
272   "")
273
274 (define_insn ""
275   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
276         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
277                     (const_int 0)))
278    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
279         (zero_extend:DI (match_dup 1)))]
280   "TARGET_64BIT"
281   "@
282    rldicl. %0,%1,0,48
283    #"
284   [(set_attr "type" "compare")
285    (set_attr "length" "4,8")])
286
287 (define_split
288   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
289         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
290                     (const_int 0)))
291    (set (match_operand:DI 0 "gpc_reg_operand" "")
292         (zero_extend:DI (match_dup 1)))]
293   "TARGET_POWERPC64 && reload_completed"
294   [(set (match_dup 0)
295         (zero_extend:DI (match_dup 1)))
296    (set (match_dup 2)
297         (compare:CC (match_dup 0)
298                     (const_int 0)))]
299   "")
300
301 (define_expand "extendhidi2"
302   [(set (match_operand:DI 0 "gpc_reg_operand" "")
303         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
304   "TARGET_POWERPC64"
305   "")
306
307 (define_insn ""
308   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
309         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
310   "TARGET_POWERPC64"
311   "@
312    lha%U1%X1 %0,%1
313    extsh %0,%1"
314   [(set_attr "type" "load_ext,*")])
315
316 (define_insn ""
317   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
318         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
319                     (const_int 0)))
320    (clobber (match_scratch:DI 2 "=r,r"))]
321   "TARGET_64BIT"
322   "@
323    extsh. %2,%1
324    #"
325   [(set_attr "type" "compare")
326    (set_attr "length" "4,8")])
327
328 (define_split
329   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
330         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
331                     (const_int 0)))
332    (clobber (match_scratch:DI 2 ""))]
333   "TARGET_POWERPC64 && reload_completed"
334   [(set (match_dup 2)
335         (sign_extend:DI (match_dup 1)))
336    (set (match_dup 0)
337         (compare:CC (match_dup 2)
338                     (const_int 0)))]
339   "")
340
341 (define_insn ""
342   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
343         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
344                     (const_int 0)))
345    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
346         (sign_extend:DI (match_dup 1)))]
347   "TARGET_64BIT"
348   "@
349    extsh. %0,%1
350    #"
351   [(set_attr "type" "compare")
352    (set_attr "length" "4,8")])
353
354 (define_split
355   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
356         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
357                     (const_int 0)))
358    (set (match_operand:DI 0 "gpc_reg_operand" "")
359         (sign_extend:DI (match_dup 1)))]
360   "TARGET_POWERPC64 && reload_completed"
361   [(set (match_dup 0)
362         (sign_extend:DI (match_dup 1)))
363    (set (match_dup 2)
364         (compare:CC (match_dup 0)
365                     (const_int 0)))]
366   "")
367
368 (define_expand "zero_extendsidi2"
369   [(set (match_operand:DI 0 "gpc_reg_operand" "")
370         (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
371   "TARGET_POWERPC64"
372   "")
373
374 (define_insn ""
375   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
376         (zero_extend:DI (match_operand:SI 1 "reg_or_mem_operand" "m,r")))]
377   "TARGET_POWERPC64"
378   "@
379    lwz%U1%X1 %0,%1
380    rldicl %0,%1,0,32"
381   [(set_attr "type" "load,*")])
382
383 (define_insn ""
384   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
385         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
386                     (const_int 0)))
387    (clobber (match_scratch:DI 2 "=r,r"))]
388   "TARGET_64BIT"
389   "@
390    rldicl. %2,%1,0,32
391    #"
392   [(set_attr "type" "compare")
393    (set_attr "length" "4,8")])
394
395 (define_split
396   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
397         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
398                     (const_int 0)))
399    (clobber (match_scratch:DI 2 ""))]
400   "TARGET_POWERPC64 && reload_completed"
401   [(set (match_dup 2)
402         (zero_extend:DI (match_dup 1)))
403    (set (match_dup 0)
404         (compare:CC (match_dup 2)
405                     (const_int 0)))]
406   "")
407
408 (define_insn ""
409   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
410         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
411                     (const_int 0)))
412    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
413         (zero_extend:DI (match_dup 1)))]
414   "TARGET_64BIT"
415   "@
416    rldicl. %0,%1,0,32
417    #"
418   [(set_attr "type" "compare")
419    (set_attr "length" "4,8")])
420
421 (define_split
422   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
423         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
424                     (const_int 0)))
425    (set (match_operand:DI 0 "gpc_reg_operand" "")
426         (zero_extend:DI (match_dup 1)))]
427   "TARGET_POWERPC64 && reload_completed"
428   [(set (match_dup 0)
429         (zero_extend:DI (match_dup 1)))
430    (set (match_dup 2)
431         (compare:CC (match_dup 0)
432                     (const_int 0)))]
433   "")
434
435 (define_expand "extendsidi2"
436   [(set (match_operand:DI 0 "gpc_reg_operand" "")
437         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
438   "TARGET_POWERPC64"
439   "")
440
441 (define_insn ""
442   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
443         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
444   "TARGET_POWERPC64"
445   "@
446    lwa%U1%X1 %0,%1
447    extsw %0,%1"
448   [(set_attr "type" "load_ext,*")])
449
450 (define_insn ""
451   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
452         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
453                     (const_int 0)))
454    (clobber (match_scratch:DI 2 "=r,r"))]
455   "TARGET_64BIT"
456   "@
457    extsw. %2,%1
458    #"
459   [(set_attr "type" "compare")
460    (set_attr "length" "4,8")])
461
462 (define_split
463   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
464         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
465                     (const_int 0)))
466    (clobber (match_scratch:DI 2 ""))]
467   "TARGET_POWERPC64 && reload_completed"
468   [(set (match_dup 2)
469         (sign_extend:DI (match_dup 1)))
470    (set (match_dup 0)
471         (compare:CC (match_dup 2)
472                     (const_int 0)))]
473   "")
474
475 (define_insn ""
476   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
477         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
478                     (const_int 0)))
479    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
480         (sign_extend:DI (match_dup 1)))]
481   "TARGET_64BIT"
482   "@
483    extsw. %0,%1
484    #"
485   [(set_attr "type" "compare")
486    (set_attr "length" "4,8")])
487
488 (define_split
489   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
490         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
491                     (const_int 0)))
492    (set (match_operand:DI 0 "gpc_reg_operand" "")
493         (sign_extend:DI (match_dup 1)))]
494   "TARGET_POWERPC64 && reload_completed"
495   [(set (match_dup 0)
496         (sign_extend:DI (match_dup 1)))
497    (set (match_dup 2)
498         (compare:CC (match_dup 0)
499                     (const_int 0)))]
500   "")
501
502 (define_expand "zero_extendqisi2"
503   [(set (match_operand:SI 0 "gpc_reg_operand" "")
504         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
505   ""
506   "")
507
508 (define_insn ""
509   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
510         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
511   ""
512   "@
513    lbz%U1%X1 %0,%1
514    {rlinm|rlwinm} %0,%1,0,0xff"
515   [(set_attr "type" "load,*")])
516
517 (define_insn ""
518   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
519         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
520                     (const_int 0)))
521    (clobber (match_scratch:SI 2 "=r,r"))]
522   ""
523   "@
524    {andil.|andi.} %2,%1,0xff
525    #"
526   [(set_attr "type" "compare")
527    (set_attr "length" "4,8")])
528
529 (define_split
530   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
531         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
532                     (const_int 0)))
533    (clobber (match_scratch:SI 2 ""))]
534   "reload_completed"
535   [(set (match_dup 2)
536         (zero_extend:SI (match_dup 1)))
537    (set (match_dup 0)
538         (compare:CC (match_dup 2)
539                     (const_int 0)))]
540   "")
541
542 (define_insn ""
543   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
544         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
545                     (const_int 0)))
546    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
547         (zero_extend:SI (match_dup 1)))]
548   ""
549   "@
550    {andil.|andi.} %0,%1,0xff
551    #"
552   [(set_attr "type" "compare")
553    (set_attr "length" "4,8")])
554
555 (define_split
556   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
557         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
558                     (const_int 0)))
559    (set (match_operand:SI 0 "gpc_reg_operand" "")
560         (zero_extend:SI (match_dup 1)))]
561   "reload_completed"
562   [(set (match_dup 0)
563         (zero_extend:SI (match_dup 1)))
564    (set (match_dup 2)
565         (compare:CC (match_dup 0)
566                     (const_int 0)))]
567   "")
568
569 (define_expand "extendqisi2"
570   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
571    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
572   ""
573   "
574 {
575   if (TARGET_POWERPC)
576     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
577   else if (TARGET_POWER)
578     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
579   else
580     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
581   DONE;
582 }")
583
584 (define_insn "extendqisi2_ppc"
585   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
586         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
587   "TARGET_POWERPC"
588   "extsb %0,%1")
589
590 (define_insn ""
591   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
592         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
593                     (const_int 0)))
594    (clobber (match_scratch:SI 2 "=r,r"))]
595   "TARGET_POWERPC"
596   "@
597    extsb. %2,%1
598    #"
599   [(set_attr "type" "compare")
600    (set_attr "length" "4,8")])
601
602 (define_split
603   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
604         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
605                     (const_int 0)))
606    (clobber (match_scratch:SI 2 ""))]
607   "TARGET_POWERPC && reload_completed"
608   [(set (match_dup 2)
609         (sign_extend:SI (match_dup 1)))
610    (set (match_dup 0)
611         (compare:CC (match_dup 2)
612                     (const_int 0)))]
613   "")
614
615 (define_insn ""
616   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
617         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
618                     (const_int 0)))
619    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
620         (sign_extend:SI (match_dup 1)))]
621   "TARGET_POWERPC"
622   "@
623    extsb. %0,%1
624    #"
625   [(set_attr "type" "compare")
626    (set_attr "length" "4,8")])
627
628 (define_split
629   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
630         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
631                     (const_int 0)))
632    (set (match_operand:SI 0 "gpc_reg_operand" "")
633         (sign_extend:SI (match_dup 1)))]
634   "TARGET_POWERPC && reload_completed"
635   [(set (match_dup 0)
636         (sign_extend:SI (match_dup 1)))
637    (set (match_dup 2)
638         (compare:CC (match_dup 0)
639                     (const_int 0)))]
640   "")
641
642 (define_expand "extendqisi2_power"
643   [(parallel [(set (match_dup 2)
644                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
645                               (const_int 24)))
646               (clobber (scratch:SI))])
647    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
648                    (ashiftrt:SI (match_dup 2)
649                                 (const_int 24)))
650               (clobber (scratch:SI))])]
651   "TARGET_POWER"
652   "
653 { operands[1] = gen_lowpart (SImode, operands[1]);
654   operands[2] = gen_reg_rtx (SImode); }")
655
656 (define_expand "extendqisi2_no_power"
657   [(set (match_dup 2)
658         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
659                    (const_int 24)))
660    (set (match_operand:SI 0 "gpc_reg_operand" "")
661         (ashiftrt:SI (match_dup 2)
662                      (const_int 24)))]
663   "! TARGET_POWER && ! TARGET_POWERPC"
664   "
665 { operands[1] = gen_lowpart (SImode, operands[1]);
666   operands[2] = gen_reg_rtx (SImode); }")
667
668 (define_expand "zero_extendqihi2"
669   [(set (match_operand:HI 0 "gpc_reg_operand" "")
670         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
671   ""
672   "")
673
674 (define_insn ""
675   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
676         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
677   ""
678   "@
679    lbz%U1%X1 %0,%1
680    {rlinm|rlwinm} %0,%1,0,0xff"
681   [(set_attr "type" "load,*")])
682
683 (define_insn ""
684   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
685         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
686                     (const_int 0)))
687    (clobber (match_scratch:HI 2 "=r,r"))]
688   ""
689   "@
690    {andil.|andi.} %2,%1,0xff
691    #"
692   [(set_attr "type" "compare")
693    (set_attr "length" "4,8")])
694
695 (define_split
696   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
697         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
698                     (const_int 0)))
699    (clobber (match_scratch:HI 2 ""))]
700   "reload_completed"
701   [(set (match_dup 2)
702         (zero_extend:HI (match_dup 1)))
703    (set (match_dup 0)
704         (compare:CC (match_dup 2)
705                     (const_int 0)))]
706   "")
707
708 (define_insn ""
709   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
710         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
711                     (const_int 0)))
712    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
713         (zero_extend:HI (match_dup 1)))]
714   ""
715   "@
716    {andil.|andi.} %0,%1,0xff
717    #"
718   [(set_attr "type" "compare")
719    (set_attr "length" "4,8")])
720
721 (define_split
722   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
723         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
724                     (const_int 0)))
725    (set (match_operand:HI 0 "gpc_reg_operand" "")
726         (zero_extend:HI (match_dup 1)))]
727   "reload_completed"
728   [(set (match_dup 0)
729         (zero_extend:HI (match_dup 1)))
730    (set (match_dup 2)
731         (compare:CC (match_dup 0)
732                     (const_int 0)))]
733   "")
734
735 (define_expand "extendqihi2"
736   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
737    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
738   ""
739   "
740 {
741   if (TARGET_POWERPC)
742     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
743   else if (TARGET_POWER)
744     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
745   else
746     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
747   DONE;
748 }")
749
750 (define_insn "extendqihi2_ppc"
751   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
752         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
753   "TARGET_POWERPC"
754   "extsb %0,%1")
755
756 (define_insn ""
757   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
758         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
759                     (const_int 0)))
760    (clobber (match_scratch:HI 2 "=r,r"))]
761   "TARGET_POWERPC"
762   "@
763    extsb. %2,%1
764    #"
765   [(set_attr "type" "compare")
766    (set_attr "length" "4,8")])
767
768 (define_split
769   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
770         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
771                     (const_int 0)))
772    (clobber (match_scratch:HI 2 ""))]
773   "TARGET_POWERPC && reload_completed"
774   [(set (match_dup 2)
775         (sign_extend:HI (match_dup 1)))
776    (set (match_dup 0)
777         (compare:CC (match_dup 2)
778                     (const_int 0)))]
779   "")
780
781 (define_insn ""
782   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
783         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
784                     (const_int 0)))
785    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
786         (sign_extend:HI (match_dup 1)))]
787   "TARGET_POWERPC"
788   "@
789    extsb. %0,%1
790    #"
791   [(set_attr "type" "compare")
792    (set_attr "length" "4,8")])
793
794 (define_split
795   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
796         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
797                     (const_int 0)))
798    (set (match_operand:HI 0 "gpc_reg_operand" "")
799         (sign_extend:HI (match_dup 1)))]
800   "TARGET_POWERPC && reload_completed"
801   [(set (match_dup 0)
802         (sign_extend:HI (match_dup 1)))
803    (set (match_dup 2)
804         (compare:CC (match_dup 0)
805                     (const_int 0)))]
806   "")
807
808 (define_expand "extendqihi2_power"
809   [(parallel [(set (match_dup 2)
810                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
811                               (const_int 24)))
812               (clobber (scratch:SI))])
813    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
814                    (ashiftrt:SI (match_dup 2)
815                                 (const_int 24)))
816               (clobber (scratch:SI))])]
817   "TARGET_POWER"
818   "
819 { operands[0] = gen_lowpart (SImode, operands[0]);
820   operands[1] = gen_lowpart (SImode, operands[1]);
821   operands[2] = gen_reg_rtx (SImode); }")
822
823 (define_expand "extendqihi2_no_power"
824   [(set (match_dup 2)
825         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
826                    (const_int 24)))
827    (set (match_operand:HI 0 "gpc_reg_operand" "")
828         (ashiftrt:SI (match_dup 2)
829                      (const_int 24)))]
830   "! TARGET_POWER && ! TARGET_POWERPC"
831   "
832 { operands[0] = gen_lowpart (SImode, operands[0]);
833   operands[1] = gen_lowpart (SImode, operands[1]);
834   operands[2] = gen_reg_rtx (SImode); }")
835
836 (define_expand "zero_extendhisi2"
837   [(set (match_operand:SI 0 "gpc_reg_operand" "")
838         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
839   ""
840   "")
841
842 (define_insn ""
843   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
844         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
845   ""
846   "@
847    lhz%U1%X1 %0,%1
848    {rlinm|rlwinm} %0,%1,0,0xffff"
849   [(set_attr "type" "load,*")])
850
851 (define_insn ""
852   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
853         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
854                     (const_int 0)))
855    (clobber (match_scratch:SI 2 "=r,r"))]
856   ""
857   "@
858    {andil.|andi.} %2,%1,0xffff
859    #"
860   [(set_attr "type" "compare")
861    (set_attr "length" "4,8")])
862
863 (define_split
864   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
865         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
866                     (const_int 0)))
867    (clobber (match_scratch:SI 2 ""))]
868   "reload_completed"
869   [(set (match_dup 2)
870         (zero_extend:SI (match_dup 1)))
871    (set (match_dup 0)
872         (compare:CC (match_dup 2)
873                     (const_int 0)))]
874   "")
875
876 (define_insn ""
877   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
878         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
879                     (const_int 0)))
880    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
881         (zero_extend:SI (match_dup 1)))]
882   ""
883   "@
884    {andil.|andi.} %0,%1,0xffff
885    #"
886   [(set_attr "type" "compare")
887    (set_attr "length" "4,8")])
888
889 (define_split
890   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
891         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
892                     (const_int 0)))
893    (set (match_operand:SI 0 "gpc_reg_operand" "")
894         (zero_extend:SI (match_dup 1)))]
895   "reload_completed"
896   [(set (match_dup 0)
897         (zero_extend:SI (match_dup 1)))
898    (set (match_dup 2)
899         (compare:CC (match_dup 0)
900                     (const_int 0)))]
901   "")
902
903 (define_expand "extendhisi2"
904   [(set (match_operand:SI 0 "gpc_reg_operand" "")
905         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
906   ""
907   "")
908
909 (define_insn ""
910   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
911         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
912   ""
913   "@
914    lha%U1%X1 %0,%1
915    {exts|extsh} %0,%1"
916   [(set_attr "type" "load_ext,*")])
917
918 (define_insn ""
919   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
920         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
921                     (const_int 0)))
922    (clobber (match_scratch:SI 2 "=r,r"))]
923   ""
924   "@
925    {exts.|extsh.} %2,%1
926    #"
927   [(set_attr "type" "compare")
928    (set_attr "length" "4,8")])
929
930 (define_split
931   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
932         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
933                     (const_int 0)))
934    (clobber (match_scratch:SI 2 ""))]
935   "reload_completed"
936   [(set (match_dup 2)
937         (sign_extend:SI (match_dup 1)))
938    (set (match_dup 0)
939         (compare:CC (match_dup 2)
940                     (const_int 0)))]
941   "")
942
943 (define_insn ""
944   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
945         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
946                     (const_int 0)))
947    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
948         (sign_extend:SI (match_dup 1)))]
949   ""
950   "@
951    {exts.|extsh.} %0,%1
952    #"
953   [(set_attr "type" "compare")
954    (set_attr "length" "4,8")])
955 \f
956 (define_split
957   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
958         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
959                     (const_int 0)))
960    (set (match_operand:SI 0 "gpc_reg_operand" "")
961         (sign_extend:SI (match_dup 1)))]
962   "reload_completed"
963   [(set (match_dup 0)
964         (sign_extend:SI (match_dup 1)))
965    (set (match_dup 2)
966         (compare:CC (match_dup 0)
967                     (const_int 0)))]
968   "")
969
970 ;; Fixed-point arithmetic insns.
971
972 ;; Discourage ai/addic because of carry but provide it in an alternative
973 ;; allowing register zero as source.
974 (define_expand "addsi3"
975   [(set (match_operand:SI 0 "gpc_reg_operand" "")
976         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
977                  (match_operand:SI 2 "reg_or_arith_cint_operand" "")))]
978   ""
979   "
980 {
981   if (GET_CODE (operands[2]) == CONST_INT
982                 && ! add_operand (operands[2], SImode))
983     {
984       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
985                  ? operands[0] : gen_reg_rtx (SImode));
986
987       HOST_WIDE_INT val = INTVAL (operands[2]);
988       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
989       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, SImode);
990
991       /* The ordering here is important for the prolog expander.
992          When space is allocated from the stack, adding 'low' first may
993          produce a temporary deallocation (which would be bad).  */
994       emit_insn (gen_addsi3 (tmp, operands[1], GEN_INT (rest)));
995       emit_insn (gen_addsi3 (operands[0], tmp, GEN_INT (low)));
996       DONE;
997     }
998 }")
999
1000 (define_insn "*addsi3_internal1"
1001   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,?r,r")
1002         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,b,r,b")
1003                  (match_operand:SI 2 "add_operand" "r,I,I,L")))]
1004   ""
1005   "@
1006    {cax|add} %0,%1,%2
1007    {cal %0,%2(%1)|addi %0,%1,%2}
1008    {ai|addic} %0,%1,%2
1009    {cau|addis} %0,%1,%v2"
1010   [(set_attr "length" "4,4,4,4")])
1011
1012 (define_insn "addsi3_high"
1013   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1014         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1015                  (high:SI (match_operand 2 "" ""))))]
1016   "TARGET_MACHO && !TARGET_64BIT"
1017   "{cau|addis} %0,%1,ha16(%2)"
1018   [(set_attr "length" "4")])
1019
1020 (define_insn "*addsi3_internal2"
1021   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1022         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1023                              (match_operand:SI 2 "reg_or_short_operand" "r,I,r,I"))
1024                     (const_int 0)))
1025    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
1026   "TARGET_32BIT"
1027   "@
1028    {cax.|add.} %3,%1,%2
1029    {ai.|addic.} %3,%1,%2
1030    #
1031    #"
1032   [(set_attr "type" "fast_compare,compare,compare,compare")
1033    (set_attr "length" "4,4,8,8")])
1034
1035 (define_split
1036   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1037         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1038                              (match_operand:SI 2 "reg_or_short_operand" ""))
1039                     (const_int 0)))
1040    (clobber (match_scratch:SI 3 ""))]
1041   "TARGET_32BIT && reload_completed"
1042   [(set (match_dup 3)
1043         (plus:SI (match_dup 1)
1044                  (match_dup 2)))
1045    (set (match_dup 0)
1046         (compare:CC (match_dup 3)
1047                     (const_int 0)))]
1048   "")
1049
1050 (define_insn "*addsi3_internal3"
1051   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1052         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1053                              (match_operand:SI 2 "reg_or_short_operand" "r,I,r,I"))
1054                     (const_int 0)))
1055    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
1056         (plus:SI (match_dup 1)
1057                  (match_dup 2)))]
1058   "TARGET_32BIT"
1059   "@
1060    {cax.|add.} %0,%1,%2
1061    {ai.|addic.} %0,%1,%2
1062    #
1063    #"
1064   [(set_attr "type" "fast_compare,compare,compare,compare")
1065    (set_attr "length" "4,4,8,8")])
1066
1067 (define_split
1068   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1069         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1070                              (match_operand:SI 2 "reg_or_short_operand" ""))
1071                     (const_int 0)))
1072    (set (match_operand:SI 0 "gpc_reg_operand" "")
1073         (plus:SI (match_dup 1) (match_dup 2)))]
1074   "TARGET_32BIT && reload_completed"
1075   [(set (match_dup 0)
1076         (plus:SI (match_dup 1)
1077                  (match_dup 2)))
1078    (set (match_dup 3)
1079         (compare:CC (match_dup 0)
1080                     (const_int 0)))]
1081   "")
1082
1083 ;; Split an add that we can't do in one insn into two insns, each of which
1084 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1085 ;; add should be last in case the result gets used in an address.
1086
1087 (define_split
1088   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1089         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1090                  (match_operand:SI 2 "non_add_cint_operand" "")))]
1091   ""
1092   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 3)))
1093    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 4)))]
1094 "
1095 {
1096   HOST_WIDE_INT val = INTVAL (operands[2]);
1097   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1098   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, SImode);
1099
1100   operands[3] = GEN_INT (rest);
1101   operands[4] = GEN_INT (low);
1102 }")
1103
1104 (define_insn "one_cmplsi2"
1105   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1106         (not:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1107   ""
1108   "nor %0,%1,%1")
1109
1110 (define_insn ""
1111   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1112         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1113                     (const_int 0)))
1114    (clobber (match_scratch:SI 2 "=r,r"))]
1115   "TARGET_32BIT"
1116   "@
1117    nor. %2,%1,%1
1118    #"
1119   [(set_attr "type" "compare")
1120    (set_attr "length" "4,8")])
1121
1122 (define_split
1123   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1124         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1125                     (const_int 0)))
1126    (clobber (match_scratch:SI 2 ""))]
1127   "TARGET_32BIT && reload_completed"
1128   [(set (match_dup 2)
1129         (not:SI (match_dup 1)))
1130    (set (match_dup 0)
1131         (compare:CC (match_dup 2)
1132                     (const_int 0)))]
1133   "")
1134
1135 (define_insn ""
1136   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1137         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1138                     (const_int 0)))
1139    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1140         (not:SI (match_dup 1)))]
1141   "TARGET_32BIT"
1142   "@
1143    nor. %0,%1,%1
1144    #"
1145   [(set_attr "type" "compare")
1146    (set_attr "length" "4,8")])
1147
1148 (define_split
1149   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1150         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1151                     (const_int 0)))
1152    (set (match_operand:SI 0 "gpc_reg_operand" "")
1153         (not:SI (match_dup 1)))]
1154   "TARGET_32BIT && reload_completed"
1155   [(set (match_dup 0)
1156         (not:SI (match_dup 1)))
1157    (set (match_dup 2)
1158         (compare:CC (match_dup 0)
1159                     (const_int 0)))]
1160   "")
1161
1162 (define_insn ""
1163   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1164         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
1165                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
1166   "! TARGET_POWERPC"
1167   "{sf%I1|subf%I1c} %0,%2,%1")
1168
1169 (define_insn ""
1170   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1171         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "r,I")
1172                   (match_operand:SI 2 "gpc_reg_operand" "r,r")))]
1173   "TARGET_POWERPC"
1174   "@
1175    subf %0,%2,%1
1176    subfic %0,%2,%1")
1177
1178 (define_insn ""
1179   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1180         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1181                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1182                     (const_int 0)))
1183    (clobber (match_scratch:SI 3 "=r,r"))]
1184   "! TARGET_POWERPC"
1185   "@
1186    {sf.|subfc.} %3,%2,%1
1187    #"
1188   [(set_attr "type" "compare")
1189    (set_attr "length" "4,8")])
1190
1191 (define_insn ""
1192   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1193         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1194                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1195                     (const_int 0)))
1196    (clobber (match_scratch:SI 3 "=r,r"))]
1197   "TARGET_POWERPC && TARGET_32BIT"
1198   "@
1199    subf. %3,%2,%1
1200    #"
1201   [(set_attr "type" "fast_compare")
1202    (set_attr "length" "4,8")])
1203
1204 (define_split
1205   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1206         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1207                               (match_operand:SI 2 "gpc_reg_operand" ""))
1208                     (const_int 0)))
1209    (clobber (match_scratch:SI 3 ""))]
1210   "TARGET_32BIT && reload_completed"
1211   [(set (match_dup 3)
1212         (minus:SI (match_dup 1)
1213                   (match_dup 2)))
1214    (set (match_dup 0)
1215         (compare:CC (match_dup 3)
1216                     (const_int 0)))]
1217   "")
1218
1219 (define_insn ""
1220   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1221         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1222                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1223                     (const_int 0)))
1224    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1225         (minus:SI (match_dup 1) (match_dup 2)))]
1226   "! TARGET_POWERPC"
1227   "@
1228    {sf.|subfc.} %0,%2,%1
1229    #"
1230   [(set_attr "type" "compare")
1231    (set_attr "length" "4,8")])
1232
1233 (define_insn ""
1234   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1235         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1236                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1237                     (const_int 0)))
1238    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1239         (minus:SI (match_dup 1)
1240                   (match_dup 2)))]
1241   "TARGET_POWERPC && TARGET_32BIT"
1242   "@
1243    subf. %0,%2,%1
1244    #"
1245   [(set_attr "type" "fast_compare")
1246    (set_attr "length" "4,8")])
1247
1248 (define_split
1249   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1250         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1251                               (match_operand:SI 2 "gpc_reg_operand" ""))
1252                     (const_int 0)))
1253    (set (match_operand:SI 0 "gpc_reg_operand" "")
1254         (minus:SI (match_dup 1)
1255                   (match_dup 2)))]
1256   "TARGET_32BIT && reload_completed"
1257   [(set (match_dup 0)
1258         (minus:SI (match_dup 1)
1259                   (match_dup 2)))
1260    (set (match_dup 3)
1261         (compare:CC (match_dup 0)
1262                     (const_int 0)))]
1263   "")
1264
1265 (define_expand "subsi3"
1266   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1267         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "")
1268                   (match_operand:SI 2 "reg_or_arith_cint_operand" "")))]
1269   ""
1270   "
1271 {
1272   if (GET_CODE (operands[2]) == CONST_INT)
1273     {
1274       emit_insn (gen_addsi3 (operands[0], operands[1],
1275                              negate_rtx (SImode, operands[2])));
1276       DONE;
1277     }
1278 }")
1279
1280 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1281 ;; instruction and some auxiliary computations.  Then we just have a single
1282 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1283 ;; combine.
1284
1285 (define_expand "sminsi3"
1286   [(set (match_dup 3)
1287         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1288                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1289                          (const_int 0)
1290                          (minus:SI (match_dup 2) (match_dup 1))))
1291    (set (match_operand:SI 0 "gpc_reg_operand" "")
1292         (minus:SI (match_dup 2) (match_dup 3)))]
1293   "TARGET_POWER || TARGET_ISEL"
1294   "
1295 {
1296   if (TARGET_ISEL)
1297     {
1298       operands[2] = force_reg (SImode, operands[2]);
1299       rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
1300       DONE;
1301     }
1302
1303   operands[3] = gen_reg_rtx (SImode);
1304 }")
1305
1306 (define_split
1307   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1308         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1309                  (match_operand:SI 2 "reg_or_short_operand" "")))
1310    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1311   "TARGET_POWER"
1312   [(set (match_dup 3)
1313         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1314                          (const_int 0)
1315                          (minus:SI (match_dup 2) (match_dup 1))))
1316    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1317   "")
1318
1319 (define_expand "smaxsi3"
1320   [(set (match_dup 3)
1321         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1322                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1323                          (const_int 0)
1324                          (minus:SI (match_dup 2) (match_dup 1))))
1325    (set (match_operand:SI 0 "gpc_reg_operand" "")
1326         (plus:SI (match_dup 3) (match_dup 1)))]
1327   "TARGET_POWER || TARGET_ISEL"
1328   "
1329 {
1330   if (TARGET_ISEL)
1331     {
1332       operands[2] = force_reg (SImode, operands[2]);
1333       rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
1334       DONE;
1335     }
1336   operands[3] = gen_reg_rtx (SImode);
1337 }")
1338
1339 (define_split
1340   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1341         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1342                  (match_operand:SI 2 "reg_or_short_operand" "")))
1343    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1344   "TARGET_POWER"
1345   [(set (match_dup 3)
1346         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1347                          (const_int 0)
1348                          (minus:SI (match_dup 2) (match_dup 1))))
1349    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1350   "")
1351
1352 (define_expand "uminsi3"
1353   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1354                               (match_dup 5)))
1355    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1356                               (match_dup 5)))
1357    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1358                                        (const_int 0)
1359                                        (minus:SI (match_dup 4) (match_dup 3))))
1360    (set (match_operand:SI 0 "gpc_reg_operand" "")
1361         (minus:SI (match_dup 2) (match_dup 3)))]
1362   "TARGET_POWER || TARGET_ISEL"
1363   "
1364 {
1365   if (TARGET_ISEL)
1366     {
1367       rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
1368       DONE;
1369     }
1370   operands[3] = gen_reg_rtx (SImode);
1371   operands[4] = gen_reg_rtx (SImode);
1372   operands[5] = GEN_INT (-2147483647 - 1);
1373 }")
1374
1375 (define_expand "umaxsi3"
1376   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1377                               (match_dup 5)))
1378    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1379                               (match_dup 5)))
1380    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1381                                        (const_int 0)
1382                                        (minus:SI (match_dup 4) (match_dup 3))))
1383    (set (match_operand:SI 0 "gpc_reg_operand" "")
1384         (plus:SI (match_dup 3) (match_dup 1)))]
1385   "TARGET_POWER || TARGET_ISEL"
1386   "
1387 {
1388   if (TARGET_ISEL)
1389     {
1390       rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
1391       DONE;
1392     }
1393   operands[3] = gen_reg_rtx (SImode);
1394   operands[4] = gen_reg_rtx (SImode);
1395   operands[5] = GEN_INT (-2147483647 - 1);
1396 }")
1397
1398 (define_insn ""
1399   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1400         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1401                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
1402                          (const_int 0)
1403                          (minus:SI (match_dup 2) (match_dup 1))))]
1404   "TARGET_POWER"
1405   "doz%I2 %0,%1,%2")
1406
1407 (define_insn ""
1408   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1409         (compare:CC
1410          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1411                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1412                           (const_int 0)
1413                           (minus:SI (match_dup 2) (match_dup 1)))
1414          (const_int 0)))
1415    (clobber (match_scratch:SI 3 "=r,r"))]
1416   "TARGET_POWER"
1417   "@
1418    doz%I2. %3,%1,%2
1419    #"
1420   [(set_attr "type" "delayed_compare")
1421    (set_attr "length" "4,8")])
1422
1423 (define_split
1424   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1425         (compare:CC
1426          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1427                               (match_operand:SI 2 "reg_or_short_operand" ""))
1428                           (const_int 0)
1429                           (minus:SI (match_dup 2) (match_dup 1)))
1430          (const_int 0)))
1431    (clobber (match_scratch:SI 3 ""))]
1432   "TARGET_POWER && reload_completed"
1433   [(set (match_dup 3)
1434         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1435                           (const_int 0)
1436                           (minus:SI (match_dup 2) (match_dup 1))))
1437    (set (match_dup 0)
1438         (compare:CC (match_dup 3)
1439                     (const_int 0)))]
1440   "")
1441
1442 (define_insn ""
1443   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1444         (compare:CC
1445          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1446                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1447                           (const_int 0)
1448                           (minus:SI (match_dup 2) (match_dup 1)))
1449          (const_int 0)))
1450    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1451         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1452                          (const_int 0)
1453                          (minus:SI (match_dup 2) (match_dup 1))))]
1454   "TARGET_POWER"
1455   "@
1456    doz%I2. %0,%1,%2
1457    #"
1458   [(set_attr "type" "delayed_compare")
1459    (set_attr "length" "4,8")])
1460
1461 (define_split
1462   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1463         (compare:CC
1464          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1465                               (match_operand:SI 2 "reg_or_short_operand" ""))
1466                           (const_int 0)
1467                           (minus:SI (match_dup 2) (match_dup 1)))
1468          (const_int 0)))
1469    (set (match_operand:SI 0 "gpc_reg_operand" "")
1470         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1471                          (const_int 0)
1472                          (minus:SI (match_dup 2) (match_dup 1))))]
1473   "TARGET_POWER && reload_completed"
1474   [(set (match_dup 0)
1475         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1476                          (const_int 0)
1477                          (minus:SI (match_dup 2) (match_dup 1))))
1478    (set (match_dup 3)
1479         (compare:CC (match_dup 0)
1480                     (const_int 0)))]
1481   "")
1482
1483 ;; We don't need abs with condition code because such comparisons should
1484 ;; never be done.
1485 (define_expand "abssi2"
1486   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1487         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
1488   ""
1489   "
1490 {
1491   if (TARGET_ISEL)
1492     {
1493       emit_insn (gen_abssi2_isel (operands[0], operands[1]));
1494       DONE;
1495     }
1496   else if (! TARGET_POWER)
1497     {
1498       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
1499       DONE;
1500     }
1501 }")
1502
1503 (define_insn "*abssi2_power"
1504   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1505         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1506   "TARGET_POWER"
1507   "abs %0,%1")
1508
1509 (define_insn_and_split "abssi2_isel"
1510   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1511         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
1512    (clobber (match_scratch:SI 2 "=&b"))
1513    (clobber (match_scratch:CC 3 "=y"))]
1514   "TARGET_ISEL"
1515   "#"
1516   "&& reload_completed"
1517   [(set (match_dup 2) (neg:SI (match_dup 1)))
1518    (set (match_dup 3)
1519         (compare:CC (match_dup 1)
1520                     (const_int 0)))
1521    (set (match_dup 0)
1522         (if_then_else:SI (ge (match_dup 3)
1523                              (const_int 0))
1524                          (match_dup 1)
1525                          (match_dup 2)))]
1526   "")
1527
1528 (define_insn_and_split "abssi2_nopower"
1529   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1530         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
1531    (clobber (match_scratch:SI 2 "=&r,&r"))]
1532   "! TARGET_POWER && ! TARGET_ISEL"
1533   "#"
1534   "&& reload_completed"
1535   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1536    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1537    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
1538   "")
1539
1540 (define_insn "*nabs_power"
1541   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1542         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
1543   "TARGET_POWER"
1544   "nabs %0,%1")
1545
1546 (define_insn_and_split "*nabs_nopower"
1547   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1548         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
1549    (clobber (match_scratch:SI 2 "=&r,&r"))]
1550   "! TARGET_POWER"
1551   "#"
1552   "&& reload_completed"
1553   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1554    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1555    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
1556   "")
1557
1558 (define_insn "negsi2"
1559   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1560         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1561   ""
1562   "neg %0,%1")
1563
1564 (define_insn ""
1565   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1566         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1567                     (const_int 0)))
1568    (clobber (match_scratch:SI 2 "=r,r"))]
1569   "TARGET_32BIT"
1570   "@
1571    neg. %2,%1
1572    #"
1573   [(set_attr "type" "fast_compare")
1574    (set_attr "length" "4,8")])
1575
1576 (define_split
1577   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1578         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1579                     (const_int 0)))
1580    (clobber (match_scratch:SI 2 ""))]
1581   "TARGET_32BIT && reload_completed"
1582   [(set (match_dup 2)
1583         (neg:SI (match_dup 1)))
1584    (set (match_dup 0)
1585         (compare:CC (match_dup 2)
1586                     (const_int 0)))]
1587   "")
1588
1589 (define_insn ""
1590   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1591         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1592                     (const_int 0)))
1593    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1594         (neg:SI (match_dup 1)))]
1595   "TARGET_32BIT"
1596   "@
1597    neg. %0,%1
1598    #"
1599   [(set_attr "type" "fast_compare")
1600    (set_attr "length" "4,8")])
1601
1602 (define_split
1603   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1604         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1605                     (const_int 0)))
1606    (set (match_operand:SI 0 "gpc_reg_operand" "")
1607         (neg:SI (match_dup 1)))]
1608   "TARGET_32BIT && reload_completed"
1609   [(set (match_dup 0)
1610         (neg:SI (match_dup 1)))
1611    (set (match_dup 2)
1612         (compare:CC (match_dup 0)
1613                     (const_int 0)))]
1614   "")
1615
1616 (define_insn "clzsi2"
1617   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1618         (clz:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1619   ""
1620   "{cntlz|cntlzw} %0,%1")
1621
1622 (define_expand "ctzsi2"
1623   [(set (match_dup 2)
1624         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
1625    (parallel [(set (match_dup 3) (and:SI (match_dup 1)
1626                                          (match_dup 2)))
1627               (clobber (scratch:CC))])
1628    (set (match_dup 4) (clz:SI (match_dup 3)))
1629    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1630         (minus:SI (const_int 31) (match_dup 4)))]
1631   ""
1632   {
1633      operands[2] = gen_reg_rtx (SImode);
1634      operands[3] = gen_reg_rtx (SImode);
1635      operands[4] = gen_reg_rtx (SImode);
1636   })
1637   
1638 (define_expand "ffssi2"
1639   [(set (match_dup 2)
1640         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
1641    (parallel [(set (match_dup 3) (and:SI (match_dup 1)
1642                                          (match_dup 2)))
1643               (clobber (scratch:CC))])
1644    (set (match_dup 4) (clz:SI (match_dup 3)))
1645    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1646         (minus:SI (const_int 32) (match_dup 4)))]
1647   ""
1648   {
1649      operands[2] = gen_reg_rtx (SImode);
1650      operands[3] = gen_reg_rtx (SImode);
1651      operands[4] = gen_reg_rtx (SImode);
1652   })
1653   
1654 (define_expand "mulsi3"
1655   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1656    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1657    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
1658   ""
1659   "
1660 {
1661   if (TARGET_POWER)
1662     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
1663   else
1664     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
1665   DONE;
1666 }")
1667
1668 (define_insn "mulsi3_mq"
1669   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1670         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1671                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
1672    (clobber (match_scratch:SI 3 "=q,q"))]
1673   "TARGET_POWER"
1674   "@
1675    {muls|mullw} %0,%1,%2
1676    {muli|mulli} %0,%1,%2"
1677    [(set (attr "type") 
1678       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
1679                 (const_string "imul3")
1680              (match_operand:SI 2 "short_cint_operand" "") 
1681                 (const_string "imul2")]
1682         (const_string "imul")))])
1683
1684 (define_insn "mulsi3_no_mq"
1685   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1686         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1687                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
1688   "! TARGET_POWER"
1689   "@
1690    {muls|mullw} %0,%1,%2
1691    {muli|mulli} %0,%1,%2"
1692    [(set (attr "type") 
1693       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
1694                 (const_string "imul3")
1695              (match_operand:SI 2 "short_cint_operand" "") 
1696                 (const_string "imul2")]
1697         (const_string "imul")))])
1698
1699 (define_insn "*mulsi3_mq_internal1"
1700   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1701         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1702                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1703                     (const_int 0)))
1704    (clobber (match_scratch:SI 3 "=r,r"))
1705    (clobber (match_scratch:SI 4 "=q,q"))]
1706   "TARGET_POWER"
1707   "@
1708    {muls.|mullw.} %3,%1,%2
1709    #"
1710   [(set_attr "type" "imul_compare")
1711    (set_attr "length" "4,8")])
1712
1713 (define_split
1714   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1715         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1716                              (match_operand:SI 2 "gpc_reg_operand" ""))
1717                     (const_int 0)))
1718    (clobber (match_scratch:SI 3 ""))
1719    (clobber (match_scratch:SI 4 ""))]
1720   "TARGET_POWER && reload_completed"
1721   [(parallel [(set (match_dup 3)
1722         (mult:SI (match_dup 1) (match_dup 2)))
1723    (clobber (match_dup 4))])
1724    (set (match_dup 0)
1725         (compare:CC (match_dup 3)
1726                     (const_int 0)))]
1727   "")
1728
1729 (define_insn "*mulsi3_no_mq_internal1"
1730   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1731         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1732                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1733                     (const_int 0)))
1734    (clobber (match_scratch:SI 3 "=r,r"))]
1735   "! TARGET_POWER"
1736   "@
1737    {muls.|mullw.} %3,%1,%2
1738    #"
1739   [(set_attr "type" "imul_compare")
1740    (set_attr "length" "4,8")])
1741
1742 (define_split
1743   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1744         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1745                              (match_operand:SI 2 "gpc_reg_operand" ""))
1746                     (const_int 0)))
1747    (clobber (match_scratch:SI 3 ""))]
1748   "! TARGET_POWER && reload_completed"
1749   [(set (match_dup 3)
1750         (mult:SI (match_dup 1) (match_dup 2)))
1751    (set (match_dup 0)
1752         (compare:CC (match_dup 3)
1753                     (const_int 0)))]
1754   "")
1755
1756 (define_insn "*mulsi3_mq_internal2"
1757   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1758         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1759                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1760                     (const_int 0)))
1761    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1762         (mult:SI (match_dup 1) (match_dup 2)))
1763    (clobber (match_scratch:SI 4 "=q,q"))]
1764   "TARGET_POWER"
1765   "@
1766    {muls.|mullw.} %0,%1,%2
1767    #"
1768   [(set_attr "type" "imul_compare")
1769    (set_attr "length" "4,8")])
1770
1771 (define_split
1772   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1773         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1774                              (match_operand:SI 2 "gpc_reg_operand" ""))
1775                     (const_int 0)))
1776    (set (match_operand:SI 0 "gpc_reg_operand" "")
1777         (mult:SI (match_dup 1) (match_dup 2)))
1778    (clobber (match_scratch:SI 4 ""))]
1779   "TARGET_POWER && reload_completed"
1780   [(parallel [(set (match_dup 0)
1781         (mult:SI (match_dup 1) (match_dup 2)))
1782    (clobber (match_dup 4))])
1783    (set (match_dup 3)
1784         (compare:CC (match_dup 0)
1785                     (const_int 0)))]
1786   "")
1787
1788 (define_insn "*mulsi3_no_mq_internal2"
1789   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1790         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1791                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1792                     (const_int 0)))
1793    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1794         (mult:SI (match_dup 1) (match_dup 2)))]
1795   "! TARGET_POWER"
1796   "@
1797    {muls.|mullw.} %0,%1,%2
1798    #"
1799   [(set_attr "type" "imul_compare")
1800    (set_attr "length" "4,8")])
1801
1802 (define_split
1803   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1804         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1805                              (match_operand:SI 2 "gpc_reg_operand" ""))
1806                     (const_int 0)))
1807    (set (match_operand:SI 0 "gpc_reg_operand" "")
1808         (mult:SI (match_dup 1) (match_dup 2)))]
1809   "! TARGET_POWER && reload_completed"
1810   [(set (match_dup 0)
1811         (mult:SI (match_dup 1) (match_dup 2)))
1812    (set (match_dup 3)
1813         (compare:CC (match_dup 0)
1814                     (const_int 0)))]
1815   "")
1816
1817 ;; Operand 1 is divided by operand 2; quotient goes to operand
1818 ;; 0 and remainder to operand 3.
1819 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
1820
1821 (define_expand "divmodsi4"
1822   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
1823                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1824                            (match_operand:SI 2 "gpc_reg_operand" "")))
1825               (set (match_operand:SI 3 "register_operand" "")
1826                    (mod:SI (match_dup 1) (match_dup 2)))])]
1827   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
1828   "
1829 {
1830   if (! TARGET_POWER && ! TARGET_POWERPC)
1831     {
1832       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
1833       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
1834       emit_insn (gen_divss_call ());
1835       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
1836       emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
1837       DONE;
1838     }
1839 }")
1840
1841 (define_insn "*divmodsi4_internal"
1842   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1843         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1844                 (match_operand:SI 2 "gpc_reg_operand" "r")))
1845    (set (match_operand:SI 3 "register_operand" "=q")
1846         (mod:SI (match_dup 1) (match_dup 2)))]
1847   "TARGET_POWER"
1848   "divs %0,%1,%2"
1849   [(set_attr "type" "idiv")])
1850
1851 (define_expand "udivsi3"
1852   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1853         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
1854                  (match_operand:SI 2 "gpc_reg_operand" "")))]
1855   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
1856   "
1857 {
1858   if (! TARGET_POWER && ! TARGET_POWERPC)
1859     {
1860       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
1861       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
1862       emit_insn (gen_quous_call ());
1863       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
1864       DONE;
1865     }
1866   else if (TARGET_POWER)
1867     {
1868       emit_insn (gen_udivsi3_mq (operands[0], operands[1], operands[2]));
1869       DONE;
1870     }
1871 }")
1872
1873 (define_insn "udivsi3_mq"
1874   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1875         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1876                  (match_operand:SI 2 "gpc_reg_operand" "r")))
1877    (clobber (match_scratch:SI 3 "=q"))]
1878   "TARGET_POWERPC && TARGET_POWER"
1879   "divwu %0,%1,%2"
1880   [(set_attr "type" "idiv")])
1881
1882 (define_insn "*udivsi3_no_mq"
1883   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1884         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1885                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
1886   "TARGET_POWERPC && ! TARGET_POWER"
1887   "divwu %0,%1,%2"
1888   [(set_attr "type" "idiv")])
1889
1890 ;; For powers of two we can do srai/aze for divide and then adjust for
1891 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
1892 ;; used; for PowerPC, force operands into register and do a normal divide;
1893 ;; for AIX common-mode, use quoss call on register operands.
1894 (define_expand "divsi3"
1895   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1896         (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1897                 (match_operand:SI 2 "reg_or_cint_operand" "")))]
1898   ""
1899   "
1900 {
1901   if (GET_CODE (operands[2]) == CONST_INT
1902       && INTVAL (operands[2]) > 0
1903       && exact_log2 (INTVAL (operands[2])) >= 0)
1904     ;
1905   else if (TARGET_POWERPC)
1906     {
1907       operands[2] = force_reg (SImode, operands[2]);
1908       if (TARGET_POWER)
1909         {
1910           emit_insn (gen_divsi3_mq (operands[0], operands[1], operands[2]));
1911           DONE;
1912         }
1913     }
1914   else if (TARGET_POWER)
1915     FAIL;
1916   else
1917     {
1918       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
1919       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
1920       emit_insn (gen_quoss_call ());
1921       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
1922       DONE;
1923     }
1924 }")
1925
1926 (define_insn "divsi3_mq"
1927   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1928         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1929                 (match_operand:SI 2 "gpc_reg_operand" "r")))
1930    (clobber (match_scratch:SI 3 "=q"))]
1931   "TARGET_POWERPC && TARGET_POWER"
1932   "divw %0,%1,%2"
1933   [(set_attr "type" "idiv")])
1934
1935 (define_insn "*divsi3_no_mq"
1936   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1937         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1938                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
1939   "TARGET_POWERPC && ! TARGET_POWER"
1940   "divw %0,%1,%2"
1941   [(set_attr "type" "idiv")])
1942
1943 (define_expand "modsi3"
1944   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1945    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1946    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
1947   ""
1948   "
1949 {
1950   int i;
1951   rtx temp1;
1952   rtx temp2;
1953
1954   if (GET_CODE (operands[2]) != CONST_INT
1955       || INTVAL (operands[2]) <= 0
1956       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
1957     FAIL;
1958
1959   temp1 = gen_reg_rtx (SImode);
1960   temp2 = gen_reg_rtx (SImode);
1961
1962   emit_insn (gen_divsi3 (temp1, operands[1], operands[2]));
1963   emit_insn (gen_ashlsi3 (temp2, temp1, GEN_INT (i)));
1964   emit_insn (gen_subsi3 (operands[0], operands[1], temp2));
1965   DONE;
1966 }")
1967
1968 (define_insn ""
1969   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1970         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1971                 (match_operand:SI 2 "exact_log2_cint_operand" "N")))]
1972   ""
1973   "{srai|srawi} %0,%1,%p2\;{aze|addze} %0,%0"
1974   [(set_attr "length" "8")])
1975
1976 (define_insn ""
1977   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1978         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1979                             (match_operand:SI 2 "exact_log2_cint_operand" "N,N"))
1980                     (const_int 0)))
1981    (clobber (match_scratch:SI 3 "=r,r"))]
1982   ""
1983   "@
1984    {srai|srawi} %3,%1,%p2\;{aze.|addze.} %3,%3
1985    #"
1986   [(set_attr "type" "compare")
1987    (set_attr "length" "8,12")])
1988
1989 (define_split
1990   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1991         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1992                             (match_operand:SI 2 "exact_log2_cint_operand" ""))
1993                     (const_int 0)))
1994    (clobber (match_scratch:SI 3 ""))]
1995   "reload_completed"
1996   [(set (match_dup 3)
1997         (div:SI (match_dup 1) (match_dup 2)))
1998    (set (match_dup 0)
1999         (compare:CC (match_dup 3)
2000                     (const_int 0)))]
2001   "")
2002
2003 (define_insn ""
2004   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2005         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2006                             (match_operand:SI 2 "exact_log2_cint_operand" "N,N"))
2007                     (const_int 0)))
2008    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2009         (div:SI (match_dup 1) (match_dup 2)))]
2010   ""
2011   "@
2012    {srai|srawi} %0,%1,%p2\;{aze.|addze.} %0,%0
2013    #"
2014   [(set_attr "type" "compare")
2015    (set_attr "length" "8,12")])
2016
2017 (define_split
2018   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2019         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2020                             (match_operand:SI 2 "exact_log2_cint_operand" ""))
2021                     (const_int 0)))
2022    (set (match_operand:SI 0 "gpc_reg_operand" "")
2023         (div:SI (match_dup 1) (match_dup 2)))]
2024   "reload_completed"
2025   [(set (match_dup 0)
2026         (div:SI (match_dup 1) (match_dup 2)))
2027    (set (match_dup 3)
2028         (compare:CC (match_dup 0)
2029                     (const_int 0)))]
2030   "")
2031
2032 (define_insn ""
2033   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2034         (udiv:SI
2035          (plus:DI (ashift:DI
2036                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
2037                    (const_int 32))
2038                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
2039          (match_operand:SI 3 "gpc_reg_operand" "r")))
2040    (set (match_operand:SI 2 "register_operand" "=*q")
2041         (umod:SI
2042          (plus:DI (ashift:DI
2043                    (zero_extend:DI (match_dup 1)) (const_int 32))
2044                   (zero_extend:DI (match_dup 4)))
2045          (match_dup 3)))]
2046   "TARGET_POWER"
2047   "div %0,%1,%3"
2048   [(set_attr "type" "idiv")])
2049
2050 ;; To do unsigned divide we handle the cases of the divisor looking like a
2051 ;; negative number.  If it is a constant that is less than 2**31, we don't
2052 ;; have to worry about the branches.  So make a few subroutines here.
2053 ;;
2054 ;; First comes the normal case.
2055 (define_expand "udivmodsi4_normal"
2056   [(set (match_dup 4) (const_int 0))
2057    (parallel [(set (match_operand:SI 0 "" "")
2058                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2059                                                 (const_int 32))
2060                                      (zero_extend:DI (match_operand:SI 1 "" "")))
2061                             (match_operand:SI 2 "" "")))
2062               (set (match_operand:SI 3 "" "")
2063                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2064                                                 (const_int 32))
2065                                      (zero_extend:DI (match_dup 1)))
2066                             (match_dup 2)))])]
2067   "TARGET_POWER"
2068   "
2069 { operands[4] = gen_reg_rtx (SImode); }")
2070
2071 ;; This handles the branches.
2072 (define_expand "udivmodsi4_tests"
2073   [(set (match_operand:SI 0 "" "") (const_int 0))
2074    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
2075    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
2076    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
2077                            (label_ref (match_operand:SI 4 "" "")) (pc)))
2078    (set (match_dup 0) (const_int 1))
2079    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
2080    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
2081    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
2082                            (label_ref (match_dup 4)) (pc)))]
2083   "TARGET_POWER"
2084   "
2085 { operands[5] = gen_reg_rtx (CCUNSmode);
2086   operands[6] = gen_reg_rtx (CCmode);
2087 }")
2088
2089 (define_expand "udivmodsi4"
2090   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2091                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
2092                             (match_operand:SI 2 "reg_or_cint_operand" "")))
2093               (set (match_operand:SI 3 "gpc_reg_operand" "")
2094                    (umod:SI (match_dup 1) (match_dup 2)))])]
2095   ""
2096   "
2097 {
2098   rtx label = 0;
2099
2100   if (! TARGET_POWER)
2101     {
2102       if (! TARGET_POWERPC)
2103         {
2104           emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2105           emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2106           emit_insn (gen_divus_call ());
2107           emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2108           emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2109           DONE;
2110         }
2111       else
2112         FAIL;
2113     }
2114
2115   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
2116     {
2117       operands[2] = force_reg (SImode, operands[2]);
2118       label = gen_label_rtx ();
2119       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
2120                                   operands[3], label));
2121     }
2122   else
2123     operands[2] = force_reg (SImode, operands[2]);
2124
2125   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
2126                                operands[3]));
2127   if (label)
2128     emit_label (label);
2129
2130   DONE;
2131 }")
2132
2133 ;; AIX architecture-independent common-mode multiply (DImode),
2134 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
2135 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
2136 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
2137 ;; assumed unused if generating common-mode, so ignore.
2138 (define_insn "mulh_call"
2139   [(set (reg:SI 3)
2140         (truncate:SI
2141          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
2142                                (sign_extend:DI (reg:SI 4)))
2143                       (const_int 32))))
2144    (clobber (match_scratch:SI 0 "=l"))]
2145   "! TARGET_POWER && ! TARGET_POWERPC"
2146   "bla __mulh"
2147   [(set_attr "type" "imul")])
2148
2149 (define_insn "mull_call"
2150   [(set (reg:DI 3)
2151         (mult:DI (sign_extend:DI (reg:SI 3))
2152                  (sign_extend:DI (reg:SI 4))))
2153    (clobber (match_scratch:SI 0 "=l"))
2154    (clobber (reg:SI 0))]
2155   "! TARGET_POWER && ! TARGET_POWERPC"
2156   "bla __mull"
2157   [(set_attr "type" "imul")])
2158
2159 (define_insn "divss_call"
2160   [(set (reg:SI 3)
2161         (div:SI (reg:SI 3) (reg:SI 4)))
2162    (set (reg:SI 4)
2163         (mod:SI (reg:SI 3) (reg:SI 4)))
2164    (clobber (match_scratch:SI 0 "=l"))
2165    (clobber (reg:SI 0))]
2166   "! TARGET_POWER && ! TARGET_POWERPC"
2167   "bla __divss"
2168   [(set_attr "type" "idiv")])
2169
2170 (define_insn "divus_call"
2171   [(set (reg:SI 3)
2172         (udiv:SI (reg:SI 3) (reg:SI 4)))
2173    (set (reg:SI 4)
2174         (umod:SI (reg:SI 3) (reg:SI 4)))
2175    (clobber (match_scratch:SI 0 "=l"))
2176    (clobber (reg:SI 0))
2177    (clobber (match_scratch:CC 1 "=x"))
2178    (clobber (reg:CC 69))]
2179   "! TARGET_POWER && ! TARGET_POWERPC"
2180   "bla __divus"
2181   [(set_attr "type" "idiv")])
2182
2183 (define_insn "quoss_call"
2184   [(set (reg:SI 3)
2185         (div:SI (reg:SI 3) (reg:SI 4)))
2186    (clobber (match_scratch:SI 0 "=l"))]
2187   "! TARGET_POWER && ! TARGET_POWERPC"
2188   "bla __quoss"
2189   [(set_attr "type" "idiv")])
2190
2191 (define_insn "quous_call"
2192   [(set (reg:SI 3)
2193         (udiv:SI (reg:SI 3) (reg:SI 4)))
2194    (clobber (match_scratch:SI 0 "=l"))
2195    (clobber (reg:SI 0))
2196    (clobber (match_scratch:CC 1 "=x"))
2197    (clobber (reg:CC 69))]
2198   "! TARGET_POWER && ! TARGET_POWERPC"
2199   "bla __quous"
2200   [(set_attr "type" "idiv")])
2201 \f
2202 ;; Logical instructions
2203 ;; The logical instructions are mostly combined by using match_operator,
2204 ;; but the plain AND insns are somewhat different because there is no
2205 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2206 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2207
2208 (define_insn "andsi3"
2209   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2210         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2211                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2212    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2213   ""
2214   "@
2215    and %0,%1,%2
2216    {rlinm|rlwinm} %0,%1,0,%m2,%M2
2217    {andil.|andi.} %0,%1,%b2
2218    {andiu.|andis.} %0,%1,%u2")
2219
2220 ;; Note to set cr's other than cr0 we do the and immediate and then
2221 ;; the test again -- this avoids a mfcr which on the higher end
2222 ;; machines causes an execution serialization
2223
2224 (define_insn "*andsi3_internal2"
2225   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2226         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2227                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2228                     (const_int 0)))
2229    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2230    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2231   "TARGET_32BIT"
2232   "@
2233    and. %3,%1,%2
2234    {andil.|andi.} %3,%1,%b2
2235    {andiu.|andis.} %3,%1,%u2
2236    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2237    #
2238    #
2239    #
2240    #"
2241   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2242    (set_attr "length" "4,4,4,4,8,8,8,8")])
2243
2244 (define_insn "*andsi3_internal3"
2245   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2246         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2247                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2248                     (const_int 0)))
2249    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2250    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2251   "TARGET_64BIT"
2252   "@
2253    #
2254    {andil.|andi.} %3,%1,%b2
2255    {andiu.|andis.} %3,%1,%u2
2256    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2257    #
2258    #
2259    #
2260    #"
2261   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2262    (set_attr "length" "8,4,4,4,8,8,8,8")])
2263
2264 (define_split
2265   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2266         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2267                             (match_operand:SI 2 "and_operand" ""))
2268                     (const_int 0)))
2269    (clobber (match_scratch:SI 3 ""))
2270    (clobber (match_scratch:CC 4 ""))]
2271   "reload_completed"
2272   [(parallel [(set (match_dup 3)
2273                    (and:SI (match_dup 1)
2274                            (match_dup 2)))
2275               (clobber (match_dup 4))])
2276    (set (match_dup 0)
2277         (compare:CC (match_dup 3)
2278                     (const_int 0)))]
2279   "")
2280
2281 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
2282 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
2283
2284 (define_split
2285   [(set (match_operand:CC 0 "cc_reg_operand" "")
2286         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2287                             (match_operand:SI 2 "gpc_reg_operand" ""))
2288                     (const_int 0)))
2289    (clobber (match_scratch:SI 3 ""))
2290    (clobber (match_scratch:CC 4 ""))]
2291   "TARGET_POWERPC64 && reload_completed"
2292   [(parallel [(set (match_dup 3)
2293                    (and:SI (match_dup 1)
2294                            (match_dup 2)))
2295               (clobber (match_dup 4))])
2296    (set (match_dup 0)
2297         (compare:CC (match_dup 3)
2298                     (const_int 0)))]
2299   "")
2300
2301 (define_insn "*andsi3_internal4"
2302   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2303         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2304                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2305                     (const_int 0)))
2306    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2307         (and:SI (match_dup 1)
2308                 (match_dup 2)))
2309    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2310   "TARGET_32BIT"
2311   "@
2312    and. %0,%1,%2
2313    {andil.|andi.} %0,%1,%b2
2314    {andiu.|andis.} %0,%1,%u2
2315    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2316    #
2317    #
2318    #
2319    #"
2320   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2321    (set_attr "length" "4,4,4,4,8,8,8,8")])
2322
2323 (define_insn "*andsi3_internal5"
2324   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2325         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2326                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2327                     (const_int 0)))
2328    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2329         (and:SI (match_dup 1)
2330                 (match_dup 2)))
2331    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2332   "TARGET_64BIT"
2333   "@
2334    #
2335    {andil.|andi.} %0,%1,%b2
2336    {andiu.|andis.} %0,%1,%u2
2337    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2338    #
2339    #
2340    #
2341    #"
2342   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2343    (set_attr "length" "8,4,4,4,8,8,8,8")])
2344
2345 (define_split
2346   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2347         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2348                             (match_operand:SI 2 "and_operand" ""))
2349                     (const_int 0)))
2350    (set (match_operand:SI 0 "gpc_reg_operand" "")
2351         (and:SI (match_dup 1)
2352                 (match_dup 2)))
2353    (clobber (match_scratch:CC 4 ""))]
2354   "reload_completed"
2355   [(parallel [(set (match_dup 0)
2356                    (and:SI (match_dup 1)
2357                            (match_dup 2)))
2358               (clobber (match_dup 4))])
2359    (set (match_dup 3)
2360         (compare:CC (match_dup 0)
2361                     (const_int 0)))]
2362   "")
2363
2364 (define_split
2365   [(set (match_operand:CC 3 "cc_reg_operand" "")
2366         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2367                             (match_operand:SI 2 "gpc_reg_operand" ""))
2368                     (const_int 0)))
2369    (set (match_operand:SI 0 "gpc_reg_operand" "")
2370         (and:SI (match_dup 1)
2371                 (match_dup 2)))
2372    (clobber (match_scratch:CC 4 ""))]
2373   "TARGET_POWERPC64 && reload_completed"
2374   [(parallel [(set (match_dup 0)
2375                    (and:SI (match_dup 1)
2376                            (match_dup 2)))
2377               (clobber (match_dup 4))])
2378    (set (match_dup 3)
2379         (compare:CC (match_dup 0)
2380                     (const_int 0)))]
2381   "")
2382
2383 ;; Handle the PowerPC64 rlwinm corner case
2384
2385 (define_insn_and_split "*andsi3_internal6"
2386   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2387         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2388                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
2389   "TARGET_POWERPC64"
2390   "#"
2391   "TARGET_POWERPC64"
2392   [(set (match_dup 0)
2393         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
2394                 (match_dup 4)))
2395    (set (match_dup 0)
2396         (rotate:SI (match_dup 0) (match_dup 5)))]
2397   "
2398 {
2399   int mb = extract_MB (operands[2]);
2400   int me = extract_ME (operands[2]);
2401   operands[3] = GEN_INT (me + 1);
2402   operands[5] = GEN_INT (32 - (me + 1));
2403   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2404 }"
2405   [(set_attr "length" "8")])
2406
2407 (define_expand "iorsi3"
2408   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2409         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
2410                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2411   ""
2412   "
2413 {
2414   if (GET_CODE (operands[2]) == CONST_INT
2415       && ! logical_operand (operands[2], SImode))
2416     {
2417       HOST_WIDE_INT value = INTVAL (operands[2]);
2418       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2419                  ? operands[0] : gen_reg_rtx (SImode));
2420
2421       emit_insn (gen_iorsi3 (tmp, operands[1],
2422                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2423       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2424       DONE;
2425     }
2426 }")
2427
2428 (define_expand "xorsi3"
2429   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2430         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
2431                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2432   ""
2433   "
2434 {
2435   if (GET_CODE (operands[2]) == CONST_INT
2436       && ! logical_operand (operands[2], SImode))
2437     {
2438       HOST_WIDE_INT value = INTVAL (operands[2]);
2439       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2440                  ? operands[0] : gen_reg_rtx (SImode));
2441
2442       emit_insn (gen_xorsi3 (tmp, operands[1],
2443                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2444       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2445       DONE;
2446     }
2447 }")
2448
2449 (define_insn "*boolsi3_internal1"
2450   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
2451         (match_operator:SI 3 "boolean_or_operator"
2452          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
2453           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
2454   ""
2455   "@
2456    %q3 %0,%1,%2
2457    {%q3il|%q3i} %0,%1,%b2
2458    {%q3iu|%q3is} %0,%1,%u2")
2459
2460 (define_insn "*boolsi3_internal2"
2461   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2462         (compare:CC (match_operator:SI 4 "boolean_or_operator"
2463          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2464           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2465          (const_int 0)))
2466    (clobber (match_scratch:SI 3 "=r,r"))]
2467   "TARGET_32BIT"
2468   "@
2469    %q4. %3,%1,%2
2470    #"
2471   [(set_attr "type" "compare")
2472    (set_attr "length" "4,8")])
2473
2474 (define_split
2475   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2476         (compare:CC (match_operator:SI 4 "boolean_operator"
2477          [(match_operand:SI 1 "gpc_reg_operand" "")
2478           (match_operand:SI 2 "gpc_reg_operand" "")])
2479          (const_int 0)))
2480    (clobber (match_scratch:SI 3 ""))]
2481   "TARGET_32BIT && reload_completed"
2482   [(set (match_dup 3) (match_dup 4))
2483    (set (match_dup 0)
2484         (compare:CC (match_dup 3)
2485                     (const_int 0)))]
2486   "")
2487
2488 (define_insn "*boolsi3_internal3"
2489   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2490         (compare:CC (match_operator:SI 4 "boolean_operator"
2491          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2492           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2493          (const_int 0)))
2494    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2495         (match_dup 4))]
2496   "TARGET_32BIT"
2497   "@
2498    %q4. %0,%1,%2
2499    #"
2500   [(set_attr "type" "compare")
2501    (set_attr "length" "4,8")])
2502
2503 (define_split
2504   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2505         (compare:CC (match_operator:SI 4 "boolean_operator"
2506          [(match_operand:SI 1 "gpc_reg_operand" "")
2507           (match_operand:SI 2 "gpc_reg_operand" "")])
2508          (const_int 0)))
2509    (set (match_operand:SI 0 "gpc_reg_operand" "")
2510         (match_dup 4))]
2511   "TARGET_32BIT && reload_completed"
2512   [(set (match_dup 0) (match_dup 4))
2513    (set (match_dup 3)
2514         (compare:CC (match_dup 0)
2515                     (const_int 0)))]
2516   "")
2517
2518 ;; Split a logical operation that we can't do in one insn into two insns, 
2519 ;; each of which does one 16-bit part.  This is used by combine.
2520
2521 (define_split
2522   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2523         (match_operator:SI 3 "boolean_or_operator"
2524          [(match_operand:SI 1 "gpc_reg_operand" "")
2525           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
2526   ""
2527   [(set (match_dup 0) (match_dup 4))
2528    (set (match_dup 0) (match_dup 5))]
2529 "
2530 {
2531   rtx i;
2532   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
2533   operands[4] = gen_rtx (GET_CODE (operands[3]), SImode,
2534                          operands[1], i);
2535   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
2536   operands[5] = gen_rtx (GET_CODE (operands[3]), SImode,
2537                          operands[0], i);
2538 }")
2539
2540 (define_insn "*boolcsi3_internal1"
2541   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2542         (match_operator:SI 3 "boolean_operator"
2543          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
2544           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
2545   ""
2546   "%q3 %0,%2,%1")
2547
2548 (define_insn "*boolcsi3_internal2"
2549   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2550         (compare:CC (match_operator:SI 4 "boolean_operator"
2551          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2552           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2553          (const_int 0)))
2554    (clobber (match_scratch:SI 3 "=r,r"))]
2555   "TARGET_32BIT"
2556   "@
2557    %q4. %3,%2,%1
2558    #"
2559   [(set_attr "type" "compare")
2560    (set_attr "length" "4,8")])
2561
2562 (define_split
2563   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2564         (compare:CC (match_operator:SI 4 "boolean_operator"
2565          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2566           (match_operand:SI 2 "gpc_reg_operand" "")])
2567          (const_int 0)))
2568    (clobber (match_scratch:SI 3 ""))]
2569   "TARGET_32BIT && reload_completed"
2570   [(set (match_dup 3) (match_dup 4))
2571    (set (match_dup 0)
2572         (compare:CC (match_dup 3)
2573                     (const_int 0)))]
2574   "")
2575
2576 (define_insn "*boolcsi3_internal3"
2577   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2578         (compare:CC (match_operator:SI 4 "boolean_operator"
2579          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
2580           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2581          (const_int 0)))
2582    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2583         (match_dup 4))]
2584   "TARGET_32BIT"
2585   "@
2586    %q4. %0,%2,%1
2587    #"
2588   [(set_attr "type" "compare")
2589    (set_attr "length" "4,8")])
2590
2591 (define_split
2592   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2593         (compare:CC (match_operator:SI 4 "boolean_operator"
2594          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2595           (match_operand:SI 2 "gpc_reg_operand" "")])
2596          (const_int 0)))
2597    (set (match_operand:SI 0 "gpc_reg_operand" "")
2598         (match_dup 4))]
2599   "TARGET_32BIT && reload_completed"
2600   [(set (match_dup 0) (match_dup 4))
2601    (set (match_dup 3)
2602         (compare:CC (match_dup 0)
2603                     (const_int 0)))]
2604   "")
2605
2606 (define_insn "*boolccsi3_internal1"
2607   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2608         (match_operator:SI 3 "boolean_operator"
2609          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
2610           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
2611   ""
2612   "%q3 %0,%1,%2")
2613
2614 (define_insn "*boolccsi3_internal2"
2615   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2616         (compare:CC (match_operator:SI 4 "boolean_operator"
2617          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2618           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
2619          (const_int 0)))
2620    (clobber (match_scratch:SI 3 "=r,r"))]
2621   "TARGET_32BIT"
2622   "@
2623    %q4. %3,%1,%2
2624    #"
2625   [(set_attr "type" "compare")
2626    (set_attr "length" "4,8")])
2627
2628 (define_split
2629   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2630         (compare:CC (match_operator:SI 4 "boolean_operator"
2631          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2632           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
2633          (const_int 0)))
2634    (clobber (match_scratch:SI 3 ""))]
2635   "TARGET_32BIT && reload_completed"
2636   [(set (match_dup 3) (match_dup 4))
2637    (set (match_dup 0)
2638         (compare:CC (match_dup 3)
2639                     (const_int 0)))]
2640   "")
2641
2642 (define_insn "*boolccsi3_internal3"
2643   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2644         (compare:CC (match_operator:SI 4 "boolean_operator"
2645          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
2646           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
2647          (const_int 0)))
2648    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2649         (match_dup 4))]
2650   "TARGET_32BIT"
2651   "@
2652    %q4. %0,%1,%2
2653    #"
2654   [(set_attr "type" "compare")
2655    (set_attr "length" "4,8")])
2656
2657 (define_split
2658   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2659         (compare:CC (match_operator:SI 4 "boolean_operator"
2660          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2661           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
2662          (const_int 0)))
2663    (set (match_operand:SI 0 "gpc_reg_operand" "")
2664         (match_dup 4))]
2665   "TARGET_32BIT && reload_completed"
2666   [(set (match_dup 0) (match_dup 4))
2667    (set (match_dup 3)
2668         (compare:CC (match_dup 0)
2669                     (const_int 0)))]
2670   "")
2671
2672 ;; maskir insn.  We need four forms because things might be in arbitrary
2673 ;; orders.  Don't define forms that only set CR fields because these
2674 ;; would modify an input register.
2675
2676 (define_insn "*maskir_internal1"
2677   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2678         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
2679                         (match_operand:SI 1 "gpc_reg_operand" "0"))
2680                 (and:SI (match_dup 2)
2681                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
2682   "TARGET_POWER"
2683   "maskir %0,%3,%2")
2684
2685 (define_insn "*maskir_internal2"
2686   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2687         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
2688                         (match_operand:SI 1 "gpc_reg_operand" "0"))
2689                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2690                         (match_dup 2))))]
2691   "TARGET_POWER"
2692   "maskir %0,%3,%2")
2693
2694 (define_insn "*maskir_internal3"
2695   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2696         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2697                         (match_operand:SI 3 "gpc_reg_operand" "r"))
2698                 (and:SI (not:SI (match_dup 2))
2699                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
2700   "TARGET_POWER"
2701   "maskir %0,%3,%2")
2702
2703 (define_insn "*maskir_internal4"
2704   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2705         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2706                         (match_operand:SI 2 "gpc_reg_operand" "r"))
2707                 (and:SI (not:SI (match_dup 2))
2708                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
2709   "TARGET_POWER"
2710   "maskir %0,%3,%2")
2711
2712 (define_insn "*maskir_internal5"
2713   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2714         (compare:CC
2715          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2716                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
2717                  (and:SI (match_dup 2)
2718                          (match_operand:SI 3 "gpc_reg_operand" "r,r")))
2719          (const_int 0)))
2720    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2721         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2722                 (and:SI (match_dup 2) (match_dup 3))))]
2723   "TARGET_POWER"
2724   "@
2725    maskir. %0,%3,%2
2726    #"
2727   [(set_attr "type" "compare")
2728    (set_attr "length" "4,8")])
2729
2730 (define_split
2731   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2732         (compare:CC
2733          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
2734                          (match_operand:SI 1 "gpc_reg_operand" ""))
2735                  (and:SI (match_dup 2)
2736                          (match_operand:SI 3 "gpc_reg_operand" "")))
2737          (const_int 0)))
2738    (set (match_operand:SI 0 "gpc_reg_operand" "")
2739         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2740                 (and:SI (match_dup 2) (match_dup 3))))]
2741   "TARGET_POWER && reload_completed"
2742   [(set (match_dup 0)
2743         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2744                 (and:SI (match_dup 2) (match_dup 3))))
2745    (set (match_dup 4)
2746         (compare:CC (match_dup 0)
2747                     (const_int 0)))]
2748   "")
2749
2750 (define_insn "*maskir_internal6"
2751   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2752         (compare:CC
2753          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2754                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
2755                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
2756                          (match_dup 2)))
2757          (const_int 0)))
2758    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2759         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2760                 (and:SI (match_dup 3) (match_dup 2))))]
2761   "TARGET_POWER"
2762   "@
2763    maskir. %0,%3,%2
2764    #"
2765   [(set_attr "type" "compare")
2766    (set_attr "length" "4,8")])
2767
2768 (define_split
2769   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2770         (compare:CC
2771          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
2772                          (match_operand:SI 1 "gpc_reg_operand" ""))
2773                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
2774                          (match_dup 2)))
2775          (const_int 0)))
2776    (set (match_operand:SI 0 "gpc_reg_operand" "")
2777         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2778                 (and:SI (match_dup 3) (match_dup 2))))]
2779   "TARGET_POWER && reload_completed"
2780   [(set (match_dup 0)
2781         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2782                 (and:SI (match_dup 3) (match_dup 2))))
2783    (set (match_dup 4)
2784         (compare:CC (match_dup 0)
2785                     (const_int 0)))]
2786   "")
2787
2788 (define_insn "*maskir_internal7"
2789   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2790         (compare:CC
2791          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r,r")
2792                          (match_operand:SI 3 "gpc_reg_operand" "r,r"))
2793                  (and:SI (not:SI (match_dup 2))
2794                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
2795          (const_int 0)))
2796    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2797         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2798                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2799   "TARGET_POWER"
2800   "@
2801    maskir. %0,%3,%2
2802    #"
2803   [(set_attr "type" "compare")
2804    (set_attr "length" "4,8")])
2805
2806 (define_split
2807   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2808         (compare:CC
2809          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "")
2810                          (match_operand:SI 3 "gpc_reg_operand" ""))
2811                  (and:SI (not:SI (match_dup 2))
2812                          (match_operand:SI 1 "gpc_reg_operand" "")))
2813          (const_int 0)))
2814    (set (match_operand:SI 0 "gpc_reg_operand" "")
2815         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2816                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2817   "TARGET_POWER && reload_completed"
2818   [(set (match_dup 0)
2819         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2820                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
2821    (set (match_dup 4)
2822         (compare:CC (match_dup 0)
2823                     (const_int 0)))]
2824   "")
2825
2826 (define_insn "*maskir_internal8"
2827   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2828         (compare:CC
2829          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
2830                          (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2831                  (and:SI (not:SI (match_dup 2))
2832                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
2833          (const_int 0)))
2834    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2835         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2836                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2837   "TARGET_POWER"
2838   "@
2839    maskir. %0,%3,%2
2840    #"
2841   [(set_attr "type" "compare")
2842    (set_attr "length" "4,8")])
2843
2844 (define_split
2845   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2846         (compare:CC
2847          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
2848                          (match_operand:SI 2 "gpc_reg_operand" ""))
2849                  (and:SI (not:SI (match_dup 2))
2850                          (match_operand:SI 1 "gpc_reg_operand" "")))
2851          (const_int 0)))
2852    (set (match_operand:SI 0 "gpc_reg_operand" "")
2853         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2854                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2855   "TARGET_POWER && reload_completed"
2856   [(set (match_dup 0)
2857         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2858                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
2859    (set (match_dup 4)
2860         (compare:CC (match_dup 0)
2861                     (const_int 0)))]
2862   "")
2863 \f
2864 ;; Rotate and shift insns, in all their variants.  These support shifts,
2865 ;; field inserts and extracts, and various combinations thereof.
2866 (define_expand "insv"
2867   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
2868                        (match_operand:SI 1 "const_int_operand" "")
2869                        (match_operand:SI 2 "const_int_operand" ""))
2870         (match_operand 3 "gpc_reg_operand" ""))]
2871   ""
2872   "
2873 {
2874   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
2875      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
2876      compiler if the address of the structure is taken later.  */
2877   if (GET_CODE (operands[0]) == SUBREG
2878       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
2879     FAIL;
2880
2881   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
2882     emit_insn (gen_insvdi (operands[0], operands[1], operands[2], operands[3]));
2883   else
2884     emit_insn (gen_insvsi (operands[0], operands[1], operands[2], operands[3]));
2885   DONE;
2886 }")
2887
2888 (define_insn "insvsi"
2889   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2890                          (match_operand:SI 1 "const_int_operand" "i")
2891                          (match_operand:SI 2 "const_int_operand" "i"))
2892         (match_operand:SI 3 "gpc_reg_operand" "r"))]
2893   ""
2894   "*
2895 {
2896   int start = INTVAL (operands[2]) & 31;
2897   int size = INTVAL (operands[1]) & 31;
2898
2899   operands[4] = GEN_INT (32 - start - size);
2900   operands[1] = GEN_INT (start + size - 1);
2901   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2902 }"
2903   [(set_attr "type" "insert_word")])
2904
2905 (define_insn "*insvsi_internal1"
2906   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2907                          (match_operand:SI 1 "const_int_operand" "i")
2908                          (match_operand:SI 2 "const_int_operand" "i"))
2909         (ashift:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2910                    (match_operand:SI 4 "const_int_operand" "i")))]
2911   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
2912   "*
2913 {
2914   int shift = INTVAL (operands[4]) & 31;
2915   int start = INTVAL (operands[2]) & 31;
2916   int size = INTVAL (operands[1]) & 31;
2917
2918   operands[4] = GEN_INT (shift - start - size);
2919   operands[1] = GEN_INT (start + size - 1);
2920   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2921 }"
2922   [(set_attr "type" "insert_word")])
2923
2924 (define_insn "*insvsi_internal2"
2925   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2926                          (match_operand:SI 1 "const_int_operand" "i")
2927                          (match_operand:SI 2 "const_int_operand" "i"))
2928         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2929                      (match_operand:SI 4 "const_int_operand" "i")))]
2930   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
2931   "*
2932 {
2933   int shift = INTVAL (operands[4]) & 31;
2934   int start = INTVAL (operands[2]) & 31;
2935   int size = INTVAL (operands[1]) & 31;
2936
2937   operands[4] = GEN_INT (32 - shift - start - size);
2938   operands[1] = GEN_INT (start + size - 1);
2939   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2940 }"
2941   [(set_attr "type" "insert_word")])
2942
2943 (define_insn "*insvsi_internal3"
2944   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2945                          (match_operand:SI 1 "const_int_operand" "i")
2946                          (match_operand:SI 2 "const_int_operand" "i"))
2947         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2948                      (match_operand:SI 4 "const_int_operand" "i")))]
2949   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
2950   "*
2951 {
2952   int shift = INTVAL (operands[4]) & 31;
2953   int start = INTVAL (operands[2]) & 31;
2954   int size = INTVAL (operands[1]) & 31;
2955
2956   operands[4] = GEN_INT (32 - shift - start - size);
2957   operands[1] = GEN_INT (start + size - 1);
2958   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2959 }"
2960   [(set_attr "type" "insert_word")])
2961
2962 (define_insn "*insvsi_internal4"
2963   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2964                          (match_operand:SI 1 "const_int_operand" "i")
2965                          (match_operand:SI 2 "const_int_operand" "i"))
2966         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2967                          (match_operand:SI 4 "const_int_operand" "i")
2968                          (match_operand:SI 5 "const_int_operand" "i")))]
2969   "INTVAL (operands[4]) >= INTVAL (operands[1])"
2970   "*
2971 {
2972   int extract_start = INTVAL (operands[5]) & 31;
2973   int extract_size = INTVAL (operands[4]) & 31;
2974   int insert_start = INTVAL (operands[2]) & 31;
2975   int insert_size = INTVAL (operands[1]) & 31;
2976
2977 /* Align extract field with insert field */
2978   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
2979   operands[1] = GEN_INT (insert_start + insert_size - 1);
2980   return \"{rlimi|rlwimi} %0,%3,%h5,%h2,%h1\";
2981 }"
2982   [(set_attr "type" "insert_word")])
2983
2984 (define_insn "insvdi"
2985   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
2986                          (match_operand:SI 1 "const_int_operand" "i")
2987                          (match_operand:SI 2 "const_int_operand" "i"))
2988         (match_operand:DI 3 "gpc_reg_operand" "r"))]
2989   "TARGET_POWERPC64"
2990   "*
2991 {
2992   int start = INTVAL (operands[2]) & 63;
2993   int size = INTVAL (operands[1]) & 63;
2994
2995   operands[1] = GEN_INT (64 - start - size);
2996   return \"rldimi %0,%3,%H1,%H2\";
2997 }")
2998
2999 (define_expand "extzv"
3000   [(set (match_operand 0 "gpc_reg_operand" "")
3001         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3002                        (match_operand:SI 2 "const_int_operand" "")
3003                        (match_operand:SI 3 "const_int_operand" "")))]
3004   ""
3005   "
3006 {
3007   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3008      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3009      compiler if the address of the structure is taken later.  */
3010   if (GET_CODE (operands[0]) == SUBREG
3011       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3012     FAIL;
3013
3014   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3015     emit_insn (gen_extzvdi (operands[0], operands[1], operands[2], operands[3]));
3016   else
3017     emit_insn (gen_extzvsi (operands[0], operands[1], operands[2], operands[3]));
3018   DONE;
3019 }")
3020
3021 (define_insn "extzvsi"
3022   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3023         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3024                          (match_operand:SI 2 "const_int_operand" "i")
3025                          (match_operand:SI 3 "const_int_operand" "i")))]
3026   ""
3027   "*
3028 {
3029   int start = INTVAL (operands[3]) & 31;
3030   int size = INTVAL (operands[2]) & 31;
3031
3032   if (start + size >= 32)
3033     operands[3] = const0_rtx;
3034   else
3035     operands[3] = GEN_INT (start + size);
3036   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
3037 }")
3038
3039 (define_insn "*extzvsi_internal1"
3040   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3041         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3042                          (match_operand:SI 2 "const_int_operand" "i,i")
3043                          (match_operand:SI 3 "const_int_operand" "i,i"))
3044                     (const_int 0)))
3045    (clobber (match_scratch:SI 4 "=r,r"))]
3046   ""
3047   "*
3048 {
3049   int start = INTVAL (operands[3]) & 31;
3050   int size = INTVAL (operands[2]) & 31;
3051
3052   /* Force split for non-cc0 compare.  */
3053   if (which_alternative == 1)
3054      return \"#\";
3055
3056   /* If the bit-field being tested fits in the upper or lower half of a
3057      word, it is possible to use andiu. or andil. to test it.  This is
3058      useful because the condition register set-use delay is smaller for
3059      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3060      position is 0 because the LT and GT bits may be set wrong.  */
3061
3062   if ((start > 0 && start + size <= 16) || start >= 16)
3063     {
3064       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3065                               - (1 << (16 - (start & 15) - size))));
3066       if (start < 16)
3067         return \"{andiu.|andis.} %4,%1,%3\";
3068       else
3069         return \"{andil.|andi.} %4,%1,%3\";
3070     }
3071
3072   if (start + size >= 32)
3073     operands[3] = const0_rtx;
3074   else
3075     operands[3] = GEN_INT (start + size);
3076   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
3077 }"
3078   [(set_attr "type" "compare")
3079    (set_attr "length" "4,8")])
3080
3081 (define_split
3082   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3083         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3084                          (match_operand:SI 2 "const_int_operand" "")
3085                          (match_operand:SI 3 "const_int_operand" ""))
3086                     (const_int 0)))
3087    (clobber (match_scratch:SI 4 ""))]
3088   "reload_completed"
3089   [(set (match_dup 4)
3090         (zero_extract:SI (match_dup 1) (match_dup 2)
3091                          (match_dup 3)))
3092    (set (match_dup 0)
3093         (compare:CC (match_dup 4)
3094                     (const_int 0)))]
3095   "")
3096
3097 (define_insn "*extzvsi_internal2"
3098   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3099         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3100                          (match_operand:SI 2 "const_int_operand" "i,i")
3101                          (match_operand:SI 3 "const_int_operand" "i,i"))
3102                     (const_int 0)))
3103    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3104         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3105   ""
3106   "*
3107 {
3108   int start = INTVAL (operands[3]) & 31;
3109   int size = INTVAL (operands[2]) & 31;
3110
3111   /* Force split for non-cc0 compare.  */
3112   if (which_alternative == 1)
3113      return \"#\";
3114
3115   /* Since we are using the output value, we can't ignore any need for
3116      a shift.  The bit-field must end at the LSB.  */
3117   if (start >= 16 && start + size == 32)
3118     {
3119       operands[3] = GEN_INT ((1 << size) - 1);
3120       return \"{andil.|andi.} %0,%1,%3\";
3121     }
3122
3123   if (start + size >= 32)
3124     operands[3] = const0_rtx;
3125   else
3126     operands[3] = GEN_INT (start + size);
3127   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
3128 }"
3129   [(set_attr "type" "compare")
3130    (set_attr "length" "4,8")])
3131
3132 (define_split
3133   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3134         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3135                          (match_operand:SI 2 "const_int_operand" "")
3136                          (match_operand:SI 3 "const_int_operand" ""))
3137                     (const_int 0)))
3138    (set (match_operand:SI 0 "gpc_reg_operand" "")
3139         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3140   "reload_completed"
3141   [(set (match_dup 0)
3142         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3143    (set (match_dup 4)
3144         (compare:CC (match_dup 0)
3145                     (const_int 0)))]
3146   "")
3147
3148 (define_insn "extzvdi"
3149   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3150         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3151                          (match_operand:SI 2 "const_int_operand" "i")
3152                          (match_operand:SI 3 "const_int_operand" "i")))]
3153   "TARGET_POWERPC64"
3154   "*
3155 {
3156   int start = INTVAL (operands[3]) & 63;
3157   int size = INTVAL (operands[2]) & 63;
3158
3159   if (start + size >= 64)
3160     operands[3] = const0_rtx;
3161   else
3162     operands[3] = GEN_INT (start + size);
3163   operands[2] = GEN_INT (64 - size);
3164   return \"rldicl %0,%1,%3,%2\";
3165 }")
3166
3167 (define_insn "*extzvdi_internal1"
3168   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3169         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3170                          (match_operand:SI 2 "const_int_operand" "i")
3171                          (match_operand:SI 3 "const_int_operand" "i"))
3172                     (const_int 0)))
3173    (clobber (match_scratch:DI 4 "=r"))]
3174   "TARGET_64BIT"
3175   "*
3176 {
3177   int start = INTVAL (operands[3]) & 63;
3178   int size = INTVAL (operands[2]) & 63;
3179
3180   if (start + size >= 64)
3181     operands[3] = const0_rtx;
3182   else
3183     operands[3] = GEN_INT (start + size);
3184   operands[2] = GEN_INT (64 - size);
3185   return \"rldicl. %4,%1,%3,%2\";
3186 }")
3187
3188 (define_insn "*extzvdi_internal2"
3189   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3190         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3191                          (match_operand:SI 2 "const_int_operand" "i")
3192                          (match_operand:SI 3 "const_int_operand" "i"))
3193                     (const_int 0)))
3194    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3195         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3196   "TARGET_64BIT"
3197   "*
3198 {
3199   int start = INTVAL (operands[3]) & 63;
3200   int size = INTVAL (operands[2]) & 63;
3201
3202   if (start + size >= 64)
3203     operands[3] = const0_rtx;
3204   else
3205     operands[3] = GEN_INT (start + size);
3206   operands[2] = GEN_INT (64 - size);
3207   return \"rldicl. %0,%1,%3,%2\";
3208 }")
3209
3210 (define_insn "rotlsi3"
3211   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3212         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3213                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3214   ""
3215   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffffffff")
3216
3217 (define_insn "*rotlsi3_internal2"
3218   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3219         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3220                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3221                     (const_int 0)))
3222    (clobber (match_scratch:SI 3 "=r,r"))]
3223   ""
3224   "@
3225    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffffffff
3226    #"
3227   [(set_attr "type" "delayed_compare")
3228    (set_attr "length" "4,8")])
3229
3230 (define_split
3231   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3232         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3233                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3234                     (const_int 0)))
3235    (clobber (match_scratch:SI 3 ""))]
3236   "reload_completed"
3237   [(set (match_dup 3)
3238         (rotate:SI (match_dup 1) (match_dup 2)))
3239    (set (match_dup 0)
3240         (compare:CC (match_dup 3)
3241                     (const_int 0)))]
3242   "")
3243
3244 (define_insn "*rotlsi3_internal3"
3245   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3246         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3247                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3248                     (const_int 0)))
3249    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3250         (rotate:SI (match_dup 1) (match_dup 2)))]
3251   ""
3252   "@
3253    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffffffff
3254    #"
3255   [(set_attr "type" "delayed_compare")
3256    (set_attr "length" "4,8")])
3257
3258 (define_split
3259   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3260         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3261                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3262                     (const_int 0)))
3263    (set (match_operand:SI 0 "gpc_reg_operand" "")
3264         (rotate:SI (match_dup 1) (match_dup 2)))]
3265   "reload_completed"
3266   [(set (match_dup 0)
3267         (rotate:SI (match_dup 1) (match_dup 2)))
3268    (set (match_dup 3)
3269         (compare:CC (match_dup 0)
3270                     (const_int 0)))]
3271   "")
3272
3273 (define_insn "*rotlsi3_internal4"
3274   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3275         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3276                            (match_operand:SI 2 "reg_or_cint_operand" "ri"))
3277                 (match_operand:SI 3 "mask_operand" "n")))]
3278   ""
3279   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,%m3,%M3")
3280
3281 (define_insn "*rotlsi3_internal5"
3282   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3283         (compare:CC (and:SI
3284                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3285                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3286                      (match_operand:SI 3 "mask_operand" "n,n"))
3287                     (const_int 0)))
3288    (clobber (match_scratch:SI 4 "=r,r"))]
3289   ""
3290   "@
3291    {rl%I2nm.|rlw%I2nm.} %4,%1,%h2,%m3,%M3
3292    #"
3293   [(set_attr "type" "delayed_compare")
3294    (set_attr "length" "4,8")])
3295
3296 (define_split
3297   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3298         (compare:CC (and:SI
3299                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3300                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3301                      (match_operand:SI 3 "mask_operand" ""))
3302                     (const_int 0)))
3303    (clobber (match_scratch:SI 4 ""))]
3304   "reload_completed"
3305   [(set (match_dup 4)
3306         (and:SI (rotate:SI (match_dup 1)
3307                                 (match_dup 2))
3308                      (match_dup 3)))
3309    (set (match_dup 0)
3310         (compare:CC (match_dup 4)
3311                     (const_int 0)))]
3312   "")
3313
3314 (define_insn "*rotlsi3_internal6"
3315   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3316         (compare:CC (and:SI
3317                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3318                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3319                      (match_operand:SI 3 "mask_operand" "n,n"))
3320                     (const_int 0)))
3321    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3322         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3323   ""
3324   "@
3325    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,%m3,%M3
3326    #"
3327   [(set_attr "type" "delayed_compare")
3328    (set_attr "length" "4,8")])
3329
3330 (define_split
3331   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3332         (compare:CC (and:SI
3333                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3334                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3335                      (match_operand:SI 3 "mask_operand" ""))
3336                     (const_int 0)))
3337    (set (match_operand:SI 0 "gpc_reg_operand" "")
3338         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3339   "reload_completed"
3340   [(set (match_dup 0)
3341         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3342    (set (match_dup 4)
3343         (compare:CC (match_dup 0)
3344                     (const_int 0)))]
3345   "")
3346
3347 (define_insn "*rotlsi3_internal7"
3348   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3349         (zero_extend:SI
3350          (subreg:QI
3351           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3352                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3353   ""
3354   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff")
3355
3356 (define_insn "*rotlsi3_internal8"
3357   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3358         (compare:CC (zero_extend:SI
3359                      (subreg:QI
3360                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3361                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3362                     (const_int 0)))
3363    (clobber (match_scratch:SI 3 "=r,r"))]
3364   ""
3365   "@
3366    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xff
3367    #"
3368   [(set_attr "type" "delayed_compare")
3369    (set_attr "length" "4,8")])
3370
3371 (define_split
3372   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3373         (compare:CC (zero_extend:SI
3374                      (subreg:QI
3375                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3376                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3377                     (const_int 0)))
3378    (clobber (match_scratch:SI 3 ""))]
3379   "reload_completed"
3380   [(set (match_dup 3)
3381         (zero_extend:SI (subreg:QI
3382                       (rotate:SI (match_dup 1)
3383                                  (match_dup 2)) 0)))
3384    (set (match_dup 0)
3385         (compare:CC (match_dup 3)
3386                     (const_int 0)))]
3387   "")
3388
3389 (define_insn "*rotlsi3_internal9"
3390   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3391         (compare:CC (zero_extend:SI
3392                      (subreg:QI
3393                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3394                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3395                     (const_int 0)))
3396    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3397         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3398   ""
3399   "@
3400    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xff
3401    #"
3402   [(set_attr "type" "delayed_compare")
3403    (set_attr "length" "4,8")])
3404
3405 (define_split
3406   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3407         (compare:CC (zero_extend:SI
3408                      (subreg:QI
3409                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3410                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3411                     (const_int 0)))
3412    (set (match_operand:SI 0 "gpc_reg_operand" "")
3413         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3414   "reload_completed"
3415   [(set (match_dup 0)
3416         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3417    (set (match_dup 3)
3418         (compare:CC (match_dup 0)
3419                     (const_int 0)))]
3420   "")
3421
3422 (define_insn "*rotlsi3_internal10"
3423   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3424         (zero_extend:SI
3425          (subreg:HI
3426           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3427                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3428   ""
3429   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffff")
3430
3431 (define_insn "*rotlsi3_internal11"
3432   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3433         (compare:CC (zero_extend:SI
3434                      (subreg:HI
3435                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3436                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3437                     (const_int 0)))
3438    (clobber (match_scratch:SI 3 "=r,r"))]
3439   ""
3440   "@
3441    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffff
3442    #"
3443   [(set_attr "type" "delayed_compare")
3444    (set_attr "length" "4,8")])
3445
3446 (define_split
3447   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3448         (compare:CC (zero_extend:SI
3449                      (subreg:HI
3450                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3451                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3452                     (const_int 0)))
3453    (clobber (match_scratch:SI 3 ""))]
3454   "reload_completed"
3455   [(set (match_dup 3)
3456         (zero_extend:SI (subreg:HI
3457                       (rotate:SI (match_dup 1)
3458                                  (match_dup 2)) 0)))
3459    (set (match_dup 0)
3460         (compare:CC (match_dup 3)
3461                     (const_int 0)))]
3462   "")
3463
3464 (define_insn "*rotlsi3_internal12"
3465   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3466         (compare:CC (zero_extend:SI
3467                      (subreg:HI
3468                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3469                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3470                     (const_int 0)))
3471    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3472         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3473   ""
3474   "@
3475    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffff
3476    #"
3477   [(set_attr "type" "delayed_compare")
3478    (set_attr "length" "4,8")])
3479
3480 (define_split
3481   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3482         (compare:CC (zero_extend:SI
3483                      (subreg:HI
3484                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3485                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3486                     (const_int 0)))
3487    (set (match_operand:SI 0 "gpc_reg_operand" "")
3488         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3489   "reload_completed"
3490   [(set (match_dup 0)
3491         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3492    (set (match_dup 3)
3493         (compare:CC (match_dup 0)
3494                     (const_int 0)))]
3495   "")
3496
3497 ;; Note that we use "sle." instead of "sl." so that we can set
3498 ;; SHIFT_COUNT_TRUNCATED.
3499
3500 (define_expand "ashlsi3"
3501   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
3502    (use (match_operand:SI 1 "gpc_reg_operand" ""))
3503    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
3504   ""
3505   "
3506 {
3507   if (TARGET_POWER)
3508     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
3509   else
3510     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
3511   DONE;
3512 }")
3513
3514 (define_insn "ashlsi3_power"
3515   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3516         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3517                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
3518    (clobber (match_scratch:SI 3 "=q,X"))]
3519   "TARGET_POWER"
3520   "@
3521    sle %0,%1,%2
3522    {sli|slwi} %0,%1,%h2")
3523
3524 (define_insn "ashlsi3_no_power"
3525   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3526         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3527                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3528   "! TARGET_POWER"
3529   "{sl|slw}%I2 %0,%1,%h2")
3530
3531 (define_insn ""
3532   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3533         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3534                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3535                     (const_int 0)))
3536    (clobber (match_scratch:SI 3 "=r,r,r,r"))
3537    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
3538   "TARGET_POWER"
3539   "@
3540    sle. %3,%1,%2
3541    {sli.|slwi.} %3,%1,%h2
3542    #
3543    #"
3544   [(set_attr "type" "delayed_compare")
3545    (set_attr "length" "4,4,8,8")])
3546
3547 (define_split
3548   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3549         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3550                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3551                     (const_int 0)))
3552    (clobber (match_scratch:SI 3 ""))
3553    (clobber (match_scratch:SI 4 ""))]
3554   "TARGET_POWER && reload_completed"
3555   [(parallel [(set (match_dup 3)
3556         (ashift:SI (match_dup 1) (match_dup 2)))
3557    (clobber (match_dup 4))])
3558    (set (match_dup 0)
3559         (compare:CC (match_dup 3)
3560                     (const_int 0)))]
3561   "")
3562
3563 (define_insn ""
3564   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3565         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3566                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3567                     (const_int 0)))
3568    (clobber (match_scratch:SI 3 "=r,r"))]
3569   "! TARGET_POWER && TARGET_32BIT"
3570   "@
3571    {sl|slw}%I2. %3,%1,%h2
3572    #"
3573   [(set_attr "type" "delayed_compare")
3574    (set_attr "length" "4,8")])
3575
3576 (define_split
3577   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3578         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3579                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3580                     (const_int 0)))
3581    (clobber (match_scratch:SI 3 ""))]
3582   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3583   [(set (match_dup 3)
3584         (ashift:SI (match_dup 1) (match_dup 2)))
3585    (set (match_dup 0)
3586         (compare:CC (match_dup 3)
3587                     (const_int 0)))]
3588   "")
3589
3590 (define_insn ""
3591   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3592         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3593                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3594                     (const_int 0)))
3595    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3596         (ashift:SI (match_dup 1) (match_dup 2)))
3597    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
3598   "TARGET_POWER"
3599   "@
3600    sle. %0,%1,%2
3601    {sli.|slwi.} %0,%1,%h2
3602    #
3603    #"
3604   [(set_attr "type" "delayed_compare")
3605    (set_attr "length" "4,4,8,8")])
3606
3607 (define_split
3608   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3609         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3610                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3611                     (const_int 0)))
3612    (set (match_operand:SI 0 "gpc_reg_operand" "")
3613         (ashift:SI (match_dup 1) (match_dup 2)))
3614    (clobber (match_scratch:SI 4 ""))]
3615   "TARGET_POWER && reload_completed"
3616   [(parallel [(set (match_dup 0)
3617         (ashift:SI (match_dup 1) (match_dup 2)))
3618    (clobber (match_dup 4))])
3619    (set (match_dup 3)
3620         (compare:CC (match_dup 0)
3621                     (const_int 0)))]
3622   "")
3623
3624 (define_insn ""
3625   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3626         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3627                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3628                     (const_int 0)))
3629    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3630         (ashift:SI (match_dup 1) (match_dup 2)))]
3631   "! TARGET_POWER && TARGET_32BIT"
3632   "@
3633    {sl|slw}%I2. %0,%1,%h2
3634    #"
3635   [(set_attr "type" "delayed_compare")
3636    (set_attr "length" "4,8")])
3637
3638 (define_split
3639   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3640         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3641                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3642                     (const_int 0)))
3643    (set (match_operand:SI 0 "gpc_reg_operand" "")
3644         (ashift:SI (match_dup 1) (match_dup 2)))]
3645   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3646   [(set (match_dup 0)
3647         (ashift:SI (match_dup 1) (match_dup 2)))
3648    (set (match_dup 3)
3649         (compare:CC (match_dup 0)
3650                     (const_int 0)))]
3651   "")
3652
3653 (define_insn ""
3654   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3655         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3656                            (match_operand:SI 2 "const_int_operand" "i"))
3657                 (match_operand:SI 3 "mask_operand" "n")))]
3658   "includes_lshift_p (operands[2], operands[3])"
3659   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
3660
3661 (define_insn ""
3662   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3663         (compare:CC
3664          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3665                             (match_operand:SI 2 "const_int_operand" "i,i"))
3666                  (match_operand:SI 3 "mask_operand" "n,n"))
3667          (const_int 0)))
3668    (clobber (match_scratch:SI 4 "=r,r"))]
3669   "includes_lshift_p (operands[2], operands[3])"
3670   "@
3671    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
3672    #"
3673   [(set_attr "type" "delayed_compare")
3674    (set_attr "length" "4,8")])
3675
3676 (define_split
3677   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3678         (compare:CC
3679          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3680                             (match_operand:SI 2 "const_int_operand" ""))
3681                  (match_operand:SI 3 "mask_operand" ""))
3682          (const_int 0)))
3683    (clobber (match_scratch:SI 4 ""))]
3684   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
3685   [(set (match_dup 4)
3686         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
3687                  (match_dup 3)))
3688    (set (match_dup 0)
3689         (compare:CC (match_dup 4)
3690                     (const_int 0)))]
3691   "")
3692
3693 (define_insn ""
3694   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3695         (compare:CC
3696          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3697                             (match_operand:SI 2 "const_int_operand" "i,i"))
3698                  (match_operand:SI 3 "mask_operand" "n,n"))
3699          (const_int 0)))
3700    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3701         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3702   "includes_lshift_p (operands[2], operands[3])"
3703   "@
3704    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
3705    #"
3706   [(set_attr "type" "delayed_compare")
3707    (set_attr "length" "4,8")])
3708
3709 (define_split
3710   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3711         (compare:CC
3712          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3713                             (match_operand:SI 2 "const_int_operand" ""))
3714                  (match_operand:SI 3 "mask_operand" ""))
3715          (const_int 0)))
3716    (set (match_operand:SI 0 "gpc_reg_operand" "")
3717         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3718   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
3719   [(set (match_dup 0)
3720         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3721    (set (match_dup 4)
3722         (compare:CC (match_dup 0)
3723                     (const_int 0)))]
3724   "")
3725
3726 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
3727 ;; "sli x,x,0".
3728 (define_expand "lshrsi3"
3729   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
3730    (use (match_operand:SI 1 "gpc_reg_operand" ""))
3731    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
3732   ""
3733   "
3734 {
3735   if (TARGET_POWER)
3736     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
3737   else
3738     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
3739   DONE;
3740 }")
3741
3742 (define_insn "lshrsi3_power"
3743   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
3744         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
3745                      (match_operand:SI 2 "reg_or_cint_operand" "r,O,i")))
3746    (clobber (match_scratch:SI 3 "=q,X,X"))]
3747   "TARGET_POWER"
3748   "@
3749   sre %0,%1,%2
3750   mr %0,%1
3751   {s%A2i|s%A2wi} %0,%1,%h2")
3752
3753 (define_insn "lshrsi3_no_power"
3754   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3755         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3756                      (match_operand:SI 2 "reg_or_cint_operand" "O,ri")))]
3757   "! TARGET_POWER"
3758   "@
3759   mr %0,%1
3760   {sr|srw}%I2 %0,%1,%h2")
3761
3762 (define_insn ""
3763   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
3764         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
3765                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
3766                     (const_int 0)))
3767    (clobber (match_scratch:SI 3 "=r,X,r,r,X,r"))
3768    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
3769   "TARGET_POWER"
3770   "@
3771   sre. %3,%1,%2
3772   mr. %1,%1
3773   {s%A2i.|s%A2wi.} %3,%1,%h2
3774   #
3775   #
3776   #"
3777   [(set_attr "type" "delayed_compare")
3778    (set_attr "length" "4,4,4,8,8,8")])
3779
3780 (define_split
3781   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3782         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3783                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3784                     (const_int 0)))
3785    (clobber (match_scratch:SI 3 ""))
3786    (clobber (match_scratch:SI 4 ""))]
3787   "TARGET_POWER && reload_completed"
3788   [(parallel [(set (match_dup 3)
3789         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3790    (clobber (match_dup 4))])
3791    (set (match_dup 0)
3792         (compare:CC (match_dup 3)
3793                     (const_int 0)))]
3794   "")
3795
3796 (define_insn ""
3797   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3798         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3799                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
3800                     (const_int 0)))
3801    (clobber (match_scratch:SI 3 "=X,r,X,r"))]
3802   "! TARGET_POWER && TARGET_32BIT"
3803   "@
3804    mr. %1,%1
3805    {sr|srw}%I2. %3,%1,%h2
3806    #
3807    #"
3808   [(set_attr "type" "delayed_compare")
3809    (set_attr "length" "4,4,8,8")])
3810
3811 (define_split
3812   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3813         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3814                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3815                     (const_int 0)))
3816    (clobber (match_scratch:SI 3 ""))]
3817   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3818   [(set (match_dup 3)
3819         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3820    (set (match_dup 0)
3821         (compare:CC (match_dup 3)
3822                     (const_int 0)))]
3823   "")
3824
3825 (define_insn ""
3826   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
3827         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
3828                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
3829                     (const_int 0)))
3830    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
3831         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3832    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
3833   "TARGET_POWER"
3834   "@
3835   sre. %0,%1,%2
3836   mr. %0,%1
3837   {s%A2i.|s%A2wi.} %0,%1,%h2
3838   #
3839   #
3840   #"
3841   [(set_attr "type" "delayed_compare")
3842    (set_attr "length" "4,4,4,8,8,8")])
3843
3844 (define_split
3845   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3846         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3847                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3848                     (const_int 0)))
3849    (set (match_operand:SI 0 "gpc_reg_operand" "")
3850         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3851    (clobber (match_scratch:SI 4 ""))]
3852   "TARGET_POWER && reload_completed"
3853   [(parallel [(set (match_dup 0)
3854         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3855    (clobber (match_dup 4))])
3856    (set (match_dup 3)
3857         (compare:CC (match_dup 0)
3858                     (const_int 0)))]
3859   "")
3860
3861 (define_insn ""
3862   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3863         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3864                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
3865                     (const_int 0)))
3866    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3867         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
3868   "! TARGET_POWER && TARGET_32BIT"
3869   "@
3870    mr. %0,%1
3871    {sr|srw}%I2. %0,%1,%h2
3872    #
3873    #"
3874   [(set_attr "type" "delayed_compare")
3875    (set_attr "length" "4,4,8,8")])
3876
3877 (define_split
3878   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3879         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3880                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3881                     (const_int 0)))
3882    (set (match_operand:SI 0 "gpc_reg_operand" "")
3883         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
3884   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3885   [(set (match_dup 0)
3886         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3887    (set (match_dup 3)
3888         (compare:CC (match_dup 0)
3889                     (const_int 0)))]
3890   "")
3891
3892 (define_insn ""
3893   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3894         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3895                              (match_operand:SI 2 "const_int_operand" "i"))
3896                 (match_operand:SI 3 "mask_operand" "n")))]
3897   "includes_rshift_p (operands[2], operands[3])"
3898   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
3899
3900 (define_insn ""
3901   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3902         (compare:CC
3903          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3904                               (match_operand:SI 2 "const_int_operand" "i,i"))
3905                  (match_operand:SI 3 "mask_operand" "n,n"))
3906          (const_int 0)))
3907    (clobber (match_scratch:SI 4 "=r,r"))]
3908   "includes_rshift_p (operands[2], operands[3])"
3909   "@
3910    {rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3
3911    #"
3912   [(set_attr "type" "delayed_compare")
3913    (set_attr "length" "4,8")])
3914
3915 (define_split
3916   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3917         (compare:CC
3918          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3919                               (match_operand:SI 2 "const_int_operand" ""))
3920                  (match_operand:SI 3 "mask_operand" ""))
3921          (const_int 0)))
3922    (clobber (match_scratch:SI 4 ""))]
3923   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
3924   [(set (match_dup 4)
3925         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
3926                  (match_dup 3)))
3927    (set (match_dup 0)
3928         (compare:CC (match_dup 4)
3929                     (const_int 0)))]
3930   "")
3931
3932 (define_insn ""
3933   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3934         (compare:CC
3935          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3936                               (match_operand:SI 2 "const_int_operand" "i,i"))
3937                  (match_operand:SI 3 "mask_operand" "n,n"))
3938          (const_int 0)))
3939    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3940         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3941   "includes_rshift_p (operands[2], operands[3])"
3942   "@
3943    {rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3
3944    #"
3945   [(set_attr "type" "delayed_compare")
3946    (set_attr "length" "4,8")])
3947
3948 (define_split
3949   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3950         (compare:CC
3951          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3952                               (match_operand:SI 2 "const_int_operand" ""))
3953                  (match_operand:SI 3 "mask_operand" ""))
3954          (const_int 0)))
3955    (set (match_operand:SI 0 "gpc_reg_operand" "")
3956         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3957   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
3958   [(set (match_dup 0)
3959         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3960    (set (match_dup 4)
3961         (compare:CC (match_dup 0)
3962                     (const_int 0)))]
3963   "")
3964
3965 (define_insn ""
3966   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3967         (zero_extend:SI
3968          (subreg:QI
3969           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3970                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
3971   "includes_rshift_p (operands[2], GEN_INT (255))"
3972   "{rlinm|rlwinm} %0,%1,%s2,0xff")
3973
3974 (define_insn ""
3975   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3976         (compare:CC
3977          (zero_extend:SI
3978           (subreg:QI
3979            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3980                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
3981          (const_int 0)))
3982    (clobber (match_scratch:SI 3 "=r,r"))]
3983   "includes_rshift_p (operands[2], GEN_INT (255))"
3984   "@
3985    {rlinm.|rlwinm.} %3,%1,%s2,0xff
3986    #"
3987   [(set_attr "type" "delayed_compare")
3988    (set_attr "length" "4,8")])
3989
3990 (define_split
3991   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3992         (compare:CC
3993          (zero_extend:SI
3994           (subreg:QI
3995            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3996                         (match_operand:SI 2 "const_int_operand" "")) 0))
3997          (const_int 0)))
3998    (clobber (match_scratch:SI 3 ""))]
3999   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4000   [(set (match_dup 3)
4001         (zero_extend:SI (subreg:QI
4002            (lshiftrt:SI (match_dup 1)
4003                         (match_dup 2)) 0)))
4004    (set (match_dup 0)
4005         (compare:CC (match_dup 3)
4006                     (const_int 0)))]
4007   "")
4008
4009 (define_insn ""
4010   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4011         (compare:CC
4012          (zero_extend:SI
4013           (subreg:QI
4014            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4015                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4016          (const_int 0)))
4017    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4018         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4019   "includes_rshift_p (operands[2], GEN_INT (255))"
4020   "@
4021    {rlinm.|rlwinm.} %0,%1,%s2,0xff
4022    #"
4023   [(set_attr "type" "delayed_compare")
4024    (set_attr "length" "4,8")])
4025
4026 (define_split
4027   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4028         (compare:CC
4029          (zero_extend:SI
4030           (subreg:QI
4031            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4032                         (match_operand:SI 2 "const_int_operand" "")) 0))
4033          (const_int 0)))
4034    (set (match_operand:SI 0 "gpc_reg_operand" "")
4035         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4036   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4037   [(set (match_dup 0)
4038         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4039    (set (match_dup 3)
4040         (compare:CC (match_dup 0)
4041                     (const_int 0)))]
4042   "")
4043
4044 (define_insn ""
4045   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4046         (zero_extend:SI
4047          (subreg:HI
4048           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4049                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4050   "includes_rshift_p (operands[2], GEN_INT (65535))"
4051   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
4052
4053 (define_insn ""
4054   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4055         (compare:CC
4056          (zero_extend:SI
4057           (subreg:HI
4058            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4059                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4060          (const_int 0)))
4061    (clobber (match_scratch:SI 3 "=r,r"))]
4062   "includes_rshift_p (operands[2], GEN_INT (65535))"
4063   "@
4064    {rlinm.|rlwinm.} %3,%1,%s2,0xffff
4065    #"
4066   [(set_attr "type" "delayed_compare")
4067    (set_attr "length" "4,8")])
4068
4069 (define_split
4070   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4071         (compare:CC
4072          (zero_extend:SI
4073           (subreg:HI
4074            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4075                         (match_operand:SI 2 "const_int_operand" "")) 0))
4076          (const_int 0)))
4077    (clobber (match_scratch:SI 3 ""))]
4078   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4079   [(set (match_dup 3)
4080         (zero_extend:SI (subreg:HI
4081            (lshiftrt:SI (match_dup 1)
4082                         (match_dup 2)) 0)))
4083    (set (match_dup 0)
4084         (compare:CC (match_dup 3)
4085                     (const_int 0)))]
4086   "")
4087
4088 (define_insn ""
4089   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4090         (compare:CC
4091          (zero_extend:SI
4092           (subreg:HI
4093            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4094                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4095          (const_int 0)))
4096    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4097         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4098   "includes_rshift_p (operands[2], GEN_INT (65535))"
4099   "@
4100    {rlinm.|rlwinm.} %0,%1,%s2,0xffff
4101    #"
4102   [(set_attr "type" "delayed_compare")
4103    (set_attr "length" "4,8")])
4104
4105 (define_split
4106   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4107         (compare:CC
4108          (zero_extend:SI
4109           (subreg:HI
4110            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4111                         (match_operand:SI 2 "const_int_operand" "")) 0))
4112          (const_int 0)))
4113    (set (match_operand:SI 0 "gpc_reg_operand" "")
4114         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4115   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4116   [(set (match_dup 0)
4117         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4118    (set (match_dup 3)
4119         (compare:CC (match_dup 0)
4120                     (const_int 0)))]
4121   "")
4122
4123 (define_insn ""
4124   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4125                          (const_int 1)
4126                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4127         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4128                      (const_int 31)))]
4129   "TARGET_POWER"
4130   "rrib %0,%1,%2")
4131
4132 (define_insn ""
4133   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4134                          (const_int 1)
4135                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4136         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4137                      (const_int 31)))]
4138   "TARGET_POWER"
4139   "rrib %0,%1,%2")
4140
4141 (define_insn ""
4142   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4143                          (const_int 1)
4144                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4145         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4146                          (const_int 1)
4147                          (const_int 0)))]
4148   "TARGET_POWER"
4149   "rrib %0,%1,%2")
4150
4151 (define_expand "ashrsi3"
4152   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4153         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4154                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
4155   ""
4156   "
4157 {
4158   if (TARGET_POWER)
4159     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
4160   else
4161     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
4162   DONE;
4163 }")
4164
4165 (define_insn "ashrsi3_power"
4166   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4167         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4168                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4169    (clobber (match_scratch:SI 3 "=q,X"))]
4170   "TARGET_POWER"
4171   "@
4172    srea %0,%1,%2
4173    {srai|srawi} %0,%1,%h2")
4174
4175 (define_insn "ashrsi3_no_power"
4176   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4177         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4178                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4179   "! TARGET_POWER"
4180   "{sra|sraw}%I2 %0,%1,%h2")
4181
4182 (define_insn ""
4183   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4184         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4185                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4186                     (const_int 0)))
4187    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4188    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4189   "TARGET_POWER"
4190   "@
4191    srea. %3,%1,%2
4192    {srai.|srawi.} %3,%1,%h2
4193    #
4194    #"
4195   [(set_attr "type" "delayed_compare")
4196    (set_attr "length" "4,4,8,8")])
4197
4198 (define_split
4199   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4200         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4201                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4202                     (const_int 0)))
4203    (clobber (match_scratch:SI 3 ""))
4204    (clobber (match_scratch:SI 4 ""))]
4205   "TARGET_POWER && reload_completed"
4206   [(parallel [(set (match_dup 3)
4207         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4208    (clobber (match_dup 4))])
4209    (set (match_dup 0)
4210         (compare:CC (match_dup 3)
4211                     (const_int 0)))]
4212   "")
4213
4214 (define_insn ""
4215   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4216         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4217                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4218                     (const_int 0)))
4219    (clobber (match_scratch:SI 3 "=r,r"))]
4220   "! TARGET_POWER"
4221   "@
4222    {sra|sraw}%I2. %3,%1,%h2
4223    #"
4224   [(set_attr "type" "delayed_compare")
4225    (set_attr "length" "4,8")])
4226
4227 (define_split
4228   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4229         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4230                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4231                     (const_int 0)))
4232    (clobber (match_scratch:SI 3 ""))]
4233   "! TARGET_POWER && reload_completed"
4234   [(set (match_dup 3)
4235         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4236    (set (match_dup 0)
4237         (compare:CC (match_dup 3)
4238                     (const_int 0)))]
4239   "")
4240
4241 (define_insn ""
4242   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4243         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4244                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4245                     (const_int 0)))
4246    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4247         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4248    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4249   "TARGET_POWER"
4250   "@
4251    srea. %0,%1,%2
4252    {srai.|srawi.} %0,%1,%h2
4253    #
4254    #"
4255   [(set_attr "type" "delayed_compare")
4256    (set_attr "length" "4,4,8,8")])
4257
4258 (define_split
4259   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4260         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4261                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4262                     (const_int 0)))
4263    (set (match_operand:SI 0 "gpc_reg_operand" "")
4264         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4265    (clobber (match_scratch:SI 4 ""))]
4266   "TARGET_POWER && reload_completed"
4267   [(parallel [(set (match_dup 0)
4268         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4269    (clobber (match_dup 4))])
4270    (set (match_dup 3)
4271         (compare:CC (match_dup 0)
4272                     (const_int 0)))]
4273   "")
4274
4275 (define_insn ""
4276   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4277         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4278                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4279                     (const_int 0)))
4280    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4281         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4282   "! TARGET_POWER"
4283   "@
4284    {sra|sraw}%I2. %0,%1,%h2
4285    #"
4286   [(set_attr "type" "delayed_compare")
4287    (set_attr "length" "4,8")])
4288 \f
4289 (define_split
4290   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4291         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4292                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4293                     (const_int 0)))
4294    (set (match_operand:SI 0 "gpc_reg_operand" "")
4295         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4296   "! TARGET_POWER && reload_completed"
4297   [(set (match_dup 0)
4298         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4299    (set (match_dup 3)
4300         (compare:CC (match_dup 0)
4301                     (const_int 0)))]
4302   "")
4303
4304 ;; Floating-point insns, excluding normal data motion.
4305 ;;
4306 ;; PowerPC has a full set of single-precision floating point instructions.
4307 ;;
4308 ;; For the POWER architecture, we pretend that we have both SFmode and
4309 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
4310 ;; The only conversions we will do will be when storing to memory.  In that
4311 ;; case, we will use the "frsp" instruction before storing.
4312 ;;
4313 ;; Note that when we store into a single-precision memory location, we need to
4314 ;; use the frsp insn first.  If the register being stored isn't dead, we
4315 ;; need a scratch register for the frsp.  But this is difficult when the store
4316 ;; is done by reload.  It is not incorrect to do the frsp on the register in
4317 ;; this case, we just lose precision that we would have otherwise gotten but
4318 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
4319
4320 (define_insn "extendsfdf2"
4321   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4322         (float_extend:DF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4323   "TARGET_HARD_FLOAT && TARGET_FPRS"
4324   "*
4325 {
4326   if (REGNO (operands[0]) == REGNO (operands[1]))
4327     return \"\";
4328   else
4329     return \"fmr %0,%1\";
4330 }"
4331   [(set_attr "type" "fp")])
4332
4333 (define_insn "truncdfsf2"
4334   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4335         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4336   "TARGET_HARD_FLOAT && TARGET_FPRS"
4337   "frsp %0,%1"
4338   [(set_attr "type" "fp")])
4339
4340 (define_insn "aux_truncdfsf2"
4341   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4342         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRSP))]
4343   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4344   "frsp %0,%1"
4345   [(set_attr "type" "fp")])
4346
4347 (define_expand "negsf2"
4348   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4349         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4350   "TARGET_HARD_FLOAT"
4351   "")
4352
4353 (define_insn "*negsf2"
4354   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4355         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4356   "TARGET_HARD_FLOAT && TARGET_FPRS"
4357   "fneg %0,%1"
4358   [(set_attr "type" "fp")])
4359
4360 (define_expand "abssf2"
4361   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4362         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4363   "TARGET_HARD_FLOAT"
4364   "")
4365
4366 (define_insn "*abssf2"
4367   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4368         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4369   "TARGET_HARD_FLOAT && TARGET_FPRS"
4370   "fabs %0,%1"
4371   [(set_attr "type" "fp")])
4372
4373 (define_insn ""
4374   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4375         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
4376   "TARGET_HARD_FLOAT && TARGET_FPRS"
4377   "fnabs %0,%1"
4378   [(set_attr "type" "fp")])
4379
4380 (define_expand "addsf3"
4381   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4382         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4383                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4384   "TARGET_HARD_FLOAT"
4385   "")
4386
4387 (define_insn ""
4388   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4389         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4390                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4391   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4392   "fadds %0,%1,%2"
4393   [(set_attr "type" "fp")])
4394
4395 (define_insn ""
4396   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4397         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4398                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4399   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4400   "{fa|fadd} %0,%1,%2"
4401   [(set_attr "type" "fp")])
4402
4403 (define_expand "subsf3"
4404   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4405         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4406                   (match_operand:SF 2 "gpc_reg_operand" "")))]
4407   "TARGET_HARD_FLOAT"
4408   "")
4409
4410 (define_insn ""
4411   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4412         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4413                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
4414   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4415   "fsubs %0,%1,%2"
4416   [(set_attr "type" "fp")])
4417
4418 (define_insn ""
4419   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4420         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4421                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
4422   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4423   "{fs|fsub} %0,%1,%2"
4424   [(set_attr "type" "fp")])
4425
4426 (define_expand "mulsf3"
4427   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4428         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
4429                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4430   "TARGET_HARD_FLOAT"
4431   "")
4432
4433 (define_insn ""
4434   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4435         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4436                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4437   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4438   "fmuls %0,%1,%2"
4439   [(set_attr "type" "fp")])
4440
4441 (define_insn ""
4442   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4443         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4444                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4445   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4446   "{fm|fmul} %0,%1,%2"
4447   [(set_attr "type" "dmul")])
4448
4449 (define_expand "divsf3"
4450   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4451         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
4452                 (match_operand:SF 2 "gpc_reg_operand" "")))]
4453   "TARGET_HARD_FLOAT"
4454   "")
4455
4456 (define_insn ""
4457   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4458         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4459                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
4460   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4461   "fdivs %0,%1,%2"
4462   [(set_attr "type" "sdiv")])
4463
4464 (define_insn ""
4465   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4466         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4467                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
4468   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4469   "{fd|fdiv} %0,%1,%2"
4470   [(set_attr "type" "ddiv")])
4471
4472 (define_insn ""
4473   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4474         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4475                           (match_operand:SF 2 "gpc_reg_operand" "f"))
4476                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
4477   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4478   "fmadds %0,%1,%2,%3"
4479   [(set_attr "type" "fp")])
4480
4481 (define_insn ""
4482   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4483         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4484                           (match_operand:SF 2 "gpc_reg_operand" "f"))
4485                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
4486   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4487   "{fma|fmadd} %0,%1,%2,%3"
4488   [(set_attr "type" "dmul")])
4489
4490 (define_insn ""
4491   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4492         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4493                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4494                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
4495   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4496   "fmsubs %0,%1,%2,%3"
4497   [(set_attr "type" "fp")])
4498
4499 (define_insn ""
4500   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4501         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4502                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4503                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
4504   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4505   "{fms|fmsub} %0,%1,%2,%3"
4506   [(set_attr "type" "dmul")])
4507
4508 (define_insn ""
4509   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4510         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4511                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
4512                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4513   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4514    && HONOR_SIGNED_ZEROS (SFmode)"
4515   "fnmadds %0,%1,%2,%3"
4516   [(set_attr "type" "fp")])
4517
4518 (define_insn ""
4519   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4520         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
4521                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4522                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4523   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4524    && ! HONOR_SIGNED_ZEROS (SFmode)"
4525   "fnmadds %0,%1,%2,%3"
4526   [(set_attr "type" "fp")])
4527
4528 (define_insn ""
4529   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4530         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4531                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
4532                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4533   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4534   "{fnma|fnmadd} %0,%1,%2,%3"
4535   [(set_attr "type" "dmul")])
4536
4537 (define_insn ""
4538   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4539         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
4540                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4541                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4542   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4543    && ! HONOR_SIGNED_ZEROS (SFmode)"
4544   "{fnma|fnmadd} %0,%1,%2,%3"
4545   [(set_attr "type" "dmul")])
4546
4547 (define_insn ""
4548   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4549         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4550                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
4551                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4552   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4553    && HONOR_SIGNED_ZEROS (SFmode)"
4554   "fnmsubs %0,%1,%2,%3"
4555   [(set_attr "type" "fp")])
4556
4557 (define_insn ""
4558   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4559         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
4560                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4561                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
4562   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4563    && ! HONOR_SIGNED_ZEROS (SFmode)"
4564   "fnmsubs %0,%1,%2,%3"
4565   [(set_attr "type" "fp")])
4566
4567 (define_insn ""
4568   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4569         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4570                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
4571                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4572   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4573   "{fnms|fnmsub} %0,%1,%2,%3"
4574   [(set_attr "type" "dmul")])
4575
4576 (define_insn ""
4577   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4578         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
4579                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4580                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
4581   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4582    && ! HONOR_SIGNED_ZEROS (SFmode)"
4583   "{fnms|fnmsub} %0,%1,%2,%3"
4584   [(set_attr "type" "fp")])
4585
4586 (define_expand "sqrtsf2"
4587   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4588         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4589   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
4590   "")
4591
4592 (define_insn ""
4593   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4594         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4595   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4596   "fsqrts %0,%1"
4597   [(set_attr "type" "ssqrt")])
4598
4599 (define_insn ""
4600   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4601         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4602   "TARGET_POWER2 && TARGET_HARD_FLOAT && TARGET_FPRS"
4603   "fsqrt %0,%1"
4604   [(set_attr "type" "dsqrt")])
4605
4606 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
4607 ;; fsel instruction and some auxiliary computations.  Then we just have a
4608 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
4609 ;; combine.
4610 (define_expand "maxsf3"
4611   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4612         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
4613                              (match_operand:SF 2 "gpc_reg_operand" ""))
4614                          (match_dup 1)
4615                          (match_dup 2)))]
4616   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4617   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
4618
4619 (define_expand "minsf3"
4620   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4621         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
4622                              (match_operand:SF 2 "gpc_reg_operand" ""))
4623                          (match_dup 2)
4624                          (match_dup 1)))]
4625   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4626   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
4627
4628 (define_split
4629   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4630         (match_operator:SF 3 "min_max_operator"
4631          [(match_operand:SF 1 "gpc_reg_operand" "")
4632           (match_operand:SF 2 "gpc_reg_operand" "")]))]
4633   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4634   [(const_int 0)]
4635   "
4636 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]), 
4637                       operands[1], operands[2]);
4638   DONE;
4639 }")
4640
4641 (define_expand "movsicc"
4642    [(set (match_operand:SI 0 "gpc_reg_operand" "")
4643          (if_then_else:SI (match_operand 1 "comparison_operator" "")
4644                           (match_operand:SI 2 "gpc_reg_operand" "")
4645                           (match_operand:SI 3 "gpc_reg_operand" "")))]
4646   "TARGET_ISEL"
4647   "
4648 {
4649   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4650     DONE;
4651   else
4652     FAIL;
4653 }")
4654
4655 ;; We use the BASE_REGS for the isel input operands because, if rA is
4656 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
4657 ;; because we may switch the operands and rB may end up being rA.
4658 ;;
4659 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
4660 ;; leave out the mode in operand 4 and use one pattern, but reload can
4661 ;; change the mode underneath our feet and then gets confused trying
4662 ;; to reload the value.
4663 (define_insn "isel_signed"
4664   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4665         (if_then_else:SI
4666          (match_operator 1 "comparison_operator"
4667                          [(match_operand:CC 4 "cc_reg_operand" "y")
4668                           (const_int 0)])
4669          (match_operand:SI 2 "gpc_reg_operand" "b")
4670          (match_operand:SI 3 "gpc_reg_operand" "b")))]
4671   "TARGET_ISEL"
4672   "*
4673 { return output_isel (operands); }"
4674   [(set_attr "length" "4")])
4675
4676 (define_insn "isel_unsigned"
4677   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4678         (if_then_else:SI
4679          (match_operator 1 "comparison_operator"
4680                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
4681                           (const_int 0)])
4682          (match_operand:SI 2 "gpc_reg_operand" "b")
4683          (match_operand:SI 3 "gpc_reg_operand" "b")))]
4684   "TARGET_ISEL"
4685   "*
4686 { return output_isel (operands); }"
4687   [(set_attr "length" "4")])
4688
4689 (define_expand "movsfcc"
4690    [(set (match_operand:SF 0 "gpc_reg_operand" "")
4691          (if_then_else:SF (match_operand 1 "comparison_operator" "")
4692                           (match_operand:SF 2 "gpc_reg_operand" "")
4693                           (match_operand:SF 3 "gpc_reg_operand" "")))]
4694   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4695   "
4696 {
4697   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4698     DONE;
4699   else
4700     FAIL;
4701 }")
4702
4703 (define_insn "*fselsfsf4"
4704   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4705         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
4706                              (match_operand:SF 4 "zero_fp_constant" "F"))
4707                          (match_operand:SF 2 "gpc_reg_operand" "f")
4708                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4709   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4710   "fsel %0,%1,%2,%3"
4711   [(set_attr "type" "fp")])
4712
4713 (define_insn "*fseldfsf4"
4714   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4715         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
4716                              (match_operand:DF 4 "zero_fp_constant" "F"))
4717                          (match_operand:SF 2 "gpc_reg_operand" "f")
4718                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4719   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4720   "fsel %0,%1,%2,%3"
4721   [(set_attr "type" "fp")])
4722
4723 (define_insn "negdf2"
4724   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4725         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4726   "TARGET_HARD_FLOAT && TARGET_FPRS"
4727   "fneg %0,%1"
4728   [(set_attr "type" "fp")])
4729
4730 (define_insn "absdf2"
4731   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4732         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4733   "TARGET_HARD_FLOAT && TARGET_FPRS"
4734   "fabs %0,%1"
4735   [(set_attr "type" "fp")])
4736
4737 (define_insn ""
4738   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4739         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f"))))]
4740   "TARGET_HARD_FLOAT && TARGET_FPRS"
4741   "fnabs %0,%1"
4742   [(set_attr "type" "fp")])
4743
4744 (define_insn "adddf3"
4745   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4746         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4747                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
4748   "TARGET_HARD_FLOAT && TARGET_FPRS"
4749   "{fa|fadd} %0,%1,%2"
4750   [(set_attr "type" "fp")])
4751
4752 (define_insn "subdf3"
4753   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4754         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "f")
4755                   (match_operand:DF 2 "gpc_reg_operand" "f")))]
4756   "TARGET_HARD_FLOAT && TARGET_FPRS"
4757   "{fs|fsub} %0,%1,%2"
4758   [(set_attr "type" "fp")])
4759
4760 (define_insn "muldf3"
4761   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4762         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4763                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
4764   "TARGET_HARD_FLOAT && TARGET_FPRS"
4765   "{fm|fmul} %0,%1,%2"
4766   [(set_attr "type" "dmul")])
4767
4768 (define_insn "divdf3"
4769   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4770         (div:DF (match_operand:DF 1 "gpc_reg_operand" "f")
4771                 (match_operand:DF 2 "gpc_reg_operand" "f")))]
4772   "TARGET_HARD_FLOAT && TARGET_FPRS"
4773   "{fd|fdiv} %0,%1,%2"
4774   [(set_attr "type" "ddiv")])
4775
4776 (define_insn ""
4777   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4778         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4779                           (match_operand:DF 2 "gpc_reg_operand" "f"))
4780                  (match_operand:DF 3 "gpc_reg_operand" "f")))]
4781   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4782   "{fma|fmadd} %0,%1,%2,%3"
4783   [(set_attr "type" "dmul")])
4784
4785 (define_insn ""
4786   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4787         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4788                            (match_operand:DF 2 "gpc_reg_operand" "f"))
4789                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
4790   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4791   "{fms|fmsub} %0,%1,%2,%3"
4792   [(set_attr "type" "dmul")])
4793
4794 (define_insn ""
4795   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4796         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4797                                   (match_operand:DF 2 "gpc_reg_operand" "f"))
4798                          (match_operand:DF 3 "gpc_reg_operand" "f"))))]
4799   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4800    && HONOR_SIGNED_ZEROS (DFmode)"
4801   "{fnma|fnmadd} %0,%1,%2,%3"
4802   [(set_attr "type" "dmul")])
4803
4804 (define_insn ""
4805   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4806         (minus:DF (mult:DF (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f"))
4807                            (match_operand:DF 2 "gpc_reg_operand" "f"))
4808                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
4809   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4810    && ! HONOR_SIGNED_ZEROS (DFmode)"
4811   "{fnma|fnmadd} %0,%1,%2,%3"
4812   [(set_attr "type" "dmul")])
4813
4814 (define_insn ""
4815   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4816         (neg:DF (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4817                                    (match_operand:DF 2 "gpc_reg_operand" "f"))
4818                           (match_operand:DF 3 "gpc_reg_operand" "f"))))]
4819   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4820    && HONOR_SIGNED_ZEROS (DFmode)"
4821   "{fnms|fnmsub} %0,%1,%2,%3"
4822   [(set_attr "type" "dmul")])
4823
4824 (define_insn ""
4825   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4826         (minus:DF (match_operand:DF 3 "gpc_reg_operand" "f")
4827                   (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4828                            (match_operand:DF 2 "gpc_reg_operand" "f"))))]
4829   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD 
4830    && ! HONOR_SIGNED_ZEROS (DFmode)"
4831   "{fnms|fnmsub} %0,%1,%2,%3"
4832   [(set_attr "type" "dmul")])
4833
4834 (define_insn "sqrtdf2"
4835   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4836         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4837   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
4838   "fsqrt %0,%1"
4839   [(set_attr "type" "dsqrt")])
4840
4841 ;; The conditional move instructions allow us to perform max and min
4842 ;; operations even when 
4843
4844 (define_expand "maxdf3"
4845   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4846         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
4847                              (match_operand:DF 2 "gpc_reg_operand" ""))
4848                          (match_dup 1)
4849                          (match_dup 2)))]
4850   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4851   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
4852
4853 (define_expand "mindf3"
4854   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4855         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
4856                              (match_operand:DF 2 "gpc_reg_operand" ""))
4857                          (match_dup 2)
4858                          (match_dup 1)))]
4859   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4860   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
4861
4862 (define_split
4863   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4864         (match_operator:DF 3 "min_max_operator"
4865          [(match_operand:DF 1 "gpc_reg_operand" "")
4866           (match_operand:DF 2 "gpc_reg_operand" "")]))]
4867   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4868   [(const_int 0)]
4869   "
4870 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]), 
4871                       operands[1], operands[2]);
4872   DONE;
4873 }")
4874
4875 (define_expand "movdfcc"
4876    [(set (match_operand:DF 0 "gpc_reg_operand" "")
4877          (if_then_else:DF (match_operand 1 "comparison_operator" "")
4878                           (match_operand:DF 2 "gpc_reg_operand" "")
4879                           (match_operand:DF 3 "gpc_reg_operand" "")))]
4880   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4881   "
4882 {
4883   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4884     DONE;
4885   else
4886     FAIL;
4887 }")
4888
4889 (define_insn "*fseldfdf4"
4890   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4891         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
4892                              (match_operand:DF 4 "zero_fp_constant" "F"))
4893                          (match_operand:DF 2 "gpc_reg_operand" "f")
4894                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
4895   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4896   "fsel %0,%1,%2,%3"
4897   [(set_attr "type" "fp")])
4898
4899 (define_insn "*fselsfdf4"
4900   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4901         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
4902                              (match_operand:SF 4 "zero_fp_constant" "F"))
4903                          (match_operand:DF 2 "gpc_reg_operand" "f")
4904                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
4905   "TARGET_PPC_GFXOPT"
4906   "fsel %0,%1,%2,%3"
4907   [(set_attr "type" "fp")])
4908 \f
4909 ;; Conversions to and from floating-point.
4910
4911 (define_expand "fixuns_truncsfsi2"
4912   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4913         (unsigned_fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
4914   "TARGET_HARD_FLOAT && !TARGET_FPRS"
4915   "")
4916
4917 (define_expand "fix_truncsfsi2"
4918   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4919         (fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
4920   "TARGET_HARD_FLOAT && !TARGET_FPRS"
4921   "")
4922
4923 ; For each of these conversions, there is a define_expand, a define_insn
4924 ; with a '#' template, and a define_split (with C code).  The idea is
4925 ; to allow constant folding with the template of the define_insn,
4926 ; then to have the insns split later (between sched1 and final).
4927
4928 (define_expand "floatsidf2"
4929   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
4930                    (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
4931               (use (match_dup 2))
4932               (use (match_dup 3))
4933               (clobber (match_dup 4))
4934               (clobber (match_dup 5))
4935               (clobber (match_dup 6))])]
4936   "TARGET_HARD_FLOAT && TARGET_FPRS"
4937   "
4938 {
4939   if (TARGET_POWERPC64)
4940     {
4941       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
4942       rtx t1 = gen_reg_rtx (DImode);
4943       rtx t2 = gen_reg_rtx (DImode);
4944       emit_insn (gen_floatsidf_ppc64 (operands[0], operands[1], mem, t1, t2));
4945       DONE;
4946     }
4947
4948   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
4949   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
4950   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
4951   operands[5] = gen_reg_rtx (DFmode);
4952   operands[6] = gen_reg_rtx (SImode);
4953 }")
4954
4955 (define_insn "*floatsidf2_internal"
4956   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
4957         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
4958    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
4959    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
4960    (clobber (match_operand:DF 4 "memory_operand" "=o"))
4961    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))
4962    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
4963   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
4964   "#"
4965   [(set_attr "length" "24")])
4966
4967 (define_split
4968   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4969         (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
4970    (use (match_operand:SI 2 "gpc_reg_operand" ""))
4971    (use (match_operand:DF 3 "gpc_reg_operand" ""))
4972    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
4973    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))
4974    (clobber (match_operand:SI 6 "gpc_reg_operand" ""))]
4975   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
4976   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4977         (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
4978    (use (match_operand:SI 2 "gpc_reg_operand" ""))
4979    (use (match_operand:DF 3 "gpc_reg_operand" ""))
4980    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
4981    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))
4982    (clobber (match_operand:SI 6 "gpc_reg_operand" ""))]
4983   "
4984 {
4985   rtx lowword, highword;
4986   if (GET_CODE (operands[4]) != MEM)
4987     abort();
4988   highword = XEXP (operands[4], 0);
4989   lowword = plus_constant (highword, 4);
4990   if (! WORDS_BIG_ENDIAN)
4991     {
4992       rtx tmp;
4993       tmp = highword; highword = lowword; lowword = tmp;
4994     }
4995
4996   emit_insn (gen_xorsi3 (operands[6], operands[1], 
4997                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
4998   emit_move_insn (gen_rtx_MEM (SImode, lowword), operands[6]);
4999   emit_move_insn (gen_rtx_MEM (SImode, highword), operands[2]);
5000   emit_move_insn (operands[5], operands[4]);
5001   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5002   DONE;
5003 }")
5004
5005 (define_expand "floatunssisf2"
5006   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5007         (unsigned_float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5008   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5009   "")
5010
5011 (define_expand "floatunssidf2"
5012   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5013                    (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5014               (use (match_dup 2))
5015               (use (match_dup 3))
5016               (clobber (match_dup 4))
5017               (clobber (match_dup 5))])]
5018   "TARGET_HARD_FLOAT && TARGET_FPRS"
5019   "
5020 {
5021   if (TARGET_POWERPC64)
5022     {
5023       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5024       rtx t1 = gen_reg_rtx (DImode);
5025       rtx t2 = gen_reg_rtx (DImode);
5026       emit_insn (gen_floatunssidf_ppc64 (operands[0], operands[1], mem,
5027                                          t1, t2));
5028       DONE;
5029     }
5030
5031   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5032   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
5033   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5034   operands[5] = gen_reg_rtx (DFmode);
5035 }")
5036
5037 (define_insn "*floatunssidf2_internal"
5038   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5039         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5040    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5041    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5042    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5043    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))]
5044   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5045   "#"
5046   [(set_attr "length" "20")])
5047
5048 (define_split
5049   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5050         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5051    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5052    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5053    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5054    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))]
5055   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5056   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5057         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5058    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5059    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5060    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5061    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))]
5062   "
5063 {
5064   rtx lowword, highword;
5065   if (GET_CODE (operands[4]) != MEM)
5066     abort();
5067   highword = XEXP (operands[4], 0);
5068   lowword = plus_constant (highword, 4);
5069   if (! WORDS_BIG_ENDIAN)
5070     {
5071       rtx tmp;
5072       tmp = highword; highword = lowword; lowword = tmp;
5073     }
5074
5075   emit_move_insn (gen_rtx_MEM (SImode, lowword), operands[1]);
5076   emit_move_insn (gen_rtx_MEM (SImode, highword), operands[2]);
5077   emit_move_insn (operands[5], operands[4]);
5078   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5079   DONE;
5080 }")
5081
5082 (define_expand "fix_truncdfsi2"
5083   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
5084                    (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5085               (clobber (match_dup 2))
5086               (clobber (match_dup 3))])]
5087   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5088   "
5089 {
5090   operands[2] = gen_reg_rtx (DImode);
5091   operands[3] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5092 }")
5093
5094 (define_insn "*fix_truncdfsi2_internal"
5095   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5096         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5097    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))
5098    (clobber (match_operand:DI 3 "memory_operand" "=o"))]
5099   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5100   "#"
5101   [(set_attr "length" "16")])
5102
5103 (define_split
5104   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5105         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5106    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
5107    (clobber (match_operand:DI 3 "offsettable_mem_operand" ""))]
5108   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5109   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5110         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5111    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
5112    (clobber (match_operand:DI 3 "offsettable_mem_operand" ""))]
5113   "
5114 {
5115   rtx lowword;
5116   if (GET_CODE (operands[3]) != MEM)
5117     abort();
5118   lowword = XEXP (operands[3], 0);
5119   if (WORDS_BIG_ENDIAN)
5120     lowword = plus_constant (lowword, 4);
5121
5122   emit_insn (gen_fctiwz (operands[2], operands[1]));
5123   emit_move_insn (operands[3], operands[2]);
5124   emit_move_insn (operands[0], gen_rtx_MEM (SImode, lowword));
5125   DONE;
5126 }")
5127
5128 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
5129 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
5130 ; because the first makes it clear that operand 0 is not live
5131 ; before the instruction.
5132 (define_insn "fctiwz"
5133   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
5134         (unspec:DI [(fix:SI (match_operand:DF 1 "gpc_reg_operand" "f"))]
5135                    UNSPEC_FCTIWZ))]
5136   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5137   "{fcirz|fctiwz} %0,%1"
5138   [(set_attr "type" "fp")])
5139
5140 (define_expand "floatsisf2"
5141   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5142         (float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5143   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5144   "")
5145
5146 (define_insn "floatdidf2"
5147   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5148         (float:DF (match_operand:DI 1 "gpc_reg_operand" "*f")))]
5149   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5150   "fcfid %0,%1"
5151   [(set_attr "type" "fp")])
5152
5153 (define_insn_and_split "floatsidf_ppc64"
5154   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5155         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5156    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5157    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5158    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5159   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5160   "#"
5161   "&& 1"
5162   [(set (match_dup 3) (sign_extend:DI (match_dup 1)))
5163    (set (match_dup 2) (match_dup 3))
5164    (set (match_dup 4) (match_dup 2))
5165    (set (match_dup 0) (float:DF (match_dup 4)))]
5166   "")
5167
5168 (define_insn_and_split "floatunssidf_ppc64"
5169   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5170         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5171    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5172    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5173    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5174   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5175   "#"
5176   "&& 1"
5177   [(set (match_dup 3) (zero_extend:DI (match_dup 1)))
5178    (set (match_dup 2) (match_dup 3))
5179    (set (match_dup 4) (match_dup 2))
5180    (set (match_dup 0) (float:DF (match_dup 4)))]
5181   "")
5182
5183 (define_insn "fix_truncdfdi2"
5184   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
5185         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "f")))]
5186   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5187   "fctidz %0,%1"
5188   [(set_attr "type" "fp")])
5189
5190 (define_expand "floatdisf2"
5191   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5192         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
5193   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5194   "
5195 {
5196   rtx val = operands[1];
5197   if (!flag_unsafe_math_optimizations)
5198     {
5199       rtx label = gen_label_rtx ();
5200       val = gen_reg_rtx (DImode);
5201       emit_insn (gen_floatdisf2_internal2 (val, operands[1], label));
5202       emit_label (label);
5203     }
5204   emit_insn (gen_floatdisf2_internal1 (operands[0], val));
5205   DONE;
5206 }")
5207
5208 ;; This is not IEEE compliant if rounding mode is "round to nearest".
5209 ;; If the DI->DF conversion is inexact, then it's possible to suffer
5210 ;; from double rounding.
5211 (define_insn_and_split "floatdisf2_internal1"
5212   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5213         (float:SF (match_operand:DI 1 "gpc_reg_operand" "*f")))
5214    (clobber (match_scratch:DF 2 "=f"))]
5215   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5216   "#"
5217   "&& reload_completed"
5218   [(set (match_dup 2)
5219         (float:DF (match_dup 1)))
5220    (set (match_dup 0)
5221         (float_truncate:SF (match_dup 2)))]
5222   "")
5223
5224 ;; Twiddles bits to avoid double rounding.
5225 ;; Bits that might be truncated when converting to DFmode are replaced
5226 ;; by a bit that won't be lost at that stage, but is below the SFmode
5227 ;; rounding position.
5228 (define_expand "floatdisf2_internal2"
5229   [(set (match_dup 3) (ashiftrt:DI (match_operand:DI 1 "" "")
5230                                    (const_int 53)))
5231    (parallel [(set (match_operand:DI 0 "" "") (and:DI (match_dup 1)
5232                                                       (const_int 2047)))
5233               (clobber (scratch:CC))])
5234    (set (match_dup 3) (plus:DI (match_dup 3)
5235                                (const_int 1)))
5236    (set (match_dup 0) (plus:DI (match_dup 0)
5237                                (const_int 2047)))
5238    (set (match_dup 4) (compare:CCUNS (match_dup 3)
5239                                      (const_int 3)))
5240    (set (match_dup 0) (ior:DI (match_dup 0)
5241                               (match_dup 1)))
5242    (parallel [(set (match_dup 0) (and:DI (match_dup 0)
5243                                          (const_int -2048)))
5244               (clobber (scratch:CC))])
5245    (set (pc) (if_then_else (geu (match_dup 4) (const_int 0))
5246                            (label_ref (match_operand:DI 2 "" ""))
5247                            (pc)))
5248    (set (match_dup 0) (match_dup 1))]
5249   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5250   "
5251 {
5252   operands[3] = gen_reg_rtx (DImode);
5253   operands[4] = gen_reg_rtx (CCUNSmode);
5254 }")
5255 \f
5256 ;; Define the DImode operations that can be done in a small number
5257 ;; of instructions.  The & constraints are to prevent the register
5258 ;; allocator from allocating registers that overlap with the inputs
5259 ;; (for example, having an input in 7,8 and an output in 6,7).  We
5260 ;; also allow for the output being the same as one of the inputs.
5261
5262 (define_insn "*adddi3_noppc64"
5263   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
5264         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
5265                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
5266   "! TARGET_POWERPC64"
5267   "*
5268 {
5269   if (WORDS_BIG_ENDIAN)
5270     return (GET_CODE (operands[2])) != CONST_INT
5271             ? \"{a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2\"
5272             : \"{ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1\";
5273   else
5274     return (GET_CODE (operands[2])) != CONST_INT
5275             ? \"{a|addc} %0,%1,%2\;{ae|adde} %L0,%L1,%L2\"
5276             : \"{ai|addic} %0,%1,%2\;{a%G2e|add%G2e} %L0,%L1\";
5277 }"
5278   [(set_attr "length" "8")])
5279
5280 (define_insn "*subdi3_noppc64"
5281   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
5282         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
5283                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
5284   "! TARGET_POWERPC64"
5285   "*
5286 {
5287   if (WORDS_BIG_ENDIAN)
5288     return (GET_CODE (operands[1]) != CONST_INT)
5289             ? \"{sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1\"
5290             : \"{sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2\";
5291   else
5292     return (GET_CODE (operands[1]) != CONST_INT)
5293             ? \"{sf|subfc} %0,%2,%1\;{sfe|subfe} %L0,%L2,%L1\"
5294             : \"{sfi|subfic} %0,%2,%1\;{sf%G1e|subf%G1e} %L0,%L2\";
5295 }"
5296   [(set_attr "length" "8")])
5297
5298 (define_insn "*negdi2_noppc64"
5299   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5300         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
5301   "! TARGET_POWERPC64"
5302   "*
5303 {
5304   return (WORDS_BIG_ENDIAN)
5305     ? \"{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1\"
5306     : \"{sfi|subfic} %0,%1,0\;{sfze|subfze} %L0,%L1\";
5307 }"
5308   [(set_attr "length" "8")])
5309
5310 (define_expand "mulsidi3"
5311   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5312         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5313                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5314   "! TARGET_POWERPC64"
5315   "
5316 {
5317   if (! TARGET_POWER && ! TARGET_POWERPC)
5318     {
5319       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
5320       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
5321       emit_insn (gen_mull_call ());
5322       if (WORDS_BIG_ENDIAN)
5323         emit_move_insn (operands[0], gen_rtx_REG (DImode, 3));
5324       else
5325         {
5326           emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
5327                           gen_rtx_REG (SImode, 3));
5328           emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
5329                           gen_rtx_REG (SImode, 4));
5330         }
5331       DONE;
5332     }
5333   else if (TARGET_POWER)
5334     {
5335       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
5336       DONE;
5337     }
5338 }")
5339
5340 (define_insn "mulsidi3_mq"
5341   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5342         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5343                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
5344    (clobber (match_scratch:SI 3 "=q"))]
5345   "TARGET_POWER"
5346   "mul %0,%1,%2\;mfmq %L0"
5347   [(set_attr "type" "imul")
5348    (set_attr "length" "8")])
5349
5350 (define_insn "*mulsidi3_no_mq"
5351   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5352         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5353                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
5354   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
5355   "*
5356 {
5357   return (WORDS_BIG_ENDIAN)
5358     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
5359     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
5360 }"
5361   [(set_attr "type" "imul")
5362    (set_attr "length" "8")])
5363
5364 (define_split
5365   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5366         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5367                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5368   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
5369   [(set (match_dup 3)
5370         (truncate:SI
5371          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
5372                                (sign_extend:DI (match_dup 2)))
5373                       (const_int 32))))
5374    (set (match_dup 4)
5375         (mult:SI (match_dup 1)
5376                  (match_dup 2)))]
5377   "
5378 {
5379   int endian = (WORDS_BIG_ENDIAN == 0);
5380   operands[3] = operand_subword (operands[0], endian, 0, DImode);
5381   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
5382 }")
5383
5384 (define_expand "umulsidi3"
5385   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5386         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5387                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5388   "TARGET_POWERPC && ! TARGET_POWERPC64"
5389   "
5390 {
5391   if (TARGET_POWER)
5392     {
5393       emit_insn (gen_umulsidi3_mq (operands[0], operands[1], operands[2]));
5394       DONE;
5395     }
5396 }")
5397
5398 (define_insn "umulsidi3_mq"
5399   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5400         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5401                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
5402    (clobber (match_scratch:SI 3 "=q"))]
5403   "TARGET_POWERPC && TARGET_POWER"
5404   "*
5405 {
5406   return (WORDS_BIG_ENDIAN)
5407     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
5408     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
5409 }"
5410   [(set_attr "type" "imul")
5411    (set_attr "length" "8")])
5412
5413 (define_insn "*umulsidi3_no_mq"
5414   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5415         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5416                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
5417   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
5418   "*
5419 {
5420   return (WORDS_BIG_ENDIAN)
5421     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
5422     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
5423 }"
5424   [(set_attr "type" "imul")
5425    (set_attr "length" "8")])
5426
5427 (define_split
5428   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5429         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5430                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5431   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
5432   [(set (match_dup 3)
5433         (truncate:SI
5434          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
5435                                (zero_extend:DI (match_dup 2)))
5436                       (const_int 32))))
5437    (set (match_dup 4)
5438         (mult:SI (match_dup 1)
5439                  (match_dup 2)))]
5440   "
5441 {
5442   int endian = (WORDS_BIG_ENDIAN == 0);
5443   operands[3] = operand_subword (operands[0], endian, 0, DImode);
5444   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
5445 }")
5446
5447 (define_expand "smulsi3_highpart"
5448   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5449         (truncate:SI
5450          (lshiftrt:DI (mult:DI (sign_extend:DI
5451                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5452                                (sign_extend:DI
5453                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5454                       (const_int 32))))]
5455   ""
5456   "
5457 {
5458   if (! TARGET_POWER && ! TARGET_POWERPC)
5459     {
5460       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
5461       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
5462       emit_insn (gen_mulh_call ());
5463       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
5464       DONE;
5465     }
5466   else if (TARGET_POWER)
5467     {
5468       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
5469       DONE;
5470     }
5471 }")
5472
5473 (define_insn "smulsi3_highpart_mq"
5474   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5475         (truncate:SI
5476          (lshiftrt:DI (mult:DI (sign_extend:DI
5477                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5478                                (sign_extend:DI
5479                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5480                       (const_int 32))))
5481    (clobber (match_scratch:SI 3 "=q"))]
5482   "TARGET_POWER"
5483   "mul %0,%1,%2"
5484   [(set_attr "type" "imul")])
5485
5486 (define_insn "*smulsi3_highpart_no_mq"
5487   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5488         (truncate:SI
5489          (lshiftrt:DI (mult:DI (sign_extend:DI
5490                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5491                                (sign_extend:DI
5492                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5493                       (const_int 32))))]
5494   "TARGET_POWERPC && ! TARGET_POWER"
5495   "mulhw %0,%1,%2"
5496   [(set_attr "type" "imul")])
5497
5498 (define_expand "umulsi3_highpart"
5499   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5500         (truncate:SI
5501          (lshiftrt:DI (mult:DI (zero_extend:DI
5502                                 (match_operand:SI 1 "gpc_reg_operand" ""))
5503                                (zero_extend:DI
5504                                 (match_operand:SI 2 "gpc_reg_operand" "")))
5505                       (const_int 32))))]
5506   "TARGET_POWERPC"
5507   "
5508 {
5509   if (TARGET_POWER)
5510     {
5511       emit_insn (gen_umulsi3_highpart_mq (operands[0], operands[1], operands[2]));
5512       DONE;
5513     }
5514 }")
5515
5516 (define_insn "umulsi3_highpart_mq"
5517   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5518         (truncate:SI
5519          (lshiftrt:DI (mult:DI (zero_extend:DI
5520                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5521                                (zero_extend:DI
5522                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5523                       (const_int 32))))
5524    (clobber (match_scratch:SI 3 "=q"))]
5525   "TARGET_POWERPC && TARGET_POWER"
5526   "mulhwu %0,%1,%2"
5527   [(set_attr "type" "imul")])
5528
5529 (define_insn "*umulsi3_highpart_no_mq"
5530   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5531         (truncate:SI
5532          (lshiftrt:DI (mult:DI (zero_extend:DI
5533                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5534                                (zero_extend:DI
5535                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5536                       (const_int 32))))]
5537   "TARGET_POWERPC && ! TARGET_POWER"
5538   "mulhwu %0,%1,%2"
5539   [(set_attr "type" "imul")])
5540
5541 ;; If operands 0 and 2 are in the same register, we have a problem.  But
5542 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
5543 ;; why we have the strange constraints below.
5544 (define_insn "ashldi3_power"
5545   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
5546         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
5547                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
5548    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
5549   "TARGET_POWER"
5550   "@
5551    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
5552    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
5553    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
5554    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
5555   [(set_attr "length" "8")])
5556
5557 (define_insn "lshrdi3_power"
5558   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
5559         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
5560                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
5561    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
5562   "TARGET_POWER"
5563   "@
5564    {s%A2i|s%A2wi} %L0,%1,%h2\;{cal %0,0(0)|li %0,0}
5565    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
5566    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
5567    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
5568   [(set_attr "length" "8")])
5569
5570 ;; Shift by a variable amount is too complex to be worth open-coding.  We
5571 ;; just handle shifts by constants.
5572 (define_insn "ashrdi3_power"
5573   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5574         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5575                      (match_operand:SI 2 "const_int_operand" "M,i")))
5576    (clobber (match_scratch:SI 3 "=X,q"))]
5577   "TARGET_POWER"
5578   "@
5579    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
5580    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
5581   [(set_attr "length" "8")])
5582
5583 (define_insn "ashrdi3_no_power"
5584   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
5585         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5586                      (match_operand:SI 2 "const_int_operand" "M,i")))]
5587   "TARGET_32BIT && !TARGET_POWERPC64 && !TARGET_POWER && WORDS_BIG_ENDIAN"
5588   "@
5589    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
5590    {sri|srwi} %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;{srai|srawi} %0,%1,%h2"
5591   [(set_attr "length" "8,12")])
5592
5593 (define_insn "*ashrdisi3_noppc64"
5594   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5595         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")    
5596                                 (const_int 32)) 4))]
5597   "TARGET_32BIT && !TARGET_POWERPC64"
5598   "*
5599 {
5600   if (REGNO (operands[0]) == REGNO (operands[1]))
5601     return \"\";
5602   else
5603     return \"mr %0,%1\";
5604 }"
5605    [(set_attr "length" "4")])      
5606
5607 \f
5608 ;; PowerPC64 DImode operations.
5609
5610 (define_expand "adddi3"
5611   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5612         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5613                  (match_operand:DI 2 "reg_or_add_cint64_operand" "")))]
5614   ""
5615   "
5616 {
5617   if (! TARGET_POWERPC64)
5618     {
5619       if (non_short_cint_operand (operands[2], DImode))
5620         FAIL;
5621     }
5622   else
5623     if (GET_CODE (operands[2]) == CONST_INT
5624         && ! add_operand (operands[2], DImode))
5625       {
5626         rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
5627                    ? operands[0] : gen_reg_rtx (DImode));
5628
5629         HOST_WIDE_INT val = INTVAL (operands[2]);
5630         HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
5631         HOST_WIDE_INT rest = trunc_int_for_mode (val - low, DImode);
5632
5633         if (!CONST_OK_FOR_LETTER_P (rest, 'L'))
5634           FAIL;
5635
5636         /* The ordering here is important for the prolog expander.
5637            When space is allocated from the stack, adding 'low' first may
5638            produce a temporary deallocation (which would be bad).  */
5639         emit_insn (gen_adddi3 (tmp, operands[1], GEN_INT (rest)));
5640         emit_insn (gen_adddi3 (operands[0], tmp, GEN_INT (low)));
5641         DONE;
5642       }
5643 }")
5644
5645 ;; Discourage ai/addic because of carry but provide it in an alternative
5646 ;; allowing register zero as source.
5647
5648 (define_insn "*adddi3_internal1"
5649   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,?r,r")
5650         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,b,r,b")
5651                  (match_operand:DI 2 "add_operand" "r,I,I,L")))]
5652   "TARGET_POWERPC64"
5653   "@
5654    add %0,%1,%2
5655    addi %0,%1,%2
5656    addic %0,%1,%2
5657    addis %0,%1,%v2")
5658
5659 (define_insn "*adddi3_internal2"
5660   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
5661         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
5662                              (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I"))
5663                     (const_int 0)))
5664    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
5665   "TARGET_64BIT"
5666   "@
5667    add. %3,%1,%2
5668    addic. %3,%1,%2
5669    #
5670    #"
5671   [(set_attr "type" "fast_compare,compare,compare,compare")
5672    (set_attr "length" "4,4,8,8")])
5673
5674 (define_split
5675   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5676         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5677                              (match_operand:DI 2 "reg_or_short_operand" ""))
5678                     (const_int 0)))
5679    (clobber (match_scratch:DI 3 ""))]
5680   "TARGET_POWERPC64 && reload_completed"
5681   [(set (match_dup 3)
5682         (plus:DI (match_dup 1) (match_dup 2)))
5683    (set (match_dup 0)
5684         (compare:CC (match_dup 3)
5685                     (const_int 0)))]
5686   "")
5687
5688 (define_insn "*adddi3_internal3"
5689   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
5690         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
5691                              (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I"))
5692                     (const_int 0)))
5693    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
5694         (plus:DI (match_dup 1) (match_dup 2)))]
5695   "TARGET_64BIT"
5696   "@
5697    add. %0,%1,%2
5698    addic. %0,%1,%2
5699    #
5700    #"
5701   [(set_attr "type" "fast_compare,compare,compare,compare")
5702    (set_attr "length" "4,4,8,8")])
5703
5704 (define_split
5705   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5706         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5707                              (match_operand:DI 2 "reg_or_short_operand" ""))
5708                     (const_int 0)))
5709    (set (match_operand:DI 0 "gpc_reg_operand" "")
5710         (plus:DI (match_dup 1) (match_dup 2)))]
5711   "TARGET_POWERPC64 && reload_completed"
5712   [(set (match_dup 0)
5713         (plus:DI (match_dup 1) (match_dup 2)))
5714    (set (match_dup 3)
5715         (compare:CC (match_dup 0)
5716                     (const_int 0)))]
5717   "")
5718
5719 ;; Split an add that we can't do in one insn into two insns, each of which
5720 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
5721 ;; add should be last in case the result gets used in an address.
5722
5723 (define_split
5724   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5725         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5726                  (match_operand:DI 2 "non_add_cint_operand" "")))]
5727   "TARGET_POWERPC64"
5728   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 3)))
5729    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 4)))]
5730 "
5731 {
5732   HOST_WIDE_INT val = INTVAL (operands[2]);
5733   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
5734   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, DImode);
5735
5736   operands[4] = GEN_INT (low);
5737   if (CONST_OK_FOR_LETTER_P (rest, 'L'))
5738     operands[3] = GEN_INT (rest);
5739   else if (! no_new_pseudos)
5740     {
5741       operands[3] = gen_reg_rtx (DImode);
5742       emit_move_insn (operands[3], operands[2]);
5743       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
5744       DONE;
5745     }
5746   else
5747     FAIL;
5748 }")
5749
5750 (define_insn "one_cmpldi2"
5751   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5752         (not:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
5753   "TARGET_POWERPC64"
5754   "nor %0,%1,%1")
5755
5756 (define_insn ""
5757   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5758         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
5759                     (const_int 0)))
5760    (clobber (match_scratch:DI 2 "=r,r"))]
5761   "TARGET_64BIT"
5762   "@
5763    nor. %2,%1,%1
5764    #"
5765   [(set_attr "type" "compare")
5766    (set_attr "length" "4,8")])
5767
5768 (define_split
5769   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5770         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
5771                     (const_int 0)))
5772    (clobber (match_scratch:DI 2 ""))]
5773   "TARGET_POWERPC64 && reload_completed"
5774   [(set (match_dup 2)
5775         (not:DI (match_dup 1)))
5776    (set (match_dup 0)
5777         (compare:CC (match_dup 2)
5778                     (const_int 0)))]
5779   "")
5780
5781 (define_insn ""
5782   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
5783         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
5784                     (const_int 0)))
5785    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5786         (not:DI (match_dup 1)))]
5787   "TARGET_64BIT"
5788   "@
5789    nor. %0,%1,%1
5790    #"
5791   [(set_attr "type" "compare")
5792    (set_attr "length" "4,8")])
5793
5794 (define_split
5795   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
5796         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
5797                     (const_int 0)))
5798    (set (match_operand:DI 0 "gpc_reg_operand" "")
5799         (not:DI (match_dup 1)))]
5800   "TARGET_POWERPC64 && reload_completed"
5801   [(set (match_dup 0)
5802         (not:DI (match_dup 1)))
5803    (set (match_dup 2)
5804         (compare:CC (match_dup 0)
5805                     (const_int 0)))]
5806   "")
5807
5808 (define_insn ""
5809   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5810         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I")
5811                   (match_operand:DI 2 "gpc_reg_operand" "r,r")))]
5812   "TARGET_POWERPC64"
5813   "@
5814    subf %0,%2,%1
5815    subfic %0,%2,%1")
5816
5817 (define_insn ""
5818   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5819         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5820                               (match_operand:DI 2 "gpc_reg_operand" "r,r"))
5821                     (const_int 0)))
5822    (clobber (match_scratch:DI 3 "=r,r"))]
5823   "TARGET_64BIT"
5824   "@
5825    subf. %3,%2,%1
5826    #"
5827   [(set_attr "type" "fast_compare")
5828    (set_attr "length" "4,8")])
5829
5830 (define_split
5831   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5832         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5833                               (match_operand:DI 2 "gpc_reg_operand" ""))
5834                     (const_int 0)))
5835    (clobber (match_scratch:DI 3 ""))]
5836   "TARGET_POWERPC64 && reload_completed"
5837   [(set (match_dup 3)
5838         (minus:DI (match_dup 1) (match_dup 2)))
5839    (set (match_dup 0)
5840         (compare:CC (match_dup 3)
5841                     (const_int 0)))]
5842   "")
5843
5844 (define_insn ""
5845   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
5846         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5847                               (match_operand:DI 2 "gpc_reg_operand" "r,r"))
5848                     (const_int 0)))
5849    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5850         (minus:DI (match_dup 1) (match_dup 2)))]
5851   "TARGET_64BIT"
5852   "@
5853    subf. %0,%2,%1
5854    #"
5855   [(set_attr "type" "fast_compare")
5856    (set_attr "length" "4,8")])
5857
5858 (define_split
5859   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5860         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5861                               (match_operand:DI 2 "gpc_reg_operand" ""))
5862                     (const_int 0)))
5863    (set (match_operand:DI 0 "gpc_reg_operand" "")
5864         (minus:DI (match_dup 1) (match_dup 2)))]
5865   "TARGET_POWERPC64 && reload_completed"
5866   [(set (match_dup 0)
5867         (minus:DI (match_dup 1) (match_dup 2)))
5868    (set (match_dup 3)
5869         (compare:CC (match_dup 0)
5870                     (const_int 0)))]
5871   "")
5872
5873 (define_expand "subdi3"
5874   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5875         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "")
5876                   (match_operand:DI 2 "reg_or_sub_cint64_operand" "")))]
5877   ""
5878   "
5879 {
5880   if (GET_CODE (operands[2]) == CONST_INT)
5881     {
5882       emit_insn (gen_adddi3 (operands[0], operands[1],
5883                              negate_rtx (DImode, operands[2])));
5884       DONE;
5885     }
5886 }")
5887
5888 (define_insn_and_split "absdi2"
5889   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5890         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
5891    (clobber (match_scratch:DI 2 "=&r,&r"))]
5892   "TARGET_POWERPC64"
5893   "#"
5894   "&& reload_completed"
5895   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
5896    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
5897    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
5898   "")
5899
5900 (define_insn_and_split "*nabsdi2"
5901   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5902         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
5903    (clobber (match_scratch:DI 2 "=&r,&r"))]
5904   "TARGET_POWERPC64"
5905   "#"
5906   "&& reload_completed"
5907   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
5908    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
5909    (set (match_dup 0) (minus:DI (match_dup 2) (match_dup 0)))]
5910   "")
5911
5912 (define_expand "negdi2"
5913   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5914         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "")))]
5915   ""
5916   "")
5917
5918 (define_insn ""
5919   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5920         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
5921   "TARGET_POWERPC64"
5922   "neg %0,%1")
5923
5924 (define_insn ""
5925   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5926         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
5927                     (const_int 0)))
5928    (clobber (match_scratch:DI 2 "=r,r"))]
5929   "TARGET_64BIT"
5930   "@
5931    neg. %2,%1
5932    #"
5933   [(set_attr "type" "fast_compare")
5934    (set_attr "length" "4,8")])
5935
5936 (define_split
5937   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5938         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" ""))
5939                     (const_int 0)))
5940    (clobber (match_scratch:DI 2 ""))]
5941   "TARGET_POWERPC64 && reload_completed"
5942   [(set (match_dup 2)
5943         (neg:DI (match_dup 1)))
5944    (set (match_dup 0)
5945         (compare:CC (match_dup 2)
5946                     (const_int 0)))]
5947   "")
5948
5949 (define_insn ""
5950   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
5951         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
5952                     (const_int 0)))
5953    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5954         (neg:DI (match_dup 1)))]
5955   "TARGET_64BIT"
5956   "@
5957    neg. %0,%1
5958    #"
5959   [(set_attr "type" "fast_compare")
5960    (set_attr "length" "4,8")])
5961
5962 (define_split
5963   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
5964         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" ""))
5965                     (const_int 0)))
5966    (set (match_operand:DI 0 "gpc_reg_operand" "")
5967         (neg:DI (match_dup 1)))]
5968   "TARGET_POWERPC64 && reload_completed"
5969   [(set (match_dup 0)
5970         (neg:DI (match_dup 1)))
5971    (set (match_dup 2)
5972         (compare:CC (match_dup 0)
5973                     (const_int 0)))]
5974   "")
5975
5976 (define_insn "clzdi2"
5977   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5978         (clz:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
5979   "TARGET_POWERPC64"
5980   "cntlzd %0,%1")
5981
5982 (define_expand "ctzdi2"
5983   [(set (match_dup 2)
5984         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
5985    (parallel [(set (match_dup 3) (and:DI (match_dup 1)      
5986                                          (match_dup 2)))   
5987               (clobber (scratch:CC))])
5988    (set (match_dup 4) (clz:DI (match_dup 3)))
5989    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
5990         (minus:DI (const_int 63) (match_dup 4)))]
5991   "TARGET_POWERPC64"
5992   {
5993      operands[2] = gen_reg_rtx (DImode); 
5994      operands[3] = gen_reg_rtx (DImode);
5995      operands[4] = gen_reg_rtx (DImode);
5996   })
5997
5998 (define_expand "ffsdi2"
5999   [(set (match_dup 2)
6000         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
6001    (parallel [(set (match_dup 3) (and:DI (match_dup 1)      
6002                                          (match_dup 2)))   
6003               (clobber (scratch:CC))])
6004    (set (match_dup 4) (clz:DI (match_dup 3)))
6005    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
6006         (minus:DI (const_int 64) (match_dup 4)))]
6007   "TARGET_POWERPC64"
6008   {
6009      operands[2] = gen_reg_rtx (DImode); 
6010      operands[3] = gen_reg_rtx (DImode);
6011      operands[4] = gen_reg_rtx (DImode);
6012   })
6013
6014 (define_insn "muldi3"
6015   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6016         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
6017                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
6018   "TARGET_POWERPC64"
6019   "mulld %0,%1,%2"
6020    [(set_attr "type" "lmul")])
6021
6022 (define_insn "*muldi3_internal1"
6023   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6024         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6025                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6026                     (const_int 0)))
6027    (clobber (match_scratch:DI 3 "=r,r"))]
6028   "TARGET_POWERPC64"
6029   "@
6030    mulld. %3,%1,%2
6031    #"
6032   [(set_attr "type" "lmul_compare")
6033    (set_attr "length" "4,8")])
6034
6035 (define_split
6036   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6037         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6038                              (match_operand:DI 2 "gpc_reg_operand" ""))
6039                     (const_int 0)))
6040    (clobber (match_scratch:DI 3 ""))]
6041   "TARGET_POWERPC64 && reload_completed"
6042   [(set (match_dup 3)
6043         (mult:DI (match_dup 1) (match_dup 2)))
6044    (set (match_dup 0)
6045         (compare:CC (match_dup 3)
6046                     (const_int 0)))]
6047   "")
6048
6049 (define_insn "*muldi3_internal2"
6050   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6051         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6052                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6053                     (const_int 0)))
6054    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6055         (mult:DI (match_dup 1) (match_dup 2)))]
6056   "TARGET_POWERPC64"
6057   "@
6058    mulld. %0,%1,%2
6059    #"
6060   [(set_attr "type" "lmul_compare")
6061    (set_attr "length" "4,8")])
6062
6063 (define_split
6064   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6065         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6066                              (match_operand:DI 2 "gpc_reg_operand" ""))
6067                     (const_int 0)))
6068    (set (match_operand:DI 0 "gpc_reg_operand" "")
6069         (mult:DI (match_dup 1) (match_dup 2)))]
6070   "TARGET_POWERPC64 && reload_completed"
6071   [(set (match_dup 0)
6072         (mult:DI (match_dup 1) (match_dup 2)))
6073    (set (match_dup 3)
6074         (compare:CC (match_dup 0)
6075                     (const_int 0)))]
6076   "")
6077
6078 (define_insn "smuldi3_highpart"
6079   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6080         (truncate:DI
6081          (lshiftrt:TI (mult:TI (sign_extend:TI
6082                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6083                                (sign_extend:TI
6084                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6085                       (const_int 64))))]
6086   "TARGET_POWERPC64"
6087   "mulhd %0,%1,%2"
6088   [(set_attr "type" "lmul")])
6089
6090 (define_insn "umuldi3_highpart"
6091   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6092         (truncate:DI
6093          (lshiftrt:TI (mult:TI (zero_extend:TI
6094                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6095                                (zero_extend:TI
6096                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6097                       (const_int 64))))]
6098   "TARGET_POWERPC64"
6099   "mulhdu %0,%1,%2"
6100   [(set_attr "type" "lmul")])
6101
6102 (define_expand "divdi3"
6103   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6104         (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6105                 (match_operand:DI 2 "reg_or_cint_operand" "")))]
6106   "TARGET_POWERPC64"
6107   "
6108 {
6109   if (GET_CODE (operands[2]) == CONST_INT
6110       && INTVAL (operands[2]) > 0
6111       && exact_log2 (INTVAL (operands[2])) >= 0)
6112     ;
6113   else
6114     operands[2] = force_reg (DImode, operands[2]);
6115 }")
6116
6117 (define_expand "moddi3"
6118   [(use (match_operand:DI 0 "gpc_reg_operand" ""))
6119    (use (match_operand:DI 1 "gpc_reg_operand" ""))
6120    (use (match_operand:DI 2 "reg_or_cint_operand" ""))]
6121   "TARGET_POWERPC64"
6122   "
6123 {
6124   int i;
6125   rtx temp1;
6126   rtx temp2;
6127
6128   if (GET_CODE (operands[2]) != CONST_INT
6129       || INTVAL (operands[2]) <= 0
6130       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
6131     FAIL;
6132
6133   temp1 = gen_reg_rtx (DImode);
6134   temp2 = gen_reg_rtx (DImode);
6135
6136   emit_insn (gen_divdi3 (temp1, operands[1], operands[2]));
6137   emit_insn (gen_ashldi3 (temp2, temp1, GEN_INT (i)));
6138   emit_insn (gen_subdi3 (operands[0], operands[1], temp2));
6139   DONE;
6140 }")
6141
6142 (define_insn ""
6143   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6144         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6145                 (match_operand:DI 2 "exact_log2_cint_operand" "N")))]
6146   "TARGET_POWERPC64"
6147   "sradi %0,%1,%p2\;addze %0,%0"
6148   [(set_attr "length" "8")])
6149
6150 (define_insn ""
6151   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6152         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6153                             (match_operand:DI 2 "exact_log2_cint_operand" "N,N"))
6154                     (const_int 0)))
6155    (clobber (match_scratch:DI 3 "=r,r"))]
6156   "TARGET_64BIT"
6157   "@
6158    sradi %3,%1,%p2\;addze. %3,%3
6159    #"
6160   [(set_attr "type" "compare")
6161    (set_attr "length" "8,12")])
6162
6163 (define_split
6164   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6165         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6166                             (match_operand:DI 2 "exact_log2_cint_operand" ""))
6167                     (const_int 0)))
6168    (clobber (match_scratch:DI 3 ""))]
6169   "TARGET_POWERPC64 && reload_completed"
6170   [(set (match_dup 3)
6171         (div:DI (match_dup 1) (match_dup 2)))
6172    (set (match_dup 0)
6173         (compare:CC (match_dup 3)
6174                     (const_int 0)))]
6175   "")
6176
6177 (define_insn ""
6178   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6179         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6180                             (match_operand:DI 2 "exact_log2_cint_operand" "N,N"))
6181                     (const_int 0)))
6182    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6183         (div:DI (match_dup 1) (match_dup 2)))]
6184   "TARGET_64BIT"
6185   "@
6186    sradi %0,%1,%p2\;addze. %0,%0
6187    #"
6188   [(set_attr "type" "compare")
6189    (set_attr "length" "8,12")])
6190
6191 (define_split
6192   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6193         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6194                             (match_operand:DI 2 "exact_log2_cint_operand" ""))
6195                     (const_int 0)))
6196    (set (match_operand:DI 0 "gpc_reg_operand" "")
6197         (div:DI (match_dup 1) (match_dup 2)))]
6198   "TARGET_POWERPC64 && reload_completed"
6199   [(set (match_dup 0)
6200         (div:DI (match_dup 1) (match_dup 2)))
6201    (set (match_dup 3)
6202         (compare:CC (match_dup 0)
6203                     (const_int 0)))]
6204   "")
6205
6206 (define_insn ""
6207   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6208         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6209                 (match_operand:DI 2 "gpc_reg_operand" "r")))]
6210   "TARGET_POWERPC64"
6211   "divd %0,%1,%2"
6212   [(set_attr "type" "ldiv")])
6213
6214 (define_insn "udivdi3"
6215   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6216         (udiv:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6217                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
6218   "TARGET_POWERPC64"
6219   "divdu %0,%1,%2"
6220   [(set_attr "type" "ldiv")])
6221
6222 (define_insn "rotldi3"
6223   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6224         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6225                    (match_operand:DI 2 "reg_or_cint_operand" "ri")))]
6226   "TARGET_POWERPC64"
6227   "rld%I2cl %0,%1,%H2,0")
6228
6229 (define_insn "*rotldi3_internal2"
6230   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6231         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6232                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6233                     (const_int 0)))
6234    (clobber (match_scratch:DI 3 "=r,r"))]
6235   "TARGET_64BIT"
6236   "@
6237    rld%I2cl. %3,%1,%H2,0
6238    #"
6239   [(set_attr "type" "delayed_compare")
6240    (set_attr "length" "4,8")])
6241
6242 (define_split
6243   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6244         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6245                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6246                     (const_int 0)))
6247    (clobber (match_scratch:DI 3 ""))]
6248   "TARGET_POWERPC64 && reload_completed"
6249   [(set (match_dup 3)
6250         (rotate:DI (match_dup 1) (match_dup 2)))
6251    (set (match_dup 0)
6252         (compare:CC (match_dup 3)
6253                     (const_int 0)))]
6254   "")
6255
6256 (define_insn "*rotldi3_internal3"
6257   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6258         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6259                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6260                     (const_int 0)))
6261    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6262         (rotate:DI (match_dup 1) (match_dup 2)))]
6263   "TARGET_64BIT"
6264   "@
6265    rld%I2cl. %0,%1,%H2,0
6266    #"
6267   [(set_attr "type" "delayed_compare")
6268    (set_attr "length" "4,8")])
6269
6270 (define_split
6271   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6272         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6273                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6274                     (const_int 0)))
6275    (set (match_operand:DI 0 "gpc_reg_operand" "")
6276         (rotate:DI (match_dup 1) (match_dup 2)))]
6277   "TARGET_POWERPC64 && reload_completed"
6278   [(set (match_dup 0)
6279         (rotate:DI (match_dup 1) (match_dup 2)))
6280    (set (match_dup 3)
6281         (compare:CC (match_dup 0)
6282                     (const_int 0)))]
6283   "")
6284
6285 (define_insn "*rotldi3_internal4"
6286   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6287         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6288                            (match_operand:DI 2 "reg_or_cint_operand" "ri"))
6289                 (match_operand:DI 3 "mask64_operand" "n")))]
6290   "TARGET_POWERPC64"
6291   "rld%I2c%B3 %0,%1,%H2,%S3")
6292
6293 (define_insn "*rotldi3_internal5"
6294   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6295         (compare:CC (and:DI
6296                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6297                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6298                      (match_operand:DI 3 "mask64_operand" "n,n"))
6299                     (const_int 0)))
6300    (clobber (match_scratch:DI 4 "=r,r"))]
6301   "TARGET_64BIT"
6302   "@
6303    rld%I2c%B3. %4,%1,%H2,%S3
6304    #"
6305   [(set_attr "type" "delayed_compare")
6306    (set_attr "length" "4,8")])
6307
6308 (define_split
6309   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6310         (compare:CC (and:DI
6311                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6312                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6313                      (match_operand:DI 3 "mask64_operand" ""))
6314                     (const_int 0)))
6315    (clobber (match_scratch:DI 4 ""))]
6316   "TARGET_POWERPC64 && reload_completed"
6317   [(set (match_dup 4)
6318         (and:DI (rotate:DI (match_dup 1)
6319                                 (match_dup 2))
6320                      (match_dup 3)))
6321    (set (match_dup 0)
6322         (compare:CC (match_dup 4)
6323                     (const_int 0)))]
6324   "")
6325
6326 (define_insn "*rotldi3_internal6"
6327   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6328         (compare:CC (and:DI
6329                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6330                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6331                      (match_operand:DI 3 "mask64_operand" "n,n"))
6332                     (const_int 0)))
6333    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6334         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6335   "TARGET_64BIT"
6336   "@
6337    rld%I2c%B3. %0,%1,%H2,%S3
6338    #"
6339   [(set_attr "type" "delayed_compare")
6340    (set_attr "length" "4,8")])
6341
6342 (define_split
6343   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6344         (compare:CC (and:DI
6345                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6346                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6347                      (match_operand:DI 3 "mask64_operand" ""))
6348                     (const_int 0)))
6349    (set (match_operand:DI 0 "gpc_reg_operand" "")
6350         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6351   "TARGET_POWERPC64 && reload_completed"
6352   [(set (match_dup 0)
6353         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
6354    (set (match_dup 4)
6355         (compare:CC (match_dup 0)
6356                     (const_int 0)))]
6357   "")
6358
6359 (define_insn "*rotldi3_internal7"
6360   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6361         (zero_extend:DI
6362          (subreg:QI
6363           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6364                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6365   "TARGET_POWERPC64"
6366   "rld%I2cl %0,%1,%H2,56")
6367
6368 (define_insn "*rotldi3_internal8"
6369   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6370         (compare:CC (zero_extend:DI
6371                      (subreg:QI
6372                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6373                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6374                     (const_int 0)))
6375    (clobber (match_scratch:DI 3 "=r,r"))]
6376   "TARGET_64BIT"
6377   "@
6378    rld%I2cl. %3,%1,%H2,56
6379    #"
6380   [(set_attr "type" "delayed_compare")
6381    (set_attr "length" "4,8")])
6382
6383 (define_split
6384   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6385         (compare:CC (zero_extend:DI
6386                      (subreg:QI
6387                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6388                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6389                     (const_int 0)))
6390    (clobber (match_scratch:DI 3 ""))]
6391   "TARGET_POWERPC64 && reload_completed"
6392   [(set (match_dup 3)
6393         (zero_extend:DI (subreg:QI
6394                       (rotate:DI (match_dup 1)
6395                                  (match_dup 2)) 0)))
6396    (set (match_dup 0)
6397         (compare:CC (match_dup 3)
6398                     (const_int 0)))]
6399   "")
6400
6401 (define_insn "*rotldi3_internal9"
6402   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6403         (compare:CC (zero_extend:DI
6404                      (subreg:QI
6405                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6406                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6407                     (const_int 0)))
6408    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6409         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6410   "TARGET_64BIT"
6411   "@
6412    rld%I2cl. %0,%1,%H2,56
6413    #"
6414   [(set_attr "type" "delayed_compare")
6415    (set_attr "length" "4,8")])
6416
6417 (define_split
6418   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6419         (compare:CC (zero_extend:DI
6420                      (subreg:QI
6421                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6422                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6423                     (const_int 0)))
6424    (set (match_operand:DI 0 "gpc_reg_operand" "")
6425         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6426   "TARGET_POWERPC64 && reload_completed"
6427   [(set (match_dup 0)
6428         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6429    (set (match_dup 3)
6430         (compare:CC (match_dup 0)
6431                     (const_int 0)))]
6432   "")
6433
6434 (define_insn "*rotldi3_internal10"
6435   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6436         (zero_extend:DI
6437          (subreg:HI
6438           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6439                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6440   "TARGET_POWERPC64"
6441   "rld%I2cl %0,%1,%H2,48")
6442
6443 (define_insn "*rotldi3_internal11"
6444   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6445         (compare:CC (zero_extend:DI
6446                      (subreg:HI
6447                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6448                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6449                     (const_int 0)))
6450    (clobber (match_scratch:DI 3 "=r,r"))]
6451   "TARGET_64BIT"
6452   "@
6453    rld%I2cl. %3,%1,%H2,48
6454    #"
6455   [(set_attr "type" "delayed_compare")
6456    (set_attr "length" "4,8")])
6457
6458 (define_split
6459   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6460         (compare:CC (zero_extend:DI
6461                      (subreg:HI
6462                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6463                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6464                     (const_int 0)))
6465    (clobber (match_scratch:DI 3 ""))]
6466   "TARGET_POWERPC64 && reload_completed"
6467   [(set (match_dup 3)
6468         (zero_extend:DI (subreg:HI
6469                       (rotate:DI (match_dup 1)
6470                                  (match_dup 2)) 0)))
6471    (set (match_dup 0)
6472         (compare:CC (match_dup 3)
6473                     (const_int 0)))]
6474   "")
6475
6476 (define_insn "*rotldi3_internal12"
6477   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6478         (compare:CC (zero_extend:DI
6479                      (subreg:HI
6480                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6481                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6482                     (const_int 0)))
6483    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6484         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6485   "TARGET_64BIT"
6486   "@
6487    rld%I2cl. %0,%1,%H2,48
6488    #"
6489   [(set_attr "type" "delayed_compare")
6490    (set_attr "length" "4,8")])
6491
6492 (define_split
6493   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6494         (compare:CC (zero_extend:DI
6495                      (subreg:HI
6496                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6497                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6498                     (const_int 0)))
6499    (set (match_operand:DI 0 "gpc_reg_operand" "")
6500         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6501   "TARGET_POWERPC64 && reload_completed"
6502   [(set (match_dup 0)
6503         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6504    (set (match_dup 3)
6505         (compare:CC (match_dup 0)
6506                     (const_int 0)))]
6507   "")
6508
6509 (define_insn "*rotldi3_internal13"
6510   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6511         (zero_extend:DI
6512          (subreg:SI
6513           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6514                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6515   "TARGET_POWERPC64"
6516   "rld%I2cl %0,%1,%H2,32")
6517
6518 (define_insn "*rotldi3_internal14"
6519   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6520         (compare:CC (zero_extend:DI
6521                      (subreg:SI
6522                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6523                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6524                     (const_int 0)))
6525    (clobber (match_scratch:DI 3 "=r,r"))]
6526   "TARGET_64BIT"
6527   "@
6528    rld%I2cl. %3,%1,%H2,32
6529    #"
6530   [(set_attr "type" "delayed_compare")
6531    (set_attr "length" "4,8")])
6532
6533 (define_split
6534   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6535         (compare:CC (zero_extend:DI
6536                      (subreg:SI
6537                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6538                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6539                     (const_int 0)))
6540    (clobber (match_scratch:DI 3 ""))]
6541   "TARGET_POWERPC64 && reload_completed"
6542   [(set (match_dup 3)
6543         (zero_extend:DI (subreg:SI
6544                       (rotate:DI (match_dup 1)
6545                                  (match_dup 2)) 0)))
6546    (set (match_dup 0)
6547         (compare:CC (match_dup 3)
6548                     (const_int 0)))]
6549   "")
6550
6551 (define_insn "*rotldi3_internal15"
6552   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6553         (compare:CC (zero_extend:DI
6554                      (subreg:SI
6555                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6556                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6557                     (const_int 0)))
6558    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6559         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6560   "TARGET_64BIT"
6561   "@
6562    rld%I2cl. %0,%1,%H2,32
6563    #"
6564   [(set_attr "type" "delayed_compare")
6565    (set_attr "length" "4,8")])
6566
6567 (define_split
6568   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6569         (compare:CC (zero_extend:DI
6570                      (subreg:SI
6571                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6572                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6573                     (const_int 0)))
6574    (set (match_operand:DI 0 "gpc_reg_operand" "")
6575         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6576   "TARGET_POWERPC64 && reload_completed"
6577   [(set (match_dup 0)
6578         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6579    (set (match_dup 3)
6580         (compare:CC (match_dup 0)
6581                     (const_int 0)))]
6582   "")
6583
6584 (define_expand "ashldi3"
6585   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6586         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6587                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
6588   "TARGET_POWERPC64 || TARGET_POWER"
6589   "
6590 {
6591   if (TARGET_POWERPC64)
6592     ;
6593   else if (TARGET_POWER)
6594     {
6595       emit_insn (gen_ashldi3_power (operands[0], operands[1], operands[2]));
6596       DONE;
6597     }
6598   else
6599     FAIL;
6600 }")
6601
6602 (define_insn "*ashldi3_internal1"
6603   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6604         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6605                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6606   "TARGET_POWERPC64"
6607   "sld%I2 %0,%1,%H2"
6608   [(set_attr "length" "8")])
6609   
6610 (define_insn "*ashldi3_internal2"
6611   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6612         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6613                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6614                     (const_int 0)))
6615    (clobber (match_scratch:DI 3 "=r,r"))]
6616   "TARGET_64BIT"
6617   "@
6618    sld%I2. %3,%1,%H2
6619    #"
6620   [(set_attr "type" "delayed_compare")
6621    (set_attr "length" "4,8")])
6622   
6623 (define_split
6624   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6625         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6626                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6627                     (const_int 0)))
6628    (clobber (match_scratch:DI 3 ""))]
6629   "TARGET_POWERPC64 && reload_completed"
6630   [(set (match_dup 3)
6631         (ashift:DI (match_dup 1) (match_dup 2)))
6632    (set (match_dup 0)
6633         (compare:CC (match_dup 3)
6634                     (const_int 0)))]
6635   "")
6636
6637 (define_insn "*ashldi3_internal3"
6638   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6639         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6640                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6641                     (const_int 0)))
6642    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6643         (ashift:DI (match_dup 1) (match_dup 2)))]
6644   "TARGET_64BIT"
6645   "@
6646    sld%I2. %0,%1,%H2
6647    #"
6648   [(set_attr "type" "delayed_compare")
6649    (set_attr "length" "4,8")])
6650
6651 (define_split
6652   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6653         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6654                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6655                     (const_int 0)))
6656    (set (match_operand:DI 0 "gpc_reg_operand" "")
6657         (ashift:DI (match_dup 1) (match_dup 2)))]
6658   "TARGET_POWERPC64 && reload_completed"
6659   [(set (match_dup 0)
6660         (ashift:DI (match_dup 1) (match_dup 2)))
6661    (set (match_dup 3)
6662         (compare:CC (match_dup 0)
6663                     (const_int 0)))]
6664   "")
6665
6666 (define_insn "*ashldi3_internal4"
6667   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6668         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6669                            (match_operand:SI 2 "const_int_operand" "i"))
6670                 (match_operand:DI 3 "const_int_operand" "n")))]
6671   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
6672   "rldic %0,%1,%H2,%W3")
6673
6674 (define_insn "ashldi3_internal5"
6675   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6676         (compare:CC
6677          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6678                             (match_operand:SI 2 "const_int_operand" "i,i"))
6679                  (match_operand:DI 3 "const_int_operand" "n,n"))
6680          (const_int 0)))
6681    (clobber (match_scratch:DI 4 "=r,r"))]
6682   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6683   "@
6684    rldic. %4,%1,%H2,%W3
6685    #"
6686   [(set_attr "type" "delayed_compare")
6687    (set_attr "length" "4,8")])
6688
6689 (define_split
6690   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6691         (compare:CC
6692          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6693                             (match_operand:SI 2 "const_int_operand" ""))
6694                  (match_operand:DI 3 "const_int_operand" ""))
6695          (const_int 0)))
6696    (clobber (match_scratch:DI 4 ""))]
6697   "TARGET_POWERPC64 && reload_completed
6698    && includes_rldic_lshift_p (operands[2], operands[3])"
6699   [(set (match_dup 4)
6700         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6701                 (match_dup 3)))
6702    (set (match_dup 0)
6703         (compare:CC (match_dup 4)
6704                     (const_int 0)))]
6705   "")
6706
6707 (define_insn "*ashldi3_internal6"
6708   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6709         (compare:CC
6710          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6711                             (match_operand:SI 2 "const_int_operand" "i,i"))
6712                     (match_operand:DI 3 "const_int_operand" "n,n"))
6713          (const_int 0)))
6714    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6715         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6716   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6717   "@
6718    rldic. %0,%1,%H2,%W3
6719    #"
6720   [(set_attr "type" "delayed_compare")
6721    (set_attr "length" "4,8")])
6722
6723 (define_split
6724   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6725         (compare:CC
6726          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6727                             (match_operand:SI 2 "const_int_operand" ""))
6728                  (match_operand:DI 3 "const_int_operand" ""))
6729          (const_int 0)))
6730    (set (match_operand:DI 0 "gpc_reg_operand" "")
6731         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6732   "TARGET_POWERPC64 && reload_completed
6733    && includes_rldic_lshift_p (operands[2], operands[3])"
6734   [(set (match_dup 0)
6735         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6736                 (match_dup 3)))
6737    (set (match_dup 4)
6738         (compare:CC (match_dup 0)
6739                     (const_int 0)))]
6740   "")
6741
6742 (define_insn "*ashldi3_internal7"
6743   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6744         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6745                            (match_operand:SI 2 "const_int_operand" "i"))
6746                 (match_operand:DI 3 "mask64_operand" "n")))]
6747   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
6748   "rldicr %0,%1,%H2,%S3")
6749
6750 (define_insn "ashldi3_internal8"
6751   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6752         (compare:CC
6753          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6754                             (match_operand:SI 2 "const_int_operand" "i,i"))
6755                  (match_operand:DI 3 "mask64_operand" "n,n"))
6756          (const_int 0)))
6757    (clobber (match_scratch:DI 4 "=r,r"))]
6758   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
6759   "@
6760    rldicr. %4,%1,%H2,%S3
6761    #"
6762   [(set_attr "type" "delayed_compare")
6763    (set_attr "length" "4,8")])
6764
6765 (define_split
6766   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6767         (compare:CC
6768          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6769                             (match_operand:SI 2 "const_int_operand" ""))
6770                  (match_operand:DI 3 "mask64_operand" ""))
6771          (const_int 0)))
6772    (clobber (match_scratch:DI 4 ""))]
6773   "TARGET_POWERPC64 && reload_completed
6774    && includes_rldicr_lshift_p (operands[2], operands[3])"
6775   [(set (match_dup 4)
6776         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6777                 (match_dup 3)))
6778    (set (match_dup 0)
6779         (compare:CC (match_dup 4)
6780                     (const_int 0)))]
6781   "")
6782
6783 (define_insn "*ashldi3_internal9"
6784   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6785         (compare:CC
6786          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6787                             (match_operand:SI 2 "const_int_operand" "i,i"))
6788                     (match_operand:DI 3 "mask64_operand" "n,n"))
6789          (const_int 0)))
6790    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6791         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6792   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
6793   "@
6794    rldicr. %0,%1,%H2,%S3
6795    #"
6796   [(set_attr "type" "delayed_compare")
6797    (set_attr "length" "4,8")])
6798
6799 (define_split
6800   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6801         (compare:CC
6802          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6803                             (match_operand:SI 2 "const_int_operand" ""))
6804                  (match_operand:DI 3 "mask64_operand" ""))
6805          (const_int 0)))
6806    (set (match_operand:DI 0 "gpc_reg_operand" "")
6807         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6808   "TARGET_POWERPC64 && reload_completed
6809    && includes_rldicr_lshift_p (operands[2], operands[3])"
6810   [(set (match_dup 0)
6811         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6812                 (match_dup 3)))
6813    (set (match_dup 4)
6814         (compare:CC (match_dup 0)
6815                     (const_int 0)))]
6816   "")
6817
6818 (define_expand "lshrdi3"
6819   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6820         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6821                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
6822   "TARGET_POWERPC64 || TARGET_POWER"
6823   "
6824 {
6825   if (TARGET_POWERPC64)
6826     ;
6827   else if (TARGET_POWER)
6828     {
6829       emit_insn (gen_lshrdi3_power (operands[0], operands[1], operands[2]));
6830       DONE;
6831     }
6832   else
6833     FAIL;
6834 }")
6835
6836 (define_insn "*lshrdi3_internal1"
6837   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6838         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6839                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6840   "TARGET_POWERPC64"
6841   "srd%I2 %0,%1,%H2")
6842
6843 (define_insn "*lshrdi3_internal2"
6844   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6845         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6846                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6847                     (const_int 0)))
6848    (clobber (match_scratch:DI 3 "=r,r"))]
6849   "TARGET_64BIT "
6850   "@
6851    srd%I2. %3,%1,%H2
6852    #"
6853   [(set_attr "type" "delayed_compare")
6854    (set_attr "length" "4,8")])
6855
6856 (define_split
6857   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6858         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6859                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6860                     (const_int 0)))
6861    (clobber (match_scratch:DI 3 ""))]
6862   "TARGET_POWERPC64 && reload_completed"
6863   [(set (match_dup 3)
6864         (lshiftrt:DI (match_dup 1) (match_dup 2)))
6865    (set (match_dup 0)
6866         (compare:CC (match_dup 3)
6867                     (const_int 0)))]
6868   "")
6869
6870 (define_insn "*lshrdi3_internal3"
6871   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6872         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6873                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6874                     (const_int 0)))
6875    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6876         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
6877   "TARGET_64BIT"
6878   "@
6879    srd%I2. %0,%1,%H2
6880    #"
6881   [(set_attr "type" "delayed_compare")
6882    (set_attr "length" "4,8")])
6883
6884 (define_split
6885   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6886         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6887                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6888                     (const_int 0)))
6889    (set (match_operand:DI 0 "gpc_reg_operand" "")
6890         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
6891   "TARGET_POWERPC64 && reload_completed"
6892   [(set (match_dup 0)
6893         (lshiftrt:DI (match_dup 1) (match_dup 2)))
6894    (set (match_dup 3)
6895         (compare:CC (match_dup 0)
6896                     (const_int 0)))]
6897   "")
6898
6899 (define_expand "ashrdi3"
6900   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6901         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6902                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
6903   "WORDS_BIG_ENDIAN"
6904   "
6905 {
6906   if (TARGET_POWERPC64)
6907     ;
6908   else if (TARGET_POWER && GET_CODE (operands[2]) == CONST_INT)
6909     {
6910       emit_insn (gen_ashrdi3_power (operands[0], operands[1], operands[2]));
6911       DONE;
6912     }
6913   else if (TARGET_32BIT && GET_CODE (operands[2]) == CONST_INT
6914            && WORDS_BIG_ENDIAN)
6915     {
6916       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
6917       DONE;
6918     }
6919   else
6920     FAIL;
6921 }")
6922
6923 (define_insn "*ashrdi3_internal1"
6924   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6925         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6926                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6927   "TARGET_POWERPC64"
6928   "srad%I2 %0,%1,%H2")
6929
6930 (define_insn "*ashrdi3_internal2"
6931   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6932         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6933                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6934                     (const_int 0)))
6935    (clobber (match_scratch:DI 3 "=r,r"))]
6936   "TARGET_64BIT"
6937   "@
6938    srad%I2. %3,%1,%H2
6939    #"
6940   [(set_attr "type" "delayed_compare")
6941    (set_attr "length" "4,8")])
6942
6943 (define_split
6944   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6945         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6946                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6947                     (const_int 0)))
6948    (clobber (match_scratch:DI 3 ""))]
6949   "TARGET_POWERPC64 && reload_completed"
6950   [(set (match_dup 3)
6951         (ashiftrt:DI (match_dup 1) (match_dup 2)))
6952    (set (match_dup 0)
6953         (compare:CC (match_dup 3)
6954                     (const_int 0)))]
6955   "")
6956
6957 (define_insn "*ashrdi3_internal3"
6958   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6959         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6960                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6961                     (const_int 0)))
6962    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6963         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
6964   "TARGET_64BIT"
6965   "@
6966    srad%I2. %0,%1,%H2
6967    #"
6968   [(set_attr "type" "delayed_compare")
6969    (set_attr "length" "4,8")])
6970
6971 (define_split
6972   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6973         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6974                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6975                     (const_int 0)))
6976    (set (match_operand:DI 0 "gpc_reg_operand" "")
6977         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
6978   "TARGET_POWERPC64 && reload_completed"
6979   [(set (match_dup 0)
6980         (ashiftrt:DI (match_dup 1) (match_dup 2)))
6981    (set (match_dup 3)
6982         (compare:CC (match_dup 0)
6983                     (const_int 0)))]
6984   "")
6985
6986 (define_insn "anddi3"
6987   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r")
6988         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r")
6989                 (match_operand:DI 2 "and64_2_operand" "?r,S,K,J,t")))
6990    (clobber (match_scratch:CC 3 "=X,X,x,x,X"))]
6991   "TARGET_POWERPC64"
6992   "@
6993    and %0,%1,%2
6994    rldic%B2 %0,%1,0,%S2
6995    andi. %0,%1,%b2
6996    andis. %0,%1,%u2
6997    #"
6998   [(set_attr "length" "4,4,4,4,8")])
6999
7000 (define_split
7001   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7002         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7003                 (match_operand:DI 2 "mask64_2_operand" "")))
7004    (clobber (match_scratch:CC 3 ""))]
7005   "TARGET_POWERPC64
7006     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7007     && !mask64_operand (operands[2], DImode)"
7008   [(set (match_dup 0)
7009         (and:DI (rotate:DI (match_dup 1)
7010                            (match_dup 4))
7011                 (match_dup 5)))
7012    (set (match_dup 0)
7013         (and:DI (rotate:DI (match_dup 0)
7014                            (match_dup 6))
7015                 (match_dup 7)))]
7016   "
7017 {
7018   build_mask64_2_operands (operands[2], &operands[4]);
7019 }")
7020
7021 (define_insn "*anddi3_internal2"
7022   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,??y,??y,?y")
7023         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
7024                             (match_operand:DI 2 "and64_2_operand" "r,S,K,J,t,r,S,K,J,t"))
7025                     (const_int 0)))
7026    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r"))
7027    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,x,x,X"))]
7028   "TARGET_64BIT"
7029   "@
7030    and. %3,%1,%2
7031    rldic%B2. %3,%1,0,%S2
7032    andi. %3,%1,%b2
7033    andis. %3,%1,%u2
7034    #
7035    #
7036    #
7037    #
7038    #
7039    #"
7040   [(set_attr "type" "compare,delayed_compare,compare,compare,delayed_compare,compare,compare,compare,compare,compare")
7041    (set_attr "length" "4,4,4,4,8,8,8,8,8,12")])
7042
7043 (define_split
7044   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7045         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7046                             (match_operand:DI 2 "and64_operand" ""))
7047                     (const_int 0)))
7048    (clobber (match_scratch:DI 3 ""))
7049    (clobber (match_scratch:CC 4 ""))]
7050   "TARGET_POWERPC64 && reload_completed"
7051   [(parallel [(set (match_dup 3)
7052                    (and:DI (match_dup 1)
7053                            (match_dup 2)))
7054               (clobber (match_dup 4))])
7055    (set (match_dup 0)
7056         (compare:CC (match_dup 3)
7057                     (const_int 0)))]
7058   "")
7059
7060 (define_split
7061   [(set (match_operand:CC 0 "cc_reg_operand" "")
7062         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7063                             (match_operand:DI 2 "mask64_2_operand" ""))
7064                     (const_int 0)))
7065    (clobber (match_scratch:DI 3 ""))
7066    (clobber (match_scratch:CC 4 ""))]
7067   "TARGET_POWERPC64 && reload_completed
7068     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7069     && !mask64_operand (operands[2], DImode)"
7070   [(set (match_dup 3)
7071         (and:DI (rotate:DI (match_dup 1)
7072                            (match_dup 5))
7073                 (match_dup 6)))
7074    (parallel [(set (match_dup 0)
7075                    (compare:CC (and:DI (rotate:DI (match_dup 3)
7076                                                   (match_dup 7))
7077                                        (match_dup 8))
7078                                (const_int 0)))
7079               (clobber (match_dup 3))])]
7080   "
7081 {
7082   build_mask64_2_operands (operands[2], &operands[5]);
7083 }")
7084
7085 (define_insn "*anddi3_internal3"
7086   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,?y,?y,??y,??y,?y")
7087         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
7088                             (match_operand:DI 2 "and64_2_operand" "r,S,K,J,t,r,S,K,J,t"))
7089                     (const_int 0)))
7090    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
7091         (and:DI (match_dup 1) (match_dup 2)))
7092    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,x,x,X"))]
7093   "TARGET_64BIT"
7094   "@
7095    and. %0,%1,%2
7096    rldic%B2. %0,%1,0,%S2
7097    andi. %0,%1,%b2
7098    andis. %0,%1,%u2
7099    #
7100    #
7101    #
7102    #
7103    #
7104    #"
7105   [(set_attr "type" "compare,delayed_compare,compare,compare,delayed_compare,compare,compare,compare,compare,compare")
7106    (set_attr "length" "4,4,4,4,8,8,8,8,8,12")])
7107
7108 (define_split
7109   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7110         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7111                             (match_operand:DI 2 "and64_operand" ""))
7112                     (const_int 0)))
7113    (set (match_operand:DI 0 "gpc_reg_operand" "")
7114         (and:DI (match_dup 1) (match_dup 2)))
7115    (clobber (match_scratch:CC 4 ""))]
7116   "TARGET_POWERPC64 && reload_completed"
7117   [(parallel [(set (match_dup 0)
7118                     (and:DI (match_dup 1) (match_dup 2)))
7119                (clobber (match_dup 4))])
7120    (set (match_dup 3)
7121         (compare:CC (match_dup 0)
7122                     (const_int 0)))]
7123   "")
7124
7125 (define_split
7126   [(set (match_operand:CC 3 "cc_reg_operand" "")
7127         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7128                             (match_operand:DI 2 "mask64_2_operand" ""))
7129                     (const_int 0)))
7130    (set (match_operand:DI 0 "gpc_reg_operand" "")
7131         (and:DI (match_dup 1) (match_dup 2)))
7132    (clobber (match_scratch:CC 4 ""))]
7133   "TARGET_POWERPC64 && reload_completed
7134     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7135     && !mask64_operand (operands[2], DImode)"
7136   [(set (match_dup 0)
7137         (and:DI (rotate:DI (match_dup 1)
7138                            (match_dup 5))
7139                 (match_dup 6)))
7140    (parallel [(set (match_dup 3)
7141                    (compare:CC (and:DI (rotate:DI (match_dup 0)
7142                                                   (match_dup 7))
7143                                        (match_dup 8))
7144                                (const_int 0)))
7145               (set (match_dup 0)
7146                    (and:DI (rotate:DI (match_dup 0)
7147                                       (match_dup 7))
7148                            (match_dup 8)))])]
7149   "
7150 {
7151   build_mask64_2_operands (operands[2], &operands[5]);
7152 }")
7153
7154 (define_expand "iordi3"
7155   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7156         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
7157                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7158   "TARGET_POWERPC64"
7159   "
7160 {
7161   if (non_logical_cint_operand (operands[2], DImode))
7162     {
7163       HOST_WIDE_INT value;
7164       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7165                  ? operands[0] : gen_reg_rtx (DImode));
7166
7167       if (GET_CODE (operands[2]) == CONST_INT)
7168         {
7169           value = INTVAL (operands[2]);
7170           emit_insn (gen_iordi3 (tmp, operands[1],
7171                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7172         }
7173       else
7174         {
7175           value = CONST_DOUBLE_LOW (operands[2]);
7176           emit_insn (gen_iordi3 (tmp, operands[1],
7177                                  immed_double_const (value
7178                                                      & (~ (HOST_WIDE_INT) 0xffff),
7179                                                      0, DImode)));
7180         }
7181
7182       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7183       DONE;
7184     }
7185 }")
7186
7187 (define_expand "xordi3"
7188   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7189         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
7190                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7191   "TARGET_POWERPC64"
7192   "
7193 {
7194   if (non_logical_cint_operand (operands[2], DImode))
7195     {
7196       HOST_WIDE_INT value;
7197       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7198                  ? operands[0] : gen_reg_rtx (DImode));
7199
7200       if (GET_CODE (operands[2]) == CONST_INT)
7201         {
7202           value = INTVAL (operands[2]);
7203           emit_insn (gen_xordi3 (tmp, operands[1],
7204                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7205         }
7206       else
7207         {
7208           value = CONST_DOUBLE_LOW (operands[2]);
7209           emit_insn (gen_xordi3 (tmp, operands[1],
7210                                  immed_double_const (value
7211                                                      & (~ (HOST_WIDE_INT) 0xffff),
7212                                                      0, DImode)));
7213         }
7214
7215       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7216       DONE;
7217     }
7218 }")
7219
7220 (define_insn "*booldi3_internal1"
7221   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
7222         (match_operator:DI 3 "boolean_or_operator"
7223          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
7224           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
7225   "TARGET_POWERPC64"
7226   "@
7227    %q3 %0,%1,%2
7228    %q3i %0,%1,%b2
7229    %q3is %0,%1,%u2")
7230
7231 (define_insn "*booldi3_internal2"
7232   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7233         (compare:CC (match_operator:DI 4 "boolean_or_operator"
7234          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7235           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7236          (const_int 0)))
7237    (clobber (match_scratch:DI 3 "=r,r"))]
7238   "TARGET_64BIT"
7239   "@
7240    %q4. %3,%1,%2
7241    #"
7242   [(set_attr "type" "compare")
7243    (set_attr "length" "4,8")])
7244
7245 (define_split
7246   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7247         (compare:CC (match_operator:DI 4 "boolean_operator"
7248          [(match_operand:DI 1 "gpc_reg_operand" "")
7249           (match_operand:DI 2 "gpc_reg_operand" "")])
7250          (const_int 0)))
7251    (clobber (match_scratch:DI 3 ""))]
7252   "TARGET_POWERPC64 && reload_completed"
7253   [(set (match_dup 3) (match_dup 4))
7254    (set (match_dup 0)
7255         (compare:CC (match_dup 3)
7256                     (const_int 0)))]
7257   "")
7258
7259 (define_insn "*booldi3_internal3"
7260   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7261         (compare:CC (match_operator:DI 4 "boolean_operator"
7262          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7263           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7264          (const_int 0)))
7265    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7266         (match_dup 4))]
7267   "TARGET_64BIT"
7268   "@
7269    %q4. %0,%1,%2
7270    #"
7271   [(set_attr "type" "compare")
7272    (set_attr "length" "4,8")])
7273
7274 (define_split
7275   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7276         (compare:CC (match_operator:DI 4 "boolean_operator"
7277          [(match_operand:DI 1 "gpc_reg_operand" "")
7278           (match_operand:DI 2 "gpc_reg_operand" "")])
7279          (const_int 0)))
7280    (set (match_operand:DI 0 "gpc_reg_operand" "")
7281         (match_dup 4))]
7282   "TARGET_POWERPC64 && reload_completed"
7283   [(set (match_dup 0) (match_dup 4))
7284    (set (match_dup 3)
7285         (compare:CC (match_dup 0)
7286                     (const_int 0)))]
7287   "")
7288
7289 ;; Split a logical operation that we can't do in one insn into two insns, 
7290 ;; each of which does one 16-bit part.  This is used by combine.
7291
7292 (define_split
7293   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7294         (match_operator:DI 3 "boolean_or_operator"
7295          [(match_operand:DI 1 "gpc_reg_operand" "")
7296           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
7297   "TARGET_POWERPC64"
7298   [(set (match_dup 0) (match_dup 4))
7299    (set (match_dup 0) (match_dup 5))]
7300 "
7301 {
7302   rtx i3,i4;
7303   
7304   if (GET_CODE (operands[2]) == CONST_DOUBLE)
7305     {
7306       HOST_WIDE_INT value = CONST_DOUBLE_LOW (operands[2]);
7307       i3 = immed_double_const (value & (~ (HOST_WIDE_INT) 0xffff),
7308                                         0, DImode);
7309       i4 = GEN_INT (value & 0xffff);
7310     }
7311   else
7312     {
7313       i3 = GEN_INT (INTVAL (operands[2])
7314                              & (~ (HOST_WIDE_INT) 0xffff));
7315       i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
7316     }
7317   operands[4] = gen_rtx (GET_CODE (operands[3]), DImode,
7318                          operands[1], i3);
7319   operands[5] = gen_rtx (GET_CODE (operands[3]), DImode,
7320                          operands[0], i4);
7321 }")
7322
7323 (define_insn "*boolcdi3_internal1"
7324   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7325         (match_operator:DI 3 "boolean_operator"
7326          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7327           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
7328   "TARGET_POWERPC64"
7329   "%q3 %0,%2,%1")
7330
7331 (define_insn "*boolcdi3_internal2"
7332   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7333         (compare:CC (match_operator:DI 4 "boolean_operator"
7334          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7335           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7336          (const_int 0)))
7337    (clobber (match_scratch:DI 3 "=r,r"))]
7338   "TARGET_64BIT"
7339   "@
7340    %q4. %3,%2,%1
7341    #"
7342   [(set_attr "type" "compare")
7343    (set_attr "length" "4,8")])
7344
7345 (define_split
7346   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7347         (compare:CC (match_operator:DI 4 "boolean_operator"
7348          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7349           (match_operand:DI 2 "gpc_reg_operand" "")])
7350          (const_int 0)))
7351    (clobber (match_scratch:DI 3 ""))]
7352   "TARGET_POWERPC64 && reload_completed"
7353   [(set (match_dup 3) (match_dup 4))
7354    (set (match_dup 0)
7355         (compare:CC (match_dup 3)
7356                     (const_int 0)))]
7357   "")
7358
7359 (define_insn "*boolcdi3_internal3"
7360   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7361         (compare:CC (match_operator:DI 4 "boolean_operator"
7362          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7363           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7364          (const_int 0)))
7365    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7366         (match_dup 4))]
7367   "TARGET_64BIT"
7368   "@
7369    %q4. %0,%2,%1
7370    #"
7371   [(set_attr "type" "compare")
7372    (set_attr "length" "4,8")])
7373
7374 (define_split
7375   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7376         (compare:CC (match_operator:DI 4 "boolean_operator"
7377          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7378           (match_operand:DI 2 "gpc_reg_operand" "")])
7379          (const_int 0)))
7380    (set (match_operand:DI 0 "gpc_reg_operand" "")
7381         (match_dup 4))]
7382   "TARGET_POWERPC64 && reload_completed"
7383   [(set (match_dup 0) (match_dup 4))
7384    (set (match_dup 3)
7385         (compare:CC (match_dup 0)
7386                     (const_int 0)))]
7387   "")
7388
7389 (define_insn "*boolccdi3_internal1"
7390   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7391         (match_operator:DI 3 "boolean_operator"
7392          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7393           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
7394   "TARGET_POWERPC64"
7395   "%q3 %0,%1,%2")
7396
7397 (define_insn "*boolccdi3_internal2"
7398   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7399         (compare:CC (match_operator:DI 4 "boolean_operator"
7400          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7401           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7402          (const_int 0)))
7403    (clobber (match_scratch:DI 3 "=r,r"))]
7404   "TARGET_64BIT"
7405   "@
7406    %q4. %3,%1,%2
7407    #"
7408   [(set_attr "type" "compare")
7409    (set_attr "length" "4,8")])
7410
7411 (define_split
7412   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7413         (compare:CC (match_operator:DI 4 "boolean_operator"
7414          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7415           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7416          (const_int 0)))
7417    (clobber (match_scratch:DI 3 ""))]
7418   "TARGET_POWERPC64 && reload_completed"
7419   [(set (match_dup 3) (match_dup 4))
7420    (set (match_dup 0)
7421         (compare:CC (match_dup 3)
7422                     (const_int 0)))]
7423   "")
7424
7425 (define_insn "*boolccdi3_internal3"
7426   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7427         (compare:CC (match_operator:DI 4 "boolean_operator"
7428          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7429           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7430          (const_int 0)))
7431    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7432         (match_dup 4))]
7433   "TARGET_64BIT"
7434   "@
7435    %q4. %0,%1,%2
7436    #"
7437   [(set_attr "type" "compare")
7438    (set_attr "length" "4,8")])
7439
7440 (define_split
7441   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7442         (compare:CC (match_operator:DI 4 "boolean_operator"
7443          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7444           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7445          (const_int 0)))
7446    (set (match_operand:DI 0 "gpc_reg_operand" "")
7447         (match_dup 4))]
7448   "TARGET_POWERPC64 && reload_completed"
7449   [(set (match_dup 0) (match_dup 4))
7450    (set (match_dup 3)
7451         (compare:CC (match_dup 0)
7452                     (const_int 0)))]
7453   "")
7454 \f
7455 ;; Now define ways of moving data around.
7456
7457 ;; Elf specific ways of loading addresses for non-PIC code.
7458 ;; The output of this could be r0, but we make a very strong
7459 ;; preference for a base register because it will usually
7460 ;; be needed there.
7461 (define_insn "elf_high"
7462   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
7463         (high:SI (match_operand 1 "" "")))]
7464   "TARGET_ELF && ! TARGET_64BIT"
7465   "{liu|lis} %0,%1@ha")
7466
7467 (define_insn "elf_low"
7468   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
7469         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
7470                    (match_operand 2 "" "")))]
7471    "TARGET_ELF && ! TARGET_64BIT"
7472    "@
7473     {cal|la} %0,%2@l(%1)
7474     {ai|addic} %0,%1,%K2")
7475
7476 ;; Mach-O PIC trickery.
7477 (define_insn "macho_high"
7478   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
7479         (high:SI (match_operand 1 "" "")))]
7480   "TARGET_MACHO && ! TARGET_64BIT"
7481   "{liu|lis} %0,ha16(%1)")
7482
7483 (define_insn "macho_low"
7484   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
7485         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
7486                    (match_operand 2 "" "")))]
7487    "TARGET_MACHO && ! TARGET_64BIT"
7488    "@
7489     {cal %0,%a2@l(%1)|la %0,lo16(%2)(%1)}
7490     {cal %0,%a2@l(%1)|addic %0,%1,lo16(%2)}")
7491
7492 ;; Set up a register with a value from the GOT table
7493
7494 (define_expand "movsi_got"
7495   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7496         (unspec:SI [(match_operand:SI 1 "got_operand" "")
7497                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
7498   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7499   "
7500 {
7501   if (GET_CODE (operands[1]) == CONST)
7502     {
7503       rtx offset = const0_rtx;
7504       HOST_WIDE_INT value;
7505
7506       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
7507       value = INTVAL (offset);
7508       if (value != 0)
7509         {
7510           rtx tmp = (no_new_pseudos ? operands[0] : gen_reg_rtx (Pmode));
7511           emit_insn (gen_movsi_got (tmp, operands[1]));
7512           emit_insn (gen_addsi3 (operands[0], tmp, offset));
7513           DONE;
7514         }
7515     }
7516
7517   operands[2] = rs6000_got_register (operands[1]);
7518 }")
7519
7520 (define_insn "*movsi_got_internal"
7521   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7522         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7523                     (match_operand:SI 2 "gpc_reg_operand" "b")]
7524                    UNSPEC_MOVSI_GOT))]
7525   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7526   "{l|lwz} %0,%a1@got(%2)"
7527   [(set_attr "type" "load")])
7528
7529 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
7530 ;; didn't get allocated to a hard register.
7531 (define_split 
7532   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7533         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7534                     (match_operand:SI 2 "memory_operand" "")]
7535                    UNSPEC_MOVSI_GOT))]
7536   "DEFAULT_ABI == ABI_V4
7537     && flag_pic == 1
7538     && (reload_in_progress || reload_completed)"
7539   [(set (match_dup 0) (match_dup 2))
7540    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
7541                                  UNSPEC_MOVSI_GOT))]
7542   "")
7543
7544 ;; For SI, we special-case integers that can't be loaded in one insn.  We
7545 ;; do the load 16-bits at a time.  We could do this by loading from memory,
7546 ;; and this is even supposed to be faster, but it is simpler not to get
7547 ;; integers in the TOC.
7548 (define_expand "movsi"
7549   [(set (match_operand:SI 0 "general_operand" "")
7550         (match_operand:SI 1 "any_operand" ""))]
7551   ""
7552   "{ rs6000_emit_move (operands[0], operands[1], SImode); DONE; }")
7553
7554 (define_insn "movsi_low"
7555   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7556         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7557                            (match_operand 2 "" ""))))]
7558   "TARGET_MACHO && ! TARGET_64BIT"
7559   "{l|lwz} %0,lo16(%2)(%1)"
7560   [(set_attr "type" "load")
7561    (set_attr "length" "4")])
7562
7563 (define_insn "movsi_low_st"
7564   [(set (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7565                            (match_operand 2 "" "")))
7566         (match_operand:SI 0 "gpc_reg_operand" "r"))]
7567   "TARGET_MACHO && ! TARGET_64BIT"
7568   "{st|stw} %0,lo16(%2)(%1)"
7569   [(set_attr "type" "store")
7570    (set_attr "length" "4")])
7571
7572 (define_insn "movdf_low"
7573   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,!r")
7574         (mem:DF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
7575                            (match_operand 2 "" ""))))]
7576   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
7577   "*
7578 {
7579   switch (which_alternative)
7580     {
7581       case 0:
7582         return \"lfd %0,lo16(%2)(%1)\";
7583       case 1:
7584         {
7585           rtx operands2[4];
7586           operands2[0] = operands[0];
7587           operands2[1] = operands[1];
7588           operands2[2] = operands[2];
7589           if (TARGET_POWERPC64 && TARGET_32BIT)
7590             /* Note, old assemblers didn't support relocation here.  */
7591             return \"ld %0,lo16(%2)(%1)\";
7592           else
7593           {
7594             operands2[3] = gen_rtx_REG (SImode, RS6000_PIC_OFFSET_TABLE_REGNUM);     
7595             output_asm_insn (\"{l|lwz} %0,lo16(%2)(%1)\", operands);
7596 #if TARGET_MACHO
7597             if (MACHO_DYNAMIC_NO_PIC_P)
7598               output_asm_insn (\"{liu|lis} %L0,ha16(%2+4)\", operands);
7599             else     
7600             /* We cannot rely on ha16(low half)==ha16(high half), alas,
7601                although in practice it almost always is.  */
7602             output_asm_insn (\"{cau|addis} %L0,%3,ha16(%2+4)\", operands2);
7603 #endif
7604             return (\"{l|lwz} %L0,lo16(%2+4)(%L0)\");
7605           }
7606         }
7607       default:
7608         abort();
7609     }
7610 }"
7611   [(set_attr "type" "load")
7612    (set_attr "length" "4,12")])
7613
7614 (define_insn "movdf_low_st"
7615   [(set (mem:DF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7616                            (match_operand 2 "" "")))
7617         (match_operand:DF 0 "gpc_reg_operand" "f"))]
7618   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
7619   "stfd %0,lo16(%2)(%1)"
7620   [(set_attr "type" "store")
7621    (set_attr "length" "4")])
7622
7623 (define_insn "movsf_low"
7624   [(set (match_operand:SF 0 "gpc_reg_operand" "=f,!r")
7625         (mem:SF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
7626                            (match_operand 2 "" ""))))]
7627   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
7628   "@
7629    lfs %0,lo16(%2)(%1)
7630    {l|lwz} %0,lo16(%2)(%1)"
7631   [(set_attr "type" "load")
7632    (set_attr "length" "4")])
7633
7634 (define_insn "movsf_low_st"
7635   [(set (mem:SF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
7636                            (match_operand 2 "" "")))
7637         (match_operand:SF 0 "gpc_reg_operand" "f,!r"))]
7638   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
7639   "@
7640    stfs %0,lo16(%2)(%1)
7641    {st|stw} %0,lo16(%2)(%1)"
7642   [(set_attr "type" "store")
7643    (set_attr "length" "4")])
7644
7645 (define_insn "*movsi_internal1"
7646   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h")
7647         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0"))]
7648   "gpc_reg_operand (operands[0], SImode)
7649    || gpc_reg_operand (operands[1], SImode)"
7650   "@
7651    mr %0,%1
7652    {cal|la} %0,%a1
7653    {l%U1%X1|lwz%U1%X1} %0,%1
7654    {st%U0%X0|stw%U0%X0} %1,%0
7655    {lil|li} %0,%1
7656    {liu|lis} %0,%v1
7657    #
7658    {cal|la} %0,%a1
7659    mf%1 %0
7660    mt%0 %1
7661    mt%0 %1
7662    mt%0 %1
7663    {cror 0,0,0|nop}"
7664   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*")
7665    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
7666
7667 ;; Split a load of a large constant into the appropriate two-insn
7668 ;; sequence.
7669
7670 (define_split
7671   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7672         (match_operand:SI 1 "const_int_operand" ""))]
7673   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
7674    && (INTVAL (operands[1]) & 0xffff) != 0"
7675   [(set (match_dup 0)
7676         (match_dup 2))
7677    (set (match_dup 0)
7678         (ior:SI (match_dup 0)
7679                 (match_dup 3)))]
7680   "
7681 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
7682
7683   if (tem == operands[0])
7684     DONE;
7685   else
7686     FAIL;
7687 }")
7688
7689 (define_insn "*movsi_internal2"
7690   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
7691         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "0,r,r")
7692                     (const_int 0)))
7693    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
7694   "TARGET_32BIT"
7695   "@
7696    {cmpi|cmpwi} %2,%0,0
7697    mr. %0,%1
7698    #"
7699   [(set_attr "type" "cmp,compare,cmp")
7700    (set_attr "length" "4,4,8")])
7701
7702 (define_split
7703   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
7704         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
7705                     (const_int 0)))
7706    (set (match_operand:SI 0 "gpc_reg_operand" "") (match_dup 1))]
7707   "TARGET_32BIT && reload_completed"
7708   [(set (match_dup 0) (match_dup 1))
7709    (set (match_dup 2)
7710         (compare:CC (match_dup 0)
7711                     (const_int 0)))]
7712   "")
7713 \f
7714 (define_expand "movhi"
7715   [(set (match_operand:HI 0 "general_operand" "")
7716         (match_operand:HI 1 "any_operand" ""))]
7717   ""
7718   "{ rs6000_emit_move (operands[0], operands[1], HImode); DONE; }")
7719
7720 (define_insn "*movhi_internal"
7721   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7722         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7723   "gpc_reg_operand (operands[0], HImode)
7724    || gpc_reg_operand (operands[1], HImode)"
7725   "@
7726    mr %0,%1
7727    lhz%U1%X1 %0,%1
7728    sth%U0%X0 %1,%0
7729    {lil|li} %0,%w1
7730    mf%1 %0
7731    mt%0 %1
7732    mt%0 %1
7733    {cror 0,0,0|nop}"
7734   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7735
7736 (define_expand "movqi"
7737   [(set (match_operand:QI 0 "general_operand" "")
7738         (match_operand:QI 1 "any_operand" ""))]
7739   ""
7740   "{ rs6000_emit_move (operands[0], operands[1], QImode); DONE; }")
7741
7742 (define_insn "*movqi_internal"
7743   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7744         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7745   "gpc_reg_operand (operands[0], QImode)
7746    || gpc_reg_operand (operands[1], QImode)"
7747   "@
7748    mr %0,%1
7749    lbz%U1%X1 %0,%1
7750    stb%U0%X0 %1,%0
7751    {lil|li} %0,%1
7752    mf%1 %0
7753    mt%0 %1
7754    mt%0 %1
7755    {cror 0,0,0|nop}"
7756   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7757 \f
7758 ;; Here is how to move condition codes around.  When we store CC data in
7759 ;; an integer register or memory, we store just the high-order 4 bits.
7760 ;; This lets us not shift in the most common case of CR0.
7761 (define_expand "movcc"
7762   [(set (match_operand:CC 0 "nonimmediate_operand" "")
7763         (match_operand:CC 1 "nonimmediate_operand" ""))]
7764   ""
7765   "")
7766
7767 (define_insn "*movcc_internal1"
7768   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,r,r,r,r,q,cl,r,m")
7769         (match_operand:CC 1 "nonimmediate_operand" "y,r,r,x,y,r,h,r,r,m,r"))]
7770   "register_operand (operands[0], CCmode)
7771    || register_operand (operands[1], CCmode)"
7772   "@
7773    mcrf %0,%1
7774    mtcrf 128,%1
7775    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
7776    mfcr %0%Q1
7777    mfcr %0%Q1\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
7778    mr %0,%1
7779    mf%1 %0
7780    mt%0 %1
7781    mt%0 %1
7782    {l%U1%X1|lwz%U1%X1} %0,%1
7783    {st%U0%U1|stw%U0%U1} %1,%0"
7784   [(set (attr "type")
7785      (cond [(eq_attr "alternative" "0")
7786                 (const_string "cr_logical")
7787             (eq_attr "alternative" "1,2")
7788                 (const_string "mtcr")
7789             (eq_attr "alternative" "5,7")
7790                 (const_string "integer")
7791             (eq_attr "alternative" "6")
7792                 (const_string "mfjmpr")
7793             (eq_attr "alternative" "8")
7794                 (const_string "mtjmpr")
7795             (eq_attr "alternative" "9")
7796                 (const_string "load")
7797             (eq_attr "alternative" "10")
7798                 (const_string "store")
7799             (ne (symbol_ref "TARGET_MFCRF") (const_int 0))
7800                 (const_string "mfcrf")
7801            ]
7802         (const_string "mfcr")))
7803    (set_attr "length" "4,4,12,4,8,4,4,4,4,4,4")])
7804 \f
7805 ;; For floating-point, we normally deal with the floating-point registers
7806 ;; unless -msoft-float is used.  The sole exception is that parameter passing
7807 ;; can produce floating-point values in fixed-point registers.  Unless the
7808 ;; value is a simple constant or already in memory, we deal with this by
7809 ;; allocating memory and copying the value explicitly via that memory location.
7810 (define_expand "movsf"
7811   [(set (match_operand:SF 0 "nonimmediate_operand" "")
7812         (match_operand:SF 1 "any_operand" ""))]
7813   ""
7814   "{ rs6000_emit_move (operands[0], operands[1], SFmode); DONE; }")
7815
7816 (define_split
7817   [(set (match_operand:SF 0 "gpc_reg_operand" "")
7818         (match_operand:SF 1 "const_double_operand" ""))]
7819   "reload_completed
7820    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7821        || (GET_CODE (operands[0]) == SUBREG
7822            && GET_CODE (SUBREG_REG (operands[0])) == REG
7823            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7824   [(set (match_dup 2) (match_dup 3))]
7825   "
7826 {
7827   long l;
7828   REAL_VALUE_TYPE rv;
7829
7830   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7831   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
7832
7833   if (! TARGET_POWERPC64)
7834     operands[2] = operand_subword (operands[0], 0, 0, SFmode);
7835   else
7836     operands[2] = gen_lowpart (SImode, operands[0]);
7837
7838   operands[3] = gen_int_mode (l, SImode);
7839 }")
7840
7841 (define_insn "*movsf_hardfloat"
7842   [(set (match_operand:SF 0 "nonimmediate_operand" "=!r,!r,m,f,f,m,!cl,!q,!r,!r,!r")
7843         (match_operand:SF 1 "input_operand" "r,m,r,f,m,f,r,r,h,G,Fn"))]
7844   "(gpc_reg_operand (operands[0], SFmode)
7845    || gpc_reg_operand (operands[1], SFmode))
7846    && (TARGET_HARD_FLOAT && TARGET_FPRS)"
7847   "@
7848    mr %0,%1
7849    {l%U1%X1|lwz%U1%X1} %0,%1
7850    {st%U0%X0|stw%U0%X0} %1,%0
7851    fmr %0,%1
7852    lfs%U1%X1 %0,%1
7853    stfs%U0%X0 %1,%0
7854    mt%0 %1
7855    mt%0 %1
7856    mf%1 %0
7857    #
7858    #"
7859   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,mtjmpr,*,*,*")
7860    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8")])
7861
7862 (define_insn "*movsf_softfloat"
7863   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,cl,q,r,r,m,r,r,r,r,r,*h")
7864         (match_operand:SF 1 "input_operand" "r,r,r,h,m,r,I,L,R,G,Fn,0"))]
7865   "(gpc_reg_operand (operands[0], SFmode)
7866    || gpc_reg_operand (operands[1], SFmode))
7867    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
7868   "@
7869    mr %0,%1
7870    mt%0 %1
7871    mt%0 %1
7872    mf%1 %0
7873    {l%U1%X1|lwz%U1%X1} %0,%1
7874    {st%U0%X0|stw%U0%X0} %1,%0
7875    {lil|li} %0,%1
7876    {liu|lis} %0,%v1
7877    {cal|la} %0,%a1
7878    #
7879    #
7880    {cror 0,0,0|nop}"
7881   [(set_attr "type" "*,mtjmpr,*,*,load,store,*,*,*,*,*,*")
7882    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,4")])
7883
7884 \f
7885 (define_expand "movdf"
7886   [(set (match_operand:DF 0 "nonimmediate_operand" "")
7887         (match_operand:DF 1 "any_operand" ""))]
7888   ""
7889   "{ rs6000_emit_move (operands[0], operands[1], DFmode); DONE; }")
7890
7891 (define_split
7892   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7893         (match_operand:DF 1 "const_int_operand" ""))]
7894   "! TARGET_POWERPC64 && reload_completed
7895    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7896        || (GET_CODE (operands[0]) == SUBREG
7897            && GET_CODE (SUBREG_REG (operands[0])) == REG
7898            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7899   [(set (match_dup 2) (match_dup 4))
7900    (set (match_dup 3) (match_dup 1))]
7901   "
7902 {
7903   int endian = (WORDS_BIG_ENDIAN == 0);
7904   HOST_WIDE_INT value = INTVAL (operands[1]);
7905
7906   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
7907   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
7908 #if HOST_BITS_PER_WIDE_INT == 32
7909   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
7910 #else
7911   operands[4] = GEN_INT (value >> 32);
7912   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
7913 #endif
7914 }")
7915
7916 (define_split
7917   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7918         (match_operand:DF 1 "const_double_operand" ""))]
7919   "! TARGET_POWERPC64 && reload_completed
7920    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7921        || (GET_CODE (operands[0]) == SUBREG
7922            && GET_CODE (SUBREG_REG (operands[0])) == REG
7923            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7924   [(set (match_dup 2) (match_dup 4))
7925    (set (match_dup 3) (match_dup 5))]
7926   "
7927 {
7928   int endian = (WORDS_BIG_ENDIAN == 0);
7929   long l[2];
7930   REAL_VALUE_TYPE rv;
7931
7932   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7933   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
7934
7935   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
7936   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
7937   operands[4] = gen_int_mode (l[endian], SImode);
7938   operands[5] = gen_int_mode (l[1 - endian], SImode);
7939 }")
7940
7941 (define_split
7942   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7943         (match_operand:DF 1 "easy_fp_constant" ""))]
7944   "TARGET_POWERPC64 && reload_completed
7945    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7946        || (GET_CODE (operands[0]) == SUBREG
7947            && GET_CODE (SUBREG_REG (operands[0])) == REG
7948            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7949   [(set (match_dup 2) (match_dup 3))]
7950   "
7951 {
7952   int endian = (WORDS_BIG_ENDIAN == 0);
7953   long l[2];
7954   REAL_VALUE_TYPE rv;
7955 #if HOST_BITS_PER_WIDE_INT >= 64
7956   HOST_WIDE_INT val;
7957 #endif
7958
7959   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7960   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
7961
7962   operands[2] = gen_lowpart (DImode, operands[0]);
7963   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
7964 #if HOST_BITS_PER_WIDE_INT >= 64
7965   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
7966          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
7967
7968   operands[3] = gen_int_mode (val, DImode);
7969 #else
7970   operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
7971 #endif
7972 }")
7973
7974 ;; Don't have reload use general registers to load a constant.  First,
7975 ;; it might not work if the output operand is the equivalent of
7976 ;; a non-offsettable memref, but also it is less efficient than loading
7977 ;; the constant into an FP register, since it will probably be used there.
7978 ;; The "??" is a kludge until we can figure out a more reasonable way
7979 ;; of handling these non-offsettable values.
7980 (define_insn "*movdf_hardfloat32"
7981   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,m,f,f,m,!r,!r,!r")
7982         (match_operand:DF 1 "input_operand" "r,m,r,f,m,f,G,H,F"))]
7983   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
7984    && (gpc_reg_operand (operands[0], DFmode)
7985        || gpc_reg_operand (operands[1], DFmode))"
7986   "*
7987 {
7988   switch (which_alternative)
7989     {
7990     default:
7991       abort ();
7992     case 0:
7993       /* We normally copy the low-numbered register first.  However, if
7994          the first register operand 0 is the same as the second register
7995          of operand 1, we must copy in the opposite order.  */
7996       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
7997         return \"mr %L0,%L1\;mr %0,%1\";
7998       else
7999         return \"mr %0,%1\;mr %L0,%L1\";
8000     case 1:
8001       if (offsettable_memref_p (operands[1])
8002           || (GET_CODE (operands[1]) == MEM
8003               && (GET_CODE (XEXP (operands[1], 0)) == LO_SUM
8004                   || GET_CODE (XEXP (operands[1], 0)) == PRE_INC
8005                   || GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)))
8006         {
8007           /* If the low-address word is used in the address, we must load
8008              it last.  Otherwise, load it first.  Note that we cannot have
8009              auto-increment in that case since the address register is
8010              known to be dead.  */
8011           if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8012                                  operands[1], 0))
8013             return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8014           else
8015             return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8016         }
8017       else
8018         {
8019           rtx addreg;
8020
8021           addreg = find_addr_reg (XEXP (operands[1], 0));
8022           if (refers_to_regno_p (REGNO (operands[0]),
8023                                  REGNO (operands[0]) + 1,
8024                                  operands[1], 0))
8025             {
8026               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8027               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
8028               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8029               return \"{lx|lwzx} %0,%1\";
8030             }
8031           else
8032             {
8033               output_asm_insn (\"{lx|lwzx} %0,%1\", operands);
8034               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8035               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
8036               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8037               return \"\";
8038             }
8039         }
8040     case 2:
8041       if (offsettable_memref_p (operands[0])
8042           || (GET_CODE (operands[0]) == MEM
8043               && (GET_CODE (XEXP (operands[0], 0)) == LO_SUM
8044                   || GET_CODE (XEXP (operands[0], 0)) == PRE_INC
8045                   || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)))
8046         return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8047       else
8048         {
8049           rtx addreg;
8050
8051           addreg = find_addr_reg (XEXP (operands[0], 0));
8052           output_asm_insn (\"{stx|stwx} %1,%0\", operands);
8053           output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8054           output_asm_insn (\"{stx|stwx} %L1,%0\", operands);
8055           output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8056           return \"\";
8057         }
8058     case 3:
8059       return \"fmr %0,%1\";
8060     case 4:
8061       return \"lfd%U1%X1 %0,%1\";
8062     case 5:
8063       return \"stfd%U0%X0 %1,%0\";
8064     case 6:
8065     case 7:
8066     case 8:
8067       return \"#\";
8068     }
8069 }"
8070   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,*,*")
8071    (set_attr "length" "8,16,16,4,4,4,8,12,16")])
8072
8073 (define_insn "*movdf_softfloat32"
8074   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
8075         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F"))]
8076   "! TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8077    && (gpc_reg_operand (operands[0], DFmode)
8078        || gpc_reg_operand (operands[1], DFmode))"
8079   "*
8080 {
8081   switch (which_alternative)
8082     {
8083     default:
8084       abort ();
8085     case 0:
8086       /* We normally copy the low-numbered register first.  However, if
8087          the first register operand 0 is the same as the second register of
8088          operand 1, we must copy in the opposite order.  */
8089       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8090         return \"mr %L0,%L1\;mr %0,%1\";
8091       else
8092         return \"mr %0,%1\;mr %L0,%L1\";
8093     case 1:
8094       /* If the low-address word is used in the address, we must load
8095          it last.  Otherwise, load it first.  Note that we cannot have
8096          auto-increment in that case since the address register is
8097          known to be dead.  */
8098       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8099                              operands[1], 0))
8100         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8101       else
8102         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8103     case 2:
8104       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8105     case 3:
8106     case 4:
8107     case 5:
8108       return \"#\";
8109     }
8110 }"
8111   [(set_attr "type" "*,load,store,*,*,*")
8112    (set_attr "length" "8,8,8,8,12,16")])
8113
8114 ; ld/std require word-aligned displacements -> 'Y' constraint.
8115 ; List Y->r and r->Y before r->r for reload.
8116 (define_insn "*movdf_hardfloat64"
8117   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,b,!r,f,f,m,!cl,!r,!r,!r,!r")
8118         (match_operand:DF 1 "input_operand" "r,Y,m,r,f,m,f,r,h,G,H,F"))]
8119   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8120    && (gpc_reg_operand (operands[0], DFmode)
8121        || gpc_reg_operand (operands[1], DFmode))"
8122   "@
8123    std%U0%X0 %1,%0
8124    ld%U1%X1 %0,%1
8125    #
8126    mr %0,%1
8127    fmr %0,%1
8128    lfd%U1%X1 %0,%1
8129    stfd%U0%X0 %1,%0
8130    mt%0 %1
8131    mf%1 %0
8132    #
8133    #
8134    #"
8135   [(set_attr "type" "store,load,load,*,fp,fpload,fpstore,mtjmpr,*,*,*,*")
8136    (set_attr "length" "4,4,8,4,4,4,4,4,4,8,12,16")])
8137
8138 (define_split
8139   [(set (match_operand:DF 0 "base_reg_operand" "")
8140         (match_operand:DF 1 "invalid_gpr_mem" ""))]
8141   "TARGET_POWERPC64 && no_new_pseudos"
8142   [(set (match_dup 2) (match_dup 3))
8143    (set (match_dup 0) (match_dup 4))]
8144   "
8145 {
8146   operands[2] = gen_rtx_REG (Pmode, REGNO (operands[0]));
8147   operands[3] = XEXP (operands[1], 0);
8148   operands[4] = replace_equiv_address (operands[1], operands[2]);
8149 }")
8150
8151 (define_expand "reload_outdf"
8152   [(parallel [(match_operand:DF 0 "invalid_gpr_mem" "")
8153               (match_operand:DF 1 "register_operand" "")
8154               (match_operand:DI 2 "register_operand" "=&b")])]
8155   "TARGET_POWERPC64"
8156 {
8157   if (!TARGET_64BIT)
8158     operands[2] = gen_rtx_REG (SImode, REGNO (operands[2]));
8159   emit_move_insn (operands[2], XEXP (operands[0], 0));
8160   operands[0] = replace_equiv_address (operands[0], operands[2]);
8161   emit_move_insn (operands[0], operands[1]);
8162   DONE;
8163 })
8164
8165 (define_expand "reload_indf"
8166   [(parallel [(match_operand:DF 0 "register_operand" "")
8167               (match_operand:DF 1 "invalid_gpr_mem" "")
8168               (match_operand:DI 2 "register_operand" "=&b")])]
8169   "TARGET_POWERPC64"
8170 {
8171   if (!TARGET_64BIT)
8172     operands[2] = gen_rtx_REG (SImode, REGNO (operands[2]));
8173   emit_move_insn (operands[2], XEXP (operands[1], 0));
8174   operands[1] = replace_equiv_address (operands[1], operands[2]);
8175   emit_move_insn (operands[0], operands[1]);
8176   DONE;
8177 })
8178
8179 (define_insn "*movdf_softfloat64"
8180   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,Y,r,cl,r,r,r,r,*h")
8181         (match_operand:DF 1 "input_operand" "Y,r,r,r,h,G,H,F,0"))]
8182   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8183    && (gpc_reg_operand (operands[0], DFmode)
8184        || gpc_reg_operand (operands[1], DFmode))"
8185   "@
8186    ld%U1%X1 %0,%1
8187    std%U0%X0 %1,%0
8188    mr %0,%1
8189    mt%0 %1
8190    mf%1 %0
8191    #
8192    #
8193    #
8194    nop"
8195   [(set_attr "type" "load,store,*,*,*,*,*,*,*")
8196    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
8197 \f
8198 (define_expand "movtf"
8199   [(set (match_operand:TF 0 "general_operand" "")
8200         (match_operand:TF 1 "any_operand" ""))]
8201   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8202    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8203   "{ rs6000_emit_move (operands[0], operands[1], TFmode); DONE; }")
8204
8205 ; It's important to list the o->f and f->o moves before f->f because
8206 ; otherwise reload, given m->f, will try to pick f->f and reload it,
8207 ; which doesn't make progress.
8208 (define_insn_and_split "*movtf_internal"
8209   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,f,rm,r")
8210         (match_operand:TF 1 "input_operand"         "f,o,f,r,mGHF"))]
8211   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8212    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
8213    && (gpc_reg_operand (operands[0], TFmode)
8214        || gpc_reg_operand (operands[1], TFmode))"
8215   "#"
8216   "&& reload_completed"
8217   [(pc)]
8218 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
8219   [(set_attr "length" "8,8,8,20,20")])
8220
8221 (define_expand "extenddftf2"
8222   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
8223                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
8224               (use (match_dup 2))])]
8225   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8226    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8227 {
8228   operands[2] = CONST0_RTX (DFmode);
8229 })
8230
8231 (define_insn_and_split "*extenddftf2_internal"
8232   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,&f,r")
8233        (float_extend:TF (match_operand:DF 1 "input_operand" "fr,mf,mf,rmGHF")))
8234    (use (match_operand:DF 2 "input_operand" "rf,m,f,n"))]
8235   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8236    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8237   "#"
8238   "&& reload_completed"
8239   [(pc)]
8240 {
8241   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8242   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8243   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
8244                   operands[1]);
8245   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
8246                   operands[2]);
8247   DONE;
8248 })  
8249
8250 (define_expand "extendsftf2"
8251   [(set (match_operand:TF 0 "nonimmediate_operand" "")
8252         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
8253   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8254    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8255 {
8256   rtx tmp = gen_reg_rtx (DFmode);
8257   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
8258   emit_insn (gen_extenddftf2 (operands[0], tmp));
8259   DONE;
8260 })
8261
8262 (define_expand "trunctfdf2"
8263   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8264         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))]
8265   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8266    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8267   "")
8268
8269 (define_insn_and_split "trunctfdf2_internal1"
8270   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,?f")
8271         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "0,f")))]
8272   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN) && !TARGET_XL_COMPAT
8273    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8274   "@
8275    #
8276    fmr %0,%1"
8277   "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
8278   [(const_int 0)]
8279 {
8280   emit_note (NOTE_INSN_DELETED);
8281   DONE;
8282 }
8283   [(set_attr "type" "fp")])
8284
8285 (define_insn "trunctfdf2_internal2"
8286   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8287         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8288   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN) && TARGET_XL_COMPAT
8289    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8290   "fadd %0,%1,%L1"
8291   [(set_attr "type" "fp")])
8292
8293 (define_insn_and_split "trunctfsf2"
8294   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
8295         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "f")))
8296    (clobber (match_scratch:DF 2 "=f"))]
8297   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8298    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8299   "#"
8300   "&& reload_completed"
8301   [(set (match_dup 2)
8302         (float_truncate:DF (match_dup 1)))
8303    (set (match_dup 0)
8304         (float_truncate:SF (match_dup 2)))]
8305   "")
8306
8307 (define_expand "floatsitf2"
8308   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8309         (float:TF (match_operand:SI 1 "gpc_reg_operand" "r")))]
8310   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8311    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8312 {
8313   rtx tmp = gen_reg_rtx (DFmode);
8314   expand_float (tmp, operands[1], false);
8315   emit_insn (gen_extenddftf2 (operands[0], tmp));
8316   DONE;
8317 })
8318
8319 ; fadd, but rounding towards zero.
8320 ; This is probably not the optimal code sequence.
8321 (define_insn "fix_trunc_helper"
8322   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8323         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "f")]
8324                    UNSPEC_FIX_TRUNC_TF))
8325    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&f"))]
8326   "TARGET_HARD_FLOAT && TARGET_FPRS"
8327   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
8328   [(set_attr "type" "fp")
8329    (set_attr "length" "20")])
8330
8331 (define_expand "fix_trunctfsi2"
8332   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
8333                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
8334               (clobber (match_dup 2))
8335               (clobber (match_dup 3))
8336               (clobber (match_dup 4))
8337               (clobber (match_dup 5))])]
8338   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8339    && (TARGET_POWER2 || TARGET_POWERPC)
8340    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8341 {
8342   operands[2] = gen_reg_rtx (DFmode);
8343   operands[3] = gen_reg_rtx (DFmode);
8344   operands[4] = gen_reg_rtx (DImode);
8345   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
8346 })
8347
8348 (define_insn_and_split "*fix_trunctfsi2_internal"
8349   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8350         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "f")))
8351    (clobber (match_operand:DF 2 "gpc_reg_operand" "=f"))
8352    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&f"))
8353    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))
8354    (clobber (match_operand:DI 5 "memory_operand" "=o"))]
8355   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8356    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8357   "#"
8358   "&& reload_completed"
8359   [(pc)]
8360 {
8361   rtx lowword;
8362   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
8363
8364   if (GET_CODE (operands[5]) != MEM)
8365     abort();
8366   lowword = XEXP (operands[5], 0);
8367   if (WORDS_BIG_ENDIAN)
8368     lowword = plus_constant (lowword, 4);
8369
8370   emit_insn (gen_fctiwz (operands[4], operands[2]));
8371   emit_move_insn (operands[5], operands[4]);
8372   emit_move_insn (operands[0], gen_rtx_MEM (SImode, lowword));
8373   DONE;
8374 })
8375
8376 (define_insn "negtf2"
8377   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8378         (neg: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 \"fneg %L0,%L1\;fneg %0,%1\";
8385   else
8386     return \"fneg %0,%1\;fneg %L0,%L1\";
8387 }"
8388   [(set_attr "type" "fp")
8389    (set_attr "length" "8")])
8390
8391 (define_expand "abstf2"
8392   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8393         (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   rtx label = gen_label_rtx ();
8399   emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
8400   emit_label (label);
8401   DONE;
8402 }")
8403
8404 (define_expand "abstf2_internal"
8405   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8406         (match_operand:TF 1 "gpc_reg_operand" "f"))
8407    (set (match_dup 3) (match_dup 5))
8408    (set (match_dup 5) (abs:DF (match_dup 5)))
8409    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
8410    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
8411                            (label_ref (match_operand 2 "" ""))
8412                            (pc)))
8413    (set (match_dup 6) (neg:DF (match_dup 6)))]
8414   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8415    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8416   "
8417 {
8418   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8419   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8420   operands[3] = gen_reg_rtx (DFmode);
8421   operands[4] = gen_reg_rtx (CCFPmode);
8422   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
8423   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
8424 }")
8425 \f
8426 ;; Next come the multi-word integer load and store and the load and store
8427 ;; multiple insns.
8428 (define_expand "movdi"
8429   [(set (match_operand:DI 0 "general_operand" "")
8430         (match_operand:DI 1 "any_operand" ""))]
8431   ""
8432   "{ rs6000_emit_move (operands[0], operands[1], DImode); DONE; }")
8433
8434 (define_insn "*movdi_internal32"
8435   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,f,f,m,r,r,r,r,r")
8436         (match_operand:DI 1 "input_operand" "r,m,r,f,m,f,IJK,n,G,H,F"))]
8437   "! TARGET_POWERPC64
8438    && (gpc_reg_operand (operands[0], DImode)
8439        || gpc_reg_operand (operands[1], DImode))"
8440   "*
8441 {
8442   switch (which_alternative)
8443     {
8444     default:
8445       abort ();
8446     case 0:
8447     case 1:
8448     case 2:
8449       return \"#\";
8450     case 3:
8451       return \"fmr %0,%1\";
8452     case 4:
8453       return \"lfd%U1%X1 %0,%1\";
8454     case 5:
8455       return \"stfd%U0%X0 %1,%0\";
8456     case 6:
8457     case 7:
8458     case 8:
8459     case 9:
8460     case 10:
8461       return \"#\";
8462     }
8463 }"
8464   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,*,*,*,*")])
8465
8466 (define_split
8467   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8468         (match_operand:DI 1 "const_int_operand" ""))]
8469   "! TARGET_POWERPC64 && reload_completed"
8470   [(set (match_dup 2) (match_dup 4))
8471    (set (match_dup 3) (match_dup 1))]
8472   "
8473 {
8474   HOST_WIDE_INT value = INTVAL (operands[1]);
8475   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8476                                        DImode);
8477   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8478                                        DImode);
8479 #if HOST_BITS_PER_WIDE_INT == 32
8480   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8481 #else
8482   operands[4] = GEN_INT (value >> 32);
8483   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8484 #endif
8485 }")
8486
8487 (define_split
8488   [(set (match_operand:DI 0 "nonimmediate_operand" "")
8489         (match_operand:DI 1 "input_operand" ""))]
8490   "reload_completed && !TARGET_POWERPC64 
8491    && gpr_or_gpr_p (operands[0], operands[1])"
8492   [(pc)]
8493 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8494
8495 (define_split
8496   [(set (match_operand:TI 0 "gpc_reg_operand" "")
8497         (match_operand:TI 1 "const_double_operand" ""))]
8498   "TARGET_POWERPC64"
8499   [(set (match_dup 2) (match_dup 4))
8500    (set (match_dup 3) (match_dup 5))]
8501   "
8502 {
8503   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8504                                        TImode);
8505   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8506                                        TImode);
8507   if (GET_CODE (operands[1]) == CONST_DOUBLE)
8508     {
8509       operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
8510       operands[5] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
8511     }
8512   else if (GET_CODE (operands[1]) == CONST_INT)
8513     {
8514       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
8515       operands[5] = operands[1];
8516     }
8517   else
8518     FAIL;
8519 }")
8520
8521 (define_insn "*movdi_internal64"
8522   [(set (match_operand:DI 0 "nonimmediate_operand" "=Y,r,b,r,r,r,r,r,??f,f,m,r,*h,*h")
8523         (match_operand:DI 1 "input_operand" "r,Y,m,r,I,L,nF,R,f,m,f,*h,r,0"))]
8524   "TARGET_POWERPC64
8525    && (gpc_reg_operand (operands[0], DImode)
8526        || gpc_reg_operand (operands[1], DImode))"
8527   "@
8528    std%U0%X0 %1,%0
8529    ld%U1%X1 %0,%1
8530    #
8531    mr %0,%1
8532    li %0,%1
8533    lis %0,%v1
8534    #
8535    {cal|la} %0,%a1
8536    fmr %0,%1
8537    lfd%U1%X1 %0,%1
8538    stfd%U0%X0 %1,%0
8539    mf%1 %0
8540    mt%0 %1
8541    {cror 0,0,0|nop}"
8542   [(set_attr "type" "store,load,load,*,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*")
8543    (set_attr "length" "4,4,8,4,4,4,20,4,4,4,4,4,4,4")])
8544
8545 (define_split
8546   [(set (match_operand:DI 0 "base_reg_operand" "")
8547         (match_operand:DI 1 "invalid_gpr_mem" ""))]
8548   "TARGET_POWERPC64 && no_new_pseudos"
8549   [(set (match_dup 2) (match_dup 3))
8550    (set (match_dup 0) (match_dup 4))]
8551   "
8552 {
8553   operands[2] = operands[0];
8554   if (!TARGET_64BIT)
8555     operands[2] = gen_rtx_REG (SImode, REGNO (operands[0]));
8556   operands[3] = XEXP (operands[1], 0);
8557   operands[4] = replace_equiv_address (operands[1], operands[2]);
8558 }")
8559
8560 (define_expand "reload_outdi"
8561   [(parallel [(match_operand:DI 0 "invalid_gpr_mem" "")
8562               (match_operand:DI 1 "register_operand" "")
8563               (match_operand:DI 2 "register_operand" "=&b")])]
8564   "TARGET_POWERPC64"
8565 {
8566   if (!TARGET_64BIT)
8567     operands[2] = gen_rtx_REG (SImode, REGNO (operands[2]));
8568   emit_move_insn (operands[2], XEXP (operands[0], 0));
8569   operands[0] = replace_equiv_address (operands[0], operands[2]);
8570   emit_move_insn (operands[0], operands[1]);
8571   DONE;
8572 })
8573
8574 (define_expand "reload_indi"
8575   [(parallel [(match_operand:DI 0 "register_operand" "")
8576               (match_operand:DI 1 "invalid_gpr_mem" "")
8577               (match_operand:DI 2 "register_operand" "=&b")])]
8578   "TARGET_POWERPC64"
8579 {
8580   if (!TARGET_64BIT)
8581     operands[2] = gen_rtx_REG (SImode, REGNO (operands[2]));
8582   emit_move_insn (operands[2], XEXP (operands[1], 0));
8583   operands[1] = replace_equiv_address (operands[1], operands[2]);
8584   emit_move_insn (operands[0], operands[1]);
8585   DONE;
8586 })
8587
8588 ;; immediate value valid for a single instruction hiding in a const_double
8589 (define_insn ""
8590   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8591         (match_operand:DI 1 "const_double_operand" "F"))]
8592   "HOST_BITS_PER_WIDE_INT == 32 && TARGET_POWERPC64
8593    && GET_CODE (operands[1]) == CONST_DOUBLE
8594    && num_insns_constant (operands[1], DImode) == 1"
8595   "*
8596 {
8597   return ((unsigned HOST_WIDE_INT)
8598           (CONST_DOUBLE_LOW (operands[1]) + 0x8000) < 0x10000)
8599          ? \"li %0,%1\" : \"lis %0,%v1\";
8600 }")
8601
8602 ;; Generate all one-bits and clear left or right.
8603 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
8604 (define_split
8605   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8606         (match_operand:DI 1 "mask64_operand" ""))]
8607   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8608   [(set (match_dup 0) (const_int -1))
8609    (set (match_dup 0)
8610         (and:DI (rotate:DI (match_dup 0)
8611                            (const_int 0))
8612                 (match_dup 1)))]
8613   "")
8614
8615 ;; Split a load of a large constant into the appropriate five-instruction
8616 ;; sequence.  Handle anything in a constant number of insns.
8617 ;; When non-easy constants can go in the TOC, this should use
8618 ;; easy_fp_constant predicate.
8619 (define_split
8620   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8621         (match_operand:DI 1 "const_int_operand" ""))]
8622   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8623   [(set (match_dup 0) (match_dup 2))
8624    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8625   "
8626 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8627
8628   if (tem == operands[0])
8629     DONE;
8630   else
8631     FAIL;
8632 }")
8633
8634 (define_split
8635   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8636         (match_operand:DI 1 "const_double_operand" ""))]
8637   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8638   [(set (match_dup 0) (match_dup 2))
8639    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8640   "
8641 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8642
8643   if (tem == operands[0])
8644     DONE;
8645   else
8646     FAIL;
8647 }")
8648
8649 (define_insn "*movdi_internal2"
8650   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
8651         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "0,r,r")
8652                     (const_int 0)))
8653    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
8654   "TARGET_64BIT"
8655   "@
8656    cmpdi %2,%0,0
8657    mr. %0,%1
8658    #"
8659   [(set_attr "type" "cmp,compare,cmp")
8660    (set_attr "length" "4,4,8")])
8661
8662 (define_split
8663   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
8664         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "")
8665                     (const_int 0)))
8666    (set (match_operand:DI 0 "gpc_reg_operand" "") (match_dup 1))]
8667   "TARGET_POWERPC64 && reload_completed"
8668   [(set (match_dup 0) (match_dup 1))
8669    (set (match_dup 2)
8670         (compare:CC (match_dup 0)
8671                     (const_int 0)))]
8672   "")
8673 \f
8674 ;; TImode is similar, except that we usually want to compute the address into
8675 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
8676 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
8677 (define_expand "movti"
8678   [(parallel [(set (match_operand:TI 0 "general_operand" "")
8679                    (match_operand:TI 1 "general_operand" ""))
8680               (clobber (scratch:SI))])]
8681   ""
8682   "{ rs6000_emit_move (operands[0], operands[1], TImode); DONE; }")
8683
8684 ;; We say that MQ is clobbered in the last alternative because the first
8685 ;; alternative would never get used otherwise since it would need a reload
8686 ;; while the 2nd alternative would not.  We put memory cases first so they
8687 ;; are preferred.  Otherwise, we'd try to reload the output instead of
8688 ;; giving the SCRATCH mq.
8689
8690 (define_insn "*movti_power"
8691   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r")
8692         (match_operand:TI 1 "reg_or_mem_operand" "r,r,r,Q,m"))
8693    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X"))]
8694   "TARGET_POWER && ! TARGET_POWERPC64 
8695    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8696   "*
8697 {
8698   switch (which_alternative)
8699     {
8700     default:
8701       abort ();
8702
8703     case 0:
8704       if (TARGET_STRING)
8705         return \"{stsi|stswi} %1,%P0,16\";
8706     case 1:
8707     case 2:
8708       return \"#\";
8709     case 3:
8710       /* If the address is not used in the output, we can use lsi.  Otherwise,
8711          fall through to generating four loads.  */
8712       if (TARGET_STRING
8713           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8714         return \"{lsi|lswi} %0,%P1,16\";
8715       /* ... fall through ...  */
8716     case 4:
8717       return \"#\";
8718     }
8719 }"
8720   [(set_attr "type" "store,store,*,load,load")])
8721
8722 (define_insn "*movti_string"
8723   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r")
8724         (match_operand:TI 1 "reg_or_mem_operand" "r,r,r,Q,m"))]
8725   "! TARGET_POWER && ! TARGET_POWERPC64
8726    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8727   "*
8728 {
8729   switch (which_alternative)
8730     {
8731     default:
8732       abort ();
8733     case 0:
8734       if (TARGET_STRING)
8735         return \"{stsi|stswi} %1,%P0,16\";
8736     case 1:
8737     case 2:
8738       return \"#\";
8739     case 3:
8740       /* If the address is not used in the output, we can use lsi.  Otherwise,
8741          fall through to generating four loads.  */
8742       if (TARGET_STRING  
8743           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8744         return \"{lsi|lswi} %0,%P1,16\";
8745       /* ... fall through ...  */
8746     case 4:
8747       return \"#\";
8748     }
8749 }"
8750   [(set_attr "type" "store,store,*,load,load")])
8751
8752 (define_insn "*movti_ppc64"
8753   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,m,r")
8754         (match_operand:TI 1 "input_operand" "r,r,o"))]
8755   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
8756    || gpc_reg_operand (operands[1], TImode))"
8757   "@
8758    #    
8759    #    
8760    #"
8761   [(set_attr "type" "*,load,store")])
8762
8763 (define_split
8764   [(set (match_operand:TI 0 "nonimmediate_operand" "")
8765         (match_operand:TI 1 "input_operand" ""))]
8766   "reload_completed
8767    && gpr_or_gpr_p (operands[0], operands[1])"
8768   [(pc)]
8769 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8770 \f
8771 (define_expand "load_multiple"
8772   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8773                           (match_operand:SI 1 "" ""))
8774                      (use (match_operand:SI 2 "" ""))])]
8775   "TARGET_STRING && !TARGET_POWERPC64"
8776   "
8777 {
8778   int regno;
8779   int count;
8780   rtx op1;
8781   int i;
8782
8783   /* Support only loading a constant number of fixed-point registers from
8784      memory and only bother with this if more than two; the machine
8785      doesn't support more than eight.  */
8786   if (GET_CODE (operands[2]) != CONST_INT
8787       || INTVAL (operands[2]) <= 2
8788       || INTVAL (operands[2]) > 8
8789       || GET_CODE (operands[1]) != MEM
8790       || GET_CODE (operands[0]) != REG
8791       || REGNO (operands[0]) >= 32)
8792     FAIL;
8793
8794   count = INTVAL (operands[2]);
8795   regno = REGNO (operands[0]);
8796
8797   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
8798   op1 = replace_equiv_address (operands[1],
8799                                force_reg (SImode, XEXP (operands[1], 0)));
8800
8801   for (i = 0; i < count; i++)
8802     XVECEXP (operands[3], 0, i)
8803       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
8804                      adjust_address_nv (op1, SImode, i * 4));
8805 }")
8806
8807 (define_insn "*ldmsi8"
8808   [(match_parallel 0 "load_multiple_operation"
8809     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8810           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8811      (set (match_operand:SI 3 "gpc_reg_operand" "")
8812           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8813      (set (match_operand:SI 4 "gpc_reg_operand" "")
8814           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8815      (set (match_operand:SI 5 "gpc_reg_operand" "")
8816           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8817      (set (match_operand:SI 6 "gpc_reg_operand" "")
8818           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8819      (set (match_operand:SI 7 "gpc_reg_operand" "")
8820           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8821      (set (match_operand:SI 8 "gpc_reg_operand" "")
8822           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
8823      (set (match_operand:SI 9 "gpc_reg_operand" "")
8824           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
8825   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
8826   "*
8827 { return rs6000_output_load_multiple (operands); }"
8828   [(set_attr "type" "load")
8829    (set_attr "length" "32")])
8830
8831 (define_insn "*ldmsi7"
8832   [(match_parallel 0 "load_multiple_operation"
8833     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8834           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8835      (set (match_operand:SI 3 "gpc_reg_operand" "")
8836           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8837      (set (match_operand:SI 4 "gpc_reg_operand" "")
8838           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8839      (set (match_operand:SI 5 "gpc_reg_operand" "")
8840           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8841      (set (match_operand:SI 6 "gpc_reg_operand" "")
8842           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8843      (set (match_operand:SI 7 "gpc_reg_operand" "")
8844           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8845      (set (match_operand:SI 8 "gpc_reg_operand" "")
8846           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
8847   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
8848   "*
8849 { return rs6000_output_load_multiple (operands); }"
8850   [(set_attr "type" "load")
8851    (set_attr "length" "32")])
8852
8853 (define_insn "*ldmsi6"
8854   [(match_parallel 0 "load_multiple_operation"
8855     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8856           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8857      (set (match_operand:SI 3 "gpc_reg_operand" "")
8858           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8859      (set (match_operand:SI 4 "gpc_reg_operand" "")
8860           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8861      (set (match_operand:SI 5 "gpc_reg_operand" "")
8862           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8863      (set (match_operand:SI 6 "gpc_reg_operand" "")
8864           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8865      (set (match_operand:SI 7 "gpc_reg_operand" "")
8866           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
8867   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
8868   "*
8869 { return rs6000_output_load_multiple (operands); }"
8870   [(set_attr "type" "load")
8871    (set_attr "length" "32")])
8872
8873 (define_insn "*ldmsi5"
8874   [(match_parallel 0 "load_multiple_operation"
8875     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8876           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8877      (set (match_operand:SI 3 "gpc_reg_operand" "")
8878           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8879      (set (match_operand:SI 4 "gpc_reg_operand" "")
8880           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8881      (set (match_operand:SI 5 "gpc_reg_operand" "")
8882           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8883      (set (match_operand:SI 6 "gpc_reg_operand" "")
8884           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
8885   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
8886   "*
8887 { return rs6000_output_load_multiple (operands); }"
8888   [(set_attr "type" "load")
8889    (set_attr "length" "32")])
8890
8891 (define_insn "*ldmsi4"
8892   [(match_parallel 0 "load_multiple_operation"
8893     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8894           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8895      (set (match_operand:SI 3 "gpc_reg_operand" "")
8896           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8897      (set (match_operand:SI 4 "gpc_reg_operand" "")
8898           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8899      (set (match_operand:SI 5 "gpc_reg_operand" "")
8900           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
8901   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
8902   "*
8903 { return rs6000_output_load_multiple (operands); }"
8904   [(set_attr "type" "load")
8905    (set_attr "length" "32")])
8906
8907 (define_insn "*ldmsi3"
8908   [(match_parallel 0 "load_multiple_operation"
8909     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8910           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8911      (set (match_operand:SI 3 "gpc_reg_operand" "")
8912           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8913      (set (match_operand:SI 4 "gpc_reg_operand" "")
8914           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
8915   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
8916   "*
8917 { return rs6000_output_load_multiple (operands); }"
8918   [(set_attr "type" "load")
8919    (set_attr "length" "32")])
8920
8921 (define_expand "store_multiple"
8922   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8923                           (match_operand:SI 1 "" ""))
8924                      (clobber (scratch:SI))
8925                      (use (match_operand:SI 2 "" ""))])]
8926   "TARGET_STRING && !TARGET_POWERPC64"
8927   "
8928 {
8929   int regno;
8930   int count;
8931   rtx to;
8932   rtx op0;
8933   int i;
8934
8935   /* Support only storing a constant number of fixed-point registers to
8936      memory and only bother with this if more than two; the machine
8937      doesn't support more than eight.  */
8938   if (GET_CODE (operands[2]) != CONST_INT
8939       || INTVAL (operands[2]) <= 2
8940       || INTVAL (operands[2]) > 8
8941       || GET_CODE (operands[0]) != MEM
8942       || GET_CODE (operands[1]) != REG
8943       || REGNO (operands[1]) >= 32)
8944     FAIL;
8945
8946   count = INTVAL (operands[2]);
8947   regno = REGNO (operands[1]);
8948
8949   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
8950   to = force_reg (SImode, XEXP (operands[0], 0));
8951   op0 = replace_equiv_address (operands[0], to);
8952
8953   XVECEXP (operands[3], 0, 0)
8954     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
8955   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
8956                                                  gen_rtx_SCRATCH (SImode));
8957
8958   for (i = 1; i < count; i++)
8959     XVECEXP (operands[3], 0, i + 1)
8960       = gen_rtx_SET (VOIDmode,
8961                      adjust_address_nv (op0, SImode, i * 4),
8962                      gen_rtx_REG (SImode, regno + i));
8963 }")
8964
8965 (define_insn "*store_multiple_power"
8966   [(match_parallel 0 "store_multiple_operation"
8967                    [(set (match_operand:SI 1 "indirect_operand" "=Q")
8968                          (match_operand:SI 2 "gpc_reg_operand" "r"))
8969                     (clobber (match_scratch:SI 3 "=q"))])]
8970   "TARGET_STRING && TARGET_POWER"
8971   "{stsi|stswi} %2,%P1,%O0"
8972   [(set_attr "type" "store")])
8973
8974 (define_insn "*stmsi8"
8975   [(match_parallel 0 "store_multiple_operation"
8976     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8977           (match_operand:SI 2 "gpc_reg_operand" "r"))
8978      (clobber (match_scratch:SI 3 "X"))
8979      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8980           (match_operand:SI 4 "gpc_reg_operand" "r"))
8981      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8982           (match_operand:SI 5 "gpc_reg_operand" "r"))
8983      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8984           (match_operand:SI 6 "gpc_reg_operand" "r"))
8985      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8986           (match_operand:SI 7 "gpc_reg_operand" "r"))
8987      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8988           (match_operand:SI 8 "gpc_reg_operand" "r"))
8989      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
8990           (match_operand:SI 9 "gpc_reg_operand" "r"))
8991      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
8992           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
8993   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 9"
8994   "{stsi|stswi} %2,%1,%O0"
8995   [(set_attr "type" "store")])
8996
8997 (define_insn "*stmsi7"
8998   [(match_parallel 0 "store_multiple_operation"
8999     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9000           (match_operand:SI 2 "gpc_reg_operand" "r"))
9001      (clobber (match_scratch:SI 3 "X"))
9002      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9003           (match_operand:SI 4 "gpc_reg_operand" "r"))
9004      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9005           (match_operand:SI 5 "gpc_reg_operand" "r"))
9006      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9007           (match_operand:SI 6 "gpc_reg_operand" "r"))
9008      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9009           (match_operand:SI 7 "gpc_reg_operand" "r"))
9010      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9011           (match_operand:SI 8 "gpc_reg_operand" "r"))
9012      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9013           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
9014   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 8"
9015   "{stsi|stswi} %2,%1,%O0"
9016   [(set_attr "type" "store")])
9017
9018 (define_insn "*stmsi6"
9019   [(match_parallel 0 "store_multiple_operation"
9020     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9021           (match_operand:SI 2 "gpc_reg_operand" "r"))
9022      (clobber (match_scratch:SI 3 "X"))
9023      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9024           (match_operand:SI 4 "gpc_reg_operand" "r"))
9025      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9026           (match_operand:SI 5 "gpc_reg_operand" "r"))
9027      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9028           (match_operand:SI 6 "gpc_reg_operand" "r"))
9029      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9030           (match_operand:SI 7 "gpc_reg_operand" "r"))
9031      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9032           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
9033   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 7"
9034   "{stsi|stswi} %2,%1,%O0"
9035   [(set_attr "type" "store")])
9036
9037 (define_insn "*stmsi5"
9038   [(match_parallel 0 "store_multiple_operation"
9039     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9040           (match_operand:SI 2 "gpc_reg_operand" "r"))
9041      (clobber (match_scratch:SI 3 "X"))
9042      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9043           (match_operand:SI 4 "gpc_reg_operand" "r"))
9044      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9045           (match_operand:SI 5 "gpc_reg_operand" "r"))
9046      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9047           (match_operand:SI 6 "gpc_reg_operand" "r"))
9048      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9049           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
9050   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 6"
9051   "{stsi|stswi} %2,%1,%O0"
9052   [(set_attr "type" "store")])
9053
9054 (define_insn "*stmsi4"
9055   [(match_parallel 0 "store_multiple_operation"
9056     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9057           (match_operand:SI 2 "gpc_reg_operand" "r"))
9058      (clobber (match_scratch:SI 3 "X"))
9059      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9060           (match_operand:SI 4 "gpc_reg_operand" "r"))
9061      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9062           (match_operand:SI 5 "gpc_reg_operand" "r"))
9063      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9064           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
9065   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 5"
9066   "{stsi|stswi} %2,%1,%O0"
9067   [(set_attr "type" "store")])
9068
9069 (define_insn "*stmsi3"
9070   [(match_parallel 0 "store_multiple_operation"
9071     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9072           (match_operand:SI 2 "gpc_reg_operand" "r"))
9073      (clobber (match_scratch:SI 3 "X"))
9074      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9075           (match_operand:SI 4 "gpc_reg_operand" "r"))
9076      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9077           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
9078   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 4"
9079   "{stsi|stswi} %2,%1,%O0"
9080   [(set_attr "type" "store")])
9081 \f
9082 ;; String/block move insn.
9083 ;; Argument 0 is the destination
9084 ;; Argument 1 is the source
9085 ;; Argument 2 is the length
9086 ;; Argument 3 is the alignment
9087
9088 (define_expand "movstrsi"
9089   [(parallel [(set (match_operand:BLK 0 "" "")
9090                    (match_operand:BLK 1 "" ""))
9091               (use (match_operand:SI 2 "" ""))
9092               (use (match_operand:SI 3 "" ""))])]
9093   ""
9094   "
9095 {
9096   if (expand_block_move (operands))
9097     DONE;
9098   else
9099     FAIL;
9100 }")
9101
9102 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
9103 ;; register allocator doesn't have a clue about allocating 8 word registers.
9104 ;; rD/rS = r5 is preferred, efficient form.
9105 (define_expand "movstrsi_8reg"
9106   [(parallel [(set (match_operand 0 "" "")
9107                    (match_operand 1 "" ""))
9108               (use (match_operand 2 "" ""))
9109               (use (match_operand 3 "" ""))
9110               (clobber (reg:SI  5))
9111               (clobber (reg:SI  6))
9112               (clobber (reg:SI  7))
9113               (clobber (reg:SI  8))
9114               (clobber (reg:SI  9))
9115               (clobber (reg:SI 10))
9116               (clobber (reg:SI 11))
9117               (clobber (reg:SI 12))
9118               (clobber (match_scratch:SI 4 ""))])]
9119   "TARGET_STRING"
9120   "")
9121
9122 (define_insn ""
9123   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9124         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9125    (use (match_operand:SI 2 "immediate_operand" "i"))
9126    (use (match_operand:SI 3 "immediate_operand" "i"))
9127    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9128    (clobber (reg:SI  6))
9129    (clobber (reg:SI  7))
9130    (clobber (reg:SI  8))
9131    (clobber (reg:SI  9))
9132    (clobber (reg:SI 10))
9133    (clobber (reg:SI 11))
9134    (clobber (reg:SI 12))
9135    (clobber (match_scratch:SI 5 "=q"))]
9136   "TARGET_STRING && TARGET_POWER
9137    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9138        || INTVAL (operands[2]) == 0)
9139    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9140    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9141    && REGNO (operands[4]) == 5"
9142   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9143   [(set_attr "type" "load")
9144    (set_attr "length" "8")])
9145
9146 (define_insn ""
9147   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9148         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9149    (use (match_operand:SI 2 "immediate_operand" "i"))
9150    (use (match_operand:SI 3 "immediate_operand" "i"))
9151    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9152    (clobber (reg:SI  6))
9153    (clobber (reg:SI  7))
9154    (clobber (reg:SI  8))
9155    (clobber (reg:SI  9))
9156    (clobber (reg:SI 10))
9157    (clobber (reg:SI 11))
9158    (clobber (reg:SI 12))
9159    (clobber (match_scratch:SI 5 "X"))]
9160   "TARGET_STRING && ! TARGET_POWER
9161    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9162        || INTVAL (operands[2]) == 0)
9163    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9164    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9165    && REGNO (operands[4]) == 5"
9166   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9167   [(set_attr "type" "load")
9168    (set_attr "length" "8")])
9169
9170 (define_insn ""
9171   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9172         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9173    (use (match_operand:SI 2 "immediate_operand" "i"))
9174    (use (match_operand:SI 3 "immediate_operand" "i"))
9175    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9176    (clobber (reg:SI  6))
9177    (clobber (reg:SI  7))
9178    (clobber (reg:SI  8))
9179    (clobber (reg:SI  9))
9180    (clobber (reg:SI 10))
9181    (clobber (reg:SI 11))
9182    (clobber (reg:SI 12))
9183    (clobber (match_scratch:SI 5 "X"))]
9184   "TARGET_STRING && TARGET_POWERPC64
9185    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9186        || INTVAL (operands[2]) == 0)
9187    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9188    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9189    && REGNO (operands[4]) == 5"
9190   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9191   [(set_attr "type" "load")
9192    (set_attr "length" "8")])
9193
9194 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
9195 ;; register allocator doesn't have a clue about allocating 6 word registers.
9196 ;; rD/rS = r5 is preferred, efficient form.
9197 (define_expand "movstrsi_6reg"
9198   [(parallel [(set (match_operand 0 "" "")
9199                    (match_operand 1 "" ""))
9200               (use (match_operand 2 "" ""))
9201               (use (match_operand 3 "" ""))
9202               (clobber (reg:SI  5))
9203               (clobber (reg:SI  6))
9204               (clobber (reg:SI  7))
9205               (clobber (reg:SI  8))
9206               (clobber (reg:SI  9))
9207               (clobber (reg:SI 10))
9208               (clobber (match_scratch:SI 4 ""))])]
9209   "TARGET_STRING"
9210   "")
9211
9212 (define_insn ""
9213   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9214         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9215    (use (match_operand:SI 2 "immediate_operand" "i"))
9216    (use (match_operand:SI 3 "immediate_operand" "i"))
9217    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9218    (clobber (reg:SI  6))
9219    (clobber (reg:SI  7))
9220    (clobber (reg:SI  8))
9221    (clobber (reg:SI  9))
9222    (clobber (reg:SI 10))
9223    (clobber (match_scratch:SI 5 "=q"))]
9224   "TARGET_STRING && TARGET_POWER
9225    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
9226    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9227    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9228    && REGNO (operands[4]) == 5"
9229   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9230   [(set_attr "type" "load")
9231    (set_attr "length" "8")])
9232
9233 (define_insn ""
9234   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9235         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9236    (use (match_operand:SI 2 "immediate_operand" "i"))
9237    (use (match_operand:SI 3 "immediate_operand" "i"))
9238    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9239    (clobber (reg:SI  6))
9240    (clobber (reg:SI  7))
9241    (clobber (reg:SI  8))
9242    (clobber (reg:SI  9))
9243    (clobber (reg:SI 10))
9244    (clobber (match_scratch:SI 5 "X"))]
9245   "TARGET_STRING && ! TARGET_POWER
9246    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9247    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9248    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9249    && REGNO (operands[4]) == 5"
9250   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9251   [(set_attr "type" "load")
9252    (set_attr "length" "8")])
9253
9254 (define_insn ""
9255   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9256         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9257    (use (match_operand:SI 2 "immediate_operand" "i"))
9258    (use (match_operand:SI 3 "immediate_operand" "i"))
9259    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9260    (clobber (reg:SI  6))
9261    (clobber (reg:SI  7))
9262    (clobber (reg:SI  8))
9263    (clobber (reg:SI  9))
9264    (clobber (reg:SI 10))
9265    (clobber (match_scratch:SI 5 "X"))]
9266   "TARGET_STRING && TARGET_POWERPC64
9267    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9268    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9269    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9270    && REGNO (operands[4]) == 5"
9271   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9272   [(set_attr "type" "load")
9273    (set_attr "length" "8")])
9274
9275 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
9276 ;; problems with TImode.
9277 ;; rD/rS = r5 is preferred, efficient form.
9278 (define_expand "movstrsi_4reg"
9279   [(parallel [(set (match_operand 0 "" "")
9280                    (match_operand 1 "" ""))
9281               (use (match_operand 2 "" ""))
9282               (use (match_operand 3 "" ""))
9283               (clobber (reg:SI 5))
9284               (clobber (reg:SI 6))
9285               (clobber (reg:SI 7))
9286               (clobber (reg:SI 8))
9287               (clobber (match_scratch:SI 4 ""))])]
9288   "TARGET_STRING"
9289   "")
9290
9291 (define_insn ""
9292   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9293         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9294    (use (match_operand:SI 2 "immediate_operand" "i"))
9295    (use (match_operand:SI 3 "immediate_operand" "i"))
9296    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9297    (clobber (reg:SI 6))
9298    (clobber (reg:SI 7))
9299    (clobber (reg:SI 8))
9300    (clobber (match_scratch:SI 5 "=q"))]
9301   "TARGET_STRING && TARGET_POWER
9302    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9303    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9304    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9305    && REGNO (operands[4]) == 5"
9306   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9307   [(set_attr "type" "load")
9308    (set_attr "length" "8")])
9309
9310 (define_insn ""
9311   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9312         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9313    (use (match_operand:SI 2 "immediate_operand" "i"))
9314    (use (match_operand:SI 3 "immediate_operand" "i"))
9315    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9316    (clobber (reg:SI 6))
9317    (clobber (reg:SI 7))
9318    (clobber (reg:SI 8))
9319    (clobber (match_scratch:SI 5 "X"))]
9320   "TARGET_STRING && ! TARGET_POWER
9321    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9322    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9323    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9324    && REGNO (operands[4]) == 5"
9325   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9326   [(set_attr "type" "load")
9327    (set_attr "length" "8")])
9328
9329 (define_insn ""
9330   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9331         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9332    (use (match_operand:SI 2 "immediate_operand" "i"))
9333    (use (match_operand:SI 3 "immediate_operand" "i"))
9334    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9335    (clobber (reg:SI 6))
9336    (clobber (reg:SI 7))
9337    (clobber (reg:SI 8))
9338    (clobber (match_scratch:SI 5 "X"))]
9339   "TARGET_STRING && TARGET_POWERPC64
9340    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9341    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9342    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9343    && REGNO (operands[4]) == 5"
9344   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9345   [(set_attr "type" "load")
9346    (set_attr "length" "8")])
9347
9348 ;; Move up to 8 bytes at a time.
9349 (define_expand "movstrsi_2reg"
9350   [(parallel [(set (match_operand 0 "" "")
9351                    (match_operand 1 "" ""))
9352               (use (match_operand 2 "" ""))
9353               (use (match_operand 3 "" ""))
9354               (clobber (match_scratch:DI 4 ""))
9355               (clobber (match_scratch:SI 5 ""))])]
9356   "TARGET_STRING && ! TARGET_POWERPC64"
9357   "")
9358
9359 (define_insn ""
9360   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9361         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9362    (use (match_operand:SI 2 "immediate_operand" "i"))
9363    (use (match_operand:SI 3 "immediate_operand" "i"))
9364    (clobber (match_scratch:DI 4 "=&r"))
9365    (clobber (match_scratch:SI 5 "=q"))]
9366   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
9367    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9368   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9369   [(set_attr "type" "load")
9370    (set_attr "length" "8")])
9371
9372 (define_insn ""
9373   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9374         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9375    (use (match_operand:SI 2 "immediate_operand" "i"))
9376    (use (match_operand:SI 3 "immediate_operand" "i"))
9377    (clobber (match_scratch:DI 4 "=&r"))
9378    (clobber (match_scratch:SI 5 "X"))]
9379   "TARGET_STRING && ! TARGET_POWER && ! TARGET_POWERPC64
9380    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9381   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9382   [(set_attr "type" "load")
9383    (set_attr "length" "8")])
9384
9385 ;; Move up to 4 bytes at a time.
9386 (define_expand "movstrsi_1reg"
9387   [(parallel [(set (match_operand 0 "" "")
9388                    (match_operand 1 "" ""))
9389               (use (match_operand 2 "" ""))
9390               (use (match_operand 3 "" ""))
9391               (clobber (match_scratch:SI 4 ""))
9392               (clobber (match_scratch:SI 5 ""))])]
9393   "TARGET_STRING"
9394   "")
9395
9396 (define_insn ""
9397   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9398         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9399    (use (match_operand:SI 2 "immediate_operand" "i"))
9400    (use (match_operand:SI 3 "immediate_operand" "i"))
9401    (clobber (match_scratch:SI 4 "=&r"))
9402    (clobber (match_scratch:SI 5 "=q"))]
9403   "TARGET_STRING && TARGET_POWER
9404    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9405   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9406   [(set_attr "type" "load")
9407    (set_attr "length" "8")])
9408
9409 (define_insn ""
9410   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9411         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9412    (use (match_operand:SI 2 "immediate_operand" "i"))
9413    (use (match_operand:SI 3 "immediate_operand" "i"))
9414    (clobber (match_scratch:SI 4 "=&r"))
9415    (clobber (match_scratch:SI 5 "X"))]
9416   "TARGET_STRING && ! TARGET_POWER
9417    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9418   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9419   [(set_attr "type" "load")
9420    (set_attr "length" "8")])
9421
9422 (define_insn ""
9423   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9424         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9425    (use (match_operand:SI 2 "immediate_operand" "i"))
9426    (use (match_operand:SI 3 "immediate_operand" "i"))
9427    (clobber (match_scratch:SI 4 "=&r"))
9428    (clobber (match_scratch:SI 5 "X"))]
9429   "TARGET_STRING && TARGET_POWERPC64
9430    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9431   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9432   [(set_attr "type" "load")
9433    (set_attr "length" "8")])
9434
9435 \f
9436 ;; Define insns that do load or store with update.  Some of these we can
9437 ;; get by using pre-decrement or pre-increment, but the hardware can also
9438 ;; do cases where the increment is not the size of the object.
9439 ;;
9440 ;; In all these cases, we use operands 0 and 1 for the register being
9441 ;; incremented because those are the operands that local-alloc will
9442 ;; tie and these are the pair most likely to be tieable (and the ones
9443 ;; that will benefit the most).
9444
9445 (define_insn "*movdi_update1"
9446   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
9447         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9448                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
9449    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9450         (plus:DI (match_dup 1) (match_dup 2)))]
9451   "TARGET_POWERPC64 && TARGET_UPDATE"
9452   "@
9453    ldux %3,%0,%2
9454    ldu %3,%2(%0)"
9455   [(set_attr "type" "load_ux,load_u")])
9456
9457 (define_insn "movdi_update"
9458   [(set (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9459                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I")))
9460         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
9461    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9462         (plus:DI (match_dup 1) (match_dup 2)))]
9463   "TARGET_POWERPC64 && TARGET_UPDATE"
9464   "@
9465    stdux %3,%0,%2
9466    stdu %3,%2(%0)"
9467   [(set_attr "type" "store_ux,store_u")])
9468
9469 (define_insn "*movsi_update1"
9470   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9471         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9472                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9473    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9474         (plus:SI (match_dup 1) (match_dup 2)))]
9475   "TARGET_UPDATE"
9476   "@
9477    {lux|lwzux} %3,%0,%2
9478    {lu|lwzu} %3,%2(%0)"
9479   [(set_attr "type" "load_ux,load_u")])
9480
9481 (define_insn "*movsi_update2"
9482   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
9483         (sign_extend:DI
9484          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
9485                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
9486    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
9487         (plus:DI (match_dup 1) (match_dup 2)))]
9488   "TARGET_POWERPC64"
9489   "lwaux %3,%0,%2"
9490   [(set_attr "type" "load_ext_ux")])
9491
9492 (define_insn "movsi_update"
9493   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9494                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9495         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
9496    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9497         (plus:SI (match_dup 1) (match_dup 2)))]
9498   "TARGET_UPDATE"
9499   "@
9500    {stux|stwux} %3,%0,%2
9501    {stu|stwu} %3,%2(%0)"
9502   [(set_attr "type" "store_ux,store_u")])
9503
9504 (define_insn "*movhi_update1"
9505   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
9506         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9507                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9508    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9509         (plus:SI (match_dup 1) (match_dup 2)))]
9510   "TARGET_UPDATE"
9511   "@
9512    lhzux %3,%0,%2
9513    lhzu %3,%2(%0)"
9514   [(set_attr "type" "load_ux,load_u")])
9515
9516 (define_insn "*movhi_update2"
9517   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9518         (zero_extend:SI
9519          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9520                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9521    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9522         (plus:SI (match_dup 1) (match_dup 2)))]
9523   "TARGET_UPDATE"
9524   "@
9525    lhzux %3,%0,%2
9526    lhzu %3,%2(%0)"
9527   [(set_attr "type" "load_ux,load_u")])
9528
9529 (define_insn "*movhi_update3"
9530   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9531         (sign_extend:SI
9532          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9533                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9534    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9535         (plus:SI (match_dup 1) (match_dup 2)))]
9536   "TARGET_UPDATE"
9537   "@
9538    lhaux %3,%0,%2
9539    lhau %3,%2(%0)"
9540   [(set_attr "type" "load_ext_ux,load_ext_u")])
9541
9542 (define_insn "*movhi_update4"
9543   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9544                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9545         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
9546    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9547         (plus:SI (match_dup 1) (match_dup 2)))]
9548   "TARGET_UPDATE"
9549   "@
9550    sthux %3,%0,%2
9551    sthu %3,%2(%0)"
9552   [(set_attr "type" "store_ux,store_u")])
9553
9554 (define_insn "*movqi_update1"
9555   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
9556         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9557                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9558    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9559         (plus:SI (match_dup 1) (match_dup 2)))]
9560   "TARGET_UPDATE"
9561   "@
9562    lbzux %3,%0,%2
9563    lbzu %3,%2(%0)"
9564   [(set_attr "type" "load_ux,load_u")])
9565
9566 (define_insn "*movqi_update2"
9567   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9568         (zero_extend:SI
9569          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9570                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9571    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9572         (plus:SI (match_dup 1) (match_dup 2)))]
9573   "TARGET_UPDATE"
9574   "@
9575    lbzux %3,%0,%2
9576    lbzu %3,%2(%0)"
9577   [(set_attr "type" "load_ux,load_u")])
9578
9579 (define_insn "*movqi_update3"
9580   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9581                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9582         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
9583    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9584         (plus:SI (match_dup 1) (match_dup 2)))]
9585   "TARGET_UPDATE"
9586   "@
9587    stbux %3,%0,%2
9588    stbu %3,%2(%0)"
9589   [(set_attr "type" "store_ux,store_u")])
9590
9591 (define_insn "*movsf_update1"
9592   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
9593         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9594                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9595    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9596         (plus:SI (match_dup 1) (match_dup 2)))]
9597   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9598   "@
9599    lfsux %3,%0,%2
9600    lfsu %3,%2(%0)"
9601   [(set_attr "type" "fpload_ux,fpload_u")])
9602
9603 (define_insn "*movsf_update2"
9604   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9605                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9606         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
9607    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9608         (plus:SI (match_dup 1) (match_dup 2)))]
9609   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9610   "@
9611    stfsux %3,%0,%2
9612    stfsu %3,%2(%0)"
9613   [(set_attr "type" "fpstore_ux,fpstore_u")])
9614
9615 (define_insn "*movsf_update3"
9616   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
9617         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9618                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9619    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9620         (plus:SI (match_dup 1) (match_dup 2)))]
9621   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9622   "@
9623    {lux|lwzux} %3,%0,%2
9624    {lu|lwzu} %3,%2(%0)"
9625   [(set_attr "type" "load_ux,load_u")])
9626
9627 (define_insn "*movsf_update4"
9628   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9629                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9630         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
9631    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9632         (plus:SI (match_dup 1) (match_dup 2)))]
9633   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9634   "@
9635    {stux|stwux} %3,%0,%2
9636    {stu|stwu} %3,%2(%0)"
9637   [(set_attr "type" "store_ux,store_u")])
9638
9639 (define_insn "*movdf_update1"
9640   [(set (match_operand:DF 3 "gpc_reg_operand" "=f,f")
9641         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9642                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9643    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9644         (plus:SI (match_dup 1) (match_dup 2)))]
9645   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9646   "@
9647    lfdux %3,%0,%2
9648    lfdu %3,%2(%0)"
9649   [(set_attr "type" "fpload_ux,fpload_u")])
9650
9651 (define_insn "*movdf_update2"
9652   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9653                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9654         (match_operand:DF 3 "gpc_reg_operand" "f,f"))
9655    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9656         (plus:SI (match_dup 1) (match_dup 2)))]
9657   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9658   "@
9659    stfdux %3,%0,%2
9660    stfdu %3,%2(%0)"
9661   [(set_attr "type" "fpstore_ux,fpstore_u")])
9662
9663 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
9664
9665 (define_peephole
9666   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
9667         (match_operand:DF 1 "memory_operand" ""))
9668    (set (match_operand:DF 2 "gpc_reg_operand" "=f")
9669         (match_operand:DF 3 "memory_operand" ""))]
9670   "TARGET_POWER2
9671    && TARGET_HARD_FLOAT && TARGET_FPRS
9672    && registers_ok_for_quad_peep (operands[0], operands[2])
9673    && ! MEM_VOLATILE_P (operands[1]) && ! MEM_VOLATILE_P (operands[3])
9674    && addrs_ok_for_quad_peep (XEXP (operands[1], 0), XEXP (operands[3], 0))"
9675   "lfq%U1%X1 %0,%1")
9676
9677 (define_peephole
9678   [(set (match_operand:DF 0 "memory_operand" "")
9679         (match_operand:DF 1 "gpc_reg_operand" "f"))
9680    (set (match_operand:DF 2 "memory_operand" "")
9681         (match_operand:DF 3 "gpc_reg_operand" "f"))]
9682   "TARGET_POWER2
9683    && TARGET_HARD_FLOAT && TARGET_FPRS
9684    && registers_ok_for_quad_peep (operands[1], operands[3])
9685    && ! MEM_VOLATILE_P (operands[0]) && ! MEM_VOLATILE_P (operands[2])
9686    && addrs_ok_for_quad_peep (XEXP (operands[0], 0), XEXP (operands[2], 0))"
9687   "stfq%U0%X0 %1,%0")
9688 \f
9689 ;; TLS support.
9690
9691 ;; "b" output constraint here and on tls_ld to support tls linker optimization.
9692 (define_insn "tls_gd_32"
9693   [(set (match_operand:SI 0 "register_operand" "=b")
9694         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9695                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9696                    UNSPEC_TLSGD))]
9697   "HAVE_AS_TLS && !TARGET_64BIT"
9698   "addi %0,%1,%2@got@tlsgd")
9699
9700 (define_insn "tls_gd_64"
9701   [(set (match_operand:DI 0 "register_operand" "=b")
9702         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9703                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9704                    UNSPEC_TLSGD))]
9705   "HAVE_AS_TLS && TARGET_64BIT"
9706   "addi %0,%1,%2@got@tlsgd")
9707
9708 (define_insn "tls_ld_32"
9709   [(set (match_operand:SI 0 "register_operand" "=b")
9710         (unspec:SI [(match_operand:SI 1 "register_operand" "b")]
9711                    UNSPEC_TLSLD))]
9712   "HAVE_AS_TLS && !TARGET_64BIT"
9713   "addi %0,%1,%&@got@tlsld")
9714
9715 (define_insn "tls_ld_64"
9716   [(set (match_operand:DI 0 "register_operand" "=b")
9717         (unspec:DI [(match_operand:DI 1 "register_operand" "b")]
9718                    UNSPEC_TLSLD))]
9719   "HAVE_AS_TLS && TARGET_64BIT"
9720   "addi %0,%1,%&@got@tlsld")
9721
9722 (define_insn "tls_dtprel_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_TLSDTPREL))]
9727   "HAVE_AS_TLS && !TARGET_64BIT"
9728   "addi %0,%1,%2@dtprel")
9729
9730 (define_insn "tls_dtprel_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_TLSDTPREL))]
9735   "HAVE_AS_TLS && TARGET_64BIT"
9736   "addi %0,%1,%2@dtprel")
9737
9738 (define_insn "tls_dtprel_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_TLSDTPRELHA))]
9743   "HAVE_AS_TLS && !TARGET_64BIT"
9744   "addis %0,%1,%2@dtprel@ha")
9745
9746 (define_insn "tls_dtprel_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_TLSDTPRELHA))]
9751   "HAVE_AS_TLS && TARGET_64BIT"
9752   "addis %0,%1,%2@dtprel@ha")
9753
9754 (define_insn "tls_dtprel_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_TLSDTPRELLO))]
9759   "HAVE_AS_TLS && !TARGET_64BIT"
9760   "addi %0,%1,%2@dtprel@l")
9761
9762 (define_insn "tls_dtprel_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_TLSDTPRELLO))]
9767   "HAVE_AS_TLS && TARGET_64BIT"
9768   "addi %0,%1,%2@dtprel@l")
9769
9770 (define_insn "tls_got_dtprel_32"
9771   [(set (match_operand:SI 0 "register_operand" "=r")
9772         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9773                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9774                    UNSPEC_TLSGOTDTPREL))]
9775   "HAVE_AS_TLS && !TARGET_64BIT"
9776   "lwz %0,%2@got@dtprel(%1)")
9777
9778 (define_insn "tls_got_dtprel_64"
9779   [(set (match_operand:DI 0 "register_operand" "=r")
9780         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9781                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9782                    UNSPEC_TLSGOTDTPREL))]
9783   "HAVE_AS_TLS && TARGET_64BIT"
9784   "ld %0,%2@got@dtprel(%1)")
9785
9786 (define_insn "tls_tprel_32"
9787   [(set (match_operand:SI 0 "register_operand" "=r")
9788         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9789                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9790                    UNSPEC_TLSTPREL))]
9791   "HAVE_AS_TLS && !TARGET_64BIT"
9792   "addi %0,%1,%2@tprel")
9793
9794 (define_insn "tls_tprel_64"
9795   [(set (match_operand:DI 0 "register_operand" "=r")
9796         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9797                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9798                    UNSPEC_TLSTPREL))]
9799   "HAVE_AS_TLS && TARGET_64BIT"
9800   "addi %0,%1,%2@tprel")
9801
9802 (define_insn "tls_tprel_ha_32"
9803   [(set (match_operand:SI 0 "register_operand" "=r")
9804         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9805                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9806                    UNSPEC_TLSTPRELHA))]
9807   "HAVE_AS_TLS && !TARGET_64BIT"
9808   "addis %0,%1,%2@tprel@ha")
9809
9810 (define_insn "tls_tprel_ha_64"
9811   [(set (match_operand:DI 0 "register_operand" "=r")
9812         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9813                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9814                    UNSPEC_TLSTPRELHA))]
9815   "HAVE_AS_TLS && TARGET_64BIT"
9816   "addis %0,%1,%2@tprel@ha")
9817
9818 (define_insn "tls_tprel_lo_32"
9819   [(set (match_operand:SI 0 "register_operand" "=r")
9820         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9821                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9822                    UNSPEC_TLSTPRELLO))]
9823   "HAVE_AS_TLS && !TARGET_64BIT"
9824   "addi %0,%1,%2@tprel@l")
9825
9826 (define_insn "tls_tprel_lo_64"
9827   [(set (match_operand:DI 0 "register_operand" "=r")
9828         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9829                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9830                    UNSPEC_TLSTPRELLO))]
9831   "HAVE_AS_TLS && TARGET_64BIT"
9832   "addi %0,%1,%2@tprel@l")
9833
9834 ;; "b" output constraint here and on tls_tls input to support linker tls
9835 ;; optimization.  The linker may edit the instructions emitted by a
9836 ;; tls_got_tprel/tls_tls pair to addis,addi.
9837 (define_insn "tls_got_tprel_32"
9838   [(set (match_operand:SI 0 "register_operand" "=b")
9839         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9840                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9841                    UNSPEC_TLSGOTTPREL))]
9842   "HAVE_AS_TLS && !TARGET_64BIT"
9843   "lwz %0,%2@got@tprel(%1)")
9844
9845 (define_insn "tls_got_tprel_64"
9846   [(set (match_operand:DI 0 "register_operand" "=b")
9847         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9848                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9849                    UNSPEC_TLSGOTTPREL))]
9850   "HAVE_AS_TLS && TARGET_64BIT"
9851   "ld %0,%2@got@tprel(%1)")
9852
9853 (define_insn "tls_tls_32"
9854   [(set (match_operand:SI 0 "register_operand" "=r")
9855         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9856                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9857                    UNSPEC_TLSTLS))]
9858   "HAVE_AS_TLS && !TARGET_64BIT"
9859   "add %0,%1,%2@tls")
9860
9861 (define_insn "tls_tls_64"
9862   [(set (match_operand:DI 0 "register_operand" "=r")
9863         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9864                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9865                    UNSPEC_TLSTLS))]
9866   "HAVE_AS_TLS && TARGET_64BIT"
9867   "add %0,%1,%2@tls")
9868 \f
9869 ;; Next come insns related to the calling sequence.
9870 ;;
9871 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
9872 ;; We move the back-chain and decrement the stack pointer.
9873
9874 (define_expand "allocate_stack"
9875   [(set (match_operand 0 "gpc_reg_operand" "=r")
9876         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
9877    (set (reg 1)
9878         (minus (reg 1) (match_dup 1)))]
9879   ""
9880   "
9881 { rtx chain = gen_reg_rtx (Pmode);
9882   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
9883   rtx neg_op0;
9884
9885   emit_move_insn (chain, stack_bot);
9886
9887   /* Check stack bounds if necessary.  */
9888   if (current_function_limit_stack)
9889     {
9890       rtx available;
9891       available = expand_binop (Pmode, sub_optab, 
9892                                 stack_pointer_rtx, stack_limit_rtx,
9893                                 NULL_RTX, 1, OPTAB_WIDEN);
9894       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
9895     }
9896
9897   if (GET_CODE (operands[1]) != CONST_INT
9898       || INTVAL (operands[1]) < -32767
9899       || INTVAL (operands[1]) > 32768)
9900     {
9901       neg_op0 = gen_reg_rtx (Pmode);
9902       if (TARGET_32BIT)
9903         emit_insn (gen_negsi2 (neg_op0, operands[1]));
9904       else
9905         emit_insn (gen_negdi2 (neg_op0, operands[1]));
9906     }
9907   else
9908     neg_op0 = GEN_INT (- INTVAL (operands[1]));
9909
9910   if (TARGET_UPDATE)
9911     emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update : gen_movdi_update))
9912                 (stack_pointer_rtx, stack_pointer_rtx, neg_op0, chain));
9913
9914   else
9915     {
9916       emit_insn ((* ((TARGET_32BIT) ? gen_addsi3 : gen_adddi3))
9917                  (stack_pointer_rtx, stack_pointer_rtx, neg_op0));
9918       emit_move_insn (gen_rtx_MEM (Pmode, stack_pointer_rtx), chain);
9919     }
9920
9921   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
9922   DONE;
9923 }")
9924
9925 ;; These patterns say how to save and restore the stack pointer.  We need not
9926 ;; save the stack pointer at function level since we are careful to
9927 ;; preserve the backchain.  At block level, we have to restore the backchain
9928 ;; when we restore the stack pointer.
9929 ;;
9930 ;; For nonlocal gotos, we must save both the stack pointer and its
9931 ;; backchain and restore both.  Note that in the nonlocal case, the
9932 ;; save area is a memory location.
9933
9934 (define_expand "save_stack_function"
9935   [(match_operand 0 "any_operand" "")
9936    (match_operand 1 "any_operand" "")]
9937   ""
9938   "DONE;")
9939
9940 (define_expand "restore_stack_function"
9941   [(match_operand 0 "any_operand" "")
9942    (match_operand 1 "any_operand" "")]
9943   ""
9944   "DONE;")
9945
9946 (define_expand "restore_stack_block"
9947   [(use (match_operand 0 "register_operand" ""))
9948    (set (match_dup 2) (match_dup 3))
9949    (set (match_dup 0) (match_operand 1 "register_operand" ""))
9950    (set (match_dup 3) (match_dup 2))]
9951   ""
9952   "
9953 {
9954   operands[2] = gen_reg_rtx (Pmode);
9955   operands[3] = gen_rtx_MEM (Pmode, operands[0]);
9956 }")
9957
9958 (define_expand "save_stack_nonlocal"
9959   [(match_operand 0 "memory_operand" "")
9960    (match_operand 1 "register_operand" "")]
9961   ""
9962   "
9963 {
9964   rtx temp = gen_reg_rtx (Pmode);
9965
9966   /* Copy the backchain to the first word, sp to the second.  */
9967   emit_move_insn (temp, gen_rtx_MEM (Pmode, operands[1]));
9968   emit_move_insn (operand_subword (operands[0], 0, 0,
9969                                    (TARGET_32BIT ? DImode : TImode)),
9970                   temp);
9971   emit_move_insn (operand_subword (operands[0], 1, 0, (TARGET_32BIT ? DImode : TImode)),
9972                   operands[1]);
9973   DONE;
9974 }")
9975
9976 (define_expand "restore_stack_nonlocal"
9977   [(match_operand 0 "register_operand" "")
9978    (match_operand 1 "memory_operand" "")]
9979   ""
9980   "
9981 {
9982   rtx temp = gen_reg_rtx (Pmode);
9983
9984   /* Restore the backchain from the first word, sp from the second.  */
9985   emit_move_insn (temp,
9986                   operand_subword (operands[1], 0, 0, (TARGET_32BIT ? DImode : TImode)));
9987   emit_move_insn (operands[0],
9988                   operand_subword (operands[1], 1, 0,
9989                                    (TARGET_32BIT ? DImode : TImode)));
9990   emit_move_insn (gen_rtx_MEM (Pmode, operands[0]), temp);
9991   DONE;
9992 }")
9993 \f
9994 ;; TOC register handling.
9995
9996 ;; Code to initialize the TOC register...
9997
9998 (define_insn "load_toc_aix_si"
9999   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10000                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
10001               (use (reg:SI 2))])]
10002   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
10003   "*
10004 {
10005   char buf[30];
10006   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10007   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10008   operands[2] = gen_rtx_REG (Pmode, 2);
10009   return \"{l|lwz} %0,%1(%2)\";
10010 }"
10011   [(set_attr "type" "load")])
10012
10013 (define_insn "load_toc_aix_di"
10014   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10015                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
10016               (use (reg:DI 2))])]
10017   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
10018   "*
10019 {
10020   char buf[30];
10021 #ifdef TARGET_RELOCATABLE
10022   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
10023                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
10024 #else
10025   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10026 #endif
10027   if (TARGET_ELF)
10028     strcat (buf, \"@toc\");
10029   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10030   operands[2] = gen_rtx_REG (Pmode, 2);
10031   return \"ld %0,%1(%2)\";
10032 }"
10033   [(set_attr "type" "load")])
10034
10035 (define_insn "load_toc_v4_pic_si"
10036   [(set (match_operand:SI 0 "register_operand" "=l")
10037         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
10038   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
10039   "bl _GLOBAL_OFFSET_TABLE_@local-4"
10040   [(set_attr "type" "branch")
10041    (set_attr "length" "4")])
10042
10043 (define_insn "load_toc_v4_PIC_1"
10044   [(set (match_operand:SI 0 "register_operand" "=l")
10045         (match_operand:SI 1 "immediate_operand" "s"))
10046    (use (unspec [(match_dup 1)] UNSPEC_TOC))]
10047   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10048   "bcl 20,31,%1\\n%1:"
10049   [(set_attr "type" "branch")
10050    (set_attr "length" "4")])
10051
10052 (define_insn "load_toc_v4_PIC_1b"
10053   [(set (match_operand:SI 0 "register_operand" "=l")
10054         (unspec:SI [(match_operand:SI 1 "immediate_operand" "s")]
10055                 UNSPEC_TOCPTR))]
10056   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10057   "bcl 20,31,$+8\\n\\t.long %1-$"
10058   [(set_attr "type" "branch")
10059    (set_attr "length" "8")])
10060
10061 (define_insn "load_toc_v4_PIC_2"
10062   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10063         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10064                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
10065                              (match_operand:SI 3 "immediate_operand" "s")))))]
10066   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10067   "{l|lwz} %0,%2-%3(%1)"
10068   [(set_attr "type" "load")])
10069
10070 (define_insn "load_macho_picbase"
10071   [(set (match_operand:SI 0 "register_operand" "=l")
10072         (unspec:SI [(match_operand:SI 1 "immediate_operand" "s")]
10073                    UNSPEC_LD_MPIC))]
10074   "(DEFAULT_ABI == ABI_DARWIN) && flag_pic"
10075   "bcl 20,31,%1\\n%1:"
10076   [(set_attr "type" "branch")
10077    (set_attr "length" "4")])
10078
10079 (define_insn "macho_correct_pic"
10080   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10081         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
10082                  (unspec:SI [(match_operand:SI 2 "immediate_operand" "s")
10083                              (match_operand:SI 3 "immediate_operand" "s")]
10084                             UNSPEC_MPIC_CORRECT)))]
10085   "DEFAULT_ABI == ABI_DARWIN"
10086   "addis %0,%1,ha16(%2-%3)\n\taddi %0,%0,lo16(%2-%3)"
10087   [(set_attr "length" "8")])
10088
10089 ;; If the TOC is shared over a translation unit, as happens with all
10090 ;; the kinds of PIC that we support, we need to restore the TOC
10091 ;; pointer only when jumping over units of translation.
10092 ;; On Darwin, we need to reload the picbase.
10093
10094 (define_expand "builtin_setjmp_receiver"
10095   [(use (label_ref (match_operand 0 "" "")))]
10096   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
10097    || (TARGET_TOC && TARGET_MINIMAL_TOC)
10098    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
10099   "
10100 {
10101 #if TARGET_MACHO
10102   if (DEFAULT_ABI == ABI_DARWIN)
10103     {
10104       const char *picbase = machopic_function_base_name ();
10105       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (picbase));
10106       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
10107       rtx tmplabrtx;
10108       char tmplab[20];
10109
10110       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
10111                                   CODE_LABEL_NUMBER (operands[0]));
10112       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
10113
10114       emit_insn (gen_load_macho_picbase (picreg, tmplabrtx));
10115       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
10116     }
10117   else
10118 #endif
10119     rs6000_emit_load_toc_table (FALSE);
10120   DONE;
10121 }")
10122 \f
10123 ;; A function pointer under AIX is a pointer to a data area whose first word
10124 ;; contains the actual address of the function, whose second word contains a
10125 ;; pointer to its TOC, and whose third word contains a value to place in the
10126 ;; static chain register (r11).  Note that if we load the static chain, our
10127 ;; "trampoline" need not have any executable code.
10128
10129 (define_expand "call_indirect_aix32"
10130   [(set (match_dup 2)
10131         (mem:SI (match_operand:SI 0 "gpc_reg_operand" "")))
10132    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10133         (reg:SI 2))
10134    (set (reg:SI 2)
10135         (mem:SI (plus:SI (match_dup 0)
10136                          (const_int 4))))
10137    (set (reg:SI 11)
10138         (mem:SI (plus:SI (match_dup 0)
10139                          (const_int 8))))
10140    (parallel [(call (mem:SI (match_dup 2))
10141                     (match_operand 1 "" ""))
10142               (use (reg:SI 2))
10143               (use (reg:SI 11))
10144               (set (reg:SI 2)
10145                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10146               (clobber (scratch:SI))])]
10147   "TARGET_32BIT"
10148   "
10149 { operands[2] = gen_reg_rtx (SImode); }")
10150
10151 (define_expand "call_indirect_aix64"
10152   [(set (match_dup 2)
10153         (mem:DI (match_operand:DI 0 "gpc_reg_operand" "")))
10154    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10155         (reg:DI 2))
10156    (set (reg:DI 2)
10157         (mem:DI (plus:DI (match_dup 0)
10158                          (const_int 8))))
10159    (set (reg:DI 11)
10160         (mem:DI (plus:DI (match_dup 0)
10161                          (const_int 16))))
10162    (parallel [(call (mem:SI (match_dup 2))
10163                     (match_operand 1 "" ""))
10164               (use (reg:DI 2))
10165               (use (reg:DI 11))
10166               (set (reg:DI 2)
10167                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10168               (clobber (scratch:SI))])]
10169   "TARGET_64BIT"
10170   "
10171 { operands[2] = gen_reg_rtx (DImode); }")
10172
10173 (define_expand "call_value_indirect_aix32"
10174   [(set (match_dup 3)
10175         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
10176    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10177         (reg:SI 2))
10178    (set (reg:SI 2)
10179         (mem:SI (plus:SI (match_dup 1)
10180                          (const_int 4))))
10181    (set (reg:SI 11)
10182         (mem:SI (plus:SI (match_dup 1)
10183                          (const_int 8))))
10184    (parallel [(set (match_operand 0 "" "")
10185                    (call (mem:SI (match_dup 3))
10186                          (match_operand 2 "" "")))
10187               (use (reg:SI 2))
10188               (use (reg:SI 11))
10189               (set (reg:SI 2)
10190                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10191               (clobber (scratch:SI))])]
10192   "TARGET_32BIT"
10193   "
10194 { operands[3] = gen_reg_rtx (SImode); }")
10195
10196 (define_expand "call_value_indirect_aix64"
10197   [(set (match_dup 3)
10198         (mem:DI (match_operand:DI 1 "gpc_reg_operand" "")))
10199    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10200         (reg:DI 2))
10201    (set (reg:DI 2)
10202         (mem:DI (plus:DI (match_dup 1)
10203                          (const_int 8))))
10204    (set (reg:DI 11)
10205         (mem:DI (plus:DI (match_dup 1)
10206                          (const_int 16))))
10207    (parallel [(set (match_operand 0 "" "")
10208                    (call (mem:SI (match_dup 3))
10209                          (match_operand 2 "" "")))
10210               (use (reg:DI 2))
10211               (use (reg:DI 11))
10212               (set (reg:DI 2)
10213                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10214               (clobber (scratch:SI))])]
10215   "TARGET_64BIT"
10216   "
10217 { operands[3] = gen_reg_rtx (DImode); }")
10218
10219 ;; Now the definitions for the call and call_value insns
10220 (define_expand "call"
10221   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10222                     (match_operand 1 "" ""))
10223               (use (match_operand 2 "" ""))
10224               (clobber (scratch:SI))])]
10225   ""
10226   "
10227 {
10228 #if TARGET_MACHO
10229   if (MACHOPIC_INDIRECT)
10230     operands[0] = machopic_indirect_call_target (operands[0]);
10231 #endif
10232
10233   if (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != CONST_INT)
10234     abort ();
10235
10236   operands[0] = XEXP (operands[0], 0);
10237
10238   if (GET_CODE (operands[0]) != SYMBOL_REF
10239       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
10240       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
10241     {
10242       if (INTVAL (operands[2]) & CALL_LONG)
10243         operands[0] = rs6000_longcall_ref (operands[0]);
10244
10245       if (DEFAULT_ABI == ABI_V4
10246           || DEFAULT_ABI == ABI_DARWIN)
10247         operands[0] = force_reg (Pmode, operands[0]);
10248
10249       else if (DEFAULT_ABI == ABI_AIX)
10250         {
10251           /* AIX function pointers are really pointers to a three word
10252              area.  */
10253           emit_call_insn (TARGET_32BIT
10254                           ? gen_call_indirect_aix32 (force_reg (SImode,
10255                                                                 operands[0]),
10256                                                      operands[1])
10257                           : gen_call_indirect_aix64 (force_reg (DImode,
10258                                                                 operands[0]),
10259                                                      operands[1]));
10260           DONE;
10261         }
10262       else
10263         abort ();
10264     }
10265 }")
10266
10267 (define_expand "call_value"
10268   [(parallel [(set (match_operand 0 "" "")
10269                    (call (mem:SI (match_operand 1 "address_operand" ""))
10270                          (match_operand 2 "" "")))
10271               (use (match_operand 3 "" ""))
10272               (clobber (scratch:SI))])]
10273   ""
10274   "
10275 {
10276 #if TARGET_MACHO
10277   if (MACHOPIC_INDIRECT)
10278     operands[1] = machopic_indirect_call_target (operands[1]);
10279 #endif
10280
10281   if (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != CONST_INT)
10282     abort ();
10283
10284   operands[1] = XEXP (operands[1], 0);
10285
10286   if (GET_CODE (operands[1]) != SYMBOL_REF
10287       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
10288       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
10289     {
10290       if (INTVAL (operands[3]) & CALL_LONG)
10291         operands[1] = rs6000_longcall_ref (operands[1]);
10292
10293       if (DEFAULT_ABI == ABI_V4
10294           || DEFAULT_ABI == ABI_DARWIN)
10295         operands[1] = force_reg (Pmode, operands[1]);
10296
10297       else if (DEFAULT_ABI == ABI_AIX)
10298         {
10299           /* AIX function pointers are really pointers to a three word
10300              area.  */
10301           emit_call_insn (TARGET_32BIT
10302                           ? gen_call_value_indirect_aix32 (operands[0],
10303                                                            force_reg (SImode,
10304                                                                       operands[1]),
10305                                                            operands[2])
10306                           : gen_call_value_indirect_aix64 (operands[0],
10307                                                            force_reg (DImode,
10308                                                                       operands[1]),
10309                                                            operands[2]));
10310           DONE;
10311         }
10312       else
10313         abort ();
10314     }
10315 }")
10316
10317 ;; Call to function in current module.  No TOC pointer reload needed.
10318 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10319 ;; either the function was not prototyped, or it was prototyped as a
10320 ;; variable argument function.  It is > 0 if FP registers were passed
10321 ;; and < 0 if they were not.
10322
10323 (define_insn "*call_local32"
10324   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10325          (match_operand 1 "" "g,g"))
10326    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10327    (clobber (match_scratch:SI 3 "=l,l"))]
10328   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10329   "*
10330 {
10331   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10332     output_asm_insn (\"crxor 6,6,6\", operands);
10333
10334   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10335     output_asm_insn (\"creqv 6,6,6\", operands);
10336
10337   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10338 }"
10339   [(set_attr "type" "branch")
10340    (set_attr "length" "4,8")])
10341
10342 (define_insn "*call_local64"
10343   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10344          (match_operand 1 "" "g,g"))
10345    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10346    (clobber (match_scratch:SI 3 "=l,l"))]
10347   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10348   "*
10349 {
10350   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10351     output_asm_insn (\"crxor 6,6,6\", operands);
10352
10353   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10354     output_asm_insn (\"creqv 6,6,6\", operands);
10355
10356   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10357 }"
10358   [(set_attr "type" "branch")
10359    (set_attr "length" "4,8")])
10360
10361 (define_insn "*call_value_local32"
10362   [(set (match_operand 0 "" "")
10363         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10364               (match_operand 2 "" "g,g")))
10365    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10366    (clobber (match_scratch:SI 4 "=l,l"))]
10367   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10368   "*
10369 {
10370   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10371     output_asm_insn (\"crxor 6,6,6\", operands);
10372
10373   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10374     output_asm_insn (\"creqv 6,6,6\", operands);
10375
10376   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10377 }"
10378   [(set_attr "type" "branch")
10379    (set_attr "length" "4,8")])
10380
10381
10382 (define_insn "*call_value_local64"
10383   [(set (match_operand 0 "" "")
10384         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10385               (match_operand 2 "" "g,g")))
10386    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10387    (clobber (match_scratch:SI 4 "=l,l"))]
10388   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10389   "*
10390 {
10391   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10392     output_asm_insn (\"crxor 6,6,6\", operands);
10393
10394   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10395     output_asm_insn (\"creqv 6,6,6\", operands);
10396
10397   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10398 }"
10399   [(set_attr "type" "branch")
10400    (set_attr "length" "4,8")])
10401
10402 ;; Call to function which may be in another module.  Restore the TOC
10403 ;; pointer (r2) after the call unless this is System V.
10404 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10405 ;; either the function was not prototyped, or it was prototyped as a
10406 ;; variable argument function.  It is > 0 if FP registers were passed
10407 ;; and < 0 if they were not.
10408
10409 (define_insn "*call_indirect_nonlocal_aix32"
10410   [(call (mem:SI (match_operand:SI 0 "register_operand" "cl"))
10411          (match_operand 1 "" "g"))
10412    (use (reg:SI 2))
10413    (use (reg:SI 11))
10414    (set (reg:SI 2)
10415         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10416    (clobber (match_scratch:SI 2 "=l"))]
10417   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10418   "b%T0l\;{l|lwz} 2,20(1)"
10419   [(set_attr "type" "jmpreg")
10420    (set_attr "length" "8")])
10421
10422 (define_insn "*call_nonlocal_aix32"
10423   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10424          (match_operand 1 "" "g"))
10425    (use (match_operand:SI 2 "immediate_operand" "O"))
10426    (clobber (match_scratch:SI 3 "=l"))]
10427   "TARGET_32BIT
10428    && DEFAULT_ABI == ABI_AIX
10429    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10430   "bl %z0\;%."
10431   [(set_attr "type" "branch")
10432    (set_attr "length" "8")])
10433
10434 (define_insn "*call_indirect_nonlocal_aix64"
10435   [(call (mem:SI (match_operand:DI 0 "register_operand" "cl"))
10436          (match_operand 1 "" "g"))
10437    (use (reg:DI 2))
10438    (use (reg:DI 11))
10439    (set (reg:DI 2)
10440         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10441    (clobber (match_scratch:SI 2 "=l"))]
10442   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10443   "b%T0l\;ld 2,40(1)"
10444   [(set_attr "type" "jmpreg")
10445    (set_attr "length" "8")])
10446
10447 (define_insn "*call_nonlocal_aix64"
10448   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10449          (match_operand 1 "" "g"))
10450    (use (match_operand:SI 2 "immediate_operand" "O"))
10451    (clobber (match_scratch:SI 3 "=l"))]
10452   "TARGET_64BIT 
10453    && DEFAULT_ABI == ABI_AIX
10454    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10455   "bl %z0\;%."
10456   [(set_attr "type" "branch")
10457    (set_attr "length" "8")])
10458
10459 (define_insn "*call_value_indirect_nonlocal_aix32"
10460   [(set (match_operand 0 "" "")
10461         (call (mem:SI (match_operand:SI 1 "register_operand" "cl"))
10462               (match_operand 2 "" "g")))
10463    (use (reg:SI 2))
10464    (use (reg:SI 11))
10465    (set (reg:SI 2)
10466         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10467    (clobber (match_scratch:SI 3 "=l"))]
10468   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10469   "b%T1l\;{l|lwz} 2,20(1)"
10470   [(set_attr "type" "jmpreg")
10471    (set_attr "length" "8")])
10472
10473 (define_insn "*call_value_nonlocal_aix32"
10474   [(set (match_operand 0 "" "")
10475         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10476               (match_operand 2 "" "g")))
10477    (use (match_operand:SI 3 "immediate_operand" "O"))
10478    (clobber (match_scratch:SI 4 "=l"))]
10479   "TARGET_32BIT
10480    && DEFAULT_ABI == ABI_AIX
10481    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10482   "bl %z1\;%."
10483   [(set_attr "type" "branch")
10484    (set_attr "length" "8")])
10485
10486 (define_insn "*call_value_indirect_nonlocal_aix64"
10487   [(set (match_operand 0 "" "")
10488         (call (mem:SI (match_operand:DI 1 "register_operand" "cl"))
10489               (match_operand 2 "" "g")))
10490    (use (reg:DI 2))
10491    (use (reg:DI 11))
10492    (set (reg:DI 2)
10493         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10494    (clobber (match_scratch:SI 3 "=l"))]
10495   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10496   "b%T1l\;ld 2,40(1)"
10497   [(set_attr "type" "jmpreg")
10498    (set_attr "length" "8")])
10499
10500 (define_insn "*call_value_nonlocal_aix64"
10501   [(set (match_operand 0 "" "")
10502         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10503               (match_operand 2 "" "g")))
10504    (use (match_operand:SI 3 "immediate_operand" "O"))
10505    (clobber (match_scratch:SI 4 "=l"))]
10506   "TARGET_64BIT 
10507    && DEFAULT_ABI == ABI_AIX
10508    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10509   "bl %z1\;%."
10510   [(set_attr "type" "branch")
10511    (set_attr "length" "8")])
10512
10513 ;; A function pointer under System V is just a normal pointer
10514 ;; operands[0] is the function pointer
10515 ;; operands[1] is the stack size to clean up
10516 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
10517 ;; which indicates how to set cr1
10518
10519 (define_insn "*call_indirect_nonlocal_sysv"
10520   [(call (mem:SI (match_operand:SI 0 "register_operand" "cl,cl"))
10521          (match_operand 1 "" "g,g"))
10522    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10523    (clobber (match_scratch:SI 3 "=l,l"))]
10524   "DEFAULT_ABI == ABI_V4
10525    || DEFAULT_ABI == ABI_DARWIN"
10526 {
10527   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10528     output_asm_insn ("crxor 6,6,6", operands);
10529
10530   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10531     output_asm_insn ("creqv 6,6,6", operands);
10532
10533   return "b%T0l";
10534 }
10535   [(set_attr "type" "jmpreg,jmpreg")
10536    (set_attr "length" "4,8")])
10537
10538 (define_insn "*call_nonlocal_sysv"
10539   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s,s"))
10540          (match_operand 1 "" "g,g"))
10541    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10542    (clobber (match_scratch:SI 3 "=l,l"))]
10543   "(DEFAULT_ABI == ABI_DARWIN
10544    || (DEFAULT_ABI == ABI_V4
10545        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
10546 {
10547   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10548     output_asm_insn ("crxor 6,6,6", operands);
10549
10550   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10551     output_asm_insn ("creqv 6,6,6", operands);
10552
10553 #if TARGET_MACHO
10554   return output_call(insn, operands, 0, 2);
10555 #else
10556   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z0@plt" : "bl %z0";
10557 #endif     
10558 }
10559   [(set_attr "type" "branch,branch")
10560    (set_attr "length" "4,8")])
10561
10562 (define_insn "*call_value_indirect_nonlocal_sysv"
10563   [(set (match_operand 0 "" "")
10564         (call (mem:SI (match_operand:SI 1 "register_operand" "cl,cl"))
10565               (match_operand 2 "" "g,g")))
10566    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10567    (clobber (match_scratch:SI 4 "=l,l"))]
10568   "DEFAULT_ABI == ABI_V4
10569    || DEFAULT_ABI == ABI_DARWIN"
10570 {
10571   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10572     output_asm_insn ("crxor 6,6,6", operands);
10573
10574   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10575     output_asm_insn ("creqv 6,6,6", operands);
10576
10577   return "b%T1l";
10578 }
10579   [(set_attr "type" "jmpreg,jmpreg")
10580    (set_attr "length" "4,8")])
10581
10582 (define_insn "*call_value_nonlocal_sysv"
10583   [(set (match_operand 0 "" "")
10584         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s,s"))
10585               (match_operand 2 "" "g,g")))
10586    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10587    (clobber (match_scratch:SI 4 "=l,l"))]
10588   "(DEFAULT_ABI == ABI_DARWIN
10589    || (DEFAULT_ABI == ABI_V4
10590        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
10591 {
10592   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10593     output_asm_insn ("crxor 6,6,6", operands);
10594
10595   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10596     output_asm_insn ("creqv 6,6,6", operands);
10597
10598 #if TARGET_MACHO
10599   return output_call(insn, operands, 1, 3);
10600 #else
10601   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z1@plt" : "bl %z1";
10602 #endif     
10603 }
10604   [(set_attr "type" "branch,branch")
10605    (set_attr "length" "4,8")])
10606
10607 ;; Call subroutine returning any type.
10608 (define_expand "untyped_call"
10609   [(parallel [(call (match_operand 0 "" "")
10610                     (const_int 0))
10611               (match_operand 1 "" "")
10612               (match_operand 2 "" "")])]
10613   ""
10614   "
10615 {
10616   int i;
10617
10618   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
10619
10620   for (i = 0; i < XVECLEN (operands[2], 0); i++)
10621     {
10622       rtx set = XVECEXP (operands[2], 0, i);
10623       emit_move_insn (SET_DEST (set), SET_SRC (set));
10624     }
10625
10626   /* The optimizer does not know that the call sets the function value
10627      registers we stored in the result block.  We avoid problems by
10628      claiming that all hard registers are used and clobbered at this
10629      point.  */
10630   emit_insn (gen_blockage ());
10631
10632   DONE;
10633 }")
10634
10635 ;; sibling call patterns
10636 (define_expand "sibcall"
10637   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10638                     (match_operand 1 "" ""))
10639               (use (match_operand 2 "" ""))
10640               (use (match_operand 3 "" ""))
10641               (return)])]
10642   ""
10643   "
10644 {
10645 #if TARGET_MACHO
10646   if (MACHOPIC_INDIRECT)
10647     operands[0] = machopic_indirect_call_target (operands[0]);
10648 #endif
10649
10650   if (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != CONST_INT)
10651     abort ();
10652
10653   operands[0] = XEXP (operands[0], 0);
10654   operands[3] = gen_reg_rtx (SImode);
10655
10656 }")
10657
10658 ;; this and similar patterns must be marked as using LR, otherwise
10659 ;; dataflow will try to delete the store into it.  This is true
10660 ;; even when the actual reg to jump to is in CTR, when LR was
10661 ;; saved and restored around the PIC-setting BCL.
10662 (define_insn "*sibcall_local32"
10663   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10664          (match_operand 1 "" "g,g"))
10665    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10666    (use (match_operand:SI 3 "register_operand" "l,l"))
10667    (return)]
10668   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10669   "*
10670 {
10671   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10672     output_asm_insn (\"crxor 6,6,6\", operands);
10673
10674   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10675     output_asm_insn (\"creqv 6,6,6\", operands);
10676
10677   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
10678 }"
10679   [(set_attr "type" "branch")
10680    (set_attr "length" "4,8")])
10681
10682 (define_insn "*sibcall_local64"
10683   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10684          (match_operand 1 "" "g,g"))
10685    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10686    (use (match_operand:SI 3 "register_operand" "l,l"))
10687    (return)]
10688   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10689   "*
10690 {
10691   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10692     output_asm_insn (\"crxor 6,6,6\", operands);
10693
10694   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10695     output_asm_insn (\"creqv 6,6,6\", operands);
10696
10697   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
10698 }"
10699   [(set_attr "type" "branch")
10700    (set_attr "length" "4,8")])
10701
10702 (define_insn "*sibcall_value_local32"
10703   [(set (match_operand 0 "" "")
10704         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10705               (match_operand 2 "" "g,g")))
10706    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10707    (use (match_operand:SI 4 "register_operand" "l,l"))
10708    (return)]
10709   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10710   "*
10711 {
10712   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10713     output_asm_insn (\"crxor 6,6,6\", operands);
10714
10715   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10716     output_asm_insn (\"creqv 6,6,6\", operands);
10717
10718   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
10719 }"
10720   [(set_attr "type" "branch")
10721    (set_attr "length" "4,8")])
10722
10723
10724 (define_insn "*sibcall_value_local64"
10725   [(set (match_operand 0 "" "")
10726         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10727               (match_operand 2 "" "g,g")))
10728    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10729    (use (match_operand:SI 4 "register_operand" "l,l"))
10730    (return)]
10731   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10732   "*
10733 {
10734   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10735     output_asm_insn (\"crxor 6,6,6\", operands);
10736
10737   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10738     output_asm_insn (\"creqv 6,6,6\", operands);
10739
10740   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
10741 }"
10742   [(set_attr "type" "branch")
10743    (set_attr "length" "4,8")])
10744
10745 (define_insn "*sibcall_nonlocal_aix32"
10746   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10747          (match_operand 1 "" "g"))
10748    (use (match_operand:SI 2 "immediate_operand" "O"))
10749    (use (match_operand:SI 3 "register_operand" "l"))
10750    (return)]
10751   "TARGET_32BIT
10752    && DEFAULT_ABI == ABI_AIX
10753    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10754   "b %z0"
10755   [(set_attr "type" "branch")
10756    (set_attr "length" "4")])
10757
10758 (define_insn "*sibcall_nonlocal_aix64"
10759   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10760          (match_operand 1 "" "g"))
10761    (use (match_operand:SI 2 "immediate_operand" "O"))
10762    (use (match_operand:SI 3 "register_operand" "l"))
10763    (return)]
10764   "TARGET_64BIT 
10765    && DEFAULT_ABI == ABI_AIX
10766    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10767   "b %z0"
10768   [(set_attr "type" "branch")
10769    (set_attr "length" "4")])
10770
10771 (define_insn "*sibcall_value_nonlocal_aix32"
10772   [(set (match_operand 0 "" "")
10773         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10774               (match_operand 2 "" "g")))
10775    (use (match_operand:SI 3 "immediate_operand" "O"))
10776    (use (match_operand:SI 4 "register_operand" "l"))
10777    (return)]
10778   "TARGET_32BIT
10779    && DEFAULT_ABI == ABI_AIX
10780    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10781   "b %z1"
10782   [(set_attr "type" "branch")
10783    (set_attr "length" "4")])
10784
10785 (define_insn "*sibcall_value_nonlocal_aix64"
10786   [(set (match_operand 0 "" "")
10787         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10788               (match_operand 2 "" "g")))
10789    (use (match_operand:SI 3 "immediate_operand" "O"))
10790    (use (match_operand:SI 4 "register_operand" "l"))
10791    (return)]
10792   "TARGET_64BIT 
10793    && DEFAULT_ABI == ABI_AIX
10794    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10795   "b %z1"
10796   [(set_attr "type" "branch")
10797    (set_attr "length" "4")])
10798
10799 (define_insn "*sibcall_nonlocal_sysv"
10800   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s,s"))
10801          (match_operand 1 "" ""))
10802    (use (match_operand 2 "immediate_operand" "O,n"))
10803    (use (match_operand:SI 3 "register_operand" "l,l"))
10804    (return)]
10805   "(DEFAULT_ABI == ABI_DARWIN
10806      || DEFAULT_ABI == ABI_V4)
10807    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10808   "*
10809 {
10810   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10811     output_asm_insn (\"crxor 6,6,6\", operands);
10812
10813   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10814     output_asm_insn (\"creqv 6,6,6\", operands);
10815
10816   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@plt\" : \"b %z0\";
10817 }"
10818   [(set_attr "type" "branch,branch")
10819    (set_attr "length" "4,8")])
10820
10821 (define_expand "sibcall_value"
10822   [(parallel [(set (match_operand 0 "register_operand" "")
10823                 (call (mem:SI (match_operand 1 "address_operand" ""))
10824                       (match_operand 2 "" "")))
10825               (use (match_operand 3 "" ""))
10826               (use (match_operand 4 "" ""))
10827               (return)])]
10828   ""
10829   "
10830 {
10831 #if TARGET_MACHO
10832   if (MACHOPIC_INDIRECT)
10833     operands[1] = machopic_indirect_call_target (operands[1]);
10834 #endif
10835
10836   if (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != CONST_INT)
10837     abort ();
10838
10839   operands[1] = XEXP (operands[1], 0);
10840   operands[4] = gen_reg_rtx (SImode);
10841
10842 }")
10843
10844 (define_insn "*sibcall_value_nonlocal_sysv"
10845   [(set (match_operand 0 "" "")
10846         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s,s"))
10847               (match_operand 2 "" "")))
10848    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10849    (use (match_operand:SI 4 "register_operand" "l,l"))
10850    (return)]
10851   "(DEFAULT_ABI == ABI_DARWIN
10852        || DEFAULT_ABI == ABI_V4)
10853    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10854   "*
10855 {
10856   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10857     output_asm_insn (\"crxor 6,6,6\", operands);
10858
10859   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10860     output_asm_insn (\"creqv 6,6,6\", operands);
10861
10862   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@plt\" : \"b %z1\";
10863 }"
10864   [(set_attr "type" "branch,branch")
10865    (set_attr "length" "4,8")])
10866
10867 (define_expand "sibcall_epilogue"
10868   [(use (const_int 0))]
10869   "TARGET_SCHED_PROLOG"
10870   "
10871 {
10872       rs6000_emit_epilogue (TRUE);
10873       DONE;
10874 }")
10875
10876 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
10877 ;; all of memory.  This blocks insns from being moved across this point.
10878
10879 (define_insn "blockage"
10880   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
10881   ""
10882   "")
10883 \f
10884 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
10885 ;; signed & unsigned, and one type of branch.
10886 ;;
10887 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
10888 ;; insns, and branches.  We store the operands of compares until we see
10889 ;; how it is used.
10890 (define_expand "cmpsi"
10891   [(set (cc0)
10892         (compare (match_operand:SI 0 "gpc_reg_operand" "")
10893                  (match_operand:SI 1 "reg_or_short_operand" "")))]
10894   ""
10895   "
10896 {
10897   /* Take care of the possibility that operands[1] might be negative but
10898      this might be a logical operation.  That insn doesn't exist.  */
10899   if (GET_CODE (operands[1]) == CONST_INT
10900       && INTVAL (operands[1]) < 0)
10901     operands[1] = force_reg (SImode, operands[1]);
10902
10903   rs6000_compare_op0 = operands[0];
10904   rs6000_compare_op1 = operands[1];
10905   rs6000_compare_fp_p = 0;
10906   DONE;
10907 }")
10908
10909 (define_expand "cmpdi"
10910   [(set (cc0)
10911         (compare (match_operand:DI 0 "gpc_reg_operand" "")
10912                  (match_operand:DI 1 "reg_or_short_operand" "")))]
10913   "TARGET_POWERPC64"
10914   "
10915 {
10916   /* Take care of the possibility that operands[1] might be negative but
10917      this might be a logical operation.  That insn doesn't exist.  */
10918   if (GET_CODE (operands[1]) == CONST_INT
10919       && INTVAL (operands[1]) < 0)
10920     operands[1] = force_reg (DImode, operands[1]);
10921
10922   rs6000_compare_op0 = operands[0];
10923   rs6000_compare_op1 = operands[1];
10924   rs6000_compare_fp_p = 0;
10925   DONE;
10926 }")
10927
10928 (define_expand "cmpsf"
10929   [(set (cc0) (compare (match_operand:SF 0 "gpc_reg_operand" "")
10930                        (match_operand:SF 1 "gpc_reg_operand" "")))]
10931   "TARGET_HARD_FLOAT"
10932   "
10933 {
10934   rs6000_compare_op0 = operands[0];
10935   rs6000_compare_op1 = operands[1];
10936   rs6000_compare_fp_p = 1;
10937   DONE;
10938 }")
10939
10940 (define_expand "cmpdf"
10941   [(set (cc0) (compare (match_operand:DF 0 "gpc_reg_operand" "")
10942                        (match_operand:DF 1 "gpc_reg_operand" "")))]
10943   "TARGET_HARD_FLOAT && TARGET_FPRS"
10944   "
10945 {
10946   rs6000_compare_op0 = operands[0];
10947   rs6000_compare_op1 = operands[1];
10948   rs6000_compare_fp_p = 1;
10949   DONE;
10950 }")
10951
10952 (define_expand "cmptf"
10953   [(set (cc0) (compare (match_operand:TF 0 "gpc_reg_operand" "")
10954                        (match_operand:TF 1 "gpc_reg_operand" "")))]
10955   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
10956    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
10957   "
10958 {
10959   rs6000_compare_op0 = operands[0];
10960   rs6000_compare_op1 = operands[1];
10961   rs6000_compare_fp_p = 1;
10962   DONE;
10963 }")
10964
10965 (define_expand "beq"
10966   [(use (match_operand 0 "" ""))]
10967   ""
10968   "{ rs6000_emit_cbranch (EQ, operands[0]); DONE; }")
10969
10970 (define_expand "bne"
10971   [(use (match_operand 0 "" ""))]
10972   ""
10973   "{ rs6000_emit_cbranch (NE, operands[0]); DONE; }")
10974
10975 (define_expand "bge"
10976   [(use (match_operand 0 "" ""))]
10977   ""
10978   "{ rs6000_emit_cbranch (GE, operands[0]); DONE; }")
10979
10980 (define_expand "bgt"
10981   [(use (match_operand 0 "" ""))]
10982   ""
10983   "{ rs6000_emit_cbranch (GT, operands[0]); DONE; }")
10984
10985 (define_expand "ble"
10986   [(use (match_operand 0 "" ""))]
10987   ""
10988   "{ rs6000_emit_cbranch (LE, operands[0]); DONE; }")
10989
10990 (define_expand "blt"
10991   [(use (match_operand 0 "" ""))]
10992   ""
10993   "{ rs6000_emit_cbranch (LT, operands[0]); DONE; }")
10994
10995 (define_expand "bgeu"
10996   [(use (match_operand 0 "" ""))]
10997   ""
10998   "{ rs6000_emit_cbranch (GEU, operands[0]); DONE; }")
10999
11000 (define_expand "bgtu"
11001   [(use (match_operand 0 "" ""))]
11002   ""
11003   "{ rs6000_emit_cbranch (GTU, operands[0]); DONE; }")
11004
11005 (define_expand "bleu"
11006   [(use (match_operand 0 "" ""))]
11007   ""
11008   "{ rs6000_emit_cbranch (LEU, operands[0]); DONE; }")
11009
11010 (define_expand "bltu"
11011   [(use (match_operand 0 "" ""))]
11012   ""
11013   "{ rs6000_emit_cbranch (LTU, operands[0]); DONE; }")
11014
11015 (define_expand "bunordered"
11016   [(use (match_operand 0 "" ""))]
11017   ""
11018   "{ rs6000_emit_cbranch (UNORDERED, operands[0]); DONE; }")
11019
11020 (define_expand "bordered"
11021   [(use (match_operand 0 "" ""))]
11022   ""
11023   "{ rs6000_emit_cbranch (ORDERED, operands[0]); DONE; }")
11024
11025 (define_expand "buneq"
11026   [(use (match_operand 0 "" ""))]
11027   ""
11028   "{ rs6000_emit_cbranch (UNEQ, operands[0]); DONE; }")
11029
11030 (define_expand "bunge"
11031   [(use (match_operand 0 "" ""))]
11032   ""
11033   "{ rs6000_emit_cbranch (UNGE, operands[0]); DONE; }")
11034
11035 (define_expand "bungt"
11036   [(use (match_operand 0 "" ""))]
11037   ""
11038   "{ rs6000_emit_cbranch (UNGT, operands[0]); DONE; }")
11039
11040 (define_expand "bunle"
11041   [(use (match_operand 0 "" ""))]
11042   ""
11043   "{ rs6000_emit_cbranch (UNLE, operands[0]); DONE; }")
11044
11045 (define_expand "bunlt"
11046   [(use (match_operand 0 "" ""))]
11047   ""
11048   "{ rs6000_emit_cbranch (UNLT, operands[0]); DONE; }")
11049
11050 (define_expand "bltgt"
11051   [(use (match_operand 0 "" ""))]
11052   ""
11053   "{ rs6000_emit_cbranch (LTGT, operands[0]); DONE; }")
11054
11055 ;; For SNE, we would prefer that the xor/abs sequence be used for integers.
11056 ;; For SEQ, likewise, except that comparisons with zero should be done
11057 ;; with an scc insns.  However, due to the order that combine see the
11058 ;; resulting insns, we must, in fact, allow SEQ for integers.  Fail in
11059 ;; the cases we don't want to handle.
11060 (define_expand "seq"
11061   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11062   ""
11063   "{ rs6000_emit_sCOND (EQ, operands[0]); DONE; }")
11064
11065 (define_expand "sne"
11066   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11067   ""
11068   "
11069
11070   if (! rs6000_compare_fp_p)
11071     FAIL;
11072
11073   rs6000_emit_sCOND (NE, operands[0]); 
11074   DONE;
11075 }")
11076
11077 ;; A >= 0 is best done the portable way for A an integer.
11078 (define_expand "sge"
11079   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11080   ""
11081   "
11082 {
11083   if (! rs6000_compare_fp_p
11084       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
11085     FAIL;
11086
11087   rs6000_emit_sCOND (GE, operands[0]);
11088   DONE;
11089 }")
11090
11091 ;; A > 0 is best done using the portable sequence, so fail in that case.
11092 (define_expand "sgt"
11093   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11094   ""
11095   "
11096 {
11097   if (! rs6000_compare_fp_p
11098       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
11099     FAIL;
11100
11101   rs6000_emit_sCOND (GT, operands[0]); 
11102   DONE;
11103 }")
11104
11105 ;; A <= 0 is best done the portable way for A an integer.
11106 (define_expand "sle"
11107   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11108   ""
11109   "
11110 {
11111   if (! rs6000_compare_fp_p
11112       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
11113     FAIL;
11114
11115   rs6000_emit_sCOND (LE, operands[0]); 
11116   DONE;
11117 }")
11118
11119 ;; A < 0 is best done in the portable way for A an integer.
11120 (define_expand "slt"
11121   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11122   ""
11123   "
11124 {
11125   if (! rs6000_compare_fp_p 
11126       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
11127     FAIL;
11128
11129   rs6000_emit_sCOND (LT, operands[0]); 
11130   DONE;
11131 }")
11132
11133 (define_expand "sgeu"
11134   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11135   ""
11136   "{ rs6000_emit_sCOND (GEU, operands[0]); DONE; }")
11137
11138 (define_expand "sgtu"
11139   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11140   ""
11141   "{ rs6000_emit_sCOND (GTU, operands[0]); DONE; }")
11142
11143 (define_expand "sleu"
11144   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11145   ""
11146   "{ rs6000_emit_sCOND (LEU, operands[0]); DONE; }")
11147
11148 (define_expand "sltu"
11149   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11150   ""
11151   "{ rs6000_emit_sCOND (LTU, operands[0]); DONE; }")
11152
11153 (define_expand "sunordered"
11154   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11155   ""
11156   "{ rs6000_emit_sCOND (UNORDERED, operands[0]); DONE; }")
11157
11158 (define_expand "sordered"
11159   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11160   ""
11161   "{ rs6000_emit_sCOND (ORDERED, operands[0]); DONE; }")
11162
11163 (define_expand "suneq"
11164   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11165   ""
11166   "{ rs6000_emit_sCOND (UNEQ, operands[0]); DONE; }")
11167
11168 (define_expand "sunge"
11169   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11170   ""
11171   "{ rs6000_emit_sCOND (UNGE, operands[0]); DONE; }")
11172
11173 (define_expand "sungt"
11174   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11175   ""
11176   "{ rs6000_emit_sCOND (UNGT, operands[0]); DONE; }")
11177
11178 (define_expand "sunle"
11179   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11180   ""
11181   "{ rs6000_emit_sCOND (UNLE, operands[0]); DONE; }")
11182
11183 (define_expand "sunlt"
11184   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11185   ""
11186   "{ rs6000_emit_sCOND (UNLT, operands[0]); DONE; }")
11187
11188 (define_expand "sltgt"
11189   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11190   ""
11191   "{ rs6000_emit_sCOND (LTGT, operands[0]); DONE; }")
11192
11193 \f
11194 ;; Here are the actual compare insns.
11195 (define_insn "*cmpsi_internal1"
11196   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11197         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11198                     (match_operand:SI 2 "reg_or_short_operand" "rI")))]
11199   ""
11200   "{cmp%I2|cmpw%I2} %0,%1,%2"
11201   [(set_attr "type" "cmp")])
11202
11203 (define_insn "*cmpdi_internal1"
11204   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11205         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "r")
11206                     (match_operand:DI 2 "reg_or_short_operand" "rI")))]
11207   "TARGET_POWERPC64"
11208   "cmpd%I2 %0,%1,%2"
11209   [(set_attr "type" "cmp")])
11210
11211 ;; If we are comparing a register for equality with a large constant,
11212 ;; we can do this with an XOR followed by a compare.  But we need a scratch
11213 ;; register for the result of the XOR.
11214
11215 (define_split
11216   [(set (match_operand:CC 0 "cc_reg_operand" "")
11217         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11218                     (match_operand:SI 2 "non_short_cint_operand" "")))
11219    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
11220   "find_single_use (operands[0], insn, 0)
11221    && (GET_CODE (*find_single_use (operands[0], insn, 0)) == EQ
11222        || GET_CODE (*find_single_use (operands[0], insn, 0)) == NE)"
11223   [(set (match_dup 3) (xor:SI (match_dup 1) (match_dup 4)))
11224    (set (match_dup 0) (compare:CC (match_dup 3) (match_dup 5)))]
11225   "
11226 {
11227   /* Get the constant we are comparing against, C,  and see what it looks like
11228      sign-extended to 16 bits.  Then see what constant could be XOR'ed
11229      with C to get the sign-extended value.  */
11230
11231   HOST_WIDE_INT c = INTVAL (operands[2]);
11232   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
11233   HOST_WIDE_INT xorv = c ^ sextc;
11234
11235   operands[4] = GEN_INT (xorv);
11236   operands[5] = GEN_INT (sextc);
11237 }")
11238
11239 (define_insn "*cmpsi_internal2"
11240   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11241         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11242                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
11243   ""
11244   "{cmpl%I2|cmplw%I2} %0,%1,%b2"
11245   [(set_attr "type" "cmp")])
11246
11247 (define_insn "*cmpdi_internal2"
11248   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11249         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
11250                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
11251   ""
11252   "cmpld%I2 %0,%1,%b2"
11253   [(set_attr "type" "cmp")])
11254
11255 ;; The following two insns don't exist as single insns, but if we provide
11256 ;; them, we can swap an add and compare, which will enable us to overlap more
11257 ;; of the required delay between a compare and branch.  We generate code for
11258 ;; them by splitting.
11259
11260 (define_insn ""
11261   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
11262         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11263                     (match_operand:SI 2 "short_cint_operand" "i")))
11264    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11265         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11266   ""
11267   "#"
11268   [(set_attr "length" "8")])
11269
11270 (define_insn ""
11271   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
11272         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11273                        (match_operand:SI 2 "u_short_cint_operand" "i")))
11274    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11275         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11276   ""
11277   "#"
11278   [(set_attr "length" "8")])
11279
11280 (define_split
11281   [(set (match_operand:CC 3 "cc_reg_operand" "")
11282         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11283                     (match_operand:SI 2 "short_cint_operand" "")))
11284    (set (match_operand:SI 0 "gpc_reg_operand" "")
11285         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11286   ""
11287   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
11288    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11289
11290 (define_split
11291   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
11292         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
11293                        (match_operand:SI 2 "u_short_cint_operand" "")))
11294    (set (match_operand:SI 0 "gpc_reg_operand" "")
11295         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11296   ""
11297   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
11298    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11299
11300 (define_insn "*cmpsf_internal1"
11301   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11302         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
11303                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
11304   "TARGET_HARD_FLOAT && TARGET_FPRS"
11305   "fcmpu %0,%1,%2"
11306   [(set_attr "type" "fpcompare")])
11307
11308 (define_insn "*cmpdf_internal1"
11309   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11310         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "f")
11311                       (match_operand:DF 2 "gpc_reg_operand" "f")))]
11312   "TARGET_HARD_FLOAT && TARGET_FPRS"
11313   "fcmpu %0,%1,%2"
11314   [(set_attr "type" "fpcompare")])
11315
11316 ;; Only need to compare second words if first words equal
11317 (define_insn "*cmptf_internal1"
11318   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11319         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11320                       (match_operand:TF 2 "gpc_reg_operand" "f")))]
11321   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN) && !TARGET_XL_COMPAT
11322    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
11323   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
11324   [(set_attr "type" "fpcompare")
11325    (set_attr "length" "12")])
11326
11327 (define_insn_and_split "*cmptf_internal2"
11328   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11329         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11330                       (match_operand:TF 2 "gpc_reg_operand" "f")))
11331     (clobber (match_scratch:DF 3 "=f"))
11332     (clobber (match_scratch:DF 4 "=f"))
11333     (clobber (match_scratch:DF 5 "=f"))
11334     (clobber (match_scratch:DF 6 "=f"))
11335     (clobber (match_scratch:DF 7 "=f"))
11336     (clobber (match_scratch:DF 8 "=f"))
11337     (clobber (match_scratch:DF 9 "=f"))
11338     (clobber (match_scratch:DF 10 "=f"))]
11339   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN) && TARGET_XL_COMPAT
11340    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
11341   "#"
11342   "&& reload_completed"
11343   [(set (match_dup 3) (match_dup 13))
11344    (set (match_dup 4) (match_dup 14))
11345    (set (match_dup 9) (abs:DF (match_dup 5)))
11346    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
11347    (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
11348                            (label_ref (match_dup 11))
11349                            (pc)))
11350    (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
11351    (set (pc) (label_ref (match_dup 12)))
11352    (match_dup 11)
11353    (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
11354    (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
11355    (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
11356    (set (match_dup 0) (compare:CCFP (match_dup 7) (match_dup 4)))
11357    (match_dup 12)]
11358 {
11359   REAL_VALUE_TYPE rv;
11360   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
11361   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
11362
11363   operands[5] = simplify_gen_subreg (DFmode, operands[1], TFmode, hi_word);
11364   operands[6] = simplify_gen_subreg (DFmode, operands[1], TFmode, lo_word);
11365   operands[7] = simplify_gen_subreg (DFmode, operands[2], TFmode, hi_word);
11366   operands[8] = simplify_gen_subreg (DFmode, operands[2], TFmode, lo_word);
11367   operands[11] = gen_label_rtx ();
11368   operands[12] = gen_label_rtx ();
11369   real_inf (&rv);
11370   operands[13] = force_const_mem (DFmode,
11371                                   CONST_DOUBLE_FROM_REAL_VALUE (rv, DFmode));
11372   operands[14] = force_const_mem (DFmode,
11373                                   CONST_DOUBLE_FROM_REAL_VALUE (dconst0,
11374                                                                 DFmode));
11375   if (TARGET_TOC)
11376     {
11377       operands[13] = gen_rtx_MEM (DFmode,
11378                                   create_TOC_reference (XEXP (operands[13], 0)));
11379       operands[14] = gen_rtx_MEM (DFmode,
11380                                   create_TOC_reference (XEXP (operands[14], 0)));
11381       set_mem_alias_set (operands[13], get_TOC_alias_set ());
11382       set_mem_alias_set (operands[14], get_TOC_alias_set ());
11383       RTX_UNCHANGING_P (operands[13]) = 1;
11384       RTX_UNCHANGING_P (operands[14]) = 1;
11385     }
11386 })
11387 \f
11388 ;; Now we have the scc insns.  We can do some combinations because of the
11389 ;; way the machine works.
11390 ;;
11391 ;; Note that this is probably faster if we can put an insn between the
11392 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
11393 ;; cases the insns below which don't use an intermediate CR field will
11394 ;; be used instead.
11395 (define_insn ""
11396   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11397         (match_operator:SI 1 "scc_comparison_operator"
11398                            [(match_operand 2 "cc_reg_operand" "y")
11399                             (const_int 0)]))]
11400   ""
11401   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11402   [(set (attr "type")
11403      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11404                 (const_string "mfcrf")
11405            ]
11406         (const_string "mfcr")))
11407    (set_attr "length" "12")])
11408
11409 ;; Same as above, but get the EQ bit.
11410 (define_insn "move_from_CR_eq_bit"
11411   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11412        (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_EQ))]
11413   "TARGET_E500"
11414   "mfcr %0\;{rlinm|rlwinm} %0,%0,%D1,1"
11415   [(set_attr "type" "mfcr")
11416    (set_attr "length" "12")])
11417
11418 ;; Same as above, but get the OV/ORDERED bit.
11419 (define_insn "move_from_CR_ov_bit"
11420   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11421         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_OV))]
11422   "TARGET_ISEL"
11423   "mfcr %0\;{rlinm|rlwinm} %0,%0,%t1,1"
11424   [(set_attr "type" "mfcr")
11425    (set_attr "length" "12")])
11426
11427 (define_insn ""
11428   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11429         (match_operator:DI 1 "scc_comparison_operator"
11430                            [(match_operand 2 "cc_reg_operand" "y")
11431                             (const_int 0)]))]
11432   "TARGET_POWERPC64"
11433   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11434   [(set (attr "type")
11435      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11436                 (const_string "mfcrf")
11437            ]
11438         (const_string "mfcr")))
11439    (set_attr "length" "12")])
11440
11441 (define_insn ""
11442   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11443         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11444                                        [(match_operand 2 "cc_reg_operand" "y,y")
11445                                         (const_int 0)])
11446                     (const_int 0)))
11447    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11448         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11449   "TARGET_32BIT"
11450   "@
11451    mfcr %3%Q2\;{rlinm.|rlwinm.} %3,%3,%J1,1
11452    #"
11453   [(set_attr "type" "delayed_compare")
11454    (set_attr "length" "12,16")])
11455
11456 (define_split
11457   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11458         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11459                                        [(match_operand 2 "cc_reg_operand" "")
11460                                         (const_int 0)])
11461                     (const_int 0)))
11462    (set (match_operand:SI 3 "gpc_reg_operand" "")
11463         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11464   "TARGET_32BIT && reload_completed"
11465   [(set (match_dup 3)
11466         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
11467    (set (match_dup 0)
11468         (compare:CC (match_dup 3)
11469                     (const_int 0)))]
11470   "")
11471
11472 (define_insn ""
11473   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11474         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11475                                       [(match_operand 2 "cc_reg_operand" "y")
11476                                        (const_int 0)])
11477                    (match_operand:SI 3 "const_int_operand" "n")))]
11478   ""
11479   "*
11480 {
11481   int is_bit = ccr_bit (operands[1], 1);
11482   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11483   int count;
11484
11485   if (is_bit >= put_bit)
11486     count = is_bit - put_bit;
11487   else
11488     count = 32 - (put_bit - is_bit);
11489
11490   operands[4] = GEN_INT (count);
11491   operands[5] = GEN_INT (put_bit);
11492
11493   return \"mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
11494 }"
11495   [(set (attr "type")
11496      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11497                 (const_string "mfcrf")
11498            ]
11499         (const_string "mfcr")))
11500    (set_attr "length" "12")])
11501
11502 (define_insn ""
11503   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11504         (compare:CC
11505          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11506                                        [(match_operand 2 "cc_reg_operand" "y,y")
11507                                         (const_int 0)])
11508                     (match_operand:SI 3 "const_int_operand" "n,n"))
11509          (const_int 0)))
11510    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
11511         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11512                    (match_dup 3)))]
11513   ""
11514   "*
11515 {
11516   int is_bit = ccr_bit (operands[1], 1);
11517   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11518   int count;
11519
11520   /* Force split for non-cc0 compare.  */
11521   if (which_alternative == 1)
11522      return \"#\";
11523
11524   if (is_bit >= put_bit)
11525     count = is_bit - put_bit;
11526   else
11527     count = 32 - (put_bit - is_bit);
11528
11529   operands[5] = GEN_INT (count);
11530   operands[6] = GEN_INT (put_bit);
11531
11532   return \"mfcr %4%Q2\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
11533 }"
11534   [(set_attr "type" "delayed_compare")
11535    (set_attr "length" "12,16")])
11536
11537 (define_split
11538   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11539         (compare:CC
11540          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11541                                        [(match_operand 2 "cc_reg_operand" "")
11542                                         (const_int 0)])
11543                     (match_operand:SI 3 "const_int_operand" ""))
11544          (const_int 0)))
11545    (set (match_operand:SI 4 "gpc_reg_operand" "")
11546         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11547                    (match_dup 3)))]
11548   "reload_completed"
11549   [(set (match_dup 4)
11550         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11551                    (match_dup 3)))
11552    (set (match_dup 0)
11553         (compare:CC (match_dup 4)
11554                     (const_int 0)))]
11555   "")
11556
11557 ;; There is a 3 cycle delay between consecutive mfcr instructions
11558 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
11559
11560 (define_peephole
11561   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11562         (match_operator:SI 1 "scc_comparison_operator"
11563                            [(match_operand 2 "cc_reg_operand" "y")
11564                             (const_int 0)]))
11565    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
11566         (match_operator:SI 4 "scc_comparison_operator"
11567                            [(match_operand 5 "cc_reg_operand" "y")
11568                             (const_int 0)]))]
11569   "REGNO (operands[2]) != REGNO (operands[5])"
11570   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11571   [(set_attr "type" "mfcr")
11572    (set_attr "length" "20")])
11573
11574 (define_peephole
11575   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11576         (match_operator:DI 1 "scc_comparison_operator"
11577                            [(match_operand 2 "cc_reg_operand" "y")
11578                             (const_int 0)]))
11579    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
11580         (match_operator:DI 4 "scc_comparison_operator"
11581                            [(match_operand 5 "cc_reg_operand" "y")
11582                             (const_int 0)]))]
11583   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
11584   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11585   [(set_attr "type" "mfcr")
11586    (set_attr "length" "20")])
11587
11588 ;; There are some scc insns that can be done directly, without a compare.
11589 ;; These are faster because they don't involve the communications between
11590 ;; the FXU and branch units.   In fact, we will be replacing all of the
11591 ;; integer scc insns here or in the portable methods in emit_store_flag.
11592 ;;
11593 ;; Also support (neg (scc ..)) since that construct is used to replace
11594 ;; branches, (plus (scc ..) ..) since that construct is common and
11595 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
11596 ;; cases where it is no more expensive than (neg (scc ..)).
11597
11598 ;; Have reload force a constant into a register for the simple insns that
11599 ;; otherwise won't accept constants.  We do this because it is faster than
11600 ;; the cmp/mfcr sequence we would otherwise generate.
11601
11602 (define_insn ""
11603   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
11604         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11605                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I")))
11606    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
11607   "TARGET_32BIT"
11608   "@
11609    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11610    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
11611    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11612    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11613    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
11614   [(set_attr "length" "12,8,12,12,12")])
11615
11616 (define_insn ""
11617   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r")
11618         (eq:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r")
11619                (match_operand:DI 2 "reg_or_cint_operand" "r,O,K,J,I")))
11620    (clobber (match_scratch:DI 3 "=r,&r,r,r,r"))]
11621   "TARGET_64BIT"
11622   "@
11623    xor %0,%1,%2\;subfic %3,%0,0\;adde %0,%3,%0
11624    subfic %3,%1,0\;adde %0,%3,%1
11625    xori %0,%1,%b2\;subfic %3,%0,0\;adde %0,%3,%0
11626    xoris %0,%1,%u2\;subfic %3,%0,0\;adde %0,%3,%0
11627    subfic %0,%1,%2\;subfic %3,%0,0\;adde %0,%3,%0"
11628   [(set_attr "length" "12,8,12,12,12")])
11629
11630 (define_insn ""
11631   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11632         (compare:CC
11633          (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11634                 (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11635          (const_int 0)))
11636    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
11637         (eq:SI (match_dup 1) (match_dup 2)))
11638    (clobber (match_scratch:SI 3 "=r,&r,r,r,r,r,&r,r,r,r"))]
11639   "TARGET_32BIT"
11640   "@
11641    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11642    {sfi|subfic} %3,%1,0\;{ae.|adde.} %0,%3,%1
11643    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11644    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11645    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11646    #
11647    #
11648    #
11649    #
11650    #"
11651   [(set_attr "type" "compare")
11652    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11653
11654 (define_split
11655   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11656         (compare:CC
11657          (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11658                 (match_operand:SI 2 "reg_or_cint_operand" ""))
11659          (const_int 0)))
11660    (set (match_operand:SI 0 "gpc_reg_operand" "")
11661         (eq:SI (match_dup 1) (match_dup 2)))
11662    (clobber (match_scratch:SI 3 ""))]
11663   "TARGET_32BIT && reload_completed"
11664   [(parallel [(set (match_dup 0)
11665         (eq:SI (match_dup 1) (match_dup 2)))
11666    (clobber (match_dup 3))])
11667    (set (match_dup 4)
11668         (compare:CC (match_dup 0)
11669                     (const_int 0)))]
11670   "")
11671
11672 (define_insn ""
11673   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11674         (compare:CC
11675          (eq:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11676                 (match_operand:DI 2 "reg_or_cint_operand" "r,O,K,J,I,r,O,K,J,I"))
11677          (const_int 0)))
11678    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
11679         (eq:DI (match_dup 1) (match_dup 2)))
11680    (clobber (match_scratch:DI 3 "=r,&r,r,r,r,r,&r,r,r,r"))]
11681   "TARGET_64BIT"
11682   "@
11683    xor %0,%1,%2\;subfic %3,%0,0\;adde. %0,%3,%0
11684    subfic %3,%1,0\;adde. %0,%3,%1
11685    xori %0,%1,%b2\;subfic %3,%0,0\;adde. %0,%3,%0
11686    xoris %0,%1,%u2\;subfic %3,%0,0\;adde. %0,%3,%0
11687    subfic %0,%1,%2\;subfic %3,%0,0\;adde. %0,%3,%0
11688    #
11689    #
11690    #
11691    #
11692    #"
11693   [(set_attr "type" "compare")
11694    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11695
11696 (define_split
11697   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11698         (compare:CC
11699          (eq:DI (match_operand:DI 1 "gpc_reg_operand" "")
11700                 (match_operand:DI 2 "reg_or_cint_operand" ""))
11701          (const_int 0)))
11702    (set (match_operand:DI 0 "gpc_reg_operand" "")
11703         (eq:DI (match_dup 1) (match_dup 2)))
11704    (clobber (match_scratch:DI 3 ""))]
11705   "TARGET_64BIT && reload_completed"
11706   [(parallel [(set (match_dup 0)
11707         (eq:DI (match_dup 1) (match_dup 2)))
11708    (clobber (match_dup 3))])
11709    (set (match_dup 4)
11710         (compare:CC (match_dup 0)
11711                     (const_int 0)))]
11712   "")
11713
11714 ;; We have insns of the form shown by the first define_insn below.  If
11715 ;; there is something inside the comparison operation, we must split it.
11716 (define_split
11717   [(set (match_operand:SI 0 "gpc_reg_operand" "")
11718         (plus:SI (match_operator 1 "comparison_operator"
11719                                  [(match_operand:SI 2 "" "")
11720                                   (match_operand:SI 3
11721                                                     "reg_or_cint_operand" "")])
11722                  (match_operand:SI 4 "gpc_reg_operand" "")))
11723    (clobber (match_operand:SI 5 "register_operand" ""))]
11724   "! gpc_reg_operand (operands[2], SImode)"
11725   [(set (match_dup 5) (match_dup 2))
11726    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
11727                                (match_dup 4)))])
11728
11729 (define_insn ""
11730   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
11731         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11732                         (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I"))
11733                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
11734   "TARGET_32BIT"
11735   "@
11736    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11737    {sfi|subfic} %0,%1,0\;{aze|addze} %0,%3
11738    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11739    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11740    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
11741   [(set_attr "length" "12,8,12,12,12")])
11742
11743 (define_insn ""
11744   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11745         (compare:CC
11746          (plus:SI
11747           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11748                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11749           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11750          (const_int 0)))
11751    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
11752   "TARGET_32BIT"
11753   "@
11754    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11755    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
11756    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11757    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11758    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11759    #
11760    #
11761    #
11762    #
11763    #"
11764   [(set_attr "type" "compare")
11765    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11766
11767 (define_split
11768   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11769         (compare:CC
11770          (plus:SI
11771           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11772                  (match_operand:SI 2 "reg_or_cint_operand" ""))
11773           (match_operand:SI 3 "gpc_reg_operand" ""))
11774          (const_int 0)))
11775    (clobber (match_scratch:SI 4 ""))]
11776   "TARGET_32BIT && reload_completed"
11777   [(set (match_dup 4)
11778         (plus:SI (eq:SI (match_dup 1)
11779                  (match_dup 2))
11780           (match_dup 3)))
11781    (set (match_dup 0)
11782         (compare:CC (match_dup 4)
11783                     (const_int 0)))]
11784   "")
11785
11786 (define_insn ""
11787   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11788         (compare:CC
11789          (plus:SI
11790           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11791                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11792           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11793          (const_int 0)))
11794    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
11795         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11796   "TARGET_32BIT"
11797   "@
11798    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11799    {sfi|subfic} %0,%1,0\;{aze.|addze.} %0,%3
11800    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11801    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11802    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11803    #
11804    #
11805    #
11806    #
11807    #"
11808   [(set_attr "type" "compare")
11809    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11810
11811 (define_split
11812   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11813         (compare:CC
11814          (plus:SI
11815           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11816                  (match_operand:SI 2 "reg_or_cint_operand" ""))
11817           (match_operand:SI 3 "gpc_reg_operand" ""))
11818          (const_int 0)))
11819    (set (match_operand:SI 0 "gpc_reg_operand" "")
11820         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11821   "TARGET_32BIT && reload_completed"
11822   [(set (match_dup 0)
11823         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
11824    (set (match_dup 4)
11825         (compare:CC (match_dup 0)
11826                     (const_int 0)))]
11827   "")
11828
11829 (define_insn ""
11830   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
11831         (neg:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11832                        (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I"))))]
11833   "TARGET_32BIT"
11834   "@
11835    xor %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11836    {ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0
11837    {xoril|xori} %0,%1,%b2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11838    {xoriu|xoris} %0,%1,%u2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11839    {sfi|subfic} %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
11840    [(set_attr "length" "12,8,12,12,12")])
11841
11842 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
11843 ;; since it nabs/sr is just as fast.
11844 (define_insn "*ne0"
11845   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
11846         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
11847                      (const_int 31)))
11848    (clobber (match_scratch:SI 2 "=&r"))]
11849   "! TARGET_POWER && TARGET_32BIT && !TARGET_ISEL"
11850   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
11851   [(set_attr "length" "8")])
11852
11853 (define_insn ""
11854   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11855         (lshiftrt:DI (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
11856                      (const_int 63)))
11857    (clobber (match_scratch:DI 2 "=&r"))]
11858   "TARGET_64BIT"
11859   "addic %2,%1,-1\;subfe %0,%2,%1"
11860   [(set_attr "length" "8")])
11861
11862 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
11863 (define_insn ""
11864   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11865         (plus:SI (lshiftrt:SI
11866                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
11867                   (const_int 31))
11868                  (match_operand:SI 2 "gpc_reg_operand" "r")))
11869    (clobber (match_scratch:SI 3 "=&r"))]
11870   "TARGET_32BIT"
11871   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
11872   [(set_attr "length" "8")])
11873
11874 (define_insn ""
11875   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11876         (plus:DI (lshiftrt:DI
11877                   (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
11878                   (const_int 63))
11879                  (match_operand:DI 2 "gpc_reg_operand" "r")))
11880    (clobber (match_scratch:DI 3 "=&r"))]
11881   "TARGET_64BIT"
11882   "addic %3,%1,-1\;addze %0,%2"
11883   [(set_attr "length" "8")])
11884
11885 (define_insn ""
11886   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11887         (compare:CC
11888          (plus:SI (lshiftrt:SI
11889                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
11890                    (const_int 31))
11891                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
11892          (const_int 0)))
11893    (clobber (match_scratch:SI 3 "=&r,&r"))
11894    (clobber (match_scratch:SI 4 "=X,&r"))]
11895   "TARGET_32BIT"
11896   "@
11897    {ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2
11898    #"
11899   [(set_attr "type" "compare")
11900    (set_attr "length" "8,12")])
11901
11902 (define_split
11903   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11904         (compare:CC
11905          (plus:SI (lshiftrt:SI
11906                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11907                    (const_int 31))
11908                   (match_operand:SI 2 "gpc_reg_operand" ""))
11909          (const_int 0)))
11910    (clobber (match_scratch:SI 3 ""))
11911    (clobber (match_scratch:SI 4 ""))]
11912   "TARGET_32BIT && reload_completed"
11913   [(parallel [(set (match_dup 3)
11914                    (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1)))
11915                                          (const_int 31))
11916                             (match_dup 2)))
11917               (clobber (match_dup 4))])
11918    (set (match_dup 0)
11919         (compare:CC (match_dup 3)
11920                     (const_int 0)))]
11921   "")
11922
11923 (define_insn ""
11924   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11925         (compare:CC
11926          (plus:DI (lshiftrt:DI
11927                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
11928                    (const_int 63))
11929                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
11930          (const_int 0)))
11931    (clobber (match_scratch:DI 3 "=&r,&r"))]
11932   "TARGET_64BIT"
11933   "@
11934    addic %3,%1,-1\;addze. %3,%2
11935    #"
11936   [(set_attr "type" "compare")
11937    (set_attr "length" "8,12")])
11938
11939 (define_split
11940   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11941         (compare:CC
11942          (plus:DI (lshiftrt:DI
11943                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
11944                    (const_int 63))
11945                   (match_operand:DI 2 "gpc_reg_operand" ""))
11946          (const_int 0)))
11947    (clobber (match_scratch:DI 3 ""))]
11948   "TARGET_64BIT && reload_completed"
11949   [(set (match_dup 3)
11950         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1)))
11951                    (const_int 63))
11952                   (match_dup 2)))
11953    (set (match_dup 0)
11954         (compare:CC (match_dup 3)
11955                     (const_int 0)))]
11956   "")
11957
11958 (define_insn ""
11959   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
11960         (compare:CC
11961          (plus:SI (lshiftrt:SI
11962                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
11963                    (const_int 31))
11964                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
11965          (const_int 0)))
11966    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11967         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11968                  (match_dup 2)))
11969    (clobber (match_scratch:SI 3 "=&r,&r"))]
11970   "TARGET_32BIT"
11971   "@
11972    {ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2
11973    #"
11974   [(set_attr "type" "compare")
11975    (set_attr "length" "8,12")])
11976
11977 (define_split
11978   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11979         (compare:CC
11980          (plus:SI (lshiftrt:SI
11981                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11982                    (const_int 31))
11983                   (match_operand:SI 2 "gpc_reg_operand" ""))
11984          (const_int 0)))
11985    (set (match_operand:SI 0 "gpc_reg_operand" "")
11986         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11987                  (match_dup 2)))
11988    (clobber (match_scratch:SI 3 ""))]
11989   "TARGET_32BIT && reload_completed"
11990   [(parallel [(set (match_dup 0)
11991         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11992                  (match_dup 2)))
11993    (clobber (match_dup 3))])
11994    (set (match_dup 4)
11995         (compare:CC (match_dup 0)
11996                     (const_int 0)))]
11997   "")
11998
11999 (define_insn ""
12000   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12001         (compare:CC
12002          (plus:DI (lshiftrt:DI
12003                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
12004                    (const_int 63))
12005                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
12006          (const_int 0)))
12007    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12008         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
12009                  (match_dup 2)))
12010    (clobber (match_scratch:DI 3 "=&r,&r"))]
12011   "TARGET_64BIT"
12012   "@
12013    addic %3,%1,-1\;addze. %0,%2
12014    #"
12015   [(set_attr "type" "compare")
12016    (set_attr "length" "8,12")])
12017
12018 (define_split
12019   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12020         (compare:CC
12021          (plus:DI (lshiftrt:DI
12022                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
12023                    (const_int 63))
12024                   (match_operand:DI 2 "gpc_reg_operand" ""))
12025          (const_int 0)))
12026    (set (match_operand:DI 0 "gpc_reg_operand" "")
12027         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
12028                  (match_dup 2)))
12029    (clobber (match_scratch:DI 3 ""))]
12030   "TARGET_64BIT && reload_completed"
12031   [(parallel [(set (match_dup 0)
12032         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
12033                  (match_dup 2)))
12034    (clobber (match_dup 3))])
12035    (set (match_dup 4)
12036         (compare:CC (match_dup 0)
12037                     (const_int 0)))]
12038   "")
12039
12040 (define_insn ""
12041   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12042         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12043                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
12044    (clobber (match_scratch:SI 3 "=r,X"))]
12045   "TARGET_POWER"
12046   "@
12047    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
12048    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
12049   [(set_attr "length" "12")])
12050
12051 (define_insn ""
12052   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12053         (compare:CC
12054          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12055                 (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12056          (const_int 0)))
12057    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12058         (le:SI (match_dup 1) (match_dup 2)))
12059    (clobber (match_scratch:SI 3 "=r,X,r,X"))]
12060   "TARGET_POWER"
12061   "@
12062    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
12063    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31
12064    #
12065    #"
12066   [(set_attr "type" "compare,delayed_compare,compare,delayed_compare")
12067    (set_attr "length" "12,12,16,16")])
12068
12069 (define_split
12070   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12071         (compare:CC
12072          (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12073                 (match_operand:SI 2 "reg_or_short_operand" ""))
12074          (const_int 0)))
12075    (set (match_operand:SI 0 "gpc_reg_operand" "")
12076         (le:SI (match_dup 1) (match_dup 2)))
12077    (clobber (match_scratch:SI 3 ""))]
12078   "TARGET_POWER && reload_completed"
12079   [(parallel [(set (match_dup 0)
12080         (le:SI (match_dup 1) (match_dup 2)))
12081    (clobber (match_dup 3))])
12082    (set (match_dup 4)
12083         (compare:CC (match_dup 0)
12084                     (const_int 0)))]
12085   "")
12086
12087 (define_insn ""
12088   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12089         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12090                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
12091                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12092   "TARGET_POWER"
12093   "@
12094    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
12095    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze|addze} %0,%3"
12096   [(set_attr "length" "12")])
12097
12098 (define_insn ""
12099   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12100         (compare:CC
12101          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12102                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12103                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12104          (const_int 0)))
12105    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12106   "TARGET_POWER"
12107   "@
12108    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12109    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3
12110    #
12111    #"
12112   [(set_attr "type" "compare")
12113    (set_attr "length" "12,12,16,16")])
12114
12115 (define_split
12116   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12117         (compare:CC
12118          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12119                          (match_operand:SI 2 "reg_or_short_operand" ""))
12120                   (match_operand:SI 3 "gpc_reg_operand" ""))
12121          (const_int 0)))
12122    (clobber (match_scratch:SI 4 ""))]
12123   "TARGET_POWER && reload_completed"
12124   [(set (match_dup 4)
12125         (plus:SI (le:SI (match_dup 1) (match_dup 2))
12126                  (match_dup 3)))
12127    (set (match_dup 0)
12128         (compare:CC (match_dup 4)
12129                     (const_int 0)))]
12130   "")
12131
12132 (define_insn ""
12133   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12134         (compare:CC
12135          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12136                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12137                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12138          (const_int 0)))
12139    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12140         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12141   "TARGET_POWER"
12142   "@
12143    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12144    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze.|addze.} %0,%3
12145    #
12146    #"
12147   [(set_attr "type" "compare")
12148    (set_attr "length" "12,12,16,16")])
12149
12150 (define_split
12151   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12152         (compare:CC
12153          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12154                          (match_operand:SI 2 "reg_or_short_operand" ""))
12155                   (match_operand:SI 3 "gpc_reg_operand" ""))
12156          (const_int 0)))
12157    (set (match_operand:SI 0 "gpc_reg_operand" "")
12158         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12159   "TARGET_POWER && reload_completed"
12160   [(set (match_dup 0)
12161         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12162    (set (match_dup 4)
12163         (compare:CC (match_dup 0)
12164                     (const_int 0)))]
12165   "")
12166
12167 (define_insn ""
12168   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12169         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12170                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
12171   "TARGET_POWER"
12172   "@
12173    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
12174    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
12175   [(set_attr "length" "12")])
12176
12177 (define_insn ""
12178   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12179         (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12180                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12181   "TARGET_32BIT"
12182   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12183   [(set_attr "length" "12")])
12184
12185 (define_insn ""
12186   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12187         (leu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
12188                 (match_operand:DI 2 "reg_or_short_operand" "rI")))]
12189   "TARGET_64BIT"
12190   "subf%I2c %0,%1,%2\;li %0,0\;adde %0,%0,%0"
12191   [(set_attr "length" "12")])
12192
12193 (define_insn ""
12194   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12195         (compare:CC
12196          (leu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12197                  (match_operand:DI 2 "reg_or_short_operand" "rI,rI"))
12198          (const_int 0)))
12199    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12200         (leu:DI (match_dup 1) (match_dup 2)))]
12201   "TARGET_64BIT"
12202   "@
12203    subf%I2c %0,%1,%2\;li %0,0\;adde. %0,%0,%0
12204    #"
12205   [(set_attr "type" "compare")
12206    (set_attr "length" "12,16")])
12207
12208 (define_split
12209   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12210         (compare:CC
12211          (leu:DI (match_operand:DI 1 "gpc_reg_operand" "")
12212                  (match_operand:DI 2 "reg_or_short_operand" ""))
12213          (const_int 0)))
12214    (set (match_operand:DI 0 "gpc_reg_operand" "")
12215         (leu:DI (match_dup 1) (match_dup 2)))]
12216   "TARGET_64BIT && reload_completed"
12217   [(set (match_dup 0)
12218         (leu:DI (match_dup 1) (match_dup 2)))
12219    (set (match_dup 3)
12220         (compare:CC (match_dup 0)
12221                     (const_int 0)))]
12222   "")
12223
12224 (define_insn ""
12225   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12226         (compare:CC
12227          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12228                  (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12229          (const_int 0)))
12230    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12231         (leu:SI (match_dup 1) (match_dup 2)))]
12232   "TARGET_32BIT"
12233   "@
12234    {sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12235    #"
12236   [(set_attr "type" "compare")
12237    (set_attr "length" "12,16")])
12238
12239 (define_split
12240   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12241         (compare:CC
12242          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12243                  (match_operand:SI 2 "reg_or_short_operand" ""))
12244          (const_int 0)))
12245    (set (match_operand:SI 0 "gpc_reg_operand" "")
12246         (leu:SI (match_dup 1) (match_dup 2)))]
12247   "TARGET_32BIT && reload_completed"
12248   [(set (match_dup 0)
12249         (leu:SI (match_dup 1) (match_dup 2)))
12250    (set (match_dup 3)
12251         (compare:CC (match_dup 0)
12252                     (const_int 0)))]
12253   "")
12254
12255 (define_insn ""
12256   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12257         (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12258                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
12259                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12260   "TARGET_32BIT"
12261   "{sf%I2|subf%I2c} %0,%1,%2\;{aze|addze} %0,%3"
12262   [(set_attr "length" "8")])
12263
12264 (define_insn ""
12265   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12266         (compare:CC
12267          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12268                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12269                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12270          (const_int 0)))
12271    (clobber (match_scratch:SI 4 "=&r,&r"))]
12272   "TARGET_32BIT"
12273   "@
12274    {sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3
12275    #"
12276   [(set_attr "type" "compare")
12277    (set_attr "length" "8,12")])
12278
12279 (define_split
12280   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12281         (compare:CC
12282          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12283                           (match_operand:SI 2 "reg_or_short_operand" ""))
12284                   (match_operand:SI 3 "gpc_reg_operand" ""))
12285          (const_int 0)))
12286    (clobber (match_scratch:SI 4 ""))]
12287   "TARGET_32BIT && reload_completed"
12288   [(set (match_dup 4)
12289         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
12290                   (match_dup 3)))
12291    (set (match_dup 0)
12292         (compare:CC (match_dup 4)
12293                     (const_int 0)))]
12294   "")
12295
12296 (define_insn ""
12297   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12298         (compare:CC
12299          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12300                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12301                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12302          (const_int 0)))
12303    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12304         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12305   "TARGET_32BIT"
12306   "@
12307    {sf%I2|subf%I2c} %0,%1,%2\;{aze.|addze.} %0,%3
12308    #"
12309   [(set_attr "type" "compare")
12310    (set_attr "length" "8,12")])
12311
12312 (define_split
12313   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12314         (compare:CC
12315          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12316                           (match_operand:SI 2 "reg_or_short_operand" ""))
12317                   (match_operand:SI 3 "gpc_reg_operand" ""))
12318          (const_int 0)))
12319    (set (match_operand:SI 0 "gpc_reg_operand" "")
12320         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12321   "TARGET_32BIT && reload_completed"
12322   [(set (match_dup 0)
12323         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12324    (set (match_dup 4)
12325         (compare:CC (match_dup 0)
12326                     (const_int 0)))]
12327   "")
12328
12329 (define_insn ""
12330   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12331         (neg:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12332                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12333   "TARGET_32BIT"
12334   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
12335    [(set_attr "length" "12")])
12336
12337 (define_insn ""
12338   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12339         (and:SI (neg:SI
12340                  (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12341                          (match_operand:SI 2 "reg_or_short_operand" "rI")))
12342                 (match_operand:SI 3 "gpc_reg_operand" "r")))]
12343   "TARGET_32BIT"
12344   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12345   [(set_attr "length" "12")])
12346
12347 (define_insn ""
12348   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12349         (compare:CC
12350          (and:SI (neg:SI
12351                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12352                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12353                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12354          (const_int 0)))
12355    (clobber (match_scratch:SI 4 "=&r,&r"))]
12356   "TARGET_32BIT"
12357   "@
12358    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12359    #"
12360   [(set_attr "type" "compare")
12361    (set_attr "length" "12,16")])
12362
12363 (define_split
12364   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12365         (compare:CC
12366          (and:SI (neg:SI
12367                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12368                           (match_operand:SI 2 "reg_or_short_operand" "")))
12369                  (match_operand:SI 3 "gpc_reg_operand" ""))
12370          (const_int 0)))
12371    (clobber (match_scratch:SI 4 ""))]
12372   "TARGET_32BIT && reload_completed"
12373   [(set (match_dup 4)
12374         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12375                 (match_dup 3)))
12376    (set (match_dup 0)
12377         (compare:CC (match_dup 4)
12378                     (const_int 0)))]
12379   "")
12380
12381 (define_insn ""
12382   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12383         (compare:CC
12384          (and:SI (neg:SI
12385                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12386                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12387                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12388          (const_int 0)))
12389    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12390         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12391   "TARGET_32BIT"
12392   "@
12393    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12394    #"
12395   [(set_attr "type" "compare")
12396    (set_attr "length" "12,16")])
12397
12398 (define_split
12399   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12400         (compare:CC
12401          (and:SI (neg:SI
12402                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12403                           (match_operand:SI 2 "reg_or_short_operand" "")))
12404                  (match_operand:SI 3 "gpc_reg_operand" ""))
12405          (const_int 0)))
12406    (set (match_operand:SI 0 "gpc_reg_operand" "")
12407         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12408   "TARGET_32BIT && reload_completed"
12409   [(set (match_dup 0)
12410         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12411                 (match_dup 3)))
12412    (set (match_dup 4)
12413         (compare:CC (match_dup 0)
12414                     (const_int 0)))]
12415   "")
12416
12417 (define_insn ""
12418   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12419         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12420                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12421   "TARGET_POWER"
12422   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
12423    [(set_attr "length" "12")])
12424
12425 (define_insn ""
12426   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12427         (compare:CC
12428          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12429                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12430          (const_int 0)))
12431    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12432         (lt:SI (match_dup 1) (match_dup 2)))]
12433   "TARGET_POWER"
12434   "@
12435    doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
12436    #"
12437   [(set_attr "type" "delayed_compare")
12438    (set_attr "length" "12,16")])
12439
12440 (define_split
12441   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12442         (compare:CC
12443          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12444                 (match_operand:SI 2 "reg_or_short_operand" ""))
12445          (const_int 0)))
12446    (set (match_operand:SI 0 "gpc_reg_operand" "")
12447         (lt:SI (match_dup 1) (match_dup 2)))]
12448   "TARGET_POWER && reload_completed"
12449   [(set (match_dup 0)
12450         (lt:SI (match_dup 1) (match_dup 2)))
12451    (set (match_dup 3)
12452         (compare:CC (match_dup 0)
12453                     (const_int 0)))]
12454   "")
12455
12456 (define_insn ""
12457   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12458         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12459                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12460                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12461   "TARGET_POWER"
12462   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
12463   [(set_attr "length" "12")])
12464
12465 (define_insn ""
12466   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12467         (compare:CC
12468          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12469                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12470                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12471          (const_int 0)))
12472    (clobber (match_scratch:SI 4 "=&r,&r"))]
12473   "TARGET_POWER"
12474   "@
12475    doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
12476    #"
12477   [(set_attr "type" "compare")
12478    (set_attr "length" "12,16")])
12479
12480 (define_split
12481   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12482         (compare:CC
12483          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12484                          (match_operand:SI 2 "reg_or_short_operand" ""))
12485                   (match_operand:SI 3 "gpc_reg_operand" ""))
12486          (const_int 0)))
12487    (clobber (match_scratch:SI 4 ""))]
12488   "TARGET_POWER && reload_completed"
12489   [(set (match_dup 4)
12490         (plus:SI (lt:SI (match_dup 1) (match_dup 2))
12491                  (match_dup 3)))
12492    (set (match_dup 0)
12493         (compare:CC (match_dup 4)
12494                     (const_int 0)))]
12495   "")
12496
12497 (define_insn ""
12498   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12499         (compare:CC
12500          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12501                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12502                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12503          (const_int 0)))
12504    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12505         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12506   "TARGET_POWER"
12507   "@
12508    doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
12509    #"
12510   [(set_attr "type" "compare")
12511    (set_attr "length" "12,16")])
12512
12513 (define_split
12514   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12515         (compare:CC
12516          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12517                          (match_operand:SI 2 "reg_or_short_operand" ""))
12518                   (match_operand:SI 3 "gpc_reg_operand" ""))
12519          (const_int 0)))
12520    (set (match_operand:SI 0 "gpc_reg_operand" "")
12521         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12522   "TARGET_POWER && reload_completed"
12523   [(set (match_dup 0)
12524         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12525    (set (match_dup 4)
12526         (compare:CC (match_dup 0)
12527                     (const_int 0)))]
12528   "")
12529
12530 (define_insn ""
12531   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12532         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12533                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12534   "TARGET_POWER"
12535   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
12536   [(set_attr "length" "12")])
12537
12538 (define_insn ""
12539   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12540         (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12541                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
12542   "TARGET_32BIT"
12543   "@
12544    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg %0,%0
12545    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg %0,%0"
12546   [(set_attr "length" "12")])
12547
12548 (define_insn ""
12549   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12550         (compare:CC
12551          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12552                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12553          (const_int 0)))
12554    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12555         (ltu:SI (match_dup 1) (match_dup 2)))]
12556   "TARGET_32BIT"
12557   "@
12558    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
12559    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
12560    #
12561    #"
12562   [(set_attr "type" "compare")
12563    (set_attr "length" "12,12,16,16")])
12564
12565 (define_split
12566   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12567         (compare:CC
12568          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12569                  (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12570          (const_int 0)))
12571    (set (match_operand:SI 0 "gpc_reg_operand" "")
12572         (ltu:SI (match_dup 1) (match_dup 2)))]
12573   "TARGET_32BIT && reload_completed"
12574   [(set (match_dup 0)
12575         (ltu:SI (match_dup 1) (match_dup 2)))
12576    (set (match_dup 3)
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,&r")
12583         (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12584                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
12585                  (match_operand:SI 3 "reg_or_short_operand" "rI,rI")))]
12586   "TARGET_32BIT"
12587   "@
12588   {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;{sf%I3|subf%I3c} %0,%0,%3
12589   {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;{sf%I3|subf%I3c} %0,%0,%3"
12590  [(set_attr "length" "12")])
12591
12592 (define_insn ""
12593   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12594         (compare:CC
12595          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12596                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12597                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12598          (const_int 0)))
12599    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12600   "TARGET_32BIT"
12601   "@
12602    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
12603    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
12604    #
12605    #"
12606   [(set_attr "type" "compare")
12607    (set_attr "length" "12,12,16,16")])
12608
12609 (define_split
12610   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12611         (compare:CC
12612          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12613                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12614                   (match_operand:SI 3 "gpc_reg_operand" ""))
12615          (const_int 0)))
12616    (clobber (match_scratch:SI 4 ""))]
12617   "TARGET_32BIT && reload_completed"
12618   [(set (match_dup 4)
12619         (plus:SI (ltu:SI (match_dup 1) (match_dup 2))
12620                  (match_dup 3)))
12621    (set (match_dup 0)
12622         (compare:CC (match_dup 4)
12623                     (const_int 0)))]
12624   "")
12625
12626 (define_insn ""
12627   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12628         (compare:CC
12629          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12630                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12631                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12632          (const_int 0)))
12633    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12634         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12635   "TARGET_32BIT"
12636   "@
12637    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;{sf.|subfc.} %0,%0,%3
12638    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;{sf.|subfc.} %0,%0,%3
12639    #
12640    #"
12641   [(set_attr "type" "compare")
12642    (set_attr "length" "12,12,16,16")])
12643
12644 (define_split
12645   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12646         (compare:CC
12647          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12648                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12649                   (match_operand:SI 3 "gpc_reg_operand" ""))
12650          (const_int 0)))
12651    (set (match_operand:SI 0 "gpc_reg_operand" "")
12652         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12653   "TARGET_32BIT && reload_completed"
12654   [(set (match_dup 0)
12655         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12656    (set (match_dup 4)
12657         (compare:CC (match_dup 0)
12658                     (const_int 0)))]
12659   "")
12660
12661 (define_insn ""
12662   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12663         (neg:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12664                         (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))))]
12665   "TARGET_32BIT"
12666   "@
12667    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
12668    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
12669   [(set_attr "length" "8")])
12670
12671 (define_insn ""
12672   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12673         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12674                (match_operand:SI 2 "reg_or_short_operand" "rI")))
12675    (clobber (match_scratch:SI 3 "=r"))]
12676   "TARGET_POWER"
12677   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
12678    [(set_attr "length" "12")])
12679
12680 (define_insn ""
12681   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12682         (compare:CC
12683          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12684                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12685          (const_int 0)))
12686    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12687         (ge:SI (match_dup 1) (match_dup 2)))
12688    (clobber (match_scratch:SI 3 "=r,r"))]
12689   "TARGET_POWER"
12690   "@
12691    doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
12692    #"
12693   [(set_attr "type" "compare")
12694    (set_attr "length" "12,16")])
12695
12696 (define_split
12697   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12698         (compare:CC
12699          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12700                 (match_operand:SI 2 "reg_or_short_operand" ""))
12701          (const_int 0)))
12702    (set (match_operand:SI 0 "gpc_reg_operand" "")
12703         (ge:SI (match_dup 1) (match_dup 2)))
12704    (clobber (match_scratch:SI 3 ""))]
12705   "TARGET_POWER && reload_completed"
12706   [(parallel [(set (match_dup 0)
12707                    (ge:SI (match_dup 1) (match_dup 2)))
12708               (clobber (match_dup 3))])
12709    (set (match_dup 4)
12710         (compare:CC (match_dup 0)
12711                     (const_int 0)))]
12712   "")
12713
12714 (define_insn ""
12715   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12716         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12717                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12718                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12719   "TARGET_POWER"
12720   "doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
12721   [(set_attr "length" "12")])
12722
12723 (define_insn ""
12724   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12725         (compare:CC
12726          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12727                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12728                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12729          (const_int 0)))
12730    (clobber (match_scratch:SI 4 "=&r,&r"))]
12731   "TARGET_POWER"
12732   "@
12733    doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12734    #"
12735   [(set_attr "type" "compare")
12736    (set_attr "length" "12,16")])
12737
12738 (define_split
12739   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12740         (compare:CC
12741          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12742                          (match_operand:SI 2 "reg_or_short_operand" ""))
12743                   (match_operand:SI 3 "gpc_reg_operand" ""))
12744          (const_int 0)))
12745    (clobber (match_scratch:SI 4 ""))]
12746   "TARGET_POWER && reload_completed"
12747   [(set (match_dup 4)
12748         (plus:SI (ge:SI (match_dup 1) (match_dup 2))
12749                  (match_dup 3)))
12750    (set (match_dup 0)
12751         (compare:CC (match_dup 4)
12752                     (const_int 0)))]
12753   "")
12754
12755 (define_insn ""
12756   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12757         (compare:CC
12758          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12759                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12760                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12761          (const_int 0)))
12762    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12763         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12764   "TARGET_POWER"
12765   "@
12766    doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12767    #"
12768   [(set_attr "type" "compare")
12769    (set_attr "length" "12,16")])
12770
12771 (define_split
12772   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12773         (compare:CC
12774          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12775                          (match_operand:SI 2 "reg_or_short_operand" ""))
12776                   (match_operand:SI 3 "gpc_reg_operand" ""))
12777          (const_int 0)))
12778    (set (match_operand:SI 0 "gpc_reg_operand" "")
12779         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12780   "TARGET_POWER && reload_completed"
12781   [(set (match_dup 0)
12782         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12783    (set (match_dup 4)
12784         (compare:CC (match_dup 0)
12785                     (const_int 0)))]
12786   "")
12787
12788 (define_insn ""
12789   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12790         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12791                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12792   "TARGET_POWER"
12793   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
12794   [(set_attr "length" "12")])
12795
12796 (define_insn ""
12797   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12798         (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12799                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
12800   "TARGET_32BIT"
12801   "@
12802    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
12803    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12804   [(set_attr "length" "12")])
12805
12806 (define_insn ""
12807   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12808         (geu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12809                 (match_operand:DI 2 "reg_or_neg_short_operand" "r,P")))]
12810   "TARGET_64BIT"
12811   "@
12812    subfc %0,%2,%1\;li %0,0\;adde %0,%0,%0
12813    addic %0,%1,%n2\;li %0,0\;adde %0,%0,%0"
12814   [(set_attr "length" "12")])
12815
12816 (define_insn ""
12817   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12818         (compare:CC
12819          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12820                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12821          (const_int 0)))
12822    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12823         (geu:SI (match_dup 1) (match_dup 2)))]
12824   "TARGET_32BIT"
12825   "@
12826    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12827    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12828    #
12829    #"
12830   [(set_attr "type" "compare")
12831    (set_attr "length" "12,12,16,16")])
12832
12833 (define_split
12834   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12835         (compare:CC
12836          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12837                  (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12838          (const_int 0)))
12839    (set (match_operand:SI 0 "gpc_reg_operand" "")
12840         (geu:SI (match_dup 1) (match_dup 2)))]
12841   "TARGET_32BIT && reload_completed"
12842   [(set (match_dup 0)
12843         (geu:SI (match_dup 1) (match_dup 2)))
12844    (set (match_dup 3)
12845         (compare:CC (match_dup 0)
12846                     (const_int 0)))]
12847   "")
12848
12849 (define_insn ""
12850   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12851         (compare:CC
12852          (geu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
12853                  (match_operand:DI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12854          (const_int 0)))
12855    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
12856         (geu:DI (match_dup 1) (match_dup 2)))]
12857   "TARGET_64BIT"
12858   "@
12859    subfc %0,%2,%1\;li %0,0\;adde. %0,%0,%0
12860    addic %0,%1,%n2\;li %0,0\;adde. %0,%0,%0
12861    #
12862    #"
12863   [(set_attr "type" "compare")
12864    (set_attr "length" "12,12,16,16")])
12865
12866 (define_split
12867   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12868         (compare:CC
12869          (geu:DI (match_operand:DI 1 "gpc_reg_operand" "")
12870                  (match_operand:DI 2 "reg_or_neg_short_operand" ""))
12871          (const_int 0)))
12872    (set (match_operand:DI 0 "gpc_reg_operand" "")
12873         (geu:DI (match_dup 1) (match_dup 2)))]
12874   "TARGET_64BIT && reload_completed"
12875   [(set (match_dup 0)
12876         (geu:DI (match_dup 1) (match_dup 2)))
12877    (set (match_dup 3)
12878         (compare:CC (match_dup 0)
12879                     (const_int 0)))]
12880   "")
12881
12882 (define_insn ""
12883   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12884         (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12885                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
12886                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12887   "TARGET_32BIT"
12888   "@
12889    {sf|subfc} %0,%2,%1\;{aze|addze} %0,%3
12890    {ai|addic} %0,%1,%n2\;{aze|addze} %0,%3"
12891   [(set_attr "length" "8")])
12892
12893 (define_insn ""
12894   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12895         (compare:CC
12896          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12897                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12898                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12899          (const_int 0)))
12900    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12901   "TARGET_32BIT"
12902   "@
12903    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
12904    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3
12905    #
12906    #"
12907   [(set_attr "type" "compare")
12908    (set_attr "length" "8,8,12,12")])
12909
12910 (define_split
12911   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12912         (compare:CC
12913          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12914                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12915                   (match_operand:SI 3 "gpc_reg_operand" ""))
12916          (const_int 0)))
12917    (clobber (match_scratch:SI 4 ""))]
12918   "TARGET_32BIT && reload_completed"
12919   [(set (match_dup 4)
12920         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
12921                   (match_dup 3)))
12922    (set (match_dup 0)
12923         (compare:CC (match_dup 4)
12924                     (const_int 0)))]
12925   "")
12926
12927 (define_insn ""
12928   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12929         (compare:CC
12930          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12931                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12932                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12933          (const_int 0)))
12934    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12935         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12936   "TARGET_32BIT"
12937   "@
12938    {sf|subfc} %0,%2,%1\;{aze.|addze.} %0,%3
12939    {ai|addic} %0,%1,%n2\;{aze.|addze.} %0,%3
12940    #
12941    #"
12942   [(set_attr "type" "compare")
12943    (set_attr "length" "8,8,12,12")])
12944
12945 (define_split
12946   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12947         (compare:CC
12948          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12949                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12950                   (match_operand:SI 3 "gpc_reg_operand" ""))
12951          (const_int 0)))
12952    (set (match_operand:SI 0 "gpc_reg_operand" "")
12953         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12954   "TARGET_32BIT && reload_completed"
12955   [(set (match_dup 0)
12956         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12957    (set (match_dup 4)
12958         (compare:CC (match_dup 0)
12959                     (const_int 0)))]
12960   "")
12961
12962 (define_insn ""
12963   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12964         (neg:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12965                         (match_operand:SI 2 "reg_or_short_operand" "r,I"))))]
12966   "TARGET_32BIT"
12967   "@
12968    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
12969    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
12970   [(set_attr "length" "12")])
12971
12972 (define_insn ""
12973   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12974         (and:SI (neg:SI
12975                  (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12976                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
12977                 (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12978   "TARGET_32BIT"
12979   "@
12980    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0
12981    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12982   [(set_attr "length" "12")])
12983
12984 (define_insn ""
12985   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12986         (compare:CC
12987          (and:SI (neg:SI
12988                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12989                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
12990                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12991          (const_int 0)))
12992    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12993   "TARGET_32BIT"
12994   "@
12995    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12996    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12997    #
12998    #"
12999   [(set_attr "type" "compare")
13000    (set_attr "length" "12,12,16,16")])
13001
13002 (define_split
13003   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13004         (compare:CC
13005          (and:SI (neg:SI
13006                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13007                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
13008                  (match_operand:SI 3 "gpc_reg_operand" ""))
13009          (const_int 0)))
13010    (clobber (match_scratch:SI 4 ""))]
13011   "TARGET_32BIT && reload_completed"
13012   [(set (match_dup 4)
13013         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
13014                 (match_dup 3)))
13015    (set (match_dup 0)
13016         (compare:CC (match_dup 4)
13017                     (const_int 0)))]
13018   "")
13019
13020 (define_insn ""
13021   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13022         (compare:CC
13023          (and:SI (neg:SI
13024                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13025                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
13026                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13027          (const_int 0)))
13028    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13029         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13030   "TARGET_32BIT"
13031   "@
13032    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
13033    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
13034    #
13035    #"
13036   [(set_attr "type" "compare")
13037    (set_attr "length" "12,12,16,16")])
13038
13039 (define_split
13040   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13041         (compare:CC
13042          (and:SI (neg:SI
13043                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13044                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
13045                  (match_operand:SI 3 "gpc_reg_operand" ""))
13046          (const_int 0)))
13047    (set (match_operand:SI 0 "gpc_reg_operand" "")
13048         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13049   "TARGET_32BIT && reload_completed"
13050   [(set (match_dup 0)
13051         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
13052    (set (match_dup 4)
13053         (compare:CC (match_dup 0)
13054                     (const_int 0)))]
13055   "")
13056
13057 (define_insn ""
13058   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13059         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13060                (const_int 0)))]
13061   "TARGET_32BIT"
13062   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri|srwi} %0,%0,31"
13063   [(set_attr "length" "12")])
13064
13065 (define_insn ""
13066   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13067         (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13068                (const_int 0)))]
13069   "TARGET_64BIT"
13070   "subfic %0,%1,0\;addme %0,%0\;srdi %0,%0,63"
13071   [(set_attr "length" "12")])
13072
13073 (define_insn ""
13074   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
13075         (compare:CC
13076          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13077                 (const_int 0))
13078          (const_int 0)))
13079    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13080         (gt:SI (match_dup 1) (const_int 0)))]
13081   "TARGET_32BIT"
13082   "@
13083    {sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri.|srwi.} %0,%0,31
13084    #"
13085   [(set_attr "type" "delayed_compare")
13086    (set_attr "length" "12,16")])
13087
13088 (define_split
13089   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
13090         (compare:CC
13091          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13092                 (const_int 0))
13093          (const_int 0)))
13094    (set (match_operand:SI 0 "gpc_reg_operand" "")
13095         (gt:SI (match_dup 1) (const_int 0)))]
13096   "TARGET_32BIT && reload_completed"
13097   [(set (match_dup 0)
13098         (gt:SI (match_dup 1) (const_int 0)))
13099    (set (match_dup 2)
13100         (compare:CC (match_dup 0)
13101                     (const_int 0)))]
13102   "")
13103
13104 (define_insn ""
13105   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
13106         (compare:CC
13107          (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13108                 (const_int 0))
13109          (const_int 0)))
13110    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
13111         (gt:DI (match_dup 1) (const_int 0)))]
13112   "TARGET_64BIT"
13113   "@
13114    subfic %0,%1,0\;addme %0,%0\;srdi. %0,%0,63
13115    #"
13116   [(set_attr "type" "delayed_compare")
13117    (set_attr "length" "12,16")])
13118
13119 (define_split
13120   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
13121         (compare:CC
13122          (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13123                 (const_int 0))
13124          (const_int 0)))
13125    (set (match_operand:DI 0 "gpc_reg_operand" "")
13126         (gt:DI (match_dup 1) (const_int 0)))]
13127   "TARGET_64BIT && reload_completed"
13128   [(set (match_dup 0)
13129         (gt:DI (match_dup 1) (const_int 0)))
13130    (set (match_dup 2)
13131         (compare:CC (match_dup 0)
13132                     (const_int 0)))]
13133   "")
13134
13135 (define_insn ""
13136   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13137         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13138                (match_operand:SI 2 "reg_or_short_operand" "r")))]
13139   "TARGET_POWER"
13140   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
13141   [(set_attr "length" "12")])
13142
13143 (define_insn ""
13144   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13145         (compare:CC
13146          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13147                 (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13148          (const_int 0)))
13149    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13150         (gt:SI (match_dup 1) (match_dup 2)))]
13151   "TARGET_POWER"
13152   "@
13153    doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
13154    #"
13155   [(set_attr "type" "delayed_compare")
13156    (set_attr "length" "12,16")])
13157
13158 (define_split
13159   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13160         (compare:CC
13161          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13162                 (match_operand:SI 2 "reg_or_short_operand" ""))
13163          (const_int 0)))
13164    (set (match_operand:SI 0 "gpc_reg_operand" "")
13165         (gt:SI (match_dup 1) (match_dup 2)))]
13166   "TARGET_POWER && reload_completed"
13167   [(set (match_dup 0)
13168         (gt:SI (match_dup 1) (match_dup 2)))
13169    (set (match_dup 3)
13170         (compare:CC (match_dup 0)
13171                     (const_int 0)))]
13172   "")
13173
13174 (define_insn ""
13175   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13176         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13177                         (const_int 0))
13178                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
13179   "TARGET_32BIT"
13180   "{a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze|addze} %0,%2"
13181   [(set_attr "length" "12")])
13182
13183 (define_insn ""
13184   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
13185         (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13186                         (const_int 0))
13187                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
13188   "TARGET_64BIT"
13189   "addc %0,%1,%1\;subfe %0,%1,%0\;addze %0,%2"
13190   [(set_attr "length" "12")])
13191
13192 (define_insn ""
13193   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13194         (compare:CC
13195          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13196                          (const_int 0))
13197                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13198          (const_int 0)))
13199    (clobber (match_scratch:SI 3 "=&r,&r"))]
13200   "TARGET_32BIT"
13201   "@
13202    {a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2
13203    #"
13204   [(set_attr "type" "compare")
13205    (set_attr "length" "12,16")])
13206
13207 (define_split
13208   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13209         (compare:CC
13210          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13211                          (const_int 0))
13212                   (match_operand:SI 2 "gpc_reg_operand" ""))
13213          (const_int 0)))
13214    (clobber (match_scratch:SI 3 ""))]
13215   "TARGET_32BIT && reload_completed"
13216   [(set (match_dup 3)
13217         (plus:SI (gt:SI (match_dup 1) (const_int 0))
13218                   (match_dup 2)))
13219    (set (match_dup 0)
13220         (compare:CC (match_dup 3)
13221                     (const_int 0)))]
13222   "")
13223
13224 (define_insn ""
13225   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13226         (compare:CC
13227          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13228                          (const_int 0))
13229                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13230          (const_int 0)))
13231    (clobber (match_scratch:DI 3 "=&r,&r"))]
13232   "TARGET_64BIT"
13233   "@
13234    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
13235    #"
13236   [(set_attr "type" "compare")
13237    (set_attr "length" "12,16")])
13238
13239 (define_split
13240   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13241         (compare:CC
13242          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13243                          (const_int 0))
13244                   (match_operand:DI 2 "gpc_reg_operand" ""))
13245          (const_int 0)))
13246    (clobber (match_scratch:DI 3 ""))]
13247   "TARGET_64BIT && reload_completed"
13248   [(set (match_dup 3)
13249         (plus:DI (gt:DI (match_dup 1) (const_int 0))
13250                  (match_dup 2)))
13251    (set (match_dup 0)
13252         (compare:CC (match_dup 3)
13253                     (const_int 0)))]
13254   "")
13255
13256 (define_insn ""
13257   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13258         (compare:CC
13259          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13260                          (const_int 0))
13261                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13262          (const_int 0)))
13263    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13264         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13265   "TARGET_32BIT"
13266   "@
13267    {a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze.|addze.} %0,%2
13268    #"
13269   [(set_attr "type" "compare")
13270    (set_attr "length" "12,16")])
13271
13272 (define_split
13273   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13274         (compare:CC
13275          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13276                          (const_int 0))
13277                   (match_operand:SI 2 "gpc_reg_operand" ""))
13278          (const_int 0)))
13279    (set (match_operand:SI 0 "gpc_reg_operand" "")
13280         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13281   "TARGET_32BIT && reload_completed"
13282   [(set (match_dup 0)
13283         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
13284    (set (match_dup 3)
13285         (compare:CC (match_dup 0)
13286                     (const_int 0)))]
13287   "")
13288
13289 (define_insn ""
13290   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13291         (compare:CC
13292          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13293                          (const_int 0))
13294                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13295          (const_int 0)))
13296    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
13297         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13298   "TARGET_64BIT"
13299   "@
13300    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
13301    #"
13302   [(set_attr "type" "compare")
13303    (set_attr "length" "12,16")])
13304
13305 (define_split
13306   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13307         (compare:CC
13308          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13309                          (const_int 0))
13310                   (match_operand:DI 2 "gpc_reg_operand" ""))
13311          (const_int 0)))
13312    (set (match_operand:DI 0 "gpc_reg_operand" "")
13313         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13314   "TARGET_64BIT && reload_completed"
13315   [(set (match_dup 0)
13316         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
13317    (set (match_dup 3)
13318         (compare:CC (match_dup 0)
13319                     (const_int 0)))]
13320   "")
13321
13322 (define_insn ""
13323   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13324         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13325                         (match_operand:SI 2 "reg_or_short_operand" "r"))
13326                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
13327   "TARGET_POWER"
13328   "doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
13329   [(set_attr "length" "12")])
13330
13331 (define_insn ""
13332   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13333         (compare:CC
13334          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13335                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13336                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13337          (const_int 0)))
13338    (clobber (match_scratch:SI 4 "=&r,&r"))]
13339   "TARGET_POWER"
13340   "@
13341    doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
13342    #"
13343   [(set_attr "type" "compare")
13344    (set_attr "length" "12,16")])
13345
13346 (define_split
13347   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13348         (compare:CC
13349          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13350                          (match_operand:SI 2 "reg_or_short_operand" ""))
13351                   (match_operand:SI 3 "gpc_reg_operand" ""))
13352          (const_int 0)))
13353    (clobber (match_scratch:SI 4 ""))]
13354   "TARGET_POWER && reload_completed"
13355   [(set (match_dup 4)
13356         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13357    (set (match_dup 0)
13358         (compare:CC (match_dup 4)
13359                     (const_int 0)))]
13360   "")
13361
13362 (define_insn ""
13363   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13364         (compare:CC
13365          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13366                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13367                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13368          (const_int 0)))
13369    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13370         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13371   "TARGET_POWER"
13372   "@
13373    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
13374    #"
13375   [(set_attr "type" "compare")
13376    (set_attr "length" "12,16")])
13377
13378 (define_split
13379   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13380         (compare:CC
13381          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13382                          (match_operand:SI 2 "reg_or_short_operand" ""))
13383                   (match_operand:SI 3 "gpc_reg_operand" ""))
13384          (const_int 0)))
13385    (set (match_operand:SI 0 "gpc_reg_operand" "")
13386         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13387   "TARGET_POWER && reload_completed"
13388   [(set (match_dup 0)
13389         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13390    (set (match_dup 4)
13391         (compare:CC (match_dup 0)
13392                     (const_int 0)))]
13393   "")
13394
13395 (define_insn ""
13396   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13397         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13398                        (const_int 0))))]
13399   "TARGET_32BIT"
13400   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{srai|srawi} %0,%0,31"
13401   [(set_attr "length" "12")])
13402
13403 (define_insn ""
13404   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13405         (neg:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13406                        (const_int 0))))]
13407   "TARGET_64BIT"
13408   "subfic %0,%1,0\;addme %0,%0\;sradi %0,%0,63"
13409   [(set_attr "length" "12")])
13410
13411 (define_insn ""
13412   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13413         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13414                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
13415   "TARGET_POWER"
13416   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
13417   [(set_attr "length" "12")])
13418
13419 (define_insn ""
13420   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13421         (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13422                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
13423   "TARGET_32BIT"
13424   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg %0,%0"
13425   [(set_attr "length" "12")])
13426
13427 (define_insn ""
13428   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13429         (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13430                 (match_operand:DI 2 "reg_or_short_operand" "rI")))]
13431   "TARGET_64BIT"
13432   "subf%I2c %0,%1,%2\;subfe %0,%0,%0\;neg %0,%0"
13433   [(set_attr "length" "12")])
13434
13435 (define_insn ""
13436   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13437         (compare:CC
13438          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13439                  (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13440          (const_int 0)))
13441    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13442         (gtu:SI (match_dup 1) (match_dup 2)))]
13443   "TARGET_32BIT"
13444   "@
13445    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
13446    #"
13447   [(set_attr "type" "compare")
13448    (set_attr "length" "12,16")])
13449
13450 (define_split
13451   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13452         (compare:CC
13453          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13454                  (match_operand:SI 2 "reg_or_short_operand" ""))
13455          (const_int 0)))
13456    (set (match_operand:SI 0 "gpc_reg_operand" "")
13457         (gtu:SI (match_dup 1) (match_dup 2)))]
13458   "TARGET_32BIT && reload_completed"
13459   [(set (match_dup 0)
13460         (gtu:SI (match_dup 1) (match_dup 2)))
13461    (set (match_dup 3)
13462         (compare:CC (match_dup 0)
13463                     (const_int 0)))]
13464   "")
13465
13466 (define_insn ""
13467   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13468         (compare:CC
13469          (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13470                  (match_operand:DI 2 "reg_or_short_operand" "rI,rI"))
13471          (const_int 0)))
13472    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
13473         (gtu:DI (match_dup 1) (match_dup 2)))]
13474   "TARGET_64BIT"
13475   "@
13476    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;neg. %0,%0
13477    #"
13478   [(set_attr "type" "compare")
13479    (set_attr "length" "12,16")])
13480
13481 (define_split
13482   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13483         (compare:CC
13484          (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13485                  (match_operand:DI 2 "reg_or_short_operand" ""))
13486          (const_int 0)))
13487    (set (match_operand:DI 0 "gpc_reg_operand" "")
13488         (gtu:DI (match_dup 1) (match_dup 2)))]
13489   "TARGET_64BIT && reload_completed"
13490   [(set (match_dup 0)
13491         (gtu:DI (match_dup 1) (match_dup 2)))
13492    (set (match_dup 3)
13493         (compare:CC (match_dup 0)
13494                     (const_int 0)))]
13495   "")
13496
13497 (define_insn ""
13498   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13499         (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13500                          (match_operand:SI 2 "reg_or_short_operand" "I,rI"))
13501                  (match_operand:SI 3 "reg_or_short_operand" "r,rI")))]
13502   "TARGET_32BIT"
13503   "@
13504    {ai|addic} %0,%1,%k2\;{aze|addze} %0,%3
13505    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;{sf%I3|subf%I3c} %0,%0,%3"
13506   [(set_attr "length" "8,12")])
13507
13508 (define_insn ""
13509   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
13510         (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13511                          (match_operand:DI 2 "reg_or_short_operand" "I,rI"))
13512                  (match_operand:DI 3 "reg_or_short_operand" "r,rI")))]
13513   "TARGET_64BIT"
13514   "@
13515    addic %0,%1,%k2\;addze %0,%3
13516    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;subf%I3c %0,%0,%3"
13517   [(set_attr "length" "8,12")])
13518
13519 (define_insn ""
13520   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13521         (compare:CC
13522          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13523                           (match_operand:SI 2 "reg_or_short_operand" "I,r,I,r"))
13524                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13525          (const_int 0)))
13526    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13527   "TARGET_32BIT"
13528   "@
13529    {ai|addic} %4,%1,%k2\;{aze.|addze.} %4,%3
13530    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
13531    #
13532    #"
13533   [(set_attr "type" "compare")
13534    (set_attr "length" "8,12,12,16")])
13535
13536 (define_split
13537   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13538         (compare:CC
13539          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13540                           (match_operand:SI 2 "reg_or_short_operand" ""))
13541                   (match_operand:SI 3 "gpc_reg_operand" ""))
13542          (const_int 0)))
13543    (clobber (match_scratch:SI 4 ""))]
13544   "TARGET_32BIT && reload_completed"
13545   [(set (match_dup 4)
13546         (plus:SI (gtu:SI (match_dup 1) (match_dup 2))
13547                  (match_dup 3)))
13548    (set (match_dup 0)
13549         (compare:CC (match_dup 4)
13550                     (const_int 0)))]
13551   "")
13552
13553 (define_insn ""
13554   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13555         (compare:CC
13556          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
13557                           (match_operand:DI 2 "reg_or_short_operand" "I,r,I,r"))
13558                   (match_operand:DI 3 "gpc_reg_operand" "r,r,r,r"))
13559          (const_int 0)))
13560    (clobber (match_scratch:DI 4 "=&r,&r,&r,&r"))]
13561   "TARGET_64BIT"
13562   "@
13563    addic %4,%1,%k2\;addze. %4,%3
13564    subf%I2c %4,%1,%2\;subfe %4,%4,%4\;subfc. %4,%4,%3
13565    #
13566    #"
13567   [(set_attr "type" "compare")
13568    (set_attr "length" "8,12,12,16")])
13569
13570 (define_split
13571   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13572         (compare:CC
13573          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13574                           (match_operand:DI 2 "reg_or_short_operand" ""))
13575                   (match_operand:DI 3 "gpc_reg_operand" ""))
13576          (const_int 0)))
13577    (clobber (match_scratch:DI 4 ""))]
13578   "TARGET_64BIT && reload_completed"
13579   [(set (match_dup 4)
13580         (plus:DI (gtu:DI (match_dup 1) (match_dup 2))
13581                   (match_dup 3)))
13582    (set (match_dup 0)
13583         (compare:CC (match_dup 4)
13584                     (const_int 0)))]
13585   "")
13586
13587 (define_insn ""
13588   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13589         (compare:CC
13590          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13591                           (match_operand:SI 2 "reg_or_short_operand" "I,r,I,r"))
13592                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13593          (const_int 0)))
13594    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13595         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13596   "TARGET_32BIT"
13597   "@
13598    {ai|addic} %0,%1,%k2\;{aze.|addze.} %0,%3
13599    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;{sf.|subfc.} %0,%0,%3
13600    #
13601    #"
13602   [(set_attr "type" "compare")
13603    (set_attr "length" "8,12,12,16")])
13604
13605 (define_split
13606   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13607         (compare:CC
13608          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13609                           (match_operand:SI 2 "reg_or_short_operand" ""))
13610                   (match_operand:SI 3 "gpc_reg_operand" ""))
13611          (const_int 0)))
13612    (set (match_operand:SI 0 "gpc_reg_operand" "")
13613         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13614   "TARGET_32BIT && reload_completed"
13615   [(set (match_dup 0)
13616         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13617    (set (match_dup 4)
13618         (compare:CC (match_dup 0)
13619                     (const_int 0)))]
13620   "")
13621
13622 (define_insn ""
13623   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13624         (compare:CC
13625          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
13626                           (match_operand:DI 2 "reg_or_short_operand" "I,r,I,r"))
13627                   (match_operand:DI 3 "gpc_reg_operand" "r,r,r,r"))
13628          (const_int 0)))
13629    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13630         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13631   "TARGET_64BIT"
13632   "@
13633    addic %0,%1,%k2\;addze. %0,%3
13634    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;subfc. %0,%0,%3
13635    #
13636    #"
13637   [(set_attr "type" "compare")
13638    (set_attr "length" "8,12,12,16")])
13639
13640 (define_split
13641   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13642         (compare:CC
13643          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13644                           (match_operand:DI 2 "reg_or_short_operand" ""))
13645                   (match_operand:DI 3 "gpc_reg_operand" ""))
13646          (const_int 0)))
13647    (set (match_operand:DI 0 "gpc_reg_operand" "")
13648         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13649   "TARGET_64BIT && reload_completed"
13650   [(set (match_dup 0)
13651         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
13652    (set (match_dup 4)
13653         (compare:CC (match_dup 0)
13654                     (const_int 0)))]
13655   "")
13656
13657 (define_insn ""
13658   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13659         (neg:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13660                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
13661   "TARGET_32BIT"
13662   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
13663   [(set_attr "length" "8")])
13664
13665 (define_insn ""
13666   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13667         (neg:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13668                         (match_operand:DI 2 "reg_or_short_operand" "rI"))))]
13669   "TARGET_64BIT"
13670   "subf%I2c %0,%1,%2\;subfe %0,%0,%0"
13671   [(set_attr "length" "8")])
13672 \f
13673 ;; Define both directions of branch and return.  If we need a reload
13674 ;; register, we'd rather use CR0 since it is much easier to copy a
13675 ;; register CC value to there.
13676
13677 (define_insn ""
13678   [(set (pc)
13679         (if_then_else (match_operator 1 "branch_comparison_operator"
13680                                       [(match_operand 2
13681                                                       "cc_reg_operand" "y")
13682                                        (const_int 0)])
13683                       (label_ref (match_operand 0 "" ""))
13684                       (pc)))]
13685   ""
13686   "*
13687 {
13688   return output_cbranch (operands[1], \"%l0\", 0, insn);
13689 }"
13690   [(set_attr "type" "branch")])
13691
13692 (define_insn ""
13693   [(set (pc)
13694         (if_then_else (match_operator 0 "branch_comparison_operator"
13695                                       [(match_operand 1
13696                                                       "cc_reg_operand" "y")
13697                                        (const_int 0)])
13698                       (return)
13699                       (pc)))]
13700   "direct_return ()"
13701   "*
13702 {
13703   return output_cbranch (operands[0], NULL, 0, insn);
13704 }"
13705   [(set_attr "type" "branch")
13706    (set_attr "length" "4")])
13707
13708 (define_insn ""
13709   [(set (pc)
13710         (if_then_else (match_operator 1 "branch_comparison_operator"
13711                                       [(match_operand 2
13712                                                       "cc_reg_operand" "y")
13713                                        (const_int 0)])
13714                       (pc)
13715                       (label_ref (match_operand 0 "" ""))))]
13716   ""
13717   "*
13718 {
13719   return output_cbranch (operands[1], \"%l0\", 1, insn);
13720 }"
13721   [(set_attr "type" "branch")])
13722
13723 (define_insn ""
13724   [(set (pc)
13725         (if_then_else (match_operator 0 "branch_comparison_operator"
13726                                       [(match_operand 1
13727                                                       "cc_reg_operand" "y")
13728                                        (const_int 0)])
13729                       (pc)
13730                       (return)))]
13731   "direct_return ()"
13732   "*
13733 {
13734   return output_cbranch (operands[0], NULL, 1, insn);
13735 }"
13736   [(set_attr "type" "branch")
13737    (set_attr "length" "4")])
13738
13739 ;; Logic on condition register values.
13740
13741 ; This pattern matches things like
13742 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
13743 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
13744 ;                                  (const_int 1)))
13745 ; which are generated by the branch logic.
13746 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
13747
13748 (define_insn "*cceq_ior_compare"
13749   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13750         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
13751                         [(match_operator:SI 2
13752                                       "branch_positive_comparison_operator"
13753                                       [(match_operand 3
13754                                                       "cc_reg_operand" "y,y")
13755                                        (const_int 0)])
13756                          (match_operator:SI 4
13757                                       "branch_positive_comparison_operator"
13758                                       [(match_operand 5
13759                                                       "cc_reg_operand" "0,y")
13760                                        (const_int 0)])])
13761                       (const_int 1)))]
13762   ""
13763   "cr%q1 %E0,%j2,%j4"
13764   [(set_attr "type" "cr_logical,delayed_cr")])
13765
13766 ; Why is the constant -1 here, but 1 in the previous pattern?
13767 ; Because ~1 has all but the low bit set.
13768 (define_insn ""
13769   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13770         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
13771                         [(not:SI (match_operator:SI 2
13772                                       "branch_positive_comparison_operator"
13773                                       [(match_operand 3
13774                                                       "cc_reg_operand" "y,y")
13775                                        (const_int 0)]))
13776                          (match_operator:SI 4
13777                                 "branch_positive_comparison_operator"
13778                                 [(match_operand 5
13779                                                 "cc_reg_operand" "0,y")
13780                                  (const_int 0)])])
13781                       (const_int -1)))]
13782   ""
13783   "cr%q1 %E0,%j2,%j4"
13784   [(set_attr "type" "cr_logical,delayed_cr")])
13785
13786 (define_insn "*cceq_rev_compare"
13787   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13788         (compare:CCEQ (match_operator:SI 1
13789                                       "branch_positive_comparison_operator"
13790                                       [(match_operand 2
13791                                                       "cc_reg_operand" "0,y")
13792                                        (const_int 0)])
13793                       (const_int 0)))]
13794   ""
13795   "{crnor %E0,%j1,%j1|crnot %E0,%j1}"
13796   [(set_attr "type" "cr_logical,delayed_cr")])
13797
13798 ;; If we are comparing the result of two comparisons, this can be done
13799 ;; using creqv or crxor.
13800
13801 (define_insn_and_split ""
13802   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
13803         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
13804                               [(match_operand 2 "cc_reg_operand" "y")
13805                                (const_int 0)])
13806                       (match_operator 3 "branch_comparison_operator"
13807                               [(match_operand 4 "cc_reg_operand" "y")
13808                                (const_int 0)])))]
13809   ""
13810   "#"
13811   ""
13812   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
13813                                     (match_dup 5)))]
13814   "
13815 {
13816   int positive_1, positive_2;
13817
13818   positive_1 = branch_positive_comparison_operator (operands[1], CCEQmode);
13819   positive_2 = branch_positive_comparison_operator (operands[3], CCEQmode);
13820
13821   if (! positive_1)
13822     operands[1] = gen_rtx (rs6000_reverse_condition (GET_MODE (operands[2]),
13823                                                      GET_CODE (operands[1])),
13824                            SImode,
13825                            operands[2], const0_rtx);
13826   else if (GET_MODE (operands[1]) != SImode)
13827     operands[1] = gen_rtx (GET_CODE (operands[1]),
13828                            SImode,
13829                            operands[2], const0_rtx);
13830
13831   if (! positive_2)
13832     operands[3] = gen_rtx (rs6000_reverse_condition (GET_MODE (operands[4]),
13833                                                      GET_CODE (operands[3])),
13834                            SImode,
13835                            operands[4], const0_rtx);
13836   else if (GET_MODE (operands[3]) != SImode)
13837     operands[3] = gen_rtx (GET_CODE (operands[3]),
13838                            SImode,
13839                            operands[4], const0_rtx);
13840
13841   if (positive_1 == positive_2)
13842     {
13843       operands[1] = gen_rtx_NOT (SImode, operands[1]);
13844       operands[5] = constm1_rtx;
13845     }
13846   else
13847     {
13848       operands[5] = const1_rtx;
13849     }
13850 }")
13851
13852 ;; Unconditional branch and return.
13853
13854 (define_insn "jump"
13855   [(set (pc)
13856         (label_ref (match_operand 0 "" "")))]
13857   ""
13858   "b %l0"
13859   [(set_attr "type" "branch")])
13860
13861 (define_insn "return"
13862   [(return)]
13863   "direct_return ()"
13864   "{br|blr}"
13865   [(set_attr "type" "jmpreg")])
13866
13867 (define_expand "indirect_jump"
13868   [(set (pc) (match_operand 0 "register_operand" ""))]
13869   ""
13870   "
13871 {
13872   if (TARGET_32BIT)
13873     emit_jump_insn (gen_indirect_jumpsi (operands[0]));
13874   else
13875     emit_jump_insn (gen_indirect_jumpdi (operands[0]));
13876   DONE;
13877 }")
13878
13879 (define_insn "indirect_jumpsi"
13880   [(set (pc) (match_operand:SI 0 "register_operand" "c,*l"))]
13881   "TARGET_32BIT"
13882   "@
13883    bctr
13884    {br|blr}"
13885   [(set_attr "type" "jmpreg")])
13886
13887 (define_insn "indirect_jumpdi"
13888   [(set (pc) (match_operand:DI 0 "register_operand" "c,*l"))]
13889   "TARGET_64BIT"
13890   "@
13891    bctr
13892    blr"
13893   [(set_attr "type" "jmpreg")])
13894
13895 ;; Table jump for switch statements:
13896 (define_expand "tablejump"
13897   [(use (match_operand 0 "" ""))
13898    (use (label_ref (match_operand 1 "" "")))]
13899   ""
13900   "
13901 {
13902   if (TARGET_32BIT)
13903     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
13904   else
13905     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
13906   DONE;
13907 }")
13908
13909 (define_expand "tablejumpsi"
13910   [(set (match_dup 3)
13911         (plus:SI (match_operand:SI 0 "" "")
13912                  (match_dup 2)))
13913    (parallel [(set (pc) (match_dup 3))
13914               (use (label_ref (match_operand 1 "" "")))])]
13915   "TARGET_32BIT"
13916   "
13917 { operands[0] = force_reg (SImode, operands[0]);
13918   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
13919   operands[3] = gen_reg_rtx (SImode);
13920 }")
13921
13922 (define_expand "tablejumpdi"
13923   [(set (match_dup 4) 
13924         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "rm")))
13925    (set (match_dup 3)
13926         (plus:DI (match_dup 4)
13927                  (match_dup 2)))
13928    (parallel [(set (pc) (match_dup 3))
13929               (use (label_ref (match_operand 1 "" "")))])]
13930   "TARGET_64BIT"
13931   "
13932 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
13933   operands[3] = gen_reg_rtx (DImode);
13934   operands[4] = gen_reg_rtx (DImode);
13935 }")
13936
13937 (define_insn ""
13938   [(set (pc)
13939         (match_operand:SI 0 "register_operand" "c,*l"))
13940    (use (label_ref (match_operand 1 "" "")))]
13941   "TARGET_32BIT"
13942   "@
13943    bctr
13944    {br|blr}"
13945   [(set_attr "type" "jmpreg")])
13946
13947 (define_insn ""
13948   [(set (pc)
13949         (match_operand:DI 0 "register_operand" "c,*l"))
13950    (use (label_ref (match_operand 1 "" "")))]
13951   "TARGET_64BIT"
13952   "@
13953    bctr
13954    blr"
13955   [(set_attr "type" "jmpreg")])
13956
13957 (define_insn "nop"
13958   [(const_int 0)]
13959   ""
13960   "{cror 0,0,0|nop}")
13961 \f
13962 ;; Define the subtract-one-and-jump insns, starting with the template
13963 ;; so loop.c knows what to generate.
13964
13965 (define_expand "doloop_end"
13966   [(use (match_operand 0 "" ""))        ; loop pseudo
13967    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
13968    (use (match_operand 2 "" ""))        ; max iterations
13969    (use (match_operand 3 "" ""))        ; loop level
13970    (use (match_operand 4 "" ""))]       ; label
13971   ""
13972   "
13973 {
13974   /* Only use this on innermost loops.  */
13975   if (INTVAL (operands[3]) > 1)
13976     FAIL;
13977   if (TARGET_64BIT)
13978     {
13979       if (GET_MODE (operands[0]) != DImode)
13980         FAIL;
13981       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
13982     }
13983   else
13984     {
13985       if (GET_MODE (operands[0]) != SImode)
13986         FAIL;
13987       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
13988     }
13989   DONE;
13990 }")
13991
13992 (define_expand "ctrsi"
13993   [(parallel [(set (pc)
13994                    (if_then_else (ne (match_operand:SI 0 "register_operand" "")
13995                                      (const_int 1))
13996                                  (label_ref (match_operand 1 "" ""))
13997                                  (pc)))
13998               (set (match_dup 0)
13999                    (plus:SI (match_dup 0)
14000                             (const_int -1)))
14001               (clobber (match_scratch:CC 2 ""))
14002               (clobber (match_scratch:SI 3 ""))])]
14003   "TARGET_32BIT"
14004   "")
14005
14006 (define_expand "ctrdi"
14007   [(parallel [(set (pc)
14008                    (if_then_else (ne (match_operand:DI 0 "register_operand" "")
14009                                      (const_int 1))
14010                                  (label_ref (match_operand 1 "" ""))
14011                                  (pc)))
14012               (set (match_dup 0)
14013                    (plus:DI (match_dup 0)
14014                             (const_int -1)))
14015               (clobber (match_scratch:CC 2 ""))
14016               (clobber (match_scratch:DI 3 ""))])]
14017   "TARGET_64BIT"
14018   "")
14019
14020 ;; We need to be able to do this for any operand, including MEM, or we
14021 ;; will cause reload to blow up since we don't allow output reloads on
14022 ;; JUMP_INSNs.
14023 ;; For the length attribute to be calculated correctly, the
14024 ;; label MUST be operand 0.
14025
14026 (define_insn "*ctrsi_internal1"
14027   [(set (pc)
14028         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14029                           (const_int 1))
14030                       (label_ref (match_operand 0 "" ""))
14031                       (pc)))
14032    (set (match_operand:SI 2 "register_operand" "=1,*r,m,*q*c*l")
14033         (plus:SI (match_dup 1)
14034                  (const_int -1)))
14035    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14036    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14037   "TARGET_32BIT"
14038   "*
14039 {
14040   if (which_alternative != 0)
14041     return \"#\";
14042   else if (get_attr_length (insn) == 4)
14043     return \"{bdn|bdnz} %l0\";
14044   else
14045     return \"bdz $+8\;b %l0\";
14046 }"
14047   [(set_attr "type" "branch")
14048    (set_attr "length" "*,12,16,16")])
14049
14050 (define_insn "*ctrsi_internal2"
14051   [(set (pc)
14052         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14053                           (const_int 1))
14054                       (pc)
14055                       (label_ref (match_operand 0 "" ""))))
14056    (set (match_operand:SI 2 "register_operand" "=1,*r,m,*q*c*l")
14057         (plus:SI (match_dup 1)
14058                  (const_int -1)))
14059    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14060    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14061   "TARGET_32BIT"
14062   "*
14063 {
14064   if (which_alternative != 0)
14065     return \"#\";
14066   else if (get_attr_length (insn) == 4)
14067     return \"bdz %l0\";
14068   else
14069     return \"{bdn|bdnz} $+8\;b %l0\";
14070 }"
14071   [(set_attr "type" "branch")
14072    (set_attr "length" "*,12,16,16")])
14073
14074 (define_insn "*ctrdi_internal1"
14075   [(set (pc)
14076         (if_then_else (ne (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14077                           (const_int 1))
14078                       (label_ref (match_operand 0 "" ""))
14079                       (pc)))
14080    (set (match_operand:DI 2 "register_operand" "=1,*r,m,*c*l")
14081         (plus:DI (match_dup 1)
14082                  (const_int -1)))
14083    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14084    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14085   "TARGET_64BIT"
14086   "*
14087 {
14088   if (which_alternative != 0)
14089     return \"#\";
14090   else if (get_attr_length (insn) == 4)
14091     return \"{bdn|bdnz} %l0\";
14092   else
14093     return \"bdz $+8\;b %l0\";
14094 }"
14095   [(set_attr "type" "branch")
14096    (set_attr "length" "*,12,16,16")])
14097
14098 (define_insn "*ctrdi_internal2"
14099   [(set (pc)
14100         (if_then_else (ne (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14101                           (const_int 1))
14102                       (pc)
14103                       (label_ref (match_operand 0 "" ""))))
14104    (set (match_operand:DI 2 "register_operand" "=1,*r,m,*c*l")
14105         (plus:DI (match_dup 1)
14106                  (const_int -1)))
14107    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14108    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14109   "TARGET_64BIT"
14110   "*
14111 {
14112   if (which_alternative != 0)
14113     return \"#\";
14114   else if (get_attr_length (insn) == 4)
14115     return \"bdz %l0\";
14116   else
14117     return \"{bdn|bdnz} $+8\;b %l0\";
14118 }"
14119   [(set_attr "type" "branch")
14120    (set_attr "length" "*,12,16,16")])
14121
14122 ;; Similar, but we can use GE since we have a REG_NONNEG.
14123
14124 (define_insn "*ctrsi_internal3"
14125   [(set (pc)
14126         (if_then_else (ge (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14127                           (const_int 0))
14128                       (label_ref (match_operand 0 "" ""))
14129                       (pc)))
14130    (set (match_operand:SI 2 "register_operand" "=1,*r,m,*q*c*l")
14131         (plus:SI (match_dup 1)
14132                  (const_int -1)))
14133    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14134    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14135   "TARGET_32BIT && find_reg_note (insn, REG_NONNEG, 0)"
14136   "*
14137 {
14138   if (which_alternative != 0)
14139     return \"#\";
14140   else if (get_attr_length (insn) == 4)
14141     return \"{bdn|bdnz} %l0\";
14142   else
14143     return \"bdz $+8\;b %l0\";
14144 }"
14145   [(set_attr "type" "branch")
14146    (set_attr "length" "*,12,16,16")])
14147
14148 (define_insn "*ctrsi_internal4"
14149   [(set (pc)
14150         (if_then_else (ge (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14151                           (const_int 0))
14152                       (pc)
14153                       (label_ref (match_operand 0 "" ""))))
14154    (set (match_operand:SI 2 "register_operand" "=1,*r,m,*q*c*l")
14155         (plus:SI (match_dup 1)
14156                  (const_int -1)))
14157    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14158    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14159   "TARGET_32BIT && find_reg_note (insn, REG_NONNEG, 0)"
14160   "*
14161 {
14162   if (which_alternative != 0)
14163     return \"#\";
14164   else if (get_attr_length (insn) == 4)
14165     return \"bdz %l0\";
14166   else
14167     return \"{bdn|bdnz} $+8\;b %l0\";
14168 }"
14169   [(set_attr "type" "branch")
14170    (set_attr "length" "*,12,16,16")])
14171
14172 (define_insn "*ctrdi_internal3"
14173   [(set (pc)
14174         (if_then_else (ge (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14175                           (const_int 0))
14176                       (label_ref (match_operand 0 "" ""))
14177                       (pc)))
14178    (set (match_operand:DI 2 "register_operand" "=1,*r,m,*c*l")
14179         (plus:DI (match_dup 1)
14180                  (const_int -1)))
14181    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14182    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14183   "TARGET_64BIT && find_reg_note (insn, REG_NONNEG, 0)"
14184   "*
14185 {
14186   if (which_alternative != 0)
14187     return \"#\";
14188   else if (get_attr_length (insn) == 4)
14189     return \"{bdn|bdnz} %l0\";
14190   else
14191     return \"bdz $+8\;b %l0\";
14192 }"
14193   [(set_attr "type" "branch")
14194    (set_attr "length" "*,12,16,16")])
14195
14196 (define_insn "*ctrdi_internal4"
14197   [(set (pc)
14198         (if_then_else (ge (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14199                           (const_int 0))
14200                       (pc)
14201                       (label_ref (match_operand 0 "" ""))))
14202    (set (match_operand:DI 2 "register_operand" "=1,*r,m,*c*l")
14203         (plus:DI (match_dup 1)
14204                  (const_int -1)))
14205    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14206    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14207   "TARGET_64BIT && find_reg_note (insn, REG_NONNEG, 0)"
14208   "*
14209 {
14210   if (which_alternative != 0)
14211     return \"#\";
14212   else if (get_attr_length (insn) == 4)
14213     return \"bdz %l0\";
14214   else
14215     return \"{bdn|bdnz} $+8\;b %l0\";
14216 }"
14217   [(set_attr "type" "branch")
14218    (set_attr "length" "*,12,16,16")])
14219
14220 ;; Similar but use EQ
14221
14222 (define_insn "*ctrsi_internal5"
14223   [(set (pc)
14224         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14225                           (const_int 1))
14226                       (label_ref (match_operand 0 "" ""))
14227                       (pc)))
14228    (set (match_operand:SI 2 "register_operand" "=1,*r,m,*q*c*l")
14229         (plus:SI (match_dup 1)
14230                  (const_int -1)))
14231    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14232    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14233   "TARGET_32BIT"
14234   "*
14235 {
14236   if (which_alternative != 0)
14237     return \"#\";
14238   else if (get_attr_length (insn) == 4)
14239     return \"bdz %l0\";
14240   else
14241     return \"{bdn|bdnz} $+8\;b %l0\";
14242 }"
14243   [(set_attr "type" "branch")
14244    (set_attr "length" "*,12,16,16")])
14245
14246 (define_insn "*ctrsi_internal6"
14247   [(set (pc)
14248         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14249                           (const_int 1))
14250                       (pc)
14251                       (label_ref (match_operand 0 "" ""))))
14252    (set (match_operand:SI 2 "register_operand" "=1,*r,m,*q*c*l")
14253         (plus:SI (match_dup 1)
14254                  (const_int -1)))
14255    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14256    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14257   "TARGET_32BIT"
14258   "*
14259 {
14260   if (which_alternative != 0)
14261     return \"#\";
14262   else if (get_attr_length (insn) == 4)
14263     return \"{bdn|bdnz} %l0\";
14264   else
14265     return \"bdz $+8\;b %l0\";
14266 }"
14267   [(set_attr "type" "branch")
14268    (set_attr "length" "*,12,16,16")])
14269
14270 (define_insn "*ctrdi_internal5"
14271   [(set (pc)
14272         (if_then_else (eq (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14273                           (const_int 1))
14274                       (label_ref (match_operand 0 "" ""))
14275                       (pc)))
14276    (set (match_operand:DI 2 "register_operand" "=1,*r,m,*c*l")
14277         (plus:DI (match_dup 1)
14278                  (const_int -1)))
14279    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14280    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14281   "TARGET_64BIT"
14282   "*
14283 {
14284   if (which_alternative != 0)
14285     return \"#\";
14286   else if (get_attr_length (insn) == 4)
14287     return \"bdz %l0\";
14288   else
14289     return \"{bdn|bdnz} $+8\;b %l0\";
14290 }"
14291   [(set_attr "type" "branch")
14292    (set_attr "length" "*,12,16,16")])
14293
14294 (define_insn "*ctrdi_internal6"
14295   [(set (pc)
14296         (if_then_else (eq (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14297                           (const_int 1))
14298                       (pc)
14299                       (label_ref (match_operand 0 "" ""))))
14300    (set (match_operand:DI 2 "register_operand" "=1,*r,m,*c*l")
14301         (plus:DI (match_dup 1)
14302                  (const_int -1)))
14303    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14304    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14305   "TARGET_64BIT"
14306   "*
14307 {
14308   if (which_alternative != 0)
14309     return \"#\";
14310   else if (get_attr_length (insn) == 4)
14311     return \"{bdn|bdnz} %l0\";
14312   else
14313     return \"bdz $+8\;b %l0\";
14314 }"
14315   [(set_attr "type" "branch")
14316    (set_attr "length" "*,12,16,16")])
14317
14318 ;; Now the splitters if we could not allocate the CTR register
14319
14320 (define_split
14321   [(set (pc)
14322         (if_then_else (match_operator 2 "comparison_operator"
14323                                       [(match_operand:SI 1 "gpc_reg_operand" "")
14324                                        (const_int 1)])
14325                       (match_operand 5 "" "")
14326                       (match_operand 6 "" "")))
14327    (set (match_operand:SI 0 "gpc_reg_operand" "")
14328         (plus:SI (match_dup 1)
14329                  (const_int -1)))
14330    (clobber (match_scratch:CC 3 ""))
14331    (clobber (match_scratch:SI 4 ""))]
14332   "TARGET_32BIT && reload_completed"
14333   [(parallel [(set (match_dup 3)
14334                    (compare:CC (plus:SI (match_dup 1)
14335                                         (const_int -1))
14336                                (const_int 0)))
14337               (set (match_dup 0)
14338                    (plus:SI (match_dup 1)
14339                             (const_int -1)))])
14340    (set (pc) (if_then_else (match_dup 7)
14341                            (match_dup 5)
14342                            (match_dup 6)))]
14343   "
14344 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
14345                          const0_rtx); }")
14346
14347 (define_split
14348   [(set (pc)
14349         (if_then_else (match_operator 2 "comparison_operator"
14350                                       [(match_operand:SI 1 "gpc_reg_operand" "")
14351                                        (const_int 1)])
14352                       (match_operand 5 "" "")
14353                       (match_operand 6 "" "")))
14354    (set (match_operand:SI 0 "nonimmediate_operand" "")
14355         (plus:SI (match_dup 1) (const_int -1)))
14356    (clobber (match_scratch:CC 3 ""))
14357    (clobber (match_scratch:SI 4 ""))]
14358   "TARGET_32BIT && reload_completed
14359    && ! gpc_reg_operand (operands[0], SImode)"
14360   [(parallel [(set (match_dup 3)
14361                    (compare:CC (plus:SI (match_dup 1)
14362                                         (const_int -1))
14363                                (const_int 0)))
14364               (set (match_dup 4)
14365                    (plus:SI (match_dup 1)
14366                             (const_int -1)))])
14367    (set (match_dup 0)
14368         (match_dup 4))
14369    (set (pc) (if_then_else (match_dup 7)
14370                            (match_dup 5)
14371                            (match_dup 6)))]
14372   "
14373 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
14374                          const0_rtx); }")
14375 (define_split
14376   [(set (pc)
14377         (if_then_else (match_operator 2 "comparison_operator"
14378                                       [(match_operand:DI 1 "gpc_reg_operand" "")
14379                                        (const_int 1)])
14380                       (match_operand 5 "" "")
14381                       (match_operand 6 "" "")))
14382    (set (match_operand:DI 0 "gpc_reg_operand" "")
14383         (plus:DI (match_dup 1)
14384                  (const_int -1)))
14385    (clobber (match_scratch:CC 3 ""))
14386    (clobber (match_scratch:DI 4 ""))]
14387   "TARGET_64BIT && reload_completed"
14388   [(parallel [(set (match_dup 3)
14389                    (compare:CC (plus:DI (match_dup 1)
14390                                         (const_int -1))
14391                                (const_int 0)))
14392               (set (match_dup 0)
14393                    (plus:DI (match_dup 1)
14394                             (const_int -1)))])
14395    (set (pc) (if_then_else (match_dup 7)
14396                            (match_dup 5)
14397                            (match_dup 6)))]
14398   "
14399 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
14400                          const0_rtx); }")
14401
14402 (define_split
14403   [(set (pc)
14404         (if_then_else (match_operator 2 "comparison_operator"
14405                                       [(match_operand:DI 1 "gpc_reg_operand" "")
14406                                        (const_int 1)])
14407                       (match_operand 5 "" "")
14408                       (match_operand 6 "" "")))
14409    (set (match_operand:DI 0 "nonimmediate_operand" "")
14410         (plus:DI (match_dup 1) (const_int -1)))
14411    (clobber (match_scratch:CC 3 ""))
14412    (clobber (match_scratch:DI 4 ""))]
14413   "TARGET_64BIT && reload_completed
14414    && ! gpc_reg_operand (operands[0], DImode)"
14415   [(parallel [(set (match_dup 3)
14416                    (compare:CC (plus:DI (match_dup 1)
14417                                         (const_int -1))
14418                                (const_int 0)))
14419               (set (match_dup 4)
14420                    (plus:DI (match_dup 1)
14421                             (const_int -1)))])
14422    (set (match_dup 0)
14423         (match_dup 4))
14424    (set (pc) (if_then_else (match_dup 7)
14425                            (match_dup 5)
14426                            (match_dup 6)))]
14427   "
14428 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
14429                          const0_rtx); }")
14430 \f
14431 (define_insn "trap"
14432   [(trap_if (const_int 1) (const_int 0))]
14433   ""
14434   "{t 31,0,0|trap}")
14435
14436 (define_expand "conditional_trap"
14437   [(trap_if (match_operator 0 "trap_comparison_operator"
14438                             [(match_dup 2) (match_dup 3)])
14439             (match_operand 1 "const_int_operand" ""))]
14440   ""
14441   "if (rs6000_compare_fp_p || operands[1] != const0_rtx) FAIL;
14442    operands[2] = rs6000_compare_op0;
14443    operands[3] = rs6000_compare_op1;")
14444
14445 (define_insn ""
14446   [(trap_if (match_operator 0 "trap_comparison_operator"
14447                             [(match_operand:SI 1 "register_operand" "r")
14448                              (match_operand:SI 2 "reg_or_short_operand" "rI")])
14449             (const_int 0))]
14450   ""
14451   "{t|tw}%V0%I2 %1,%2")
14452
14453 (define_insn ""
14454   [(trap_if (match_operator 0 "trap_comparison_operator"
14455                             [(match_operand:DI 1 "register_operand" "r")
14456                              (match_operand:DI 2 "reg_or_short_operand" "rI")])
14457             (const_int 0))]
14458   "TARGET_POWERPC64"
14459   "td%V0%I2 %1,%2")
14460 \f
14461 ;; Insns related to generating the function prologue and epilogue.
14462
14463 (define_expand "prologue"
14464   [(use (const_int 0))]
14465   "TARGET_SCHED_PROLOG"
14466   "
14467 {
14468       rs6000_emit_prologue ();
14469       DONE;
14470 }")
14471
14472 (define_insn "*movesi_from_cr_one"
14473   [(match_parallel 0 "mfcr_operation"
14474                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14475                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
14476                                      (match_operand 3 "immediate_operand" "n")]
14477                           UNSPEC_MOVESI_FROM_CR))])]
14478   "TARGET_MFCRF"
14479   "*
14480 {
14481   int mask = 0;
14482   int i;
14483   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14484   {
14485     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14486     operands[4] = GEN_INT (mask);
14487     output_asm_insn (\"mfcr %1,%4\", operands);
14488   }
14489   return \"\";
14490 }"
14491   [(set_attr "type" "mfcrf")])
14492
14493 (define_insn "movesi_from_cr"
14494   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14495         (unspec:SI [(reg:CC 68) (reg:CC 69) (reg:CC 70) (reg:CC 71) 
14496                     (reg:CC 72) (reg:CC 73) (reg:CC 74) (reg:CC 75)]
14497                    UNSPEC_MOVESI_FROM_CR))]
14498   ""
14499   "mfcr %0"
14500   [(set_attr "type" "mfcr")])
14501
14502 (define_insn "*stmw"
14503   [(match_parallel 0 "stmw_operation"
14504                    [(set (match_operand:SI 1 "memory_operand" "=m")
14505                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
14506   "TARGET_MULTIPLE"
14507   "{stm|stmw} %2,%1")
14508  
14509 (define_insn "*save_fpregs_si"
14510   [(match_parallel 0 "any_operand"
14511                    [(clobber (match_operand:SI 1 "register_operand" "=l"))
14512                     (use (match_operand:SI 2 "call_operand" "s"))
14513                     (set (match_operand:DF 3 "memory_operand" "=m")
14514                          (match_operand:DF 4 "gpc_reg_operand" "f"))])]
14515   "TARGET_32BIT"
14516   "bl %z2"
14517   [(set_attr "type" "branch")
14518    (set_attr "length" "4")])
14519
14520 (define_insn "*save_fpregs_di"
14521   [(match_parallel 0 "any_operand"
14522                    [(clobber (match_operand:DI 1 "register_operand" "=l"))
14523                     (use (match_operand:DI 2 "call_operand" "s"))
14524                     (set (match_operand:DF 3 "memory_operand" "=m")
14525                          (match_operand:DF 4 "gpc_reg_operand" "f"))])]
14526   "TARGET_64BIT"
14527   "bl %z2"
14528   [(set_attr "type" "branch")
14529    (set_attr "length" "4")])
14530
14531 ; These are to explain that changes to the stack pointer should
14532 ; not be moved over stores to stack memory.
14533 (define_insn "stack_tie"
14534   [(set (match_operand:BLK 0 "memory_operand" "+m")
14535         (unspec:BLK [(match_dup 0)] UNSPEC_TIE))]
14536   ""
14537   ""
14538   [(set_attr "length" "0")])
14539
14540
14541 (define_expand "epilogue"
14542   [(use (const_int 0))]
14543   "TARGET_SCHED_PROLOG"
14544   "
14545 {
14546       rs6000_emit_epilogue (FALSE);
14547       DONE;
14548 }")
14549
14550 ; On some processors, doing the mtcrf one CC register at a time is
14551 ; faster (like on the 604e).  On others, doing them all at once is
14552 ; faster; for instance, on the 601 and 750.
14553
14554 (define_expand "movsi_to_cr_one"
14555   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14556         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14557                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
14558   ""
14559   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
14560
14561 (define_insn "*movsi_to_cr"
14562   [(match_parallel 0 "mtcrf_operation"
14563                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
14564                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
14565                                      (match_operand 3 "immediate_operand" "n")]
14566                                     UNSPEC_MOVESI_TO_CR))])]
14567  ""
14568  "*
14569 {
14570   int mask = 0;
14571   int i;
14572   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14573     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14574   operands[4] = GEN_INT (mask);
14575   return \"mtcrf %4,%2\";
14576 }"
14577   [(set_attr "type" "mtcr")])
14578
14579 (define_insn "*mtcrfsi"
14580   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14581         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14582                     (match_operand 2 "immediate_operand" "n")]
14583                    UNSPEC_MOVESI_TO_CR))]
14584   "GET_CODE (operands[0]) == REG 
14585    && CR_REGNO_P (REGNO (operands[0]))
14586    && GET_CODE (operands[2]) == CONST_INT
14587    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
14588   "mtcrf %R0,%1"
14589   [(set_attr "type" "mtcr")])
14590
14591 ; The load-multiple instructions have similar properties.
14592 ; Note that "load_multiple" is a name known to the machine-independent
14593 ; code that actually corresponds to the powerpc load-string.
14594
14595 (define_insn "*lmw"
14596   [(match_parallel 0 "lmw_operation"
14597                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14598                          (match_operand:SI 2 "memory_operand" "m"))])]
14599   "TARGET_MULTIPLE"
14600   "{lm|lmw} %1,%2")
14601  
14602 (define_insn "*return_internal_si"
14603   [(return)
14604    (use (match_operand:SI 0 "register_operand" "lc"))]
14605   "TARGET_32BIT"
14606   "b%T0"
14607   [(set_attr "type" "jmpreg")])
14608
14609 (define_insn "*return_internal_di"
14610   [(return)
14611    (use (match_operand:DI 0 "register_operand" "lc"))]
14612   "TARGET_64BIT"
14613   "b%T0"
14614   [(set_attr "type" "jmpreg")])
14615
14616 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
14617 ; stuff was in GCC.  Oh, and "any_operand" is a bit flexible...
14618
14619 (define_insn "*return_and_restore_fpregs_si"
14620  [(match_parallel 0 "any_operand"
14621                   [(return)
14622                    (use (match_operand:SI 1 "register_operand" "l"))
14623                    (use (match_operand:SI 2 "call_operand" "s"))
14624                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
14625                         (match_operand:DF 4 "memory_operand" "m"))])]
14626  "TARGET_32BIT"
14627  "b %z2")
14628
14629 (define_insn "*return_and_restore_fpregs_di"
14630  [(match_parallel 0 "any_operand"
14631                   [(return)
14632                    (use (match_operand:DI 1 "register_operand" "l"))
14633                    (use (match_operand:DI 2 "call_operand" "s"))
14634                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
14635                         (match_operand:DF 4 "memory_operand" "m"))])]
14636  "TARGET_64BIT"
14637  "b %z2")
14638
14639 ; This is used in compiling the unwind routines.
14640 (define_expand "eh_return"
14641   [(use (match_operand 0 "general_operand" ""))]
14642   ""
14643   "
14644 {
14645   if (TARGET_32BIT)
14646     emit_insn (gen_eh_set_lr_si (operands[0]));
14647   else
14648     emit_insn (gen_eh_set_lr_di (operands[0]));
14649   DONE;
14650 }")
14651
14652 ; We can't expand this before we know where the link register is stored.
14653 (define_insn "eh_set_lr_si"
14654   [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
14655                     UNSPECV_EH_RR)
14656    (clobber (match_scratch:SI 1 "=&b"))]
14657   "TARGET_32BIT"
14658   "#")
14659
14660 (define_insn "eh_set_lr_di"
14661   [(unspec_volatile [(match_operand:DI 0 "register_operand" "r")]
14662                     UNSPECV_EH_RR)
14663    (clobber (match_scratch:DI 1 "=&b"))]
14664   "TARGET_64BIT"
14665   "#")
14666
14667 (define_split
14668   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
14669    (clobber (match_scratch 1 ""))]
14670   "reload_completed"
14671   [(const_int 0)]
14672   "
14673 {
14674   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
14675   DONE;
14676 }")
14677
14678 (define_insn "prefetch"
14679   [(prefetch (match_operand:V4SI 0 "address_operand" "p")
14680              (match_operand:SI 1 "const_int_operand" "n")
14681              (match_operand:SI 2 "const_int_operand" "n"))]
14682   "TARGET_POWERPC"
14683   "*
14684 {
14685   if (GET_CODE (operands[0]) == REG)
14686     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
14687   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
14688 }"
14689   [(set_attr "type" "load")])
14690
14691 (include "altivec.md")
14692 (include "spe.md")