OSDN Git Service

2004-06-22 Eric Christopher <echristo@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, 2004 Free Software Foundation, Inc.
4 ;; Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
5
6 ;; This file is part of GCC.
7
8 ;; GCC is free software; you can redistribute it and/or modify it
9 ;; under the terms of the GNU General Public License as published
10 ;; by the Free Software Foundation; either version 2, or (at your
11 ;; option) any later version.
12
13 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
14 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16 ;; License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING.  If not, write to the
20 ;; Free Software Foundation, 59 Temple Place - Suite 330, Boston,
21 ;; MA 02111-1307, USA.
22
23 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
24
25 ;;
26 ;; UNSPEC usage
27 ;;
28
29 (define_constants
30   [(UNSPEC_FRSP                 0)      ; frsp for POWER machines
31    (UNSPEC_TIE                  5)      ; tie stack contents and stack pointer
32    (UNSPEC_TOCPTR               6)      ; address of a word pointing to the TOC
33    (UNSPEC_TOC                  7)      ; address of the TOC (more-or-less)
34    (UNSPEC_MOVSI_GOT            8)
35    (UNSPEC_MV_CR_OV             9)      ; move_from_CR_ov_bit
36    (UNSPEC_FCTIWZ               10)
37    (UNSPEC_LD_MPIC              15)     ; load_macho_picbase
38    (UNSPEC_MPIC_CORRECT         16)     ; macho_correct_pic
39    (UNSPEC_TLSGD                17)
40    (UNSPEC_TLSLD                18)
41    (UNSPEC_MOVESI_FROM_CR       19)
42    (UNSPEC_MOVESI_TO_CR         20)
43    (UNSPEC_TLSDTPREL            21)
44    (UNSPEC_TLSDTPRELHA          22)
45    (UNSPEC_TLSDTPRELLO          23)
46    (UNSPEC_TLSGOTDTPREL         24)
47    (UNSPEC_TLSTPREL             25)
48    (UNSPEC_TLSTPRELHA           26)
49    (UNSPEC_TLSTPRELLO           27)
50    (UNSPEC_TLSGOTTPREL          28)
51    (UNSPEC_TLSTLS               29)
52    (UNSPEC_FIX_TRUNC_TF         30)     ; fadd, rounding towards zero
53    (UNSPEC_MV_CR_GT             31)     ; move_from_CR_gt_bit
54   ])
55
56 ;;
57 ;; UNSPEC_VOLATILE usage
58 ;;
59
60 (define_constants
61   [(UNSPECV_BLOCK               0)
62    (UNSPECV_EH_RR               9)      ; eh_reg_restore
63   ])
64 \f
65 ;; Define an insn type attribute.  This is used in function unit delay
66 ;; computations.
67 (define_attr "type" "integer,load,load_ext,load_ext_u,load_ext_ux,load_ux,load_u,store,store_ux,store_u,fpload,fpload_ux,fpload_u,fpstore,fpstore_ux,fpstore_u,vecload,vecstore,imul,imul2,imul3,lmul,idiv,ldiv,insert_word,branch,cmp,fast_compare,compare,delayed_compare,imul_compare,lmul_compare,fpcompare,cr_logical,delayed_cr,mfcr,mfcrf,mtcr,mfjmpr,mtjmpr,fp,fpsimple,dmul,sdiv,ddiv,ssqrt,dsqrt,jmpreg,brinc,vecsimple,veccomplex,vecdiv,veccmp,veccmpsimple,vecperm,vecfloat,vecfdiv"
68   (const_string "integer"))
69
70 ;; Length (in bytes).
71 ; '(pc)' in the following doesn't include the instruction itself; it is
72 ; calculated as if the instruction had zero size.
73 (define_attr "length" ""
74   (if_then_else (eq_attr "type" "branch")
75                 (if_then_else (and (ge (minus (match_dup 0) (pc))
76                                        (const_int -32768))
77                                    (lt (minus (match_dup 0) (pc))
78                                        (const_int 32764)))
79                               (const_int 4)
80                               (const_int 8))
81                 (const_int 4)))
82
83 ;; Processor type -- this attribute must exactly match the processor_type
84 ;; enumeration in rs6000.h.
85
86 (define_attr "cpu" "rios1,rios2,rs64a,mpccore,ppc403,ppc405,ppc440,ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630,ppc750,ppc7400,ppc7450,ppc8540,power4,power5"
87   (const (symbol_ref "rs6000_cpu_attr")))
88
89 (automata_option "ndfa")
90
91 (include "rios1.md")
92 (include "rios2.md")
93 (include "rs64.md")
94 (include "mpc.md")
95 (include "40x.md")
96 (include "440.md")
97 (include "603.md")
98 (include "6xx.md")
99 (include "7xx.md")
100 (include "7450.md")
101 (include "8540.md")
102 (include "power4.md")
103 (include "power5.md")
104
105 \f
106 ;; Start with fixed-point load and store insns.  Here we put only the more
107 ;; complex forms.  Basic data transfer is done later.
108
109 (define_expand "zero_extendqidi2"
110   [(set (match_operand:DI 0 "gpc_reg_operand" "")
111         (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "")))]
112   "TARGET_POWERPC64"
113   "")
114
115 (define_insn ""
116   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
117         (zero_extend:DI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
118   "TARGET_POWERPC64"
119   "@
120    lbz%U1%X1 %0,%1
121    rldicl %0,%1,0,56"
122   [(set_attr "type" "load,*")])
123
124 (define_insn ""
125   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
126         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
127                     (const_int 0)))
128    (clobber (match_scratch:DI 2 "=r,r"))]
129   "TARGET_64BIT"
130   "@
131    rldicl. %2,%1,0,56
132    #"
133   [(set_attr "type" "compare")
134    (set_attr "length" "4,8")])
135
136 (define_split
137   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
138         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
139                     (const_int 0)))
140    (clobber (match_scratch:DI 2 ""))]
141   "TARGET_POWERPC64 && reload_completed"
142   [(set (match_dup 2)
143         (zero_extend:DI (match_dup 1)))
144    (set (match_dup 0)
145         (compare:CC (match_dup 2)
146                     (const_int 0)))]
147   "")
148
149 (define_insn ""
150   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
151         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
152                     (const_int 0)))
153    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
154         (zero_extend:DI (match_dup 1)))]
155   "TARGET_64BIT"
156   "@
157    rldicl. %0,%1,0,56
158    #"
159   [(set_attr "type" "compare")
160    (set_attr "length" "4,8")])
161
162 (define_split
163   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
164         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
165                     (const_int 0)))
166    (set (match_operand:DI 0 "gpc_reg_operand" "")
167         (zero_extend:DI (match_dup 1)))]
168   "TARGET_POWERPC64 && reload_completed"
169   [(set (match_dup 0)
170         (zero_extend:DI (match_dup 1)))
171    (set (match_dup 2)
172         (compare:CC (match_dup 0)
173                     (const_int 0)))]
174   "")
175
176 (define_insn "extendqidi2"
177   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
178         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
179   "TARGET_POWERPC64"
180   "extsb %0,%1")
181
182 (define_insn ""
183   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
184         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
185                     (const_int 0)))
186    (clobber (match_scratch:DI 2 "=r,r"))]
187   "TARGET_64BIT"
188   "@
189    extsb. %2,%1
190    #"
191   [(set_attr "type" "compare")
192    (set_attr "length" "4,8")])
193
194 (define_split
195   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
196         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
197                     (const_int 0)))
198    (clobber (match_scratch:DI 2 ""))]
199   "TARGET_POWERPC64 && reload_completed"
200   [(set (match_dup 2)
201         (sign_extend:DI (match_dup 1)))
202    (set (match_dup 0)
203         (compare:CC (match_dup 2)
204                     (const_int 0)))]
205   "")
206
207 (define_insn ""
208   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
209         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
210                     (const_int 0)))
211    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
212         (sign_extend:DI (match_dup 1)))]
213   "TARGET_64BIT"
214   "@
215    extsb. %0,%1
216    #"
217   [(set_attr "type" "compare")
218    (set_attr "length" "4,8")])
219
220 (define_split
221   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
222         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
223                     (const_int 0)))
224    (set (match_operand:DI 0 "gpc_reg_operand" "")
225         (sign_extend:DI (match_dup 1)))]
226   "TARGET_POWERPC64 && reload_completed"
227   [(set (match_dup 0)
228         (sign_extend:DI (match_dup 1)))
229    (set (match_dup 2)
230         (compare:CC (match_dup 0)
231                     (const_int 0)))]
232   "")
233
234 (define_expand "zero_extendhidi2"
235   [(set (match_operand:DI 0 "gpc_reg_operand" "")
236         (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
237   "TARGET_POWERPC64"
238   "")
239
240 (define_insn ""
241   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
242         (zero_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
243   "TARGET_POWERPC64"
244   "@
245    lhz%U1%X1 %0,%1
246    rldicl %0,%1,0,48"
247   [(set_attr "type" "load,*")])
248
249 (define_insn ""
250   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
251         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
252                     (const_int 0)))
253    (clobber (match_scratch:DI 2 "=r,r"))]
254   "TARGET_64BIT"
255   "@
256    rldicl. %2,%1,0,48
257    #"
258   [(set_attr "type" "compare")
259    (set_attr "length" "4,8")])
260
261 (define_split
262   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
263         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
264                     (const_int 0)))
265    (clobber (match_scratch:DI 2 ""))]
266   "TARGET_POWERPC64 && reload_completed"
267   [(set (match_dup 2)
268         (zero_extend:DI (match_dup 1)))
269    (set (match_dup 0)
270         (compare:CC (match_dup 2)
271                     (const_int 0)))]
272   "")
273
274 (define_insn ""
275   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
276         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
277                     (const_int 0)))
278    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
279         (zero_extend:DI (match_dup 1)))]
280   "TARGET_64BIT"
281   "@
282    rldicl. %0,%1,0,48
283    #"
284   [(set_attr "type" "compare")
285    (set_attr "length" "4,8")])
286
287 (define_split
288   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
289         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
290                     (const_int 0)))
291    (set (match_operand:DI 0 "gpc_reg_operand" "")
292         (zero_extend:DI (match_dup 1)))]
293   "TARGET_POWERPC64 && reload_completed"
294   [(set (match_dup 0)
295         (zero_extend:DI (match_dup 1)))
296    (set (match_dup 2)
297         (compare:CC (match_dup 0)
298                     (const_int 0)))]
299   "")
300
301 (define_expand "extendhidi2"
302   [(set (match_operand:DI 0 "gpc_reg_operand" "")
303         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
304   "TARGET_POWERPC64"
305   "")
306
307 (define_insn ""
308   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
309         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
310   "TARGET_POWERPC64"
311   "@
312    lha%U1%X1 %0,%1
313    extsh %0,%1"
314   [(set_attr "type" "load_ext,*")])
315
316 (define_insn ""
317   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
318         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
319                     (const_int 0)))
320    (clobber (match_scratch:DI 2 "=r,r"))]
321   "TARGET_64BIT"
322   "@
323    extsh. %2,%1
324    #"
325   [(set_attr "type" "compare")
326    (set_attr "length" "4,8")])
327
328 (define_split
329   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
330         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
331                     (const_int 0)))
332    (clobber (match_scratch:DI 2 ""))]
333   "TARGET_POWERPC64 && reload_completed"
334   [(set (match_dup 2)
335         (sign_extend:DI (match_dup 1)))
336    (set (match_dup 0)
337         (compare:CC (match_dup 2)
338                     (const_int 0)))]
339   "")
340
341 (define_insn ""
342   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
343         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
344                     (const_int 0)))
345    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
346         (sign_extend:DI (match_dup 1)))]
347   "TARGET_64BIT"
348   "@
349    extsh. %0,%1
350    #"
351   [(set_attr "type" "compare")
352    (set_attr "length" "4,8")])
353
354 (define_split
355   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
356         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
357                     (const_int 0)))
358    (set (match_operand:DI 0 "gpc_reg_operand" "")
359         (sign_extend:DI (match_dup 1)))]
360   "TARGET_POWERPC64 && reload_completed"
361   [(set (match_dup 0)
362         (sign_extend:DI (match_dup 1)))
363    (set (match_dup 2)
364         (compare:CC (match_dup 0)
365                     (const_int 0)))]
366   "")
367
368 (define_expand "zero_extendsidi2"
369   [(set (match_operand:DI 0 "gpc_reg_operand" "")
370         (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
371   "TARGET_POWERPC64"
372   "")
373
374 (define_insn ""
375   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
376         (zero_extend:DI (match_operand:SI 1 "reg_or_mem_operand" "m,r")))]
377   "TARGET_POWERPC64"
378   "@
379    lwz%U1%X1 %0,%1
380    rldicl %0,%1,0,32"
381   [(set_attr "type" "load,*")])
382
383 (define_insn ""
384   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
385         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
386                     (const_int 0)))
387    (clobber (match_scratch:DI 2 "=r,r"))]
388   "TARGET_64BIT"
389   "@
390    rldicl. %2,%1,0,32
391    #"
392   [(set_attr "type" "compare")
393    (set_attr "length" "4,8")])
394
395 (define_split
396   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
397         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
398                     (const_int 0)))
399    (clobber (match_scratch:DI 2 ""))]
400   "TARGET_POWERPC64 && reload_completed"
401   [(set (match_dup 2)
402         (zero_extend:DI (match_dup 1)))
403    (set (match_dup 0)
404         (compare:CC (match_dup 2)
405                     (const_int 0)))]
406   "")
407
408 (define_insn ""
409   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
410         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
411                     (const_int 0)))
412    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
413         (zero_extend:DI (match_dup 1)))]
414   "TARGET_64BIT"
415   "@
416    rldicl. %0,%1,0,32
417    #"
418   [(set_attr "type" "compare")
419    (set_attr "length" "4,8")])
420
421 (define_split
422   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
423         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
424                     (const_int 0)))
425    (set (match_operand:DI 0 "gpc_reg_operand" "")
426         (zero_extend:DI (match_dup 1)))]
427   "TARGET_POWERPC64 && reload_completed"
428   [(set (match_dup 0)
429         (zero_extend:DI (match_dup 1)))
430    (set (match_dup 2)
431         (compare:CC (match_dup 0)
432                     (const_int 0)))]
433   "")
434
435 (define_expand "extendsidi2"
436   [(set (match_operand:DI 0 "gpc_reg_operand" "")
437         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
438   "TARGET_POWERPC64"
439   "")
440
441 (define_insn ""
442   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
443         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
444   "TARGET_POWERPC64"
445   "@
446    lwa%U1%X1 %0,%1
447    extsw %0,%1"
448   [(set_attr "type" "load_ext,*")])
449
450 (define_insn ""
451   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
452         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
453                     (const_int 0)))
454    (clobber (match_scratch:DI 2 "=r,r"))]
455   "TARGET_64BIT"
456   "@
457    extsw. %2,%1
458    #"
459   [(set_attr "type" "compare")
460    (set_attr "length" "4,8")])
461
462 (define_split
463   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
464         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
465                     (const_int 0)))
466    (clobber (match_scratch:DI 2 ""))]
467   "TARGET_POWERPC64 && reload_completed"
468   [(set (match_dup 2)
469         (sign_extend:DI (match_dup 1)))
470    (set (match_dup 0)
471         (compare:CC (match_dup 2)
472                     (const_int 0)))]
473   "")
474
475 (define_insn ""
476   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
477         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
478                     (const_int 0)))
479    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
480         (sign_extend:DI (match_dup 1)))]
481   "TARGET_64BIT"
482   "@
483    extsw. %0,%1
484    #"
485   [(set_attr "type" "compare")
486    (set_attr "length" "4,8")])
487
488 (define_split
489   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
490         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
491                     (const_int 0)))
492    (set (match_operand:DI 0 "gpc_reg_operand" "")
493         (sign_extend:DI (match_dup 1)))]
494   "TARGET_POWERPC64 && reload_completed"
495   [(set (match_dup 0)
496         (sign_extend:DI (match_dup 1)))
497    (set (match_dup 2)
498         (compare:CC (match_dup 0)
499                     (const_int 0)))]
500   "")
501
502 (define_expand "zero_extendqisi2"
503   [(set (match_operand:SI 0 "gpc_reg_operand" "")
504         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
505   ""
506   "")
507
508 (define_insn ""
509   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
510         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
511   ""
512   "@
513    lbz%U1%X1 %0,%1
514    {rlinm|rlwinm} %0,%1,0,0xff"
515   [(set_attr "type" "load,*")])
516
517 (define_insn ""
518   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
519         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
520                     (const_int 0)))
521    (clobber (match_scratch:SI 2 "=r,r"))]
522   ""
523   "@
524    {andil.|andi.} %2,%1,0xff
525    #"
526   [(set_attr "type" "compare")
527    (set_attr "length" "4,8")])
528
529 (define_split
530   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
531         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
532                     (const_int 0)))
533    (clobber (match_scratch:SI 2 ""))]
534   "reload_completed"
535   [(set (match_dup 2)
536         (zero_extend:SI (match_dup 1)))
537    (set (match_dup 0)
538         (compare:CC (match_dup 2)
539                     (const_int 0)))]
540   "")
541
542 (define_insn ""
543   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
544         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
545                     (const_int 0)))
546    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
547         (zero_extend:SI (match_dup 1)))]
548   ""
549   "@
550    {andil.|andi.} %0,%1,0xff
551    #"
552   [(set_attr "type" "compare")
553    (set_attr "length" "4,8")])
554
555 (define_split
556   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
557         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
558                     (const_int 0)))
559    (set (match_operand:SI 0 "gpc_reg_operand" "")
560         (zero_extend:SI (match_dup 1)))]
561   "reload_completed"
562   [(set (match_dup 0)
563         (zero_extend:SI (match_dup 1)))
564    (set (match_dup 2)
565         (compare:CC (match_dup 0)
566                     (const_int 0)))]
567   "")
568
569 (define_expand "extendqisi2"
570   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
571    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
572   ""
573   "
574 {
575   if (TARGET_POWERPC)
576     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
577   else if (TARGET_POWER)
578     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
579   else
580     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
581   DONE;
582 }")
583
584 (define_insn "extendqisi2_ppc"
585   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
586         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
587   "TARGET_POWERPC"
588   "extsb %0,%1")
589
590 (define_insn ""
591   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
592         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
593                     (const_int 0)))
594    (clobber (match_scratch:SI 2 "=r,r"))]
595   "TARGET_POWERPC"
596   "@
597    extsb. %2,%1
598    #"
599   [(set_attr "type" "compare")
600    (set_attr "length" "4,8")])
601
602 (define_split
603   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
604         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
605                     (const_int 0)))
606    (clobber (match_scratch:SI 2 ""))]
607   "TARGET_POWERPC && reload_completed"
608   [(set (match_dup 2)
609         (sign_extend:SI (match_dup 1)))
610    (set (match_dup 0)
611         (compare:CC (match_dup 2)
612                     (const_int 0)))]
613   "")
614
615 (define_insn ""
616   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
617         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
618                     (const_int 0)))
619    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
620         (sign_extend:SI (match_dup 1)))]
621   "TARGET_POWERPC"
622   "@
623    extsb. %0,%1
624    #"
625   [(set_attr "type" "compare")
626    (set_attr "length" "4,8")])
627
628 (define_split
629   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
630         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
631                     (const_int 0)))
632    (set (match_operand:SI 0 "gpc_reg_operand" "")
633         (sign_extend:SI (match_dup 1)))]
634   "TARGET_POWERPC && reload_completed"
635   [(set (match_dup 0)
636         (sign_extend:SI (match_dup 1)))
637    (set (match_dup 2)
638         (compare:CC (match_dup 0)
639                     (const_int 0)))]
640   "")
641
642 (define_expand "extendqisi2_power"
643   [(parallel [(set (match_dup 2)
644                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
645                               (const_int 24)))
646               (clobber (scratch:SI))])
647    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
648                    (ashiftrt:SI (match_dup 2)
649                                 (const_int 24)))
650               (clobber (scratch:SI))])]
651   "TARGET_POWER"
652   "
653 { operands[1] = gen_lowpart (SImode, operands[1]);
654   operands[2] = gen_reg_rtx (SImode); }")
655
656 (define_expand "extendqisi2_no_power"
657   [(set (match_dup 2)
658         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
659                    (const_int 24)))
660    (set (match_operand:SI 0 "gpc_reg_operand" "")
661         (ashiftrt:SI (match_dup 2)
662                      (const_int 24)))]
663   "! TARGET_POWER && ! TARGET_POWERPC"
664   "
665 { operands[1] = gen_lowpart (SImode, operands[1]);
666   operands[2] = gen_reg_rtx (SImode); }")
667
668 (define_expand "zero_extendqihi2"
669   [(set (match_operand:HI 0 "gpc_reg_operand" "")
670         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
671   ""
672   "")
673
674 (define_insn ""
675   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
676         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
677   ""
678   "@
679    lbz%U1%X1 %0,%1
680    {rlinm|rlwinm} %0,%1,0,0xff"
681   [(set_attr "type" "load,*")])
682
683 (define_insn ""
684   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
685         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
686                     (const_int 0)))
687    (clobber (match_scratch:HI 2 "=r,r"))]
688   ""
689   "@
690    {andil.|andi.} %2,%1,0xff
691    #"
692   [(set_attr "type" "compare")
693    (set_attr "length" "4,8")])
694
695 (define_split
696   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
697         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
698                     (const_int 0)))
699    (clobber (match_scratch:HI 2 ""))]
700   "reload_completed"
701   [(set (match_dup 2)
702         (zero_extend:HI (match_dup 1)))
703    (set (match_dup 0)
704         (compare:CC (match_dup 2)
705                     (const_int 0)))]
706   "")
707
708 (define_insn ""
709   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
710         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
711                     (const_int 0)))
712    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
713         (zero_extend:HI (match_dup 1)))]
714   ""
715   "@
716    {andil.|andi.} %0,%1,0xff
717    #"
718   [(set_attr "type" "compare")
719    (set_attr "length" "4,8")])
720
721 (define_split
722   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
723         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
724                     (const_int 0)))
725    (set (match_operand:HI 0 "gpc_reg_operand" "")
726         (zero_extend:HI (match_dup 1)))]
727   "reload_completed"
728   [(set (match_dup 0)
729         (zero_extend:HI (match_dup 1)))
730    (set (match_dup 2)
731         (compare:CC (match_dup 0)
732                     (const_int 0)))]
733   "")
734
735 (define_expand "extendqihi2"
736   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
737    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
738   ""
739   "
740 {
741   if (TARGET_POWERPC)
742     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
743   else if (TARGET_POWER)
744     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
745   else
746     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
747   DONE;
748 }")
749
750 (define_insn "extendqihi2_ppc"
751   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
752         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
753   "TARGET_POWERPC"
754   "extsb %0,%1")
755
756 (define_insn ""
757   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
758         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
759                     (const_int 0)))
760    (clobber (match_scratch:HI 2 "=r,r"))]
761   "TARGET_POWERPC"
762   "@
763    extsb. %2,%1
764    #"
765   [(set_attr "type" "compare")
766    (set_attr "length" "4,8")])
767
768 (define_split
769   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
770         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
771                     (const_int 0)))
772    (clobber (match_scratch:HI 2 ""))]
773   "TARGET_POWERPC && reload_completed"
774   [(set (match_dup 2)
775         (sign_extend:HI (match_dup 1)))
776    (set (match_dup 0)
777         (compare:CC (match_dup 2)
778                     (const_int 0)))]
779   "")
780
781 (define_insn ""
782   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
783         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
784                     (const_int 0)))
785    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
786         (sign_extend:HI (match_dup 1)))]
787   "TARGET_POWERPC"
788   "@
789    extsb. %0,%1
790    #"
791   [(set_attr "type" "compare")
792    (set_attr "length" "4,8")])
793
794 (define_split
795   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
796         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
797                     (const_int 0)))
798    (set (match_operand:HI 0 "gpc_reg_operand" "")
799         (sign_extend:HI (match_dup 1)))]
800   "TARGET_POWERPC && reload_completed"
801   [(set (match_dup 0)
802         (sign_extend:HI (match_dup 1)))
803    (set (match_dup 2)
804         (compare:CC (match_dup 0)
805                     (const_int 0)))]
806   "")
807
808 (define_expand "extendqihi2_power"
809   [(parallel [(set (match_dup 2)
810                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
811                               (const_int 24)))
812               (clobber (scratch:SI))])
813    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
814                    (ashiftrt:SI (match_dup 2)
815                                 (const_int 24)))
816               (clobber (scratch:SI))])]
817   "TARGET_POWER"
818   "
819 { operands[0] = gen_lowpart (SImode, operands[0]);
820   operands[1] = gen_lowpart (SImode, operands[1]);
821   operands[2] = gen_reg_rtx (SImode); }")
822
823 (define_expand "extendqihi2_no_power"
824   [(set (match_dup 2)
825         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
826                    (const_int 24)))
827    (set (match_operand:HI 0 "gpc_reg_operand" "")
828         (ashiftrt:SI (match_dup 2)
829                      (const_int 24)))]
830   "! TARGET_POWER && ! TARGET_POWERPC"
831   "
832 { operands[0] = gen_lowpart (SImode, operands[0]);
833   operands[1] = gen_lowpart (SImode, operands[1]);
834   operands[2] = gen_reg_rtx (SImode); }")
835
836 (define_expand "zero_extendhisi2"
837   [(set (match_operand:SI 0 "gpc_reg_operand" "")
838         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
839   ""
840   "")
841
842 (define_insn ""
843   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
844         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
845   ""
846   "@
847    lhz%U1%X1 %0,%1
848    {rlinm|rlwinm} %0,%1,0,0xffff"
849   [(set_attr "type" "load,*")])
850
851 (define_insn ""
852   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
853         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
854                     (const_int 0)))
855    (clobber (match_scratch:SI 2 "=r,r"))]
856   ""
857   "@
858    {andil.|andi.} %2,%1,0xffff
859    #"
860   [(set_attr "type" "compare")
861    (set_attr "length" "4,8")])
862
863 (define_split
864   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
865         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
866                     (const_int 0)))
867    (clobber (match_scratch:SI 2 ""))]
868   "reload_completed"
869   [(set (match_dup 2)
870         (zero_extend:SI (match_dup 1)))
871    (set (match_dup 0)
872         (compare:CC (match_dup 2)
873                     (const_int 0)))]
874   "")
875
876 (define_insn ""
877   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
878         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
879                     (const_int 0)))
880    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
881         (zero_extend:SI (match_dup 1)))]
882   ""
883   "@
884    {andil.|andi.} %0,%1,0xffff
885    #"
886   [(set_attr "type" "compare")
887    (set_attr "length" "4,8")])
888
889 (define_split
890   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
891         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
892                     (const_int 0)))
893    (set (match_operand:SI 0 "gpc_reg_operand" "")
894         (zero_extend:SI (match_dup 1)))]
895   "reload_completed"
896   [(set (match_dup 0)
897         (zero_extend:SI (match_dup 1)))
898    (set (match_dup 2)
899         (compare:CC (match_dup 0)
900                     (const_int 0)))]
901   "")
902
903 (define_expand "extendhisi2"
904   [(set (match_operand:SI 0 "gpc_reg_operand" "")
905         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
906   ""
907   "")
908
909 (define_insn ""
910   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
911         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
912   ""
913   "@
914    lha%U1%X1 %0,%1
915    {exts|extsh} %0,%1"
916   [(set_attr "type" "load_ext,*")])
917
918 (define_insn ""
919   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
920         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
921                     (const_int 0)))
922    (clobber (match_scratch:SI 2 "=r,r"))]
923   ""
924   "@
925    {exts.|extsh.} %2,%1
926    #"
927   [(set_attr "type" "compare")
928    (set_attr "length" "4,8")])
929
930 (define_split
931   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
932         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
933                     (const_int 0)))
934    (clobber (match_scratch:SI 2 ""))]
935   "reload_completed"
936   [(set (match_dup 2)
937         (sign_extend:SI (match_dup 1)))
938    (set (match_dup 0)
939         (compare:CC (match_dup 2)
940                     (const_int 0)))]
941   "")
942
943 (define_insn ""
944   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
945         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
946                     (const_int 0)))
947    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
948         (sign_extend:SI (match_dup 1)))]
949   ""
950   "@
951    {exts.|extsh.} %0,%1
952    #"
953   [(set_attr "type" "compare")
954    (set_attr "length" "4,8")])
955 \f
956 (define_split
957   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
958         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
959                     (const_int 0)))
960    (set (match_operand:SI 0 "gpc_reg_operand" "")
961         (sign_extend:SI (match_dup 1)))]
962   "reload_completed"
963   [(set (match_dup 0)
964         (sign_extend:SI (match_dup 1)))
965    (set (match_dup 2)
966         (compare:CC (match_dup 0)
967                     (const_int 0)))]
968   "")
969
970 ;; Fixed-point arithmetic insns.
971
972 ;; Discourage ai/addic because of carry but provide it in an alternative
973 ;; allowing register zero as source.
974 (define_expand "addsi3"
975   [(set (match_operand:SI 0 "gpc_reg_operand" "")
976         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
977                  (match_operand:SI 2 "reg_or_arith_cint_operand" "")))]
978   ""
979   "
980 {
981   if (GET_CODE (operands[2]) == CONST_INT
982                 && ! add_operand (operands[2], SImode))
983     {
984       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
985                  ? operands[0] : gen_reg_rtx (SImode));
986
987       HOST_WIDE_INT val = INTVAL (operands[2]);
988       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
989       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, SImode);
990
991       /* The ordering here is important for the prolog expander.
992          When space is allocated from the stack, adding 'low' first may
993          produce a temporary deallocation (which would be bad).  */
994       emit_insn (gen_addsi3 (tmp, operands[1], GEN_INT (rest)));
995       emit_insn (gen_addsi3 (operands[0], tmp, GEN_INT (low)));
996       DONE;
997     }
998 }")
999
1000 (define_insn "*addsi3_internal1"
1001   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,?r,r")
1002         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,b,r,b")
1003                  (match_operand:SI 2 "add_operand" "r,I,I,L")))]
1004   ""
1005   "@
1006    {cax|add} %0,%1,%2
1007    {cal %0,%2(%1)|addi %0,%1,%2}
1008    {ai|addic} %0,%1,%2
1009    {cau|addis} %0,%1,%v2"
1010   [(set_attr "length" "4,4,4,4")])
1011
1012 (define_insn "addsi3_high"
1013   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1014         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1015                  (high:SI (match_operand 2 "" ""))))]
1016   "TARGET_MACHO && !TARGET_64BIT"
1017   "{cau|addis} %0,%1,ha16(%2)"
1018   [(set_attr "length" "4")])
1019
1020 (define_insn "*addsi3_internal2"
1021   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1022         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1023                              (match_operand:SI 2 "reg_or_short_operand" "r,I,r,I"))
1024                     (const_int 0)))
1025    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
1026   "TARGET_32BIT"
1027   "@
1028    {cax.|add.} %3,%1,%2
1029    {ai.|addic.} %3,%1,%2
1030    #
1031    #"
1032   [(set_attr "type" "fast_compare,compare,compare,compare")
1033    (set_attr "length" "4,4,8,8")])
1034
1035 (define_split
1036   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1037         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1038                              (match_operand:SI 2 "reg_or_short_operand" ""))
1039                     (const_int 0)))
1040    (clobber (match_scratch:SI 3 ""))]
1041   "TARGET_32BIT && reload_completed"
1042   [(set (match_dup 3)
1043         (plus:SI (match_dup 1)
1044                  (match_dup 2)))
1045    (set (match_dup 0)
1046         (compare:CC (match_dup 3)
1047                     (const_int 0)))]
1048   "")
1049
1050 (define_insn "*addsi3_internal3"
1051   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1052         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1053                              (match_operand:SI 2 "reg_or_short_operand" "r,I,r,I"))
1054                     (const_int 0)))
1055    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
1056         (plus:SI (match_dup 1)
1057                  (match_dup 2)))]
1058   "TARGET_32BIT"
1059   "@
1060    {cax.|add.} %0,%1,%2
1061    {ai.|addic.} %0,%1,%2
1062    #
1063    #"
1064   [(set_attr "type" "fast_compare,compare,compare,compare")
1065    (set_attr "length" "4,4,8,8")])
1066
1067 (define_split
1068   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1069         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1070                              (match_operand:SI 2 "reg_or_short_operand" ""))
1071                     (const_int 0)))
1072    (set (match_operand:SI 0 "gpc_reg_operand" "")
1073         (plus:SI (match_dup 1) (match_dup 2)))]
1074   "TARGET_32BIT && reload_completed"
1075   [(set (match_dup 0)
1076         (plus:SI (match_dup 1)
1077                  (match_dup 2)))
1078    (set (match_dup 3)
1079         (compare:CC (match_dup 0)
1080                     (const_int 0)))]
1081   "")
1082
1083 ;; Split an add that we can't do in one insn into two insns, each of which
1084 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1085 ;; add should be last in case the result gets used in an address.
1086
1087 (define_split
1088   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1089         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1090                  (match_operand:SI 2 "non_add_cint_operand" "")))]
1091   ""
1092   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 3)))
1093    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 4)))]
1094 "
1095 {
1096   HOST_WIDE_INT val = INTVAL (operands[2]);
1097   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1098   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, SImode);
1099
1100   operands[3] = GEN_INT (rest);
1101   operands[4] = GEN_INT (low);
1102 }")
1103
1104 (define_insn "one_cmplsi2"
1105   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1106         (not:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1107   ""
1108   "nor %0,%1,%1")
1109
1110 (define_insn ""
1111   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1112         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1113                     (const_int 0)))
1114    (clobber (match_scratch:SI 2 "=r,r"))]
1115   "TARGET_32BIT"
1116   "@
1117    nor. %2,%1,%1
1118    #"
1119   [(set_attr "type" "compare")
1120    (set_attr "length" "4,8")])
1121
1122 (define_split
1123   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1124         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1125                     (const_int 0)))
1126    (clobber (match_scratch:SI 2 ""))]
1127   "TARGET_32BIT && reload_completed"
1128   [(set (match_dup 2)
1129         (not:SI (match_dup 1)))
1130    (set (match_dup 0)
1131         (compare:CC (match_dup 2)
1132                     (const_int 0)))]
1133   "")
1134
1135 (define_insn ""
1136   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1137         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1138                     (const_int 0)))
1139    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1140         (not:SI (match_dup 1)))]
1141   "TARGET_32BIT"
1142   "@
1143    nor. %0,%1,%1
1144    #"
1145   [(set_attr "type" "compare")
1146    (set_attr "length" "4,8")])
1147
1148 (define_split
1149   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1150         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1151                     (const_int 0)))
1152    (set (match_operand:SI 0 "gpc_reg_operand" "")
1153         (not:SI (match_dup 1)))]
1154   "TARGET_32BIT && reload_completed"
1155   [(set (match_dup 0)
1156         (not:SI (match_dup 1)))
1157    (set (match_dup 2)
1158         (compare:CC (match_dup 0)
1159                     (const_int 0)))]
1160   "")
1161
1162 (define_insn ""
1163   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1164         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
1165                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
1166   "! TARGET_POWERPC"
1167   "{sf%I1|subf%I1c} %0,%2,%1")
1168
1169 (define_insn ""
1170   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1171         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "r,I")
1172                   (match_operand:SI 2 "gpc_reg_operand" "r,r")))]
1173   "TARGET_POWERPC"
1174   "@
1175    subf %0,%2,%1
1176    subfic %0,%2,%1")
1177
1178 (define_insn ""
1179   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1180         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1181                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1182                     (const_int 0)))
1183    (clobber (match_scratch:SI 3 "=r,r"))]
1184   "! TARGET_POWERPC"
1185   "@
1186    {sf.|subfc.} %3,%2,%1
1187    #"
1188   [(set_attr "type" "compare")
1189    (set_attr "length" "4,8")])
1190
1191 (define_insn ""
1192   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1193         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1194                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1195                     (const_int 0)))
1196    (clobber (match_scratch:SI 3 "=r,r"))]
1197   "TARGET_POWERPC && TARGET_32BIT"
1198   "@
1199    subf. %3,%2,%1
1200    #"
1201   [(set_attr "type" "fast_compare")
1202    (set_attr "length" "4,8")])
1203
1204 (define_split
1205   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1206         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1207                               (match_operand:SI 2 "gpc_reg_operand" ""))
1208                     (const_int 0)))
1209    (clobber (match_scratch:SI 3 ""))]
1210   "TARGET_32BIT && reload_completed"
1211   [(set (match_dup 3)
1212         (minus:SI (match_dup 1)
1213                   (match_dup 2)))
1214    (set (match_dup 0)
1215         (compare:CC (match_dup 3)
1216                     (const_int 0)))]
1217   "")
1218
1219 (define_insn ""
1220   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1221         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1222                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1223                     (const_int 0)))
1224    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1225         (minus:SI (match_dup 1) (match_dup 2)))]
1226   "! TARGET_POWERPC"
1227   "@
1228    {sf.|subfc.} %0,%2,%1
1229    #"
1230   [(set_attr "type" "compare")
1231    (set_attr "length" "4,8")])
1232
1233 (define_insn ""
1234   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1235         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1236                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1237                     (const_int 0)))
1238    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1239         (minus:SI (match_dup 1)
1240                   (match_dup 2)))]
1241   "TARGET_POWERPC && TARGET_32BIT"
1242   "@
1243    subf. %0,%2,%1
1244    #"
1245   [(set_attr "type" "fast_compare")
1246    (set_attr "length" "4,8")])
1247
1248 (define_split
1249   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1250         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1251                               (match_operand:SI 2 "gpc_reg_operand" ""))
1252                     (const_int 0)))
1253    (set (match_operand:SI 0 "gpc_reg_operand" "")
1254         (minus:SI (match_dup 1)
1255                   (match_dup 2)))]
1256   "TARGET_32BIT && reload_completed"
1257   [(set (match_dup 0)
1258         (minus:SI (match_dup 1)
1259                   (match_dup 2)))
1260    (set (match_dup 3)
1261         (compare:CC (match_dup 0)
1262                     (const_int 0)))]
1263   "")
1264
1265 (define_expand "subsi3"
1266   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1267         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "")
1268                   (match_operand:SI 2 "reg_or_arith_cint_operand" "")))]
1269   ""
1270   "
1271 {
1272   if (GET_CODE (operands[2]) == CONST_INT)
1273     {
1274       emit_insn (gen_addsi3 (operands[0], operands[1],
1275                              negate_rtx (SImode, operands[2])));
1276       DONE;
1277     }
1278 }")
1279
1280 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1281 ;; instruction and some auxiliary computations.  Then we just have a single
1282 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1283 ;; combine.
1284
1285 (define_expand "sminsi3"
1286   [(set (match_dup 3)
1287         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1288                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1289                          (const_int 0)
1290                          (minus:SI (match_dup 2) (match_dup 1))))
1291    (set (match_operand:SI 0 "gpc_reg_operand" "")
1292         (minus:SI (match_dup 2) (match_dup 3)))]
1293   "TARGET_POWER || TARGET_ISEL"
1294   "
1295 {
1296   if (TARGET_ISEL)
1297     {
1298       operands[2] = force_reg (SImode, operands[2]);
1299       rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
1300       DONE;
1301     }
1302
1303   operands[3] = gen_reg_rtx (SImode);
1304 }")
1305
1306 (define_split
1307   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1308         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1309                  (match_operand:SI 2 "reg_or_short_operand" "")))
1310    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1311   "TARGET_POWER"
1312   [(set (match_dup 3)
1313         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1314                          (const_int 0)
1315                          (minus:SI (match_dup 2) (match_dup 1))))
1316    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1317   "")
1318
1319 (define_expand "smaxsi3"
1320   [(set (match_dup 3)
1321         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1322                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1323                          (const_int 0)
1324                          (minus:SI (match_dup 2) (match_dup 1))))
1325    (set (match_operand:SI 0 "gpc_reg_operand" "")
1326         (plus:SI (match_dup 3) (match_dup 1)))]
1327   "TARGET_POWER || TARGET_ISEL"
1328   "
1329 {
1330   if (TARGET_ISEL)
1331     {
1332       operands[2] = force_reg (SImode, operands[2]);
1333       rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
1334       DONE;
1335     }
1336   operands[3] = gen_reg_rtx (SImode);
1337 }")
1338
1339 (define_split
1340   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1341         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1342                  (match_operand:SI 2 "reg_or_short_operand" "")))
1343    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1344   "TARGET_POWER"
1345   [(set (match_dup 3)
1346         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1347                          (const_int 0)
1348                          (minus:SI (match_dup 2) (match_dup 1))))
1349    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1350   "")
1351
1352 (define_expand "uminsi3"
1353   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1354                               (match_dup 5)))
1355    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1356                               (match_dup 5)))
1357    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1358                                        (const_int 0)
1359                                        (minus:SI (match_dup 4) (match_dup 3))))
1360    (set (match_operand:SI 0 "gpc_reg_operand" "")
1361         (minus:SI (match_dup 2) (match_dup 3)))]
1362   "TARGET_POWER || TARGET_ISEL"
1363   "
1364 {
1365   if (TARGET_ISEL)
1366     {
1367       rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
1368       DONE;
1369     }
1370   operands[3] = gen_reg_rtx (SImode);
1371   operands[4] = gen_reg_rtx (SImode);
1372   operands[5] = GEN_INT (-2147483647 - 1);
1373 }")
1374
1375 (define_expand "umaxsi3"
1376   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1377                               (match_dup 5)))
1378    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1379                               (match_dup 5)))
1380    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1381                                        (const_int 0)
1382                                        (minus:SI (match_dup 4) (match_dup 3))))
1383    (set (match_operand:SI 0 "gpc_reg_operand" "")
1384         (plus:SI (match_dup 3) (match_dup 1)))]
1385   "TARGET_POWER || TARGET_ISEL"
1386   "
1387 {
1388   if (TARGET_ISEL)
1389     {
1390       rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
1391       DONE;
1392     }
1393   operands[3] = gen_reg_rtx (SImode);
1394   operands[4] = gen_reg_rtx (SImode);
1395   operands[5] = GEN_INT (-2147483647 - 1);
1396 }")
1397
1398 (define_insn ""
1399   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1400         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1401                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
1402                          (const_int 0)
1403                          (minus:SI (match_dup 2) (match_dup 1))))]
1404   "TARGET_POWER"
1405   "doz%I2 %0,%1,%2")
1406
1407 (define_insn ""
1408   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1409         (compare:CC
1410          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1411                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1412                           (const_int 0)
1413                           (minus:SI (match_dup 2) (match_dup 1)))
1414          (const_int 0)))
1415    (clobber (match_scratch:SI 3 "=r,r"))]
1416   "TARGET_POWER"
1417   "@
1418    doz%I2. %3,%1,%2
1419    #"
1420   [(set_attr "type" "delayed_compare")
1421    (set_attr "length" "4,8")])
1422
1423 (define_split
1424   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1425         (compare:CC
1426          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1427                               (match_operand:SI 2 "reg_or_short_operand" ""))
1428                           (const_int 0)
1429                           (minus:SI (match_dup 2) (match_dup 1)))
1430          (const_int 0)))
1431    (clobber (match_scratch:SI 3 ""))]
1432   "TARGET_POWER && reload_completed"
1433   [(set (match_dup 3)
1434         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1435                           (const_int 0)
1436                           (minus:SI (match_dup 2) (match_dup 1))))
1437    (set (match_dup 0)
1438         (compare:CC (match_dup 3)
1439                     (const_int 0)))]
1440   "")
1441
1442 (define_insn ""
1443   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1444         (compare:CC
1445          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1446                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1447                           (const_int 0)
1448                           (minus:SI (match_dup 2) (match_dup 1)))
1449          (const_int 0)))
1450    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1451         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1452                          (const_int 0)
1453                          (minus:SI (match_dup 2) (match_dup 1))))]
1454   "TARGET_POWER"
1455   "@
1456    doz%I2. %0,%1,%2
1457    #"
1458   [(set_attr "type" "delayed_compare")
1459    (set_attr "length" "4,8")])
1460
1461 (define_split
1462   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1463         (compare:CC
1464          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1465                               (match_operand:SI 2 "reg_or_short_operand" ""))
1466                           (const_int 0)
1467                           (minus:SI (match_dup 2) (match_dup 1)))
1468          (const_int 0)))
1469    (set (match_operand:SI 0 "gpc_reg_operand" "")
1470         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1471                          (const_int 0)
1472                          (minus:SI (match_dup 2) (match_dup 1))))]
1473   "TARGET_POWER && reload_completed"
1474   [(set (match_dup 0)
1475         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1476                          (const_int 0)
1477                          (minus:SI (match_dup 2) (match_dup 1))))
1478    (set (match_dup 3)
1479         (compare:CC (match_dup 0)
1480                     (const_int 0)))]
1481   "")
1482
1483 ;; We don't need abs with condition code because such comparisons should
1484 ;; never be done.
1485 (define_expand "abssi2"
1486   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1487         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
1488   ""
1489   "
1490 {
1491   if (TARGET_ISEL)
1492     {
1493       emit_insn (gen_abssi2_isel (operands[0], operands[1]));
1494       DONE;
1495     }
1496   else if (! TARGET_POWER)
1497     {
1498       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
1499       DONE;
1500     }
1501 }")
1502
1503 (define_insn "*abssi2_power"
1504   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1505         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1506   "TARGET_POWER"
1507   "abs %0,%1")
1508
1509 (define_insn_and_split "abssi2_isel"
1510   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1511         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
1512    (clobber (match_scratch:SI 2 "=&b"))
1513    (clobber (match_scratch:CC 3 "=y"))]
1514   "TARGET_ISEL"
1515   "#"
1516   "&& reload_completed"
1517   [(set (match_dup 2) (neg:SI (match_dup 1)))
1518    (set (match_dup 3)
1519         (compare:CC (match_dup 1)
1520                     (const_int 0)))
1521    (set (match_dup 0)
1522         (if_then_else:SI (ge (match_dup 3)
1523                              (const_int 0))
1524                          (match_dup 1)
1525                          (match_dup 2)))]
1526   "")
1527
1528 (define_insn_and_split "abssi2_nopower"
1529   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1530         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
1531    (clobber (match_scratch:SI 2 "=&r,&r"))]
1532   "! TARGET_POWER && ! TARGET_ISEL"
1533   "#"
1534   "&& reload_completed"
1535   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1536    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1537    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
1538   "")
1539
1540 (define_insn "*nabs_power"
1541   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1542         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
1543   "TARGET_POWER"
1544   "nabs %0,%1")
1545
1546 (define_insn_and_split "*nabs_nopower"
1547   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1548         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
1549    (clobber (match_scratch:SI 2 "=&r,&r"))]
1550   "! TARGET_POWER"
1551   "#"
1552   "&& reload_completed"
1553   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1554    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1555    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
1556   "")
1557
1558 (define_insn "negsi2"
1559   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1560         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1561   ""
1562   "neg %0,%1")
1563
1564 (define_insn ""
1565   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1566         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1567                     (const_int 0)))
1568    (clobber (match_scratch:SI 2 "=r,r"))]
1569   "TARGET_32BIT"
1570   "@
1571    neg. %2,%1
1572    #"
1573   [(set_attr "type" "fast_compare")
1574    (set_attr "length" "4,8")])
1575
1576 (define_split
1577   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1578         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1579                     (const_int 0)))
1580    (clobber (match_scratch:SI 2 ""))]
1581   "TARGET_32BIT && reload_completed"
1582   [(set (match_dup 2)
1583         (neg:SI (match_dup 1)))
1584    (set (match_dup 0)
1585         (compare:CC (match_dup 2)
1586                     (const_int 0)))]
1587   "")
1588
1589 (define_insn ""
1590   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1591         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1592                     (const_int 0)))
1593    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1594         (neg:SI (match_dup 1)))]
1595   "TARGET_32BIT"
1596   "@
1597    neg. %0,%1
1598    #"
1599   [(set_attr "type" "fast_compare")
1600    (set_attr "length" "4,8")])
1601
1602 (define_split
1603   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1604         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1605                     (const_int 0)))
1606    (set (match_operand:SI 0 "gpc_reg_operand" "")
1607         (neg:SI (match_dup 1)))]
1608   "TARGET_32BIT && reload_completed"
1609   [(set (match_dup 0)
1610         (neg:SI (match_dup 1)))
1611    (set (match_dup 2)
1612         (compare:CC (match_dup 0)
1613                     (const_int 0)))]
1614   "")
1615
1616 (define_insn "clzsi2"
1617   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1618         (clz:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1619   ""
1620   "{cntlz|cntlzw} %0,%1")
1621
1622 (define_expand "ctzsi2"
1623   [(set (match_dup 2)
1624         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
1625    (parallel [(set (match_dup 3) (and:SI (match_dup 1)
1626                                          (match_dup 2)))
1627               (clobber (scratch:CC))])
1628    (set (match_dup 4) (clz:SI (match_dup 3)))
1629    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1630         (minus:SI (const_int 31) (match_dup 4)))]
1631   ""
1632   {
1633      operands[2] = gen_reg_rtx (SImode);
1634      operands[3] = gen_reg_rtx (SImode);
1635      operands[4] = gen_reg_rtx (SImode);
1636   })
1637
1638 (define_expand "ffssi2"
1639   [(set (match_dup 2)
1640         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
1641    (parallel [(set (match_dup 3) (and:SI (match_dup 1)
1642                                          (match_dup 2)))
1643               (clobber (scratch:CC))])
1644    (set (match_dup 4) (clz:SI (match_dup 3)))
1645    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1646         (minus:SI (const_int 32) (match_dup 4)))]
1647   ""
1648   {
1649      operands[2] = gen_reg_rtx (SImode);
1650      operands[3] = gen_reg_rtx (SImode);
1651      operands[4] = gen_reg_rtx (SImode);
1652   })
1653
1654 (define_expand "mulsi3"
1655   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1656    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1657    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
1658   ""
1659   "
1660 {
1661   if (TARGET_POWER)
1662     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
1663   else
1664     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
1665   DONE;
1666 }")
1667
1668 (define_insn "mulsi3_mq"
1669   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1670         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1671                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
1672    (clobber (match_scratch:SI 3 "=q,q"))]
1673   "TARGET_POWER"
1674   "@
1675    {muls|mullw} %0,%1,%2
1676    {muli|mulli} %0,%1,%2"
1677    [(set (attr "type")
1678       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
1679                 (const_string "imul3")
1680              (match_operand:SI 2 "short_cint_operand" "")
1681                 (const_string "imul2")]
1682         (const_string "imul")))])
1683
1684 (define_insn "mulsi3_no_mq"
1685   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1686         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1687                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
1688   "! TARGET_POWER"
1689   "@
1690    {muls|mullw} %0,%1,%2
1691    {muli|mulli} %0,%1,%2"
1692    [(set (attr "type")
1693       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
1694                 (const_string "imul3")
1695              (match_operand:SI 2 "short_cint_operand" "")
1696                 (const_string "imul2")]
1697         (const_string "imul")))])
1698
1699 (define_insn "*mulsi3_mq_internal1"
1700   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1701         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1702                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1703                     (const_int 0)))
1704    (clobber (match_scratch:SI 3 "=r,r"))
1705    (clobber (match_scratch:SI 4 "=q,q"))]
1706   "TARGET_POWER"
1707   "@
1708    {muls.|mullw.} %3,%1,%2
1709    #"
1710   [(set_attr "type" "imul_compare")
1711    (set_attr "length" "4,8")])
1712
1713 (define_split
1714   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1715         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1716                              (match_operand:SI 2 "gpc_reg_operand" ""))
1717                     (const_int 0)))
1718    (clobber (match_scratch:SI 3 ""))
1719    (clobber (match_scratch:SI 4 ""))]
1720   "TARGET_POWER && reload_completed"
1721   [(parallel [(set (match_dup 3)
1722         (mult:SI (match_dup 1) (match_dup 2)))
1723    (clobber (match_dup 4))])
1724    (set (match_dup 0)
1725         (compare:CC (match_dup 3)
1726                     (const_int 0)))]
1727   "")
1728
1729 (define_insn "*mulsi3_no_mq_internal1"
1730   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1731         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1732                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1733                     (const_int 0)))
1734    (clobber (match_scratch:SI 3 "=r,r"))]
1735   "! TARGET_POWER"
1736   "@
1737    {muls.|mullw.} %3,%1,%2
1738    #"
1739   [(set_attr "type" "imul_compare")
1740    (set_attr "length" "4,8")])
1741
1742 (define_split
1743   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1744         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1745                              (match_operand:SI 2 "gpc_reg_operand" ""))
1746                     (const_int 0)))
1747    (clobber (match_scratch:SI 3 ""))]
1748   "! TARGET_POWER && reload_completed"
1749   [(set (match_dup 3)
1750         (mult:SI (match_dup 1) (match_dup 2)))
1751    (set (match_dup 0)
1752         (compare:CC (match_dup 3)
1753                     (const_int 0)))]
1754   "")
1755
1756 (define_insn "*mulsi3_mq_internal2"
1757   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1758         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1759                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1760                     (const_int 0)))
1761    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1762         (mult:SI (match_dup 1) (match_dup 2)))
1763    (clobber (match_scratch:SI 4 "=q,q"))]
1764   "TARGET_POWER"
1765   "@
1766    {muls.|mullw.} %0,%1,%2
1767    #"
1768   [(set_attr "type" "imul_compare")
1769    (set_attr "length" "4,8")])
1770
1771 (define_split
1772   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1773         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1774                              (match_operand:SI 2 "gpc_reg_operand" ""))
1775                     (const_int 0)))
1776    (set (match_operand:SI 0 "gpc_reg_operand" "")
1777         (mult:SI (match_dup 1) (match_dup 2)))
1778    (clobber (match_scratch:SI 4 ""))]
1779   "TARGET_POWER && reload_completed"
1780   [(parallel [(set (match_dup 0)
1781         (mult:SI (match_dup 1) (match_dup 2)))
1782    (clobber (match_dup 4))])
1783    (set (match_dup 3)
1784         (compare:CC (match_dup 0)
1785                     (const_int 0)))]
1786   "")
1787
1788 (define_insn "*mulsi3_no_mq_internal2"
1789   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1790         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1791                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1792                     (const_int 0)))
1793    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1794         (mult:SI (match_dup 1) (match_dup 2)))]
1795   "! TARGET_POWER"
1796   "@
1797    {muls.|mullw.} %0,%1,%2
1798    #"
1799   [(set_attr "type" "imul_compare")
1800    (set_attr "length" "4,8")])
1801
1802 (define_split
1803   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1804         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1805                              (match_operand:SI 2 "gpc_reg_operand" ""))
1806                     (const_int 0)))
1807    (set (match_operand:SI 0 "gpc_reg_operand" "")
1808         (mult:SI (match_dup 1) (match_dup 2)))]
1809   "! TARGET_POWER && reload_completed"
1810   [(set (match_dup 0)
1811         (mult:SI (match_dup 1) (match_dup 2)))
1812    (set (match_dup 3)
1813         (compare:CC (match_dup 0)
1814                     (const_int 0)))]
1815   "")
1816
1817 ;; Operand 1 is divided by operand 2; quotient goes to operand
1818 ;; 0 and remainder to operand 3.
1819 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
1820
1821 (define_expand "divmodsi4"
1822   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
1823                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1824                            (match_operand:SI 2 "gpc_reg_operand" "")))
1825               (set (match_operand:SI 3 "register_operand" "")
1826                    (mod:SI (match_dup 1) (match_dup 2)))])]
1827   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
1828   "
1829 {
1830   if (! TARGET_POWER && ! TARGET_POWERPC)
1831     {
1832       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
1833       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
1834       emit_insn (gen_divss_call ());
1835       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
1836       emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
1837       DONE;
1838     }
1839 }")
1840
1841 (define_insn "*divmodsi4_internal"
1842   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1843         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1844                 (match_operand:SI 2 "gpc_reg_operand" "r")))
1845    (set (match_operand:SI 3 "register_operand" "=q")
1846         (mod:SI (match_dup 1) (match_dup 2)))]
1847   "TARGET_POWER"
1848   "divs %0,%1,%2"
1849   [(set_attr "type" "idiv")])
1850
1851 (define_expand "udivsi3"
1852   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1853         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
1854                  (match_operand:SI 2 "gpc_reg_operand" "")))]
1855   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
1856   "
1857 {
1858   if (! TARGET_POWER && ! TARGET_POWERPC)
1859     {
1860       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
1861       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
1862       emit_insn (gen_quous_call ());
1863       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
1864       DONE;
1865     }
1866   else if (TARGET_POWER)
1867     {
1868       emit_insn (gen_udivsi3_mq (operands[0], operands[1], operands[2]));
1869       DONE;
1870     }
1871 }")
1872
1873 (define_insn "udivsi3_mq"
1874   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1875         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1876                  (match_operand:SI 2 "gpc_reg_operand" "r")))
1877    (clobber (match_scratch:SI 3 "=q"))]
1878   "TARGET_POWERPC && TARGET_POWER"
1879   "divwu %0,%1,%2"
1880   [(set_attr "type" "idiv")])
1881
1882 (define_insn "*udivsi3_no_mq"
1883   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1884         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1885                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
1886   "TARGET_POWERPC && ! TARGET_POWER"
1887   "divwu %0,%1,%2"
1888   [(set_attr "type" "idiv")])
1889
1890 ;; For powers of two we can do srai/aze for divide and then adjust for
1891 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
1892 ;; used; for PowerPC, force operands into register and do a normal divide;
1893 ;; for AIX common-mode, use quoss call on register operands.
1894 (define_expand "divsi3"
1895   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1896         (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1897                 (match_operand:SI 2 "reg_or_cint_operand" "")))]
1898   ""
1899   "
1900 {
1901   if (GET_CODE (operands[2]) == CONST_INT
1902       && INTVAL (operands[2]) > 0
1903       && exact_log2 (INTVAL (operands[2])) >= 0)
1904     ;
1905   else if (TARGET_POWERPC)
1906     {
1907       operands[2] = force_reg (SImode, operands[2]);
1908       if (TARGET_POWER)
1909         {
1910           emit_insn (gen_divsi3_mq (operands[0], operands[1], operands[2]));
1911           DONE;
1912         }
1913     }
1914   else if (TARGET_POWER)
1915     FAIL;
1916   else
1917     {
1918       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
1919       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
1920       emit_insn (gen_quoss_call ());
1921       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
1922       DONE;
1923     }
1924 }")
1925
1926 (define_insn "divsi3_mq"
1927   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1928         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1929                 (match_operand:SI 2 "gpc_reg_operand" "r")))
1930    (clobber (match_scratch:SI 3 "=q"))]
1931   "TARGET_POWERPC && TARGET_POWER"
1932   "divw %0,%1,%2"
1933   [(set_attr "type" "idiv")])
1934
1935 (define_insn "*divsi3_no_mq"
1936   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1937         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1938                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
1939   "TARGET_POWERPC && ! TARGET_POWER"
1940   "divw %0,%1,%2"
1941   [(set_attr "type" "idiv")])
1942
1943 (define_expand "modsi3"
1944   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1945    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1946    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
1947   ""
1948   "
1949 {
1950   int i;
1951   rtx temp1;
1952   rtx temp2;
1953
1954   if (GET_CODE (operands[2]) != CONST_INT
1955       || INTVAL (operands[2]) <= 0
1956       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
1957     FAIL;
1958
1959   temp1 = gen_reg_rtx (SImode);
1960   temp2 = gen_reg_rtx (SImode);
1961
1962   emit_insn (gen_divsi3 (temp1, operands[1], operands[2]));
1963   emit_insn (gen_ashlsi3 (temp2, temp1, GEN_INT (i)));
1964   emit_insn (gen_subsi3 (operands[0], operands[1], temp2));
1965   DONE;
1966 }")
1967
1968 (define_insn ""
1969   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1970         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1971                 (match_operand:SI 2 "exact_log2_cint_operand" "N")))]
1972   ""
1973   "{srai|srawi} %0,%1,%p2\;{aze|addze} %0,%0"
1974   [(set_attr "length" "8")])
1975
1976 (define_insn ""
1977   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1978         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1979                             (match_operand:SI 2 "exact_log2_cint_operand" "N,N"))
1980                     (const_int 0)))
1981    (clobber (match_scratch:SI 3 "=r,r"))]
1982   ""
1983   "@
1984    {srai|srawi} %3,%1,%p2\;{aze.|addze.} %3,%3
1985    #"
1986   [(set_attr "type" "compare")
1987    (set_attr "length" "8,12")])
1988
1989 (define_split
1990   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1991         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1992                             (match_operand:SI 2 "exact_log2_cint_operand" ""))
1993                     (const_int 0)))
1994    (clobber (match_scratch:SI 3 ""))]
1995   "reload_completed"
1996   [(set (match_dup 3)
1997         (div:SI (match_dup 1) (match_dup 2)))
1998    (set (match_dup 0)
1999         (compare:CC (match_dup 3)
2000                     (const_int 0)))]
2001   "")
2002
2003 (define_insn ""
2004   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2005         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2006                             (match_operand:SI 2 "exact_log2_cint_operand" "N,N"))
2007                     (const_int 0)))
2008    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2009         (div:SI (match_dup 1) (match_dup 2)))]
2010   ""
2011   "@
2012    {srai|srawi} %0,%1,%p2\;{aze.|addze.} %0,%0
2013    #"
2014   [(set_attr "type" "compare")
2015    (set_attr "length" "8,12")])
2016
2017 (define_split
2018   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2019         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2020                             (match_operand:SI 2 "exact_log2_cint_operand" ""))
2021                     (const_int 0)))
2022    (set (match_operand:SI 0 "gpc_reg_operand" "")
2023         (div:SI (match_dup 1) (match_dup 2)))]
2024   "reload_completed"
2025   [(set (match_dup 0)
2026         (div:SI (match_dup 1) (match_dup 2)))
2027    (set (match_dup 3)
2028         (compare:CC (match_dup 0)
2029                     (const_int 0)))]
2030   "")
2031
2032 (define_insn ""
2033   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2034         (udiv:SI
2035          (plus:DI (ashift:DI
2036                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
2037                    (const_int 32))
2038                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
2039          (match_operand:SI 3 "gpc_reg_operand" "r")))
2040    (set (match_operand:SI 2 "register_operand" "=*q")
2041         (umod:SI
2042          (plus:DI (ashift:DI
2043                    (zero_extend:DI (match_dup 1)) (const_int 32))
2044                   (zero_extend:DI (match_dup 4)))
2045          (match_dup 3)))]
2046   "TARGET_POWER"
2047   "div %0,%1,%3"
2048   [(set_attr "type" "idiv")])
2049
2050 ;; To do unsigned divide we handle the cases of the divisor looking like a
2051 ;; negative number.  If it is a constant that is less than 2**31, we don't
2052 ;; have to worry about the branches.  So make a few subroutines here.
2053 ;;
2054 ;; First comes the normal case.
2055 (define_expand "udivmodsi4_normal"
2056   [(set (match_dup 4) (const_int 0))
2057    (parallel [(set (match_operand:SI 0 "" "")
2058                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2059                                                 (const_int 32))
2060                                      (zero_extend:DI (match_operand:SI 1 "" "")))
2061                             (match_operand:SI 2 "" "")))
2062               (set (match_operand:SI 3 "" "")
2063                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2064                                                 (const_int 32))
2065                                      (zero_extend:DI (match_dup 1)))
2066                             (match_dup 2)))])]
2067   "TARGET_POWER"
2068   "
2069 { operands[4] = gen_reg_rtx (SImode); }")
2070
2071 ;; This handles the branches.
2072 (define_expand "udivmodsi4_tests"
2073   [(set (match_operand:SI 0 "" "") (const_int 0))
2074    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
2075    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
2076    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
2077                            (label_ref (match_operand:SI 4 "" "")) (pc)))
2078    (set (match_dup 0) (const_int 1))
2079    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
2080    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
2081    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
2082                            (label_ref (match_dup 4)) (pc)))]
2083   "TARGET_POWER"
2084   "
2085 { operands[5] = gen_reg_rtx (CCUNSmode);
2086   operands[6] = gen_reg_rtx (CCmode);
2087 }")
2088
2089 (define_expand "udivmodsi4"
2090   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2091                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
2092                             (match_operand:SI 2 "reg_or_cint_operand" "")))
2093               (set (match_operand:SI 3 "gpc_reg_operand" "")
2094                    (umod:SI (match_dup 1) (match_dup 2)))])]
2095   ""
2096   "
2097 {
2098   rtx label = 0;
2099
2100   if (! TARGET_POWER)
2101     {
2102       if (! TARGET_POWERPC)
2103         {
2104           emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2105           emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2106           emit_insn (gen_divus_call ());
2107           emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2108           emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2109           DONE;
2110         }
2111       else
2112         FAIL;
2113     }
2114
2115   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
2116     {
2117       operands[2] = force_reg (SImode, operands[2]);
2118       label = gen_label_rtx ();
2119       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
2120                                   operands[3], label));
2121     }
2122   else
2123     operands[2] = force_reg (SImode, operands[2]);
2124
2125   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
2126                                operands[3]));
2127   if (label)
2128     emit_label (label);
2129
2130   DONE;
2131 }")
2132
2133 ;; AIX architecture-independent common-mode multiply (DImode),
2134 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
2135 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
2136 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
2137 ;; assumed unused if generating common-mode, so ignore.
2138 (define_insn "mulh_call"
2139   [(set (reg:SI 3)
2140         (truncate:SI
2141          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
2142                                (sign_extend:DI (reg:SI 4)))
2143                       (const_int 32))))
2144    (clobber (match_scratch:SI 0 "=l"))]
2145   "! TARGET_POWER && ! TARGET_POWERPC"
2146   "bla __mulh"
2147   [(set_attr "type" "imul")])
2148
2149 (define_insn "mull_call"
2150   [(set (reg:DI 3)
2151         (mult:DI (sign_extend:DI (reg:SI 3))
2152                  (sign_extend:DI (reg:SI 4))))
2153    (clobber (match_scratch:SI 0 "=l"))
2154    (clobber (reg:SI 0))]
2155   "! TARGET_POWER && ! TARGET_POWERPC"
2156   "bla __mull"
2157   [(set_attr "type" "imul")])
2158
2159 (define_insn "divss_call"
2160   [(set (reg:SI 3)
2161         (div:SI (reg:SI 3) (reg:SI 4)))
2162    (set (reg:SI 4)
2163         (mod:SI (reg:SI 3) (reg:SI 4)))
2164    (clobber (match_scratch:SI 0 "=l"))
2165    (clobber (reg:SI 0))]
2166   "! TARGET_POWER && ! TARGET_POWERPC"
2167   "bla __divss"
2168   [(set_attr "type" "idiv")])
2169
2170 (define_insn "divus_call"
2171   [(set (reg:SI 3)
2172         (udiv:SI (reg:SI 3) (reg:SI 4)))
2173    (set (reg:SI 4)
2174         (umod:SI (reg:SI 3) (reg:SI 4)))
2175    (clobber (match_scratch:SI 0 "=l"))
2176    (clobber (reg:SI 0))
2177    (clobber (match_scratch:CC 1 "=x"))
2178    (clobber (reg:CC 69))]
2179   "! TARGET_POWER && ! TARGET_POWERPC"
2180   "bla __divus"
2181   [(set_attr "type" "idiv")])
2182
2183 (define_insn "quoss_call"
2184   [(set (reg:SI 3)
2185         (div:SI (reg:SI 3) (reg:SI 4)))
2186    (clobber (match_scratch:SI 0 "=l"))]
2187   "! TARGET_POWER && ! TARGET_POWERPC"
2188   "bla __quoss"
2189   [(set_attr "type" "idiv")])
2190
2191 (define_insn "quous_call"
2192   [(set (reg:SI 3)
2193         (udiv:SI (reg:SI 3) (reg:SI 4)))
2194    (clobber (match_scratch:SI 0 "=l"))
2195    (clobber (reg:SI 0))
2196    (clobber (match_scratch:CC 1 "=x"))
2197    (clobber (reg:CC 69))]
2198   "! TARGET_POWER && ! TARGET_POWERPC"
2199   "bla __quous"
2200   [(set_attr "type" "idiv")])
2201 \f
2202 ;; Logical instructions
2203 ;; The logical instructions are mostly combined by using match_operator,
2204 ;; but the plain AND insns are somewhat different because there is no
2205 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2206 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2207
2208 (define_insn "andsi3"
2209   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2210         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2211                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2212    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2213   ""
2214   "@
2215    and %0,%1,%2
2216    {rlinm|rlwinm} %0,%1,0,%m2,%M2
2217    {andil.|andi.} %0,%1,%b2
2218    {andiu.|andis.} %0,%1,%u2")
2219
2220 ;; Note to set cr's other than cr0 we do the and immediate and then
2221 ;; the test again -- this avoids a mfcr which on the higher end
2222 ;; machines causes an execution serialization
2223
2224 (define_insn "*andsi3_internal2"
2225   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2226         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2227                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2228                     (const_int 0)))
2229    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2230    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2231   "TARGET_32BIT"
2232   "@
2233    and. %3,%1,%2
2234    {andil.|andi.} %3,%1,%b2
2235    {andiu.|andis.} %3,%1,%u2
2236    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2237    #
2238    #
2239    #
2240    #"
2241   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2242    (set_attr "length" "4,4,4,4,8,8,8,8")])
2243
2244 (define_insn "*andsi3_internal3"
2245   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2246         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2247                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2248                     (const_int 0)))
2249    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2250    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2251   "TARGET_64BIT"
2252   "@
2253    #
2254    {andil.|andi.} %3,%1,%b2
2255    {andiu.|andis.} %3,%1,%u2
2256    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2257    #
2258    #
2259    #
2260    #"
2261   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2262    (set_attr "length" "8,4,4,4,8,8,8,8")])
2263
2264 (define_split
2265   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2266         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2267                             (match_operand:SI 2 "and_operand" ""))
2268                     (const_int 0)))
2269    (clobber (match_scratch:SI 3 ""))
2270    (clobber (match_scratch:CC 4 ""))]
2271   "reload_completed"
2272   [(parallel [(set (match_dup 3)
2273                    (and:SI (match_dup 1)
2274                            (match_dup 2)))
2275               (clobber (match_dup 4))])
2276    (set (match_dup 0)
2277         (compare:CC (match_dup 3)
2278                     (const_int 0)))]
2279   "")
2280
2281 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
2282 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
2283
2284 (define_split
2285   [(set (match_operand:CC 0 "cc_reg_operand" "")
2286         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2287                             (match_operand:SI 2 "gpc_reg_operand" ""))
2288                     (const_int 0)))
2289    (clobber (match_scratch:SI 3 ""))
2290    (clobber (match_scratch:CC 4 ""))]
2291   "TARGET_POWERPC64 && reload_completed"
2292   [(parallel [(set (match_dup 3)
2293                    (and:SI (match_dup 1)
2294                            (match_dup 2)))
2295               (clobber (match_dup 4))])
2296    (set (match_dup 0)
2297         (compare:CC (match_dup 3)
2298                     (const_int 0)))]
2299   "")
2300
2301 (define_insn "*andsi3_internal4"
2302   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2303         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2304                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2305                     (const_int 0)))
2306    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2307         (and:SI (match_dup 1)
2308                 (match_dup 2)))
2309    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2310   "TARGET_32BIT"
2311   "@
2312    and. %0,%1,%2
2313    {andil.|andi.} %0,%1,%b2
2314    {andiu.|andis.} %0,%1,%u2
2315    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2316    #
2317    #
2318    #
2319    #"
2320   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2321    (set_attr "length" "4,4,4,4,8,8,8,8")])
2322
2323 (define_insn "*andsi3_internal5"
2324   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2325         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2326                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2327                     (const_int 0)))
2328    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2329         (and:SI (match_dup 1)
2330                 (match_dup 2)))
2331    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2332   "TARGET_64BIT"
2333   "@
2334    #
2335    {andil.|andi.} %0,%1,%b2
2336    {andiu.|andis.} %0,%1,%u2
2337    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2338    #
2339    #
2340    #
2341    #"
2342   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2343    (set_attr "length" "8,4,4,4,8,8,8,8")])
2344
2345 (define_split
2346   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2347         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2348                             (match_operand:SI 2 "and_operand" ""))
2349                     (const_int 0)))
2350    (set (match_operand:SI 0 "gpc_reg_operand" "")
2351         (and:SI (match_dup 1)
2352                 (match_dup 2)))
2353    (clobber (match_scratch:CC 4 ""))]
2354   "reload_completed"
2355   [(parallel [(set (match_dup 0)
2356                    (and:SI (match_dup 1)
2357                            (match_dup 2)))
2358               (clobber (match_dup 4))])
2359    (set (match_dup 3)
2360         (compare:CC (match_dup 0)
2361                     (const_int 0)))]
2362   "")
2363
2364 (define_split
2365   [(set (match_operand:CC 3 "cc_reg_operand" "")
2366         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2367                             (match_operand:SI 2 "gpc_reg_operand" ""))
2368                     (const_int 0)))
2369    (set (match_operand:SI 0 "gpc_reg_operand" "")
2370         (and:SI (match_dup 1)
2371                 (match_dup 2)))
2372    (clobber (match_scratch:CC 4 ""))]
2373   "TARGET_POWERPC64 && reload_completed"
2374   [(parallel [(set (match_dup 0)
2375                    (and:SI (match_dup 1)
2376                            (match_dup 2)))
2377               (clobber (match_dup 4))])
2378    (set (match_dup 3)
2379         (compare:CC (match_dup 0)
2380                     (const_int 0)))]
2381   "")
2382
2383 ;; Handle the PowerPC64 rlwinm corner case
2384
2385 (define_insn_and_split "*andsi3_internal6"
2386   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2387         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2388                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
2389   "TARGET_POWERPC64"
2390   "#"
2391   "TARGET_POWERPC64"
2392   [(set (match_dup 0)
2393         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
2394                 (match_dup 4)))
2395    (set (match_dup 0)
2396         (rotate:SI (match_dup 0) (match_dup 5)))]
2397   "
2398 {
2399   int mb = extract_MB (operands[2]);
2400   int me = extract_ME (operands[2]);
2401   operands[3] = GEN_INT (me + 1);
2402   operands[5] = GEN_INT (32 - (me + 1));
2403   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2404 }"
2405   [(set_attr "length" "8")])
2406
2407 (define_insn_and_split "*andsi3_internal7"
2408   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2409         (compare:CC (and:SI (match_operand:SI 0 "gpc_reg_operand" "r,r")
2410                             (match_operand:SI 1 "mask_operand_wrap" "i,i"))
2411                     (const_int 0)))
2412    (clobber (match_scratch:SI 3 "=r,r"))]
2413   "TARGET_POWERPC64"
2414   "#"
2415   "TARGET_POWERPC64"
2416   [(parallel [(set (match_dup 2)
2417                    (compare:CC (and:SI (rotate:SI (match_dup 0) (match_dup 4))
2418                                        (match_dup 5))
2419                                (const_int 0)))
2420               (clobber (match_dup 3))])]
2421   "
2422 {
2423   int mb = extract_MB (operands[1]);
2424   int me = extract_ME (operands[1]);
2425   operands[4] = GEN_INT (me + 1);
2426   operands[5] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2427 }"
2428   [(set_attr "type" "delayed_compare,compare")
2429    (set_attr "length" "4,8")])
2430
2431 (define_insn_and_split "*andsi3_internal8"
2432   [(set (match_operand:CC 3 "cc_reg_operand" "=x,??y")
2433         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2434                             (match_operand:SI 2 "mask_operand_wrap" "i,i"))
2435                     (const_int 0)))
2436    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2437         (and:SI (match_dup 1)
2438                 (match_dup 2)))]
2439   "TARGET_POWERPC64"
2440   "#"
2441   "TARGET_POWERPC64"
2442   [(parallel [(set (match_dup 3)
2443                    (compare:CC (and:SI (rotate:SI (match_dup 1) (match_dup 4))
2444                                        (match_dup 5))
2445                                (const_int 0)))
2446               (set (match_dup 0)
2447                    (and:SI (rotate:SI (match_dup 1) (match_dup 4))
2448                            (match_dup 5)))])
2449    (set (match_dup 0)
2450         (rotate:SI (match_dup 0) (match_dup 6)))]
2451   "
2452 {
2453   int mb = extract_MB (operands[2]);
2454   int me = extract_ME (operands[2]);
2455   operands[4] = GEN_INT (me + 1);
2456   operands[6] = GEN_INT (32 - (me + 1));
2457   operands[5] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2458 }"
2459   [(set_attr "type" "delayed_compare,compare")
2460    (set_attr "length" "8,12")])
2461
2462 (define_expand "iorsi3"
2463   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2464         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
2465                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2466   ""
2467   "
2468 {
2469   if (GET_CODE (operands[2]) == CONST_INT
2470       && ! logical_operand (operands[2], SImode))
2471     {
2472       HOST_WIDE_INT value = INTVAL (operands[2]);
2473       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2474                  ? operands[0] : gen_reg_rtx (SImode));
2475
2476       emit_insn (gen_iorsi3 (tmp, operands[1],
2477                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2478       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2479       DONE;
2480     }
2481 }")
2482
2483 (define_expand "xorsi3"
2484   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2485         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
2486                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2487   ""
2488   "
2489 {
2490   if (GET_CODE (operands[2]) == CONST_INT
2491       && ! logical_operand (operands[2], SImode))
2492     {
2493       HOST_WIDE_INT value = INTVAL (operands[2]);
2494       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2495                  ? operands[0] : gen_reg_rtx (SImode));
2496
2497       emit_insn (gen_xorsi3 (tmp, operands[1],
2498                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2499       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2500       DONE;
2501     }
2502 }")
2503
2504 (define_insn "*boolsi3_internal1"
2505   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
2506         (match_operator:SI 3 "boolean_or_operator"
2507          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
2508           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
2509   ""
2510   "@
2511    %q3 %0,%1,%2
2512    {%q3il|%q3i} %0,%1,%b2
2513    {%q3iu|%q3is} %0,%1,%u2")
2514
2515 (define_insn "*boolsi3_internal2"
2516   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2517         (compare:CC (match_operator:SI 4 "boolean_or_operator"
2518          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2519           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2520          (const_int 0)))
2521    (clobber (match_scratch:SI 3 "=r,r"))]
2522   "TARGET_32BIT"
2523   "@
2524    %q4. %3,%1,%2
2525    #"
2526   [(set_attr "type" "compare")
2527    (set_attr "length" "4,8")])
2528
2529 (define_split
2530   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2531         (compare:CC (match_operator:SI 4 "boolean_operator"
2532          [(match_operand:SI 1 "gpc_reg_operand" "")
2533           (match_operand:SI 2 "gpc_reg_operand" "")])
2534          (const_int 0)))
2535    (clobber (match_scratch:SI 3 ""))]
2536   "TARGET_32BIT && reload_completed"
2537   [(set (match_dup 3) (match_dup 4))
2538    (set (match_dup 0)
2539         (compare:CC (match_dup 3)
2540                     (const_int 0)))]
2541   "")
2542
2543 (define_insn "*boolsi3_internal3"
2544   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2545         (compare:CC (match_operator:SI 4 "boolean_operator"
2546          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2547           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2548          (const_int 0)))
2549    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2550         (match_dup 4))]
2551   "TARGET_32BIT"
2552   "@
2553    %q4. %0,%1,%2
2554    #"
2555   [(set_attr "type" "compare")
2556    (set_attr "length" "4,8")])
2557
2558 (define_split
2559   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2560         (compare:CC (match_operator:SI 4 "boolean_operator"
2561          [(match_operand:SI 1 "gpc_reg_operand" "")
2562           (match_operand:SI 2 "gpc_reg_operand" "")])
2563          (const_int 0)))
2564    (set (match_operand:SI 0 "gpc_reg_operand" "")
2565         (match_dup 4))]
2566   "TARGET_32BIT && reload_completed"
2567   [(set (match_dup 0) (match_dup 4))
2568    (set (match_dup 3)
2569         (compare:CC (match_dup 0)
2570                     (const_int 0)))]
2571   "")
2572
2573 ;; Split a logical operation that we can't do in one insn into two insns,
2574 ;; each of which does one 16-bit part.  This is used by combine.
2575
2576 (define_split
2577   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2578         (match_operator:SI 3 "boolean_or_operator"
2579          [(match_operand:SI 1 "gpc_reg_operand" "")
2580           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
2581   ""
2582   [(set (match_dup 0) (match_dup 4))
2583    (set (match_dup 0) (match_dup 5))]
2584 "
2585 {
2586   rtx i;
2587   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
2588   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2589                                 operands[1], i);
2590   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
2591   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2592                                 operands[0], i);
2593 }")
2594
2595 (define_insn "*boolcsi3_internal1"
2596   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2597         (match_operator:SI 3 "boolean_operator"
2598          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
2599           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
2600   ""
2601   "%q3 %0,%2,%1")
2602
2603 (define_insn "*boolcsi3_internal2"
2604   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2605         (compare:CC (match_operator:SI 4 "boolean_operator"
2606          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2607           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2608          (const_int 0)))
2609    (clobber (match_scratch:SI 3 "=r,r"))]
2610   "TARGET_32BIT"
2611   "@
2612    %q4. %3,%2,%1
2613    #"
2614   [(set_attr "type" "compare")
2615    (set_attr "length" "4,8")])
2616
2617 (define_split
2618   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2619         (compare:CC (match_operator:SI 4 "boolean_operator"
2620          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2621           (match_operand:SI 2 "gpc_reg_operand" "")])
2622          (const_int 0)))
2623    (clobber (match_scratch:SI 3 ""))]
2624   "TARGET_32BIT && reload_completed"
2625   [(set (match_dup 3) (match_dup 4))
2626    (set (match_dup 0)
2627         (compare:CC (match_dup 3)
2628                     (const_int 0)))]
2629   "")
2630
2631 (define_insn "*boolcsi3_internal3"
2632   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2633         (compare:CC (match_operator:SI 4 "boolean_operator"
2634          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
2635           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2636          (const_int 0)))
2637    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2638         (match_dup 4))]
2639   "TARGET_32BIT"
2640   "@
2641    %q4. %0,%2,%1
2642    #"
2643   [(set_attr "type" "compare")
2644    (set_attr "length" "4,8")])
2645
2646 (define_split
2647   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2648         (compare:CC (match_operator:SI 4 "boolean_operator"
2649          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2650           (match_operand:SI 2 "gpc_reg_operand" "")])
2651          (const_int 0)))
2652    (set (match_operand:SI 0 "gpc_reg_operand" "")
2653         (match_dup 4))]
2654   "TARGET_32BIT && reload_completed"
2655   [(set (match_dup 0) (match_dup 4))
2656    (set (match_dup 3)
2657         (compare:CC (match_dup 0)
2658                     (const_int 0)))]
2659   "")
2660
2661 (define_insn "*boolccsi3_internal1"
2662   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2663         (match_operator:SI 3 "boolean_operator"
2664          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
2665           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
2666   ""
2667   "%q3 %0,%1,%2")
2668
2669 (define_insn "*boolccsi3_internal2"
2670   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2671         (compare:CC (match_operator:SI 4 "boolean_operator"
2672          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2673           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
2674          (const_int 0)))
2675    (clobber (match_scratch:SI 3 "=r,r"))]
2676   "TARGET_32BIT"
2677   "@
2678    %q4. %3,%1,%2
2679    #"
2680   [(set_attr "type" "compare")
2681    (set_attr "length" "4,8")])
2682
2683 (define_split
2684   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2685         (compare:CC (match_operator:SI 4 "boolean_operator"
2686          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2687           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
2688          (const_int 0)))
2689    (clobber (match_scratch:SI 3 ""))]
2690   "TARGET_32BIT && reload_completed"
2691   [(set (match_dup 3) (match_dup 4))
2692    (set (match_dup 0)
2693         (compare:CC (match_dup 3)
2694                     (const_int 0)))]
2695   "")
2696
2697 (define_insn "*boolccsi3_internal3"
2698   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2699         (compare:CC (match_operator:SI 4 "boolean_operator"
2700          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
2701           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
2702          (const_int 0)))
2703    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2704         (match_dup 4))]
2705   "TARGET_32BIT"
2706   "@
2707    %q4. %0,%1,%2
2708    #"
2709   [(set_attr "type" "compare")
2710    (set_attr "length" "4,8")])
2711
2712 (define_split
2713   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2714         (compare:CC (match_operator:SI 4 "boolean_operator"
2715          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2716           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
2717          (const_int 0)))
2718    (set (match_operand:SI 0 "gpc_reg_operand" "")
2719         (match_dup 4))]
2720   "TARGET_32BIT && reload_completed"
2721   [(set (match_dup 0) (match_dup 4))
2722    (set (match_dup 3)
2723         (compare:CC (match_dup 0)
2724                     (const_int 0)))]
2725   "")
2726
2727 ;; maskir insn.  We need four forms because things might be in arbitrary
2728 ;; orders.  Don't define forms that only set CR fields because these
2729 ;; would modify an input register.
2730
2731 (define_insn "*maskir_internal1"
2732   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2733         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
2734                         (match_operand:SI 1 "gpc_reg_operand" "0"))
2735                 (and:SI (match_dup 2)
2736                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
2737   "TARGET_POWER"
2738   "maskir %0,%3,%2")
2739
2740 (define_insn "*maskir_internal2"
2741   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2742         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
2743                         (match_operand:SI 1 "gpc_reg_operand" "0"))
2744                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2745                         (match_dup 2))))]
2746   "TARGET_POWER"
2747   "maskir %0,%3,%2")
2748
2749 (define_insn "*maskir_internal3"
2750   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2751         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2752                         (match_operand:SI 3 "gpc_reg_operand" "r"))
2753                 (and:SI (not:SI (match_dup 2))
2754                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
2755   "TARGET_POWER"
2756   "maskir %0,%3,%2")
2757
2758 (define_insn "*maskir_internal4"
2759   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2760         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2761                         (match_operand:SI 2 "gpc_reg_operand" "r"))
2762                 (and:SI (not:SI (match_dup 2))
2763                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
2764   "TARGET_POWER"
2765   "maskir %0,%3,%2")
2766
2767 (define_insn "*maskir_internal5"
2768   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2769         (compare:CC
2770          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2771                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
2772                  (and:SI (match_dup 2)
2773                          (match_operand:SI 3 "gpc_reg_operand" "r,r")))
2774          (const_int 0)))
2775    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2776         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2777                 (and:SI (match_dup 2) (match_dup 3))))]
2778   "TARGET_POWER"
2779   "@
2780    maskir. %0,%3,%2
2781    #"
2782   [(set_attr "type" "compare")
2783    (set_attr "length" "4,8")])
2784
2785 (define_split
2786   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2787         (compare:CC
2788          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
2789                          (match_operand:SI 1 "gpc_reg_operand" ""))
2790                  (and:SI (match_dup 2)
2791                          (match_operand:SI 3 "gpc_reg_operand" "")))
2792          (const_int 0)))
2793    (set (match_operand:SI 0 "gpc_reg_operand" "")
2794         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2795                 (and:SI (match_dup 2) (match_dup 3))))]
2796   "TARGET_POWER && reload_completed"
2797   [(set (match_dup 0)
2798         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2799                 (and:SI (match_dup 2) (match_dup 3))))
2800    (set (match_dup 4)
2801         (compare:CC (match_dup 0)
2802                     (const_int 0)))]
2803   "")
2804
2805 (define_insn "*maskir_internal6"
2806   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2807         (compare:CC
2808          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2809                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
2810                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
2811                          (match_dup 2)))
2812          (const_int 0)))
2813    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2814         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2815                 (and:SI (match_dup 3) (match_dup 2))))]
2816   "TARGET_POWER"
2817   "@
2818    maskir. %0,%3,%2
2819    #"
2820   [(set_attr "type" "compare")
2821    (set_attr "length" "4,8")])
2822
2823 (define_split
2824   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2825         (compare:CC
2826          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
2827                          (match_operand:SI 1 "gpc_reg_operand" ""))
2828                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
2829                          (match_dup 2)))
2830          (const_int 0)))
2831    (set (match_operand:SI 0 "gpc_reg_operand" "")
2832         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2833                 (and:SI (match_dup 3) (match_dup 2))))]
2834   "TARGET_POWER && reload_completed"
2835   [(set (match_dup 0)
2836         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2837                 (and:SI (match_dup 3) (match_dup 2))))
2838    (set (match_dup 4)
2839         (compare:CC (match_dup 0)
2840                     (const_int 0)))]
2841   "")
2842
2843 (define_insn "*maskir_internal7"
2844   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2845         (compare:CC
2846          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r,r")
2847                          (match_operand:SI 3 "gpc_reg_operand" "r,r"))
2848                  (and:SI (not:SI (match_dup 2))
2849                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
2850          (const_int 0)))
2851    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2852         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2853                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2854   "TARGET_POWER"
2855   "@
2856    maskir. %0,%3,%2
2857    #"
2858   [(set_attr "type" "compare")
2859    (set_attr "length" "4,8")])
2860
2861 (define_split
2862   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2863         (compare:CC
2864          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "")
2865                          (match_operand:SI 3 "gpc_reg_operand" ""))
2866                  (and:SI (not:SI (match_dup 2))
2867                          (match_operand:SI 1 "gpc_reg_operand" "")))
2868          (const_int 0)))
2869    (set (match_operand:SI 0 "gpc_reg_operand" "")
2870         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2871                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2872   "TARGET_POWER && reload_completed"
2873   [(set (match_dup 0)
2874         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2875                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
2876    (set (match_dup 4)
2877         (compare:CC (match_dup 0)
2878                     (const_int 0)))]
2879   "")
2880
2881 (define_insn "*maskir_internal8"
2882   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2883         (compare:CC
2884          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
2885                          (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2886                  (and:SI (not:SI (match_dup 2))
2887                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
2888          (const_int 0)))
2889    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2890         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2891                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2892   "TARGET_POWER"
2893   "@
2894    maskir. %0,%3,%2
2895    #"
2896   [(set_attr "type" "compare")
2897    (set_attr "length" "4,8")])
2898
2899 (define_split
2900   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2901         (compare:CC
2902          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
2903                          (match_operand:SI 2 "gpc_reg_operand" ""))
2904                  (and:SI (not:SI (match_dup 2))
2905                          (match_operand:SI 1 "gpc_reg_operand" "")))
2906          (const_int 0)))
2907    (set (match_operand:SI 0 "gpc_reg_operand" "")
2908         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2909                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2910   "TARGET_POWER && reload_completed"
2911   [(set (match_dup 0)
2912         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2913                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
2914    (set (match_dup 4)
2915         (compare:CC (match_dup 0)
2916                     (const_int 0)))]
2917   "")
2918 \f
2919 ;; Rotate and shift insns, in all their variants.  These support shifts,
2920 ;; field inserts and extracts, and various combinations thereof.
2921 (define_expand "insv"
2922   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
2923                        (match_operand:SI 1 "const_int_operand" "")
2924                        (match_operand:SI 2 "const_int_operand" ""))
2925         (match_operand 3 "gpc_reg_operand" ""))]
2926   ""
2927   "
2928 {
2929   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
2930      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
2931      compiler if the address of the structure is taken later.  */
2932   if (GET_CODE (operands[0]) == SUBREG
2933       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
2934     FAIL;
2935
2936   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
2937     emit_insn (gen_insvdi (operands[0], operands[1], operands[2], operands[3]));
2938   else
2939     emit_insn (gen_insvsi (operands[0], operands[1], operands[2], operands[3]));
2940   DONE;
2941 }")
2942
2943 (define_insn "insvsi"
2944   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2945                          (match_operand:SI 1 "const_int_operand" "i")
2946                          (match_operand:SI 2 "const_int_operand" "i"))
2947         (match_operand:SI 3 "gpc_reg_operand" "r"))]
2948   ""
2949   "*
2950 {
2951   int start = INTVAL (operands[2]) & 31;
2952   int size = INTVAL (operands[1]) & 31;
2953
2954   operands[4] = GEN_INT (32 - start - size);
2955   operands[1] = GEN_INT (start + size - 1);
2956   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2957 }"
2958   [(set_attr "type" "insert_word")])
2959
2960 (define_insn "*insvsi_internal1"
2961   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2962                          (match_operand:SI 1 "const_int_operand" "i")
2963                          (match_operand:SI 2 "const_int_operand" "i"))
2964         (ashift:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2965                    (match_operand:SI 4 "const_int_operand" "i")))]
2966   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
2967   "*
2968 {
2969   int shift = INTVAL (operands[4]) & 31;
2970   int start = INTVAL (operands[2]) & 31;
2971   int size = INTVAL (operands[1]) & 31;
2972
2973   operands[4] = GEN_INT (shift - start - size);
2974   operands[1] = GEN_INT (start + size - 1);
2975   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2976 }"
2977   [(set_attr "type" "insert_word")])
2978
2979 (define_insn "*insvsi_internal2"
2980   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2981                          (match_operand:SI 1 "const_int_operand" "i")
2982                          (match_operand:SI 2 "const_int_operand" "i"))
2983         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2984                      (match_operand:SI 4 "const_int_operand" "i")))]
2985   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
2986   "*
2987 {
2988   int shift = INTVAL (operands[4]) & 31;
2989   int start = INTVAL (operands[2]) & 31;
2990   int size = INTVAL (operands[1]) & 31;
2991
2992   operands[4] = GEN_INT (32 - shift - start - size);
2993   operands[1] = GEN_INT (start + size - 1);
2994   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2995 }"
2996   [(set_attr "type" "insert_word")])
2997
2998 (define_insn "*insvsi_internal3"
2999   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3000                          (match_operand:SI 1 "const_int_operand" "i")
3001                          (match_operand:SI 2 "const_int_operand" "i"))
3002         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3003                      (match_operand:SI 4 "const_int_operand" "i")))]
3004   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3005   "*
3006 {
3007   int shift = INTVAL (operands[4]) & 31;
3008   int start = INTVAL (operands[2]) & 31;
3009   int size = INTVAL (operands[1]) & 31;
3010
3011   operands[4] = GEN_INT (32 - shift - start - size);
3012   operands[1] = GEN_INT (start + size - 1);
3013   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3014 }"
3015   [(set_attr "type" "insert_word")])
3016
3017 (define_insn "*insvsi_internal4"
3018   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3019                          (match_operand:SI 1 "const_int_operand" "i")
3020                          (match_operand:SI 2 "const_int_operand" "i"))
3021         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3022                          (match_operand:SI 4 "const_int_operand" "i")
3023                          (match_operand:SI 5 "const_int_operand" "i")))]
3024   "INTVAL (operands[4]) >= INTVAL (operands[1])"
3025   "*
3026 {
3027   int extract_start = INTVAL (operands[5]) & 31;
3028   int extract_size = INTVAL (operands[4]) & 31;
3029   int insert_start = INTVAL (operands[2]) & 31;
3030   int insert_size = INTVAL (operands[1]) & 31;
3031
3032 /* Align extract field with insert field */
3033   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
3034   operands[1] = GEN_INT (insert_start + insert_size - 1);
3035   return \"{rlimi|rlwimi} %0,%3,%h5,%h2,%h1\";
3036 }"
3037   [(set_attr "type" "insert_word")])
3038
3039 ;; combine patterns for rlwimi
3040 (define_insn "*insvsi_internal5"
3041   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3042         (ior:SI (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3043                         (match_operand:SI 1 "mask_operand" "i"))
3044                 (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3045                                      (match_operand:SI 2 "const_int_operand" "i"))
3046                         (match_operand:SI 5 "mask_operand" "i"))))]
3047   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
3048   "*
3049 {
3050  int me = extract_ME(operands[5]);
3051  int mb = extract_MB(operands[5]);
3052  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3053  operands[2] = GEN_INT(mb);
3054  operands[1] = GEN_INT(me);
3055  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3056 }"
3057   [(set_attr "type" "insert_word")])
3058
3059 (define_insn "*insvsi_internal6"
3060   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3061         (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3062                                      (match_operand:SI 2 "const_int_operand" "i"))
3063                         (match_operand:SI 5 "mask_operand" "i"))
3064                 (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3065                         (match_operand:SI 1 "mask_operand" "i"))))]
3066   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
3067   "*
3068 {
3069  int me = extract_ME(operands[5]);
3070  int mb = extract_MB(operands[5]);
3071  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3072  operands[2] = GEN_INT(mb);
3073  operands[1] = GEN_INT(me);
3074  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3075 }"
3076   [(set_attr "type" "insert_word")])
3077
3078 (define_insn "insvdi"
3079   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3080                          (match_operand:SI 1 "const_int_operand" "i")
3081                          (match_operand:SI 2 "const_int_operand" "i"))
3082         (match_operand:DI 3 "gpc_reg_operand" "r"))]
3083   "TARGET_POWERPC64"
3084   "*
3085 {
3086   int start = INTVAL (operands[2]) & 63;
3087   int size = INTVAL (operands[1]) & 63;
3088
3089   operands[1] = GEN_INT (64 - start - size);
3090   return \"rldimi %0,%3,%H1,%H2\";
3091 }")
3092
3093 (define_expand "extzv"
3094   [(set (match_operand 0 "gpc_reg_operand" "")
3095         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3096                        (match_operand:SI 2 "const_int_operand" "")
3097                        (match_operand:SI 3 "const_int_operand" "")))]
3098   ""
3099   "
3100 {
3101   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3102      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3103      compiler if the address of the structure is taken later.  */
3104   if (GET_CODE (operands[0]) == SUBREG
3105       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3106     FAIL;
3107
3108   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3109     emit_insn (gen_extzvdi (operands[0], operands[1], operands[2], operands[3]));
3110   else
3111     emit_insn (gen_extzvsi (operands[0], operands[1], operands[2], operands[3]));
3112   DONE;
3113 }")
3114
3115 (define_insn "extzvsi"
3116   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3117         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3118                          (match_operand:SI 2 "const_int_operand" "i")
3119                          (match_operand:SI 3 "const_int_operand" "i")))]
3120   ""
3121   "*
3122 {
3123   int start = INTVAL (operands[3]) & 31;
3124   int size = INTVAL (operands[2]) & 31;
3125
3126   if (start + size >= 32)
3127     operands[3] = const0_rtx;
3128   else
3129     operands[3] = GEN_INT (start + size);
3130   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
3131 }")
3132
3133 (define_insn "*extzvsi_internal1"
3134   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3135         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3136                          (match_operand:SI 2 "const_int_operand" "i,i")
3137                          (match_operand:SI 3 "const_int_operand" "i,i"))
3138                     (const_int 0)))
3139    (clobber (match_scratch:SI 4 "=r,r"))]
3140   ""
3141   "*
3142 {
3143   int start = INTVAL (operands[3]) & 31;
3144   int size = INTVAL (operands[2]) & 31;
3145
3146   /* Force split for non-cc0 compare.  */
3147   if (which_alternative == 1)
3148      return \"#\";
3149
3150   /* If the bit-field being tested fits in the upper or lower half of a
3151      word, it is possible to use andiu. or andil. to test it.  This is
3152      useful because the condition register set-use delay is smaller for
3153      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3154      position is 0 because the LT and GT bits may be set wrong.  */
3155
3156   if ((start > 0 && start + size <= 16) || start >= 16)
3157     {
3158       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3159                               - (1 << (16 - (start & 15) - size))));
3160       if (start < 16)
3161         return \"{andiu.|andis.} %4,%1,%3\";
3162       else
3163         return \"{andil.|andi.} %4,%1,%3\";
3164     }
3165
3166   if (start + size >= 32)
3167     operands[3] = const0_rtx;
3168   else
3169     operands[3] = GEN_INT (start + size);
3170   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
3171 }"
3172   [(set_attr "type" "compare")
3173    (set_attr "length" "4,8")])
3174
3175 (define_split
3176   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3177         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3178                          (match_operand:SI 2 "const_int_operand" "")
3179                          (match_operand:SI 3 "const_int_operand" ""))
3180                     (const_int 0)))
3181    (clobber (match_scratch:SI 4 ""))]
3182   "reload_completed"
3183   [(set (match_dup 4)
3184         (zero_extract:SI (match_dup 1) (match_dup 2)
3185                          (match_dup 3)))
3186    (set (match_dup 0)
3187         (compare:CC (match_dup 4)
3188                     (const_int 0)))]
3189   "")
3190
3191 (define_insn "*extzvsi_internal2"
3192   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3193         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3194                          (match_operand:SI 2 "const_int_operand" "i,i")
3195                          (match_operand:SI 3 "const_int_operand" "i,i"))
3196                     (const_int 0)))
3197    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3198         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3199   ""
3200   "*
3201 {
3202   int start = INTVAL (operands[3]) & 31;
3203   int size = INTVAL (operands[2]) & 31;
3204
3205   /* Force split for non-cc0 compare.  */
3206   if (which_alternative == 1)
3207      return \"#\";
3208
3209   /* Since we are using the output value, we can't ignore any need for
3210      a shift.  The bit-field must end at the LSB.  */
3211   if (start >= 16 && start + size == 32)
3212     {
3213       operands[3] = GEN_INT ((1 << size) - 1);
3214       return \"{andil.|andi.} %0,%1,%3\";
3215     }
3216
3217   if (start + size >= 32)
3218     operands[3] = const0_rtx;
3219   else
3220     operands[3] = GEN_INT (start + size);
3221   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
3222 }"
3223   [(set_attr "type" "compare")
3224    (set_attr "length" "4,8")])
3225
3226 (define_split
3227   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3228         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3229                          (match_operand:SI 2 "const_int_operand" "")
3230                          (match_operand:SI 3 "const_int_operand" ""))
3231                     (const_int 0)))
3232    (set (match_operand:SI 0 "gpc_reg_operand" "")
3233         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3234   "reload_completed"
3235   [(set (match_dup 0)
3236         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3237    (set (match_dup 4)
3238         (compare:CC (match_dup 0)
3239                     (const_int 0)))]
3240   "")
3241
3242 (define_insn "extzvdi"
3243   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3244         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3245                          (match_operand:SI 2 "const_int_operand" "i")
3246                          (match_operand:SI 3 "const_int_operand" "i")))]
3247   "TARGET_POWERPC64"
3248   "*
3249 {
3250   int start = INTVAL (operands[3]) & 63;
3251   int size = INTVAL (operands[2]) & 63;
3252
3253   if (start + size >= 64)
3254     operands[3] = const0_rtx;
3255   else
3256     operands[3] = GEN_INT (start + size);
3257   operands[2] = GEN_INT (64 - size);
3258   return \"rldicl %0,%1,%3,%2\";
3259 }")
3260
3261 (define_insn "*extzvdi_internal1"
3262   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3263         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3264                          (match_operand:SI 2 "const_int_operand" "i")
3265                          (match_operand:SI 3 "const_int_operand" "i"))
3266                     (const_int 0)))
3267    (clobber (match_scratch:DI 4 "=r"))]
3268   "TARGET_64BIT"
3269   "*
3270 {
3271   int start = INTVAL (operands[3]) & 63;
3272   int size = INTVAL (operands[2]) & 63;
3273
3274   if (start + size >= 64)
3275     operands[3] = const0_rtx;
3276   else
3277     operands[3] = GEN_INT (start + size);
3278   operands[2] = GEN_INT (64 - size);
3279   return \"rldicl. %4,%1,%3,%2\";
3280 }")
3281
3282 (define_insn "*extzvdi_internal2"
3283   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3284         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3285                          (match_operand:SI 2 "const_int_operand" "i")
3286                          (match_operand:SI 3 "const_int_operand" "i"))
3287                     (const_int 0)))
3288    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3289         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3290   "TARGET_64BIT"
3291   "*
3292 {
3293   int start = INTVAL (operands[3]) & 63;
3294   int size = INTVAL (operands[2]) & 63;
3295
3296   if (start + size >= 64)
3297     operands[3] = const0_rtx;
3298   else
3299     operands[3] = GEN_INT (start + size);
3300   operands[2] = GEN_INT (64 - size);
3301   return \"rldicl. %0,%1,%3,%2\";
3302 }")
3303
3304 (define_insn "rotlsi3"
3305   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3306         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3307                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3308   ""
3309   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffffffff")
3310
3311 (define_insn "*rotlsi3_internal2"
3312   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3313         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3314                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3315                     (const_int 0)))
3316    (clobber (match_scratch:SI 3 "=r,r"))]
3317   ""
3318   "@
3319    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffffffff
3320    #"
3321   [(set_attr "type" "delayed_compare")
3322    (set_attr "length" "4,8")])
3323
3324 (define_split
3325   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3326         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3327                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3328                     (const_int 0)))
3329    (clobber (match_scratch:SI 3 ""))]
3330   "reload_completed"
3331   [(set (match_dup 3)
3332         (rotate:SI (match_dup 1) (match_dup 2)))
3333    (set (match_dup 0)
3334         (compare:CC (match_dup 3)
3335                     (const_int 0)))]
3336   "")
3337
3338 (define_insn "*rotlsi3_internal3"
3339   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3340         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3341                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3342                     (const_int 0)))
3343    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3344         (rotate:SI (match_dup 1) (match_dup 2)))]
3345   ""
3346   "@
3347    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffffffff
3348    #"
3349   [(set_attr "type" "delayed_compare")
3350    (set_attr "length" "4,8")])
3351
3352 (define_split
3353   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3354         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3355                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3356                     (const_int 0)))
3357    (set (match_operand:SI 0 "gpc_reg_operand" "")
3358         (rotate:SI (match_dup 1) (match_dup 2)))]
3359   "reload_completed"
3360   [(set (match_dup 0)
3361         (rotate:SI (match_dup 1) (match_dup 2)))
3362    (set (match_dup 3)
3363         (compare:CC (match_dup 0)
3364                     (const_int 0)))]
3365   "")
3366
3367 (define_insn "*rotlsi3_internal4"
3368   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3369         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3370                            (match_operand:SI 2 "reg_or_cint_operand" "ri"))
3371                 (match_operand:SI 3 "mask_operand" "n")))]
3372   ""
3373   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,%m3,%M3")
3374
3375 (define_insn "*rotlsi3_internal5"
3376   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3377         (compare:CC (and:SI
3378                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3379                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3380                      (match_operand:SI 3 "mask_operand" "n,n"))
3381                     (const_int 0)))
3382    (clobber (match_scratch:SI 4 "=r,r"))]
3383   ""
3384   "@
3385    {rl%I2nm.|rlw%I2nm.} %4,%1,%h2,%m3,%M3
3386    #"
3387   [(set_attr "type" "delayed_compare")
3388    (set_attr "length" "4,8")])
3389
3390 (define_split
3391   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3392         (compare:CC (and:SI
3393                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3394                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3395                      (match_operand:SI 3 "mask_operand" ""))
3396                     (const_int 0)))
3397    (clobber (match_scratch:SI 4 ""))]
3398   "reload_completed"
3399   [(set (match_dup 4)
3400         (and:SI (rotate:SI (match_dup 1)
3401                                 (match_dup 2))
3402                      (match_dup 3)))
3403    (set (match_dup 0)
3404         (compare:CC (match_dup 4)
3405                     (const_int 0)))]
3406   "")
3407
3408 (define_insn "*rotlsi3_internal6"
3409   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3410         (compare:CC (and:SI
3411                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3412                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3413                      (match_operand:SI 3 "mask_operand" "n,n"))
3414                     (const_int 0)))
3415    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3416         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3417   ""
3418   "@
3419    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,%m3,%M3
3420    #"
3421   [(set_attr "type" "delayed_compare")
3422    (set_attr "length" "4,8")])
3423
3424 (define_split
3425   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3426         (compare:CC (and:SI
3427                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3428                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3429                      (match_operand:SI 3 "mask_operand" ""))
3430                     (const_int 0)))
3431    (set (match_operand:SI 0 "gpc_reg_operand" "")
3432         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3433   "reload_completed"
3434   [(set (match_dup 0)
3435         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3436    (set (match_dup 4)
3437         (compare:CC (match_dup 0)
3438                     (const_int 0)))]
3439   "")
3440
3441 (define_insn "*rotlsi3_internal7"
3442   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3443         (zero_extend:SI
3444          (subreg:QI
3445           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3446                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3447   ""
3448   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff")
3449
3450 (define_insn "*rotlsi3_internal8"
3451   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3452         (compare:CC (zero_extend:SI
3453                      (subreg:QI
3454                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3455                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3456                     (const_int 0)))
3457    (clobber (match_scratch:SI 3 "=r,r"))]
3458   ""
3459   "@
3460    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xff
3461    #"
3462   [(set_attr "type" "delayed_compare")
3463    (set_attr "length" "4,8")])
3464
3465 (define_split
3466   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3467         (compare:CC (zero_extend:SI
3468                      (subreg:QI
3469                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3470                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3471                     (const_int 0)))
3472    (clobber (match_scratch:SI 3 ""))]
3473   "reload_completed"
3474   [(set (match_dup 3)
3475         (zero_extend:SI (subreg:QI
3476                       (rotate:SI (match_dup 1)
3477                                  (match_dup 2)) 0)))
3478    (set (match_dup 0)
3479         (compare:CC (match_dup 3)
3480                     (const_int 0)))]
3481   "")
3482
3483 (define_insn "*rotlsi3_internal9"
3484   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3485         (compare:CC (zero_extend:SI
3486                      (subreg:QI
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    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3491         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3492   ""
3493   "@
3494    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xff
3495    #"
3496   [(set_attr "type" "delayed_compare")
3497    (set_attr "length" "4,8")])
3498
3499 (define_split
3500   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3501         (compare:CC (zero_extend:SI
3502                      (subreg:QI
3503                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3504                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3505                     (const_int 0)))
3506    (set (match_operand:SI 0 "gpc_reg_operand" "")
3507         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3508   "reload_completed"
3509   [(set (match_dup 0)
3510         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3511    (set (match_dup 3)
3512         (compare:CC (match_dup 0)
3513                     (const_int 0)))]
3514   "")
3515
3516 (define_insn "*rotlsi3_internal10"
3517   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3518         (zero_extend:SI
3519          (subreg:HI
3520           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3521                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3522   ""
3523   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffff")
3524
3525 (define_insn "*rotlsi3_internal11"
3526   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3527         (compare:CC (zero_extend:SI
3528                      (subreg:HI
3529                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3530                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3531                     (const_int 0)))
3532    (clobber (match_scratch:SI 3 "=r,r"))]
3533   ""
3534   "@
3535    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffff
3536    #"
3537   [(set_attr "type" "delayed_compare")
3538    (set_attr "length" "4,8")])
3539
3540 (define_split
3541   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3542         (compare:CC (zero_extend:SI
3543                      (subreg:HI
3544                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3545                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3546                     (const_int 0)))
3547    (clobber (match_scratch:SI 3 ""))]
3548   "reload_completed"
3549   [(set (match_dup 3)
3550         (zero_extend:SI (subreg:HI
3551                       (rotate:SI (match_dup 1)
3552                                  (match_dup 2)) 0)))
3553    (set (match_dup 0)
3554         (compare:CC (match_dup 3)
3555                     (const_int 0)))]
3556   "")
3557
3558 (define_insn "*rotlsi3_internal12"
3559   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3560         (compare:CC (zero_extend:SI
3561                      (subreg:HI
3562                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3563                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3564                     (const_int 0)))
3565    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3566         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3567   ""
3568   "@
3569    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffff
3570    #"
3571   [(set_attr "type" "delayed_compare")
3572    (set_attr "length" "4,8")])
3573
3574 (define_split
3575   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3576         (compare:CC (zero_extend:SI
3577                      (subreg:HI
3578                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3579                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3580                     (const_int 0)))
3581    (set (match_operand:SI 0 "gpc_reg_operand" "")
3582         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3583   "reload_completed"
3584   [(set (match_dup 0)
3585         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3586    (set (match_dup 3)
3587         (compare:CC (match_dup 0)
3588                     (const_int 0)))]
3589   "")
3590
3591 ;; Note that we use "sle." instead of "sl." so that we can set
3592 ;; SHIFT_COUNT_TRUNCATED.
3593
3594 (define_expand "ashlsi3"
3595   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
3596    (use (match_operand:SI 1 "gpc_reg_operand" ""))
3597    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
3598   ""
3599   "
3600 {
3601   if (TARGET_POWER)
3602     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
3603   else
3604     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
3605   DONE;
3606 }")
3607
3608 (define_insn "ashlsi3_power"
3609   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3610         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3611                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
3612    (clobber (match_scratch:SI 3 "=q,X"))]
3613   "TARGET_POWER"
3614   "@
3615    sle %0,%1,%2
3616    {sli|slwi} %0,%1,%h2")
3617
3618 (define_insn "ashlsi3_no_power"
3619   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3620         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3621                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3622   "! TARGET_POWER"
3623   "{sl|slw}%I2 %0,%1,%h2")
3624
3625 (define_insn ""
3626   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3627         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3628                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3629                     (const_int 0)))
3630    (clobber (match_scratch:SI 3 "=r,r,r,r"))
3631    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
3632   "TARGET_POWER"
3633   "@
3634    sle. %3,%1,%2
3635    {sli.|slwi.} %3,%1,%h2
3636    #
3637    #"
3638   [(set_attr "type" "delayed_compare")
3639    (set_attr "length" "4,4,8,8")])
3640
3641 (define_split
3642   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3643         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3644                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3645                     (const_int 0)))
3646    (clobber (match_scratch:SI 3 ""))
3647    (clobber (match_scratch:SI 4 ""))]
3648   "TARGET_POWER && reload_completed"
3649   [(parallel [(set (match_dup 3)
3650         (ashift:SI (match_dup 1) (match_dup 2)))
3651    (clobber (match_dup 4))])
3652    (set (match_dup 0)
3653         (compare:CC (match_dup 3)
3654                     (const_int 0)))]
3655   "")
3656
3657 (define_insn ""
3658   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3659         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3660                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3661                     (const_int 0)))
3662    (clobber (match_scratch:SI 3 "=r,r"))]
3663   "! TARGET_POWER && TARGET_32BIT"
3664   "@
3665    {sl|slw}%I2. %3,%1,%h2
3666    #"
3667   [(set_attr "type" "delayed_compare")
3668    (set_attr "length" "4,8")])
3669
3670 (define_split
3671   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3672         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3673                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3674                     (const_int 0)))
3675    (clobber (match_scratch:SI 3 ""))]
3676   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3677   [(set (match_dup 3)
3678         (ashift:SI (match_dup 1) (match_dup 2)))
3679    (set (match_dup 0)
3680         (compare:CC (match_dup 3)
3681                     (const_int 0)))]
3682   "")
3683
3684 (define_insn ""
3685   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3686         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3687                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3688                     (const_int 0)))
3689    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3690         (ashift:SI (match_dup 1) (match_dup 2)))
3691    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
3692   "TARGET_POWER"
3693   "@
3694    sle. %0,%1,%2
3695    {sli.|slwi.} %0,%1,%h2
3696    #
3697    #"
3698   [(set_attr "type" "delayed_compare")
3699    (set_attr "length" "4,4,8,8")])
3700
3701 (define_split
3702   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3703         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3704                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3705                     (const_int 0)))
3706    (set (match_operand:SI 0 "gpc_reg_operand" "")
3707         (ashift:SI (match_dup 1) (match_dup 2)))
3708    (clobber (match_scratch:SI 4 ""))]
3709   "TARGET_POWER && reload_completed"
3710   [(parallel [(set (match_dup 0)
3711         (ashift:SI (match_dup 1) (match_dup 2)))
3712    (clobber (match_dup 4))])
3713    (set (match_dup 3)
3714         (compare:CC (match_dup 0)
3715                     (const_int 0)))]
3716   "")
3717
3718 (define_insn ""
3719   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3720         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3721                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3722                     (const_int 0)))
3723    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3724         (ashift:SI (match_dup 1) (match_dup 2)))]
3725   "! TARGET_POWER && TARGET_32BIT"
3726   "@
3727    {sl|slw}%I2. %0,%1,%h2
3728    #"
3729   [(set_attr "type" "delayed_compare")
3730    (set_attr "length" "4,8")])
3731
3732 (define_split
3733   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3734         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3735                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3736                     (const_int 0)))
3737    (set (match_operand:SI 0 "gpc_reg_operand" "")
3738         (ashift:SI (match_dup 1) (match_dup 2)))]
3739   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3740   [(set (match_dup 0)
3741         (ashift:SI (match_dup 1) (match_dup 2)))
3742    (set (match_dup 3)
3743         (compare:CC (match_dup 0)
3744                     (const_int 0)))]
3745   "")
3746
3747 (define_insn ""
3748   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3749         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3750                            (match_operand:SI 2 "const_int_operand" "i"))
3751                 (match_operand:SI 3 "mask_operand" "n")))]
3752   "includes_lshift_p (operands[2], operands[3])"
3753   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
3754
3755 (define_insn ""
3756   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3757         (compare:CC
3758          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3759                             (match_operand:SI 2 "const_int_operand" "i,i"))
3760                  (match_operand:SI 3 "mask_operand" "n,n"))
3761          (const_int 0)))
3762    (clobber (match_scratch:SI 4 "=r,r"))]
3763   "includes_lshift_p (operands[2], operands[3])"
3764   "@
3765    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
3766    #"
3767   [(set_attr "type" "delayed_compare")
3768    (set_attr "length" "4,8")])
3769
3770 (define_split
3771   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3772         (compare:CC
3773          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3774                             (match_operand:SI 2 "const_int_operand" ""))
3775                  (match_operand:SI 3 "mask_operand" ""))
3776          (const_int 0)))
3777    (clobber (match_scratch:SI 4 ""))]
3778   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
3779   [(set (match_dup 4)
3780         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
3781                  (match_dup 3)))
3782    (set (match_dup 0)
3783         (compare:CC (match_dup 4)
3784                     (const_int 0)))]
3785   "")
3786
3787 (define_insn ""
3788   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3789         (compare:CC
3790          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3791                             (match_operand:SI 2 "const_int_operand" "i,i"))
3792                  (match_operand:SI 3 "mask_operand" "n,n"))
3793          (const_int 0)))
3794    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3795         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3796   "includes_lshift_p (operands[2], operands[3])"
3797   "@
3798    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
3799    #"
3800   [(set_attr "type" "delayed_compare")
3801    (set_attr "length" "4,8")])
3802
3803 (define_split
3804   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3805         (compare:CC
3806          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3807                             (match_operand:SI 2 "const_int_operand" ""))
3808                  (match_operand:SI 3 "mask_operand" ""))
3809          (const_int 0)))
3810    (set (match_operand:SI 0 "gpc_reg_operand" "")
3811         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3812   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
3813   [(set (match_dup 0)
3814         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3815    (set (match_dup 4)
3816         (compare:CC (match_dup 0)
3817                     (const_int 0)))]
3818   "")
3819
3820 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
3821 ;; "sli x,x,0".
3822 (define_expand "lshrsi3"
3823   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
3824    (use (match_operand:SI 1 "gpc_reg_operand" ""))
3825    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
3826   ""
3827   "
3828 {
3829   if (TARGET_POWER)
3830     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
3831   else
3832     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
3833   DONE;
3834 }")
3835
3836 (define_insn "lshrsi3_power"
3837   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
3838         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
3839                      (match_operand:SI 2 "reg_or_cint_operand" "r,O,i")))
3840    (clobber (match_scratch:SI 3 "=q,X,X"))]
3841   "TARGET_POWER"
3842   "@
3843   sre %0,%1,%2
3844   mr %0,%1
3845   {s%A2i|s%A2wi} %0,%1,%h2")
3846
3847 (define_insn "lshrsi3_no_power"
3848   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3849         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3850                      (match_operand:SI 2 "reg_or_cint_operand" "O,ri")))]
3851   "! TARGET_POWER"
3852   "@
3853   mr %0,%1
3854   {sr|srw}%I2 %0,%1,%h2")
3855
3856 (define_insn ""
3857   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
3858         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
3859                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
3860                     (const_int 0)))
3861    (clobber (match_scratch:SI 3 "=r,X,r,r,X,r"))
3862    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
3863   "TARGET_POWER"
3864   "@
3865   sre. %3,%1,%2
3866   mr. %1,%1
3867   {s%A2i.|s%A2wi.} %3,%1,%h2
3868   #
3869   #
3870   #"
3871   [(set_attr "type" "delayed_compare")
3872    (set_attr "length" "4,4,4,8,8,8")])
3873
3874 (define_split
3875   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3876         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3877                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3878                     (const_int 0)))
3879    (clobber (match_scratch:SI 3 ""))
3880    (clobber (match_scratch:SI 4 ""))]
3881   "TARGET_POWER && reload_completed"
3882   [(parallel [(set (match_dup 3)
3883         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3884    (clobber (match_dup 4))])
3885    (set (match_dup 0)
3886         (compare:CC (match_dup 3)
3887                     (const_int 0)))]
3888   "")
3889
3890 (define_insn ""
3891   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3892         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3893                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
3894                     (const_int 0)))
3895    (clobber (match_scratch:SI 3 "=X,r,X,r"))]
3896   "! TARGET_POWER && TARGET_32BIT"
3897   "@
3898    mr. %1,%1
3899    {sr|srw}%I2. %3,%1,%h2
3900    #
3901    #"
3902   [(set_attr "type" "delayed_compare")
3903    (set_attr "length" "4,4,8,8")])
3904
3905 (define_split
3906   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3907         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3908                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3909                     (const_int 0)))
3910    (clobber (match_scratch:SI 3 ""))]
3911   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3912   [(set (match_dup 3)
3913         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3914    (set (match_dup 0)
3915         (compare:CC (match_dup 3)
3916                     (const_int 0)))]
3917   "")
3918
3919 (define_insn ""
3920   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
3921         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
3922                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
3923                     (const_int 0)))
3924    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
3925         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3926    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
3927   "TARGET_POWER"
3928   "@
3929   sre. %0,%1,%2
3930   mr. %0,%1
3931   {s%A2i.|s%A2wi.} %0,%1,%h2
3932   #
3933   #
3934   #"
3935   [(set_attr "type" "delayed_compare")
3936    (set_attr "length" "4,4,4,8,8,8")])
3937
3938 (define_split
3939   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3940         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3941                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3942                     (const_int 0)))
3943    (set (match_operand:SI 0 "gpc_reg_operand" "")
3944         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3945    (clobber (match_scratch:SI 4 ""))]
3946   "TARGET_POWER && reload_completed"
3947   [(parallel [(set (match_dup 0)
3948         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3949    (clobber (match_dup 4))])
3950    (set (match_dup 3)
3951         (compare:CC (match_dup 0)
3952                     (const_int 0)))]
3953   "")
3954
3955 (define_insn ""
3956   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3957         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3958                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
3959                     (const_int 0)))
3960    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3961         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
3962   "! TARGET_POWER && TARGET_32BIT"
3963   "@
3964    mr. %0,%1
3965    {sr|srw}%I2. %0,%1,%h2
3966    #
3967    #"
3968   [(set_attr "type" "delayed_compare")
3969    (set_attr "length" "4,4,8,8")])
3970
3971 (define_split
3972   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3973         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3974                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3975                     (const_int 0)))
3976    (set (match_operand:SI 0 "gpc_reg_operand" "")
3977         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
3978   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3979   [(set (match_dup 0)
3980         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3981    (set (match_dup 3)
3982         (compare:CC (match_dup 0)
3983                     (const_int 0)))]
3984   "")
3985
3986 (define_insn ""
3987   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3988         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3989                              (match_operand:SI 2 "const_int_operand" "i"))
3990                 (match_operand:SI 3 "mask_operand" "n")))]
3991   "includes_rshift_p (operands[2], operands[3])"
3992   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
3993
3994 (define_insn ""
3995   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3996         (compare:CC
3997          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3998                               (match_operand:SI 2 "const_int_operand" "i,i"))
3999                  (match_operand:SI 3 "mask_operand" "n,n"))
4000          (const_int 0)))
4001    (clobber (match_scratch:SI 4 "=r,r"))]
4002   "includes_rshift_p (operands[2], operands[3])"
4003   "@
4004    {rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3
4005    #"
4006   [(set_attr "type" "delayed_compare")
4007    (set_attr "length" "4,8")])
4008
4009 (define_split
4010   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4011         (compare:CC
4012          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4013                               (match_operand:SI 2 "const_int_operand" ""))
4014                  (match_operand:SI 3 "mask_operand" ""))
4015          (const_int 0)))
4016    (clobber (match_scratch:SI 4 ""))]
4017   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4018   [(set (match_dup 4)
4019         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
4020                  (match_dup 3)))
4021    (set (match_dup 0)
4022         (compare:CC (match_dup 4)
4023                     (const_int 0)))]
4024   "")
4025
4026 (define_insn ""
4027   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4028         (compare:CC
4029          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4030                               (match_operand:SI 2 "const_int_operand" "i,i"))
4031                  (match_operand:SI 3 "mask_operand" "n,n"))
4032          (const_int 0)))
4033    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4034         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4035   "includes_rshift_p (operands[2], operands[3])"
4036   "@
4037    {rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3
4038    #"
4039   [(set_attr "type" "delayed_compare")
4040    (set_attr "length" "4,8")])
4041
4042 (define_split
4043   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4044         (compare:CC
4045          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4046                               (match_operand:SI 2 "const_int_operand" ""))
4047                  (match_operand:SI 3 "mask_operand" ""))
4048          (const_int 0)))
4049    (set (match_operand:SI 0 "gpc_reg_operand" "")
4050         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4051   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4052   [(set (match_dup 0)
4053         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4054    (set (match_dup 4)
4055         (compare:CC (match_dup 0)
4056                     (const_int 0)))]
4057   "")
4058
4059 (define_insn ""
4060   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4061         (zero_extend:SI
4062          (subreg:QI
4063           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4064                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4065   "includes_rshift_p (operands[2], GEN_INT (255))"
4066   "{rlinm|rlwinm} %0,%1,%s2,0xff")
4067
4068 (define_insn ""
4069   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4070         (compare:CC
4071          (zero_extend:SI
4072           (subreg:QI
4073            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4074                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4075          (const_int 0)))
4076    (clobber (match_scratch:SI 3 "=r,r"))]
4077   "includes_rshift_p (operands[2], GEN_INT (255))"
4078   "@
4079    {rlinm.|rlwinm.} %3,%1,%s2,0xff
4080    #"
4081   [(set_attr "type" "delayed_compare")
4082    (set_attr "length" "4,8")])
4083
4084 (define_split
4085   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4086         (compare:CC
4087          (zero_extend:SI
4088           (subreg:QI
4089            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4090                         (match_operand:SI 2 "const_int_operand" "")) 0))
4091          (const_int 0)))
4092    (clobber (match_scratch:SI 3 ""))]
4093   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4094   [(set (match_dup 3)
4095         (zero_extend:SI (subreg:QI
4096            (lshiftrt:SI (match_dup 1)
4097                         (match_dup 2)) 0)))
4098    (set (match_dup 0)
4099         (compare:CC (match_dup 3)
4100                     (const_int 0)))]
4101   "")
4102
4103 (define_insn ""
4104   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4105         (compare:CC
4106          (zero_extend:SI
4107           (subreg:QI
4108            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4109                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4110          (const_int 0)))
4111    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4112         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4113   "includes_rshift_p (operands[2], GEN_INT (255))"
4114   "@
4115    {rlinm.|rlwinm.} %0,%1,%s2,0xff
4116    #"
4117   [(set_attr "type" "delayed_compare")
4118    (set_attr "length" "4,8")])
4119
4120 (define_split
4121   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4122         (compare:CC
4123          (zero_extend:SI
4124           (subreg:QI
4125            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4126                         (match_operand:SI 2 "const_int_operand" "")) 0))
4127          (const_int 0)))
4128    (set (match_operand:SI 0 "gpc_reg_operand" "")
4129         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4130   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4131   [(set (match_dup 0)
4132         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4133    (set (match_dup 3)
4134         (compare:CC (match_dup 0)
4135                     (const_int 0)))]
4136   "")
4137
4138 (define_insn ""
4139   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4140         (zero_extend:SI
4141          (subreg:HI
4142           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4143                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4144   "includes_rshift_p (operands[2], GEN_INT (65535))"
4145   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
4146
4147 (define_insn ""
4148   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4149         (compare:CC
4150          (zero_extend:SI
4151           (subreg:HI
4152            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4153                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4154          (const_int 0)))
4155    (clobber (match_scratch:SI 3 "=r,r"))]
4156   "includes_rshift_p (operands[2], GEN_INT (65535))"
4157   "@
4158    {rlinm.|rlwinm.} %3,%1,%s2,0xffff
4159    #"
4160   [(set_attr "type" "delayed_compare")
4161    (set_attr "length" "4,8")])
4162
4163 (define_split
4164   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4165         (compare:CC
4166          (zero_extend:SI
4167           (subreg:HI
4168            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4169                         (match_operand:SI 2 "const_int_operand" "")) 0))
4170          (const_int 0)))
4171    (clobber (match_scratch:SI 3 ""))]
4172   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4173   [(set (match_dup 3)
4174         (zero_extend:SI (subreg:HI
4175            (lshiftrt:SI (match_dup 1)
4176                         (match_dup 2)) 0)))
4177    (set (match_dup 0)
4178         (compare:CC (match_dup 3)
4179                     (const_int 0)))]
4180   "")
4181
4182 (define_insn ""
4183   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4184         (compare:CC
4185          (zero_extend:SI
4186           (subreg:HI
4187            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4188                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4189          (const_int 0)))
4190    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4191         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4192   "includes_rshift_p (operands[2], GEN_INT (65535))"
4193   "@
4194    {rlinm.|rlwinm.} %0,%1,%s2,0xffff
4195    #"
4196   [(set_attr "type" "delayed_compare")
4197    (set_attr "length" "4,8")])
4198
4199 (define_split
4200   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4201         (compare:CC
4202          (zero_extend:SI
4203           (subreg:HI
4204            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4205                         (match_operand:SI 2 "const_int_operand" "")) 0))
4206          (const_int 0)))
4207    (set (match_operand:SI 0 "gpc_reg_operand" "")
4208         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4209   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4210   [(set (match_dup 0)
4211         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4212    (set (match_dup 3)
4213         (compare:CC (match_dup 0)
4214                     (const_int 0)))]
4215   "")
4216
4217 (define_insn ""
4218   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4219                          (const_int 1)
4220                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4221         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4222                      (const_int 31)))]
4223   "TARGET_POWER"
4224   "rrib %0,%1,%2")
4225
4226 (define_insn ""
4227   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4228                          (const_int 1)
4229                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4230         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4231                      (const_int 31)))]
4232   "TARGET_POWER"
4233   "rrib %0,%1,%2")
4234
4235 (define_insn ""
4236   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4237                          (const_int 1)
4238                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4239         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4240                          (const_int 1)
4241                          (const_int 0)))]
4242   "TARGET_POWER"
4243   "rrib %0,%1,%2")
4244
4245 (define_expand "ashrsi3"
4246   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4247         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4248                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
4249   ""
4250   "
4251 {
4252   if (TARGET_POWER)
4253     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
4254   else
4255     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
4256   DONE;
4257 }")
4258
4259 (define_insn "ashrsi3_power"
4260   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4261         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4262                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4263    (clobber (match_scratch:SI 3 "=q,X"))]
4264   "TARGET_POWER"
4265   "@
4266    srea %0,%1,%2
4267    {srai|srawi} %0,%1,%h2")
4268
4269 (define_insn "ashrsi3_no_power"
4270   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4271         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4272                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4273   "! TARGET_POWER"
4274   "{sra|sraw}%I2 %0,%1,%h2")
4275
4276 (define_insn ""
4277   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4278         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4279                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4280                     (const_int 0)))
4281    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4282    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4283   "TARGET_POWER"
4284   "@
4285    srea. %3,%1,%2
4286    {srai.|srawi.} %3,%1,%h2
4287    #
4288    #"
4289   [(set_attr "type" "delayed_compare")
4290    (set_attr "length" "4,4,8,8")])
4291
4292 (define_split
4293   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4294         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4295                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4296                     (const_int 0)))
4297    (clobber (match_scratch:SI 3 ""))
4298    (clobber (match_scratch:SI 4 ""))]
4299   "TARGET_POWER && reload_completed"
4300   [(parallel [(set (match_dup 3)
4301         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4302    (clobber (match_dup 4))])
4303    (set (match_dup 0)
4304         (compare:CC (match_dup 3)
4305                     (const_int 0)))]
4306   "")
4307
4308 (define_insn ""
4309   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4310         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4311                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4312                     (const_int 0)))
4313    (clobber (match_scratch:SI 3 "=r,r"))]
4314   "! TARGET_POWER"
4315   "@
4316    {sra|sraw}%I2. %3,%1,%h2
4317    #"
4318   [(set_attr "type" "delayed_compare")
4319    (set_attr "length" "4,8")])
4320
4321 (define_split
4322   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4323         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4324                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4325                     (const_int 0)))
4326    (clobber (match_scratch:SI 3 ""))]
4327   "! TARGET_POWER && reload_completed"
4328   [(set (match_dup 3)
4329         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4330    (set (match_dup 0)
4331         (compare:CC (match_dup 3)
4332                     (const_int 0)))]
4333   "")
4334
4335 (define_insn ""
4336   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4337         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4338                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4339                     (const_int 0)))
4340    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4341         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4342    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4343   "TARGET_POWER"
4344   "@
4345    srea. %0,%1,%2
4346    {srai.|srawi.} %0,%1,%h2
4347    #
4348    #"
4349   [(set_attr "type" "delayed_compare")
4350    (set_attr "length" "4,4,8,8")])
4351
4352 (define_split
4353   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4354         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4355                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4356                     (const_int 0)))
4357    (set (match_operand:SI 0 "gpc_reg_operand" "")
4358         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4359    (clobber (match_scratch:SI 4 ""))]
4360   "TARGET_POWER && reload_completed"
4361   [(parallel [(set (match_dup 0)
4362         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4363    (clobber (match_dup 4))])
4364    (set (match_dup 3)
4365         (compare:CC (match_dup 0)
4366                     (const_int 0)))]
4367   "")
4368
4369 (define_insn ""
4370   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4371         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4372                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4373                     (const_int 0)))
4374    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4375         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4376   "! TARGET_POWER"
4377   "@
4378    {sra|sraw}%I2. %0,%1,%h2
4379    #"
4380   [(set_attr "type" "delayed_compare")
4381    (set_attr "length" "4,8")])
4382 \f
4383 (define_split
4384   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4385         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4386                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4387                     (const_int 0)))
4388    (set (match_operand:SI 0 "gpc_reg_operand" "")
4389         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4390   "! TARGET_POWER && reload_completed"
4391   [(set (match_dup 0)
4392         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4393    (set (match_dup 3)
4394         (compare:CC (match_dup 0)
4395                     (const_int 0)))]
4396   "")
4397
4398 ;; Floating-point insns, excluding normal data motion.
4399 ;;
4400 ;; PowerPC has a full set of single-precision floating point instructions.
4401 ;;
4402 ;; For the POWER architecture, we pretend that we have both SFmode and
4403 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
4404 ;; The only conversions we will do will be when storing to memory.  In that
4405 ;; case, we will use the "frsp" instruction before storing.
4406 ;;
4407 ;; Note that when we store into a single-precision memory location, we need to
4408 ;; use the frsp insn first.  If the register being stored isn't dead, we
4409 ;; need a scratch register for the frsp.  But this is difficult when the store
4410 ;; is done by reload.  It is not incorrect to do the frsp on the register in
4411 ;; this case, we just lose precision that we would have otherwise gotten but
4412 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
4413
4414 (define_insn "extendsfdf2"
4415   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4416         (float_extend:DF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4417   "TARGET_HARD_FLOAT && TARGET_FPRS"
4418   "*
4419 {
4420   if (REGNO (operands[0]) == REGNO (operands[1]))
4421     return \"\";
4422   else
4423     return \"fmr %0,%1\";
4424 }"
4425   [(set_attr "type" "fp")])
4426
4427 (define_insn "truncdfsf2"
4428   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4429         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4430   "TARGET_HARD_FLOAT && TARGET_FPRS"
4431   "frsp %0,%1"
4432   [(set_attr "type" "fp")])
4433
4434 (define_insn "aux_truncdfsf2"
4435   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4436         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRSP))]
4437   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4438   "frsp %0,%1"
4439   [(set_attr "type" "fp")])
4440
4441 (define_expand "negsf2"
4442   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4443         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4444   "TARGET_HARD_FLOAT"
4445   "")
4446
4447 (define_insn "*negsf2"
4448   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4449         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4450   "TARGET_HARD_FLOAT && TARGET_FPRS"
4451   "fneg %0,%1"
4452   [(set_attr "type" "fp")])
4453
4454 (define_expand "abssf2"
4455   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4456         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4457   "TARGET_HARD_FLOAT"
4458   "")
4459
4460 (define_insn "*abssf2"
4461   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4462         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4463   "TARGET_HARD_FLOAT && TARGET_FPRS"
4464   "fabs %0,%1"
4465   [(set_attr "type" "fp")])
4466
4467 (define_insn ""
4468   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4469         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
4470   "TARGET_HARD_FLOAT && TARGET_FPRS"
4471   "fnabs %0,%1"
4472   [(set_attr "type" "fp")])
4473
4474 (define_expand "addsf3"
4475   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4476         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4477                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4478   "TARGET_HARD_FLOAT"
4479   "")
4480
4481 (define_insn ""
4482   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4483         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4484                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4485   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4486   "fadds %0,%1,%2"
4487   [(set_attr "type" "fp")])
4488
4489 (define_insn ""
4490   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4491         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4492                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4493   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4494   "{fa|fadd} %0,%1,%2"
4495   [(set_attr "type" "fp")])
4496
4497 (define_expand "subsf3"
4498   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4499         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4500                   (match_operand:SF 2 "gpc_reg_operand" "")))]
4501   "TARGET_HARD_FLOAT"
4502   "")
4503
4504 (define_insn ""
4505   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4506         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4507                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
4508   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4509   "fsubs %0,%1,%2"
4510   [(set_attr "type" "fp")])
4511
4512 (define_insn ""
4513   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4514         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4515                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
4516   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4517   "{fs|fsub} %0,%1,%2"
4518   [(set_attr "type" "fp")])
4519
4520 (define_expand "mulsf3"
4521   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4522         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
4523                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4524   "TARGET_HARD_FLOAT"
4525   "")
4526
4527 (define_insn ""
4528   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4529         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4530                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4531   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4532   "fmuls %0,%1,%2"
4533   [(set_attr "type" "fp")])
4534
4535 (define_insn ""
4536   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4537         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4538                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4539   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4540   "{fm|fmul} %0,%1,%2"
4541   [(set_attr "type" "dmul")])
4542
4543 (define_expand "divsf3"
4544   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4545         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
4546                 (match_operand:SF 2 "gpc_reg_operand" "")))]
4547   "TARGET_HARD_FLOAT"
4548   "")
4549
4550 (define_insn ""
4551   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4552         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4553                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
4554   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4555   "fdivs %0,%1,%2"
4556   [(set_attr "type" "sdiv")])
4557
4558 (define_insn ""
4559   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4560         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4561                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
4562   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4563   "{fd|fdiv} %0,%1,%2"
4564   [(set_attr "type" "ddiv")])
4565
4566 (define_insn ""
4567   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4568         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4569                           (match_operand:SF 2 "gpc_reg_operand" "f"))
4570                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
4571   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4572   "fmadds %0,%1,%2,%3"
4573   [(set_attr "type" "fp")])
4574
4575 (define_insn ""
4576   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4577         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4578                           (match_operand:SF 2 "gpc_reg_operand" "f"))
4579                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
4580   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4581   "{fma|fmadd} %0,%1,%2,%3"
4582   [(set_attr "type" "dmul")])
4583
4584 (define_insn ""
4585   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4586         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4587                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4588                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
4589   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4590   "fmsubs %0,%1,%2,%3"
4591   [(set_attr "type" "fp")])
4592
4593 (define_insn ""
4594   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4595         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4596                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4597                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
4598   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4599   "{fms|fmsub} %0,%1,%2,%3"
4600   [(set_attr "type" "dmul")])
4601
4602 (define_insn ""
4603   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4604         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4605                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
4606                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4607   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4608    && HONOR_SIGNED_ZEROS (SFmode)"
4609   "fnmadds %0,%1,%2,%3"
4610   [(set_attr "type" "fp")])
4611
4612 (define_insn ""
4613   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4614         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
4615                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4616                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4617   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4618    && ! HONOR_SIGNED_ZEROS (SFmode)"
4619   "fnmadds %0,%1,%2,%3"
4620   [(set_attr "type" "fp")])
4621
4622 (define_insn ""
4623   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4624         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4625                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
4626                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4627   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4628   "{fnma|fnmadd} %0,%1,%2,%3"
4629   [(set_attr "type" "dmul")])
4630
4631 (define_insn ""
4632   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4633         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
4634                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4635                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4636   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4637    && ! HONOR_SIGNED_ZEROS (SFmode)"
4638   "{fnma|fnmadd} %0,%1,%2,%3"
4639   [(set_attr "type" "dmul")])
4640
4641 (define_insn ""
4642   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4643         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4644                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
4645                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4646   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4647    && HONOR_SIGNED_ZEROS (SFmode)"
4648   "fnmsubs %0,%1,%2,%3"
4649   [(set_attr "type" "fp")])
4650
4651 (define_insn ""
4652   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4653         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
4654                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4655                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
4656   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4657    && ! HONOR_SIGNED_ZEROS (SFmode)"
4658   "fnmsubs %0,%1,%2,%3"
4659   [(set_attr "type" "fp")])
4660
4661 (define_insn ""
4662   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4663         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4664                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
4665                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4666   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4667   "{fnms|fnmsub} %0,%1,%2,%3"
4668   [(set_attr "type" "dmul")])
4669
4670 (define_insn ""
4671   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4672         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
4673                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4674                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
4675   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4676    && ! HONOR_SIGNED_ZEROS (SFmode)"
4677   "{fnms|fnmsub} %0,%1,%2,%3"
4678   [(set_attr "type" "fp")])
4679
4680 (define_expand "sqrtsf2"
4681   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4682         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4683   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
4684   "")
4685
4686 (define_insn ""
4687   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4688         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4689   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4690   "fsqrts %0,%1"
4691   [(set_attr "type" "ssqrt")])
4692
4693 (define_insn ""
4694   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4695         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4696   "TARGET_POWER2 && TARGET_HARD_FLOAT && TARGET_FPRS"
4697   "fsqrt %0,%1"
4698   [(set_attr "type" "dsqrt")])
4699
4700 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
4701 ;; fsel instruction and some auxiliary computations.  Then we just have a
4702 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
4703 ;; combine.
4704 (define_expand "maxsf3"
4705   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4706         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
4707                              (match_operand:SF 2 "gpc_reg_operand" ""))
4708                          (match_dup 1)
4709                          (match_dup 2)))]
4710   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4711   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
4712
4713 (define_expand "minsf3"
4714   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4715         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
4716                              (match_operand:SF 2 "gpc_reg_operand" ""))
4717                          (match_dup 2)
4718                          (match_dup 1)))]
4719   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4720   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
4721
4722 (define_split
4723   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4724         (match_operator:SF 3 "min_max_operator"
4725          [(match_operand:SF 1 "gpc_reg_operand" "")
4726           (match_operand:SF 2 "gpc_reg_operand" "")]))]
4727   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4728   [(const_int 0)]
4729   "
4730 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
4731                       operands[1], operands[2]);
4732   DONE;
4733 }")
4734
4735 (define_expand "movsicc"
4736    [(set (match_operand:SI 0 "gpc_reg_operand" "")
4737          (if_then_else:SI (match_operand 1 "comparison_operator" "")
4738                           (match_operand:SI 2 "gpc_reg_operand" "")
4739                           (match_operand:SI 3 "gpc_reg_operand" "")))]
4740   "TARGET_ISEL"
4741   "
4742 {
4743   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4744     DONE;
4745   else
4746     FAIL;
4747 }")
4748
4749 ;; We use the BASE_REGS for the isel input operands because, if rA is
4750 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
4751 ;; because we may switch the operands and rB may end up being rA.
4752 ;;
4753 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
4754 ;; leave out the mode in operand 4 and use one pattern, but reload can
4755 ;; change the mode underneath our feet and then gets confused trying
4756 ;; to reload the value.
4757 (define_insn "isel_signed"
4758   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4759         (if_then_else:SI
4760          (match_operator 1 "comparison_operator"
4761                          [(match_operand:CC 4 "cc_reg_operand" "y")
4762                           (const_int 0)])
4763          (match_operand:SI 2 "gpc_reg_operand" "b")
4764          (match_operand:SI 3 "gpc_reg_operand" "b")))]
4765   "TARGET_ISEL"
4766   "*
4767 { return output_isel (operands); }"
4768   [(set_attr "length" "4")])
4769
4770 (define_insn "isel_unsigned"
4771   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4772         (if_then_else:SI
4773          (match_operator 1 "comparison_operator"
4774                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
4775                           (const_int 0)])
4776          (match_operand:SI 2 "gpc_reg_operand" "b")
4777          (match_operand:SI 3 "gpc_reg_operand" "b")))]
4778   "TARGET_ISEL"
4779   "*
4780 { return output_isel (operands); }"
4781   [(set_attr "length" "4")])
4782
4783 (define_expand "movsfcc"
4784    [(set (match_operand:SF 0 "gpc_reg_operand" "")
4785          (if_then_else:SF (match_operand 1 "comparison_operator" "")
4786                           (match_operand:SF 2 "gpc_reg_operand" "")
4787                           (match_operand:SF 3 "gpc_reg_operand" "")))]
4788   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4789   "
4790 {
4791   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4792     DONE;
4793   else
4794     FAIL;
4795 }")
4796
4797 (define_insn "*fselsfsf4"
4798   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4799         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
4800                              (match_operand:SF 4 "zero_fp_constant" "F"))
4801                          (match_operand:SF 2 "gpc_reg_operand" "f")
4802                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4803   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4804   "fsel %0,%1,%2,%3"
4805   [(set_attr "type" "fp")])
4806
4807 (define_insn "*fseldfsf4"
4808   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4809         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
4810                              (match_operand:DF 4 "zero_fp_constant" "F"))
4811                          (match_operand:SF 2 "gpc_reg_operand" "f")
4812                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4813   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4814   "fsel %0,%1,%2,%3"
4815   [(set_attr "type" "fp")])
4816
4817 (define_insn "negdf2"
4818   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4819         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4820   "TARGET_HARD_FLOAT && TARGET_FPRS"
4821   "fneg %0,%1"
4822   [(set_attr "type" "fp")])
4823
4824 (define_insn "absdf2"
4825   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4826         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4827   "TARGET_HARD_FLOAT && TARGET_FPRS"
4828   "fabs %0,%1"
4829   [(set_attr "type" "fp")])
4830
4831 (define_insn ""
4832   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4833         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f"))))]
4834   "TARGET_HARD_FLOAT && TARGET_FPRS"
4835   "fnabs %0,%1"
4836   [(set_attr "type" "fp")])
4837
4838 (define_insn "adddf3"
4839   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4840         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4841                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
4842   "TARGET_HARD_FLOAT && TARGET_FPRS"
4843   "{fa|fadd} %0,%1,%2"
4844   [(set_attr "type" "fp")])
4845
4846 (define_insn "subdf3"
4847   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4848         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "f")
4849                   (match_operand:DF 2 "gpc_reg_operand" "f")))]
4850   "TARGET_HARD_FLOAT && TARGET_FPRS"
4851   "{fs|fsub} %0,%1,%2"
4852   [(set_attr "type" "fp")])
4853
4854 (define_insn "muldf3"
4855   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4856         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4857                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
4858   "TARGET_HARD_FLOAT && TARGET_FPRS"
4859   "{fm|fmul} %0,%1,%2"
4860   [(set_attr "type" "dmul")])
4861
4862 (define_insn "divdf3"
4863   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4864         (div:DF (match_operand:DF 1 "gpc_reg_operand" "f")
4865                 (match_operand:DF 2 "gpc_reg_operand" "f")))]
4866   "TARGET_HARD_FLOAT && TARGET_FPRS"
4867   "{fd|fdiv} %0,%1,%2"
4868   [(set_attr "type" "ddiv")])
4869
4870 (define_insn ""
4871   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4872         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4873                           (match_operand:DF 2 "gpc_reg_operand" "f"))
4874                  (match_operand:DF 3 "gpc_reg_operand" "f")))]
4875   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4876   "{fma|fmadd} %0,%1,%2,%3"
4877   [(set_attr "type" "dmul")])
4878
4879 (define_insn ""
4880   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4881         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4882                            (match_operand:DF 2 "gpc_reg_operand" "f"))
4883                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
4884   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4885   "{fms|fmsub} %0,%1,%2,%3"
4886   [(set_attr "type" "dmul")])
4887
4888 (define_insn ""
4889   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4890         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4891                                   (match_operand:DF 2 "gpc_reg_operand" "f"))
4892                          (match_operand:DF 3 "gpc_reg_operand" "f"))))]
4893   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4894    && HONOR_SIGNED_ZEROS (DFmode)"
4895   "{fnma|fnmadd} %0,%1,%2,%3"
4896   [(set_attr "type" "dmul")])
4897
4898 (define_insn ""
4899   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4900         (minus:DF (mult:DF (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f"))
4901                            (match_operand:DF 2 "gpc_reg_operand" "f"))
4902                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
4903   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4904    && ! HONOR_SIGNED_ZEROS (DFmode)"
4905   "{fnma|fnmadd} %0,%1,%2,%3"
4906   [(set_attr "type" "dmul")])
4907
4908 (define_insn ""
4909   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4910         (neg:DF (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4911                                    (match_operand:DF 2 "gpc_reg_operand" "f"))
4912                           (match_operand:DF 3 "gpc_reg_operand" "f"))))]
4913   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4914    && HONOR_SIGNED_ZEROS (DFmode)"
4915   "{fnms|fnmsub} %0,%1,%2,%3"
4916   [(set_attr "type" "dmul")])
4917
4918 (define_insn ""
4919   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4920         (minus:DF (match_operand:DF 3 "gpc_reg_operand" "f")
4921                   (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4922                            (match_operand:DF 2 "gpc_reg_operand" "f"))))]
4923   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4924    && ! HONOR_SIGNED_ZEROS (DFmode)"
4925   "{fnms|fnmsub} %0,%1,%2,%3"
4926   [(set_attr "type" "dmul")])
4927
4928 (define_insn "sqrtdf2"
4929   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4930         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4931   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
4932   "fsqrt %0,%1"
4933   [(set_attr "type" "dsqrt")])
4934
4935 ;; The conditional move instructions allow us to perform max and min
4936 ;; operations even when
4937
4938 (define_expand "maxdf3"
4939   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4940         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
4941                              (match_operand:DF 2 "gpc_reg_operand" ""))
4942                          (match_dup 1)
4943                          (match_dup 2)))]
4944   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4945   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
4946
4947 (define_expand "mindf3"
4948   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4949         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
4950                              (match_operand:DF 2 "gpc_reg_operand" ""))
4951                          (match_dup 2)
4952                          (match_dup 1)))]
4953   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4954   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
4955
4956 (define_split
4957   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4958         (match_operator:DF 3 "min_max_operator"
4959          [(match_operand:DF 1 "gpc_reg_operand" "")
4960           (match_operand:DF 2 "gpc_reg_operand" "")]))]
4961   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4962   [(const_int 0)]
4963   "
4964 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
4965                       operands[1], operands[2]);
4966   DONE;
4967 }")
4968
4969 (define_expand "movdfcc"
4970    [(set (match_operand:DF 0 "gpc_reg_operand" "")
4971          (if_then_else:DF (match_operand 1 "comparison_operator" "")
4972                           (match_operand:DF 2 "gpc_reg_operand" "")
4973                           (match_operand:DF 3 "gpc_reg_operand" "")))]
4974   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4975   "
4976 {
4977   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4978     DONE;
4979   else
4980     FAIL;
4981 }")
4982
4983 (define_insn "*fseldfdf4"
4984   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4985         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
4986                              (match_operand:DF 4 "zero_fp_constant" "F"))
4987                          (match_operand:DF 2 "gpc_reg_operand" "f")
4988                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
4989   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4990   "fsel %0,%1,%2,%3"
4991   [(set_attr "type" "fp")])
4992
4993 (define_insn "*fselsfdf4"
4994   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4995         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
4996                              (match_operand:SF 4 "zero_fp_constant" "F"))
4997                          (match_operand:DF 2 "gpc_reg_operand" "f")
4998                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
4999   "TARGET_PPC_GFXOPT"
5000   "fsel %0,%1,%2,%3"
5001   [(set_attr "type" "fp")])
5002 \f
5003 ;; Conversions to and from floating-point.
5004
5005 (define_expand "fixuns_truncsfsi2"
5006   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5007         (unsigned_fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
5008   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5009   "")
5010
5011 (define_expand "fix_truncsfsi2"
5012   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5013         (fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
5014   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5015   "")
5016
5017 ; For each of these conversions, there is a define_expand, a define_insn
5018 ; with a '#' template, and a define_split (with C code).  The idea is
5019 ; to allow constant folding with the template of the define_insn,
5020 ; then to have the insns split later (between sched1 and final).
5021
5022 (define_expand "floatsidf2"
5023   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5024                    (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5025               (use (match_dup 2))
5026               (use (match_dup 3))
5027               (clobber (match_dup 4))
5028               (clobber (match_dup 5))
5029               (clobber (match_dup 6))])]
5030   "TARGET_HARD_FLOAT && TARGET_FPRS"
5031   "
5032 {
5033   if (TARGET_POWERPC64)
5034     {
5035       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5036       rtx t1 = gen_reg_rtx (DImode);
5037       rtx t2 = gen_reg_rtx (DImode);
5038       emit_insn (gen_floatsidf_ppc64 (operands[0], operands[1], mem, t1, t2));
5039       DONE;
5040     }
5041
5042   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5043   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
5044   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5045   operands[5] = gen_reg_rtx (DFmode);
5046   operands[6] = gen_reg_rtx (SImode);
5047 }")
5048
5049 (define_insn "*floatsidf2_internal"
5050   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5051         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5052    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5053    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5054    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5055    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))
5056    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
5057   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5058   "#"
5059   [(set_attr "length" "24")])
5060
5061 (define_split
5062   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5063         (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5064    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5065    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5066    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5067    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))
5068    (clobber (match_operand:SI 6 "gpc_reg_operand" ""))]
5069   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5070   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5071         (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5072    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5073    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5074    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5075    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))
5076    (clobber (match_operand:SI 6 "gpc_reg_operand" ""))]
5077   "
5078 {
5079   rtx lowword, highword;
5080   if (GET_CODE (operands[4]) != MEM)
5081     abort();
5082   highword = XEXP (operands[4], 0);
5083   lowword = plus_constant (highword, 4);
5084   if (! WORDS_BIG_ENDIAN)
5085     {
5086       rtx tmp;
5087       tmp = highword; highword = lowword; lowword = tmp;
5088     }
5089
5090   emit_insn (gen_xorsi3 (operands[6], operands[1],
5091                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
5092   emit_move_insn (gen_rtx_MEM (SImode, lowword), operands[6]);
5093   emit_move_insn (gen_rtx_MEM (SImode, highword), operands[2]);
5094   emit_move_insn (operands[5], operands[4]);
5095   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5096   DONE;
5097 }")
5098
5099 (define_expand "floatunssisf2"
5100   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5101         (unsigned_float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5102   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5103   "")
5104
5105 (define_expand "floatunssidf2"
5106   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5107                    (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5108               (use (match_dup 2))
5109               (use (match_dup 3))
5110               (clobber (match_dup 4))
5111               (clobber (match_dup 5))])]
5112   "TARGET_HARD_FLOAT && TARGET_FPRS"
5113   "
5114 {
5115   if (TARGET_POWERPC64)
5116     {
5117       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5118       rtx t1 = gen_reg_rtx (DImode);
5119       rtx t2 = gen_reg_rtx (DImode);
5120       emit_insn (gen_floatunssidf_ppc64 (operands[0], operands[1], mem,
5121                                          t1, t2));
5122       DONE;
5123     }
5124
5125   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5126   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
5127   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5128   operands[5] = gen_reg_rtx (DFmode);
5129 }")
5130
5131 (define_insn "*floatunssidf2_internal"
5132   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5133         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5134    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5135    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5136    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5137    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))]
5138   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5139   "#"
5140   [(set_attr "length" "20")])
5141
5142 (define_split
5143   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5144         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5145    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5146    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5147    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5148    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))]
5149   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5150   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5151         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5152    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5153    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5154    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5155    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))]
5156   "
5157 {
5158   rtx lowword, highword;
5159   if (GET_CODE (operands[4]) != MEM)
5160     abort();
5161   highword = XEXP (operands[4], 0);
5162   lowword = plus_constant (highword, 4);
5163   if (! WORDS_BIG_ENDIAN)
5164     {
5165       rtx tmp;
5166       tmp = highword; highword = lowword; lowword = tmp;
5167     }
5168
5169   emit_move_insn (gen_rtx_MEM (SImode, lowword), operands[1]);
5170   emit_move_insn (gen_rtx_MEM (SImode, highword), operands[2]);
5171   emit_move_insn (operands[5], operands[4]);
5172   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5173   DONE;
5174 }")
5175
5176 (define_expand "fix_truncdfsi2"
5177   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
5178                    (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5179               (clobber (match_dup 2))
5180               (clobber (match_dup 3))])]
5181   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5182   "
5183 {
5184   operands[2] = gen_reg_rtx (DImode);
5185   operands[3] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5186 }")
5187
5188 (define_insn "*fix_truncdfsi2_internal"
5189   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5190         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5191    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))
5192    (clobber (match_operand:DI 3 "memory_operand" "=o"))]
5193   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5194   "#"
5195   [(set_attr "length" "16")])
5196
5197 (define_split
5198   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5199         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5200    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
5201    (clobber (match_operand:DI 3 "offsettable_mem_operand" ""))]
5202   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5203   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5204         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5205    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
5206    (clobber (match_operand:DI 3 "offsettable_mem_operand" ""))]
5207   "
5208 {
5209   rtx lowword;
5210   if (GET_CODE (operands[3]) != MEM)
5211     abort();
5212   lowword = XEXP (operands[3], 0);
5213   if (WORDS_BIG_ENDIAN)
5214     lowword = plus_constant (lowword, 4);
5215
5216   emit_insn (gen_fctiwz (operands[2], operands[1]));
5217   emit_move_insn (operands[3], operands[2]);
5218   emit_move_insn (operands[0], gen_rtx_MEM (SImode, lowword));
5219   DONE;
5220 }")
5221
5222 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
5223 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
5224 ; because the first makes it clear that operand 0 is not live
5225 ; before the instruction.
5226 (define_insn "fctiwz"
5227   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
5228         (unspec:DI [(fix:SI (match_operand:DF 1 "gpc_reg_operand" "f"))]
5229                    UNSPEC_FCTIWZ))]
5230   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5231   "{fcirz|fctiwz} %0,%1"
5232   [(set_attr "type" "fp")])
5233
5234 (define_expand "floatsisf2"
5235   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5236         (float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5237   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5238   "")
5239
5240 (define_insn "floatdidf2"
5241   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5242         (float:DF (match_operand:DI 1 "gpc_reg_operand" "*f")))]
5243   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5244   "fcfid %0,%1"
5245   [(set_attr "type" "fp")])
5246
5247 (define_insn_and_split "floatsidf_ppc64"
5248   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5249         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5250    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5251    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5252    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5253   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5254   "#"
5255   "&& 1"
5256   [(set (match_dup 3) (sign_extend:DI (match_dup 1)))
5257    (set (match_dup 2) (match_dup 3))
5258    (set (match_dup 4) (match_dup 2))
5259    (set (match_dup 0) (float:DF (match_dup 4)))]
5260   "")
5261
5262 (define_insn_and_split "floatunssidf_ppc64"
5263   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5264         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5265    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5266    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5267    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5268   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5269   "#"
5270   "&& 1"
5271   [(set (match_dup 3) (zero_extend:DI (match_dup 1)))
5272    (set (match_dup 2) (match_dup 3))
5273    (set (match_dup 4) (match_dup 2))
5274    (set (match_dup 0) (float:DF (match_dup 4)))]
5275   "")
5276
5277 (define_insn "fix_truncdfdi2"
5278   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
5279         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "f")))]
5280   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5281   "fctidz %0,%1"
5282   [(set_attr "type" "fp")])
5283
5284 (define_expand "floatdisf2"
5285   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5286         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
5287   "TARGET_64BIT && TARGET_HARD_FLOAT && TARGET_FPRS"
5288   "
5289 {
5290   if (!flag_unsafe_math_optimizations)
5291     {
5292       rtx label = gen_label_rtx ();
5293       emit_insn (gen_floatdisf2_internal2 (operands[1], label));
5294       emit_label (label);
5295     }
5296   emit_insn (gen_floatdisf2_internal1 (operands[0], operands[1]));
5297   DONE;
5298 }")
5299
5300 ;; This is not IEEE compliant if rounding mode is "round to nearest".
5301 ;; If the DI->DF conversion is inexact, then it's possible to suffer
5302 ;; from double rounding.
5303 (define_insn_and_split "floatdisf2_internal1"
5304   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5305         (float:SF (match_operand:DI 1 "gpc_reg_operand" "*f")))
5306    (clobber (match_scratch:DF 2 "=f"))]
5307   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5308   "#"
5309   "&& reload_completed"
5310   [(set (match_dup 2)
5311         (float:DF (match_dup 1)))
5312    (set (match_dup 0)
5313         (float_truncate:SF (match_dup 2)))]
5314   "")
5315
5316 ;; Twiddles bits to avoid double rounding.
5317 ;; Bits that might be truncated when converting to DFmode are replaced
5318 ;; by a bit that won't be lost at that stage, but is below the SFmode
5319 ;; rounding position.
5320 (define_expand "floatdisf2_internal2"
5321   [(parallel [(set (match_dup 4)
5322                    (compare:CC (and:DI (match_operand:DI 0 "" "")
5323                                        (const_int 2047))
5324                                (const_int 0)))
5325               (set (match_dup 2) (and:DI (match_dup 0) (const_int 2047)))
5326               (clobber (match_scratch:CC 7 ""))])
5327    (set (match_dup 3) (ashiftrt:DI (match_dup 0) (const_int 53)))
5328    (set (match_dup 3) (plus:DI (match_dup 3) (const_int 1)))
5329    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
5330                            (label_ref (match_operand:DI 1 "" ""))
5331                            (pc)))
5332    (set (match_dup 5) (compare:CCUNS (match_dup 3) (const_int 2)))
5333    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
5334                            (label_ref (match_dup 1))
5335                            (pc)))
5336    (set (match_dup 0) (xor:DI (match_dup 0) (match_dup 2)))
5337    (set (match_dup 0) (ior:DI (match_dup 0) (const_int 2048)))]
5338   "TARGET_64BIT && TARGET_HARD_FLOAT && TARGET_FPRS"
5339   "
5340 {
5341   operands[2] = gen_reg_rtx (DImode);
5342   operands[3] = gen_reg_rtx (DImode);
5343   operands[4] = gen_reg_rtx (CCmode);
5344   operands[5] = gen_reg_rtx (CCUNSmode);
5345 }")
5346 \f
5347 ;; Define the DImode operations that can be done in a small number
5348 ;; of instructions.  The & constraints are to prevent the register
5349 ;; allocator from allocating registers that overlap with the inputs
5350 ;; (for example, having an input in 7,8 and an output in 6,7).  We
5351 ;; also allow for the output being the same as one of the inputs.
5352
5353 (define_insn "*adddi3_noppc64"
5354   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
5355         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
5356                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
5357   "! TARGET_POWERPC64"
5358   "*
5359 {
5360   if (WORDS_BIG_ENDIAN)
5361     return (GET_CODE (operands[2])) != CONST_INT
5362             ? \"{a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2\"
5363             : \"{ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1\";
5364   else
5365     return (GET_CODE (operands[2])) != CONST_INT
5366             ? \"{a|addc} %0,%1,%2\;{ae|adde} %L0,%L1,%L2\"
5367             : \"{ai|addic} %0,%1,%2\;{a%G2e|add%G2e} %L0,%L1\";
5368 }"
5369   [(set_attr "length" "8")])
5370
5371 (define_insn "*subdi3_noppc64"
5372   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
5373         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
5374                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
5375   "! TARGET_POWERPC64"
5376   "*
5377 {
5378   if (WORDS_BIG_ENDIAN)
5379     return (GET_CODE (operands[1]) != CONST_INT)
5380             ? \"{sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1\"
5381             : \"{sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2\";
5382   else
5383     return (GET_CODE (operands[1]) != CONST_INT)
5384             ? \"{sf|subfc} %0,%2,%1\;{sfe|subfe} %L0,%L2,%L1\"
5385             : \"{sfi|subfic} %0,%2,%1\;{sf%G1e|subf%G1e} %L0,%L2\";
5386 }"
5387   [(set_attr "length" "8")])
5388
5389 (define_insn "*negdi2_noppc64"
5390   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5391         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
5392   "! TARGET_POWERPC64"
5393   "*
5394 {
5395   return (WORDS_BIG_ENDIAN)
5396     ? \"{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1\"
5397     : \"{sfi|subfic} %0,%1,0\;{sfze|subfze} %L0,%L1\";
5398 }"
5399   [(set_attr "length" "8")])
5400
5401 (define_expand "mulsidi3"
5402   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5403         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5404                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5405   "! TARGET_POWERPC64"
5406   "
5407 {
5408   if (! TARGET_POWER && ! TARGET_POWERPC)
5409     {
5410       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
5411       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
5412       emit_insn (gen_mull_call ());
5413       if (WORDS_BIG_ENDIAN)
5414         emit_move_insn (operands[0], gen_rtx_REG (DImode, 3));
5415       else
5416         {
5417           emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
5418                           gen_rtx_REG (SImode, 3));
5419           emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
5420                           gen_rtx_REG (SImode, 4));
5421         }
5422       DONE;
5423     }
5424   else if (TARGET_POWER)
5425     {
5426       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
5427       DONE;
5428     }
5429 }")
5430
5431 (define_insn "mulsidi3_mq"
5432   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5433         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5434                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
5435    (clobber (match_scratch:SI 3 "=q"))]
5436   "TARGET_POWER"
5437   "mul %0,%1,%2\;mfmq %L0"
5438   [(set_attr "type" "imul")
5439    (set_attr "length" "8")])
5440
5441 (define_insn "*mulsidi3_no_mq"
5442   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5443         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5444                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
5445   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
5446   "*
5447 {
5448   return (WORDS_BIG_ENDIAN)
5449     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
5450     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
5451 }"
5452   [(set_attr "type" "imul")
5453    (set_attr "length" "8")])
5454
5455 (define_split
5456   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5457         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5458                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5459   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
5460   [(set (match_dup 3)
5461         (truncate:SI
5462          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
5463                                (sign_extend:DI (match_dup 2)))
5464                       (const_int 32))))
5465    (set (match_dup 4)
5466         (mult:SI (match_dup 1)
5467                  (match_dup 2)))]
5468   "
5469 {
5470   int endian = (WORDS_BIG_ENDIAN == 0);
5471   operands[3] = operand_subword (operands[0], endian, 0, DImode);
5472   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
5473 }")
5474
5475 (define_expand "umulsidi3"
5476   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5477         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5478                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5479   "TARGET_POWERPC && ! TARGET_POWERPC64"
5480   "
5481 {
5482   if (TARGET_POWER)
5483     {
5484       emit_insn (gen_umulsidi3_mq (operands[0], operands[1], operands[2]));
5485       DONE;
5486     }
5487 }")
5488
5489 (define_insn "umulsidi3_mq"
5490   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5491         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5492                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
5493    (clobber (match_scratch:SI 3 "=q"))]
5494   "TARGET_POWERPC && TARGET_POWER"
5495   "*
5496 {
5497   return (WORDS_BIG_ENDIAN)
5498     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
5499     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
5500 }"
5501   [(set_attr "type" "imul")
5502    (set_attr "length" "8")])
5503
5504 (define_insn "*umulsidi3_no_mq"
5505   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5506         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5507                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
5508   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
5509   "*
5510 {
5511   return (WORDS_BIG_ENDIAN)
5512     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
5513     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
5514 }"
5515   [(set_attr "type" "imul")
5516    (set_attr "length" "8")])
5517
5518 (define_split
5519   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5520         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5521                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5522   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
5523   [(set (match_dup 3)
5524         (truncate:SI
5525          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
5526                                (zero_extend:DI (match_dup 2)))
5527                       (const_int 32))))
5528    (set (match_dup 4)
5529         (mult:SI (match_dup 1)
5530                  (match_dup 2)))]
5531   "
5532 {
5533   int endian = (WORDS_BIG_ENDIAN == 0);
5534   operands[3] = operand_subword (operands[0], endian, 0, DImode);
5535   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
5536 }")
5537
5538 (define_expand "smulsi3_highpart"
5539   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5540         (truncate:SI
5541          (lshiftrt:DI (mult:DI (sign_extend:DI
5542                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5543                                (sign_extend:DI
5544                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5545                       (const_int 32))))]
5546   ""
5547   "
5548 {
5549   if (! TARGET_POWER && ! TARGET_POWERPC)
5550     {
5551       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
5552       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
5553       emit_insn (gen_mulh_call ());
5554       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
5555       DONE;
5556     }
5557   else if (TARGET_POWER)
5558     {
5559       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
5560       DONE;
5561     }
5562 }")
5563
5564 (define_insn "smulsi3_highpart_mq"
5565   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5566         (truncate:SI
5567          (lshiftrt:DI (mult:DI (sign_extend:DI
5568                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5569                                (sign_extend:DI
5570                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5571                       (const_int 32))))
5572    (clobber (match_scratch:SI 3 "=q"))]
5573   "TARGET_POWER"
5574   "mul %0,%1,%2"
5575   [(set_attr "type" "imul")])
5576
5577 (define_insn "*smulsi3_highpart_no_mq"
5578   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5579         (truncate:SI
5580          (lshiftrt:DI (mult:DI (sign_extend:DI
5581                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5582                                (sign_extend:DI
5583                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5584                       (const_int 32))))]
5585   "TARGET_POWERPC && ! TARGET_POWER"
5586   "mulhw %0,%1,%2"
5587   [(set_attr "type" "imul")])
5588
5589 (define_expand "umulsi3_highpart"
5590   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5591         (truncate:SI
5592          (lshiftrt:DI (mult:DI (zero_extend:DI
5593                                 (match_operand:SI 1 "gpc_reg_operand" ""))
5594                                (zero_extend:DI
5595                                 (match_operand:SI 2 "gpc_reg_operand" "")))
5596                       (const_int 32))))]
5597   "TARGET_POWERPC"
5598   "
5599 {
5600   if (TARGET_POWER)
5601     {
5602       emit_insn (gen_umulsi3_highpart_mq (operands[0], operands[1], operands[2]));
5603       DONE;
5604     }
5605 }")
5606
5607 (define_insn "umulsi3_highpart_mq"
5608   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5609         (truncate:SI
5610          (lshiftrt:DI (mult:DI (zero_extend:DI
5611                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5612                                (zero_extend:DI
5613                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5614                       (const_int 32))))
5615    (clobber (match_scratch:SI 3 "=q"))]
5616   "TARGET_POWERPC && TARGET_POWER"
5617   "mulhwu %0,%1,%2"
5618   [(set_attr "type" "imul")])
5619
5620 (define_insn "*umulsi3_highpart_no_mq"
5621   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5622         (truncate:SI
5623          (lshiftrt:DI (mult:DI (zero_extend:DI
5624                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5625                                (zero_extend:DI
5626                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5627                       (const_int 32))))]
5628   "TARGET_POWERPC && ! TARGET_POWER"
5629   "mulhwu %0,%1,%2"
5630   [(set_attr "type" "imul")])
5631
5632 ;; If operands 0 and 2 are in the same register, we have a problem.  But
5633 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
5634 ;; why we have the strange constraints below.
5635 (define_insn "ashldi3_power"
5636   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
5637         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
5638                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
5639    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
5640   "TARGET_POWER"
5641   "@
5642    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
5643    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
5644    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
5645    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
5646   [(set_attr "length" "8")])
5647
5648 (define_insn "lshrdi3_power"
5649   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
5650         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
5651                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
5652    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
5653   "TARGET_POWER"
5654   "@
5655    {s%A2i|s%A2wi} %L0,%1,%h2\;{cal %0,0(0)|li %0,0}
5656    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
5657    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
5658    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
5659   [(set_attr "length" "8")])
5660
5661 ;; Shift by a variable amount is too complex to be worth open-coding.  We
5662 ;; just handle shifts by constants.
5663 (define_insn "ashrdi3_power"
5664   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5665         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5666                      (match_operand:SI 2 "const_int_operand" "M,i")))
5667    (clobber (match_scratch:SI 3 "=X,q"))]
5668   "TARGET_POWER"
5669   "@
5670    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
5671    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
5672   [(set_attr "length" "8")])
5673
5674 (define_insn "ashrdi3_no_power"
5675   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
5676         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5677                      (match_operand:SI 2 "const_int_operand" "M,i")))]
5678   "TARGET_32BIT && !TARGET_POWERPC64 && !TARGET_POWER && WORDS_BIG_ENDIAN"
5679   "@
5680    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
5681    {sri|srwi} %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;{srai|srawi} %0,%1,%h2"
5682   [(set_attr "length" "8,12")])
5683
5684 (define_insn "*ashrdisi3_noppc64"
5685   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5686         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
5687                                 (const_int 32)) 4))]
5688   "TARGET_32BIT && !TARGET_POWERPC64"
5689   "*
5690 {
5691   if (REGNO (operands[0]) == REGNO (operands[1]))
5692     return \"\";
5693   else
5694     return \"mr %0,%1\";
5695 }"
5696    [(set_attr "length" "4")])
5697
5698 \f
5699 ;; PowerPC64 DImode operations.
5700
5701 (define_expand "adddi3"
5702   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5703         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5704                  (match_operand:DI 2 "reg_or_add_cint64_operand" "")))]
5705   ""
5706   "
5707 {
5708   if (! TARGET_POWERPC64)
5709     {
5710       if (non_short_cint_operand (operands[2], DImode))
5711         FAIL;
5712     }
5713   else
5714     if (GET_CODE (operands[2]) == CONST_INT
5715         && ! add_operand (operands[2], DImode))
5716       {
5717         rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
5718                    ? operands[0] : gen_reg_rtx (DImode));
5719
5720         HOST_WIDE_INT val = INTVAL (operands[2]);
5721         HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
5722         HOST_WIDE_INT rest = trunc_int_for_mode (val - low, DImode);
5723
5724         if (!CONST_OK_FOR_LETTER_P (rest, 'L'))
5725           FAIL;
5726
5727         /* The ordering here is important for the prolog expander.
5728            When space is allocated from the stack, adding 'low' first may
5729            produce a temporary deallocation (which would be bad).  */
5730         emit_insn (gen_adddi3 (tmp, operands[1], GEN_INT (rest)));
5731         emit_insn (gen_adddi3 (operands[0], tmp, GEN_INT (low)));
5732         DONE;
5733       }
5734 }")
5735
5736 ;; Discourage ai/addic because of carry but provide it in an alternative
5737 ;; allowing register zero as source.
5738
5739 (define_insn "*adddi3_internal1"
5740   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,?r,r")
5741         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,b,r,b")
5742                  (match_operand:DI 2 "add_operand" "r,I,I,L")))]
5743   "TARGET_POWERPC64"
5744   "@
5745    add %0,%1,%2
5746    addi %0,%1,%2
5747    addic %0,%1,%2
5748    addis %0,%1,%v2")
5749
5750 (define_insn "*adddi3_internal2"
5751   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
5752         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
5753                              (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I"))
5754                     (const_int 0)))
5755    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
5756   "TARGET_64BIT"
5757   "@
5758    add. %3,%1,%2
5759    addic. %3,%1,%2
5760    #
5761    #"
5762   [(set_attr "type" "fast_compare,compare,compare,compare")
5763    (set_attr "length" "4,4,8,8")])
5764
5765 (define_split
5766   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5767         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5768                              (match_operand:DI 2 "reg_or_short_operand" ""))
5769                     (const_int 0)))
5770    (clobber (match_scratch:DI 3 ""))]
5771   "TARGET_POWERPC64 && reload_completed"
5772   [(set (match_dup 3)
5773         (plus:DI (match_dup 1) (match_dup 2)))
5774    (set (match_dup 0)
5775         (compare:CC (match_dup 3)
5776                     (const_int 0)))]
5777   "")
5778
5779 (define_insn "*adddi3_internal3"
5780   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
5781         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
5782                              (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I"))
5783                     (const_int 0)))
5784    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
5785         (plus:DI (match_dup 1) (match_dup 2)))]
5786   "TARGET_64BIT"
5787   "@
5788    add. %0,%1,%2
5789    addic. %0,%1,%2
5790    #
5791    #"
5792   [(set_attr "type" "fast_compare,compare,compare,compare")
5793    (set_attr "length" "4,4,8,8")])
5794
5795 (define_split
5796   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5797         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5798                              (match_operand:DI 2 "reg_or_short_operand" ""))
5799                     (const_int 0)))
5800    (set (match_operand:DI 0 "gpc_reg_operand" "")
5801         (plus:DI (match_dup 1) (match_dup 2)))]
5802   "TARGET_POWERPC64 && reload_completed"
5803   [(set (match_dup 0)
5804         (plus:DI (match_dup 1) (match_dup 2)))
5805    (set (match_dup 3)
5806         (compare:CC (match_dup 0)
5807                     (const_int 0)))]
5808   "")
5809
5810 ;; Split an add that we can't do in one insn into two insns, each of which
5811 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
5812 ;; add should be last in case the result gets used in an address.
5813
5814 (define_split
5815   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5816         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5817                  (match_operand:DI 2 "non_add_cint_operand" "")))]
5818   "TARGET_POWERPC64"
5819   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 3)))
5820    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 4)))]
5821 "
5822 {
5823   HOST_WIDE_INT val = INTVAL (operands[2]);
5824   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
5825   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, DImode);
5826
5827   operands[4] = GEN_INT (low);
5828   if (CONST_OK_FOR_LETTER_P (rest, 'L'))
5829     operands[3] = GEN_INT (rest);
5830   else if (! no_new_pseudos)
5831     {
5832       operands[3] = gen_reg_rtx (DImode);
5833       emit_move_insn (operands[3], operands[2]);
5834       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
5835       DONE;
5836     }
5837   else
5838     FAIL;
5839 }")
5840
5841 (define_insn "one_cmpldi2"
5842   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5843         (not:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
5844   "TARGET_POWERPC64"
5845   "nor %0,%1,%1")
5846
5847 (define_insn ""
5848   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5849         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
5850                     (const_int 0)))
5851    (clobber (match_scratch:DI 2 "=r,r"))]
5852   "TARGET_64BIT"
5853   "@
5854    nor. %2,%1,%1
5855    #"
5856   [(set_attr "type" "compare")
5857    (set_attr "length" "4,8")])
5858
5859 (define_split
5860   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5861         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
5862                     (const_int 0)))
5863    (clobber (match_scratch:DI 2 ""))]
5864   "TARGET_POWERPC64 && reload_completed"
5865   [(set (match_dup 2)
5866         (not:DI (match_dup 1)))
5867    (set (match_dup 0)
5868         (compare:CC (match_dup 2)
5869                     (const_int 0)))]
5870   "")
5871
5872 (define_insn ""
5873   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
5874         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
5875                     (const_int 0)))
5876    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5877         (not:DI (match_dup 1)))]
5878   "TARGET_64BIT"
5879   "@
5880    nor. %0,%1,%1
5881    #"
5882   [(set_attr "type" "compare")
5883    (set_attr "length" "4,8")])
5884
5885 (define_split
5886   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
5887         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
5888                     (const_int 0)))
5889    (set (match_operand:DI 0 "gpc_reg_operand" "")
5890         (not:DI (match_dup 1)))]
5891   "TARGET_POWERPC64 && reload_completed"
5892   [(set (match_dup 0)
5893         (not:DI (match_dup 1)))
5894    (set (match_dup 2)
5895         (compare:CC (match_dup 0)
5896                     (const_int 0)))]
5897   "")
5898
5899 (define_insn ""
5900   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5901         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I")
5902                   (match_operand:DI 2 "gpc_reg_operand" "r,r")))]
5903   "TARGET_POWERPC64"
5904   "@
5905    subf %0,%2,%1
5906    subfic %0,%2,%1")
5907
5908 (define_insn ""
5909   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5910         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5911                               (match_operand:DI 2 "gpc_reg_operand" "r,r"))
5912                     (const_int 0)))
5913    (clobber (match_scratch:DI 3 "=r,r"))]
5914   "TARGET_64BIT"
5915   "@
5916    subf. %3,%2,%1
5917    #"
5918   [(set_attr "type" "fast_compare")
5919    (set_attr "length" "4,8")])
5920
5921 (define_split
5922   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5923         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5924                               (match_operand:DI 2 "gpc_reg_operand" ""))
5925                     (const_int 0)))
5926    (clobber (match_scratch:DI 3 ""))]
5927   "TARGET_POWERPC64 && reload_completed"
5928   [(set (match_dup 3)
5929         (minus:DI (match_dup 1) (match_dup 2)))
5930    (set (match_dup 0)
5931         (compare:CC (match_dup 3)
5932                     (const_int 0)))]
5933   "")
5934
5935 (define_insn ""
5936   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
5937         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5938                               (match_operand:DI 2 "gpc_reg_operand" "r,r"))
5939                     (const_int 0)))
5940    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5941         (minus:DI (match_dup 1) (match_dup 2)))]
5942   "TARGET_64BIT"
5943   "@
5944    subf. %0,%2,%1
5945    #"
5946   [(set_attr "type" "fast_compare")
5947    (set_attr "length" "4,8")])
5948
5949 (define_split
5950   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5951         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5952                               (match_operand:DI 2 "gpc_reg_operand" ""))
5953                     (const_int 0)))
5954    (set (match_operand:DI 0 "gpc_reg_operand" "")
5955         (minus:DI (match_dup 1) (match_dup 2)))]
5956   "TARGET_POWERPC64 && reload_completed"
5957   [(set (match_dup 0)
5958         (minus:DI (match_dup 1) (match_dup 2)))
5959    (set (match_dup 3)
5960         (compare:CC (match_dup 0)
5961                     (const_int 0)))]
5962   "")
5963
5964 (define_expand "subdi3"
5965   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5966         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "")
5967                   (match_operand:DI 2 "reg_or_sub_cint64_operand" "")))]
5968   ""
5969   "
5970 {
5971   if (GET_CODE (operands[2]) == CONST_INT)
5972     {
5973       emit_insn (gen_adddi3 (operands[0], operands[1],
5974                              negate_rtx (DImode, operands[2])));
5975       DONE;
5976     }
5977 }")
5978
5979 (define_insn_and_split "absdi2"
5980   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5981         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
5982    (clobber (match_scratch:DI 2 "=&r,&r"))]
5983   "TARGET_POWERPC64"
5984   "#"
5985   "&& reload_completed"
5986   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
5987    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
5988    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
5989   "")
5990
5991 (define_insn_and_split "*nabsdi2"
5992   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5993         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
5994    (clobber (match_scratch:DI 2 "=&r,&r"))]
5995   "TARGET_POWERPC64"
5996   "#"
5997   "&& reload_completed"
5998   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
5999    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
6000    (set (match_dup 0) (minus:DI (match_dup 2) (match_dup 0)))]
6001   "")
6002
6003 (define_expand "negdi2"
6004   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6005         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "")))]
6006   ""
6007   "")
6008
6009 (define_insn ""
6010   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6011         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
6012   "TARGET_POWERPC64"
6013   "neg %0,%1")
6014
6015 (define_insn ""
6016   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6017         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
6018                     (const_int 0)))
6019    (clobber (match_scratch:DI 2 "=r,r"))]
6020   "TARGET_64BIT"
6021   "@
6022    neg. %2,%1
6023    #"
6024   [(set_attr "type" "fast_compare")
6025    (set_attr "length" "4,8")])
6026
6027 (define_split
6028   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6029         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" ""))
6030                     (const_int 0)))
6031    (clobber (match_scratch:DI 2 ""))]
6032   "TARGET_POWERPC64 && reload_completed"
6033   [(set (match_dup 2)
6034         (neg:DI (match_dup 1)))
6035    (set (match_dup 0)
6036         (compare:CC (match_dup 2)
6037                     (const_int 0)))]
6038   "")
6039
6040 (define_insn ""
6041   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
6042         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
6043                     (const_int 0)))
6044    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6045         (neg:DI (match_dup 1)))]
6046   "TARGET_64BIT"
6047   "@
6048    neg. %0,%1
6049    #"
6050   [(set_attr "type" "fast_compare")
6051    (set_attr "length" "4,8")])
6052
6053 (define_split
6054   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
6055         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" ""))
6056                     (const_int 0)))
6057    (set (match_operand:DI 0 "gpc_reg_operand" "")
6058         (neg:DI (match_dup 1)))]
6059   "TARGET_POWERPC64 && reload_completed"
6060   [(set (match_dup 0)
6061         (neg:DI (match_dup 1)))
6062    (set (match_dup 2)
6063         (compare:CC (match_dup 0)
6064                     (const_int 0)))]
6065   "")
6066
6067 (define_insn "clzdi2"
6068   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6069         (clz:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
6070   "TARGET_POWERPC64"
6071   "cntlzd %0,%1")
6072
6073 (define_expand "ctzdi2"
6074   [(set (match_dup 2)
6075         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
6076    (parallel [(set (match_dup 3) (and:DI (match_dup 1)
6077                                          (match_dup 2)))
6078               (clobber (scratch:CC))])
6079    (set (match_dup 4) (clz:DI (match_dup 3)))
6080    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
6081         (minus:DI (const_int 63) (match_dup 4)))]
6082   "TARGET_POWERPC64"
6083   {
6084      operands[2] = gen_reg_rtx (DImode);
6085      operands[3] = gen_reg_rtx (DImode);
6086      operands[4] = gen_reg_rtx (DImode);
6087   })
6088
6089 (define_expand "ffsdi2"
6090   [(set (match_dup 2)
6091         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
6092    (parallel [(set (match_dup 3) (and:DI (match_dup 1)
6093                                          (match_dup 2)))
6094               (clobber (scratch:CC))])
6095    (set (match_dup 4) (clz:DI (match_dup 3)))
6096    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
6097         (minus:DI (const_int 64) (match_dup 4)))]
6098   "TARGET_POWERPC64"
6099   {
6100      operands[2] = gen_reg_rtx (DImode);
6101      operands[3] = gen_reg_rtx (DImode);
6102      operands[4] = gen_reg_rtx (DImode);
6103   })
6104
6105 (define_insn "muldi3"
6106   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6107         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
6108                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
6109   "TARGET_POWERPC64"
6110   "mulld %0,%1,%2"
6111    [(set_attr "type" "lmul")])
6112
6113 (define_insn "*muldi3_internal1"
6114   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6115         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6116                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6117                     (const_int 0)))
6118    (clobber (match_scratch:DI 3 "=r,r"))]
6119   "TARGET_POWERPC64"
6120   "@
6121    mulld. %3,%1,%2
6122    #"
6123   [(set_attr "type" "lmul_compare")
6124    (set_attr "length" "4,8")])
6125
6126 (define_split
6127   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6128         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6129                              (match_operand:DI 2 "gpc_reg_operand" ""))
6130                     (const_int 0)))
6131    (clobber (match_scratch:DI 3 ""))]
6132   "TARGET_POWERPC64 && reload_completed"
6133   [(set (match_dup 3)
6134         (mult:DI (match_dup 1) (match_dup 2)))
6135    (set (match_dup 0)
6136         (compare:CC (match_dup 3)
6137                     (const_int 0)))]
6138   "")
6139
6140 (define_insn "*muldi3_internal2"
6141   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6142         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6143                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6144                     (const_int 0)))
6145    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6146         (mult:DI (match_dup 1) (match_dup 2)))]
6147   "TARGET_POWERPC64"
6148   "@
6149    mulld. %0,%1,%2
6150    #"
6151   [(set_attr "type" "lmul_compare")
6152    (set_attr "length" "4,8")])
6153
6154 (define_split
6155   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6156         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6157                              (match_operand:DI 2 "gpc_reg_operand" ""))
6158                     (const_int 0)))
6159    (set (match_operand:DI 0 "gpc_reg_operand" "")
6160         (mult:DI (match_dup 1) (match_dup 2)))]
6161   "TARGET_POWERPC64 && reload_completed"
6162   [(set (match_dup 0)
6163         (mult:DI (match_dup 1) (match_dup 2)))
6164    (set (match_dup 3)
6165         (compare:CC (match_dup 0)
6166                     (const_int 0)))]
6167   "")
6168
6169 (define_insn "smuldi3_highpart"
6170   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6171         (truncate:DI
6172          (lshiftrt:TI (mult:TI (sign_extend:TI
6173                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6174                                (sign_extend:TI
6175                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6176                       (const_int 64))))]
6177   "TARGET_POWERPC64"
6178   "mulhd %0,%1,%2"
6179   [(set_attr "type" "lmul")])
6180
6181 (define_insn "umuldi3_highpart"
6182   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6183         (truncate:DI
6184          (lshiftrt:TI (mult:TI (zero_extend:TI
6185                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6186                                (zero_extend:TI
6187                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6188                       (const_int 64))))]
6189   "TARGET_POWERPC64"
6190   "mulhdu %0,%1,%2"
6191   [(set_attr "type" "lmul")])
6192
6193 (define_expand "divdi3"
6194   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6195         (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6196                 (match_operand:DI 2 "reg_or_cint_operand" "")))]
6197   "TARGET_POWERPC64"
6198   "
6199 {
6200   if (GET_CODE (operands[2]) == CONST_INT
6201       && INTVAL (operands[2]) > 0
6202       && exact_log2 (INTVAL (operands[2])) >= 0)
6203     ;
6204   else
6205     operands[2] = force_reg (DImode, operands[2]);
6206 }")
6207
6208 (define_expand "moddi3"
6209   [(use (match_operand:DI 0 "gpc_reg_operand" ""))
6210    (use (match_operand:DI 1 "gpc_reg_operand" ""))
6211    (use (match_operand:DI 2 "reg_or_cint_operand" ""))]
6212   "TARGET_POWERPC64"
6213   "
6214 {
6215   int i;
6216   rtx temp1;
6217   rtx temp2;
6218
6219   if (GET_CODE (operands[2]) != CONST_INT
6220       || INTVAL (operands[2]) <= 0
6221       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
6222     FAIL;
6223
6224   temp1 = gen_reg_rtx (DImode);
6225   temp2 = gen_reg_rtx (DImode);
6226
6227   emit_insn (gen_divdi3 (temp1, operands[1], operands[2]));
6228   emit_insn (gen_ashldi3 (temp2, temp1, GEN_INT (i)));
6229   emit_insn (gen_subdi3 (operands[0], operands[1], temp2));
6230   DONE;
6231 }")
6232
6233 (define_insn ""
6234   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6235         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6236                 (match_operand:DI 2 "exact_log2_cint_operand" "N")))]
6237   "TARGET_POWERPC64"
6238   "sradi %0,%1,%p2\;addze %0,%0"
6239   [(set_attr "length" "8")])
6240
6241 (define_insn ""
6242   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6243         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6244                             (match_operand:DI 2 "exact_log2_cint_operand" "N,N"))
6245                     (const_int 0)))
6246    (clobber (match_scratch:DI 3 "=r,r"))]
6247   "TARGET_64BIT"
6248   "@
6249    sradi %3,%1,%p2\;addze. %3,%3
6250    #"
6251   [(set_attr "type" "compare")
6252    (set_attr "length" "8,12")])
6253
6254 (define_split
6255   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6256         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6257                             (match_operand:DI 2 "exact_log2_cint_operand" ""))
6258                     (const_int 0)))
6259    (clobber (match_scratch:DI 3 ""))]
6260   "TARGET_POWERPC64 && reload_completed"
6261   [(set (match_dup 3)
6262         (div:DI (match_dup 1) (match_dup 2)))
6263    (set (match_dup 0)
6264         (compare:CC (match_dup 3)
6265                     (const_int 0)))]
6266   "")
6267
6268 (define_insn ""
6269   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6270         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6271                             (match_operand:DI 2 "exact_log2_cint_operand" "N,N"))
6272                     (const_int 0)))
6273    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6274         (div:DI (match_dup 1) (match_dup 2)))]
6275   "TARGET_64BIT"
6276   "@
6277    sradi %0,%1,%p2\;addze. %0,%0
6278    #"
6279   [(set_attr "type" "compare")
6280    (set_attr "length" "8,12")])
6281
6282 (define_split
6283   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6284         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6285                             (match_operand:DI 2 "exact_log2_cint_operand" ""))
6286                     (const_int 0)))
6287    (set (match_operand:DI 0 "gpc_reg_operand" "")
6288         (div:DI (match_dup 1) (match_dup 2)))]
6289   "TARGET_POWERPC64 && reload_completed"
6290   [(set (match_dup 0)
6291         (div:DI (match_dup 1) (match_dup 2)))
6292    (set (match_dup 3)
6293         (compare:CC (match_dup 0)
6294                     (const_int 0)))]
6295   "")
6296
6297 (define_insn ""
6298   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6299         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6300                 (match_operand:DI 2 "gpc_reg_operand" "r")))]
6301   "TARGET_POWERPC64"
6302   "divd %0,%1,%2"
6303   [(set_attr "type" "ldiv")])
6304
6305 (define_insn "udivdi3"
6306   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6307         (udiv:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6308                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
6309   "TARGET_POWERPC64"
6310   "divdu %0,%1,%2"
6311   [(set_attr "type" "ldiv")])
6312
6313 (define_insn "rotldi3"
6314   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6315         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6316                    (match_operand:DI 2 "reg_or_cint_operand" "ri")))]
6317   "TARGET_POWERPC64"
6318   "rld%I2cl %0,%1,%H2,0")
6319
6320 (define_insn "*rotldi3_internal2"
6321   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6322         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6323                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6324                     (const_int 0)))
6325    (clobber (match_scratch:DI 3 "=r,r"))]
6326   "TARGET_64BIT"
6327   "@
6328    rld%I2cl. %3,%1,%H2,0
6329    #"
6330   [(set_attr "type" "delayed_compare")
6331    (set_attr "length" "4,8")])
6332
6333 (define_split
6334   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6335         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6336                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6337                     (const_int 0)))
6338    (clobber (match_scratch:DI 3 ""))]
6339   "TARGET_POWERPC64 && reload_completed"
6340   [(set (match_dup 3)
6341         (rotate:DI (match_dup 1) (match_dup 2)))
6342    (set (match_dup 0)
6343         (compare:CC (match_dup 3)
6344                     (const_int 0)))]
6345   "")
6346
6347 (define_insn "*rotldi3_internal3"
6348   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6349         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6350                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6351                     (const_int 0)))
6352    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6353         (rotate:DI (match_dup 1) (match_dup 2)))]
6354   "TARGET_64BIT"
6355   "@
6356    rld%I2cl. %0,%1,%H2,0
6357    #"
6358   [(set_attr "type" "delayed_compare")
6359    (set_attr "length" "4,8")])
6360
6361 (define_split
6362   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6363         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6364                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6365                     (const_int 0)))
6366    (set (match_operand:DI 0 "gpc_reg_operand" "")
6367         (rotate:DI (match_dup 1) (match_dup 2)))]
6368   "TARGET_POWERPC64 && reload_completed"
6369   [(set (match_dup 0)
6370         (rotate:DI (match_dup 1) (match_dup 2)))
6371    (set (match_dup 3)
6372         (compare:CC (match_dup 0)
6373                     (const_int 0)))]
6374   "")
6375
6376 (define_insn "*rotldi3_internal4"
6377   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6378         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6379                            (match_operand:DI 2 "reg_or_cint_operand" "ri"))
6380                 (match_operand:DI 3 "mask64_operand" "n")))]
6381   "TARGET_POWERPC64"
6382   "rld%I2c%B3 %0,%1,%H2,%S3")
6383
6384 (define_insn "*rotldi3_internal5"
6385   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6386         (compare:CC (and:DI
6387                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6388                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6389                      (match_operand:DI 3 "mask64_operand" "n,n"))
6390                     (const_int 0)))
6391    (clobber (match_scratch:DI 4 "=r,r"))]
6392   "TARGET_64BIT"
6393   "@
6394    rld%I2c%B3. %4,%1,%H2,%S3
6395    #"
6396   [(set_attr "type" "delayed_compare")
6397    (set_attr "length" "4,8")])
6398
6399 (define_split
6400   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6401         (compare:CC (and:DI
6402                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6403                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6404                      (match_operand:DI 3 "mask64_operand" ""))
6405                     (const_int 0)))
6406    (clobber (match_scratch:DI 4 ""))]
6407   "TARGET_POWERPC64 && reload_completed"
6408   [(set (match_dup 4)
6409         (and:DI (rotate:DI (match_dup 1)
6410                                 (match_dup 2))
6411                      (match_dup 3)))
6412    (set (match_dup 0)
6413         (compare:CC (match_dup 4)
6414                     (const_int 0)))]
6415   "")
6416
6417 (define_insn "*rotldi3_internal6"
6418   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6419         (compare:CC (and:DI
6420                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6421                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6422                      (match_operand:DI 3 "mask64_operand" "n,n"))
6423                     (const_int 0)))
6424    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6425         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6426   "TARGET_64BIT"
6427   "@
6428    rld%I2c%B3. %0,%1,%H2,%S3
6429    #"
6430   [(set_attr "type" "delayed_compare")
6431    (set_attr "length" "4,8")])
6432
6433 (define_split
6434   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6435         (compare:CC (and:DI
6436                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6437                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6438                      (match_operand:DI 3 "mask64_operand" ""))
6439                     (const_int 0)))
6440    (set (match_operand:DI 0 "gpc_reg_operand" "")
6441         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6442   "TARGET_POWERPC64 && reload_completed"
6443   [(set (match_dup 0)
6444         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
6445    (set (match_dup 4)
6446         (compare:CC (match_dup 0)
6447                     (const_int 0)))]
6448   "")
6449
6450 (define_insn "*rotldi3_internal7"
6451   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6452         (zero_extend:DI
6453          (subreg:QI
6454           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6455                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6456   "TARGET_POWERPC64"
6457   "rld%I2cl %0,%1,%H2,56")
6458
6459 (define_insn "*rotldi3_internal8"
6460   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6461         (compare:CC (zero_extend:DI
6462                      (subreg:QI
6463                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6464                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6465                     (const_int 0)))
6466    (clobber (match_scratch:DI 3 "=r,r"))]
6467   "TARGET_64BIT"
6468   "@
6469    rld%I2cl. %3,%1,%H2,56
6470    #"
6471   [(set_attr "type" "delayed_compare")
6472    (set_attr "length" "4,8")])
6473
6474 (define_split
6475   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6476         (compare:CC (zero_extend:DI
6477                      (subreg:QI
6478                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6479                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6480                     (const_int 0)))
6481    (clobber (match_scratch:DI 3 ""))]
6482   "TARGET_POWERPC64 && reload_completed"
6483   [(set (match_dup 3)
6484         (zero_extend:DI (subreg:QI
6485                       (rotate:DI (match_dup 1)
6486                                  (match_dup 2)) 0)))
6487    (set (match_dup 0)
6488         (compare:CC (match_dup 3)
6489                     (const_int 0)))]
6490   "")
6491
6492 (define_insn "*rotldi3_internal9"
6493   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6494         (compare:CC (zero_extend:DI
6495                      (subreg:QI
6496                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6497                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6498                     (const_int 0)))
6499    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6500         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6501   "TARGET_64BIT"
6502   "@
6503    rld%I2cl. %0,%1,%H2,56
6504    #"
6505   [(set_attr "type" "delayed_compare")
6506    (set_attr "length" "4,8")])
6507
6508 (define_split
6509   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6510         (compare:CC (zero_extend:DI
6511                      (subreg:QI
6512                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6513                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6514                     (const_int 0)))
6515    (set (match_operand:DI 0 "gpc_reg_operand" "")
6516         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6517   "TARGET_POWERPC64 && reload_completed"
6518   [(set (match_dup 0)
6519         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6520    (set (match_dup 3)
6521         (compare:CC (match_dup 0)
6522                     (const_int 0)))]
6523   "")
6524
6525 (define_insn "*rotldi3_internal10"
6526   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6527         (zero_extend:DI
6528          (subreg:HI
6529           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6530                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6531   "TARGET_POWERPC64"
6532   "rld%I2cl %0,%1,%H2,48")
6533
6534 (define_insn "*rotldi3_internal11"
6535   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6536         (compare:CC (zero_extend:DI
6537                      (subreg:HI
6538                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6539                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6540                     (const_int 0)))
6541    (clobber (match_scratch:DI 3 "=r,r"))]
6542   "TARGET_64BIT"
6543   "@
6544    rld%I2cl. %3,%1,%H2,48
6545    #"
6546   [(set_attr "type" "delayed_compare")
6547    (set_attr "length" "4,8")])
6548
6549 (define_split
6550   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6551         (compare:CC (zero_extend:DI
6552                      (subreg:HI
6553                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6554                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6555                     (const_int 0)))
6556    (clobber (match_scratch:DI 3 ""))]
6557   "TARGET_POWERPC64 && reload_completed"
6558   [(set (match_dup 3)
6559         (zero_extend:DI (subreg:HI
6560                       (rotate:DI (match_dup 1)
6561                                  (match_dup 2)) 0)))
6562    (set (match_dup 0)
6563         (compare:CC (match_dup 3)
6564                     (const_int 0)))]
6565   "")
6566
6567 (define_insn "*rotldi3_internal12"
6568   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6569         (compare:CC (zero_extend:DI
6570                      (subreg:HI
6571                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6572                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6573                     (const_int 0)))
6574    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6575         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6576   "TARGET_64BIT"
6577   "@
6578    rld%I2cl. %0,%1,%H2,48
6579    #"
6580   [(set_attr "type" "delayed_compare")
6581    (set_attr "length" "4,8")])
6582
6583 (define_split
6584   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6585         (compare:CC (zero_extend:DI
6586                      (subreg:HI
6587                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6588                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6589                     (const_int 0)))
6590    (set (match_operand:DI 0 "gpc_reg_operand" "")
6591         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6592   "TARGET_POWERPC64 && reload_completed"
6593   [(set (match_dup 0)
6594         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6595    (set (match_dup 3)
6596         (compare:CC (match_dup 0)
6597                     (const_int 0)))]
6598   "")
6599
6600 (define_insn "*rotldi3_internal13"
6601   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6602         (zero_extend:DI
6603          (subreg:SI
6604           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6605                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6606   "TARGET_POWERPC64"
6607   "rld%I2cl %0,%1,%H2,32")
6608
6609 (define_insn "*rotldi3_internal14"
6610   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6611         (compare:CC (zero_extend:DI
6612                      (subreg:SI
6613                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6614                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6615                     (const_int 0)))
6616    (clobber (match_scratch:DI 3 "=r,r"))]
6617   "TARGET_64BIT"
6618   "@
6619    rld%I2cl. %3,%1,%H2,32
6620    #"
6621   [(set_attr "type" "delayed_compare")
6622    (set_attr "length" "4,8")])
6623
6624 (define_split
6625   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6626         (compare:CC (zero_extend:DI
6627                      (subreg:SI
6628                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6629                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6630                     (const_int 0)))
6631    (clobber (match_scratch:DI 3 ""))]
6632   "TARGET_POWERPC64 && reload_completed"
6633   [(set (match_dup 3)
6634         (zero_extend:DI (subreg:SI
6635                       (rotate:DI (match_dup 1)
6636                                  (match_dup 2)) 0)))
6637    (set (match_dup 0)
6638         (compare:CC (match_dup 3)
6639                     (const_int 0)))]
6640   "")
6641
6642 (define_insn "*rotldi3_internal15"
6643   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6644         (compare:CC (zero_extend:DI
6645                      (subreg:SI
6646                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6647                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6648                     (const_int 0)))
6649    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6650         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6651   "TARGET_64BIT"
6652   "@
6653    rld%I2cl. %0,%1,%H2,32
6654    #"
6655   [(set_attr "type" "delayed_compare")
6656    (set_attr "length" "4,8")])
6657
6658 (define_split
6659   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6660         (compare:CC (zero_extend:DI
6661                      (subreg:SI
6662                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6663                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6664                     (const_int 0)))
6665    (set (match_operand:DI 0 "gpc_reg_operand" "")
6666         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6667   "TARGET_POWERPC64 && reload_completed"
6668   [(set (match_dup 0)
6669         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6670    (set (match_dup 3)
6671         (compare:CC (match_dup 0)
6672                     (const_int 0)))]
6673   "")
6674
6675 (define_expand "ashldi3"
6676   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6677         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6678                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
6679   "TARGET_POWERPC64 || TARGET_POWER"
6680   "
6681 {
6682   if (TARGET_POWERPC64)
6683     ;
6684   else if (TARGET_POWER)
6685     {
6686       emit_insn (gen_ashldi3_power (operands[0], operands[1], operands[2]));
6687       DONE;
6688     }
6689   else
6690     FAIL;
6691 }")
6692
6693 (define_insn "*ashldi3_internal1"
6694   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6695         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6696                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6697   "TARGET_POWERPC64"
6698   "sld%I2 %0,%1,%H2"
6699   [(set_attr "length" "8")])
6700
6701 (define_insn "*ashldi3_internal2"
6702   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6703         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6704                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6705                     (const_int 0)))
6706    (clobber (match_scratch:DI 3 "=r,r"))]
6707   "TARGET_64BIT"
6708   "@
6709    sld%I2. %3,%1,%H2
6710    #"
6711   [(set_attr "type" "delayed_compare")
6712    (set_attr "length" "4,8")])
6713
6714 (define_split
6715   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6716         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6717                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6718                     (const_int 0)))
6719    (clobber (match_scratch:DI 3 ""))]
6720   "TARGET_POWERPC64 && reload_completed"
6721   [(set (match_dup 3)
6722         (ashift:DI (match_dup 1) (match_dup 2)))
6723    (set (match_dup 0)
6724         (compare:CC (match_dup 3)
6725                     (const_int 0)))]
6726   "")
6727
6728 (define_insn "*ashldi3_internal3"
6729   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6730         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6731                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6732                     (const_int 0)))
6733    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6734         (ashift:DI (match_dup 1) (match_dup 2)))]
6735   "TARGET_64BIT"
6736   "@
6737    sld%I2. %0,%1,%H2
6738    #"
6739   [(set_attr "type" "delayed_compare")
6740    (set_attr "length" "4,8")])
6741
6742 (define_split
6743   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6744         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6745                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6746                     (const_int 0)))
6747    (set (match_operand:DI 0 "gpc_reg_operand" "")
6748         (ashift:DI (match_dup 1) (match_dup 2)))]
6749   "TARGET_POWERPC64 && reload_completed"
6750   [(set (match_dup 0)
6751         (ashift:DI (match_dup 1) (match_dup 2)))
6752    (set (match_dup 3)
6753         (compare:CC (match_dup 0)
6754                     (const_int 0)))]
6755   "")
6756
6757 (define_insn "*ashldi3_internal4"
6758   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6759         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6760                            (match_operand:SI 2 "const_int_operand" "i"))
6761                 (match_operand:DI 3 "const_int_operand" "n")))]
6762   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
6763   "rldic %0,%1,%H2,%W3")
6764
6765 (define_insn "ashldi3_internal5"
6766   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6767         (compare:CC
6768          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6769                             (match_operand:SI 2 "const_int_operand" "i,i"))
6770                  (match_operand:DI 3 "const_int_operand" "n,n"))
6771          (const_int 0)))
6772    (clobber (match_scratch:DI 4 "=r,r"))]
6773   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6774   "@
6775    rldic. %4,%1,%H2,%W3
6776    #"
6777   [(set_attr "type" "delayed_compare")
6778    (set_attr "length" "4,8")])
6779
6780 (define_split
6781   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6782         (compare:CC
6783          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6784                             (match_operand:SI 2 "const_int_operand" ""))
6785                  (match_operand:DI 3 "const_int_operand" ""))
6786          (const_int 0)))
6787    (clobber (match_scratch:DI 4 ""))]
6788   "TARGET_POWERPC64 && reload_completed
6789    && includes_rldic_lshift_p (operands[2], operands[3])"
6790   [(set (match_dup 4)
6791         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6792                 (match_dup 3)))
6793    (set (match_dup 0)
6794         (compare:CC (match_dup 4)
6795                     (const_int 0)))]
6796   "")
6797
6798 (define_insn "*ashldi3_internal6"
6799   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6800         (compare:CC
6801          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6802                             (match_operand:SI 2 "const_int_operand" "i,i"))
6803                     (match_operand:DI 3 "const_int_operand" "n,n"))
6804          (const_int 0)))
6805    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6806         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6807   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6808   "@
6809    rldic. %0,%1,%H2,%W3
6810    #"
6811   [(set_attr "type" "delayed_compare")
6812    (set_attr "length" "4,8")])
6813
6814 (define_split
6815   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6816         (compare:CC
6817          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6818                             (match_operand:SI 2 "const_int_operand" ""))
6819                  (match_operand:DI 3 "const_int_operand" ""))
6820          (const_int 0)))
6821    (set (match_operand:DI 0 "gpc_reg_operand" "")
6822         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6823   "TARGET_POWERPC64 && reload_completed
6824    && includes_rldic_lshift_p (operands[2], operands[3])"
6825   [(set (match_dup 0)
6826         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6827                 (match_dup 3)))
6828    (set (match_dup 4)
6829         (compare:CC (match_dup 0)
6830                     (const_int 0)))]
6831   "")
6832
6833 (define_insn "*ashldi3_internal7"
6834   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6835         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6836                            (match_operand:SI 2 "const_int_operand" "i"))
6837                 (match_operand:DI 3 "mask64_operand" "n")))]
6838   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
6839   "rldicr %0,%1,%H2,%S3")
6840
6841 (define_insn "ashldi3_internal8"
6842   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6843         (compare:CC
6844          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6845                             (match_operand:SI 2 "const_int_operand" "i,i"))
6846                  (match_operand:DI 3 "mask64_operand" "n,n"))
6847          (const_int 0)))
6848    (clobber (match_scratch:DI 4 "=r,r"))]
6849   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
6850   "@
6851    rldicr. %4,%1,%H2,%S3
6852    #"
6853   [(set_attr "type" "delayed_compare")
6854    (set_attr "length" "4,8")])
6855
6856 (define_split
6857   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6858         (compare:CC
6859          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6860                             (match_operand:SI 2 "const_int_operand" ""))
6861                  (match_operand:DI 3 "mask64_operand" ""))
6862          (const_int 0)))
6863    (clobber (match_scratch:DI 4 ""))]
6864   "TARGET_POWERPC64 && reload_completed
6865    && includes_rldicr_lshift_p (operands[2], operands[3])"
6866   [(set (match_dup 4)
6867         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6868                 (match_dup 3)))
6869    (set (match_dup 0)
6870         (compare:CC (match_dup 4)
6871                     (const_int 0)))]
6872   "")
6873
6874 (define_insn "*ashldi3_internal9"
6875   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6876         (compare:CC
6877          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6878                             (match_operand:SI 2 "const_int_operand" "i,i"))
6879                     (match_operand:DI 3 "mask64_operand" "n,n"))
6880          (const_int 0)))
6881    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6882         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6883   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
6884   "@
6885    rldicr. %0,%1,%H2,%S3
6886    #"
6887   [(set_attr "type" "delayed_compare")
6888    (set_attr "length" "4,8")])
6889
6890 (define_split
6891   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6892         (compare:CC
6893          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6894                             (match_operand:SI 2 "const_int_operand" ""))
6895                  (match_operand:DI 3 "mask64_operand" ""))
6896          (const_int 0)))
6897    (set (match_operand:DI 0 "gpc_reg_operand" "")
6898         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6899   "TARGET_POWERPC64 && reload_completed
6900    && includes_rldicr_lshift_p (operands[2], operands[3])"
6901   [(set (match_dup 0)
6902         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6903                 (match_dup 3)))
6904    (set (match_dup 4)
6905         (compare:CC (match_dup 0)
6906                     (const_int 0)))]
6907   "")
6908
6909 (define_expand "lshrdi3"
6910   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6911         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6912                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
6913   "TARGET_POWERPC64 || TARGET_POWER"
6914   "
6915 {
6916   if (TARGET_POWERPC64)
6917     ;
6918   else if (TARGET_POWER)
6919     {
6920       emit_insn (gen_lshrdi3_power (operands[0], operands[1], operands[2]));
6921       DONE;
6922     }
6923   else
6924     FAIL;
6925 }")
6926
6927 (define_insn "*lshrdi3_internal1"
6928   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6929         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6930                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6931   "TARGET_POWERPC64"
6932   "srd%I2 %0,%1,%H2")
6933
6934 (define_insn "*lshrdi3_internal2"
6935   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6936         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6937                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6938                     (const_int 0)))
6939    (clobber (match_scratch:DI 3 "=r,r"))]
6940   "TARGET_64BIT "
6941   "@
6942    srd%I2. %3,%1,%H2
6943    #"
6944   [(set_attr "type" "delayed_compare")
6945    (set_attr "length" "4,8")])
6946
6947 (define_split
6948   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6949         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6950                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6951                     (const_int 0)))
6952    (clobber (match_scratch:DI 3 ""))]
6953   "TARGET_POWERPC64 && reload_completed"
6954   [(set (match_dup 3)
6955         (lshiftrt:DI (match_dup 1) (match_dup 2)))
6956    (set (match_dup 0)
6957         (compare:CC (match_dup 3)
6958                     (const_int 0)))]
6959   "")
6960
6961 (define_insn "*lshrdi3_internal3"
6962   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6963         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6964                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6965                     (const_int 0)))
6966    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6967         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
6968   "TARGET_64BIT"
6969   "@
6970    srd%I2. %0,%1,%H2
6971    #"
6972   [(set_attr "type" "delayed_compare")
6973    (set_attr "length" "4,8")])
6974
6975 (define_split
6976   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6977         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6978                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6979                     (const_int 0)))
6980    (set (match_operand:DI 0 "gpc_reg_operand" "")
6981         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
6982   "TARGET_POWERPC64 && reload_completed"
6983   [(set (match_dup 0)
6984         (lshiftrt:DI (match_dup 1) (match_dup 2)))
6985    (set (match_dup 3)
6986         (compare:CC (match_dup 0)
6987                     (const_int 0)))]
6988   "")
6989
6990 (define_expand "ashrdi3"
6991   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6992         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6993                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
6994   "WORDS_BIG_ENDIAN"
6995   "
6996 {
6997   if (TARGET_POWERPC64)
6998     ;
6999   else if (TARGET_POWER && GET_CODE (operands[2]) == CONST_INT)
7000     {
7001       emit_insn (gen_ashrdi3_power (operands[0], operands[1], operands[2]));
7002       DONE;
7003     }
7004   else if (TARGET_32BIT && GET_CODE (operands[2]) == CONST_INT
7005            && WORDS_BIG_ENDIAN)
7006     {
7007       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
7008       DONE;
7009     }
7010   else
7011     FAIL;
7012 }")
7013
7014 (define_insn "*ashrdi3_internal1"
7015   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7016         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7017                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
7018   "TARGET_POWERPC64"
7019   "srad%I2 %0,%1,%H2")
7020
7021 (define_insn "*ashrdi3_internal2"
7022   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7023         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7024                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7025                     (const_int 0)))
7026    (clobber (match_scratch:DI 3 "=r,r"))]
7027   "TARGET_64BIT"
7028   "@
7029    srad%I2. %3,%1,%H2
7030    #"
7031   [(set_attr "type" "delayed_compare")
7032    (set_attr "length" "4,8")])
7033
7034 (define_split
7035   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7036         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7037                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7038                     (const_int 0)))
7039    (clobber (match_scratch:DI 3 ""))]
7040   "TARGET_POWERPC64 && reload_completed"
7041   [(set (match_dup 3)
7042         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7043    (set (match_dup 0)
7044         (compare:CC (match_dup 3)
7045                     (const_int 0)))]
7046   "")
7047
7048 (define_insn "*ashrdi3_internal3"
7049   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7050         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7051                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7052                     (const_int 0)))
7053    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7054         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7055   "TARGET_64BIT"
7056   "@
7057    srad%I2. %0,%1,%H2
7058    #"
7059   [(set_attr "type" "delayed_compare")
7060    (set_attr "length" "4,8")])
7061
7062 (define_split
7063   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7064         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7065                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7066                     (const_int 0)))
7067    (set (match_operand:DI 0 "gpc_reg_operand" "")
7068         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7069   "TARGET_POWERPC64 && reload_completed"
7070   [(set (match_dup 0)
7071         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7072    (set (match_dup 3)
7073         (compare:CC (match_dup 0)
7074                     (const_int 0)))]
7075   "")
7076
7077 (define_insn "anddi3"
7078   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r")
7079         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r")
7080                 (match_operand:DI 2 "and64_2_operand" "?r,S,K,J,t")))
7081    (clobber (match_scratch:CC 3 "=X,X,x,x,X"))]
7082   "TARGET_POWERPC64"
7083   "@
7084    and %0,%1,%2
7085    rldic%B2 %0,%1,0,%S2
7086    andi. %0,%1,%b2
7087    andis. %0,%1,%u2
7088    #"
7089   [(set_attr "length" "4,4,4,4,8")])
7090
7091 (define_split
7092   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7093         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7094                 (match_operand:DI 2 "mask64_2_operand" "")))
7095    (clobber (match_scratch:CC 3 ""))]
7096   "TARGET_POWERPC64
7097     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7098     && !mask64_operand (operands[2], DImode)"
7099   [(set (match_dup 0)
7100         (and:DI (rotate:DI (match_dup 1)
7101                            (match_dup 4))
7102                 (match_dup 5)))
7103    (set (match_dup 0)
7104         (and:DI (rotate:DI (match_dup 0)
7105                            (match_dup 6))
7106                 (match_dup 7)))]
7107   "
7108 {
7109   build_mask64_2_operands (operands[2], &operands[4]);
7110 }")
7111
7112 (define_insn "*anddi3_internal2"
7113   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,??y,??y,?y")
7114         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
7115                             (match_operand:DI 2 "and64_2_operand" "r,S,K,J,t,r,S,K,J,t"))
7116                     (const_int 0)))
7117    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r"))
7118    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,x,x,X"))]
7119   "TARGET_64BIT"
7120   "@
7121    and. %3,%1,%2
7122    rldic%B2. %3,%1,0,%S2
7123    andi. %3,%1,%b2
7124    andis. %3,%1,%u2
7125    #
7126    #
7127    #
7128    #
7129    #
7130    #"
7131   [(set_attr "type" "compare,delayed_compare,compare,compare,delayed_compare,compare,compare,compare,compare,compare")
7132    (set_attr "length" "4,4,4,4,8,8,8,8,8,12")])
7133
7134 (define_split
7135   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7136         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7137                             (match_operand:DI 2 "and64_operand" ""))
7138                     (const_int 0)))
7139    (clobber (match_scratch:DI 3 ""))
7140    (clobber (match_scratch:CC 4 ""))]
7141   "TARGET_POWERPC64 && reload_completed"
7142   [(parallel [(set (match_dup 3)
7143                    (and:DI (match_dup 1)
7144                            (match_dup 2)))
7145               (clobber (match_dup 4))])
7146    (set (match_dup 0)
7147         (compare:CC (match_dup 3)
7148                     (const_int 0)))]
7149   "")
7150
7151 (define_split
7152   [(set (match_operand:CC 0 "cc_reg_operand" "")
7153         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7154                             (match_operand:DI 2 "mask64_2_operand" ""))
7155                     (const_int 0)))
7156    (clobber (match_scratch:DI 3 ""))
7157    (clobber (match_scratch:CC 4 ""))]
7158   "TARGET_POWERPC64 && reload_completed
7159     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7160     && !mask64_operand (operands[2], DImode)"
7161   [(set (match_dup 3)
7162         (and:DI (rotate:DI (match_dup 1)
7163                            (match_dup 5))
7164                 (match_dup 6)))
7165    (parallel [(set (match_dup 0)
7166                    (compare:CC (and:DI (rotate:DI (match_dup 3)
7167                                                   (match_dup 7))
7168                                        (match_dup 8))
7169                                (const_int 0)))
7170               (clobber (match_dup 3))])]
7171   "
7172 {
7173   build_mask64_2_operands (operands[2], &operands[5]);
7174 }")
7175
7176 (define_insn "*anddi3_internal3"
7177   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,?y,?y,??y,??y,?y")
7178         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
7179                             (match_operand:DI 2 "and64_2_operand" "r,S,K,J,t,r,S,K,J,t"))
7180                     (const_int 0)))
7181    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
7182         (and:DI (match_dup 1) (match_dup 2)))
7183    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,x,x,X"))]
7184   "TARGET_64BIT"
7185   "@
7186    and. %0,%1,%2
7187    rldic%B2. %0,%1,0,%S2
7188    andi. %0,%1,%b2
7189    andis. %0,%1,%u2
7190    #
7191    #
7192    #
7193    #
7194    #
7195    #"
7196   [(set_attr "type" "compare,delayed_compare,compare,compare,delayed_compare,compare,compare,compare,compare,compare")
7197    (set_attr "length" "4,4,4,4,8,8,8,8,8,12")])
7198
7199 (define_split
7200   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7201         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7202                             (match_operand:DI 2 "and64_operand" ""))
7203                     (const_int 0)))
7204    (set (match_operand:DI 0 "gpc_reg_operand" "")
7205         (and:DI (match_dup 1) (match_dup 2)))
7206    (clobber (match_scratch:CC 4 ""))]
7207   "TARGET_POWERPC64 && reload_completed"
7208   [(parallel [(set (match_dup 0)
7209                     (and:DI (match_dup 1) (match_dup 2)))
7210                (clobber (match_dup 4))])
7211    (set (match_dup 3)
7212         (compare:CC (match_dup 0)
7213                     (const_int 0)))]
7214   "")
7215
7216 (define_split
7217   [(set (match_operand:CC 3 "cc_reg_operand" "")
7218         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7219                             (match_operand:DI 2 "mask64_2_operand" ""))
7220                     (const_int 0)))
7221    (set (match_operand:DI 0 "gpc_reg_operand" "")
7222         (and:DI (match_dup 1) (match_dup 2)))
7223    (clobber (match_scratch:CC 4 ""))]
7224   "TARGET_POWERPC64 && reload_completed
7225     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7226     && !mask64_operand (operands[2], DImode)"
7227   [(set (match_dup 0)
7228         (and:DI (rotate:DI (match_dup 1)
7229                            (match_dup 5))
7230                 (match_dup 6)))
7231    (parallel [(set (match_dup 3)
7232                    (compare:CC (and:DI (rotate:DI (match_dup 0)
7233                                                   (match_dup 7))
7234                                        (match_dup 8))
7235                                (const_int 0)))
7236               (set (match_dup 0)
7237                    (and:DI (rotate:DI (match_dup 0)
7238                                       (match_dup 7))
7239                            (match_dup 8)))])]
7240   "
7241 {
7242   build_mask64_2_operands (operands[2], &operands[5]);
7243 }")
7244
7245 (define_expand "iordi3"
7246   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7247         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
7248                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7249   "TARGET_POWERPC64"
7250   "
7251 {
7252   if (non_logical_cint_operand (operands[2], DImode))
7253     {
7254       HOST_WIDE_INT value;
7255       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7256                  ? operands[0] : gen_reg_rtx (DImode));
7257
7258       if (GET_CODE (operands[2]) == CONST_INT)
7259         {
7260           value = INTVAL (operands[2]);
7261           emit_insn (gen_iordi3 (tmp, operands[1],
7262                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7263         }
7264       else
7265         {
7266           value = CONST_DOUBLE_LOW (operands[2]);
7267           emit_insn (gen_iordi3 (tmp, operands[1],
7268                                  immed_double_const (value
7269                                                      & (~ (HOST_WIDE_INT) 0xffff),
7270                                                      0, DImode)));
7271         }
7272
7273       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7274       DONE;
7275     }
7276 }")
7277
7278 (define_expand "xordi3"
7279   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7280         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
7281                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7282   "TARGET_POWERPC64"
7283   "
7284 {
7285   if (non_logical_cint_operand (operands[2], DImode))
7286     {
7287       HOST_WIDE_INT value;
7288       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7289                  ? operands[0] : gen_reg_rtx (DImode));
7290
7291       if (GET_CODE (operands[2]) == CONST_INT)
7292         {
7293           value = INTVAL (operands[2]);
7294           emit_insn (gen_xordi3 (tmp, operands[1],
7295                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7296         }
7297       else
7298         {
7299           value = CONST_DOUBLE_LOW (operands[2]);
7300           emit_insn (gen_xordi3 (tmp, operands[1],
7301                                  immed_double_const (value
7302                                                      & (~ (HOST_WIDE_INT) 0xffff),
7303                                                      0, DImode)));
7304         }
7305
7306       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7307       DONE;
7308     }
7309 }")
7310
7311 (define_insn "*booldi3_internal1"
7312   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
7313         (match_operator:DI 3 "boolean_or_operator"
7314          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
7315           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
7316   "TARGET_POWERPC64"
7317   "@
7318    %q3 %0,%1,%2
7319    %q3i %0,%1,%b2
7320    %q3is %0,%1,%u2")
7321
7322 (define_insn "*booldi3_internal2"
7323   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7324         (compare:CC (match_operator:DI 4 "boolean_or_operator"
7325          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7326           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7327          (const_int 0)))
7328    (clobber (match_scratch:DI 3 "=r,r"))]
7329   "TARGET_64BIT"
7330   "@
7331    %q4. %3,%1,%2
7332    #"
7333   [(set_attr "type" "compare")
7334    (set_attr "length" "4,8")])
7335
7336 (define_split
7337   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7338         (compare:CC (match_operator:DI 4 "boolean_operator"
7339          [(match_operand:DI 1 "gpc_reg_operand" "")
7340           (match_operand:DI 2 "gpc_reg_operand" "")])
7341          (const_int 0)))
7342    (clobber (match_scratch:DI 3 ""))]
7343   "TARGET_POWERPC64 && reload_completed"
7344   [(set (match_dup 3) (match_dup 4))
7345    (set (match_dup 0)
7346         (compare:CC (match_dup 3)
7347                     (const_int 0)))]
7348   "")
7349
7350 (define_insn "*booldi3_internal3"
7351   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7352         (compare:CC (match_operator:DI 4 "boolean_operator"
7353          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7354           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7355          (const_int 0)))
7356    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7357         (match_dup 4))]
7358   "TARGET_64BIT"
7359   "@
7360    %q4. %0,%1,%2
7361    #"
7362   [(set_attr "type" "compare")
7363    (set_attr "length" "4,8")])
7364
7365 (define_split
7366   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7367         (compare:CC (match_operator:DI 4 "boolean_operator"
7368          [(match_operand:DI 1 "gpc_reg_operand" "")
7369           (match_operand:DI 2 "gpc_reg_operand" "")])
7370          (const_int 0)))
7371    (set (match_operand:DI 0 "gpc_reg_operand" "")
7372         (match_dup 4))]
7373   "TARGET_POWERPC64 && reload_completed"
7374   [(set (match_dup 0) (match_dup 4))
7375    (set (match_dup 3)
7376         (compare:CC (match_dup 0)
7377                     (const_int 0)))]
7378   "")
7379
7380 ;; Split a logical operation that we can't do in one insn into two insns,
7381 ;; each of which does one 16-bit part.  This is used by combine.
7382
7383 (define_split
7384   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7385         (match_operator:DI 3 "boolean_or_operator"
7386          [(match_operand:DI 1 "gpc_reg_operand" "")
7387           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
7388   "TARGET_POWERPC64"
7389   [(set (match_dup 0) (match_dup 4))
7390    (set (match_dup 0) (match_dup 5))]
7391 "
7392 {
7393   rtx i3,i4;
7394
7395   if (GET_CODE (operands[2]) == CONST_DOUBLE)
7396     {
7397       HOST_WIDE_INT value = CONST_DOUBLE_LOW (operands[2]);
7398       i3 = immed_double_const (value & (~ (HOST_WIDE_INT) 0xffff),
7399                                         0, DImode);
7400       i4 = GEN_INT (value & 0xffff);
7401     }
7402   else
7403     {
7404       i3 = GEN_INT (INTVAL (operands[2])
7405                              & (~ (HOST_WIDE_INT) 0xffff));
7406       i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
7407     }
7408   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7409                                 operands[1], i3);
7410   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7411                                 operands[0], i4);
7412 }")
7413
7414 (define_insn "*boolcdi3_internal1"
7415   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7416         (match_operator:DI 3 "boolean_operator"
7417          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7418           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
7419   "TARGET_POWERPC64"
7420   "%q3 %0,%2,%1")
7421
7422 (define_insn "*boolcdi3_internal2"
7423   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7424         (compare:CC (match_operator:DI 4 "boolean_operator"
7425          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7426           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7427          (const_int 0)))
7428    (clobber (match_scratch:DI 3 "=r,r"))]
7429   "TARGET_64BIT"
7430   "@
7431    %q4. %3,%2,%1
7432    #"
7433   [(set_attr "type" "compare")
7434    (set_attr "length" "4,8")])
7435
7436 (define_split
7437   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7438         (compare:CC (match_operator:DI 4 "boolean_operator"
7439          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7440           (match_operand:DI 2 "gpc_reg_operand" "")])
7441          (const_int 0)))
7442    (clobber (match_scratch:DI 3 ""))]
7443   "TARGET_POWERPC64 && reload_completed"
7444   [(set (match_dup 3) (match_dup 4))
7445    (set (match_dup 0)
7446         (compare:CC (match_dup 3)
7447                     (const_int 0)))]
7448   "")
7449
7450 (define_insn "*boolcdi3_internal3"
7451   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7452         (compare:CC (match_operator:DI 4 "boolean_operator"
7453          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7454           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7455          (const_int 0)))
7456    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7457         (match_dup 4))]
7458   "TARGET_64BIT"
7459   "@
7460    %q4. %0,%2,%1
7461    #"
7462   [(set_attr "type" "compare")
7463    (set_attr "length" "4,8")])
7464
7465 (define_split
7466   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7467         (compare:CC (match_operator:DI 4 "boolean_operator"
7468          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7469           (match_operand:DI 2 "gpc_reg_operand" "")])
7470          (const_int 0)))
7471    (set (match_operand:DI 0 "gpc_reg_operand" "")
7472         (match_dup 4))]
7473   "TARGET_POWERPC64 && reload_completed"
7474   [(set (match_dup 0) (match_dup 4))
7475    (set (match_dup 3)
7476         (compare:CC (match_dup 0)
7477                     (const_int 0)))]
7478   "")
7479
7480 (define_insn "*boolccdi3_internal1"
7481   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7482         (match_operator:DI 3 "boolean_operator"
7483          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7484           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
7485   "TARGET_POWERPC64"
7486   "%q3 %0,%1,%2")
7487
7488 (define_insn "*boolccdi3_internal2"
7489   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7490         (compare:CC (match_operator:DI 4 "boolean_operator"
7491          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7492           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7493          (const_int 0)))
7494    (clobber (match_scratch:DI 3 "=r,r"))]
7495   "TARGET_64BIT"
7496   "@
7497    %q4. %3,%1,%2
7498    #"
7499   [(set_attr "type" "compare")
7500    (set_attr "length" "4,8")])
7501
7502 (define_split
7503   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7504         (compare:CC (match_operator:DI 4 "boolean_operator"
7505          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7506           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7507          (const_int 0)))
7508    (clobber (match_scratch:DI 3 ""))]
7509   "TARGET_POWERPC64 && reload_completed"
7510   [(set (match_dup 3) (match_dup 4))
7511    (set (match_dup 0)
7512         (compare:CC (match_dup 3)
7513                     (const_int 0)))]
7514   "")
7515
7516 (define_insn "*boolccdi3_internal3"
7517   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7518         (compare:CC (match_operator:DI 4 "boolean_operator"
7519          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7520           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7521          (const_int 0)))
7522    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7523         (match_dup 4))]
7524   "TARGET_64BIT"
7525   "@
7526    %q4. %0,%1,%2
7527    #"
7528   [(set_attr "type" "compare")
7529    (set_attr "length" "4,8")])
7530
7531 (define_split
7532   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7533         (compare:CC (match_operator:DI 4 "boolean_operator"
7534          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7535           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7536          (const_int 0)))
7537    (set (match_operand:DI 0 "gpc_reg_operand" "")
7538         (match_dup 4))]
7539   "TARGET_POWERPC64 && reload_completed"
7540   [(set (match_dup 0) (match_dup 4))
7541    (set (match_dup 3)
7542         (compare:CC (match_dup 0)
7543                     (const_int 0)))]
7544   "")
7545 \f
7546 ;; Now define ways of moving data around.
7547
7548 ;; Elf specific ways of loading addresses for non-PIC code.
7549 ;; The output of this could be r0, but we make a very strong
7550 ;; preference for a base register because it will usually
7551 ;; be needed there.
7552 (define_insn "elf_high"
7553   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
7554         (high:SI (match_operand 1 "" "")))]
7555   "TARGET_ELF && ! TARGET_64BIT"
7556   "{liu|lis} %0,%1@ha")
7557
7558 (define_insn "elf_low"
7559   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
7560         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
7561                    (match_operand 2 "" "")))]
7562    "TARGET_ELF && ! TARGET_64BIT"
7563    "@
7564     {cal|la} %0,%2@l(%1)
7565     {ai|addic} %0,%1,%K2")
7566
7567 ;; Mach-O PIC trickery.
7568 (define_insn "macho_high"
7569   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
7570         (high:SI (match_operand 1 "" "")))]
7571   "TARGET_MACHO && ! TARGET_64BIT"
7572   "{liu|lis} %0,ha16(%1)")
7573
7574 (define_insn "macho_low"
7575   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
7576         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
7577                    (match_operand 2 "" "")))]
7578    "TARGET_MACHO && ! TARGET_64BIT"
7579    "@
7580     {cal %0,%a2@l(%1)|la %0,lo16(%2)(%1)}
7581     {cal %0,%a2@l(%1)|addic %0,%1,lo16(%2)}")
7582
7583 ;; Set up a register with a value from the GOT table
7584
7585 (define_expand "movsi_got"
7586   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7587         (unspec:SI [(match_operand:SI 1 "got_operand" "")
7588                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
7589   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7590   "
7591 {
7592   if (GET_CODE (operands[1]) == CONST)
7593     {
7594       rtx offset = const0_rtx;
7595       HOST_WIDE_INT value;
7596
7597       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
7598       value = INTVAL (offset);
7599       if (value != 0)
7600         {
7601           rtx tmp = (no_new_pseudos ? operands[0] : gen_reg_rtx (Pmode));
7602           emit_insn (gen_movsi_got (tmp, operands[1]));
7603           emit_insn (gen_addsi3 (operands[0], tmp, offset));
7604           DONE;
7605         }
7606     }
7607
7608   operands[2] = rs6000_got_register (operands[1]);
7609 }")
7610
7611 (define_insn "*movsi_got_internal"
7612   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7613         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7614                     (match_operand:SI 2 "gpc_reg_operand" "b")]
7615                    UNSPEC_MOVSI_GOT))]
7616   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7617   "{l|lwz} %0,%a1@got(%2)"
7618   [(set_attr "type" "load")])
7619
7620 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
7621 ;; didn't get allocated to a hard register.
7622 (define_split
7623   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7624         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7625                     (match_operand:SI 2 "memory_operand" "")]
7626                    UNSPEC_MOVSI_GOT))]
7627   "DEFAULT_ABI == ABI_V4
7628     && flag_pic == 1
7629     && (reload_in_progress || reload_completed)"
7630   [(set (match_dup 0) (match_dup 2))
7631    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
7632                                  UNSPEC_MOVSI_GOT))]
7633   "")
7634
7635 ;; For SI, we special-case integers that can't be loaded in one insn.  We
7636 ;; do the load 16-bits at a time.  We could do this by loading from memory,
7637 ;; and this is even supposed to be faster, but it is simpler not to get
7638 ;; integers in the TOC.
7639 (define_expand "movsi"
7640   [(set (match_operand:SI 0 "general_operand" "")
7641         (match_operand:SI 1 "any_operand" ""))]
7642   ""
7643   "{ rs6000_emit_move (operands[0], operands[1], SImode); DONE; }")
7644
7645 (define_insn "movsi_low"
7646   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7647         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7648                            (match_operand 2 "" ""))))]
7649   "TARGET_MACHO && ! TARGET_64BIT"
7650   "{l|lwz} %0,lo16(%2)(%1)"
7651   [(set_attr "type" "load")
7652    (set_attr "length" "4")])
7653
7654 (define_insn "movsi_low_st"
7655   [(set (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7656                            (match_operand 2 "" "")))
7657         (match_operand:SI 0 "gpc_reg_operand" "r"))]
7658   "TARGET_MACHO && ! TARGET_64BIT"
7659   "{st|stw} %0,lo16(%2)(%1)"
7660   [(set_attr "type" "store")
7661    (set_attr "length" "4")])
7662
7663 (define_insn "movdf_low"
7664   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,!r")
7665         (mem:DF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
7666                            (match_operand 2 "" ""))))]
7667   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
7668   "*
7669 {
7670   switch (which_alternative)
7671     {
7672       case 0:
7673         return \"lfd %0,lo16(%2)(%1)\";
7674       case 1:
7675         {
7676           rtx operands2[4];
7677           operands2[0] = operands[0];
7678           operands2[1] = operands[1];
7679           operands2[2] = operands[2];
7680           if (TARGET_POWERPC64 && TARGET_32BIT)
7681             /* Note, old assemblers didn't support relocation here.  */
7682             return \"ld %0,lo16(%2)(%1)\";
7683           else
7684           {
7685             operands2[3] = gen_rtx_REG (SImode, RS6000_PIC_OFFSET_TABLE_REGNUM);
7686             output_asm_insn (\"{l|lwz} %0,lo16(%2)(%1)\", operands);
7687 #if TARGET_MACHO
7688             if (MACHO_DYNAMIC_NO_PIC_P)
7689               output_asm_insn (\"{liu|lis} %L0,ha16(%2+4)\", operands);
7690             else
7691             /* We cannot rely on ha16(low half)==ha16(high half), alas,
7692                although in practice it almost always is.  */
7693             output_asm_insn (\"{cau|addis} %L0,%3,ha16(%2+4)\", operands2);
7694 #endif
7695             return (\"{l|lwz} %L0,lo16(%2+4)(%L0)\");
7696           }
7697         }
7698       default:
7699         abort();
7700     }
7701 }"
7702   [(set_attr "type" "load")
7703    (set_attr "length" "4,12")])
7704
7705 (define_insn "movdf_low_st"
7706   [(set (mem:DF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7707                            (match_operand 2 "" "")))
7708         (match_operand:DF 0 "gpc_reg_operand" "f"))]
7709   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
7710   "stfd %0,lo16(%2)(%1)"
7711   [(set_attr "type" "store")
7712    (set_attr "length" "4")])
7713
7714 (define_insn "movsf_low"
7715   [(set (match_operand:SF 0 "gpc_reg_operand" "=f,!r")
7716         (mem:SF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
7717                            (match_operand 2 "" ""))))]
7718   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
7719   "@
7720    lfs %0,lo16(%2)(%1)
7721    {l|lwz} %0,lo16(%2)(%1)"
7722   [(set_attr "type" "load")
7723    (set_attr "length" "4")])
7724
7725 (define_insn "movsf_low_st"
7726   [(set (mem:SF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
7727                            (match_operand 2 "" "")))
7728         (match_operand:SF 0 "gpc_reg_operand" "f,!r"))]
7729   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
7730   "@
7731    stfs %0,lo16(%2)(%1)
7732    {st|stw} %0,lo16(%2)(%1)"
7733   [(set_attr "type" "store")
7734    (set_attr "length" "4")])
7735
7736 (define_insn "*movsi_internal1"
7737   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h")
7738         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0"))]
7739   "gpc_reg_operand (operands[0], SImode)
7740    || gpc_reg_operand (operands[1], SImode)"
7741   "@
7742    mr %0,%1
7743    {cal|la} %0,%a1
7744    {l%U1%X1|lwz%U1%X1} %0,%1
7745    {st%U0%X0|stw%U0%X0} %1,%0
7746    {lil|li} %0,%1
7747    {liu|lis} %0,%v1
7748    #
7749    {cal|la} %0,%a1
7750    mf%1 %0
7751    mt%0 %1
7752    mt%0 %1
7753    mt%0 %1
7754    {cror 0,0,0|nop}"
7755   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*")
7756    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
7757
7758 ;; Split a load of a large constant into the appropriate two-insn
7759 ;; sequence.
7760
7761 (define_split
7762   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7763         (match_operand:SI 1 "const_int_operand" ""))]
7764   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
7765    && (INTVAL (operands[1]) & 0xffff) != 0"
7766   [(set (match_dup 0)
7767         (match_dup 2))
7768    (set (match_dup 0)
7769         (ior:SI (match_dup 0)
7770                 (match_dup 3)))]
7771   "
7772 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
7773
7774   if (tem == operands[0])
7775     DONE;
7776   else
7777     FAIL;
7778 }")
7779
7780 (define_insn "*movsi_internal2"
7781   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
7782         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "0,r,r")
7783                     (const_int 0)))
7784    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
7785   "TARGET_32BIT"
7786   "@
7787    {cmpi|cmpwi} %2,%0,0
7788    mr. %0,%1
7789    #"
7790   [(set_attr "type" "cmp,compare,cmp")
7791    (set_attr "length" "4,4,8")])
7792
7793 (define_split
7794   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
7795         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
7796                     (const_int 0)))
7797    (set (match_operand:SI 0 "gpc_reg_operand" "") (match_dup 1))]
7798   "TARGET_32BIT && reload_completed"
7799   [(set (match_dup 0) (match_dup 1))
7800    (set (match_dup 2)
7801         (compare:CC (match_dup 0)
7802                     (const_int 0)))]
7803   "")
7804 \f
7805 (define_expand "movhi"
7806   [(set (match_operand:HI 0 "general_operand" "")
7807         (match_operand:HI 1 "any_operand" ""))]
7808   ""
7809   "{ rs6000_emit_move (operands[0], operands[1], HImode); DONE; }")
7810
7811 (define_insn "*movhi_internal"
7812   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7813         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7814   "gpc_reg_operand (operands[0], HImode)
7815    || gpc_reg_operand (operands[1], HImode)"
7816   "@
7817    mr %0,%1
7818    lhz%U1%X1 %0,%1
7819    sth%U0%X0 %1,%0
7820    {lil|li} %0,%w1
7821    mf%1 %0
7822    mt%0 %1
7823    mt%0 %1
7824    {cror 0,0,0|nop}"
7825   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7826
7827 (define_expand "movqi"
7828   [(set (match_operand:QI 0 "general_operand" "")
7829         (match_operand:QI 1 "any_operand" ""))]
7830   ""
7831   "{ rs6000_emit_move (operands[0], operands[1], QImode); DONE; }")
7832
7833 (define_insn "*movqi_internal"
7834   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7835         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7836   "gpc_reg_operand (operands[0], QImode)
7837    || gpc_reg_operand (operands[1], QImode)"
7838   "@
7839    mr %0,%1
7840    lbz%U1%X1 %0,%1
7841    stb%U0%X0 %1,%0
7842    {lil|li} %0,%1
7843    mf%1 %0
7844    mt%0 %1
7845    mt%0 %1
7846    {cror 0,0,0|nop}"
7847   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7848 \f
7849 ;; Here is how to move condition codes around.  When we store CC data in
7850 ;; an integer register or memory, we store just the high-order 4 bits.
7851 ;; This lets us not shift in the most common case of CR0.
7852 (define_expand "movcc"
7853   [(set (match_operand:CC 0 "nonimmediate_operand" "")
7854         (match_operand:CC 1 "nonimmediate_operand" ""))]
7855   ""
7856   "")
7857
7858 (define_insn "*movcc_internal1"
7859   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,r,r,r,r,q,cl,r,m")
7860         (match_operand:CC 1 "nonimmediate_operand" "y,r,r,x,y,r,h,r,r,m,r"))]
7861   "register_operand (operands[0], CCmode)
7862    || register_operand (operands[1], CCmode)"
7863   "@
7864    mcrf %0,%1
7865    mtcrf 128,%1
7866    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
7867    mfcr %0%Q1
7868    mfcr %0%Q1\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
7869    mr %0,%1
7870    mf%1 %0
7871    mt%0 %1
7872    mt%0 %1
7873    {l%U1%X1|lwz%U1%X1} %0,%1
7874    {st%U0%U1|stw%U0%U1} %1,%0"
7875   [(set (attr "type")
7876      (cond [(eq_attr "alternative" "0")
7877                 (const_string "cr_logical")
7878             (eq_attr "alternative" "1,2")
7879                 (const_string "mtcr")
7880             (eq_attr "alternative" "5,7")
7881                 (const_string "integer")
7882             (eq_attr "alternative" "6")
7883                 (const_string "mfjmpr")
7884             (eq_attr "alternative" "8")
7885                 (const_string "mtjmpr")
7886             (eq_attr "alternative" "9")
7887                 (const_string "load")
7888             (eq_attr "alternative" "10")
7889                 (const_string "store")
7890             (ne (symbol_ref "TARGET_MFCRF") (const_int 0))
7891                 (const_string "mfcrf")
7892            ]
7893         (const_string "mfcr")))
7894    (set_attr "length" "4,4,12,4,8,4,4,4,4,4,4")])
7895 \f
7896 ;; For floating-point, we normally deal with the floating-point registers
7897 ;; unless -msoft-float is used.  The sole exception is that parameter passing
7898 ;; can produce floating-point values in fixed-point registers.  Unless the
7899 ;; value is a simple constant or already in memory, we deal with this by
7900 ;; allocating memory and copying the value explicitly via that memory location.
7901 (define_expand "movsf"
7902   [(set (match_operand:SF 0 "nonimmediate_operand" "")
7903         (match_operand:SF 1 "any_operand" ""))]
7904   ""
7905   "{ rs6000_emit_move (operands[0], operands[1], SFmode); DONE; }")
7906
7907 (define_split
7908   [(set (match_operand:SF 0 "gpc_reg_operand" "")
7909         (match_operand:SF 1 "const_double_operand" ""))]
7910   "reload_completed
7911    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7912        || (GET_CODE (operands[0]) == SUBREG
7913            && GET_CODE (SUBREG_REG (operands[0])) == REG
7914            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7915   [(set (match_dup 2) (match_dup 3))]
7916   "
7917 {
7918   long l;
7919   REAL_VALUE_TYPE rv;
7920
7921   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7922   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
7923
7924   if (! TARGET_POWERPC64)
7925     operands[2] = operand_subword (operands[0], 0, 0, SFmode);
7926   else
7927     operands[2] = gen_lowpart (SImode, operands[0]);
7928
7929   operands[3] = gen_int_mode (l, SImode);
7930 }")
7931
7932 (define_insn "*movsf_hardfloat"
7933   [(set (match_operand:SF 0 "nonimmediate_operand" "=!r,!r,m,f,f,m,!cl,!q,!r,!h,!r,!r")
7934         (match_operand:SF 1 "input_operand" "r,m,r,f,m,f,r,r,h,0,G,Fn"))]
7935   "(gpc_reg_operand (operands[0], SFmode)
7936    || gpc_reg_operand (operands[1], SFmode))
7937    && (TARGET_HARD_FLOAT && TARGET_FPRS)"
7938   "@
7939    mr %0,%1
7940    {l%U1%X1|lwz%U1%X1} %0,%1
7941    {st%U0%X0|stw%U0%X0} %1,%0
7942    fmr %0,%1
7943    lfs%U1%X1 %0,%1
7944    stfs%U0%X0 %1,%0
7945    mt%0 %1
7946    mt%0 %1
7947    mf%1 %0
7948    {cror 0,0,0|nop}
7949    #
7950    #"
7951   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,mtjmpr,*,*,*,*")
7952    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,8")])
7953
7954 (define_insn "*movsf_softfloat"
7955   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,cl,q,r,r,m,r,r,r,r,r,*h")
7956         (match_operand:SF 1 "input_operand" "r,r,r,h,m,r,I,L,R,G,Fn,0"))]
7957   "(gpc_reg_operand (operands[0], SFmode)
7958    || gpc_reg_operand (operands[1], SFmode))
7959    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
7960   "@
7961    mr %0,%1
7962    mt%0 %1
7963    mt%0 %1
7964    mf%1 %0
7965    {l%U1%X1|lwz%U1%X1} %0,%1
7966    {st%U0%X0|stw%U0%X0} %1,%0
7967    {lil|li} %0,%1
7968    {liu|lis} %0,%v1
7969    {cal|la} %0,%a1
7970    #
7971    #
7972    {cror 0,0,0|nop}"
7973   [(set_attr "type" "*,mtjmpr,*,*,load,store,*,*,*,*,*,*")
7974    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,4")])
7975
7976 \f
7977 (define_expand "movdf"
7978   [(set (match_operand:DF 0 "nonimmediate_operand" "")
7979         (match_operand:DF 1 "any_operand" ""))]
7980   ""
7981   "{ rs6000_emit_move (operands[0], operands[1], DFmode); DONE; }")
7982
7983 (define_split
7984   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7985         (match_operand:DF 1 "const_int_operand" ""))]
7986   "! TARGET_POWERPC64 && reload_completed
7987    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7988        || (GET_CODE (operands[0]) == SUBREG
7989            && GET_CODE (SUBREG_REG (operands[0])) == REG
7990            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7991   [(set (match_dup 2) (match_dup 4))
7992    (set (match_dup 3) (match_dup 1))]
7993   "
7994 {
7995   int endian = (WORDS_BIG_ENDIAN == 0);
7996   HOST_WIDE_INT value = INTVAL (operands[1]);
7997
7998   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
7999   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
8000 #if HOST_BITS_PER_WIDE_INT == 32
8001   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8002 #else
8003   operands[4] = GEN_INT (value >> 32);
8004   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8005 #endif
8006 }")
8007
8008 (define_split
8009   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8010         (match_operand:DF 1 "const_double_operand" ""))]
8011   "! TARGET_POWERPC64 && reload_completed
8012    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8013        || (GET_CODE (operands[0]) == SUBREG
8014            && GET_CODE (SUBREG_REG (operands[0])) == REG
8015            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8016   [(set (match_dup 2) (match_dup 4))
8017    (set (match_dup 3) (match_dup 5))]
8018   "
8019 {
8020   int endian = (WORDS_BIG_ENDIAN == 0);
8021   long l[2];
8022   REAL_VALUE_TYPE rv;
8023
8024   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8025   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8026
8027   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
8028   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
8029   operands[4] = gen_int_mode (l[endian], SImode);
8030   operands[5] = gen_int_mode (l[1 - endian], SImode);
8031 }")
8032
8033 (define_split
8034   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8035         (match_operand:DF 1 "easy_fp_constant" ""))]
8036   "TARGET_POWERPC64 && reload_completed
8037    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8038        || (GET_CODE (operands[0]) == SUBREG
8039            && GET_CODE (SUBREG_REG (operands[0])) == REG
8040            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8041   [(set (match_dup 2) (match_dup 3))]
8042   "
8043 {
8044   int endian = (WORDS_BIG_ENDIAN == 0);
8045   long l[2];
8046   REAL_VALUE_TYPE rv;
8047 #if HOST_BITS_PER_WIDE_INT >= 64
8048   HOST_WIDE_INT val;
8049 #endif
8050
8051   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8052   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8053
8054   operands[2] = gen_lowpart (DImode, operands[0]);
8055   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
8056 #if HOST_BITS_PER_WIDE_INT >= 64
8057   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
8058          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
8059
8060   operands[3] = gen_int_mode (val, DImode);
8061 #else
8062   operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
8063 #endif
8064 }")
8065
8066 ;; Don't have reload use general registers to load a constant.  First,
8067 ;; it might not work if the output operand is the equivalent of
8068 ;; a non-offsettable memref, but also it is less efficient than loading
8069 ;; the constant into an FP register, since it will probably be used there.
8070 ;; The "??" is a kludge until we can figure out a more reasonable way
8071 ;; of handling these non-offsettable values.
8072 (define_insn "*movdf_hardfloat32"
8073   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,m,f,f,m,!r,!r,!r")
8074         (match_operand:DF 1 "input_operand" "r,m,r,f,m,f,G,H,F"))]
8075   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8076    && (gpc_reg_operand (operands[0], DFmode)
8077        || gpc_reg_operand (operands[1], DFmode))"
8078   "*
8079 {
8080   switch (which_alternative)
8081     {
8082     default:
8083       abort ();
8084     case 0:
8085       /* We normally copy the low-numbered register first.  However, if
8086          the first register operand 0 is the same as the second register
8087          of operand 1, we must copy in the opposite order.  */
8088       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8089         return \"mr %L0,%L1\;mr %0,%1\";
8090       else
8091         return \"mr %0,%1\;mr %L0,%L1\";
8092     case 1:
8093       if (offsettable_memref_p (operands[1])
8094           || (GET_CODE (operands[1]) == MEM
8095               && (GET_CODE (XEXP (operands[1], 0)) == LO_SUM
8096                   || GET_CODE (XEXP (operands[1], 0)) == PRE_INC
8097                   || GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)))
8098         {
8099           /* If the low-address word is used in the address, we must load
8100              it last.  Otherwise, load it first.  Note that we cannot have
8101              auto-increment in that case since the address register is
8102              known to be dead.  */
8103           if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8104                                  operands[1], 0))
8105             return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8106           else
8107             return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8108         }
8109       else
8110         {
8111           rtx addreg;
8112
8113           addreg = find_addr_reg (XEXP (operands[1], 0));
8114           if (refers_to_regno_p (REGNO (operands[0]),
8115                                  REGNO (operands[0]) + 1,
8116                                  operands[1], 0))
8117             {
8118               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8119               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
8120               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8121               return \"{lx|lwzx} %0,%1\";
8122             }
8123           else
8124             {
8125               output_asm_insn (\"{lx|lwzx} %0,%1\", operands);
8126               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8127               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
8128               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8129               return \"\";
8130             }
8131         }
8132     case 2:
8133       if (offsettable_memref_p (operands[0])
8134           || (GET_CODE (operands[0]) == MEM
8135               && (GET_CODE (XEXP (operands[0], 0)) == LO_SUM
8136                   || GET_CODE (XEXP (operands[0], 0)) == PRE_INC
8137                   || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)))
8138         return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8139       else
8140         {
8141           rtx addreg;
8142
8143           addreg = find_addr_reg (XEXP (operands[0], 0));
8144           output_asm_insn (\"{stx|stwx} %1,%0\", operands);
8145           output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8146           output_asm_insn (\"{stx|stwx} %L1,%0\", operands);
8147           output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8148           return \"\";
8149         }
8150     case 3:
8151       return \"fmr %0,%1\";
8152     case 4:
8153       return \"lfd%U1%X1 %0,%1\";
8154     case 5:
8155       return \"stfd%U0%X0 %1,%0\";
8156     case 6:
8157     case 7:
8158     case 8:
8159       return \"#\";
8160     }
8161 }"
8162   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,*,*")
8163    (set_attr "length" "8,16,16,4,4,4,8,12,16")])
8164
8165 (define_insn "*movdf_softfloat32"
8166   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
8167         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F"))]
8168   "! TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8169    && (gpc_reg_operand (operands[0], DFmode)
8170        || gpc_reg_operand (operands[1], DFmode))"
8171   "*
8172 {
8173   switch (which_alternative)
8174     {
8175     default:
8176       abort ();
8177     case 0:
8178       /* We normally copy the low-numbered register first.  However, if
8179          the first register operand 0 is the same as the second register of
8180          operand 1, we must copy in the opposite order.  */
8181       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8182         return \"mr %L0,%L1\;mr %0,%1\";
8183       else
8184         return \"mr %0,%1\;mr %L0,%L1\";
8185     case 1:
8186       /* If the low-address word is used in the address, we must load
8187          it last.  Otherwise, load it first.  Note that we cannot have
8188          auto-increment in that case since the address register is
8189          known to be dead.  */
8190       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8191                              operands[1], 0))
8192         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8193       else
8194         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8195     case 2:
8196       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8197     case 3:
8198     case 4:
8199     case 5:
8200       return \"#\";
8201     }
8202 }"
8203   [(set_attr "type" "*,load,store,*,*,*")
8204    (set_attr "length" "8,8,8,8,12,16")])
8205
8206 ; ld/std require word-aligned displacements -> 'Y' constraint.
8207 ; List Y->r and r->Y before r->r for reload.
8208 (define_insn "*movdf_hardfloat64"
8209   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,!r,f,f,m,!cl,!r,!h,!r,!r,!r")
8210         (match_operand:DF 1 "input_operand" "r,Y,r,f,m,f,r,h,0,G,H,F"))]
8211   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8212    && (gpc_reg_operand (operands[0], DFmode)
8213        || gpc_reg_operand (operands[1], DFmode))"
8214   "@
8215    std%U0%X0 %1,%0
8216    ld%U1%X1 %0,%1
8217    mr %0,%1
8218    fmr %0,%1
8219    lfd%U1%X1 %0,%1
8220    stfd%U0%X0 %1,%0
8221    mt%0 %1
8222    mf%1 %0
8223    {cror 0,0,0|nop}
8224    #
8225    #
8226    #"
8227   [(set_attr "type" "*,load,store,fp,fpload,fpstore,mtjmpr,*,*,*,*,*")
8228    (set_attr "length" "4,4,4,4,4,4,4,4,4,8,12,16")])
8229
8230 (define_insn "*movdf_softfloat64"
8231   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,Y,r,cl,r,r,r,r,*h")
8232         (match_operand:DF 1 "input_operand" "Y,r,r,r,h,G,H,F,0"))]
8233   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8234    && (gpc_reg_operand (operands[0], DFmode)
8235        || gpc_reg_operand (operands[1], DFmode))"
8236   "@
8237    ld%U1%X1 %0,%1
8238    std%U0%X0 %1,%0
8239    mr %0,%1
8240    mt%0 %1
8241    mf%1 %0
8242    #
8243    #
8244    #
8245    {cror 0,0,0|nop}"
8246   [(set_attr "type" "load,store,*,*,*,*,*,*,*")
8247    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
8248 \f
8249 (define_expand "movtf"
8250   [(set (match_operand:TF 0 "general_operand" "")
8251         (match_operand:TF 1 "any_operand" ""))]
8252   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8253    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8254   "{ rs6000_emit_move (operands[0], operands[1], TFmode); DONE; }")
8255
8256 ; It's important to list the o->f and f->o moves before f->f because
8257 ; otherwise reload, given m->f, will try to pick f->f and reload it,
8258 ; which doesn't make progress.
8259 (define_insn_and_split "*movtf_internal"
8260   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,f,rm,r")
8261         (match_operand:TF 1 "input_operand"         "f,o,f,r,mGHF"))]
8262   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8263    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
8264    && (gpc_reg_operand (operands[0], TFmode)
8265        || gpc_reg_operand (operands[1], TFmode))"
8266   "#"
8267   "&& reload_completed"
8268   [(pc)]
8269 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
8270   [(set_attr "length" "8,8,8,20,20")])
8271
8272 (define_expand "extenddftf2"
8273   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
8274                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
8275               (use (match_dup 2))])]
8276   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8277    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8278 {
8279   operands[2] = CONST0_RTX (DFmode);
8280 })
8281
8282 (define_insn_and_split "*extenddftf2_internal"
8283   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,&f,r")
8284        (float_extend:TF (match_operand:DF 1 "input_operand" "fr,mf,mf,rmGHF")))
8285    (use (match_operand:DF 2 "input_operand" "rf,m,f,n"))]
8286   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8287    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8288   "#"
8289   "&& reload_completed"
8290   [(pc)]
8291 {
8292   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8293   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8294   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
8295                   operands[1]);
8296   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
8297                   operands[2]);
8298   DONE;
8299 })
8300
8301 (define_expand "extendsftf2"
8302   [(set (match_operand:TF 0 "nonimmediate_operand" "")
8303         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
8304   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8305    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8306 {
8307   rtx tmp = gen_reg_rtx (DFmode);
8308   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
8309   emit_insn (gen_extenddftf2 (operands[0], tmp));
8310   DONE;
8311 })
8312
8313 (define_insn "trunctfdf2"
8314   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8315         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8316   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8317    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8318   "fadd %0,%1,%L1"
8319   [(set_attr "type" "fp")
8320    (set_attr "length" "4")])
8321
8322 (define_insn_and_split "trunctfsf2"
8323   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
8324         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "f")))
8325    (clobber (match_scratch:DF 2 "=f"))]
8326   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8327    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8328   "#"
8329   "&& reload_completed"
8330   [(set (match_dup 2)
8331         (float_truncate:DF (match_dup 1)))
8332    (set (match_dup 0)
8333         (float_truncate:SF (match_dup 2)))]
8334   "")
8335
8336 (define_expand "floatsitf2"
8337   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8338         (float:TF (match_operand:SI 1 "gpc_reg_operand" "r")))]
8339   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8340    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8341 {
8342   rtx tmp = gen_reg_rtx (DFmode);
8343   expand_float (tmp, operands[1], false);
8344   emit_insn (gen_extenddftf2 (operands[0], tmp));
8345   DONE;
8346 })
8347
8348 ; fadd, but rounding towards zero.
8349 ; This is probably not the optimal code sequence.
8350 (define_insn "fix_trunc_helper"
8351   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8352         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "f")]
8353                    UNSPEC_FIX_TRUNC_TF))
8354    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&f"))]
8355   "TARGET_HARD_FLOAT && TARGET_FPRS"
8356   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
8357   [(set_attr "type" "fp")
8358    (set_attr "length" "20")])
8359
8360 (define_expand "fix_trunctfsi2"
8361   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
8362                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
8363               (clobber (match_dup 2))
8364               (clobber (match_dup 3))
8365               (clobber (match_dup 4))
8366               (clobber (match_dup 5))])]
8367   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8368    && (TARGET_POWER2 || TARGET_POWERPC)
8369    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8370 {
8371   operands[2] = gen_reg_rtx (DFmode);
8372   operands[3] = gen_reg_rtx (DFmode);
8373   operands[4] = gen_reg_rtx (DImode);
8374   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
8375 })
8376
8377 (define_insn_and_split "*fix_trunctfsi2_internal"
8378   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8379         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "f")))
8380    (clobber (match_operand:DF 2 "gpc_reg_operand" "=f"))
8381    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&f"))
8382    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))
8383    (clobber (match_operand:DI 5 "memory_operand" "=o"))]
8384   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8385    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8386   "#"
8387   "&& reload_completed"
8388   [(pc)]
8389 {
8390   rtx lowword;
8391   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
8392
8393   if (GET_CODE (operands[5]) != MEM)
8394     abort();
8395   lowword = XEXP (operands[5], 0);
8396   if (WORDS_BIG_ENDIAN)
8397     lowword = plus_constant (lowword, 4);
8398
8399   emit_insn (gen_fctiwz (operands[4], operands[2]));
8400   emit_move_insn (operands[5], operands[4]);
8401   emit_move_insn (operands[0], gen_rtx_MEM (SImode, lowword));
8402   DONE;
8403 })
8404
8405 (define_insn "negtf2"
8406   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8407         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8408   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8409    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8410   "*
8411 {
8412   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8413     return \"fneg %L0,%L1\;fneg %0,%1\";
8414   else
8415     return \"fneg %0,%1\;fneg %L0,%L1\";
8416 }"
8417   [(set_attr "type" "fp")
8418    (set_attr "length" "8")])
8419
8420 (define_expand "abstf2"
8421   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8422         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8423   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8424    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8425   "
8426 {
8427   rtx label = gen_label_rtx ();
8428   emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
8429   emit_label (label);
8430   DONE;
8431 }")
8432
8433 (define_expand "abstf2_internal"
8434   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8435         (match_operand:TF 1 "gpc_reg_operand" "f"))
8436    (set (match_dup 3) (match_dup 5))
8437    (set (match_dup 5) (abs:DF (match_dup 5)))
8438    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
8439    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
8440                            (label_ref (match_operand 2 "" ""))
8441                            (pc)))
8442    (set (match_dup 6) (neg:DF (match_dup 6)))]
8443   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8444    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8445   "
8446 {
8447   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8448   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8449   operands[3] = gen_reg_rtx (DFmode);
8450   operands[4] = gen_reg_rtx (CCFPmode);
8451   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
8452   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
8453 }")
8454 \f
8455 ;; Next come the multi-word integer load and store and the load and store
8456 ;; multiple insns.
8457 (define_expand "movdi"
8458   [(set (match_operand:DI 0 "general_operand" "")
8459         (match_operand:DI 1 "any_operand" ""))]
8460   ""
8461   "{ rs6000_emit_move (operands[0], operands[1], DImode); DONE; }")
8462
8463 (define_insn "*movdi_internal32"
8464   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,f,f,m,r,r,r,r,r")
8465         (match_operand:DI 1 "input_operand" "r,m,r,f,m,f,IJK,n,G,H,F"))]
8466   "! TARGET_POWERPC64
8467    && (gpc_reg_operand (operands[0], DImode)
8468        || gpc_reg_operand (operands[1], DImode))"
8469   "*
8470 {
8471   switch (which_alternative)
8472     {
8473     default:
8474       abort ();
8475     case 0:
8476     case 1:
8477     case 2:
8478       return \"#\";
8479     case 3:
8480       return \"fmr %0,%1\";
8481     case 4:
8482       return \"lfd%U1%X1 %0,%1\";
8483     case 5:
8484       return \"stfd%U0%X0 %1,%0\";
8485     case 6:
8486     case 7:
8487     case 8:
8488     case 9:
8489     case 10:
8490       return \"#\";
8491     }
8492 }"
8493   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,*,*,*,*")])
8494
8495 (define_split
8496   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8497         (match_operand:DI 1 "const_int_operand" ""))]
8498   "! TARGET_POWERPC64 && reload_completed"
8499   [(set (match_dup 2) (match_dup 4))
8500    (set (match_dup 3) (match_dup 1))]
8501   "
8502 {
8503   HOST_WIDE_INT value = INTVAL (operands[1]);
8504   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8505                                        DImode);
8506   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8507                                        DImode);
8508 #if HOST_BITS_PER_WIDE_INT == 32
8509   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8510 #else
8511   operands[4] = GEN_INT (value >> 32);
8512   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8513 #endif
8514 }")
8515
8516 (define_split
8517   [(set (match_operand:DI 0 "nonimmediate_operand" "")
8518         (match_operand:DI 1 "input_operand" ""))]
8519   "reload_completed && !TARGET_POWERPC64
8520    && gpr_or_gpr_p (operands[0], operands[1])"
8521   [(pc)]
8522 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8523
8524 (define_split
8525   [(set (match_operand:TI 0 "gpc_reg_operand" "")
8526         (match_operand:TI 1 "const_double_operand" ""))]
8527   "TARGET_POWERPC64"
8528   [(set (match_dup 2) (match_dup 4))
8529    (set (match_dup 3) (match_dup 5))]
8530   "
8531 {
8532   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8533                                        TImode);
8534   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8535                                        TImode);
8536   if (GET_CODE (operands[1]) == CONST_DOUBLE)
8537     {
8538       operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
8539       operands[5] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
8540     }
8541   else if (GET_CODE (operands[1]) == CONST_INT)
8542     {
8543       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
8544       operands[5] = operands[1];
8545     }
8546   else
8547     FAIL;
8548 }")
8549
8550 (define_insn "*movdi_internal64"
8551   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,?f,f,m,r,*h,*h")
8552         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,f,m,f,*h,r,0"))]
8553   "TARGET_POWERPC64
8554    && (gpc_reg_operand (operands[0], DImode)
8555        || gpc_reg_operand (operands[1], DImode))"
8556   "@
8557    mr %0,%1
8558    ld%U1%X1 %0,%1
8559    std%U0%X0 %1,%0
8560    li %0,%1
8561    lis %0,%v1
8562    #
8563    {cal|la} %0,%a1
8564    fmr %0,%1
8565    lfd%U1%X1 %0,%1
8566    stfd%U0%X0 %1,%0
8567    mf%1 %0
8568    mt%0 %1
8569    {cror 0,0,0|nop}"
8570   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*")
8571    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4")])
8572
8573 ;; immediate value valid for a single instruction hiding in a const_double
8574 (define_insn ""
8575   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8576         (match_operand:DI 1 "const_double_operand" "F"))]
8577   "HOST_BITS_PER_WIDE_INT == 32 && TARGET_POWERPC64
8578    && GET_CODE (operands[1]) == CONST_DOUBLE
8579    && num_insns_constant (operands[1], DImode) == 1"
8580   "*
8581 {
8582   return ((unsigned HOST_WIDE_INT)
8583           (CONST_DOUBLE_LOW (operands[1]) + 0x8000) < 0x10000)
8584          ? \"li %0,%1\" : \"lis %0,%v1\";
8585 }")
8586
8587 ;; Generate all one-bits and clear left or right.
8588 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
8589 (define_split
8590   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8591         (match_operand:DI 1 "mask64_operand" ""))]
8592   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8593   [(set (match_dup 0) (const_int -1))
8594    (set (match_dup 0)
8595         (and:DI (rotate:DI (match_dup 0)
8596                            (const_int 0))
8597                 (match_dup 1)))]
8598   "")
8599
8600 ;; Split a load of a large constant into the appropriate five-instruction
8601 ;; sequence.  Handle anything in a constant number of insns.
8602 ;; When non-easy constants can go in the TOC, this should use
8603 ;; easy_fp_constant predicate.
8604 (define_split
8605   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8606         (match_operand:DI 1 "const_int_operand" ""))]
8607   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8608   [(set (match_dup 0) (match_dup 2))
8609    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8610   "
8611 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8612
8613   if (tem == operands[0])
8614     DONE;
8615   else
8616     FAIL;
8617 }")
8618
8619 (define_split
8620   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8621         (match_operand:DI 1 "const_double_operand" ""))]
8622   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8623   [(set (match_dup 0) (match_dup 2))
8624    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8625   "
8626 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8627
8628   if (tem == operands[0])
8629     DONE;
8630   else
8631     FAIL;
8632 }")
8633
8634 (define_insn "*movdi_internal2"
8635   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
8636         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "0,r,r")
8637                     (const_int 0)))
8638    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
8639   "TARGET_64BIT"
8640   "@
8641    cmpdi %2,%0,0
8642    mr. %0,%1
8643    #"
8644   [(set_attr "type" "cmp,compare,cmp")
8645    (set_attr "length" "4,4,8")])
8646
8647 (define_split
8648   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
8649         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "")
8650                     (const_int 0)))
8651    (set (match_operand:DI 0 "gpc_reg_operand" "") (match_dup 1))]
8652   "TARGET_POWERPC64 && reload_completed"
8653   [(set (match_dup 0) (match_dup 1))
8654    (set (match_dup 2)
8655         (compare:CC (match_dup 0)
8656                     (const_int 0)))]
8657   "")
8658 \f
8659 ;; TImode is similar, except that we usually want to compute the address into
8660 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
8661 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
8662 (define_expand "movti"
8663   [(parallel [(set (match_operand:TI 0 "general_operand" "")
8664                    (match_operand:TI 1 "general_operand" ""))
8665               (clobber (scratch:SI))])]
8666   ""
8667   "{ rs6000_emit_move (operands[0], operands[1], TImode); DONE; }")
8668
8669 ;; We say that MQ is clobbered in the last alternative because the first
8670 ;; alternative would never get used otherwise since it would need a reload
8671 ;; while the 2nd alternative would not.  We put memory cases first so they
8672 ;; are preferred.  Otherwise, we'd try to reload the output instead of
8673 ;; giving the SCRATCH mq.
8674
8675 (define_insn "*movti_power"
8676   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r")
8677         (match_operand:TI 1 "reg_or_mem_operand" "r,r,r,Q,m"))
8678    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X"))]
8679   "TARGET_POWER && ! TARGET_POWERPC64
8680    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8681   "*
8682 {
8683   switch (which_alternative)
8684     {
8685     default:
8686       abort ();
8687
8688     case 0:
8689       if (TARGET_STRING)
8690         return \"{stsi|stswi} %1,%P0,16\";
8691     case 1:
8692     case 2:
8693       return \"#\";
8694     case 3:
8695       /* If the address is not used in the output, we can use lsi.  Otherwise,
8696          fall through to generating four loads.  */
8697       if (TARGET_STRING
8698           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8699         return \"{lsi|lswi} %0,%P1,16\";
8700       /* ... fall through ...  */
8701     case 4:
8702       return \"#\";
8703     }
8704 }"
8705   [(set_attr "type" "store,store,*,load,load")])
8706
8707 (define_insn "*movti_string"
8708   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r")
8709         (match_operand:TI 1 "reg_or_mem_operand" "r,r,r,Q,m"))]
8710   "! TARGET_POWER && ! TARGET_POWERPC64
8711    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8712   "*
8713 {
8714   switch (which_alternative)
8715     {
8716     default:
8717       abort ();
8718     case 0:
8719       if (TARGET_STRING)
8720         return \"{stsi|stswi} %1,%P0,16\";
8721     case 1:
8722     case 2:
8723       return \"#\";
8724     case 3:
8725       /* If the address is not used in the output, we can use lsi.  Otherwise,
8726          fall through to generating four loads.  */
8727       if (TARGET_STRING
8728           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8729         return \"{lsi|lswi} %0,%P1,16\";
8730       /* ... fall through ...  */
8731     case 4:
8732       return \"#\";
8733     }
8734 }"
8735   [(set_attr "type" "store,store,*,load,load")])
8736
8737 (define_insn "*movti_ppc64"
8738   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,m,r")
8739         (match_operand:TI 1 "input_operand" "r,r,o"))]
8740   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
8741    || gpc_reg_operand (operands[1], TImode))"
8742   "@
8743    #
8744    #
8745    #"
8746   [(set_attr "type" "*,load,store")])
8747
8748 (define_split
8749   [(set (match_operand:TI 0 "nonimmediate_operand" "")
8750         (match_operand:TI 1 "input_operand" ""))]
8751   "reload_completed
8752    && gpr_or_gpr_p (operands[0], operands[1])"
8753   [(pc)]
8754 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8755 \f
8756 (define_expand "load_multiple"
8757   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8758                           (match_operand:SI 1 "" ""))
8759                      (use (match_operand:SI 2 "" ""))])]
8760   "TARGET_STRING && !TARGET_POWERPC64"
8761   "
8762 {
8763   int regno;
8764   int count;
8765   rtx op1;
8766   int i;
8767
8768   /* Support only loading a constant number of fixed-point registers from
8769      memory and only bother with this if more than two; the machine
8770      doesn't support more than eight.  */
8771   if (GET_CODE (operands[2]) != CONST_INT
8772       || INTVAL (operands[2]) <= 2
8773       || INTVAL (operands[2]) > 8
8774       || GET_CODE (operands[1]) != MEM
8775       || GET_CODE (operands[0]) != REG
8776       || REGNO (operands[0]) >= 32)
8777     FAIL;
8778
8779   count = INTVAL (operands[2]);
8780   regno = REGNO (operands[0]);
8781
8782   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
8783   op1 = replace_equiv_address (operands[1],
8784                                force_reg (SImode, XEXP (operands[1], 0)));
8785
8786   for (i = 0; i < count; i++)
8787     XVECEXP (operands[3], 0, i)
8788       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
8789                      adjust_address_nv (op1, SImode, i * 4));
8790 }")
8791
8792 (define_insn "*ldmsi8"
8793   [(match_parallel 0 "load_multiple_operation"
8794     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8795           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8796      (set (match_operand:SI 3 "gpc_reg_operand" "")
8797           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8798      (set (match_operand:SI 4 "gpc_reg_operand" "")
8799           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8800      (set (match_operand:SI 5 "gpc_reg_operand" "")
8801           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8802      (set (match_operand:SI 6 "gpc_reg_operand" "")
8803           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8804      (set (match_operand:SI 7 "gpc_reg_operand" "")
8805           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8806      (set (match_operand:SI 8 "gpc_reg_operand" "")
8807           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
8808      (set (match_operand:SI 9 "gpc_reg_operand" "")
8809           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
8810   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
8811   "*
8812 { return rs6000_output_load_multiple (operands); }"
8813   [(set_attr "type" "load")
8814    (set_attr "length" "32")])
8815
8816 (define_insn "*ldmsi7"
8817   [(match_parallel 0 "load_multiple_operation"
8818     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8819           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8820      (set (match_operand:SI 3 "gpc_reg_operand" "")
8821           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8822      (set (match_operand:SI 4 "gpc_reg_operand" "")
8823           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8824      (set (match_operand:SI 5 "gpc_reg_operand" "")
8825           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8826      (set (match_operand:SI 6 "gpc_reg_operand" "")
8827           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8828      (set (match_operand:SI 7 "gpc_reg_operand" "")
8829           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8830      (set (match_operand:SI 8 "gpc_reg_operand" "")
8831           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
8832   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
8833   "*
8834 { return rs6000_output_load_multiple (operands); }"
8835   [(set_attr "type" "load")
8836    (set_attr "length" "32")])
8837
8838 (define_insn "*ldmsi6"
8839   [(match_parallel 0 "load_multiple_operation"
8840     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8841           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8842      (set (match_operand:SI 3 "gpc_reg_operand" "")
8843           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8844      (set (match_operand:SI 4 "gpc_reg_operand" "")
8845           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8846      (set (match_operand:SI 5 "gpc_reg_operand" "")
8847           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8848      (set (match_operand:SI 6 "gpc_reg_operand" "")
8849           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8850      (set (match_operand:SI 7 "gpc_reg_operand" "")
8851           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
8852   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
8853   "*
8854 { return rs6000_output_load_multiple (operands); }"
8855   [(set_attr "type" "load")
8856    (set_attr "length" "32")])
8857
8858 (define_insn "*ldmsi5"
8859   [(match_parallel 0 "load_multiple_operation"
8860     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8861           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8862      (set (match_operand:SI 3 "gpc_reg_operand" "")
8863           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8864      (set (match_operand:SI 4 "gpc_reg_operand" "")
8865           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8866      (set (match_operand:SI 5 "gpc_reg_operand" "")
8867           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8868      (set (match_operand:SI 6 "gpc_reg_operand" "")
8869           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
8870   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
8871   "*
8872 { return rs6000_output_load_multiple (operands); }"
8873   [(set_attr "type" "load")
8874    (set_attr "length" "32")])
8875
8876 (define_insn "*ldmsi4"
8877   [(match_parallel 0 "load_multiple_operation"
8878     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8879           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8880      (set (match_operand:SI 3 "gpc_reg_operand" "")
8881           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8882      (set (match_operand:SI 4 "gpc_reg_operand" "")
8883           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8884      (set (match_operand:SI 5 "gpc_reg_operand" "")
8885           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
8886   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
8887   "*
8888 { return rs6000_output_load_multiple (operands); }"
8889   [(set_attr "type" "load")
8890    (set_attr "length" "32")])
8891
8892 (define_insn "*ldmsi3"
8893   [(match_parallel 0 "load_multiple_operation"
8894     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8895           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8896      (set (match_operand:SI 3 "gpc_reg_operand" "")
8897           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8898      (set (match_operand:SI 4 "gpc_reg_operand" "")
8899           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
8900   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
8901   "*
8902 { return rs6000_output_load_multiple (operands); }"
8903   [(set_attr "type" "load")
8904    (set_attr "length" "32")])
8905
8906 (define_expand "store_multiple"
8907   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8908                           (match_operand:SI 1 "" ""))
8909                      (clobber (scratch:SI))
8910                      (use (match_operand:SI 2 "" ""))])]
8911   "TARGET_STRING && !TARGET_POWERPC64"
8912   "
8913 {
8914   int regno;
8915   int count;
8916   rtx to;
8917   rtx op0;
8918   int i;
8919
8920   /* Support only storing a constant number of fixed-point registers to
8921      memory and only bother with this if more than two; the machine
8922      doesn't support more than eight.  */
8923   if (GET_CODE (operands[2]) != CONST_INT
8924       || INTVAL (operands[2]) <= 2
8925       || INTVAL (operands[2]) > 8
8926       || GET_CODE (operands[0]) != MEM
8927       || GET_CODE (operands[1]) != REG
8928       || REGNO (operands[1]) >= 32)
8929     FAIL;
8930
8931   count = INTVAL (operands[2]);
8932   regno = REGNO (operands[1]);
8933
8934   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
8935   to = force_reg (SImode, XEXP (operands[0], 0));
8936   op0 = replace_equiv_address (operands[0], to);
8937
8938   XVECEXP (operands[3], 0, 0)
8939     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
8940   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
8941                                                  gen_rtx_SCRATCH (SImode));
8942
8943   for (i = 1; i < count; i++)
8944     XVECEXP (operands[3], 0, i + 1)
8945       = gen_rtx_SET (VOIDmode,
8946                      adjust_address_nv (op0, SImode, i * 4),
8947                      gen_rtx_REG (SImode, regno + i));
8948 }")
8949
8950 (define_insn "*store_multiple_power"
8951   [(match_parallel 0 "store_multiple_operation"
8952                    [(set (match_operand:SI 1 "indirect_operand" "=Q")
8953                          (match_operand:SI 2 "gpc_reg_operand" "r"))
8954                     (clobber (match_scratch:SI 3 "=q"))])]
8955   "TARGET_STRING && TARGET_POWER"
8956   "{stsi|stswi} %2,%P1,%O0"
8957   [(set_attr "type" "store")])
8958
8959 (define_insn "*stmsi8"
8960   [(match_parallel 0 "store_multiple_operation"
8961     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8962           (match_operand:SI 2 "gpc_reg_operand" "r"))
8963      (clobber (match_scratch:SI 3 "X"))
8964      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8965           (match_operand:SI 4 "gpc_reg_operand" "r"))
8966      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8967           (match_operand:SI 5 "gpc_reg_operand" "r"))
8968      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8969           (match_operand:SI 6 "gpc_reg_operand" "r"))
8970      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8971           (match_operand:SI 7 "gpc_reg_operand" "r"))
8972      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8973           (match_operand:SI 8 "gpc_reg_operand" "r"))
8974      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
8975           (match_operand:SI 9 "gpc_reg_operand" "r"))
8976      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
8977           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
8978   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 9"
8979   "{stsi|stswi} %2,%1,%O0"
8980   [(set_attr "type" "store")])
8981
8982 (define_insn "*stmsi7"
8983   [(match_parallel 0 "store_multiple_operation"
8984     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8985           (match_operand:SI 2 "gpc_reg_operand" "r"))
8986      (clobber (match_scratch:SI 3 "X"))
8987      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8988           (match_operand:SI 4 "gpc_reg_operand" "r"))
8989      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8990           (match_operand:SI 5 "gpc_reg_operand" "r"))
8991      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8992           (match_operand:SI 6 "gpc_reg_operand" "r"))
8993      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8994           (match_operand:SI 7 "gpc_reg_operand" "r"))
8995      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8996           (match_operand:SI 8 "gpc_reg_operand" "r"))
8997      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
8998           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
8999   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 8"
9000   "{stsi|stswi} %2,%1,%O0"
9001   [(set_attr "type" "store")])
9002
9003 (define_insn "*stmsi6"
9004   [(match_parallel 0 "store_multiple_operation"
9005     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9006           (match_operand:SI 2 "gpc_reg_operand" "r"))
9007      (clobber (match_scratch:SI 3 "X"))
9008      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9009           (match_operand:SI 4 "gpc_reg_operand" "r"))
9010      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9011           (match_operand:SI 5 "gpc_reg_operand" "r"))
9012      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9013           (match_operand:SI 6 "gpc_reg_operand" "r"))
9014      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9015           (match_operand:SI 7 "gpc_reg_operand" "r"))
9016      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9017           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
9018   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 7"
9019   "{stsi|stswi} %2,%1,%O0"
9020   [(set_attr "type" "store")])
9021
9022 (define_insn "*stmsi5"
9023   [(match_parallel 0 "store_multiple_operation"
9024     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9025           (match_operand:SI 2 "gpc_reg_operand" "r"))
9026      (clobber (match_scratch:SI 3 "X"))
9027      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9028           (match_operand:SI 4 "gpc_reg_operand" "r"))
9029      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9030           (match_operand:SI 5 "gpc_reg_operand" "r"))
9031      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9032           (match_operand:SI 6 "gpc_reg_operand" "r"))
9033      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9034           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
9035   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 6"
9036   "{stsi|stswi} %2,%1,%O0"
9037   [(set_attr "type" "store")])
9038
9039 (define_insn "*stmsi4"
9040   [(match_parallel 0 "store_multiple_operation"
9041     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9042           (match_operand:SI 2 "gpc_reg_operand" "r"))
9043      (clobber (match_scratch:SI 3 "X"))
9044      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9045           (match_operand:SI 4 "gpc_reg_operand" "r"))
9046      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9047           (match_operand:SI 5 "gpc_reg_operand" "r"))
9048      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9049           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
9050   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 5"
9051   "{stsi|stswi} %2,%1,%O0"
9052   [(set_attr "type" "store")])
9053
9054 (define_insn "*stmsi3"
9055   [(match_parallel 0 "store_multiple_operation"
9056     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9057           (match_operand:SI 2 "gpc_reg_operand" "r"))
9058      (clobber (match_scratch:SI 3 "X"))
9059      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9060           (match_operand:SI 4 "gpc_reg_operand" "r"))
9061      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9062           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
9063   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 4"
9064   "{stsi|stswi} %2,%1,%O0"
9065   [(set_attr "type" "store")])
9066 \f
9067 ;; String/block move insn.
9068 ;; Argument 0 is the destination
9069 ;; Argument 1 is the source
9070 ;; Argument 2 is the length
9071 ;; Argument 3 is the alignment
9072
9073 (define_expand "movstrsi"
9074   [(parallel [(set (match_operand:BLK 0 "" "")
9075                    (match_operand:BLK 1 "" ""))
9076               (use (match_operand:SI 2 "" ""))
9077               (use (match_operand:SI 3 "" ""))])]
9078   ""
9079   "
9080 {
9081   if (expand_block_move (operands))
9082     DONE;
9083   else
9084     FAIL;
9085 }")
9086
9087 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
9088 ;; register allocator doesn't have a clue about allocating 8 word registers.
9089 ;; rD/rS = r5 is preferred, efficient form.
9090 (define_expand "movstrsi_8reg"
9091   [(parallel [(set (match_operand 0 "" "")
9092                    (match_operand 1 "" ""))
9093               (use (match_operand 2 "" ""))
9094               (use (match_operand 3 "" ""))
9095               (clobber (reg:SI  5))
9096               (clobber (reg:SI  6))
9097               (clobber (reg:SI  7))
9098               (clobber (reg:SI  8))
9099               (clobber (reg:SI  9))
9100               (clobber (reg:SI 10))
9101               (clobber (reg:SI 11))
9102               (clobber (reg:SI 12))
9103               (clobber (match_scratch:SI 4 ""))])]
9104   "TARGET_STRING"
9105   "")
9106
9107 (define_insn ""
9108   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9109         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9110    (use (match_operand:SI 2 "immediate_operand" "i"))
9111    (use (match_operand:SI 3 "immediate_operand" "i"))
9112    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9113    (clobber (reg:SI  6))
9114    (clobber (reg:SI  7))
9115    (clobber (reg:SI  8))
9116    (clobber (reg:SI  9))
9117    (clobber (reg:SI 10))
9118    (clobber (reg:SI 11))
9119    (clobber (reg:SI 12))
9120    (clobber (match_scratch:SI 5 "=q"))]
9121   "TARGET_STRING && TARGET_POWER
9122    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9123        || INTVAL (operands[2]) == 0)
9124    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9125    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9126    && REGNO (operands[4]) == 5"
9127   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9128   [(set_attr "type" "load")
9129    (set_attr "length" "8")])
9130
9131 (define_insn ""
9132   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9133         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9134    (use (match_operand:SI 2 "immediate_operand" "i"))
9135    (use (match_operand:SI 3 "immediate_operand" "i"))
9136    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9137    (clobber (reg:SI  6))
9138    (clobber (reg:SI  7))
9139    (clobber (reg:SI  8))
9140    (clobber (reg:SI  9))
9141    (clobber (reg:SI 10))
9142    (clobber (reg:SI 11))
9143    (clobber (reg:SI 12))
9144    (clobber (match_scratch:SI 5 "X"))]
9145   "TARGET_STRING && ! TARGET_POWER
9146    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9147        || INTVAL (operands[2]) == 0)
9148    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9149    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9150    && REGNO (operands[4]) == 5"
9151   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9152   [(set_attr "type" "load")
9153    (set_attr "length" "8")])
9154
9155 (define_insn ""
9156   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9157         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9158    (use (match_operand:SI 2 "immediate_operand" "i"))
9159    (use (match_operand:SI 3 "immediate_operand" "i"))
9160    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9161    (clobber (reg:SI  6))
9162    (clobber (reg:SI  7))
9163    (clobber (reg:SI  8))
9164    (clobber (reg:SI  9))
9165    (clobber (reg:SI 10))
9166    (clobber (reg:SI 11))
9167    (clobber (reg:SI 12))
9168    (clobber (match_scratch:SI 5 "X"))]
9169   "TARGET_STRING && TARGET_POWERPC64
9170    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9171        || INTVAL (operands[2]) == 0)
9172    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9173    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9174    && REGNO (operands[4]) == 5"
9175   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9176   [(set_attr "type" "load")
9177    (set_attr "length" "8")])
9178
9179 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
9180 ;; register allocator doesn't have a clue about allocating 6 word registers.
9181 ;; rD/rS = r5 is preferred, efficient form.
9182 (define_expand "movstrsi_6reg"
9183   [(parallel [(set (match_operand 0 "" "")
9184                    (match_operand 1 "" ""))
9185               (use (match_operand 2 "" ""))
9186               (use (match_operand 3 "" ""))
9187               (clobber (reg:SI  5))
9188               (clobber (reg:SI  6))
9189               (clobber (reg:SI  7))
9190               (clobber (reg:SI  8))
9191               (clobber (reg:SI  9))
9192               (clobber (reg:SI 10))
9193               (clobber (match_scratch:SI 4 ""))])]
9194   "TARGET_STRING"
9195   "")
9196
9197 (define_insn ""
9198   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9199         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9200    (use (match_operand:SI 2 "immediate_operand" "i"))
9201    (use (match_operand:SI 3 "immediate_operand" "i"))
9202    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9203    (clobber (reg:SI  6))
9204    (clobber (reg:SI  7))
9205    (clobber (reg:SI  8))
9206    (clobber (reg:SI  9))
9207    (clobber (reg:SI 10))
9208    (clobber (match_scratch:SI 5 "=q"))]
9209   "TARGET_STRING && TARGET_POWER
9210    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
9211    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9212    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9213    && REGNO (operands[4]) == 5"
9214   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9215   [(set_attr "type" "load")
9216    (set_attr "length" "8")])
9217
9218 (define_insn ""
9219   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9220         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9221    (use (match_operand:SI 2 "immediate_operand" "i"))
9222    (use (match_operand:SI 3 "immediate_operand" "i"))
9223    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9224    (clobber (reg:SI  6))
9225    (clobber (reg:SI  7))
9226    (clobber (reg:SI  8))
9227    (clobber (reg:SI  9))
9228    (clobber (reg:SI 10))
9229    (clobber (match_scratch:SI 5 "X"))]
9230   "TARGET_STRING && ! TARGET_POWER
9231    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9232    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9233    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9234    && REGNO (operands[4]) == 5"
9235   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9236   [(set_attr "type" "load")
9237    (set_attr "length" "8")])
9238
9239 (define_insn ""
9240   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9241         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9242    (use (match_operand:SI 2 "immediate_operand" "i"))
9243    (use (match_operand:SI 3 "immediate_operand" "i"))
9244    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9245    (clobber (reg:SI  6))
9246    (clobber (reg:SI  7))
9247    (clobber (reg:SI  8))
9248    (clobber (reg:SI  9))
9249    (clobber (reg:SI 10))
9250    (clobber (match_scratch:SI 5 "X"))]
9251   "TARGET_STRING && TARGET_POWERPC64
9252    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9253    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9254    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9255    && REGNO (operands[4]) == 5"
9256   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9257   [(set_attr "type" "load")
9258    (set_attr "length" "8")])
9259
9260 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
9261 ;; problems with TImode.
9262 ;; rD/rS = r5 is preferred, efficient form.
9263 (define_expand "movstrsi_4reg"
9264   [(parallel [(set (match_operand 0 "" "")
9265                    (match_operand 1 "" ""))
9266               (use (match_operand 2 "" ""))
9267               (use (match_operand 3 "" ""))
9268               (clobber (reg:SI 5))
9269               (clobber (reg:SI 6))
9270               (clobber (reg:SI 7))
9271               (clobber (reg:SI 8))
9272               (clobber (match_scratch:SI 4 ""))])]
9273   "TARGET_STRING"
9274   "")
9275
9276 (define_insn ""
9277   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9278         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9279    (use (match_operand:SI 2 "immediate_operand" "i"))
9280    (use (match_operand:SI 3 "immediate_operand" "i"))
9281    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9282    (clobber (reg:SI 6))
9283    (clobber (reg:SI 7))
9284    (clobber (reg:SI 8))
9285    (clobber (match_scratch:SI 5 "=q"))]
9286   "TARGET_STRING && TARGET_POWER
9287    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9288    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9289    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9290    && REGNO (operands[4]) == 5"
9291   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9292   [(set_attr "type" "load")
9293    (set_attr "length" "8")])
9294
9295 (define_insn ""
9296   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9297         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9298    (use (match_operand:SI 2 "immediate_operand" "i"))
9299    (use (match_operand:SI 3 "immediate_operand" "i"))
9300    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9301    (clobber (reg:SI 6))
9302    (clobber (reg:SI 7))
9303    (clobber (reg:SI 8))
9304    (clobber (match_scratch:SI 5 "X"))]
9305   "TARGET_STRING && ! TARGET_POWER
9306    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9307    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9308    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9309    && REGNO (operands[4]) == 5"
9310   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9311   [(set_attr "type" "load")
9312    (set_attr "length" "8")])
9313
9314 (define_insn ""
9315   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9316         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9317    (use (match_operand:SI 2 "immediate_operand" "i"))
9318    (use (match_operand:SI 3 "immediate_operand" "i"))
9319    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9320    (clobber (reg:SI 6))
9321    (clobber (reg:SI 7))
9322    (clobber (reg:SI 8))
9323    (clobber (match_scratch:SI 5 "X"))]
9324   "TARGET_STRING && TARGET_POWERPC64
9325    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9326    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9327    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9328    && REGNO (operands[4]) == 5"
9329   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9330   [(set_attr "type" "load")
9331    (set_attr "length" "8")])
9332
9333 ;; Move up to 8 bytes at a time.
9334 (define_expand "movstrsi_2reg"
9335   [(parallel [(set (match_operand 0 "" "")
9336                    (match_operand 1 "" ""))
9337               (use (match_operand 2 "" ""))
9338               (use (match_operand 3 "" ""))
9339               (clobber (match_scratch:DI 4 ""))
9340               (clobber (match_scratch:SI 5 ""))])]
9341   "TARGET_STRING && ! TARGET_POWERPC64"
9342   "")
9343
9344 (define_insn ""
9345   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9346         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9347    (use (match_operand:SI 2 "immediate_operand" "i"))
9348    (use (match_operand:SI 3 "immediate_operand" "i"))
9349    (clobber (match_scratch:DI 4 "=&r"))
9350    (clobber (match_scratch:SI 5 "=q"))]
9351   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
9352    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9353   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9354   [(set_attr "type" "load")
9355    (set_attr "length" "8")])
9356
9357 (define_insn ""
9358   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9359         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9360    (use (match_operand:SI 2 "immediate_operand" "i"))
9361    (use (match_operand:SI 3 "immediate_operand" "i"))
9362    (clobber (match_scratch:DI 4 "=&r"))
9363    (clobber (match_scratch:SI 5 "X"))]
9364   "TARGET_STRING && ! TARGET_POWER && ! TARGET_POWERPC64
9365    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9366   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9367   [(set_attr "type" "load")
9368    (set_attr "length" "8")])
9369
9370 ;; Move up to 4 bytes at a time.
9371 (define_expand "movstrsi_1reg"
9372   [(parallel [(set (match_operand 0 "" "")
9373                    (match_operand 1 "" ""))
9374               (use (match_operand 2 "" ""))
9375               (use (match_operand 3 "" ""))
9376               (clobber (match_scratch:SI 4 ""))
9377               (clobber (match_scratch:SI 5 ""))])]
9378   "TARGET_STRING"
9379   "")
9380
9381 (define_insn ""
9382   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9383         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9384    (use (match_operand:SI 2 "immediate_operand" "i"))
9385    (use (match_operand:SI 3 "immediate_operand" "i"))
9386    (clobber (match_scratch:SI 4 "=&r"))
9387    (clobber (match_scratch:SI 5 "=q"))]
9388   "TARGET_STRING && TARGET_POWER
9389    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9390   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9391   [(set_attr "type" "load")
9392    (set_attr "length" "8")])
9393
9394 (define_insn ""
9395   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9396         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9397    (use (match_operand:SI 2 "immediate_operand" "i"))
9398    (use (match_operand:SI 3 "immediate_operand" "i"))
9399    (clobber (match_scratch:SI 4 "=&r"))
9400    (clobber (match_scratch:SI 5 "X"))]
9401   "TARGET_STRING && ! TARGET_POWER
9402    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9403   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9404   [(set_attr "type" "load")
9405    (set_attr "length" "8")])
9406
9407 (define_insn ""
9408   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9409         (mem:BLK (match_operand:DI 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 "X"))]
9414   "TARGET_STRING && TARGET_POWERPC64
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 \f
9421 ;; Define insns that do load or store with update.  Some of these we can
9422 ;; get by using pre-decrement or pre-increment, but the hardware can also
9423 ;; do cases where the increment is not the size of the object.
9424 ;;
9425 ;; In all these cases, we use operands 0 and 1 for the register being
9426 ;; incremented because those are the operands that local-alloc will
9427 ;; tie and these are the pair most likely to be tieable (and the ones
9428 ;; that will benefit the most).
9429
9430 (define_insn "*movdi_update1"
9431   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
9432         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9433                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
9434    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9435         (plus:DI (match_dup 1) (match_dup 2)))]
9436   "TARGET_POWERPC64 && TARGET_UPDATE"
9437   "@
9438    ldux %3,%0,%2
9439    ldu %3,%2(%0)"
9440   [(set_attr "type" "load_ux,load_u")])
9441
9442 (define_insn "movdi_update"
9443   [(set (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9444                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I")))
9445         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
9446    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9447         (plus:DI (match_dup 1) (match_dup 2)))]
9448   "TARGET_POWERPC64 && TARGET_UPDATE"
9449   "@
9450    stdux %3,%0,%2
9451    stdu %3,%2(%0)"
9452   [(set_attr "type" "store_ux,store_u")])
9453
9454 (define_insn "*movsi_update1"
9455   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9456         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9457                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9458    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9459         (plus:SI (match_dup 1) (match_dup 2)))]
9460   "TARGET_UPDATE"
9461   "@
9462    {lux|lwzux} %3,%0,%2
9463    {lu|lwzu} %3,%2(%0)"
9464   [(set_attr "type" "load_ux,load_u")])
9465
9466 (define_insn "*movsi_update2"
9467   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
9468         (sign_extend:DI
9469          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
9470                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
9471    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
9472         (plus:DI (match_dup 1) (match_dup 2)))]
9473   "TARGET_POWERPC64"
9474   "lwaux %3,%0,%2"
9475   [(set_attr "type" "load_ext_ux")])
9476
9477 (define_insn "movsi_update"
9478   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9479                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9480         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
9481    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9482         (plus:SI (match_dup 1) (match_dup 2)))]
9483   "TARGET_UPDATE"
9484   "@
9485    {stux|stwux} %3,%0,%2
9486    {stu|stwu} %3,%2(%0)"
9487   [(set_attr "type" "store_ux,store_u")])
9488
9489 (define_insn "*movhi_update1"
9490   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
9491         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9492                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9493    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9494         (plus:SI (match_dup 1) (match_dup 2)))]
9495   "TARGET_UPDATE"
9496   "@
9497    lhzux %3,%0,%2
9498    lhzu %3,%2(%0)"
9499   [(set_attr "type" "load_ux,load_u")])
9500
9501 (define_insn "*movhi_update2"
9502   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9503         (zero_extend:SI
9504          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9505                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9506    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9507         (plus:SI (match_dup 1) (match_dup 2)))]
9508   "TARGET_UPDATE"
9509   "@
9510    lhzux %3,%0,%2
9511    lhzu %3,%2(%0)"
9512   [(set_attr "type" "load_ux,load_u")])
9513
9514 (define_insn "*movhi_update3"
9515   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9516         (sign_extend:SI
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    lhaux %3,%0,%2
9524    lhau %3,%2(%0)"
9525   [(set_attr "type" "load_ext_ux,load_ext_u")])
9526
9527 (define_insn "*movhi_update4"
9528   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9529                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9530         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
9531    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9532         (plus:SI (match_dup 1) (match_dup 2)))]
9533   "TARGET_UPDATE"
9534   "@
9535    sthux %3,%0,%2
9536    sthu %3,%2(%0)"
9537   [(set_attr "type" "store_ux,store_u")])
9538
9539 (define_insn "*movqi_update1"
9540   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
9541         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9542                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9543    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9544         (plus:SI (match_dup 1) (match_dup 2)))]
9545   "TARGET_UPDATE"
9546   "@
9547    lbzux %3,%0,%2
9548    lbzu %3,%2(%0)"
9549   [(set_attr "type" "load_ux,load_u")])
9550
9551 (define_insn "*movqi_update2"
9552   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9553         (zero_extend:SI
9554          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9555                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9556    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9557         (plus:SI (match_dup 1) (match_dup 2)))]
9558   "TARGET_UPDATE"
9559   "@
9560    lbzux %3,%0,%2
9561    lbzu %3,%2(%0)"
9562   [(set_attr "type" "load_ux,load_u")])
9563
9564 (define_insn "*movqi_update3"
9565   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9566                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9567         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
9568    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9569         (plus:SI (match_dup 1) (match_dup 2)))]
9570   "TARGET_UPDATE"
9571   "@
9572    stbux %3,%0,%2
9573    stbu %3,%2(%0)"
9574   [(set_attr "type" "store_ux,store_u")])
9575
9576 (define_insn "*movsf_update1"
9577   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
9578         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9579                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9580    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9581         (plus:SI (match_dup 1) (match_dup 2)))]
9582   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9583   "@
9584    lfsux %3,%0,%2
9585    lfsu %3,%2(%0)"
9586   [(set_attr "type" "fpload_ux,fpload_u")])
9587
9588 (define_insn "*movsf_update2"
9589   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9590                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9591         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
9592    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9593         (plus:SI (match_dup 1) (match_dup 2)))]
9594   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9595   "@
9596    stfsux %3,%0,%2
9597    stfsu %3,%2(%0)"
9598   [(set_attr "type" "fpstore_ux,fpstore_u")])
9599
9600 (define_insn "*movsf_update3"
9601   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
9602         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9603                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9604    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9605         (plus:SI (match_dup 1) (match_dup 2)))]
9606   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9607   "@
9608    {lux|lwzux} %3,%0,%2
9609    {lu|lwzu} %3,%2(%0)"
9610   [(set_attr "type" "load_ux,load_u")])
9611
9612 (define_insn "*movsf_update4"
9613   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9614                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9615         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
9616    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9617         (plus:SI (match_dup 1) (match_dup 2)))]
9618   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9619   "@
9620    {stux|stwux} %3,%0,%2
9621    {stu|stwu} %3,%2(%0)"
9622   [(set_attr "type" "store_ux,store_u")])
9623
9624 (define_insn "*movdf_update1"
9625   [(set (match_operand:DF 3 "gpc_reg_operand" "=f,f")
9626         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9627                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9628    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9629         (plus:SI (match_dup 1) (match_dup 2)))]
9630   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9631   "@
9632    lfdux %3,%0,%2
9633    lfdu %3,%2(%0)"
9634   [(set_attr "type" "fpload_ux,fpload_u")])
9635
9636 (define_insn "*movdf_update2"
9637   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9638                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9639         (match_operand:DF 3 "gpc_reg_operand" "f,f"))
9640    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9641         (plus:SI (match_dup 1) (match_dup 2)))]
9642   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9643   "@
9644    stfdux %3,%0,%2
9645    stfdu %3,%2(%0)"
9646   [(set_attr "type" "fpstore_ux,fpstore_u")])
9647
9648 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
9649
9650 (define_insn "*lfq_power2"
9651   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
9652         (match_operand:TF 1 "memory_operand" ""))]
9653   "TARGET_POWER2
9654    && TARGET_HARD_FLOAT && TARGET_FPRS"
9655    "lfq%U1%X1 %0,%1")
9656
9657 (define_peephole2
9658   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9659         (match_operand:DF 1 "memory_operand" ""))
9660    (set (match_operand:DF 2 "gpc_reg_operand" "")
9661         (match_operand:DF 3 "memory_operand" ""))]
9662   "TARGET_POWER2
9663    && TARGET_HARD_FLOAT && TARGET_FPRS
9664    && registers_ok_for_quad_peep (operands[0], operands[2])
9665    && mems_ok_for_quad_peep (operands[1], operands[3])"
9666   [(set (match_dup 0)
9667         (match_dup 1))]
9668   "operands[1] = widen_memory_access (operands[1], TFmode, 0);
9669    operands[0] = gen_rtx_REG (TFmode, REGNO (operands[0]));")
9670
9671 (define_insn "*stfq_power2"
9672   [(set (match_operand:TF 0 "memory_operand" "")
9673         (match_operand:TF 1 "gpc_reg_operand" "f"))]
9674   "TARGET_POWER2
9675    && TARGET_HARD_FLOAT && TARGET_FPRS"
9676   "stfq%U0%X0 %1,%0")
9677
9678
9679 (define_peephole2
9680   [(set (match_operand:DF 0 "memory_operand" "")
9681         (match_operand:DF 1 "gpc_reg_operand" ""))
9682    (set (match_operand:DF 2 "memory_operand" "")
9683         (match_operand:DF 3 "gpc_reg_operand" ""))]
9684   "TARGET_POWER2
9685    && TARGET_HARD_FLOAT && TARGET_FPRS
9686    && registers_ok_for_quad_peep (operands[1], operands[3])
9687    && mems_ok_for_quad_peep (operands[0], operands[2])"
9688   [(set (match_dup 0)
9689         (match_dup 1))]
9690   "operands[0] = widen_memory_access (operands[0], TFmode, 0);
9691    operands[1] = gen_rtx_REG (TFmode, REGNO (operands[1]));")
9692 \f
9693 ;; TLS support.
9694
9695 ;; "b" output constraint here and on tls_ld to support tls linker optimization.
9696 (define_insn "tls_gd_32"
9697   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9698         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9699                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9700                    UNSPEC_TLSGD))]
9701   "HAVE_AS_TLS && !TARGET_64BIT"
9702   "addi %0,%1,%2@got@tlsgd")
9703
9704 (define_insn "tls_gd_64"
9705   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9706         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9707                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9708                    UNSPEC_TLSGD))]
9709   "HAVE_AS_TLS && TARGET_64BIT"
9710   "addi %0,%1,%2@got@tlsgd")
9711
9712 (define_insn "tls_ld_32"
9713   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9714         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")]
9715                    UNSPEC_TLSLD))]
9716   "HAVE_AS_TLS && !TARGET_64BIT"
9717   "addi %0,%1,%&@got@tlsld")
9718
9719 (define_insn "tls_ld_64"
9720   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9721         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")]
9722                    UNSPEC_TLSLD))]
9723   "HAVE_AS_TLS && TARGET_64BIT"
9724   "addi %0,%1,%&@got@tlsld")
9725
9726 (define_insn "tls_dtprel_32"
9727   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9728         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9729                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9730                    UNSPEC_TLSDTPREL))]
9731   "HAVE_AS_TLS && !TARGET_64BIT"
9732   "addi %0,%1,%2@dtprel")
9733
9734 (define_insn "tls_dtprel_64"
9735   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9736         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9737                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9738                    UNSPEC_TLSDTPREL))]
9739   "HAVE_AS_TLS && TARGET_64BIT"
9740   "addi %0,%1,%2@dtprel")
9741
9742 (define_insn "tls_dtprel_ha_32"
9743   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9744         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9745                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9746                    UNSPEC_TLSDTPRELHA))]
9747   "HAVE_AS_TLS && !TARGET_64BIT"
9748   "addis %0,%1,%2@dtprel@ha")
9749
9750 (define_insn "tls_dtprel_ha_64"
9751   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9752         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9753                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9754                    UNSPEC_TLSDTPRELHA))]
9755   "HAVE_AS_TLS && TARGET_64BIT"
9756   "addis %0,%1,%2@dtprel@ha")
9757
9758 (define_insn "tls_dtprel_lo_32"
9759   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9760         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9761                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9762                    UNSPEC_TLSDTPRELLO))]
9763   "HAVE_AS_TLS && !TARGET_64BIT"
9764   "addi %0,%1,%2@dtprel@l")
9765
9766 (define_insn "tls_dtprel_lo_64"
9767   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9768         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9769                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9770                    UNSPEC_TLSDTPRELLO))]
9771   "HAVE_AS_TLS && TARGET_64BIT"
9772   "addi %0,%1,%2@dtprel@l")
9773
9774 (define_insn "tls_got_dtprel_32"
9775   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9776         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9777                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9778                    UNSPEC_TLSGOTDTPREL))]
9779   "HAVE_AS_TLS && !TARGET_64BIT"
9780   "lwz %0,%2@got@dtprel(%1)")
9781
9782 (define_insn "tls_got_dtprel_64"
9783   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9784         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9785                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9786                    UNSPEC_TLSGOTDTPREL))]
9787   "HAVE_AS_TLS && TARGET_64BIT"
9788   "ld %0,%2@got@dtprel(%1)")
9789
9790 (define_insn "tls_tprel_32"
9791   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9792         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9793                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9794                    UNSPEC_TLSTPREL))]
9795   "HAVE_AS_TLS && !TARGET_64BIT"
9796   "addi %0,%1,%2@tprel")
9797
9798 (define_insn "tls_tprel_64"
9799   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9800         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9801                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9802                    UNSPEC_TLSTPREL))]
9803   "HAVE_AS_TLS && TARGET_64BIT"
9804   "addi %0,%1,%2@tprel")
9805
9806 (define_insn "tls_tprel_ha_32"
9807   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9808         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9809                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9810                    UNSPEC_TLSTPRELHA))]
9811   "HAVE_AS_TLS && !TARGET_64BIT"
9812   "addis %0,%1,%2@tprel@ha")
9813
9814 (define_insn "tls_tprel_ha_64"
9815   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9816         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9817                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9818                    UNSPEC_TLSTPRELHA))]
9819   "HAVE_AS_TLS && TARGET_64BIT"
9820   "addis %0,%1,%2@tprel@ha")
9821
9822 (define_insn "tls_tprel_lo_32"
9823   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9824         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9825                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9826                    UNSPEC_TLSTPRELLO))]
9827   "HAVE_AS_TLS && !TARGET_64BIT"
9828   "addi %0,%1,%2@tprel@l")
9829
9830 (define_insn "tls_tprel_lo_64"
9831   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9832         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9833                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9834                    UNSPEC_TLSTPRELLO))]
9835   "HAVE_AS_TLS && TARGET_64BIT"
9836   "addi %0,%1,%2@tprel@l")
9837
9838 ;; "b" output constraint here and on tls_tls input to support linker tls
9839 ;; optimization.  The linker may edit the instructions emitted by a
9840 ;; tls_got_tprel/tls_tls pair to addis,addi.
9841 (define_insn "tls_got_tprel_32"
9842   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9843         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9844                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9845                    UNSPEC_TLSGOTTPREL))]
9846   "HAVE_AS_TLS && !TARGET_64BIT"
9847   "lwz %0,%2@got@tprel(%1)")
9848
9849 (define_insn "tls_got_tprel_64"
9850   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9851         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9852                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9853                    UNSPEC_TLSGOTTPREL))]
9854   "HAVE_AS_TLS && TARGET_64BIT"
9855   "ld %0,%2@got@tprel(%1)")
9856
9857 (define_insn "tls_tls_32"
9858   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9859         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9860                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9861                    UNSPEC_TLSTLS))]
9862   "HAVE_AS_TLS && !TARGET_64BIT"
9863   "add %0,%1,%2@tls")
9864
9865 (define_insn "tls_tls_64"
9866   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9867         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9868                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9869                    UNSPEC_TLSTLS))]
9870   "HAVE_AS_TLS && TARGET_64BIT"
9871   "add %0,%1,%2@tls")
9872 \f
9873 ;; Next come insns related to the calling sequence.
9874 ;;
9875 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
9876 ;; We move the back-chain and decrement the stack pointer.
9877
9878 (define_expand "allocate_stack"
9879   [(set (match_operand 0 "gpc_reg_operand" "=r")
9880         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
9881    (set (reg 1)
9882         (minus (reg 1) (match_dup 1)))]
9883   ""
9884   "
9885 { rtx chain = gen_reg_rtx (Pmode);
9886   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
9887   rtx neg_op0;
9888
9889   emit_move_insn (chain, stack_bot);
9890
9891   /* Check stack bounds if necessary.  */
9892   if (current_function_limit_stack)
9893     {
9894       rtx available;
9895       available = expand_binop (Pmode, sub_optab,
9896                                 stack_pointer_rtx, stack_limit_rtx,
9897                                 NULL_RTX, 1, OPTAB_WIDEN);
9898       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
9899     }
9900
9901   if (GET_CODE (operands[1]) != CONST_INT
9902       || INTVAL (operands[1]) < -32767
9903       || INTVAL (operands[1]) > 32768)
9904     {
9905       neg_op0 = gen_reg_rtx (Pmode);
9906       if (TARGET_32BIT)
9907         emit_insn (gen_negsi2 (neg_op0, operands[1]));
9908       else
9909         emit_insn (gen_negdi2 (neg_op0, operands[1]));
9910     }
9911   else
9912     neg_op0 = GEN_INT (- INTVAL (operands[1]));
9913
9914   if (TARGET_UPDATE)
9915     emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update : gen_movdi_update))
9916                 (stack_pointer_rtx, stack_pointer_rtx, neg_op0, chain));
9917
9918   else
9919     {
9920       emit_insn ((* ((TARGET_32BIT) ? gen_addsi3 : gen_adddi3))
9921                  (stack_pointer_rtx, stack_pointer_rtx, neg_op0));
9922       emit_move_insn (gen_rtx_MEM (Pmode, stack_pointer_rtx), chain);
9923     }
9924
9925   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
9926   DONE;
9927 }")
9928
9929 ;; These patterns say how to save and restore the stack pointer.  We need not
9930 ;; save the stack pointer at function level since we are careful to
9931 ;; preserve the backchain.  At block level, we have to restore the backchain
9932 ;; when we restore the stack pointer.
9933 ;;
9934 ;; For nonlocal gotos, we must save both the stack pointer and its
9935 ;; backchain and restore both.  Note that in the nonlocal case, the
9936 ;; save area is a memory location.
9937
9938 (define_expand "save_stack_function"
9939   [(match_operand 0 "any_operand" "")
9940    (match_operand 1 "any_operand" "")]
9941   ""
9942   "DONE;")
9943
9944 (define_expand "restore_stack_function"
9945   [(match_operand 0 "any_operand" "")
9946    (match_operand 1 "any_operand" "")]
9947   ""
9948   "DONE;")
9949
9950 (define_expand "restore_stack_block"
9951   [(use (match_operand 0 "register_operand" ""))
9952    (set (match_dup 2) (match_dup 3))
9953    (set (match_dup 0) (match_operand 1 "register_operand" ""))
9954    (set (match_dup 3) (match_dup 2))]
9955   ""
9956   "
9957 {
9958   operands[2] = gen_reg_rtx (Pmode);
9959   operands[3] = gen_rtx_MEM (Pmode, operands[0]);
9960 }")
9961
9962 (define_expand "save_stack_nonlocal"
9963   [(match_operand 0 "memory_operand" "")
9964    (match_operand 1 "register_operand" "")]
9965   ""
9966   "
9967 {
9968   rtx temp = gen_reg_rtx (Pmode);
9969   int units_per_word = (TARGET_32BIT) ? 4 : 8;
9970
9971   /* Copy the backchain to the first word, sp to the second.  */
9972   emit_move_insn (temp, gen_rtx_MEM (Pmode, operands[1]));
9973   emit_move_insn (adjust_address_nv (operands[0], Pmode, 0), temp);
9974   emit_move_insn (adjust_address_nv (operands[0], Pmode, units_per_word),
9975                   operands[1]);
9976   DONE;
9977 }")
9978
9979 (define_expand "restore_stack_nonlocal"
9980   [(match_operand 0 "register_operand" "")
9981    (match_operand 1 "memory_operand" "")]
9982   ""
9983   "
9984 {
9985   rtx temp = gen_reg_rtx (Pmode);
9986   int units_per_word = (TARGET_32BIT) ? 4 : 8;
9987
9988   /* Restore the backchain from the first word, sp from the second.  */
9989   emit_move_insn (temp,
9990                   adjust_address_nv (operands[1], Pmode, 0));
9991   emit_move_insn (operands[0],
9992                   adjust_address_nv (operands[1], Pmode, units_per_word));
9993   emit_move_insn (gen_rtx_MEM (Pmode, operands[0]), temp);
9994   DONE;
9995 }")
9996 \f
9997 ;; TOC register handling.
9998
9999 ;; Code to initialize the TOC register...
10000
10001 (define_insn "load_toc_aix_si"
10002   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10003                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
10004               (use (reg:SI 2))])]
10005   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
10006   "*
10007 {
10008   char buf[30];
10009   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10010   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10011   operands[2] = gen_rtx_REG (Pmode, 2);
10012   return \"{l|lwz} %0,%1(%2)\";
10013 }"
10014   [(set_attr "type" "load")])
10015
10016 (define_insn "load_toc_aix_di"
10017   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10018                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
10019               (use (reg:DI 2))])]
10020   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
10021   "*
10022 {
10023   char buf[30];
10024 #ifdef TARGET_RELOCATABLE
10025   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
10026                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
10027 #else
10028   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10029 #endif
10030   if (TARGET_ELF)
10031     strcat (buf, \"@toc\");
10032   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10033   operands[2] = gen_rtx_REG (Pmode, 2);
10034   return \"ld %0,%1(%2)\";
10035 }"
10036   [(set_attr "type" "load")])
10037
10038 (define_insn "load_toc_v4_pic_si"
10039   [(set (match_operand:SI 0 "register_operand" "=l")
10040         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
10041   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
10042   "bl _GLOBAL_OFFSET_TABLE_@local-4"
10043   [(set_attr "type" "branch")
10044    (set_attr "length" "4")])
10045
10046 (define_insn "load_toc_v4_PIC_1"
10047   [(set (match_operand:SI 0 "register_operand" "=l")
10048         (match_operand:SI 1 "immediate_operand" "s"))
10049    (use (unspec [(match_dup 1)] UNSPEC_TOC))]
10050   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10051   "bcl 20,31,%1\\n%1:"
10052   [(set_attr "type" "branch")
10053    (set_attr "length" "4")])
10054
10055 (define_insn "load_toc_v4_PIC_1b"
10056   [(set (match_operand:SI 0 "register_operand" "=l")
10057         (match_operand:SI 1 "immediate_operand" "s"))
10058    (use (unspec [(match_dup 1) (match_operand 2 "immediate_operand" "s")]
10059                 UNSPEC_TOCPTR))]
10060   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10061   "bcl 20,31,%1+4\\n%1:\\n\\t.long %2-%1"
10062   [(set_attr "type" "branch")
10063    (set_attr "length" "8")])
10064
10065 (define_insn "load_toc_v4_PIC_2"
10066   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10067         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10068                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
10069                              (match_operand:SI 3 "immediate_operand" "s")))))]
10070   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10071   "{l|lwz} %0,%2-%3(%1)"
10072   [(set_attr "type" "load")])
10073
10074 (define_insn "load_macho_picbase"
10075   [(set (match_operand:SI 0 "register_operand" "=l")
10076         (unspec:SI [(match_operand:SI 1 "immediate_operand" "s")]
10077                    UNSPEC_LD_MPIC))]
10078   "(DEFAULT_ABI == ABI_DARWIN) && flag_pic"
10079   "bcl 20,31,%1\\n%1:"
10080   [(set_attr "type" "branch")
10081    (set_attr "length" "4")])
10082
10083 (define_insn "macho_correct_pic"
10084   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10085         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
10086                  (unspec:SI [(match_operand:SI 2 "immediate_operand" "s")
10087                              (match_operand:SI 3 "immediate_operand" "s")]
10088                             UNSPEC_MPIC_CORRECT)))]
10089   "DEFAULT_ABI == ABI_DARWIN"
10090   "addis %0,%1,ha16(%2-%3)\n\taddi %0,%0,lo16(%2-%3)"
10091   [(set_attr "length" "8")])
10092
10093 ;; If the TOC is shared over a translation unit, as happens with all
10094 ;; the kinds of PIC that we support, we need to restore the TOC
10095 ;; pointer only when jumping over units of translation.
10096 ;; On Darwin, we need to reload the picbase.
10097
10098 (define_expand "builtin_setjmp_receiver"
10099   [(use (label_ref (match_operand 0 "" "")))]
10100   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
10101    || (TARGET_TOC && TARGET_MINIMAL_TOC)
10102    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
10103   "
10104 {
10105 #if TARGET_MACHO
10106   if (DEFAULT_ABI == ABI_DARWIN)
10107     {
10108       const char *picbase = machopic_function_base_name ();
10109       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (picbase));
10110       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
10111       rtx tmplabrtx;
10112       char tmplab[20];
10113
10114       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
10115                                   CODE_LABEL_NUMBER (operands[0]));
10116       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
10117
10118       emit_insn (gen_load_macho_picbase (picreg, tmplabrtx));
10119       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
10120     }
10121   else
10122 #endif
10123     rs6000_emit_load_toc_table (FALSE);
10124   DONE;
10125 }")
10126 \f
10127 ;; A function pointer under AIX is a pointer to a data area whose first word
10128 ;; contains the actual address of the function, whose second word contains a
10129 ;; pointer to its TOC, and whose third word contains a value to place in the
10130 ;; static chain register (r11).  Note that if we load the static chain, our
10131 ;; "trampoline" need not have any executable code.
10132
10133 (define_expand "call_indirect_aix32"
10134   [(set (match_dup 2)
10135         (mem:SI (match_operand:SI 0 "gpc_reg_operand" "")))
10136    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10137         (reg:SI 2))
10138    (set (reg:SI 2)
10139         (mem:SI (plus:SI (match_dup 0)
10140                          (const_int 4))))
10141    (set (reg:SI 11)
10142         (mem:SI (plus:SI (match_dup 0)
10143                          (const_int 8))))
10144    (parallel [(call (mem:SI (match_dup 2))
10145                     (match_operand 1 "" ""))
10146               (use (reg:SI 2))
10147               (use (reg:SI 11))
10148               (set (reg:SI 2)
10149                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10150               (clobber (scratch:SI))])]
10151   "TARGET_32BIT"
10152   "
10153 { operands[2] = gen_reg_rtx (SImode); }")
10154
10155 (define_expand "call_indirect_aix64"
10156   [(set (match_dup 2)
10157         (mem:DI (match_operand:DI 0 "gpc_reg_operand" "")))
10158    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10159         (reg:DI 2))
10160    (set (reg:DI 2)
10161         (mem:DI (plus:DI (match_dup 0)
10162                          (const_int 8))))
10163    (set (reg:DI 11)
10164         (mem:DI (plus:DI (match_dup 0)
10165                          (const_int 16))))
10166    (parallel [(call (mem:SI (match_dup 2))
10167                     (match_operand 1 "" ""))
10168               (use (reg:DI 2))
10169               (use (reg:DI 11))
10170               (set (reg:DI 2)
10171                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10172               (clobber (scratch:SI))])]
10173   "TARGET_64BIT"
10174   "
10175 { operands[2] = gen_reg_rtx (DImode); }")
10176
10177 (define_expand "call_value_indirect_aix32"
10178   [(set (match_dup 3)
10179         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
10180    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10181         (reg:SI 2))
10182    (set (reg:SI 2)
10183         (mem:SI (plus:SI (match_dup 1)
10184                          (const_int 4))))
10185    (set (reg:SI 11)
10186         (mem:SI (plus:SI (match_dup 1)
10187                          (const_int 8))))
10188    (parallel [(set (match_operand 0 "" "")
10189                    (call (mem:SI (match_dup 3))
10190                          (match_operand 2 "" "")))
10191               (use (reg:SI 2))
10192               (use (reg:SI 11))
10193               (set (reg:SI 2)
10194                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10195               (clobber (scratch:SI))])]
10196   "TARGET_32BIT"
10197   "
10198 { operands[3] = gen_reg_rtx (SImode); }")
10199
10200 (define_expand "call_value_indirect_aix64"
10201   [(set (match_dup 3)
10202         (mem:DI (match_operand:DI 1 "gpc_reg_operand" "")))
10203    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10204         (reg:DI 2))
10205    (set (reg:DI 2)
10206         (mem:DI (plus:DI (match_dup 1)
10207                          (const_int 8))))
10208    (set (reg:DI 11)
10209         (mem:DI (plus:DI (match_dup 1)
10210                          (const_int 16))))
10211    (parallel [(set (match_operand 0 "" "")
10212                    (call (mem:SI (match_dup 3))
10213                          (match_operand 2 "" "")))
10214               (use (reg:DI 2))
10215               (use (reg:DI 11))
10216               (set (reg:DI 2)
10217                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10218               (clobber (scratch:SI))])]
10219   "TARGET_64BIT"
10220   "
10221 { operands[3] = gen_reg_rtx (DImode); }")
10222
10223 ;; Now the definitions for the call and call_value insns
10224 (define_expand "call"
10225   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10226                     (match_operand 1 "" ""))
10227               (use (match_operand 2 "" ""))
10228               (clobber (scratch:SI))])]
10229   ""
10230   "
10231 {
10232 #if TARGET_MACHO
10233   if (MACHOPIC_INDIRECT)
10234     operands[0] = machopic_indirect_call_target (operands[0]);
10235 #endif
10236
10237   if (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != CONST_INT)
10238     abort ();
10239
10240   operands[0] = XEXP (operands[0], 0);
10241
10242   if (GET_CODE (operands[0]) != SYMBOL_REF
10243       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
10244       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
10245     {
10246       if (INTVAL (operands[2]) & CALL_LONG)
10247         operands[0] = rs6000_longcall_ref (operands[0]);
10248
10249       if (DEFAULT_ABI == ABI_V4
10250           || DEFAULT_ABI == ABI_DARWIN)
10251         operands[0] = force_reg (Pmode, operands[0]);
10252
10253       else if (DEFAULT_ABI == ABI_AIX)
10254         {
10255           /* AIX function pointers are really pointers to a three word
10256              area.  */
10257           emit_call_insn (TARGET_32BIT
10258                           ? gen_call_indirect_aix32 (force_reg (SImode,
10259                                                                 operands[0]),
10260                                                      operands[1])
10261                           : gen_call_indirect_aix64 (force_reg (DImode,
10262                                                                 operands[0]),
10263                                                      operands[1]));
10264           DONE;
10265         }
10266       else
10267         abort ();
10268     }
10269 }")
10270
10271 (define_expand "call_value"
10272   [(parallel [(set (match_operand 0 "" "")
10273                    (call (mem:SI (match_operand 1 "address_operand" ""))
10274                          (match_operand 2 "" "")))
10275               (use (match_operand 3 "" ""))
10276               (clobber (scratch:SI))])]
10277   ""
10278   "
10279 {
10280 #if TARGET_MACHO
10281   if (MACHOPIC_INDIRECT)
10282     operands[1] = machopic_indirect_call_target (operands[1]);
10283 #endif
10284
10285   if (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != CONST_INT)
10286     abort ();
10287
10288   operands[1] = XEXP (operands[1], 0);
10289
10290   if (GET_CODE (operands[1]) != SYMBOL_REF
10291       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
10292       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
10293     {
10294       if (INTVAL (operands[3]) & CALL_LONG)
10295         operands[1] = rs6000_longcall_ref (operands[1]);
10296
10297       if (DEFAULT_ABI == ABI_V4
10298           || DEFAULT_ABI == ABI_DARWIN)
10299         operands[1] = force_reg (Pmode, operands[1]);
10300
10301       else if (DEFAULT_ABI == ABI_AIX)
10302         {
10303           /* AIX function pointers are really pointers to a three word
10304              area.  */
10305           emit_call_insn (TARGET_32BIT
10306                           ? gen_call_value_indirect_aix32 (operands[0],
10307                                                            force_reg (SImode,
10308                                                                       operands[1]),
10309                                                            operands[2])
10310                           : gen_call_value_indirect_aix64 (operands[0],
10311                                                            force_reg (DImode,
10312                                                                       operands[1]),
10313                                                            operands[2]));
10314           DONE;
10315         }
10316       else
10317         abort ();
10318     }
10319 }")
10320
10321 ;; Call to function in current module.  No TOC pointer reload needed.
10322 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10323 ;; either the function was not prototyped, or it was prototyped as a
10324 ;; variable argument function.  It is > 0 if FP registers were passed
10325 ;; and < 0 if they were not.
10326
10327 (define_insn "*call_local32"
10328   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10329          (match_operand 1 "" "g,g"))
10330    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10331    (clobber (match_scratch:SI 3 "=l,l"))]
10332   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10333   "*
10334 {
10335   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10336     output_asm_insn (\"crxor 6,6,6\", operands);
10337
10338   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10339     output_asm_insn (\"creqv 6,6,6\", operands);
10340
10341   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10342 }"
10343   [(set_attr "type" "branch")
10344    (set_attr "length" "4,8")])
10345
10346 (define_insn "*call_local64"
10347   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10348          (match_operand 1 "" "g,g"))
10349    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10350    (clobber (match_scratch:SI 3 "=l,l"))]
10351   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10352   "*
10353 {
10354   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10355     output_asm_insn (\"crxor 6,6,6\", operands);
10356
10357   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10358     output_asm_insn (\"creqv 6,6,6\", operands);
10359
10360   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10361 }"
10362   [(set_attr "type" "branch")
10363    (set_attr "length" "4,8")])
10364
10365 (define_insn "*call_value_local32"
10366   [(set (match_operand 0 "" "")
10367         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10368               (match_operand 2 "" "g,g")))
10369    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10370    (clobber (match_scratch:SI 4 "=l,l"))]
10371   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10372   "*
10373 {
10374   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10375     output_asm_insn (\"crxor 6,6,6\", operands);
10376
10377   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10378     output_asm_insn (\"creqv 6,6,6\", operands);
10379
10380   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10381 }"
10382   [(set_attr "type" "branch")
10383    (set_attr "length" "4,8")])
10384
10385
10386 (define_insn "*call_value_local64"
10387   [(set (match_operand 0 "" "")
10388         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10389               (match_operand 2 "" "g,g")))
10390    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10391    (clobber (match_scratch:SI 4 "=l,l"))]
10392   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10393   "*
10394 {
10395   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10396     output_asm_insn (\"crxor 6,6,6\", operands);
10397
10398   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10399     output_asm_insn (\"creqv 6,6,6\", operands);
10400
10401   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10402 }"
10403   [(set_attr "type" "branch")
10404    (set_attr "length" "4,8")])
10405
10406 ;; Call to function which may be in another module.  Restore the TOC
10407 ;; pointer (r2) after the call unless this is System V.
10408 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10409 ;; either the function was not prototyped, or it was prototyped as a
10410 ;; variable argument function.  It is > 0 if FP registers were passed
10411 ;; and < 0 if they were not.
10412
10413 (define_insn "*call_indirect_nonlocal_aix32"
10414   [(call (mem:SI (match_operand:SI 0 "register_operand" "cl"))
10415          (match_operand 1 "" "g"))
10416    (use (reg:SI 2))
10417    (use (reg:SI 11))
10418    (set (reg:SI 2)
10419         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10420    (clobber (match_scratch:SI 2 "=l"))]
10421   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10422   "b%T0l\;{l|lwz} 2,20(1)"
10423   [(set_attr "type" "jmpreg")
10424    (set_attr "length" "8")])
10425
10426 (define_insn "*call_nonlocal_aix32"
10427   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10428          (match_operand 1 "" "g"))
10429    (use (match_operand:SI 2 "immediate_operand" "O"))
10430    (clobber (match_scratch:SI 3 "=l"))]
10431   "TARGET_32BIT
10432    && DEFAULT_ABI == ABI_AIX
10433    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10434   "bl %z0\;%."
10435   [(set_attr "type" "branch")
10436    (set_attr "length" "8")])
10437
10438 (define_insn "*call_indirect_nonlocal_aix64"
10439   [(call (mem:SI (match_operand:DI 0 "register_operand" "cl"))
10440          (match_operand 1 "" "g"))
10441    (use (reg:DI 2))
10442    (use (reg:DI 11))
10443    (set (reg:DI 2)
10444         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10445    (clobber (match_scratch:SI 2 "=l"))]
10446   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10447   "b%T0l\;ld 2,40(1)"
10448   [(set_attr "type" "jmpreg")
10449    (set_attr "length" "8")])
10450
10451 (define_insn "*call_nonlocal_aix64"
10452   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10453          (match_operand 1 "" "g"))
10454    (use (match_operand:SI 2 "immediate_operand" "O"))
10455    (clobber (match_scratch:SI 3 "=l"))]
10456   "TARGET_64BIT
10457    && DEFAULT_ABI == ABI_AIX
10458    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10459   "bl %z0\;%."
10460   [(set_attr "type" "branch")
10461    (set_attr "length" "8")])
10462
10463 (define_insn "*call_value_indirect_nonlocal_aix32"
10464   [(set (match_operand 0 "" "")
10465         (call (mem:SI (match_operand:SI 1 "register_operand" "cl"))
10466               (match_operand 2 "" "g")))
10467    (use (reg:SI 2))
10468    (use (reg:SI 11))
10469    (set (reg:SI 2)
10470         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10471    (clobber (match_scratch:SI 3 "=l"))]
10472   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10473   "b%T1l\;{l|lwz} 2,20(1)"
10474   [(set_attr "type" "jmpreg")
10475    (set_attr "length" "8")])
10476
10477 (define_insn "*call_value_nonlocal_aix32"
10478   [(set (match_operand 0 "" "")
10479         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10480               (match_operand 2 "" "g")))
10481    (use (match_operand:SI 3 "immediate_operand" "O"))
10482    (clobber (match_scratch:SI 4 "=l"))]
10483   "TARGET_32BIT
10484    && DEFAULT_ABI == ABI_AIX
10485    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10486   "bl %z1\;%."
10487   [(set_attr "type" "branch")
10488    (set_attr "length" "8")])
10489
10490 (define_insn "*call_value_indirect_nonlocal_aix64"
10491   [(set (match_operand 0 "" "")
10492         (call (mem:SI (match_operand:DI 1 "register_operand" "cl"))
10493               (match_operand 2 "" "g")))
10494    (use (reg:DI 2))
10495    (use (reg:DI 11))
10496    (set (reg:DI 2)
10497         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10498    (clobber (match_scratch:SI 3 "=l"))]
10499   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10500   "b%T1l\;ld 2,40(1)"
10501   [(set_attr "type" "jmpreg")
10502    (set_attr "length" "8")])
10503
10504 (define_insn "*call_value_nonlocal_aix64"
10505   [(set (match_operand 0 "" "")
10506         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10507               (match_operand 2 "" "g")))
10508    (use (match_operand:SI 3 "immediate_operand" "O"))
10509    (clobber (match_scratch:SI 4 "=l"))]
10510   "TARGET_64BIT
10511    && DEFAULT_ABI == ABI_AIX
10512    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10513   "bl %z1\;%."
10514   [(set_attr "type" "branch")
10515    (set_attr "length" "8")])
10516
10517 ;; A function pointer under System V is just a normal pointer
10518 ;; operands[0] is the function pointer
10519 ;; operands[1] is the stack size to clean up
10520 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
10521 ;; which indicates how to set cr1
10522
10523 (define_insn "*call_indirect_nonlocal_sysv"
10524   [(call (mem:SI (match_operand:SI 0 "register_operand" "cl,cl"))
10525          (match_operand 1 "" "g,g"))
10526    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10527    (clobber (match_scratch:SI 3 "=l,l"))]
10528   "DEFAULT_ABI == ABI_V4
10529    || DEFAULT_ABI == ABI_DARWIN"
10530 {
10531   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10532     output_asm_insn ("crxor 6,6,6", operands);
10533
10534   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10535     output_asm_insn ("creqv 6,6,6", operands);
10536
10537   return "b%T0l";
10538 }
10539   [(set_attr "type" "jmpreg,jmpreg")
10540    (set_attr "length" "4,8")])
10541
10542 (define_insn "*call_nonlocal_sysv"
10543   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s,s"))
10544          (match_operand 1 "" "g,g"))
10545    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10546    (clobber (match_scratch:SI 3 "=l,l"))]
10547   "(DEFAULT_ABI == ABI_DARWIN
10548    || (DEFAULT_ABI == ABI_V4
10549        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
10550 {
10551   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10552     output_asm_insn ("crxor 6,6,6", operands);
10553
10554   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10555     output_asm_insn ("creqv 6,6,6", operands);
10556
10557 #if TARGET_MACHO
10558   return output_call(insn, operands, 0, 2);
10559 #else
10560   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z0@plt" : "bl %z0";
10561 #endif
10562 }
10563   [(set_attr "type" "branch,branch")
10564    (set_attr "length" "4,8")])
10565
10566 (define_insn "*call_value_indirect_nonlocal_sysv"
10567   [(set (match_operand 0 "" "")
10568         (call (mem:SI (match_operand:SI 1 "register_operand" "cl,cl"))
10569               (match_operand 2 "" "g,g")))
10570    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10571    (clobber (match_scratch:SI 4 "=l,l"))]
10572   "DEFAULT_ABI == ABI_V4
10573    || DEFAULT_ABI == ABI_DARWIN"
10574 {
10575   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10576     output_asm_insn ("crxor 6,6,6", operands);
10577
10578   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10579     output_asm_insn ("creqv 6,6,6", operands);
10580
10581   return "b%T1l";
10582 }
10583   [(set_attr "type" "jmpreg,jmpreg")
10584    (set_attr "length" "4,8")])
10585
10586 (define_insn "*call_value_nonlocal_sysv"
10587   [(set (match_operand 0 "" "")
10588         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s,s"))
10589               (match_operand 2 "" "g,g")))
10590    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10591    (clobber (match_scratch:SI 4 "=l,l"))]
10592   "(DEFAULT_ABI == ABI_DARWIN
10593    || (DEFAULT_ABI == ABI_V4
10594        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
10595 {
10596   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10597     output_asm_insn ("crxor 6,6,6", operands);
10598
10599   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10600     output_asm_insn ("creqv 6,6,6", operands);
10601
10602 #if TARGET_MACHO
10603   return output_call(insn, operands, 1, 3);
10604 #else
10605   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z1@plt" : "bl %z1";
10606 #endif
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 || DEFAULT_ABI == ABI_DARWIN)
10960    && TARGET_HARD_FLOAT && 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 || DEFAULT_ABI == ABI_DARWIN)
11326    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
11327   "fcmpu %0,%1,%2\;bne %0,$+8\;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 GT bit.
11353 (define_insn "move_from_CR_gt_bit"
11354   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11355         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
11356   "TARGET_E500"
11357   "mfcr %0\;{rlinm|rlwinm} %0,%0,%D1,1"
11358   [(set_attr "type" "mfcr")
11359    (set_attr "length" "12")])
11360
11361 ;; Same as above, but get the OV/ORDERED bit.
11362 (define_insn "move_from_CR_ov_bit"
11363   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11364         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_OV))]
11365   "TARGET_ISEL"
11366   "mfcr %0\;{rlinm|rlwinm} %0,%0,%t1,1"
11367   [(set_attr "type" "mfcr")
11368    (set_attr "length" "12")])
11369
11370 (define_insn ""
11371   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11372         (match_operator:DI 1 "scc_comparison_operator"
11373                            [(match_operand 2 "cc_reg_operand" "y")
11374                             (const_int 0)]))]
11375   "TARGET_POWERPC64"
11376   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11377   [(set (attr "type")
11378      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11379                 (const_string "mfcrf")
11380            ]
11381         (const_string "mfcr")))
11382    (set_attr "length" "12")])
11383
11384 (define_insn ""
11385   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11386         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11387                                        [(match_operand 2 "cc_reg_operand" "y,y")
11388                                         (const_int 0)])
11389                     (const_int 0)))
11390    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11391         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11392   "TARGET_32BIT"
11393   "@
11394    mfcr %3%Q2\;{rlinm.|rlwinm.} %3,%3,%J1,1
11395    #"
11396   [(set_attr "type" "delayed_compare")
11397    (set_attr "length" "12,16")])
11398
11399 (define_split
11400   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11401         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11402                                        [(match_operand 2 "cc_reg_operand" "")
11403                                         (const_int 0)])
11404                     (const_int 0)))
11405    (set (match_operand:SI 3 "gpc_reg_operand" "")
11406         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11407   "TARGET_32BIT && reload_completed"
11408   [(set (match_dup 3)
11409         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
11410    (set (match_dup 0)
11411         (compare:CC (match_dup 3)
11412                     (const_int 0)))]
11413   "")
11414
11415 (define_insn ""
11416   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11417         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11418                                       [(match_operand 2 "cc_reg_operand" "y")
11419                                        (const_int 0)])
11420                    (match_operand:SI 3 "const_int_operand" "n")))]
11421   ""
11422   "*
11423 {
11424   int is_bit = ccr_bit (operands[1], 1);
11425   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11426   int count;
11427
11428   if (is_bit >= put_bit)
11429     count = is_bit - put_bit;
11430   else
11431     count = 32 - (put_bit - is_bit);
11432
11433   operands[4] = GEN_INT (count);
11434   operands[5] = GEN_INT (put_bit);
11435
11436   return \"mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
11437 }"
11438   [(set (attr "type")
11439      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11440                 (const_string "mfcrf")
11441            ]
11442         (const_string "mfcr")))
11443    (set_attr "length" "12")])
11444
11445 (define_insn ""
11446   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11447         (compare:CC
11448          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11449                                        [(match_operand 2 "cc_reg_operand" "y,y")
11450                                         (const_int 0)])
11451                     (match_operand:SI 3 "const_int_operand" "n,n"))
11452          (const_int 0)))
11453    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
11454         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11455                    (match_dup 3)))]
11456   ""
11457   "*
11458 {
11459   int is_bit = ccr_bit (operands[1], 1);
11460   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11461   int count;
11462
11463   /* Force split for non-cc0 compare.  */
11464   if (which_alternative == 1)
11465      return \"#\";
11466
11467   if (is_bit >= put_bit)
11468     count = is_bit - put_bit;
11469   else
11470     count = 32 - (put_bit - is_bit);
11471
11472   operands[5] = GEN_INT (count);
11473   operands[6] = GEN_INT (put_bit);
11474
11475   return \"mfcr %4%Q2\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
11476 }"
11477   [(set_attr "type" "delayed_compare")
11478    (set_attr "length" "12,16")])
11479
11480 (define_split
11481   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11482         (compare:CC
11483          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11484                                        [(match_operand 2 "cc_reg_operand" "")
11485                                         (const_int 0)])
11486                     (match_operand:SI 3 "const_int_operand" ""))
11487          (const_int 0)))
11488    (set (match_operand:SI 4 "gpc_reg_operand" "")
11489         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11490                    (match_dup 3)))]
11491   "reload_completed"
11492   [(set (match_dup 4)
11493         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11494                    (match_dup 3)))
11495    (set (match_dup 0)
11496         (compare:CC (match_dup 4)
11497                     (const_int 0)))]
11498   "")
11499
11500 ;; There is a 3 cycle delay between consecutive mfcr instructions
11501 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
11502
11503 (define_peephole
11504   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11505         (match_operator:SI 1 "scc_comparison_operator"
11506                            [(match_operand 2 "cc_reg_operand" "y")
11507                             (const_int 0)]))
11508    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
11509         (match_operator:SI 4 "scc_comparison_operator"
11510                            [(match_operand 5 "cc_reg_operand" "y")
11511                             (const_int 0)]))]
11512   "REGNO (operands[2]) != REGNO (operands[5])"
11513   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11514   [(set_attr "type" "mfcr")
11515    (set_attr "length" "20")])
11516
11517 (define_peephole
11518   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11519         (match_operator:DI 1 "scc_comparison_operator"
11520                            [(match_operand 2 "cc_reg_operand" "y")
11521                             (const_int 0)]))
11522    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
11523         (match_operator:DI 4 "scc_comparison_operator"
11524                            [(match_operand 5 "cc_reg_operand" "y")
11525                             (const_int 0)]))]
11526   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
11527   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11528   [(set_attr "type" "mfcr")
11529    (set_attr "length" "20")])
11530
11531 ;; There are some scc insns that can be done directly, without a compare.
11532 ;; These are faster because they don't involve the communications between
11533 ;; the FXU and branch units.   In fact, we will be replacing all of the
11534 ;; integer scc insns here or in the portable methods in emit_store_flag.
11535 ;;
11536 ;; Also support (neg (scc ..)) since that construct is used to replace
11537 ;; branches, (plus (scc ..) ..) since that construct is common and
11538 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
11539 ;; cases where it is no more expensive than (neg (scc ..)).
11540
11541 ;; Have reload force a constant into a register for the simple insns that
11542 ;; otherwise won't accept constants.  We do this because it is faster than
11543 ;; the cmp/mfcr sequence we would otherwise generate.
11544
11545 (define_insn ""
11546   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
11547         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11548                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I")))
11549    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
11550   "TARGET_32BIT"
11551   "@
11552    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11553    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
11554    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11555    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11556    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
11557   [(set_attr "length" "12,8,12,12,12")])
11558
11559 (define_insn ""
11560   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r")
11561         (eq:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r")
11562                (match_operand:DI 2 "reg_or_cint_operand" "r,O,K,J,I")))
11563    (clobber (match_scratch:DI 3 "=r,&r,r,r,r"))]
11564   "TARGET_64BIT"
11565   "@
11566    xor %0,%1,%2\;subfic %3,%0,0\;adde %0,%3,%0
11567    subfic %3,%1,0\;adde %0,%3,%1
11568    xori %0,%1,%b2\;subfic %3,%0,0\;adde %0,%3,%0
11569    xoris %0,%1,%u2\;subfic %3,%0,0\;adde %0,%3,%0
11570    subfic %0,%1,%2\;subfic %3,%0,0\;adde %0,%3,%0"
11571   [(set_attr "length" "12,8,12,12,12")])
11572
11573 (define_insn ""
11574   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11575         (compare:CC
11576          (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11577                 (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11578          (const_int 0)))
11579    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
11580         (eq:SI (match_dup 1) (match_dup 2)))
11581    (clobber (match_scratch:SI 3 "=r,&r,r,r,r,r,&r,r,r,r"))]
11582   "TARGET_32BIT"
11583   "@
11584    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11585    {sfi|subfic} %3,%1,0\;{ae.|adde.} %0,%3,%1
11586    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11587    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11588    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11589    #
11590    #
11591    #
11592    #
11593    #"
11594   [(set_attr "type" "compare")
11595    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11596
11597 (define_split
11598   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11599         (compare:CC
11600          (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11601                 (match_operand:SI 2 "reg_or_cint_operand" ""))
11602          (const_int 0)))
11603    (set (match_operand:SI 0 "gpc_reg_operand" "")
11604         (eq:SI (match_dup 1) (match_dup 2)))
11605    (clobber (match_scratch:SI 3 ""))]
11606   "TARGET_32BIT && reload_completed"
11607   [(parallel [(set (match_dup 0)
11608         (eq:SI (match_dup 1) (match_dup 2)))
11609    (clobber (match_dup 3))])
11610    (set (match_dup 4)
11611         (compare:CC (match_dup 0)
11612                     (const_int 0)))]
11613   "")
11614
11615 (define_insn ""
11616   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11617         (compare:CC
11618          (eq:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11619                 (match_operand:DI 2 "reg_or_cint_operand" "r,O,K,J,I,r,O,K,J,I"))
11620          (const_int 0)))
11621    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
11622         (eq:DI (match_dup 1) (match_dup 2)))
11623    (clobber (match_scratch:DI 3 "=r,&r,r,r,r,r,&r,r,r,r"))]
11624   "TARGET_64BIT"
11625   "@
11626    xor %0,%1,%2\;subfic %3,%0,0\;adde. %0,%3,%0
11627    subfic %3,%1,0\;adde. %0,%3,%1
11628    xori %0,%1,%b2\;subfic %3,%0,0\;adde. %0,%3,%0
11629    xoris %0,%1,%u2\;subfic %3,%0,0\;adde. %0,%3,%0
11630    subfic %0,%1,%2\;subfic %3,%0,0\;adde. %0,%3,%0
11631    #
11632    #
11633    #
11634    #
11635    #"
11636   [(set_attr "type" "compare")
11637    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11638
11639 (define_split
11640   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11641         (compare:CC
11642          (eq:DI (match_operand:DI 1 "gpc_reg_operand" "")
11643                 (match_operand:DI 2 "reg_or_cint_operand" ""))
11644          (const_int 0)))
11645    (set (match_operand:DI 0 "gpc_reg_operand" "")
11646         (eq:DI (match_dup 1) (match_dup 2)))
11647    (clobber (match_scratch:DI 3 ""))]
11648   "TARGET_64BIT && reload_completed"
11649   [(parallel [(set (match_dup 0)
11650         (eq:DI (match_dup 1) (match_dup 2)))
11651    (clobber (match_dup 3))])
11652    (set (match_dup 4)
11653         (compare:CC (match_dup 0)
11654                     (const_int 0)))]
11655   "")
11656
11657 ;; We have insns of the form shown by the first define_insn below.  If
11658 ;; there is something inside the comparison operation, we must split it.
11659 (define_split
11660   [(set (match_operand:SI 0 "gpc_reg_operand" "")
11661         (plus:SI (match_operator 1 "comparison_operator"
11662                                  [(match_operand:SI 2 "" "")
11663                                   (match_operand:SI 3
11664                                                     "reg_or_cint_operand" "")])
11665                  (match_operand:SI 4 "gpc_reg_operand" "")))
11666    (clobber (match_operand:SI 5 "register_operand" ""))]
11667   "! gpc_reg_operand (operands[2], SImode)"
11668   [(set (match_dup 5) (match_dup 2))
11669    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
11670                                (match_dup 4)))])
11671
11672 (define_insn ""
11673   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
11674         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11675                         (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I"))
11676                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
11677   "TARGET_32BIT"
11678   "@
11679    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11680    {sfi|subfic} %0,%1,0\;{aze|addze} %0,%3
11681    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11682    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11683    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
11684   [(set_attr "length" "12,8,12,12,12")])
11685
11686 (define_insn ""
11687   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11688         (compare:CC
11689          (plus:SI
11690           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11691                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11692           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11693          (const_int 0)))
11694    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
11695   "TARGET_32BIT"
11696   "@
11697    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11698    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
11699    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11700    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11701    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11702    #
11703    #
11704    #
11705    #
11706    #"
11707   [(set_attr "type" "compare")
11708    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11709
11710 (define_split
11711   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11712         (compare:CC
11713          (plus:SI
11714           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11715                  (match_operand:SI 2 "reg_or_cint_operand" ""))
11716           (match_operand:SI 3 "gpc_reg_operand" ""))
11717          (const_int 0)))
11718    (clobber (match_scratch:SI 4 ""))]
11719   "TARGET_32BIT && reload_completed"
11720   [(set (match_dup 4)
11721         (plus:SI (eq:SI (match_dup 1)
11722                  (match_dup 2))
11723           (match_dup 3)))
11724    (set (match_dup 0)
11725         (compare:CC (match_dup 4)
11726                     (const_int 0)))]
11727   "")
11728
11729 (define_insn ""
11730   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11731         (compare:CC
11732          (plus:SI
11733           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11734                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11735           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11736          (const_int 0)))
11737    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
11738         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11739   "TARGET_32BIT"
11740   "@
11741    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11742    {sfi|subfic} %0,%1,0\;{aze.|addze.} %0,%3
11743    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11744    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11745    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11746    #
11747    #
11748    #
11749    #
11750    #"
11751   [(set_attr "type" "compare")
11752    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11753
11754 (define_split
11755   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11756         (compare:CC
11757          (plus:SI
11758           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11759                  (match_operand:SI 2 "reg_or_cint_operand" ""))
11760           (match_operand:SI 3 "gpc_reg_operand" ""))
11761          (const_int 0)))
11762    (set (match_operand:SI 0 "gpc_reg_operand" "")
11763         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11764   "TARGET_32BIT && reload_completed"
11765   [(set (match_dup 0)
11766         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
11767    (set (match_dup 4)
11768         (compare:CC (match_dup 0)
11769                     (const_int 0)))]
11770   "")
11771
11772 (define_insn ""
11773   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
11774         (neg:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11775                        (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I"))))]
11776   "TARGET_32BIT"
11777   "@
11778    xor %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11779    {ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0
11780    {xoril|xori} %0,%1,%b2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11781    {xoriu|xoris} %0,%1,%u2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11782    {sfi|subfic} %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
11783    [(set_attr "length" "12,8,12,12,12")])
11784
11785 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
11786 ;; since it nabs/sr is just as fast.
11787 (define_insn "*ne0"
11788   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
11789         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
11790                      (const_int 31)))
11791    (clobber (match_scratch:SI 2 "=&r"))]
11792   "! TARGET_POWER && TARGET_32BIT && !TARGET_ISEL"
11793   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
11794   [(set_attr "length" "8")])
11795
11796 (define_insn ""
11797   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11798         (lshiftrt:DI (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
11799                      (const_int 63)))
11800    (clobber (match_scratch:DI 2 "=&r"))]
11801   "TARGET_64BIT"
11802   "addic %2,%1,-1\;subfe %0,%2,%1"
11803   [(set_attr "length" "8")])
11804
11805 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
11806 (define_insn ""
11807   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11808         (plus:SI (lshiftrt:SI
11809                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
11810                   (const_int 31))
11811                  (match_operand:SI 2 "gpc_reg_operand" "r")))
11812    (clobber (match_scratch:SI 3 "=&r"))]
11813   "TARGET_32BIT"
11814   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
11815   [(set_attr "length" "8")])
11816
11817 (define_insn ""
11818   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11819         (plus:DI (lshiftrt:DI
11820                   (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
11821                   (const_int 63))
11822                  (match_operand:DI 2 "gpc_reg_operand" "r")))
11823    (clobber (match_scratch:DI 3 "=&r"))]
11824   "TARGET_64BIT"
11825   "addic %3,%1,-1\;addze %0,%2"
11826   [(set_attr "length" "8")])
11827
11828 (define_insn ""
11829   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11830         (compare:CC
11831          (plus:SI (lshiftrt:SI
11832                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
11833                    (const_int 31))
11834                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
11835          (const_int 0)))
11836    (clobber (match_scratch:SI 3 "=&r,&r"))
11837    (clobber (match_scratch:SI 4 "=X,&r"))]
11838   "TARGET_32BIT"
11839   "@
11840    {ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2
11841    #"
11842   [(set_attr "type" "compare")
11843    (set_attr "length" "8,12")])
11844
11845 (define_split
11846   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11847         (compare:CC
11848          (plus:SI (lshiftrt:SI
11849                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11850                    (const_int 31))
11851                   (match_operand:SI 2 "gpc_reg_operand" ""))
11852          (const_int 0)))
11853    (clobber (match_scratch:SI 3 ""))
11854    (clobber (match_scratch:SI 4 ""))]
11855   "TARGET_32BIT && reload_completed"
11856   [(parallel [(set (match_dup 3)
11857                    (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1)))
11858                                          (const_int 31))
11859                             (match_dup 2)))
11860               (clobber (match_dup 4))])
11861    (set (match_dup 0)
11862         (compare:CC (match_dup 3)
11863                     (const_int 0)))]
11864   "")
11865
11866 (define_insn ""
11867   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11868         (compare:CC
11869          (plus:DI (lshiftrt:DI
11870                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
11871                    (const_int 63))
11872                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
11873          (const_int 0)))
11874    (clobber (match_scratch:DI 3 "=&r,&r"))]
11875   "TARGET_64BIT"
11876   "@
11877    addic %3,%1,-1\;addze. %3,%2
11878    #"
11879   [(set_attr "type" "compare")
11880    (set_attr "length" "8,12")])
11881
11882 (define_split
11883   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11884         (compare:CC
11885          (plus:DI (lshiftrt:DI
11886                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
11887                    (const_int 63))
11888                   (match_operand:DI 2 "gpc_reg_operand" ""))
11889          (const_int 0)))
11890    (clobber (match_scratch:DI 3 ""))]
11891   "TARGET_64BIT && reload_completed"
11892   [(set (match_dup 3)
11893         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1)))
11894                    (const_int 63))
11895                   (match_dup 2)))
11896    (set (match_dup 0)
11897         (compare:CC (match_dup 3)
11898                     (const_int 0)))]
11899   "")
11900
11901 (define_insn ""
11902   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
11903         (compare:CC
11904          (plus:SI (lshiftrt:SI
11905                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
11906                    (const_int 31))
11907                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
11908          (const_int 0)))
11909    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11910         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11911                  (match_dup 2)))
11912    (clobber (match_scratch:SI 3 "=&r,&r"))]
11913   "TARGET_32BIT"
11914   "@
11915    {ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2
11916    #"
11917   [(set_attr "type" "compare")
11918    (set_attr "length" "8,12")])
11919
11920 (define_split
11921   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11922         (compare:CC
11923          (plus:SI (lshiftrt:SI
11924                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11925                    (const_int 31))
11926                   (match_operand:SI 2 "gpc_reg_operand" ""))
11927          (const_int 0)))
11928    (set (match_operand:SI 0 "gpc_reg_operand" "")
11929         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11930                  (match_dup 2)))
11931    (clobber (match_scratch:SI 3 ""))]
11932   "TARGET_32BIT && reload_completed"
11933   [(parallel [(set (match_dup 0)
11934         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11935                  (match_dup 2)))
11936    (clobber (match_dup 3))])
11937    (set (match_dup 4)
11938         (compare:CC (match_dup 0)
11939                     (const_int 0)))]
11940   "")
11941
11942 (define_insn ""
11943   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
11944         (compare:CC
11945          (plus:DI (lshiftrt:DI
11946                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
11947                    (const_int 63))
11948                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
11949          (const_int 0)))
11950    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
11951         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11952                  (match_dup 2)))
11953    (clobber (match_scratch:DI 3 "=&r,&r"))]
11954   "TARGET_64BIT"
11955   "@
11956    addic %3,%1,-1\;addze. %0,%2
11957    #"
11958   [(set_attr "type" "compare")
11959    (set_attr "length" "8,12")])
11960
11961 (define_split
11962   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11963         (compare:CC
11964          (plus:DI (lshiftrt:DI
11965                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
11966                    (const_int 63))
11967                   (match_operand:DI 2 "gpc_reg_operand" ""))
11968          (const_int 0)))
11969    (set (match_operand:DI 0 "gpc_reg_operand" "")
11970         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11971                  (match_dup 2)))
11972    (clobber (match_scratch:DI 3 ""))]
11973   "TARGET_64BIT && reload_completed"
11974   [(parallel [(set (match_dup 0)
11975         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11976                  (match_dup 2)))
11977    (clobber (match_dup 3))])
11978    (set (match_dup 4)
11979         (compare:CC (match_dup 0)
11980                     (const_int 0)))]
11981   "")
11982
11983 (define_insn ""
11984   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11985         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
11986                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
11987    (clobber (match_scratch:SI 3 "=r,X"))]
11988   "TARGET_POWER"
11989   "@
11990    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
11991    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
11992   [(set_attr "length" "12")])
11993
11994 (define_insn ""
11995   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
11996         (compare:CC
11997          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
11998                 (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
11999          (const_int 0)))
12000    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12001         (le:SI (match_dup 1) (match_dup 2)))
12002    (clobber (match_scratch:SI 3 "=r,X,r,X"))]
12003   "TARGET_POWER"
12004   "@
12005    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
12006    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31
12007    #
12008    #"
12009   [(set_attr "type" "compare,delayed_compare,compare,delayed_compare")
12010    (set_attr "length" "12,12,16,16")])
12011
12012 (define_split
12013   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12014         (compare:CC
12015          (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12016                 (match_operand:SI 2 "reg_or_short_operand" ""))
12017          (const_int 0)))
12018    (set (match_operand:SI 0 "gpc_reg_operand" "")
12019         (le:SI (match_dup 1) (match_dup 2)))
12020    (clobber (match_scratch:SI 3 ""))]
12021   "TARGET_POWER && reload_completed"
12022   [(parallel [(set (match_dup 0)
12023         (le:SI (match_dup 1) (match_dup 2)))
12024    (clobber (match_dup 3))])
12025    (set (match_dup 4)
12026         (compare:CC (match_dup 0)
12027                     (const_int 0)))]
12028   "")
12029
12030 (define_insn ""
12031   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12032         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12033                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
12034                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12035   "TARGET_POWER"
12036   "@
12037    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
12038    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze|addze} %0,%3"
12039   [(set_attr "length" "12")])
12040
12041 (define_insn ""
12042   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12043         (compare:CC
12044          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12045                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12046                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12047          (const_int 0)))
12048    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12049   "TARGET_POWER"
12050   "@
12051    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12052    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3
12053    #
12054    #"
12055   [(set_attr "type" "compare")
12056    (set_attr "length" "12,12,16,16")])
12057
12058 (define_split
12059   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12060         (compare:CC
12061          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12062                          (match_operand:SI 2 "reg_or_short_operand" ""))
12063                   (match_operand:SI 3 "gpc_reg_operand" ""))
12064          (const_int 0)))
12065    (clobber (match_scratch:SI 4 ""))]
12066   "TARGET_POWER && reload_completed"
12067   [(set (match_dup 4)
12068         (plus:SI (le:SI (match_dup 1) (match_dup 2))
12069                  (match_dup 3)))
12070    (set (match_dup 0)
12071         (compare:CC (match_dup 4)
12072                     (const_int 0)))]
12073   "")
12074
12075 (define_insn ""
12076   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12077         (compare:CC
12078          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12079                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12080                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12081          (const_int 0)))
12082    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12083         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12084   "TARGET_POWER"
12085   "@
12086    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12087    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze.|addze.} %0,%3
12088    #
12089    #"
12090   [(set_attr "type" "compare")
12091    (set_attr "length" "12,12,16,16")])
12092
12093 (define_split
12094   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12095         (compare:CC
12096          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12097                          (match_operand:SI 2 "reg_or_short_operand" ""))
12098                   (match_operand:SI 3 "gpc_reg_operand" ""))
12099          (const_int 0)))
12100    (set (match_operand:SI 0 "gpc_reg_operand" "")
12101         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12102   "TARGET_POWER && reload_completed"
12103   [(set (match_dup 0)
12104         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12105    (set (match_dup 4)
12106         (compare:CC (match_dup 0)
12107                     (const_int 0)))]
12108   "")
12109
12110 (define_insn ""
12111   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12112         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12113                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
12114   "TARGET_POWER"
12115   "@
12116    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
12117    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
12118   [(set_attr "length" "12")])
12119
12120 (define_insn ""
12121   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12122         (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12123                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12124   "TARGET_32BIT"
12125   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12126   [(set_attr "length" "12")])
12127
12128 (define_insn ""
12129   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12130         (leu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
12131                 (match_operand:DI 2 "reg_or_short_operand" "rI")))]
12132   "TARGET_64BIT"
12133   "subf%I2c %0,%1,%2\;li %0,0\;adde %0,%0,%0"
12134   [(set_attr "length" "12")])
12135
12136 (define_insn ""
12137   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12138         (compare:CC
12139          (leu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12140                  (match_operand:DI 2 "reg_or_short_operand" "rI,rI"))
12141          (const_int 0)))
12142    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12143         (leu:DI (match_dup 1) (match_dup 2)))]
12144   "TARGET_64BIT"
12145   "@
12146    subf%I2c %0,%1,%2\;li %0,0\;adde. %0,%0,%0
12147    #"
12148   [(set_attr "type" "compare")
12149    (set_attr "length" "12,16")])
12150
12151 (define_split
12152   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12153         (compare:CC
12154          (leu:DI (match_operand:DI 1 "gpc_reg_operand" "")
12155                  (match_operand:DI 2 "reg_or_short_operand" ""))
12156          (const_int 0)))
12157    (set (match_operand:DI 0 "gpc_reg_operand" "")
12158         (leu:DI (match_dup 1) (match_dup 2)))]
12159   "TARGET_64BIT && reload_completed"
12160   [(set (match_dup 0)
12161         (leu:DI (match_dup 1) (match_dup 2)))
12162    (set (match_dup 3)
12163         (compare:CC (match_dup 0)
12164                     (const_int 0)))]
12165   "")
12166
12167 (define_insn ""
12168   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12169         (compare:CC
12170          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12171                  (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12172          (const_int 0)))
12173    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12174         (leu:SI (match_dup 1) (match_dup 2)))]
12175   "TARGET_32BIT"
12176   "@
12177    {sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12178    #"
12179   [(set_attr "type" "compare")
12180    (set_attr "length" "12,16")])
12181
12182 (define_split
12183   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12184         (compare:CC
12185          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12186                  (match_operand:SI 2 "reg_or_short_operand" ""))
12187          (const_int 0)))
12188    (set (match_operand:SI 0 "gpc_reg_operand" "")
12189         (leu:SI (match_dup 1) (match_dup 2)))]
12190   "TARGET_32BIT && reload_completed"
12191   [(set (match_dup 0)
12192         (leu:SI (match_dup 1) (match_dup 2)))
12193    (set (match_dup 3)
12194         (compare:CC (match_dup 0)
12195                     (const_int 0)))]
12196   "")
12197
12198 (define_insn ""
12199   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12200         (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12201                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
12202                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12203   "TARGET_32BIT"
12204   "{sf%I2|subf%I2c} %0,%1,%2\;{aze|addze} %0,%3"
12205   [(set_attr "length" "8")])
12206
12207 (define_insn ""
12208   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12209         (compare:CC
12210          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12211                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12212                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12213          (const_int 0)))
12214    (clobber (match_scratch:SI 4 "=&r,&r"))]
12215   "TARGET_32BIT"
12216   "@
12217    {sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3
12218    #"
12219   [(set_attr "type" "compare")
12220    (set_attr "length" "8,12")])
12221
12222 (define_split
12223   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12224         (compare:CC
12225          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12226                           (match_operand:SI 2 "reg_or_short_operand" ""))
12227                   (match_operand:SI 3 "gpc_reg_operand" ""))
12228          (const_int 0)))
12229    (clobber (match_scratch:SI 4 ""))]
12230   "TARGET_32BIT && reload_completed"
12231   [(set (match_dup 4)
12232         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
12233                   (match_dup 3)))
12234    (set (match_dup 0)
12235         (compare:CC (match_dup 4)
12236                     (const_int 0)))]
12237   "")
12238
12239 (define_insn ""
12240   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12241         (compare:CC
12242          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12243                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12244                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12245          (const_int 0)))
12246    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12247         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12248   "TARGET_32BIT"
12249   "@
12250    {sf%I2|subf%I2c} %0,%1,%2\;{aze.|addze.} %0,%3
12251    #"
12252   [(set_attr "type" "compare")
12253    (set_attr "length" "8,12")])
12254
12255 (define_split
12256   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12257         (compare:CC
12258          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12259                           (match_operand:SI 2 "reg_or_short_operand" ""))
12260                   (match_operand:SI 3 "gpc_reg_operand" ""))
12261          (const_int 0)))
12262    (set (match_operand:SI 0 "gpc_reg_operand" "")
12263         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12264   "TARGET_32BIT && reload_completed"
12265   [(set (match_dup 0)
12266         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12267    (set (match_dup 4)
12268         (compare:CC (match_dup 0)
12269                     (const_int 0)))]
12270   "")
12271
12272 (define_insn ""
12273   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12274         (neg:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12275                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12276   "TARGET_32BIT"
12277   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
12278    [(set_attr "length" "12")])
12279
12280 (define_insn ""
12281   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12282         (and:SI (neg:SI
12283                  (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12284                          (match_operand:SI 2 "reg_or_short_operand" "rI")))
12285                 (match_operand:SI 3 "gpc_reg_operand" "r")))]
12286   "TARGET_32BIT"
12287   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12288   [(set_attr "length" "12")])
12289
12290 (define_insn ""
12291   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12292         (compare:CC
12293          (and:SI (neg:SI
12294                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12295                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12296                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12297          (const_int 0)))
12298    (clobber (match_scratch:SI 4 "=&r,&r"))]
12299   "TARGET_32BIT"
12300   "@
12301    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12302    #"
12303   [(set_attr "type" "compare")
12304    (set_attr "length" "12,16")])
12305
12306 (define_split
12307   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12308         (compare:CC
12309          (and:SI (neg:SI
12310                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12311                           (match_operand:SI 2 "reg_or_short_operand" "")))
12312                  (match_operand:SI 3 "gpc_reg_operand" ""))
12313          (const_int 0)))
12314    (clobber (match_scratch:SI 4 ""))]
12315   "TARGET_32BIT && reload_completed"
12316   [(set (match_dup 4)
12317         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12318                 (match_dup 3)))
12319    (set (match_dup 0)
12320         (compare:CC (match_dup 4)
12321                     (const_int 0)))]
12322   "")
12323
12324 (define_insn ""
12325   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12326         (compare:CC
12327          (and:SI (neg:SI
12328                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12329                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12330                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12331          (const_int 0)))
12332    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12333         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12334   "TARGET_32BIT"
12335   "@
12336    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12337    #"
12338   [(set_attr "type" "compare")
12339    (set_attr "length" "12,16")])
12340
12341 (define_split
12342   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12343         (compare:CC
12344          (and:SI (neg:SI
12345                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12346                           (match_operand:SI 2 "reg_or_short_operand" "")))
12347                  (match_operand:SI 3 "gpc_reg_operand" ""))
12348          (const_int 0)))
12349    (set (match_operand:SI 0 "gpc_reg_operand" "")
12350         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12351   "TARGET_32BIT && reload_completed"
12352   [(set (match_dup 0)
12353         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12354                 (match_dup 3)))
12355    (set (match_dup 4)
12356         (compare:CC (match_dup 0)
12357                     (const_int 0)))]
12358   "")
12359
12360 (define_insn ""
12361   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12362         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12363                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12364   "TARGET_POWER"
12365   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
12366    [(set_attr "length" "12")])
12367
12368 (define_insn ""
12369   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12370         (compare:CC
12371          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12372                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12373          (const_int 0)))
12374    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12375         (lt:SI (match_dup 1) (match_dup 2)))]
12376   "TARGET_POWER"
12377   "@
12378    doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
12379    #"
12380   [(set_attr "type" "delayed_compare")
12381    (set_attr "length" "12,16")])
12382
12383 (define_split
12384   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12385         (compare:CC
12386          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12387                 (match_operand:SI 2 "reg_or_short_operand" ""))
12388          (const_int 0)))
12389    (set (match_operand:SI 0 "gpc_reg_operand" "")
12390         (lt:SI (match_dup 1) (match_dup 2)))]
12391   "TARGET_POWER && reload_completed"
12392   [(set (match_dup 0)
12393         (lt:SI (match_dup 1) (match_dup 2)))
12394    (set (match_dup 3)
12395         (compare:CC (match_dup 0)
12396                     (const_int 0)))]
12397   "")
12398
12399 (define_insn ""
12400   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12401         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12402                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12403                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12404   "TARGET_POWER"
12405   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
12406   [(set_attr "length" "12")])
12407
12408 (define_insn ""
12409   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12410         (compare:CC
12411          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12412                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12413                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12414          (const_int 0)))
12415    (clobber (match_scratch:SI 4 "=&r,&r"))]
12416   "TARGET_POWER"
12417   "@
12418    doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
12419    #"
12420   [(set_attr "type" "compare")
12421    (set_attr "length" "12,16")])
12422
12423 (define_split
12424   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12425         (compare:CC
12426          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12427                          (match_operand:SI 2 "reg_or_short_operand" ""))
12428                   (match_operand:SI 3 "gpc_reg_operand" ""))
12429          (const_int 0)))
12430    (clobber (match_scratch:SI 4 ""))]
12431   "TARGET_POWER && reload_completed"
12432   [(set (match_dup 4)
12433         (plus:SI (lt:SI (match_dup 1) (match_dup 2))
12434                  (match_dup 3)))
12435    (set (match_dup 0)
12436         (compare:CC (match_dup 4)
12437                     (const_int 0)))]
12438   "")
12439
12440 (define_insn ""
12441   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12442         (compare:CC
12443          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12444                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12445                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12446          (const_int 0)))
12447    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12448         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12449   "TARGET_POWER"
12450   "@
12451    doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
12452    #"
12453   [(set_attr "type" "compare")
12454    (set_attr "length" "12,16")])
12455
12456 (define_split
12457   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12458         (compare:CC
12459          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12460                          (match_operand:SI 2 "reg_or_short_operand" ""))
12461                   (match_operand:SI 3 "gpc_reg_operand" ""))
12462          (const_int 0)))
12463    (set (match_operand:SI 0 "gpc_reg_operand" "")
12464         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12465   "TARGET_POWER && reload_completed"
12466   [(set (match_dup 0)
12467         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12468    (set (match_dup 4)
12469         (compare:CC (match_dup 0)
12470                     (const_int 0)))]
12471   "")
12472
12473 (define_insn ""
12474   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12475         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12476                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12477   "TARGET_POWER"
12478   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
12479   [(set_attr "length" "12")])
12480
12481 (define_insn ""
12482   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12483         (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12484                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
12485   "TARGET_32BIT"
12486   "@
12487    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg %0,%0
12488    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg %0,%0"
12489   [(set_attr "length" "12")])
12490
12491 (define_insn ""
12492   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12493         (compare:CC
12494          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12495                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12496          (const_int 0)))
12497    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12498         (ltu:SI (match_dup 1) (match_dup 2)))]
12499   "TARGET_32BIT"
12500   "@
12501    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
12502    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
12503    #
12504    #"
12505   [(set_attr "type" "compare")
12506    (set_attr "length" "12,12,16,16")])
12507
12508 (define_split
12509   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12510         (compare:CC
12511          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12512                  (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12513          (const_int 0)))
12514    (set (match_operand:SI 0 "gpc_reg_operand" "")
12515         (ltu:SI (match_dup 1) (match_dup 2)))]
12516   "TARGET_32BIT && reload_completed"
12517   [(set (match_dup 0)
12518         (ltu:SI (match_dup 1) (match_dup 2)))
12519    (set (match_dup 3)
12520         (compare:CC (match_dup 0)
12521                     (const_int 0)))]
12522   "")
12523
12524 (define_insn ""
12525   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12526         (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12527                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
12528                  (match_operand:SI 3 "reg_or_short_operand" "rI,rI")))]
12529   "TARGET_32BIT"
12530   "@
12531   {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;{sf%I3|subf%I3c} %0,%0,%3
12532   {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;{sf%I3|subf%I3c} %0,%0,%3"
12533  [(set_attr "length" "12")])
12534
12535 (define_insn ""
12536   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12537         (compare:CC
12538          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12539                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12540                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12541          (const_int 0)))
12542    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12543   "TARGET_32BIT"
12544   "@
12545    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
12546    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
12547    #
12548    #"
12549   [(set_attr "type" "compare")
12550    (set_attr "length" "12,12,16,16")])
12551
12552 (define_split
12553   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12554         (compare:CC
12555          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12556                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12557                   (match_operand:SI 3 "gpc_reg_operand" ""))
12558          (const_int 0)))
12559    (clobber (match_scratch:SI 4 ""))]
12560   "TARGET_32BIT && reload_completed"
12561   [(set (match_dup 4)
12562         (plus:SI (ltu:SI (match_dup 1) (match_dup 2))
12563                  (match_dup 3)))
12564    (set (match_dup 0)
12565         (compare:CC (match_dup 4)
12566                     (const_int 0)))]
12567   "")
12568
12569 (define_insn ""
12570   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12571         (compare:CC
12572          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12573                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12574                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12575          (const_int 0)))
12576    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12577         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12578   "TARGET_32BIT"
12579   "@
12580    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;{sf.|subfc.} %0,%0,%3
12581    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;{sf.|subfc.} %0,%0,%3
12582    #
12583    #"
12584   [(set_attr "type" "compare")
12585    (set_attr "length" "12,12,16,16")])
12586
12587 (define_split
12588   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12589         (compare:CC
12590          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12591                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12592                   (match_operand:SI 3 "gpc_reg_operand" ""))
12593          (const_int 0)))
12594    (set (match_operand:SI 0 "gpc_reg_operand" "")
12595         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12596   "TARGET_32BIT && reload_completed"
12597   [(set (match_dup 0)
12598         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12599    (set (match_dup 4)
12600         (compare:CC (match_dup 0)
12601                     (const_int 0)))]
12602   "")
12603
12604 (define_insn ""
12605   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12606         (neg:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12607                         (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))))]
12608   "TARGET_32BIT"
12609   "@
12610    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
12611    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
12612   [(set_attr "length" "8")])
12613
12614 (define_insn ""
12615   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12616         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12617                (match_operand:SI 2 "reg_or_short_operand" "rI")))
12618    (clobber (match_scratch:SI 3 "=r"))]
12619   "TARGET_POWER"
12620   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
12621    [(set_attr "length" "12")])
12622
12623 (define_insn ""
12624   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12625         (compare:CC
12626          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12627                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12628          (const_int 0)))
12629    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12630         (ge:SI (match_dup 1) (match_dup 2)))
12631    (clobber (match_scratch:SI 3 "=r,r"))]
12632   "TARGET_POWER"
12633   "@
12634    doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
12635    #"
12636   [(set_attr "type" "compare")
12637    (set_attr "length" "12,16")])
12638
12639 (define_split
12640   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12641         (compare:CC
12642          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12643                 (match_operand:SI 2 "reg_or_short_operand" ""))
12644          (const_int 0)))
12645    (set (match_operand:SI 0 "gpc_reg_operand" "")
12646         (ge:SI (match_dup 1) (match_dup 2)))
12647    (clobber (match_scratch:SI 3 ""))]
12648   "TARGET_POWER && reload_completed"
12649   [(parallel [(set (match_dup 0)
12650                    (ge:SI (match_dup 1) (match_dup 2)))
12651               (clobber (match_dup 3))])
12652    (set (match_dup 4)
12653         (compare:CC (match_dup 0)
12654                     (const_int 0)))]
12655   "")
12656
12657 (define_insn ""
12658   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12659         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12660                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12661                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12662   "TARGET_POWER"
12663   "doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
12664   [(set_attr "length" "12")])
12665
12666 (define_insn ""
12667   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12668         (compare:CC
12669          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12670                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12671                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12672          (const_int 0)))
12673    (clobber (match_scratch:SI 4 "=&r,&r"))]
12674   "TARGET_POWER"
12675   "@
12676    doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12677    #"
12678   [(set_attr "type" "compare")
12679    (set_attr "length" "12,16")])
12680
12681 (define_split
12682   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12683         (compare:CC
12684          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12685                          (match_operand:SI 2 "reg_or_short_operand" ""))
12686                   (match_operand:SI 3 "gpc_reg_operand" ""))
12687          (const_int 0)))
12688    (clobber (match_scratch:SI 4 ""))]
12689   "TARGET_POWER && reload_completed"
12690   [(set (match_dup 4)
12691         (plus:SI (ge:SI (match_dup 1) (match_dup 2))
12692                  (match_dup 3)))
12693    (set (match_dup 0)
12694         (compare:CC (match_dup 4)
12695                     (const_int 0)))]
12696   "")
12697
12698 (define_insn ""
12699   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12700         (compare:CC
12701          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12702                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12703                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12704          (const_int 0)))
12705    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12706         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12707   "TARGET_POWER"
12708   "@
12709    doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12710    #"
12711   [(set_attr "type" "compare")
12712    (set_attr "length" "12,16")])
12713
12714 (define_split
12715   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12716         (compare:CC
12717          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12718                          (match_operand:SI 2 "reg_or_short_operand" ""))
12719                   (match_operand:SI 3 "gpc_reg_operand" ""))
12720          (const_int 0)))
12721    (set (match_operand:SI 0 "gpc_reg_operand" "")
12722         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12723   "TARGET_POWER && reload_completed"
12724   [(set (match_dup 0)
12725         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12726    (set (match_dup 4)
12727         (compare:CC (match_dup 0)
12728                     (const_int 0)))]
12729   "")
12730
12731 (define_insn ""
12732   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12733         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12734                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12735   "TARGET_POWER"
12736   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
12737   [(set_attr "length" "12")])
12738
12739 (define_insn ""
12740   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12741         (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12742                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
12743   "TARGET_32BIT"
12744   "@
12745    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
12746    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12747   [(set_attr "length" "12")])
12748
12749 (define_insn ""
12750   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12751         (geu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12752                 (match_operand:DI 2 "reg_or_neg_short_operand" "r,P")))]
12753   "TARGET_64BIT"
12754   "@
12755    subfc %0,%2,%1\;li %0,0\;adde %0,%0,%0
12756    addic %0,%1,%n2\;li %0,0\;adde %0,%0,%0"
12757   [(set_attr "length" "12")])
12758
12759 (define_insn ""
12760   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12761         (compare:CC
12762          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12763                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12764          (const_int 0)))
12765    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12766         (geu:SI (match_dup 1) (match_dup 2)))]
12767   "TARGET_32BIT"
12768   "@
12769    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12770    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12771    #
12772    #"
12773   [(set_attr "type" "compare")
12774    (set_attr "length" "12,12,16,16")])
12775
12776 (define_split
12777   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12778         (compare:CC
12779          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12780                  (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12781          (const_int 0)))
12782    (set (match_operand:SI 0 "gpc_reg_operand" "")
12783         (geu:SI (match_dup 1) (match_dup 2)))]
12784   "TARGET_32BIT && reload_completed"
12785   [(set (match_dup 0)
12786         (geu:SI (match_dup 1) (match_dup 2)))
12787    (set (match_dup 3)
12788         (compare:CC (match_dup 0)
12789                     (const_int 0)))]
12790   "")
12791
12792 (define_insn ""
12793   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12794         (compare:CC
12795          (geu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
12796                  (match_operand:DI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12797          (const_int 0)))
12798    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
12799         (geu:DI (match_dup 1) (match_dup 2)))]
12800   "TARGET_64BIT"
12801   "@
12802    subfc %0,%2,%1\;li %0,0\;adde. %0,%0,%0
12803    addic %0,%1,%n2\;li %0,0\;adde. %0,%0,%0
12804    #
12805    #"
12806   [(set_attr "type" "compare")
12807    (set_attr "length" "12,12,16,16")])
12808
12809 (define_split
12810   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12811         (compare:CC
12812          (geu:DI (match_operand:DI 1 "gpc_reg_operand" "")
12813                  (match_operand:DI 2 "reg_or_neg_short_operand" ""))
12814          (const_int 0)))
12815    (set (match_operand:DI 0 "gpc_reg_operand" "")
12816         (geu:DI (match_dup 1) (match_dup 2)))]
12817   "TARGET_64BIT && reload_completed"
12818   [(set (match_dup 0)
12819         (geu:DI (match_dup 1) (match_dup 2)))
12820    (set (match_dup 3)
12821         (compare:CC (match_dup 0)
12822                     (const_int 0)))]
12823   "")
12824
12825 (define_insn ""
12826   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12827         (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12828                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
12829                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12830   "TARGET_32BIT"
12831   "@
12832    {sf|subfc} %0,%2,%1\;{aze|addze} %0,%3
12833    {ai|addic} %0,%1,%n2\;{aze|addze} %0,%3"
12834   [(set_attr "length" "8")])
12835
12836 (define_insn ""
12837   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12838         (compare:CC
12839          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12840                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12841                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12842          (const_int 0)))
12843    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12844   "TARGET_32BIT"
12845   "@
12846    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
12847    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3
12848    #
12849    #"
12850   [(set_attr "type" "compare")
12851    (set_attr "length" "8,8,12,12")])
12852
12853 (define_split
12854   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12855         (compare:CC
12856          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12857                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12858                   (match_operand:SI 3 "gpc_reg_operand" ""))
12859          (const_int 0)))
12860    (clobber (match_scratch:SI 4 ""))]
12861   "TARGET_32BIT && reload_completed"
12862   [(set (match_dup 4)
12863         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
12864                   (match_dup 3)))
12865    (set (match_dup 0)
12866         (compare:CC (match_dup 4)
12867                     (const_int 0)))]
12868   "")
12869
12870 (define_insn ""
12871   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12872         (compare:CC
12873          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12874                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12875                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12876          (const_int 0)))
12877    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12878         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12879   "TARGET_32BIT"
12880   "@
12881    {sf|subfc} %0,%2,%1\;{aze.|addze.} %0,%3
12882    {ai|addic} %0,%1,%n2\;{aze.|addze.} %0,%3
12883    #
12884    #"
12885   [(set_attr "type" "compare")
12886    (set_attr "length" "8,8,12,12")])
12887
12888 (define_split
12889   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12890         (compare:CC
12891          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12892                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12893                   (match_operand:SI 3 "gpc_reg_operand" ""))
12894          (const_int 0)))
12895    (set (match_operand:SI 0 "gpc_reg_operand" "")
12896         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12897   "TARGET_32BIT && reload_completed"
12898   [(set (match_dup 0)
12899         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12900    (set (match_dup 4)
12901         (compare:CC (match_dup 0)
12902                     (const_int 0)))]
12903   "")
12904
12905 (define_insn ""
12906   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12907         (neg:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12908                         (match_operand:SI 2 "reg_or_short_operand" "r,I"))))]
12909   "TARGET_32BIT"
12910   "@
12911    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
12912    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
12913   [(set_attr "length" "12")])
12914
12915 (define_insn ""
12916   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12917         (and:SI (neg:SI
12918                  (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12919                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
12920                 (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12921   "TARGET_32BIT"
12922   "@
12923    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0
12924    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12925   [(set_attr "length" "12")])
12926
12927 (define_insn ""
12928   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12929         (compare:CC
12930          (and:SI (neg:SI
12931                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12932                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
12933                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12934          (const_int 0)))
12935    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12936   "TARGET_32BIT"
12937   "@
12938    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12939    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12940    #
12941    #"
12942   [(set_attr "type" "compare")
12943    (set_attr "length" "12,12,16,16")])
12944
12945 (define_split
12946   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12947         (compare:CC
12948          (and:SI (neg:SI
12949                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12950                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
12951                  (match_operand:SI 3 "gpc_reg_operand" ""))
12952          (const_int 0)))
12953    (clobber (match_scratch:SI 4 ""))]
12954   "TARGET_32BIT && reload_completed"
12955   [(set (match_dup 4)
12956         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
12957                 (match_dup 3)))
12958    (set (match_dup 0)
12959         (compare:CC (match_dup 4)
12960                     (const_int 0)))]
12961   "")
12962
12963 (define_insn ""
12964   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12965         (compare:CC
12966          (and:SI (neg:SI
12967                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12968                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
12969                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12970          (const_int 0)))
12971    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12972         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12973   "TARGET_32BIT"
12974   "@
12975    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12976    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12977    #
12978    #"
12979   [(set_attr "type" "compare")
12980    (set_attr "length" "12,12,16,16")])
12981
12982 (define_split
12983   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12984         (compare:CC
12985          (and:SI (neg:SI
12986                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12987                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
12988                  (match_operand:SI 3 "gpc_reg_operand" ""))
12989          (const_int 0)))
12990    (set (match_operand:SI 0 "gpc_reg_operand" "")
12991         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12992   "TARGET_32BIT && reload_completed"
12993   [(set (match_dup 0)
12994         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
12995    (set (match_dup 4)
12996         (compare:CC (match_dup 0)
12997                     (const_int 0)))]
12998   "")
12999
13000 (define_insn ""
13001   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13002         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13003                (const_int 0)))]
13004   "TARGET_32BIT"
13005   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri|srwi} %0,%0,31"
13006   [(set_attr "length" "12")])
13007
13008 (define_insn ""
13009   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13010         (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13011                (const_int 0)))]
13012   "TARGET_64BIT"
13013   "subfic %0,%1,0\;addme %0,%0\;srdi %0,%0,63"
13014   [(set_attr "length" "12")])
13015
13016 (define_insn ""
13017   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
13018         (compare:CC
13019          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13020                 (const_int 0))
13021          (const_int 0)))
13022    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13023         (gt:SI (match_dup 1) (const_int 0)))]
13024   "TARGET_32BIT"
13025   "@
13026    {sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri.|srwi.} %0,%0,31
13027    #"
13028   [(set_attr "type" "delayed_compare")
13029    (set_attr "length" "12,16")])
13030
13031 (define_split
13032   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
13033         (compare:CC
13034          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13035                 (const_int 0))
13036          (const_int 0)))
13037    (set (match_operand:SI 0 "gpc_reg_operand" "")
13038         (gt:SI (match_dup 1) (const_int 0)))]
13039   "TARGET_32BIT && reload_completed"
13040   [(set (match_dup 0)
13041         (gt:SI (match_dup 1) (const_int 0)))
13042    (set (match_dup 2)
13043         (compare:CC (match_dup 0)
13044                     (const_int 0)))]
13045   "")
13046
13047 (define_insn ""
13048   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
13049         (compare:CC
13050          (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13051                 (const_int 0))
13052          (const_int 0)))
13053    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
13054         (gt:DI (match_dup 1) (const_int 0)))]
13055   "TARGET_64BIT"
13056   "@
13057    subfic %0,%1,0\;addme %0,%0\;srdi. %0,%0,63
13058    #"
13059   [(set_attr "type" "delayed_compare")
13060    (set_attr "length" "12,16")])
13061
13062 (define_split
13063   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
13064         (compare:CC
13065          (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13066                 (const_int 0))
13067          (const_int 0)))
13068    (set (match_operand:DI 0 "gpc_reg_operand" "")
13069         (gt:DI (match_dup 1) (const_int 0)))]
13070   "TARGET_64BIT && reload_completed"
13071   [(set (match_dup 0)
13072         (gt:DI (match_dup 1) (const_int 0)))
13073    (set (match_dup 2)
13074         (compare:CC (match_dup 0)
13075                     (const_int 0)))]
13076   "")
13077
13078 (define_insn ""
13079   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13080         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13081                (match_operand:SI 2 "reg_or_short_operand" "r")))]
13082   "TARGET_POWER"
13083   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
13084   [(set_attr "length" "12")])
13085
13086 (define_insn ""
13087   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13088         (compare:CC
13089          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13090                 (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13091          (const_int 0)))
13092    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13093         (gt:SI (match_dup 1) (match_dup 2)))]
13094   "TARGET_POWER"
13095   "@
13096    doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
13097    #"
13098   [(set_attr "type" "delayed_compare")
13099    (set_attr "length" "12,16")])
13100
13101 (define_split
13102   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13103         (compare:CC
13104          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13105                 (match_operand:SI 2 "reg_or_short_operand" ""))
13106          (const_int 0)))
13107    (set (match_operand:SI 0 "gpc_reg_operand" "")
13108         (gt:SI (match_dup 1) (match_dup 2)))]
13109   "TARGET_POWER && reload_completed"
13110   [(set (match_dup 0)
13111         (gt:SI (match_dup 1) (match_dup 2)))
13112    (set (match_dup 3)
13113         (compare:CC (match_dup 0)
13114                     (const_int 0)))]
13115   "")
13116
13117 (define_insn ""
13118   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13119         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13120                         (const_int 0))
13121                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
13122   "TARGET_32BIT"
13123   "{a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze|addze} %0,%2"
13124   [(set_attr "length" "12")])
13125
13126 (define_insn ""
13127   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
13128         (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13129                         (const_int 0))
13130                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
13131   "TARGET_64BIT"
13132   "addc %0,%1,%1\;subfe %0,%1,%0\;addze %0,%2"
13133   [(set_attr "length" "12")])
13134
13135 (define_insn ""
13136   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13137         (compare:CC
13138          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13139                          (const_int 0))
13140                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13141          (const_int 0)))
13142    (clobber (match_scratch:SI 3 "=&r,&r"))]
13143   "TARGET_32BIT"
13144   "@
13145    {a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2
13146    #"
13147   [(set_attr "type" "compare")
13148    (set_attr "length" "12,16")])
13149
13150 (define_split
13151   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13152         (compare:CC
13153          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13154                          (const_int 0))
13155                   (match_operand:SI 2 "gpc_reg_operand" ""))
13156          (const_int 0)))
13157    (clobber (match_scratch:SI 3 ""))]
13158   "TARGET_32BIT && reload_completed"
13159   [(set (match_dup 3)
13160         (plus:SI (gt:SI (match_dup 1) (const_int 0))
13161                   (match_dup 2)))
13162    (set (match_dup 0)
13163         (compare:CC (match_dup 3)
13164                     (const_int 0)))]
13165   "")
13166
13167 (define_insn ""
13168   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13169         (compare:CC
13170          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13171                          (const_int 0))
13172                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13173          (const_int 0)))
13174    (clobber (match_scratch:DI 3 "=&r,&r"))]
13175   "TARGET_64BIT"
13176   "@
13177    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
13178    #"
13179   [(set_attr "type" "compare")
13180    (set_attr "length" "12,16")])
13181
13182 (define_split
13183   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13184         (compare:CC
13185          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13186                          (const_int 0))
13187                   (match_operand:DI 2 "gpc_reg_operand" ""))
13188          (const_int 0)))
13189    (clobber (match_scratch:DI 3 ""))]
13190   "TARGET_64BIT && reload_completed"
13191   [(set (match_dup 3)
13192         (plus:DI (gt:DI (match_dup 1) (const_int 0))
13193                  (match_dup 2)))
13194    (set (match_dup 0)
13195         (compare:CC (match_dup 3)
13196                     (const_int 0)))]
13197   "")
13198
13199 (define_insn ""
13200   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13201         (compare:CC
13202          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13203                          (const_int 0))
13204                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13205          (const_int 0)))
13206    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13207         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13208   "TARGET_32BIT"
13209   "@
13210    {a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze.|addze.} %0,%2
13211    #"
13212   [(set_attr "type" "compare")
13213    (set_attr "length" "12,16")])
13214
13215 (define_split
13216   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13217         (compare:CC
13218          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13219                          (const_int 0))
13220                   (match_operand:SI 2 "gpc_reg_operand" ""))
13221          (const_int 0)))
13222    (set (match_operand:SI 0 "gpc_reg_operand" "")
13223         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13224   "TARGET_32BIT && reload_completed"
13225   [(set (match_dup 0)
13226         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
13227    (set (match_dup 3)
13228         (compare:CC (match_dup 0)
13229                     (const_int 0)))]
13230   "")
13231
13232 (define_insn ""
13233   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13234         (compare:CC
13235          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13236                          (const_int 0))
13237                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13238          (const_int 0)))
13239    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
13240         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13241   "TARGET_64BIT"
13242   "@
13243    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
13244    #"
13245   [(set_attr "type" "compare")
13246    (set_attr "length" "12,16")])
13247
13248 (define_split
13249   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13250         (compare:CC
13251          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13252                          (const_int 0))
13253                   (match_operand:DI 2 "gpc_reg_operand" ""))
13254          (const_int 0)))
13255    (set (match_operand:DI 0 "gpc_reg_operand" "")
13256         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13257   "TARGET_64BIT && reload_completed"
13258   [(set (match_dup 0)
13259         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
13260    (set (match_dup 3)
13261         (compare:CC (match_dup 0)
13262                     (const_int 0)))]
13263   "")
13264
13265 (define_insn ""
13266   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13267         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13268                         (match_operand:SI 2 "reg_or_short_operand" "r"))
13269                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
13270   "TARGET_POWER"
13271   "doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
13272   [(set_attr "length" "12")])
13273
13274 (define_insn ""
13275   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13276         (compare:CC
13277          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13278                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13279                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13280          (const_int 0)))
13281    (clobber (match_scratch:SI 4 "=&r,&r"))]
13282   "TARGET_POWER"
13283   "@
13284    doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
13285    #"
13286   [(set_attr "type" "compare")
13287    (set_attr "length" "12,16")])
13288
13289 (define_split
13290   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13291         (compare:CC
13292          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13293                          (match_operand:SI 2 "reg_or_short_operand" ""))
13294                   (match_operand:SI 3 "gpc_reg_operand" ""))
13295          (const_int 0)))
13296    (clobber (match_scratch:SI 4 ""))]
13297   "TARGET_POWER && reload_completed"
13298   [(set (match_dup 4)
13299         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13300    (set (match_dup 0)
13301         (compare:CC (match_dup 4)
13302                     (const_int 0)))]
13303   "")
13304
13305 (define_insn ""
13306   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13307         (compare:CC
13308          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13309                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13310                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13311          (const_int 0)))
13312    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13313         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13314   "TARGET_POWER"
13315   "@
13316    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
13317    #"
13318   [(set_attr "type" "compare")
13319    (set_attr "length" "12,16")])
13320
13321 (define_split
13322   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13323         (compare:CC
13324          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13325                          (match_operand:SI 2 "reg_or_short_operand" ""))
13326                   (match_operand:SI 3 "gpc_reg_operand" ""))
13327          (const_int 0)))
13328    (set (match_operand:SI 0 "gpc_reg_operand" "")
13329         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13330   "TARGET_POWER && reload_completed"
13331   [(set (match_dup 0)
13332         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13333    (set (match_dup 4)
13334         (compare:CC (match_dup 0)
13335                     (const_int 0)))]
13336   "")
13337
13338 (define_insn ""
13339   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13340         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13341                        (const_int 0))))]
13342   "TARGET_32BIT"
13343   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{srai|srawi} %0,%0,31"
13344   [(set_attr "length" "12")])
13345
13346 (define_insn ""
13347   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13348         (neg:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13349                        (const_int 0))))]
13350   "TARGET_64BIT"
13351   "subfic %0,%1,0\;addme %0,%0\;sradi %0,%0,63"
13352   [(set_attr "length" "12")])
13353
13354 (define_insn ""
13355   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13356         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13357                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
13358   "TARGET_POWER"
13359   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
13360   [(set_attr "length" "12")])
13361
13362 (define_insn ""
13363   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13364         (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13365                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
13366   "TARGET_32BIT"
13367   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg %0,%0"
13368   [(set_attr "length" "12")])
13369
13370 (define_insn ""
13371   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13372         (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13373                 (match_operand:DI 2 "reg_or_short_operand" "rI")))]
13374   "TARGET_64BIT"
13375   "subf%I2c %0,%1,%2\;subfe %0,%0,%0\;neg %0,%0"
13376   [(set_attr "length" "12")])
13377
13378 (define_insn ""
13379   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13380         (compare:CC
13381          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13382                  (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13383          (const_int 0)))
13384    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13385         (gtu:SI (match_dup 1) (match_dup 2)))]
13386   "TARGET_32BIT"
13387   "@
13388    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
13389    #"
13390   [(set_attr "type" "compare")
13391    (set_attr "length" "12,16")])
13392
13393 (define_split
13394   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13395         (compare:CC
13396          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13397                  (match_operand:SI 2 "reg_or_short_operand" ""))
13398          (const_int 0)))
13399    (set (match_operand:SI 0 "gpc_reg_operand" "")
13400         (gtu:SI (match_dup 1) (match_dup 2)))]
13401   "TARGET_32BIT && reload_completed"
13402   [(set (match_dup 0)
13403         (gtu:SI (match_dup 1) (match_dup 2)))
13404    (set (match_dup 3)
13405         (compare:CC (match_dup 0)
13406                     (const_int 0)))]
13407   "")
13408
13409 (define_insn ""
13410   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13411         (compare:CC
13412          (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13413                  (match_operand:DI 2 "reg_or_short_operand" "rI,rI"))
13414          (const_int 0)))
13415    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
13416         (gtu:DI (match_dup 1) (match_dup 2)))]
13417   "TARGET_64BIT"
13418   "@
13419    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;neg. %0,%0
13420    #"
13421   [(set_attr "type" "compare")
13422    (set_attr "length" "12,16")])
13423
13424 (define_split
13425   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13426         (compare:CC
13427          (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13428                  (match_operand:DI 2 "reg_or_short_operand" ""))
13429          (const_int 0)))
13430    (set (match_operand:DI 0 "gpc_reg_operand" "")
13431         (gtu:DI (match_dup 1) (match_dup 2)))]
13432   "TARGET_64BIT && reload_completed"
13433   [(set (match_dup 0)
13434         (gtu:DI (match_dup 1) (match_dup 2)))
13435    (set (match_dup 3)
13436         (compare:CC (match_dup 0)
13437                     (const_int 0)))]
13438   "")
13439
13440 (define_insn ""
13441   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13442         (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13443                          (match_operand:SI 2 "reg_or_short_operand" "I,rI"))
13444                  (match_operand:SI 3 "reg_or_short_operand" "r,rI")))]
13445   "TARGET_32BIT"
13446   "@
13447    {ai|addic} %0,%1,%k2\;{aze|addze} %0,%3
13448    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;{sf%I3|subf%I3c} %0,%0,%3"
13449   [(set_attr "length" "8,12")])
13450
13451 (define_insn ""
13452   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
13453         (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13454                          (match_operand:DI 2 "reg_or_short_operand" "I,rI"))
13455                  (match_operand:DI 3 "reg_or_short_operand" "r,rI")))]
13456   "TARGET_64BIT"
13457   "@
13458    addic %0,%1,%k2\;addze %0,%3
13459    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;subf%I3c %0,%0,%3"
13460   [(set_attr "length" "8,12")])
13461
13462 (define_insn ""
13463   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13464         (compare:CC
13465          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13466                           (match_operand:SI 2 "reg_or_short_operand" "I,r,I,r"))
13467                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13468          (const_int 0)))
13469    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13470   "TARGET_32BIT"
13471   "@
13472    {ai|addic} %4,%1,%k2\;{aze.|addze.} %4,%3
13473    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
13474    #
13475    #"
13476   [(set_attr "type" "compare")
13477    (set_attr "length" "8,12,12,16")])
13478
13479 (define_split
13480   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13481         (compare:CC
13482          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13483                           (match_operand:SI 2 "reg_or_short_operand" ""))
13484                   (match_operand:SI 3 "gpc_reg_operand" ""))
13485          (const_int 0)))
13486    (clobber (match_scratch:SI 4 ""))]
13487   "TARGET_32BIT && reload_completed"
13488   [(set (match_dup 4)
13489         (plus:SI (gtu:SI (match_dup 1) (match_dup 2))
13490                  (match_dup 3)))
13491    (set (match_dup 0)
13492         (compare:CC (match_dup 4)
13493                     (const_int 0)))]
13494   "")
13495
13496 (define_insn ""
13497   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13498         (compare:CC
13499          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
13500                           (match_operand:DI 2 "reg_or_short_operand" "I,r,I,r"))
13501                   (match_operand:DI 3 "gpc_reg_operand" "r,r,r,r"))
13502          (const_int 0)))
13503    (clobber (match_scratch:DI 4 "=&r,&r,&r,&r"))]
13504   "TARGET_64BIT"
13505   "@
13506    addic %4,%1,%k2\;addze. %4,%3
13507    subf%I2c %4,%1,%2\;subfe %4,%4,%4\;subfc. %4,%4,%3
13508    #
13509    #"
13510   [(set_attr "type" "compare")
13511    (set_attr "length" "8,12,12,16")])
13512
13513 (define_split
13514   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13515         (compare:CC
13516          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13517                           (match_operand:DI 2 "reg_or_short_operand" ""))
13518                   (match_operand:DI 3 "gpc_reg_operand" ""))
13519          (const_int 0)))
13520    (clobber (match_scratch:DI 4 ""))]
13521   "TARGET_64BIT && reload_completed"
13522   [(set (match_dup 4)
13523         (plus:DI (gtu:DI (match_dup 1) (match_dup 2))
13524                   (match_dup 3)))
13525    (set (match_dup 0)
13526         (compare:CC (match_dup 4)
13527                     (const_int 0)))]
13528   "")
13529
13530 (define_insn ""
13531   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13532         (compare:CC
13533          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13534                           (match_operand:SI 2 "reg_or_short_operand" "I,r,I,r"))
13535                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13536          (const_int 0)))
13537    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13538         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13539   "TARGET_32BIT"
13540   "@
13541    {ai|addic} %0,%1,%k2\;{aze.|addze.} %0,%3
13542    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;{sf.|subfc.} %0,%0,%3
13543    #
13544    #"
13545   [(set_attr "type" "compare")
13546    (set_attr "length" "8,12,12,16")])
13547
13548 (define_split
13549   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13550         (compare:CC
13551          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13552                           (match_operand:SI 2 "reg_or_short_operand" ""))
13553                   (match_operand:SI 3 "gpc_reg_operand" ""))
13554          (const_int 0)))
13555    (set (match_operand:SI 0 "gpc_reg_operand" "")
13556         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13557   "TARGET_32BIT && reload_completed"
13558   [(set (match_dup 0)
13559         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13560    (set (match_dup 4)
13561         (compare:CC (match_dup 0)
13562                     (const_int 0)))]
13563   "")
13564
13565 (define_insn ""
13566   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13567         (compare:CC
13568          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
13569                           (match_operand:DI 2 "reg_or_short_operand" "I,r,I,r"))
13570                   (match_operand:DI 3 "gpc_reg_operand" "r,r,r,r"))
13571          (const_int 0)))
13572    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13573         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13574   "TARGET_64BIT"
13575   "@
13576    addic %0,%1,%k2\;addze. %0,%3
13577    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;subfc. %0,%0,%3
13578    #
13579    #"
13580   [(set_attr "type" "compare")
13581    (set_attr "length" "8,12,12,16")])
13582
13583 (define_split
13584   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13585         (compare:CC
13586          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13587                           (match_operand:DI 2 "reg_or_short_operand" ""))
13588                   (match_operand:DI 3 "gpc_reg_operand" ""))
13589          (const_int 0)))
13590    (set (match_operand:DI 0 "gpc_reg_operand" "")
13591         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13592   "TARGET_64BIT && reload_completed"
13593   [(set (match_dup 0)
13594         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
13595    (set (match_dup 4)
13596         (compare:CC (match_dup 0)
13597                     (const_int 0)))]
13598   "")
13599
13600 (define_insn ""
13601   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13602         (neg:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13603                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
13604   "TARGET_32BIT"
13605   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
13606   [(set_attr "length" "8")])
13607
13608 (define_insn ""
13609   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13610         (neg:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13611                         (match_operand:DI 2 "reg_or_short_operand" "rI"))))]
13612   "TARGET_64BIT"
13613   "subf%I2c %0,%1,%2\;subfe %0,%0,%0"
13614   [(set_attr "length" "8")])
13615 \f
13616 ;; Define both directions of branch and return.  If we need a reload
13617 ;; register, we'd rather use CR0 since it is much easier to copy a
13618 ;; register CC value to there.
13619
13620 (define_insn ""
13621   [(set (pc)
13622         (if_then_else (match_operator 1 "branch_comparison_operator"
13623                                       [(match_operand 2
13624                                                       "cc_reg_operand" "y")
13625                                        (const_int 0)])
13626                       (label_ref (match_operand 0 "" ""))
13627                       (pc)))]
13628   ""
13629   "*
13630 {
13631   return output_cbranch (operands[1], \"%l0\", 0, insn);
13632 }"
13633   [(set_attr "type" "branch")])
13634
13635 (define_insn ""
13636   [(set (pc)
13637         (if_then_else (match_operator 0 "branch_comparison_operator"
13638                                       [(match_operand 1
13639                                                       "cc_reg_operand" "y")
13640                                        (const_int 0)])
13641                       (return)
13642                       (pc)))]
13643   "direct_return ()"
13644   "*
13645 {
13646   return output_cbranch (operands[0], NULL, 0, insn);
13647 }"
13648   [(set_attr "type" "branch")
13649    (set_attr "length" "4")])
13650
13651 (define_insn ""
13652   [(set (pc)
13653         (if_then_else (match_operator 1 "branch_comparison_operator"
13654                                       [(match_operand 2
13655                                                       "cc_reg_operand" "y")
13656                                        (const_int 0)])
13657                       (pc)
13658                       (label_ref (match_operand 0 "" ""))))]
13659   ""
13660   "*
13661 {
13662   return output_cbranch (operands[1], \"%l0\", 1, insn);
13663 }"
13664   [(set_attr "type" "branch")])
13665
13666 (define_insn ""
13667   [(set (pc)
13668         (if_then_else (match_operator 0 "branch_comparison_operator"
13669                                       [(match_operand 1
13670                                                       "cc_reg_operand" "y")
13671                                        (const_int 0)])
13672                       (pc)
13673                       (return)))]
13674   "direct_return ()"
13675   "*
13676 {
13677   return output_cbranch (operands[0], NULL, 1, insn);
13678 }"
13679   [(set_attr "type" "branch")
13680    (set_attr "length" "4")])
13681
13682 ;; Logic on condition register values.
13683
13684 ; This pattern matches things like
13685 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
13686 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
13687 ;                                  (const_int 1)))
13688 ; which are generated by the branch logic.
13689 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
13690
13691 (define_insn "*cceq_ior_compare"
13692   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13693         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
13694                         [(match_operator:SI 2
13695                                       "branch_positive_comparison_operator"
13696                                       [(match_operand 3
13697                                                       "cc_reg_operand" "y,y")
13698                                        (const_int 0)])
13699                          (match_operator:SI 4
13700                                       "branch_positive_comparison_operator"
13701                                       [(match_operand 5
13702                                                       "cc_reg_operand" "0,y")
13703                                        (const_int 0)])])
13704                       (const_int 1)))]
13705   "!(TARGET_E500 && TARGET_HARD_FLOAT && !TARGET_FPRS)"
13706   "cr%q1 %E0,%j2,%j4"
13707   [(set_attr "type" "cr_logical,delayed_cr")])
13708
13709 ; Why is the constant -1 here, but 1 in the previous pattern?
13710 ; Because ~1 has all but the low bit set.
13711 (define_insn ""
13712   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13713         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
13714                         [(not:SI (match_operator:SI 2
13715                                       "branch_positive_comparison_operator"
13716                                       [(match_operand 3
13717                                                       "cc_reg_operand" "y,y")
13718                                        (const_int 0)]))
13719                          (match_operator:SI 4
13720                                 "branch_positive_comparison_operator"
13721                                 [(match_operand 5
13722                                                 "cc_reg_operand" "0,y")
13723                                  (const_int 0)])])
13724                       (const_int -1)))]
13725   ""
13726   "cr%q1 %E0,%j2,%j4"
13727   [(set_attr "type" "cr_logical,delayed_cr")])
13728
13729 (define_insn "*cceq_rev_compare"
13730   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13731         (compare:CCEQ (match_operator:SI 1
13732                                       "branch_positive_comparison_operator"
13733                                       [(match_operand 2
13734                                                       "cc_reg_operand" "0,y")
13735                                        (const_int 0)])
13736                       (const_int 0)))]
13737   ""
13738   "{crnor %E0,%j1,%j1|crnot %E0,%j1}"
13739   [(set_attr "type" "cr_logical,delayed_cr")])
13740
13741 ;; If we are comparing the result of two comparisons, this can be done
13742 ;; using creqv or crxor.
13743
13744 (define_insn_and_split ""
13745   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
13746         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
13747                               [(match_operand 2 "cc_reg_operand" "y")
13748                                (const_int 0)])
13749                       (match_operator 3 "branch_comparison_operator"
13750                               [(match_operand 4 "cc_reg_operand" "y")
13751                                (const_int 0)])))]
13752   ""
13753   "#"
13754   ""
13755   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
13756                                     (match_dup 5)))]
13757   "
13758 {
13759   int positive_1, positive_2;
13760
13761   positive_1 = branch_positive_comparison_operator (operands[1], CCEQmode);
13762   positive_2 = branch_positive_comparison_operator (operands[3], CCEQmode);
13763
13764   if (! positive_1)
13765     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
13766                                                             GET_CODE (operands[1])),
13767                                   SImode,
13768                                   operands[2], const0_rtx);
13769   else if (GET_MODE (operands[1]) != SImode)
13770     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
13771                                   operands[2], const0_rtx);
13772
13773   if (! positive_2)
13774     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
13775                                                             GET_CODE (operands[3])),
13776                                   SImode,
13777                                   operands[4], const0_rtx);
13778   else if (GET_MODE (operands[3]) != SImode)
13779     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
13780                                   operands[4], const0_rtx);
13781
13782   if (positive_1 == positive_2)
13783     {
13784       operands[1] = gen_rtx_NOT (SImode, operands[1]);
13785       operands[5] = constm1_rtx;
13786     }
13787   else
13788     {
13789       operands[5] = const1_rtx;
13790     }
13791 }")
13792
13793 ;; Unconditional branch and return.
13794
13795 (define_insn "jump"
13796   [(set (pc)
13797         (label_ref (match_operand 0 "" "")))]
13798   ""
13799   "b %l0"
13800   [(set_attr "type" "branch")])
13801
13802 (define_insn "return"
13803   [(return)]
13804   "direct_return ()"
13805   "{br|blr}"
13806   [(set_attr "type" "jmpreg")])
13807
13808 (define_expand "indirect_jump"
13809   [(set (pc) (match_operand 0 "register_operand" ""))]
13810   ""
13811   "
13812 {
13813   if (TARGET_32BIT)
13814     emit_jump_insn (gen_indirect_jumpsi (operands[0]));
13815   else
13816     emit_jump_insn (gen_indirect_jumpdi (operands[0]));
13817   DONE;
13818 }")
13819
13820 (define_insn "indirect_jumpsi"
13821   [(set (pc) (match_operand:SI 0 "register_operand" "c,*l"))]
13822   "TARGET_32BIT"
13823   "@
13824    bctr
13825    {br|blr}"
13826   [(set_attr "type" "jmpreg")])
13827
13828 (define_insn "indirect_jumpdi"
13829   [(set (pc) (match_operand:DI 0 "register_operand" "c,*l"))]
13830   "TARGET_64BIT"
13831   "@
13832    bctr
13833    blr"
13834   [(set_attr "type" "jmpreg")])
13835
13836 ;; Table jump for switch statements:
13837 (define_expand "tablejump"
13838   [(use (match_operand 0 "" ""))
13839    (use (label_ref (match_operand 1 "" "")))]
13840   ""
13841   "
13842 {
13843   if (TARGET_32BIT)
13844     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
13845   else
13846     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
13847   DONE;
13848 }")
13849
13850 (define_expand "tablejumpsi"
13851   [(set (match_dup 3)
13852         (plus:SI (match_operand:SI 0 "" "")
13853                  (match_dup 2)))
13854    (parallel [(set (pc) (match_dup 3))
13855               (use (label_ref (match_operand 1 "" "")))])]
13856   "TARGET_32BIT"
13857   "
13858 { operands[0] = force_reg (SImode, operands[0]);
13859   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
13860   operands[3] = gen_reg_rtx (SImode);
13861 }")
13862
13863 (define_expand "tablejumpdi"
13864   [(set (match_dup 4)
13865         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "rm")))
13866    (set (match_dup 3)
13867         (plus:DI (match_dup 4)
13868                  (match_dup 2)))
13869    (parallel [(set (pc) (match_dup 3))
13870               (use (label_ref (match_operand 1 "" "")))])]
13871   "TARGET_64BIT"
13872   "
13873 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
13874   operands[3] = gen_reg_rtx (DImode);
13875   operands[4] = gen_reg_rtx (DImode);
13876 }")
13877
13878 (define_insn ""
13879   [(set (pc)
13880         (match_operand:SI 0 "register_operand" "c,*l"))
13881    (use (label_ref (match_operand 1 "" "")))]
13882   "TARGET_32BIT"
13883   "@
13884    bctr
13885    {br|blr}"
13886   [(set_attr "type" "jmpreg")])
13887
13888 (define_insn ""
13889   [(set (pc)
13890         (match_operand:DI 0 "register_operand" "c,*l"))
13891    (use (label_ref (match_operand 1 "" "")))]
13892   "TARGET_64BIT"
13893   "@
13894    bctr
13895    blr"
13896   [(set_attr "type" "jmpreg")])
13897
13898 (define_insn "nop"
13899   [(const_int 0)]
13900   ""
13901   "{cror 0,0,0|nop}")
13902 \f
13903 ;; Define the subtract-one-and-jump insns, starting with the template
13904 ;; so loop.c knows what to generate.
13905
13906 (define_expand "doloop_end"
13907   [(use (match_operand 0 "" ""))        ; loop pseudo
13908    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
13909    (use (match_operand 2 "" ""))        ; max iterations
13910    (use (match_operand 3 "" ""))        ; loop level
13911    (use (match_operand 4 "" ""))]       ; label
13912   ""
13913   "
13914 {
13915   /* Only use this on innermost loops.  */
13916   if (INTVAL (operands[3]) > 1)
13917     FAIL;
13918   if (TARGET_64BIT)
13919     {
13920       if (GET_MODE (operands[0]) != DImode)
13921         FAIL;
13922       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
13923     }
13924   else
13925     {
13926       if (GET_MODE (operands[0]) != SImode)
13927         FAIL;
13928       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
13929     }
13930   DONE;
13931 }")
13932
13933 (define_expand "ctrsi"
13934   [(parallel [(set (pc)
13935                    (if_then_else (ne (match_operand:SI 0 "register_operand" "")
13936                                      (const_int 1))
13937                                  (label_ref (match_operand 1 "" ""))
13938                                  (pc)))
13939               (set (match_dup 0)
13940                    (plus:SI (match_dup 0)
13941                             (const_int -1)))
13942               (clobber (match_scratch:CC 2 ""))
13943               (clobber (match_scratch:SI 3 ""))])]
13944   "TARGET_32BIT"
13945   "")
13946
13947 (define_expand "ctrdi"
13948   [(parallel [(set (pc)
13949                    (if_then_else (ne (match_operand:DI 0 "register_operand" "")
13950                                      (const_int 1))
13951                                  (label_ref (match_operand 1 "" ""))
13952                                  (pc)))
13953               (set (match_dup 0)
13954                    (plus:DI (match_dup 0)
13955                             (const_int -1)))
13956               (clobber (match_scratch:CC 2 ""))
13957               (clobber (match_scratch:DI 3 ""))])]
13958   "TARGET_64BIT"
13959   "")
13960
13961 ;; We need to be able to do this for any operand, including MEM, or we
13962 ;; will cause reload to blow up since we don't allow output reloads on
13963 ;; JUMP_INSNs.
13964 ;; For the length attribute to be calculated correctly, the
13965 ;; label MUST be operand 0.
13966
13967 (define_insn "*ctrsi_internal1"
13968   [(set (pc)
13969         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
13970                           (const_int 1))
13971                       (label_ref (match_operand 0 "" ""))
13972                       (pc)))
13973    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
13974         (plus:SI (match_dup 1)
13975                  (const_int -1)))
13976    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13977    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
13978   "TARGET_32BIT"
13979   "*
13980 {
13981   if (which_alternative != 0)
13982     return \"#\";
13983   else if (get_attr_length (insn) == 4)
13984     return \"{bdn|bdnz} %l0\";
13985   else
13986     return \"bdz $+8\;b %l0\";
13987 }"
13988   [(set_attr "type" "branch")
13989    (set_attr "length" "*,12,16,16")])
13990
13991 (define_insn "*ctrsi_internal2"
13992   [(set (pc)
13993         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
13994                           (const_int 1))
13995                       (pc)
13996                       (label_ref (match_operand 0 "" ""))))
13997    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
13998         (plus:SI (match_dup 1)
13999                  (const_int -1)))
14000    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14001    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14002   "TARGET_32BIT"
14003   "*
14004 {
14005   if (which_alternative != 0)
14006     return \"#\";
14007   else if (get_attr_length (insn) == 4)
14008     return \"bdz %l0\";
14009   else
14010     return \"{bdn|bdnz} $+8\;b %l0\";
14011 }"
14012   [(set_attr "type" "branch")
14013    (set_attr "length" "*,12,16,16")])
14014
14015 (define_insn "*ctrdi_internal1"
14016   [(set (pc)
14017         (if_then_else (ne (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14018                           (const_int 1))
14019                       (label_ref (match_operand 0 "" ""))
14020                       (pc)))
14021    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14022         (plus:DI (match_dup 1)
14023                  (const_int -1)))
14024    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14025    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14026   "TARGET_64BIT"
14027   "*
14028 {
14029   if (which_alternative != 0)
14030     return \"#\";
14031   else if (get_attr_length (insn) == 4)
14032     return \"{bdn|bdnz} %l0\";
14033   else
14034     return \"bdz $+8\;b %l0\";
14035 }"
14036   [(set_attr "type" "branch")
14037    (set_attr "length" "*,12,16,16")])
14038
14039 (define_insn "*ctrdi_internal2"
14040   [(set (pc)
14041         (if_then_else (ne (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14042                           (const_int 1))
14043                       (pc)
14044                       (label_ref (match_operand 0 "" ""))))
14045    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14046         (plus:DI (match_dup 1)
14047                  (const_int -1)))
14048    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14049    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14050   "TARGET_64BIT"
14051   "*
14052 {
14053   if (which_alternative != 0)
14054     return \"#\";
14055   else if (get_attr_length (insn) == 4)
14056     return \"bdz %l0\";
14057   else
14058     return \"{bdn|bdnz} $+8\;b %l0\";
14059 }"
14060   [(set_attr "type" "branch")
14061    (set_attr "length" "*,12,16,16")])
14062
14063 ;; Similar but use EQ
14064
14065 (define_insn "*ctrsi_internal5"
14066   [(set (pc)
14067         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14068                           (const_int 1))
14069                       (label_ref (match_operand 0 "" ""))
14070                       (pc)))
14071    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14072         (plus:SI (match_dup 1)
14073                  (const_int -1)))
14074    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14075    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14076   "TARGET_32BIT"
14077   "*
14078 {
14079   if (which_alternative != 0)
14080     return \"#\";
14081   else if (get_attr_length (insn) == 4)
14082     return \"bdz %l0\";
14083   else
14084     return \"{bdn|bdnz} $+8\;b %l0\";
14085 }"
14086   [(set_attr "type" "branch")
14087    (set_attr "length" "*,12,16,16")])
14088
14089 (define_insn "*ctrsi_internal6"
14090   [(set (pc)
14091         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14092                           (const_int 1))
14093                       (pc)
14094                       (label_ref (match_operand 0 "" ""))))
14095    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14096         (plus:SI (match_dup 1)
14097                  (const_int -1)))
14098    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14099    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14100   "TARGET_32BIT"
14101   "*
14102 {
14103   if (which_alternative != 0)
14104     return \"#\";
14105   else if (get_attr_length (insn) == 4)
14106     return \"{bdn|bdnz} %l0\";
14107   else
14108     return \"bdz $+8\;b %l0\";
14109 }"
14110   [(set_attr "type" "branch")
14111    (set_attr "length" "*,12,16,16")])
14112
14113 (define_insn "*ctrdi_internal5"
14114   [(set (pc)
14115         (if_then_else (eq (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14116                           (const_int 1))
14117                       (label_ref (match_operand 0 "" ""))
14118                       (pc)))
14119    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14120         (plus:DI (match_dup 1)
14121                  (const_int -1)))
14122    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14123    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14124   "TARGET_64BIT"
14125   "*
14126 {
14127   if (which_alternative != 0)
14128     return \"#\";
14129   else if (get_attr_length (insn) == 4)
14130     return \"bdz %l0\";
14131   else
14132     return \"{bdn|bdnz} $+8\;b %l0\";
14133 }"
14134   [(set_attr "type" "branch")
14135    (set_attr "length" "*,12,16,16")])
14136
14137 (define_insn "*ctrdi_internal6"
14138   [(set (pc)
14139         (if_then_else (eq (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14140                           (const_int 1))
14141                       (pc)
14142                       (label_ref (match_operand 0 "" ""))))
14143    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14144         (plus:DI (match_dup 1)
14145                  (const_int -1)))
14146    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14147    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14148   "TARGET_64BIT"
14149   "*
14150 {
14151   if (which_alternative != 0)
14152     return \"#\";
14153   else if (get_attr_length (insn) == 4)
14154     return \"{bdn|bdnz} %l0\";
14155   else
14156     return \"bdz $+8\;b %l0\";
14157 }"
14158   [(set_attr "type" "branch")
14159    (set_attr "length" "*,12,16,16")])
14160
14161 ;; Now the splitters if we could not allocate the CTR register
14162
14163 (define_split
14164   [(set (pc)
14165         (if_then_else (match_operator 2 "comparison_operator"
14166                                       [(match_operand:SI 1 "gpc_reg_operand" "")
14167                                        (const_int 1)])
14168                       (match_operand 5 "" "")
14169                       (match_operand 6 "" "")))
14170    (set (match_operand:SI 0 "gpc_reg_operand" "")
14171         (plus:SI (match_dup 1)
14172                  (const_int -1)))
14173    (clobber (match_scratch:CC 3 ""))
14174    (clobber (match_scratch:SI 4 ""))]
14175   "TARGET_32BIT && reload_completed"
14176   [(parallel [(set (match_dup 3)
14177                    (compare:CC (plus:SI (match_dup 1)
14178                                         (const_int -1))
14179                                (const_int 0)))
14180               (set (match_dup 0)
14181                    (plus:SI (match_dup 1)
14182                             (const_int -1)))])
14183    (set (pc) (if_then_else (match_dup 7)
14184                            (match_dup 5)
14185                            (match_dup 6)))]
14186   "
14187 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14188                                 operands[3], const0_rtx); }")
14189
14190 (define_split
14191   [(set (pc)
14192         (if_then_else (match_operator 2 "comparison_operator"
14193                                       [(match_operand:SI 1 "gpc_reg_operand" "")
14194                                        (const_int 1)])
14195                       (match_operand 5 "" "")
14196                       (match_operand 6 "" "")))
14197    (set (match_operand:SI 0 "nonimmediate_operand" "")
14198         (plus:SI (match_dup 1) (const_int -1)))
14199    (clobber (match_scratch:CC 3 ""))
14200    (clobber (match_scratch:SI 4 ""))]
14201   "TARGET_32BIT && reload_completed
14202    && ! gpc_reg_operand (operands[0], SImode)"
14203   [(parallel [(set (match_dup 3)
14204                    (compare:CC (plus:SI (match_dup 1)
14205                                         (const_int -1))
14206                                (const_int 0)))
14207               (set (match_dup 4)
14208                    (plus:SI (match_dup 1)
14209                             (const_int -1)))])
14210    (set (match_dup 0)
14211         (match_dup 4))
14212    (set (pc) (if_then_else (match_dup 7)
14213                            (match_dup 5)
14214                            (match_dup 6)))]
14215   "
14216 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14217                                 operands[3], const0_rtx); }")
14218 (define_split
14219   [(set (pc)
14220         (if_then_else (match_operator 2 "comparison_operator"
14221                                       [(match_operand:DI 1 "gpc_reg_operand" "")
14222                                        (const_int 1)])
14223                       (match_operand 5 "" "")
14224                       (match_operand 6 "" "")))
14225    (set (match_operand:DI 0 "gpc_reg_operand" "")
14226         (plus:DI (match_dup 1)
14227                  (const_int -1)))
14228    (clobber (match_scratch:CC 3 ""))
14229    (clobber (match_scratch:DI 4 ""))]
14230   "TARGET_64BIT && reload_completed"
14231   [(parallel [(set (match_dup 3)
14232                    (compare:CC (plus:DI (match_dup 1)
14233                                         (const_int -1))
14234                                (const_int 0)))
14235               (set (match_dup 0)
14236                    (plus:DI (match_dup 1)
14237                             (const_int -1)))])
14238    (set (pc) (if_then_else (match_dup 7)
14239                            (match_dup 5)
14240                            (match_dup 6)))]
14241   "
14242 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14243                                 operands[3], const0_rtx); }")
14244
14245 (define_split
14246   [(set (pc)
14247         (if_then_else (match_operator 2 "comparison_operator"
14248                                       [(match_operand:DI 1 "gpc_reg_operand" "")
14249                                        (const_int 1)])
14250                       (match_operand 5 "" "")
14251                       (match_operand 6 "" "")))
14252    (set (match_operand:DI 0 "nonimmediate_operand" "")
14253         (plus:DI (match_dup 1) (const_int -1)))
14254    (clobber (match_scratch:CC 3 ""))
14255    (clobber (match_scratch:DI 4 ""))]
14256   "TARGET_64BIT && reload_completed
14257    && ! gpc_reg_operand (operands[0], DImode)"
14258   [(parallel [(set (match_dup 3)
14259                    (compare:CC (plus:DI (match_dup 1)
14260                                         (const_int -1))
14261                                (const_int 0)))
14262               (set (match_dup 4)
14263                    (plus:DI (match_dup 1)
14264                             (const_int -1)))])
14265    (set (match_dup 0)
14266         (match_dup 4))
14267    (set (pc) (if_then_else (match_dup 7)
14268                            (match_dup 5)
14269                            (match_dup 6)))]
14270   "
14271 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14272                                 operands[3], const0_rtx); }")
14273 \f
14274 (define_insn "trap"
14275   [(trap_if (const_int 1) (const_int 0))]
14276   ""
14277   "{t 31,0,0|trap}")
14278
14279 (define_expand "conditional_trap"
14280   [(trap_if (match_operator 0 "trap_comparison_operator"
14281                             [(match_dup 2) (match_dup 3)])
14282             (match_operand 1 "const_int_operand" ""))]
14283   ""
14284   "if (rs6000_compare_fp_p || operands[1] != const0_rtx) FAIL;
14285    operands[2] = rs6000_compare_op0;
14286    operands[3] = rs6000_compare_op1;")
14287
14288 (define_insn ""
14289   [(trap_if (match_operator 0 "trap_comparison_operator"
14290                             [(match_operand:SI 1 "register_operand" "r")
14291                              (match_operand:SI 2 "reg_or_short_operand" "rI")])
14292             (const_int 0))]
14293   ""
14294   "{t|tw}%V0%I2 %1,%2")
14295
14296 (define_insn ""
14297   [(trap_if (match_operator 0 "trap_comparison_operator"
14298                             [(match_operand:DI 1 "register_operand" "r")
14299                              (match_operand:DI 2 "reg_or_short_operand" "rI")])
14300             (const_int 0))]
14301   "TARGET_POWERPC64"
14302   "td%V0%I2 %1,%2")
14303 \f
14304 ;; Insns related to generating the function prologue and epilogue.
14305
14306 (define_expand "prologue"
14307   [(use (const_int 0))]
14308   "TARGET_SCHED_PROLOG"
14309   "
14310 {
14311       rs6000_emit_prologue ();
14312       DONE;
14313 }")
14314
14315 (define_insn "*movesi_from_cr_one"
14316   [(match_parallel 0 "mfcr_operation"
14317                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14318                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
14319                                      (match_operand 3 "immediate_operand" "n")]
14320                           UNSPEC_MOVESI_FROM_CR))])]
14321   "TARGET_MFCRF"
14322   "*
14323 {
14324   int mask = 0;
14325   int i;
14326   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14327   {
14328     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14329     operands[4] = GEN_INT (mask);
14330     output_asm_insn (\"mfcr %1,%4\", operands);
14331   }
14332   return \"\";
14333 }"
14334   [(set_attr "type" "mfcrf")])
14335
14336 (define_insn "movesi_from_cr"
14337   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14338         (unspec:SI [(reg:CC 68) (reg:CC 69) (reg:CC 70) (reg:CC 71)
14339                     (reg:CC 72) (reg:CC 73) (reg:CC 74) (reg:CC 75)]
14340                    UNSPEC_MOVESI_FROM_CR))]
14341   ""
14342   "mfcr %0"
14343   [(set_attr "type" "mfcr")])
14344
14345 (define_insn "*stmw"
14346   [(match_parallel 0 "stmw_operation"
14347                    [(set (match_operand:SI 1 "memory_operand" "=m")
14348                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
14349   "TARGET_MULTIPLE"
14350   "{stm|stmw} %2,%1")
14351
14352 (define_insn "*save_fpregs_si"
14353   [(match_parallel 0 "any_operand"
14354                    [(clobber (match_operand:SI 1 "register_operand" "=l"))
14355                     (use (match_operand:SI 2 "call_operand" "s"))
14356                     (set (match_operand:DF 3 "memory_operand" "=m")
14357                          (match_operand:DF 4 "gpc_reg_operand" "f"))])]
14358   "TARGET_32BIT"
14359   "bl %z2"
14360   [(set_attr "type" "branch")
14361    (set_attr "length" "4")])
14362
14363 (define_insn "*save_fpregs_di"
14364   [(match_parallel 0 "any_operand"
14365                    [(clobber (match_operand:DI 1 "register_operand" "=l"))
14366                     (use (match_operand:DI 2 "call_operand" "s"))
14367                     (set (match_operand:DF 3 "memory_operand" "=m")
14368                          (match_operand:DF 4 "gpc_reg_operand" "f"))])]
14369   "TARGET_64BIT"
14370   "bl %z2"
14371   [(set_attr "type" "branch")
14372    (set_attr "length" "4")])
14373
14374 ; These are to explain that changes to the stack pointer should
14375 ; not be moved over stores to stack memory.
14376 (define_insn "stack_tie"
14377   [(set (match_operand:BLK 0 "memory_operand" "+m")
14378         (unspec:BLK [(match_dup 0)] UNSPEC_TIE))]
14379   ""
14380   ""
14381   [(set_attr "length" "0")])
14382
14383
14384 (define_expand "epilogue"
14385   [(use (const_int 0))]
14386   "TARGET_SCHED_PROLOG"
14387   "
14388 {
14389       rs6000_emit_epilogue (FALSE);
14390       DONE;
14391 }")
14392
14393 ; On some processors, doing the mtcrf one CC register at a time is
14394 ; faster (like on the 604e).  On others, doing them all at once is
14395 ; faster; for instance, on the 601 and 750.
14396
14397 (define_expand "movsi_to_cr_one"
14398   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14399         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14400                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
14401   ""
14402   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
14403
14404 (define_insn "*movsi_to_cr"
14405   [(match_parallel 0 "mtcrf_operation"
14406                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
14407                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
14408                                      (match_operand 3 "immediate_operand" "n")]
14409                                     UNSPEC_MOVESI_TO_CR))])]
14410  ""
14411  "*
14412 {
14413   int mask = 0;
14414   int i;
14415   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14416     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14417   operands[4] = GEN_INT (mask);
14418   return \"mtcrf %4,%2\";
14419 }"
14420   [(set_attr "type" "mtcr")])
14421
14422 (define_insn "*mtcrfsi"
14423   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14424         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14425                     (match_operand 2 "immediate_operand" "n")]
14426                    UNSPEC_MOVESI_TO_CR))]
14427   "GET_CODE (operands[0]) == REG
14428    && CR_REGNO_P (REGNO (operands[0]))
14429    && GET_CODE (operands[2]) == CONST_INT
14430    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
14431   "mtcrf %R0,%1"
14432   [(set_attr "type" "mtcr")])
14433
14434 ; The load-multiple instructions have similar properties.
14435 ; Note that "load_multiple" is a name known to the machine-independent
14436 ; code that actually corresponds to the powerpc load-string.
14437
14438 (define_insn "*lmw"
14439   [(match_parallel 0 "lmw_operation"
14440                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14441                          (match_operand:SI 2 "memory_operand" "m"))])]
14442   "TARGET_MULTIPLE"
14443   "{lm|lmw} %1,%2")
14444
14445 (define_insn "*return_internal_si"
14446   [(return)
14447    (use (match_operand:SI 0 "register_operand" "lc"))]
14448   "TARGET_32BIT"
14449   "b%T0"
14450   [(set_attr "type" "jmpreg")])
14451
14452 (define_insn "*return_internal_di"
14453   [(return)
14454    (use (match_operand:DI 0 "register_operand" "lc"))]
14455   "TARGET_64BIT"
14456   "b%T0"
14457   [(set_attr "type" "jmpreg")])
14458
14459 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
14460 ; stuff was in GCC.  Oh, and "any_operand" is a bit flexible...
14461
14462 (define_insn "*return_and_restore_fpregs_si"
14463  [(match_parallel 0 "any_operand"
14464                   [(return)
14465                    (use (match_operand:SI 1 "register_operand" "l"))
14466                    (use (match_operand:SI 2 "call_operand" "s"))
14467                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
14468                         (match_operand:DF 4 "memory_operand" "m"))])]
14469  "TARGET_32BIT"
14470  "b %z2")
14471
14472 (define_insn "*return_and_restore_fpregs_di"
14473  [(match_parallel 0 "any_operand"
14474                   [(return)
14475                    (use (match_operand:DI 1 "register_operand" "l"))
14476                    (use (match_operand:DI 2 "call_operand" "s"))
14477                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
14478                         (match_operand:DF 4 "memory_operand" "m"))])]
14479  "TARGET_64BIT"
14480  "b %z2")
14481
14482 ; This is used in compiling the unwind routines.
14483 (define_expand "eh_return"
14484   [(use (match_operand 0 "general_operand" ""))]
14485   ""
14486   "
14487 {
14488   if (TARGET_32BIT)
14489     emit_insn (gen_eh_set_lr_si (operands[0]));
14490   else
14491     emit_insn (gen_eh_set_lr_di (operands[0]));
14492   DONE;
14493 }")
14494
14495 ; We can't expand this before we know where the link register is stored.
14496 (define_insn "eh_set_lr_si"
14497   [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
14498                     UNSPECV_EH_RR)
14499    (clobber (match_scratch:SI 1 "=&b"))]
14500   "TARGET_32BIT"
14501   "#")
14502
14503 (define_insn "eh_set_lr_di"
14504   [(unspec_volatile [(match_operand:DI 0 "register_operand" "r")]
14505                     UNSPECV_EH_RR)
14506    (clobber (match_scratch:DI 1 "=&b"))]
14507   "TARGET_64BIT"
14508   "#")
14509
14510 (define_split
14511   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
14512    (clobber (match_scratch 1 ""))]
14513   "reload_completed"
14514   [(const_int 0)]
14515   "
14516 {
14517   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
14518   DONE;
14519 }")
14520
14521 (define_insn "prefetch"
14522   [(prefetch (match_operand:V4SI 0 "address_operand" "p")
14523              (match_operand:SI 1 "const_int_operand" "n")
14524              (match_operand:SI 2 "const_int_operand" "n"))]
14525   "TARGET_POWERPC"
14526   "*
14527 {
14528   if (GET_CODE (operands[0]) == REG)
14529     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
14530   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
14531 }"
14532   [(set_attr "type" "load")])
14533
14534 (include "altivec.md")
14535 (include "spe.md")