OSDN Git Service

* config/rs6000/rs6000.md (UNSPEC_MV_CR_GT): New constant.
[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 (define_insn "insvdi"
3040   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3041                          (match_operand:SI 1 "const_int_operand" "i")
3042                          (match_operand:SI 2 "const_int_operand" "i"))
3043         (match_operand:DI 3 "gpc_reg_operand" "r"))]
3044   "TARGET_POWERPC64"
3045   "*
3046 {
3047   int start = INTVAL (operands[2]) & 63;
3048   int size = INTVAL (operands[1]) & 63;
3049
3050   operands[1] = GEN_INT (64 - start - size);
3051   return \"rldimi %0,%3,%H1,%H2\";
3052 }")
3053
3054 (define_expand "extzv"
3055   [(set (match_operand 0 "gpc_reg_operand" "")
3056         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3057                        (match_operand:SI 2 "const_int_operand" "")
3058                        (match_operand:SI 3 "const_int_operand" "")))]
3059   ""
3060   "
3061 {
3062   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3063      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3064      compiler if the address of the structure is taken later.  */
3065   if (GET_CODE (operands[0]) == SUBREG
3066       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3067     FAIL;
3068
3069   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3070     emit_insn (gen_extzvdi (operands[0], operands[1], operands[2], operands[3]));
3071   else
3072     emit_insn (gen_extzvsi (operands[0], operands[1], operands[2], operands[3]));
3073   DONE;
3074 }")
3075
3076 (define_insn "extzvsi"
3077   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3078         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3079                          (match_operand:SI 2 "const_int_operand" "i")
3080                          (match_operand:SI 3 "const_int_operand" "i")))]
3081   ""
3082   "*
3083 {
3084   int start = INTVAL (operands[3]) & 31;
3085   int size = INTVAL (operands[2]) & 31;
3086
3087   if (start + size >= 32)
3088     operands[3] = const0_rtx;
3089   else
3090     operands[3] = GEN_INT (start + size);
3091   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
3092 }")
3093
3094 (define_insn "*extzvsi_internal1"
3095   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3096         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3097                          (match_operand:SI 2 "const_int_operand" "i,i")
3098                          (match_operand:SI 3 "const_int_operand" "i,i"))
3099                     (const_int 0)))
3100    (clobber (match_scratch:SI 4 "=r,r"))]
3101   ""
3102   "*
3103 {
3104   int start = INTVAL (operands[3]) & 31;
3105   int size = INTVAL (operands[2]) & 31;
3106
3107   /* Force split for non-cc0 compare.  */
3108   if (which_alternative == 1)
3109      return \"#\";
3110
3111   /* If the bit-field being tested fits in the upper or lower half of a
3112      word, it is possible to use andiu. or andil. to test it.  This is
3113      useful because the condition register set-use delay is smaller for
3114      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3115      position is 0 because the LT and GT bits may be set wrong.  */
3116
3117   if ((start > 0 && start + size <= 16) || start >= 16)
3118     {
3119       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3120                               - (1 << (16 - (start & 15) - size))));
3121       if (start < 16)
3122         return \"{andiu.|andis.} %4,%1,%3\";
3123       else
3124         return \"{andil.|andi.} %4,%1,%3\";
3125     }
3126
3127   if (start + size >= 32)
3128     operands[3] = const0_rtx;
3129   else
3130     operands[3] = GEN_INT (start + size);
3131   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
3132 }"
3133   [(set_attr "type" "compare")
3134    (set_attr "length" "4,8")])
3135
3136 (define_split
3137   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3138         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3139                          (match_operand:SI 2 "const_int_operand" "")
3140                          (match_operand:SI 3 "const_int_operand" ""))
3141                     (const_int 0)))
3142    (clobber (match_scratch:SI 4 ""))]
3143   "reload_completed"
3144   [(set (match_dup 4)
3145         (zero_extract:SI (match_dup 1) (match_dup 2)
3146                          (match_dup 3)))
3147    (set (match_dup 0)
3148         (compare:CC (match_dup 4)
3149                     (const_int 0)))]
3150   "")
3151
3152 (define_insn "*extzvsi_internal2"
3153   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3154         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3155                          (match_operand:SI 2 "const_int_operand" "i,i")
3156                          (match_operand:SI 3 "const_int_operand" "i,i"))
3157                     (const_int 0)))
3158    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3159         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3160   ""
3161   "*
3162 {
3163   int start = INTVAL (operands[3]) & 31;
3164   int size = INTVAL (operands[2]) & 31;
3165
3166   /* Force split for non-cc0 compare.  */
3167   if (which_alternative == 1)
3168      return \"#\";
3169
3170   /* Since we are using the output value, we can't ignore any need for
3171      a shift.  The bit-field must end at the LSB.  */
3172   if (start >= 16 && start + size == 32)
3173     {
3174       operands[3] = GEN_INT ((1 << size) - 1);
3175       return \"{andil.|andi.} %0,%1,%3\";
3176     }
3177
3178   if (start + size >= 32)
3179     operands[3] = const0_rtx;
3180   else
3181     operands[3] = GEN_INT (start + size);
3182   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
3183 }"
3184   [(set_attr "type" "compare")
3185    (set_attr "length" "4,8")])
3186
3187 (define_split
3188   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3189         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3190                          (match_operand:SI 2 "const_int_operand" "")
3191                          (match_operand:SI 3 "const_int_operand" ""))
3192                     (const_int 0)))
3193    (set (match_operand:SI 0 "gpc_reg_operand" "")
3194         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3195   "reload_completed"
3196   [(set (match_dup 0)
3197         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3198    (set (match_dup 4)
3199         (compare:CC (match_dup 0)
3200                     (const_int 0)))]
3201   "")
3202
3203 (define_insn "extzvdi"
3204   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3205         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3206                          (match_operand:SI 2 "const_int_operand" "i")
3207                          (match_operand:SI 3 "const_int_operand" "i")))]
3208   "TARGET_POWERPC64"
3209   "*
3210 {
3211   int start = INTVAL (operands[3]) & 63;
3212   int size = INTVAL (operands[2]) & 63;
3213
3214   if (start + size >= 64)
3215     operands[3] = const0_rtx;
3216   else
3217     operands[3] = GEN_INT (start + size);
3218   operands[2] = GEN_INT (64 - size);
3219   return \"rldicl %0,%1,%3,%2\";
3220 }")
3221
3222 (define_insn "*extzvdi_internal1"
3223   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3224         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3225                          (match_operand:SI 2 "const_int_operand" "i")
3226                          (match_operand:SI 3 "const_int_operand" "i"))
3227                     (const_int 0)))
3228    (clobber (match_scratch:DI 4 "=r"))]
3229   "TARGET_64BIT"
3230   "*
3231 {
3232   int start = INTVAL (operands[3]) & 63;
3233   int size = INTVAL (operands[2]) & 63;
3234
3235   if (start + size >= 64)
3236     operands[3] = const0_rtx;
3237   else
3238     operands[3] = GEN_INT (start + size);
3239   operands[2] = GEN_INT (64 - size);
3240   return \"rldicl. %4,%1,%3,%2\";
3241 }")
3242
3243 (define_insn "*extzvdi_internal2"
3244   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3245         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3246                          (match_operand:SI 2 "const_int_operand" "i")
3247                          (match_operand:SI 3 "const_int_operand" "i"))
3248                     (const_int 0)))
3249    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3250         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3251   "TARGET_64BIT"
3252   "*
3253 {
3254   int start = INTVAL (operands[3]) & 63;
3255   int size = INTVAL (operands[2]) & 63;
3256
3257   if (start + size >= 64)
3258     operands[3] = const0_rtx;
3259   else
3260     operands[3] = GEN_INT (start + size);
3261   operands[2] = GEN_INT (64 - size);
3262   return \"rldicl. %0,%1,%3,%2\";
3263 }")
3264
3265 (define_insn "rotlsi3"
3266   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3267         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3268                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3269   ""
3270   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffffffff")
3271
3272 (define_insn "*rotlsi3_internal2"
3273   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3274         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3275                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3276                     (const_int 0)))
3277    (clobber (match_scratch:SI 3 "=r,r"))]
3278   ""
3279   "@
3280    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffffffff
3281    #"
3282   [(set_attr "type" "delayed_compare")
3283    (set_attr "length" "4,8")])
3284
3285 (define_split
3286   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3287         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3288                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3289                     (const_int 0)))
3290    (clobber (match_scratch:SI 3 ""))]
3291   "reload_completed"
3292   [(set (match_dup 3)
3293         (rotate:SI (match_dup 1) (match_dup 2)))
3294    (set (match_dup 0)
3295         (compare:CC (match_dup 3)
3296                     (const_int 0)))]
3297   "")
3298
3299 (define_insn "*rotlsi3_internal3"
3300   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3301         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3302                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3303                     (const_int 0)))
3304    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3305         (rotate:SI (match_dup 1) (match_dup 2)))]
3306   ""
3307   "@
3308    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffffffff
3309    #"
3310   [(set_attr "type" "delayed_compare")
3311    (set_attr "length" "4,8")])
3312
3313 (define_split
3314   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3315         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3316                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3317                     (const_int 0)))
3318    (set (match_operand:SI 0 "gpc_reg_operand" "")
3319         (rotate:SI (match_dup 1) (match_dup 2)))]
3320   "reload_completed"
3321   [(set (match_dup 0)
3322         (rotate:SI (match_dup 1) (match_dup 2)))
3323    (set (match_dup 3)
3324         (compare:CC (match_dup 0)
3325                     (const_int 0)))]
3326   "")
3327
3328 (define_insn "*rotlsi3_internal4"
3329   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3330         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3331                            (match_operand:SI 2 "reg_or_cint_operand" "ri"))
3332                 (match_operand:SI 3 "mask_operand" "n")))]
3333   ""
3334   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,%m3,%M3")
3335
3336 (define_insn "*rotlsi3_internal5"
3337   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3338         (compare:CC (and:SI
3339                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3340                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3341                      (match_operand:SI 3 "mask_operand" "n,n"))
3342                     (const_int 0)))
3343    (clobber (match_scratch:SI 4 "=r,r"))]
3344   ""
3345   "@
3346    {rl%I2nm.|rlw%I2nm.} %4,%1,%h2,%m3,%M3
3347    #"
3348   [(set_attr "type" "delayed_compare")
3349    (set_attr "length" "4,8")])
3350
3351 (define_split
3352   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3353         (compare:CC (and:SI
3354                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3355                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3356                      (match_operand:SI 3 "mask_operand" ""))
3357                     (const_int 0)))
3358    (clobber (match_scratch:SI 4 ""))]
3359   "reload_completed"
3360   [(set (match_dup 4)
3361         (and:SI (rotate:SI (match_dup 1)
3362                                 (match_dup 2))
3363                      (match_dup 3)))
3364    (set (match_dup 0)
3365         (compare:CC (match_dup 4)
3366                     (const_int 0)))]
3367   "")
3368
3369 (define_insn "*rotlsi3_internal6"
3370   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3371         (compare:CC (and:SI
3372                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3373                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3374                      (match_operand:SI 3 "mask_operand" "n,n"))
3375                     (const_int 0)))
3376    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3377         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3378   ""
3379   "@
3380    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,%m3,%M3
3381    #"
3382   [(set_attr "type" "delayed_compare")
3383    (set_attr "length" "4,8")])
3384
3385 (define_split
3386   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3387         (compare:CC (and:SI
3388                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3389                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3390                      (match_operand:SI 3 "mask_operand" ""))
3391                     (const_int 0)))
3392    (set (match_operand:SI 0 "gpc_reg_operand" "")
3393         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3394   "reload_completed"
3395   [(set (match_dup 0)
3396         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3397    (set (match_dup 4)
3398         (compare:CC (match_dup 0)
3399                     (const_int 0)))]
3400   "")
3401
3402 (define_insn "*rotlsi3_internal7"
3403   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3404         (zero_extend:SI
3405          (subreg:QI
3406           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3407                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3408   ""
3409   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff")
3410
3411 (define_insn "*rotlsi3_internal8"
3412   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3413         (compare:CC (zero_extend:SI
3414                      (subreg:QI
3415                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3416                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3417                     (const_int 0)))
3418    (clobber (match_scratch:SI 3 "=r,r"))]
3419   ""
3420   "@
3421    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xff
3422    #"
3423   [(set_attr "type" "delayed_compare")
3424    (set_attr "length" "4,8")])
3425
3426 (define_split
3427   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3428         (compare:CC (zero_extend:SI
3429                      (subreg:QI
3430                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3431                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3432                     (const_int 0)))
3433    (clobber (match_scratch:SI 3 ""))]
3434   "reload_completed"
3435   [(set (match_dup 3)
3436         (zero_extend:SI (subreg:QI
3437                       (rotate:SI (match_dup 1)
3438                                  (match_dup 2)) 0)))
3439    (set (match_dup 0)
3440         (compare:CC (match_dup 3)
3441                     (const_int 0)))]
3442   "")
3443
3444 (define_insn "*rotlsi3_internal9"
3445   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3446         (compare:CC (zero_extend:SI
3447                      (subreg:QI
3448                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3449                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3450                     (const_int 0)))
3451    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3452         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3453   ""
3454   "@
3455    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xff
3456    #"
3457   [(set_attr "type" "delayed_compare")
3458    (set_attr "length" "4,8")])
3459
3460 (define_split
3461   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3462         (compare:CC (zero_extend:SI
3463                      (subreg:QI
3464                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3465                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3466                     (const_int 0)))
3467    (set (match_operand:SI 0 "gpc_reg_operand" "")
3468         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3469   "reload_completed"
3470   [(set (match_dup 0)
3471         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3472    (set (match_dup 3)
3473         (compare:CC (match_dup 0)
3474                     (const_int 0)))]
3475   "")
3476
3477 (define_insn "*rotlsi3_internal10"
3478   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3479         (zero_extend:SI
3480          (subreg:HI
3481           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3482                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3483   ""
3484   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffff")
3485
3486 (define_insn "*rotlsi3_internal11"
3487   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3488         (compare:CC (zero_extend:SI
3489                      (subreg:HI
3490                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3491                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3492                     (const_int 0)))
3493    (clobber (match_scratch:SI 3 "=r,r"))]
3494   ""
3495   "@
3496    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffff
3497    #"
3498   [(set_attr "type" "delayed_compare")
3499    (set_attr "length" "4,8")])
3500
3501 (define_split
3502   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3503         (compare:CC (zero_extend:SI
3504                      (subreg:HI
3505                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3506                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3507                     (const_int 0)))
3508    (clobber (match_scratch:SI 3 ""))]
3509   "reload_completed"
3510   [(set (match_dup 3)
3511         (zero_extend:SI (subreg:HI
3512                       (rotate:SI (match_dup 1)
3513                                  (match_dup 2)) 0)))
3514    (set (match_dup 0)
3515         (compare:CC (match_dup 3)
3516                     (const_int 0)))]
3517   "")
3518
3519 (define_insn "*rotlsi3_internal12"
3520   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3521         (compare:CC (zero_extend:SI
3522                      (subreg:HI
3523                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3524                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3525                     (const_int 0)))
3526    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3527         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3528   ""
3529   "@
3530    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffff
3531    #"
3532   [(set_attr "type" "delayed_compare")
3533    (set_attr "length" "4,8")])
3534
3535 (define_split
3536   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3537         (compare:CC (zero_extend:SI
3538                      (subreg:HI
3539                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3540                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3541                     (const_int 0)))
3542    (set (match_operand:SI 0 "gpc_reg_operand" "")
3543         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3544   "reload_completed"
3545   [(set (match_dup 0)
3546         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3547    (set (match_dup 3)
3548         (compare:CC (match_dup 0)
3549                     (const_int 0)))]
3550   "")
3551
3552 ;; Note that we use "sle." instead of "sl." so that we can set
3553 ;; SHIFT_COUNT_TRUNCATED.
3554
3555 (define_expand "ashlsi3"
3556   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
3557    (use (match_operand:SI 1 "gpc_reg_operand" ""))
3558    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
3559   ""
3560   "
3561 {
3562   if (TARGET_POWER)
3563     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
3564   else
3565     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
3566   DONE;
3567 }")
3568
3569 (define_insn "ashlsi3_power"
3570   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3571         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3572                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
3573    (clobber (match_scratch:SI 3 "=q,X"))]
3574   "TARGET_POWER"
3575   "@
3576    sle %0,%1,%2
3577    {sli|slwi} %0,%1,%h2")
3578
3579 (define_insn "ashlsi3_no_power"
3580   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3581         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3582                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3583   "! TARGET_POWER"
3584   "{sl|slw}%I2 %0,%1,%h2")
3585
3586 (define_insn ""
3587   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3588         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3589                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3590                     (const_int 0)))
3591    (clobber (match_scratch:SI 3 "=r,r,r,r"))
3592    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
3593   "TARGET_POWER"
3594   "@
3595    sle. %3,%1,%2
3596    {sli.|slwi.} %3,%1,%h2
3597    #
3598    #"
3599   [(set_attr "type" "delayed_compare")
3600    (set_attr "length" "4,4,8,8")])
3601
3602 (define_split
3603   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3604         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3605                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3606                     (const_int 0)))
3607    (clobber (match_scratch:SI 3 ""))
3608    (clobber (match_scratch:SI 4 ""))]
3609   "TARGET_POWER && reload_completed"
3610   [(parallel [(set (match_dup 3)
3611         (ashift:SI (match_dup 1) (match_dup 2)))
3612    (clobber (match_dup 4))])
3613    (set (match_dup 0)
3614         (compare:CC (match_dup 3)
3615                     (const_int 0)))]
3616   "")
3617
3618 (define_insn ""
3619   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3620         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3621                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3622                     (const_int 0)))
3623    (clobber (match_scratch:SI 3 "=r,r"))]
3624   "! TARGET_POWER && TARGET_32BIT"
3625   "@
3626    {sl|slw}%I2. %3,%1,%h2
3627    #"
3628   [(set_attr "type" "delayed_compare")
3629    (set_attr "length" "4,8")])
3630
3631 (define_split
3632   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3633         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3634                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3635                     (const_int 0)))
3636    (clobber (match_scratch:SI 3 ""))]
3637   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3638   [(set (match_dup 3)
3639         (ashift:SI (match_dup 1) (match_dup 2)))
3640    (set (match_dup 0)
3641         (compare:CC (match_dup 3)
3642                     (const_int 0)))]
3643   "")
3644
3645 (define_insn ""
3646   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3647         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3648                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3649                     (const_int 0)))
3650    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3651         (ashift:SI (match_dup 1) (match_dup 2)))
3652    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
3653   "TARGET_POWER"
3654   "@
3655    sle. %0,%1,%2
3656    {sli.|slwi.} %0,%1,%h2
3657    #
3658    #"
3659   [(set_attr "type" "delayed_compare")
3660    (set_attr "length" "4,4,8,8")])
3661
3662 (define_split
3663   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3664         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3665                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3666                     (const_int 0)))
3667    (set (match_operand:SI 0 "gpc_reg_operand" "")
3668         (ashift:SI (match_dup 1) (match_dup 2)))
3669    (clobber (match_scratch:SI 4 ""))]
3670   "TARGET_POWER && reload_completed"
3671   [(parallel [(set (match_dup 0)
3672         (ashift:SI (match_dup 1) (match_dup 2)))
3673    (clobber (match_dup 4))])
3674    (set (match_dup 3)
3675         (compare:CC (match_dup 0)
3676                     (const_int 0)))]
3677   "")
3678
3679 (define_insn ""
3680   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3681         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3682                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3683                     (const_int 0)))
3684    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3685         (ashift:SI (match_dup 1) (match_dup 2)))]
3686   "! TARGET_POWER && TARGET_32BIT"
3687   "@
3688    {sl|slw}%I2. %0,%1,%h2
3689    #"
3690   [(set_attr "type" "delayed_compare")
3691    (set_attr "length" "4,8")])
3692
3693 (define_split
3694   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3695         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3696                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3697                     (const_int 0)))
3698    (set (match_operand:SI 0 "gpc_reg_operand" "")
3699         (ashift:SI (match_dup 1) (match_dup 2)))]
3700   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3701   [(set (match_dup 0)
3702         (ashift:SI (match_dup 1) (match_dup 2)))
3703    (set (match_dup 3)
3704         (compare:CC (match_dup 0)
3705                     (const_int 0)))]
3706   "")
3707
3708 (define_insn ""
3709   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3710         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3711                            (match_operand:SI 2 "const_int_operand" "i"))
3712                 (match_operand:SI 3 "mask_operand" "n")))]
3713   "includes_lshift_p (operands[2], operands[3])"
3714   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
3715
3716 (define_insn ""
3717   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3718         (compare:CC
3719          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3720                             (match_operand:SI 2 "const_int_operand" "i,i"))
3721                  (match_operand:SI 3 "mask_operand" "n,n"))
3722          (const_int 0)))
3723    (clobber (match_scratch:SI 4 "=r,r"))]
3724   "includes_lshift_p (operands[2], operands[3])"
3725   "@
3726    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
3727    #"
3728   [(set_attr "type" "delayed_compare")
3729    (set_attr "length" "4,8")])
3730
3731 (define_split
3732   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3733         (compare:CC
3734          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3735                             (match_operand:SI 2 "const_int_operand" ""))
3736                  (match_operand:SI 3 "mask_operand" ""))
3737          (const_int 0)))
3738    (clobber (match_scratch:SI 4 ""))]
3739   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
3740   [(set (match_dup 4)
3741         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
3742                  (match_dup 3)))
3743    (set (match_dup 0)
3744         (compare:CC (match_dup 4)
3745                     (const_int 0)))]
3746   "")
3747
3748 (define_insn ""
3749   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3750         (compare:CC
3751          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3752                             (match_operand:SI 2 "const_int_operand" "i,i"))
3753                  (match_operand:SI 3 "mask_operand" "n,n"))
3754          (const_int 0)))
3755    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3756         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3757   "includes_lshift_p (operands[2], operands[3])"
3758   "@
3759    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
3760    #"
3761   [(set_attr "type" "delayed_compare")
3762    (set_attr "length" "4,8")])
3763
3764 (define_split
3765   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3766         (compare:CC
3767          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3768                             (match_operand:SI 2 "const_int_operand" ""))
3769                  (match_operand:SI 3 "mask_operand" ""))
3770          (const_int 0)))
3771    (set (match_operand:SI 0 "gpc_reg_operand" "")
3772         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3773   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
3774   [(set (match_dup 0)
3775         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3776    (set (match_dup 4)
3777         (compare:CC (match_dup 0)
3778                     (const_int 0)))]
3779   "")
3780
3781 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
3782 ;; "sli x,x,0".
3783 (define_expand "lshrsi3"
3784   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
3785    (use (match_operand:SI 1 "gpc_reg_operand" ""))
3786    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
3787   ""
3788   "
3789 {
3790   if (TARGET_POWER)
3791     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
3792   else
3793     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
3794   DONE;
3795 }")
3796
3797 (define_insn "lshrsi3_power"
3798   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
3799         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
3800                      (match_operand:SI 2 "reg_or_cint_operand" "r,O,i")))
3801    (clobber (match_scratch:SI 3 "=q,X,X"))]
3802   "TARGET_POWER"
3803   "@
3804   sre %0,%1,%2
3805   mr %0,%1
3806   {s%A2i|s%A2wi} %0,%1,%h2")
3807
3808 (define_insn "lshrsi3_no_power"
3809   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3810         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3811                      (match_operand:SI 2 "reg_or_cint_operand" "O,ri")))]
3812   "! TARGET_POWER"
3813   "@
3814   mr %0,%1
3815   {sr|srw}%I2 %0,%1,%h2")
3816
3817 (define_insn ""
3818   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
3819         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
3820                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
3821                     (const_int 0)))
3822    (clobber (match_scratch:SI 3 "=r,X,r,r,X,r"))
3823    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
3824   "TARGET_POWER"
3825   "@
3826   sre. %3,%1,%2
3827   mr. %1,%1
3828   {s%A2i.|s%A2wi.} %3,%1,%h2
3829   #
3830   #
3831   #"
3832   [(set_attr "type" "delayed_compare")
3833    (set_attr "length" "4,4,4,8,8,8")])
3834
3835 (define_split
3836   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3837         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3838                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3839                     (const_int 0)))
3840    (clobber (match_scratch:SI 3 ""))
3841    (clobber (match_scratch:SI 4 ""))]
3842   "TARGET_POWER && reload_completed"
3843   [(parallel [(set (match_dup 3)
3844         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3845    (clobber (match_dup 4))])
3846    (set (match_dup 0)
3847         (compare:CC (match_dup 3)
3848                     (const_int 0)))]
3849   "")
3850
3851 (define_insn ""
3852   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3853         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3854                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
3855                     (const_int 0)))
3856    (clobber (match_scratch:SI 3 "=X,r,X,r"))]
3857   "! TARGET_POWER && TARGET_32BIT"
3858   "@
3859    mr. %1,%1
3860    {sr|srw}%I2. %3,%1,%h2
3861    #
3862    #"
3863   [(set_attr "type" "delayed_compare")
3864    (set_attr "length" "4,4,8,8")])
3865
3866 (define_split
3867   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3868         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3869                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3870                     (const_int 0)))
3871    (clobber (match_scratch:SI 3 ""))]
3872   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3873   [(set (match_dup 3)
3874         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3875    (set (match_dup 0)
3876         (compare:CC (match_dup 3)
3877                     (const_int 0)))]
3878   "")
3879
3880 (define_insn ""
3881   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
3882         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
3883                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
3884                     (const_int 0)))
3885    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
3886         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3887    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
3888   "TARGET_POWER"
3889   "@
3890   sre. %0,%1,%2
3891   mr. %0,%1
3892   {s%A2i.|s%A2wi.} %0,%1,%h2
3893   #
3894   #
3895   #"
3896   [(set_attr "type" "delayed_compare")
3897    (set_attr "length" "4,4,4,8,8,8")])
3898
3899 (define_split
3900   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3901         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3902                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3903                     (const_int 0)))
3904    (set (match_operand:SI 0 "gpc_reg_operand" "")
3905         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3906    (clobber (match_scratch:SI 4 ""))]
3907   "TARGET_POWER && reload_completed"
3908   [(parallel [(set (match_dup 0)
3909         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3910    (clobber (match_dup 4))])
3911    (set (match_dup 3)
3912         (compare:CC (match_dup 0)
3913                     (const_int 0)))]
3914   "")
3915
3916 (define_insn ""
3917   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3918         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3919                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
3920                     (const_int 0)))
3921    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3922         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
3923   "! TARGET_POWER && TARGET_32BIT"
3924   "@
3925    mr. %0,%1
3926    {sr|srw}%I2. %0,%1,%h2
3927    #
3928    #"
3929   [(set_attr "type" "delayed_compare")
3930    (set_attr "length" "4,4,8,8")])
3931
3932 (define_split
3933   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3934         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3935                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3936                     (const_int 0)))
3937    (set (match_operand:SI 0 "gpc_reg_operand" "")
3938         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
3939   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3940   [(set (match_dup 0)
3941         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3942    (set (match_dup 3)
3943         (compare:CC (match_dup 0)
3944                     (const_int 0)))]
3945   "")
3946
3947 (define_insn ""
3948   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3949         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3950                              (match_operand:SI 2 "const_int_operand" "i"))
3951                 (match_operand:SI 3 "mask_operand" "n")))]
3952   "includes_rshift_p (operands[2], operands[3])"
3953   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
3954
3955 (define_insn ""
3956   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3957         (compare:CC
3958          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3959                               (match_operand:SI 2 "const_int_operand" "i,i"))
3960                  (match_operand:SI 3 "mask_operand" "n,n"))
3961          (const_int 0)))
3962    (clobber (match_scratch:SI 4 "=r,r"))]
3963   "includes_rshift_p (operands[2], operands[3])"
3964   "@
3965    {rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3
3966    #"
3967   [(set_attr "type" "delayed_compare")
3968    (set_attr "length" "4,8")])
3969
3970 (define_split
3971   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3972         (compare:CC
3973          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3974                               (match_operand:SI 2 "const_int_operand" ""))
3975                  (match_operand:SI 3 "mask_operand" ""))
3976          (const_int 0)))
3977    (clobber (match_scratch:SI 4 ""))]
3978   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
3979   [(set (match_dup 4)
3980         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
3981                  (match_dup 3)))
3982    (set (match_dup 0)
3983         (compare:CC (match_dup 4)
3984                     (const_int 0)))]
3985   "")
3986
3987 (define_insn ""
3988   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3989         (compare:CC
3990          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3991                               (match_operand:SI 2 "const_int_operand" "i,i"))
3992                  (match_operand:SI 3 "mask_operand" "n,n"))
3993          (const_int 0)))
3994    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3995         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3996   "includes_rshift_p (operands[2], operands[3])"
3997   "@
3998    {rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3
3999    #"
4000   [(set_attr "type" "delayed_compare")
4001    (set_attr "length" "4,8")])
4002
4003 (define_split
4004   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4005         (compare:CC
4006          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4007                               (match_operand:SI 2 "const_int_operand" ""))
4008                  (match_operand:SI 3 "mask_operand" ""))
4009          (const_int 0)))
4010    (set (match_operand:SI 0 "gpc_reg_operand" "")
4011         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4012   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4013   [(set (match_dup 0)
4014         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4015    (set (match_dup 4)
4016         (compare:CC (match_dup 0)
4017                     (const_int 0)))]
4018   "")
4019
4020 (define_insn ""
4021   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4022         (zero_extend:SI
4023          (subreg:QI
4024           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4025                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4026   "includes_rshift_p (operands[2], GEN_INT (255))"
4027   "{rlinm|rlwinm} %0,%1,%s2,0xff")
4028
4029 (define_insn ""
4030   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4031         (compare:CC
4032          (zero_extend:SI
4033           (subreg:QI
4034            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4035                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4036          (const_int 0)))
4037    (clobber (match_scratch:SI 3 "=r,r"))]
4038   "includes_rshift_p (operands[2], GEN_INT (255))"
4039   "@
4040    {rlinm.|rlwinm.} %3,%1,%s2,0xff
4041    #"
4042   [(set_attr "type" "delayed_compare")
4043    (set_attr "length" "4,8")])
4044
4045 (define_split
4046   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4047         (compare:CC
4048          (zero_extend:SI
4049           (subreg:QI
4050            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4051                         (match_operand:SI 2 "const_int_operand" "")) 0))
4052          (const_int 0)))
4053    (clobber (match_scratch:SI 3 ""))]
4054   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4055   [(set (match_dup 3)
4056         (zero_extend:SI (subreg:QI
4057            (lshiftrt:SI (match_dup 1)
4058                         (match_dup 2)) 0)))
4059    (set (match_dup 0)
4060         (compare:CC (match_dup 3)
4061                     (const_int 0)))]
4062   "")
4063
4064 (define_insn ""
4065   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4066         (compare:CC
4067          (zero_extend:SI
4068           (subreg:QI
4069            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4070                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4071          (const_int 0)))
4072    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4073         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4074   "includes_rshift_p (operands[2], GEN_INT (255))"
4075   "@
4076    {rlinm.|rlwinm.} %0,%1,%s2,0xff
4077    #"
4078   [(set_attr "type" "delayed_compare")
4079    (set_attr "length" "4,8")])
4080
4081 (define_split
4082   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4083         (compare:CC
4084          (zero_extend:SI
4085           (subreg:QI
4086            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4087                         (match_operand:SI 2 "const_int_operand" "")) 0))
4088          (const_int 0)))
4089    (set (match_operand:SI 0 "gpc_reg_operand" "")
4090         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4091   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4092   [(set (match_dup 0)
4093         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4094    (set (match_dup 3)
4095         (compare:CC (match_dup 0)
4096                     (const_int 0)))]
4097   "")
4098
4099 (define_insn ""
4100   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4101         (zero_extend:SI
4102          (subreg:HI
4103           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4104                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4105   "includes_rshift_p (operands[2], GEN_INT (65535))"
4106   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
4107
4108 (define_insn ""
4109   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4110         (compare:CC
4111          (zero_extend:SI
4112           (subreg:HI
4113            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4114                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4115          (const_int 0)))
4116    (clobber (match_scratch:SI 3 "=r,r"))]
4117   "includes_rshift_p (operands[2], GEN_INT (65535))"
4118   "@
4119    {rlinm.|rlwinm.} %3,%1,%s2,0xffff
4120    #"
4121   [(set_attr "type" "delayed_compare")
4122    (set_attr "length" "4,8")])
4123
4124 (define_split
4125   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4126         (compare:CC
4127          (zero_extend:SI
4128           (subreg:HI
4129            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4130                         (match_operand:SI 2 "const_int_operand" "")) 0))
4131          (const_int 0)))
4132    (clobber (match_scratch:SI 3 ""))]
4133   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4134   [(set (match_dup 3)
4135         (zero_extend:SI (subreg:HI
4136            (lshiftrt:SI (match_dup 1)
4137                         (match_dup 2)) 0)))
4138    (set (match_dup 0)
4139         (compare:CC (match_dup 3)
4140                     (const_int 0)))]
4141   "")
4142
4143 (define_insn ""
4144   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4145         (compare:CC
4146          (zero_extend:SI
4147           (subreg:HI
4148            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4149                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4150          (const_int 0)))
4151    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4152         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4153   "includes_rshift_p (operands[2], GEN_INT (65535))"
4154   "@
4155    {rlinm.|rlwinm.} %0,%1,%s2,0xffff
4156    #"
4157   [(set_attr "type" "delayed_compare")
4158    (set_attr "length" "4,8")])
4159
4160 (define_split
4161   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4162         (compare:CC
4163          (zero_extend:SI
4164           (subreg:HI
4165            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4166                         (match_operand:SI 2 "const_int_operand" "")) 0))
4167          (const_int 0)))
4168    (set (match_operand:SI 0 "gpc_reg_operand" "")
4169         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4170   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4171   [(set (match_dup 0)
4172         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4173    (set (match_dup 3)
4174         (compare:CC (match_dup 0)
4175                     (const_int 0)))]
4176   "")
4177
4178 (define_insn ""
4179   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4180                          (const_int 1)
4181                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4182         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4183                      (const_int 31)))]
4184   "TARGET_POWER"
4185   "rrib %0,%1,%2")
4186
4187 (define_insn ""
4188   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4189                          (const_int 1)
4190                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4191         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4192                      (const_int 31)))]
4193   "TARGET_POWER"
4194   "rrib %0,%1,%2")
4195
4196 (define_insn ""
4197   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4198                          (const_int 1)
4199                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4200         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4201                          (const_int 1)
4202                          (const_int 0)))]
4203   "TARGET_POWER"
4204   "rrib %0,%1,%2")
4205
4206 (define_expand "ashrsi3"
4207   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4208         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4209                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
4210   ""
4211   "
4212 {
4213   if (TARGET_POWER)
4214     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
4215   else
4216     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
4217   DONE;
4218 }")
4219
4220 (define_insn "ashrsi3_power"
4221   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4222         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4223                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4224    (clobber (match_scratch:SI 3 "=q,X"))]
4225   "TARGET_POWER"
4226   "@
4227    srea %0,%1,%2
4228    {srai|srawi} %0,%1,%h2")
4229
4230 (define_insn "ashrsi3_no_power"
4231   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4232         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4233                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4234   "! TARGET_POWER"
4235   "{sra|sraw}%I2 %0,%1,%h2")
4236
4237 (define_insn ""
4238   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4239         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4240                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4241                     (const_int 0)))
4242    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4243    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4244   "TARGET_POWER"
4245   "@
4246    srea. %3,%1,%2
4247    {srai.|srawi.} %3,%1,%h2
4248    #
4249    #"
4250   [(set_attr "type" "delayed_compare")
4251    (set_attr "length" "4,4,8,8")])
4252
4253 (define_split
4254   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4255         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4256                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4257                     (const_int 0)))
4258    (clobber (match_scratch:SI 3 ""))
4259    (clobber (match_scratch:SI 4 ""))]
4260   "TARGET_POWER && reload_completed"
4261   [(parallel [(set (match_dup 3)
4262         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4263    (clobber (match_dup 4))])
4264    (set (match_dup 0)
4265         (compare:CC (match_dup 3)
4266                     (const_int 0)))]
4267   "")
4268
4269 (define_insn ""
4270   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4271         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4272                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4273                     (const_int 0)))
4274    (clobber (match_scratch:SI 3 "=r,r"))]
4275   "! TARGET_POWER"
4276   "@
4277    {sra|sraw}%I2. %3,%1,%h2
4278    #"
4279   [(set_attr "type" "delayed_compare")
4280    (set_attr "length" "4,8")])
4281
4282 (define_split
4283   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4284         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4285                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4286                     (const_int 0)))
4287    (clobber (match_scratch:SI 3 ""))]
4288   "! TARGET_POWER && reload_completed"
4289   [(set (match_dup 3)
4290         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4291    (set (match_dup 0)
4292         (compare:CC (match_dup 3)
4293                     (const_int 0)))]
4294   "")
4295
4296 (define_insn ""
4297   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4298         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4299                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4300                     (const_int 0)))
4301    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4302         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4303    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4304   "TARGET_POWER"
4305   "@
4306    srea. %0,%1,%2
4307    {srai.|srawi.} %0,%1,%h2
4308    #
4309    #"
4310   [(set_attr "type" "delayed_compare")
4311    (set_attr "length" "4,4,8,8")])
4312
4313 (define_split
4314   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4315         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4316                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4317                     (const_int 0)))
4318    (set (match_operand:SI 0 "gpc_reg_operand" "")
4319         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4320    (clobber (match_scratch:SI 4 ""))]
4321   "TARGET_POWER && reload_completed"
4322   [(parallel [(set (match_dup 0)
4323         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4324    (clobber (match_dup 4))])
4325    (set (match_dup 3)
4326         (compare:CC (match_dup 0)
4327                     (const_int 0)))]
4328   "")
4329
4330 (define_insn ""
4331   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4332         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4333                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4334                     (const_int 0)))
4335    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4336         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4337   "! TARGET_POWER"
4338   "@
4339    {sra|sraw}%I2. %0,%1,%h2
4340    #"
4341   [(set_attr "type" "delayed_compare")
4342    (set_attr "length" "4,8")])
4343 \f
4344 (define_split
4345   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4346         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4347                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4348                     (const_int 0)))
4349    (set (match_operand:SI 0 "gpc_reg_operand" "")
4350         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4351   "! TARGET_POWER && reload_completed"
4352   [(set (match_dup 0)
4353         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4354    (set (match_dup 3)
4355         (compare:CC (match_dup 0)
4356                     (const_int 0)))]
4357   "")
4358
4359 ;; Floating-point insns, excluding normal data motion.
4360 ;;
4361 ;; PowerPC has a full set of single-precision floating point instructions.
4362 ;;
4363 ;; For the POWER architecture, we pretend that we have both SFmode and
4364 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
4365 ;; The only conversions we will do will be when storing to memory.  In that
4366 ;; case, we will use the "frsp" instruction before storing.
4367 ;;
4368 ;; Note that when we store into a single-precision memory location, we need to
4369 ;; use the frsp insn first.  If the register being stored isn't dead, we
4370 ;; need a scratch register for the frsp.  But this is difficult when the store
4371 ;; is done by reload.  It is not incorrect to do the frsp on the register in
4372 ;; this case, we just lose precision that we would have otherwise gotten but
4373 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
4374
4375 (define_insn "extendsfdf2"
4376   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4377         (float_extend:DF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4378   "TARGET_HARD_FLOAT && TARGET_FPRS"
4379   "*
4380 {
4381   if (REGNO (operands[0]) == REGNO (operands[1]))
4382     return \"\";
4383   else
4384     return \"fmr %0,%1\";
4385 }"
4386   [(set_attr "type" "fp")])
4387
4388 (define_insn "truncdfsf2"
4389   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4390         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4391   "TARGET_HARD_FLOAT && TARGET_FPRS"
4392   "frsp %0,%1"
4393   [(set_attr "type" "fp")])
4394
4395 (define_insn "aux_truncdfsf2"
4396   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4397         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRSP))]
4398   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4399   "frsp %0,%1"
4400   [(set_attr "type" "fp")])
4401
4402 (define_expand "negsf2"
4403   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4404         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4405   "TARGET_HARD_FLOAT"
4406   "")
4407
4408 (define_insn "*negsf2"
4409   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4410         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4411   "TARGET_HARD_FLOAT && TARGET_FPRS"
4412   "fneg %0,%1"
4413   [(set_attr "type" "fp")])
4414
4415 (define_expand "abssf2"
4416   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4417         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4418   "TARGET_HARD_FLOAT"
4419   "")
4420
4421 (define_insn "*abssf2"
4422   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4423         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4424   "TARGET_HARD_FLOAT && TARGET_FPRS"
4425   "fabs %0,%1"
4426   [(set_attr "type" "fp")])
4427
4428 (define_insn ""
4429   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4430         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
4431   "TARGET_HARD_FLOAT && TARGET_FPRS"
4432   "fnabs %0,%1"
4433   [(set_attr "type" "fp")])
4434
4435 (define_expand "addsf3"
4436   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4437         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4438                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4439   "TARGET_HARD_FLOAT"
4440   "")
4441
4442 (define_insn ""
4443   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4444         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4445                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4446   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4447   "fadds %0,%1,%2"
4448   [(set_attr "type" "fp")])
4449
4450 (define_insn ""
4451   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4452         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4453                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4454   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4455   "{fa|fadd} %0,%1,%2"
4456   [(set_attr "type" "fp")])
4457
4458 (define_expand "subsf3"
4459   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4460         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4461                   (match_operand:SF 2 "gpc_reg_operand" "")))]
4462   "TARGET_HARD_FLOAT"
4463   "")
4464
4465 (define_insn ""
4466   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4467         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4468                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
4469   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4470   "fsubs %0,%1,%2"
4471   [(set_attr "type" "fp")])
4472
4473 (define_insn ""
4474   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4475         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4476                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
4477   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4478   "{fs|fsub} %0,%1,%2"
4479   [(set_attr "type" "fp")])
4480
4481 (define_expand "mulsf3"
4482   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4483         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
4484                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4485   "TARGET_HARD_FLOAT"
4486   "")
4487
4488 (define_insn ""
4489   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4490         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4491                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4492   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4493   "fmuls %0,%1,%2"
4494   [(set_attr "type" "fp")])
4495
4496 (define_insn ""
4497   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4498         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4499                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4500   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4501   "{fm|fmul} %0,%1,%2"
4502   [(set_attr "type" "dmul")])
4503
4504 (define_expand "divsf3"
4505   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4506         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
4507                 (match_operand:SF 2 "gpc_reg_operand" "")))]
4508   "TARGET_HARD_FLOAT"
4509   "")
4510
4511 (define_insn ""
4512   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4513         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4514                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
4515   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4516   "fdivs %0,%1,%2"
4517   [(set_attr "type" "sdiv")])
4518
4519 (define_insn ""
4520   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4521         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4522                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
4523   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4524   "{fd|fdiv} %0,%1,%2"
4525   [(set_attr "type" "ddiv")])
4526
4527 (define_insn ""
4528   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4529         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4530                           (match_operand:SF 2 "gpc_reg_operand" "f"))
4531                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
4532   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4533   "fmadds %0,%1,%2,%3"
4534   [(set_attr "type" "fp")])
4535
4536 (define_insn ""
4537   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4538         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4539                           (match_operand:SF 2 "gpc_reg_operand" "f"))
4540                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
4541   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4542   "{fma|fmadd} %0,%1,%2,%3"
4543   [(set_attr "type" "dmul")])
4544
4545 (define_insn ""
4546   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4547         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4548                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4549                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
4550   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4551   "fmsubs %0,%1,%2,%3"
4552   [(set_attr "type" "fp")])
4553
4554 (define_insn ""
4555   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4556         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4557                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4558                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
4559   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4560   "{fms|fmsub} %0,%1,%2,%3"
4561   [(set_attr "type" "dmul")])
4562
4563 (define_insn ""
4564   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4565         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4566                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
4567                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4568   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4569    && HONOR_SIGNED_ZEROS (SFmode)"
4570   "fnmadds %0,%1,%2,%3"
4571   [(set_attr "type" "fp")])
4572
4573 (define_insn ""
4574   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4575         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
4576                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4577                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4578   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4579    && ! HONOR_SIGNED_ZEROS (SFmode)"
4580   "fnmadds %0,%1,%2,%3"
4581   [(set_attr "type" "fp")])
4582
4583 (define_insn ""
4584   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4585         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4586                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
4587                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4588   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4589   "{fnma|fnmadd} %0,%1,%2,%3"
4590   [(set_attr "type" "dmul")])
4591
4592 (define_insn ""
4593   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4594         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
4595                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4596                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4597   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4598    && ! HONOR_SIGNED_ZEROS (SFmode)"
4599   "{fnma|fnmadd} %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 (minus: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   "fnmsubs %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 (match_operand:SF 3 "gpc_reg_operand" "f")
4615                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4616                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
4617   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4618    && ! HONOR_SIGNED_ZEROS (SFmode)"
4619   "fnmsubs %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 (minus: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   "{fnms|fnmsub} %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 (match_operand:SF 3 "gpc_reg_operand" "f")
4634                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4635                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
4636   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4637    && ! HONOR_SIGNED_ZEROS (SFmode)"
4638   "{fnms|fnmsub} %0,%1,%2,%3"
4639   [(set_attr "type" "fp")])
4640
4641 (define_expand "sqrtsf2"
4642   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4643         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4644   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
4645   "")
4646
4647 (define_insn ""
4648   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4649         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4650   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4651   "fsqrts %0,%1"
4652   [(set_attr "type" "ssqrt")])
4653
4654 (define_insn ""
4655   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4656         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4657   "TARGET_POWER2 && TARGET_HARD_FLOAT && TARGET_FPRS"
4658   "fsqrt %0,%1"
4659   [(set_attr "type" "dsqrt")])
4660
4661 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
4662 ;; fsel instruction and some auxiliary computations.  Then we just have a
4663 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
4664 ;; combine.
4665 (define_expand "maxsf3"
4666   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4667         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
4668                              (match_operand:SF 2 "gpc_reg_operand" ""))
4669                          (match_dup 1)
4670                          (match_dup 2)))]
4671   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4672   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
4673
4674 (define_expand "minsf3"
4675   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4676         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
4677                              (match_operand:SF 2 "gpc_reg_operand" ""))
4678                          (match_dup 2)
4679                          (match_dup 1)))]
4680   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4681   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
4682
4683 (define_split
4684   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4685         (match_operator:SF 3 "min_max_operator"
4686          [(match_operand:SF 1 "gpc_reg_operand" "")
4687           (match_operand:SF 2 "gpc_reg_operand" "")]))]
4688   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4689   [(const_int 0)]
4690   "
4691 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
4692                       operands[1], operands[2]);
4693   DONE;
4694 }")
4695
4696 (define_expand "movsicc"
4697    [(set (match_operand:SI 0 "gpc_reg_operand" "")
4698          (if_then_else:SI (match_operand 1 "comparison_operator" "")
4699                           (match_operand:SI 2 "gpc_reg_operand" "")
4700                           (match_operand:SI 3 "gpc_reg_operand" "")))]
4701   "TARGET_ISEL"
4702   "
4703 {
4704   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4705     DONE;
4706   else
4707     FAIL;
4708 }")
4709
4710 ;; We use the BASE_REGS for the isel input operands because, if rA is
4711 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
4712 ;; because we may switch the operands and rB may end up being rA.
4713 ;;
4714 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
4715 ;; leave out the mode in operand 4 and use one pattern, but reload can
4716 ;; change the mode underneath our feet and then gets confused trying
4717 ;; to reload the value.
4718 (define_insn "isel_signed"
4719   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4720         (if_then_else:SI
4721          (match_operator 1 "comparison_operator"
4722                          [(match_operand:CC 4 "cc_reg_operand" "y")
4723                           (const_int 0)])
4724          (match_operand:SI 2 "gpc_reg_operand" "b")
4725          (match_operand:SI 3 "gpc_reg_operand" "b")))]
4726   "TARGET_ISEL"
4727   "*
4728 { return output_isel (operands); }"
4729   [(set_attr "length" "4")])
4730
4731 (define_insn "isel_unsigned"
4732   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4733         (if_then_else:SI
4734          (match_operator 1 "comparison_operator"
4735                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
4736                           (const_int 0)])
4737          (match_operand:SI 2 "gpc_reg_operand" "b")
4738          (match_operand:SI 3 "gpc_reg_operand" "b")))]
4739   "TARGET_ISEL"
4740   "*
4741 { return output_isel (operands); }"
4742   [(set_attr "length" "4")])
4743
4744 (define_expand "movsfcc"
4745    [(set (match_operand:SF 0 "gpc_reg_operand" "")
4746          (if_then_else:SF (match_operand 1 "comparison_operator" "")
4747                           (match_operand:SF 2 "gpc_reg_operand" "")
4748                           (match_operand:SF 3 "gpc_reg_operand" "")))]
4749   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4750   "
4751 {
4752   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4753     DONE;
4754   else
4755     FAIL;
4756 }")
4757
4758 (define_insn "*fselsfsf4"
4759   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4760         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
4761                              (match_operand:SF 4 "zero_fp_constant" "F"))
4762                          (match_operand:SF 2 "gpc_reg_operand" "f")
4763                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4764   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4765   "fsel %0,%1,%2,%3"
4766   [(set_attr "type" "fp")])
4767
4768 (define_insn "*fseldfsf4"
4769   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4770         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
4771                              (match_operand:DF 4 "zero_fp_constant" "F"))
4772                          (match_operand:SF 2 "gpc_reg_operand" "f")
4773                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4774   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4775   "fsel %0,%1,%2,%3"
4776   [(set_attr "type" "fp")])
4777
4778 (define_insn "negdf2"
4779   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4780         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4781   "TARGET_HARD_FLOAT && TARGET_FPRS"
4782   "fneg %0,%1"
4783   [(set_attr "type" "fp")])
4784
4785 (define_insn "absdf2"
4786   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4787         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4788   "TARGET_HARD_FLOAT && TARGET_FPRS"
4789   "fabs %0,%1"
4790   [(set_attr "type" "fp")])
4791
4792 (define_insn ""
4793   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4794         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f"))))]
4795   "TARGET_HARD_FLOAT && TARGET_FPRS"
4796   "fnabs %0,%1"
4797   [(set_attr "type" "fp")])
4798
4799 (define_insn "adddf3"
4800   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4801         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4802                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
4803   "TARGET_HARD_FLOAT && TARGET_FPRS"
4804   "{fa|fadd} %0,%1,%2"
4805   [(set_attr "type" "fp")])
4806
4807 (define_insn "subdf3"
4808   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4809         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "f")
4810                   (match_operand:DF 2 "gpc_reg_operand" "f")))]
4811   "TARGET_HARD_FLOAT && TARGET_FPRS"
4812   "{fs|fsub} %0,%1,%2"
4813   [(set_attr "type" "fp")])
4814
4815 (define_insn "muldf3"
4816   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4817         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4818                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
4819   "TARGET_HARD_FLOAT && TARGET_FPRS"
4820   "{fm|fmul} %0,%1,%2"
4821   [(set_attr "type" "dmul")])
4822
4823 (define_insn "divdf3"
4824   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4825         (div:DF (match_operand:DF 1 "gpc_reg_operand" "f")
4826                 (match_operand:DF 2 "gpc_reg_operand" "f")))]
4827   "TARGET_HARD_FLOAT && TARGET_FPRS"
4828   "{fd|fdiv} %0,%1,%2"
4829   [(set_attr "type" "ddiv")])
4830
4831 (define_insn ""
4832   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4833         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4834                           (match_operand:DF 2 "gpc_reg_operand" "f"))
4835                  (match_operand:DF 3 "gpc_reg_operand" "f")))]
4836   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4837   "{fma|fmadd} %0,%1,%2,%3"
4838   [(set_attr "type" "dmul")])
4839
4840 (define_insn ""
4841   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4842         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4843                            (match_operand:DF 2 "gpc_reg_operand" "f"))
4844                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
4845   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4846   "{fms|fmsub} %0,%1,%2,%3"
4847   [(set_attr "type" "dmul")])
4848
4849 (define_insn ""
4850   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4851         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4852                                   (match_operand:DF 2 "gpc_reg_operand" "f"))
4853                          (match_operand:DF 3 "gpc_reg_operand" "f"))))]
4854   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4855    && HONOR_SIGNED_ZEROS (DFmode)"
4856   "{fnma|fnmadd} %0,%1,%2,%3"
4857   [(set_attr "type" "dmul")])
4858
4859 (define_insn ""
4860   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4861         (minus:DF (mult:DF (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f"))
4862                            (match_operand:DF 2 "gpc_reg_operand" "f"))
4863                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
4864   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4865    && ! HONOR_SIGNED_ZEROS (DFmode)"
4866   "{fnma|fnmadd} %0,%1,%2,%3"
4867   [(set_attr "type" "dmul")])
4868
4869 (define_insn ""
4870   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4871         (neg:DF (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4872                                    (match_operand:DF 2 "gpc_reg_operand" "f"))
4873                           (match_operand:DF 3 "gpc_reg_operand" "f"))))]
4874   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4875    && HONOR_SIGNED_ZEROS (DFmode)"
4876   "{fnms|fnmsub} %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 (match_operand:DF 3 "gpc_reg_operand" "f")
4882                   (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4883                            (match_operand:DF 2 "gpc_reg_operand" "f"))))]
4884   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4885    && ! HONOR_SIGNED_ZEROS (DFmode)"
4886   "{fnms|fnmsub} %0,%1,%2,%3"
4887   [(set_attr "type" "dmul")])
4888
4889 (define_insn "sqrtdf2"
4890   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4891         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4892   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
4893   "fsqrt %0,%1"
4894   [(set_attr "type" "dsqrt")])
4895
4896 ;; The conditional move instructions allow us to perform max and min
4897 ;; operations even when
4898
4899 (define_expand "maxdf3"
4900   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4901         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
4902                              (match_operand:DF 2 "gpc_reg_operand" ""))
4903                          (match_dup 1)
4904                          (match_dup 2)))]
4905   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4906   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
4907
4908 (define_expand "mindf3"
4909   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4910         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
4911                              (match_operand:DF 2 "gpc_reg_operand" ""))
4912                          (match_dup 2)
4913                          (match_dup 1)))]
4914   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4915   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
4916
4917 (define_split
4918   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4919         (match_operator:DF 3 "min_max_operator"
4920          [(match_operand:DF 1 "gpc_reg_operand" "")
4921           (match_operand:DF 2 "gpc_reg_operand" "")]))]
4922   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4923   [(const_int 0)]
4924   "
4925 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
4926                       operands[1], operands[2]);
4927   DONE;
4928 }")
4929
4930 (define_expand "movdfcc"
4931    [(set (match_operand:DF 0 "gpc_reg_operand" "")
4932          (if_then_else:DF (match_operand 1 "comparison_operator" "")
4933                           (match_operand:DF 2 "gpc_reg_operand" "")
4934                           (match_operand:DF 3 "gpc_reg_operand" "")))]
4935   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4936   "
4937 {
4938   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4939     DONE;
4940   else
4941     FAIL;
4942 }")
4943
4944 (define_insn "*fseldfdf4"
4945   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4946         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
4947                              (match_operand:DF 4 "zero_fp_constant" "F"))
4948                          (match_operand:DF 2 "gpc_reg_operand" "f")
4949                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
4950   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4951   "fsel %0,%1,%2,%3"
4952   [(set_attr "type" "fp")])
4953
4954 (define_insn "*fselsfdf4"
4955   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4956         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
4957                              (match_operand:SF 4 "zero_fp_constant" "F"))
4958                          (match_operand:DF 2 "gpc_reg_operand" "f")
4959                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
4960   "TARGET_PPC_GFXOPT"
4961   "fsel %0,%1,%2,%3"
4962   [(set_attr "type" "fp")])
4963 \f
4964 ;; Conversions to and from floating-point.
4965
4966 (define_expand "fixuns_truncsfsi2"
4967   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4968         (unsigned_fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
4969   "TARGET_HARD_FLOAT && !TARGET_FPRS"
4970   "")
4971
4972 (define_expand "fix_truncsfsi2"
4973   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4974         (fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
4975   "TARGET_HARD_FLOAT && !TARGET_FPRS"
4976   "")
4977
4978 ; For each of these conversions, there is a define_expand, a define_insn
4979 ; with a '#' template, and a define_split (with C code).  The idea is
4980 ; to allow constant folding with the template of the define_insn,
4981 ; then to have the insns split later (between sched1 and final).
4982
4983 (define_expand "floatsidf2"
4984   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
4985                    (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
4986               (use (match_dup 2))
4987               (use (match_dup 3))
4988               (clobber (match_dup 4))
4989               (clobber (match_dup 5))
4990               (clobber (match_dup 6))])]
4991   "TARGET_HARD_FLOAT && TARGET_FPRS"
4992   "
4993 {
4994   if (TARGET_POWERPC64)
4995     {
4996       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
4997       rtx t1 = gen_reg_rtx (DImode);
4998       rtx t2 = gen_reg_rtx (DImode);
4999       emit_insn (gen_floatsidf_ppc64 (operands[0], operands[1], mem, t1, t2));
5000       DONE;
5001     }
5002
5003   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5004   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
5005   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5006   operands[5] = gen_reg_rtx (DFmode);
5007   operands[6] = gen_reg_rtx (SImode);
5008 }")
5009
5010 (define_insn "*floatsidf2_internal"
5011   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5012         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5013    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5014    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5015    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5016    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))
5017    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
5018   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5019   "#"
5020   [(set_attr "length" "24")])
5021
5022 (define_split
5023   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5024         (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5025    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5026    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5027    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5028    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))
5029    (clobber (match_operand:SI 6 "gpc_reg_operand" ""))]
5030   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5031   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5032         (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5033    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5034    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5035    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5036    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))
5037    (clobber (match_operand:SI 6 "gpc_reg_operand" ""))]
5038   "
5039 {
5040   rtx lowword, highword;
5041   if (GET_CODE (operands[4]) != MEM)
5042     abort();
5043   highword = XEXP (operands[4], 0);
5044   lowword = plus_constant (highword, 4);
5045   if (! WORDS_BIG_ENDIAN)
5046     {
5047       rtx tmp;
5048       tmp = highword; highword = lowword; lowword = tmp;
5049     }
5050
5051   emit_insn (gen_xorsi3 (operands[6], operands[1],
5052                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
5053   emit_move_insn (gen_rtx_MEM (SImode, lowword), operands[6]);
5054   emit_move_insn (gen_rtx_MEM (SImode, highword), operands[2]);
5055   emit_move_insn (operands[5], operands[4]);
5056   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5057   DONE;
5058 }")
5059
5060 (define_expand "floatunssisf2"
5061   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5062         (unsigned_float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5063   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5064   "")
5065
5066 (define_expand "floatunssidf2"
5067   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5068                    (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5069               (use (match_dup 2))
5070               (use (match_dup 3))
5071               (clobber (match_dup 4))
5072               (clobber (match_dup 5))])]
5073   "TARGET_HARD_FLOAT && TARGET_FPRS"
5074   "
5075 {
5076   if (TARGET_POWERPC64)
5077     {
5078       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5079       rtx t1 = gen_reg_rtx (DImode);
5080       rtx t2 = gen_reg_rtx (DImode);
5081       emit_insn (gen_floatunssidf_ppc64 (operands[0], operands[1], mem,
5082                                          t1, t2));
5083       DONE;
5084     }
5085
5086   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5087   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
5088   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5089   operands[5] = gen_reg_rtx (DFmode);
5090 }")
5091
5092 (define_insn "*floatunssidf2_internal"
5093   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5094         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5095    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5096    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5097    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5098    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))]
5099   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5100   "#"
5101   [(set_attr "length" "20")])
5102
5103 (define_split
5104   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5105         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5106    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5107    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5108    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5109    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))]
5110   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5111   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5112         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5113    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5114    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5115    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5116    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))]
5117   "
5118 {
5119   rtx lowword, highword;
5120   if (GET_CODE (operands[4]) != MEM)
5121     abort();
5122   highword = XEXP (operands[4], 0);
5123   lowword = plus_constant (highword, 4);
5124   if (! WORDS_BIG_ENDIAN)
5125     {
5126       rtx tmp;
5127       tmp = highword; highword = lowword; lowword = tmp;
5128     }
5129
5130   emit_move_insn (gen_rtx_MEM (SImode, lowword), operands[1]);
5131   emit_move_insn (gen_rtx_MEM (SImode, highword), operands[2]);
5132   emit_move_insn (operands[5], operands[4]);
5133   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5134   DONE;
5135 }")
5136
5137 (define_expand "fix_truncdfsi2"
5138   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
5139                    (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5140               (clobber (match_dup 2))
5141               (clobber (match_dup 3))])]
5142   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5143   "
5144 {
5145   operands[2] = gen_reg_rtx (DImode);
5146   operands[3] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5147 }")
5148
5149 (define_insn "*fix_truncdfsi2_internal"
5150   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5151         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5152    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))
5153    (clobber (match_operand:DI 3 "memory_operand" "=o"))]
5154   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5155   "#"
5156   [(set_attr "length" "16")])
5157
5158 (define_split
5159   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5160         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5161    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
5162    (clobber (match_operand:DI 3 "offsettable_mem_operand" ""))]
5163   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5164   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5165         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5166    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
5167    (clobber (match_operand:DI 3 "offsettable_mem_operand" ""))]
5168   "
5169 {
5170   rtx lowword;
5171   if (GET_CODE (operands[3]) != MEM)
5172     abort();
5173   lowword = XEXP (operands[3], 0);
5174   if (WORDS_BIG_ENDIAN)
5175     lowword = plus_constant (lowword, 4);
5176
5177   emit_insn (gen_fctiwz (operands[2], operands[1]));
5178   emit_move_insn (operands[3], operands[2]);
5179   emit_move_insn (operands[0], gen_rtx_MEM (SImode, lowword));
5180   DONE;
5181 }")
5182
5183 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
5184 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
5185 ; because the first makes it clear that operand 0 is not live
5186 ; before the instruction.
5187 (define_insn "fctiwz"
5188   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
5189         (unspec:DI [(fix:SI (match_operand:DF 1 "gpc_reg_operand" "f"))]
5190                    UNSPEC_FCTIWZ))]
5191   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5192   "{fcirz|fctiwz} %0,%1"
5193   [(set_attr "type" "fp")])
5194
5195 (define_expand "floatsisf2"
5196   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5197         (float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5198   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5199   "")
5200
5201 (define_insn "floatdidf2"
5202   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5203         (float:DF (match_operand:DI 1 "gpc_reg_operand" "*f")))]
5204   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5205   "fcfid %0,%1"
5206   [(set_attr "type" "fp")])
5207
5208 (define_insn_and_split "floatsidf_ppc64"
5209   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5210         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5211    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5212    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5213    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5214   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5215   "#"
5216   "&& 1"
5217   [(set (match_dup 3) (sign_extend:DI (match_dup 1)))
5218    (set (match_dup 2) (match_dup 3))
5219    (set (match_dup 4) (match_dup 2))
5220    (set (match_dup 0) (float:DF (match_dup 4)))]
5221   "")
5222
5223 (define_insn_and_split "floatunssidf_ppc64"
5224   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5225         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5226    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5227    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5228    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5229   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5230   "#"
5231   "&& 1"
5232   [(set (match_dup 3) (zero_extend:DI (match_dup 1)))
5233    (set (match_dup 2) (match_dup 3))
5234    (set (match_dup 4) (match_dup 2))
5235    (set (match_dup 0) (float:DF (match_dup 4)))]
5236   "")
5237
5238 (define_insn "fix_truncdfdi2"
5239   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
5240         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "f")))]
5241   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5242   "fctidz %0,%1"
5243   [(set_attr "type" "fp")])
5244
5245 (define_expand "floatdisf2"
5246   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5247         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
5248   "TARGET_64BIT && TARGET_HARD_FLOAT && TARGET_FPRS"
5249   "
5250 {
5251   if (!flag_unsafe_math_optimizations)
5252     {
5253       rtx label = gen_label_rtx ();
5254       emit_insn (gen_floatdisf2_internal2 (operands[1], label));
5255       emit_label (label);
5256     }
5257   emit_insn (gen_floatdisf2_internal1 (operands[0], operands[1]));
5258   DONE;
5259 }")
5260
5261 ;; This is not IEEE compliant if rounding mode is "round to nearest".
5262 ;; If the DI->DF conversion is inexact, then it's possible to suffer
5263 ;; from double rounding.
5264 (define_insn_and_split "floatdisf2_internal1"
5265   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5266         (float:SF (match_operand:DI 1 "gpc_reg_operand" "*f")))
5267    (clobber (match_scratch:DF 2 "=f"))]
5268   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5269   "#"
5270   "&& reload_completed"
5271   [(set (match_dup 2)
5272         (float:DF (match_dup 1)))
5273    (set (match_dup 0)
5274         (float_truncate:SF (match_dup 2)))]
5275   "")
5276
5277 ;; Twiddles bits to avoid double rounding.
5278 ;; Bits that might be truncated when converting to DFmode are replaced
5279 ;; by a bit that won't be lost at that stage, but is below the SFmode
5280 ;; rounding position.
5281 (define_expand "floatdisf2_internal2"
5282   [(parallel [(set (match_dup 4)
5283                    (compare:CC (and:DI (match_operand:DI 0 "" "")
5284                                        (const_int 2047))
5285                                (const_int 0)))
5286               (set (match_dup 2) (and:DI (match_dup 0) (const_int 2047)))
5287               (clobber (match_scratch:CC 7 ""))])
5288    (set (match_dup 3) (ashiftrt:DI (match_dup 0) (const_int 53)))
5289    (set (match_dup 3) (plus:DI (match_dup 3) (const_int 1)))
5290    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
5291                            (label_ref (match_operand:DI 1 "" ""))
5292                            (pc)))
5293    (set (match_dup 5) (compare:CCUNS (match_dup 3) (const_int 2)))
5294    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
5295                            (label_ref (match_dup 1))
5296                            (pc)))
5297    (set (match_dup 0) (xor:DI (match_dup 0) (match_dup 2)))
5298    (set (match_dup 0) (ior:DI (match_dup 0) (const_int 2048)))]
5299   "TARGET_64BIT && TARGET_HARD_FLOAT && TARGET_FPRS"
5300   "
5301 {
5302   operands[2] = gen_reg_rtx (DImode);
5303   operands[3] = gen_reg_rtx (DImode);
5304   operands[4] = gen_reg_rtx (CCmode);
5305   operands[5] = gen_reg_rtx (CCUNSmode);
5306 }")
5307 \f
5308 ;; Define the DImode operations that can be done in a small number
5309 ;; of instructions.  The & constraints are to prevent the register
5310 ;; allocator from allocating registers that overlap with the inputs
5311 ;; (for example, having an input in 7,8 and an output in 6,7).  We
5312 ;; also allow for the output being the same as one of the inputs.
5313
5314 (define_insn "*adddi3_noppc64"
5315   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
5316         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
5317                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
5318   "! TARGET_POWERPC64"
5319   "*
5320 {
5321   if (WORDS_BIG_ENDIAN)
5322     return (GET_CODE (operands[2])) != CONST_INT
5323             ? \"{a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2\"
5324             : \"{ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1\";
5325   else
5326     return (GET_CODE (operands[2])) != CONST_INT
5327             ? \"{a|addc} %0,%1,%2\;{ae|adde} %L0,%L1,%L2\"
5328             : \"{ai|addic} %0,%1,%2\;{a%G2e|add%G2e} %L0,%L1\";
5329 }"
5330   [(set_attr "length" "8")])
5331
5332 (define_insn "*subdi3_noppc64"
5333   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
5334         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
5335                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
5336   "! TARGET_POWERPC64"
5337   "*
5338 {
5339   if (WORDS_BIG_ENDIAN)
5340     return (GET_CODE (operands[1]) != CONST_INT)
5341             ? \"{sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1\"
5342             : \"{sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2\";
5343   else
5344     return (GET_CODE (operands[1]) != CONST_INT)
5345             ? \"{sf|subfc} %0,%2,%1\;{sfe|subfe} %L0,%L2,%L1\"
5346             : \"{sfi|subfic} %0,%2,%1\;{sf%G1e|subf%G1e} %L0,%L2\";
5347 }"
5348   [(set_attr "length" "8")])
5349
5350 (define_insn "*negdi2_noppc64"
5351   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5352         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
5353   "! TARGET_POWERPC64"
5354   "*
5355 {
5356   return (WORDS_BIG_ENDIAN)
5357     ? \"{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1\"
5358     : \"{sfi|subfic} %0,%1,0\;{sfze|subfze} %L0,%L1\";
5359 }"
5360   [(set_attr "length" "8")])
5361
5362 (define_expand "mulsidi3"
5363   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5364         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5365                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5366   "! TARGET_POWERPC64"
5367   "
5368 {
5369   if (! TARGET_POWER && ! TARGET_POWERPC)
5370     {
5371       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
5372       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
5373       emit_insn (gen_mull_call ());
5374       if (WORDS_BIG_ENDIAN)
5375         emit_move_insn (operands[0], gen_rtx_REG (DImode, 3));
5376       else
5377         {
5378           emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
5379                           gen_rtx_REG (SImode, 3));
5380           emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
5381                           gen_rtx_REG (SImode, 4));
5382         }
5383       DONE;
5384     }
5385   else if (TARGET_POWER)
5386     {
5387       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
5388       DONE;
5389     }
5390 }")
5391
5392 (define_insn "mulsidi3_mq"
5393   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5394         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5395                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
5396    (clobber (match_scratch:SI 3 "=q"))]
5397   "TARGET_POWER"
5398   "mul %0,%1,%2\;mfmq %L0"
5399   [(set_attr "type" "imul")
5400    (set_attr "length" "8")])
5401
5402 (define_insn "*mulsidi3_no_mq"
5403   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5404         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5405                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
5406   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
5407   "*
5408 {
5409   return (WORDS_BIG_ENDIAN)
5410     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
5411     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
5412 }"
5413   [(set_attr "type" "imul")
5414    (set_attr "length" "8")])
5415
5416 (define_split
5417   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5418         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5419                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5420   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
5421   [(set (match_dup 3)
5422         (truncate:SI
5423          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
5424                                (sign_extend:DI (match_dup 2)))
5425                       (const_int 32))))
5426    (set (match_dup 4)
5427         (mult:SI (match_dup 1)
5428                  (match_dup 2)))]
5429   "
5430 {
5431   int endian = (WORDS_BIG_ENDIAN == 0);
5432   operands[3] = operand_subword (operands[0], endian, 0, DImode);
5433   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
5434 }")
5435
5436 (define_expand "umulsidi3"
5437   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5438         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5439                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5440   "TARGET_POWERPC && ! TARGET_POWERPC64"
5441   "
5442 {
5443   if (TARGET_POWER)
5444     {
5445       emit_insn (gen_umulsidi3_mq (operands[0], operands[1], operands[2]));
5446       DONE;
5447     }
5448 }")
5449
5450 (define_insn "umulsidi3_mq"
5451   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5452         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5453                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
5454    (clobber (match_scratch:SI 3 "=q"))]
5455   "TARGET_POWERPC && TARGET_POWER"
5456   "*
5457 {
5458   return (WORDS_BIG_ENDIAN)
5459     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
5460     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
5461 }"
5462   [(set_attr "type" "imul")
5463    (set_attr "length" "8")])
5464
5465 (define_insn "*umulsidi3_no_mq"
5466   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5467         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5468                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
5469   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
5470   "*
5471 {
5472   return (WORDS_BIG_ENDIAN)
5473     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
5474     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
5475 }"
5476   [(set_attr "type" "imul")
5477    (set_attr "length" "8")])
5478
5479 (define_split
5480   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5481         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5482                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5483   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
5484   [(set (match_dup 3)
5485         (truncate:SI
5486          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
5487                                (zero_extend:DI (match_dup 2)))
5488                       (const_int 32))))
5489    (set (match_dup 4)
5490         (mult:SI (match_dup 1)
5491                  (match_dup 2)))]
5492   "
5493 {
5494   int endian = (WORDS_BIG_ENDIAN == 0);
5495   operands[3] = operand_subword (operands[0], endian, 0, DImode);
5496   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
5497 }")
5498
5499 (define_expand "smulsi3_highpart"
5500   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5501         (truncate:SI
5502          (lshiftrt:DI (mult:DI (sign_extend:DI
5503                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5504                                (sign_extend:DI
5505                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5506                       (const_int 32))))]
5507   ""
5508   "
5509 {
5510   if (! TARGET_POWER && ! TARGET_POWERPC)
5511     {
5512       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
5513       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
5514       emit_insn (gen_mulh_call ());
5515       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
5516       DONE;
5517     }
5518   else if (TARGET_POWER)
5519     {
5520       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
5521       DONE;
5522     }
5523 }")
5524
5525 (define_insn "smulsi3_highpart_mq"
5526   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5527         (truncate:SI
5528          (lshiftrt:DI (mult:DI (sign_extend:DI
5529                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5530                                (sign_extend:DI
5531                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5532                       (const_int 32))))
5533    (clobber (match_scratch:SI 3 "=q"))]
5534   "TARGET_POWER"
5535   "mul %0,%1,%2"
5536   [(set_attr "type" "imul")])
5537
5538 (define_insn "*smulsi3_highpart_no_mq"
5539   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
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   "TARGET_POWERPC && ! TARGET_POWER"
5547   "mulhw %0,%1,%2"
5548   [(set_attr "type" "imul")])
5549
5550 (define_expand "umulsi3_highpart"
5551   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5552         (truncate:SI
5553          (lshiftrt:DI (mult:DI (zero_extend:DI
5554                                 (match_operand:SI 1 "gpc_reg_operand" ""))
5555                                (zero_extend:DI
5556                                 (match_operand:SI 2 "gpc_reg_operand" "")))
5557                       (const_int 32))))]
5558   "TARGET_POWERPC"
5559   "
5560 {
5561   if (TARGET_POWER)
5562     {
5563       emit_insn (gen_umulsi3_highpart_mq (operands[0], operands[1], operands[2]));
5564       DONE;
5565     }
5566 }")
5567
5568 (define_insn "umulsi3_highpart_mq"
5569   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5570         (truncate:SI
5571          (lshiftrt:DI (mult:DI (zero_extend:DI
5572                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5573                                (zero_extend:DI
5574                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5575                       (const_int 32))))
5576    (clobber (match_scratch:SI 3 "=q"))]
5577   "TARGET_POWERPC && TARGET_POWER"
5578   "mulhwu %0,%1,%2"
5579   [(set_attr "type" "imul")])
5580
5581 (define_insn "*umulsi3_highpart_no_mq"
5582   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5583         (truncate:SI
5584          (lshiftrt:DI (mult:DI (zero_extend:DI
5585                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5586                                (zero_extend:DI
5587                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5588                       (const_int 32))))]
5589   "TARGET_POWERPC && ! TARGET_POWER"
5590   "mulhwu %0,%1,%2"
5591   [(set_attr "type" "imul")])
5592
5593 ;; If operands 0 and 2 are in the same register, we have a problem.  But
5594 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
5595 ;; why we have the strange constraints below.
5596 (define_insn "ashldi3_power"
5597   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
5598         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
5599                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
5600    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
5601   "TARGET_POWER"
5602   "@
5603    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
5604    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
5605    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
5606    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
5607   [(set_attr "length" "8")])
5608
5609 (define_insn "lshrdi3_power"
5610   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
5611         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
5612                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
5613    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
5614   "TARGET_POWER"
5615   "@
5616    {s%A2i|s%A2wi} %L0,%1,%h2\;{cal %0,0(0)|li %0,0}
5617    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
5618    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
5619    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
5620   [(set_attr "length" "8")])
5621
5622 ;; Shift by a variable amount is too complex to be worth open-coding.  We
5623 ;; just handle shifts by constants.
5624 (define_insn "ashrdi3_power"
5625   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5626         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5627                      (match_operand:SI 2 "const_int_operand" "M,i")))
5628    (clobber (match_scratch:SI 3 "=X,q"))]
5629   "TARGET_POWER"
5630   "@
5631    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
5632    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
5633   [(set_attr "length" "8")])
5634
5635 (define_insn "ashrdi3_no_power"
5636   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
5637         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5638                      (match_operand:SI 2 "const_int_operand" "M,i")))]
5639   "TARGET_32BIT && !TARGET_POWERPC64 && !TARGET_POWER && WORDS_BIG_ENDIAN"
5640   "@
5641    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
5642    {sri|srwi} %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;{srai|srawi} %0,%1,%h2"
5643   [(set_attr "length" "8,12")])
5644
5645 (define_insn "*ashrdisi3_noppc64"
5646   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5647         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
5648                                 (const_int 32)) 4))]
5649   "TARGET_32BIT && !TARGET_POWERPC64"
5650   "*
5651 {
5652   if (REGNO (operands[0]) == REGNO (operands[1]))
5653     return \"\";
5654   else
5655     return \"mr %0,%1\";
5656 }"
5657    [(set_attr "length" "4")])
5658
5659 \f
5660 ;; PowerPC64 DImode operations.
5661
5662 (define_expand "adddi3"
5663   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5664         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5665                  (match_operand:DI 2 "reg_or_add_cint64_operand" "")))]
5666   ""
5667   "
5668 {
5669   if (! TARGET_POWERPC64)
5670     {
5671       if (non_short_cint_operand (operands[2], DImode))
5672         FAIL;
5673     }
5674   else
5675     if (GET_CODE (operands[2]) == CONST_INT
5676         && ! add_operand (operands[2], DImode))
5677       {
5678         rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
5679                    ? operands[0] : gen_reg_rtx (DImode));
5680
5681         HOST_WIDE_INT val = INTVAL (operands[2]);
5682         HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
5683         HOST_WIDE_INT rest = trunc_int_for_mode (val - low, DImode);
5684
5685         if (!CONST_OK_FOR_LETTER_P (rest, 'L'))
5686           FAIL;
5687
5688         /* The ordering here is important for the prolog expander.
5689            When space is allocated from the stack, adding 'low' first may
5690            produce a temporary deallocation (which would be bad).  */
5691         emit_insn (gen_adddi3 (tmp, operands[1], GEN_INT (rest)));
5692         emit_insn (gen_adddi3 (operands[0], tmp, GEN_INT (low)));
5693         DONE;
5694       }
5695 }")
5696
5697 ;; Discourage ai/addic because of carry but provide it in an alternative
5698 ;; allowing register zero as source.
5699
5700 (define_insn "*adddi3_internal1"
5701   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,?r,r")
5702         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,b,r,b")
5703                  (match_operand:DI 2 "add_operand" "r,I,I,L")))]
5704   "TARGET_POWERPC64"
5705   "@
5706    add %0,%1,%2
5707    addi %0,%1,%2
5708    addic %0,%1,%2
5709    addis %0,%1,%v2")
5710
5711 (define_insn "*adddi3_internal2"
5712   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
5713         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
5714                              (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I"))
5715                     (const_int 0)))
5716    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
5717   "TARGET_64BIT"
5718   "@
5719    add. %3,%1,%2
5720    addic. %3,%1,%2
5721    #
5722    #"
5723   [(set_attr "type" "fast_compare,compare,compare,compare")
5724    (set_attr "length" "4,4,8,8")])
5725
5726 (define_split
5727   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5728         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5729                              (match_operand:DI 2 "reg_or_short_operand" ""))
5730                     (const_int 0)))
5731    (clobber (match_scratch:DI 3 ""))]
5732   "TARGET_POWERPC64 && reload_completed"
5733   [(set (match_dup 3)
5734         (plus:DI (match_dup 1) (match_dup 2)))
5735    (set (match_dup 0)
5736         (compare:CC (match_dup 3)
5737                     (const_int 0)))]
5738   "")
5739
5740 (define_insn "*adddi3_internal3"
5741   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
5742         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
5743                              (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I"))
5744                     (const_int 0)))
5745    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
5746         (plus:DI (match_dup 1) (match_dup 2)))]
5747   "TARGET_64BIT"
5748   "@
5749    add. %0,%1,%2
5750    addic. %0,%1,%2
5751    #
5752    #"
5753   [(set_attr "type" "fast_compare,compare,compare,compare")
5754    (set_attr "length" "4,4,8,8")])
5755
5756 (define_split
5757   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5758         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5759                              (match_operand:DI 2 "reg_or_short_operand" ""))
5760                     (const_int 0)))
5761    (set (match_operand:DI 0 "gpc_reg_operand" "")
5762         (plus:DI (match_dup 1) (match_dup 2)))]
5763   "TARGET_POWERPC64 && reload_completed"
5764   [(set (match_dup 0)
5765         (plus:DI (match_dup 1) (match_dup 2)))
5766    (set (match_dup 3)
5767         (compare:CC (match_dup 0)
5768                     (const_int 0)))]
5769   "")
5770
5771 ;; Split an add that we can't do in one insn into two insns, each of which
5772 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
5773 ;; add should be last in case the result gets used in an address.
5774
5775 (define_split
5776   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5777         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5778                  (match_operand:DI 2 "non_add_cint_operand" "")))]
5779   "TARGET_POWERPC64"
5780   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 3)))
5781    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 4)))]
5782 "
5783 {
5784   HOST_WIDE_INT val = INTVAL (operands[2]);
5785   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
5786   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, DImode);
5787
5788   operands[4] = GEN_INT (low);
5789   if (CONST_OK_FOR_LETTER_P (rest, 'L'))
5790     operands[3] = GEN_INT (rest);
5791   else if (! no_new_pseudos)
5792     {
5793       operands[3] = gen_reg_rtx (DImode);
5794       emit_move_insn (operands[3], operands[2]);
5795       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
5796       DONE;
5797     }
5798   else
5799     FAIL;
5800 }")
5801
5802 (define_insn "one_cmpldi2"
5803   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5804         (not:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
5805   "TARGET_POWERPC64"
5806   "nor %0,%1,%1")
5807
5808 (define_insn ""
5809   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5810         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
5811                     (const_int 0)))
5812    (clobber (match_scratch:DI 2 "=r,r"))]
5813   "TARGET_64BIT"
5814   "@
5815    nor. %2,%1,%1
5816    #"
5817   [(set_attr "type" "compare")
5818    (set_attr "length" "4,8")])
5819
5820 (define_split
5821   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5822         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
5823                     (const_int 0)))
5824    (clobber (match_scratch:DI 2 ""))]
5825   "TARGET_POWERPC64 && reload_completed"
5826   [(set (match_dup 2)
5827         (not:DI (match_dup 1)))
5828    (set (match_dup 0)
5829         (compare:CC (match_dup 2)
5830                     (const_int 0)))]
5831   "")
5832
5833 (define_insn ""
5834   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
5835         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
5836                     (const_int 0)))
5837    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5838         (not:DI (match_dup 1)))]
5839   "TARGET_64BIT"
5840   "@
5841    nor. %0,%1,%1
5842    #"
5843   [(set_attr "type" "compare")
5844    (set_attr "length" "4,8")])
5845
5846 (define_split
5847   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
5848         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
5849                     (const_int 0)))
5850    (set (match_operand:DI 0 "gpc_reg_operand" "")
5851         (not:DI (match_dup 1)))]
5852   "TARGET_POWERPC64 && reload_completed"
5853   [(set (match_dup 0)
5854         (not:DI (match_dup 1)))
5855    (set (match_dup 2)
5856         (compare:CC (match_dup 0)
5857                     (const_int 0)))]
5858   "")
5859
5860 (define_insn ""
5861   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5862         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I")
5863                   (match_operand:DI 2 "gpc_reg_operand" "r,r")))]
5864   "TARGET_POWERPC64"
5865   "@
5866    subf %0,%2,%1
5867    subfic %0,%2,%1")
5868
5869 (define_insn ""
5870   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5871         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5872                               (match_operand:DI 2 "gpc_reg_operand" "r,r"))
5873                     (const_int 0)))
5874    (clobber (match_scratch:DI 3 "=r,r"))]
5875   "TARGET_64BIT"
5876   "@
5877    subf. %3,%2,%1
5878    #"
5879   [(set_attr "type" "fast_compare")
5880    (set_attr "length" "4,8")])
5881
5882 (define_split
5883   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5884         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5885                               (match_operand:DI 2 "gpc_reg_operand" ""))
5886                     (const_int 0)))
5887    (clobber (match_scratch:DI 3 ""))]
5888   "TARGET_POWERPC64 && reload_completed"
5889   [(set (match_dup 3)
5890         (minus:DI (match_dup 1) (match_dup 2)))
5891    (set (match_dup 0)
5892         (compare:CC (match_dup 3)
5893                     (const_int 0)))]
5894   "")
5895
5896 (define_insn ""
5897   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
5898         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5899                               (match_operand:DI 2 "gpc_reg_operand" "r,r"))
5900                     (const_int 0)))
5901    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5902         (minus:DI (match_dup 1) (match_dup 2)))]
5903   "TARGET_64BIT"
5904   "@
5905    subf. %0,%2,%1
5906    #"
5907   [(set_attr "type" "fast_compare")
5908    (set_attr "length" "4,8")])
5909
5910 (define_split
5911   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5912         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5913                               (match_operand:DI 2 "gpc_reg_operand" ""))
5914                     (const_int 0)))
5915    (set (match_operand:DI 0 "gpc_reg_operand" "")
5916         (minus:DI (match_dup 1) (match_dup 2)))]
5917   "TARGET_POWERPC64 && reload_completed"
5918   [(set (match_dup 0)
5919         (minus:DI (match_dup 1) (match_dup 2)))
5920    (set (match_dup 3)
5921         (compare:CC (match_dup 0)
5922                     (const_int 0)))]
5923   "")
5924
5925 (define_expand "subdi3"
5926   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5927         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "")
5928                   (match_operand:DI 2 "reg_or_sub_cint64_operand" "")))]
5929   ""
5930   "
5931 {
5932   if (GET_CODE (operands[2]) == CONST_INT)
5933     {
5934       emit_insn (gen_adddi3 (operands[0], operands[1],
5935                              negate_rtx (DImode, operands[2])));
5936       DONE;
5937     }
5938 }")
5939
5940 (define_insn_and_split "absdi2"
5941   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5942         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
5943    (clobber (match_scratch:DI 2 "=&r,&r"))]
5944   "TARGET_POWERPC64"
5945   "#"
5946   "&& reload_completed"
5947   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
5948    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
5949    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
5950   "")
5951
5952 (define_insn_and_split "*nabsdi2"
5953   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5954         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
5955    (clobber (match_scratch:DI 2 "=&r,&r"))]
5956   "TARGET_POWERPC64"
5957   "#"
5958   "&& reload_completed"
5959   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
5960    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
5961    (set (match_dup 0) (minus:DI (match_dup 2) (match_dup 0)))]
5962   "")
5963
5964 (define_expand "negdi2"
5965   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5966         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "")))]
5967   ""
5968   "")
5969
5970 (define_insn ""
5971   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5972         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
5973   "TARGET_POWERPC64"
5974   "neg %0,%1")
5975
5976 (define_insn ""
5977   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5978         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
5979                     (const_int 0)))
5980    (clobber (match_scratch:DI 2 "=r,r"))]
5981   "TARGET_64BIT"
5982   "@
5983    neg. %2,%1
5984    #"
5985   [(set_attr "type" "fast_compare")
5986    (set_attr "length" "4,8")])
5987
5988 (define_split
5989   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5990         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" ""))
5991                     (const_int 0)))
5992    (clobber (match_scratch:DI 2 ""))]
5993   "TARGET_POWERPC64 && reload_completed"
5994   [(set (match_dup 2)
5995         (neg:DI (match_dup 1)))
5996    (set (match_dup 0)
5997         (compare:CC (match_dup 2)
5998                     (const_int 0)))]
5999   "")
6000
6001 (define_insn ""
6002   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
6003         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
6004                     (const_int 0)))
6005    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6006         (neg:DI (match_dup 1)))]
6007   "TARGET_64BIT"
6008   "@
6009    neg. %0,%1
6010    #"
6011   [(set_attr "type" "fast_compare")
6012    (set_attr "length" "4,8")])
6013
6014 (define_split
6015   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
6016         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" ""))
6017                     (const_int 0)))
6018    (set (match_operand:DI 0 "gpc_reg_operand" "")
6019         (neg:DI (match_dup 1)))]
6020   "TARGET_POWERPC64 && reload_completed"
6021   [(set (match_dup 0)
6022         (neg:DI (match_dup 1)))
6023    (set (match_dup 2)
6024         (compare:CC (match_dup 0)
6025                     (const_int 0)))]
6026   "")
6027
6028 (define_insn "clzdi2"
6029   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6030         (clz:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
6031   "TARGET_POWERPC64"
6032   "cntlzd %0,%1")
6033
6034 (define_expand "ctzdi2"
6035   [(set (match_dup 2)
6036         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
6037    (parallel [(set (match_dup 3) (and:DI (match_dup 1)
6038                                          (match_dup 2)))
6039               (clobber (scratch:CC))])
6040    (set (match_dup 4) (clz:DI (match_dup 3)))
6041    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
6042         (minus:DI (const_int 63) (match_dup 4)))]
6043   "TARGET_POWERPC64"
6044   {
6045      operands[2] = gen_reg_rtx (DImode);
6046      operands[3] = gen_reg_rtx (DImode);
6047      operands[4] = gen_reg_rtx (DImode);
6048   })
6049
6050 (define_expand "ffsdi2"
6051   [(set (match_dup 2)
6052         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
6053    (parallel [(set (match_dup 3) (and:DI (match_dup 1)
6054                                          (match_dup 2)))
6055               (clobber (scratch:CC))])
6056    (set (match_dup 4) (clz:DI (match_dup 3)))
6057    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
6058         (minus:DI (const_int 64) (match_dup 4)))]
6059   "TARGET_POWERPC64"
6060   {
6061      operands[2] = gen_reg_rtx (DImode);
6062      operands[3] = gen_reg_rtx (DImode);
6063      operands[4] = gen_reg_rtx (DImode);
6064   })
6065
6066 (define_insn "muldi3"
6067   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6068         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
6069                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
6070   "TARGET_POWERPC64"
6071   "mulld %0,%1,%2"
6072    [(set_attr "type" "lmul")])
6073
6074 (define_insn "*muldi3_internal1"
6075   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6076         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6077                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6078                     (const_int 0)))
6079    (clobber (match_scratch:DI 3 "=r,r"))]
6080   "TARGET_POWERPC64"
6081   "@
6082    mulld. %3,%1,%2
6083    #"
6084   [(set_attr "type" "lmul_compare")
6085    (set_attr "length" "4,8")])
6086
6087 (define_split
6088   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6089         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6090                              (match_operand:DI 2 "gpc_reg_operand" ""))
6091                     (const_int 0)))
6092    (clobber (match_scratch:DI 3 ""))]
6093   "TARGET_POWERPC64 && reload_completed"
6094   [(set (match_dup 3)
6095         (mult:DI (match_dup 1) (match_dup 2)))
6096    (set (match_dup 0)
6097         (compare:CC (match_dup 3)
6098                     (const_int 0)))]
6099   "")
6100
6101 (define_insn "*muldi3_internal2"
6102   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6103         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6104                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6105                     (const_int 0)))
6106    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6107         (mult:DI (match_dup 1) (match_dup 2)))]
6108   "TARGET_POWERPC64"
6109   "@
6110    mulld. %0,%1,%2
6111    #"
6112   [(set_attr "type" "lmul_compare")
6113    (set_attr "length" "4,8")])
6114
6115 (define_split
6116   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6117         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6118                              (match_operand:DI 2 "gpc_reg_operand" ""))
6119                     (const_int 0)))
6120    (set (match_operand:DI 0 "gpc_reg_operand" "")
6121         (mult:DI (match_dup 1) (match_dup 2)))]
6122   "TARGET_POWERPC64 && reload_completed"
6123   [(set (match_dup 0)
6124         (mult:DI (match_dup 1) (match_dup 2)))
6125    (set (match_dup 3)
6126         (compare:CC (match_dup 0)
6127                     (const_int 0)))]
6128   "")
6129
6130 (define_insn "smuldi3_highpart"
6131   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6132         (truncate:DI
6133          (lshiftrt:TI (mult:TI (sign_extend:TI
6134                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6135                                (sign_extend:TI
6136                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6137                       (const_int 64))))]
6138   "TARGET_POWERPC64"
6139   "mulhd %0,%1,%2"
6140   [(set_attr "type" "lmul")])
6141
6142 (define_insn "umuldi3_highpart"
6143   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6144         (truncate:DI
6145          (lshiftrt:TI (mult:TI (zero_extend:TI
6146                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6147                                (zero_extend:TI
6148                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6149                       (const_int 64))))]
6150   "TARGET_POWERPC64"
6151   "mulhdu %0,%1,%2"
6152   [(set_attr "type" "lmul")])
6153
6154 (define_expand "divdi3"
6155   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6156         (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6157                 (match_operand:DI 2 "reg_or_cint_operand" "")))]
6158   "TARGET_POWERPC64"
6159   "
6160 {
6161   if (GET_CODE (operands[2]) == CONST_INT
6162       && INTVAL (operands[2]) > 0
6163       && exact_log2 (INTVAL (operands[2])) >= 0)
6164     ;
6165   else
6166     operands[2] = force_reg (DImode, operands[2]);
6167 }")
6168
6169 (define_expand "moddi3"
6170   [(use (match_operand:DI 0 "gpc_reg_operand" ""))
6171    (use (match_operand:DI 1 "gpc_reg_operand" ""))
6172    (use (match_operand:DI 2 "reg_or_cint_operand" ""))]
6173   "TARGET_POWERPC64"
6174   "
6175 {
6176   int i;
6177   rtx temp1;
6178   rtx temp2;
6179
6180   if (GET_CODE (operands[2]) != CONST_INT
6181       || INTVAL (operands[2]) <= 0
6182       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
6183     FAIL;
6184
6185   temp1 = gen_reg_rtx (DImode);
6186   temp2 = gen_reg_rtx (DImode);
6187
6188   emit_insn (gen_divdi3 (temp1, operands[1], operands[2]));
6189   emit_insn (gen_ashldi3 (temp2, temp1, GEN_INT (i)));
6190   emit_insn (gen_subdi3 (operands[0], operands[1], temp2));
6191   DONE;
6192 }")
6193
6194 (define_insn ""
6195   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6196         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6197                 (match_operand:DI 2 "exact_log2_cint_operand" "N")))]
6198   "TARGET_POWERPC64"
6199   "sradi %0,%1,%p2\;addze %0,%0"
6200   [(set_attr "length" "8")])
6201
6202 (define_insn ""
6203   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6204         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6205                             (match_operand:DI 2 "exact_log2_cint_operand" "N,N"))
6206                     (const_int 0)))
6207    (clobber (match_scratch:DI 3 "=r,r"))]
6208   "TARGET_64BIT"
6209   "@
6210    sradi %3,%1,%p2\;addze. %3,%3
6211    #"
6212   [(set_attr "type" "compare")
6213    (set_attr "length" "8,12")])
6214
6215 (define_split
6216   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6217         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6218                             (match_operand:DI 2 "exact_log2_cint_operand" ""))
6219                     (const_int 0)))
6220    (clobber (match_scratch:DI 3 ""))]
6221   "TARGET_POWERPC64 && reload_completed"
6222   [(set (match_dup 3)
6223         (div:DI (match_dup 1) (match_dup 2)))
6224    (set (match_dup 0)
6225         (compare:CC (match_dup 3)
6226                     (const_int 0)))]
6227   "")
6228
6229 (define_insn ""
6230   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6231         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6232                             (match_operand:DI 2 "exact_log2_cint_operand" "N,N"))
6233                     (const_int 0)))
6234    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6235         (div:DI (match_dup 1) (match_dup 2)))]
6236   "TARGET_64BIT"
6237   "@
6238    sradi %0,%1,%p2\;addze. %0,%0
6239    #"
6240   [(set_attr "type" "compare")
6241    (set_attr "length" "8,12")])
6242
6243 (define_split
6244   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6245         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6246                             (match_operand:DI 2 "exact_log2_cint_operand" ""))
6247                     (const_int 0)))
6248    (set (match_operand:DI 0 "gpc_reg_operand" "")
6249         (div:DI (match_dup 1) (match_dup 2)))]
6250   "TARGET_POWERPC64 && reload_completed"
6251   [(set (match_dup 0)
6252         (div:DI (match_dup 1) (match_dup 2)))
6253    (set (match_dup 3)
6254         (compare:CC (match_dup 0)
6255                     (const_int 0)))]
6256   "")
6257
6258 (define_insn ""
6259   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6260         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6261                 (match_operand:DI 2 "gpc_reg_operand" "r")))]
6262   "TARGET_POWERPC64"
6263   "divd %0,%1,%2"
6264   [(set_attr "type" "ldiv")])
6265
6266 (define_insn "udivdi3"
6267   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6268         (udiv:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6269                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
6270   "TARGET_POWERPC64"
6271   "divdu %0,%1,%2"
6272   [(set_attr "type" "ldiv")])
6273
6274 (define_insn "rotldi3"
6275   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6276         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6277                    (match_operand:DI 2 "reg_or_cint_operand" "ri")))]
6278   "TARGET_POWERPC64"
6279   "rld%I2cl %0,%1,%H2,0")
6280
6281 (define_insn "*rotldi3_internal2"
6282   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6283         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6284                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6285                     (const_int 0)))
6286    (clobber (match_scratch:DI 3 "=r,r"))]
6287   "TARGET_64BIT"
6288   "@
6289    rld%I2cl. %3,%1,%H2,0
6290    #"
6291   [(set_attr "type" "delayed_compare")
6292    (set_attr "length" "4,8")])
6293
6294 (define_split
6295   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6296         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6297                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6298                     (const_int 0)))
6299    (clobber (match_scratch:DI 3 ""))]
6300   "TARGET_POWERPC64 && reload_completed"
6301   [(set (match_dup 3)
6302         (rotate:DI (match_dup 1) (match_dup 2)))
6303    (set (match_dup 0)
6304         (compare:CC (match_dup 3)
6305                     (const_int 0)))]
6306   "")
6307
6308 (define_insn "*rotldi3_internal3"
6309   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6310         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6311                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6312                     (const_int 0)))
6313    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6314         (rotate:DI (match_dup 1) (match_dup 2)))]
6315   "TARGET_64BIT"
6316   "@
6317    rld%I2cl. %0,%1,%H2,0
6318    #"
6319   [(set_attr "type" "delayed_compare")
6320    (set_attr "length" "4,8")])
6321
6322 (define_split
6323   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6324         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6325                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6326                     (const_int 0)))
6327    (set (match_operand:DI 0 "gpc_reg_operand" "")
6328         (rotate:DI (match_dup 1) (match_dup 2)))]
6329   "TARGET_POWERPC64 && reload_completed"
6330   [(set (match_dup 0)
6331         (rotate:DI (match_dup 1) (match_dup 2)))
6332    (set (match_dup 3)
6333         (compare:CC (match_dup 0)
6334                     (const_int 0)))]
6335   "")
6336
6337 (define_insn "*rotldi3_internal4"
6338   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6339         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6340                            (match_operand:DI 2 "reg_or_cint_operand" "ri"))
6341                 (match_operand:DI 3 "mask64_operand" "n")))]
6342   "TARGET_POWERPC64"
6343   "rld%I2c%B3 %0,%1,%H2,%S3")
6344
6345 (define_insn "*rotldi3_internal5"
6346   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6347         (compare:CC (and:DI
6348                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6349                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6350                      (match_operand:DI 3 "mask64_operand" "n,n"))
6351                     (const_int 0)))
6352    (clobber (match_scratch:DI 4 "=r,r"))]
6353   "TARGET_64BIT"
6354   "@
6355    rld%I2c%B3. %4,%1,%H2,%S3
6356    #"
6357   [(set_attr "type" "delayed_compare")
6358    (set_attr "length" "4,8")])
6359
6360 (define_split
6361   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6362         (compare:CC (and:DI
6363                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6364                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6365                      (match_operand:DI 3 "mask64_operand" ""))
6366                     (const_int 0)))
6367    (clobber (match_scratch:DI 4 ""))]
6368   "TARGET_POWERPC64 && reload_completed"
6369   [(set (match_dup 4)
6370         (and:DI (rotate:DI (match_dup 1)
6371                                 (match_dup 2))
6372                      (match_dup 3)))
6373    (set (match_dup 0)
6374         (compare:CC (match_dup 4)
6375                     (const_int 0)))]
6376   "")
6377
6378 (define_insn "*rotldi3_internal6"
6379   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6380         (compare:CC (and:DI
6381                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6382                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6383                      (match_operand:DI 3 "mask64_operand" "n,n"))
6384                     (const_int 0)))
6385    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6386         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6387   "TARGET_64BIT"
6388   "@
6389    rld%I2c%B3. %0,%1,%H2,%S3
6390    #"
6391   [(set_attr "type" "delayed_compare")
6392    (set_attr "length" "4,8")])
6393
6394 (define_split
6395   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6396         (compare:CC (and:DI
6397                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6398                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6399                      (match_operand:DI 3 "mask64_operand" ""))
6400                     (const_int 0)))
6401    (set (match_operand:DI 0 "gpc_reg_operand" "")
6402         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6403   "TARGET_POWERPC64 && reload_completed"
6404   [(set (match_dup 0)
6405         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
6406    (set (match_dup 4)
6407         (compare:CC (match_dup 0)
6408                     (const_int 0)))]
6409   "")
6410
6411 (define_insn "*rotldi3_internal7"
6412   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6413         (zero_extend:DI
6414          (subreg:QI
6415           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6416                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6417   "TARGET_POWERPC64"
6418   "rld%I2cl %0,%1,%H2,56")
6419
6420 (define_insn "*rotldi3_internal8"
6421   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6422         (compare:CC (zero_extend:DI
6423                      (subreg:QI
6424                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6425                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6426                     (const_int 0)))
6427    (clobber (match_scratch:DI 3 "=r,r"))]
6428   "TARGET_64BIT"
6429   "@
6430    rld%I2cl. %3,%1,%H2,56
6431    #"
6432   [(set_attr "type" "delayed_compare")
6433    (set_attr "length" "4,8")])
6434
6435 (define_split
6436   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6437         (compare:CC (zero_extend:DI
6438                      (subreg:QI
6439                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6440                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6441                     (const_int 0)))
6442    (clobber (match_scratch:DI 3 ""))]
6443   "TARGET_POWERPC64 && reload_completed"
6444   [(set (match_dup 3)
6445         (zero_extend:DI (subreg:QI
6446                       (rotate:DI (match_dup 1)
6447                                  (match_dup 2)) 0)))
6448    (set (match_dup 0)
6449         (compare:CC (match_dup 3)
6450                     (const_int 0)))]
6451   "")
6452
6453 (define_insn "*rotldi3_internal9"
6454   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6455         (compare:CC (zero_extend:DI
6456                      (subreg:QI
6457                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6458                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6459                     (const_int 0)))
6460    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6461         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6462   "TARGET_64BIT"
6463   "@
6464    rld%I2cl. %0,%1,%H2,56
6465    #"
6466   [(set_attr "type" "delayed_compare")
6467    (set_attr "length" "4,8")])
6468
6469 (define_split
6470   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6471         (compare:CC (zero_extend:DI
6472                      (subreg:QI
6473                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6474                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6475                     (const_int 0)))
6476    (set (match_operand:DI 0 "gpc_reg_operand" "")
6477         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6478   "TARGET_POWERPC64 && reload_completed"
6479   [(set (match_dup 0)
6480         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6481    (set (match_dup 3)
6482         (compare:CC (match_dup 0)
6483                     (const_int 0)))]
6484   "")
6485
6486 (define_insn "*rotldi3_internal10"
6487   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6488         (zero_extend:DI
6489          (subreg:HI
6490           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6491                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6492   "TARGET_POWERPC64"
6493   "rld%I2cl %0,%1,%H2,48")
6494
6495 (define_insn "*rotldi3_internal11"
6496   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6497         (compare:CC (zero_extend:DI
6498                      (subreg:HI
6499                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6500                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6501                     (const_int 0)))
6502    (clobber (match_scratch:DI 3 "=r,r"))]
6503   "TARGET_64BIT"
6504   "@
6505    rld%I2cl. %3,%1,%H2,48
6506    #"
6507   [(set_attr "type" "delayed_compare")
6508    (set_attr "length" "4,8")])
6509
6510 (define_split
6511   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6512         (compare:CC (zero_extend:DI
6513                      (subreg:HI
6514                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6515                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6516                     (const_int 0)))
6517    (clobber (match_scratch:DI 3 ""))]
6518   "TARGET_POWERPC64 && reload_completed"
6519   [(set (match_dup 3)
6520         (zero_extend:DI (subreg:HI
6521                       (rotate:DI (match_dup 1)
6522                                  (match_dup 2)) 0)))
6523    (set (match_dup 0)
6524         (compare:CC (match_dup 3)
6525                     (const_int 0)))]
6526   "")
6527
6528 (define_insn "*rotldi3_internal12"
6529   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6530         (compare:CC (zero_extend:DI
6531                      (subreg:HI
6532                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6533                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6534                     (const_int 0)))
6535    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6536         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6537   "TARGET_64BIT"
6538   "@
6539    rld%I2cl. %0,%1,%H2,48
6540    #"
6541   [(set_attr "type" "delayed_compare")
6542    (set_attr "length" "4,8")])
6543
6544 (define_split
6545   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6546         (compare:CC (zero_extend:DI
6547                      (subreg:HI
6548                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6549                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6550                     (const_int 0)))
6551    (set (match_operand:DI 0 "gpc_reg_operand" "")
6552         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6553   "TARGET_POWERPC64 && reload_completed"
6554   [(set (match_dup 0)
6555         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6556    (set (match_dup 3)
6557         (compare:CC (match_dup 0)
6558                     (const_int 0)))]
6559   "")
6560
6561 (define_insn "*rotldi3_internal13"
6562   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6563         (zero_extend:DI
6564          (subreg:SI
6565           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6566                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6567   "TARGET_POWERPC64"
6568   "rld%I2cl %0,%1,%H2,32")
6569
6570 (define_insn "*rotldi3_internal14"
6571   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6572         (compare:CC (zero_extend:DI
6573                      (subreg:SI
6574                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6575                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6576                     (const_int 0)))
6577    (clobber (match_scratch:DI 3 "=r,r"))]
6578   "TARGET_64BIT"
6579   "@
6580    rld%I2cl. %3,%1,%H2,32
6581    #"
6582   [(set_attr "type" "delayed_compare")
6583    (set_attr "length" "4,8")])
6584
6585 (define_split
6586   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6587         (compare:CC (zero_extend:DI
6588                      (subreg:SI
6589                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6590                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6591                     (const_int 0)))
6592    (clobber (match_scratch:DI 3 ""))]
6593   "TARGET_POWERPC64 && reload_completed"
6594   [(set (match_dup 3)
6595         (zero_extend:DI (subreg:SI
6596                       (rotate:DI (match_dup 1)
6597                                  (match_dup 2)) 0)))
6598    (set (match_dup 0)
6599         (compare:CC (match_dup 3)
6600                     (const_int 0)))]
6601   "")
6602
6603 (define_insn "*rotldi3_internal15"
6604   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6605         (compare:CC (zero_extend:DI
6606                      (subreg:SI
6607                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6608                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6609                     (const_int 0)))
6610    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6611         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6612   "TARGET_64BIT"
6613   "@
6614    rld%I2cl. %0,%1,%H2,32
6615    #"
6616   [(set_attr "type" "delayed_compare")
6617    (set_attr "length" "4,8")])
6618
6619 (define_split
6620   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6621         (compare:CC (zero_extend:DI
6622                      (subreg:SI
6623                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6624                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6625                     (const_int 0)))
6626    (set (match_operand:DI 0 "gpc_reg_operand" "")
6627         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6628   "TARGET_POWERPC64 && reload_completed"
6629   [(set (match_dup 0)
6630         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6631    (set (match_dup 3)
6632         (compare:CC (match_dup 0)
6633                     (const_int 0)))]
6634   "")
6635
6636 (define_expand "ashldi3"
6637   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6638         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6639                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
6640   "TARGET_POWERPC64 || TARGET_POWER"
6641   "
6642 {
6643   if (TARGET_POWERPC64)
6644     ;
6645   else if (TARGET_POWER)
6646     {
6647       emit_insn (gen_ashldi3_power (operands[0], operands[1], operands[2]));
6648       DONE;
6649     }
6650   else
6651     FAIL;
6652 }")
6653
6654 (define_insn "*ashldi3_internal1"
6655   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6656         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6657                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6658   "TARGET_POWERPC64"
6659   "sld%I2 %0,%1,%H2"
6660   [(set_attr "length" "8")])
6661
6662 (define_insn "*ashldi3_internal2"
6663   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6664         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6665                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6666                     (const_int 0)))
6667    (clobber (match_scratch:DI 3 "=r,r"))]
6668   "TARGET_64BIT"
6669   "@
6670    sld%I2. %3,%1,%H2
6671    #"
6672   [(set_attr "type" "delayed_compare")
6673    (set_attr "length" "4,8")])
6674
6675 (define_split
6676   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6677         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6678                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6679                     (const_int 0)))
6680    (clobber (match_scratch:DI 3 ""))]
6681   "TARGET_POWERPC64 && reload_completed"
6682   [(set (match_dup 3)
6683         (ashift:DI (match_dup 1) (match_dup 2)))
6684    (set (match_dup 0)
6685         (compare:CC (match_dup 3)
6686                     (const_int 0)))]
6687   "")
6688
6689 (define_insn "*ashldi3_internal3"
6690   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6691         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6692                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6693                     (const_int 0)))
6694    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6695         (ashift:DI (match_dup 1) (match_dup 2)))]
6696   "TARGET_64BIT"
6697   "@
6698    sld%I2. %0,%1,%H2
6699    #"
6700   [(set_attr "type" "delayed_compare")
6701    (set_attr "length" "4,8")])
6702
6703 (define_split
6704   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6705         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6706                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6707                     (const_int 0)))
6708    (set (match_operand:DI 0 "gpc_reg_operand" "")
6709         (ashift:DI (match_dup 1) (match_dup 2)))]
6710   "TARGET_POWERPC64 && reload_completed"
6711   [(set (match_dup 0)
6712         (ashift:DI (match_dup 1) (match_dup 2)))
6713    (set (match_dup 3)
6714         (compare:CC (match_dup 0)
6715                     (const_int 0)))]
6716   "")
6717
6718 (define_insn "*ashldi3_internal4"
6719   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6720         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6721                            (match_operand:SI 2 "const_int_operand" "i"))
6722                 (match_operand:DI 3 "const_int_operand" "n")))]
6723   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
6724   "rldic %0,%1,%H2,%W3")
6725
6726 (define_insn "ashldi3_internal5"
6727   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6728         (compare:CC
6729          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6730                             (match_operand:SI 2 "const_int_operand" "i,i"))
6731                  (match_operand:DI 3 "const_int_operand" "n,n"))
6732          (const_int 0)))
6733    (clobber (match_scratch:DI 4 "=r,r"))]
6734   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6735   "@
6736    rldic. %4,%1,%H2,%W3
6737    #"
6738   [(set_attr "type" "delayed_compare")
6739    (set_attr "length" "4,8")])
6740
6741 (define_split
6742   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6743         (compare:CC
6744          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6745                             (match_operand:SI 2 "const_int_operand" ""))
6746                  (match_operand:DI 3 "const_int_operand" ""))
6747          (const_int 0)))
6748    (clobber (match_scratch:DI 4 ""))]
6749   "TARGET_POWERPC64 && reload_completed
6750    && includes_rldic_lshift_p (operands[2], operands[3])"
6751   [(set (match_dup 4)
6752         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6753                 (match_dup 3)))
6754    (set (match_dup 0)
6755         (compare:CC (match_dup 4)
6756                     (const_int 0)))]
6757   "")
6758
6759 (define_insn "*ashldi3_internal6"
6760   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6761         (compare:CC
6762          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6763                             (match_operand:SI 2 "const_int_operand" "i,i"))
6764                     (match_operand:DI 3 "const_int_operand" "n,n"))
6765          (const_int 0)))
6766    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6767         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6768   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6769   "@
6770    rldic. %0,%1,%H2,%W3
6771    #"
6772   [(set_attr "type" "delayed_compare")
6773    (set_attr "length" "4,8")])
6774
6775 (define_split
6776   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6777         (compare:CC
6778          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6779                             (match_operand:SI 2 "const_int_operand" ""))
6780                  (match_operand:DI 3 "const_int_operand" ""))
6781          (const_int 0)))
6782    (set (match_operand:DI 0 "gpc_reg_operand" "")
6783         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6784   "TARGET_POWERPC64 && reload_completed
6785    && includes_rldic_lshift_p (operands[2], operands[3])"
6786   [(set (match_dup 0)
6787         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6788                 (match_dup 3)))
6789    (set (match_dup 4)
6790         (compare:CC (match_dup 0)
6791                     (const_int 0)))]
6792   "")
6793
6794 (define_insn "*ashldi3_internal7"
6795   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6796         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6797                            (match_operand:SI 2 "const_int_operand" "i"))
6798                 (match_operand:DI 3 "mask64_operand" "n")))]
6799   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
6800   "rldicr %0,%1,%H2,%S3")
6801
6802 (define_insn "ashldi3_internal8"
6803   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6804         (compare:CC
6805          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6806                             (match_operand:SI 2 "const_int_operand" "i,i"))
6807                  (match_operand:DI 3 "mask64_operand" "n,n"))
6808          (const_int 0)))
6809    (clobber (match_scratch:DI 4 "=r,r"))]
6810   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
6811   "@
6812    rldicr. %4,%1,%H2,%S3
6813    #"
6814   [(set_attr "type" "delayed_compare")
6815    (set_attr "length" "4,8")])
6816
6817 (define_split
6818   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6819         (compare:CC
6820          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6821                             (match_operand:SI 2 "const_int_operand" ""))
6822                  (match_operand:DI 3 "mask64_operand" ""))
6823          (const_int 0)))
6824    (clobber (match_scratch:DI 4 ""))]
6825   "TARGET_POWERPC64 && reload_completed
6826    && includes_rldicr_lshift_p (operands[2], operands[3])"
6827   [(set (match_dup 4)
6828         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6829                 (match_dup 3)))
6830    (set (match_dup 0)
6831         (compare:CC (match_dup 4)
6832                     (const_int 0)))]
6833   "")
6834
6835 (define_insn "*ashldi3_internal9"
6836   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6837         (compare:CC
6838          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6839                             (match_operand:SI 2 "const_int_operand" "i,i"))
6840                     (match_operand:DI 3 "mask64_operand" "n,n"))
6841          (const_int 0)))
6842    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6843         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6844   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
6845   "@
6846    rldicr. %0,%1,%H2,%S3
6847    #"
6848   [(set_attr "type" "delayed_compare")
6849    (set_attr "length" "4,8")])
6850
6851 (define_split
6852   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6853         (compare:CC
6854          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6855                             (match_operand:SI 2 "const_int_operand" ""))
6856                  (match_operand:DI 3 "mask64_operand" ""))
6857          (const_int 0)))
6858    (set (match_operand:DI 0 "gpc_reg_operand" "")
6859         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6860   "TARGET_POWERPC64 && reload_completed
6861    && includes_rldicr_lshift_p (operands[2], operands[3])"
6862   [(set (match_dup 0)
6863         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6864                 (match_dup 3)))
6865    (set (match_dup 4)
6866         (compare:CC (match_dup 0)
6867                     (const_int 0)))]
6868   "")
6869
6870 (define_expand "lshrdi3"
6871   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6872         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6873                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
6874   "TARGET_POWERPC64 || TARGET_POWER"
6875   "
6876 {
6877   if (TARGET_POWERPC64)
6878     ;
6879   else if (TARGET_POWER)
6880     {
6881       emit_insn (gen_lshrdi3_power (operands[0], operands[1], operands[2]));
6882       DONE;
6883     }
6884   else
6885     FAIL;
6886 }")
6887
6888 (define_insn "*lshrdi3_internal1"
6889   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6890         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6891                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6892   "TARGET_POWERPC64"
6893   "srd%I2 %0,%1,%H2")
6894
6895 (define_insn "*lshrdi3_internal2"
6896   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6897         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6898                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6899                     (const_int 0)))
6900    (clobber (match_scratch:DI 3 "=r,r"))]
6901   "TARGET_64BIT "
6902   "@
6903    srd%I2. %3,%1,%H2
6904    #"
6905   [(set_attr "type" "delayed_compare")
6906    (set_attr "length" "4,8")])
6907
6908 (define_split
6909   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6910         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6911                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6912                     (const_int 0)))
6913    (clobber (match_scratch:DI 3 ""))]
6914   "TARGET_POWERPC64 && reload_completed"
6915   [(set (match_dup 3)
6916         (lshiftrt:DI (match_dup 1) (match_dup 2)))
6917    (set (match_dup 0)
6918         (compare:CC (match_dup 3)
6919                     (const_int 0)))]
6920   "")
6921
6922 (define_insn "*lshrdi3_internal3"
6923   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6924         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6925                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6926                     (const_int 0)))
6927    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6928         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
6929   "TARGET_64BIT"
6930   "@
6931    srd%I2. %0,%1,%H2
6932    #"
6933   [(set_attr "type" "delayed_compare")
6934    (set_attr "length" "4,8")])
6935
6936 (define_split
6937   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6938         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6939                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6940                     (const_int 0)))
6941    (set (match_operand:DI 0 "gpc_reg_operand" "")
6942         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
6943   "TARGET_POWERPC64 && reload_completed"
6944   [(set (match_dup 0)
6945         (lshiftrt:DI (match_dup 1) (match_dup 2)))
6946    (set (match_dup 3)
6947         (compare:CC (match_dup 0)
6948                     (const_int 0)))]
6949   "")
6950
6951 (define_expand "ashrdi3"
6952   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6953         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6954                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
6955   "WORDS_BIG_ENDIAN"
6956   "
6957 {
6958   if (TARGET_POWERPC64)
6959     ;
6960   else if (TARGET_POWER && GET_CODE (operands[2]) == CONST_INT)
6961     {
6962       emit_insn (gen_ashrdi3_power (operands[0], operands[1], operands[2]));
6963       DONE;
6964     }
6965   else if (TARGET_32BIT && GET_CODE (operands[2]) == CONST_INT
6966            && WORDS_BIG_ENDIAN)
6967     {
6968       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
6969       DONE;
6970     }
6971   else
6972     FAIL;
6973 }")
6974
6975 (define_insn "*ashrdi3_internal1"
6976   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6977         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6978                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6979   "TARGET_POWERPC64"
6980   "srad%I2 %0,%1,%H2")
6981
6982 (define_insn "*ashrdi3_internal2"
6983   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6984         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6985                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6986                     (const_int 0)))
6987    (clobber (match_scratch:DI 3 "=r,r"))]
6988   "TARGET_64BIT"
6989   "@
6990    srad%I2. %3,%1,%H2
6991    #"
6992   [(set_attr "type" "delayed_compare")
6993    (set_attr "length" "4,8")])
6994
6995 (define_split
6996   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6997         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6998                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6999                     (const_int 0)))
7000    (clobber (match_scratch:DI 3 ""))]
7001   "TARGET_POWERPC64 && reload_completed"
7002   [(set (match_dup 3)
7003         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7004    (set (match_dup 0)
7005         (compare:CC (match_dup 3)
7006                     (const_int 0)))]
7007   "")
7008
7009 (define_insn "*ashrdi3_internal3"
7010   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7011         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7012                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7013                     (const_int 0)))
7014    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7015         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7016   "TARGET_64BIT"
7017   "@
7018    srad%I2. %0,%1,%H2
7019    #"
7020   [(set_attr "type" "delayed_compare")
7021    (set_attr "length" "4,8")])
7022
7023 (define_split
7024   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7025         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7026                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7027                     (const_int 0)))
7028    (set (match_operand:DI 0 "gpc_reg_operand" "")
7029         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7030   "TARGET_POWERPC64 && reload_completed"
7031   [(set (match_dup 0)
7032         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7033    (set (match_dup 3)
7034         (compare:CC (match_dup 0)
7035                     (const_int 0)))]
7036   "")
7037
7038 (define_insn "anddi3"
7039   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r")
7040         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r")
7041                 (match_operand:DI 2 "and64_2_operand" "?r,S,K,J,t")))
7042    (clobber (match_scratch:CC 3 "=X,X,x,x,X"))]
7043   "TARGET_POWERPC64"
7044   "@
7045    and %0,%1,%2
7046    rldic%B2 %0,%1,0,%S2
7047    andi. %0,%1,%b2
7048    andis. %0,%1,%u2
7049    #"
7050   [(set_attr "length" "4,4,4,4,8")])
7051
7052 (define_split
7053   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7054         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7055                 (match_operand:DI 2 "mask64_2_operand" "")))
7056    (clobber (match_scratch:CC 3 ""))]
7057   "TARGET_POWERPC64
7058     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7059     && !mask64_operand (operands[2], DImode)"
7060   [(set (match_dup 0)
7061         (and:DI (rotate:DI (match_dup 1)
7062                            (match_dup 4))
7063                 (match_dup 5)))
7064    (set (match_dup 0)
7065         (and:DI (rotate:DI (match_dup 0)
7066                            (match_dup 6))
7067                 (match_dup 7)))]
7068   "
7069 {
7070   build_mask64_2_operands (operands[2], &operands[4]);
7071 }")
7072
7073 (define_insn "*anddi3_internal2"
7074   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,??y,??y,?y")
7075         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
7076                             (match_operand:DI 2 "and64_2_operand" "r,S,K,J,t,r,S,K,J,t"))
7077                     (const_int 0)))
7078    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r"))
7079    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,x,x,X"))]
7080   "TARGET_64BIT"
7081   "@
7082    and. %3,%1,%2
7083    rldic%B2. %3,%1,0,%S2
7084    andi. %3,%1,%b2
7085    andis. %3,%1,%u2
7086    #
7087    #
7088    #
7089    #
7090    #
7091    #"
7092   [(set_attr "type" "compare,delayed_compare,compare,compare,delayed_compare,compare,compare,compare,compare,compare")
7093    (set_attr "length" "4,4,4,4,8,8,8,8,8,12")])
7094
7095 (define_split
7096   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7097         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7098                             (match_operand:DI 2 "and64_operand" ""))
7099                     (const_int 0)))
7100    (clobber (match_scratch:DI 3 ""))
7101    (clobber (match_scratch:CC 4 ""))]
7102   "TARGET_POWERPC64 && reload_completed"
7103   [(parallel [(set (match_dup 3)
7104                    (and:DI (match_dup 1)
7105                            (match_dup 2)))
7106               (clobber (match_dup 4))])
7107    (set (match_dup 0)
7108         (compare:CC (match_dup 3)
7109                     (const_int 0)))]
7110   "")
7111
7112 (define_split
7113   [(set (match_operand:CC 0 "cc_reg_operand" "")
7114         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7115                             (match_operand:DI 2 "mask64_2_operand" ""))
7116                     (const_int 0)))
7117    (clobber (match_scratch:DI 3 ""))
7118    (clobber (match_scratch:CC 4 ""))]
7119   "TARGET_POWERPC64 && reload_completed
7120     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7121     && !mask64_operand (operands[2], DImode)"
7122   [(set (match_dup 3)
7123         (and:DI (rotate:DI (match_dup 1)
7124                            (match_dup 5))
7125                 (match_dup 6)))
7126    (parallel [(set (match_dup 0)
7127                    (compare:CC (and:DI (rotate:DI (match_dup 3)
7128                                                   (match_dup 7))
7129                                        (match_dup 8))
7130                                (const_int 0)))
7131               (clobber (match_dup 3))])]
7132   "
7133 {
7134   build_mask64_2_operands (operands[2], &operands[5]);
7135 }")
7136
7137 (define_insn "*anddi3_internal3"
7138   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,?y,?y,??y,??y,?y")
7139         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
7140                             (match_operand:DI 2 "and64_2_operand" "r,S,K,J,t,r,S,K,J,t"))
7141                     (const_int 0)))
7142    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
7143         (and:DI (match_dup 1) (match_dup 2)))
7144    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,x,x,X"))]
7145   "TARGET_64BIT"
7146   "@
7147    and. %0,%1,%2
7148    rldic%B2. %0,%1,0,%S2
7149    andi. %0,%1,%b2
7150    andis. %0,%1,%u2
7151    #
7152    #
7153    #
7154    #
7155    #
7156    #"
7157   [(set_attr "type" "compare,delayed_compare,compare,compare,delayed_compare,compare,compare,compare,compare,compare")
7158    (set_attr "length" "4,4,4,4,8,8,8,8,8,12")])
7159
7160 (define_split
7161   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7162         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7163                             (match_operand:DI 2 "and64_operand" ""))
7164                     (const_int 0)))
7165    (set (match_operand:DI 0 "gpc_reg_operand" "")
7166         (and:DI (match_dup 1) (match_dup 2)))
7167    (clobber (match_scratch:CC 4 ""))]
7168   "TARGET_POWERPC64 && reload_completed"
7169   [(parallel [(set (match_dup 0)
7170                     (and:DI (match_dup 1) (match_dup 2)))
7171                (clobber (match_dup 4))])
7172    (set (match_dup 3)
7173         (compare:CC (match_dup 0)
7174                     (const_int 0)))]
7175   "")
7176
7177 (define_split
7178   [(set (match_operand:CC 3 "cc_reg_operand" "")
7179         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7180                             (match_operand:DI 2 "mask64_2_operand" ""))
7181                     (const_int 0)))
7182    (set (match_operand:DI 0 "gpc_reg_operand" "")
7183         (and:DI (match_dup 1) (match_dup 2)))
7184    (clobber (match_scratch:CC 4 ""))]
7185   "TARGET_POWERPC64 && reload_completed
7186     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7187     && !mask64_operand (operands[2], DImode)"
7188   [(set (match_dup 0)
7189         (and:DI (rotate:DI (match_dup 1)
7190                            (match_dup 5))
7191                 (match_dup 6)))
7192    (parallel [(set (match_dup 3)
7193                    (compare:CC (and:DI (rotate:DI (match_dup 0)
7194                                                   (match_dup 7))
7195                                        (match_dup 8))
7196                                (const_int 0)))
7197               (set (match_dup 0)
7198                    (and:DI (rotate:DI (match_dup 0)
7199                                       (match_dup 7))
7200                            (match_dup 8)))])]
7201   "
7202 {
7203   build_mask64_2_operands (operands[2], &operands[5]);
7204 }")
7205
7206 (define_expand "iordi3"
7207   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7208         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
7209                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7210   "TARGET_POWERPC64"
7211   "
7212 {
7213   if (non_logical_cint_operand (operands[2], DImode))
7214     {
7215       HOST_WIDE_INT value;
7216       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7217                  ? operands[0] : gen_reg_rtx (DImode));
7218
7219       if (GET_CODE (operands[2]) == CONST_INT)
7220         {
7221           value = INTVAL (operands[2]);
7222           emit_insn (gen_iordi3 (tmp, operands[1],
7223                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7224         }
7225       else
7226         {
7227           value = CONST_DOUBLE_LOW (operands[2]);
7228           emit_insn (gen_iordi3 (tmp, operands[1],
7229                                  immed_double_const (value
7230                                                      & (~ (HOST_WIDE_INT) 0xffff),
7231                                                      0, DImode)));
7232         }
7233
7234       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7235       DONE;
7236     }
7237 }")
7238
7239 (define_expand "xordi3"
7240   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7241         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
7242                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7243   "TARGET_POWERPC64"
7244   "
7245 {
7246   if (non_logical_cint_operand (operands[2], DImode))
7247     {
7248       HOST_WIDE_INT value;
7249       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7250                  ? operands[0] : gen_reg_rtx (DImode));
7251
7252       if (GET_CODE (operands[2]) == CONST_INT)
7253         {
7254           value = INTVAL (operands[2]);
7255           emit_insn (gen_xordi3 (tmp, operands[1],
7256                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7257         }
7258       else
7259         {
7260           value = CONST_DOUBLE_LOW (operands[2]);
7261           emit_insn (gen_xordi3 (tmp, operands[1],
7262                                  immed_double_const (value
7263                                                      & (~ (HOST_WIDE_INT) 0xffff),
7264                                                      0, DImode)));
7265         }
7266
7267       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7268       DONE;
7269     }
7270 }")
7271
7272 (define_insn "*booldi3_internal1"
7273   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
7274         (match_operator:DI 3 "boolean_or_operator"
7275          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
7276           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
7277   "TARGET_POWERPC64"
7278   "@
7279    %q3 %0,%1,%2
7280    %q3i %0,%1,%b2
7281    %q3is %0,%1,%u2")
7282
7283 (define_insn "*booldi3_internal2"
7284   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7285         (compare:CC (match_operator:DI 4 "boolean_or_operator"
7286          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7287           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7288          (const_int 0)))
7289    (clobber (match_scratch:DI 3 "=r,r"))]
7290   "TARGET_64BIT"
7291   "@
7292    %q4. %3,%1,%2
7293    #"
7294   [(set_attr "type" "compare")
7295    (set_attr "length" "4,8")])
7296
7297 (define_split
7298   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7299         (compare:CC (match_operator:DI 4 "boolean_operator"
7300          [(match_operand:DI 1 "gpc_reg_operand" "")
7301           (match_operand:DI 2 "gpc_reg_operand" "")])
7302          (const_int 0)))
7303    (clobber (match_scratch:DI 3 ""))]
7304   "TARGET_POWERPC64 && reload_completed"
7305   [(set (match_dup 3) (match_dup 4))
7306    (set (match_dup 0)
7307         (compare:CC (match_dup 3)
7308                     (const_int 0)))]
7309   "")
7310
7311 (define_insn "*booldi3_internal3"
7312   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7313         (compare:CC (match_operator:DI 4 "boolean_operator"
7314          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7315           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7316          (const_int 0)))
7317    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7318         (match_dup 4))]
7319   "TARGET_64BIT"
7320   "@
7321    %q4. %0,%1,%2
7322    #"
7323   [(set_attr "type" "compare")
7324    (set_attr "length" "4,8")])
7325
7326 (define_split
7327   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7328         (compare:CC (match_operator:DI 4 "boolean_operator"
7329          [(match_operand:DI 1 "gpc_reg_operand" "")
7330           (match_operand:DI 2 "gpc_reg_operand" "")])
7331          (const_int 0)))
7332    (set (match_operand:DI 0 "gpc_reg_operand" "")
7333         (match_dup 4))]
7334   "TARGET_POWERPC64 && reload_completed"
7335   [(set (match_dup 0) (match_dup 4))
7336    (set (match_dup 3)
7337         (compare:CC (match_dup 0)
7338                     (const_int 0)))]
7339   "")
7340
7341 ;; Split a logical operation that we can't do in one insn into two insns,
7342 ;; each of which does one 16-bit part.  This is used by combine.
7343
7344 (define_split
7345   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7346         (match_operator:DI 3 "boolean_or_operator"
7347          [(match_operand:DI 1 "gpc_reg_operand" "")
7348           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
7349   "TARGET_POWERPC64"
7350   [(set (match_dup 0) (match_dup 4))
7351    (set (match_dup 0) (match_dup 5))]
7352 "
7353 {
7354   rtx i3,i4;
7355
7356   if (GET_CODE (operands[2]) == CONST_DOUBLE)
7357     {
7358       HOST_WIDE_INT value = CONST_DOUBLE_LOW (operands[2]);
7359       i3 = immed_double_const (value & (~ (HOST_WIDE_INT) 0xffff),
7360                                         0, DImode);
7361       i4 = GEN_INT (value & 0xffff);
7362     }
7363   else
7364     {
7365       i3 = GEN_INT (INTVAL (operands[2])
7366                              & (~ (HOST_WIDE_INT) 0xffff));
7367       i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
7368     }
7369   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7370                                 operands[1], i3);
7371   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7372                                 operands[0], i4);
7373 }")
7374
7375 (define_insn "*boolcdi3_internal1"
7376   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7377         (match_operator:DI 3 "boolean_operator"
7378          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7379           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
7380   "TARGET_POWERPC64"
7381   "%q3 %0,%2,%1")
7382
7383 (define_insn "*boolcdi3_internal2"
7384   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7385         (compare:CC (match_operator:DI 4 "boolean_operator"
7386          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7387           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7388          (const_int 0)))
7389    (clobber (match_scratch:DI 3 "=r,r"))]
7390   "TARGET_64BIT"
7391   "@
7392    %q4. %3,%2,%1
7393    #"
7394   [(set_attr "type" "compare")
7395    (set_attr "length" "4,8")])
7396
7397 (define_split
7398   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7399         (compare:CC (match_operator:DI 4 "boolean_operator"
7400          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7401           (match_operand:DI 2 "gpc_reg_operand" "")])
7402          (const_int 0)))
7403    (clobber (match_scratch:DI 3 ""))]
7404   "TARGET_POWERPC64 && reload_completed"
7405   [(set (match_dup 3) (match_dup 4))
7406    (set (match_dup 0)
7407         (compare:CC (match_dup 3)
7408                     (const_int 0)))]
7409   "")
7410
7411 (define_insn "*boolcdi3_internal3"
7412   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7413         (compare:CC (match_operator:DI 4 "boolean_operator"
7414          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7415           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7416          (const_int 0)))
7417    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7418         (match_dup 4))]
7419   "TARGET_64BIT"
7420   "@
7421    %q4. %0,%2,%1
7422    #"
7423   [(set_attr "type" "compare")
7424    (set_attr "length" "4,8")])
7425
7426 (define_split
7427   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7428         (compare:CC (match_operator:DI 4 "boolean_operator"
7429          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7430           (match_operand:DI 2 "gpc_reg_operand" "")])
7431          (const_int 0)))
7432    (set (match_operand:DI 0 "gpc_reg_operand" "")
7433         (match_dup 4))]
7434   "TARGET_POWERPC64 && reload_completed"
7435   [(set (match_dup 0) (match_dup 4))
7436    (set (match_dup 3)
7437         (compare:CC (match_dup 0)
7438                     (const_int 0)))]
7439   "")
7440
7441 (define_insn "*boolccdi3_internal1"
7442   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7443         (match_operator:DI 3 "boolean_operator"
7444          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7445           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
7446   "TARGET_POWERPC64"
7447   "%q3 %0,%1,%2")
7448
7449 (define_insn "*boolccdi3_internal2"
7450   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7451         (compare:CC (match_operator:DI 4 "boolean_operator"
7452          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7453           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7454          (const_int 0)))
7455    (clobber (match_scratch:DI 3 "=r,r"))]
7456   "TARGET_64BIT"
7457   "@
7458    %q4. %3,%1,%2
7459    #"
7460   [(set_attr "type" "compare")
7461    (set_attr "length" "4,8")])
7462
7463 (define_split
7464   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7465         (compare:CC (match_operator:DI 4 "boolean_operator"
7466          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7467           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7468          (const_int 0)))
7469    (clobber (match_scratch:DI 3 ""))]
7470   "TARGET_POWERPC64 && reload_completed"
7471   [(set (match_dup 3) (match_dup 4))
7472    (set (match_dup 0)
7473         (compare:CC (match_dup 3)
7474                     (const_int 0)))]
7475   "")
7476
7477 (define_insn "*boolccdi3_internal3"
7478   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7479         (compare:CC (match_operator:DI 4 "boolean_operator"
7480          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7481           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7482          (const_int 0)))
7483    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7484         (match_dup 4))]
7485   "TARGET_64BIT"
7486   "@
7487    %q4. %0,%1,%2
7488    #"
7489   [(set_attr "type" "compare")
7490    (set_attr "length" "4,8")])
7491
7492 (define_split
7493   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7494         (compare:CC (match_operator:DI 4 "boolean_operator"
7495          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7496           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7497          (const_int 0)))
7498    (set (match_operand:DI 0 "gpc_reg_operand" "")
7499         (match_dup 4))]
7500   "TARGET_POWERPC64 && reload_completed"
7501   [(set (match_dup 0) (match_dup 4))
7502    (set (match_dup 3)
7503         (compare:CC (match_dup 0)
7504                     (const_int 0)))]
7505   "")
7506 \f
7507 ;; Now define ways of moving data around.
7508
7509 ;; Elf specific ways of loading addresses for non-PIC code.
7510 ;; The output of this could be r0, but we make a very strong
7511 ;; preference for a base register because it will usually
7512 ;; be needed there.
7513 (define_insn "elf_high"
7514   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
7515         (high:SI (match_operand 1 "" "")))]
7516   "TARGET_ELF && ! TARGET_64BIT"
7517   "{liu|lis} %0,%1@ha")
7518
7519 (define_insn "elf_low"
7520   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
7521         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
7522                    (match_operand 2 "" "")))]
7523    "TARGET_ELF && ! TARGET_64BIT"
7524    "@
7525     {cal|la} %0,%2@l(%1)
7526     {ai|addic} %0,%1,%K2")
7527
7528 ;; Mach-O PIC trickery.
7529 (define_insn "macho_high"
7530   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
7531         (high:SI (match_operand 1 "" "")))]
7532   "TARGET_MACHO && ! TARGET_64BIT"
7533   "{liu|lis} %0,ha16(%1)")
7534
7535 (define_insn "macho_low"
7536   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
7537         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
7538                    (match_operand 2 "" "")))]
7539    "TARGET_MACHO && ! TARGET_64BIT"
7540    "@
7541     {cal %0,%a2@l(%1)|la %0,lo16(%2)(%1)}
7542     {cal %0,%a2@l(%1)|addic %0,%1,lo16(%2)}")
7543
7544 ;; Set up a register with a value from the GOT table
7545
7546 (define_expand "movsi_got"
7547   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7548         (unspec:SI [(match_operand:SI 1 "got_operand" "")
7549                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
7550   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7551   "
7552 {
7553   if (GET_CODE (operands[1]) == CONST)
7554     {
7555       rtx offset = const0_rtx;
7556       HOST_WIDE_INT value;
7557
7558       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
7559       value = INTVAL (offset);
7560       if (value != 0)
7561         {
7562           rtx tmp = (no_new_pseudos ? operands[0] : gen_reg_rtx (Pmode));
7563           emit_insn (gen_movsi_got (tmp, operands[1]));
7564           emit_insn (gen_addsi3 (operands[0], tmp, offset));
7565           DONE;
7566         }
7567     }
7568
7569   operands[2] = rs6000_got_register (operands[1]);
7570 }")
7571
7572 (define_insn "*movsi_got_internal"
7573   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7574         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7575                     (match_operand:SI 2 "gpc_reg_operand" "b")]
7576                    UNSPEC_MOVSI_GOT))]
7577   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7578   "{l|lwz} %0,%a1@got(%2)"
7579   [(set_attr "type" "load")])
7580
7581 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
7582 ;; didn't get allocated to a hard register.
7583 (define_split
7584   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7585         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7586                     (match_operand:SI 2 "memory_operand" "")]
7587                    UNSPEC_MOVSI_GOT))]
7588   "DEFAULT_ABI == ABI_V4
7589     && flag_pic == 1
7590     && (reload_in_progress || reload_completed)"
7591   [(set (match_dup 0) (match_dup 2))
7592    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
7593                                  UNSPEC_MOVSI_GOT))]
7594   "")
7595
7596 ;; For SI, we special-case integers that can't be loaded in one insn.  We
7597 ;; do the load 16-bits at a time.  We could do this by loading from memory,
7598 ;; and this is even supposed to be faster, but it is simpler not to get
7599 ;; integers in the TOC.
7600 (define_expand "movsi"
7601   [(set (match_operand:SI 0 "general_operand" "")
7602         (match_operand:SI 1 "any_operand" ""))]
7603   ""
7604   "{ rs6000_emit_move (operands[0], operands[1], SImode); DONE; }")
7605
7606 (define_insn "movsi_low"
7607   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7608         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7609                            (match_operand 2 "" ""))))]
7610   "TARGET_MACHO && ! TARGET_64BIT"
7611   "{l|lwz} %0,lo16(%2)(%1)"
7612   [(set_attr "type" "load")
7613    (set_attr "length" "4")])
7614
7615 (define_insn "movsi_low_st"
7616   [(set (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7617                            (match_operand 2 "" "")))
7618         (match_operand:SI 0 "gpc_reg_operand" "r"))]
7619   "TARGET_MACHO && ! TARGET_64BIT"
7620   "{st|stw} %0,lo16(%2)(%1)"
7621   [(set_attr "type" "store")
7622    (set_attr "length" "4")])
7623
7624 (define_insn "movdf_low"
7625   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,!r")
7626         (mem:DF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
7627                            (match_operand 2 "" ""))))]
7628   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
7629   "*
7630 {
7631   switch (which_alternative)
7632     {
7633       case 0:
7634         return \"lfd %0,lo16(%2)(%1)\";
7635       case 1:
7636         {
7637           rtx operands2[4];
7638           operands2[0] = operands[0];
7639           operands2[1] = operands[1];
7640           operands2[2] = operands[2];
7641           if (TARGET_POWERPC64 && TARGET_32BIT)
7642             /* Note, old assemblers didn't support relocation here.  */
7643             return \"ld %0,lo16(%2)(%1)\";
7644           else
7645           {
7646             operands2[3] = gen_rtx_REG (SImode, RS6000_PIC_OFFSET_TABLE_REGNUM);
7647             output_asm_insn (\"{l|lwz} %0,lo16(%2)(%1)\", operands);
7648 #if TARGET_MACHO
7649             if (MACHO_DYNAMIC_NO_PIC_P)
7650               output_asm_insn (\"{liu|lis} %L0,ha16(%2+4)\", operands);
7651             else
7652             /* We cannot rely on ha16(low half)==ha16(high half), alas,
7653                although in practice it almost always is.  */
7654             output_asm_insn (\"{cau|addis} %L0,%3,ha16(%2+4)\", operands2);
7655 #endif
7656             return (\"{l|lwz} %L0,lo16(%2+4)(%L0)\");
7657           }
7658         }
7659       default:
7660         abort();
7661     }
7662 }"
7663   [(set_attr "type" "load")
7664    (set_attr "length" "4,12")])
7665
7666 (define_insn "movdf_low_st"
7667   [(set (mem:DF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7668                            (match_operand 2 "" "")))
7669         (match_operand:DF 0 "gpc_reg_operand" "f"))]
7670   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
7671   "stfd %0,lo16(%2)(%1)"
7672   [(set_attr "type" "store")
7673    (set_attr "length" "4")])
7674
7675 (define_insn "movsf_low"
7676   [(set (match_operand:SF 0 "gpc_reg_operand" "=f,!r")
7677         (mem:SF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
7678                            (match_operand 2 "" ""))))]
7679   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
7680   "@
7681    lfs %0,lo16(%2)(%1)
7682    {l|lwz} %0,lo16(%2)(%1)"
7683   [(set_attr "type" "load")
7684    (set_attr "length" "4")])
7685
7686 (define_insn "movsf_low_st"
7687   [(set (mem:SF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
7688                            (match_operand 2 "" "")))
7689         (match_operand:SF 0 "gpc_reg_operand" "f,!r"))]
7690   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
7691   "@
7692    stfs %0,lo16(%2)(%1)
7693    {st|stw} %0,lo16(%2)(%1)"
7694   [(set_attr "type" "store")
7695    (set_attr "length" "4")])
7696
7697 (define_insn "*movsi_internal1"
7698   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h")
7699         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0"))]
7700   "gpc_reg_operand (operands[0], SImode)
7701    || gpc_reg_operand (operands[1], SImode)"
7702   "@
7703    mr %0,%1
7704    {cal|la} %0,%a1
7705    {l%U1%X1|lwz%U1%X1} %0,%1
7706    {st%U0%X0|stw%U0%X0} %1,%0
7707    {lil|li} %0,%1
7708    {liu|lis} %0,%v1
7709    #
7710    {cal|la} %0,%a1
7711    mf%1 %0
7712    mt%0 %1
7713    mt%0 %1
7714    mt%0 %1
7715    {cror 0,0,0|nop}"
7716   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*")
7717    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
7718
7719 ;; Split a load of a large constant into the appropriate two-insn
7720 ;; sequence.
7721
7722 (define_split
7723   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7724         (match_operand:SI 1 "const_int_operand" ""))]
7725   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
7726    && (INTVAL (operands[1]) & 0xffff) != 0"
7727   [(set (match_dup 0)
7728         (match_dup 2))
7729    (set (match_dup 0)
7730         (ior:SI (match_dup 0)
7731                 (match_dup 3)))]
7732   "
7733 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
7734
7735   if (tem == operands[0])
7736     DONE;
7737   else
7738     FAIL;
7739 }")
7740
7741 (define_insn "*movsi_internal2"
7742   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
7743         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "0,r,r")
7744                     (const_int 0)))
7745    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
7746   "TARGET_32BIT"
7747   "@
7748    {cmpi|cmpwi} %2,%0,0
7749    mr. %0,%1
7750    #"
7751   [(set_attr "type" "cmp,compare,cmp")
7752    (set_attr "length" "4,4,8")])
7753
7754 (define_split
7755   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
7756         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
7757                     (const_int 0)))
7758    (set (match_operand:SI 0 "gpc_reg_operand" "") (match_dup 1))]
7759   "TARGET_32BIT && reload_completed"
7760   [(set (match_dup 0) (match_dup 1))
7761    (set (match_dup 2)
7762         (compare:CC (match_dup 0)
7763                     (const_int 0)))]
7764   "")
7765 \f
7766 (define_expand "movhi"
7767   [(set (match_operand:HI 0 "general_operand" "")
7768         (match_operand:HI 1 "any_operand" ""))]
7769   ""
7770   "{ rs6000_emit_move (operands[0], operands[1], HImode); DONE; }")
7771
7772 (define_insn "*movhi_internal"
7773   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7774         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7775   "gpc_reg_operand (operands[0], HImode)
7776    || gpc_reg_operand (operands[1], HImode)"
7777   "@
7778    mr %0,%1
7779    lhz%U1%X1 %0,%1
7780    sth%U0%X0 %1,%0
7781    {lil|li} %0,%w1
7782    mf%1 %0
7783    mt%0 %1
7784    mt%0 %1
7785    {cror 0,0,0|nop}"
7786   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7787
7788 (define_expand "movqi"
7789   [(set (match_operand:QI 0 "general_operand" "")
7790         (match_operand:QI 1 "any_operand" ""))]
7791   ""
7792   "{ rs6000_emit_move (operands[0], operands[1], QImode); DONE; }")
7793
7794 (define_insn "*movqi_internal"
7795   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7796         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7797   "gpc_reg_operand (operands[0], QImode)
7798    || gpc_reg_operand (operands[1], QImode)"
7799   "@
7800    mr %0,%1
7801    lbz%U1%X1 %0,%1
7802    stb%U0%X0 %1,%0
7803    {lil|li} %0,%1
7804    mf%1 %0
7805    mt%0 %1
7806    mt%0 %1
7807    {cror 0,0,0|nop}"
7808   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7809 \f
7810 ;; Here is how to move condition codes around.  When we store CC data in
7811 ;; an integer register or memory, we store just the high-order 4 bits.
7812 ;; This lets us not shift in the most common case of CR0.
7813 (define_expand "movcc"
7814   [(set (match_operand:CC 0 "nonimmediate_operand" "")
7815         (match_operand:CC 1 "nonimmediate_operand" ""))]
7816   ""
7817   "")
7818
7819 (define_insn "*movcc_internal1"
7820   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,r,r,r,r,q,cl,r,m")
7821         (match_operand:CC 1 "nonimmediate_operand" "y,r,r,x,y,r,h,r,r,m,r"))]
7822   "register_operand (operands[0], CCmode)
7823    || register_operand (operands[1], CCmode)"
7824   "@
7825    mcrf %0,%1
7826    mtcrf 128,%1
7827    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
7828    mfcr %0%Q1
7829    mfcr %0%Q1\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
7830    mr %0,%1
7831    mf%1 %0
7832    mt%0 %1
7833    mt%0 %1
7834    {l%U1%X1|lwz%U1%X1} %0,%1
7835    {st%U0%U1|stw%U0%U1} %1,%0"
7836   [(set (attr "type")
7837      (cond [(eq_attr "alternative" "0")
7838                 (const_string "cr_logical")
7839             (eq_attr "alternative" "1,2")
7840                 (const_string "mtcr")
7841             (eq_attr "alternative" "5,7")
7842                 (const_string "integer")
7843             (eq_attr "alternative" "6")
7844                 (const_string "mfjmpr")
7845             (eq_attr "alternative" "8")
7846                 (const_string "mtjmpr")
7847             (eq_attr "alternative" "9")
7848                 (const_string "load")
7849             (eq_attr "alternative" "10")
7850                 (const_string "store")
7851             (ne (symbol_ref "TARGET_MFCRF") (const_int 0))
7852                 (const_string "mfcrf")
7853            ]
7854         (const_string "mfcr")))
7855    (set_attr "length" "4,4,12,4,8,4,4,4,4,4,4")])
7856 \f
7857 ;; For floating-point, we normally deal with the floating-point registers
7858 ;; unless -msoft-float is used.  The sole exception is that parameter passing
7859 ;; can produce floating-point values in fixed-point registers.  Unless the
7860 ;; value is a simple constant or already in memory, we deal with this by
7861 ;; allocating memory and copying the value explicitly via that memory location.
7862 (define_expand "movsf"
7863   [(set (match_operand:SF 0 "nonimmediate_operand" "")
7864         (match_operand:SF 1 "any_operand" ""))]
7865   ""
7866   "{ rs6000_emit_move (operands[0], operands[1], SFmode); DONE; }")
7867
7868 (define_split
7869   [(set (match_operand:SF 0 "gpc_reg_operand" "")
7870         (match_operand:SF 1 "const_double_operand" ""))]
7871   "reload_completed
7872    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7873        || (GET_CODE (operands[0]) == SUBREG
7874            && GET_CODE (SUBREG_REG (operands[0])) == REG
7875            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7876   [(set (match_dup 2) (match_dup 3))]
7877   "
7878 {
7879   long l;
7880   REAL_VALUE_TYPE rv;
7881
7882   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7883   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
7884
7885   if (! TARGET_POWERPC64)
7886     operands[2] = operand_subword (operands[0], 0, 0, SFmode);
7887   else
7888     operands[2] = gen_lowpart (SImode, operands[0]);
7889
7890   operands[3] = gen_int_mode (l, SImode);
7891 }")
7892
7893 (define_insn "*movsf_hardfloat"
7894   [(set (match_operand:SF 0 "nonimmediate_operand" "=!r,!r,m,f,f,m,!cl,!q,!r,!h,!r,!r")
7895         (match_operand:SF 1 "input_operand" "r,m,r,f,m,f,r,r,h,0,G,Fn"))]
7896   "(gpc_reg_operand (operands[0], SFmode)
7897    || gpc_reg_operand (operands[1], SFmode))
7898    && (TARGET_HARD_FLOAT && TARGET_FPRS)"
7899   "@
7900    mr %0,%1
7901    {l%U1%X1|lwz%U1%X1} %0,%1
7902    {st%U0%X0|stw%U0%X0} %1,%0
7903    fmr %0,%1
7904    lfs%U1%X1 %0,%1
7905    stfs%U0%X0 %1,%0
7906    mt%0 %1
7907    mt%0 %1
7908    mf%1 %0
7909    {cror 0,0,0|nop}
7910    #
7911    #"
7912   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,mtjmpr,*,*,*,*")
7913    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,8")])
7914
7915 (define_insn "*movsf_softfloat"
7916   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,cl,q,r,r,m,r,r,r,r,r,*h")
7917         (match_operand:SF 1 "input_operand" "r,r,r,h,m,r,I,L,R,G,Fn,0"))]
7918   "(gpc_reg_operand (operands[0], SFmode)
7919    || gpc_reg_operand (operands[1], SFmode))
7920    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
7921   "@
7922    mr %0,%1
7923    mt%0 %1
7924    mt%0 %1
7925    mf%1 %0
7926    {l%U1%X1|lwz%U1%X1} %0,%1
7927    {st%U0%X0|stw%U0%X0} %1,%0
7928    {lil|li} %0,%1
7929    {liu|lis} %0,%v1
7930    {cal|la} %0,%a1
7931    #
7932    #
7933    {cror 0,0,0|nop}"
7934   [(set_attr "type" "*,mtjmpr,*,*,load,store,*,*,*,*,*,*")
7935    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,4")])
7936
7937 \f
7938 (define_expand "movdf"
7939   [(set (match_operand:DF 0 "nonimmediate_operand" "")
7940         (match_operand:DF 1 "any_operand" ""))]
7941   ""
7942   "{ rs6000_emit_move (operands[0], operands[1], DFmode); DONE; }")
7943
7944 (define_split
7945   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7946         (match_operand:DF 1 "const_int_operand" ""))]
7947   "! TARGET_POWERPC64 && reload_completed
7948    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7949        || (GET_CODE (operands[0]) == SUBREG
7950            && GET_CODE (SUBREG_REG (operands[0])) == REG
7951            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7952   [(set (match_dup 2) (match_dup 4))
7953    (set (match_dup 3) (match_dup 1))]
7954   "
7955 {
7956   int endian = (WORDS_BIG_ENDIAN == 0);
7957   HOST_WIDE_INT value = INTVAL (operands[1]);
7958
7959   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
7960   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
7961 #if HOST_BITS_PER_WIDE_INT == 32
7962   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
7963 #else
7964   operands[4] = GEN_INT (value >> 32);
7965   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
7966 #endif
7967 }")
7968
7969 (define_split
7970   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7971         (match_operand:DF 1 "const_double_operand" ""))]
7972   "! TARGET_POWERPC64 && reload_completed
7973    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7974        || (GET_CODE (operands[0]) == SUBREG
7975            && GET_CODE (SUBREG_REG (operands[0])) == REG
7976            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7977   [(set (match_dup 2) (match_dup 4))
7978    (set (match_dup 3) (match_dup 5))]
7979   "
7980 {
7981   int endian = (WORDS_BIG_ENDIAN == 0);
7982   long l[2];
7983   REAL_VALUE_TYPE rv;
7984
7985   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7986   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
7987
7988   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
7989   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
7990   operands[4] = gen_int_mode (l[endian], SImode);
7991   operands[5] = gen_int_mode (l[1 - endian], SImode);
7992 }")
7993
7994 (define_split
7995   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7996         (match_operand:DF 1 "easy_fp_constant" ""))]
7997   "TARGET_POWERPC64 && reload_completed
7998    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7999        || (GET_CODE (operands[0]) == SUBREG
8000            && GET_CODE (SUBREG_REG (operands[0])) == REG
8001            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8002   [(set (match_dup 2) (match_dup 3))]
8003   "
8004 {
8005   int endian = (WORDS_BIG_ENDIAN == 0);
8006   long l[2];
8007   REAL_VALUE_TYPE rv;
8008 #if HOST_BITS_PER_WIDE_INT >= 64
8009   HOST_WIDE_INT val;
8010 #endif
8011
8012   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8013   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8014
8015   operands[2] = gen_lowpart (DImode, operands[0]);
8016   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
8017 #if HOST_BITS_PER_WIDE_INT >= 64
8018   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
8019          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
8020
8021   operands[3] = gen_int_mode (val, DImode);
8022 #else
8023   operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
8024 #endif
8025 }")
8026
8027 ;; Don't have reload use general registers to load a constant.  First,
8028 ;; it might not work if the output operand is the equivalent of
8029 ;; a non-offsettable memref, but also it is less efficient than loading
8030 ;; the constant into an FP register, since it will probably be used there.
8031 ;; The "??" is a kludge until we can figure out a more reasonable way
8032 ;; of handling these non-offsettable values.
8033 (define_insn "*movdf_hardfloat32"
8034   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,m,f,f,m,!r,!r,!r")
8035         (match_operand:DF 1 "input_operand" "r,m,r,f,m,f,G,H,F"))]
8036   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8037    && (gpc_reg_operand (operands[0], DFmode)
8038        || gpc_reg_operand (operands[1], DFmode))"
8039   "*
8040 {
8041   switch (which_alternative)
8042     {
8043     default:
8044       abort ();
8045     case 0:
8046       /* We normally copy the low-numbered register first.  However, if
8047          the first register operand 0 is the same as the second register
8048          of operand 1, we must copy in the opposite order.  */
8049       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8050         return \"mr %L0,%L1\;mr %0,%1\";
8051       else
8052         return \"mr %0,%1\;mr %L0,%L1\";
8053     case 1:
8054       if (offsettable_memref_p (operands[1])
8055           || (GET_CODE (operands[1]) == MEM
8056               && (GET_CODE (XEXP (operands[1], 0)) == LO_SUM
8057                   || GET_CODE (XEXP (operands[1], 0)) == PRE_INC
8058                   || GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)))
8059         {
8060           /* If the low-address word is used in the address, we must load
8061              it last.  Otherwise, load it first.  Note that we cannot have
8062              auto-increment in that case since the address register is
8063              known to be dead.  */
8064           if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8065                                  operands[1], 0))
8066             return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8067           else
8068             return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8069         }
8070       else
8071         {
8072           rtx addreg;
8073
8074           addreg = find_addr_reg (XEXP (operands[1], 0));
8075           if (refers_to_regno_p (REGNO (operands[0]),
8076                                  REGNO (operands[0]) + 1,
8077                                  operands[1], 0))
8078             {
8079               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8080               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
8081               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8082               return \"{lx|lwzx} %0,%1\";
8083             }
8084           else
8085             {
8086               output_asm_insn (\"{lx|lwzx} %0,%1\", operands);
8087               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8088               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
8089               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8090               return \"\";
8091             }
8092         }
8093     case 2:
8094       if (offsettable_memref_p (operands[0])
8095           || (GET_CODE (operands[0]) == MEM
8096               && (GET_CODE (XEXP (operands[0], 0)) == LO_SUM
8097                   || GET_CODE (XEXP (operands[0], 0)) == PRE_INC
8098                   || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)))
8099         return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8100       else
8101         {
8102           rtx addreg;
8103
8104           addreg = find_addr_reg (XEXP (operands[0], 0));
8105           output_asm_insn (\"{stx|stwx} %1,%0\", operands);
8106           output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8107           output_asm_insn (\"{stx|stwx} %L1,%0\", operands);
8108           output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8109           return \"\";
8110         }
8111     case 3:
8112       return \"fmr %0,%1\";
8113     case 4:
8114       return \"lfd%U1%X1 %0,%1\";
8115     case 5:
8116       return \"stfd%U0%X0 %1,%0\";
8117     case 6:
8118     case 7:
8119     case 8:
8120       return \"#\";
8121     }
8122 }"
8123   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,*,*")
8124    (set_attr "length" "8,16,16,4,4,4,8,12,16")])
8125
8126 (define_insn "*movdf_softfloat32"
8127   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
8128         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F"))]
8129   "! TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8130    && (gpc_reg_operand (operands[0], DFmode)
8131        || gpc_reg_operand (operands[1], DFmode))"
8132   "*
8133 {
8134   switch (which_alternative)
8135     {
8136     default:
8137       abort ();
8138     case 0:
8139       /* We normally copy the low-numbered register first.  However, if
8140          the first register operand 0 is the same as the second register of
8141          operand 1, we must copy in the opposite order.  */
8142       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8143         return \"mr %L0,%L1\;mr %0,%1\";
8144       else
8145         return \"mr %0,%1\;mr %L0,%L1\";
8146     case 1:
8147       /* If the low-address word is used in the address, we must load
8148          it last.  Otherwise, load it first.  Note that we cannot have
8149          auto-increment in that case since the address register is
8150          known to be dead.  */
8151       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8152                              operands[1], 0))
8153         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8154       else
8155         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8156     case 2:
8157       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8158     case 3:
8159     case 4:
8160     case 5:
8161       return \"#\";
8162     }
8163 }"
8164   [(set_attr "type" "*,load,store,*,*,*")
8165    (set_attr "length" "8,8,8,8,12,16")])
8166
8167 ; ld/std require word-aligned displacements -> 'Y' constraint.
8168 ; List Y->r and r->Y before r->r for reload.
8169 (define_insn "*movdf_hardfloat64"
8170   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,!r,f,f,m,!cl,!r,!h,!r,!r,!r")
8171         (match_operand:DF 1 "input_operand" "r,Y,r,f,m,f,r,h,0,G,H,F"))]
8172   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8173    && (gpc_reg_operand (operands[0], DFmode)
8174        || gpc_reg_operand (operands[1], DFmode))"
8175   "@
8176    std%U0%X0 %1,%0
8177    ld%U1%X1 %0,%1
8178    mr %0,%1
8179    fmr %0,%1
8180    lfd%U1%X1 %0,%1
8181    stfd%U0%X0 %1,%0
8182    mt%0 %1
8183    mf%1 %0
8184    {cror 0,0,0|nop}
8185    #
8186    #
8187    #"
8188   [(set_attr "type" "*,load,store,fp,fpload,fpstore,mtjmpr,*,*,*,*,*")
8189    (set_attr "length" "4,4,4,4,4,4,4,4,4,8,12,16")])
8190
8191 (define_insn "*movdf_softfloat64"
8192   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,Y,r,cl,r,r,r,r,*h")
8193         (match_operand:DF 1 "input_operand" "Y,r,r,r,h,G,H,F,0"))]
8194   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8195    && (gpc_reg_operand (operands[0], DFmode)
8196        || gpc_reg_operand (operands[1], DFmode))"
8197   "@
8198    ld%U1%X1 %0,%1
8199    std%U0%X0 %1,%0
8200    mr %0,%1
8201    mt%0 %1
8202    mf%1 %0
8203    #
8204    #
8205    #
8206    {cror 0,0,0|nop}"
8207   [(set_attr "type" "load,store,*,*,*,*,*,*,*")
8208    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
8209 \f
8210 (define_expand "movtf"
8211   [(set (match_operand:TF 0 "general_operand" "")
8212         (match_operand:TF 1 "any_operand" ""))]
8213   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8214    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8215   "{ rs6000_emit_move (operands[0], operands[1], TFmode); DONE; }")
8216
8217 ; It's important to list the o->f and f->o moves before f->f because
8218 ; otherwise reload, given m->f, will try to pick f->f and reload it,
8219 ; which doesn't make progress.
8220 (define_insn_and_split "*movtf_internal"
8221   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,f,rm,r")
8222         (match_operand:TF 1 "input_operand"         "f,o,f,r,mGHF"))]
8223   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8224    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
8225    && (gpc_reg_operand (operands[0], TFmode)
8226        || gpc_reg_operand (operands[1], TFmode))"
8227   "#"
8228   "&& reload_completed"
8229   [(pc)]
8230 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
8231   [(set_attr "length" "8,8,8,20,20")])
8232
8233 (define_expand "extenddftf2"
8234   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
8235                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
8236               (use (match_dup 2))])]
8237   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8238    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8239 {
8240   operands[2] = CONST0_RTX (DFmode);
8241 })
8242
8243 (define_insn_and_split "*extenddftf2_internal"
8244   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,&f,r")
8245        (float_extend:TF (match_operand:DF 1 "input_operand" "fr,mf,mf,rmGHF")))
8246    (use (match_operand:DF 2 "input_operand" "rf,m,f,n"))]
8247   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8248    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8249   "#"
8250   "&& reload_completed"
8251   [(pc)]
8252 {
8253   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8254   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8255   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
8256                   operands[1]);
8257   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
8258                   operands[2]);
8259   DONE;
8260 })
8261
8262 (define_expand "extendsftf2"
8263   [(set (match_operand:TF 0 "nonimmediate_operand" "")
8264         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
8265   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8266    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8267 {
8268   rtx tmp = gen_reg_rtx (DFmode);
8269   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
8270   emit_insn (gen_extenddftf2 (operands[0], tmp));
8271   DONE;
8272 })
8273
8274 (define_insn "trunctfdf2"
8275   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8276         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8277   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8278    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8279   "fadd %0,%1,%L1"
8280   [(set_attr "type" "fp")
8281    (set_attr "length" "4")])
8282
8283 (define_insn_and_split "trunctfsf2"
8284   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
8285         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "f")))
8286    (clobber (match_scratch:DF 2 "=f"))]
8287   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8288    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8289   "#"
8290   "&& reload_completed"
8291   [(set (match_dup 2)
8292         (float_truncate:DF (match_dup 1)))
8293    (set (match_dup 0)
8294         (float_truncate:SF (match_dup 2)))]
8295   "")
8296
8297 (define_expand "floatsitf2"
8298   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8299         (float:TF (match_operand:SI 1 "gpc_reg_operand" "r")))]
8300   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8301    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8302 {
8303   rtx tmp = gen_reg_rtx (DFmode);
8304   expand_float (tmp, operands[1], false);
8305   emit_insn (gen_extenddftf2 (operands[0], tmp));
8306   DONE;
8307 })
8308
8309 ; fadd, but rounding towards zero.
8310 ; This is probably not the optimal code sequence.
8311 (define_insn "fix_trunc_helper"
8312   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8313         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "f")]
8314                    UNSPEC_FIX_TRUNC_TF))
8315    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&f"))]
8316   "TARGET_HARD_FLOAT && TARGET_FPRS"
8317   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
8318   [(set_attr "type" "fp")
8319    (set_attr "length" "20")])
8320
8321 (define_expand "fix_trunctfsi2"
8322   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
8323                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
8324               (clobber (match_dup 2))
8325               (clobber (match_dup 3))
8326               (clobber (match_dup 4))
8327               (clobber (match_dup 5))])]
8328   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8329    && (TARGET_POWER2 || TARGET_POWERPC)
8330    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8331 {
8332   operands[2] = gen_reg_rtx (DFmode);
8333   operands[3] = gen_reg_rtx (DFmode);
8334   operands[4] = gen_reg_rtx (DImode);
8335   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
8336 })
8337
8338 (define_insn_and_split "*fix_trunctfsi2_internal"
8339   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8340         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "f")))
8341    (clobber (match_operand:DF 2 "gpc_reg_operand" "=f"))
8342    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&f"))
8343    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))
8344    (clobber (match_operand:DI 5 "memory_operand" "=o"))]
8345   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8346    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8347   "#"
8348   "&& reload_completed"
8349   [(pc)]
8350 {
8351   rtx lowword;
8352   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
8353
8354   if (GET_CODE (operands[5]) != MEM)
8355     abort();
8356   lowword = XEXP (operands[5], 0);
8357   if (WORDS_BIG_ENDIAN)
8358     lowword = plus_constant (lowword, 4);
8359
8360   emit_insn (gen_fctiwz (operands[4], operands[2]));
8361   emit_move_insn (operands[5], operands[4]);
8362   emit_move_insn (operands[0], gen_rtx_MEM (SImode, lowword));
8363   DONE;
8364 })
8365
8366 (define_insn "negtf2"
8367   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8368         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8369   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8370    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8371   "*
8372 {
8373   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8374     return \"fneg %L0,%L1\;fneg %0,%1\";
8375   else
8376     return \"fneg %0,%1\;fneg %L0,%L1\";
8377 }"
8378   [(set_attr "type" "fp")
8379    (set_attr "length" "8")])
8380
8381 (define_expand "abstf2"
8382   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8383         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8384   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8385    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8386   "
8387 {
8388   rtx label = gen_label_rtx ();
8389   emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
8390   emit_label (label);
8391   DONE;
8392 }")
8393
8394 (define_expand "abstf2_internal"
8395   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8396         (match_operand:TF 1 "gpc_reg_operand" "f"))
8397    (set (match_dup 3) (match_dup 5))
8398    (set (match_dup 5) (abs:DF (match_dup 5)))
8399    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
8400    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
8401                            (label_ref (match_operand 2 "" ""))
8402                            (pc)))
8403    (set (match_dup 6) (neg:DF (match_dup 6)))]
8404   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8405    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8406   "
8407 {
8408   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8409   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8410   operands[3] = gen_reg_rtx (DFmode);
8411   operands[4] = gen_reg_rtx (CCFPmode);
8412   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
8413   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
8414 }")
8415 \f
8416 ;; Next come the multi-word integer load and store and the load and store
8417 ;; multiple insns.
8418 (define_expand "movdi"
8419   [(set (match_operand:DI 0 "general_operand" "")
8420         (match_operand:DI 1 "any_operand" ""))]
8421   ""
8422   "{ rs6000_emit_move (operands[0], operands[1], DImode); DONE; }")
8423
8424 (define_insn "*movdi_internal32"
8425   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,f,f,m,r,r,r,r,r")
8426         (match_operand:DI 1 "input_operand" "r,m,r,f,m,f,IJK,n,G,H,F"))]
8427   "! TARGET_POWERPC64
8428    && (gpc_reg_operand (operands[0], DImode)
8429        || gpc_reg_operand (operands[1], DImode))"
8430   "*
8431 {
8432   switch (which_alternative)
8433     {
8434     default:
8435       abort ();
8436     case 0:
8437     case 1:
8438     case 2:
8439       return \"#\";
8440     case 3:
8441       return \"fmr %0,%1\";
8442     case 4:
8443       return \"lfd%U1%X1 %0,%1\";
8444     case 5:
8445       return \"stfd%U0%X0 %1,%0\";
8446     case 6:
8447     case 7:
8448     case 8:
8449     case 9:
8450     case 10:
8451       return \"#\";
8452     }
8453 }"
8454   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,*,*,*,*")])
8455
8456 (define_split
8457   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8458         (match_operand:DI 1 "const_int_operand" ""))]
8459   "! TARGET_POWERPC64 && reload_completed"
8460   [(set (match_dup 2) (match_dup 4))
8461    (set (match_dup 3) (match_dup 1))]
8462   "
8463 {
8464   HOST_WIDE_INT value = INTVAL (operands[1]);
8465   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8466                                        DImode);
8467   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8468                                        DImode);
8469 #if HOST_BITS_PER_WIDE_INT == 32
8470   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8471 #else
8472   operands[4] = GEN_INT (value >> 32);
8473   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8474 #endif
8475 }")
8476
8477 (define_split
8478   [(set (match_operand:DI 0 "nonimmediate_operand" "")
8479         (match_operand:DI 1 "input_operand" ""))]
8480   "reload_completed && !TARGET_POWERPC64
8481    && gpr_or_gpr_p (operands[0], operands[1])"
8482   [(pc)]
8483 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8484
8485 (define_split
8486   [(set (match_operand:TI 0 "gpc_reg_operand" "")
8487         (match_operand:TI 1 "const_double_operand" ""))]
8488   "TARGET_POWERPC64"
8489   [(set (match_dup 2) (match_dup 4))
8490    (set (match_dup 3) (match_dup 5))]
8491   "
8492 {
8493   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8494                                        TImode);
8495   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8496                                        TImode);
8497   if (GET_CODE (operands[1]) == CONST_DOUBLE)
8498     {
8499       operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
8500       operands[5] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
8501     }
8502   else if (GET_CODE (operands[1]) == CONST_INT)
8503     {
8504       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
8505       operands[5] = operands[1];
8506     }
8507   else
8508     FAIL;
8509 }")
8510
8511 (define_insn "*movdi_internal64"
8512   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,?f,f,m,r,*h,*h")
8513         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,f,m,f,*h,r,0"))]
8514   "TARGET_POWERPC64
8515    && (gpc_reg_operand (operands[0], DImode)
8516        || gpc_reg_operand (operands[1], DImode))"
8517   "@
8518    mr %0,%1
8519    ld%U1%X1 %0,%1
8520    std%U0%X0 %1,%0
8521    li %0,%1
8522    lis %0,%v1
8523    #
8524    {cal|la} %0,%a1
8525    fmr %0,%1
8526    lfd%U1%X1 %0,%1
8527    stfd%U0%X0 %1,%0
8528    mf%1 %0
8529    mt%0 %1
8530    {cror 0,0,0|nop}"
8531   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*")
8532    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4")])
8533
8534 ;; immediate value valid for a single instruction hiding in a const_double
8535 (define_insn ""
8536   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8537         (match_operand:DI 1 "const_double_operand" "F"))]
8538   "HOST_BITS_PER_WIDE_INT == 32 && TARGET_POWERPC64
8539    && GET_CODE (operands[1]) == CONST_DOUBLE
8540    && num_insns_constant (operands[1], DImode) == 1"
8541   "*
8542 {
8543   return ((unsigned HOST_WIDE_INT)
8544           (CONST_DOUBLE_LOW (operands[1]) + 0x8000) < 0x10000)
8545          ? \"li %0,%1\" : \"lis %0,%v1\";
8546 }")
8547
8548 ;; Generate all one-bits and clear left or right.
8549 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
8550 (define_split
8551   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8552         (match_operand:DI 1 "mask64_operand" ""))]
8553   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8554   [(set (match_dup 0) (const_int -1))
8555    (set (match_dup 0)
8556         (and:DI (rotate:DI (match_dup 0)
8557                            (const_int 0))
8558                 (match_dup 1)))]
8559   "")
8560
8561 ;; Split a load of a large constant into the appropriate five-instruction
8562 ;; sequence.  Handle anything in a constant number of insns.
8563 ;; When non-easy constants can go in the TOC, this should use
8564 ;; easy_fp_constant predicate.
8565 (define_split
8566   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8567         (match_operand:DI 1 "const_int_operand" ""))]
8568   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8569   [(set (match_dup 0) (match_dup 2))
8570    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8571   "
8572 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8573
8574   if (tem == operands[0])
8575     DONE;
8576   else
8577     FAIL;
8578 }")
8579
8580 (define_split
8581   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8582         (match_operand:DI 1 "const_double_operand" ""))]
8583   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8584   [(set (match_dup 0) (match_dup 2))
8585    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8586   "
8587 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8588
8589   if (tem == operands[0])
8590     DONE;
8591   else
8592     FAIL;
8593 }")
8594
8595 (define_insn "*movdi_internal2"
8596   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
8597         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "0,r,r")
8598                     (const_int 0)))
8599    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
8600   "TARGET_64BIT"
8601   "@
8602    cmpdi %2,%0,0
8603    mr. %0,%1
8604    #"
8605   [(set_attr "type" "cmp,compare,cmp")
8606    (set_attr "length" "4,4,8")])
8607
8608 (define_split
8609   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
8610         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "")
8611                     (const_int 0)))
8612    (set (match_operand:DI 0 "gpc_reg_operand" "") (match_dup 1))]
8613   "TARGET_POWERPC64 && reload_completed"
8614   [(set (match_dup 0) (match_dup 1))
8615    (set (match_dup 2)
8616         (compare:CC (match_dup 0)
8617                     (const_int 0)))]
8618   "")
8619 \f
8620 ;; TImode is similar, except that we usually want to compute the address into
8621 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
8622 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
8623 (define_expand "movti"
8624   [(parallel [(set (match_operand:TI 0 "general_operand" "")
8625                    (match_operand:TI 1 "general_operand" ""))
8626               (clobber (scratch:SI))])]
8627   ""
8628   "{ rs6000_emit_move (operands[0], operands[1], TImode); DONE; }")
8629
8630 ;; We say that MQ is clobbered in the last alternative because the first
8631 ;; alternative would never get used otherwise since it would need a reload
8632 ;; while the 2nd alternative would not.  We put memory cases first so they
8633 ;; are preferred.  Otherwise, we'd try to reload the output instead of
8634 ;; giving the SCRATCH mq.
8635
8636 (define_insn "*movti_power"
8637   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r")
8638         (match_operand:TI 1 "reg_or_mem_operand" "r,r,r,Q,m"))
8639    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X"))]
8640   "TARGET_POWER && ! TARGET_POWERPC64
8641    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8642   "*
8643 {
8644   switch (which_alternative)
8645     {
8646     default:
8647       abort ();
8648
8649     case 0:
8650       if (TARGET_STRING)
8651         return \"{stsi|stswi} %1,%P0,16\";
8652     case 1:
8653     case 2:
8654       return \"#\";
8655     case 3:
8656       /* If the address is not used in the output, we can use lsi.  Otherwise,
8657          fall through to generating four loads.  */
8658       if (TARGET_STRING
8659           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8660         return \"{lsi|lswi} %0,%P1,16\";
8661       /* ... fall through ...  */
8662     case 4:
8663       return \"#\";
8664     }
8665 }"
8666   [(set_attr "type" "store,store,*,load,load")])
8667
8668 (define_insn "*movti_string"
8669   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r")
8670         (match_operand:TI 1 "reg_or_mem_operand" "r,r,r,Q,m"))]
8671   "! TARGET_POWER && ! TARGET_POWERPC64
8672    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8673   "*
8674 {
8675   switch (which_alternative)
8676     {
8677     default:
8678       abort ();
8679     case 0:
8680       if (TARGET_STRING)
8681         return \"{stsi|stswi} %1,%P0,16\";
8682     case 1:
8683     case 2:
8684       return \"#\";
8685     case 3:
8686       /* If the address is not used in the output, we can use lsi.  Otherwise,
8687          fall through to generating four loads.  */
8688       if (TARGET_STRING
8689           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8690         return \"{lsi|lswi} %0,%P1,16\";
8691       /* ... fall through ...  */
8692     case 4:
8693       return \"#\";
8694     }
8695 }"
8696   [(set_attr "type" "store,store,*,load,load")])
8697
8698 (define_insn "*movti_ppc64"
8699   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,m,r")
8700         (match_operand:TI 1 "input_operand" "r,r,o"))]
8701   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
8702    || gpc_reg_operand (operands[1], TImode))"
8703   "@
8704    #
8705    #
8706    #"
8707   [(set_attr "type" "*,load,store")])
8708
8709 (define_split
8710   [(set (match_operand:TI 0 "nonimmediate_operand" "")
8711         (match_operand:TI 1 "input_operand" ""))]
8712   "reload_completed
8713    && gpr_or_gpr_p (operands[0], operands[1])"
8714   [(pc)]
8715 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8716 \f
8717 (define_expand "load_multiple"
8718   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8719                           (match_operand:SI 1 "" ""))
8720                      (use (match_operand:SI 2 "" ""))])]
8721   "TARGET_STRING && !TARGET_POWERPC64"
8722   "
8723 {
8724   int regno;
8725   int count;
8726   rtx op1;
8727   int i;
8728
8729   /* Support only loading a constant number of fixed-point registers from
8730      memory and only bother with this if more than two; the machine
8731      doesn't support more than eight.  */
8732   if (GET_CODE (operands[2]) != CONST_INT
8733       || INTVAL (operands[2]) <= 2
8734       || INTVAL (operands[2]) > 8
8735       || GET_CODE (operands[1]) != MEM
8736       || GET_CODE (operands[0]) != REG
8737       || REGNO (operands[0]) >= 32)
8738     FAIL;
8739
8740   count = INTVAL (operands[2]);
8741   regno = REGNO (operands[0]);
8742
8743   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
8744   op1 = replace_equiv_address (operands[1],
8745                                force_reg (SImode, XEXP (operands[1], 0)));
8746
8747   for (i = 0; i < count; i++)
8748     XVECEXP (operands[3], 0, i)
8749       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
8750                      adjust_address_nv (op1, SImode, i * 4));
8751 }")
8752
8753 (define_insn "*ldmsi8"
8754   [(match_parallel 0 "load_multiple_operation"
8755     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8756           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8757      (set (match_operand:SI 3 "gpc_reg_operand" "")
8758           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8759      (set (match_operand:SI 4 "gpc_reg_operand" "")
8760           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8761      (set (match_operand:SI 5 "gpc_reg_operand" "")
8762           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8763      (set (match_operand:SI 6 "gpc_reg_operand" "")
8764           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8765      (set (match_operand:SI 7 "gpc_reg_operand" "")
8766           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8767      (set (match_operand:SI 8 "gpc_reg_operand" "")
8768           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
8769      (set (match_operand:SI 9 "gpc_reg_operand" "")
8770           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
8771   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
8772   "*
8773 { return rs6000_output_load_multiple (operands); }"
8774   [(set_attr "type" "load")
8775    (set_attr "length" "32")])
8776
8777 (define_insn "*ldmsi7"
8778   [(match_parallel 0 "load_multiple_operation"
8779     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8780           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8781      (set (match_operand:SI 3 "gpc_reg_operand" "")
8782           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8783      (set (match_operand:SI 4 "gpc_reg_operand" "")
8784           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8785      (set (match_operand:SI 5 "gpc_reg_operand" "")
8786           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8787      (set (match_operand:SI 6 "gpc_reg_operand" "")
8788           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8789      (set (match_operand:SI 7 "gpc_reg_operand" "")
8790           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8791      (set (match_operand:SI 8 "gpc_reg_operand" "")
8792           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
8793   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
8794   "*
8795 { return rs6000_output_load_multiple (operands); }"
8796   [(set_attr "type" "load")
8797    (set_attr "length" "32")])
8798
8799 (define_insn "*ldmsi6"
8800   [(match_parallel 0 "load_multiple_operation"
8801     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8802           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8803      (set (match_operand:SI 3 "gpc_reg_operand" "")
8804           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8805      (set (match_operand:SI 4 "gpc_reg_operand" "")
8806           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8807      (set (match_operand:SI 5 "gpc_reg_operand" "")
8808           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8809      (set (match_operand:SI 6 "gpc_reg_operand" "")
8810           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8811      (set (match_operand:SI 7 "gpc_reg_operand" "")
8812           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
8813   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
8814   "*
8815 { return rs6000_output_load_multiple (operands); }"
8816   [(set_attr "type" "load")
8817    (set_attr "length" "32")])
8818
8819 (define_insn "*ldmsi5"
8820   [(match_parallel 0 "load_multiple_operation"
8821     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8822           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8823      (set (match_operand:SI 3 "gpc_reg_operand" "")
8824           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8825      (set (match_operand:SI 4 "gpc_reg_operand" "")
8826           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8827      (set (match_operand:SI 5 "gpc_reg_operand" "")
8828           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8829      (set (match_operand:SI 6 "gpc_reg_operand" "")
8830           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
8831   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
8832   "*
8833 { return rs6000_output_load_multiple (operands); }"
8834   [(set_attr "type" "load")
8835    (set_attr "length" "32")])
8836
8837 (define_insn "*ldmsi4"
8838   [(match_parallel 0 "load_multiple_operation"
8839     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8840           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8841      (set (match_operand:SI 3 "gpc_reg_operand" "")
8842           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8843      (set (match_operand:SI 4 "gpc_reg_operand" "")
8844           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8845      (set (match_operand:SI 5 "gpc_reg_operand" "")
8846           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
8847   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
8848   "*
8849 { return rs6000_output_load_multiple (operands); }"
8850   [(set_attr "type" "load")
8851    (set_attr "length" "32")])
8852
8853 (define_insn "*ldmsi3"
8854   [(match_parallel 0 "load_multiple_operation"
8855     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8856           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8857      (set (match_operand:SI 3 "gpc_reg_operand" "")
8858           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8859      (set (match_operand:SI 4 "gpc_reg_operand" "")
8860           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
8861   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
8862   "*
8863 { return rs6000_output_load_multiple (operands); }"
8864   [(set_attr "type" "load")
8865    (set_attr "length" "32")])
8866
8867 (define_expand "store_multiple"
8868   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8869                           (match_operand:SI 1 "" ""))
8870                      (clobber (scratch:SI))
8871                      (use (match_operand:SI 2 "" ""))])]
8872   "TARGET_STRING && !TARGET_POWERPC64"
8873   "
8874 {
8875   int regno;
8876   int count;
8877   rtx to;
8878   rtx op0;
8879   int i;
8880
8881   /* Support only storing a constant number of fixed-point registers to
8882      memory and only bother with this if more than two; the machine
8883      doesn't support more than eight.  */
8884   if (GET_CODE (operands[2]) != CONST_INT
8885       || INTVAL (operands[2]) <= 2
8886       || INTVAL (operands[2]) > 8
8887       || GET_CODE (operands[0]) != MEM
8888       || GET_CODE (operands[1]) != REG
8889       || REGNO (operands[1]) >= 32)
8890     FAIL;
8891
8892   count = INTVAL (operands[2]);
8893   regno = REGNO (operands[1]);
8894
8895   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
8896   to = force_reg (SImode, XEXP (operands[0], 0));
8897   op0 = replace_equiv_address (operands[0], to);
8898
8899   XVECEXP (operands[3], 0, 0)
8900     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
8901   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
8902                                                  gen_rtx_SCRATCH (SImode));
8903
8904   for (i = 1; i < count; i++)
8905     XVECEXP (operands[3], 0, i + 1)
8906       = gen_rtx_SET (VOIDmode,
8907                      adjust_address_nv (op0, SImode, i * 4),
8908                      gen_rtx_REG (SImode, regno + i));
8909 }")
8910
8911 (define_insn "*store_multiple_power"
8912   [(match_parallel 0 "store_multiple_operation"
8913                    [(set (match_operand:SI 1 "indirect_operand" "=Q")
8914                          (match_operand:SI 2 "gpc_reg_operand" "r"))
8915                     (clobber (match_scratch:SI 3 "=q"))])]
8916   "TARGET_STRING && TARGET_POWER"
8917   "{stsi|stswi} %2,%P1,%O0"
8918   [(set_attr "type" "store")])
8919
8920 (define_insn "*stmsi8"
8921   [(match_parallel 0 "store_multiple_operation"
8922     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8923           (match_operand:SI 2 "gpc_reg_operand" "r"))
8924      (clobber (match_scratch:SI 3 "X"))
8925      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8926           (match_operand:SI 4 "gpc_reg_operand" "r"))
8927      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8928           (match_operand:SI 5 "gpc_reg_operand" "r"))
8929      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8930           (match_operand:SI 6 "gpc_reg_operand" "r"))
8931      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8932           (match_operand:SI 7 "gpc_reg_operand" "r"))
8933      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8934           (match_operand:SI 8 "gpc_reg_operand" "r"))
8935      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
8936           (match_operand:SI 9 "gpc_reg_operand" "r"))
8937      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
8938           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
8939   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 9"
8940   "{stsi|stswi} %2,%1,%O0"
8941   [(set_attr "type" "store")])
8942
8943 (define_insn "*stmsi7"
8944   [(match_parallel 0 "store_multiple_operation"
8945     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8946           (match_operand:SI 2 "gpc_reg_operand" "r"))
8947      (clobber (match_scratch:SI 3 "X"))
8948      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8949           (match_operand:SI 4 "gpc_reg_operand" "r"))
8950      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8951           (match_operand:SI 5 "gpc_reg_operand" "r"))
8952      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8953           (match_operand:SI 6 "gpc_reg_operand" "r"))
8954      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8955           (match_operand:SI 7 "gpc_reg_operand" "r"))
8956      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8957           (match_operand:SI 8 "gpc_reg_operand" "r"))
8958      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
8959           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
8960   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 8"
8961   "{stsi|stswi} %2,%1,%O0"
8962   [(set_attr "type" "store")])
8963
8964 (define_insn "*stmsi6"
8965   [(match_parallel 0 "store_multiple_operation"
8966     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8967           (match_operand:SI 2 "gpc_reg_operand" "r"))
8968      (clobber (match_scratch:SI 3 "X"))
8969      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8970           (match_operand:SI 4 "gpc_reg_operand" "r"))
8971      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8972           (match_operand:SI 5 "gpc_reg_operand" "r"))
8973      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8974           (match_operand:SI 6 "gpc_reg_operand" "r"))
8975      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8976           (match_operand:SI 7 "gpc_reg_operand" "r"))
8977      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8978           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
8979   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 7"
8980   "{stsi|stswi} %2,%1,%O0"
8981   [(set_attr "type" "store")])
8982
8983 (define_insn "*stmsi5"
8984   [(match_parallel 0 "store_multiple_operation"
8985     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8986           (match_operand:SI 2 "gpc_reg_operand" "r"))
8987      (clobber (match_scratch:SI 3 "X"))
8988      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8989           (match_operand:SI 4 "gpc_reg_operand" "r"))
8990      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8991           (match_operand:SI 5 "gpc_reg_operand" "r"))
8992      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8993           (match_operand:SI 6 "gpc_reg_operand" "r"))
8994      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8995           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
8996   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 6"
8997   "{stsi|stswi} %2,%1,%O0"
8998   [(set_attr "type" "store")])
8999
9000 (define_insn "*stmsi4"
9001   [(match_parallel 0 "store_multiple_operation"
9002     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9003           (match_operand:SI 2 "gpc_reg_operand" "r"))
9004      (clobber (match_scratch:SI 3 "X"))
9005      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9006           (match_operand:SI 4 "gpc_reg_operand" "r"))
9007      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9008           (match_operand:SI 5 "gpc_reg_operand" "r"))
9009      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9010           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
9011   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 5"
9012   "{stsi|stswi} %2,%1,%O0"
9013   [(set_attr "type" "store")])
9014
9015 (define_insn "*stmsi3"
9016   [(match_parallel 0 "store_multiple_operation"
9017     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9018           (match_operand:SI 2 "gpc_reg_operand" "r"))
9019      (clobber (match_scratch:SI 3 "X"))
9020      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9021           (match_operand:SI 4 "gpc_reg_operand" "r"))
9022      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9023           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
9024   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 4"
9025   "{stsi|stswi} %2,%1,%O0"
9026   [(set_attr "type" "store")])
9027 \f
9028 ;; String/block move insn.
9029 ;; Argument 0 is the destination
9030 ;; Argument 1 is the source
9031 ;; Argument 2 is the length
9032 ;; Argument 3 is the alignment
9033
9034 (define_expand "movstrsi"
9035   [(parallel [(set (match_operand:BLK 0 "" "")
9036                    (match_operand:BLK 1 "" ""))
9037               (use (match_operand:SI 2 "" ""))
9038               (use (match_operand:SI 3 "" ""))])]
9039   ""
9040   "
9041 {
9042   if (expand_block_move (operands))
9043     DONE;
9044   else
9045     FAIL;
9046 }")
9047
9048 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
9049 ;; register allocator doesn't have a clue about allocating 8 word registers.
9050 ;; rD/rS = r5 is preferred, efficient form.
9051 (define_expand "movstrsi_8reg"
9052   [(parallel [(set (match_operand 0 "" "")
9053                    (match_operand 1 "" ""))
9054               (use (match_operand 2 "" ""))
9055               (use (match_operand 3 "" ""))
9056               (clobber (reg:SI  5))
9057               (clobber (reg:SI  6))
9058               (clobber (reg:SI  7))
9059               (clobber (reg:SI  8))
9060               (clobber (reg:SI  9))
9061               (clobber (reg:SI 10))
9062               (clobber (reg:SI 11))
9063               (clobber (reg:SI 12))
9064               (clobber (match_scratch:SI 4 ""))])]
9065   "TARGET_STRING"
9066   "")
9067
9068 (define_insn ""
9069   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9070         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9071    (use (match_operand:SI 2 "immediate_operand" "i"))
9072    (use (match_operand:SI 3 "immediate_operand" "i"))
9073    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9074    (clobber (reg:SI  6))
9075    (clobber (reg:SI  7))
9076    (clobber (reg:SI  8))
9077    (clobber (reg:SI  9))
9078    (clobber (reg:SI 10))
9079    (clobber (reg:SI 11))
9080    (clobber (reg:SI 12))
9081    (clobber (match_scratch:SI 5 "=q"))]
9082   "TARGET_STRING && TARGET_POWER
9083    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9084        || INTVAL (operands[2]) == 0)
9085    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9086    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9087    && REGNO (operands[4]) == 5"
9088   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9089   [(set_attr "type" "load")
9090    (set_attr "length" "8")])
9091
9092 (define_insn ""
9093   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9094         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9095    (use (match_operand:SI 2 "immediate_operand" "i"))
9096    (use (match_operand:SI 3 "immediate_operand" "i"))
9097    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9098    (clobber (reg:SI  6))
9099    (clobber (reg:SI  7))
9100    (clobber (reg:SI  8))
9101    (clobber (reg:SI  9))
9102    (clobber (reg:SI 10))
9103    (clobber (reg:SI 11))
9104    (clobber (reg:SI 12))
9105    (clobber (match_scratch:SI 5 "X"))]
9106   "TARGET_STRING && ! TARGET_POWER
9107    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9108        || INTVAL (operands[2]) == 0)
9109    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9110    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9111    && REGNO (operands[4]) == 5"
9112   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9113   [(set_attr "type" "load")
9114    (set_attr "length" "8")])
9115
9116 (define_insn ""
9117   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9118         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9119    (use (match_operand:SI 2 "immediate_operand" "i"))
9120    (use (match_operand:SI 3 "immediate_operand" "i"))
9121    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9122    (clobber (reg:SI  6))
9123    (clobber (reg:SI  7))
9124    (clobber (reg:SI  8))
9125    (clobber (reg:SI  9))
9126    (clobber (reg:SI 10))
9127    (clobber (reg:SI 11))
9128    (clobber (reg:SI 12))
9129    (clobber (match_scratch:SI 5 "X"))]
9130   "TARGET_STRING && TARGET_POWERPC64
9131    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9132        || INTVAL (operands[2]) == 0)
9133    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9134    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9135    && REGNO (operands[4]) == 5"
9136   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9137   [(set_attr "type" "load")
9138    (set_attr "length" "8")])
9139
9140 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
9141 ;; register allocator doesn't have a clue about allocating 6 word registers.
9142 ;; rD/rS = r5 is preferred, efficient form.
9143 (define_expand "movstrsi_6reg"
9144   [(parallel [(set (match_operand 0 "" "")
9145                    (match_operand 1 "" ""))
9146               (use (match_operand 2 "" ""))
9147               (use (match_operand 3 "" ""))
9148               (clobber (reg:SI  5))
9149               (clobber (reg:SI  6))
9150               (clobber (reg:SI  7))
9151               (clobber (reg:SI  8))
9152               (clobber (reg:SI  9))
9153               (clobber (reg:SI 10))
9154               (clobber (match_scratch:SI 4 ""))])]
9155   "TARGET_STRING"
9156   "")
9157
9158 (define_insn ""
9159   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9160         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9161    (use (match_operand:SI 2 "immediate_operand" "i"))
9162    (use (match_operand:SI 3 "immediate_operand" "i"))
9163    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9164    (clobber (reg:SI  6))
9165    (clobber (reg:SI  7))
9166    (clobber (reg:SI  8))
9167    (clobber (reg:SI  9))
9168    (clobber (reg:SI 10))
9169    (clobber (match_scratch:SI 5 "=q"))]
9170   "TARGET_STRING && TARGET_POWER
9171    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
9172    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9173    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
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 (define_insn ""
9180   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9181         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9182    (use (match_operand:SI 2 "immediate_operand" "i"))
9183    (use (match_operand:SI 3 "immediate_operand" "i"))
9184    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9185    (clobber (reg:SI  6))
9186    (clobber (reg:SI  7))
9187    (clobber (reg:SI  8))
9188    (clobber (reg:SI  9))
9189    (clobber (reg:SI 10))
9190    (clobber (match_scratch:SI 5 "X"))]
9191   "TARGET_STRING && ! TARGET_POWER
9192    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9193    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9194    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9195    && REGNO (operands[4]) == 5"
9196   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9197   [(set_attr "type" "load")
9198    (set_attr "length" "8")])
9199
9200 (define_insn ""
9201   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9202         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9203    (use (match_operand:SI 2 "immediate_operand" "i"))
9204    (use (match_operand:SI 3 "immediate_operand" "i"))
9205    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9206    (clobber (reg:SI  6))
9207    (clobber (reg:SI  7))
9208    (clobber (reg:SI  8))
9209    (clobber (reg:SI  9))
9210    (clobber (reg:SI 10))
9211    (clobber (match_scratch:SI 5 "X"))]
9212   "TARGET_STRING && TARGET_POWERPC64
9213    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9214    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9215    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9216    && REGNO (operands[4]) == 5"
9217   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9218   [(set_attr "type" "load")
9219    (set_attr "length" "8")])
9220
9221 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
9222 ;; problems with TImode.
9223 ;; rD/rS = r5 is preferred, efficient form.
9224 (define_expand "movstrsi_4reg"
9225   [(parallel [(set (match_operand 0 "" "")
9226                    (match_operand 1 "" ""))
9227               (use (match_operand 2 "" ""))
9228               (use (match_operand 3 "" ""))
9229               (clobber (reg:SI 5))
9230               (clobber (reg:SI 6))
9231               (clobber (reg:SI 7))
9232               (clobber (reg:SI 8))
9233               (clobber (match_scratch:SI 4 ""))])]
9234   "TARGET_STRING"
9235   "")
9236
9237 (define_insn ""
9238   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9239         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9240    (use (match_operand:SI 2 "immediate_operand" "i"))
9241    (use (match_operand:SI 3 "immediate_operand" "i"))
9242    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9243    (clobber (reg:SI 6))
9244    (clobber (reg:SI 7))
9245    (clobber (reg:SI 8))
9246    (clobber (match_scratch:SI 5 "=q"))]
9247   "TARGET_STRING && TARGET_POWER
9248    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9249    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9250    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9251    && REGNO (operands[4]) == 5"
9252   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9253   [(set_attr "type" "load")
9254    (set_attr "length" "8")])
9255
9256 (define_insn ""
9257   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9258         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9259    (use (match_operand:SI 2 "immediate_operand" "i"))
9260    (use (match_operand:SI 3 "immediate_operand" "i"))
9261    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9262    (clobber (reg:SI 6))
9263    (clobber (reg:SI 7))
9264    (clobber (reg:SI 8))
9265    (clobber (match_scratch:SI 5 "X"))]
9266   "TARGET_STRING && ! TARGET_POWER
9267    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9268    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9269    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9270    && REGNO (operands[4]) == 5"
9271   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9272   [(set_attr "type" "load")
9273    (set_attr "length" "8")])
9274
9275 (define_insn ""
9276   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9277         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9278    (use (match_operand:SI 2 "immediate_operand" "i"))
9279    (use (match_operand:SI 3 "immediate_operand" "i"))
9280    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9281    (clobber (reg:SI 6))
9282    (clobber (reg:SI 7))
9283    (clobber (reg:SI 8))
9284    (clobber (match_scratch:SI 5 "X"))]
9285   "TARGET_STRING && TARGET_POWERPC64
9286    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9287    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9288    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9289    && REGNO (operands[4]) == 5"
9290   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9291   [(set_attr "type" "load")
9292    (set_attr "length" "8")])
9293
9294 ;; Move up to 8 bytes at a time.
9295 (define_expand "movstrsi_2reg"
9296   [(parallel [(set (match_operand 0 "" "")
9297                    (match_operand 1 "" ""))
9298               (use (match_operand 2 "" ""))
9299               (use (match_operand 3 "" ""))
9300               (clobber (match_scratch:DI 4 ""))
9301               (clobber (match_scratch:SI 5 ""))])]
9302   "TARGET_STRING && ! TARGET_POWERPC64"
9303   "")
9304
9305 (define_insn ""
9306   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9307         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9308    (use (match_operand:SI 2 "immediate_operand" "i"))
9309    (use (match_operand:SI 3 "immediate_operand" "i"))
9310    (clobber (match_scratch:DI 4 "=&r"))
9311    (clobber (match_scratch:SI 5 "=q"))]
9312   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
9313    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9314   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9315   [(set_attr "type" "load")
9316    (set_attr "length" "8")])
9317
9318 (define_insn ""
9319   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9320         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9321    (use (match_operand:SI 2 "immediate_operand" "i"))
9322    (use (match_operand:SI 3 "immediate_operand" "i"))
9323    (clobber (match_scratch:DI 4 "=&r"))
9324    (clobber (match_scratch:SI 5 "X"))]
9325   "TARGET_STRING && ! TARGET_POWER && ! TARGET_POWERPC64
9326    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9327   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9328   [(set_attr "type" "load")
9329    (set_attr "length" "8")])
9330
9331 ;; Move up to 4 bytes at a time.
9332 (define_expand "movstrsi_1reg"
9333   [(parallel [(set (match_operand 0 "" "")
9334                    (match_operand 1 "" ""))
9335               (use (match_operand 2 "" ""))
9336               (use (match_operand 3 "" ""))
9337               (clobber (match_scratch:SI 4 ""))
9338               (clobber (match_scratch:SI 5 ""))])]
9339   "TARGET_STRING"
9340   "")
9341
9342 (define_insn ""
9343   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9344         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9345    (use (match_operand:SI 2 "immediate_operand" "i"))
9346    (use (match_operand:SI 3 "immediate_operand" "i"))
9347    (clobber (match_scratch:SI 4 "=&r"))
9348    (clobber (match_scratch:SI 5 "=q"))]
9349   "TARGET_STRING && TARGET_POWER
9350    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9351   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9352   [(set_attr "type" "load")
9353    (set_attr "length" "8")])
9354
9355 (define_insn ""
9356   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9357         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9358    (use (match_operand:SI 2 "immediate_operand" "i"))
9359    (use (match_operand:SI 3 "immediate_operand" "i"))
9360    (clobber (match_scratch:SI 4 "=&r"))
9361    (clobber (match_scratch:SI 5 "X"))]
9362   "TARGET_STRING && ! TARGET_POWER
9363    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9364   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9365   [(set_attr "type" "load")
9366    (set_attr "length" "8")])
9367
9368 (define_insn ""
9369   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9370         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9371    (use (match_operand:SI 2 "immediate_operand" "i"))
9372    (use (match_operand:SI 3 "immediate_operand" "i"))
9373    (clobber (match_scratch:SI 4 "=&r"))
9374    (clobber (match_scratch:SI 5 "X"))]
9375   "TARGET_STRING && TARGET_POWERPC64
9376    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9377   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9378   [(set_attr "type" "load")
9379    (set_attr "length" "8")])
9380
9381 \f
9382 ;; Define insns that do load or store with update.  Some of these we can
9383 ;; get by using pre-decrement or pre-increment, but the hardware can also
9384 ;; do cases where the increment is not the size of the object.
9385 ;;
9386 ;; In all these cases, we use operands 0 and 1 for the register being
9387 ;; incremented because those are the operands that local-alloc will
9388 ;; tie and these are the pair most likely to be tieable (and the ones
9389 ;; that will benefit the most).
9390
9391 (define_insn "*movdi_update1"
9392   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
9393         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9394                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
9395    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9396         (plus:DI (match_dup 1) (match_dup 2)))]
9397   "TARGET_POWERPC64 && TARGET_UPDATE"
9398   "@
9399    ldux %3,%0,%2
9400    ldu %3,%2(%0)"
9401   [(set_attr "type" "load_ux,load_u")])
9402
9403 (define_insn "movdi_update"
9404   [(set (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9405                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I")))
9406         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
9407    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9408         (plus:DI (match_dup 1) (match_dup 2)))]
9409   "TARGET_POWERPC64 && TARGET_UPDATE"
9410   "@
9411    stdux %3,%0,%2
9412    stdu %3,%2(%0)"
9413   [(set_attr "type" "store_ux,store_u")])
9414
9415 (define_insn "*movsi_update1"
9416   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9417         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9418                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9419    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9420         (plus:SI (match_dup 1) (match_dup 2)))]
9421   "TARGET_UPDATE"
9422   "@
9423    {lux|lwzux} %3,%0,%2
9424    {lu|lwzu} %3,%2(%0)"
9425   [(set_attr "type" "load_ux,load_u")])
9426
9427 (define_insn "*movsi_update2"
9428   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
9429         (sign_extend:DI
9430          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
9431                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
9432    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
9433         (plus:DI (match_dup 1) (match_dup 2)))]
9434   "TARGET_POWERPC64"
9435   "lwaux %3,%0,%2"
9436   [(set_attr "type" "load_ext_ux")])
9437
9438 (define_insn "movsi_update"
9439   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9440                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9441         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
9442    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9443         (plus:SI (match_dup 1) (match_dup 2)))]
9444   "TARGET_UPDATE"
9445   "@
9446    {stux|stwux} %3,%0,%2
9447    {stu|stwu} %3,%2(%0)"
9448   [(set_attr "type" "store_ux,store_u")])
9449
9450 (define_insn "*movhi_update1"
9451   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
9452         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9453                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9454    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9455         (plus:SI (match_dup 1) (match_dup 2)))]
9456   "TARGET_UPDATE"
9457   "@
9458    lhzux %3,%0,%2
9459    lhzu %3,%2(%0)"
9460   [(set_attr "type" "load_ux,load_u")])
9461
9462 (define_insn "*movhi_update2"
9463   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9464         (zero_extend:SI
9465          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9466                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9467    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9468         (plus:SI (match_dup 1) (match_dup 2)))]
9469   "TARGET_UPDATE"
9470   "@
9471    lhzux %3,%0,%2
9472    lhzu %3,%2(%0)"
9473   [(set_attr "type" "load_ux,load_u")])
9474
9475 (define_insn "*movhi_update3"
9476   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9477         (sign_extend:SI
9478          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9479                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9480    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9481         (plus:SI (match_dup 1) (match_dup 2)))]
9482   "TARGET_UPDATE"
9483   "@
9484    lhaux %3,%0,%2
9485    lhau %3,%2(%0)"
9486   [(set_attr "type" "load_ext_ux,load_ext_u")])
9487
9488 (define_insn "*movhi_update4"
9489   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9490                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9491         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
9492    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9493         (plus:SI (match_dup 1) (match_dup 2)))]
9494   "TARGET_UPDATE"
9495   "@
9496    sthux %3,%0,%2
9497    sthu %3,%2(%0)"
9498   [(set_attr "type" "store_ux,store_u")])
9499
9500 (define_insn "*movqi_update1"
9501   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
9502         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9503                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9504    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9505         (plus:SI (match_dup 1) (match_dup 2)))]
9506   "TARGET_UPDATE"
9507   "@
9508    lbzux %3,%0,%2
9509    lbzu %3,%2(%0)"
9510   [(set_attr "type" "load_ux,load_u")])
9511
9512 (define_insn "*movqi_update2"
9513   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9514         (zero_extend:SI
9515          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9516                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9517    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9518         (plus:SI (match_dup 1) (match_dup 2)))]
9519   "TARGET_UPDATE"
9520   "@
9521    lbzux %3,%0,%2
9522    lbzu %3,%2(%0)"
9523   [(set_attr "type" "load_ux,load_u")])
9524
9525 (define_insn "*movqi_update3"
9526   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9527                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9528         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
9529    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9530         (plus:SI (match_dup 1) (match_dup 2)))]
9531   "TARGET_UPDATE"
9532   "@
9533    stbux %3,%0,%2
9534    stbu %3,%2(%0)"
9535   [(set_attr "type" "store_ux,store_u")])
9536
9537 (define_insn "*movsf_update1"
9538   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
9539         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9540                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9541    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9542         (plus:SI (match_dup 1) (match_dup 2)))]
9543   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9544   "@
9545    lfsux %3,%0,%2
9546    lfsu %3,%2(%0)"
9547   [(set_attr "type" "fpload_ux,fpload_u")])
9548
9549 (define_insn "*movsf_update2"
9550   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9551                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9552         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
9553    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9554         (plus:SI (match_dup 1) (match_dup 2)))]
9555   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9556   "@
9557    stfsux %3,%0,%2
9558    stfsu %3,%2(%0)"
9559   [(set_attr "type" "fpstore_ux,fpstore_u")])
9560
9561 (define_insn "*movsf_update3"
9562   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
9563         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9564                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9565    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9566         (plus:SI (match_dup 1) (match_dup 2)))]
9567   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9568   "@
9569    {lux|lwzux} %3,%0,%2
9570    {lu|lwzu} %3,%2(%0)"
9571   [(set_attr "type" "load_ux,load_u")])
9572
9573 (define_insn "*movsf_update4"
9574   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9575                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9576         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
9577    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9578         (plus:SI (match_dup 1) (match_dup 2)))]
9579   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9580   "@
9581    {stux|stwux} %3,%0,%2
9582    {stu|stwu} %3,%2(%0)"
9583   [(set_attr "type" "store_ux,store_u")])
9584
9585 (define_insn "*movdf_update1"
9586   [(set (match_operand:DF 3 "gpc_reg_operand" "=f,f")
9587         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9588                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9589    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9590         (plus:SI (match_dup 1) (match_dup 2)))]
9591   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9592   "@
9593    lfdux %3,%0,%2
9594    lfdu %3,%2(%0)"
9595   [(set_attr "type" "fpload_ux,fpload_u")])
9596
9597 (define_insn "*movdf_update2"
9598   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9599                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9600         (match_operand:DF 3 "gpc_reg_operand" "f,f"))
9601    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9602         (plus:SI (match_dup 1) (match_dup 2)))]
9603   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9604   "@
9605    stfdux %3,%0,%2
9606    stfdu %3,%2(%0)"
9607   [(set_attr "type" "fpstore_ux,fpstore_u")])
9608
9609 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
9610
9611 (define_peephole
9612   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
9613         (match_operand:DF 1 "memory_operand" ""))
9614    (set (match_operand:DF 2 "gpc_reg_operand" "=f")
9615         (match_operand:DF 3 "memory_operand" ""))]
9616   "TARGET_POWER2
9617    && TARGET_HARD_FLOAT && TARGET_FPRS
9618    && registers_ok_for_quad_peep (operands[0], operands[2])
9619    && ! MEM_VOLATILE_P (operands[1]) && ! MEM_VOLATILE_P (operands[3])
9620    && addrs_ok_for_quad_peep (XEXP (operands[1], 0), XEXP (operands[3], 0))"
9621   "lfq%U1%X1 %0,%1")
9622
9623 (define_peephole
9624   [(set (match_operand:DF 0 "memory_operand" "")
9625         (match_operand:DF 1 "gpc_reg_operand" "f"))
9626    (set (match_operand:DF 2 "memory_operand" "")
9627         (match_operand:DF 3 "gpc_reg_operand" "f"))]
9628   "TARGET_POWER2
9629    && TARGET_HARD_FLOAT && TARGET_FPRS
9630    && registers_ok_for_quad_peep (operands[1], operands[3])
9631    && ! MEM_VOLATILE_P (operands[0]) && ! MEM_VOLATILE_P (operands[2])
9632    && addrs_ok_for_quad_peep (XEXP (operands[0], 0), XEXP (operands[2], 0))"
9633   "stfq%U0%X0 %1,%0")
9634 \f
9635 ;; TLS support.
9636
9637 ;; "b" output constraint here and on tls_ld to support tls linker optimization.
9638 (define_insn "tls_gd_32"
9639   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9640         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9641                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9642                    UNSPEC_TLSGD))]
9643   "HAVE_AS_TLS && !TARGET_64BIT"
9644   "addi %0,%1,%2@got@tlsgd")
9645
9646 (define_insn "tls_gd_64"
9647   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9648         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9649                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9650                    UNSPEC_TLSGD))]
9651   "HAVE_AS_TLS && TARGET_64BIT"
9652   "addi %0,%1,%2@got@tlsgd")
9653
9654 (define_insn "tls_ld_32"
9655   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9656         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")]
9657                    UNSPEC_TLSLD))]
9658   "HAVE_AS_TLS && !TARGET_64BIT"
9659   "addi %0,%1,%&@got@tlsld")
9660
9661 (define_insn "tls_ld_64"
9662   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9663         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")]
9664                    UNSPEC_TLSLD))]
9665   "HAVE_AS_TLS && TARGET_64BIT"
9666   "addi %0,%1,%&@got@tlsld")
9667
9668 (define_insn "tls_dtprel_32"
9669   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9670         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9671                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9672                    UNSPEC_TLSDTPREL))]
9673   "HAVE_AS_TLS && !TARGET_64BIT"
9674   "addi %0,%1,%2@dtprel")
9675
9676 (define_insn "tls_dtprel_64"
9677   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9678         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9679                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9680                    UNSPEC_TLSDTPREL))]
9681   "HAVE_AS_TLS && TARGET_64BIT"
9682   "addi %0,%1,%2@dtprel")
9683
9684 (define_insn "tls_dtprel_ha_32"
9685   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9686         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9687                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9688                    UNSPEC_TLSDTPRELHA))]
9689   "HAVE_AS_TLS && !TARGET_64BIT"
9690   "addis %0,%1,%2@dtprel@ha")
9691
9692 (define_insn "tls_dtprel_ha_64"
9693   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9694         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9695                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9696                    UNSPEC_TLSDTPRELHA))]
9697   "HAVE_AS_TLS && TARGET_64BIT"
9698   "addis %0,%1,%2@dtprel@ha")
9699
9700 (define_insn "tls_dtprel_lo_32"
9701   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9702         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9703                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9704                    UNSPEC_TLSDTPRELLO))]
9705   "HAVE_AS_TLS && !TARGET_64BIT"
9706   "addi %0,%1,%2@dtprel@l")
9707
9708 (define_insn "tls_dtprel_lo_64"
9709   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9710         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9711                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9712                    UNSPEC_TLSDTPRELLO))]
9713   "HAVE_AS_TLS && TARGET_64BIT"
9714   "addi %0,%1,%2@dtprel@l")
9715
9716 (define_insn "tls_got_dtprel_32"
9717   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9718         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9719                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9720                    UNSPEC_TLSGOTDTPREL))]
9721   "HAVE_AS_TLS && !TARGET_64BIT"
9722   "lwz %0,%2@got@dtprel(%1)")
9723
9724 (define_insn "tls_got_dtprel_64"
9725   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9726         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9727                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9728                    UNSPEC_TLSGOTDTPREL))]
9729   "HAVE_AS_TLS && TARGET_64BIT"
9730   "ld %0,%2@got@dtprel(%1)")
9731
9732 (define_insn "tls_tprel_32"
9733   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9734         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9735                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9736                    UNSPEC_TLSTPREL))]
9737   "HAVE_AS_TLS && !TARGET_64BIT"
9738   "addi %0,%1,%2@tprel")
9739
9740 (define_insn "tls_tprel_64"
9741   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9742         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9743                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9744                    UNSPEC_TLSTPREL))]
9745   "HAVE_AS_TLS && TARGET_64BIT"
9746   "addi %0,%1,%2@tprel")
9747
9748 (define_insn "tls_tprel_ha_32"
9749   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9750         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9751                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9752                    UNSPEC_TLSTPRELHA))]
9753   "HAVE_AS_TLS && !TARGET_64BIT"
9754   "addis %0,%1,%2@tprel@ha")
9755
9756 (define_insn "tls_tprel_ha_64"
9757   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9758         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9759                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9760                    UNSPEC_TLSTPRELHA))]
9761   "HAVE_AS_TLS && TARGET_64BIT"
9762   "addis %0,%1,%2@tprel@ha")
9763
9764 (define_insn "tls_tprel_lo_32"
9765   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9766         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9767                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9768                    UNSPEC_TLSTPRELLO))]
9769   "HAVE_AS_TLS && !TARGET_64BIT"
9770   "addi %0,%1,%2@tprel@l")
9771
9772 (define_insn "tls_tprel_lo_64"
9773   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9774         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9775                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9776                    UNSPEC_TLSTPRELLO))]
9777   "HAVE_AS_TLS && TARGET_64BIT"
9778   "addi %0,%1,%2@tprel@l")
9779
9780 ;; "b" output constraint here and on tls_tls input to support linker tls
9781 ;; optimization.  The linker may edit the instructions emitted by a
9782 ;; tls_got_tprel/tls_tls pair to addis,addi.
9783 (define_insn "tls_got_tprel_32"
9784   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9785         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9786                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9787                    UNSPEC_TLSGOTTPREL))]
9788   "HAVE_AS_TLS && !TARGET_64BIT"
9789   "lwz %0,%2@got@tprel(%1)")
9790
9791 (define_insn "tls_got_tprel_64"
9792   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9793         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9794                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9795                    UNSPEC_TLSGOTTPREL))]
9796   "HAVE_AS_TLS && TARGET_64BIT"
9797   "ld %0,%2@got@tprel(%1)")
9798
9799 (define_insn "tls_tls_32"
9800   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9801         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9802                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9803                    UNSPEC_TLSTLS))]
9804   "HAVE_AS_TLS && !TARGET_64BIT"
9805   "add %0,%1,%2@tls")
9806
9807 (define_insn "tls_tls_64"
9808   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9809         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9810                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9811                    UNSPEC_TLSTLS))]
9812   "HAVE_AS_TLS && TARGET_64BIT"
9813   "add %0,%1,%2@tls")
9814 \f
9815 ;; Next come insns related to the calling sequence.
9816 ;;
9817 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
9818 ;; We move the back-chain and decrement the stack pointer.
9819
9820 (define_expand "allocate_stack"
9821   [(set (match_operand 0 "gpc_reg_operand" "=r")
9822         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
9823    (set (reg 1)
9824         (minus (reg 1) (match_dup 1)))]
9825   ""
9826   "
9827 { rtx chain = gen_reg_rtx (Pmode);
9828   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
9829   rtx neg_op0;
9830
9831   emit_move_insn (chain, stack_bot);
9832
9833   /* Check stack bounds if necessary.  */
9834   if (current_function_limit_stack)
9835     {
9836       rtx available;
9837       available = expand_binop (Pmode, sub_optab,
9838                                 stack_pointer_rtx, stack_limit_rtx,
9839                                 NULL_RTX, 1, OPTAB_WIDEN);
9840       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
9841     }
9842
9843   if (GET_CODE (operands[1]) != CONST_INT
9844       || INTVAL (operands[1]) < -32767
9845       || INTVAL (operands[1]) > 32768)
9846     {
9847       neg_op0 = gen_reg_rtx (Pmode);
9848       if (TARGET_32BIT)
9849         emit_insn (gen_negsi2 (neg_op0, operands[1]));
9850       else
9851         emit_insn (gen_negdi2 (neg_op0, operands[1]));
9852     }
9853   else
9854     neg_op0 = GEN_INT (- INTVAL (operands[1]));
9855
9856   if (TARGET_UPDATE)
9857     emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update : gen_movdi_update))
9858                 (stack_pointer_rtx, stack_pointer_rtx, neg_op0, chain));
9859
9860   else
9861     {
9862       emit_insn ((* ((TARGET_32BIT) ? gen_addsi3 : gen_adddi3))
9863                  (stack_pointer_rtx, stack_pointer_rtx, neg_op0));
9864       emit_move_insn (gen_rtx_MEM (Pmode, stack_pointer_rtx), chain);
9865     }
9866
9867   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
9868   DONE;
9869 }")
9870
9871 ;; These patterns say how to save and restore the stack pointer.  We need not
9872 ;; save the stack pointer at function level since we are careful to
9873 ;; preserve the backchain.  At block level, we have to restore the backchain
9874 ;; when we restore the stack pointer.
9875 ;;
9876 ;; For nonlocal gotos, we must save both the stack pointer and its
9877 ;; backchain and restore both.  Note that in the nonlocal case, the
9878 ;; save area is a memory location.
9879
9880 (define_expand "save_stack_function"
9881   [(match_operand 0 "any_operand" "")
9882    (match_operand 1 "any_operand" "")]
9883   ""
9884   "DONE;")
9885
9886 (define_expand "restore_stack_function"
9887   [(match_operand 0 "any_operand" "")
9888    (match_operand 1 "any_operand" "")]
9889   ""
9890   "DONE;")
9891
9892 (define_expand "restore_stack_block"
9893   [(use (match_operand 0 "register_operand" ""))
9894    (set (match_dup 2) (match_dup 3))
9895    (set (match_dup 0) (match_operand 1 "register_operand" ""))
9896    (set (match_dup 3) (match_dup 2))]
9897   ""
9898   "
9899 {
9900   operands[2] = gen_reg_rtx (Pmode);
9901   operands[3] = gen_rtx_MEM (Pmode, operands[0]);
9902 }")
9903
9904 (define_expand "save_stack_nonlocal"
9905   [(match_operand 0 "memory_operand" "")
9906    (match_operand 1 "register_operand" "")]
9907   ""
9908   "
9909 {
9910   rtx temp = gen_reg_rtx (Pmode);
9911   int units_per_word = (TARGET_32BIT) ? 4 : 8;
9912
9913   /* Copy the backchain to the first word, sp to the second.  */
9914   emit_move_insn (temp, gen_rtx_MEM (Pmode, operands[1]));
9915   emit_move_insn (adjust_address_nv (operands[0], Pmode, 0), temp);
9916   emit_move_insn (adjust_address_nv (operands[0], Pmode, units_per_word),
9917                   operands[1]);
9918   DONE;
9919 }")
9920
9921 (define_expand "restore_stack_nonlocal"
9922   [(match_operand 0 "register_operand" "")
9923    (match_operand 1 "memory_operand" "")]
9924   ""
9925   "
9926 {
9927   rtx temp = gen_reg_rtx (Pmode);
9928   int units_per_word = (TARGET_32BIT) ? 4 : 8;
9929
9930   /* Restore the backchain from the first word, sp from the second.  */
9931   emit_move_insn (temp,
9932                   adjust_address_nv (operands[1], Pmode, 0));
9933   emit_move_insn (operands[0],
9934                   adjust_address_nv (operands[1], Pmode, units_per_word));
9935   emit_move_insn (gen_rtx_MEM (Pmode, operands[0]), temp);
9936   DONE;
9937 }")
9938 \f
9939 ;; TOC register handling.
9940
9941 ;; Code to initialize the TOC register...
9942
9943 (define_insn "load_toc_aix_si"
9944   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9945                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
9946               (use (reg:SI 2))])]
9947   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
9948   "*
9949 {
9950   char buf[30];
9951   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
9952   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9953   operands[2] = gen_rtx_REG (Pmode, 2);
9954   return \"{l|lwz} %0,%1(%2)\";
9955 }"
9956   [(set_attr "type" "load")])
9957
9958 (define_insn "load_toc_aix_di"
9959   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9960                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
9961               (use (reg:DI 2))])]
9962   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
9963   "*
9964 {
9965   char buf[30];
9966 #ifdef TARGET_RELOCATABLE
9967   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
9968                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
9969 #else
9970   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
9971 #endif
9972   if (TARGET_ELF)
9973     strcat (buf, \"@toc\");
9974   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9975   operands[2] = gen_rtx_REG (Pmode, 2);
9976   return \"ld %0,%1(%2)\";
9977 }"
9978   [(set_attr "type" "load")])
9979
9980 (define_insn "load_toc_v4_pic_si"
9981   [(set (match_operand:SI 0 "register_operand" "=l")
9982         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
9983   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
9984   "bl _GLOBAL_OFFSET_TABLE_@local-4"
9985   [(set_attr "type" "branch")
9986    (set_attr "length" "4")])
9987
9988 (define_insn "load_toc_v4_PIC_1"
9989   [(set (match_operand:SI 0 "register_operand" "=l")
9990         (match_operand:SI 1 "immediate_operand" "s"))
9991    (use (unspec [(match_dup 1)] UNSPEC_TOC))]
9992   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
9993   "bcl 20,31,%1\\n%1:"
9994   [(set_attr "type" "branch")
9995    (set_attr "length" "4")])
9996
9997 (define_insn "load_toc_v4_PIC_1b"
9998   [(set (match_operand:SI 0 "register_operand" "=l")
9999         (match_operand:SI 1 "immediate_operand" "s"))
10000    (use (unspec [(match_dup 1) (match_operand 2 "immediate_operand" "s")]
10001                 UNSPEC_TOCPTR))]
10002   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10003   "bcl 20,31,%1+4\\n%1:\\n\\t.long %2-%1"
10004   [(set_attr "type" "branch")
10005    (set_attr "length" "8")])
10006
10007 (define_insn "load_toc_v4_PIC_2"
10008   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10009         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10010                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
10011                              (match_operand:SI 3 "immediate_operand" "s")))))]
10012   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10013   "{l|lwz} %0,%2-%3(%1)"
10014   [(set_attr "type" "load")])
10015
10016 (define_insn "load_macho_picbase"
10017   [(set (match_operand:SI 0 "register_operand" "=l")
10018         (unspec:SI [(match_operand:SI 1 "immediate_operand" "s")]
10019                    UNSPEC_LD_MPIC))]
10020   "(DEFAULT_ABI == ABI_DARWIN) && flag_pic"
10021   "bcl 20,31,%1\\n%1:"
10022   [(set_attr "type" "branch")
10023    (set_attr "length" "4")])
10024
10025 (define_insn "macho_correct_pic"
10026   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10027         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
10028                  (unspec:SI [(match_operand:SI 2 "immediate_operand" "s")
10029                              (match_operand:SI 3 "immediate_operand" "s")]
10030                             UNSPEC_MPIC_CORRECT)))]
10031   "DEFAULT_ABI == ABI_DARWIN"
10032   "addis %0,%1,ha16(%2-%3)\n\taddi %0,%0,lo16(%2-%3)"
10033   [(set_attr "length" "8")])
10034
10035 ;; If the TOC is shared over a translation unit, as happens with all
10036 ;; the kinds of PIC that we support, we need to restore the TOC
10037 ;; pointer only when jumping over units of translation.
10038 ;; On Darwin, we need to reload the picbase.
10039
10040 (define_expand "builtin_setjmp_receiver"
10041   [(use (label_ref (match_operand 0 "" "")))]
10042   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
10043    || (TARGET_TOC && TARGET_MINIMAL_TOC)
10044    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
10045   "
10046 {
10047 #if TARGET_MACHO
10048   if (DEFAULT_ABI == ABI_DARWIN)
10049     {
10050       const char *picbase = machopic_function_base_name ();
10051       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (picbase));
10052       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
10053       rtx tmplabrtx;
10054       char tmplab[20];
10055
10056       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
10057                                   CODE_LABEL_NUMBER (operands[0]));
10058       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
10059
10060       emit_insn (gen_load_macho_picbase (picreg, tmplabrtx));
10061       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
10062     }
10063   else
10064 #endif
10065     rs6000_emit_load_toc_table (FALSE);
10066   DONE;
10067 }")
10068 \f
10069 ;; A function pointer under AIX is a pointer to a data area whose first word
10070 ;; contains the actual address of the function, whose second word contains a
10071 ;; pointer to its TOC, and whose third word contains a value to place in the
10072 ;; static chain register (r11).  Note that if we load the static chain, our
10073 ;; "trampoline" need not have any executable code.
10074
10075 (define_expand "call_indirect_aix32"
10076   [(set (match_dup 2)
10077         (mem:SI (match_operand:SI 0 "gpc_reg_operand" "")))
10078    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10079         (reg:SI 2))
10080    (set (reg:SI 2)
10081         (mem:SI (plus:SI (match_dup 0)
10082                          (const_int 4))))
10083    (set (reg:SI 11)
10084         (mem:SI (plus:SI (match_dup 0)
10085                          (const_int 8))))
10086    (parallel [(call (mem:SI (match_dup 2))
10087                     (match_operand 1 "" ""))
10088               (use (reg:SI 2))
10089               (use (reg:SI 11))
10090               (set (reg:SI 2)
10091                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10092               (clobber (scratch:SI))])]
10093   "TARGET_32BIT"
10094   "
10095 { operands[2] = gen_reg_rtx (SImode); }")
10096
10097 (define_expand "call_indirect_aix64"
10098   [(set (match_dup 2)
10099         (mem:DI (match_operand:DI 0 "gpc_reg_operand" "")))
10100    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10101         (reg:DI 2))
10102    (set (reg:DI 2)
10103         (mem:DI (plus:DI (match_dup 0)
10104                          (const_int 8))))
10105    (set (reg:DI 11)
10106         (mem:DI (plus:DI (match_dup 0)
10107                          (const_int 16))))
10108    (parallel [(call (mem:SI (match_dup 2))
10109                     (match_operand 1 "" ""))
10110               (use (reg:DI 2))
10111               (use (reg:DI 11))
10112               (set (reg:DI 2)
10113                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10114               (clobber (scratch:SI))])]
10115   "TARGET_64BIT"
10116   "
10117 { operands[2] = gen_reg_rtx (DImode); }")
10118
10119 (define_expand "call_value_indirect_aix32"
10120   [(set (match_dup 3)
10121         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
10122    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10123         (reg:SI 2))
10124    (set (reg:SI 2)
10125         (mem:SI (plus:SI (match_dup 1)
10126                          (const_int 4))))
10127    (set (reg:SI 11)
10128         (mem:SI (plus:SI (match_dup 1)
10129                          (const_int 8))))
10130    (parallel [(set (match_operand 0 "" "")
10131                    (call (mem:SI (match_dup 3))
10132                          (match_operand 2 "" "")))
10133               (use (reg:SI 2))
10134               (use (reg:SI 11))
10135               (set (reg:SI 2)
10136                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10137               (clobber (scratch:SI))])]
10138   "TARGET_32BIT"
10139   "
10140 { operands[3] = gen_reg_rtx (SImode); }")
10141
10142 (define_expand "call_value_indirect_aix64"
10143   [(set (match_dup 3)
10144         (mem:DI (match_operand:DI 1 "gpc_reg_operand" "")))
10145    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10146         (reg:DI 2))
10147    (set (reg:DI 2)
10148         (mem:DI (plus:DI (match_dup 1)
10149                          (const_int 8))))
10150    (set (reg:DI 11)
10151         (mem:DI (plus:DI (match_dup 1)
10152                          (const_int 16))))
10153    (parallel [(set (match_operand 0 "" "")
10154                    (call (mem:SI (match_dup 3))
10155                          (match_operand 2 "" "")))
10156               (use (reg:DI 2))
10157               (use (reg:DI 11))
10158               (set (reg:DI 2)
10159                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10160               (clobber (scratch:SI))])]
10161   "TARGET_64BIT"
10162   "
10163 { operands[3] = gen_reg_rtx (DImode); }")
10164
10165 ;; Now the definitions for the call and call_value insns
10166 (define_expand "call"
10167   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10168                     (match_operand 1 "" ""))
10169               (use (match_operand 2 "" ""))
10170               (clobber (scratch:SI))])]
10171   ""
10172   "
10173 {
10174 #if TARGET_MACHO
10175   if (MACHOPIC_INDIRECT)
10176     operands[0] = machopic_indirect_call_target (operands[0]);
10177 #endif
10178
10179   if (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != CONST_INT)
10180     abort ();
10181
10182   operands[0] = XEXP (operands[0], 0);
10183
10184   if (GET_CODE (operands[0]) != SYMBOL_REF
10185       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
10186       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
10187     {
10188       if (INTVAL (operands[2]) & CALL_LONG)
10189         operands[0] = rs6000_longcall_ref (operands[0]);
10190
10191       if (DEFAULT_ABI == ABI_V4
10192           || DEFAULT_ABI == ABI_DARWIN)
10193         operands[0] = force_reg (Pmode, operands[0]);
10194
10195       else if (DEFAULT_ABI == ABI_AIX)
10196         {
10197           /* AIX function pointers are really pointers to a three word
10198              area.  */
10199           emit_call_insn (TARGET_32BIT
10200                           ? gen_call_indirect_aix32 (force_reg (SImode,
10201                                                                 operands[0]),
10202                                                      operands[1])
10203                           : gen_call_indirect_aix64 (force_reg (DImode,
10204                                                                 operands[0]),
10205                                                      operands[1]));
10206           DONE;
10207         }
10208       else
10209         abort ();
10210     }
10211 }")
10212
10213 (define_expand "call_value"
10214   [(parallel [(set (match_operand 0 "" "")
10215                    (call (mem:SI (match_operand 1 "address_operand" ""))
10216                          (match_operand 2 "" "")))
10217               (use (match_operand 3 "" ""))
10218               (clobber (scratch:SI))])]
10219   ""
10220   "
10221 {
10222 #if TARGET_MACHO
10223   if (MACHOPIC_INDIRECT)
10224     operands[1] = machopic_indirect_call_target (operands[1]);
10225 #endif
10226
10227   if (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != CONST_INT)
10228     abort ();
10229
10230   operands[1] = XEXP (operands[1], 0);
10231
10232   if (GET_CODE (operands[1]) != SYMBOL_REF
10233       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
10234       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
10235     {
10236       if (INTVAL (operands[3]) & CALL_LONG)
10237         operands[1] = rs6000_longcall_ref (operands[1]);
10238
10239       if (DEFAULT_ABI == ABI_V4
10240           || DEFAULT_ABI == ABI_DARWIN)
10241         operands[1] = force_reg (Pmode, operands[1]);
10242
10243       else if (DEFAULT_ABI == ABI_AIX)
10244         {
10245           /* AIX function pointers are really pointers to a three word
10246              area.  */
10247           emit_call_insn (TARGET_32BIT
10248                           ? gen_call_value_indirect_aix32 (operands[0],
10249                                                            force_reg (SImode,
10250                                                                       operands[1]),
10251                                                            operands[2])
10252                           : gen_call_value_indirect_aix64 (operands[0],
10253                                                            force_reg (DImode,
10254                                                                       operands[1]),
10255                                                            operands[2]));
10256           DONE;
10257         }
10258       else
10259         abort ();
10260     }
10261 }")
10262
10263 ;; Call to function in current module.  No TOC pointer reload needed.
10264 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10265 ;; either the function was not prototyped, or it was prototyped as a
10266 ;; variable argument function.  It is > 0 if FP registers were passed
10267 ;; and < 0 if they were not.
10268
10269 (define_insn "*call_local32"
10270   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10271          (match_operand 1 "" "g,g"))
10272    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10273    (clobber (match_scratch:SI 3 "=l,l"))]
10274   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10275   "*
10276 {
10277   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10278     output_asm_insn (\"crxor 6,6,6\", operands);
10279
10280   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10281     output_asm_insn (\"creqv 6,6,6\", operands);
10282
10283   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10284 }"
10285   [(set_attr "type" "branch")
10286    (set_attr "length" "4,8")])
10287
10288 (define_insn "*call_local64"
10289   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10290          (match_operand 1 "" "g,g"))
10291    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10292    (clobber (match_scratch:SI 3 "=l,l"))]
10293   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10294   "*
10295 {
10296   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10297     output_asm_insn (\"crxor 6,6,6\", operands);
10298
10299   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10300     output_asm_insn (\"creqv 6,6,6\", operands);
10301
10302   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10303 }"
10304   [(set_attr "type" "branch")
10305    (set_attr "length" "4,8")])
10306
10307 (define_insn "*call_value_local32"
10308   [(set (match_operand 0 "" "")
10309         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10310               (match_operand 2 "" "g,g")))
10311    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10312    (clobber (match_scratch:SI 4 "=l,l"))]
10313   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10314   "*
10315 {
10316   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10317     output_asm_insn (\"crxor 6,6,6\", operands);
10318
10319   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10320     output_asm_insn (\"creqv 6,6,6\", operands);
10321
10322   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10323 }"
10324   [(set_attr "type" "branch")
10325    (set_attr "length" "4,8")])
10326
10327
10328 (define_insn "*call_value_local64"
10329   [(set (match_operand 0 "" "")
10330         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10331               (match_operand 2 "" "g,g")))
10332    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10333    (clobber (match_scratch:SI 4 "=l,l"))]
10334   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10335   "*
10336 {
10337   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10338     output_asm_insn (\"crxor 6,6,6\", operands);
10339
10340   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10341     output_asm_insn (\"creqv 6,6,6\", operands);
10342
10343   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10344 }"
10345   [(set_attr "type" "branch")
10346    (set_attr "length" "4,8")])
10347
10348 ;; Call to function which may be in another module.  Restore the TOC
10349 ;; pointer (r2) after the call unless this is System V.
10350 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10351 ;; either the function was not prototyped, or it was prototyped as a
10352 ;; variable argument function.  It is > 0 if FP registers were passed
10353 ;; and < 0 if they were not.
10354
10355 (define_insn "*call_indirect_nonlocal_aix32"
10356   [(call (mem:SI (match_operand:SI 0 "register_operand" "cl"))
10357          (match_operand 1 "" "g"))
10358    (use (reg:SI 2))
10359    (use (reg:SI 11))
10360    (set (reg:SI 2)
10361         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10362    (clobber (match_scratch:SI 2 "=l"))]
10363   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10364   "b%T0l\;{l|lwz} 2,20(1)"
10365   [(set_attr "type" "jmpreg")
10366    (set_attr "length" "8")])
10367
10368 (define_insn "*call_nonlocal_aix32"
10369   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10370          (match_operand 1 "" "g"))
10371    (use (match_operand:SI 2 "immediate_operand" "O"))
10372    (clobber (match_scratch:SI 3 "=l"))]
10373   "TARGET_32BIT
10374    && DEFAULT_ABI == ABI_AIX
10375    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10376   "bl %z0\;%."
10377   [(set_attr "type" "branch")
10378    (set_attr "length" "8")])
10379
10380 (define_insn "*call_indirect_nonlocal_aix64"
10381   [(call (mem:SI (match_operand:DI 0 "register_operand" "cl"))
10382          (match_operand 1 "" "g"))
10383    (use (reg:DI 2))
10384    (use (reg:DI 11))
10385    (set (reg:DI 2)
10386         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10387    (clobber (match_scratch:SI 2 "=l"))]
10388   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10389   "b%T0l\;ld 2,40(1)"
10390   [(set_attr "type" "jmpreg")
10391    (set_attr "length" "8")])
10392
10393 (define_insn "*call_nonlocal_aix64"
10394   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10395          (match_operand 1 "" "g"))
10396    (use (match_operand:SI 2 "immediate_operand" "O"))
10397    (clobber (match_scratch:SI 3 "=l"))]
10398   "TARGET_64BIT
10399    && DEFAULT_ABI == ABI_AIX
10400    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10401   "bl %z0\;%."
10402   [(set_attr "type" "branch")
10403    (set_attr "length" "8")])
10404
10405 (define_insn "*call_value_indirect_nonlocal_aix32"
10406   [(set (match_operand 0 "" "")
10407         (call (mem:SI (match_operand:SI 1 "register_operand" "cl"))
10408               (match_operand 2 "" "g")))
10409    (use (reg:SI 2))
10410    (use (reg:SI 11))
10411    (set (reg:SI 2)
10412         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10413    (clobber (match_scratch:SI 3 "=l"))]
10414   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10415   "b%T1l\;{l|lwz} 2,20(1)"
10416   [(set_attr "type" "jmpreg")
10417    (set_attr "length" "8")])
10418
10419 (define_insn "*call_value_nonlocal_aix32"
10420   [(set (match_operand 0 "" "")
10421         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10422               (match_operand 2 "" "g")))
10423    (use (match_operand:SI 3 "immediate_operand" "O"))
10424    (clobber (match_scratch:SI 4 "=l"))]
10425   "TARGET_32BIT
10426    && DEFAULT_ABI == ABI_AIX
10427    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10428   "bl %z1\;%."
10429   [(set_attr "type" "branch")
10430    (set_attr "length" "8")])
10431
10432 (define_insn "*call_value_indirect_nonlocal_aix64"
10433   [(set (match_operand 0 "" "")
10434         (call (mem:SI (match_operand:DI 1 "register_operand" "cl"))
10435               (match_operand 2 "" "g")))
10436    (use (reg:DI 2))
10437    (use (reg:DI 11))
10438    (set (reg:DI 2)
10439         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10440    (clobber (match_scratch:SI 3 "=l"))]
10441   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10442   "b%T1l\;ld 2,40(1)"
10443   [(set_attr "type" "jmpreg")
10444    (set_attr "length" "8")])
10445
10446 (define_insn "*call_value_nonlocal_aix64"
10447   [(set (match_operand 0 "" "")
10448         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10449               (match_operand 2 "" "g")))
10450    (use (match_operand:SI 3 "immediate_operand" "O"))
10451    (clobber (match_scratch:SI 4 "=l"))]
10452   "TARGET_64BIT
10453    && DEFAULT_ABI == ABI_AIX
10454    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10455   "bl %z1\;%."
10456   [(set_attr "type" "branch")
10457    (set_attr "length" "8")])
10458
10459 ;; A function pointer under System V is just a normal pointer
10460 ;; operands[0] is the function pointer
10461 ;; operands[1] is the stack size to clean up
10462 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
10463 ;; which indicates how to set cr1
10464
10465 (define_insn "*call_indirect_nonlocal_sysv"
10466   [(call (mem:SI (match_operand:SI 0 "register_operand" "cl,cl"))
10467          (match_operand 1 "" "g,g"))
10468    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10469    (clobber (match_scratch:SI 3 "=l,l"))]
10470   "DEFAULT_ABI == ABI_V4
10471    || DEFAULT_ABI == ABI_DARWIN"
10472 {
10473   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10474     output_asm_insn ("crxor 6,6,6", operands);
10475
10476   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10477     output_asm_insn ("creqv 6,6,6", operands);
10478
10479   return "b%T0l";
10480 }
10481   [(set_attr "type" "jmpreg,jmpreg")
10482    (set_attr "length" "4,8")])
10483
10484 (define_insn "*call_nonlocal_sysv"
10485   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s,s"))
10486          (match_operand 1 "" "g,g"))
10487    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10488    (clobber (match_scratch:SI 3 "=l,l"))]
10489   "(DEFAULT_ABI == ABI_DARWIN
10490    || (DEFAULT_ABI == ABI_V4
10491        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
10492 {
10493   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10494     output_asm_insn ("crxor 6,6,6", operands);
10495
10496   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10497     output_asm_insn ("creqv 6,6,6", operands);
10498
10499 #if TARGET_MACHO
10500   return output_call(insn, operands, 0, 2);
10501 #else
10502   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z0@plt" : "bl %z0";
10503 #endif
10504 }
10505   [(set_attr "type" "branch,branch")
10506    (set_attr "length" "4,8")])
10507
10508 (define_insn "*call_value_indirect_nonlocal_sysv"
10509   [(set (match_operand 0 "" "")
10510         (call (mem:SI (match_operand:SI 1 "register_operand" "cl,cl"))
10511               (match_operand 2 "" "g,g")))
10512    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10513    (clobber (match_scratch:SI 4 "=l,l"))]
10514   "DEFAULT_ABI == ABI_V4
10515    || DEFAULT_ABI == ABI_DARWIN"
10516 {
10517   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10518     output_asm_insn ("crxor 6,6,6", operands);
10519
10520   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10521     output_asm_insn ("creqv 6,6,6", operands);
10522
10523   return "b%T1l";
10524 }
10525   [(set_attr "type" "jmpreg,jmpreg")
10526    (set_attr "length" "4,8")])
10527
10528 (define_insn "*call_value_nonlocal_sysv"
10529   [(set (match_operand 0 "" "")
10530         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s,s"))
10531               (match_operand 2 "" "g,g")))
10532    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10533    (clobber (match_scratch:SI 4 "=l,l"))]
10534   "(DEFAULT_ABI == ABI_DARWIN
10535    || (DEFAULT_ABI == ABI_V4
10536        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
10537 {
10538   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10539     output_asm_insn ("crxor 6,6,6", operands);
10540
10541   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10542     output_asm_insn ("creqv 6,6,6", operands);
10543
10544 #if TARGET_MACHO
10545   return output_call(insn, operands, 1, 3);
10546 #else
10547   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z1@plt" : "bl %z1";
10548 #endif
10549 }
10550   [(set_attr "type" "branch,branch")
10551    (set_attr "length" "4,8")])
10552
10553 ;; Call subroutine returning any type.
10554 (define_expand "untyped_call"
10555   [(parallel [(call (match_operand 0 "" "")
10556                     (const_int 0))
10557               (match_operand 1 "" "")
10558               (match_operand 2 "" "")])]
10559   ""
10560   "
10561 {
10562   int i;
10563
10564   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
10565
10566   for (i = 0; i < XVECLEN (operands[2], 0); i++)
10567     {
10568       rtx set = XVECEXP (operands[2], 0, i);
10569       emit_move_insn (SET_DEST (set), SET_SRC (set));
10570     }
10571
10572   /* The optimizer does not know that the call sets the function value
10573      registers we stored in the result block.  We avoid problems by
10574      claiming that all hard registers are used and clobbered at this
10575      point.  */
10576   emit_insn (gen_blockage ());
10577
10578   DONE;
10579 }")
10580
10581 ;; sibling call patterns
10582 (define_expand "sibcall"
10583   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10584                     (match_operand 1 "" ""))
10585               (use (match_operand 2 "" ""))
10586               (use (match_operand 3 "" ""))
10587               (return)])]
10588   ""
10589   "
10590 {
10591 #if TARGET_MACHO
10592   if (MACHOPIC_INDIRECT)
10593     operands[0] = machopic_indirect_call_target (operands[0]);
10594 #endif
10595
10596   if (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != CONST_INT)
10597     abort ();
10598
10599   operands[0] = XEXP (operands[0], 0);
10600   operands[3] = gen_reg_rtx (SImode);
10601
10602 }")
10603
10604 ;; this and similar patterns must be marked as using LR, otherwise
10605 ;; dataflow will try to delete the store into it.  This is true
10606 ;; even when the actual reg to jump to is in CTR, when LR was
10607 ;; saved and restored around the PIC-setting BCL.
10608 (define_insn "*sibcall_local32"
10609   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10610          (match_operand 1 "" "g,g"))
10611    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10612    (use (match_operand:SI 3 "register_operand" "l,l"))
10613    (return)]
10614   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10615   "*
10616 {
10617   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10618     output_asm_insn (\"crxor 6,6,6\", operands);
10619
10620   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10621     output_asm_insn (\"creqv 6,6,6\", operands);
10622
10623   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
10624 }"
10625   [(set_attr "type" "branch")
10626    (set_attr "length" "4,8")])
10627
10628 (define_insn "*sibcall_local64"
10629   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10630          (match_operand 1 "" "g,g"))
10631    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10632    (use (match_operand:SI 3 "register_operand" "l,l"))
10633    (return)]
10634   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10635   "*
10636 {
10637   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10638     output_asm_insn (\"crxor 6,6,6\", operands);
10639
10640   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10641     output_asm_insn (\"creqv 6,6,6\", operands);
10642
10643   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
10644 }"
10645   [(set_attr "type" "branch")
10646    (set_attr "length" "4,8")])
10647
10648 (define_insn "*sibcall_value_local32"
10649   [(set (match_operand 0 "" "")
10650         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10651               (match_operand 2 "" "g,g")))
10652    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10653    (use (match_operand:SI 4 "register_operand" "l,l"))
10654    (return)]
10655   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10656   "*
10657 {
10658   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10659     output_asm_insn (\"crxor 6,6,6\", operands);
10660
10661   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10662     output_asm_insn (\"creqv 6,6,6\", operands);
10663
10664   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
10665 }"
10666   [(set_attr "type" "branch")
10667    (set_attr "length" "4,8")])
10668
10669
10670 (define_insn "*sibcall_value_local64"
10671   [(set (match_operand 0 "" "")
10672         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10673               (match_operand 2 "" "g,g")))
10674    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10675    (use (match_operand:SI 4 "register_operand" "l,l"))
10676    (return)]
10677   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10678   "*
10679 {
10680   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10681     output_asm_insn (\"crxor 6,6,6\", operands);
10682
10683   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10684     output_asm_insn (\"creqv 6,6,6\", operands);
10685
10686   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
10687 }"
10688   [(set_attr "type" "branch")
10689    (set_attr "length" "4,8")])
10690
10691 (define_insn "*sibcall_nonlocal_aix32"
10692   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10693          (match_operand 1 "" "g"))
10694    (use (match_operand:SI 2 "immediate_operand" "O"))
10695    (use (match_operand:SI 3 "register_operand" "l"))
10696    (return)]
10697   "TARGET_32BIT
10698    && DEFAULT_ABI == ABI_AIX
10699    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10700   "b %z0"
10701   [(set_attr "type" "branch")
10702    (set_attr "length" "4")])
10703
10704 (define_insn "*sibcall_nonlocal_aix64"
10705   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10706          (match_operand 1 "" "g"))
10707    (use (match_operand:SI 2 "immediate_operand" "O"))
10708    (use (match_operand:SI 3 "register_operand" "l"))
10709    (return)]
10710   "TARGET_64BIT
10711    && DEFAULT_ABI == ABI_AIX
10712    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10713   "b %z0"
10714   [(set_attr "type" "branch")
10715    (set_attr "length" "4")])
10716
10717 (define_insn "*sibcall_value_nonlocal_aix32"
10718   [(set (match_operand 0 "" "")
10719         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10720               (match_operand 2 "" "g")))
10721    (use (match_operand:SI 3 "immediate_operand" "O"))
10722    (use (match_operand:SI 4 "register_operand" "l"))
10723    (return)]
10724   "TARGET_32BIT
10725    && DEFAULT_ABI == ABI_AIX
10726    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10727   "b %z1"
10728   [(set_attr "type" "branch")
10729    (set_attr "length" "4")])
10730
10731 (define_insn "*sibcall_value_nonlocal_aix64"
10732   [(set (match_operand 0 "" "")
10733         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10734               (match_operand 2 "" "g")))
10735    (use (match_operand:SI 3 "immediate_operand" "O"))
10736    (use (match_operand:SI 4 "register_operand" "l"))
10737    (return)]
10738   "TARGET_64BIT
10739    && DEFAULT_ABI == ABI_AIX
10740    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10741   "b %z1"
10742   [(set_attr "type" "branch")
10743    (set_attr "length" "4")])
10744
10745 (define_insn "*sibcall_nonlocal_sysv"
10746   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s,s"))
10747          (match_operand 1 "" ""))
10748    (use (match_operand 2 "immediate_operand" "O,n"))
10749    (use (match_operand:SI 3 "register_operand" "l,l"))
10750    (return)]
10751   "(DEFAULT_ABI == ABI_DARWIN
10752      || DEFAULT_ABI == ABI_V4)
10753    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10754   "*
10755 {
10756   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10757     output_asm_insn (\"crxor 6,6,6\", operands);
10758
10759   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10760     output_asm_insn (\"creqv 6,6,6\", operands);
10761
10762   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@plt\" : \"b %z0\";
10763 }"
10764   [(set_attr "type" "branch,branch")
10765    (set_attr "length" "4,8")])
10766
10767 (define_expand "sibcall_value"
10768   [(parallel [(set (match_operand 0 "register_operand" "")
10769                 (call (mem:SI (match_operand 1 "address_operand" ""))
10770                       (match_operand 2 "" "")))
10771               (use (match_operand 3 "" ""))
10772               (use (match_operand 4 "" ""))
10773               (return)])]
10774   ""
10775   "
10776 {
10777 #if TARGET_MACHO
10778   if (MACHOPIC_INDIRECT)
10779     operands[1] = machopic_indirect_call_target (operands[1]);
10780 #endif
10781
10782   if (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != CONST_INT)
10783     abort ();
10784
10785   operands[1] = XEXP (operands[1], 0);
10786   operands[4] = gen_reg_rtx (SImode);
10787
10788 }")
10789
10790 (define_insn "*sibcall_value_nonlocal_sysv"
10791   [(set (match_operand 0 "" "")
10792         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s,s"))
10793               (match_operand 2 "" "")))
10794    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10795    (use (match_operand:SI 4 "register_operand" "l,l"))
10796    (return)]
10797   "(DEFAULT_ABI == ABI_DARWIN
10798        || DEFAULT_ABI == ABI_V4)
10799    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10800   "*
10801 {
10802   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10803     output_asm_insn (\"crxor 6,6,6\", operands);
10804
10805   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10806     output_asm_insn (\"creqv 6,6,6\", operands);
10807
10808   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@plt\" : \"b %z1\";
10809 }"
10810   [(set_attr "type" "branch,branch")
10811    (set_attr "length" "4,8")])
10812
10813 (define_expand "sibcall_epilogue"
10814   [(use (const_int 0))]
10815   "TARGET_SCHED_PROLOG"
10816   "
10817 {
10818       rs6000_emit_epilogue (TRUE);
10819       DONE;
10820 }")
10821
10822 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
10823 ;; all of memory.  This blocks insns from being moved across this point.
10824
10825 (define_insn "blockage"
10826   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
10827   ""
10828   "")
10829 \f
10830 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
10831 ;; signed & unsigned, and one type of branch.
10832 ;;
10833 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
10834 ;; insns, and branches.  We store the operands of compares until we see
10835 ;; how it is used.
10836 (define_expand "cmpsi"
10837   [(set (cc0)
10838         (compare (match_operand:SI 0 "gpc_reg_operand" "")
10839                  (match_operand:SI 1 "reg_or_short_operand" "")))]
10840   ""
10841   "
10842 {
10843   /* Take care of the possibility that operands[1] might be negative but
10844      this might be a logical operation.  That insn doesn't exist.  */
10845   if (GET_CODE (operands[1]) == CONST_INT
10846       && INTVAL (operands[1]) < 0)
10847     operands[1] = force_reg (SImode, operands[1]);
10848
10849   rs6000_compare_op0 = operands[0];
10850   rs6000_compare_op1 = operands[1];
10851   rs6000_compare_fp_p = 0;
10852   DONE;
10853 }")
10854
10855 (define_expand "cmpdi"
10856   [(set (cc0)
10857         (compare (match_operand:DI 0 "gpc_reg_operand" "")
10858                  (match_operand:DI 1 "reg_or_short_operand" "")))]
10859   "TARGET_POWERPC64"
10860   "
10861 {
10862   /* Take care of the possibility that operands[1] might be negative but
10863      this might be a logical operation.  That insn doesn't exist.  */
10864   if (GET_CODE (operands[1]) == CONST_INT
10865       && INTVAL (operands[1]) < 0)
10866     operands[1] = force_reg (DImode, operands[1]);
10867
10868   rs6000_compare_op0 = operands[0];
10869   rs6000_compare_op1 = operands[1];
10870   rs6000_compare_fp_p = 0;
10871   DONE;
10872 }")
10873
10874 (define_expand "cmpsf"
10875   [(set (cc0) (compare (match_operand:SF 0 "gpc_reg_operand" "")
10876                        (match_operand:SF 1 "gpc_reg_operand" "")))]
10877   "TARGET_HARD_FLOAT"
10878   "
10879 {
10880   rs6000_compare_op0 = operands[0];
10881   rs6000_compare_op1 = operands[1];
10882   rs6000_compare_fp_p = 1;
10883   DONE;
10884 }")
10885
10886 (define_expand "cmpdf"
10887   [(set (cc0) (compare (match_operand:DF 0 "gpc_reg_operand" "")
10888                        (match_operand:DF 1 "gpc_reg_operand" "")))]
10889   "TARGET_HARD_FLOAT && TARGET_FPRS"
10890   "
10891 {
10892   rs6000_compare_op0 = operands[0];
10893   rs6000_compare_op1 = operands[1];
10894   rs6000_compare_fp_p = 1;
10895   DONE;
10896 }")
10897
10898 (define_expand "cmptf"
10899   [(set (cc0) (compare (match_operand:TF 0 "gpc_reg_operand" "")
10900                        (match_operand:TF 1 "gpc_reg_operand" "")))]
10901   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
10902    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
10903   "
10904 {
10905   rs6000_compare_op0 = operands[0];
10906   rs6000_compare_op1 = operands[1];
10907   rs6000_compare_fp_p = 1;
10908   DONE;
10909 }")
10910
10911 (define_expand "beq"
10912   [(use (match_operand 0 "" ""))]
10913   ""
10914   "{ rs6000_emit_cbranch (EQ, operands[0]); DONE; }")
10915
10916 (define_expand "bne"
10917   [(use (match_operand 0 "" ""))]
10918   ""
10919   "{ rs6000_emit_cbranch (NE, operands[0]); DONE; }")
10920
10921 (define_expand "bge"
10922   [(use (match_operand 0 "" ""))]
10923   ""
10924   "{ rs6000_emit_cbranch (GE, operands[0]); DONE; }")
10925
10926 (define_expand "bgt"
10927   [(use (match_operand 0 "" ""))]
10928   ""
10929   "{ rs6000_emit_cbranch (GT, operands[0]); DONE; }")
10930
10931 (define_expand "ble"
10932   [(use (match_operand 0 "" ""))]
10933   ""
10934   "{ rs6000_emit_cbranch (LE, operands[0]); DONE; }")
10935
10936 (define_expand "blt"
10937   [(use (match_operand 0 "" ""))]
10938   ""
10939   "{ rs6000_emit_cbranch (LT, operands[0]); DONE; }")
10940
10941 (define_expand "bgeu"
10942   [(use (match_operand 0 "" ""))]
10943   ""
10944   "{ rs6000_emit_cbranch (GEU, operands[0]); DONE; }")
10945
10946 (define_expand "bgtu"
10947   [(use (match_operand 0 "" ""))]
10948   ""
10949   "{ rs6000_emit_cbranch (GTU, operands[0]); DONE; }")
10950
10951 (define_expand "bleu"
10952   [(use (match_operand 0 "" ""))]
10953   ""
10954   "{ rs6000_emit_cbranch (LEU, operands[0]); DONE; }")
10955
10956 (define_expand "bltu"
10957   [(use (match_operand 0 "" ""))]
10958   ""
10959   "{ rs6000_emit_cbranch (LTU, operands[0]); DONE; }")
10960
10961 (define_expand "bunordered"
10962   [(use (match_operand 0 "" ""))]
10963   ""
10964   "{ rs6000_emit_cbranch (UNORDERED, operands[0]); DONE; }")
10965
10966 (define_expand "bordered"
10967   [(use (match_operand 0 "" ""))]
10968   ""
10969   "{ rs6000_emit_cbranch (ORDERED, operands[0]); DONE; }")
10970
10971 (define_expand "buneq"
10972   [(use (match_operand 0 "" ""))]
10973   ""
10974   "{ rs6000_emit_cbranch (UNEQ, operands[0]); DONE; }")
10975
10976 (define_expand "bunge"
10977   [(use (match_operand 0 "" ""))]
10978   ""
10979   "{ rs6000_emit_cbranch (UNGE, operands[0]); DONE; }")
10980
10981 (define_expand "bungt"
10982   [(use (match_operand 0 "" ""))]
10983   ""
10984   "{ rs6000_emit_cbranch (UNGT, operands[0]); DONE; }")
10985
10986 (define_expand "bunle"
10987   [(use (match_operand 0 "" ""))]
10988   ""
10989   "{ rs6000_emit_cbranch (UNLE, operands[0]); DONE; }")
10990
10991 (define_expand "bunlt"
10992   [(use (match_operand 0 "" ""))]
10993   ""
10994   "{ rs6000_emit_cbranch (UNLT, operands[0]); DONE; }")
10995
10996 (define_expand "bltgt"
10997   [(use (match_operand 0 "" ""))]
10998   ""
10999   "{ rs6000_emit_cbranch (LTGT, operands[0]); DONE; }")
11000
11001 ;; For SNE, we would prefer that the xor/abs sequence be used for integers.
11002 ;; For SEQ, likewise, except that comparisons with zero should be done
11003 ;; with an scc insns.  However, due to the order that combine see the
11004 ;; resulting insns, we must, in fact, allow SEQ for integers.  Fail in
11005 ;; the cases we don't want to handle.
11006 (define_expand "seq"
11007   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11008   ""
11009   "{ rs6000_emit_sCOND (EQ, operands[0]); DONE; }")
11010
11011 (define_expand "sne"
11012   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11013   ""
11014   "
11015 {
11016   if (! rs6000_compare_fp_p)
11017     FAIL;
11018
11019   rs6000_emit_sCOND (NE, operands[0]);
11020   DONE;
11021 }")
11022
11023 ;; A >= 0 is best done the portable way for A an integer.
11024 (define_expand "sge"
11025   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11026   ""
11027   "
11028 {
11029   if (! rs6000_compare_fp_p
11030       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
11031     FAIL;
11032
11033   rs6000_emit_sCOND (GE, operands[0]);
11034   DONE;
11035 }")
11036
11037 ;; A > 0 is best done using the portable sequence, so fail in that case.
11038 (define_expand "sgt"
11039   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11040   ""
11041   "
11042 {
11043   if (! rs6000_compare_fp_p
11044       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
11045     FAIL;
11046
11047   rs6000_emit_sCOND (GT, operands[0]);
11048   DONE;
11049 }")
11050
11051 ;; A <= 0 is best done the portable way for A an integer.
11052 (define_expand "sle"
11053   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11054   ""
11055   "
11056 {
11057   if (! rs6000_compare_fp_p
11058       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
11059     FAIL;
11060
11061   rs6000_emit_sCOND (LE, operands[0]);
11062   DONE;
11063 }")
11064
11065 ;; A < 0 is best done in the portable way for A an integer.
11066 (define_expand "slt"
11067   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11068   ""
11069   "
11070 {
11071   if (! rs6000_compare_fp_p
11072       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
11073     FAIL;
11074
11075   rs6000_emit_sCOND (LT, operands[0]);
11076   DONE;
11077 }")
11078
11079 (define_expand "sgeu"
11080   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11081   ""
11082   "{ rs6000_emit_sCOND (GEU, operands[0]); DONE; }")
11083
11084 (define_expand "sgtu"
11085   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11086   ""
11087   "{ rs6000_emit_sCOND (GTU, operands[0]); DONE; }")
11088
11089 (define_expand "sleu"
11090   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11091   ""
11092   "{ rs6000_emit_sCOND (LEU, operands[0]); DONE; }")
11093
11094 (define_expand "sltu"
11095   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11096   ""
11097   "{ rs6000_emit_sCOND (LTU, operands[0]); DONE; }")
11098
11099 (define_expand "sunordered"
11100   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11101   ""
11102   "{ rs6000_emit_sCOND (UNORDERED, operands[0]); DONE; }")
11103
11104 (define_expand "sordered"
11105   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11106   ""
11107   "{ rs6000_emit_sCOND (ORDERED, operands[0]); DONE; }")
11108
11109 (define_expand "suneq"
11110   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11111   ""
11112   "{ rs6000_emit_sCOND (UNEQ, operands[0]); DONE; }")
11113
11114 (define_expand "sunge"
11115   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11116   ""
11117   "{ rs6000_emit_sCOND (UNGE, operands[0]); DONE; }")
11118
11119 (define_expand "sungt"
11120   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11121   ""
11122   "{ rs6000_emit_sCOND (UNGT, operands[0]); DONE; }")
11123
11124 (define_expand "sunle"
11125   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11126   ""
11127   "{ rs6000_emit_sCOND (UNLE, operands[0]); DONE; }")
11128
11129 (define_expand "sunlt"
11130   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11131   ""
11132   "{ rs6000_emit_sCOND (UNLT, operands[0]); DONE; }")
11133
11134 (define_expand "sltgt"
11135   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11136   ""
11137   "{ rs6000_emit_sCOND (LTGT, operands[0]); DONE; }")
11138
11139 \f
11140 ;; Here are the actual compare insns.
11141 (define_insn "*cmpsi_internal1"
11142   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11143         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11144                     (match_operand:SI 2 "reg_or_short_operand" "rI")))]
11145   ""
11146   "{cmp%I2|cmpw%I2} %0,%1,%2"
11147   [(set_attr "type" "cmp")])
11148
11149 (define_insn "*cmpdi_internal1"
11150   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11151         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "r")
11152                     (match_operand:DI 2 "reg_or_short_operand" "rI")))]
11153   "TARGET_POWERPC64"
11154   "cmpd%I2 %0,%1,%2"
11155   [(set_attr "type" "cmp")])
11156
11157 ;; If we are comparing a register for equality with a large constant,
11158 ;; we can do this with an XOR followed by a compare.  But we need a scratch
11159 ;; register for the result of the XOR.
11160
11161 (define_split
11162   [(set (match_operand:CC 0 "cc_reg_operand" "")
11163         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11164                     (match_operand:SI 2 "non_short_cint_operand" "")))
11165    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
11166   "find_single_use (operands[0], insn, 0)
11167    && (GET_CODE (*find_single_use (operands[0], insn, 0)) == EQ
11168        || GET_CODE (*find_single_use (operands[0], insn, 0)) == NE)"
11169   [(set (match_dup 3) (xor:SI (match_dup 1) (match_dup 4)))
11170    (set (match_dup 0) (compare:CC (match_dup 3) (match_dup 5)))]
11171   "
11172 {
11173   /* Get the constant we are comparing against, C,  and see what it looks like
11174      sign-extended to 16 bits.  Then see what constant could be XOR'ed
11175      with C to get the sign-extended value.  */
11176
11177   HOST_WIDE_INT c = INTVAL (operands[2]);
11178   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
11179   HOST_WIDE_INT xorv = c ^ sextc;
11180
11181   operands[4] = GEN_INT (xorv);
11182   operands[5] = GEN_INT (sextc);
11183 }")
11184
11185 (define_insn "*cmpsi_internal2"
11186   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11187         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11188                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
11189   ""
11190   "{cmpl%I2|cmplw%I2} %0,%1,%b2"
11191   [(set_attr "type" "cmp")])
11192
11193 (define_insn "*cmpdi_internal2"
11194   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11195         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
11196                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
11197   ""
11198   "cmpld%I2 %0,%1,%b2"
11199   [(set_attr "type" "cmp")])
11200
11201 ;; The following two insns don't exist as single insns, but if we provide
11202 ;; them, we can swap an add and compare, which will enable us to overlap more
11203 ;; of the required delay between a compare and branch.  We generate code for
11204 ;; them by splitting.
11205
11206 (define_insn ""
11207   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
11208         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11209                     (match_operand:SI 2 "short_cint_operand" "i")))
11210    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11211         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11212   ""
11213   "#"
11214   [(set_attr "length" "8")])
11215
11216 (define_insn ""
11217   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
11218         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11219                        (match_operand:SI 2 "u_short_cint_operand" "i")))
11220    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11221         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11222   ""
11223   "#"
11224   [(set_attr "length" "8")])
11225
11226 (define_split
11227   [(set (match_operand:CC 3 "cc_reg_operand" "")
11228         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11229                     (match_operand:SI 2 "short_cint_operand" "")))
11230    (set (match_operand:SI 0 "gpc_reg_operand" "")
11231         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11232   ""
11233   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
11234    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11235
11236 (define_split
11237   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
11238         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
11239                        (match_operand:SI 2 "u_short_cint_operand" "")))
11240    (set (match_operand:SI 0 "gpc_reg_operand" "")
11241         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11242   ""
11243   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
11244    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11245
11246 (define_insn "*cmpsf_internal1"
11247   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11248         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
11249                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
11250   "TARGET_HARD_FLOAT && TARGET_FPRS"
11251   "fcmpu %0,%1,%2"
11252   [(set_attr "type" "fpcompare")])
11253
11254 (define_insn "*cmpdf_internal1"
11255   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11256         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "f")
11257                       (match_operand:DF 2 "gpc_reg_operand" "f")))]
11258   "TARGET_HARD_FLOAT && TARGET_FPRS"
11259   "fcmpu %0,%1,%2"
11260   [(set_attr "type" "fpcompare")])
11261
11262 ;; Only need to compare second words if first words equal
11263 (define_insn "*cmptf_internal1"
11264   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11265         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11266                       (match_operand:TF 2 "gpc_reg_operand" "f")))]
11267   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
11268    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
11269   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
11270   [(set_attr "type" "fpcompare")
11271    (set_attr "length" "12")])
11272 \f
11273 ;; Now we have the scc insns.  We can do some combinations because of the
11274 ;; way the machine works.
11275 ;;
11276 ;; Note that this is probably faster if we can put an insn between the
11277 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
11278 ;; cases the insns below which don't use an intermediate CR field will
11279 ;; be used instead.
11280 (define_insn ""
11281   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11282         (match_operator:SI 1 "scc_comparison_operator"
11283                            [(match_operand 2 "cc_reg_operand" "y")
11284                             (const_int 0)]))]
11285   ""
11286   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11287   [(set (attr "type")
11288      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11289                 (const_string "mfcrf")
11290            ]
11291         (const_string "mfcr")))
11292    (set_attr "length" "12")])
11293
11294 ;; Same as above, but get the GT bit.
11295 (define_insn "move_from_CR_gt_bit"
11296   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11297         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
11298   "TARGET_E500"
11299   "mfcr %0\;{rlinm|rlwinm} %0,%0,%D1,1"
11300   [(set_attr "type" "mfcr")
11301    (set_attr "length" "12")])
11302
11303 ;; Same as above, but get the OV/ORDERED bit.
11304 (define_insn "move_from_CR_ov_bit"
11305   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11306         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_OV))]
11307   "TARGET_ISEL"
11308   "mfcr %0\;{rlinm|rlwinm} %0,%0,%t1,1"
11309   [(set_attr "type" "mfcr")
11310    (set_attr "length" "12")])
11311
11312 (define_insn ""
11313   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11314         (match_operator:DI 1 "scc_comparison_operator"
11315                            [(match_operand 2 "cc_reg_operand" "y")
11316                             (const_int 0)]))]
11317   "TARGET_POWERPC64"
11318   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11319   [(set (attr "type")
11320      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11321                 (const_string "mfcrf")
11322            ]
11323         (const_string "mfcr")))
11324    (set_attr "length" "12")])
11325
11326 (define_insn ""
11327   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11328         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11329                                        [(match_operand 2 "cc_reg_operand" "y,y")
11330                                         (const_int 0)])
11331                     (const_int 0)))
11332    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11333         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11334   "TARGET_32BIT"
11335   "@
11336    mfcr %3%Q2\;{rlinm.|rlwinm.} %3,%3,%J1,1
11337    #"
11338   [(set_attr "type" "delayed_compare")
11339    (set_attr "length" "12,16")])
11340
11341 (define_split
11342   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11343         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11344                                        [(match_operand 2 "cc_reg_operand" "")
11345                                         (const_int 0)])
11346                     (const_int 0)))
11347    (set (match_operand:SI 3 "gpc_reg_operand" "")
11348         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11349   "TARGET_32BIT && reload_completed"
11350   [(set (match_dup 3)
11351         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
11352    (set (match_dup 0)
11353         (compare:CC (match_dup 3)
11354                     (const_int 0)))]
11355   "")
11356
11357 (define_insn ""
11358   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11359         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11360                                       [(match_operand 2 "cc_reg_operand" "y")
11361                                        (const_int 0)])
11362                    (match_operand:SI 3 "const_int_operand" "n")))]
11363   ""
11364   "*
11365 {
11366   int is_bit = ccr_bit (operands[1], 1);
11367   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11368   int count;
11369
11370   if (is_bit >= put_bit)
11371     count = is_bit - put_bit;
11372   else
11373     count = 32 - (put_bit - is_bit);
11374
11375   operands[4] = GEN_INT (count);
11376   operands[5] = GEN_INT (put_bit);
11377
11378   return \"mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
11379 }"
11380   [(set (attr "type")
11381      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11382                 (const_string "mfcrf")
11383            ]
11384         (const_string "mfcr")))
11385    (set_attr "length" "12")])
11386
11387 (define_insn ""
11388   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11389         (compare:CC
11390          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11391                                        [(match_operand 2 "cc_reg_operand" "y,y")
11392                                         (const_int 0)])
11393                     (match_operand:SI 3 "const_int_operand" "n,n"))
11394          (const_int 0)))
11395    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
11396         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11397                    (match_dup 3)))]
11398   ""
11399   "*
11400 {
11401   int is_bit = ccr_bit (operands[1], 1);
11402   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11403   int count;
11404
11405   /* Force split for non-cc0 compare.  */
11406   if (which_alternative == 1)
11407      return \"#\";
11408
11409   if (is_bit >= put_bit)
11410     count = is_bit - put_bit;
11411   else
11412     count = 32 - (put_bit - is_bit);
11413
11414   operands[5] = GEN_INT (count);
11415   operands[6] = GEN_INT (put_bit);
11416
11417   return \"mfcr %4%Q2\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
11418 }"
11419   [(set_attr "type" "delayed_compare")
11420    (set_attr "length" "12,16")])
11421
11422 (define_split
11423   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11424         (compare:CC
11425          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11426                                        [(match_operand 2 "cc_reg_operand" "")
11427                                         (const_int 0)])
11428                     (match_operand:SI 3 "const_int_operand" ""))
11429          (const_int 0)))
11430    (set (match_operand:SI 4 "gpc_reg_operand" "")
11431         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11432                    (match_dup 3)))]
11433   "reload_completed"
11434   [(set (match_dup 4)
11435         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11436                    (match_dup 3)))
11437    (set (match_dup 0)
11438         (compare:CC (match_dup 4)
11439                     (const_int 0)))]
11440   "")
11441
11442 ;; There is a 3 cycle delay between consecutive mfcr instructions
11443 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
11444
11445 (define_peephole
11446   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11447         (match_operator:SI 1 "scc_comparison_operator"
11448                            [(match_operand 2 "cc_reg_operand" "y")
11449                             (const_int 0)]))
11450    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
11451         (match_operator:SI 4 "scc_comparison_operator"
11452                            [(match_operand 5 "cc_reg_operand" "y")
11453                             (const_int 0)]))]
11454   "REGNO (operands[2]) != REGNO (operands[5])"
11455   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11456   [(set_attr "type" "mfcr")
11457    (set_attr "length" "20")])
11458
11459 (define_peephole
11460   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11461         (match_operator:DI 1 "scc_comparison_operator"
11462                            [(match_operand 2 "cc_reg_operand" "y")
11463                             (const_int 0)]))
11464    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
11465         (match_operator:DI 4 "scc_comparison_operator"
11466                            [(match_operand 5 "cc_reg_operand" "y")
11467                             (const_int 0)]))]
11468   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
11469   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11470   [(set_attr "type" "mfcr")
11471    (set_attr "length" "20")])
11472
11473 ;; There are some scc insns that can be done directly, without a compare.
11474 ;; These are faster because they don't involve the communications between
11475 ;; the FXU and branch units.   In fact, we will be replacing all of the
11476 ;; integer scc insns here or in the portable methods in emit_store_flag.
11477 ;;
11478 ;; Also support (neg (scc ..)) since that construct is used to replace
11479 ;; branches, (plus (scc ..) ..) since that construct is common and
11480 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
11481 ;; cases where it is no more expensive than (neg (scc ..)).
11482
11483 ;; Have reload force a constant into a register for the simple insns that
11484 ;; otherwise won't accept constants.  We do this because it is faster than
11485 ;; the cmp/mfcr sequence we would otherwise generate.
11486
11487 (define_insn ""
11488   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
11489         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11490                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I")))
11491    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
11492   "TARGET_32BIT"
11493   "@
11494    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11495    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
11496    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11497    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11498    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
11499   [(set_attr "length" "12,8,12,12,12")])
11500
11501 (define_insn ""
11502   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r")
11503         (eq:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r")
11504                (match_operand:DI 2 "reg_or_cint_operand" "r,O,K,J,I")))
11505    (clobber (match_scratch:DI 3 "=r,&r,r,r,r"))]
11506   "TARGET_64BIT"
11507   "@
11508    xor %0,%1,%2\;subfic %3,%0,0\;adde %0,%3,%0
11509    subfic %3,%1,0\;adde %0,%3,%1
11510    xori %0,%1,%b2\;subfic %3,%0,0\;adde %0,%3,%0
11511    xoris %0,%1,%u2\;subfic %3,%0,0\;adde %0,%3,%0
11512    subfic %0,%1,%2\;subfic %3,%0,0\;adde %0,%3,%0"
11513   [(set_attr "length" "12,8,12,12,12")])
11514
11515 (define_insn ""
11516   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11517         (compare:CC
11518          (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11519                 (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11520          (const_int 0)))
11521    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
11522         (eq:SI (match_dup 1) (match_dup 2)))
11523    (clobber (match_scratch:SI 3 "=r,&r,r,r,r,r,&r,r,r,r"))]
11524   "TARGET_32BIT"
11525   "@
11526    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11527    {sfi|subfic} %3,%1,0\;{ae.|adde.} %0,%3,%1
11528    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11529    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11530    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11531    #
11532    #
11533    #
11534    #
11535    #"
11536   [(set_attr "type" "compare")
11537    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11538
11539 (define_split
11540   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11541         (compare:CC
11542          (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11543                 (match_operand:SI 2 "reg_or_cint_operand" ""))
11544          (const_int 0)))
11545    (set (match_operand:SI 0 "gpc_reg_operand" "")
11546         (eq:SI (match_dup 1) (match_dup 2)))
11547    (clobber (match_scratch:SI 3 ""))]
11548   "TARGET_32BIT && reload_completed"
11549   [(parallel [(set (match_dup 0)
11550         (eq:SI (match_dup 1) (match_dup 2)))
11551    (clobber (match_dup 3))])
11552    (set (match_dup 4)
11553         (compare:CC (match_dup 0)
11554                     (const_int 0)))]
11555   "")
11556
11557 (define_insn ""
11558   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11559         (compare:CC
11560          (eq:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11561                 (match_operand:DI 2 "reg_or_cint_operand" "r,O,K,J,I,r,O,K,J,I"))
11562          (const_int 0)))
11563    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
11564         (eq:DI (match_dup 1) (match_dup 2)))
11565    (clobber (match_scratch:DI 3 "=r,&r,r,r,r,r,&r,r,r,r"))]
11566   "TARGET_64BIT"
11567   "@
11568    xor %0,%1,%2\;subfic %3,%0,0\;adde. %0,%3,%0
11569    subfic %3,%1,0\;adde. %0,%3,%1
11570    xori %0,%1,%b2\;subfic %3,%0,0\;adde. %0,%3,%0
11571    xoris %0,%1,%u2\;subfic %3,%0,0\;adde. %0,%3,%0
11572    subfic %0,%1,%2\;subfic %3,%0,0\;adde. %0,%3,%0
11573    #
11574    #
11575    #
11576    #
11577    #"
11578   [(set_attr "type" "compare")
11579    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11580
11581 (define_split
11582   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11583         (compare:CC
11584          (eq:DI (match_operand:DI 1 "gpc_reg_operand" "")
11585                 (match_operand:DI 2 "reg_or_cint_operand" ""))
11586          (const_int 0)))
11587    (set (match_operand:DI 0 "gpc_reg_operand" "")
11588         (eq:DI (match_dup 1) (match_dup 2)))
11589    (clobber (match_scratch:DI 3 ""))]
11590   "TARGET_64BIT && reload_completed"
11591   [(parallel [(set (match_dup 0)
11592         (eq:DI (match_dup 1) (match_dup 2)))
11593    (clobber (match_dup 3))])
11594    (set (match_dup 4)
11595         (compare:CC (match_dup 0)
11596                     (const_int 0)))]
11597   "")
11598
11599 ;; We have insns of the form shown by the first define_insn below.  If
11600 ;; there is something inside the comparison operation, we must split it.
11601 (define_split
11602   [(set (match_operand:SI 0 "gpc_reg_operand" "")
11603         (plus:SI (match_operator 1 "comparison_operator"
11604                                  [(match_operand:SI 2 "" "")
11605                                   (match_operand:SI 3
11606                                                     "reg_or_cint_operand" "")])
11607                  (match_operand:SI 4 "gpc_reg_operand" "")))
11608    (clobber (match_operand:SI 5 "register_operand" ""))]
11609   "! gpc_reg_operand (operands[2], SImode)"
11610   [(set (match_dup 5) (match_dup 2))
11611    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
11612                                (match_dup 4)))])
11613
11614 (define_insn ""
11615   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
11616         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11617                         (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I"))
11618                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
11619   "TARGET_32BIT"
11620   "@
11621    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11622    {sfi|subfic} %0,%1,0\;{aze|addze} %0,%3
11623    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11624    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11625    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
11626   [(set_attr "length" "12,8,12,12,12")])
11627
11628 (define_insn ""
11629   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11630         (compare:CC
11631          (plus:SI
11632           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11633                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11634           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11635          (const_int 0)))
11636    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
11637   "TARGET_32BIT"
11638   "@
11639    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11640    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
11641    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11642    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11643    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11644    #
11645    #
11646    #
11647    #
11648    #"
11649   [(set_attr "type" "compare")
11650    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11651
11652 (define_split
11653   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11654         (compare:CC
11655          (plus:SI
11656           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11657                  (match_operand:SI 2 "reg_or_cint_operand" ""))
11658           (match_operand:SI 3 "gpc_reg_operand" ""))
11659          (const_int 0)))
11660    (clobber (match_scratch:SI 4 ""))]
11661   "TARGET_32BIT && reload_completed"
11662   [(set (match_dup 4)
11663         (plus:SI (eq:SI (match_dup 1)
11664                  (match_dup 2))
11665           (match_dup 3)))
11666    (set (match_dup 0)
11667         (compare:CC (match_dup 4)
11668                     (const_int 0)))]
11669   "")
11670
11671 (define_insn ""
11672   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11673         (compare:CC
11674          (plus:SI
11675           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11676                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11677           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11678          (const_int 0)))
11679    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
11680         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11681   "TARGET_32BIT"
11682   "@
11683    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11684    {sfi|subfic} %0,%1,0\;{aze.|addze.} %0,%3
11685    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11686    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11687    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11688    #
11689    #
11690    #
11691    #
11692    #"
11693   [(set_attr "type" "compare")
11694    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11695
11696 (define_split
11697   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11698         (compare:CC
11699          (plus:SI
11700           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11701                  (match_operand:SI 2 "reg_or_cint_operand" ""))
11702           (match_operand:SI 3 "gpc_reg_operand" ""))
11703          (const_int 0)))
11704    (set (match_operand:SI 0 "gpc_reg_operand" "")
11705         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11706   "TARGET_32BIT && reload_completed"
11707   [(set (match_dup 0)
11708         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
11709    (set (match_dup 4)
11710         (compare:CC (match_dup 0)
11711                     (const_int 0)))]
11712   "")
11713
11714 (define_insn ""
11715   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
11716         (neg:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11717                        (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I"))))]
11718   "TARGET_32BIT"
11719   "@
11720    xor %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11721    {ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0
11722    {xoril|xori} %0,%1,%b2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11723    {xoriu|xoris} %0,%1,%u2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11724    {sfi|subfic} %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
11725    [(set_attr "length" "12,8,12,12,12")])
11726
11727 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
11728 ;; since it nabs/sr is just as fast.
11729 (define_insn "*ne0"
11730   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
11731         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
11732                      (const_int 31)))
11733    (clobber (match_scratch:SI 2 "=&r"))]
11734   "! TARGET_POWER && TARGET_32BIT && !TARGET_ISEL"
11735   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
11736   [(set_attr "length" "8")])
11737
11738 (define_insn ""
11739   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11740         (lshiftrt:DI (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
11741                      (const_int 63)))
11742    (clobber (match_scratch:DI 2 "=&r"))]
11743   "TARGET_64BIT"
11744   "addic %2,%1,-1\;subfe %0,%2,%1"
11745   [(set_attr "length" "8")])
11746
11747 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
11748 (define_insn ""
11749   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11750         (plus:SI (lshiftrt:SI
11751                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
11752                   (const_int 31))
11753                  (match_operand:SI 2 "gpc_reg_operand" "r")))
11754    (clobber (match_scratch:SI 3 "=&r"))]
11755   "TARGET_32BIT"
11756   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
11757   [(set_attr "length" "8")])
11758
11759 (define_insn ""
11760   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11761         (plus:DI (lshiftrt:DI
11762                   (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
11763                   (const_int 63))
11764                  (match_operand:DI 2 "gpc_reg_operand" "r")))
11765    (clobber (match_scratch:DI 3 "=&r"))]
11766   "TARGET_64BIT"
11767   "addic %3,%1,-1\;addze %0,%2"
11768   [(set_attr "length" "8")])
11769
11770 (define_insn ""
11771   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11772         (compare:CC
11773          (plus:SI (lshiftrt:SI
11774                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
11775                    (const_int 31))
11776                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
11777          (const_int 0)))
11778    (clobber (match_scratch:SI 3 "=&r,&r"))
11779    (clobber (match_scratch:SI 4 "=X,&r"))]
11780   "TARGET_32BIT"
11781   "@
11782    {ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2
11783    #"
11784   [(set_attr "type" "compare")
11785    (set_attr "length" "8,12")])
11786
11787 (define_split
11788   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11789         (compare:CC
11790          (plus:SI (lshiftrt:SI
11791                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11792                    (const_int 31))
11793                   (match_operand:SI 2 "gpc_reg_operand" ""))
11794          (const_int 0)))
11795    (clobber (match_scratch:SI 3 ""))
11796    (clobber (match_scratch:SI 4 ""))]
11797   "TARGET_32BIT && reload_completed"
11798   [(parallel [(set (match_dup 3)
11799                    (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1)))
11800                                          (const_int 31))
11801                             (match_dup 2)))
11802               (clobber (match_dup 4))])
11803    (set (match_dup 0)
11804         (compare:CC (match_dup 3)
11805                     (const_int 0)))]
11806   "")
11807
11808 (define_insn ""
11809   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11810         (compare:CC
11811          (plus:DI (lshiftrt:DI
11812                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
11813                    (const_int 63))
11814                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
11815          (const_int 0)))
11816    (clobber (match_scratch:DI 3 "=&r,&r"))]
11817   "TARGET_64BIT"
11818   "@
11819    addic %3,%1,-1\;addze. %3,%2
11820    #"
11821   [(set_attr "type" "compare")
11822    (set_attr "length" "8,12")])
11823
11824 (define_split
11825   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11826         (compare:CC
11827          (plus:DI (lshiftrt:DI
11828                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
11829                    (const_int 63))
11830                   (match_operand:DI 2 "gpc_reg_operand" ""))
11831          (const_int 0)))
11832    (clobber (match_scratch:DI 3 ""))]
11833   "TARGET_64BIT && reload_completed"
11834   [(set (match_dup 3)
11835         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1)))
11836                    (const_int 63))
11837                   (match_dup 2)))
11838    (set (match_dup 0)
11839         (compare:CC (match_dup 3)
11840                     (const_int 0)))]
11841   "")
11842
11843 (define_insn ""
11844   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
11845         (compare:CC
11846          (plus:SI (lshiftrt:SI
11847                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
11848                    (const_int 31))
11849                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
11850          (const_int 0)))
11851    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11852         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11853                  (match_dup 2)))
11854    (clobber (match_scratch:SI 3 "=&r,&r"))]
11855   "TARGET_32BIT"
11856   "@
11857    {ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2
11858    #"
11859   [(set_attr "type" "compare")
11860    (set_attr "length" "8,12")])
11861
11862 (define_split
11863   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11864         (compare:CC
11865          (plus:SI (lshiftrt:SI
11866                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11867                    (const_int 31))
11868                   (match_operand:SI 2 "gpc_reg_operand" ""))
11869          (const_int 0)))
11870    (set (match_operand:SI 0 "gpc_reg_operand" "")
11871         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11872                  (match_dup 2)))
11873    (clobber (match_scratch:SI 3 ""))]
11874   "TARGET_32BIT && reload_completed"
11875   [(parallel [(set (match_dup 0)
11876         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11877                  (match_dup 2)))
11878    (clobber (match_dup 3))])
11879    (set (match_dup 4)
11880         (compare:CC (match_dup 0)
11881                     (const_int 0)))]
11882   "")
11883
11884 (define_insn ""
11885   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
11886         (compare:CC
11887          (plus:DI (lshiftrt:DI
11888                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
11889                    (const_int 63))
11890                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
11891          (const_int 0)))
11892    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
11893         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11894                  (match_dup 2)))
11895    (clobber (match_scratch:DI 3 "=&r,&r"))]
11896   "TARGET_64BIT"
11897   "@
11898    addic %3,%1,-1\;addze. %0,%2
11899    #"
11900   [(set_attr "type" "compare")
11901    (set_attr "length" "8,12")])
11902
11903 (define_split
11904   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11905         (compare:CC
11906          (plus:DI (lshiftrt:DI
11907                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
11908                    (const_int 63))
11909                   (match_operand:DI 2 "gpc_reg_operand" ""))
11910          (const_int 0)))
11911    (set (match_operand:DI 0 "gpc_reg_operand" "")
11912         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11913                  (match_dup 2)))
11914    (clobber (match_scratch:DI 3 ""))]
11915   "TARGET_64BIT && reload_completed"
11916   [(parallel [(set (match_dup 0)
11917         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11918                  (match_dup 2)))
11919    (clobber (match_dup 3))])
11920    (set (match_dup 4)
11921         (compare:CC (match_dup 0)
11922                     (const_int 0)))]
11923   "")
11924
11925 (define_insn ""
11926   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11927         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
11928                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
11929    (clobber (match_scratch:SI 3 "=r,X"))]
11930   "TARGET_POWER"
11931   "@
11932    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
11933    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
11934   [(set_attr "length" "12")])
11935
11936 (define_insn ""
11937   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
11938         (compare:CC
11939          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
11940                 (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
11941          (const_int 0)))
11942    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
11943         (le:SI (match_dup 1) (match_dup 2)))
11944    (clobber (match_scratch:SI 3 "=r,X,r,X"))]
11945   "TARGET_POWER"
11946   "@
11947    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
11948    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31
11949    #
11950    #"
11951   [(set_attr "type" "compare,delayed_compare,compare,delayed_compare")
11952    (set_attr "length" "12,12,16,16")])
11953
11954 (define_split
11955   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11956         (compare:CC
11957          (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
11958                 (match_operand:SI 2 "reg_or_short_operand" ""))
11959          (const_int 0)))
11960    (set (match_operand:SI 0 "gpc_reg_operand" "")
11961         (le:SI (match_dup 1) (match_dup 2)))
11962    (clobber (match_scratch:SI 3 ""))]
11963   "TARGET_POWER && reload_completed"
11964   [(parallel [(set (match_dup 0)
11965         (le:SI (match_dup 1) (match_dup 2)))
11966    (clobber (match_dup 3))])
11967    (set (match_dup 4)
11968         (compare:CC (match_dup 0)
11969                     (const_int 0)))]
11970   "")
11971
11972 (define_insn ""
11973   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
11974         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
11975                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
11976                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
11977   "TARGET_POWER"
11978   "@
11979    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11980    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze|addze} %0,%3"
11981   [(set_attr "length" "12")])
11982
11983 (define_insn ""
11984   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
11985         (compare:CC
11986          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
11987                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
11988                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
11989          (const_int 0)))
11990    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
11991   "TARGET_POWER"
11992   "@
11993    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11994    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3
11995    #
11996    #"
11997   [(set_attr "type" "compare")
11998    (set_attr "length" "12,12,16,16")])
11999
12000 (define_split
12001   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12002         (compare:CC
12003          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12004                          (match_operand:SI 2 "reg_or_short_operand" ""))
12005                   (match_operand:SI 3 "gpc_reg_operand" ""))
12006          (const_int 0)))
12007    (clobber (match_scratch:SI 4 ""))]
12008   "TARGET_POWER && reload_completed"
12009   [(set (match_dup 4)
12010         (plus:SI (le:SI (match_dup 1) (match_dup 2))
12011                  (match_dup 3)))
12012    (set (match_dup 0)
12013         (compare:CC (match_dup 4)
12014                     (const_int 0)))]
12015   "")
12016
12017 (define_insn ""
12018   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12019         (compare:CC
12020          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12021                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12022                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12023          (const_int 0)))
12024    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12025         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12026   "TARGET_POWER"
12027   "@
12028    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12029    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze.|addze.} %0,%3
12030    #
12031    #"
12032   [(set_attr "type" "compare")
12033    (set_attr "length" "12,12,16,16")])
12034
12035 (define_split
12036   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12037         (compare:CC
12038          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12039                          (match_operand:SI 2 "reg_or_short_operand" ""))
12040                   (match_operand:SI 3 "gpc_reg_operand" ""))
12041          (const_int 0)))
12042    (set (match_operand:SI 0 "gpc_reg_operand" "")
12043         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12044   "TARGET_POWER && reload_completed"
12045   [(set (match_dup 0)
12046         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12047    (set (match_dup 4)
12048         (compare:CC (match_dup 0)
12049                     (const_int 0)))]
12050   "")
12051
12052 (define_insn ""
12053   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12054         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12055                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
12056   "TARGET_POWER"
12057   "@
12058    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
12059    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
12060   [(set_attr "length" "12")])
12061
12062 (define_insn ""
12063   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12064         (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12065                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12066   "TARGET_32BIT"
12067   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12068   [(set_attr "length" "12")])
12069
12070 (define_insn ""
12071   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12072         (leu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
12073                 (match_operand:DI 2 "reg_or_short_operand" "rI")))]
12074   "TARGET_64BIT"
12075   "subf%I2c %0,%1,%2\;li %0,0\;adde %0,%0,%0"
12076   [(set_attr "length" "12")])
12077
12078 (define_insn ""
12079   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12080         (compare:CC
12081          (leu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12082                  (match_operand:DI 2 "reg_or_short_operand" "rI,rI"))
12083          (const_int 0)))
12084    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12085         (leu:DI (match_dup 1) (match_dup 2)))]
12086   "TARGET_64BIT"
12087   "@
12088    subf%I2c %0,%1,%2\;li %0,0\;adde. %0,%0,%0
12089    #"
12090   [(set_attr "type" "compare")
12091    (set_attr "length" "12,16")])
12092
12093 (define_split
12094   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12095         (compare:CC
12096          (leu:DI (match_operand:DI 1 "gpc_reg_operand" "")
12097                  (match_operand:DI 2 "reg_or_short_operand" ""))
12098          (const_int 0)))
12099    (set (match_operand:DI 0 "gpc_reg_operand" "")
12100         (leu:DI (match_dup 1) (match_dup 2)))]
12101   "TARGET_64BIT && reload_completed"
12102   [(set (match_dup 0)
12103         (leu:DI (match_dup 1) (match_dup 2)))
12104    (set (match_dup 3)
12105         (compare:CC (match_dup 0)
12106                     (const_int 0)))]
12107   "")
12108
12109 (define_insn ""
12110   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12111         (compare:CC
12112          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12113                  (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12114          (const_int 0)))
12115    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12116         (leu:SI (match_dup 1) (match_dup 2)))]
12117   "TARGET_32BIT"
12118   "@
12119    {sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12120    #"
12121   [(set_attr "type" "compare")
12122    (set_attr "length" "12,16")])
12123
12124 (define_split
12125   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12126         (compare:CC
12127          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12128                  (match_operand:SI 2 "reg_or_short_operand" ""))
12129          (const_int 0)))
12130    (set (match_operand:SI 0 "gpc_reg_operand" "")
12131         (leu:SI (match_dup 1) (match_dup 2)))]
12132   "TARGET_32BIT && reload_completed"
12133   [(set (match_dup 0)
12134         (leu:SI (match_dup 1) (match_dup 2)))
12135    (set (match_dup 3)
12136         (compare:CC (match_dup 0)
12137                     (const_int 0)))]
12138   "")
12139
12140 (define_insn ""
12141   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12142         (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12143                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
12144                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12145   "TARGET_32BIT"
12146   "{sf%I2|subf%I2c} %0,%1,%2\;{aze|addze} %0,%3"
12147   [(set_attr "length" "8")])
12148
12149 (define_insn ""
12150   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12151         (compare:CC
12152          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12153                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12154                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12155          (const_int 0)))
12156    (clobber (match_scratch:SI 4 "=&r,&r"))]
12157   "TARGET_32BIT"
12158   "@
12159    {sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3
12160    #"
12161   [(set_attr "type" "compare")
12162    (set_attr "length" "8,12")])
12163
12164 (define_split
12165   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12166         (compare:CC
12167          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12168                           (match_operand:SI 2 "reg_or_short_operand" ""))
12169                   (match_operand:SI 3 "gpc_reg_operand" ""))
12170          (const_int 0)))
12171    (clobber (match_scratch:SI 4 ""))]
12172   "TARGET_32BIT && reload_completed"
12173   [(set (match_dup 4)
12174         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
12175                   (match_dup 3)))
12176    (set (match_dup 0)
12177         (compare:CC (match_dup 4)
12178                     (const_int 0)))]
12179   "")
12180
12181 (define_insn ""
12182   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12183         (compare:CC
12184          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12185                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12186                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12187          (const_int 0)))
12188    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12189         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12190   "TARGET_32BIT"
12191   "@
12192    {sf%I2|subf%I2c} %0,%1,%2\;{aze.|addze.} %0,%3
12193    #"
12194   [(set_attr "type" "compare")
12195    (set_attr "length" "8,12")])
12196
12197 (define_split
12198   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12199         (compare:CC
12200          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12201                           (match_operand:SI 2 "reg_or_short_operand" ""))
12202                   (match_operand:SI 3 "gpc_reg_operand" ""))
12203          (const_int 0)))
12204    (set (match_operand:SI 0 "gpc_reg_operand" "")
12205         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12206   "TARGET_32BIT && reload_completed"
12207   [(set (match_dup 0)
12208         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12209    (set (match_dup 4)
12210         (compare:CC (match_dup 0)
12211                     (const_int 0)))]
12212   "")
12213
12214 (define_insn ""
12215   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12216         (neg:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12217                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12218   "TARGET_32BIT"
12219   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
12220    [(set_attr "length" "12")])
12221
12222 (define_insn ""
12223   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12224         (and:SI (neg:SI
12225                  (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12226                          (match_operand:SI 2 "reg_or_short_operand" "rI")))
12227                 (match_operand:SI 3 "gpc_reg_operand" "r")))]
12228   "TARGET_32BIT"
12229   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12230   [(set_attr "length" "12")])
12231
12232 (define_insn ""
12233   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12234         (compare:CC
12235          (and:SI (neg:SI
12236                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12237                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12238                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12239          (const_int 0)))
12240    (clobber (match_scratch:SI 4 "=&r,&r"))]
12241   "TARGET_32BIT"
12242   "@
12243    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12244    #"
12245   [(set_attr "type" "compare")
12246    (set_attr "length" "12,16")])
12247
12248 (define_split
12249   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12250         (compare:CC
12251          (and:SI (neg:SI
12252                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12253                           (match_operand:SI 2 "reg_or_short_operand" "")))
12254                  (match_operand:SI 3 "gpc_reg_operand" ""))
12255          (const_int 0)))
12256    (clobber (match_scratch:SI 4 ""))]
12257   "TARGET_32BIT && reload_completed"
12258   [(set (match_dup 4)
12259         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12260                 (match_dup 3)))
12261    (set (match_dup 0)
12262         (compare:CC (match_dup 4)
12263                     (const_int 0)))]
12264   "")
12265
12266 (define_insn ""
12267   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12268         (compare:CC
12269          (and:SI (neg:SI
12270                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12271                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12272                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12273          (const_int 0)))
12274    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12275         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12276   "TARGET_32BIT"
12277   "@
12278    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12279    #"
12280   [(set_attr "type" "compare")
12281    (set_attr "length" "12,16")])
12282
12283 (define_split
12284   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12285         (compare:CC
12286          (and:SI (neg:SI
12287                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12288                           (match_operand:SI 2 "reg_or_short_operand" "")))
12289                  (match_operand:SI 3 "gpc_reg_operand" ""))
12290          (const_int 0)))
12291    (set (match_operand:SI 0 "gpc_reg_operand" "")
12292         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12293   "TARGET_32BIT && reload_completed"
12294   [(set (match_dup 0)
12295         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12296                 (match_dup 3)))
12297    (set (match_dup 4)
12298         (compare:CC (match_dup 0)
12299                     (const_int 0)))]
12300   "")
12301
12302 (define_insn ""
12303   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12304         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12305                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12306   "TARGET_POWER"
12307   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
12308    [(set_attr "length" "12")])
12309
12310 (define_insn ""
12311   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12312         (compare:CC
12313          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12314                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12315          (const_int 0)))
12316    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12317         (lt:SI (match_dup 1) (match_dup 2)))]
12318   "TARGET_POWER"
12319   "@
12320    doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
12321    #"
12322   [(set_attr "type" "delayed_compare")
12323    (set_attr "length" "12,16")])
12324
12325 (define_split
12326   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12327         (compare:CC
12328          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12329                 (match_operand:SI 2 "reg_or_short_operand" ""))
12330          (const_int 0)))
12331    (set (match_operand:SI 0 "gpc_reg_operand" "")
12332         (lt:SI (match_dup 1) (match_dup 2)))]
12333   "TARGET_POWER && reload_completed"
12334   [(set (match_dup 0)
12335         (lt:SI (match_dup 1) (match_dup 2)))
12336    (set (match_dup 3)
12337         (compare:CC (match_dup 0)
12338                     (const_int 0)))]
12339   "")
12340
12341 (define_insn ""
12342   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12343         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12344                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12345                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12346   "TARGET_POWER"
12347   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
12348   [(set_attr "length" "12")])
12349
12350 (define_insn ""
12351   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12352         (compare:CC
12353          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12354                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12355                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12356          (const_int 0)))
12357    (clobber (match_scratch:SI 4 "=&r,&r"))]
12358   "TARGET_POWER"
12359   "@
12360    doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
12361    #"
12362   [(set_attr "type" "compare")
12363    (set_attr "length" "12,16")])
12364
12365 (define_split
12366   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12367         (compare:CC
12368          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12369                          (match_operand:SI 2 "reg_or_short_operand" ""))
12370                   (match_operand:SI 3 "gpc_reg_operand" ""))
12371          (const_int 0)))
12372    (clobber (match_scratch:SI 4 ""))]
12373   "TARGET_POWER && reload_completed"
12374   [(set (match_dup 4)
12375         (plus:SI (lt:SI (match_dup 1) (match_dup 2))
12376                  (match_dup 3)))
12377    (set (match_dup 0)
12378         (compare:CC (match_dup 4)
12379                     (const_int 0)))]
12380   "")
12381
12382 (define_insn ""
12383   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12384         (compare:CC
12385          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12386                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12387                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12388          (const_int 0)))
12389    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12390         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12391   "TARGET_POWER"
12392   "@
12393    doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
12394    #"
12395   [(set_attr "type" "compare")
12396    (set_attr "length" "12,16")])
12397
12398 (define_split
12399   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12400         (compare:CC
12401          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12402                          (match_operand:SI 2 "reg_or_short_operand" ""))
12403                   (match_operand:SI 3 "gpc_reg_operand" ""))
12404          (const_int 0)))
12405    (set (match_operand:SI 0 "gpc_reg_operand" "")
12406         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12407   "TARGET_POWER && reload_completed"
12408   [(set (match_dup 0)
12409         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12410    (set (match_dup 4)
12411         (compare:CC (match_dup 0)
12412                     (const_int 0)))]
12413   "")
12414
12415 (define_insn ""
12416   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12417         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12418                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12419   "TARGET_POWER"
12420   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
12421   [(set_attr "length" "12")])
12422
12423 (define_insn ""
12424   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12425         (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12426                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
12427   "TARGET_32BIT"
12428   "@
12429    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg %0,%0
12430    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg %0,%0"
12431   [(set_attr "length" "12")])
12432
12433 (define_insn ""
12434   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12435         (compare:CC
12436          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12437                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12438          (const_int 0)))
12439    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12440         (ltu:SI (match_dup 1) (match_dup 2)))]
12441   "TARGET_32BIT"
12442   "@
12443    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
12444    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
12445    #
12446    #"
12447   [(set_attr "type" "compare")
12448    (set_attr "length" "12,12,16,16")])
12449
12450 (define_split
12451   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12452         (compare:CC
12453          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12454                  (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12455          (const_int 0)))
12456    (set (match_operand:SI 0 "gpc_reg_operand" "")
12457         (ltu:SI (match_dup 1) (match_dup 2)))]
12458   "TARGET_32BIT && reload_completed"
12459   [(set (match_dup 0)
12460         (ltu:SI (match_dup 1) (match_dup 2)))
12461    (set (match_dup 3)
12462         (compare:CC (match_dup 0)
12463                     (const_int 0)))]
12464   "")
12465
12466 (define_insn ""
12467   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12468         (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12469                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
12470                  (match_operand:SI 3 "reg_or_short_operand" "rI,rI")))]
12471   "TARGET_32BIT"
12472   "@
12473   {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;{sf%I3|subf%I3c} %0,%0,%3
12474   {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;{sf%I3|subf%I3c} %0,%0,%3"
12475  [(set_attr "length" "12")])
12476
12477 (define_insn ""
12478   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12479         (compare:CC
12480          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12481                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12482                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12483          (const_int 0)))
12484    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12485   "TARGET_32BIT"
12486   "@
12487    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
12488    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
12489    #
12490    #"
12491   [(set_attr "type" "compare")
12492    (set_attr "length" "12,12,16,16")])
12493
12494 (define_split
12495   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12496         (compare:CC
12497          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12498                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12499                   (match_operand:SI 3 "gpc_reg_operand" ""))
12500          (const_int 0)))
12501    (clobber (match_scratch:SI 4 ""))]
12502   "TARGET_32BIT && reload_completed"
12503   [(set (match_dup 4)
12504         (plus:SI (ltu:SI (match_dup 1) (match_dup 2))
12505                  (match_dup 3)))
12506    (set (match_dup 0)
12507         (compare:CC (match_dup 4)
12508                     (const_int 0)))]
12509   "")
12510
12511 (define_insn ""
12512   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12513         (compare:CC
12514          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12515                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12516                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12517          (const_int 0)))
12518    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12519         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12520   "TARGET_32BIT"
12521   "@
12522    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;{sf.|subfc.} %0,%0,%3
12523    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;{sf.|subfc.} %0,%0,%3
12524    #
12525    #"
12526   [(set_attr "type" "compare")
12527    (set_attr "length" "12,12,16,16")])
12528
12529 (define_split
12530   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12531         (compare:CC
12532          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12533                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12534                   (match_operand:SI 3 "gpc_reg_operand" ""))
12535          (const_int 0)))
12536    (set (match_operand:SI 0 "gpc_reg_operand" "")
12537         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12538   "TARGET_32BIT && reload_completed"
12539   [(set (match_dup 0)
12540         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12541    (set (match_dup 4)
12542         (compare:CC (match_dup 0)
12543                     (const_int 0)))]
12544   "")
12545
12546 (define_insn ""
12547   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12548         (neg:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12549                         (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))))]
12550   "TARGET_32BIT"
12551   "@
12552    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
12553    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
12554   [(set_attr "length" "8")])
12555
12556 (define_insn ""
12557   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12558         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12559                (match_operand:SI 2 "reg_or_short_operand" "rI")))
12560    (clobber (match_scratch:SI 3 "=r"))]
12561   "TARGET_POWER"
12562   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
12563    [(set_attr "length" "12")])
12564
12565 (define_insn ""
12566   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12567         (compare:CC
12568          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12569                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12570          (const_int 0)))
12571    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12572         (ge:SI (match_dup 1) (match_dup 2)))
12573    (clobber (match_scratch:SI 3 "=r,r"))]
12574   "TARGET_POWER"
12575   "@
12576    doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
12577    #"
12578   [(set_attr "type" "compare")
12579    (set_attr "length" "12,16")])
12580
12581 (define_split
12582   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12583         (compare:CC
12584          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12585                 (match_operand:SI 2 "reg_or_short_operand" ""))
12586          (const_int 0)))
12587    (set (match_operand:SI 0 "gpc_reg_operand" "")
12588         (ge:SI (match_dup 1) (match_dup 2)))
12589    (clobber (match_scratch:SI 3 ""))]
12590   "TARGET_POWER && reload_completed"
12591   [(parallel [(set (match_dup 0)
12592                    (ge:SI (match_dup 1) (match_dup 2)))
12593               (clobber (match_dup 3))])
12594    (set (match_dup 4)
12595         (compare:CC (match_dup 0)
12596                     (const_int 0)))]
12597   "")
12598
12599 (define_insn ""
12600   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12601         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12602                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12603                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12604   "TARGET_POWER"
12605   "doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
12606   [(set_attr "length" "12")])
12607
12608 (define_insn ""
12609   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12610         (compare:CC
12611          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12612                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12613                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12614          (const_int 0)))
12615    (clobber (match_scratch:SI 4 "=&r,&r"))]
12616   "TARGET_POWER"
12617   "@
12618    doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12619    #"
12620   [(set_attr "type" "compare")
12621    (set_attr "length" "12,16")])
12622
12623 (define_split
12624   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12625         (compare:CC
12626          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12627                          (match_operand:SI 2 "reg_or_short_operand" ""))
12628                   (match_operand:SI 3 "gpc_reg_operand" ""))
12629          (const_int 0)))
12630    (clobber (match_scratch:SI 4 ""))]
12631   "TARGET_POWER && reload_completed"
12632   [(set (match_dup 4)
12633         (plus:SI (ge:SI (match_dup 1) (match_dup 2))
12634                  (match_dup 3)))
12635    (set (match_dup 0)
12636         (compare:CC (match_dup 4)
12637                     (const_int 0)))]
12638   "")
12639
12640 (define_insn ""
12641   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12642         (compare:CC
12643          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12644                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12645                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12646          (const_int 0)))
12647    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12648         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12649   "TARGET_POWER"
12650   "@
12651    doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12652    #"
12653   [(set_attr "type" "compare")
12654    (set_attr "length" "12,16")])
12655
12656 (define_split
12657   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12658         (compare:CC
12659          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12660                          (match_operand:SI 2 "reg_or_short_operand" ""))
12661                   (match_operand:SI 3 "gpc_reg_operand" ""))
12662          (const_int 0)))
12663    (set (match_operand:SI 0 "gpc_reg_operand" "")
12664         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12665   "TARGET_POWER && reload_completed"
12666   [(set (match_dup 0)
12667         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12668    (set (match_dup 4)
12669         (compare:CC (match_dup 0)
12670                     (const_int 0)))]
12671   "")
12672
12673 (define_insn ""
12674   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12675         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12676                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12677   "TARGET_POWER"
12678   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
12679   [(set_attr "length" "12")])
12680
12681 (define_insn ""
12682   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12683         (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12684                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
12685   "TARGET_32BIT"
12686   "@
12687    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
12688    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12689   [(set_attr "length" "12")])
12690
12691 (define_insn ""
12692   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12693         (geu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12694                 (match_operand:DI 2 "reg_or_neg_short_operand" "r,P")))]
12695   "TARGET_64BIT"
12696   "@
12697    subfc %0,%2,%1\;li %0,0\;adde %0,%0,%0
12698    addic %0,%1,%n2\;li %0,0\;adde %0,%0,%0"
12699   [(set_attr "length" "12")])
12700
12701 (define_insn ""
12702   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12703         (compare:CC
12704          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12705                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12706          (const_int 0)))
12707    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12708         (geu:SI (match_dup 1) (match_dup 2)))]
12709   "TARGET_32BIT"
12710   "@
12711    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12712    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12713    #
12714    #"
12715   [(set_attr "type" "compare")
12716    (set_attr "length" "12,12,16,16")])
12717
12718 (define_split
12719   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12720         (compare:CC
12721          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12722                  (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12723          (const_int 0)))
12724    (set (match_operand:SI 0 "gpc_reg_operand" "")
12725         (geu:SI (match_dup 1) (match_dup 2)))]
12726   "TARGET_32BIT && reload_completed"
12727   [(set (match_dup 0)
12728         (geu:SI (match_dup 1) (match_dup 2)))
12729    (set (match_dup 3)
12730         (compare:CC (match_dup 0)
12731                     (const_int 0)))]
12732   "")
12733
12734 (define_insn ""
12735   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12736         (compare:CC
12737          (geu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
12738                  (match_operand:DI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12739          (const_int 0)))
12740    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
12741         (geu:DI (match_dup 1) (match_dup 2)))]
12742   "TARGET_64BIT"
12743   "@
12744    subfc %0,%2,%1\;li %0,0\;adde. %0,%0,%0
12745    addic %0,%1,%n2\;li %0,0\;adde. %0,%0,%0
12746    #
12747    #"
12748   [(set_attr "type" "compare")
12749    (set_attr "length" "12,12,16,16")])
12750
12751 (define_split
12752   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12753         (compare:CC
12754          (geu:DI (match_operand:DI 1 "gpc_reg_operand" "")
12755                  (match_operand:DI 2 "reg_or_neg_short_operand" ""))
12756          (const_int 0)))
12757    (set (match_operand:DI 0 "gpc_reg_operand" "")
12758         (geu:DI (match_dup 1) (match_dup 2)))]
12759   "TARGET_64BIT && reload_completed"
12760   [(set (match_dup 0)
12761         (geu:DI (match_dup 1) (match_dup 2)))
12762    (set (match_dup 3)
12763         (compare:CC (match_dup 0)
12764                     (const_int 0)))]
12765   "")
12766
12767 (define_insn ""
12768   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12769         (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12770                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
12771                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12772   "TARGET_32BIT"
12773   "@
12774    {sf|subfc} %0,%2,%1\;{aze|addze} %0,%3
12775    {ai|addic} %0,%1,%n2\;{aze|addze} %0,%3"
12776   [(set_attr "length" "8")])
12777
12778 (define_insn ""
12779   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12780         (compare:CC
12781          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12782                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12783                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12784          (const_int 0)))
12785    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12786   "TARGET_32BIT"
12787   "@
12788    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
12789    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3
12790    #
12791    #"
12792   [(set_attr "type" "compare")
12793    (set_attr "length" "8,8,12,12")])
12794
12795 (define_split
12796   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12797         (compare:CC
12798          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12799                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12800                   (match_operand:SI 3 "gpc_reg_operand" ""))
12801          (const_int 0)))
12802    (clobber (match_scratch:SI 4 ""))]
12803   "TARGET_32BIT && reload_completed"
12804   [(set (match_dup 4)
12805         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
12806                   (match_dup 3)))
12807    (set (match_dup 0)
12808         (compare:CC (match_dup 4)
12809                     (const_int 0)))]
12810   "")
12811
12812 (define_insn ""
12813   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12814         (compare:CC
12815          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12816                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12817                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12818          (const_int 0)))
12819    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12820         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12821   "TARGET_32BIT"
12822   "@
12823    {sf|subfc} %0,%2,%1\;{aze.|addze.} %0,%3
12824    {ai|addic} %0,%1,%n2\;{aze.|addze.} %0,%3
12825    #
12826    #"
12827   [(set_attr "type" "compare")
12828    (set_attr "length" "8,8,12,12")])
12829
12830 (define_split
12831   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12832         (compare:CC
12833          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12834                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12835                   (match_operand:SI 3 "gpc_reg_operand" ""))
12836          (const_int 0)))
12837    (set (match_operand:SI 0 "gpc_reg_operand" "")
12838         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12839   "TARGET_32BIT && reload_completed"
12840   [(set (match_dup 0)
12841         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12842    (set (match_dup 4)
12843         (compare:CC (match_dup 0)
12844                     (const_int 0)))]
12845   "")
12846
12847 (define_insn ""
12848   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12849         (neg:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12850                         (match_operand:SI 2 "reg_or_short_operand" "r,I"))))]
12851   "TARGET_32BIT"
12852   "@
12853    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
12854    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
12855   [(set_attr "length" "12")])
12856
12857 (define_insn ""
12858   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12859         (and:SI (neg:SI
12860                  (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12861                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
12862                 (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12863   "TARGET_32BIT"
12864   "@
12865    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0
12866    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12867   [(set_attr "length" "12")])
12868
12869 (define_insn ""
12870   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12871         (compare:CC
12872          (and:SI (neg:SI
12873                   (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    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12878   "TARGET_32BIT"
12879   "@
12880    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12881    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12882    #
12883    #"
12884   [(set_attr "type" "compare")
12885    (set_attr "length" "12,12,16,16")])
12886
12887 (define_split
12888   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12889         (compare:CC
12890          (and:SI (neg:SI
12891                   (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    (clobber (match_scratch:SI 4 ""))]
12896   "TARGET_32BIT && reload_completed"
12897   [(set (match_dup 4)
12898         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
12899                 (match_dup 3)))
12900    (set (match_dup 0)
12901         (compare:CC (match_dup 4)
12902                     (const_int 0)))]
12903   "")
12904
12905 (define_insn ""
12906   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12907         (compare:CC
12908          (and:SI (neg:SI
12909                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12910                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
12911                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12912          (const_int 0)))
12913    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12914         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12915   "TARGET_32BIT"
12916   "@
12917    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12918    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12919    #
12920    #"
12921   [(set_attr "type" "compare")
12922    (set_attr "length" "12,12,16,16")])
12923
12924 (define_split
12925   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12926         (compare:CC
12927          (and:SI (neg:SI
12928                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12929                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
12930                  (match_operand:SI 3 "gpc_reg_operand" ""))
12931          (const_int 0)))
12932    (set (match_operand:SI 0 "gpc_reg_operand" "")
12933         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12934   "TARGET_32BIT && reload_completed"
12935   [(set (match_dup 0)
12936         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
12937    (set (match_dup 4)
12938         (compare:CC (match_dup 0)
12939                     (const_int 0)))]
12940   "")
12941
12942 (define_insn ""
12943   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12944         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12945                (const_int 0)))]
12946   "TARGET_32BIT"
12947   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri|srwi} %0,%0,31"
12948   [(set_attr "length" "12")])
12949
12950 (define_insn ""
12951   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12952         (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
12953                (const_int 0)))]
12954   "TARGET_64BIT"
12955   "subfic %0,%1,0\;addme %0,%0\;srdi %0,%0,63"
12956   [(set_attr "length" "12")])
12957
12958 (define_insn ""
12959   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
12960         (compare:CC
12961          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12962                 (const_int 0))
12963          (const_int 0)))
12964    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12965         (gt:SI (match_dup 1) (const_int 0)))]
12966   "TARGET_32BIT"
12967   "@
12968    {sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri.|srwi.} %0,%0,31
12969    #"
12970   [(set_attr "type" "delayed_compare")
12971    (set_attr "length" "12,16")])
12972
12973 (define_split
12974   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
12975         (compare:CC
12976          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12977                 (const_int 0))
12978          (const_int 0)))
12979    (set (match_operand:SI 0 "gpc_reg_operand" "")
12980         (gt:SI (match_dup 1) (const_int 0)))]
12981   "TARGET_32BIT && reload_completed"
12982   [(set (match_dup 0)
12983         (gt:SI (match_dup 1) (const_int 0)))
12984    (set (match_dup 2)
12985         (compare:CC (match_dup 0)
12986                     (const_int 0)))]
12987   "")
12988
12989 (define_insn ""
12990   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
12991         (compare:CC
12992          (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12993                 (const_int 0))
12994          (const_int 0)))
12995    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12996         (gt:DI (match_dup 1) (const_int 0)))]
12997   "TARGET_64BIT"
12998   "@
12999    subfic %0,%1,0\;addme %0,%0\;srdi. %0,%0,63
13000    #"
13001   [(set_attr "type" "delayed_compare")
13002    (set_attr "length" "12,16")])
13003
13004 (define_split
13005   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
13006         (compare:CC
13007          (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13008                 (const_int 0))
13009          (const_int 0)))
13010    (set (match_operand:DI 0 "gpc_reg_operand" "")
13011         (gt:DI (match_dup 1) (const_int 0)))]
13012   "TARGET_64BIT && reload_completed"
13013   [(set (match_dup 0)
13014         (gt:DI (match_dup 1) (const_int 0)))
13015    (set (match_dup 2)
13016         (compare:CC (match_dup 0)
13017                     (const_int 0)))]
13018   "")
13019
13020 (define_insn ""
13021   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13022         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13023                (match_operand:SI 2 "reg_or_short_operand" "r")))]
13024   "TARGET_POWER"
13025   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
13026   [(set_attr "length" "12")])
13027
13028 (define_insn ""
13029   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13030         (compare:CC
13031          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13032                 (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13033          (const_int 0)))
13034    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13035         (gt:SI (match_dup 1) (match_dup 2)))]
13036   "TARGET_POWER"
13037   "@
13038    doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
13039    #"
13040   [(set_attr "type" "delayed_compare")
13041    (set_attr "length" "12,16")])
13042
13043 (define_split
13044   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13045         (compare:CC
13046          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13047                 (match_operand:SI 2 "reg_or_short_operand" ""))
13048          (const_int 0)))
13049    (set (match_operand:SI 0 "gpc_reg_operand" "")
13050         (gt:SI (match_dup 1) (match_dup 2)))]
13051   "TARGET_POWER && reload_completed"
13052   [(set (match_dup 0)
13053         (gt:SI (match_dup 1) (match_dup 2)))
13054    (set (match_dup 3)
13055         (compare:CC (match_dup 0)
13056                     (const_int 0)))]
13057   "")
13058
13059 (define_insn ""
13060   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13061         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13062                         (const_int 0))
13063                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
13064   "TARGET_32BIT"
13065   "{a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze|addze} %0,%2"
13066   [(set_attr "length" "12")])
13067
13068 (define_insn ""
13069   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
13070         (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13071                         (const_int 0))
13072                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
13073   "TARGET_64BIT"
13074   "addc %0,%1,%1\;subfe %0,%1,%0\;addze %0,%2"
13075   [(set_attr "length" "12")])
13076
13077 (define_insn ""
13078   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13079         (compare:CC
13080          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13081                          (const_int 0))
13082                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13083          (const_int 0)))
13084    (clobber (match_scratch:SI 3 "=&r,&r"))]
13085   "TARGET_32BIT"
13086   "@
13087    {a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2
13088    #"
13089   [(set_attr "type" "compare")
13090    (set_attr "length" "12,16")])
13091
13092 (define_split
13093   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13094         (compare:CC
13095          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13096                          (const_int 0))
13097                   (match_operand:SI 2 "gpc_reg_operand" ""))
13098          (const_int 0)))
13099    (clobber (match_scratch:SI 3 ""))]
13100   "TARGET_32BIT && reload_completed"
13101   [(set (match_dup 3)
13102         (plus:SI (gt:SI (match_dup 1) (const_int 0))
13103                   (match_dup 2)))
13104    (set (match_dup 0)
13105         (compare:CC (match_dup 3)
13106                     (const_int 0)))]
13107   "")
13108
13109 (define_insn ""
13110   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13111         (compare:CC
13112          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13113                          (const_int 0))
13114                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13115          (const_int 0)))
13116    (clobber (match_scratch:DI 3 "=&r,&r"))]
13117   "TARGET_64BIT"
13118   "@
13119    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
13120    #"
13121   [(set_attr "type" "compare")
13122    (set_attr "length" "12,16")])
13123
13124 (define_split
13125   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13126         (compare:CC
13127          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13128                          (const_int 0))
13129                   (match_operand:DI 2 "gpc_reg_operand" ""))
13130          (const_int 0)))
13131    (clobber (match_scratch:DI 3 ""))]
13132   "TARGET_64BIT && reload_completed"
13133   [(set (match_dup 3)
13134         (plus:DI (gt:DI (match_dup 1) (const_int 0))
13135                  (match_dup 2)))
13136    (set (match_dup 0)
13137         (compare:CC (match_dup 3)
13138                     (const_int 0)))]
13139   "")
13140
13141 (define_insn ""
13142   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13143         (compare:CC
13144          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13145                          (const_int 0))
13146                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13147          (const_int 0)))
13148    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13149         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13150   "TARGET_32BIT"
13151   "@
13152    {a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze.|addze.} %0,%2
13153    #"
13154   [(set_attr "type" "compare")
13155    (set_attr "length" "12,16")])
13156
13157 (define_split
13158   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13159         (compare:CC
13160          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13161                          (const_int 0))
13162                   (match_operand:SI 2 "gpc_reg_operand" ""))
13163          (const_int 0)))
13164    (set (match_operand:SI 0 "gpc_reg_operand" "")
13165         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13166   "TARGET_32BIT && reload_completed"
13167   [(set (match_dup 0)
13168         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
13169    (set (match_dup 3)
13170         (compare:CC (match_dup 0)
13171                     (const_int 0)))]
13172   "")
13173
13174 (define_insn ""
13175   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13176         (compare:CC
13177          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13178                          (const_int 0))
13179                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13180          (const_int 0)))
13181    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
13182         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13183   "TARGET_64BIT"
13184   "@
13185    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
13186    #"
13187   [(set_attr "type" "compare")
13188    (set_attr "length" "12,16")])
13189
13190 (define_split
13191   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13192         (compare:CC
13193          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13194                          (const_int 0))
13195                   (match_operand:DI 2 "gpc_reg_operand" ""))
13196          (const_int 0)))
13197    (set (match_operand:DI 0 "gpc_reg_operand" "")
13198         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13199   "TARGET_64BIT && reload_completed"
13200   [(set (match_dup 0)
13201         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
13202    (set (match_dup 3)
13203         (compare:CC (match_dup 0)
13204                     (const_int 0)))]
13205   "")
13206
13207 (define_insn ""
13208   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13209         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13210                         (match_operand:SI 2 "reg_or_short_operand" "r"))
13211                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
13212   "TARGET_POWER"
13213   "doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
13214   [(set_attr "length" "12")])
13215
13216 (define_insn ""
13217   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13218         (compare:CC
13219          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13220                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13221                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13222          (const_int 0)))
13223    (clobber (match_scratch:SI 4 "=&r,&r"))]
13224   "TARGET_POWER"
13225   "@
13226    doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
13227    #"
13228   [(set_attr "type" "compare")
13229    (set_attr "length" "12,16")])
13230
13231 (define_split
13232   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13233         (compare:CC
13234          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13235                          (match_operand:SI 2 "reg_or_short_operand" ""))
13236                   (match_operand:SI 3 "gpc_reg_operand" ""))
13237          (const_int 0)))
13238    (clobber (match_scratch:SI 4 ""))]
13239   "TARGET_POWER && reload_completed"
13240   [(set (match_dup 4)
13241         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13242    (set (match_dup 0)
13243         (compare:CC (match_dup 4)
13244                     (const_int 0)))]
13245   "")
13246
13247 (define_insn ""
13248   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13249         (compare:CC
13250          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13251                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13252                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13253          (const_int 0)))
13254    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13255         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13256   "TARGET_POWER"
13257   "@
13258    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
13259    #"
13260   [(set_attr "type" "compare")
13261    (set_attr "length" "12,16")])
13262
13263 (define_split
13264   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13265         (compare:CC
13266          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13267                          (match_operand:SI 2 "reg_or_short_operand" ""))
13268                   (match_operand:SI 3 "gpc_reg_operand" ""))
13269          (const_int 0)))
13270    (set (match_operand:SI 0 "gpc_reg_operand" "")
13271         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13272   "TARGET_POWER && reload_completed"
13273   [(set (match_dup 0)
13274         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13275    (set (match_dup 4)
13276         (compare:CC (match_dup 0)
13277                     (const_int 0)))]
13278   "")
13279
13280 (define_insn ""
13281   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13282         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13283                        (const_int 0))))]
13284   "TARGET_32BIT"
13285   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{srai|srawi} %0,%0,31"
13286   [(set_attr "length" "12")])
13287
13288 (define_insn ""
13289   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13290         (neg:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13291                        (const_int 0))))]
13292   "TARGET_64BIT"
13293   "subfic %0,%1,0\;addme %0,%0\;sradi %0,%0,63"
13294   [(set_attr "length" "12")])
13295
13296 (define_insn ""
13297   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13298         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13299                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
13300   "TARGET_POWER"
13301   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
13302   [(set_attr "length" "12")])
13303
13304 (define_insn ""
13305   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13306         (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13307                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
13308   "TARGET_32BIT"
13309   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg %0,%0"
13310   [(set_attr "length" "12")])
13311
13312 (define_insn ""
13313   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13314         (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13315                 (match_operand:DI 2 "reg_or_short_operand" "rI")))]
13316   "TARGET_64BIT"
13317   "subf%I2c %0,%1,%2\;subfe %0,%0,%0\;neg %0,%0"
13318   [(set_attr "length" "12")])
13319
13320 (define_insn ""
13321   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13322         (compare:CC
13323          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13324                  (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13325          (const_int 0)))
13326    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13327         (gtu:SI (match_dup 1) (match_dup 2)))]
13328   "TARGET_32BIT"
13329   "@
13330    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
13331    #"
13332   [(set_attr "type" "compare")
13333    (set_attr "length" "12,16")])
13334
13335 (define_split
13336   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13337         (compare:CC
13338          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13339                  (match_operand:SI 2 "reg_or_short_operand" ""))
13340          (const_int 0)))
13341    (set (match_operand:SI 0 "gpc_reg_operand" "")
13342         (gtu:SI (match_dup 1) (match_dup 2)))]
13343   "TARGET_32BIT && reload_completed"
13344   [(set (match_dup 0)
13345         (gtu:SI (match_dup 1) (match_dup 2)))
13346    (set (match_dup 3)
13347         (compare:CC (match_dup 0)
13348                     (const_int 0)))]
13349   "")
13350
13351 (define_insn ""
13352   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13353         (compare:CC
13354          (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13355                  (match_operand:DI 2 "reg_or_short_operand" "rI,rI"))
13356          (const_int 0)))
13357    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
13358         (gtu:DI (match_dup 1) (match_dup 2)))]
13359   "TARGET_64BIT"
13360   "@
13361    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;neg. %0,%0
13362    #"
13363   [(set_attr "type" "compare")
13364    (set_attr "length" "12,16")])
13365
13366 (define_split
13367   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13368         (compare:CC
13369          (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13370                  (match_operand:DI 2 "reg_or_short_operand" ""))
13371          (const_int 0)))
13372    (set (match_operand:DI 0 "gpc_reg_operand" "")
13373         (gtu:DI (match_dup 1) (match_dup 2)))]
13374   "TARGET_64BIT && reload_completed"
13375   [(set (match_dup 0)
13376         (gtu:DI (match_dup 1) (match_dup 2)))
13377    (set (match_dup 3)
13378         (compare:CC (match_dup 0)
13379                     (const_int 0)))]
13380   "")
13381
13382 (define_insn ""
13383   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13384         (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13385                          (match_operand:SI 2 "reg_or_short_operand" "I,rI"))
13386                  (match_operand:SI 3 "reg_or_short_operand" "r,rI")))]
13387   "TARGET_32BIT"
13388   "@
13389    {ai|addic} %0,%1,%k2\;{aze|addze} %0,%3
13390    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;{sf%I3|subf%I3c} %0,%0,%3"
13391   [(set_attr "length" "8,12")])
13392
13393 (define_insn ""
13394   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
13395         (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13396                          (match_operand:DI 2 "reg_or_short_operand" "I,rI"))
13397                  (match_operand:DI 3 "reg_or_short_operand" "r,rI")))]
13398   "TARGET_64BIT"
13399   "@
13400    addic %0,%1,%k2\;addze %0,%3
13401    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;subf%I3c %0,%0,%3"
13402   [(set_attr "length" "8,12")])
13403
13404 (define_insn ""
13405   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13406         (compare:CC
13407          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13408                           (match_operand:SI 2 "reg_or_short_operand" "I,r,I,r"))
13409                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13410          (const_int 0)))
13411    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13412   "TARGET_32BIT"
13413   "@
13414    {ai|addic} %4,%1,%k2\;{aze.|addze.} %4,%3
13415    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
13416    #
13417    #"
13418   [(set_attr "type" "compare")
13419    (set_attr "length" "8,12,12,16")])
13420
13421 (define_split
13422   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13423         (compare:CC
13424          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13425                           (match_operand:SI 2 "reg_or_short_operand" ""))
13426                   (match_operand:SI 3 "gpc_reg_operand" ""))
13427          (const_int 0)))
13428    (clobber (match_scratch:SI 4 ""))]
13429   "TARGET_32BIT && reload_completed"
13430   [(set (match_dup 4)
13431         (plus:SI (gtu:SI (match_dup 1) (match_dup 2))
13432                  (match_dup 3)))
13433    (set (match_dup 0)
13434         (compare:CC (match_dup 4)
13435                     (const_int 0)))]
13436   "")
13437
13438 (define_insn ""
13439   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13440         (compare:CC
13441          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
13442                           (match_operand:DI 2 "reg_or_short_operand" "I,r,I,r"))
13443                   (match_operand:DI 3 "gpc_reg_operand" "r,r,r,r"))
13444          (const_int 0)))
13445    (clobber (match_scratch:DI 4 "=&r,&r,&r,&r"))]
13446   "TARGET_64BIT"
13447   "@
13448    addic %4,%1,%k2\;addze. %4,%3
13449    subf%I2c %4,%1,%2\;subfe %4,%4,%4\;subfc. %4,%4,%3
13450    #
13451    #"
13452   [(set_attr "type" "compare")
13453    (set_attr "length" "8,12,12,16")])
13454
13455 (define_split
13456   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13457         (compare:CC
13458          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13459                           (match_operand:DI 2 "reg_or_short_operand" ""))
13460                   (match_operand:DI 3 "gpc_reg_operand" ""))
13461          (const_int 0)))
13462    (clobber (match_scratch:DI 4 ""))]
13463   "TARGET_64BIT && reload_completed"
13464   [(set (match_dup 4)
13465         (plus:DI (gtu:DI (match_dup 1) (match_dup 2))
13466                   (match_dup 3)))
13467    (set (match_dup 0)
13468         (compare:CC (match_dup 4)
13469                     (const_int 0)))]
13470   "")
13471
13472 (define_insn ""
13473   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13474         (compare:CC
13475          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13476                           (match_operand:SI 2 "reg_or_short_operand" "I,r,I,r"))
13477                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13478          (const_int 0)))
13479    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13480         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13481   "TARGET_32BIT"
13482   "@
13483    {ai|addic} %0,%1,%k2\;{aze.|addze.} %0,%3
13484    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;{sf.|subfc.} %0,%0,%3
13485    #
13486    #"
13487   [(set_attr "type" "compare")
13488    (set_attr "length" "8,12,12,16")])
13489
13490 (define_split
13491   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13492         (compare:CC
13493          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13494                           (match_operand:SI 2 "reg_or_short_operand" ""))
13495                   (match_operand:SI 3 "gpc_reg_operand" ""))
13496          (const_int 0)))
13497    (set (match_operand:SI 0 "gpc_reg_operand" "")
13498         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13499   "TARGET_32BIT && reload_completed"
13500   [(set (match_dup 0)
13501         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13502    (set (match_dup 4)
13503         (compare:CC (match_dup 0)
13504                     (const_int 0)))]
13505   "")
13506
13507 (define_insn ""
13508   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13509         (compare:CC
13510          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
13511                           (match_operand:DI 2 "reg_or_short_operand" "I,r,I,r"))
13512                   (match_operand:DI 3 "gpc_reg_operand" "r,r,r,r"))
13513          (const_int 0)))
13514    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13515         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13516   "TARGET_64BIT"
13517   "@
13518    addic %0,%1,%k2\;addze. %0,%3
13519    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;subfc. %0,%0,%3
13520    #
13521    #"
13522   [(set_attr "type" "compare")
13523    (set_attr "length" "8,12,12,16")])
13524
13525 (define_split
13526   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13527         (compare:CC
13528          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13529                           (match_operand:DI 2 "reg_or_short_operand" ""))
13530                   (match_operand:DI 3 "gpc_reg_operand" ""))
13531          (const_int 0)))
13532    (set (match_operand:DI 0 "gpc_reg_operand" "")
13533         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13534   "TARGET_64BIT && reload_completed"
13535   [(set (match_dup 0)
13536         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
13537    (set (match_dup 4)
13538         (compare:CC (match_dup 0)
13539                     (const_int 0)))]
13540   "")
13541
13542 (define_insn ""
13543   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13544         (neg:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13545                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
13546   "TARGET_32BIT"
13547   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
13548   [(set_attr "length" "8")])
13549
13550 (define_insn ""
13551   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13552         (neg:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13553                         (match_operand:DI 2 "reg_or_short_operand" "rI"))))]
13554   "TARGET_64BIT"
13555   "subf%I2c %0,%1,%2\;subfe %0,%0,%0"
13556   [(set_attr "length" "8")])
13557 \f
13558 ;; Define both directions of branch and return.  If we need a reload
13559 ;; register, we'd rather use CR0 since it is much easier to copy a
13560 ;; register CC value to there.
13561
13562 (define_insn ""
13563   [(set (pc)
13564         (if_then_else (match_operator 1 "branch_comparison_operator"
13565                                       [(match_operand 2
13566                                                       "cc_reg_operand" "y")
13567                                        (const_int 0)])
13568                       (label_ref (match_operand 0 "" ""))
13569                       (pc)))]
13570   ""
13571   "*
13572 {
13573   return output_cbranch (operands[1], \"%l0\", 0, insn);
13574 }"
13575   [(set_attr "type" "branch")])
13576
13577 (define_insn ""
13578   [(set (pc)
13579         (if_then_else (match_operator 0 "branch_comparison_operator"
13580                                       [(match_operand 1
13581                                                       "cc_reg_operand" "y")
13582                                        (const_int 0)])
13583                       (return)
13584                       (pc)))]
13585   "direct_return ()"
13586   "*
13587 {
13588   return output_cbranch (operands[0], NULL, 0, insn);
13589 }"
13590   [(set_attr "type" "branch")
13591    (set_attr "length" "4")])
13592
13593 (define_insn ""
13594   [(set (pc)
13595         (if_then_else (match_operator 1 "branch_comparison_operator"
13596                                       [(match_operand 2
13597                                                       "cc_reg_operand" "y")
13598                                        (const_int 0)])
13599                       (pc)
13600                       (label_ref (match_operand 0 "" ""))))]
13601   ""
13602   "*
13603 {
13604   return output_cbranch (operands[1], \"%l0\", 1, insn);
13605 }"
13606   [(set_attr "type" "branch")])
13607
13608 (define_insn ""
13609   [(set (pc)
13610         (if_then_else (match_operator 0 "branch_comparison_operator"
13611                                       [(match_operand 1
13612                                                       "cc_reg_operand" "y")
13613                                        (const_int 0)])
13614                       (pc)
13615                       (return)))]
13616   "direct_return ()"
13617   "*
13618 {
13619   return output_cbranch (operands[0], NULL, 1, insn);
13620 }"
13621   [(set_attr "type" "branch")
13622    (set_attr "length" "4")])
13623
13624 ;; Logic on condition register values.
13625
13626 ; This pattern matches things like
13627 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
13628 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
13629 ;                                  (const_int 1)))
13630 ; which are generated by the branch logic.
13631 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
13632
13633 (define_insn "*cceq_ior_compare"
13634   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13635         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
13636                         [(match_operator:SI 2
13637                                       "branch_positive_comparison_operator"
13638                                       [(match_operand 3
13639                                                       "cc_reg_operand" "y,y")
13640                                        (const_int 0)])
13641                          (match_operator:SI 4
13642                                       "branch_positive_comparison_operator"
13643                                       [(match_operand 5
13644                                                       "cc_reg_operand" "0,y")
13645                                        (const_int 0)])])
13646                       (const_int 1)))]
13647   "!(TARGET_E500 && TARGET_HARD_FLOAT && !TARGET_FPRS)"
13648   "cr%q1 %E0,%j2,%j4"
13649   [(set_attr "type" "cr_logical,delayed_cr")])
13650
13651 ; Why is the constant -1 here, but 1 in the previous pattern?
13652 ; Because ~1 has all but the low bit set.
13653 (define_insn ""
13654   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13655         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
13656                         [(not:SI (match_operator:SI 2
13657                                       "branch_positive_comparison_operator"
13658                                       [(match_operand 3
13659                                                       "cc_reg_operand" "y,y")
13660                                        (const_int 0)]))
13661                          (match_operator:SI 4
13662                                 "branch_positive_comparison_operator"
13663                                 [(match_operand 5
13664                                                 "cc_reg_operand" "0,y")
13665                                  (const_int 0)])])
13666                       (const_int -1)))]
13667   ""
13668   "cr%q1 %E0,%j2,%j4"
13669   [(set_attr "type" "cr_logical,delayed_cr")])
13670
13671 (define_insn "*cceq_rev_compare"
13672   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13673         (compare:CCEQ (match_operator:SI 1
13674                                       "branch_positive_comparison_operator"
13675                                       [(match_operand 2
13676                                                       "cc_reg_operand" "0,y")
13677                                        (const_int 0)])
13678                       (const_int 0)))]
13679   ""
13680   "{crnor %E0,%j1,%j1|crnot %E0,%j1}"
13681   [(set_attr "type" "cr_logical,delayed_cr")])
13682
13683 ;; If we are comparing the result of two comparisons, this can be done
13684 ;; using creqv or crxor.
13685
13686 (define_insn_and_split ""
13687   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
13688         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
13689                               [(match_operand 2 "cc_reg_operand" "y")
13690                                (const_int 0)])
13691                       (match_operator 3 "branch_comparison_operator"
13692                               [(match_operand 4 "cc_reg_operand" "y")
13693                                (const_int 0)])))]
13694   ""
13695   "#"
13696   ""
13697   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
13698                                     (match_dup 5)))]
13699   "
13700 {
13701   int positive_1, positive_2;
13702
13703   positive_1 = branch_positive_comparison_operator (operands[1], CCEQmode);
13704   positive_2 = branch_positive_comparison_operator (operands[3], CCEQmode);
13705
13706   if (! positive_1)
13707     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
13708                                                             GET_CODE (operands[1])),
13709                                   SImode,
13710                                   operands[2], const0_rtx);
13711   else if (GET_MODE (operands[1]) != SImode)
13712     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
13713                                   operands[2], const0_rtx);
13714
13715   if (! positive_2)
13716     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
13717                                                             GET_CODE (operands[3])),
13718                                   SImode,
13719                                   operands[4], const0_rtx);
13720   else if (GET_MODE (operands[3]) != SImode)
13721     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
13722                                   operands[4], const0_rtx);
13723
13724   if (positive_1 == positive_2)
13725     {
13726       operands[1] = gen_rtx_NOT (SImode, operands[1]);
13727       operands[5] = constm1_rtx;
13728     }
13729   else
13730     {
13731       operands[5] = const1_rtx;
13732     }
13733 }")
13734
13735 ;; Unconditional branch and return.
13736
13737 (define_insn "jump"
13738   [(set (pc)
13739         (label_ref (match_operand 0 "" "")))]
13740   ""
13741   "b %l0"
13742   [(set_attr "type" "branch")])
13743
13744 (define_insn "return"
13745   [(return)]
13746   "direct_return ()"
13747   "{br|blr}"
13748   [(set_attr "type" "jmpreg")])
13749
13750 (define_expand "indirect_jump"
13751   [(set (pc) (match_operand 0 "register_operand" ""))]
13752   ""
13753   "
13754 {
13755   if (TARGET_32BIT)
13756     emit_jump_insn (gen_indirect_jumpsi (operands[0]));
13757   else
13758     emit_jump_insn (gen_indirect_jumpdi (operands[0]));
13759   DONE;
13760 }")
13761
13762 (define_insn "indirect_jumpsi"
13763   [(set (pc) (match_operand:SI 0 "register_operand" "c,*l"))]
13764   "TARGET_32BIT"
13765   "@
13766    bctr
13767    {br|blr}"
13768   [(set_attr "type" "jmpreg")])
13769
13770 (define_insn "indirect_jumpdi"
13771   [(set (pc) (match_operand:DI 0 "register_operand" "c,*l"))]
13772   "TARGET_64BIT"
13773   "@
13774    bctr
13775    blr"
13776   [(set_attr "type" "jmpreg")])
13777
13778 ;; Table jump for switch statements:
13779 (define_expand "tablejump"
13780   [(use (match_operand 0 "" ""))
13781    (use (label_ref (match_operand 1 "" "")))]
13782   ""
13783   "
13784 {
13785   if (TARGET_32BIT)
13786     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
13787   else
13788     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
13789   DONE;
13790 }")
13791
13792 (define_expand "tablejumpsi"
13793   [(set (match_dup 3)
13794         (plus:SI (match_operand:SI 0 "" "")
13795                  (match_dup 2)))
13796    (parallel [(set (pc) (match_dup 3))
13797               (use (label_ref (match_operand 1 "" "")))])]
13798   "TARGET_32BIT"
13799   "
13800 { operands[0] = force_reg (SImode, operands[0]);
13801   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
13802   operands[3] = gen_reg_rtx (SImode);
13803 }")
13804
13805 (define_expand "tablejumpdi"
13806   [(set (match_dup 4)
13807         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "rm")))
13808    (set (match_dup 3)
13809         (plus:DI (match_dup 4)
13810                  (match_dup 2)))
13811    (parallel [(set (pc) (match_dup 3))
13812               (use (label_ref (match_operand 1 "" "")))])]
13813   "TARGET_64BIT"
13814   "
13815 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
13816   operands[3] = gen_reg_rtx (DImode);
13817   operands[4] = gen_reg_rtx (DImode);
13818 }")
13819
13820 (define_insn ""
13821   [(set (pc)
13822         (match_operand:SI 0 "register_operand" "c,*l"))
13823    (use (label_ref (match_operand 1 "" "")))]
13824   "TARGET_32BIT"
13825   "@
13826    bctr
13827    {br|blr}"
13828   [(set_attr "type" "jmpreg")])
13829
13830 (define_insn ""
13831   [(set (pc)
13832         (match_operand:DI 0 "register_operand" "c,*l"))
13833    (use (label_ref (match_operand 1 "" "")))]
13834   "TARGET_64BIT"
13835   "@
13836    bctr
13837    blr"
13838   [(set_attr "type" "jmpreg")])
13839
13840 (define_insn "nop"
13841   [(const_int 0)]
13842   ""
13843   "{cror 0,0,0|nop}")
13844 \f
13845 ;; Define the subtract-one-and-jump insns, starting with the template
13846 ;; so loop.c knows what to generate.
13847
13848 (define_expand "doloop_end"
13849   [(use (match_operand 0 "" ""))        ; loop pseudo
13850    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
13851    (use (match_operand 2 "" ""))        ; max iterations
13852    (use (match_operand 3 "" ""))        ; loop level
13853    (use (match_operand 4 "" ""))]       ; label
13854   ""
13855   "
13856 {
13857   /* Only use this on innermost loops.  */
13858   if (INTVAL (operands[3]) > 1)
13859     FAIL;
13860   if (TARGET_64BIT)
13861     {
13862       if (GET_MODE (operands[0]) != DImode)
13863         FAIL;
13864       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
13865     }
13866   else
13867     {
13868       if (GET_MODE (operands[0]) != SImode)
13869         FAIL;
13870       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
13871     }
13872   DONE;
13873 }")
13874
13875 (define_expand "ctrsi"
13876   [(parallel [(set (pc)
13877                    (if_then_else (ne (match_operand:SI 0 "register_operand" "")
13878                                      (const_int 1))
13879                                  (label_ref (match_operand 1 "" ""))
13880                                  (pc)))
13881               (set (match_dup 0)
13882                    (plus:SI (match_dup 0)
13883                             (const_int -1)))
13884               (clobber (match_scratch:CC 2 ""))
13885               (clobber (match_scratch:SI 3 ""))])]
13886   "TARGET_32BIT"
13887   "")
13888
13889 (define_expand "ctrdi"
13890   [(parallel [(set (pc)
13891                    (if_then_else (ne (match_operand:DI 0 "register_operand" "")
13892                                      (const_int 1))
13893                                  (label_ref (match_operand 1 "" ""))
13894                                  (pc)))
13895               (set (match_dup 0)
13896                    (plus:DI (match_dup 0)
13897                             (const_int -1)))
13898               (clobber (match_scratch:CC 2 ""))
13899               (clobber (match_scratch:DI 3 ""))])]
13900   "TARGET_64BIT"
13901   "")
13902
13903 ;; We need to be able to do this for any operand, including MEM, or we
13904 ;; will cause reload to blow up since we don't allow output reloads on
13905 ;; JUMP_INSNs.
13906 ;; For the length attribute to be calculated correctly, the
13907 ;; label MUST be operand 0.
13908
13909 (define_insn "*ctrsi_internal1"
13910   [(set (pc)
13911         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
13912                           (const_int 1))
13913                       (label_ref (match_operand 0 "" ""))
13914                       (pc)))
13915    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
13916         (plus:SI (match_dup 1)
13917                  (const_int -1)))
13918    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13919    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
13920   "TARGET_32BIT"
13921   "*
13922 {
13923   if (which_alternative != 0)
13924     return \"#\";
13925   else if (get_attr_length (insn) == 4)
13926     return \"{bdn|bdnz} %l0\";
13927   else
13928     return \"bdz $+8\;b %l0\";
13929 }"
13930   [(set_attr "type" "branch")
13931    (set_attr "length" "*,12,16,16")])
13932
13933 (define_insn "*ctrsi_internal2"
13934   [(set (pc)
13935         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
13936                           (const_int 1))
13937                       (pc)
13938                       (label_ref (match_operand 0 "" ""))))
13939    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
13940         (plus:SI (match_dup 1)
13941                  (const_int -1)))
13942    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13943    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
13944   "TARGET_32BIT"
13945   "*
13946 {
13947   if (which_alternative != 0)
13948     return \"#\";
13949   else if (get_attr_length (insn) == 4)
13950     return \"bdz %l0\";
13951   else
13952     return \"{bdn|bdnz} $+8\;b %l0\";
13953 }"
13954   [(set_attr "type" "branch")
13955    (set_attr "length" "*,12,16,16")])
13956
13957 (define_insn "*ctrdi_internal1"
13958   [(set (pc)
13959         (if_then_else (ne (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
13960                           (const_int 1))
13961                       (label_ref (match_operand 0 "" ""))
13962                       (pc)))
13963    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
13964         (plus:DI (match_dup 1)
13965                  (const_int -1)))
13966    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13967    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
13968   "TARGET_64BIT"
13969   "*
13970 {
13971   if (which_alternative != 0)
13972     return \"#\";
13973   else if (get_attr_length (insn) == 4)
13974     return \"{bdn|bdnz} %l0\";
13975   else
13976     return \"bdz $+8\;b %l0\";
13977 }"
13978   [(set_attr "type" "branch")
13979    (set_attr "length" "*,12,16,16")])
13980
13981 (define_insn "*ctrdi_internal2"
13982   [(set (pc)
13983         (if_then_else (ne (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
13984                           (const_int 1))
13985                       (pc)
13986                       (label_ref (match_operand 0 "" ""))))
13987    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
13988         (plus:DI (match_dup 1)
13989                  (const_int -1)))
13990    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13991    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
13992   "TARGET_64BIT"
13993   "*
13994 {
13995   if (which_alternative != 0)
13996     return \"#\";
13997   else if (get_attr_length (insn) == 4)
13998     return \"bdz %l0\";
13999   else
14000     return \"{bdn|bdnz} $+8\;b %l0\";
14001 }"
14002   [(set_attr "type" "branch")
14003    (set_attr "length" "*,12,16,16")])
14004
14005 ;; Similar, but we can use GE since we have a REG_NONNEG.
14006
14007 (define_insn "*ctrsi_internal3"
14008   [(set (pc)
14009         (if_then_else (ge (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14010                           (const_int 0))
14011                       (label_ref (match_operand 0 "" ""))
14012                       (pc)))
14013    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14014         (plus:SI (match_dup 1)
14015                  (const_int -1)))
14016    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14017    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14018   "TARGET_32BIT && find_reg_note (insn, REG_NONNEG, 0)"
14019   "*
14020 {
14021   if (which_alternative != 0)
14022     return \"#\";
14023   else if (get_attr_length (insn) == 4)
14024     return \"{bdn|bdnz} %l0\";
14025   else
14026     return \"bdz $+8\;b %l0\";
14027 }"
14028   [(set_attr "type" "branch")
14029    (set_attr "length" "*,12,16,16")])
14030
14031 (define_insn "*ctrsi_internal4"
14032   [(set (pc)
14033         (if_then_else (ge (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14034                           (const_int 0))
14035                       (pc)
14036                       (label_ref (match_operand 0 "" ""))))
14037    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14038         (plus:SI (match_dup 1)
14039                  (const_int -1)))
14040    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14041    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14042   "TARGET_32BIT && find_reg_note (insn, REG_NONNEG, 0)"
14043   "*
14044 {
14045   if (which_alternative != 0)
14046     return \"#\";
14047   else if (get_attr_length (insn) == 4)
14048     return \"bdz %l0\";
14049   else
14050     return \"{bdn|bdnz} $+8\;b %l0\";
14051 }"
14052   [(set_attr "type" "branch")
14053    (set_attr "length" "*,12,16,16")])
14054
14055 (define_insn "*ctrdi_internal3"
14056   [(set (pc)
14057         (if_then_else (ge (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14058                           (const_int 0))
14059                       (label_ref (match_operand 0 "" ""))
14060                       (pc)))
14061    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14062         (plus:DI (match_dup 1)
14063                  (const_int -1)))
14064    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14065    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14066   "TARGET_64BIT && find_reg_note (insn, REG_NONNEG, 0)"
14067   "*
14068 {
14069   if (which_alternative != 0)
14070     return \"#\";
14071   else if (get_attr_length (insn) == 4)
14072     return \"{bdn|bdnz} %l0\";
14073   else
14074     return \"bdz $+8\;b %l0\";
14075 }"
14076   [(set_attr "type" "branch")
14077    (set_attr "length" "*,12,16,16")])
14078
14079 (define_insn "*ctrdi_internal4"
14080   [(set (pc)
14081         (if_then_else (ge (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14082                           (const_int 0))
14083                       (pc)
14084                       (label_ref (match_operand 0 "" ""))))
14085    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14086         (plus:DI (match_dup 1)
14087                  (const_int -1)))
14088    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14089    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14090   "TARGET_64BIT && find_reg_note (insn, REG_NONNEG, 0)"
14091   "*
14092 {
14093   if (which_alternative != 0)
14094     return \"#\";
14095   else if (get_attr_length (insn) == 4)
14096     return \"bdz %l0\";
14097   else
14098     return \"{bdn|bdnz} $+8\;b %l0\";
14099 }"
14100   [(set_attr "type" "branch")
14101    (set_attr "length" "*,12,16,16")])
14102
14103 ;; Similar but use EQ
14104
14105 (define_insn "*ctrsi_internal5"
14106   [(set (pc)
14107         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14108                           (const_int 1))
14109                       (label_ref (match_operand 0 "" ""))
14110                       (pc)))
14111    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14112         (plus:SI (match_dup 1)
14113                  (const_int -1)))
14114    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14115    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14116   "TARGET_32BIT"
14117   "*
14118 {
14119   if (which_alternative != 0)
14120     return \"#\";
14121   else if (get_attr_length (insn) == 4)
14122     return \"bdz %l0\";
14123   else
14124     return \"{bdn|bdnz} $+8\;b %l0\";
14125 }"
14126   [(set_attr "type" "branch")
14127    (set_attr "length" "*,12,16,16")])
14128
14129 (define_insn "*ctrsi_internal6"
14130   [(set (pc)
14131         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14132                           (const_int 1))
14133                       (pc)
14134                       (label_ref (match_operand 0 "" ""))))
14135    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14136         (plus:SI (match_dup 1)
14137                  (const_int -1)))
14138    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14139    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14140   "TARGET_32BIT"
14141   "*
14142 {
14143   if (which_alternative != 0)
14144     return \"#\";
14145   else if (get_attr_length (insn) == 4)
14146     return \"{bdn|bdnz} %l0\";
14147   else
14148     return \"bdz $+8\;b %l0\";
14149 }"
14150   [(set_attr "type" "branch")
14151    (set_attr "length" "*,12,16,16")])
14152
14153 (define_insn "*ctrdi_internal5"
14154   [(set (pc)
14155         (if_then_else (eq (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14156                           (const_int 1))
14157                       (label_ref (match_operand 0 "" ""))
14158                       (pc)))
14159    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14160         (plus:DI (match_dup 1)
14161                  (const_int -1)))
14162    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14163    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14164   "TARGET_64BIT"
14165   "*
14166 {
14167   if (which_alternative != 0)
14168     return \"#\";
14169   else if (get_attr_length (insn) == 4)
14170     return \"bdz %l0\";
14171   else
14172     return \"{bdn|bdnz} $+8\;b %l0\";
14173 }"
14174   [(set_attr "type" "branch")
14175    (set_attr "length" "*,12,16,16")])
14176
14177 (define_insn "*ctrdi_internal6"
14178   [(set (pc)
14179         (if_then_else (eq (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14180                           (const_int 1))
14181                       (pc)
14182                       (label_ref (match_operand 0 "" ""))))
14183    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14184         (plus:DI (match_dup 1)
14185                  (const_int -1)))
14186    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14187    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14188   "TARGET_64BIT"
14189   "*
14190 {
14191   if (which_alternative != 0)
14192     return \"#\";
14193   else if (get_attr_length (insn) == 4)
14194     return \"{bdn|bdnz} %l0\";
14195   else
14196     return \"bdz $+8\;b %l0\";
14197 }"
14198   [(set_attr "type" "branch")
14199    (set_attr "length" "*,12,16,16")])
14200
14201 ;; Now the splitters if we could not allocate the CTR register
14202
14203 (define_split
14204   [(set (pc)
14205         (if_then_else (match_operator 2 "comparison_operator"
14206                                       [(match_operand:SI 1 "gpc_reg_operand" "")
14207                                        (const_int 1)])
14208                       (match_operand 5 "" "")
14209                       (match_operand 6 "" "")))
14210    (set (match_operand:SI 0 "gpc_reg_operand" "")
14211         (plus:SI (match_dup 1)
14212                  (const_int -1)))
14213    (clobber (match_scratch:CC 3 ""))
14214    (clobber (match_scratch:SI 4 ""))]
14215   "TARGET_32BIT && reload_completed"
14216   [(parallel [(set (match_dup 3)
14217                    (compare:CC (plus:SI (match_dup 1)
14218                                         (const_int -1))
14219                                (const_int 0)))
14220               (set (match_dup 0)
14221                    (plus:SI (match_dup 1)
14222                             (const_int -1)))])
14223    (set (pc) (if_then_else (match_dup 7)
14224                            (match_dup 5)
14225                            (match_dup 6)))]
14226   "
14227 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14228                                 operands[3], const0_rtx); }")
14229
14230 (define_split
14231   [(set (pc)
14232         (if_then_else (match_operator 2 "comparison_operator"
14233                                       [(match_operand:SI 1 "gpc_reg_operand" "")
14234                                        (const_int 1)])
14235                       (match_operand 5 "" "")
14236                       (match_operand 6 "" "")))
14237    (set (match_operand:SI 0 "nonimmediate_operand" "")
14238         (plus:SI (match_dup 1) (const_int -1)))
14239    (clobber (match_scratch:CC 3 ""))
14240    (clobber (match_scratch:SI 4 ""))]
14241   "TARGET_32BIT && reload_completed
14242    && ! gpc_reg_operand (operands[0], SImode)"
14243   [(parallel [(set (match_dup 3)
14244                    (compare:CC (plus:SI (match_dup 1)
14245                                         (const_int -1))
14246                                (const_int 0)))
14247               (set (match_dup 4)
14248                    (plus:SI (match_dup 1)
14249                             (const_int -1)))])
14250    (set (match_dup 0)
14251         (match_dup 4))
14252    (set (pc) (if_then_else (match_dup 7)
14253                            (match_dup 5)
14254                            (match_dup 6)))]
14255   "
14256 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14257                                 operands[3], const0_rtx); }")
14258 (define_split
14259   [(set (pc)
14260         (if_then_else (match_operator 2 "comparison_operator"
14261                                       [(match_operand:DI 1 "gpc_reg_operand" "")
14262                                        (const_int 1)])
14263                       (match_operand 5 "" "")
14264                       (match_operand 6 "" "")))
14265    (set (match_operand:DI 0 "gpc_reg_operand" "")
14266         (plus:DI (match_dup 1)
14267                  (const_int -1)))
14268    (clobber (match_scratch:CC 3 ""))
14269    (clobber (match_scratch:DI 4 ""))]
14270   "TARGET_64BIT && reload_completed"
14271   [(parallel [(set (match_dup 3)
14272                    (compare:CC (plus:DI (match_dup 1)
14273                                         (const_int -1))
14274                                (const_int 0)))
14275               (set (match_dup 0)
14276                    (plus:DI (match_dup 1)
14277                             (const_int -1)))])
14278    (set (pc) (if_then_else (match_dup 7)
14279                            (match_dup 5)
14280                            (match_dup 6)))]
14281   "
14282 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14283                                 operands[3], const0_rtx); }")
14284
14285 (define_split
14286   [(set (pc)
14287         (if_then_else (match_operator 2 "comparison_operator"
14288                                       [(match_operand:DI 1 "gpc_reg_operand" "")
14289                                        (const_int 1)])
14290                       (match_operand 5 "" "")
14291                       (match_operand 6 "" "")))
14292    (set (match_operand:DI 0 "nonimmediate_operand" "")
14293         (plus:DI (match_dup 1) (const_int -1)))
14294    (clobber (match_scratch:CC 3 ""))
14295    (clobber (match_scratch:DI 4 ""))]
14296   "TARGET_64BIT && reload_completed
14297    && ! gpc_reg_operand (operands[0], DImode)"
14298   [(parallel [(set (match_dup 3)
14299                    (compare:CC (plus:DI (match_dup 1)
14300                                         (const_int -1))
14301                                (const_int 0)))
14302               (set (match_dup 4)
14303                    (plus:DI (match_dup 1)
14304                             (const_int -1)))])
14305    (set (match_dup 0)
14306         (match_dup 4))
14307    (set (pc) (if_then_else (match_dup 7)
14308                            (match_dup 5)
14309                            (match_dup 6)))]
14310   "
14311 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14312                                 operands[3], const0_rtx); }")
14313 \f
14314 (define_insn "trap"
14315   [(trap_if (const_int 1) (const_int 0))]
14316   ""
14317   "{t 31,0,0|trap}")
14318
14319 (define_expand "conditional_trap"
14320   [(trap_if (match_operator 0 "trap_comparison_operator"
14321                             [(match_dup 2) (match_dup 3)])
14322             (match_operand 1 "const_int_operand" ""))]
14323   ""
14324   "if (rs6000_compare_fp_p || operands[1] != const0_rtx) FAIL;
14325    operands[2] = rs6000_compare_op0;
14326    operands[3] = rs6000_compare_op1;")
14327
14328 (define_insn ""
14329   [(trap_if (match_operator 0 "trap_comparison_operator"
14330                             [(match_operand:SI 1 "register_operand" "r")
14331                              (match_operand:SI 2 "reg_or_short_operand" "rI")])
14332             (const_int 0))]
14333   ""
14334   "{t|tw}%V0%I2 %1,%2")
14335
14336 (define_insn ""
14337   [(trap_if (match_operator 0 "trap_comparison_operator"
14338                             [(match_operand:DI 1 "register_operand" "r")
14339                              (match_operand:DI 2 "reg_or_short_operand" "rI")])
14340             (const_int 0))]
14341   "TARGET_POWERPC64"
14342   "td%V0%I2 %1,%2")
14343 \f
14344 ;; Insns related to generating the function prologue and epilogue.
14345
14346 (define_expand "prologue"
14347   [(use (const_int 0))]
14348   "TARGET_SCHED_PROLOG"
14349   "
14350 {
14351       rs6000_emit_prologue ();
14352       DONE;
14353 }")
14354
14355 (define_insn "*movesi_from_cr_one"
14356   [(match_parallel 0 "mfcr_operation"
14357                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14358                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
14359                                      (match_operand 3 "immediate_operand" "n")]
14360                           UNSPEC_MOVESI_FROM_CR))])]
14361   "TARGET_MFCRF"
14362   "*
14363 {
14364   int mask = 0;
14365   int i;
14366   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14367   {
14368     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14369     operands[4] = GEN_INT (mask);
14370     output_asm_insn (\"mfcr %1,%4\", operands);
14371   }
14372   return \"\";
14373 }"
14374   [(set_attr "type" "mfcrf")])
14375
14376 (define_insn "movesi_from_cr"
14377   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14378         (unspec:SI [(reg:CC 68) (reg:CC 69) (reg:CC 70) (reg:CC 71)
14379                     (reg:CC 72) (reg:CC 73) (reg:CC 74) (reg:CC 75)]
14380                    UNSPEC_MOVESI_FROM_CR))]
14381   ""
14382   "mfcr %0"
14383   [(set_attr "type" "mfcr")])
14384
14385 (define_insn "*stmw"
14386   [(match_parallel 0 "stmw_operation"
14387                    [(set (match_operand:SI 1 "memory_operand" "=m")
14388                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
14389   "TARGET_MULTIPLE"
14390   "{stm|stmw} %2,%1")
14391
14392 (define_insn "*save_fpregs_si"
14393   [(match_parallel 0 "any_operand"
14394                    [(clobber (match_operand:SI 1 "register_operand" "=l"))
14395                     (use (match_operand:SI 2 "call_operand" "s"))
14396                     (set (match_operand:DF 3 "memory_operand" "=m")
14397                          (match_operand:DF 4 "gpc_reg_operand" "f"))])]
14398   "TARGET_32BIT"
14399   "bl %z2"
14400   [(set_attr "type" "branch")
14401    (set_attr "length" "4")])
14402
14403 (define_insn "*save_fpregs_di"
14404   [(match_parallel 0 "any_operand"
14405                    [(clobber (match_operand:DI 1 "register_operand" "=l"))
14406                     (use (match_operand:DI 2 "call_operand" "s"))
14407                     (set (match_operand:DF 3 "memory_operand" "=m")
14408                          (match_operand:DF 4 "gpc_reg_operand" "f"))])]
14409   "TARGET_64BIT"
14410   "bl %z2"
14411   [(set_attr "type" "branch")
14412    (set_attr "length" "4")])
14413
14414 ; These are to explain that changes to the stack pointer should
14415 ; not be moved over stores to stack memory.
14416 (define_insn "stack_tie"
14417   [(set (match_operand:BLK 0 "memory_operand" "+m")
14418         (unspec:BLK [(match_dup 0)] UNSPEC_TIE))]
14419   ""
14420   ""
14421   [(set_attr "length" "0")])
14422
14423
14424 (define_expand "epilogue"
14425   [(use (const_int 0))]
14426   "TARGET_SCHED_PROLOG"
14427   "
14428 {
14429       rs6000_emit_epilogue (FALSE);
14430       DONE;
14431 }")
14432
14433 ; On some processors, doing the mtcrf one CC register at a time is
14434 ; faster (like on the 604e).  On others, doing them all at once is
14435 ; faster; for instance, on the 601 and 750.
14436
14437 (define_expand "movsi_to_cr_one"
14438   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14439         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14440                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
14441   ""
14442   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
14443
14444 (define_insn "*movsi_to_cr"
14445   [(match_parallel 0 "mtcrf_operation"
14446                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
14447                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
14448                                      (match_operand 3 "immediate_operand" "n")]
14449                                     UNSPEC_MOVESI_TO_CR))])]
14450  ""
14451  "*
14452 {
14453   int mask = 0;
14454   int i;
14455   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14456     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14457   operands[4] = GEN_INT (mask);
14458   return \"mtcrf %4,%2\";
14459 }"
14460   [(set_attr "type" "mtcr")])
14461
14462 (define_insn "*mtcrfsi"
14463   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14464         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14465                     (match_operand 2 "immediate_operand" "n")]
14466                    UNSPEC_MOVESI_TO_CR))]
14467   "GET_CODE (operands[0]) == REG
14468    && CR_REGNO_P (REGNO (operands[0]))
14469    && GET_CODE (operands[2]) == CONST_INT
14470    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
14471   "mtcrf %R0,%1"
14472   [(set_attr "type" "mtcr")])
14473
14474 ; The load-multiple instructions have similar properties.
14475 ; Note that "load_multiple" is a name known to the machine-independent
14476 ; code that actually corresponds to the powerpc load-string.
14477
14478 (define_insn "*lmw"
14479   [(match_parallel 0 "lmw_operation"
14480                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14481                          (match_operand:SI 2 "memory_operand" "m"))])]
14482   "TARGET_MULTIPLE"
14483   "{lm|lmw} %1,%2")
14484
14485 (define_insn "*return_internal_si"
14486   [(return)
14487    (use (match_operand:SI 0 "register_operand" "lc"))]
14488   "TARGET_32BIT"
14489   "b%T0"
14490   [(set_attr "type" "jmpreg")])
14491
14492 (define_insn "*return_internal_di"
14493   [(return)
14494    (use (match_operand:DI 0 "register_operand" "lc"))]
14495   "TARGET_64BIT"
14496   "b%T0"
14497   [(set_attr "type" "jmpreg")])
14498
14499 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
14500 ; stuff was in GCC.  Oh, and "any_operand" is a bit flexible...
14501
14502 (define_insn "*return_and_restore_fpregs_si"
14503  [(match_parallel 0 "any_operand"
14504                   [(return)
14505                    (use (match_operand:SI 1 "register_operand" "l"))
14506                    (use (match_operand:SI 2 "call_operand" "s"))
14507                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
14508                         (match_operand:DF 4 "memory_operand" "m"))])]
14509  "TARGET_32BIT"
14510  "b %z2")
14511
14512 (define_insn "*return_and_restore_fpregs_di"
14513  [(match_parallel 0 "any_operand"
14514                   [(return)
14515                    (use (match_operand:DI 1 "register_operand" "l"))
14516                    (use (match_operand:DI 2 "call_operand" "s"))
14517                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
14518                         (match_operand:DF 4 "memory_operand" "m"))])]
14519  "TARGET_64BIT"
14520  "b %z2")
14521
14522 ; This is used in compiling the unwind routines.
14523 (define_expand "eh_return"
14524   [(use (match_operand 0 "general_operand" ""))]
14525   ""
14526   "
14527 {
14528   if (TARGET_32BIT)
14529     emit_insn (gen_eh_set_lr_si (operands[0]));
14530   else
14531     emit_insn (gen_eh_set_lr_di (operands[0]));
14532   DONE;
14533 }")
14534
14535 ; We can't expand this before we know where the link register is stored.
14536 (define_insn "eh_set_lr_si"
14537   [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
14538                     UNSPECV_EH_RR)
14539    (clobber (match_scratch:SI 1 "=&b"))]
14540   "TARGET_32BIT"
14541   "#")
14542
14543 (define_insn "eh_set_lr_di"
14544   [(unspec_volatile [(match_operand:DI 0 "register_operand" "r")]
14545                     UNSPECV_EH_RR)
14546    (clobber (match_scratch:DI 1 "=&b"))]
14547   "TARGET_64BIT"
14548   "#")
14549
14550 (define_split
14551   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
14552    (clobber (match_scratch 1 ""))]
14553   "reload_completed"
14554   [(const_int 0)]
14555   "
14556 {
14557   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
14558   DONE;
14559 }")
14560
14561 (define_insn "prefetch"
14562   [(prefetch (match_operand:V4SI 0 "address_operand" "p")
14563              (match_operand:SI 1 "const_int_operand" "n")
14564              (match_operand:SI 2 "const_int_operand" "n"))]
14565   "TARGET_POWERPC"
14566   "*
14567 {
14568   if (GET_CODE (operands[0]) == REG)
14569     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
14570   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
14571 }"
14572   [(set_attr "type" "load")])
14573
14574 (include "altivec.md")
14575 (include "spe.md")