OSDN Git Service

* config/rs6000/rs6000.md (eq): Convert to define_insn_and_split.
[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, 2005 Free Software Foundation, Inc.
4 ;; Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
5
6 ;; This file is part of GCC.
7
8 ;; GCC is free software; you can redistribute it and/or modify it
9 ;; under the terms of the GNU General Public License as published
10 ;; by the Free Software Foundation; either version 2, or (at your
11 ;; option) any later version.
12
13 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
14 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16 ;; License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING.  If not, write to the
20 ;; Free Software Foundation, 59 Temple Place - Suite 330, Boston,
21 ;; MA 02111-1307, USA.
22
23 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
24
25 ;;
26 ;; UNSPEC usage
27 ;;
28
29 (define_constants
30   [(UNSPEC_FRSP                 0)      ; frsp for POWER machines
31    (UNSPEC_TIE                  5)      ; tie stack contents and stack pointer
32    (UNSPEC_TOCPTR               6)      ; address of a word pointing to the TOC
33    (UNSPEC_TOC                  7)      ; address of the TOC (more-or-less)
34    (UNSPEC_MOVSI_GOT            8)
35    (UNSPEC_MV_CR_OV             9)      ; move_from_CR_ov_bit
36    (UNSPEC_FCTIWZ               10)
37    (UNSPEC_LD_MPIC              15)     ; load_macho_picbase
38    (UNSPEC_MPIC_CORRECT         16)     ; macho_correct_pic
39    (UNSPEC_TLSGD                17)
40    (UNSPEC_TLSLD                18)
41    (UNSPEC_MOVESI_FROM_CR       19)
42    (UNSPEC_MOVESI_TO_CR         20)
43    (UNSPEC_TLSDTPREL            21)
44    (UNSPEC_TLSDTPRELHA          22)
45    (UNSPEC_TLSDTPRELLO          23)
46    (UNSPEC_TLSGOTDTPREL         24)
47    (UNSPEC_TLSTPREL             25)
48    (UNSPEC_TLSTPRELHA           26)
49    (UNSPEC_TLSTPRELLO           27)
50    (UNSPEC_TLSGOTTPREL          28)
51    (UNSPEC_TLSTLS               29)
52    (UNSPEC_FIX_TRUNC_TF         30)     ; fadd, rounding towards zero
53    (UNSPEC_MV_CR_GT             31)     ; move_from_CR_eq_bit
54    (UNSPEC_STFIWX               32)
55    (UNSPEC_SYNC                 33)
56    (UNSPEC_SYNC_OP              34)
57    (UNSPEC_SYNC_SWAP            35)
58    (UNSPEC_LWSYNC               36)
59    (UNSPEC_ISYNC                37)
60    (UNSPEC_POPCNTB              38)
61    (UNSPEC_FRES                 39)
62   ])
63
64 ;;
65 ;; UNSPEC_VOLATILE usage
66 ;;
67
68 (define_constants
69   [(UNSPECV_BLOCK               0)
70    (UNSPECV_EH_RR               9)      ; eh_reg_restore
71   ])
72 \f
73 ;; Define an insn type attribute.  This is used in function unit delay
74 ;; computations.
75 (define_attr "type" "integer,two,three,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"
76   (const_string "integer"))
77
78 ;; Length (in bytes).
79 ; '(pc)' in the following doesn't include the instruction itself; it is
80 ; calculated as if the instruction had zero size.
81 (define_attr "length" ""
82   (if_then_else (eq_attr "type" "branch")
83                 (if_then_else (and (ge (minus (match_dup 0) (pc))
84                                        (const_int -32768))
85                                    (lt (minus (match_dup 0) (pc))
86                                        (const_int 32764)))
87                               (const_int 4)
88                               (const_int 8))
89                 (const_int 4)))
90
91 ;; Processor type -- this attribute must exactly match the processor_type
92 ;; enumeration in rs6000.h.
93
94 (define_attr "cpu" "rios1,rios2,rs64a,mpccore,ppc403,ppc405,ppc440,ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630,ppc750,ppc7400,ppc7450,ppc8540,power4,power5"
95   (const (symbol_ref "rs6000_cpu_attr")))
96
97 (automata_option "ndfa")
98
99 (include "rios1.md")
100 (include "rios2.md")
101 (include "rs64.md")
102 (include "mpc.md")
103 (include "40x.md")
104 (include "440.md")
105 (include "603.md")
106 (include "6xx.md")
107 (include "7xx.md")
108 (include "7450.md")
109 (include "8540.md")
110 (include "power4.md")
111 (include "power5.md")
112
113 (include "predicates.md")
114
115 (include "darwin.md")
116
117 \f
118 ;; Mode macros
119
120 ; This mode macro allows :GPR to be used to indicate the allowable size
121 ; of whole values in GPRs.
122 (define_mode_macro GPR [SI (DI "TARGET_POWERPC64")])
123
124 ; Any supported integer mode.
125 (define_mode_macro INT [QI HI SI DI TI])
126
127 ; Any supported integer mode that fits in one register.
128 (define_mode_macro INT1 [QI HI SI (DI "TARGET_POWERPC64")])
129
130 ; SImode or DImode, even if DImode doesn't fit in GPRs.
131 (define_mode_macro SDI [SI DI])
132
133 ; The size of a pointer.  Also, the size of the value that a record-condition
134 ; (one with a '.') will compare.
135 (define_mode_macro P [(SI "TARGET_32BIT") (DI "TARGET_64BIT")])
136
137 ; Various instructions that come in SI and DI forms.
138 (define_mode_attr larx [(SI "lwarx") (DI "ldarx")])
139 (define_mode_attr stcx [(SI "stwcx.") (DI "stdcx.")])
140 ; A generic w/d attribute, for things like cmpw/cmpd.
141 (define_mode_attr wd [(SI "w") (DI "d")])
142
143 \f
144 ;; Start with fixed-point load and store insns.  Here we put only the more
145 ;; complex forms.  Basic data transfer is done later.
146
147 (define_expand "zero_extendqidi2"
148   [(set (match_operand:DI 0 "gpc_reg_operand" "")
149         (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "")))]
150   "TARGET_POWERPC64"
151   "")
152
153 (define_insn ""
154   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
155         (zero_extend:DI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
156   "TARGET_POWERPC64"
157   "@
158    lbz%U1%X1 %0,%1
159    rldicl %0,%1,0,56"
160   [(set_attr "type" "load,*")])
161
162 (define_insn ""
163   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
164         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
165                     (const_int 0)))
166    (clobber (match_scratch:DI 2 "=r,r"))]
167   "TARGET_64BIT"
168   "@
169    rldicl. %2,%1,0,56
170    #"
171   [(set_attr "type" "compare")
172    (set_attr "length" "4,8")])
173
174 (define_split
175   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
176         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
177                     (const_int 0)))
178    (clobber (match_scratch:DI 2 ""))]
179   "TARGET_POWERPC64 && reload_completed"
180   [(set (match_dup 2)
181         (zero_extend:DI (match_dup 1)))
182    (set (match_dup 0)
183         (compare:CC (match_dup 2)
184                     (const_int 0)))]
185   "")
186
187 (define_insn ""
188   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
189         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
190                     (const_int 0)))
191    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
192         (zero_extend:DI (match_dup 1)))]
193   "TARGET_64BIT"
194   "@
195    rldicl. %0,%1,0,56
196    #"
197   [(set_attr "type" "compare")
198    (set_attr "length" "4,8")])
199
200 (define_split
201   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
202         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
203                     (const_int 0)))
204    (set (match_operand:DI 0 "gpc_reg_operand" "")
205         (zero_extend:DI (match_dup 1)))]
206   "TARGET_POWERPC64 && reload_completed"
207   [(set (match_dup 0)
208         (zero_extend:DI (match_dup 1)))
209    (set (match_dup 2)
210         (compare:CC (match_dup 0)
211                     (const_int 0)))]
212   "")
213
214 (define_insn "extendqidi2"
215   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
216         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
217   "TARGET_POWERPC64"
218   "extsb %0,%1")
219
220 (define_insn ""
221   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
222         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
223                     (const_int 0)))
224    (clobber (match_scratch:DI 2 "=r,r"))]
225   "TARGET_64BIT"
226   "@
227    extsb. %2,%1
228    #"
229   [(set_attr "type" "compare")
230    (set_attr "length" "4,8")])
231
232 (define_split
233   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
234         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
235                     (const_int 0)))
236    (clobber (match_scratch:DI 2 ""))]
237   "TARGET_POWERPC64 && reload_completed"
238   [(set (match_dup 2)
239         (sign_extend:DI (match_dup 1)))
240    (set (match_dup 0)
241         (compare:CC (match_dup 2)
242                     (const_int 0)))]
243   "")
244
245 (define_insn ""
246   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
247         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
248                     (const_int 0)))
249    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
250         (sign_extend:DI (match_dup 1)))]
251   "TARGET_64BIT"
252   "@
253    extsb. %0,%1
254    #"
255   [(set_attr "type" "compare")
256    (set_attr "length" "4,8")])
257
258 (define_split
259   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
260         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
261                     (const_int 0)))
262    (set (match_operand:DI 0 "gpc_reg_operand" "")
263         (sign_extend:DI (match_dup 1)))]
264   "TARGET_POWERPC64 && reload_completed"
265   [(set (match_dup 0)
266         (sign_extend:DI (match_dup 1)))
267    (set (match_dup 2)
268         (compare:CC (match_dup 0)
269                     (const_int 0)))]
270   "")
271
272 (define_expand "zero_extendhidi2"
273   [(set (match_operand:DI 0 "gpc_reg_operand" "")
274         (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
275   "TARGET_POWERPC64"
276   "")
277
278 (define_insn ""
279   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
280         (zero_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
281   "TARGET_POWERPC64"
282   "@
283    lhz%U1%X1 %0,%1
284    rldicl %0,%1,0,48"
285   [(set_attr "type" "load,*")])
286
287 (define_insn ""
288   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
289         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
290                     (const_int 0)))
291    (clobber (match_scratch:DI 2 "=r,r"))]
292   "TARGET_64BIT"
293   "@
294    rldicl. %2,%1,0,48
295    #"
296   [(set_attr "type" "compare")
297    (set_attr "length" "4,8")])
298
299 (define_split
300   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
301         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
302                     (const_int 0)))
303    (clobber (match_scratch:DI 2 ""))]
304   "TARGET_POWERPC64 && reload_completed"
305   [(set (match_dup 2)
306         (zero_extend:DI (match_dup 1)))
307    (set (match_dup 0)
308         (compare:CC (match_dup 2)
309                     (const_int 0)))]
310   "")
311
312 (define_insn ""
313   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
314         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
315                     (const_int 0)))
316    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
317         (zero_extend:DI (match_dup 1)))]
318   "TARGET_64BIT"
319   "@
320    rldicl. %0,%1,0,48
321    #"
322   [(set_attr "type" "compare")
323    (set_attr "length" "4,8")])
324
325 (define_split
326   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
327         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
328                     (const_int 0)))
329    (set (match_operand:DI 0 "gpc_reg_operand" "")
330         (zero_extend:DI (match_dup 1)))]
331   "TARGET_POWERPC64 && reload_completed"
332   [(set (match_dup 0)
333         (zero_extend:DI (match_dup 1)))
334    (set (match_dup 2)
335         (compare:CC (match_dup 0)
336                     (const_int 0)))]
337   "")
338
339 (define_expand "extendhidi2"
340   [(set (match_operand:DI 0 "gpc_reg_operand" "")
341         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
342   "TARGET_POWERPC64"
343   "")
344
345 (define_insn ""
346   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
347         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
348   "TARGET_POWERPC64"
349   "@
350    lha%U1%X1 %0,%1
351    extsh %0,%1"
352   [(set_attr "type" "load_ext,*")])
353
354 (define_insn ""
355   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
356         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
357                     (const_int 0)))
358    (clobber (match_scratch:DI 2 "=r,r"))]
359   "TARGET_64BIT"
360   "@
361    extsh. %2,%1
362    #"
363   [(set_attr "type" "compare")
364    (set_attr "length" "4,8")])
365
366 (define_split
367   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
368         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
369                     (const_int 0)))
370    (clobber (match_scratch:DI 2 ""))]
371   "TARGET_POWERPC64 && reload_completed"
372   [(set (match_dup 2)
373         (sign_extend:DI (match_dup 1)))
374    (set (match_dup 0)
375         (compare:CC (match_dup 2)
376                     (const_int 0)))]
377   "")
378
379 (define_insn ""
380   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
381         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
382                     (const_int 0)))
383    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
384         (sign_extend:DI (match_dup 1)))]
385   "TARGET_64BIT"
386   "@
387    extsh. %0,%1
388    #"
389   [(set_attr "type" "compare")
390    (set_attr "length" "4,8")])
391
392 (define_split
393   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
394         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
395                     (const_int 0)))
396    (set (match_operand:DI 0 "gpc_reg_operand" "")
397         (sign_extend:DI (match_dup 1)))]
398   "TARGET_POWERPC64 && reload_completed"
399   [(set (match_dup 0)
400         (sign_extend:DI (match_dup 1)))
401    (set (match_dup 2)
402         (compare:CC (match_dup 0)
403                     (const_int 0)))]
404   "")
405
406 (define_expand "zero_extendsidi2"
407   [(set (match_operand:DI 0 "gpc_reg_operand" "")
408         (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
409   "TARGET_POWERPC64"
410   "")
411
412 (define_insn ""
413   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
414         (zero_extend:DI (match_operand:SI 1 "reg_or_mem_operand" "m,r")))]
415   "TARGET_POWERPC64"
416   "@
417    lwz%U1%X1 %0,%1
418    rldicl %0,%1,0,32"
419   [(set_attr "type" "load,*")])
420
421 (define_insn ""
422   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
423         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
424                     (const_int 0)))
425    (clobber (match_scratch:DI 2 "=r,r"))]
426   "TARGET_64BIT"
427   "@
428    rldicl. %2,%1,0,32
429    #"
430   [(set_attr "type" "compare")
431    (set_attr "length" "4,8")])
432
433 (define_split
434   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
435         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
436                     (const_int 0)))
437    (clobber (match_scratch:DI 2 ""))]
438   "TARGET_POWERPC64 && reload_completed"
439   [(set (match_dup 2)
440         (zero_extend:DI (match_dup 1)))
441    (set (match_dup 0)
442         (compare:CC (match_dup 2)
443                     (const_int 0)))]
444   "")
445
446 (define_insn ""
447   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
448         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
449                     (const_int 0)))
450    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
451         (zero_extend:DI (match_dup 1)))]
452   "TARGET_64BIT"
453   "@
454    rldicl. %0,%1,0,32
455    #"
456   [(set_attr "type" "compare")
457    (set_attr "length" "4,8")])
458
459 (define_split
460   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
461         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
462                     (const_int 0)))
463    (set (match_operand:DI 0 "gpc_reg_operand" "")
464         (zero_extend:DI (match_dup 1)))]
465   "TARGET_POWERPC64 && reload_completed"
466   [(set (match_dup 0)
467         (zero_extend:DI (match_dup 1)))
468    (set (match_dup 2)
469         (compare:CC (match_dup 0)
470                     (const_int 0)))]
471   "")
472
473 (define_expand "extendsidi2"
474   [(set (match_operand:DI 0 "gpc_reg_operand" "")
475         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
476   "TARGET_POWERPC64"
477   "")
478
479 (define_insn ""
480   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
481         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
482   "TARGET_POWERPC64"
483   "@
484    lwa%U1%X1 %0,%1
485    extsw %0,%1"
486   [(set_attr "type" "load_ext,*")])
487
488 (define_insn ""
489   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
490         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
491                     (const_int 0)))
492    (clobber (match_scratch:DI 2 "=r,r"))]
493   "TARGET_64BIT"
494   "@
495    extsw. %2,%1
496    #"
497   [(set_attr "type" "compare")
498    (set_attr "length" "4,8")])
499
500 (define_split
501   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
502         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
503                     (const_int 0)))
504    (clobber (match_scratch:DI 2 ""))]
505   "TARGET_POWERPC64 && reload_completed"
506   [(set (match_dup 2)
507         (sign_extend:DI (match_dup 1)))
508    (set (match_dup 0)
509         (compare:CC (match_dup 2)
510                     (const_int 0)))]
511   "")
512
513 (define_insn ""
514   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
515         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
516                     (const_int 0)))
517    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
518         (sign_extend:DI (match_dup 1)))]
519   "TARGET_64BIT"
520   "@
521    extsw. %0,%1
522    #"
523   [(set_attr "type" "compare")
524    (set_attr "length" "4,8")])
525
526 (define_split
527   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
528         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
529                     (const_int 0)))
530    (set (match_operand:DI 0 "gpc_reg_operand" "")
531         (sign_extend:DI (match_dup 1)))]
532   "TARGET_POWERPC64 && reload_completed"
533   [(set (match_dup 0)
534         (sign_extend:DI (match_dup 1)))
535    (set (match_dup 2)
536         (compare:CC (match_dup 0)
537                     (const_int 0)))]
538   "")
539
540 (define_expand "zero_extendqisi2"
541   [(set (match_operand:SI 0 "gpc_reg_operand" "")
542         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
543   ""
544   "")
545
546 (define_insn ""
547   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
548         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
549   ""
550   "@
551    lbz%U1%X1 %0,%1
552    {rlinm|rlwinm} %0,%1,0,0xff"
553   [(set_attr "type" "load,*")])
554
555 (define_insn ""
556   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
557         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
558                     (const_int 0)))
559    (clobber (match_scratch:SI 2 "=r,r"))]
560   ""
561   "@
562    {andil.|andi.} %2,%1,0xff
563    #"
564   [(set_attr "type" "compare")
565    (set_attr "length" "4,8")])
566
567 (define_split
568   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
569         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
570                     (const_int 0)))
571    (clobber (match_scratch:SI 2 ""))]
572   "reload_completed"
573   [(set (match_dup 2)
574         (zero_extend:SI (match_dup 1)))
575    (set (match_dup 0)
576         (compare:CC (match_dup 2)
577                     (const_int 0)))]
578   "")
579
580 (define_insn ""
581   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
582         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
583                     (const_int 0)))
584    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
585         (zero_extend:SI (match_dup 1)))]
586   ""
587   "@
588    {andil.|andi.} %0,%1,0xff
589    #"
590   [(set_attr "type" "compare")
591    (set_attr "length" "4,8")])
592
593 (define_split
594   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
595         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
596                     (const_int 0)))
597    (set (match_operand:SI 0 "gpc_reg_operand" "")
598         (zero_extend:SI (match_dup 1)))]
599   "reload_completed"
600   [(set (match_dup 0)
601         (zero_extend:SI (match_dup 1)))
602    (set (match_dup 2)
603         (compare:CC (match_dup 0)
604                     (const_int 0)))]
605   "")
606
607 (define_expand "extendqisi2"
608   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
609    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
610   ""
611   "
612 {
613   if (TARGET_POWERPC)
614     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
615   else if (TARGET_POWER)
616     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
617   else
618     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
619   DONE;
620 }")
621
622 (define_insn "extendqisi2_ppc"
623   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
624         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
625   "TARGET_POWERPC"
626   "extsb %0,%1")
627
628 (define_insn ""
629   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
630         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
631                     (const_int 0)))
632    (clobber (match_scratch:SI 2 "=r,r"))]
633   "TARGET_POWERPC"
634   "@
635    extsb. %2,%1
636    #"
637   [(set_attr "type" "compare")
638    (set_attr "length" "4,8")])
639
640 (define_split
641   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
642         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
643                     (const_int 0)))
644    (clobber (match_scratch:SI 2 ""))]
645   "TARGET_POWERPC && reload_completed"
646   [(set (match_dup 2)
647         (sign_extend:SI (match_dup 1)))
648    (set (match_dup 0)
649         (compare:CC (match_dup 2)
650                     (const_int 0)))]
651   "")
652
653 (define_insn ""
654   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
655         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
656                     (const_int 0)))
657    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
658         (sign_extend:SI (match_dup 1)))]
659   "TARGET_POWERPC"
660   "@
661    extsb. %0,%1
662    #"
663   [(set_attr "type" "compare")
664    (set_attr "length" "4,8")])
665
666 (define_split
667   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
668         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
669                     (const_int 0)))
670    (set (match_operand:SI 0 "gpc_reg_operand" "")
671         (sign_extend:SI (match_dup 1)))]
672   "TARGET_POWERPC && reload_completed"
673   [(set (match_dup 0)
674         (sign_extend:SI (match_dup 1)))
675    (set (match_dup 2)
676         (compare:CC (match_dup 0)
677                     (const_int 0)))]
678   "")
679
680 (define_expand "extendqisi2_power"
681   [(parallel [(set (match_dup 2)
682                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
683                               (const_int 24)))
684               (clobber (scratch:SI))])
685    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
686                    (ashiftrt:SI (match_dup 2)
687                                 (const_int 24)))
688               (clobber (scratch:SI))])]
689   "TARGET_POWER"
690   "
691 { operands[1] = gen_lowpart (SImode, operands[1]);
692   operands[2] = gen_reg_rtx (SImode); }")
693
694 (define_expand "extendqisi2_no_power"
695   [(set (match_dup 2)
696         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
697                    (const_int 24)))
698    (set (match_operand:SI 0 "gpc_reg_operand" "")
699         (ashiftrt:SI (match_dup 2)
700                      (const_int 24)))]
701   "! TARGET_POWER && ! TARGET_POWERPC"
702   "
703 { operands[1] = gen_lowpart (SImode, operands[1]);
704   operands[2] = gen_reg_rtx (SImode); }")
705
706 (define_expand "zero_extendqihi2"
707   [(set (match_operand:HI 0 "gpc_reg_operand" "")
708         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
709   ""
710   "")
711
712 (define_insn ""
713   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
714         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
715   ""
716   "@
717    lbz%U1%X1 %0,%1
718    {rlinm|rlwinm} %0,%1,0,0xff"
719   [(set_attr "type" "load,*")])
720
721 (define_insn ""
722   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
723         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
724                     (const_int 0)))
725    (clobber (match_scratch:HI 2 "=r,r"))]
726   ""
727   "@
728    {andil.|andi.} %2,%1,0xff
729    #"
730   [(set_attr "type" "compare")
731    (set_attr "length" "4,8")])
732
733 (define_split
734   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
735         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
736                     (const_int 0)))
737    (clobber (match_scratch:HI 2 ""))]
738   "reload_completed"
739   [(set (match_dup 2)
740         (zero_extend:HI (match_dup 1)))
741    (set (match_dup 0)
742         (compare:CC (match_dup 2)
743                     (const_int 0)))]
744   "")
745
746 (define_insn ""
747   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
748         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
749                     (const_int 0)))
750    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
751         (zero_extend:HI (match_dup 1)))]
752   ""
753   "@
754    {andil.|andi.} %0,%1,0xff
755    #"
756   [(set_attr "type" "compare")
757    (set_attr "length" "4,8")])
758
759 (define_split
760   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
761         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
762                     (const_int 0)))
763    (set (match_operand:HI 0 "gpc_reg_operand" "")
764         (zero_extend:HI (match_dup 1)))]
765   "reload_completed"
766   [(set (match_dup 0)
767         (zero_extend:HI (match_dup 1)))
768    (set (match_dup 2)
769         (compare:CC (match_dup 0)
770                     (const_int 0)))]
771   "")
772
773 (define_expand "extendqihi2"
774   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
775    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
776   ""
777   "
778 {
779   if (TARGET_POWERPC)
780     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
781   else if (TARGET_POWER)
782     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
783   else
784     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
785   DONE;
786 }")
787
788 (define_insn "extendqihi2_ppc"
789   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
790         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
791   "TARGET_POWERPC"
792   "extsb %0,%1")
793
794 (define_insn ""
795   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
796         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
797                     (const_int 0)))
798    (clobber (match_scratch:HI 2 "=r,r"))]
799   "TARGET_POWERPC"
800   "@
801    extsb. %2,%1
802    #"
803   [(set_attr "type" "compare")
804    (set_attr "length" "4,8")])
805
806 (define_split
807   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
808         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
809                     (const_int 0)))
810    (clobber (match_scratch:HI 2 ""))]
811   "TARGET_POWERPC && reload_completed"
812   [(set (match_dup 2)
813         (sign_extend:HI (match_dup 1)))
814    (set (match_dup 0)
815         (compare:CC (match_dup 2)
816                     (const_int 0)))]
817   "")
818
819 (define_insn ""
820   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
821         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
822                     (const_int 0)))
823    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
824         (sign_extend:HI (match_dup 1)))]
825   "TARGET_POWERPC"
826   "@
827    extsb. %0,%1
828    #"
829   [(set_attr "type" "compare")
830    (set_attr "length" "4,8")])
831
832 (define_split
833   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
834         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
835                     (const_int 0)))
836    (set (match_operand:HI 0 "gpc_reg_operand" "")
837         (sign_extend:HI (match_dup 1)))]
838   "TARGET_POWERPC && reload_completed"
839   [(set (match_dup 0)
840         (sign_extend:HI (match_dup 1)))
841    (set (match_dup 2)
842         (compare:CC (match_dup 0)
843                     (const_int 0)))]
844   "")
845
846 (define_expand "extendqihi2_power"
847   [(parallel [(set (match_dup 2)
848                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
849                               (const_int 24)))
850               (clobber (scratch:SI))])
851    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
852                    (ashiftrt:SI (match_dup 2)
853                                 (const_int 24)))
854               (clobber (scratch:SI))])]
855   "TARGET_POWER"
856   "
857 { operands[0] = gen_lowpart (SImode, operands[0]);
858   operands[1] = gen_lowpart (SImode, operands[1]);
859   operands[2] = gen_reg_rtx (SImode); }")
860
861 (define_expand "extendqihi2_no_power"
862   [(set (match_dup 2)
863         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
864                    (const_int 24)))
865    (set (match_operand:HI 0 "gpc_reg_operand" "")
866         (ashiftrt:SI (match_dup 2)
867                      (const_int 24)))]
868   "! TARGET_POWER && ! TARGET_POWERPC"
869   "
870 { operands[0] = gen_lowpart (SImode, operands[0]);
871   operands[1] = gen_lowpart (SImode, operands[1]);
872   operands[2] = gen_reg_rtx (SImode); }")
873
874 (define_expand "zero_extendhisi2"
875   [(set (match_operand:SI 0 "gpc_reg_operand" "")
876         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
877   ""
878   "")
879
880 (define_insn ""
881   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
882         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
883   ""
884   "@
885    lhz%U1%X1 %0,%1
886    {rlinm|rlwinm} %0,%1,0,0xffff"
887   [(set_attr "type" "load,*")])
888
889 (define_insn ""
890   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
891         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
892                     (const_int 0)))
893    (clobber (match_scratch:SI 2 "=r,r"))]
894   ""
895   "@
896    {andil.|andi.} %2,%1,0xffff
897    #"
898   [(set_attr "type" "compare")
899    (set_attr "length" "4,8")])
900
901 (define_split
902   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
903         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
904                     (const_int 0)))
905    (clobber (match_scratch:SI 2 ""))]
906   "reload_completed"
907   [(set (match_dup 2)
908         (zero_extend:SI (match_dup 1)))
909    (set (match_dup 0)
910         (compare:CC (match_dup 2)
911                     (const_int 0)))]
912   "")
913
914 (define_insn ""
915   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
916         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
917                     (const_int 0)))
918    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
919         (zero_extend:SI (match_dup 1)))]
920   ""
921   "@
922    {andil.|andi.} %0,%1,0xffff
923    #"
924   [(set_attr "type" "compare")
925    (set_attr "length" "4,8")])
926
927 (define_split
928   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
929         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
930                     (const_int 0)))
931    (set (match_operand:SI 0 "gpc_reg_operand" "")
932         (zero_extend:SI (match_dup 1)))]
933   "reload_completed"
934   [(set (match_dup 0)
935         (zero_extend:SI (match_dup 1)))
936    (set (match_dup 2)
937         (compare:CC (match_dup 0)
938                     (const_int 0)))]
939   "")
940
941 (define_expand "extendhisi2"
942   [(set (match_operand:SI 0 "gpc_reg_operand" "")
943         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
944   ""
945   "")
946
947 (define_insn ""
948   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
949         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
950   ""
951   "@
952    lha%U1%X1 %0,%1
953    {exts|extsh} %0,%1"
954   [(set_attr "type" "load_ext,*")])
955
956 (define_insn ""
957   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
958         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
959                     (const_int 0)))
960    (clobber (match_scratch:SI 2 "=r,r"))]
961   ""
962   "@
963    {exts.|extsh.} %2,%1
964    #"
965   [(set_attr "type" "compare")
966    (set_attr "length" "4,8")])
967
968 (define_split
969   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
970         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
971                     (const_int 0)))
972    (clobber (match_scratch:SI 2 ""))]
973   "reload_completed"
974   [(set (match_dup 2)
975         (sign_extend:SI (match_dup 1)))
976    (set (match_dup 0)
977         (compare:CC (match_dup 2)
978                     (const_int 0)))]
979   "")
980
981 (define_insn ""
982   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
983         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
984                     (const_int 0)))
985    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
986         (sign_extend:SI (match_dup 1)))]
987   ""
988   "@
989    {exts.|extsh.} %0,%1
990    #"
991   [(set_attr "type" "compare")
992    (set_attr "length" "4,8")])
993 \f
994 (define_split
995   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
996         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
997                     (const_int 0)))
998    (set (match_operand:SI 0 "gpc_reg_operand" "")
999         (sign_extend:SI (match_dup 1)))]
1000   "reload_completed"
1001   [(set (match_dup 0)
1002         (sign_extend:SI (match_dup 1)))
1003    (set (match_dup 2)
1004         (compare:CC (match_dup 0)
1005                     (const_int 0)))]
1006   "")
1007
1008 ;; Fixed-point arithmetic insns.
1009
1010 (define_mode_attr add_op2 [(SI "reg_or_arith_cint_operand")
1011                            (DI "reg_or_add_cint64_operand")])
1012
1013 (define_expand "add<mode>3"
1014   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1015         (plus:SDI (match_operand:SDI 1 "gpc_reg_operand" "")
1016                   (match_operand:SDI 2 "<add_op2>" "")))]
1017   ""
1018   "
1019 {
1020   if (<MODE>mode == DImode && ! TARGET_POWERPC64)
1021     {
1022       if (non_short_cint_operand (operands[2], DImode))
1023         FAIL;
1024     }
1025   else if (GET_CODE (operands[2]) == CONST_INT
1026            && ! add_operand (operands[2], <MODE>mode))
1027     {
1028       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
1029                  ? operands[0] : gen_reg_rtx (<MODE>mode));
1030
1031       HOST_WIDE_INT val = INTVAL (operands[2]);
1032       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1033       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1034
1035       if (<MODE>mode == DImode && !CONST_OK_FOR_LETTER_P (rest, 'L'))
1036         FAIL;
1037
1038       /* The ordering here is important for the prolog expander.
1039          When space is allocated from the stack, adding 'low' first may
1040          produce a temporary deallocation (which would be bad).  */
1041       emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1042       emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1043       DONE;
1044     }
1045 }")
1046
1047 ;; Discourage ai/addic because of carry but provide it in an alternative
1048 ;; allowing register zero as source.
1049 (define_insn "*add<mode>3_internal1"
1050   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,?r,r")
1051         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,r,b")
1052                   (match_operand:GPR 2 "add_operand" "r,I,I,L")))]
1053   ""
1054   "@
1055    {cax|add} %0,%1,%2
1056    {cal %0,%2(%1)|addi %0,%1,%2}
1057    {ai|addic} %0,%1,%2
1058    {cau|addis} %0,%1,%v2"
1059   [(set_attr "length" "4,4,4,4")])
1060
1061 (define_insn "addsi3_high"
1062   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1063         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1064                  (high:SI (match_operand 2 "" ""))))]
1065   "TARGET_MACHO && !TARGET_64BIT"
1066   "{cau|addis} %0,%1,ha16(%2)"
1067   [(set_attr "length" "4")])
1068
1069 (define_insn "*add<mode>3_internal2"
1070   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1071         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1072                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1073                     (const_int 0)))
1074    (clobber (match_scratch:P 3 "=r,r,r,r"))]
1075   ""
1076   "@
1077    {cax.|add.} %3,%1,%2
1078    {ai.|addic.} %3,%1,%2
1079    #
1080    #"
1081   [(set_attr "type" "fast_compare,compare,compare,compare")
1082    (set_attr "length" "4,4,8,8")])
1083
1084 (define_split
1085   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1086         (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1087                               (match_operand:GPR 2 "reg_or_short_operand" ""))
1088                     (const_int 0)))
1089    (clobber (match_scratch:GPR 3 ""))]
1090   "reload_completed"
1091   [(set (match_dup 3)
1092         (plus:GPR (match_dup 1)
1093                  (match_dup 2)))
1094    (set (match_dup 0)
1095         (compare:CC (match_dup 3)
1096                     (const_int 0)))]
1097   "")
1098
1099 (define_insn "*add<mode>3_internal3"
1100   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1101         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1102                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1103                     (const_int 0)))
1104    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
1105         (plus:P (match_dup 1)
1106                 (match_dup 2)))]
1107   ""
1108   "@
1109    {cax.|add.} %0,%1,%2
1110    {ai.|addic.} %0,%1,%2
1111    #
1112    #"
1113   [(set_attr "type" "fast_compare,compare,compare,compare")
1114    (set_attr "length" "4,4,8,8")])
1115
1116 (define_split
1117   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1118         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "")
1119                             (match_operand:P 2 "reg_or_short_operand" ""))
1120                     (const_int 0)))
1121    (set (match_operand:P 0 "gpc_reg_operand" "")
1122         (plus:P (match_dup 1) (match_dup 2)))]
1123   "reload_completed"
1124   [(set (match_dup 0)
1125         (plus:P (match_dup 1)
1126                 (match_dup 2)))
1127    (set (match_dup 3)
1128         (compare:CC (match_dup 0)
1129                     (const_int 0)))]
1130   "")
1131
1132 ;; Split an add that we can't do in one insn into two insns, each of which
1133 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1134 ;; add should be last in case the result gets used in an address.
1135
1136 (define_split
1137   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1138         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1139                   (match_operand:GPR 2 "non_add_cint_operand" "")))]
1140   ""
1141   [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1142    (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
1143 "
1144 {
1145   HOST_WIDE_INT val = INTVAL (operands[2]);
1146   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1147   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1148
1149   operands[4] = GEN_INT (low);
1150   if (<MODE>mode == SImode || CONST_OK_FOR_LETTER_P (rest, 'L'))
1151     operands[3] = GEN_INT (rest);
1152   else if (! no_new_pseudos)
1153     {
1154       operands[3] = gen_reg_rtx (DImode);
1155       emit_move_insn (operands[3], operands[2]);
1156       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
1157       DONE;
1158     }
1159   else
1160     FAIL;
1161 }")
1162
1163 (define_insn "one_cmpl<mode>2"
1164   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1165         (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1166   ""
1167   "nor %0,%1,%1")
1168
1169 (define_insn ""
1170   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1171         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1172                     (const_int 0)))
1173    (clobber (match_scratch:P 2 "=r,r"))]
1174   ""
1175   "@
1176    nor. %2,%1,%1
1177    #"
1178   [(set_attr "type" "compare")
1179    (set_attr "length" "4,8")])
1180
1181 (define_split
1182   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1183         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1184                     (const_int 0)))
1185    (clobber (match_scratch:P 2 ""))]
1186   "reload_completed"
1187   [(set (match_dup 2)
1188         (not:P (match_dup 1)))
1189    (set (match_dup 0)
1190         (compare:CC (match_dup 2)
1191                     (const_int 0)))]
1192   "")
1193
1194 (define_insn ""
1195   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1196         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1197                     (const_int 0)))
1198    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1199         (not:P (match_dup 1)))]
1200   ""
1201   "@
1202    nor. %0,%1,%1
1203    #"
1204   [(set_attr "type" "compare")
1205    (set_attr "length" "4,8")])
1206
1207 (define_split
1208   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1209         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1210                     (const_int 0)))
1211    (set (match_operand:P 0 "gpc_reg_operand" "")
1212         (not:P (match_dup 1)))]
1213   "reload_completed"
1214   [(set (match_dup 0)
1215         (not:P (match_dup 1)))
1216    (set (match_dup 2)
1217         (compare:CC (match_dup 0)
1218                     (const_int 0)))]
1219   "")
1220
1221 (define_insn ""
1222   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1223         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
1224                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
1225   "! TARGET_POWERPC"
1226   "{sf%I1|subf%I1c} %0,%2,%1")
1227
1228 (define_insn ""
1229   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
1230         (minus:GPR (match_operand:GPR 1 "reg_or_short_operand" "r,I")
1231                    (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
1232   "TARGET_POWERPC"
1233   "@
1234    subf %0,%2,%1
1235    subfic %0,%2,%1")
1236
1237 (define_insn ""
1238   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1239         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1240                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1241                     (const_int 0)))
1242    (clobber (match_scratch:SI 3 "=r,r"))]
1243   "! TARGET_POWERPC"
1244   "@
1245    {sf.|subfc.} %3,%2,%1
1246    #"
1247   [(set_attr "type" "compare")
1248    (set_attr "length" "4,8")])
1249
1250 (define_insn ""
1251   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1252         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1253                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1254                     (const_int 0)))
1255    (clobber (match_scratch:P 3 "=r,r"))]
1256   "TARGET_POWERPC"
1257   "@
1258    subf. %3,%2,%1
1259    #"
1260   [(set_attr "type" "fast_compare")
1261    (set_attr "length" "4,8")])
1262
1263 (define_split
1264   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1265         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1266                              (match_operand:P 2 "gpc_reg_operand" ""))
1267                     (const_int 0)))
1268    (clobber (match_scratch:P 3 ""))]
1269   "reload_completed"
1270   [(set (match_dup 3)
1271         (minus:P (match_dup 1)
1272                   (match_dup 2)))
1273    (set (match_dup 0)
1274         (compare:CC (match_dup 3)
1275                     (const_int 0)))]
1276   "")
1277
1278 (define_insn ""
1279   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1280         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1281                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1282                     (const_int 0)))
1283    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1284         (minus:SI (match_dup 1) (match_dup 2)))]
1285   "! TARGET_POWERPC"
1286   "@
1287    {sf.|subfc.} %0,%2,%1
1288    #"
1289   [(set_attr "type" "compare")
1290    (set_attr "length" "4,8")])
1291
1292 (define_insn ""
1293   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1294         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1295                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1296                     (const_int 0)))
1297    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1298         (minus:P (match_dup 1)
1299                   (match_dup 2)))]
1300   "TARGET_POWERPC"
1301   "@
1302    subf. %0,%2,%1
1303    #"
1304   [(set_attr "type" "fast_compare")
1305    (set_attr "length" "4,8")])
1306
1307 (define_split
1308   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1309         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1310                              (match_operand:P 2 "gpc_reg_operand" ""))
1311                     (const_int 0)))
1312    (set (match_operand:P 0 "gpc_reg_operand" "")
1313         (minus:P (match_dup 1)
1314                   (match_dup 2)))]
1315   "reload_completed"
1316   [(set (match_dup 0)
1317         (minus:P (match_dup 1)
1318                   (match_dup 2)))
1319    (set (match_dup 3)
1320         (compare:CC (match_dup 0)
1321                     (const_int 0)))]
1322   "")
1323
1324 (define_mode_attr sub_op2 [(SI "reg_or_arith_cint_operand")
1325                            (DI "reg_or_sub_cint64_operand")])
1326
1327 (define_expand "sub<mode>3"
1328   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1329         (minus:SDI (match_operand:SDI 1 "reg_or_short_operand" "")
1330                    (match_operand:SDI 2 "<sub_op2>" "")))]
1331   ""
1332   "
1333 {
1334   if (GET_CODE (operands[2]) == CONST_INT)
1335     {
1336       emit_insn (gen_add<mode>3 (operands[0], operands[1],
1337                                  negate_rtx (<MODE>mode, operands[2])));
1338       DONE;
1339     }
1340 }")
1341
1342 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1343 ;; instruction and some auxiliary computations.  Then we just have a single
1344 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1345 ;; combine.
1346
1347 (define_expand "sminsi3"
1348   [(set (match_dup 3)
1349         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1350                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1351                          (const_int 0)
1352                          (minus:SI (match_dup 2) (match_dup 1))))
1353    (set (match_operand:SI 0 "gpc_reg_operand" "")
1354         (minus:SI (match_dup 2) (match_dup 3)))]
1355   "TARGET_POWER || TARGET_ISEL"
1356   "
1357 {
1358   if (TARGET_ISEL)
1359     {
1360       operands[2] = force_reg (SImode, operands[2]);
1361       rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
1362       DONE;
1363     }
1364
1365   operands[3] = gen_reg_rtx (SImode);
1366 }")
1367
1368 (define_split
1369   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1370         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1371                  (match_operand:SI 2 "reg_or_short_operand" "")))
1372    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1373   "TARGET_POWER"
1374   [(set (match_dup 3)
1375         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1376                          (const_int 0)
1377                          (minus:SI (match_dup 2) (match_dup 1))))
1378    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1379   "")
1380
1381 (define_expand "smaxsi3"
1382   [(set (match_dup 3)
1383         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1384                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1385                          (const_int 0)
1386                          (minus:SI (match_dup 2) (match_dup 1))))
1387    (set (match_operand:SI 0 "gpc_reg_operand" "")
1388         (plus:SI (match_dup 3) (match_dup 1)))]
1389   "TARGET_POWER || TARGET_ISEL"
1390   "
1391 {
1392   if (TARGET_ISEL)
1393     {
1394       operands[2] = force_reg (SImode, operands[2]);
1395       rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
1396       DONE;
1397     }
1398   operands[3] = gen_reg_rtx (SImode);
1399 }")
1400
1401 (define_split
1402   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1403         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1404                  (match_operand:SI 2 "reg_or_short_operand" "")))
1405    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1406   "TARGET_POWER"
1407   [(set (match_dup 3)
1408         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1409                          (const_int 0)
1410                          (minus:SI (match_dup 2) (match_dup 1))))
1411    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1412   "")
1413
1414 (define_expand "uminsi3"
1415   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1416                               (match_dup 5)))
1417    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1418                               (match_dup 5)))
1419    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1420                                        (const_int 0)
1421                                        (minus:SI (match_dup 4) (match_dup 3))))
1422    (set (match_operand:SI 0 "gpc_reg_operand" "")
1423         (minus:SI (match_dup 2) (match_dup 3)))]
1424   "TARGET_POWER || TARGET_ISEL"
1425   "
1426 {
1427   if (TARGET_ISEL)
1428     {
1429       rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
1430       DONE;
1431     }
1432   operands[3] = gen_reg_rtx (SImode);
1433   operands[4] = gen_reg_rtx (SImode);
1434   operands[5] = GEN_INT (-2147483647 - 1);
1435 }")
1436
1437 (define_expand "umaxsi3"
1438   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1439                               (match_dup 5)))
1440    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1441                               (match_dup 5)))
1442    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1443                                        (const_int 0)
1444                                        (minus:SI (match_dup 4) (match_dup 3))))
1445    (set (match_operand:SI 0 "gpc_reg_operand" "")
1446         (plus:SI (match_dup 3) (match_dup 1)))]
1447   "TARGET_POWER || TARGET_ISEL"
1448   "
1449 {
1450   if (TARGET_ISEL)
1451     {
1452       rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
1453       DONE;
1454     }
1455   operands[3] = gen_reg_rtx (SImode);
1456   operands[4] = gen_reg_rtx (SImode);
1457   operands[5] = GEN_INT (-2147483647 - 1);
1458 }")
1459
1460 (define_insn ""
1461   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1462         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1463                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
1464                          (const_int 0)
1465                          (minus:SI (match_dup 2) (match_dup 1))))]
1466   "TARGET_POWER"
1467   "doz%I2 %0,%1,%2")
1468
1469 (define_insn ""
1470   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1471         (compare:CC
1472          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1473                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1474                           (const_int 0)
1475                           (minus:SI (match_dup 2) (match_dup 1)))
1476          (const_int 0)))
1477    (clobber (match_scratch:SI 3 "=r,r"))]
1478   "TARGET_POWER"
1479   "@
1480    doz%I2. %3,%1,%2
1481    #"
1482   [(set_attr "type" "delayed_compare")
1483    (set_attr "length" "4,8")])
1484
1485 (define_split
1486   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1487         (compare:CC
1488          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1489                               (match_operand:SI 2 "reg_or_short_operand" ""))
1490                           (const_int 0)
1491                           (minus:SI (match_dup 2) (match_dup 1)))
1492          (const_int 0)))
1493    (clobber (match_scratch:SI 3 ""))]
1494   "TARGET_POWER && reload_completed"
1495   [(set (match_dup 3)
1496         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1497                           (const_int 0)
1498                           (minus:SI (match_dup 2) (match_dup 1))))
1499    (set (match_dup 0)
1500         (compare:CC (match_dup 3)
1501                     (const_int 0)))]
1502   "")
1503
1504 (define_insn ""
1505   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1506         (compare:CC
1507          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1508                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1509                           (const_int 0)
1510                           (minus:SI (match_dup 2) (match_dup 1)))
1511          (const_int 0)))
1512    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1513         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1514                          (const_int 0)
1515                          (minus:SI (match_dup 2) (match_dup 1))))]
1516   "TARGET_POWER"
1517   "@
1518    doz%I2. %0,%1,%2
1519    #"
1520   [(set_attr "type" "delayed_compare")
1521    (set_attr "length" "4,8")])
1522
1523 (define_split
1524   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1525         (compare:CC
1526          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1527                               (match_operand:SI 2 "reg_or_short_operand" ""))
1528                           (const_int 0)
1529                           (minus:SI (match_dup 2) (match_dup 1)))
1530          (const_int 0)))
1531    (set (match_operand:SI 0 "gpc_reg_operand" "")
1532         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1533                          (const_int 0)
1534                          (minus:SI (match_dup 2) (match_dup 1))))]
1535   "TARGET_POWER && reload_completed"
1536   [(set (match_dup 0)
1537         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1538                          (const_int 0)
1539                          (minus:SI (match_dup 2) (match_dup 1))))
1540    (set (match_dup 3)
1541         (compare:CC (match_dup 0)
1542                     (const_int 0)))]
1543   "")
1544
1545 ;; We don't need abs with condition code because such comparisons should
1546 ;; never be done.
1547 (define_expand "abssi2"
1548   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1549         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
1550   ""
1551   "
1552 {
1553   if (TARGET_ISEL)
1554     {
1555       emit_insn (gen_abssi2_isel (operands[0], operands[1]));
1556       DONE;
1557     }
1558   else if (! TARGET_POWER)
1559     {
1560       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
1561       DONE;
1562     }
1563 }")
1564
1565 (define_insn "*abssi2_power"
1566   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1567         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1568   "TARGET_POWER"
1569   "abs %0,%1")
1570
1571 (define_insn_and_split "abssi2_isel"
1572   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1573         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
1574    (clobber (match_scratch:SI 2 "=&b"))
1575    (clobber (match_scratch:CC 3 "=y"))]
1576   "TARGET_ISEL"
1577   "#"
1578   "&& reload_completed"
1579   [(set (match_dup 2) (neg:SI (match_dup 1)))
1580    (set (match_dup 3)
1581         (compare:CC (match_dup 1)
1582                     (const_int 0)))
1583    (set (match_dup 0)
1584         (if_then_else:SI (ge (match_dup 3)
1585                              (const_int 0))
1586                          (match_dup 1)
1587                          (match_dup 2)))]
1588   "")
1589
1590 (define_insn_and_split "abssi2_nopower"
1591   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1592         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
1593    (clobber (match_scratch:SI 2 "=&r,&r"))]
1594   "! TARGET_POWER && ! TARGET_ISEL"
1595   "#"
1596   "&& reload_completed"
1597   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1598    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1599    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
1600   "")
1601
1602 (define_insn "*nabs_power"
1603   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1604         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
1605   "TARGET_POWER"
1606   "nabs %0,%1")
1607
1608 (define_insn_and_split "*nabs_nopower"
1609   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1610         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
1611    (clobber (match_scratch:SI 2 "=&r,&r"))]
1612   "! TARGET_POWER"
1613   "#"
1614   "&& reload_completed"
1615   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1616    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1617    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
1618   "")
1619
1620 (define_expand "neg<mode>2"
1621   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1622         (neg:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
1623   ""
1624   "")
1625
1626 (define_insn "*neg<mode>2_internal"
1627   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1628         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1629   ""
1630   "neg %0,%1")
1631
1632 (define_insn ""
1633   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1634         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1635                     (const_int 0)))
1636    (clobber (match_scratch:P 2 "=r,r"))]
1637   ""
1638   "@
1639    neg. %2,%1
1640    #"
1641   [(set_attr "type" "fast_compare")
1642    (set_attr "length" "4,8")])
1643
1644 (define_split
1645   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1646         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
1647                     (const_int 0)))
1648    (clobber (match_scratch:P 2 ""))]
1649   "reload_completed"
1650   [(set (match_dup 2)
1651         (neg:P (match_dup 1)))
1652    (set (match_dup 0)
1653         (compare:CC (match_dup 2)
1654                     (const_int 0)))]
1655   "")
1656
1657 (define_insn ""
1658   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1659         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1660                     (const_int 0)))
1661    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1662         (neg:P (match_dup 1)))]
1663   ""
1664   "@
1665    neg. %0,%1
1666    #"
1667   [(set_attr "type" "fast_compare")
1668    (set_attr "length" "4,8")])
1669
1670 (define_split
1671   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1672         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
1673                     (const_int 0)))
1674    (set (match_operand:P 0 "gpc_reg_operand" "")
1675         (neg:P (match_dup 1)))]
1676   "reload_completed"
1677   [(set (match_dup 0)
1678         (neg:P (match_dup 1)))
1679    (set (match_dup 2)
1680         (compare:CC (match_dup 0)
1681                     (const_int 0)))]
1682   "")
1683
1684 (define_insn "clz<mode>2"
1685   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1686         (clz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1687   ""
1688   "{cntlz|cntlz<wd>} %0,%1")
1689
1690 (define_expand "ctz<mode>2"
1691   [(set (match_dup 2)
1692         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))
1693    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
1694                                           (match_dup 2)))
1695               (clobber (scratch:CC))])
1696    (set (match_dup 4) (clz:GPR (match_dup 3)))
1697    (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1698         (minus:GPR (match_dup 5) (match_dup 4)))]
1699   ""
1700   {
1701      operands[2] = gen_reg_rtx (<MODE>mode);
1702      operands[3] = gen_reg_rtx (<MODE>mode);
1703      operands[4] = gen_reg_rtx (<MODE>mode);
1704      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 1);
1705   })
1706
1707 (define_expand "ffs<mode>2"
1708   [(set (match_dup 2)
1709         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))
1710    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
1711                                           (match_dup 2)))
1712               (clobber (scratch:CC))])
1713    (set (match_dup 4) (clz:GPR (match_dup 3)))
1714    (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1715         (minus:GPR (match_dup 5) (match_dup 4)))]
1716   ""
1717   {
1718      operands[2] = gen_reg_rtx (<MODE>mode);
1719      operands[3] = gen_reg_rtx (<MODE>mode);
1720      operands[4] = gen_reg_rtx (<MODE>mode);
1721      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
1722   })
1723
1724 (define_expand "popcount<mode>2"
1725   [(set (match_dup 2)
1726         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
1727                      UNSPEC_POPCNTB))
1728    (set (match_dup 3)
1729         (mult:GPR (match_dup 2) (match_dup 4)))
1730    (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1731         (lshiftrt:GPR (match_dup 3) (match_dup 5)))]
1732   "TARGET_POPCNTB"
1733   {
1734     operands[2] = gen_reg_rtx (<MODE>mode);
1735     operands[3] = gen_reg_rtx (<MODE>mode);
1736     operands[4] = force_reg (<MODE>mode,
1737                              <MODE>mode == SImode
1738                              ? GEN_INT (0x01010101)
1739                              : GEN_INT ((HOST_WIDE_INT)
1740                                         0x01010101 << 32 | 0x01010101));
1741     operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 8);
1742   })
1743
1744 (define_insn "popcntb<mode>2"
1745   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1746         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
1747                      UNSPEC_POPCNTB))]
1748   "TARGET_POPCNTB"
1749   "popcntb %0,%1")
1750
1751 (define_expand "mulsi3"
1752   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1753    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1754    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
1755   ""
1756   "
1757 {
1758   if (TARGET_POWER)
1759     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
1760   else
1761     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
1762   DONE;
1763 }")
1764
1765 (define_insn "mulsi3_mq"
1766   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1767         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1768                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
1769    (clobber (match_scratch:SI 3 "=q,q"))]
1770   "TARGET_POWER"
1771   "@
1772    {muls|mullw} %0,%1,%2
1773    {muli|mulli} %0,%1,%2"
1774    [(set (attr "type")
1775       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
1776                 (const_string "imul3")
1777              (match_operand:SI 2 "short_cint_operand" "")
1778                 (const_string "imul2")]
1779         (const_string "imul")))])
1780
1781 (define_insn "mulsi3_no_mq"
1782   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1783         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1784                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
1785   "! TARGET_POWER"
1786   "@
1787    {muls|mullw} %0,%1,%2
1788    {muli|mulli} %0,%1,%2"
1789    [(set (attr "type")
1790       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
1791                 (const_string "imul3")
1792              (match_operand:SI 2 "short_cint_operand" "")
1793                 (const_string "imul2")]
1794         (const_string "imul")))])
1795
1796 (define_insn "*mulsi3_mq_internal1"
1797   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1798         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1799                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1800                     (const_int 0)))
1801    (clobber (match_scratch:SI 3 "=r,r"))
1802    (clobber (match_scratch:SI 4 "=q,q"))]
1803   "TARGET_POWER"
1804   "@
1805    {muls.|mullw.} %3,%1,%2
1806    #"
1807   [(set_attr "type" "imul_compare")
1808    (set_attr "length" "4,8")])
1809
1810 (define_split
1811   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1812         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1813                              (match_operand:SI 2 "gpc_reg_operand" ""))
1814                     (const_int 0)))
1815    (clobber (match_scratch:SI 3 ""))
1816    (clobber (match_scratch:SI 4 ""))]
1817   "TARGET_POWER && reload_completed"
1818   [(parallel [(set (match_dup 3)
1819         (mult:SI (match_dup 1) (match_dup 2)))
1820    (clobber (match_dup 4))])
1821    (set (match_dup 0)
1822         (compare:CC (match_dup 3)
1823                     (const_int 0)))]
1824   "")
1825
1826 (define_insn "*mulsi3_no_mq_internal1"
1827   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1828         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1829                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1830                     (const_int 0)))
1831    (clobber (match_scratch:SI 3 "=r,r"))]
1832   "! TARGET_POWER"
1833   "@
1834    {muls.|mullw.} %3,%1,%2
1835    #"
1836   [(set_attr "type" "imul_compare")
1837    (set_attr "length" "4,8")])
1838
1839 (define_split
1840   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1841         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1842                              (match_operand:SI 2 "gpc_reg_operand" ""))
1843                     (const_int 0)))
1844    (clobber (match_scratch:SI 3 ""))]
1845   "! TARGET_POWER && reload_completed"
1846   [(set (match_dup 3)
1847         (mult:SI (match_dup 1) (match_dup 2)))
1848    (set (match_dup 0)
1849         (compare:CC (match_dup 3)
1850                     (const_int 0)))]
1851   "")
1852
1853 (define_insn "*mulsi3_mq_internal2"
1854   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1855         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1856                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1857                     (const_int 0)))
1858    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1859         (mult:SI (match_dup 1) (match_dup 2)))
1860    (clobber (match_scratch:SI 4 "=q,q"))]
1861   "TARGET_POWER"
1862   "@
1863    {muls.|mullw.} %0,%1,%2
1864    #"
1865   [(set_attr "type" "imul_compare")
1866    (set_attr "length" "4,8")])
1867
1868 (define_split
1869   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1870         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1871                              (match_operand:SI 2 "gpc_reg_operand" ""))
1872                     (const_int 0)))
1873    (set (match_operand:SI 0 "gpc_reg_operand" "")
1874         (mult:SI (match_dup 1) (match_dup 2)))
1875    (clobber (match_scratch:SI 4 ""))]
1876   "TARGET_POWER && reload_completed"
1877   [(parallel [(set (match_dup 0)
1878         (mult:SI (match_dup 1) (match_dup 2)))
1879    (clobber (match_dup 4))])
1880    (set (match_dup 3)
1881         (compare:CC (match_dup 0)
1882                     (const_int 0)))]
1883   "")
1884
1885 (define_insn "*mulsi3_no_mq_internal2"
1886   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1887         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1888                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1889                     (const_int 0)))
1890    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1891         (mult:SI (match_dup 1) (match_dup 2)))]
1892   "! TARGET_POWER"
1893   "@
1894    {muls.|mullw.} %0,%1,%2
1895    #"
1896   [(set_attr "type" "imul_compare")
1897    (set_attr "length" "4,8")])
1898
1899 (define_split
1900   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1901         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1902                              (match_operand:SI 2 "gpc_reg_operand" ""))
1903                     (const_int 0)))
1904    (set (match_operand:SI 0 "gpc_reg_operand" "")
1905         (mult:SI (match_dup 1) (match_dup 2)))]
1906   "! TARGET_POWER && reload_completed"
1907   [(set (match_dup 0)
1908         (mult:SI (match_dup 1) (match_dup 2)))
1909    (set (match_dup 3)
1910         (compare:CC (match_dup 0)
1911                     (const_int 0)))]
1912   "")
1913
1914 ;; Operand 1 is divided by operand 2; quotient goes to operand
1915 ;; 0 and remainder to operand 3.
1916 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
1917
1918 (define_expand "divmodsi4"
1919   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
1920                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1921                            (match_operand:SI 2 "gpc_reg_operand" "")))
1922               (set (match_operand:SI 3 "register_operand" "")
1923                    (mod:SI (match_dup 1) (match_dup 2)))])]
1924   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
1925   "
1926 {
1927   if (! TARGET_POWER && ! TARGET_POWERPC)
1928     {
1929       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
1930       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
1931       emit_insn (gen_divss_call ());
1932       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
1933       emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
1934       DONE;
1935     }
1936 }")
1937
1938 (define_insn "*divmodsi4_internal"
1939   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1940         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1941                 (match_operand:SI 2 "gpc_reg_operand" "r")))
1942    (set (match_operand:SI 3 "register_operand" "=q")
1943         (mod:SI (match_dup 1) (match_dup 2)))]
1944   "TARGET_POWER"
1945   "divs %0,%1,%2"
1946   [(set_attr "type" "idiv")])
1947
1948 (define_expand "udivsi3"
1949   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1950         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
1951                  (match_operand:SI 2 "gpc_reg_operand" "")))]
1952   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
1953   "
1954 {
1955   if (! TARGET_POWER && ! TARGET_POWERPC)
1956     {
1957       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
1958       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
1959       emit_insn (gen_quous_call ());
1960       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
1961       DONE;
1962     }
1963   else if (TARGET_POWER)
1964     {
1965       emit_insn (gen_udivsi3_mq (operands[0], operands[1], operands[2]));
1966       DONE;
1967     }
1968 }")
1969
1970 (define_insn "udivsi3_mq"
1971   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1972         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1973                  (match_operand:SI 2 "gpc_reg_operand" "r")))
1974    (clobber (match_scratch:SI 3 "=q"))]
1975   "TARGET_POWERPC && TARGET_POWER"
1976   "divwu %0,%1,%2"
1977   [(set_attr "type" "idiv")])
1978
1979 (define_insn "*udivsi3_no_mq"
1980   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1981         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1982                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
1983   "TARGET_POWERPC && ! TARGET_POWER"
1984   "divwu %0,%1,%2"
1985   [(set_attr "type" "idiv")])
1986
1987 ;; For powers of two we can do srai/aze for divide and then adjust for
1988 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
1989 ;; used; for PowerPC, force operands into register and do a normal divide;
1990 ;; for AIX common-mode, use quoss call on register operands.
1991 (define_expand "divsi3"
1992   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1993         (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1994                 (match_operand:SI 2 "reg_or_cint_operand" "")))]
1995   ""
1996   "
1997 {
1998   if (GET_CODE (operands[2]) == CONST_INT
1999       && INTVAL (operands[2]) > 0
2000       && exact_log2 (INTVAL (operands[2])) >= 0)
2001     ;
2002   else if (TARGET_POWERPC)
2003     {
2004       operands[2] = force_reg (SImode, operands[2]);
2005       if (TARGET_POWER)
2006         {
2007           emit_insn (gen_divsi3_mq (operands[0], operands[1], operands[2]));
2008           DONE;
2009         }
2010     }
2011   else if (TARGET_POWER)
2012     FAIL;
2013   else
2014     {
2015       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2016       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2017       emit_insn (gen_quoss_call ());
2018       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2019       DONE;
2020     }
2021 }")
2022
2023 (define_insn "divsi3_mq"
2024   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2025         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2026                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2027    (clobber (match_scratch:SI 3 "=q"))]
2028   "TARGET_POWERPC && TARGET_POWER"
2029   "divw %0,%1,%2"
2030   [(set_attr "type" "idiv")])
2031
2032 (define_insn "*divsi3_no_mq"
2033   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2034         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2035                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
2036   "TARGET_POWERPC && ! TARGET_POWER"
2037   "divw %0,%1,%2"
2038   [(set_attr "type" "idiv")])
2039
2040 (define_expand "modsi3"
2041   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2042    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2043    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
2044   ""
2045   "
2046 {
2047   int i;
2048   rtx temp1;
2049   rtx temp2;
2050
2051   if (GET_CODE (operands[2]) != CONST_INT
2052       || INTVAL (operands[2]) <= 0
2053       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
2054     FAIL;
2055
2056   temp1 = gen_reg_rtx (SImode);
2057   temp2 = gen_reg_rtx (SImode);
2058
2059   emit_insn (gen_divsi3 (temp1, operands[1], operands[2]));
2060   emit_insn (gen_ashlsi3 (temp2, temp1, GEN_INT (i)));
2061   emit_insn (gen_subsi3 (operands[0], operands[1], temp2));
2062   DONE;
2063 }")
2064
2065 (define_insn ""
2066   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2067         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2068                 (match_operand:SI 2 "exact_log2_cint_operand" "N")))]
2069   ""
2070   "{srai|srawi} %0,%1,%p2\;{aze|addze} %0,%0"
2071   [(set_attr "type" "two")
2072    (set_attr "length" "8")])
2073
2074 (define_insn ""
2075   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2076         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2077                             (match_operand:SI 2 "exact_log2_cint_operand" "N,N"))
2078                     (const_int 0)))
2079    (clobber (match_scratch:SI 3 "=r,r"))]
2080   ""
2081   "@
2082    {srai|srawi} %3,%1,%p2\;{aze.|addze.} %3,%3
2083    #"
2084   [(set_attr "type" "compare")
2085    (set_attr "length" "8,12")])
2086
2087 (define_split
2088   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2089         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2090                             (match_operand:SI 2 "exact_log2_cint_operand" ""))
2091                     (const_int 0)))
2092    (clobber (match_scratch:SI 3 ""))]
2093   "reload_completed"
2094   [(set (match_dup 3)
2095         (div:SI (match_dup 1) (match_dup 2)))
2096    (set (match_dup 0)
2097         (compare:CC (match_dup 3)
2098                     (const_int 0)))]
2099   "")
2100
2101 (define_insn ""
2102   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2103         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2104                             (match_operand:SI 2 "exact_log2_cint_operand" "N,N"))
2105                     (const_int 0)))
2106    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2107         (div:SI (match_dup 1) (match_dup 2)))]
2108   ""
2109   "@
2110    {srai|srawi} %0,%1,%p2\;{aze.|addze.} %0,%0
2111    #"
2112   [(set_attr "type" "compare")
2113    (set_attr "length" "8,12")])
2114
2115 (define_split
2116   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2117         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2118                             (match_operand:SI 2 "exact_log2_cint_operand" ""))
2119                     (const_int 0)))
2120    (set (match_operand:SI 0 "gpc_reg_operand" "")
2121         (div:SI (match_dup 1) (match_dup 2)))]
2122   "reload_completed"
2123   [(set (match_dup 0)
2124         (div:SI (match_dup 1) (match_dup 2)))
2125    (set (match_dup 3)
2126         (compare:CC (match_dup 0)
2127                     (const_int 0)))]
2128   "")
2129
2130 (define_insn ""
2131   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2132         (udiv:SI
2133          (plus:DI (ashift:DI
2134                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
2135                    (const_int 32))
2136                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
2137          (match_operand:SI 3 "gpc_reg_operand" "r")))
2138    (set (match_operand:SI 2 "register_operand" "=*q")
2139         (umod:SI
2140          (plus:DI (ashift:DI
2141                    (zero_extend:DI (match_dup 1)) (const_int 32))
2142                   (zero_extend:DI (match_dup 4)))
2143          (match_dup 3)))]
2144   "TARGET_POWER"
2145   "div %0,%1,%3"
2146   [(set_attr "type" "idiv")])
2147
2148 ;; To do unsigned divide we handle the cases of the divisor looking like a
2149 ;; negative number.  If it is a constant that is less than 2**31, we don't
2150 ;; have to worry about the branches.  So make a few subroutines here.
2151 ;;
2152 ;; First comes the normal case.
2153 (define_expand "udivmodsi4_normal"
2154   [(set (match_dup 4) (const_int 0))
2155    (parallel [(set (match_operand:SI 0 "" "")
2156                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2157                                                 (const_int 32))
2158                                      (zero_extend:DI (match_operand:SI 1 "" "")))
2159                             (match_operand:SI 2 "" "")))
2160               (set (match_operand:SI 3 "" "")
2161                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2162                                                 (const_int 32))
2163                                      (zero_extend:DI (match_dup 1)))
2164                             (match_dup 2)))])]
2165   "TARGET_POWER"
2166   "
2167 { operands[4] = gen_reg_rtx (SImode); }")
2168
2169 ;; This handles the branches.
2170 (define_expand "udivmodsi4_tests"
2171   [(set (match_operand:SI 0 "" "") (const_int 0))
2172    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
2173    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
2174    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
2175                            (label_ref (match_operand:SI 4 "" "")) (pc)))
2176    (set (match_dup 0) (const_int 1))
2177    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
2178    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
2179    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
2180                            (label_ref (match_dup 4)) (pc)))]
2181   "TARGET_POWER"
2182   "
2183 { operands[5] = gen_reg_rtx (CCUNSmode);
2184   operands[6] = gen_reg_rtx (CCmode);
2185 }")
2186
2187 (define_expand "udivmodsi4"
2188   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2189                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
2190                             (match_operand:SI 2 "reg_or_cint_operand" "")))
2191               (set (match_operand:SI 3 "gpc_reg_operand" "")
2192                    (umod:SI (match_dup 1) (match_dup 2)))])]
2193   ""
2194   "
2195 {
2196   rtx label = 0;
2197
2198   if (! TARGET_POWER)
2199     {
2200       if (! TARGET_POWERPC)
2201         {
2202           emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2203           emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2204           emit_insn (gen_divus_call ());
2205           emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2206           emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2207           DONE;
2208         }
2209       else
2210         FAIL;
2211     }
2212
2213   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
2214     {
2215       operands[2] = force_reg (SImode, operands[2]);
2216       label = gen_label_rtx ();
2217       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
2218                                   operands[3], label));
2219     }
2220   else
2221     operands[2] = force_reg (SImode, operands[2]);
2222
2223   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
2224                                operands[3]));
2225   if (label)
2226     emit_label (label);
2227
2228   DONE;
2229 }")
2230
2231 ;; AIX architecture-independent common-mode multiply (DImode),
2232 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
2233 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
2234 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
2235 ;; assumed unused if generating common-mode, so ignore.
2236 (define_insn "mulh_call"
2237   [(set (reg:SI 3)
2238         (truncate:SI
2239          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
2240                                (sign_extend:DI (reg:SI 4)))
2241                       (const_int 32))))
2242    (clobber (match_scratch:SI 0 "=l"))]
2243   "! TARGET_POWER && ! TARGET_POWERPC"
2244   "bla __mulh"
2245   [(set_attr "type" "imul")])
2246
2247 (define_insn "mull_call"
2248   [(set (reg:DI 3)
2249         (mult:DI (sign_extend:DI (reg:SI 3))
2250                  (sign_extend:DI (reg:SI 4))))
2251    (clobber (match_scratch:SI 0 "=l"))
2252    (clobber (reg:SI 0))]
2253   "! TARGET_POWER && ! TARGET_POWERPC"
2254   "bla __mull"
2255   [(set_attr "type" "imul")])
2256
2257 (define_insn "divss_call"
2258   [(set (reg:SI 3)
2259         (div:SI (reg:SI 3) (reg:SI 4)))
2260    (set (reg:SI 4)
2261         (mod:SI (reg:SI 3) (reg:SI 4)))
2262    (clobber (match_scratch:SI 0 "=l"))
2263    (clobber (reg:SI 0))]
2264   "! TARGET_POWER && ! TARGET_POWERPC"
2265   "bla __divss"
2266   [(set_attr "type" "idiv")])
2267
2268 (define_insn "divus_call"
2269   [(set (reg:SI 3)
2270         (udiv:SI (reg:SI 3) (reg:SI 4)))
2271    (set (reg:SI 4)
2272         (umod:SI (reg:SI 3) (reg:SI 4)))
2273    (clobber (match_scratch:SI 0 "=l"))
2274    (clobber (reg:SI 0))
2275    (clobber (match_scratch:CC 1 "=x"))
2276    (clobber (reg:CC 69))]
2277   "! TARGET_POWER && ! TARGET_POWERPC"
2278   "bla __divus"
2279   [(set_attr "type" "idiv")])
2280
2281 (define_insn "quoss_call"
2282   [(set (reg:SI 3)
2283         (div:SI (reg:SI 3) (reg:SI 4)))
2284    (clobber (match_scratch:SI 0 "=l"))]
2285   "! TARGET_POWER && ! TARGET_POWERPC"
2286   "bla __quoss"
2287   [(set_attr "type" "idiv")])
2288
2289 (define_insn "quous_call"
2290   [(set (reg:SI 3)
2291         (udiv:SI (reg:SI 3) (reg:SI 4)))
2292    (clobber (match_scratch:SI 0 "=l"))
2293    (clobber (reg:SI 0))
2294    (clobber (match_scratch:CC 1 "=x"))
2295    (clobber (reg:CC 69))]
2296   "! TARGET_POWER && ! TARGET_POWERPC"
2297   "bla __quous"
2298   [(set_attr "type" "idiv")])
2299 \f
2300 ;; Logical instructions
2301 ;; The logical instructions are mostly combined by using match_operator,
2302 ;; but the plain AND insns are somewhat different because there is no
2303 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2304 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2305
2306 (define_insn "andsi3"
2307   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2308         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2309                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2310    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2311   ""
2312   "@
2313    and %0,%1,%2
2314    {rlinm|rlwinm} %0,%1,0,%m2,%M2
2315    {andil.|andi.} %0,%1,%b2
2316    {andiu.|andis.} %0,%1,%u2"
2317   [(set_attr "type" "*,*,compare,compare")])
2318
2319 ;; Note to set cr's other than cr0 we do the and immediate and then
2320 ;; the test again -- this avoids a mfcr which on the higher end
2321 ;; machines causes an execution serialization
2322
2323 (define_insn "*andsi3_internal2"
2324   [(set (match_operand:CC 0 "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    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2329    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2330   "TARGET_32BIT"
2331   "@
2332    and. %3,%1,%2
2333    {andil.|andi.} %3,%1,%b2
2334    {andiu.|andis.} %3,%1,%u2
2335    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2336    #
2337    #
2338    #
2339    #"
2340   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2341    (set_attr "length" "4,4,4,4,8,8,8,8")])
2342
2343 (define_insn "*andsi3_internal3"
2344   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2345         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2346                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2347                     (const_int 0)))
2348    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2349    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2350   "TARGET_64BIT"
2351   "@
2352    #
2353    {andil.|andi.} %3,%1,%b2
2354    {andiu.|andis.} %3,%1,%u2
2355    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2356    #
2357    #
2358    #
2359    #"
2360   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2361    (set_attr "length" "8,4,4,4,8,8,8,8")])
2362
2363 (define_split
2364   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2365         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2366                             (match_operand:SI 2 "and_operand" ""))
2367                     (const_int 0)))
2368    (clobber (match_scratch:SI 3 ""))
2369    (clobber (match_scratch:CC 4 ""))]
2370   "reload_completed"
2371   [(parallel [(set (match_dup 3)
2372                    (and:SI (match_dup 1)
2373                            (match_dup 2)))
2374               (clobber (match_dup 4))])
2375    (set (match_dup 0)
2376         (compare:CC (match_dup 3)
2377                     (const_int 0)))]
2378   "")
2379
2380 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
2381 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
2382
2383 (define_split
2384   [(set (match_operand:CC 0 "cc_reg_operand" "")
2385         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2386                             (match_operand:SI 2 "gpc_reg_operand" ""))
2387                     (const_int 0)))
2388    (clobber (match_scratch:SI 3 ""))
2389    (clobber (match_scratch:CC 4 ""))]
2390   "TARGET_POWERPC64 && reload_completed"
2391   [(parallel [(set (match_dup 3)
2392                    (and:SI (match_dup 1)
2393                            (match_dup 2)))
2394               (clobber (match_dup 4))])
2395    (set (match_dup 0)
2396         (compare:CC (match_dup 3)
2397                     (const_int 0)))]
2398   "")
2399
2400 (define_insn "*andsi3_internal4"
2401   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2402         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2403                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2404                     (const_int 0)))
2405    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2406         (and:SI (match_dup 1)
2407                 (match_dup 2)))
2408    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2409   "TARGET_32BIT"
2410   "@
2411    and. %0,%1,%2
2412    {andil.|andi.} %0,%1,%b2
2413    {andiu.|andis.} %0,%1,%u2
2414    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2415    #
2416    #
2417    #
2418    #"
2419   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2420    (set_attr "length" "4,4,4,4,8,8,8,8")])
2421
2422 (define_insn "*andsi3_internal5"
2423   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2424         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2425                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2426                     (const_int 0)))
2427    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2428         (and:SI (match_dup 1)
2429                 (match_dup 2)))
2430    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2431   "TARGET_64BIT"
2432   "@
2433    #
2434    {andil.|andi.} %0,%1,%b2
2435    {andiu.|andis.} %0,%1,%u2
2436    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2437    #
2438    #
2439    #
2440    #"
2441   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2442    (set_attr "length" "8,4,4,4,8,8,8,8")])
2443
2444 (define_split
2445   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2446         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2447                             (match_operand:SI 2 "and_operand" ""))
2448                     (const_int 0)))
2449    (set (match_operand:SI 0 "gpc_reg_operand" "")
2450         (and:SI (match_dup 1)
2451                 (match_dup 2)))
2452    (clobber (match_scratch:CC 4 ""))]
2453   "reload_completed"
2454   [(parallel [(set (match_dup 0)
2455                    (and:SI (match_dup 1)
2456                            (match_dup 2)))
2457               (clobber (match_dup 4))])
2458    (set (match_dup 3)
2459         (compare:CC (match_dup 0)
2460                     (const_int 0)))]
2461   "")
2462
2463 (define_split
2464   [(set (match_operand:CC 3 "cc_reg_operand" "")
2465         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2466                             (match_operand:SI 2 "gpc_reg_operand" ""))
2467                     (const_int 0)))
2468    (set (match_operand:SI 0 "gpc_reg_operand" "")
2469         (and:SI (match_dup 1)
2470                 (match_dup 2)))
2471    (clobber (match_scratch:CC 4 ""))]
2472   "TARGET_POWERPC64 && reload_completed"
2473   [(parallel [(set (match_dup 0)
2474                    (and:SI (match_dup 1)
2475                            (match_dup 2)))
2476               (clobber (match_dup 4))])
2477    (set (match_dup 3)
2478         (compare:CC (match_dup 0)
2479                     (const_int 0)))]
2480   "")
2481
2482 ;; Handle the PowerPC64 rlwinm corner case
2483
2484 (define_insn_and_split "*andsi3_internal6"
2485   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2486         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2487                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
2488   "TARGET_POWERPC64"
2489   "#"
2490   "TARGET_POWERPC64"
2491   [(set (match_dup 0)
2492         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
2493                 (match_dup 4)))
2494    (set (match_dup 0)
2495         (rotate:SI (match_dup 0) (match_dup 5)))]
2496   "
2497 {
2498   int mb = extract_MB (operands[2]);
2499   int me = extract_ME (operands[2]);
2500   operands[3] = GEN_INT (me + 1);
2501   operands[5] = GEN_INT (32 - (me + 1));
2502   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2503 }"
2504   [(set_attr "length" "8")])
2505
2506 (define_expand "iorsi3"
2507   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2508         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
2509                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2510   ""
2511   "
2512 {
2513   if (GET_CODE (operands[2]) == CONST_INT
2514       && ! logical_operand (operands[2], SImode))
2515     {
2516       HOST_WIDE_INT value = INTVAL (operands[2]);
2517       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2518                  ? operands[0] : gen_reg_rtx (SImode));
2519
2520       emit_insn (gen_iorsi3 (tmp, operands[1],
2521                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2522       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2523       DONE;
2524     }
2525 }")
2526
2527 (define_expand "xorsi3"
2528   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2529         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
2530                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2531   ""
2532   "
2533 {
2534   if (GET_CODE (operands[2]) == CONST_INT
2535       && ! logical_operand (operands[2], SImode))
2536     {
2537       HOST_WIDE_INT value = INTVAL (operands[2]);
2538       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2539                  ? operands[0] : gen_reg_rtx (SImode));
2540
2541       emit_insn (gen_xorsi3 (tmp, operands[1],
2542                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2543       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2544       DONE;
2545     }
2546 }")
2547
2548 (define_insn "*boolsi3_internal1"
2549   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
2550         (match_operator:SI 3 "boolean_or_operator"
2551          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
2552           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
2553   ""
2554   "@
2555    %q3 %0,%1,%2
2556    {%q3il|%q3i} %0,%1,%b2
2557    {%q3iu|%q3is} %0,%1,%u2")
2558
2559 (define_insn "*boolsi3_internal2"
2560   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2561         (compare:CC (match_operator:SI 4 "boolean_or_operator"
2562          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2563           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2564          (const_int 0)))
2565    (clobber (match_scratch:SI 3 "=r,r"))]
2566   "TARGET_32BIT"
2567   "@
2568    %q4. %3,%1,%2
2569    #"
2570   [(set_attr "type" "compare")
2571    (set_attr "length" "4,8")])
2572
2573 (define_split
2574   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2575         (compare:CC (match_operator:SI 4 "boolean_operator"
2576          [(match_operand:SI 1 "gpc_reg_operand" "")
2577           (match_operand:SI 2 "gpc_reg_operand" "")])
2578          (const_int 0)))
2579    (clobber (match_scratch:SI 3 ""))]
2580   "TARGET_32BIT && reload_completed"
2581   [(set (match_dup 3) (match_dup 4))
2582    (set (match_dup 0)
2583         (compare:CC (match_dup 3)
2584                     (const_int 0)))]
2585   "")
2586
2587 (define_insn "*boolsi3_internal3"
2588   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2589         (compare:CC (match_operator:SI 4 "boolean_operator"
2590          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2591           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2592          (const_int 0)))
2593    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2594         (match_dup 4))]
2595   "TARGET_32BIT"
2596   "@
2597    %q4. %0,%1,%2
2598    #"
2599   [(set_attr "type" "compare")
2600    (set_attr "length" "4,8")])
2601
2602 (define_split
2603   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2604         (compare:CC (match_operator:SI 4 "boolean_operator"
2605          [(match_operand:SI 1 "gpc_reg_operand" "")
2606           (match_operand:SI 2 "gpc_reg_operand" "")])
2607          (const_int 0)))
2608    (set (match_operand:SI 0 "gpc_reg_operand" "")
2609         (match_dup 4))]
2610   "TARGET_32BIT && reload_completed"
2611   [(set (match_dup 0) (match_dup 4))
2612    (set (match_dup 3)
2613         (compare:CC (match_dup 0)
2614                     (const_int 0)))]
2615   "")
2616
2617 ;; Split a logical operation that we can't do in one insn into two insns,
2618 ;; each of which does one 16-bit part.  This is used by combine.
2619
2620 (define_split
2621   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2622         (match_operator:SI 3 "boolean_or_operator"
2623          [(match_operand:SI 1 "gpc_reg_operand" "")
2624           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
2625   ""
2626   [(set (match_dup 0) (match_dup 4))
2627    (set (match_dup 0) (match_dup 5))]
2628 "
2629 {
2630   rtx i;
2631   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
2632   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2633                                 operands[1], i);
2634   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
2635   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2636                                 operands[0], i);
2637 }")
2638
2639 (define_insn "*boolcsi3_internal1"
2640   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2641         (match_operator:SI 3 "boolean_operator"
2642          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
2643           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
2644   ""
2645   "%q3 %0,%2,%1")
2646
2647 (define_insn "*boolcsi3_internal2"
2648   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2649         (compare:CC (match_operator:SI 4 "boolean_operator"
2650          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2651           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2652          (const_int 0)))
2653    (clobber (match_scratch:SI 3 "=r,r"))]
2654   "TARGET_32BIT"
2655   "@
2656    %q4. %3,%2,%1
2657    #"
2658   [(set_attr "type" "compare")
2659    (set_attr "length" "4,8")])
2660
2661 (define_split
2662   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2663         (compare:CC (match_operator:SI 4 "boolean_operator"
2664          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2665           (match_operand:SI 2 "gpc_reg_operand" "")])
2666          (const_int 0)))
2667    (clobber (match_scratch:SI 3 ""))]
2668   "TARGET_32BIT && reload_completed"
2669   [(set (match_dup 3) (match_dup 4))
2670    (set (match_dup 0)
2671         (compare:CC (match_dup 3)
2672                     (const_int 0)))]
2673   "")
2674
2675 (define_insn "*boolcsi3_internal3"
2676   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2677         (compare:CC (match_operator:SI 4 "boolean_operator"
2678          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
2679           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2680          (const_int 0)))
2681    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2682         (match_dup 4))]
2683   "TARGET_32BIT"
2684   "@
2685    %q4. %0,%2,%1
2686    #"
2687   [(set_attr "type" "compare")
2688    (set_attr "length" "4,8")])
2689
2690 (define_split
2691   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2692         (compare:CC (match_operator:SI 4 "boolean_operator"
2693          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2694           (match_operand:SI 2 "gpc_reg_operand" "")])
2695          (const_int 0)))
2696    (set (match_operand:SI 0 "gpc_reg_operand" "")
2697         (match_dup 4))]
2698   "TARGET_32BIT && reload_completed"
2699   [(set (match_dup 0) (match_dup 4))
2700    (set (match_dup 3)
2701         (compare:CC (match_dup 0)
2702                     (const_int 0)))]
2703   "")
2704
2705 (define_insn "*boolccsi3_internal1"
2706   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2707         (match_operator:SI 3 "boolean_operator"
2708          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
2709           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
2710   ""
2711   "%q3 %0,%1,%2")
2712
2713 (define_insn "*boolccsi3_internal2"
2714   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2715         (compare:CC (match_operator:SI 4 "boolean_operator"
2716          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2717           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
2718          (const_int 0)))
2719    (clobber (match_scratch:SI 3 "=r,r"))]
2720   "TARGET_32BIT"
2721   "@
2722    %q4. %3,%1,%2
2723    #"
2724   [(set_attr "type" "compare")
2725    (set_attr "length" "4,8")])
2726
2727 (define_split
2728   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2729         (compare:CC (match_operator:SI 4 "boolean_operator"
2730          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2731           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
2732          (const_int 0)))
2733    (clobber (match_scratch:SI 3 ""))]
2734   "TARGET_32BIT && reload_completed"
2735   [(set (match_dup 3) (match_dup 4))
2736    (set (match_dup 0)
2737         (compare:CC (match_dup 3)
2738                     (const_int 0)))]
2739   "")
2740
2741 (define_insn "*boolccsi3_internal3"
2742   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2743         (compare:CC (match_operator:SI 4 "boolean_operator"
2744          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
2745           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
2746          (const_int 0)))
2747    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2748         (match_dup 4))]
2749   "TARGET_32BIT"
2750   "@
2751    %q4. %0,%1,%2
2752    #"
2753   [(set_attr "type" "compare")
2754    (set_attr "length" "4,8")])
2755
2756 (define_split
2757   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2758         (compare:CC (match_operator:SI 4 "boolean_operator"
2759          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2760           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
2761          (const_int 0)))
2762    (set (match_operand:SI 0 "gpc_reg_operand" "")
2763         (match_dup 4))]
2764   "TARGET_32BIT && reload_completed"
2765   [(set (match_dup 0) (match_dup 4))
2766    (set (match_dup 3)
2767         (compare:CC (match_dup 0)
2768                     (const_int 0)))]
2769   "")
2770
2771 ;; maskir insn.  We need four forms because things might be in arbitrary
2772 ;; orders.  Don't define forms that only set CR fields because these
2773 ;; would modify an input register.
2774
2775 (define_insn "*maskir_internal1"
2776   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2777         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
2778                         (match_operand:SI 1 "gpc_reg_operand" "0"))
2779                 (and:SI (match_dup 2)
2780                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
2781   "TARGET_POWER"
2782   "maskir %0,%3,%2")
2783
2784 (define_insn "*maskir_internal2"
2785   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2786         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
2787                         (match_operand:SI 1 "gpc_reg_operand" "0"))
2788                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2789                         (match_dup 2))))]
2790   "TARGET_POWER"
2791   "maskir %0,%3,%2")
2792
2793 (define_insn "*maskir_internal3"
2794   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2795         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2796                         (match_operand:SI 3 "gpc_reg_operand" "r"))
2797                 (and:SI (not:SI (match_dup 2))
2798                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
2799   "TARGET_POWER"
2800   "maskir %0,%3,%2")
2801
2802 (define_insn "*maskir_internal4"
2803   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2804         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2805                         (match_operand:SI 2 "gpc_reg_operand" "r"))
2806                 (and:SI (not:SI (match_dup 2))
2807                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
2808   "TARGET_POWER"
2809   "maskir %0,%3,%2")
2810
2811 (define_insn "*maskir_internal5"
2812   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2813         (compare:CC
2814          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2815                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
2816                  (and:SI (match_dup 2)
2817                          (match_operand:SI 3 "gpc_reg_operand" "r,r")))
2818          (const_int 0)))
2819    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2820         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2821                 (and:SI (match_dup 2) (match_dup 3))))]
2822   "TARGET_POWER"
2823   "@
2824    maskir. %0,%3,%2
2825    #"
2826   [(set_attr "type" "compare")
2827    (set_attr "length" "4,8")])
2828
2829 (define_split
2830   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2831         (compare:CC
2832          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
2833                          (match_operand:SI 1 "gpc_reg_operand" ""))
2834                  (and:SI (match_dup 2)
2835                          (match_operand:SI 3 "gpc_reg_operand" "")))
2836          (const_int 0)))
2837    (set (match_operand:SI 0 "gpc_reg_operand" "")
2838         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2839                 (and:SI (match_dup 2) (match_dup 3))))]
2840   "TARGET_POWER && reload_completed"
2841   [(set (match_dup 0)
2842         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2843                 (and:SI (match_dup 2) (match_dup 3))))
2844    (set (match_dup 4)
2845         (compare:CC (match_dup 0)
2846                     (const_int 0)))]
2847   "")
2848
2849 (define_insn "*maskir_internal6"
2850   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2851         (compare:CC
2852          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2853                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
2854                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
2855                          (match_dup 2)))
2856          (const_int 0)))
2857    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2858         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2859                 (and:SI (match_dup 3) (match_dup 2))))]
2860   "TARGET_POWER"
2861   "@
2862    maskir. %0,%3,%2
2863    #"
2864   [(set_attr "type" "compare")
2865    (set_attr "length" "4,8")])
2866
2867 (define_split
2868   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2869         (compare:CC
2870          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
2871                          (match_operand:SI 1 "gpc_reg_operand" ""))
2872                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
2873                          (match_dup 2)))
2874          (const_int 0)))
2875    (set (match_operand:SI 0 "gpc_reg_operand" "")
2876         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2877                 (and:SI (match_dup 3) (match_dup 2))))]
2878   "TARGET_POWER && reload_completed"
2879   [(set (match_dup 0)
2880         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2881                 (and:SI (match_dup 3) (match_dup 2))))
2882    (set (match_dup 4)
2883         (compare:CC (match_dup 0)
2884                     (const_int 0)))]
2885   "")
2886
2887 (define_insn "*maskir_internal7"
2888   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2889         (compare:CC
2890          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r,r")
2891                          (match_operand:SI 3 "gpc_reg_operand" "r,r"))
2892                  (and:SI (not:SI (match_dup 2))
2893                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
2894          (const_int 0)))
2895    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2896         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2897                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2898   "TARGET_POWER"
2899   "@
2900    maskir. %0,%3,%2
2901    #"
2902   [(set_attr "type" "compare")
2903    (set_attr "length" "4,8")])
2904
2905 (define_split
2906   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2907         (compare:CC
2908          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "")
2909                          (match_operand:SI 3 "gpc_reg_operand" ""))
2910                  (and:SI (not:SI (match_dup 2))
2911                          (match_operand:SI 1 "gpc_reg_operand" "")))
2912          (const_int 0)))
2913    (set (match_operand:SI 0 "gpc_reg_operand" "")
2914         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2915                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2916   "TARGET_POWER && reload_completed"
2917   [(set (match_dup 0)
2918         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2919                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
2920    (set (match_dup 4)
2921         (compare:CC (match_dup 0)
2922                     (const_int 0)))]
2923   "")
2924
2925 (define_insn "*maskir_internal8"
2926   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2927         (compare:CC
2928          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
2929                          (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2930                  (and:SI (not:SI (match_dup 2))
2931                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
2932          (const_int 0)))
2933    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2934         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2935                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2936   "TARGET_POWER"
2937   "@
2938    maskir. %0,%3,%2
2939    #"
2940   [(set_attr "type" "compare")
2941    (set_attr "length" "4,8")])
2942
2943 (define_split
2944   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2945         (compare:CC
2946          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
2947                          (match_operand:SI 2 "gpc_reg_operand" ""))
2948                  (and:SI (not:SI (match_dup 2))
2949                          (match_operand:SI 1 "gpc_reg_operand" "")))
2950          (const_int 0)))
2951    (set (match_operand:SI 0 "gpc_reg_operand" "")
2952         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2953                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2954   "TARGET_POWER && reload_completed"
2955   [(set (match_dup 0)
2956         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2957                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
2958    (set (match_dup 4)
2959         (compare:CC (match_dup 0)
2960                     (const_int 0)))]
2961   "")
2962 \f
2963 ;; Rotate and shift insns, in all their variants.  These support shifts,
2964 ;; field inserts and extracts, and various combinations thereof.
2965 (define_expand "insv"
2966   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
2967                        (match_operand:SI 1 "const_int_operand" "")
2968                        (match_operand:SI 2 "const_int_operand" ""))
2969         (match_operand 3 "gpc_reg_operand" ""))]
2970   ""
2971   "
2972 {
2973   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
2974      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
2975      compiler if the address of the structure is taken later.  */
2976   if (GET_CODE (operands[0]) == SUBREG
2977       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
2978     FAIL;
2979
2980   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
2981     emit_insn (gen_insvdi (operands[0], operands[1], operands[2], operands[3]));
2982   else
2983     emit_insn (gen_insvsi (operands[0], operands[1], operands[2], operands[3]));
2984   DONE;
2985 }")
2986
2987 (define_insn "insvsi"
2988   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2989                          (match_operand:SI 1 "const_int_operand" "i")
2990                          (match_operand:SI 2 "const_int_operand" "i"))
2991         (match_operand:SI 3 "gpc_reg_operand" "r"))]
2992   ""
2993   "*
2994 {
2995   int start = INTVAL (operands[2]) & 31;
2996   int size = INTVAL (operands[1]) & 31;
2997
2998   operands[4] = GEN_INT (32 - start - size);
2999   operands[1] = GEN_INT (start + size - 1);
3000   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3001 }"
3002   [(set_attr "type" "insert_word")])
3003
3004 (define_insn "*insvsi_internal1"
3005   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3006                          (match_operand:SI 1 "const_int_operand" "i")
3007                          (match_operand:SI 2 "const_int_operand" "i"))
3008         (rotate:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3009                    (match_operand:SI 4 "const_int_operand" "i")))]
3010   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3011   "*
3012 {
3013   int shift = INTVAL (operands[4]) & 31;
3014   int start = INTVAL (operands[2]) & 31;
3015   int size = INTVAL (operands[1]) & 31;
3016
3017   operands[4] = GEN_INT (shift - start - size);
3018   operands[1] = GEN_INT (start + size - 1);
3019   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3020 }"
3021   [(set_attr "type" "insert_word")])
3022
3023 (define_insn "*insvsi_internal2"
3024   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3025                          (match_operand:SI 1 "const_int_operand" "i")
3026                          (match_operand:SI 2 "const_int_operand" "i"))
3027         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3028                      (match_operand:SI 4 "const_int_operand" "i")))]
3029   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3030   "*
3031 {
3032   int shift = INTVAL (operands[4]) & 31;
3033   int start = INTVAL (operands[2]) & 31;
3034   int size = INTVAL (operands[1]) & 31;
3035
3036   operands[4] = GEN_INT (32 - shift - start - size);
3037   operands[1] = GEN_INT (start + size - 1);
3038   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3039 }"
3040   [(set_attr "type" "insert_word")])
3041
3042 (define_insn "*insvsi_internal3"
3043   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3044                          (match_operand:SI 1 "const_int_operand" "i")
3045                          (match_operand:SI 2 "const_int_operand" "i"))
3046         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3047                      (match_operand:SI 4 "const_int_operand" "i")))]
3048   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3049   "*
3050 {
3051   int shift = INTVAL (operands[4]) & 31;
3052   int start = INTVAL (operands[2]) & 31;
3053   int size = INTVAL (operands[1]) & 31;
3054
3055   operands[4] = GEN_INT (32 - shift - start - size);
3056   operands[1] = GEN_INT (start + size - 1);
3057   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3058 }"
3059   [(set_attr "type" "insert_word")])
3060
3061 (define_insn "*insvsi_internal4"
3062   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3063                          (match_operand:SI 1 "const_int_operand" "i")
3064                          (match_operand:SI 2 "const_int_operand" "i"))
3065         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3066                          (match_operand:SI 4 "const_int_operand" "i")
3067                          (match_operand:SI 5 "const_int_operand" "i")))]
3068   "INTVAL (operands[4]) >= INTVAL (operands[1])"
3069   "*
3070 {
3071   int extract_start = INTVAL (operands[5]) & 31;
3072   int extract_size = INTVAL (operands[4]) & 31;
3073   int insert_start = INTVAL (operands[2]) & 31;
3074   int insert_size = INTVAL (operands[1]) & 31;
3075
3076 /* Align extract field with insert field */
3077   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
3078   operands[1] = GEN_INT (insert_start + insert_size - 1);
3079   return \"{rlimi|rlwimi} %0,%3,%h5,%h2,%h1\";
3080 }"
3081   [(set_attr "type" "insert_word")])
3082
3083 ;; combine patterns for rlwimi
3084 (define_insn "*insvsi_internal5"
3085   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3086         (ior:SI (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3087                         (match_operand:SI 1 "mask_operand" "i"))
3088                 (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3089                                      (match_operand:SI 2 "const_int_operand" "i"))
3090                         (match_operand:SI 5 "mask_operand" "i"))))]
3091   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
3092   "*
3093 {
3094  int me = extract_ME(operands[5]);
3095  int mb = extract_MB(operands[5]);
3096  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3097  operands[2] = GEN_INT(mb);
3098  operands[1] = GEN_INT(me);
3099  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3100 }"
3101   [(set_attr "type" "insert_word")])
3102
3103 (define_insn "*insvsi_internal6"
3104   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3105         (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3106                                      (match_operand:SI 2 "const_int_operand" "i"))
3107                         (match_operand:SI 5 "mask_operand" "i"))
3108                 (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3109                         (match_operand:SI 1 "mask_operand" "i"))))]
3110   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
3111   "*
3112 {
3113  int me = extract_ME(operands[5]);
3114  int mb = extract_MB(operands[5]);
3115  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3116  operands[2] = GEN_INT(mb);
3117  operands[1] = GEN_INT(me);
3118  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3119 }"
3120   [(set_attr "type" "insert_word")])
3121
3122 (define_insn "insvdi"
3123   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3124                          (match_operand:SI 1 "const_int_operand" "i")
3125                          (match_operand:SI 2 "const_int_operand" "i"))
3126         (match_operand:DI 3 "gpc_reg_operand" "r"))]
3127   "TARGET_POWERPC64"
3128   "*
3129 {
3130   int start = INTVAL (operands[2]) & 63;
3131   int size = INTVAL (operands[1]) & 63;
3132
3133   operands[1] = GEN_INT (64 - start - size);
3134   return \"rldimi %0,%3,%H1,%H2\";
3135 }")
3136
3137 (define_insn "*insvdi_internal2"
3138   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3139                          (match_operand:SI 1 "const_int_operand" "i")
3140                          (match_operand:SI 2 "const_int_operand" "i"))
3141         (ashiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3142                      (match_operand:SI 4 "const_int_operand" "i")))]
3143   "TARGET_POWERPC64
3144    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3145   "*
3146 {
3147   int shift = INTVAL (operands[4]) & 63;
3148   int start = (INTVAL (operands[2]) & 63) - 32;
3149   int size = INTVAL (operands[1]) & 63;
3150
3151   operands[4] = GEN_INT (64 - shift - start - size);
3152   operands[2] = GEN_INT (start);
3153   operands[1] = GEN_INT (start + size - 1);
3154   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3155 }")
3156
3157 (define_insn "*insvdi_internal3"
3158   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3159                          (match_operand:SI 1 "const_int_operand" "i")
3160                          (match_operand:SI 2 "const_int_operand" "i"))
3161         (lshiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3162                      (match_operand:SI 4 "const_int_operand" "i")))]
3163   "TARGET_POWERPC64
3164    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3165   "*
3166 {
3167   int shift = INTVAL (operands[4]) & 63;
3168   int start = (INTVAL (operands[2]) & 63) - 32;
3169   int size = INTVAL (operands[1]) & 63;
3170
3171   operands[4] = GEN_INT (64 - shift - start - size);
3172   operands[2] = GEN_INT (start);
3173   operands[1] = GEN_INT (start + size - 1);
3174   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3175 }")
3176
3177 (define_expand "extzv"
3178   [(set (match_operand 0 "gpc_reg_operand" "")
3179         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3180                        (match_operand:SI 2 "const_int_operand" "")
3181                        (match_operand:SI 3 "const_int_operand" "")))]
3182   ""
3183   "
3184 {
3185   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3186      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3187      compiler if the address of the structure is taken later.  */
3188   if (GET_CODE (operands[0]) == SUBREG
3189       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3190     FAIL;
3191
3192   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3193     emit_insn (gen_extzvdi (operands[0], operands[1], operands[2], operands[3]));
3194   else
3195     emit_insn (gen_extzvsi (operands[0], operands[1], operands[2], operands[3]));
3196   DONE;
3197 }")
3198
3199 (define_insn "extzvsi"
3200   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3201         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3202                          (match_operand:SI 2 "const_int_operand" "i")
3203                          (match_operand:SI 3 "const_int_operand" "i")))]
3204   ""
3205   "*
3206 {
3207   int start = INTVAL (operands[3]) & 31;
3208   int size = INTVAL (operands[2]) & 31;
3209
3210   if (start + size >= 32)
3211     operands[3] = const0_rtx;
3212   else
3213     operands[3] = GEN_INT (start + size);
3214   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
3215 }")
3216
3217 (define_insn "*extzvsi_internal1"
3218   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3219         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3220                          (match_operand:SI 2 "const_int_operand" "i,i")
3221                          (match_operand:SI 3 "const_int_operand" "i,i"))
3222                     (const_int 0)))
3223    (clobber (match_scratch:SI 4 "=r,r"))]
3224   ""
3225   "*
3226 {
3227   int start = INTVAL (operands[3]) & 31;
3228   int size = INTVAL (operands[2]) & 31;
3229
3230   /* Force split for non-cc0 compare.  */
3231   if (which_alternative == 1)
3232      return \"#\";
3233
3234   /* If the bit-field being tested fits in the upper or lower half of a
3235      word, it is possible to use andiu. or andil. to test it.  This is
3236      useful because the condition register set-use delay is smaller for
3237      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3238      position is 0 because the LT and GT bits may be set wrong.  */
3239
3240   if ((start > 0 && start + size <= 16) || start >= 16)
3241     {
3242       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3243                               - (1 << (16 - (start & 15) - size))));
3244       if (start < 16)
3245         return \"{andiu.|andis.} %4,%1,%3\";
3246       else
3247         return \"{andil.|andi.} %4,%1,%3\";
3248     }
3249
3250   if (start + size >= 32)
3251     operands[3] = const0_rtx;
3252   else
3253     operands[3] = GEN_INT (start + size);
3254   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
3255 }"
3256   [(set_attr "type" "compare")
3257    (set_attr "length" "4,8")])
3258
3259 (define_split
3260   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3261         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3262                          (match_operand:SI 2 "const_int_operand" "")
3263                          (match_operand:SI 3 "const_int_operand" ""))
3264                     (const_int 0)))
3265    (clobber (match_scratch:SI 4 ""))]
3266   "reload_completed"
3267   [(set (match_dup 4)
3268         (zero_extract:SI (match_dup 1) (match_dup 2)
3269                          (match_dup 3)))
3270    (set (match_dup 0)
3271         (compare:CC (match_dup 4)
3272                     (const_int 0)))]
3273   "")
3274
3275 (define_insn "*extzvsi_internal2"
3276   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3277         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3278                          (match_operand:SI 2 "const_int_operand" "i,i")
3279                          (match_operand:SI 3 "const_int_operand" "i,i"))
3280                     (const_int 0)))
3281    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3282         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3283   ""
3284   "*
3285 {
3286   int start = INTVAL (operands[3]) & 31;
3287   int size = INTVAL (operands[2]) & 31;
3288
3289   /* Force split for non-cc0 compare.  */
3290   if (which_alternative == 1)
3291      return \"#\";
3292
3293   /* Since we are using the output value, we can't ignore any need for
3294      a shift.  The bit-field must end at the LSB.  */
3295   if (start >= 16 && start + size == 32)
3296     {
3297       operands[3] = GEN_INT ((1 << size) - 1);
3298       return \"{andil.|andi.} %0,%1,%3\";
3299     }
3300
3301   if (start + size >= 32)
3302     operands[3] = const0_rtx;
3303   else
3304     operands[3] = GEN_INT (start + size);
3305   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
3306 }"
3307   [(set_attr "type" "compare")
3308    (set_attr "length" "4,8")])
3309
3310 (define_split
3311   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3312         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3313                          (match_operand:SI 2 "const_int_operand" "")
3314                          (match_operand:SI 3 "const_int_operand" ""))
3315                     (const_int 0)))
3316    (set (match_operand:SI 0 "gpc_reg_operand" "")
3317         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3318   "reload_completed"
3319   [(set (match_dup 0)
3320         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3321    (set (match_dup 4)
3322         (compare:CC (match_dup 0)
3323                     (const_int 0)))]
3324   "")
3325
3326 (define_insn "extzvdi"
3327   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3328         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3329                          (match_operand:SI 2 "const_int_operand" "i")
3330                          (match_operand:SI 3 "const_int_operand" "i")))]
3331   "TARGET_POWERPC64"
3332   "*
3333 {
3334   int start = INTVAL (operands[3]) & 63;
3335   int size = INTVAL (operands[2]) & 63;
3336
3337   if (start + size >= 64)
3338     operands[3] = const0_rtx;
3339   else
3340     operands[3] = GEN_INT (start + size);
3341   operands[2] = GEN_INT (64 - size);
3342   return \"rldicl %0,%1,%3,%2\";
3343 }")
3344
3345 (define_insn "*extzvdi_internal1"
3346   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3347         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3348                          (match_operand:SI 2 "const_int_operand" "i")
3349                          (match_operand:SI 3 "const_int_operand" "i"))
3350                     (const_int 0)))
3351    (clobber (match_scratch:DI 4 "=r"))]
3352   "TARGET_64BIT"
3353   "*
3354 {
3355   int start = INTVAL (operands[3]) & 63;
3356   int size = INTVAL (operands[2]) & 63;
3357
3358   if (start + size >= 64)
3359     operands[3] = const0_rtx;
3360   else
3361     operands[3] = GEN_INT (start + size);
3362   operands[2] = GEN_INT (64 - size);
3363   return \"rldicl. %4,%1,%3,%2\";
3364 }"
3365   [(set_attr "type" "compare")])
3366
3367 (define_insn "*extzvdi_internal2"
3368   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3369         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3370                          (match_operand:SI 2 "const_int_operand" "i")
3371                          (match_operand:SI 3 "const_int_operand" "i"))
3372                     (const_int 0)))
3373    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3374         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3375   "TARGET_64BIT"
3376   "*
3377 {
3378   int start = INTVAL (operands[3]) & 63;
3379   int size = INTVAL (operands[2]) & 63;
3380
3381   if (start + size >= 64)
3382     operands[3] = const0_rtx;
3383   else
3384     operands[3] = GEN_INT (start + size);
3385   operands[2] = GEN_INT (64 - size);
3386   return \"rldicl. %0,%1,%3,%2\";
3387 }"
3388   [(set_attr "type" "compare")])
3389
3390 (define_insn "rotlsi3"
3391   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3392         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3393                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3394   ""
3395   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffffffff")
3396
3397 (define_insn "*rotlsi3_internal2"
3398   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3399         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3400                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3401                     (const_int 0)))
3402    (clobber (match_scratch:SI 3 "=r,r"))]
3403   ""
3404   "@
3405    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffffffff
3406    #"
3407   [(set_attr "type" "delayed_compare")
3408    (set_attr "length" "4,8")])
3409
3410 (define_split
3411   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3412         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3413                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3414                     (const_int 0)))
3415    (clobber (match_scratch:SI 3 ""))]
3416   "reload_completed"
3417   [(set (match_dup 3)
3418         (rotate:SI (match_dup 1) (match_dup 2)))
3419    (set (match_dup 0)
3420         (compare:CC (match_dup 3)
3421                     (const_int 0)))]
3422   "")
3423
3424 (define_insn "*rotlsi3_internal3"
3425   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3426         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3427                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3428                     (const_int 0)))
3429    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3430         (rotate:SI (match_dup 1) (match_dup 2)))]
3431   ""
3432   "@
3433    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffffffff
3434    #"
3435   [(set_attr "type" "delayed_compare")
3436    (set_attr "length" "4,8")])
3437
3438 (define_split
3439   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3440         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3441                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3442                     (const_int 0)))
3443    (set (match_operand:SI 0 "gpc_reg_operand" "")
3444         (rotate:SI (match_dup 1) (match_dup 2)))]
3445   "reload_completed"
3446   [(set (match_dup 0)
3447         (rotate:SI (match_dup 1) (match_dup 2)))
3448    (set (match_dup 3)
3449         (compare:CC (match_dup 0)
3450                     (const_int 0)))]
3451   "")
3452
3453 (define_insn "*rotlsi3_internal4"
3454   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3455         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3456                            (match_operand:SI 2 "reg_or_cint_operand" "ri"))
3457                 (match_operand:SI 3 "mask_operand" "n")))]
3458   ""
3459   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,%m3,%M3")
3460
3461 (define_insn "*rotlsi3_internal5"
3462   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3463         (compare:CC (and:SI
3464                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3465                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3466                      (match_operand:SI 3 "mask_operand" "n,n"))
3467                     (const_int 0)))
3468    (clobber (match_scratch:SI 4 "=r,r"))]
3469   ""
3470   "@
3471    {rl%I2nm.|rlw%I2nm.} %4,%1,%h2,%m3,%M3
3472    #"
3473   [(set_attr "type" "delayed_compare")
3474    (set_attr "length" "4,8")])
3475
3476 (define_split
3477   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3478         (compare:CC (and:SI
3479                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3480                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3481                      (match_operand:SI 3 "mask_operand" ""))
3482                     (const_int 0)))
3483    (clobber (match_scratch:SI 4 ""))]
3484   "reload_completed"
3485   [(set (match_dup 4)
3486         (and:SI (rotate:SI (match_dup 1)
3487                                 (match_dup 2))
3488                      (match_dup 3)))
3489    (set (match_dup 0)
3490         (compare:CC (match_dup 4)
3491                     (const_int 0)))]
3492   "")
3493
3494 (define_insn "*rotlsi3_internal6"
3495   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3496         (compare:CC (and:SI
3497                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3498                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3499                      (match_operand:SI 3 "mask_operand" "n,n"))
3500                     (const_int 0)))
3501    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3502         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3503   ""
3504   "@
3505    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,%m3,%M3
3506    #"
3507   [(set_attr "type" "delayed_compare")
3508    (set_attr "length" "4,8")])
3509
3510 (define_split
3511   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3512         (compare:CC (and:SI
3513                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3514                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3515                      (match_operand:SI 3 "mask_operand" ""))
3516                     (const_int 0)))
3517    (set (match_operand:SI 0 "gpc_reg_operand" "")
3518         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3519   "reload_completed"
3520   [(set (match_dup 0)
3521         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3522    (set (match_dup 4)
3523         (compare:CC (match_dup 0)
3524                     (const_int 0)))]
3525   "")
3526
3527 (define_insn "*rotlsi3_internal7"
3528   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3529         (zero_extend:SI
3530          (subreg:QI
3531           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3532                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3533   ""
3534   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff")
3535
3536 (define_insn "*rotlsi3_internal8"
3537   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3538         (compare:CC (zero_extend:SI
3539                      (subreg:QI
3540                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3541                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3542                     (const_int 0)))
3543    (clobber (match_scratch:SI 3 "=r,r"))]
3544   ""
3545   "@
3546    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xff
3547    #"
3548   [(set_attr "type" "delayed_compare")
3549    (set_attr "length" "4,8")])
3550
3551 (define_split
3552   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3553         (compare:CC (zero_extend:SI
3554                      (subreg:QI
3555                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3556                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3557                     (const_int 0)))
3558    (clobber (match_scratch:SI 3 ""))]
3559   "reload_completed"
3560   [(set (match_dup 3)
3561         (zero_extend:SI (subreg:QI
3562                       (rotate:SI (match_dup 1)
3563                                  (match_dup 2)) 0)))
3564    (set (match_dup 0)
3565         (compare:CC (match_dup 3)
3566                     (const_int 0)))]
3567   "")
3568
3569 (define_insn "*rotlsi3_internal9"
3570   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3571         (compare:CC (zero_extend:SI
3572                      (subreg:QI
3573                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3574                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3575                     (const_int 0)))
3576    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3577         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3578   ""
3579   "@
3580    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xff
3581    #"
3582   [(set_attr "type" "delayed_compare")
3583    (set_attr "length" "4,8")])
3584
3585 (define_split
3586   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3587         (compare:CC (zero_extend:SI
3588                      (subreg:QI
3589                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3590                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3591                     (const_int 0)))
3592    (set (match_operand:SI 0 "gpc_reg_operand" "")
3593         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3594   "reload_completed"
3595   [(set (match_dup 0)
3596         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3597    (set (match_dup 3)
3598         (compare:CC (match_dup 0)
3599                     (const_int 0)))]
3600   "")
3601
3602 (define_insn "*rotlsi3_internal10"
3603   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3604         (zero_extend:SI
3605          (subreg:HI
3606           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3607                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3608   ""
3609   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffff")
3610
3611 (define_insn "*rotlsi3_internal11"
3612   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3613         (compare:CC (zero_extend:SI
3614                      (subreg:HI
3615                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3616                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3617                     (const_int 0)))
3618    (clobber (match_scratch:SI 3 "=r,r"))]
3619   ""
3620   "@
3621    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffff
3622    #"
3623   [(set_attr "type" "delayed_compare")
3624    (set_attr "length" "4,8")])
3625
3626 (define_split
3627   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3628         (compare:CC (zero_extend:SI
3629                      (subreg:HI
3630                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3631                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3632                     (const_int 0)))
3633    (clobber (match_scratch:SI 3 ""))]
3634   "reload_completed"
3635   [(set (match_dup 3)
3636         (zero_extend:SI (subreg:HI
3637                       (rotate:SI (match_dup 1)
3638                                  (match_dup 2)) 0)))
3639    (set (match_dup 0)
3640         (compare:CC (match_dup 3)
3641                     (const_int 0)))]
3642   "")
3643
3644 (define_insn "*rotlsi3_internal12"
3645   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3646         (compare:CC (zero_extend:SI
3647                      (subreg:HI
3648                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3649                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3650                     (const_int 0)))
3651    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3652         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3653   ""
3654   "@
3655    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffff
3656    #"
3657   [(set_attr "type" "delayed_compare")
3658    (set_attr "length" "4,8")])
3659
3660 (define_split
3661   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3662         (compare:CC (zero_extend:SI
3663                      (subreg:HI
3664                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3665                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3666                     (const_int 0)))
3667    (set (match_operand:SI 0 "gpc_reg_operand" "")
3668         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3669   "reload_completed"
3670   [(set (match_dup 0)
3671         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3672    (set (match_dup 3)
3673         (compare:CC (match_dup 0)
3674                     (const_int 0)))]
3675   "")
3676
3677 ;; Note that we use "sle." instead of "sl." so that we can set
3678 ;; SHIFT_COUNT_TRUNCATED.
3679
3680 (define_expand "ashlsi3"
3681   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
3682    (use (match_operand:SI 1 "gpc_reg_operand" ""))
3683    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
3684   ""
3685   "
3686 {
3687   if (TARGET_POWER)
3688     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
3689   else
3690     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
3691   DONE;
3692 }")
3693
3694 (define_insn "ashlsi3_power"
3695   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3696         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3697                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
3698    (clobber (match_scratch:SI 3 "=q,X"))]
3699   "TARGET_POWER"
3700   "@
3701    sle %0,%1,%2
3702    {sli|slwi} %0,%1,%h2")
3703
3704 (define_insn "ashlsi3_no_power"
3705   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3706         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3707                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3708   "! TARGET_POWER"
3709   "{sl|slw}%I2 %0,%1,%h2")
3710
3711 (define_insn ""
3712   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3713         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3714                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3715                     (const_int 0)))
3716    (clobber (match_scratch:SI 3 "=r,r,r,r"))
3717    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
3718   "TARGET_POWER"
3719   "@
3720    sle. %3,%1,%2
3721    {sli.|slwi.} %3,%1,%h2
3722    #
3723    #"
3724   [(set_attr "type" "delayed_compare")
3725    (set_attr "length" "4,4,8,8")])
3726
3727 (define_split
3728   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3729         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3730                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3731                     (const_int 0)))
3732    (clobber (match_scratch:SI 3 ""))
3733    (clobber (match_scratch:SI 4 ""))]
3734   "TARGET_POWER && reload_completed"
3735   [(parallel [(set (match_dup 3)
3736         (ashift:SI (match_dup 1) (match_dup 2)))
3737    (clobber (match_dup 4))])
3738    (set (match_dup 0)
3739         (compare:CC (match_dup 3)
3740                     (const_int 0)))]
3741   "")
3742
3743 (define_insn ""
3744   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3745         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3746                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3747                     (const_int 0)))
3748    (clobber (match_scratch:SI 3 "=r,r"))]
3749   "! TARGET_POWER && TARGET_32BIT"
3750   "@
3751    {sl|slw}%I2. %3,%1,%h2
3752    #"
3753   [(set_attr "type" "delayed_compare")
3754    (set_attr "length" "4,8")])
3755
3756 (define_split
3757   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3758         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3759                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3760                     (const_int 0)))
3761    (clobber (match_scratch:SI 3 ""))]
3762   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3763   [(set (match_dup 3)
3764         (ashift:SI (match_dup 1) (match_dup 2)))
3765    (set (match_dup 0)
3766         (compare:CC (match_dup 3)
3767                     (const_int 0)))]
3768   "")
3769
3770 (define_insn ""
3771   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3772         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3773                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3774                     (const_int 0)))
3775    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3776         (ashift:SI (match_dup 1) (match_dup 2)))
3777    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
3778   "TARGET_POWER"
3779   "@
3780    sle. %0,%1,%2
3781    {sli.|slwi.} %0,%1,%h2
3782    #
3783    #"
3784   [(set_attr "type" "delayed_compare")
3785    (set_attr "length" "4,4,8,8")])
3786
3787 (define_split
3788   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3789         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3790                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3791                     (const_int 0)))
3792    (set (match_operand:SI 0 "gpc_reg_operand" "")
3793         (ashift:SI (match_dup 1) (match_dup 2)))
3794    (clobber (match_scratch:SI 4 ""))]
3795   "TARGET_POWER && reload_completed"
3796   [(parallel [(set (match_dup 0)
3797         (ashift:SI (match_dup 1) (match_dup 2)))
3798    (clobber (match_dup 4))])
3799    (set (match_dup 3)
3800         (compare:CC (match_dup 0)
3801                     (const_int 0)))]
3802   "")
3803
3804 (define_insn ""
3805   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3806         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3807                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3808                     (const_int 0)))
3809    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3810         (ashift:SI (match_dup 1) (match_dup 2)))]
3811   "! TARGET_POWER && TARGET_32BIT"
3812   "@
3813    {sl|slw}%I2. %0,%1,%h2
3814    #"
3815   [(set_attr "type" "delayed_compare")
3816    (set_attr "length" "4,8")])
3817
3818 (define_split
3819   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3820         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3821                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3822                     (const_int 0)))
3823    (set (match_operand:SI 0 "gpc_reg_operand" "")
3824         (ashift:SI (match_dup 1) (match_dup 2)))]
3825   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3826   [(set (match_dup 0)
3827         (ashift:SI (match_dup 1) (match_dup 2)))
3828    (set (match_dup 3)
3829         (compare:CC (match_dup 0)
3830                     (const_int 0)))]
3831   "")
3832
3833 (define_insn "rlwinm"
3834   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3835         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3836                            (match_operand:SI 2 "const_int_operand" "i"))
3837                 (match_operand:SI 3 "mask_operand" "n")))]
3838   "includes_lshift_p (operands[2], operands[3])"
3839   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
3840
3841 (define_insn ""
3842   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3843         (compare:CC
3844          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3845                             (match_operand:SI 2 "const_int_operand" "i,i"))
3846                  (match_operand:SI 3 "mask_operand" "n,n"))
3847          (const_int 0)))
3848    (clobber (match_scratch:SI 4 "=r,r"))]
3849   "includes_lshift_p (operands[2], operands[3])"
3850   "@
3851    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
3852    #"
3853   [(set_attr "type" "delayed_compare")
3854    (set_attr "length" "4,8")])
3855
3856 (define_split
3857   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3858         (compare:CC
3859          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3860                             (match_operand:SI 2 "const_int_operand" ""))
3861                  (match_operand:SI 3 "mask_operand" ""))
3862          (const_int 0)))
3863    (clobber (match_scratch:SI 4 ""))]
3864   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
3865   [(set (match_dup 4)
3866         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
3867                  (match_dup 3)))
3868    (set (match_dup 0)
3869         (compare:CC (match_dup 4)
3870                     (const_int 0)))]
3871   "")
3872
3873 (define_insn ""
3874   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3875         (compare:CC
3876          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3877                             (match_operand:SI 2 "const_int_operand" "i,i"))
3878                  (match_operand:SI 3 "mask_operand" "n,n"))
3879          (const_int 0)))
3880    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3881         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3882   "includes_lshift_p (operands[2], operands[3])"
3883   "@
3884    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
3885    #"
3886   [(set_attr "type" "delayed_compare")
3887    (set_attr "length" "4,8")])
3888
3889 (define_split
3890   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3891         (compare:CC
3892          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3893                             (match_operand:SI 2 "const_int_operand" ""))
3894                  (match_operand:SI 3 "mask_operand" ""))
3895          (const_int 0)))
3896    (set (match_operand:SI 0 "gpc_reg_operand" "")
3897         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3898   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
3899   [(set (match_dup 0)
3900         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3901    (set (match_dup 4)
3902         (compare:CC (match_dup 0)
3903                     (const_int 0)))]
3904   "")
3905
3906 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
3907 ;; "sli x,x,0".
3908 (define_expand "lshrsi3"
3909   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
3910    (use (match_operand:SI 1 "gpc_reg_operand" ""))
3911    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
3912   ""
3913   "
3914 {
3915   if (TARGET_POWER)
3916     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
3917   else
3918     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
3919   DONE;
3920 }")
3921
3922 (define_insn "lshrsi3_power"
3923   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
3924         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
3925                      (match_operand:SI 2 "reg_or_cint_operand" "r,O,i")))
3926    (clobber (match_scratch:SI 3 "=q,X,X"))]
3927   "TARGET_POWER"
3928   "@
3929   sre %0,%1,%2
3930   mr %0,%1
3931   {s%A2i|s%A2wi} %0,%1,%h2")
3932
3933 (define_insn "lshrsi3_no_power"
3934   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3935         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3936                      (match_operand:SI 2 "reg_or_cint_operand" "O,ri")))]
3937   "! TARGET_POWER"
3938   "@
3939   mr %0,%1
3940   {sr|srw}%I2 %0,%1,%h2")
3941
3942 (define_insn ""
3943   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
3944         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
3945                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
3946                     (const_int 0)))
3947    (clobber (match_scratch:SI 3 "=r,X,r,r,X,r"))
3948    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
3949   "TARGET_POWER"
3950   "@
3951   sre. %3,%1,%2
3952   mr. %1,%1
3953   {s%A2i.|s%A2wi.} %3,%1,%h2
3954   #
3955   #
3956   #"
3957   [(set_attr "type" "delayed_compare")
3958    (set_attr "length" "4,4,4,8,8,8")])
3959
3960 (define_split
3961   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3962         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3963                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3964                     (const_int 0)))
3965    (clobber (match_scratch:SI 3 ""))
3966    (clobber (match_scratch:SI 4 ""))]
3967   "TARGET_POWER && reload_completed"
3968   [(parallel [(set (match_dup 3)
3969         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3970    (clobber (match_dup 4))])
3971    (set (match_dup 0)
3972         (compare:CC (match_dup 3)
3973                     (const_int 0)))]
3974   "")
3975
3976 (define_insn ""
3977   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3978         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3979                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
3980                     (const_int 0)))
3981    (clobber (match_scratch:SI 3 "=X,r,X,r"))]
3982   "! TARGET_POWER && TARGET_32BIT"
3983   "@
3984    mr. %1,%1
3985    {sr|srw}%I2. %3,%1,%h2
3986    #
3987    #"
3988   [(set_attr "type" "delayed_compare")
3989    (set_attr "length" "4,4,8,8")])
3990
3991 (define_split
3992   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3993         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3994                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3995                     (const_int 0)))
3996    (clobber (match_scratch:SI 3 ""))]
3997   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3998   [(set (match_dup 3)
3999         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4000    (set (match_dup 0)
4001         (compare:CC (match_dup 3)
4002                     (const_int 0)))]
4003   "")
4004
4005 (define_insn ""
4006   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4007         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4008                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
4009                     (const_int 0)))
4010    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
4011         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4012    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
4013   "TARGET_POWER"
4014   "@
4015   sre. %0,%1,%2
4016   mr. %0,%1
4017   {s%A2i.|s%A2wi.} %0,%1,%h2
4018   #
4019   #
4020   #"
4021   [(set_attr "type" "delayed_compare")
4022    (set_attr "length" "4,4,4,8,8,8")])
4023
4024 (define_split
4025   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4026         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4027                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4028                     (const_int 0)))
4029    (set (match_operand:SI 0 "gpc_reg_operand" "")
4030         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4031    (clobber (match_scratch:SI 4 ""))]
4032   "TARGET_POWER && reload_completed"
4033   [(parallel [(set (match_dup 0)
4034         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4035    (clobber (match_dup 4))])
4036    (set (match_dup 3)
4037         (compare:CC (match_dup 0)
4038                     (const_int 0)))]
4039   "")
4040
4041 (define_insn ""
4042   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4043         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4044                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
4045                     (const_int 0)))
4046    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4047         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4048   "! TARGET_POWER && TARGET_32BIT"
4049   "@
4050    mr. %0,%1
4051    {sr|srw}%I2. %0,%1,%h2
4052    #
4053    #"
4054   [(set_attr "type" "delayed_compare")
4055    (set_attr "length" "4,4,8,8")])
4056
4057 (define_split
4058   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4059         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4060                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4061                     (const_int 0)))
4062    (set (match_operand:SI 0 "gpc_reg_operand" "")
4063         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4064   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4065   [(set (match_dup 0)
4066         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4067    (set (match_dup 3)
4068         (compare:CC (match_dup 0)
4069                     (const_int 0)))]
4070   "")
4071
4072 (define_insn ""
4073   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4074         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4075                              (match_operand:SI 2 "const_int_operand" "i"))
4076                 (match_operand:SI 3 "mask_operand" "n")))]
4077   "includes_rshift_p (operands[2], operands[3])"
4078   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
4079
4080 (define_insn ""
4081   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4082         (compare:CC
4083          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4084                               (match_operand:SI 2 "const_int_operand" "i,i"))
4085                  (match_operand:SI 3 "mask_operand" "n,n"))
4086          (const_int 0)))
4087    (clobber (match_scratch:SI 4 "=r,r"))]
4088   "includes_rshift_p (operands[2], operands[3])"
4089   "@
4090    {rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3
4091    #"
4092   [(set_attr "type" "delayed_compare")
4093    (set_attr "length" "4,8")])
4094
4095 (define_split
4096   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4097         (compare:CC
4098          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4099                               (match_operand:SI 2 "const_int_operand" ""))
4100                  (match_operand:SI 3 "mask_operand" ""))
4101          (const_int 0)))
4102    (clobber (match_scratch:SI 4 ""))]
4103   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4104   [(set (match_dup 4)
4105         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
4106                  (match_dup 3)))
4107    (set (match_dup 0)
4108         (compare:CC (match_dup 4)
4109                     (const_int 0)))]
4110   "")
4111
4112 (define_insn ""
4113   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4114         (compare:CC
4115          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4116                               (match_operand:SI 2 "const_int_operand" "i,i"))
4117                  (match_operand:SI 3 "mask_operand" "n,n"))
4118          (const_int 0)))
4119    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4120         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4121   "includes_rshift_p (operands[2], operands[3])"
4122   "@
4123    {rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3
4124    #"
4125   [(set_attr "type" "delayed_compare")
4126    (set_attr "length" "4,8")])
4127
4128 (define_split
4129   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4130         (compare:CC
4131          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4132                               (match_operand:SI 2 "const_int_operand" ""))
4133                  (match_operand:SI 3 "mask_operand" ""))
4134          (const_int 0)))
4135    (set (match_operand:SI 0 "gpc_reg_operand" "")
4136         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4137   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4138   [(set (match_dup 0)
4139         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4140    (set (match_dup 4)
4141         (compare:CC (match_dup 0)
4142                     (const_int 0)))]
4143   "")
4144
4145 (define_insn ""
4146   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4147         (zero_extend:SI
4148          (subreg:QI
4149           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4150                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4151   "includes_rshift_p (operands[2], GEN_INT (255))"
4152   "{rlinm|rlwinm} %0,%1,%s2,0xff")
4153
4154 (define_insn ""
4155   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4156         (compare:CC
4157          (zero_extend:SI
4158           (subreg:QI
4159            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4160                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4161          (const_int 0)))
4162    (clobber (match_scratch:SI 3 "=r,r"))]
4163   "includes_rshift_p (operands[2], GEN_INT (255))"
4164   "@
4165    {rlinm.|rlwinm.} %3,%1,%s2,0xff
4166    #"
4167   [(set_attr "type" "delayed_compare")
4168    (set_attr "length" "4,8")])
4169
4170 (define_split
4171   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4172         (compare:CC
4173          (zero_extend:SI
4174           (subreg:QI
4175            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4176                         (match_operand:SI 2 "const_int_operand" "")) 0))
4177          (const_int 0)))
4178    (clobber (match_scratch:SI 3 ""))]
4179   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4180   [(set (match_dup 3)
4181         (zero_extend:SI (subreg:QI
4182            (lshiftrt:SI (match_dup 1)
4183                         (match_dup 2)) 0)))
4184    (set (match_dup 0)
4185         (compare:CC (match_dup 3)
4186                     (const_int 0)))]
4187   "")
4188
4189 (define_insn ""
4190   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4191         (compare:CC
4192          (zero_extend:SI
4193           (subreg:QI
4194            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4195                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4196          (const_int 0)))
4197    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4198         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4199   "includes_rshift_p (operands[2], GEN_INT (255))"
4200   "@
4201    {rlinm.|rlwinm.} %0,%1,%s2,0xff
4202    #"
4203   [(set_attr "type" "delayed_compare")
4204    (set_attr "length" "4,8")])
4205
4206 (define_split
4207   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4208         (compare:CC
4209          (zero_extend:SI
4210           (subreg:QI
4211            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4212                         (match_operand:SI 2 "const_int_operand" "")) 0))
4213          (const_int 0)))
4214    (set (match_operand:SI 0 "gpc_reg_operand" "")
4215         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4216   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4217   [(set (match_dup 0)
4218         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4219    (set (match_dup 3)
4220         (compare:CC (match_dup 0)
4221                     (const_int 0)))]
4222   "")
4223
4224 (define_insn ""
4225   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4226         (zero_extend:SI
4227          (subreg:HI
4228           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4229                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4230   "includes_rshift_p (operands[2], GEN_INT (65535))"
4231   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
4232
4233 (define_insn ""
4234   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4235         (compare:CC
4236          (zero_extend:SI
4237           (subreg:HI
4238            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4239                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4240          (const_int 0)))
4241    (clobber (match_scratch:SI 3 "=r,r"))]
4242   "includes_rshift_p (operands[2], GEN_INT (65535))"
4243   "@
4244    {rlinm.|rlwinm.} %3,%1,%s2,0xffff
4245    #"
4246   [(set_attr "type" "delayed_compare")
4247    (set_attr "length" "4,8")])
4248
4249 (define_split
4250   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4251         (compare:CC
4252          (zero_extend:SI
4253           (subreg:HI
4254            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4255                         (match_operand:SI 2 "const_int_operand" "")) 0))
4256          (const_int 0)))
4257    (clobber (match_scratch:SI 3 ""))]
4258   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4259   [(set (match_dup 3)
4260         (zero_extend:SI (subreg:HI
4261            (lshiftrt:SI (match_dup 1)
4262                         (match_dup 2)) 0)))
4263    (set (match_dup 0)
4264         (compare:CC (match_dup 3)
4265                     (const_int 0)))]
4266   "")
4267
4268 (define_insn ""
4269   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4270         (compare:CC
4271          (zero_extend:SI
4272           (subreg:HI
4273            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4274                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4275          (const_int 0)))
4276    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4277         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4278   "includes_rshift_p (operands[2], GEN_INT (65535))"
4279   "@
4280    {rlinm.|rlwinm.} %0,%1,%s2,0xffff
4281    #"
4282   [(set_attr "type" "delayed_compare")
4283    (set_attr "length" "4,8")])
4284
4285 (define_split
4286   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4287         (compare:CC
4288          (zero_extend:SI
4289           (subreg:HI
4290            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4291                         (match_operand:SI 2 "const_int_operand" "")) 0))
4292          (const_int 0)))
4293    (set (match_operand:SI 0 "gpc_reg_operand" "")
4294         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4295   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4296   [(set (match_dup 0)
4297         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4298    (set (match_dup 3)
4299         (compare:CC (match_dup 0)
4300                     (const_int 0)))]
4301   "")
4302
4303 (define_insn ""
4304   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4305                          (const_int 1)
4306                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4307         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4308                      (const_int 31)))]
4309   "TARGET_POWER"
4310   "rrib %0,%1,%2")
4311
4312 (define_insn ""
4313   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4314                          (const_int 1)
4315                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4316         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4317                      (const_int 31)))]
4318   "TARGET_POWER"
4319   "rrib %0,%1,%2")
4320
4321 (define_insn ""
4322   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4323                          (const_int 1)
4324                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4325         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4326                          (const_int 1)
4327                          (const_int 0)))]
4328   "TARGET_POWER"
4329   "rrib %0,%1,%2")
4330
4331 (define_expand "ashrsi3"
4332   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4333         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4334                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
4335   ""
4336   "
4337 {
4338   if (TARGET_POWER)
4339     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
4340   else
4341     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
4342   DONE;
4343 }")
4344
4345 (define_insn "ashrsi3_power"
4346   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4347         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4348                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4349    (clobber (match_scratch:SI 3 "=q,X"))]
4350   "TARGET_POWER"
4351   "@
4352    srea %0,%1,%2
4353    {srai|srawi} %0,%1,%h2")
4354
4355 (define_insn "ashrsi3_no_power"
4356   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4357         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4358                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4359   "! TARGET_POWER"
4360   "{sra|sraw}%I2 %0,%1,%h2")
4361
4362 (define_insn ""
4363   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4364         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4365                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4366                     (const_int 0)))
4367    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4368    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4369   "TARGET_POWER"
4370   "@
4371    srea. %3,%1,%2
4372    {srai.|srawi.} %3,%1,%h2
4373    #
4374    #"
4375   [(set_attr "type" "delayed_compare")
4376    (set_attr "length" "4,4,8,8")])
4377
4378 (define_split
4379   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4380         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4381                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4382                     (const_int 0)))
4383    (clobber (match_scratch:SI 3 ""))
4384    (clobber (match_scratch:SI 4 ""))]
4385   "TARGET_POWER && reload_completed"
4386   [(parallel [(set (match_dup 3)
4387         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4388    (clobber (match_dup 4))])
4389    (set (match_dup 0)
4390         (compare:CC (match_dup 3)
4391                     (const_int 0)))]
4392   "")
4393
4394 (define_insn ""
4395   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4396         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4397                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4398                     (const_int 0)))
4399    (clobber (match_scratch:SI 3 "=r,r"))]
4400   "! TARGET_POWER"
4401   "@
4402    {sra|sraw}%I2. %3,%1,%h2
4403    #"
4404   [(set_attr "type" "delayed_compare")
4405    (set_attr "length" "4,8")])
4406
4407 (define_split
4408   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4409         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4410                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4411                     (const_int 0)))
4412    (clobber (match_scratch:SI 3 ""))]
4413   "! TARGET_POWER && reload_completed"
4414   [(set (match_dup 3)
4415         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4416    (set (match_dup 0)
4417         (compare:CC (match_dup 3)
4418                     (const_int 0)))]
4419   "")
4420
4421 (define_insn ""
4422   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4423         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4424                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4425                     (const_int 0)))
4426    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4427         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4428    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4429   "TARGET_POWER"
4430   "@
4431    srea. %0,%1,%2
4432    {srai.|srawi.} %0,%1,%h2
4433    #
4434    #"
4435   [(set_attr "type" "delayed_compare")
4436    (set_attr "length" "4,4,8,8")])
4437
4438 (define_split
4439   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4440         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4441                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4442                     (const_int 0)))
4443    (set (match_operand:SI 0 "gpc_reg_operand" "")
4444         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4445    (clobber (match_scratch:SI 4 ""))]
4446   "TARGET_POWER && reload_completed"
4447   [(parallel [(set (match_dup 0)
4448         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4449    (clobber (match_dup 4))])
4450    (set (match_dup 3)
4451         (compare:CC (match_dup 0)
4452                     (const_int 0)))]
4453   "")
4454
4455 (define_insn ""
4456   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4457         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4458                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4459                     (const_int 0)))
4460    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4461         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4462   "! TARGET_POWER"
4463   "@
4464    {sra|sraw}%I2. %0,%1,%h2
4465    #"
4466   [(set_attr "type" "delayed_compare")
4467    (set_attr "length" "4,8")])
4468 \f
4469 (define_split
4470   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4471         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4472                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4473                     (const_int 0)))
4474    (set (match_operand:SI 0 "gpc_reg_operand" "")
4475         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4476   "! TARGET_POWER && reload_completed"
4477   [(set (match_dup 0)
4478         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4479    (set (match_dup 3)
4480         (compare:CC (match_dup 0)
4481                     (const_int 0)))]
4482   "")
4483
4484 ;; Floating-point insns, excluding normal data motion.
4485 ;;
4486 ;; PowerPC has a full set of single-precision floating point instructions.
4487 ;;
4488 ;; For the POWER architecture, we pretend that we have both SFmode and
4489 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
4490 ;; The only conversions we will do will be when storing to memory.  In that
4491 ;; case, we will use the "frsp" instruction before storing.
4492 ;;
4493 ;; Note that when we store into a single-precision memory location, we need to
4494 ;; use the frsp insn first.  If the register being stored isn't dead, we
4495 ;; need a scratch register for the frsp.  But this is difficult when the store
4496 ;; is done by reload.  It is not incorrect to do the frsp on the register in
4497 ;; this case, we just lose precision that we would have otherwise gotten but
4498 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
4499
4500 (define_expand "extendsfdf2"
4501   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4502         (float_extend:DF (match_operand:SF 1 "reg_or_none500mem_operand" "")))]
4503   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4504   "")
4505
4506 (define_insn_and_split "*extendsfdf2_fpr"
4507   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,?f,f")
4508         (float_extend:DF (match_operand:SF 1 "reg_or_mem_operand" "0,f,m")))]
4509   "TARGET_HARD_FLOAT && TARGET_FPRS"
4510   "@
4511    #
4512    fmr %0,%1
4513    lfs%U1%X1 %0,%1"
4514   "&& reload_completed && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])"
4515   [(const_int 0)]
4516 {
4517   emit_note (NOTE_INSN_DELETED);
4518   DONE;
4519 }
4520   [(set_attr "type" "fp,fp,fpload")])
4521
4522 (define_expand "truncdfsf2"
4523   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4524         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "")))]
4525   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4526   "")
4527
4528 (define_insn "*truncdfsf2_fpr"
4529   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4530         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4531   "TARGET_HARD_FLOAT && TARGET_FPRS"
4532   "frsp %0,%1"
4533   [(set_attr "type" "fp")])
4534
4535 (define_insn "aux_truncdfsf2"
4536   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4537         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRSP))]
4538   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4539   "frsp %0,%1"
4540   [(set_attr "type" "fp")])
4541
4542 (define_expand "negsf2"
4543   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4544         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4545   "TARGET_HARD_FLOAT"
4546   "")
4547
4548 (define_insn "*negsf2"
4549   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4550         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4551   "TARGET_HARD_FLOAT && TARGET_FPRS"
4552   "fneg %0,%1"
4553   [(set_attr "type" "fp")])
4554
4555 (define_expand "abssf2"
4556   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4557         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4558   "TARGET_HARD_FLOAT"
4559   "")
4560
4561 (define_insn "*abssf2"
4562   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4563         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4564   "TARGET_HARD_FLOAT && TARGET_FPRS"
4565   "fabs %0,%1"
4566   [(set_attr "type" "fp")])
4567
4568 (define_insn ""
4569   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4570         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
4571   "TARGET_HARD_FLOAT && TARGET_FPRS"
4572   "fnabs %0,%1"
4573   [(set_attr "type" "fp")])
4574
4575 (define_expand "addsf3"
4576   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4577         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4578                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4579   "TARGET_HARD_FLOAT"
4580   "")
4581
4582 (define_insn ""
4583   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4584         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4585                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4586   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4587   "fadds %0,%1,%2"
4588   [(set_attr "type" "fp")])
4589
4590 (define_insn ""
4591   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4592         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4593                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4594   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4595   "{fa|fadd} %0,%1,%2"
4596   [(set_attr "type" "fp")])
4597
4598 (define_expand "subsf3"
4599   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4600         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4601                   (match_operand:SF 2 "gpc_reg_operand" "")))]
4602   "TARGET_HARD_FLOAT"
4603   "")
4604
4605 (define_insn ""
4606   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4607         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4608                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
4609   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4610   "fsubs %0,%1,%2"
4611   [(set_attr "type" "fp")])
4612
4613 (define_insn ""
4614   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4615         (minus: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"
4618   "{fs|fsub} %0,%1,%2"
4619   [(set_attr "type" "fp")])
4620
4621 (define_expand "mulsf3"
4622   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4623         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
4624                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4625   "TARGET_HARD_FLOAT"
4626   "")
4627
4628 (define_insn ""
4629   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4630         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4631                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4632   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4633   "fmuls %0,%1,%2"
4634   [(set_attr "type" "fp")])
4635
4636 (define_insn ""
4637   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4638         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4639                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4640   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4641   "{fm|fmul} %0,%1,%2"
4642   [(set_attr "type" "dmul")])
4643
4644 (define_insn "fres"
4645   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4646         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
4647   "TARGET_PPC_GFXOPT && flag_finite_math_only"
4648   "fres %0,%1"
4649   [(set_attr "type" "fp")])
4650
4651 (define_expand "divsf3"
4652   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4653         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
4654                 (match_operand:SF 2 "gpc_reg_operand" "")))]
4655   "TARGET_HARD_FLOAT"
4656 {
4657   if (swdiv && !optimize_size && TARGET_PPC_GFXOPT
4658   && flag_finite_math_only && !flag_trapping_math)
4659     {
4660       rs6000_emit_swdivsf (operands[0], operands[1], operands[2]);
4661       DONE;
4662     }
4663 })
4664
4665 (define_insn ""
4666   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4667         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4668                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
4669   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4670   "fdivs %0,%1,%2"
4671   [(set_attr "type" "sdiv")])
4672
4673 (define_insn ""
4674   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4675         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4676                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
4677   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4678   "{fd|fdiv} %0,%1,%2"
4679   [(set_attr "type" "ddiv")])
4680
4681 (define_insn ""
4682   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4683         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4684                           (match_operand:SF 2 "gpc_reg_operand" "f"))
4685                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
4686   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4687   "fmadds %0,%1,%2,%3"
4688   [(set_attr "type" "fp")])
4689
4690 (define_insn ""
4691   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4692         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4693                           (match_operand:SF 2 "gpc_reg_operand" "f"))
4694                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
4695   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4696   "{fma|fmadd} %0,%1,%2,%3"
4697   [(set_attr "type" "dmul")])
4698
4699 (define_insn ""
4700   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4701         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4702                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4703                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
4704   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4705   "fmsubs %0,%1,%2,%3"
4706   [(set_attr "type" "fp")])
4707
4708 (define_insn ""
4709   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4710         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4711                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4712                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
4713   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4714   "{fms|fmsub} %0,%1,%2,%3"
4715   [(set_attr "type" "dmul")])
4716
4717 (define_insn ""
4718   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4719         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4720                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
4721                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4722   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4723    && HONOR_SIGNED_ZEROS (SFmode)"
4724   "fnmadds %0,%1,%2,%3"
4725   [(set_attr "type" "fp")])
4726
4727 (define_insn ""
4728   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4729         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
4730                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4731                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4732   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4733    && ! HONOR_SIGNED_ZEROS (SFmode)"
4734   "fnmadds %0,%1,%2,%3"
4735   [(set_attr "type" "fp")])
4736
4737 (define_insn ""
4738   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4739         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4740                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
4741                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4742   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4743   "{fnma|fnmadd} %0,%1,%2,%3"
4744   [(set_attr "type" "dmul")])
4745
4746 (define_insn ""
4747   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4748         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
4749                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4750                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4751   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4752    && ! HONOR_SIGNED_ZEROS (SFmode)"
4753   "{fnma|fnmadd} %0,%1,%2,%3"
4754   [(set_attr "type" "dmul")])
4755
4756 (define_insn ""
4757   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4758         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4759                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
4760                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4761   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4762    && HONOR_SIGNED_ZEROS (SFmode)"
4763   "fnmsubs %0,%1,%2,%3"
4764   [(set_attr "type" "fp")])
4765
4766 (define_insn ""
4767   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4768         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
4769                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4770                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
4771   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4772    && ! HONOR_SIGNED_ZEROS (SFmode)"
4773   "fnmsubs %0,%1,%2,%3"
4774   [(set_attr "type" "fp")])
4775
4776 (define_insn ""
4777   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4778         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4779                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
4780                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4781   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4782   "{fnms|fnmsub} %0,%1,%2,%3"
4783   [(set_attr "type" "dmul")])
4784
4785 (define_insn ""
4786   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4787         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
4788                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4789                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
4790   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4791    && ! HONOR_SIGNED_ZEROS (SFmode)"
4792   "{fnms|fnmsub} %0,%1,%2,%3"
4793   [(set_attr "type" "fp")])
4794
4795 (define_expand "sqrtsf2"
4796   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4797         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4798   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
4799   "")
4800
4801 (define_insn ""
4802   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4803         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4804   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4805   "fsqrts %0,%1"
4806   [(set_attr "type" "ssqrt")])
4807
4808 (define_insn ""
4809   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4810         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4811   "TARGET_POWER2 && TARGET_HARD_FLOAT && TARGET_FPRS"
4812   "fsqrt %0,%1"
4813   [(set_attr "type" "dsqrt")])
4814
4815 (define_expand "copysignsf3"
4816   [(set (match_dup 3)
4817         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))
4818    (set (match_dup 4)
4819         (neg:SF (abs:SF (match_dup 1))))
4820    (set (match_operand:SF 0 "gpc_reg_operand" "")
4821         (if_then_else:SF (ge (match_operand:SF 2 "gpc_reg_operand" "")
4822                              (match_dup 5))
4823                          (match_dup 3)
4824                          (match_dup 4)))]
4825   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS
4826    && !HONOR_NANS (SFmode) && !HONOR_SIGNED_ZEROS (SFmode)" 
4827   {
4828      operands[3] = gen_reg_rtx (SFmode);
4829      operands[4] = gen_reg_rtx (SFmode);
4830      operands[5] = CONST0_RTX (SFmode);
4831   })
4832
4833 (define_expand "copysigndf3"
4834   [(set (match_dup 3)
4835         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))
4836    (set (match_dup 4)
4837         (neg:DF (abs:DF (match_dup 1))))
4838    (set (match_operand:DF 0 "gpc_reg_operand" "")
4839         (if_then_else:DF (ge (match_operand:DF 2 "gpc_reg_operand" "")
4840                              (match_dup 5))
4841                          (match_dup 3)
4842                          (match_dup 4)))]
4843   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS
4844    && !HONOR_NANS (DFmode) && !HONOR_SIGNED_ZEROS (DFmode)"
4845   {
4846      operands[3] = gen_reg_rtx (DFmode);
4847      operands[4] = gen_reg_rtx (DFmode);
4848      operands[5] = CONST0_RTX (DFmode);
4849   })
4850
4851 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
4852 ;; fsel instruction and some auxiliary computations.  Then we just have a
4853 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
4854 ;; combine.
4855 (define_expand "smaxsf3"
4856   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4857         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
4858                              (match_operand:SF 2 "gpc_reg_operand" ""))
4859                          (match_dup 1)
4860                          (match_dup 2)))]
4861   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
4862   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
4863
4864 (define_expand "sminsf3"
4865   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4866         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
4867                              (match_operand:SF 2 "gpc_reg_operand" ""))
4868                          (match_dup 2)
4869                          (match_dup 1)))]
4870   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
4871   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
4872
4873 (define_split
4874   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4875         (match_operator:SF 3 "min_max_operator"
4876          [(match_operand:SF 1 "gpc_reg_operand" "")
4877           (match_operand:SF 2 "gpc_reg_operand" "")]))]
4878   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
4879   [(const_int 0)]
4880   "
4881 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
4882                       operands[1], operands[2]);
4883   DONE;
4884 }")
4885
4886 (define_expand "movsicc"
4887    [(set (match_operand:SI 0 "gpc_reg_operand" "")
4888          (if_then_else:SI (match_operand 1 "comparison_operator" "")
4889                           (match_operand:SI 2 "gpc_reg_operand" "")
4890                           (match_operand:SI 3 "gpc_reg_operand" "")))]
4891   "TARGET_ISEL"
4892   "
4893 {
4894   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4895     DONE;
4896   else
4897     FAIL;
4898 }")
4899
4900 ;; We use the BASE_REGS for the isel input operands because, if rA is
4901 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
4902 ;; because we may switch the operands and rB may end up being rA.
4903 ;;
4904 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
4905 ;; leave out the mode in operand 4 and use one pattern, but reload can
4906 ;; change the mode underneath our feet and then gets confused trying
4907 ;; to reload the value.
4908 (define_insn "isel_signed"
4909   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4910         (if_then_else:SI
4911          (match_operator 1 "comparison_operator"
4912                          [(match_operand:CC 4 "cc_reg_operand" "y")
4913                           (const_int 0)])
4914          (match_operand:SI 2 "gpc_reg_operand" "b")
4915          (match_operand:SI 3 "gpc_reg_operand" "b")))]
4916   "TARGET_ISEL"
4917   "*
4918 { return output_isel (operands); }"
4919   [(set_attr "length" "4")])
4920
4921 (define_insn "isel_unsigned"
4922   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4923         (if_then_else:SI
4924          (match_operator 1 "comparison_operator"
4925                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
4926                           (const_int 0)])
4927          (match_operand:SI 2 "gpc_reg_operand" "b")
4928          (match_operand:SI 3 "gpc_reg_operand" "b")))]
4929   "TARGET_ISEL"
4930   "*
4931 { return output_isel (operands); }"
4932   [(set_attr "length" "4")])
4933
4934 (define_expand "movsfcc"
4935    [(set (match_operand:SF 0 "gpc_reg_operand" "")
4936          (if_then_else:SF (match_operand 1 "comparison_operator" "")
4937                           (match_operand:SF 2 "gpc_reg_operand" "")
4938                           (match_operand:SF 3 "gpc_reg_operand" "")))]
4939   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4940   "
4941 {
4942   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4943     DONE;
4944   else
4945     FAIL;
4946 }")
4947
4948 (define_insn "*fselsfsf4"
4949   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4950         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
4951                              (match_operand:SF 4 "zero_fp_constant" "F"))
4952                          (match_operand:SF 2 "gpc_reg_operand" "f")
4953                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4954   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4955   "fsel %0,%1,%2,%3"
4956   [(set_attr "type" "fp")])
4957
4958 (define_insn "*fseldfsf4"
4959   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4960         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
4961                              (match_operand:DF 4 "zero_fp_constant" "F"))
4962                          (match_operand:SF 2 "gpc_reg_operand" "f")
4963                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4964   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4965   "fsel %0,%1,%2,%3"
4966   [(set_attr "type" "fp")])
4967
4968 (define_expand "negdf2"
4969   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4970         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
4971   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4972   "")
4973
4974 (define_insn "*negdf2_fpr"
4975   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4976         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4977   "TARGET_HARD_FLOAT && TARGET_FPRS"
4978   "fneg %0,%1"
4979   [(set_attr "type" "fp")])
4980
4981 (define_expand "absdf2"
4982   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4983         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
4984   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4985   "")
4986
4987 (define_insn "*absdf2_fpr"
4988   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4989         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4990   "TARGET_HARD_FLOAT && TARGET_FPRS"
4991   "fabs %0,%1"
4992   [(set_attr "type" "fp")])
4993
4994 (define_insn "*nabsdf2_fpr"
4995   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4996         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f"))))]
4997   "TARGET_HARD_FLOAT && TARGET_FPRS"
4998   "fnabs %0,%1"
4999   [(set_attr "type" "fp")])
5000
5001 (define_expand "adddf3"
5002   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5003         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "")
5004                  (match_operand:DF 2 "gpc_reg_operand" "")))]
5005   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5006   "")
5007
5008 (define_insn "*adddf3_fpr"
5009   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5010         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5011                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
5012   "TARGET_HARD_FLOAT && TARGET_FPRS"
5013   "{fa|fadd} %0,%1,%2"
5014   [(set_attr "type" "fp")])
5015
5016 (define_expand "subdf3"
5017   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5018         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "")
5019                   (match_operand:DF 2 "gpc_reg_operand" "")))]
5020   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5021   "")
5022
5023 (define_insn "*subdf3_fpr"
5024   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5025         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5026                   (match_operand:DF 2 "gpc_reg_operand" "f")))]
5027   "TARGET_HARD_FLOAT && TARGET_FPRS"
5028   "{fs|fsub} %0,%1,%2"
5029   [(set_attr "type" "fp")])
5030
5031 (define_expand "muldf3"
5032   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5033         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "")
5034                  (match_operand:DF 2 "gpc_reg_operand" "")))]
5035   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5036   "")
5037
5038 (define_insn "*muldf3_fpr"
5039   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5040         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5041                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
5042   "TARGET_HARD_FLOAT && TARGET_FPRS"
5043   "{fm|fmul} %0,%1,%2"
5044   [(set_attr "type" "dmul")])
5045
5046 (define_insn "fred"
5047   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5048         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
5049   "TARGET_POPCNTB && flag_finite_math_only"
5050   "fre %0,%1"
5051   [(set_attr "type" "fp")])
5052
5053 (define_expand "divdf3"
5054   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5055         (div:DF (match_operand:DF 1 "gpc_reg_operand" "")
5056                 (match_operand:DF 2 "gpc_reg_operand" "")))]
5057   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5058 {
5059   if (swdiv && !optimize_size && TARGET_POPCNTB
5060   && flag_finite_math_only && !flag_trapping_math)
5061     {
5062       rs6000_emit_swdivdf (operands[0], operands[1], operands[2]);
5063       DONE;
5064     }
5065 })
5066
5067 (define_insn "*divdf3_fpr"
5068   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5069         (div:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5070                 (match_operand:DF 2 "gpc_reg_operand" "f")))]
5071   "TARGET_HARD_FLOAT && TARGET_FPRS"
5072   "{fd|fdiv} %0,%1,%2"
5073   [(set_attr "type" "ddiv")])
5074
5075 (define_insn ""
5076   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5077         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5078                           (match_operand:DF 2 "gpc_reg_operand" "f"))
5079                  (match_operand:DF 3 "gpc_reg_operand" "f")))]
5080   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5081   "{fma|fmadd} %0,%1,%2,%3"
5082   [(set_attr "type" "dmul")])
5083
5084 (define_insn ""
5085   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5086         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5087                            (match_operand:DF 2 "gpc_reg_operand" "f"))
5088                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
5089   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5090   "{fms|fmsub} %0,%1,%2,%3"
5091   [(set_attr "type" "dmul")])
5092
5093 (define_insn ""
5094   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5095         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5096                                   (match_operand:DF 2 "gpc_reg_operand" "f"))
5097                          (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5098   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5099    && HONOR_SIGNED_ZEROS (DFmode)"
5100   "{fnma|fnmadd} %0,%1,%2,%3"
5101   [(set_attr "type" "dmul")])
5102
5103 (define_insn ""
5104   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5105         (minus:DF (mult:DF (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f"))
5106                            (match_operand:DF 2 "gpc_reg_operand" "f"))
5107                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
5108   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5109    && ! HONOR_SIGNED_ZEROS (DFmode)"
5110   "{fnma|fnmadd} %0,%1,%2,%3"
5111   [(set_attr "type" "dmul")])
5112
5113 (define_insn ""
5114   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5115         (neg:DF (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5116                                    (match_operand:DF 2 "gpc_reg_operand" "f"))
5117                           (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5118   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5119    && HONOR_SIGNED_ZEROS (DFmode)"
5120   "{fnms|fnmsub} %0,%1,%2,%3"
5121   [(set_attr "type" "dmul")])
5122
5123 (define_insn ""
5124   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5125         (minus:DF (match_operand:DF 3 "gpc_reg_operand" "f")
5126                   (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5127                            (match_operand:DF 2 "gpc_reg_operand" "f"))))]
5128   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5129    && ! HONOR_SIGNED_ZEROS (DFmode)"
5130   "{fnms|fnmsub} %0,%1,%2,%3"
5131   [(set_attr "type" "dmul")])
5132
5133 (define_insn "sqrtdf2"
5134   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5135         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5136   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
5137   "fsqrt %0,%1"
5138   [(set_attr "type" "dsqrt")])
5139
5140 ;; The conditional move instructions allow us to perform max and min
5141 ;; operations even when
5142
5143 (define_expand "smaxdf3"
5144   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5145         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5146                              (match_operand:DF 2 "gpc_reg_operand" ""))
5147                          (match_dup 1)
5148                          (match_dup 2)))]
5149   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5150   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
5151
5152 (define_expand "smindf3"
5153   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5154         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5155                              (match_operand:DF 2 "gpc_reg_operand" ""))
5156                          (match_dup 2)
5157                          (match_dup 1)))]
5158   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5159   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
5160
5161 (define_split
5162   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5163         (match_operator:DF 3 "min_max_operator"
5164          [(match_operand:DF 1 "gpc_reg_operand" "")
5165           (match_operand:DF 2 "gpc_reg_operand" "")]))]
5166   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5167   [(const_int 0)]
5168   "
5169 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5170                       operands[1], operands[2]);
5171   DONE;
5172 }")
5173
5174 (define_expand "movdfcc"
5175    [(set (match_operand:DF 0 "gpc_reg_operand" "")
5176          (if_then_else:DF (match_operand 1 "comparison_operator" "")
5177                           (match_operand:DF 2 "gpc_reg_operand" "")
5178                           (match_operand:DF 3 "gpc_reg_operand" "")))]
5179   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5180   "
5181 {
5182   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5183     DONE;
5184   else
5185     FAIL;
5186 }")
5187
5188 (define_insn "*fseldfdf4"
5189   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5190         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
5191                              (match_operand:DF 4 "zero_fp_constant" "F"))
5192                          (match_operand:DF 2 "gpc_reg_operand" "f")
5193                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
5194   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5195   "fsel %0,%1,%2,%3"
5196   [(set_attr "type" "fp")])
5197
5198 (define_insn "*fselsfdf4"
5199   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5200         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5201                              (match_operand:SF 4 "zero_fp_constant" "F"))
5202                          (match_operand:DF 2 "gpc_reg_operand" "f")
5203                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
5204   "TARGET_PPC_GFXOPT"
5205   "fsel %0,%1,%2,%3"
5206   [(set_attr "type" "fp")])
5207 \f
5208 ;; Conversions to and from floating-point.
5209
5210 (define_expand "fixuns_truncsfsi2"
5211   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5212         (unsigned_fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
5213   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5214   "")
5215
5216 (define_expand "fix_truncsfsi2"
5217   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5218         (fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
5219   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5220   "")
5221
5222 ; For each of these conversions, there is a define_expand, a define_insn
5223 ; with a '#' template, and a define_split (with C code).  The idea is
5224 ; to allow constant folding with the template of the define_insn,
5225 ; then to have the insns split later (between sched1 and final).
5226
5227 (define_expand "floatsidf2"
5228   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5229                    (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5230               (use (match_dup 2))
5231               (use (match_dup 3))
5232               (clobber (match_dup 4))
5233               (clobber (match_dup 5))
5234               (clobber (match_dup 6))])]
5235   "TARGET_HARD_FLOAT && TARGET_FPRS"
5236   "
5237 {
5238   if (TARGET_E500_DOUBLE)
5239     {
5240       emit_insn (gen_spe_floatsidf2 (operands[0], operands[1]));
5241       DONE;
5242     }
5243   if (TARGET_POWERPC64)
5244     {
5245       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5246       rtx t1 = gen_reg_rtx (DImode);
5247       rtx t2 = gen_reg_rtx (DImode);
5248       emit_insn (gen_floatsidf_ppc64 (operands[0], operands[1], mem, t1, t2));
5249       DONE;
5250     }
5251
5252   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5253   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
5254   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5255   operands[5] = gen_reg_rtx (DFmode);
5256   operands[6] = gen_reg_rtx (SImode);
5257 }")
5258
5259 (define_insn_and_split "*floatsidf2_internal"
5260   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5261         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5262    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5263    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5264    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5265    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))
5266    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
5267   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5268   "#"
5269   "&& (!no_new_pseudos || offsettable_nonstrict_memref_p (operands[4]))"
5270   [(pc)]
5271   "
5272 {
5273   rtx lowword, highword;
5274   gcc_assert (MEM_P (operands[4]));
5275   highword = adjust_address (operands[4], SImode, 0);
5276   lowword = adjust_address (operands[4], SImode, 4);
5277   if (! WORDS_BIG_ENDIAN)
5278     {
5279       rtx tmp;
5280       tmp = highword; highword = lowword; lowword = tmp;
5281     }
5282
5283   emit_insn (gen_xorsi3 (operands[6], operands[1],
5284                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
5285   emit_move_insn (lowword, operands[6]);
5286   emit_move_insn (highword, operands[2]);
5287   emit_move_insn (operands[5], operands[4]);
5288   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5289   DONE;
5290 }"
5291   [(set_attr "length" "24")])
5292
5293 (define_expand "floatunssisf2"
5294   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5295         (unsigned_float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5296   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5297   "")
5298
5299 (define_expand "floatunssidf2"
5300   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5301                    (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5302               (use (match_dup 2))
5303               (use (match_dup 3))
5304               (clobber (match_dup 4))
5305               (clobber (match_dup 5))])]
5306   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5307   "
5308 {
5309   if (TARGET_E500_DOUBLE)
5310     {
5311       emit_insn (gen_spe_floatunssidf2 (operands[0], operands[1]));
5312       DONE;
5313     }
5314   if (TARGET_POWERPC64)
5315     {
5316       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5317       rtx t1 = gen_reg_rtx (DImode);
5318       rtx t2 = gen_reg_rtx (DImode);
5319       emit_insn (gen_floatunssidf_ppc64 (operands[0], operands[1], mem,
5320                                          t1, t2));
5321       DONE;
5322     }
5323
5324   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5325   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
5326   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5327   operands[5] = gen_reg_rtx (DFmode);
5328 }")
5329
5330 (define_insn_and_split "*floatunssidf2_internal"
5331   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5332         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5333    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5334    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5335    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5336    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))]
5337   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5338   "#"
5339   "&& (!no_new_pseudos || offsettable_nonstrict_memref_p (operands[4]))"
5340   [(pc)]
5341   "
5342 {
5343   rtx lowword, highword;
5344   gcc_assert (MEM_P (operands[4]));
5345   highword = adjust_address (operands[4], SImode, 0);
5346   lowword = adjust_address (operands[4], SImode, 4);
5347   if (! WORDS_BIG_ENDIAN)
5348     {
5349       rtx tmp;
5350       tmp = highword; highword = lowword; lowword = tmp;
5351     }
5352
5353   emit_move_insn (lowword, operands[1]);
5354   emit_move_insn (highword, operands[2]);
5355   emit_move_insn (operands[5], operands[4]);
5356   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5357   DONE;
5358 }"
5359   [(set_attr "length" "20")])
5360
5361 (define_expand "fix_truncdfsi2"
5362   [(parallel [(set (match_operand:SI 0 "fix_trunc_dest_operand" "")
5363                    (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5364               (clobber (match_dup 2))
5365               (clobber (match_dup 3))])]
5366   "(TARGET_POWER2 || TARGET_POWERPC)
5367    && TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5368   "
5369 {
5370   if (TARGET_E500_DOUBLE)
5371     {
5372      emit_insn (gen_spe_fix_truncdfsi2 (operands[0], operands[1]));
5373      DONE;
5374     }
5375   operands[2] = gen_reg_rtx (DImode);
5376   if (TARGET_PPC_GFXOPT)
5377     {
5378       rtx orig_dest = operands[0];
5379       if (! memory_operand (orig_dest, GET_MODE (orig_dest)))
5380         operands[0] = assign_stack_temp (SImode, GET_MODE_SIZE (SImode), 0);
5381       emit_insn (gen_fix_truncdfsi2_internal_gfxopt (operands[0], operands[1],
5382                                                      operands[2]));
5383       if (operands[0] != orig_dest)
5384         emit_move_insn (orig_dest, operands[0]);
5385       DONE;
5386     }
5387   operands[3] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5388 }")
5389
5390 (define_insn_and_split "*fix_truncdfsi2_internal"
5391   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5392         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5393    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))
5394    (clobber (match_operand:DI 3 "memory_operand" "=o"))]
5395   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5396   "#"
5397   "&& (!no_new_pseudos || offsettable_nonstrict_memref_p (operands[3]))"
5398   [(pc)]
5399   "
5400 {
5401   rtx lowword;
5402   gcc_assert (MEM_P (operands[3]));
5403   lowword = adjust_address (operands[3], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
5404
5405   emit_insn (gen_fctiwz (operands[2], operands[1]));
5406   emit_move_insn (operands[3], operands[2]);
5407   emit_move_insn (operands[0], lowword);
5408   DONE;
5409 }"
5410   [(set_attr "length" "16")])
5411
5412 (define_insn_and_split "fix_truncdfsi2_internal_gfxopt"
5413   [(set (match_operand:SI 0 "memory_operand" "=Z")
5414         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5415    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))]
5416   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS
5417    && TARGET_PPC_GFXOPT"
5418   "#"
5419   "&& 1"
5420   [(pc)]
5421   "
5422 {
5423   emit_insn (gen_fctiwz (operands[2], operands[1]));
5424   emit_insn (gen_stfiwx (operands[0], operands[2]));
5425   DONE;
5426 }"
5427   [(set_attr "length" "16")])
5428
5429 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
5430 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
5431 ; because the first makes it clear that operand 0 is not live
5432 ; before the instruction.
5433 (define_insn "fctiwz"
5434   [(set (match_operand:DI 0 "gpc_reg_operand" "=f")
5435         (unspec:DI [(fix:SI (match_operand:DF 1 "gpc_reg_operand" "f"))]
5436                    UNSPEC_FCTIWZ))]
5437   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5438   "{fcirz|fctiwz} %0,%1"
5439   [(set_attr "type" "fp")])
5440
5441 ; An UNSPEC is used so we don't have to support SImode in FP registers.
5442 (define_insn "stfiwx"
5443   [(set (match_operand:SI 0 "memory_operand" "=Z")
5444         (unspec:SI [(match_operand:DI 1 "gpc_reg_operand" "f")]
5445                    UNSPEC_STFIWX))]
5446   "TARGET_PPC_GFXOPT"
5447   "stfiwx %1,%y0"
5448   [(set_attr "type" "fpstore")])
5449
5450 (define_expand "floatsisf2"
5451   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5452         (float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5453   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5454   "")
5455
5456 (define_insn "floatdidf2"
5457   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5458         (float:DF (match_operand:DI 1 "gpc_reg_operand" "*f")))]
5459   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5460   "fcfid %0,%1"
5461   [(set_attr "type" "fp")])
5462
5463 (define_insn_and_split "floatsidf_ppc64"
5464   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5465         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5466    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5467    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5468    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5469   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5470   "#"
5471   "&& 1"
5472   [(set (match_dup 3) (sign_extend:DI (match_dup 1)))
5473    (set (match_dup 2) (match_dup 3))
5474    (set (match_dup 4) (match_dup 2))
5475    (set (match_dup 0) (float:DF (match_dup 4)))]
5476   "")
5477
5478 (define_insn_and_split "floatunssidf_ppc64"
5479   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5480         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5481    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5482    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5483    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5484   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5485   "#"
5486   "&& 1"
5487   [(set (match_dup 3) (zero_extend:DI (match_dup 1)))
5488    (set (match_dup 2) (match_dup 3))
5489    (set (match_dup 4) (match_dup 2))
5490    (set (match_dup 0) (float:DF (match_dup 4)))]
5491   "")
5492
5493 (define_insn "fix_truncdfdi2"
5494   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
5495         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "f")))]
5496   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5497   "fctidz %0,%1"
5498   [(set_attr "type" "fp")])
5499
5500 (define_expand "floatdisf2"
5501   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5502         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
5503   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5504   "
5505 {
5506   rtx val = operands[1];
5507   if (!flag_unsafe_math_optimizations)
5508     {
5509       rtx label = gen_label_rtx ();
5510       val = gen_reg_rtx (DImode);
5511       emit_insn (gen_floatdisf2_internal2 (val, operands[1], label));
5512       emit_label (label);
5513     }
5514   emit_insn (gen_floatdisf2_internal1 (operands[0], val));
5515   DONE;
5516 }")
5517
5518 ;; This is not IEEE compliant if rounding mode is "round to nearest".
5519 ;; If the DI->DF conversion is inexact, then it's possible to suffer
5520 ;; from double rounding.
5521 (define_insn_and_split "floatdisf2_internal1"
5522   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5523         (float:SF (match_operand:DI 1 "gpc_reg_operand" "*f")))
5524    (clobber (match_scratch:DF 2 "=f"))]
5525   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5526   "#"
5527   "&& reload_completed"
5528   [(set (match_dup 2)
5529         (float:DF (match_dup 1)))
5530    (set (match_dup 0)
5531         (float_truncate:SF (match_dup 2)))]
5532   "")
5533
5534 ;; Twiddles bits to avoid double rounding.
5535 ;; Bits that might be truncated when converting to DFmode are replaced
5536 ;; by a bit that won't be lost at that stage, but is below the SFmode
5537 ;; rounding position.
5538 (define_expand "floatdisf2_internal2"
5539   [(set (match_dup 3) (ashiftrt:DI (match_operand:DI 1 "" "")
5540                                    (const_int 53)))
5541    (parallel [(set (match_operand:DI 0 "" "") (and:DI (match_dup 1)
5542                                                       (const_int 2047)))
5543               (clobber (scratch:CC))])
5544    (set (match_dup 3) (plus:DI (match_dup 3)
5545                                (const_int 1)))
5546    (set (match_dup 0) (plus:DI (match_dup 0)
5547                                (const_int 2047)))
5548    (set (match_dup 4) (compare:CCUNS (match_dup 3)
5549                                      (const_int 3)))
5550    (set (match_dup 0) (ior:DI (match_dup 0)
5551                               (match_dup 1)))
5552    (parallel [(set (match_dup 0) (and:DI (match_dup 0)
5553                                          (const_int -2048)))
5554               (clobber (scratch:CC))])
5555    (set (pc) (if_then_else (geu (match_dup 4) (const_int 0))
5556                            (label_ref (match_operand:DI 2 "" ""))
5557                            (pc)))
5558    (set (match_dup 0) (match_dup 1))]
5559   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5560   "
5561 {
5562   operands[3] = gen_reg_rtx (DImode);
5563   operands[4] = gen_reg_rtx (CCUNSmode);
5564 }")
5565 \f
5566 ;; Define the DImode operations that can be done in a small number
5567 ;; of instructions.  The & constraints are to prevent the register
5568 ;; allocator from allocating registers that overlap with the inputs
5569 ;; (for example, having an input in 7,8 and an output in 6,7).  We
5570 ;; also allow for the output being the same as one of the inputs.
5571
5572 (define_insn "*adddi3_noppc64"
5573   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
5574         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
5575                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
5576   "! TARGET_POWERPC64"
5577   "*
5578 {
5579   if (WORDS_BIG_ENDIAN)
5580     return (GET_CODE (operands[2])) != CONST_INT
5581             ? \"{a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2\"
5582             : \"{ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1\";
5583   else
5584     return (GET_CODE (operands[2])) != CONST_INT
5585             ? \"{a|addc} %0,%1,%2\;{ae|adde} %L0,%L1,%L2\"
5586             : \"{ai|addic} %0,%1,%2\;{a%G2e|add%G2e} %L0,%L1\";
5587 }"
5588   [(set_attr "type" "two")
5589    (set_attr "length" "8")])
5590
5591 (define_insn "*subdi3_noppc64"
5592   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
5593         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
5594                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
5595   "! TARGET_POWERPC64"
5596   "*
5597 {
5598   if (WORDS_BIG_ENDIAN)
5599     return (GET_CODE (operands[1]) != CONST_INT)
5600             ? \"{sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1\"
5601             : \"{sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2\";
5602   else
5603     return (GET_CODE (operands[1]) != CONST_INT)
5604             ? \"{sf|subfc} %0,%2,%1\;{sfe|subfe} %L0,%L2,%L1\"
5605             : \"{sfi|subfic} %0,%2,%1\;{sf%G1e|subf%G1e} %L0,%L2\";
5606 }"
5607   [(set_attr "type" "two")
5608    (set_attr "length" "8")])
5609
5610 (define_insn "*negdi2_noppc64"
5611   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5612         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
5613   "! TARGET_POWERPC64"
5614   "*
5615 {
5616   return (WORDS_BIG_ENDIAN)
5617     ? \"{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1\"
5618     : \"{sfi|subfic} %0,%1,0\;{sfze|subfze} %L0,%L1\";
5619 }"
5620   [(set_attr "type" "two")
5621    (set_attr "length" "8")])
5622
5623 (define_expand "mulsidi3"
5624   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5625         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5626                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5627   "! TARGET_POWERPC64"
5628   "
5629 {
5630   if (! TARGET_POWER && ! TARGET_POWERPC)
5631     {
5632       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
5633       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
5634       emit_insn (gen_mull_call ());
5635       if (WORDS_BIG_ENDIAN)
5636         emit_move_insn (operands[0], gen_rtx_REG (DImode, 3));
5637       else
5638         {
5639           emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
5640                           gen_rtx_REG (SImode, 3));
5641           emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
5642                           gen_rtx_REG (SImode, 4));
5643         }
5644       DONE;
5645     }
5646   else if (TARGET_POWER)
5647     {
5648       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
5649       DONE;
5650     }
5651 }")
5652
5653 (define_insn "mulsidi3_mq"
5654   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5655         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5656                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
5657    (clobber (match_scratch:SI 3 "=q"))]
5658   "TARGET_POWER"
5659   "mul %0,%1,%2\;mfmq %L0"
5660   [(set_attr "type" "imul")
5661    (set_attr "length" "8")])
5662
5663 (define_insn "*mulsidi3_no_mq"
5664   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5665         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5666                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
5667   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
5668   "*
5669 {
5670   return (WORDS_BIG_ENDIAN)
5671     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
5672     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
5673 }"
5674   [(set_attr "type" "imul")
5675    (set_attr "length" "8")])
5676
5677 (define_split
5678   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5679         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5680                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5681   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
5682   [(set (match_dup 3)
5683         (truncate:SI
5684          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
5685                                (sign_extend:DI (match_dup 2)))
5686                       (const_int 32))))
5687    (set (match_dup 4)
5688         (mult:SI (match_dup 1)
5689                  (match_dup 2)))]
5690   "
5691 {
5692   int endian = (WORDS_BIG_ENDIAN == 0);
5693   operands[3] = operand_subword (operands[0], endian, 0, DImode);
5694   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
5695 }")
5696
5697 (define_expand "umulsidi3"
5698   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5699         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5700                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5701   "TARGET_POWERPC && ! TARGET_POWERPC64"
5702   "
5703 {
5704   if (TARGET_POWER)
5705     {
5706       emit_insn (gen_umulsidi3_mq (operands[0], operands[1], operands[2]));
5707       DONE;
5708     }
5709 }")
5710
5711 (define_insn "umulsidi3_mq"
5712   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5713         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5714                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
5715    (clobber (match_scratch:SI 3 "=q"))]
5716   "TARGET_POWERPC && TARGET_POWER"
5717   "*
5718 {
5719   return (WORDS_BIG_ENDIAN)
5720     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
5721     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
5722 }"
5723   [(set_attr "type" "imul")
5724    (set_attr "length" "8")])
5725
5726 (define_insn "*umulsidi3_no_mq"
5727   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5728         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5729                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
5730   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
5731   "*
5732 {
5733   return (WORDS_BIG_ENDIAN)
5734     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
5735     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
5736 }"
5737   [(set_attr "type" "imul")
5738    (set_attr "length" "8")])
5739
5740 (define_split
5741   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5742         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5743                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5744   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
5745   [(set (match_dup 3)
5746         (truncate:SI
5747          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
5748                                (zero_extend:DI (match_dup 2)))
5749                       (const_int 32))))
5750    (set (match_dup 4)
5751         (mult:SI (match_dup 1)
5752                  (match_dup 2)))]
5753   "
5754 {
5755   int endian = (WORDS_BIG_ENDIAN == 0);
5756   operands[3] = operand_subword (operands[0], endian, 0, DImode);
5757   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
5758 }")
5759
5760 (define_expand "smulsi3_highpart"
5761   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5762         (truncate:SI
5763          (lshiftrt:DI (mult:DI (sign_extend:DI
5764                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5765                                (sign_extend:DI
5766                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5767                       (const_int 32))))]
5768   ""
5769   "
5770 {
5771   if (! TARGET_POWER && ! TARGET_POWERPC)
5772     {
5773       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
5774       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
5775       emit_insn (gen_mulh_call ());
5776       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
5777       DONE;
5778     }
5779   else if (TARGET_POWER)
5780     {
5781       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
5782       DONE;
5783     }
5784 }")
5785
5786 (define_insn "smulsi3_highpart_mq"
5787   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5788         (truncate:SI
5789          (lshiftrt:DI (mult:DI (sign_extend:DI
5790                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5791                                (sign_extend:DI
5792                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5793                       (const_int 32))))
5794    (clobber (match_scratch:SI 3 "=q"))]
5795   "TARGET_POWER"
5796   "mul %0,%1,%2"
5797   [(set_attr "type" "imul")])
5798
5799 (define_insn "*smulsi3_highpart_no_mq"
5800   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5801         (truncate:SI
5802          (lshiftrt:DI (mult:DI (sign_extend:DI
5803                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5804                                (sign_extend:DI
5805                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5806                       (const_int 32))))]
5807   "TARGET_POWERPC && ! TARGET_POWER"
5808   "mulhw %0,%1,%2"
5809   [(set_attr "type" "imul")])
5810
5811 (define_expand "umulsi3_highpart"
5812   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5813         (truncate:SI
5814          (lshiftrt:DI (mult:DI (zero_extend:DI
5815                                 (match_operand:SI 1 "gpc_reg_operand" ""))
5816                                (zero_extend:DI
5817                                 (match_operand:SI 2 "gpc_reg_operand" "")))
5818                       (const_int 32))))]
5819   "TARGET_POWERPC"
5820   "
5821 {
5822   if (TARGET_POWER)
5823     {
5824       emit_insn (gen_umulsi3_highpart_mq (operands[0], operands[1], operands[2]));
5825       DONE;
5826     }
5827 }")
5828
5829 (define_insn "umulsi3_highpart_mq"
5830   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5831         (truncate:SI
5832          (lshiftrt:DI (mult:DI (zero_extend:DI
5833                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5834                                (zero_extend:DI
5835                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5836                       (const_int 32))))
5837    (clobber (match_scratch:SI 3 "=q"))]
5838   "TARGET_POWERPC && TARGET_POWER"
5839   "mulhwu %0,%1,%2"
5840   [(set_attr "type" "imul")])
5841
5842 (define_insn "*umulsi3_highpart_no_mq"
5843   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5844         (truncate:SI
5845          (lshiftrt:DI (mult:DI (zero_extend:DI
5846                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5847                                (zero_extend:DI
5848                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5849                       (const_int 32))))]
5850   "TARGET_POWERPC && ! TARGET_POWER"
5851   "mulhwu %0,%1,%2"
5852   [(set_attr "type" "imul")])
5853
5854 ;; If operands 0 and 2 are in the same register, we have a problem.  But
5855 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
5856 ;; why we have the strange constraints below.
5857 (define_insn "ashldi3_power"
5858   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
5859         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
5860                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
5861    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
5862   "TARGET_POWER"
5863   "@
5864    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
5865    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
5866    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
5867    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
5868   [(set_attr "length" "8")])
5869
5870 (define_insn "lshrdi3_power"
5871   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
5872         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
5873                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
5874    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
5875   "TARGET_POWER"
5876   "@
5877    {s%A2i|s%A2wi} %L0,%1,%h2\;{cal %0,0(0)|li %0,0}
5878    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
5879    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
5880    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
5881   [(set_attr "length" "8")])
5882
5883 ;; Shift by a variable amount is too complex to be worth open-coding.  We
5884 ;; just handle shifts by constants.
5885 (define_insn "ashrdi3_power"
5886   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5887         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5888                      (match_operand:SI 2 "const_int_operand" "M,i")))
5889    (clobber (match_scratch:SI 3 "=X,q"))]
5890   "TARGET_POWER"
5891   "@
5892    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
5893    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
5894   [(set_attr "length" "8")])
5895
5896 (define_insn "ashrdi3_no_power"
5897   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
5898         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5899                      (match_operand:SI 2 "const_int_operand" "M,i")))]
5900   "TARGET_32BIT && !TARGET_POWERPC64 && !TARGET_POWER && WORDS_BIG_ENDIAN"
5901   "@
5902    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
5903    {sri|srwi} %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;{srai|srawi} %0,%1,%h2"
5904   [(set_attr "type" "two,three")
5905    (set_attr "length" "8,12")])
5906
5907 (define_insn "*ashrdisi3_noppc64"
5908   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5909         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
5910                                 (const_int 32)) 4))]
5911   "TARGET_32BIT && !TARGET_POWERPC64"
5912   "*
5913 {
5914   if (REGNO (operands[0]) == REGNO (operands[1]))
5915     return \"\";
5916   else
5917     return \"mr %0,%1\";
5918 }"
5919    [(set_attr "length" "4")])
5920
5921 \f
5922 ;; PowerPC64 DImode operations.
5923
5924 (define_insn_and_split "absdi2"
5925   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5926         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
5927    (clobber (match_scratch:DI 2 "=&r,&r"))]
5928   "TARGET_POWERPC64"
5929   "#"
5930   "&& reload_completed"
5931   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
5932    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
5933    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
5934   "")
5935
5936 (define_insn_and_split "*nabsdi2"
5937   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5938         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
5939    (clobber (match_scratch:DI 2 "=&r,&r"))]
5940   "TARGET_POWERPC64"
5941   "#"
5942   "&& reload_completed"
5943   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
5944    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
5945    (set (match_dup 0) (minus:DI (match_dup 2) (match_dup 0)))]
5946   "")
5947
5948 (define_insn "muldi3"
5949   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5950         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
5951                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
5952   "TARGET_POWERPC64"
5953   "mulld %0,%1,%2"
5954    [(set_attr "type" "lmul")])
5955
5956 (define_insn "*muldi3_internal1"
5957   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5958         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
5959                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
5960                     (const_int 0)))
5961    (clobber (match_scratch:DI 3 "=r,r"))]
5962   "TARGET_POWERPC64"
5963   "@
5964    mulld. %3,%1,%2
5965    #"
5966   [(set_attr "type" "lmul_compare")
5967    (set_attr "length" "4,8")])
5968
5969 (define_split
5970   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5971         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
5972                              (match_operand:DI 2 "gpc_reg_operand" ""))
5973                     (const_int 0)))
5974    (clobber (match_scratch:DI 3 ""))]
5975   "TARGET_POWERPC64 && reload_completed"
5976   [(set (match_dup 3)
5977         (mult:DI (match_dup 1) (match_dup 2)))
5978    (set (match_dup 0)
5979         (compare:CC (match_dup 3)
5980                     (const_int 0)))]
5981   "")
5982
5983 (define_insn "*muldi3_internal2"
5984   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
5985         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
5986                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
5987                     (const_int 0)))
5988    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5989         (mult:DI (match_dup 1) (match_dup 2)))]
5990   "TARGET_POWERPC64"
5991   "@
5992    mulld. %0,%1,%2
5993    #"
5994   [(set_attr "type" "lmul_compare")
5995    (set_attr "length" "4,8")])
5996
5997 (define_split
5998   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5999         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6000                              (match_operand:DI 2 "gpc_reg_operand" ""))
6001                     (const_int 0)))
6002    (set (match_operand:DI 0 "gpc_reg_operand" "")
6003         (mult:DI (match_dup 1) (match_dup 2)))]
6004   "TARGET_POWERPC64 && reload_completed"
6005   [(set (match_dup 0)
6006         (mult:DI (match_dup 1) (match_dup 2)))
6007    (set (match_dup 3)
6008         (compare:CC (match_dup 0)
6009                     (const_int 0)))]
6010   "")
6011
6012 (define_insn "smuldi3_highpart"
6013   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6014         (truncate:DI
6015          (lshiftrt:TI (mult:TI (sign_extend:TI
6016                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6017                                (sign_extend:TI
6018                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6019                       (const_int 64))))]
6020   "TARGET_POWERPC64"
6021   "mulhd %0,%1,%2"
6022   [(set_attr "type" "lmul")])
6023
6024 (define_insn "umuldi3_highpart"
6025   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6026         (truncate:DI
6027          (lshiftrt:TI (mult:TI (zero_extend:TI
6028                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6029                                (zero_extend:TI
6030                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6031                       (const_int 64))))]
6032   "TARGET_POWERPC64"
6033   "mulhdu %0,%1,%2"
6034   [(set_attr "type" "lmul")])
6035
6036 (define_expand "divdi3"
6037   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6038         (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6039                 (match_operand:DI 2 "reg_or_cint_operand" "")))]
6040   "TARGET_POWERPC64"
6041   "
6042 {
6043   if (GET_CODE (operands[2]) == CONST_INT
6044       && INTVAL (operands[2]) > 0
6045       && exact_log2 (INTVAL (operands[2])) >= 0)
6046     ;
6047   else
6048     operands[2] = force_reg (DImode, operands[2]);
6049 }")
6050
6051 (define_expand "moddi3"
6052   [(use (match_operand:DI 0 "gpc_reg_operand" ""))
6053    (use (match_operand:DI 1 "gpc_reg_operand" ""))
6054    (use (match_operand:DI 2 "reg_or_cint_operand" ""))]
6055   "TARGET_POWERPC64"
6056   "
6057 {
6058   int i;
6059   rtx temp1;
6060   rtx temp2;
6061
6062   if (GET_CODE (operands[2]) != CONST_INT
6063       || INTVAL (operands[2]) <= 0
6064       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
6065     FAIL;
6066
6067   temp1 = gen_reg_rtx (DImode);
6068   temp2 = gen_reg_rtx (DImode);
6069
6070   emit_insn (gen_divdi3 (temp1, operands[1], operands[2]));
6071   emit_insn (gen_ashldi3 (temp2, temp1, GEN_INT (i)));
6072   emit_insn (gen_subdi3 (operands[0], operands[1], temp2));
6073   DONE;
6074 }")
6075
6076 (define_insn ""
6077   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6078         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6079                 (match_operand:DI 2 "exact_log2_cint_operand" "N")))]
6080   "TARGET_POWERPC64"
6081   "sradi %0,%1,%p2\;addze %0,%0"
6082   [(set_attr "type" "two")
6083    (set_attr "length" "8")])
6084
6085 (define_insn ""
6086   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6087         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6088                             (match_operand:DI 2 "exact_log2_cint_operand" "N,N"))
6089                     (const_int 0)))
6090    (clobber (match_scratch:DI 3 "=r,r"))]
6091   "TARGET_64BIT"
6092   "@
6093    sradi %3,%1,%p2\;addze. %3,%3
6094    #"
6095   [(set_attr "type" "compare")
6096    (set_attr "length" "8,12")])
6097
6098 (define_split
6099   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6100         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6101                             (match_operand:DI 2 "exact_log2_cint_operand" ""))
6102                     (const_int 0)))
6103    (clobber (match_scratch:DI 3 ""))]
6104   "TARGET_POWERPC64 && reload_completed"
6105   [(set (match_dup 3)
6106         (div:DI (match_dup 1) (match_dup 2)))
6107    (set (match_dup 0)
6108         (compare:CC (match_dup 3)
6109                     (const_int 0)))]
6110   "")
6111
6112 (define_insn ""
6113   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6114         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6115                             (match_operand:DI 2 "exact_log2_cint_operand" "N,N"))
6116                     (const_int 0)))
6117    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6118         (div:DI (match_dup 1) (match_dup 2)))]
6119   "TARGET_64BIT"
6120   "@
6121    sradi %0,%1,%p2\;addze. %0,%0
6122    #"
6123   [(set_attr "type" "compare")
6124    (set_attr "length" "8,12")])
6125
6126 (define_split
6127   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6128         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6129                             (match_operand:DI 2 "exact_log2_cint_operand" ""))
6130                     (const_int 0)))
6131    (set (match_operand:DI 0 "gpc_reg_operand" "")
6132         (div:DI (match_dup 1) (match_dup 2)))]
6133   "TARGET_POWERPC64 && reload_completed"
6134   [(set (match_dup 0)
6135         (div:DI (match_dup 1) (match_dup 2)))
6136    (set (match_dup 3)
6137         (compare:CC (match_dup 0)
6138                     (const_int 0)))]
6139   "")
6140
6141 (define_insn ""
6142   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6143         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6144                 (match_operand:DI 2 "gpc_reg_operand" "r")))]
6145   "TARGET_POWERPC64"
6146   "divd %0,%1,%2"
6147   [(set_attr "type" "ldiv")])
6148
6149 (define_insn "udivdi3"
6150   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6151         (udiv:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6152                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
6153   "TARGET_POWERPC64"
6154   "divdu %0,%1,%2"
6155   [(set_attr "type" "ldiv")])
6156
6157 (define_insn "rotldi3"
6158   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6159         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6160                    (match_operand:DI 2 "reg_or_cint_operand" "ri")))]
6161   "TARGET_POWERPC64"
6162   "rld%I2cl %0,%1,%H2,0")
6163
6164 (define_insn "*rotldi3_internal2"
6165   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6166         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6167                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6168                     (const_int 0)))
6169    (clobber (match_scratch:DI 3 "=r,r"))]
6170   "TARGET_64BIT"
6171   "@
6172    rld%I2cl. %3,%1,%H2,0
6173    #"
6174   [(set_attr "type" "delayed_compare")
6175    (set_attr "length" "4,8")])
6176
6177 (define_split
6178   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6179         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6180                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6181                     (const_int 0)))
6182    (clobber (match_scratch:DI 3 ""))]
6183   "TARGET_POWERPC64 && reload_completed"
6184   [(set (match_dup 3)
6185         (rotate:DI (match_dup 1) (match_dup 2)))
6186    (set (match_dup 0)
6187         (compare:CC (match_dup 3)
6188                     (const_int 0)))]
6189   "")
6190
6191 (define_insn "*rotldi3_internal3"
6192   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6193         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6194                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6195                     (const_int 0)))
6196    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6197         (rotate:DI (match_dup 1) (match_dup 2)))]
6198   "TARGET_64BIT"
6199   "@
6200    rld%I2cl. %0,%1,%H2,0
6201    #"
6202   [(set_attr "type" "delayed_compare")
6203    (set_attr "length" "4,8")])
6204
6205 (define_split
6206   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6207         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6208                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6209                     (const_int 0)))
6210    (set (match_operand:DI 0 "gpc_reg_operand" "")
6211         (rotate:DI (match_dup 1) (match_dup 2)))]
6212   "TARGET_POWERPC64 && reload_completed"
6213   [(set (match_dup 0)
6214         (rotate:DI (match_dup 1) (match_dup 2)))
6215    (set (match_dup 3)
6216         (compare:CC (match_dup 0)
6217                     (const_int 0)))]
6218   "")
6219
6220 (define_insn "*rotldi3_internal4"
6221   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6222         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6223                            (match_operand:DI 2 "reg_or_cint_operand" "ri"))
6224                 (match_operand:DI 3 "mask64_operand" "n")))]
6225   "TARGET_POWERPC64"
6226   "rld%I2c%B3 %0,%1,%H2,%S3")
6227
6228 (define_insn "*rotldi3_internal5"
6229   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6230         (compare:CC (and:DI
6231                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6232                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6233                      (match_operand:DI 3 "mask64_operand" "n,n"))
6234                     (const_int 0)))
6235    (clobber (match_scratch:DI 4 "=r,r"))]
6236   "TARGET_64BIT"
6237   "@
6238    rld%I2c%B3. %4,%1,%H2,%S3
6239    #"
6240   [(set_attr "type" "delayed_compare")
6241    (set_attr "length" "4,8")])
6242
6243 (define_split
6244   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6245         (compare:CC (and:DI
6246                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6247                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6248                      (match_operand:DI 3 "mask64_operand" ""))
6249                     (const_int 0)))
6250    (clobber (match_scratch:DI 4 ""))]
6251   "TARGET_POWERPC64 && reload_completed"
6252   [(set (match_dup 4)
6253         (and:DI (rotate:DI (match_dup 1)
6254                                 (match_dup 2))
6255                      (match_dup 3)))
6256    (set (match_dup 0)
6257         (compare:CC (match_dup 4)
6258                     (const_int 0)))]
6259   "")
6260
6261 (define_insn "*rotldi3_internal6"
6262   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6263         (compare:CC (and:DI
6264                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6265                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6266                      (match_operand:DI 3 "mask64_operand" "n,n"))
6267                     (const_int 0)))
6268    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6269         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6270   "TARGET_64BIT"
6271   "@
6272    rld%I2c%B3. %0,%1,%H2,%S3
6273    #"
6274   [(set_attr "type" "delayed_compare")
6275    (set_attr "length" "4,8")])
6276
6277 (define_split
6278   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6279         (compare:CC (and:DI
6280                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6281                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6282                      (match_operand:DI 3 "mask64_operand" ""))
6283                     (const_int 0)))
6284    (set (match_operand:DI 0 "gpc_reg_operand" "")
6285         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6286   "TARGET_POWERPC64 && reload_completed"
6287   [(set (match_dup 0)
6288         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
6289    (set (match_dup 4)
6290         (compare:CC (match_dup 0)
6291                     (const_int 0)))]
6292   "")
6293
6294 (define_insn "*rotldi3_internal7"
6295   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6296         (zero_extend:DI
6297          (subreg:QI
6298           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6299                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6300   "TARGET_POWERPC64"
6301   "rld%I2cl %0,%1,%H2,56")
6302
6303 (define_insn "*rotldi3_internal8"
6304   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6305         (compare:CC (zero_extend:DI
6306                      (subreg:QI
6307                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6308                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6309                     (const_int 0)))
6310    (clobber (match_scratch:DI 3 "=r,r"))]
6311   "TARGET_64BIT"
6312   "@
6313    rld%I2cl. %3,%1,%H2,56
6314    #"
6315   [(set_attr "type" "delayed_compare")
6316    (set_attr "length" "4,8")])
6317
6318 (define_split
6319   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6320         (compare:CC (zero_extend:DI
6321                      (subreg:QI
6322                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6323                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6324                     (const_int 0)))
6325    (clobber (match_scratch:DI 3 ""))]
6326   "TARGET_POWERPC64 && reload_completed"
6327   [(set (match_dup 3)
6328         (zero_extend:DI (subreg:QI
6329                       (rotate:DI (match_dup 1)
6330                                  (match_dup 2)) 0)))
6331    (set (match_dup 0)
6332         (compare:CC (match_dup 3)
6333                     (const_int 0)))]
6334   "")
6335
6336 (define_insn "*rotldi3_internal9"
6337   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6338         (compare:CC (zero_extend:DI
6339                      (subreg:QI
6340                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6341                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6342                     (const_int 0)))
6343    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6344         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6345   "TARGET_64BIT"
6346   "@
6347    rld%I2cl. %0,%1,%H2,56
6348    #"
6349   [(set_attr "type" "delayed_compare")
6350    (set_attr "length" "4,8")])
6351
6352 (define_split
6353   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6354         (compare:CC (zero_extend:DI
6355                      (subreg:QI
6356                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6357                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6358                     (const_int 0)))
6359    (set (match_operand:DI 0 "gpc_reg_operand" "")
6360         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6361   "TARGET_POWERPC64 && reload_completed"
6362   [(set (match_dup 0)
6363         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6364    (set (match_dup 3)
6365         (compare:CC (match_dup 0)
6366                     (const_int 0)))]
6367   "")
6368
6369 (define_insn "*rotldi3_internal10"
6370   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6371         (zero_extend:DI
6372          (subreg:HI
6373           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6374                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6375   "TARGET_POWERPC64"
6376   "rld%I2cl %0,%1,%H2,48")
6377
6378 (define_insn "*rotldi3_internal11"
6379   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6380         (compare:CC (zero_extend:DI
6381                      (subreg:HI
6382                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6383                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6384                     (const_int 0)))
6385    (clobber (match_scratch:DI 3 "=r,r"))]
6386   "TARGET_64BIT"
6387   "@
6388    rld%I2cl. %3,%1,%H2,48
6389    #"
6390   [(set_attr "type" "delayed_compare")
6391    (set_attr "length" "4,8")])
6392
6393 (define_split
6394   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6395         (compare:CC (zero_extend:DI
6396                      (subreg:HI
6397                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6398                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6399                     (const_int 0)))
6400    (clobber (match_scratch:DI 3 ""))]
6401   "TARGET_POWERPC64 && reload_completed"
6402   [(set (match_dup 3)
6403         (zero_extend:DI (subreg:HI
6404                       (rotate:DI (match_dup 1)
6405                                  (match_dup 2)) 0)))
6406    (set (match_dup 0)
6407         (compare:CC (match_dup 3)
6408                     (const_int 0)))]
6409   "")
6410
6411 (define_insn "*rotldi3_internal12"
6412   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6413         (compare:CC (zero_extend:DI
6414                      (subreg:HI
6415                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6416                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6417                     (const_int 0)))
6418    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6419         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6420   "TARGET_64BIT"
6421   "@
6422    rld%I2cl. %0,%1,%H2,48
6423    #"
6424   [(set_attr "type" "delayed_compare")
6425    (set_attr "length" "4,8")])
6426
6427 (define_split
6428   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6429         (compare:CC (zero_extend:DI
6430                      (subreg:HI
6431                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6432                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6433                     (const_int 0)))
6434    (set (match_operand:DI 0 "gpc_reg_operand" "")
6435         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6436   "TARGET_POWERPC64 && reload_completed"
6437   [(set (match_dup 0)
6438         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6439    (set (match_dup 3)
6440         (compare:CC (match_dup 0)
6441                     (const_int 0)))]
6442   "")
6443
6444 (define_insn "*rotldi3_internal13"
6445   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6446         (zero_extend:DI
6447          (subreg:SI
6448           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6449                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6450   "TARGET_POWERPC64"
6451   "rld%I2cl %0,%1,%H2,32")
6452
6453 (define_insn "*rotldi3_internal14"
6454   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6455         (compare:CC (zero_extend:DI
6456                      (subreg:SI
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    (clobber (match_scratch:DI 3 "=r,r"))]
6461   "TARGET_64BIT"
6462   "@
6463    rld%I2cl. %3,%1,%H2,32
6464    #"
6465   [(set_attr "type" "delayed_compare")
6466    (set_attr "length" "4,8")])
6467
6468 (define_split
6469   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6470         (compare:CC (zero_extend:DI
6471                      (subreg:SI
6472                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6473                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6474                     (const_int 0)))
6475    (clobber (match_scratch:DI 3 ""))]
6476   "TARGET_POWERPC64 && reload_completed"
6477   [(set (match_dup 3)
6478         (zero_extend:DI (subreg:SI
6479                       (rotate:DI (match_dup 1)
6480                                  (match_dup 2)) 0)))
6481    (set (match_dup 0)
6482         (compare:CC (match_dup 3)
6483                     (const_int 0)))]
6484   "")
6485
6486 (define_insn "*rotldi3_internal15"
6487   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6488         (compare:CC (zero_extend:DI
6489                      (subreg:SI
6490                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6491                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6492                     (const_int 0)))
6493    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6494         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6495   "TARGET_64BIT"
6496   "@
6497    rld%I2cl. %0,%1,%H2,32
6498    #"
6499   [(set_attr "type" "delayed_compare")
6500    (set_attr "length" "4,8")])
6501
6502 (define_split
6503   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6504         (compare:CC (zero_extend:DI
6505                      (subreg:SI
6506                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6507                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6508                     (const_int 0)))
6509    (set (match_operand:DI 0 "gpc_reg_operand" "")
6510         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6511   "TARGET_POWERPC64 && reload_completed"
6512   [(set (match_dup 0)
6513         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6514    (set (match_dup 3)
6515         (compare:CC (match_dup 0)
6516                     (const_int 0)))]
6517   "")
6518
6519 (define_expand "ashldi3"
6520   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6521         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6522                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
6523   "TARGET_POWERPC64 || TARGET_POWER"
6524   "
6525 {
6526   if (TARGET_POWERPC64)
6527     ;
6528   else if (TARGET_POWER)
6529     {
6530       emit_insn (gen_ashldi3_power (operands[0], operands[1], operands[2]));
6531       DONE;
6532     }
6533   else
6534     FAIL;
6535 }")
6536
6537 (define_insn "*ashldi3_internal1"
6538   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6539         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6540                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6541   "TARGET_POWERPC64"
6542   "sld%I2 %0,%1,%H2")
6543
6544 (define_insn "*ashldi3_internal2"
6545   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6546         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6547                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6548                     (const_int 0)))
6549    (clobber (match_scratch:DI 3 "=r,r"))]
6550   "TARGET_64BIT"
6551   "@
6552    sld%I2. %3,%1,%H2
6553    #"
6554   [(set_attr "type" "delayed_compare")
6555    (set_attr "length" "4,8")])
6556
6557 (define_split
6558   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6559         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6560                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6561                     (const_int 0)))
6562    (clobber (match_scratch:DI 3 ""))]
6563   "TARGET_POWERPC64 && reload_completed"
6564   [(set (match_dup 3)
6565         (ashift:DI (match_dup 1) (match_dup 2)))
6566    (set (match_dup 0)
6567         (compare:CC (match_dup 3)
6568                     (const_int 0)))]
6569   "")
6570
6571 (define_insn "*ashldi3_internal3"
6572   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6573         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6574                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6575                     (const_int 0)))
6576    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6577         (ashift:DI (match_dup 1) (match_dup 2)))]
6578   "TARGET_64BIT"
6579   "@
6580    sld%I2. %0,%1,%H2
6581    #"
6582   [(set_attr "type" "delayed_compare")
6583    (set_attr "length" "4,8")])
6584
6585 (define_split
6586   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6587         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6588                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6589                     (const_int 0)))
6590    (set (match_operand:DI 0 "gpc_reg_operand" "")
6591         (ashift:DI (match_dup 1) (match_dup 2)))]
6592   "TARGET_POWERPC64 && reload_completed"
6593   [(set (match_dup 0)
6594         (ashift:DI (match_dup 1) (match_dup 2)))
6595    (set (match_dup 3)
6596         (compare:CC (match_dup 0)
6597                     (const_int 0)))]
6598   "")
6599
6600 (define_insn "*ashldi3_internal4"
6601   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6602         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6603                            (match_operand:SI 2 "const_int_operand" "i"))
6604                 (match_operand:DI 3 "const_int_operand" "n")))]
6605   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
6606   "rldic %0,%1,%H2,%W3")
6607
6608 (define_insn "ashldi3_internal5"
6609   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6610         (compare:CC
6611          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6612                             (match_operand:SI 2 "const_int_operand" "i,i"))
6613                  (match_operand:DI 3 "const_int_operand" "n,n"))
6614          (const_int 0)))
6615    (clobber (match_scratch:DI 4 "=r,r"))]
6616   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6617   "@
6618    rldic. %4,%1,%H2,%W3
6619    #"
6620   [(set_attr "type" "delayed_compare")
6621    (set_attr "length" "4,8")])
6622
6623 (define_split
6624   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6625         (compare:CC
6626          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6627                             (match_operand:SI 2 "const_int_operand" ""))
6628                  (match_operand:DI 3 "const_int_operand" ""))
6629          (const_int 0)))
6630    (clobber (match_scratch:DI 4 ""))]
6631   "TARGET_POWERPC64 && reload_completed
6632    && includes_rldic_lshift_p (operands[2], operands[3])"
6633   [(set (match_dup 4)
6634         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6635                 (match_dup 3)))
6636    (set (match_dup 0)
6637         (compare:CC (match_dup 4)
6638                     (const_int 0)))]
6639   "")
6640
6641 (define_insn "*ashldi3_internal6"
6642   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6643         (compare:CC
6644          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6645                             (match_operand:SI 2 "const_int_operand" "i,i"))
6646                     (match_operand:DI 3 "const_int_operand" "n,n"))
6647          (const_int 0)))
6648    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6649         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6650   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6651   "@
6652    rldic. %0,%1,%H2,%W3
6653    #"
6654   [(set_attr "type" "delayed_compare")
6655    (set_attr "length" "4,8")])
6656
6657 (define_split
6658   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6659         (compare:CC
6660          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6661                             (match_operand:SI 2 "const_int_operand" ""))
6662                  (match_operand:DI 3 "const_int_operand" ""))
6663          (const_int 0)))
6664    (set (match_operand:DI 0 "gpc_reg_operand" "")
6665         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6666   "TARGET_POWERPC64 && reload_completed
6667    && includes_rldic_lshift_p (operands[2], operands[3])"
6668   [(set (match_dup 0)
6669         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6670                 (match_dup 3)))
6671    (set (match_dup 4)
6672         (compare:CC (match_dup 0)
6673                     (const_int 0)))]
6674   "")
6675
6676 (define_insn "*ashldi3_internal7"
6677   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6678         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6679                            (match_operand:SI 2 "const_int_operand" "i"))
6680                 (match_operand:DI 3 "mask64_operand" "n")))]
6681   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
6682   "rldicr %0,%1,%H2,%S3")
6683
6684 (define_insn "ashldi3_internal8"
6685   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6686         (compare:CC
6687          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6688                             (match_operand:SI 2 "const_int_operand" "i,i"))
6689                  (match_operand:DI 3 "mask64_operand" "n,n"))
6690          (const_int 0)))
6691    (clobber (match_scratch:DI 4 "=r,r"))]
6692   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
6693   "@
6694    rldicr. %4,%1,%H2,%S3
6695    #"
6696   [(set_attr "type" "delayed_compare")
6697    (set_attr "length" "4,8")])
6698
6699 (define_split
6700   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6701         (compare:CC
6702          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6703                             (match_operand:SI 2 "const_int_operand" ""))
6704                  (match_operand:DI 3 "mask64_operand" ""))
6705          (const_int 0)))
6706    (clobber (match_scratch:DI 4 ""))]
6707   "TARGET_POWERPC64 && reload_completed
6708    && includes_rldicr_lshift_p (operands[2], operands[3])"
6709   [(set (match_dup 4)
6710         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6711                 (match_dup 3)))
6712    (set (match_dup 0)
6713         (compare:CC (match_dup 4)
6714                     (const_int 0)))]
6715   "")
6716
6717 (define_insn "*ashldi3_internal9"
6718   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6719         (compare:CC
6720          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6721                             (match_operand:SI 2 "const_int_operand" "i,i"))
6722                     (match_operand:DI 3 "mask64_operand" "n,n"))
6723          (const_int 0)))
6724    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6725         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6726   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
6727   "@
6728    rldicr. %0,%1,%H2,%S3
6729    #"
6730   [(set_attr "type" "delayed_compare")
6731    (set_attr "length" "4,8")])
6732
6733 (define_split
6734   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6735         (compare:CC
6736          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6737                             (match_operand:SI 2 "const_int_operand" ""))
6738                  (match_operand:DI 3 "mask64_operand" ""))
6739          (const_int 0)))
6740    (set (match_operand:DI 0 "gpc_reg_operand" "")
6741         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6742   "TARGET_POWERPC64 && reload_completed
6743    && includes_rldicr_lshift_p (operands[2], operands[3])"
6744   [(set (match_dup 0)
6745         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6746                 (match_dup 3)))
6747    (set (match_dup 4)
6748         (compare:CC (match_dup 0)
6749                     (const_int 0)))]
6750   "")
6751
6752 (define_expand "lshrdi3"
6753   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6754         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6755                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
6756   "TARGET_POWERPC64 || TARGET_POWER"
6757   "
6758 {
6759   if (TARGET_POWERPC64)
6760     ;
6761   else if (TARGET_POWER)
6762     {
6763       emit_insn (gen_lshrdi3_power (operands[0], operands[1], operands[2]));
6764       DONE;
6765     }
6766   else
6767     FAIL;
6768 }")
6769
6770 (define_insn "*lshrdi3_internal1"
6771   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6772         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6773                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6774   "TARGET_POWERPC64"
6775   "srd%I2 %0,%1,%H2")
6776
6777 (define_insn "*lshrdi3_internal2"
6778   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6779         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6780                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6781                     (const_int 0)))
6782    (clobber (match_scratch:DI 3 "=r,r"))]
6783   "TARGET_64BIT "
6784   "@
6785    srd%I2. %3,%1,%H2
6786    #"
6787   [(set_attr "type" "delayed_compare")
6788    (set_attr "length" "4,8")])
6789
6790 (define_split
6791   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6792         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6793                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6794                     (const_int 0)))
6795    (clobber (match_scratch:DI 3 ""))]
6796   "TARGET_POWERPC64 && reload_completed"
6797   [(set (match_dup 3)
6798         (lshiftrt:DI (match_dup 1) (match_dup 2)))
6799    (set (match_dup 0)
6800         (compare:CC (match_dup 3)
6801                     (const_int 0)))]
6802   "")
6803
6804 (define_insn "*lshrdi3_internal3"
6805   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6806         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6807                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6808                     (const_int 0)))
6809    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6810         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
6811   "TARGET_64BIT"
6812   "@
6813    srd%I2. %0,%1,%H2
6814    #"
6815   [(set_attr "type" "delayed_compare")
6816    (set_attr "length" "4,8")])
6817
6818 (define_split
6819   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6820         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6821                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6822                     (const_int 0)))
6823    (set (match_operand:DI 0 "gpc_reg_operand" "")
6824         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
6825   "TARGET_POWERPC64 && reload_completed"
6826   [(set (match_dup 0)
6827         (lshiftrt:DI (match_dup 1) (match_dup 2)))
6828    (set (match_dup 3)
6829         (compare:CC (match_dup 0)
6830                     (const_int 0)))]
6831   "")
6832
6833 (define_expand "ashrdi3"
6834   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6835         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6836                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
6837   "WORDS_BIG_ENDIAN"
6838   "
6839 {
6840   if (TARGET_POWERPC64)
6841     ;
6842   else if (TARGET_POWER && GET_CODE (operands[2]) == CONST_INT)
6843     {
6844       emit_insn (gen_ashrdi3_power (operands[0], operands[1], operands[2]));
6845       DONE;
6846     }
6847   else if (TARGET_32BIT && GET_CODE (operands[2]) == CONST_INT
6848            && WORDS_BIG_ENDIAN)
6849     {
6850       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
6851       DONE;
6852     }
6853   else
6854     FAIL;
6855 }")
6856
6857 (define_insn "*ashrdi3_internal1"
6858   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6859         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6860                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6861   "TARGET_POWERPC64"
6862   "srad%I2 %0,%1,%H2")
6863
6864 (define_insn "*ashrdi3_internal2"
6865   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6866         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6867                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6868                     (const_int 0)))
6869    (clobber (match_scratch:DI 3 "=r,r"))]
6870   "TARGET_64BIT"
6871   "@
6872    srad%I2. %3,%1,%H2
6873    #"
6874   [(set_attr "type" "delayed_compare")
6875    (set_attr "length" "4,8")])
6876
6877 (define_split
6878   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6879         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6880                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6881                     (const_int 0)))
6882    (clobber (match_scratch:DI 3 ""))]
6883   "TARGET_POWERPC64 && reload_completed"
6884   [(set (match_dup 3)
6885         (ashiftrt:DI (match_dup 1) (match_dup 2)))
6886    (set (match_dup 0)
6887         (compare:CC (match_dup 3)
6888                     (const_int 0)))]
6889   "")
6890
6891 (define_insn "*ashrdi3_internal3"
6892   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6893         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6894                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6895                     (const_int 0)))
6896    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6897         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
6898   "TARGET_64BIT"
6899   "@
6900    srad%I2. %0,%1,%H2
6901    #"
6902   [(set_attr "type" "delayed_compare")
6903    (set_attr "length" "4,8")])
6904
6905 (define_split
6906   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6907         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6908                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6909                     (const_int 0)))
6910    (set (match_operand:DI 0 "gpc_reg_operand" "")
6911         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
6912   "TARGET_POWERPC64 && reload_completed"
6913   [(set (match_dup 0)
6914         (ashiftrt:DI (match_dup 1) (match_dup 2)))
6915    (set (match_dup 3)
6916         (compare:CC (match_dup 0)
6917                     (const_int 0)))]
6918   "")
6919
6920 (define_insn "anddi3"
6921   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
6922         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r")
6923                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,K,J,t")))
6924    (clobber (match_scratch:CC 3 "=X,X,X,x,x,X"))]
6925   "TARGET_POWERPC64"
6926   "@
6927    and %0,%1,%2
6928    rldic%B2 %0,%1,0,%S2
6929    rlwinm %0,%1,0,%m2,%M2
6930    andi. %0,%1,%b2
6931    andis. %0,%1,%u2
6932    #"
6933   [(set_attr "type" "*,*,*,compare,compare,*")
6934    (set_attr "length" "4,4,4,4,4,8")])
6935
6936 (define_split
6937   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6938         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
6939                 (match_operand:DI 2 "mask64_2_operand" "")))
6940    (clobber (match_scratch:CC 3 ""))]
6941   "TARGET_POWERPC64
6942     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
6943     && !mask64_operand (operands[2], DImode)"
6944   [(set (match_dup 0)
6945         (and:DI (rotate:DI (match_dup 1)
6946                            (match_dup 4))
6947                 (match_dup 5)))
6948    (set (match_dup 0)
6949         (and:DI (rotate:DI (match_dup 0)
6950                            (match_dup 6))
6951                 (match_dup 7)))]
6952 {
6953   build_mask64_2_operands (operands[2], &operands[4]);
6954 })
6955
6956 (define_insn "*anddi3_internal2"
6957   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,??y,??y,?y")
6958         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
6959                             (match_operand:DI 2 "and64_2_operand" "r,S,K,J,t,r,S,K,J,t"))
6960                     (const_int 0)))
6961    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r"))
6962    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,x,x,X"))]
6963   "TARGET_64BIT"
6964   "@
6965    and. %3,%1,%2
6966    rldic%B2. %3,%1,0,%S2
6967    andi. %3,%1,%b2
6968    andis. %3,%1,%u2
6969    #
6970    #
6971    #
6972    #
6973    #
6974    #"
6975   [(set_attr "type" "compare,delayed_compare,compare,compare,delayed_compare,compare,compare,compare,compare,compare")
6976    (set_attr "length" "4,4,4,4,8,8,8,8,8,12")])
6977
6978 (define_split
6979   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6980         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
6981                             (match_operand:DI 2 "and64_operand" ""))
6982                     (const_int 0)))
6983    (clobber (match_scratch:DI 3 ""))
6984    (clobber (match_scratch:CC 4 ""))]
6985   "TARGET_POWERPC64 && reload_completed"
6986   [(parallel [(set (match_dup 3)
6987                    (and:DI (match_dup 1)
6988                            (match_dup 2)))
6989               (clobber (match_dup 4))])
6990    (set (match_dup 0)
6991         (compare:CC (match_dup 3)
6992                     (const_int 0)))]
6993   "")
6994
6995 (define_split
6996   [(set (match_operand:CC 0 "cc_reg_operand" "")
6997         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
6998                             (match_operand:DI 2 "mask64_2_operand" ""))
6999                     (const_int 0)))
7000    (clobber (match_scratch:DI 3 ""))
7001    (clobber (match_scratch:CC 4 ""))]
7002   "TARGET_POWERPC64 && reload_completed
7003     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7004     && !mask64_operand (operands[2], DImode)"
7005   [(set (match_dup 3)
7006         (and:DI (rotate:DI (match_dup 1)
7007                            (match_dup 5))
7008                 (match_dup 6)))
7009    (parallel [(set (match_dup 0)
7010                    (compare:CC (and:DI (rotate:DI (match_dup 3)
7011                                                   (match_dup 7))
7012                                        (match_dup 8))
7013                                (const_int 0)))
7014               (clobber (match_dup 3))])]
7015   "
7016 {
7017   build_mask64_2_operands (operands[2], &operands[5]);
7018 }")
7019
7020 (define_insn "*anddi3_internal3"
7021   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,?y,?y,??y,??y,?y")
7022         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
7023                             (match_operand:DI 2 "and64_2_operand" "r,S,K,J,t,r,S,K,J,t"))
7024                     (const_int 0)))
7025    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
7026         (and:DI (match_dup 1) (match_dup 2)))
7027    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,x,x,X"))]
7028   "TARGET_64BIT"
7029   "@
7030    and. %0,%1,%2
7031    rldic%B2. %0,%1,0,%S2
7032    andi. %0,%1,%b2
7033    andis. %0,%1,%u2
7034    #
7035    #
7036    #
7037    #
7038    #
7039    #"
7040   [(set_attr "type" "compare,delayed_compare,compare,compare,delayed_compare,compare,compare,compare,compare,compare")
7041    (set_attr "length" "4,4,4,4,8,8,8,8,8,12")])
7042
7043 (define_split
7044   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7045         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7046                             (match_operand:DI 2 "and64_operand" ""))
7047                     (const_int 0)))
7048    (set (match_operand:DI 0 "gpc_reg_operand" "")
7049         (and:DI (match_dup 1) (match_dup 2)))
7050    (clobber (match_scratch:CC 4 ""))]
7051   "TARGET_POWERPC64 && reload_completed"
7052   [(parallel [(set (match_dup 0)
7053                     (and:DI (match_dup 1) (match_dup 2)))
7054                (clobber (match_dup 4))])
7055    (set (match_dup 3)
7056         (compare:CC (match_dup 0)
7057                     (const_int 0)))]
7058   "")
7059
7060 (define_split
7061   [(set (match_operand:CC 3 "cc_reg_operand" "")
7062         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7063                             (match_operand:DI 2 "mask64_2_operand" ""))
7064                     (const_int 0)))
7065    (set (match_operand:DI 0 "gpc_reg_operand" "")
7066         (and:DI (match_dup 1) (match_dup 2)))
7067    (clobber (match_scratch:CC 4 ""))]
7068   "TARGET_POWERPC64 && reload_completed
7069     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7070     && !mask64_operand (operands[2], DImode)"
7071   [(set (match_dup 0)
7072         (and:DI (rotate:DI (match_dup 1)
7073                            (match_dup 5))
7074                 (match_dup 6)))
7075    (parallel [(set (match_dup 3)
7076                    (compare:CC (and:DI (rotate:DI (match_dup 0)
7077                                                   (match_dup 7))
7078                                        (match_dup 8))
7079                                (const_int 0)))
7080               (set (match_dup 0)
7081                    (and:DI (rotate:DI (match_dup 0)
7082                                       (match_dup 7))
7083                            (match_dup 8)))])]
7084   "
7085 {
7086   build_mask64_2_operands (operands[2], &operands[5]);
7087 }")
7088
7089 (define_expand "iordi3"
7090   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7091         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
7092                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7093   "TARGET_POWERPC64"
7094   "
7095 {
7096   if (non_logical_cint_operand (operands[2], DImode))
7097     {
7098       HOST_WIDE_INT value;
7099       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7100                  ? operands[0] : gen_reg_rtx (DImode));
7101
7102       if (GET_CODE (operands[2]) == CONST_INT)
7103         {
7104           value = INTVAL (operands[2]);
7105           emit_insn (gen_iordi3 (tmp, operands[1],
7106                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7107         }
7108       else
7109         {
7110           value = CONST_DOUBLE_LOW (operands[2]);
7111           emit_insn (gen_iordi3 (tmp, operands[1],
7112                                  immed_double_const (value
7113                                                      & (~ (HOST_WIDE_INT) 0xffff),
7114                                                      0, DImode)));
7115         }
7116
7117       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7118       DONE;
7119     }
7120 }")
7121
7122 (define_expand "xordi3"
7123   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7124         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
7125                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7126   "TARGET_POWERPC64"
7127   "
7128 {
7129   if (non_logical_cint_operand (operands[2], DImode))
7130     {
7131       HOST_WIDE_INT value;
7132       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7133                  ? operands[0] : gen_reg_rtx (DImode));
7134
7135       if (GET_CODE (operands[2]) == CONST_INT)
7136         {
7137           value = INTVAL (operands[2]);
7138           emit_insn (gen_xordi3 (tmp, operands[1],
7139                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7140         }
7141       else
7142         {
7143           value = CONST_DOUBLE_LOW (operands[2]);
7144           emit_insn (gen_xordi3 (tmp, operands[1],
7145                                  immed_double_const (value
7146                                                      & (~ (HOST_WIDE_INT) 0xffff),
7147                                                      0, DImode)));
7148         }
7149
7150       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7151       DONE;
7152     }
7153 }")
7154
7155 (define_insn "*booldi3_internal1"
7156   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
7157         (match_operator:DI 3 "boolean_or_operator"
7158          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
7159           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
7160   "TARGET_POWERPC64"
7161   "@
7162    %q3 %0,%1,%2
7163    %q3i %0,%1,%b2
7164    %q3is %0,%1,%u2")
7165
7166 (define_insn "*booldi3_internal2"
7167   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7168         (compare:CC (match_operator:DI 4 "boolean_or_operator"
7169          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7170           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7171          (const_int 0)))
7172    (clobber (match_scratch:DI 3 "=r,r"))]
7173   "TARGET_64BIT"
7174   "@
7175    %q4. %3,%1,%2
7176    #"
7177   [(set_attr "type" "compare")
7178    (set_attr "length" "4,8")])
7179
7180 (define_split
7181   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7182         (compare:CC (match_operator:DI 4 "boolean_operator"
7183          [(match_operand:DI 1 "gpc_reg_operand" "")
7184           (match_operand:DI 2 "gpc_reg_operand" "")])
7185          (const_int 0)))
7186    (clobber (match_scratch:DI 3 ""))]
7187   "TARGET_POWERPC64 && reload_completed"
7188   [(set (match_dup 3) (match_dup 4))
7189    (set (match_dup 0)
7190         (compare:CC (match_dup 3)
7191                     (const_int 0)))]
7192   "")
7193
7194 (define_insn "*booldi3_internal3"
7195   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7196         (compare:CC (match_operator:DI 4 "boolean_operator"
7197          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7198           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7199          (const_int 0)))
7200    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7201         (match_dup 4))]
7202   "TARGET_64BIT"
7203   "@
7204    %q4. %0,%1,%2
7205    #"
7206   [(set_attr "type" "compare")
7207    (set_attr "length" "4,8")])
7208
7209 (define_split
7210   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7211         (compare:CC (match_operator:DI 4 "boolean_operator"
7212          [(match_operand:DI 1 "gpc_reg_operand" "")
7213           (match_operand:DI 2 "gpc_reg_operand" "")])
7214          (const_int 0)))
7215    (set (match_operand:DI 0 "gpc_reg_operand" "")
7216         (match_dup 4))]
7217   "TARGET_POWERPC64 && reload_completed"
7218   [(set (match_dup 0) (match_dup 4))
7219    (set (match_dup 3)
7220         (compare:CC (match_dup 0)
7221                     (const_int 0)))]
7222   "")
7223
7224 ;; Split a logical operation that we can't do in one insn into two insns,
7225 ;; each of which does one 16-bit part.  This is used by combine.
7226
7227 (define_split
7228   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7229         (match_operator:DI 3 "boolean_or_operator"
7230          [(match_operand:DI 1 "gpc_reg_operand" "")
7231           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
7232   "TARGET_POWERPC64"
7233   [(set (match_dup 0) (match_dup 4))
7234    (set (match_dup 0) (match_dup 5))]
7235 "
7236 {
7237   rtx i3,i4;
7238
7239   if (GET_CODE (operands[2]) == CONST_DOUBLE)
7240     {
7241       HOST_WIDE_INT value = CONST_DOUBLE_LOW (operands[2]);
7242       i3 = immed_double_const (value & (~ (HOST_WIDE_INT) 0xffff),
7243                                         0, DImode);
7244       i4 = GEN_INT (value & 0xffff);
7245     }
7246   else
7247     {
7248       i3 = GEN_INT (INTVAL (operands[2])
7249                              & (~ (HOST_WIDE_INT) 0xffff));
7250       i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
7251     }
7252   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7253                                 operands[1], i3);
7254   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7255                                 operands[0], i4);
7256 }")
7257
7258 (define_insn "*boolcdi3_internal1"
7259   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7260         (match_operator:DI 3 "boolean_operator"
7261          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7262           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
7263   "TARGET_POWERPC64"
7264   "%q3 %0,%2,%1")
7265
7266 (define_insn "*boolcdi3_internal2"
7267   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7268         (compare:CC (match_operator:DI 4 "boolean_operator"
7269          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7270           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7271          (const_int 0)))
7272    (clobber (match_scratch:DI 3 "=r,r"))]
7273   "TARGET_64BIT"
7274   "@
7275    %q4. %3,%2,%1
7276    #"
7277   [(set_attr "type" "compare")
7278    (set_attr "length" "4,8")])
7279
7280 (define_split
7281   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7282         (compare:CC (match_operator:DI 4 "boolean_operator"
7283          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7284           (match_operand:DI 2 "gpc_reg_operand" "")])
7285          (const_int 0)))
7286    (clobber (match_scratch:DI 3 ""))]
7287   "TARGET_POWERPC64 && reload_completed"
7288   [(set (match_dup 3) (match_dup 4))
7289    (set (match_dup 0)
7290         (compare:CC (match_dup 3)
7291                     (const_int 0)))]
7292   "")
7293
7294 (define_insn "*boolcdi3_internal3"
7295   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7296         (compare:CC (match_operator:DI 4 "boolean_operator"
7297          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7298           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7299          (const_int 0)))
7300    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7301         (match_dup 4))]
7302   "TARGET_64BIT"
7303   "@
7304    %q4. %0,%2,%1
7305    #"
7306   [(set_attr "type" "compare")
7307    (set_attr "length" "4,8")])
7308
7309 (define_split
7310   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7311         (compare:CC (match_operator:DI 4 "boolean_operator"
7312          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7313           (match_operand:DI 2 "gpc_reg_operand" "")])
7314          (const_int 0)))
7315    (set (match_operand:DI 0 "gpc_reg_operand" "")
7316         (match_dup 4))]
7317   "TARGET_POWERPC64 && reload_completed"
7318   [(set (match_dup 0) (match_dup 4))
7319    (set (match_dup 3)
7320         (compare:CC (match_dup 0)
7321                     (const_int 0)))]
7322   "")
7323
7324 (define_insn "*boolccdi3_internal1"
7325   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7326         (match_operator:DI 3 "boolean_operator"
7327          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7328           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
7329   "TARGET_POWERPC64"
7330   "%q3 %0,%1,%2")
7331
7332 (define_insn "*boolccdi3_internal2"
7333   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7334         (compare:CC (match_operator:DI 4 "boolean_operator"
7335          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7336           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7337          (const_int 0)))
7338    (clobber (match_scratch:DI 3 "=r,r"))]
7339   "TARGET_64BIT"
7340   "@
7341    %q4. %3,%1,%2
7342    #"
7343   [(set_attr "type" "compare")
7344    (set_attr "length" "4,8")])
7345
7346 (define_split
7347   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7348         (compare:CC (match_operator:DI 4 "boolean_operator"
7349          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7350           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7351          (const_int 0)))
7352    (clobber (match_scratch:DI 3 ""))]
7353   "TARGET_POWERPC64 && reload_completed"
7354   [(set (match_dup 3) (match_dup 4))
7355    (set (match_dup 0)
7356         (compare:CC (match_dup 3)
7357                     (const_int 0)))]
7358   "")
7359
7360 (define_insn "*boolccdi3_internal3"
7361   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7362         (compare:CC (match_operator:DI 4 "boolean_operator"
7363          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7364           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7365          (const_int 0)))
7366    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7367         (match_dup 4))]
7368   "TARGET_64BIT"
7369   "@
7370    %q4. %0,%1,%2
7371    #"
7372   [(set_attr "type" "compare")
7373    (set_attr "length" "4,8")])
7374
7375 (define_split
7376   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7377         (compare:CC (match_operator:DI 4 "boolean_operator"
7378          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7379           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7380          (const_int 0)))
7381    (set (match_operand:DI 0 "gpc_reg_operand" "")
7382         (match_dup 4))]
7383   "TARGET_POWERPC64 && reload_completed"
7384   [(set (match_dup 0) (match_dup 4))
7385    (set (match_dup 3)
7386         (compare:CC (match_dup 0)
7387                     (const_int 0)))]
7388   "")
7389 \f
7390 ;; Now define ways of moving data around.
7391
7392 ;; Set up a register with a value from the GOT table
7393
7394 (define_expand "movsi_got"
7395   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7396         (unspec:SI [(match_operand:SI 1 "got_operand" "")
7397                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
7398   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7399   "
7400 {
7401   if (GET_CODE (operands[1]) == CONST)
7402     {
7403       rtx offset = const0_rtx;
7404       HOST_WIDE_INT value;
7405
7406       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
7407       value = INTVAL (offset);
7408       if (value != 0)
7409         {
7410           rtx tmp = (no_new_pseudos ? operands[0] : gen_reg_rtx (Pmode));
7411           emit_insn (gen_movsi_got (tmp, operands[1]));
7412           emit_insn (gen_addsi3 (operands[0], tmp, offset));
7413           DONE;
7414         }
7415     }
7416
7417   operands[2] = rs6000_got_register (operands[1]);
7418 }")
7419
7420 (define_insn "*movsi_got_internal"
7421   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7422         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7423                     (match_operand:SI 2 "gpc_reg_operand" "b")]
7424                    UNSPEC_MOVSI_GOT))]
7425   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7426   "{l|lwz} %0,%a1@got(%2)"
7427   [(set_attr "type" "load")])
7428
7429 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
7430 ;; didn't get allocated to a hard register.
7431 (define_split
7432   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7433         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7434                     (match_operand:SI 2 "memory_operand" "")]
7435                    UNSPEC_MOVSI_GOT))]
7436   "DEFAULT_ABI == ABI_V4
7437     && flag_pic == 1
7438     && (reload_in_progress || reload_completed)"
7439   [(set (match_dup 0) (match_dup 2))
7440    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
7441                                  UNSPEC_MOVSI_GOT))]
7442   "")
7443
7444 ;; For SI, we special-case integers that can't be loaded in one insn.  We
7445 ;; do the load 16-bits at a time.  We could do this by loading from memory,
7446 ;; and this is even supposed to be faster, but it is simpler not to get
7447 ;; integers in the TOC.
7448 (define_expand "movsi"
7449   [(set (match_operand:SI 0 "general_operand" "")
7450         (match_operand:SI 1 "any_operand" ""))]
7451   ""
7452   "{ rs6000_emit_move (operands[0], operands[1], SImode); DONE; }")
7453
7454 (define_insn "movsi_low"
7455   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7456         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7457                            (match_operand 2 "" ""))))]
7458   "TARGET_MACHO && ! TARGET_64BIT"
7459   "{l|lwz} %0,lo16(%2)(%1)"
7460   [(set_attr "type" "load")
7461    (set_attr "length" "4")])
7462
7463 (define_insn "*movsi_internal1"
7464   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h")
7465         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0"))]
7466   "gpc_reg_operand (operands[0], SImode)
7467    || gpc_reg_operand (operands[1], SImode)"
7468   "@
7469    mr %0,%1
7470    {cal|la} %0,%a1
7471    {l%U1%X1|lwz%U1%X1} %0,%1
7472    {st%U0%X0|stw%U0%X0} %1,%0
7473    {lil|li} %0,%1
7474    {liu|lis} %0,%v1
7475    #
7476    {cal|la} %0,%a1
7477    mf%1 %0
7478    mt%0 %1
7479    mt%0 %1
7480    mt%0 %1
7481    {cror 0,0,0|nop}"
7482   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*")
7483    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
7484
7485 ;; Split a load of a large constant into the appropriate two-insn
7486 ;; sequence.
7487
7488 (define_split
7489   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7490         (match_operand:SI 1 "const_int_operand" ""))]
7491   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
7492    && (INTVAL (operands[1]) & 0xffff) != 0"
7493   [(set (match_dup 0)
7494         (match_dup 2))
7495    (set (match_dup 0)
7496         (ior:SI (match_dup 0)
7497                 (match_dup 3)))]
7498   "
7499 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
7500
7501   if (tem == operands[0])
7502     DONE;
7503   else
7504     FAIL;
7505 }")
7506
7507 (define_insn "*movsi_internal2"
7508   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
7509         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "0,r,r")
7510                     (const_int 0)))
7511    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
7512   "TARGET_32BIT"
7513   "@
7514    {cmpi|cmpwi} %2,%0,0
7515    mr. %0,%1
7516    #"
7517   [(set_attr "type" "cmp,compare,cmp")
7518    (set_attr "length" "4,4,8")])
7519
7520 (define_split
7521   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
7522         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
7523                     (const_int 0)))
7524    (set (match_operand:SI 0 "gpc_reg_operand" "") (match_dup 1))]
7525   "TARGET_32BIT && reload_completed"
7526   [(set (match_dup 0) (match_dup 1))
7527    (set (match_dup 2)
7528         (compare:CC (match_dup 0)
7529                     (const_int 0)))]
7530   "")
7531 \f
7532 (define_expand "movhi"
7533   [(set (match_operand:HI 0 "general_operand" "")
7534         (match_operand:HI 1 "any_operand" ""))]
7535   ""
7536   "{ rs6000_emit_move (operands[0], operands[1], HImode); DONE; }")
7537
7538 (define_insn "*movhi_internal"
7539   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7540         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7541   "gpc_reg_operand (operands[0], HImode)
7542    || gpc_reg_operand (operands[1], HImode)"
7543   "@
7544    mr %0,%1
7545    lhz%U1%X1 %0,%1
7546    sth%U0%X0 %1,%0
7547    {lil|li} %0,%w1
7548    mf%1 %0
7549    mt%0 %1
7550    mt%0 %1
7551    {cror 0,0,0|nop}"
7552   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7553
7554 (define_expand "movqi"
7555   [(set (match_operand:QI 0 "general_operand" "")
7556         (match_operand:QI 1 "any_operand" ""))]
7557   ""
7558   "{ rs6000_emit_move (operands[0], operands[1], QImode); DONE; }")
7559
7560 (define_insn "*movqi_internal"
7561   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7562         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7563   "gpc_reg_operand (operands[0], QImode)
7564    || gpc_reg_operand (operands[1], QImode)"
7565   "@
7566    mr %0,%1
7567    lbz%U1%X1 %0,%1
7568    stb%U0%X0 %1,%0
7569    {lil|li} %0,%1
7570    mf%1 %0
7571    mt%0 %1
7572    mt%0 %1
7573    {cror 0,0,0|nop}"
7574   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7575 \f
7576 ;; Here is how to move condition codes around.  When we store CC data in
7577 ;; an integer register or memory, we store just the high-order 4 bits.
7578 ;; This lets us not shift in the most common case of CR0.
7579 (define_expand "movcc"
7580   [(set (match_operand:CC 0 "nonimmediate_operand" "")
7581         (match_operand:CC 1 "nonimmediate_operand" ""))]
7582   ""
7583   "")
7584
7585 (define_insn "*movcc_internal1"
7586   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,r,r,r,r,q,cl,r,m")
7587         (match_operand:CC 1 "nonimmediate_operand" "y,r,r,x,y,r,h,r,r,m,r"))]
7588   "register_operand (operands[0], CCmode)
7589    || register_operand (operands[1], CCmode)"
7590   "@
7591    mcrf %0,%1
7592    mtcrf 128,%1
7593    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
7594    mfcr %0%Q1
7595    mfcr %0%Q1\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
7596    mr %0,%1
7597    mf%1 %0
7598    mt%0 %1
7599    mt%0 %1
7600    {l%U1%X1|lwz%U1%X1} %0,%1
7601    {st%U0%U1|stw%U0%U1} %1,%0"
7602   [(set (attr "type")
7603      (cond [(eq_attr "alternative" "0")
7604                 (const_string "cr_logical")
7605             (eq_attr "alternative" "1,2")
7606                 (const_string "mtcr")
7607             (eq_attr "alternative" "5,7")
7608                 (const_string "integer")
7609             (eq_attr "alternative" "6")
7610                 (const_string "mfjmpr")
7611             (eq_attr "alternative" "8")
7612                 (const_string "mtjmpr")
7613             (eq_attr "alternative" "9")
7614                 (const_string "load")
7615             (eq_attr "alternative" "10")
7616                 (const_string "store")
7617             (ne (symbol_ref "TARGET_MFCRF") (const_int 0))
7618                 (const_string "mfcrf")
7619            ]
7620         (const_string "mfcr")))
7621    (set_attr "length" "4,4,12,4,8,4,4,4,4,4,4")])
7622 \f
7623 ;; For floating-point, we normally deal with the floating-point registers
7624 ;; unless -msoft-float is used.  The sole exception is that parameter passing
7625 ;; can produce floating-point values in fixed-point registers.  Unless the
7626 ;; value is a simple constant or already in memory, we deal with this by
7627 ;; allocating memory and copying the value explicitly via that memory location.
7628 (define_expand "movsf"
7629   [(set (match_operand:SF 0 "nonimmediate_operand" "")
7630         (match_operand:SF 1 "any_operand" ""))]
7631   ""
7632   "{ rs6000_emit_move (operands[0], operands[1], SFmode); DONE; }")
7633
7634 (define_split
7635   [(set (match_operand:SF 0 "gpc_reg_operand" "")
7636         (match_operand:SF 1 "const_double_operand" ""))]
7637   "reload_completed
7638    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7639        || (GET_CODE (operands[0]) == SUBREG
7640            && GET_CODE (SUBREG_REG (operands[0])) == REG
7641            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7642   [(set (match_dup 2) (match_dup 3))]
7643   "
7644 {
7645   long l;
7646   REAL_VALUE_TYPE rv;
7647
7648   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7649   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
7650
7651   if (! TARGET_POWERPC64)
7652     operands[2] = operand_subword (operands[0], 0, 0, SFmode);
7653   else
7654     operands[2] = gen_lowpart (SImode, operands[0]);
7655
7656   operands[3] = gen_int_mode (l, SImode);
7657 }")
7658
7659 (define_insn "*movsf_hardfloat"
7660   [(set (match_operand:SF 0 "nonimmediate_operand" "=!r,!r,m,f,f,m,!cl,!q,!r,!h,!r,!r")
7661         (match_operand:SF 1 "input_operand" "r,m,r,f,m,f,r,r,h,0,G,Fn"))]
7662   "(gpc_reg_operand (operands[0], SFmode)
7663    || gpc_reg_operand (operands[1], SFmode))
7664    && (TARGET_HARD_FLOAT && TARGET_FPRS)"
7665   "@
7666    mr %0,%1
7667    {l%U1%X1|lwz%U1%X1} %0,%1
7668    {st%U0%X0|stw%U0%X0} %1,%0
7669    fmr %0,%1
7670    lfs%U1%X1 %0,%1
7671    stfs%U0%X0 %1,%0
7672    mt%0 %1
7673    mt%0 %1
7674    mf%1 %0
7675    {cror 0,0,0|nop}
7676    #
7677    #"
7678   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,mtjmpr,*,*,*,*")
7679    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,8")])
7680
7681 (define_insn "*movsf_softfloat"
7682   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,cl,q,r,r,m,r,r,r,r,r,*h")
7683         (match_operand:SF 1 "input_operand" "r,r,r,h,m,r,I,L,R,G,Fn,0"))]
7684   "(gpc_reg_operand (operands[0], SFmode)
7685    || gpc_reg_operand (operands[1], SFmode))
7686    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
7687   "@
7688    mr %0,%1
7689    mt%0 %1
7690    mt%0 %1
7691    mf%1 %0
7692    {l%U1%X1|lwz%U1%X1} %0,%1
7693    {st%U0%X0|stw%U0%X0} %1,%0
7694    {lil|li} %0,%1
7695    {liu|lis} %0,%v1
7696    {cal|la} %0,%a1
7697    #
7698    #
7699    {cror 0,0,0|nop}"
7700   [(set_attr "type" "*,mtjmpr,*,*,load,store,*,*,*,*,*,*")
7701    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,4")])
7702
7703 \f
7704 (define_expand "movdf"
7705   [(set (match_operand:DF 0 "nonimmediate_operand" "")
7706         (match_operand:DF 1 "any_operand" ""))]
7707   ""
7708   "{ rs6000_emit_move (operands[0], operands[1], DFmode); DONE; }")
7709
7710 (define_split
7711   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7712         (match_operand:DF 1 "const_int_operand" ""))]
7713   "! TARGET_POWERPC64 && reload_completed
7714    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7715        || (GET_CODE (operands[0]) == SUBREG
7716            && GET_CODE (SUBREG_REG (operands[0])) == REG
7717            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7718   [(set (match_dup 2) (match_dup 4))
7719    (set (match_dup 3) (match_dup 1))]
7720   "
7721 {
7722   int endian = (WORDS_BIG_ENDIAN == 0);
7723   HOST_WIDE_INT value = INTVAL (operands[1]);
7724
7725   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
7726   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
7727 #if HOST_BITS_PER_WIDE_INT == 32
7728   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
7729 #else
7730   operands[4] = GEN_INT (value >> 32);
7731   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
7732 #endif
7733 }")
7734
7735 (define_split
7736   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7737         (match_operand:DF 1 "const_double_operand" ""))]
7738   "! TARGET_POWERPC64 && reload_completed
7739    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7740        || (GET_CODE (operands[0]) == SUBREG
7741            && GET_CODE (SUBREG_REG (operands[0])) == REG
7742            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7743   [(set (match_dup 2) (match_dup 4))
7744    (set (match_dup 3) (match_dup 5))]
7745   "
7746 {
7747   int endian = (WORDS_BIG_ENDIAN == 0);
7748   long l[2];
7749   REAL_VALUE_TYPE rv;
7750
7751   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7752   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
7753
7754   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
7755   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
7756   operands[4] = gen_int_mode (l[endian], SImode);
7757   operands[5] = gen_int_mode (l[1 - endian], SImode);
7758 }")
7759
7760 (define_split
7761   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7762         (match_operand:DF 1 "easy_fp_constant" ""))]
7763   "TARGET_POWERPC64 && reload_completed
7764    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7765        || (GET_CODE (operands[0]) == SUBREG
7766            && GET_CODE (SUBREG_REG (operands[0])) == REG
7767            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7768   [(set (match_dup 2) (match_dup 3))]
7769   "
7770 {
7771   int endian = (WORDS_BIG_ENDIAN == 0);
7772   long l[2];
7773   REAL_VALUE_TYPE rv;
7774 #if HOST_BITS_PER_WIDE_INT >= 64
7775   HOST_WIDE_INT val;
7776 #endif
7777
7778   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7779   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
7780
7781   operands[2] = gen_lowpart (DImode, operands[0]);
7782   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
7783 #if HOST_BITS_PER_WIDE_INT >= 64
7784   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
7785          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
7786
7787   operands[3] = gen_int_mode (val, DImode);
7788 #else
7789   operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
7790 #endif
7791 }")
7792
7793 ;; Don't have reload use general registers to load a constant.  First,
7794 ;; it might not work if the output operand is the equivalent of
7795 ;; a non-offsettable memref, but also it is less efficient than loading
7796 ;; the constant into an FP register, since it will probably be used there.
7797 ;; The "??" is a kludge until we can figure out a more reasonable way
7798 ;; of handling these non-offsettable values.
7799 (define_insn "*movdf_hardfloat32"
7800   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,m,f,f,m,!r,!r,!r")
7801         (match_operand:DF 1 "input_operand" "r,m,r,f,m,f,G,H,F"))]
7802   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
7803    && (gpc_reg_operand (operands[0], DFmode)
7804        || gpc_reg_operand (operands[1], DFmode))"
7805   "*
7806 {
7807   switch (which_alternative)
7808     {
7809     default:
7810       gcc_unreachable ();
7811     case 0:
7812       /* We normally copy the low-numbered register first.  However, if
7813          the first register operand 0 is the same as the second register
7814          of operand 1, we must copy in the opposite order.  */
7815       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
7816         return \"mr %L0,%L1\;mr %0,%1\";
7817       else
7818         return \"mr %0,%1\;mr %L0,%L1\";
7819     case 1:
7820       if (GET_CODE (operands[1]) == MEM
7821           && (rs6000_legitimate_offset_address_p (DFmode, XEXP (operands[1], 0),
7822                         reload_completed || reload_in_progress)
7823               || GET_CODE (XEXP (operands[1], 0)) == REG
7824               || GET_CODE (XEXP (operands[1], 0)) == LO_SUM
7825                   || GET_CODE (XEXP (operands[1], 0)) == PRE_INC
7826               || GET_CODE (XEXP (operands[1], 0)) == PRE_DEC))
7827         {
7828           /* If the low-address word is used in the address, we must load
7829              it last.  Otherwise, load it first.  Note that we cannot have
7830              auto-increment in that case since the address register is
7831              known to be dead.  */
7832           if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
7833                                  operands[1], 0))
7834             return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
7835           else
7836             return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
7837         }
7838       else
7839         {
7840           rtx addreg;
7841
7842           addreg = find_addr_reg (XEXP (operands[1], 0));
7843           if (refers_to_regno_p (REGNO (operands[0]),
7844                                  REGNO (operands[0]) + 1,
7845                                  operands[1], 0))
7846             {
7847               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
7848               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
7849               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
7850               return \"{lx|lwzx} %0,%1\";
7851             }
7852           else
7853             {
7854               output_asm_insn (\"{lx|lwzx} %0,%1\", operands);
7855               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
7856               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
7857               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
7858               return \"\";
7859             }
7860         }
7861     case 2:
7862       if (GET_CODE (operands[0]) == MEM
7863           && (rs6000_legitimate_offset_address_p (DFmode, XEXP (operands[0], 0),
7864                     reload_completed || reload_in_progress)
7865               || GET_CODE (XEXP (operands[0], 0)) == REG
7866               || GET_CODE (XEXP (operands[0], 0)) == LO_SUM
7867                   || GET_CODE (XEXP (operands[0], 0)) == PRE_INC
7868               || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC))
7869         return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
7870       else
7871         {
7872           rtx addreg;
7873
7874           addreg = find_addr_reg (XEXP (operands[0], 0));
7875           output_asm_insn (\"{stx|stwx} %1,%0\", operands);
7876           output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
7877           output_asm_insn (\"{stx|stwx} %L1,%0\", operands);
7878           output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
7879           return \"\";
7880         }
7881     case 3:
7882       return \"fmr %0,%1\";
7883     case 4:
7884       return \"lfd%U1%X1 %0,%1\";
7885     case 5:
7886       return \"stfd%U0%X0 %1,%0\";
7887     case 6:
7888     case 7:
7889     case 8:
7890       return \"#\";
7891     }
7892 }"
7893   [(set_attr "type" "two,load,store,fp,fpload,fpstore,*,*,*")
7894    (set_attr "length" "8,16,16,4,4,4,8,12,16")])
7895
7896 (define_insn "*movdf_softfloat32"
7897   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
7898         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F"))]
7899   "! TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || TARGET_E500_SINGLE)
7900    && (gpc_reg_operand (operands[0], DFmode)
7901        || gpc_reg_operand (operands[1], DFmode))"
7902   "*
7903 {
7904   switch (which_alternative)
7905     {
7906     default:
7907       gcc_unreachable ();
7908     case 0:
7909       /* We normally copy the low-numbered register first.  However, if
7910          the first register operand 0 is the same as the second register of
7911          operand 1, we must copy in the opposite order.  */
7912       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
7913         return \"mr %L0,%L1\;mr %0,%1\";
7914       else
7915         return \"mr %0,%1\;mr %L0,%L1\";
7916     case 1:
7917       /* If the low-address word is used in the address, we must load
7918          it last.  Otherwise, load it first.  Note that we cannot have
7919          auto-increment in that case since the address register is
7920          known to be dead.  */
7921       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
7922                              operands[1], 0))
7923         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
7924       else
7925         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
7926     case 2:
7927       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
7928     case 3:
7929     case 4:
7930     case 5:
7931       return \"#\";
7932     }
7933 }"
7934   [(set_attr "type" "two,load,store,*,*,*")
7935    (set_attr "length" "8,8,8,8,12,16")])
7936
7937 ; ld/std require word-aligned displacements -> 'Y' constraint.
7938 ; List Y->r and r->Y before r->r for reload.
7939 (define_insn "*movdf_hardfloat64"
7940   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,!r,f,f,m,!cl,!r,!h,!r,!r,!r")
7941         (match_operand:DF 1 "input_operand" "r,Y,r,f,m,f,r,h,0,G,H,F"))]
7942   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
7943    && (gpc_reg_operand (operands[0], DFmode)
7944        || gpc_reg_operand (operands[1], DFmode))"
7945   "@
7946    std%U0%X0 %1,%0
7947    ld%U1%X1 %0,%1
7948    mr %0,%1
7949    fmr %0,%1
7950    lfd%U1%X1 %0,%1
7951    stfd%U0%X0 %1,%0
7952    mt%0 %1
7953    mf%1 %0
7954    {cror 0,0,0|nop}
7955    #
7956    #
7957    #"
7958   [(set_attr "type" "*,load,store,fp,fpload,fpstore,mtjmpr,*,*,*,*,*")
7959    (set_attr "length" "4,4,4,4,4,4,4,4,4,8,12,16")])
7960
7961 (define_insn "*movdf_softfloat64"
7962   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,Y,r,cl,r,r,r,r,*h")
7963         (match_operand:DF 1 "input_operand" "Y,r,r,r,h,G,H,F,0"))]
7964   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
7965    && (gpc_reg_operand (operands[0], DFmode)
7966        || gpc_reg_operand (operands[1], DFmode))"
7967   "@
7968    ld%U1%X1 %0,%1
7969    std%U0%X0 %1,%0
7970    mr %0,%1
7971    mt%0 %1
7972    mf%1 %0
7973    #
7974    #
7975    #
7976    {cror 0,0,0|nop}"
7977   [(set_attr "type" "load,store,*,*,*,*,*,*,*")
7978    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
7979 \f
7980 (define_expand "movtf"
7981   [(set (match_operand:TF 0 "general_operand" "")
7982         (match_operand:TF 1 "any_operand" ""))]
7983   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
7984    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
7985   "{ rs6000_emit_move (operands[0], operands[1], TFmode); DONE; }")
7986
7987 ; It's important to list the o->f and f->o moves before f->f because
7988 ; otherwise reload, given m->f, will try to pick f->f and reload it,
7989 ; which doesn't make progress.  Likewise r->Y must be before r->r.
7990 (define_insn_and_split "*movtf_internal"
7991   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,f,r,Y,r")
7992         (match_operand:TF 1 "input_operand"         "f,o,f,YGHF,r,r"))]
7993   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
7994    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
7995    && (gpc_reg_operand (operands[0], TFmode)
7996        || gpc_reg_operand (operands[1], TFmode))"
7997   "#"
7998   "&& reload_completed"
7999   [(pc)]
8000 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
8001   [(set_attr "length" "8,8,8,20,20,16")])
8002
8003 (define_expand "extenddftf2"
8004   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
8005                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
8006               (use (match_dup 2))])]
8007   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8008    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8009 {
8010   operands[2] = CONST0_RTX (DFmode);
8011 })
8012
8013 (define_insn_and_split "*extenddftf2_internal"
8014   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,&f,r")
8015        (float_extend:TF (match_operand:DF 1 "input_operand" "fr,mf,mf,rmGHF")))
8016    (use (match_operand:DF 2 "zero_reg_mem_operand" "rf,m,f,n"))]
8017   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8018    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8019   "#"
8020   "&& reload_completed"
8021   [(pc)]
8022 {
8023   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8024   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8025   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
8026                   operands[1]);
8027   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
8028                   operands[2]);
8029   DONE;
8030 })
8031
8032 (define_expand "extendsftf2"
8033   [(set (match_operand:TF 0 "nonimmediate_operand" "")
8034         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
8035   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8036    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8037 {
8038   rtx tmp = gen_reg_rtx (DFmode);
8039   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
8040   emit_insn (gen_extenddftf2 (operands[0], tmp));
8041   DONE;
8042 })
8043
8044 (define_expand "trunctfdf2"
8045   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8046         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))]
8047   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8048    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8049   "")
8050
8051 (define_insn_and_split "trunctfdf2_internal1"
8052   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,?f")
8053         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "0,f")))]
8054   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN) && !TARGET_XL_COMPAT
8055    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8056   "@
8057    #
8058    fmr %0,%1"
8059   "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
8060   [(const_int 0)]
8061 {
8062   emit_note (NOTE_INSN_DELETED);
8063   DONE;
8064 }
8065   [(set_attr "type" "fp")])
8066
8067 (define_insn "trunctfdf2_internal2"
8068   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8069         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8070   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN) && TARGET_XL_COMPAT
8071    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8072   "fadd %0,%1,%L1"
8073   [(set_attr "type" "fp")])
8074
8075 (define_insn_and_split "trunctfsf2"
8076   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
8077         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "f")))
8078    (clobber (match_scratch:DF 2 "=f"))]
8079   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8080    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8081   "#"
8082   "&& reload_completed"
8083   [(set (match_dup 2)
8084         (float_truncate:DF (match_dup 1)))
8085    (set (match_dup 0)
8086         (float_truncate:SF (match_dup 2)))]
8087   "")
8088
8089 (define_expand "floatsitf2"
8090   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8091         (float:TF (match_operand:SI 1 "gpc_reg_operand" "r")))]
8092   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8093    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8094 {
8095   rtx tmp = gen_reg_rtx (DFmode);
8096   expand_float (tmp, operands[1], false);
8097   emit_insn (gen_extenddftf2 (operands[0], tmp));
8098   DONE;
8099 })
8100
8101 ; fadd, but rounding towards zero.
8102 ; This is probably not the optimal code sequence.
8103 (define_insn "fix_trunc_helper"
8104   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8105         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "f")]
8106                    UNSPEC_FIX_TRUNC_TF))
8107    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&f"))]
8108   "TARGET_HARD_FLOAT && TARGET_FPRS"
8109   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
8110   [(set_attr "type" "fp")
8111    (set_attr "length" "20")])
8112
8113 (define_expand "fix_trunctfsi2"
8114   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
8115                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
8116               (clobber (match_dup 2))
8117               (clobber (match_dup 3))
8118               (clobber (match_dup 4))
8119               (clobber (match_dup 5))])]
8120   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8121    && (TARGET_POWER2 || TARGET_POWERPC)
8122    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8123 {
8124   operands[2] = gen_reg_rtx (DFmode);
8125   operands[3] = gen_reg_rtx (DFmode);
8126   operands[4] = gen_reg_rtx (DImode);
8127   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
8128 })
8129
8130 (define_insn_and_split "*fix_trunctfsi2_internal"
8131   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8132         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "f")))
8133    (clobber (match_operand:DF 2 "gpc_reg_operand" "=f"))
8134    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&f"))
8135    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))
8136    (clobber (match_operand:DI 5 "memory_operand" "=o"))]
8137   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8138    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8139   "#"
8140   "&& (!no_new_pseudos || offsettable_nonstrict_memref_p (operands[5]))"
8141   [(pc)]
8142 {
8143   rtx lowword;
8144   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
8145
8146   gcc_assert (MEM_P (operands[5]));
8147   lowword = adjust_address (operands[5], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
8148
8149   emit_insn (gen_fctiwz (operands[4], operands[2]));
8150   emit_move_insn (operands[5], operands[4]);
8151   emit_move_insn (operands[0], lowword);
8152   DONE;
8153 })
8154
8155 (define_insn "negtf2"
8156   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8157         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8158   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8159    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8160   "*
8161 {
8162   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8163     return \"fneg %L0,%L1\;fneg %0,%1\";
8164   else
8165     return \"fneg %0,%1\;fneg %L0,%L1\";
8166 }"
8167   [(set_attr "type" "fp")
8168    (set_attr "length" "8")])
8169
8170 (define_expand "abstf2"
8171   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8172         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8173   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8174    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8175   "
8176 {
8177   rtx label = gen_label_rtx ();
8178   emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
8179   emit_label (label);
8180   DONE;
8181 }")
8182
8183 (define_expand "abstf2_internal"
8184   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8185         (match_operand:TF 1 "gpc_reg_operand" "f"))
8186    (set (match_dup 3) (match_dup 5))
8187    (set (match_dup 5) (abs:DF (match_dup 5)))
8188    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
8189    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
8190                            (label_ref (match_operand 2 "" ""))
8191                            (pc)))
8192    (set (match_dup 6) (neg:DF (match_dup 6)))]
8193   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8194    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8195   "
8196 {
8197   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8198   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8199   operands[3] = gen_reg_rtx (DFmode);
8200   operands[4] = gen_reg_rtx (CCFPmode);
8201   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
8202   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
8203 }")
8204 \f
8205 ;; Next come the multi-word integer load and store and the load and store
8206 ;; multiple insns.
8207 (define_expand "movdi"
8208   [(set (match_operand:DI 0 "general_operand" "")
8209         (match_operand:DI 1 "any_operand" ""))]
8210   ""
8211   "{ rs6000_emit_move (operands[0], operands[1], DImode); DONE; }")
8212
8213 ; List r->r after r->"o<>", otherwise reload will try to reload a
8214 ; non-offsettable address by using r->r which won't make progress.
8215 (define_insn "*movdi_internal32"
8216   [(set (match_operand:DI 0 "nonimmediate_operand" "=o<>,r,r,*f,*f,m,r")
8217         (match_operand:DI 1 "input_operand" "r,r,m,f,m,f,IJKnGHF"))]
8218   "! TARGET_POWERPC64
8219    && (gpc_reg_operand (operands[0], DImode)
8220        || gpc_reg_operand (operands[1], DImode))"
8221   "@
8222    #
8223    #
8224    #
8225    fmr %0,%1
8226    lfd%U1%X1 %0,%1
8227    stfd%U0%X0 %1,%0
8228    #"
8229   [(set_attr "type" "load,*,store,fp,fpload,fpstore,*")])
8230
8231 (define_split
8232   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8233         (match_operand:DI 1 "const_int_operand" ""))]
8234   "! TARGET_POWERPC64 && reload_completed"
8235   [(set (match_dup 2) (match_dup 4))
8236    (set (match_dup 3) (match_dup 1))]
8237   "
8238 {
8239   HOST_WIDE_INT value = INTVAL (operands[1]);
8240   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8241                                        DImode);
8242   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8243                                        DImode);
8244 #if HOST_BITS_PER_WIDE_INT == 32
8245   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8246 #else
8247   operands[4] = GEN_INT (value >> 32);
8248   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8249 #endif
8250 }")
8251
8252 (define_split
8253   [(set (match_operand:DI 0 "nonimmediate_operand" "")
8254         (match_operand:DI 1 "input_operand" ""))]
8255   "reload_completed && !TARGET_POWERPC64
8256    && gpr_or_gpr_p (operands[0], operands[1])"
8257   [(pc)]
8258 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8259
8260 (define_insn "*movdi_internal64"
8261   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,*f,*f,m,r,*h,*h")
8262         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,f,m,f,*h,r,0"))]
8263   "TARGET_POWERPC64
8264    && (gpc_reg_operand (operands[0], DImode)
8265        || gpc_reg_operand (operands[1], DImode))"
8266   "@
8267    mr %0,%1
8268    ld%U1%X1 %0,%1
8269    std%U0%X0 %1,%0
8270    li %0,%1
8271    lis %0,%v1
8272    #
8273    {cal|la} %0,%a1
8274    fmr %0,%1
8275    lfd%U1%X1 %0,%1
8276    stfd%U0%X0 %1,%0
8277    mf%1 %0
8278    mt%0 %1
8279    {cror 0,0,0|nop}"
8280   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*")
8281    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4")])
8282
8283 ;; immediate value valid for a single instruction hiding in a const_double
8284 (define_insn ""
8285   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8286         (match_operand:DI 1 "const_double_operand" "F"))]
8287   "HOST_BITS_PER_WIDE_INT == 32 && TARGET_POWERPC64
8288    && GET_CODE (operands[1]) == CONST_DOUBLE
8289    && num_insns_constant (operands[1], DImode) == 1"
8290   "*
8291 {
8292   return ((unsigned HOST_WIDE_INT)
8293           (CONST_DOUBLE_LOW (operands[1]) + 0x8000) < 0x10000)
8294          ? \"li %0,%1\" : \"lis %0,%v1\";
8295 }")
8296
8297 ;; Generate all one-bits and clear left or right.
8298 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
8299 (define_split
8300   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8301         (match_operand:DI 1 "mask64_operand" ""))]
8302   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8303   [(set (match_dup 0) (const_int -1))
8304    (set (match_dup 0)
8305         (and:DI (rotate:DI (match_dup 0)
8306                            (const_int 0))
8307                 (match_dup 1)))]
8308   "")
8309
8310 ;; Split a load of a large constant into the appropriate five-instruction
8311 ;; sequence.  Handle anything in a constant number of insns.
8312 ;; When non-easy constants can go in the TOC, this should use
8313 ;; easy_fp_constant predicate.
8314 (define_split
8315   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8316         (match_operand:DI 1 "const_int_operand" ""))]
8317   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8318   [(set (match_dup 0) (match_dup 2))
8319    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8320   "
8321 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8322
8323   if (tem == operands[0])
8324     DONE;
8325   else
8326     FAIL;
8327 }")
8328
8329 (define_split
8330   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8331         (match_operand:DI 1 "const_double_operand" ""))]
8332   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8333   [(set (match_dup 0) (match_dup 2))
8334    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8335   "
8336 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8337
8338   if (tem == operands[0])
8339     DONE;
8340   else
8341     FAIL;
8342 }")
8343
8344 (define_insn "*movdi_internal2"
8345   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
8346         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "0,r,r")
8347                     (const_int 0)))
8348    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
8349   "TARGET_64BIT"
8350   "@
8351    cmpdi %2,%0,0
8352    mr. %0,%1
8353    #"
8354   [(set_attr "type" "cmp,compare,cmp")
8355    (set_attr "length" "4,4,8")])
8356
8357 (define_split
8358   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
8359         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "")
8360                     (const_int 0)))
8361    (set (match_operand:DI 0 "gpc_reg_operand" "") (match_dup 1))]
8362   "TARGET_POWERPC64 && reload_completed"
8363   [(set (match_dup 0) (match_dup 1))
8364    (set (match_dup 2)
8365         (compare:CC (match_dup 0)
8366                     (const_int 0)))]
8367   "")
8368 \f
8369 ;; TImode is similar, except that we usually want to compute the address into
8370 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
8371 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
8372 (define_expand "movti"
8373   [(parallel [(set (match_operand:TI 0 "general_operand" "")
8374                    (match_operand:TI 1 "general_operand" ""))
8375               (clobber (scratch:SI))])]
8376   ""
8377   "{ rs6000_emit_move (operands[0], operands[1], TImode); DONE; }")
8378
8379 ;; We say that MQ is clobbered in the last alternative because the first
8380 ;; alternative would never get used otherwise since it would need a reload
8381 ;; while the 2nd alternative would not.  We put memory cases first so they
8382 ;; are preferred.  Otherwise, we'd try to reload the output instead of
8383 ;; giving the SCRATCH mq.
8384
8385 (define_insn "*movti_power"
8386   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r,r")
8387         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))
8388    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X,X"))]
8389   "TARGET_POWER && ! TARGET_POWERPC64
8390    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8391   "*
8392 {
8393   switch (which_alternative)
8394     {
8395     default:
8396       gcc_unreachable ();
8397
8398     case 0:
8399       if (TARGET_STRING)
8400         return \"{stsi|stswi} %1,%P0,16\";
8401     case 1:
8402     case 2:
8403       return \"#\";
8404     case 3:
8405       /* If the address is not used in the output, we can use lsi.  Otherwise,
8406          fall through to generating four loads.  */
8407       if (TARGET_STRING
8408           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8409         return \"{lsi|lswi} %0,%P1,16\";
8410       /* ... fall through ...  */
8411     case 4:
8412     case 5:
8413       return \"#\";
8414     }
8415 }"
8416   [(set_attr "type" "store,store,*,load,load,*")])
8417
8418 (define_insn "*movti_string"
8419   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,o<>,????r,????r,????r,r")
8420         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))]
8421   "! TARGET_POWER && ! TARGET_POWERPC64
8422    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8423   "*
8424 {
8425   switch (which_alternative)
8426     {
8427     default:
8428       gcc_unreachable ();
8429     case 0:
8430       if (TARGET_STRING)
8431         return \"{stsi|stswi} %1,%P0,16\";
8432     case 1:
8433     case 2:
8434       return \"#\";
8435     case 3:
8436       /* If the address is not used in the output, we can use lsi.  Otherwise,
8437          fall through to generating four loads.  */
8438       if (TARGET_STRING
8439           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8440         return \"{lsi|lswi} %0,%P1,16\";
8441       /* ... fall through ...  */
8442     case 4:
8443     case 5:
8444       return \"#\";
8445     }
8446 }"
8447   [(set_attr "type" "store,store,*,load,load,*")])
8448
8449 (define_insn "*movti_ppc64"
8450   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,o<>,r")
8451         (match_operand:TI 1 "input_operand" "r,r,m"))]
8452   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
8453    || gpc_reg_operand (operands[1], TImode))"
8454   "#"
8455   [(set_attr "type" "*,load,store")])
8456
8457 (define_split
8458   [(set (match_operand:TI 0 "gpc_reg_operand" "")
8459         (match_operand:TI 1 "const_double_operand" ""))]
8460   "TARGET_POWERPC64"
8461   [(set (match_dup 2) (match_dup 4))
8462    (set (match_dup 3) (match_dup 5))]
8463   "
8464 {
8465   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8466                                        TImode);
8467   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8468                                        TImode);
8469   if (GET_CODE (operands[1]) == CONST_DOUBLE)
8470     {
8471       operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
8472       operands[5] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
8473     }
8474   else if (GET_CODE (operands[1]) == CONST_INT)
8475     {
8476       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
8477       operands[5] = operands[1];
8478     }
8479   else
8480     FAIL;
8481 }")
8482
8483 (define_split
8484   [(set (match_operand:TI 0 "nonimmediate_operand" "")
8485         (match_operand:TI 1 "input_operand" ""))]
8486   "reload_completed
8487    && gpr_or_gpr_p (operands[0], operands[1])"
8488   [(pc)]
8489 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8490 \f
8491 (define_expand "load_multiple"
8492   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8493                           (match_operand:SI 1 "" ""))
8494                      (use (match_operand:SI 2 "" ""))])]
8495   "TARGET_STRING && !TARGET_POWERPC64"
8496   "
8497 {
8498   int regno;
8499   int count;
8500   rtx op1;
8501   int i;
8502
8503   /* Support only loading a constant number of fixed-point registers from
8504      memory and only bother with this if more than two; the machine
8505      doesn't support more than eight.  */
8506   if (GET_CODE (operands[2]) != CONST_INT
8507       || INTVAL (operands[2]) <= 2
8508       || INTVAL (operands[2]) > 8
8509       || GET_CODE (operands[1]) != MEM
8510       || GET_CODE (operands[0]) != REG
8511       || REGNO (operands[0]) >= 32)
8512     FAIL;
8513
8514   count = INTVAL (operands[2]);
8515   regno = REGNO (operands[0]);
8516
8517   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
8518   op1 = replace_equiv_address (operands[1],
8519                                force_reg (SImode, XEXP (operands[1], 0)));
8520
8521   for (i = 0; i < count; i++)
8522     XVECEXP (operands[3], 0, i)
8523       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
8524                      adjust_address_nv (op1, SImode, i * 4));
8525 }")
8526
8527 (define_insn "*ldmsi8"
8528   [(match_parallel 0 "load_multiple_operation"
8529     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8530           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8531      (set (match_operand:SI 3 "gpc_reg_operand" "")
8532           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8533      (set (match_operand:SI 4 "gpc_reg_operand" "")
8534           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8535      (set (match_operand:SI 5 "gpc_reg_operand" "")
8536           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8537      (set (match_operand:SI 6 "gpc_reg_operand" "")
8538           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8539      (set (match_operand:SI 7 "gpc_reg_operand" "")
8540           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8541      (set (match_operand:SI 8 "gpc_reg_operand" "")
8542           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
8543      (set (match_operand:SI 9 "gpc_reg_operand" "")
8544           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
8545   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
8546   "*
8547 { return rs6000_output_load_multiple (operands); }"
8548   [(set_attr "type" "load")
8549    (set_attr "length" "32")])
8550
8551 (define_insn "*ldmsi7"
8552   [(match_parallel 0 "load_multiple_operation"
8553     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8554           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8555      (set (match_operand:SI 3 "gpc_reg_operand" "")
8556           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8557      (set (match_operand:SI 4 "gpc_reg_operand" "")
8558           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8559      (set (match_operand:SI 5 "gpc_reg_operand" "")
8560           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8561      (set (match_operand:SI 6 "gpc_reg_operand" "")
8562           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8563      (set (match_operand:SI 7 "gpc_reg_operand" "")
8564           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8565      (set (match_operand:SI 8 "gpc_reg_operand" "")
8566           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
8567   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
8568   "*
8569 { return rs6000_output_load_multiple (operands); }"
8570   [(set_attr "type" "load")
8571    (set_attr "length" "32")])
8572
8573 (define_insn "*ldmsi6"
8574   [(match_parallel 0 "load_multiple_operation"
8575     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8576           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8577      (set (match_operand:SI 3 "gpc_reg_operand" "")
8578           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8579      (set (match_operand:SI 4 "gpc_reg_operand" "")
8580           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8581      (set (match_operand:SI 5 "gpc_reg_operand" "")
8582           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8583      (set (match_operand:SI 6 "gpc_reg_operand" "")
8584           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8585      (set (match_operand:SI 7 "gpc_reg_operand" "")
8586           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
8587   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
8588   "*
8589 { return rs6000_output_load_multiple (operands); }"
8590   [(set_attr "type" "load")
8591    (set_attr "length" "32")])
8592
8593 (define_insn "*ldmsi5"
8594   [(match_parallel 0 "load_multiple_operation"
8595     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8596           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8597      (set (match_operand:SI 3 "gpc_reg_operand" "")
8598           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8599      (set (match_operand:SI 4 "gpc_reg_operand" "")
8600           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8601      (set (match_operand:SI 5 "gpc_reg_operand" "")
8602           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8603      (set (match_operand:SI 6 "gpc_reg_operand" "")
8604           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
8605   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
8606   "*
8607 { return rs6000_output_load_multiple (operands); }"
8608   [(set_attr "type" "load")
8609    (set_attr "length" "32")])
8610
8611 (define_insn "*ldmsi4"
8612   [(match_parallel 0 "load_multiple_operation"
8613     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8614           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8615      (set (match_operand:SI 3 "gpc_reg_operand" "")
8616           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8617      (set (match_operand:SI 4 "gpc_reg_operand" "")
8618           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8619      (set (match_operand:SI 5 "gpc_reg_operand" "")
8620           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
8621   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
8622   "*
8623 { return rs6000_output_load_multiple (operands); }"
8624   [(set_attr "type" "load")
8625    (set_attr "length" "32")])
8626
8627 (define_insn "*ldmsi3"
8628   [(match_parallel 0 "load_multiple_operation"
8629     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8630           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8631      (set (match_operand:SI 3 "gpc_reg_operand" "")
8632           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8633      (set (match_operand:SI 4 "gpc_reg_operand" "")
8634           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
8635   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
8636   "*
8637 { return rs6000_output_load_multiple (operands); }"
8638   [(set_attr "type" "load")
8639    (set_attr "length" "32")])
8640
8641 (define_expand "store_multiple"
8642   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8643                           (match_operand:SI 1 "" ""))
8644                      (clobber (scratch:SI))
8645                      (use (match_operand:SI 2 "" ""))])]
8646   "TARGET_STRING && !TARGET_POWERPC64"
8647   "
8648 {
8649   int regno;
8650   int count;
8651   rtx to;
8652   rtx op0;
8653   int i;
8654
8655   /* Support only storing a constant number of fixed-point registers to
8656      memory and only bother with this if more than two; the machine
8657      doesn't support more than eight.  */
8658   if (GET_CODE (operands[2]) != CONST_INT
8659       || INTVAL (operands[2]) <= 2
8660       || INTVAL (operands[2]) > 8
8661       || GET_CODE (operands[0]) != MEM
8662       || GET_CODE (operands[1]) != REG
8663       || REGNO (operands[1]) >= 32)
8664     FAIL;
8665
8666   count = INTVAL (operands[2]);
8667   regno = REGNO (operands[1]);
8668
8669   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
8670   to = force_reg (SImode, XEXP (operands[0], 0));
8671   op0 = replace_equiv_address (operands[0], to);
8672
8673   XVECEXP (operands[3], 0, 0)
8674     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
8675   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
8676                                                  gen_rtx_SCRATCH (SImode));
8677
8678   for (i = 1; i < count; i++)
8679     XVECEXP (operands[3], 0, i + 1)
8680       = gen_rtx_SET (VOIDmode,
8681                      adjust_address_nv (op0, SImode, i * 4),
8682                      gen_rtx_REG (SImode, regno + i));
8683 }")
8684
8685 (define_insn "*store_multiple_power"
8686   [(match_parallel 0 "store_multiple_operation"
8687                    [(set (match_operand:SI 1 "indirect_operand" "=Q")
8688                          (match_operand:SI 2 "gpc_reg_operand" "r"))
8689                     (clobber (match_scratch:SI 3 "=q"))])]
8690   "TARGET_STRING && TARGET_POWER"
8691   "{stsi|stswi} %2,%P1,%O0"
8692   [(set_attr "type" "store")])
8693
8694 (define_insn "*stmsi8"
8695   [(match_parallel 0 "store_multiple_operation"
8696     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8697           (match_operand:SI 2 "gpc_reg_operand" "r"))
8698      (clobber (match_scratch:SI 3 "X"))
8699      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8700           (match_operand:SI 4 "gpc_reg_operand" "r"))
8701      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8702           (match_operand:SI 5 "gpc_reg_operand" "r"))
8703      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8704           (match_operand:SI 6 "gpc_reg_operand" "r"))
8705      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8706           (match_operand:SI 7 "gpc_reg_operand" "r"))
8707      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8708           (match_operand:SI 8 "gpc_reg_operand" "r"))
8709      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
8710           (match_operand:SI 9 "gpc_reg_operand" "r"))
8711      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
8712           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
8713   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 9"
8714   "{stsi|stswi} %2,%1,%O0"
8715   [(set_attr "type" "store")])
8716
8717 (define_insn "*stmsi7"
8718   [(match_parallel 0 "store_multiple_operation"
8719     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8720           (match_operand:SI 2 "gpc_reg_operand" "r"))
8721      (clobber (match_scratch:SI 3 "X"))
8722      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8723           (match_operand:SI 4 "gpc_reg_operand" "r"))
8724      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8725           (match_operand:SI 5 "gpc_reg_operand" "r"))
8726      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8727           (match_operand:SI 6 "gpc_reg_operand" "r"))
8728      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8729           (match_operand:SI 7 "gpc_reg_operand" "r"))
8730      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8731           (match_operand:SI 8 "gpc_reg_operand" "r"))
8732      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
8733           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
8734   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 8"
8735   "{stsi|stswi} %2,%1,%O0"
8736   [(set_attr "type" "store")])
8737
8738 (define_insn "*stmsi6"
8739   [(match_parallel 0 "store_multiple_operation"
8740     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8741           (match_operand:SI 2 "gpc_reg_operand" "r"))
8742      (clobber (match_scratch:SI 3 "X"))
8743      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8744           (match_operand:SI 4 "gpc_reg_operand" "r"))
8745      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8746           (match_operand:SI 5 "gpc_reg_operand" "r"))
8747      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8748           (match_operand:SI 6 "gpc_reg_operand" "r"))
8749      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8750           (match_operand:SI 7 "gpc_reg_operand" "r"))
8751      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8752           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
8753   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 7"
8754   "{stsi|stswi} %2,%1,%O0"
8755   [(set_attr "type" "store")])
8756
8757 (define_insn "*stmsi5"
8758   [(match_parallel 0 "store_multiple_operation"
8759     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8760           (match_operand:SI 2 "gpc_reg_operand" "r"))
8761      (clobber (match_scratch:SI 3 "X"))
8762      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8763           (match_operand:SI 4 "gpc_reg_operand" "r"))
8764      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8765           (match_operand:SI 5 "gpc_reg_operand" "r"))
8766      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8767           (match_operand:SI 6 "gpc_reg_operand" "r"))
8768      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8769           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
8770   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 6"
8771   "{stsi|stswi} %2,%1,%O0"
8772   [(set_attr "type" "store")])
8773
8774 (define_insn "*stmsi4"
8775   [(match_parallel 0 "store_multiple_operation"
8776     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8777           (match_operand:SI 2 "gpc_reg_operand" "r"))
8778      (clobber (match_scratch:SI 3 "X"))
8779      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8780           (match_operand:SI 4 "gpc_reg_operand" "r"))
8781      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8782           (match_operand:SI 5 "gpc_reg_operand" "r"))
8783      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8784           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
8785   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 5"
8786   "{stsi|stswi} %2,%1,%O0"
8787   [(set_attr "type" "store")])
8788
8789 (define_insn "*stmsi3"
8790   [(match_parallel 0 "store_multiple_operation"
8791     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8792           (match_operand:SI 2 "gpc_reg_operand" "r"))
8793      (clobber (match_scratch:SI 3 "X"))
8794      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8795           (match_operand:SI 4 "gpc_reg_operand" "r"))
8796      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8797           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
8798   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 4"
8799   "{stsi|stswi} %2,%1,%O0"
8800   [(set_attr "type" "store")])
8801 \f
8802 (define_expand "clrmemsi"
8803   [(parallel [(set (match_operand:BLK 0 "" "")
8804                    (const_int 0))
8805               (use (match_operand:SI 1 "" ""))
8806               (use (match_operand:SI 2 "" ""))])]
8807   ""
8808   "
8809 {
8810   if (expand_block_clear (operands))
8811     DONE;
8812   else
8813     FAIL;
8814 }")
8815
8816 ;; String/block move insn.
8817 ;; Argument 0 is the destination
8818 ;; Argument 1 is the source
8819 ;; Argument 2 is the length
8820 ;; Argument 3 is the alignment
8821
8822 (define_expand "movmemsi"
8823   [(parallel [(set (match_operand:BLK 0 "" "")
8824                    (match_operand:BLK 1 "" ""))
8825               (use (match_operand:SI 2 "" ""))
8826               (use (match_operand:SI 3 "" ""))])]
8827   ""
8828   "
8829 {
8830   if (expand_block_move (operands))
8831     DONE;
8832   else
8833     FAIL;
8834 }")
8835
8836 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
8837 ;; register allocator doesn't have a clue about allocating 8 word registers.
8838 ;; rD/rS = r5 is preferred, efficient form.
8839 (define_expand "movmemsi_8reg"
8840   [(parallel [(set (match_operand 0 "" "")
8841                    (match_operand 1 "" ""))
8842               (use (match_operand 2 "" ""))
8843               (use (match_operand 3 "" ""))
8844               (clobber (reg:SI  5))
8845               (clobber (reg:SI  6))
8846               (clobber (reg:SI  7))
8847               (clobber (reg:SI  8))
8848               (clobber (reg:SI  9))
8849               (clobber (reg:SI 10))
8850               (clobber (reg:SI 11))
8851               (clobber (reg:SI 12))
8852               (clobber (match_scratch:SI 4 ""))])]
8853   "TARGET_STRING"
8854   "")
8855
8856 (define_insn ""
8857   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
8858         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
8859    (use (match_operand:SI 2 "immediate_operand" "i"))
8860    (use (match_operand:SI 3 "immediate_operand" "i"))
8861    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
8862    (clobber (reg:SI  6))
8863    (clobber (reg:SI  7))
8864    (clobber (reg:SI  8))
8865    (clobber (reg:SI  9))
8866    (clobber (reg:SI 10))
8867    (clobber (reg:SI 11))
8868    (clobber (reg:SI 12))
8869    (clobber (match_scratch:SI 5 "=q"))]
8870   "TARGET_STRING && TARGET_POWER
8871    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
8872        || INTVAL (operands[2]) == 0)
8873    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
8874    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
8875    && REGNO (operands[4]) == 5"
8876   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
8877   [(set_attr "type" "load")
8878    (set_attr "length" "8")])
8879
8880 (define_insn ""
8881   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
8882         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
8883    (use (match_operand:SI 2 "immediate_operand" "i"))
8884    (use (match_operand:SI 3 "immediate_operand" "i"))
8885    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
8886    (clobber (reg:SI  6))
8887    (clobber (reg:SI  7))
8888    (clobber (reg:SI  8))
8889    (clobber (reg:SI  9))
8890    (clobber (reg:SI 10))
8891    (clobber (reg:SI 11))
8892    (clobber (reg:SI 12))
8893    (clobber (match_scratch:SI 5 "X"))]
8894   "TARGET_STRING && ! TARGET_POWER
8895    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
8896        || INTVAL (operands[2]) == 0)
8897    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
8898    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
8899    && REGNO (operands[4]) == 5"
8900   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
8901   [(set_attr "type" "load")
8902    (set_attr "length" "8")])
8903
8904 (define_insn ""
8905   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
8906         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
8907    (use (match_operand:SI 2 "immediate_operand" "i"))
8908    (use (match_operand:SI 3 "immediate_operand" "i"))
8909    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
8910    (clobber (reg:SI  6))
8911    (clobber (reg:SI  7))
8912    (clobber (reg:SI  8))
8913    (clobber (reg:SI  9))
8914    (clobber (reg:SI 10))
8915    (clobber (reg:SI 11))
8916    (clobber (reg:SI 12))
8917    (clobber (match_scratch:SI 5 "X"))]
8918   "TARGET_STRING && TARGET_POWERPC64
8919    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
8920        || INTVAL (operands[2]) == 0)
8921    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
8922    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
8923    && REGNO (operands[4]) == 5"
8924   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
8925   [(set_attr "type" "load")
8926    (set_attr "length" "8")])
8927
8928 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
8929 ;; register allocator doesn't have a clue about allocating 6 word registers.
8930 ;; rD/rS = r5 is preferred, efficient form.
8931 (define_expand "movmemsi_6reg"
8932   [(parallel [(set (match_operand 0 "" "")
8933                    (match_operand 1 "" ""))
8934               (use (match_operand 2 "" ""))
8935               (use (match_operand 3 "" ""))
8936               (clobber (reg:SI  5))
8937               (clobber (reg:SI  6))
8938               (clobber (reg:SI  7))
8939               (clobber (reg:SI  8))
8940               (clobber (reg:SI  9))
8941               (clobber (reg:SI 10))
8942               (clobber (match_scratch:SI 4 ""))])]
8943   "TARGET_STRING"
8944   "")
8945
8946 (define_insn ""
8947   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
8948         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
8949    (use (match_operand:SI 2 "immediate_operand" "i"))
8950    (use (match_operand:SI 3 "immediate_operand" "i"))
8951    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
8952    (clobber (reg:SI  6))
8953    (clobber (reg:SI  7))
8954    (clobber (reg:SI  8))
8955    (clobber (reg:SI  9))
8956    (clobber (reg:SI 10))
8957    (clobber (match_scratch:SI 5 "=q"))]
8958   "TARGET_STRING && TARGET_POWER
8959    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
8960    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
8961    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
8962    && REGNO (operands[4]) == 5"
8963   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
8964   [(set_attr "type" "load")
8965    (set_attr "length" "8")])
8966
8967 (define_insn ""
8968   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
8969         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
8970    (use (match_operand:SI 2 "immediate_operand" "i"))
8971    (use (match_operand:SI 3 "immediate_operand" "i"))
8972    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
8973    (clobber (reg:SI  6))
8974    (clobber (reg:SI  7))
8975    (clobber (reg:SI  8))
8976    (clobber (reg:SI  9))
8977    (clobber (reg:SI 10))
8978    (clobber (match_scratch:SI 5 "X"))]
8979   "TARGET_STRING && ! TARGET_POWER
8980    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
8981    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
8982    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
8983    && REGNO (operands[4]) == 5"
8984   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
8985   [(set_attr "type" "load")
8986    (set_attr "length" "8")])
8987
8988 (define_insn ""
8989   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
8990         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
8991    (use (match_operand:SI 2 "immediate_operand" "i"))
8992    (use (match_operand:SI 3 "immediate_operand" "i"))
8993    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
8994    (clobber (reg:SI  6))
8995    (clobber (reg:SI  7))
8996    (clobber (reg:SI  8))
8997    (clobber (reg:SI  9))
8998    (clobber (reg:SI 10))
8999    (clobber (match_scratch:SI 5 "X"))]
9000   "TARGET_STRING && TARGET_POWERPC64
9001    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9002    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9003    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9004    && REGNO (operands[4]) == 5"
9005   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9006   [(set_attr "type" "load")
9007    (set_attr "length" "8")])
9008
9009 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
9010 ;; problems with TImode.
9011 ;; rD/rS = r5 is preferred, efficient form.
9012 (define_expand "movmemsi_4reg"
9013   [(parallel [(set (match_operand 0 "" "")
9014                    (match_operand 1 "" ""))
9015               (use (match_operand 2 "" ""))
9016               (use (match_operand 3 "" ""))
9017               (clobber (reg:SI 5))
9018               (clobber (reg:SI 6))
9019               (clobber (reg:SI 7))
9020               (clobber (reg:SI 8))
9021               (clobber (match_scratch:SI 4 ""))])]
9022   "TARGET_STRING"
9023   "")
9024
9025 (define_insn ""
9026   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9027         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9028    (use (match_operand:SI 2 "immediate_operand" "i"))
9029    (use (match_operand:SI 3 "immediate_operand" "i"))
9030    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9031    (clobber (reg:SI 6))
9032    (clobber (reg:SI 7))
9033    (clobber (reg:SI 8))
9034    (clobber (match_scratch:SI 5 "=q"))]
9035   "TARGET_STRING && TARGET_POWER
9036    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9037    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9038    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9039    && REGNO (operands[4]) == 5"
9040   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9041   [(set_attr "type" "load")
9042    (set_attr "length" "8")])
9043
9044 (define_insn ""
9045   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9046         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9047    (use (match_operand:SI 2 "immediate_operand" "i"))
9048    (use (match_operand:SI 3 "immediate_operand" "i"))
9049    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9050    (clobber (reg:SI 6))
9051    (clobber (reg:SI 7))
9052    (clobber (reg:SI 8))
9053    (clobber (match_scratch:SI 5 "X"))]
9054   "TARGET_STRING && ! TARGET_POWER
9055    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9056    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9057    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9058    && REGNO (operands[4]) == 5"
9059   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9060   [(set_attr "type" "load")
9061    (set_attr "length" "8")])
9062
9063 (define_insn ""
9064   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9065         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9066    (use (match_operand:SI 2 "immediate_operand" "i"))
9067    (use (match_operand:SI 3 "immediate_operand" "i"))
9068    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9069    (clobber (reg:SI 6))
9070    (clobber (reg:SI 7))
9071    (clobber (reg:SI 8))
9072    (clobber (match_scratch:SI 5 "X"))]
9073   "TARGET_STRING && TARGET_POWERPC64
9074    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9075    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9076    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9077    && REGNO (operands[4]) == 5"
9078   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9079   [(set_attr "type" "load")
9080    (set_attr "length" "8")])
9081
9082 ;; Move up to 8 bytes at a time.
9083 (define_expand "movmemsi_2reg"
9084   [(parallel [(set (match_operand 0 "" "")
9085                    (match_operand 1 "" ""))
9086               (use (match_operand 2 "" ""))
9087               (use (match_operand 3 "" ""))
9088               (clobber (match_scratch:DI 4 ""))
9089               (clobber (match_scratch:SI 5 ""))])]
9090   "TARGET_STRING && ! TARGET_POWERPC64"
9091   "")
9092
9093 (define_insn ""
9094   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9095         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9096    (use (match_operand:SI 2 "immediate_operand" "i"))
9097    (use (match_operand:SI 3 "immediate_operand" "i"))
9098    (clobber (match_scratch:DI 4 "=&r"))
9099    (clobber (match_scratch:SI 5 "=q"))]
9100   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
9101    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9102   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9103   [(set_attr "type" "load")
9104    (set_attr "length" "8")])
9105
9106 (define_insn ""
9107   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9108         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9109    (use (match_operand:SI 2 "immediate_operand" "i"))
9110    (use (match_operand:SI 3 "immediate_operand" "i"))
9111    (clobber (match_scratch:DI 4 "=&r"))
9112    (clobber (match_scratch:SI 5 "X"))]
9113   "TARGET_STRING && ! TARGET_POWER && ! TARGET_POWERPC64
9114    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9115   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9116   [(set_attr "type" "load")
9117    (set_attr "length" "8")])
9118
9119 ;; Move up to 4 bytes at a time.
9120 (define_expand "movmemsi_1reg"
9121   [(parallel [(set (match_operand 0 "" "")
9122                    (match_operand 1 "" ""))
9123               (use (match_operand 2 "" ""))
9124               (use (match_operand 3 "" ""))
9125               (clobber (match_scratch:SI 4 ""))
9126               (clobber (match_scratch:SI 5 ""))])]
9127   "TARGET_STRING"
9128   "")
9129
9130 (define_insn ""
9131   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9132         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9133    (use (match_operand:SI 2 "immediate_operand" "i"))
9134    (use (match_operand:SI 3 "immediate_operand" "i"))
9135    (clobber (match_scratch:SI 4 "=&r"))
9136    (clobber (match_scratch:SI 5 "=q"))]
9137   "TARGET_STRING && TARGET_POWER
9138    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9139   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9140   [(set_attr "type" "load")
9141    (set_attr "length" "8")])
9142
9143 (define_insn ""
9144   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9145         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9146    (use (match_operand:SI 2 "immediate_operand" "i"))
9147    (use (match_operand:SI 3 "immediate_operand" "i"))
9148    (clobber (match_scratch:SI 4 "=&r"))
9149    (clobber (match_scratch:SI 5 "X"))]
9150   "TARGET_STRING && ! TARGET_POWER
9151    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9152   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9153   [(set_attr "type" "load")
9154    (set_attr "length" "8")])
9155
9156 (define_insn ""
9157   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9158         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9159    (use (match_operand:SI 2 "immediate_operand" "i"))
9160    (use (match_operand:SI 3 "immediate_operand" "i"))
9161    (clobber (match_scratch:SI 4 "=&r"))
9162    (clobber (match_scratch:SI 5 "X"))]
9163   "TARGET_STRING && TARGET_POWERPC64
9164    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9165   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9166   [(set_attr "type" "load")
9167    (set_attr "length" "8")])
9168
9169 \f
9170 ;; Define insns that do load or store with update.  Some of these we can
9171 ;; get by using pre-decrement or pre-increment, but the hardware can also
9172 ;; do cases where the increment is not the size of the object.
9173 ;;
9174 ;; In all these cases, we use operands 0 and 1 for the register being
9175 ;; incremented because those are the operands that local-alloc will
9176 ;; tie and these are the pair most likely to be tieable (and the ones
9177 ;; that will benefit the most).
9178
9179 (define_insn "*movdi_update1"
9180   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
9181         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9182                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
9183    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9184         (plus:DI (match_dup 1) (match_dup 2)))]
9185   "TARGET_POWERPC64 && TARGET_UPDATE"
9186   "@
9187    ldux %3,%0,%2
9188    ldu %3,%2(%0)"
9189   [(set_attr "type" "load_ux,load_u")])
9190
9191 (define_insn "movdi_<mode>_update"
9192   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
9193                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
9194         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
9195    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
9196         (plus:P (match_dup 1) (match_dup 2)))]
9197   "TARGET_POWERPC64 && TARGET_UPDATE"
9198   "@
9199    stdux %3,%0,%2
9200    stdu %3,%2(%0)"
9201   [(set_attr "type" "store_ux,store_u")])
9202
9203 (define_insn "*movsi_update1"
9204   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9205         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9206                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9207    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9208         (plus:SI (match_dup 1) (match_dup 2)))]
9209   "TARGET_UPDATE"
9210   "@
9211    {lux|lwzux} %3,%0,%2
9212    {lu|lwzu} %3,%2(%0)"
9213   [(set_attr "type" "load_ux,load_u")])
9214
9215 (define_insn "*movsi_update2"
9216   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
9217         (sign_extend:DI
9218          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
9219                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
9220    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
9221         (plus:DI (match_dup 1) (match_dup 2)))]
9222   "TARGET_POWERPC64"
9223   "lwaux %3,%0,%2"
9224   [(set_attr "type" "load_ext_ux")])
9225
9226 (define_insn "movsi_update"
9227   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9228                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9229         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
9230    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9231         (plus:SI (match_dup 1) (match_dup 2)))]
9232   "TARGET_UPDATE"
9233   "@
9234    {stux|stwux} %3,%0,%2
9235    {stu|stwu} %3,%2(%0)"
9236   [(set_attr "type" "store_ux,store_u")])
9237
9238 (define_insn "*movhi_update1"
9239   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
9240         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9241                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9242    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9243         (plus:SI (match_dup 1) (match_dup 2)))]
9244   "TARGET_UPDATE"
9245   "@
9246    lhzux %3,%0,%2
9247    lhzu %3,%2(%0)"
9248   [(set_attr "type" "load_ux,load_u")])
9249
9250 (define_insn "*movhi_update2"
9251   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9252         (zero_extend:SI
9253          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9254                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9255    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9256         (plus:SI (match_dup 1) (match_dup 2)))]
9257   "TARGET_UPDATE"
9258   "@
9259    lhzux %3,%0,%2
9260    lhzu %3,%2(%0)"
9261   [(set_attr "type" "load_ux,load_u")])
9262
9263 (define_insn "*movhi_update3"
9264   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9265         (sign_extend:SI
9266          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9267                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9268    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9269         (plus:SI (match_dup 1) (match_dup 2)))]
9270   "TARGET_UPDATE"
9271   "@
9272    lhaux %3,%0,%2
9273    lhau %3,%2(%0)"
9274   [(set_attr "type" "load_ext_ux,load_ext_u")])
9275
9276 (define_insn "*movhi_update4"
9277   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9278                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9279         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
9280    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9281         (plus:SI (match_dup 1) (match_dup 2)))]
9282   "TARGET_UPDATE"
9283   "@
9284    sthux %3,%0,%2
9285    sthu %3,%2(%0)"
9286   [(set_attr "type" "store_ux,store_u")])
9287
9288 (define_insn "*movqi_update1"
9289   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
9290         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9291                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9292    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9293         (plus:SI (match_dup 1) (match_dup 2)))]
9294   "TARGET_UPDATE"
9295   "@
9296    lbzux %3,%0,%2
9297    lbzu %3,%2(%0)"
9298   [(set_attr "type" "load_ux,load_u")])
9299
9300 (define_insn "*movqi_update2"
9301   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9302         (zero_extend:SI
9303          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9304                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9305    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9306         (plus:SI (match_dup 1) (match_dup 2)))]
9307   "TARGET_UPDATE"
9308   "@
9309    lbzux %3,%0,%2
9310    lbzu %3,%2(%0)"
9311   [(set_attr "type" "load_ux,load_u")])
9312
9313 (define_insn "*movqi_update3"
9314   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9315                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9316         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
9317    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9318         (plus:SI (match_dup 1) (match_dup 2)))]
9319   "TARGET_UPDATE"
9320   "@
9321    stbux %3,%0,%2
9322    stbu %3,%2(%0)"
9323   [(set_attr "type" "store_ux,store_u")])
9324
9325 (define_insn "*movsf_update1"
9326   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
9327         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9328                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9329    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9330         (plus:SI (match_dup 1) (match_dup 2)))]
9331   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9332   "@
9333    lfsux %3,%0,%2
9334    lfsu %3,%2(%0)"
9335   [(set_attr "type" "fpload_ux,fpload_u")])
9336
9337 (define_insn "*movsf_update2"
9338   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9339                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9340         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
9341    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9342         (plus:SI (match_dup 1) (match_dup 2)))]
9343   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9344   "@
9345    stfsux %3,%0,%2
9346    stfsu %3,%2(%0)"
9347   [(set_attr "type" "fpstore_ux,fpstore_u")])
9348
9349 (define_insn "*movsf_update3"
9350   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
9351         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9352                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9353    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9354         (plus:SI (match_dup 1) (match_dup 2)))]
9355   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9356   "@
9357    {lux|lwzux} %3,%0,%2
9358    {lu|lwzu} %3,%2(%0)"
9359   [(set_attr "type" "load_ux,load_u")])
9360
9361 (define_insn "*movsf_update4"
9362   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9363                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9364         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
9365    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9366         (plus:SI (match_dup 1) (match_dup 2)))]
9367   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9368   "@
9369    {stux|stwux} %3,%0,%2
9370    {stu|stwu} %3,%2(%0)"
9371   [(set_attr "type" "store_ux,store_u")])
9372
9373 (define_insn "*movdf_update1"
9374   [(set (match_operand:DF 3 "gpc_reg_operand" "=f,f")
9375         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9376                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9377    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9378         (plus:SI (match_dup 1) (match_dup 2)))]
9379   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9380   "@
9381    lfdux %3,%0,%2
9382    lfdu %3,%2(%0)"
9383   [(set_attr "type" "fpload_ux,fpload_u")])
9384
9385 (define_insn "*movdf_update2"
9386   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9387                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9388         (match_operand:DF 3 "gpc_reg_operand" "f,f"))
9389    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9390         (plus:SI (match_dup 1) (match_dup 2)))]
9391   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9392   "@
9393    stfdux %3,%0,%2
9394    stfdu %3,%2(%0)"
9395   [(set_attr "type" "fpstore_ux,fpstore_u")])
9396
9397 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
9398
9399 (define_insn "*lfq_power2"
9400   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
9401         (match_operand:TF 1 "memory_operand" ""))]
9402   "TARGET_POWER2
9403    && TARGET_HARD_FLOAT && TARGET_FPRS"
9404    "lfq%U1%X1 %0,%1")
9405
9406 (define_peephole2
9407   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9408         (match_operand:DF 1 "memory_operand" ""))
9409    (set (match_operand:DF 2 "gpc_reg_operand" "")
9410         (match_operand:DF 3 "memory_operand" ""))]
9411   "TARGET_POWER2
9412    && TARGET_HARD_FLOAT && TARGET_FPRS
9413    && registers_ok_for_quad_peep (operands[0], operands[2])
9414    && mems_ok_for_quad_peep (operands[1], operands[3])"
9415   [(set (match_dup 0)
9416         (match_dup 1))]
9417   "operands[1] = widen_memory_access (operands[1], TFmode, 0);
9418    operands[0] = gen_rtx_REG (TFmode, REGNO (operands[0]));")
9419
9420 (define_insn "*stfq_power2"
9421   [(set (match_operand:TF 0 "memory_operand" "")
9422         (match_operand:TF 1 "gpc_reg_operand" "f"))]
9423   "TARGET_POWER2
9424    && TARGET_HARD_FLOAT && TARGET_FPRS"
9425   "stfq%U0%X0 %1,%0")
9426
9427
9428 (define_peephole2
9429   [(set (match_operand:DF 0 "memory_operand" "")
9430         (match_operand:DF 1 "gpc_reg_operand" ""))
9431    (set (match_operand:DF 2 "memory_operand" "")
9432         (match_operand:DF 3 "gpc_reg_operand" ""))]
9433   "TARGET_POWER2
9434    && TARGET_HARD_FLOAT && TARGET_FPRS
9435    && registers_ok_for_quad_peep (operands[1], operands[3])
9436    && mems_ok_for_quad_peep (operands[0], operands[2])"
9437   [(set (match_dup 0)
9438         (match_dup 1))]
9439   "operands[0] = widen_memory_access (operands[0], TFmode, 0);
9440    operands[1] = gen_rtx_REG (TFmode, REGNO (operands[1]));")
9441
9442 ;; after inserting conditional returns we can sometimes have
9443 ;; unnecessary register moves.  Unfortunately we cannot have a
9444 ;; modeless peephole here, because some single SImode sets have early
9445 ;; clobber outputs.  Although those sets expand to multi-ppc-insn
9446 ;; sequences, using get_attr_length here will smash the operands
9447 ;; array.  Neither is there an early_cobbler_p predicate.
9448 (define_peephole2
9449   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9450         (match_operand:DF 1 "any_operand" ""))
9451    (set (match_operand:DF 2 "gpc_reg_operand" "")
9452         (match_dup 0))]
9453   "peep2_reg_dead_p (2, operands[0])"
9454   [(set (match_dup 2) (match_dup 1))])
9455
9456 (define_peephole2
9457   [(set (match_operand:SF 0 "gpc_reg_operand" "")
9458         (match_operand:SF 1 "any_operand" ""))
9459    (set (match_operand:SF 2 "gpc_reg_operand" "")
9460         (match_dup 0))]
9461   "peep2_reg_dead_p (2, operands[0])"
9462   [(set (match_dup 2) (match_dup 1))])
9463
9464 \f
9465 ;; TLS support.
9466
9467 ;; "b" output constraint here and on tls_ld to support tls linker optimization.
9468 (define_insn "tls_gd_32"
9469   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9470         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9471                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9472                    UNSPEC_TLSGD))]
9473   "HAVE_AS_TLS && !TARGET_64BIT"
9474   "addi %0,%1,%2@got@tlsgd")
9475
9476 (define_insn "tls_gd_64"
9477   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9478         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9479                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9480                    UNSPEC_TLSGD))]
9481   "HAVE_AS_TLS && TARGET_64BIT"
9482   "addi %0,%1,%2@got@tlsgd")
9483
9484 (define_insn "tls_ld_32"
9485   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9486         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")]
9487                    UNSPEC_TLSLD))]
9488   "HAVE_AS_TLS && !TARGET_64BIT"
9489   "addi %0,%1,%&@got@tlsld")
9490
9491 (define_insn "tls_ld_64"
9492   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9493         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")]
9494                    UNSPEC_TLSLD))]
9495   "HAVE_AS_TLS && TARGET_64BIT"
9496   "addi %0,%1,%&@got@tlsld")
9497
9498 (define_insn "tls_dtprel_32"
9499   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9500         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9501                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9502                    UNSPEC_TLSDTPREL))]
9503   "HAVE_AS_TLS && !TARGET_64BIT"
9504   "addi %0,%1,%2@dtprel")
9505
9506 (define_insn "tls_dtprel_64"
9507   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9508         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9509                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9510                    UNSPEC_TLSDTPREL))]
9511   "HAVE_AS_TLS && TARGET_64BIT"
9512   "addi %0,%1,%2@dtprel")
9513
9514 (define_insn "tls_dtprel_ha_32"
9515   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9516         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9517                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9518                    UNSPEC_TLSDTPRELHA))]
9519   "HAVE_AS_TLS && !TARGET_64BIT"
9520   "addis %0,%1,%2@dtprel@ha")
9521
9522 (define_insn "tls_dtprel_ha_64"
9523   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9524         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9525                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9526                    UNSPEC_TLSDTPRELHA))]
9527   "HAVE_AS_TLS && TARGET_64BIT"
9528   "addis %0,%1,%2@dtprel@ha")
9529
9530 (define_insn "tls_dtprel_lo_32"
9531   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9532         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9533                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9534                    UNSPEC_TLSDTPRELLO))]
9535   "HAVE_AS_TLS && !TARGET_64BIT"
9536   "addi %0,%1,%2@dtprel@l")
9537
9538 (define_insn "tls_dtprel_lo_64"
9539   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9540         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9541                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9542                    UNSPEC_TLSDTPRELLO))]
9543   "HAVE_AS_TLS && TARGET_64BIT"
9544   "addi %0,%1,%2@dtprel@l")
9545
9546 (define_insn "tls_got_dtprel_32"
9547   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9548         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9549                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9550                    UNSPEC_TLSGOTDTPREL))]
9551   "HAVE_AS_TLS && !TARGET_64BIT"
9552   "lwz %0,%2@got@dtprel(%1)")
9553
9554 (define_insn "tls_got_dtprel_64"
9555   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9556         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9557                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9558                    UNSPEC_TLSGOTDTPREL))]
9559   "HAVE_AS_TLS && TARGET_64BIT"
9560   "ld %0,%2@got@dtprel(%1)")
9561
9562 (define_insn "tls_tprel_32"
9563   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9564         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9565                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9566                    UNSPEC_TLSTPREL))]
9567   "HAVE_AS_TLS && !TARGET_64BIT"
9568   "addi %0,%1,%2@tprel")
9569
9570 (define_insn "tls_tprel_64"
9571   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9572         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9573                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9574                    UNSPEC_TLSTPREL))]
9575   "HAVE_AS_TLS && TARGET_64BIT"
9576   "addi %0,%1,%2@tprel")
9577
9578 (define_insn "tls_tprel_ha_32"
9579   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9580         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9581                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9582                    UNSPEC_TLSTPRELHA))]
9583   "HAVE_AS_TLS && !TARGET_64BIT"
9584   "addis %0,%1,%2@tprel@ha")
9585
9586 (define_insn "tls_tprel_ha_64"
9587   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9588         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9589                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9590                    UNSPEC_TLSTPRELHA))]
9591   "HAVE_AS_TLS && TARGET_64BIT"
9592   "addis %0,%1,%2@tprel@ha")
9593
9594 (define_insn "tls_tprel_lo_32"
9595   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9596         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9597                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9598                    UNSPEC_TLSTPRELLO))]
9599   "HAVE_AS_TLS && !TARGET_64BIT"
9600   "addi %0,%1,%2@tprel@l")
9601
9602 (define_insn "tls_tprel_lo_64"
9603   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9604         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9605                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9606                    UNSPEC_TLSTPRELLO))]
9607   "HAVE_AS_TLS && TARGET_64BIT"
9608   "addi %0,%1,%2@tprel@l")
9609
9610 ;; "b" output constraint here and on tls_tls input to support linker tls
9611 ;; optimization.  The linker may edit the instructions emitted by a
9612 ;; tls_got_tprel/tls_tls pair to addis,addi.
9613 (define_insn "tls_got_tprel_32"
9614   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9615         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9616                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9617                    UNSPEC_TLSGOTTPREL))]
9618   "HAVE_AS_TLS && !TARGET_64BIT"
9619   "lwz %0,%2@got@tprel(%1)")
9620
9621 (define_insn "tls_got_tprel_64"
9622   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9623         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9624                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9625                    UNSPEC_TLSGOTTPREL))]
9626   "HAVE_AS_TLS && TARGET_64BIT"
9627   "ld %0,%2@got@tprel(%1)")
9628
9629 (define_insn "tls_tls_32"
9630   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9631         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9632                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9633                    UNSPEC_TLSTLS))]
9634   "HAVE_AS_TLS && !TARGET_64BIT"
9635   "add %0,%1,%2@tls")
9636
9637 (define_insn "tls_tls_64"
9638   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9639         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9640                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9641                    UNSPEC_TLSTLS))]
9642   "HAVE_AS_TLS && TARGET_64BIT"
9643   "add %0,%1,%2@tls")
9644 \f
9645 ;; Next come insns related to the calling sequence.
9646 ;;
9647 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
9648 ;; We move the back-chain and decrement the stack pointer.
9649
9650 (define_expand "allocate_stack"
9651   [(set (match_operand 0 "gpc_reg_operand" "=r")
9652         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
9653    (set (reg 1)
9654         (minus (reg 1) (match_dup 1)))]
9655   ""
9656   "
9657 { rtx chain = gen_reg_rtx (Pmode);
9658   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
9659   rtx neg_op0;
9660
9661   emit_move_insn (chain, stack_bot);
9662
9663   /* Check stack bounds if necessary.  */
9664   if (current_function_limit_stack)
9665     {
9666       rtx available;
9667       available = expand_binop (Pmode, sub_optab,
9668                                 stack_pointer_rtx, stack_limit_rtx,
9669                                 NULL_RTX, 1, OPTAB_WIDEN);
9670       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
9671     }
9672
9673   if (GET_CODE (operands[1]) != CONST_INT
9674       || INTVAL (operands[1]) < -32767
9675       || INTVAL (operands[1]) > 32768)
9676     {
9677       neg_op0 = gen_reg_rtx (Pmode);
9678       if (TARGET_32BIT)
9679         emit_insn (gen_negsi2 (neg_op0, operands[1]));
9680       else
9681         emit_insn (gen_negdi2 (neg_op0, operands[1]));
9682     }
9683   else
9684     neg_op0 = GEN_INT (- INTVAL (operands[1]));
9685
9686   if (TARGET_UPDATE)
9687     emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update : gen_movdi_di_update))
9688                 (stack_pointer_rtx, stack_pointer_rtx, neg_op0, chain));
9689
9690   else
9691     {
9692       emit_insn ((* ((TARGET_32BIT) ? gen_addsi3 : gen_adddi3))
9693                  (stack_pointer_rtx, stack_pointer_rtx, neg_op0));
9694       emit_move_insn (gen_rtx_MEM (Pmode, stack_pointer_rtx), chain);
9695     }
9696
9697   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
9698   DONE;
9699 }")
9700
9701 ;; These patterns say how to save and restore the stack pointer.  We need not
9702 ;; save the stack pointer at function level since we are careful to
9703 ;; preserve the backchain.  At block level, we have to restore the backchain
9704 ;; when we restore the stack pointer.
9705 ;;
9706 ;; For nonlocal gotos, we must save both the stack pointer and its
9707 ;; backchain and restore both.  Note that in the nonlocal case, the
9708 ;; save area is a memory location.
9709
9710 (define_expand "save_stack_function"
9711   [(match_operand 0 "any_operand" "")
9712    (match_operand 1 "any_operand" "")]
9713   ""
9714   "DONE;")
9715
9716 (define_expand "restore_stack_function"
9717   [(match_operand 0 "any_operand" "")
9718    (match_operand 1 "any_operand" "")]
9719   ""
9720   "DONE;")
9721
9722 (define_expand "restore_stack_block"
9723   [(use (match_operand 0 "register_operand" ""))
9724    (set (match_dup 2) (match_dup 3))
9725    (set (match_dup 0) (match_operand 1 "register_operand" ""))
9726    (set (match_dup 3) (match_dup 2))]
9727   ""
9728   "
9729 {
9730   operands[2] = gen_reg_rtx (Pmode);
9731   operands[3] = gen_rtx_MEM (Pmode, operands[0]);
9732 }")
9733
9734 (define_expand "save_stack_nonlocal"
9735   [(match_operand 0 "memory_operand" "")
9736    (match_operand 1 "register_operand" "")]
9737   ""
9738   "
9739 {
9740   rtx temp = gen_reg_rtx (Pmode);
9741   int units_per_word = (TARGET_32BIT) ? 4 : 8;
9742
9743   /* Copy the backchain to the first word, sp to the second.  */
9744   emit_move_insn (temp, gen_rtx_MEM (Pmode, operands[1]));
9745   emit_move_insn (adjust_address_nv (operands[0], Pmode, 0), temp);
9746   emit_move_insn (adjust_address_nv (operands[0], Pmode, units_per_word),
9747                   operands[1]);
9748   DONE;
9749 }")
9750
9751 (define_expand "restore_stack_nonlocal"
9752   [(match_operand 0 "register_operand" "")
9753    (match_operand 1 "memory_operand" "")]
9754   ""
9755   "
9756 {
9757   rtx temp = gen_reg_rtx (Pmode);
9758   int units_per_word = (TARGET_32BIT) ? 4 : 8;
9759
9760   /* Restore the backchain from the first word, sp from the second.  */
9761   emit_move_insn (temp,
9762                   adjust_address_nv (operands[1], Pmode, 0));
9763   emit_move_insn (operands[0],
9764                   adjust_address_nv (operands[1], Pmode, units_per_word));
9765   emit_move_insn (gen_rtx_MEM (Pmode, operands[0]), temp);
9766   DONE;
9767 }")
9768 \f
9769 ;; TOC register handling.
9770
9771 ;; Code to initialize the TOC register...
9772
9773 (define_insn "load_toc_aix_si"
9774   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9775                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
9776               (use (reg:SI 2))])]
9777   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
9778   "*
9779 {
9780   char buf[30];
9781   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
9782   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9783   operands[2] = gen_rtx_REG (Pmode, 2);
9784   return \"{l|lwz} %0,%1(%2)\";
9785 }"
9786   [(set_attr "type" "load")])
9787
9788 (define_insn "load_toc_aix_di"
9789   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9790                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
9791               (use (reg:DI 2))])]
9792   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
9793   "*
9794 {
9795   char buf[30];
9796 #ifdef TARGET_RELOCATABLE
9797   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
9798                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
9799 #else
9800   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
9801 #endif
9802   if (TARGET_ELF)
9803     strcat (buf, \"@toc\");
9804   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9805   operands[2] = gen_rtx_REG (Pmode, 2);
9806   return \"ld %0,%1(%2)\";
9807 }"
9808   [(set_attr "type" "load")])
9809
9810 (define_insn "load_toc_v4_pic_si"
9811   [(set (match_operand:SI 0 "register_operand" "=l")
9812         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
9813   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
9814   "bl _GLOBAL_OFFSET_TABLE_@local-4"
9815   [(set_attr "type" "branch")
9816    (set_attr "length" "4")])
9817
9818 (define_insn "load_toc_v4_PIC_1"
9819   [(set (match_operand:SI 0 "register_operand" "=l")
9820         (match_operand:SI 1 "immediate_operand" "s"))
9821    (use (unspec [(match_dup 1)] UNSPEC_TOC))]
9822   "TARGET_ELF && DEFAULT_ABI != ABI_AIX
9823    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
9824   "bcl 20,31,%1\\n%1:"
9825   [(set_attr "type" "branch")
9826    (set_attr "length" "4")])
9827
9828 (define_insn "load_toc_v4_PIC_1b"
9829   [(set (match_operand:SI 0 "register_operand" "=l")
9830         (unspec:SI [(match_operand:SI 1 "immediate_operand" "s")]
9831                 UNSPEC_TOCPTR))]
9832   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
9833   "bcl 20,31,$+8\\n\\t.long %1-$"
9834   [(set_attr "type" "branch")
9835    (set_attr "length" "8")])
9836
9837 (define_insn "load_toc_v4_PIC_2"
9838   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9839         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
9840                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
9841                              (match_operand:SI 3 "immediate_operand" "s")))))]
9842   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
9843   "{l|lwz} %0,%2-%3(%1)"
9844   [(set_attr "type" "load")])
9845
9846 (define_insn "load_toc_v4_PIC_3b"
9847   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9848         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
9849                  (high:SI
9850                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
9851                              (match_operand:SI 3 "symbol_ref_operand" "s")))))]
9852   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
9853   "{cau|addis} %0,%1,%2-%3@ha")
9854
9855 (define_insn "load_toc_v4_PIC_3c"
9856   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9857         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
9858                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
9859                              (match_operand:SI 3 "symbol_ref_operand" "s"))))]
9860   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
9861   "{cal|addi} %0,%1,%2-%3@l")
9862
9863 ;; If the TOC is shared over a translation unit, as happens with all
9864 ;; the kinds of PIC that we support, we need to restore the TOC
9865 ;; pointer only when jumping over units of translation.
9866 ;; On Darwin, we need to reload the picbase.
9867
9868 (define_expand "builtin_setjmp_receiver"
9869   [(use (label_ref (match_operand 0 "" "")))]
9870   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
9871    || (TARGET_TOC && TARGET_MINIMAL_TOC)
9872    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
9873   "
9874 {
9875 #if TARGET_MACHO
9876   if (DEFAULT_ABI == ABI_DARWIN)
9877     {
9878       const char *picbase = machopic_function_base_name ();
9879       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (picbase));
9880       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
9881       rtx tmplabrtx;
9882       char tmplab[20];
9883
9884       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
9885                                   CODE_LABEL_NUMBER (operands[0]));
9886       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
9887
9888       emit_insn (gen_load_macho_picbase (picreg, tmplabrtx));
9889       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
9890     }
9891   else
9892 #endif
9893     rs6000_emit_load_toc_table (FALSE);
9894   DONE;
9895 }")
9896
9897 ;; Elf specific ways of loading addresses for non-PIC code.
9898 ;; The output of this could be r0, but we make a very strong
9899 ;; preference for a base register because it will usually
9900 ;; be needed there.
9901 (define_insn "elf_high"
9902   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
9903         (high:SI (match_operand 1 "" "")))]
9904   "TARGET_ELF && ! TARGET_64BIT"
9905   "{liu|lis} %0,%1@ha")
9906
9907 (define_insn "elf_low"
9908   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
9909         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
9910                    (match_operand 2 "" "")))]
9911    "TARGET_ELF && ! TARGET_64BIT"
9912    "@
9913     {cal|la} %0,%2@l(%1)
9914     {ai|addic} %0,%1,%K2")
9915 \f
9916 ;; A function pointer under AIX is a pointer to a data area whose first word
9917 ;; contains the actual address of the function, whose second word contains a
9918 ;; pointer to its TOC, and whose third word contains a value to place in the
9919 ;; static chain register (r11).  Note that if we load the static chain, our
9920 ;; "trampoline" need not have any executable code.
9921
9922 (define_expand "call_indirect_aix32"
9923   [(set (match_dup 2)
9924         (mem:SI (match_operand:SI 0 "gpc_reg_operand" "")))
9925    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
9926         (reg:SI 2))
9927    (set (reg:SI 2)
9928         (mem:SI (plus:SI (match_dup 0)
9929                          (const_int 4))))
9930    (set (reg:SI 11)
9931         (mem:SI (plus:SI (match_dup 0)
9932                          (const_int 8))))
9933    (parallel [(call (mem:SI (match_dup 2))
9934                     (match_operand 1 "" ""))
9935               (use (reg:SI 2))
9936               (use (reg:SI 11))
9937               (set (reg:SI 2)
9938                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
9939               (clobber (scratch:SI))])]
9940   "TARGET_32BIT"
9941   "
9942 { operands[2] = gen_reg_rtx (SImode); }")
9943
9944 (define_expand "call_indirect_aix64"
9945   [(set (match_dup 2)
9946         (mem:DI (match_operand:DI 0 "gpc_reg_operand" "")))
9947    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
9948         (reg:DI 2))
9949    (set (reg:DI 2)
9950         (mem:DI (plus:DI (match_dup 0)
9951                          (const_int 8))))
9952    (set (reg:DI 11)
9953         (mem:DI (plus:DI (match_dup 0)
9954                          (const_int 16))))
9955    (parallel [(call (mem:SI (match_dup 2))
9956                     (match_operand 1 "" ""))
9957               (use (reg:DI 2))
9958               (use (reg:DI 11))
9959               (set (reg:DI 2)
9960                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
9961               (clobber (scratch:SI))])]
9962   "TARGET_64BIT"
9963   "
9964 { operands[2] = gen_reg_rtx (DImode); }")
9965
9966 (define_expand "call_value_indirect_aix32"
9967   [(set (match_dup 3)
9968         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
9969    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
9970         (reg:SI 2))
9971    (set (reg:SI 2)
9972         (mem:SI (plus:SI (match_dup 1)
9973                          (const_int 4))))
9974    (set (reg:SI 11)
9975         (mem:SI (plus:SI (match_dup 1)
9976                          (const_int 8))))
9977    (parallel [(set (match_operand 0 "" "")
9978                    (call (mem:SI (match_dup 3))
9979                          (match_operand 2 "" "")))
9980               (use (reg:SI 2))
9981               (use (reg:SI 11))
9982               (set (reg:SI 2)
9983                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
9984               (clobber (scratch:SI))])]
9985   "TARGET_32BIT"
9986   "
9987 { operands[3] = gen_reg_rtx (SImode); }")
9988
9989 (define_expand "call_value_indirect_aix64"
9990   [(set (match_dup 3)
9991         (mem:DI (match_operand:DI 1 "gpc_reg_operand" "")))
9992    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
9993         (reg:DI 2))
9994    (set (reg:DI 2)
9995         (mem:DI (plus:DI (match_dup 1)
9996                          (const_int 8))))
9997    (set (reg:DI 11)
9998         (mem:DI (plus:DI (match_dup 1)
9999                          (const_int 16))))
10000    (parallel [(set (match_operand 0 "" "")
10001                    (call (mem:SI (match_dup 3))
10002                          (match_operand 2 "" "")))
10003               (use (reg:DI 2))
10004               (use (reg:DI 11))
10005               (set (reg:DI 2)
10006                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10007               (clobber (scratch:SI))])]
10008   "TARGET_64BIT"
10009   "
10010 { operands[3] = gen_reg_rtx (DImode); }")
10011
10012 ;; Now the definitions for the call and call_value insns
10013 (define_expand "call"
10014   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10015                     (match_operand 1 "" ""))
10016               (use (match_operand 2 "" ""))
10017               (clobber (scratch:SI))])]
10018   ""
10019   "
10020 {
10021 #if TARGET_MACHO
10022   if (MACHOPIC_INDIRECT)
10023     operands[0] = machopic_indirect_call_target (operands[0]);
10024 #endif
10025
10026   gcc_assert (GET_CODE (operands[0]) == MEM);
10027   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
10028
10029   operands[0] = XEXP (operands[0], 0);
10030
10031   if (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT
10032       && flag_pic
10033       && GET_CODE (operands[0]) == SYMBOL_REF
10034       && !SYMBOL_REF_LOCAL_P (operands[0]))
10035     {
10036       rtx call;
10037       rtvec tmp;
10038
10039       tmp = gen_rtvec (3,
10040                        gen_rtx_CALL (VOIDmode,
10041                                      gen_rtx_MEM (SImode, operands[0]),
10042                                      operands[1]),
10043                        gen_rtx_USE (VOIDmode, operands[2]),
10044                        gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (SImode)));
10045       call = emit_call_insn (gen_rtx_PARALLEL (VOIDmode, tmp));
10046       use_reg (&CALL_INSN_FUNCTION_USAGE (call), pic_offset_table_rtx);
10047       DONE;
10048     }
10049
10050   if (GET_CODE (operands[0]) != SYMBOL_REF
10051       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
10052       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
10053     {
10054       if (INTVAL (operands[2]) & CALL_LONG)
10055         operands[0] = rs6000_longcall_ref (operands[0]);
10056
10057       switch (DEFAULT_ABI)
10058         {
10059         case ABI_V4:
10060         case ABI_DARWIN:
10061           operands[0] = force_reg (Pmode, operands[0]);
10062           break;
10063
10064         case ABI_AIX:
10065           /* AIX function pointers are really pointers to a three word
10066              area.  */
10067           emit_call_insn (TARGET_32BIT
10068                           ? gen_call_indirect_aix32 (force_reg (SImode,
10069                                                                 operands[0]),
10070                                                      operands[1])
10071                           : gen_call_indirect_aix64 (force_reg (DImode,
10072                                                                 operands[0]),
10073                                                      operands[1]));
10074           DONE;
10075
10076         default:
10077           gcc_unreachable ();
10078         }
10079     }
10080 }")
10081
10082 (define_expand "call_value"
10083   [(parallel [(set (match_operand 0 "" "")
10084                    (call (mem:SI (match_operand 1 "address_operand" ""))
10085                          (match_operand 2 "" "")))
10086               (use (match_operand 3 "" ""))
10087               (clobber (scratch:SI))])]
10088   ""
10089   "
10090 {
10091 #if TARGET_MACHO
10092   if (MACHOPIC_INDIRECT)
10093     operands[1] = machopic_indirect_call_target (operands[1]);
10094 #endif
10095
10096   gcc_assert (GET_CODE (operands[1]) == MEM);
10097   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
10098
10099   operands[1] = XEXP (operands[1], 0);
10100
10101   if (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT
10102       && flag_pic
10103       && GET_CODE (operands[1]) == SYMBOL_REF
10104       && !SYMBOL_REF_LOCAL_P (operands[1]))
10105     {
10106       rtx call;
10107       rtvec tmp;
10108
10109       tmp = gen_rtvec (3,
10110                        gen_rtx_SET (VOIDmode,
10111                                     operands[0],
10112                                     gen_rtx_CALL (VOIDmode,
10113                                                   gen_rtx_MEM (SImode,
10114                                                                operands[1]),
10115                                                   operands[2])),
10116                        gen_rtx_USE (VOIDmode, operands[3]),
10117                        gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (SImode)));
10118       call = emit_call_insn (gen_rtx_PARALLEL (VOIDmode, tmp));
10119       use_reg (&CALL_INSN_FUNCTION_USAGE (call), pic_offset_table_rtx);
10120       DONE;
10121     }
10122
10123   if (GET_CODE (operands[1]) != SYMBOL_REF
10124       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
10125       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
10126     {
10127       if (INTVAL (operands[3]) & CALL_LONG)
10128         operands[1] = rs6000_longcall_ref (operands[1]);
10129
10130       switch (DEFAULT_ABI)
10131         {
10132         case ABI_V4:
10133         case ABI_DARWIN:
10134           operands[1] = force_reg (Pmode, operands[1]);
10135           break;
10136
10137         case ABI_AIX:
10138           /* AIX function pointers are really pointers to a three word
10139              area.  */
10140           emit_call_insn (TARGET_32BIT
10141                           ? gen_call_value_indirect_aix32 (operands[0],
10142                                                            force_reg (SImode,
10143                                                                       operands[1]),
10144                                                            operands[2])
10145                           : gen_call_value_indirect_aix64 (operands[0],
10146                                                            force_reg (DImode,
10147                                                                       operands[1]),
10148                                                            operands[2]));
10149           DONE;
10150
10151         default:
10152           gcc_unreachable ();
10153         }
10154     }
10155 }")
10156
10157 ;; Call to function in current module.  No TOC pointer reload needed.
10158 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10159 ;; either the function was not prototyped, or it was prototyped as a
10160 ;; variable argument function.  It is > 0 if FP registers were passed
10161 ;; and < 0 if they were not.
10162
10163 (define_insn "*call_local32"
10164   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10165          (match_operand 1 "" "g,g"))
10166    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10167    (clobber (match_scratch:SI 3 "=l,l"))]
10168   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10169   "*
10170 {
10171   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10172     output_asm_insn (\"crxor 6,6,6\", operands);
10173
10174   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10175     output_asm_insn (\"creqv 6,6,6\", operands);
10176
10177   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10178 }"
10179   [(set_attr "type" "branch")
10180    (set_attr "length" "4,8")])
10181
10182 (define_insn "*call_local64"
10183   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10184          (match_operand 1 "" "g,g"))
10185    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10186    (clobber (match_scratch:SI 3 "=l,l"))]
10187   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10188   "*
10189 {
10190   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10191     output_asm_insn (\"crxor 6,6,6\", operands);
10192
10193   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10194     output_asm_insn (\"creqv 6,6,6\", operands);
10195
10196   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10197 }"
10198   [(set_attr "type" "branch")
10199    (set_attr "length" "4,8")])
10200
10201 (define_insn "*call_value_local32"
10202   [(set (match_operand 0 "" "")
10203         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10204               (match_operand 2 "" "g,g")))
10205    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10206    (clobber (match_scratch:SI 4 "=l,l"))]
10207   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10208   "*
10209 {
10210   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10211     output_asm_insn (\"crxor 6,6,6\", operands);
10212
10213   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10214     output_asm_insn (\"creqv 6,6,6\", operands);
10215
10216   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10217 }"
10218   [(set_attr "type" "branch")
10219    (set_attr "length" "4,8")])
10220
10221
10222 (define_insn "*call_value_local64"
10223   [(set (match_operand 0 "" "")
10224         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10225               (match_operand 2 "" "g,g")))
10226    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10227    (clobber (match_scratch:SI 4 "=l,l"))]
10228   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10229   "*
10230 {
10231   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10232     output_asm_insn (\"crxor 6,6,6\", operands);
10233
10234   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10235     output_asm_insn (\"creqv 6,6,6\", operands);
10236
10237   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10238 }"
10239   [(set_attr "type" "branch")
10240    (set_attr "length" "4,8")])
10241
10242 ;; Call to function which may be in another module.  Restore the TOC
10243 ;; pointer (r2) after the call unless this is System V.
10244 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10245 ;; either the function was not prototyped, or it was prototyped as a
10246 ;; variable argument function.  It is > 0 if FP registers were passed
10247 ;; and < 0 if they were not.
10248
10249 (define_insn "*call_indirect_nonlocal_aix32"
10250   [(call (mem:SI (match_operand:SI 0 "register_operand" "c,*l"))
10251          (match_operand 1 "" "g,g"))
10252    (use (reg:SI 2))
10253    (use (reg:SI 11))
10254    (set (reg:SI 2)
10255         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10256    (clobber (match_scratch:SI 2 "=l,l"))]
10257   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10258   "b%T0l\;{l|lwz} 2,20(1)"
10259   [(set_attr "type" "jmpreg")
10260    (set_attr "length" "8")])
10261
10262 (define_insn "*call_nonlocal_aix32"
10263   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10264          (match_operand 1 "" "g"))
10265    (use (match_operand:SI 2 "immediate_operand" "O"))
10266    (clobber (match_scratch:SI 3 "=l"))]
10267   "TARGET_32BIT
10268    && DEFAULT_ABI == ABI_AIX
10269    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10270   "bl %z0\;%."
10271   [(set_attr "type" "branch")
10272    (set_attr "length" "8")])
10273
10274 (define_insn "*call_indirect_nonlocal_aix64"
10275   [(call (mem:SI (match_operand:DI 0 "register_operand" "c,*l"))
10276          (match_operand 1 "" "g,g"))
10277    (use (reg:DI 2))
10278    (use (reg:DI 11))
10279    (set (reg:DI 2)
10280         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10281    (clobber (match_scratch:SI 2 "=l,l"))]
10282   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10283   "b%T0l\;ld 2,40(1)"
10284   [(set_attr "type" "jmpreg")
10285    (set_attr "length" "8")])
10286
10287 (define_insn "*call_nonlocal_aix64"
10288   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10289          (match_operand 1 "" "g"))
10290    (use (match_operand:SI 2 "immediate_operand" "O"))
10291    (clobber (match_scratch:SI 3 "=l"))]
10292   "TARGET_64BIT
10293    && DEFAULT_ABI == ABI_AIX
10294    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10295   "bl %z0\;%."
10296   [(set_attr "type" "branch")
10297    (set_attr "length" "8")])
10298
10299 (define_insn "*call_value_indirect_nonlocal_aix32"
10300   [(set (match_operand 0 "" "")
10301         (call (mem:SI (match_operand:SI 1 "register_operand" "c,*l"))
10302               (match_operand 2 "" "g,g")))
10303    (use (reg:SI 2))
10304    (use (reg:SI 11))
10305    (set (reg:SI 2)
10306         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10307    (clobber (match_scratch:SI 3 "=l,l"))]
10308   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10309   "b%T1l\;{l|lwz} 2,20(1)"
10310   [(set_attr "type" "jmpreg")
10311    (set_attr "length" "8")])
10312
10313 (define_insn "*call_value_nonlocal_aix32"
10314   [(set (match_operand 0 "" "")
10315         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10316               (match_operand 2 "" "g")))
10317    (use (match_operand:SI 3 "immediate_operand" "O"))
10318    (clobber (match_scratch:SI 4 "=l"))]
10319   "TARGET_32BIT
10320    && DEFAULT_ABI == ABI_AIX
10321    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10322   "bl %z1\;%."
10323   [(set_attr "type" "branch")
10324    (set_attr "length" "8")])
10325
10326 (define_insn "*call_value_indirect_nonlocal_aix64"
10327   [(set (match_operand 0 "" "")
10328         (call (mem:SI (match_operand:DI 1 "register_operand" "c,*l"))
10329               (match_operand 2 "" "g,g")))
10330    (use (reg:DI 2))
10331    (use (reg:DI 11))
10332    (set (reg:DI 2)
10333         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10334    (clobber (match_scratch:SI 3 "=l,l"))]
10335   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10336   "b%T1l\;ld 2,40(1)"
10337   [(set_attr "type" "jmpreg")
10338    (set_attr "length" "8")])
10339
10340 (define_insn "*call_value_nonlocal_aix64"
10341   [(set (match_operand 0 "" "")
10342         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10343               (match_operand 2 "" "g")))
10344    (use (match_operand:SI 3 "immediate_operand" "O"))
10345    (clobber (match_scratch:SI 4 "=l"))]
10346   "TARGET_64BIT
10347    && DEFAULT_ABI == ABI_AIX
10348    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10349   "bl %z1\;%."
10350   [(set_attr "type" "branch")
10351    (set_attr "length" "8")])
10352
10353 ;; A function pointer under System V is just a normal pointer
10354 ;; operands[0] is the function pointer
10355 ;; operands[1] is the stack size to clean up
10356 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
10357 ;; which indicates how to set cr1
10358
10359 (define_insn "*call_indirect_nonlocal_sysv"
10360   [(call (mem:SI (match_operand:SI 0 "register_operand" "c,*l,c,*l"))
10361          (match_operand 1 "" "g,g,g,g"))
10362    (use (match_operand:SI 2 "immediate_operand" "O,O,n,n"))
10363    (clobber (match_scratch:SI 3 "=l,l,l,l"))]
10364   "DEFAULT_ABI == ABI_V4
10365    || DEFAULT_ABI == ABI_DARWIN"
10366 {
10367   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10368     output_asm_insn ("crxor 6,6,6", operands);
10369
10370   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10371     output_asm_insn ("creqv 6,6,6", operands);
10372
10373   return "b%T0l";
10374 }
10375   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
10376    (set_attr "length" "4,4,8,8")])
10377
10378 (define_insn "*call_nonlocal_sysv"
10379   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s,s"))
10380          (match_operand 1 "" "g,g"))
10381    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10382    (clobber (match_scratch:SI 3 "=l,l"))]
10383   "(DEFAULT_ABI == ABI_DARWIN
10384    || (DEFAULT_ABI == ABI_V4
10385        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
10386 {
10387   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10388     output_asm_insn ("crxor 6,6,6", operands);
10389
10390   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10391     output_asm_insn ("creqv 6,6,6", operands);
10392
10393 #if TARGET_MACHO
10394   return output_call(insn, operands, 0, 2);
10395 #else
10396   if (DEFAULT_ABI == ABI_V4 && flag_pic)
10397     {
10398       if (TARGET_SECURE_PLT && flag_pic == 2)
10399         /* The magic 32768 offset here and in the other sysv call insns
10400            corresponds to the offset of r30 in .got2, as given by LCTOC1.
10401            See sysv4.h:toc_section.  */
10402         return "bl %z0+32768@plt";
10403       else
10404         return "bl %z0@plt";
10405     }
10406   else
10407     return "bl %z0";
10408 #endif
10409 }
10410   [(set_attr "type" "branch,branch")
10411    (set_attr "length" "4,8")])
10412
10413 (define_insn "*call_value_indirect_nonlocal_sysv"
10414   [(set (match_operand 0 "" "")
10415         (call (mem:SI (match_operand:SI 1 "register_operand" "c,*l,c,*l"))
10416               (match_operand 2 "" "g,g,g,g")))
10417    (use (match_operand:SI 3 "immediate_operand" "O,O,n,n"))
10418    (clobber (match_scratch:SI 4 "=l,l,l,l"))]
10419   "DEFAULT_ABI == ABI_V4
10420    || DEFAULT_ABI == ABI_DARWIN"
10421 {
10422   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10423     output_asm_insn ("crxor 6,6,6", operands);
10424
10425   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10426     output_asm_insn ("creqv 6,6,6", operands);
10427
10428   return "b%T1l";
10429 }
10430   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
10431    (set_attr "length" "4,4,8,8")])
10432
10433 (define_insn "*call_value_nonlocal_sysv"
10434   [(set (match_operand 0 "" "")
10435         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s,s"))
10436               (match_operand 2 "" "g,g")))
10437    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10438    (clobber (match_scratch:SI 4 "=l,l"))]
10439   "(DEFAULT_ABI == ABI_DARWIN
10440    || (DEFAULT_ABI == ABI_V4
10441        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
10442 {
10443   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10444     output_asm_insn ("crxor 6,6,6", operands);
10445
10446   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10447     output_asm_insn ("creqv 6,6,6", operands);
10448
10449 #if TARGET_MACHO
10450   return output_call(insn, operands, 1, 3);
10451 #else
10452   if (DEFAULT_ABI == ABI_V4 && flag_pic)
10453     {
10454       if (TARGET_SECURE_PLT && flag_pic == 2)
10455         return "bl %z1+32768@plt";
10456       else
10457         return "bl %z1@plt";
10458     }
10459   else
10460     return "bl %z1";
10461 #endif
10462 }
10463   [(set_attr "type" "branch,branch")
10464    (set_attr "length" "4,8")])
10465
10466 ;; Call subroutine returning any type.
10467 (define_expand "untyped_call"
10468   [(parallel [(call (match_operand 0 "" "")
10469                     (const_int 0))
10470               (match_operand 1 "" "")
10471               (match_operand 2 "" "")])]
10472   ""
10473   "
10474 {
10475   int i;
10476
10477   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
10478
10479   for (i = 0; i < XVECLEN (operands[2], 0); i++)
10480     {
10481       rtx set = XVECEXP (operands[2], 0, i);
10482       emit_move_insn (SET_DEST (set), SET_SRC (set));
10483     }
10484
10485   /* The optimizer does not know that the call sets the function value
10486      registers we stored in the result block.  We avoid problems by
10487      claiming that all hard registers are used and clobbered at this
10488      point.  */
10489   emit_insn (gen_blockage ());
10490
10491   DONE;
10492 }")
10493
10494 ;; sibling call patterns
10495 (define_expand "sibcall"
10496   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10497                     (match_operand 1 "" ""))
10498               (use (match_operand 2 "" ""))
10499               (use (match_operand 3 "" ""))
10500               (return)])]
10501   ""
10502   "
10503 {
10504 #if TARGET_MACHO
10505   if (MACHOPIC_INDIRECT)
10506     operands[0] = machopic_indirect_call_target (operands[0]);
10507 #endif
10508
10509   gcc_assert (GET_CODE (operands[0]) == MEM);
10510   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
10511
10512   operands[0] = XEXP (operands[0], 0);
10513   operands[3] = gen_reg_rtx (SImode);
10514
10515 }")
10516
10517 ;; this and similar patterns must be marked as using LR, otherwise
10518 ;; dataflow will try to delete the store into it.  This is true
10519 ;; even when the actual reg to jump to is in CTR, when LR was
10520 ;; saved and restored around the PIC-setting BCL.
10521 (define_insn "*sibcall_local32"
10522   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10523          (match_operand 1 "" "g,g"))
10524    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10525    (use (match_operand:SI 3 "register_operand" "l,l"))
10526    (return)]
10527   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10528   "*
10529 {
10530   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10531     output_asm_insn (\"crxor 6,6,6\", operands);
10532
10533   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10534     output_asm_insn (\"creqv 6,6,6\", operands);
10535
10536   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
10537 }"
10538   [(set_attr "type" "branch")
10539    (set_attr "length" "4,8")])
10540
10541 (define_insn "*sibcall_local64"
10542   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10543          (match_operand 1 "" "g,g"))
10544    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10545    (use (match_operand:SI 3 "register_operand" "l,l"))
10546    (return)]
10547   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10548   "*
10549 {
10550   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10551     output_asm_insn (\"crxor 6,6,6\", operands);
10552
10553   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10554     output_asm_insn (\"creqv 6,6,6\", operands);
10555
10556   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
10557 }"
10558   [(set_attr "type" "branch")
10559    (set_attr "length" "4,8")])
10560
10561 (define_insn "*sibcall_value_local32"
10562   [(set (match_operand 0 "" "")
10563         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10564               (match_operand 2 "" "g,g")))
10565    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10566    (use (match_operand:SI 4 "register_operand" "l,l"))
10567    (return)]
10568   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10569   "*
10570 {
10571   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10572     output_asm_insn (\"crxor 6,6,6\", operands);
10573
10574   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10575     output_asm_insn (\"creqv 6,6,6\", operands);
10576
10577   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
10578 }"
10579   [(set_attr "type" "branch")
10580    (set_attr "length" "4,8")])
10581
10582
10583 (define_insn "*sibcall_value_local64"
10584   [(set (match_operand 0 "" "")
10585         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10586               (match_operand 2 "" "g,g")))
10587    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10588    (use (match_operand:SI 4 "register_operand" "l,l"))
10589    (return)]
10590   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10591   "*
10592 {
10593   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10594     output_asm_insn (\"crxor 6,6,6\", operands);
10595
10596   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10597     output_asm_insn (\"creqv 6,6,6\", operands);
10598
10599   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
10600 }"
10601   [(set_attr "type" "branch")
10602    (set_attr "length" "4,8")])
10603
10604 (define_insn "*sibcall_nonlocal_aix32"
10605   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10606          (match_operand 1 "" "g"))
10607    (use (match_operand:SI 2 "immediate_operand" "O"))
10608    (use (match_operand:SI 3 "register_operand" "l"))
10609    (return)]
10610   "TARGET_32BIT
10611    && DEFAULT_ABI == ABI_AIX
10612    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10613   "b %z0"
10614   [(set_attr "type" "branch")
10615    (set_attr "length" "4")])
10616
10617 (define_insn "*sibcall_nonlocal_aix64"
10618   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10619          (match_operand 1 "" "g"))
10620    (use (match_operand:SI 2 "immediate_operand" "O"))
10621    (use (match_operand:SI 3 "register_operand" "l"))
10622    (return)]
10623   "TARGET_64BIT
10624    && DEFAULT_ABI == ABI_AIX
10625    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10626   "b %z0"
10627   [(set_attr "type" "branch")
10628    (set_attr "length" "4")])
10629
10630 (define_insn "*sibcall_value_nonlocal_aix32"
10631   [(set (match_operand 0 "" "")
10632         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10633               (match_operand 2 "" "g")))
10634    (use (match_operand:SI 3 "immediate_operand" "O"))
10635    (use (match_operand:SI 4 "register_operand" "l"))
10636    (return)]
10637   "TARGET_32BIT
10638    && DEFAULT_ABI == ABI_AIX
10639    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10640   "b %z1"
10641   [(set_attr "type" "branch")
10642    (set_attr "length" "4")])
10643
10644 (define_insn "*sibcall_value_nonlocal_aix64"
10645   [(set (match_operand 0 "" "")
10646         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10647               (match_operand 2 "" "g")))
10648    (use (match_operand:SI 3 "immediate_operand" "O"))
10649    (use (match_operand:SI 4 "register_operand" "l"))
10650    (return)]
10651   "TARGET_64BIT
10652    && DEFAULT_ABI == ABI_AIX
10653    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10654   "b %z1"
10655   [(set_attr "type" "branch")
10656    (set_attr "length" "4")])
10657
10658 (define_insn "*sibcall_nonlocal_sysv"
10659   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s,s"))
10660          (match_operand 1 "" ""))
10661    (use (match_operand 2 "immediate_operand" "O,n"))
10662    (use (match_operand:SI 3 "register_operand" "l,l"))
10663    (return)]
10664   "(DEFAULT_ABI == ABI_DARWIN
10665      || DEFAULT_ABI == ABI_V4)
10666    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10667   "*
10668 {
10669   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10670     output_asm_insn (\"crxor 6,6,6\", operands);
10671
10672   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10673     output_asm_insn (\"creqv 6,6,6\", operands);
10674
10675   if (DEFAULT_ABI == ABI_V4 && flag_pic)
10676     {
10677       if (TARGET_SECURE_PLT && flag_pic == 2)
10678         return \"b %z0+32768@plt\";
10679       else
10680         return \"b %z0@plt\";
10681     }
10682   else
10683     return \"b %z0\";
10684 }"
10685   [(set_attr "type" "branch,branch")
10686    (set_attr "length" "4,8")])
10687
10688 (define_expand "sibcall_value"
10689   [(parallel [(set (match_operand 0 "register_operand" "")
10690                 (call (mem:SI (match_operand 1 "address_operand" ""))
10691                       (match_operand 2 "" "")))
10692               (use (match_operand 3 "" ""))
10693               (use (match_operand 4 "" ""))
10694               (return)])]
10695   ""
10696   "
10697 {
10698 #if TARGET_MACHO
10699   if (MACHOPIC_INDIRECT)
10700     operands[1] = machopic_indirect_call_target (operands[1]);
10701 #endif
10702
10703   gcc_assert (GET_CODE (operands[1]) == MEM);
10704   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
10705
10706   operands[1] = XEXP (operands[1], 0);
10707   operands[4] = gen_reg_rtx (SImode);
10708
10709 }")
10710
10711 (define_insn "*sibcall_value_nonlocal_sysv"
10712   [(set (match_operand 0 "" "")
10713         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s,s"))
10714               (match_operand 2 "" "")))
10715    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10716    (use (match_operand:SI 4 "register_operand" "l,l"))
10717    (return)]
10718   "(DEFAULT_ABI == ABI_DARWIN
10719        || DEFAULT_ABI == ABI_V4)
10720    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10721   "*
10722 {
10723   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10724     output_asm_insn (\"crxor 6,6,6\", operands);
10725
10726   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10727     output_asm_insn (\"creqv 6,6,6\", operands);
10728
10729   if (DEFAULT_ABI == ABI_V4 && flag_pic)
10730     {
10731       if (TARGET_SECURE_PLT && flag_pic == 2)
10732         return \"b %z1+32768@plt\";
10733       else
10734         return \"b %z1@plt\";
10735     }
10736   else
10737     return \"b %z1\";
10738 }"
10739   [(set_attr "type" "branch,branch")
10740    (set_attr "length" "4,8")])
10741
10742 (define_expand "sibcall_epilogue"
10743   [(use (const_int 0))]
10744   "TARGET_SCHED_PROLOG"
10745   "
10746 {
10747       rs6000_emit_epilogue (TRUE);
10748       DONE;
10749 }")
10750
10751 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
10752 ;; all of memory.  This blocks insns from being moved across this point.
10753
10754 (define_insn "blockage"
10755   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
10756   ""
10757   "")
10758 \f
10759 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
10760 ;; signed & unsigned, and one type of branch.
10761 ;;
10762 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
10763 ;; insns, and branches.  We store the operands of compares until we see
10764 ;; how it is used.
10765 (define_expand "cmpsi"
10766   [(set (cc0)
10767         (compare (match_operand:SI 0 "gpc_reg_operand" "")
10768                  (match_operand:SI 1 "reg_or_short_operand" "")))]
10769   ""
10770   "
10771 {
10772   /* Take care of the possibility that operands[1] might be negative but
10773      this might be a logical operation.  That insn doesn't exist.  */
10774   if (GET_CODE (operands[1]) == CONST_INT
10775       && INTVAL (operands[1]) < 0)
10776     operands[1] = force_reg (SImode, operands[1]);
10777
10778   rs6000_compare_op0 = operands[0];
10779   rs6000_compare_op1 = operands[1];
10780   rs6000_compare_fp_p = 0;
10781   DONE;
10782 }")
10783
10784 (define_expand "cmpdi"
10785   [(set (cc0)
10786         (compare (match_operand:DI 0 "gpc_reg_operand" "")
10787                  (match_operand:DI 1 "reg_or_short_operand" "")))]
10788   "TARGET_POWERPC64"
10789   "
10790 {
10791   /* Take care of the possibility that operands[1] might be negative but
10792      this might be a logical operation.  That insn doesn't exist.  */
10793   if (GET_CODE (operands[1]) == CONST_INT
10794       && INTVAL (operands[1]) < 0)
10795     operands[1] = force_reg (DImode, operands[1]);
10796
10797   rs6000_compare_op0 = operands[0];
10798   rs6000_compare_op1 = operands[1];
10799   rs6000_compare_fp_p = 0;
10800   DONE;
10801 }")
10802
10803 (define_expand "cmpsf"
10804   [(set (cc0) (compare (match_operand:SF 0 "gpc_reg_operand" "")
10805                        (match_operand:SF 1 "gpc_reg_operand" "")))]
10806   "TARGET_HARD_FLOAT"
10807   "
10808 {
10809   rs6000_compare_op0 = operands[0];
10810   rs6000_compare_op1 = operands[1];
10811   rs6000_compare_fp_p = 1;
10812   DONE;
10813 }")
10814
10815 (define_expand "cmpdf"
10816   [(set (cc0) (compare (match_operand:DF 0 "gpc_reg_operand" "")
10817                        (match_operand:DF 1 "gpc_reg_operand" "")))]
10818   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
10819   "
10820 {
10821   rs6000_compare_op0 = operands[0];
10822   rs6000_compare_op1 = operands[1];
10823   rs6000_compare_fp_p = 1;
10824   DONE;
10825 }")
10826
10827 (define_expand "cmptf"
10828   [(set (cc0) (compare (match_operand:TF 0 "gpc_reg_operand" "")
10829                        (match_operand:TF 1 "gpc_reg_operand" "")))]
10830   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
10831    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
10832   "
10833 {
10834   rs6000_compare_op0 = operands[0];
10835   rs6000_compare_op1 = operands[1];
10836   rs6000_compare_fp_p = 1;
10837   DONE;
10838 }")
10839
10840 (define_expand "beq"
10841   [(use (match_operand 0 "" ""))]
10842   ""
10843   "{ rs6000_emit_cbranch (EQ, operands[0]); DONE; }")
10844
10845 (define_expand "bne"
10846   [(use (match_operand 0 "" ""))]
10847   ""
10848   "{ rs6000_emit_cbranch (NE, operands[0]); DONE; }")
10849
10850 (define_expand "bge"
10851   [(use (match_operand 0 "" ""))]
10852   ""
10853   "{ rs6000_emit_cbranch (GE, operands[0]); DONE; }")
10854
10855 (define_expand "bgt"
10856   [(use (match_operand 0 "" ""))]
10857   ""
10858   "{ rs6000_emit_cbranch (GT, operands[0]); DONE; }")
10859
10860 (define_expand "ble"
10861   [(use (match_operand 0 "" ""))]
10862   ""
10863   "{ rs6000_emit_cbranch (LE, operands[0]); DONE; }")
10864
10865 (define_expand "blt"
10866   [(use (match_operand 0 "" ""))]
10867   ""
10868   "{ rs6000_emit_cbranch (LT, operands[0]); DONE; }")
10869
10870 (define_expand "bgeu"
10871   [(use (match_operand 0 "" ""))]
10872   ""
10873   "{ rs6000_emit_cbranch (GEU, operands[0]); DONE; }")
10874
10875 (define_expand "bgtu"
10876   [(use (match_operand 0 "" ""))]
10877   ""
10878   "{ rs6000_emit_cbranch (GTU, operands[0]); DONE; }")
10879
10880 (define_expand "bleu"
10881   [(use (match_operand 0 "" ""))]
10882   ""
10883   "{ rs6000_emit_cbranch (LEU, operands[0]); DONE; }")
10884
10885 (define_expand "bltu"
10886   [(use (match_operand 0 "" ""))]
10887   ""
10888   "{ rs6000_emit_cbranch (LTU, operands[0]); DONE; }")
10889
10890 (define_expand "bunordered"
10891   [(use (match_operand 0 "" ""))]
10892   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
10893   "{ rs6000_emit_cbranch (UNORDERED, operands[0]); DONE; }")
10894
10895 (define_expand "bordered"
10896   [(use (match_operand 0 "" ""))]
10897   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
10898   "{ rs6000_emit_cbranch (ORDERED, operands[0]); DONE; }")
10899
10900 (define_expand "buneq"
10901   [(use (match_operand 0 "" ""))]
10902   ""
10903   "{ rs6000_emit_cbranch (UNEQ, operands[0]); DONE; }")
10904
10905 (define_expand "bunge"
10906   [(use (match_operand 0 "" ""))]
10907   ""
10908   "{ rs6000_emit_cbranch (UNGE, operands[0]); DONE; }")
10909
10910 (define_expand "bungt"
10911   [(use (match_operand 0 "" ""))]
10912   ""
10913   "{ rs6000_emit_cbranch (UNGT, operands[0]); DONE; }")
10914
10915 (define_expand "bunle"
10916   [(use (match_operand 0 "" ""))]
10917   ""
10918   "{ rs6000_emit_cbranch (UNLE, operands[0]); DONE; }")
10919
10920 (define_expand "bunlt"
10921   [(use (match_operand 0 "" ""))]
10922   ""
10923   "{ rs6000_emit_cbranch (UNLT, operands[0]); DONE; }")
10924
10925 (define_expand "bltgt"
10926   [(use (match_operand 0 "" ""))]
10927   ""
10928   "{ rs6000_emit_cbranch (LTGT, operands[0]); DONE; }")
10929
10930 ;; For SNE, we would prefer that the xor/abs sequence be used for integers.
10931 ;; For SEQ, likewise, except that comparisons with zero should be done
10932 ;; with an scc insns.  However, due to the order that combine see the
10933 ;; resulting insns, we must, in fact, allow SEQ for integers.  Fail in
10934 ;; the cases we don't want to handle.
10935 (define_expand "seq"
10936   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10937   ""
10938   "{ rs6000_emit_sCOND (EQ, operands[0]); DONE; }")
10939
10940 (define_expand "sne"
10941   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10942   ""
10943   "
10944 {
10945   if (! rs6000_compare_fp_p)
10946     FAIL;
10947
10948   rs6000_emit_sCOND (NE, operands[0]);
10949   DONE;
10950 }")
10951
10952 ;; A >= 0 is best done the portable way for A an integer.
10953 (define_expand "sge"
10954   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10955   ""
10956   "
10957 {
10958   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
10959     FAIL;
10960
10961   rs6000_emit_sCOND (GE, operands[0]);
10962   DONE;
10963 }")
10964
10965 ;; A > 0 is best done using the portable sequence, so fail in that case.
10966 (define_expand "sgt"
10967   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10968   ""
10969   "
10970 {
10971   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
10972     FAIL;
10973
10974   rs6000_emit_sCOND (GT, operands[0]);
10975   DONE;
10976 }")
10977
10978 ;; A <= 0 is best done the portable way for A an integer.
10979 (define_expand "sle"
10980   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10981   ""
10982   "
10983 {
10984   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
10985     FAIL;
10986
10987   rs6000_emit_sCOND (LE, operands[0]);
10988   DONE;
10989 }")
10990
10991 ;; A < 0 is best done in the portable way for A an integer.
10992 (define_expand "slt"
10993   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10994   ""
10995   "
10996 {
10997   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
10998     FAIL;
10999
11000   rs6000_emit_sCOND (LT, operands[0]);
11001   DONE;
11002 }")
11003
11004 (define_expand "sgeu"
11005   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11006   ""
11007   "{ rs6000_emit_sCOND (GEU, operands[0]); DONE; }")
11008
11009 (define_expand "sgtu"
11010   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11011   ""
11012   "{ rs6000_emit_sCOND (GTU, operands[0]); DONE; }")
11013
11014 (define_expand "sleu"
11015   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11016   ""
11017   "{ rs6000_emit_sCOND (LEU, operands[0]); DONE; }")
11018
11019 (define_expand "sltu"
11020   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11021   ""
11022   "{ rs6000_emit_sCOND (LTU, operands[0]); DONE; }")
11023
11024 (define_expand "sunordered"
11025   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11026   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
11027   "{ rs6000_emit_sCOND (UNORDERED, operands[0]); DONE; }")
11028
11029 (define_expand "sordered"
11030   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11031   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
11032   "{ rs6000_emit_sCOND (ORDERED, operands[0]); DONE; }")
11033
11034 (define_expand "suneq"
11035   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11036   ""
11037   "{ rs6000_emit_sCOND (UNEQ, operands[0]); DONE; }")
11038
11039 (define_expand "sunge"
11040   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11041   ""
11042   "{ rs6000_emit_sCOND (UNGE, operands[0]); DONE; }")
11043
11044 (define_expand "sungt"
11045   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11046   ""
11047   "{ rs6000_emit_sCOND (UNGT, operands[0]); DONE; }")
11048
11049 (define_expand "sunle"
11050   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11051   ""
11052   "{ rs6000_emit_sCOND (UNLE, operands[0]); DONE; }")
11053
11054 (define_expand "sunlt"
11055   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11056   ""
11057   "{ rs6000_emit_sCOND (UNLT, operands[0]); DONE; }")
11058
11059 (define_expand "sltgt"
11060   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11061   ""
11062   "{ rs6000_emit_sCOND (LTGT, operands[0]); DONE; }")
11063
11064 \f
11065 ;; Here are the actual compare insns.
11066 (define_insn "*cmpsi_internal1"
11067   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11068         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11069                     (match_operand:SI 2 "reg_or_short_operand" "rI")))]
11070   ""
11071   "{cmp%I2|cmpw%I2} %0,%1,%2"
11072   [(set_attr "type" "cmp")])
11073
11074 (define_insn "*cmpdi_internal1"
11075   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11076         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "r")
11077                     (match_operand:DI 2 "reg_or_short_operand" "rI")))]
11078   "TARGET_POWERPC64"
11079   "cmpd%I2 %0,%1,%2"
11080   [(set_attr "type" "cmp")])
11081
11082 ;; If we are comparing a register for equality with a large constant,
11083 ;; we can do this with an XOR followed by a compare.  But we need a scratch
11084 ;; register for the result of the XOR.
11085
11086 (define_split
11087   [(set (match_operand:CC 0 "cc_reg_operand" "")
11088         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11089                     (match_operand:SI 2 "non_short_cint_operand" "")))
11090    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
11091   "find_single_use (operands[0], insn, 0)
11092    && (GET_CODE (*find_single_use (operands[0], insn, 0)) == EQ
11093        || GET_CODE (*find_single_use (operands[0], insn, 0)) == NE)"
11094   [(set (match_dup 3) (xor:SI (match_dup 1) (match_dup 4)))
11095    (set (match_dup 0) (compare:CC (match_dup 3) (match_dup 5)))]
11096   "
11097 {
11098   /* Get the constant we are comparing against, C,  and see what it looks like
11099      sign-extended to 16 bits.  Then see what constant could be XOR'ed
11100      with C to get the sign-extended value.  */
11101
11102   HOST_WIDE_INT c = INTVAL (operands[2]);
11103   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
11104   HOST_WIDE_INT xorv = c ^ sextc;
11105
11106   operands[4] = GEN_INT (xorv);
11107   operands[5] = GEN_INT (sextc);
11108 }")
11109
11110 (define_insn "*cmpsi_internal2"
11111   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11112         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11113                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
11114   ""
11115   "{cmpl%I2|cmplw%I2} %0,%1,%b2"
11116   [(set_attr "type" "cmp")])
11117
11118 (define_insn "*cmpdi_internal2"
11119   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11120         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
11121                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
11122   ""
11123   "cmpld%I2 %0,%1,%b2"
11124   [(set_attr "type" "cmp")])
11125
11126 ;; The following two insns don't exist as single insns, but if we provide
11127 ;; them, we can swap an add and compare, which will enable us to overlap more
11128 ;; of the required delay between a compare and branch.  We generate code for
11129 ;; them by splitting.
11130
11131 (define_insn ""
11132   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
11133         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11134                     (match_operand:SI 2 "short_cint_operand" "i")))
11135    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11136         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11137   ""
11138   "#"
11139   [(set_attr "length" "8")])
11140
11141 (define_insn ""
11142   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
11143         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11144                        (match_operand:SI 2 "u_short_cint_operand" "i")))
11145    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11146         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11147   ""
11148   "#"
11149   [(set_attr "length" "8")])
11150
11151 (define_split
11152   [(set (match_operand:CC 3 "cc_reg_operand" "")
11153         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11154                     (match_operand:SI 2 "short_cint_operand" "")))
11155    (set (match_operand:SI 0 "gpc_reg_operand" "")
11156         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11157   ""
11158   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
11159    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11160
11161 (define_split
11162   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
11163         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
11164                        (match_operand:SI 2 "u_short_cint_operand" "")))
11165    (set (match_operand:SI 0 "gpc_reg_operand" "")
11166         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11167   ""
11168   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
11169    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11170
11171 (define_insn "*cmpsf_internal1"
11172   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11173         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
11174                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
11175   "TARGET_HARD_FLOAT && TARGET_FPRS"
11176   "fcmpu %0,%1,%2"
11177   [(set_attr "type" "fpcompare")])
11178
11179 (define_insn "*cmpdf_internal1"
11180   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11181         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "f")
11182                       (match_operand:DF 2 "gpc_reg_operand" "f")))]
11183   "TARGET_HARD_FLOAT && TARGET_FPRS"
11184   "fcmpu %0,%1,%2"
11185   [(set_attr "type" "fpcompare")])
11186
11187 ;; Only need to compare second words if first words equal
11188 (define_insn "*cmptf_internal1"
11189   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11190         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11191                       (match_operand:TF 2 "gpc_reg_operand" "f")))]
11192   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN) && !TARGET_XL_COMPAT
11193    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
11194   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
11195   [(set_attr "type" "fpcompare")
11196    (set_attr "length" "12")])
11197
11198 (define_insn_and_split "*cmptf_internal2"
11199   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11200         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11201                       (match_operand:TF 2 "gpc_reg_operand" "f")))
11202     (clobber (match_scratch:DF 3 "=f"))
11203     (clobber (match_scratch:DF 4 "=f"))
11204     (clobber (match_scratch:DF 5 "=f"))
11205     (clobber (match_scratch:DF 6 "=f"))
11206     (clobber (match_scratch:DF 7 "=f"))
11207     (clobber (match_scratch:DF 8 "=f"))
11208     (clobber (match_scratch:DF 9 "=f"))
11209     (clobber (match_scratch:DF 10 "=f"))]
11210   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN) && TARGET_XL_COMPAT
11211    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
11212   "#"
11213   "&& reload_completed"
11214   [(set (match_dup 3) (match_dup 13))
11215    (set (match_dup 4) (match_dup 14))
11216    (set (match_dup 9) (abs:DF (match_dup 5)))
11217    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
11218    (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
11219                            (label_ref (match_dup 11))
11220                            (pc)))
11221    (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
11222    (set (pc) (label_ref (match_dup 12)))
11223    (match_dup 11)
11224    (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
11225    (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
11226    (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
11227    (set (match_dup 0) (compare:CCFP (match_dup 7) (match_dup 4)))
11228    (match_dup 12)]
11229 {
11230   REAL_VALUE_TYPE rv;
11231   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
11232   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
11233
11234   operands[5] = simplify_gen_subreg (DFmode, operands[1], TFmode, hi_word);
11235   operands[6] = simplify_gen_subreg (DFmode, operands[1], TFmode, lo_word);
11236   operands[7] = simplify_gen_subreg (DFmode, operands[2], TFmode, hi_word);
11237   operands[8] = simplify_gen_subreg (DFmode, operands[2], TFmode, lo_word);
11238   operands[11] = gen_label_rtx ();
11239   operands[12] = gen_label_rtx ();
11240   real_inf (&rv);
11241   operands[13] = force_const_mem (DFmode,
11242                                   CONST_DOUBLE_FROM_REAL_VALUE (rv, DFmode));
11243   operands[14] = force_const_mem (DFmode,
11244                                   CONST_DOUBLE_FROM_REAL_VALUE (dconst0,
11245                                                                 DFmode));
11246   if (TARGET_TOC)
11247     {
11248       operands[13] = gen_const_mem (DFmode,
11249                                     create_TOC_reference (XEXP (operands[13], 0)));
11250       operands[14] = gen_const_mem (DFmode,
11251                                     create_TOC_reference (XEXP (operands[14], 0)));
11252       set_mem_alias_set (operands[13], get_TOC_alias_set ());
11253       set_mem_alias_set (operands[14], get_TOC_alias_set ());
11254     }
11255 })
11256 \f
11257 ;; Now we have the scc insns.  We can do some combinations because of the
11258 ;; way the machine works.
11259 ;;
11260 ;; Note that this is probably faster if we can put an insn between the
11261 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
11262 ;; cases the insns below which don't use an intermediate CR field will
11263 ;; be used instead.
11264 (define_insn ""
11265   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11266         (match_operator:SI 1 "scc_comparison_operator"
11267                            [(match_operand 2 "cc_reg_operand" "y")
11268                             (const_int 0)]))]
11269   ""
11270   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11271   [(set (attr "type")
11272      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11273                 (const_string "mfcrf")
11274            ]
11275         (const_string "mfcr")))
11276    (set_attr "length" "8")])
11277
11278 ;; Same as above, but get the GT bit.
11279 (define_insn "move_from_CR_gt_bit"
11280   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11281         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
11282   "TARGET_E500"
11283   "mfcr %0\;{rlinm|rlwinm} %0,%0,%D1,31,31"
11284   [(set_attr "type" "mfcr")
11285    (set_attr "length" "8")])
11286
11287 ;; Same as above, but get the OV/ORDERED bit.
11288 (define_insn "move_from_CR_ov_bit"
11289   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11290         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_OV))]
11291   "TARGET_ISEL"
11292   "mfcr %0\;{rlinm|rlwinm} %0,%0,%t1,1"
11293   [(set_attr "type" "mfcr")
11294    (set_attr "length" "8")])
11295
11296 (define_insn ""
11297   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11298         (match_operator:DI 1 "scc_comparison_operator"
11299                            [(match_operand 2 "cc_reg_operand" "y")
11300                             (const_int 0)]))]
11301   "TARGET_POWERPC64"
11302   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11303   [(set (attr "type")
11304      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11305                 (const_string "mfcrf")
11306            ]
11307         (const_string "mfcr")))
11308    (set_attr "length" "8")])
11309
11310 (define_insn ""
11311   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11312         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11313                                        [(match_operand 2 "cc_reg_operand" "y,y")
11314                                         (const_int 0)])
11315                     (const_int 0)))
11316    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11317         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11318   "TARGET_32BIT"
11319   "@
11320    mfcr %3%Q2\;{rlinm.|rlwinm.} %3,%3,%J1,1
11321    #"
11322   [(set_attr "type" "delayed_compare")
11323    (set_attr "length" "8,16")])
11324
11325 (define_split
11326   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11327         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11328                                        [(match_operand 2 "cc_reg_operand" "")
11329                                         (const_int 0)])
11330                     (const_int 0)))
11331    (set (match_operand:SI 3 "gpc_reg_operand" "")
11332         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11333   "TARGET_32BIT && reload_completed"
11334   [(set (match_dup 3)
11335         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
11336    (set (match_dup 0)
11337         (compare:CC (match_dup 3)
11338                     (const_int 0)))]
11339   "")
11340
11341 (define_insn ""
11342   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11343         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11344                                       [(match_operand 2 "cc_reg_operand" "y")
11345                                        (const_int 0)])
11346                    (match_operand:SI 3 "const_int_operand" "n")))]
11347   ""
11348   "*
11349 {
11350   int is_bit = ccr_bit (operands[1], 1);
11351   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11352   int count;
11353
11354   if (is_bit >= put_bit)
11355     count = is_bit - put_bit;
11356   else
11357     count = 32 - (put_bit - is_bit);
11358
11359   operands[4] = GEN_INT (count);
11360   operands[5] = GEN_INT (put_bit);
11361
11362   return \"mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
11363 }"
11364   [(set (attr "type")
11365      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11366                 (const_string "mfcrf")
11367            ]
11368         (const_string "mfcr")))
11369    (set_attr "length" "8")])
11370
11371 (define_insn ""
11372   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11373         (compare:CC
11374          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11375                                        [(match_operand 2 "cc_reg_operand" "y,y")
11376                                         (const_int 0)])
11377                     (match_operand:SI 3 "const_int_operand" "n,n"))
11378          (const_int 0)))
11379    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
11380         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11381                    (match_dup 3)))]
11382   ""
11383   "*
11384 {
11385   int is_bit = ccr_bit (operands[1], 1);
11386   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11387   int count;
11388
11389   /* Force split for non-cc0 compare.  */
11390   if (which_alternative == 1)
11391      return \"#\";
11392
11393   if (is_bit >= put_bit)
11394     count = is_bit - put_bit;
11395   else
11396     count = 32 - (put_bit - is_bit);
11397
11398   operands[5] = GEN_INT (count);
11399   operands[6] = GEN_INT (put_bit);
11400
11401   return \"mfcr %4%Q2\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
11402 }"
11403   [(set_attr "type" "delayed_compare")
11404    (set_attr "length" "8,16")])
11405
11406 (define_split
11407   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11408         (compare:CC
11409          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11410                                        [(match_operand 2 "cc_reg_operand" "")
11411                                         (const_int 0)])
11412                     (match_operand:SI 3 "const_int_operand" ""))
11413          (const_int 0)))
11414    (set (match_operand:SI 4 "gpc_reg_operand" "")
11415         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11416                    (match_dup 3)))]
11417   "reload_completed"
11418   [(set (match_dup 4)
11419         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11420                    (match_dup 3)))
11421    (set (match_dup 0)
11422         (compare:CC (match_dup 4)
11423                     (const_int 0)))]
11424   "")
11425
11426 ;; There is a 3 cycle delay between consecutive mfcr instructions
11427 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
11428
11429 (define_peephole
11430   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11431         (match_operator:SI 1 "scc_comparison_operator"
11432                            [(match_operand 2 "cc_reg_operand" "y")
11433                             (const_int 0)]))
11434    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
11435         (match_operator:SI 4 "scc_comparison_operator"
11436                            [(match_operand 5 "cc_reg_operand" "y")
11437                             (const_int 0)]))]
11438   "REGNO (operands[2]) != REGNO (operands[5])"
11439   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11440   [(set_attr "type" "mfcr")
11441    (set_attr "length" "12")])
11442
11443 (define_peephole
11444   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11445         (match_operator:DI 1 "scc_comparison_operator"
11446                            [(match_operand 2 "cc_reg_operand" "y")
11447                             (const_int 0)]))
11448    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
11449         (match_operator:DI 4 "scc_comparison_operator"
11450                            [(match_operand 5 "cc_reg_operand" "y")
11451                             (const_int 0)]))]
11452   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
11453   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11454   [(set_attr "type" "mfcr")
11455    (set_attr "length" "12")])
11456
11457 ;; There are some scc insns that can be done directly, without a compare.
11458 ;; These are faster because they don't involve the communications between
11459 ;; the FXU and branch units.   In fact, we will be replacing all of the
11460 ;; integer scc insns here or in the portable methods in emit_store_flag.
11461 ;;
11462 ;; Also support (neg (scc ..)) since that construct is used to replace
11463 ;; branches, (plus (scc ..) ..) since that construct is common and
11464 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
11465 ;; cases where it is no more expensive than (neg (scc ..)).
11466
11467 ;; Have reload force a constant into a register for the simple insns that
11468 ;; otherwise won't accept constants.  We do this because it is faster than
11469 ;; the cmp/mfcr sequence we would otherwise generate.
11470
11471 (define_mode_attr scc_eq_op2 [(SI "rKLI")
11472                               (DI "rKJI")])
11473
11474 (define_insn_and_split "*eq<mode>"
11475   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
11476         (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
11477                 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))
11478    (clobber (match_scratch:GPR 3 "=r"))
11479    (clobber (match_scratch:GPR 4 "=r"))]
11480   ""
11481   "#"
11482   "reload_completed"
11483   [(set (match_dup 3)
11484         (clz:GPR (match_dup 4)))
11485    (set (match_dup 0)
11486         (lshiftrt:GPR (match_dup 3) (match_dup 5)))]
11487   {
11488     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
11489       {
11490         if (logical_operand (operands[2], <MODE>mode))
11491           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
11492                                   gen_rtx_XOR (<MODE>mode,
11493                                                operands[1], operands[2])));
11494         else
11495           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
11496                                   gen_rtx_PLUS (<MODE>mode, operands[1],
11497                                                 negate_rtx (<MODE>mode,
11498                                                             operands[2]))));
11499       }
11500     else
11501       operands[4] = operands[1];
11502
11503     operands[5] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
11504   })
11505
11506 (define_insn_and_split "*eq<mode>_compare"
11507   [(set (match_operand:CC 5 "cc_reg_operand" "=y")
11508         (compare:CC
11509          (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "=r")
11510                  (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>"))
11511          (const_int 0)))
11512    (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
11513         (eq:GPR (match_dup 1) (match_dup 2)))
11514    (clobber (match_scratch:GPR 3 "=r"))
11515    (clobber (match_scratch:GPR 4 "=r"))]
11516   ""
11517   "#"
11518   "reload_completed"
11519   [(set (match_dup 3)
11520         (clz:GPR (match_dup 4)))
11521    (parallel [(set (match_dup 5)
11522                    (compare:CC (lshiftrt:GPR (match_dup 3) (match_dup 6))
11523                                (const_int 0)))
11524               (set (match_dup 0)
11525                    (lshiftrt:GPR (match_dup 3) (match_dup 6)))])]
11526   {
11527     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
11528       {
11529         if (logical_operand (operands[2], <MODE>mode))
11530           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
11531                                   gen_rtx_XOR (<MODE>mode,
11532                                                operands[1], operands[2])));
11533         else
11534           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
11535                                   gen_rtx_PLUS (<MODE>mode, operands[1],
11536                                                 negate_rtx (<MODE>mode,
11537                                                             operands[2]))));
11538       }
11539     else
11540       operands[4] = operands[1];
11541
11542     operands[6] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
11543   })
11544
11545 ;; We have insns of the form shown by the first define_insn below.  If
11546 ;; there is something inside the comparison operation, we must split it.
11547 (define_split
11548   [(set (match_operand:SI 0 "gpc_reg_operand" "")
11549         (plus:SI (match_operator 1 "comparison_operator"
11550                                  [(match_operand:SI 2 "" "")
11551                                   (match_operand:SI 3
11552                                                     "reg_or_cint_operand" "")])
11553                  (match_operand:SI 4 "gpc_reg_operand" "")))
11554    (clobber (match_operand:SI 5 "register_operand" ""))]
11555   "! gpc_reg_operand (operands[2], SImode)"
11556   [(set (match_dup 5) (match_dup 2))
11557    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
11558                                (match_dup 4)))])
11559
11560 (define_insn ""
11561   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
11562         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11563                         (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I"))
11564                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
11565   "TARGET_32BIT"
11566   "@
11567    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11568    {sfi|subfic} %0,%1,0\;{aze|addze} %0,%3
11569    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11570    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11571    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
11572   [(set_attr "type" "three,two,three,three,three")
11573    (set_attr "length" "12,8,12,12,12")])
11574
11575 (define_insn ""
11576   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11577         (compare:CC
11578          (plus:SI
11579           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11580                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11581           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11582          (const_int 0)))
11583    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
11584   "TARGET_32BIT"
11585   "@
11586    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11587    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
11588    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11589    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11590    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11591    #
11592    #
11593    #
11594    #
11595    #"
11596   [(set_attr "type" "compare")
11597    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11598
11599 (define_split
11600   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11601         (compare:CC
11602          (plus:SI
11603           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11604                  (match_operand:SI 2 "reg_or_cint_operand" ""))
11605           (match_operand:SI 3 "gpc_reg_operand" ""))
11606          (const_int 0)))
11607    (clobber (match_scratch:SI 4 ""))]
11608   "TARGET_32BIT && reload_completed"
11609   [(set (match_dup 4)
11610         (plus:SI (eq:SI (match_dup 1)
11611                  (match_dup 2))
11612           (match_dup 3)))
11613    (set (match_dup 0)
11614         (compare:CC (match_dup 4)
11615                     (const_int 0)))]
11616   "")
11617
11618 (define_insn ""
11619   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11620         (compare:CC
11621          (plus:SI
11622           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11623                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11624           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11625          (const_int 0)))
11626    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
11627         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11628   "TARGET_32BIT"
11629   "@
11630    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11631    {sfi|subfic} %0,%1,0\;{aze.|addze.} %0,%3
11632    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11633    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11634    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11635    #
11636    #
11637    #
11638    #
11639    #"
11640   [(set_attr "type" "compare")
11641    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11642
11643 (define_split
11644   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11645         (compare:CC
11646          (plus:SI
11647           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11648                  (match_operand:SI 2 "reg_or_cint_operand" ""))
11649           (match_operand:SI 3 "gpc_reg_operand" ""))
11650          (const_int 0)))
11651    (set (match_operand:SI 0 "gpc_reg_operand" "")
11652         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11653   "TARGET_32BIT && reload_completed"
11654   [(set (match_dup 0)
11655         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
11656    (set (match_dup 4)
11657         (compare:CC (match_dup 0)
11658                     (const_int 0)))]
11659   "")
11660
11661 (define_insn ""
11662   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
11663         (neg:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11664                        (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I"))))]
11665   "TARGET_32BIT"
11666   "@
11667    xor %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11668    {ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0
11669    {xoril|xori} %0,%1,%b2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11670    {xoriu|xoris} %0,%1,%u2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11671    {sfi|subfic} %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
11672    [(set_attr "type" "three,two,three,three,three")
11673     (set_attr "length" "12,8,12,12,12")])
11674
11675 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
11676 ;; since it nabs/sr is just as fast.
11677 (define_insn "*ne0"
11678   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
11679         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
11680                      (const_int 31)))
11681    (clobber (match_scratch:SI 2 "=&r"))]
11682   "! TARGET_POWER && TARGET_32BIT && !TARGET_ISEL"
11683   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
11684   [(set_attr "type" "two")
11685    (set_attr "length" "8")])
11686
11687 (define_insn ""
11688   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11689         (lshiftrt:DI (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
11690                      (const_int 63)))
11691    (clobber (match_scratch:DI 2 "=&r"))]
11692   "TARGET_64BIT"
11693   "addic %2,%1,-1\;subfe %0,%2,%1"
11694   [(set_attr "type" "two")
11695    (set_attr "length" "8")])
11696
11697 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
11698 (define_insn ""
11699   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11700         (plus:SI (lshiftrt:SI
11701                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
11702                   (const_int 31))
11703                  (match_operand:SI 2 "gpc_reg_operand" "r")))
11704    (clobber (match_scratch:SI 3 "=&r"))]
11705   "TARGET_32BIT"
11706   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
11707   [(set_attr "type" "two")
11708    (set_attr "length" "8")])
11709
11710 (define_insn ""
11711   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11712         (plus:DI (lshiftrt:DI
11713                   (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
11714                   (const_int 63))
11715                  (match_operand:DI 2 "gpc_reg_operand" "r")))
11716    (clobber (match_scratch:DI 3 "=&r"))]
11717   "TARGET_64BIT"
11718   "addic %3,%1,-1\;addze %0,%2"
11719   [(set_attr "type" "two")
11720    (set_attr "length" "8")])
11721
11722 (define_insn ""
11723   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11724         (compare:CC
11725          (plus:SI (lshiftrt:SI
11726                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
11727                    (const_int 31))
11728                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
11729          (const_int 0)))
11730    (clobber (match_scratch:SI 3 "=&r,&r"))
11731    (clobber (match_scratch:SI 4 "=X,&r"))]
11732   "TARGET_32BIT"
11733   "@
11734    {ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2
11735    #"
11736   [(set_attr "type" "compare")
11737    (set_attr "length" "8,12")])
11738
11739 (define_split
11740   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11741         (compare:CC
11742          (plus:SI (lshiftrt:SI
11743                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11744                    (const_int 31))
11745                   (match_operand:SI 2 "gpc_reg_operand" ""))
11746          (const_int 0)))
11747    (clobber (match_scratch:SI 3 ""))
11748    (clobber (match_scratch:SI 4 ""))]
11749   "TARGET_32BIT && reload_completed"
11750   [(parallel [(set (match_dup 3)
11751                    (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1)))
11752                                          (const_int 31))
11753                             (match_dup 2)))
11754               (clobber (match_dup 4))])
11755    (set (match_dup 0)
11756         (compare:CC (match_dup 3)
11757                     (const_int 0)))]
11758   "")
11759
11760 (define_insn ""
11761   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11762         (compare:CC
11763          (plus:DI (lshiftrt:DI
11764                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
11765                    (const_int 63))
11766                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
11767          (const_int 0)))
11768    (clobber (match_scratch:DI 3 "=&r,&r"))]
11769   "TARGET_64BIT"
11770   "@
11771    addic %3,%1,-1\;addze. %3,%2
11772    #"
11773   [(set_attr "type" "compare")
11774    (set_attr "length" "8,12")])
11775
11776 (define_split
11777   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11778         (compare:CC
11779          (plus:DI (lshiftrt:DI
11780                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
11781                    (const_int 63))
11782                   (match_operand:DI 2 "gpc_reg_operand" ""))
11783          (const_int 0)))
11784    (clobber (match_scratch:DI 3 ""))]
11785   "TARGET_64BIT && reload_completed"
11786   [(set (match_dup 3)
11787         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1)))
11788                    (const_int 63))
11789                   (match_dup 2)))
11790    (set (match_dup 0)
11791         (compare:CC (match_dup 3)
11792                     (const_int 0)))]
11793   "")
11794
11795 (define_insn ""
11796   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
11797         (compare:CC
11798          (plus:SI (lshiftrt:SI
11799                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
11800                    (const_int 31))
11801                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
11802          (const_int 0)))
11803    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11804         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11805                  (match_dup 2)))
11806    (clobber (match_scratch:SI 3 "=&r,&r"))]
11807   "TARGET_32BIT"
11808   "@
11809    {ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2
11810    #"
11811   [(set_attr "type" "compare")
11812    (set_attr "length" "8,12")])
11813
11814 (define_split
11815   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11816         (compare:CC
11817          (plus:SI (lshiftrt:SI
11818                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11819                    (const_int 31))
11820                   (match_operand:SI 2 "gpc_reg_operand" ""))
11821          (const_int 0)))
11822    (set (match_operand:SI 0 "gpc_reg_operand" "")
11823         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11824                  (match_dup 2)))
11825    (clobber (match_scratch:SI 3 ""))]
11826   "TARGET_32BIT && reload_completed"
11827   [(parallel [(set (match_dup 0)
11828         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11829                  (match_dup 2)))
11830    (clobber (match_dup 3))])
11831    (set (match_dup 4)
11832         (compare:CC (match_dup 0)
11833                     (const_int 0)))]
11834   "")
11835
11836 (define_insn ""
11837   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
11838         (compare:CC
11839          (plus:DI (lshiftrt:DI
11840                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
11841                    (const_int 63))
11842                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
11843          (const_int 0)))
11844    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
11845         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11846                  (match_dup 2)))
11847    (clobber (match_scratch:DI 3 "=&r,&r"))]
11848   "TARGET_64BIT"
11849   "@
11850    addic %3,%1,-1\;addze. %0,%2
11851    #"
11852   [(set_attr "type" "compare")
11853    (set_attr "length" "8,12")])
11854
11855 (define_split
11856   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11857         (compare:CC
11858          (plus:DI (lshiftrt:DI
11859                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
11860                    (const_int 63))
11861                   (match_operand:DI 2 "gpc_reg_operand" ""))
11862          (const_int 0)))
11863    (set (match_operand:DI 0 "gpc_reg_operand" "")
11864         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11865                  (match_dup 2)))
11866    (clobber (match_scratch:DI 3 ""))]
11867   "TARGET_64BIT && reload_completed"
11868   [(parallel [(set (match_dup 0)
11869         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11870                  (match_dup 2)))
11871    (clobber (match_dup 3))])
11872    (set (match_dup 4)
11873         (compare:CC (match_dup 0)
11874                     (const_int 0)))]
11875   "")
11876
11877 (define_insn ""
11878   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11879         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
11880                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
11881    (clobber (match_scratch:SI 3 "=r,X"))]
11882   "TARGET_POWER"
11883   "@
11884    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
11885    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
11886   [(set_attr "length" "12")])
11887
11888 (define_insn ""
11889   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
11890         (compare:CC
11891          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
11892                 (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
11893          (const_int 0)))
11894    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
11895         (le:SI (match_dup 1) (match_dup 2)))
11896    (clobber (match_scratch:SI 3 "=r,X,r,X"))]
11897   "TARGET_POWER"
11898   "@
11899    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
11900    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31
11901    #
11902    #"
11903   [(set_attr "type" "compare,delayed_compare,compare,delayed_compare")
11904    (set_attr "length" "12,12,16,16")])
11905
11906 (define_split
11907   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11908         (compare:CC
11909          (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
11910                 (match_operand:SI 2 "reg_or_short_operand" ""))
11911          (const_int 0)))
11912    (set (match_operand:SI 0 "gpc_reg_operand" "")
11913         (le:SI (match_dup 1) (match_dup 2)))
11914    (clobber (match_scratch:SI 3 ""))]
11915   "TARGET_POWER && reload_completed"
11916   [(parallel [(set (match_dup 0)
11917         (le:SI (match_dup 1) (match_dup 2)))
11918    (clobber (match_dup 3))])
11919    (set (match_dup 4)
11920         (compare:CC (match_dup 0)
11921                     (const_int 0)))]
11922   "")
11923
11924 (define_insn ""
11925   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
11926         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
11927                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
11928                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
11929   "TARGET_POWER"
11930   "@
11931    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11932    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze|addze} %0,%3"
11933   [(set_attr "length" "12")])
11934
11935 (define_insn ""
11936   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
11937         (compare:CC
11938          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
11939                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
11940                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
11941          (const_int 0)))
11942    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
11943   "TARGET_POWER"
11944   "@
11945    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11946    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3
11947    #
11948    #"
11949   [(set_attr "type" "compare")
11950    (set_attr "length" "12,12,16,16")])
11951
11952 (define_split
11953   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11954         (compare:CC
11955          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
11956                          (match_operand:SI 2 "reg_or_short_operand" ""))
11957                   (match_operand:SI 3 "gpc_reg_operand" ""))
11958          (const_int 0)))
11959    (clobber (match_scratch:SI 4 ""))]
11960   "TARGET_POWER && reload_completed"
11961   [(set (match_dup 4)
11962         (plus:SI (le:SI (match_dup 1) (match_dup 2))
11963                  (match_dup 3)))
11964    (set (match_dup 0)
11965         (compare:CC (match_dup 4)
11966                     (const_int 0)))]
11967   "")
11968
11969 (define_insn ""
11970   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
11971         (compare:CC
11972          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
11973                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
11974                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
11975          (const_int 0)))
11976    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
11977         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11978   "TARGET_POWER"
11979   "@
11980    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11981    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze.|addze.} %0,%3
11982    #
11983    #"
11984   [(set_attr "type" "compare")
11985    (set_attr "length" "12,12,16,16")])
11986
11987 (define_split
11988   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11989         (compare:CC
11990          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
11991                          (match_operand:SI 2 "reg_or_short_operand" ""))
11992                   (match_operand:SI 3 "gpc_reg_operand" ""))
11993          (const_int 0)))
11994    (set (match_operand:SI 0 "gpc_reg_operand" "")
11995         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11996   "TARGET_POWER && reload_completed"
11997   [(set (match_dup 0)
11998         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
11999    (set (match_dup 4)
12000         (compare:CC (match_dup 0)
12001                     (const_int 0)))]
12002   "")
12003
12004 (define_insn ""
12005   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12006         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12007                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
12008   "TARGET_POWER"
12009   "@
12010    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
12011    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
12012   [(set_attr "length" "12")])
12013
12014 (define_insn ""
12015   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12016         (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12017                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12018   "TARGET_32BIT"
12019   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12020   [(set_attr "type" "three")
12021    (set_attr "length" "12")])
12022
12023 (define_insn ""
12024   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12025         (leu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
12026                 (match_operand:DI 2 "reg_or_short_operand" "rI")))]
12027   "TARGET_64BIT"
12028   "subf%I2c %0,%1,%2\;li %0,0\;adde %0,%0,%0"
12029   [(set_attr "type" "three")
12030    (set_attr "length" "12")])
12031
12032 (define_insn ""
12033   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12034         (compare:CC
12035          (leu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12036                  (match_operand:DI 2 "reg_or_short_operand" "rI,rI"))
12037          (const_int 0)))
12038    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12039         (leu:DI (match_dup 1) (match_dup 2)))]
12040   "TARGET_64BIT"
12041   "@
12042    subf%I2c %0,%1,%2\;li %0,0\;adde. %0,%0,%0
12043    #"
12044   [(set_attr "type" "compare")
12045    (set_attr "length" "12,16")])
12046
12047 (define_split
12048   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12049         (compare:CC
12050          (leu:DI (match_operand:DI 1 "gpc_reg_operand" "")
12051                  (match_operand:DI 2 "reg_or_short_operand" ""))
12052          (const_int 0)))
12053    (set (match_operand:DI 0 "gpc_reg_operand" "")
12054         (leu:DI (match_dup 1) (match_dup 2)))]
12055   "TARGET_64BIT && reload_completed"
12056   [(set (match_dup 0)
12057         (leu:DI (match_dup 1) (match_dup 2)))
12058    (set (match_dup 3)
12059         (compare:CC (match_dup 0)
12060                     (const_int 0)))]
12061   "")
12062
12063 (define_insn ""
12064   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12065         (compare:CC
12066          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12067                  (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12068          (const_int 0)))
12069    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12070         (leu:SI (match_dup 1) (match_dup 2)))]
12071   "TARGET_32BIT"
12072   "@
12073    {sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12074    #"
12075   [(set_attr "type" "compare")
12076    (set_attr "length" "12,16")])
12077
12078 (define_split
12079   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12080         (compare:CC
12081          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12082                  (match_operand:SI 2 "reg_or_short_operand" ""))
12083          (const_int 0)))
12084    (set (match_operand:SI 0 "gpc_reg_operand" "")
12085         (leu:SI (match_dup 1) (match_dup 2)))]
12086   "TARGET_32BIT && reload_completed"
12087   [(set (match_dup 0)
12088         (leu:SI (match_dup 1) (match_dup 2)))
12089    (set (match_dup 3)
12090         (compare:CC (match_dup 0)
12091                     (const_int 0)))]
12092   "")
12093
12094 (define_insn ""
12095   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12096         (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12097                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
12098                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12099   "TARGET_32BIT"
12100   "{sf%I2|subf%I2c} %0,%1,%2\;{aze|addze} %0,%3"
12101   [(set_attr "type" "two")
12102    (set_attr "length" "8")])
12103
12104 (define_insn ""
12105   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12106         (compare:CC
12107          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12108                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12109                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12110          (const_int 0)))
12111    (clobber (match_scratch:SI 4 "=&r,&r"))]
12112   "TARGET_32BIT"
12113   "@
12114    {sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3
12115    #"
12116   [(set_attr "type" "compare")
12117    (set_attr "length" "8,12")])
12118
12119 (define_split
12120   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12121         (compare:CC
12122          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12123                           (match_operand:SI 2 "reg_or_short_operand" ""))
12124                   (match_operand:SI 3 "gpc_reg_operand" ""))
12125          (const_int 0)))
12126    (clobber (match_scratch:SI 4 ""))]
12127   "TARGET_32BIT && reload_completed"
12128   [(set (match_dup 4)
12129         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
12130                   (match_dup 3)))
12131    (set (match_dup 0)
12132         (compare:CC (match_dup 4)
12133                     (const_int 0)))]
12134   "")
12135
12136 (define_insn ""
12137   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12138         (compare:CC
12139          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12140                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12141                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12142          (const_int 0)))
12143    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12144         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12145   "TARGET_32BIT"
12146   "@
12147    {sf%I2|subf%I2c} %0,%1,%2\;{aze.|addze.} %0,%3
12148    #"
12149   [(set_attr "type" "compare")
12150    (set_attr "length" "8,12")])
12151
12152 (define_split
12153   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12154         (compare:CC
12155          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12156                           (match_operand:SI 2 "reg_or_short_operand" ""))
12157                   (match_operand:SI 3 "gpc_reg_operand" ""))
12158          (const_int 0)))
12159    (set (match_operand:SI 0 "gpc_reg_operand" "")
12160         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12161   "TARGET_32BIT && reload_completed"
12162   [(set (match_dup 0)
12163         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12164    (set (match_dup 4)
12165         (compare:CC (match_dup 0)
12166                     (const_int 0)))]
12167   "")
12168
12169 (define_insn ""
12170   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12171         (neg:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12172                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12173   "TARGET_32BIT"
12174   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
12175    [(set_attr "type" "three")
12176     (set_attr "length" "12")])
12177
12178 (define_insn ""
12179   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12180         (and:SI (neg:SI
12181                  (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12182                          (match_operand:SI 2 "reg_or_short_operand" "rI")))
12183                 (match_operand:SI 3 "gpc_reg_operand" "r")))]
12184   "TARGET_32BIT"
12185   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12186   [(set_attr "type" "three")
12187    (set_attr "length" "12")])
12188
12189 (define_insn ""
12190   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12191         (compare:CC
12192          (and:SI (neg:SI
12193                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12194                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12195                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12196          (const_int 0)))
12197    (clobber (match_scratch:SI 4 "=&r,&r"))]
12198   "TARGET_32BIT"
12199   "@
12200    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12201    #"
12202   [(set_attr "type" "compare")
12203    (set_attr "length" "12,16")])
12204
12205 (define_split
12206   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12207         (compare:CC
12208          (and:SI (neg:SI
12209                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12210                           (match_operand:SI 2 "reg_or_short_operand" "")))
12211                  (match_operand:SI 3 "gpc_reg_operand" ""))
12212          (const_int 0)))
12213    (clobber (match_scratch:SI 4 ""))]
12214   "TARGET_32BIT && reload_completed"
12215   [(set (match_dup 4)
12216         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12217                 (match_dup 3)))
12218    (set (match_dup 0)
12219         (compare:CC (match_dup 4)
12220                     (const_int 0)))]
12221   "")
12222
12223 (define_insn ""
12224   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12225         (compare:CC
12226          (and:SI (neg:SI
12227                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12228                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12229                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12230          (const_int 0)))
12231    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12232         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12233   "TARGET_32BIT"
12234   "@
12235    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12236    #"
12237   [(set_attr "type" "compare")
12238    (set_attr "length" "12,16")])
12239
12240 (define_split
12241   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12242         (compare:CC
12243          (and:SI (neg:SI
12244                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12245                           (match_operand:SI 2 "reg_or_short_operand" "")))
12246                  (match_operand:SI 3 "gpc_reg_operand" ""))
12247          (const_int 0)))
12248    (set (match_operand:SI 0 "gpc_reg_operand" "")
12249         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12250   "TARGET_32BIT && reload_completed"
12251   [(set (match_dup 0)
12252         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12253                 (match_dup 3)))
12254    (set (match_dup 4)
12255         (compare:CC (match_dup 0)
12256                     (const_int 0)))]
12257   "")
12258
12259 (define_insn ""
12260   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12261         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12262                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12263   "TARGET_POWER"
12264   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
12265    [(set_attr "length" "12")])
12266
12267 (define_insn ""
12268   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12269         (compare:CC
12270          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12271                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12272          (const_int 0)))
12273    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12274         (lt:SI (match_dup 1) (match_dup 2)))]
12275   "TARGET_POWER"
12276   "@
12277    doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
12278    #"
12279   [(set_attr "type" "delayed_compare")
12280    (set_attr "length" "12,16")])
12281
12282 (define_split
12283   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12284         (compare:CC
12285          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12286                 (match_operand:SI 2 "reg_or_short_operand" ""))
12287          (const_int 0)))
12288    (set (match_operand:SI 0 "gpc_reg_operand" "")
12289         (lt:SI (match_dup 1) (match_dup 2)))]
12290   "TARGET_POWER && reload_completed"
12291   [(set (match_dup 0)
12292         (lt:SI (match_dup 1) (match_dup 2)))
12293    (set (match_dup 3)
12294         (compare:CC (match_dup 0)
12295                     (const_int 0)))]
12296   "")
12297
12298 (define_insn ""
12299   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12300         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12301                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12302                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12303   "TARGET_POWER"
12304   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
12305   [(set_attr "length" "12")])
12306
12307 (define_insn ""
12308   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12309         (compare:CC
12310          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12311                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12312                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12313          (const_int 0)))
12314    (clobber (match_scratch:SI 4 "=&r,&r"))]
12315   "TARGET_POWER"
12316   "@
12317    doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
12318    #"
12319   [(set_attr "type" "compare")
12320    (set_attr "length" "12,16")])
12321
12322 (define_split
12323   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12324         (compare:CC
12325          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12326                          (match_operand:SI 2 "reg_or_short_operand" ""))
12327                   (match_operand:SI 3 "gpc_reg_operand" ""))
12328          (const_int 0)))
12329    (clobber (match_scratch:SI 4 ""))]
12330   "TARGET_POWER && reload_completed"
12331   [(set (match_dup 4)
12332         (plus:SI (lt:SI (match_dup 1) (match_dup 2))
12333                  (match_dup 3)))
12334    (set (match_dup 0)
12335         (compare:CC (match_dup 4)
12336                     (const_int 0)))]
12337   "")
12338
12339 (define_insn ""
12340   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12341         (compare:CC
12342          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12343                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12344                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12345          (const_int 0)))
12346    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12347         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12348   "TARGET_POWER"
12349   "@
12350    doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
12351    #"
12352   [(set_attr "type" "compare")
12353    (set_attr "length" "12,16")])
12354
12355 (define_split
12356   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12357         (compare:CC
12358          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12359                          (match_operand:SI 2 "reg_or_short_operand" ""))
12360                   (match_operand:SI 3 "gpc_reg_operand" ""))
12361          (const_int 0)))
12362    (set (match_operand:SI 0 "gpc_reg_operand" "")
12363         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12364   "TARGET_POWER && reload_completed"
12365   [(set (match_dup 0)
12366         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12367    (set (match_dup 4)
12368         (compare:CC (match_dup 0)
12369                     (const_int 0)))]
12370   "")
12371
12372 (define_insn ""
12373   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12374         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12375                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12376   "TARGET_POWER"
12377   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
12378   [(set_attr "length" "12")])
12379
12380 (define_insn_and_split ""
12381   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12382         (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12383                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
12384   "TARGET_32BIT"
12385   "#"
12386   "TARGET_32BIT"
12387   [(set (match_dup 0) (neg:SI (ltu:SI (match_dup 1) (match_dup 2))))
12388    (set (match_dup 0) (neg:SI (match_dup 0)))]
12389   "")
12390
12391 (define_insn_and_split ""
12392   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12393         (ltu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12394                 (match_operand:DI 2 "reg_or_neg_short_operand" "r,P")))]
12395   "TARGET_64BIT"
12396   "#"
12397   "TARGET_64BIT"
12398   [(set (match_dup 0) (neg:DI (ltu:DI (match_dup 1) (match_dup 2))))
12399    (set (match_dup 0) (neg:DI (match_dup 0)))]
12400   "")
12401
12402 (define_insn ""
12403   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12404         (compare:CC
12405          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12406                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12407          (const_int 0)))
12408    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12409         (ltu:SI (match_dup 1) (match_dup 2)))]
12410   "TARGET_32BIT"
12411   "@
12412    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
12413    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
12414    #
12415    #"
12416   [(set_attr "type" "compare")
12417    (set_attr "length" "12,12,16,16")])
12418
12419 (define_split
12420   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12421         (compare:CC
12422          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12423                  (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12424          (const_int 0)))
12425    (set (match_operand:SI 0 "gpc_reg_operand" "")
12426         (ltu:SI (match_dup 1) (match_dup 2)))]
12427   "TARGET_32BIT && reload_completed"
12428   [(set (match_dup 0)
12429         (ltu:SI (match_dup 1) (match_dup 2)))
12430    (set (match_dup 3)
12431         (compare:CC (match_dup 0)
12432                     (const_int 0)))]
12433   "")
12434
12435 (define_insn_and_split ""
12436   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
12437         (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12438                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
12439                  (match_operand:SI 3 "reg_or_short_operand" "rI,rI")))]
12440   "TARGET_32BIT"
12441   "#"
12442   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
12443   [(set (match_dup 0) (neg:SI (ltu:SI (match_dup 1) (match_dup 2))))
12444    (set (match_dup 0) (minus:SI (match_dup 3) (match_dup 0)))]
12445   "")
12446
12447 (define_insn_and_split ""
12448   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
12449         (plus:DI (ltu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12450                          (match_operand:DI 2 "reg_or_neg_short_operand" "r,P"))
12451                  (match_operand:DI 3 "reg_or_short_operand" "rI,rI")))]
12452   "TARGET_64BIT"
12453   "#"
12454   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
12455   [(set (match_dup 0) (neg:DI (ltu:DI (match_dup 1) (match_dup 2))))
12456    (set (match_dup 0) (minus:DI (match_dup 3) (match_dup 0)))]
12457   "")
12458
12459 (define_insn ""
12460   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12461         (compare:CC
12462          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12463                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12464                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12465          (const_int 0)))
12466    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12467   "TARGET_32BIT"
12468   "@
12469    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf.|subf.} %4,%4,%3
12470    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf.|subf.} %4,%4,%3
12471    #
12472    #"
12473   [(set_attr "type" "compare")
12474    (set_attr "length" "12,12,16,16")])
12475
12476 (define_split
12477   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12478         (compare:CC
12479          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12480                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12481                   (match_operand:SI 3 "gpc_reg_operand" ""))
12482          (const_int 0)))
12483    (clobber (match_scratch:SI 4 ""))]
12484   "TARGET_32BIT && reload_completed"
12485   [(set (match_dup 4)
12486         (plus:SI (ltu:SI (match_dup 1) (match_dup 2))
12487                  (match_dup 3)))
12488    (set (match_dup 0)
12489         (compare:CC (match_dup 4)
12490                     (const_int 0)))]
12491   "")
12492
12493 (define_insn ""
12494   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12495         (compare:CC
12496          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12497                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12498                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12499          (const_int 0)))
12500    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12501         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12502   "TARGET_32BIT"
12503   "@
12504    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;{sf.|subf.} %0,%0,%3
12505    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;{sf.|subf.} %0,%0,%3
12506    #
12507    #"
12508   [(set_attr "type" "compare")
12509    (set_attr "length" "12,12,16,16")])
12510
12511 (define_split
12512   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12513         (compare:CC
12514          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12515                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12516                   (match_operand:SI 3 "gpc_reg_operand" ""))
12517          (const_int 0)))
12518    (set (match_operand:SI 0 "gpc_reg_operand" "")
12519         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12520   "TARGET_32BIT && reload_completed"
12521   [(set (match_dup 0)
12522         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12523    (set (match_dup 4)
12524         (compare:CC (match_dup 0)
12525                     (const_int 0)))]
12526   "")
12527
12528 (define_insn ""
12529   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12530         (neg:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12531                         (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))))]
12532   "TARGET_32BIT"
12533   "@
12534    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
12535    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
12536   [(set_attr "type" "two")
12537    (set_attr "length" "8")])
12538
12539 (define_insn ""
12540   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12541         (neg:DI (ltu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12542                         (match_operand:DI 2 "reg_or_neg_short_operand" "r,P"))))]
12543   "TARGET_64BIT"
12544   "@
12545    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
12546    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
12547   [(set_attr "type" "two")
12548    (set_attr "length" "8")])
12549
12550 (define_insn ""
12551   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12552         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12553                (match_operand:SI 2 "reg_or_short_operand" "rI")))
12554    (clobber (match_scratch:SI 3 "=r"))]
12555   "TARGET_POWER"
12556   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
12557    [(set_attr "length" "12")])
12558
12559 (define_insn ""
12560   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12561         (compare:CC
12562          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12563                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12564          (const_int 0)))
12565    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12566         (ge:SI (match_dup 1) (match_dup 2)))
12567    (clobber (match_scratch:SI 3 "=r,r"))]
12568   "TARGET_POWER"
12569   "@
12570    doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
12571    #"
12572   [(set_attr "type" "compare")
12573    (set_attr "length" "12,16")])
12574
12575 (define_split
12576   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12577         (compare:CC
12578          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12579                 (match_operand:SI 2 "reg_or_short_operand" ""))
12580          (const_int 0)))
12581    (set (match_operand:SI 0 "gpc_reg_operand" "")
12582         (ge:SI (match_dup 1) (match_dup 2)))
12583    (clobber (match_scratch:SI 3 ""))]
12584   "TARGET_POWER && reload_completed"
12585   [(parallel [(set (match_dup 0)
12586                    (ge:SI (match_dup 1) (match_dup 2)))
12587               (clobber (match_dup 3))])
12588    (set (match_dup 4)
12589         (compare:CC (match_dup 0)
12590                     (const_int 0)))]
12591   "")
12592
12593 (define_insn ""
12594   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12595         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12596                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12597                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12598   "TARGET_POWER"
12599   "doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
12600   [(set_attr "length" "12")])
12601
12602 (define_insn ""
12603   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12604         (compare:CC
12605          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12606                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12607                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12608          (const_int 0)))
12609    (clobber (match_scratch:SI 4 "=&r,&r"))]
12610   "TARGET_POWER"
12611   "@
12612    doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12613    #"
12614   [(set_attr "type" "compare")
12615    (set_attr "length" "12,16")])
12616
12617 (define_split
12618   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12619         (compare:CC
12620          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12621                          (match_operand:SI 2 "reg_or_short_operand" ""))
12622                   (match_operand:SI 3 "gpc_reg_operand" ""))
12623          (const_int 0)))
12624    (clobber (match_scratch:SI 4 ""))]
12625   "TARGET_POWER && reload_completed"
12626   [(set (match_dup 4)
12627         (plus:SI (ge:SI (match_dup 1) (match_dup 2))
12628                  (match_dup 3)))
12629    (set (match_dup 0)
12630         (compare:CC (match_dup 4)
12631                     (const_int 0)))]
12632   "")
12633
12634 (define_insn ""
12635   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12636         (compare:CC
12637          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12638                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12639                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12640          (const_int 0)))
12641    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12642         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12643   "TARGET_POWER"
12644   "@
12645    doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12646    #"
12647   [(set_attr "type" "compare")
12648    (set_attr "length" "12,16")])
12649
12650 (define_split
12651   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12652         (compare:CC
12653          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12654                          (match_operand:SI 2 "reg_or_short_operand" ""))
12655                   (match_operand:SI 3 "gpc_reg_operand" ""))
12656          (const_int 0)))
12657    (set (match_operand:SI 0 "gpc_reg_operand" "")
12658         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12659   "TARGET_POWER && reload_completed"
12660   [(set (match_dup 0)
12661         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12662    (set (match_dup 4)
12663         (compare:CC (match_dup 0)
12664                     (const_int 0)))]
12665   "")
12666
12667 (define_insn ""
12668   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12669         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12670                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12671   "TARGET_POWER"
12672   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
12673   [(set_attr "length" "12")])
12674
12675 (define_insn ""
12676   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12677         (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12678                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
12679   "TARGET_32BIT"
12680   "@
12681    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
12682    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12683   [(set_attr "type" "three")
12684    (set_attr "length" "12")])
12685
12686 (define_insn ""
12687   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12688         (geu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12689                 (match_operand:DI 2 "reg_or_neg_short_operand" "r,P")))]
12690   "TARGET_64BIT"
12691   "@
12692    subfc %0,%2,%1\;li %0,0\;adde %0,%0,%0
12693    addic %0,%1,%n2\;li %0,0\;adde %0,%0,%0"
12694   [(set_attr "type" "three")
12695    (set_attr "length" "12")])
12696
12697 (define_insn ""
12698   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12699         (compare:CC
12700          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12701                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12702          (const_int 0)))
12703    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12704         (geu:SI (match_dup 1) (match_dup 2)))]
12705   "TARGET_32BIT"
12706   "@
12707    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12708    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12709    #
12710    #"
12711   [(set_attr "type" "compare")
12712    (set_attr "length" "12,12,16,16")])
12713
12714 (define_split
12715   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12716         (compare:CC
12717          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12718                  (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12719          (const_int 0)))
12720    (set (match_operand:SI 0 "gpc_reg_operand" "")
12721         (geu:SI (match_dup 1) (match_dup 2)))]
12722   "TARGET_32BIT && reload_completed"
12723   [(set (match_dup 0)
12724         (geu:SI (match_dup 1) (match_dup 2)))
12725    (set (match_dup 3)
12726         (compare:CC (match_dup 0)
12727                     (const_int 0)))]
12728   "")
12729
12730 (define_insn ""
12731   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12732         (compare:CC
12733          (geu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
12734                  (match_operand:DI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12735          (const_int 0)))
12736    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
12737         (geu:DI (match_dup 1) (match_dup 2)))]
12738   "TARGET_64BIT"
12739   "@
12740    subfc %0,%2,%1\;li %0,0\;adde. %0,%0,%0
12741    addic %0,%1,%n2\;li %0,0\;adde. %0,%0,%0
12742    #
12743    #"
12744   [(set_attr "type" "compare")
12745    (set_attr "length" "12,12,16,16")])
12746
12747 (define_split
12748   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12749         (compare:CC
12750          (geu:DI (match_operand:DI 1 "gpc_reg_operand" "")
12751                  (match_operand:DI 2 "reg_or_neg_short_operand" ""))
12752          (const_int 0)))
12753    (set (match_operand:DI 0 "gpc_reg_operand" "")
12754         (geu:DI (match_dup 1) (match_dup 2)))]
12755   "TARGET_64BIT && reload_completed"
12756   [(set (match_dup 0)
12757         (geu:DI (match_dup 1) (match_dup 2)))
12758    (set (match_dup 3)
12759         (compare:CC (match_dup 0)
12760                     (const_int 0)))]
12761   "")
12762
12763 (define_insn ""
12764   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12765         (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12766                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
12767                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12768   "TARGET_32BIT"
12769   "@
12770    {sf|subfc} %0,%2,%1\;{aze|addze} %0,%3
12771    {ai|addic} %0,%1,%n2\;{aze|addze} %0,%3"
12772   [(set_attr "type" "two")
12773    (set_attr "length" "8")])
12774
12775 (define_insn ""
12776   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12777         (compare:CC
12778          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12779                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12780                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12781          (const_int 0)))
12782    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12783   "TARGET_32BIT"
12784   "@
12785    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
12786    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3
12787    #
12788    #"
12789   [(set_attr "type" "compare")
12790    (set_attr "length" "8,8,12,12")])
12791
12792 (define_split
12793   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12794         (compare:CC
12795          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12796                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12797                   (match_operand:SI 3 "gpc_reg_operand" ""))
12798          (const_int 0)))
12799    (clobber (match_scratch:SI 4 ""))]
12800   "TARGET_32BIT && reload_completed"
12801   [(set (match_dup 4)
12802         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
12803                   (match_dup 3)))
12804    (set (match_dup 0)
12805         (compare:CC (match_dup 4)
12806                     (const_int 0)))]
12807   "")
12808
12809 (define_insn ""
12810   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12811         (compare:CC
12812          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12813                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12814                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12815          (const_int 0)))
12816    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12817         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12818   "TARGET_32BIT"
12819   "@
12820    {sf|subfc} %0,%2,%1\;{aze.|addze.} %0,%3
12821    {ai|addic} %0,%1,%n2\;{aze.|addze.} %0,%3
12822    #
12823    #"
12824   [(set_attr "type" "compare")
12825    (set_attr "length" "8,8,12,12")])
12826
12827 (define_split
12828   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12829         (compare:CC
12830          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12831                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12832                   (match_operand:SI 3 "gpc_reg_operand" ""))
12833          (const_int 0)))
12834    (set (match_operand:SI 0 "gpc_reg_operand" "")
12835         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12836   "TARGET_32BIT && reload_completed"
12837   [(set (match_dup 0)
12838         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12839    (set (match_dup 4)
12840         (compare:CC (match_dup 0)
12841                     (const_int 0)))]
12842   "")
12843
12844 (define_insn ""
12845   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12846         (neg:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12847                         (match_operand:SI 2 "reg_or_short_operand" "r,I"))))]
12848   "TARGET_32BIT"
12849   "@
12850    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
12851    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
12852   [(set_attr "type" "three")
12853    (set_attr "length" "12")])
12854
12855 (define_insn ""
12856   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12857         (and:SI (neg:SI
12858                  (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12859                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
12860                 (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12861   "TARGET_32BIT"
12862   "@
12863    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0
12864    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12865   [(set_attr "type" "three")
12866    (set_attr "length" "12")])
12867
12868 (define_insn ""
12869   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12870         (compare:CC
12871          (and:SI (neg:SI
12872                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12873                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
12874                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12875          (const_int 0)))
12876    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12877   "TARGET_32BIT"
12878   "@
12879    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12880    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12881    #
12882    #"
12883   [(set_attr "type" "compare")
12884    (set_attr "length" "12,12,16,16")])
12885
12886 (define_split
12887   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12888         (compare:CC
12889          (and:SI (neg:SI
12890                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12891                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
12892                  (match_operand:SI 3 "gpc_reg_operand" ""))
12893          (const_int 0)))
12894    (clobber (match_scratch:SI 4 ""))]
12895   "TARGET_32BIT && reload_completed"
12896   [(set (match_dup 4)
12897         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
12898                 (match_dup 3)))
12899    (set (match_dup 0)
12900         (compare:CC (match_dup 4)
12901                     (const_int 0)))]
12902   "")
12903
12904 (define_insn ""
12905   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12906         (compare:CC
12907          (and:SI (neg:SI
12908                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12909                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
12910                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12911          (const_int 0)))
12912    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12913         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12914   "TARGET_32BIT"
12915   "@
12916    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12917    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12918    #
12919    #"
12920   [(set_attr "type" "compare")
12921    (set_attr "length" "12,12,16,16")])
12922
12923 (define_split
12924   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12925         (compare:CC
12926          (and:SI (neg:SI
12927                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12928                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
12929                  (match_operand:SI 3 "gpc_reg_operand" ""))
12930          (const_int 0)))
12931    (set (match_operand:SI 0 "gpc_reg_operand" "")
12932         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12933   "TARGET_32BIT && reload_completed"
12934   [(set (match_dup 0)
12935         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
12936    (set (match_dup 4)
12937         (compare:CC (match_dup 0)
12938                     (const_int 0)))]
12939   "")
12940
12941 (define_insn ""
12942   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12943         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12944                (const_int 0)))]
12945   "TARGET_32BIT"
12946   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri|srwi} %0,%0,31"
12947   [(set_attr "type" "three")
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 "type" "three")
12957    (set_attr "length" "12")])
12958
12959 (define_insn ""
12960   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
12961         (compare:CC
12962          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12963                 (const_int 0))
12964          (const_int 0)))
12965    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12966         (gt:SI (match_dup 1) (const_int 0)))]
12967   "TARGET_32BIT"
12968   "@
12969    {sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri.|srwi.} %0,%0,31
12970    #"
12971   [(set_attr "type" "delayed_compare")
12972    (set_attr "length" "12,16")])
12973
12974 (define_split
12975   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
12976         (compare:CC
12977          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12978                 (const_int 0))
12979          (const_int 0)))
12980    (set (match_operand:SI 0 "gpc_reg_operand" "")
12981         (gt:SI (match_dup 1) (const_int 0)))]
12982   "TARGET_32BIT && reload_completed"
12983   [(set (match_dup 0)
12984         (gt:SI (match_dup 1) (const_int 0)))
12985    (set (match_dup 2)
12986         (compare:CC (match_dup 0)
12987                     (const_int 0)))]
12988   "")
12989
12990 (define_insn ""
12991   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
12992         (compare:CC
12993          (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12994                 (const_int 0))
12995          (const_int 0)))
12996    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12997         (gt:DI (match_dup 1) (const_int 0)))]
12998   "TARGET_64BIT"
12999   "@
13000    subfic %0,%1,0\;addme %0,%0\;srdi. %0,%0,63
13001    #"
13002   [(set_attr "type" "delayed_compare")
13003    (set_attr "length" "12,16")])
13004
13005 (define_split
13006   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
13007         (compare:CC
13008          (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13009                 (const_int 0))
13010          (const_int 0)))
13011    (set (match_operand:DI 0 "gpc_reg_operand" "")
13012         (gt:DI (match_dup 1) (const_int 0)))]
13013   "TARGET_64BIT && reload_completed"
13014   [(set (match_dup 0)
13015         (gt:DI (match_dup 1) (const_int 0)))
13016    (set (match_dup 2)
13017         (compare:CC (match_dup 0)
13018                     (const_int 0)))]
13019   "")
13020
13021 (define_insn ""
13022   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13023         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13024                (match_operand:SI 2 "reg_or_short_operand" "r")))]
13025   "TARGET_POWER"
13026   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
13027   [(set_attr "length" "12")])
13028
13029 (define_insn ""
13030   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13031         (compare:CC
13032          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13033                 (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13034          (const_int 0)))
13035    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13036         (gt:SI (match_dup 1) (match_dup 2)))]
13037   "TARGET_POWER"
13038   "@
13039    doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
13040    #"
13041   [(set_attr "type" "delayed_compare")
13042    (set_attr "length" "12,16")])
13043
13044 (define_split
13045   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13046         (compare:CC
13047          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13048                 (match_operand:SI 2 "reg_or_short_operand" ""))
13049          (const_int 0)))
13050    (set (match_operand:SI 0 "gpc_reg_operand" "")
13051         (gt:SI (match_dup 1) (match_dup 2)))]
13052   "TARGET_POWER && reload_completed"
13053   [(set (match_dup 0)
13054         (gt:SI (match_dup 1) (match_dup 2)))
13055    (set (match_dup 3)
13056         (compare:CC (match_dup 0)
13057                     (const_int 0)))]
13058   "")
13059
13060 (define_insn ""
13061   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13062         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13063                         (const_int 0))
13064                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
13065   "TARGET_32BIT"
13066   "{a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze|addze} %0,%2"
13067   [(set_attr "type" "three")
13068    (set_attr "length" "12")])
13069
13070 (define_insn ""
13071   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
13072         (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13073                         (const_int 0))
13074                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
13075   "TARGET_64BIT"
13076   "addc %0,%1,%1\;subfe %0,%1,%0\;addze %0,%2"
13077   [(set_attr "type" "three")
13078    (set_attr "length" "12")])
13079
13080 (define_insn ""
13081   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13082         (compare:CC
13083          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13084                          (const_int 0))
13085                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13086          (const_int 0)))
13087    (clobber (match_scratch:SI 3 "=&r,&r"))]
13088   "TARGET_32BIT"
13089   "@
13090    {a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2
13091    #"
13092   [(set_attr "type" "compare")
13093    (set_attr "length" "12,16")])
13094
13095 (define_split
13096   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13097         (compare:CC
13098          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13099                          (const_int 0))
13100                   (match_operand:SI 2 "gpc_reg_operand" ""))
13101          (const_int 0)))
13102    (clobber (match_scratch:SI 3 ""))]
13103   "TARGET_32BIT && reload_completed"
13104   [(set (match_dup 3)
13105         (plus:SI (gt:SI (match_dup 1) (const_int 0))
13106                   (match_dup 2)))
13107    (set (match_dup 0)
13108         (compare:CC (match_dup 3)
13109                     (const_int 0)))]
13110   "")
13111
13112 (define_insn ""
13113   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13114         (compare:CC
13115          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13116                          (const_int 0))
13117                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13118          (const_int 0)))
13119    (clobber (match_scratch:DI 3 "=&r,&r"))]
13120   "TARGET_64BIT"
13121   "@
13122    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
13123    #"
13124   [(set_attr "type" "compare")
13125    (set_attr "length" "12,16")])
13126
13127 (define_split
13128   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13129         (compare:CC
13130          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13131                          (const_int 0))
13132                   (match_operand:DI 2 "gpc_reg_operand" ""))
13133          (const_int 0)))
13134    (clobber (match_scratch:DI 3 ""))]
13135   "TARGET_64BIT && reload_completed"
13136   [(set (match_dup 3)
13137         (plus:DI (gt:DI (match_dup 1) (const_int 0))
13138                  (match_dup 2)))
13139    (set (match_dup 0)
13140         (compare:CC (match_dup 3)
13141                     (const_int 0)))]
13142   "")
13143
13144 (define_insn ""
13145   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13146         (compare:CC
13147          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13148                          (const_int 0))
13149                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13150          (const_int 0)))
13151    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13152         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13153   "TARGET_32BIT"
13154   "@
13155    {a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze.|addze.} %0,%2
13156    #"
13157   [(set_attr "type" "compare")
13158    (set_attr "length" "12,16")])
13159
13160 (define_split
13161   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13162         (compare:CC
13163          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13164                          (const_int 0))
13165                   (match_operand:SI 2 "gpc_reg_operand" ""))
13166          (const_int 0)))
13167    (set (match_operand:SI 0 "gpc_reg_operand" "")
13168         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13169   "TARGET_32BIT && reload_completed"
13170   [(set (match_dup 0)
13171         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
13172    (set (match_dup 3)
13173         (compare:CC (match_dup 0)
13174                     (const_int 0)))]
13175   "")
13176
13177 (define_insn ""
13178   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13179         (compare:CC
13180          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13181                          (const_int 0))
13182                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13183          (const_int 0)))
13184    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
13185         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13186   "TARGET_64BIT"
13187   "@
13188    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
13189    #"
13190   [(set_attr "type" "compare")
13191    (set_attr "length" "12,16")])
13192
13193 (define_split
13194   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13195         (compare:CC
13196          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13197                          (const_int 0))
13198                   (match_operand:DI 2 "gpc_reg_operand" ""))
13199          (const_int 0)))
13200    (set (match_operand:DI 0 "gpc_reg_operand" "")
13201         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13202   "TARGET_64BIT && reload_completed"
13203   [(set (match_dup 0)
13204         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
13205    (set (match_dup 3)
13206         (compare:CC (match_dup 0)
13207                     (const_int 0)))]
13208   "")
13209
13210 (define_insn ""
13211   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13212         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13213                         (match_operand:SI 2 "reg_or_short_operand" "r"))
13214                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
13215   "TARGET_POWER"
13216   "doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
13217   [(set_attr "length" "12")])
13218
13219 (define_insn ""
13220   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13221         (compare:CC
13222          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13223                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13224                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13225          (const_int 0)))
13226    (clobber (match_scratch:SI 4 "=&r,&r"))]
13227   "TARGET_POWER"
13228   "@
13229    doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
13230    #"
13231   [(set_attr "type" "compare")
13232    (set_attr "length" "12,16")])
13233
13234 (define_split
13235   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13236         (compare:CC
13237          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13238                          (match_operand:SI 2 "reg_or_short_operand" ""))
13239                   (match_operand:SI 3 "gpc_reg_operand" ""))
13240          (const_int 0)))
13241    (clobber (match_scratch:SI 4 ""))]
13242   "TARGET_POWER && reload_completed"
13243   [(set (match_dup 4)
13244         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13245    (set (match_dup 0)
13246         (compare:CC (match_dup 4)
13247                     (const_int 0)))]
13248   "")
13249
13250 (define_insn ""
13251   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13252         (compare:CC
13253          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13254                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13255                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13256          (const_int 0)))
13257    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13258         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13259   "TARGET_POWER"
13260   "@
13261    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
13262    #"
13263   [(set_attr "type" "compare")
13264    (set_attr "length" "12,16")])
13265
13266 (define_split
13267   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13268         (compare:CC
13269          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13270                          (match_operand:SI 2 "reg_or_short_operand" ""))
13271                   (match_operand:SI 3 "gpc_reg_operand" ""))
13272          (const_int 0)))
13273    (set (match_operand:SI 0 "gpc_reg_operand" "")
13274         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13275   "TARGET_POWER && reload_completed"
13276   [(set (match_dup 0)
13277         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13278    (set (match_dup 4)
13279         (compare:CC (match_dup 0)
13280                     (const_int 0)))]
13281   "")
13282
13283 (define_insn ""
13284   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13285         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13286                        (const_int 0))))]
13287   "TARGET_32BIT"
13288   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{srai|srawi} %0,%0,31"
13289   [(set_attr "type" "three")
13290    (set_attr "length" "12")])
13291
13292 (define_insn ""
13293   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13294         (neg:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13295                        (const_int 0))))]
13296   "TARGET_64BIT"
13297   "subfic %0,%1,0\;addme %0,%0\;sradi %0,%0,63"
13298   [(set_attr "type" "three")
13299    (set_attr "length" "12")])
13300
13301 (define_insn ""
13302   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13303         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13304                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
13305   "TARGET_POWER"
13306   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
13307   [(set_attr "length" "12")])
13308
13309 (define_insn_and_split ""
13310   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13311         (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13312                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
13313   "TARGET_32BIT"
13314   "#"
13315   "TARGET_32BIT"
13316   [(set (match_dup 0) (neg:SI (gtu:SI (match_dup 1) (match_dup 2))))
13317    (set (match_dup 0) (neg:SI (match_dup 0)))]
13318   "")
13319
13320 (define_insn_and_split ""
13321   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13322         (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13323                 (match_operand:DI 2 "reg_or_short_operand" "rI")))]
13324   "TARGET_64BIT"
13325   "#"
13326   "TARGET_64BIT"
13327   [(set (match_dup 0) (neg:DI (gtu:DI (match_dup 1) (match_dup 2))))
13328    (set (match_dup 0) (neg:DI (match_dup 0)))]
13329   "")
13330
13331 (define_insn ""
13332   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13333         (compare:CC
13334          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13335                  (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13336          (const_int 0)))
13337    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13338         (gtu:SI (match_dup 1) (match_dup 2)))]
13339   "TARGET_32BIT"
13340   "@
13341    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
13342    #"
13343   [(set_attr "type" "compare")
13344    (set_attr "length" "12,16")])
13345
13346 (define_split
13347   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13348         (compare:CC
13349          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13350                  (match_operand:SI 2 "reg_or_short_operand" ""))
13351          (const_int 0)))
13352    (set (match_operand:SI 0 "gpc_reg_operand" "")
13353         (gtu:SI (match_dup 1) (match_dup 2)))]
13354   "TARGET_32BIT && reload_completed"
13355   [(set (match_dup 0)
13356         (gtu:SI (match_dup 1) (match_dup 2)))
13357    (set (match_dup 3)
13358         (compare:CC (match_dup 0)
13359                     (const_int 0)))]
13360   "")
13361
13362 (define_insn ""
13363   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13364         (compare:CC
13365          (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13366                  (match_operand:DI 2 "reg_or_short_operand" "rI,rI"))
13367          (const_int 0)))
13368    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
13369         (gtu:DI (match_dup 1) (match_dup 2)))]
13370   "TARGET_64BIT"
13371   "@
13372    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;neg. %0,%0
13373    #"
13374   [(set_attr "type" "compare")
13375    (set_attr "length" "12,16")])
13376
13377 (define_split
13378   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13379         (compare:CC
13380          (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13381                  (match_operand:DI 2 "reg_or_short_operand" ""))
13382          (const_int 0)))
13383    (set (match_operand:DI 0 "gpc_reg_operand" "")
13384         (gtu:DI (match_dup 1) (match_dup 2)))]
13385   "TARGET_64BIT && reload_completed"
13386   [(set (match_dup 0)
13387         (gtu:DI (match_dup 1) (match_dup 2)))
13388    (set (match_dup 3)
13389         (compare:CC (match_dup 0)
13390                     (const_int 0)))]
13391   "")
13392
13393 (define_insn_and_split ""
13394   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13395         (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13396                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
13397                  (match_operand:SI 3 "reg_or_short_operand" "rI")))]
13398   "TARGET_32BIT"
13399   "#"
13400   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13401   [(set (match_dup 0) (neg:SI (gtu:SI (match_dup 1) (match_dup 2))))
13402    (set (match_dup 0) (minus:SI (match_dup 3) (match_dup 0)))]
13403   "")
13404
13405 (define_insn_and_split ""
13406   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
13407         (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13408                          (match_operand:DI 2 "reg_or_short_operand" "rI"))
13409                  (match_operand:DI 3 "reg_or_short_operand" "rI")))]
13410   "TARGET_64BIT"
13411   "#"
13412   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13413   [(set (match_dup 0) (neg:DI (gtu:DI (match_dup 1) (match_dup 2))))
13414    (set (match_dup 0) (minus:DI (match_dup 3) (match_dup 0)))]
13415   "")
13416
13417 (define_insn ""
13418   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13419         (compare:CC
13420          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13421                           (match_operand:SI 2 "reg_or_short_operand" "I,r,I,r"))
13422                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13423          (const_int 0)))
13424    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13425   "TARGET_32BIT"
13426   "@
13427    {ai|addic} %4,%1,%k2\;{aze.|addze.} %4,%3
13428    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf.|subf.} %4,%4,%3
13429    #
13430    #"
13431   [(set_attr "type" "compare")
13432    (set_attr "length" "8,12,12,16")])
13433
13434 (define_split
13435   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13436         (compare:CC
13437          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13438                           (match_operand:SI 2 "reg_or_short_operand" ""))
13439                   (match_operand:SI 3 "gpc_reg_operand" ""))
13440          (const_int 0)))
13441    (clobber (match_scratch:SI 4 ""))]
13442   "TARGET_32BIT && reload_completed"
13443   [(set (match_dup 4)
13444         (plus:SI (gtu:SI (match_dup 1) (match_dup 2))
13445                  (match_dup 3)))
13446    (set (match_dup 0)
13447         (compare:CC (match_dup 4)
13448                     (const_int 0)))]
13449   "")
13450
13451 (define_insn ""
13452   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13453         (compare:CC
13454          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
13455                           (match_operand:DI 2 "reg_or_short_operand" "I,r,I,r"))
13456                   (match_operand:DI 3 "gpc_reg_operand" "r,r,r,r"))
13457          (const_int 0)))
13458    (clobber (match_scratch:DI 4 "=&r,&r,&r,&r"))]
13459   "TARGET_64BIT"
13460   "@
13461    addic %4,%1,%k2\;addze. %4,%3
13462    subf%I2c %4,%1,%2\;subfe %4,%4,%4\;subf. %4,%4,%3
13463    #
13464    #"
13465   [(set_attr "type" "compare")
13466    (set_attr "length" "8,12,12,16")])
13467
13468 (define_split
13469   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13470         (compare:CC
13471          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13472                           (match_operand:DI 2 "reg_or_short_operand" ""))
13473                   (match_operand:DI 3 "gpc_reg_operand" ""))
13474          (const_int 0)))
13475    (clobber (match_scratch:DI 4 ""))]
13476   "TARGET_64BIT && reload_completed"
13477   [(set (match_dup 4)
13478         (plus:DI (gtu:DI (match_dup 1) (match_dup 2))
13479                   (match_dup 3)))
13480    (set (match_dup 0)
13481         (compare:CC (match_dup 4)
13482                     (const_int 0)))]
13483   "")
13484
13485 (define_insn ""
13486   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13487         (compare:CC
13488          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13489                           (match_operand:SI 2 "reg_or_short_operand" "I,r,I,r"))
13490                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13491          (const_int 0)))
13492    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13493         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13494   "TARGET_32BIT"
13495   "@
13496    {ai|addic} %0,%1,%k2\;{aze.|addze.} %0,%3
13497    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;{sf.|subf.} %0,%0,%3
13498    #
13499    #"
13500   [(set_attr "type" "compare")
13501    (set_attr "length" "8,12,12,16")])
13502
13503 (define_split
13504   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13505         (compare:CC
13506          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13507                           (match_operand:SI 2 "reg_or_short_operand" ""))
13508                   (match_operand:SI 3 "gpc_reg_operand" ""))
13509          (const_int 0)))
13510    (set (match_operand:SI 0 "gpc_reg_operand" "")
13511         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13512   "TARGET_32BIT && reload_completed"
13513   [(set (match_dup 0)
13514         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13515    (set (match_dup 4)
13516         (compare:CC (match_dup 0)
13517                     (const_int 0)))]
13518   "")
13519
13520 (define_insn ""
13521   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13522         (compare:CC
13523          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
13524                           (match_operand:DI 2 "reg_or_short_operand" "I,r,I,r"))
13525                   (match_operand:DI 3 "gpc_reg_operand" "r,r,r,r"))
13526          (const_int 0)))
13527    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13528         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13529   "TARGET_64BIT"
13530   "@
13531    addic %0,%1,%k2\;addze. %0,%3
13532    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;subf. %0,%0,%3
13533    #
13534    #"
13535   [(set_attr "type" "compare")
13536    (set_attr "length" "8,12,12,16")])
13537
13538 (define_split
13539   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13540         (compare:CC
13541          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13542                           (match_operand:DI 2 "reg_or_short_operand" ""))
13543                   (match_operand:DI 3 "gpc_reg_operand" ""))
13544          (const_int 0)))
13545    (set (match_operand:DI 0 "gpc_reg_operand" "")
13546         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13547   "TARGET_64BIT && reload_completed"
13548   [(set (match_dup 0)
13549         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
13550    (set (match_dup 4)
13551         (compare:CC (match_dup 0)
13552                     (const_int 0)))]
13553   "")
13554
13555 (define_insn ""
13556   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13557         (neg:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13558                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
13559   "TARGET_32BIT"
13560   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
13561   [(set_attr "type" "two")
13562    (set_attr "length" "8")])
13563
13564 (define_insn ""
13565   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13566         (neg:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13567                         (match_operand:DI 2 "reg_or_short_operand" "rI"))))]
13568   "TARGET_64BIT"
13569   "subf%I2c %0,%1,%2\;subfe %0,%0,%0"
13570   [(set_attr "type" "two")
13571    (set_attr "length" "8")])
13572 \f
13573 ;; Define both directions of branch and return.  If we need a reload
13574 ;; register, we'd rather use CR0 since it is much easier to copy a
13575 ;; register CC value to there.
13576
13577 (define_insn ""
13578   [(set (pc)
13579         (if_then_else (match_operator 1 "branch_comparison_operator"
13580                                       [(match_operand 2
13581                                                       "cc_reg_operand" "y")
13582                                        (const_int 0)])
13583                       (label_ref (match_operand 0 "" ""))
13584                       (pc)))]
13585   ""
13586   "*
13587 {
13588   return output_cbranch (operands[1], \"%l0\", 0, insn);
13589 }"
13590   [(set_attr "type" "branch")])
13591
13592 (define_insn ""
13593   [(set (pc)
13594         (if_then_else (match_operator 0 "branch_comparison_operator"
13595                                       [(match_operand 1
13596                                                       "cc_reg_operand" "y")
13597                                        (const_int 0)])
13598                       (return)
13599                       (pc)))]
13600   "direct_return ()"
13601   "*
13602 {
13603   return output_cbranch (operands[0], NULL, 0, insn);
13604 }"
13605   [(set_attr "type" "branch")
13606    (set_attr "length" "4")])
13607
13608 (define_insn ""
13609   [(set (pc)
13610         (if_then_else (match_operator 1 "branch_comparison_operator"
13611                                       [(match_operand 2
13612                                                       "cc_reg_operand" "y")
13613                                        (const_int 0)])
13614                       (pc)
13615                       (label_ref (match_operand 0 "" ""))))]
13616   ""
13617   "*
13618 {
13619   return output_cbranch (operands[1], \"%l0\", 1, insn);
13620 }"
13621   [(set_attr "type" "branch")])
13622
13623 (define_insn ""
13624   [(set (pc)
13625         (if_then_else (match_operator 0 "branch_comparison_operator"
13626                                       [(match_operand 1
13627                                                       "cc_reg_operand" "y")
13628                                        (const_int 0)])
13629                       (pc)
13630                       (return)))]
13631   "direct_return ()"
13632   "*
13633 {
13634   return output_cbranch (operands[0], NULL, 1, insn);
13635 }"
13636   [(set_attr "type" "branch")
13637    (set_attr "length" "4")])
13638
13639 ;; Logic on condition register values.
13640
13641 ; This pattern matches things like
13642 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
13643 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
13644 ;                                  (const_int 1)))
13645 ; which are generated by the branch logic.
13646 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
13647
13648 (define_insn "*cceq_ior_compare"
13649   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13650         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
13651                         [(match_operator:SI 2
13652                                       "branch_positive_comparison_operator"
13653                                       [(match_operand 3
13654                                                       "cc_reg_operand" "y,y")
13655                                        (const_int 0)])
13656                          (match_operator:SI 4
13657                                       "branch_positive_comparison_operator"
13658                                       [(match_operand 5
13659                                                       "cc_reg_operand" "0,y")
13660                                        (const_int 0)])])
13661                       (const_int 1)))]
13662   ""
13663   "cr%q1 %E0,%j2,%j4"
13664   [(set_attr "type" "cr_logical,delayed_cr")])
13665
13666 ; Why is the constant -1 here, but 1 in the previous pattern?
13667 ; Because ~1 has all but the low bit set.
13668 (define_insn ""
13669   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13670         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
13671                         [(not:SI (match_operator:SI 2
13672                                       "branch_positive_comparison_operator"
13673                                       [(match_operand 3
13674                                                       "cc_reg_operand" "y,y")
13675                                        (const_int 0)]))
13676                          (match_operator:SI 4
13677                                 "branch_positive_comparison_operator"
13678                                 [(match_operand 5
13679                                                 "cc_reg_operand" "0,y")
13680                                  (const_int 0)])])
13681                       (const_int -1)))]
13682   ""
13683   "cr%q1 %E0,%j2,%j4"
13684   [(set_attr "type" "cr_logical,delayed_cr")])
13685
13686 (define_insn "*cceq_rev_compare"
13687   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13688         (compare:CCEQ (match_operator:SI 1
13689                                       "branch_positive_comparison_operator"
13690                                       [(match_operand 2
13691                                                       "cc_reg_operand" "0,y")
13692                                        (const_int 0)])
13693                       (const_int 0)))]
13694   ""
13695   "{crnor %E0,%j1,%j1|crnot %E0,%j1}"
13696   [(set_attr "type" "cr_logical,delayed_cr")])
13697
13698 ;; If we are comparing the result of two comparisons, this can be done
13699 ;; using creqv or crxor.
13700
13701 (define_insn_and_split ""
13702   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
13703         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
13704                               [(match_operand 2 "cc_reg_operand" "y")
13705                                (const_int 0)])
13706                       (match_operator 3 "branch_comparison_operator"
13707                               [(match_operand 4 "cc_reg_operand" "y")
13708                                (const_int 0)])))]
13709   ""
13710   "#"
13711   ""
13712   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
13713                                     (match_dup 5)))]
13714   "
13715 {
13716   int positive_1, positive_2;
13717
13718   positive_1 = branch_positive_comparison_operator (operands[1],
13719                                                     GET_MODE (operands[1]));
13720   positive_2 = branch_positive_comparison_operator (operands[3],
13721                                                     GET_MODE (operands[3]));
13722
13723   if (! positive_1)
13724     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
13725                                                             GET_CODE (operands[1])),
13726                                   SImode,
13727                                   operands[2], const0_rtx);
13728   else if (GET_MODE (operands[1]) != SImode)
13729     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
13730                                   operands[2], const0_rtx);
13731
13732   if (! positive_2)
13733     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
13734                                                             GET_CODE (operands[3])),
13735                                   SImode,
13736                                   operands[4], const0_rtx);
13737   else if (GET_MODE (operands[3]) != SImode)
13738     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
13739                                   operands[4], const0_rtx);
13740
13741   if (positive_1 == positive_2)
13742     {
13743       operands[1] = gen_rtx_NOT (SImode, operands[1]);
13744       operands[5] = constm1_rtx;
13745     }
13746   else
13747     {
13748       operands[5] = const1_rtx;
13749     }
13750 }")
13751
13752 ;; Unconditional branch and return.
13753
13754 (define_insn "jump"
13755   [(set (pc)
13756         (label_ref (match_operand 0 "" "")))]
13757   ""
13758   "b %l0"
13759   [(set_attr "type" "branch")])
13760
13761 (define_insn "return"
13762   [(return)]
13763   "direct_return ()"
13764   "{br|blr}"
13765   [(set_attr "type" "jmpreg")])
13766
13767 (define_expand "indirect_jump"
13768   [(set (pc) (match_operand 0 "register_operand" ""))]
13769   ""
13770   "
13771 {
13772   if (TARGET_32BIT)
13773     emit_jump_insn (gen_indirect_jumpsi (operands[0]));
13774   else
13775     emit_jump_insn (gen_indirect_jumpdi (operands[0]));
13776   DONE;
13777 }")
13778
13779 (define_insn "indirect_jumpsi"
13780   [(set (pc) (match_operand:SI 0 "register_operand" "c,*l"))]
13781   "TARGET_32BIT"
13782   "@
13783    bctr
13784    {br|blr}"
13785   [(set_attr "type" "jmpreg")])
13786
13787 (define_insn "indirect_jumpdi"
13788   [(set (pc) (match_operand:DI 0 "register_operand" "c,*l"))]
13789   "TARGET_64BIT"
13790   "@
13791    bctr
13792    blr"
13793   [(set_attr "type" "jmpreg")])
13794
13795 ;; Table jump for switch statements:
13796 (define_expand "tablejump"
13797   [(use (match_operand 0 "" ""))
13798    (use (label_ref (match_operand 1 "" "")))]
13799   ""
13800   "
13801 {
13802   if (TARGET_32BIT)
13803     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
13804   else
13805     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
13806   DONE;
13807 }")
13808
13809 (define_expand "tablejumpsi"
13810   [(set (match_dup 3)
13811         (plus:SI (match_operand:SI 0 "" "")
13812                  (match_dup 2)))
13813    (parallel [(set (pc) (match_dup 3))
13814               (use (label_ref (match_operand 1 "" "")))])]
13815   "TARGET_32BIT"
13816   "
13817 { operands[0] = force_reg (SImode, operands[0]);
13818   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
13819   operands[3] = gen_reg_rtx (SImode);
13820 }")
13821
13822 (define_expand "tablejumpdi"
13823   [(set (match_dup 4)
13824         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "rm")))
13825    (set (match_dup 3)
13826         (plus:DI (match_dup 4)
13827                  (match_dup 2)))
13828    (parallel [(set (pc) (match_dup 3))
13829               (use (label_ref (match_operand 1 "" "")))])]
13830   "TARGET_64BIT"
13831   "
13832 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
13833   operands[3] = gen_reg_rtx (DImode);
13834   operands[4] = gen_reg_rtx (DImode);
13835 }")
13836
13837 (define_insn ""
13838   [(set (pc)
13839         (match_operand:SI 0 "register_operand" "c,*l"))
13840    (use (label_ref (match_operand 1 "" "")))]
13841   "TARGET_32BIT"
13842   "@
13843    bctr
13844    {br|blr}"
13845   [(set_attr "type" "jmpreg")])
13846
13847 (define_insn ""
13848   [(set (pc)
13849         (match_operand:DI 0 "register_operand" "c,*l"))
13850    (use (label_ref (match_operand 1 "" "")))]
13851   "TARGET_64BIT"
13852   "@
13853    bctr
13854    blr"
13855   [(set_attr "type" "jmpreg")])
13856
13857 (define_insn "nop"
13858   [(const_int 0)]
13859   ""
13860   "{cror 0,0,0|nop}")
13861 \f
13862 ;; Define the subtract-one-and-jump insns, starting with the template
13863 ;; so loop.c knows what to generate.
13864
13865 (define_expand "doloop_end"
13866   [(use (match_operand 0 "" ""))        ; loop pseudo
13867    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
13868    (use (match_operand 2 "" ""))        ; max iterations
13869    (use (match_operand 3 "" ""))        ; loop level
13870    (use (match_operand 4 "" ""))]       ; label
13871   ""
13872   "
13873 {
13874   /* Only use this on innermost loops.  */
13875   if (INTVAL (operands[3]) > 1)
13876     FAIL;
13877   if (TARGET_64BIT)
13878     {
13879       if (GET_MODE (operands[0]) != DImode)
13880         FAIL;
13881       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
13882     }
13883   else
13884     {
13885       if (GET_MODE (operands[0]) != SImode)
13886         FAIL;
13887       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
13888     }
13889   DONE;
13890 }")
13891
13892 (define_expand "ctrsi"
13893   [(parallel [(set (pc)
13894                    (if_then_else (ne (match_operand:SI 0 "register_operand" "")
13895                                      (const_int 1))
13896                                  (label_ref (match_operand 1 "" ""))
13897                                  (pc)))
13898               (set (match_dup 0)
13899                    (plus:SI (match_dup 0)
13900                             (const_int -1)))
13901               (clobber (match_scratch:CC 2 ""))
13902               (clobber (match_scratch:SI 3 ""))])]
13903   "TARGET_32BIT"
13904   "")
13905
13906 (define_expand "ctrdi"
13907   [(parallel [(set (pc)
13908                    (if_then_else (ne (match_operand:DI 0 "register_operand" "")
13909                                      (const_int 1))
13910                                  (label_ref (match_operand 1 "" ""))
13911                                  (pc)))
13912               (set (match_dup 0)
13913                    (plus:DI (match_dup 0)
13914                             (const_int -1)))
13915               (clobber (match_scratch:CC 2 ""))
13916               (clobber (match_scratch:DI 3 ""))])]
13917   "TARGET_64BIT"
13918   "")
13919
13920 ;; We need to be able to do this for any operand, including MEM, or we
13921 ;; will cause reload to blow up since we don't allow output reloads on
13922 ;; JUMP_INSNs.
13923 ;; For the length attribute to be calculated correctly, the
13924 ;; label MUST be operand 0.
13925
13926 (define_insn "*ctrsi_internal1"
13927   [(set (pc)
13928         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
13929                           (const_int 1))
13930                       (label_ref (match_operand 0 "" ""))
13931                       (pc)))
13932    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
13933         (plus:SI (match_dup 1)
13934                  (const_int -1)))
13935    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13936    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
13937   "TARGET_32BIT"
13938   "*
13939 {
13940   if (which_alternative != 0)
13941     return \"#\";
13942   else if (get_attr_length (insn) == 4)
13943     return \"{bdn|bdnz} %l0\";
13944   else
13945     return \"bdz $+8\;b %l0\";
13946 }"
13947   [(set_attr "type" "branch")
13948    (set_attr "length" "*,12,16,16")])
13949
13950 (define_insn "*ctrsi_internal2"
13951   [(set (pc)
13952         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
13953                           (const_int 1))
13954                       (pc)
13955                       (label_ref (match_operand 0 "" ""))))
13956    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
13957         (plus:SI (match_dup 1)
13958                  (const_int -1)))
13959    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13960    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
13961   "TARGET_32BIT"
13962   "*
13963 {
13964   if (which_alternative != 0)
13965     return \"#\";
13966   else if (get_attr_length (insn) == 4)
13967     return \"bdz %l0\";
13968   else
13969     return \"{bdn|bdnz} $+8\;b %l0\";
13970 }"
13971   [(set_attr "type" "branch")
13972    (set_attr "length" "*,12,16,16")])
13973
13974 (define_insn "*ctrdi_internal1"
13975   [(set (pc)
13976         (if_then_else (ne (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
13977                           (const_int 1))
13978                       (label_ref (match_operand 0 "" ""))
13979                       (pc)))
13980    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
13981         (plus:DI (match_dup 1)
13982                  (const_int -1)))
13983    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13984    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
13985   "TARGET_64BIT"
13986   "*
13987 {
13988   if (which_alternative != 0)
13989     return \"#\";
13990   else if (get_attr_length (insn) == 4)
13991     return \"{bdn|bdnz} %l0\";
13992   else
13993     return \"bdz $+8\;b %l0\";
13994 }"
13995   [(set_attr "type" "branch")
13996    (set_attr "length" "*,12,16,16")])
13997
13998 (define_insn "*ctrdi_internal2"
13999   [(set (pc)
14000         (if_then_else (ne (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14001                           (const_int 1))
14002                       (pc)
14003                       (label_ref (match_operand 0 "" ""))))
14004    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14005         (plus:DI (match_dup 1)
14006                  (const_int -1)))
14007    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14008    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14009   "TARGET_64BIT"
14010   "*
14011 {
14012   if (which_alternative != 0)
14013     return \"#\";
14014   else if (get_attr_length (insn) == 4)
14015     return \"bdz %l0\";
14016   else
14017     return \"{bdn|bdnz} $+8\;b %l0\";
14018 }"
14019   [(set_attr "type" "branch")
14020    (set_attr "length" "*,12,16,16")])
14021
14022 ;; Similar but use EQ
14023
14024 (define_insn "*ctrsi_internal5"
14025   [(set (pc)
14026         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14027                           (const_int 1))
14028                       (label_ref (match_operand 0 "" ""))
14029                       (pc)))
14030    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14031         (plus:SI (match_dup 1)
14032                  (const_int -1)))
14033    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14034    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14035   "TARGET_32BIT"
14036   "*
14037 {
14038   if (which_alternative != 0)
14039     return \"#\";
14040   else if (get_attr_length (insn) == 4)
14041     return \"bdz %l0\";
14042   else
14043     return \"{bdn|bdnz} $+8\;b %l0\";
14044 }"
14045   [(set_attr "type" "branch")
14046    (set_attr "length" "*,12,16,16")])
14047
14048 (define_insn "*ctrsi_internal6"
14049   [(set (pc)
14050         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14051                           (const_int 1))
14052                       (pc)
14053                       (label_ref (match_operand 0 "" ""))))
14054    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14055         (plus:SI (match_dup 1)
14056                  (const_int -1)))
14057    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14058    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14059   "TARGET_32BIT"
14060   "*
14061 {
14062   if (which_alternative != 0)
14063     return \"#\";
14064   else if (get_attr_length (insn) == 4)
14065     return \"{bdn|bdnz} %l0\";
14066   else
14067     return \"bdz $+8\;b %l0\";
14068 }"
14069   [(set_attr "type" "branch")
14070    (set_attr "length" "*,12,16,16")])
14071
14072 (define_insn "*ctrdi_internal5"
14073   [(set (pc)
14074         (if_then_else (eq (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14075                           (const_int 1))
14076                       (label_ref (match_operand 0 "" ""))
14077                       (pc)))
14078    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14079         (plus:DI (match_dup 1)
14080                  (const_int -1)))
14081    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14082    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14083   "TARGET_64BIT"
14084   "*
14085 {
14086   if (which_alternative != 0)
14087     return \"#\";
14088   else if (get_attr_length (insn) == 4)
14089     return \"bdz %l0\";
14090   else
14091     return \"{bdn|bdnz} $+8\;b %l0\";
14092 }"
14093   [(set_attr "type" "branch")
14094    (set_attr "length" "*,12,16,16")])
14095
14096 (define_insn "*ctrdi_internal6"
14097   [(set (pc)
14098         (if_then_else (eq (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14099                           (const_int 1))
14100                       (pc)
14101                       (label_ref (match_operand 0 "" ""))))
14102    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14103         (plus:DI (match_dup 1)
14104                  (const_int -1)))
14105    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14106    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14107   "TARGET_64BIT"
14108   "*
14109 {
14110   if (which_alternative != 0)
14111     return \"#\";
14112   else if (get_attr_length (insn) == 4)
14113     return \"{bdn|bdnz} %l0\";
14114   else
14115     return \"bdz $+8\;b %l0\";
14116 }"
14117   [(set_attr "type" "branch")
14118    (set_attr "length" "*,12,16,16")])
14119
14120 ;; Now the splitters if we could not allocate the CTR register
14121
14122 (define_split
14123   [(set (pc)
14124         (if_then_else (match_operator 2 "comparison_operator"
14125                                       [(match_operand:SI 1 "gpc_reg_operand" "")
14126                                        (const_int 1)])
14127                       (match_operand 5 "" "")
14128                       (match_operand 6 "" "")))
14129    (set (match_operand:SI 0 "gpc_reg_operand" "")
14130         (plus:SI (match_dup 1)
14131                  (const_int -1)))
14132    (clobber (match_scratch:CC 3 ""))
14133    (clobber (match_scratch:SI 4 ""))]
14134   "TARGET_32BIT && reload_completed"
14135   [(parallel [(set (match_dup 3)
14136                    (compare:CC (plus:SI (match_dup 1)
14137                                         (const_int -1))
14138                                (const_int 0)))
14139               (set (match_dup 0)
14140                    (plus:SI (match_dup 1)
14141                             (const_int -1)))])
14142    (set (pc) (if_then_else (match_dup 7)
14143                            (match_dup 5)
14144                            (match_dup 6)))]
14145   "
14146 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14147                                 operands[3], const0_rtx); }")
14148
14149 (define_split
14150   [(set (pc)
14151         (if_then_else (match_operator 2 "comparison_operator"
14152                                       [(match_operand:SI 1 "gpc_reg_operand" "")
14153                                        (const_int 1)])
14154                       (match_operand 5 "" "")
14155                       (match_operand 6 "" "")))
14156    (set (match_operand:SI 0 "nonimmediate_operand" "")
14157         (plus:SI (match_dup 1) (const_int -1)))
14158    (clobber (match_scratch:CC 3 ""))
14159    (clobber (match_scratch:SI 4 ""))]
14160   "TARGET_32BIT && reload_completed
14161    && ! gpc_reg_operand (operands[0], SImode)"
14162   [(parallel [(set (match_dup 3)
14163                    (compare:CC (plus:SI (match_dup 1)
14164                                         (const_int -1))
14165                                (const_int 0)))
14166               (set (match_dup 4)
14167                    (plus:SI (match_dup 1)
14168                             (const_int -1)))])
14169    (set (match_dup 0)
14170         (match_dup 4))
14171    (set (pc) (if_then_else (match_dup 7)
14172                            (match_dup 5)
14173                            (match_dup 6)))]
14174   "
14175 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14176                                 operands[3], const0_rtx); }")
14177 (define_split
14178   [(set (pc)
14179         (if_then_else (match_operator 2 "comparison_operator"
14180                                       [(match_operand:DI 1 "gpc_reg_operand" "")
14181                                        (const_int 1)])
14182                       (match_operand 5 "" "")
14183                       (match_operand 6 "" "")))
14184    (set (match_operand:DI 0 "gpc_reg_operand" "")
14185         (plus:DI (match_dup 1)
14186                  (const_int -1)))
14187    (clobber (match_scratch:CC 3 ""))
14188    (clobber (match_scratch:DI 4 ""))]
14189   "TARGET_64BIT && reload_completed"
14190   [(parallel [(set (match_dup 3)
14191                    (compare:CC (plus:DI (match_dup 1)
14192                                         (const_int -1))
14193                                (const_int 0)))
14194               (set (match_dup 0)
14195                    (plus:DI (match_dup 1)
14196                             (const_int -1)))])
14197    (set (pc) (if_then_else (match_dup 7)
14198                            (match_dup 5)
14199                            (match_dup 6)))]
14200   "
14201 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14202                                 operands[3], const0_rtx); }")
14203
14204 (define_split
14205   [(set (pc)
14206         (if_then_else (match_operator 2 "comparison_operator"
14207                                       [(match_operand:DI 1 "gpc_reg_operand" "")
14208                                        (const_int 1)])
14209                       (match_operand 5 "" "")
14210                       (match_operand 6 "" "")))
14211    (set (match_operand:DI 0 "nonimmediate_operand" "")
14212         (plus:DI (match_dup 1) (const_int -1)))
14213    (clobber (match_scratch:CC 3 ""))
14214    (clobber (match_scratch:DI 4 ""))]
14215   "TARGET_64BIT && reload_completed
14216    && ! gpc_reg_operand (operands[0], DImode)"
14217   [(parallel [(set (match_dup 3)
14218                    (compare:CC (plus:DI (match_dup 1)
14219                                         (const_int -1))
14220                                (const_int 0)))
14221               (set (match_dup 4)
14222                    (plus:DI (match_dup 1)
14223                             (const_int -1)))])
14224    (set (match_dup 0)
14225         (match_dup 4))
14226    (set (pc) (if_then_else (match_dup 7)
14227                            (match_dup 5)
14228                            (match_dup 6)))]
14229   "
14230 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14231                                 operands[3], const0_rtx); }")
14232 \f
14233 (define_insn "trap"
14234   [(trap_if (const_int 1) (const_int 0))]
14235   ""
14236   "{t 31,0,0|trap}")
14237
14238 (define_expand "conditional_trap"
14239   [(trap_if (match_operator 0 "trap_comparison_operator"
14240                             [(match_dup 2) (match_dup 3)])
14241             (match_operand 1 "const_int_operand" ""))]
14242   ""
14243   "if (rs6000_compare_fp_p || operands[1] != const0_rtx) FAIL;
14244    operands[2] = rs6000_compare_op0;
14245    operands[3] = rs6000_compare_op1;")
14246
14247 (define_insn ""
14248   [(trap_if (match_operator 0 "trap_comparison_operator"
14249                             [(match_operand:SI 1 "register_operand" "r")
14250                              (match_operand:SI 2 "reg_or_short_operand" "rI")])
14251             (const_int 0))]
14252   ""
14253   "{t|tw}%V0%I2 %1,%2")
14254
14255 (define_insn ""
14256   [(trap_if (match_operator 0 "trap_comparison_operator"
14257                             [(match_operand:DI 1 "register_operand" "r")
14258                              (match_operand:DI 2 "reg_or_short_operand" "rI")])
14259             (const_int 0))]
14260   "TARGET_POWERPC64"
14261   "td%V0%I2 %1,%2")
14262 \f
14263 ;; Insns related to generating the function prologue and epilogue.
14264
14265 (define_expand "prologue"
14266   [(use (const_int 0))]
14267   "TARGET_SCHED_PROLOG"
14268   "
14269 {
14270       rs6000_emit_prologue ();
14271       DONE;
14272 }")
14273
14274 (define_insn "*movesi_from_cr_one"
14275   [(match_parallel 0 "mfcr_operation"
14276                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14277                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
14278                                      (match_operand 3 "immediate_operand" "n")]
14279                           UNSPEC_MOVESI_FROM_CR))])]
14280   "TARGET_MFCRF"
14281   "*
14282 {
14283   int mask = 0;
14284   int i;
14285   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14286   {
14287     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14288     operands[4] = GEN_INT (mask);
14289     output_asm_insn (\"mfcr %1,%4\", operands);
14290   }
14291   return \"\";
14292 }"
14293   [(set_attr "type" "mfcrf")])
14294
14295 (define_insn "movesi_from_cr"
14296   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14297         (unspec:SI [(reg:CC 68) (reg:CC 69) (reg:CC 70) (reg:CC 71)
14298                     (reg:CC 72) (reg:CC 73) (reg:CC 74) (reg:CC 75)]
14299                    UNSPEC_MOVESI_FROM_CR))]
14300   ""
14301   "mfcr %0"
14302   [(set_attr "type" "mfcr")])
14303
14304 (define_insn "*stmw"
14305   [(match_parallel 0 "stmw_operation"
14306                    [(set (match_operand:SI 1 "memory_operand" "=m")
14307                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
14308   "TARGET_MULTIPLE"
14309   "{stm|stmw} %2,%1")
14310
14311 (define_insn "*save_fpregs_si"
14312   [(match_parallel 0 "any_parallel_operand"
14313                    [(clobber (match_operand:SI 1 "register_operand" "=l"))
14314                     (use (match_operand:SI 2 "call_operand" "s"))
14315                     (set (match_operand:DF 3 "memory_operand" "=m")
14316                          (match_operand:DF 4 "gpc_reg_operand" "f"))])]
14317   "TARGET_32BIT"
14318   "bl %z2"
14319   [(set_attr "type" "branch")
14320    (set_attr "length" "4")])
14321
14322 (define_insn "*save_fpregs_di"
14323   [(match_parallel 0 "any_parallel_operand"
14324                    [(clobber (match_operand:DI 1 "register_operand" "=l"))
14325                     (use (match_operand:DI 2 "call_operand" "s"))
14326                     (set (match_operand:DF 3 "memory_operand" "=m")
14327                          (match_operand:DF 4 "gpc_reg_operand" "f"))])]
14328   "TARGET_64BIT"
14329   "bl %z2"
14330   [(set_attr "type" "branch")
14331    (set_attr "length" "4")])
14332
14333 ; These are to explain that changes to the stack pointer should
14334 ; not be moved over stores to stack memory.
14335 (define_insn "stack_tie"
14336   [(set (match_operand:BLK 0 "memory_operand" "+m")
14337         (unspec:BLK [(match_dup 0)] UNSPEC_TIE))]
14338   ""
14339   ""
14340   [(set_attr "length" "0")])
14341
14342
14343 (define_expand "epilogue"
14344   [(use (const_int 0))]
14345   "TARGET_SCHED_PROLOG"
14346   "
14347 {
14348       rs6000_emit_epilogue (FALSE);
14349       DONE;
14350 }")
14351
14352 ; On some processors, doing the mtcrf one CC register at a time is
14353 ; faster (like on the 604e).  On others, doing them all at once is
14354 ; faster; for instance, on the 601 and 750.
14355
14356 (define_expand "movsi_to_cr_one"
14357   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14358         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14359                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
14360   ""
14361   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
14362
14363 (define_insn "*movsi_to_cr"
14364   [(match_parallel 0 "mtcrf_operation"
14365                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
14366                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
14367                                      (match_operand 3 "immediate_operand" "n")]
14368                                     UNSPEC_MOVESI_TO_CR))])]
14369  ""
14370  "*
14371 {
14372   int mask = 0;
14373   int i;
14374   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14375     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14376   operands[4] = GEN_INT (mask);
14377   return \"mtcrf %4,%2\";
14378 }"
14379   [(set_attr "type" "mtcr")])
14380
14381 (define_insn "*mtcrfsi"
14382   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14383         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14384                     (match_operand 2 "immediate_operand" "n")]
14385                    UNSPEC_MOVESI_TO_CR))]
14386   "GET_CODE (operands[0]) == REG
14387    && CR_REGNO_P (REGNO (operands[0]))
14388    && GET_CODE (operands[2]) == CONST_INT
14389    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
14390   "mtcrf %R0,%1"
14391   [(set_attr "type" "mtcr")])
14392
14393 ; The load-multiple instructions have similar properties.
14394 ; Note that "load_multiple" is a name known to the machine-independent
14395 ; code that actually corresponds to the powerpc load-string.
14396
14397 (define_insn "*lmw"
14398   [(match_parallel 0 "lmw_operation"
14399                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14400                          (match_operand:SI 2 "memory_operand" "m"))])]
14401   "TARGET_MULTIPLE"
14402   "{lm|lmw} %1,%2")
14403
14404 (define_insn "*return_internal_si"
14405   [(return)
14406    (use (match_operand:SI 0 "register_operand" "lc"))]
14407   "TARGET_32BIT"
14408   "b%T0"
14409   [(set_attr "type" "jmpreg")])
14410
14411 (define_insn "*return_internal_di"
14412   [(return)
14413    (use (match_operand:DI 0 "register_operand" "lc"))]
14414   "TARGET_64BIT"
14415   "b%T0"
14416   [(set_attr "type" "jmpreg")])
14417
14418 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
14419 ; stuff was in GCC.  Oh, and "any_parallel_operand" is a bit flexible...
14420
14421 (define_insn "*return_and_restore_fpregs_si"
14422  [(match_parallel 0 "any_parallel_operand"
14423                   [(return)
14424                    (use (match_operand:SI 1 "register_operand" "l"))
14425                    (use (match_operand:SI 2 "call_operand" "s"))
14426                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
14427                         (match_operand:DF 4 "memory_operand" "m"))])]
14428  "TARGET_32BIT"
14429  "b %z2")
14430
14431 (define_insn "*return_and_restore_fpregs_di"
14432  [(match_parallel 0 "any_parallel_operand"
14433                   [(return)
14434                    (use (match_operand:DI 1 "register_operand" "l"))
14435                    (use (match_operand:DI 2 "call_operand" "s"))
14436                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
14437                         (match_operand:DF 4 "memory_operand" "m"))])]
14438  "TARGET_64BIT"
14439  "b %z2")
14440
14441 ; This is used in compiling the unwind routines.
14442 (define_expand "eh_return"
14443   [(use (match_operand 0 "general_operand" ""))]
14444   ""
14445   "
14446 {
14447   if (TARGET_32BIT)
14448     emit_insn (gen_eh_set_lr_si (operands[0]));
14449   else
14450     emit_insn (gen_eh_set_lr_di (operands[0]));
14451   DONE;
14452 }")
14453
14454 ; We can't expand this before we know where the link register is stored.
14455 (define_insn "eh_set_lr_si"
14456   [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
14457                     UNSPECV_EH_RR)
14458    (clobber (match_scratch:SI 1 "=&b"))]
14459   "TARGET_32BIT"
14460   "#")
14461
14462 (define_insn "eh_set_lr_di"
14463   [(unspec_volatile [(match_operand:DI 0 "register_operand" "r")]
14464                     UNSPECV_EH_RR)
14465    (clobber (match_scratch:DI 1 "=&b"))]
14466   "TARGET_64BIT"
14467   "#")
14468
14469 (define_split
14470   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
14471    (clobber (match_scratch 1 ""))]
14472   "reload_completed"
14473   [(const_int 0)]
14474   "
14475 {
14476   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
14477   DONE;
14478 }")
14479
14480 (define_insn "prefetch"
14481   [(prefetch (match_operand:V4SI 0 "address_operand" "p")
14482              (match_operand:SI 1 "const_int_operand" "n")
14483              (match_operand:SI 2 "const_int_operand" "n"))]
14484   "TARGET_POWERPC"
14485   "*
14486 {
14487   if (GET_CODE (operands[0]) == REG)
14488     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
14489   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
14490 }"
14491   [(set_attr "type" "load")])
14492 \f
14493 ; Atomic instructions
14494
14495 (define_insn "memory_barrier"
14496   [(set (mem:BLK (match_scratch 0 "X"))
14497         (unspec:BLK [(mem:BLK (match_scratch 1 "X"))] UNSPEC_SYNC))]
14498   ""
14499   "{ics|sync}")
14500
14501 (define_insn "sync_compare_and_swap<mode>"
14502   [(set (match_operand:GPR 1 "memory_operand" "+Z")
14503         (unspec:GPR [(match_dup 1)
14504                      (match_operand:GPR 2 "reg_or_short_operand" "rI")
14505                      (match_operand:GPR 3 "gpc_reg_operand" "r")]
14506                     UNSPEC_SYNC_SWAP))
14507    (set (match_operand:GPR 0 "gpc_reg_operand" "=&r") (match_dup 1))
14508    (set (mem:BLK (match_scratch 5 "X"))
14509         (unspec:BLK [(mem:BLK (match_scratch 6 "X"))] UNSPEC_SYNC))
14510    (clobber (match_scratch:CC 4 "=&x"))]
14511   "TARGET_POWERPC"
14512   "sync\n\t<larx> %0,%y1\n\tcmp<wd>%I2 %0,%2\n\tbne- $+12\n\t<stcx> %3,%y1\n\tbne- $-16\n\tisync"
14513   [(set_attr "length" "28")])
14514
14515 (define_expand "sync_add<mode>"
14516   [(use (match_operand:INT1 0 "memory_operand" ""))
14517    (use (match_operand:INT1 1 "add_operand" ""))]
14518   "TARGET_POWERPC"
14519   "
14520 {
14521   rs6000_emit_sync (PLUS, <MODE>mode, operands[0], operands[1], 
14522                     NULL_RTX, NULL_RTX, true);
14523   DONE;
14524 }")
14525
14526 (define_expand "sync_sub<mode>"
14527   [(use (match_operand:GPR 0 "memory_operand" ""))
14528    (use (match_operand:GPR 1 "gpc_reg_operand" ""))]
14529   "TARGET_POWERPC"
14530   "
14531 {
14532   rs6000_emit_sync (MINUS, <MODE>mode, operands[0], operands[1], 
14533                     NULL_RTX, NULL_RTX, true);
14534   DONE;
14535 }")
14536
14537 (define_expand "sync_ior<mode>"
14538   [(use (match_operand:INT1 0 "memory_operand" ""))
14539    (use (match_operand:INT1 1 "logical_operand" ""))]
14540   "TARGET_POWERPC"
14541   "
14542 {
14543   rs6000_emit_sync (IOR, <MODE>mode, operands[0], operands[1], 
14544                     NULL_RTX, NULL_RTX, true);
14545   DONE;
14546 }")
14547
14548 (define_expand "sync_and<mode>"
14549   [(use (match_operand:INT1 0 "memory_operand" ""))
14550    (use (match_operand:INT1 1 "and_operand" ""))]
14551   "TARGET_POWERPC"
14552   "
14553 {
14554   rs6000_emit_sync (AND, <MODE>mode, operands[0], operands[1], 
14555                     NULL_RTX, NULL_RTX, true);
14556   DONE;
14557 }")
14558
14559 (define_expand "sync_xor<mode>"
14560   [(use (match_operand:INT1 0 "memory_operand" ""))
14561    (use (match_operand:INT1 1 "logical_operand" ""))]
14562   "TARGET_POWERPC"
14563   "
14564 {
14565   rs6000_emit_sync (XOR, <MODE>mode, operands[0], operands[1], 
14566                     NULL_RTX, NULL_RTX, true);
14567   DONE;
14568 }")
14569
14570 (define_expand "sync_nand<mode>"
14571   [(use (match_operand:INT1 0 "memory_operand" ""))
14572    (use (match_operand:INT1 1 "gpc_reg_operand" ""))]
14573   "TARGET_POWERPC"
14574   "
14575 {
14576   rs6000_emit_sync (AND, <MODE>mode, 
14577                     gen_rtx_NOT (<MODE>mode, operands[0]),
14578                     operands[1],
14579                     NULL_RTX, NULL_RTX, true);
14580   DONE;
14581 }")
14582
14583 (define_expand "sync_old_add<mode>"
14584   [(use (match_operand:INT1 0 "gpc_reg_operand" ""))
14585    (use (match_operand:INT1 1 "memory_operand" ""))
14586    (use (match_operand:INT1 2 "add_operand" ""))]
14587   "TARGET_POWERPC"
14588   "
14589 {
14590   rs6000_emit_sync (PLUS, <MODE>mode, operands[1], operands[2], 
14591                     operands[0], NULL_RTX, true);
14592   DONE;
14593 }")
14594
14595 (define_expand "sync_old_sub<mode>"
14596   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
14597    (use (match_operand:GPR 1 "memory_operand" ""))
14598    (use (match_operand:GPR 2 "gpc_reg_operand" ""))]
14599   "TARGET_POWERPC"
14600   "
14601 {
14602   rs6000_emit_sync (MINUS, <MODE>mode, operands[1], operands[2], 
14603                     operands[0], NULL_RTX, true);
14604   DONE;
14605 }")
14606
14607 (define_expand "sync_old_ior<mode>"
14608   [(use (match_operand:INT1 0 "gpc_reg_operand" ""))
14609    (use (match_operand:INT1 1 "memory_operand" ""))
14610    (use (match_operand:INT1 2 "logical_operand" ""))]
14611   "TARGET_POWERPC"
14612   "
14613 {
14614   rs6000_emit_sync (IOR, <MODE>mode, operands[1], operands[2], 
14615                     operands[0], NULL_RTX, true);
14616   DONE;
14617 }")
14618
14619 (define_expand "sync_old_and<mode>"
14620   [(use (match_operand:INT1 0 "gpc_reg_operand" ""))
14621    (use (match_operand:INT1 1 "memory_operand" ""))
14622    (use (match_operand:INT1 2 "and_operand" ""))]
14623   "TARGET_POWERPC"
14624   "
14625 {
14626   rs6000_emit_sync (AND, <MODE>mode, operands[1], operands[2], 
14627                     operands[0], NULL_RTX, true);
14628   DONE;
14629 }")
14630
14631 (define_expand "sync_old_xor<mode>"
14632   [(use (match_operand:INT1 0 "gpc_reg_operand" ""))
14633    (use (match_operand:INT1 1 "memory_operand" ""))
14634    (use (match_operand:INT1 2 "logical_operand" ""))]
14635   "TARGET_POWERPC"
14636   "
14637 {
14638   rs6000_emit_sync (XOR, <MODE>mode, operands[1], operands[2], 
14639                     operands[0], NULL_RTX, true);
14640   DONE;
14641 }")
14642
14643 (define_expand "sync_old_nand<mode>"
14644   [(use (match_operand:INT1 0 "gpc_reg_operand" ""))
14645    (use (match_operand:INT1 1 "memory_operand" ""))
14646    (use (match_operand:INT1 2 "gpc_reg_operand" ""))]
14647   "TARGET_POWERPC"
14648   "
14649 {
14650   rs6000_emit_sync (AND, <MODE>mode, 
14651                     gen_rtx_NOT (<MODE>mode, operands[1]),
14652                     operands[2],
14653                     operands[0], NULL_RTX, true);
14654   DONE;
14655 }")
14656
14657 (define_expand "sync_new_add<mode>"
14658   [(use (match_operand:INT1 0 "gpc_reg_operand" ""))
14659    (use (match_operand:INT1 1 "memory_operand" ""))
14660    (use (match_operand:INT1 2 "add_operand" ""))]
14661   "TARGET_POWERPC"
14662   "
14663 {
14664   rs6000_emit_sync (PLUS, <MODE>mode, operands[1], operands[2], 
14665                     NULL_RTX, operands[0], true);
14666   DONE;
14667 }")
14668
14669 (define_expand "sync_new_sub<mode>"
14670   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
14671    (use (match_operand:GPR 1 "memory_operand" ""))
14672    (use (match_operand:GPR 2 "gpc_reg_operand" ""))]
14673   "TARGET_POWERPC"
14674   "
14675 {
14676   rs6000_emit_sync (MINUS, <MODE>mode, operands[1], operands[2], 
14677                     NULL_RTX, operands[0], true);
14678   DONE;
14679 }")
14680
14681 (define_expand "sync_new_ior<mode>"
14682   [(use (match_operand:INT1 0 "gpc_reg_operand" ""))
14683    (use (match_operand:INT1 1 "memory_operand" ""))
14684    (use (match_operand:INT1 2 "logical_operand" ""))]
14685   "TARGET_POWERPC"
14686   "
14687 {
14688   rs6000_emit_sync (IOR, <MODE>mode, operands[1], operands[2], 
14689                     NULL_RTX, operands[0], true);
14690   DONE;
14691 }")
14692
14693 (define_expand "sync_new_and<mode>"
14694   [(use (match_operand:INT1 0 "gpc_reg_operand" ""))
14695    (use (match_operand:INT1 1 "memory_operand" ""))
14696    (use (match_operand:INT1 2 "and_operand" ""))]
14697   "TARGET_POWERPC"
14698   "
14699 {
14700   rs6000_emit_sync (AND, <MODE>mode, operands[1], operands[2], 
14701                     NULL_RTX, operands[0], true);
14702   DONE;
14703 }")
14704
14705 (define_expand "sync_new_xor<mode>"
14706   [(use (match_operand:INT1 0 "gpc_reg_operand" ""))
14707    (use (match_operand:INT1 1 "memory_operand" ""))
14708    (use (match_operand:INT1 2 "logical_operand" ""))]
14709   "TARGET_POWERPC"
14710   "
14711 {
14712   rs6000_emit_sync (XOR, <MODE>mode, operands[1], operands[2], 
14713                     NULL_RTX, operands[0], true);
14714   DONE;
14715 }")
14716
14717 (define_expand "sync_new_nand<mode>"
14718   [(use (match_operand:INT1 0 "gpc_reg_operand" ""))
14719    (use (match_operand:INT1 1 "memory_operand" ""))
14720    (use (match_operand:INT1 2 "gpc_reg_operand" ""))]
14721   "TARGET_POWERPC"
14722   "
14723 {
14724   rs6000_emit_sync (AND, <MODE>mode, 
14725                     gen_rtx_NOT (<MODE>mode, operands[1]),
14726                     operands[2],
14727                     NULL_RTX, operands[0], true);
14728   DONE;
14729 }")
14730
14731 ; the sync_*_internal patterns all have these operands:
14732 ; 0 - memory location
14733 ; 1 - operand
14734 ; 2 - value in memory after operation
14735 ; 3 - value in memory immediately before operation
14736
14737 (define_insn "*sync_add<mode>_internal"
14738   [(set (match_operand:GPR 2 "gpc_reg_operand" "=&r,&r")
14739         (plus:GPR (match_operand:GPR 0 "memory_operand" "+Z,Z")
14740                  (match_operand:GPR 1 "add_operand" "rI,L")))
14741    (set (match_operand:GPR 3 "gpc_reg_operand" "=&b,&b") (match_dup 0))
14742    (set (match_dup 0) 
14743         (unspec:GPR [(plus:GPR (match_dup 0) (match_dup 1))]
14744                    UNSPEC_SYNC_OP))
14745    (clobber (match_scratch:CC 4 "=&x,&x"))]
14746   "TARGET_POWERPC"
14747   "@
14748    <larx> %3,%y0\n\tadd%I1 %2,%3,%1\n\t<stcx> %2,%y0\n\tbne- $-12
14749    <larx> %3,%y0\n\taddis %2,%3,%v1\n\t<stcx> %2,%y0\n\tbne- $-12"
14750   [(set_attr "length" "16,16")])
14751
14752 (define_insn "*sync_addshort_internal"
14753   [(set (match_operand:SI 2 "gpc_reg_operand" "=&r")
14754         (ior:SI (and:SI (plus:SI (match_operand:SI 0 "memory_operand" "+Z")
14755                                  (match_operand:SI 1 "add_operand" "rI"))
14756                         (match_operand:SI 4 "gpc_reg_operand" "r"))
14757                 (and:SI (not:SI (match_dup 4)) (match_dup 0))))
14758    (set (match_operand:SI 3 "gpc_reg_operand" "=&b") (match_dup 0))
14759    (set (match_dup 0) 
14760         (unspec:SI [(ior:SI (and:SI (plus:SI (match_dup 0) (match_dup 1))
14761                                     (match_dup 4))
14762                             (and:SI (not:SI (match_dup 4)) (match_dup 0)))]
14763                    UNSPEC_SYNC_OP))
14764    (clobber (match_scratch:CC 5 "=&x"))
14765    (clobber (match_scratch:SI 6 "=&r"))]
14766   "TARGET_POWERPC"
14767   "lwarx %3,%y0\n\tadd%I1 %2,%3,%1\n\tandc %6,%3,%4\n\tand %2,%2,%4\n\tor %2,%2,%6\n\tstwcx. %2,%y0\n\tbne- $-24"
14768   [(set_attr "length" "28")])
14769
14770 (define_insn "*sync_sub<mode>_internal"
14771   [(set (match_operand:GPR 2 "gpc_reg_operand" "=&r")
14772         (minus:GPR (match_operand:GPR 0 "memory_operand" "+Z")
14773                   (match_operand:GPR 1 "gpc_reg_operand" "r")))
14774    (set (match_operand:GPR 3 "gpc_reg_operand" "=&b") (match_dup 0))
14775    (set (match_dup 0) 
14776         (unspec:GPR [(minus:GPR (match_dup 0) (match_dup 1))]
14777                    UNSPEC_SYNC_OP))
14778    (clobber (match_scratch:CC 4 "=&x"))]
14779   "TARGET_POWERPC"
14780   "<larx> %3,%y0\n\tsubf %2,%1,%3\n\t<stcx> %2,%y0\n\tbne- $-12"
14781   [(set_attr "length" "16")])
14782
14783 (define_insn "*sync_andsi_internal"
14784   [(set (match_operand:SI 2 "gpc_reg_operand" "=&r,&r,&r,&r")
14785         (and:SI (match_operand:SI 0 "memory_operand" "+Z,Z,Z,Z")
14786                 (match_operand:SI 1 "and_operand" "r,T,K,L")))
14787    (set (match_operand:SI 3 "gpc_reg_operand" "=&b,&b,&b,&b") (match_dup 0))
14788    (set (match_dup 0) 
14789         (unspec:SI [(and:SI (match_dup 0) (match_dup 1))]
14790                    UNSPEC_SYNC_OP))
14791    (clobber (match_scratch:CC 4 "=&x,&x,&x,&x"))]
14792   "TARGET_POWERPC"
14793   "@
14794    lwarx %3,%y0\n\tand %2,%3,%1\n\tstwcx. %2,%y0\n\tbne- $-12
14795    lwarx %3,%y0\n\trlwinm %2,%3,0,%m1,%M1\n\tstwcx. %2,%y0\n\tbne- $-12
14796    lwarx %3,%y0\n\tandi. %2,%3,%b1\n\tstwcx. %2,%y0\n\tbne- $-12
14797    lwarx %3,%y0\n\tandis. %2,%3,%u1\n\tstwcx. %2,%y0\n\tbne- $-12"
14798   [(set_attr "length" "16,16,16,16")])
14799
14800 (define_insn "*sync_anddi_internal"
14801   [(set (match_operand:DI 2 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
14802         (and:DI (match_operand:DI 0 "memory_operand" "+Z,Z,Z,Z,Z")
14803                 (match_operand:DI 1 "and_operand" "r,S,T,K,J")))
14804    (set (match_operand:DI 3 "gpc_reg_operand" "=&b,&b,&b,&b,&b") (match_dup 0))
14805    (set (match_dup 0) 
14806         (unspec:DI [(and:DI (match_dup 0) (match_dup 1))]
14807                    UNSPEC_SYNC_OP))
14808    (clobber (match_scratch:CC 4 "=&x,&x,&x,&x,&x"))]
14809   "TARGET_POWERPC64"
14810   "@
14811    ldarx %3,%y0\n\tand %2,%3,%1\n\tstdcx. %2,%y0\n\tbne- $-12
14812    ldarx %3,%y0\n\trldic%B1 %2,%3,0,%S1\n\tstdcx. %2,%y0\n\tbne- $-12
14813    ldarx %3,%y0\n\trlwinm %2,%3,0,%m1,%M1\n\tstdcx. %2,%y0\n\tbne- $-12
14814    ldarx %3,%y0\n\tandi. %2,%3,%b1\n\tstdcx. %2,%y0\n\tbne- $-12
14815    ldarx %3,%y0\n\tandis. %2,%3,%b1\n\tstdcx. %2,%y0\n\tbne- $-12"
14816   [(set_attr "length" "16,16,16,16,16")])
14817
14818 (define_insn "*sync_boolsi_internal"
14819   [(set (match_operand:SI 2 "gpc_reg_operand" "=&r,&r,&r")
14820         (match_operator:SI 4 "boolean_or_operator"
14821          [(match_operand:SI 0 "memory_operand" "+Z,Z,Z")
14822           (match_operand:SI 1 "logical_operand" "r,K,L")]))
14823    (set (match_operand:SI 3 "gpc_reg_operand" "=&b,&b,&b") (match_dup 0))
14824    (set (match_dup 0) (unspec:SI [(match_dup 4)] UNSPEC_SYNC_OP))
14825    (clobber (match_scratch:CC 5 "=&x,&x,&x"))]
14826   "TARGET_POWERPC"
14827   "@
14828    lwarx %3,%y0\n\t%q4 %2,%3,%1\n\tstwcx. %2,%y0\n\tbne- $-12
14829    lwarx %3,%y0\n\t%q4i %2,%3,%b1\n\tstwcx. %2,%y0\n\tbne- $-12
14830    lwarx %3,%y0\n\t%q4is %2,%3,%u1\n\tstwcx. %2,%y0\n\tbne- $-12"
14831   [(set_attr "length" "16,16,16")])
14832
14833 (define_insn "*sync_booldi_internal"
14834   [(set (match_operand:DI 2 "gpc_reg_operand" "=&r,&r,&r")
14835         (match_operator:DI 4 "boolean_or_operator"
14836          [(match_operand:DI 0 "memory_operand" "+Z,Z,Z")
14837           (match_operand:DI 1 "logical_operand" "r,K,JF")]))
14838    (set (match_operand:DI 3 "gpc_reg_operand" "=&b,&b,&b") (match_dup 0))
14839    (set (match_dup 0) (unspec:DI [(match_dup 4)] UNSPEC_SYNC_OP))
14840    (clobber (match_scratch:CC 5 "=&x,&x,&x"))]
14841   "TARGET_POWERPC64"
14842   "@
14843    ldarx %3,%y0\n\t%q4 %2,%3,%1\n\tstdcx. %2,%y0\n\tbne- $-12
14844    ldarx %3,%y0\n\t%q4i %2,%3,%b1\n\tstdcx. %2,%y0\n\tbne- $-12
14845    ldarx %3,%y0\n\t%q4is %2,%3,%u1\n\tstdcx. %2,%y0\n\tbne- $-12"
14846   [(set_attr "length" "16,16,16")])
14847
14848 (define_insn "*sync_boolc<mode>_internal"
14849   [(set (match_operand:GPR 2 "gpc_reg_operand" "=&r")
14850         (match_operator:GPR 4 "boolean_operator"
14851          [(not:GPR (match_operand:GPR 0 "memory_operand" "+Z"))
14852           (match_operand:GPR 1 "gpc_reg_operand" "r")]))
14853    (set (match_operand:GPR 3 "gpc_reg_operand" "=&b") (match_dup 0))
14854    (set (match_dup 0) (unspec:GPR [(match_dup 4)] UNSPEC_SYNC_OP))
14855    (clobber (match_scratch:CC 5 "=&x"))]
14856   "TARGET_POWERPC"
14857   "<larx> %3,%y0\n\t%q4 %2,%1,%3\n\t<stcx> %2,%y0\n\tbne- $-12"
14858   [(set_attr "length" "16")])
14859
14860 ; This pattern could also take immediate values of operand 1,
14861 ; since the non-NOT version of the operator is used; but this is not
14862 ; very useful, since in practice operand 1 is a full 32-bit value.
14863 ; Likewise, operand 5 is in practice either <= 2^16 or it is a register.
14864 (define_insn "*sync_boolcshort_internal"
14865   [(set (match_operand:SI 2 "gpc_reg_operand" "=&r")
14866         (match_operator:SI 4 "boolean_operator"
14867          [(xor:SI (match_operand:SI 0 "memory_operand" "+Z")
14868                   (match_operand:SI 5 "logical_operand" "rK"))
14869           (match_operand:SI 1 "gpc_reg_operand" "r")]))
14870    (set (match_operand:SI 3 "gpc_reg_operand" "=&b") (match_dup 0))
14871    (set (match_dup 0) (unspec:SI [(match_dup 4)] UNSPEC_SYNC_OP))
14872    (clobber (match_scratch:CC 6 "=&x"))]
14873   "TARGET_POWERPC"
14874   "lwarx %3,%y0\n\txor%I2 %2,%3,%5\n\t%q4 %2,%2,%1\n\tstwcx. %2,%y0\n\tbne- $-16"
14875   [(set_attr "length" "20")])
14876
14877 (define_insn "*sync_boolc<mode>_internal2"
14878   [(set (match_operand:GPR 2 "gpc_reg_operand" "=&r")
14879         (match_operator:GPR 4 "boolean_operator"
14880          [(not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r"))
14881           (match_operand:GPR 0 "memory_operand" "+Z")]))
14882    (set (match_operand:GPR 3 "gpc_reg_operand" "=&b") (match_dup 0))
14883    (set (match_dup 0) (unspec:GPR [(match_dup 4)] UNSPEC_SYNC_OP))
14884    (clobber (match_scratch:CC 5 "=&x"))]
14885   "TARGET_POWERPC"
14886   "<larx> %3,%y0\n\t%q4 %2,%3,%1\n\t<stcx> %2,%y0\n\tbne- $-12"
14887   [(set_attr "length" "16")])
14888
14889 (define_insn "*sync_boolcc<mode>_internal"
14890   [(set (match_operand:GPR 2 "gpc_reg_operand" "=&r")
14891         (match_operator:GPR 4 "boolean_operator"
14892          [(not:GPR (match_operand:GPR 0 "memory_operand" "+Z"))
14893           (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r"))]))
14894    (set (match_operand:GPR 3 "gpc_reg_operand" "=&b") (match_dup 0))
14895    (set (match_dup 0) (unspec:GPR [(match_dup 4)] UNSPEC_SYNC_OP))
14896    (clobber (match_scratch:CC 5 "=&x"))]
14897   "TARGET_POWERPC"
14898   "<larx> %3,%y0\n\t%q4 %2,%1,%3\n\t<stcx> %2,%y0\n\tbne- $-12"
14899   [(set_attr "length" "16")])
14900
14901 (define_insn "isync"
14902   [(set (mem:BLK (match_scratch 0 "X"))
14903         (unspec:BLK [(mem:BLK (match_scratch 1 "X"))] UNSPEC_ISYNC))]
14904   "TARGET_POWERPC"
14905   "isync")
14906
14907 (define_insn "sync_lock_test_and_set<mode>"
14908   [(set (match_operand:GPR 0 "gpc_reg_operand" "=&r")
14909         (match_operand:GPR 1 "memory_operand" "+Z"))
14910    (set (match_dup 1) (unspec:GPR [(match_operand:GPR 2 "gpc_reg_operand" "r")] 
14911                                  UNSPEC_SYNC_OP))
14912    (clobber (match_scratch:CC 3 "=&x"))
14913    (set (mem:BLK (match_scratch 4 "X"))
14914         (unspec:BLK [(mem:BLK (match_scratch 5 "X"))] UNSPEC_ISYNC))]
14915   "TARGET_POWERPC"
14916   "<larx> %0,%y1\n\t<stcx> %2,%y1\n\tbne- $-8\n\tisync"
14917   [(set_attr "length" "16")])
14918
14919 (define_expand "sync_lock_release<mode>"
14920   [(set (match_operand:INT 0 "memory_operand")
14921         (match_operand:INT 1 "any_operand"))]
14922   ""
14923   "
14924 {
14925   emit_insn (gen_lwsync ());
14926   emit_move_insn (operands[0], operands[1]);
14927   DONE;
14928 }")
14929
14930 ; Some AIX assemblers don't accept lwsync, so we use a .long.
14931 (define_insn "lwsync"
14932   [(set (mem:BLK (match_scratch 0 "X"))
14933         (unspec:BLK [(mem:BLK (match_scratch 1 "X"))] UNSPEC_LWSYNC))]
14934   ""
14935   ".long 0x7c2004ac")
14936
14937 \f
14938
14939 (include "altivec.md")
14940 (include "spe.md")