OSDN Git Service

Index: ChangeLog
[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   ])
62
63 ;;
64 ;; UNSPEC_VOLATILE usage
65 ;;
66
67 (define_constants
68   [(UNSPECV_BLOCK               0)
69    (UNSPECV_EH_RR               9)      ; eh_reg_restore
70   ])
71 \f
72 ;; Define an insn type attribute.  This is used in function unit delay
73 ;; computations.
74 (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"
75   (const_string "integer"))
76
77 ;; Length (in bytes).
78 ; '(pc)' in the following doesn't include the instruction itself; it is
79 ; calculated as if the instruction had zero size.
80 (define_attr "length" ""
81   (if_then_else (eq_attr "type" "branch")
82                 (if_then_else (and (ge (minus (match_dup 0) (pc))
83                                        (const_int -32768))
84                                    (lt (minus (match_dup 0) (pc))
85                                        (const_int 32764)))
86                               (const_int 4)
87                               (const_int 8))
88                 (const_int 4)))
89
90 ;; Processor type -- this attribute must exactly match the processor_type
91 ;; enumeration in rs6000.h.
92
93 (define_attr "cpu" "rios1,rios2,rs64a,mpccore,ppc403,ppc405,ppc440,ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630,ppc750,ppc7400,ppc7450,ppc8540,power4,power5"
94   (const (symbol_ref "rs6000_cpu_attr")))
95
96 (automata_option "ndfa")
97
98 (include "rios1.md")
99 (include "rios2.md")
100 (include "rs64.md")
101 (include "mpc.md")
102 (include "40x.md")
103 (include "440.md")
104 (include "603.md")
105 (include "6xx.md")
106 (include "7xx.md")
107 (include "7450.md")
108 (include "8540.md")
109 (include "power4.md")
110 (include "power5.md")
111
112 (include "predicates.md")
113
114 (include "darwin.md")
115
116 \f
117 ;; Mode macros
118
119 ; This mode macro allows :GPR to be used to indicate the allowable size
120 ; of whole values in GPRs.
121 (define_mode_macro GPR [SI (DI "TARGET_POWERPC64")])
122
123 ; Any supported integer mode.
124 (define_mode_macro INT [QI HI SI DI TI])
125
126 ; Any supported integer mode that fits in one register.
127 (define_mode_macro INT1 [QI HI SI (DI "TARGET_POWERPC64")])
128
129 ; SImode or DImode, even if DImode doesn't fit in GPRs.
130 (define_mode_macro SDI [SI DI])
131
132 ; The size of a pointer.  Also, the size of the value that a record-condition
133 ; (one with a '.') will compare.
134 (define_mode_macro P [(SI "TARGET_32BIT") (DI "TARGET_64BIT")])
135
136 ; Various instructions that come in SI and DI forms.
137 (define_mode_attr larx [(SI "lwarx") (DI "ldarx")])
138 (define_mode_attr stcx [(SI "stwcx.") (DI "stdcx.")])
139 ; A generic w/d attribute, for things like cmpw/cmpd.
140 (define_mode_attr wd [(SI "w") (DI "d")])
141
142 \f
143 ;; Start with fixed-point load and store insns.  Here we put only the more
144 ;; complex forms.  Basic data transfer is done later.
145
146 (define_expand "zero_extendqidi2"
147   [(set (match_operand:DI 0 "gpc_reg_operand" "")
148         (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "")))]
149   "TARGET_POWERPC64"
150   "")
151
152 (define_insn ""
153   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
154         (zero_extend:DI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
155   "TARGET_POWERPC64"
156   "@
157    lbz%U1%X1 %0,%1
158    rldicl %0,%1,0,56"
159   [(set_attr "type" "load,*")])
160
161 (define_insn ""
162   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
163         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
164                     (const_int 0)))
165    (clobber (match_scratch:DI 2 "=r,r"))]
166   "TARGET_64BIT"
167   "@
168    rldicl. %2,%1,0,56
169    #"
170   [(set_attr "type" "compare")
171    (set_attr "length" "4,8")])
172
173 (define_split
174   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
175         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
176                     (const_int 0)))
177    (clobber (match_scratch:DI 2 ""))]
178   "TARGET_POWERPC64 && reload_completed"
179   [(set (match_dup 2)
180         (zero_extend:DI (match_dup 1)))
181    (set (match_dup 0)
182         (compare:CC (match_dup 2)
183                     (const_int 0)))]
184   "")
185
186 (define_insn ""
187   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
188         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
189                     (const_int 0)))
190    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
191         (zero_extend:DI (match_dup 1)))]
192   "TARGET_64BIT"
193   "@
194    rldicl. %0,%1,0,56
195    #"
196   [(set_attr "type" "compare")
197    (set_attr "length" "4,8")])
198
199 (define_split
200   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
201         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
202                     (const_int 0)))
203    (set (match_operand:DI 0 "gpc_reg_operand" "")
204         (zero_extend:DI (match_dup 1)))]
205   "TARGET_POWERPC64 && reload_completed"
206   [(set (match_dup 0)
207         (zero_extend:DI (match_dup 1)))
208    (set (match_dup 2)
209         (compare:CC (match_dup 0)
210                     (const_int 0)))]
211   "")
212
213 (define_insn "extendqidi2"
214   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
215         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
216   "TARGET_POWERPC64"
217   "extsb %0,%1")
218
219 (define_insn ""
220   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
221         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
222                     (const_int 0)))
223    (clobber (match_scratch:DI 2 "=r,r"))]
224   "TARGET_64BIT"
225   "@
226    extsb. %2,%1
227    #"
228   [(set_attr "type" "compare")
229    (set_attr "length" "4,8")])
230
231 (define_split
232   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
233         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
234                     (const_int 0)))
235    (clobber (match_scratch:DI 2 ""))]
236   "TARGET_POWERPC64 && reload_completed"
237   [(set (match_dup 2)
238         (sign_extend:DI (match_dup 1)))
239    (set (match_dup 0)
240         (compare:CC (match_dup 2)
241                     (const_int 0)))]
242   "")
243
244 (define_insn ""
245   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
246         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
247                     (const_int 0)))
248    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
249         (sign_extend:DI (match_dup 1)))]
250   "TARGET_64BIT"
251   "@
252    extsb. %0,%1
253    #"
254   [(set_attr "type" "compare")
255    (set_attr "length" "4,8")])
256
257 (define_split
258   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
259         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
260                     (const_int 0)))
261    (set (match_operand:DI 0 "gpc_reg_operand" "")
262         (sign_extend:DI (match_dup 1)))]
263   "TARGET_POWERPC64 && reload_completed"
264   [(set (match_dup 0)
265         (sign_extend:DI (match_dup 1)))
266    (set (match_dup 2)
267         (compare:CC (match_dup 0)
268                     (const_int 0)))]
269   "")
270
271 (define_expand "zero_extendhidi2"
272   [(set (match_operand:DI 0 "gpc_reg_operand" "")
273         (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
274   "TARGET_POWERPC64"
275   "")
276
277 (define_insn ""
278   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
279         (zero_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
280   "TARGET_POWERPC64"
281   "@
282    lhz%U1%X1 %0,%1
283    rldicl %0,%1,0,48"
284   [(set_attr "type" "load,*")])
285
286 (define_insn ""
287   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
288         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
289                     (const_int 0)))
290    (clobber (match_scratch:DI 2 "=r,r"))]
291   "TARGET_64BIT"
292   "@
293    rldicl. %2,%1,0,48
294    #"
295   [(set_attr "type" "compare")
296    (set_attr "length" "4,8")])
297
298 (define_split
299   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
300         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
301                     (const_int 0)))
302    (clobber (match_scratch:DI 2 ""))]
303   "TARGET_POWERPC64 && reload_completed"
304   [(set (match_dup 2)
305         (zero_extend:DI (match_dup 1)))
306    (set (match_dup 0)
307         (compare:CC (match_dup 2)
308                     (const_int 0)))]
309   "")
310
311 (define_insn ""
312   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
313         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
314                     (const_int 0)))
315    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
316         (zero_extend:DI (match_dup 1)))]
317   "TARGET_64BIT"
318   "@
319    rldicl. %0,%1,0,48
320    #"
321   [(set_attr "type" "compare")
322    (set_attr "length" "4,8")])
323
324 (define_split
325   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
326         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
327                     (const_int 0)))
328    (set (match_operand:DI 0 "gpc_reg_operand" "")
329         (zero_extend:DI (match_dup 1)))]
330   "TARGET_POWERPC64 && reload_completed"
331   [(set (match_dup 0)
332         (zero_extend:DI (match_dup 1)))
333    (set (match_dup 2)
334         (compare:CC (match_dup 0)
335                     (const_int 0)))]
336   "")
337
338 (define_expand "extendhidi2"
339   [(set (match_operand:DI 0 "gpc_reg_operand" "")
340         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
341   "TARGET_POWERPC64"
342   "")
343
344 (define_insn ""
345   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
346         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
347   "TARGET_POWERPC64"
348   "@
349    lha%U1%X1 %0,%1
350    extsh %0,%1"
351   [(set_attr "type" "load_ext,*")])
352
353 (define_insn ""
354   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
355         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
356                     (const_int 0)))
357    (clobber (match_scratch:DI 2 "=r,r"))]
358   "TARGET_64BIT"
359   "@
360    extsh. %2,%1
361    #"
362   [(set_attr "type" "compare")
363    (set_attr "length" "4,8")])
364
365 (define_split
366   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
367         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
368                     (const_int 0)))
369    (clobber (match_scratch:DI 2 ""))]
370   "TARGET_POWERPC64 && reload_completed"
371   [(set (match_dup 2)
372         (sign_extend:DI (match_dup 1)))
373    (set (match_dup 0)
374         (compare:CC (match_dup 2)
375                     (const_int 0)))]
376   "")
377
378 (define_insn ""
379   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
380         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
381                     (const_int 0)))
382    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
383         (sign_extend:DI (match_dup 1)))]
384   "TARGET_64BIT"
385   "@
386    extsh. %0,%1
387    #"
388   [(set_attr "type" "compare")
389    (set_attr "length" "4,8")])
390
391 (define_split
392   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
393         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
394                     (const_int 0)))
395    (set (match_operand:DI 0 "gpc_reg_operand" "")
396         (sign_extend:DI (match_dup 1)))]
397   "TARGET_POWERPC64 && reload_completed"
398   [(set (match_dup 0)
399         (sign_extend:DI (match_dup 1)))
400    (set (match_dup 2)
401         (compare:CC (match_dup 0)
402                     (const_int 0)))]
403   "")
404
405 (define_expand "zero_extendsidi2"
406   [(set (match_operand:DI 0 "gpc_reg_operand" "")
407         (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
408   "TARGET_POWERPC64"
409   "")
410
411 (define_insn ""
412   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
413         (zero_extend:DI (match_operand:SI 1 "reg_or_mem_operand" "m,r")))]
414   "TARGET_POWERPC64"
415   "@
416    lwz%U1%X1 %0,%1
417    rldicl %0,%1,0,32"
418   [(set_attr "type" "load,*")])
419
420 (define_insn ""
421   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
422         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
423                     (const_int 0)))
424    (clobber (match_scratch:DI 2 "=r,r"))]
425   "TARGET_64BIT"
426   "@
427    rldicl. %2,%1,0,32
428    #"
429   [(set_attr "type" "compare")
430    (set_attr "length" "4,8")])
431
432 (define_split
433   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
434         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
435                     (const_int 0)))
436    (clobber (match_scratch:DI 2 ""))]
437   "TARGET_POWERPC64 && reload_completed"
438   [(set (match_dup 2)
439         (zero_extend:DI (match_dup 1)))
440    (set (match_dup 0)
441         (compare:CC (match_dup 2)
442                     (const_int 0)))]
443   "")
444
445 (define_insn ""
446   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
447         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
448                     (const_int 0)))
449    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
450         (zero_extend:DI (match_dup 1)))]
451   "TARGET_64BIT"
452   "@
453    rldicl. %0,%1,0,32
454    #"
455   [(set_attr "type" "compare")
456    (set_attr "length" "4,8")])
457
458 (define_split
459   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
460         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
461                     (const_int 0)))
462    (set (match_operand:DI 0 "gpc_reg_operand" "")
463         (zero_extend:DI (match_dup 1)))]
464   "TARGET_POWERPC64 && reload_completed"
465   [(set (match_dup 0)
466         (zero_extend:DI (match_dup 1)))
467    (set (match_dup 2)
468         (compare:CC (match_dup 0)
469                     (const_int 0)))]
470   "")
471
472 (define_expand "extendsidi2"
473   [(set (match_operand:DI 0 "gpc_reg_operand" "")
474         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
475   "TARGET_POWERPC64"
476   "")
477
478 (define_insn ""
479   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
480         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
481   "TARGET_POWERPC64"
482   "@
483    lwa%U1%X1 %0,%1
484    extsw %0,%1"
485   [(set_attr "type" "load_ext,*")])
486
487 (define_insn ""
488   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
489         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
490                     (const_int 0)))
491    (clobber (match_scratch:DI 2 "=r,r"))]
492   "TARGET_64BIT"
493   "@
494    extsw. %2,%1
495    #"
496   [(set_attr "type" "compare")
497    (set_attr "length" "4,8")])
498
499 (define_split
500   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
501         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
502                     (const_int 0)))
503    (clobber (match_scratch:DI 2 ""))]
504   "TARGET_POWERPC64 && reload_completed"
505   [(set (match_dup 2)
506         (sign_extend:DI (match_dup 1)))
507    (set (match_dup 0)
508         (compare:CC (match_dup 2)
509                     (const_int 0)))]
510   "")
511
512 (define_insn ""
513   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
514         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
515                     (const_int 0)))
516    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
517         (sign_extend:DI (match_dup 1)))]
518   "TARGET_64BIT"
519   "@
520    extsw. %0,%1
521    #"
522   [(set_attr "type" "compare")
523    (set_attr "length" "4,8")])
524
525 (define_split
526   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
527         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
528                     (const_int 0)))
529    (set (match_operand:DI 0 "gpc_reg_operand" "")
530         (sign_extend:DI (match_dup 1)))]
531   "TARGET_POWERPC64 && reload_completed"
532   [(set (match_dup 0)
533         (sign_extend:DI (match_dup 1)))
534    (set (match_dup 2)
535         (compare:CC (match_dup 0)
536                     (const_int 0)))]
537   "")
538
539 (define_expand "zero_extendqisi2"
540   [(set (match_operand:SI 0 "gpc_reg_operand" "")
541         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
542   ""
543   "")
544
545 (define_insn ""
546   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
547         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
548   ""
549   "@
550    lbz%U1%X1 %0,%1
551    {rlinm|rlwinm} %0,%1,0,0xff"
552   [(set_attr "type" "load,*")])
553
554 (define_insn ""
555   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
556         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
557                     (const_int 0)))
558    (clobber (match_scratch:SI 2 "=r,r"))]
559   ""
560   "@
561    {andil.|andi.} %2,%1,0xff
562    #"
563   [(set_attr "type" "compare")
564    (set_attr "length" "4,8")])
565
566 (define_split
567   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
568         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
569                     (const_int 0)))
570    (clobber (match_scratch:SI 2 ""))]
571   "reload_completed"
572   [(set (match_dup 2)
573         (zero_extend:SI (match_dup 1)))
574    (set (match_dup 0)
575         (compare:CC (match_dup 2)
576                     (const_int 0)))]
577   "")
578
579 (define_insn ""
580   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
581         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
582                     (const_int 0)))
583    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
584         (zero_extend:SI (match_dup 1)))]
585   ""
586   "@
587    {andil.|andi.} %0,%1,0xff
588    #"
589   [(set_attr "type" "compare")
590    (set_attr "length" "4,8")])
591
592 (define_split
593   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
594         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
595                     (const_int 0)))
596    (set (match_operand:SI 0 "gpc_reg_operand" "")
597         (zero_extend:SI (match_dup 1)))]
598   "reload_completed"
599   [(set (match_dup 0)
600         (zero_extend:SI (match_dup 1)))
601    (set (match_dup 2)
602         (compare:CC (match_dup 0)
603                     (const_int 0)))]
604   "")
605
606 (define_expand "extendqisi2"
607   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
608    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
609   ""
610   "
611 {
612   if (TARGET_POWERPC)
613     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
614   else if (TARGET_POWER)
615     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
616   else
617     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
618   DONE;
619 }")
620
621 (define_insn "extendqisi2_ppc"
622   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
623         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
624   "TARGET_POWERPC"
625   "extsb %0,%1")
626
627 (define_insn ""
628   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
629         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
630                     (const_int 0)))
631    (clobber (match_scratch:SI 2 "=r,r"))]
632   "TARGET_POWERPC"
633   "@
634    extsb. %2,%1
635    #"
636   [(set_attr "type" "compare")
637    (set_attr "length" "4,8")])
638
639 (define_split
640   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
641         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
642                     (const_int 0)))
643    (clobber (match_scratch:SI 2 ""))]
644   "TARGET_POWERPC && reload_completed"
645   [(set (match_dup 2)
646         (sign_extend:SI (match_dup 1)))
647    (set (match_dup 0)
648         (compare:CC (match_dup 2)
649                     (const_int 0)))]
650   "")
651
652 (define_insn ""
653   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
654         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
655                     (const_int 0)))
656    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
657         (sign_extend:SI (match_dup 1)))]
658   "TARGET_POWERPC"
659   "@
660    extsb. %0,%1
661    #"
662   [(set_attr "type" "compare")
663    (set_attr "length" "4,8")])
664
665 (define_split
666   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
667         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
668                     (const_int 0)))
669    (set (match_operand:SI 0 "gpc_reg_operand" "")
670         (sign_extend:SI (match_dup 1)))]
671   "TARGET_POWERPC && reload_completed"
672   [(set (match_dup 0)
673         (sign_extend:SI (match_dup 1)))
674    (set (match_dup 2)
675         (compare:CC (match_dup 0)
676                     (const_int 0)))]
677   "")
678
679 (define_expand "extendqisi2_power"
680   [(parallel [(set (match_dup 2)
681                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
682                               (const_int 24)))
683               (clobber (scratch:SI))])
684    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
685                    (ashiftrt:SI (match_dup 2)
686                                 (const_int 24)))
687               (clobber (scratch:SI))])]
688   "TARGET_POWER"
689   "
690 { operands[1] = gen_lowpart (SImode, operands[1]);
691   operands[2] = gen_reg_rtx (SImode); }")
692
693 (define_expand "extendqisi2_no_power"
694   [(set (match_dup 2)
695         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
696                    (const_int 24)))
697    (set (match_operand:SI 0 "gpc_reg_operand" "")
698         (ashiftrt:SI (match_dup 2)
699                      (const_int 24)))]
700   "! TARGET_POWER && ! TARGET_POWERPC"
701   "
702 { operands[1] = gen_lowpart (SImode, operands[1]);
703   operands[2] = gen_reg_rtx (SImode); }")
704
705 (define_expand "zero_extendqihi2"
706   [(set (match_operand:HI 0 "gpc_reg_operand" "")
707         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
708   ""
709   "")
710
711 (define_insn ""
712   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
713         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
714   ""
715   "@
716    lbz%U1%X1 %0,%1
717    {rlinm|rlwinm} %0,%1,0,0xff"
718   [(set_attr "type" "load,*")])
719
720 (define_insn ""
721   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
722         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
723                     (const_int 0)))
724    (clobber (match_scratch:HI 2 "=r,r"))]
725   ""
726   "@
727    {andil.|andi.} %2,%1,0xff
728    #"
729   [(set_attr "type" "compare")
730    (set_attr "length" "4,8")])
731
732 (define_split
733   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
734         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
735                     (const_int 0)))
736    (clobber (match_scratch:HI 2 ""))]
737   "reload_completed"
738   [(set (match_dup 2)
739         (zero_extend:HI (match_dup 1)))
740    (set (match_dup 0)
741         (compare:CC (match_dup 2)
742                     (const_int 0)))]
743   "")
744
745 (define_insn ""
746   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
747         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
748                     (const_int 0)))
749    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
750         (zero_extend:HI (match_dup 1)))]
751   ""
752   "@
753    {andil.|andi.} %0,%1,0xff
754    #"
755   [(set_attr "type" "compare")
756    (set_attr "length" "4,8")])
757
758 (define_split
759   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
760         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
761                     (const_int 0)))
762    (set (match_operand:HI 0 "gpc_reg_operand" "")
763         (zero_extend:HI (match_dup 1)))]
764   "reload_completed"
765   [(set (match_dup 0)
766         (zero_extend:HI (match_dup 1)))
767    (set (match_dup 2)
768         (compare:CC (match_dup 0)
769                     (const_int 0)))]
770   "")
771
772 (define_expand "extendqihi2"
773   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
774    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
775   ""
776   "
777 {
778   if (TARGET_POWERPC)
779     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
780   else if (TARGET_POWER)
781     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
782   else
783     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
784   DONE;
785 }")
786
787 (define_insn "extendqihi2_ppc"
788   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
789         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
790   "TARGET_POWERPC"
791   "extsb %0,%1")
792
793 (define_insn ""
794   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
795         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
796                     (const_int 0)))
797    (clobber (match_scratch:HI 2 "=r,r"))]
798   "TARGET_POWERPC"
799   "@
800    extsb. %2,%1
801    #"
802   [(set_attr "type" "compare")
803    (set_attr "length" "4,8")])
804
805 (define_split
806   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
807         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
808                     (const_int 0)))
809    (clobber (match_scratch:HI 2 ""))]
810   "TARGET_POWERPC && reload_completed"
811   [(set (match_dup 2)
812         (sign_extend:HI (match_dup 1)))
813    (set (match_dup 0)
814         (compare:CC (match_dup 2)
815                     (const_int 0)))]
816   "")
817
818 (define_insn ""
819   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
820         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
821                     (const_int 0)))
822    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
823         (sign_extend:HI (match_dup 1)))]
824   "TARGET_POWERPC"
825   "@
826    extsb. %0,%1
827    #"
828   [(set_attr "type" "compare")
829    (set_attr "length" "4,8")])
830
831 (define_split
832   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
833         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
834                     (const_int 0)))
835    (set (match_operand:HI 0 "gpc_reg_operand" "")
836         (sign_extend:HI (match_dup 1)))]
837   "TARGET_POWERPC && reload_completed"
838   [(set (match_dup 0)
839         (sign_extend:HI (match_dup 1)))
840    (set (match_dup 2)
841         (compare:CC (match_dup 0)
842                     (const_int 0)))]
843   "")
844
845 (define_expand "extendqihi2_power"
846   [(parallel [(set (match_dup 2)
847                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
848                               (const_int 24)))
849               (clobber (scratch:SI))])
850    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
851                    (ashiftrt:SI (match_dup 2)
852                                 (const_int 24)))
853               (clobber (scratch:SI))])]
854   "TARGET_POWER"
855   "
856 { operands[0] = gen_lowpart (SImode, operands[0]);
857   operands[1] = gen_lowpart (SImode, operands[1]);
858   operands[2] = gen_reg_rtx (SImode); }")
859
860 (define_expand "extendqihi2_no_power"
861   [(set (match_dup 2)
862         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
863                    (const_int 24)))
864    (set (match_operand:HI 0 "gpc_reg_operand" "")
865         (ashiftrt:SI (match_dup 2)
866                      (const_int 24)))]
867   "! TARGET_POWER && ! TARGET_POWERPC"
868   "
869 { operands[0] = gen_lowpart (SImode, operands[0]);
870   operands[1] = gen_lowpart (SImode, operands[1]);
871   operands[2] = gen_reg_rtx (SImode); }")
872
873 (define_expand "zero_extendhisi2"
874   [(set (match_operand:SI 0 "gpc_reg_operand" "")
875         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
876   ""
877   "")
878
879 (define_insn ""
880   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
881         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
882   ""
883   "@
884    lhz%U1%X1 %0,%1
885    {rlinm|rlwinm} %0,%1,0,0xffff"
886   [(set_attr "type" "load,*")])
887
888 (define_insn ""
889   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
890         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
891                     (const_int 0)))
892    (clobber (match_scratch:SI 2 "=r,r"))]
893   ""
894   "@
895    {andil.|andi.} %2,%1,0xffff
896    #"
897   [(set_attr "type" "compare")
898    (set_attr "length" "4,8")])
899
900 (define_split
901   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
902         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
903                     (const_int 0)))
904    (clobber (match_scratch:SI 2 ""))]
905   "reload_completed"
906   [(set (match_dup 2)
907         (zero_extend:SI (match_dup 1)))
908    (set (match_dup 0)
909         (compare:CC (match_dup 2)
910                     (const_int 0)))]
911   "")
912
913 (define_insn ""
914   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
915         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
916                     (const_int 0)))
917    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
918         (zero_extend:SI (match_dup 1)))]
919   ""
920   "@
921    {andil.|andi.} %0,%1,0xffff
922    #"
923   [(set_attr "type" "compare")
924    (set_attr "length" "4,8")])
925
926 (define_split
927   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
928         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
929                     (const_int 0)))
930    (set (match_operand:SI 0 "gpc_reg_operand" "")
931         (zero_extend:SI (match_dup 1)))]
932   "reload_completed"
933   [(set (match_dup 0)
934         (zero_extend:SI (match_dup 1)))
935    (set (match_dup 2)
936         (compare:CC (match_dup 0)
937                     (const_int 0)))]
938   "")
939
940 (define_expand "extendhisi2"
941   [(set (match_operand:SI 0 "gpc_reg_operand" "")
942         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
943   ""
944   "")
945
946 (define_insn ""
947   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
948         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
949   ""
950   "@
951    lha%U1%X1 %0,%1
952    {exts|extsh} %0,%1"
953   [(set_attr "type" "load_ext,*")])
954
955 (define_insn ""
956   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
957         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
958                     (const_int 0)))
959    (clobber (match_scratch:SI 2 "=r,r"))]
960   ""
961   "@
962    {exts.|extsh.} %2,%1
963    #"
964   [(set_attr "type" "compare")
965    (set_attr "length" "4,8")])
966
967 (define_split
968   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
969         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
970                     (const_int 0)))
971    (clobber (match_scratch:SI 2 ""))]
972   "reload_completed"
973   [(set (match_dup 2)
974         (sign_extend:SI (match_dup 1)))
975    (set (match_dup 0)
976         (compare:CC (match_dup 2)
977                     (const_int 0)))]
978   "")
979
980 (define_insn ""
981   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
982         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
983                     (const_int 0)))
984    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
985         (sign_extend:SI (match_dup 1)))]
986   ""
987   "@
988    {exts.|extsh.} %0,%1
989    #"
990   [(set_attr "type" "compare")
991    (set_attr "length" "4,8")])
992 \f
993 (define_split
994   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
995         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
996                     (const_int 0)))
997    (set (match_operand:SI 0 "gpc_reg_operand" "")
998         (sign_extend:SI (match_dup 1)))]
999   "reload_completed"
1000   [(set (match_dup 0)
1001         (sign_extend:SI (match_dup 1)))
1002    (set (match_dup 2)
1003         (compare:CC (match_dup 0)
1004                     (const_int 0)))]
1005   "")
1006
1007 ;; Fixed-point arithmetic insns.
1008
1009 (define_mode_attr add_op2 [(SI "reg_or_arith_cint_operand")
1010                            (DI "reg_or_add_cint64_operand")])
1011
1012 (define_expand "add<mode>3"
1013   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1014         (plus:SDI (match_operand:SDI 1 "gpc_reg_operand" "")
1015                   (match_operand:SDI 2 "<add_op2>" "")))]
1016   ""
1017   "
1018 {
1019   if (<MODE>mode == DImode && ! TARGET_POWERPC64)
1020     {
1021       if (non_short_cint_operand (operands[2], DImode))
1022         FAIL;
1023     }
1024   else if (GET_CODE (operands[2]) == CONST_INT
1025            && ! add_operand (operands[2], <MODE>mode))
1026     {
1027       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
1028                  ? operands[0] : gen_reg_rtx (<MODE>mode));
1029
1030       HOST_WIDE_INT val = INTVAL (operands[2]);
1031       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1032       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1033
1034       if (<MODE>mode == DImode && !CONST_OK_FOR_LETTER_P (rest, 'L'))
1035         FAIL;
1036
1037       /* The ordering here is important for the prolog expander.
1038          When space is allocated from the stack, adding 'low' first may
1039          produce a temporary deallocation (which would be bad).  */
1040       emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1041       emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1042       DONE;
1043     }
1044 }")
1045
1046 ;; Discourage ai/addic because of carry but provide it in an alternative
1047 ;; allowing register zero as source.
1048 (define_insn "*add<mode>3_internal1"
1049   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,?r,r")
1050         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,r,b")
1051                   (match_operand:GPR 2 "add_operand" "r,I,I,L")))]
1052   ""
1053   "@
1054    {cax|add} %0,%1,%2
1055    {cal %0,%2(%1)|addi %0,%1,%2}
1056    {ai|addic} %0,%1,%2
1057    {cau|addis} %0,%1,%v2"
1058   [(set_attr "length" "4,4,4,4")])
1059
1060 (define_insn "addsi3_high"
1061   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1062         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1063                  (high:SI (match_operand 2 "" ""))))]
1064   "TARGET_MACHO && !TARGET_64BIT"
1065   "{cau|addis} %0,%1,ha16(%2)"
1066   [(set_attr "length" "4")])
1067
1068 (define_insn "*add<mode>3_internal2"
1069   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1070         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1071                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1072                     (const_int 0)))
1073    (clobber (match_scratch:P 3 "=r,r,r,r"))]
1074   ""
1075   "@
1076    {cax.|add.} %3,%1,%2
1077    {ai.|addic.} %3,%1,%2
1078    #
1079    #"
1080   [(set_attr "type" "fast_compare,compare,compare,compare")
1081    (set_attr "length" "4,4,8,8")])
1082
1083 (define_split
1084   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1085         (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1086                               (match_operand:GPR 2 "reg_or_short_operand" ""))
1087                     (const_int 0)))
1088    (clobber (match_scratch:GPR 3 ""))]
1089   "reload_completed"
1090   [(set (match_dup 3)
1091         (plus:GPR (match_dup 1)
1092                  (match_dup 2)))
1093    (set (match_dup 0)
1094         (compare:CC (match_dup 3)
1095                     (const_int 0)))]
1096   "")
1097
1098 (define_insn "*add<mode>3_internal3"
1099   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1100         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1101                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1102                     (const_int 0)))
1103    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
1104         (plus:P (match_dup 1)
1105                 (match_dup 2)))]
1106   ""
1107   "@
1108    {cax.|add.} %0,%1,%2
1109    {ai.|addic.} %0,%1,%2
1110    #
1111    #"
1112   [(set_attr "type" "fast_compare,compare,compare,compare")
1113    (set_attr "length" "4,4,8,8")])
1114
1115 (define_split
1116   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1117         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "")
1118                             (match_operand:P 2 "reg_or_short_operand" ""))
1119                     (const_int 0)))
1120    (set (match_operand:P 0 "gpc_reg_operand" "")
1121         (plus:P (match_dup 1) (match_dup 2)))]
1122   "reload_completed"
1123   [(set (match_dup 0)
1124         (plus:P (match_dup 1)
1125                 (match_dup 2)))
1126    (set (match_dup 3)
1127         (compare:CC (match_dup 0)
1128                     (const_int 0)))]
1129   "")
1130
1131 ;; Split an add that we can't do in one insn into two insns, each of which
1132 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1133 ;; add should be last in case the result gets used in an address.
1134
1135 (define_split
1136   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1137         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1138                   (match_operand:GPR 2 "non_add_cint_operand" "")))]
1139   ""
1140   [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1141    (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
1142 "
1143 {
1144   HOST_WIDE_INT val = INTVAL (operands[2]);
1145   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1146   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1147
1148   operands[4] = GEN_INT (low);
1149   if (<MODE>mode == SImode || CONST_OK_FOR_LETTER_P (rest, 'L'))
1150     operands[3] = GEN_INT (rest);
1151   else if (! no_new_pseudos)
1152     {
1153       operands[3] = gen_reg_rtx (DImode);
1154       emit_move_insn (operands[3], operands[2]);
1155       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
1156       DONE;
1157     }
1158   else
1159     FAIL;
1160 }")
1161
1162 (define_insn "one_cmpl<mode>2"
1163   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1164         (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1165   ""
1166   "nor %0,%1,%1")
1167
1168 (define_insn ""
1169   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1170         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1171                     (const_int 0)))
1172    (clobber (match_scratch:P 2 "=r,r"))]
1173   ""
1174   "@
1175    nor. %2,%1,%1
1176    #"
1177   [(set_attr "type" "compare")
1178    (set_attr "length" "4,8")])
1179
1180 (define_split
1181   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1182         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1183                     (const_int 0)))
1184    (clobber (match_scratch:P 2 ""))]
1185   "reload_completed"
1186   [(set (match_dup 2)
1187         (not:P (match_dup 1)))
1188    (set (match_dup 0)
1189         (compare:CC (match_dup 2)
1190                     (const_int 0)))]
1191   "")
1192
1193 (define_insn ""
1194   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1195         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1196                     (const_int 0)))
1197    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1198         (not:P (match_dup 1)))]
1199   ""
1200   "@
1201    nor. %0,%1,%1
1202    #"
1203   [(set_attr "type" "compare")
1204    (set_attr "length" "4,8")])
1205
1206 (define_split
1207   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1208         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1209                     (const_int 0)))
1210    (set (match_operand:P 0 "gpc_reg_operand" "")
1211         (not:P (match_dup 1)))]
1212   "reload_completed"
1213   [(set (match_dup 0)
1214         (not:P (match_dup 1)))
1215    (set (match_dup 2)
1216         (compare:CC (match_dup 0)
1217                     (const_int 0)))]
1218   "")
1219
1220 (define_insn ""
1221   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1222         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
1223                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
1224   "! TARGET_POWERPC"
1225   "{sf%I1|subf%I1c} %0,%2,%1")
1226
1227 (define_insn ""
1228   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
1229         (minus:GPR (match_operand:GPR 1 "reg_or_short_operand" "r,I")
1230                    (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
1231   "TARGET_POWERPC"
1232   "@
1233    subf %0,%2,%1
1234    subfic %0,%2,%1")
1235
1236 (define_insn ""
1237   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1238         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1239                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1240                     (const_int 0)))
1241    (clobber (match_scratch:SI 3 "=r,r"))]
1242   "! TARGET_POWERPC"
1243   "@
1244    {sf.|subfc.} %3,%2,%1
1245    #"
1246   [(set_attr "type" "compare")
1247    (set_attr "length" "4,8")])
1248
1249 (define_insn ""
1250   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1251         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1252                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1253                     (const_int 0)))
1254    (clobber (match_scratch:P 3 "=r,r"))]
1255   "TARGET_POWERPC"
1256   "@
1257    subf. %3,%2,%1
1258    #"
1259   [(set_attr "type" "fast_compare")
1260    (set_attr "length" "4,8")])
1261
1262 (define_split
1263   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1264         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1265                              (match_operand:P 2 "gpc_reg_operand" ""))
1266                     (const_int 0)))
1267    (clobber (match_scratch:P 3 ""))]
1268   "reload_completed"
1269   [(set (match_dup 3)
1270         (minus:P (match_dup 1)
1271                   (match_dup 2)))
1272    (set (match_dup 0)
1273         (compare:CC (match_dup 3)
1274                     (const_int 0)))]
1275   "")
1276
1277 (define_insn ""
1278   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1279         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1280                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1281                     (const_int 0)))
1282    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1283         (minus:SI (match_dup 1) (match_dup 2)))]
1284   "! TARGET_POWERPC"
1285   "@
1286    {sf.|subfc.} %0,%2,%1
1287    #"
1288   [(set_attr "type" "compare")
1289    (set_attr "length" "4,8")])
1290
1291 (define_insn ""
1292   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1293         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1294                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1295                     (const_int 0)))
1296    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1297         (minus:P (match_dup 1)
1298                   (match_dup 2)))]
1299   "TARGET_POWERPC"
1300   "@
1301    subf. %0,%2,%1
1302    #"
1303   [(set_attr "type" "fast_compare")
1304    (set_attr "length" "4,8")])
1305
1306 (define_split
1307   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1308         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1309                              (match_operand:P 2 "gpc_reg_operand" ""))
1310                     (const_int 0)))
1311    (set (match_operand:P 0 "gpc_reg_operand" "")
1312         (minus:P (match_dup 1)
1313                   (match_dup 2)))]
1314   "reload_completed"
1315   [(set (match_dup 0)
1316         (minus:P (match_dup 1)
1317                   (match_dup 2)))
1318    (set (match_dup 3)
1319         (compare:CC (match_dup 0)
1320                     (const_int 0)))]
1321   "")
1322
1323 (define_mode_attr sub_op2 [(SI "reg_or_arith_cint_operand")
1324                            (DI "reg_or_sub_cint64_operand")])
1325
1326 (define_expand "sub<mode>3"
1327   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1328         (minus:SDI (match_operand:SDI 1 "reg_or_short_operand" "")
1329                    (match_operand:SDI 2 "<sub_op2>" "")))]
1330   ""
1331   "
1332 {
1333   if (GET_CODE (operands[2]) == CONST_INT)
1334     {
1335       emit_insn (gen_add<mode>3 (operands[0], operands[1],
1336                                  negate_rtx (<MODE>mode, operands[2])));
1337       DONE;
1338     }
1339 }")
1340
1341 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1342 ;; instruction and some auxiliary computations.  Then we just have a single
1343 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1344 ;; combine.
1345
1346 (define_expand "sminsi3"
1347   [(set (match_dup 3)
1348         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1349                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1350                          (const_int 0)
1351                          (minus:SI (match_dup 2) (match_dup 1))))
1352    (set (match_operand:SI 0 "gpc_reg_operand" "")
1353         (minus:SI (match_dup 2) (match_dup 3)))]
1354   "TARGET_POWER || TARGET_ISEL"
1355   "
1356 {
1357   if (TARGET_ISEL)
1358     {
1359       operands[2] = force_reg (SImode, operands[2]);
1360       rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
1361       DONE;
1362     }
1363
1364   operands[3] = gen_reg_rtx (SImode);
1365 }")
1366
1367 (define_split
1368   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1369         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1370                  (match_operand:SI 2 "reg_or_short_operand" "")))
1371    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1372   "TARGET_POWER"
1373   [(set (match_dup 3)
1374         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1375                          (const_int 0)
1376                          (minus:SI (match_dup 2) (match_dup 1))))
1377    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1378   "")
1379
1380 (define_expand "smaxsi3"
1381   [(set (match_dup 3)
1382         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1383                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1384                          (const_int 0)
1385                          (minus:SI (match_dup 2) (match_dup 1))))
1386    (set (match_operand:SI 0 "gpc_reg_operand" "")
1387         (plus:SI (match_dup 3) (match_dup 1)))]
1388   "TARGET_POWER || TARGET_ISEL"
1389   "
1390 {
1391   if (TARGET_ISEL)
1392     {
1393       operands[2] = force_reg (SImode, operands[2]);
1394       rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
1395       DONE;
1396     }
1397   operands[3] = gen_reg_rtx (SImode);
1398 }")
1399
1400 (define_split
1401   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1402         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1403                  (match_operand:SI 2 "reg_or_short_operand" "")))
1404    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1405   "TARGET_POWER"
1406   [(set (match_dup 3)
1407         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1408                          (const_int 0)
1409                          (minus:SI (match_dup 2) (match_dup 1))))
1410    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1411   "")
1412
1413 (define_expand "uminsi3"
1414   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1415                               (match_dup 5)))
1416    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1417                               (match_dup 5)))
1418    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1419                                        (const_int 0)
1420                                        (minus:SI (match_dup 4) (match_dup 3))))
1421    (set (match_operand:SI 0 "gpc_reg_operand" "")
1422         (minus:SI (match_dup 2) (match_dup 3)))]
1423   "TARGET_POWER || TARGET_ISEL"
1424   "
1425 {
1426   if (TARGET_ISEL)
1427     {
1428       rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
1429       DONE;
1430     }
1431   operands[3] = gen_reg_rtx (SImode);
1432   operands[4] = gen_reg_rtx (SImode);
1433   operands[5] = GEN_INT (-2147483647 - 1);
1434 }")
1435
1436 (define_expand "umaxsi3"
1437   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1438                               (match_dup 5)))
1439    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1440                               (match_dup 5)))
1441    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1442                                        (const_int 0)
1443                                        (minus:SI (match_dup 4) (match_dup 3))))
1444    (set (match_operand:SI 0 "gpc_reg_operand" "")
1445         (plus:SI (match_dup 3) (match_dup 1)))]
1446   "TARGET_POWER || TARGET_ISEL"
1447   "
1448 {
1449   if (TARGET_ISEL)
1450     {
1451       rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
1452       DONE;
1453     }
1454   operands[3] = gen_reg_rtx (SImode);
1455   operands[4] = gen_reg_rtx (SImode);
1456   operands[5] = GEN_INT (-2147483647 - 1);
1457 }")
1458
1459 (define_insn ""
1460   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1461         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1462                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
1463                          (const_int 0)
1464                          (minus:SI (match_dup 2) (match_dup 1))))]
1465   "TARGET_POWER"
1466   "doz%I2 %0,%1,%2")
1467
1468 (define_insn ""
1469   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1470         (compare:CC
1471          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1472                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1473                           (const_int 0)
1474                           (minus:SI (match_dup 2) (match_dup 1)))
1475          (const_int 0)))
1476    (clobber (match_scratch:SI 3 "=r,r"))]
1477   "TARGET_POWER"
1478   "@
1479    doz%I2. %3,%1,%2
1480    #"
1481   [(set_attr "type" "delayed_compare")
1482    (set_attr "length" "4,8")])
1483
1484 (define_split
1485   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1486         (compare:CC
1487          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1488                               (match_operand:SI 2 "reg_or_short_operand" ""))
1489                           (const_int 0)
1490                           (minus:SI (match_dup 2) (match_dup 1)))
1491          (const_int 0)))
1492    (clobber (match_scratch:SI 3 ""))]
1493   "TARGET_POWER && reload_completed"
1494   [(set (match_dup 3)
1495         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1496                           (const_int 0)
1497                           (minus:SI (match_dup 2) (match_dup 1))))
1498    (set (match_dup 0)
1499         (compare:CC (match_dup 3)
1500                     (const_int 0)))]
1501   "")
1502
1503 (define_insn ""
1504   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1505         (compare:CC
1506          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1507                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1508                           (const_int 0)
1509                           (minus:SI (match_dup 2) (match_dup 1)))
1510          (const_int 0)))
1511    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1512         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1513                          (const_int 0)
1514                          (minus:SI (match_dup 2) (match_dup 1))))]
1515   "TARGET_POWER"
1516   "@
1517    doz%I2. %0,%1,%2
1518    #"
1519   [(set_attr "type" "delayed_compare")
1520    (set_attr "length" "4,8")])
1521
1522 (define_split
1523   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1524         (compare:CC
1525          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1526                               (match_operand:SI 2 "reg_or_short_operand" ""))
1527                           (const_int 0)
1528                           (minus:SI (match_dup 2) (match_dup 1)))
1529          (const_int 0)))
1530    (set (match_operand:SI 0 "gpc_reg_operand" "")
1531         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1532                          (const_int 0)
1533                          (minus:SI (match_dup 2) (match_dup 1))))]
1534   "TARGET_POWER && reload_completed"
1535   [(set (match_dup 0)
1536         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1537                          (const_int 0)
1538                          (minus:SI (match_dup 2) (match_dup 1))))
1539    (set (match_dup 3)
1540         (compare:CC (match_dup 0)
1541                     (const_int 0)))]
1542   "")
1543
1544 ;; We don't need abs with condition code because such comparisons should
1545 ;; never be done.
1546 (define_expand "abssi2"
1547   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1548         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
1549   ""
1550   "
1551 {
1552   if (TARGET_ISEL)
1553     {
1554       emit_insn (gen_abssi2_isel (operands[0], operands[1]));
1555       DONE;
1556     }
1557   else if (! TARGET_POWER)
1558     {
1559       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
1560       DONE;
1561     }
1562 }")
1563
1564 (define_insn "*abssi2_power"
1565   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1566         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1567   "TARGET_POWER"
1568   "abs %0,%1")
1569
1570 (define_insn_and_split "abssi2_isel"
1571   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1572         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
1573    (clobber (match_scratch:SI 2 "=&b"))
1574    (clobber (match_scratch:CC 3 "=y"))]
1575   "TARGET_ISEL"
1576   "#"
1577   "&& reload_completed"
1578   [(set (match_dup 2) (neg:SI (match_dup 1)))
1579    (set (match_dup 3)
1580         (compare:CC (match_dup 1)
1581                     (const_int 0)))
1582    (set (match_dup 0)
1583         (if_then_else:SI (ge (match_dup 3)
1584                              (const_int 0))
1585                          (match_dup 1)
1586                          (match_dup 2)))]
1587   "")
1588
1589 (define_insn_and_split "abssi2_nopower"
1590   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1591         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
1592    (clobber (match_scratch:SI 2 "=&r,&r"))]
1593   "! TARGET_POWER && ! TARGET_ISEL"
1594   "#"
1595   "&& reload_completed"
1596   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1597    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1598    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
1599   "")
1600
1601 (define_insn "*nabs_power"
1602   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1603         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
1604   "TARGET_POWER"
1605   "nabs %0,%1")
1606
1607 (define_insn_and_split "*nabs_nopower"
1608   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1609         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
1610    (clobber (match_scratch:SI 2 "=&r,&r"))]
1611   "! TARGET_POWER"
1612   "#"
1613   "&& reload_completed"
1614   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1615    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1616    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
1617   "")
1618
1619 (define_expand "neg<mode>2"
1620   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1621         (neg:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
1622   ""
1623   "")
1624
1625 (define_insn "*neg<mode>2_internal"
1626   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1627         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1628   ""
1629   "neg %0,%1")
1630
1631 (define_insn ""
1632   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1633         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1634                     (const_int 0)))
1635    (clobber (match_scratch:P 2 "=r,r"))]
1636   ""
1637   "@
1638    neg. %2,%1
1639    #"
1640   [(set_attr "type" "fast_compare")
1641    (set_attr "length" "4,8")])
1642
1643 (define_split
1644   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1645         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
1646                     (const_int 0)))
1647    (clobber (match_scratch:P 2 ""))]
1648   "reload_completed"
1649   [(set (match_dup 2)
1650         (neg:P (match_dup 1)))
1651    (set (match_dup 0)
1652         (compare:CC (match_dup 2)
1653                     (const_int 0)))]
1654   "")
1655
1656 (define_insn ""
1657   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1658         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1659                     (const_int 0)))
1660    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1661         (neg:P (match_dup 1)))]
1662   ""
1663   "@
1664    neg. %0,%1
1665    #"
1666   [(set_attr "type" "fast_compare")
1667    (set_attr "length" "4,8")])
1668
1669 (define_split
1670   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1671         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
1672                     (const_int 0)))
1673    (set (match_operand:P 0 "gpc_reg_operand" "")
1674         (neg:P (match_dup 1)))]
1675   "reload_completed"
1676   [(set (match_dup 0)
1677         (neg:P (match_dup 1)))
1678    (set (match_dup 2)
1679         (compare:CC (match_dup 0)
1680                     (const_int 0)))]
1681   "")
1682
1683 (define_insn "clz<mode>2"
1684   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1685         (clz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1686   ""
1687   "{cntlz|cntlz<wd>} %0,%1")
1688
1689 (define_expand "ctz<mode>2"
1690   [(set (match_dup 2)
1691         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))
1692    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
1693                                           (match_dup 2)))
1694               (clobber (scratch:CC))])
1695    (set (match_dup 4) (clz:GPR (match_dup 3)))
1696    (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1697         (minus:GPR (match_dup 5) (match_dup 4)))]
1698   ""
1699   {
1700      operands[2] = gen_reg_rtx (<MODE>mode);
1701      operands[3] = gen_reg_rtx (<MODE>mode);
1702      operands[4] = gen_reg_rtx (<MODE>mode);
1703      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 1);
1704   })
1705
1706 (define_expand "ffs<mode>2"
1707   [(set (match_dup 2)
1708         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))
1709    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
1710                                           (match_dup 2)))
1711               (clobber (scratch:CC))])
1712    (set (match_dup 4) (clz:GPR (match_dup 3)))
1713    (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1714         (minus:GPR (match_dup 5) (match_dup 4)))]
1715   ""
1716   {
1717      operands[2] = gen_reg_rtx (<MODE>mode);
1718      operands[3] = gen_reg_rtx (<MODE>mode);
1719      operands[4] = gen_reg_rtx (<MODE>mode);
1720      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
1721   })
1722
1723 (define_expand "popcount<mode>2"
1724   [(set (match_dup 2)
1725         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
1726                      UNSPEC_POPCNTB))
1727    (set (match_dup 3)
1728         (mult:GPR (match_dup 2) (match_dup 4)))
1729    (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1730         (lshiftrt:GPR (match_dup 3) (match_dup 5)))]
1731   "TARGET_POPCNTB"
1732   {
1733     operands[2] = gen_reg_rtx (<MODE>mode);
1734     operands[3] = gen_reg_rtx (<MODE>mode);
1735     operands[4] = force_reg (<MODE>mode,
1736                              <MODE>mode == SImode
1737                              ? GEN_INT (0x01010101)
1738                              : GEN_INT ((HOST_WIDE_INT)
1739                                         0x01010101 << 32 | 0x01010101));
1740     operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 8);
1741   })
1742
1743 (define_insn "popcntb<mode>2"
1744   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1745         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
1746                      UNSPEC_POPCNTB))]
1747   "TARGET_POPCNTB"
1748   "popcntb %0,%1")
1749
1750 (define_expand "mulsi3"
1751   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1752    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1753    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
1754   ""
1755   "
1756 {
1757   if (TARGET_POWER)
1758     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
1759   else
1760     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
1761   DONE;
1762 }")
1763
1764 (define_insn "mulsi3_mq"
1765   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1766         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1767                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
1768    (clobber (match_scratch:SI 3 "=q,q"))]
1769   "TARGET_POWER"
1770   "@
1771    {muls|mullw} %0,%1,%2
1772    {muli|mulli} %0,%1,%2"
1773    [(set (attr "type")
1774       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
1775                 (const_string "imul3")
1776              (match_operand:SI 2 "short_cint_operand" "")
1777                 (const_string "imul2")]
1778         (const_string "imul")))])
1779
1780 (define_insn "mulsi3_no_mq"
1781   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1782         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1783                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
1784   "! TARGET_POWER"
1785   "@
1786    {muls|mullw} %0,%1,%2
1787    {muli|mulli} %0,%1,%2"
1788    [(set (attr "type")
1789       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
1790                 (const_string "imul3")
1791              (match_operand:SI 2 "short_cint_operand" "")
1792                 (const_string "imul2")]
1793         (const_string "imul")))])
1794
1795 (define_insn "*mulsi3_mq_internal1"
1796   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1797         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1798                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1799                     (const_int 0)))
1800    (clobber (match_scratch:SI 3 "=r,r"))
1801    (clobber (match_scratch:SI 4 "=q,q"))]
1802   "TARGET_POWER"
1803   "@
1804    {muls.|mullw.} %3,%1,%2
1805    #"
1806   [(set_attr "type" "imul_compare")
1807    (set_attr "length" "4,8")])
1808
1809 (define_split
1810   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1811         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1812                              (match_operand:SI 2 "gpc_reg_operand" ""))
1813                     (const_int 0)))
1814    (clobber (match_scratch:SI 3 ""))
1815    (clobber (match_scratch:SI 4 ""))]
1816   "TARGET_POWER && reload_completed"
1817   [(parallel [(set (match_dup 3)
1818         (mult:SI (match_dup 1) (match_dup 2)))
1819    (clobber (match_dup 4))])
1820    (set (match_dup 0)
1821         (compare:CC (match_dup 3)
1822                     (const_int 0)))]
1823   "")
1824
1825 (define_insn "*mulsi3_no_mq_internal1"
1826   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1827         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1828                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1829                     (const_int 0)))
1830    (clobber (match_scratch:SI 3 "=r,r"))]
1831   "! TARGET_POWER"
1832   "@
1833    {muls.|mullw.} %3,%1,%2
1834    #"
1835   [(set_attr "type" "imul_compare")
1836    (set_attr "length" "4,8")])
1837
1838 (define_split
1839   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1840         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1841                              (match_operand:SI 2 "gpc_reg_operand" ""))
1842                     (const_int 0)))
1843    (clobber (match_scratch:SI 3 ""))]
1844   "! TARGET_POWER && reload_completed"
1845   [(set (match_dup 3)
1846         (mult:SI (match_dup 1) (match_dup 2)))
1847    (set (match_dup 0)
1848         (compare:CC (match_dup 3)
1849                     (const_int 0)))]
1850   "")
1851
1852 (define_insn "*mulsi3_mq_internal2"
1853   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1854         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1855                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1856                     (const_int 0)))
1857    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1858         (mult:SI (match_dup 1) (match_dup 2)))
1859    (clobber (match_scratch:SI 4 "=q,q"))]
1860   "TARGET_POWER"
1861   "@
1862    {muls.|mullw.} %0,%1,%2
1863    #"
1864   [(set_attr "type" "imul_compare")
1865    (set_attr "length" "4,8")])
1866
1867 (define_split
1868   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1869         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1870                              (match_operand:SI 2 "gpc_reg_operand" ""))
1871                     (const_int 0)))
1872    (set (match_operand:SI 0 "gpc_reg_operand" "")
1873         (mult:SI (match_dup 1) (match_dup 2)))
1874    (clobber (match_scratch:SI 4 ""))]
1875   "TARGET_POWER && reload_completed"
1876   [(parallel [(set (match_dup 0)
1877         (mult:SI (match_dup 1) (match_dup 2)))
1878    (clobber (match_dup 4))])
1879    (set (match_dup 3)
1880         (compare:CC (match_dup 0)
1881                     (const_int 0)))]
1882   "")
1883
1884 (define_insn "*mulsi3_no_mq_internal2"
1885   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1886         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1887                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1888                     (const_int 0)))
1889    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1890         (mult:SI (match_dup 1) (match_dup 2)))]
1891   "! TARGET_POWER"
1892   "@
1893    {muls.|mullw.} %0,%1,%2
1894    #"
1895   [(set_attr "type" "imul_compare")
1896    (set_attr "length" "4,8")])
1897
1898 (define_split
1899   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1900         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1901                              (match_operand:SI 2 "gpc_reg_operand" ""))
1902                     (const_int 0)))
1903    (set (match_operand:SI 0 "gpc_reg_operand" "")
1904         (mult:SI (match_dup 1) (match_dup 2)))]
1905   "! TARGET_POWER && reload_completed"
1906   [(set (match_dup 0)
1907         (mult:SI (match_dup 1) (match_dup 2)))
1908    (set (match_dup 3)
1909         (compare:CC (match_dup 0)
1910                     (const_int 0)))]
1911   "")
1912
1913 ;; Operand 1 is divided by operand 2; quotient goes to operand
1914 ;; 0 and remainder to operand 3.
1915 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
1916
1917 (define_expand "divmodsi4"
1918   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
1919                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1920                            (match_operand:SI 2 "gpc_reg_operand" "")))
1921               (set (match_operand:SI 3 "register_operand" "")
1922                    (mod:SI (match_dup 1) (match_dup 2)))])]
1923   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
1924   "
1925 {
1926   if (! TARGET_POWER && ! TARGET_POWERPC)
1927     {
1928       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
1929       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
1930       emit_insn (gen_divss_call ());
1931       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
1932       emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
1933       DONE;
1934     }
1935 }")
1936
1937 (define_insn "*divmodsi4_internal"
1938   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1939         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1940                 (match_operand:SI 2 "gpc_reg_operand" "r")))
1941    (set (match_operand:SI 3 "register_operand" "=q")
1942         (mod:SI (match_dup 1) (match_dup 2)))]
1943   "TARGET_POWER"
1944   "divs %0,%1,%2"
1945   [(set_attr "type" "idiv")])
1946
1947 (define_expand "udivsi3"
1948   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1949         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
1950                  (match_operand:SI 2 "gpc_reg_operand" "")))]
1951   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
1952   "
1953 {
1954   if (! TARGET_POWER && ! TARGET_POWERPC)
1955     {
1956       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
1957       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
1958       emit_insn (gen_quous_call ());
1959       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
1960       DONE;
1961     }
1962   else if (TARGET_POWER)
1963     {
1964       emit_insn (gen_udivsi3_mq (operands[0], operands[1], operands[2]));
1965       DONE;
1966     }
1967 }")
1968
1969 (define_insn "udivsi3_mq"
1970   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1971         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1972                  (match_operand:SI 2 "gpc_reg_operand" "r")))
1973    (clobber (match_scratch:SI 3 "=q"))]
1974   "TARGET_POWERPC && TARGET_POWER"
1975   "divwu %0,%1,%2"
1976   [(set_attr "type" "idiv")])
1977
1978 (define_insn "*udivsi3_no_mq"
1979   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1980         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1981                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
1982   "TARGET_POWERPC && ! TARGET_POWER"
1983   "divwu %0,%1,%2"
1984   [(set_attr "type" "idiv")])
1985
1986 ;; For powers of two we can do srai/aze for divide and then adjust for
1987 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
1988 ;; used; for PowerPC, force operands into register and do a normal divide;
1989 ;; for AIX common-mode, use quoss call on register operands.
1990 (define_expand "divsi3"
1991   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1992         (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1993                 (match_operand:SI 2 "reg_or_cint_operand" "")))]
1994   ""
1995   "
1996 {
1997   if (GET_CODE (operands[2]) == CONST_INT
1998       && INTVAL (operands[2]) > 0
1999       && exact_log2 (INTVAL (operands[2])) >= 0)
2000     ;
2001   else if (TARGET_POWERPC)
2002     {
2003       operands[2] = force_reg (SImode, operands[2]);
2004       if (TARGET_POWER)
2005         {
2006           emit_insn (gen_divsi3_mq (operands[0], operands[1], operands[2]));
2007           DONE;
2008         }
2009     }
2010   else if (TARGET_POWER)
2011     FAIL;
2012   else
2013     {
2014       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2015       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2016       emit_insn (gen_quoss_call ());
2017       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2018       DONE;
2019     }
2020 }")
2021
2022 (define_insn "divsi3_mq"
2023   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2024         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2025                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2026    (clobber (match_scratch:SI 3 "=q"))]
2027   "TARGET_POWERPC && TARGET_POWER"
2028   "divw %0,%1,%2"
2029   [(set_attr "type" "idiv")])
2030
2031 (define_insn "*divsi3_no_mq"
2032   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2033         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2034                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
2035   "TARGET_POWERPC && ! TARGET_POWER"
2036   "divw %0,%1,%2"
2037   [(set_attr "type" "idiv")])
2038
2039 (define_expand "modsi3"
2040   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2041    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2042    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
2043   ""
2044   "
2045 {
2046   int i;
2047   rtx temp1;
2048   rtx temp2;
2049
2050   if (GET_CODE (operands[2]) != CONST_INT
2051       || INTVAL (operands[2]) <= 0
2052       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
2053     FAIL;
2054
2055   temp1 = gen_reg_rtx (SImode);
2056   temp2 = gen_reg_rtx (SImode);
2057
2058   emit_insn (gen_divsi3 (temp1, operands[1], operands[2]));
2059   emit_insn (gen_ashlsi3 (temp2, temp1, GEN_INT (i)));
2060   emit_insn (gen_subsi3 (operands[0], operands[1], temp2));
2061   DONE;
2062 }")
2063
2064 (define_insn ""
2065   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2066         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2067                 (match_operand:SI 2 "exact_log2_cint_operand" "N")))]
2068   ""
2069   "{srai|srawi} %0,%1,%p2\;{aze|addze} %0,%0"
2070   [(set_attr "type" "two")
2071    (set_attr "length" "8")])
2072
2073 (define_insn ""
2074   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2075         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2076                             (match_operand:SI 2 "exact_log2_cint_operand" "N,N"))
2077                     (const_int 0)))
2078    (clobber (match_scratch:SI 3 "=r,r"))]
2079   ""
2080   "@
2081    {srai|srawi} %3,%1,%p2\;{aze.|addze.} %3,%3
2082    #"
2083   [(set_attr "type" "compare")
2084    (set_attr "length" "8,12")])
2085
2086 (define_split
2087   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2088         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2089                             (match_operand:SI 2 "exact_log2_cint_operand" ""))
2090                     (const_int 0)))
2091    (clobber (match_scratch:SI 3 ""))]
2092   "reload_completed"
2093   [(set (match_dup 3)
2094         (div:SI (match_dup 1) (match_dup 2)))
2095    (set (match_dup 0)
2096         (compare:CC (match_dup 3)
2097                     (const_int 0)))]
2098   "")
2099
2100 (define_insn ""
2101   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2102         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2103                             (match_operand:SI 2 "exact_log2_cint_operand" "N,N"))
2104                     (const_int 0)))
2105    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2106         (div:SI (match_dup 1) (match_dup 2)))]
2107   ""
2108   "@
2109    {srai|srawi} %0,%1,%p2\;{aze.|addze.} %0,%0
2110    #"
2111   [(set_attr "type" "compare")
2112    (set_attr "length" "8,12")])
2113
2114 (define_split
2115   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2116         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2117                             (match_operand:SI 2 "exact_log2_cint_operand" ""))
2118                     (const_int 0)))
2119    (set (match_operand:SI 0 "gpc_reg_operand" "")
2120         (div:SI (match_dup 1) (match_dup 2)))]
2121   "reload_completed"
2122   [(set (match_dup 0)
2123         (div:SI (match_dup 1) (match_dup 2)))
2124    (set (match_dup 3)
2125         (compare:CC (match_dup 0)
2126                     (const_int 0)))]
2127   "")
2128
2129 (define_insn ""
2130   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2131         (udiv:SI
2132          (plus:DI (ashift:DI
2133                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
2134                    (const_int 32))
2135                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
2136          (match_operand:SI 3 "gpc_reg_operand" "r")))
2137    (set (match_operand:SI 2 "register_operand" "=*q")
2138         (umod:SI
2139          (plus:DI (ashift:DI
2140                    (zero_extend:DI (match_dup 1)) (const_int 32))
2141                   (zero_extend:DI (match_dup 4)))
2142          (match_dup 3)))]
2143   "TARGET_POWER"
2144   "div %0,%1,%3"
2145   [(set_attr "type" "idiv")])
2146
2147 ;; To do unsigned divide we handle the cases of the divisor looking like a
2148 ;; negative number.  If it is a constant that is less than 2**31, we don't
2149 ;; have to worry about the branches.  So make a few subroutines here.
2150 ;;
2151 ;; First comes the normal case.
2152 (define_expand "udivmodsi4_normal"
2153   [(set (match_dup 4) (const_int 0))
2154    (parallel [(set (match_operand:SI 0 "" "")
2155                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2156                                                 (const_int 32))
2157                                      (zero_extend:DI (match_operand:SI 1 "" "")))
2158                             (match_operand:SI 2 "" "")))
2159               (set (match_operand:SI 3 "" "")
2160                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2161                                                 (const_int 32))
2162                                      (zero_extend:DI (match_dup 1)))
2163                             (match_dup 2)))])]
2164   "TARGET_POWER"
2165   "
2166 { operands[4] = gen_reg_rtx (SImode); }")
2167
2168 ;; This handles the branches.
2169 (define_expand "udivmodsi4_tests"
2170   [(set (match_operand:SI 0 "" "") (const_int 0))
2171    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
2172    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
2173    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
2174                            (label_ref (match_operand:SI 4 "" "")) (pc)))
2175    (set (match_dup 0) (const_int 1))
2176    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
2177    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
2178    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
2179                            (label_ref (match_dup 4)) (pc)))]
2180   "TARGET_POWER"
2181   "
2182 { operands[5] = gen_reg_rtx (CCUNSmode);
2183   operands[6] = gen_reg_rtx (CCmode);
2184 }")
2185
2186 (define_expand "udivmodsi4"
2187   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2188                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
2189                             (match_operand:SI 2 "reg_or_cint_operand" "")))
2190               (set (match_operand:SI 3 "gpc_reg_operand" "")
2191                    (umod:SI (match_dup 1) (match_dup 2)))])]
2192   ""
2193   "
2194 {
2195   rtx label = 0;
2196
2197   if (! TARGET_POWER)
2198     {
2199       if (! TARGET_POWERPC)
2200         {
2201           emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2202           emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2203           emit_insn (gen_divus_call ());
2204           emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2205           emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2206           DONE;
2207         }
2208       else
2209         FAIL;
2210     }
2211
2212   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
2213     {
2214       operands[2] = force_reg (SImode, operands[2]);
2215       label = gen_label_rtx ();
2216       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
2217                                   operands[3], label));
2218     }
2219   else
2220     operands[2] = force_reg (SImode, operands[2]);
2221
2222   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
2223                                operands[3]));
2224   if (label)
2225     emit_label (label);
2226
2227   DONE;
2228 }")
2229
2230 ;; AIX architecture-independent common-mode multiply (DImode),
2231 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
2232 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
2233 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
2234 ;; assumed unused if generating common-mode, so ignore.
2235 (define_insn "mulh_call"
2236   [(set (reg:SI 3)
2237         (truncate:SI
2238          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
2239                                (sign_extend:DI (reg:SI 4)))
2240                       (const_int 32))))
2241    (clobber (match_scratch:SI 0 "=l"))]
2242   "! TARGET_POWER && ! TARGET_POWERPC"
2243   "bla __mulh"
2244   [(set_attr "type" "imul")])
2245
2246 (define_insn "mull_call"
2247   [(set (reg:DI 3)
2248         (mult:DI (sign_extend:DI (reg:SI 3))
2249                  (sign_extend:DI (reg:SI 4))))
2250    (clobber (match_scratch:SI 0 "=l"))
2251    (clobber (reg:SI 0))]
2252   "! TARGET_POWER && ! TARGET_POWERPC"
2253   "bla __mull"
2254   [(set_attr "type" "imul")])
2255
2256 (define_insn "divss_call"
2257   [(set (reg:SI 3)
2258         (div:SI (reg:SI 3) (reg:SI 4)))
2259    (set (reg:SI 4)
2260         (mod:SI (reg:SI 3) (reg:SI 4)))
2261    (clobber (match_scratch:SI 0 "=l"))
2262    (clobber (reg:SI 0))]
2263   "! TARGET_POWER && ! TARGET_POWERPC"
2264   "bla __divss"
2265   [(set_attr "type" "idiv")])
2266
2267 (define_insn "divus_call"
2268   [(set (reg:SI 3)
2269         (udiv:SI (reg:SI 3) (reg:SI 4)))
2270    (set (reg:SI 4)
2271         (umod:SI (reg:SI 3) (reg:SI 4)))
2272    (clobber (match_scratch:SI 0 "=l"))
2273    (clobber (reg:SI 0))
2274    (clobber (match_scratch:CC 1 "=x"))
2275    (clobber (reg:CC 69))]
2276   "! TARGET_POWER && ! TARGET_POWERPC"
2277   "bla __divus"
2278   [(set_attr "type" "idiv")])
2279
2280 (define_insn "quoss_call"
2281   [(set (reg:SI 3)
2282         (div:SI (reg:SI 3) (reg:SI 4)))
2283    (clobber (match_scratch:SI 0 "=l"))]
2284   "! TARGET_POWER && ! TARGET_POWERPC"
2285   "bla __quoss"
2286   [(set_attr "type" "idiv")])
2287
2288 (define_insn "quous_call"
2289   [(set (reg:SI 3)
2290         (udiv:SI (reg:SI 3) (reg:SI 4)))
2291    (clobber (match_scratch:SI 0 "=l"))
2292    (clobber (reg:SI 0))
2293    (clobber (match_scratch:CC 1 "=x"))
2294    (clobber (reg:CC 69))]
2295   "! TARGET_POWER && ! TARGET_POWERPC"
2296   "bla __quous"
2297   [(set_attr "type" "idiv")])
2298 \f
2299 ;; Logical instructions
2300 ;; The logical instructions are mostly combined by using match_operator,
2301 ;; but the plain AND insns are somewhat different because there is no
2302 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2303 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2304
2305 (define_insn "andsi3"
2306   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2307         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2308                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2309    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2310   ""
2311   "@
2312    and %0,%1,%2
2313    {rlinm|rlwinm} %0,%1,0,%m2,%M2
2314    {andil.|andi.} %0,%1,%b2
2315    {andiu.|andis.} %0,%1,%u2"
2316   [(set_attr "type" "*,*,compare,compare")])
2317
2318 ;; Note to set cr's other than cr0 we do the and immediate and then
2319 ;; the test again -- this avoids a mfcr which on the higher end
2320 ;; machines causes an execution serialization
2321
2322 (define_insn "*andsi3_internal2"
2323   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2324         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2325                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2326                     (const_int 0)))
2327    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2328    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2329   "TARGET_32BIT"
2330   "@
2331    and. %3,%1,%2
2332    {andil.|andi.} %3,%1,%b2
2333    {andiu.|andis.} %3,%1,%u2
2334    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2335    #
2336    #
2337    #
2338    #"
2339   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2340    (set_attr "length" "4,4,4,4,8,8,8,8")])
2341
2342 (define_insn "*andsi3_internal3"
2343   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2344         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2345                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2346                     (const_int 0)))
2347    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2348    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2349   "TARGET_64BIT"
2350   "@
2351    #
2352    {andil.|andi.} %3,%1,%b2
2353    {andiu.|andis.} %3,%1,%u2
2354    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2355    #
2356    #
2357    #
2358    #"
2359   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2360    (set_attr "length" "8,4,4,4,8,8,8,8")])
2361
2362 (define_split
2363   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2364         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2365                             (match_operand:SI 2 "and_operand" ""))
2366                     (const_int 0)))
2367    (clobber (match_scratch:SI 3 ""))
2368    (clobber (match_scratch:CC 4 ""))]
2369   "reload_completed"
2370   [(parallel [(set (match_dup 3)
2371                    (and:SI (match_dup 1)
2372                            (match_dup 2)))
2373               (clobber (match_dup 4))])
2374    (set (match_dup 0)
2375         (compare:CC (match_dup 3)
2376                     (const_int 0)))]
2377   "")
2378
2379 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
2380 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
2381
2382 (define_split
2383   [(set (match_operand:CC 0 "cc_reg_operand" "")
2384         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2385                             (match_operand:SI 2 "gpc_reg_operand" ""))
2386                     (const_int 0)))
2387    (clobber (match_scratch:SI 3 ""))
2388    (clobber (match_scratch:CC 4 ""))]
2389   "TARGET_POWERPC64 && reload_completed"
2390   [(parallel [(set (match_dup 3)
2391                    (and:SI (match_dup 1)
2392                            (match_dup 2)))
2393               (clobber (match_dup 4))])
2394    (set (match_dup 0)
2395         (compare:CC (match_dup 3)
2396                     (const_int 0)))]
2397   "")
2398
2399 (define_insn "*andsi3_internal4"
2400   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2401         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2402                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2403                     (const_int 0)))
2404    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2405         (and:SI (match_dup 1)
2406                 (match_dup 2)))
2407    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2408   "TARGET_32BIT"
2409   "@
2410    and. %0,%1,%2
2411    {andil.|andi.} %0,%1,%b2
2412    {andiu.|andis.} %0,%1,%u2
2413    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2414    #
2415    #
2416    #
2417    #"
2418   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2419    (set_attr "length" "4,4,4,4,8,8,8,8")])
2420
2421 (define_insn "*andsi3_internal5"
2422   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2423         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2424                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2425                     (const_int 0)))
2426    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2427         (and:SI (match_dup 1)
2428                 (match_dup 2)))
2429    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2430   "TARGET_64BIT"
2431   "@
2432    #
2433    {andil.|andi.} %0,%1,%b2
2434    {andiu.|andis.} %0,%1,%u2
2435    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2436    #
2437    #
2438    #
2439    #"
2440   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2441    (set_attr "length" "8,4,4,4,8,8,8,8")])
2442
2443 (define_split
2444   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2445         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2446                             (match_operand:SI 2 "and_operand" ""))
2447                     (const_int 0)))
2448    (set (match_operand:SI 0 "gpc_reg_operand" "")
2449         (and:SI (match_dup 1)
2450                 (match_dup 2)))
2451    (clobber (match_scratch:CC 4 ""))]
2452   "reload_completed"
2453   [(parallel [(set (match_dup 0)
2454                    (and:SI (match_dup 1)
2455                            (match_dup 2)))
2456               (clobber (match_dup 4))])
2457    (set (match_dup 3)
2458         (compare:CC (match_dup 0)
2459                     (const_int 0)))]
2460   "")
2461
2462 (define_split
2463   [(set (match_operand:CC 3 "cc_reg_operand" "")
2464         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2465                             (match_operand:SI 2 "gpc_reg_operand" ""))
2466                     (const_int 0)))
2467    (set (match_operand:SI 0 "gpc_reg_operand" "")
2468         (and:SI (match_dup 1)
2469                 (match_dup 2)))
2470    (clobber (match_scratch:CC 4 ""))]
2471   "TARGET_POWERPC64 && reload_completed"
2472   [(parallel [(set (match_dup 0)
2473                    (and:SI (match_dup 1)
2474                            (match_dup 2)))
2475               (clobber (match_dup 4))])
2476    (set (match_dup 3)
2477         (compare:CC (match_dup 0)
2478                     (const_int 0)))]
2479   "")
2480
2481 ;; Handle the PowerPC64 rlwinm corner case
2482
2483 (define_insn_and_split "*andsi3_internal6"
2484   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2485         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2486                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
2487   "TARGET_POWERPC64"
2488   "#"
2489   "TARGET_POWERPC64"
2490   [(set (match_dup 0)
2491         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
2492                 (match_dup 4)))
2493    (set (match_dup 0)
2494         (rotate:SI (match_dup 0) (match_dup 5)))]
2495   "
2496 {
2497   int mb = extract_MB (operands[2]);
2498   int me = extract_ME (operands[2]);
2499   operands[3] = GEN_INT (me + 1);
2500   operands[5] = GEN_INT (32 - (me + 1));
2501   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2502 }"
2503   [(set_attr "length" "8")])
2504
2505 (define_expand "iorsi3"
2506   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2507         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
2508                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2509   ""
2510   "
2511 {
2512   if (GET_CODE (operands[2]) == CONST_INT
2513       && ! logical_operand (operands[2], SImode))
2514     {
2515       HOST_WIDE_INT value = INTVAL (operands[2]);
2516       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2517                  ? operands[0] : gen_reg_rtx (SImode));
2518
2519       emit_insn (gen_iorsi3 (tmp, operands[1],
2520                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2521       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2522       DONE;
2523     }
2524 }")
2525
2526 (define_expand "xorsi3"
2527   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2528         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
2529                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2530   ""
2531   "
2532 {
2533   if (GET_CODE (operands[2]) == CONST_INT
2534       && ! logical_operand (operands[2], SImode))
2535     {
2536       HOST_WIDE_INT value = INTVAL (operands[2]);
2537       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2538                  ? operands[0] : gen_reg_rtx (SImode));
2539
2540       emit_insn (gen_xorsi3 (tmp, operands[1],
2541                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2542       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2543       DONE;
2544     }
2545 }")
2546
2547 (define_insn "*boolsi3_internal1"
2548   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
2549         (match_operator:SI 3 "boolean_or_operator"
2550          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
2551           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
2552   ""
2553   "@
2554    %q3 %0,%1,%2
2555    {%q3il|%q3i} %0,%1,%b2
2556    {%q3iu|%q3is} %0,%1,%u2")
2557
2558 (define_insn "*boolsi3_internal2"
2559   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2560         (compare:CC (match_operator:SI 4 "boolean_or_operator"
2561          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2562           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2563          (const_int 0)))
2564    (clobber (match_scratch:SI 3 "=r,r"))]
2565   "TARGET_32BIT"
2566   "@
2567    %q4. %3,%1,%2
2568    #"
2569   [(set_attr "type" "compare")
2570    (set_attr "length" "4,8")])
2571
2572 (define_split
2573   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2574         (compare:CC (match_operator:SI 4 "boolean_operator"
2575          [(match_operand:SI 1 "gpc_reg_operand" "")
2576           (match_operand:SI 2 "gpc_reg_operand" "")])
2577          (const_int 0)))
2578    (clobber (match_scratch:SI 3 ""))]
2579   "TARGET_32BIT && reload_completed"
2580   [(set (match_dup 3) (match_dup 4))
2581    (set (match_dup 0)
2582         (compare:CC (match_dup 3)
2583                     (const_int 0)))]
2584   "")
2585
2586 (define_insn "*boolsi3_internal3"
2587   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2588         (compare:CC (match_operator:SI 4 "boolean_operator"
2589          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2590           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2591          (const_int 0)))
2592    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2593         (match_dup 4))]
2594   "TARGET_32BIT"
2595   "@
2596    %q4. %0,%1,%2
2597    #"
2598   [(set_attr "type" "compare")
2599    (set_attr "length" "4,8")])
2600
2601 (define_split
2602   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2603         (compare:CC (match_operator:SI 4 "boolean_operator"
2604          [(match_operand:SI 1 "gpc_reg_operand" "")
2605           (match_operand:SI 2 "gpc_reg_operand" "")])
2606          (const_int 0)))
2607    (set (match_operand:SI 0 "gpc_reg_operand" "")
2608         (match_dup 4))]
2609   "TARGET_32BIT && reload_completed"
2610   [(set (match_dup 0) (match_dup 4))
2611    (set (match_dup 3)
2612         (compare:CC (match_dup 0)
2613                     (const_int 0)))]
2614   "")
2615
2616 ;; Split a logical operation that we can't do in one insn into two insns,
2617 ;; each of which does one 16-bit part.  This is used by combine.
2618
2619 (define_split
2620   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2621         (match_operator:SI 3 "boolean_or_operator"
2622          [(match_operand:SI 1 "gpc_reg_operand" "")
2623           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
2624   ""
2625   [(set (match_dup 0) (match_dup 4))
2626    (set (match_dup 0) (match_dup 5))]
2627 "
2628 {
2629   rtx i;
2630   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
2631   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2632                                 operands[1], i);
2633   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
2634   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2635                                 operands[0], i);
2636 }")
2637
2638 (define_insn "*boolcsi3_internal1"
2639   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2640         (match_operator:SI 3 "boolean_operator"
2641          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
2642           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
2643   ""
2644   "%q3 %0,%2,%1")
2645
2646 (define_insn "*boolcsi3_internal2"
2647   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2648         (compare:CC (match_operator:SI 4 "boolean_operator"
2649          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2650           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2651          (const_int 0)))
2652    (clobber (match_scratch:SI 3 "=r,r"))]
2653   "TARGET_32BIT"
2654   "@
2655    %q4. %3,%2,%1
2656    #"
2657   [(set_attr "type" "compare")
2658    (set_attr "length" "4,8")])
2659
2660 (define_split
2661   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2662         (compare:CC (match_operator:SI 4 "boolean_operator"
2663          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2664           (match_operand:SI 2 "gpc_reg_operand" "")])
2665          (const_int 0)))
2666    (clobber (match_scratch:SI 3 ""))]
2667   "TARGET_32BIT && reload_completed"
2668   [(set (match_dup 3) (match_dup 4))
2669    (set (match_dup 0)
2670         (compare:CC (match_dup 3)
2671                     (const_int 0)))]
2672   "")
2673
2674 (define_insn "*boolcsi3_internal3"
2675   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2676         (compare:CC (match_operator:SI 4 "boolean_operator"
2677          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
2678           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2679          (const_int 0)))
2680    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2681         (match_dup 4))]
2682   "TARGET_32BIT"
2683   "@
2684    %q4. %0,%2,%1
2685    #"
2686   [(set_attr "type" "compare")
2687    (set_attr "length" "4,8")])
2688
2689 (define_split
2690   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2691         (compare:CC (match_operator:SI 4 "boolean_operator"
2692          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2693           (match_operand:SI 2 "gpc_reg_operand" "")])
2694          (const_int 0)))
2695    (set (match_operand:SI 0 "gpc_reg_operand" "")
2696         (match_dup 4))]
2697   "TARGET_32BIT && reload_completed"
2698   [(set (match_dup 0) (match_dup 4))
2699    (set (match_dup 3)
2700         (compare:CC (match_dup 0)
2701                     (const_int 0)))]
2702   "")
2703
2704 (define_insn "*boolccsi3_internal1"
2705   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2706         (match_operator:SI 3 "boolean_operator"
2707          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
2708           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
2709   ""
2710   "%q3 %0,%1,%2")
2711
2712 (define_insn "*boolccsi3_internal2"
2713   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2714         (compare:CC (match_operator:SI 4 "boolean_operator"
2715          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2716           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
2717          (const_int 0)))
2718    (clobber (match_scratch:SI 3 "=r,r"))]
2719   "TARGET_32BIT"
2720   "@
2721    %q4. %3,%1,%2
2722    #"
2723   [(set_attr "type" "compare")
2724    (set_attr "length" "4,8")])
2725
2726 (define_split
2727   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2728         (compare:CC (match_operator:SI 4 "boolean_operator"
2729          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2730           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
2731          (const_int 0)))
2732    (clobber (match_scratch:SI 3 ""))]
2733   "TARGET_32BIT && reload_completed"
2734   [(set (match_dup 3) (match_dup 4))
2735    (set (match_dup 0)
2736         (compare:CC (match_dup 3)
2737                     (const_int 0)))]
2738   "")
2739
2740 (define_insn "*boolccsi3_internal3"
2741   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2742         (compare:CC (match_operator:SI 4 "boolean_operator"
2743          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
2744           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
2745          (const_int 0)))
2746    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2747         (match_dup 4))]
2748   "TARGET_32BIT"
2749   "@
2750    %q4. %0,%1,%2
2751    #"
2752   [(set_attr "type" "compare")
2753    (set_attr "length" "4,8")])
2754
2755 (define_split
2756   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2757         (compare:CC (match_operator:SI 4 "boolean_operator"
2758          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2759           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
2760          (const_int 0)))
2761    (set (match_operand:SI 0 "gpc_reg_operand" "")
2762         (match_dup 4))]
2763   "TARGET_32BIT && reload_completed"
2764   [(set (match_dup 0) (match_dup 4))
2765    (set (match_dup 3)
2766         (compare:CC (match_dup 0)
2767                     (const_int 0)))]
2768   "")
2769
2770 ;; maskir insn.  We need four forms because things might be in arbitrary
2771 ;; orders.  Don't define forms that only set CR fields because these
2772 ;; would modify an input register.
2773
2774 (define_insn "*maskir_internal1"
2775   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2776         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
2777                         (match_operand:SI 1 "gpc_reg_operand" "0"))
2778                 (and:SI (match_dup 2)
2779                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
2780   "TARGET_POWER"
2781   "maskir %0,%3,%2")
2782
2783 (define_insn "*maskir_internal2"
2784   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2785         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
2786                         (match_operand:SI 1 "gpc_reg_operand" "0"))
2787                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2788                         (match_dup 2))))]
2789   "TARGET_POWER"
2790   "maskir %0,%3,%2")
2791
2792 (define_insn "*maskir_internal3"
2793   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2794         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2795                         (match_operand:SI 3 "gpc_reg_operand" "r"))
2796                 (and:SI (not:SI (match_dup 2))
2797                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
2798   "TARGET_POWER"
2799   "maskir %0,%3,%2")
2800
2801 (define_insn "*maskir_internal4"
2802   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2803         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2804                         (match_operand:SI 2 "gpc_reg_operand" "r"))
2805                 (and:SI (not:SI (match_dup 2))
2806                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
2807   "TARGET_POWER"
2808   "maskir %0,%3,%2")
2809
2810 (define_insn "*maskir_internal5"
2811   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2812         (compare:CC
2813          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2814                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
2815                  (and:SI (match_dup 2)
2816                          (match_operand:SI 3 "gpc_reg_operand" "r,r")))
2817          (const_int 0)))
2818    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2819         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2820                 (and:SI (match_dup 2) (match_dup 3))))]
2821   "TARGET_POWER"
2822   "@
2823    maskir. %0,%3,%2
2824    #"
2825   [(set_attr "type" "compare")
2826    (set_attr "length" "4,8")])
2827
2828 (define_split
2829   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2830         (compare:CC
2831          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
2832                          (match_operand:SI 1 "gpc_reg_operand" ""))
2833                  (and:SI (match_dup 2)
2834                          (match_operand:SI 3 "gpc_reg_operand" "")))
2835          (const_int 0)))
2836    (set (match_operand:SI 0 "gpc_reg_operand" "")
2837         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2838                 (and:SI (match_dup 2) (match_dup 3))))]
2839   "TARGET_POWER && reload_completed"
2840   [(set (match_dup 0)
2841         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2842                 (and:SI (match_dup 2) (match_dup 3))))
2843    (set (match_dup 4)
2844         (compare:CC (match_dup 0)
2845                     (const_int 0)))]
2846   "")
2847
2848 (define_insn "*maskir_internal6"
2849   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2850         (compare:CC
2851          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2852                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
2853                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
2854                          (match_dup 2)))
2855          (const_int 0)))
2856    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2857         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2858                 (and:SI (match_dup 3) (match_dup 2))))]
2859   "TARGET_POWER"
2860   "@
2861    maskir. %0,%3,%2
2862    #"
2863   [(set_attr "type" "compare")
2864    (set_attr "length" "4,8")])
2865
2866 (define_split
2867   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2868         (compare:CC
2869          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
2870                          (match_operand:SI 1 "gpc_reg_operand" ""))
2871                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
2872                          (match_dup 2)))
2873          (const_int 0)))
2874    (set (match_operand:SI 0 "gpc_reg_operand" "")
2875         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2876                 (and:SI (match_dup 3) (match_dup 2))))]
2877   "TARGET_POWER && reload_completed"
2878   [(set (match_dup 0)
2879         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2880                 (and:SI (match_dup 3) (match_dup 2))))
2881    (set (match_dup 4)
2882         (compare:CC (match_dup 0)
2883                     (const_int 0)))]
2884   "")
2885
2886 (define_insn "*maskir_internal7"
2887   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2888         (compare:CC
2889          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r,r")
2890                          (match_operand:SI 3 "gpc_reg_operand" "r,r"))
2891                  (and:SI (not:SI (match_dup 2))
2892                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
2893          (const_int 0)))
2894    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2895         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2896                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2897   "TARGET_POWER"
2898   "@
2899    maskir. %0,%3,%2
2900    #"
2901   [(set_attr "type" "compare")
2902    (set_attr "length" "4,8")])
2903
2904 (define_split
2905   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2906         (compare:CC
2907          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "")
2908                          (match_operand:SI 3 "gpc_reg_operand" ""))
2909                  (and:SI (not:SI (match_dup 2))
2910                          (match_operand:SI 1 "gpc_reg_operand" "")))
2911          (const_int 0)))
2912    (set (match_operand:SI 0 "gpc_reg_operand" "")
2913         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2914                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2915   "TARGET_POWER && reload_completed"
2916   [(set (match_dup 0)
2917         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2918                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
2919    (set (match_dup 4)
2920         (compare:CC (match_dup 0)
2921                     (const_int 0)))]
2922   "")
2923
2924 (define_insn "*maskir_internal8"
2925   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2926         (compare:CC
2927          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
2928                          (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2929                  (and:SI (not:SI (match_dup 2))
2930                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
2931          (const_int 0)))
2932    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2933         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2934                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2935   "TARGET_POWER"
2936   "@
2937    maskir. %0,%3,%2
2938    #"
2939   [(set_attr "type" "compare")
2940    (set_attr "length" "4,8")])
2941
2942 (define_split
2943   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2944         (compare:CC
2945          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
2946                          (match_operand:SI 2 "gpc_reg_operand" ""))
2947                  (and:SI (not:SI (match_dup 2))
2948                          (match_operand:SI 1 "gpc_reg_operand" "")))
2949          (const_int 0)))
2950    (set (match_operand:SI 0 "gpc_reg_operand" "")
2951         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2952                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2953   "TARGET_POWER && reload_completed"
2954   [(set (match_dup 0)
2955         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2956                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
2957    (set (match_dup 4)
2958         (compare:CC (match_dup 0)
2959                     (const_int 0)))]
2960   "")
2961 \f
2962 ;; Rotate and shift insns, in all their variants.  These support shifts,
2963 ;; field inserts and extracts, and various combinations thereof.
2964 (define_expand "insv"
2965   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
2966                        (match_operand:SI 1 "const_int_operand" "")
2967                        (match_operand:SI 2 "const_int_operand" ""))
2968         (match_operand 3 "gpc_reg_operand" ""))]
2969   ""
2970   "
2971 {
2972   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
2973      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
2974      compiler if the address of the structure is taken later.  */
2975   if (GET_CODE (operands[0]) == SUBREG
2976       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
2977     FAIL;
2978
2979   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
2980     emit_insn (gen_insvdi (operands[0], operands[1], operands[2], operands[3]));
2981   else
2982     emit_insn (gen_insvsi (operands[0], operands[1], operands[2], operands[3]));
2983   DONE;
2984 }")
2985
2986 (define_insn "insvsi"
2987   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2988                          (match_operand:SI 1 "const_int_operand" "i")
2989                          (match_operand:SI 2 "const_int_operand" "i"))
2990         (match_operand:SI 3 "gpc_reg_operand" "r"))]
2991   ""
2992   "*
2993 {
2994   int start = INTVAL (operands[2]) & 31;
2995   int size = INTVAL (operands[1]) & 31;
2996
2997   operands[4] = GEN_INT (32 - start - size);
2998   operands[1] = GEN_INT (start + size - 1);
2999   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3000 }"
3001   [(set_attr "type" "insert_word")])
3002
3003 (define_insn "*insvsi_internal1"
3004   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3005                          (match_operand:SI 1 "const_int_operand" "i")
3006                          (match_operand:SI 2 "const_int_operand" "i"))
3007         (ashift:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3008                    (match_operand:SI 4 "const_int_operand" "i")))]
3009   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3010   "*
3011 {
3012   int shift = INTVAL (operands[4]) & 31;
3013   int start = INTVAL (operands[2]) & 31;
3014   int size = INTVAL (operands[1]) & 31;
3015
3016   operands[4] = GEN_INT (shift - start - size);
3017   operands[1] = GEN_INT (start + size - 1 - shift);
3018   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3019 }"
3020   [(set_attr "type" "insert_word")])
3021
3022 (define_insn "*insvsi_internal2"
3023   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3024                          (match_operand:SI 1 "const_int_operand" "i")
3025                          (match_operand:SI 2 "const_int_operand" "i"))
3026         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3027                      (match_operand:SI 4 "const_int_operand" "i")))]
3028   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3029   "*
3030 {
3031   int shift = INTVAL (operands[4]) & 31;
3032   int start = INTVAL (operands[2]) & 31;
3033   int size = INTVAL (operands[1]) & 31;
3034
3035   operands[4] = GEN_INT (32 - shift - start - size);
3036   operands[1] = GEN_INT (start + size - 1);
3037   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3038 }"
3039   [(set_attr "type" "insert_word")])
3040
3041 (define_insn "*insvsi_internal3"
3042   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3043                          (match_operand:SI 1 "const_int_operand" "i")
3044                          (match_operand:SI 2 "const_int_operand" "i"))
3045         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3046                      (match_operand:SI 4 "const_int_operand" "i")))]
3047   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3048   "*
3049 {
3050   int shift = INTVAL (operands[4]) & 31;
3051   int start = INTVAL (operands[2]) & 31;
3052   int size = INTVAL (operands[1]) & 31;
3053
3054   operands[4] = GEN_INT (32 - shift - start - size);
3055   operands[1] = GEN_INT (start + size - 1);
3056   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3057 }"
3058   [(set_attr "type" "insert_word")])
3059
3060 (define_insn "*insvsi_internal4"
3061   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3062                          (match_operand:SI 1 "const_int_operand" "i")
3063                          (match_operand:SI 2 "const_int_operand" "i"))
3064         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3065                          (match_operand:SI 4 "const_int_operand" "i")
3066                          (match_operand:SI 5 "const_int_operand" "i")))]
3067   "INTVAL (operands[4]) >= INTVAL (operands[1])"
3068   "*
3069 {
3070   int extract_start = INTVAL (operands[5]) & 31;
3071   int extract_size = INTVAL (operands[4]) & 31;
3072   int insert_start = INTVAL (operands[2]) & 31;
3073   int insert_size = INTVAL (operands[1]) & 31;
3074
3075 /* Align extract field with insert field */
3076   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
3077   operands[1] = GEN_INT (insert_start + insert_size - 1);
3078   return \"{rlimi|rlwimi} %0,%3,%h5,%h2,%h1\";
3079 }"
3080   [(set_attr "type" "insert_word")])
3081
3082 ;; combine patterns for rlwimi
3083 (define_insn "*insvsi_internal5"
3084   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3085         (ior:SI (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3086                         (match_operand:SI 1 "mask_operand" "i"))
3087                 (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3088                                      (match_operand:SI 2 "const_int_operand" "i"))
3089                         (match_operand:SI 5 "mask_operand" "i"))))]
3090   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
3091   "*
3092 {
3093  int me = extract_ME(operands[5]);
3094  int mb = extract_MB(operands[5]);
3095  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3096  operands[2] = GEN_INT(mb);
3097  operands[1] = GEN_INT(me);
3098  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3099 }"
3100   [(set_attr "type" "insert_word")])
3101
3102 (define_insn "*insvsi_internal6"
3103   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3104         (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3105                                      (match_operand:SI 2 "const_int_operand" "i"))
3106                         (match_operand:SI 5 "mask_operand" "i"))
3107                 (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3108                         (match_operand:SI 1 "mask_operand" "i"))))]
3109   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
3110   "*
3111 {
3112  int me = extract_ME(operands[5]);
3113  int mb = extract_MB(operands[5]);
3114  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3115  operands[2] = GEN_INT(mb);
3116  operands[1] = GEN_INT(me);
3117  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3118 }"
3119   [(set_attr "type" "insert_word")])
3120
3121 (define_insn "insvdi"
3122   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3123                          (match_operand:SI 1 "const_int_operand" "i")
3124                          (match_operand:SI 2 "const_int_operand" "i"))
3125         (match_operand:DI 3 "gpc_reg_operand" "r"))]
3126   "TARGET_POWERPC64"
3127   "*
3128 {
3129   int start = INTVAL (operands[2]) & 63;
3130   int size = INTVAL (operands[1]) & 63;
3131
3132   operands[1] = GEN_INT (64 - start - size);
3133   return \"rldimi %0,%3,%H1,%H2\";
3134 }")
3135
3136 (define_insn "*insvdi_internal2"
3137   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3138                          (match_operand:SI 1 "const_int_operand" "i")
3139                          (match_operand:SI 2 "const_int_operand" "i"))
3140         (ashiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3141                      (match_operand:SI 4 "const_int_operand" "i")))]
3142   "TARGET_POWERPC64
3143    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3144   "*
3145 {
3146   int shift = INTVAL (operands[4]) & 63;
3147   int start = (INTVAL (operands[2]) & 63) - 32;
3148   int size = INTVAL (operands[1]) & 63;
3149
3150   operands[4] = GEN_INT (64 - shift - start - size);
3151   operands[2] = GEN_INT (start);
3152   operands[1] = GEN_INT (start + size - 1);
3153   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3154 }")
3155
3156 (define_insn "*insvdi_internal3"
3157   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3158                          (match_operand:SI 1 "const_int_operand" "i")
3159                          (match_operand:SI 2 "const_int_operand" "i"))
3160         (lshiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3161                      (match_operand:SI 4 "const_int_operand" "i")))]
3162   "TARGET_POWERPC64
3163    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3164   "*
3165 {
3166   int shift = INTVAL (operands[4]) & 63;
3167   int start = (INTVAL (operands[2]) & 63) - 32;
3168   int size = INTVAL (operands[1]) & 63;
3169
3170   operands[4] = GEN_INT (64 - shift - start - size);
3171   operands[2] = GEN_INT (start);
3172   operands[1] = GEN_INT (start + size - 1);
3173   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3174 }")
3175
3176 (define_expand "extzv"
3177   [(set (match_operand 0 "gpc_reg_operand" "")
3178         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3179                        (match_operand:SI 2 "const_int_operand" "")
3180                        (match_operand:SI 3 "const_int_operand" "")))]
3181   ""
3182   "
3183 {
3184   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3185      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3186      compiler if the address of the structure is taken later.  */
3187   if (GET_CODE (operands[0]) == SUBREG
3188       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3189     FAIL;
3190
3191   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3192     emit_insn (gen_extzvdi (operands[0], operands[1], operands[2], operands[3]));
3193   else
3194     emit_insn (gen_extzvsi (operands[0], operands[1], operands[2], operands[3]));
3195   DONE;
3196 }")
3197
3198 (define_insn "extzvsi"
3199   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3200         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3201                          (match_operand:SI 2 "const_int_operand" "i")
3202                          (match_operand:SI 3 "const_int_operand" "i")))]
3203   ""
3204   "*
3205 {
3206   int start = INTVAL (operands[3]) & 31;
3207   int size = INTVAL (operands[2]) & 31;
3208
3209   if (start + size >= 32)
3210     operands[3] = const0_rtx;
3211   else
3212     operands[3] = GEN_INT (start + size);
3213   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
3214 }")
3215
3216 (define_insn "*extzvsi_internal1"
3217   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3218         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3219                          (match_operand:SI 2 "const_int_operand" "i,i")
3220                          (match_operand:SI 3 "const_int_operand" "i,i"))
3221                     (const_int 0)))
3222    (clobber (match_scratch:SI 4 "=r,r"))]
3223   ""
3224   "*
3225 {
3226   int start = INTVAL (operands[3]) & 31;
3227   int size = INTVAL (operands[2]) & 31;
3228
3229   /* Force split for non-cc0 compare.  */
3230   if (which_alternative == 1)
3231      return \"#\";
3232
3233   /* If the bit-field being tested fits in the upper or lower half of a
3234      word, it is possible to use andiu. or andil. to test it.  This is
3235      useful because the condition register set-use delay is smaller for
3236      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3237      position is 0 because the LT and GT bits may be set wrong.  */
3238
3239   if ((start > 0 && start + size <= 16) || start >= 16)
3240     {
3241       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3242                               - (1 << (16 - (start & 15) - size))));
3243       if (start < 16)
3244         return \"{andiu.|andis.} %4,%1,%3\";
3245       else
3246         return \"{andil.|andi.} %4,%1,%3\";
3247     }
3248
3249   if (start + size >= 32)
3250     operands[3] = const0_rtx;
3251   else
3252     operands[3] = GEN_INT (start + size);
3253   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
3254 }"
3255   [(set_attr "type" "compare")
3256    (set_attr "length" "4,8")])
3257
3258 (define_split
3259   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3260         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3261                          (match_operand:SI 2 "const_int_operand" "")
3262                          (match_operand:SI 3 "const_int_operand" ""))
3263                     (const_int 0)))
3264    (clobber (match_scratch:SI 4 ""))]
3265   "reload_completed"
3266   [(set (match_dup 4)
3267         (zero_extract:SI (match_dup 1) (match_dup 2)
3268                          (match_dup 3)))
3269    (set (match_dup 0)
3270         (compare:CC (match_dup 4)
3271                     (const_int 0)))]
3272   "")
3273
3274 (define_insn "*extzvsi_internal2"
3275   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3276         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3277                          (match_operand:SI 2 "const_int_operand" "i,i")
3278                          (match_operand:SI 3 "const_int_operand" "i,i"))
3279                     (const_int 0)))
3280    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3281         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3282   ""
3283   "*
3284 {
3285   int start = INTVAL (operands[3]) & 31;
3286   int size = INTVAL (operands[2]) & 31;
3287
3288   /* Force split for non-cc0 compare.  */
3289   if (which_alternative == 1)
3290      return \"#\";
3291
3292   /* Since we are using the output value, we can't ignore any need for
3293      a shift.  The bit-field must end at the LSB.  */
3294   if (start >= 16 && start + size == 32)
3295     {
3296       operands[3] = GEN_INT ((1 << size) - 1);
3297       return \"{andil.|andi.} %0,%1,%3\";
3298     }
3299
3300   if (start + size >= 32)
3301     operands[3] = const0_rtx;
3302   else
3303     operands[3] = GEN_INT (start + size);
3304   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
3305 }"
3306   [(set_attr "type" "compare")
3307    (set_attr "length" "4,8")])
3308
3309 (define_split
3310   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3311         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3312                          (match_operand:SI 2 "const_int_operand" "")
3313                          (match_operand:SI 3 "const_int_operand" ""))
3314                     (const_int 0)))
3315    (set (match_operand:SI 0 "gpc_reg_operand" "")
3316         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3317   "reload_completed"
3318   [(set (match_dup 0)
3319         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3320    (set (match_dup 4)
3321         (compare:CC (match_dup 0)
3322                     (const_int 0)))]
3323   "")
3324
3325 (define_insn "extzvdi"
3326   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3327         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3328                          (match_operand:SI 2 "const_int_operand" "i")
3329                          (match_operand:SI 3 "const_int_operand" "i")))]
3330   "TARGET_POWERPC64"
3331   "*
3332 {
3333   int start = INTVAL (operands[3]) & 63;
3334   int size = INTVAL (operands[2]) & 63;
3335
3336   if (start + size >= 64)
3337     operands[3] = const0_rtx;
3338   else
3339     operands[3] = GEN_INT (start + size);
3340   operands[2] = GEN_INT (64 - size);
3341   return \"rldicl %0,%1,%3,%2\";
3342 }")
3343
3344 (define_insn "*extzvdi_internal1"
3345   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3346         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3347                          (match_operand:SI 2 "const_int_operand" "i")
3348                          (match_operand:SI 3 "const_int_operand" "i"))
3349                     (const_int 0)))
3350    (clobber (match_scratch:DI 4 "=r"))]
3351   "TARGET_64BIT"
3352   "*
3353 {
3354   int start = INTVAL (operands[3]) & 63;
3355   int size = INTVAL (operands[2]) & 63;
3356
3357   if (start + size >= 64)
3358     operands[3] = const0_rtx;
3359   else
3360     operands[3] = GEN_INT (start + size);
3361   operands[2] = GEN_INT (64 - size);
3362   return \"rldicl. %4,%1,%3,%2\";
3363 }"
3364   [(set_attr "type" "compare")])
3365
3366 (define_insn "*extzvdi_internal2"
3367   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3368         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3369                          (match_operand:SI 2 "const_int_operand" "i")
3370                          (match_operand:SI 3 "const_int_operand" "i"))
3371                     (const_int 0)))
3372    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3373         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3374   "TARGET_64BIT"
3375   "*
3376 {
3377   int start = INTVAL (operands[3]) & 63;
3378   int size = INTVAL (operands[2]) & 63;
3379
3380   if (start + size >= 64)
3381     operands[3] = const0_rtx;
3382   else
3383     operands[3] = GEN_INT (start + size);
3384   operands[2] = GEN_INT (64 - size);
3385   return \"rldicl. %0,%1,%3,%2\";
3386 }"
3387   [(set_attr "type" "compare")])
3388
3389 (define_insn "rotlsi3"
3390   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3391         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3392                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3393   ""
3394   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffffffff")
3395
3396 (define_insn "*rotlsi3_internal2"
3397   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3398         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3399                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3400                     (const_int 0)))
3401    (clobber (match_scratch:SI 3 "=r,r"))]
3402   ""
3403   "@
3404    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffffffff
3405    #"
3406   [(set_attr "type" "delayed_compare")
3407    (set_attr "length" "4,8")])
3408
3409 (define_split
3410   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3411         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3412                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3413                     (const_int 0)))
3414    (clobber (match_scratch:SI 3 ""))]
3415   "reload_completed"
3416   [(set (match_dup 3)
3417         (rotate:SI (match_dup 1) (match_dup 2)))
3418    (set (match_dup 0)
3419         (compare:CC (match_dup 3)
3420                     (const_int 0)))]
3421   "")
3422
3423 (define_insn "*rotlsi3_internal3"
3424   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3425         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3426                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3427                     (const_int 0)))
3428    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3429         (rotate:SI (match_dup 1) (match_dup 2)))]
3430   ""
3431   "@
3432    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffffffff
3433    #"
3434   [(set_attr "type" "delayed_compare")
3435    (set_attr "length" "4,8")])
3436
3437 (define_split
3438   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3439         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3440                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3441                     (const_int 0)))
3442    (set (match_operand:SI 0 "gpc_reg_operand" "")
3443         (rotate:SI (match_dup 1) (match_dup 2)))]
3444   "reload_completed"
3445   [(set (match_dup 0)
3446         (rotate:SI (match_dup 1) (match_dup 2)))
3447    (set (match_dup 3)
3448         (compare:CC (match_dup 0)
3449                     (const_int 0)))]
3450   "")
3451
3452 (define_insn "*rotlsi3_internal4"
3453   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3454         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3455                            (match_operand:SI 2 "reg_or_cint_operand" "ri"))
3456                 (match_operand:SI 3 "mask_operand" "n")))]
3457   ""
3458   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,%m3,%M3")
3459
3460 (define_insn "*rotlsi3_internal5"
3461   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3462         (compare:CC (and:SI
3463                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3464                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3465                      (match_operand:SI 3 "mask_operand" "n,n"))
3466                     (const_int 0)))
3467    (clobber (match_scratch:SI 4 "=r,r"))]
3468   ""
3469   "@
3470    {rl%I2nm.|rlw%I2nm.} %4,%1,%h2,%m3,%M3
3471    #"
3472   [(set_attr "type" "delayed_compare")
3473    (set_attr "length" "4,8")])
3474
3475 (define_split
3476   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3477         (compare:CC (and:SI
3478                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3479                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3480                      (match_operand:SI 3 "mask_operand" ""))
3481                     (const_int 0)))
3482    (clobber (match_scratch:SI 4 ""))]
3483   "reload_completed"
3484   [(set (match_dup 4)
3485         (and:SI (rotate:SI (match_dup 1)
3486                                 (match_dup 2))
3487                      (match_dup 3)))
3488    (set (match_dup 0)
3489         (compare:CC (match_dup 4)
3490                     (const_int 0)))]
3491   "")
3492
3493 (define_insn "*rotlsi3_internal6"
3494   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3495         (compare:CC (and:SI
3496                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3497                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3498                      (match_operand:SI 3 "mask_operand" "n,n"))
3499                     (const_int 0)))
3500    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3501         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3502   ""
3503   "@
3504    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,%m3,%M3
3505    #"
3506   [(set_attr "type" "delayed_compare")
3507    (set_attr "length" "4,8")])
3508
3509 (define_split
3510   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3511         (compare:CC (and:SI
3512                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3513                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3514                      (match_operand:SI 3 "mask_operand" ""))
3515                     (const_int 0)))
3516    (set (match_operand:SI 0 "gpc_reg_operand" "")
3517         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3518   "reload_completed"
3519   [(set (match_dup 0)
3520         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3521    (set (match_dup 4)
3522         (compare:CC (match_dup 0)
3523                     (const_int 0)))]
3524   "")
3525
3526 (define_insn "*rotlsi3_internal7"
3527   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3528         (zero_extend:SI
3529          (subreg:QI
3530           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3531                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3532   ""
3533   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff")
3534
3535 (define_insn "*rotlsi3_internal8"
3536   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3537         (compare:CC (zero_extend:SI
3538                      (subreg:QI
3539                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3540                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3541                     (const_int 0)))
3542    (clobber (match_scratch:SI 3 "=r,r"))]
3543   ""
3544   "@
3545    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xff
3546    #"
3547   [(set_attr "type" "delayed_compare")
3548    (set_attr "length" "4,8")])
3549
3550 (define_split
3551   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3552         (compare:CC (zero_extend:SI
3553                      (subreg:QI
3554                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3555                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3556                     (const_int 0)))
3557    (clobber (match_scratch:SI 3 ""))]
3558   "reload_completed"
3559   [(set (match_dup 3)
3560         (zero_extend:SI (subreg:QI
3561                       (rotate:SI (match_dup 1)
3562                                  (match_dup 2)) 0)))
3563    (set (match_dup 0)
3564         (compare:CC (match_dup 3)
3565                     (const_int 0)))]
3566   "")
3567
3568 (define_insn "*rotlsi3_internal9"
3569   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3570         (compare:CC (zero_extend:SI
3571                      (subreg:QI
3572                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3573                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3574                     (const_int 0)))
3575    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3576         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3577   ""
3578   "@
3579    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xff
3580    #"
3581   [(set_attr "type" "delayed_compare")
3582    (set_attr "length" "4,8")])
3583
3584 (define_split
3585   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3586         (compare:CC (zero_extend:SI
3587                      (subreg:QI
3588                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3589                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3590                     (const_int 0)))
3591    (set (match_operand:SI 0 "gpc_reg_operand" "")
3592         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3593   "reload_completed"
3594   [(set (match_dup 0)
3595         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3596    (set (match_dup 3)
3597         (compare:CC (match_dup 0)
3598                     (const_int 0)))]
3599   "")
3600
3601 (define_insn "*rotlsi3_internal10"
3602   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3603         (zero_extend:SI
3604          (subreg:HI
3605           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3606                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3607   ""
3608   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffff")
3609
3610 (define_insn "*rotlsi3_internal11"
3611   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3612         (compare:CC (zero_extend:SI
3613                      (subreg:HI
3614                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3615                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3616                     (const_int 0)))
3617    (clobber (match_scratch:SI 3 "=r,r"))]
3618   ""
3619   "@
3620    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffff
3621    #"
3622   [(set_attr "type" "delayed_compare")
3623    (set_attr "length" "4,8")])
3624
3625 (define_split
3626   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3627         (compare:CC (zero_extend:SI
3628                      (subreg:HI
3629                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3630                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3631                     (const_int 0)))
3632    (clobber (match_scratch:SI 3 ""))]
3633   "reload_completed"
3634   [(set (match_dup 3)
3635         (zero_extend:SI (subreg:HI
3636                       (rotate:SI (match_dup 1)
3637                                  (match_dup 2)) 0)))
3638    (set (match_dup 0)
3639         (compare:CC (match_dup 3)
3640                     (const_int 0)))]
3641   "")
3642
3643 (define_insn "*rotlsi3_internal12"
3644   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3645         (compare:CC (zero_extend:SI
3646                      (subreg:HI
3647                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3648                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3649                     (const_int 0)))
3650    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3651         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3652   ""
3653   "@
3654    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffff
3655    #"
3656   [(set_attr "type" "delayed_compare")
3657    (set_attr "length" "4,8")])
3658
3659 (define_split
3660   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3661         (compare:CC (zero_extend:SI
3662                      (subreg:HI
3663                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3664                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3665                     (const_int 0)))
3666    (set (match_operand:SI 0 "gpc_reg_operand" "")
3667         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3668   "reload_completed"
3669   [(set (match_dup 0)
3670         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3671    (set (match_dup 3)
3672         (compare:CC (match_dup 0)
3673                     (const_int 0)))]
3674   "")
3675
3676 ;; Note that we use "sle." instead of "sl." so that we can set
3677 ;; SHIFT_COUNT_TRUNCATED.
3678
3679 (define_expand "ashlsi3"
3680   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
3681    (use (match_operand:SI 1 "gpc_reg_operand" ""))
3682    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
3683   ""
3684   "
3685 {
3686   if (TARGET_POWER)
3687     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
3688   else
3689     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
3690   DONE;
3691 }")
3692
3693 (define_insn "ashlsi3_power"
3694   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3695         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3696                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
3697    (clobber (match_scratch:SI 3 "=q,X"))]
3698   "TARGET_POWER"
3699   "@
3700    sle %0,%1,%2
3701    {sli|slwi} %0,%1,%h2")
3702
3703 (define_insn "ashlsi3_no_power"
3704   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3705         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3706                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3707   "! TARGET_POWER"
3708   "{sl|slw}%I2 %0,%1,%h2")
3709
3710 (define_insn ""
3711   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3712         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3713                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3714                     (const_int 0)))
3715    (clobber (match_scratch:SI 3 "=r,r,r,r"))
3716    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
3717   "TARGET_POWER"
3718   "@
3719    sle. %3,%1,%2
3720    {sli.|slwi.} %3,%1,%h2
3721    #
3722    #"
3723   [(set_attr "type" "delayed_compare")
3724    (set_attr "length" "4,4,8,8")])
3725
3726 (define_split
3727   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3728         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3729                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3730                     (const_int 0)))
3731    (clobber (match_scratch:SI 3 ""))
3732    (clobber (match_scratch:SI 4 ""))]
3733   "TARGET_POWER && reload_completed"
3734   [(parallel [(set (match_dup 3)
3735         (ashift:SI (match_dup 1) (match_dup 2)))
3736    (clobber (match_dup 4))])
3737    (set (match_dup 0)
3738         (compare:CC (match_dup 3)
3739                     (const_int 0)))]
3740   "")
3741
3742 (define_insn ""
3743   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3744         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3745                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3746                     (const_int 0)))
3747    (clobber (match_scratch:SI 3 "=r,r"))]
3748   "! TARGET_POWER && TARGET_32BIT"
3749   "@
3750    {sl|slw}%I2. %3,%1,%h2
3751    #"
3752   [(set_attr "type" "delayed_compare")
3753    (set_attr "length" "4,8")])
3754
3755 (define_split
3756   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3757         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3758                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3759                     (const_int 0)))
3760    (clobber (match_scratch:SI 3 ""))]
3761   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3762   [(set (match_dup 3)
3763         (ashift:SI (match_dup 1) (match_dup 2)))
3764    (set (match_dup 0)
3765         (compare:CC (match_dup 3)
3766                     (const_int 0)))]
3767   "")
3768
3769 (define_insn ""
3770   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3771         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3772                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3773                     (const_int 0)))
3774    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3775         (ashift:SI (match_dup 1) (match_dup 2)))
3776    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
3777   "TARGET_POWER"
3778   "@
3779    sle. %0,%1,%2
3780    {sli.|slwi.} %0,%1,%h2
3781    #
3782    #"
3783   [(set_attr "type" "delayed_compare")
3784    (set_attr "length" "4,4,8,8")])
3785
3786 (define_split
3787   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3788         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3789                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3790                     (const_int 0)))
3791    (set (match_operand:SI 0 "gpc_reg_operand" "")
3792         (ashift:SI (match_dup 1) (match_dup 2)))
3793    (clobber (match_scratch:SI 4 ""))]
3794   "TARGET_POWER && reload_completed"
3795   [(parallel [(set (match_dup 0)
3796         (ashift:SI (match_dup 1) (match_dup 2)))
3797    (clobber (match_dup 4))])
3798    (set (match_dup 3)
3799         (compare:CC (match_dup 0)
3800                     (const_int 0)))]
3801   "")
3802
3803 (define_insn ""
3804   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3805         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3806                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3807                     (const_int 0)))
3808    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3809         (ashift:SI (match_dup 1) (match_dup 2)))]
3810   "! TARGET_POWER && TARGET_32BIT"
3811   "@
3812    {sl|slw}%I2. %0,%1,%h2
3813    #"
3814   [(set_attr "type" "delayed_compare")
3815    (set_attr "length" "4,8")])
3816
3817 (define_split
3818   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3819         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3820                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3821                     (const_int 0)))
3822    (set (match_operand:SI 0 "gpc_reg_operand" "")
3823         (ashift:SI (match_dup 1) (match_dup 2)))]
3824   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3825   [(set (match_dup 0)
3826         (ashift:SI (match_dup 1) (match_dup 2)))
3827    (set (match_dup 3)
3828         (compare:CC (match_dup 0)
3829                     (const_int 0)))]
3830   "")
3831
3832 (define_insn "rlwinm"
3833   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3834         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3835                            (match_operand:SI 2 "const_int_operand" "i"))
3836                 (match_operand:SI 3 "mask_operand" "n")))]
3837   "includes_lshift_p (operands[2], operands[3])"
3838   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
3839
3840 (define_insn ""
3841   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3842         (compare:CC
3843          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3844                             (match_operand:SI 2 "const_int_operand" "i,i"))
3845                  (match_operand:SI 3 "mask_operand" "n,n"))
3846          (const_int 0)))
3847    (clobber (match_scratch:SI 4 "=r,r"))]
3848   "includes_lshift_p (operands[2], operands[3])"
3849   "@
3850    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
3851    #"
3852   [(set_attr "type" "delayed_compare")
3853    (set_attr "length" "4,8")])
3854
3855 (define_split
3856   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3857         (compare:CC
3858          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3859                             (match_operand:SI 2 "const_int_operand" ""))
3860                  (match_operand:SI 3 "mask_operand" ""))
3861          (const_int 0)))
3862    (clobber (match_scratch:SI 4 ""))]
3863   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
3864   [(set (match_dup 4)
3865         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
3866                  (match_dup 3)))
3867    (set (match_dup 0)
3868         (compare:CC (match_dup 4)
3869                     (const_int 0)))]
3870   "")
3871
3872 (define_insn ""
3873   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3874         (compare:CC
3875          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3876                             (match_operand:SI 2 "const_int_operand" "i,i"))
3877                  (match_operand:SI 3 "mask_operand" "n,n"))
3878          (const_int 0)))
3879    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3880         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3881   "includes_lshift_p (operands[2], operands[3])"
3882   "@
3883    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
3884    #"
3885   [(set_attr "type" "delayed_compare")
3886    (set_attr "length" "4,8")])
3887
3888 (define_split
3889   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3890         (compare:CC
3891          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3892                             (match_operand:SI 2 "const_int_operand" ""))
3893                  (match_operand:SI 3 "mask_operand" ""))
3894          (const_int 0)))
3895    (set (match_operand:SI 0 "gpc_reg_operand" "")
3896         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3897   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
3898   [(set (match_dup 0)
3899         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3900    (set (match_dup 4)
3901         (compare:CC (match_dup 0)
3902                     (const_int 0)))]
3903   "")
3904
3905 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
3906 ;; "sli x,x,0".
3907 (define_expand "lshrsi3"
3908   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
3909    (use (match_operand:SI 1 "gpc_reg_operand" ""))
3910    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
3911   ""
3912   "
3913 {
3914   if (TARGET_POWER)
3915     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
3916   else
3917     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
3918   DONE;
3919 }")
3920
3921 (define_insn "lshrsi3_power"
3922   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
3923         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
3924                      (match_operand:SI 2 "reg_or_cint_operand" "r,O,i")))
3925    (clobber (match_scratch:SI 3 "=q,X,X"))]
3926   "TARGET_POWER"
3927   "@
3928   sre %0,%1,%2
3929   mr %0,%1
3930   {s%A2i|s%A2wi} %0,%1,%h2")
3931
3932 (define_insn "lshrsi3_no_power"
3933   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3934         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3935                      (match_operand:SI 2 "reg_or_cint_operand" "O,ri")))]
3936   "! TARGET_POWER"
3937   "@
3938   mr %0,%1
3939   {sr|srw}%I2 %0,%1,%h2")
3940
3941 (define_insn ""
3942   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
3943         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
3944                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
3945                     (const_int 0)))
3946    (clobber (match_scratch:SI 3 "=r,X,r,r,X,r"))
3947    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
3948   "TARGET_POWER"
3949   "@
3950   sre. %3,%1,%2
3951   mr. %1,%1
3952   {s%A2i.|s%A2wi.} %3,%1,%h2
3953   #
3954   #
3955   #"
3956   [(set_attr "type" "delayed_compare")
3957    (set_attr "length" "4,4,4,8,8,8")])
3958
3959 (define_split
3960   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3961         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3962                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3963                     (const_int 0)))
3964    (clobber (match_scratch:SI 3 ""))
3965    (clobber (match_scratch:SI 4 ""))]
3966   "TARGET_POWER && reload_completed"
3967   [(parallel [(set (match_dup 3)
3968         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3969    (clobber (match_dup 4))])
3970    (set (match_dup 0)
3971         (compare:CC (match_dup 3)
3972                     (const_int 0)))]
3973   "")
3974
3975 (define_insn ""
3976   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3977         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3978                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
3979                     (const_int 0)))
3980    (clobber (match_scratch:SI 3 "=X,r,X,r"))]
3981   "! TARGET_POWER && TARGET_32BIT"
3982   "@
3983    mr. %1,%1
3984    {sr|srw}%I2. %3,%1,%h2
3985    #
3986    #"
3987   [(set_attr "type" "delayed_compare")
3988    (set_attr "length" "4,4,8,8")])
3989
3990 (define_split
3991   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3992         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3993                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3994                     (const_int 0)))
3995    (clobber (match_scratch:SI 3 ""))]
3996   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3997   [(set (match_dup 3)
3998         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3999    (set (match_dup 0)
4000         (compare:CC (match_dup 3)
4001                     (const_int 0)))]
4002   "")
4003
4004 (define_insn ""
4005   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4006         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4007                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
4008                     (const_int 0)))
4009    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
4010         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4011    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
4012   "TARGET_POWER"
4013   "@
4014   sre. %0,%1,%2
4015   mr. %0,%1
4016   {s%A2i.|s%A2wi.} %0,%1,%h2
4017   #
4018   #
4019   #"
4020   [(set_attr "type" "delayed_compare")
4021    (set_attr "length" "4,4,4,8,8,8")])
4022
4023 (define_split
4024   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4025         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4026                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4027                     (const_int 0)))
4028    (set (match_operand:SI 0 "gpc_reg_operand" "")
4029         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4030    (clobber (match_scratch:SI 4 ""))]
4031   "TARGET_POWER && reload_completed"
4032   [(parallel [(set (match_dup 0)
4033         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4034    (clobber (match_dup 4))])
4035    (set (match_dup 3)
4036         (compare:CC (match_dup 0)
4037                     (const_int 0)))]
4038   "")
4039
4040 (define_insn ""
4041   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4042         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4043                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
4044                     (const_int 0)))
4045    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4046         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4047   "! TARGET_POWER && TARGET_32BIT"
4048   "@
4049    mr. %0,%1
4050    {sr|srw}%I2. %0,%1,%h2
4051    #
4052    #"
4053   [(set_attr "type" "delayed_compare")
4054    (set_attr "length" "4,4,8,8")])
4055
4056 (define_split
4057   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4058         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4059                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4060                     (const_int 0)))
4061    (set (match_operand:SI 0 "gpc_reg_operand" "")
4062         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4063   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4064   [(set (match_dup 0)
4065         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4066    (set (match_dup 3)
4067         (compare:CC (match_dup 0)
4068                     (const_int 0)))]
4069   "")
4070
4071 (define_insn ""
4072   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4073         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4074                              (match_operand:SI 2 "const_int_operand" "i"))
4075                 (match_operand:SI 3 "mask_operand" "n")))]
4076   "includes_rshift_p (operands[2], operands[3])"
4077   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
4078
4079 (define_insn ""
4080   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4081         (compare:CC
4082          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4083                               (match_operand:SI 2 "const_int_operand" "i,i"))
4084                  (match_operand:SI 3 "mask_operand" "n,n"))
4085          (const_int 0)))
4086    (clobber (match_scratch:SI 4 "=r,r"))]
4087   "includes_rshift_p (operands[2], operands[3])"
4088   "@
4089    {rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3
4090    #"
4091   [(set_attr "type" "delayed_compare")
4092    (set_attr "length" "4,8")])
4093
4094 (define_split
4095   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4096         (compare:CC
4097          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4098                               (match_operand:SI 2 "const_int_operand" ""))
4099                  (match_operand:SI 3 "mask_operand" ""))
4100          (const_int 0)))
4101    (clobber (match_scratch:SI 4 ""))]
4102   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4103   [(set (match_dup 4)
4104         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
4105                  (match_dup 3)))
4106    (set (match_dup 0)
4107         (compare:CC (match_dup 4)
4108                     (const_int 0)))]
4109   "")
4110
4111 (define_insn ""
4112   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4113         (compare:CC
4114          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4115                               (match_operand:SI 2 "const_int_operand" "i,i"))
4116                  (match_operand:SI 3 "mask_operand" "n,n"))
4117          (const_int 0)))
4118    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4119         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4120   "includes_rshift_p (operands[2], operands[3])"
4121   "@
4122    {rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3
4123    #"
4124   [(set_attr "type" "delayed_compare")
4125    (set_attr "length" "4,8")])
4126
4127 (define_split
4128   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4129         (compare:CC
4130          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4131                               (match_operand:SI 2 "const_int_operand" ""))
4132                  (match_operand:SI 3 "mask_operand" ""))
4133          (const_int 0)))
4134    (set (match_operand:SI 0 "gpc_reg_operand" "")
4135         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4136   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4137   [(set (match_dup 0)
4138         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4139    (set (match_dup 4)
4140         (compare:CC (match_dup 0)
4141                     (const_int 0)))]
4142   "")
4143
4144 (define_insn ""
4145   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4146         (zero_extend:SI
4147          (subreg:QI
4148           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4149                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4150   "includes_rshift_p (operands[2], GEN_INT (255))"
4151   "{rlinm|rlwinm} %0,%1,%s2,0xff")
4152
4153 (define_insn ""
4154   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4155         (compare:CC
4156          (zero_extend:SI
4157           (subreg:QI
4158            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4159                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4160          (const_int 0)))
4161    (clobber (match_scratch:SI 3 "=r,r"))]
4162   "includes_rshift_p (operands[2], GEN_INT (255))"
4163   "@
4164    {rlinm.|rlwinm.} %3,%1,%s2,0xff
4165    #"
4166   [(set_attr "type" "delayed_compare")
4167    (set_attr "length" "4,8")])
4168
4169 (define_split
4170   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4171         (compare:CC
4172          (zero_extend:SI
4173           (subreg:QI
4174            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4175                         (match_operand:SI 2 "const_int_operand" "")) 0))
4176          (const_int 0)))
4177    (clobber (match_scratch:SI 3 ""))]
4178   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4179   [(set (match_dup 3)
4180         (zero_extend:SI (subreg:QI
4181            (lshiftrt:SI (match_dup 1)
4182                         (match_dup 2)) 0)))
4183    (set (match_dup 0)
4184         (compare:CC (match_dup 3)
4185                     (const_int 0)))]
4186   "")
4187
4188 (define_insn ""
4189   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4190         (compare:CC
4191          (zero_extend:SI
4192           (subreg:QI
4193            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4194                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4195          (const_int 0)))
4196    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4197         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4198   "includes_rshift_p (operands[2], GEN_INT (255))"
4199   "@
4200    {rlinm.|rlwinm.} %0,%1,%s2,0xff
4201    #"
4202   [(set_attr "type" "delayed_compare")
4203    (set_attr "length" "4,8")])
4204
4205 (define_split
4206   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4207         (compare:CC
4208          (zero_extend:SI
4209           (subreg:QI
4210            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4211                         (match_operand:SI 2 "const_int_operand" "")) 0))
4212          (const_int 0)))
4213    (set (match_operand:SI 0 "gpc_reg_operand" "")
4214         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4215   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4216   [(set (match_dup 0)
4217         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4218    (set (match_dup 3)
4219         (compare:CC (match_dup 0)
4220                     (const_int 0)))]
4221   "")
4222
4223 (define_insn ""
4224   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4225         (zero_extend:SI
4226          (subreg:HI
4227           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4228                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4229   "includes_rshift_p (operands[2], GEN_INT (65535))"
4230   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
4231
4232 (define_insn ""
4233   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4234         (compare:CC
4235          (zero_extend:SI
4236           (subreg:HI
4237            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4238                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4239          (const_int 0)))
4240    (clobber (match_scratch:SI 3 "=r,r"))]
4241   "includes_rshift_p (operands[2], GEN_INT (65535))"
4242   "@
4243    {rlinm.|rlwinm.} %3,%1,%s2,0xffff
4244    #"
4245   [(set_attr "type" "delayed_compare")
4246    (set_attr "length" "4,8")])
4247
4248 (define_split
4249   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4250         (compare:CC
4251          (zero_extend:SI
4252           (subreg:HI
4253            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4254                         (match_operand:SI 2 "const_int_operand" "")) 0))
4255          (const_int 0)))
4256    (clobber (match_scratch:SI 3 ""))]
4257   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4258   [(set (match_dup 3)
4259         (zero_extend:SI (subreg:HI
4260            (lshiftrt:SI (match_dup 1)
4261                         (match_dup 2)) 0)))
4262    (set (match_dup 0)
4263         (compare:CC (match_dup 3)
4264                     (const_int 0)))]
4265   "")
4266
4267 (define_insn ""
4268   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4269         (compare:CC
4270          (zero_extend:SI
4271           (subreg:HI
4272            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4273                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4274          (const_int 0)))
4275    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4276         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4277   "includes_rshift_p (operands[2], GEN_INT (65535))"
4278   "@
4279    {rlinm.|rlwinm.} %0,%1,%s2,0xffff
4280    #"
4281   [(set_attr "type" "delayed_compare")
4282    (set_attr "length" "4,8")])
4283
4284 (define_split
4285   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4286         (compare:CC
4287          (zero_extend:SI
4288           (subreg:HI
4289            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4290                         (match_operand:SI 2 "const_int_operand" "")) 0))
4291          (const_int 0)))
4292    (set (match_operand:SI 0 "gpc_reg_operand" "")
4293         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4294   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4295   [(set (match_dup 0)
4296         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4297    (set (match_dup 3)
4298         (compare:CC (match_dup 0)
4299                     (const_int 0)))]
4300   "")
4301
4302 (define_insn ""
4303   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4304                          (const_int 1)
4305                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4306         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4307                      (const_int 31)))]
4308   "TARGET_POWER"
4309   "rrib %0,%1,%2")
4310
4311 (define_insn ""
4312   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4313                          (const_int 1)
4314                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4315         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4316                      (const_int 31)))]
4317   "TARGET_POWER"
4318   "rrib %0,%1,%2")
4319
4320 (define_insn ""
4321   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4322                          (const_int 1)
4323                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4324         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4325                          (const_int 1)
4326                          (const_int 0)))]
4327   "TARGET_POWER"
4328   "rrib %0,%1,%2")
4329
4330 (define_expand "ashrsi3"
4331   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4332         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4333                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
4334   ""
4335   "
4336 {
4337   if (TARGET_POWER)
4338     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
4339   else
4340     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
4341   DONE;
4342 }")
4343
4344 (define_insn "ashrsi3_power"
4345   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4346         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4347                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4348    (clobber (match_scratch:SI 3 "=q,X"))]
4349   "TARGET_POWER"
4350   "@
4351    srea %0,%1,%2
4352    {srai|srawi} %0,%1,%h2")
4353
4354 (define_insn "ashrsi3_no_power"
4355   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4356         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4357                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4358   "! TARGET_POWER"
4359   "{sra|sraw}%I2 %0,%1,%h2")
4360
4361 (define_insn ""
4362   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4363         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4364                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4365                     (const_int 0)))
4366    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4367    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4368   "TARGET_POWER"
4369   "@
4370    srea. %3,%1,%2
4371    {srai.|srawi.} %3,%1,%h2
4372    #
4373    #"
4374   [(set_attr "type" "delayed_compare")
4375    (set_attr "length" "4,4,8,8")])
4376
4377 (define_split
4378   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4379         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4380                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4381                     (const_int 0)))
4382    (clobber (match_scratch:SI 3 ""))
4383    (clobber (match_scratch:SI 4 ""))]
4384   "TARGET_POWER && reload_completed"
4385   [(parallel [(set (match_dup 3)
4386         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4387    (clobber (match_dup 4))])
4388    (set (match_dup 0)
4389         (compare:CC (match_dup 3)
4390                     (const_int 0)))]
4391   "")
4392
4393 (define_insn ""
4394   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4395         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4396                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4397                     (const_int 0)))
4398    (clobber (match_scratch:SI 3 "=r,r"))]
4399   "! TARGET_POWER"
4400   "@
4401    {sra|sraw}%I2. %3,%1,%h2
4402    #"
4403   [(set_attr "type" "delayed_compare")
4404    (set_attr "length" "4,8")])
4405
4406 (define_split
4407   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4408         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4409                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4410                     (const_int 0)))
4411    (clobber (match_scratch:SI 3 ""))]
4412   "! TARGET_POWER && reload_completed"
4413   [(set (match_dup 3)
4414         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4415    (set (match_dup 0)
4416         (compare:CC (match_dup 3)
4417                     (const_int 0)))]
4418   "")
4419
4420 (define_insn ""
4421   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4422         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4423                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4424                     (const_int 0)))
4425    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4426         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4427    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4428   "TARGET_POWER"
4429   "@
4430    srea. %0,%1,%2
4431    {srai.|srawi.} %0,%1,%h2
4432    #
4433    #"
4434   [(set_attr "type" "delayed_compare")
4435    (set_attr "length" "4,4,8,8")])
4436
4437 (define_split
4438   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4439         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4440                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4441                     (const_int 0)))
4442    (set (match_operand:SI 0 "gpc_reg_operand" "")
4443         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4444    (clobber (match_scratch:SI 4 ""))]
4445   "TARGET_POWER && reload_completed"
4446   [(parallel [(set (match_dup 0)
4447         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4448    (clobber (match_dup 4))])
4449    (set (match_dup 3)
4450         (compare:CC (match_dup 0)
4451                     (const_int 0)))]
4452   "")
4453
4454 (define_insn ""
4455   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4456         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4457                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4458                     (const_int 0)))
4459    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4460         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4461   "! TARGET_POWER"
4462   "@
4463    {sra|sraw}%I2. %0,%1,%h2
4464    #"
4465   [(set_attr "type" "delayed_compare")
4466    (set_attr "length" "4,8")])
4467 \f
4468 (define_split
4469   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4470         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4471                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4472                     (const_int 0)))
4473    (set (match_operand:SI 0 "gpc_reg_operand" "")
4474         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4475   "! TARGET_POWER && reload_completed"
4476   [(set (match_dup 0)
4477         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4478    (set (match_dup 3)
4479         (compare:CC (match_dup 0)
4480                     (const_int 0)))]
4481   "")
4482
4483 ;; Floating-point insns, excluding normal data motion.
4484 ;;
4485 ;; PowerPC has a full set of single-precision floating point instructions.
4486 ;;
4487 ;; For the POWER architecture, we pretend that we have both SFmode and
4488 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
4489 ;; The only conversions we will do will be when storing to memory.  In that
4490 ;; case, we will use the "frsp" instruction before storing.
4491 ;;
4492 ;; Note that when we store into a single-precision memory location, we need to
4493 ;; use the frsp insn first.  If the register being stored isn't dead, we
4494 ;; need a scratch register for the frsp.  But this is difficult when the store
4495 ;; is done by reload.  It is not incorrect to do the frsp on the register in
4496 ;; this case, we just lose precision that we would have otherwise gotten but
4497 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
4498
4499 (define_expand "extendsfdf2"
4500   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4501         (float_extend:DF (match_operand:SF 1 "reg_or_none500mem_operand" "")))]
4502   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4503   "")
4504
4505 (define_insn_and_split "*extendsfdf2_fpr"
4506   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,?f,f")
4507         (float_extend:DF (match_operand:SF 1 "reg_or_mem_operand" "0,f,m")))]
4508   "TARGET_HARD_FLOAT && TARGET_FPRS"
4509   "@
4510    #
4511    fmr %0,%1
4512    lfs%U1%X1 %0,%1"
4513   "&& reload_completed && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])"
4514   [(const_int 0)]
4515 {
4516   emit_note (NOTE_INSN_DELETED);
4517   DONE;
4518 }
4519   [(set_attr "type" "fp,fp,fpload")])
4520
4521 (define_expand "truncdfsf2"
4522   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4523         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "")))]
4524   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4525   "")
4526
4527 (define_insn "*truncdfsf2_fpr"
4528   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4529         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4530   "TARGET_HARD_FLOAT && TARGET_FPRS"
4531   "frsp %0,%1"
4532   [(set_attr "type" "fp")])
4533
4534 (define_insn "aux_truncdfsf2"
4535   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4536         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRSP))]
4537   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4538   "frsp %0,%1"
4539   [(set_attr "type" "fp")])
4540
4541 (define_expand "negsf2"
4542   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4543         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4544   "TARGET_HARD_FLOAT"
4545   "")
4546
4547 (define_insn "*negsf2"
4548   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4549         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4550   "TARGET_HARD_FLOAT && TARGET_FPRS"
4551   "fneg %0,%1"
4552   [(set_attr "type" "fp")])
4553
4554 (define_expand "abssf2"
4555   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4556         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4557   "TARGET_HARD_FLOAT"
4558   "")
4559
4560 (define_insn "*abssf2"
4561   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4562         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4563   "TARGET_HARD_FLOAT && TARGET_FPRS"
4564   "fabs %0,%1"
4565   [(set_attr "type" "fp")])
4566
4567 (define_insn ""
4568   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4569         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
4570   "TARGET_HARD_FLOAT && TARGET_FPRS"
4571   "fnabs %0,%1"
4572   [(set_attr "type" "fp")])
4573
4574 (define_expand "addsf3"
4575   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4576         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4577                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4578   "TARGET_HARD_FLOAT"
4579   "")
4580
4581 (define_insn ""
4582   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4583         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4584                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4585   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4586   "fadds %0,%1,%2"
4587   [(set_attr "type" "fp")])
4588
4589 (define_insn ""
4590   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4591         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4592                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4593   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4594   "{fa|fadd} %0,%1,%2"
4595   [(set_attr "type" "fp")])
4596
4597 (define_expand "subsf3"
4598   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4599         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4600                   (match_operand:SF 2 "gpc_reg_operand" "")))]
4601   "TARGET_HARD_FLOAT"
4602   "")
4603
4604 (define_insn ""
4605   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4606         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4607                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
4608   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4609   "fsubs %0,%1,%2"
4610   [(set_attr "type" "fp")])
4611
4612 (define_insn ""
4613   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4614         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4615                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
4616   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4617   "{fs|fsub} %0,%1,%2"
4618   [(set_attr "type" "fp")])
4619
4620 (define_expand "mulsf3"
4621   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4622         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
4623                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4624   "TARGET_HARD_FLOAT"
4625   "")
4626
4627 (define_insn ""
4628   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4629         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4630                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4631   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4632   "fmuls %0,%1,%2"
4633   [(set_attr "type" "fp")])
4634
4635 (define_insn ""
4636   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4637         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4638                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4639   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4640   "{fm|fmul} %0,%1,%2"
4641   [(set_attr "type" "dmul")])
4642
4643 (define_expand "divsf3"
4644   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4645         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
4646                 (match_operand:SF 2 "gpc_reg_operand" "")))]
4647   "TARGET_HARD_FLOAT"
4648   "")
4649
4650 (define_insn ""
4651   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4652         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4653                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
4654   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4655   "fdivs %0,%1,%2"
4656   [(set_attr "type" "sdiv")])
4657
4658 (define_insn ""
4659   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4660         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4661                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
4662   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4663   "{fd|fdiv} %0,%1,%2"
4664   [(set_attr "type" "ddiv")])
4665
4666 (define_insn ""
4667   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4668         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4669                           (match_operand:SF 2 "gpc_reg_operand" "f"))
4670                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
4671   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4672   "fmadds %0,%1,%2,%3"
4673   [(set_attr "type" "fp")])
4674
4675 (define_insn ""
4676   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4677         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4678                           (match_operand:SF 2 "gpc_reg_operand" "f"))
4679                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
4680   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4681   "{fma|fmadd} %0,%1,%2,%3"
4682   [(set_attr "type" "dmul")])
4683
4684 (define_insn ""
4685   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4686         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4687                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4688                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
4689   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4690   "fmsubs %0,%1,%2,%3"
4691   [(set_attr "type" "fp")])
4692
4693 (define_insn ""
4694   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4695         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4696                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4697                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
4698   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4699   "{fms|fmsub} %0,%1,%2,%3"
4700   [(set_attr "type" "dmul")])
4701
4702 (define_insn ""
4703   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4704         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4705                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
4706                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4707   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4708    && HONOR_SIGNED_ZEROS (SFmode)"
4709   "fnmadds %0,%1,%2,%3"
4710   [(set_attr "type" "fp")])
4711
4712 (define_insn ""
4713   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4714         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
4715                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4716                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4717   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4718    && ! HONOR_SIGNED_ZEROS (SFmode)"
4719   "fnmadds %0,%1,%2,%3"
4720   [(set_attr "type" "fp")])
4721
4722 (define_insn ""
4723   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4724         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4725                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
4726                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4727   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4728   "{fnma|fnmadd} %0,%1,%2,%3"
4729   [(set_attr "type" "dmul")])
4730
4731 (define_insn ""
4732   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4733         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
4734                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4735                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4736   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4737    && ! HONOR_SIGNED_ZEROS (SFmode)"
4738   "{fnma|fnmadd} %0,%1,%2,%3"
4739   [(set_attr "type" "dmul")])
4740
4741 (define_insn ""
4742   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4743         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4744                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
4745                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4746   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4747    && HONOR_SIGNED_ZEROS (SFmode)"
4748   "fnmsubs %0,%1,%2,%3"
4749   [(set_attr "type" "fp")])
4750
4751 (define_insn ""
4752   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4753         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
4754                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4755                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
4756   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4757    && ! HONOR_SIGNED_ZEROS (SFmode)"
4758   "fnmsubs %0,%1,%2,%3"
4759   [(set_attr "type" "fp")])
4760
4761 (define_insn ""
4762   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4763         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4764                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
4765                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4766   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4767   "{fnms|fnmsub} %0,%1,%2,%3"
4768   [(set_attr "type" "dmul")])
4769
4770 (define_insn ""
4771   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4772         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
4773                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4774                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
4775   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4776    && ! HONOR_SIGNED_ZEROS (SFmode)"
4777   "{fnms|fnmsub} %0,%1,%2,%3"
4778   [(set_attr "type" "fp")])
4779
4780 (define_expand "sqrtsf2"
4781   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4782         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4783   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
4784   "")
4785
4786 (define_insn ""
4787   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4788         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4789   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4790   "fsqrts %0,%1"
4791   [(set_attr "type" "ssqrt")])
4792
4793 (define_insn ""
4794   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4795         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4796   "TARGET_POWER2 && TARGET_HARD_FLOAT && TARGET_FPRS"
4797   "fsqrt %0,%1"
4798   [(set_attr "type" "dsqrt")])
4799
4800 (define_expand "copysignsf3"
4801   [(set (match_dup 3)
4802         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))
4803    (set (match_dup 4)
4804         (neg:SF (abs:SF (match_dup 1))))
4805    (set (match_operand:SF 0 "gpc_reg_operand" "")
4806         (if_then_else:SF (ge (match_operand:SF 2 "gpc_reg_operand" "")
4807                              (match_dup 5))
4808                          (match_dup 3)
4809                          (match_dup 4)))]
4810   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS
4811    && !HONOR_NANS (SFmode) && !HONOR_SIGNED_ZEROS (SFmode)" 
4812   {
4813      operands[3] = gen_reg_rtx (SFmode);
4814      operands[4] = gen_reg_rtx (SFmode);
4815      operands[5] = CONST0_RTX (SFmode);
4816   })
4817
4818 (define_expand "copysigndf3"
4819   [(set (match_dup 3)
4820         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))
4821    (set (match_dup 4)
4822         (neg:DF (abs:DF (match_dup 1))))
4823    (set (match_operand:DF 0 "gpc_reg_operand" "")
4824         (if_then_else:DF (ge (match_operand:DF 2 "gpc_reg_operand" "")
4825                              (match_dup 5))
4826                          (match_dup 3)
4827                          (match_dup 4)))]
4828   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS
4829    && !HONOR_NANS (DFmode) && !HONOR_SIGNED_ZEROS (DFmode)"
4830   {
4831      operands[3] = gen_reg_rtx (DFmode);
4832      operands[4] = gen_reg_rtx (DFmode);
4833      operands[5] = CONST0_RTX (DFmode);
4834   })
4835
4836 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
4837 ;; fsel instruction and some auxiliary computations.  Then we just have a
4838 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
4839 ;; combine.
4840 (define_expand "smaxsf3"
4841   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4842         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
4843                              (match_operand:SF 2 "gpc_reg_operand" ""))
4844                          (match_dup 1)
4845                          (match_dup 2)))]
4846   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
4847   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
4848
4849 (define_expand "sminsf3"
4850   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4851         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
4852                              (match_operand:SF 2 "gpc_reg_operand" ""))
4853                          (match_dup 2)
4854                          (match_dup 1)))]
4855   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
4856   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
4857
4858 (define_split
4859   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4860         (match_operator:SF 3 "min_max_operator"
4861          [(match_operand:SF 1 "gpc_reg_operand" "")
4862           (match_operand:SF 2 "gpc_reg_operand" "")]))]
4863   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
4864   [(const_int 0)]
4865   "
4866 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
4867                       operands[1], operands[2]);
4868   DONE;
4869 }")
4870
4871 (define_expand "movsicc"
4872    [(set (match_operand:SI 0 "gpc_reg_operand" "")
4873          (if_then_else:SI (match_operand 1 "comparison_operator" "")
4874                           (match_operand:SI 2 "gpc_reg_operand" "")
4875                           (match_operand:SI 3 "gpc_reg_operand" "")))]
4876   "TARGET_ISEL"
4877   "
4878 {
4879   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4880     DONE;
4881   else
4882     FAIL;
4883 }")
4884
4885 ;; We use the BASE_REGS for the isel input operands because, if rA is
4886 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
4887 ;; because we may switch the operands and rB may end up being rA.
4888 ;;
4889 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
4890 ;; leave out the mode in operand 4 and use one pattern, but reload can
4891 ;; change the mode underneath our feet and then gets confused trying
4892 ;; to reload the value.
4893 (define_insn "isel_signed"
4894   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4895         (if_then_else:SI
4896          (match_operator 1 "comparison_operator"
4897                          [(match_operand:CC 4 "cc_reg_operand" "y")
4898                           (const_int 0)])
4899          (match_operand:SI 2 "gpc_reg_operand" "b")
4900          (match_operand:SI 3 "gpc_reg_operand" "b")))]
4901   "TARGET_ISEL"
4902   "*
4903 { return output_isel (operands); }"
4904   [(set_attr "length" "4")])
4905
4906 (define_insn "isel_unsigned"
4907   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4908         (if_then_else:SI
4909          (match_operator 1 "comparison_operator"
4910                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
4911                           (const_int 0)])
4912          (match_operand:SI 2 "gpc_reg_operand" "b")
4913          (match_operand:SI 3 "gpc_reg_operand" "b")))]
4914   "TARGET_ISEL"
4915   "*
4916 { return output_isel (operands); }"
4917   [(set_attr "length" "4")])
4918
4919 (define_expand "movsfcc"
4920    [(set (match_operand:SF 0 "gpc_reg_operand" "")
4921          (if_then_else:SF (match_operand 1 "comparison_operator" "")
4922                           (match_operand:SF 2 "gpc_reg_operand" "")
4923                           (match_operand:SF 3 "gpc_reg_operand" "")))]
4924   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4925   "
4926 {
4927   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4928     DONE;
4929   else
4930     FAIL;
4931 }")
4932
4933 (define_insn "*fselsfsf4"
4934   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4935         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
4936                              (match_operand:SF 4 "zero_fp_constant" "F"))
4937                          (match_operand:SF 2 "gpc_reg_operand" "f")
4938                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4939   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4940   "fsel %0,%1,%2,%3"
4941   [(set_attr "type" "fp")])
4942
4943 (define_insn "*fseldfsf4"
4944   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4945         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
4946                              (match_operand:DF 4 "zero_fp_constant" "F"))
4947                          (match_operand:SF 2 "gpc_reg_operand" "f")
4948                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4949   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4950   "fsel %0,%1,%2,%3"
4951   [(set_attr "type" "fp")])
4952
4953 (define_expand "negdf2"
4954   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4955         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
4956   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4957   "")
4958
4959 (define_insn "*negdf2_fpr"
4960   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4961         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4962   "TARGET_HARD_FLOAT && TARGET_FPRS"
4963   "fneg %0,%1"
4964   [(set_attr "type" "fp")])
4965
4966 (define_expand "absdf2"
4967   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4968         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
4969   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4970   "")
4971
4972 (define_insn "*absdf2_fpr"
4973   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4974         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4975   "TARGET_HARD_FLOAT && TARGET_FPRS"
4976   "fabs %0,%1"
4977   [(set_attr "type" "fp")])
4978
4979 (define_insn "*nabsdf2_fpr"
4980   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4981         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f"))))]
4982   "TARGET_HARD_FLOAT && TARGET_FPRS"
4983   "fnabs %0,%1"
4984   [(set_attr "type" "fp")])
4985
4986 (define_expand "adddf3"
4987   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4988         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "")
4989                  (match_operand:DF 2 "gpc_reg_operand" "")))]
4990   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4991   "")
4992
4993 (define_insn "*adddf3_fpr"
4994   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4995         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4996                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
4997   "TARGET_HARD_FLOAT && TARGET_FPRS"
4998   "{fa|fadd} %0,%1,%2"
4999   [(set_attr "type" "fp")])
5000
5001 (define_expand "subdf3"
5002   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5003         (minus: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 "*subdf3_fpr"
5009   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5010         (minus: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   "{fs|fsub} %0,%1,%2"
5014   [(set_attr "type" "fp")])
5015
5016 (define_expand "muldf3"
5017   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5018         (mult: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 "*muldf3_fpr"
5024   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5025         (mult: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   "{fm|fmul} %0,%1,%2"
5029   [(set_attr "type" "dmul")])
5030
5031 (define_expand "divdf3"
5032   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5033         (div: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 "*divdf3_fpr"
5039   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5040         (div: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   "{fd|fdiv} %0,%1,%2"
5044   [(set_attr "type" "ddiv")])
5045
5046 (define_insn ""
5047   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5048         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5049                           (match_operand:DF 2 "gpc_reg_operand" "f"))
5050                  (match_operand:DF 3 "gpc_reg_operand" "f")))]
5051   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5052   "{fma|fmadd} %0,%1,%2,%3"
5053   [(set_attr "type" "dmul")])
5054
5055 (define_insn ""
5056   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5057         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5058                            (match_operand:DF 2 "gpc_reg_operand" "f"))
5059                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
5060   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5061   "{fms|fmsub} %0,%1,%2,%3"
5062   [(set_attr "type" "dmul")])
5063
5064 (define_insn ""
5065   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5066         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5067                                   (match_operand:DF 2 "gpc_reg_operand" "f"))
5068                          (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5069   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5070    && HONOR_SIGNED_ZEROS (DFmode)"
5071   "{fnma|fnmadd} %0,%1,%2,%3"
5072   [(set_attr "type" "dmul")])
5073
5074 (define_insn ""
5075   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5076         (minus:DF (mult:DF (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f"))
5077                            (match_operand:DF 2 "gpc_reg_operand" "f"))
5078                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
5079   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5080    && ! HONOR_SIGNED_ZEROS (DFmode)"
5081   "{fnma|fnmadd} %0,%1,%2,%3"
5082   [(set_attr "type" "dmul")])
5083
5084 (define_insn ""
5085   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5086         (neg:DF (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    && HONOR_SIGNED_ZEROS (DFmode)"
5091   "{fnms|fnmsub} %0,%1,%2,%3"
5092   [(set_attr "type" "dmul")])
5093
5094 (define_insn ""
5095   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5096         (minus:DF (match_operand:DF 3 "gpc_reg_operand" "f")
5097                   (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5098                            (match_operand:DF 2 "gpc_reg_operand" "f"))))]
5099   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5100    && ! HONOR_SIGNED_ZEROS (DFmode)"
5101   "{fnms|fnmsub} %0,%1,%2,%3"
5102   [(set_attr "type" "dmul")])
5103
5104 (define_insn "sqrtdf2"
5105   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5106         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5107   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
5108   "fsqrt %0,%1"
5109   [(set_attr "type" "dsqrt")])
5110
5111 ;; The conditional move instructions allow us to perform max and min
5112 ;; operations even when
5113
5114 (define_expand "smaxdf3"
5115   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5116         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5117                              (match_operand:DF 2 "gpc_reg_operand" ""))
5118                          (match_dup 1)
5119                          (match_dup 2)))]
5120   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5121   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
5122
5123 (define_expand "smindf3"
5124   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5125         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5126                              (match_operand:DF 2 "gpc_reg_operand" ""))
5127                          (match_dup 2)
5128                          (match_dup 1)))]
5129   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5130   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
5131
5132 (define_split
5133   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5134         (match_operator:DF 3 "min_max_operator"
5135          [(match_operand:DF 1 "gpc_reg_operand" "")
5136           (match_operand:DF 2 "gpc_reg_operand" "")]))]
5137   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5138   [(const_int 0)]
5139   "
5140 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5141                       operands[1], operands[2]);
5142   DONE;
5143 }")
5144
5145 (define_expand "movdfcc"
5146    [(set (match_operand:DF 0 "gpc_reg_operand" "")
5147          (if_then_else:DF (match_operand 1 "comparison_operator" "")
5148                           (match_operand:DF 2 "gpc_reg_operand" "")
5149                           (match_operand:DF 3 "gpc_reg_operand" "")))]
5150   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5151   "
5152 {
5153   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5154     DONE;
5155   else
5156     FAIL;
5157 }")
5158
5159 (define_insn "*fseldfdf4"
5160   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5161         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
5162                              (match_operand:DF 4 "zero_fp_constant" "F"))
5163                          (match_operand:DF 2 "gpc_reg_operand" "f")
5164                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
5165   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5166   "fsel %0,%1,%2,%3"
5167   [(set_attr "type" "fp")])
5168
5169 (define_insn "*fselsfdf4"
5170   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5171         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5172                              (match_operand:SF 4 "zero_fp_constant" "F"))
5173                          (match_operand:DF 2 "gpc_reg_operand" "f")
5174                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
5175   "TARGET_PPC_GFXOPT"
5176   "fsel %0,%1,%2,%3"
5177   [(set_attr "type" "fp")])
5178 \f
5179 ;; Conversions to and from floating-point.
5180
5181 (define_expand "fixuns_truncsfsi2"
5182   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5183         (unsigned_fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
5184   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5185   "")
5186
5187 (define_expand "fix_truncsfsi2"
5188   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5189         (fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
5190   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5191   "")
5192
5193 ; For each of these conversions, there is a define_expand, a define_insn
5194 ; with a '#' template, and a define_split (with C code).  The idea is
5195 ; to allow constant folding with the template of the define_insn,
5196 ; then to have the insns split later (between sched1 and final).
5197
5198 (define_expand "floatsidf2"
5199   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5200                    (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5201               (use (match_dup 2))
5202               (use (match_dup 3))
5203               (clobber (match_dup 4))
5204               (clobber (match_dup 5))
5205               (clobber (match_dup 6))])]
5206   "TARGET_HARD_FLOAT && TARGET_FPRS"
5207   "
5208 {
5209   if (TARGET_E500_DOUBLE)
5210     {
5211       emit_insn (gen_spe_floatsidf2 (operands[0], operands[1]));
5212       DONE;
5213     }
5214   if (TARGET_POWERPC64)
5215     {
5216       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5217       rtx t1 = gen_reg_rtx (DImode);
5218       rtx t2 = gen_reg_rtx (DImode);
5219       emit_insn (gen_floatsidf_ppc64 (operands[0], operands[1], mem, t1, t2));
5220       DONE;
5221     }
5222
5223   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5224   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
5225   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5226   operands[5] = gen_reg_rtx (DFmode);
5227   operands[6] = gen_reg_rtx (SImode);
5228 }")
5229
5230 (define_insn_and_split "*floatsidf2_internal"
5231   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5232         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5233    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5234    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5235    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5236    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))
5237    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
5238   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5239   "#"
5240   "&& (!no_new_pseudos || offsettable_nonstrict_memref_p (operands[4]))"
5241   [(pc)]
5242   "
5243 {
5244   rtx lowword, highword;
5245   gcc_assert (MEM_P (operands[4]));
5246   highword = adjust_address (operands[4], SImode, 0);
5247   lowword = adjust_address (operands[4], SImode, 4);
5248   if (! WORDS_BIG_ENDIAN)
5249     {
5250       rtx tmp;
5251       tmp = highword; highword = lowword; lowword = tmp;
5252     }
5253
5254   emit_insn (gen_xorsi3 (operands[6], operands[1],
5255                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
5256   emit_move_insn (lowword, operands[6]);
5257   emit_move_insn (highword, operands[2]);
5258   emit_move_insn (operands[5], operands[4]);
5259   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5260   DONE;
5261 }"
5262   [(set_attr "length" "24")])
5263
5264 (define_expand "floatunssisf2"
5265   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5266         (unsigned_float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5267   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5268   "")
5269
5270 (define_expand "floatunssidf2"
5271   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5272                    (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5273               (use (match_dup 2))
5274               (use (match_dup 3))
5275               (clobber (match_dup 4))
5276               (clobber (match_dup 5))])]
5277   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5278   "
5279 {
5280   if (TARGET_E500_DOUBLE)
5281     {
5282       emit_insn (gen_spe_floatunssidf2 (operands[0], operands[1]));
5283       DONE;
5284     }
5285   if (TARGET_POWERPC64)
5286     {
5287       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5288       rtx t1 = gen_reg_rtx (DImode);
5289       rtx t2 = gen_reg_rtx (DImode);
5290       emit_insn (gen_floatunssidf_ppc64 (operands[0], operands[1], mem,
5291                                          t1, t2));
5292       DONE;
5293     }
5294
5295   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5296   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
5297   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5298   operands[5] = gen_reg_rtx (DFmode);
5299 }")
5300
5301 (define_insn_and_split "*floatunssidf2_internal"
5302   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5303         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5304    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5305    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5306    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5307    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))]
5308   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5309   "#"
5310   "&& (!no_new_pseudos || offsettable_nonstrict_memref_p (operands[4]))"
5311   [(pc)]
5312   "
5313 {
5314   rtx lowword, highword;
5315   gcc_assert (MEM_P (operands[4]));
5316   highword = adjust_address (operands[4], SImode, 0);
5317   lowword = adjust_address (operands[4], SImode, 4);
5318   if (! WORDS_BIG_ENDIAN)
5319     {
5320       rtx tmp;
5321       tmp = highword; highword = lowword; lowword = tmp;
5322     }
5323
5324   emit_move_insn (lowword, operands[1]);
5325   emit_move_insn (highword, operands[2]);
5326   emit_move_insn (operands[5], operands[4]);
5327   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5328   DONE;
5329 }"
5330   [(set_attr "length" "20")])
5331
5332 (define_expand "fix_truncdfsi2"
5333   [(parallel [(set (match_operand:SI 0 "fix_trunc_dest_operand" "")
5334                    (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5335               (clobber (match_dup 2))
5336               (clobber (match_dup 3))])]
5337   "(TARGET_POWER2 || TARGET_POWERPC)
5338    && TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5339   "
5340 {
5341   if (TARGET_E500_DOUBLE)
5342     {
5343      emit_insn (gen_spe_fix_truncdfsi2 (operands[0], operands[1]));
5344      DONE;
5345     }
5346   operands[2] = gen_reg_rtx (DImode);
5347   if (TARGET_PPC_GFXOPT)
5348     {
5349       rtx orig_dest = operands[0];
5350       if (! memory_operand (orig_dest, GET_MODE (orig_dest)))
5351         operands[0] = assign_stack_temp (SImode, GET_MODE_SIZE (SImode), 0);
5352       emit_insn (gen_fix_truncdfsi2_internal_gfxopt (operands[0], operands[1],
5353                                                      operands[2]));
5354       if (operands[0] != orig_dest)
5355         emit_move_insn (orig_dest, operands[0]);
5356       DONE;
5357     }
5358   operands[3] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5359 }")
5360
5361 (define_insn_and_split "*fix_truncdfsi2_internal"
5362   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5363         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5364    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))
5365    (clobber (match_operand:DI 3 "memory_operand" "=o"))]
5366   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5367   "#"
5368   "&& (!no_new_pseudos || offsettable_nonstrict_memref_p (operands[3]))"
5369   [(pc)]
5370   "
5371 {
5372   rtx lowword;
5373   gcc_assert (MEM_P (operands[3]));
5374   lowword = adjust_address (operands[3], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
5375
5376   emit_insn (gen_fctiwz (operands[2], operands[1]));
5377   emit_move_insn (operands[3], operands[2]);
5378   emit_move_insn (operands[0], lowword);
5379   DONE;
5380 }"
5381   [(set_attr "length" "16")])
5382
5383 (define_insn_and_split "fix_truncdfsi2_internal_gfxopt"
5384   [(set (match_operand:SI 0 "memory_operand" "=Z")
5385         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5386    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))]
5387   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS
5388    && TARGET_PPC_GFXOPT"
5389   "#"
5390   "&& 1"
5391   [(pc)]
5392   "
5393 {
5394   emit_insn (gen_fctiwz (operands[2], operands[1]));
5395   emit_insn (gen_stfiwx (operands[0], operands[2]));
5396   DONE;
5397 }"
5398   [(set_attr "length" "16")])
5399
5400 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
5401 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
5402 ; because the first makes it clear that operand 0 is not live
5403 ; before the instruction.
5404 (define_insn "fctiwz"
5405   [(set (match_operand:DI 0 "gpc_reg_operand" "=f")
5406         (unspec:DI [(fix:SI (match_operand:DF 1 "gpc_reg_operand" "f"))]
5407                    UNSPEC_FCTIWZ))]
5408   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5409   "{fcirz|fctiwz} %0,%1"
5410   [(set_attr "type" "fp")])
5411
5412 ; An UNSPEC is used so we don't have to support SImode in FP registers.
5413 (define_insn "stfiwx"
5414   [(set (match_operand:SI 0 "memory_operand" "=Z")
5415         (unspec:SI [(match_operand:DI 1 "gpc_reg_operand" "f")]
5416                    UNSPEC_STFIWX))]
5417   "TARGET_PPC_GFXOPT"
5418   "stfiwx %1,%y0"
5419   [(set_attr "type" "fpstore")])
5420
5421 (define_expand "floatsisf2"
5422   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5423         (float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5424   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5425   "")
5426
5427 (define_insn "floatdidf2"
5428   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5429         (float:DF (match_operand:DI 1 "gpc_reg_operand" "*f")))]
5430   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5431   "fcfid %0,%1"
5432   [(set_attr "type" "fp")])
5433
5434 (define_insn_and_split "floatsidf_ppc64"
5435   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5436         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5437    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5438    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5439    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5440   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5441   "#"
5442   "&& 1"
5443   [(set (match_dup 3) (sign_extend:DI (match_dup 1)))
5444    (set (match_dup 2) (match_dup 3))
5445    (set (match_dup 4) (match_dup 2))
5446    (set (match_dup 0) (float:DF (match_dup 4)))]
5447   "")
5448
5449 (define_insn_and_split "floatunssidf_ppc64"
5450   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5451         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5452    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5453    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5454    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5455   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5456   "#"
5457   "&& 1"
5458   [(set (match_dup 3) (zero_extend:DI (match_dup 1)))
5459    (set (match_dup 2) (match_dup 3))
5460    (set (match_dup 4) (match_dup 2))
5461    (set (match_dup 0) (float:DF (match_dup 4)))]
5462   "")
5463
5464 (define_insn "fix_truncdfdi2"
5465   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
5466         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "f")))]
5467   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5468   "fctidz %0,%1"
5469   [(set_attr "type" "fp")])
5470
5471 (define_expand "floatdisf2"
5472   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5473         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
5474   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5475   "
5476 {
5477   rtx val = operands[1];
5478   if (!flag_unsafe_math_optimizations)
5479     {
5480       rtx label = gen_label_rtx ();
5481       val = gen_reg_rtx (DImode);
5482       emit_insn (gen_floatdisf2_internal2 (val, operands[1], label));
5483       emit_label (label);
5484     }
5485   emit_insn (gen_floatdisf2_internal1 (operands[0], val));
5486   DONE;
5487 }")
5488
5489 ;; This is not IEEE compliant if rounding mode is "round to nearest".
5490 ;; If the DI->DF conversion is inexact, then it's possible to suffer
5491 ;; from double rounding.
5492 (define_insn_and_split "floatdisf2_internal1"
5493   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5494         (float:SF (match_operand:DI 1 "gpc_reg_operand" "*f")))
5495    (clobber (match_scratch:DF 2 "=f"))]
5496   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5497   "#"
5498   "&& reload_completed"
5499   [(set (match_dup 2)
5500         (float:DF (match_dup 1)))
5501    (set (match_dup 0)
5502         (float_truncate:SF (match_dup 2)))]
5503   "")
5504
5505 ;; Twiddles bits to avoid double rounding.
5506 ;; Bits that might be truncated when converting to DFmode are replaced
5507 ;; by a bit that won't be lost at that stage, but is below the SFmode
5508 ;; rounding position.
5509 (define_expand "floatdisf2_internal2"
5510   [(set (match_dup 3) (ashiftrt:DI (match_operand:DI 1 "" "")
5511                                    (const_int 53)))
5512    (parallel [(set (match_operand:DI 0 "" "") (and:DI (match_dup 1)
5513                                                       (const_int 2047)))
5514               (clobber (scratch:CC))])
5515    (set (match_dup 3) (plus:DI (match_dup 3)
5516                                (const_int 1)))
5517    (set (match_dup 0) (plus:DI (match_dup 0)
5518                                (const_int 2047)))
5519    (set (match_dup 4) (compare:CCUNS (match_dup 3)
5520                                      (const_int 3)))
5521    (set (match_dup 0) (ior:DI (match_dup 0)
5522                               (match_dup 1)))
5523    (parallel [(set (match_dup 0) (and:DI (match_dup 0)
5524                                          (const_int -2048)))
5525               (clobber (scratch:CC))])
5526    (set (pc) (if_then_else (geu (match_dup 4) (const_int 0))
5527                            (label_ref (match_operand:DI 2 "" ""))
5528                            (pc)))
5529    (set (match_dup 0) (match_dup 1))]
5530   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5531   "
5532 {
5533   operands[3] = gen_reg_rtx (DImode);
5534   operands[4] = gen_reg_rtx (CCUNSmode);
5535 }")
5536 \f
5537 ;; Define the DImode operations that can be done in a small number
5538 ;; of instructions.  The & constraints are to prevent the register
5539 ;; allocator from allocating registers that overlap with the inputs
5540 ;; (for example, having an input in 7,8 and an output in 6,7).  We
5541 ;; also allow for the output being the same as one of the inputs.
5542
5543 (define_insn "*adddi3_noppc64"
5544   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
5545         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
5546                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
5547   "! TARGET_POWERPC64"
5548   "*
5549 {
5550   if (WORDS_BIG_ENDIAN)
5551     return (GET_CODE (operands[2])) != CONST_INT
5552             ? \"{a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2\"
5553             : \"{ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1\";
5554   else
5555     return (GET_CODE (operands[2])) != CONST_INT
5556             ? \"{a|addc} %0,%1,%2\;{ae|adde} %L0,%L1,%L2\"
5557             : \"{ai|addic} %0,%1,%2\;{a%G2e|add%G2e} %L0,%L1\";
5558 }"
5559   [(set_attr "type" "two")
5560    (set_attr "length" "8")])
5561
5562 (define_insn "*subdi3_noppc64"
5563   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
5564         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
5565                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
5566   "! TARGET_POWERPC64"
5567   "*
5568 {
5569   if (WORDS_BIG_ENDIAN)
5570     return (GET_CODE (operands[1]) != CONST_INT)
5571             ? \"{sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1\"
5572             : \"{sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2\";
5573   else
5574     return (GET_CODE (operands[1]) != CONST_INT)
5575             ? \"{sf|subfc} %0,%2,%1\;{sfe|subfe} %L0,%L2,%L1\"
5576             : \"{sfi|subfic} %0,%2,%1\;{sf%G1e|subf%G1e} %L0,%L2\";
5577 }"
5578   [(set_attr "type" "two")
5579    (set_attr "length" "8")])
5580
5581 (define_insn "*negdi2_noppc64"
5582   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5583         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
5584   "! TARGET_POWERPC64"
5585   "*
5586 {
5587   return (WORDS_BIG_ENDIAN)
5588     ? \"{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1\"
5589     : \"{sfi|subfic} %0,%1,0\;{sfze|subfze} %L0,%L1\";
5590 }"
5591   [(set_attr "type" "two")
5592    (set_attr "length" "8")])
5593
5594 (define_expand "mulsidi3"
5595   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5596         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5597                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5598   "! TARGET_POWERPC64"
5599   "
5600 {
5601   if (! TARGET_POWER && ! TARGET_POWERPC)
5602     {
5603       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
5604       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
5605       emit_insn (gen_mull_call ());
5606       if (WORDS_BIG_ENDIAN)
5607         emit_move_insn (operands[0], gen_rtx_REG (DImode, 3));
5608       else
5609         {
5610           emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
5611                           gen_rtx_REG (SImode, 3));
5612           emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
5613                           gen_rtx_REG (SImode, 4));
5614         }
5615       DONE;
5616     }
5617   else if (TARGET_POWER)
5618     {
5619       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
5620       DONE;
5621     }
5622 }")
5623
5624 (define_insn "mulsidi3_mq"
5625   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5626         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5627                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
5628    (clobber (match_scratch:SI 3 "=q"))]
5629   "TARGET_POWER"
5630   "mul %0,%1,%2\;mfmq %L0"
5631   [(set_attr "type" "imul")
5632    (set_attr "length" "8")])
5633
5634 (define_insn "*mulsidi3_no_mq"
5635   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5636         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5637                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
5638   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
5639   "*
5640 {
5641   return (WORDS_BIG_ENDIAN)
5642     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
5643     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
5644 }"
5645   [(set_attr "type" "imul")
5646    (set_attr "length" "8")])
5647
5648 (define_split
5649   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5650         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5651                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5652   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
5653   [(set (match_dup 3)
5654         (truncate:SI
5655          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
5656                                (sign_extend:DI (match_dup 2)))
5657                       (const_int 32))))
5658    (set (match_dup 4)
5659         (mult:SI (match_dup 1)
5660                  (match_dup 2)))]
5661   "
5662 {
5663   int endian = (WORDS_BIG_ENDIAN == 0);
5664   operands[3] = operand_subword (operands[0], endian, 0, DImode);
5665   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
5666 }")
5667
5668 (define_expand "umulsidi3"
5669   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5670         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5671                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5672   "TARGET_POWERPC && ! TARGET_POWERPC64"
5673   "
5674 {
5675   if (TARGET_POWER)
5676     {
5677       emit_insn (gen_umulsidi3_mq (operands[0], operands[1], operands[2]));
5678       DONE;
5679     }
5680 }")
5681
5682 (define_insn "umulsidi3_mq"
5683   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5684         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5685                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
5686    (clobber (match_scratch:SI 3 "=q"))]
5687   "TARGET_POWERPC && TARGET_POWER"
5688   "*
5689 {
5690   return (WORDS_BIG_ENDIAN)
5691     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
5692     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
5693 }"
5694   [(set_attr "type" "imul")
5695    (set_attr "length" "8")])
5696
5697 (define_insn "*umulsidi3_no_mq"
5698   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5699         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5700                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
5701   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
5702   "*
5703 {
5704   return (WORDS_BIG_ENDIAN)
5705     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
5706     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
5707 }"
5708   [(set_attr "type" "imul")
5709    (set_attr "length" "8")])
5710
5711 (define_split
5712   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5713         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5714                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5715   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
5716   [(set (match_dup 3)
5717         (truncate:SI
5718          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
5719                                (zero_extend:DI (match_dup 2)))
5720                       (const_int 32))))
5721    (set (match_dup 4)
5722         (mult:SI (match_dup 1)
5723                  (match_dup 2)))]
5724   "
5725 {
5726   int endian = (WORDS_BIG_ENDIAN == 0);
5727   operands[3] = operand_subword (operands[0], endian, 0, DImode);
5728   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
5729 }")
5730
5731 (define_expand "smulsi3_highpart"
5732   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5733         (truncate:SI
5734          (lshiftrt:DI (mult:DI (sign_extend:DI
5735                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5736                                (sign_extend:DI
5737                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5738                       (const_int 32))))]
5739   ""
5740   "
5741 {
5742   if (! TARGET_POWER && ! TARGET_POWERPC)
5743     {
5744       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
5745       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
5746       emit_insn (gen_mulh_call ());
5747       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
5748       DONE;
5749     }
5750   else if (TARGET_POWER)
5751     {
5752       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
5753       DONE;
5754     }
5755 }")
5756
5757 (define_insn "smulsi3_highpart_mq"
5758   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5759         (truncate:SI
5760          (lshiftrt:DI (mult:DI (sign_extend:DI
5761                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5762                                (sign_extend:DI
5763                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5764                       (const_int 32))))
5765    (clobber (match_scratch:SI 3 "=q"))]
5766   "TARGET_POWER"
5767   "mul %0,%1,%2"
5768   [(set_attr "type" "imul")])
5769
5770 (define_insn "*smulsi3_highpart_no_mq"
5771   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5772         (truncate:SI
5773          (lshiftrt:DI (mult:DI (sign_extend:DI
5774                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5775                                (sign_extend:DI
5776                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5777                       (const_int 32))))]
5778   "TARGET_POWERPC && ! TARGET_POWER"
5779   "mulhw %0,%1,%2"
5780   [(set_attr "type" "imul")])
5781
5782 (define_expand "umulsi3_highpart"
5783   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5784         (truncate:SI
5785          (lshiftrt:DI (mult:DI (zero_extend:DI
5786                                 (match_operand:SI 1 "gpc_reg_operand" ""))
5787                                (zero_extend:DI
5788                                 (match_operand:SI 2 "gpc_reg_operand" "")))
5789                       (const_int 32))))]
5790   "TARGET_POWERPC"
5791   "
5792 {
5793   if (TARGET_POWER)
5794     {
5795       emit_insn (gen_umulsi3_highpart_mq (operands[0], operands[1], operands[2]));
5796       DONE;
5797     }
5798 }")
5799
5800 (define_insn "umulsi3_highpart_mq"
5801   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5802         (truncate:SI
5803          (lshiftrt:DI (mult:DI (zero_extend:DI
5804                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5805                                (zero_extend:DI
5806                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5807                       (const_int 32))))
5808    (clobber (match_scratch:SI 3 "=q"))]
5809   "TARGET_POWERPC && TARGET_POWER"
5810   "mulhwu %0,%1,%2"
5811   [(set_attr "type" "imul")])
5812
5813 (define_insn "*umulsi3_highpart_no_mq"
5814   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5815         (truncate:SI
5816          (lshiftrt:DI (mult:DI (zero_extend:DI
5817                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5818                                (zero_extend:DI
5819                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5820                       (const_int 32))))]
5821   "TARGET_POWERPC && ! TARGET_POWER"
5822   "mulhwu %0,%1,%2"
5823   [(set_attr "type" "imul")])
5824
5825 ;; If operands 0 and 2 are in the same register, we have a problem.  But
5826 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
5827 ;; why we have the strange constraints below.
5828 (define_insn "ashldi3_power"
5829   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
5830         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
5831                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
5832    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
5833   "TARGET_POWER"
5834   "@
5835    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
5836    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
5837    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
5838    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
5839   [(set_attr "length" "8")])
5840
5841 (define_insn "lshrdi3_power"
5842   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
5843         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
5844                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
5845    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
5846   "TARGET_POWER"
5847   "@
5848    {s%A2i|s%A2wi} %L0,%1,%h2\;{cal %0,0(0)|li %0,0}
5849    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
5850    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
5851    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
5852   [(set_attr "length" "8")])
5853
5854 ;; Shift by a variable amount is too complex to be worth open-coding.  We
5855 ;; just handle shifts by constants.
5856 (define_insn "ashrdi3_power"
5857   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5858         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5859                      (match_operand:SI 2 "const_int_operand" "M,i")))
5860    (clobber (match_scratch:SI 3 "=X,q"))]
5861   "TARGET_POWER"
5862   "@
5863    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
5864    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
5865   [(set_attr "length" "8")])
5866
5867 (define_insn "ashrdi3_no_power"
5868   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
5869         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5870                      (match_operand:SI 2 "const_int_operand" "M,i")))]
5871   "TARGET_32BIT && !TARGET_POWERPC64 && !TARGET_POWER && WORDS_BIG_ENDIAN"
5872   "@
5873    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
5874    {sri|srwi} %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;{srai|srawi} %0,%1,%h2"
5875   [(set_attr "type" "two,three")
5876    (set_attr "length" "8,12")])
5877
5878 (define_insn "*ashrdisi3_noppc64"
5879   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5880         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
5881                                 (const_int 32)) 4))]
5882   "TARGET_32BIT && !TARGET_POWERPC64"
5883   "*
5884 {
5885   if (REGNO (operands[0]) == REGNO (operands[1]))
5886     return \"\";
5887   else
5888     return \"mr %0,%1\";
5889 }"
5890    [(set_attr "length" "4")])
5891
5892 \f
5893 ;; PowerPC64 DImode operations.
5894
5895 (define_insn_and_split "absdi2"
5896   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5897         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
5898    (clobber (match_scratch:DI 2 "=&r,&r"))]
5899   "TARGET_POWERPC64"
5900   "#"
5901   "&& reload_completed"
5902   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
5903    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
5904    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
5905   "")
5906
5907 (define_insn_and_split "*nabsdi2"
5908   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5909         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
5910    (clobber (match_scratch:DI 2 "=&r,&r"))]
5911   "TARGET_POWERPC64"
5912   "#"
5913   "&& reload_completed"
5914   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
5915    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
5916    (set (match_dup 0) (minus:DI (match_dup 2) (match_dup 0)))]
5917   "")
5918
5919 (define_insn "muldi3"
5920   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5921         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
5922                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
5923   "TARGET_POWERPC64"
5924   "mulld %0,%1,%2"
5925    [(set_attr "type" "lmul")])
5926
5927 (define_insn "*muldi3_internal1"
5928   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5929         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
5930                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
5931                     (const_int 0)))
5932    (clobber (match_scratch:DI 3 "=r,r"))]
5933   "TARGET_POWERPC64"
5934   "@
5935    mulld. %3,%1,%2
5936    #"
5937   [(set_attr "type" "lmul_compare")
5938    (set_attr "length" "4,8")])
5939
5940 (define_split
5941   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5942         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
5943                              (match_operand:DI 2 "gpc_reg_operand" ""))
5944                     (const_int 0)))
5945    (clobber (match_scratch:DI 3 ""))]
5946   "TARGET_POWERPC64 && reload_completed"
5947   [(set (match_dup 3)
5948         (mult:DI (match_dup 1) (match_dup 2)))
5949    (set (match_dup 0)
5950         (compare:CC (match_dup 3)
5951                     (const_int 0)))]
5952   "")
5953
5954 (define_insn "*muldi3_internal2"
5955   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
5956         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
5957                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
5958                     (const_int 0)))
5959    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5960         (mult:DI (match_dup 1) (match_dup 2)))]
5961   "TARGET_POWERPC64"
5962   "@
5963    mulld. %0,%1,%2
5964    #"
5965   [(set_attr "type" "lmul_compare")
5966    (set_attr "length" "4,8")])
5967
5968 (define_split
5969   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5970         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
5971                              (match_operand:DI 2 "gpc_reg_operand" ""))
5972                     (const_int 0)))
5973    (set (match_operand:DI 0 "gpc_reg_operand" "")
5974         (mult:DI (match_dup 1) (match_dup 2)))]
5975   "TARGET_POWERPC64 && reload_completed"
5976   [(set (match_dup 0)
5977         (mult:DI (match_dup 1) (match_dup 2)))
5978    (set (match_dup 3)
5979         (compare:CC (match_dup 0)
5980                     (const_int 0)))]
5981   "")
5982
5983 (define_insn "smuldi3_highpart"
5984   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5985         (truncate:DI
5986          (lshiftrt:TI (mult:TI (sign_extend:TI
5987                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
5988                                (sign_extend:TI
5989                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
5990                       (const_int 64))))]
5991   "TARGET_POWERPC64"
5992   "mulhd %0,%1,%2"
5993   [(set_attr "type" "lmul")])
5994
5995 (define_insn "umuldi3_highpart"
5996   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5997         (truncate:DI
5998          (lshiftrt:TI (mult:TI (zero_extend:TI
5999                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6000                                (zero_extend:TI
6001                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6002                       (const_int 64))))]
6003   "TARGET_POWERPC64"
6004   "mulhdu %0,%1,%2"
6005   [(set_attr "type" "lmul")])
6006
6007 (define_expand "divdi3"
6008   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6009         (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6010                 (match_operand:DI 2 "reg_or_cint_operand" "")))]
6011   "TARGET_POWERPC64"
6012   "
6013 {
6014   if (GET_CODE (operands[2]) == CONST_INT
6015       && INTVAL (operands[2]) > 0
6016       && exact_log2 (INTVAL (operands[2])) >= 0)
6017     ;
6018   else
6019     operands[2] = force_reg (DImode, operands[2]);
6020 }")
6021
6022 (define_expand "moddi3"
6023   [(use (match_operand:DI 0 "gpc_reg_operand" ""))
6024    (use (match_operand:DI 1 "gpc_reg_operand" ""))
6025    (use (match_operand:DI 2 "reg_or_cint_operand" ""))]
6026   "TARGET_POWERPC64"
6027   "
6028 {
6029   int i;
6030   rtx temp1;
6031   rtx temp2;
6032
6033   if (GET_CODE (operands[2]) != CONST_INT
6034       || INTVAL (operands[2]) <= 0
6035       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
6036     FAIL;
6037
6038   temp1 = gen_reg_rtx (DImode);
6039   temp2 = gen_reg_rtx (DImode);
6040
6041   emit_insn (gen_divdi3 (temp1, operands[1], operands[2]));
6042   emit_insn (gen_ashldi3 (temp2, temp1, GEN_INT (i)));
6043   emit_insn (gen_subdi3 (operands[0], operands[1], temp2));
6044   DONE;
6045 }")
6046
6047 (define_insn ""
6048   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6049         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6050                 (match_operand:DI 2 "exact_log2_cint_operand" "N")))]
6051   "TARGET_POWERPC64"
6052   "sradi %0,%1,%p2\;addze %0,%0"
6053   [(set_attr "type" "two")
6054    (set_attr "length" "8")])
6055
6056 (define_insn ""
6057   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6058         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6059                             (match_operand:DI 2 "exact_log2_cint_operand" "N,N"))
6060                     (const_int 0)))
6061    (clobber (match_scratch:DI 3 "=r,r"))]
6062   "TARGET_64BIT"
6063   "@
6064    sradi %3,%1,%p2\;addze. %3,%3
6065    #"
6066   [(set_attr "type" "compare")
6067    (set_attr "length" "8,12")])
6068
6069 (define_split
6070   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6071         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6072                             (match_operand:DI 2 "exact_log2_cint_operand" ""))
6073                     (const_int 0)))
6074    (clobber (match_scratch:DI 3 ""))]
6075   "TARGET_POWERPC64 && reload_completed"
6076   [(set (match_dup 3)
6077         (div:DI (match_dup 1) (match_dup 2)))
6078    (set (match_dup 0)
6079         (compare:CC (match_dup 3)
6080                     (const_int 0)))]
6081   "")
6082
6083 (define_insn ""
6084   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6085         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6086                             (match_operand:DI 2 "exact_log2_cint_operand" "N,N"))
6087                     (const_int 0)))
6088    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6089         (div:DI (match_dup 1) (match_dup 2)))]
6090   "TARGET_64BIT"
6091   "@
6092    sradi %0,%1,%p2\;addze. %0,%0
6093    #"
6094   [(set_attr "type" "compare")
6095    (set_attr "length" "8,12")])
6096
6097 (define_split
6098   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6099         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6100                             (match_operand:DI 2 "exact_log2_cint_operand" ""))
6101                     (const_int 0)))
6102    (set (match_operand:DI 0 "gpc_reg_operand" "")
6103         (div:DI (match_dup 1) (match_dup 2)))]
6104   "TARGET_POWERPC64 && reload_completed"
6105   [(set (match_dup 0)
6106         (div:DI (match_dup 1) (match_dup 2)))
6107    (set (match_dup 3)
6108         (compare:CC (match_dup 0)
6109                     (const_int 0)))]
6110   "")
6111
6112 (define_insn ""
6113   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6114         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6115                 (match_operand:DI 2 "gpc_reg_operand" "r")))]
6116   "TARGET_POWERPC64"
6117   "divd %0,%1,%2"
6118   [(set_attr "type" "ldiv")])
6119
6120 (define_insn "udivdi3"
6121   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6122         (udiv:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6123                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
6124   "TARGET_POWERPC64"
6125   "divdu %0,%1,%2"
6126   [(set_attr "type" "ldiv")])
6127
6128 (define_insn "rotldi3"
6129   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6130         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6131                    (match_operand:DI 2 "reg_or_cint_operand" "ri")))]
6132   "TARGET_POWERPC64"
6133   "rld%I2cl %0,%1,%H2,0")
6134
6135 (define_insn "*rotldi3_internal2"
6136   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6137         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6138                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6139                     (const_int 0)))
6140    (clobber (match_scratch:DI 3 "=r,r"))]
6141   "TARGET_64BIT"
6142   "@
6143    rld%I2cl. %3,%1,%H2,0
6144    #"
6145   [(set_attr "type" "delayed_compare")
6146    (set_attr "length" "4,8")])
6147
6148 (define_split
6149   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6150         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6151                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6152                     (const_int 0)))
6153    (clobber (match_scratch:DI 3 ""))]
6154   "TARGET_POWERPC64 && reload_completed"
6155   [(set (match_dup 3)
6156         (rotate:DI (match_dup 1) (match_dup 2)))
6157    (set (match_dup 0)
6158         (compare:CC (match_dup 3)
6159                     (const_int 0)))]
6160   "")
6161
6162 (define_insn "*rotldi3_internal3"
6163   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6164         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6165                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6166                     (const_int 0)))
6167    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6168         (rotate:DI (match_dup 1) (match_dup 2)))]
6169   "TARGET_64BIT"
6170   "@
6171    rld%I2cl. %0,%1,%H2,0
6172    #"
6173   [(set_attr "type" "delayed_compare")
6174    (set_attr "length" "4,8")])
6175
6176 (define_split
6177   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6178         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6179                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6180                     (const_int 0)))
6181    (set (match_operand:DI 0 "gpc_reg_operand" "")
6182         (rotate:DI (match_dup 1) (match_dup 2)))]
6183   "TARGET_POWERPC64 && reload_completed"
6184   [(set (match_dup 0)
6185         (rotate:DI (match_dup 1) (match_dup 2)))
6186    (set (match_dup 3)
6187         (compare:CC (match_dup 0)
6188                     (const_int 0)))]
6189   "")
6190
6191 (define_insn "*rotldi3_internal4"
6192   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6193         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6194                            (match_operand:DI 2 "reg_or_cint_operand" "ri"))
6195                 (match_operand:DI 3 "mask64_operand" "n")))]
6196   "TARGET_POWERPC64"
6197   "rld%I2c%B3 %0,%1,%H2,%S3")
6198
6199 (define_insn "*rotldi3_internal5"
6200   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6201         (compare:CC (and:DI
6202                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6203                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6204                      (match_operand:DI 3 "mask64_operand" "n,n"))
6205                     (const_int 0)))
6206    (clobber (match_scratch:DI 4 "=r,r"))]
6207   "TARGET_64BIT"
6208   "@
6209    rld%I2c%B3. %4,%1,%H2,%S3
6210    #"
6211   [(set_attr "type" "delayed_compare")
6212    (set_attr "length" "4,8")])
6213
6214 (define_split
6215   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6216         (compare:CC (and:DI
6217                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6218                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6219                      (match_operand:DI 3 "mask64_operand" ""))
6220                     (const_int 0)))
6221    (clobber (match_scratch:DI 4 ""))]
6222   "TARGET_POWERPC64 && reload_completed"
6223   [(set (match_dup 4)
6224         (and:DI (rotate:DI (match_dup 1)
6225                                 (match_dup 2))
6226                      (match_dup 3)))
6227    (set (match_dup 0)
6228         (compare:CC (match_dup 4)
6229                     (const_int 0)))]
6230   "")
6231
6232 (define_insn "*rotldi3_internal6"
6233   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6234         (compare:CC (and:DI
6235                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6236                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6237                      (match_operand:DI 3 "mask64_operand" "n,n"))
6238                     (const_int 0)))
6239    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6240         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6241   "TARGET_64BIT"
6242   "@
6243    rld%I2c%B3. %0,%1,%H2,%S3
6244    #"
6245   [(set_attr "type" "delayed_compare")
6246    (set_attr "length" "4,8")])
6247
6248 (define_split
6249   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6250         (compare:CC (and:DI
6251                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6252                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6253                      (match_operand:DI 3 "mask64_operand" ""))
6254                     (const_int 0)))
6255    (set (match_operand:DI 0 "gpc_reg_operand" "")
6256         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6257   "TARGET_POWERPC64 && reload_completed"
6258   [(set (match_dup 0)
6259         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
6260    (set (match_dup 4)
6261         (compare:CC (match_dup 0)
6262                     (const_int 0)))]
6263   "")
6264
6265 (define_insn "*rotldi3_internal7"
6266   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6267         (zero_extend:DI
6268          (subreg:QI
6269           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6270                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6271   "TARGET_POWERPC64"
6272   "rld%I2cl %0,%1,%H2,56")
6273
6274 (define_insn "*rotldi3_internal8"
6275   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6276         (compare:CC (zero_extend:DI
6277                      (subreg:QI
6278                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6279                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6280                     (const_int 0)))
6281    (clobber (match_scratch:DI 3 "=r,r"))]
6282   "TARGET_64BIT"
6283   "@
6284    rld%I2cl. %3,%1,%H2,56
6285    #"
6286   [(set_attr "type" "delayed_compare")
6287    (set_attr "length" "4,8")])
6288
6289 (define_split
6290   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6291         (compare:CC (zero_extend:DI
6292                      (subreg:QI
6293                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6294                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6295                     (const_int 0)))
6296    (clobber (match_scratch:DI 3 ""))]
6297   "TARGET_POWERPC64 && reload_completed"
6298   [(set (match_dup 3)
6299         (zero_extend:DI (subreg:QI
6300                       (rotate:DI (match_dup 1)
6301                                  (match_dup 2)) 0)))
6302    (set (match_dup 0)
6303         (compare:CC (match_dup 3)
6304                     (const_int 0)))]
6305   "")
6306
6307 (define_insn "*rotldi3_internal9"
6308   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6309         (compare:CC (zero_extend:DI
6310                      (subreg:QI
6311                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6312                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6313                     (const_int 0)))
6314    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6315         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6316   "TARGET_64BIT"
6317   "@
6318    rld%I2cl. %0,%1,%H2,56
6319    #"
6320   [(set_attr "type" "delayed_compare")
6321    (set_attr "length" "4,8")])
6322
6323 (define_split
6324   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6325         (compare:CC (zero_extend:DI
6326                      (subreg:QI
6327                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6328                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6329                     (const_int 0)))
6330    (set (match_operand:DI 0 "gpc_reg_operand" "")
6331         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6332   "TARGET_POWERPC64 && reload_completed"
6333   [(set (match_dup 0)
6334         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6335    (set (match_dup 3)
6336         (compare:CC (match_dup 0)
6337                     (const_int 0)))]
6338   "")
6339
6340 (define_insn "*rotldi3_internal10"
6341   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6342         (zero_extend:DI
6343          (subreg:HI
6344           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6345                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6346   "TARGET_POWERPC64"
6347   "rld%I2cl %0,%1,%H2,48")
6348
6349 (define_insn "*rotldi3_internal11"
6350   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6351         (compare:CC (zero_extend:DI
6352                      (subreg:HI
6353                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6354                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6355                     (const_int 0)))
6356    (clobber (match_scratch:DI 3 "=r,r"))]
6357   "TARGET_64BIT"
6358   "@
6359    rld%I2cl. %3,%1,%H2,48
6360    #"
6361   [(set_attr "type" "delayed_compare")
6362    (set_attr "length" "4,8")])
6363
6364 (define_split
6365   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6366         (compare:CC (zero_extend:DI
6367                      (subreg:HI
6368                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6369                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6370                     (const_int 0)))
6371    (clobber (match_scratch:DI 3 ""))]
6372   "TARGET_POWERPC64 && reload_completed"
6373   [(set (match_dup 3)
6374         (zero_extend:DI (subreg:HI
6375                       (rotate:DI (match_dup 1)
6376                                  (match_dup 2)) 0)))
6377    (set (match_dup 0)
6378         (compare:CC (match_dup 3)
6379                     (const_int 0)))]
6380   "")
6381
6382 (define_insn "*rotldi3_internal12"
6383   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6384         (compare:CC (zero_extend:DI
6385                      (subreg:HI
6386                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6387                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6388                     (const_int 0)))
6389    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6390         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6391   "TARGET_64BIT"
6392   "@
6393    rld%I2cl. %0,%1,%H2,48
6394    #"
6395   [(set_attr "type" "delayed_compare")
6396    (set_attr "length" "4,8")])
6397
6398 (define_split
6399   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6400         (compare:CC (zero_extend:DI
6401                      (subreg:HI
6402                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6403                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6404                     (const_int 0)))
6405    (set (match_operand:DI 0 "gpc_reg_operand" "")
6406         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6407   "TARGET_POWERPC64 && reload_completed"
6408   [(set (match_dup 0)
6409         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6410    (set (match_dup 3)
6411         (compare:CC (match_dup 0)
6412                     (const_int 0)))]
6413   "")
6414
6415 (define_insn "*rotldi3_internal13"
6416   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6417         (zero_extend:DI
6418          (subreg:SI
6419           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6420                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6421   "TARGET_POWERPC64"
6422   "rld%I2cl %0,%1,%H2,32")
6423
6424 (define_insn "*rotldi3_internal14"
6425   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6426         (compare:CC (zero_extend:DI
6427                      (subreg:SI
6428                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6429                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6430                     (const_int 0)))
6431    (clobber (match_scratch:DI 3 "=r,r"))]
6432   "TARGET_64BIT"
6433   "@
6434    rld%I2cl. %3,%1,%H2,32
6435    #"
6436   [(set_attr "type" "delayed_compare")
6437    (set_attr "length" "4,8")])
6438
6439 (define_split
6440   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6441         (compare:CC (zero_extend:DI
6442                      (subreg:SI
6443                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6444                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6445                     (const_int 0)))
6446    (clobber (match_scratch:DI 3 ""))]
6447   "TARGET_POWERPC64 && reload_completed"
6448   [(set (match_dup 3)
6449         (zero_extend:DI (subreg:SI
6450                       (rotate:DI (match_dup 1)
6451                                  (match_dup 2)) 0)))
6452    (set (match_dup 0)
6453         (compare:CC (match_dup 3)
6454                     (const_int 0)))]
6455   "")
6456
6457 (define_insn "*rotldi3_internal15"
6458   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6459         (compare:CC (zero_extend:DI
6460                      (subreg:SI
6461                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6462                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6463                     (const_int 0)))
6464    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6465         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6466   "TARGET_64BIT"
6467   "@
6468    rld%I2cl. %0,%1,%H2,32
6469    #"
6470   [(set_attr "type" "delayed_compare")
6471    (set_attr "length" "4,8")])
6472
6473 (define_split
6474   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6475         (compare:CC (zero_extend:DI
6476                      (subreg:SI
6477                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6478                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6479                     (const_int 0)))
6480    (set (match_operand:DI 0 "gpc_reg_operand" "")
6481         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6482   "TARGET_POWERPC64 && reload_completed"
6483   [(set (match_dup 0)
6484         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6485    (set (match_dup 3)
6486         (compare:CC (match_dup 0)
6487                     (const_int 0)))]
6488   "")
6489
6490 (define_expand "ashldi3"
6491   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6492         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6493                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
6494   "TARGET_POWERPC64 || TARGET_POWER"
6495   "
6496 {
6497   if (TARGET_POWERPC64)
6498     ;
6499   else if (TARGET_POWER)
6500     {
6501       emit_insn (gen_ashldi3_power (operands[0], operands[1], operands[2]));
6502       DONE;
6503     }
6504   else
6505     FAIL;
6506 }")
6507
6508 (define_insn "*ashldi3_internal1"
6509   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6510         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6511                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6512   "TARGET_POWERPC64"
6513   "sld%I2 %0,%1,%H2")
6514
6515 (define_insn "*ashldi3_internal2"
6516   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6517         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6518                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6519                     (const_int 0)))
6520    (clobber (match_scratch:DI 3 "=r,r"))]
6521   "TARGET_64BIT"
6522   "@
6523    sld%I2. %3,%1,%H2
6524    #"
6525   [(set_attr "type" "delayed_compare")
6526    (set_attr "length" "4,8")])
6527
6528 (define_split
6529   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6530         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6531                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6532                     (const_int 0)))
6533    (clobber (match_scratch:DI 3 ""))]
6534   "TARGET_POWERPC64 && reload_completed"
6535   [(set (match_dup 3)
6536         (ashift:DI (match_dup 1) (match_dup 2)))
6537    (set (match_dup 0)
6538         (compare:CC (match_dup 3)
6539                     (const_int 0)))]
6540   "")
6541
6542 (define_insn "*ashldi3_internal3"
6543   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6544         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6545                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6546                     (const_int 0)))
6547    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6548         (ashift:DI (match_dup 1) (match_dup 2)))]
6549   "TARGET_64BIT"
6550   "@
6551    sld%I2. %0,%1,%H2
6552    #"
6553   [(set_attr "type" "delayed_compare")
6554    (set_attr "length" "4,8")])
6555
6556 (define_split
6557   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6558         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6559                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6560                     (const_int 0)))
6561    (set (match_operand:DI 0 "gpc_reg_operand" "")
6562         (ashift:DI (match_dup 1) (match_dup 2)))]
6563   "TARGET_POWERPC64 && reload_completed"
6564   [(set (match_dup 0)
6565         (ashift:DI (match_dup 1) (match_dup 2)))
6566    (set (match_dup 3)
6567         (compare:CC (match_dup 0)
6568                     (const_int 0)))]
6569   "")
6570
6571 (define_insn "*ashldi3_internal4"
6572   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6573         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6574                            (match_operand:SI 2 "const_int_operand" "i"))
6575                 (match_operand:DI 3 "const_int_operand" "n")))]
6576   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
6577   "rldic %0,%1,%H2,%W3")
6578
6579 (define_insn "ashldi3_internal5"
6580   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6581         (compare:CC
6582          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6583                             (match_operand:SI 2 "const_int_operand" "i,i"))
6584                  (match_operand:DI 3 "const_int_operand" "n,n"))
6585          (const_int 0)))
6586    (clobber (match_scratch:DI 4 "=r,r"))]
6587   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6588   "@
6589    rldic. %4,%1,%H2,%W3
6590    #"
6591   [(set_attr "type" "delayed_compare")
6592    (set_attr "length" "4,8")])
6593
6594 (define_split
6595   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6596         (compare:CC
6597          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6598                             (match_operand:SI 2 "const_int_operand" ""))
6599                  (match_operand:DI 3 "const_int_operand" ""))
6600          (const_int 0)))
6601    (clobber (match_scratch:DI 4 ""))]
6602   "TARGET_POWERPC64 && reload_completed
6603    && includes_rldic_lshift_p (operands[2], operands[3])"
6604   [(set (match_dup 4)
6605         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6606                 (match_dup 3)))
6607    (set (match_dup 0)
6608         (compare:CC (match_dup 4)
6609                     (const_int 0)))]
6610   "")
6611
6612 (define_insn "*ashldi3_internal6"
6613   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6614         (compare:CC
6615          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6616                             (match_operand:SI 2 "const_int_operand" "i,i"))
6617                     (match_operand:DI 3 "const_int_operand" "n,n"))
6618          (const_int 0)))
6619    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6620         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6621   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6622   "@
6623    rldic. %0,%1,%H2,%W3
6624    #"
6625   [(set_attr "type" "delayed_compare")
6626    (set_attr "length" "4,8")])
6627
6628 (define_split
6629   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6630         (compare:CC
6631          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6632                             (match_operand:SI 2 "const_int_operand" ""))
6633                  (match_operand:DI 3 "const_int_operand" ""))
6634          (const_int 0)))
6635    (set (match_operand:DI 0 "gpc_reg_operand" "")
6636         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6637   "TARGET_POWERPC64 && reload_completed
6638    && includes_rldic_lshift_p (operands[2], operands[3])"
6639   [(set (match_dup 0)
6640         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6641                 (match_dup 3)))
6642    (set (match_dup 4)
6643         (compare:CC (match_dup 0)
6644                     (const_int 0)))]
6645   "")
6646
6647 (define_insn "*ashldi3_internal7"
6648   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6649         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6650                            (match_operand:SI 2 "const_int_operand" "i"))
6651                 (match_operand:DI 3 "mask64_operand" "n")))]
6652   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
6653   "rldicr %0,%1,%H2,%S3")
6654
6655 (define_insn "ashldi3_internal8"
6656   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6657         (compare:CC
6658          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6659                             (match_operand:SI 2 "const_int_operand" "i,i"))
6660                  (match_operand:DI 3 "mask64_operand" "n,n"))
6661          (const_int 0)))
6662    (clobber (match_scratch:DI 4 "=r,r"))]
6663   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
6664   "@
6665    rldicr. %4,%1,%H2,%S3
6666    #"
6667   [(set_attr "type" "delayed_compare")
6668    (set_attr "length" "4,8")])
6669
6670 (define_split
6671   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6672         (compare:CC
6673          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6674                             (match_operand:SI 2 "const_int_operand" ""))
6675                  (match_operand:DI 3 "mask64_operand" ""))
6676          (const_int 0)))
6677    (clobber (match_scratch:DI 4 ""))]
6678   "TARGET_POWERPC64 && reload_completed
6679    && includes_rldicr_lshift_p (operands[2], operands[3])"
6680   [(set (match_dup 4)
6681         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6682                 (match_dup 3)))
6683    (set (match_dup 0)
6684         (compare:CC (match_dup 4)
6685                     (const_int 0)))]
6686   "")
6687
6688 (define_insn "*ashldi3_internal9"
6689   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6690         (compare:CC
6691          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6692                             (match_operand:SI 2 "const_int_operand" "i,i"))
6693                     (match_operand:DI 3 "mask64_operand" "n,n"))
6694          (const_int 0)))
6695    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6696         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6697   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
6698   "@
6699    rldicr. %0,%1,%H2,%S3
6700    #"
6701   [(set_attr "type" "delayed_compare")
6702    (set_attr "length" "4,8")])
6703
6704 (define_split
6705   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6706         (compare:CC
6707          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6708                             (match_operand:SI 2 "const_int_operand" ""))
6709                  (match_operand:DI 3 "mask64_operand" ""))
6710          (const_int 0)))
6711    (set (match_operand:DI 0 "gpc_reg_operand" "")
6712         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6713   "TARGET_POWERPC64 && reload_completed
6714    && includes_rldicr_lshift_p (operands[2], operands[3])"
6715   [(set (match_dup 0)
6716         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6717                 (match_dup 3)))
6718    (set (match_dup 4)
6719         (compare:CC (match_dup 0)
6720                     (const_int 0)))]
6721   "")
6722
6723 (define_expand "lshrdi3"
6724   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6725         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6726                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
6727   "TARGET_POWERPC64 || TARGET_POWER"
6728   "
6729 {
6730   if (TARGET_POWERPC64)
6731     ;
6732   else if (TARGET_POWER)
6733     {
6734       emit_insn (gen_lshrdi3_power (operands[0], operands[1], operands[2]));
6735       DONE;
6736     }
6737   else
6738     FAIL;
6739 }")
6740
6741 (define_insn "*lshrdi3_internal1"
6742   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6743         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6744                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6745   "TARGET_POWERPC64"
6746   "srd%I2 %0,%1,%H2")
6747
6748 (define_insn "*lshrdi3_internal2"
6749   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6750         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6751                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6752                     (const_int 0)))
6753    (clobber (match_scratch:DI 3 "=r,r"))]
6754   "TARGET_64BIT "
6755   "@
6756    srd%I2. %3,%1,%H2
6757    #"
6758   [(set_attr "type" "delayed_compare")
6759    (set_attr "length" "4,8")])
6760
6761 (define_split
6762   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6763         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6764                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6765                     (const_int 0)))
6766    (clobber (match_scratch:DI 3 ""))]
6767   "TARGET_POWERPC64 && reload_completed"
6768   [(set (match_dup 3)
6769         (lshiftrt:DI (match_dup 1) (match_dup 2)))
6770    (set (match_dup 0)
6771         (compare:CC (match_dup 3)
6772                     (const_int 0)))]
6773   "")
6774
6775 (define_insn "*lshrdi3_internal3"
6776   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6777         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6778                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6779                     (const_int 0)))
6780    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6781         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
6782   "TARGET_64BIT"
6783   "@
6784    srd%I2. %0,%1,%H2
6785    #"
6786   [(set_attr "type" "delayed_compare")
6787    (set_attr "length" "4,8")])
6788
6789 (define_split
6790   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6791         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6792                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6793                     (const_int 0)))
6794    (set (match_operand:DI 0 "gpc_reg_operand" "")
6795         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
6796   "TARGET_POWERPC64 && reload_completed"
6797   [(set (match_dup 0)
6798         (lshiftrt:DI (match_dup 1) (match_dup 2)))
6799    (set (match_dup 3)
6800         (compare:CC (match_dup 0)
6801                     (const_int 0)))]
6802   "")
6803
6804 (define_expand "ashrdi3"
6805   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6806         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6807                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
6808   "WORDS_BIG_ENDIAN"
6809   "
6810 {
6811   if (TARGET_POWERPC64)
6812     ;
6813   else if (TARGET_POWER && GET_CODE (operands[2]) == CONST_INT)
6814     {
6815       emit_insn (gen_ashrdi3_power (operands[0], operands[1], operands[2]));
6816       DONE;
6817     }
6818   else if (TARGET_32BIT && GET_CODE (operands[2]) == CONST_INT
6819            && WORDS_BIG_ENDIAN)
6820     {
6821       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
6822       DONE;
6823     }
6824   else
6825     FAIL;
6826 }")
6827
6828 (define_insn "*ashrdi3_internal1"
6829   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6830         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6831                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6832   "TARGET_POWERPC64"
6833   "srad%I2 %0,%1,%H2")
6834
6835 (define_insn "*ashrdi3_internal2"
6836   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6837         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6838                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6839                     (const_int 0)))
6840    (clobber (match_scratch:DI 3 "=r,r"))]
6841   "TARGET_64BIT"
6842   "@
6843    srad%I2. %3,%1,%H2
6844    #"
6845   [(set_attr "type" "delayed_compare")
6846    (set_attr "length" "4,8")])
6847
6848 (define_split
6849   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6850         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6851                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6852                     (const_int 0)))
6853    (clobber (match_scratch:DI 3 ""))]
6854   "TARGET_POWERPC64 && reload_completed"
6855   [(set (match_dup 3)
6856         (ashiftrt:DI (match_dup 1) (match_dup 2)))
6857    (set (match_dup 0)
6858         (compare:CC (match_dup 3)
6859                     (const_int 0)))]
6860   "")
6861
6862 (define_insn "*ashrdi3_internal3"
6863   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6864         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6865                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6866                     (const_int 0)))
6867    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6868         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
6869   "TARGET_64BIT"
6870   "@
6871    srad%I2. %0,%1,%H2
6872    #"
6873   [(set_attr "type" "delayed_compare")
6874    (set_attr "length" "4,8")])
6875
6876 (define_split
6877   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6878         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6879                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
6880                     (const_int 0)))
6881    (set (match_operand:DI 0 "gpc_reg_operand" "")
6882         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
6883   "TARGET_POWERPC64 && reload_completed"
6884   [(set (match_dup 0)
6885         (ashiftrt:DI (match_dup 1) (match_dup 2)))
6886    (set (match_dup 3)
6887         (compare:CC (match_dup 0)
6888                     (const_int 0)))]
6889   "")
6890
6891 (define_insn "anddi3"
6892   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
6893         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r")
6894                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,K,J,t")))
6895    (clobber (match_scratch:CC 3 "=X,X,X,x,x,X"))]
6896   "TARGET_POWERPC64"
6897   "@
6898    and %0,%1,%2
6899    rldic%B2 %0,%1,0,%S2
6900    rlwinm %0,%1,0,%m2,%M2
6901    andi. %0,%1,%b2
6902    andis. %0,%1,%u2
6903    #"
6904   [(set_attr "type" "*,*,*,compare,compare,*")
6905    (set_attr "length" "4,4,4,4,4,8")])
6906
6907 (define_split
6908   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6909         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
6910                 (match_operand:DI 2 "mask64_2_operand" "")))
6911    (clobber (match_scratch:CC 3 ""))]
6912   "TARGET_POWERPC64
6913     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
6914     && !mask64_operand (operands[2], DImode)"
6915   [(set (match_dup 0)
6916         (and:DI (rotate:DI (match_dup 1)
6917                            (match_dup 4))
6918                 (match_dup 5)))
6919    (set (match_dup 0)
6920         (and:DI (rotate:DI (match_dup 0)
6921                            (match_dup 6))
6922                 (match_dup 7)))]
6923 {
6924   build_mask64_2_operands (operands[2], &operands[4]);
6925 })
6926
6927 (define_insn "*anddi3_internal2"
6928   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,??y,??y,?y")
6929         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
6930                             (match_operand:DI 2 "and64_2_operand" "r,S,K,J,t,r,S,K,J,t"))
6931                     (const_int 0)))
6932    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r"))
6933    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,x,x,X"))]
6934   "TARGET_64BIT"
6935   "@
6936    and. %3,%1,%2
6937    rldic%B2. %3,%1,0,%S2
6938    andi. %3,%1,%b2
6939    andis. %3,%1,%u2
6940    #
6941    #
6942    #
6943    #
6944    #
6945    #"
6946   [(set_attr "type" "compare,delayed_compare,compare,compare,delayed_compare,compare,compare,compare,compare,compare")
6947    (set_attr "length" "4,4,4,4,8,8,8,8,8,12")])
6948
6949 (define_split
6950   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6951         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
6952                             (match_operand:DI 2 "and64_operand" ""))
6953                     (const_int 0)))
6954    (clobber (match_scratch:DI 3 ""))
6955    (clobber (match_scratch:CC 4 ""))]
6956   "TARGET_POWERPC64 && reload_completed"
6957   [(parallel [(set (match_dup 3)
6958                    (and:DI (match_dup 1)
6959                            (match_dup 2)))
6960               (clobber (match_dup 4))])
6961    (set (match_dup 0)
6962         (compare:CC (match_dup 3)
6963                     (const_int 0)))]
6964   "")
6965
6966 (define_split
6967   [(set (match_operand:CC 0 "cc_reg_operand" "")
6968         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
6969                             (match_operand:DI 2 "mask64_2_operand" ""))
6970                     (const_int 0)))
6971    (clobber (match_scratch:DI 3 ""))
6972    (clobber (match_scratch:CC 4 ""))]
6973   "TARGET_POWERPC64 && reload_completed
6974     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
6975     && !mask64_operand (operands[2], DImode)"
6976   [(set (match_dup 3)
6977         (and:DI (rotate:DI (match_dup 1)
6978                            (match_dup 5))
6979                 (match_dup 6)))
6980    (parallel [(set (match_dup 0)
6981                    (compare:CC (and:DI (rotate:DI (match_dup 3)
6982                                                   (match_dup 7))
6983                                        (match_dup 8))
6984                                (const_int 0)))
6985               (clobber (match_dup 3))])]
6986   "
6987 {
6988   build_mask64_2_operands (operands[2], &operands[5]);
6989 }")
6990
6991 (define_insn "*anddi3_internal3"
6992   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,?y,?y,??y,??y,?y")
6993         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
6994                             (match_operand:DI 2 "and64_2_operand" "r,S,K,J,t,r,S,K,J,t"))
6995                     (const_int 0)))
6996    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
6997         (and:DI (match_dup 1) (match_dup 2)))
6998    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,x,x,X"))]
6999   "TARGET_64BIT"
7000   "@
7001    and. %0,%1,%2
7002    rldic%B2. %0,%1,0,%S2
7003    andi. %0,%1,%b2
7004    andis. %0,%1,%u2
7005    #
7006    #
7007    #
7008    #
7009    #
7010    #"
7011   [(set_attr "type" "compare,delayed_compare,compare,compare,delayed_compare,compare,compare,compare,compare,compare")
7012    (set_attr "length" "4,4,4,4,8,8,8,8,8,12")])
7013
7014 (define_split
7015   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7016         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7017                             (match_operand:DI 2 "and64_operand" ""))
7018                     (const_int 0)))
7019    (set (match_operand:DI 0 "gpc_reg_operand" "")
7020         (and:DI (match_dup 1) (match_dup 2)))
7021    (clobber (match_scratch:CC 4 ""))]
7022   "TARGET_POWERPC64 && reload_completed"
7023   [(parallel [(set (match_dup 0)
7024                     (and:DI (match_dup 1) (match_dup 2)))
7025                (clobber (match_dup 4))])
7026    (set (match_dup 3)
7027         (compare:CC (match_dup 0)
7028                     (const_int 0)))]
7029   "")
7030
7031 (define_split
7032   [(set (match_operand:CC 3 "cc_reg_operand" "")
7033         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7034                             (match_operand:DI 2 "mask64_2_operand" ""))
7035                     (const_int 0)))
7036    (set (match_operand:DI 0 "gpc_reg_operand" "")
7037         (and:DI (match_dup 1) (match_dup 2)))
7038    (clobber (match_scratch:CC 4 ""))]
7039   "TARGET_POWERPC64 && reload_completed
7040     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7041     && !mask64_operand (operands[2], DImode)"
7042   [(set (match_dup 0)
7043         (and:DI (rotate:DI (match_dup 1)
7044                            (match_dup 5))
7045                 (match_dup 6)))
7046    (parallel [(set (match_dup 3)
7047                    (compare:CC (and:DI (rotate:DI (match_dup 0)
7048                                                   (match_dup 7))
7049                                        (match_dup 8))
7050                                (const_int 0)))
7051               (set (match_dup 0)
7052                    (and:DI (rotate:DI (match_dup 0)
7053                                       (match_dup 7))
7054                            (match_dup 8)))])]
7055   "
7056 {
7057   build_mask64_2_operands (operands[2], &operands[5]);
7058 }")
7059
7060 (define_expand "iordi3"
7061   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7062         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
7063                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7064   "TARGET_POWERPC64"
7065   "
7066 {
7067   if (non_logical_cint_operand (operands[2], DImode))
7068     {
7069       HOST_WIDE_INT value;
7070       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7071                  ? operands[0] : gen_reg_rtx (DImode));
7072
7073       if (GET_CODE (operands[2]) == CONST_INT)
7074         {
7075           value = INTVAL (operands[2]);
7076           emit_insn (gen_iordi3 (tmp, operands[1],
7077                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7078         }
7079       else
7080         {
7081           value = CONST_DOUBLE_LOW (operands[2]);
7082           emit_insn (gen_iordi3 (tmp, operands[1],
7083                                  immed_double_const (value
7084                                                      & (~ (HOST_WIDE_INT) 0xffff),
7085                                                      0, DImode)));
7086         }
7087
7088       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7089       DONE;
7090     }
7091 }")
7092
7093 (define_expand "xordi3"
7094   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7095         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
7096                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7097   "TARGET_POWERPC64"
7098   "
7099 {
7100   if (non_logical_cint_operand (operands[2], DImode))
7101     {
7102       HOST_WIDE_INT value;
7103       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7104                  ? operands[0] : gen_reg_rtx (DImode));
7105
7106       if (GET_CODE (operands[2]) == CONST_INT)
7107         {
7108           value = INTVAL (operands[2]);
7109           emit_insn (gen_xordi3 (tmp, operands[1],
7110                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7111         }
7112       else
7113         {
7114           value = CONST_DOUBLE_LOW (operands[2]);
7115           emit_insn (gen_xordi3 (tmp, operands[1],
7116                                  immed_double_const (value
7117                                                      & (~ (HOST_WIDE_INT) 0xffff),
7118                                                      0, DImode)));
7119         }
7120
7121       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7122       DONE;
7123     }
7124 }")
7125
7126 (define_insn "*booldi3_internal1"
7127   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
7128         (match_operator:DI 3 "boolean_or_operator"
7129          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
7130           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
7131   "TARGET_POWERPC64"
7132   "@
7133    %q3 %0,%1,%2
7134    %q3i %0,%1,%b2
7135    %q3is %0,%1,%u2")
7136
7137 (define_insn "*booldi3_internal2"
7138   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7139         (compare:CC (match_operator:DI 4 "boolean_or_operator"
7140          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7141           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7142          (const_int 0)))
7143    (clobber (match_scratch:DI 3 "=r,r"))]
7144   "TARGET_64BIT"
7145   "@
7146    %q4. %3,%1,%2
7147    #"
7148   [(set_attr "type" "compare")
7149    (set_attr "length" "4,8")])
7150
7151 (define_split
7152   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7153         (compare:CC (match_operator:DI 4 "boolean_operator"
7154          [(match_operand:DI 1 "gpc_reg_operand" "")
7155           (match_operand:DI 2 "gpc_reg_operand" "")])
7156          (const_int 0)))
7157    (clobber (match_scratch:DI 3 ""))]
7158   "TARGET_POWERPC64 && reload_completed"
7159   [(set (match_dup 3) (match_dup 4))
7160    (set (match_dup 0)
7161         (compare:CC (match_dup 3)
7162                     (const_int 0)))]
7163   "")
7164
7165 (define_insn "*booldi3_internal3"
7166   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7167         (compare:CC (match_operator:DI 4 "boolean_operator"
7168          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7169           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7170          (const_int 0)))
7171    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7172         (match_dup 4))]
7173   "TARGET_64BIT"
7174   "@
7175    %q4. %0,%1,%2
7176    #"
7177   [(set_attr "type" "compare")
7178    (set_attr "length" "4,8")])
7179
7180 (define_split
7181   [(set (match_operand:CC 3 "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    (set (match_operand:DI 0 "gpc_reg_operand" "")
7187         (match_dup 4))]
7188   "TARGET_POWERPC64 && reload_completed"
7189   [(set (match_dup 0) (match_dup 4))
7190    (set (match_dup 3)
7191         (compare:CC (match_dup 0)
7192                     (const_int 0)))]
7193   "")
7194
7195 ;; Split a logical operation that we can't do in one insn into two insns,
7196 ;; each of which does one 16-bit part.  This is used by combine.
7197
7198 (define_split
7199   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7200         (match_operator:DI 3 "boolean_or_operator"
7201          [(match_operand:DI 1 "gpc_reg_operand" "")
7202           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
7203   "TARGET_POWERPC64"
7204   [(set (match_dup 0) (match_dup 4))
7205    (set (match_dup 0) (match_dup 5))]
7206 "
7207 {
7208   rtx i3,i4;
7209
7210   if (GET_CODE (operands[2]) == CONST_DOUBLE)
7211     {
7212       HOST_WIDE_INT value = CONST_DOUBLE_LOW (operands[2]);
7213       i3 = immed_double_const (value & (~ (HOST_WIDE_INT) 0xffff),
7214                                         0, DImode);
7215       i4 = GEN_INT (value & 0xffff);
7216     }
7217   else
7218     {
7219       i3 = GEN_INT (INTVAL (operands[2])
7220                              & (~ (HOST_WIDE_INT) 0xffff));
7221       i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
7222     }
7223   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7224                                 operands[1], i3);
7225   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7226                                 operands[0], i4);
7227 }")
7228
7229 (define_insn "*boolcdi3_internal1"
7230   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7231         (match_operator:DI 3 "boolean_operator"
7232          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7233           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
7234   "TARGET_POWERPC64"
7235   "%q3 %0,%2,%1")
7236
7237 (define_insn "*boolcdi3_internal2"
7238   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7239         (compare:CC (match_operator:DI 4 "boolean_operator"
7240          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7241           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7242          (const_int 0)))
7243    (clobber (match_scratch:DI 3 "=r,r"))]
7244   "TARGET_64BIT"
7245   "@
7246    %q4. %3,%2,%1
7247    #"
7248   [(set_attr "type" "compare")
7249    (set_attr "length" "4,8")])
7250
7251 (define_split
7252   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7253         (compare:CC (match_operator:DI 4 "boolean_operator"
7254          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7255           (match_operand:DI 2 "gpc_reg_operand" "")])
7256          (const_int 0)))
7257    (clobber (match_scratch:DI 3 ""))]
7258   "TARGET_POWERPC64 && reload_completed"
7259   [(set (match_dup 3) (match_dup 4))
7260    (set (match_dup 0)
7261         (compare:CC (match_dup 3)
7262                     (const_int 0)))]
7263   "")
7264
7265 (define_insn "*boolcdi3_internal3"
7266   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7267         (compare:CC (match_operator:DI 4 "boolean_operator"
7268          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7269           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7270          (const_int 0)))
7271    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7272         (match_dup 4))]
7273   "TARGET_64BIT"
7274   "@
7275    %q4. %0,%2,%1
7276    #"
7277   [(set_attr "type" "compare")
7278    (set_attr "length" "4,8")])
7279
7280 (define_split
7281   [(set (match_operand:CC 3 "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    (set (match_operand:DI 0 "gpc_reg_operand" "")
7287         (match_dup 4))]
7288   "TARGET_POWERPC64 && reload_completed"
7289   [(set (match_dup 0) (match_dup 4))
7290    (set (match_dup 3)
7291         (compare:CC (match_dup 0)
7292                     (const_int 0)))]
7293   "")
7294
7295 (define_insn "*boolccdi3_internal1"
7296   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7297         (match_operator:DI 3 "boolean_operator"
7298          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7299           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
7300   "TARGET_POWERPC64"
7301   "%q3 %0,%1,%2")
7302
7303 (define_insn "*boolccdi3_internal2"
7304   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7305         (compare:CC (match_operator:DI 4 "boolean_operator"
7306          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7307           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7308          (const_int 0)))
7309    (clobber (match_scratch:DI 3 "=r,r"))]
7310   "TARGET_64BIT"
7311   "@
7312    %q4. %3,%1,%2
7313    #"
7314   [(set_attr "type" "compare")
7315    (set_attr "length" "4,8")])
7316
7317 (define_split
7318   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7319         (compare:CC (match_operator:DI 4 "boolean_operator"
7320          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7321           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7322          (const_int 0)))
7323    (clobber (match_scratch:DI 3 ""))]
7324   "TARGET_POWERPC64 && reload_completed"
7325   [(set (match_dup 3) (match_dup 4))
7326    (set (match_dup 0)
7327         (compare:CC (match_dup 3)
7328                     (const_int 0)))]
7329   "")
7330
7331 (define_insn "*boolccdi3_internal3"
7332   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7333         (compare:CC (match_operator:DI 4 "boolean_operator"
7334          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7335           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7336          (const_int 0)))
7337    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7338         (match_dup 4))]
7339   "TARGET_64BIT"
7340   "@
7341    %q4. %0,%1,%2
7342    #"
7343   [(set_attr "type" "compare")
7344    (set_attr "length" "4,8")])
7345
7346 (define_split
7347   [(set (match_operand:CC 3 "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    (set (match_operand:DI 0 "gpc_reg_operand" "")
7353         (match_dup 4))]
7354   "TARGET_POWERPC64 && reload_completed"
7355   [(set (match_dup 0) (match_dup 4))
7356    (set (match_dup 3)
7357         (compare:CC (match_dup 0)
7358                     (const_int 0)))]
7359   "")
7360 \f
7361 ;; Now define ways of moving data around.
7362
7363 ;; Set up a register with a value from the GOT table
7364
7365 (define_expand "movsi_got"
7366   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7367         (unspec:SI [(match_operand:SI 1 "got_operand" "")
7368                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
7369   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7370   "
7371 {
7372   if (GET_CODE (operands[1]) == CONST)
7373     {
7374       rtx offset = const0_rtx;
7375       HOST_WIDE_INT value;
7376
7377       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
7378       value = INTVAL (offset);
7379       if (value != 0)
7380         {
7381           rtx tmp = (no_new_pseudos ? operands[0] : gen_reg_rtx (Pmode));
7382           emit_insn (gen_movsi_got (tmp, operands[1]));
7383           emit_insn (gen_addsi3 (operands[0], tmp, offset));
7384           DONE;
7385         }
7386     }
7387
7388   operands[2] = rs6000_got_register (operands[1]);
7389 }")
7390
7391 (define_insn "*movsi_got_internal"
7392   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7393         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7394                     (match_operand:SI 2 "gpc_reg_operand" "b")]
7395                    UNSPEC_MOVSI_GOT))]
7396   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7397   "{l|lwz} %0,%a1@got(%2)"
7398   [(set_attr "type" "load")])
7399
7400 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
7401 ;; didn't get allocated to a hard register.
7402 (define_split
7403   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7404         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7405                     (match_operand:SI 2 "memory_operand" "")]
7406                    UNSPEC_MOVSI_GOT))]
7407   "DEFAULT_ABI == ABI_V4
7408     && flag_pic == 1
7409     && (reload_in_progress || reload_completed)"
7410   [(set (match_dup 0) (match_dup 2))
7411    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
7412                                  UNSPEC_MOVSI_GOT))]
7413   "")
7414
7415 ;; For SI, we special-case integers that can't be loaded in one insn.  We
7416 ;; do the load 16-bits at a time.  We could do this by loading from memory,
7417 ;; and this is even supposed to be faster, but it is simpler not to get
7418 ;; integers in the TOC.
7419 (define_expand "movsi"
7420   [(set (match_operand:SI 0 "general_operand" "")
7421         (match_operand:SI 1 "any_operand" ""))]
7422   ""
7423   "{ rs6000_emit_move (operands[0], operands[1], SImode); DONE; }")
7424
7425 (define_insn "movsi_low"
7426   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7427         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7428                            (match_operand 2 "" ""))))]
7429   "TARGET_MACHO && ! TARGET_64BIT"
7430   "{l|lwz} %0,lo16(%2)(%1)"
7431   [(set_attr "type" "load")
7432    (set_attr "length" "4")])
7433
7434 (define_insn "*movsi_internal1"
7435   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h")
7436         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0"))]
7437   "gpc_reg_operand (operands[0], SImode)
7438    || gpc_reg_operand (operands[1], SImode)"
7439   "@
7440    mr %0,%1
7441    {cal|la} %0,%a1
7442    {l%U1%X1|lwz%U1%X1} %0,%1
7443    {st%U0%X0|stw%U0%X0} %1,%0
7444    {lil|li} %0,%1
7445    {liu|lis} %0,%v1
7446    #
7447    {cal|la} %0,%a1
7448    mf%1 %0
7449    mt%0 %1
7450    mt%0 %1
7451    mt%0 %1
7452    {cror 0,0,0|nop}"
7453   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*")
7454    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
7455
7456 ;; Split a load of a large constant into the appropriate two-insn
7457 ;; sequence.
7458
7459 (define_split
7460   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7461         (match_operand:SI 1 "const_int_operand" ""))]
7462   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
7463    && (INTVAL (operands[1]) & 0xffff) != 0"
7464   [(set (match_dup 0)
7465         (match_dup 2))
7466    (set (match_dup 0)
7467         (ior:SI (match_dup 0)
7468                 (match_dup 3)))]
7469   "
7470 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
7471
7472   if (tem == operands[0])
7473     DONE;
7474   else
7475     FAIL;
7476 }")
7477
7478 (define_insn "*movsi_internal2"
7479   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
7480         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "0,r,r")
7481                     (const_int 0)))
7482    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
7483   "TARGET_32BIT"
7484   "@
7485    {cmpi|cmpwi} %2,%0,0
7486    mr. %0,%1
7487    #"
7488   [(set_attr "type" "cmp,compare,cmp")
7489    (set_attr "length" "4,4,8")])
7490
7491 (define_split
7492   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
7493         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
7494                     (const_int 0)))
7495    (set (match_operand:SI 0 "gpc_reg_operand" "") (match_dup 1))]
7496   "TARGET_32BIT && reload_completed"
7497   [(set (match_dup 0) (match_dup 1))
7498    (set (match_dup 2)
7499         (compare:CC (match_dup 0)
7500                     (const_int 0)))]
7501   "")
7502 \f
7503 (define_expand "movhi"
7504   [(set (match_operand:HI 0 "general_operand" "")
7505         (match_operand:HI 1 "any_operand" ""))]
7506   ""
7507   "{ rs6000_emit_move (operands[0], operands[1], HImode); DONE; }")
7508
7509 (define_insn "*movhi_internal"
7510   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7511         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7512   "gpc_reg_operand (operands[0], HImode)
7513    || gpc_reg_operand (operands[1], HImode)"
7514   "@
7515    mr %0,%1
7516    lhz%U1%X1 %0,%1
7517    sth%U0%X0 %1,%0
7518    {lil|li} %0,%w1
7519    mf%1 %0
7520    mt%0 %1
7521    mt%0 %1
7522    {cror 0,0,0|nop}"
7523   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7524
7525 (define_expand "movqi"
7526   [(set (match_operand:QI 0 "general_operand" "")
7527         (match_operand:QI 1 "any_operand" ""))]
7528   ""
7529   "{ rs6000_emit_move (operands[0], operands[1], QImode); DONE; }")
7530
7531 (define_insn "*movqi_internal"
7532   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7533         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7534   "gpc_reg_operand (operands[0], QImode)
7535    || gpc_reg_operand (operands[1], QImode)"
7536   "@
7537    mr %0,%1
7538    lbz%U1%X1 %0,%1
7539    stb%U0%X0 %1,%0
7540    {lil|li} %0,%1
7541    mf%1 %0
7542    mt%0 %1
7543    mt%0 %1
7544    {cror 0,0,0|nop}"
7545   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7546 \f
7547 ;; Here is how to move condition codes around.  When we store CC data in
7548 ;; an integer register or memory, we store just the high-order 4 bits.
7549 ;; This lets us not shift in the most common case of CR0.
7550 (define_expand "movcc"
7551   [(set (match_operand:CC 0 "nonimmediate_operand" "")
7552         (match_operand:CC 1 "nonimmediate_operand" ""))]
7553   ""
7554   "")
7555
7556 (define_insn "*movcc_internal1"
7557   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,r,r,r,r,q,cl,r,m")
7558         (match_operand:CC 1 "nonimmediate_operand" "y,r,r,x,y,r,h,r,r,m,r"))]
7559   "register_operand (operands[0], CCmode)
7560    || register_operand (operands[1], CCmode)"
7561   "@
7562    mcrf %0,%1
7563    mtcrf 128,%1
7564    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
7565    mfcr %0%Q1
7566    mfcr %0%Q1\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
7567    mr %0,%1
7568    mf%1 %0
7569    mt%0 %1
7570    mt%0 %1
7571    {l%U1%X1|lwz%U1%X1} %0,%1
7572    {st%U0%U1|stw%U0%U1} %1,%0"
7573   [(set (attr "type")
7574      (cond [(eq_attr "alternative" "0")
7575                 (const_string "cr_logical")
7576             (eq_attr "alternative" "1,2")
7577                 (const_string "mtcr")
7578             (eq_attr "alternative" "5,7")
7579                 (const_string "integer")
7580             (eq_attr "alternative" "6")
7581                 (const_string "mfjmpr")
7582             (eq_attr "alternative" "8")
7583                 (const_string "mtjmpr")
7584             (eq_attr "alternative" "9")
7585                 (const_string "load")
7586             (eq_attr "alternative" "10")
7587                 (const_string "store")
7588             (ne (symbol_ref "TARGET_MFCRF") (const_int 0))
7589                 (const_string "mfcrf")
7590            ]
7591         (const_string "mfcr")))
7592    (set_attr "length" "4,4,12,4,8,4,4,4,4,4,4")])
7593 \f
7594 ;; For floating-point, we normally deal with the floating-point registers
7595 ;; unless -msoft-float is used.  The sole exception is that parameter passing
7596 ;; can produce floating-point values in fixed-point registers.  Unless the
7597 ;; value is a simple constant or already in memory, we deal with this by
7598 ;; allocating memory and copying the value explicitly via that memory location.
7599 (define_expand "movsf"
7600   [(set (match_operand:SF 0 "nonimmediate_operand" "")
7601         (match_operand:SF 1 "any_operand" ""))]
7602   ""
7603   "{ rs6000_emit_move (operands[0], operands[1], SFmode); DONE; }")
7604
7605 (define_split
7606   [(set (match_operand:SF 0 "gpc_reg_operand" "")
7607         (match_operand:SF 1 "const_double_operand" ""))]
7608   "reload_completed
7609    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7610        || (GET_CODE (operands[0]) == SUBREG
7611            && GET_CODE (SUBREG_REG (operands[0])) == REG
7612            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7613   [(set (match_dup 2) (match_dup 3))]
7614   "
7615 {
7616   long l;
7617   REAL_VALUE_TYPE rv;
7618
7619   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7620   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
7621
7622   if (! TARGET_POWERPC64)
7623     operands[2] = operand_subword (operands[0], 0, 0, SFmode);
7624   else
7625     operands[2] = gen_lowpart (SImode, operands[0]);
7626
7627   operands[3] = gen_int_mode (l, SImode);
7628 }")
7629
7630 (define_insn "*movsf_hardfloat"
7631   [(set (match_operand:SF 0 "nonimmediate_operand" "=!r,!r,m,f,f,m,!cl,!q,!r,!h,!r,!r")
7632         (match_operand:SF 1 "input_operand" "r,m,r,f,m,f,r,r,h,0,G,Fn"))]
7633   "(gpc_reg_operand (operands[0], SFmode)
7634    || gpc_reg_operand (operands[1], SFmode))
7635    && (TARGET_HARD_FLOAT && TARGET_FPRS)"
7636   "@
7637    mr %0,%1
7638    {l%U1%X1|lwz%U1%X1} %0,%1
7639    {st%U0%X0|stw%U0%X0} %1,%0
7640    fmr %0,%1
7641    lfs%U1%X1 %0,%1
7642    stfs%U0%X0 %1,%0
7643    mt%0 %1
7644    mt%0 %1
7645    mf%1 %0
7646    {cror 0,0,0|nop}
7647    #
7648    #"
7649   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,mtjmpr,*,*,*,*")
7650    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,8")])
7651
7652 (define_insn "*movsf_softfloat"
7653   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,cl,q,r,r,m,r,r,r,r,r,*h")
7654         (match_operand:SF 1 "input_operand" "r,r,r,h,m,r,I,L,R,G,Fn,0"))]
7655   "(gpc_reg_operand (operands[0], SFmode)
7656    || gpc_reg_operand (operands[1], SFmode))
7657    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
7658   "@
7659    mr %0,%1
7660    mt%0 %1
7661    mt%0 %1
7662    mf%1 %0
7663    {l%U1%X1|lwz%U1%X1} %0,%1
7664    {st%U0%X0|stw%U0%X0} %1,%0
7665    {lil|li} %0,%1
7666    {liu|lis} %0,%v1
7667    {cal|la} %0,%a1
7668    #
7669    #
7670    {cror 0,0,0|nop}"
7671   [(set_attr "type" "*,mtjmpr,*,*,load,store,*,*,*,*,*,*")
7672    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,4")])
7673
7674 \f
7675 (define_expand "movdf"
7676   [(set (match_operand:DF 0 "nonimmediate_operand" "")
7677         (match_operand:DF 1 "any_operand" ""))]
7678   ""
7679   "{ rs6000_emit_move (operands[0], operands[1], DFmode); DONE; }")
7680
7681 (define_split
7682   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7683         (match_operand:DF 1 "const_int_operand" ""))]
7684   "! TARGET_POWERPC64 && reload_completed
7685    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7686        || (GET_CODE (operands[0]) == SUBREG
7687            && GET_CODE (SUBREG_REG (operands[0])) == REG
7688            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7689   [(set (match_dup 2) (match_dup 4))
7690    (set (match_dup 3) (match_dup 1))]
7691   "
7692 {
7693   int endian = (WORDS_BIG_ENDIAN == 0);
7694   HOST_WIDE_INT value = INTVAL (operands[1]);
7695
7696   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
7697   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
7698 #if HOST_BITS_PER_WIDE_INT == 32
7699   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
7700 #else
7701   operands[4] = GEN_INT (value >> 32);
7702   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
7703 #endif
7704 }")
7705
7706 (define_split
7707   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7708         (match_operand:DF 1 "const_double_operand" ""))]
7709   "! TARGET_POWERPC64 && reload_completed
7710    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7711        || (GET_CODE (operands[0]) == SUBREG
7712            && GET_CODE (SUBREG_REG (operands[0])) == REG
7713            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7714   [(set (match_dup 2) (match_dup 4))
7715    (set (match_dup 3) (match_dup 5))]
7716   "
7717 {
7718   int endian = (WORDS_BIG_ENDIAN == 0);
7719   long l[2];
7720   REAL_VALUE_TYPE rv;
7721
7722   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7723   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
7724
7725   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
7726   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
7727   operands[4] = gen_int_mode (l[endian], SImode);
7728   operands[5] = gen_int_mode (l[1 - endian], SImode);
7729 }")
7730
7731 (define_split
7732   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7733         (match_operand:DF 1 "easy_fp_constant" ""))]
7734   "TARGET_POWERPC64 && reload_completed
7735    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7736        || (GET_CODE (operands[0]) == SUBREG
7737            && GET_CODE (SUBREG_REG (operands[0])) == REG
7738            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7739   [(set (match_dup 2) (match_dup 3))]
7740   "
7741 {
7742   int endian = (WORDS_BIG_ENDIAN == 0);
7743   long l[2];
7744   REAL_VALUE_TYPE rv;
7745 #if HOST_BITS_PER_WIDE_INT >= 64
7746   HOST_WIDE_INT val;
7747 #endif
7748
7749   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7750   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
7751
7752   operands[2] = gen_lowpart (DImode, operands[0]);
7753   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
7754 #if HOST_BITS_PER_WIDE_INT >= 64
7755   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
7756          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
7757
7758   operands[3] = gen_int_mode (val, DImode);
7759 #else
7760   operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
7761 #endif
7762 }")
7763
7764 ;; Don't have reload use general registers to load a constant.  First,
7765 ;; it might not work if the output operand is the equivalent of
7766 ;; a non-offsettable memref, but also it is less efficient than loading
7767 ;; the constant into an FP register, since it will probably be used there.
7768 ;; The "??" is a kludge until we can figure out a more reasonable way
7769 ;; of handling these non-offsettable values.
7770 (define_insn "*movdf_hardfloat32"
7771   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,m,f,f,m,!r,!r,!r")
7772         (match_operand:DF 1 "input_operand" "r,m,r,f,m,f,G,H,F"))]
7773   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
7774    && (gpc_reg_operand (operands[0], DFmode)
7775        || gpc_reg_operand (operands[1], DFmode))"
7776   "*
7777 {
7778   switch (which_alternative)
7779     {
7780     default:
7781       gcc_unreachable ();
7782     case 0:
7783       /* We normally copy the low-numbered register first.  However, if
7784          the first register operand 0 is the same as the second register
7785          of operand 1, we must copy in the opposite order.  */
7786       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
7787         return \"mr %L0,%L1\;mr %0,%1\";
7788       else
7789         return \"mr %0,%1\;mr %L0,%L1\";
7790     case 1:
7791       if (GET_CODE (operands[1]) == MEM
7792           && (rs6000_legitimate_offset_address_p (DFmode, XEXP (operands[1], 0),
7793                         reload_completed || reload_in_progress)
7794               || GET_CODE (XEXP (operands[1], 0)) == REG
7795               || GET_CODE (XEXP (operands[1], 0)) == LO_SUM
7796                   || GET_CODE (XEXP (operands[1], 0)) == PRE_INC
7797               || GET_CODE (XEXP (operands[1], 0)) == PRE_DEC))
7798         {
7799           /* If the low-address word is used in the address, we must load
7800              it last.  Otherwise, load it first.  Note that we cannot have
7801              auto-increment in that case since the address register is
7802              known to be dead.  */
7803           if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
7804                                  operands[1], 0))
7805             return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
7806           else
7807             return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
7808         }
7809       else
7810         {
7811           rtx addreg;
7812
7813           addreg = find_addr_reg (XEXP (operands[1], 0));
7814           if (refers_to_regno_p (REGNO (operands[0]),
7815                                  REGNO (operands[0]) + 1,
7816                                  operands[1], 0))
7817             {
7818               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
7819               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
7820               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
7821               return \"{lx|lwzx} %0,%1\";
7822             }
7823           else
7824             {
7825               output_asm_insn (\"{lx|lwzx} %0,%1\", operands);
7826               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
7827               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
7828               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
7829               return \"\";
7830             }
7831         }
7832     case 2:
7833       if (GET_CODE (operands[0]) == MEM
7834           && (rs6000_legitimate_offset_address_p (DFmode, XEXP (operands[0], 0),
7835                     reload_completed || reload_in_progress)
7836               || GET_CODE (XEXP (operands[0], 0)) == REG
7837               || GET_CODE (XEXP (operands[0], 0)) == LO_SUM
7838                   || GET_CODE (XEXP (operands[0], 0)) == PRE_INC
7839               || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC))
7840         return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
7841       else
7842         {
7843           rtx addreg;
7844
7845           addreg = find_addr_reg (XEXP (operands[0], 0));
7846           output_asm_insn (\"{stx|stwx} %1,%0\", operands);
7847           output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
7848           output_asm_insn (\"{stx|stwx} %L1,%0\", operands);
7849           output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
7850           return \"\";
7851         }
7852     case 3:
7853       return \"fmr %0,%1\";
7854     case 4:
7855       return \"lfd%U1%X1 %0,%1\";
7856     case 5:
7857       return \"stfd%U0%X0 %1,%0\";
7858     case 6:
7859     case 7:
7860     case 8:
7861       return \"#\";
7862     }
7863 }"
7864   [(set_attr "type" "two,load,store,fp,fpload,fpstore,*,*,*")
7865    (set_attr "length" "8,16,16,4,4,4,8,12,16")])
7866
7867 (define_insn "*movdf_softfloat32"
7868   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
7869         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F"))]
7870   "! TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || TARGET_E500_SINGLE)
7871    && (gpc_reg_operand (operands[0], DFmode)
7872        || gpc_reg_operand (operands[1], DFmode))"
7873   "*
7874 {
7875   switch (which_alternative)
7876     {
7877     default:
7878       gcc_unreachable ();
7879     case 0:
7880       /* We normally copy the low-numbered register first.  However, if
7881          the first register operand 0 is the same as the second register of
7882          operand 1, we must copy in the opposite order.  */
7883       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
7884         return \"mr %L0,%L1\;mr %0,%1\";
7885       else
7886         return \"mr %0,%1\;mr %L0,%L1\";
7887     case 1:
7888       /* If the low-address word is used in the address, we must load
7889          it last.  Otherwise, load it first.  Note that we cannot have
7890          auto-increment in that case since the address register is
7891          known to be dead.  */
7892       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
7893                              operands[1], 0))
7894         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
7895       else
7896         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
7897     case 2:
7898       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
7899     case 3:
7900     case 4:
7901     case 5:
7902       return \"#\";
7903     }
7904 }"
7905   [(set_attr "type" "two,load,store,*,*,*")
7906    (set_attr "length" "8,8,8,8,12,16")])
7907
7908 ; ld/std require word-aligned displacements -> 'Y' constraint.
7909 ; List Y->r and r->Y before r->r for reload.
7910 (define_insn "*movdf_hardfloat64"
7911   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,!r,f,f,m,!cl,!r,!h,!r,!r,!r")
7912         (match_operand:DF 1 "input_operand" "r,Y,r,f,m,f,r,h,0,G,H,F"))]
7913   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
7914    && (gpc_reg_operand (operands[0], DFmode)
7915        || gpc_reg_operand (operands[1], DFmode))"
7916   "@
7917    std%U0%X0 %1,%0
7918    ld%U1%X1 %0,%1
7919    mr %0,%1
7920    fmr %0,%1
7921    lfd%U1%X1 %0,%1
7922    stfd%U0%X0 %1,%0
7923    mt%0 %1
7924    mf%1 %0
7925    {cror 0,0,0|nop}
7926    #
7927    #
7928    #"
7929   [(set_attr "type" "*,load,store,fp,fpload,fpstore,mtjmpr,*,*,*,*,*")
7930    (set_attr "length" "4,4,4,4,4,4,4,4,4,8,12,16")])
7931
7932 (define_insn "*movdf_softfloat64"
7933   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,Y,r,cl,r,r,r,r,*h")
7934         (match_operand:DF 1 "input_operand" "Y,r,r,r,h,G,H,F,0"))]
7935   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
7936    && (gpc_reg_operand (operands[0], DFmode)
7937        || gpc_reg_operand (operands[1], DFmode))"
7938   "@
7939    ld%U1%X1 %0,%1
7940    std%U0%X0 %1,%0
7941    mr %0,%1
7942    mt%0 %1
7943    mf%1 %0
7944    #
7945    #
7946    #
7947    {cror 0,0,0|nop}"
7948   [(set_attr "type" "load,store,*,*,*,*,*,*,*")
7949    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
7950 \f
7951 (define_expand "movtf"
7952   [(set (match_operand:TF 0 "general_operand" "")
7953         (match_operand:TF 1 "any_operand" ""))]
7954   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
7955    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
7956   "{ rs6000_emit_move (operands[0], operands[1], TFmode); DONE; }")
7957
7958 ; It's important to list the o->f and f->o moves before f->f because
7959 ; otherwise reload, given m->f, will try to pick f->f and reload it,
7960 ; which doesn't make progress.  Likewise r->Y must be before r->r.
7961 (define_insn_and_split "*movtf_internal"
7962   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,f,r,Y,r")
7963         (match_operand:TF 1 "input_operand"         "f,o,f,YGHF,r,r"))]
7964   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
7965    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
7966    && (gpc_reg_operand (operands[0], TFmode)
7967        || gpc_reg_operand (operands[1], TFmode))"
7968   "#"
7969   "&& reload_completed"
7970   [(pc)]
7971 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
7972   [(set_attr "length" "8,8,8,20,20,16")])
7973
7974 (define_expand "extenddftf2"
7975   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
7976                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
7977               (use (match_dup 2))])]
7978   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
7979    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
7980 {
7981   operands[2] = CONST0_RTX (DFmode);
7982 })
7983
7984 (define_insn_and_split "*extenddftf2_internal"
7985   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,&f,r")
7986        (float_extend:TF (match_operand:DF 1 "input_operand" "fr,mf,mf,rmGHF")))
7987    (use (match_operand:DF 2 "zero_reg_mem_operand" "rf,m,f,n"))]
7988   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
7989    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
7990   "#"
7991   "&& reload_completed"
7992   [(pc)]
7993 {
7994   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
7995   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
7996   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
7997                   operands[1]);
7998   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
7999                   operands[2]);
8000   DONE;
8001 })
8002
8003 (define_expand "extendsftf2"
8004   [(set (match_operand:TF 0 "nonimmediate_operand" "")
8005         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
8006   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8007    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8008 {
8009   rtx tmp = gen_reg_rtx (DFmode);
8010   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
8011   emit_insn (gen_extenddftf2 (operands[0], tmp));
8012   DONE;
8013 })
8014
8015 (define_expand "trunctfdf2"
8016   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8017         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))]
8018   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8019    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8020   "")
8021
8022 (define_insn_and_split "trunctfdf2_internal1"
8023   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,?f")
8024         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "0,f")))]
8025   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN) && !TARGET_XL_COMPAT
8026    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8027   "@
8028    #
8029    fmr %0,%1"
8030   "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
8031   [(const_int 0)]
8032 {
8033   emit_note (NOTE_INSN_DELETED);
8034   DONE;
8035 }
8036   [(set_attr "type" "fp")])
8037
8038 (define_insn "trunctfdf2_internal2"
8039   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8040         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8041   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN) && TARGET_XL_COMPAT
8042    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8043   "fadd %0,%1,%L1"
8044   [(set_attr "type" "fp")])
8045
8046 (define_insn_and_split "trunctfsf2"
8047   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
8048         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "f")))
8049    (clobber (match_scratch:DF 2 "=f"))]
8050   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8051    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8052   "#"
8053   "&& reload_completed"
8054   [(set (match_dup 2)
8055         (float_truncate:DF (match_dup 1)))
8056    (set (match_dup 0)
8057         (float_truncate:SF (match_dup 2)))]
8058   "")
8059
8060 (define_expand "floatsitf2"
8061   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8062         (float:TF (match_operand:SI 1 "gpc_reg_operand" "r")))]
8063   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8064    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8065 {
8066   rtx tmp = gen_reg_rtx (DFmode);
8067   expand_float (tmp, operands[1], false);
8068   emit_insn (gen_extenddftf2 (operands[0], tmp));
8069   DONE;
8070 })
8071
8072 ; fadd, but rounding towards zero.
8073 ; This is probably not the optimal code sequence.
8074 (define_insn "fix_trunc_helper"
8075   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8076         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "f")]
8077                    UNSPEC_FIX_TRUNC_TF))
8078    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&f"))]
8079   "TARGET_HARD_FLOAT && TARGET_FPRS"
8080   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
8081   [(set_attr "type" "fp")
8082    (set_attr "length" "20")])
8083
8084 (define_expand "fix_trunctfsi2"
8085   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
8086                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
8087               (clobber (match_dup 2))
8088               (clobber (match_dup 3))
8089               (clobber (match_dup 4))
8090               (clobber (match_dup 5))])]
8091   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8092    && (TARGET_POWER2 || TARGET_POWERPC)
8093    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8094 {
8095   operands[2] = gen_reg_rtx (DFmode);
8096   operands[3] = gen_reg_rtx (DFmode);
8097   operands[4] = gen_reg_rtx (DImode);
8098   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
8099 })
8100
8101 (define_insn_and_split "*fix_trunctfsi2_internal"
8102   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8103         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "f")))
8104    (clobber (match_operand:DF 2 "gpc_reg_operand" "=f"))
8105    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&f"))
8106    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))
8107    (clobber (match_operand:DI 5 "memory_operand" "=o"))]
8108   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8109    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8110   "#"
8111   "&& (!no_new_pseudos || offsettable_nonstrict_memref_p (operands[5]))"
8112   [(pc)]
8113 {
8114   rtx lowword;
8115   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
8116
8117   gcc_assert (MEM_P (operands[5]));
8118   lowword = adjust_address (operands[5], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
8119
8120   emit_insn (gen_fctiwz (operands[4], operands[2]));
8121   emit_move_insn (operands[5], operands[4]);
8122   emit_move_insn (operands[0], lowword);
8123   DONE;
8124 })
8125
8126 (define_insn "negtf2"
8127   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8128         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8129   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8130    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8131   "*
8132 {
8133   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8134     return \"fneg %L0,%L1\;fneg %0,%1\";
8135   else
8136     return \"fneg %0,%1\;fneg %L0,%L1\";
8137 }"
8138   [(set_attr "type" "fp")
8139    (set_attr "length" "8")])
8140
8141 (define_expand "abstf2"
8142   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8143         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8144   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8145    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8146   "
8147 {
8148   rtx label = gen_label_rtx ();
8149   emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
8150   emit_label (label);
8151   DONE;
8152 }")
8153
8154 (define_expand "abstf2_internal"
8155   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8156         (match_operand:TF 1 "gpc_reg_operand" "f"))
8157    (set (match_dup 3) (match_dup 5))
8158    (set (match_dup 5) (abs:DF (match_dup 5)))
8159    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
8160    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
8161                            (label_ref (match_operand 2 "" ""))
8162                            (pc)))
8163    (set (match_dup 6) (neg:DF (match_dup 6)))]
8164   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8165    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8166   "
8167 {
8168   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8169   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8170   operands[3] = gen_reg_rtx (DFmode);
8171   operands[4] = gen_reg_rtx (CCFPmode);
8172   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
8173   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
8174 }")
8175 \f
8176 ;; Next come the multi-word integer load and store and the load and store
8177 ;; multiple insns.
8178 (define_expand "movdi"
8179   [(set (match_operand:DI 0 "general_operand" "")
8180         (match_operand:DI 1 "any_operand" ""))]
8181   ""
8182   "{ rs6000_emit_move (operands[0], operands[1], DImode); DONE; }")
8183
8184 ; List r->r after r->"o<>", otherwise reload will try to reload a
8185 ; non-offsettable address by using r->r which won't make progress.
8186 (define_insn "*movdi_internal32"
8187   [(set (match_operand:DI 0 "nonimmediate_operand" "=o<>,r,r,*f,*f,m,r")
8188         (match_operand:DI 1 "input_operand" "r,r,m,f,m,f,IJKnGHF"))]
8189   "! TARGET_POWERPC64
8190    && (gpc_reg_operand (operands[0], DImode)
8191        || gpc_reg_operand (operands[1], DImode))"
8192   "@
8193    #
8194    #
8195    #
8196    fmr %0,%1
8197    lfd%U1%X1 %0,%1
8198    stfd%U0%X0 %1,%0
8199    #"
8200   [(set_attr "type" "load,*,store,fp,fpload,fpstore,*")])
8201
8202 (define_split
8203   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8204         (match_operand:DI 1 "const_int_operand" ""))]
8205   "! TARGET_POWERPC64 && reload_completed"
8206   [(set (match_dup 2) (match_dup 4))
8207    (set (match_dup 3) (match_dup 1))]
8208   "
8209 {
8210   HOST_WIDE_INT value = INTVAL (operands[1]);
8211   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8212                                        DImode);
8213   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8214                                        DImode);
8215 #if HOST_BITS_PER_WIDE_INT == 32
8216   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8217 #else
8218   operands[4] = GEN_INT (value >> 32);
8219   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8220 #endif
8221 }")
8222
8223 (define_split
8224   [(set (match_operand:DI 0 "nonimmediate_operand" "")
8225         (match_operand:DI 1 "input_operand" ""))]
8226   "reload_completed && !TARGET_POWERPC64
8227    && gpr_or_gpr_p (operands[0], operands[1])"
8228   [(pc)]
8229 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8230
8231 (define_insn "*movdi_internal64"
8232   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,*f,*f,m,r,*h,*h")
8233         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,f,m,f,*h,r,0"))]
8234   "TARGET_POWERPC64
8235    && (gpc_reg_operand (operands[0], DImode)
8236        || gpc_reg_operand (operands[1], DImode))"
8237   "@
8238    mr %0,%1
8239    ld%U1%X1 %0,%1
8240    std%U0%X0 %1,%0
8241    li %0,%1
8242    lis %0,%v1
8243    #
8244    {cal|la} %0,%a1
8245    fmr %0,%1
8246    lfd%U1%X1 %0,%1
8247    stfd%U0%X0 %1,%0
8248    mf%1 %0
8249    mt%0 %1
8250    {cror 0,0,0|nop}"
8251   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*")
8252    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4")])
8253
8254 ;; immediate value valid for a single instruction hiding in a const_double
8255 (define_insn ""
8256   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8257         (match_operand:DI 1 "const_double_operand" "F"))]
8258   "HOST_BITS_PER_WIDE_INT == 32 && TARGET_POWERPC64
8259    && GET_CODE (operands[1]) == CONST_DOUBLE
8260    && num_insns_constant (operands[1], DImode) == 1"
8261   "*
8262 {
8263   return ((unsigned HOST_WIDE_INT)
8264           (CONST_DOUBLE_LOW (operands[1]) + 0x8000) < 0x10000)
8265          ? \"li %0,%1\" : \"lis %0,%v1\";
8266 }")
8267
8268 ;; Generate all one-bits and clear left or right.
8269 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
8270 (define_split
8271   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8272         (match_operand:DI 1 "mask64_operand" ""))]
8273   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8274   [(set (match_dup 0) (const_int -1))
8275    (set (match_dup 0)
8276         (and:DI (rotate:DI (match_dup 0)
8277                            (const_int 0))
8278                 (match_dup 1)))]
8279   "")
8280
8281 ;; Split a load of a large constant into the appropriate five-instruction
8282 ;; sequence.  Handle anything in a constant number of insns.
8283 ;; When non-easy constants can go in the TOC, this should use
8284 ;; easy_fp_constant predicate.
8285 (define_split
8286   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8287         (match_operand:DI 1 "const_int_operand" ""))]
8288   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8289   [(set (match_dup 0) (match_dup 2))
8290    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8291   "
8292 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8293
8294   if (tem == operands[0])
8295     DONE;
8296   else
8297     FAIL;
8298 }")
8299
8300 (define_split
8301   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8302         (match_operand:DI 1 "const_double_operand" ""))]
8303   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8304   [(set (match_dup 0) (match_dup 2))
8305    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8306   "
8307 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8308
8309   if (tem == operands[0])
8310     DONE;
8311   else
8312     FAIL;
8313 }")
8314
8315 (define_insn "*movdi_internal2"
8316   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
8317         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "0,r,r")
8318                     (const_int 0)))
8319    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
8320   "TARGET_64BIT"
8321   "@
8322    cmpdi %2,%0,0
8323    mr. %0,%1
8324    #"
8325   [(set_attr "type" "cmp,compare,cmp")
8326    (set_attr "length" "4,4,8")])
8327
8328 (define_split
8329   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
8330         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "")
8331                     (const_int 0)))
8332    (set (match_operand:DI 0 "gpc_reg_operand" "") (match_dup 1))]
8333   "TARGET_POWERPC64 && reload_completed"
8334   [(set (match_dup 0) (match_dup 1))
8335    (set (match_dup 2)
8336         (compare:CC (match_dup 0)
8337                     (const_int 0)))]
8338   "")
8339 \f
8340 ;; TImode is similar, except that we usually want to compute the address into
8341 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
8342 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
8343 (define_expand "movti"
8344   [(parallel [(set (match_operand:TI 0 "general_operand" "")
8345                    (match_operand:TI 1 "general_operand" ""))
8346               (clobber (scratch:SI))])]
8347   ""
8348   "{ rs6000_emit_move (operands[0], operands[1], TImode); DONE; }")
8349
8350 ;; We say that MQ is clobbered in the last alternative because the first
8351 ;; alternative would never get used otherwise since it would need a reload
8352 ;; while the 2nd alternative would not.  We put memory cases first so they
8353 ;; are preferred.  Otherwise, we'd try to reload the output instead of
8354 ;; giving the SCRATCH mq.
8355
8356 (define_insn "*movti_power"
8357   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r,r")
8358         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))
8359    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X,X"))]
8360   "TARGET_POWER && ! TARGET_POWERPC64
8361    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8362   "*
8363 {
8364   switch (which_alternative)
8365     {
8366     default:
8367       gcc_unreachable ();
8368
8369     case 0:
8370       if (TARGET_STRING)
8371         return \"{stsi|stswi} %1,%P0,16\";
8372     case 1:
8373     case 2:
8374       return \"#\";
8375     case 3:
8376       /* If the address is not used in the output, we can use lsi.  Otherwise,
8377          fall through to generating four loads.  */
8378       if (TARGET_STRING
8379           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8380         return \"{lsi|lswi} %0,%P1,16\";
8381       /* ... fall through ...  */
8382     case 4:
8383     case 5:
8384       return \"#\";
8385     }
8386 }"
8387   [(set_attr "type" "store,store,*,load,load,*")])
8388
8389 (define_insn "*movti_string"
8390   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,o<>,????r,????r,????r,r")
8391         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))]
8392   "! TARGET_POWER && ! TARGET_POWERPC64
8393    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8394   "*
8395 {
8396   switch (which_alternative)
8397     {
8398     default:
8399       gcc_unreachable ();
8400     case 0:
8401       if (TARGET_STRING)
8402         return \"{stsi|stswi} %1,%P0,16\";
8403     case 1:
8404     case 2:
8405       return \"#\";
8406     case 3:
8407       /* If the address is not used in the output, we can use lsi.  Otherwise,
8408          fall through to generating four loads.  */
8409       if (TARGET_STRING
8410           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8411         return \"{lsi|lswi} %0,%P1,16\";
8412       /* ... fall through ...  */
8413     case 4:
8414     case 5:
8415       return \"#\";
8416     }
8417 }"
8418   [(set_attr "type" "store,store,*,load,load,*")])
8419
8420 (define_insn "*movti_ppc64"
8421   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,o<>,r")
8422         (match_operand:TI 1 "input_operand" "r,r,m"))]
8423   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
8424    || gpc_reg_operand (operands[1], TImode))"
8425   "#"
8426   [(set_attr "type" "*,load,store")])
8427
8428 (define_split
8429   [(set (match_operand:TI 0 "gpc_reg_operand" "")
8430         (match_operand:TI 1 "const_double_operand" ""))]
8431   "TARGET_POWERPC64"
8432   [(set (match_dup 2) (match_dup 4))
8433    (set (match_dup 3) (match_dup 5))]
8434   "
8435 {
8436   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8437                                        TImode);
8438   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8439                                        TImode);
8440   if (GET_CODE (operands[1]) == CONST_DOUBLE)
8441     {
8442       operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
8443       operands[5] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
8444     }
8445   else if (GET_CODE (operands[1]) == CONST_INT)
8446     {
8447       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
8448       operands[5] = operands[1];
8449     }
8450   else
8451     FAIL;
8452 }")
8453
8454 (define_split
8455   [(set (match_operand:TI 0 "nonimmediate_operand" "")
8456         (match_operand:TI 1 "input_operand" ""))]
8457   "reload_completed
8458    && gpr_or_gpr_p (operands[0], operands[1])"
8459   [(pc)]
8460 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8461 \f
8462 (define_expand "load_multiple"
8463   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8464                           (match_operand:SI 1 "" ""))
8465                      (use (match_operand:SI 2 "" ""))])]
8466   "TARGET_STRING && !TARGET_POWERPC64"
8467   "
8468 {
8469   int regno;
8470   int count;
8471   rtx op1;
8472   int i;
8473
8474   /* Support only loading a constant number of fixed-point registers from
8475      memory and only bother with this if more than two; the machine
8476      doesn't support more than eight.  */
8477   if (GET_CODE (operands[2]) != CONST_INT
8478       || INTVAL (operands[2]) <= 2
8479       || INTVAL (operands[2]) > 8
8480       || GET_CODE (operands[1]) != MEM
8481       || GET_CODE (operands[0]) != REG
8482       || REGNO (operands[0]) >= 32)
8483     FAIL;
8484
8485   count = INTVAL (operands[2]);
8486   regno = REGNO (operands[0]);
8487
8488   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
8489   op1 = replace_equiv_address (operands[1],
8490                                force_reg (SImode, XEXP (operands[1], 0)));
8491
8492   for (i = 0; i < count; i++)
8493     XVECEXP (operands[3], 0, i)
8494       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
8495                      adjust_address_nv (op1, SImode, i * 4));
8496 }")
8497
8498 (define_insn "*ldmsi8"
8499   [(match_parallel 0 "load_multiple_operation"
8500     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8501           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8502      (set (match_operand:SI 3 "gpc_reg_operand" "")
8503           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8504      (set (match_operand:SI 4 "gpc_reg_operand" "")
8505           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8506      (set (match_operand:SI 5 "gpc_reg_operand" "")
8507           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8508      (set (match_operand:SI 6 "gpc_reg_operand" "")
8509           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8510      (set (match_operand:SI 7 "gpc_reg_operand" "")
8511           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8512      (set (match_operand:SI 8 "gpc_reg_operand" "")
8513           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
8514      (set (match_operand:SI 9 "gpc_reg_operand" "")
8515           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
8516   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
8517   "*
8518 { return rs6000_output_load_multiple (operands); }"
8519   [(set_attr "type" "load")
8520    (set_attr "length" "32")])
8521
8522 (define_insn "*ldmsi7"
8523   [(match_parallel 0 "load_multiple_operation"
8524     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8525           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8526      (set (match_operand:SI 3 "gpc_reg_operand" "")
8527           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8528      (set (match_operand:SI 4 "gpc_reg_operand" "")
8529           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8530      (set (match_operand:SI 5 "gpc_reg_operand" "")
8531           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8532      (set (match_operand:SI 6 "gpc_reg_operand" "")
8533           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8534      (set (match_operand:SI 7 "gpc_reg_operand" "")
8535           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8536      (set (match_operand:SI 8 "gpc_reg_operand" "")
8537           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
8538   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
8539   "*
8540 { return rs6000_output_load_multiple (operands); }"
8541   [(set_attr "type" "load")
8542    (set_attr "length" "32")])
8543
8544 (define_insn "*ldmsi6"
8545   [(match_parallel 0 "load_multiple_operation"
8546     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8547           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8548      (set (match_operand:SI 3 "gpc_reg_operand" "")
8549           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8550      (set (match_operand:SI 4 "gpc_reg_operand" "")
8551           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8552      (set (match_operand:SI 5 "gpc_reg_operand" "")
8553           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8554      (set (match_operand:SI 6 "gpc_reg_operand" "")
8555           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8556      (set (match_operand:SI 7 "gpc_reg_operand" "")
8557           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
8558   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
8559   "*
8560 { return rs6000_output_load_multiple (operands); }"
8561   [(set_attr "type" "load")
8562    (set_attr "length" "32")])
8563
8564 (define_insn "*ldmsi5"
8565   [(match_parallel 0 "load_multiple_operation"
8566     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8567           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8568      (set (match_operand:SI 3 "gpc_reg_operand" "")
8569           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8570      (set (match_operand:SI 4 "gpc_reg_operand" "")
8571           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8572      (set (match_operand:SI 5 "gpc_reg_operand" "")
8573           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8574      (set (match_operand:SI 6 "gpc_reg_operand" "")
8575           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
8576   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
8577   "*
8578 { return rs6000_output_load_multiple (operands); }"
8579   [(set_attr "type" "load")
8580    (set_attr "length" "32")])
8581
8582 (define_insn "*ldmsi4"
8583   [(match_parallel 0 "load_multiple_operation"
8584     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8585           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8586      (set (match_operand:SI 3 "gpc_reg_operand" "")
8587           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8588      (set (match_operand:SI 4 "gpc_reg_operand" "")
8589           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8590      (set (match_operand:SI 5 "gpc_reg_operand" "")
8591           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
8592   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
8593   "*
8594 { return rs6000_output_load_multiple (operands); }"
8595   [(set_attr "type" "load")
8596    (set_attr "length" "32")])
8597
8598 (define_insn "*ldmsi3"
8599   [(match_parallel 0 "load_multiple_operation"
8600     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8601           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8602      (set (match_operand:SI 3 "gpc_reg_operand" "")
8603           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8604      (set (match_operand:SI 4 "gpc_reg_operand" "")
8605           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
8606   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
8607   "*
8608 { return rs6000_output_load_multiple (operands); }"
8609   [(set_attr "type" "load")
8610    (set_attr "length" "32")])
8611
8612 (define_expand "store_multiple"
8613   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8614                           (match_operand:SI 1 "" ""))
8615                      (clobber (scratch:SI))
8616                      (use (match_operand:SI 2 "" ""))])]
8617   "TARGET_STRING && !TARGET_POWERPC64"
8618   "
8619 {
8620   int regno;
8621   int count;
8622   rtx to;
8623   rtx op0;
8624   int i;
8625
8626   /* Support only storing a constant number of fixed-point registers to
8627      memory and only bother with this if more than two; the machine
8628      doesn't support more than eight.  */
8629   if (GET_CODE (operands[2]) != CONST_INT
8630       || INTVAL (operands[2]) <= 2
8631       || INTVAL (operands[2]) > 8
8632       || GET_CODE (operands[0]) != MEM
8633       || GET_CODE (operands[1]) != REG
8634       || REGNO (operands[1]) >= 32)
8635     FAIL;
8636
8637   count = INTVAL (operands[2]);
8638   regno = REGNO (operands[1]);
8639
8640   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
8641   to = force_reg (SImode, XEXP (operands[0], 0));
8642   op0 = replace_equiv_address (operands[0], to);
8643
8644   XVECEXP (operands[3], 0, 0)
8645     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
8646   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
8647                                                  gen_rtx_SCRATCH (SImode));
8648
8649   for (i = 1; i < count; i++)
8650     XVECEXP (operands[3], 0, i + 1)
8651       = gen_rtx_SET (VOIDmode,
8652                      adjust_address_nv (op0, SImode, i * 4),
8653                      gen_rtx_REG (SImode, regno + i));
8654 }")
8655
8656 (define_insn "*store_multiple_power"
8657   [(match_parallel 0 "store_multiple_operation"
8658                    [(set (match_operand:SI 1 "indirect_operand" "=Q")
8659                          (match_operand:SI 2 "gpc_reg_operand" "r"))
8660                     (clobber (match_scratch:SI 3 "=q"))])]
8661   "TARGET_STRING && TARGET_POWER"
8662   "{stsi|stswi} %2,%P1,%O0"
8663   [(set_attr "type" "store")])
8664
8665 (define_insn "*stmsi8"
8666   [(match_parallel 0 "store_multiple_operation"
8667     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8668           (match_operand:SI 2 "gpc_reg_operand" "r"))
8669      (clobber (match_scratch:SI 3 "X"))
8670      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8671           (match_operand:SI 4 "gpc_reg_operand" "r"))
8672      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8673           (match_operand:SI 5 "gpc_reg_operand" "r"))
8674      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8675           (match_operand:SI 6 "gpc_reg_operand" "r"))
8676      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8677           (match_operand:SI 7 "gpc_reg_operand" "r"))
8678      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8679           (match_operand:SI 8 "gpc_reg_operand" "r"))
8680      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
8681           (match_operand:SI 9 "gpc_reg_operand" "r"))
8682      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
8683           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
8684   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 9"
8685   "{stsi|stswi} %2,%1,%O0"
8686   [(set_attr "type" "store")])
8687
8688 (define_insn "*stmsi7"
8689   [(match_parallel 0 "store_multiple_operation"
8690     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8691           (match_operand:SI 2 "gpc_reg_operand" "r"))
8692      (clobber (match_scratch:SI 3 "X"))
8693      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8694           (match_operand:SI 4 "gpc_reg_operand" "r"))
8695      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8696           (match_operand:SI 5 "gpc_reg_operand" "r"))
8697      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8698           (match_operand:SI 6 "gpc_reg_operand" "r"))
8699      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8700           (match_operand:SI 7 "gpc_reg_operand" "r"))
8701      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8702           (match_operand:SI 8 "gpc_reg_operand" "r"))
8703      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
8704           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
8705   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 8"
8706   "{stsi|stswi} %2,%1,%O0"
8707   [(set_attr "type" "store")])
8708
8709 (define_insn "*stmsi6"
8710   [(match_parallel 0 "store_multiple_operation"
8711     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8712           (match_operand:SI 2 "gpc_reg_operand" "r"))
8713      (clobber (match_scratch:SI 3 "X"))
8714      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8715           (match_operand:SI 4 "gpc_reg_operand" "r"))
8716      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8717           (match_operand:SI 5 "gpc_reg_operand" "r"))
8718      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8719           (match_operand:SI 6 "gpc_reg_operand" "r"))
8720      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8721           (match_operand:SI 7 "gpc_reg_operand" "r"))
8722      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8723           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
8724   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 7"
8725   "{stsi|stswi} %2,%1,%O0"
8726   [(set_attr "type" "store")])
8727
8728 (define_insn "*stmsi5"
8729   [(match_parallel 0 "store_multiple_operation"
8730     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8731           (match_operand:SI 2 "gpc_reg_operand" "r"))
8732      (clobber (match_scratch:SI 3 "X"))
8733      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8734           (match_operand:SI 4 "gpc_reg_operand" "r"))
8735      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8736           (match_operand:SI 5 "gpc_reg_operand" "r"))
8737      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8738           (match_operand:SI 6 "gpc_reg_operand" "r"))
8739      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8740           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
8741   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 6"
8742   "{stsi|stswi} %2,%1,%O0"
8743   [(set_attr "type" "store")])
8744
8745 (define_insn "*stmsi4"
8746   [(match_parallel 0 "store_multiple_operation"
8747     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8748           (match_operand:SI 2 "gpc_reg_operand" "r"))
8749      (clobber (match_scratch:SI 3 "X"))
8750      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8751           (match_operand:SI 4 "gpc_reg_operand" "r"))
8752      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8753           (match_operand:SI 5 "gpc_reg_operand" "r"))
8754      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8755           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
8756   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 5"
8757   "{stsi|stswi} %2,%1,%O0"
8758   [(set_attr "type" "store")])
8759
8760 (define_insn "*stmsi3"
8761   [(match_parallel 0 "store_multiple_operation"
8762     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8763           (match_operand:SI 2 "gpc_reg_operand" "r"))
8764      (clobber (match_scratch:SI 3 "X"))
8765      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8766           (match_operand:SI 4 "gpc_reg_operand" "r"))
8767      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8768           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
8769   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 4"
8770   "{stsi|stswi} %2,%1,%O0"
8771   [(set_attr "type" "store")])
8772 \f
8773 (define_expand "clrmemsi"
8774   [(parallel [(set (match_operand:BLK 0 "" "")
8775                    (const_int 0))
8776               (use (match_operand:SI 1 "" ""))
8777               (use (match_operand:SI 2 "" ""))])]
8778   ""
8779   "
8780 {
8781   if (expand_block_clear (operands))
8782     DONE;
8783   else
8784     FAIL;
8785 }")
8786
8787 ;; String/block move insn.
8788 ;; Argument 0 is the destination
8789 ;; Argument 1 is the source
8790 ;; Argument 2 is the length
8791 ;; Argument 3 is the alignment
8792
8793 (define_expand "movmemsi"
8794   [(parallel [(set (match_operand:BLK 0 "" "")
8795                    (match_operand:BLK 1 "" ""))
8796               (use (match_operand:SI 2 "" ""))
8797               (use (match_operand:SI 3 "" ""))])]
8798   ""
8799   "
8800 {
8801   if (expand_block_move (operands))
8802     DONE;
8803   else
8804     FAIL;
8805 }")
8806
8807 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
8808 ;; register allocator doesn't have a clue about allocating 8 word registers.
8809 ;; rD/rS = r5 is preferred, efficient form.
8810 (define_expand "movmemsi_8reg"
8811   [(parallel [(set (match_operand 0 "" "")
8812                    (match_operand 1 "" ""))
8813               (use (match_operand 2 "" ""))
8814               (use (match_operand 3 "" ""))
8815               (clobber (reg:SI  5))
8816               (clobber (reg:SI  6))
8817               (clobber (reg:SI  7))
8818               (clobber (reg:SI  8))
8819               (clobber (reg:SI  9))
8820               (clobber (reg:SI 10))
8821               (clobber (reg:SI 11))
8822               (clobber (reg:SI 12))
8823               (clobber (match_scratch:SI 4 ""))])]
8824   "TARGET_STRING"
8825   "")
8826
8827 (define_insn ""
8828   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
8829         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
8830    (use (match_operand:SI 2 "immediate_operand" "i"))
8831    (use (match_operand:SI 3 "immediate_operand" "i"))
8832    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
8833    (clobber (reg:SI  6))
8834    (clobber (reg:SI  7))
8835    (clobber (reg:SI  8))
8836    (clobber (reg:SI  9))
8837    (clobber (reg:SI 10))
8838    (clobber (reg:SI 11))
8839    (clobber (reg:SI 12))
8840    (clobber (match_scratch:SI 5 "=q"))]
8841   "TARGET_STRING && TARGET_POWER
8842    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
8843        || INTVAL (operands[2]) == 0)
8844    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
8845    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
8846    && REGNO (operands[4]) == 5"
8847   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
8848   [(set_attr "type" "load")
8849    (set_attr "length" "8")])
8850
8851 (define_insn ""
8852   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
8853         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
8854    (use (match_operand:SI 2 "immediate_operand" "i"))
8855    (use (match_operand:SI 3 "immediate_operand" "i"))
8856    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
8857    (clobber (reg:SI  6))
8858    (clobber (reg:SI  7))
8859    (clobber (reg:SI  8))
8860    (clobber (reg:SI  9))
8861    (clobber (reg:SI 10))
8862    (clobber (reg:SI 11))
8863    (clobber (reg:SI 12))
8864    (clobber (match_scratch:SI 5 "X"))]
8865   "TARGET_STRING && ! TARGET_POWER
8866    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
8867        || INTVAL (operands[2]) == 0)
8868    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
8869    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
8870    && REGNO (operands[4]) == 5"
8871   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
8872   [(set_attr "type" "load")
8873    (set_attr "length" "8")])
8874
8875 (define_insn ""
8876   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
8877         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
8878    (use (match_operand:SI 2 "immediate_operand" "i"))
8879    (use (match_operand:SI 3 "immediate_operand" "i"))
8880    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
8881    (clobber (reg:SI  6))
8882    (clobber (reg:SI  7))
8883    (clobber (reg:SI  8))
8884    (clobber (reg:SI  9))
8885    (clobber (reg:SI 10))
8886    (clobber (reg:SI 11))
8887    (clobber (reg:SI 12))
8888    (clobber (match_scratch:SI 5 "X"))]
8889   "TARGET_STRING && TARGET_POWERPC64
8890    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
8891        || INTVAL (operands[2]) == 0)
8892    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
8893    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
8894    && REGNO (operands[4]) == 5"
8895   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
8896   [(set_attr "type" "load")
8897    (set_attr "length" "8")])
8898
8899 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
8900 ;; register allocator doesn't have a clue about allocating 6 word registers.
8901 ;; rD/rS = r5 is preferred, efficient form.
8902 (define_expand "movmemsi_6reg"
8903   [(parallel [(set (match_operand 0 "" "")
8904                    (match_operand 1 "" ""))
8905               (use (match_operand 2 "" ""))
8906               (use (match_operand 3 "" ""))
8907               (clobber (reg:SI  5))
8908               (clobber (reg:SI  6))
8909               (clobber (reg:SI  7))
8910               (clobber (reg:SI  8))
8911               (clobber (reg:SI  9))
8912               (clobber (reg:SI 10))
8913               (clobber (match_scratch:SI 4 ""))])]
8914   "TARGET_STRING"
8915   "")
8916
8917 (define_insn ""
8918   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
8919         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
8920    (use (match_operand:SI 2 "immediate_operand" "i"))
8921    (use (match_operand:SI 3 "immediate_operand" "i"))
8922    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
8923    (clobber (reg:SI  6))
8924    (clobber (reg:SI  7))
8925    (clobber (reg:SI  8))
8926    (clobber (reg:SI  9))
8927    (clobber (reg:SI 10))
8928    (clobber (match_scratch:SI 5 "=q"))]
8929   "TARGET_STRING && TARGET_POWER
8930    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
8931    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
8932    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
8933    && REGNO (operands[4]) == 5"
8934   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
8935   [(set_attr "type" "load")
8936    (set_attr "length" "8")])
8937
8938 (define_insn ""
8939   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
8940         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
8941    (use (match_operand:SI 2 "immediate_operand" "i"))
8942    (use (match_operand:SI 3 "immediate_operand" "i"))
8943    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
8944    (clobber (reg:SI  6))
8945    (clobber (reg:SI  7))
8946    (clobber (reg:SI  8))
8947    (clobber (reg:SI  9))
8948    (clobber (reg:SI 10))
8949    (clobber (match_scratch:SI 5 "X"))]
8950   "TARGET_STRING && ! TARGET_POWER
8951    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
8952    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
8953    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
8954    && REGNO (operands[4]) == 5"
8955   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
8956   [(set_attr "type" "load")
8957    (set_attr "length" "8")])
8958
8959 (define_insn ""
8960   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
8961         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
8962    (use (match_operand:SI 2 "immediate_operand" "i"))
8963    (use (match_operand:SI 3 "immediate_operand" "i"))
8964    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
8965    (clobber (reg:SI  6))
8966    (clobber (reg:SI  7))
8967    (clobber (reg:SI  8))
8968    (clobber (reg:SI  9))
8969    (clobber (reg:SI 10))
8970    (clobber (match_scratch:SI 5 "X"))]
8971   "TARGET_STRING && TARGET_POWERPC64
8972    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
8973    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
8974    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
8975    && REGNO (operands[4]) == 5"
8976   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
8977   [(set_attr "type" "load")
8978    (set_attr "length" "8")])
8979
8980 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
8981 ;; problems with TImode.
8982 ;; rD/rS = r5 is preferred, efficient form.
8983 (define_expand "movmemsi_4reg"
8984   [(parallel [(set (match_operand 0 "" "")
8985                    (match_operand 1 "" ""))
8986               (use (match_operand 2 "" ""))
8987               (use (match_operand 3 "" ""))
8988               (clobber (reg:SI 5))
8989               (clobber (reg:SI 6))
8990               (clobber (reg:SI 7))
8991               (clobber (reg:SI 8))
8992               (clobber (match_scratch:SI 4 ""))])]
8993   "TARGET_STRING"
8994   "")
8995
8996 (define_insn ""
8997   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
8998         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
8999    (use (match_operand:SI 2 "immediate_operand" "i"))
9000    (use (match_operand:SI 3 "immediate_operand" "i"))
9001    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9002    (clobber (reg:SI 6))
9003    (clobber (reg:SI 7))
9004    (clobber (reg:SI 8))
9005    (clobber (match_scratch:SI 5 "=q"))]
9006   "TARGET_STRING && TARGET_POWER
9007    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9008    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9009    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9010    && REGNO (operands[4]) == 5"
9011   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9012   [(set_attr "type" "load")
9013    (set_attr "length" "8")])
9014
9015 (define_insn ""
9016   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9017         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9018    (use (match_operand:SI 2 "immediate_operand" "i"))
9019    (use (match_operand:SI 3 "immediate_operand" "i"))
9020    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9021    (clobber (reg:SI 6))
9022    (clobber (reg:SI 7))
9023    (clobber (reg:SI 8))
9024    (clobber (match_scratch:SI 5 "X"))]
9025   "TARGET_STRING && ! TARGET_POWER
9026    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9027    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9028    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9029    && REGNO (operands[4]) == 5"
9030   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9031   [(set_attr "type" "load")
9032    (set_attr "length" "8")])
9033
9034 (define_insn ""
9035   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9036         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9037    (use (match_operand:SI 2 "immediate_operand" "i"))
9038    (use (match_operand:SI 3 "immediate_operand" "i"))
9039    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9040    (clobber (reg:SI 6))
9041    (clobber (reg:SI 7))
9042    (clobber (reg:SI 8))
9043    (clobber (match_scratch:SI 5 "X"))]
9044   "TARGET_STRING && TARGET_POWERPC64
9045    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9046    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9047    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9048    && REGNO (operands[4]) == 5"
9049   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9050   [(set_attr "type" "load")
9051    (set_attr "length" "8")])
9052
9053 ;; Move up to 8 bytes at a time.
9054 (define_expand "movmemsi_2reg"
9055   [(parallel [(set (match_operand 0 "" "")
9056                    (match_operand 1 "" ""))
9057               (use (match_operand 2 "" ""))
9058               (use (match_operand 3 "" ""))
9059               (clobber (match_scratch:DI 4 ""))
9060               (clobber (match_scratch:SI 5 ""))])]
9061   "TARGET_STRING && ! TARGET_POWERPC64"
9062   "")
9063
9064 (define_insn ""
9065   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9066         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9067    (use (match_operand:SI 2 "immediate_operand" "i"))
9068    (use (match_operand:SI 3 "immediate_operand" "i"))
9069    (clobber (match_scratch:DI 4 "=&r"))
9070    (clobber (match_scratch:SI 5 "=q"))]
9071   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
9072    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9073   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9074   [(set_attr "type" "load")
9075    (set_attr "length" "8")])
9076
9077 (define_insn ""
9078   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9079         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9080    (use (match_operand:SI 2 "immediate_operand" "i"))
9081    (use (match_operand:SI 3 "immediate_operand" "i"))
9082    (clobber (match_scratch:DI 4 "=&r"))
9083    (clobber (match_scratch:SI 5 "X"))]
9084   "TARGET_STRING && ! TARGET_POWER && ! TARGET_POWERPC64
9085    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9086   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9087   [(set_attr "type" "load")
9088    (set_attr "length" "8")])
9089
9090 ;; Move up to 4 bytes at a time.
9091 (define_expand "movmemsi_1reg"
9092   [(parallel [(set (match_operand 0 "" "")
9093                    (match_operand 1 "" ""))
9094               (use (match_operand 2 "" ""))
9095               (use (match_operand 3 "" ""))
9096               (clobber (match_scratch:SI 4 ""))
9097               (clobber (match_scratch:SI 5 ""))])]
9098   "TARGET_STRING"
9099   "")
9100
9101 (define_insn ""
9102   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9103         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9104    (use (match_operand:SI 2 "immediate_operand" "i"))
9105    (use (match_operand:SI 3 "immediate_operand" "i"))
9106    (clobber (match_scratch:SI 4 "=&r"))
9107    (clobber (match_scratch:SI 5 "=q"))]
9108   "TARGET_STRING && TARGET_POWER
9109    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9110   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9111   [(set_attr "type" "load")
9112    (set_attr "length" "8")])
9113
9114 (define_insn ""
9115   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9116         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9117    (use (match_operand:SI 2 "immediate_operand" "i"))
9118    (use (match_operand:SI 3 "immediate_operand" "i"))
9119    (clobber (match_scratch:SI 4 "=&r"))
9120    (clobber (match_scratch:SI 5 "X"))]
9121   "TARGET_STRING && ! TARGET_POWER
9122    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9123   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9124   [(set_attr "type" "load")
9125    (set_attr "length" "8")])
9126
9127 (define_insn ""
9128   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9129         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9130    (use (match_operand:SI 2 "immediate_operand" "i"))
9131    (use (match_operand:SI 3 "immediate_operand" "i"))
9132    (clobber (match_scratch:SI 4 "=&r"))
9133    (clobber (match_scratch:SI 5 "X"))]
9134   "TARGET_STRING && TARGET_POWERPC64
9135    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9136   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9137   [(set_attr "type" "load")
9138    (set_attr "length" "8")])
9139
9140 \f
9141 ;; Define insns that do load or store with update.  Some of these we can
9142 ;; get by using pre-decrement or pre-increment, but the hardware can also
9143 ;; do cases where the increment is not the size of the object.
9144 ;;
9145 ;; In all these cases, we use operands 0 and 1 for the register being
9146 ;; incremented because those are the operands that local-alloc will
9147 ;; tie and these are the pair most likely to be tieable (and the ones
9148 ;; that will benefit the most).
9149
9150 (define_insn "*movdi_update1"
9151   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
9152         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9153                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
9154    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9155         (plus:DI (match_dup 1) (match_dup 2)))]
9156   "TARGET_POWERPC64 && TARGET_UPDATE"
9157   "@
9158    ldux %3,%0,%2
9159    ldu %3,%2(%0)"
9160   [(set_attr "type" "load_ux,load_u")])
9161
9162 (define_insn "movdi_<mode>_update"
9163   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
9164                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
9165         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
9166    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
9167         (plus:P (match_dup 1) (match_dup 2)))]
9168   "TARGET_POWERPC64 && TARGET_UPDATE"
9169   "@
9170    stdux %3,%0,%2
9171    stdu %3,%2(%0)"
9172   [(set_attr "type" "store_ux,store_u")])
9173
9174 (define_insn "*movsi_update1"
9175   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9176         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9177                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9178    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9179         (plus:SI (match_dup 1) (match_dup 2)))]
9180   "TARGET_UPDATE"
9181   "@
9182    {lux|lwzux} %3,%0,%2
9183    {lu|lwzu} %3,%2(%0)"
9184   [(set_attr "type" "load_ux,load_u")])
9185
9186 (define_insn "*movsi_update2"
9187   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
9188         (sign_extend:DI
9189          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
9190                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
9191    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
9192         (plus:DI (match_dup 1) (match_dup 2)))]
9193   "TARGET_POWERPC64"
9194   "lwaux %3,%0,%2"
9195   [(set_attr "type" "load_ext_ux")])
9196
9197 (define_insn "movsi_update"
9198   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9199                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9200         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
9201    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9202         (plus:SI (match_dup 1) (match_dup 2)))]
9203   "TARGET_UPDATE"
9204   "@
9205    {stux|stwux} %3,%0,%2
9206    {stu|stwu} %3,%2(%0)"
9207   [(set_attr "type" "store_ux,store_u")])
9208
9209 (define_insn "*movhi_update1"
9210   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
9211         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9212                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9213    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9214         (plus:SI (match_dup 1) (match_dup 2)))]
9215   "TARGET_UPDATE"
9216   "@
9217    lhzux %3,%0,%2
9218    lhzu %3,%2(%0)"
9219   [(set_attr "type" "load_ux,load_u")])
9220
9221 (define_insn "*movhi_update2"
9222   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9223         (zero_extend:SI
9224          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9225                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9226    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9227         (plus:SI (match_dup 1) (match_dup 2)))]
9228   "TARGET_UPDATE"
9229   "@
9230    lhzux %3,%0,%2
9231    lhzu %3,%2(%0)"
9232   [(set_attr "type" "load_ux,load_u")])
9233
9234 (define_insn "*movhi_update3"
9235   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9236         (sign_extend:SI
9237          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9238                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9239    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9240         (plus:SI (match_dup 1) (match_dup 2)))]
9241   "TARGET_UPDATE"
9242   "@
9243    lhaux %3,%0,%2
9244    lhau %3,%2(%0)"
9245   [(set_attr "type" "load_ext_ux,load_ext_u")])
9246
9247 (define_insn "*movhi_update4"
9248   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9249                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9250         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
9251    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9252         (plus:SI (match_dup 1) (match_dup 2)))]
9253   "TARGET_UPDATE"
9254   "@
9255    sthux %3,%0,%2
9256    sthu %3,%2(%0)"
9257   [(set_attr "type" "store_ux,store_u")])
9258
9259 (define_insn "*movqi_update1"
9260   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
9261         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9262                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9263    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9264         (plus:SI (match_dup 1) (match_dup 2)))]
9265   "TARGET_UPDATE"
9266   "@
9267    lbzux %3,%0,%2
9268    lbzu %3,%2(%0)"
9269   [(set_attr "type" "load_ux,load_u")])
9270
9271 (define_insn "*movqi_update2"
9272   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9273         (zero_extend:SI
9274          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9275                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9276    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9277         (plus:SI (match_dup 1) (match_dup 2)))]
9278   "TARGET_UPDATE"
9279   "@
9280    lbzux %3,%0,%2
9281    lbzu %3,%2(%0)"
9282   [(set_attr "type" "load_ux,load_u")])
9283
9284 (define_insn "*movqi_update3"
9285   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9286                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9287         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
9288    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9289         (plus:SI (match_dup 1) (match_dup 2)))]
9290   "TARGET_UPDATE"
9291   "@
9292    stbux %3,%0,%2
9293    stbu %3,%2(%0)"
9294   [(set_attr "type" "store_ux,store_u")])
9295
9296 (define_insn "*movsf_update1"
9297   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
9298         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9299                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9300    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9301         (plus:SI (match_dup 1) (match_dup 2)))]
9302   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9303   "@
9304    lfsux %3,%0,%2
9305    lfsu %3,%2(%0)"
9306   [(set_attr "type" "fpload_ux,fpload_u")])
9307
9308 (define_insn "*movsf_update2"
9309   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9310                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9311         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
9312    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9313         (plus:SI (match_dup 1) (match_dup 2)))]
9314   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9315   "@
9316    stfsux %3,%0,%2
9317    stfsu %3,%2(%0)"
9318   [(set_attr "type" "fpstore_ux,fpstore_u")])
9319
9320 (define_insn "*movsf_update3"
9321   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
9322         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9323                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9324    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9325         (plus:SI (match_dup 1) (match_dup 2)))]
9326   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9327   "@
9328    {lux|lwzux} %3,%0,%2
9329    {lu|lwzu} %3,%2(%0)"
9330   [(set_attr "type" "load_ux,load_u")])
9331
9332 (define_insn "*movsf_update4"
9333   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9334                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9335         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
9336    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9337         (plus:SI (match_dup 1) (match_dup 2)))]
9338   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9339   "@
9340    {stux|stwux} %3,%0,%2
9341    {stu|stwu} %3,%2(%0)"
9342   [(set_attr "type" "store_ux,store_u")])
9343
9344 (define_insn "*movdf_update1"
9345   [(set (match_operand:DF 3 "gpc_reg_operand" "=f,f")
9346         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9347                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9348    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9349         (plus:SI (match_dup 1) (match_dup 2)))]
9350   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9351   "@
9352    lfdux %3,%0,%2
9353    lfdu %3,%2(%0)"
9354   [(set_attr "type" "fpload_ux,fpload_u")])
9355
9356 (define_insn "*movdf_update2"
9357   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9358                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9359         (match_operand:DF 3 "gpc_reg_operand" "f,f"))
9360    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9361         (plus:SI (match_dup 1) (match_dup 2)))]
9362   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9363   "@
9364    stfdux %3,%0,%2
9365    stfdu %3,%2(%0)"
9366   [(set_attr "type" "fpstore_ux,fpstore_u")])
9367
9368 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
9369
9370 (define_insn "*lfq_power2"
9371   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
9372         (match_operand:TF 1 "memory_operand" ""))]
9373   "TARGET_POWER2
9374    && TARGET_HARD_FLOAT && TARGET_FPRS"
9375    "lfq%U1%X1 %0,%1")
9376
9377 (define_peephole2
9378   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9379         (match_operand:DF 1 "memory_operand" ""))
9380    (set (match_operand:DF 2 "gpc_reg_operand" "")
9381         (match_operand:DF 3 "memory_operand" ""))]
9382   "TARGET_POWER2
9383    && TARGET_HARD_FLOAT && TARGET_FPRS
9384    && registers_ok_for_quad_peep (operands[0], operands[2])
9385    && mems_ok_for_quad_peep (operands[1], operands[3])"
9386   [(set (match_dup 0)
9387         (match_dup 1))]
9388   "operands[1] = widen_memory_access (operands[1], TFmode, 0);
9389    operands[0] = gen_rtx_REG (TFmode, REGNO (operands[0]));")
9390
9391 (define_insn "*stfq_power2"
9392   [(set (match_operand:TF 0 "memory_operand" "")
9393         (match_operand:TF 1 "gpc_reg_operand" "f"))]
9394   "TARGET_POWER2
9395    && TARGET_HARD_FLOAT && TARGET_FPRS"
9396   "stfq%U0%X0 %1,%0")
9397
9398
9399 (define_peephole2
9400   [(set (match_operand:DF 0 "memory_operand" "")
9401         (match_operand:DF 1 "gpc_reg_operand" ""))
9402    (set (match_operand:DF 2 "memory_operand" "")
9403         (match_operand:DF 3 "gpc_reg_operand" ""))]
9404   "TARGET_POWER2
9405    && TARGET_HARD_FLOAT && TARGET_FPRS
9406    && registers_ok_for_quad_peep (operands[1], operands[3])
9407    && mems_ok_for_quad_peep (operands[0], operands[2])"
9408   [(set (match_dup 0)
9409         (match_dup 1))]
9410   "operands[0] = widen_memory_access (operands[0], TFmode, 0);
9411    operands[1] = gen_rtx_REG (TFmode, REGNO (operands[1]));")
9412
9413 ;; after inserting conditional returns we can sometimes have
9414 ;; unnecessary register moves.  Unfortunately we cannot have a
9415 ;; modeless peephole here, because some single SImode sets have early
9416 ;; clobber outputs.  Although those sets expand to multi-ppc-insn
9417 ;; sequences, using get_attr_length here will smash the operands
9418 ;; array.  Neither is there an early_cobbler_p predicate.
9419 (define_peephole2
9420   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9421         (match_operand:DF 1 "any_operand" ""))
9422    (set (match_operand:DF 2 "gpc_reg_operand" "")
9423         (match_dup 0))]
9424   "peep2_reg_dead_p (2, operands[0])"
9425   [(set (match_dup 2) (match_dup 1))])
9426
9427 (define_peephole2
9428   [(set (match_operand:SF 0 "gpc_reg_operand" "")
9429         (match_operand:SF 1 "any_operand" ""))
9430    (set (match_operand:SF 2 "gpc_reg_operand" "")
9431         (match_dup 0))]
9432   "peep2_reg_dead_p (2, operands[0])"
9433   [(set (match_dup 2) (match_dup 1))])
9434
9435 \f
9436 ;; TLS support.
9437
9438 ;; "b" output constraint here and on tls_ld to support tls linker optimization.
9439 (define_insn "tls_gd_32"
9440   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9441         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9442                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9443                    UNSPEC_TLSGD))]
9444   "HAVE_AS_TLS && !TARGET_64BIT"
9445   "addi %0,%1,%2@got@tlsgd")
9446
9447 (define_insn "tls_gd_64"
9448   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9449         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9450                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9451                    UNSPEC_TLSGD))]
9452   "HAVE_AS_TLS && TARGET_64BIT"
9453   "addi %0,%1,%2@got@tlsgd")
9454
9455 (define_insn "tls_ld_32"
9456   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9457         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")]
9458                    UNSPEC_TLSLD))]
9459   "HAVE_AS_TLS && !TARGET_64BIT"
9460   "addi %0,%1,%&@got@tlsld")
9461
9462 (define_insn "tls_ld_64"
9463   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9464         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")]
9465                    UNSPEC_TLSLD))]
9466   "HAVE_AS_TLS && TARGET_64BIT"
9467   "addi %0,%1,%&@got@tlsld")
9468
9469 (define_insn "tls_dtprel_32"
9470   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9471         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9472                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9473                    UNSPEC_TLSDTPREL))]
9474   "HAVE_AS_TLS && !TARGET_64BIT"
9475   "addi %0,%1,%2@dtprel")
9476
9477 (define_insn "tls_dtprel_64"
9478   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9479         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9480                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9481                    UNSPEC_TLSDTPREL))]
9482   "HAVE_AS_TLS && TARGET_64BIT"
9483   "addi %0,%1,%2@dtprel")
9484
9485 (define_insn "tls_dtprel_ha_32"
9486   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9487         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9488                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9489                    UNSPEC_TLSDTPRELHA))]
9490   "HAVE_AS_TLS && !TARGET_64BIT"
9491   "addis %0,%1,%2@dtprel@ha")
9492
9493 (define_insn "tls_dtprel_ha_64"
9494   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9495         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9496                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9497                    UNSPEC_TLSDTPRELHA))]
9498   "HAVE_AS_TLS && TARGET_64BIT"
9499   "addis %0,%1,%2@dtprel@ha")
9500
9501 (define_insn "tls_dtprel_lo_32"
9502   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9503         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9504                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9505                    UNSPEC_TLSDTPRELLO))]
9506   "HAVE_AS_TLS && !TARGET_64BIT"
9507   "addi %0,%1,%2@dtprel@l")
9508
9509 (define_insn "tls_dtprel_lo_64"
9510   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9511         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9512                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9513                    UNSPEC_TLSDTPRELLO))]
9514   "HAVE_AS_TLS && TARGET_64BIT"
9515   "addi %0,%1,%2@dtprel@l")
9516
9517 (define_insn "tls_got_dtprel_32"
9518   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9519         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9520                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9521                    UNSPEC_TLSGOTDTPREL))]
9522   "HAVE_AS_TLS && !TARGET_64BIT"
9523   "lwz %0,%2@got@dtprel(%1)")
9524
9525 (define_insn "tls_got_dtprel_64"
9526   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9527         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9528                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9529                    UNSPEC_TLSGOTDTPREL))]
9530   "HAVE_AS_TLS && TARGET_64BIT"
9531   "ld %0,%2@got@dtprel(%1)")
9532
9533 (define_insn "tls_tprel_32"
9534   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9535         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9536                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9537                    UNSPEC_TLSTPREL))]
9538   "HAVE_AS_TLS && !TARGET_64BIT"
9539   "addi %0,%1,%2@tprel")
9540
9541 (define_insn "tls_tprel_64"
9542   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9543         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9544                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9545                    UNSPEC_TLSTPREL))]
9546   "HAVE_AS_TLS && TARGET_64BIT"
9547   "addi %0,%1,%2@tprel")
9548
9549 (define_insn "tls_tprel_ha_32"
9550   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9551         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9552                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9553                    UNSPEC_TLSTPRELHA))]
9554   "HAVE_AS_TLS && !TARGET_64BIT"
9555   "addis %0,%1,%2@tprel@ha")
9556
9557 (define_insn "tls_tprel_ha_64"
9558   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9559         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9560                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9561                    UNSPEC_TLSTPRELHA))]
9562   "HAVE_AS_TLS && TARGET_64BIT"
9563   "addis %0,%1,%2@tprel@ha")
9564
9565 (define_insn "tls_tprel_lo_32"
9566   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9567         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9568                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9569                    UNSPEC_TLSTPRELLO))]
9570   "HAVE_AS_TLS && !TARGET_64BIT"
9571   "addi %0,%1,%2@tprel@l")
9572
9573 (define_insn "tls_tprel_lo_64"
9574   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9575         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9576                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9577                    UNSPEC_TLSTPRELLO))]
9578   "HAVE_AS_TLS && TARGET_64BIT"
9579   "addi %0,%1,%2@tprel@l")
9580
9581 ;; "b" output constraint here and on tls_tls input to support linker tls
9582 ;; optimization.  The linker may edit the instructions emitted by a
9583 ;; tls_got_tprel/tls_tls pair to addis,addi.
9584 (define_insn "tls_got_tprel_32"
9585   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9586         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9587                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9588                    UNSPEC_TLSGOTTPREL))]
9589   "HAVE_AS_TLS && !TARGET_64BIT"
9590   "lwz %0,%2@got@tprel(%1)")
9591
9592 (define_insn "tls_got_tprel_64"
9593   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9594         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9595                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9596                    UNSPEC_TLSGOTTPREL))]
9597   "HAVE_AS_TLS && TARGET_64BIT"
9598   "ld %0,%2@got@tprel(%1)")
9599
9600 (define_insn "tls_tls_32"
9601   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9602         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9603                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9604                    UNSPEC_TLSTLS))]
9605   "HAVE_AS_TLS && !TARGET_64BIT"
9606   "add %0,%1,%2@tls")
9607
9608 (define_insn "tls_tls_64"
9609   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9610         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9611                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9612                    UNSPEC_TLSTLS))]
9613   "HAVE_AS_TLS && TARGET_64BIT"
9614   "add %0,%1,%2@tls")
9615 \f
9616 ;; Next come insns related to the calling sequence.
9617 ;;
9618 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
9619 ;; We move the back-chain and decrement the stack pointer.
9620
9621 (define_expand "allocate_stack"
9622   [(set (match_operand 0 "gpc_reg_operand" "=r")
9623         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
9624    (set (reg 1)
9625         (minus (reg 1) (match_dup 1)))]
9626   ""
9627   "
9628 { rtx chain = gen_reg_rtx (Pmode);
9629   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
9630   rtx neg_op0;
9631
9632   emit_move_insn (chain, stack_bot);
9633
9634   /* Check stack bounds if necessary.  */
9635   if (current_function_limit_stack)
9636     {
9637       rtx available;
9638       available = expand_binop (Pmode, sub_optab,
9639                                 stack_pointer_rtx, stack_limit_rtx,
9640                                 NULL_RTX, 1, OPTAB_WIDEN);
9641       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
9642     }
9643
9644   if (GET_CODE (operands[1]) != CONST_INT
9645       || INTVAL (operands[1]) < -32767
9646       || INTVAL (operands[1]) > 32768)
9647     {
9648       neg_op0 = gen_reg_rtx (Pmode);
9649       if (TARGET_32BIT)
9650         emit_insn (gen_negsi2 (neg_op0, operands[1]));
9651       else
9652         emit_insn (gen_negdi2 (neg_op0, operands[1]));
9653     }
9654   else
9655     neg_op0 = GEN_INT (- INTVAL (operands[1]));
9656
9657   if (TARGET_UPDATE)
9658     emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update : gen_movdi_di_update))
9659                 (stack_pointer_rtx, stack_pointer_rtx, neg_op0, chain));
9660
9661   else
9662     {
9663       emit_insn ((* ((TARGET_32BIT) ? gen_addsi3 : gen_adddi3))
9664                  (stack_pointer_rtx, stack_pointer_rtx, neg_op0));
9665       emit_move_insn (gen_rtx_MEM (Pmode, stack_pointer_rtx), chain);
9666     }
9667
9668   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
9669   DONE;
9670 }")
9671
9672 ;; These patterns say how to save and restore the stack pointer.  We need not
9673 ;; save the stack pointer at function level since we are careful to
9674 ;; preserve the backchain.  At block level, we have to restore the backchain
9675 ;; when we restore the stack pointer.
9676 ;;
9677 ;; For nonlocal gotos, we must save both the stack pointer and its
9678 ;; backchain and restore both.  Note that in the nonlocal case, the
9679 ;; save area is a memory location.
9680
9681 (define_expand "save_stack_function"
9682   [(match_operand 0 "any_operand" "")
9683    (match_operand 1 "any_operand" "")]
9684   ""
9685   "DONE;")
9686
9687 (define_expand "restore_stack_function"
9688   [(match_operand 0 "any_operand" "")
9689    (match_operand 1 "any_operand" "")]
9690   ""
9691   "DONE;")
9692
9693 (define_expand "restore_stack_block"
9694   [(use (match_operand 0 "register_operand" ""))
9695    (set (match_dup 2) (match_dup 3))
9696    (set (match_dup 0) (match_operand 1 "register_operand" ""))
9697    (set (match_dup 3) (match_dup 2))]
9698   ""
9699   "
9700 {
9701   operands[2] = gen_reg_rtx (Pmode);
9702   operands[3] = gen_rtx_MEM (Pmode, operands[0]);
9703 }")
9704
9705 (define_expand "save_stack_nonlocal"
9706   [(match_operand 0 "memory_operand" "")
9707    (match_operand 1 "register_operand" "")]
9708   ""
9709   "
9710 {
9711   rtx temp = gen_reg_rtx (Pmode);
9712   int units_per_word = (TARGET_32BIT) ? 4 : 8;
9713
9714   /* Copy the backchain to the first word, sp to the second.  */
9715   emit_move_insn (temp, gen_rtx_MEM (Pmode, operands[1]));
9716   emit_move_insn (adjust_address_nv (operands[0], Pmode, 0), temp);
9717   emit_move_insn (adjust_address_nv (operands[0], Pmode, units_per_word),
9718                   operands[1]);
9719   DONE;
9720 }")
9721
9722 (define_expand "restore_stack_nonlocal"
9723   [(match_operand 0 "register_operand" "")
9724    (match_operand 1 "memory_operand" "")]
9725   ""
9726   "
9727 {
9728   rtx temp = gen_reg_rtx (Pmode);
9729   int units_per_word = (TARGET_32BIT) ? 4 : 8;
9730
9731   /* Restore the backchain from the first word, sp from the second.  */
9732   emit_move_insn (temp,
9733                   adjust_address_nv (operands[1], Pmode, 0));
9734   emit_move_insn (operands[0],
9735                   adjust_address_nv (operands[1], Pmode, units_per_word));
9736   emit_move_insn (gen_rtx_MEM (Pmode, operands[0]), temp);
9737   DONE;
9738 }")
9739 \f
9740 ;; TOC register handling.
9741
9742 ;; Code to initialize the TOC register...
9743
9744 (define_insn "load_toc_aix_si"
9745   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9746                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
9747               (use (reg:SI 2))])]
9748   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
9749   "*
9750 {
9751   char buf[30];
9752   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
9753   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9754   operands[2] = gen_rtx_REG (Pmode, 2);
9755   return \"{l|lwz} %0,%1(%2)\";
9756 }"
9757   [(set_attr "type" "load")])
9758
9759 (define_insn "load_toc_aix_di"
9760   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9761                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
9762               (use (reg:DI 2))])]
9763   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
9764   "*
9765 {
9766   char buf[30];
9767 #ifdef TARGET_RELOCATABLE
9768   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
9769                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
9770 #else
9771   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
9772 #endif
9773   if (TARGET_ELF)
9774     strcat (buf, \"@toc\");
9775   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9776   operands[2] = gen_rtx_REG (Pmode, 2);
9777   return \"ld %0,%1(%2)\";
9778 }"
9779   [(set_attr "type" "load")])
9780
9781 (define_insn "load_toc_v4_pic_si"
9782   [(set (match_operand:SI 0 "register_operand" "=l")
9783         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
9784   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
9785   "bl _GLOBAL_OFFSET_TABLE_@local-4"
9786   [(set_attr "type" "branch")
9787    (set_attr "length" "4")])
9788
9789 (define_insn "load_toc_v4_PIC_1"
9790   [(set (match_operand:SI 0 "register_operand" "=l")
9791         (match_operand:SI 1 "immediate_operand" "s"))
9792    (use (unspec [(match_dup 1)] UNSPEC_TOC))]
9793   "TARGET_ELF && DEFAULT_ABI != ABI_AIX
9794    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
9795   "bcl 20,31,%1\\n%1:"
9796   [(set_attr "type" "branch")
9797    (set_attr "length" "4")])
9798
9799 (define_insn "load_toc_v4_PIC_1b"
9800   [(set (match_operand:SI 0 "register_operand" "=l")
9801         (unspec:SI [(match_operand:SI 1 "immediate_operand" "s")]
9802                 UNSPEC_TOCPTR))]
9803   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
9804   "bcl 20,31,$+8\\n\\t.long %1-$"
9805   [(set_attr "type" "branch")
9806    (set_attr "length" "8")])
9807
9808 (define_insn "load_toc_v4_PIC_2"
9809   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9810         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
9811                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
9812                              (match_operand:SI 3 "immediate_operand" "s")))))]
9813   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
9814   "{l|lwz} %0,%2-%3(%1)"
9815   [(set_attr "type" "load")])
9816
9817 (define_insn "load_toc_v4_PIC_3b"
9818   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9819         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
9820                  (high:SI
9821                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
9822                              (match_operand:SI 3 "symbol_ref_operand" "s")))))]
9823   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
9824   "{cau|addis} %0,%1,%2-%3@ha")
9825
9826 (define_insn "load_toc_v4_PIC_3c"
9827   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9828         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
9829                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
9830                              (match_operand:SI 3 "symbol_ref_operand" "s"))))]
9831   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
9832   "{cal|addi} %0,%1,%2-%3@l")
9833
9834 ;; If the TOC is shared over a translation unit, as happens with all
9835 ;; the kinds of PIC that we support, we need to restore the TOC
9836 ;; pointer only when jumping over units of translation.
9837 ;; On Darwin, we need to reload the picbase.
9838
9839 (define_expand "builtin_setjmp_receiver"
9840   [(use (label_ref (match_operand 0 "" "")))]
9841   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
9842    || (TARGET_TOC && TARGET_MINIMAL_TOC)
9843    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
9844   "
9845 {
9846 #if TARGET_MACHO
9847   if (DEFAULT_ABI == ABI_DARWIN)
9848     {
9849       const char *picbase = machopic_function_base_name ();
9850       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (picbase));
9851       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
9852       rtx tmplabrtx;
9853       char tmplab[20];
9854
9855       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
9856                                   CODE_LABEL_NUMBER (operands[0]));
9857       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
9858
9859       emit_insn (gen_load_macho_picbase (picreg, tmplabrtx));
9860       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
9861     }
9862   else
9863 #endif
9864     rs6000_emit_load_toc_table (FALSE);
9865   DONE;
9866 }")
9867
9868 ;; Elf specific ways of loading addresses for non-PIC code.
9869 ;; The output of this could be r0, but we make a very strong
9870 ;; preference for a base register because it will usually
9871 ;; be needed there.
9872 (define_insn "elf_high"
9873   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
9874         (high:SI (match_operand 1 "" "")))]
9875   "TARGET_ELF && ! TARGET_64BIT"
9876   "{liu|lis} %0,%1@ha")
9877
9878 (define_insn "elf_low"
9879   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
9880         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
9881                    (match_operand 2 "" "")))]
9882    "TARGET_ELF && ! TARGET_64BIT"
9883    "@
9884     {cal|la} %0,%2@l(%1)
9885     {ai|addic} %0,%1,%K2")
9886 \f
9887 ;; A function pointer under AIX is a pointer to a data area whose first word
9888 ;; contains the actual address of the function, whose second word contains a
9889 ;; pointer to its TOC, and whose third word contains a value to place in the
9890 ;; static chain register (r11).  Note that if we load the static chain, our
9891 ;; "trampoline" need not have any executable code.
9892
9893 (define_expand "call_indirect_aix32"
9894   [(set (match_dup 2)
9895         (mem:SI (match_operand:SI 0 "gpc_reg_operand" "")))
9896    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
9897         (reg:SI 2))
9898    (set (reg:SI 2)
9899         (mem:SI (plus:SI (match_dup 0)
9900                          (const_int 4))))
9901    (set (reg:SI 11)
9902         (mem:SI (plus:SI (match_dup 0)
9903                          (const_int 8))))
9904    (parallel [(call (mem:SI (match_dup 2))
9905                     (match_operand 1 "" ""))
9906               (use (reg:SI 2))
9907               (use (reg:SI 11))
9908               (set (reg:SI 2)
9909                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
9910               (clobber (scratch:SI))])]
9911   "TARGET_32BIT"
9912   "
9913 { operands[2] = gen_reg_rtx (SImode); }")
9914
9915 (define_expand "call_indirect_aix64"
9916   [(set (match_dup 2)
9917         (mem:DI (match_operand:DI 0 "gpc_reg_operand" "")))
9918    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
9919         (reg:DI 2))
9920    (set (reg:DI 2)
9921         (mem:DI (plus:DI (match_dup 0)
9922                          (const_int 8))))
9923    (set (reg:DI 11)
9924         (mem:DI (plus:DI (match_dup 0)
9925                          (const_int 16))))
9926    (parallel [(call (mem:SI (match_dup 2))
9927                     (match_operand 1 "" ""))
9928               (use (reg:DI 2))
9929               (use (reg:DI 11))
9930               (set (reg:DI 2)
9931                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
9932               (clobber (scratch:SI))])]
9933   "TARGET_64BIT"
9934   "
9935 { operands[2] = gen_reg_rtx (DImode); }")
9936
9937 (define_expand "call_value_indirect_aix32"
9938   [(set (match_dup 3)
9939         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
9940    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
9941         (reg:SI 2))
9942    (set (reg:SI 2)
9943         (mem:SI (plus:SI (match_dup 1)
9944                          (const_int 4))))
9945    (set (reg:SI 11)
9946         (mem:SI (plus:SI (match_dup 1)
9947                          (const_int 8))))
9948    (parallel [(set (match_operand 0 "" "")
9949                    (call (mem:SI (match_dup 3))
9950                          (match_operand 2 "" "")))
9951               (use (reg:SI 2))
9952               (use (reg:SI 11))
9953               (set (reg:SI 2)
9954                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
9955               (clobber (scratch:SI))])]
9956   "TARGET_32BIT"
9957   "
9958 { operands[3] = gen_reg_rtx (SImode); }")
9959
9960 (define_expand "call_value_indirect_aix64"
9961   [(set (match_dup 3)
9962         (mem:DI (match_operand:DI 1 "gpc_reg_operand" "")))
9963    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
9964         (reg:DI 2))
9965    (set (reg:DI 2)
9966         (mem:DI (plus:DI (match_dup 1)
9967                          (const_int 8))))
9968    (set (reg:DI 11)
9969         (mem:DI (plus:DI (match_dup 1)
9970                          (const_int 16))))
9971    (parallel [(set (match_operand 0 "" "")
9972                    (call (mem:SI (match_dup 3))
9973                          (match_operand 2 "" "")))
9974               (use (reg:DI 2))
9975               (use (reg:DI 11))
9976               (set (reg:DI 2)
9977                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
9978               (clobber (scratch:SI))])]
9979   "TARGET_64BIT"
9980   "
9981 { operands[3] = gen_reg_rtx (DImode); }")
9982
9983 ;; Now the definitions for the call and call_value insns
9984 (define_expand "call"
9985   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
9986                     (match_operand 1 "" ""))
9987               (use (match_operand 2 "" ""))
9988               (clobber (scratch:SI))])]
9989   ""
9990   "
9991 {
9992 #if TARGET_MACHO
9993   if (MACHOPIC_INDIRECT)
9994     operands[0] = machopic_indirect_call_target (operands[0]);
9995 #endif
9996
9997   gcc_assert (GET_CODE (operands[0]) == MEM);
9998   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
9999
10000   operands[0] = XEXP (operands[0], 0);
10001
10002   if (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT
10003       && flag_pic
10004       && GET_CODE (operands[0]) == SYMBOL_REF
10005       && !SYMBOL_REF_LOCAL_P (operands[0]))
10006     {
10007       rtx call;
10008       rtvec tmp;
10009
10010       tmp = gen_rtvec (3,
10011                        gen_rtx_CALL (VOIDmode,
10012                                      gen_rtx_MEM (SImode, operands[0]),
10013                                      operands[1]),
10014                        gen_rtx_USE (VOIDmode, operands[2]),
10015                        gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (SImode)));
10016       call = emit_call_insn (gen_rtx_PARALLEL (VOIDmode, tmp));
10017       use_reg (&CALL_INSN_FUNCTION_USAGE (call), pic_offset_table_rtx);
10018       DONE;
10019     }
10020
10021   if (GET_CODE (operands[0]) != SYMBOL_REF
10022       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
10023       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
10024     {
10025       if (INTVAL (operands[2]) & CALL_LONG)
10026         operands[0] = rs6000_longcall_ref (operands[0]);
10027
10028       switch (DEFAULT_ABI)
10029         {
10030         case ABI_V4:
10031         case ABI_DARWIN:
10032           operands[0] = force_reg (Pmode, operands[0]);
10033           break;
10034
10035         case ABI_AIX:
10036           /* AIX function pointers are really pointers to a three word
10037              area.  */
10038           emit_call_insn (TARGET_32BIT
10039                           ? gen_call_indirect_aix32 (force_reg (SImode,
10040                                                                 operands[0]),
10041                                                      operands[1])
10042                           : gen_call_indirect_aix64 (force_reg (DImode,
10043                                                                 operands[0]),
10044                                                      operands[1]));
10045           DONE;
10046
10047         default:
10048           gcc_unreachable ();
10049         }
10050     }
10051 }")
10052
10053 (define_expand "call_value"
10054   [(parallel [(set (match_operand 0 "" "")
10055                    (call (mem:SI (match_operand 1 "address_operand" ""))
10056                          (match_operand 2 "" "")))
10057               (use (match_operand 3 "" ""))
10058               (clobber (scratch:SI))])]
10059   ""
10060   "
10061 {
10062 #if TARGET_MACHO
10063   if (MACHOPIC_INDIRECT)
10064     operands[1] = machopic_indirect_call_target (operands[1]);
10065 #endif
10066
10067   gcc_assert (GET_CODE (operands[1]) == MEM);
10068   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
10069
10070   operands[1] = XEXP (operands[1], 0);
10071
10072   if (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT
10073       && flag_pic
10074       && GET_CODE (operands[1]) == SYMBOL_REF
10075       && !SYMBOL_REF_LOCAL_P (operands[1]))
10076     {
10077       rtx call;
10078       rtvec tmp;
10079
10080       tmp = gen_rtvec (3,
10081                        gen_rtx_SET (VOIDmode,
10082                                     operands[0],
10083                                     gen_rtx_CALL (VOIDmode,
10084                                                   gen_rtx_MEM (SImode,
10085                                                                operands[1]),
10086                                                   operands[2])),
10087                        gen_rtx_USE (VOIDmode, operands[3]),
10088                        gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (SImode)));
10089       call = emit_call_insn (gen_rtx_PARALLEL (VOIDmode, tmp));
10090       use_reg (&CALL_INSN_FUNCTION_USAGE (call), pic_offset_table_rtx);
10091       DONE;
10092     }
10093
10094   if (GET_CODE (operands[1]) != SYMBOL_REF
10095       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
10096       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
10097     {
10098       if (INTVAL (operands[3]) & CALL_LONG)
10099         operands[1] = rs6000_longcall_ref (operands[1]);
10100
10101       switch (DEFAULT_ABI)
10102         {
10103         case ABI_V4:
10104         case ABI_DARWIN:
10105           operands[1] = force_reg (Pmode, operands[1]);
10106           break;
10107
10108         case ABI_AIX:
10109           /* AIX function pointers are really pointers to a three word
10110              area.  */
10111           emit_call_insn (TARGET_32BIT
10112                           ? gen_call_value_indirect_aix32 (operands[0],
10113                                                            force_reg (SImode,
10114                                                                       operands[1]),
10115                                                            operands[2])
10116                           : gen_call_value_indirect_aix64 (operands[0],
10117                                                            force_reg (DImode,
10118                                                                       operands[1]),
10119                                                            operands[2]));
10120           DONE;
10121
10122         default:
10123           gcc_unreachable ();
10124         }
10125     }
10126 }")
10127
10128 ;; Call to function in current module.  No TOC pointer reload needed.
10129 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10130 ;; either the function was not prototyped, or it was prototyped as a
10131 ;; variable argument function.  It is > 0 if FP registers were passed
10132 ;; and < 0 if they were not.
10133
10134 (define_insn "*call_local32"
10135   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10136          (match_operand 1 "" "g,g"))
10137    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10138    (clobber (match_scratch:SI 3 "=l,l"))]
10139   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10140   "*
10141 {
10142   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10143     output_asm_insn (\"crxor 6,6,6\", operands);
10144
10145   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10146     output_asm_insn (\"creqv 6,6,6\", operands);
10147
10148   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10149 }"
10150   [(set_attr "type" "branch")
10151    (set_attr "length" "4,8")])
10152
10153 (define_insn "*call_local64"
10154   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10155          (match_operand 1 "" "g,g"))
10156    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10157    (clobber (match_scratch:SI 3 "=l,l"))]
10158   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10159   "*
10160 {
10161   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10162     output_asm_insn (\"crxor 6,6,6\", operands);
10163
10164   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10165     output_asm_insn (\"creqv 6,6,6\", operands);
10166
10167   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10168 }"
10169   [(set_attr "type" "branch")
10170    (set_attr "length" "4,8")])
10171
10172 (define_insn "*call_value_local32"
10173   [(set (match_operand 0 "" "")
10174         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10175               (match_operand 2 "" "g,g")))
10176    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10177    (clobber (match_scratch:SI 4 "=l,l"))]
10178   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10179   "*
10180 {
10181   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10182     output_asm_insn (\"crxor 6,6,6\", operands);
10183
10184   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10185     output_asm_insn (\"creqv 6,6,6\", operands);
10186
10187   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10188 }"
10189   [(set_attr "type" "branch")
10190    (set_attr "length" "4,8")])
10191
10192
10193 (define_insn "*call_value_local64"
10194   [(set (match_operand 0 "" "")
10195         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10196               (match_operand 2 "" "g,g")))
10197    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10198    (clobber (match_scratch:SI 4 "=l,l"))]
10199   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10200   "*
10201 {
10202   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10203     output_asm_insn (\"crxor 6,6,6\", operands);
10204
10205   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10206     output_asm_insn (\"creqv 6,6,6\", operands);
10207
10208   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10209 }"
10210   [(set_attr "type" "branch")
10211    (set_attr "length" "4,8")])
10212
10213 ;; Call to function which may be in another module.  Restore the TOC
10214 ;; pointer (r2) after the call unless this is System V.
10215 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10216 ;; either the function was not prototyped, or it was prototyped as a
10217 ;; variable argument function.  It is > 0 if FP registers were passed
10218 ;; and < 0 if they were not.
10219
10220 (define_insn "*call_indirect_nonlocal_aix32"
10221   [(call (mem:SI (match_operand:SI 0 "register_operand" "cl"))
10222          (match_operand 1 "" "g"))
10223    (use (reg:SI 2))
10224    (use (reg:SI 11))
10225    (set (reg:SI 2)
10226         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10227    (clobber (match_scratch:SI 2 "=l"))]
10228   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10229   "b%T0l\;{l|lwz} 2,20(1)"
10230   [(set_attr "type" "jmpreg")
10231    (set_attr "length" "8")])
10232
10233 (define_insn "*call_nonlocal_aix32"
10234   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10235          (match_operand 1 "" "g"))
10236    (use (match_operand:SI 2 "immediate_operand" "O"))
10237    (clobber (match_scratch:SI 3 "=l"))]
10238   "TARGET_32BIT
10239    && DEFAULT_ABI == ABI_AIX
10240    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10241   "bl %z0\;%."
10242   [(set_attr "type" "branch")
10243    (set_attr "length" "8")])
10244
10245 (define_insn "*call_indirect_nonlocal_aix64"
10246   [(call (mem:SI (match_operand:DI 0 "register_operand" "cl"))
10247          (match_operand 1 "" "g"))
10248    (use (reg:DI 2))
10249    (use (reg:DI 11))
10250    (set (reg:DI 2)
10251         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10252    (clobber (match_scratch:SI 2 "=l"))]
10253   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10254   "b%T0l\;ld 2,40(1)"
10255   [(set_attr "type" "jmpreg")
10256    (set_attr "length" "8")])
10257
10258 (define_insn "*call_nonlocal_aix64"
10259   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10260          (match_operand 1 "" "g"))
10261    (use (match_operand:SI 2 "immediate_operand" "O"))
10262    (clobber (match_scratch:SI 3 "=l"))]
10263   "TARGET_64BIT
10264    && DEFAULT_ABI == ABI_AIX
10265    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10266   "bl %z0\;%."
10267   [(set_attr "type" "branch")
10268    (set_attr "length" "8")])
10269
10270 (define_insn "*call_value_indirect_nonlocal_aix32"
10271   [(set (match_operand 0 "" "")
10272         (call (mem:SI (match_operand:SI 1 "register_operand" "cl"))
10273               (match_operand 2 "" "g")))
10274    (use (reg:SI 2))
10275    (use (reg:SI 11))
10276    (set (reg:SI 2)
10277         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10278    (clobber (match_scratch:SI 3 "=l"))]
10279   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10280   "b%T1l\;{l|lwz} 2,20(1)"
10281   [(set_attr "type" "jmpreg")
10282    (set_attr "length" "8")])
10283
10284 (define_insn "*call_value_nonlocal_aix32"
10285   [(set (match_operand 0 "" "")
10286         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10287               (match_operand 2 "" "g")))
10288    (use (match_operand:SI 3 "immediate_operand" "O"))
10289    (clobber (match_scratch:SI 4 "=l"))]
10290   "TARGET_32BIT
10291    && DEFAULT_ABI == ABI_AIX
10292    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10293   "bl %z1\;%."
10294   [(set_attr "type" "branch")
10295    (set_attr "length" "8")])
10296
10297 (define_insn "*call_value_indirect_nonlocal_aix64"
10298   [(set (match_operand 0 "" "")
10299         (call (mem:SI (match_operand:DI 1 "register_operand" "cl"))
10300               (match_operand 2 "" "g")))
10301    (use (reg:DI 2))
10302    (use (reg:DI 11))
10303    (set (reg:DI 2)
10304         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10305    (clobber (match_scratch:SI 3 "=l"))]
10306   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10307   "b%T1l\;ld 2,40(1)"
10308   [(set_attr "type" "jmpreg")
10309    (set_attr "length" "8")])
10310
10311 (define_insn "*call_value_nonlocal_aix64"
10312   [(set (match_operand 0 "" "")
10313         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10314               (match_operand 2 "" "g")))
10315    (use (match_operand:SI 3 "immediate_operand" "O"))
10316    (clobber (match_scratch:SI 4 "=l"))]
10317   "TARGET_64BIT
10318    && DEFAULT_ABI == ABI_AIX
10319    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10320   "bl %z1\;%."
10321   [(set_attr "type" "branch")
10322    (set_attr "length" "8")])
10323
10324 ;; A function pointer under System V is just a normal pointer
10325 ;; operands[0] is the function pointer
10326 ;; operands[1] is the stack size to clean up
10327 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
10328 ;; which indicates how to set cr1
10329
10330 (define_insn "*call_indirect_nonlocal_sysv"
10331   [(call (mem:SI (match_operand:SI 0 "register_operand" "cl,cl"))
10332          (match_operand 1 "" "g,g"))
10333    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10334    (clobber (match_scratch:SI 3 "=l,l"))]
10335   "DEFAULT_ABI == ABI_V4
10336    || DEFAULT_ABI == ABI_DARWIN"
10337 {
10338   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10339     output_asm_insn ("crxor 6,6,6", operands);
10340
10341   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10342     output_asm_insn ("creqv 6,6,6", operands);
10343
10344   return "b%T0l";
10345 }
10346   [(set_attr "type" "jmpreg,jmpreg")
10347    (set_attr "length" "4,8")])
10348
10349 (define_insn "*call_nonlocal_sysv"
10350   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s,s"))
10351          (match_operand 1 "" "g,g"))
10352    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10353    (clobber (match_scratch:SI 3 "=l,l"))]
10354   "(DEFAULT_ABI == ABI_DARWIN
10355    || (DEFAULT_ABI == ABI_V4
10356        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
10357 {
10358   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10359     output_asm_insn ("crxor 6,6,6", operands);
10360
10361   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10362     output_asm_insn ("creqv 6,6,6", operands);
10363
10364 #if TARGET_MACHO
10365   return output_call(insn, operands, 0, 2);
10366 #else
10367   if (DEFAULT_ABI == ABI_V4 && flag_pic)
10368     {
10369       if (TARGET_SECURE_PLT && flag_pic == 2)
10370         /* The magic 32768 offset here and in the other sysv call insns
10371            corresponds to the offset of r30 in .got2, as given by LCTOC1.
10372            See sysv4.h:toc_section.  */
10373         return "bl %z0+32768@plt";
10374       else
10375         return "bl %z0@plt";
10376     }
10377   else
10378     return "bl %z0";
10379 #endif
10380 }
10381   [(set_attr "type" "branch,branch")
10382    (set_attr "length" "4,8")])
10383
10384 (define_insn "*call_value_indirect_nonlocal_sysv"
10385   [(set (match_operand 0 "" "")
10386         (call (mem:SI (match_operand:SI 1 "register_operand" "cl,cl"))
10387               (match_operand 2 "" "g,g")))
10388    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10389    (clobber (match_scratch:SI 4 "=l,l"))]
10390   "DEFAULT_ABI == ABI_V4
10391    || DEFAULT_ABI == ABI_DARWIN"
10392 {
10393   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10394     output_asm_insn ("crxor 6,6,6", operands);
10395
10396   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10397     output_asm_insn ("creqv 6,6,6", operands);
10398
10399   return "b%T1l";
10400 }
10401   [(set_attr "type" "jmpreg,jmpreg")
10402    (set_attr "length" "4,8")])
10403
10404 (define_insn "*call_value_nonlocal_sysv"
10405   [(set (match_operand 0 "" "")
10406         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s,s"))
10407               (match_operand 2 "" "g,g")))
10408    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10409    (clobber (match_scratch:SI 4 "=l,l"))]
10410   "(DEFAULT_ABI == ABI_DARWIN
10411    || (DEFAULT_ABI == ABI_V4
10412        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
10413 {
10414   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10415     output_asm_insn ("crxor 6,6,6", operands);
10416
10417   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10418     output_asm_insn ("creqv 6,6,6", operands);
10419
10420 #if TARGET_MACHO
10421   return output_call(insn, operands, 1, 3);
10422 #else
10423   if (DEFAULT_ABI == ABI_V4 && flag_pic)
10424     {
10425       if (TARGET_SECURE_PLT && flag_pic == 2)
10426         return "bl %z1+32768@plt";
10427       else
10428         return "bl %z1@plt";
10429     }
10430   else
10431     return "bl %z1";
10432 #endif
10433 }
10434   [(set_attr "type" "branch,branch")
10435    (set_attr "length" "4,8")])
10436
10437 ;; Call subroutine returning any type.
10438 (define_expand "untyped_call"
10439   [(parallel [(call (match_operand 0 "" "")
10440                     (const_int 0))
10441               (match_operand 1 "" "")
10442               (match_operand 2 "" "")])]
10443   ""
10444   "
10445 {
10446   int i;
10447
10448   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
10449
10450   for (i = 0; i < XVECLEN (operands[2], 0); i++)
10451     {
10452       rtx set = XVECEXP (operands[2], 0, i);
10453       emit_move_insn (SET_DEST (set), SET_SRC (set));
10454     }
10455
10456   /* The optimizer does not know that the call sets the function value
10457      registers we stored in the result block.  We avoid problems by
10458      claiming that all hard registers are used and clobbered at this
10459      point.  */
10460   emit_insn (gen_blockage ());
10461
10462   DONE;
10463 }")
10464
10465 ;; sibling call patterns
10466 (define_expand "sibcall"
10467   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10468                     (match_operand 1 "" ""))
10469               (use (match_operand 2 "" ""))
10470               (use (match_operand 3 "" ""))
10471               (return)])]
10472   ""
10473   "
10474 {
10475 #if TARGET_MACHO
10476   if (MACHOPIC_INDIRECT)
10477     operands[0] = machopic_indirect_call_target (operands[0]);
10478 #endif
10479
10480   gcc_assert (GET_CODE (operands[0]) == MEM);
10481   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
10482
10483   operands[0] = XEXP (operands[0], 0);
10484   operands[3] = gen_reg_rtx (SImode);
10485
10486 }")
10487
10488 ;; this and similar patterns must be marked as using LR, otherwise
10489 ;; dataflow will try to delete the store into it.  This is true
10490 ;; even when the actual reg to jump to is in CTR, when LR was
10491 ;; saved and restored around the PIC-setting BCL.
10492 (define_insn "*sibcall_local32"
10493   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10494          (match_operand 1 "" "g,g"))
10495    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10496    (use (match_operand:SI 3 "register_operand" "l,l"))
10497    (return)]
10498   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10499   "*
10500 {
10501   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10502     output_asm_insn (\"crxor 6,6,6\", operands);
10503
10504   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10505     output_asm_insn (\"creqv 6,6,6\", operands);
10506
10507   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
10508 }"
10509   [(set_attr "type" "branch")
10510    (set_attr "length" "4,8")])
10511
10512 (define_insn "*sibcall_local64"
10513   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10514          (match_operand 1 "" "g,g"))
10515    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10516    (use (match_operand:SI 3 "register_operand" "l,l"))
10517    (return)]
10518   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10519   "*
10520 {
10521   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10522     output_asm_insn (\"crxor 6,6,6\", operands);
10523
10524   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10525     output_asm_insn (\"creqv 6,6,6\", operands);
10526
10527   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
10528 }"
10529   [(set_attr "type" "branch")
10530    (set_attr "length" "4,8")])
10531
10532 (define_insn "*sibcall_value_local32"
10533   [(set (match_operand 0 "" "")
10534         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10535               (match_operand 2 "" "g,g")))
10536    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10537    (use (match_operand:SI 4 "register_operand" "l,l"))
10538    (return)]
10539   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10540   "*
10541 {
10542   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10543     output_asm_insn (\"crxor 6,6,6\", operands);
10544
10545   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10546     output_asm_insn (\"creqv 6,6,6\", operands);
10547
10548   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
10549 }"
10550   [(set_attr "type" "branch")
10551    (set_attr "length" "4,8")])
10552
10553
10554 (define_insn "*sibcall_value_local64"
10555   [(set (match_operand 0 "" "")
10556         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10557               (match_operand 2 "" "g,g")))
10558    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10559    (use (match_operand:SI 4 "register_operand" "l,l"))
10560    (return)]
10561   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10562   "*
10563 {
10564   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10565     output_asm_insn (\"crxor 6,6,6\", operands);
10566
10567   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10568     output_asm_insn (\"creqv 6,6,6\", operands);
10569
10570   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
10571 }"
10572   [(set_attr "type" "branch")
10573    (set_attr "length" "4,8")])
10574
10575 (define_insn "*sibcall_nonlocal_aix32"
10576   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10577          (match_operand 1 "" "g"))
10578    (use (match_operand:SI 2 "immediate_operand" "O"))
10579    (use (match_operand:SI 3 "register_operand" "l"))
10580    (return)]
10581   "TARGET_32BIT
10582    && DEFAULT_ABI == ABI_AIX
10583    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10584   "b %z0"
10585   [(set_attr "type" "branch")
10586    (set_attr "length" "4")])
10587
10588 (define_insn "*sibcall_nonlocal_aix64"
10589   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10590          (match_operand 1 "" "g"))
10591    (use (match_operand:SI 2 "immediate_operand" "O"))
10592    (use (match_operand:SI 3 "register_operand" "l"))
10593    (return)]
10594   "TARGET_64BIT
10595    && DEFAULT_ABI == ABI_AIX
10596    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10597   "b %z0"
10598   [(set_attr "type" "branch")
10599    (set_attr "length" "4")])
10600
10601 (define_insn "*sibcall_value_nonlocal_aix32"
10602   [(set (match_operand 0 "" "")
10603         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10604               (match_operand 2 "" "g")))
10605    (use (match_operand:SI 3 "immediate_operand" "O"))
10606    (use (match_operand:SI 4 "register_operand" "l"))
10607    (return)]
10608   "TARGET_32BIT
10609    && DEFAULT_ABI == ABI_AIX
10610    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10611   "b %z1"
10612   [(set_attr "type" "branch")
10613    (set_attr "length" "4")])
10614
10615 (define_insn "*sibcall_value_nonlocal_aix64"
10616   [(set (match_operand 0 "" "")
10617         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10618               (match_operand 2 "" "g")))
10619    (use (match_operand:SI 3 "immediate_operand" "O"))
10620    (use (match_operand:SI 4 "register_operand" "l"))
10621    (return)]
10622   "TARGET_64BIT
10623    && DEFAULT_ABI == ABI_AIX
10624    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10625   "b %z1"
10626   [(set_attr "type" "branch")
10627    (set_attr "length" "4")])
10628
10629 (define_insn "*sibcall_nonlocal_sysv"
10630   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s,s"))
10631          (match_operand 1 "" ""))
10632    (use (match_operand 2 "immediate_operand" "O,n"))
10633    (use (match_operand:SI 3 "register_operand" "l,l"))
10634    (return)]
10635   "(DEFAULT_ABI == ABI_DARWIN
10636      || DEFAULT_ABI == ABI_V4)
10637    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10638   "*
10639 {
10640   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10641     output_asm_insn (\"crxor 6,6,6\", operands);
10642
10643   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10644     output_asm_insn (\"creqv 6,6,6\", operands);
10645
10646   if (DEFAULT_ABI == ABI_V4 && flag_pic)
10647     {
10648       if (TARGET_SECURE_PLT && flag_pic == 2)
10649         return \"b %z0+32768@plt\";
10650       else
10651         return \"b %z0@plt\";
10652     }
10653   else
10654     return \"b %z0\";
10655 }"
10656   [(set_attr "type" "branch,branch")
10657    (set_attr "length" "4,8")])
10658
10659 (define_expand "sibcall_value"
10660   [(parallel [(set (match_operand 0 "register_operand" "")
10661                 (call (mem:SI (match_operand 1 "address_operand" ""))
10662                       (match_operand 2 "" "")))
10663               (use (match_operand 3 "" ""))
10664               (use (match_operand 4 "" ""))
10665               (return)])]
10666   ""
10667   "
10668 {
10669 #if TARGET_MACHO
10670   if (MACHOPIC_INDIRECT)
10671     operands[1] = machopic_indirect_call_target (operands[1]);
10672 #endif
10673
10674   gcc_assert (GET_CODE (operands[1]) == MEM);
10675   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
10676
10677   operands[1] = XEXP (operands[1], 0);
10678   operands[4] = gen_reg_rtx (SImode);
10679
10680 }")
10681
10682 (define_insn "*sibcall_value_nonlocal_sysv"
10683   [(set (match_operand 0 "" "")
10684         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s,s"))
10685               (match_operand 2 "" "")))
10686    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10687    (use (match_operand:SI 4 "register_operand" "l,l"))
10688    (return)]
10689   "(DEFAULT_ABI == ABI_DARWIN
10690        || DEFAULT_ABI == ABI_V4)
10691    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10692   "*
10693 {
10694   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10695     output_asm_insn (\"crxor 6,6,6\", operands);
10696
10697   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10698     output_asm_insn (\"creqv 6,6,6\", operands);
10699
10700   if (DEFAULT_ABI == ABI_V4 && flag_pic)
10701     {
10702       if (TARGET_SECURE_PLT && flag_pic == 2)
10703         return \"b %z1+32768@plt\";
10704       else
10705         return \"b %z1@plt\";
10706     }
10707   else
10708     return \"b %z1\";
10709 }"
10710   [(set_attr "type" "branch,branch")
10711    (set_attr "length" "4,8")])
10712
10713 (define_expand "sibcall_epilogue"
10714   [(use (const_int 0))]
10715   "TARGET_SCHED_PROLOG"
10716   "
10717 {
10718       rs6000_emit_epilogue (TRUE);
10719       DONE;
10720 }")
10721
10722 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
10723 ;; all of memory.  This blocks insns from being moved across this point.
10724
10725 (define_insn "blockage"
10726   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
10727   ""
10728   "")
10729 \f
10730 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
10731 ;; signed & unsigned, and one type of branch.
10732 ;;
10733 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
10734 ;; insns, and branches.  We store the operands of compares until we see
10735 ;; how it is used.
10736 (define_expand "cmpsi"
10737   [(set (cc0)
10738         (compare (match_operand:SI 0 "gpc_reg_operand" "")
10739                  (match_operand:SI 1 "reg_or_short_operand" "")))]
10740   ""
10741   "
10742 {
10743   /* Take care of the possibility that operands[1] might be negative but
10744      this might be a logical operation.  That insn doesn't exist.  */
10745   if (GET_CODE (operands[1]) == CONST_INT
10746       && INTVAL (operands[1]) < 0)
10747     operands[1] = force_reg (SImode, operands[1]);
10748
10749   rs6000_compare_op0 = operands[0];
10750   rs6000_compare_op1 = operands[1];
10751   rs6000_compare_fp_p = 0;
10752   DONE;
10753 }")
10754
10755 (define_expand "cmpdi"
10756   [(set (cc0)
10757         (compare (match_operand:DI 0 "gpc_reg_operand" "")
10758                  (match_operand:DI 1 "reg_or_short_operand" "")))]
10759   "TARGET_POWERPC64"
10760   "
10761 {
10762   /* Take care of the possibility that operands[1] might be negative but
10763      this might be a logical operation.  That insn doesn't exist.  */
10764   if (GET_CODE (operands[1]) == CONST_INT
10765       && INTVAL (operands[1]) < 0)
10766     operands[1] = force_reg (DImode, operands[1]);
10767
10768   rs6000_compare_op0 = operands[0];
10769   rs6000_compare_op1 = operands[1];
10770   rs6000_compare_fp_p = 0;
10771   DONE;
10772 }")
10773
10774 (define_expand "cmpsf"
10775   [(set (cc0) (compare (match_operand:SF 0 "gpc_reg_operand" "")
10776                        (match_operand:SF 1 "gpc_reg_operand" "")))]
10777   "TARGET_HARD_FLOAT"
10778   "
10779 {
10780   rs6000_compare_op0 = operands[0];
10781   rs6000_compare_op1 = operands[1];
10782   rs6000_compare_fp_p = 1;
10783   DONE;
10784 }")
10785
10786 (define_expand "cmpdf"
10787   [(set (cc0) (compare (match_operand:DF 0 "gpc_reg_operand" "")
10788                        (match_operand:DF 1 "gpc_reg_operand" "")))]
10789   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
10790   "
10791 {
10792   rs6000_compare_op0 = operands[0];
10793   rs6000_compare_op1 = operands[1];
10794   rs6000_compare_fp_p = 1;
10795   DONE;
10796 }")
10797
10798 (define_expand "cmptf"
10799   [(set (cc0) (compare (match_operand:TF 0 "gpc_reg_operand" "")
10800                        (match_operand:TF 1 "gpc_reg_operand" "")))]
10801   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
10802    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
10803   "
10804 {
10805   rs6000_compare_op0 = operands[0];
10806   rs6000_compare_op1 = operands[1];
10807   rs6000_compare_fp_p = 1;
10808   DONE;
10809 }")
10810
10811 (define_expand "beq"
10812   [(use (match_operand 0 "" ""))]
10813   ""
10814   "{ rs6000_emit_cbranch (EQ, operands[0]); DONE; }")
10815
10816 (define_expand "bne"
10817   [(use (match_operand 0 "" ""))]
10818   ""
10819   "{ rs6000_emit_cbranch (NE, operands[0]); DONE; }")
10820
10821 (define_expand "bge"
10822   [(use (match_operand 0 "" ""))]
10823   ""
10824   "{ rs6000_emit_cbranch (GE, operands[0]); DONE; }")
10825
10826 (define_expand "bgt"
10827   [(use (match_operand 0 "" ""))]
10828   ""
10829   "{ rs6000_emit_cbranch (GT, operands[0]); DONE; }")
10830
10831 (define_expand "ble"
10832   [(use (match_operand 0 "" ""))]
10833   ""
10834   "{ rs6000_emit_cbranch (LE, operands[0]); DONE; }")
10835
10836 (define_expand "blt"
10837   [(use (match_operand 0 "" ""))]
10838   ""
10839   "{ rs6000_emit_cbranch (LT, operands[0]); DONE; }")
10840
10841 (define_expand "bgeu"
10842   [(use (match_operand 0 "" ""))]
10843   ""
10844   "{ rs6000_emit_cbranch (GEU, operands[0]); DONE; }")
10845
10846 (define_expand "bgtu"
10847   [(use (match_operand 0 "" ""))]
10848   ""
10849   "{ rs6000_emit_cbranch (GTU, operands[0]); DONE; }")
10850
10851 (define_expand "bleu"
10852   [(use (match_operand 0 "" ""))]
10853   ""
10854   "{ rs6000_emit_cbranch (LEU, operands[0]); DONE; }")
10855
10856 (define_expand "bltu"
10857   [(use (match_operand 0 "" ""))]
10858   ""
10859   "{ rs6000_emit_cbranch (LTU, operands[0]); DONE; }")
10860
10861 (define_expand "bunordered"
10862   [(use (match_operand 0 "" ""))]
10863   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
10864   "{ rs6000_emit_cbranch (UNORDERED, operands[0]); DONE; }")
10865
10866 (define_expand "bordered"
10867   [(use (match_operand 0 "" ""))]
10868   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
10869   "{ rs6000_emit_cbranch (ORDERED, operands[0]); DONE; }")
10870
10871 (define_expand "buneq"
10872   [(use (match_operand 0 "" ""))]
10873   ""
10874   "{ rs6000_emit_cbranch (UNEQ, operands[0]); DONE; }")
10875
10876 (define_expand "bunge"
10877   [(use (match_operand 0 "" ""))]
10878   ""
10879   "{ rs6000_emit_cbranch (UNGE, operands[0]); DONE; }")
10880
10881 (define_expand "bungt"
10882   [(use (match_operand 0 "" ""))]
10883   ""
10884   "{ rs6000_emit_cbranch (UNGT, operands[0]); DONE; }")
10885
10886 (define_expand "bunle"
10887   [(use (match_operand 0 "" ""))]
10888   ""
10889   "{ rs6000_emit_cbranch (UNLE, operands[0]); DONE; }")
10890
10891 (define_expand "bunlt"
10892   [(use (match_operand 0 "" ""))]
10893   ""
10894   "{ rs6000_emit_cbranch (UNLT, operands[0]); DONE; }")
10895
10896 (define_expand "bltgt"
10897   [(use (match_operand 0 "" ""))]
10898   ""
10899   "{ rs6000_emit_cbranch (LTGT, operands[0]); DONE; }")
10900
10901 ;; For SNE, we would prefer that the xor/abs sequence be used for integers.
10902 ;; For SEQ, likewise, except that comparisons with zero should be done
10903 ;; with an scc insns.  However, due to the order that combine see the
10904 ;; resulting insns, we must, in fact, allow SEQ for integers.  Fail in
10905 ;; the cases we don't want to handle.
10906 (define_expand "seq"
10907   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10908   ""
10909   "{ rs6000_emit_sCOND (EQ, operands[0]); DONE; }")
10910
10911 (define_expand "sne"
10912   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10913   ""
10914   "
10915 {
10916   if (! rs6000_compare_fp_p)
10917     FAIL;
10918
10919   rs6000_emit_sCOND (NE, operands[0]);
10920   DONE;
10921 }")
10922
10923 ;; A >= 0 is best done the portable way for A an integer.
10924 (define_expand "sge"
10925   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10926   ""
10927   "
10928 {
10929   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
10930     FAIL;
10931
10932   rs6000_emit_sCOND (GE, operands[0]);
10933   DONE;
10934 }")
10935
10936 ;; A > 0 is best done using the portable sequence, so fail in that case.
10937 (define_expand "sgt"
10938   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10939   ""
10940   "
10941 {
10942   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
10943     FAIL;
10944
10945   rs6000_emit_sCOND (GT, operands[0]);
10946   DONE;
10947 }")
10948
10949 ;; A <= 0 is best done the portable way for A an integer.
10950 (define_expand "sle"
10951   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10952   ""
10953   "
10954 {
10955   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
10956     FAIL;
10957
10958   rs6000_emit_sCOND (LE, operands[0]);
10959   DONE;
10960 }")
10961
10962 ;; A < 0 is best done in the portable way for A an integer.
10963 (define_expand "slt"
10964   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10965   ""
10966   "
10967 {
10968   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
10969     FAIL;
10970
10971   rs6000_emit_sCOND (LT, operands[0]);
10972   DONE;
10973 }")
10974
10975 (define_expand "sgeu"
10976   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10977   ""
10978   "{ rs6000_emit_sCOND (GEU, operands[0]); DONE; }")
10979
10980 (define_expand "sgtu"
10981   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10982   ""
10983   "{ rs6000_emit_sCOND (GTU, operands[0]); DONE; }")
10984
10985 (define_expand "sleu"
10986   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10987   ""
10988   "{ rs6000_emit_sCOND (LEU, operands[0]); DONE; }")
10989
10990 (define_expand "sltu"
10991   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10992   ""
10993   "{ rs6000_emit_sCOND (LTU, operands[0]); DONE; }")
10994
10995 (define_expand "sunordered"
10996   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10997   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
10998   "{ rs6000_emit_sCOND (UNORDERED, operands[0]); DONE; }")
10999
11000 (define_expand "sordered"
11001   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11002   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
11003   "{ rs6000_emit_sCOND (ORDERED, operands[0]); DONE; }")
11004
11005 (define_expand "suneq"
11006   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11007   ""
11008   "{ rs6000_emit_sCOND (UNEQ, operands[0]); DONE; }")
11009
11010 (define_expand "sunge"
11011   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11012   ""
11013   "{ rs6000_emit_sCOND (UNGE, operands[0]); DONE; }")
11014
11015 (define_expand "sungt"
11016   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11017   ""
11018   "{ rs6000_emit_sCOND (UNGT, operands[0]); DONE; }")
11019
11020 (define_expand "sunle"
11021   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11022   ""
11023   "{ rs6000_emit_sCOND (UNLE, operands[0]); DONE; }")
11024
11025 (define_expand "sunlt"
11026   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11027   ""
11028   "{ rs6000_emit_sCOND (UNLT, operands[0]); DONE; }")
11029
11030 (define_expand "sltgt"
11031   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11032   ""
11033   "{ rs6000_emit_sCOND (LTGT, operands[0]); DONE; }")
11034
11035 \f
11036 ;; Here are the actual compare insns.
11037 (define_insn "*cmpsi_internal1"
11038   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11039         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11040                     (match_operand:SI 2 "reg_or_short_operand" "rI")))]
11041   ""
11042   "{cmp%I2|cmpw%I2} %0,%1,%2"
11043   [(set_attr "type" "cmp")])
11044
11045 (define_insn "*cmpdi_internal1"
11046   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11047         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "r")
11048                     (match_operand:DI 2 "reg_or_short_operand" "rI")))]
11049   "TARGET_POWERPC64"
11050   "cmpd%I2 %0,%1,%2"
11051   [(set_attr "type" "cmp")])
11052
11053 ;; If we are comparing a register for equality with a large constant,
11054 ;; we can do this with an XOR followed by a compare.  But we need a scratch
11055 ;; register for the result of the XOR.
11056
11057 (define_split
11058   [(set (match_operand:CC 0 "cc_reg_operand" "")
11059         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11060                     (match_operand:SI 2 "non_short_cint_operand" "")))
11061    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
11062   "find_single_use (operands[0], insn, 0)
11063    && (GET_CODE (*find_single_use (operands[0], insn, 0)) == EQ
11064        || GET_CODE (*find_single_use (operands[0], insn, 0)) == NE)"
11065   [(set (match_dup 3) (xor:SI (match_dup 1) (match_dup 4)))
11066    (set (match_dup 0) (compare:CC (match_dup 3) (match_dup 5)))]
11067   "
11068 {
11069   /* Get the constant we are comparing against, C,  and see what it looks like
11070      sign-extended to 16 bits.  Then see what constant could be XOR'ed
11071      with C to get the sign-extended value.  */
11072
11073   HOST_WIDE_INT c = INTVAL (operands[2]);
11074   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
11075   HOST_WIDE_INT xorv = c ^ sextc;
11076
11077   operands[4] = GEN_INT (xorv);
11078   operands[5] = GEN_INT (sextc);
11079 }")
11080
11081 (define_insn "*cmpsi_internal2"
11082   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11083         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11084                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
11085   ""
11086   "{cmpl%I2|cmplw%I2} %0,%1,%b2"
11087   [(set_attr "type" "cmp")])
11088
11089 (define_insn "*cmpdi_internal2"
11090   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11091         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
11092                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
11093   ""
11094   "cmpld%I2 %0,%1,%b2"
11095   [(set_attr "type" "cmp")])
11096
11097 ;; The following two insns don't exist as single insns, but if we provide
11098 ;; them, we can swap an add and compare, which will enable us to overlap more
11099 ;; of the required delay between a compare and branch.  We generate code for
11100 ;; them by splitting.
11101
11102 (define_insn ""
11103   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
11104         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11105                     (match_operand:SI 2 "short_cint_operand" "i")))
11106    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11107         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11108   ""
11109   "#"
11110   [(set_attr "length" "8")])
11111
11112 (define_insn ""
11113   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
11114         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11115                        (match_operand:SI 2 "u_short_cint_operand" "i")))
11116    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11117         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11118   ""
11119   "#"
11120   [(set_attr "length" "8")])
11121
11122 (define_split
11123   [(set (match_operand:CC 3 "cc_reg_operand" "")
11124         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11125                     (match_operand:SI 2 "short_cint_operand" "")))
11126    (set (match_operand:SI 0 "gpc_reg_operand" "")
11127         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11128   ""
11129   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
11130    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11131
11132 (define_split
11133   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
11134         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
11135                        (match_operand:SI 2 "u_short_cint_operand" "")))
11136    (set (match_operand:SI 0 "gpc_reg_operand" "")
11137         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11138   ""
11139   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
11140    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11141
11142 (define_insn "*cmpsf_internal1"
11143   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11144         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
11145                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
11146   "TARGET_HARD_FLOAT && TARGET_FPRS"
11147   "fcmpu %0,%1,%2"
11148   [(set_attr "type" "fpcompare")])
11149
11150 (define_insn "*cmpdf_internal1"
11151   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11152         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "f")
11153                       (match_operand:DF 2 "gpc_reg_operand" "f")))]
11154   "TARGET_HARD_FLOAT && TARGET_FPRS"
11155   "fcmpu %0,%1,%2"
11156   [(set_attr "type" "fpcompare")])
11157
11158 ;; Only need to compare second words if first words equal
11159 (define_insn "*cmptf_internal1"
11160   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11161         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11162                       (match_operand:TF 2 "gpc_reg_operand" "f")))]
11163   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN) && !TARGET_XL_COMPAT
11164    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
11165   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
11166   [(set_attr "type" "fpcompare")
11167    (set_attr "length" "12")])
11168
11169 (define_insn_and_split "*cmptf_internal2"
11170   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11171         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11172                       (match_operand:TF 2 "gpc_reg_operand" "f")))
11173     (clobber (match_scratch:DF 3 "=f"))
11174     (clobber (match_scratch:DF 4 "=f"))
11175     (clobber (match_scratch:DF 5 "=f"))
11176     (clobber (match_scratch:DF 6 "=f"))
11177     (clobber (match_scratch:DF 7 "=f"))
11178     (clobber (match_scratch:DF 8 "=f"))
11179     (clobber (match_scratch:DF 9 "=f"))
11180     (clobber (match_scratch:DF 10 "=f"))]
11181   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN) && TARGET_XL_COMPAT
11182    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
11183   "#"
11184   "&& reload_completed"
11185   [(set (match_dup 3) (match_dup 13))
11186    (set (match_dup 4) (match_dup 14))
11187    (set (match_dup 9) (abs:DF (match_dup 5)))
11188    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
11189    (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
11190                            (label_ref (match_dup 11))
11191                            (pc)))
11192    (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
11193    (set (pc) (label_ref (match_dup 12)))
11194    (match_dup 11)
11195    (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
11196    (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
11197    (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
11198    (set (match_dup 0) (compare:CCFP (match_dup 7) (match_dup 4)))
11199    (match_dup 12)]
11200 {
11201   REAL_VALUE_TYPE rv;
11202   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
11203   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
11204
11205   operands[5] = simplify_gen_subreg (DFmode, operands[1], TFmode, hi_word);
11206   operands[6] = simplify_gen_subreg (DFmode, operands[1], TFmode, lo_word);
11207   operands[7] = simplify_gen_subreg (DFmode, operands[2], TFmode, hi_word);
11208   operands[8] = simplify_gen_subreg (DFmode, operands[2], TFmode, lo_word);
11209   operands[11] = gen_label_rtx ();
11210   operands[12] = gen_label_rtx ();
11211   real_inf (&rv);
11212   operands[13] = force_const_mem (DFmode,
11213                                   CONST_DOUBLE_FROM_REAL_VALUE (rv, DFmode));
11214   operands[14] = force_const_mem (DFmode,
11215                                   CONST_DOUBLE_FROM_REAL_VALUE (dconst0,
11216                                                                 DFmode));
11217   if (TARGET_TOC)
11218     {
11219       operands[13] = gen_const_mem (DFmode,
11220                                     create_TOC_reference (XEXP (operands[13], 0)));
11221       operands[14] = gen_const_mem (DFmode,
11222                                     create_TOC_reference (XEXP (operands[14], 0)));
11223       set_mem_alias_set (operands[13], get_TOC_alias_set ());
11224       set_mem_alias_set (operands[14], get_TOC_alias_set ());
11225     }
11226 })
11227 \f
11228 ;; Now we have the scc insns.  We can do some combinations because of the
11229 ;; way the machine works.
11230 ;;
11231 ;; Note that this is probably faster if we can put an insn between the
11232 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
11233 ;; cases the insns below which don't use an intermediate CR field will
11234 ;; be used instead.
11235 (define_insn ""
11236   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11237         (match_operator:SI 1 "scc_comparison_operator"
11238                            [(match_operand 2 "cc_reg_operand" "y")
11239                             (const_int 0)]))]
11240   ""
11241   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11242   [(set (attr "type")
11243      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11244                 (const_string "mfcrf")
11245            ]
11246         (const_string "mfcr")))
11247    (set_attr "length" "8")])
11248
11249 ;; Same as above, but get the GT bit.
11250 (define_insn "move_from_CR_gt_bit"
11251   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11252         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
11253   "TARGET_E500"
11254   "mfcr %0\;{rlinm|rlwinm} %0,%0,%D1,31,31"
11255   [(set_attr "type" "mfcr")
11256    (set_attr "length" "8")])
11257
11258 ;; Same as above, but get the OV/ORDERED bit.
11259 (define_insn "move_from_CR_ov_bit"
11260   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11261         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_OV))]
11262   "TARGET_ISEL"
11263   "mfcr %0\;{rlinm|rlwinm} %0,%0,%t1,1"
11264   [(set_attr "type" "mfcr")
11265    (set_attr "length" "8")])
11266
11267 (define_insn ""
11268   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11269         (match_operator:DI 1 "scc_comparison_operator"
11270                            [(match_operand 2 "cc_reg_operand" "y")
11271                             (const_int 0)]))]
11272   "TARGET_POWERPC64"
11273   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11274   [(set (attr "type")
11275      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11276                 (const_string "mfcrf")
11277            ]
11278         (const_string "mfcr")))
11279    (set_attr "length" "8")])
11280
11281 (define_insn ""
11282   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11283         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11284                                        [(match_operand 2 "cc_reg_operand" "y,y")
11285                                         (const_int 0)])
11286                     (const_int 0)))
11287    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11288         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11289   "TARGET_32BIT"
11290   "@
11291    mfcr %3%Q2\;{rlinm.|rlwinm.} %3,%3,%J1,1
11292    #"
11293   [(set_attr "type" "delayed_compare")
11294    (set_attr "length" "8,16")])
11295
11296 (define_split
11297   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11298         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11299                                        [(match_operand 2 "cc_reg_operand" "")
11300                                         (const_int 0)])
11301                     (const_int 0)))
11302    (set (match_operand:SI 3 "gpc_reg_operand" "")
11303         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11304   "TARGET_32BIT && reload_completed"
11305   [(set (match_dup 3)
11306         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
11307    (set (match_dup 0)
11308         (compare:CC (match_dup 3)
11309                     (const_int 0)))]
11310   "")
11311
11312 (define_insn ""
11313   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11314         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11315                                       [(match_operand 2 "cc_reg_operand" "y")
11316                                        (const_int 0)])
11317                    (match_operand:SI 3 "const_int_operand" "n")))]
11318   ""
11319   "*
11320 {
11321   int is_bit = ccr_bit (operands[1], 1);
11322   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11323   int count;
11324
11325   if (is_bit >= put_bit)
11326     count = is_bit - put_bit;
11327   else
11328     count = 32 - (put_bit - is_bit);
11329
11330   operands[4] = GEN_INT (count);
11331   operands[5] = GEN_INT (put_bit);
11332
11333   return \"mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
11334 }"
11335   [(set (attr "type")
11336      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11337                 (const_string "mfcrf")
11338            ]
11339         (const_string "mfcr")))
11340    (set_attr "length" "8")])
11341
11342 (define_insn ""
11343   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11344         (compare:CC
11345          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11346                                        [(match_operand 2 "cc_reg_operand" "y,y")
11347                                         (const_int 0)])
11348                     (match_operand:SI 3 "const_int_operand" "n,n"))
11349          (const_int 0)))
11350    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
11351         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11352                    (match_dup 3)))]
11353   ""
11354   "*
11355 {
11356   int is_bit = ccr_bit (operands[1], 1);
11357   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11358   int count;
11359
11360   /* Force split for non-cc0 compare.  */
11361   if (which_alternative == 1)
11362      return \"#\";
11363
11364   if (is_bit >= put_bit)
11365     count = is_bit - put_bit;
11366   else
11367     count = 32 - (put_bit - is_bit);
11368
11369   operands[5] = GEN_INT (count);
11370   operands[6] = GEN_INT (put_bit);
11371
11372   return \"mfcr %4%Q2\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
11373 }"
11374   [(set_attr "type" "delayed_compare")
11375    (set_attr "length" "8,16")])
11376
11377 (define_split
11378   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11379         (compare:CC
11380          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11381                                        [(match_operand 2 "cc_reg_operand" "")
11382                                         (const_int 0)])
11383                     (match_operand:SI 3 "const_int_operand" ""))
11384          (const_int 0)))
11385    (set (match_operand:SI 4 "gpc_reg_operand" "")
11386         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11387                    (match_dup 3)))]
11388   "reload_completed"
11389   [(set (match_dup 4)
11390         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11391                    (match_dup 3)))
11392    (set (match_dup 0)
11393         (compare:CC (match_dup 4)
11394                     (const_int 0)))]
11395   "")
11396
11397 ;; There is a 3 cycle delay between consecutive mfcr instructions
11398 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
11399
11400 (define_peephole
11401   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11402         (match_operator:SI 1 "scc_comparison_operator"
11403                            [(match_operand 2 "cc_reg_operand" "y")
11404                             (const_int 0)]))
11405    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
11406         (match_operator:SI 4 "scc_comparison_operator"
11407                            [(match_operand 5 "cc_reg_operand" "y")
11408                             (const_int 0)]))]
11409   "REGNO (operands[2]) != REGNO (operands[5])"
11410   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11411   [(set_attr "type" "mfcr")
11412    (set_attr "length" "12")])
11413
11414 (define_peephole
11415   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11416         (match_operator:DI 1 "scc_comparison_operator"
11417                            [(match_operand 2 "cc_reg_operand" "y")
11418                             (const_int 0)]))
11419    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
11420         (match_operator:DI 4 "scc_comparison_operator"
11421                            [(match_operand 5 "cc_reg_operand" "y")
11422                             (const_int 0)]))]
11423   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
11424   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11425   [(set_attr "type" "mfcr")
11426    (set_attr "length" "12")])
11427
11428 ;; There are some scc insns that can be done directly, without a compare.
11429 ;; These are faster because they don't involve the communications between
11430 ;; the FXU and branch units.   In fact, we will be replacing all of the
11431 ;; integer scc insns here or in the portable methods in emit_store_flag.
11432 ;;
11433 ;; Also support (neg (scc ..)) since that construct is used to replace
11434 ;; branches, (plus (scc ..) ..) since that construct is common and
11435 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
11436 ;; cases where it is no more expensive than (neg (scc ..)).
11437
11438 ;; Have reload force a constant into a register for the simple insns that
11439 ;; otherwise won't accept constants.  We do this because it is faster than
11440 ;; the cmp/mfcr sequence we would otherwise generate.
11441
11442 (define_insn ""
11443   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
11444         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11445                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I")))
11446    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
11447   "TARGET_32BIT"
11448   "@
11449    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11450    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
11451    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11452    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11453    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
11454   [(set_attr "type" "three,two,three,three,three")
11455    (set_attr "length" "12,8,12,12,12")])
11456
11457 (define_insn ""
11458   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r")
11459         (eq:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r")
11460                (match_operand:DI 2 "reg_or_cint_operand" "r,O,K,J,I")))
11461    (clobber (match_scratch:DI 3 "=r,&r,r,r,r"))]
11462   "TARGET_64BIT"
11463   "@
11464    xor %0,%1,%2\;subfic %3,%0,0\;adde %0,%3,%0
11465    subfic %3,%1,0\;adde %0,%3,%1
11466    xori %0,%1,%b2\;subfic %3,%0,0\;adde %0,%3,%0
11467    xoris %0,%1,%u2\;subfic %3,%0,0\;adde %0,%3,%0
11468    subfic %0,%1,%2\;subfic %3,%0,0\;adde %0,%3,%0"
11469   [(set_attr "type" "three,two,three,three,three")
11470    (set_attr "length" "12,8,12,12,12")])
11471
11472 (define_insn ""
11473   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11474         (compare:CC
11475          (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11476                 (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11477          (const_int 0)))
11478    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
11479         (eq:SI (match_dup 1) (match_dup 2)))
11480    (clobber (match_scratch:SI 3 "=r,&r,r,r,r,r,&r,r,r,r"))]
11481   "TARGET_32BIT"
11482   "@
11483    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11484    {sfi|subfic} %3,%1,0\;{ae.|adde.} %0,%3,%1
11485    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11486    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11487    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11488    #
11489    #
11490    #
11491    #
11492    #"
11493   [(set_attr "type" "compare")
11494    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11495
11496 (define_split
11497   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11498         (compare:CC
11499          (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11500                 (match_operand:SI 2 "reg_or_cint_operand" ""))
11501          (const_int 0)))
11502    (set (match_operand:SI 0 "gpc_reg_operand" "")
11503         (eq:SI (match_dup 1) (match_dup 2)))
11504    (clobber (match_scratch:SI 3 ""))]
11505   "TARGET_32BIT && reload_completed"
11506   [(parallel [(set (match_dup 0)
11507         (eq:SI (match_dup 1) (match_dup 2)))
11508    (clobber (match_dup 3))])
11509    (set (match_dup 4)
11510         (compare:CC (match_dup 0)
11511                     (const_int 0)))]
11512   "")
11513
11514 (define_insn ""
11515   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11516         (compare:CC
11517          (eq:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11518                 (match_operand:DI 2 "reg_or_cint_operand" "r,O,K,J,I,r,O,K,J,I"))
11519          (const_int 0)))
11520    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
11521         (eq:DI (match_dup 1) (match_dup 2)))
11522    (clobber (match_scratch:DI 3 "=r,&r,r,r,r,r,&r,r,r,r"))]
11523   "TARGET_64BIT"
11524   "@
11525    xor %0,%1,%2\;subfic %3,%0,0\;adde. %0,%3,%0
11526    subfic %3,%1,0\;adde. %0,%3,%1
11527    xori %0,%1,%b2\;subfic %3,%0,0\;adde. %0,%3,%0
11528    xoris %0,%1,%u2\;subfic %3,%0,0\;adde. %0,%3,%0
11529    subfic %0,%1,%2\;subfic %3,%0,0\;adde. %0,%3,%0
11530    #
11531    #
11532    #
11533    #
11534    #"
11535   [(set_attr "type" "compare")
11536    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11537
11538 (define_split
11539   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11540         (compare:CC
11541          (eq:DI (match_operand:DI 1 "gpc_reg_operand" "")
11542                 (match_operand:DI 2 "reg_or_cint_operand" ""))
11543          (const_int 0)))
11544    (set (match_operand:DI 0 "gpc_reg_operand" "")
11545         (eq:DI (match_dup 1) (match_dup 2)))
11546    (clobber (match_scratch:DI 3 ""))]
11547   "TARGET_64BIT && reload_completed"
11548   [(parallel [(set (match_dup 0)
11549         (eq:DI (match_dup 1) (match_dup 2)))
11550    (clobber (match_dup 3))])
11551    (set (match_dup 4)
11552         (compare:CC (match_dup 0)
11553                     (const_int 0)))]
11554   "")
11555
11556 ;; We have insns of the form shown by the first define_insn below.  If
11557 ;; there is something inside the comparison operation, we must split it.
11558 (define_split
11559   [(set (match_operand:SI 0 "gpc_reg_operand" "")
11560         (plus:SI (match_operator 1 "comparison_operator"
11561                                  [(match_operand:SI 2 "" "")
11562                                   (match_operand:SI 3
11563                                                     "reg_or_cint_operand" "")])
11564                  (match_operand:SI 4 "gpc_reg_operand" "")))
11565    (clobber (match_operand:SI 5 "register_operand" ""))]
11566   "! gpc_reg_operand (operands[2], SImode)"
11567   [(set (match_dup 5) (match_dup 2))
11568    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
11569                                (match_dup 4)))])
11570
11571 (define_insn ""
11572   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
11573         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11574                         (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I"))
11575                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
11576   "TARGET_32BIT"
11577   "@
11578    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11579    {sfi|subfic} %0,%1,0\;{aze|addze} %0,%3
11580    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11581    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11582    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
11583   [(set_attr "type" "three,two,three,three,three")
11584    (set_attr "length" "12,8,12,12,12")])
11585
11586 (define_insn ""
11587   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11588         (compare:CC
11589          (plus:SI
11590           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11591                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11592           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11593          (const_int 0)))
11594    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
11595   "TARGET_32BIT"
11596   "@
11597    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11598    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
11599    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11600    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11601    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11602    #
11603    #
11604    #
11605    #
11606    #"
11607   [(set_attr "type" "compare")
11608    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11609
11610 (define_split
11611   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11612         (compare:CC
11613          (plus:SI
11614           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11615                  (match_operand:SI 2 "reg_or_cint_operand" ""))
11616           (match_operand:SI 3 "gpc_reg_operand" ""))
11617          (const_int 0)))
11618    (clobber (match_scratch:SI 4 ""))]
11619   "TARGET_32BIT && reload_completed"
11620   [(set (match_dup 4)
11621         (plus:SI (eq:SI (match_dup 1)
11622                  (match_dup 2))
11623           (match_dup 3)))
11624    (set (match_dup 0)
11625         (compare:CC (match_dup 4)
11626                     (const_int 0)))]
11627   "")
11628
11629 (define_insn ""
11630   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11631         (compare:CC
11632          (plus:SI
11633           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11634                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11635           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11636          (const_int 0)))
11637    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
11638         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11639   "TARGET_32BIT"
11640   "@
11641    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11642    {sfi|subfic} %0,%1,0\;{aze.|addze.} %0,%3
11643    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11644    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11645    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11646    #
11647    #
11648    #
11649    #
11650    #"
11651   [(set_attr "type" "compare")
11652    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11653
11654 (define_split
11655   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11656         (compare:CC
11657          (plus:SI
11658           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11659                  (match_operand:SI 2 "reg_or_cint_operand" ""))
11660           (match_operand:SI 3 "gpc_reg_operand" ""))
11661          (const_int 0)))
11662    (set (match_operand:SI 0 "gpc_reg_operand" "")
11663         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11664   "TARGET_32BIT && reload_completed"
11665   [(set (match_dup 0)
11666         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
11667    (set (match_dup 4)
11668         (compare:CC (match_dup 0)
11669                     (const_int 0)))]
11670   "")
11671
11672 (define_insn ""
11673   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
11674         (neg:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11675                        (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I"))))]
11676   "TARGET_32BIT"
11677   "@
11678    xor %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11679    {ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0
11680    {xoril|xori} %0,%1,%b2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11681    {xoriu|xoris} %0,%1,%u2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11682    {sfi|subfic} %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
11683    [(set_attr "type" "three,two,three,three,three")
11684     (set_attr "length" "12,8,12,12,12")])
11685
11686 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
11687 ;; since it nabs/sr is just as fast.
11688 (define_insn "*ne0"
11689   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
11690         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
11691                      (const_int 31)))
11692    (clobber (match_scratch:SI 2 "=&r"))]
11693   "! TARGET_POWER && TARGET_32BIT && !TARGET_ISEL"
11694   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
11695   [(set_attr "type" "two")
11696    (set_attr "length" "8")])
11697
11698 (define_insn ""
11699   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11700         (lshiftrt:DI (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
11701                      (const_int 63)))
11702    (clobber (match_scratch:DI 2 "=&r"))]
11703   "TARGET_64BIT"
11704   "addic %2,%1,-1\;subfe %0,%2,%1"
11705   [(set_attr "type" "two")
11706    (set_attr "length" "8")])
11707
11708 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
11709 (define_insn ""
11710   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11711         (plus:SI (lshiftrt:SI
11712                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
11713                   (const_int 31))
11714                  (match_operand:SI 2 "gpc_reg_operand" "r")))
11715    (clobber (match_scratch:SI 3 "=&r"))]
11716   "TARGET_32BIT"
11717   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
11718   [(set_attr "type" "two")
11719    (set_attr "length" "8")])
11720
11721 (define_insn ""
11722   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11723         (plus:DI (lshiftrt:DI
11724                   (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
11725                   (const_int 63))
11726                  (match_operand:DI 2 "gpc_reg_operand" "r")))
11727    (clobber (match_scratch:DI 3 "=&r"))]
11728   "TARGET_64BIT"
11729   "addic %3,%1,-1\;addze %0,%2"
11730   [(set_attr "type" "two")
11731    (set_attr "length" "8")])
11732
11733 (define_insn ""
11734   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11735         (compare:CC
11736          (plus:SI (lshiftrt:SI
11737                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
11738                    (const_int 31))
11739                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
11740          (const_int 0)))
11741    (clobber (match_scratch:SI 3 "=&r,&r"))
11742    (clobber (match_scratch:SI 4 "=X,&r"))]
11743   "TARGET_32BIT"
11744   "@
11745    {ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2
11746    #"
11747   [(set_attr "type" "compare")
11748    (set_attr "length" "8,12")])
11749
11750 (define_split
11751   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11752         (compare:CC
11753          (plus:SI (lshiftrt:SI
11754                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11755                    (const_int 31))
11756                   (match_operand:SI 2 "gpc_reg_operand" ""))
11757          (const_int 0)))
11758    (clobber (match_scratch:SI 3 ""))
11759    (clobber (match_scratch:SI 4 ""))]
11760   "TARGET_32BIT && reload_completed"
11761   [(parallel [(set (match_dup 3)
11762                    (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1)))
11763                                          (const_int 31))
11764                             (match_dup 2)))
11765               (clobber (match_dup 4))])
11766    (set (match_dup 0)
11767         (compare:CC (match_dup 3)
11768                     (const_int 0)))]
11769   "")
11770
11771 (define_insn ""
11772   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11773         (compare:CC
11774          (plus:DI (lshiftrt:DI
11775                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
11776                    (const_int 63))
11777                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
11778          (const_int 0)))
11779    (clobber (match_scratch:DI 3 "=&r,&r"))]
11780   "TARGET_64BIT"
11781   "@
11782    addic %3,%1,-1\;addze. %3,%2
11783    #"
11784   [(set_attr "type" "compare")
11785    (set_attr "length" "8,12")])
11786
11787 (define_split
11788   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11789         (compare:CC
11790          (plus:DI (lshiftrt:DI
11791                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
11792                    (const_int 63))
11793                   (match_operand:DI 2 "gpc_reg_operand" ""))
11794          (const_int 0)))
11795    (clobber (match_scratch:DI 3 ""))]
11796   "TARGET_64BIT && reload_completed"
11797   [(set (match_dup 3)
11798         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1)))
11799                    (const_int 63))
11800                   (match_dup 2)))
11801    (set (match_dup 0)
11802         (compare:CC (match_dup 3)
11803                     (const_int 0)))]
11804   "")
11805
11806 (define_insn ""
11807   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
11808         (compare:CC
11809          (plus:SI (lshiftrt:SI
11810                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
11811                    (const_int 31))
11812                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
11813          (const_int 0)))
11814    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11815         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11816                  (match_dup 2)))
11817    (clobber (match_scratch:SI 3 "=&r,&r"))]
11818   "TARGET_32BIT"
11819   "@
11820    {ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2
11821    #"
11822   [(set_attr "type" "compare")
11823    (set_attr "length" "8,12")])
11824
11825 (define_split
11826   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11827         (compare:CC
11828          (plus:SI (lshiftrt:SI
11829                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11830                    (const_int 31))
11831                   (match_operand:SI 2 "gpc_reg_operand" ""))
11832          (const_int 0)))
11833    (set (match_operand:SI 0 "gpc_reg_operand" "")
11834         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11835                  (match_dup 2)))
11836    (clobber (match_scratch:SI 3 ""))]
11837   "TARGET_32BIT && reload_completed"
11838   [(parallel [(set (match_dup 0)
11839         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11840                  (match_dup 2)))
11841    (clobber (match_dup 3))])
11842    (set (match_dup 4)
11843         (compare:CC (match_dup 0)
11844                     (const_int 0)))]
11845   "")
11846
11847 (define_insn ""
11848   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
11849         (compare:CC
11850          (plus:DI (lshiftrt:DI
11851                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
11852                    (const_int 63))
11853                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
11854          (const_int 0)))
11855    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
11856         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11857                  (match_dup 2)))
11858    (clobber (match_scratch:DI 3 "=&r,&r"))]
11859   "TARGET_64BIT"
11860   "@
11861    addic %3,%1,-1\;addze. %0,%2
11862    #"
11863   [(set_attr "type" "compare")
11864    (set_attr "length" "8,12")])
11865
11866 (define_split
11867   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11868         (compare:CC
11869          (plus:DI (lshiftrt:DI
11870                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
11871                    (const_int 63))
11872                   (match_operand:DI 2 "gpc_reg_operand" ""))
11873          (const_int 0)))
11874    (set (match_operand:DI 0 "gpc_reg_operand" "")
11875         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11876                  (match_dup 2)))
11877    (clobber (match_scratch:DI 3 ""))]
11878   "TARGET_64BIT && reload_completed"
11879   [(parallel [(set (match_dup 0)
11880         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11881                  (match_dup 2)))
11882    (clobber (match_dup 3))])
11883    (set (match_dup 4)
11884         (compare:CC (match_dup 0)
11885                     (const_int 0)))]
11886   "")
11887
11888 (define_insn ""
11889   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11890         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
11891                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
11892    (clobber (match_scratch:SI 3 "=r,X"))]
11893   "TARGET_POWER"
11894   "@
11895    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
11896    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
11897   [(set_attr "length" "12")])
11898
11899 (define_insn ""
11900   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
11901         (compare:CC
11902          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
11903                 (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
11904          (const_int 0)))
11905    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
11906         (le:SI (match_dup 1) (match_dup 2)))
11907    (clobber (match_scratch:SI 3 "=r,X,r,X"))]
11908   "TARGET_POWER"
11909   "@
11910    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
11911    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31
11912    #
11913    #"
11914   [(set_attr "type" "compare,delayed_compare,compare,delayed_compare")
11915    (set_attr "length" "12,12,16,16")])
11916
11917 (define_split
11918   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11919         (compare:CC
11920          (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
11921                 (match_operand:SI 2 "reg_or_short_operand" ""))
11922          (const_int 0)))
11923    (set (match_operand:SI 0 "gpc_reg_operand" "")
11924         (le:SI (match_dup 1) (match_dup 2)))
11925    (clobber (match_scratch:SI 3 ""))]
11926   "TARGET_POWER && reload_completed"
11927   [(parallel [(set (match_dup 0)
11928         (le:SI (match_dup 1) (match_dup 2)))
11929    (clobber (match_dup 3))])
11930    (set (match_dup 4)
11931         (compare:CC (match_dup 0)
11932                     (const_int 0)))]
11933   "")
11934
11935 (define_insn ""
11936   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
11937         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
11938                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
11939                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
11940   "TARGET_POWER"
11941   "@
11942    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11943    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze|addze} %0,%3"
11944   [(set_attr "length" "12")])
11945
11946 (define_insn ""
11947   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
11948         (compare:CC
11949          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
11950                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
11951                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
11952          (const_int 0)))
11953    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
11954   "TARGET_POWER"
11955   "@
11956    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11957    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3
11958    #
11959    #"
11960   [(set_attr "type" "compare")
11961    (set_attr "length" "12,12,16,16")])
11962
11963 (define_split
11964   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11965         (compare:CC
11966          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
11967                          (match_operand:SI 2 "reg_or_short_operand" ""))
11968                   (match_operand:SI 3 "gpc_reg_operand" ""))
11969          (const_int 0)))
11970    (clobber (match_scratch:SI 4 ""))]
11971   "TARGET_POWER && reload_completed"
11972   [(set (match_dup 4)
11973         (plus:SI (le:SI (match_dup 1) (match_dup 2))
11974                  (match_dup 3)))
11975    (set (match_dup 0)
11976         (compare:CC (match_dup 4)
11977                     (const_int 0)))]
11978   "")
11979
11980 (define_insn ""
11981   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
11982         (compare:CC
11983          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
11984                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
11985                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
11986          (const_int 0)))
11987    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
11988         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11989   "TARGET_POWER"
11990   "@
11991    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11992    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze.|addze.} %0,%3
11993    #
11994    #"
11995   [(set_attr "type" "compare")
11996    (set_attr "length" "12,12,16,16")])
11997
11998 (define_split
11999   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12000         (compare:CC
12001          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12002                          (match_operand:SI 2 "reg_or_short_operand" ""))
12003                   (match_operand:SI 3 "gpc_reg_operand" ""))
12004          (const_int 0)))
12005    (set (match_operand:SI 0 "gpc_reg_operand" "")
12006         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12007   "TARGET_POWER && reload_completed"
12008   [(set (match_dup 0)
12009         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12010    (set (match_dup 4)
12011         (compare:CC (match_dup 0)
12012                     (const_int 0)))]
12013   "")
12014
12015 (define_insn ""
12016   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12017         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12018                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
12019   "TARGET_POWER"
12020   "@
12021    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
12022    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
12023   [(set_attr "length" "12")])
12024
12025 (define_insn ""
12026   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12027         (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12028                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12029   "TARGET_32BIT"
12030   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12031   [(set_attr "type" "three")
12032    (set_attr "length" "12")])
12033
12034 (define_insn ""
12035   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12036         (leu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
12037                 (match_operand:DI 2 "reg_or_short_operand" "rI")))]
12038   "TARGET_64BIT"
12039   "subf%I2c %0,%1,%2\;li %0,0\;adde %0,%0,%0"
12040   [(set_attr "type" "three")
12041    (set_attr "length" "12")])
12042
12043 (define_insn ""
12044   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12045         (compare:CC
12046          (leu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12047                  (match_operand:DI 2 "reg_or_short_operand" "rI,rI"))
12048          (const_int 0)))
12049    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12050         (leu:DI (match_dup 1) (match_dup 2)))]
12051   "TARGET_64BIT"
12052   "@
12053    subf%I2c %0,%1,%2\;li %0,0\;adde. %0,%0,%0
12054    #"
12055   [(set_attr "type" "compare")
12056    (set_attr "length" "12,16")])
12057
12058 (define_split
12059   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12060         (compare:CC
12061          (leu:DI (match_operand:DI 1 "gpc_reg_operand" "")
12062                  (match_operand:DI 2 "reg_or_short_operand" ""))
12063          (const_int 0)))
12064    (set (match_operand:DI 0 "gpc_reg_operand" "")
12065         (leu:DI (match_dup 1) (match_dup 2)))]
12066   "TARGET_64BIT && reload_completed"
12067   [(set (match_dup 0)
12068         (leu:DI (match_dup 1) (match_dup 2)))
12069    (set (match_dup 3)
12070         (compare:CC (match_dup 0)
12071                     (const_int 0)))]
12072   "")
12073
12074 (define_insn ""
12075   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12076         (compare:CC
12077          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12078                  (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12079          (const_int 0)))
12080    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12081         (leu:SI (match_dup 1) (match_dup 2)))]
12082   "TARGET_32BIT"
12083   "@
12084    {sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12085    #"
12086   [(set_attr "type" "compare")
12087    (set_attr "length" "12,16")])
12088
12089 (define_split
12090   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12091         (compare:CC
12092          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12093                  (match_operand:SI 2 "reg_or_short_operand" ""))
12094          (const_int 0)))
12095    (set (match_operand:SI 0 "gpc_reg_operand" "")
12096         (leu:SI (match_dup 1) (match_dup 2)))]
12097   "TARGET_32BIT && reload_completed"
12098   [(set (match_dup 0)
12099         (leu:SI (match_dup 1) (match_dup 2)))
12100    (set (match_dup 3)
12101         (compare:CC (match_dup 0)
12102                     (const_int 0)))]
12103   "")
12104
12105 (define_insn ""
12106   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12107         (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12108                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
12109                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12110   "TARGET_32BIT"
12111   "{sf%I2|subf%I2c} %0,%1,%2\;{aze|addze} %0,%3"
12112   [(set_attr "type" "two")
12113    (set_attr "length" "8")])
12114
12115 (define_insn ""
12116   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12117         (compare:CC
12118          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12119                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12120                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12121          (const_int 0)))
12122    (clobber (match_scratch:SI 4 "=&r,&r"))]
12123   "TARGET_32BIT"
12124   "@
12125    {sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3
12126    #"
12127   [(set_attr "type" "compare")
12128    (set_attr "length" "8,12")])
12129
12130 (define_split
12131   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12132         (compare:CC
12133          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12134                           (match_operand:SI 2 "reg_or_short_operand" ""))
12135                   (match_operand:SI 3 "gpc_reg_operand" ""))
12136          (const_int 0)))
12137    (clobber (match_scratch:SI 4 ""))]
12138   "TARGET_32BIT && reload_completed"
12139   [(set (match_dup 4)
12140         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
12141                   (match_dup 3)))
12142    (set (match_dup 0)
12143         (compare:CC (match_dup 4)
12144                     (const_int 0)))]
12145   "")
12146
12147 (define_insn ""
12148   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12149         (compare:CC
12150          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12151                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12152                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12153          (const_int 0)))
12154    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12155         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12156   "TARGET_32BIT"
12157   "@
12158    {sf%I2|subf%I2c} %0,%1,%2\;{aze.|addze.} %0,%3
12159    #"
12160   [(set_attr "type" "compare")
12161    (set_attr "length" "8,12")])
12162
12163 (define_split
12164   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12165         (compare:CC
12166          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12167                           (match_operand:SI 2 "reg_or_short_operand" ""))
12168                   (match_operand:SI 3 "gpc_reg_operand" ""))
12169          (const_int 0)))
12170    (set (match_operand:SI 0 "gpc_reg_operand" "")
12171         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12172   "TARGET_32BIT && reload_completed"
12173   [(set (match_dup 0)
12174         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12175    (set (match_dup 4)
12176         (compare:CC (match_dup 0)
12177                     (const_int 0)))]
12178   "")
12179
12180 (define_insn ""
12181   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12182         (neg:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12183                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12184   "TARGET_32BIT"
12185   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
12186    [(set_attr "type" "three")
12187     (set_attr "length" "12")])
12188
12189 (define_insn ""
12190   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12191         (and:SI (neg:SI
12192                  (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12193                          (match_operand:SI 2 "reg_or_short_operand" "rI")))
12194                 (match_operand:SI 3 "gpc_reg_operand" "r")))]
12195   "TARGET_32BIT"
12196   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12197   [(set_attr "type" "three")
12198    (set_attr "length" "12")])
12199
12200 (define_insn ""
12201   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12202         (compare:CC
12203          (and:SI (neg:SI
12204                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12205                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12206                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12207          (const_int 0)))
12208    (clobber (match_scratch:SI 4 "=&r,&r"))]
12209   "TARGET_32BIT"
12210   "@
12211    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12212    #"
12213   [(set_attr "type" "compare")
12214    (set_attr "length" "12,16")])
12215
12216 (define_split
12217   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12218         (compare:CC
12219          (and:SI (neg:SI
12220                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12221                           (match_operand:SI 2 "reg_or_short_operand" "")))
12222                  (match_operand:SI 3 "gpc_reg_operand" ""))
12223          (const_int 0)))
12224    (clobber (match_scratch:SI 4 ""))]
12225   "TARGET_32BIT && reload_completed"
12226   [(set (match_dup 4)
12227         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12228                 (match_dup 3)))
12229    (set (match_dup 0)
12230         (compare:CC (match_dup 4)
12231                     (const_int 0)))]
12232   "")
12233
12234 (define_insn ""
12235   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12236         (compare:CC
12237          (and:SI (neg:SI
12238                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12239                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12240                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12241          (const_int 0)))
12242    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12243         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12244   "TARGET_32BIT"
12245   "@
12246    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12247    #"
12248   [(set_attr "type" "compare")
12249    (set_attr "length" "12,16")])
12250
12251 (define_split
12252   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12253         (compare:CC
12254          (and:SI (neg:SI
12255                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12256                           (match_operand:SI 2 "reg_or_short_operand" "")))
12257                  (match_operand:SI 3 "gpc_reg_operand" ""))
12258          (const_int 0)))
12259    (set (match_operand:SI 0 "gpc_reg_operand" "")
12260         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12261   "TARGET_32BIT && reload_completed"
12262   [(set (match_dup 0)
12263         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12264                 (match_dup 3)))
12265    (set (match_dup 4)
12266         (compare:CC (match_dup 0)
12267                     (const_int 0)))]
12268   "")
12269
12270 (define_insn ""
12271   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12272         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12273                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12274   "TARGET_POWER"
12275   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
12276    [(set_attr "length" "12")])
12277
12278 (define_insn ""
12279   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12280         (compare:CC
12281          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12282                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12283          (const_int 0)))
12284    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12285         (lt:SI (match_dup 1) (match_dup 2)))]
12286   "TARGET_POWER"
12287   "@
12288    doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
12289    #"
12290   [(set_attr "type" "delayed_compare")
12291    (set_attr "length" "12,16")])
12292
12293 (define_split
12294   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12295         (compare:CC
12296          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12297                 (match_operand:SI 2 "reg_or_short_operand" ""))
12298          (const_int 0)))
12299    (set (match_operand:SI 0 "gpc_reg_operand" "")
12300         (lt:SI (match_dup 1) (match_dup 2)))]
12301   "TARGET_POWER && reload_completed"
12302   [(set (match_dup 0)
12303         (lt:SI (match_dup 1) (match_dup 2)))
12304    (set (match_dup 3)
12305         (compare:CC (match_dup 0)
12306                     (const_int 0)))]
12307   "")
12308
12309 (define_insn ""
12310   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12311         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12312                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12313                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12314   "TARGET_POWER"
12315   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
12316   [(set_attr "length" "12")])
12317
12318 (define_insn ""
12319   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12320         (compare:CC
12321          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12322                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12323                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12324          (const_int 0)))
12325    (clobber (match_scratch:SI 4 "=&r,&r"))]
12326   "TARGET_POWER"
12327   "@
12328    doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
12329    #"
12330   [(set_attr "type" "compare")
12331    (set_attr "length" "12,16")])
12332
12333 (define_split
12334   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12335         (compare:CC
12336          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12337                          (match_operand:SI 2 "reg_or_short_operand" ""))
12338                   (match_operand:SI 3 "gpc_reg_operand" ""))
12339          (const_int 0)))
12340    (clobber (match_scratch:SI 4 ""))]
12341   "TARGET_POWER && reload_completed"
12342   [(set (match_dup 4)
12343         (plus:SI (lt:SI (match_dup 1) (match_dup 2))
12344                  (match_dup 3)))
12345    (set (match_dup 0)
12346         (compare:CC (match_dup 4)
12347                     (const_int 0)))]
12348   "")
12349
12350 (define_insn ""
12351   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12352         (compare:CC
12353          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12354                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12355                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12356          (const_int 0)))
12357    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12358         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12359   "TARGET_POWER"
12360   "@
12361    doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
12362    #"
12363   [(set_attr "type" "compare")
12364    (set_attr "length" "12,16")])
12365
12366 (define_split
12367   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12368         (compare:CC
12369          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12370                          (match_operand:SI 2 "reg_or_short_operand" ""))
12371                   (match_operand:SI 3 "gpc_reg_operand" ""))
12372          (const_int 0)))
12373    (set (match_operand:SI 0 "gpc_reg_operand" "")
12374         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12375   "TARGET_POWER && reload_completed"
12376   [(set (match_dup 0)
12377         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12378    (set (match_dup 4)
12379         (compare:CC (match_dup 0)
12380                     (const_int 0)))]
12381   "")
12382
12383 (define_insn ""
12384   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12385         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12386                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12387   "TARGET_POWER"
12388   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
12389   [(set_attr "length" "12")])
12390
12391 (define_insn_and_split ""
12392   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12393         (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12394                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
12395   "TARGET_32BIT"
12396   "#"
12397   "TARGET_32BIT"
12398   [(set (match_dup 0) (neg:SI (ltu:SI (match_dup 1) (match_dup 2))))
12399    (set (match_dup 0) (neg:SI (match_dup 0)))]
12400   "")
12401
12402 (define_insn_and_split ""
12403   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12404         (ltu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12405                 (match_operand:DI 2 "reg_or_neg_short_operand" "r,P")))]
12406   "TARGET_64BIT"
12407   "#"
12408   "TARGET_64BIT"
12409   [(set (match_dup 0) (neg:DI (ltu:DI (match_dup 1) (match_dup 2))))
12410    (set (match_dup 0) (neg:DI (match_dup 0)))]
12411   "")
12412
12413 (define_insn ""
12414   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12415         (compare:CC
12416          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12417                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12418          (const_int 0)))
12419    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12420         (ltu:SI (match_dup 1) (match_dup 2)))]
12421   "TARGET_32BIT"
12422   "@
12423    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
12424    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
12425    #
12426    #"
12427   [(set_attr "type" "compare")
12428    (set_attr "length" "12,12,16,16")])
12429
12430 (define_split
12431   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12432         (compare:CC
12433          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12434                  (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12435          (const_int 0)))
12436    (set (match_operand:SI 0 "gpc_reg_operand" "")
12437         (ltu:SI (match_dup 1) (match_dup 2)))]
12438   "TARGET_32BIT && reload_completed"
12439   [(set (match_dup 0)
12440         (ltu:SI (match_dup 1) (match_dup 2)))
12441    (set (match_dup 3)
12442         (compare:CC (match_dup 0)
12443                     (const_int 0)))]
12444   "")
12445
12446 (define_insn_and_split ""
12447   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
12448         (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12449                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
12450                  (match_operand:SI 3 "reg_or_short_operand" "rI,rI")))]
12451   "TARGET_32BIT"
12452   "#"
12453   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
12454   [(set (match_dup 0) (neg:SI (ltu:SI (match_dup 1) (match_dup 2))))
12455    (set (match_dup 0) (minus:SI (match_dup 3) (match_dup 0)))]
12456   "")
12457
12458 (define_insn_and_split ""
12459   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
12460         (plus:DI (ltu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12461                          (match_operand:DI 2 "reg_or_neg_short_operand" "r,P"))
12462                  (match_operand:DI 3 "reg_or_short_operand" "rI,rI")))]
12463   "TARGET_64BIT"
12464   "#"
12465   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
12466   [(set (match_dup 0) (neg:DI (ltu:DI (match_dup 1) (match_dup 2))))
12467    (set (match_dup 0) (minus:DI (match_dup 3) (match_dup 0)))]
12468   "")
12469
12470 (define_insn ""
12471   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12472         (compare:CC
12473          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12474                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12475                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12476          (const_int 0)))
12477    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12478   "TARGET_32BIT"
12479   "@
12480    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf.|subf.} %4,%4,%3
12481    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf.|subf.} %4,%4,%3
12482    #
12483    #"
12484   [(set_attr "type" "compare")
12485    (set_attr "length" "12,12,16,16")])
12486
12487 (define_split
12488   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12489         (compare:CC
12490          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12491                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12492                   (match_operand:SI 3 "gpc_reg_operand" ""))
12493          (const_int 0)))
12494    (clobber (match_scratch:SI 4 ""))]
12495   "TARGET_32BIT && reload_completed"
12496   [(set (match_dup 4)
12497         (plus:SI (ltu:SI (match_dup 1) (match_dup 2))
12498                  (match_dup 3)))
12499    (set (match_dup 0)
12500         (compare:CC (match_dup 4)
12501                     (const_int 0)))]
12502   "")
12503
12504 (define_insn ""
12505   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12506         (compare:CC
12507          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12508                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12509                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12510          (const_int 0)))
12511    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12512         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12513   "TARGET_32BIT"
12514   "@
12515    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;{sf.|subf.} %0,%0,%3
12516    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;{sf.|subf.} %0,%0,%3
12517    #
12518    #"
12519   [(set_attr "type" "compare")
12520    (set_attr "length" "12,12,16,16")])
12521
12522 (define_split
12523   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12524         (compare:CC
12525          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12526                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12527                   (match_operand:SI 3 "gpc_reg_operand" ""))
12528          (const_int 0)))
12529    (set (match_operand:SI 0 "gpc_reg_operand" "")
12530         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12531   "TARGET_32BIT && reload_completed"
12532   [(set (match_dup 0)
12533         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12534    (set (match_dup 4)
12535         (compare:CC (match_dup 0)
12536                     (const_int 0)))]
12537   "")
12538
12539 (define_insn ""
12540   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12541         (neg:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12542                         (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))))]
12543   "TARGET_32BIT"
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:DI 0 "gpc_reg_operand" "=r,r")
12552         (neg:DI (ltu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12553                         (match_operand:DI 2 "reg_or_neg_short_operand" "r,P"))))]
12554   "TARGET_64BIT"
12555   "@
12556    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
12557    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
12558   [(set_attr "type" "two")
12559    (set_attr "length" "8")])
12560
12561 (define_insn ""
12562   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12563         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12564                (match_operand:SI 2 "reg_or_short_operand" "rI")))
12565    (clobber (match_scratch:SI 3 "=r"))]
12566   "TARGET_POWER"
12567   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
12568    [(set_attr "length" "12")])
12569
12570 (define_insn ""
12571   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12572         (compare:CC
12573          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12574                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12575          (const_int 0)))
12576    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12577         (ge:SI (match_dup 1) (match_dup 2)))
12578    (clobber (match_scratch:SI 3 "=r,r"))]
12579   "TARGET_POWER"
12580   "@
12581    doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
12582    #"
12583   [(set_attr "type" "compare")
12584    (set_attr "length" "12,16")])
12585
12586 (define_split
12587   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12588         (compare:CC
12589          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12590                 (match_operand:SI 2 "reg_or_short_operand" ""))
12591          (const_int 0)))
12592    (set (match_operand:SI 0 "gpc_reg_operand" "")
12593         (ge:SI (match_dup 1) (match_dup 2)))
12594    (clobber (match_scratch:SI 3 ""))]
12595   "TARGET_POWER && reload_completed"
12596   [(parallel [(set (match_dup 0)
12597                    (ge:SI (match_dup 1) (match_dup 2)))
12598               (clobber (match_dup 3))])
12599    (set (match_dup 4)
12600         (compare:CC (match_dup 0)
12601                     (const_int 0)))]
12602   "")
12603
12604 (define_insn ""
12605   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12606         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12607                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12608                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12609   "TARGET_POWER"
12610   "doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
12611   [(set_attr "length" "12")])
12612
12613 (define_insn ""
12614   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12615         (compare:CC
12616          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12617                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12618                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12619          (const_int 0)))
12620    (clobber (match_scratch:SI 4 "=&r,&r"))]
12621   "TARGET_POWER"
12622   "@
12623    doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12624    #"
12625   [(set_attr "type" "compare")
12626    (set_attr "length" "12,16")])
12627
12628 (define_split
12629   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12630         (compare:CC
12631          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12632                          (match_operand:SI 2 "reg_or_short_operand" ""))
12633                   (match_operand:SI 3 "gpc_reg_operand" ""))
12634          (const_int 0)))
12635    (clobber (match_scratch:SI 4 ""))]
12636   "TARGET_POWER && reload_completed"
12637   [(set (match_dup 4)
12638         (plus:SI (ge:SI (match_dup 1) (match_dup 2))
12639                  (match_dup 3)))
12640    (set (match_dup 0)
12641         (compare:CC (match_dup 4)
12642                     (const_int 0)))]
12643   "")
12644
12645 (define_insn ""
12646   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12647         (compare:CC
12648          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12649                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12650                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12651          (const_int 0)))
12652    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12653         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12654   "TARGET_POWER"
12655   "@
12656    doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12657    #"
12658   [(set_attr "type" "compare")
12659    (set_attr "length" "12,16")])
12660
12661 (define_split
12662   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12663         (compare:CC
12664          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12665                          (match_operand:SI 2 "reg_or_short_operand" ""))
12666                   (match_operand:SI 3 "gpc_reg_operand" ""))
12667          (const_int 0)))
12668    (set (match_operand:SI 0 "gpc_reg_operand" "")
12669         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12670   "TARGET_POWER && reload_completed"
12671   [(set (match_dup 0)
12672         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12673    (set (match_dup 4)
12674         (compare:CC (match_dup 0)
12675                     (const_int 0)))]
12676   "")
12677
12678 (define_insn ""
12679   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12680         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12681                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12682   "TARGET_POWER"
12683   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
12684   [(set_attr "length" "12")])
12685
12686 (define_insn ""
12687   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12688         (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12689                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
12690   "TARGET_32BIT"
12691   "@
12692    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
12693    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12694   [(set_attr "type" "three")
12695    (set_attr "length" "12")])
12696
12697 (define_insn ""
12698   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12699         (geu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12700                 (match_operand:DI 2 "reg_or_neg_short_operand" "r,P")))]
12701   "TARGET_64BIT"
12702   "@
12703    subfc %0,%2,%1\;li %0,0\;adde %0,%0,%0
12704    addic %0,%1,%n2\;li %0,0\;adde %0,%0,%0"
12705   [(set_attr "type" "three")
12706    (set_attr "length" "12")])
12707
12708 (define_insn ""
12709   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12710         (compare:CC
12711          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12712                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12713          (const_int 0)))
12714    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12715         (geu:SI (match_dup 1) (match_dup 2)))]
12716   "TARGET_32BIT"
12717   "@
12718    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12719    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12720    #
12721    #"
12722   [(set_attr "type" "compare")
12723    (set_attr "length" "12,12,16,16")])
12724
12725 (define_split
12726   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12727         (compare:CC
12728          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12729                  (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12730          (const_int 0)))
12731    (set (match_operand:SI 0 "gpc_reg_operand" "")
12732         (geu:SI (match_dup 1) (match_dup 2)))]
12733   "TARGET_32BIT && reload_completed"
12734   [(set (match_dup 0)
12735         (geu:SI (match_dup 1) (match_dup 2)))
12736    (set (match_dup 3)
12737         (compare:CC (match_dup 0)
12738                     (const_int 0)))]
12739   "")
12740
12741 (define_insn ""
12742   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12743         (compare:CC
12744          (geu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
12745                  (match_operand:DI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12746          (const_int 0)))
12747    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
12748         (geu:DI (match_dup 1) (match_dup 2)))]
12749   "TARGET_64BIT"
12750   "@
12751    subfc %0,%2,%1\;li %0,0\;adde. %0,%0,%0
12752    addic %0,%1,%n2\;li %0,0\;adde. %0,%0,%0
12753    #
12754    #"
12755   [(set_attr "type" "compare")
12756    (set_attr "length" "12,12,16,16")])
12757
12758 (define_split
12759   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12760         (compare:CC
12761          (geu:DI (match_operand:DI 1 "gpc_reg_operand" "")
12762                  (match_operand:DI 2 "reg_or_neg_short_operand" ""))
12763          (const_int 0)))
12764    (set (match_operand:DI 0 "gpc_reg_operand" "")
12765         (geu:DI (match_dup 1) (match_dup 2)))]
12766   "TARGET_64BIT && reload_completed"
12767   [(set (match_dup 0)
12768         (geu:DI (match_dup 1) (match_dup 2)))
12769    (set (match_dup 3)
12770         (compare:CC (match_dup 0)
12771                     (const_int 0)))]
12772   "")
12773
12774 (define_insn ""
12775   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12776         (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12777                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
12778                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12779   "TARGET_32BIT"
12780   "@
12781    {sf|subfc} %0,%2,%1\;{aze|addze} %0,%3
12782    {ai|addic} %0,%1,%n2\;{aze|addze} %0,%3"
12783   [(set_attr "type" "two")
12784    (set_attr "length" "8")])
12785
12786 (define_insn ""
12787   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12788         (compare:CC
12789          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12790                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12791                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12792          (const_int 0)))
12793    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12794   "TARGET_32BIT"
12795   "@
12796    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
12797    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3
12798    #
12799    #"
12800   [(set_attr "type" "compare")
12801    (set_attr "length" "8,8,12,12")])
12802
12803 (define_split
12804   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12805         (compare:CC
12806          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12807                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12808                   (match_operand:SI 3 "gpc_reg_operand" ""))
12809          (const_int 0)))
12810    (clobber (match_scratch:SI 4 ""))]
12811   "TARGET_32BIT && reload_completed"
12812   [(set (match_dup 4)
12813         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
12814                   (match_dup 3)))
12815    (set (match_dup 0)
12816         (compare:CC (match_dup 4)
12817                     (const_int 0)))]
12818   "")
12819
12820 (define_insn ""
12821   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12822         (compare:CC
12823          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12824                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12825                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12826          (const_int 0)))
12827    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12828         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12829   "TARGET_32BIT"
12830   "@
12831    {sf|subfc} %0,%2,%1\;{aze.|addze.} %0,%3
12832    {ai|addic} %0,%1,%n2\;{aze.|addze.} %0,%3
12833    #
12834    #"
12835   [(set_attr "type" "compare")
12836    (set_attr "length" "8,8,12,12")])
12837
12838 (define_split
12839   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12840         (compare:CC
12841          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12842                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12843                   (match_operand:SI 3 "gpc_reg_operand" ""))
12844          (const_int 0)))
12845    (set (match_operand:SI 0 "gpc_reg_operand" "")
12846         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12847   "TARGET_32BIT && reload_completed"
12848   [(set (match_dup 0)
12849         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12850    (set (match_dup 4)
12851         (compare:CC (match_dup 0)
12852                     (const_int 0)))]
12853   "")
12854
12855 (define_insn ""
12856   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12857         (neg:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12858                         (match_operand:SI 2 "reg_or_short_operand" "r,I"))))]
12859   "TARGET_32BIT"
12860   "@
12861    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
12862    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
12863   [(set_attr "type" "three")
12864    (set_attr "length" "12")])
12865
12866 (define_insn ""
12867   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12868         (and:SI (neg:SI
12869                  (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12870                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
12871                 (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12872   "TARGET_32BIT"
12873   "@
12874    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0
12875    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12876   [(set_attr "type" "three")
12877    (set_attr "length" "12")])
12878
12879 (define_insn ""
12880   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12881         (compare:CC
12882          (and:SI (neg:SI
12883                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12884                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
12885                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12886          (const_int 0)))
12887    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12888   "TARGET_32BIT"
12889   "@
12890    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12891    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12892    #
12893    #"
12894   [(set_attr "type" "compare")
12895    (set_attr "length" "12,12,16,16")])
12896
12897 (define_split
12898   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12899         (compare:CC
12900          (and:SI (neg:SI
12901                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12902                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
12903                  (match_operand:SI 3 "gpc_reg_operand" ""))
12904          (const_int 0)))
12905    (clobber (match_scratch:SI 4 ""))]
12906   "TARGET_32BIT && reload_completed"
12907   [(set (match_dup 4)
12908         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
12909                 (match_dup 3)))
12910    (set (match_dup 0)
12911         (compare:CC (match_dup 4)
12912                     (const_int 0)))]
12913   "")
12914
12915 (define_insn ""
12916   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12917         (compare:CC
12918          (and:SI (neg:SI
12919                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12920                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
12921                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12922          (const_int 0)))
12923    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12924         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12925   "TARGET_32BIT"
12926   "@
12927    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12928    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12929    #
12930    #"
12931   [(set_attr "type" "compare")
12932    (set_attr "length" "12,12,16,16")])
12933
12934 (define_split
12935   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12936         (compare:CC
12937          (and:SI (neg:SI
12938                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12939                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
12940                  (match_operand:SI 3 "gpc_reg_operand" ""))
12941          (const_int 0)))
12942    (set (match_operand:SI 0 "gpc_reg_operand" "")
12943         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12944   "TARGET_32BIT && reload_completed"
12945   [(set (match_dup 0)
12946         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
12947    (set (match_dup 4)
12948         (compare:CC (match_dup 0)
12949                     (const_int 0)))]
12950   "")
12951
12952 (define_insn ""
12953   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12954         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12955                (const_int 0)))]
12956   "TARGET_32BIT"
12957   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri|srwi} %0,%0,31"
12958   [(set_attr "type" "three")
12959    (set_attr "length" "12")])
12960
12961 (define_insn ""
12962   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12963         (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
12964                (const_int 0)))]
12965   "TARGET_64BIT"
12966   "subfic %0,%1,0\;addme %0,%0\;srdi %0,%0,63"
12967   [(set_attr "type" "three")
12968    (set_attr "length" "12")])
12969
12970 (define_insn ""
12971   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
12972         (compare:CC
12973          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12974                 (const_int 0))
12975          (const_int 0)))
12976    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12977         (gt:SI (match_dup 1) (const_int 0)))]
12978   "TARGET_32BIT"
12979   "@
12980    {sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri.|srwi.} %0,%0,31
12981    #"
12982   [(set_attr "type" "delayed_compare")
12983    (set_attr "length" "12,16")])
12984
12985 (define_split
12986   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
12987         (compare:CC
12988          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12989                 (const_int 0))
12990          (const_int 0)))
12991    (set (match_operand:SI 0 "gpc_reg_operand" "")
12992         (gt:SI (match_dup 1) (const_int 0)))]
12993   "TARGET_32BIT && reload_completed"
12994   [(set (match_dup 0)
12995         (gt:SI (match_dup 1) (const_int 0)))
12996    (set (match_dup 2)
12997         (compare:CC (match_dup 0)
12998                     (const_int 0)))]
12999   "")
13000
13001 (define_insn ""
13002   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
13003         (compare:CC
13004          (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13005                 (const_int 0))
13006          (const_int 0)))
13007    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
13008         (gt:DI (match_dup 1) (const_int 0)))]
13009   "TARGET_64BIT"
13010   "@
13011    subfic %0,%1,0\;addme %0,%0\;srdi. %0,%0,63
13012    #"
13013   [(set_attr "type" "delayed_compare")
13014    (set_attr "length" "12,16")])
13015
13016 (define_split
13017   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
13018         (compare:CC
13019          (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13020                 (const_int 0))
13021          (const_int 0)))
13022    (set (match_operand:DI 0 "gpc_reg_operand" "")
13023         (gt:DI (match_dup 1) (const_int 0)))]
13024   "TARGET_64BIT && reload_completed"
13025   [(set (match_dup 0)
13026         (gt:DI (match_dup 1) (const_int 0)))
13027    (set (match_dup 2)
13028         (compare:CC (match_dup 0)
13029                     (const_int 0)))]
13030   "")
13031
13032 (define_insn ""
13033   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13034         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13035                (match_operand:SI 2 "reg_or_short_operand" "r")))]
13036   "TARGET_POWER"
13037   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
13038   [(set_attr "length" "12")])
13039
13040 (define_insn ""
13041   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13042         (compare:CC
13043          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13044                 (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13045          (const_int 0)))
13046    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13047         (gt:SI (match_dup 1) (match_dup 2)))]
13048   "TARGET_POWER"
13049   "@
13050    doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
13051    #"
13052   [(set_attr "type" "delayed_compare")
13053    (set_attr "length" "12,16")])
13054
13055 (define_split
13056   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13057         (compare:CC
13058          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13059                 (match_operand:SI 2 "reg_or_short_operand" ""))
13060          (const_int 0)))
13061    (set (match_operand:SI 0 "gpc_reg_operand" "")
13062         (gt:SI (match_dup 1) (match_dup 2)))]
13063   "TARGET_POWER && reload_completed"
13064   [(set (match_dup 0)
13065         (gt:SI (match_dup 1) (match_dup 2)))
13066    (set (match_dup 3)
13067         (compare:CC (match_dup 0)
13068                     (const_int 0)))]
13069   "")
13070
13071 (define_insn ""
13072   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13073         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13074                         (const_int 0))
13075                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
13076   "TARGET_32BIT"
13077   "{a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze|addze} %0,%2"
13078   [(set_attr "type" "three")
13079    (set_attr "length" "12")])
13080
13081 (define_insn ""
13082   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
13083         (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13084                         (const_int 0))
13085                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
13086   "TARGET_64BIT"
13087   "addc %0,%1,%1\;subfe %0,%1,%0\;addze %0,%2"
13088   [(set_attr "type" "three")
13089    (set_attr "length" "12")])
13090
13091 (define_insn ""
13092   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13093         (compare:CC
13094          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13095                          (const_int 0))
13096                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13097          (const_int 0)))
13098    (clobber (match_scratch:SI 3 "=&r,&r"))]
13099   "TARGET_32BIT"
13100   "@
13101    {a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2
13102    #"
13103   [(set_attr "type" "compare")
13104    (set_attr "length" "12,16")])
13105
13106 (define_split
13107   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13108         (compare:CC
13109          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13110                          (const_int 0))
13111                   (match_operand:SI 2 "gpc_reg_operand" ""))
13112          (const_int 0)))
13113    (clobber (match_scratch:SI 3 ""))]
13114   "TARGET_32BIT && reload_completed"
13115   [(set (match_dup 3)
13116         (plus:SI (gt:SI (match_dup 1) (const_int 0))
13117                   (match_dup 2)))
13118    (set (match_dup 0)
13119         (compare:CC (match_dup 3)
13120                     (const_int 0)))]
13121   "")
13122
13123 (define_insn ""
13124   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13125         (compare:CC
13126          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13127                          (const_int 0))
13128                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13129          (const_int 0)))
13130    (clobber (match_scratch:DI 3 "=&r,&r"))]
13131   "TARGET_64BIT"
13132   "@
13133    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
13134    #"
13135   [(set_attr "type" "compare")
13136    (set_attr "length" "12,16")])
13137
13138 (define_split
13139   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13140         (compare:CC
13141          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13142                          (const_int 0))
13143                   (match_operand:DI 2 "gpc_reg_operand" ""))
13144          (const_int 0)))
13145    (clobber (match_scratch:DI 3 ""))]
13146   "TARGET_64BIT && reload_completed"
13147   [(set (match_dup 3)
13148         (plus:DI (gt:DI (match_dup 1) (const_int 0))
13149                  (match_dup 2)))
13150    (set (match_dup 0)
13151         (compare:CC (match_dup 3)
13152                     (const_int 0)))]
13153   "")
13154
13155 (define_insn ""
13156   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13157         (compare:CC
13158          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13159                          (const_int 0))
13160                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13161          (const_int 0)))
13162    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13163         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13164   "TARGET_32BIT"
13165   "@
13166    {a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze.|addze.} %0,%2
13167    #"
13168   [(set_attr "type" "compare")
13169    (set_attr "length" "12,16")])
13170
13171 (define_split
13172   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13173         (compare:CC
13174          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13175                          (const_int 0))
13176                   (match_operand:SI 2 "gpc_reg_operand" ""))
13177          (const_int 0)))
13178    (set (match_operand:SI 0 "gpc_reg_operand" "")
13179         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13180   "TARGET_32BIT && reload_completed"
13181   [(set (match_dup 0)
13182         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
13183    (set (match_dup 3)
13184         (compare:CC (match_dup 0)
13185                     (const_int 0)))]
13186   "")
13187
13188 (define_insn ""
13189   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13190         (compare:CC
13191          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13192                          (const_int 0))
13193                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13194          (const_int 0)))
13195    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
13196         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13197   "TARGET_64BIT"
13198   "@
13199    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
13200    #"
13201   [(set_attr "type" "compare")
13202    (set_attr "length" "12,16")])
13203
13204 (define_split
13205   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13206         (compare:CC
13207          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13208                          (const_int 0))
13209                   (match_operand:DI 2 "gpc_reg_operand" ""))
13210          (const_int 0)))
13211    (set (match_operand:DI 0 "gpc_reg_operand" "")
13212         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13213   "TARGET_64BIT && reload_completed"
13214   [(set (match_dup 0)
13215         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
13216    (set (match_dup 3)
13217         (compare:CC (match_dup 0)
13218                     (const_int 0)))]
13219   "")
13220
13221 (define_insn ""
13222   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13223         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13224                         (match_operand:SI 2 "reg_or_short_operand" "r"))
13225                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
13226   "TARGET_POWER"
13227   "doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
13228   [(set_attr "length" "12")])
13229
13230 (define_insn ""
13231   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13232         (compare:CC
13233          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13234                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13235                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13236          (const_int 0)))
13237    (clobber (match_scratch:SI 4 "=&r,&r"))]
13238   "TARGET_POWER"
13239   "@
13240    doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
13241    #"
13242   [(set_attr "type" "compare")
13243    (set_attr "length" "12,16")])
13244
13245 (define_split
13246   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13247         (compare:CC
13248          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13249                          (match_operand:SI 2 "reg_or_short_operand" ""))
13250                   (match_operand:SI 3 "gpc_reg_operand" ""))
13251          (const_int 0)))
13252    (clobber (match_scratch:SI 4 ""))]
13253   "TARGET_POWER && reload_completed"
13254   [(set (match_dup 4)
13255         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13256    (set (match_dup 0)
13257         (compare:CC (match_dup 4)
13258                     (const_int 0)))]
13259   "")
13260
13261 (define_insn ""
13262   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13263         (compare:CC
13264          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13265                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13266                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13267          (const_int 0)))
13268    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13269         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13270   "TARGET_POWER"
13271   "@
13272    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
13273    #"
13274   [(set_attr "type" "compare")
13275    (set_attr "length" "12,16")])
13276
13277 (define_split
13278   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13279         (compare:CC
13280          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13281                          (match_operand:SI 2 "reg_or_short_operand" ""))
13282                   (match_operand:SI 3 "gpc_reg_operand" ""))
13283          (const_int 0)))
13284    (set (match_operand:SI 0 "gpc_reg_operand" "")
13285         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13286   "TARGET_POWER && reload_completed"
13287   [(set (match_dup 0)
13288         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13289    (set (match_dup 4)
13290         (compare:CC (match_dup 0)
13291                     (const_int 0)))]
13292   "")
13293
13294 (define_insn ""
13295   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13296         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13297                        (const_int 0))))]
13298   "TARGET_32BIT"
13299   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{srai|srawi} %0,%0,31"
13300   [(set_attr "type" "three")
13301    (set_attr "length" "12")])
13302
13303 (define_insn ""
13304   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13305         (neg:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13306                        (const_int 0))))]
13307   "TARGET_64BIT"
13308   "subfic %0,%1,0\;addme %0,%0\;sradi %0,%0,63"
13309   [(set_attr "type" "three")
13310    (set_attr "length" "12")])
13311
13312 (define_insn ""
13313   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13314         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13315                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
13316   "TARGET_POWER"
13317   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
13318   [(set_attr "length" "12")])
13319
13320 (define_insn_and_split ""
13321   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13322         (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13323                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
13324   "TARGET_32BIT"
13325   "#"
13326   "TARGET_32BIT"
13327   [(set (match_dup 0) (neg:SI (gtu:SI (match_dup 1) (match_dup 2))))
13328    (set (match_dup 0) (neg:SI (match_dup 0)))]
13329   "")
13330
13331 (define_insn_and_split ""
13332   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13333         (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13334                 (match_operand:DI 2 "reg_or_short_operand" "rI")))]
13335   "TARGET_64BIT"
13336   "#"
13337   "TARGET_64BIT"
13338   [(set (match_dup 0) (neg:DI (gtu:DI (match_dup 1) (match_dup 2))))
13339    (set (match_dup 0) (neg:DI (match_dup 0)))]
13340   "")
13341
13342 (define_insn ""
13343   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13344         (compare:CC
13345          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13346                  (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13347          (const_int 0)))
13348    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13349         (gtu:SI (match_dup 1) (match_dup 2)))]
13350   "TARGET_32BIT"
13351   "@
13352    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
13353    #"
13354   [(set_attr "type" "compare")
13355    (set_attr "length" "12,16")])
13356
13357 (define_split
13358   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13359         (compare:CC
13360          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13361                  (match_operand:SI 2 "reg_or_short_operand" ""))
13362          (const_int 0)))
13363    (set (match_operand:SI 0 "gpc_reg_operand" "")
13364         (gtu:SI (match_dup 1) (match_dup 2)))]
13365   "TARGET_32BIT && reload_completed"
13366   [(set (match_dup 0)
13367         (gtu:SI (match_dup 1) (match_dup 2)))
13368    (set (match_dup 3)
13369         (compare:CC (match_dup 0)
13370                     (const_int 0)))]
13371   "")
13372
13373 (define_insn ""
13374   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13375         (compare:CC
13376          (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13377                  (match_operand:DI 2 "reg_or_short_operand" "rI,rI"))
13378          (const_int 0)))
13379    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
13380         (gtu:DI (match_dup 1) (match_dup 2)))]
13381   "TARGET_64BIT"
13382   "@
13383    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;neg. %0,%0
13384    #"
13385   [(set_attr "type" "compare")
13386    (set_attr "length" "12,16")])
13387
13388 (define_split
13389   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13390         (compare:CC
13391          (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13392                  (match_operand:DI 2 "reg_or_short_operand" ""))
13393          (const_int 0)))
13394    (set (match_operand:DI 0 "gpc_reg_operand" "")
13395         (gtu:DI (match_dup 1) (match_dup 2)))]
13396   "TARGET_64BIT && reload_completed"
13397   [(set (match_dup 0)
13398         (gtu:DI (match_dup 1) (match_dup 2)))
13399    (set (match_dup 3)
13400         (compare:CC (match_dup 0)
13401                     (const_int 0)))]
13402   "")
13403
13404 (define_insn_and_split ""
13405   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13406         (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13407                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
13408                  (match_operand:SI 3 "reg_or_short_operand" "rI")))]
13409   "TARGET_32BIT"
13410   "#"
13411   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13412   [(set (match_dup 0) (neg:SI (gtu:SI (match_dup 1) (match_dup 2))))
13413    (set (match_dup 0) (minus:SI (match_dup 3) (match_dup 0)))]
13414   "")
13415
13416 (define_insn_and_split ""
13417   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
13418         (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13419                          (match_operand:DI 2 "reg_or_short_operand" "rI"))
13420                  (match_operand:DI 3 "reg_or_short_operand" "rI")))]
13421   "TARGET_64BIT"
13422   "#"
13423   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13424   [(set (match_dup 0) (neg:DI (gtu:DI (match_dup 1) (match_dup 2))))
13425    (set (match_dup 0) (minus:DI (match_dup 3) (match_dup 0)))]
13426   "")
13427
13428 (define_insn ""
13429   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13430         (compare:CC
13431          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13432                           (match_operand:SI 2 "reg_or_short_operand" "I,r,I,r"))
13433                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13434          (const_int 0)))
13435    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13436   "TARGET_32BIT"
13437   "@
13438    {ai|addic} %4,%1,%k2\;{aze.|addze.} %4,%3
13439    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf.|subf.} %4,%4,%3
13440    #
13441    #"
13442   [(set_attr "type" "compare")
13443    (set_attr "length" "8,12,12,16")])
13444
13445 (define_split
13446   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13447         (compare:CC
13448          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13449                           (match_operand:SI 2 "reg_or_short_operand" ""))
13450                   (match_operand:SI 3 "gpc_reg_operand" ""))
13451          (const_int 0)))
13452    (clobber (match_scratch:SI 4 ""))]
13453   "TARGET_32BIT && reload_completed"
13454   [(set (match_dup 4)
13455         (plus:SI (gtu:SI (match_dup 1) (match_dup 2))
13456                  (match_dup 3)))
13457    (set (match_dup 0)
13458         (compare:CC (match_dup 4)
13459                     (const_int 0)))]
13460   "")
13461
13462 (define_insn ""
13463   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13464         (compare:CC
13465          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
13466                           (match_operand:DI 2 "reg_or_short_operand" "I,r,I,r"))
13467                   (match_operand:DI 3 "gpc_reg_operand" "r,r,r,r"))
13468          (const_int 0)))
13469    (clobber (match_scratch:DI 4 "=&r,&r,&r,&r"))]
13470   "TARGET_64BIT"
13471   "@
13472    addic %4,%1,%k2\;addze. %4,%3
13473    subf%I2c %4,%1,%2\;subfe %4,%4,%4\;subf. %4,%4,%3
13474    #
13475    #"
13476   [(set_attr "type" "compare")
13477    (set_attr "length" "8,12,12,16")])
13478
13479 (define_split
13480   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13481         (compare:CC
13482          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13483                           (match_operand:DI 2 "reg_or_short_operand" ""))
13484                   (match_operand:DI 3 "gpc_reg_operand" ""))
13485          (const_int 0)))
13486    (clobber (match_scratch:DI 4 ""))]
13487   "TARGET_64BIT && reload_completed"
13488   [(set (match_dup 4)
13489         (plus:DI (gtu:DI (match_dup 1) (match_dup 2))
13490                   (match_dup 3)))
13491    (set (match_dup 0)
13492         (compare:CC (match_dup 4)
13493                     (const_int 0)))]
13494   "")
13495
13496 (define_insn ""
13497   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13498         (compare:CC
13499          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13500                           (match_operand:SI 2 "reg_or_short_operand" "I,r,I,r"))
13501                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13502          (const_int 0)))
13503    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13504         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13505   "TARGET_32BIT"
13506   "@
13507    {ai|addic} %0,%1,%k2\;{aze.|addze.} %0,%3
13508    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;{sf.|subf.} %0,%0,%3
13509    #
13510    #"
13511   [(set_attr "type" "compare")
13512    (set_attr "length" "8,12,12,16")])
13513
13514 (define_split
13515   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13516         (compare:CC
13517          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13518                           (match_operand:SI 2 "reg_or_short_operand" ""))
13519                   (match_operand:SI 3 "gpc_reg_operand" ""))
13520          (const_int 0)))
13521    (set (match_operand:SI 0 "gpc_reg_operand" "")
13522         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13523   "TARGET_32BIT && reload_completed"
13524   [(set (match_dup 0)
13525         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13526    (set (match_dup 4)
13527         (compare:CC (match_dup 0)
13528                     (const_int 0)))]
13529   "")
13530
13531 (define_insn ""
13532   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13533         (compare:CC
13534          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
13535                           (match_operand:DI 2 "reg_or_short_operand" "I,r,I,r"))
13536                   (match_operand:DI 3 "gpc_reg_operand" "r,r,r,r"))
13537          (const_int 0)))
13538    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13539         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13540   "TARGET_64BIT"
13541   "@
13542    addic %0,%1,%k2\;addze. %0,%3
13543    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;subf. %0,%0,%3
13544    #
13545    #"
13546   [(set_attr "type" "compare")
13547    (set_attr "length" "8,12,12,16")])
13548
13549 (define_split
13550   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13551         (compare:CC
13552          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13553                           (match_operand:DI 2 "reg_or_short_operand" ""))
13554                   (match_operand:DI 3 "gpc_reg_operand" ""))
13555          (const_int 0)))
13556    (set (match_operand:DI 0 "gpc_reg_operand" "")
13557         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13558   "TARGET_64BIT && reload_completed"
13559   [(set (match_dup 0)
13560         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
13561    (set (match_dup 4)
13562         (compare:CC (match_dup 0)
13563                     (const_int 0)))]
13564   "")
13565
13566 (define_insn ""
13567   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13568         (neg:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13569                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
13570   "TARGET_32BIT"
13571   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
13572   [(set_attr "type" "two")
13573    (set_attr "length" "8")])
13574
13575 (define_insn ""
13576   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13577         (neg:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13578                         (match_operand:DI 2 "reg_or_short_operand" "rI"))))]
13579   "TARGET_64BIT"
13580   "subf%I2c %0,%1,%2\;subfe %0,%0,%0"
13581   [(set_attr "type" "two")
13582    (set_attr "length" "8")])
13583 \f
13584 ;; Define both directions of branch and return.  If we need a reload
13585 ;; register, we'd rather use CR0 since it is much easier to copy a
13586 ;; register CC value to there.
13587
13588 (define_insn ""
13589   [(set (pc)
13590         (if_then_else (match_operator 1 "branch_comparison_operator"
13591                                       [(match_operand 2
13592                                                       "cc_reg_operand" "y")
13593                                        (const_int 0)])
13594                       (label_ref (match_operand 0 "" ""))
13595                       (pc)))]
13596   ""
13597   "*
13598 {
13599   return output_cbranch (operands[1], \"%l0\", 0, insn);
13600 }"
13601   [(set_attr "type" "branch")])
13602
13603 (define_insn ""
13604   [(set (pc)
13605         (if_then_else (match_operator 0 "branch_comparison_operator"
13606                                       [(match_operand 1
13607                                                       "cc_reg_operand" "y")
13608                                        (const_int 0)])
13609                       (return)
13610                       (pc)))]
13611   "direct_return ()"
13612   "*
13613 {
13614   return output_cbranch (operands[0], NULL, 0, insn);
13615 }"
13616   [(set_attr "type" "branch")
13617    (set_attr "length" "4")])
13618
13619 (define_insn ""
13620   [(set (pc)
13621         (if_then_else (match_operator 1 "branch_comparison_operator"
13622                                       [(match_operand 2
13623                                                       "cc_reg_operand" "y")
13624                                        (const_int 0)])
13625                       (pc)
13626                       (label_ref (match_operand 0 "" ""))))]
13627   ""
13628   "*
13629 {
13630   return output_cbranch (operands[1], \"%l0\", 1, insn);
13631 }"
13632   [(set_attr "type" "branch")])
13633
13634 (define_insn ""
13635   [(set (pc)
13636         (if_then_else (match_operator 0 "branch_comparison_operator"
13637                                       [(match_operand 1
13638                                                       "cc_reg_operand" "y")
13639                                        (const_int 0)])
13640                       (pc)
13641                       (return)))]
13642   "direct_return ()"
13643   "*
13644 {
13645   return output_cbranch (operands[0], NULL, 1, insn);
13646 }"
13647   [(set_attr "type" "branch")
13648    (set_attr "length" "4")])
13649
13650 ;; Logic on condition register values.
13651
13652 ; This pattern matches things like
13653 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
13654 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
13655 ;                                  (const_int 1)))
13656 ; which are generated by the branch logic.
13657 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
13658
13659 (define_insn "*cceq_ior_compare"
13660   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13661         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
13662                         [(match_operator:SI 2
13663                                       "branch_positive_comparison_operator"
13664                                       [(match_operand 3
13665                                                       "cc_reg_operand" "y,y")
13666                                        (const_int 0)])
13667                          (match_operator:SI 4
13668                                       "branch_positive_comparison_operator"
13669                                       [(match_operand 5
13670                                                       "cc_reg_operand" "0,y")
13671                                        (const_int 0)])])
13672                       (const_int 1)))]
13673   ""
13674   "cr%q1 %E0,%j2,%j4"
13675   [(set_attr "type" "cr_logical,delayed_cr")])
13676
13677 ; Why is the constant -1 here, but 1 in the previous pattern?
13678 ; Because ~1 has all but the low bit set.
13679 (define_insn ""
13680   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13681         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
13682                         [(not:SI (match_operator:SI 2
13683                                       "branch_positive_comparison_operator"
13684                                       [(match_operand 3
13685                                                       "cc_reg_operand" "y,y")
13686                                        (const_int 0)]))
13687                          (match_operator:SI 4
13688                                 "branch_positive_comparison_operator"
13689                                 [(match_operand 5
13690                                                 "cc_reg_operand" "0,y")
13691                                  (const_int 0)])])
13692                       (const_int -1)))]
13693   ""
13694   "cr%q1 %E0,%j2,%j4"
13695   [(set_attr "type" "cr_logical,delayed_cr")])
13696
13697 (define_insn "*cceq_rev_compare"
13698   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13699         (compare:CCEQ (match_operator:SI 1
13700                                       "branch_positive_comparison_operator"
13701                                       [(match_operand 2
13702                                                       "cc_reg_operand" "0,y")
13703                                        (const_int 0)])
13704                       (const_int 0)))]
13705   ""
13706   "{crnor %E0,%j1,%j1|crnot %E0,%j1}"
13707   [(set_attr "type" "cr_logical,delayed_cr")])
13708
13709 ;; If we are comparing the result of two comparisons, this can be done
13710 ;; using creqv or crxor.
13711
13712 (define_insn_and_split ""
13713   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
13714         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
13715                               [(match_operand 2 "cc_reg_operand" "y")
13716                                (const_int 0)])
13717                       (match_operator 3 "branch_comparison_operator"
13718                               [(match_operand 4 "cc_reg_operand" "y")
13719                                (const_int 0)])))]
13720   ""
13721   "#"
13722   ""
13723   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
13724                                     (match_dup 5)))]
13725   "
13726 {
13727   int positive_1, positive_2;
13728
13729   positive_1 = branch_positive_comparison_operator (operands[1],
13730                                                     GET_MODE (operands[1]));
13731   positive_2 = branch_positive_comparison_operator (operands[3],
13732                                                     GET_MODE (operands[3]));
13733
13734   if (! positive_1)
13735     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
13736                                                             GET_CODE (operands[1])),
13737                                   SImode,
13738                                   operands[2], const0_rtx);
13739   else if (GET_MODE (operands[1]) != SImode)
13740     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
13741                                   operands[2], const0_rtx);
13742
13743   if (! positive_2)
13744     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
13745                                                             GET_CODE (operands[3])),
13746                                   SImode,
13747                                   operands[4], const0_rtx);
13748   else if (GET_MODE (operands[3]) != SImode)
13749     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
13750                                   operands[4], const0_rtx);
13751
13752   if (positive_1 == positive_2)
13753     {
13754       operands[1] = gen_rtx_NOT (SImode, operands[1]);
13755       operands[5] = constm1_rtx;
13756     }
13757   else
13758     {
13759       operands[5] = const1_rtx;
13760     }
13761 }")
13762
13763 ;; Unconditional branch and return.
13764
13765 (define_insn "jump"
13766   [(set (pc)
13767         (label_ref (match_operand 0 "" "")))]
13768   ""
13769   "b %l0"
13770   [(set_attr "type" "branch")])
13771
13772 (define_insn "return"
13773   [(return)]
13774   "direct_return ()"
13775   "{br|blr}"
13776   [(set_attr "type" "jmpreg")])
13777
13778 (define_expand "indirect_jump"
13779   [(set (pc) (match_operand 0 "register_operand" ""))]
13780   ""
13781   "
13782 {
13783   if (TARGET_32BIT)
13784     emit_jump_insn (gen_indirect_jumpsi (operands[0]));
13785   else
13786     emit_jump_insn (gen_indirect_jumpdi (operands[0]));
13787   DONE;
13788 }")
13789
13790 (define_insn "indirect_jumpsi"
13791   [(set (pc) (match_operand:SI 0 "register_operand" "c,*l"))]
13792   "TARGET_32BIT"
13793   "@
13794    bctr
13795    {br|blr}"
13796   [(set_attr "type" "jmpreg")])
13797
13798 (define_insn "indirect_jumpdi"
13799   [(set (pc) (match_operand:DI 0 "register_operand" "c,*l"))]
13800   "TARGET_64BIT"
13801   "@
13802    bctr
13803    blr"
13804   [(set_attr "type" "jmpreg")])
13805
13806 ;; Table jump for switch statements:
13807 (define_expand "tablejump"
13808   [(use (match_operand 0 "" ""))
13809    (use (label_ref (match_operand 1 "" "")))]
13810   ""
13811   "
13812 {
13813   if (TARGET_32BIT)
13814     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
13815   else
13816     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
13817   DONE;
13818 }")
13819
13820 (define_expand "tablejumpsi"
13821   [(set (match_dup 3)
13822         (plus:SI (match_operand:SI 0 "" "")
13823                  (match_dup 2)))
13824    (parallel [(set (pc) (match_dup 3))
13825               (use (label_ref (match_operand 1 "" "")))])]
13826   "TARGET_32BIT"
13827   "
13828 { operands[0] = force_reg (SImode, operands[0]);
13829   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
13830   operands[3] = gen_reg_rtx (SImode);
13831 }")
13832
13833 (define_expand "tablejumpdi"
13834   [(set (match_dup 4)
13835         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "rm")))
13836    (set (match_dup 3)
13837         (plus:DI (match_dup 4)
13838                  (match_dup 2)))
13839    (parallel [(set (pc) (match_dup 3))
13840               (use (label_ref (match_operand 1 "" "")))])]
13841   "TARGET_64BIT"
13842   "
13843 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
13844   operands[3] = gen_reg_rtx (DImode);
13845   operands[4] = gen_reg_rtx (DImode);
13846 }")
13847
13848 (define_insn ""
13849   [(set (pc)
13850         (match_operand:SI 0 "register_operand" "c,*l"))
13851    (use (label_ref (match_operand 1 "" "")))]
13852   "TARGET_32BIT"
13853   "@
13854    bctr
13855    {br|blr}"
13856   [(set_attr "type" "jmpreg")])
13857
13858 (define_insn ""
13859   [(set (pc)
13860         (match_operand:DI 0 "register_operand" "c,*l"))
13861    (use (label_ref (match_operand 1 "" "")))]
13862   "TARGET_64BIT"
13863   "@
13864    bctr
13865    blr"
13866   [(set_attr "type" "jmpreg")])
13867
13868 (define_insn "nop"
13869   [(const_int 0)]
13870   ""
13871   "{cror 0,0,0|nop}")
13872 \f
13873 ;; Define the subtract-one-and-jump insns, starting with the template
13874 ;; so loop.c knows what to generate.
13875
13876 (define_expand "doloop_end"
13877   [(use (match_operand 0 "" ""))        ; loop pseudo
13878    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
13879    (use (match_operand 2 "" ""))        ; max iterations
13880    (use (match_operand 3 "" ""))        ; loop level
13881    (use (match_operand 4 "" ""))]       ; label
13882   ""
13883   "
13884 {
13885   /* Only use this on innermost loops.  */
13886   if (INTVAL (operands[3]) > 1)
13887     FAIL;
13888   if (TARGET_64BIT)
13889     {
13890       if (GET_MODE (operands[0]) != DImode)
13891         FAIL;
13892       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
13893     }
13894   else
13895     {
13896       if (GET_MODE (operands[0]) != SImode)
13897         FAIL;
13898       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
13899     }
13900   DONE;
13901 }")
13902
13903 (define_expand "ctrsi"
13904   [(parallel [(set (pc)
13905                    (if_then_else (ne (match_operand:SI 0 "register_operand" "")
13906                                      (const_int 1))
13907                                  (label_ref (match_operand 1 "" ""))
13908                                  (pc)))
13909               (set (match_dup 0)
13910                    (plus:SI (match_dup 0)
13911                             (const_int -1)))
13912               (clobber (match_scratch:CC 2 ""))
13913               (clobber (match_scratch:SI 3 ""))])]
13914   "TARGET_32BIT"
13915   "")
13916
13917 (define_expand "ctrdi"
13918   [(parallel [(set (pc)
13919                    (if_then_else (ne (match_operand:DI 0 "register_operand" "")
13920                                      (const_int 1))
13921                                  (label_ref (match_operand 1 "" ""))
13922                                  (pc)))
13923               (set (match_dup 0)
13924                    (plus:DI (match_dup 0)
13925                             (const_int -1)))
13926               (clobber (match_scratch:CC 2 ""))
13927               (clobber (match_scratch:DI 3 ""))])]
13928   "TARGET_64BIT"
13929   "")
13930
13931 ;; We need to be able to do this for any operand, including MEM, or we
13932 ;; will cause reload to blow up since we don't allow output reloads on
13933 ;; JUMP_INSNs.
13934 ;; For the length attribute to be calculated correctly, the
13935 ;; label MUST be operand 0.
13936
13937 (define_insn "*ctrsi_internal1"
13938   [(set (pc)
13939         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
13940                           (const_int 1))
13941                       (label_ref (match_operand 0 "" ""))
13942                       (pc)))
13943    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
13944         (plus:SI (match_dup 1)
13945                  (const_int -1)))
13946    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13947    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
13948   "TARGET_32BIT"
13949   "*
13950 {
13951   if (which_alternative != 0)
13952     return \"#\";
13953   else if (get_attr_length (insn) == 4)
13954     return \"{bdn|bdnz} %l0\";
13955   else
13956     return \"bdz $+8\;b %l0\";
13957 }"
13958   [(set_attr "type" "branch")
13959    (set_attr "length" "*,12,16,16")])
13960
13961 (define_insn "*ctrsi_internal2"
13962   [(set (pc)
13963         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
13964                           (const_int 1))
13965                       (pc)
13966                       (label_ref (match_operand 0 "" ""))))
13967    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
13968         (plus:SI (match_dup 1)
13969                  (const_int -1)))
13970    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13971    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
13972   "TARGET_32BIT"
13973   "*
13974 {
13975   if (which_alternative != 0)
13976     return \"#\";
13977   else if (get_attr_length (insn) == 4)
13978     return \"bdz %l0\";
13979   else
13980     return \"{bdn|bdnz} $+8\;b %l0\";
13981 }"
13982   [(set_attr "type" "branch")
13983    (set_attr "length" "*,12,16,16")])
13984
13985 (define_insn "*ctrdi_internal1"
13986   [(set (pc)
13987         (if_then_else (ne (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
13988                           (const_int 1))
13989                       (label_ref (match_operand 0 "" ""))
13990                       (pc)))
13991    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
13992         (plus:DI (match_dup 1)
13993                  (const_int -1)))
13994    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13995    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
13996   "TARGET_64BIT"
13997   "*
13998 {
13999   if (which_alternative != 0)
14000     return \"#\";
14001   else if (get_attr_length (insn) == 4)
14002     return \"{bdn|bdnz} %l0\";
14003   else
14004     return \"bdz $+8\;b %l0\";
14005 }"
14006   [(set_attr "type" "branch")
14007    (set_attr "length" "*,12,16,16")])
14008
14009 (define_insn "*ctrdi_internal2"
14010   [(set (pc)
14011         (if_then_else (ne (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14012                           (const_int 1))
14013                       (pc)
14014                       (label_ref (match_operand 0 "" ""))))
14015    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14016         (plus:DI (match_dup 1)
14017                  (const_int -1)))
14018    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14019    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14020   "TARGET_64BIT"
14021   "*
14022 {
14023   if (which_alternative != 0)
14024     return \"#\";
14025   else if (get_attr_length (insn) == 4)
14026     return \"bdz %l0\";
14027   else
14028     return \"{bdn|bdnz} $+8\;b %l0\";
14029 }"
14030   [(set_attr "type" "branch")
14031    (set_attr "length" "*,12,16,16")])
14032
14033 ;; Similar but use EQ
14034
14035 (define_insn "*ctrsi_internal5"
14036   [(set (pc)
14037         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14038                           (const_int 1))
14039                       (label_ref (match_operand 0 "" ""))
14040                       (pc)))
14041    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14042         (plus:SI (match_dup 1)
14043                  (const_int -1)))
14044    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14045    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14046   "TARGET_32BIT"
14047   "*
14048 {
14049   if (which_alternative != 0)
14050     return \"#\";
14051   else if (get_attr_length (insn) == 4)
14052     return \"bdz %l0\";
14053   else
14054     return \"{bdn|bdnz} $+8\;b %l0\";
14055 }"
14056   [(set_attr "type" "branch")
14057    (set_attr "length" "*,12,16,16")])
14058
14059 (define_insn "*ctrsi_internal6"
14060   [(set (pc)
14061         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14062                           (const_int 1))
14063                       (pc)
14064                       (label_ref (match_operand 0 "" ""))))
14065    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14066         (plus:SI (match_dup 1)
14067                  (const_int -1)))
14068    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14069    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14070   "TARGET_32BIT"
14071   "*
14072 {
14073   if (which_alternative != 0)
14074     return \"#\";
14075   else if (get_attr_length (insn) == 4)
14076     return \"{bdn|bdnz} %l0\";
14077   else
14078     return \"bdz $+8\;b %l0\";
14079 }"
14080   [(set_attr "type" "branch")
14081    (set_attr "length" "*,12,16,16")])
14082
14083 (define_insn "*ctrdi_internal5"
14084   [(set (pc)
14085         (if_then_else (eq (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14086                           (const_int 1))
14087                       (label_ref (match_operand 0 "" ""))
14088                       (pc)))
14089    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14090         (plus:DI (match_dup 1)
14091                  (const_int -1)))
14092    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14093    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14094   "TARGET_64BIT"
14095   "*
14096 {
14097   if (which_alternative != 0)
14098     return \"#\";
14099   else if (get_attr_length (insn) == 4)
14100     return \"bdz %l0\";
14101   else
14102     return \"{bdn|bdnz} $+8\;b %l0\";
14103 }"
14104   [(set_attr "type" "branch")
14105    (set_attr "length" "*,12,16,16")])
14106
14107 (define_insn "*ctrdi_internal6"
14108   [(set (pc)
14109         (if_then_else (eq (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14110                           (const_int 1))
14111                       (pc)
14112                       (label_ref (match_operand 0 "" ""))))
14113    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14114         (plus:DI (match_dup 1)
14115                  (const_int -1)))
14116    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14117    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14118   "TARGET_64BIT"
14119   "*
14120 {
14121   if (which_alternative != 0)
14122     return \"#\";
14123   else if (get_attr_length (insn) == 4)
14124     return \"{bdn|bdnz} %l0\";
14125   else
14126     return \"bdz $+8\;b %l0\";
14127 }"
14128   [(set_attr "type" "branch")
14129    (set_attr "length" "*,12,16,16")])
14130
14131 ;; Now the splitters if we could not allocate the CTR register
14132
14133 (define_split
14134   [(set (pc)
14135         (if_then_else (match_operator 2 "comparison_operator"
14136                                       [(match_operand:SI 1 "gpc_reg_operand" "")
14137                                        (const_int 1)])
14138                       (match_operand 5 "" "")
14139                       (match_operand 6 "" "")))
14140    (set (match_operand:SI 0 "gpc_reg_operand" "")
14141         (plus:SI (match_dup 1)
14142                  (const_int -1)))
14143    (clobber (match_scratch:CC 3 ""))
14144    (clobber (match_scratch:SI 4 ""))]
14145   "TARGET_32BIT && reload_completed"
14146   [(parallel [(set (match_dup 3)
14147                    (compare:CC (plus:SI (match_dup 1)
14148                                         (const_int -1))
14149                                (const_int 0)))
14150               (set (match_dup 0)
14151                    (plus:SI (match_dup 1)
14152                             (const_int -1)))])
14153    (set (pc) (if_then_else (match_dup 7)
14154                            (match_dup 5)
14155                            (match_dup 6)))]
14156   "
14157 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14158                                 operands[3], const0_rtx); }")
14159
14160 (define_split
14161   [(set (pc)
14162         (if_then_else (match_operator 2 "comparison_operator"
14163                                       [(match_operand:SI 1 "gpc_reg_operand" "")
14164                                        (const_int 1)])
14165                       (match_operand 5 "" "")
14166                       (match_operand 6 "" "")))
14167    (set (match_operand:SI 0 "nonimmediate_operand" "")
14168         (plus:SI (match_dup 1) (const_int -1)))
14169    (clobber (match_scratch:CC 3 ""))
14170    (clobber (match_scratch:SI 4 ""))]
14171   "TARGET_32BIT && reload_completed
14172    && ! gpc_reg_operand (operands[0], SImode)"
14173   [(parallel [(set (match_dup 3)
14174                    (compare:CC (plus:SI (match_dup 1)
14175                                         (const_int -1))
14176                                (const_int 0)))
14177               (set (match_dup 4)
14178                    (plus:SI (match_dup 1)
14179                             (const_int -1)))])
14180    (set (match_dup 0)
14181         (match_dup 4))
14182    (set (pc) (if_then_else (match_dup 7)
14183                            (match_dup 5)
14184                            (match_dup 6)))]
14185   "
14186 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14187                                 operands[3], const0_rtx); }")
14188 (define_split
14189   [(set (pc)
14190         (if_then_else (match_operator 2 "comparison_operator"
14191                                       [(match_operand:DI 1 "gpc_reg_operand" "")
14192                                        (const_int 1)])
14193                       (match_operand 5 "" "")
14194                       (match_operand 6 "" "")))
14195    (set (match_operand:DI 0 "gpc_reg_operand" "")
14196         (plus:DI (match_dup 1)
14197                  (const_int -1)))
14198    (clobber (match_scratch:CC 3 ""))
14199    (clobber (match_scratch:DI 4 ""))]
14200   "TARGET_64BIT && reload_completed"
14201   [(parallel [(set (match_dup 3)
14202                    (compare:CC (plus:DI (match_dup 1)
14203                                         (const_int -1))
14204                                (const_int 0)))
14205               (set (match_dup 0)
14206                    (plus:DI (match_dup 1)
14207                             (const_int -1)))])
14208    (set (pc) (if_then_else (match_dup 7)
14209                            (match_dup 5)
14210                            (match_dup 6)))]
14211   "
14212 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14213                                 operands[3], const0_rtx); }")
14214
14215 (define_split
14216   [(set (pc)
14217         (if_then_else (match_operator 2 "comparison_operator"
14218                                       [(match_operand:DI 1 "gpc_reg_operand" "")
14219                                        (const_int 1)])
14220                       (match_operand 5 "" "")
14221                       (match_operand 6 "" "")))
14222    (set (match_operand:DI 0 "nonimmediate_operand" "")
14223         (plus:DI (match_dup 1) (const_int -1)))
14224    (clobber (match_scratch:CC 3 ""))
14225    (clobber (match_scratch:DI 4 ""))]
14226   "TARGET_64BIT && reload_completed
14227    && ! gpc_reg_operand (operands[0], DImode)"
14228   [(parallel [(set (match_dup 3)
14229                    (compare:CC (plus:DI (match_dup 1)
14230                                         (const_int -1))
14231                                (const_int 0)))
14232               (set (match_dup 4)
14233                    (plus:DI (match_dup 1)
14234                             (const_int -1)))])
14235    (set (match_dup 0)
14236         (match_dup 4))
14237    (set (pc) (if_then_else (match_dup 7)
14238                            (match_dup 5)
14239                            (match_dup 6)))]
14240   "
14241 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14242                                 operands[3], const0_rtx); }")
14243 \f
14244 (define_insn "trap"
14245   [(trap_if (const_int 1) (const_int 0))]
14246   ""
14247   "{t 31,0,0|trap}")
14248
14249 (define_expand "conditional_trap"
14250   [(trap_if (match_operator 0 "trap_comparison_operator"
14251                             [(match_dup 2) (match_dup 3)])
14252             (match_operand 1 "const_int_operand" ""))]
14253   ""
14254   "if (rs6000_compare_fp_p || operands[1] != const0_rtx) FAIL;
14255    operands[2] = rs6000_compare_op0;
14256    operands[3] = rs6000_compare_op1;")
14257
14258 (define_insn ""
14259   [(trap_if (match_operator 0 "trap_comparison_operator"
14260                             [(match_operand:SI 1 "register_operand" "r")
14261                              (match_operand:SI 2 "reg_or_short_operand" "rI")])
14262             (const_int 0))]
14263   ""
14264   "{t|tw}%V0%I2 %1,%2")
14265
14266 (define_insn ""
14267   [(trap_if (match_operator 0 "trap_comparison_operator"
14268                             [(match_operand:DI 1 "register_operand" "r")
14269                              (match_operand:DI 2 "reg_or_short_operand" "rI")])
14270             (const_int 0))]
14271   "TARGET_POWERPC64"
14272   "td%V0%I2 %1,%2")
14273 \f
14274 ;; Insns related to generating the function prologue and epilogue.
14275
14276 (define_expand "prologue"
14277   [(use (const_int 0))]
14278   "TARGET_SCHED_PROLOG"
14279   "
14280 {
14281       rs6000_emit_prologue ();
14282       DONE;
14283 }")
14284
14285 (define_insn "*movesi_from_cr_one"
14286   [(match_parallel 0 "mfcr_operation"
14287                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14288                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
14289                                      (match_operand 3 "immediate_operand" "n")]
14290                           UNSPEC_MOVESI_FROM_CR))])]
14291   "TARGET_MFCRF"
14292   "*
14293 {
14294   int mask = 0;
14295   int i;
14296   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14297   {
14298     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14299     operands[4] = GEN_INT (mask);
14300     output_asm_insn (\"mfcr %1,%4\", operands);
14301   }
14302   return \"\";
14303 }"
14304   [(set_attr "type" "mfcrf")])
14305
14306 (define_insn "movesi_from_cr"
14307   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14308         (unspec:SI [(reg:CC 68) (reg:CC 69) (reg:CC 70) (reg:CC 71)
14309                     (reg:CC 72) (reg:CC 73) (reg:CC 74) (reg:CC 75)]
14310                    UNSPEC_MOVESI_FROM_CR))]
14311   ""
14312   "mfcr %0"
14313   [(set_attr "type" "mfcr")])
14314
14315 (define_insn "*stmw"
14316   [(match_parallel 0 "stmw_operation"
14317                    [(set (match_operand:SI 1 "memory_operand" "=m")
14318                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
14319   "TARGET_MULTIPLE"
14320   "{stm|stmw} %2,%1")
14321
14322 (define_insn "*save_fpregs_si"
14323   [(match_parallel 0 "any_parallel_operand"
14324                    [(clobber (match_operand:SI 1 "register_operand" "=l"))
14325                     (use (match_operand:SI 2 "call_operand" "s"))
14326                     (set (match_operand:DF 3 "memory_operand" "=m")
14327                          (match_operand:DF 4 "gpc_reg_operand" "f"))])]
14328   "TARGET_32BIT"
14329   "bl %z2"
14330   [(set_attr "type" "branch")
14331    (set_attr "length" "4")])
14332
14333 (define_insn "*save_fpregs_di"
14334   [(match_parallel 0 "any_parallel_operand"
14335                    [(clobber (match_operand:DI 1 "register_operand" "=l"))
14336                     (use (match_operand:DI 2 "call_operand" "s"))
14337                     (set (match_operand:DF 3 "memory_operand" "=m")
14338                          (match_operand:DF 4 "gpc_reg_operand" "f"))])]
14339   "TARGET_64BIT"
14340   "bl %z2"
14341   [(set_attr "type" "branch")
14342    (set_attr "length" "4")])
14343
14344 ; These are to explain that changes to the stack pointer should
14345 ; not be moved over stores to stack memory.
14346 (define_insn "stack_tie"
14347   [(set (match_operand:BLK 0 "memory_operand" "+m")
14348         (unspec:BLK [(match_dup 0)] UNSPEC_TIE))]
14349   ""
14350   ""
14351   [(set_attr "length" "0")])
14352
14353
14354 (define_expand "epilogue"
14355   [(use (const_int 0))]
14356   "TARGET_SCHED_PROLOG"
14357   "
14358 {
14359       rs6000_emit_epilogue (FALSE);
14360       DONE;
14361 }")
14362
14363 ; On some processors, doing the mtcrf one CC register at a time is
14364 ; faster (like on the 604e).  On others, doing them all at once is
14365 ; faster; for instance, on the 601 and 750.
14366
14367 (define_expand "movsi_to_cr_one"
14368   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14369         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14370                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
14371   ""
14372   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
14373
14374 (define_insn "*movsi_to_cr"
14375   [(match_parallel 0 "mtcrf_operation"
14376                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
14377                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
14378                                      (match_operand 3 "immediate_operand" "n")]
14379                                     UNSPEC_MOVESI_TO_CR))])]
14380  ""
14381  "*
14382 {
14383   int mask = 0;
14384   int i;
14385   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14386     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14387   operands[4] = GEN_INT (mask);
14388   return \"mtcrf %4,%2\";
14389 }"
14390   [(set_attr "type" "mtcr")])
14391
14392 (define_insn "*mtcrfsi"
14393   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14394         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14395                     (match_operand 2 "immediate_operand" "n")]
14396                    UNSPEC_MOVESI_TO_CR))]
14397   "GET_CODE (operands[0]) == REG
14398    && CR_REGNO_P (REGNO (operands[0]))
14399    && GET_CODE (operands[2]) == CONST_INT
14400    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
14401   "mtcrf %R0,%1"
14402   [(set_attr "type" "mtcr")])
14403
14404 ; The load-multiple instructions have similar properties.
14405 ; Note that "load_multiple" is a name known to the machine-independent
14406 ; code that actually corresponds to the powerpc load-string.
14407
14408 (define_insn "*lmw"
14409   [(match_parallel 0 "lmw_operation"
14410                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14411                          (match_operand:SI 2 "memory_operand" "m"))])]
14412   "TARGET_MULTIPLE"
14413   "{lm|lmw} %1,%2")
14414
14415 (define_insn "*return_internal_si"
14416   [(return)
14417    (use (match_operand:SI 0 "register_operand" "lc"))]
14418   "TARGET_32BIT"
14419   "b%T0"
14420   [(set_attr "type" "jmpreg")])
14421
14422 (define_insn "*return_internal_di"
14423   [(return)
14424    (use (match_operand:DI 0 "register_operand" "lc"))]
14425   "TARGET_64BIT"
14426   "b%T0"
14427   [(set_attr "type" "jmpreg")])
14428
14429 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
14430 ; stuff was in GCC.  Oh, and "any_parallel_operand" is a bit flexible...
14431
14432 (define_insn "*return_and_restore_fpregs_si"
14433  [(match_parallel 0 "any_parallel_operand"
14434                   [(return)
14435                    (use (match_operand:SI 1 "register_operand" "l"))
14436                    (use (match_operand:SI 2 "call_operand" "s"))
14437                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
14438                         (match_operand:DF 4 "memory_operand" "m"))])]
14439  "TARGET_32BIT"
14440  "b %z2")
14441
14442 (define_insn "*return_and_restore_fpregs_di"
14443  [(match_parallel 0 "any_parallel_operand"
14444                   [(return)
14445                    (use (match_operand:DI 1 "register_operand" "l"))
14446                    (use (match_operand:DI 2 "call_operand" "s"))
14447                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
14448                         (match_operand:DF 4 "memory_operand" "m"))])]
14449  "TARGET_64BIT"
14450  "b %z2")
14451
14452 ; This is used in compiling the unwind routines.
14453 (define_expand "eh_return"
14454   [(use (match_operand 0 "general_operand" ""))]
14455   ""
14456   "
14457 {
14458   if (TARGET_32BIT)
14459     emit_insn (gen_eh_set_lr_si (operands[0]));
14460   else
14461     emit_insn (gen_eh_set_lr_di (operands[0]));
14462   DONE;
14463 }")
14464
14465 ; We can't expand this before we know where the link register is stored.
14466 (define_insn "eh_set_lr_si"
14467   [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
14468                     UNSPECV_EH_RR)
14469    (clobber (match_scratch:SI 1 "=&b"))]
14470   "TARGET_32BIT"
14471   "#")
14472
14473 (define_insn "eh_set_lr_di"
14474   [(unspec_volatile [(match_operand:DI 0 "register_operand" "r")]
14475                     UNSPECV_EH_RR)
14476    (clobber (match_scratch:DI 1 "=&b"))]
14477   "TARGET_64BIT"
14478   "#")
14479
14480 (define_split
14481   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
14482    (clobber (match_scratch 1 ""))]
14483   "reload_completed"
14484   [(const_int 0)]
14485   "
14486 {
14487   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
14488   DONE;
14489 }")
14490
14491 (define_insn "prefetch"
14492   [(prefetch (match_operand:V4SI 0 "address_operand" "p")
14493              (match_operand:SI 1 "const_int_operand" "n")
14494              (match_operand:SI 2 "const_int_operand" "n"))]
14495   "TARGET_POWERPC"
14496   "*
14497 {
14498   if (GET_CODE (operands[0]) == REG)
14499     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
14500   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
14501 }"
14502   [(set_attr "type" "load")])
14503 \f
14504 ; Atomic instructions
14505
14506 (define_insn "memory_barrier"
14507   [(set (mem:BLK (match_scratch 0 "X"))
14508         (unspec:BLK [(mem:BLK (match_scratch 1 "X"))] UNSPEC_SYNC))]
14509   ""
14510   "{ics|sync}")
14511
14512 (define_insn "sync_compare_and_swap<mode>"
14513   [(set (match_operand:GPR 1 "memory_operand" "+Z")
14514         (unspec:GPR [(match_dup 1)
14515                      (match_operand:GPR 2 "reg_or_short_operand" "rI")
14516                      (match_operand:GPR 3 "gpc_reg_operand" "r")]
14517                     UNSPEC_SYNC_SWAP))
14518    (set (match_operand:GPR 0 "gpc_reg_operand" "=&r") (match_dup 1))
14519    (set (mem:BLK (match_scratch 5 "X"))
14520         (unspec:BLK [(mem:BLK (match_scratch 6 "X"))] UNSPEC_SYNC))
14521    (clobber (match_scratch:CC 4 "=&x"))]
14522   "TARGET_POWERPC"
14523   "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"
14524   [(set_attr "length" "28")])
14525
14526 (define_expand "sync_add<mode>"
14527   [(use (match_operand:INT1 0 "memory_operand" ""))
14528    (use (match_operand:INT1 1 "add_operand" ""))]
14529   "TARGET_POWERPC"
14530   "
14531 {
14532   rs6000_emit_sync (PLUS, <MODE>mode, operands[0], operands[1], 
14533                     NULL_RTX, NULL_RTX, true);
14534   DONE;
14535 }")
14536
14537 (define_expand "sync_sub<mode>"
14538   [(use (match_operand:GPR 0 "memory_operand" ""))
14539    (use (match_operand:GPR 1 "gpc_reg_operand" ""))]
14540   "TARGET_POWERPC"
14541   "
14542 {
14543   rs6000_emit_sync (MINUS, <MODE>mode, operands[0], operands[1], 
14544                     NULL_RTX, NULL_RTX, true);
14545   DONE;
14546 }")
14547
14548 (define_expand "sync_ior<mode>"
14549   [(use (match_operand:INT1 0 "memory_operand" ""))
14550    (use (match_operand:INT1 1 "logical_operand" ""))]
14551   "TARGET_POWERPC"
14552   "
14553 {
14554   rs6000_emit_sync (IOR, <MODE>mode, operands[0], operands[1], 
14555                     NULL_RTX, NULL_RTX, true);
14556   DONE;
14557 }")
14558
14559 (define_expand "sync_and<mode>"
14560   [(use (match_operand:INT1 0 "memory_operand" ""))
14561    (use (match_operand:INT1 1 "and_operand" ""))]
14562   "TARGET_POWERPC"
14563   "
14564 {
14565   rs6000_emit_sync (AND, <MODE>mode, operands[0], operands[1], 
14566                     NULL_RTX, NULL_RTX, true);
14567   DONE;
14568 }")
14569
14570 (define_expand "sync_xor<mode>"
14571   [(use (match_operand:INT1 0 "memory_operand" ""))
14572    (use (match_operand:INT1 1 "logical_operand" ""))]
14573   "TARGET_POWERPC"
14574   "
14575 {
14576   rs6000_emit_sync (XOR, <MODE>mode, operands[0], operands[1], 
14577                     NULL_RTX, NULL_RTX, true);
14578   DONE;
14579 }")
14580
14581 (define_expand "sync_nand<mode>"
14582   [(use (match_operand:INT1 0 "memory_operand" ""))
14583    (use (match_operand:INT1 1 "gpc_reg_operand" ""))]
14584   "TARGET_POWERPC"
14585   "
14586 {
14587   rs6000_emit_sync (AND, <MODE>mode, 
14588                     gen_rtx_NOT (<MODE>mode, operands[0]),
14589                     operands[1],
14590                     NULL_RTX, NULL_RTX, true);
14591   DONE;
14592 }")
14593
14594 (define_expand "sync_old_add<mode>"
14595   [(use (match_operand:INT1 0 "gpc_reg_operand" ""))
14596    (use (match_operand:INT1 1 "memory_operand" ""))
14597    (use (match_operand:INT1 2 "add_operand" ""))]
14598   "TARGET_POWERPC"
14599   "
14600 {
14601   rs6000_emit_sync (PLUS, <MODE>mode, operands[1], operands[2], 
14602                     operands[0], NULL_RTX, true);
14603   DONE;
14604 }")
14605
14606 (define_expand "sync_old_sub<mode>"
14607   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
14608    (use (match_operand:GPR 1 "memory_operand" ""))
14609    (use (match_operand:GPR 2 "gpc_reg_operand" ""))]
14610   "TARGET_POWERPC"
14611   "
14612 {
14613   rs6000_emit_sync (MINUS, <MODE>mode, operands[1], operands[2], 
14614                     operands[0], NULL_RTX, true);
14615   DONE;
14616 }")
14617
14618 (define_expand "sync_old_ior<mode>"
14619   [(use (match_operand:INT1 0 "gpc_reg_operand" ""))
14620    (use (match_operand:INT1 1 "memory_operand" ""))
14621    (use (match_operand:INT1 2 "logical_operand" ""))]
14622   "TARGET_POWERPC"
14623   "
14624 {
14625   rs6000_emit_sync (IOR, <MODE>mode, operands[1], operands[2], 
14626                     operands[0], NULL_RTX, true);
14627   DONE;
14628 }")
14629
14630 (define_expand "sync_old_and<mode>"
14631   [(use (match_operand:INT1 0 "gpc_reg_operand" ""))
14632    (use (match_operand:INT1 1 "memory_operand" ""))
14633    (use (match_operand:INT1 2 "and_operand" ""))]
14634   "TARGET_POWERPC"
14635   "
14636 {
14637   rs6000_emit_sync (AND, <MODE>mode, operands[1], operands[2], 
14638                     operands[0], NULL_RTX, true);
14639   DONE;
14640 }")
14641
14642 (define_expand "sync_old_xor<mode>"
14643   [(use (match_operand:INT1 0 "gpc_reg_operand" ""))
14644    (use (match_operand:INT1 1 "memory_operand" ""))
14645    (use (match_operand:INT1 2 "logical_operand" ""))]
14646   "TARGET_POWERPC"
14647   "
14648 {
14649   rs6000_emit_sync (XOR, <MODE>mode, operands[1], operands[2], 
14650                     operands[0], NULL_RTX, true);
14651   DONE;
14652 }")
14653
14654 (define_expand "sync_old_nand<mode>"
14655   [(use (match_operand:INT1 0 "gpc_reg_operand" ""))
14656    (use (match_operand:INT1 1 "memory_operand" ""))
14657    (use (match_operand:INT1 2 "gpc_reg_operand" ""))]
14658   "TARGET_POWERPC"
14659   "
14660 {
14661   rs6000_emit_sync (AND, <MODE>mode, 
14662                     gen_rtx_NOT (<MODE>mode, operands[1]),
14663                     operands[2],
14664                     operands[0], NULL_RTX, true);
14665   DONE;
14666 }")
14667
14668 (define_expand "sync_new_add<mode>"
14669   [(use (match_operand:INT1 0 "gpc_reg_operand" ""))
14670    (use (match_operand:INT1 1 "memory_operand" ""))
14671    (use (match_operand:INT1 2 "add_operand" ""))]
14672   "TARGET_POWERPC"
14673   "
14674 {
14675   rs6000_emit_sync (PLUS, <MODE>mode, operands[1], operands[2], 
14676                     NULL_RTX, operands[0], true);
14677   DONE;
14678 }")
14679
14680 (define_expand "sync_new_sub<mode>"
14681   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
14682    (use (match_operand:GPR 1 "memory_operand" ""))
14683    (use (match_operand:GPR 2 "gpc_reg_operand" ""))]
14684   "TARGET_POWERPC"
14685   "
14686 {
14687   rs6000_emit_sync (MINUS, <MODE>mode, operands[1], operands[2], 
14688                     NULL_RTX, operands[0], true);
14689   DONE;
14690 }")
14691
14692 (define_expand "sync_new_ior<mode>"
14693   [(use (match_operand:INT1 0 "gpc_reg_operand" ""))
14694    (use (match_operand:INT1 1 "memory_operand" ""))
14695    (use (match_operand:INT1 2 "logical_operand" ""))]
14696   "TARGET_POWERPC"
14697   "
14698 {
14699   rs6000_emit_sync (IOR, <MODE>mode, operands[1], operands[2], 
14700                     NULL_RTX, operands[0], true);
14701   DONE;
14702 }")
14703
14704 (define_expand "sync_new_and<mode>"
14705   [(use (match_operand:INT1 0 "gpc_reg_operand" ""))
14706    (use (match_operand:INT1 1 "memory_operand" ""))
14707    (use (match_operand:INT1 2 "and_operand" ""))]
14708   "TARGET_POWERPC"
14709   "
14710 {
14711   rs6000_emit_sync (AND, <MODE>mode, operands[1], operands[2], 
14712                     NULL_RTX, operands[0], true);
14713   DONE;
14714 }")
14715
14716 (define_expand "sync_new_xor<mode>"
14717   [(use (match_operand:INT1 0 "gpc_reg_operand" ""))
14718    (use (match_operand:INT1 1 "memory_operand" ""))
14719    (use (match_operand:INT1 2 "logical_operand" ""))]
14720   "TARGET_POWERPC"
14721   "
14722 {
14723   rs6000_emit_sync (XOR, <MODE>mode, operands[1], operands[2], 
14724                     NULL_RTX, operands[0], true);
14725   DONE;
14726 }")
14727
14728 (define_expand "sync_new_nand<mode>"
14729   [(use (match_operand:INT1 0 "gpc_reg_operand" ""))
14730    (use (match_operand:INT1 1 "memory_operand" ""))
14731    (use (match_operand:INT1 2 "gpc_reg_operand" ""))]
14732   "TARGET_POWERPC"
14733   "
14734 {
14735   rs6000_emit_sync (AND, <MODE>mode, 
14736                     gen_rtx_NOT (<MODE>mode, operands[1]),
14737                     operands[2],
14738                     NULL_RTX, operands[0], true);
14739   DONE;
14740 }")
14741
14742 ; the sync_*_internal patterns all have these operands:
14743 ; 0 - memory location
14744 ; 1 - operand
14745 ; 2 - value in memory after operation
14746 ; 3 - value in memory immediately before operation
14747
14748 (define_insn "*sync_add<mode>_internal"
14749   [(set (match_operand:GPR 2 "gpc_reg_operand" "=&r,&r")
14750         (plus:GPR (match_operand:GPR 0 "memory_operand" "+Z,Z")
14751                  (match_operand:GPR 1 "add_operand" "rI,L")))
14752    (set (match_operand:GPR 3 "gpc_reg_operand" "=&b,&b") (match_dup 0))
14753    (set (match_dup 0) 
14754         (unspec:GPR [(plus:GPR (match_dup 0) (match_dup 1))]
14755                    UNSPEC_SYNC_OP))
14756    (clobber (match_scratch:CC 4 "=&x,&x"))]
14757   "TARGET_POWERPC"
14758   "@
14759    <larx> %3,%y0\n\tadd%I1 %2,%3,%1\n\t<stcx> %2,%y0\n\tbne- $-12
14760    <larx> %3,%y0\n\taddis %2,%3,%v1\n\t<stcx> %2,%y0\n\tbne- $-12"
14761   [(set_attr "length" "16,16")])
14762
14763 (define_insn "*sync_addshort_internal"
14764   [(set (match_operand:SI 2 "gpc_reg_operand" "=&r")
14765         (ior:SI (and:SI (plus:SI (match_operand:SI 0 "memory_operand" "+Z")
14766                                  (match_operand:SI 1 "add_operand" "rI"))
14767                         (match_operand:SI 4 "gpc_reg_operand" "r"))
14768                 (and:SI (not:SI (match_dup 4)) (match_dup 0))))
14769    (set (match_operand:SI 3 "gpc_reg_operand" "=&b") (match_dup 0))
14770    (set (match_dup 0) 
14771         (unspec:SI [(ior:SI (and:SI (plus:SI (match_dup 0) (match_dup 1))
14772                                     (match_dup 4))
14773                             (and:SI (not:SI (match_dup 4)) (match_dup 0)))]
14774                    UNSPEC_SYNC_OP))
14775    (clobber (match_scratch:CC 5 "=&x"))
14776    (clobber (match_scratch:SI 6 "=&r"))]
14777   "TARGET_POWERPC"
14778   "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"
14779   [(set_attr "length" "28")])
14780
14781 (define_insn "*sync_sub<mode>_internal"
14782   [(set (match_operand:GPR 2 "gpc_reg_operand" "=&r")
14783         (minus:GPR (match_operand:GPR 0 "memory_operand" "+Z")
14784                   (match_operand:GPR 1 "gpc_reg_operand" "r")))
14785    (set (match_operand:GPR 3 "gpc_reg_operand" "=&b") (match_dup 0))
14786    (set (match_dup 0) 
14787         (unspec:GPR [(minus:GPR (match_dup 0) (match_dup 1))]
14788                    UNSPEC_SYNC_OP))
14789    (clobber (match_scratch:CC 4 "=&x"))]
14790   "TARGET_POWERPC"
14791   "<larx> %3,%y0\n\tsubf %2,%1,%3\n\t<stcx> %2,%y0\n\tbne- $-12"
14792   [(set_attr "length" "16")])
14793
14794 (define_insn "*sync_andsi_internal"
14795   [(set (match_operand:SI 2 "gpc_reg_operand" "=&r,&r,&r,&r")
14796         (and:SI (match_operand:SI 0 "memory_operand" "+Z,Z,Z,Z")
14797                 (match_operand:SI 1 "and_operand" "r,T,K,L")))
14798    (set (match_operand:SI 3 "gpc_reg_operand" "=&b,&b,&b,&b") (match_dup 0))
14799    (set (match_dup 0) 
14800         (unspec:SI [(and:SI (match_dup 0) (match_dup 1))]
14801                    UNSPEC_SYNC_OP))
14802    (clobber (match_scratch:CC 4 "=&x,&x,&x,&x"))]
14803   "TARGET_POWERPC"
14804   "@
14805    lwarx %3,%y0\n\tand %2,%3,%1\n\tstwcx. %2,%y0\n\tbne- $-12
14806    lwarx %3,%y0\n\trlwinm %2,%3,0,%m1,%M1\n\tstwcx. %2,%y0\n\tbne- $-12
14807    lwarx %3,%y0\n\tandi. %2,%3,%b1\n\tstwcx. %2,%y0\n\tbne- $-12
14808    lwarx %3,%y0\n\tandis. %2,%3,%u1\n\tstwcx. %2,%y0\n\tbne- $-12"
14809   [(set_attr "length" "16,16,16,16")])
14810
14811 (define_insn "*sync_anddi_internal"
14812   [(set (match_operand:DI 2 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
14813         (and:DI (match_operand:DI 0 "memory_operand" "+Z,Z,Z,Z,Z")
14814                 (match_operand:DI 1 "and_operand" "r,S,T,K,J")))
14815    (set (match_operand:DI 3 "gpc_reg_operand" "=&b,&b,&b,&b,&b") (match_dup 0))
14816    (set (match_dup 0) 
14817         (unspec:DI [(and:DI (match_dup 0) (match_dup 1))]
14818                    UNSPEC_SYNC_OP))
14819    (clobber (match_scratch:CC 4 "=&x,&x,&x,&x,&x"))]
14820   "TARGET_POWERPC64"
14821   "@
14822    ldarx %3,%y0\n\tand %2,%3,%1\n\tstdcx. %2,%y0\n\tbne- $-12
14823    ldarx %3,%y0\n\trldic%B1 %2,%3,0,%S1\n\tstdcx. %2,%y0\n\tbne- $-12
14824    ldarx %3,%y0\n\trlwinm %2,%3,0,%m1,%M1\n\tstdcx. %2,%y0\n\tbne- $-12
14825    ldarx %3,%y0\n\tandi. %2,%3,%b1\n\tstdcx. %2,%y0\n\tbne- $-12
14826    ldarx %3,%y0\n\tandis. %2,%3,%b1\n\tstdcx. %2,%y0\n\tbne- $-12"
14827   [(set_attr "length" "16,16,16,16,16")])
14828
14829 (define_insn "*sync_boolsi_internal"
14830   [(set (match_operand:SI 2 "gpc_reg_operand" "=&r,&r,&r")
14831         (match_operator:SI 4 "boolean_or_operator"
14832          [(match_operand:SI 0 "memory_operand" "+Z,Z,Z")
14833           (match_operand:SI 1 "logical_operand" "r,K,L")]))
14834    (set (match_operand:SI 3 "gpc_reg_operand" "=&b,&b,&b") (match_dup 0))
14835    (set (match_dup 0) (unspec:SI [(match_dup 4)] UNSPEC_SYNC_OP))
14836    (clobber (match_scratch:CC 5 "=&x,&x,&x"))]
14837   "TARGET_POWERPC"
14838   "@
14839    lwarx %3,%y0\n\t%q4 %2,%3,%1\n\tstwcx. %2,%y0\n\tbne- $-12
14840    lwarx %3,%y0\n\t%q4i %2,%3,%b1\n\tstwcx. %2,%y0\n\tbne- $-12
14841    lwarx %3,%y0\n\t%q4is %2,%3,%u1\n\tstwcx. %2,%y0\n\tbne- $-12"
14842   [(set_attr "length" "16,16,16")])
14843
14844 (define_insn "*sync_booldi_internal"
14845   [(set (match_operand:DI 2 "gpc_reg_operand" "=&r,&r,&r")
14846         (match_operator:DI 4 "boolean_or_operator"
14847          [(match_operand:DI 0 "memory_operand" "+Z,Z,Z")
14848           (match_operand:DI 1 "logical_operand" "r,K,JF")]))
14849    (set (match_operand:DI 3 "gpc_reg_operand" "=&b,&b,&b") (match_dup 0))
14850    (set (match_dup 0) (unspec:DI [(match_dup 4)] UNSPEC_SYNC_OP))
14851    (clobber (match_scratch:CC 5 "=&x,&x,&x"))]
14852   "TARGET_POWERPC64"
14853   "@
14854    ldarx %3,%y0\n\t%q4 %2,%3,%1\n\tstdcx. %2,%y0\n\tbne- $-12
14855    ldarx %3,%y0\n\t%q4i %2,%3,%b1\n\tstdcx. %2,%y0\n\tbne- $-12
14856    ldarx %3,%y0\n\t%q4is %2,%3,%u1\n\tstdcx. %2,%y0\n\tbne- $-12"
14857   [(set_attr "length" "16,16,16")])
14858
14859 (define_insn "*sync_boolc<mode>_internal"
14860   [(set (match_operand:GPR 2 "gpc_reg_operand" "=&r")
14861         (match_operator:GPR 4 "boolean_operator"
14862          [(not:GPR (match_operand:GPR 0 "memory_operand" "+Z"))
14863           (match_operand:GPR 1 "gpc_reg_operand" "r")]))
14864    (set (match_operand:GPR 3 "gpc_reg_operand" "=&b") (match_dup 0))
14865    (set (match_dup 0) (unspec:GPR [(match_dup 4)] UNSPEC_SYNC_OP))
14866    (clobber (match_scratch:CC 5 "=&x"))]
14867   "TARGET_POWERPC"
14868   "<larx> %3,%y0\n\t%q4 %2,%1,%3\n\t<stcx> %2,%y0\n\tbne- $-12"
14869   [(set_attr "length" "16")])
14870
14871 ; This pattern could also take immediate values of operand 1,
14872 ; since the non-NOT version of the operator is used; but this is not
14873 ; very useful, since in practise operand 1 is a full 32-bit value.
14874 ; Likewise, operand 5 is in practise either <= 2^16 or it is a register.
14875 (define_insn "*sync_boolcshort_internal"
14876   [(set (match_operand:SI 2 "gpc_reg_operand" "=&r")
14877         (match_operator:SI 4 "boolean_operator"
14878          [(xor:SI (match_operand:SI 0 "memory_operand" "+Z")
14879                   (match_operand:SI 5 "logical_operand" "rK"))
14880           (match_operand:SI 1 "gpc_reg_operand" "r")]))
14881    (set (match_operand:SI 3 "gpc_reg_operand" "=&b") (match_dup 0))
14882    (set (match_dup 0) (unspec:SI [(match_dup 4)] UNSPEC_SYNC_OP))
14883    (clobber (match_scratch:CC 6 "=&x"))]
14884   "TARGET_POWERPC"
14885   "lwarx %3,%y0\n\txor%I2 %2,%3,%5\n\t%q4 %2,%2,%1\n\tstwcx. %2,%y0\n\tbne- $-16"
14886   [(set_attr "length" "20")])
14887
14888 (define_insn "*sync_boolc<mode>_internal2"
14889   [(set (match_operand:GPR 2 "gpc_reg_operand" "=&r")
14890         (match_operator:GPR 4 "boolean_operator"
14891          [(not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r"))
14892           (match_operand:GPR 0 "memory_operand" "+Z")]))
14893    (set (match_operand:GPR 3 "gpc_reg_operand" "=&b") (match_dup 0))
14894    (set (match_dup 0) (unspec:GPR [(match_dup 4)] UNSPEC_SYNC_OP))
14895    (clobber (match_scratch:CC 5 "=&x"))]
14896   "TARGET_POWERPC"
14897   "<larx> %3,%y0\n\t%q4 %2,%3,%1\n\t<stcx> %2,%y0\n\tbne- $-12"
14898   [(set_attr "length" "16")])
14899
14900 (define_insn "*sync_boolcc<mode>_internal"
14901   [(set (match_operand:GPR 2 "gpc_reg_operand" "=&r")
14902         (match_operator:GPR 4 "boolean_operator"
14903          [(not:GPR (match_operand:GPR 0 "memory_operand" "+Z"))
14904           (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r"))]))
14905    (set (match_operand:GPR 3 "gpc_reg_operand" "=&b") (match_dup 0))
14906    (set (match_dup 0) (unspec:GPR [(match_dup 4)] UNSPEC_SYNC_OP))
14907    (clobber (match_scratch:CC 5 "=&x"))]
14908   "TARGET_POWERPC"
14909   "<larx> %3,%y0\n\t%q4 %2,%1,%3\n\t<stcx> %2,%y0\n\tbne- $-12"
14910   [(set_attr "length" "16")])
14911
14912 (define_insn "isync"
14913   [(set (mem:BLK (match_scratch 0 "X"))
14914         (unspec:BLK [(mem:BLK (match_scratch 1 "X"))] UNSPEC_ISYNC))]
14915   "TARGET_POWERPC"
14916   "isync")
14917
14918 (define_insn "sync_lock_test_and_set<mode>"
14919   [(set (match_operand:GPR 0 "gpc_reg_operand" "=&r")
14920         (match_operand:GPR 1 "memory_operand" "+Z"))
14921    (set (match_dup 1) (unspec:GPR [(match_operand:GPR 2 "gpc_reg_operand" "r")] 
14922                                  UNSPEC_SYNC_OP))
14923    (clobber (match_scratch:CC 3 "=&x"))
14924    (set (mem:BLK (match_scratch 4 "X"))
14925         (unspec:BLK [(mem:BLK (match_scratch 5 "X"))] UNSPEC_ISYNC))]
14926   "TARGET_POWERPC"
14927   "<larx> %0,%y1\n\t<stcx> %2,%y1\n\tbne- $-8\n\tisync"
14928   [(set_attr "length" "16")])
14929
14930 (define_expand "sync_lock_release<mode>"
14931   [(set (match_operand:INT 0 "memory_operand")
14932         (match_operand:INT 1 "any_operand"))]
14933   ""
14934   "
14935 {
14936   emit_insn (gen_lwsync ());
14937   emit_move_insn (operands[0], operands[1]);
14938   DONE;
14939 }")
14940
14941 ; Some AIX assemblers don't accept lwsync, so we use a .long.
14942 (define_insn "lwsync"
14943   [(set (mem:BLK (match_scratch 0 "X"))
14944         (unspec:BLK [(mem:BLK (match_scratch 1 "X"))] UNSPEC_LWSYNC))]
14945   ""
14946   ".long 0x7c2004ac")
14947
14948 \f
14949
14950 (include "altivec.md")
14951 (include "spe.md")