OSDN Git Service

2003-10-08 Aldy Hernandez <aldyh@redhat.com>
[pf3gnuchains/gcc-fork.git] / gcc / config / rs6000 / rs6000.md
1 ;; Machine description for IBM RISC System 6000 (POWER) for GNU C compiler
2 ;; Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 ;; 1999, 2000, 2001, 2002, 2003 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   ])
53
54 ;;
55 ;; UNSPEC_VOLATILE usage
56 ;;
57
58 (define_constants
59   [(UNSPECV_BLOCK               0)
60    (UNSPECV_EH_RR               9)      ; eh_reg_restore
61   ])
62 \f
63 ;; Define an insn type attribute.  This is used in function unit delay
64 ;; computations.
65 (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"
66   (const_string "integer"))
67
68 ;; Length (in bytes).
69 ; '(pc)' in the following doesn't include the instruction itself; it is 
70 ; calculated as if the instruction had zero size.
71 (define_attr "length" ""
72   (if_then_else (eq_attr "type" "branch")
73                 (if_then_else (and (ge (minus (match_dup 0) (pc))
74                                        (const_int -32768))
75                                    (lt (minus (match_dup 0) (pc))
76                                        (const_int 32764)))
77                               (const_int 4)
78                               (const_int 8))
79                 (const_int 4)))
80
81 ;; Processor type -- this attribute must exactly match the processor_type
82 ;; enumeration in rs6000.h.
83
84 (define_attr "cpu" "rios1,rios2,rs64a,mpccore,ppc403,ppc405,ppc440,ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630,ppc750,ppc7400,ppc7450,ppc8540,power4"
85   (const (symbol_ref "rs6000_cpu_attr")))
86
87 (automata_option "ndfa")
88
89 (include "rios1.md")
90 (include "rios2.md")
91 (include "rs64.md")
92 (include "mpc.md")
93 (include "40x.md")
94 (include "440.md")
95 (include "603.md")
96 (include "6xx.md")
97 (include "7xx.md")
98 (include "7450.md")
99 (include "8540.md")
100 (include "power4.md")
101
102 \f
103 ;; Start with fixed-point load and store insns.  Here we put only the more
104 ;; complex forms.  Basic data transfer is done later.
105
106 (define_expand "zero_extendqidi2"
107   [(set (match_operand:DI 0 "gpc_reg_operand" "")
108         (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "")))]
109   "TARGET_POWERPC64"
110   "")
111
112 (define_insn ""
113   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
114         (zero_extend:DI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
115   "TARGET_POWERPC64"
116   "@
117    lbz%U1%X1 %0,%1
118    rldicl %0,%1,0,56"
119   [(set_attr "type" "load,*")])
120
121 (define_insn ""
122   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
123         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
124                     (const_int 0)))
125    (clobber (match_scratch:DI 2 "=r,r"))]
126   "TARGET_POWERPC64"
127   "@
128    rldicl. %2,%1,0,56
129    #"
130   [(set_attr "type" "compare")
131    (set_attr "length" "4,8")])
132
133 (define_split
134   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
135         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
136                     (const_int 0)))
137    (clobber (match_scratch:DI 2 ""))]
138   "TARGET_POWERPC64 && reload_completed"
139   [(set (match_dup 2)
140         (zero_extend:DI (match_dup 1)))
141    (set (match_dup 0)
142         (compare:CC (match_dup 2)
143                     (const_int 0)))]
144   "")
145
146 (define_insn ""
147   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
148         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
149                     (const_int 0)))
150    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
151         (zero_extend:DI (match_dup 1)))]
152   "TARGET_POWERPC64"
153   "@
154    rldicl. %0,%1,0,56
155    #"
156   [(set_attr "type" "compare")
157    (set_attr "length" "4,8")])
158
159 (define_split
160   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
161         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
162                     (const_int 0)))
163    (set (match_operand:DI 0 "gpc_reg_operand" "")
164         (zero_extend:DI (match_dup 1)))]
165   "TARGET_POWERPC64 && reload_completed"
166   [(set (match_dup 0)
167         (zero_extend:DI (match_dup 1)))
168    (set (match_dup 2)
169         (compare:CC (match_dup 0)
170                     (const_int 0)))]
171   "")
172
173 (define_insn "extendqidi2"
174   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
175         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
176   "TARGET_POWERPC64"
177   "extsb %0,%1")
178
179 (define_insn ""
180   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
181         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
182                     (const_int 0)))
183    (clobber (match_scratch:DI 2 "=r,r"))]
184   "TARGET_POWERPC64"
185   "@
186    extsb. %2,%1
187    #"
188   [(set_attr "type" "compare")
189    (set_attr "length" "4,8")])
190
191 (define_split
192   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
193         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
194                     (const_int 0)))
195    (clobber (match_scratch:DI 2 ""))]
196   "TARGET_POWERPC64 && reload_completed"
197   [(set (match_dup 2)
198         (sign_extend:DI (match_dup 1)))
199    (set (match_dup 0)
200         (compare:CC (match_dup 2)
201                     (const_int 0)))]
202   "")
203
204 (define_insn ""
205   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
206         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
207                     (const_int 0)))
208    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
209         (sign_extend:DI (match_dup 1)))]
210   "TARGET_POWERPC64"
211   "@
212    extsb. %0,%1
213    #"
214   [(set_attr "type" "compare")
215    (set_attr "length" "4,8")])
216
217 (define_split
218   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
219         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
220                     (const_int 0)))
221    (set (match_operand:DI 0 "gpc_reg_operand" "")
222         (sign_extend:DI (match_dup 1)))]
223   "TARGET_POWERPC64 && reload_completed"
224   [(set (match_dup 0)
225         (sign_extend:DI (match_dup 1)))
226    (set (match_dup 2)
227         (compare:CC (match_dup 0)
228                     (const_int 0)))]
229   "")
230
231 (define_expand "zero_extendhidi2"
232   [(set (match_operand:DI 0 "gpc_reg_operand" "")
233         (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
234   "TARGET_POWERPC64"
235   "")
236
237 (define_insn ""
238   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
239         (zero_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
240   "TARGET_POWERPC64"
241   "@
242    lhz%U1%X1 %0,%1
243    rldicl %0,%1,0,48"
244   [(set_attr "type" "load,*")])
245
246 (define_insn ""
247   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
248         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
249                     (const_int 0)))
250    (clobber (match_scratch:DI 2 "=r,r"))]
251   "TARGET_POWERPC64"
252   "@
253    rldicl. %2,%1,0,48
254    #"
255   [(set_attr "type" "compare")
256    (set_attr "length" "4,8")])
257
258 (define_split
259   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
260         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
261                     (const_int 0)))
262    (clobber (match_scratch:DI 2 ""))]
263   "TARGET_POWERPC64 && reload_completed"
264   [(set (match_dup 2)
265         (zero_extend:DI (match_dup 1)))
266    (set (match_dup 0)
267         (compare:CC (match_dup 2)
268                     (const_int 0)))]
269   "")
270
271 (define_insn ""
272   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
273         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
274                     (const_int 0)))
275    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
276         (zero_extend:DI (match_dup 1)))]
277   "TARGET_POWERPC64"
278   "@
279    rldicl. %0,%1,0,48
280    #"
281   [(set_attr "type" "compare")
282    (set_attr "length" "4,8")])
283
284 (define_split
285   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
286         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
287                     (const_int 0)))
288    (set (match_operand:DI 0 "gpc_reg_operand" "")
289         (zero_extend:DI (match_dup 1)))]
290   "TARGET_POWERPC64 && reload_completed"
291   [(set (match_dup 0)
292         (zero_extend:DI (match_dup 1)))
293    (set (match_dup 2)
294         (compare:CC (match_dup 0)
295                     (const_int 0)))]
296   "")
297
298 (define_expand "extendhidi2"
299   [(set (match_operand:DI 0 "gpc_reg_operand" "")
300         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
301   "TARGET_POWERPC64"
302   "")
303
304 (define_insn ""
305   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
306         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
307   "TARGET_POWERPC64"
308   "@
309    lha%U1%X1 %0,%1
310    extsh %0,%1"
311   [(set_attr "type" "load_ext,*")])
312
313 (define_insn ""
314   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
315         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
316                     (const_int 0)))
317    (clobber (match_scratch:DI 2 "=r,r"))]
318   "TARGET_POWERPC64"
319   "@
320    extsh. %2,%1
321    #"
322   [(set_attr "type" "compare")
323    (set_attr "length" "4,8")])
324
325 (define_split
326   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
327         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
328                     (const_int 0)))
329    (clobber (match_scratch:DI 2 ""))]
330   "TARGET_POWERPC64 && reload_completed"
331   [(set (match_dup 2)
332         (sign_extend:DI (match_dup 1)))
333    (set (match_dup 0)
334         (compare:CC (match_dup 2)
335                     (const_int 0)))]
336   "")
337
338 (define_insn ""
339   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
340         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
341                     (const_int 0)))
342    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
343         (sign_extend:DI (match_dup 1)))]
344   "TARGET_POWERPC64"
345   "@
346    extsh. %0,%1
347    #"
348   [(set_attr "type" "compare")
349    (set_attr "length" "4,8")])
350
351 (define_split
352   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
353         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
354                     (const_int 0)))
355    (set (match_operand:DI 0 "gpc_reg_operand" "")
356         (sign_extend:DI (match_dup 1)))]
357   "TARGET_POWERPC64 && reload_completed"
358   [(set (match_dup 0)
359         (sign_extend:DI (match_dup 1)))
360    (set (match_dup 2)
361         (compare:CC (match_dup 0)
362                     (const_int 0)))]
363   "")
364
365 (define_expand "zero_extendsidi2"
366   [(set (match_operand:DI 0 "gpc_reg_operand" "")
367         (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
368   "TARGET_POWERPC64"
369   "")
370
371 (define_insn ""
372   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
373         (zero_extend:DI (match_operand:SI 1 "reg_or_mem_operand" "m,r")))]
374   "TARGET_POWERPC64"
375   "@
376    lwz%U1%X1 %0,%1
377    rldicl %0,%1,0,32"
378   [(set_attr "type" "load,*")])
379
380 (define_insn ""
381   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
382         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
383                     (const_int 0)))
384    (clobber (match_scratch:DI 2 "=r,r"))]
385   "TARGET_POWERPC64"
386   "@
387    rldicl. %2,%1,0,32
388    #"
389   [(set_attr "type" "compare")
390    (set_attr "length" "4,8")])
391
392 (define_split
393   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
394         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
395                     (const_int 0)))
396    (clobber (match_scratch:DI 2 ""))]
397   "TARGET_POWERPC64 && reload_completed"
398   [(set (match_dup 2)
399         (zero_extend:DI (match_dup 1)))
400    (set (match_dup 0)
401         (compare:CC (match_dup 2)
402                     (const_int 0)))]
403   "")
404
405 (define_insn ""
406   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
407         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
408                     (const_int 0)))
409    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
410         (zero_extend:DI (match_dup 1)))]
411   "TARGET_POWERPC64"
412   "@
413    rldicl. %0,%1,0,32
414    #"
415   [(set_attr "type" "compare")
416    (set_attr "length" "4,8")])
417
418 (define_split
419   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
420         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
421                     (const_int 0)))
422    (set (match_operand:DI 0 "gpc_reg_operand" "")
423         (zero_extend:DI (match_dup 1)))]
424   "TARGET_POWERPC64 && reload_completed"
425   [(set (match_dup 0)
426         (zero_extend:DI (match_dup 1)))
427    (set (match_dup 2)
428         (compare:CC (match_dup 0)
429                     (const_int 0)))]
430   "")
431
432 (define_expand "extendsidi2"
433   [(set (match_operand:DI 0 "gpc_reg_operand" "")
434         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
435   "TARGET_POWERPC64"
436   "")
437
438 (define_insn ""
439   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
440         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
441   "TARGET_POWERPC64"
442   "@
443    lwa%U1%X1 %0,%1
444    extsw %0,%1"
445   [(set_attr "type" "load_ext,*")])
446
447 (define_insn ""
448   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
449         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
450                     (const_int 0)))
451    (clobber (match_scratch:DI 2 "=r,r"))]
452   "TARGET_POWERPC64"
453   "@
454    extsw. %2,%1
455    #"
456   [(set_attr "type" "compare")
457    (set_attr "length" "4,8")])
458
459 (define_split
460   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
461         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
462                     (const_int 0)))
463    (clobber (match_scratch:DI 2 ""))]
464   "TARGET_POWERPC64 && reload_completed"
465   [(set (match_dup 2)
466         (sign_extend:DI (match_dup 1)))
467    (set (match_dup 0)
468         (compare:CC (match_dup 2)
469                     (const_int 0)))]
470   "")
471
472 (define_insn ""
473   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
474         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
475                     (const_int 0)))
476    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
477         (sign_extend:DI (match_dup 1)))]
478   "TARGET_POWERPC64"
479   "@
480    extsw. %0,%1
481    #"
482   [(set_attr "type" "compare")
483    (set_attr "length" "4,8")])
484
485 (define_split
486   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
487         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
488                     (const_int 0)))
489    (set (match_operand:DI 0 "gpc_reg_operand" "")
490         (sign_extend:DI (match_dup 1)))]
491   "TARGET_POWERPC64 && reload_completed"
492   [(set (match_dup 0)
493         (sign_extend:DI (match_dup 1)))
494    (set (match_dup 2)
495         (compare:CC (match_dup 0)
496                     (const_int 0)))]
497   "")
498
499 (define_expand "zero_extendqisi2"
500   [(set (match_operand:SI 0 "gpc_reg_operand" "")
501         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
502   ""
503   "")
504
505 (define_insn ""
506   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
507         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
508   ""
509   "@
510    lbz%U1%X1 %0,%1
511    {rlinm|rlwinm} %0,%1,0,0xff"
512   [(set_attr "type" "load,*")])
513
514 (define_insn ""
515   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
516         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
517                     (const_int 0)))
518    (clobber (match_scratch:SI 2 "=r,r"))]
519   ""
520   "@
521    {andil.|andi.} %2,%1,0xff
522    #"
523   [(set_attr "type" "compare")
524    (set_attr "length" "4,8")])
525
526 (define_split
527   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
528         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
529                     (const_int 0)))
530    (clobber (match_scratch:SI 2 ""))]
531   "reload_completed"
532   [(set (match_dup 2)
533         (zero_extend:SI (match_dup 1)))
534    (set (match_dup 0)
535         (compare:CC (match_dup 2)
536                     (const_int 0)))]
537   "")
538
539 (define_insn ""
540   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
541         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
542                     (const_int 0)))
543    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
544         (zero_extend:SI (match_dup 1)))]
545   ""
546   "@
547    {andil.|andi.} %0,%1,0xff
548    #"
549   [(set_attr "type" "compare")
550    (set_attr "length" "4,8")])
551
552 (define_split
553   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
554         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
555                     (const_int 0)))
556    (set (match_operand:SI 0 "gpc_reg_operand" "")
557         (zero_extend:SI (match_dup 1)))]
558   "reload_completed"
559   [(set (match_dup 0)
560         (zero_extend:SI (match_dup 1)))
561    (set (match_dup 2)
562         (compare:CC (match_dup 0)
563                     (const_int 0)))]
564   "")
565
566 (define_expand "extendqisi2"
567   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
568    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
569   ""
570   "
571 {
572   if (TARGET_POWERPC)
573     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
574   else if (TARGET_POWER)
575     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
576   else
577     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
578   DONE;
579 }")
580
581 (define_insn "extendqisi2_ppc"
582   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
583         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
584   "TARGET_POWERPC"
585   "extsb %0,%1")
586
587 (define_insn ""
588   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
589         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
590                     (const_int 0)))
591    (clobber (match_scratch:SI 2 "=r,r"))]
592   "TARGET_POWERPC"
593   "@
594    extsb. %2,%1
595    #"
596   [(set_attr "type" "compare")
597    (set_attr "length" "4,8")])
598
599 (define_split
600   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
601         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
602                     (const_int 0)))
603    (clobber (match_scratch:SI 2 ""))]
604   "TARGET_POWERPC && reload_completed"
605   [(set (match_dup 2)
606         (sign_extend:SI (match_dup 1)))
607    (set (match_dup 0)
608         (compare:CC (match_dup 2)
609                     (const_int 0)))]
610   "")
611
612 (define_insn ""
613   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
614         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
615                     (const_int 0)))
616    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
617         (sign_extend:SI (match_dup 1)))]
618   "TARGET_POWERPC"
619   "@
620    extsb. %0,%1
621    #"
622   [(set_attr "type" "compare")
623    (set_attr "length" "4,8")])
624
625 (define_split
626   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
627         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
628                     (const_int 0)))
629    (set (match_operand:SI 0 "gpc_reg_operand" "")
630         (sign_extend:SI (match_dup 1)))]
631   "TARGET_POWERPC && reload_completed"
632   [(set (match_dup 0)
633         (sign_extend:SI (match_dup 1)))
634    (set (match_dup 2)
635         (compare:CC (match_dup 0)
636                     (const_int 0)))]
637   "")
638
639 (define_expand "extendqisi2_power"
640   [(parallel [(set (match_dup 2)
641                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
642                               (const_int 24)))
643               (clobber (scratch:SI))])
644    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
645                    (ashiftrt:SI (match_dup 2)
646                                 (const_int 24)))
647               (clobber (scratch:SI))])]
648   "TARGET_POWER"
649   "
650 { operands[1] = gen_lowpart (SImode, operands[1]);
651   operands[2] = gen_reg_rtx (SImode); }")
652
653 (define_expand "extendqisi2_no_power"
654   [(set (match_dup 2)
655         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
656                    (const_int 24)))
657    (set (match_operand:SI 0 "gpc_reg_operand" "")
658         (ashiftrt:SI (match_dup 2)
659                      (const_int 24)))]
660   "! TARGET_POWER && ! TARGET_POWERPC"
661   "
662 { operands[1] = gen_lowpart (SImode, operands[1]);
663   operands[2] = gen_reg_rtx (SImode); }")
664
665 (define_expand "zero_extendqihi2"
666   [(set (match_operand:HI 0 "gpc_reg_operand" "")
667         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
668   ""
669   "")
670
671 (define_insn ""
672   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
673         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
674   ""
675   "@
676    lbz%U1%X1 %0,%1
677    {rlinm|rlwinm} %0,%1,0,0xff"
678   [(set_attr "type" "load,*")])
679
680 (define_insn ""
681   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
682         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
683                     (const_int 0)))
684    (clobber (match_scratch:HI 2 "=r,r"))]
685   ""
686   "@
687    {andil.|andi.} %2,%1,0xff
688    #"
689   [(set_attr "type" "compare")
690    (set_attr "length" "4,8")])
691
692 (define_split
693   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
694         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
695                     (const_int 0)))
696    (clobber (match_scratch:HI 2 ""))]
697   "reload_completed"
698   [(set (match_dup 2)
699         (zero_extend:HI (match_dup 1)))
700    (set (match_dup 0)
701         (compare:CC (match_dup 2)
702                     (const_int 0)))]
703   "")
704
705 (define_insn ""
706   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
707         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
708                     (const_int 0)))
709    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
710         (zero_extend:HI (match_dup 1)))]
711   ""
712   "@
713    {andil.|andi.} %0,%1,0xff
714    #"
715   [(set_attr "type" "compare")
716    (set_attr "length" "4,8")])
717
718 (define_split
719   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
720         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
721                     (const_int 0)))
722    (set (match_operand:HI 0 "gpc_reg_operand" "")
723         (zero_extend:HI (match_dup 1)))]
724   "reload_completed"
725   [(set (match_dup 0)
726         (zero_extend:HI (match_dup 1)))
727    (set (match_dup 2)
728         (compare:CC (match_dup 0)
729                     (const_int 0)))]
730   "")
731
732 (define_expand "extendqihi2"
733   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
734    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
735   ""
736   "
737 {
738   if (TARGET_POWERPC)
739     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
740   else if (TARGET_POWER)
741     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
742   else
743     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
744   DONE;
745 }")
746
747 (define_insn "extendqihi2_ppc"
748   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
749         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
750   "TARGET_POWERPC"
751   "extsb %0,%1")
752
753 (define_insn ""
754   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
755         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
756                     (const_int 0)))
757    (clobber (match_scratch:HI 2 "=r,r"))]
758   "TARGET_POWERPC"
759   "@
760    extsb. %2,%1
761    #"
762   [(set_attr "type" "compare")
763    (set_attr "length" "4,8")])
764
765 (define_split
766   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
767         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
768                     (const_int 0)))
769    (clobber (match_scratch:HI 2 ""))]
770   "TARGET_POWERPC && reload_completed"
771   [(set (match_dup 2)
772         (sign_extend:HI (match_dup 1)))
773    (set (match_dup 0)
774         (compare:CC (match_dup 2)
775                     (const_int 0)))]
776   "")
777
778 (define_insn ""
779   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
780         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
781                     (const_int 0)))
782    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
783         (sign_extend:HI (match_dup 1)))]
784   "TARGET_POWERPC"
785   "@
786    extsb. %0,%1
787    #"
788   [(set_attr "type" "compare")
789    (set_attr "length" "4,8")])
790
791 (define_split
792   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
793         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
794                     (const_int 0)))
795    (set (match_operand:HI 0 "gpc_reg_operand" "")
796         (sign_extend:HI (match_dup 1)))]
797   "TARGET_POWERPC && reload_completed"
798   [(set (match_dup 0)
799         (sign_extend:HI (match_dup 1)))
800    (set (match_dup 2)
801         (compare:CC (match_dup 0)
802                     (const_int 0)))]
803   "")
804
805 (define_expand "extendqihi2_power"
806   [(parallel [(set (match_dup 2)
807                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
808                               (const_int 24)))
809               (clobber (scratch:SI))])
810    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
811                    (ashiftrt:SI (match_dup 2)
812                                 (const_int 24)))
813               (clobber (scratch:SI))])]
814   "TARGET_POWER"
815   "
816 { operands[0] = gen_lowpart (SImode, operands[0]);
817   operands[1] = gen_lowpart (SImode, operands[1]);
818   operands[2] = gen_reg_rtx (SImode); }")
819
820 (define_expand "extendqihi2_no_power"
821   [(set (match_dup 2)
822         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
823                    (const_int 24)))
824    (set (match_operand:HI 0 "gpc_reg_operand" "")
825         (ashiftrt:SI (match_dup 2)
826                      (const_int 24)))]
827   "! TARGET_POWER && ! TARGET_POWERPC"
828   "
829 { operands[0] = gen_lowpart (SImode, operands[0]);
830   operands[1] = gen_lowpart (SImode, operands[1]);
831   operands[2] = gen_reg_rtx (SImode); }")
832
833 (define_expand "zero_extendhisi2"
834   [(set (match_operand:SI 0 "gpc_reg_operand" "")
835         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
836   ""
837   "")
838
839 (define_insn ""
840   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
841         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
842   ""
843   "@
844    lhz%U1%X1 %0,%1
845    {rlinm|rlwinm} %0,%1,0,0xffff"
846   [(set_attr "type" "load,*")])
847
848 (define_insn ""
849   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
850         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
851                     (const_int 0)))
852    (clobber (match_scratch:SI 2 "=r,r"))]
853   ""
854   "@
855    {andil.|andi.} %2,%1,0xffff
856    #"
857   [(set_attr "type" "compare")
858    (set_attr "length" "4,8")])
859
860 (define_split
861   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
862         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
863                     (const_int 0)))
864    (clobber (match_scratch:SI 2 ""))]
865   "reload_completed"
866   [(set (match_dup 2)
867         (zero_extend:SI (match_dup 1)))
868    (set (match_dup 0)
869         (compare:CC (match_dup 2)
870                     (const_int 0)))]
871   "")
872
873 (define_insn ""
874   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
875         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
876                     (const_int 0)))
877    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
878         (zero_extend:SI (match_dup 1)))]
879   ""
880   "@
881    {andil.|andi.} %0,%1,0xffff
882    #"
883   [(set_attr "type" "compare")
884    (set_attr "length" "4,8")])
885
886 (define_split
887   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
888         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
889                     (const_int 0)))
890    (set (match_operand:SI 0 "gpc_reg_operand" "")
891         (zero_extend:SI (match_dup 1)))]
892   "reload_completed"
893   [(set (match_dup 0)
894         (zero_extend:SI (match_dup 1)))
895    (set (match_dup 2)
896         (compare:CC (match_dup 0)
897                     (const_int 0)))]
898   "")
899
900 (define_expand "extendhisi2"
901   [(set (match_operand:SI 0 "gpc_reg_operand" "")
902         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
903   ""
904   "")
905
906 (define_insn ""
907   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
908         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
909   ""
910   "@
911    lha%U1%X1 %0,%1
912    {exts|extsh} %0,%1"
913   [(set_attr "type" "load_ext,*")])
914
915 (define_insn ""
916   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
917         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
918                     (const_int 0)))
919    (clobber (match_scratch:SI 2 "=r,r"))]
920   ""
921   "@
922    {exts.|extsh.} %2,%1
923    #"
924   [(set_attr "type" "compare")
925    (set_attr "length" "4,8")])
926
927 (define_split
928   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
929         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
930                     (const_int 0)))
931    (clobber (match_scratch:SI 2 ""))]
932   "reload_completed"
933   [(set (match_dup 2)
934         (sign_extend:SI (match_dup 1)))
935    (set (match_dup 0)
936         (compare:CC (match_dup 2)
937                     (const_int 0)))]
938   "")
939
940 (define_insn ""
941   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
942         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
943                     (const_int 0)))
944    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
945         (sign_extend:SI (match_dup 1)))]
946   ""
947   "@
948    {exts.|extsh.} %0,%1
949    #"
950   [(set_attr "type" "compare")
951    (set_attr "length" "4,8")])
952 \f
953 (define_split
954   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
955         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
956                     (const_int 0)))
957    (set (match_operand:SI 0 "gpc_reg_operand" "")
958         (sign_extend:SI (match_dup 1)))]
959   "reload_completed"
960   [(set (match_dup 0)
961         (sign_extend:SI (match_dup 1)))
962    (set (match_dup 2)
963         (compare:CC (match_dup 0)
964                     (const_int 0)))]
965   "")
966
967 ;; Fixed-point arithmetic insns.
968
969 ;; Discourage ai/addic because of carry but provide it in an alternative
970 ;; allowing register zero as source.
971 (define_expand "addsi3"
972   [(set (match_operand:SI 0 "gpc_reg_operand" "")
973         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
974                  (match_operand:SI 2 "reg_or_arith_cint_operand" "")))]
975   ""
976   "
977 {
978   if (GET_CODE (operands[2]) == CONST_INT
979                 && ! add_operand (operands[2], SImode))
980     {
981       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
982                  ? operands[0] : gen_reg_rtx (SImode));
983
984       HOST_WIDE_INT val = INTVAL (operands[2]);
985       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
986       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, SImode);
987
988       /* The ordering here is important for the prolog expander.
989          When space is allocated from the stack, adding 'low' first may
990          produce a temporary deallocation (which would be bad).  */
991       emit_insn (gen_addsi3 (tmp, operands[1], GEN_INT (rest)));
992       emit_insn (gen_addsi3 (operands[0], tmp, GEN_INT (low)));
993       DONE;
994     }
995 }")
996
997 (define_insn "*addsi3_internal1"
998   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,?r,r")
999         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,b,r,b")
1000                  (match_operand:SI 2 "add_operand" "r,I,I,L")))]
1001   ""
1002   "@
1003    {cax|add} %0,%1,%2
1004    {cal %0,%2(%1)|addi %0,%1,%2}
1005    {ai|addic} %0,%1,%2
1006    {cau|addis} %0,%1,%v2"
1007   [(set_attr "length" "4,4,4,4")])
1008
1009 (define_insn "addsi3_high"
1010   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1011         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1012                  (high:SI (match_operand 2 "" ""))))]
1013   "TARGET_MACHO && !TARGET_64BIT"
1014   "{cau|addis} %0,%1,ha16(%2)"
1015   [(set_attr "length" "4")])
1016
1017 (define_insn "*addsi3_internal2"
1018   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1019         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1020                              (match_operand:SI 2 "reg_or_short_operand" "r,I,r,I"))
1021                     (const_int 0)))
1022    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
1023   "! TARGET_POWERPC64"
1024   "@
1025    {cax.|add.} %3,%1,%2
1026    {ai.|addic.} %3,%1,%2
1027    #
1028    #"
1029   [(set_attr "type" "fast_compare,compare,compare,compare")
1030    (set_attr "length" "4,4,8,8")])
1031
1032 (define_split
1033   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1034         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1035                              (match_operand:SI 2 "reg_or_short_operand" ""))
1036                     (const_int 0)))
1037    (clobber (match_scratch:SI 3 ""))]
1038   "! TARGET_POWERPC64 && reload_completed"
1039   [(set (match_dup 3)
1040         (plus:SI (match_dup 1)
1041                  (match_dup 2)))
1042    (set (match_dup 0)
1043         (compare:CC (match_dup 3)
1044                     (const_int 0)))]
1045   "")
1046
1047 (define_insn "*addsi3_internal3"
1048   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1049         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1050                              (match_operand:SI 2 "reg_or_short_operand" "r,I,r,I"))
1051                     (const_int 0)))
1052    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
1053         (plus:SI (match_dup 1)
1054                  (match_dup 2)))]
1055   "! TARGET_POWERPC64"
1056   "@
1057    {cax.|add.} %0,%1,%2
1058    {ai.|addic.} %0,%1,%2
1059    #
1060    #"
1061   [(set_attr "type" "fast_compare,compare,compare,compare")
1062    (set_attr "length" "4,4,8,8")])
1063
1064 (define_split
1065   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1066         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1067                              (match_operand:SI 2 "reg_or_short_operand" ""))
1068                     (const_int 0)))
1069    (set (match_operand:SI 0 "gpc_reg_operand" "")
1070         (plus:SI (match_dup 1) (match_dup 2)))]
1071   "! TARGET_POWERPC64 && reload_completed"
1072   [(set (match_dup 0)
1073         (plus:SI (match_dup 1)
1074                  (match_dup 2)))
1075    (set (match_dup 3)
1076         (compare:CC (match_dup 0)
1077                     (const_int 0)))]
1078   "")
1079
1080 ;; Split an add that we can't do in one insn into two insns, each of which
1081 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1082 ;; add should be last in case the result gets used in an address.
1083
1084 (define_split
1085   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1086         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1087                  (match_operand:SI 2 "non_add_cint_operand" "")))]
1088   ""
1089   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 3)))
1090    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 4)))]
1091 "
1092 {
1093   HOST_WIDE_INT val = INTVAL (operands[2]);
1094   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1095   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, SImode);
1096
1097   operands[3] = GEN_INT (rest);
1098   operands[4] = GEN_INT (low);
1099 }")
1100
1101 (define_insn "one_cmplsi2"
1102   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1103         (not:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1104   ""
1105   "nor %0,%1,%1")
1106
1107 (define_insn ""
1108   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1109         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1110                     (const_int 0)))
1111    (clobber (match_scratch:SI 2 "=r,r"))]
1112   "! TARGET_POWERPC64"
1113   "@
1114    nor. %2,%1,%1
1115    #"
1116   [(set_attr "type" "compare")
1117    (set_attr "length" "4,8")])
1118
1119 (define_split
1120   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1121         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1122                     (const_int 0)))
1123    (clobber (match_scratch:SI 2 ""))]
1124   "! TARGET_POWERPC64 && reload_completed"
1125   [(set (match_dup 2)
1126         (not:SI (match_dup 1)))
1127    (set (match_dup 0)
1128         (compare:CC (match_dup 2)
1129                     (const_int 0)))]
1130   "")
1131
1132 (define_insn ""
1133   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1134         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1135                     (const_int 0)))
1136    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1137         (not:SI (match_dup 1)))]
1138   "! TARGET_POWERPC64"
1139   "@
1140    nor. %0,%1,%1
1141    #"
1142   [(set_attr "type" "compare")
1143    (set_attr "length" "4,8")])
1144
1145 (define_split
1146   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1147         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1148                     (const_int 0)))
1149    (set (match_operand:SI 0 "gpc_reg_operand" "")
1150         (not:SI (match_dup 1)))]
1151   "! TARGET_POWERPC64 && reload_completed"
1152   [(set (match_dup 0)
1153         (not:SI (match_dup 1)))
1154    (set (match_dup 2)
1155         (compare:CC (match_dup 0)
1156                     (const_int 0)))]
1157   "")
1158
1159 (define_insn ""
1160   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1161         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
1162                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
1163   "! TARGET_POWERPC"
1164   "{sf%I1|subf%I1c} %0,%2,%1")
1165
1166 (define_insn ""
1167   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1168         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "r,I")
1169                   (match_operand:SI 2 "gpc_reg_operand" "r,r")))]
1170   "TARGET_POWERPC"
1171   "@
1172    subf %0,%2,%1
1173    subfic %0,%2,%1")
1174
1175 (define_insn ""
1176   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1177         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1178                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1179                     (const_int 0)))
1180    (clobber (match_scratch:SI 3 "=r,r"))]
1181   "! TARGET_POWERPC"
1182   "@
1183    {sf.|subfc.} %3,%2,%1
1184    #"
1185   [(set_attr "type" "compare")
1186    (set_attr "length" "4,8")])
1187
1188 (define_insn ""
1189   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1190         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1191                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1192                     (const_int 0)))
1193    (clobber (match_scratch:SI 3 "=r,r"))]
1194   "TARGET_POWERPC && ! TARGET_POWERPC64"
1195   "@
1196    subf. %3,%2,%1
1197    #"
1198   [(set_attr "type" "fast_compare")
1199    (set_attr "length" "4,8")])
1200
1201 (define_split
1202   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1203         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1204                               (match_operand:SI 2 "gpc_reg_operand" ""))
1205                     (const_int 0)))
1206    (clobber (match_scratch:SI 3 ""))]
1207   "! TARGET_POWERPC64 && reload_completed"
1208   [(set (match_dup 3)
1209         (minus:SI (match_dup 1)
1210                   (match_dup 2)))
1211    (set (match_dup 0)
1212         (compare:CC (match_dup 3)
1213                     (const_int 0)))]
1214   "")
1215
1216 (define_insn ""
1217   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1218         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1219                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1220                     (const_int 0)))
1221    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1222         (minus:SI (match_dup 1) (match_dup 2)))]
1223   "! TARGET_POWERPC"
1224   "@
1225    {sf.|subfc.} %0,%2,%1
1226    #"
1227   [(set_attr "type" "compare")
1228    (set_attr "length" "4,8")])
1229
1230 (define_insn ""
1231   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1232         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1233                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1234                     (const_int 0)))
1235    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1236         (minus:SI (match_dup 1)
1237                   (match_dup 2)))]
1238   "TARGET_POWERPC && ! TARGET_POWERPC64"
1239   "@
1240    subf. %0,%2,%1
1241    #"
1242   [(set_attr "type" "fast_compare")
1243    (set_attr "length" "4,8")])
1244
1245 (define_split
1246   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1247         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1248                               (match_operand:SI 2 "gpc_reg_operand" ""))
1249                     (const_int 0)))
1250    (set (match_operand:SI 0 "gpc_reg_operand" "")
1251         (minus:SI (match_dup 1)
1252                   (match_dup 2)))]
1253   "! TARGET_POWERPC64 && reload_completed"
1254   [(set (match_dup 0)
1255         (minus:SI (match_dup 1)
1256                   (match_dup 2)))
1257    (set (match_dup 3)
1258         (compare:CC (match_dup 0)
1259                     (const_int 0)))]
1260   "")
1261
1262 (define_expand "subsi3"
1263   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1264         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "")
1265                   (match_operand:SI 2 "reg_or_arith_cint_operand" "")))]
1266   ""
1267   "
1268 {
1269   if (GET_CODE (operands[2]) == CONST_INT)
1270     {
1271       emit_insn (gen_addsi3 (operands[0], operands[1],
1272                              negate_rtx (SImode, operands[2])));
1273       DONE;
1274     }
1275 }")
1276
1277 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1278 ;; instruction and some auxiliary computations.  Then we just have a single
1279 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1280 ;; combine.
1281
1282 (define_expand "sminsi3"
1283   [(set (match_dup 3)
1284         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1285                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1286                          (const_int 0)
1287                          (minus:SI (match_dup 2) (match_dup 1))))
1288    (set (match_operand:SI 0 "gpc_reg_operand" "")
1289         (minus:SI (match_dup 2) (match_dup 3)))]
1290   "TARGET_POWER || TARGET_ISEL"
1291   "
1292 {
1293   if (TARGET_ISEL)
1294     {
1295       operands[2] = force_reg (SImode, operands[2]);
1296       rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
1297       DONE;
1298     }
1299
1300   operands[3] = gen_reg_rtx (SImode);
1301 }")
1302
1303 (define_split
1304   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1305         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1306                  (match_operand:SI 2 "reg_or_short_operand" "")))
1307    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1308   "TARGET_POWER"
1309   [(set (match_dup 3)
1310         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1311                          (const_int 0)
1312                          (minus:SI (match_dup 2) (match_dup 1))))
1313    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1314   "")
1315
1316 (define_expand "smaxsi3"
1317   [(set (match_dup 3)
1318         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1319                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1320                          (const_int 0)
1321                          (minus:SI (match_dup 2) (match_dup 1))))
1322    (set (match_operand:SI 0 "gpc_reg_operand" "")
1323         (plus:SI (match_dup 3) (match_dup 1)))]
1324   "TARGET_POWER || TARGET_ISEL"
1325   "
1326 {
1327   if (TARGET_ISEL)
1328     {
1329       operands[2] = force_reg (SImode, operands[2]);
1330       rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
1331       DONE;
1332     }
1333   operands[3] = gen_reg_rtx (SImode);
1334 }")
1335
1336 (define_split
1337   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1338         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1339                  (match_operand:SI 2 "reg_or_short_operand" "")))
1340    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1341   "TARGET_POWER"
1342   [(set (match_dup 3)
1343         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1344                          (const_int 0)
1345                          (minus:SI (match_dup 2) (match_dup 1))))
1346    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1347   "")
1348
1349 (define_expand "uminsi3"
1350   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1351                               (match_dup 5)))
1352    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1353                               (match_dup 5)))
1354    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1355                                        (const_int 0)
1356                                        (minus:SI (match_dup 4) (match_dup 3))))
1357    (set (match_operand:SI 0 "gpc_reg_operand" "")
1358         (minus:SI (match_dup 2) (match_dup 3)))]
1359   "TARGET_POWER || TARGET_ISEL"
1360   "
1361 {
1362   if (TARGET_ISEL)
1363     {
1364       rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
1365       DONE;
1366     }
1367   operands[3] = gen_reg_rtx (SImode);
1368   operands[4] = gen_reg_rtx (SImode);
1369   operands[5] = GEN_INT (-2147483647 - 1);
1370 }")
1371
1372 (define_expand "umaxsi3"
1373   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1374                               (match_dup 5)))
1375    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1376                               (match_dup 5)))
1377    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1378                                        (const_int 0)
1379                                        (minus:SI (match_dup 4) (match_dup 3))))
1380    (set (match_operand:SI 0 "gpc_reg_operand" "")
1381         (plus:SI (match_dup 3) (match_dup 1)))]
1382   "TARGET_POWER || TARGET_ISEL"
1383   "
1384 {
1385   if (TARGET_ISEL)
1386     {
1387       rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
1388       DONE;
1389     }
1390   operands[3] = gen_reg_rtx (SImode);
1391   operands[4] = gen_reg_rtx (SImode);
1392   operands[5] = GEN_INT (-2147483647 - 1);
1393 }")
1394
1395 (define_insn ""
1396   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1397         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1398                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
1399                          (const_int 0)
1400                          (minus:SI (match_dup 2) (match_dup 1))))]
1401   "TARGET_POWER"
1402   "doz%I2 %0,%1,%2")
1403
1404 (define_insn ""
1405   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1406         (compare:CC
1407          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1408                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1409                           (const_int 0)
1410                           (minus:SI (match_dup 2) (match_dup 1)))
1411          (const_int 0)))
1412    (clobber (match_scratch:SI 3 "=r,r"))]
1413   "TARGET_POWER"
1414   "@
1415    doz%I2. %3,%1,%2
1416    #"
1417   [(set_attr "type" "delayed_compare")
1418    (set_attr "length" "4,8")])
1419
1420 (define_split
1421   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1422         (compare:CC
1423          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1424                               (match_operand:SI 2 "reg_or_short_operand" ""))
1425                           (const_int 0)
1426                           (minus:SI (match_dup 2) (match_dup 1)))
1427          (const_int 0)))
1428    (clobber (match_scratch:SI 3 ""))]
1429   "TARGET_POWER && reload_completed"
1430   [(set (match_dup 3)
1431         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1432                           (const_int 0)
1433                           (minus:SI (match_dup 2) (match_dup 1))))
1434    (set (match_dup 0)
1435         (compare:CC (match_dup 3)
1436                     (const_int 0)))]
1437   "")
1438
1439 (define_insn ""
1440   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1441         (compare:CC
1442          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1443                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1444                           (const_int 0)
1445                           (minus:SI (match_dup 2) (match_dup 1)))
1446          (const_int 0)))
1447    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1448         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1449                          (const_int 0)
1450                          (minus:SI (match_dup 2) (match_dup 1))))]
1451   "TARGET_POWER"
1452   "@
1453    doz%I2. %0,%1,%2
1454    #"
1455   [(set_attr "type" "delayed_compare")
1456    (set_attr "length" "4,8")])
1457
1458 (define_split
1459   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1460         (compare:CC
1461          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1462                               (match_operand:SI 2 "reg_or_short_operand" ""))
1463                           (const_int 0)
1464                           (minus:SI (match_dup 2) (match_dup 1)))
1465          (const_int 0)))
1466    (set (match_operand:SI 0 "gpc_reg_operand" "")
1467         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1468                          (const_int 0)
1469                          (minus:SI (match_dup 2) (match_dup 1))))]
1470   "TARGET_POWER && reload_completed"
1471   [(set (match_dup 0)
1472         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1473                          (const_int 0)
1474                          (minus:SI (match_dup 2) (match_dup 1))))
1475    (set (match_dup 3)
1476         (compare:CC (match_dup 0)
1477                     (const_int 0)))]
1478   "")
1479
1480 ;; We don't need abs with condition code because such comparisons should
1481 ;; never be done.
1482 (define_expand "abssi2"
1483   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1484         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
1485   ""
1486   "
1487 {
1488   if (TARGET_ISEL)
1489     {
1490       emit_insn (gen_abssi2_isel (operands[0], operands[1]));
1491       DONE;
1492     }
1493   else if (! TARGET_POWER)
1494     {
1495       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
1496       DONE;
1497     }
1498 }")
1499
1500 (define_insn "*abssi2_power"
1501   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1502         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1503   "TARGET_POWER"
1504   "abs %0,%1")
1505
1506 (define_insn_and_split "abssi2_isel"
1507   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1508         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
1509    (clobber (match_scratch:SI 2 "=&b"))
1510    (clobber (match_scratch:CC 3 "=y"))]
1511   "TARGET_ISEL"
1512   "#"
1513   "&& reload_completed"
1514   [(set (match_dup 2) (neg:SI (match_dup 1)))
1515    (set (match_dup 3)
1516         (compare:CC (match_dup 1)
1517                     (const_int 0)))
1518    (set (match_dup 0)
1519         (if_then_else:SI (ge (match_dup 3)
1520                              (const_int 0))
1521                          (match_dup 1)
1522                          (match_dup 2)))]
1523   "")
1524
1525 (define_insn_and_split "abssi2_nopower"
1526   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1527         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
1528    (clobber (match_scratch:SI 2 "=&r,&r"))]
1529   "! TARGET_POWER && ! TARGET_ISEL"
1530   "#"
1531   "&& reload_completed"
1532   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1533    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1534    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
1535   "")
1536
1537 (define_insn "*nabs_power"
1538   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1539         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
1540   "TARGET_POWER"
1541   "nabs %0,%1")
1542
1543 (define_insn_and_split "*nabs_nopower"
1544   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1545         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
1546    (clobber (match_scratch:SI 2 "=&r,&r"))]
1547   "! TARGET_POWER"
1548   "#"
1549   "&& reload_completed"
1550   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1551    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1552    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
1553   "")
1554
1555 (define_insn "negsi2"
1556   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1557         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1558   ""
1559   "neg %0,%1")
1560
1561 (define_insn ""
1562   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1563         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1564                     (const_int 0)))
1565    (clobber (match_scratch:SI 2 "=r,r"))]
1566   "! TARGET_POWERPC64"
1567   "@
1568    neg. %2,%1
1569    #"
1570   [(set_attr "type" "fast_compare")
1571    (set_attr "length" "4,8")])
1572
1573 (define_split
1574   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1575         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1576                     (const_int 0)))
1577    (clobber (match_scratch:SI 2 ""))]
1578   "! TARGET_POWERPC64 && reload_completed"
1579   [(set (match_dup 2)
1580         (neg:SI (match_dup 1)))
1581    (set (match_dup 0)
1582         (compare:CC (match_dup 2)
1583                     (const_int 0)))]
1584   "")
1585
1586 (define_insn ""
1587   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1588         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1589                     (const_int 0)))
1590    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1591         (neg:SI (match_dup 1)))]
1592   "! TARGET_POWERPC64"
1593   "@
1594    neg. %0,%1
1595    #"
1596   [(set_attr "type" "fast_compare")
1597    (set_attr "length" "4,8")])
1598
1599 (define_split
1600   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1601         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1602                     (const_int 0)))
1603    (set (match_operand:SI 0 "gpc_reg_operand" "")
1604         (neg:SI (match_dup 1)))]
1605   "! TARGET_POWERPC64 && reload_completed"
1606   [(set (match_dup 0)
1607         (neg:SI (match_dup 1)))
1608    (set (match_dup 2)
1609         (compare:CC (match_dup 0)
1610                     (const_int 0)))]
1611   "")
1612
1613 (define_insn "clzsi2"
1614   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1615         (clz:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1616   ""
1617   "{cntlz|cntlzw} %0,%1")
1618
1619 (define_expand "ctzsi2"
1620   [(set (match_dup 2)
1621         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
1622    (parallel [(set (match_dup 3) (and:SI (match_dup 1)
1623                                          (match_dup 2)))
1624               (clobber (scratch:CC))])
1625    (set (match_dup 4) (clz:SI (match_dup 3)))
1626    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1627         (minus:SI (const_int 31) (match_dup 4)))]
1628   ""
1629   {
1630      operands[2] = gen_reg_rtx (SImode);
1631      operands[3] = gen_reg_rtx (SImode);
1632      operands[4] = gen_reg_rtx (SImode);
1633   })
1634   
1635 (define_expand "ffssi2"
1636   [(set (match_dup 2)
1637         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
1638    (parallel [(set (match_dup 3) (and:SI (match_dup 1)
1639                                          (match_dup 2)))
1640               (clobber (scratch:CC))])
1641    (set (match_dup 4) (clz:SI (match_dup 3)))
1642    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1643         (minus:SI (const_int 32) (match_dup 4)))]
1644   ""
1645   {
1646      operands[2] = gen_reg_rtx (SImode);
1647      operands[3] = gen_reg_rtx (SImode);
1648      operands[4] = gen_reg_rtx (SImode);
1649   })
1650   
1651 (define_expand "mulsi3"
1652   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1653    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1654    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
1655   ""
1656   "
1657 {
1658   if (TARGET_POWER)
1659     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
1660   else
1661     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
1662   DONE;
1663 }")
1664
1665 (define_insn "mulsi3_mq"
1666   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1667         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1668                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
1669    (clobber (match_scratch:SI 3 "=q,q"))]
1670   "TARGET_POWER"
1671   "@
1672    {muls|mullw} %0,%1,%2
1673    {muli|mulli} %0,%1,%2"
1674    [(set (attr "type") 
1675       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
1676                 (const_string "imul3")
1677              (match_operand:SI 2 "short_cint_operand" "") 
1678                 (const_string "imul2")]
1679         (const_string "imul")))])
1680
1681 (define_insn "mulsi3_no_mq"
1682   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1683         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1684                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
1685   "! TARGET_POWER"
1686   "@
1687    {muls|mullw} %0,%1,%2
1688    {muli|mulli} %0,%1,%2"
1689    [(set (attr "type") 
1690       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
1691                 (const_string "imul3")
1692              (match_operand:SI 2 "short_cint_operand" "") 
1693                 (const_string "imul2")]
1694         (const_string "imul")))])
1695
1696 (define_insn "*mulsi3_mq_internal1"
1697   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1698         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1699                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1700                     (const_int 0)))
1701    (clobber (match_scratch:SI 3 "=r,r"))
1702    (clobber (match_scratch:SI 4 "=q,q"))]
1703   "TARGET_POWER"
1704   "@
1705    {muls.|mullw.} %3,%1,%2
1706    #"
1707   [(set_attr "type" "imul_compare")
1708    (set_attr "length" "4,8")])
1709
1710 (define_split
1711   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1712         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1713                              (match_operand:SI 2 "gpc_reg_operand" ""))
1714                     (const_int 0)))
1715    (clobber (match_scratch:SI 3 ""))
1716    (clobber (match_scratch:SI 4 ""))]
1717   "TARGET_POWER && reload_completed"
1718   [(parallel [(set (match_dup 3)
1719         (mult:SI (match_dup 1) (match_dup 2)))
1720    (clobber (match_dup 4))])
1721    (set (match_dup 0)
1722         (compare:CC (match_dup 3)
1723                     (const_int 0)))]
1724   "")
1725
1726 (define_insn "*mulsi3_no_mq_internal1"
1727   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1728         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1729                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1730                     (const_int 0)))
1731    (clobber (match_scratch:SI 3 "=r,r"))]
1732   "! TARGET_POWER"
1733   "@
1734    {muls.|mullw.} %3,%1,%2
1735    #"
1736   [(set_attr "type" "imul_compare")
1737    (set_attr "length" "4,8")])
1738
1739 (define_split
1740   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1741         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1742                              (match_operand:SI 2 "gpc_reg_operand" ""))
1743                     (const_int 0)))
1744    (clobber (match_scratch:SI 3 ""))]
1745   "! TARGET_POWER && reload_completed"
1746   [(set (match_dup 3)
1747         (mult:SI (match_dup 1) (match_dup 2)))
1748    (set (match_dup 0)
1749         (compare:CC (match_dup 3)
1750                     (const_int 0)))]
1751   "")
1752
1753 (define_insn "*mulsi3_mq_internal2"
1754   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1755         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1756                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1757                     (const_int 0)))
1758    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1759         (mult:SI (match_dup 1) (match_dup 2)))
1760    (clobber (match_scratch:SI 4 "=q,q"))]
1761   "TARGET_POWER"
1762   "@
1763    {muls.|mullw.} %0,%1,%2
1764    #"
1765   [(set_attr "type" "imul_compare")
1766    (set_attr "length" "4,8")])
1767
1768 (define_split
1769   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1770         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1771                              (match_operand:SI 2 "gpc_reg_operand" ""))
1772                     (const_int 0)))
1773    (set (match_operand:SI 0 "gpc_reg_operand" "")
1774         (mult:SI (match_dup 1) (match_dup 2)))
1775    (clobber (match_scratch:SI 4 ""))]
1776   "TARGET_POWER && reload_completed"
1777   [(parallel [(set (match_dup 0)
1778         (mult:SI (match_dup 1) (match_dup 2)))
1779    (clobber (match_dup 4))])
1780    (set (match_dup 3)
1781         (compare:CC (match_dup 0)
1782                     (const_int 0)))]
1783   "")
1784
1785 (define_insn "*mulsi3_no_mq_internal2"
1786   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1787         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1788                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1789                     (const_int 0)))
1790    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1791         (mult:SI (match_dup 1) (match_dup 2)))]
1792   "! TARGET_POWER"
1793   "@
1794    {muls.|mullw.} %0,%1,%2
1795    #"
1796   [(set_attr "type" "imul_compare")
1797    (set_attr "length" "4,8")])
1798
1799 (define_split
1800   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1801         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1802                              (match_operand:SI 2 "gpc_reg_operand" ""))
1803                     (const_int 0)))
1804    (set (match_operand:SI 0 "gpc_reg_operand" "")
1805         (mult:SI (match_dup 1) (match_dup 2)))]
1806   "! TARGET_POWER && reload_completed"
1807   [(set (match_dup 0)
1808         (mult:SI (match_dup 1) (match_dup 2)))
1809    (set (match_dup 3)
1810         (compare:CC (match_dup 0)
1811                     (const_int 0)))]
1812   "")
1813
1814 ;; Operand 1 is divided by operand 2; quotient goes to operand
1815 ;; 0 and remainder to operand 3.
1816 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
1817
1818 (define_expand "divmodsi4"
1819   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
1820                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1821                            (match_operand:SI 2 "gpc_reg_operand" "")))
1822               (set (match_operand:SI 3 "register_operand" "")
1823                    (mod:SI (match_dup 1) (match_dup 2)))])]
1824   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
1825   "
1826 {
1827   if (! TARGET_POWER && ! TARGET_POWERPC)
1828     {
1829       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
1830       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
1831       emit_insn (gen_divss_call ());
1832       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
1833       emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
1834       DONE;
1835     }
1836 }")
1837
1838 (define_insn "*divmodsi4_internal"
1839   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1840         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1841                 (match_operand:SI 2 "gpc_reg_operand" "r")))
1842    (set (match_operand:SI 3 "register_operand" "=q")
1843         (mod:SI (match_dup 1) (match_dup 2)))]
1844   "TARGET_POWER"
1845   "divs %0,%1,%2"
1846   [(set_attr "type" "idiv")])
1847
1848 (define_expand "udivsi3"
1849   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1850         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
1851                  (match_operand:SI 2 "gpc_reg_operand" "")))]
1852   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
1853   "
1854 {
1855   if (! TARGET_POWER && ! TARGET_POWERPC)
1856     {
1857       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
1858       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
1859       emit_insn (gen_quous_call ());
1860       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
1861       DONE;
1862     }
1863   else if (TARGET_POWER)
1864     {
1865       emit_insn (gen_udivsi3_mq (operands[0], operands[1], operands[2]));
1866       DONE;
1867     }
1868 }")
1869
1870 (define_insn "udivsi3_mq"
1871   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1872         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1873                  (match_operand:SI 2 "gpc_reg_operand" "r")))
1874    (clobber (match_scratch:SI 3 "=q"))]
1875   "TARGET_POWERPC && TARGET_POWER"
1876   "divwu %0,%1,%2"
1877   [(set_attr "type" "idiv")])
1878
1879 (define_insn "*udivsi3_no_mq"
1880   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1881         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1882                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
1883   "TARGET_POWERPC && ! TARGET_POWER"
1884   "divwu %0,%1,%2"
1885   [(set_attr "type" "idiv")])
1886
1887 ;; For powers of two we can do srai/aze for divide and then adjust for
1888 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
1889 ;; used; for PowerPC, force operands into register and do a normal divide;
1890 ;; for AIX common-mode, use quoss call on register operands.
1891 (define_expand "divsi3"
1892   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1893         (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1894                 (match_operand:SI 2 "reg_or_cint_operand" "")))]
1895   ""
1896   "
1897 {
1898   if (GET_CODE (operands[2]) == CONST_INT
1899       && INTVAL (operands[2]) > 0
1900       && exact_log2 (INTVAL (operands[2])) >= 0)
1901     ;
1902   else if (TARGET_POWERPC)
1903     {
1904       operands[2] = force_reg (SImode, operands[2]);
1905       if (TARGET_POWER)
1906         {
1907           emit_insn (gen_divsi3_mq (operands[0], operands[1], operands[2]));
1908           DONE;
1909         }
1910     }
1911   else if (TARGET_POWER)
1912     FAIL;
1913   else
1914     {
1915       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
1916       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
1917       emit_insn (gen_quoss_call ());
1918       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
1919       DONE;
1920     }
1921 }")
1922
1923 (define_insn "divsi3_mq"
1924   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1925         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1926                 (match_operand:SI 2 "gpc_reg_operand" "r")))
1927    (clobber (match_scratch:SI 3 "=q"))]
1928   "TARGET_POWERPC && TARGET_POWER"
1929   "divw %0,%1,%2"
1930   [(set_attr "type" "idiv")])
1931
1932 (define_insn "*divsi3_no_mq"
1933   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1934         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1935                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
1936   "TARGET_POWERPC && ! TARGET_POWER"
1937   "divw %0,%1,%2"
1938   [(set_attr "type" "idiv")])
1939
1940 (define_expand "modsi3"
1941   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1942    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1943    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
1944   ""
1945   "
1946 {
1947   int i;
1948   rtx temp1;
1949   rtx temp2;
1950
1951   if (GET_CODE (operands[2]) != CONST_INT
1952       || INTVAL (operands[2]) <= 0
1953       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
1954     FAIL;
1955
1956   temp1 = gen_reg_rtx (SImode);
1957   temp2 = gen_reg_rtx (SImode);
1958
1959   emit_insn (gen_divsi3 (temp1, operands[1], operands[2]));
1960   emit_insn (gen_ashlsi3 (temp2, temp1, GEN_INT (i)));
1961   emit_insn (gen_subsi3 (operands[0], operands[1], temp2));
1962   DONE;
1963 }")
1964
1965 (define_insn ""
1966   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1967         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1968                 (match_operand:SI 2 "exact_log2_cint_operand" "N")))]
1969   ""
1970   "{srai|srawi} %0,%1,%p2\;{aze|addze} %0,%0"
1971   [(set_attr "length" "8")])
1972
1973 (define_insn ""
1974   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1975         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1976                             (match_operand:SI 2 "exact_log2_cint_operand" "N,N"))
1977                     (const_int 0)))
1978    (clobber (match_scratch:SI 3 "=r,r"))]
1979   ""
1980   "@
1981    {srai|srawi} %3,%1,%p2\;{aze.|addze.} %3,%3
1982    #"
1983   [(set_attr "type" "compare")
1984    (set_attr "length" "8,12")])
1985
1986 (define_split
1987   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1988         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1989                             (match_operand:SI 2 "exact_log2_cint_operand" ""))
1990                     (const_int 0)))
1991    (clobber (match_scratch:SI 3 ""))]
1992   "reload_completed"
1993   [(set (match_dup 3)
1994         (div:SI (match_dup 1) (match_dup 2)))
1995    (set (match_dup 0)
1996         (compare:CC (match_dup 3)
1997                     (const_int 0)))]
1998   "")
1999
2000 (define_insn ""
2001   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2002         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2003                             (match_operand:SI 2 "exact_log2_cint_operand" "N,N"))
2004                     (const_int 0)))
2005    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2006         (div:SI (match_dup 1) (match_dup 2)))]
2007   ""
2008   "@
2009    {srai|srawi} %0,%1,%p2\;{aze.|addze.} %0,%0
2010    #"
2011   [(set_attr "type" "compare")
2012    (set_attr "length" "8,12")])
2013
2014 (define_split
2015   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2016         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2017                             (match_operand:SI 2 "exact_log2_cint_operand" ""))
2018                     (const_int 0)))
2019    (set (match_operand:SI 0 "gpc_reg_operand" "")
2020         (div:SI (match_dup 1) (match_dup 2)))]
2021   "reload_completed"
2022   [(set (match_dup 0)
2023         (div:SI (match_dup 1) (match_dup 2)))
2024    (set (match_dup 3)
2025         (compare:CC (match_dup 0)
2026                     (const_int 0)))]
2027   "")
2028
2029 (define_insn ""
2030   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2031         (udiv:SI
2032          (plus:DI (ashift:DI
2033                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
2034                    (const_int 32))
2035                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
2036          (match_operand:SI 3 "gpc_reg_operand" "r")))
2037    (set (match_operand:SI 2 "register_operand" "=*q")
2038         (umod:SI
2039          (plus:DI (ashift:DI
2040                    (zero_extend:DI (match_dup 1)) (const_int 32))
2041                   (zero_extend:DI (match_dup 4)))
2042          (match_dup 3)))]
2043   "TARGET_POWER"
2044   "div %0,%1,%3"
2045   [(set_attr "type" "idiv")])
2046
2047 ;; To do unsigned divide we handle the cases of the divisor looking like a
2048 ;; negative number.  If it is a constant that is less than 2**31, we don't
2049 ;; have to worry about the branches.  So make a few subroutines here.
2050 ;;
2051 ;; First comes the normal case.
2052 (define_expand "udivmodsi4_normal"
2053   [(set (match_dup 4) (const_int 0))
2054    (parallel [(set (match_operand:SI 0 "" "")
2055                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2056                                                 (const_int 32))
2057                                      (zero_extend:DI (match_operand:SI 1 "" "")))
2058                             (match_operand:SI 2 "" "")))
2059               (set (match_operand:SI 3 "" "")
2060                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2061                                                 (const_int 32))
2062                                      (zero_extend:DI (match_dup 1)))
2063                             (match_dup 2)))])]
2064   "TARGET_POWER"
2065   "
2066 { operands[4] = gen_reg_rtx (SImode); }")
2067
2068 ;; This handles the branches.
2069 (define_expand "udivmodsi4_tests"
2070   [(set (match_operand:SI 0 "" "") (const_int 0))
2071    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
2072    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
2073    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
2074                            (label_ref (match_operand:SI 4 "" "")) (pc)))
2075    (set (match_dup 0) (const_int 1))
2076    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
2077    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
2078    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
2079                            (label_ref (match_dup 4)) (pc)))]
2080   "TARGET_POWER"
2081   "
2082 { operands[5] = gen_reg_rtx (CCUNSmode);
2083   operands[6] = gen_reg_rtx (CCmode);
2084 }")
2085
2086 (define_expand "udivmodsi4"
2087   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2088                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
2089                             (match_operand:SI 2 "reg_or_cint_operand" "")))
2090               (set (match_operand:SI 3 "gpc_reg_operand" "")
2091                    (umod:SI (match_dup 1) (match_dup 2)))])]
2092   ""
2093   "
2094 {
2095   rtx label = 0;
2096
2097   if (! TARGET_POWER)
2098     {
2099       if (! TARGET_POWERPC)
2100         {
2101           emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2102           emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2103           emit_insn (gen_divus_call ());
2104           emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2105           emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2106           DONE;
2107         }
2108       else
2109         FAIL;
2110     }
2111
2112   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
2113     {
2114       operands[2] = force_reg (SImode, operands[2]);
2115       label = gen_label_rtx ();
2116       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
2117                                   operands[3], label));
2118     }
2119   else
2120     operands[2] = force_reg (SImode, operands[2]);
2121
2122   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
2123                                operands[3]));
2124   if (label)
2125     emit_label (label);
2126
2127   DONE;
2128 }")
2129
2130 ;; AIX architecture-independent common-mode multiply (DImode),
2131 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
2132 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
2133 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
2134 ;; assumed unused if generating common-mode, so ignore.
2135 (define_insn "mulh_call"
2136   [(set (reg:SI 3)
2137         (truncate:SI
2138          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
2139                                (sign_extend:DI (reg:SI 4)))
2140                       (const_int 32))))
2141    (clobber (match_scratch:SI 0 "=l"))]
2142   "! TARGET_POWER && ! TARGET_POWERPC"
2143   "bla __mulh"
2144   [(set_attr "type" "imul")])
2145
2146 (define_insn "mull_call"
2147   [(set (reg:DI 3)
2148         (mult:DI (sign_extend:DI (reg:SI 3))
2149                  (sign_extend:DI (reg:SI 4))))
2150    (clobber (match_scratch:SI 0 "=l"))
2151    (clobber (reg:SI 0))]
2152   "! TARGET_POWER && ! TARGET_POWERPC"
2153   "bla __mull"
2154   [(set_attr "type" "imul")])
2155
2156 (define_insn "divss_call"
2157   [(set (reg:SI 3)
2158         (div:SI (reg:SI 3) (reg:SI 4)))
2159    (set (reg:SI 4)
2160         (mod:SI (reg:SI 3) (reg:SI 4)))
2161    (clobber (match_scratch:SI 0 "=l"))
2162    (clobber (reg:SI 0))]
2163   "! TARGET_POWER && ! TARGET_POWERPC"
2164   "bla __divss"
2165   [(set_attr "type" "idiv")])
2166
2167 (define_insn "divus_call"
2168   [(set (reg:SI 3)
2169         (udiv:SI (reg:SI 3) (reg:SI 4)))
2170    (set (reg:SI 4)
2171         (umod:SI (reg:SI 3) (reg:SI 4)))
2172    (clobber (match_scratch:SI 0 "=l"))
2173    (clobber (reg:SI 0))
2174    (clobber (match_scratch:CC 1 "=x"))
2175    (clobber (reg:CC 69))]
2176   "! TARGET_POWER && ! TARGET_POWERPC"
2177   "bla __divus"
2178   [(set_attr "type" "idiv")])
2179
2180 (define_insn "quoss_call"
2181   [(set (reg:SI 3)
2182         (div:SI (reg:SI 3) (reg:SI 4)))
2183    (clobber (match_scratch:SI 0 "=l"))]
2184   "! TARGET_POWER && ! TARGET_POWERPC"
2185   "bla __quoss"
2186   [(set_attr "type" "idiv")])
2187
2188 (define_insn "quous_call"
2189   [(set (reg:SI 3)
2190         (udiv:SI (reg:SI 3) (reg:SI 4)))
2191    (clobber (match_scratch:SI 0 "=l"))
2192    (clobber (reg:SI 0))
2193    (clobber (match_scratch:CC 1 "=x"))
2194    (clobber (reg:CC 69))]
2195   "! TARGET_POWER && ! TARGET_POWERPC"
2196   "bla __quous"
2197   [(set_attr "type" "idiv")])
2198 \f
2199 ;; Logical instructions
2200 ;; The logical instructions are mostly combined by using match_operator,
2201 ;; but the plain AND insns are somewhat different because there is no
2202 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2203 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2204
2205 (define_insn "andsi3"
2206   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2207         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2208                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2209    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2210   ""
2211   "@
2212    and %0,%1,%2
2213    {rlinm|rlwinm} %0,%1,0,%m2,%M2
2214    {andil.|andi.} %0,%1,%b2
2215    {andiu.|andis.} %0,%1,%u2")
2216
2217 ;; Note to set cr's other than cr0 we do the and immediate and then
2218 ;; the test again -- this avoids a mfcr which on the higher end
2219 ;; machines causes an execution serialization
2220
2221 (define_insn "*andsi3_internal2"
2222   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2223         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2224                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2225                     (const_int 0)))
2226    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2227    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2228   "! TARGET_POWERPC64"
2229   "@
2230    and. %3,%1,%2
2231    {andil.|andi.} %3,%1,%b2
2232    {andiu.|andis.} %3,%1,%u2
2233    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2234    #
2235    #
2236    #
2237    #"
2238   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2239    (set_attr "length" "4,4,4,4,8,8,8,8")])
2240
2241 (define_insn "*andsi3_internal3"
2242   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2243         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2244                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2245                     (const_int 0)))
2246    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2247    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2248   "TARGET_POWERPC64"
2249   "@
2250    #
2251    {andil.|andi.} %3,%1,%b2
2252    {andiu.|andis.} %3,%1,%u2
2253    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2254    #
2255    #
2256    #
2257    #"
2258   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2259    (set_attr "length" "8,4,4,4,8,8,8,8")])
2260
2261 (define_split
2262   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2263         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2264                             (match_operand:SI 2 "and_operand" ""))
2265                     (const_int 0)))
2266    (clobber (match_scratch:SI 3 ""))
2267    (clobber (match_scratch:CC 4 ""))]
2268   "reload_completed"
2269   [(parallel [(set (match_dup 3)
2270                    (and:SI (match_dup 1)
2271                            (match_dup 2)))
2272               (clobber (match_dup 4))])
2273    (set (match_dup 0)
2274         (compare:CC (match_dup 3)
2275                     (const_int 0)))]
2276   "")
2277
2278 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
2279 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
2280
2281 (define_split
2282   [(set (match_operand:CC 0 "cc_reg_operand" "")
2283         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2284                             (match_operand:SI 2 "gpc_reg_operand" ""))
2285                     (const_int 0)))
2286    (clobber (match_scratch:SI 3 ""))
2287    (clobber (match_scratch:CC 4 ""))]
2288   "TARGET_POWERPC64 && reload_completed"
2289   [(parallel [(set (match_dup 3)
2290                    (and:SI (match_dup 1)
2291                            (match_dup 2)))
2292               (clobber (match_dup 4))])
2293    (set (match_dup 0)
2294         (compare:CC (match_dup 3)
2295                     (const_int 0)))]
2296   "")
2297
2298 (define_insn "*andsi3_internal4"
2299   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2300         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2301                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2302                     (const_int 0)))
2303    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2304         (and:SI (match_dup 1)
2305                 (match_dup 2)))
2306    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2307   "! TARGET_POWERPC64"
2308   "@
2309    and. %0,%1,%2
2310    {andil.|andi.} %0,%1,%b2
2311    {andiu.|andis.} %0,%1,%u2
2312    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2313    #
2314    #
2315    #
2316    #"
2317   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2318    (set_attr "length" "4,4,4,4,8,8,8,8")])
2319
2320 (define_insn "*andsi3_internal5"
2321   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2322         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2323                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2324                     (const_int 0)))
2325    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2326         (and:SI (match_dup 1)
2327                 (match_dup 2)))
2328    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2329   "TARGET_POWERPC64"
2330   "@
2331    #
2332    {andil.|andi.} %0,%1,%b2
2333    {andiu.|andis.} %0,%1,%u2
2334    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2335    #
2336    #
2337    #
2338    #"
2339   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2340    (set_attr "length" "8,4,4,4,8,8,8,8")])
2341
2342 (define_split
2343   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2344         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2345                             (match_operand:SI 2 "and_operand" ""))
2346                     (const_int 0)))
2347    (set (match_operand:SI 0 "gpc_reg_operand" "")
2348         (and:SI (match_dup 1)
2349                 (match_dup 2)))
2350    (clobber (match_scratch:CC 4 ""))]
2351   "reload_completed"
2352   [(parallel [(set (match_dup 0)
2353                    (and:SI (match_dup 1)
2354                            (match_dup 2)))
2355               (clobber (match_dup 4))])
2356    (set (match_dup 3)
2357         (compare:CC (match_dup 0)
2358                     (const_int 0)))]
2359   "")
2360
2361 (define_split
2362   [(set (match_operand:CC 3 "cc_reg_operand" "")
2363         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2364                             (match_operand:SI 2 "gpc_reg_operand" ""))
2365                     (const_int 0)))
2366    (set (match_operand:SI 0 "gpc_reg_operand" "")
2367         (and:SI (match_dup 1)
2368                 (match_dup 2)))
2369    (clobber (match_scratch:CC 4 ""))]
2370   "TARGET_POWERPC64 && reload_completed"
2371   [(parallel [(set (match_dup 0)
2372                    (and:SI (match_dup 1)
2373                            (match_dup 2)))
2374               (clobber (match_dup 4))])
2375    (set (match_dup 3)
2376         (compare:CC (match_dup 0)
2377                     (const_int 0)))]
2378   "")
2379
2380 ;; Handle the PowerPC64 rlwinm corner case
2381
2382 (define_insn_and_split "*andsi3_internal6"
2383   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2384         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2385                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
2386   "TARGET_POWERPC64"
2387   "#"
2388   "TARGET_POWERPC64"
2389   [(set (match_dup 0)
2390         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
2391                 (match_dup 4)))
2392    (set (match_dup 0)
2393         (rotate:SI (match_dup 0) (match_dup 5)))]
2394   "
2395 {
2396   int mb = extract_MB (operands[2]);
2397   int me = extract_ME (operands[2]);
2398   operands[3] = GEN_INT (me + 1);
2399   operands[5] = GEN_INT (32 - (me + 1));
2400   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2401 }"
2402   [(set_attr "length" "8")])
2403
2404 (define_insn_and_split "*andsi3_internal7"
2405   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2406         (compare:CC (and:SI (match_operand:SI 0 "gpc_reg_operand" "r,r")
2407                             (match_operand:SI 1 "mask_operand_wrap" "i,i"))
2408                     (const_int 0)))
2409    (clobber (match_scratch:SI 3 "=r,r"))]
2410   "TARGET_POWERPC64"
2411   "#"
2412   "TARGET_POWERPC64"
2413   [(parallel [(set (match_dup 2)
2414                    (compare:CC (and:SI (rotate:SI (match_dup 0) (match_dup 4))
2415                                        (match_dup 5))
2416                                (const_int 0)))
2417               (clobber (match_dup 3))])]
2418   "
2419 {
2420   int mb = extract_MB (operands[1]);
2421   int me = extract_ME (operands[1]);
2422   operands[4] = GEN_INT (me + 1);
2423   operands[5] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2424 }"
2425   [(set_attr "type" "delayed_compare,compare")
2426    (set_attr "length" "4,8")])
2427
2428 (define_insn_and_split "*andsi3_internal8"
2429   [(set (match_operand:CC 3 "cc_reg_operand" "=x,??y")
2430         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2431                             (match_operand:SI 2 "mask_operand_wrap" "i,i"))
2432                     (const_int 0)))
2433    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2434         (and:SI (match_dup 1)
2435                 (match_dup 2)))]
2436   "TARGET_POWERPC64"
2437   "#"
2438   "TARGET_POWERPC64"
2439   [(parallel [(set (match_dup 3)
2440                    (compare:CC (and:SI (rotate:SI (match_dup 1) (match_dup 4))
2441                                        (match_dup 5))
2442                                (const_int 0)))
2443               (set (match_dup 0)
2444                    (and:SI (rotate:SI (match_dup 1) (match_dup 4))
2445                            (match_dup 5)))])
2446    (set (match_dup 0)
2447         (rotate:SI (match_dup 0) (match_dup 6)))]
2448   "
2449 {
2450   int mb = extract_MB (operands[2]);
2451   int me = extract_ME (operands[2]);
2452   operands[4] = GEN_INT (me + 1);
2453   operands[6] = GEN_INT (32 - (me + 1));
2454   operands[5] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2455 }"
2456   [(set_attr "type" "delayed_compare,compare")
2457    (set_attr "length" "8,12")])
2458
2459 (define_expand "iorsi3"
2460   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2461         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
2462                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2463   ""
2464   "
2465 {
2466   if (GET_CODE (operands[2]) == CONST_INT
2467       && ! logical_operand (operands[2], SImode))
2468     {
2469       HOST_WIDE_INT value = INTVAL (operands[2]);
2470       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2471                  ? operands[0] : gen_reg_rtx (SImode));
2472
2473       emit_insn (gen_iorsi3 (tmp, operands[1],
2474                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2475       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2476       DONE;
2477     }
2478 }")
2479
2480 (define_expand "xorsi3"
2481   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2482         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
2483                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2484   ""
2485   "
2486 {
2487   if (GET_CODE (operands[2]) == CONST_INT
2488       && ! logical_operand (operands[2], SImode))
2489     {
2490       HOST_WIDE_INT value = INTVAL (operands[2]);
2491       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2492                  ? operands[0] : gen_reg_rtx (SImode));
2493
2494       emit_insn (gen_xorsi3 (tmp, operands[1],
2495                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2496       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2497       DONE;
2498     }
2499 }")
2500
2501 (define_insn "*boolsi3_internal1"
2502   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
2503         (match_operator:SI 3 "boolean_or_operator"
2504          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
2505           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
2506   ""
2507   "@
2508    %q3 %0,%1,%2
2509    {%q3il|%q3i} %0,%1,%b2
2510    {%q3iu|%q3is} %0,%1,%u2")
2511
2512 (define_insn "*boolsi3_internal2"
2513   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2514         (compare:CC (match_operator:SI 4 "boolean_or_operator"
2515          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2516           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2517          (const_int 0)))
2518    (clobber (match_scratch:SI 3 "=r,r"))]
2519   "! TARGET_POWERPC64"
2520   "@
2521    %q4. %3,%1,%2
2522    #"
2523   [(set_attr "type" "compare")
2524    (set_attr "length" "4,8")])
2525
2526 (define_split
2527   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2528         (compare:CC (match_operator:SI 4 "boolean_operator"
2529          [(match_operand:SI 1 "gpc_reg_operand" "")
2530           (match_operand:SI 2 "gpc_reg_operand" "")])
2531          (const_int 0)))
2532    (clobber (match_scratch:SI 3 ""))]
2533   "! TARGET_POWERPC64 && reload_completed"
2534   [(set (match_dup 3) (match_dup 4))
2535    (set (match_dup 0)
2536         (compare:CC (match_dup 3)
2537                     (const_int 0)))]
2538   "")
2539
2540 (define_insn "*boolsi3_internal3"
2541   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2542         (compare:CC (match_operator:SI 4 "boolean_operator"
2543          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2544           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2545          (const_int 0)))
2546    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2547         (match_dup 4))]
2548   "! TARGET_POWERPC64"
2549   "@
2550    %q4. %0,%1,%2
2551    #"
2552   [(set_attr "type" "compare")
2553    (set_attr "length" "4,8")])
2554
2555 (define_split
2556   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2557         (compare:CC (match_operator:SI 4 "boolean_operator"
2558          [(match_operand:SI 1 "gpc_reg_operand" "")
2559           (match_operand:SI 2 "gpc_reg_operand" "")])
2560          (const_int 0)))
2561    (set (match_operand:SI 0 "gpc_reg_operand" "")
2562         (match_dup 4))]
2563   "! TARGET_POWERPC64 && reload_completed"
2564   [(set (match_dup 0) (match_dup 4))
2565    (set (match_dup 3)
2566         (compare:CC (match_dup 0)
2567                     (const_int 0)))]
2568   "")
2569
2570 ;; Split a logical operation that we can't do in one insn into two insns, 
2571 ;; each of which does one 16-bit part.  This is used by combine.
2572
2573 (define_split
2574   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2575         (match_operator:SI 3 "boolean_or_operator"
2576          [(match_operand:SI 1 "gpc_reg_operand" "")
2577           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
2578   ""
2579   [(set (match_dup 0) (match_dup 4))
2580    (set (match_dup 0) (match_dup 5))]
2581 "
2582 {
2583   rtx i;
2584   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
2585   operands[4] = gen_rtx (GET_CODE (operands[3]), SImode,
2586                          operands[1], i);
2587   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
2588   operands[5] = gen_rtx (GET_CODE (operands[3]), SImode,
2589                          operands[0], i);
2590 }")
2591
2592 (define_insn "*boolcsi3_internal1"
2593   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2594         (match_operator:SI 3 "boolean_operator"
2595          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
2596           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
2597   ""
2598   "%q3 %0,%2,%1")
2599
2600 (define_insn "*boolcsi3_internal2"
2601   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2602         (compare:CC (match_operator:SI 4 "boolean_operator"
2603          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2604           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2605          (const_int 0)))
2606    (clobber (match_scratch:SI 3 "=r,r"))]
2607   "! TARGET_POWERPC64"
2608   "@
2609    %q4. %3,%2,%1
2610    #"
2611   [(set_attr "type" "compare")
2612    (set_attr "length" "4,8")])
2613
2614 (define_split
2615   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2616         (compare:CC (match_operator:SI 4 "boolean_operator"
2617          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2618           (match_operand:SI 2 "gpc_reg_operand" "")])
2619          (const_int 0)))
2620    (clobber (match_scratch:SI 3 ""))]
2621   "! TARGET_POWERPC64 && reload_completed"
2622   [(set (match_dup 3) (match_dup 4))
2623    (set (match_dup 0)
2624         (compare:CC (match_dup 3)
2625                     (const_int 0)))]
2626   "")
2627
2628 (define_insn "*boolcsi3_internal3"
2629   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2630         (compare:CC (match_operator:SI 4 "boolean_operator"
2631          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
2632           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2633          (const_int 0)))
2634    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2635         (match_dup 4))]
2636   "! TARGET_POWERPC64"
2637   "@
2638    %q4. %0,%2,%1
2639    #"
2640   [(set_attr "type" "compare")
2641    (set_attr "length" "4,8")])
2642
2643 (define_split
2644   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2645         (compare:CC (match_operator:SI 4 "boolean_operator"
2646          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2647           (match_operand:SI 2 "gpc_reg_operand" "")])
2648          (const_int 0)))
2649    (set (match_operand:SI 0 "gpc_reg_operand" "")
2650         (match_dup 4))]
2651   "! TARGET_POWERPC64 && reload_completed"
2652   [(set (match_dup 0) (match_dup 4))
2653    (set (match_dup 3)
2654         (compare:CC (match_dup 0)
2655                     (const_int 0)))]
2656   "")
2657
2658 (define_insn "*boolccsi3_internal1"
2659   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2660         (match_operator:SI 3 "boolean_operator"
2661          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
2662           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
2663   ""
2664   "%q3 %0,%1,%2")
2665
2666 (define_insn "*boolccsi3_internal2"
2667   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2668         (compare:CC (match_operator:SI 4 "boolean_operator"
2669          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2670           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
2671          (const_int 0)))
2672    (clobber (match_scratch:SI 3 "=r,r"))]
2673   "! TARGET_POWERPC64"
2674   "@
2675    %q4. %3,%1,%2
2676    #"
2677   [(set_attr "type" "compare")
2678    (set_attr "length" "4,8")])
2679
2680 (define_split
2681   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2682         (compare:CC (match_operator:SI 4 "boolean_operator"
2683          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2684           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
2685          (const_int 0)))
2686    (clobber (match_scratch:SI 3 ""))]
2687   "! TARGET_POWERPC64 && reload_completed"
2688   [(set (match_dup 3) (match_dup 4))
2689    (set (match_dup 0)
2690         (compare:CC (match_dup 3)
2691                     (const_int 0)))]
2692   "")
2693
2694 (define_insn "*boolccsi3_internal3"
2695   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2696         (compare:CC (match_operator:SI 4 "boolean_operator"
2697          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
2698           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
2699          (const_int 0)))
2700    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2701         (match_dup 4))]
2702   "! TARGET_POWERPC64"
2703   "@
2704    %q4. %0,%1,%2
2705    #"
2706   [(set_attr "type" "compare")
2707    (set_attr "length" "4,8")])
2708
2709 (define_split
2710   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2711         (compare:CC (match_operator:SI 4 "boolean_operator"
2712          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2713           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
2714          (const_int 0)))
2715    (set (match_operand:SI 0 "gpc_reg_operand" "")
2716         (match_dup 4))]
2717   "! TARGET_POWERPC64 && reload_completed"
2718   [(set (match_dup 0) (match_dup 4))
2719    (set (match_dup 3)
2720         (compare:CC (match_dup 0)
2721                     (const_int 0)))]
2722   "")
2723
2724 ;; maskir insn.  We need four forms because things might be in arbitrary
2725 ;; orders.  Don't define forms that only set CR fields because these
2726 ;; would modify an input register.
2727
2728 (define_insn "*maskir_internal1"
2729   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2730         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
2731                         (match_operand:SI 1 "gpc_reg_operand" "0"))
2732                 (and:SI (match_dup 2)
2733                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
2734   "TARGET_POWER"
2735   "maskir %0,%3,%2")
2736
2737 (define_insn "*maskir_internal2"
2738   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2739         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
2740                         (match_operand:SI 1 "gpc_reg_operand" "0"))
2741                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2742                         (match_dup 2))))]
2743   "TARGET_POWER"
2744   "maskir %0,%3,%2")
2745
2746 (define_insn "*maskir_internal3"
2747   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2748         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2749                         (match_operand:SI 3 "gpc_reg_operand" "r"))
2750                 (and:SI (not:SI (match_dup 2))
2751                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
2752   "TARGET_POWER"
2753   "maskir %0,%3,%2")
2754
2755 (define_insn "*maskir_internal4"
2756   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2757         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2758                         (match_operand:SI 2 "gpc_reg_operand" "r"))
2759                 (and:SI (not:SI (match_dup 2))
2760                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
2761   "TARGET_POWER"
2762   "maskir %0,%3,%2")
2763
2764 (define_insn "*maskir_internal5"
2765   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2766         (compare:CC
2767          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2768                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
2769                  (and:SI (match_dup 2)
2770                          (match_operand:SI 3 "gpc_reg_operand" "r,r")))
2771          (const_int 0)))
2772    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2773         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2774                 (and:SI (match_dup 2) (match_dup 3))))]
2775   "TARGET_POWER"
2776   "@
2777    maskir. %0,%3,%2
2778    #"
2779   [(set_attr "type" "compare")
2780    (set_attr "length" "4,8")])
2781
2782 (define_split
2783   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2784         (compare:CC
2785          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
2786                          (match_operand:SI 1 "gpc_reg_operand" ""))
2787                  (and:SI (match_dup 2)
2788                          (match_operand:SI 3 "gpc_reg_operand" "")))
2789          (const_int 0)))
2790    (set (match_operand:SI 0 "gpc_reg_operand" "")
2791         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2792                 (and:SI (match_dup 2) (match_dup 3))))]
2793   "TARGET_POWER && reload_completed"
2794   [(set (match_dup 0)
2795         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2796                 (and:SI (match_dup 2) (match_dup 3))))
2797    (set (match_dup 4)
2798         (compare:CC (match_dup 0)
2799                     (const_int 0)))]
2800   "")
2801
2802 (define_insn "*maskir_internal6"
2803   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2804         (compare:CC
2805          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2806                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
2807                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
2808                          (match_dup 2)))
2809          (const_int 0)))
2810    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2811         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2812                 (and:SI (match_dup 3) (match_dup 2))))]
2813   "TARGET_POWER"
2814   "@
2815    maskir. %0,%3,%2
2816    #"
2817   [(set_attr "type" "compare")
2818    (set_attr "length" "4,8")])
2819
2820 (define_split
2821   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2822         (compare:CC
2823          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
2824                          (match_operand:SI 1 "gpc_reg_operand" ""))
2825                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
2826                          (match_dup 2)))
2827          (const_int 0)))
2828    (set (match_operand:SI 0 "gpc_reg_operand" "")
2829         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2830                 (and:SI (match_dup 3) (match_dup 2))))]
2831   "TARGET_POWER && reload_completed"
2832   [(set (match_dup 0)
2833         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2834                 (and:SI (match_dup 3) (match_dup 2))))
2835    (set (match_dup 4)
2836         (compare:CC (match_dup 0)
2837                     (const_int 0)))]
2838   "")
2839
2840 (define_insn "*maskir_internal7"
2841   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2842         (compare:CC
2843          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r,r")
2844                          (match_operand:SI 3 "gpc_reg_operand" "r,r"))
2845                  (and:SI (not:SI (match_dup 2))
2846                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
2847          (const_int 0)))
2848    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2849         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2850                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2851   "TARGET_POWER"
2852   "@
2853    maskir. %0,%3,%2
2854    #"
2855   [(set_attr "type" "compare")
2856    (set_attr "length" "4,8")])
2857
2858 (define_split
2859   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2860         (compare:CC
2861          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "")
2862                          (match_operand:SI 3 "gpc_reg_operand" ""))
2863                  (and:SI (not:SI (match_dup 2))
2864                          (match_operand:SI 1 "gpc_reg_operand" "")))
2865          (const_int 0)))
2866    (set (match_operand:SI 0 "gpc_reg_operand" "")
2867         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2868                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2869   "TARGET_POWER && reload_completed"
2870   [(set (match_dup 0)
2871         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2872                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
2873    (set (match_dup 4)
2874         (compare:CC (match_dup 0)
2875                     (const_int 0)))]
2876   "")
2877
2878 (define_insn "*maskir_internal8"
2879   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2880         (compare:CC
2881          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
2882                          (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2883                  (and:SI (not:SI (match_dup 2))
2884                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
2885          (const_int 0)))
2886    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2887         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2888                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2889   "TARGET_POWER"
2890   "@
2891    maskir. %0,%3,%2
2892    #"
2893   [(set_attr "type" "compare")
2894    (set_attr "length" "4,8")])
2895
2896 (define_split
2897   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2898         (compare:CC
2899          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
2900                          (match_operand:SI 2 "gpc_reg_operand" ""))
2901                  (and:SI (not:SI (match_dup 2))
2902                          (match_operand:SI 1 "gpc_reg_operand" "")))
2903          (const_int 0)))
2904    (set (match_operand:SI 0 "gpc_reg_operand" "")
2905         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2906                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2907   "TARGET_POWER && reload_completed"
2908   [(set (match_dup 0)
2909         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2910                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
2911    (set (match_dup 4)
2912         (compare:CC (match_dup 0)
2913                     (const_int 0)))]
2914   "")
2915 \f
2916 ;; Rotate and shift insns, in all their variants.  These support shifts,
2917 ;; field inserts and extracts, and various combinations thereof.
2918 (define_expand "insv"
2919   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
2920                        (match_operand:SI 1 "const_int_operand" "")
2921                        (match_operand:SI 2 "const_int_operand" ""))
2922         (match_operand 3 "gpc_reg_operand" ""))]
2923   ""
2924   "
2925 {
2926   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
2927      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
2928      compiler if the address of the structure is taken later.  */
2929   if (GET_CODE (operands[0]) == SUBREG
2930       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
2931     FAIL;
2932
2933   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
2934     emit_insn (gen_insvdi (operands[0], operands[1], operands[2], operands[3]));
2935   else
2936     emit_insn (gen_insvsi (operands[0], operands[1], operands[2], operands[3]));
2937   DONE;
2938 }")
2939
2940 (define_insn "insvsi"
2941   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2942                          (match_operand:SI 1 "const_int_operand" "i")
2943                          (match_operand:SI 2 "const_int_operand" "i"))
2944         (match_operand:SI 3 "gpc_reg_operand" "r"))]
2945   ""
2946   "*
2947 {
2948   int start = INTVAL (operands[2]) & 31;
2949   int size = INTVAL (operands[1]) & 31;
2950
2951   operands[4] = GEN_INT (32 - start - size);
2952   operands[1] = GEN_INT (start + size - 1);
2953   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2954 }"
2955   [(set_attr "type" "insert_word")])
2956
2957 (define_insn "*insvsi_internal1"
2958   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2959                          (match_operand:SI 1 "const_int_operand" "i")
2960                          (match_operand:SI 2 "const_int_operand" "i"))
2961         (ashift:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2962                    (match_operand:SI 4 "const_int_operand" "i")))]
2963   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
2964   "*
2965 {
2966   int shift = INTVAL (operands[4]) & 31;
2967   int start = INTVAL (operands[2]) & 31;
2968   int size = INTVAL (operands[1]) & 31;
2969
2970   operands[4] = GEN_INT (shift - start - size);
2971   operands[1] = GEN_INT (start + size - 1);
2972   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2973 }"
2974   [(set_attr "type" "insert_word")])
2975
2976 (define_insn "*insvsi_internal2"
2977   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2978                          (match_operand:SI 1 "const_int_operand" "i")
2979                          (match_operand:SI 2 "const_int_operand" "i"))
2980         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2981                      (match_operand:SI 4 "const_int_operand" "i")))]
2982   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
2983   "*
2984 {
2985   int shift = INTVAL (operands[4]) & 31;
2986   int start = INTVAL (operands[2]) & 31;
2987   int size = INTVAL (operands[1]) & 31;
2988
2989   operands[4] = GEN_INT (32 - shift - start - size);
2990   operands[1] = GEN_INT (start + size - 1);
2991   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2992 }"
2993   [(set_attr "type" "insert_word")])
2994
2995 (define_insn "*insvsi_internal3"
2996   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2997                          (match_operand:SI 1 "const_int_operand" "i")
2998                          (match_operand:SI 2 "const_int_operand" "i"))
2999         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3000                      (match_operand:SI 4 "const_int_operand" "i")))]
3001   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3002   "*
3003 {
3004   int shift = INTVAL (operands[4]) & 31;
3005   int start = INTVAL (operands[2]) & 31;
3006   int size = INTVAL (operands[1]) & 31;
3007
3008   operands[4] = GEN_INT (32 - shift - start - size);
3009   operands[1] = GEN_INT (start + size - 1);
3010   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3011 }"
3012   [(set_attr "type" "insert_word")])
3013
3014 (define_insn "*insvsi_internal4"
3015   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3016                          (match_operand:SI 1 "const_int_operand" "i")
3017                          (match_operand:SI 2 "const_int_operand" "i"))
3018         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3019                          (match_operand:SI 4 "const_int_operand" "i")
3020                          (match_operand:SI 5 "const_int_operand" "i")))]
3021   "INTVAL (operands[4]) >= INTVAL (operands[1])"
3022   "*
3023 {
3024   int extract_start = INTVAL (operands[5]) & 31;
3025   int extract_size = INTVAL (operands[4]) & 31;
3026   int insert_start = INTVAL (operands[2]) & 31;
3027   int insert_size = INTVAL (operands[1]) & 31;
3028
3029 /* Align extract field with insert field */
3030   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
3031   operands[1] = GEN_INT (insert_start + insert_size - 1);
3032   return \"{rlimi|rlwimi} %0,%3,%h5,%h2,%h1\";
3033 }"
3034   [(set_attr "type" "insert_word")])
3035
3036 (define_insn "insvdi"
3037   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3038                          (match_operand:SI 1 "const_int_operand" "i")
3039                          (match_operand:SI 2 "const_int_operand" "i"))
3040         (match_operand:DI 3 "gpc_reg_operand" "r"))]
3041   "TARGET_POWERPC64"
3042   "*
3043 {
3044   int start = INTVAL (operands[2]) & 63;
3045   int size = INTVAL (operands[1]) & 63;
3046
3047   operands[1] = GEN_INT (64 - start - size);
3048   return \"rldimi %0,%3,%H1,%H2\";
3049 }")
3050
3051 (define_expand "extzv"
3052   [(set (match_operand 0 "gpc_reg_operand" "")
3053         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3054                        (match_operand:SI 2 "const_int_operand" "")
3055                        (match_operand:SI 3 "const_int_operand" "")))]
3056   ""
3057   "
3058 {
3059   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3060      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3061      compiler if the address of the structure is taken later.  */
3062   if (GET_CODE (operands[0]) == SUBREG
3063       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3064     FAIL;
3065
3066   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3067     emit_insn (gen_extzvdi (operands[0], operands[1], operands[2], operands[3]));
3068   else
3069     emit_insn (gen_extzvsi (operands[0], operands[1], operands[2], operands[3]));
3070   DONE;
3071 }")
3072
3073 (define_insn "extzvsi"
3074   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3075         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3076                          (match_operand:SI 2 "const_int_operand" "i")
3077                          (match_operand:SI 3 "const_int_operand" "i")))]
3078   ""
3079   "*
3080 {
3081   int start = INTVAL (operands[3]) & 31;
3082   int size = INTVAL (operands[2]) & 31;
3083
3084   if (start + size >= 32)
3085     operands[3] = const0_rtx;
3086   else
3087     operands[3] = GEN_INT (start + size);
3088   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
3089 }")
3090
3091 (define_insn "*extzvsi_internal1"
3092   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3093         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3094                          (match_operand:SI 2 "const_int_operand" "i,i")
3095                          (match_operand:SI 3 "const_int_operand" "i,i"))
3096                     (const_int 0)))
3097    (clobber (match_scratch:SI 4 "=r,r"))]
3098   ""
3099   "*
3100 {
3101   int start = INTVAL (operands[3]) & 31;
3102   int size = INTVAL (operands[2]) & 31;
3103
3104   /* Force split for non-cc0 compare.  */
3105   if (which_alternative == 1)
3106      return \"#\";
3107
3108   /* If the bit-field being tested fits in the upper or lower half of a
3109      word, it is possible to use andiu. or andil. to test it.  This is
3110      useful because the condition register set-use delay is smaller for
3111      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3112      position is 0 because the LT and GT bits may be set wrong.  */
3113
3114   if ((start > 0 && start + size <= 16) || start >= 16)
3115     {
3116       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3117                               - (1 << (16 - (start & 15) - size))));
3118       if (start < 16)
3119         return \"{andiu.|andis.} %4,%1,%3\";
3120       else
3121         return \"{andil.|andi.} %4,%1,%3\";
3122     }
3123
3124   if (start + size >= 32)
3125     operands[3] = const0_rtx;
3126   else
3127     operands[3] = GEN_INT (start + size);
3128   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
3129 }"
3130   [(set_attr "type" "compare")
3131    (set_attr "length" "4,8")])
3132
3133 (define_split
3134   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3135         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3136                          (match_operand:SI 2 "const_int_operand" "")
3137                          (match_operand:SI 3 "const_int_operand" ""))
3138                     (const_int 0)))
3139    (clobber (match_scratch:SI 4 ""))]
3140   "reload_completed"
3141   [(set (match_dup 4)
3142         (zero_extract:SI (match_dup 1) (match_dup 2)
3143                          (match_dup 3)))
3144    (set (match_dup 0)
3145         (compare:CC (match_dup 4)
3146                     (const_int 0)))]
3147   "")
3148
3149 (define_insn "*extzvsi_internal2"
3150   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3151         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3152                          (match_operand:SI 2 "const_int_operand" "i,i")
3153                          (match_operand:SI 3 "const_int_operand" "i,i"))
3154                     (const_int 0)))
3155    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3156         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3157   ""
3158   "*
3159 {
3160   int start = INTVAL (operands[3]) & 31;
3161   int size = INTVAL (operands[2]) & 31;
3162
3163   /* Force split for non-cc0 compare.  */
3164   if (which_alternative == 1)
3165      return \"#\";
3166
3167   /* Since we are using the output value, we can't ignore any need for
3168      a shift.  The bit-field must end at the LSB.  */
3169   if (start >= 16 && start + size == 32)
3170     {
3171       operands[3] = GEN_INT ((1 << size) - 1);
3172       return \"{andil.|andi.} %0,%1,%3\";
3173     }
3174
3175   if (start + size >= 32)
3176     operands[3] = const0_rtx;
3177   else
3178     operands[3] = GEN_INT (start + size);
3179   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
3180 }"
3181   [(set_attr "type" "compare")
3182    (set_attr "length" "4,8")])
3183
3184 (define_split
3185   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3186         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3187                          (match_operand:SI 2 "const_int_operand" "")
3188                          (match_operand:SI 3 "const_int_operand" ""))
3189                     (const_int 0)))
3190    (set (match_operand:SI 0 "gpc_reg_operand" "")
3191         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3192   "reload_completed"
3193   [(set (match_dup 0)
3194         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3195    (set (match_dup 4)
3196         (compare:CC (match_dup 0)
3197                     (const_int 0)))]
3198   "")
3199
3200 (define_insn "extzvdi"
3201   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3202         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3203                          (match_operand:SI 2 "const_int_operand" "i")
3204                          (match_operand:SI 3 "const_int_operand" "i")))]
3205   "TARGET_POWERPC64"
3206   "*
3207 {
3208   int start = INTVAL (operands[3]) & 63;
3209   int size = INTVAL (operands[2]) & 63;
3210
3211   if (start + size >= 64)
3212     operands[3] = const0_rtx;
3213   else
3214     operands[3] = GEN_INT (start + size);
3215   operands[2] = GEN_INT (64 - size);
3216   return \"rldicl %0,%1,%3,%2\";
3217 }")
3218
3219 (define_insn "*extzvdi_internal1"
3220   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3221         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3222                          (match_operand:SI 2 "const_int_operand" "i")
3223                          (match_operand:SI 3 "const_int_operand" "i"))
3224                     (const_int 0)))
3225    (clobber (match_scratch:DI 4 "=r"))]
3226   "TARGET_POWERPC64"
3227   "*
3228 {
3229   int start = INTVAL (operands[3]) & 63;
3230   int size = INTVAL (operands[2]) & 63;
3231
3232   if (start + size >= 64)
3233     operands[3] = const0_rtx;
3234   else
3235     operands[3] = GEN_INT (start + size);
3236   operands[2] = GEN_INT (64 - size);
3237   return \"rldicl. %4,%1,%3,%2\";
3238 }")
3239
3240 (define_insn "*extzvdi_internal2"
3241   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3242         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3243                          (match_operand:SI 2 "const_int_operand" "i")
3244                          (match_operand:SI 3 "const_int_operand" "i"))
3245                     (const_int 0)))
3246    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3247         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3248   "TARGET_POWERPC64"
3249   "*
3250 {
3251   int start = INTVAL (operands[3]) & 63;
3252   int size = INTVAL (operands[2]) & 63;
3253
3254   if (start + size >= 64)
3255     operands[3] = const0_rtx;
3256   else
3257     operands[3] = GEN_INT (start + size);
3258   operands[2] = GEN_INT (64 - size);
3259   return \"rldicl. %0,%1,%3,%2\";
3260 }")
3261
3262 (define_insn "rotlsi3"
3263   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3264         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3265                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3266   ""
3267   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffffffff")
3268
3269 (define_insn "*rotlsi3_internal2"
3270   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3271         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3272                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3273                     (const_int 0)))
3274    (clobber (match_scratch:SI 3 "=r,r"))]
3275   ""
3276   "@
3277    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffffffff
3278    #"
3279   [(set_attr "type" "delayed_compare")
3280    (set_attr "length" "4,8")])
3281
3282 (define_split
3283   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3284         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3285                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3286                     (const_int 0)))
3287    (clobber (match_scratch:SI 3 ""))]
3288   "reload_completed"
3289   [(set (match_dup 3)
3290         (rotate:SI (match_dup 1) (match_dup 2)))
3291    (set (match_dup 0)
3292         (compare:CC (match_dup 3)
3293                     (const_int 0)))]
3294   "")
3295
3296 (define_insn "*rotlsi3_internal3"
3297   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3298         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3299                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3300                     (const_int 0)))
3301    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3302         (rotate:SI (match_dup 1) (match_dup 2)))]
3303   ""
3304   "@
3305    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffffffff
3306    #"
3307   [(set_attr "type" "delayed_compare")
3308    (set_attr "length" "4,8")])
3309
3310 (define_split
3311   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3312         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3313                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3314                     (const_int 0)))
3315    (set (match_operand:SI 0 "gpc_reg_operand" "")
3316         (rotate:SI (match_dup 1) (match_dup 2)))]
3317   "reload_completed"
3318   [(set (match_dup 0)
3319         (rotate:SI (match_dup 1) (match_dup 2)))
3320    (set (match_dup 3)
3321         (compare:CC (match_dup 0)
3322                     (const_int 0)))]
3323   "")
3324
3325 (define_insn "*rotlsi3_internal4"
3326   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3327         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3328                            (match_operand:SI 2 "reg_or_cint_operand" "ri"))
3329                 (match_operand:SI 3 "mask_operand" "n")))]
3330   ""
3331   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,%m3,%M3")
3332
3333 (define_insn "*rotlsi3_internal5"
3334   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3335         (compare:CC (and:SI
3336                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3337                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3338                      (match_operand:SI 3 "mask_operand" "n,n"))
3339                     (const_int 0)))
3340    (clobber (match_scratch:SI 4 "=r,r"))]
3341   ""
3342   "@
3343    {rl%I2nm.|rlw%I2nm.} %4,%1,%h2,%m3,%M3
3344    #"
3345   [(set_attr "type" "delayed_compare")
3346    (set_attr "length" "4,8")])
3347
3348 (define_split
3349   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3350         (compare:CC (and:SI
3351                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3352                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3353                      (match_operand:SI 3 "mask_operand" ""))
3354                     (const_int 0)))
3355    (clobber (match_scratch:SI 4 ""))]
3356   "reload_completed"
3357   [(set (match_dup 4)
3358         (and:SI (rotate:SI (match_dup 1)
3359                                 (match_dup 2))
3360                      (match_dup 3)))
3361    (set (match_dup 0)
3362         (compare:CC (match_dup 4)
3363                     (const_int 0)))]
3364   "")
3365
3366 (define_insn "*rotlsi3_internal6"
3367   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3368         (compare:CC (and:SI
3369                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3370                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3371                      (match_operand:SI 3 "mask_operand" "n,n"))
3372                     (const_int 0)))
3373    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3374         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3375   ""
3376   "@
3377    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,%m3,%M3
3378    #"
3379   [(set_attr "type" "delayed_compare")
3380    (set_attr "length" "4,8")])
3381
3382 (define_split
3383   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3384         (compare:CC (and:SI
3385                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3386                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3387                      (match_operand:SI 3 "mask_operand" ""))
3388                     (const_int 0)))
3389    (set (match_operand:SI 0 "gpc_reg_operand" "")
3390         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3391   "reload_completed"
3392   [(set (match_dup 0)
3393         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3394    (set (match_dup 4)
3395         (compare:CC (match_dup 0)
3396                     (const_int 0)))]
3397   "")
3398
3399 (define_insn "*rotlsi3_internal7"
3400   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3401         (zero_extend:SI
3402          (subreg:QI
3403           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3404                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3405   ""
3406   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff")
3407
3408 (define_insn "*rotlsi3_internal8"
3409   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3410         (compare:CC (zero_extend:SI
3411                      (subreg:QI
3412                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3413                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3414                     (const_int 0)))
3415    (clobber (match_scratch:SI 3 "=r,r"))]
3416   ""
3417   "@
3418    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xff
3419    #"
3420   [(set_attr "type" "delayed_compare")
3421    (set_attr "length" "4,8")])
3422
3423 (define_split
3424   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3425         (compare:CC (zero_extend:SI
3426                      (subreg:QI
3427                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3428                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3429                     (const_int 0)))
3430    (clobber (match_scratch:SI 3 ""))]
3431   "reload_completed"
3432   [(set (match_dup 3)
3433         (zero_extend:SI (subreg:QI
3434                       (rotate:SI (match_dup 1)
3435                                  (match_dup 2)) 0)))
3436    (set (match_dup 0)
3437         (compare:CC (match_dup 3)
3438                     (const_int 0)))]
3439   "")
3440
3441 (define_insn "*rotlsi3_internal9"
3442   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3443         (compare:CC (zero_extend:SI
3444                      (subreg:QI
3445                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3446                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3447                     (const_int 0)))
3448    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3449         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3450   ""
3451   "@
3452    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xff
3453    #"
3454   [(set_attr "type" "delayed_compare")
3455    (set_attr "length" "4,8")])
3456
3457 (define_split
3458   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3459         (compare:CC (zero_extend:SI
3460                      (subreg:QI
3461                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3462                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3463                     (const_int 0)))
3464    (set (match_operand:SI 0 "gpc_reg_operand" "")
3465         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3466   "reload_completed"
3467   [(set (match_dup 0)
3468         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3469    (set (match_dup 3)
3470         (compare:CC (match_dup 0)
3471                     (const_int 0)))]
3472   "")
3473
3474 (define_insn "*rotlsi3_internal10"
3475   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3476         (zero_extend:SI
3477          (subreg:HI
3478           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3479                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3480   ""
3481   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffff")
3482
3483 (define_insn "*rotlsi3_internal11"
3484   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3485         (compare:CC (zero_extend:SI
3486                      (subreg:HI
3487                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3488                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3489                     (const_int 0)))
3490    (clobber (match_scratch:SI 3 "=r,r"))]
3491   ""
3492   "@
3493    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffff
3494    #"
3495   [(set_attr "type" "delayed_compare")
3496    (set_attr "length" "4,8")])
3497
3498 (define_split
3499   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3500         (compare:CC (zero_extend:SI
3501                      (subreg:HI
3502                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3503                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3504                     (const_int 0)))
3505    (clobber (match_scratch:SI 3 ""))]
3506   "reload_completed"
3507   [(set (match_dup 3)
3508         (zero_extend:SI (subreg:HI
3509                       (rotate:SI (match_dup 1)
3510                                  (match_dup 2)) 0)))
3511    (set (match_dup 0)
3512         (compare:CC (match_dup 3)
3513                     (const_int 0)))]
3514   "")
3515
3516 (define_insn "*rotlsi3_internal12"
3517   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3518         (compare:CC (zero_extend:SI
3519                      (subreg:HI
3520                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3521                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3522                     (const_int 0)))
3523    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3524         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3525   ""
3526   "@
3527    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffff
3528    #"
3529   [(set_attr "type" "delayed_compare")
3530    (set_attr "length" "4,8")])
3531
3532 (define_split
3533   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3534         (compare:CC (zero_extend:SI
3535                      (subreg:HI
3536                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3537                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3538                     (const_int 0)))
3539    (set (match_operand:SI 0 "gpc_reg_operand" "")
3540         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3541   "reload_completed"
3542   [(set (match_dup 0)
3543         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3544    (set (match_dup 3)
3545         (compare:CC (match_dup 0)
3546                     (const_int 0)))]
3547   "")
3548
3549 ;; Note that we use "sle." instead of "sl." so that we can set
3550 ;; SHIFT_COUNT_TRUNCATED.
3551
3552 (define_expand "ashlsi3"
3553   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
3554    (use (match_operand:SI 1 "gpc_reg_operand" ""))
3555    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
3556   ""
3557   "
3558 {
3559   if (TARGET_POWER)
3560     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
3561   else
3562     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
3563   DONE;
3564 }")
3565
3566 (define_insn "ashlsi3_power"
3567   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3568         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3569                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
3570    (clobber (match_scratch:SI 3 "=q,X"))]
3571   "TARGET_POWER"
3572   "@
3573    sle %0,%1,%2
3574    {sli|slwi} %0,%1,%h2")
3575
3576 (define_insn "ashlsi3_no_power"
3577   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3578         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3579                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3580   "! TARGET_POWER"
3581   "{sl|slw}%I2 %0,%1,%h2")
3582
3583 (define_insn ""
3584   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3585         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3586                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3587                     (const_int 0)))
3588    (clobber (match_scratch:SI 3 "=r,r,r,r"))
3589    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
3590   "TARGET_POWER"
3591   "@
3592    sle. %3,%1,%2
3593    {sli.|slwi.} %3,%1,%h2
3594    #
3595    #"
3596   [(set_attr "type" "delayed_compare")
3597    (set_attr "length" "4,4,8,8")])
3598
3599 (define_split
3600   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3601         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3602                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3603                     (const_int 0)))
3604    (clobber (match_scratch:SI 3 ""))
3605    (clobber (match_scratch:SI 4 ""))]
3606   "TARGET_POWER && reload_completed"
3607   [(parallel [(set (match_dup 3)
3608         (ashift:SI (match_dup 1) (match_dup 2)))
3609    (clobber (match_dup 4))])
3610    (set (match_dup 0)
3611         (compare:CC (match_dup 3)
3612                     (const_int 0)))]
3613   "")
3614
3615 (define_insn ""
3616   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3617         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3618                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3619                     (const_int 0)))
3620    (clobber (match_scratch:SI 3 "=r,r"))]
3621   "! TARGET_POWER && ! TARGET_POWERPC64"
3622   "@
3623    {sl|slw}%I2. %3,%1,%h2
3624    #"
3625   [(set_attr "type" "delayed_compare")
3626    (set_attr "length" "4,8")])
3627
3628 (define_split
3629   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3630         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3631                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3632                     (const_int 0)))
3633    (clobber (match_scratch:SI 3 ""))]
3634   "! TARGET_POWER && ! TARGET_POWERPC64 && reload_completed"
3635   [(set (match_dup 3)
3636         (ashift:SI (match_dup 1) (match_dup 2)))
3637    (set (match_dup 0)
3638         (compare:CC (match_dup 3)
3639                     (const_int 0)))]
3640   "")
3641
3642 (define_insn ""
3643   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3644         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3645                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3646                     (const_int 0)))
3647    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3648         (ashift:SI (match_dup 1) (match_dup 2)))
3649    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
3650   "TARGET_POWER"
3651   "@
3652    sle. %0,%1,%2
3653    {sli.|slwi.} %0,%1,%h2
3654    #
3655    #"
3656   [(set_attr "type" "delayed_compare")
3657    (set_attr "length" "4,4,8,8")])
3658
3659 (define_split
3660   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3661         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3662                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3663                     (const_int 0)))
3664    (set (match_operand:SI 0 "gpc_reg_operand" "")
3665         (ashift:SI (match_dup 1) (match_dup 2)))
3666    (clobber (match_scratch:SI 4 ""))]
3667   "TARGET_POWER && reload_completed"
3668   [(parallel [(set (match_dup 0)
3669         (ashift:SI (match_dup 1) (match_dup 2)))
3670    (clobber (match_dup 4))])
3671    (set (match_dup 3)
3672         (compare:CC (match_dup 0)
3673                     (const_int 0)))]
3674   "")
3675
3676 (define_insn ""
3677   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3678         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3679                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3680                     (const_int 0)))
3681    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3682         (ashift:SI (match_dup 1) (match_dup 2)))]
3683   "! TARGET_POWER && ! TARGET_POWERPC64"
3684   "@
3685    {sl|slw}%I2. %0,%1,%h2
3686    #"
3687   [(set_attr "type" "delayed_compare")
3688    (set_attr "length" "4,8")])
3689
3690 (define_split
3691   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3692         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3693                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3694                     (const_int 0)))
3695    (set (match_operand:SI 0 "gpc_reg_operand" "")
3696         (ashift:SI (match_dup 1) (match_dup 2)))]
3697   "! TARGET_POWER && ! TARGET_POWERPC64 && reload_completed"
3698   [(set (match_dup 0)
3699         (ashift:SI (match_dup 1) (match_dup 2)))
3700    (set (match_dup 3)
3701         (compare:CC (match_dup 0)
3702                     (const_int 0)))]
3703   "")
3704
3705 (define_insn ""
3706   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3707         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3708                            (match_operand:SI 2 "const_int_operand" "i"))
3709                 (match_operand:SI 3 "mask_operand" "n")))]
3710   "includes_lshift_p (operands[2], operands[3])"
3711   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
3712
3713 (define_insn ""
3714   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3715         (compare:CC
3716          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3717                             (match_operand:SI 2 "const_int_operand" "i,i"))
3718                  (match_operand:SI 3 "mask_operand" "n,n"))
3719          (const_int 0)))
3720    (clobber (match_scratch:SI 4 "=r,r"))]
3721   "includes_lshift_p (operands[2], operands[3])"
3722   "@
3723    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
3724    #"
3725   [(set_attr "type" "delayed_compare")
3726    (set_attr "length" "4,8")])
3727
3728 (define_split
3729   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3730         (compare:CC
3731          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3732                             (match_operand:SI 2 "const_int_operand" ""))
3733                  (match_operand:SI 3 "mask_operand" ""))
3734          (const_int 0)))
3735    (clobber (match_scratch:SI 4 ""))]
3736   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
3737   [(set (match_dup 4)
3738         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
3739                  (match_dup 3)))
3740    (set (match_dup 0)
3741         (compare:CC (match_dup 4)
3742                     (const_int 0)))]
3743   "")
3744
3745 (define_insn ""
3746   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3747         (compare:CC
3748          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3749                             (match_operand:SI 2 "const_int_operand" "i,i"))
3750                  (match_operand:SI 3 "mask_operand" "n,n"))
3751          (const_int 0)))
3752    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3753         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3754   "includes_lshift_p (operands[2], operands[3])"
3755   "@
3756    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
3757    #"
3758   [(set_attr "type" "delayed_compare")
3759    (set_attr "length" "4,8")])
3760
3761 (define_split
3762   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3763         (compare:CC
3764          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3765                             (match_operand:SI 2 "const_int_operand" ""))
3766                  (match_operand:SI 3 "mask_operand" ""))
3767          (const_int 0)))
3768    (set (match_operand:SI 0 "gpc_reg_operand" "")
3769         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3770   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
3771   [(set (match_dup 0)
3772         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3773    (set (match_dup 4)
3774         (compare:CC (match_dup 0)
3775                     (const_int 0)))]
3776   "")
3777
3778 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
3779 ;; "sli x,x,0".
3780 (define_expand "lshrsi3"
3781   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
3782    (use (match_operand:SI 1 "gpc_reg_operand" ""))
3783    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
3784   ""
3785   "
3786 {
3787   if (TARGET_POWER)
3788     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
3789   else
3790     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
3791   DONE;
3792 }")
3793
3794 (define_insn "lshrsi3_power"
3795   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
3796         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
3797                      (match_operand:SI 2 "reg_or_cint_operand" "r,O,i")))
3798    (clobber (match_scratch:SI 3 "=q,X,X"))]
3799   "TARGET_POWER"
3800   "@
3801   sre %0,%1,%2
3802   mr %0,%1
3803   {s%A2i|s%A2wi} %0,%1,%h2")
3804
3805 (define_insn "lshrsi3_no_power"
3806   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3807         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3808                      (match_operand:SI 2 "reg_or_cint_operand" "O,ri")))]
3809   "! TARGET_POWER"
3810   "@
3811   mr %0,%1
3812   {sr|srw}%I2 %0,%1,%h2")
3813
3814 (define_insn ""
3815   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
3816         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
3817                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
3818                     (const_int 0)))
3819    (clobber (match_scratch:SI 3 "=r,X,r,r,X,r"))
3820    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
3821   "TARGET_POWER"
3822   "@
3823   sre. %3,%1,%2
3824   mr. %1,%1
3825   {s%A2i.|s%A2wi.} %3,%1,%h2
3826   #
3827   #
3828   #"
3829   [(set_attr "type" "delayed_compare")
3830    (set_attr "length" "4,4,4,8,8,8")])
3831
3832 (define_split
3833   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3834         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3835                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3836                     (const_int 0)))
3837    (clobber (match_scratch:SI 3 ""))
3838    (clobber (match_scratch:SI 4 ""))]
3839   "TARGET_POWER && reload_completed"
3840   [(parallel [(set (match_dup 3)
3841         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3842    (clobber (match_dup 4))])
3843    (set (match_dup 0)
3844         (compare:CC (match_dup 3)
3845                     (const_int 0)))]
3846   "")
3847
3848 (define_insn ""
3849   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3850         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3851                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
3852                     (const_int 0)))
3853    (clobber (match_scratch:SI 3 "=X,r,X,r"))]
3854   "! TARGET_POWER && ! TARGET_POWERPC64"
3855   "@
3856    mr. %1,%1
3857    {sr|srw}%I2. %3,%1,%h2
3858    #
3859    #"
3860   [(set_attr "type" "delayed_compare")
3861    (set_attr "length" "4,4,8,8")])
3862
3863 (define_split
3864   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3865         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3866                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3867                     (const_int 0)))
3868    (clobber (match_scratch:SI 3 ""))]
3869   "! TARGET_POWER && ! TARGET_POWERPC64 && reload_completed"
3870   [(set (match_dup 3)
3871         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3872    (set (match_dup 0)
3873         (compare:CC (match_dup 3)
3874                     (const_int 0)))]
3875   "")
3876
3877 (define_insn ""
3878   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
3879         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
3880                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
3881                     (const_int 0)))
3882    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
3883         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3884    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
3885   "TARGET_POWER"
3886   "@
3887   sre. %0,%1,%2
3888   mr. %0,%1
3889   {s%A2i.|s%A2wi.} %0,%1,%h2
3890   #
3891   #
3892   #"
3893   [(set_attr "type" "delayed_compare")
3894    (set_attr "length" "4,4,4,8,8,8")])
3895
3896 (define_split
3897   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3898         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3899                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3900                     (const_int 0)))
3901    (set (match_operand:SI 0 "gpc_reg_operand" "")
3902         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3903    (clobber (match_scratch:SI 4 ""))]
3904   "TARGET_POWER && reload_completed"
3905   [(parallel [(set (match_dup 0)
3906         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3907    (clobber (match_dup 4))])
3908    (set (match_dup 3)
3909         (compare:CC (match_dup 0)
3910                     (const_int 0)))]
3911   "")
3912
3913 (define_insn ""
3914   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3915         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3916                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
3917                     (const_int 0)))
3918    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3919         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
3920   "! TARGET_POWER && ! TARGET_POWERPC64"
3921   "@
3922    mr. %0,%1
3923    {sr|srw}%I2. %0,%1,%h2
3924    #
3925    #"
3926   [(set_attr "type" "delayed_compare")
3927    (set_attr "length" "4,4,8,8")])
3928
3929 (define_split
3930   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3931         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3932                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3933                     (const_int 0)))
3934    (set (match_operand:SI 0 "gpc_reg_operand" "")
3935         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
3936   "! TARGET_POWER && ! TARGET_POWERPC64 && reload_completed"
3937   [(set (match_dup 0)
3938         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3939    (set (match_dup 3)
3940         (compare:CC (match_dup 0)
3941                     (const_int 0)))]
3942   "")
3943
3944 (define_insn ""
3945   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3946         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3947                              (match_operand:SI 2 "const_int_operand" "i"))
3948                 (match_operand:SI 3 "mask_operand" "n")))]
3949   "includes_rshift_p (operands[2], operands[3])"
3950   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
3951
3952 (define_insn ""
3953   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3954         (compare:CC
3955          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3956                               (match_operand:SI 2 "const_int_operand" "i,i"))
3957                  (match_operand:SI 3 "mask_operand" "n,n"))
3958          (const_int 0)))
3959    (clobber (match_scratch:SI 4 "=r,r"))]
3960   "includes_rshift_p (operands[2], operands[3])"
3961   "@
3962    {rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3
3963    #"
3964   [(set_attr "type" "delayed_compare")
3965    (set_attr "length" "4,8")])
3966
3967 (define_split
3968   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3969         (compare:CC
3970          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3971                               (match_operand:SI 2 "const_int_operand" ""))
3972                  (match_operand:SI 3 "mask_operand" ""))
3973          (const_int 0)))
3974    (clobber (match_scratch:SI 4 ""))]
3975   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
3976   [(set (match_dup 4)
3977         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
3978                  (match_dup 3)))
3979    (set (match_dup 0)
3980         (compare:CC (match_dup 4)
3981                     (const_int 0)))]
3982   "")
3983
3984 (define_insn ""
3985   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3986         (compare:CC
3987          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3988                               (match_operand:SI 2 "const_int_operand" "i,i"))
3989                  (match_operand:SI 3 "mask_operand" "n,n"))
3990          (const_int 0)))
3991    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3992         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3993   "includes_rshift_p (operands[2], operands[3])"
3994   "@
3995    {rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3
3996    #"
3997   [(set_attr "type" "delayed_compare")
3998    (set_attr "length" "4,8")])
3999
4000 (define_split
4001   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4002         (compare:CC
4003          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4004                               (match_operand:SI 2 "const_int_operand" ""))
4005                  (match_operand:SI 3 "mask_operand" ""))
4006          (const_int 0)))
4007    (set (match_operand:SI 0 "gpc_reg_operand" "")
4008         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4009   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4010   [(set (match_dup 0)
4011         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4012    (set (match_dup 4)
4013         (compare:CC (match_dup 0)
4014                     (const_int 0)))]
4015   "")
4016
4017 (define_insn ""
4018   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4019         (zero_extend:SI
4020          (subreg:QI
4021           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4022                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4023   "includes_rshift_p (operands[2], GEN_INT (255))"
4024   "{rlinm|rlwinm} %0,%1,%s2,0xff")
4025
4026 (define_insn ""
4027   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4028         (compare:CC
4029          (zero_extend:SI
4030           (subreg:QI
4031            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4032                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4033          (const_int 0)))
4034    (clobber (match_scratch:SI 3 "=r,r"))]
4035   "includes_rshift_p (operands[2], GEN_INT (255))"
4036   "@
4037    {rlinm.|rlwinm.} %3,%1,%s2,0xff
4038    #"
4039   [(set_attr "type" "delayed_compare")
4040    (set_attr "length" "4,8")])
4041
4042 (define_split
4043   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4044         (compare:CC
4045          (zero_extend:SI
4046           (subreg:QI
4047            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4048                         (match_operand:SI 2 "const_int_operand" "")) 0))
4049          (const_int 0)))
4050    (clobber (match_scratch:SI 3 ""))]
4051   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4052   [(set (match_dup 3)
4053         (zero_extend:SI (subreg:QI
4054            (lshiftrt:SI (match_dup 1)
4055                         (match_dup 2)) 0)))
4056    (set (match_dup 0)
4057         (compare:CC (match_dup 3)
4058                     (const_int 0)))]
4059   "")
4060
4061 (define_insn ""
4062   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4063         (compare:CC
4064          (zero_extend:SI
4065           (subreg:QI
4066            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4067                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4068          (const_int 0)))
4069    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4070         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4071   "includes_rshift_p (operands[2], GEN_INT (255))"
4072   "@
4073    {rlinm.|rlwinm.} %0,%1,%s2,0xff
4074    #"
4075   [(set_attr "type" "delayed_compare")
4076    (set_attr "length" "4,8")])
4077
4078 (define_split
4079   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4080         (compare:CC
4081          (zero_extend:SI
4082           (subreg:QI
4083            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4084                         (match_operand:SI 2 "const_int_operand" "")) 0))
4085          (const_int 0)))
4086    (set (match_operand:SI 0 "gpc_reg_operand" "")
4087         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4088   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4089   [(set (match_dup 0)
4090         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4091    (set (match_dup 3)
4092         (compare:CC (match_dup 0)
4093                     (const_int 0)))]
4094   "")
4095
4096 (define_insn ""
4097   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4098         (zero_extend:SI
4099          (subreg:HI
4100           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4101                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4102   "includes_rshift_p (operands[2], GEN_INT (65535))"
4103   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
4104
4105 (define_insn ""
4106   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4107         (compare:CC
4108          (zero_extend:SI
4109           (subreg:HI
4110            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4111                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4112          (const_int 0)))
4113    (clobber (match_scratch:SI 3 "=r,r"))]
4114   "includes_rshift_p (operands[2], GEN_INT (65535))"
4115   "@
4116    {rlinm.|rlwinm.} %3,%1,%s2,0xffff
4117    #"
4118   [(set_attr "type" "delayed_compare")
4119    (set_attr "length" "4,8")])
4120
4121 (define_split
4122   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4123         (compare:CC
4124          (zero_extend:SI
4125           (subreg:HI
4126            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4127                         (match_operand:SI 2 "const_int_operand" "")) 0))
4128          (const_int 0)))
4129    (clobber (match_scratch:SI 3 ""))]
4130   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4131   [(set (match_dup 3)
4132         (zero_extend:SI (subreg:HI
4133            (lshiftrt:SI (match_dup 1)
4134                         (match_dup 2)) 0)))
4135    (set (match_dup 0)
4136         (compare:CC (match_dup 3)
4137                     (const_int 0)))]
4138   "")
4139
4140 (define_insn ""
4141   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4142         (compare:CC
4143          (zero_extend:SI
4144           (subreg:HI
4145            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4146                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4147          (const_int 0)))
4148    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4149         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4150   "includes_rshift_p (operands[2], GEN_INT (65535))"
4151   "@
4152    {rlinm.|rlwinm.} %0,%1,%s2,0xffff
4153    #"
4154   [(set_attr "type" "delayed_compare")
4155    (set_attr "length" "4,8")])
4156
4157 (define_split
4158   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4159         (compare:CC
4160          (zero_extend:SI
4161           (subreg:HI
4162            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4163                         (match_operand:SI 2 "const_int_operand" "")) 0))
4164          (const_int 0)))
4165    (set (match_operand:SI 0 "gpc_reg_operand" "")
4166         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4167   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4168   [(set (match_dup 0)
4169         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4170    (set (match_dup 3)
4171         (compare:CC (match_dup 0)
4172                     (const_int 0)))]
4173   "")
4174
4175 (define_insn ""
4176   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4177                          (const_int 1)
4178                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4179         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4180                      (const_int 31)))]
4181   "TARGET_POWER"
4182   "rrib %0,%1,%2")
4183
4184 (define_insn ""
4185   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4186                          (const_int 1)
4187                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4188         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4189                      (const_int 31)))]
4190   "TARGET_POWER"
4191   "rrib %0,%1,%2")
4192
4193 (define_insn ""
4194   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4195                          (const_int 1)
4196                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4197         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4198                          (const_int 1)
4199                          (const_int 0)))]
4200   "TARGET_POWER"
4201   "rrib %0,%1,%2")
4202
4203 (define_expand "ashrsi3"
4204   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4205         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4206                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
4207   ""
4208   "
4209 {
4210   if (TARGET_POWER)
4211     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
4212   else
4213     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
4214   DONE;
4215 }")
4216
4217 (define_insn "ashrsi3_power"
4218   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4219         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4220                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4221    (clobber (match_scratch:SI 3 "=q,X"))]
4222   "TARGET_POWER"
4223   "@
4224    srea %0,%1,%2
4225    {srai|srawi} %0,%1,%h2")
4226
4227 (define_insn "ashrsi3_no_power"
4228   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4229         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4230                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4231   "! TARGET_POWER"
4232   "{sra|sraw}%I2 %0,%1,%h2")
4233
4234 (define_insn ""
4235   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4236         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4237                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4238                     (const_int 0)))
4239    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4240    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4241   "TARGET_POWER"
4242   "@
4243    srea. %3,%1,%2
4244    {srai.|srawi.} %3,%1,%h2
4245    #
4246    #"
4247   [(set_attr "type" "delayed_compare")
4248    (set_attr "length" "4,4,8,8")])
4249
4250 (define_split
4251   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4252         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4253                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4254                     (const_int 0)))
4255    (clobber (match_scratch:SI 3 ""))
4256    (clobber (match_scratch:SI 4 ""))]
4257   "TARGET_POWER && reload_completed"
4258   [(parallel [(set (match_dup 3)
4259         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4260    (clobber (match_dup 4))])
4261    (set (match_dup 0)
4262         (compare:CC (match_dup 3)
4263                     (const_int 0)))]
4264   "")
4265
4266 (define_insn ""
4267   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4268         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4269                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4270                     (const_int 0)))
4271    (clobber (match_scratch:SI 3 "=r,r"))]
4272   "! TARGET_POWER"
4273   "@
4274    {sra|sraw}%I2. %3,%1,%h2
4275    #"
4276   [(set_attr "type" "delayed_compare")
4277    (set_attr "length" "4,8")])
4278
4279 (define_split
4280   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4281         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4282                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4283                     (const_int 0)))
4284    (clobber (match_scratch:SI 3 ""))]
4285   "! TARGET_POWER && reload_completed"
4286   [(set (match_dup 3)
4287         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4288    (set (match_dup 0)
4289         (compare:CC (match_dup 3)
4290                     (const_int 0)))]
4291   "")
4292
4293 (define_insn ""
4294   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4295         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4296                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4297                     (const_int 0)))
4298    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4299         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4300    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4301   "TARGET_POWER"
4302   "@
4303    srea. %0,%1,%2
4304    {srai.|srawi.} %0,%1,%h2
4305    #
4306    #"
4307   [(set_attr "type" "delayed_compare")
4308    (set_attr "length" "4,4,8,8")])
4309
4310 (define_split
4311   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4312         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4313                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4314                     (const_int 0)))
4315    (set (match_operand:SI 0 "gpc_reg_operand" "")
4316         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4317    (clobber (match_scratch:SI 4 ""))]
4318   "TARGET_POWER && reload_completed"
4319   [(parallel [(set (match_dup 0)
4320         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4321    (clobber (match_dup 4))])
4322    (set (match_dup 3)
4323         (compare:CC (match_dup 0)
4324                     (const_int 0)))]
4325   "")
4326
4327 (define_insn ""
4328   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4329         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4330                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4331                     (const_int 0)))
4332    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4333         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4334   "! TARGET_POWER"
4335   "@
4336    {sra|sraw}%I2. %0,%1,%h2
4337    #"
4338   [(set_attr "type" "delayed_compare")
4339    (set_attr "length" "4,8")])
4340 \f
4341 (define_split
4342   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4343         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4344                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4345                     (const_int 0)))
4346    (set (match_operand:SI 0 "gpc_reg_operand" "")
4347         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4348   "! TARGET_POWER && reload_completed"
4349   [(set (match_dup 0)
4350         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4351    (set (match_dup 3)
4352         (compare:CC (match_dup 0)
4353                     (const_int 0)))]
4354   "")
4355
4356 ;; Floating-point insns, excluding normal data motion.
4357 ;;
4358 ;; PowerPC has a full set of single-precision floating point instructions.
4359 ;;
4360 ;; For the POWER architecture, we pretend that we have both SFmode and
4361 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
4362 ;; The only conversions we will do will be when storing to memory.  In that
4363 ;; case, we will use the "frsp" instruction before storing.
4364 ;;
4365 ;; Note that when we store into a single-precision memory location, we need to
4366 ;; use the frsp insn first.  If the register being stored isn't dead, we
4367 ;; need a scratch register for the frsp.  But this is difficult when the store
4368 ;; is done by reload.  It is not incorrect to do the frsp on the register in
4369 ;; this case, we just lose precision that we would have otherwise gotten but
4370 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
4371
4372 (define_insn "extendsfdf2"
4373   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4374         (float_extend:DF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4375   "TARGET_HARD_FLOAT && TARGET_FPRS"
4376   "*
4377 {
4378   if (REGNO (operands[0]) == REGNO (operands[1]))
4379     return \"\";
4380   else
4381     return \"fmr %0,%1\";
4382 }"
4383   [(set_attr "type" "fp")])
4384
4385 (define_insn "truncdfsf2"
4386   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4387         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4388   "TARGET_HARD_FLOAT && TARGET_FPRS"
4389   "frsp %0,%1"
4390   [(set_attr "type" "fp")])
4391
4392 (define_insn "aux_truncdfsf2"
4393   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4394         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRSP))]
4395   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4396   "frsp %0,%1"
4397   [(set_attr "type" "fp")])
4398
4399 (define_expand "negsf2"
4400   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4401         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4402   "TARGET_HARD_FLOAT"
4403   "")
4404
4405 (define_insn "*negsf2"
4406   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4407         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4408   "TARGET_HARD_FLOAT && TARGET_FPRS"
4409   "fneg %0,%1"
4410   [(set_attr "type" "fp")])
4411
4412 (define_expand "abssf2"
4413   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4414         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4415   "TARGET_HARD_FLOAT"
4416   "")
4417
4418 (define_insn "*abssf2"
4419   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4420         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4421   "TARGET_HARD_FLOAT && TARGET_FPRS"
4422   "fabs %0,%1"
4423   [(set_attr "type" "fp")])
4424
4425 (define_insn ""
4426   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4427         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
4428   "TARGET_HARD_FLOAT && TARGET_FPRS"
4429   "fnabs %0,%1"
4430   [(set_attr "type" "fp")])
4431
4432 (define_expand "addsf3"
4433   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4434         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4435                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4436   "TARGET_HARD_FLOAT"
4437   "")
4438
4439 (define_insn ""
4440   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4441         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4442                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4443   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4444   "fadds %0,%1,%2"
4445   [(set_attr "type" "fp")])
4446
4447 (define_insn ""
4448   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4449         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4450                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4451   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4452   "{fa|fadd} %0,%1,%2"
4453   [(set_attr "type" "fp")])
4454
4455 (define_expand "subsf3"
4456   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4457         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4458                   (match_operand:SF 2 "gpc_reg_operand" "")))]
4459   "TARGET_HARD_FLOAT"
4460   "")
4461
4462 (define_insn ""
4463   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4464         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4465                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
4466   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4467   "fsubs %0,%1,%2"
4468   [(set_attr "type" "fp")])
4469
4470 (define_insn ""
4471   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4472         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4473                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
4474   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4475   "{fs|fsub} %0,%1,%2"
4476   [(set_attr "type" "fp")])
4477
4478 (define_expand "mulsf3"
4479   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4480         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
4481                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4482   "TARGET_HARD_FLOAT"
4483   "")
4484
4485 (define_insn ""
4486   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4487         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4488                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4489   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4490   "fmuls %0,%1,%2"
4491   [(set_attr "type" "fp")])
4492
4493 (define_insn ""
4494   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4495         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4496                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4497   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4498   "{fm|fmul} %0,%1,%2"
4499   [(set_attr "type" "dmul")])
4500
4501 (define_expand "divsf3"
4502   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4503         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
4504                 (match_operand:SF 2 "gpc_reg_operand" "")))]
4505   "TARGET_HARD_FLOAT"
4506   "")
4507
4508 (define_insn ""
4509   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4510         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4511                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
4512   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4513   "fdivs %0,%1,%2"
4514   [(set_attr "type" "sdiv")])
4515
4516 (define_insn ""
4517   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4518         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4519                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
4520   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4521   "{fd|fdiv} %0,%1,%2"
4522   [(set_attr "type" "ddiv")])
4523
4524 (define_insn ""
4525   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4526         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4527                           (match_operand:SF 2 "gpc_reg_operand" "f"))
4528                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
4529   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4530   "fmadds %0,%1,%2,%3"
4531   [(set_attr "type" "fp")])
4532
4533 (define_insn ""
4534   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4535         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4536                           (match_operand:SF 2 "gpc_reg_operand" "f"))
4537                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
4538   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4539   "{fma|fmadd} %0,%1,%2,%3"
4540   [(set_attr "type" "dmul")])
4541
4542 (define_insn ""
4543   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4544         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4545                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4546                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
4547   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4548   "fmsubs %0,%1,%2,%3"
4549   [(set_attr "type" "fp")])
4550
4551 (define_insn ""
4552   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4553         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4554                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4555                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
4556   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4557   "{fms|fmsub} %0,%1,%2,%3"
4558   [(set_attr "type" "dmul")])
4559
4560 (define_insn ""
4561   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4562         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4563                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
4564                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4565   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4566    && HONOR_SIGNED_ZEROS (SFmode)"
4567   "fnmadds %0,%1,%2,%3"
4568   [(set_attr "type" "fp")])
4569
4570 (define_insn ""
4571   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4572         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
4573                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4574                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4575   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4576    && ! HONOR_SIGNED_ZEROS (SFmode)"
4577   "fnmadds %0,%1,%2,%3"
4578   [(set_attr "type" "fp")])
4579
4580 (define_insn ""
4581   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4582         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4583                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
4584                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4585   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4586   "{fnma|fnmadd} %0,%1,%2,%3"
4587   [(set_attr "type" "dmul")])
4588
4589 (define_insn ""
4590   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4591         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
4592                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4593                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4594   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4595    && ! HONOR_SIGNED_ZEROS (SFmode)"
4596   "{fnma|fnmadd} %0,%1,%2,%3"
4597   [(set_attr "type" "dmul")])
4598
4599 (define_insn ""
4600   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4601         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4602                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
4603                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4604   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4605    && HONOR_SIGNED_ZEROS (SFmode)"
4606   "fnmsubs %0,%1,%2,%3"
4607   [(set_attr "type" "fp")])
4608
4609 (define_insn ""
4610   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4611         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
4612                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4613                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
4614   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4615    && ! HONOR_SIGNED_ZEROS (SFmode)"
4616   "fnmsubs %0,%1,%2,%3"
4617   [(set_attr "type" "fp")])
4618
4619 (define_insn ""
4620   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4621         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4622                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
4623                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4624   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4625   "{fnms|fnmsub} %0,%1,%2,%3"
4626   [(set_attr "type" "dmul")])
4627
4628 (define_insn ""
4629   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4630         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
4631                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4632                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
4633   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4634    && ! HONOR_SIGNED_ZEROS (SFmode)"
4635   "{fnms|fnmsub} %0,%1,%2,%3"
4636   [(set_attr "type" "fp")])
4637
4638 (define_expand "sqrtsf2"
4639   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4640         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4641   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
4642   "")
4643
4644 (define_insn ""
4645   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4646         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4647   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4648   "fsqrts %0,%1"
4649   [(set_attr "type" "ssqrt")])
4650
4651 (define_insn ""
4652   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4653         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4654   "TARGET_POWER2 && TARGET_HARD_FLOAT && TARGET_FPRS"
4655   "fsqrt %0,%1"
4656   [(set_attr "type" "dsqrt")])
4657
4658 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
4659 ;; fsel instruction and some auxiliary computations.  Then we just have a
4660 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
4661 ;; combine.
4662 (define_expand "maxsf3"
4663   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4664         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
4665                              (match_operand:SF 2 "gpc_reg_operand" ""))
4666                          (match_dup 1)
4667                          (match_dup 2)))]
4668   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4669   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
4670
4671 (define_expand "minsf3"
4672   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4673         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
4674                              (match_operand:SF 2 "gpc_reg_operand" ""))
4675                          (match_dup 2)
4676                          (match_dup 1)))]
4677   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4678   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
4679
4680 (define_split
4681   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4682         (match_operator:SF 3 "min_max_operator"
4683          [(match_operand:SF 1 "gpc_reg_operand" "")
4684           (match_operand:SF 2 "gpc_reg_operand" "")]))]
4685   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4686   [(const_int 0)]
4687   "
4688 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]), 
4689                       operands[1], operands[2]);
4690   DONE;
4691 }")
4692
4693 (define_expand "movsicc"
4694    [(set (match_operand:SI 0 "gpc_reg_operand" "")
4695          (if_then_else:SI (match_operand 1 "comparison_operator" "")
4696                           (match_operand:SI 2 "gpc_reg_operand" "")
4697                           (match_operand:SI 3 "gpc_reg_operand" "")))]
4698   "TARGET_ISEL"
4699   "
4700 {
4701   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4702     DONE;
4703   else
4704     FAIL;
4705 }")
4706
4707 ;; We use the BASE_REGS for the isel input operands because, if rA is
4708 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
4709 ;; because we may switch the operands and rB may end up being rA.
4710 ;;
4711 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
4712 ;; leave out the mode in operand 4 and use one pattern, but reload can
4713 ;; change the mode underneath our feet and then gets confused trying
4714 ;; to reload the value.
4715 (define_insn "isel_signed"
4716   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4717         (if_then_else:SI
4718          (match_operator 1 "comparison_operator"
4719                          [(match_operand:CC 4 "cc_reg_operand" "y")
4720                           (const_int 0)])
4721          (match_operand:SI 2 "gpc_reg_operand" "b")
4722          (match_operand:SI 3 "gpc_reg_operand" "b")))]
4723   "TARGET_ISEL"
4724   "*
4725 { return output_isel (operands); }"
4726   [(set_attr "length" "4")])
4727
4728 (define_insn "isel_unsigned"
4729   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4730         (if_then_else:SI
4731          (match_operator 1 "comparison_operator"
4732                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
4733                           (const_int 0)])
4734          (match_operand:SI 2 "gpc_reg_operand" "b")
4735          (match_operand:SI 3 "gpc_reg_operand" "b")))]
4736   "TARGET_ISEL"
4737   "*
4738 { return output_isel (operands); }"
4739   [(set_attr "length" "4")])
4740
4741 (define_expand "movsfcc"
4742    [(set (match_operand:SF 0 "gpc_reg_operand" "")
4743          (if_then_else:SF (match_operand 1 "comparison_operator" "")
4744                           (match_operand:SF 2 "gpc_reg_operand" "")
4745                           (match_operand:SF 3 "gpc_reg_operand" "")))]
4746   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4747   "
4748 {
4749   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4750     DONE;
4751   else
4752     FAIL;
4753 }")
4754
4755 (define_insn "*fselsfsf4"
4756   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4757         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
4758                              (match_operand:SF 4 "zero_fp_constant" "F"))
4759                          (match_operand:SF 2 "gpc_reg_operand" "f")
4760                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4761   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4762   "fsel %0,%1,%2,%3"
4763   [(set_attr "type" "fp")])
4764
4765 (define_insn "*fseldfsf4"
4766   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4767         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
4768                              (match_operand:DF 4 "zero_fp_constant" "F"))
4769                          (match_operand:SF 2 "gpc_reg_operand" "f")
4770                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4771   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4772   "fsel %0,%1,%2,%3"
4773   [(set_attr "type" "fp")])
4774
4775 (define_insn "negdf2"
4776   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4777         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4778   "TARGET_HARD_FLOAT && TARGET_FPRS"
4779   "fneg %0,%1"
4780   [(set_attr "type" "fp")])
4781
4782 (define_insn "absdf2"
4783   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4784         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4785   "TARGET_HARD_FLOAT && TARGET_FPRS"
4786   "fabs %0,%1"
4787   [(set_attr "type" "fp")])
4788
4789 (define_insn ""
4790   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4791         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f"))))]
4792   "TARGET_HARD_FLOAT && TARGET_FPRS"
4793   "fnabs %0,%1"
4794   [(set_attr "type" "fp")])
4795
4796 (define_insn "adddf3"
4797   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4798         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4799                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
4800   "TARGET_HARD_FLOAT && TARGET_FPRS"
4801   "{fa|fadd} %0,%1,%2"
4802   [(set_attr "type" "fp")])
4803
4804 (define_insn "subdf3"
4805   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4806         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "f")
4807                   (match_operand:DF 2 "gpc_reg_operand" "f")))]
4808   "TARGET_HARD_FLOAT && TARGET_FPRS"
4809   "{fs|fsub} %0,%1,%2"
4810   [(set_attr "type" "fp")])
4811
4812 (define_insn "muldf3"
4813   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4814         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4815                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
4816   "TARGET_HARD_FLOAT && TARGET_FPRS"
4817   "{fm|fmul} %0,%1,%2"
4818   [(set_attr "type" "dmul")])
4819
4820 (define_insn "divdf3"
4821   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4822         (div:DF (match_operand:DF 1 "gpc_reg_operand" "f")
4823                 (match_operand:DF 2 "gpc_reg_operand" "f")))]
4824   "TARGET_HARD_FLOAT && TARGET_FPRS"
4825   "{fd|fdiv} %0,%1,%2"
4826   [(set_attr "type" "ddiv")])
4827
4828 (define_insn ""
4829   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4830         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4831                           (match_operand:DF 2 "gpc_reg_operand" "f"))
4832                  (match_operand:DF 3 "gpc_reg_operand" "f")))]
4833   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4834   "{fma|fmadd} %0,%1,%2,%3"
4835   [(set_attr "type" "dmul")])
4836
4837 (define_insn ""
4838   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4839         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4840                            (match_operand:DF 2 "gpc_reg_operand" "f"))
4841                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
4842   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4843   "{fms|fmsub} %0,%1,%2,%3"
4844   [(set_attr "type" "dmul")])
4845
4846 (define_insn ""
4847   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4848         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4849                                   (match_operand:DF 2 "gpc_reg_operand" "f"))
4850                          (match_operand:DF 3 "gpc_reg_operand" "f"))))]
4851   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4852    && HONOR_SIGNED_ZEROS (DFmode)"
4853   "{fnma|fnmadd} %0,%1,%2,%3"
4854   [(set_attr "type" "dmul")])
4855
4856 (define_insn ""
4857   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4858         (minus:DF (mult:DF (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f"))
4859                            (match_operand:DF 2 "gpc_reg_operand" "f"))
4860                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
4861   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4862    && ! HONOR_SIGNED_ZEROS (DFmode)"
4863   "{fnma|fnmadd} %0,%1,%2,%3"
4864   [(set_attr "type" "dmul")])
4865
4866 (define_insn ""
4867   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4868         (neg:DF (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4869                                    (match_operand:DF 2 "gpc_reg_operand" "f"))
4870                           (match_operand:DF 3 "gpc_reg_operand" "f"))))]
4871   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4872    && HONOR_SIGNED_ZEROS (DFmode)"
4873   "{fnms|fnmsub} %0,%1,%2,%3"
4874   [(set_attr "type" "dmul")])
4875
4876 (define_insn ""
4877   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4878         (minus:DF (match_operand:DF 3 "gpc_reg_operand" "f")
4879                   (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4880                            (match_operand:DF 2 "gpc_reg_operand" "f"))))]
4881   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD 
4882    && ! HONOR_SIGNED_ZEROS (DFmode)"
4883   "{fnms|fnmsub} %0,%1,%2,%3"
4884   [(set_attr "type" "dmul")])
4885
4886 (define_insn "sqrtdf2"
4887   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4888         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4889   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
4890   "fsqrt %0,%1"
4891   [(set_attr "type" "dsqrt")])
4892
4893 ;; The conditional move instructions allow us to perform max and min
4894 ;; operations even when 
4895
4896 (define_expand "maxdf3"
4897   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4898         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
4899                              (match_operand:DF 2 "gpc_reg_operand" ""))
4900                          (match_dup 1)
4901                          (match_dup 2)))]
4902   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4903   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
4904
4905 (define_expand "mindf3"
4906   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4907         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
4908                              (match_operand:DF 2 "gpc_reg_operand" ""))
4909                          (match_dup 2)
4910                          (match_dup 1)))]
4911   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4912   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
4913
4914 (define_split
4915   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4916         (match_operator:DF 3 "min_max_operator"
4917          [(match_operand:DF 1 "gpc_reg_operand" "")
4918           (match_operand:DF 2 "gpc_reg_operand" "")]))]
4919   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4920   [(const_int 0)]
4921   "
4922 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]), 
4923                       operands[1], operands[2]);
4924   DONE;
4925 }")
4926
4927 (define_expand "movdfcc"
4928    [(set (match_operand:DF 0 "gpc_reg_operand" "")
4929          (if_then_else:DF (match_operand 1 "comparison_operator" "")
4930                           (match_operand:DF 2 "gpc_reg_operand" "")
4931                           (match_operand:DF 3 "gpc_reg_operand" "")))]
4932   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4933   "
4934 {
4935   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4936     DONE;
4937   else
4938     FAIL;
4939 }")
4940
4941 (define_insn "*fseldfdf4"
4942   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4943         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
4944                              (match_operand:DF 4 "zero_fp_constant" "F"))
4945                          (match_operand:DF 2 "gpc_reg_operand" "f")
4946                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
4947   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4948   "fsel %0,%1,%2,%3"
4949   [(set_attr "type" "fp")])
4950
4951 (define_insn "*fselsfdf4"
4952   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4953         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
4954                              (match_operand:SF 4 "zero_fp_constant" "F"))
4955                          (match_operand:DF 2 "gpc_reg_operand" "f")
4956                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
4957   "TARGET_PPC_GFXOPT"
4958   "fsel %0,%1,%2,%3"
4959   [(set_attr "type" "fp")])
4960 \f
4961 ;; Conversions to and from floating-point.
4962
4963 (define_expand "fixunssfsi2"
4964   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4965         (unsigned_fix:SI (fix:SF (match_operand:SF 1 "gpc_reg_operand" ""))))]
4966   "TARGET_HARD_FLOAT && !TARGET_FPRS"
4967   "")
4968
4969 (define_expand "fix_truncsfsi2"
4970   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4971         (fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
4972   "TARGET_HARD_FLOAT && !TARGET_FPRS"
4973   "")
4974
4975 ; For each of these conversions, there is a define_expand, a define_insn
4976 ; with a '#' template, and a define_split (with C code).  The idea is
4977 ; to allow constant folding with the template of the define_insn,
4978 ; then to have the insns split later (between sched1 and final).
4979
4980 (define_expand "floatsidf2"
4981   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
4982                    (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
4983               (use (match_dup 2))
4984               (use (match_dup 3))
4985               (clobber (match_dup 4))
4986               (clobber (match_dup 5))
4987               (clobber (match_dup 6))])]
4988   "TARGET_HARD_FLOAT && TARGET_FPRS"
4989   "
4990 {
4991   if (TARGET_POWERPC64)
4992     {
4993       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
4994       rtx t1 = gen_reg_rtx (DImode);
4995       rtx t2 = gen_reg_rtx (DImode);
4996       emit_insn (gen_floatsidf_ppc64 (operands[0], operands[1], mem, t1, t2));
4997       DONE;
4998     }
4999
5000   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5001   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
5002   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5003   operands[5] = gen_reg_rtx (DFmode);
5004   operands[6] = gen_reg_rtx (SImode);
5005 }")
5006
5007 (define_insn "*floatsidf2_internal"
5008   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5009         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5010    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5011    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5012    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5013    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))
5014    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
5015   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5016   "#"
5017   [(set_attr "length" "24")])
5018
5019 (define_split
5020   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5021         (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5022    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5023    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5024    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5025    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))
5026    (clobber (match_operand:SI 6 "gpc_reg_operand" ""))]
5027   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5028   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5029         (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5030    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5031    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5032    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5033    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))
5034    (clobber (match_operand:SI 6 "gpc_reg_operand" ""))]
5035   "
5036 {
5037   rtx lowword, highword;
5038   if (GET_CODE (operands[4]) != MEM)
5039     abort();
5040   highword = XEXP (operands[4], 0);
5041   lowword = plus_constant (highword, 4);
5042   if (! WORDS_BIG_ENDIAN)
5043     {
5044       rtx tmp;
5045       tmp = highword; highword = lowword; lowword = tmp;
5046     }
5047
5048   emit_insn (gen_xorsi3 (operands[6], operands[1], 
5049                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
5050   emit_move_insn (gen_rtx_MEM (SImode, lowword), operands[6]);
5051   emit_move_insn (gen_rtx_MEM (SImode, highword), operands[2]);
5052   emit_move_insn (operands[5], operands[4]);
5053   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5054   DONE;
5055 }")
5056
5057 (define_expand "floatunssisf2"
5058   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5059         (unsigned_float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5060   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5061   "")
5062
5063 (define_expand "floatunssidf2"
5064   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5065                    (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5066               (use (match_dup 2))
5067               (use (match_dup 3))
5068               (clobber (match_dup 4))
5069               (clobber (match_dup 5))])]
5070   "TARGET_HARD_FLOAT && TARGET_FPRS"
5071   "
5072 {
5073   if (TARGET_POWERPC64)
5074     {
5075       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5076       rtx t1 = gen_reg_rtx (DImode);
5077       rtx t2 = gen_reg_rtx (DImode);
5078       emit_insn (gen_floatunssidf_ppc64 (operands[0], operands[1], mem,
5079                                          t1, t2));
5080       DONE;
5081     }
5082
5083   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5084   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
5085   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5086   operands[5] = gen_reg_rtx (DFmode);
5087 }")
5088
5089 (define_insn "*floatunssidf2_internal"
5090   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5091         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5092    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5093    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5094    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5095    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))]
5096   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5097   "#"
5098   [(set_attr "length" "20")])
5099
5100 (define_split
5101   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5102         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5103    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5104    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5105    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5106    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))]
5107   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5108   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5109         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5110    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5111    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5112    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5113    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))]
5114   "
5115 {
5116   rtx lowword, highword;
5117   if (GET_CODE (operands[4]) != MEM)
5118     abort();
5119   highword = XEXP (operands[4], 0);
5120   lowword = plus_constant (highword, 4);
5121   if (! WORDS_BIG_ENDIAN)
5122     {
5123       rtx tmp;
5124       tmp = highword; highword = lowword; lowword = tmp;
5125     }
5126
5127   emit_move_insn (gen_rtx_MEM (SImode, lowword), operands[1]);
5128   emit_move_insn (gen_rtx_MEM (SImode, highword), operands[2]);
5129   emit_move_insn (operands[5], operands[4]);
5130   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5131   DONE;
5132 }")
5133
5134 (define_expand "fix_truncdfsi2"
5135   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
5136                    (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5137               (clobber (match_dup 2))
5138               (clobber (match_dup 3))])]
5139   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5140   "
5141 {
5142   operands[2] = gen_reg_rtx (DImode);
5143   operands[3] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5144 }")
5145
5146 (define_insn "*fix_truncdfsi2_internal"
5147   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5148         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5149    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))
5150    (clobber (match_operand:DI 3 "memory_operand" "=o"))]
5151   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5152   "#"
5153   [(set_attr "length" "16")])
5154
5155 (define_split
5156   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5157         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5158    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
5159    (clobber (match_operand:DI 3 "offsettable_mem_operand" ""))]
5160   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5161   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5162         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5163    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
5164    (clobber (match_operand:DI 3 "offsettable_mem_operand" ""))]
5165   "
5166 {
5167   rtx lowword;
5168   if (GET_CODE (operands[3]) != MEM)
5169     abort();
5170   lowword = XEXP (operands[3], 0);
5171   if (WORDS_BIG_ENDIAN)
5172     lowword = plus_constant (lowword, 4);
5173
5174   emit_insn (gen_fctiwz (operands[2], operands[1]));
5175   emit_move_insn (operands[3], operands[2]);
5176   emit_move_insn (operands[0], gen_rtx_MEM (SImode, lowword));
5177   DONE;
5178 }")
5179
5180 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
5181 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
5182 ; because the first makes it clear that operand 0 is not live
5183 ; before the instruction.
5184 (define_insn "fctiwz"
5185   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
5186         (unspec:DI [(fix:SI (match_operand:DF 1 "gpc_reg_operand" "f"))]
5187                    UNSPEC_FCTIWZ))]
5188   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5189   "{fcirz|fctiwz} %0,%1"
5190   [(set_attr "type" "fp")])
5191
5192 (define_expand "floatsisf2"
5193   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5194         (float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5195   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5196   "")
5197
5198 (define_insn "floatdidf2"
5199   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5200         (float:DF (match_operand:DI 1 "gpc_reg_operand" "*f")))]
5201   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5202   "fcfid %0,%1"
5203   [(set_attr "type" "fp")])
5204
5205 (define_insn_and_split "floatsidf_ppc64"
5206   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5207         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5208    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5209    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5210    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5211   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5212   "#"
5213   ""
5214   [(set (match_dup 3) (sign_extend:DI (match_dup 1)))
5215    (set (match_dup 2) (match_dup 3))
5216    (set (match_dup 4) (match_dup 2))
5217    (set (match_dup 0) (float:DF (match_dup 4)))]
5218   "")
5219
5220 (define_insn_and_split "floatunssidf_ppc64"
5221   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5222         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5223    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5224    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5225    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5226   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5227   "#"
5228   ""
5229   [(set (match_dup 3) (zero_extend:DI (match_dup 1)))
5230    (set (match_dup 2) (match_dup 3))
5231    (set (match_dup 4) (match_dup 2))
5232    (set (match_dup 0) (float:DF (match_dup 4)))]
5233   "")
5234
5235 (define_insn "fix_truncdfdi2"
5236   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
5237         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "f")))]
5238   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5239   "fctidz %0,%1"
5240   [(set_attr "type" "fp")])
5241
5242 (define_expand "floatdisf2"
5243   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5244         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
5245   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5246   "
5247 {
5248   if (!flag_unsafe_math_optimizations)
5249     {
5250       rtx label = gen_label_rtx ();
5251       emit_insn (gen_floatdisf2_internal2 (operands[1], label));
5252       emit_label (label);
5253     }
5254   emit_insn (gen_floatdisf2_internal1 (operands[0], operands[1]));
5255   DONE;
5256 }")
5257
5258 ;; This is not IEEE compliant if rounding mode is "round to nearest".
5259 ;; If the DI->DF conversion is inexact, then it's possible to suffer
5260 ;; from double rounding.
5261 (define_insn_and_split "floatdisf2_internal1"
5262   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5263         (float:SF (match_operand:DI 1 "gpc_reg_operand" "*f")))
5264    (clobber (match_scratch:DF 2 "=f"))]
5265   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5266   "#"
5267   "&& reload_completed"
5268   [(set (match_dup 2)
5269         (float:DF (match_dup 1)))
5270    (set (match_dup 0)
5271         (float_truncate:SF (match_dup 2)))]
5272   "")
5273
5274 ;; Twiddles bits to avoid double rounding.
5275 ;; Bits that might be truncated when converting to DFmode are replaced
5276 ;; by a bit that won't be lost at that stage, but is below the SFmode
5277 ;; rounding position.
5278 (define_expand "floatdisf2_internal2"
5279   [(parallel [(set (match_dup 4)
5280                    (compare:CC (and:DI (match_operand:DI 0 "" "")
5281                                        (const_int 2047))
5282                                (const_int 0)))
5283               (set (match_dup 2) (and:DI (match_dup 0) (const_int 2047)))
5284               (clobber (match_scratch:CC 7 ""))])
5285    (set (match_dup 3) (ashiftrt:DI (match_dup 0) (const_int 53)))
5286    (set (match_dup 3) (plus:DI (match_dup 3) (const_int 1)))
5287    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
5288                            (label_ref (match_operand:DI 1 "" ""))
5289                            (pc)))
5290    (set (match_dup 5) (compare:CCUNS (match_dup 3) (const_int 2)))
5291    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
5292                            (label_ref (match_dup 1))
5293                            (pc)))
5294    (set (match_dup 0) (xor:DI (match_dup 0) (match_dup 2)))
5295    (set (match_dup 0) (ior:DI (match_dup 0) (const_int 2048)))]
5296   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5297   "
5298 {
5299   operands[2] = gen_reg_rtx (DImode);
5300   operands[3] = gen_reg_rtx (DImode);
5301   operands[4] = gen_reg_rtx (CCmode);
5302   operands[5] = gen_reg_rtx (CCUNSmode);
5303 }")
5304 \f
5305 ;; Define the DImode operations that can be done in a small number
5306 ;; of instructions.  The & constraints are to prevent the register
5307 ;; allocator from allocating registers that overlap with the inputs
5308 ;; (for example, having an input in 7,8 and an output in 6,7).  We
5309 ;; also allow for the output being the same as one of the inputs.
5310
5311 (define_insn "*adddi3_noppc64"
5312   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
5313         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
5314                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
5315   "! TARGET_POWERPC64"
5316   "*
5317 {
5318   if (WORDS_BIG_ENDIAN)
5319     return (GET_CODE (operands[2])) != CONST_INT
5320             ? \"{a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2\"
5321             : \"{ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1\";
5322   else
5323     return (GET_CODE (operands[2])) != CONST_INT
5324             ? \"{a|addc} %0,%1,%2\;{ae|adde} %L0,%L1,%L2\"
5325             : \"{ai|addic} %0,%1,%2\;{a%G2e|add%G2e} %L0,%L1\";
5326 }"
5327   [(set_attr "length" "8")])
5328
5329 (define_insn "*subdi3_noppc64"
5330   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
5331         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
5332                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
5333   "! TARGET_POWERPC64"
5334   "*
5335 {
5336   if (WORDS_BIG_ENDIAN)
5337     return (GET_CODE (operands[1]) != CONST_INT)
5338             ? \"{sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1\"
5339             : \"{sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2\";
5340   else
5341     return (GET_CODE (operands[1]) != CONST_INT)
5342             ? \"{sf|subfc} %0,%2,%1\;{sfe|subfe} %L0,%L2,%L1\"
5343             : \"{sfi|subfic} %0,%2,%1\;{sf%G1e|subf%G1e} %L0,%L2\";
5344 }"
5345   [(set_attr "length" "8")])
5346
5347 (define_insn "*negdi2_noppc64"
5348   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5349         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
5350   "! TARGET_POWERPC64"
5351   "*
5352 {
5353   return (WORDS_BIG_ENDIAN)
5354     ? \"{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1\"
5355     : \"{sfi|subfic} %0,%1,0\;{sfze|subfze} %L0,%L1\";
5356 }"
5357   [(set_attr "length" "8")])
5358
5359 (define_expand "mulsidi3"
5360   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5361         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5362                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5363   "! TARGET_POWERPC64"
5364   "
5365 {
5366   if (! TARGET_POWER && ! TARGET_POWERPC)
5367     {
5368       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
5369       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
5370       emit_insn (gen_mull_call ());
5371       if (WORDS_BIG_ENDIAN)
5372         emit_move_insn (operands[0], gen_rtx_REG (DImode, 3));
5373       else
5374         {
5375           emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
5376                           gen_rtx_REG (SImode, 3));
5377           emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
5378                           gen_rtx_REG (SImode, 4));
5379         }
5380       DONE;
5381     }
5382   else if (TARGET_POWER)
5383     {
5384       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
5385       DONE;
5386     }
5387 }")
5388
5389 (define_insn "mulsidi3_mq"
5390   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5391         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5392                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
5393    (clobber (match_scratch:SI 3 "=q"))]
5394   "TARGET_POWER"
5395   "mul %0,%1,%2\;mfmq %L0"
5396   [(set_attr "type" "imul")
5397    (set_attr "length" "8")])
5398
5399 (define_insn "*mulsidi3_no_mq"
5400   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5401         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5402                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
5403   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
5404   "*
5405 {
5406   return (WORDS_BIG_ENDIAN)
5407     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
5408     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
5409 }"
5410   [(set_attr "type" "imul")
5411    (set_attr "length" "8")])
5412
5413 (define_split
5414   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5415         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5416                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5417   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
5418   [(set (match_dup 3)
5419         (truncate:SI
5420          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
5421                                (sign_extend:DI (match_dup 2)))
5422                       (const_int 32))))
5423    (set (match_dup 4)
5424         (mult:SI (match_dup 1)
5425                  (match_dup 2)))]
5426   "
5427 {
5428   int endian = (WORDS_BIG_ENDIAN == 0);
5429   operands[3] = operand_subword (operands[0], endian, 0, DImode);
5430   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
5431 }")
5432
5433 (define_expand "umulsidi3"
5434   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5435         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5436                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5437   "TARGET_POWERPC && ! TARGET_POWERPC64"
5438   "
5439 {
5440   if (TARGET_POWER)
5441     {
5442       emit_insn (gen_umulsidi3_mq (operands[0], operands[1], operands[2]));
5443       DONE;
5444     }
5445 }")
5446
5447 (define_insn "umulsidi3_mq"
5448   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5449         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5450                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
5451    (clobber (match_scratch:SI 3 "=q"))]
5452   "TARGET_POWERPC && TARGET_POWER"
5453   "*
5454 {
5455   return (WORDS_BIG_ENDIAN)
5456     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
5457     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
5458 }"
5459   [(set_attr "type" "imul")
5460    (set_attr "length" "8")])
5461
5462 (define_insn "*umulsidi3_no_mq"
5463   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5464         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5465                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
5466   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
5467   "*
5468 {
5469   return (WORDS_BIG_ENDIAN)
5470     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
5471     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
5472 }"
5473   [(set_attr "type" "imul")
5474    (set_attr "length" "8")])
5475
5476 (define_split
5477   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5478         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5479                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5480   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
5481   [(set (match_dup 3)
5482         (truncate:SI
5483          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
5484                                (zero_extend:DI (match_dup 2)))
5485                       (const_int 32))))
5486    (set (match_dup 4)
5487         (mult:SI (match_dup 1)
5488                  (match_dup 2)))]
5489   "
5490 {
5491   int endian = (WORDS_BIG_ENDIAN == 0);
5492   operands[3] = operand_subword (operands[0], endian, 0, DImode);
5493   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
5494 }")
5495
5496 (define_expand "smulsi3_highpart"
5497   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5498         (truncate:SI
5499          (lshiftrt:DI (mult:DI (sign_extend:DI
5500                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5501                                (sign_extend:DI
5502                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5503                       (const_int 32))))]
5504   ""
5505   "
5506 {
5507   if (! TARGET_POWER && ! TARGET_POWERPC)
5508     {
5509       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
5510       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
5511       emit_insn (gen_mulh_call ());
5512       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
5513       DONE;
5514     }
5515   else if (TARGET_POWER)
5516     {
5517       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
5518       DONE;
5519     }
5520 }")
5521
5522 (define_insn "smulsi3_highpart_mq"
5523   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5524         (truncate:SI
5525          (lshiftrt:DI (mult:DI (sign_extend:DI
5526                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5527                                (sign_extend:DI
5528                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5529                       (const_int 32))))
5530    (clobber (match_scratch:SI 3 "=q"))]
5531   "TARGET_POWER"
5532   "mul %0,%1,%2"
5533   [(set_attr "type" "imul")])
5534
5535 (define_insn "*smulsi3_highpart_no_mq"
5536   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5537         (truncate:SI
5538          (lshiftrt:DI (mult:DI (sign_extend:DI
5539                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5540                                (sign_extend:DI
5541                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5542                       (const_int 32))))]
5543   "TARGET_POWERPC && ! TARGET_POWER"
5544   "mulhw %0,%1,%2"
5545   [(set_attr "type" "imul")])
5546
5547 (define_expand "umulsi3_highpart"
5548   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5549         (truncate:SI
5550          (lshiftrt:DI (mult:DI (zero_extend:DI
5551                                 (match_operand:SI 1 "gpc_reg_operand" ""))
5552                                (zero_extend:DI
5553                                 (match_operand:SI 2 "gpc_reg_operand" "")))
5554                       (const_int 32))))]
5555   "TARGET_POWERPC"
5556   "
5557 {
5558   if (TARGET_POWER)
5559     {
5560       emit_insn (gen_umulsi3_highpart_mq (operands[0], operands[1], operands[2]));
5561       DONE;
5562     }
5563 }")
5564
5565 (define_insn "umulsi3_highpart_mq"
5566   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5567         (truncate:SI
5568          (lshiftrt:DI (mult:DI (zero_extend:DI
5569                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5570                                (zero_extend:DI
5571                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5572                       (const_int 32))))
5573    (clobber (match_scratch:SI 3 "=q"))]
5574   "TARGET_POWERPC && TARGET_POWER"
5575   "mulhwu %0,%1,%2"
5576   [(set_attr "type" "imul")])
5577
5578 (define_insn "*umulsi3_highpart_no_mq"
5579   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5580         (truncate:SI
5581          (lshiftrt:DI (mult:DI (zero_extend:DI
5582                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5583                                (zero_extend:DI
5584                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5585                       (const_int 32))))]
5586   "TARGET_POWERPC && ! TARGET_POWER"
5587   "mulhwu %0,%1,%2"
5588   [(set_attr "type" "imul")])
5589
5590 ;; If operands 0 and 2 are in the same register, we have a problem.  But
5591 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
5592 ;; why we have the strange constraints below.
5593 (define_insn "ashldi3_power"
5594   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
5595         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
5596                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
5597    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
5598   "TARGET_POWER"
5599   "@
5600    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
5601    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
5602    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
5603    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
5604   [(set_attr "length" "8")])
5605
5606 (define_insn "lshrdi3_power"
5607   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
5608         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
5609                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
5610    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
5611   "TARGET_POWER"
5612   "@
5613    {s%A2i|s%A2wi} %L0,%1,%h2\;{cal %0,0(0)|li %0,0}
5614    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
5615    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
5616    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
5617   [(set_attr "length" "8")])
5618
5619 ;; Shift by a variable amount is too complex to be worth open-coding.  We
5620 ;; just handle shifts by constants.
5621 (define_insn "ashrdi3_power"
5622   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5623         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5624                      (match_operand:SI 2 "const_int_operand" "M,i")))
5625    (clobber (match_scratch:SI 3 "=X,q"))]
5626   "TARGET_POWER"
5627   "@
5628    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
5629    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
5630   [(set_attr "length" "8")])
5631
5632 (define_insn "ashrdi3_no_power"
5633   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
5634         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5635                      (match_operand:SI 2 "const_int_operand" "M,i")))]
5636   "TARGET_32BIT && !TARGET_POWER"
5637   "@
5638    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
5639    {sri|srwi} %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;{srai|srawi} %0,%1,%h2"
5640   [(set_attr "length" "8,12")])
5641 \f
5642 ;; PowerPC64 DImode operations.
5643
5644 (define_expand "adddi3"
5645   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5646         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5647                  (match_operand:DI 2 "reg_or_add_cint64_operand" "")))]
5648   ""
5649   "
5650 {
5651   if (! TARGET_POWERPC64)
5652     {
5653       if (non_short_cint_operand (operands[2], DImode))
5654         FAIL;
5655     }
5656   else
5657     if (GET_CODE (operands[2]) == CONST_INT
5658         && ! add_operand (operands[2], DImode))
5659       {
5660         rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
5661                    ? operands[0] : gen_reg_rtx (DImode));
5662
5663         HOST_WIDE_INT val = INTVAL (operands[2]);
5664         HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
5665         HOST_WIDE_INT rest = trunc_int_for_mode (val - low, DImode);
5666
5667         if (!CONST_OK_FOR_LETTER_P (rest, 'L'))
5668           FAIL;
5669
5670         /* The ordering here is important for the prolog expander.
5671            When space is allocated from the stack, adding 'low' first may
5672            produce a temporary deallocation (which would be bad).  */
5673         emit_insn (gen_adddi3 (tmp, operands[1], GEN_INT (rest)));
5674         emit_insn (gen_adddi3 (operands[0], tmp, GEN_INT (low)));
5675         DONE;
5676       }
5677 }")
5678
5679 ;; Discourage ai/addic because of carry but provide it in an alternative
5680 ;; allowing register zero as source.
5681
5682 (define_insn "*adddi3_internal1"
5683   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,?r,r")
5684         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,b,r,b")
5685                  (match_operand:DI 2 "add_operand" "r,I,I,L")))]
5686   "TARGET_POWERPC64"
5687   "@
5688    add %0,%1,%2
5689    addi %0,%1,%2
5690    addic %0,%1,%2
5691    addis %0,%1,%v2")
5692
5693 (define_insn "*adddi3_internal2"
5694   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
5695         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
5696                              (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I"))
5697                     (const_int 0)))
5698    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
5699   "TARGET_POWERPC64"
5700   "@
5701    add. %3,%1,%2
5702    addic. %3,%1,%2
5703    #
5704    #"
5705   [(set_attr "type" "fast_compare,compare,compare,compare")
5706    (set_attr "length" "4,4,8,8")])
5707
5708 (define_split
5709   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5710         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5711                              (match_operand:DI 2 "reg_or_short_operand" ""))
5712                     (const_int 0)))
5713    (clobber (match_scratch:DI 3 ""))]
5714   "TARGET_POWERPC64 && reload_completed"
5715   [(set (match_dup 3)
5716         (plus:DI (match_dup 1) (match_dup 2)))
5717    (set (match_dup 0)
5718         (compare:CC (match_dup 3)
5719                     (const_int 0)))]
5720   "")
5721
5722 (define_insn "*adddi3_internal3"
5723   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
5724         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
5725                              (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I"))
5726                     (const_int 0)))
5727    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
5728         (plus:DI (match_dup 1) (match_dup 2)))]
5729   "TARGET_POWERPC64"
5730   "@
5731    add. %0,%1,%2
5732    addic. %0,%1,%2
5733    #
5734    #"
5735   [(set_attr "type" "fast_compare,compare,compare,compare")
5736    (set_attr "length" "4,4,8,8")])
5737
5738 (define_split
5739   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5740         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5741                              (match_operand:DI 2 "reg_or_short_operand" ""))
5742                     (const_int 0)))
5743    (set (match_operand:DI 0 "gpc_reg_operand" "")
5744         (plus:DI (match_dup 1) (match_dup 2)))]
5745   "TARGET_POWERPC64 && reload_completed"
5746   [(set (match_dup 0)
5747         (plus:DI (match_dup 1) (match_dup 2)))
5748    (set (match_dup 3)
5749         (compare:CC (match_dup 0)
5750                     (const_int 0)))]
5751   "")
5752
5753 ;; Split an add that we can't do in one insn into two insns, each of which
5754 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
5755 ;; add should be last in case the result gets used in an address.
5756
5757 (define_split
5758   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5759         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5760                  (match_operand:DI 2 "non_add_cint_operand" "")))]
5761   "TARGET_POWERPC64"
5762   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 3)))
5763    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 4)))]
5764 "
5765 {
5766   HOST_WIDE_INT val = INTVAL (operands[2]);
5767   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
5768   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, DImode);
5769
5770   operands[4] = GEN_INT (low);
5771   if (CONST_OK_FOR_LETTER_P (rest, 'L'))
5772     operands[3] = GEN_INT (rest);
5773   else if (! no_new_pseudos)
5774     {
5775       operands[3] = gen_reg_rtx (DImode);
5776       emit_move_insn (operands[3], operands[2]);
5777       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
5778       DONE;
5779     }
5780   else
5781     FAIL;
5782 }")
5783
5784 (define_insn "one_cmpldi2"
5785   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5786         (not:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
5787   "TARGET_POWERPC64"
5788   "nor %0,%1,%1")
5789
5790 (define_insn ""
5791   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5792         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
5793                     (const_int 0)))
5794    (clobber (match_scratch:DI 2 "=r,r"))]
5795   "TARGET_POWERPC64"
5796   "@
5797    nor. %2,%1,%1
5798    #"
5799   [(set_attr "type" "compare")
5800    (set_attr "length" "4,8")])
5801
5802 (define_split
5803   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5804         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
5805                     (const_int 0)))
5806    (clobber (match_scratch:DI 2 ""))]
5807   "TARGET_POWERPC64 && reload_completed"
5808   [(set (match_dup 2)
5809         (not:DI (match_dup 1)))
5810    (set (match_dup 0)
5811         (compare:CC (match_dup 2)
5812                     (const_int 0)))]
5813   "")
5814
5815 (define_insn ""
5816   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
5817         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
5818                     (const_int 0)))
5819    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5820         (not:DI (match_dup 1)))]
5821   "TARGET_POWERPC64"
5822   "@
5823    nor. %0,%1,%1
5824    #"
5825   [(set_attr "type" "compare")
5826    (set_attr "length" "4,8")])
5827
5828 (define_split
5829   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
5830         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
5831                     (const_int 0)))
5832    (set (match_operand:DI 0 "gpc_reg_operand" "")
5833         (not:DI (match_dup 1)))]
5834   "TARGET_POWERPC64 && reload_completed"
5835   [(set (match_dup 0)
5836         (not:DI (match_dup 1)))
5837    (set (match_dup 2)
5838         (compare:CC (match_dup 0)
5839                     (const_int 0)))]
5840   "")
5841
5842 (define_insn ""
5843   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5844         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I")
5845                   (match_operand:DI 2 "gpc_reg_operand" "r,r")))]
5846   "TARGET_POWERPC64"
5847   "@
5848    subf %0,%2,%1
5849    subfic %0,%2,%1")
5850
5851 (define_insn ""
5852   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5853         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5854                               (match_operand:DI 2 "gpc_reg_operand" "r,r"))
5855                     (const_int 0)))
5856    (clobber (match_scratch:DI 3 "=r,r"))]
5857   "TARGET_POWERPC64"
5858   "@
5859    subf. %3,%2,%1
5860    #"
5861   [(set_attr "type" "fast_compare")
5862    (set_attr "length" "4,8")])
5863
5864 (define_split
5865   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5866         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5867                               (match_operand:DI 2 "gpc_reg_operand" ""))
5868                     (const_int 0)))
5869    (clobber (match_scratch:DI 3 ""))]
5870   "TARGET_POWERPC64 && reload_completed"
5871   [(set (match_dup 3)
5872         (minus:DI (match_dup 1) (match_dup 2)))
5873    (set (match_dup 0)
5874         (compare:CC (match_dup 3)
5875                     (const_int 0)))]
5876   "")
5877
5878 (define_insn ""
5879   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
5880         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5881                               (match_operand:DI 2 "gpc_reg_operand" "r,r"))
5882                     (const_int 0)))
5883    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5884         (minus:DI (match_dup 1) (match_dup 2)))]
5885   "TARGET_POWERPC64"
5886   "@
5887    subf. %0,%2,%1
5888    #"
5889   [(set_attr "type" "fast_compare")
5890    (set_attr "length" "4,8")])
5891
5892 (define_split
5893   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5894         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5895                               (match_operand:DI 2 "gpc_reg_operand" ""))
5896                     (const_int 0)))
5897    (set (match_operand:DI 0 "gpc_reg_operand" "")
5898         (minus:DI (match_dup 1) (match_dup 2)))]
5899   "TARGET_POWERPC64 && reload_completed"
5900   [(set (match_dup 0)
5901         (minus:DI (match_dup 1) (match_dup 2)))
5902    (set (match_dup 3)
5903         (compare:CC (match_dup 0)
5904                     (const_int 0)))]
5905   "")
5906
5907 (define_expand "subdi3"
5908   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5909         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "")
5910                   (match_operand:DI 2 "reg_or_sub_cint64_operand" "")))]
5911   ""
5912   "
5913 {
5914   if (GET_CODE (operands[2]) == CONST_INT)
5915     {
5916       emit_insn (gen_adddi3 (operands[0], operands[1],
5917                              negate_rtx (DImode, operands[2])));
5918       DONE;
5919     }
5920 }")
5921
5922 (define_insn_and_split "absdi2"
5923   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5924         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
5925    (clobber (match_scratch:DI 2 "=&r,&r"))]
5926   "TARGET_POWERPC64"
5927   "#"
5928   "&& reload_completed"
5929   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
5930    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
5931    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
5932   "")
5933
5934 (define_insn_and_split "*nabsdi2"
5935   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5936         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
5937    (clobber (match_scratch:DI 2 "=&r,&r"))]
5938   "TARGET_POWERPC64"
5939   "#"
5940   "&& reload_completed"
5941   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
5942    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
5943    (set (match_dup 0) (minus:DI (match_dup 2) (match_dup 0)))]
5944   "")
5945
5946 (define_expand "negdi2"
5947   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5948         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "")))]
5949   ""
5950   "")
5951
5952 (define_insn ""
5953   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5954         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
5955   "TARGET_POWERPC64"
5956   "neg %0,%1")
5957
5958 (define_insn ""
5959   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5960         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
5961                     (const_int 0)))
5962    (clobber (match_scratch:DI 2 "=r,r"))]
5963   "TARGET_POWERPC64"
5964   "@
5965    neg. %2,%1
5966    #"
5967   [(set_attr "type" "fast_compare")
5968    (set_attr "length" "4,8")])
5969
5970 (define_split
5971   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5972         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" ""))
5973                     (const_int 0)))
5974    (clobber (match_scratch:DI 2 ""))]
5975   "TARGET_POWERPC64 && reload_completed"
5976   [(set (match_dup 2)
5977         (neg:DI (match_dup 1)))
5978    (set (match_dup 0)
5979         (compare:CC (match_dup 2)
5980                     (const_int 0)))]
5981   "")
5982
5983 (define_insn ""
5984   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
5985         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
5986                     (const_int 0)))
5987    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5988         (neg:DI (match_dup 1)))]
5989   "TARGET_POWERPC64"
5990   "@
5991    neg. %0,%1
5992    #"
5993   [(set_attr "type" "fast_compare")
5994    (set_attr "length" "4,8")])
5995
5996 (define_split
5997   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
5998         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" ""))
5999                     (const_int 0)))
6000    (set (match_operand:DI 0 "gpc_reg_operand" "")
6001         (neg:DI (match_dup 1)))]
6002   "TARGET_POWERPC64 && reload_completed"
6003   [(set (match_dup 0)
6004         (neg:DI (match_dup 1)))
6005    (set (match_dup 2)
6006         (compare:CC (match_dup 0)
6007                     (const_int 0)))]
6008   "")
6009
6010 (define_insn "clzdi2"
6011   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6012         (clz:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
6013   "TARGET_POWERPC64"
6014   "cntlzd %0,%1")
6015
6016 (define_expand "ctzdi2"
6017   [(set (match_dup 2)
6018         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
6019    (parallel [(set (match_dup 3) (and:DI (match_dup 1)      
6020                                          (match_dup 2)))   
6021               (clobber (scratch:CC))])
6022    (set (match_dup 4) (clz:DI (match_dup 3)))
6023    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
6024         (minus:DI (const_int 63) (match_dup 4)))]
6025   "TARGET_POWERPC64"
6026   {
6027      operands[2] = gen_reg_rtx (DImode); 
6028      operands[3] = gen_reg_rtx (DImode);
6029      operands[4] = gen_reg_rtx (DImode);
6030   })
6031
6032 (define_expand "ffsdi2"
6033   [(set (match_dup 2)
6034         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
6035    (parallel [(set (match_dup 3) (and:DI (match_dup 1)      
6036                                          (match_dup 2)))   
6037               (clobber (scratch:CC))])
6038    (set (match_dup 4) (clz:DI (match_dup 3)))
6039    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
6040         (minus:DI (const_int 64) (match_dup 4)))]
6041   "TARGET_POWERPC64"
6042   {
6043      operands[2] = gen_reg_rtx (DImode); 
6044      operands[3] = gen_reg_rtx (DImode);
6045      operands[4] = gen_reg_rtx (DImode);
6046   })
6047
6048 (define_insn "muldi3"
6049   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6050         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
6051                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
6052   "TARGET_POWERPC64"
6053   "mulld %0,%1,%2"
6054    [(set_attr "type" "lmul")])
6055
6056 (define_insn "*muldi3_internal1"
6057   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6058         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6059                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6060                     (const_int 0)))
6061    (clobber (match_scratch:DI 3 "=r,r"))]
6062   "TARGET_POWERPC64"
6063   "@
6064    mulld. %3,%1,%2
6065    #"
6066   [(set_attr "type" "lmul_compare")
6067    (set_attr "length" "4,8")])
6068
6069 (define_split
6070   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6071         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6072                              (match_operand:DI 2 "gpc_reg_operand" ""))
6073                     (const_int 0)))
6074    (clobber (match_scratch:DI 3 ""))]
6075   "TARGET_POWERPC64 && reload_completed"
6076   [(set (match_dup 3)
6077         (mult:DI (match_dup 1) (match_dup 2)))
6078    (set (match_dup 0)
6079         (compare:CC (match_dup 3)
6080                     (const_int 0)))]
6081   "")
6082
6083 (define_insn "*muldi3_internal2"
6084   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6085         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6086                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6087                     (const_int 0)))
6088    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6089         (mult:DI (match_dup 1) (match_dup 2)))]
6090   "TARGET_POWERPC64"
6091   "@
6092    mulld. %0,%1,%2
6093    #"
6094   [(set_attr "type" "lmul_compare")
6095    (set_attr "length" "4,8")])
6096
6097 (define_split
6098   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6099         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6100                              (match_operand:DI 2 "gpc_reg_operand" ""))
6101                     (const_int 0)))
6102    (set (match_operand:DI 0 "gpc_reg_operand" "")
6103         (mult:DI (match_dup 1) (match_dup 2)))]
6104   "TARGET_POWERPC64 && reload_completed"
6105   [(set (match_dup 0)
6106         (mult:DI (match_dup 1) (match_dup 2)))
6107    (set (match_dup 3)
6108         (compare:CC (match_dup 0)
6109                     (const_int 0)))]
6110   "")
6111
6112 (define_insn "smuldi3_highpart"
6113   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6114         (truncate:DI
6115          (lshiftrt:TI (mult:TI (sign_extend:TI
6116                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6117                                (sign_extend:TI
6118                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6119                       (const_int 64))))]
6120   "TARGET_POWERPC64"
6121   "mulhd %0,%1,%2"
6122   [(set_attr "type" "lmul")])
6123
6124 (define_insn "umuldi3_highpart"
6125   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6126         (truncate:DI
6127          (lshiftrt:TI (mult:TI (zero_extend:TI
6128                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6129                                (zero_extend:TI
6130                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6131                       (const_int 64))))]
6132   "TARGET_POWERPC64"
6133   "mulhdu %0,%1,%2"
6134   [(set_attr "type" "lmul")])
6135
6136 (define_expand "divdi3"
6137   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6138         (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6139                 (match_operand:DI 2 "reg_or_cint_operand" "")))]
6140   "TARGET_POWERPC64"
6141   "
6142 {
6143   if (GET_CODE (operands[2]) == CONST_INT
6144       && INTVAL (operands[2]) > 0
6145       && exact_log2 (INTVAL (operands[2])) >= 0)
6146     ;
6147   else
6148     operands[2] = force_reg (DImode, operands[2]);
6149 }")
6150
6151 (define_expand "moddi3"
6152   [(use (match_operand:DI 0 "gpc_reg_operand" ""))
6153    (use (match_operand:DI 1 "gpc_reg_operand" ""))
6154    (use (match_operand:DI 2 "reg_or_cint_operand" ""))]
6155   "TARGET_POWERPC64"
6156   "
6157 {
6158   int i;
6159   rtx temp1;
6160   rtx temp2;
6161
6162   if (GET_CODE (operands[2]) != CONST_INT
6163       || INTVAL (operands[2]) <= 0
6164       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
6165     FAIL;
6166
6167   temp1 = gen_reg_rtx (DImode);
6168   temp2 = gen_reg_rtx (DImode);
6169
6170   emit_insn (gen_divdi3 (temp1, operands[1], operands[2]));
6171   emit_insn (gen_ashldi3 (temp2, temp1, GEN_INT (i)));
6172   emit_insn (gen_subdi3 (operands[0], operands[1], temp2));
6173   DONE;
6174 }")
6175
6176 (define_insn ""
6177   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6178         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6179                 (match_operand:DI 2 "exact_log2_cint_operand" "N")))]
6180   "TARGET_POWERPC64"
6181   "sradi %0,%1,%p2\;addze %0,%0"
6182   [(set_attr "length" "8")])
6183
6184 (define_insn ""
6185   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6186         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6187                             (match_operand:DI 2 "exact_log2_cint_operand" "N,N"))
6188                     (const_int 0)))
6189    (clobber (match_scratch:DI 3 "=r,r"))]
6190   "TARGET_POWERPC64"
6191   "@
6192    sradi %3,%1,%p2\;addze. %3,%3
6193    #"
6194   [(set_attr "type" "compare")
6195    (set_attr "length" "8,12")])
6196
6197 (define_split
6198   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6199         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6200                             (match_operand:DI 2 "exact_log2_cint_operand" ""))
6201                     (const_int 0)))
6202    (clobber (match_scratch:DI 3 ""))]
6203   "TARGET_POWERPC64 && reload_completed"
6204   [(set (match_dup 3)
6205         (div:DI (match_dup 1) (match_dup 2)))
6206    (set (match_dup 0)
6207         (compare:CC (match_dup 3)
6208                     (const_int 0)))]
6209   "")
6210
6211 (define_insn ""
6212   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6213         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6214                             (match_operand:DI 2 "exact_log2_cint_operand" "N,N"))
6215                     (const_int 0)))
6216    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6217         (div:DI (match_dup 1) (match_dup 2)))]
6218   "TARGET_POWERPC64"
6219   "@
6220    sradi %0,%1,%p2\;addze. %0,%0
6221    #"
6222   [(set_attr "type" "compare")
6223    (set_attr "length" "8,12")])
6224
6225 (define_split
6226   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6227         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6228                             (match_operand:DI 2 "exact_log2_cint_operand" ""))
6229                     (const_int 0)))
6230    (set (match_operand:DI 0 "gpc_reg_operand" "")
6231         (div:DI (match_dup 1) (match_dup 2)))]
6232   "TARGET_POWERPC64 && reload_completed"
6233   [(set (match_dup 0)
6234         (div:DI (match_dup 1) (match_dup 2)))
6235    (set (match_dup 3)
6236         (compare:CC (match_dup 0)
6237                     (const_int 0)))]
6238   "")
6239
6240 (define_insn ""
6241   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6242         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6243                 (match_operand:DI 2 "gpc_reg_operand" "r")))]
6244   "TARGET_POWERPC64"
6245   "divd %0,%1,%2"
6246   [(set_attr "type" "ldiv")])
6247
6248 (define_insn "udivdi3"
6249   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6250         (udiv:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6251                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
6252   "TARGET_POWERPC64"
6253   "divdu %0,%1,%2"
6254   [(set_attr "type" "ldiv")])
6255
6256 (define_insn "rotldi3"
6257   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6258         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6259                    (match_operand:DI 2 "reg_or_cint_operand" "ri")))]
6260   "TARGET_POWERPC64"
6261   "rld%I2cl %0,%1,%H2,0")
6262
6263 (define_insn "*rotldi3_internal2"
6264   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6265         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6266                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6267                     (const_int 0)))
6268    (clobber (match_scratch:DI 3 "=r,r"))]
6269   "TARGET_POWERPC64"
6270   "@
6271    rld%I2cl. %3,%1,%H2,0
6272    #"
6273   [(set_attr "type" "delayed_compare")
6274    (set_attr "length" "4,8")])
6275
6276 (define_split
6277   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6278         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6279                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6280                     (const_int 0)))
6281    (clobber (match_scratch:DI 3 ""))]
6282   "TARGET_POWERPC64 && reload_completed"
6283   [(set (match_dup 3)
6284         (rotate:DI (match_dup 1) (match_dup 2)))
6285    (set (match_dup 0)
6286         (compare:CC (match_dup 3)
6287                     (const_int 0)))]
6288   "")
6289
6290 (define_insn "*rotldi3_internal3"
6291   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6292         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6293                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6294                     (const_int 0)))
6295    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6296         (rotate:DI (match_dup 1) (match_dup 2)))]
6297   "TARGET_POWERPC64"
6298   "@
6299    rld%I2cl. %0,%1,%H2,0
6300    #"
6301   [(set_attr "type" "delayed_compare")
6302    (set_attr "length" "4,8")])
6303
6304 (define_split
6305   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6306         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6307                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6308                     (const_int 0)))
6309    (set (match_operand:DI 0 "gpc_reg_operand" "")
6310         (rotate:DI (match_dup 1) (match_dup 2)))]
6311   "TARGET_POWERPC64 && reload_completed"
6312   [(set (match_dup 0)
6313         (rotate:DI (match_dup 1) (match_dup 2)))
6314    (set (match_dup 3)
6315         (compare:CC (match_dup 0)
6316                     (const_int 0)))]
6317   "")
6318
6319 (define_insn "*rotldi3_internal4"
6320   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6321         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6322                            (match_operand:DI 2 "reg_or_cint_operand" "ri"))
6323                 (match_operand:DI 3 "mask64_operand" "n")))]
6324   "TARGET_POWERPC64"
6325   "rld%I2c%B3 %0,%1,%H2,%S3")
6326
6327 (define_insn "*rotldi3_internal5"
6328   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6329         (compare:CC (and:DI
6330                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6331                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6332                      (match_operand:DI 3 "mask64_operand" "n,n"))
6333                     (const_int 0)))
6334    (clobber (match_scratch:DI 4 "=r,r"))]
6335   "TARGET_POWERPC64"
6336   "@
6337    rld%I2c%B3. %4,%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 0 "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    (clobber (match_scratch:DI 4 ""))]
6350   "TARGET_POWERPC64 && reload_completed"
6351   [(set (match_dup 4)
6352         (and:DI (rotate:DI (match_dup 1)
6353                                 (match_dup 2))
6354                      (match_dup 3)))
6355    (set (match_dup 0)
6356         (compare:CC (match_dup 4)
6357                     (const_int 0)))]
6358   "")
6359
6360 (define_insn "*rotldi3_internal6"
6361   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6362         (compare:CC (and:DI
6363                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6364                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6365                      (match_operand:DI 3 "mask64_operand" "n,n"))
6366                     (const_int 0)))
6367    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6368         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6369   "TARGET_POWERPC64"
6370   "@
6371    rld%I2c%B3. %0,%1,%H2,%S3
6372    #"
6373   [(set_attr "type" "delayed_compare")
6374    (set_attr "length" "4,8")])
6375
6376 (define_split
6377   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6378         (compare:CC (and:DI
6379                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6380                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6381                      (match_operand:DI 3 "mask64_operand" ""))
6382                     (const_int 0)))
6383    (set (match_operand:DI 0 "gpc_reg_operand" "")
6384         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6385   "TARGET_POWERPC64 && reload_completed"
6386   [(set (match_dup 0)
6387         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
6388    (set (match_dup 4)
6389         (compare:CC (match_dup 0)
6390                     (const_int 0)))]
6391   "")
6392
6393 (define_insn "*rotldi3_internal7"
6394   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6395         (zero_extend:DI
6396          (subreg:QI
6397           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6398                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6399   "TARGET_POWERPC64"
6400   "rld%I2cl %0,%1,%H2,56")
6401
6402 (define_insn "*rotldi3_internal8"
6403   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6404         (compare:CC (zero_extend:DI
6405                      (subreg:QI
6406                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6407                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6408                     (const_int 0)))
6409    (clobber (match_scratch:DI 3 "=r,r"))]
6410   "TARGET_POWERPC64"
6411   "@
6412    rld%I2cl. %3,%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 0 "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    (clobber (match_scratch:DI 3 ""))]
6425   "TARGET_POWERPC64 && reload_completed"
6426   [(set (match_dup 3)
6427         (zero_extend:DI (subreg:QI
6428                       (rotate:DI (match_dup 1)
6429                                  (match_dup 2)) 0)))
6430    (set (match_dup 0)
6431         (compare:CC (match_dup 3)
6432                     (const_int 0)))]
6433   "")
6434
6435 (define_insn "*rotldi3_internal9"
6436   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6437         (compare:CC (zero_extend:DI
6438                      (subreg:QI
6439                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6440                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6441                     (const_int 0)))
6442    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6443         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6444   "TARGET_POWERPC64"
6445   "@
6446    rld%I2cl. %0,%1,%H2,56
6447    #"
6448   [(set_attr "type" "delayed_compare")
6449    (set_attr "length" "4,8")])
6450
6451 (define_split
6452   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6453         (compare:CC (zero_extend:DI
6454                      (subreg:QI
6455                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6456                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6457                     (const_int 0)))
6458    (set (match_operand:DI 0 "gpc_reg_operand" "")
6459         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6460   "TARGET_POWERPC64 && reload_completed"
6461   [(set (match_dup 0)
6462         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6463    (set (match_dup 3)
6464         (compare:CC (match_dup 0)
6465                     (const_int 0)))]
6466   "")
6467
6468 (define_insn "*rotldi3_internal10"
6469   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6470         (zero_extend:DI
6471          (subreg:HI
6472           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6473                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6474   "TARGET_POWERPC64"
6475   "rld%I2cl %0,%1,%H2,48")
6476
6477 (define_insn "*rotldi3_internal11"
6478   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6479         (compare:CC (zero_extend:DI
6480                      (subreg:HI
6481                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6482                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6483                     (const_int 0)))
6484    (clobber (match_scratch:DI 3 "=r,r"))]
6485   "TARGET_POWERPC64"
6486   "@
6487    rld%I2cl. %3,%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 0 "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    (clobber (match_scratch:DI 3 ""))]
6500   "TARGET_POWERPC64 && reload_completed"
6501   [(set (match_dup 3)
6502         (zero_extend:DI (subreg:HI
6503                       (rotate:DI (match_dup 1)
6504                                  (match_dup 2)) 0)))
6505    (set (match_dup 0)
6506         (compare:CC (match_dup 3)
6507                     (const_int 0)))]
6508   "")
6509
6510 (define_insn "*rotldi3_internal12"
6511   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6512         (compare:CC (zero_extend:DI
6513                      (subreg:HI
6514                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6515                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6516                     (const_int 0)))
6517    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6518         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6519   "TARGET_POWERPC64"
6520   "@
6521    rld%I2cl. %0,%1,%H2,48
6522    #"
6523   [(set_attr "type" "delayed_compare")
6524    (set_attr "length" "4,8")])
6525
6526 (define_split
6527   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6528         (compare:CC (zero_extend:DI
6529                      (subreg:HI
6530                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6531                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6532                     (const_int 0)))
6533    (set (match_operand:DI 0 "gpc_reg_operand" "")
6534         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6535   "TARGET_POWERPC64 && reload_completed"
6536   [(set (match_dup 0)
6537         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6538    (set (match_dup 3)
6539         (compare:CC (match_dup 0)
6540                     (const_int 0)))]
6541   "")
6542
6543 (define_insn "*rotldi3_internal13"
6544   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6545         (zero_extend:DI
6546          (subreg:SI
6547           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6548                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6549   "TARGET_POWERPC64"
6550   "rld%I2cl %0,%1,%H2,32")
6551
6552 (define_insn "*rotldi3_internal14"
6553   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6554         (compare:CC (zero_extend:DI
6555                      (subreg:SI
6556                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6557                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6558                     (const_int 0)))
6559    (clobber (match_scratch:DI 3 "=r,r"))]
6560   "TARGET_POWERPC64"
6561   "@
6562    rld%I2cl. %3,%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 0 "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    (clobber (match_scratch:DI 3 ""))]
6575   "TARGET_POWERPC64 && reload_completed"
6576   [(set (match_dup 3)
6577         (zero_extend:DI (subreg:SI
6578                       (rotate:DI (match_dup 1)
6579                                  (match_dup 2)) 0)))
6580    (set (match_dup 0)
6581         (compare:CC (match_dup 3)
6582                     (const_int 0)))]
6583   "")
6584
6585 (define_insn "*rotldi3_internal15"
6586   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6587         (compare:CC (zero_extend:DI
6588                      (subreg:SI
6589                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6590                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6591                     (const_int 0)))
6592    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6593         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6594   "TARGET_POWERPC64"
6595   "@
6596    rld%I2cl. %0,%1,%H2,32
6597    #"
6598   [(set_attr "type" "delayed_compare")
6599    (set_attr "length" "4,8")])
6600
6601 (define_split
6602   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6603         (compare:CC (zero_extend:DI
6604                      (subreg:SI
6605                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6606                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6607                     (const_int 0)))
6608    (set (match_operand:DI 0 "gpc_reg_operand" "")
6609         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6610   "TARGET_POWERPC64 && reload_completed"
6611   [(set (match_dup 0)
6612         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6613    (set (match_dup 3)
6614         (compare:CC (match_dup 0)
6615                     (const_int 0)))]
6616   "")
6617
6618 (define_expand "ashldi3"
6619   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6620         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6621                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
6622   "TARGET_POWERPC64 || TARGET_POWER"
6623   "
6624 {
6625   if (TARGET_POWERPC64)
6626     ;
6627   else if (TARGET_POWER)
6628     {
6629       emit_insn (gen_ashldi3_power (operands[0], operands[1], operands[2]));
6630       DONE;
6631     }
6632   else
6633     FAIL;
6634 }")
6635
6636 (define_insn "*ashldi3_internal1"
6637   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6638         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6639                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6640   "TARGET_POWERPC64"
6641   "sld%I2 %0,%1,%H2"
6642   [(set_attr "length" "8")])
6643   
6644 (define_insn "*ashldi3_internal2"
6645   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6646         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6647                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6648                     (const_int 0)))
6649    (clobber (match_scratch:DI 3 "=r,r"))]
6650   "TARGET_POWERPC64"
6651   "@
6652    sld%I2. %3,%1,%H2
6653    #"
6654   [(set_attr "type" "delayed_compare")
6655    (set_attr "length" "4,8")])
6656   
6657 (define_split
6658   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6659         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6660                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6661                     (const_int 0)))
6662    (clobber (match_scratch:DI 3 ""))]
6663   "TARGET_POWERPC64 && reload_completed"
6664   [(set (match_dup 3)
6665         (ashift:DI (match_dup 1) (match_dup 2)))
6666    (set (match_dup 0)
6667         (compare:CC (match_dup 3)
6668                     (const_int 0)))]
6669   "")
6670
6671 (define_insn "*ashldi3_internal3"
6672   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6673         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6674                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6675                     (const_int 0)))
6676    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6677         (ashift:DI (match_dup 1) (match_dup 2)))]
6678   "TARGET_POWERPC64"
6679   "@
6680    sld%I2. %0,%1,%H2
6681    #"
6682   [(set_attr "type" "delayed_compare")
6683    (set_attr "length" "4,8")])
6684
6685 (define_split
6686   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6687         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6688                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6689                     (const_int 0)))
6690    (set (match_operand:DI 0 "gpc_reg_operand" "")
6691         (ashift:DI (match_dup 1) (match_dup 2)))]
6692   "TARGET_POWERPC64 && reload_completed"
6693   [(set (match_dup 0)
6694         (ashift:DI (match_dup 1) (match_dup 2)))
6695    (set (match_dup 3)
6696         (compare:CC (match_dup 0)
6697                     (const_int 0)))]
6698   "")
6699
6700 (define_insn "*ashldi3_internal4"
6701   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6702         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6703                            (match_operand:SI 2 "const_int_operand" "i"))
6704                 (match_operand:DI 3 "const_int_operand" "n")))]
6705   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
6706   "rldic %0,%1,%H2,%W3")
6707
6708 (define_insn "ashldi3_internal5"
6709   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6710         (compare:CC
6711          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6712                             (match_operand:SI 2 "const_int_operand" "i,i"))
6713                  (match_operand:DI 3 "const_int_operand" "n,n"))
6714          (const_int 0)))
6715    (clobber (match_scratch:DI 4 "=r,r"))]
6716   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
6717   "@
6718    rldic. %4,%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 0 "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    (clobber (match_scratch:DI 4 ""))]
6731   "TARGET_POWERPC64 && reload_completed
6732    && includes_rldic_lshift_p (operands[2], operands[3])"
6733   [(set (match_dup 4)
6734         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6735                 (match_dup 3)))
6736    (set (match_dup 0)
6737         (compare:CC (match_dup 4)
6738                     (const_int 0)))]
6739   "")
6740
6741 (define_insn "*ashldi3_internal6"
6742   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6743         (compare:CC
6744          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6745                             (match_operand:SI 2 "const_int_operand" "i,i"))
6746                     (match_operand:DI 3 "const_int_operand" "n,n"))
6747          (const_int 0)))
6748    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6749         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6750   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
6751   "@
6752    rldic. %0,%1,%H2,%W3
6753    #"
6754   [(set_attr "type" "delayed_compare")
6755    (set_attr "length" "4,8")])
6756
6757 (define_split
6758   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6759         (compare:CC
6760          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6761                             (match_operand:SI 2 "const_int_operand" ""))
6762                  (match_operand:DI 3 "const_int_operand" ""))
6763          (const_int 0)))
6764    (set (match_operand:DI 0 "gpc_reg_operand" "")
6765         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6766   "TARGET_POWERPC64 && reload_completed
6767    && includes_rldic_lshift_p (operands[2], operands[3])"
6768   [(set (match_dup 0)
6769         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6770                 (match_dup 3)))
6771    (set (match_dup 4)
6772         (compare:CC (match_dup 0)
6773                     (const_int 0)))]
6774   "")
6775
6776 (define_insn "*ashldi3_internal7"
6777   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6778         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6779                            (match_operand:SI 2 "const_int_operand" "i"))
6780                 (match_operand:DI 3 "mask64_operand" "n")))]
6781   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
6782   "rldicr %0,%1,%H2,%S3")
6783
6784 (define_insn "ashldi3_internal8"
6785   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6786         (compare:CC
6787          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6788                             (match_operand:SI 2 "const_int_operand" "i,i"))
6789                  (match_operand:DI 3 "mask64_operand" "n,n"))
6790          (const_int 0)))
6791    (clobber (match_scratch:DI 4 "=r,r"))]
6792   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
6793   "@
6794    rldicr. %4,%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 0 "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    (clobber (match_scratch:DI 4 ""))]
6807   "TARGET_POWERPC64 && reload_completed
6808    && includes_rldicr_lshift_p (operands[2], operands[3])"
6809   [(set (match_dup 4)
6810         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6811                 (match_dup 3)))
6812    (set (match_dup 0)
6813         (compare:CC (match_dup 4)
6814                     (const_int 0)))]
6815   "")
6816
6817 (define_insn "*ashldi3_internal9"
6818   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6819         (compare:CC
6820          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6821                             (match_operand:SI 2 "const_int_operand" "i,i"))
6822                     (match_operand:DI 3 "mask64_operand" "n,n"))
6823          (const_int 0)))
6824    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6825         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6826   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
6827   "@
6828    rldicr. %0,%1,%H2,%S3
6829    #"
6830   [(set_attr "type" "delayed_compare")
6831    (set_attr "length" "4,8")])
6832
6833 (define_split
6834   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6835         (compare:CC
6836          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6837                             (match_operand:SI 2 "const_int_operand" ""))
6838                  (match_operand:DI 3 "mask64_operand" ""))
6839          (const_int 0)))
6840    (set (match_operand:DI 0 "gpc_reg_operand" "")
6841         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6842   "TARGET_POWERPC64 && reload_completed
6843    && includes_rldicr_lshift_p (operands[2], operands[3])"
6844   [(set (match_dup 0)
6845         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6846                 (match_dup 3)))
6847    (set (match_dup 4)
6848         (compare:CC (match_dup 0)
6849                     (const_int 0)))]
6850   "")
6851
6852 (define_expand "lshrdi3"
6853   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6854         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6855                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
6856   "TARGET_POWERPC64 || TARGET_POWER"
6857   "
6858 {
6859   if (TARGET_POWERPC64)
6860     ;
6861   else if (TARGET_POWER)
6862     {
6863       emit_insn (gen_lshrdi3_power (operands[0], operands[1], operands[2]));
6864       DONE;
6865     }
6866   else
6867     FAIL;
6868 }")
6869
6870 (define_insn "*lshrdi3_internal1"
6871   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6872         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6873                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6874   "TARGET_POWERPC64"
6875   "srd%I2 %0,%1,%H2")
6876
6877 (define_insn "*lshrdi3_internal2"
6878   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6879         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6880                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6881                     (const_int 0)))
6882    (clobber (match_scratch:DI 3 "=r,r"))]
6883   "TARGET_POWERPC64"
6884   "@
6885    srd%I2. %3,%1,%H2
6886    #"
6887   [(set_attr "type" "delayed_compare")
6888    (set_attr "length" "4,8")])
6889
6890 (define_split
6891   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6892         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6893                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6894                     (const_int 0)))
6895    (clobber (match_scratch:DI 3 ""))]
6896   "TARGET_POWERPC64 && reload_completed"
6897   [(set (match_dup 3)
6898         (lshiftrt:DI (match_dup 1) (match_dup 2)))
6899    (set (match_dup 0)
6900         (compare:CC (match_dup 3)
6901                     (const_int 0)))]
6902   "")
6903
6904 (define_insn "*lshrdi3_internal3"
6905   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6906         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6907                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6908                     (const_int 0)))
6909    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6910         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
6911   "TARGET_POWERPC64"
6912   "@
6913    srd%I2. %0,%1,%H2
6914    #"
6915   [(set_attr "type" "delayed_compare")
6916    (set_attr "length" "4,8")])
6917
6918 (define_split
6919   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6920         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6921                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6922                     (const_int 0)))
6923    (set (match_operand:DI 0 "gpc_reg_operand" "")
6924         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
6925   "TARGET_POWERPC64 && reload_completed"
6926   [(set (match_dup 0)
6927         (lshiftrt:DI (match_dup 1) (match_dup 2)))
6928    (set (match_dup 3)
6929         (compare:CC (match_dup 0)
6930                     (const_int 0)))]
6931   "")
6932
6933 (define_expand "ashrdi3"
6934   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6935         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6936                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
6937   ""
6938   "
6939 {
6940   if (TARGET_POWERPC64)
6941     ;
6942   else if (TARGET_POWER && GET_CODE (operands[2]) == CONST_INT)
6943     {
6944       emit_insn (gen_ashrdi3_power (operands[0], operands[1], operands[2]));
6945       DONE;
6946     }
6947   else if (TARGET_32BIT && GET_CODE (operands[2]) == CONST_INT)
6948     {
6949       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
6950       DONE;
6951     }
6952   else
6953     FAIL;
6954 }")
6955
6956 (define_insn "*ashrdi3_internal1"
6957   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6958         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6959                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6960   "TARGET_POWERPC64"
6961   "srad%I2 %0,%1,%H2")
6962
6963 (define_insn "*ashrdi3_internal2"
6964   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6965         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6966                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6967                     (const_int 0)))
6968    (clobber (match_scratch:DI 3 "=r,r"))]
6969   "TARGET_POWERPC64"
6970   "@
6971    srad%I2. %3,%1,%H2
6972    #"
6973   [(set_attr "type" "delayed_compare")
6974    (set_attr "length" "4,8")])
6975
6976 (define_split
6977   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6978         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6979                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6980                     (const_int 0)))
6981    (clobber (match_scratch:DI 3 ""))]
6982   "TARGET_POWERPC64 && reload_completed"
6983   [(set (match_dup 3)
6984         (ashiftrt:DI (match_dup 1) (match_dup 2)))
6985    (set (match_dup 0)
6986         (compare:CC (match_dup 3)
6987                     (const_int 0)))]
6988   "")
6989
6990 (define_insn "*ashrdi3_internal3"
6991   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6992         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6993                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6994                     (const_int 0)))
6995    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6996         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
6997   "TARGET_POWERPC64"
6998   "@
6999    srad%I2. %0,%1,%H2
7000    #"
7001   [(set_attr "type" "delayed_compare")
7002    (set_attr "length" "4,8")])
7003
7004 (define_split
7005   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7006         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7007                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7008                     (const_int 0)))
7009    (set (match_operand:DI 0 "gpc_reg_operand" "")
7010         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7011   "TARGET_POWERPC64 && reload_completed"
7012   [(set (match_dup 0)
7013         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7014    (set (match_dup 3)
7015         (compare:CC (match_dup 0)
7016                     (const_int 0)))]
7017   "")
7018
7019 (define_insn "anddi3"
7020   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r")
7021         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r")
7022                 (match_operand:DI 2 "and64_2_operand" "?r,S,K,J,t")))
7023    (clobber (match_scratch:CC 3 "=X,X,x,x,X"))]
7024   "TARGET_POWERPC64"
7025   "@
7026    and %0,%1,%2
7027    rldic%B2 %0,%1,0,%S2
7028    andi. %0,%1,%b2
7029    andis. %0,%1,%u2
7030    #"
7031   [(set_attr "length" "4,4,4,4,8")])
7032
7033 (define_split
7034   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7035         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7036                 (match_operand:DI 2 "mask64_2_operand" "")))
7037    (clobber (match_scratch:CC 3 ""))]
7038   "TARGET_POWERPC64
7039     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7040     && !mask64_operand (operands[2], DImode)"
7041   [(set (match_dup 0)
7042         (and:DI (rotate:DI (match_dup 1)
7043                            (match_dup 4))
7044                 (match_dup 5)))
7045    (set (match_dup 0)
7046         (and:DI (rotate:DI (match_dup 0)
7047                            (match_dup 6))
7048                 (match_dup 7)))]
7049   "
7050 {
7051   build_mask64_2_operands (operands[2], &operands[4]);
7052 }")
7053
7054 (define_insn "*anddi3_internal2"
7055   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,??y,??y,?y")
7056         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
7057                             (match_operand:DI 2 "and64_2_operand" "r,S,K,J,t,r,S,K,J,t"))
7058                     (const_int 0)))
7059    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r"))
7060    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,x,x,X"))]
7061   "TARGET_POWERPC64"
7062   "@
7063    and. %3,%1,%2
7064    rldic%B2. %3,%1,0,%S2
7065    andi. %3,%1,%b2
7066    andis. %3,%1,%u2
7067    #
7068    #
7069    #
7070    #
7071    #
7072    #"
7073   [(set_attr "type" "compare,delayed_compare,compare,compare,delayed_compare,compare,compare,compare,compare,compare")
7074    (set_attr "length" "4,4,4,4,8,8,8,8,8,12")])
7075
7076 (define_split
7077   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7078         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7079                             (match_operand:DI 2 "and64_operand" ""))
7080                     (const_int 0)))
7081    (clobber (match_scratch:DI 3 ""))
7082    (clobber (match_scratch:CC 4 ""))]
7083   "TARGET_POWERPC64 && reload_completed"
7084   [(parallel [(set (match_dup 3)
7085                    (and:DI (match_dup 1)
7086                            (match_dup 2)))
7087               (clobber (match_dup 4))])
7088    (set (match_dup 0)
7089         (compare:CC (match_dup 3)
7090                     (const_int 0)))]
7091   "")
7092
7093 (define_split
7094   [(set (match_operand:CC 0 "cc_reg_operand" "")
7095         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7096                             (match_operand:DI 2 "mask64_2_operand" ""))
7097                     (const_int 0)))
7098    (clobber (match_scratch:DI 3 ""))
7099    (clobber (match_scratch:CC 4 ""))]
7100   "TARGET_POWERPC64 && reload_completed
7101     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7102     && !mask64_operand (operands[2], DImode)"
7103   [(set (match_dup 3)
7104         (and:DI (rotate:DI (match_dup 1)
7105                            (match_dup 5))
7106                 (match_dup 6)))
7107    (parallel [(set (match_dup 0)
7108                    (compare:CC (and:DI (rotate:DI (match_dup 3)
7109                                                   (match_dup 7))
7110                                        (match_dup 8))
7111                                (const_int 0)))
7112               (clobber (match_dup 3))])]
7113   "
7114 {
7115   build_mask64_2_operands (operands[2], &operands[5]);
7116 }")
7117
7118 (define_insn "*anddi3_internal3"
7119   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,?y,?y,??y,??y,?y")
7120         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
7121                             (match_operand:DI 2 "and64_2_operand" "r,S,K,J,t,r,S,K,J,t"))
7122                     (const_int 0)))
7123    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
7124         (and:DI (match_dup 1) (match_dup 2)))
7125    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,x,x,X"))]
7126   "TARGET_POWERPC64"
7127   "@
7128    and. %0,%1,%2
7129    rldic%B2. %0,%1,0,%S2
7130    andi. %0,%1,%b2
7131    andis. %0,%1,%u2
7132    #
7133    #
7134    #
7135    #
7136    #
7137    #"
7138   [(set_attr "type" "compare,delayed_compare,compare,compare,delayed_compare,compare,compare,compare,compare,compare")
7139    (set_attr "length" "4,4,4,4,8,8,8,8,8,12")])
7140
7141 (define_split
7142   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7143         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7144                             (match_operand:DI 2 "and64_operand" ""))
7145                     (const_int 0)))
7146    (set (match_operand:DI 0 "gpc_reg_operand" "")
7147         (and:DI (match_dup 1) (match_dup 2)))
7148    (clobber (match_scratch:CC 4 ""))]
7149   "TARGET_POWERPC64 && reload_completed"
7150   [(parallel [(set (match_dup 0)
7151                     (and:DI (match_dup 1) (match_dup 2)))
7152                (clobber (match_dup 4))])
7153    (set (match_dup 3)
7154         (compare:CC (match_dup 0)
7155                     (const_int 0)))]
7156   "")
7157
7158 (define_split
7159   [(set (match_operand:CC 3 "cc_reg_operand" "")
7160         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7161                             (match_operand:DI 2 "mask64_2_operand" ""))
7162                     (const_int 0)))
7163    (set (match_operand:DI 0 "gpc_reg_operand" "")
7164         (and:DI (match_dup 1) (match_dup 2)))
7165    (clobber (match_scratch:CC 4 ""))]
7166   "TARGET_POWERPC64 && reload_completed
7167     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7168     && !mask64_operand (operands[2], DImode)"
7169   [(set (match_dup 0)
7170         (and:DI (rotate:DI (match_dup 1)
7171                            (match_dup 5))
7172                 (match_dup 6)))
7173    (parallel [(set (match_dup 3)
7174                    (compare:CC (and:DI (rotate:DI (match_dup 0)
7175                                                   (match_dup 7))
7176                                        (match_dup 8))
7177                                (const_int 0)))
7178               (set (match_dup 0)
7179                    (and:DI (rotate:DI (match_dup 0)
7180                                       (match_dup 7))
7181                            (match_dup 8)))])]
7182   "
7183 {
7184   build_mask64_2_operands (operands[2], &operands[5]);
7185 }")
7186
7187 (define_expand "iordi3"
7188   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7189         (ior: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_iordi3 (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_iordi3 (tmp, operands[1],
7210                                  immed_double_const (value
7211                                                      & (~ (HOST_WIDE_INT) 0xffff),
7212                                                      0, DImode)));
7213         }
7214
7215       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7216       DONE;
7217     }
7218 }")
7219
7220 (define_expand "xordi3"
7221   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7222         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
7223                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7224   "TARGET_POWERPC64"
7225   "
7226 {
7227   if (non_logical_cint_operand (operands[2], DImode))
7228     {
7229       HOST_WIDE_INT value;
7230       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7231                  ? operands[0] : gen_reg_rtx (DImode));
7232
7233       if (GET_CODE (operands[2]) == CONST_INT)
7234         {
7235           value = INTVAL (operands[2]);
7236           emit_insn (gen_xordi3 (tmp, operands[1],
7237                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7238         }
7239       else
7240         {
7241           value = CONST_DOUBLE_LOW (operands[2]);
7242           emit_insn (gen_xordi3 (tmp, operands[1],
7243                                  immed_double_const (value
7244                                                      & (~ (HOST_WIDE_INT) 0xffff),
7245                                                      0, DImode)));
7246         }
7247
7248       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7249       DONE;
7250     }
7251 }")
7252
7253 (define_insn "*booldi3_internal1"
7254   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
7255         (match_operator:DI 3 "boolean_or_operator"
7256          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
7257           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
7258   "TARGET_POWERPC64"
7259   "@
7260    %q3 %0,%1,%2
7261    %q3i %0,%1,%b2
7262    %q3is %0,%1,%u2")
7263
7264 (define_insn "*booldi3_internal2"
7265   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7266         (compare:CC (match_operator:DI 4 "boolean_or_operator"
7267          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7268           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7269          (const_int 0)))
7270    (clobber (match_scratch:DI 3 "=r,r"))]
7271   "TARGET_POWERPC64"
7272   "@
7273    %q4. %3,%1,%2
7274    #"
7275   [(set_attr "type" "compare")
7276    (set_attr "length" "4,8")])
7277
7278 (define_split
7279   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7280         (compare:CC (match_operator:DI 4 "boolean_operator"
7281          [(match_operand:DI 1 "gpc_reg_operand" "")
7282           (match_operand:DI 2 "gpc_reg_operand" "")])
7283          (const_int 0)))
7284    (clobber (match_scratch:DI 3 ""))]
7285   "TARGET_POWERPC64 && reload_completed"
7286   [(set (match_dup 3) (match_dup 4))
7287    (set (match_dup 0)
7288         (compare:CC (match_dup 3)
7289                     (const_int 0)))]
7290   "")
7291
7292 (define_insn "*booldi3_internal3"
7293   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7294         (compare:CC (match_operator:DI 4 "boolean_operator"
7295          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7296           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7297          (const_int 0)))
7298    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7299         (match_dup 4))]
7300   "TARGET_POWERPC64"
7301   "@
7302    %q4. %0,%1,%2
7303    #"
7304   [(set_attr "type" "compare")
7305    (set_attr "length" "4,8")])
7306
7307 (define_split
7308   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7309         (compare:CC (match_operator:DI 4 "boolean_operator"
7310          [(match_operand:DI 1 "gpc_reg_operand" "")
7311           (match_operand:DI 2 "gpc_reg_operand" "")])
7312          (const_int 0)))
7313    (set (match_operand:DI 0 "gpc_reg_operand" "")
7314         (match_dup 4))]
7315   "TARGET_POWERPC64 && reload_completed"
7316   [(set (match_dup 0) (match_dup 4))
7317    (set (match_dup 3)
7318         (compare:CC (match_dup 0)
7319                     (const_int 0)))]
7320   "")
7321
7322 ;; Split a logical operation that we can't do in one insn into two insns, 
7323 ;; each of which does one 16-bit part.  This is used by combine.
7324
7325 (define_split
7326   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7327         (match_operator:DI 3 "boolean_or_operator"
7328          [(match_operand:DI 1 "gpc_reg_operand" "")
7329           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
7330   "TARGET_POWERPC64"
7331   [(set (match_dup 0) (match_dup 4))
7332    (set (match_dup 0) (match_dup 5))]
7333 "
7334 {
7335   rtx i3,i4;
7336   
7337   if (GET_CODE (operands[2]) == CONST_DOUBLE)
7338     {
7339       HOST_WIDE_INT value = CONST_DOUBLE_LOW (operands[2]);
7340       i3 = immed_double_const (value & (~ (HOST_WIDE_INT) 0xffff),
7341                                         0, DImode);
7342       i4 = GEN_INT (value & 0xffff);
7343     }
7344   else
7345     {
7346       i3 = GEN_INT (INTVAL (operands[2])
7347                              & (~ (HOST_WIDE_INT) 0xffff));
7348       i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
7349     }
7350   operands[4] = gen_rtx (GET_CODE (operands[3]), DImode,
7351                          operands[1], i3);
7352   operands[5] = gen_rtx (GET_CODE (operands[3]), DImode,
7353                          operands[0], i4);
7354 }")
7355
7356 (define_insn "*boolcdi3_internal1"
7357   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7358         (match_operator:DI 3 "boolean_operator"
7359          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7360           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
7361   "TARGET_POWERPC64"
7362   "%q3 %0,%2,%1")
7363
7364 (define_insn "*boolcdi3_internal2"
7365   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7366         (compare:CC (match_operator:DI 4 "boolean_operator"
7367          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7368           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7369          (const_int 0)))
7370    (clobber (match_scratch:DI 3 "=r,r"))]
7371   "TARGET_POWERPC64"
7372   "@
7373    %q4. %3,%2,%1
7374    #"
7375   [(set_attr "type" "compare")
7376    (set_attr "length" "4,8")])
7377
7378 (define_split
7379   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7380         (compare:CC (match_operator:DI 4 "boolean_operator"
7381          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7382           (match_operand:DI 2 "gpc_reg_operand" "")])
7383          (const_int 0)))
7384    (clobber (match_scratch:DI 3 ""))]
7385   "TARGET_POWERPC64 && reload_completed"
7386   [(set (match_dup 3) (match_dup 4))
7387    (set (match_dup 0)
7388         (compare:CC (match_dup 3)
7389                     (const_int 0)))]
7390   "")
7391
7392 (define_insn "*boolcdi3_internal3"
7393   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7394         (compare:CC (match_operator:DI 4 "boolean_operator"
7395          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7396           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7397          (const_int 0)))
7398    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7399         (match_dup 4))]
7400   "TARGET_POWERPC64"
7401   "@
7402    %q4. %0,%2,%1
7403    #"
7404   [(set_attr "type" "compare")
7405    (set_attr "length" "4,8")])
7406
7407 (define_split
7408   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7409         (compare:CC (match_operator:DI 4 "boolean_operator"
7410          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7411           (match_operand:DI 2 "gpc_reg_operand" "")])
7412          (const_int 0)))
7413    (set (match_operand:DI 0 "gpc_reg_operand" "")
7414         (match_dup 4))]
7415   "TARGET_POWERPC64 && reload_completed"
7416   [(set (match_dup 0) (match_dup 4))
7417    (set (match_dup 3)
7418         (compare:CC (match_dup 0)
7419                     (const_int 0)))]
7420   "")
7421
7422 (define_insn "*boolccdi3_internal1"
7423   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7424         (match_operator:DI 3 "boolean_operator"
7425          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7426           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
7427   "TARGET_POWERPC64"
7428   "%q3 %0,%1,%2")
7429
7430 (define_insn "*boolccdi3_internal2"
7431   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7432         (compare:CC (match_operator:DI 4 "boolean_operator"
7433          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7434           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7435          (const_int 0)))
7436    (clobber (match_scratch:DI 3 "=r,r"))]
7437   "TARGET_POWERPC64"
7438   "@
7439    %q4. %3,%1,%2
7440    #"
7441   [(set_attr "type" "compare")
7442    (set_attr "length" "4,8")])
7443
7444 (define_split
7445   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7446         (compare:CC (match_operator:DI 4 "boolean_operator"
7447          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7448           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7449          (const_int 0)))
7450    (clobber (match_scratch:DI 3 ""))]
7451   "TARGET_POWERPC64 && reload_completed"
7452   [(set (match_dup 3) (match_dup 4))
7453    (set (match_dup 0)
7454         (compare:CC (match_dup 3)
7455                     (const_int 0)))]
7456   "")
7457
7458 (define_insn "*boolccdi3_internal3"
7459   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7460         (compare:CC (match_operator:DI 4 "boolean_operator"
7461          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7462           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7463          (const_int 0)))
7464    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7465         (match_dup 4))]
7466   "TARGET_POWERPC64"
7467   "@
7468    %q4. %0,%1,%2
7469    #"
7470   [(set_attr "type" "compare")
7471    (set_attr "length" "4,8")])
7472
7473 (define_split
7474   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7475         (compare:CC (match_operator:DI 4 "boolean_operator"
7476          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7477           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7478          (const_int 0)))
7479    (set (match_operand:DI 0 "gpc_reg_operand" "")
7480         (match_dup 4))]
7481   "TARGET_POWERPC64 && reload_completed"
7482   [(set (match_dup 0) (match_dup 4))
7483    (set (match_dup 3)
7484         (compare:CC (match_dup 0)
7485                     (const_int 0)))]
7486   "")
7487 \f
7488 ;; Now define ways of moving data around.
7489
7490 ;; Elf specific ways of loading addresses for non-PIC code.
7491 ;; The output of this could be r0, but we make a very strong
7492 ;; preference for a base register because it will usually
7493 ;; be needed there.
7494 (define_insn "elf_high"
7495   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
7496         (high:SI (match_operand 1 "" "")))]
7497   "TARGET_ELF && ! TARGET_64BIT"
7498   "{liu|lis} %0,%1@ha")
7499
7500 (define_insn "elf_low"
7501   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
7502         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
7503                    (match_operand 2 "" "")))]
7504    "TARGET_ELF && ! TARGET_64BIT"
7505    "@
7506     {cal|la} %0,%2@l(%1)
7507     {ai|addic} %0,%1,%K2")
7508
7509 ;; Mach-O PIC trickery.
7510 (define_insn "macho_high"
7511   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
7512         (high:SI (match_operand 1 "" "")))]
7513   "TARGET_MACHO && ! TARGET_64BIT"
7514   "{liu|lis} %0,ha16(%1)")
7515
7516 (define_insn "macho_low"
7517   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
7518         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
7519                    (match_operand 2 "" "")))]
7520    "TARGET_MACHO && ! TARGET_64BIT"
7521    "@
7522     {cal %0,%a2@l(%1)|la %0,lo16(%2)(%1)}
7523     {cal %0,%a2@l(%1)|addic %0,%1,lo16(%2)}")
7524
7525 ;; Set up a register with a value from the GOT table
7526
7527 (define_expand "movsi_got"
7528   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7529         (unspec:SI [(match_operand:SI 1 "got_operand" "")
7530                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
7531   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7532   "
7533 {
7534   if (GET_CODE (operands[1]) == CONST)
7535     {
7536       rtx offset = const0_rtx;
7537       HOST_WIDE_INT value;
7538
7539       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
7540       value = INTVAL (offset);
7541       if (value != 0)
7542         {
7543           rtx tmp = (no_new_pseudos ? operands[0] : gen_reg_rtx (Pmode));
7544           emit_insn (gen_movsi_got (tmp, operands[1]));
7545           emit_insn (gen_addsi3 (operands[0], tmp, offset));
7546           DONE;
7547         }
7548     }
7549
7550   operands[2] = rs6000_got_register (operands[1]);
7551 }")
7552
7553 (define_insn "*movsi_got_internal"
7554   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7555         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7556                     (match_operand:SI 2 "gpc_reg_operand" "b")]
7557                    UNSPEC_MOVSI_GOT))]
7558   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7559   "{l|lwz} %0,%a1@got(%2)"
7560   [(set_attr "type" "load")])
7561
7562 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
7563 ;; didn't get allocated to a hard register.
7564 (define_split 
7565   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7566         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7567                     (match_operand:SI 2 "memory_operand" "")]
7568                    UNSPEC_MOVSI_GOT))]
7569   "DEFAULT_ABI == ABI_V4
7570     && flag_pic == 1
7571     && (reload_in_progress || reload_completed)"
7572   [(set (match_dup 0) (match_dup 2))
7573    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
7574                                  UNSPEC_MOVSI_GOT))]
7575   "")
7576
7577 ;; For SI, we special-case integers that can't be loaded in one insn.  We
7578 ;; do the load 16-bits at a time.  We could do this by loading from memory,
7579 ;; and this is even supposed to be faster, but it is simpler not to get
7580 ;; integers in the TOC.
7581 (define_expand "movsi"
7582   [(set (match_operand:SI 0 "general_operand" "")
7583         (match_operand:SI 1 "any_operand" ""))]
7584   ""
7585   "{ rs6000_emit_move (operands[0], operands[1], SImode); DONE; }")
7586
7587 (define_insn "movsi_low"
7588   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7589         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7590                            (match_operand 2 "" ""))))]
7591   "TARGET_MACHO && ! TARGET_64BIT"
7592   "{l|lwz} %0,lo16(%2)(%1)"
7593   [(set_attr "type" "load")
7594    (set_attr "length" "4")])
7595
7596 (define_insn "movsi_low_st"
7597   [(set (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7598                            (match_operand 2 "" "")))
7599         (match_operand:SI 0 "gpc_reg_operand" "r"))]
7600   "TARGET_MACHO && ! TARGET_64BIT"
7601   "{st|stw} %0,lo16(%2)(%1)"
7602   [(set_attr "type" "store")
7603    (set_attr "length" "4")])
7604
7605 (define_insn "movdf_low"
7606   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,!r")
7607         (mem:DF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
7608                            (match_operand 2 "" ""))))]
7609   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
7610   "*
7611 {
7612   switch (which_alternative)
7613     {
7614       case 0:
7615         return \"lfd %0,lo16(%2)(%1)\";
7616       case 1:
7617         {
7618           rtx operands2[4];
7619           operands2[0] = operands[0];
7620           operands2[1] = operands[1];
7621           operands2[2] = operands[2];
7622           operands2[3] = gen_rtx_REG (SImode, RS6000_PIC_OFFSET_TABLE_REGNUM);
7623           output_asm_insn (\"{l|lwz} %0,lo16(%2)(%1)\", operands);
7624 #if TARGET_MACHO
7625           if (MACHO_DYNAMIC_NO_PIC_P)
7626             output_asm_insn (\"{liu|lis} %L0,ha16(%2+4)\", operands);
7627           else
7628           /* We cannot rely on ha16(low half)==ha16(high half), alas,
7629              although in practice it almost always is.  */
7630           output_asm_insn (\"{cau|addis} %L0,%3,ha16(%2+4)\", operands2);
7631 #endif
7632           return (\"{l|lwz} %L0,lo16(%2+4)(%L0)\");
7633         }
7634       default:
7635         abort();
7636     }
7637 }"
7638   [(set_attr "type" "load")
7639    (set_attr "length" "4,12")])
7640
7641 (define_insn "movdf_low_st"
7642   [(set (mem:DF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7643                            (match_operand 2 "" "")))
7644         (match_operand:DF 0 "gpc_reg_operand" "f"))]
7645   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
7646   "stfd %0,lo16(%2)(%1)"
7647   [(set_attr "type" "store")
7648    (set_attr "length" "4")])
7649
7650 (define_insn "movsf_low"
7651   [(set (match_operand:SF 0 "gpc_reg_operand" "=f,!r")
7652         (mem:SF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
7653                            (match_operand 2 "" ""))))]
7654   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
7655   "@
7656    lfs %0,lo16(%2)(%1)
7657    {l|lwz} %0,lo16(%2)(%1)"
7658   [(set_attr "type" "load")
7659    (set_attr "length" "4")])
7660
7661 (define_insn "movsf_low_st"
7662   [(set (mem:SF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
7663                            (match_operand 2 "" "")))
7664         (match_operand:SF 0 "gpc_reg_operand" "f,!r"))]
7665   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
7666   "@
7667    stfs %0,lo16(%2)(%1)
7668    {st|stw} %0,lo16(%2)(%1)"
7669   [(set_attr "type" "store")
7670    (set_attr "length" "4")])
7671
7672 (define_insn "*movsi_internal1"
7673   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h")
7674         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0"))]
7675   "gpc_reg_operand (operands[0], SImode)
7676    || gpc_reg_operand (operands[1], SImode)"
7677   "@
7678    mr %0,%1
7679    {cal|la} %0,%a1
7680    {l%U1%X1|lwz%U1%X1} %0,%1
7681    {st%U0%X0|stw%U0%X0} %1,%0
7682    {lil|li} %0,%1
7683    {liu|lis} %0,%v1
7684    #
7685    {cal|la} %0,%a1
7686    mf%1 %0
7687    mt%0 %1
7688    mt%0 %1
7689    mt%0 %1
7690    {cror 0,0,0|nop}"
7691   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*")
7692    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
7693
7694 ;; Split a load of a large constant into the appropriate two-insn
7695 ;; sequence.
7696
7697 (define_split
7698   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7699         (match_operand:SI 1 "const_int_operand" ""))]
7700   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
7701    && (INTVAL (operands[1]) & 0xffff) != 0"
7702   [(set (match_dup 0)
7703         (match_dup 2))
7704    (set (match_dup 0)
7705         (ior:SI (match_dup 0)
7706                 (match_dup 3)))]
7707   "
7708 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
7709
7710   if (tem == operands[0])
7711     DONE;
7712   else
7713     FAIL;
7714 }")
7715
7716 (define_insn "*movsi_internal2"
7717   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
7718         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "0,r,r")
7719                     (const_int 0)))
7720    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
7721   "! TARGET_POWERPC64"
7722   "@
7723    {cmpi|cmpwi} %2,%0,0
7724    mr. %0,%1
7725    #"
7726   [(set_attr "type" "cmp,compare,cmp")
7727    (set_attr "length" "4,4,8")])
7728
7729 (define_split
7730   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
7731         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
7732                     (const_int 0)))
7733    (set (match_operand:SI 0 "gpc_reg_operand" "") (match_dup 1))]
7734   "! TARGET_POWERPC64 && reload_completed"
7735   [(set (match_dup 0) (match_dup 1))
7736    (set (match_dup 2)
7737         (compare:CC (match_dup 0)
7738                     (const_int 0)))]
7739   "")
7740 \f
7741 (define_expand "movhi"
7742   [(set (match_operand:HI 0 "general_operand" "")
7743         (match_operand:HI 1 "any_operand" ""))]
7744   ""
7745   "{ rs6000_emit_move (operands[0], operands[1], HImode); DONE; }")
7746
7747 (define_insn "*movhi_internal"
7748   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7749         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7750   "gpc_reg_operand (operands[0], HImode)
7751    || gpc_reg_operand (operands[1], HImode)"
7752   "@
7753    mr %0,%1
7754    lhz%U1%X1 %0,%1
7755    sth%U0%X0 %1,%0
7756    {lil|li} %0,%w1
7757    mf%1 %0
7758    mt%0 %1
7759    mt%0 %1
7760    {cror 0,0,0|nop}"
7761   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7762
7763 (define_expand "movqi"
7764   [(set (match_operand:QI 0 "general_operand" "")
7765         (match_operand:QI 1 "any_operand" ""))]
7766   ""
7767   "{ rs6000_emit_move (operands[0], operands[1], QImode); DONE; }")
7768
7769 (define_insn "*movqi_internal"
7770   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7771         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7772   "gpc_reg_operand (operands[0], QImode)
7773    || gpc_reg_operand (operands[1], QImode)"
7774   "@
7775    mr %0,%1
7776    lbz%U1%X1 %0,%1
7777    stb%U0%X0 %1,%0
7778    {lil|li} %0,%1
7779    mf%1 %0
7780    mt%0 %1
7781    mt%0 %1
7782    {cror 0,0,0|nop}"
7783   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7784 \f
7785 ;; Here is how to move condition codes around.  When we store CC data in
7786 ;; an integer register or memory, we store just the high-order 4 bits.
7787 ;; This lets us not shift in the most common case of CR0.
7788 (define_expand "movcc"
7789   [(set (match_operand:CC 0 "nonimmediate_operand" "")
7790         (match_operand:CC 1 "nonimmediate_operand" ""))]
7791   ""
7792   "")
7793
7794 (define_insn "*movcc_internal1"
7795   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,r,r,r,r,q,cl,r,m")
7796         (match_operand:CC 1 "nonimmediate_operand" "y,r,r,x,y,r,h,r,r,m,r"))]
7797   "register_operand (operands[0], CCmode)
7798    || register_operand (operands[1], CCmode)"
7799   "@
7800    mcrf %0,%1
7801    mtcrf 128,%1
7802    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
7803    mfcr %0%Q1
7804    mfcr %0%Q1\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
7805    mr %0,%1
7806    mf%1 %0
7807    mt%0 %1
7808    mt%0 %1
7809    {l%U1%X1|lwz%U1%X1} %0,%1
7810    {st%U0%U1|stw%U0%U1} %1,%0"
7811   [(set (attr "type")
7812      (cond [(eq_attr "alternative" "0")
7813                 (const_string "cr_logical")
7814             (eq_attr "alternative" "1,2")
7815                 (const_string "mtcr")
7816             (eq_attr "alternative" "5,7")
7817                 (const_string "integer")
7818             (eq_attr "alternative" "6")
7819                 (const_string "mfjmpr")
7820             (eq_attr "alternative" "8")
7821                 (const_string "mtjmpr")
7822             (eq_attr "alternative" "9")
7823                 (const_string "load")
7824             (eq_attr "alternative" "10")
7825                 (const_string "store")
7826             (ne (symbol_ref "TARGET_MFCRF") (const_int 0))
7827                 (const_string "mfcrf")
7828            ]
7829         (const_string "mfcr")))
7830    (set_attr "length" "4,4,12,4,8,4,4,4,4,4,4")])
7831 \f
7832 ;; For floating-point, we normally deal with the floating-point registers
7833 ;; unless -msoft-float is used.  The sole exception is that parameter passing
7834 ;; can produce floating-point values in fixed-point registers.  Unless the
7835 ;; value is a simple constant or already in memory, we deal with this by
7836 ;; allocating memory and copying the value explicitly via that memory location.
7837 (define_expand "movsf"
7838   [(set (match_operand:SF 0 "nonimmediate_operand" "")
7839         (match_operand:SF 1 "any_operand" ""))]
7840   ""
7841   "{ rs6000_emit_move (operands[0], operands[1], SFmode); DONE; }")
7842
7843 (define_split
7844   [(set (match_operand:SF 0 "gpc_reg_operand" "")
7845         (match_operand:SF 1 "const_double_operand" ""))]
7846   "reload_completed
7847    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7848        || (GET_CODE (operands[0]) == SUBREG
7849            && GET_CODE (SUBREG_REG (operands[0])) == REG
7850            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7851   [(set (match_dup 2) (match_dup 3))]
7852   "
7853 {
7854   long l;
7855   REAL_VALUE_TYPE rv;
7856
7857   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7858   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
7859
7860   if (! TARGET_POWERPC64)
7861     operands[2] = operand_subword (operands[0], 0, 0, SFmode);
7862   else
7863     operands[2] = gen_lowpart (SImode, operands[0]);
7864
7865   operands[3] = gen_int_mode (l, SImode);
7866 }")
7867
7868 (define_insn "*movsf_hardfloat"
7869   [(set (match_operand:SF 0 "nonimmediate_operand" "=!r,!r,m,f,f,m,!cl,!q,!r,!r,!r")
7870         (match_operand:SF 1 "input_operand" "r,m,r,f,m,f,r,r,h,G,Fn"))]
7871   "(gpc_reg_operand (operands[0], SFmode)
7872    || gpc_reg_operand (operands[1], SFmode))
7873    && (TARGET_HARD_FLOAT && TARGET_FPRS)"
7874   "@
7875    mr %0,%1
7876    {l%U1%X1|lwz%U1%X1} %0,%1
7877    {st%U0%X0|stw%U0%X0} %1,%0
7878    fmr %0,%1
7879    lfs%U1%X1 %0,%1
7880    stfs%U0%X0 %1,%0
7881    mt%0 %1
7882    mt%0 %1
7883    mf%1 %0
7884    #
7885    #"
7886   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,mtjmpr,*,*,*")
7887    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8")])
7888
7889 (define_insn "*movsf_softfloat"
7890   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,cl,q,r,r,m,r,r,r,r,r,*h")
7891         (match_operand:SF 1 "input_operand" "r,r,r,h,m,r,I,L,R,G,Fn,0"))]
7892   "(gpc_reg_operand (operands[0], SFmode)
7893    || gpc_reg_operand (operands[1], SFmode))
7894    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
7895   "@
7896    mr %0,%1
7897    mt%0 %1
7898    mt%0 %1
7899    mf%1 %0
7900    {l%U1%X1|lwz%U1%X1} %0,%1
7901    {st%U0%X0|stw%U0%X0} %1,%0
7902    {lil|li} %0,%1
7903    {liu|lis} %0,%v1
7904    {cal|la} %0,%a1
7905    #
7906    #
7907    {cror 0,0,0|nop}"
7908   [(set_attr "type" "*,mtjmpr,*,*,load,store,*,*,*,*,*,*")
7909    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,4")])
7910
7911 \f
7912 (define_expand "movdf"
7913   [(set (match_operand:DF 0 "nonimmediate_operand" "")
7914         (match_operand:DF 1 "any_operand" ""))]
7915   ""
7916   "{ rs6000_emit_move (operands[0], operands[1], DFmode); DONE; }")
7917
7918 (define_split
7919   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7920         (match_operand:DF 1 "const_int_operand" ""))]
7921   "! TARGET_POWERPC64 && reload_completed
7922    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7923        || (GET_CODE (operands[0]) == SUBREG
7924            && GET_CODE (SUBREG_REG (operands[0])) == REG
7925            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7926   [(set (match_dup 2) (match_dup 4))
7927    (set (match_dup 3) (match_dup 1))]
7928   "
7929 {
7930   int endian = (WORDS_BIG_ENDIAN == 0);
7931   HOST_WIDE_INT value = INTVAL (operands[1]);
7932
7933   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
7934   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
7935 #if HOST_BITS_PER_WIDE_INT == 32
7936   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
7937 #else
7938   operands[4] = GEN_INT (value >> 32);
7939   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
7940 #endif
7941 }")
7942
7943 (define_split
7944   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7945         (match_operand:DF 1 "const_double_operand" ""))]
7946   "! TARGET_POWERPC64 && reload_completed
7947    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7948        || (GET_CODE (operands[0]) == SUBREG
7949            && GET_CODE (SUBREG_REG (operands[0])) == REG
7950            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7951   [(set (match_dup 2) (match_dup 4))
7952    (set (match_dup 3) (match_dup 5))]
7953   "
7954 {
7955   int endian = (WORDS_BIG_ENDIAN == 0);
7956   long l[2];
7957   REAL_VALUE_TYPE rv;
7958
7959   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7960   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
7961
7962   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
7963   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
7964   operands[4] = gen_int_mode (l[endian], SImode);
7965   operands[5] = gen_int_mode (l[1 - endian], SImode);
7966 }")
7967
7968 (define_split
7969   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7970         (match_operand:DF 1 "easy_fp_constant" ""))]
7971   "TARGET_POWERPC64 && reload_completed
7972    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7973        || (GET_CODE (operands[0]) == SUBREG
7974            && GET_CODE (SUBREG_REG (operands[0])) == REG
7975            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7976   [(set (match_dup 2) (match_dup 3))]
7977   "
7978 {
7979   int endian = (WORDS_BIG_ENDIAN == 0);
7980   long l[2];
7981   REAL_VALUE_TYPE rv;
7982 #if HOST_BITS_PER_WIDE_INT >= 64
7983   HOST_WIDE_INT val;
7984 #endif
7985
7986   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7987   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
7988
7989   operands[2] = gen_lowpart (DImode, operands[0]);
7990   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
7991 #if HOST_BITS_PER_WIDE_INT >= 64
7992   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
7993          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
7994
7995   operands[3] = gen_int_mode (val, DImode);
7996 #else
7997   operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
7998 #endif
7999 }")
8000
8001 ;; Don't have reload use general registers to load a constant.  First,
8002 ;; it might not work if the output operand is the equivalent of
8003 ;; a non-offsettable memref, but also it is less efficient than loading
8004 ;; the constant into an FP register, since it will probably be used there.
8005 ;; The "??" is a kludge until we can figure out a more reasonable way
8006 ;; of handling these non-offsettable values.
8007 (define_insn "*movdf_hardfloat32"
8008   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,m,f,f,m,!r,!r,!r")
8009         (match_operand:DF 1 "input_operand" "r,m,r,f,m,f,G,H,F"))]
8010   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8011    && (gpc_reg_operand (operands[0], DFmode)
8012        || gpc_reg_operand (operands[1], DFmode))"
8013   "*
8014 {
8015   switch (which_alternative)
8016     {
8017     default:
8018       abort ();
8019     case 0:
8020       /* We normally copy the low-numbered register first.  However, if
8021          the first register operand 0 is the same as the second register
8022          of operand 1, we must copy in the opposite order.  */
8023       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8024         return \"mr %L0,%L1\;mr %0,%1\";
8025       else
8026         return \"mr %0,%1\;mr %L0,%L1\";
8027     case 1:
8028       if (offsettable_memref_p (operands[1])
8029           || (GET_CODE (operands[1]) == MEM
8030               && (GET_CODE (XEXP (operands[1], 0)) == LO_SUM
8031                   || GET_CODE (XEXP (operands[1], 0)) == PRE_INC
8032                   || GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)))
8033         {
8034           /* If the low-address word is used in the address, we must load
8035              it last.  Otherwise, load it first.  Note that we cannot have
8036              auto-increment in that case since the address register is
8037              known to be dead.  */
8038           if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8039                                  operands[1], 0))
8040             return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8041           else
8042             return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8043         }
8044       else
8045         {
8046           rtx addreg;
8047
8048           addreg = find_addr_reg (XEXP (operands[1], 0));
8049           if (refers_to_regno_p (REGNO (operands[0]),
8050                                  REGNO (operands[0]) + 1,
8051                                  operands[1], 0))
8052             {
8053               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8054               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
8055               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8056               return \"{lx|lwzx} %0,%1\";
8057             }
8058           else
8059             {
8060               output_asm_insn (\"{lx|lwzx} %0,%1\", operands);
8061               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8062               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
8063               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8064               return \"\";
8065             }
8066         }
8067     case 2:
8068       if (offsettable_memref_p (operands[0])
8069           || (GET_CODE (operands[0]) == MEM
8070               && (GET_CODE (XEXP (operands[0], 0)) == LO_SUM
8071                   || GET_CODE (XEXP (operands[0], 0)) == PRE_INC
8072                   || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)))
8073         return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8074       else
8075         {
8076           rtx addreg;
8077
8078           addreg = find_addr_reg (XEXP (operands[0], 0));
8079           output_asm_insn (\"{stx|stwx} %1,%0\", operands);
8080           output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8081           output_asm_insn (\"{stx|stwx} %L1,%0\", operands);
8082           output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8083           return \"\";
8084         }
8085     case 3:
8086       return \"fmr %0,%1\";
8087     case 4:
8088       return \"lfd%U1%X1 %0,%1\";
8089     case 5:
8090       return \"stfd%U0%X0 %1,%0\";
8091     case 6:
8092     case 7:
8093     case 8:
8094       return \"#\";
8095     }
8096 }"
8097   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,*,*")
8098    (set_attr "length" "8,16,16,4,4,4,8,12,16")])
8099
8100 (define_insn "*movdf_softfloat32"
8101   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
8102         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F"))]
8103   "! TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8104    && (gpc_reg_operand (operands[0], DFmode)
8105        || gpc_reg_operand (operands[1], DFmode))"
8106   "*
8107 {
8108   switch (which_alternative)
8109     {
8110     default:
8111       abort ();
8112     case 0:
8113       /* We normally copy the low-numbered register first.  However, if
8114          the first register operand 0 is the same as the second register of
8115          operand 1, we must copy in the opposite order.  */
8116       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8117         return \"mr %L0,%L1\;mr %0,%1\";
8118       else
8119         return \"mr %0,%1\;mr %L0,%L1\";
8120     case 1:
8121       /* If the low-address word is used in the address, we must load
8122          it last.  Otherwise, load it first.  Note that we cannot have
8123          auto-increment in that case since the address register is
8124          known to be dead.  */
8125       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8126                              operands[1], 0))
8127         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8128       else
8129         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8130     case 2:
8131       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8132     case 3:
8133     case 4:
8134     case 5:
8135       return \"#\";
8136     }
8137 }"
8138   [(set_attr "type" "*,load,store,*,*,*")
8139    (set_attr "length" "8,8,8,8,12,16")])
8140
8141 (define_insn "*movdf_hardfloat64"
8142   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,m,f,f,m,!cl,!r,!r,!r,!r")
8143         (match_operand:DF 1 "input_operand" "r,m,r,f,m,f,r,h,G,H,F"))]
8144   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8145    && (gpc_reg_operand (operands[0], DFmode)
8146        || gpc_reg_operand (operands[1], DFmode))"
8147   "@
8148    mr %0,%1
8149    ld%U1%X1 %0,%1
8150    std%U0%X0 %1,%0
8151    fmr %0,%1
8152    lfd%U1%X1 %0,%1
8153    stfd%U0%X0 %1,%0
8154    mt%0 %1
8155    mf%1 %0
8156    #
8157    #
8158    #"
8159   [(set_attr "type" "*,load,store,fp,fpload,fpstore,mtjmpr,*,*,*,*")
8160    (set_attr "length" "4,4,4,4,4,4,4,4,8,12,16")])
8161
8162 (define_insn "*movdf_softfloat64"
8163   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,cl,r,r,m,r,r,r")
8164         (match_operand:DF 1 "input_operand" "r,r,h,m,r,G,H,F"))]
8165   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8166    && (gpc_reg_operand (operands[0], DFmode)
8167        || gpc_reg_operand (operands[1], DFmode))"
8168   "@
8169    mr %0,%1
8170    mt%0 %1
8171    mf%1 %0
8172    ld%U1%X1 %0,%1
8173    std%U0%X0 %1,%0
8174    #
8175    #
8176    #"
8177   [(set_attr "type" "*,*,*,load,store,*,*,*")
8178    (set_attr "length" "4,4,4,4,4,8,12,16")])
8179 \f
8180 (define_expand "movtf"
8181   [(set (match_operand:TF 0 "general_operand" "")
8182         (match_operand:TF 1 "any_operand" ""))]
8183   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8184    && TARGET_LONG_DOUBLE_128"
8185   "{ rs6000_emit_move (operands[0], operands[1], TFmode); DONE; }")
8186
8187 (define_insn "*movtf_internal"
8188   [(set (match_operand:TF 0 "nonimmediate_operand" "=f,f,m,!r,!r,!r")
8189         (match_operand:TF 1 "input_operand" "f,m,f,G,H,F"))]
8190   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8191    && TARGET_LONG_DOUBLE_128
8192    && (gpc_reg_operand (operands[0], TFmode)
8193        || gpc_reg_operand (operands[1], TFmode))"
8194   "*
8195 {
8196   switch (which_alternative)
8197     {
8198     default:
8199       abort ();
8200     case 0:
8201       /* We normally copy the low-numbered register first.  However, if
8202          the first register operand 0 is the same as the second register of
8203          operand 1, we must copy in the opposite order.  */
8204       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8205         return \"fmr %L0,%L1\;fmr %0,%1\";
8206       else
8207         return \"fmr %0,%1\;fmr %L0,%L1\";
8208     case 1:
8209       return \"lfd %0,%1\;lfd %L0,%Y1\";
8210     case 2:
8211       return \"stfd %1,%0\;stfd %L1,%Y0\";
8212     case 3:
8213     case 4:
8214     case 5:
8215       return \"#\";
8216     }
8217 }"
8218   [(set_attr "type" "fp,fpload,fpstore,*,*,*")
8219    (set_attr "length" "8,8,8,12,16,20")])
8220
8221 (define_split
8222   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8223         (match_operand:TF 1 "easy_fp_constant" ""))]
8224   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8225    && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_POWERPC64
8226    && TARGET_LONG_DOUBLE_128 && reload_completed
8227    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8228        || (GET_CODE (operands[0]) == SUBREG
8229            && GET_CODE (SUBREG_REG (operands[0])) == REG
8230            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8231   [(set (match_dup 2) (match_dup 6))
8232    (set (match_dup 3) (match_dup 7))
8233    (set (match_dup 4) (match_dup 8))
8234    (set (match_dup 5) (match_dup 9))]
8235   "
8236 {
8237   long l[4];
8238   REAL_VALUE_TYPE rv;
8239
8240   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8241   REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, l);
8242
8243   operands[2] = operand_subword (operands[0], 0, 0, TFmode);
8244   operands[3] = operand_subword (operands[0], 1, 0, TFmode);
8245   operands[4] = operand_subword (operands[0], 2, 0, TFmode);
8246   operands[5] = operand_subword (operands[0], 3, 0, TFmode);
8247   operands[6] = gen_int_mode (l[0], SImode);
8248   operands[7] = gen_int_mode (l[1], SImode);
8249   operands[8] = gen_int_mode (l[2], SImode);
8250   operands[9] = gen_int_mode (l[3], SImode);
8251 }")
8252
8253 (define_split
8254   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8255         (match_operand:TF 1 "easy_fp_constant" ""))]
8256   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8257    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_POWERPC64
8258    && TARGET_LONG_DOUBLE_128 && reload_completed
8259    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8260        || (GET_CODE (operands[0]) == SUBREG
8261            && GET_CODE (SUBREG_REG (operands[0])) == REG
8262            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8263   [(set (match_dup 2) (match_dup 4))
8264    (set (match_dup 3) (match_dup 5))]
8265   "
8266 {
8267   long l[4];
8268   REAL_VALUE_TYPE rv;
8269 #if HOST_BITS_PER_WIDE_INT >= 64
8270   HOST_WIDE_INT val;
8271 #endif
8272
8273   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8274   REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, l);
8275
8276   operands[2] = gen_lowpart (DImode, operands[0]);
8277   operands[3] = gen_highpart (DImode, operands[0]);
8278 #if HOST_BITS_PER_WIDE_INT >= 64
8279   val = ((HOST_WIDE_INT)(unsigned long)l[0] << 32
8280          | ((HOST_WIDE_INT)(unsigned long)l[1]));
8281   operands[4] = gen_int_mode (val, DImode);
8282
8283   val = ((HOST_WIDE_INT)(unsigned long)l[2] << 32
8284          | ((HOST_WIDE_INT)(unsigned long)l[3]));
8285   operands[5] = gen_int_mode (val, DImode);
8286 #else
8287   operands[4] = immed_double_const (l[1], l[0], DImode);
8288   operands[5] = immed_double_const (l[3], l[2], DImode);
8289 #endif
8290 }")
8291
8292 (define_insn "extenddftf2"
8293   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8294         (float_extend:TF (match_operand:DF 1 "gpc_reg_operand" "f")))]
8295   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8296    && TARGET_LONG_DOUBLE_128"
8297   "*
8298 {
8299   if (REGNO (operands[0]) == REGNO (operands[1]))
8300     return \"fsub %L0,%L0,%L0\";
8301   else
8302     return \"fmr %0,%1\;fsub %L0,%L0,%L0\";
8303 }"
8304   [(set_attr "type" "fp")])
8305
8306 (define_insn "extendsftf2"
8307   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8308         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "f")))]
8309   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8310    && TARGET_LONG_DOUBLE_128"
8311   "*
8312 {
8313   if (REGNO (operands[0]) == REGNO (operands[1]))
8314     return \"fsub %L0,%L0,%L0\";
8315   else
8316     return \"fmr %0,%1\;fsub %L0,%L0,%L0\";
8317 }"
8318   [(set_attr "type" "fp")])
8319
8320 (define_insn "trunctfdf2"
8321   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8322         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8323   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8324    && TARGET_LONG_DOUBLE_128"
8325   "fadd %0,%1,%L1"
8326   [(set_attr "type" "fp")
8327    (set_attr "length" "8")])
8328
8329 (define_insn_and_split "trunctfsf2"
8330   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
8331         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "f")))
8332    (clobber (match_scratch:DF 2 "=f"))]
8333   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT
8334    && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8335   "#"
8336   "&& reload_completed"
8337   [(set (match_dup 2)
8338         (float_truncate:DF (match_dup 1)))
8339    (set (match_dup 0)
8340         (float_truncate:SF (match_dup 2)))]
8341   "")
8342
8343 (define_insn_and_split "floatditf2"
8344   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8345         (float:TF (match_operand:DI 1 "gpc_reg_operand" "*f")))
8346    (clobber (match_scratch:DF 2 "=f"))]
8347   "DEFAULT_ABI == ABI_AIX && TARGET_POWERPC64
8348    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8349   "#"
8350   "&& reload_completed"
8351   [(set (match_dup 2)
8352         (float:DF (match_dup 1)))
8353    (set (match_dup 0)
8354         (float_extend:TF (match_dup 2)))]
8355   "")
8356
8357 (define_insn_and_split "floatsitf2"
8358   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8359         (float:TF (match_operand:SI 1 "gpc_reg_operand" "r")))
8360    (clobber (match_scratch:DF 2 "=f"))]
8361   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8362    && TARGET_LONG_DOUBLE_128"
8363   "#"
8364   "&& reload_completed"
8365   [(set (match_dup 2)
8366         (float:DF (match_dup 1)))
8367    (set (match_dup 0)
8368         (float_extend:TF (match_dup 2)))]
8369   "")
8370
8371 (define_insn_and_split "fix_trunctfdi2"
8372   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
8373         (fix:DI (match_operand:TF 1 "gpc_reg_operand" "f")))
8374    (clobber (match_scratch:DF 2 "=f"))]
8375   "DEFAULT_ABI == ABI_AIX && TARGET_POWERPC64
8376    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8377   "#"
8378   "&& reload_completed"
8379   [(set (match_dup 2)
8380         (float_truncate:DF (match_dup 1)))
8381    (set (match_dup 0)
8382         (fix:DI (match_dup 2)))]
8383   "")
8384
8385 (define_insn_and_split "fix_trunctfsi2"
8386   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8387         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "f")))
8388    (clobber (match_scratch:DF 2 "=f"))]
8389   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8390    && TARGET_LONG_DOUBLE_128"
8391   "#"
8392   "&& reload_completed"
8393   [(set (match_dup 2)
8394         (float_truncate:DF (match_dup 1)))
8395    (set (match_dup 0)
8396         (fix:SI (match_dup 2)))]
8397   "")
8398
8399 (define_insn "negtf2"
8400   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8401         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8402   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8403    && TARGET_LONG_DOUBLE_128"
8404   "*
8405 {
8406   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8407     return \"fneg %L0,%L1\;fneg %0,%1\";
8408   else
8409     return \"fneg %0,%1\;fneg %L0,%L1\";
8410 }"
8411   [(set_attr "type" "fp")
8412    (set_attr "length" "8")])
8413
8414 (define_insn "abstf2"
8415   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8416         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8417   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8418    && TARGET_LONG_DOUBLE_128"
8419   "*
8420 {
8421   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8422     return \"fabs %L0,%L1\;fabs %0,%1\";
8423   else
8424     return \"fabs %0,%1\;fabs %L0,%L1\";
8425 }"
8426   [(set_attr "type" "fp")
8427    (set_attr "length" "8")])
8428
8429 (define_insn ""
8430   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8431         (neg:TF (abs:TF (match_operand:TF 1 "gpc_reg_operand" "f"))))]
8432   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8433    && TARGET_LONG_DOUBLE_128"
8434   "*
8435 {
8436   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8437     return \"fnabs %L0,%L1\;fnabs %0,%1\";
8438   else
8439     return \"fnabs %0,%1\;fnabs %L0,%L1\";
8440 }"
8441   [(set_attr "type" "fp")
8442    (set_attr "length" "8")])
8443 \f
8444 ;; Next come the multi-word integer load and store and the load and store
8445 ;; multiple insns.
8446 (define_expand "movdi"
8447   [(set (match_operand:DI 0 "general_operand" "")
8448         (match_operand:DI 1 "any_operand" ""))]
8449   ""
8450   "{ rs6000_emit_move (operands[0], operands[1], DImode); DONE; }")
8451
8452 (define_insn "*movdi_internal32"
8453   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,f,f,m,r,r,r,r,r")
8454         (match_operand:DI 1 "input_operand" "r,m,r,f,m,f,IJK,n,G,H,F"))]
8455   "! TARGET_POWERPC64
8456    && (gpc_reg_operand (operands[0], DImode)
8457        || gpc_reg_operand (operands[1], DImode))"
8458   "*
8459 {
8460   switch (which_alternative)
8461     {
8462     default:
8463       abort ();
8464     case 0:
8465     case 1:
8466     case 2:
8467       return \"#\";
8468     case 3:
8469       return \"fmr %0,%1\";
8470     case 4:
8471       return \"lfd%U1%X1 %0,%1\";
8472     case 5:
8473       return \"stfd%U0%X0 %1,%0\";
8474     case 6:
8475     case 7:
8476     case 8:
8477     case 9:
8478     case 10:
8479       return \"#\";
8480     }
8481 }"
8482   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,*,*,*,*")])
8483
8484 (define_split
8485   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8486         (match_operand:DI 1 "const_int_operand" ""))]
8487   "! TARGET_POWERPC64 && reload_completed"
8488   [(set (match_dup 2) (match_dup 4))
8489    (set (match_dup 3) (match_dup 1))]
8490   "
8491 {
8492   HOST_WIDE_INT value = INTVAL (operands[1]);
8493   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8494                                        DImode);
8495   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8496                                        DImode);
8497 #if HOST_BITS_PER_WIDE_INT == 32
8498   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8499 #else
8500   operands[4] = GEN_INT (value >> 32);
8501   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8502 #endif
8503 }")
8504
8505 (define_split
8506   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8507         (match_operand:DI 1 "const_double_operand" ""))]
8508   "HOST_BITS_PER_WIDE_INT == 32 && ! TARGET_POWERPC64 && reload_completed"
8509   [(set (match_dup 2) (match_dup 4))
8510    (set (match_dup 3) (match_dup 5))]
8511   "
8512 {
8513   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8514                                        DImode);
8515   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8516                                        DImode);
8517   operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
8518   operands[5] = GEN_INT (CONST_DOUBLE_LOW  (operands[1]));
8519 }")
8520
8521 (define_split
8522   [(set (match_operand:DI 0 "nonimmediate_operand" "")
8523         (match_operand:DI 1 "input_operand" ""))]
8524   "reload_completed && !TARGET_POWERPC64 
8525    && gpr_or_gpr_p (operands[0], operands[1])"
8526   [(set (match_dup 2) (match_dup 4))
8527    (set (match_dup 3) (match_dup 5))]
8528 "{
8529      rs6000_split_multireg_move (operands);
8530 }")
8531
8532 (define_split
8533   [(set (match_operand:TI 0 "gpc_reg_operand" "")
8534         (match_operand:TI 1 "const_double_operand" ""))]
8535   "TARGET_POWERPC64"
8536   [(set (match_dup 2) (match_dup 4))
8537    (set (match_dup 3) (match_dup 5))]
8538   "
8539 {
8540   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8541                                        TImode);
8542   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8543                                        TImode);
8544   if (GET_CODE (operands[1]) == CONST_DOUBLE)
8545     {
8546       operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
8547       operands[5] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
8548     }
8549   else if (GET_CODE (operands[1]) == CONST_INT)
8550     {
8551       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
8552       operands[5] = operands[1];
8553     }
8554   else
8555     FAIL;
8556 }")
8557
8558 (define_insn "*movdi_internal64"
8559   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,?f,f,m,r,*h,*h")
8560         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,f,m,f,*h,r,0"))]
8561   "TARGET_POWERPC64
8562    && (gpc_reg_operand (operands[0], DImode)
8563        || gpc_reg_operand (operands[1], DImode))"
8564   "@
8565    mr %0,%1
8566    ld%U1%X1 %0,%1
8567    std%U0%X0 %1,%0
8568    li %0,%1
8569    lis %0,%v1
8570    #
8571    {cal|la} %0,%a1
8572    fmr %0,%1
8573    lfd%U1%X1 %0,%1
8574    stfd%U0%X0 %1,%0
8575    mf%1 %0
8576    mt%0 %1
8577    {cror 0,0,0|nop}"
8578   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*")
8579    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4")])
8580
8581 ;; immediate value valid for a single instruction hiding in a const_double
8582 (define_insn ""
8583   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8584         (match_operand:DI 1 "const_double_operand" "F"))]
8585   "HOST_BITS_PER_WIDE_INT == 32 && TARGET_POWERPC64
8586    && GET_CODE (operands[1]) == CONST_DOUBLE
8587    && num_insns_constant (operands[1], DImode) == 1"
8588   "*
8589 {
8590   return ((unsigned HOST_WIDE_INT)
8591           (CONST_DOUBLE_LOW (operands[1]) + 0x8000) < 0x10000)
8592          ? \"li %0,%1\" : \"lis %0,%v1\";
8593 }")
8594
8595 ;; Generate all one-bits and clear left or right.
8596 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
8597 (define_split
8598   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8599         (match_operand:DI 1 "mask64_operand" ""))]
8600   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8601   [(set (match_dup 0) (const_int -1))
8602    (set (match_dup 0)
8603         (and:DI (rotate:DI (match_dup 0)
8604                            (const_int 0))
8605                 (match_dup 1)))]
8606   "")
8607
8608 ;; Split a load of a large constant into the appropriate five-instruction
8609 ;; sequence.  Handle anything in a constant number of insns.
8610 ;; When non-easy constants can go in the TOC, this should use
8611 ;; easy_fp_constant predicate.
8612 (define_split
8613   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8614         (match_operand:DI 1 "const_int_operand" ""))]
8615   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8616   [(set (match_dup 0) (match_dup 2))
8617    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8618   "
8619 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8620
8621   if (tem == operands[0])
8622     DONE;
8623   else
8624     FAIL;
8625 }")
8626
8627 (define_split
8628   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8629         (match_operand:DI 1 "const_double_operand" ""))]
8630   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8631   [(set (match_dup 0) (match_dup 2))
8632    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8633   "
8634 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8635
8636   if (tem == operands[0])
8637     DONE;
8638   else
8639     FAIL;
8640 }")
8641
8642 (define_insn "*movdi_internal2"
8643   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
8644         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "0,r,r")
8645                     (const_int 0)))
8646    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
8647   "TARGET_POWERPC64"
8648   "@
8649    cmpdi %2,%0,0
8650    mr. %0,%1
8651    #"
8652   [(set_attr "type" "cmp,compare,cmp")
8653    (set_attr "length" "4,4,8")])
8654
8655 (define_split
8656   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
8657         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "")
8658                     (const_int 0)))
8659    (set (match_operand:DI 0 "gpc_reg_operand" "") (match_dup 1))]
8660   "TARGET_POWERPC64 && reload_completed"
8661   [(set (match_dup 0) (match_dup 1))
8662    (set (match_dup 2)
8663         (compare:CC (match_dup 0)
8664                     (const_int 0)))]
8665   "")
8666 \f
8667 ;; TImode is similar, except that we usually want to compute the address into
8668 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
8669 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
8670 (define_expand "movti"
8671   [(parallel [(set (match_operand:TI 0 "general_operand" "")
8672                    (match_operand:TI 1 "general_operand" ""))
8673               (clobber (scratch:SI))])]
8674   ""
8675   "{ rs6000_emit_move (operands[0], operands[1], TImode); DONE; }")
8676
8677 ;; We say that MQ is clobbered in the last alternative because the first
8678 ;; alternative would never get used otherwise since it would need a reload
8679 ;; while the 2nd alternative would not.  We put memory cases first so they
8680 ;; are preferred.  Otherwise, we'd try to reload the output instead of
8681 ;; giving the SCRATCH mq.
8682
8683 (define_insn "*movti_power"
8684   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r")
8685         (match_operand:TI 1 "reg_or_mem_operand" "r,r,r,Q,m"))
8686    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X"))]
8687   "TARGET_POWER && ! TARGET_POWERPC64
8688    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8689   "*
8690 {
8691   switch (which_alternative)
8692     {
8693     default:
8694       abort ();
8695
8696     case 0:
8697       if (TARGET_STRING)
8698         return \"{stsi|stswi} %1,%P0,16\";
8699     case 1:
8700     case 2:
8701       return \"#\";
8702     case 3:
8703       /* If the address is not used in the output, we can use lsi.  Otherwise,
8704          fall through to generating four loads.  */
8705       if (TARGET_STRING
8706           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8707         return \"{lsi|lswi} %0,%P1,16\";
8708       /* ... fall through ...  */
8709     case 4:
8710       return \"#\";
8711     }
8712 }"
8713   [(set_attr "type" "store,store,*,load,load")])
8714
8715 (define_insn "*movti_string"
8716   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r")
8717         (match_operand:TI 1 "reg_or_mem_operand" "r,r,r,Q,m"))]
8718   "! TARGET_POWER && ! TARGET_POWERPC64
8719    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8720   "*
8721 {
8722   switch (which_alternative)
8723     {
8724     default:
8725       abort ();
8726     case 0:
8727       if (TARGET_STRING)
8728         return \"{stsi|stswi} %1,%P0,16\";
8729     case 1:
8730     case 2:
8731       return \"#\";
8732     case 3:
8733       /* If the address is not used in the output, we can use lsi.  Otherwise,
8734          fall through to generating four loads.  */
8735       if (TARGET_STRING  
8736           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8737         return \"{lsi|lswi} %0,%P1,16\";
8738       /* ... fall through ...  */
8739     case 4:
8740       return \"#\";
8741     }
8742 }"
8743   [(set_attr "type" "store,store,*,load,load")])
8744
8745 (define_insn "*movti_ppc64"
8746   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,m,r")
8747         (match_operand:TI 1 "input_operand" "r,r,o"))]
8748   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
8749    || gpc_reg_operand (operands[1], TImode))"
8750   "@
8751    #    
8752    #    
8753    #"
8754   [(set_attr "type" "*,load,store")])
8755
8756 (define_split
8757   [(set (match_operand:TI 0 "nonimmediate_operand" "")
8758         (match_operand:TI 1 "input_operand" ""))]
8759   "reload_completed && TARGET_POWERPC64 
8760    && gpr_or_gpr_p (operands[0], operands[1])"
8761   [(set (match_dup 2) (match_dup 4))
8762    (set (match_dup 3) (match_dup 5))]
8763 "{
8764      rs6000_split_multireg_move (operands);
8765 }")
8766
8767 (define_split
8768   [(set (match_operand:TI 0 "nonimmediate_operand" "")
8769         (match_operand:TI 1 "input_operand" ""))]
8770   "reload_completed && !TARGET_POWERPC64 
8771    && gpr_or_gpr_p (operands[0], operands[1])"
8772   [(set (match_dup 2) (match_dup 6))
8773    (set (match_dup 3) (match_dup 7))
8774    (set (match_dup 4) (match_dup 8))
8775    (set (match_dup 5) (match_dup 9))]
8776 "{
8777      rs6000_split_multireg_move (operands);
8778 }")
8779
8780
8781 \f
8782 (define_expand "load_multiple"
8783   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8784                           (match_operand:SI 1 "" ""))
8785                      (use (match_operand:SI 2 "" ""))])]
8786   "TARGET_STRING && !TARGET_POWERPC64"
8787   "
8788 {
8789   int regno;
8790   int count;
8791   rtx op1;
8792   int i;
8793
8794   /* Support only loading a constant number of fixed-point registers from
8795      memory and only bother with this if more than two; the machine
8796      doesn't support more than eight.  */
8797   if (GET_CODE (operands[2]) != CONST_INT
8798       || INTVAL (operands[2]) <= 2
8799       || INTVAL (operands[2]) > 8
8800       || GET_CODE (operands[1]) != MEM
8801       || GET_CODE (operands[0]) != REG
8802       || REGNO (operands[0]) >= 32)
8803     FAIL;
8804
8805   count = INTVAL (operands[2]);
8806   regno = REGNO (operands[0]);
8807
8808   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
8809   op1 = replace_equiv_address (operands[1],
8810                                force_reg (SImode, XEXP (operands[1], 0)));
8811
8812   for (i = 0; i < count; i++)
8813     XVECEXP (operands[3], 0, i)
8814       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
8815                      adjust_address_nv (op1, SImode, i * 4));
8816 }")
8817
8818 (define_insn "*ldmsi8"
8819   [(match_parallel 0 "load_multiple_operation"
8820     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8821           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8822      (set (match_operand:SI 3 "gpc_reg_operand" "")
8823           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8824      (set (match_operand:SI 4 "gpc_reg_operand" "")
8825           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8826      (set (match_operand:SI 5 "gpc_reg_operand" "")
8827           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8828      (set (match_operand:SI 6 "gpc_reg_operand" "")
8829           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8830      (set (match_operand:SI 7 "gpc_reg_operand" "")
8831           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8832      (set (match_operand:SI 8 "gpc_reg_operand" "")
8833           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
8834      (set (match_operand:SI 9 "gpc_reg_operand" "")
8835           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
8836   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
8837   "*
8838 { return rs6000_output_load_multiple (operands); }"
8839   [(set_attr "type" "load")
8840    (set_attr "length" "32")])
8841
8842 (define_insn "*ldmsi7"
8843   [(match_parallel 0 "load_multiple_operation"
8844     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8845           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8846      (set (match_operand:SI 3 "gpc_reg_operand" "")
8847           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8848      (set (match_operand:SI 4 "gpc_reg_operand" "")
8849           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8850      (set (match_operand:SI 5 "gpc_reg_operand" "")
8851           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8852      (set (match_operand:SI 6 "gpc_reg_operand" "")
8853           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8854      (set (match_operand:SI 7 "gpc_reg_operand" "")
8855           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8856      (set (match_operand:SI 8 "gpc_reg_operand" "")
8857           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
8858   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
8859   "*
8860 { return rs6000_output_load_multiple (operands); }"
8861   [(set_attr "type" "load")
8862    (set_attr "length" "32")])
8863
8864 (define_insn "*ldmsi6"
8865   [(match_parallel 0 "load_multiple_operation"
8866     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8867           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8868      (set (match_operand:SI 3 "gpc_reg_operand" "")
8869           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8870      (set (match_operand:SI 4 "gpc_reg_operand" "")
8871           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8872      (set (match_operand:SI 5 "gpc_reg_operand" "")
8873           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8874      (set (match_operand:SI 6 "gpc_reg_operand" "")
8875           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8876      (set (match_operand:SI 7 "gpc_reg_operand" "")
8877           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
8878   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
8879   "*
8880 { return rs6000_output_load_multiple (operands); }"
8881   [(set_attr "type" "load")
8882    (set_attr "length" "32")])
8883
8884 (define_insn "*ldmsi5"
8885   [(match_parallel 0 "load_multiple_operation"
8886     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8887           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8888      (set (match_operand:SI 3 "gpc_reg_operand" "")
8889           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8890      (set (match_operand:SI 4 "gpc_reg_operand" "")
8891           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8892      (set (match_operand:SI 5 "gpc_reg_operand" "")
8893           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8894      (set (match_operand:SI 6 "gpc_reg_operand" "")
8895           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
8896   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
8897   "*
8898 { return rs6000_output_load_multiple (operands); }"
8899   [(set_attr "type" "load")
8900    (set_attr "length" "32")])
8901
8902 (define_insn "*ldmsi4"
8903   [(match_parallel 0 "load_multiple_operation"
8904     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8905           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8906      (set (match_operand:SI 3 "gpc_reg_operand" "")
8907           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8908      (set (match_operand:SI 4 "gpc_reg_operand" "")
8909           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8910      (set (match_operand:SI 5 "gpc_reg_operand" "")
8911           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
8912   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
8913   "*
8914 { return rs6000_output_load_multiple (operands); }"
8915   [(set_attr "type" "load")
8916    (set_attr "length" "32")])
8917
8918 (define_insn "*ldmsi3"
8919   [(match_parallel 0 "load_multiple_operation"
8920     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8921           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8922      (set (match_operand:SI 3 "gpc_reg_operand" "")
8923           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8924      (set (match_operand:SI 4 "gpc_reg_operand" "")
8925           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
8926   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
8927   "*
8928 { return rs6000_output_load_multiple (operands); }"
8929   [(set_attr "type" "load")
8930    (set_attr "length" "32")])
8931
8932 (define_expand "store_multiple"
8933   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8934                           (match_operand:SI 1 "" ""))
8935                      (clobber (scratch:SI))
8936                      (use (match_operand:SI 2 "" ""))])]
8937   "TARGET_STRING && !TARGET_POWERPC64"
8938   "
8939 {
8940   int regno;
8941   int count;
8942   rtx to;
8943   rtx op0;
8944   int i;
8945
8946   /* Support only storing a constant number of fixed-point registers to
8947      memory and only bother with this if more than two; the machine
8948      doesn't support more than eight.  */
8949   if (GET_CODE (operands[2]) != CONST_INT
8950       || INTVAL (operands[2]) <= 2
8951       || INTVAL (operands[2]) > 8
8952       || GET_CODE (operands[0]) != MEM
8953       || GET_CODE (operands[1]) != REG
8954       || REGNO (operands[1]) >= 32)
8955     FAIL;
8956
8957   count = INTVAL (operands[2]);
8958   regno = REGNO (operands[1]);
8959
8960   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
8961   to = force_reg (SImode, XEXP (operands[0], 0));
8962   op0 = replace_equiv_address (operands[0], to);
8963
8964   XVECEXP (operands[3], 0, 0)
8965     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
8966   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
8967                                                  gen_rtx_SCRATCH (SImode));
8968
8969   for (i = 1; i < count; i++)
8970     XVECEXP (operands[3], 0, i + 1)
8971       = gen_rtx_SET (VOIDmode,
8972                      adjust_address_nv (op0, SImode, i * 4),
8973                      gen_rtx_REG (SImode, regno + i));
8974 }")
8975
8976 (define_insn "*store_multiple_power"
8977   [(match_parallel 0 "store_multiple_operation"
8978                    [(set (match_operand:SI 1 "indirect_operand" "=Q")
8979                          (match_operand:SI 2 "gpc_reg_operand" "r"))
8980                     (clobber (match_scratch:SI 3 "=q"))])]
8981   "TARGET_STRING && TARGET_POWER"
8982   "{stsi|stswi} %2,%P1,%O0"
8983   [(set_attr "type" "store")])
8984
8985 (define_insn "*stmsi8"
8986   [(match_parallel 0 "store_multiple_operation"
8987     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8988           (match_operand:SI 2 "gpc_reg_operand" "r"))
8989      (clobber (match_scratch:SI 3 "X"))
8990      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8991           (match_operand:SI 4 "gpc_reg_operand" "r"))
8992      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8993           (match_operand:SI 5 "gpc_reg_operand" "r"))
8994      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8995           (match_operand:SI 6 "gpc_reg_operand" "r"))
8996      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8997           (match_operand:SI 7 "gpc_reg_operand" "r"))
8998      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8999           (match_operand:SI 8 "gpc_reg_operand" "r"))
9000      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9001           (match_operand:SI 9 "gpc_reg_operand" "r"))
9002      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
9003           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
9004   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 9"
9005   "{stsi|stswi} %2,%1,%O0"
9006   [(set_attr "type" "store")])
9007
9008 (define_insn "*stmsi7"
9009   [(match_parallel 0 "store_multiple_operation"
9010     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9011           (match_operand:SI 2 "gpc_reg_operand" "r"))
9012      (clobber (match_scratch:SI 3 "X"))
9013      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9014           (match_operand:SI 4 "gpc_reg_operand" "r"))
9015      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9016           (match_operand:SI 5 "gpc_reg_operand" "r"))
9017      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9018           (match_operand:SI 6 "gpc_reg_operand" "r"))
9019      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9020           (match_operand:SI 7 "gpc_reg_operand" "r"))
9021      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9022           (match_operand:SI 8 "gpc_reg_operand" "r"))
9023      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9024           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
9025   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 8"
9026   "{stsi|stswi} %2,%1,%O0"
9027   [(set_attr "type" "store")])
9028
9029 (define_insn "*stmsi6"
9030   [(match_parallel 0 "store_multiple_operation"
9031     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9032           (match_operand:SI 2 "gpc_reg_operand" "r"))
9033      (clobber (match_scratch:SI 3 "X"))
9034      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9035           (match_operand:SI 4 "gpc_reg_operand" "r"))
9036      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9037           (match_operand:SI 5 "gpc_reg_operand" "r"))
9038      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9039           (match_operand:SI 6 "gpc_reg_operand" "r"))
9040      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9041           (match_operand:SI 7 "gpc_reg_operand" "r"))
9042      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9043           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
9044   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 7"
9045   "{stsi|stswi} %2,%1,%O0"
9046   [(set_attr "type" "store")])
9047
9048 (define_insn "*stmsi5"
9049   [(match_parallel 0 "store_multiple_operation"
9050     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9051           (match_operand:SI 2 "gpc_reg_operand" "r"))
9052      (clobber (match_scratch:SI 3 "X"))
9053      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9054           (match_operand:SI 4 "gpc_reg_operand" "r"))
9055      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9056           (match_operand:SI 5 "gpc_reg_operand" "r"))
9057      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9058           (match_operand:SI 6 "gpc_reg_operand" "r"))
9059      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9060           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
9061   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 6"
9062   "{stsi|stswi} %2,%1,%O0"
9063   [(set_attr "type" "store")])
9064
9065 (define_insn "*stmsi4"
9066   [(match_parallel 0 "store_multiple_operation"
9067     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9068           (match_operand:SI 2 "gpc_reg_operand" "r"))
9069      (clobber (match_scratch:SI 3 "X"))
9070      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9071           (match_operand:SI 4 "gpc_reg_operand" "r"))
9072      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9073           (match_operand:SI 5 "gpc_reg_operand" "r"))
9074      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9075           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
9076   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 5"
9077   "{stsi|stswi} %2,%1,%O0"
9078   [(set_attr "type" "store")])
9079
9080 (define_insn "*stmsi3"
9081   [(match_parallel 0 "store_multiple_operation"
9082     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9083           (match_operand:SI 2 "gpc_reg_operand" "r"))
9084      (clobber (match_scratch:SI 3 "X"))
9085      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9086           (match_operand:SI 4 "gpc_reg_operand" "r"))
9087      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9088           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
9089   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 4"
9090   "{stsi|stswi} %2,%1,%O0"
9091   [(set_attr "type" "store")])
9092 \f
9093 ;; String/block move insn.
9094 ;; Argument 0 is the destination
9095 ;; Argument 1 is the source
9096 ;; Argument 2 is the length
9097 ;; Argument 3 is the alignment
9098
9099 (define_expand "movstrsi"
9100   [(parallel [(set (match_operand:BLK 0 "" "")
9101                    (match_operand:BLK 1 "" ""))
9102               (use (match_operand:SI 2 "" ""))
9103               (use (match_operand:SI 3 "" ""))])]
9104   ""
9105   "
9106 {
9107   if (expand_block_move (operands))
9108     DONE;
9109   else
9110     FAIL;
9111 }")
9112
9113 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
9114 ;; register allocator doesn't have a clue about allocating 8 word registers.
9115 ;; rD/rS = r5 is preferred, efficient form.
9116 (define_expand "movstrsi_8reg"
9117   [(parallel [(set (match_operand 0 "" "")
9118                    (match_operand 1 "" ""))
9119               (use (match_operand 2 "" ""))
9120               (use (match_operand 3 "" ""))
9121               (clobber (reg:SI  5))
9122               (clobber (reg:SI  6))
9123               (clobber (reg:SI  7))
9124               (clobber (reg:SI  8))
9125               (clobber (reg:SI  9))
9126               (clobber (reg:SI 10))
9127               (clobber (reg:SI 11))
9128               (clobber (reg:SI 12))
9129               (clobber (match_scratch:SI 4 ""))])]
9130   "TARGET_STRING"
9131   "")
9132
9133 (define_insn ""
9134   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9135         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9136    (use (match_operand:SI 2 "immediate_operand" "i"))
9137    (use (match_operand:SI 3 "immediate_operand" "i"))
9138    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9139    (clobber (reg:SI  6))
9140    (clobber (reg:SI  7))
9141    (clobber (reg:SI  8))
9142    (clobber (reg:SI  9))
9143    (clobber (reg:SI 10))
9144    (clobber (reg:SI 11))
9145    (clobber (reg:SI 12))
9146    (clobber (match_scratch:SI 5 "=q"))]
9147   "TARGET_STRING && TARGET_POWER
9148    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9149        || INTVAL (operands[2]) == 0)
9150    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9151    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9152    && REGNO (operands[4]) == 5"
9153   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9154   [(set_attr "type" "load")
9155    (set_attr "length" "8")])
9156
9157 (define_insn ""
9158   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9159         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9160    (use (match_operand:SI 2 "immediate_operand" "i"))
9161    (use (match_operand:SI 3 "immediate_operand" "i"))
9162    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9163    (clobber (reg:SI  6))
9164    (clobber (reg:SI  7))
9165    (clobber (reg:SI  8))
9166    (clobber (reg:SI  9))
9167    (clobber (reg:SI 10))
9168    (clobber (reg:SI 11))
9169    (clobber (reg:SI 12))
9170    (clobber (match_scratch:SI 5 "X"))]
9171   "TARGET_STRING && ! TARGET_POWER
9172    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9173        || INTVAL (operands[2]) == 0)
9174    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9175    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9176    && REGNO (operands[4]) == 5"
9177   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9178   [(set_attr "type" "load")
9179    (set_attr "length" "8")])
9180
9181 (define_insn ""
9182   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9183         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9184    (use (match_operand:SI 2 "immediate_operand" "i"))
9185    (use (match_operand:SI 3 "immediate_operand" "i"))
9186    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9187    (clobber (reg:SI  6))
9188    (clobber (reg:SI  7))
9189    (clobber (reg:SI  8))
9190    (clobber (reg:SI  9))
9191    (clobber (reg:SI 10))
9192    (clobber (reg:SI 11))
9193    (clobber (reg:SI 12))
9194    (clobber (match_scratch:SI 5 "X"))]
9195   "TARGET_STRING && TARGET_POWERPC64
9196    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9197        || INTVAL (operands[2]) == 0)
9198    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9199    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9200    && REGNO (operands[4]) == 5"
9201   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9202   [(set_attr "type" "load")
9203    (set_attr "length" "8")])
9204
9205 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
9206 ;; register allocator doesn't have a clue about allocating 6 word registers.
9207 ;; rD/rS = r5 is preferred, efficient form.
9208 (define_expand "movstrsi_6reg"
9209   [(parallel [(set (match_operand 0 "" "")
9210                    (match_operand 1 "" ""))
9211               (use (match_operand 2 "" ""))
9212               (use (match_operand 3 "" ""))
9213               (clobber (reg:SI  5))
9214               (clobber (reg:SI  6))
9215               (clobber (reg:SI  7))
9216               (clobber (reg:SI  8))
9217               (clobber (reg:SI  9))
9218               (clobber (reg:SI 10))
9219               (clobber (match_scratch:SI 4 ""))])]
9220   "TARGET_STRING"
9221   "")
9222
9223 (define_insn ""
9224   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9225         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9226    (use (match_operand:SI 2 "immediate_operand" "i"))
9227    (use (match_operand:SI 3 "immediate_operand" "i"))
9228    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9229    (clobber (reg:SI  6))
9230    (clobber (reg:SI  7))
9231    (clobber (reg:SI  8))
9232    (clobber (reg:SI  9))
9233    (clobber (reg:SI 10))
9234    (clobber (match_scratch:SI 5 "=q"))]
9235   "TARGET_STRING && TARGET_POWER
9236    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
9237    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9238    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9239    && REGNO (operands[4]) == 5"
9240   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9241   [(set_attr "type" "load")
9242    (set_attr "length" "8")])
9243
9244 (define_insn ""
9245   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9246         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9247    (use (match_operand:SI 2 "immediate_operand" "i"))
9248    (use (match_operand:SI 3 "immediate_operand" "i"))
9249    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9250    (clobber (reg:SI  6))
9251    (clobber (reg:SI  7))
9252    (clobber (reg:SI  8))
9253    (clobber (reg:SI  9))
9254    (clobber (reg:SI 10))
9255    (clobber (match_scratch:SI 5 "X"))]
9256   "TARGET_STRING && ! TARGET_POWER
9257    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9258    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9259    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9260    && REGNO (operands[4]) == 5"
9261   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9262   [(set_attr "type" "load")
9263    (set_attr "length" "8")])
9264
9265 (define_insn ""
9266   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9267         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9268    (use (match_operand:SI 2 "immediate_operand" "i"))
9269    (use (match_operand:SI 3 "immediate_operand" "i"))
9270    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9271    (clobber (reg:SI  6))
9272    (clobber (reg:SI  7))
9273    (clobber (reg:SI  8))
9274    (clobber (reg:SI  9))
9275    (clobber (reg:SI 10))
9276    (clobber (match_scratch:SI 5 "X"))]
9277   "TARGET_STRING && TARGET_POWERPC64
9278    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9279    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9280    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9281    && REGNO (operands[4]) == 5"
9282   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9283   [(set_attr "type" "load")
9284    (set_attr "length" "8")])
9285
9286 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
9287 ;; problems with TImode.
9288 ;; rD/rS = r5 is preferred, efficient form.
9289 (define_expand "movstrsi_4reg"
9290   [(parallel [(set (match_operand 0 "" "")
9291                    (match_operand 1 "" ""))
9292               (use (match_operand 2 "" ""))
9293               (use (match_operand 3 "" ""))
9294               (clobber (reg:SI 5))
9295               (clobber (reg:SI 6))
9296               (clobber (reg:SI 7))
9297               (clobber (reg:SI 8))
9298               (clobber (match_scratch:SI 4 ""))])]
9299   "TARGET_STRING"
9300   "")
9301
9302 (define_insn ""
9303   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9304         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9305    (use (match_operand:SI 2 "immediate_operand" "i"))
9306    (use (match_operand:SI 3 "immediate_operand" "i"))
9307    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9308    (clobber (reg:SI 6))
9309    (clobber (reg:SI 7))
9310    (clobber (reg:SI 8))
9311    (clobber (match_scratch:SI 5 "=q"))]
9312   "TARGET_STRING && TARGET_POWER
9313    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9314    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9315    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9316    && REGNO (operands[4]) == 5"
9317   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9318   [(set_attr "type" "load")
9319    (set_attr "length" "8")])
9320
9321 (define_insn ""
9322   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9323         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9324    (use (match_operand:SI 2 "immediate_operand" "i"))
9325    (use (match_operand:SI 3 "immediate_operand" "i"))
9326    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9327    (clobber (reg:SI 6))
9328    (clobber (reg:SI 7))
9329    (clobber (reg:SI 8))
9330    (clobber (match_scratch:SI 5 "X"))]
9331   "TARGET_STRING && ! TARGET_POWER
9332    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9333    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9334    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9335    && REGNO (operands[4]) == 5"
9336   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9337   [(set_attr "type" "load")
9338    (set_attr "length" "8")])
9339
9340 (define_insn ""
9341   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9342         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9343    (use (match_operand:SI 2 "immediate_operand" "i"))
9344    (use (match_operand:SI 3 "immediate_operand" "i"))
9345    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9346    (clobber (reg:SI 6))
9347    (clobber (reg:SI 7))
9348    (clobber (reg:SI 8))
9349    (clobber (match_scratch:SI 5 "X"))]
9350   "TARGET_STRING && TARGET_POWERPC64
9351    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9352    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9353    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9354    && REGNO (operands[4]) == 5"
9355   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9356   [(set_attr "type" "load")
9357    (set_attr "length" "8")])
9358
9359 ;; Move up to 8 bytes at a time.
9360 (define_expand "movstrsi_2reg"
9361   [(parallel [(set (match_operand 0 "" "")
9362                    (match_operand 1 "" ""))
9363               (use (match_operand 2 "" ""))
9364               (use (match_operand 3 "" ""))
9365               (clobber (match_scratch:DI 4 ""))
9366               (clobber (match_scratch:SI 5 ""))])]
9367   "TARGET_STRING && ! TARGET_POWERPC64"
9368   "")
9369
9370 (define_insn ""
9371   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9372         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9373    (use (match_operand:SI 2 "immediate_operand" "i"))
9374    (use (match_operand:SI 3 "immediate_operand" "i"))
9375    (clobber (match_scratch:DI 4 "=&r"))
9376    (clobber (match_scratch:SI 5 "=q"))]
9377   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
9378    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9379   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9380   [(set_attr "type" "load")
9381    (set_attr "length" "8")])
9382
9383 (define_insn ""
9384   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9385         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9386    (use (match_operand:SI 2 "immediate_operand" "i"))
9387    (use (match_operand:SI 3 "immediate_operand" "i"))
9388    (clobber (match_scratch:DI 4 "=&r"))
9389    (clobber (match_scratch:SI 5 "X"))]
9390   "TARGET_STRING && ! TARGET_POWER && ! TARGET_POWERPC64
9391    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9392   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9393   [(set_attr "type" "load")
9394    (set_attr "length" "8")])
9395
9396 ;; Move up to 4 bytes at a time.
9397 (define_expand "movstrsi_1reg"
9398   [(parallel [(set (match_operand 0 "" "")
9399                    (match_operand 1 "" ""))
9400               (use (match_operand 2 "" ""))
9401               (use (match_operand 3 "" ""))
9402               (clobber (match_scratch:SI 4 ""))
9403               (clobber (match_scratch:SI 5 ""))])]
9404   "TARGET_STRING"
9405   "")
9406
9407 (define_insn ""
9408   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9409         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9410    (use (match_operand:SI 2 "immediate_operand" "i"))
9411    (use (match_operand:SI 3 "immediate_operand" "i"))
9412    (clobber (match_scratch:SI 4 "=&r"))
9413    (clobber (match_scratch:SI 5 "=q"))]
9414   "TARGET_STRING && TARGET_POWER
9415    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9416   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9417   [(set_attr "type" "load")
9418    (set_attr "length" "8")])
9419
9420 (define_insn ""
9421   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9422         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9423    (use (match_operand:SI 2 "immediate_operand" "i"))
9424    (use (match_operand:SI 3 "immediate_operand" "i"))
9425    (clobber (match_scratch:SI 4 "=&r"))
9426    (clobber (match_scratch:SI 5 "X"))]
9427   "TARGET_STRING && ! TARGET_POWER
9428    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9429   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9430   [(set_attr "type" "load")
9431    (set_attr "length" "8")])
9432
9433 (define_insn ""
9434   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9435         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9436    (use (match_operand:SI 2 "immediate_operand" "i"))
9437    (use (match_operand:SI 3 "immediate_operand" "i"))
9438    (clobber (match_scratch:SI 4 "=&r"))
9439    (clobber (match_scratch:SI 5 "X"))]
9440   "TARGET_STRING && TARGET_POWERPC64
9441    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9442   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9443   [(set_attr "type" "load")
9444    (set_attr "length" "8")])
9445
9446 \f
9447 ;; Define insns that do load or store with update.  Some of these we can
9448 ;; get by using pre-decrement or pre-increment, but the hardware can also
9449 ;; do cases where the increment is not the size of the object.
9450 ;;
9451 ;; In all these cases, we use operands 0 and 1 for the register being
9452 ;; incremented because those are the operands that local-alloc will
9453 ;; tie and these are the pair most likely to be tieable (and the ones
9454 ;; that will benefit the most).
9455
9456 (define_insn "*movdi_update1"
9457   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
9458         (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    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9461         (plus:DI (match_dup 1) (match_dup 2)))]
9462   "TARGET_POWERPC64 && TARGET_UPDATE"
9463   "@
9464    ldux %3,%0,%2
9465    ldu %3,%2(%0)"
9466   [(set_attr "type" "load_ux,load_u")])
9467
9468 (define_insn "movdi_update"
9469   [(set (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9470                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I")))
9471         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
9472    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9473         (plus:DI (match_dup 1) (match_dup 2)))]
9474   "TARGET_POWERPC64 && TARGET_UPDATE"
9475   "@
9476    stdux %3,%0,%2
9477    stdu %3,%2(%0)"
9478   [(set_attr "type" "store_ux,store_u")])
9479
9480 (define_insn "*movsi_update1"
9481   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9482         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9483                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9484    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9485         (plus:SI (match_dup 1) (match_dup 2)))]
9486   "TARGET_UPDATE"
9487   "@
9488    {lux|lwzux} %3,%0,%2
9489    {lu|lwzu} %3,%2(%0)"
9490   [(set_attr "type" "load_ux,load_u")])
9491
9492 (define_insn "*movsi_update2"
9493   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
9494         (sign_extend:DI
9495          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
9496                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
9497    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
9498         (plus:DI (match_dup 1) (match_dup 2)))]
9499   "TARGET_POWERPC64"
9500   "lwaux %3,%0,%2"
9501   [(set_attr "type" "load_ext_ux")])
9502
9503 (define_insn "movsi_update"
9504   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9505                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9506         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
9507    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9508         (plus:SI (match_dup 1) (match_dup 2)))]
9509   "TARGET_UPDATE"
9510   "@
9511    {stux|stwux} %3,%0,%2
9512    {stu|stwu} %3,%2(%0)"
9513   [(set_attr "type" "store_ux,store_u")])
9514
9515 (define_insn "*movhi_update1"
9516   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
9517         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9518                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9519    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9520         (plus:SI (match_dup 1) (match_dup 2)))]
9521   "TARGET_UPDATE"
9522   "@
9523    lhzux %3,%0,%2
9524    lhzu %3,%2(%0)"
9525   [(set_attr "type" "load_ux,load_u")])
9526
9527 (define_insn "*movhi_update2"
9528   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9529         (zero_extend:SI
9530          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9531                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9532    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9533         (plus:SI (match_dup 1) (match_dup 2)))]
9534   "TARGET_UPDATE"
9535   "@
9536    lhzux %3,%0,%2
9537    lhzu %3,%2(%0)"
9538   [(set_attr "type" "load_ux,load_u")])
9539
9540 (define_insn "*movhi_update3"
9541   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9542         (sign_extend:SI
9543          (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    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9546         (plus:SI (match_dup 1) (match_dup 2)))]
9547   "TARGET_UPDATE"
9548   "@
9549    lhaux %3,%0,%2
9550    lhau %3,%2(%0)"
9551   [(set_attr "type" "load_ext_ux,load_ext_u")])
9552
9553 (define_insn "*movhi_update4"
9554   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9555                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9556         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
9557    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9558         (plus:SI (match_dup 1) (match_dup 2)))]
9559   "TARGET_UPDATE"
9560   "@
9561    sthux %3,%0,%2
9562    sthu %3,%2(%0)"
9563   [(set_attr "type" "store_ux,store_u")])
9564
9565 (define_insn "*movqi_update1"
9566   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
9567         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9568                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9569    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9570         (plus:SI (match_dup 1) (match_dup 2)))]
9571   "TARGET_UPDATE"
9572   "@
9573    lbzux %3,%0,%2
9574    lbzu %3,%2(%0)"
9575   [(set_attr "type" "load_ux,load_u")])
9576
9577 (define_insn "*movqi_update2"
9578   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9579         (zero_extend:SI
9580          (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    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9583         (plus:SI (match_dup 1) (match_dup 2)))]
9584   "TARGET_UPDATE"
9585   "@
9586    lbzux %3,%0,%2
9587    lbzu %3,%2(%0)"
9588   [(set_attr "type" "load_ux,load_u")])
9589
9590 (define_insn "*movqi_update3"
9591   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9592                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9593         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
9594    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9595         (plus:SI (match_dup 1) (match_dup 2)))]
9596   "TARGET_UPDATE"
9597   "@
9598    stbux %3,%0,%2
9599    stbu %3,%2(%0)"
9600   [(set_attr "type" "store_ux,store_u")])
9601
9602 (define_insn "*movsf_update1"
9603   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
9604         (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    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9607         (plus:SI (match_dup 1) (match_dup 2)))]
9608   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9609   "@
9610    lfsux %3,%0,%2
9611    lfsu %3,%2(%0)"
9612   [(set_attr "type" "fpload_ux,fpload_u")])
9613
9614 (define_insn "*movsf_update2"
9615   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9616                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9617         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
9618    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9619         (plus:SI (match_dup 1) (match_dup 2)))]
9620   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9621   "@
9622    stfsux %3,%0,%2
9623    stfsu %3,%2(%0)"
9624   [(set_attr "type" "fpstore_ux,fpstore_u")])
9625
9626 (define_insn "*movsf_update3"
9627   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
9628         (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    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9631         (plus:SI (match_dup 1) (match_dup 2)))]
9632   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9633   "@
9634    {lux|lwzux} %3,%0,%2
9635    {lu|lwzu} %3,%2(%0)"
9636   [(set_attr "type" "load_ux,load_u")])
9637
9638 (define_insn "*movsf_update4"
9639   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9640                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9641         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
9642    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9643         (plus:SI (match_dup 1) (match_dup 2)))]
9644   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9645   "@
9646    {stux|stwux} %3,%0,%2
9647    {stu|stwu} %3,%2(%0)"
9648   [(set_attr "type" "store_ux,store_u")])
9649
9650 (define_insn "*movdf_update1"
9651   [(set (match_operand:DF 3 "gpc_reg_operand" "=f,f")
9652         (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    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9655         (plus:SI (match_dup 1) (match_dup 2)))]
9656   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9657   "@
9658    lfdux %3,%0,%2
9659    lfdu %3,%2(%0)"
9660   [(set_attr "type" "fpload_ux,fpload_u")])
9661
9662 (define_insn "*movdf_update2"
9663   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9664                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9665         (match_operand:DF 3 "gpc_reg_operand" "f,f"))
9666    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9667         (plus:SI (match_dup 1) (match_dup 2)))]
9668   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9669   "@
9670    stfdux %3,%0,%2
9671    stfdu %3,%2(%0)"
9672   [(set_attr "type" "fpstore_ux,fpstore_u")])
9673
9674 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
9675
9676 (define_peephole
9677   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
9678         (match_operand:DF 1 "memory_operand" ""))
9679    (set (match_operand:DF 2 "gpc_reg_operand" "=f")
9680         (match_operand:DF 3 "memory_operand" ""))]
9681   "TARGET_POWER2
9682    && TARGET_HARD_FLOAT && TARGET_FPRS
9683    && registers_ok_for_quad_peep (operands[0], operands[2])
9684    && ! MEM_VOLATILE_P (operands[1]) && ! MEM_VOLATILE_P (operands[3])
9685    && addrs_ok_for_quad_peep (XEXP (operands[1], 0), XEXP (operands[3], 0))"
9686   "lfq%U1%X1 %0,%1")
9687
9688 (define_peephole
9689   [(set (match_operand:DF 0 "memory_operand" "")
9690         (match_operand:DF 1 "gpc_reg_operand" "f"))
9691    (set (match_operand:DF 2 "memory_operand" "")
9692         (match_operand:DF 3 "gpc_reg_operand" "f"))]
9693   "TARGET_POWER2
9694    && TARGET_HARD_FLOAT && TARGET_FPRS
9695    && registers_ok_for_quad_peep (operands[1], operands[3])
9696    && ! MEM_VOLATILE_P (operands[0]) && ! MEM_VOLATILE_P (operands[2])
9697    && addrs_ok_for_quad_peep (XEXP (operands[0], 0), XEXP (operands[2], 0))"
9698   "stfq%U0%X0 %1,%0")
9699 \f
9700 ;; TLS support.
9701
9702 ;; "b" output constraint here and on tls_ld to support tls linker optimization.
9703 (define_insn "tls_gd_32"
9704   [(set (match_operand:SI 0 "register_operand" "=b")
9705         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9706                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9707                    UNSPEC_TLSGD))]
9708   "HAVE_AS_TLS && !TARGET_64BIT"
9709   "addi %0,%1,%2@got@tlsgd")
9710
9711 (define_insn "tls_gd_64"
9712   [(set (match_operand:DI 0 "register_operand" "=b")
9713         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9714                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9715                    UNSPEC_TLSGD))]
9716   "HAVE_AS_TLS && TARGET_64BIT"
9717   "addi %0,%1,%2@got@tlsgd")
9718
9719 (define_insn "tls_ld_32"
9720   [(set (match_operand:SI 0 "register_operand" "=b")
9721         (unspec:SI [(match_operand:SI 1 "register_operand" "b")]
9722                    UNSPEC_TLSLD))]
9723   "HAVE_AS_TLS && !TARGET_64BIT"
9724   "addi %0,%1,%&@got@tlsld")
9725
9726 (define_insn "tls_ld_64"
9727   [(set (match_operand:DI 0 "register_operand" "=b")
9728         (unspec:DI [(match_operand:DI 1 "register_operand" "b")]
9729                    UNSPEC_TLSLD))]
9730   "HAVE_AS_TLS && TARGET_64BIT"
9731   "addi %0,%1,%&@got@tlsld")
9732
9733 (define_insn "tls_dtprel_32"
9734   [(set (match_operand:SI 0 "register_operand" "=r")
9735         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9736                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9737                    UNSPEC_TLSDTPREL))]
9738   "HAVE_AS_TLS && !TARGET_64BIT"
9739   "addi %0,%1,%2@dtprel")
9740
9741 (define_insn "tls_dtprel_64"
9742   [(set (match_operand:DI 0 "register_operand" "=r")
9743         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9744                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9745                    UNSPEC_TLSDTPREL))]
9746   "HAVE_AS_TLS && TARGET_64BIT"
9747   "addi %0,%1,%2@dtprel")
9748
9749 (define_insn "tls_dtprel_ha_32"
9750   [(set (match_operand:SI 0 "register_operand" "=r")
9751         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9752                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9753                    UNSPEC_TLSDTPRELHA))]
9754   "HAVE_AS_TLS && !TARGET_64BIT"
9755   "addis %0,%1,%2@dtprel@ha")
9756
9757 (define_insn "tls_dtprel_ha_64"
9758   [(set (match_operand:DI 0 "register_operand" "=r")
9759         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9760                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9761                    UNSPEC_TLSDTPRELHA))]
9762   "HAVE_AS_TLS && TARGET_64BIT"
9763   "addis %0,%1,%2@dtprel@ha")
9764
9765 (define_insn "tls_dtprel_lo_32"
9766   [(set (match_operand:SI 0 "register_operand" "=r")
9767         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9768                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9769                    UNSPEC_TLSDTPRELLO))]
9770   "HAVE_AS_TLS && !TARGET_64BIT"
9771   "addi %0,%1,%2@dtprel@l")
9772
9773 (define_insn "tls_dtprel_lo_64"
9774   [(set (match_operand:DI 0 "register_operand" "=r")
9775         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9776                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9777                    UNSPEC_TLSDTPRELLO))]
9778   "HAVE_AS_TLS && TARGET_64BIT"
9779   "addi %0,%1,%2@dtprel@l")
9780
9781 (define_insn "tls_got_dtprel_32"
9782   [(set (match_operand:SI 0 "register_operand" "=r")
9783         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9784                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9785                    UNSPEC_TLSGOTDTPREL))]
9786   "HAVE_AS_TLS && !TARGET_64BIT"
9787   "lwz %0,%2@got@dtprel(%1)")
9788
9789 (define_insn "tls_got_dtprel_64"
9790   [(set (match_operand:DI 0 "register_operand" "=r")
9791         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9792                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9793                    UNSPEC_TLSGOTDTPREL))]
9794   "HAVE_AS_TLS && TARGET_64BIT"
9795   "ld %0,%2@got@dtprel(%1)")
9796
9797 (define_insn "tls_tprel_32"
9798   [(set (match_operand:SI 0 "register_operand" "=r")
9799         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9800                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9801                    UNSPEC_TLSTPREL))]
9802   "HAVE_AS_TLS && !TARGET_64BIT"
9803   "addi %0,%1,%2@tprel")
9804
9805 (define_insn "tls_tprel_64"
9806   [(set (match_operand:DI 0 "register_operand" "=r")
9807         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9808                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9809                    UNSPEC_TLSTPREL))]
9810   "HAVE_AS_TLS && TARGET_64BIT"
9811   "addi %0,%1,%2@tprel")
9812
9813 (define_insn "tls_tprel_ha_32"
9814   [(set (match_operand:SI 0 "register_operand" "=r")
9815         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9816                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9817                    UNSPEC_TLSTPRELHA))]
9818   "HAVE_AS_TLS && !TARGET_64BIT"
9819   "addis %0,%1,%2@tprel@ha")
9820
9821 (define_insn "tls_tprel_ha_64"
9822   [(set (match_operand:DI 0 "register_operand" "=r")
9823         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9824                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9825                    UNSPEC_TLSTPRELHA))]
9826   "HAVE_AS_TLS && TARGET_64BIT"
9827   "addis %0,%1,%2@tprel@ha")
9828
9829 (define_insn "tls_tprel_lo_32"
9830   [(set (match_operand:SI 0 "register_operand" "=r")
9831         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9832                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9833                    UNSPEC_TLSTPRELLO))]
9834   "HAVE_AS_TLS && !TARGET_64BIT"
9835   "addi %0,%1,%2@tprel@l")
9836
9837 (define_insn "tls_tprel_lo_64"
9838   [(set (match_operand:DI 0 "register_operand" "=r")
9839         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9840                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9841                    UNSPEC_TLSTPRELLO))]
9842   "HAVE_AS_TLS && TARGET_64BIT"
9843   "addi %0,%1,%2@tprel@l")
9844
9845 ;; "b" output constraint here and on tls_tls input to support linker tls
9846 ;; optimization.  The linker may edit the instructions emitted by a
9847 ;; tls_got_tprel/tls_tls pair to addis,addi.
9848 (define_insn "tls_got_tprel_32"
9849   [(set (match_operand:SI 0 "register_operand" "=b")
9850         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9851                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9852                    UNSPEC_TLSGOTTPREL))]
9853   "HAVE_AS_TLS && !TARGET_64BIT"
9854   "lwz %0,%2@got@tprel(%1)")
9855
9856 (define_insn "tls_got_tprel_64"
9857   [(set (match_operand:DI 0 "register_operand" "=b")
9858         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9859                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9860                    UNSPEC_TLSGOTTPREL))]
9861   "HAVE_AS_TLS && TARGET_64BIT"
9862   "ld %0,%2@got@tprel(%1)")
9863
9864 (define_insn "tls_tls_32"
9865   [(set (match_operand:SI 0 "register_operand" "=r")
9866         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
9867                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9868                    UNSPEC_TLSTLS))]
9869   "HAVE_AS_TLS && !TARGET_64BIT"
9870   "add %0,%1,%2@tls")
9871
9872 (define_insn "tls_tls_64"
9873   [(set (match_operand:DI 0 "register_operand" "=r")
9874         (unspec:DI [(match_operand:DI 1 "register_operand" "b")
9875                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9876                    UNSPEC_TLSTLS))]
9877   "HAVE_AS_TLS && TARGET_64BIT"
9878   "add %0,%1,%2@tls")
9879 \f
9880 ;; Next come insns related to the calling sequence.
9881 ;;
9882 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
9883 ;; We move the back-chain and decrement the stack pointer.
9884
9885 (define_expand "allocate_stack"
9886   [(set (match_operand 0 "gpc_reg_operand" "=r")
9887         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
9888    (set (reg 1)
9889         (minus (reg 1) (match_dup 1)))]
9890   ""
9891   "
9892 { rtx chain = gen_reg_rtx (Pmode);
9893   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
9894   rtx neg_op0;
9895
9896   emit_move_insn (chain, stack_bot);
9897
9898   /* Check stack bounds if necessary.  */
9899   if (current_function_limit_stack)
9900     {
9901       rtx available;
9902       available = expand_binop (Pmode, sub_optab, 
9903                                 stack_pointer_rtx, stack_limit_rtx,
9904                                 NULL_RTX, 1, OPTAB_WIDEN);
9905       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
9906     }
9907
9908   if (GET_CODE (operands[1]) != CONST_INT
9909       || INTVAL (operands[1]) < -32767
9910       || INTVAL (operands[1]) > 32768)
9911     {
9912       neg_op0 = gen_reg_rtx (Pmode);
9913       if (TARGET_32BIT)
9914         emit_insn (gen_negsi2 (neg_op0, operands[1]));
9915       else
9916         emit_insn (gen_negdi2 (neg_op0, operands[1]));
9917     }
9918   else
9919     neg_op0 = GEN_INT (- INTVAL (operands[1]));
9920
9921   if (TARGET_UPDATE)
9922     emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update : gen_movdi_update))
9923                 (stack_pointer_rtx, stack_pointer_rtx, neg_op0, chain));
9924
9925   else
9926     {
9927       emit_insn ((* ((TARGET_32BIT) ? gen_addsi3 : gen_adddi3))
9928                  (stack_pointer_rtx, stack_pointer_rtx, neg_op0));
9929       emit_move_insn (gen_rtx_MEM (Pmode, stack_pointer_rtx), chain);
9930     }
9931
9932   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
9933   DONE;
9934 }")
9935
9936 ;; These patterns say how to save and restore the stack pointer.  We need not
9937 ;; save the stack pointer at function level since we are careful to
9938 ;; preserve the backchain.  At block level, we have to restore the backchain
9939 ;; when we restore the stack pointer.
9940 ;;
9941 ;; For nonlocal gotos, we must save both the stack pointer and its
9942 ;; backchain and restore both.  Note that in the nonlocal case, the
9943 ;; save area is a memory location.
9944
9945 (define_expand "save_stack_function"
9946   [(match_operand 0 "any_operand" "")
9947    (match_operand 1 "any_operand" "")]
9948   ""
9949   "DONE;")
9950
9951 (define_expand "restore_stack_function"
9952   [(match_operand 0 "any_operand" "")
9953    (match_operand 1 "any_operand" "")]
9954   ""
9955   "DONE;")
9956
9957 (define_expand "restore_stack_block"
9958   [(use (match_operand 0 "register_operand" ""))
9959    (set (match_dup 2) (match_dup 3))
9960    (set (match_dup 0) (match_operand 1 "register_operand" ""))
9961    (set (match_dup 3) (match_dup 2))]
9962   ""
9963   "
9964 {
9965   operands[2] = gen_reg_rtx (Pmode);
9966   operands[3] = gen_rtx_MEM (Pmode, operands[0]);
9967 }")
9968
9969 (define_expand "save_stack_nonlocal"
9970   [(match_operand 0 "memory_operand" "")
9971    (match_operand 1 "register_operand" "")]
9972   ""
9973   "
9974 {
9975   rtx temp = gen_reg_rtx (Pmode);
9976
9977   /* Copy the backchain to the first word, sp to the second.  */
9978   emit_move_insn (temp, gen_rtx_MEM (Pmode, operands[1]));
9979   emit_move_insn (operand_subword (operands[0], 0, 0,
9980                                    (TARGET_32BIT ? DImode : TImode)),
9981                   temp);
9982   emit_move_insn (operand_subword (operands[0], 1, 0, (TARGET_32BIT ? DImode : TImode)),
9983                   operands[1]);
9984   DONE;
9985 }")
9986
9987 (define_expand "restore_stack_nonlocal"
9988   [(match_operand 0 "register_operand" "")
9989    (match_operand 1 "memory_operand" "")]
9990   ""
9991   "
9992 {
9993   rtx temp = gen_reg_rtx (Pmode);
9994
9995   /* Restore the backchain from the first word, sp from the second.  */
9996   emit_move_insn (temp,
9997                   operand_subword (operands[1], 0, 0, (TARGET_32BIT ? DImode : TImode)));
9998   emit_move_insn (operands[0],
9999                   operand_subword (operands[1], 1, 0,
10000                                    (TARGET_32BIT ? DImode : TImode)));
10001   emit_move_insn (gen_rtx_MEM (Pmode, operands[0]), temp);
10002   DONE;
10003 }")
10004 \f
10005 ;; TOC register handling.
10006
10007 ;; Code to initialize the TOC register...
10008
10009 (define_insn "load_toc_aix_si"
10010   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10011                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
10012               (use (reg:SI 2))])]
10013   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
10014   "*
10015 {
10016   char buf[30];
10017   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10018   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10019   operands[2] = gen_rtx_REG (Pmode, 2);
10020   return \"{l|lwz} %0,%1(%2)\";
10021 }"
10022   [(set_attr "type" "load")])
10023
10024 (define_insn "load_toc_aix_di"
10025   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10026                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
10027               (use (reg:DI 2))])]
10028   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
10029   "*
10030 {
10031   char buf[30];
10032 #ifdef TARGET_RELOCATABLE
10033   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
10034                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
10035 #else
10036   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10037 #endif
10038   if (TARGET_ELF)
10039     strcat (buf, \"@toc\");
10040   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10041   operands[2] = gen_rtx_REG (Pmode, 2);
10042   return \"ld %0,%1(%2)\";
10043 }"
10044   [(set_attr "type" "load")])
10045
10046 (define_insn "load_toc_v4_pic_si"
10047   [(set (match_operand:SI 0 "register_operand" "=l")
10048         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
10049   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
10050   "bl _GLOBAL_OFFSET_TABLE_@local-4"
10051   [(set_attr "type" "branch")
10052    (set_attr "length" "4")])
10053
10054 (define_insn "load_toc_v4_PIC_1"
10055   [(set (match_operand:SI 0 "register_operand" "=l")
10056         (match_operand:SI 1 "immediate_operand" "s"))
10057    (use (unspec [(match_dup 1)] UNSPEC_TOC))]
10058   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10059   "bcl 20,31,%1\\n%1:"
10060   [(set_attr "type" "branch")
10061    (set_attr "length" "4")])
10062
10063 (define_insn "load_toc_v4_PIC_1b"
10064   [(set (match_operand:SI 0 "register_operand" "=l")
10065         (match_operand:SI 1 "immediate_operand" "s"))
10066    (use (unspec [(match_dup 1) (match_operand 2 "immediate_operand" "s")]
10067                 UNSPEC_TOCPTR))]
10068   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10069   "bcl 20,31,%1+4\\n%1:\\n\\t.long %2-%1"
10070   [(set_attr "type" "branch")
10071    (set_attr "length" "8")])
10072
10073 (define_insn "load_toc_v4_PIC_2"
10074   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10075         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10076                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
10077                              (match_operand:SI 3 "immediate_operand" "s")))))]
10078   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10079   "{l|lwz} %0,%2-%3(%1)"
10080   [(set_attr "type" "load")])
10081
10082 (define_insn "load_macho_picbase"
10083   [(set (match_operand:SI 0 "register_operand" "=l")
10084         (unspec:SI [(match_operand:SI 1 "immediate_operand" "s")]
10085                    UNSPEC_LD_MPIC))]
10086   "(DEFAULT_ABI == ABI_DARWIN) && flag_pic"
10087   "bcl 20,31,%1\\n%1:"
10088   [(set_attr "type" "branch")
10089    (set_attr "length" "4")])
10090
10091 (define_insn "macho_correct_pic"
10092   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10093         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
10094                  (unspec:SI [(match_operand:SI 2 "immediate_operand" "s")
10095                              (match_operand:SI 3 "immediate_operand" "s")]
10096                             UNSPEC_MPIC_CORRECT)))]
10097   "DEFAULT_ABI == ABI_DARWIN"
10098   "addis %0,%1,ha16(%2-%3)\n\taddi %0,%0,lo16(%2-%3)"
10099   [(set_attr "length" "8")])
10100
10101 ;; If the TOC is shared over a translation unit, as happens with all
10102 ;; the kinds of PIC that we support, we need to restore the TOC
10103 ;; pointer only when jumping over units of translation.
10104 ;; On Darwin, we need to reload the picbase.
10105
10106 (define_expand "builtin_setjmp_receiver"
10107   [(use (label_ref (match_operand 0 "" "")))]
10108   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
10109    || (TARGET_TOC && TARGET_MINIMAL_TOC)
10110    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
10111   "
10112 {
10113 #if TARGET_MACHO
10114   if (DEFAULT_ABI == ABI_DARWIN)
10115     {
10116       const char *picbase = machopic_function_base_name ();
10117       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (picbase));
10118       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
10119       rtx tmplabrtx;
10120       char tmplab[20];
10121
10122       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
10123                                   CODE_LABEL_NUMBER (operands[0]));
10124       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
10125
10126       emit_insn (gen_load_macho_picbase (picreg, tmplabrtx));
10127       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
10128     }
10129   else
10130 #endif
10131     rs6000_emit_load_toc_table (FALSE);
10132   DONE;
10133 }")
10134 \f
10135 ;; A function pointer under AIX is a pointer to a data area whose first word
10136 ;; contains the actual address of the function, whose second word contains a
10137 ;; pointer to its TOC, and whose third word contains a value to place in the
10138 ;; static chain register (r11).  Note that if we load the static chain, our
10139 ;; "trampoline" need not have any executable code.
10140
10141 (define_expand "call_indirect_aix32"
10142   [(set (match_dup 2)
10143         (mem:SI (match_operand:SI 0 "gpc_reg_operand" "")))
10144    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10145         (reg:SI 2))
10146    (set (reg:SI 2)
10147         (mem:SI (plus:SI (match_dup 0)
10148                          (const_int 4))))
10149    (set (reg:SI 11)
10150         (mem:SI (plus:SI (match_dup 0)
10151                          (const_int 8))))
10152    (parallel [(call (mem:SI (match_dup 2))
10153                     (match_operand 1 "" ""))
10154               (use (reg:SI 2))
10155               (use (reg:SI 11))
10156               (set (reg:SI 2)
10157                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10158               (clobber (scratch:SI))])]
10159   "TARGET_32BIT"
10160   "
10161 { operands[2] = gen_reg_rtx (SImode); }")
10162
10163 (define_expand "call_indirect_aix64"
10164   [(set (match_dup 2)
10165         (mem:DI (match_operand:DI 0 "gpc_reg_operand" "")))
10166    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10167         (reg:DI 2))
10168    (set (reg:DI 2)
10169         (mem:DI (plus:DI (match_dup 0)
10170                          (const_int 8))))
10171    (set (reg:DI 11)
10172         (mem:DI (plus:DI (match_dup 0)
10173                          (const_int 16))))
10174    (parallel [(call (mem:SI (match_dup 2))
10175                     (match_operand 1 "" ""))
10176               (use (reg:DI 2))
10177               (use (reg:DI 11))
10178               (set (reg:DI 2)
10179                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10180               (clobber (scratch:SI))])]
10181   "TARGET_64BIT"
10182   "
10183 { operands[2] = gen_reg_rtx (DImode); }")
10184
10185 (define_expand "call_value_indirect_aix32"
10186   [(set (match_dup 3)
10187         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
10188    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10189         (reg:SI 2))
10190    (set (reg:SI 2)
10191         (mem:SI (plus:SI (match_dup 1)
10192                          (const_int 4))))
10193    (set (reg:SI 11)
10194         (mem:SI (plus:SI (match_dup 1)
10195                          (const_int 8))))
10196    (parallel [(set (match_operand 0 "" "")
10197                    (call (mem:SI (match_dup 3))
10198                          (match_operand 2 "" "")))
10199               (use (reg:SI 2))
10200               (use (reg:SI 11))
10201               (set (reg:SI 2)
10202                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10203               (clobber (scratch:SI))])]
10204   "TARGET_32BIT"
10205   "
10206 { operands[3] = gen_reg_rtx (SImode); }")
10207
10208 (define_expand "call_value_indirect_aix64"
10209   [(set (match_dup 3)
10210         (mem:DI (match_operand:DI 1 "gpc_reg_operand" "")))
10211    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10212         (reg:DI 2))
10213    (set (reg:DI 2)
10214         (mem:DI (plus:DI (match_dup 1)
10215                          (const_int 8))))
10216    (set (reg:DI 11)
10217         (mem:DI (plus:DI (match_dup 1)
10218                          (const_int 16))))
10219    (parallel [(set (match_operand 0 "" "")
10220                    (call (mem:SI (match_dup 3))
10221                          (match_operand 2 "" "")))
10222               (use (reg:DI 2))
10223               (use (reg:DI 11))
10224               (set (reg:DI 2)
10225                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10226               (clobber (scratch:SI))])]
10227   "TARGET_64BIT"
10228   "
10229 { operands[3] = gen_reg_rtx (DImode); }")
10230
10231 ;; Now the definitions for the call and call_value insns
10232 (define_expand "call"
10233   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10234                     (match_operand 1 "" ""))
10235               (use (match_operand 2 "" ""))
10236               (clobber (scratch:SI))])]
10237   ""
10238   "
10239 {
10240 #if TARGET_MACHO
10241   if (MACHOPIC_INDIRECT)
10242     operands[0] = machopic_indirect_call_target (operands[0]);
10243 #endif
10244
10245   if (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != CONST_INT)
10246     abort ();
10247
10248   operands[0] = XEXP (operands[0], 0);
10249
10250   if (GET_CODE (operands[0]) != SYMBOL_REF
10251       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
10252       || (INTVAL (operands[2]) & CALL_LONG) != 0)
10253     {
10254       if (INTVAL (operands[2]) & CALL_LONG)
10255         operands[0] = rs6000_longcall_ref (operands[0]);
10256
10257       if (DEFAULT_ABI == ABI_V4
10258           || DEFAULT_ABI == ABI_DARWIN)
10259         operands[0] = force_reg (Pmode, operands[0]);
10260
10261       else if (DEFAULT_ABI == ABI_AIX)
10262         {
10263           /* AIX function pointers are really pointers to a three word
10264              area.  */
10265           emit_call_insn (TARGET_32BIT
10266                           ? gen_call_indirect_aix32 (force_reg (SImode,
10267                                                                 operands[0]),
10268                                                      operands[1])
10269                           : gen_call_indirect_aix64 (force_reg (DImode,
10270                                                                 operands[0]),
10271                                                      operands[1]));
10272           DONE;
10273         }
10274       else
10275         abort ();
10276     }
10277 }")
10278
10279 (define_expand "call_value"
10280   [(parallel [(set (match_operand 0 "" "")
10281                    (call (mem:SI (match_operand 1 "address_operand" ""))
10282                          (match_operand 2 "" "")))
10283               (use (match_operand 3 "" ""))
10284               (clobber (scratch:SI))])]
10285   ""
10286   "
10287 {
10288 #if TARGET_MACHO
10289   if (MACHOPIC_INDIRECT)
10290     operands[1] = machopic_indirect_call_target (operands[1]);
10291 #endif
10292
10293   if (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != CONST_INT)
10294     abort ();
10295
10296   operands[1] = XEXP (operands[1], 0);
10297
10298   if (GET_CODE (operands[1]) != SYMBOL_REF
10299       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
10300       || (INTVAL (operands[3]) & CALL_LONG) != 0)
10301     {
10302       if (INTVAL (operands[3]) & CALL_LONG)
10303         operands[1] = rs6000_longcall_ref (operands[1]);
10304
10305       if (DEFAULT_ABI == ABI_V4
10306           || DEFAULT_ABI == ABI_DARWIN)
10307         operands[0] = force_reg (Pmode, operands[0]);
10308
10309       else if (DEFAULT_ABI == ABI_AIX)
10310         {
10311           /* AIX function pointers are really pointers to a three word
10312              area.  */
10313           emit_call_insn (TARGET_32BIT
10314                           ? gen_call_value_indirect_aix32 (operands[0],
10315                                                            force_reg (SImode,
10316                                                                       operands[1]),
10317                                                            operands[2])
10318                           : gen_call_value_indirect_aix64 (operands[0],
10319                                                            force_reg (DImode,
10320                                                                       operands[1]),
10321                                                            operands[2]));
10322           DONE;
10323         }
10324       else
10325         abort ();
10326     }
10327 }")
10328
10329 ;; Call to function in current module.  No TOC pointer reload needed.
10330 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10331 ;; either the function was not prototyped, or it was prototyped as a
10332 ;; variable argument function.  It is > 0 if FP registers were passed
10333 ;; and < 0 if they were not.
10334
10335 (define_insn "*call_local32"
10336   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10337          (match_operand 1 "" "g,g"))
10338    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10339    (clobber (match_scratch:SI 3 "=l,l"))]
10340   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10341   "*
10342 {
10343   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10344     output_asm_insn (\"crxor 6,6,6\", operands);
10345
10346   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10347     output_asm_insn (\"creqv 6,6,6\", operands);
10348
10349   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10350 }"
10351   [(set_attr "type" "branch")
10352    (set_attr "length" "4,8")])
10353
10354 (define_insn "*call_local64"
10355   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10356          (match_operand 1 "" "g,g"))
10357    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10358    (clobber (match_scratch:SI 3 "=l,l"))]
10359   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10360   "*
10361 {
10362   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10363     output_asm_insn (\"crxor 6,6,6\", operands);
10364
10365   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10366     output_asm_insn (\"creqv 6,6,6\", operands);
10367
10368   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10369 }"
10370   [(set_attr "type" "branch")
10371    (set_attr "length" "4,8")])
10372
10373 (define_insn "*call_value_local32"
10374   [(set (match_operand 0 "" "")
10375         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10376               (match_operand 2 "" "g,g")))
10377    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10378    (clobber (match_scratch:SI 4 "=l,l"))]
10379   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10380   "*
10381 {
10382   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10383     output_asm_insn (\"crxor 6,6,6\", operands);
10384
10385   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10386     output_asm_insn (\"creqv 6,6,6\", operands);
10387
10388   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10389 }"
10390   [(set_attr "type" "branch")
10391    (set_attr "length" "4,8")])
10392
10393
10394 (define_insn "*call_value_local64"
10395   [(set (match_operand 0 "" "")
10396         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10397               (match_operand 2 "" "g,g")))
10398    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10399    (clobber (match_scratch:SI 4 "=l,l"))]
10400   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10401   "*
10402 {
10403   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10404     output_asm_insn (\"crxor 6,6,6\", operands);
10405
10406   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10407     output_asm_insn (\"creqv 6,6,6\", operands);
10408
10409   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10410 }"
10411   [(set_attr "type" "branch")
10412    (set_attr "length" "4,8")])
10413
10414 ;; Call to function which may be in another module.  Restore the TOC
10415 ;; pointer (r2) after the call unless this is System V.
10416 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10417 ;; either the function was not prototyped, or it was prototyped as a
10418 ;; variable argument function.  It is > 0 if FP registers were passed
10419 ;; and < 0 if they were not.
10420
10421 (define_insn "*call_indirect_nonlocal_aix32"
10422   [(call (mem:SI (match_operand:SI 0 "register_operand" "cl"))
10423          (match_operand 1 "" "g"))
10424    (use (reg:SI 2))
10425    (use (reg:SI 11))
10426    (set (reg:SI 2)
10427         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10428    (clobber (match_scratch:SI 2 "=l"))]
10429   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10430   "b%T0l\;{l|lwz} 2,20(1)"
10431   [(set_attr "type" "jmpreg")
10432    (set_attr "length" "8")])
10433
10434 (define_insn "*call_nonlocal_aix32"
10435   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10436          (match_operand 1 "" "g"))
10437    (use (match_operand:SI 2 "immediate_operand" "O"))
10438    (clobber (match_scratch:SI 3 "=l"))]
10439   "TARGET_32BIT
10440    && DEFAULT_ABI == ABI_AIX
10441    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10442   "bl %z0\;%."
10443   [(set_attr "type" "branch")
10444    (set_attr "length" "8")])
10445
10446 (define_insn "*call_indirect_nonlocal_aix64"
10447   [(call (mem:SI (match_operand:DI 0 "register_operand" "cl"))
10448          (match_operand 1 "" "g"))
10449    (use (reg:DI 2))
10450    (use (reg:DI 11))
10451    (set (reg:DI 2)
10452         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10453    (clobber (match_scratch:SI 2 "=l"))]
10454   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10455   "b%T0l\;ld 2,40(1)"
10456   [(set_attr "type" "jmpreg")
10457    (set_attr "length" "8")])
10458
10459 (define_insn "*call_nonlocal_aix64"
10460   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10461          (match_operand 1 "" "g"))
10462    (use (match_operand:SI 2 "immediate_operand" "O"))
10463    (clobber (match_scratch:SI 3 "=l"))]
10464   "TARGET_64BIT 
10465    && DEFAULT_ABI == ABI_AIX
10466    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10467   "bl %z0\;%."
10468   [(set_attr "type" "branch")
10469    (set_attr "length" "8")])
10470
10471 (define_insn "*call_value_indirect_nonlocal_aix32"
10472   [(set (match_operand 0 "" "")
10473         (call (mem:SI (match_operand:SI 1 "register_operand" "cl"))
10474               (match_operand 2 "" "g")))
10475    (use (reg:SI 2))
10476    (use (reg:SI 11))
10477    (set (reg:SI 2)
10478         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10479    (clobber (match_scratch:SI 3 "=l"))]
10480   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10481   "b%T1l\;{l|lwz} 2,20(1)"
10482   [(set_attr "type" "jmpreg")
10483    (set_attr "length" "8")])
10484
10485 (define_insn "*call_value_nonlocal_aix32"
10486   [(set (match_operand 0 "" "")
10487         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10488               (match_operand 2 "" "g")))
10489    (use (match_operand:SI 3 "immediate_operand" "O"))
10490    (clobber (match_scratch:SI 4 "=l"))]
10491   "TARGET_32BIT
10492    && DEFAULT_ABI == ABI_AIX
10493    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10494   "bl %z1\;%."
10495   [(set_attr "type" "branch")
10496    (set_attr "length" "8")])
10497
10498 (define_insn "*call_value_indirect_nonlocal_aix64"
10499   [(set (match_operand 0 "" "")
10500         (call (mem:SI (match_operand:DI 1 "register_operand" "cl"))
10501               (match_operand 2 "" "g")))
10502    (use (reg:DI 2))
10503    (use (reg:DI 11))
10504    (set (reg:DI 2)
10505         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10506    (clobber (match_scratch:SI 3 "=l"))]
10507   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10508   "b%T1l\;ld 2,40(1)"
10509   [(set_attr "type" "jmpreg")
10510    (set_attr "length" "8")])
10511
10512 (define_insn "*call_value_nonlocal_aix64"
10513   [(set (match_operand 0 "" "")
10514         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10515               (match_operand 2 "" "g")))
10516    (use (match_operand:SI 3 "immediate_operand" "O"))
10517    (clobber (match_scratch:SI 4 "=l"))]
10518   "TARGET_64BIT 
10519    && DEFAULT_ABI == ABI_AIX
10520    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10521   "bl %z1\;%."
10522   [(set_attr "type" "branch")
10523    (set_attr "length" "8")])
10524
10525 ;; A function pointer under System V is just a normal pointer
10526 ;; operands[0] is the function pointer
10527 ;; operands[1] is the stack size to clean up
10528 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
10529 ;; which indicates how to set cr1
10530
10531 (define_insn "*call_indirect_nonlocal_sysv"
10532   [(call (mem:SI (match_operand:SI 0 "register_operand" "cl,cl"))
10533          (match_operand 1 "" "g,g"))
10534    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10535    (clobber (match_scratch:SI 3 "=l,l"))]
10536   "DEFAULT_ABI == ABI_V4
10537    || DEFAULT_ABI == ABI_DARWIN"
10538 {
10539   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10540     output_asm_insn ("crxor 6,6,6", operands);
10541
10542   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10543     output_asm_insn ("creqv 6,6,6", operands);
10544
10545   return "b%T0l";
10546 }
10547   [(set_attr "type" "jmpreg,jmpreg")
10548    (set_attr "length" "4,8")])
10549
10550 (define_insn "*call_nonlocal_sysv"
10551   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s,s"))
10552          (match_operand 1 "" "g,g"))
10553    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10554    (clobber (match_scratch:SI 3 "=l,l"))]
10555   "(DEFAULT_ABI == ABI_V4
10556     || DEFAULT_ABI == ABI_DARWIN)
10557    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10558 {
10559   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10560     output_asm_insn ("crxor 6,6,6", operands);
10561
10562   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10563     output_asm_insn ("creqv 6,6,6", operands);
10564
10565   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z0@plt" : "bl %z0";
10566 }
10567   [(set_attr "type" "branch,branch")
10568    (set_attr "length" "4,8")])
10569
10570 (define_insn "*call_value_indirect_nonlocal_sysv"
10571   [(set (match_operand 0 "" "")
10572         (call (mem:SI (match_operand:SI 1 "register_operand" "cl,cl"))
10573               (match_operand 2 "" "g,g")))
10574    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10575    (clobber (match_scratch:SI 4 "=l,l"))]
10576   "DEFAULT_ABI == ABI_V4
10577    || DEFAULT_ABI == ABI_DARWIN"
10578 {
10579   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10580     output_asm_insn ("crxor 6,6,6", operands);
10581
10582   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10583     output_asm_insn ("creqv 6,6,6", operands);
10584
10585   return "b%T1l";
10586 }
10587   [(set_attr "type" "jmpreg,jmpreg")
10588    (set_attr "length" "4,8")])
10589
10590 (define_insn "*call_value_nonlocal_sysv"
10591   [(set (match_operand 0 "" "")
10592         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s,s"))
10593               (match_operand 2 "" "g,g")))
10594    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10595    (clobber (match_scratch:SI 4 "=l,l"))]
10596   "(DEFAULT_ABI == ABI_V4
10597     || DEFAULT_ABI == ABI_DARWIN)
10598    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10599 {
10600   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10601     output_asm_insn ("crxor 6,6,6", operands);
10602
10603   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10604     output_asm_insn ("creqv 6,6,6", operands);
10605
10606   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z1@plt" : "bl %z1";
10607 }
10608   [(set_attr "type" "branch,branch")
10609    (set_attr "length" "4,8")])
10610
10611 ;; Call subroutine returning any type.
10612 (define_expand "untyped_call"
10613   [(parallel [(call (match_operand 0 "" "")
10614                     (const_int 0))
10615               (match_operand 1 "" "")
10616               (match_operand 2 "" "")])]
10617   ""
10618   "
10619 {
10620   int i;
10621
10622   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
10623
10624   for (i = 0; i < XVECLEN (operands[2], 0); i++)
10625     {
10626       rtx set = XVECEXP (operands[2], 0, i);
10627       emit_move_insn (SET_DEST (set), SET_SRC (set));
10628     }
10629
10630   /* The optimizer does not know that the call sets the function value
10631      registers we stored in the result block.  We avoid problems by
10632      claiming that all hard registers are used and clobbered at this
10633      point.  */
10634   emit_insn (gen_blockage ());
10635
10636   DONE;
10637 }")
10638
10639 ;; sibling call patterns
10640 (define_expand "sibcall"
10641   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10642                     (match_operand 1 "" ""))
10643               (use (match_operand 2 "" ""))
10644               (use (match_operand 3 "" ""))
10645               (return)])]
10646   ""
10647   "
10648 {
10649 #if TARGET_MACHO
10650   if (MACHOPIC_INDIRECT)
10651     operands[0] = machopic_indirect_call_target (operands[0]);
10652 #endif
10653
10654   if (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != CONST_INT)
10655     abort ();
10656
10657   operands[0] = XEXP (operands[0], 0);
10658   operands[3] = gen_reg_rtx (SImode);
10659
10660 }")
10661
10662 ;; this and similar patterns must be marked as using LR, otherwise
10663 ;; dataflow will try to delete the store into it.  This is true
10664 ;; even when the actual reg to jump to is in CTR, when LR was
10665 ;; saved and restored around the PIC-setting BCL.
10666 (define_insn "*sibcall_local32"
10667   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10668          (match_operand 1 "" "g,g"))
10669    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10670    (use (match_operand:SI 3 "register_operand" "l,l"))
10671    (return)]
10672   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10673   "*
10674 {
10675   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10676     output_asm_insn (\"crxor 6,6,6\", operands);
10677
10678   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10679     output_asm_insn (\"creqv 6,6,6\", operands);
10680
10681   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
10682 }"
10683   [(set_attr "type" "branch")
10684    (set_attr "length" "4,8")])
10685
10686 (define_insn "*sibcall_local64"
10687   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10688          (match_operand 1 "" "g,g"))
10689    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10690    (use (match_operand:SI 3 "register_operand" "l,l"))
10691    (return)]
10692   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10693   "*
10694 {
10695   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10696     output_asm_insn (\"crxor 6,6,6\", operands);
10697
10698   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10699     output_asm_insn (\"creqv 6,6,6\", operands);
10700
10701   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
10702 }"
10703   [(set_attr "type" "branch")
10704    (set_attr "length" "4,8")])
10705
10706 (define_insn "*sibcall_value_local32"
10707   [(set (match_operand 0 "" "")
10708         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10709               (match_operand 2 "" "g,g")))
10710    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10711    (use (match_operand:SI 4 "register_operand" "l,l"))
10712    (return)]
10713   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10714   "*
10715 {
10716   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10717     output_asm_insn (\"crxor 6,6,6\", operands);
10718
10719   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10720     output_asm_insn (\"creqv 6,6,6\", operands);
10721
10722   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
10723 }"
10724   [(set_attr "type" "branch")
10725    (set_attr "length" "4,8")])
10726
10727
10728 (define_insn "*sibcall_value_local64"
10729   [(set (match_operand 0 "" "")
10730         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10731               (match_operand 2 "" "g,g")))
10732    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10733    (use (match_operand:SI 4 "register_operand" "l,l"))
10734    (return)]
10735   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10736   "*
10737 {
10738   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10739     output_asm_insn (\"crxor 6,6,6\", operands);
10740
10741   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10742     output_asm_insn (\"creqv 6,6,6\", operands);
10743
10744   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
10745 }"
10746   [(set_attr "type" "branch")
10747    (set_attr "length" "4,8")])
10748
10749 (define_insn "*sibcall_nonlocal_aix32"
10750   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10751          (match_operand 1 "" "g"))
10752    (use (match_operand:SI 2 "immediate_operand" "O"))
10753    (use (match_operand:SI 3 "register_operand" "l"))
10754    (return)]
10755   "TARGET_32BIT
10756    && DEFAULT_ABI == ABI_AIX
10757    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10758   "b %z0"
10759   [(set_attr "type" "branch")
10760    (set_attr "length" "4")])
10761
10762 (define_insn "*sibcall_nonlocal_aix64"
10763   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10764          (match_operand 1 "" "g"))
10765    (use (match_operand:SI 2 "immediate_operand" "O"))
10766    (use (match_operand:SI 3 "register_operand" "l"))
10767    (return)]
10768   "TARGET_64BIT 
10769    && DEFAULT_ABI == ABI_AIX
10770    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10771   "b %z0"
10772   [(set_attr "type" "branch")
10773    (set_attr "length" "4")])
10774
10775 (define_insn "*sibcall_value_nonlocal_aix32"
10776   [(set (match_operand 0 "" "")
10777         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10778               (match_operand 2 "" "g")))
10779    (use (match_operand:SI 3 "immediate_operand" "O"))
10780    (use (match_operand:SI 4 "register_operand" "l"))
10781    (return)]
10782   "TARGET_32BIT
10783    && DEFAULT_ABI == ABI_AIX
10784    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10785   "b %z1"
10786   [(set_attr "type" "branch")
10787    (set_attr "length" "4")])
10788
10789 (define_insn "*sibcall_value_nonlocal_aix64"
10790   [(set (match_operand 0 "" "")
10791         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10792               (match_operand 2 "" "g")))
10793    (use (match_operand:SI 3 "immediate_operand" "O"))
10794    (use (match_operand:SI 4 "register_operand" "l"))
10795    (return)]
10796   "TARGET_64BIT 
10797    && DEFAULT_ABI == ABI_AIX
10798    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10799   "b %z1"
10800   [(set_attr "type" "branch")
10801    (set_attr "length" "4")])
10802
10803 (define_insn "*sibcall_nonlocal_sysv"
10804   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s,s"))
10805          (match_operand 1 "" ""))
10806    (use (match_operand 2 "immediate_operand" "O,n"))
10807    (use (match_operand:SI 3 "register_operand" "l,l"))
10808    (return)]
10809   "(DEFAULT_ABI == ABI_DARWIN
10810      || DEFAULT_ABI == ABI_V4)
10811    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10812   "*
10813 {
10814   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10815     output_asm_insn (\"crxor 6,6,6\", operands);
10816
10817   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10818     output_asm_insn (\"creqv 6,6,6\", operands);
10819
10820   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@plt\" : \"b %z0\";
10821 }"
10822   [(set_attr "type" "branch,branch")
10823    (set_attr "length" "4,8")])
10824
10825 (define_expand "sibcall_value"
10826   [(parallel [(set (match_operand 0 "register_operand" "")
10827                 (call (mem:SI (match_operand 1 "address_operand" ""))
10828                       (match_operand 2 "" "")))
10829               (use (match_operand 3 "" ""))
10830               (use (match_operand 4 "" ""))
10831               (return)])]
10832   ""
10833   "
10834 {
10835 #if TARGET_MACHO
10836   if (MACHOPIC_INDIRECT)
10837     operands[1] = machopic_indirect_call_target (operands[1]);
10838 #endif
10839
10840   if (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != CONST_INT)
10841     abort ();
10842
10843   operands[1] = XEXP (operands[1], 0);
10844   operands[4] = gen_reg_rtx (SImode);
10845
10846 }")
10847
10848 (define_insn "*sibcall_value_nonlocal_sysv"
10849   [(set (match_operand 0 "" "")
10850         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s,s"))
10851               (match_operand 2 "" "")))
10852    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10853    (use (match_operand:SI 4 "register_operand" "l,l"))
10854    (return)]
10855   "(DEFAULT_ABI == ABI_DARWIN
10856        || DEFAULT_ABI == ABI_V4)
10857    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10858   "*
10859 {
10860   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10861     output_asm_insn (\"crxor 6,6,6\", operands);
10862
10863   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10864     output_asm_insn (\"creqv 6,6,6\", operands);
10865
10866   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@plt\" : \"b %z1\";
10867 }"
10868   [(set_attr "type" "branch,branch")
10869    (set_attr "length" "4,8")])
10870
10871 (define_expand "sibcall_epilogue"
10872   [(use (const_int 0))]
10873   "TARGET_SCHED_PROLOG"
10874   "
10875 {
10876       rs6000_emit_epilogue (TRUE);
10877       DONE;
10878 }")
10879
10880 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
10881 ;; all of memory.  This blocks insns from being moved across this point.
10882
10883 (define_insn "blockage"
10884   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
10885   ""
10886   "")
10887 \f
10888 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
10889 ;; signed & unsigned, and one type of branch.
10890 ;;
10891 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
10892 ;; insns, and branches.  We store the operands of compares until we see
10893 ;; how it is used.
10894 (define_expand "cmpsi"
10895   [(set (cc0)
10896         (compare (match_operand:SI 0 "gpc_reg_operand" "")
10897                  (match_operand:SI 1 "reg_or_short_operand" "")))]
10898   ""
10899   "
10900 {
10901   /* Take care of the possibility that operands[1] might be negative but
10902      this might be a logical operation.  That insn doesn't exist.  */
10903   if (GET_CODE (operands[1]) == CONST_INT
10904       && INTVAL (operands[1]) < 0)
10905     operands[1] = force_reg (SImode, operands[1]);
10906
10907   rs6000_compare_op0 = operands[0];
10908   rs6000_compare_op1 = operands[1];
10909   rs6000_compare_fp_p = 0;
10910   DONE;
10911 }")
10912
10913 (define_expand "cmpdi"
10914   [(set (cc0)
10915         (compare (match_operand:DI 0 "gpc_reg_operand" "")
10916                  (match_operand:DI 1 "reg_or_short_operand" "")))]
10917   "TARGET_POWERPC64"
10918   "
10919 {
10920   /* Take care of the possibility that operands[1] might be negative but
10921      this might be a logical operation.  That insn doesn't exist.  */
10922   if (GET_CODE (operands[1]) == CONST_INT
10923       && INTVAL (operands[1]) < 0)
10924     operands[1] = force_reg (DImode, operands[1]);
10925
10926   rs6000_compare_op0 = operands[0];
10927   rs6000_compare_op1 = operands[1];
10928   rs6000_compare_fp_p = 0;
10929   DONE;
10930 }")
10931
10932 (define_expand "cmpsf"
10933   [(set (cc0) (compare (match_operand:SF 0 "gpc_reg_operand" "")
10934                        (match_operand:SF 1 "gpc_reg_operand" "")))]
10935   "TARGET_HARD_FLOAT"
10936   "
10937 {
10938   rs6000_compare_op0 = operands[0];
10939   rs6000_compare_op1 = operands[1];
10940   rs6000_compare_fp_p = 1;
10941   DONE;
10942 }")
10943
10944 (define_expand "cmpdf"
10945   [(set (cc0) (compare (match_operand:DF 0 "gpc_reg_operand" "")
10946                        (match_operand:DF 1 "gpc_reg_operand" "")))]
10947   "TARGET_HARD_FLOAT && TARGET_FPRS"
10948   "
10949 {
10950   rs6000_compare_op0 = operands[0];
10951   rs6000_compare_op1 = operands[1];
10952   rs6000_compare_fp_p = 1;
10953   DONE;
10954 }")
10955
10956 (define_expand "cmptf"
10957   [(set (cc0) (compare (match_operand:TF 0 "gpc_reg_operand" "")
10958                        (match_operand:TF 1 "gpc_reg_operand" "")))]
10959   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT
10960    && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
10961   "
10962 {
10963   rs6000_compare_op0 = operands[0];
10964   rs6000_compare_op1 = operands[1];
10965   rs6000_compare_fp_p = 1;
10966   DONE;
10967 }")
10968
10969 (define_expand "beq"
10970   [(use (match_operand 0 "" ""))]
10971   ""
10972   "{ rs6000_emit_cbranch (EQ, operands[0]); DONE; }")
10973
10974 (define_expand "bne"
10975   [(use (match_operand 0 "" ""))]
10976   ""
10977   "{ rs6000_emit_cbranch (NE, operands[0]); DONE; }")
10978
10979 (define_expand "bge"
10980   [(use (match_operand 0 "" ""))]
10981   ""
10982   "{ rs6000_emit_cbranch (GE, operands[0]); DONE; }")
10983
10984 (define_expand "bgt"
10985   [(use (match_operand 0 "" ""))]
10986   ""
10987   "{ rs6000_emit_cbranch (GT, operands[0]); DONE; }")
10988
10989 (define_expand "ble"
10990   [(use (match_operand 0 "" ""))]
10991   ""
10992   "{ rs6000_emit_cbranch (LE, operands[0]); DONE; }")
10993
10994 (define_expand "blt"
10995   [(use (match_operand 0 "" ""))]
10996   ""
10997   "{ rs6000_emit_cbranch (LT, operands[0]); DONE; }")
10998
10999 (define_expand "bgeu"
11000   [(use (match_operand 0 "" ""))]
11001   ""
11002   "{ rs6000_emit_cbranch (GEU, operands[0]); DONE; }")
11003
11004 (define_expand "bgtu"
11005   [(use (match_operand 0 "" ""))]
11006   ""
11007   "{ rs6000_emit_cbranch (GTU, operands[0]); DONE; }")
11008
11009 (define_expand "bleu"
11010   [(use (match_operand 0 "" ""))]
11011   ""
11012   "{ rs6000_emit_cbranch (LEU, operands[0]); DONE; }")
11013
11014 (define_expand "bltu"
11015   [(use (match_operand 0 "" ""))]
11016   ""
11017   "{ rs6000_emit_cbranch (LTU, operands[0]); DONE; }")
11018
11019 (define_expand "bunordered"
11020   [(use (match_operand 0 "" ""))]
11021   ""
11022   "{ rs6000_emit_cbranch (UNORDERED, operands[0]); DONE; }")
11023
11024 (define_expand "bordered"
11025   [(use (match_operand 0 "" ""))]
11026   ""
11027   "{ rs6000_emit_cbranch (ORDERED, operands[0]); DONE; }")
11028
11029 (define_expand "buneq"
11030   [(use (match_operand 0 "" ""))]
11031   ""
11032   "{ rs6000_emit_cbranch (UNEQ, operands[0]); DONE; }")
11033
11034 (define_expand "bunge"
11035   [(use (match_operand 0 "" ""))]
11036   ""
11037   "{ rs6000_emit_cbranch (UNGE, operands[0]); DONE; }")
11038
11039 (define_expand "bungt"
11040   [(use (match_operand 0 "" ""))]
11041   ""
11042   "{ rs6000_emit_cbranch (UNGT, operands[0]); DONE; }")
11043
11044 (define_expand "bunle"
11045   [(use (match_operand 0 "" ""))]
11046   ""
11047   "{ rs6000_emit_cbranch (UNLE, operands[0]); DONE; }")
11048
11049 (define_expand "bunlt"
11050   [(use (match_operand 0 "" ""))]
11051   ""
11052   "{ rs6000_emit_cbranch (UNLT, operands[0]); DONE; }")
11053
11054 (define_expand "bltgt"
11055   [(use (match_operand 0 "" ""))]
11056   ""
11057   "{ rs6000_emit_cbranch (LTGT, operands[0]); DONE; }")
11058
11059 ;; For SNE, we would prefer that the xor/abs sequence be used for integers.
11060 ;; For SEQ, likewise, except that comparisons with zero should be done
11061 ;; with an scc insns.  However, due to the order that combine see the
11062 ;; resulting insns, we must, in fact, allow SEQ for integers.  Fail in
11063 ;; the cases we don't want to handle.
11064 (define_expand "seq"
11065   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11066   ""
11067   "{ rs6000_emit_sCOND (EQ, operands[0]); DONE; }")
11068
11069 (define_expand "sne"
11070   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11071   ""
11072   "
11073
11074   if (! rs6000_compare_fp_p)
11075     FAIL;
11076
11077   rs6000_emit_sCOND (NE, operands[0]); 
11078   DONE;
11079 }")
11080
11081 ;; A >= 0 is best done the portable way for A an integer.
11082 (define_expand "sge"
11083   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11084   ""
11085   "
11086 {
11087   if (! rs6000_compare_fp_p
11088       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
11089     FAIL;
11090
11091   rs6000_emit_sCOND (GE, operands[0]);
11092   DONE;
11093 }")
11094
11095 ;; A > 0 is best done using the portable sequence, so fail in that case.
11096 (define_expand "sgt"
11097   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11098   ""
11099   "
11100 {
11101   if (! rs6000_compare_fp_p
11102       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
11103     FAIL;
11104
11105   rs6000_emit_sCOND (GT, operands[0]); 
11106   DONE;
11107 }")
11108
11109 ;; A <= 0 is best done the portable way for A an integer.
11110 (define_expand "sle"
11111   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11112   ""
11113   "
11114 {
11115   if (! rs6000_compare_fp_p
11116       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
11117     FAIL;
11118
11119   rs6000_emit_sCOND (LE, operands[0]); 
11120   DONE;
11121 }")
11122
11123 ;; A < 0 is best done in the portable way for A an integer.
11124 (define_expand "slt"
11125   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11126   ""
11127   "
11128 {
11129   if (! rs6000_compare_fp_p 
11130       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
11131     FAIL;
11132
11133   rs6000_emit_sCOND (LT, operands[0]); 
11134   DONE;
11135 }")
11136
11137 (define_expand "sgeu"
11138   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11139   ""
11140   "{ rs6000_emit_sCOND (GEU, operands[0]); DONE; }")
11141
11142 (define_expand "sgtu"
11143   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11144   ""
11145   "{ rs6000_emit_sCOND (GTU, operands[0]); DONE; }")
11146
11147 (define_expand "sleu"
11148   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11149   ""
11150   "{ rs6000_emit_sCOND (LEU, operands[0]); DONE; }")
11151
11152 (define_expand "sltu"
11153   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11154   ""
11155   "{ rs6000_emit_sCOND (LTU, operands[0]); DONE; }")
11156
11157 (define_expand "sunordered"
11158   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11159   ""
11160   "{ rs6000_emit_sCOND (UNORDERED, operands[0]); DONE; }")
11161
11162 (define_expand "sordered"
11163   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11164   ""
11165   "{ rs6000_emit_sCOND (ORDERED, operands[0]); DONE; }")
11166
11167 (define_expand "suneq"
11168   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11169   ""
11170   "{ rs6000_emit_sCOND (UNEQ, operands[0]); DONE; }")
11171
11172 (define_expand "sunge"
11173   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11174   ""
11175   "{ rs6000_emit_sCOND (UNGE, operands[0]); DONE; }")
11176
11177 (define_expand "sungt"
11178   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11179   ""
11180   "{ rs6000_emit_sCOND (UNGT, operands[0]); DONE; }")
11181
11182 (define_expand "sunle"
11183   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11184   ""
11185   "{ rs6000_emit_sCOND (UNLE, operands[0]); DONE; }")
11186
11187 (define_expand "sunlt"
11188   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11189   ""
11190   "{ rs6000_emit_sCOND (UNLT, operands[0]); DONE; }")
11191
11192 (define_expand "sltgt"
11193   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11194   ""
11195   "{ rs6000_emit_sCOND (LTGT, operands[0]); DONE; }")
11196
11197 \f
11198 ;; Here are the actual compare insns.
11199 (define_insn "*cmpsi_internal1"
11200   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11201         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11202                     (match_operand:SI 2 "reg_or_short_operand" "rI")))]
11203   ""
11204   "{cmp%I2|cmpw%I2} %0,%1,%2"
11205   [(set_attr "type" "cmp")])
11206
11207 (define_insn "*cmpdi_internal1"
11208   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11209         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "r")
11210                     (match_operand:DI 2 "reg_or_short_operand" "rI")))]
11211   "TARGET_POWERPC64"
11212   "cmpd%I2 %0,%1,%2"
11213   [(set_attr "type" "cmp")])
11214
11215 ;; If we are comparing a register for equality with a large constant,
11216 ;; we can do this with an XOR followed by a compare.  But we need a scratch
11217 ;; register for the result of the XOR.
11218
11219 (define_split
11220   [(set (match_operand:CC 0 "cc_reg_operand" "")
11221         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11222                     (match_operand:SI 2 "non_short_cint_operand" "")))
11223    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
11224   "find_single_use (operands[0], insn, 0)
11225    && (GET_CODE (*find_single_use (operands[0], insn, 0)) == EQ
11226        || GET_CODE (*find_single_use (operands[0], insn, 0)) == NE)"
11227   [(set (match_dup 3) (xor:SI (match_dup 1) (match_dup 4)))
11228    (set (match_dup 0) (compare:CC (match_dup 3) (match_dup 5)))]
11229   "
11230 {
11231   /* Get the constant we are comparing against, C,  and see what it looks like
11232      sign-extended to 16 bits.  Then see what constant could be XOR'ed
11233      with C to get the sign-extended value.  */
11234
11235   HOST_WIDE_INT c = INTVAL (operands[2]);
11236   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
11237   HOST_WIDE_INT xorv = c ^ sextc;
11238
11239   operands[4] = GEN_INT (xorv);
11240   operands[5] = GEN_INT (sextc);
11241 }")
11242
11243 (define_insn "*cmpsi_internal2"
11244   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11245         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11246                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
11247   ""
11248   "{cmpl%I2|cmplw%I2} %0,%1,%b2"
11249   [(set_attr "type" "cmp")])
11250
11251 (define_insn "*cmpdi_internal2"
11252   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11253         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
11254                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
11255   ""
11256   "cmpld%I2 %0,%1,%b2"
11257   [(set_attr "type" "cmp")])
11258
11259 ;; The following two insns don't exist as single insns, but if we provide
11260 ;; them, we can swap an add and compare, which will enable us to overlap more
11261 ;; of the required delay between a compare and branch.  We generate code for
11262 ;; them by splitting.
11263
11264 (define_insn ""
11265   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
11266         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11267                     (match_operand:SI 2 "short_cint_operand" "i")))
11268    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11269         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11270   ""
11271   "#"
11272   [(set_attr "length" "8")])
11273
11274 (define_insn ""
11275   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
11276         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11277                        (match_operand:SI 2 "u_short_cint_operand" "i")))
11278    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11279         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11280   ""
11281   "#"
11282   [(set_attr "length" "8")])
11283
11284 (define_split
11285   [(set (match_operand:CC 3 "cc_reg_operand" "")
11286         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11287                     (match_operand:SI 2 "short_cint_operand" "")))
11288    (set (match_operand:SI 0 "gpc_reg_operand" "")
11289         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11290   ""
11291   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
11292    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11293
11294 (define_split
11295   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
11296         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
11297                        (match_operand:SI 2 "u_short_cint_operand" "")))
11298    (set (match_operand:SI 0 "gpc_reg_operand" "")
11299         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11300   ""
11301   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
11302    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11303
11304 (define_insn "*cmpsf_internal1"
11305   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11306         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
11307                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
11308   "TARGET_HARD_FLOAT && TARGET_FPRS"
11309   "fcmpu %0,%1,%2"
11310   [(set_attr "type" "fpcompare")])
11311
11312 (define_insn "*cmpdf_internal1"
11313   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11314         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "f")
11315                       (match_operand:DF 2 "gpc_reg_operand" "f")))]
11316   "TARGET_HARD_FLOAT && TARGET_FPRS"
11317   "fcmpu %0,%1,%2"
11318   [(set_attr "type" "fpcompare")])
11319
11320 ;; Only need to compare second words if first words equal
11321 (define_insn "*cmptf_internal1"
11322   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11323         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11324                       (match_operand:TF 2 "gpc_reg_operand" "f")))]
11325   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
11326    && TARGET_LONG_DOUBLE_128"
11327   "fcmpu %0,%1,%2\;bne %0,$+4\;fcmpu %0,%L1,%L2"
11328   [(set_attr "type" "fpcompare")
11329    (set_attr "length" "12")])
11330 \f
11331 ;; Now we have the scc insns.  We can do some combinations because of the
11332 ;; way the machine works.
11333 ;;
11334 ;; Note that this is probably faster if we can put an insn between the
11335 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
11336 ;; cases the insns below which don't use an intermediate CR field will
11337 ;; be used instead.
11338 (define_insn ""
11339   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11340         (match_operator:SI 1 "scc_comparison_operator"
11341                            [(match_operand 2 "cc_reg_operand" "y")
11342                             (const_int 0)]))]
11343   ""
11344   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11345   [(set (attr "type")
11346      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11347                 (const_string "mfcrf")
11348            ]
11349         (const_string "mfcr")))
11350    (set_attr "length" "12")])
11351
11352 ;; Same as above, but get the OV/ORDERED bit.
11353 (define_insn "move_from_CR_ov_bit"
11354   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11355         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_OV))]
11356   "TARGET_ISEL"
11357   "mfcr %0\;{rlinm|rlwinm} %0,%0,%t1,1"
11358   [(set_attr "type" "mfcr")
11359    (set_attr "length" "12")])
11360
11361 (define_insn ""
11362   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11363         (match_operator:DI 1 "scc_comparison_operator"
11364                            [(match_operand 2 "cc_reg_operand" "y")
11365                             (const_int 0)]))]
11366   "TARGET_POWERPC64"
11367   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11368   [(set (attr "type")
11369      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11370                 (const_string "mfcrf")
11371            ]
11372         (const_string "mfcr")))
11373    (set_attr "length" "12")])
11374
11375 (define_insn ""
11376   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11377         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11378                                        [(match_operand 2 "cc_reg_operand" "y,y")
11379                                         (const_int 0)])
11380                     (const_int 0)))
11381    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11382         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11383   "! TARGET_POWERPC64"
11384   "@
11385    mfcr %3%Q2\;{rlinm.|rlwinm.} %3,%3,%J1,1
11386    #"
11387   [(set_attr "type" "delayed_compare")
11388    (set_attr "length" "12,16")])
11389
11390 (define_split
11391   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11392         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11393                                        [(match_operand 2 "cc_reg_operand" "")
11394                                         (const_int 0)])
11395                     (const_int 0)))
11396    (set (match_operand:SI 3 "gpc_reg_operand" "")
11397         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11398   "! TARGET_POWERPC64 && reload_completed"
11399   [(set (match_dup 3)
11400         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
11401    (set (match_dup 0)
11402         (compare:CC (match_dup 3)
11403                     (const_int 0)))]
11404   "")
11405
11406 (define_insn ""
11407   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11408         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11409                                       [(match_operand 2 "cc_reg_operand" "y")
11410                                        (const_int 0)])
11411                    (match_operand:SI 3 "const_int_operand" "n")))]
11412   ""
11413   "*
11414 {
11415   int is_bit = ccr_bit (operands[1], 1);
11416   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11417   int count;
11418
11419   if (is_bit >= put_bit)
11420     count = is_bit - put_bit;
11421   else
11422     count = 32 - (put_bit - is_bit);
11423
11424   operands[4] = GEN_INT (count);
11425   operands[5] = GEN_INT (put_bit);
11426
11427   return \"mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
11428 }"
11429   [(set (attr "type")
11430      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11431                 (const_string "mfcrf")
11432            ]
11433         (const_string "mfcr")))
11434    (set_attr "length" "12")])
11435
11436 (define_insn ""
11437   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11438         (compare:CC
11439          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11440                                        [(match_operand 2 "cc_reg_operand" "y,y")
11441                                         (const_int 0)])
11442                     (match_operand:SI 3 "const_int_operand" "n,n"))
11443          (const_int 0)))
11444    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
11445         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11446                    (match_dup 3)))]
11447   ""
11448   "*
11449 {
11450   int is_bit = ccr_bit (operands[1], 1);
11451   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11452   int count;
11453
11454   /* Force split for non-cc0 compare.  */
11455   if (which_alternative == 1)
11456      return \"#\";
11457
11458   if (is_bit >= put_bit)
11459     count = is_bit - put_bit;
11460   else
11461     count = 32 - (put_bit - is_bit);
11462
11463   operands[5] = GEN_INT (count);
11464   operands[6] = GEN_INT (put_bit);
11465
11466   return \"mfcr %4%Q2\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
11467 }"
11468   [(set_attr "type" "delayed_compare")
11469    (set_attr "length" "12,16")])
11470
11471 (define_split
11472   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11473         (compare:CC
11474          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11475                                        [(match_operand 2 "cc_reg_operand" "")
11476                                         (const_int 0)])
11477                     (match_operand:SI 3 "const_int_operand" ""))
11478          (const_int 0)))
11479    (set (match_operand:SI 4 "gpc_reg_operand" "")
11480         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11481                    (match_dup 3)))]
11482   "reload_completed"
11483   [(set (match_dup 4)
11484         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11485                    (match_dup 3)))
11486    (set (match_dup 0)
11487         (compare:CC (match_dup 4)
11488                     (const_int 0)))]
11489   "")
11490
11491 ;; There is a 3 cycle delay between consecutive mfcr instructions
11492 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
11493
11494 (define_peephole
11495   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11496         (match_operator:SI 1 "scc_comparison_operator"
11497                            [(match_operand 2 "cc_reg_operand" "y")
11498                             (const_int 0)]))
11499    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
11500         (match_operator:SI 4 "scc_comparison_operator"
11501                            [(match_operand 5 "cc_reg_operand" "y")
11502                             (const_int 0)]))]
11503   "REGNO (operands[2]) != REGNO (operands[5])"
11504   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11505   [(set_attr "type" "mfcr")
11506    (set_attr "length" "20")])
11507
11508 (define_peephole
11509   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11510         (match_operator:DI 1 "scc_comparison_operator"
11511                            [(match_operand 2 "cc_reg_operand" "y")
11512                             (const_int 0)]))
11513    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
11514         (match_operator:DI 4 "scc_comparison_operator"
11515                            [(match_operand 5 "cc_reg_operand" "y")
11516                             (const_int 0)]))]
11517   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
11518   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11519   [(set_attr "type" "mfcr")
11520    (set_attr "length" "20")])
11521
11522 ;; There are some scc insns that can be done directly, without a compare.
11523 ;; These are faster because they don't involve the communications between
11524 ;; the FXU and branch units.   In fact, we will be replacing all of the
11525 ;; integer scc insns here or in the portable methods in emit_store_flag.
11526 ;;
11527 ;; Also support (neg (scc ..)) since that construct is used to replace
11528 ;; branches, (plus (scc ..) ..) since that construct is common and
11529 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
11530 ;; cases where it is no more expensive than (neg (scc ..)).
11531
11532 ;; Have reload force a constant into a register for the simple insns that
11533 ;; otherwise won't accept constants.  We do this because it is faster than
11534 ;; the cmp/mfcr sequence we would otherwise generate.
11535
11536 (define_insn ""
11537   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
11538         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11539                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I")))
11540    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
11541   "! TARGET_POWERPC64"
11542   "@
11543    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11544    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
11545    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11546    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11547    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
11548   [(set_attr "length" "12,8,12,12,12")])
11549
11550 (define_insn ""
11551   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r")
11552         (eq:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r")
11553                (match_operand:DI 2 "reg_or_cint_operand" "r,O,K,J,I")))
11554    (clobber (match_scratch:DI 3 "=r,&r,r,r,r"))]
11555   "TARGET_POWERPC64"
11556   "@
11557    xor %0,%1,%2\;subfic %3,%0,0\;adde %0,%3,%0
11558    subfic %3,%1,0\;adde %0,%3,%1
11559    xori %0,%1,%b2\;subfic %3,%0,0\;adde %0,%3,%0
11560    xoris %0,%1,%u2\;subfic %3,%0,0\;adde %0,%3,%0
11561    subfic %0,%1,%2\;subfic %3,%0,0\;adde %0,%3,%0"
11562   [(set_attr "length" "12,8,12,12,12")])
11563
11564 (define_insn ""
11565   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11566         (compare:CC
11567          (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11568                 (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11569          (const_int 0)))
11570    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
11571         (eq:SI (match_dup 1) (match_dup 2)))
11572    (clobber (match_scratch:SI 3 "=r,&r,r,r,r,r,&r,r,r,r"))]
11573   "! TARGET_POWERPC64"
11574   "@
11575    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11576    {sfi|subfic} %3,%1,0\;{ae.|adde.} %0,%3,%1
11577    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11578    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11579    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11580    #
11581    #
11582    #
11583    #
11584    #"
11585   [(set_attr "type" "compare")
11586    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11587
11588 (define_split
11589   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11590         (compare:CC
11591          (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11592                 (match_operand:SI 2 "reg_or_cint_operand" ""))
11593          (const_int 0)))
11594    (set (match_operand:SI 0 "gpc_reg_operand" "")
11595         (eq:SI (match_dup 1) (match_dup 2)))
11596    (clobber (match_scratch:SI 3 ""))]
11597   "! TARGET_POWERPC64 && reload_completed"
11598   [(parallel [(set (match_dup 0)
11599         (eq:SI (match_dup 1) (match_dup 2)))
11600    (clobber (match_dup 3))])
11601    (set (match_dup 4)
11602         (compare:CC (match_dup 0)
11603                     (const_int 0)))]
11604   "")
11605
11606 (define_insn ""
11607   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11608         (compare:CC
11609          (eq:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11610                 (match_operand:DI 2 "reg_or_cint_operand" "r,O,K,J,I,r,O,K,J,I"))
11611          (const_int 0)))
11612    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
11613         (eq:DI (match_dup 1) (match_dup 2)))
11614    (clobber (match_scratch:DI 3 "=r,&r,r,r,r,r,&r,r,r,r"))]
11615   "TARGET_POWERPC64"
11616   "@
11617    xor %0,%1,%2\;subfic %3,%0,0\;adde. %0,%3,%0
11618    subfic %3,%1,0\;adde. %0,%3,%1
11619    xori %0,%1,%b2\;subfic %3,%0,0\;adde. %0,%3,%0
11620    xoris %0,%1,%u2\;subfic %3,%0,0\;adde. %0,%3,%0
11621    subfic %0,%1,%2\;subfic %3,%0,0\;adde. %0,%3,%0
11622    #
11623    #
11624    #
11625    #
11626    #"
11627   [(set_attr "type" "compare")
11628    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11629
11630 (define_split
11631   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11632         (compare:CC
11633          (eq:DI (match_operand:DI 1 "gpc_reg_operand" "")
11634                 (match_operand:DI 2 "reg_or_cint_operand" ""))
11635          (const_int 0)))
11636    (set (match_operand:DI 0 "gpc_reg_operand" "")
11637         (eq:DI (match_dup 1) (match_dup 2)))
11638    (clobber (match_scratch:DI 3 ""))]
11639   "TARGET_POWERPC64 && reload_completed"
11640   [(parallel [(set (match_dup 0)
11641         (eq:DI (match_dup 1) (match_dup 2)))
11642    (clobber (match_dup 3))])
11643    (set (match_dup 4)
11644         (compare:CC (match_dup 0)
11645                     (const_int 0)))]
11646   "")
11647
11648 ;; We have insns of the form shown by the first define_insn below.  If
11649 ;; there is something inside the comparison operation, we must split it.
11650 (define_split
11651   [(set (match_operand:SI 0 "gpc_reg_operand" "")
11652         (plus:SI (match_operator 1 "comparison_operator"
11653                                  [(match_operand:SI 2 "" "")
11654                                   (match_operand:SI 3
11655                                                     "reg_or_cint_operand" "")])
11656                  (match_operand:SI 4 "gpc_reg_operand" "")))
11657    (clobber (match_operand:SI 5 "register_operand" ""))]
11658   "! gpc_reg_operand (operands[2], SImode)"
11659   [(set (match_dup 5) (match_dup 2))
11660    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
11661                                (match_dup 4)))])
11662
11663 (define_insn ""
11664   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
11665         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11666                         (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I"))
11667                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
11668   "! TARGET_POWERPC64"
11669   "@
11670    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11671    {sfi|subfic} %0,%1,0\;{aze|addze} %0,%3
11672    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11673    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11674    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
11675   [(set_attr "length" "12,8,12,12,12")])
11676
11677 (define_insn ""
11678   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11679         (compare:CC
11680          (plus:SI
11681           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11682                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11683           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11684          (const_int 0)))
11685    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
11686   "! TARGET_POWERPC64"
11687   "@
11688    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11689    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
11690    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11691    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11692    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11693    #
11694    #
11695    #
11696    #
11697    #"
11698   [(set_attr "type" "compare")
11699    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11700
11701 (define_split
11702   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11703         (compare:CC
11704          (plus:SI
11705           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11706                  (match_operand:SI 2 "reg_or_cint_operand" ""))
11707           (match_operand:SI 3 "gpc_reg_operand" ""))
11708          (const_int 0)))
11709    (clobber (match_scratch:SI 4 ""))]
11710   "! TARGET_POWERPC64 && reload_completed"
11711   [(set (match_dup 4)
11712         (plus:SI (eq:SI (match_dup 1)
11713                  (match_dup 2))
11714           (match_dup 3)))
11715    (set (match_dup 0)
11716         (compare:CC (match_dup 4)
11717                     (const_int 0)))]
11718   "")
11719
11720 (define_insn ""
11721   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11722         (compare:CC
11723          (plus:SI
11724           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11725                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11726           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11727          (const_int 0)))
11728    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
11729         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11730   "! TARGET_POWERPC64"
11731   "@
11732    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11733    {sfi|subfic} %0,%1,0\;{aze.|addze.} %0,%3
11734    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11735    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11736    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11737    #
11738    #
11739    #
11740    #
11741    #"
11742   [(set_attr "type" "compare")
11743    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11744
11745 (define_split
11746   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11747         (compare:CC
11748          (plus:SI
11749           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11750                  (match_operand:SI 2 "reg_or_cint_operand" ""))
11751           (match_operand:SI 3 "gpc_reg_operand" ""))
11752          (const_int 0)))
11753    (set (match_operand:SI 0 "gpc_reg_operand" "")
11754         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11755   "! TARGET_POWERPC64 && reload_completed"
11756   [(set (match_dup 0)
11757         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
11758    (set (match_dup 4)
11759         (compare:CC (match_dup 0)
11760                     (const_int 0)))]
11761   "")
11762
11763 (define_insn ""
11764   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
11765         (neg:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11766                        (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I"))))]
11767   "! TARGET_POWERPC64"
11768   "@
11769    xor %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11770    {ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0
11771    {xoril|xori} %0,%1,%b2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11772    {xoriu|xoris} %0,%1,%u2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11773    {sfi|subfic} %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
11774    [(set_attr "length" "12,8,12,12,12")])
11775
11776 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
11777 ;; since it nabs/sr is just as fast.
11778 (define_insn "*ne0"
11779   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
11780         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
11781                      (const_int 31)))
11782    (clobber (match_scratch:SI 2 "=&r"))]
11783   "! TARGET_POWER && ! TARGET_POWERPC64 && !TARGET_ISEL"
11784   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
11785   [(set_attr "length" "8")])
11786
11787 (define_insn ""
11788   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11789         (lshiftrt:DI (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
11790                      (const_int 63)))
11791    (clobber (match_scratch:DI 2 "=&r"))]
11792   "TARGET_POWERPC64"
11793   "addic %2,%1,-1\;subfe %0,%2,%1"
11794   [(set_attr "length" "8")])
11795
11796 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
11797 (define_insn ""
11798   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11799         (plus:SI (lshiftrt:SI
11800                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
11801                   (const_int 31))
11802                  (match_operand:SI 2 "gpc_reg_operand" "r")))
11803    (clobber (match_scratch:SI 3 "=&r"))]
11804   "! TARGET_POWERPC64"
11805   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
11806   [(set_attr "length" "8")])
11807
11808 (define_insn ""
11809   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11810         (plus:DI (lshiftrt:DI
11811                   (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
11812                   (const_int 63))
11813                  (match_operand:DI 2 "gpc_reg_operand" "r")))
11814    (clobber (match_scratch:DI 3 "=&r"))]
11815   "TARGET_POWERPC64"
11816   "addic %3,%1,-1\;addze %0,%2"
11817   [(set_attr "length" "8")])
11818
11819 (define_insn ""
11820   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11821         (compare:CC
11822          (plus:SI (lshiftrt:SI
11823                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
11824                    (const_int 31))
11825                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
11826          (const_int 0)))
11827    (clobber (match_scratch:SI 3 "=&r,&r"))
11828    (clobber (match_scratch:SI 4 "=X,&r"))]
11829   "! TARGET_POWERPC64"
11830   "@
11831    {ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2
11832    #"
11833   [(set_attr "type" "compare")
11834    (set_attr "length" "8,12")])
11835
11836 (define_split
11837   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11838         (compare:CC
11839          (plus:SI (lshiftrt:SI
11840                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11841                    (const_int 31))
11842                   (match_operand:SI 2 "gpc_reg_operand" ""))
11843          (const_int 0)))
11844    (clobber (match_scratch:SI 3 ""))
11845    (clobber (match_scratch:SI 4 ""))]
11846   "! TARGET_POWERPC64 && reload_completed"
11847   [(parallel [(set (match_dup 3)
11848                    (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1)))
11849                                          (const_int 31))
11850                             (match_dup 2)))
11851               (clobber (match_dup 4))])
11852    (set (match_dup 0)
11853         (compare:CC (match_dup 3)
11854                     (const_int 0)))]
11855   "")
11856
11857 (define_insn ""
11858   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11859         (compare:CC
11860          (plus:DI (lshiftrt:DI
11861                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
11862                    (const_int 63))
11863                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
11864          (const_int 0)))
11865    (clobber (match_scratch:DI 3 "=&r,&r"))]
11866   "TARGET_POWERPC64"
11867   "@
11868    addic %3,%1,-1\;addze. %3,%2
11869    #"
11870   [(set_attr "type" "compare")
11871    (set_attr "length" "8,12")])
11872
11873 (define_split
11874   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11875         (compare:CC
11876          (plus:DI (lshiftrt:DI
11877                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
11878                    (const_int 63))
11879                   (match_operand:DI 2 "gpc_reg_operand" ""))
11880          (const_int 0)))
11881    (clobber (match_scratch:DI 3 ""))]
11882   "TARGET_POWERPC64 && reload_completed"
11883   [(set (match_dup 3)
11884         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1)))
11885                    (const_int 63))
11886                   (match_dup 2)))
11887    (set (match_dup 0)
11888         (compare:CC (match_dup 3)
11889                     (const_int 0)))]
11890   "")
11891
11892 (define_insn ""
11893   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
11894         (compare:CC
11895          (plus:SI (lshiftrt:SI
11896                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
11897                    (const_int 31))
11898                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
11899          (const_int 0)))
11900    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11901         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11902                  (match_dup 2)))
11903    (clobber (match_scratch:SI 3 "=&r,&r"))]
11904   "! TARGET_POWERPC64"
11905   "@
11906    {ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2
11907    #"
11908   [(set_attr "type" "compare")
11909    (set_attr "length" "8,12")])
11910
11911 (define_split
11912   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11913         (compare:CC
11914          (plus:SI (lshiftrt:SI
11915                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11916                    (const_int 31))
11917                   (match_operand:SI 2 "gpc_reg_operand" ""))
11918          (const_int 0)))
11919    (set (match_operand:SI 0 "gpc_reg_operand" "")
11920         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11921                  (match_dup 2)))
11922    (clobber (match_scratch:SI 3 ""))]
11923   "! TARGET_POWERPC64 && reload_completed"
11924   [(parallel [(set (match_dup 0)
11925         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11926                  (match_dup 2)))
11927    (clobber (match_dup 3))])
11928    (set (match_dup 4)
11929         (compare:CC (match_dup 0)
11930                     (const_int 0)))]
11931   "")
11932
11933 (define_insn ""
11934   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
11935         (compare:CC
11936          (plus:DI (lshiftrt:DI
11937                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
11938                    (const_int 63))
11939                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
11940          (const_int 0)))
11941    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
11942         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11943                  (match_dup 2)))
11944    (clobber (match_scratch:DI 3 "=&r,&r"))]
11945   "TARGET_POWERPC64"
11946   "@
11947    addic %3,%1,-1\;addze. %0,%2
11948    #"
11949   [(set_attr "type" "compare")
11950    (set_attr "length" "8,12")])
11951
11952 (define_split
11953   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11954         (compare:CC
11955          (plus:DI (lshiftrt:DI
11956                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
11957                    (const_int 63))
11958                   (match_operand:DI 2 "gpc_reg_operand" ""))
11959          (const_int 0)))
11960    (set (match_operand:DI 0 "gpc_reg_operand" "")
11961         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11962                  (match_dup 2)))
11963    (clobber (match_scratch:DI 3 ""))]
11964   "TARGET_POWERPC64 && reload_completed"
11965   [(parallel [(set (match_dup 0)
11966         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11967                  (match_dup 2)))
11968    (clobber (match_dup 3))])
11969    (set (match_dup 4)
11970         (compare:CC (match_dup 0)
11971                     (const_int 0)))]
11972   "")
11973
11974 (define_insn ""
11975   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11976         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
11977                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
11978    (clobber (match_scratch:SI 3 "=r,X"))]
11979   "TARGET_POWER"
11980   "@
11981    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
11982    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
11983   [(set_attr "length" "12")])
11984
11985 (define_insn ""
11986   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
11987         (compare:CC
11988          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
11989                 (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
11990          (const_int 0)))
11991    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
11992         (le:SI (match_dup 1) (match_dup 2)))
11993    (clobber (match_scratch:SI 3 "=r,X,r,X"))]
11994   "TARGET_POWER"
11995   "@
11996    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
11997    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31
11998    #
11999    #"
12000   [(set_attr "type" "compare,delayed_compare,compare,delayed_compare")
12001    (set_attr "length" "12,12,16,16")])
12002
12003 (define_split
12004   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12005         (compare:CC
12006          (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12007                 (match_operand:SI 2 "reg_or_short_operand" ""))
12008          (const_int 0)))
12009    (set (match_operand:SI 0 "gpc_reg_operand" "")
12010         (le:SI (match_dup 1) (match_dup 2)))
12011    (clobber (match_scratch:SI 3 ""))]
12012   "TARGET_POWER && reload_completed"
12013   [(parallel [(set (match_dup 0)
12014         (le:SI (match_dup 1) (match_dup 2)))
12015    (clobber (match_dup 3))])
12016    (set (match_dup 4)
12017         (compare:CC (match_dup 0)
12018                     (const_int 0)))]
12019   "")
12020
12021 (define_insn ""
12022   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12023         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12024                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
12025                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12026   "TARGET_POWER"
12027   "@
12028    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
12029    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze|addze} %0,%3"
12030   [(set_attr "length" "12")])
12031
12032 (define_insn ""
12033   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12034         (compare:CC
12035          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12036                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12037                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12038          (const_int 0)))
12039    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12040   "TARGET_POWER"
12041   "@
12042    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12043    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3
12044    #
12045    #"
12046   [(set_attr "type" "compare")
12047    (set_attr "length" "12,12,16,16")])
12048
12049 (define_split
12050   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12051         (compare:CC
12052          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12053                          (match_operand:SI 2 "reg_or_short_operand" ""))
12054                   (match_operand:SI 3 "gpc_reg_operand" ""))
12055          (const_int 0)))
12056    (clobber (match_scratch:SI 4 ""))]
12057   "TARGET_POWER && reload_completed"
12058   [(set (match_dup 4)
12059         (plus:SI (le:SI (match_dup 1) (match_dup 2))
12060                  (match_dup 3)))
12061    (set (match_dup 0)
12062         (compare:CC (match_dup 4)
12063                     (const_int 0)))]
12064   "")
12065
12066 (define_insn ""
12067   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12068         (compare:CC
12069          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12070                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12071                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12072          (const_int 0)))
12073    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12074         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12075   "TARGET_POWER"
12076   "@
12077    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12078    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze.|addze.} %0,%3
12079    #
12080    #"
12081   [(set_attr "type" "compare")
12082    (set_attr "length" "12,12,16,16")])
12083
12084 (define_split
12085   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12086         (compare:CC
12087          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12088                          (match_operand:SI 2 "reg_or_short_operand" ""))
12089                   (match_operand:SI 3 "gpc_reg_operand" ""))
12090          (const_int 0)))
12091    (set (match_operand:SI 0 "gpc_reg_operand" "")
12092         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12093   "TARGET_POWER && reload_completed"
12094   [(set (match_dup 0)
12095         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12096    (set (match_dup 4)
12097         (compare:CC (match_dup 0)
12098                     (const_int 0)))]
12099   "")
12100
12101 (define_insn ""
12102   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12103         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12104                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
12105   "TARGET_POWER"
12106   "@
12107    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
12108    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
12109   [(set_attr "length" "12")])
12110
12111 (define_insn ""
12112   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12113         (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12114                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12115   "! TARGET_POWERPC64"
12116   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12117   [(set_attr "length" "12")])
12118
12119 (define_insn ""
12120   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12121         (leu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
12122                 (match_operand:DI 2 "reg_or_short_operand" "rI")))]
12123   "TARGET_POWERPC64"
12124   "subf%I2c %0,%1,%2\;li %0,0\;adde %0,%0,%0"
12125   [(set_attr "length" "12")])
12126
12127 (define_insn ""
12128   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12129         (compare:CC
12130          (leu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12131                  (match_operand:DI 2 "reg_or_short_operand" "rI,rI"))
12132          (const_int 0)))
12133    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12134         (leu:DI (match_dup 1) (match_dup 2)))]
12135   "TARGET_POWERPC64"
12136   "@
12137    subf%I2c %0,%1,%2\;li %0,0\;adde. %0,%0,%0
12138    #"
12139   [(set_attr "type" "compare")
12140    (set_attr "length" "12,16")])
12141
12142 (define_split
12143   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12144         (compare:CC
12145          (leu:DI (match_operand:DI 1 "gpc_reg_operand" "")
12146                  (match_operand:DI 2 "reg_or_short_operand" ""))
12147          (const_int 0)))
12148    (set (match_operand:DI 0 "gpc_reg_operand" "")
12149         (leu:DI (match_dup 1) (match_dup 2)))]
12150   "TARGET_POWERPC64 && reload_completed"
12151   [(set (match_dup 0)
12152         (leu:DI (match_dup 1) (match_dup 2)))
12153    (set (match_dup 3)
12154         (compare:CC (match_dup 0)
12155                     (const_int 0)))]
12156   "")
12157
12158 (define_insn ""
12159   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12160         (compare:CC
12161          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12162                  (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12163          (const_int 0)))
12164    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12165         (leu:SI (match_dup 1) (match_dup 2)))]
12166   "! TARGET_POWERPC64"
12167   "@
12168    {sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12169    #"
12170   [(set_attr "type" "compare")
12171    (set_attr "length" "12,16")])
12172
12173 (define_split
12174   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12175         (compare:CC
12176          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12177                  (match_operand:SI 2 "reg_or_short_operand" ""))
12178          (const_int 0)))
12179    (set (match_operand:SI 0 "gpc_reg_operand" "")
12180         (leu:SI (match_dup 1) (match_dup 2)))]
12181   "! TARGET_POWERPC64 && reload_completed"
12182   [(set (match_dup 0)
12183         (leu:SI (match_dup 1) (match_dup 2)))
12184    (set (match_dup 3)
12185         (compare:CC (match_dup 0)
12186                     (const_int 0)))]
12187   "")
12188
12189 (define_insn ""
12190   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12191         (compare:CC
12192          (leu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12193                  (match_operand:DI 2 "reg_or_short_operand" "rI,rI"))
12194          (const_int 0)))
12195    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12196         (leu:DI (match_dup 1) (match_dup 2)))]
12197   "TARGET_POWERPC64"
12198   "@
12199    subf%I2c %0,%1,%2\;li %0,0\;adde. %0,%0,%0
12200    #"
12201   [(set_attr "type" "compare")
12202    (set_attr "length" "12,16")])
12203
12204 (define_insn ""
12205   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12206         (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12207                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
12208                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12209   "! TARGET_POWERPC64"
12210   "{sf%I2|subf%I2c} %0,%1,%2\;{aze|addze} %0,%3"
12211   [(set_attr "length" "8")])
12212
12213 (define_insn ""
12214   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12215         (compare:CC
12216          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12217                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12218                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12219          (const_int 0)))
12220    (clobber (match_scratch:SI 4 "=&r,&r"))]
12221   "! TARGET_POWERPC64"
12222   "@
12223    {sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3
12224    #"
12225   [(set_attr "type" "compare")
12226    (set_attr "length" "8,12")])
12227
12228 (define_split
12229   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12230         (compare:CC
12231          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12232                           (match_operand:SI 2 "reg_or_short_operand" ""))
12233                   (match_operand:SI 3 "gpc_reg_operand" ""))
12234          (const_int 0)))
12235    (clobber (match_scratch:SI 4 ""))]
12236   "! TARGET_POWERPC64 && reload_completed"
12237   [(set (match_dup 4)
12238         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
12239                   (match_dup 3)))
12240    (set (match_dup 0)
12241         (compare:CC (match_dup 4)
12242                     (const_int 0)))]
12243   "")
12244
12245 (define_insn ""
12246   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12247         (compare:CC
12248          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12249                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12250                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12251          (const_int 0)))
12252    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12253         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12254   "! TARGET_POWERPC64"
12255   "@
12256    {sf%I2|subf%I2c} %0,%1,%2\;{aze.|addze.} %0,%3
12257    #"
12258   [(set_attr "type" "compare")
12259    (set_attr "length" "8,12")])
12260
12261 (define_split
12262   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12263         (compare:CC
12264          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12265                           (match_operand:SI 2 "reg_or_short_operand" ""))
12266                   (match_operand:SI 3 "gpc_reg_operand" ""))
12267          (const_int 0)))
12268    (set (match_operand:SI 0 "gpc_reg_operand" "")
12269         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12270   "! TARGET_POWERPC64 && reload_completed"
12271   [(set (match_dup 0)
12272         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12273    (set (match_dup 4)
12274         (compare:CC (match_dup 0)
12275                     (const_int 0)))]
12276   "")
12277
12278 (define_insn ""
12279   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12280         (neg:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12281                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12282   "! TARGET_POWERPC64"
12283   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
12284    [(set_attr "length" "12")])
12285
12286 (define_insn ""
12287   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12288         (and:SI (neg:SI
12289                  (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12290                          (match_operand:SI 2 "reg_or_short_operand" "rI")))
12291                 (match_operand:SI 3 "gpc_reg_operand" "r")))]
12292   "! TARGET_POWERPC64"
12293   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12294   [(set_attr "length" "12")])
12295
12296 (define_insn ""
12297   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12298         (compare:CC
12299          (and:SI (neg:SI
12300                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12301                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12302                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12303          (const_int 0)))
12304    (clobber (match_scratch:SI 4 "=&r,&r"))]
12305   "! TARGET_POWERPC64"
12306   "@
12307    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12308    #"
12309   [(set_attr "type" "compare")
12310    (set_attr "length" "12,16")])
12311
12312 (define_split
12313   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12314         (compare:CC
12315          (and:SI (neg:SI
12316                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12317                           (match_operand:SI 2 "reg_or_short_operand" "")))
12318                  (match_operand:SI 3 "gpc_reg_operand" ""))
12319          (const_int 0)))
12320    (clobber (match_scratch:SI 4 ""))]
12321   "! TARGET_POWERPC64 && reload_completed"
12322   [(set (match_dup 4)
12323         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12324                 (match_dup 3)))
12325    (set (match_dup 0)
12326         (compare:CC (match_dup 4)
12327                     (const_int 0)))]
12328   "")
12329
12330 (define_insn ""
12331   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12332         (compare:CC
12333          (and:SI (neg:SI
12334                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12335                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12336                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12337          (const_int 0)))
12338    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12339         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12340   "! TARGET_POWERPC64"
12341   "@
12342    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12343    #"
12344   [(set_attr "type" "compare")
12345    (set_attr "length" "12,16")])
12346
12347 (define_split
12348   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12349         (compare:CC
12350          (and:SI (neg:SI
12351                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12352                           (match_operand:SI 2 "reg_or_short_operand" "")))
12353                  (match_operand:SI 3 "gpc_reg_operand" ""))
12354          (const_int 0)))
12355    (set (match_operand:SI 0 "gpc_reg_operand" "")
12356         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12357   "! TARGET_POWERPC64 && reload_completed"
12358   [(set (match_dup 0)
12359         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12360                 (match_dup 3)))
12361    (set (match_dup 4)
12362         (compare:CC (match_dup 0)
12363                     (const_int 0)))]
12364   "")
12365
12366 (define_insn ""
12367   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12368         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12369                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12370   "TARGET_POWER"
12371   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
12372    [(set_attr "length" "12")])
12373
12374 (define_insn ""
12375   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12376         (compare:CC
12377          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12378                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12379          (const_int 0)))
12380    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12381         (lt:SI (match_dup 1) (match_dup 2)))]
12382   "TARGET_POWER"
12383   "@
12384    doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
12385    #"
12386   [(set_attr "type" "delayed_compare")
12387    (set_attr "length" "12,16")])
12388
12389 (define_split
12390   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12391         (compare:CC
12392          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12393                 (match_operand:SI 2 "reg_or_short_operand" ""))
12394          (const_int 0)))
12395    (set (match_operand:SI 0 "gpc_reg_operand" "")
12396         (lt:SI (match_dup 1) (match_dup 2)))]
12397   "TARGET_POWER && reload_completed"
12398   [(set (match_dup 0)
12399         (lt:SI (match_dup 1) (match_dup 2)))
12400    (set (match_dup 3)
12401         (compare:CC (match_dup 0)
12402                     (const_int 0)))]
12403   "")
12404
12405 (define_insn ""
12406   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12407         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12408                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12409                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12410   "TARGET_POWER"
12411   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
12412   [(set_attr "length" "12")])
12413
12414 (define_insn ""
12415   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12416         (compare:CC
12417          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12418                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12419                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12420          (const_int 0)))
12421    (clobber (match_scratch:SI 4 "=&r,&r"))]
12422   "TARGET_POWER"
12423   "@
12424    doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
12425    #"
12426   [(set_attr "type" "compare")
12427    (set_attr "length" "12,16")])
12428
12429 (define_split
12430   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12431         (compare:CC
12432          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12433                          (match_operand:SI 2 "reg_or_short_operand" ""))
12434                   (match_operand:SI 3 "gpc_reg_operand" ""))
12435          (const_int 0)))
12436    (clobber (match_scratch:SI 4 ""))]
12437   "TARGET_POWER && reload_completed"
12438   [(set (match_dup 4)
12439         (plus:SI (lt:SI (match_dup 1) (match_dup 2))
12440                  (match_dup 3)))
12441    (set (match_dup 0)
12442         (compare:CC (match_dup 4)
12443                     (const_int 0)))]
12444   "")
12445
12446 (define_insn ""
12447   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12448         (compare:CC
12449          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12450                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12451                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12452          (const_int 0)))
12453    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12454         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12455   "TARGET_POWER"
12456   "@
12457    doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
12458    #"
12459   [(set_attr "type" "compare")
12460    (set_attr "length" "12,16")])
12461
12462 (define_split
12463   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12464         (compare:CC
12465          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12466                          (match_operand:SI 2 "reg_or_short_operand" ""))
12467                   (match_operand:SI 3 "gpc_reg_operand" ""))
12468          (const_int 0)))
12469    (set (match_operand:SI 0 "gpc_reg_operand" "")
12470         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12471   "TARGET_POWER && reload_completed"
12472   [(set (match_dup 0)
12473         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12474    (set (match_dup 4)
12475         (compare:CC (match_dup 0)
12476                     (const_int 0)))]
12477   "")
12478
12479 (define_insn ""
12480   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12481         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12482                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12483   "TARGET_POWER"
12484   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
12485   [(set_attr "length" "12")])
12486
12487 (define_insn ""
12488   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12489         (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12490                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
12491   "! TARGET_POWERPC64"
12492   "@
12493    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg %0,%0
12494    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg %0,%0"
12495   [(set_attr "length" "12")])
12496
12497 (define_insn ""
12498   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12499         (compare:CC
12500          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12501                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12502          (const_int 0)))
12503    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12504         (ltu:SI (match_dup 1) (match_dup 2)))]
12505   "! TARGET_POWERPC64"
12506   "@
12507    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
12508    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
12509    #
12510    #"
12511   [(set_attr "type" "compare")
12512    (set_attr "length" "12,12,16,16")])
12513
12514 (define_split
12515   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12516         (compare:CC
12517          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12518                  (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12519          (const_int 0)))
12520    (set (match_operand:SI 0 "gpc_reg_operand" "")
12521         (ltu:SI (match_dup 1) (match_dup 2)))]
12522   "! TARGET_POWERPC64 && reload_completed"
12523   [(set (match_dup 0)
12524         (ltu:SI (match_dup 1) (match_dup 2)))
12525    (set (match_dup 3)
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,&r")
12532         (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12533                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
12534                  (match_operand:SI 3 "reg_or_short_operand" "rI,rI")))]
12535   "! TARGET_POWERPC64"
12536   "@
12537   {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;{sf%I3|subf%I3c} %0,%0,%3
12538   {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;{sf%I3|subf%I3c} %0,%0,%3"
12539  [(set_attr "length" "12")])
12540
12541 (define_insn ""
12542   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12543         (compare:CC
12544          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12545                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12546                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12547          (const_int 0)))
12548    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12549   "! TARGET_POWERPC64"
12550   "@
12551    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
12552    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
12553    #
12554    #"
12555   [(set_attr "type" "compare")
12556    (set_attr "length" "12,12,16,16")])
12557
12558 (define_split
12559   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12560         (compare:CC
12561          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12562                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12563                   (match_operand:SI 3 "gpc_reg_operand" ""))
12564          (const_int 0)))
12565    (clobber (match_scratch:SI 4 ""))]
12566   "! TARGET_POWERPC64 && reload_completed"
12567   [(set (match_dup 4)
12568         (plus:SI (ltu:SI (match_dup 1) (match_dup 2))
12569                  (match_dup 3)))
12570    (set (match_dup 0)
12571         (compare:CC (match_dup 4)
12572                     (const_int 0)))]
12573   "")
12574
12575 (define_insn ""
12576   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12577         (compare:CC
12578          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12579                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12580                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12581          (const_int 0)))
12582    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12583         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12584   "! TARGET_POWERPC64"
12585   "@
12586    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;{sf.|subfc.} %0,%0,%3
12587    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;{sf.|subfc.} %0,%0,%3
12588    #
12589    #"
12590   [(set_attr "type" "compare")
12591    (set_attr "length" "12,12,16,16")])
12592
12593 (define_split
12594   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12595         (compare:CC
12596          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12597                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12598                   (match_operand:SI 3 "gpc_reg_operand" ""))
12599          (const_int 0)))
12600    (set (match_operand:SI 0 "gpc_reg_operand" "")
12601         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12602   "! TARGET_POWERPC64 && reload_completed"
12603   [(set (match_dup 0)
12604         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12605    (set (match_dup 4)
12606         (compare:CC (match_dup 0)
12607                     (const_int 0)))]
12608   "")
12609
12610 (define_insn ""
12611   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12612         (neg:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12613                         (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))))]
12614   "! TARGET_POWERPC64"
12615   "@
12616    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
12617    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
12618   [(set_attr "length" "8")])
12619
12620 (define_insn ""
12621   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12622         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12623                (match_operand:SI 2 "reg_or_short_operand" "rI")))
12624    (clobber (match_scratch:SI 3 "=r"))]
12625   "TARGET_POWER"
12626   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
12627    [(set_attr "length" "12")])
12628
12629 (define_insn ""
12630   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12631         (compare:CC
12632          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12633                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12634          (const_int 0)))
12635    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12636         (ge:SI (match_dup 1) (match_dup 2)))
12637    (clobber (match_scratch:SI 3 "=r,r"))]
12638   "TARGET_POWER"
12639   "@
12640    doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
12641    #"
12642   [(set_attr "type" "compare")
12643    (set_attr "length" "12,16")])
12644
12645 (define_split
12646   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12647         (compare:CC
12648          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12649                 (match_operand:SI 2 "reg_or_short_operand" ""))
12650          (const_int 0)))
12651    (set (match_operand:SI 0 "gpc_reg_operand" "")
12652         (ge:SI (match_dup 1) (match_dup 2)))
12653    (clobber (match_scratch:SI 3 ""))]
12654   "TARGET_POWER && reload_completed"
12655   [(parallel [(set (match_dup 0)
12656                    (ge:SI (match_dup 1) (match_dup 2)))
12657               (clobber (match_dup 3))])
12658    (set (match_dup 4)
12659         (compare:CC (match_dup 0)
12660                     (const_int 0)))]
12661   "")
12662
12663 (define_insn ""
12664   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12665         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12666                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12667                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12668   "TARGET_POWER"
12669   "doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
12670   [(set_attr "length" "12")])
12671
12672 (define_insn ""
12673   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12674         (compare:CC
12675          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12676                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12677                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12678          (const_int 0)))
12679    (clobber (match_scratch:SI 4 "=&r,&r"))]
12680   "TARGET_POWER"
12681   "@
12682    doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12683    #"
12684   [(set_attr "type" "compare")
12685    (set_attr "length" "12,16")])
12686
12687 (define_split
12688   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12689         (compare:CC
12690          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12691                          (match_operand:SI 2 "reg_or_short_operand" ""))
12692                   (match_operand:SI 3 "gpc_reg_operand" ""))
12693          (const_int 0)))
12694    (clobber (match_scratch:SI 4 ""))]
12695   "TARGET_POWER && reload_completed"
12696   [(set (match_dup 4)
12697         (plus:SI (ge:SI (match_dup 1) (match_dup 2))
12698                  (match_dup 3)))
12699    (set (match_dup 0)
12700         (compare:CC (match_dup 4)
12701                     (const_int 0)))]
12702   "")
12703
12704 (define_insn ""
12705   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12706         (compare:CC
12707          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12708                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12709                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12710          (const_int 0)))
12711    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12712         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12713   "TARGET_POWER"
12714   "@
12715    doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12716    #"
12717   [(set_attr "type" "compare")
12718    (set_attr "length" "12,16")])
12719
12720 (define_split
12721   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12722         (compare:CC
12723          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12724                          (match_operand:SI 2 "reg_or_short_operand" ""))
12725                   (match_operand:SI 3 "gpc_reg_operand" ""))
12726          (const_int 0)))
12727    (set (match_operand:SI 0 "gpc_reg_operand" "")
12728         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12729   "TARGET_POWER && reload_completed"
12730   [(set (match_dup 0)
12731         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12732    (set (match_dup 4)
12733         (compare:CC (match_dup 0)
12734                     (const_int 0)))]
12735   "")
12736
12737 (define_insn ""
12738   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12739         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12740                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12741   "TARGET_POWER"
12742   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
12743   [(set_attr "length" "12")])
12744
12745 (define_insn ""
12746   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12747         (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12748                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
12749   "! TARGET_POWERPC64"
12750   "@
12751    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
12752    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12753   [(set_attr "length" "12")])
12754
12755 (define_insn ""
12756   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12757         (geu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12758                 (match_operand:DI 2 "reg_or_neg_short_operand" "r,P")))]
12759   "TARGET_POWERPC64"
12760   "@
12761    subfc %0,%2,%1\;li %0,0\;adde %0,%0,%0
12762    addic %0,%1,%n2\;li %0,0\;adde %0,%0,%0"
12763   [(set_attr "length" "12")])
12764
12765 (define_insn ""
12766   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12767         (compare:CC
12768          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12769                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12770          (const_int 0)))
12771    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12772         (geu:SI (match_dup 1) (match_dup 2)))]
12773   "! TARGET_POWERPC64"
12774   "@
12775    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12776    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12777    #
12778    #"
12779   [(set_attr "type" "compare")
12780    (set_attr "length" "12,12,16,16")])
12781
12782 (define_split
12783   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12784         (compare:CC
12785          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12786                  (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12787          (const_int 0)))
12788    (set (match_operand:SI 0 "gpc_reg_operand" "")
12789         (geu:SI (match_dup 1) (match_dup 2)))]
12790   "! TARGET_POWERPC64 && reload_completed"
12791   [(set (match_dup 0)
12792         (geu:SI (match_dup 1) (match_dup 2)))
12793    (set (match_dup 3)
12794         (compare:CC (match_dup 0)
12795                     (const_int 0)))]
12796   "")
12797
12798 (define_insn ""
12799   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12800         (compare:CC
12801          (geu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
12802                  (match_operand:DI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12803          (const_int 0)))
12804    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
12805         (geu:DI (match_dup 1) (match_dup 2)))]
12806   "TARGET_POWERPC64"
12807   "@
12808    subfc %0,%2,%1\;li %0,0\;adde. %0,%0,%0
12809    addic %0,%1,%n2\;li %0,0\;adde. %0,%0,%0
12810    #
12811    #"
12812   [(set_attr "type" "compare")
12813    (set_attr "length" "12,12,16,16")])
12814
12815 (define_split
12816   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12817         (compare:CC
12818          (geu:DI (match_operand:DI 1 "gpc_reg_operand" "")
12819                  (match_operand:DI 2 "reg_or_neg_short_operand" ""))
12820          (const_int 0)))
12821    (set (match_operand:DI 0 "gpc_reg_operand" "")
12822         (geu:DI (match_dup 1) (match_dup 2)))]
12823   "TARGET_POWERPC64 && reload_completed"
12824   [(set (match_dup 0)
12825         (geu:DI (match_dup 1) (match_dup 2)))
12826    (set (match_dup 3)
12827         (compare:CC (match_dup 0)
12828                     (const_int 0)))]
12829   "")
12830
12831 (define_insn ""
12832   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12833         (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12834                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
12835                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12836   "! TARGET_POWERPC64"
12837   "@
12838    {sf|subfc} %0,%2,%1\;{aze|addze} %0,%3
12839    {ai|addic} %0,%1,%n2\;{aze|addze} %0,%3"
12840   [(set_attr "length" "8")])
12841
12842 (define_insn ""
12843   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12844         (compare:CC
12845          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12846                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12847                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12848          (const_int 0)))
12849    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12850   "! TARGET_POWERPC64"
12851   "@
12852    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
12853    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3
12854    #
12855    #"
12856   [(set_attr "type" "compare")
12857    (set_attr "length" "8,8,12,12")])
12858
12859 (define_split
12860   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12861         (compare:CC
12862          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12863                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12864                   (match_operand:SI 3 "gpc_reg_operand" ""))
12865          (const_int 0)))
12866    (clobber (match_scratch:SI 4 ""))]
12867   "! TARGET_POWERPC64 && reload_completed"
12868   [(set (match_dup 4)
12869         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
12870                   (match_dup 3)))
12871    (set (match_dup 0)
12872         (compare:CC (match_dup 4)
12873                     (const_int 0)))]
12874   "")
12875
12876 (define_insn ""
12877   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12878         (compare:CC
12879          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12880                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12881                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12882          (const_int 0)))
12883    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12884         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12885   "! TARGET_POWERPC64"
12886   "@
12887    {sf|subfc} %0,%2,%1\;{aze.|addze.} %0,%3
12888    {ai|addic} %0,%1,%n2\;{aze.|addze.} %0,%3
12889    #
12890    #"
12891   [(set_attr "type" "compare")
12892    (set_attr "length" "8,8,12,12")])
12893
12894 (define_split
12895   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12896         (compare:CC
12897          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12898                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12899                   (match_operand:SI 3 "gpc_reg_operand" ""))
12900          (const_int 0)))
12901    (set (match_operand:SI 0 "gpc_reg_operand" "")
12902         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12903   "! TARGET_POWERPC64 && reload_completed"
12904   [(set (match_dup 0)
12905         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12906    (set (match_dup 4)
12907         (compare:CC (match_dup 0)
12908                     (const_int 0)))]
12909   "")
12910
12911 (define_insn ""
12912   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12913         (neg:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12914                         (match_operand:SI 2 "reg_or_short_operand" "r,I"))))]
12915   "! TARGET_POWERPC64"
12916   "@
12917    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
12918    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
12919   [(set_attr "length" "12")])
12920
12921 (define_insn ""
12922   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12923         (and:SI (neg:SI
12924                  (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12925                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
12926                 (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12927   "! TARGET_POWERPC64"
12928   "@
12929    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0
12930    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12931   [(set_attr "length" "12")])
12932
12933 (define_insn ""
12934   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12935         (compare:CC
12936          (and:SI (neg:SI
12937                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12938                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
12939                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12940          (const_int 0)))
12941    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12942   "! TARGET_POWERPC64"
12943   "@
12944    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12945    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12946    #
12947    #"
12948   [(set_attr "type" "compare")
12949    (set_attr "length" "12,12,16,16")])
12950
12951 (define_split
12952   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12953         (compare:CC
12954          (and:SI (neg:SI
12955                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12956                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
12957                  (match_operand:SI 3 "gpc_reg_operand" ""))
12958          (const_int 0)))
12959    (clobber (match_scratch:SI 4 ""))]
12960   "! TARGET_POWERPC64 && reload_completed"
12961   [(set (match_dup 4)
12962         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
12963                 (match_dup 3)))
12964    (set (match_dup 0)
12965         (compare:CC (match_dup 4)
12966                     (const_int 0)))]
12967   "")
12968
12969 (define_insn ""
12970   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12971         (compare:CC
12972          (and:SI (neg:SI
12973                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12974                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
12975                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12976          (const_int 0)))
12977    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12978         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12979   "! TARGET_POWERPC64"
12980   "@
12981    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12982    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12983    #
12984    #"
12985   [(set_attr "type" "compare")
12986    (set_attr "length" "12,12,16,16")])
12987
12988 (define_split
12989   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12990         (compare:CC
12991          (and:SI (neg:SI
12992                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12993                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
12994                  (match_operand:SI 3 "gpc_reg_operand" ""))
12995          (const_int 0)))
12996    (set (match_operand:SI 0 "gpc_reg_operand" "")
12997         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12998   "! TARGET_POWERPC64 && reload_completed"
12999   [(set (match_dup 0)
13000         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
13001    (set (match_dup 4)
13002         (compare:CC (match_dup 0)
13003                     (const_int 0)))]
13004   "")
13005
13006 (define_insn ""
13007   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13008         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13009                (const_int 0)))]
13010   "! TARGET_POWERPC64"
13011   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri|srwi} %0,%0,31"
13012   [(set_attr "length" "12")])
13013
13014 (define_insn ""
13015   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13016         (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13017                (const_int 0)))]
13018   "TARGET_POWERPC64"
13019   "subfic %0,%1,0\;addme %0,%0\;srdi %0,%0,63"
13020   [(set_attr "length" "12")])
13021
13022 (define_insn ""
13023   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
13024         (compare:CC
13025          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13026                 (const_int 0))
13027          (const_int 0)))
13028    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13029         (gt:SI (match_dup 1) (const_int 0)))]
13030   "! TARGET_POWERPC64"
13031   "@
13032    {sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri.|srwi.} %0,%0,31
13033    #"
13034   [(set_attr "type" "delayed_compare")
13035    (set_attr "length" "12,16")])
13036
13037 (define_split
13038   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
13039         (compare:CC
13040          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13041                 (const_int 0))
13042          (const_int 0)))
13043    (set (match_operand:SI 0 "gpc_reg_operand" "")
13044         (gt:SI (match_dup 1) (const_int 0)))]
13045   "! TARGET_POWERPC64 && reload_completed"
13046   [(set (match_dup 0)
13047         (gt:SI (match_dup 1) (const_int 0)))
13048    (set (match_dup 2)
13049         (compare:CC (match_dup 0)
13050                     (const_int 0)))]
13051   "")
13052
13053 (define_insn ""
13054   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
13055         (compare:CC
13056          (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13057                 (const_int 0))
13058          (const_int 0)))
13059    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
13060         (gt:DI (match_dup 1) (const_int 0)))]
13061   "TARGET_POWERPC64"
13062   "@
13063    subfic %0,%1,0\;addme %0,%0\;srdi. %0,%0,63
13064    #"
13065   [(set_attr "type" "delayed_compare")
13066    (set_attr "length" "12,16")])
13067
13068 (define_split
13069   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
13070         (compare:CC
13071          (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13072                 (const_int 0))
13073          (const_int 0)))
13074    (set (match_operand:DI 0 "gpc_reg_operand" "")
13075         (gt:DI (match_dup 1) (const_int 0)))]
13076   "TARGET_POWERPC64 && reload_completed"
13077   [(set (match_dup 0)
13078         (gt:DI (match_dup 1) (const_int 0)))
13079    (set (match_dup 2)
13080         (compare:CC (match_dup 0)
13081                     (const_int 0)))]
13082   "")
13083
13084 (define_insn ""
13085   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13086         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13087                (match_operand:SI 2 "reg_or_short_operand" "r")))]
13088   "TARGET_POWER"
13089   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
13090   [(set_attr "length" "12")])
13091
13092 (define_insn ""
13093   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13094         (compare:CC
13095          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13096                 (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13097          (const_int 0)))
13098    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13099         (gt:SI (match_dup 1) (match_dup 2)))]
13100   "TARGET_POWER"
13101   "@
13102    doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
13103    #"
13104   [(set_attr "type" "delayed_compare")
13105    (set_attr "length" "12,16")])
13106
13107 (define_split
13108   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13109         (compare:CC
13110          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13111                 (match_operand:SI 2 "reg_or_short_operand" ""))
13112          (const_int 0)))
13113    (set (match_operand:SI 0 "gpc_reg_operand" "")
13114         (gt:SI (match_dup 1) (match_dup 2)))]
13115   "TARGET_POWER && reload_completed"
13116   [(set (match_dup 0)
13117         (gt:SI (match_dup 1) (match_dup 2)))
13118    (set (match_dup 3)
13119         (compare:CC (match_dup 0)
13120                     (const_int 0)))]
13121   "")
13122
13123 (define_insn ""
13124   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13125         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13126                         (const_int 0))
13127                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
13128   "! TARGET_POWERPC64"
13129   "{a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze|addze} %0,%2"
13130   [(set_attr "length" "12")])
13131
13132 (define_insn ""
13133   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
13134         (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13135                         (const_int 0))
13136                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
13137   "TARGET_POWERPC64"
13138   "addc %0,%1,%1\;subfe %0,%1,%0\;addze %0,%2"
13139   [(set_attr "length" "12")])
13140
13141 (define_insn ""
13142   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13143         (compare:CC
13144          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13145                          (const_int 0))
13146                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13147          (const_int 0)))
13148    (clobber (match_scratch:SI 3 "=&r,&r"))]
13149   "! TARGET_POWERPC64"
13150   "@
13151    {a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2
13152    #"
13153   [(set_attr "type" "compare")
13154    (set_attr "length" "12,16")])
13155
13156 (define_split
13157   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13158         (compare:CC
13159          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13160                          (const_int 0))
13161                   (match_operand:SI 2 "gpc_reg_operand" ""))
13162          (const_int 0)))
13163    (clobber (match_scratch:SI 3 ""))]
13164   "! TARGET_POWERPC64 && reload_completed"
13165   [(set (match_dup 3)
13166         (plus:SI (gt:SI (match_dup 1) (const_int 0))
13167                   (match_dup 2)))
13168    (set (match_dup 0)
13169         (compare:CC (match_dup 3)
13170                     (const_int 0)))]
13171   "")
13172
13173 (define_insn ""
13174   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13175         (compare:CC
13176          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13177                          (const_int 0))
13178                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13179          (const_int 0)))
13180    (clobber (match_scratch:DI 3 "=&r,&r"))]
13181   "TARGET_POWERPC64"
13182   "@
13183    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
13184    #"
13185   [(set_attr "type" "compare")
13186    (set_attr "length" "12,16")])
13187
13188 (define_split
13189   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13190         (compare:CC
13191          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13192                          (const_int 0))
13193                   (match_operand:DI 2 "gpc_reg_operand" ""))
13194          (const_int 0)))
13195    (clobber (match_scratch:DI 3 ""))]
13196   "TARGET_POWERPC64 && reload_completed"
13197   [(set (match_dup 3)
13198         (plus:DI (gt:DI (match_dup 1) (const_int 0))
13199                  (match_dup 2)))
13200    (set (match_dup 0)
13201         (compare:CC (match_dup 3)
13202                     (const_int 0)))]
13203   "")
13204
13205 (define_insn ""
13206   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13207         (compare:CC
13208          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13209                          (const_int 0))
13210                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13211          (const_int 0)))
13212    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13213         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13214   "! TARGET_POWERPC64"
13215   "@
13216    {a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze.|addze.} %0,%2
13217    #"
13218   [(set_attr "type" "compare")
13219    (set_attr "length" "12,16")])
13220
13221 (define_split
13222   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13223         (compare:CC
13224          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13225                          (const_int 0))
13226                   (match_operand:SI 2 "gpc_reg_operand" ""))
13227          (const_int 0)))
13228    (set (match_operand:SI 0 "gpc_reg_operand" "")
13229         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13230   "! TARGET_POWERPC64 && reload_completed"
13231   [(set (match_dup 0)
13232         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
13233    (set (match_dup 3)
13234         (compare:CC (match_dup 0)
13235                     (const_int 0)))]
13236   "")
13237
13238 (define_insn ""
13239   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13240         (compare:CC
13241          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13242                          (const_int 0))
13243                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13244          (const_int 0)))
13245    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
13246         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13247   "TARGET_POWERPC64"
13248   "@
13249    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
13250    #"
13251   [(set_attr "type" "compare")
13252    (set_attr "length" "12,16")])
13253
13254 (define_split
13255   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13256         (compare:CC
13257          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13258                          (const_int 0))
13259                   (match_operand:DI 2 "gpc_reg_operand" ""))
13260          (const_int 0)))
13261    (set (match_operand:DI 0 "gpc_reg_operand" "")
13262         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13263   "TARGET_POWERPC64 && reload_completed"
13264   [(set (match_dup 0)
13265         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
13266    (set (match_dup 3)
13267         (compare:CC (match_dup 0)
13268                     (const_int 0)))]
13269   "")
13270
13271 (define_insn ""
13272   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13273         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13274                         (match_operand:SI 2 "reg_or_short_operand" "r"))
13275                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
13276   "TARGET_POWER"
13277   "doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
13278   [(set_attr "length" "12")])
13279
13280 (define_insn ""
13281   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13282         (compare:CC
13283          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13284                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13285                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13286          (const_int 0)))
13287    (clobber (match_scratch:SI 4 "=&r,&r"))]
13288   "TARGET_POWER"
13289   "@
13290    doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
13291    #"
13292   [(set_attr "type" "compare")
13293    (set_attr "length" "12,16")])
13294
13295 (define_split
13296   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13297         (compare:CC
13298          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13299                          (match_operand:SI 2 "reg_or_short_operand" ""))
13300                   (match_operand:SI 3 "gpc_reg_operand" ""))
13301          (const_int 0)))
13302    (clobber (match_scratch:SI 4 ""))]
13303   "TARGET_POWER && reload_completed"
13304   [(set (match_dup 4)
13305         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13306    (set (match_dup 0)
13307         (compare:CC (match_dup 4)
13308                     (const_int 0)))]
13309   "")
13310
13311 (define_insn ""
13312   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13313         (compare:CC
13314          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13315                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13316                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13317          (const_int 0)))
13318    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13319         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13320   "TARGET_POWER"
13321   "@
13322    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
13323    #"
13324   [(set_attr "type" "compare")
13325    (set_attr "length" "12,16")])
13326
13327 (define_split
13328   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13329         (compare:CC
13330          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13331                          (match_operand:SI 2 "reg_or_short_operand" ""))
13332                   (match_operand:SI 3 "gpc_reg_operand" ""))
13333          (const_int 0)))
13334    (set (match_operand:SI 0 "gpc_reg_operand" "")
13335         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13336   "TARGET_POWER && reload_completed"
13337   [(set (match_dup 0)
13338         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13339    (set (match_dup 4)
13340         (compare:CC (match_dup 0)
13341                     (const_int 0)))]
13342   "")
13343
13344 (define_insn ""
13345   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13346         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13347                        (const_int 0))))]
13348   "! TARGET_POWERPC64"
13349   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{srai|srawi} %0,%0,31"
13350   [(set_attr "length" "12")])
13351
13352 (define_insn ""
13353   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13354         (neg:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13355                        (const_int 0))))]
13356   "TARGET_POWERPC64"
13357   "subfic %0,%1,0\;addme %0,%0\;sradi %0,%0,63"
13358   [(set_attr "length" "12")])
13359
13360 (define_insn ""
13361   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13362         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13363                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
13364   "TARGET_POWER"
13365   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
13366   [(set_attr "length" "12")])
13367
13368 (define_insn ""
13369   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13370         (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13371                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
13372   "! TARGET_POWERPC64"
13373   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg %0,%0"
13374   [(set_attr "length" "12")])
13375
13376 (define_insn ""
13377   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13378         (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13379                 (match_operand:DI 2 "reg_or_short_operand" "rI")))]
13380   "TARGET_POWERPC64"
13381   "subf%I2c %0,%1,%2\;subfe %0,%0,%0\;neg %0,%0"
13382   [(set_attr "length" "12")])
13383
13384 (define_insn ""
13385   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13386         (compare:CC
13387          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13388                  (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13389          (const_int 0)))
13390    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13391         (gtu:SI (match_dup 1) (match_dup 2)))]
13392   "! TARGET_POWERPC64"
13393   "@
13394    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
13395    #"
13396   [(set_attr "type" "compare")
13397    (set_attr "length" "12,16")])
13398
13399 (define_split
13400   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13401         (compare:CC
13402          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13403                  (match_operand:SI 2 "reg_or_short_operand" ""))
13404          (const_int 0)))
13405    (set (match_operand:SI 0 "gpc_reg_operand" "")
13406         (gtu:SI (match_dup 1) (match_dup 2)))]
13407   "! TARGET_POWERPC64 && reload_completed"
13408   [(set (match_dup 0)
13409         (gtu:SI (match_dup 1) (match_dup 2)))
13410    (set (match_dup 3)
13411         (compare:CC (match_dup 0)
13412                     (const_int 0)))]
13413   "")
13414
13415 (define_insn ""
13416   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13417         (compare:CC
13418          (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13419                  (match_operand:DI 2 "reg_or_short_operand" "rI,rI"))
13420          (const_int 0)))
13421    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
13422         (gtu:DI (match_dup 1) (match_dup 2)))]
13423   "TARGET_POWERPC64"
13424   "@
13425    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;neg. %0,%0
13426    #"
13427   [(set_attr "type" "compare")
13428    (set_attr "length" "12,16")])
13429
13430 (define_split
13431   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13432         (compare:CC
13433          (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13434                  (match_operand:DI 2 "reg_or_short_operand" ""))
13435          (const_int 0)))
13436    (set (match_operand:DI 0 "gpc_reg_operand" "")
13437         (gtu:DI (match_dup 1) (match_dup 2)))]
13438   "TARGET_POWERPC64 && reload_completed"
13439   [(set (match_dup 0)
13440         (gtu:DI (match_dup 1) (match_dup 2)))
13441    (set (match_dup 3)
13442         (compare:CC (match_dup 0)
13443                     (const_int 0)))]
13444   "")
13445
13446 (define_insn ""
13447   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13448         (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13449                          (match_operand:SI 2 "reg_or_short_operand" "I,rI"))
13450                  (match_operand:SI 3 "reg_or_short_operand" "r,rI")))]
13451   "! TARGET_POWERPC64"
13452   "@
13453    {ai|addic} %0,%1,%k2\;{aze|addze} %0,%3
13454    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;{sf%I3|subf%I3c} %0,%0,%3"
13455   [(set_attr "length" "8,12")])
13456
13457 (define_insn ""
13458   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
13459         (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13460                          (match_operand:DI 2 "reg_or_short_operand" "I,rI"))
13461                  (match_operand:DI 3 "reg_or_short_operand" "r,rI")))]
13462   "TARGET_POWERPC64"
13463   "@
13464    addic %0,%1,%k2\;addze %0,%3
13465    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;subf%I3c %0,%0,%3"
13466   [(set_attr "length" "8,12")])
13467
13468 (define_insn ""
13469   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13470         (compare:CC
13471          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13472                           (match_operand:SI 2 "reg_or_short_operand" "I,r,I,r"))
13473                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13474          (const_int 0)))
13475    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13476   "! TARGET_POWERPC64"
13477   "@
13478    {ai|addic} %4,%1,%k2\;{aze.|addze.} %4,%3
13479    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
13480    #
13481    #"
13482   [(set_attr "type" "compare")
13483    (set_attr "length" "8,12,12,16")])
13484
13485 (define_split
13486   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13487         (compare:CC
13488          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13489                           (match_operand:SI 2 "reg_or_short_operand" ""))
13490                   (match_operand:SI 3 "gpc_reg_operand" ""))
13491          (const_int 0)))
13492    (clobber (match_scratch:SI 4 ""))]
13493   "! TARGET_POWERPC64 && reload_completed"
13494   [(set (match_dup 4)
13495         (plus:SI (gtu:SI (match_dup 1) (match_dup 2))
13496                  (match_dup 3)))
13497    (set (match_dup 0)
13498         (compare:CC (match_dup 4)
13499                     (const_int 0)))]
13500   "")
13501
13502 (define_insn ""
13503   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13504         (compare:CC
13505          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
13506                           (match_operand:DI 2 "reg_or_short_operand" "I,r,I,r"))
13507                   (match_operand:DI 3 "gpc_reg_operand" "r,r,r,r"))
13508          (const_int 0)))
13509    (clobber (match_scratch:DI 4 "=&r,&r,&r,&r"))]
13510   "TARGET_POWERPC64"
13511   "@
13512    addic %4,%1,%k2\;addze. %4,%3
13513    subf%I2c %4,%1,%2\;subfe %4,%4,%4\;subfc. %4,%4,%3
13514    #
13515    #"
13516   [(set_attr "type" "compare")
13517    (set_attr "length" "8,12,12,16")])
13518
13519 (define_split
13520   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13521         (compare:CC
13522          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13523                           (match_operand:DI 2 "reg_or_short_operand" ""))
13524                   (match_operand:DI 3 "gpc_reg_operand" ""))
13525          (const_int 0)))
13526    (clobber (match_scratch:DI 4 ""))]
13527   "TARGET_POWERPC64 && reload_completed"
13528   [(set (match_dup 4)
13529         (plus:DI (gtu:DI (match_dup 1) (match_dup 2))
13530                   (match_dup 3)))
13531    (set (match_dup 0)
13532         (compare:CC (match_dup 4)
13533                     (const_int 0)))]
13534   "")
13535
13536 (define_insn ""
13537   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13538         (compare:CC
13539          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13540                           (match_operand:SI 2 "reg_or_short_operand" "I,r,I,r"))
13541                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13542          (const_int 0)))
13543    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13544         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13545   "! TARGET_POWERPC64"
13546   "@
13547    {ai|addic} %0,%1,%k2\;{aze.|addze.} %0,%3
13548    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;{sf.|subfc.} %0,%0,%3
13549    #
13550    #"
13551   [(set_attr "type" "compare")
13552    (set_attr "length" "8,12,12,16")])
13553
13554 (define_split
13555   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13556         (compare:CC
13557          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13558                           (match_operand:SI 2 "reg_or_short_operand" ""))
13559                   (match_operand:SI 3 "gpc_reg_operand" ""))
13560          (const_int 0)))
13561    (set (match_operand:SI 0 "gpc_reg_operand" "")
13562         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13563   "! TARGET_POWERPC64 && reload_completed"
13564   [(set (match_dup 0)
13565         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13566    (set (match_dup 4)
13567         (compare:CC (match_dup 0)
13568                     (const_int 0)))]
13569   "")
13570
13571 (define_insn ""
13572   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13573         (compare:CC
13574          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
13575                           (match_operand:DI 2 "reg_or_short_operand" "I,r,I,r"))
13576                   (match_operand:DI 3 "gpc_reg_operand" "r,r,r,r"))
13577          (const_int 0)))
13578    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13579         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13580   "TARGET_POWERPC64"
13581   "@
13582    addic %0,%1,%k2\;addze. %0,%3
13583    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;subfc. %0,%0,%3
13584    #
13585    #"
13586   [(set_attr "type" "compare")
13587    (set_attr "length" "8,12,12,16")])
13588
13589 (define_split
13590   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13591         (compare:CC
13592          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13593                           (match_operand:DI 2 "reg_or_short_operand" ""))
13594                   (match_operand:DI 3 "gpc_reg_operand" ""))
13595          (const_int 0)))
13596    (set (match_operand:DI 0 "gpc_reg_operand" "")
13597         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13598   "TARGET_POWERPC64 && reload_completed"
13599   [(set (match_dup 0)
13600         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
13601    (set (match_dup 4)
13602         (compare:CC (match_dup 0)
13603                     (const_int 0)))]
13604   "")
13605
13606 (define_insn ""
13607   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13608         (neg:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13609                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
13610   "! TARGET_POWERPC64"
13611   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
13612   [(set_attr "length" "8")])
13613
13614 (define_insn ""
13615   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13616         (neg:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13617                         (match_operand:DI 2 "reg_or_short_operand" "rI"))))]
13618   "TARGET_POWERPC64"
13619   "subf%I2c %0,%1,%2\;subfe %0,%0,%0"
13620   [(set_attr "length" "8")])
13621 \f
13622 ;; Define both directions of branch and return.  If we need a reload
13623 ;; register, we'd rather use CR0 since it is much easier to copy a
13624 ;; register CC value to there.
13625
13626 (define_insn ""
13627   [(set (pc)
13628         (if_then_else (match_operator 1 "branch_comparison_operator"
13629                                       [(match_operand 2
13630                                                       "cc_reg_operand" "y")
13631                                        (const_int 0)])
13632                       (label_ref (match_operand 0 "" ""))
13633                       (pc)))]
13634   ""
13635   "*
13636 {
13637   return output_cbranch (operands[1], \"%l0\", 0, insn);
13638 }"
13639   [(set_attr "type" "branch")])
13640
13641 (define_insn ""
13642   [(set (pc)
13643         (if_then_else (match_operator 0 "branch_comparison_operator"
13644                                       [(match_operand 1
13645                                                       "cc_reg_operand" "y")
13646                                        (const_int 0)])
13647                       (return)
13648                       (pc)))]
13649   "direct_return ()"
13650   "*
13651 {
13652   return output_cbranch (operands[0], NULL, 0, insn);
13653 }"
13654   [(set_attr "type" "branch")
13655    (set_attr "length" "4")])
13656
13657 (define_insn ""
13658   [(set (pc)
13659         (if_then_else (match_operator 1 "branch_comparison_operator"
13660                                       [(match_operand 2
13661                                                       "cc_reg_operand" "y")
13662                                        (const_int 0)])
13663                       (pc)
13664                       (label_ref (match_operand 0 "" ""))))]
13665   ""
13666   "*
13667 {
13668   return output_cbranch (operands[1], \"%l0\", 1, insn);
13669 }"
13670   [(set_attr "type" "branch")])
13671
13672 (define_insn ""
13673   [(set (pc)
13674         (if_then_else (match_operator 0 "branch_comparison_operator"
13675                                       [(match_operand 1
13676                                                       "cc_reg_operand" "y")
13677                                        (const_int 0)])
13678                       (pc)
13679                       (return)))]
13680   "direct_return ()"
13681   "*
13682 {
13683   return output_cbranch (operands[0], NULL, 1, insn);
13684 }"
13685   [(set_attr "type" "branch")
13686    (set_attr "length" "4")])
13687
13688 ;; Logic on condition register values.
13689
13690 ; This pattern matches things like
13691 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
13692 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
13693 ;                                  (const_int 1)))
13694 ; which are generated by the branch logic.
13695 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
13696
13697 (define_insn ""
13698   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13699         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
13700                         [(match_operator:SI 2
13701                                       "branch_positive_comparison_operator"
13702                                       [(match_operand 3
13703                                                       "cc_reg_operand" "y,y")
13704                                        (const_int 0)])
13705                          (match_operator:SI 4
13706                                       "branch_positive_comparison_operator"
13707                                       [(match_operand 5
13708                                                       "cc_reg_operand" "0,y")
13709                                        (const_int 0)])])
13710                       (const_int 1)))]
13711   ""
13712   "cr%q1 %E0,%j2,%j4"
13713   [(set_attr "type" "cr_logical,delayed_cr")])
13714
13715 ; Why is the constant -1 here, but 1 in the previous pattern?
13716 ; Because ~1 has all but the low bit set.
13717 (define_insn ""
13718   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13719         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
13720                         [(not:SI (match_operator:SI 2
13721                                       "branch_positive_comparison_operator"
13722                                       [(match_operand 3
13723                                                       "cc_reg_operand" "y,y")
13724                                        (const_int 0)]))
13725                          (match_operator:SI 4
13726                                 "branch_positive_comparison_operator"
13727                                 [(match_operand 5
13728                                                 "cc_reg_operand" "0,y")
13729                                  (const_int 0)])])
13730                       (const_int -1)))]
13731   ""
13732   "cr%q1 %E0,%j2,%j4"
13733   [(set_attr "type" "cr_logical,delayed_cr")])
13734
13735 (define_insn ""
13736   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13737         (compare:CCEQ (match_operator:SI 1
13738                                       "branch_positive_comparison_operator"
13739                                       [(match_operand 2
13740                                                       "cc_reg_operand" "0,y")
13741                                        (const_int 0)])
13742                       (const_int 0)))]
13743   "!TARGET_SPE"
13744   "{crnor %E0,%j1,%j1|crnot %E0,%j1}"
13745   [(set_attr "type" "cr_logical,delayed_cr")])
13746
13747 ;; If we are comparing the result of two comparisons, this can be done
13748 ;; using creqv or crxor.
13749
13750 (define_insn_and_split ""
13751   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
13752         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
13753                               [(match_operand 2 "cc_reg_operand" "y")
13754                                (const_int 0)])
13755                       (match_operator 3 "branch_comparison_operator"
13756                               [(match_operand 4 "cc_reg_operand" "y")
13757                                (const_int 0)])))]
13758   ""
13759   "#"
13760   ""
13761   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
13762                                     (match_dup 5)))]
13763   "
13764 {
13765   int positive_1, positive_2;
13766
13767   positive_1 = branch_positive_comparison_operator (operands[1], CCEQmode);
13768   positive_2 = branch_positive_comparison_operator (operands[3], CCEQmode);
13769
13770   if (! positive_1)
13771     operands[1] = gen_rtx (rs6000_reverse_condition (GET_MODE (operands[2]),
13772                                                      GET_CODE (operands[1])),
13773                            SImode,
13774                            operands[2], const0_rtx);
13775   else if (GET_MODE (operands[1]) != SImode)
13776     operands[1] = gen_rtx (GET_CODE (operands[1]),
13777                            SImode,
13778                            operands[2], const0_rtx);
13779
13780   if (! positive_2)
13781     operands[3] = gen_rtx (rs6000_reverse_condition (GET_MODE (operands[4]),
13782                                                      GET_CODE (operands[3])),
13783                            SImode,
13784                            operands[4], const0_rtx);
13785   else if (GET_MODE (operands[3]) != SImode)
13786     operands[3] = gen_rtx (GET_CODE (operands[3]),
13787                            SImode,
13788                            operands[4], const0_rtx);
13789
13790   if (positive_1 == positive_2)
13791     {
13792       operands[1] = gen_rtx_NOT (SImode, operands[1]);
13793       operands[5] = constm1_rtx;
13794     }
13795   else
13796     {
13797       operands[5] = const1_rtx;
13798     }
13799 }")
13800
13801 ;; Unconditional branch and return.
13802
13803 (define_insn "jump"
13804   [(set (pc)
13805         (label_ref (match_operand 0 "" "")))]
13806   ""
13807   "b %l0"
13808   [(set_attr "type" "branch")])
13809
13810 (define_insn "return"
13811   [(return)]
13812   "direct_return ()"
13813   "{br|blr}"
13814   [(set_attr "type" "jmpreg")])
13815
13816 (define_expand "indirect_jump"
13817   [(set (pc) (match_operand 0 "register_operand" ""))]
13818   ""
13819   "
13820 {
13821   if (TARGET_32BIT)
13822     emit_jump_insn (gen_indirect_jumpsi (operands[0]));
13823   else
13824     emit_jump_insn (gen_indirect_jumpdi (operands[0]));
13825   DONE;
13826 }")
13827
13828 (define_insn "indirect_jumpsi"
13829   [(set (pc) (match_operand:SI 0 "register_operand" "c,*l"))]
13830   "TARGET_32BIT"
13831   "@
13832    bctr
13833    {br|blr}"
13834   [(set_attr "type" "jmpreg")])
13835
13836 (define_insn "indirect_jumpdi"
13837   [(set (pc) (match_operand:DI 0 "register_operand" "c,*l"))]
13838   "TARGET_64BIT"
13839   "@
13840    bctr
13841    blr"
13842   [(set_attr "type" "jmpreg")])
13843
13844 ;; Table jump for switch statements:
13845 (define_expand "tablejump"
13846   [(use (match_operand 0 "" ""))
13847    (use (label_ref (match_operand 1 "" "")))]
13848   ""
13849   "
13850 {
13851   if (TARGET_32BIT)
13852     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
13853   else
13854     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
13855   DONE;
13856 }")
13857
13858 (define_expand "tablejumpsi"
13859   [(set (match_dup 3)
13860         (plus:SI (match_operand:SI 0 "" "")
13861                  (match_dup 2)))
13862    (parallel [(set (pc) (match_dup 3))
13863               (use (label_ref (match_operand 1 "" "")))])]
13864   "TARGET_32BIT"
13865   "
13866 { operands[0] = force_reg (SImode, operands[0]);
13867   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
13868   operands[3] = gen_reg_rtx (SImode);
13869 }")
13870
13871 (define_expand "tablejumpdi"
13872   [(set (match_dup 4) 
13873         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "rm")))
13874    (set (match_dup 3)
13875         (plus:DI (match_dup 4)
13876                  (match_dup 2)))
13877    (parallel [(set (pc) (match_dup 3))
13878               (use (label_ref (match_operand 1 "" "")))])]
13879   "TARGET_64BIT"
13880   "
13881 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
13882   operands[3] = gen_reg_rtx (DImode);
13883   operands[4] = gen_reg_rtx (DImode);
13884 }")
13885
13886 (define_insn ""
13887   [(set (pc)
13888         (match_operand:SI 0 "register_operand" "c,*l"))
13889    (use (label_ref (match_operand 1 "" "")))]
13890   "TARGET_32BIT"
13891   "@
13892    bctr
13893    {br|blr}"
13894   [(set_attr "type" "jmpreg")])
13895
13896 (define_insn ""
13897   [(set (pc)
13898         (match_operand:DI 0 "register_operand" "c,*l"))
13899    (use (label_ref (match_operand 1 "" "")))]
13900   "TARGET_64BIT"
13901   "@
13902    bctr
13903    blr"
13904   [(set_attr "type" "jmpreg")])
13905
13906 (define_insn "nop"
13907   [(const_int 0)]
13908   ""
13909   "{cror 0,0,0|nop}")
13910 \f
13911 ;; Define the subtract-one-and-jump insns, starting with the template
13912 ;; so loop.c knows what to generate.
13913
13914 (define_expand "doloop_end"
13915   [(use (match_operand 0 "" ""))        ; loop pseudo
13916    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
13917    (use (match_operand 2 "" ""))        ; max iterations
13918    (use (match_operand 3 "" ""))        ; loop level
13919    (use (match_operand 4 "" ""))]       ; label
13920   ""
13921   "
13922 {
13923   /* Only use this on innermost loops.  */
13924   if (INTVAL (operands[3]) > 1)
13925     FAIL;
13926   if (TARGET_POWERPC64)
13927     {
13928       if (GET_MODE (operands[0]) != DImode)
13929         FAIL;
13930       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
13931     }
13932   else
13933     {
13934       if (GET_MODE (operands[0]) != SImode)
13935         FAIL;
13936       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
13937     }
13938   DONE;
13939 }")
13940
13941 (define_expand "ctrsi"
13942   [(parallel [(set (pc)
13943                    (if_then_else (ne (match_operand:SI 0 "register_operand" "")
13944                                      (const_int 1))
13945                                  (label_ref (match_operand 1 "" ""))
13946                                  (pc)))
13947               (set (match_dup 0)
13948                    (plus:SI (match_dup 0)
13949                             (const_int -1)))
13950               (clobber (match_scratch:CC 2 ""))
13951               (clobber (match_scratch:SI 3 ""))])]
13952   "! TARGET_POWERPC64"
13953   "")
13954
13955 (define_expand "ctrdi"
13956   [(parallel [(set (pc)
13957                    (if_then_else (ne (match_operand:DI 0 "register_operand" "")
13958                                      (const_int 1))
13959                                  (label_ref (match_operand 1 "" ""))
13960                                  (pc)))
13961               (set (match_dup 0)
13962                    (plus:DI (match_dup 0)
13963                             (const_int -1)))
13964               (clobber (match_scratch:CC 2 ""))
13965               (clobber (match_scratch:DI 3 ""))])]
13966   "TARGET_POWERPC64"
13967   "")
13968
13969 ;; We need to be able to do this for any operand, including MEM, or we
13970 ;; will cause reload to blow up since we don't allow output reloads on
13971 ;; JUMP_INSNs.
13972 ;; For the length attribute to be calculated correctly, the
13973 ;; label MUST be operand 0.
13974
13975 (define_insn "*ctrsi_internal1"
13976   [(set (pc)
13977         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
13978                           (const_int 1))
13979                       (label_ref (match_operand 0 "" ""))
13980                       (pc)))
13981    (set (match_operand:SI 2 "register_operand" "=1,*r,m,*q*c*l")
13982         (plus:SI (match_dup 1)
13983                  (const_int -1)))
13984    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13985    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
13986   "! TARGET_POWERPC64"
13987   "*
13988 {
13989   if (which_alternative != 0)
13990     return \"#\";
13991   else if (get_attr_length (insn) == 4)
13992     return \"{bdn|bdnz} %l0\";
13993   else
13994     return \"bdz $+8\;b %l0\";
13995 }"
13996   [(set_attr "type" "branch")
13997    (set_attr "length" "*,12,16,16")])
13998
13999 (define_insn "*ctrsi_internal2"
14000   [(set (pc)
14001         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14002                           (const_int 1))
14003                       (pc)
14004                       (label_ref (match_operand 0 "" ""))))
14005    (set (match_operand:SI 2 "register_operand" "=1,*r,m,*q*c*l")
14006         (plus:SI (match_dup 1)
14007                  (const_int -1)))
14008    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14009    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14010   "! TARGET_POWERPC64"
14011   "*
14012 {
14013   if (which_alternative != 0)
14014     return \"#\";
14015   else if (get_attr_length (insn) == 4)
14016     return \"bdz %l0\";
14017   else
14018     return \"{bdn|bdnz} $+8\;b %l0\";
14019 }"
14020   [(set_attr "type" "branch")
14021    (set_attr "length" "*,12,16,16")])
14022
14023 (define_insn "*ctrdi_internal1"
14024   [(set (pc)
14025         (if_then_else (ne (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14026                           (const_int 1))
14027                       (label_ref (match_operand 0 "" ""))
14028                       (pc)))
14029    (set (match_operand:DI 2 "register_operand" "=1,*r,m,*c*l")
14030         (plus:DI (match_dup 1)
14031                  (const_int -1)))
14032    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14033    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14034   "TARGET_POWERPC64"
14035   "*
14036 {
14037   if (which_alternative != 0)
14038     return \"#\";
14039   else if (get_attr_length (insn) == 4)
14040     return \"{bdn|bdnz} %l0\";
14041   else
14042     return \"bdz $+8\;b %l0\";
14043 }"
14044   [(set_attr "type" "branch")
14045    (set_attr "length" "*,12,16,16")])
14046
14047 (define_insn "*ctrdi_internal2"
14048   [(set (pc)
14049         (if_then_else (ne (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14050                           (const_int 1))
14051                       (pc)
14052                       (label_ref (match_operand 0 "" ""))))
14053    (set (match_operand:DI 2 "register_operand" "=1,*r,m,*c*l")
14054         (plus:DI (match_dup 1)
14055                  (const_int -1)))
14056    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14057    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14058   "TARGET_POWERPC64"
14059   "*
14060 {
14061   if (which_alternative != 0)
14062     return \"#\";
14063   else if (get_attr_length (insn) == 4)
14064     return \"bdz %l0\";
14065   else
14066     return \"{bdn|bdnz} $+8\;b %l0\";
14067 }"
14068   [(set_attr "type" "branch")
14069    (set_attr "length" "*,12,16,16")])
14070
14071 ;; Similar, but we can use GE since we have a REG_NONNEG.
14072
14073 (define_insn "*ctrsi_internal3"
14074   [(set (pc)
14075         (if_then_else (ge (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14076                           (const_int 0))
14077                       (label_ref (match_operand 0 "" ""))
14078                       (pc)))
14079    (set (match_operand:SI 2 "register_operand" "=1,*r,m,*q*c*l")
14080         (plus:SI (match_dup 1)
14081                  (const_int -1)))
14082    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14083    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14084   "! TARGET_POWERPC64 && find_reg_note (insn, REG_NONNEG, 0)"
14085   "*
14086 {
14087   if (which_alternative != 0)
14088     return \"#\";
14089   else if (get_attr_length (insn) == 4)
14090     return \"{bdn|bdnz} %l0\";
14091   else
14092     return \"bdz $+8\;b %l0\";
14093 }"
14094   [(set_attr "type" "branch")
14095    (set_attr "length" "*,12,16,16")])
14096
14097 (define_insn "*ctrsi_internal4"
14098   [(set (pc)
14099         (if_then_else (ge (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14100                           (const_int 0))
14101                       (pc)
14102                       (label_ref (match_operand 0 "" ""))))
14103    (set (match_operand:SI 2 "register_operand" "=1,*r,m,*q*c*l")
14104         (plus:SI (match_dup 1)
14105                  (const_int -1)))
14106    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14107    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14108   "! TARGET_POWERPC64 && find_reg_note (insn, REG_NONNEG, 0)"
14109   "*
14110 {
14111   if (which_alternative != 0)
14112     return \"#\";
14113   else if (get_attr_length (insn) == 4)
14114     return \"bdz %l0\";
14115   else
14116     return \"{bdn|bdnz} $+8\;b %l0\";
14117 }"
14118   [(set_attr "type" "branch")
14119    (set_attr "length" "*,12,16,16")])
14120
14121 (define_insn "*ctrdi_internal3"
14122   [(set (pc)
14123         (if_then_else (ge (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14124                           (const_int 0))
14125                       (label_ref (match_operand 0 "" ""))
14126                       (pc)))
14127    (set (match_operand:DI 2 "register_operand" "=1,*r,m,*c*l")
14128         (plus:DI (match_dup 1)
14129                  (const_int -1)))
14130    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14131    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14132   "TARGET_POWERPC64 && find_reg_note (insn, REG_NONNEG, 0)"
14133   "*
14134 {
14135   if (which_alternative != 0)
14136     return \"#\";
14137   else if (get_attr_length (insn) == 4)
14138     return \"{bdn|bdnz} %l0\";
14139   else
14140     return \"bdz $+8\;b %l0\";
14141 }"
14142   [(set_attr "type" "branch")
14143    (set_attr "length" "*,12,16,16")])
14144
14145 (define_insn "*ctrdi_internal4"
14146   [(set (pc)
14147         (if_then_else (ge (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14148                           (const_int 0))
14149                       (pc)
14150                       (label_ref (match_operand 0 "" ""))))
14151    (set (match_operand:DI 2 "register_operand" "=1,*r,m,*c*l")
14152         (plus:DI (match_dup 1)
14153                  (const_int -1)))
14154    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14155    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14156   "TARGET_POWERPC64 && find_reg_note (insn, REG_NONNEG, 0)"
14157   "*
14158 {
14159   if (which_alternative != 0)
14160     return \"#\";
14161   else if (get_attr_length (insn) == 4)
14162     return \"bdz %l0\";
14163   else
14164     return \"{bdn|bdnz} $+8\;b %l0\";
14165 }"
14166   [(set_attr "type" "branch")
14167    (set_attr "length" "*,12,16,16")])
14168
14169 ;; Similar but use EQ
14170
14171 (define_insn "*ctrsi_internal5"
14172   [(set (pc)
14173         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14174                           (const_int 1))
14175                       (label_ref (match_operand 0 "" ""))
14176                       (pc)))
14177    (set (match_operand:SI 2 "register_operand" "=1,*r,m,*q*c*l")
14178         (plus:SI (match_dup 1)
14179                  (const_int -1)))
14180    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14181    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14182   "! TARGET_POWERPC64"
14183   "*
14184 {
14185   if (which_alternative != 0)
14186     return \"#\";
14187   else if (get_attr_length (insn) == 4)
14188     return \"bdz %l0\";
14189   else
14190     return \"{bdn|bdnz} $+8\;b %l0\";
14191 }"
14192   [(set_attr "type" "branch")
14193    (set_attr "length" "*,12,16,16")])
14194
14195 (define_insn "*ctrsi_internal6"
14196   [(set (pc)
14197         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14198                           (const_int 1))
14199                       (pc)
14200                       (label_ref (match_operand 0 "" ""))))
14201    (set (match_operand:SI 2 "register_operand" "=1,*r,m,*q*c*l")
14202         (plus:SI (match_dup 1)
14203                  (const_int -1)))
14204    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14205    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14206   "! TARGET_POWERPC64"
14207   "*
14208 {
14209   if (which_alternative != 0)
14210     return \"#\";
14211   else if (get_attr_length (insn) == 4)
14212     return \"{bdn|bdnz} %l0\";
14213   else
14214     return \"bdz $+8\;b %l0\";
14215 }"
14216   [(set_attr "type" "branch")
14217    (set_attr "length" "*,12,16,16")])
14218
14219 (define_insn "*ctrdi_internal5"
14220   [(set (pc)
14221         (if_then_else (eq (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14222                           (const_int 1))
14223                       (label_ref (match_operand 0 "" ""))
14224                       (pc)))
14225    (set (match_operand:DI 2 "register_operand" "=1,*r,m,*c*l")
14226         (plus:DI (match_dup 1)
14227                  (const_int -1)))
14228    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14229    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14230   "TARGET_POWERPC64"
14231   "*
14232 {
14233   if (which_alternative != 0)
14234     return \"#\";
14235   else if (get_attr_length (insn) == 4)
14236     return \"bdz %l0\";
14237   else
14238     return \"{bdn|bdnz} $+8\;b %l0\";
14239 }"
14240   [(set_attr "type" "branch")
14241    (set_attr "length" "*,12,16,16")])
14242
14243 (define_insn "*ctrdi_internal6"
14244   [(set (pc)
14245         (if_then_else (eq (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14246                           (const_int 1))
14247                       (pc)
14248                       (label_ref (match_operand 0 "" ""))))
14249    (set (match_operand:DI 2 "register_operand" "=1,*r,m,*c*l")
14250         (plus:DI (match_dup 1)
14251                  (const_int -1)))
14252    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14253    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14254   "TARGET_POWERPC64"
14255   "*
14256 {
14257   if (which_alternative != 0)
14258     return \"#\";
14259   else if (get_attr_length (insn) == 4)
14260     return \"{bdn|bdnz} %l0\";
14261   else
14262     return \"bdz $+8\;b %l0\";
14263 }"
14264   [(set_attr "type" "branch")
14265    (set_attr "length" "*,12,16,16")])
14266
14267 ;; Now the splitters if we could not allocate the CTR register
14268
14269 (define_split
14270   [(set (pc)
14271         (if_then_else (match_operator 2 "comparison_operator"
14272                                       [(match_operand:SI 1 "gpc_reg_operand" "")
14273                                        (const_int 1)])
14274                       (match_operand 5 "" "")
14275                       (match_operand 6 "" "")))
14276    (set (match_operand:SI 0 "gpc_reg_operand" "")
14277         (plus:SI (match_dup 1)
14278                  (const_int -1)))
14279    (clobber (match_scratch:CC 3 ""))
14280    (clobber (match_scratch:SI 4 ""))]
14281   "! TARGET_POWERPC64 && reload_completed"
14282   [(parallel [(set (match_dup 3)
14283                    (compare:CC (plus:SI (match_dup 1)
14284                                         (const_int -1))
14285                                (const_int 0)))
14286               (set (match_dup 0)
14287                    (plus:SI (match_dup 1)
14288                             (const_int -1)))])
14289    (set (pc) (if_then_else (match_dup 7)
14290                            (match_dup 5)
14291                            (match_dup 6)))]
14292   "
14293 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
14294                          const0_rtx); }")
14295
14296 (define_split
14297   [(set (pc)
14298         (if_then_else (match_operator 2 "comparison_operator"
14299                                       [(match_operand:SI 1 "gpc_reg_operand" "")
14300                                        (const_int 1)])
14301                       (match_operand 5 "" "")
14302                       (match_operand 6 "" "")))
14303    (set (match_operand:SI 0 "nonimmediate_operand" "")
14304         (plus:SI (match_dup 1) (const_int -1)))
14305    (clobber (match_scratch:CC 3 ""))
14306    (clobber (match_scratch:SI 4 ""))]
14307   "! TARGET_POWERPC64 && reload_completed
14308    && ! gpc_reg_operand (operands[0], SImode)"
14309   [(parallel [(set (match_dup 3)
14310                    (compare:CC (plus:SI (match_dup 1)
14311                                         (const_int -1))
14312                                (const_int 0)))
14313               (set (match_dup 4)
14314                    (plus:SI (match_dup 1)
14315                             (const_int -1)))])
14316    (set (match_dup 0)
14317         (match_dup 4))
14318    (set (pc) (if_then_else (match_dup 7)
14319                            (match_dup 5)
14320                            (match_dup 6)))]
14321   "
14322 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
14323                          const0_rtx); }")
14324 (define_split
14325   [(set (pc)
14326         (if_then_else (match_operator 2 "comparison_operator"
14327                                       [(match_operand:DI 1 "gpc_reg_operand" "")
14328                                        (const_int 1)])
14329                       (match_operand 5 "" "")
14330                       (match_operand 6 "" "")))
14331    (set (match_operand:DI 0 "gpc_reg_operand" "")
14332         (plus:DI (match_dup 1)
14333                  (const_int -1)))
14334    (clobber (match_scratch:CC 3 ""))
14335    (clobber (match_scratch:DI 4 ""))]
14336   "TARGET_POWERPC64 && reload_completed"
14337   [(parallel [(set (match_dup 3)
14338                    (compare:CC (plus:DI (match_dup 1)
14339                                         (const_int -1))
14340                                (const_int 0)))
14341               (set (match_dup 0)
14342                    (plus:DI (match_dup 1)
14343                             (const_int -1)))])
14344    (set (pc) (if_then_else (match_dup 7)
14345                            (match_dup 5)
14346                            (match_dup 6)))]
14347   "
14348 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
14349                          const0_rtx); }")
14350
14351 (define_split
14352   [(set (pc)
14353         (if_then_else (match_operator 2 "comparison_operator"
14354                                       [(match_operand:DI 1 "gpc_reg_operand" "")
14355                                        (const_int 1)])
14356                       (match_operand 5 "" "")
14357                       (match_operand 6 "" "")))
14358    (set (match_operand:DI 0 "nonimmediate_operand" "")
14359         (plus:DI (match_dup 1) (const_int -1)))
14360    (clobber (match_scratch:CC 3 ""))
14361    (clobber (match_scratch:DI 4 ""))]
14362   "TARGET_POWERPC64 && reload_completed
14363    && ! gpc_reg_operand (operands[0], DImode)"
14364   [(parallel [(set (match_dup 3)
14365                    (compare:CC (plus:DI (match_dup 1)
14366                                         (const_int -1))
14367                                (const_int 0)))
14368               (set (match_dup 4)
14369                    (plus:DI (match_dup 1)
14370                             (const_int -1)))])
14371    (set (match_dup 0)
14372         (match_dup 4))
14373    (set (pc) (if_then_else (match_dup 7)
14374                            (match_dup 5)
14375                            (match_dup 6)))]
14376   "
14377 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
14378                          const0_rtx); }")
14379
14380 \f
14381 (define_insn "trap"
14382   [(trap_if (const_int 1) (const_int 0))]
14383   ""
14384   "{t 31,0,0|trap}")
14385
14386 (define_expand "conditional_trap"
14387   [(trap_if (match_operator 0 "trap_comparison_operator"
14388                             [(match_dup 2) (match_dup 3)])
14389             (match_operand 1 "const_int_operand" ""))]
14390   ""
14391   "if (rs6000_compare_fp_p || operands[1] != const0_rtx) FAIL;
14392    operands[2] = rs6000_compare_op0;
14393    operands[3] = rs6000_compare_op1;")
14394
14395 (define_insn ""
14396   [(trap_if (match_operator 0 "trap_comparison_operator"
14397                             [(match_operand:SI 1 "register_operand" "r")
14398                              (match_operand:SI 2 "reg_or_short_operand" "rI")])
14399             (const_int 0))]
14400   ""
14401   "{t|tw}%V0%I2 %1,%2")
14402
14403 (define_insn ""
14404   [(trap_if (match_operator 0 "trap_comparison_operator"
14405                             [(match_operand:DI 1 "register_operand" "r")
14406                              (match_operand:DI 2 "reg_or_short_operand" "rI")])
14407             (const_int 0))]
14408   "TARGET_POWERPC64"
14409   "td%V0%I2 %1,%2")
14410 \f
14411 ;; Insns related to generating the function prologue and epilogue.
14412
14413 (define_expand "prologue"
14414   [(use (const_int 0))]
14415   "TARGET_SCHED_PROLOG"
14416   "
14417 {
14418       rs6000_emit_prologue ();
14419       DONE;
14420 }")
14421
14422 (define_insn "*movesi_from_cr_one"
14423   [(match_parallel 0 "mfcr_operation"
14424                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14425                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
14426                                      (match_operand 3 "immediate_operand" "n")]
14427                           UNSPEC_MOVESI_FROM_CR))])]
14428   "TARGET_MFCRF"
14429   "*
14430 {
14431   int mask = 0;
14432   int i;
14433   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14434   {
14435     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14436     operands[4] = GEN_INT (mask);
14437     output_asm_insn (\"mfcr %1,%4\", operands);
14438   }
14439   return \"\";
14440 }"
14441   [(set_attr "type" "mfcrf")])
14442
14443 (define_insn "movesi_from_cr"
14444   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14445         (unspec:SI [(reg:CC 68) (reg:CC 69) (reg:CC 70) (reg:CC 71) 
14446                     (reg:CC 72) (reg:CC 73) (reg:CC 74) (reg:CC 75)]
14447                    UNSPEC_MOVESI_FROM_CR))]
14448   ""
14449   "mfcr %0"
14450   [(set_attr "type" "mfcr")])
14451
14452 (define_insn "*stmw"
14453   [(match_parallel 0 "stmw_operation"
14454                    [(set (match_operand:SI 1 "memory_operand" "=m")
14455                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
14456   "TARGET_MULTIPLE"
14457   "{stm|stmw} %2,%1")
14458  
14459 (define_insn "*save_fpregs_si"
14460   [(match_parallel 0 "any_operand"
14461                    [(clobber (match_operand:SI 1 "register_operand" "=l"))
14462                     (use (match_operand:SI 2 "call_operand" "s"))
14463                     (set (match_operand:DF 3 "memory_operand" "=m")
14464                          (match_operand:DF 4 "gpc_reg_operand" "f"))])]
14465   "TARGET_32BIT"
14466   "bl %z2"
14467   [(set_attr "type" "branch")
14468    (set_attr "length" "4")])
14469
14470 (define_insn "*save_fpregs_di"
14471   [(match_parallel 0 "any_operand"
14472                    [(clobber (match_operand:DI 1 "register_operand" "=l"))
14473                     (use (match_operand:DI 2 "call_operand" "s"))
14474                     (set (match_operand:DF 3 "memory_operand" "=m")
14475                          (match_operand:DF 4 "gpc_reg_operand" "f"))])]
14476   "TARGET_64BIT"
14477   "bl %z2"
14478   [(set_attr "type" "branch")
14479    (set_attr "length" "4")])
14480
14481 ; These are to explain that changes to the stack pointer should
14482 ; not be moved over stores to stack memory.
14483 (define_insn "stack_tie"
14484   [(set (match_operand:BLK 0 "memory_operand" "+m")
14485         (unspec:BLK [(match_dup 0)] UNSPEC_TIE))]
14486   ""
14487   ""
14488   [(set_attr "length" "0")])
14489
14490
14491 (define_expand "epilogue"
14492   [(use (const_int 0))]
14493   "TARGET_SCHED_PROLOG"
14494   "
14495 {
14496       rs6000_emit_epilogue (FALSE);
14497       DONE;
14498 }")
14499
14500 ; On some processors, doing the mtcrf one CC register at a time is
14501 ; faster (like on the 604e).  On others, doing them all at once is
14502 ; faster; for instance, on the 601 and 750.
14503
14504 (define_expand "movsi_to_cr_one"
14505   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14506         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14507                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
14508   ""
14509   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
14510
14511 (define_insn "*movsi_to_cr"
14512   [(match_parallel 0 "mtcrf_operation"
14513                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
14514                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
14515                                      (match_operand 3 "immediate_operand" "n")]
14516                                     UNSPEC_MOVESI_TO_CR))])]
14517  ""
14518  "*
14519 {
14520   int mask = 0;
14521   int i;
14522   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14523     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14524   operands[4] = GEN_INT (mask);
14525   return \"mtcrf %4,%2\";
14526 }"
14527   [(set_attr "type" "mtcr")])
14528
14529 (define_insn "*mtcrfsi"
14530   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14531         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14532                     (match_operand 2 "immediate_operand" "n")]
14533                    UNSPEC_MOVESI_TO_CR))]
14534   "GET_CODE (operands[0]) == REG 
14535    && CR_REGNO_P (REGNO (operands[0]))
14536    && GET_CODE (operands[2]) == CONST_INT
14537    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
14538   "mtcrf %R0,%1"
14539   [(set_attr "type" "mtcr")])
14540
14541 ; The load-multiple instructions have similar properties.
14542 ; Note that "load_multiple" is a name known to the machine-independent
14543 ; code that actually corresponds to the powerpc load-string.
14544
14545 (define_insn "*lmw"
14546   [(match_parallel 0 "lmw_operation"
14547                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14548                          (match_operand:SI 2 "memory_operand" "m"))])]
14549   "TARGET_MULTIPLE"
14550   "{lm|lmw} %1,%2")
14551  
14552 (define_insn "*return_internal_si"
14553   [(return)
14554    (use (match_operand:SI 0 "register_operand" "lc"))]
14555   "TARGET_32BIT"
14556   "b%T0"
14557   [(set_attr "type" "jmpreg")])
14558
14559 (define_insn "*return_internal_di"
14560   [(return)
14561    (use (match_operand:DI 0 "register_operand" "lc"))]
14562   "TARGET_64BIT"
14563   "b%T0"
14564   [(set_attr "type" "jmpreg")])
14565
14566 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
14567 ; stuff was in GCC.  Oh, and "any_operand" is a bit flexible...
14568
14569 (define_insn "*return_and_restore_fpregs_si"
14570  [(match_parallel 0 "any_operand"
14571                   [(return)
14572                    (use (match_operand:SI 1 "register_operand" "l"))
14573                    (use (match_operand:SI 2 "call_operand" "s"))
14574                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
14575                         (match_operand:DF 4 "memory_operand" "m"))])]
14576  "TARGET_32BIT"
14577  "b %z2")
14578
14579 (define_insn "*return_and_restore_fpregs_di"
14580  [(match_parallel 0 "any_operand"
14581                   [(return)
14582                    (use (match_operand:DI 1 "register_operand" "l"))
14583                    (use (match_operand:DI 2 "call_operand" "s"))
14584                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
14585                         (match_operand:DF 4 "memory_operand" "m"))])]
14586  "TARGET_64BIT"
14587  "b %z2")
14588
14589 ; This is used in compiling the unwind routines.
14590 (define_expand "eh_return"
14591   [(use (match_operand 0 "general_operand" ""))]
14592   ""
14593   "
14594 {
14595   if (TARGET_32BIT)
14596     emit_insn (gen_eh_set_lr_si (operands[0]));
14597   else
14598     emit_insn (gen_eh_set_lr_di (operands[0]));
14599   DONE;
14600 }")
14601
14602 ; We can't expand this before we know where the link register is stored.
14603 (define_insn "eh_set_lr_si"
14604   [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
14605                     UNSPECV_EH_RR)
14606    (clobber (match_scratch:SI 1 "=&b"))]
14607   "TARGET_32BIT"
14608   "#")
14609
14610 (define_insn "eh_set_lr_di"
14611   [(unspec_volatile [(match_operand:DI 0 "register_operand" "r")]
14612                     UNSPECV_EH_RR)
14613    (clobber (match_scratch:DI 1 "=&b"))]
14614   "TARGET_64BIT"
14615   "#")
14616
14617 (define_split
14618   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
14619    (clobber (match_scratch 1 ""))]
14620   "reload_completed"
14621   [(const_int 0)]
14622   "
14623 {
14624   rs6000_stack_t *info = rs6000_stack_info ();
14625
14626   if (info->lr_save_p)
14627     {
14628       rtx frame_rtx = stack_pointer_rtx;
14629       int sp_offset = 0;
14630       rtx tmp;
14631
14632       if (frame_pointer_needed
14633           || current_function_calls_alloca
14634           || info->total_size > 32767)
14635         {
14636           emit_move_insn (operands[1], gen_rtx_MEM (Pmode, frame_rtx));
14637           frame_rtx = operands[1];
14638         }
14639       else if (info->push_p)
14640         sp_offset = info->total_size;
14641
14642       tmp = plus_constant (frame_rtx, info->lr_save_offset + sp_offset);
14643       tmp = gen_rtx_MEM (Pmode, tmp);
14644       emit_move_insn (tmp, operands[0]);
14645     }
14646   else
14647     emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), operands[0]);
14648   DONE;
14649 }")
14650
14651 (define_insn "prefetch"
14652   [(prefetch (match_operand:V4SI 0 "address_operand" "p")
14653              (match_operand:SI 1 "const_int_operand" "n")
14654              (match_operand:SI 2 "const_int_operand" "n"))]
14655   "TARGET_POWERPC"
14656   "*
14657 {
14658   if (GET_CODE (operands[0]) == REG)
14659     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
14660   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
14661 }"
14662   [(set_attr "type" "load")])
14663
14664 (include "altivec.md")
14665 (include "spe.md")