]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/gcc/config/rs6000/rs6000.md
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / 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, 2006
4 ;; Free Software Foundation, Inc.
5 ;; Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
6
7 ;; This file is part of GCC.
8
9 ;; GCC is free software; you can redistribute it and/or modify it
10 ;; under the terms of the GNU General Public License as published
11 ;; by the Free Software Foundation; either version 2, or (at your
12 ;; option) any later version.
13
14 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
15 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
17 ;; License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GCC; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
22 ;; MA 02110-1301, USA.
23
24 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
25
26 ;;
27 ;; UNSPEC usage
28 ;;
29
30 (define_constants
31   [(UNSPEC_FRSP                 0)      ; frsp for POWER machines
32    (UNSPEC_TIE                  5)      ; tie stack contents and stack pointer
33    (UNSPEC_TOCPTR               6)      ; address of a word pointing to the TOC
34    (UNSPEC_TOC                  7)      ; address of the TOC (more-or-less)
35    (UNSPEC_MOVSI_GOT            8)
36    (UNSPEC_MV_CR_OV             9)      ; move_from_CR_ov_bit
37    (UNSPEC_FCTIWZ               10)
38    (UNSPEC_FRIM                 11)
39    (UNSPEC_FRIN                 12)
40    (UNSPEC_FRIP                 13)
41    (UNSPEC_FRIZ                 14)
42    (UNSPEC_LD_MPIC              15)     ; load_macho_picbase
43    (UNSPEC_MPIC_CORRECT         16)     ; macho_correct_pic
44    (UNSPEC_TLSGD                17)
45    (UNSPEC_TLSLD                18)
46    (UNSPEC_MOVESI_FROM_CR       19)
47    (UNSPEC_MOVESI_TO_CR         20)
48    (UNSPEC_TLSDTPREL            21)
49    (UNSPEC_TLSDTPRELHA          22)
50    (UNSPEC_TLSDTPRELLO          23)
51    (UNSPEC_TLSGOTDTPREL         24)
52    (UNSPEC_TLSTPREL             25)
53    (UNSPEC_TLSTPRELHA           26)
54    (UNSPEC_TLSTPRELLO           27)
55    (UNSPEC_TLSGOTTPREL          28)
56    (UNSPEC_TLSTLS               29)
57    (UNSPEC_FIX_TRUNC_TF         30)     ; fadd, rounding towards zero
58    (UNSPEC_MV_CR_GT             31)     ; move_from_CR_gt_bit
59    (UNSPEC_STFIWX               32)
60    (UNSPEC_POPCNTB              33)
61    (UNSPEC_FRES                 34)
62    (UNSPEC_SP_SET               35)
63    (UNSPEC_SP_TEST              36)
64    (UNSPEC_SYNC                 37)
65    (UNSPEC_LWSYNC               38)
66    (UNSPEC_ISYNC                39)
67    (UNSPEC_SYNC_OP              40)
68    (UNSPEC_ATOMIC               41)
69    (UNSPEC_CMPXCHG              42)
70    (UNSPEC_XCHG                 43)
71    (UNSPEC_AND                  44)
72    (UNSPEC_DLMZB                45)
73    (UNSPEC_DLMZB_CR             46)
74    (UNSPEC_DLMZB_STRLEN         47)
75   ])
76
77 ;;
78 ;; UNSPEC_VOLATILE usage
79 ;;
80
81 (define_constants
82   [(UNSPECV_BLOCK               0)
83    (UNSPECV_LL                  1)      ; load-locked
84    (UNSPECV_SC                  2)      ; store-conditional
85    (UNSPECV_EH_RR               9)      ; eh_reg_restore
86   ])
87 \f
88 ;; Define an insn type attribute.  This is used in function unit delay
89 ;; computations.
90 (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,isync,sync,load_l,store_c"
91   (const_string "integer"))
92
93 ;; Length (in bytes).
94 ; '(pc)' in the following doesn't include the instruction itself; it is
95 ; calculated as if the instruction had zero size.
96 (define_attr "length" ""
97   (if_then_else (eq_attr "type" "branch")
98                 (if_then_else (and (ge (minus (match_dup 0) (pc))
99                                        (const_int -32768))
100                                    (lt (minus (match_dup 0) (pc))
101                                        (const_int 32764)))
102                               (const_int 4)
103                               (const_int 8))
104                 (const_int 4)))
105
106 ;; Processor type -- this attribute must exactly match the processor_type
107 ;; enumeration in rs6000.h.
108
109 (define_attr "cpu" "rios1,rios2,rs64a,mpccore,ppc403,ppc405,ppc440,ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630,ppc750,ppc7400,ppc7450,ppc8540,power4,power5"
110   (const (symbol_ref "rs6000_cpu_attr")))
111
112 (automata_option "ndfa")
113
114 (include "rios1.md")
115 (include "rios2.md")
116 (include "rs64.md")
117 (include "mpc.md")
118 (include "40x.md")
119 (include "440.md")
120 (include "603.md")
121 (include "6xx.md")
122 (include "7xx.md")
123 (include "7450.md")
124 (include "8540.md")
125 (include "power4.md")
126 (include "power5.md")
127
128 (include "predicates.md")
129 (include "constraints.md")
130
131 (include "darwin.md")
132
133 \f
134 ;; Mode macros
135
136 ; This mode macro allows :GPR to be used to indicate the allowable size
137 ; of whole values in GPRs.
138 (define_mode_macro GPR [SI (DI "TARGET_POWERPC64")])
139
140 ; Any supported integer mode.
141 (define_mode_macro INT [QI HI SI DI TI])
142
143 ; Any supported integer mode that fits in one register.
144 (define_mode_macro INT1 [QI HI SI (DI "TARGET_POWERPC64")])
145
146 ; extend modes for DImode
147 (define_mode_macro QHSI [QI HI SI])
148
149 ; SImode or DImode, even if DImode doesn't fit in GPRs.
150 (define_mode_macro SDI [SI DI])
151
152 ; The size of a pointer.  Also, the size of the value that a record-condition
153 ; (one with a '.') will compare.
154 (define_mode_macro P [(SI "TARGET_32BIT") (DI "TARGET_64BIT")])
155
156 ; Any hardware-supported floating-point mode
157 (define_mode_macro FP [(SF "TARGET_HARD_FLOAT")
158   (DF "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)")
159   (TF "!TARGET_IEEEQUAD
160    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128")])
161
162 ; Various instructions that come in SI and DI forms.
163 ; A generic w/d attribute, for things like cmpw/cmpd.
164 (define_mode_attr wd [(QI "b") (HI "h") (SI "w") (DI "d")])
165
166 ; DImode bits
167 (define_mode_attr dbits [(QI "56") (HI "48") (SI "32")])
168
169 \f
170 ;; Start with fixed-point load and store insns.  Here we put only the more
171 ;; complex forms.  Basic data transfer is done later.
172
173 (define_expand "zero_extend<mode>di2"
174   [(set (match_operand:DI 0 "gpc_reg_operand" "")
175         (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "")))]
176   "TARGET_POWERPC64"
177   "")
178
179 (define_insn "*zero_extend<mode>di2_internal1"
180   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
181         (zero_extend:DI (match_operand:QHSI 1 "reg_or_mem_operand" "m,r")))]
182   "TARGET_POWERPC64"
183   "@
184    l<wd>z%U1%X1 %0,%1
185    rldicl %0,%1,0,<dbits>"
186   [(set_attr "type" "load,*")])
187
188 (define_insn "*zero_extend<mode>di2_internal2"
189   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
190         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
191                     (const_int 0)))
192    (clobber (match_scratch:DI 2 "=r,r"))]
193   "TARGET_64BIT"
194   "@
195    rldicl. %2,%1,0,<dbits>
196    #"
197   [(set_attr "type" "compare")
198    (set_attr "length" "4,8")])
199
200 (define_split
201   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
202         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
203                     (const_int 0)))
204    (clobber (match_scratch:DI 2 ""))]
205   "TARGET_POWERPC64 && reload_completed"
206   [(set (match_dup 2)
207         (zero_extend:DI (match_dup 1)))
208    (set (match_dup 0)
209         (compare:CC (match_dup 2)
210                     (const_int 0)))]
211   "")
212
213 (define_insn "*zero_extend<mode>di2_internal3"
214   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
215         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
216                     (const_int 0)))
217    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
218         (zero_extend:DI (match_dup 1)))]
219   "TARGET_64BIT"
220   "@
221    rldicl. %0,%1,0,<dbits>
222    #"
223   [(set_attr "type" "compare")
224    (set_attr "length" "4,8")])
225
226 (define_split
227   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
228         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
229                     (const_int 0)))
230    (set (match_operand:DI 0 "gpc_reg_operand" "")
231         (zero_extend:DI (match_dup 1)))]
232   "TARGET_POWERPC64 && reload_completed"
233   [(set (match_dup 0)
234         (zero_extend:DI (match_dup 1)))
235    (set (match_dup 2)
236         (compare:CC (match_dup 0)
237                     (const_int 0)))]
238   "")
239
240 (define_insn "extendqidi2"
241   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
242         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
243   "TARGET_POWERPC64"
244   "extsb %0,%1")
245
246 (define_insn ""
247   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
248         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
249                     (const_int 0)))
250    (clobber (match_scratch:DI 2 "=r,r"))]
251   "TARGET_64BIT"
252   "@
253    extsb. %2,%1
254    #"
255   [(set_attr "type" "compare")
256    (set_attr "length" "4,8")])
257
258 (define_split
259   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
260         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
261                     (const_int 0)))
262    (clobber (match_scratch:DI 2 ""))]
263   "TARGET_POWERPC64 && reload_completed"
264   [(set (match_dup 2)
265         (sign_extend:DI (match_dup 1)))
266    (set (match_dup 0)
267         (compare:CC (match_dup 2)
268                     (const_int 0)))]
269   "")
270
271 (define_insn ""
272   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
273         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
274                     (const_int 0)))
275    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
276         (sign_extend:DI (match_dup 1)))]
277   "TARGET_64BIT"
278   "@
279    extsb. %0,%1
280    #"
281   [(set_attr "type" "compare")
282    (set_attr "length" "4,8")])
283
284 (define_split
285   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
286         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
287                     (const_int 0)))
288    (set (match_operand:DI 0 "gpc_reg_operand" "")
289         (sign_extend:DI (match_dup 1)))]
290   "TARGET_POWERPC64 && reload_completed"
291   [(set (match_dup 0)
292         (sign_extend:DI (match_dup 1)))
293    (set (match_dup 2)
294         (compare:CC (match_dup 0)
295                     (const_int 0)))]
296   "")
297
298 (define_expand "extendhidi2"
299   [(set (match_operand:DI 0 "gpc_reg_operand" "")
300         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
301   "TARGET_POWERPC64"
302   "")
303
304 (define_insn ""
305   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
306         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
307   "TARGET_POWERPC64"
308   "@
309    lha%U1%X1 %0,%1
310    extsh %0,%1"
311   [(set_attr "type" "load_ext,*")])
312
313 (define_insn ""
314   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
315         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
316                     (const_int 0)))
317    (clobber (match_scratch:DI 2 "=r,r"))]
318   "TARGET_64BIT"
319   "@
320    extsh. %2,%1
321    #"
322   [(set_attr "type" "compare")
323    (set_attr "length" "4,8")])
324
325 (define_split
326   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
327         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
328                     (const_int 0)))
329    (clobber (match_scratch:DI 2 ""))]
330   "TARGET_POWERPC64 && reload_completed"
331   [(set (match_dup 2)
332         (sign_extend:DI (match_dup 1)))
333    (set (match_dup 0)
334         (compare:CC (match_dup 2)
335                     (const_int 0)))]
336   "")
337
338 (define_insn ""
339   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
340         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
341                     (const_int 0)))
342    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
343         (sign_extend:DI (match_dup 1)))]
344   "TARGET_64BIT"
345   "@
346    extsh. %0,%1
347    #"
348   [(set_attr "type" "compare")
349    (set_attr "length" "4,8")])
350
351 (define_split
352   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
353         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
354                     (const_int 0)))
355    (set (match_operand:DI 0 "gpc_reg_operand" "")
356         (sign_extend:DI (match_dup 1)))]
357   "TARGET_POWERPC64 && reload_completed"
358   [(set (match_dup 0)
359         (sign_extend:DI (match_dup 1)))
360    (set (match_dup 2)
361         (compare:CC (match_dup 0)
362                     (const_int 0)))]
363   "")
364
365 (define_expand "extendsidi2"
366   [(set (match_operand:DI 0 "gpc_reg_operand" "")
367         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
368   "TARGET_POWERPC64"
369   "")
370
371 (define_insn ""
372   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
373         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
374   "TARGET_POWERPC64"
375   "@
376    lwa%U1%X1 %0,%1
377    extsw %0,%1"
378   [(set_attr "type" "load_ext,*")])
379
380 (define_insn ""
381   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
382         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
383                     (const_int 0)))
384    (clobber (match_scratch:DI 2 "=r,r"))]
385   "TARGET_64BIT"
386   "@
387    extsw. %2,%1
388    #"
389   [(set_attr "type" "compare")
390    (set_attr "length" "4,8")])
391
392 (define_split
393   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
394         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
395                     (const_int 0)))
396    (clobber (match_scratch:DI 2 ""))]
397   "TARGET_POWERPC64 && reload_completed"
398   [(set (match_dup 2)
399         (sign_extend:DI (match_dup 1)))
400    (set (match_dup 0)
401         (compare:CC (match_dup 2)
402                     (const_int 0)))]
403   "")
404
405 (define_insn ""
406   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
407         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
408                     (const_int 0)))
409    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
410         (sign_extend:DI (match_dup 1)))]
411   "TARGET_64BIT"
412   "@
413    extsw. %0,%1
414    #"
415   [(set_attr "type" "compare")
416    (set_attr "length" "4,8")])
417
418 (define_split
419   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
420         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
421                     (const_int 0)))
422    (set (match_operand:DI 0 "gpc_reg_operand" "")
423         (sign_extend:DI (match_dup 1)))]
424   "TARGET_POWERPC64 && reload_completed"
425   [(set (match_dup 0)
426         (sign_extend:DI (match_dup 1)))
427    (set (match_dup 2)
428         (compare:CC (match_dup 0)
429                     (const_int 0)))]
430   "")
431
432 (define_expand "zero_extendqisi2"
433   [(set (match_operand:SI 0 "gpc_reg_operand" "")
434         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
435   ""
436   "")
437
438 (define_insn ""
439   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
440         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
441   ""
442   "@
443    lbz%U1%X1 %0,%1
444    {rlinm|rlwinm} %0,%1,0,0xff"
445   [(set_attr "type" "load,*")])
446
447 (define_insn ""
448   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
449         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
450                     (const_int 0)))
451    (clobber (match_scratch:SI 2 "=r,r"))]
452   ""
453   "@
454    {andil.|andi.} %2,%1,0xff
455    #"
456   [(set_attr "type" "compare")
457    (set_attr "length" "4,8")])
458
459 (define_split
460   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
461         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
462                     (const_int 0)))
463    (clobber (match_scratch:SI 2 ""))]
464   "reload_completed"
465   [(set (match_dup 2)
466         (zero_extend:SI (match_dup 1)))
467    (set (match_dup 0)
468         (compare:CC (match_dup 2)
469                     (const_int 0)))]
470   "")
471
472 (define_insn ""
473   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
474         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
475                     (const_int 0)))
476    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
477         (zero_extend:SI (match_dup 1)))]
478   ""
479   "@
480    {andil.|andi.} %0,%1,0xff
481    #"
482   [(set_attr "type" "compare")
483    (set_attr "length" "4,8")])
484
485 (define_split
486   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
487         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
488                     (const_int 0)))
489    (set (match_operand:SI 0 "gpc_reg_operand" "")
490         (zero_extend:SI (match_dup 1)))]
491   "reload_completed"
492   [(set (match_dup 0)
493         (zero_extend:SI (match_dup 1)))
494    (set (match_dup 2)
495         (compare:CC (match_dup 0)
496                     (const_int 0)))]
497   "")
498
499 (define_expand "extendqisi2"
500   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
501    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
502   ""
503   "
504 {
505   if (TARGET_POWERPC)
506     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
507   else if (TARGET_POWER)
508     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
509   else
510     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
511   DONE;
512 }")
513
514 (define_insn "extendqisi2_ppc"
515   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
516         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
517   "TARGET_POWERPC"
518   "extsb %0,%1")
519
520 (define_insn ""
521   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
522         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
523                     (const_int 0)))
524    (clobber (match_scratch:SI 2 "=r,r"))]
525   "TARGET_POWERPC"
526   "@
527    extsb. %2,%1
528    #"
529   [(set_attr "type" "compare")
530    (set_attr "length" "4,8")])
531
532 (define_split
533   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
534         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
535                     (const_int 0)))
536    (clobber (match_scratch:SI 2 ""))]
537   "TARGET_POWERPC && reload_completed"
538   [(set (match_dup 2)
539         (sign_extend:SI (match_dup 1)))
540    (set (match_dup 0)
541         (compare:CC (match_dup 2)
542                     (const_int 0)))]
543   "")
544
545 (define_insn ""
546   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
547         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
548                     (const_int 0)))
549    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
550         (sign_extend:SI (match_dup 1)))]
551   "TARGET_POWERPC"
552   "@
553    extsb. %0,%1
554    #"
555   [(set_attr "type" "compare")
556    (set_attr "length" "4,8")])
557
558 (define_split
559   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
560         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
561                     (const_int 0)))
562    (set (match_operand:SI 0 "gpc_reg_operand" "")
563         (sign_extend:SI (match_dup 1)))]
564   "TARGET_POWERPC && reload_completed"
565   [(set (match_dup 0)
566         (sign_extend:SI (match_dup 1)))
567    (set (match_dup 2)
568         (compare:CC (match_dup 0)
569                     (const_int 0)))]
570   "")
571
572 (define_expand "extendqisi2_power"
573   [(parallel [(set (match_dup 2)
574                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
575                               (const_int 24)))
576               (clobber (scratch:SI))])
577    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
578                    (ashiftrt:SI (match_dup 2)
579                                 (const_int 24)))
580               (clobber (scratch:SI))])]
581   "TARGET_POWER"
582   "
583 { operands[1] = gen_lowpart (SImode, operands[1]);
584   operands[2] = gen_reg_rtx (SImode); }")
585
586 (define_expand "extendqisi2_no_power"
587   [(set (match_dup 2)
588         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
589                    (const_int 24)))
590    (set (match_operand:SI 0 "gpc_reg_operand" "")
591         (ashiftrt:SI (match_dup 2)
592                      (const_int 24)))]
593   "! TARGET_POWER && ! TARGET_POWERPC"
594   "
595 { operands[1] = gen_lowpart (SImode, operands[1]);
596   operands[2] = gen_reg_rtx (SImode); }")
597
598 (define_expand "zero_extendqihi2"
599   [(set (match_operand:HI 0 "gpc_reg_operand" "")
600         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
601   ""
602   "")
603
604 (define_insn ""
605   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
606         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
607   ""
608   "@
609    lbz%U1%X1 %0,%1
610    {rlinm|rlwinm} %0,%1,0,0xff"
611   [(set_attr "type" "load,*")])
612
613 (define_insn ""
614   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
615         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
616                     (const_int 0)))
617    (clobber (match_scratch:HI 2 "=r,r"))]
618   ""
619   "@
620    {andil.|andi.} %2,%1,0xff
621    #"
622   [(set_attr "type" "compare")
623    (set_attr "length" "4,8")])
624
625 (define_split
626   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
627         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
628                     (const_int 0)))
629    (clobber (match_scratch:HI 2 ""))]
630   "reload_completed"
631   [(set (match_dup 2)
632         (zero_extend:HI (match_dup 1)))
633    (set (match_dup 0)
634         (compare:CC (match_dup 2)
635                     (const_int 0)))]
636   "")
637
638 (define_insn ""
639   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
640         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
641                     (const_int 0)))
642    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
643         (zero_extend:HI (match_dup 1)))]
644   ""
645   "@
646    {andil.|andi.} %0,%1,0xff
647    #"
648   [(set_attr "type" "compare")
649    (set_attr "length" "4,8")])
650
651 (define_split
652   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
653         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
654                     (const_int 0)))
655    (set (match_operand:HI 0 "gpc_reg_operand" "")
656         (zero_extend:HI (match_dup 1)))]
657   "reload_completed"
658   [(set (match_dup 0)
659         (zero_extend:HI (match_dup 1)))
660    (set (match_dup 2)
661         (compare:CC (match_dup 0)
662                     (const_int 0)))]
663   "")
664
665 (define_expand "extendqihi2"
666   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
667    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
668   ""
669   "
670 {
671   if (TARGET_POWERPC)
672     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
673   else if (TARGET_POWER)
674     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
675   else
676     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
677   DONE;
678 }")
679
680 (define_insn "extendqihi2_ppc"
681   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
682         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
683   "TARGET_POWERPC"
684   "extsb %0,%1")
685
686 (define_insn ""
687   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
688         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
689                     (const_int 0)))
690    (clobber (match_scratch:HI 2 "=r,r"))]
691   "TARGET_POWERPC"
692   "@
693    extsb. %2,%1
694    #"
695   [(set_attr "type" "compare")
696    (set_attr "length" "4,8")])
697
698 (define_split
699   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
700         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
701                     (const_int 0)))
702    (clobber (match_scratch:HI 2 ""))]
703   "TARGET_POWERPC && reload_completed"
704   [(set (match_dup 2)
705         (sign_extend:HI (match_dup 1)))
706    (set (match_dup 0)
707         (compare:CC (match_dup 2)
708                     (const_int 0)))]
709   "")
710
711 (define_insn ""
712   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
713         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
714                     (const_int 0)))
715    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
716         (sign_extend:HI (match_dup 1)))]
717   "TARGET_POWERPC"
718   "@
719    extsb. %0,%1
720    #"
721   [(set_attr "type" "compare")
722    (set_attr "length" "4,8")])
723
724 (define_split
725   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
726         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
727                     (const_int 0)))
728    (set (match_operand:HI 0 "gpc_reg_operand" "")
729         (sign_extend:HI (match_dup 1)))]
730   "TARGET_POWERPC && reload_completed"
731   [(set (match_dup 0)
732         (sign_extend:HI (match_dup 1)))
733    (set (match_dup 2)
734         (compare:CC (match_dup 0)
735                     (const_int 0)))]
736   "")
737
738 (define_expand "extendqihi2_power"
739   [(parallel [(set (match_dup 2)
740                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
741                               (const_int 24)))
742               (clobber (scratch:SI))])
743    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
744                    (ashiftrt:SI (match_dup 2)
745                                 (const_int 24)))
746               (clobber (scratch:SI))])]
747   "TARGET_POWER"
748   "
749 { operands[0] = gen_lowpart (SImode, operands[0]);
750   operands[1] = gen_lowpart (SImode, operands[1]);
751   operands[2] = gen_reg_rtx (SImode); }")
752
753 (define_expand "extendqihi2_no_power"
754   [(set (match_dup 2)
755         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
756                    (const_int 24)))
757    (set (match_operand:HI 0 "gpc_reg_operand" "")
758         (ashiftrt:SI (match_dup 2)
759                      (const_int 24)))]
760   "! TARGET_POWER && ! TARGET_POWERPC"
761   "
762 { operands[0] = gen_lowpart (SImode, operands[0]);
763   operands[1] = gen_lowpart (SImode, operands[1]);
764   operands[2] = gen_reg_rtx (SImode); }")
765
766 (define_expand "zero_extendhisi2"
767   [(set (match_operand:SI 0 "gpc_reg_operand" "")
768         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
769   ""
770   "")
771
772 (define_insn ""
773   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
774         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
775   ""
776   "@
777    lhz%U1%X1 %0,%1
778    {rlinm|rlwinm} %0,%1,0,0xffff"
779   [(set_attr "type" "load,*")])
780
781 (define_insn ""
782   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
783         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
784                     (const_int 0)))
785    (clobber (match_scratch:SI 2 "=r,r"))]
786   ""
787   "@
788    {andil.|andi.} %2,%1,0xffff
789    #"
790   [(set_attr "type" "compare")
791    (set_attr "length" "4,8")])
792
793 (define_split
794   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
795         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
796                     (const_int 0)))
797    (clobber (match_scratch:SI 2 ""))]
798   "reload_completed"
799   [(set (match_dup 2)
800         (zero_extend:SI (match_dup 1)))
801    (set (match_dup 0)
802         (compare:CC (match_dup 2)
803                     (const_int 0)))]
804   "")
805
806 (define_insn ""
807   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
808         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
809                     (const_int 0)))
810    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
811         (zero_extend:SI (match_dup 1)))]
812   ""
813   "@
814    {andil.|andi.} %0,%1,0xffff
815    #"
816   [(set_attr "type" "compare")
817    (set_attr "length" "4,8")])
818
819 (define_split
820   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
821         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
822                     (const_int 0)))
823    (set (match_operand:SI 0 "gpc_reg_operand" "")
824         (zero_extend:SI (match_dup 1)))]
825   "reload_completed"
826   [(set (match_dup 0)
827         (zero_extend:SI (match_dup 1)))
828    (set (match_dup 2)
829         (compare:CC (match_dup 0)
830                     (const_int 0)))]
831   "")
832
833 (define_expand "extendhisi2"
834   [(set (match_operand:SI 0 "gpc_reg_operand" "")
835         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
836   ""
837   "")
838
839 (define_insn ""
840   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
841         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
842   ""
843   "@
844    lha%U1%X1 %0,%1
845    {exts|extsh} %0,%1"
846   [(set_attr "type" "load_ext,*")])
847
848 (define_insn ""
849   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
850         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
851                     (const_int 0)))
852    (clobber (match_scratch:SI 2 "=r,r"))]
853   ""
854   "@
855    {exts.|extsh.} %2,%1
856    #"
857   [(set_attr "type" "compare")
858    (set_attr "length" "4,8")])
859
860 (define_split
861   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
862         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
863                     (const_int 0)))
864    (clobber (match_scratch:SI 2 ""))]
865   "reload_completed"
866   [(set (match_dup 2)
867         (sign_extend:SI (match_dup 1)))
868    (set (match_dup 0)
869         (compare:CC (match_dup 2)
870                     (const_int 0)))]
871   "")
872
873 (define_insn ""
874   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
875         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
876                     (const_int 0)))
877    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
878         (sign_extend:SI (match_dup 1)))]
879   ""
880   "@
881    {exts.|extsh.} %0,%1
882    #"
883   [(set_attr "type" "compare")
884    (set_attr "length" "4,8")])
885 \f
886 ;; IBM 405 and 440 half-word multiplication operations.
887
888 (define_insn "*macchwc"
889   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
890         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
891                                        (match_operand:SI 2 "gpc_reg_operand" "r")
892                                        (const_int 16))
893                                       (sign_extend:SI
894                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
895                              (match_operand:SI 4 "gpc_reg_operand" "0"))
896                     (const_int 0)))
897    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
898         (plus:SI (mult:SI (ashiftrt:SI
899                            (match_dup 2)
900                            (const_int 16))
901                           (sign_extend:SI
902                            (match_dup 1)))
903                  (match_dup 4)))]
904   "TARGET_MULHW"
905   "macchw. %0, %1, %2"
906   [(set_attr "type" "imul3")])
907
908 (define_insn "*macchw"
909   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
910         (plus:SI (mult:SI (ashiftrt:SI
911                            (match_operand:SI 2 "gpc_reg_operand" "r")
912                            (const_int 16))
913                           (sign_extend:SI
914                            (match_operand:HI 1 "gpc_reg_operand" "r")))
915                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
916   "TARGET_MULHW"
917   "macchw %0, %1, %2"
918   [(set_attr "type" "imul3")])
919
920 (define_insn "*macchwuc"
921   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
922         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
923                                        (match_operand:SI 2 "gpc_reg_operand" "r")
924                                        (const_int 16))
925                                       (zero_extend:SI
926                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
927                              (match_operand:SI 4 "gpc_reg_operand" "0"))
928                     (const_int 0)))
929    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
930         (plus:SI (mult:SI (lshiftrt:SI
931                            (match_dup 2)
932                            (const_int 16))
933                           (zero_extend:SI
934                            (match_dup 1)))
935                  (match_dup 4)))]
936   "TARGET_MULHW"
937   "macchwu. %0, %1, %2"
938   [(set_attr "type" "imul3")])
939
940 (define_insn "*macchwu"
941   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
942         (plus:SI (mult:SI (lshiftrt:SI
943                            (match_operand:SI 2 "gpc_reg_operand" "r")
944                            (const_int 16))
945                           (zero_extend:SI
946                            (match_operand:HI 1 "gpc_reg_operand" "r")))
947                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
948   "TARGET_MULHW"
949   "macchwu %0, %1, %2"
950   [(set_attr "type" "imul3")])
951
952 (define_insn "*machhwc"
953   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
954         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
955                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
956                                        (const_int 16))
957                                       (ashiftrt:SI
958                                        (match_operand:SI 2 "gpc_reg_operand" "r")
959                                        (const_int 16)))
960                              (match_operand:SI 4 "gpc_reg_operand" "0"))
961                     (const_int 0)))
962    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
963         (plus:SI (mult:SI (ashiftrt:SI
964                            (match_dup 1)
965                            (const_int 16))
966                           (ashiftrt:SI
967                            (match_dup 2)
968                            (const_int 16)))
969                  (match_dup 4)))]
970   "TARGET_MULHW"
971   "machhw. %0, %1, %2"
972   [(set_attr "type" "imul3")])
973
974 (define_insn "*machhw"
975   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
976         (plus:SI (mult:SI (ashiftrt:SI
977                            (match_operand:SI 1 "gpc_reg_operand" "%r")
978                            (const_int 16))
979                           (ashiftrt:SI
980                            (match_operand:SI 2 "gpc_reg_operand" "r")
981                            (const_int 16)))
982                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
983   "TARGET_MULHW"
984   "machhw %0, %1, %2"
985   [(set_attr "type" "imul3")])
986
987 (define_insn "*machhwuc"
988   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
989         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
990                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
991                                        (const_int 16))
992                                       (lshiftrt:SI
993                                        (match_operand:SI 2 "gpc_reg_operand" "r")
994                                        (const_int 16)))
995                              (match_operand:SI 4 "gpc_reg_operand" "0"))
996                     (const_int 0)))
997    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
998         (plus:SI (mult:SI (lshiftrt:SI
999                            (match_dup 1)
1000                            (const_int 16))
1001                           (lshiftrt:SI
1002                            (match_dup 2)
1003                            (const_int 16)))
1004                  (match_dup 4)))]
1005   "TARGET_MULHW"
1006   "machhwu. %0, %1, %2"
1007   [(set_attr "type" "imul3")])
1008
1009 (define_insn "*machhwu"
1010   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1011         (plus:SI (mult:SI (lshiftrt:SI
1012                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1013                            (const_int 16))
1014                           (lshiftrt:SI
1015                            (match_operand:SI 2 "gpc_reg_operand" "r")
1016                            (const_int 16)))
1017                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1018   "TARGET_MULHW"
1019   "machhwu %0, %1, %2"
1020   [(set_attr "type" "imul3")])
1021
1022 (define_insn "*maclhwc"
1023   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1024         (compare:CC (plus:SI (mult:SI (sign_extend:SI
1025                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1026                                       (sign_extend:SI
1027                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1028                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1029                     (const_int 0)))
1030    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1031         (plus:SI (mult:SI (sign_extend:SI
1032                            (match_dup 1))
1033                           (sign_extend:SI
1034                            (match_dup 2)))
1035                  (match_dup 4)))]
1036   "TARGET_MULHW"
1037   "maclhw. %0, %1, %2"
1038   [(set_attr "type" "imul3")])
1039
1040 (define_insn "*maclhw"
1041   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1042         (plus:SI (mult:SI (sign_extend:SI
1043                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1044                           (sign_extend:SI
1045                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1046                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1047   "TARGET_MULHW"
1048   "maclhw %0, %1, %2"
1049   [(set_attr "type" "imul3")])
1050
1051 (define_insn "*maclhwuc"
1052   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1053         (compare:CC (plus:SI (mult:SI (zero_extend:SI
1054                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1055                                       (zero_extend:SI
1056                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1057                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1058                     (const_int 0)))
1059    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1060         (plus:SI (mult:SI (zero_extend:SI
1061                            (match_dup 1))
1062                           (zero_extend:SI
1063                            (match_dup 2)))
1064                  (match_dup 4)))]
1065   "TARGET_MULHW"
1066   "maclhwu. %0, %1, %2"
1067   [(set_attr "type" "imul3")])
1068
1069 (define_insn "*maclhwu"
1070   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1071         (plus:SI (mult:SI (zero_extend:SI
1072                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1073                           (zero_extend:SI
1074                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1075                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1076   "TARGET_MULHW"
1077   "maclhwu %0, %1, %2"
1078   [(set_attr "type" "imul3")])
1079
1080 (define_insn "*nmacchwc"
1081   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1082         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1083                               (mult:SI (ashiftrt:SI
1084                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1085                                         (const_int 16))
1086                                        (sign_extend:SI
1087                                         (match_operand:HI 1 "gpc_reg_operand" "r"))))
1088                     (const_int 0)))
1089    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1090         (minus:SI (match_dup 4)
1091                   (mult:SI (ashiftrt:SI
1092                             (match_dup 2)
1093                             (const_int 16))
1094                            (sign_extend:SI
1095                             (match_dup 1)))))]
1096   "TARGET_MULHW"
1097   "nmacchw. %0, %1, %2"
1098   [(set_attr "type" "imul3")])
1099
1100 (define_insn "*nmacchw"
1101   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1102         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1103                   (mult:SI (ashiftrt:SI
1104                             (match_operand:SI 2 "gpc_reg_operand" "r")
1105                             (const_int 16))
1106                            (sign_extend:SI
1107                             (match_operand:HI 1 "gpc_reg_operand" "r")))))]
1108   "TARGET_MULHW"
1109   "nmacchw %0, %1, %2"
1110   [(set_attr "type" "imul3")])
1111
1112 (define_insn "*nmachhwc"
1113   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1114         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1115                               (mult:SI (ashiftrt:SI
1116                                         (match_operand:SI 1 "gpc_reg_operand" "%r")
1117                                         (const_int 16))
1118                                        (ashiftrt:SI
1119                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1120                                         (const_int 16))))
1121                     (const_int 0)))
1122    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1123         (minus:SI (match_dup 4)
1124                   (mult:SI (ashiftrt:SI
1125                             (match_dup 1)
1126                             (const_int 16))
1127                            (ashiftrt:SI
1128                             (match_dup 2)
1129                             (const_int 16)))))]
1130   "TARGET_MULHW"
1131   "nmachhw. %0, %1, %2"
1132   [(set_attr "type" "imul3")])
1133
1134 (define_insn "*nmachhw"
1135   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1136         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1137                   (mult:SI (ashiftrt:SI
1138                             (match_operand:SI 1 "gpc_reg_operand" "%r")
1139                             (const_int 16))
1140                            (ashiftrt:SI
1141                             (match_operand:SI 2 "gpc_reg_operand" "r")
1142                             (const_int 16)))))]
1143   "TARGET_MULHW"
1144   "nmachhw %0, %1, %2"
1145   [(set_attr "type" "imul3")])
1146
1147 (define_insn "*nmaclhwc"
1148   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1149         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1150                               (mult:SI (sign_extend:SI
1151                                         (match_operand:HI 1 "gpc_reg_operand" "%r"))
1152                                        (sign_extend:SI
1153                                         (match_operand:HI 2 "gpc_reg_operand" "r"))))
1154                     (const_int 0)))
1155    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1156         (minus:SI (match_dup 4)
1157                   (mult:SI (sign_extend:SI
1158                             (match_dup 1))
1159                            (sign_extend:SI
1160                             (match_dup 2)))))]
1161   "TARGET_MULHW"
1162   "nmaclhw. %0, %1, %2"
1163   [(set_attr "type" "imul3")])
1164
1165 (define_insn "*nmaclhw"
1166   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1167         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1168                   (mult:SI (sign_extend:SI
1169                             (match_operand:HI 1 "gpc_reg_operand" "%r"))
1170                            (sign_extend:SI
1171                             (match_operand:HI 2 "gpc_reg_operand" "r")))))]
1172   "TARGET_MULHW"
1173   "nmaclhw %0, %1, %2"
1174   [(set_attr "type" "imul3")])
1175
1176 (define_insn "*mulchwc"
1177   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1178         (compare:CC (mult:SI (ashiftrt:SI
1179                               (match_operand:SI 2 "gpc_reg_operand" "r")
1180                               (const_int 16))
1181                              (sign_extend:SI
1182                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1183                     (const_int 0)))
1184    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1185         (mult:SI (ashiftrt:SI
1186                   (match_dup 2)
1187                   (const_int 16))
1188                  (sign_extend:SI
1189                   (match_dup 1))))]
1190   "TARGET_MULHW"
1191   "mulchw. %0, %1, %2"
1192   [(set_attr "type" "imul3")])
1193
1194 (define_insn "*mulchw"
1195   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1196         (mult:SI (ashiftrt:SI
1197                   (match_operand:SI 2 "gpc_reg_operand" "r")
1198                   (const_int 16))
1199                  (sign_extend:SI
1200                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1201   "TARGET_MULHW"
1202   "mulchw %0, %1, %2"
1203   [(set_attr "type" "imul3")])
1204
1205 (define_insn "*mulchwuc"
1206   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1207         (compare:CC (mult:SI (lshiftrt:SI
1208                               (match_operand:SI 2 "gpc_reg_operand" "r")
1209                               (const_int 16))
1210                              (zero_extend:SI
1211                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1212                     (const_int 0)))
1213    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1214         (mult:SI (lshiftrt:SI
1215                   (match_dup 2)
1216                   (const_int 16))
1217                  (zero_extend:SI
1218                   (match_dup 1))))]
1219   "TARGET_MULHW"
1220   "mulchwu. %0, %1, %2"
1221   [(set_attr "type" "imul3")])
1222
1223 (define_insn "*mulchwu"
1224   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1225         (mult:SI (lshiftrt:SI
1226                   (match_operand:SI 2 "gpc_reg_operand" "r")
1227                   (const_int 16))
1228                  (zero_extend:SI
1229                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1230   "TARGET_MULHW"
1231   "mulchwu %0, %1, %2"
1232   [(set_attr "type" "imul3")])
1233
1234 (define_insn "*mulhhwc"
1235   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1236         (compare:CC (mult:SI (ashiftrt:SI
1237                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1238                               (const_int 16))
1239                              (ashiftrt:SI
1240                               (match_operand:SI 2 "gpc_reg_operand" "r")
1241                               (const_int 16)))
1242                     (const_int 0)))
1243    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1244         (mult:SI (ashiftrt:SI
1245                   (match_dup 1)
1246                   (const_int 16))
1247                  (ashiftrt:SI
1248                   (match_dup 2)
1249                   (const_int 16))))]
1250   "TARGET_MULHW"
1251   "mulhhw. %0, %1, %2"
1252   [(set_attr "type" "imul3")])
1253
1254 (define_insn "*mulhhw"
1255   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1256         (mult:SI (ashiftrt:SI
1257                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1258                   (const_int 16))
1259                  (ashiftrt:SI
1260                   (match_operand:SI 2 "gpc_reg_operand" "r")
1261                   (const_int 16))))]
1262   "TARGET_MULHW"
1263   "mulhhw %0, %1, %2"
1264   [(set_attr "type" "imul3")])
1265
1266 (define_insn "*mulhhwuc"
1267   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1268         (compare:CC (mult:SI (lshiftrt:SI
1269                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1270                               (const_int 16))
1271                              (lshiftrt:SI
1272                               (match_operand:SI 2 "gpc_reg_operand" "r")
1273                               (const_int 16)))
1274                     (const_int 0)))
1275    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1276         (mult:SI (lshiftrt:SI
1277                   (match_dup 1)
1278                   (const_int 16))
1279                  (lshiftrt:SI
1280                   (match_dup 2)
1281                   (const_int 16))))]
1282   "TARGET_MULHW"
1283   "mulhhwu. %0, %1, %2"
1284   [(set_attr "type" "imul3")])
1285
1286 (define_insn "*mulhhwu"
1287   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1288         (mult:SI (lshiftrt:SI
1289                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1290                   (const_int 16))
1291                  (lshiftrt:SI
1292                   (match_operand:SI 2 "gpc_reg_operand" "r")
1293                   (const_int 16))))]
1294   "TARGET_MULHW"
1295   "mulhhwu %0, %1, %2"
1296   [(set_attr "type" "imul3")])
1297
1298 (define_insn "*mullhwc"
1299   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1300         (compare:CC (mult:SI (sign_extend:SI
1301                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1302                              (sign_extend:SI
1303                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1304                     (const_int 0)))
1305    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1306         (mult:SI (sign_extend:SI
1307                   (match_dup 1))
1308                  (sign_extend:SI
1309                   (match_dup 2))))]
1310   "TARGET_MULHW"
1311   "mullhw. %0, %1, %2"
1312   [(set_attr "type" "imul3")])
1313
1314 (define_insn "*mullhw"
1315   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1316         (mult:SI (sign_extend:SI
1317                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1318                  (sign_extend:SI
1319                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1320   "TARGET_MULHW"
1321   "mullhw %0, %1, %2"
1322   [(set_attr "type" "imul3")])
1323
1324 (define_insn "*mullhwuc"
1325   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1326         (compare:CC (mult:SI (zero_extend:SI
1327                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1328                              (zero_extend:SI
1329                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1330                     (const_int 0)))
1331    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1332         (mult:SI (zero_extend:SI
1333                   (match_dup 1))
1334                  (zero_extend:SI
1335                   (match_dup 2))))]
1336   "TARGET_MULHW"
1337   "mullhwu. %0, %1, %2"
1338   [(set_attr "type" "imul3")])
1339
1340 (define_insn "*mullhwu"
1341   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1342         (mult:SI (zero_extend:SI
1343                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1344                  (zero_extend:SI
1345                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1346   "TARGET_MULHW"
1347   "mullhwu %0, %1, %2"
1348   [(set_attr "type" "imul3")])
1349 \f
1350 ;; IBM 405 and 440 string-search dlmzb instruction support.
1351 (define_insn "dlmzb"
1352   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1353         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
1354                     (match_operand:SI 2 "gpc_reg_operand" "r")]
1355                    UNSPEC_DLMZB_CR))
1356    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1357         (unspec:SI [(match_dup 1)
1358                     (match_dup 2)]
1359                    UNSPEC_DLMZB))]
1360   "TARGET_DLMZB"
1361   "dlmzb. %0, %1, %2")
1362
1363 (define_expand "strlensi"
1364   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1365         (unspec:SI [(match_operand:BLK 1 "general_operand" "")
1366                     (match_operand:QI 2 "const_int_operand" "")
1367                     (match_operand 3 "const_int_operand" "")]
1368                    UNSPEC_DLMZB_STRLEN))
1369    (clobber (match_scratch:CC 4 "=x"))]
1370   "TARGET_DLMZB && WORDS_BIG_ENDIAN && !optimize_size"
1371 {
1372   rtx result = operands[0];
1373   rtx src = operands[1];
1374   rtx search_char = operands[2];
1375   rtx align = operands[3];
1376   rtx addr, scratch_string, word1, word2, scratch_dlmzb;
1377   rtx loop_label, end_label, mem, cr0, cond;
1378   if (search_char != const0_rtx
1379       || GET_CODE (align) != CONST_INT
1380       || INTVAL (align) < 8)
1381         FAIL;
1382   word1 = gen_reg_rtx (SImode);
1383   word2 = gen_reg_rtx (SImode);
1384   scratch_dlmzb = gen_reg_rtx (SImode);
1385   scratch_string = gen_reg_rtx (Pmode);
1386   loop_label = gen_label_rtx ();
1387   end_label = gen_label_rtx ();
1388   addr = force_reg (Pmode, XEXP (src, 0));
1389   emit_move_insn (scratch_string, addr);
1390   emit_label (loop_label);
1391   mem = change_address (src, SImode, scratch_string);
1392   emit_move_insn (word1, mem);
1393   emit_move_insn (word2, adjust_address (mem, SImode, 4));
1394   cr0 = gen_rtx_REG (CCmode, CR0_REGNO);
1395   emit_insn (gen_dlmzb (scratch_dlmzb, word1, word2, cr0));
1396   cond = gen_rtx_NE (VOIDmode, cr0, const0_rtx);
1397   emit_jump_insn (gen_rtx_SET (VOIDmode,
1398                                pc_rtx,
1399                                gen_rtx_IF_THEN_ELSE (VOIDmode,
1400                                                      cond,
1401                                                      gen_rtx_LABEL_REF
1402                                                        (VOIDmode,
1403                                                         end_label),
1404                                                      pc_rtx)));
1405   emit_insn (gen_addsi3 (scratch_string, scratch_string, GEN_INT (8)));
1406   emit_jump_insn (gen_rtx_SET (VOIDmode,
1407                                pc_rtx,
1408                                gen_rtx_LABEL_REF (VOIDmode, loop_label)));
1409   emit_barrier ();
1410   emit_label (end_label);
1411   emit_insn (gen_addsi3 (scratch_string, scratch_string, scratch_dlmzb));
1412   emit_insn (gen_subsi3 (result, scratch_string, addr));
1413   emit_insn (gen_subsi3 (result, result, const1_rtx));
1414   DONE;
1415 })
1416 \f
1417 (define_split
1418   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1419         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1420                     (const_int 0)))
1421    (set (match_operand:SI 0 "gpc_reg_operand" "")
1422         (sign_extend:SI (match_dup 1)))]
1423   "reload_completed"
1424   [(set (match_dup 0)
1425         (sign_extend:SI (match_dup 1)))
1426    (set (match_dup 2)
1427         (compare:CC (match_dup 0)
1428                     (const_int 0)))]
1429   "")
1430
1431 ;; Fixed-point arithmetic insns.
1432
1433 (define_expand "add<mode>3"
1434   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1435         (plus:SDI (match_operand:SDI 1 "gpc_reg_operand" "")
1436                   (match_operand:SDI 2 "reg_or_add_cint_operand" "")))]
1437   ""
1438 {
1439   if (<MODE>mode == DImode && ! TARGET_POWERPC64)
1440     {
1441       if (non_short_cint_operand (operands[2], DImode))
1442         FAIL;
1443     }
1444   else if (GET_CODE (operands[2]) == CONST_INT
1445            && ! add_operand (operands[2], <MODE>mode))
1446     {
1447       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
1448                  ? operands[0] : gen_reg_rtx (<MODE>mode));
1449
1450       HOST_WIDE_INT val = INTVAL (operands[2]);
1451       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1452       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1453
1454       if (<MODE>mode == DImode && !satisfies_constraint_L (GEN_INT (rest)))
1455         FAIL;
1456
1457       /* The ordering here is important for the prolog expander.
1458          When space is allocated from the stack, adding 'low' first may
1459          produce a temporary deallocation (which would be bad).  */
1460       emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1461       emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1462       DONE;
1463     }
1464 })
1465
1466 ;; Discourage ai/addic because of carry but provide it in an alternative
1467 ;; allowing register zero as source.
1468 (define_insn "*add<mode>3_internal1"
1469   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,?r,r")
1470         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,r,b")
1471                   (match_operand:GPR 2 "add_operand" "r,I,I,L")))]
1472   ""
1473   "@
1474    {cax|add} %0,%1,%2
1475    {cal %0,%2(%1)|addi %0,%1,%2}
1476    {ai|addic} %0,%1,%2
1477    {cau|addis} %0,%1,%v2"
1478   [(set_attr "length" "4,4,4,4")])
1479
1480 (define_insn "addsi3_high"
1481   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1482         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1483                  (high:SI (match_operand 2 "" ""))))]
1484   "TARGET_MACHO && !TARGET_64BIT"
1485   "{cau|addis} %0,%1,ha16(%2)"
1486   [(set_attr "length" "4")])
1487
1488 (define_insn "*add<mode>3_internal2"
1489   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1490         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1491                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1492                     (const_int 0)))
1493    (clobber (match_scratch:P 3 "=r,r,r,r"))]
1494   ""
1495   "@
1496    {cax.|add.} %3,%1,%2
1497    {ai.|addic.} %3,%1,%2
1498    #
1499    #"
1500   [(set_attr "type" "fast_compare,compare,compare,compare")
1501    (set_attr "length" "4,4,8,8")])
1502
1503 (define_split
1504   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1505         (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1506                               (match_operand:GPR 2 "reg_or_short_operand" ""))
1507                     (const_int 0)))
1508    (clobber (match_scratch:GPR 3 ""))]
1509   "reload_completed"
1510   [(set (match_dup 3)
1511         (plus:GPR (match_dup 1)
1512                  (match_dup 2)))
1513    (set (match_dup 0)
1514         (compare:CC (match_dup 3)
1515                     (const_int 0)))]
1516   "")
1517
1518 (define_insn "*add<mode>3_internal3"
1519   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1520         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1521                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1522                     (const_int 0)))
1523    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
1524         (plus:P (match_dup 1)
1525                 (match_dup 2)))]
1526   ""
1527   "@
1528    {cax.|add.} %0,%1,%2
1529    {ai.|addic.} %0,%1,%2
1530    #
1531    #"
1532   [(set_attr "type" "fast_compare,compare,compare,compare")
1533    (set_attr "length" "4,4,8,8")])
1534
1535 (define_split
1536   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1537         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "")
1538                             (match_operand:P 2 "reg_or_short_operand" ""))
1539                     (const_int 0)))
1540    (set (match_operand:P 0 "gpc_reg_operand" "")
1541         (plus:P (match_dup 1) (match_dup 2)))]
1542   "reload_completed"
1543   [(set (match_dup 0)
1544         (plus:P (match_dup 1)
1545                 (match_dup 2)))
1546    (set (match_dup 3)
1547         (compare:CC (match_dup 0)
1548                     (const_int 0)))]
1549   "")
1550
1551 ;; Split an add that we can't do in one insn into two insns, each of which
1552 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1553 ;; add should be last in case the result gets used in an address.
1554
1555 (define_split
1556   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1557         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1558                   (match_operand:GPR 2 "non_add_cint_operand" "")))]
1559   ""
1560   [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1561    (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
1562 {
1563   HOST_WIDE_INT val = INTVAL (operands[2]);
1564   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1565   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1566
1567   operands[4] = GEN_INT (low);
1568   if (<MODE>mode == SImode || satisfies_constraint_L (GEN_INT (rest)))
1569     operands[3] = GEN_INT (rest);
1570   else if (! no_new_pseudos)
1571     {
1572       operands[3] = gen_reg_rtx (DImode);
1573       emit_move_insn (operands[3], operands[2]);
1574       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
1575       DONE;
1576     }
1577   else
1578     FAIL;
1579 })
1580
1581 (define_insn "one_cmpl<mode>2"
1582   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1583         (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1584   ""
1585   "nor %0,%1,%1")
1586
1587 (define_insn ""
1588   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1589         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1590                     (const_int 0)))
1591    (clobber (match_scratch:P 2 "=r,r"))]
1592   ""
1593   "@
1594    nor. %2,%1,%1
1595    #"
1596   [(set_attr "type" "compare")
1597    (set_attr "length" "4,8")])
1598
1599 (define_split
1600   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1601         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1602                     (const_int 0)))
1603    (clobber (match_scratch:P 2 ""))]
1604   "reload_completed"
1605   [(set (match_dup 2)
1606         (not:P (match_dup 1)))
1607    (set (match_dup 0)
1608         (compare:CC (match_dup 2)
1609                     (const_int 0)))]
1610   "")
1611
1612 (define_insn ""
1613   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1614         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1615                     (const_int 0)))
1616    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1617         (not:P (match_dup 1)))]
1618   ""
1619   "@
1620    nor. %0,%1,%1
1621    #"
1622   [(set_attr "type" "compare")
1623    (set_attr "length" "4,8")])
1624
1625 (define_split
1626   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1627         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1628                     (const_int 0)))
1629    (set (match_operand:P 0 "gpc_reg_operand" "")
1630         (not:P (match_dup 1)))]
1631   "reload_completed"
1632   [(set (match_dup 0)
1633         (not:P (match_dup 1)))
1634    (set (match_dup 2)
1635         (compare:CC (match_dup 0)
1636                     (const_int 0)))]
1637   "")
1638
1639 (define_insn ""
1640   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1641         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
1642                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
1643   "! TARGET_POWERPC"
1644   "{sf%I1|subf%I1c} %0,%2,%1")
1645
1646 (define_insn ""
1647   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
1648         (minus:GPR (match_operand:GPR 1 "reg_or_short_operand" "r,I")
1649                    (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
1650   "TARGET_POWERPC"
1651   "@
1652    subf %0,%2,%1
1653    subfic %0,%2,%1")
1654
1655 (define_insn ""
1656   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1657         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1658                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1659                     (const_int 0)))
1660    (clobber (match_scratch:SI 3 "=r,r"))]
1661   "! TARGET_POWERPC"
1662   "@
1663    {sf.|subfc.} %3,%2,%1
1664    #"
1665   [(set_attr "type" "compare")
1666    (set_attr "length" "4,8")])
1667
1668 (define_insn ""
1669   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1670         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1671                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1672                     (const_int 0)))
1673    (clobber (match_scratch:P 3 "=r,r"))]
1674   "TARGET_POWERPC"
1675   "@
1676    subf. %3,%2,%1
1677    #"
1678   [(set_attr "type" "fast_compare")
1679    (set_attr "length" "4,8")])
1680
1681 (define_split
1682   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1683         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1684                              (match_operand:P 2 "gpc_reg_operand" ""))
1685                     (const_int 0)))
1686    (clobber (match_scratch:P 3 ""))]
1687   "reload_completed"
1688   [(set (match_dup 3)
1689         (minus:P (match_dup 1)
1690                   (match_dup 2)))
1691    (set (match_dup 0)
1692         (compare:CC (match_dup 3)
1693                     (const_int 0)))]
1694   "")
1695
1696 (define_insn ""
1697   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1698         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1699                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1700                     (const_int 0)))
1701    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1702         (minus:SI (match_dup 1) (match_dup 2)))]
1703   "! TARGET_POWERPC"
1704   "@
1705    {sf.|subfc.} %0,%2,%1
1706    #"
1707   [(set_attr "type" "compare")
1708    (set_attr "length" "4,8")])
1709
1710 (define_insn ""
1711   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1712         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1713                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1714                     (const_int 0)))
1715    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1716         (minus:P (match_dup 1)
1717                   (match_dup 2)))]
1718   "TARGET_POWERPC"
1719   "@
1720    subf. %0,%2,%1
1721    #"
1722   [(set_attr "type" "fast_compare")
1723    (set_attr "length" "4,8")])
1724
1725 (define_split
1726   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1727         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1728                              (match_operand:P 2 "gpc_reg_operand" ""))
1729                     (const_int 0)))
1730    (set (match_operand:P 0 "gpc_reg_operand" "")
1731         (minus:P (match_dup 1)
1732                   (match_dup 2)))]
1733   "reload_completed"
1734   [(set (match_dup 0)
1735         (minus:P (match_dup 1)
1736                   (match_dup 2)))
1737    (set (match_dup 3)
1738         (compare:CC (match_dup 0)
1739                     (const_int 0)))]
1740   "")
1741
1742 (define_expand "sub<mode>3"
1743   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1744         (minus:SDI (match_operand:SDI 1 "reg_or_short_operand" "")
1745                    (match_operand:SDI 2 "reg_or_sub_cint_operand" "")))]
1746   ""
1747   "
1748 {
1749   if (GET_CODE (operands[2]) == CONST_INT)
1750     {
1751       emit_insn (gen_add<mode>3 (operands[0], operands[1],
1752                                  negate_rtx (<MODE>mode, operands[2])));
1753       DONE;
1754     }
1755 }")
1756
1757 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1758 ;; instruction and some auxiliary computations.  Then we just have a single
1759 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1760 ;; combine.
1761
1762 (define_expand "sminsi3"
1763   [(set (match_dup 3)
1764         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1765                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1766                          (const_int 0)
1767                          (minus:SI (match_dup 2) (match_dup 1))))
1768    (set (match_operand:SI 0 "gpc_reg_operand" "")
1769         (minus:SI (match_dup 2) (match_dup 3)))]
1770   "TARGET_POWER || TARGET_ISEL"
1771   "
1772 {
1773   if (TARGET_ISEL)
1774     {
1775       operands[2] = force_reg (SImode, operands[2]);
1776       rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
1777       DONE;
1778     }
1779
1780   operands[3] = gen_reg_rtx (SImode);
1781 }")
1782
1783 (define_split
1784   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1785         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1786                  (match_operand:SI 2 "reg_or_short_operand" "")))
1787    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1788   "TARGET_POWER"
1789   [(set (match_dup 3)
1790         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1791                          (const_int 0)
1792                          (minus:SI (match_dup 2) (match_dup 1))))
1793    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1794   "")
1795
1796 (define_expand "smaxsi3"
1797   [(set (match_dup 3)
1798         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1799                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1800                          (const_int 0)
1801                          (minus:SI (match_dup 2) (match_dup 1))))
1802    (set (match_operand:SI 0 "gpc_reg_operand" "")
1803         (plus:SI (match_dup 3) (match_dup 1)))]
1804   "TARGET_POWER || TARGET_ISEL"
1805   "
1806 {
1807   if (TARGET_ISEL)
1808     {
1809       operands[2] = force_reg (SImode, operands[2]);
1810       rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
1811       DONE;
1812     }
1813   operands[3] = gen_reg_rtx (SImode);
1814 }")
1815
1816 (define_split
1817   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1818         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1819                  (match_operand:SI 2 "reg_or_short_operand" "")))
1820    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1821   "TARGET_POWER"
1822   [(set (match_dup 3)
1823         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1824                          (const_int 0)
1825                          (minus:SI (match_dup 2) (match_dup 1))))
1826    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1827   "")
1828
1829 (define_expand "uminsi3"
1830   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1831                               (match_dup 5)))
1832    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1833                               (match_dup 5)))
1834    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1835                                        (const_int 0)
1836                                        (minus:SI (match_dup 4) (match_dup 3))))
1837    (set (match_operand:SI 0 "gpc_reg_operand" "")
1838         (minus:SI (match_dup 2) (match_dup 3)))]
1839   "TARGET_POWER || TARGET_ISEL"
1840   "
1841 {
1842   if (TARGET_ISEL)
1843     {
1844       rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
1845       DONE;
1846     }
1847   operands[3] = gen_reg_rtx (SImode);
1848   operands[4] = gen_reg_rtx (SImode);
1849   operands[5] = GEN_INT (-2147483647 - 1);
1850 }")
1851
1852 (define_expand "umaxsi3"
1853   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1854                               (match_dup 5)))
1855    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1856                               (match_dup 5)))
1857    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1858                                        (const_int 0)
1859                                        (minus:SI (match_dup 4) (match_dup 3))))
1860    (set (match_operand:SI 0 "gpc_reg_operand" "")
1861         (plus:SI (match_dup 3) (match_dup 1)))]
1862   "TARGET_POWER || TARGET_ISEL"
1863   "
1864 {
1865   if (TARGET_ISEL)
1866     {
1867       rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
1868       DONE;
1869     }
1870   operands[3] = gen_reg_rtx (SImode);
1871   operands[4] = gen_reg_rtx (SImode);
1872   operands[5] = GEN_INT (-2147483647 - 1);
1873 }")
1874
1875 (define_insn ""
1876   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1877         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1878                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
1879                          (const_int 0)
1880                          (minus:SI (match_dup 2) (match_dup 1))))]
1881   "TARGET_POWER"
1882   "doz%I2 %0,%1,%2")
1883
1884 (define_insn ""
1885   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1886         (compare:CC
1887          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1888                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1889                           (const_int 0)
1890                           (minus:SI (match_dup 2) (match_dup 1)))
1891          (const_int 0)))
1892    (clobber (match_scratch:SI 3 "=r,r"))]
1893   "TARGET_POWER"
1894   "@
1895    doz%I2. %3,%1,%2
1896    #"
1897   [(set_attr "type" "delayed_compare")
1898    (set_attr "length" "4,8")])
1899
1900 (define_split
1901   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1902         (compare:CC
1903          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1904                               (match_operand:SI 2 "reg_or_short_operand" ""))
1905                           (const_int 0)
1906                           (minus:SI (match_dup 2) (match_dup 1)))
1907          (const_int 0)))
1908    (clobber (match_scratch:SI 3 ""))]
1909   "TARGET_POWER && reload_completed"
1910   [(set (match_dup 3)
1911         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1912                           (const_int 0)
1913                           (minus:SI (match_dup 2) (match_dup 1))))
1914    (set (match_dup 0)
1915         (compare:CC (match_dup 3)
1916                     (const_int 0)))]
1917   "")
1918
1919 (define_insn ""
1920   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1921         (compare:CC
1922          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1923                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1924                           (const_int 0)
1925                           (minus:SI (match_dup 2) (match_dup 1)))
1926          (const_int 0)))
1927    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1928         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1929                          (const_int 0)
1930                          (minus:SI (match_dup 2) (match_dup 1))))]
1931   "TARGET_POWER"
1932   "@
1933    doz%I2. %0,%1,%2
1934    #"
1935   [(set_attr "type" "delayed_compare")
1936    (set_attr "length" "4,8")])
1937
1938 (define_split
1939   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1940         (compare:CC
1941          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1942                               (match_operand:SI 2 "reg_or_short_operand" ""))
1943                           (const_int 0)
1944                           (minus:SI (match_dup 2) (match_dup 1)))
1945          (const_int 0)))
1946    (set (match_operand:SI 0 "gpc_reg_operand" "")
1947         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1948                          (const_int 0)
1949                          (minus:SI (match_dup 2) (match_dup 1))))]
1950   "TARGET_POWER && reload_completed"
1951   [(set (match_dup 0)
1952         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1953                          (const_int 0)
1954                          (minus:SI (match_dup 2) (match_dup 1))))
1955    (set (match_dup 3)
1956         (compare:CC (match_dup 0)
1957                     (const_int 0)))]
1958   "")
1959
1960 ;; We don't need abs with condition code because such comparisons should
1961 ;; never be done.
1962 (define_expand "abssi2"
1963   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1964         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
1965   ""
1966   "
1967 {
1968   if (TARGET_ISEL)
1969     {
1970       emit_insn (gen_abssi2_isel (operands[0], operands[1]));
1971       DONE;
1972     }
1973   else if (! TARGET_POWER)
1974     {
1975       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
1976       DONE;
1977     }
1978 }")
1979
1980 (define_insn "*abssi2_power"
1981   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1982         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1983   "TARGET_POWER"
1984   "abs %0,%1")
1985
1986 (define_insn_and_split "abssi2_isel"
1987   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1988         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
1989    (clobber (match_scratch:SI 2 "=&b"))
1990    (clobber (match_scratch:CC 3 "=y"))]
1991   "TARGET_ISEL"
1992   "#"
1993   "&& reload_completed"
1994   [(set (match_dup 2) (neg:SI (match_dup 1)))
1995    (set (match_dup 3)
1996         (compare:CC (match_dup 1)
1997                     (const_int 0)))
1998    (set (match_dup 0)
1999         (if_then_else:SI (ge (match_dup 3)
2000                              (const_int 0))
2001                          (match_dup 1)
2002                          (match_dup 2)))]
2003   "")
2004
2005 (define_insn_and_split "abssi2_nopower"
2006   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
2007         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
2008    (clobber (match_scratch:SI 2 "=&r,&r"))]
2009   "! TARGET_POWER && ! TARGET_ISEL"
2010   "#"
2011   "&& reload_completed"
2012   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
2013    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
2014    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
2015   "")
2016
2017 (define_insn "*nabs_power"
2018   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2019         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
2020   "TARGET_POWER"
2021   "nabs %0,%1")
2022
2023 (define_insn_and_split "*nabs_nopower"
2024   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
2025         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
2026    (clobber (match_scratch:SI 2 "=&r,&r"))]
2027   "! TARGET_POWER"
2028   "#"
2029   "&& reload_completed"
2030   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
2031    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
2032    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
2033   "")
2034
2035 (define_expand "neg<mode>2"
2036   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
2037         (neg:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
2038   ""
2039   "")
2040
2041 (define_insn "*neg<mode>2_internal"
2042   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2043         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2044   ""
2045   "neg %0,%1")
2046
2047 (define_insn ""
2048   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2049         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2050                     (const_int 0)))
2051    (clobber (match_scratch:P 2 "=r,r"))]
2052   ""
2053   "@
2054    neg. %2,%1
2055    #"
2056   [(set_attr "type" "fast_compare")
2057    (set_attr "length" "4,8")])
2058
2059 (define_split
2060   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2061         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2062                     (const_int 0)))
2063    (clobber (match_scratch:P 2 ""))]
2064   "reload_completed"
2065   [(set (match_dup 2)
2066         (neg:P (match_dup 1)))
2067    (set (match_dup 0)
2068         (compare:CC (match_dup 2)
2069                     (const_int 0)))]
2070   "")
2071
2072 (define_insn ""
2073   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2074         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2075                     (const_int 0)))
2076    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2077         (neg:P (match_dup 1)))]
2078   ""
2079   "@
2080    neg. %0,%1
2081    #"
2082   [(set_attr "type" "fast_compare")
2083    (set_attr "length" "4,8")])
2084
2085 (define_split
2086   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
2087         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2088                     (const_int 0)))
2089    (set (match_operand:P 0 "gpc_reg_operand" "")
2090         (neg:P (match_dup 1)))]
2091   "reload_completed"
2092   [(set (match_dup 0)
2093         (neg:P (match_dup 1)))
2094    (set (match_dup 2)
2095         (compare:CC (match_dup 0)
2096                     (const_int 0)))]
2097   "")
2098
2099 (define_insn "clz<mode>2"
2100   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2101         (clz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2102   ""
2103   "{cntlz|cntlz<wd>} %0,%1")
2104
2105 (define_expand "ctz<mode>2"
2106   [(set (match_dup 2)
2107         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))
2108    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2109                                           (match_dup 2)))
2110               (clobber (scratch:CC))])
2111    (set (match_dup 4) (clz:GPR (match_dup 3)))
2112    (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2113         (minus:GPR (match_dup 5) (match_dup 4)))]
2114   ""
2115   {
2116      operands[2] = gen_reg_rtx (<MODE>mode);
2117      operands[3] = gen_reg_rtx (<MODE>mode);
2118      operands[4] = gen_reg_rtx (<MODE>mode);
2119      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 1);
2120   })
2121
2122 (define_expand "ffs<mode>2"
2123   [(set (match_dup 2)
2124         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))
2125    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2126                                           (match_dup 2)))
2127               (clobber (scratch:CC))])
2128    (set (match_dup 4) (clz:GPR (match_dup 3)))
2129    (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2130         (minus:GPR (match_dup 5) (match_dup 4)))]
2131   ""
2132   {
2133      operands[2] = gen_reg_rtx (<MODE>mode);
2134      operands[3] = gen_reg_rtx (<MODE>mode);
2135      operands[4] = gen_reg_rtx (<MODE>mode);
2136      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
2137   })
2138
2139 (define_expand "popcount<mode>2"
2140   [(set (match_dup 2)
2141         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
2142                      UNSPEC_POPCNTB))
2143    (set (match_dup 3)
2144         (mult:GPR (match_dup 2) (match_dup 4)))
2145    (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2146         (lshiftrt:GPR (match_dup 3) (match_dup 5)))]
2147   "TARGET_POPCNTB"
2148   {
2149     operands[2] = gen_reg_rtx (<MODE>mode);
2150     operands[3] = gen_reg_rtx (<MODE>mode);
2151     operands[4] = force_reg (<MODE>mode,
2152                              <MODE>mode == SImode
2153                              ? GEN_INT (0x01010101)
2154                              : GEN_INT ((HOST_WIDE_INT)
2155                                         0x01010101 << 32 | 0x01010101));
2156     operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 8);
2157   })
2158
2159 (define_insn "popcntb<mode>2"
2160   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2161         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
2162                      UNSPEC_POPCNTB))]
2163   "TARGET_POPCNTB"
2164   "popcntb %0,%1")
2165
2166 (define_expand "mulsi3"
2167   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2168    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2169    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
2170   ""
2171   "
2172 {
2173   if (TARGET_POWER)
2174     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
2175   else
2176     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
2177   DONE;
2178 }")
2179
2180 (define_insn "mulsi3_mq"
2181   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2182         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2183                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
2184    (clobber (match_scratch:SI 3 "=q,q"))]
2185   "TARGET_POWER"
2186   "@
2187    {muls|mullw} %0,%1,%2
2188    {muli|mulli} %0,%1,%2"
2189    [(set (attr "type")
2190       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2191                 (const_string "imul3")
2192              (match_operand:SI 2 "short_cint_operand" "")
2193                 (const_string "imul2")]
2194         (const_string "imul")))])
2195
2196 (define_insn "mulsi3_no_mq"
2197   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2198         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2199                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
2200   "! TARGET_POWER"
2201   "@
2202    {muls|mullw} %0,%1,%2
2203    {muli|mulli} %0,%1,%2"
2204    [(set (attr "type")
2205       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2206                 (const_string "imul3")
2207              (match_operand:SI 2 "short_cint_operand" "")
2208                 (const_string "imul2")]
2209         (const_string "imul")))])
2210
2211 (define_insn "*mulsi3_mq_internal1"
2212   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2213         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2214                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2215                     (const_int 0)))
2216    (clobber (match_scratch:SI 3 "=r,r"))
2217    (clobber (match_scratch:SI 4 "=q,q"))]
2218   "TARGET_POWER"
2219   "@
2220    {muls.|mullw.} %3,%1,%2
2221    #"
2222   [(set_attr "type" "imul_compare")
2223    (set_attr "length" "4,8")])
2224
2225 (define_split
2226   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2227         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2228                              (match_operand:SI 2 "gpc_reg_operand" ""))
2229                     (const_int 0)))
2230    (clobber (match_scratch:SI 3 ""))
2231    (clobber (match_scratch:SI 4 ""))]
2232   "TARGET_POWER && reload_completed"
2233   [(parallel [(set (match_dup 3)
2234         (mult:SI (match_dup 1) (match_dup 2)))
2235    (clobber (match_dup 4))])
2236    (set (match_dup 0)
2237         (compare:CC (match_dup 3)
2238                     (const_int 0)))]
2239   "")
2240
2241 (define_insn "*mulsi3_no_mq_internal1"
2242   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2243         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2244                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2245                     (const_int 0)))
2246    (clobber (match_scratch:SI 3 "=r,r"))]
2247   "! TARGET_POWER"
2248   "@
2249    {muls.|mullw.} %3,%1,%2
2250    #"
2251   [(set_attr "type" "imul_compare")
2252    (set_attr "length" "4,8")])
2253
2254 (define_split
2255   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2256         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2257                              (match_operand:SI 2 "gpc_reg_operand" ""))
2258                     (const_int 0)))
2259    (clobber (match_scratch:SI 3 ""))]
2260   "! TARGET_POWER && reload_completed"
2261   [(set (match_dup 3)
2262         (mult:SI (match_dup 1) (match_dup 2)))
2263    (set (match_dup 0)
2264         (compare:CC (match_dup 3)
2265                     (const_int 0)))]
2266   "")
2267
2268 (define_insn "*mulsi3_mq_internal2"
2269   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2270         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2271                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2272                     (const_int 0)))
2273    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2274         (mult:SI (match_dup 1) (match_dup 2)))
2275    (clobber (match_scratch:SI 4 "=q,q"))]
2276   "TARGET_POWER"
2277   "@
2278    {muls.|mullw.} %0,%1,%2
2279    #"
2280   [(set_attr "type" "imul_compare")
2281    (set_attr "length" "4,8")])
2282
2283 (define_split
2284   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2285         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2286                              (match_operand:SI 2 "gpc_reg_operand" ""))
2287                     (const_int 0)))
2288    (set (match_operand:SI 0 "gpc_reg_operand" "")
2289         (mult:SI (match_dup 1) (match_dup 2)))
2290    (clobber (match_scratch:SI 4 ""))]
2291   "TARGET_POWER && reload_completed"
2292   [(parallel [(set (match_dup 0)
2293         (mult:SI (match_dup 1) (match_dup 2)))
2294    (clobber (match_dup 4))])
2295    (set (match_dup 3)
2296         (compare:CC (match_dup 0)
2297                     (const_int 0)))]
2298   "")
2299
2300 (define_insn "*mulsi3_no_mq_internal2"
2301   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2302         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2303                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2304                     (const_int 0)))
2305    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2306         (mult:SI (match_dup 1) (match_dup 2)))]
2307   "! TARGET_POWER"
2308   "@
2309    {muls.|mullw.} %0,%1,%2
2310    #"
2311   [(set_attr "type" "imul_compare")
2312    (set_attr "length" "4,8")])
2313
2314 (define_split
2315   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2316         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2317                              (match_operand:SI 2 "gpc_reg_operand" ""))
2318                     (const_int 0)))
2319    (set (match_operand:SI 0 "gpc_reg_operand" "")
2320         (mult:SI (match_dup 1) (match_dup 2)))]
2321   "! TARGET_POWER && reload_completed"
2322   [(set (match_dup 0)
2323         (mult:SI (match_dup 1) (match_dup 2)))
2324    (set (match_dup 3)
2325         (compare:CC (match_dup 0)
2326                     (const_int 0)))]
2327   "")
2328
2329 ;; Operand 1 is divided by operand 2; quotient goes to operand
2330 ;; 0 and remainder to operand 3.
2331 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
2332
2333 (define_expand "divmodsi4"
2334   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2335                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2336                            (match_operand:SI 2 "gpc_reg_operand" "")))
2337               (set (match_operand:SI 3 "register_operand" "")
2338                    (mod:SI (match_dup 1) (match_dup 2)))])]
2339   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
2340   "
2341 {
2342   if (! TARGET_POWER && ! TARGET_POWERPC)
2343     {
2344       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2345       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2346       emit_insn (gen_divss_call ());
2347       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2348       emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2349       DONE;
2350     }
2351 }")
2352
2353 (define_insn "*divmodsi4_internal"
2354   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2355         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2356                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2357    (set (match_operand:SI 3 "register_operand" "=q")
2358         (mod:SI (match_dup 1) (match_dup 2)))]
2359   "TARGET_POWER"
2360   "divs %0,%1,%2"
2361   [(set_attr "type" "idiv")])
2362
2363 (define_expand "udiv<mode>3"
2364   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2365         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2366                   (match_operand:GPR 2 "gpc_reg_operand" "")))]
2367   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
2368   "
2369 {
2370   if (! TARGET_POWER && ! TARGET_POWERPC)
2371     {
2372       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2373       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2374       emit_insn (gen_quous_call ());
2375       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2376       DONE;
2377     }
2378   else if (TARGET_POWER)
2379     {
2380       emit_insn (gen_udivsi3_mq (operands[0], operands[1], operands[2]));
2381       DONE;
2382     }
2383 }")
2384
2385 (define_insn "udivsi3_mq"
2386   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2387         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2388                  (match_operand:SI 2 "gpc_reg_operand" "r")))
2389    (clobber (match_scratch:SI 3 "=q"))]
2390   "TARGET_POWERPC && TARGET_POWER"
2391   "divwu %0,%1,%2"
2392   [(set_attr "type" "idiv")])
2393
2394 (define_insn "*udivsi3_no_mq"
2395   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2396         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2397                   (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2398   "TARGET_POWERPC && ! TARGET_POWER"
2399   "div<wd>u %0,%1,%2"
2400   [(set_attr "type" "idiv")])
2401
2402 ;; For powers of two we can do srai/aze for divide and then adjust for
2403 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
2404 ;; used; for PowerPC, force operands into register and do a normal divide;
2405 ;; for AIX common-mode, use quoss call on register operands.
2406 (define_expand "div<mode>3"
2407   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2408         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2409                  (match_operand:GPR 2 "reg_or_cint_operand" "")))]
2410   ""
2411   "
2412 {
2413   if (GET_CODE (operands[2]) == CONST_INT
2414       && INTVAL (operands[2]) > 0
2415       && exact_log2 (INTVAL (operands[2])) >= 0)
2416     ;
2417   else if (TARGET_POWERPC)
2418     {
2419       operands[2] = force_reg (<MODE>mode, operands[2]);
2420       if (TARGET_POWER)
2421         {
2422           emit_insn (gen_divsi3_mq (operands[0], operands[1], operands[2]));
2423           DONE;
2424         }
2425     }
2426   else if (TARGET_POWER)
2427     FAIL;
2428   else
2429     {
2430       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2431       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2432       emit_insn (gen_quoss_call ());
2433       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2434       DONE;
2435     }
2436 }")
2437
2438 (define_insn "divsi3_mq"
2439   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2440         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2441                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2442    (clobber (match_scratch:SI 3 "=q"))]
2443   "TARGET_POWERPC && TARGET_POWER"
2444   "divw %0,%1,%2"
2445   [(set_attr "type" "idiv")])
2446
2447 (define_insn "*div<mode>3_no_mq"
2448   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2449         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2450                  (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2451   "TARGET_POWERPC && ! TARGET_POWER"
2452   "div<wd> %0,%1,%2"
2453   [(set_attr "type" "idiv")])
2454
2455 (define_expand "mod<mode>3"
2456   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
2457    (use (match_operand:GPR 1 "gpc_reg_operand" ""))
2458    (use (match_operand:GPR 2 "reg_or_cint_operand" ""))]
2459   ""
2460   "
2461 {
2462   int i;
2463   rtx temp1;
2464   rtx temp2;
2465
2466   if (GET_CODE (operands[2]) != CONST_INT
2467       || INTVAL (operands[2]) <= 0
2468       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
2469     FAIL;
2470
2471   temp1 = gen_reg_rtx (<MODE>mode);
2472   temp2 = gen_reg_rtx (<MODE>mode);
2473
2474   emit_insn (gen_div<mode>3 (temp1, operands[1], operands[2]));
2475   emit_insn (gen_ashl<mode>3 (temp2, temp1, GEN_INT (i)));
2476   emit_insn (gen_sub<mode>3 (operands[0], operands[1], temp2));
2477   DONE;
2478 }")
2479
2480 (define_insn ""
2481   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2482         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2483                  (match_operand:GPR 2 "exact_log2_cint_operand" "N")))]
2484   ""
2485   "{srai|sra<wd>i} %0,%1,%p2\;{aze|addze} %0,%0"
2486   [(set_attr "type" "two")
2487    (set_attr "length" "8")])
2488
2489 (define_insn ""
2490   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2491         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2492                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2493                     (const_int 0)))
2494    (clobber (match_scratch:P 3 "=r,r"))]
2495   ""
2496   "@
2497    {srai|sra<wd>i} %3,%1,%p2\;{aze.|addze.} %3,%3
2498    #"
2499   [(set_attr "type" "compare")
2500    (set_attr "length" "8,12")])
2501
2502 (define_split
2503   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2504         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2505                              (match_operand:GPR 2 "exact_log2_cint_operand"
2506                               ""))
2507                     (const_int 0)))
2508    (clobber (match_scratch:GPR 3 ""))]
2509   "reload_completed"
2510   [(set (match_dup 3)
2511         (div:<MODE> (match_dup 1) (match_dup 2)))
2512    (set (match_dup 0)
2513         (compare:CC (match_dup 3)
2514                     (const_int 0)))]
2515   "")
2516
2517 (define_insn ""
2518   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2519         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2520                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2521                     (const_int 0)))
2522    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2523         (div:P (match_dup 1) (match_dup 2)))]
2524   ""
2525   "@
2526    {srai|sra<wd>i} %0,%1,%p2\;{aze.|addze.} %0,%0
2527    #"
2528   [(set_attr "type" "compare")
2529    (set_attr "length" "8,12")])
2530
2531 (define_split
2532   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2533         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2534                              (match_operand:GPR 2 "exact_log2_cint_operand"
2535                               ""))
2536                     (const_int 0)))
2537    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2538         (div:GPR (match_dup 1) (match_dup 2)))]
2539   "reload_completed"
2540   [(set (match_dup 0)
2541         (div:<MODE> (match_dup 1) (match_dup 2)))
2542    (set (match_dup 3)
2543         (compare:CC (match_dup 0)
2544                     (const_int 0)))]
2545   "")
2546
2547 (define_insn ""
2548   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2549         (udiv:SI
2550          (plus:DI (ashift:DI
2551                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
2552                    (const_int 32))
2553                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
2554          (match_operand:SI 3 "gpc_reg_operand" "r")))
2555    (set (match_operand:SI 2 "register_operand" "=*q")
2556         (umod:SI
2557          (plus:DI (ashift:DI
2558                    (zero_extend:DI (match_dup 1)) (const_int 32))
2559                   (zero_extend:DI (match_dup 4)))
2560          (match_dup 3)))]
2561   "TARGET_POWER"
2562   "div %0,%1,%3"
2563   [(set_attr "type" "idiv")])
2564
2565 ;; To do unsigned divide we handle the cases of the divisor looking like a
2566 ;; negative number.  If it is a constant that is less than 2**31, we don't
2567 ;; have to worry about the branches.  So make a few subroutines here.
2568 ;;
2569 ;; First comes the normal case.
2570 (define_expand "udivmodsi4_normal"
2571   [(set (match_dup 4) (const_int 0))
2572    (parallel [(set (match_operand:SI 0 "" "")
2573                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2574                                                 (const_int 32))
2575                                      (zero_extend:DI (match_operand:SI 1 "" "")))
2576                             (match_operand:SI 2 "" "")))
2577               (set (match_operand:SI 3 "" "")
2578                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2579                                                 (const_int 32))
2580                                      (zero_extend:DI (match_dup 1)))
2581                             (match_dup 2)))])]
2582   "TARGET_POWER"
2583   "
2584 { operands[4] = gen_reg_rtx (SImode); }")
2585
2586 ;; This handles the branches.
2587 (define_expand "udivmodsi4_tests"
2588   [(set (match_operand:SI 0 "" "") (const_int 0))
2589    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
2590    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
2591    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
2592                            (label_ref (match_operand:SI 4 "" "")) (pc)))
2593    (set (match_dup 0) (const_int 1))
2594    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
2595    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
2596    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
2597                            (label_ref (match_dup 4)) (pc)))]
2598   "TARGET_POWER"
2599   "
2600 { operands[5] = gen_reg_rtx (CCUNSmode);
2601   operands[6] = gen_reg_rtx (CCmode);
2602 }")
2603
2604 (define_expand "udivmodsi4"
2605   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2606                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
2607                             (match_operand:SI 2 "reg_or_cint_operand" "")))
2608               (set (match_operand:SI 3 "gpc_reg_operand" "")
2609                    (umod:SI (match_dup 1) (match_dup 2)))])]
2610   ""
2611   "
2612 {
2613   rtx label = 0;
2614
2615   if (! TARGET_POWER)
2616     {
2617       if (! TARGET_POWERPC)
2618         {
2619           emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2620           emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2621           emit_insn (gen_divus_call ());
2622           emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2623           emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2624           DONE;
2625         }
2626       else
2627         FAIL;
2628     }
2629
2630   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
2631     {
2632       operands[2] = force_reg (SImode, operands[2]);
2633       label = gen_label_rtx ();
2634       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
2635                                   operands[3], label));
2636     }
2637   else
2638     operands[2] = force_reg (SImode, operands[2]);
2639
2640   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
2641                                operands[3]));
2642   if (label)
2643     emit_label (label);
2644
2645   DONE;
2646 }")
2647
2648 ;; AIX architecture-independent common-mode multiply (DImode),
2649 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
2650 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
2651 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
2652 ;; assumed unused if generating common-mode, so ignore.
2653 (define_insn "mulh_call"
2654   [(set (reg:SI 3)
2655         (truncate:SI
2656          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
2657                                (sign_extend:DI (reg:SI 4)))
2658                       (const_int 32))))
2659    (clobber (match_scratch:SI 0 "=l"))]
2660   "! TARGET_POWER && ! TARGET_POWERPC"
2661   "bla __mulh"
2662   [(set_attr "type" "imul")])
2663
2664 (define_insn "mull_call"
2665   [(set (reg:DI 3)
2666         (mult:DI (sign_extend:DI (reg:SI 3))
2667                  (sign_extend:DI (reg:SI 4))))
2668    (clobber (match_scratch:SI 0 "=l"))
2669    (clobber (reg:SI 0))]
2670   "! TARGET_POWER && ! TARGET_POWERPC"
2671   "bla __mull"
2672   [(set_attr "type" "imul")])
2673
2674 (define_insn "divss_call"
2675   [(set (reg:SI 3)
2676         (div:SI (reg:SI 3) (reg:SI 4)))
2677    (set (reg:SI 4)
2678         (mod:SI (reg:SI 3) (reg:SI 4)))
2679    (clobber (match_scratch:SI 0 "=l"))
2680    (clobber (reg:SI 0))]
2681   "! TARGET_POWER && ! TARGET_POWERPC"
2682   "bla __divss"
2683   [(set_attr "type" "idiv")])
2684
2685 (define_insn "divus_call"
2686   [(set (reg:SI 3)
2687         (udiv:SI (reg:SI 3) (reg:SI 4)))
2688    (set (reg:SI 4)
2689         (umod:SI (reg:SI 3) (reg:SI 4)))
2690    (clobber (match_scratch:SI 0 "=l"))
2691    (clobber (reg:SI 0))
2692    (clobber (match_scratch:CC 1 "=x"))
2693    (clobber (reg:CC 69))]
2694   "! TARGET_POWER && ! TARGET_POWERPC"
2695   "bla __divus"
2696   [(set_attr "type" "idiv")])
2697
2698 (define_insn "quoss_call"
2699   [(set (reg:SI 3)
2700         (div:SI (reg:SI 3) (reg:SI 4)))
2701    (clobber (match_scratch:SI 0 "=l"))]
2702   "! TARGET_POWER && ! TARGET_POWERPC"
2703   "bla __quoss"
2704   [(set_attr "type" "idiv")])
2705
2706 (define_insn "quous_call"
2707   [(set (reg:SI 3)
2708         (udiv:SI (reg:SI 3) (reg:SI 4)))
2709    (clobber (match_scratch:SI 0 "=l"))
2710    (clobber (reg:SI 0))
2711    (clobber (match_scratch:CC 1 "=x"))
2712    (clobber (reg:CC 69))]
2713   "! TARGET_POWER && ! TARGET_POWERPC"
2714   "bla __quous"
2715   [(set_attr "type" "idiv")])
2716 \f
2717 ;; Logical instructions
2718 ;; The logical instructions are mostly combined by using match_operator,
2719 ;; but the plain AND insns are somewhat different because there is no
2720 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2721 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2722
2723 (define_insn "andsi3"
2724   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2725         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2726                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2727    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2728   ""
2729   "@
2730    and %0,%1,%2
2731    {rlinm|rlwinm} %0,%1,0,%m2,%M2
2732    {andil.|andi.} %0,%1,%b2
2733    {andiu.|andis.} %0,%1,%u2"
2734   [(set_attr "type" "*,*,compare,compare")])
2735
2736 ;; Note to set cr's other than cr0 we do the and immediate and then
2737 ;; the test again -- this avoids a mfcr which on the higher end
2738 ;; machines causes an execution serialization
2739
2740 (define_insn "*andsi3_internal2"
2741   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2742         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2743                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2744                     (const_int 0)))
2745    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2746    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2747   "TARGET_32BIT"
2748   "@
2749    and. %3,%1,%2
2750    {andil.|andi.} %3,%1,%b2
2751    {andiu.|andis.} %3,%1,%u2
2752    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2753    #
2754    #
2755    #
2756    #"
2757   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2758    (set_attr "length" "4,4,4,4,8,8,8,8")])
2759
2760 (define_insn "*andsi3_internal3"
2761   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2762         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2763                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2764                     (const_int 0)))
2765    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2766    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2767   "TARGET_64BIT"
2768   "@
2769    #
2770    {andil.|andi.} %3,%1,%b2
2771    {andiu.|andis.} %3,%1,%u2
2772    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2773    #
2774    #
2775    #
2776    #"
2777   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2778    (set_attr "length" "8,4,4,4,8,8,8,8")])
2779
2780 (define_split
2781   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2782         (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2783                              (match_operand:GPR 2 "and_operand" ""))
2784                     (const_int 0)))
2785    (clobber (match_scratch:GPR 3 ""))
2786    (clobber (match_scratch:CC 4 ""))]
2787   "reload_completed"
2788   [(parallel [(set (match_dup 3)
2789                    (and:<MODE> (match_dup 1)
2790                                (match_dup 2)))
2791               (clobber (match_dup 4))])
2792    (set (match_dup 0)
2793         (compare:CC (match_dup 3)
2794                     (const_int 0)))]
2795   "")
2796
2797 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
2798 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
2799
2800 (define_split
2801   [(set (match_operand:CC 0 "cc_reg_operand" "")
2802         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2803                             (match_operand:SI 2 "gpc_reg_operand" ""))
2804                     (const_int 0)))
2805    (clobber (match_scratch:SI 3 ""))
2806    (clobber (match_scratch:CC 4 ""))]
2807   "TARGET_POWERPC64 && reload_completed"
2808   [(parallel [(set (match_dup 3)
2809                    (and:SI (match_dup 1)
2810                            (match_dup 2)))
2811               (clobber (match_dup 4))])
2812    (set (match_dup 0)
2813         (compare:CC (match_dup 3)
2814                     (const_int 0)))]
2815   "")
2816
2817 (define_insn "*andsi3_internal4"
2818   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2819         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2820                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2821                     (const_int 0)))
2822    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2823         (and:SI (match_dup 1)
2824                 (match_dup 2)))
2825    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2826   "TARGET_32BIT"
2827   "@
2828    and. %0,%1,%2
2829    {andil.|andi.} %0,%1,%b2
2830    {andiu.|andis.} %0,%1,%u2
2831    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2832    #
2833    #
2834    #
2835    #"
2836   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2837    (set_attr "length" "4,4,4,4,8,8,8,8")])
2838
2839 (define_insn "*andsi3_internal5"
2840   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2841         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2842                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2843                     (const_int 0)))
2844    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2845         (and:SI (match_dup 1)
2846                 (match_dup 2)))
2847    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2848   "TARGET_64BIT"
2849   "@
2850    #
2851    {andil.|andi.} %0,%1,%b2
2852    {andiu.|andis.} %0,%1,%u2
2853    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2854    #
2855    #
2856    #
2857    #"
2858   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2859    (set_attr "length" "8,4,4,4,8,8,8,8")])
2860
2861 (define_split
2862   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2863         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2864                             (match_operand:SI 2 "and_operand" ""))
2865                     (const_int 0)))
2866    (set (match_operand:SI 0 "gpc_reg_operand" "")
2867         (and:SI (match_dup 1)
2868                 (match_dup 2)))
2869    (clobber (match_scratch:CC 4 ""))]
2870   "reload_completed"
2871   [(parallel [(set (match_dup 0)
2872                    (and:SI (match_dup 1)
2873                            (match_dup 2)))
2874               (clobber (match_dup 4))])
2875    (set (match_dup 3)
2876         (compare:CC (match_dup 0)
2877                     (const_int 0)))]
2878   "")
2879
2880 (define_split
2881   [(set (match_operand:CC 3 "cc_reg_operand" "")
2882         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2883                             (match_operand:SI 2 "gpc_reg_operand" ""))
2884                     (const_int 0)))
2885    (set (match_operand:SI 0 "gpc_reg_operand" "")
2886         (and:SI (match_dup 1)
2887                 (match_dup 2)))
2888    (clobber (match_scratch:CC 4 ""))]
2889   "TARGET_POWERPC64 && reload_completed"
2890   [(parallel [(set (match_dup 0)
2891                    (and:SI (match_dup 1)
2892                            (match_dup 2)))
2893               (clobber (match_dup 4))])
2894    (set (match_dup 3)
2895         (compare:CC (match_dup 0)
2896                     (const_int 0)))]
2897   "")
2898
2899 ;; Handle the PowerPC64 rlwinm corner case
2900
2901 (define_insn_and_split "*andsi3_internal6"
2902   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2903         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2904                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
2905   "TARGET_POWERPC64"
2906   "#"
2907   "TARGET_POWERPC64"
2908   [(set (match_dup 0)
2909         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
2910                 (match_dup 4)))
2911    (set (match_dup 0)
2912         (rotate:SI (match_dup 0) (match_dup 5)))]
2913   "
2914 {
2915   int mb = extract_MB (operands[2]);
2916   int me = extract_ME (operands[2]);
2917   operands[3] = GEN_INT (me + 1);
2918   operands[5] = GEN_INT (32 - (me + 1));
2919   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2920 }"
2921   [(set_attr "length" "8")])
2922
2923 (define_expand "iorsi3"
2924   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2925         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
2926                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2927   ""
2928   "
2929 {
2930   if (GET_CODE (operands[2]) == CONST_INT
2931       && ! logical_operand (operands[2], SImode))
2932     {
2933       HOST_WIDE_INT value = INTVAL (operands[2]);
2934       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2935                  ? operands[0] : gen_reg_rtx (SImode));
2936
2937       emit_insn (gen_iorsi3 (tmp, operands[1],
2938                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2939       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2940       DONE;
2941     }
2942 }")
2943
2944 (define_expand "xorsi3"
2945   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2946         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
2947                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2948   ""
2949   "
2950 {
2951   if (GET_CODE (operands[2]) == CONST_INT
2952       && ! logical_operand (operands[2], SImode))
2953     {
2954       HOST_WIDE_INT value = INTVAL (operands[2]);
2955       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2956                  ? operands[0] : gen_reg_rtx (SImode));
2957
2958       emit_insn (gen_xorsi3 (tmp, operands[1],
2959                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2960       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2961       DONE;
2962     }
2963 }")
2964
2965 (define_insn "*boolsi3_internal1"
2966   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
2967         (match_operator:SI 3 "boolean_or_operator"
2968          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
2969           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
2970   ""
2971   "@
2972    %q3 %0,%1,%2
2973    {%q3il|%q3i} %0,%1,%b2
2974    {%q3iu|%q3is} %0,%1,%u2")
2975
2976 (define_insn "*boolsi3_internal2"
2977   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2978         (compare:CC (match_operator:SI 4 "boolean_or_operator"
2979          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2980           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2981          (const_int 0)))
2982    (clobber (match_scratch:SI 3 "=r,r"))]
2983   "TARGET_32BIT"
2984   "@
2985    %q4. %3,%1,%2
2986    #"
2987   [(set_attr "type" "compare")
2988    (set_attr "length" "4,8")])
2989
2990 (define_split
2991   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2992         (compare:CC (match_operator:SI 4 "boolean_operator"
2993          [(match_operand:SI 1 "gpc_reg_operand" "")
2994           (match_operand:SI 2 "gpc_reg_operand" "")])
2995          (const_int 0)))
2996    (clobber (match_scratch:SI 3 ""))]
2997   "TARGET_32BIT && reload_completed"
2998   [(set (match_dup 3) (match_dup 4))
2999    (set (match_dup 0)
3000         (compare:CC (match_dup 3)
3001                     (const_int 0)))]
3002   "")
3003
3004 (define_insn "*boolsi3_internal3"
3005   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3006         (compare:CC (match_operator:SI 4 "boolean_operator"
3007          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3008           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3009          (const_int 0)))
3010    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3011         (match_dup 4))]
3012   "TARGET_32BIT"
3013   "@
3014    %q4. %0,%1,%2
3015    #"
3016   [(set_attr "type" "compare")
3017    (set_attr "length" "4,8")])
3018
3019 (define_split
3020   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3021         (compare:CC (match_operator:SI 4 "boolean_operator"
3022          [(match_operand:SI 1 "gpc_reg_operand" "")
3023           (match_operand:SI 2 "gpc_reg_operand" "")])
3024          (const_int 0)))
3025    (set (match_operand:SI 0 "gpc_reg_operand" "")
3026         (match_dup 4))]
3027   "TARGET_32BIT && reload_completed"
3028   [(set (match_dup 0) (match_dup 4))
3029    (set (match_dup 3)
3030         (compare:CC (match_dup 0)
3031                     (const_int 0)))]
3032   "")
3033
3034 ;; Split a logical operation that we can't do in one insn into two insns,
3035 ;; each of which does one 16-bit part.  This is used by combine.
3036
3037 (define_split
3038   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3039         (match_operator:SI 3 "boolean_or_operator"
3040          [(match_operand:SI 1 "gpc_reg_operand" "")
3041           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
3042   ""
3043   [(set (match_dup 0) (match_dup 4))
3044    (set (match_dup 0) (match_dup 5))]
3045 "
3046 {
3047   rtx i;
3048   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
3049   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3050                                 operands[1], i);
3051   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
3052   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3053                                 operands[0], i);
3054 }")
3055
3056 (define_insn "*boolcsi3_internal1"
3057   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3058         (match_operator:SI 3 "boolean_operator"
3059          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3060           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
3061   ""
3062   "%q3 %0,%2,%1")
3063
3064 (define_insn "*boolcsi3_internal2"
3065   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3066         (compare:CC (match_operator:SI 4 "boolean_operator"
3067          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3068           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3069          (const_int 0)))
3070    (clobber (match_scratch:SI 3 "=r,r"))]
3071   "TARGET_32BIT"
3072   "@
3073    %q4. %3,%2,%1
3074    #"
3075   [(set_attr "type" "compare")
3076    (set_attr "length" "4,8")])
3077
3078 (define_split
3079   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3080         (compare:CC (match_operator:SI 4 "boolean_operator"
3081          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3082           (match_operand:SI 2 "gpc_reg_operand" "")])
3083          (const_int 0)))
3084    (clobber (match_scratch:SI 3 ""))]
3085   "TARGET_32BIT && reload_completed"
3086   [(set (match_dup 3) (match_dup 4))
3087    (set (match_dup 0)
3088         (compare:CC (match_dup 3)
3089                     (const_int 0)))]
3090   "")
3091
3092 (define_insn "*boolcsi3_internal3"
3093   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3094         (compare:CC (match_operator:SI 4 "boolean_operator"
3095          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3096           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3097          (const_int 0)))
3098    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3099         (match_dup 4))]
3100   "TARGET_32BIT"
3101   "@
3102    %q4. %0,%2,%1
3103    #"
3104   [(set_attr "type" "compare")
3105    (set_attr "length" "4,8")])
3106
3107 (define_split
3108   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3109         (compare:CC (match_operator:SI 4 "boolean_operator"
3110          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3111           (match_operand:SI 2 "gpc_reg_operand" "")])
3112          (const_int 0)))
3113    (set (match_operand:SI 0 "gpc_reg_operand" "")
3114         (match_dup 4))]
3115   "TARGET_32BIT && reload_completed"
3116   [(set (match_dup 0) (match_dup 4))
3117    (set (match_dup 3)
3118         (compare:CC (match_dup 0)
3119                     (const_int 0)))]
3120   "")
3121
3122 (define_insn "*boolccsi3_internal1"
3123   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3124         (match_operator:SI 3 "boolean_operator"
3125          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3126           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
3127   ""
3128   "%q3 %0,%1,%2")
3129
3130 (define_insn "*boolccsi3_internal2"
3131   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3132         (compare:CC (match_operator:SI 4 "boolean_operator"
3133          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3134           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3135          (const_int 0)))
3136    (clobber (match_scratch:SI 3 "=r,r"))]
3137   "TARGET_32BIT"
3138   "@
3139    %q4. %3,%1,%2
3140    #"
3141   [(set_attr "type" "compare")
3142    (set_attr "length" "4,8")])
3143
3144 (define_split
3145   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3146         (compare:CC (match_operator:SI 4 "boolean_operator"
3147          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3148           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3149          (const_int 0)))
3150    (clobber (match_scratch:SI 3 ""))]
3151   "TARGET_32BIT && reload_completed"
3152   [(set (match_dup 3) (match_dup 4))
3153    (set (match_dup 0)
3154         (compare:CC (match_dup 3)
3155                     (const_int 0)))]
3156   "")
3157
3158 (define_insn "*boolccsi3_internal3"
3159   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3160         (compare:CC (match_operator:SI 4 "boolean_operator"
3161          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3162           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3163          (const_int 0)))
3164    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3165         (match_dup 4))]
3166   "TARGET_32BIT"
3167   "@
3168    %q4. %0,%1,%2
3169    #"
3170   [(set_attr "type" "compare")
3171    (set_attr "length" "4,8")])
3172
3173 (define_split
3174   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3175         (compare:CC (match_operator:SI 4 "boolean_operator"
3176          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3177           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3178          (const_int 0)))
3179    (set (match_operand:SI 0 "gpc_reg_operand" "")
3180         (match_dup 4))]
3181   "TARGET_32BIT && reload_completed"
3182   [(set (match_dup 0) (match_dup 4))
3183    (set (match_dup 3)
3184         (compare:CC (match_dup 0)
3185                     (const_int 0)))]
3186   "")
3187
3188 ;; maskir insn.  We need four forms because things might be in arbitrary
3189 ;; orders.  Don't define forms that only set CR fields because these
3190 ;; would modify an input register.
3191
3192 (define_insn "*maskir_internal1"
3193   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3194         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3195                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3196                 (and:SI (match_dup 2)
3197                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
3198   "TARGET_POWER"
3199   "maskir %0,%3,%2")
3200
3201 (define_insn "*maskir_internal2"
3202   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3203         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3204                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3205                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3206                         (match_dup 2))))]
3207   "TARGET_POWER"
3208   "maskir %0,%3,%2")
3209
3210 (define_insn "*maskir_internal3"
3211   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3212         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
3213                         (match_operand:SI 3 "gpc_reg_operand" "r"))
3214                 (and:SI (not:SI (match_dup 2))
3215                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3216   "TARGET_POWER"
3217   "maskir %0,%3,%2")
3218
3219 (define_insn "*maskir_internal4"
3220   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3221         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3222                         (match_operand:SI 2 "gpc_reg_operand" "r"))
3223                 (and:SI (not:SI (match_dup 2))
3224                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3225   "TARGET_POWER"
3226   "maskir %0,%3,%2")
3227
3228 (define_insn "*maskir_internal5"
3229   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3230         (compare:CC
3231          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3232                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3233                  (and:SI (match_dup 2)
3234                          (match_operand:SI 3 "gpc_reg_operand" "r,r")))
3235          (const_int 0)))
3236    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3237         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3238                 (and:SI (match_dup 2) (match_dup 3))))]
3239   "TARGET_POWER"
3240   "@
3241    maskir. %0,%3,%2
3242    #"
3243   [(set_attr "type" "compare")
3244    (set_attr "length" "4,8")])
3245
3246 (define_split
3247   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3248         (compare:CC
3249          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3250                          (match_operand:SI 1 "gpc_reg_operand" ""))
3251                  (and:SI (match_dup 2)
3252                          (match_operand:SI 3 "gpc_reg_operand" "")))
3253          (const_int 0)))
3254    (set (match_operand:SI 0 "gpc_reg_operand" "")
3255         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3256                 (and:SI (match_dup 2) (match_dup 3))))]
3257   "TARGET_POWER && reload_completed"
3258   [(set (match_dup 0)
3259         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3260                 (and:SI (match_dup 2) (match_dup 3))))
3261    (set (match_dup 4)
3262         (compare:CC (match_dup 0)
3263                     (const_int 0)))]
3264   "")
3265
3266 (define_insn "*maskir_internal6"
3267   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3268         (compare:CC
3269          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3270                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3271                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
3272                          (match_dup 2)))
3273          (const_int 0)))
3274    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3275         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3276                 (and:SI (match_dup 3) (match_dup 2))))]
3277   "TARGET_POWER"
3278   "@
3279    maskir. %0,%3,%2
3280    #"
3281   [(set_attr "type" "compare")
3282    (set_attr "length" "4,8")])
3283
3284 (define_split
3285   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3286         (compare:CC
3287          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3288                          (match_operand:SI 1 "gpc_reg_operand" ""))
3289                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
3290                          (match_dup 2)))
3291          (const_int 0)))
3292    (set (match_operand:SI 0 "gpc_reg_operand" "")
3293         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3294                 (and:SI (match_dup 3) (match_dup 2))))]
3295   "TARGET_POWER && reload_completed"
3296   [(set (match_dup 0)
3297         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3298                 (and:SI (match_dup 3) (match_dup 2))))
3299    (set (match_dup 4)
3300         (compare:CC (match_dup 0)
3301                     (const_int 0)))]
3302   "")
3303
3304 (define_insn "*maskir_internal7"
3305   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3306         (compare:CC
3307          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r,r")
3308                          (match_operand:SI 3 "gpc_reg_operand" "r,r"))
3309                  (and:SI (not:SI (match_dup 2))
3310                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
3311          (const_int 0)))
3312    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3313         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3314                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3315   "TARGET_POWER"
3316   "@
3317    maskir. %0,%3,%2
3318    #"
3319   [(set_attr "type" "compare")
3320    (set_attr "length" "4,8")])
3321
3322 (define_split
3323   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3324         (compare:CC
3325          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "")
3326                          (match_operand:SI 3 "gpc_reg_operand" ""))
3327                  (and:SI (not:SI (match_dup 2))
3328                          (match_operand:SI 1 "gpc_reg_operand" "")))
3329          (const_int 0)))
3330    (set (match_operand:SI 0 "gpc_reg_operand" "")
3331         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3332                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3333   "TARGET_POWER && reload_completed"
3334   [(set (match_dup 0)
3335         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3336                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
3337    (set (match_dup 4)
3338         (compare:CC (match_dup 0)
3339                     (const_int 0)))]
3340   "")
3341
3342 (define_insn "*maskir_internal8"
3343   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3344         (compare:CC
3345          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
3346                          (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3347                  (and:SI (not:SI (match_dup 2))
3348                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
3349          (const_int 0)))
3350    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3351         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3352                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3353   "TARGET_POWER"
3354   "@
3355    maskir. %0,%3,%2
3356    #"
3357   [(set_attr "type" "compare")
3358    (set_attr "length" "4,8")])
3359
3360 (define_split
3361   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3362         (compare:CC
3363          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
3364                          (match_operand:SI 2 "gpc_reg_operand" ""))
3365                  (and:SI (not:SI (match_dup 2))
3366                          (match_operand:SI 1 "gpc_reg_operand" "")))
3367          (const_int 0)))
3368    (set (match_operand:SI 0 "gpc_reg_operand" "")
3369         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3370                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3371   "TARGET_POWER && reload_completed"
3372   [(set (match_dup 0)
3373         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3374                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
3375    (set (match_dup 4)
3376         (compare:CC (match_dup 0)
3377                     (const_int 0)))]
3378   "")
3379 \f
3380 ;; Rotate and shift insns, in all their variants.  These support shifts,
3381 ;; field inserts and extracts, and various combinations thereof.
3382 (define_expand "insv"
3383   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
3384                        (match_operand:SI 1 "const_int_operand" "")
3385                        (match_operand:SI 2 "const_int_operand" ""))
3386         (match_operand 3 "gpc_reg_operand" ""))]
3387   ""
3388   "
3389 {
3390   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3391      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3392      compiler if the address of the structure is taken later.  Likewise, do
3393      not handle invalid E500 subregs.  */
3394   if (GET_CODE (operands[0]) == SUBREG
3395       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD
3396           || ((TARGET_E500_DOUBLE || TARGET_SPE)
3397               && invalid_e500_subreg (operands[0], GET_MODE (operands[0])))))
3398     FAIL;
3399
3400   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
3401     emit_insn (gen_insvdi (operands[0], operands[1], operands[2], operands[3]));
3402   else
3403     emit_insn (gen_insvsi (operands[0], operands[1], operands[2], operands[3]));
3404   DONE;
3405 }")
3406
3407 (define_insn "insvsi"
3408   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3409                          (match_operand:SI 1 "const_int_operand" "i")
3410                          (match_operand:SI 2 "const_int_operand" "i"))
3411         (match_operand:SI 3 "gpc_reg_operand" "r"))]
3412   ""
3413   "*
3414 {
3415   int start = INTVAL (operands[2]) & 31;
3416   int size = INTVAL (operands[1]) & 31;
3417
3418   operands[4] = GEN_INT (32 - start - size);
3419   operands[1] = GEN_INT (start + size - 1);
3420   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3421 }"
3422   [(set_attr "type" "insert_word")])
3423
3424 (define_insn "*insvsi_internal1"
3425   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3426                          (match_operand:SI 1 "const_int_operand" "i")
3427                          (match_operand:SI 2 "const_int_operand" "i"))
3428         (rotate:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3429                    (match_operand:SI 4 "const_int_operand" "i")))]
3430   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3431   "*
3432 {
3433   int shift = INTVAL (operands[4]) & 31;
3434   int start = INTVAL (operands[2]) & 31;
3435   int size = INTVAL (operands[1]) & 31;
3436
3437   operands[4] = GEN_INT (shift - start - size);
3438   operands[1] = GEN_INT (start + size - 1);
3439   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3440 }"
3441   [(set_attr "type" "insert_word")])
3442
3443 (define_insn "*insvsi_internal2"
3444   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3445                          (match_operand:SI 1 "const_int_operand" "i")
3446                          (match_operand:SI 2 "const_int_operand" "i"))
3447         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3448                      (match_operand:SI 4 "const_int_operand" "i")))]
3449   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3450   "*
3451 {
3452   int shift = INTVAL (operands[4]) & 31;
3453   int start = INTVAL (operands[2]) & 31;
3454   int size = INTVAL (operands[1]) & 31;
3455
3456   operands[4] = GEN_INT (32 - shift - start - size);
3457   operands[1] = GEN_INT (start + size - 1);
3458   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3459 }"
3460   [(set_attr "type" "insert_word")])
3461
3462 (define_insn "*insvsi_internal3"
3463   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3464                          (match_operand:SI 1 "const_int_operand" "i")
3465                          (match_operand:SI 2 "const_int_operand" "i"))
3466         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3467                      (match_operand:SI 4 "const_int_operand" "i")))]
3468   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3469   "*
3470 {
3471   int shift = INTVAL (operands[4]) & 31;
3472   int start = INTVAL (operands[2]) & 31;
3473   int size = INTVAL (operands[1]) & 31;
3474
3475   operands[4] = GEN_INT (32 - shift - start - size);
3476   operands[1] = GEN_INT (start + size - 1);
3477   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3478 }"
3479   [(set_attr "type" "insert_word")])
3480
3481 (define_insn "*insvsi_internal4"
3482   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3483                          (match_operand:SI 1 "const_int_operand" "i")
3484                          (match_operand:SI 2 "const_int_operand" "i"))
3485         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3486                          (match_operand:SI 4 "const_int_operand" "i")
3487                          (match_operand:SI 5 "const_int_operand" "i")))]
3488   "INTVAL (operands[4]) >= INTVAL (operands[1])"
3489   "*
3490 {
3491   int extract_start = INTVAL (operands[5]) & 31;
3492   int extract_size = INTVAL (operands[4]) & 31;
3493   int insert_start = INTVAL (operands[2]) & 31;
3494   int insert_size = INTVAL (operands[1]) & 31;
3495
3496 /* Align extract field with insert field */
3497   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
3498   operands[1] = GEN_INT (insert_start + insert_size - 1);
3499   return \"{rlimi|rlwimi} %0,%3,%h5,%h2,%h1\";
3500 }"
3501   [(set_attr "type" "insert_word")])
3502
3503 ;; combine patterns for rlwimi
3504 (define_insn "*insvsi_internal5"
3505   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3506         (ior:SI (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3507                         (match_operand:SI 1 "mask_operand" "i"))
3508                 (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3509                                      (match_operand:SI 2 "const_int_operand" "i"))
3510                         (match_operand:SI 5 "mask_operand" "i"))))]
3511   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
3512   "*
3513 {
3514  int me = extract_ME(operands[5]);
3515  int mb = extract_MB(operands[5]);
3516  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3517  operands[2] = GEN_INT(mb);
3518  operands[1] = GEN_INT(me);
3519  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3520 }"
3521   [(set_attr "type" "insert_word")])
3522
3523 (define_insn "*insvsi_internal6"
3524   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3525         (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3526                                      (match_operand:SI 2 "const_int_operand" "i"))
3527                         (match_operand:SI 5 "mask_operand" "i"))
3528                 (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3529                         (match_operand:SI 1 "mask_operand" "i"))))]
3530   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
3531   "*
3532 {
3533  int me = extract_ME(operands[5]);
3534  int mb = extract_MB(operands[5]);
3535  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3536  operands[2] = GEN_INT(mb);
3537  operands[1] = GEN_INT(me);
3538  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3539 }"
3540   [(set_attr "type" "insert_word")])
3541
3542 (define_insn "insvdi"
3543   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3544                          (match_operand:SI 1 "const_int_operand" "i")
3545                          (match_operand:SI 2 "const_int_operand" "i"))
3546         (match_operand:DI 3 "gpc_reg_operand" "r"))]
3547   "TARGET_POWERPC64"
3548   "*
3549 {
3550   int start = INTVAL (operands[2]) & 63;
3551   int size = INTVAL (operands[1]) & 63;
3552
3553   operands[1] = GEN_INT (64 - start - size);
3554   return \"rldimi %0,%3,%H1,%H2\";
3555 }")
3556
3557 (define_insn "*insvdi_internal2"
3558   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3559                          (match_operand:SI 1 "const_int_operand" "i")
3560                          (match_operand:SI 2 "const_int_operand" "i"))
3561         (ashiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3562                      (match_operand:SI 4 "const_int_operand" "i")))]
3563   "TARGET_POWERPC64
3564    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3565   "*
3566 {
3567   int shift = INTVAL (operands[4]) & 63;
3568   int start = (INTVAL (operands[2]) & 63) - 32;
3569   int size = INTVAL (operands[1]) & 63;
3570
3571   operands[4] = GEN_INT (64 - shift - start - size);
3572   operands[2] = GEN_INT (start);
3573   operands[1] = GEN_INT (start + size - 1);
3574   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3575 }")
3576
3577 (define_insn "*insvdi_internal3"
3578   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3579                          (match_operand:SI 1 "const_int_operand" "i")
3580                          (match_operand:SI 2 "const_int_operand" "i"))
3581         (lshiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3582                      (match_operand:SI 4 "const_int_operand" "i")))]
3583   "TARGET_POWERPC64
3584    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3585   "*
3586 {
3587   int shift = INTVAL (operands[4]) & 63;
3588   int start = (INTVAL (operands[2]) & 63) - 32;
3589   int size = INTVAL (operands[1]) & 63;
3590
3591   operands[4] = GEN_INT (64 - shift - start - size);
3592   operands[2] = GEN_INT (start);
3593   operands[1] = GEN_INT (start + size - 1);
3594   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3595 }")
3596
3597 (define_expand "extzv"
3598   [(set (match_operand 0 "gpc_reg_operand" "")
3599         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3600                        (match_operand:SI 2 "const_int_operand" "")
3601                        (match_operand:SI 3 "const_int_operand" "")))]
3602   ""
3603   "
3604 {
3605   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3606      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3607      compiler if the address of the structure is taken later.  */
3608   if (GET_CODE (operands[0]) == SUBREG
3609       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3610     FAIL;
3611
3612   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3613     emit_insn (gen_extzvdi (operands[0], operands[1], operands[2], operands[3]));
3614   else
3615     emit_insn (gen_extzvsi (operands[0], operands[1], operands[2], operands[3]));
3616   DONE;
3617 }")
3618
3619 (define_insn "extzvsi"
3620   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3621         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3622                          (match_operand:SI 2 "const_int_operand" "i")
3623                          (match_operand:SI 3 "const_int_operand" "i")))]
3624   ""
3625   "*
3626 {
3627   int start = INTVAL (operands[3]) & 31;
3628   int size = INTVAL (operands[2]) & 31;
3629
3630   if (start + size >= 32)
3631     operands[3] = const0_rtx;
3632   else
3633     operands[3] = GEN_INT (start + size);
3634   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
3635 }")
3636
3637 (define_insn "*extzvsi_internal1"
3638   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3639         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3640                          (match_operand:SI 2 "const_int_operand" "i,i")
3641                          (match_operand:SI 3 "const_int_operand" "i,i"))
3642                     (const_int 0)))
3643    (clobber (match_scratch:SI 4 "=r,r"))]
3644   ""
3645   "*
3646 {
3647   int start = INTVAL (operands[3]) & 31;
3648   int size = INTVAL (operands[2]) & 31;
3649
3650   /* Force split for non-cc0 compare.  */
3651   if (which_alternative == 1)
3652      return \"#\";
3653
3654   /* If the bit-field being tested fits in the upper or lower half of a
3655      word, it is possible to use andiu. or andil. to test it.  This is
3656      useful because the condition register set-use delay is smaller for
3657      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3658      position is 0 because the LT and GT bits may be set wrong.  */
3659
3660   if ((start > 0 && start + size <= 16) || start >= 16)
3661     {
3662       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3663                               - (1 << (16 - (start & 15) - size))));
3664       if (start < 16)
3665         return \"{andiu.|andis.} %4,%1,%3\";
3666       else
3667         return \"{andil.|andi.} %4,%1,%3\";
3668     }
3669
3670   if (start + size >= 32)
3671     operands[3] = const0_rtx;
3672   else
3673     operands[3] = GEN_INT (start + size);
3674   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
3675 }"
3676   [(set_attr "type" "compare")
3677    (set_attr "length" "4,8")])
3678
3679 (define_split
3680   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3681         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3682                          (match_operand:SI 2 "const_int_operand" "")
3683                          (match_operand:SI 3 "const_int_operand" ""))
3684                     (const_int 0)))
3685    (clobber (match_scratch:SI 4 ""))]
3686   "reload_completed"
3687   [(set (match_dup 4)
3688         (zero_extract:SI (match_dup 1) (match_dup 2)
3689                          (match_dup 3)))
3690    (set (match_dup 0)
3691         (compare:CC (match_dup 4)
3692                     (const_int 0)))]
3693   "")
3694
3695 (define_insn "*extzvsi_internal2"
3696   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3697         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3698                          (match_operand:SI 2 "const_int_operand" "i,i")
3699                          (match_operand:SI 3 "const_int_operand" "i,i"))
3700                     (const_int 0)))
3701    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3702         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3703   ""
3704   "*
3705 {
3706   int start = INTVAL (operands[3]) & 31;
3707   int size = INTVAL (operands[2]) & 31;
3708
3709   /* Force split for non-cc0 compare.  */
3710   if (which_alternative == 1)
3711      return \"#\";
3712
3713   /* Since we are using the output value, we can't ignore any need for
3714      a shift.  The bit-field must end at the LSB.  */
3715   if (start >= 16 && start + size == 32)
3716     {
3717       operands[3] = GEN_INT ((1 << size) - 1);
3718       return \"{andil.|andi.} %0,%1,%3\";
3719     }
3720
3721   if (start + size >= 32)
3722     operands[3] = const0_rtx;
3723   else
3724     operands[3] = GEN_INT (start + size);
3725   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
3726 }"
3727   [(set_attr "type" "compare")
3728    (set_attr "length" "4,8")])
3729
3730 (define_split
3731   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3732         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3733                          (match_operand:SI 2 "const_int_operand" "")
3734                          (match_operand:SI 3 "const_int_operand" ""))
3735                     (const_int 0)))
3736    (set (match_operand:SI 0 "gpc_reg_operand" "")
3737         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3738   "reload_completed"
3739   [(set (match_dup 0)
3740         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3741    (set (match_dup 4)
3742         (compare:CC (match_dup 0)
3743                     (const_int 0)))]
3744   "")
3745
3746 (define_insn "extzvdi"
3747   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3748         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3749                          (match_operand:SI 2 "const_int_operand" "i")
3750                          (match_operand:SI 3 "const_int_operand" "i")))]
3751   "TARGET_POWERPC64"
3752   "*
3753 {
3754   int start = INTVAL (operands[3]) & 63;
3755   int size = INTVAL (operands[2]) & 63;
3756
3757   if (start + size >= 64)
3758     operands[3] = const0_rtx;
3759   else
3760     operands[3] = GEN_INT (start + size);
3761   operands[2] = GEN_INT (64 - size);
3762   return \"rldicl %0,%1,%3,%2\";
3763 }")
3764
3765 (define_insn "*extzvdi_internal1"
3766   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3767         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3768                          (match_operand:SI 2 "const_int_operand" "i")
3769                          (match_operand:SI 3 "const_int_operand" "i"))
3770                     (const_int 0)))
3771    (clobber (match_scratch:DI 4 "=r"))]
3772   "TARGET_64BIT"
3773   "*
3774 {
3775   int start = INTVAL (operands[3]) & 63;
3776   int size = INTVAL (operands[2]) & 63;
3777
3778   if (start + size >= 64)
3779     operands[3] = const0_rtx;
3780   else
3781     operands[3] = GEN_INT (start + size);
3782   operands[2] = GEN_INT (64 - size);
3783   return \"rldicl. %4,%1,%3,%2\";
3784 }"
3785   [(set_attr "type" "compare")])
3786
3787 (define_insn "*extzvdi_internal2"
3788   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3789         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3790                          (match_operand:SI 2 "const_int_operand" "i")
3791                          (match_operand:SI 3 "const_int_operand" "i"))
3792                     (const_int 0)))
3793    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3794         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3795   "TARGET_64BIT"
3796   "*
3797 {
3798   int start = INTVAL (operands[3]) & 63;
3799   int size = INTVAL (operands[2]) & 63;
3800
3801   if (start + size >= 64)
3802     operands[3] = const0_rtx;
3803   else
3804     operands[3] = GEN_INT (start + size);
3805   operands[2] = GEN_INT (64 - size);
3806   return \"rldicl. %0,%1,%3,%2\";
3807 }"
3808   [(set_attr "type" "compare")])
3809
3810 (define_insn "rotlsi3"
3811   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3812         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3813                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3814   ""
3815   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffffffff")
3816
3817 (define_insn "*rotlsi3_internal2"
3818   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3819         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3820                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3821                     (const_int 0)))
3822    (clobber (match_scratch:SI 3 "=r,r"))]
3823   ""
3824   "@
3825    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffffffff
3826    #"
3827   [(set_attr "type" "delayed_compare")
3828    (set_attr "length" "4,8")])
3829
3830 (define_split
3831   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3832         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3833                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3834                     (const_int 0)))
3835    (clobber (match_scratch:SI 3 ""))]
3836   "reload_completed"
3837   [(set (match_dup 3)
3838         (rotate:SI (match_dup 1) (match_dup 2)))
3839    (set (match_dup 0)
3840         (compare:CC (match_dup 3)
3841                     (const_int 0)))]
3842   "")
3843
3844 (define_insn "*rotlsi3_internal3"
3845   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3846         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3847                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3848                     (const_int 0)))
3849    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3850         (rotate:SI (match_dup 1) (match_dup 2)))]
3851   ""
3852   "@
3853    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffffffff
3854    #"
3855   [(set_attr "type" "delayed_compare")
3856    (set_attr "length" "4,8")])
3857
3858 (define_split
3859   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3860         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3861                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3862                     (const_int 0)))
3863    (set (match_operand:SI 0 "gpc_reg_operand" "")
3864         (rotate:SI (match_dup 1) (match_dup 2)))]
3865   "reload_completed"
3866   [(set (match_dup 0)
3867         (rotate:SI (match_dup 1) (match_dup 2)))
3868    (set (match_dup 3)
3869         (compare:CC (match_dup 0)
3870                     (const_int 0)))]
3871   "")
3872
3873 (define_insn "*rotlsi3_internal4"
3874   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3875         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3876                            (match_operand:SI 2 "reg_or_cint_operand" "ri"))
3877                 (match_operand:SI 3 "mask_operand" "n")))]
3878   ""
3879   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,%m3,%M3")
3880
3881 (define_insn "*rotlsi3_internal5"
3882   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3883         (compare:CC (and:SI
3884                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3885                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3886                      (match_operand:SI 3 "mask_operand" "n,n"))
3887                     (const_int 0)))
3888    (clobber (match_scratch:SI 4 "=r,r"))]
3889   ""
3890   "@
3891    {rl%I2nm.|rlw%I2nm.} %4,%1,%h2,%m3,%M3
3892    #"
3893   [(set_attr "type" "delayed_compare")
3894    (set_attr "length" "4,8")])
3895
3896 (define_split
3897   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3898         (compare:CC (and:SI
3899                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3900                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3901                      (match_operand:SI 3 "mask_operand" ""))
3902                     (const_int 0)))
3903    (clobber (match_scratch:SI 4 ""))]
3904   "reload_completed"
3905   [(set (match_dup 4)
3906         (and:SI (rotate:SI (match_dup 1)
3907                                 (match_dup 2))
3908                      (match_dup 3)))
3909    (set (match_dup 0)
3910         (compare:CC (match_dup 4)
3911                     (const_int 0)))]
3912   "")
3913
3914 (define_insn "*rotlsi3_internal6"
3915   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3916         (compare:CC (and:SI
3917                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3918                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3919                      (match_operand:SI 3 "mask_operand" "n,n"))
3920                     (const_int 0)))
3921    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3922         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3923   ""
3924   "@
3925    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,%m3,%M3
3926    #"
3927   [(set_attr "type" "delayed_compare")
3928    (set_attr "length" "4,8")])
3929
3930 (define_split
3931   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3932         (compare:CC (and:SI
3933                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3934                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3935                      (match_operand:SI 3 "mask_operand" ""))
3936                     (const_int 0)))
3937    (set (match_operand:SI 0 "gpc_reg_operand" "")
3938         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3939   "reload_completed"
3940   [(set (match_dup 0)
3941         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3942    (set (match_dup 4)
3943         (compare:CC (match_dup 0)
3944                     (const_int 0)))]
3945   "")
3946
3947 (define_insn "*rotlsi3_internal7"
3948   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3949         (zero_extend:SI
3950          (subreg:QI
3951           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3952                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3953   ""
3954   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff")
3955
3956 (define_insn "*rotlsi3_internal8"
3957   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3958         (compare:CC (zero_extend:SI
3959                      (subreg:QI
3960                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3961                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3962                     (const_int 0)))
3963    (clobber (match_scratch:SI 3 "=r,r"))]
3964   ""
3965   "@
3966    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xff
3967    #"
3968   [(set_attr "type" "delayed_compare")
3969    (set_attr "length" "4,8")])
3970
3971 (define_split
3972   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3973         (compare:CC (zero_extend:SI
3974                      (subreg:QI
3975                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3976                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3977                     (const_int 0)))
3978    (clobber (match_scratch:SI 3 ""))]
3979   "reload_completed"
3980   [(set (match_dup 3)
3981         (zero_extend:SI (subreg:QI
3982                       (rotate:SI (match_dup 1)
3983                                  (match_dup 2)) 0)))
3984    (set (match_dup 0)
3985         (compare:CC (match_dup 3)
3986                     (const_int 0)))]
3987   "")
3988
3989 (define_insn "*rotlsi3_internal9"
3990   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3991         (compare:CC (zero_extend:SI
3992                      (subreg:QI
3993                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3994                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3995                     (const_int 0)))
3996    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3997         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3998   ""
3999   "@
4000    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xff
4001    #"
4002   [(set_attr "type" "delayed_compare")
4003    (set_attr "length" "4,8")])
4004
4005 (define_split
4006   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4007         (compare:CC (zero_extend:SI
4008                      (subreg:QI
4009                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4010                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4011                     (const_int 0)))
4012    (set (match_operand:SI 0 "gpc_reg_operand" "")
4013         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4014   "reload_completed"
4015   [(set (match_dup 0)
4016         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4017    (set (match_dup 3)
4018         (compare:CC (match_dup 0)
4019                     (const_int 0)))]
4020   "")
4021
4022 (define_insn "*rotlsi3_internal10"
4023   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4024         (zero_extend:SI
4025          (subreg:HI
4026           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4027                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
4028   ""
4029   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffff")
4030
4031 (define_insn "*rotlsi3_internal11"
4032   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4033         (compare:CC (zero_extend:SI
4034                      (subreg:HI
4035                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4036                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
4037                     (const_int 0)))
4038    (clobber (match_scratch:SI 3 "=r,r"))]
4039   ""
4040   "@
4041    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffff
4042    #"
4043   [(set_attr "type" "delayed_compare")
4044    (set_attr "length" "4,8")])
4045
4046 (define_split
4047   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4048         (compare:CC (zero_extend:SI
4049                      (subreg:HI
4050                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4051                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4052                     (const_int 0)))
4053    (clobber (match_scratch:SI 3 ""))]
4054   "reload_completed"
4055   [(set (match_dup 3)
4056         (zero_extend:SI (subreg:HI
4057                       (rotate:SI (match_dup 1)
4058                                  (match_dup 2)) 0)))
4059    (set (match_dup 0)
4060         (compare:CC (match_dup 3)
4061                     (const_int 0)))]
4062   "")
4063
4064 (define_insn "*rotlsi3_internal12"
4065   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4066         (compare:CC (zero_extend:SI
4067                      (subreg:HI
4068                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4069                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
4070                     (const_int 0)))
4071    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4072         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4073   ""
4074   "@
4075    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffff
4076    #"
4077   [(set_attr "type" "delayed_compare")
4078    (set_attr "length" "4,8")])
4079
4080 (define_split
4081   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4082         (compare:CC (zero_extend:SI
4083                      (subreg:HI
4084                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4085                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4086                     (const_int 0)))
4087    (set (match_operand:SI 0 "gpc_reg_operand" "")
4088         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4089   "reload_completed"
4090   [(set (match_dup 0)
4091         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4092    (set (match_dup 3)
4093         (compare:CC (match_dup 0)
4094                     (const_int 0)))]
4095   "")
4096
4097 ;; Note that we use "sle." instead of "sl." so that we can set
4098 ;; SHIFT_COUNT_TRUNCATED.
4099
4100 (define_expand "ashlsi3"
4101   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
4102    (use (match_operand:SI 1 "gpc_reg_operand" ""))
4103    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
4104   ""
4105   "
4106 {
4107   if (TARGET_POWER)
4108     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
4109   else
4110     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
4111   DONE;
4112 }")
4113
4114 (define_insn "ashlsi3_power"
4115   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4116         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4117                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4118    (clobber (match_scratch:SI 3 "=q,X"))]
4119   "TARGET_POWER"
4120   "@
4121    sle %0,%1,%2
4122    {sli|slwi} %0,%1,%h2")
4123
4124 (define_insn "ashlsi3_no_power"
4125   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4126         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4127                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4128   "! TARGET_POWER"
4129   "{sl|slw}%I2 %0,%1,%h2")
4130
4131 (define_insn ""
4132   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4133         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4134                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4135                     (const_int 0)))
4136    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4137    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4138   "TARGET_POWER"
4139   "@
4140    sle. %3,%1,%2
4141    {sli.|slwi.} %3,%1,%h2
4142    #
4143    #"
4144   [(set_attr "type" "delayed_compare")
4145    (set_attr "length" "4,4,8,8")])
4146
4147 (define_split
4148   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4149         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4150                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4151                     (const_int 0)))
4152    (clobber (match_scratch:SI 3 ""))
4153    (clobber (match_scratch:SI 4 ""))]
4154   "TARGET_POWER && reload_completed"
4155   [(parallel [(set (match_dup 3)
4156         (ashift:SI (match_dup 1) (match_dup 2)))
4157    (clobber (match_dup 4))])
4158    (set (match_dup 0)
4159         (compare:CC (match_dup 3)
4160                     (const_int 0)))]
4161   "")
4162
4163 (define_insn ""
4164   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4165         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4166                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4167                     (const_int 0)))
4168    (clobber (match_scratch:SI 3 "=r,r"))]
4169   "! TARGET_POWER && TARGET_32BIT"
4170   "@
4171    {sl|slw}%I2. %3,%1,%h2
4172    #"
4173   [(set_attr "type" "delayed_compare")
4174    (set_attr "length" "4,8")])
4175
4176 (define_split
4177   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4178         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4179                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4180                     (const_int 0)))
4181    (clobber (match_scratch:SI 3 ""))]
4182   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4183   [(set (match_dup 3)
4184         (ashift:SI (match_dup 1) (match_dup 2)))
4185    (set (match_dup 0)
4186         (compare:CC (match_dup 3)
4187                     (const_int 0)))]
4188   "")
4189
4190 (define_insn ""
4191   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4192         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4193                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4194                     (const_int 0)))
4195    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4196         (ashift:SI (match_dup 1) (match_dup 2)))
4197    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4198   "TARGET_POWER"
4199   "@
4200    sle. %0,%1,%2
4201    {sli.|slwi.} %0,%1,%h2
4202    #
4203    #"
4204   [(set_attr "type" "delayed_compare")
4205    (set_attr "length" "4,4,8,8")])
4206
4207 (define_split
4208   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4209         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4210                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4211                     (const_int 0)))
4212    (set (match_operand:SI 0 "gpc_reg_operand" "")
4213         (ashift:SI (match_dup 1) (match_dup 2)))
4214    (clobber (match_scratch:SI 4 ""))]
4215   "TARGET_POWER && reload_completed"
4216   [(parallel [(set (match_dup 0)
4217         (ashift:SI (match_dup 1) (match_dup 2)))
4218    (clobber (match_dup 4))])
4219    (set (match_dup 3)
4220         (compare:CC (match_dup 0)
4221                     (const_int 0)))]
4222   "")
4223
4224 (define_insn ""
4225   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4226         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4227                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4228                     (const_int 0)))
4229    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4230         (ashift:SI (match_dup 1) (match_dup 2)))]
4231   "! TARGET_POWER && TARGET_32BIT"
4232   "@
4233    {sl|slw}%I2. %0,%1,%h2
4234    #"
4235   [(set_attr "type" "delayed_compare")
4236    (set_attr "length" "4,8")])
4237
4238 (define_split
4239   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4240         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4241                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4242                     (const_int 0)))
4243    (set (match_operand:SI 0 "gpc_reg_operand" "")
4244         (ashift:SI (match_dup 1) (match_dup 2)))]
4245   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4246   [(set (match_dup 0)
4247         (ashift:SI (match_dup 1) (match_dup 2)))
4248    (set (match_dup 3)
4249         (compare:CC (match_dup 0)
4250                     (const_int 0)))]
4251   "")
4252
4253 (define_insn "rlwinm"
4254   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4255         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4256                            (match_operand:SI 2 "const_int_operand" "i"))
4257                 (match_operand:SI 3 "mask_operand" "n")))]
4258   "includes_lshift_p (operands[2], operands[3])"
4259   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
4260
4261 (define_insn ""
4262   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4263         (compare:CC
4264          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4265                             (match_operand:SI 2 "const_int_operand" "i,i"))
4266                  (match_operand:SI 3 "mask_operand" "n,n"))
4267          (const_int 0)))
4268    (clobber (match_scratch:SI 4 "=r,r"))]
4269   "includes_lshift_p (operands[2], operands[3])"
4270   "@
4271    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
4272    #"
4273   [(set_attr "type" "delayed_compare")
4274    (set_attr "length" "4,8")])
4275
4276 (define_split
4277   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4278         (compare:CC
4279          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4280                             (match_operand:SI 2 "const_int_operand" ""))
4281                  (match_operand:SI 3 "mask_operand" ""))
4282          (const_int 0)))
4283    (clobber (match_scratch:SI 4 ""))]
4284   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4285   [(set (match_dup 4)
4286         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
4287                  (match_dup 3)))
4288    (set (match_dup 0)
4289         (compare:CC (match_dup 4)
4290                     (const_int 0)))]
4291   "")
4292
4293 (define_insn ""
4294   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4295         (compare:CC
4296          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4297                             (match_operand:SI 2 "const_int_operand" "i,i"))
4298                  (match_operand:SI 3 "mask_operand" "n,n"))
4299          (const_int 0)))
4300    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4301         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4302   "includes_lshift_p (operands[2], operands[3])"
4303   "@
4304    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
4305    #"
4306   [(set_attr "type" "delayed_compare")
4307    (set_attr "length" "4,8")])
4308
4309 (define_split
4310   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4311         (compare:CC
4312          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4313                             (match_operand:SI 2 "const_int_operand" ""))
4314                  (match_operand:SI 3 "mask_operand" ""))
4315          (const_int 0)))
4316    (set (match_operand:SI 0 "gpc_reg_operand" "")
4317         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4318   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4319   [(set (match_dup 0)
4320         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4321    (set (match_dup 4)
4322         (compare:CC (match_dup 0)
4323                     (const_int 0)))]
4324   "")
4325
4326 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
4327 ;; "sli x,x,0".
4328 (define_expand "lshrsi3"
4329   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
4330    (use (match_operand:SI 1 "gpc_reg_operand" ""))
4331    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
4332   ""
4333   "
4334 {
4335   if (TARGET_POWER)
4336     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
4337   else
4338     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
4339   DONE;
4340 }")
4341
4342 (define_insn "lshrsi3_power"
4343   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
4344         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
4345                      (match_operand:SI 2 "reg_or_cint_operand" "r,O,i")))
4346    (clobber (match_scratch:SI 3 "=q,X,X"))]
4347   "TARGET_POWER"
4348   "@
4349   sre %0,%1,%2
4350   mr %0,%1
4351   {s%A2i|s%A2wi} %0,%1,%h2")
4352
4353 (define_insn "lshrsi3_no_power"
4354   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4355         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4356                      (match_operand:SI 2 "reg_or_cint_operand" "O,ri")))]
4357   "! TARGET_POWER"
4358   "@
4359   mr %0,%1
4360   {sr|srw}%I2 %0,%1,%h2")
4361
4362 (define_insn ""
4363   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4364         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4365                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
4366                     (const_int 0)))
4367    (clobber (match_scratch:SI 3 "=r,X,r,r,X,r"))
4368    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
4369   "TARGET_POWER"
4370   "@
4371   sre. %3,%1,%2
4372   mr. %1,%1
4373   {s%A2i.|s%A2wi.} %3,%1,%h2
4374   #
4375   #
4376   #"
4377   [(set_attr "type" "delayed_compare")
4378    (set_attr "length" "4,4,4,8,8,8")])
4379
4380 (define_split
4381   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4382         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4383                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4384                     (const_int 0)))
4385    (clobber (match_scratch:SI 3 ""))
4386    (clobber (match_scratch:SI 4 ""))]
4387   "TARGET_POWER && reload_completed"
4388   [(parallel [(set (match_dup 3)
4389         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4390    (clobber (match_dup 4))])
4391    (set (match_dup 0)
4392         (compare:CC (match_dup 3)
4393                     (const_int 0)))]
4394   "")
4395
4396 (define_insn ""
4397   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4398         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4399                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
4400                     (const_int 0)))
4401    (clobber (match_scratch:SI 3 "=X,r,X,r"))]
4402   "! TARGET_POWER && TARGET_32BIT"
4403   "@
4404    mr. %1,%1
4405    {sr|srw}%I2. %3,%1,%h2
4406    #
4407    #"
4408   [(set_attr "type" "delayed_compare")
4409    (set_attr "length" "4,4,8,8")])
4410
4411 (define_split
4412   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4413         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4414                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4415                     (const_int 0)))
4416    (clobber (match_scratch:SI 3 ""))]
4417   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4418   [(set (match_dup 3)
4419         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4420    (set (match_dup 0)
4421         (compare:CC (match_dup 3)
4422                     (const_int 0)))]
4423   "")
4424
4425 (define_insn ""
4426   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4427         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4428                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
4429                     (const_int 0)))
4430    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
4431         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4432    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
4433   "TARGET_POWER"
4434   "@
4435   sre. %0,%1,%2
4436   mr. %0,%1
4437   {s%A2i.|s%A2wi.} %0,%1,%h2
4438   #
4439   #
4440   #"
4441   [(set_attr "type" "delayed_compare")
4442    (set_attr "length" "4,4,4,8,8,8")])
4443
4444 (define_split
4445   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4446         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4447                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4448                     (const_int 0)))
4449    (set (match_operand:SI 0 "gpc_reg_operand" "")
4450         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4451    (clobber (match_scratch:SI 4 ""))]
4452   "TARGET_POWER && reload_completed"
4453   [(parallel [(set (match_dup 0)
4454         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4455    (clobber (match_dup 4))])
4456    (set (match_dup 3)
4457         (compare:CC (match_dup 0)
4458                     (const_int 0)))]
4459   "")
4460
4461 (define_insn ""
4462   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4463         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4464                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
4465                     (const_int 0)))
4466    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4467         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4468   "! TARGET_POWER && TARGET_32BIT"
4469   "@
4470    mr. %0,%1
4471    {sr|srw}%I2. %0,%1,%h2
4472    #
4473    #"
4474   [(set_attr "type" "delayed_compare")
4475    (set_attr "length" "4,4,8,8")])
4476
4477 (define_split
4478   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4479         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4480                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4481                     (const_int 0)))
4482    (set (match_operand:SI 0 "gpc_reg_operand" "")
4483         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4484   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4485   [(set (match_dup 0)
4486         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4487    (set (match_dup 3)
4488         (compare:CC (match_dup 0)
4489                     (const_int 0)))]
4490   "")
4491
4492 (define_insn ""
4493   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4494         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4495                              (match_operand:SI 2 "const_int_operand" "i"))
4496                 (match_operand:SI 3 "mask_operand" "n")))]
4497   "includes_rshift_p (operands[2], operands[3])"
4498   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
4499
4500 (define_insn ""
4501   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4502         (compare:CC
4503          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4504                               (match_operand:SI 2 "const_int_operand" "i,i"))
4505                  (match_operand:SI 3 "mask_operand" "n,n"))
4506          (const_int 0)))
4507    (clobber (match_scratch:SI 4 "=r,r"))]
4508   "includes_rshift_p (operands[2], operands[3])"
4509   "@
4510    {rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3
4511    #"
4512   [(set_attr "type" "delayed_compare")
4513    (set_attr "length" "4,8")])
4514
4515 (define_split
4516   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4517         (compare:CC
4518          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4519                               (match_operand:SI 2 "const_int_operand" ""))
4520                  (match_operand:SI 3 "mask_operand" ""))
4521          (const_int 0)))
4522    (clobber (match_scratch:SI 4 ""))]
4523   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4524   [(set (match_dup 4)
4525         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
4526                  (match_dup 3)))
4527    (set (match_dup 0)
4528         (compare:CC (match_dup 4)
4529                     (const_int 0)))]
4530   "")
4531
4532 (define_insn ""
4533   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4534         (compare:CC
4535          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4536                               (match_operand:SI 2 "const_int_operand" "i,i"))
4537                  (match_operand:SI 3 "mask_operand" "n,n"))
4538          (const_int 0)))
4539    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4540         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4541   "includes_rshift_p (operands[2], operands[3])"
4542   "@
4543    {rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3
4544    #"
4545   [(set_attr "type" "delayed_compare")
4546    (set_attr "length" "4,8")])
4547
4548 (define_split
4549   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4550         (compare:CC
4551          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4552                               (match_operand:SI 2 "const_int_operand" ""))
4553                  (match_operand:SI 3 "mask_operand" ""))
4554          (const_int 0)))
4555    (set (match_operand:SI 0 "gpc_reg_operand" "")
4556         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4557   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4558   [(set (match_dup 0)
4559         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4560    (set (match_dup 4)
4561         (compare:CC (match_dup 0)
4562                     (const_int 0)))]
4563   "")
4564
4565 (define_insn ""
4566   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4567         (zero_extend:SI
4568          (subreg:QI
4569           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4570                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4571   "includes_rshift_p (operands[2], GEN_INT (255))"
4572   "{rlinm|rlwinm} %0,%1,%s2,0xff")
4573
4574 (define_insn ""
4575   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4576         (compare:CC
4577          (zero_extend:SI
4578           (subreg:QI
4579            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4580                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4581          (const_int 0)))
4582    (clobber (match_scratch:SI 3 "=r,r"))]
4583   "includes_rshift_p (operands[2], GEN_INT (255))"
4584   "@
4585    {rlinm.|rlwinm.} %3,%1,%s2,0xff
4586    #"
4587   [(set_attr "type" "delayed_compare")
4588    (set_attr "length" "4,8")])
4589
4590 (define_split
4591   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4592         (compare:CC
4593          (zero_extend:SI
4594           (subreg:QI
4595            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4596                         (match_operand:SI 2 "const_int_operand" "")) 0))
4597          (const_int 0)))
4598    (clobber (match_scratch:SI 3 ""))]
4599   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4600   [(set (match_dup 3)
4601         (zero_extend:SI (subreg:QI
4602            (lshiftrt:SI (match_dup 1)
4603                         (match_dup 2)) 0)))
4604    (set (match_dup 0)
4605         (compare:CC (match_dup 3)
4606                     (const_int 0)))]
4607   "")
4608
4609 (define_insn ""
4610   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4611         (compare:CC
4612          (zero_extend:SI
4613           (subreg:QI
4614            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4615                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4616          (const_int 0)))
4617    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4618         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4619   "includes_rshift_p (operands[2], GEN_INT (255))"
4620   "@
4621    {rlinm.|rlwinm.} %0,%1,%s2,0xff
4622    #"
4623   [(set_attr "type" "delayed_compare")
4624    (set_attr "length" "4,8")])
4625
4626 (define_split
4627   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4628         (compare:CC
4629          (zero_extend:SI
4630           (subreg:QI
4631            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4632                         (match_operand:SI 2 "const_int_operand" "")) 0))
4633          (const_int 0)))
4634    (set (match_operand:SI 0 "gpc_reg_operand" "")
4635         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4636   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4637   [(set (match_dup 0)
4638         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4639    (set (match_dup 3)
4640         (compare:CC (match_dup 0)
4641                     (const_int 0)))]
4642   "")
4643
4644 (define_insn ""
4645   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4646         (zero_extend:SI
4647          (subreg:HI
4648           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4649                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4650   "includes_rshift_p (operands[2], GEN_INT (65535))"
4651   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
4652
4653 (define_insn ""
4654   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4655         (compare:CC
4656          (zero_extend:SI
4657           (subreg:HI
4658            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4659                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4660          (const_int 0)))
4661    (clobber (match_scratch:SI 3 "=r,r"))]
4662   "includes_rshift_p (operands[2], GEN_INT (65535))"
4663   "@
4664    {rlinm.|rlwinm.} %3,%1,%s2,0xffff
4665    #"
4666   [(set_attr "type" "delayed_compare")
4667    (set_attr "length" "4,8")])
4668
4669 (define_split
4670   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4671         (compare:CC
4672          (zero_extend:SI
4673           (subreg:HI
4674            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4675                         (match_operand:SI 2 "const_int_operand" "")) 0))
4676          (const_int 0)))
4677    (clobber (match_scratch:SI 3 ""))]
4678   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4679   [(set (match_dup 3)
4680         (zero_extend:SI (subreg:HI
4681            (lshiftrt:SI (match_dup 1)
4682                         (match_dup 2)) 0)))
4683    (set (match_dup 0)
4684         (compare:CC (match_dup 3)
4685                     (const_int 0)))]
4686   "")
4687
4688 (define_insn ""
4689   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4690         (compare:CC
4691          (zero_extend:SI
4692           (subreg:HI
4693            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4694                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4695          (const_int 0)))
4696    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4697         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4698   "includes_rshift_p (operands[2], GEN_INT (65535))"
4699   "@
4700    {rlinm.|rlwinm.} %0,%1,%s2,0xffff
4701    #"
4702   [(set_attr "type" "delayed_compare")
4703    (set_attr "length" "4,8")])
4704
4705 (define_split
4706   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4707         (compare:CC
4708          (zero_extend:SI
4709           (subreg:HI
4710            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4711                         (match_operand:SI 2 "const_int_operand" "")) 0))
4712          (const_int 0)))
4713    (set (match_operand:SI 0 "gpc_reg_operand" "")
4714         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4715   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4716   [(set (match_dup 0)
4717         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4718    (set (match_dup 3)
4719         (compare:CC (match_dup 0)
4720                     (const_int 0)))]
4721   "")
4722
4723 (define_insn ""
4724   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4725                          (const_int 1)
4726                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4727         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4728                      (const_int 31)))]
4729   "TARGET_POWER"
4730   "rrib %0,%1,%2")
4731
4732 (define_insn ""
4733   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4734                          (const_int 1)
4735                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4736         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4737                      (const_int 31)))]
4738   "TARGET_POWER"
4739   "rrib %0,%1,%2")
4740
4741 (define_insn ""
4742   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4743                          (const_int 1)
4744                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4745         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4746                          (const_int 1)
4747                          (const_int 0)))]
4748   "TARGET_POWER"
4749   "rrib %0,%1,%2")
4750
4751 (define_expand "ashrsi3"
4752   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4753         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4754                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
4755   ""
4756   "
4757 {
4758   if (TARGET_POWER)
4759     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
4760   else
4761     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
4762   DONE;
4763 }")
4764
4765 (define_insn "ashrsi3_power"
4766   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4767         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4768                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4769    (clobber (match_scratch:SI 3 "=q,X"))]
4770   "TARGET_POWER"
4771   "@
4772    srea %0,%1,%2
4773    {srai|srawi} %0,%1,%h2")
4774
4775 (define_insn "ashrsi3_no_power"
4776   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4777         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4778                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4779   "! TARGET_POWER"
4780   "{sra|sraw}%I2 %0,%1,%h2")
4781
4782 (define_insn ""
4783   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4784         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4785                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4786                     (const_int 0)))
4787    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4788    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4789   "TARGET_POWER"
4790   "@
4791    srea. %3,%1,%2
4792    {srai.|srawi.} %3,%1,%h2
4793    #
4794    #"
4795   [(set_attr "type" "delayed_compare")
4796    (set_attr "length" "4,4,8,8")])
4797
4798 (define_split
4799   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4800         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4801                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4802                     (const_int 0)))
4803    (clobber (match_scratch:SI 3 ""))
4804    (clobber (match_scratch:SI 4 ""))]
4805   "TARGET_POWER && reload_completed"
4806   [(parallel [(set (match_dup 3)
4807         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4808    (clobber (match_dup 4))])
4809    (set (match_dup 0)
4810         (compare:CC (match_dup 3)
4811                     (const_int 0)))]
4812   "")
4813
4814 (define_insn ""
4815   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4816         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4817                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4818                     (const_int 0)))
4819    (clobber (match_scratch:SI 3 "=r,r"))]
4820   "! TARGET_POWER"
4821   "@
4822    {sra|sraw}%I2. %3,%1,%h2
4823    #"
4824   [(set_attr "type" "delayed_compare")
4825    (set_attr "length" "4,8")])
4826
4827 (define_split
4828   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4829         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4830                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4831                     (const_int 0)))
4832    (clobber (match_scratch:SI 3 ""))]
4833   "! TARGET_POWER && reload_completed"
4834   [(set (match_dup 3)
4835         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4836    (set (match_dup 0)
4837         (compare:CC (match_dup 3)
4838                     (const_int 0)))]
4839   "")
4840
4841 (define_insn ""
4842   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4843         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4844                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4845                     (const_int 0)))
4846    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4847         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4848    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4849   "TARGET_POWER"
4850   "@
4851    srea. %0,%1,%2
4852    {srai.|srawi.} %0,%1,%h2
4853    #
4854    #"
4855   [(set_attr "type" "delayed_compare")
4856    (set_attr "length" "4,4,8,8")])
4857
4858 (define_split
4859   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4860         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4861                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4862                     (const_int 0)))
4863    (set (match_operand:SI 0 "gpc_reg_operand" "")
4864         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4865    (clobber (match_scratch:SI 4 ""))]
4866   "TARGET_POWER && reload_completed"
4867   [(parallel [(set (match_dup 0)
4868         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4869    (clobber (match_dup 4))])
4870    (set (match_dup 3)
4871         (compare:CC (match_dup 0)
4872                     (const_int 0)))]
4873   "")
4874
4875 (define_insn ""
4876   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4877         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4878                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4879                     (const_int 0)))
4880    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4881         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4882   "! TARGET_POWER"
4883   "@
4884    {sra|sraw}%I2. %0,%1,%h2
4885    #"
4886   [(set_attr "type" "delayed_compare")
4887    (set_attr "length" "4,8")])
4888 \f
4889 (define_split
4890   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4891         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4892                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4893                     (const_int 0)))
4894    (set (match_operand:SI 0 "gpc_reg_operand" "")
4895         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4896   "! TARGET_POWER && reload_completed"
4897   [(set (match_dup 0)
4898         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4899    (set (match_dup 3)
4900         (compare:CC (match_dup 0)
4901                     (const_int 0)))]
4902   "")
4903
4904 ;; Floating-point insns, excluding normal data motion.
4905 ;;
4906 ;; PowerPC has a full set of single-precision floating point instructions.
4907 ;;
4908 ;; For the POWER architecture, we pretend that we have both SFmode and
4909 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
4910 ;; The only conversions we will do will be when storing to memory.  In that
4911 ;; case, we will use the "frsp" instruction before storing.
4912 ;;
4913 ;; Note that when we store into a single-precision memory location, we need to
4914 ;; use the frsp insn first.  If the register being stored isn't dead, we
4915 ;; need a scratch register for the frsp.  But this is difficult when the store
4916 ;; is done by reload.  It is not incorrect to do the frsp on the register in
4917 ;; this case, we just lose precision that we would have otherwise gotten but
4918 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
4919
4920 (define_expand "extendsfdf2"
4921   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4922         (float_extend:DF (match_operand:SF 1 "reg_or_none500mem_operand" "")))]
4923   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4924   "")
4925
4926 (define_insn_and_split "*extendsfdf2_fpr"
4927   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,?f,f")
4928         (float_extend:DF (match_operand:SF 1 "reg_or_mem_operand" "0,f,m")))]
4929   "TARGET_HARD_FLOAT && TARGET_FPRS"
4930   "@
4931    #
4932    fmr %0,%1
4933    lfs%U1%X1 %0,%1"
4934   "&& reload_completed && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])"
4935   [(const_int 0)]
4936 {
4937   emit_note (NOTE_INSN_DELETED);
4938   DONE;
4939 }
4940   [(set_attr "type" "fp,fp,fpload")])
4941
4942 (define_expand "truncdfsf2"
4943   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4944         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "")))]
4945   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4946   "")
4947
4948 (define_insn "*truncdfsf2_fpr"
4949   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4950         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4951   "TARGET_HARD_FLOAT && TARGET_FPRS"
4952   "frsp %0,%1"
4953   [(set_attr "type" "fp")])
4954
4955 (define_insn "aux_truncdfsf2"
4956   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4957         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRSP))]
4958   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4959   "frsp %0,%1"
4960   [(set_attr "type" "fp")])
4961
4962 (define_expand "negsf2"
4963   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4964         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4965   "TARGET_HARD_FLOAT"
4966   "")
4967
4968 (define_insn "*negsf2"
4969   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4970         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4971   "TARGET_HARD_FLOAT && TARGET_FPRS"
4972   "fneg %0,%1"
4973   [(set_attr "type" "fp")])
4974
4975 (define_expand "abssf2"
4976   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4977         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4978   "TARGET_HARD_FLOAT"
4979   "")
4980
4981 (define_insn "*abssf2"
4982   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4983         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4984   "TARGET_HARD_FLOAT && TARGET_FPRS"
4985   "fabs %0,%1"
4986   [(set_attr "type" "fp")])
4987
4988 (define_insn ""
4989   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4990         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
4991   "TARGET_HARD_FLOAT && TARGET_FPRS"
4992   "fnabs %0,%1"
4993   [(set_attr "type" "fp")])
4994
4995 (define_expand "addsf3"
4996   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4997         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4998                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4999   "TARGET_HARD_FLOAT"
5000   "")
5001
5002 (define_insn ""
5003   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5004         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5005                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5006   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5007   "fadds %0,%1,%2"
5008   [(set_attr "type" "fp")])
5009
5010 (define_insn ""
5011   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5012         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5013                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5014   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5015   "{fa|fadd} %0,%1,%2"
5016   [(set_attr "type" "fp")])
5017
5018 (define_expand "subsf3"
5019   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5020         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
5021                   (match_operand:SF 2 "gpc_reg_operand" "")))]
5022   "TARGET_HARD_FLOAT"
5023   "")
5024
5025 (define_insn ""
5026   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5027         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5028                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
5029   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5030   "fsubs %0,%1,%2"
5031   [(set_attr "type" "fp")])
5032
5033 (define_insn ""
5034   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5035         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5036                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
5037   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5038   "{fs|fsub} %0,%1,%2"
5039   [(set_attr "type" "fp")])
5040
5041 (define_expand "mulsf3"
5042   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5043         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
5044                  (match_operand:SF 2 "gpc_reg_operand" "")))]
5045   "TARGET_HARD_FLOAT"
5046   "")
5047
5048 (define_insn ""
5049   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5050         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5051                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5052   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5053   "fmuls %0,%1,%2"
5054   [(set_attr "type" "fp")])
5055
5056 (define_insn ""
5057   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5058         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5059                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5060   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5061   "{fm|fmul} %0,%1,%2"
5062   [(set_attr "type" "dmul")])
5063
5064 (define_insn "fres"
5065   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5066         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
5067   "TARGET_PPC_GFXOPT && flag_finite_math_only"
5068   "fres %0,%1"
5069   [(set_attr "type" "fp")])
5070
5071 (define_expand "divsf3"
5072   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5073         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
5074                 (match_operand:SF 2 "gpc_reg_operand" "")))]
5075   "TARGET_HARD_FLOAT"
5076 {
5077   if (swdiv && !optimize_size && TARGET_PPC_GFXOPT
5078   && flag_finite_math_only && !flag_trapping_math)
5079     {
5080       rs6000_emit_swdivsf (operands[0], operands[1], operands[2]);
5081       DONE;
5082     }
5083 })
5084
5085 (define_insn ""
5086   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5087         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5088                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5089   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5090   "fdivs %0,%1,%2"
5091   [(set_attr "type" "sdiv")])
5092
5093 (define_insn ""
5094   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5095         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5096                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5097   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5098   "{fd|fdiv} %0,%1,%2"
5099   [(set_attr "type" "ddiv")])
5100
5101 (define_insn ""
5102   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5103         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5104                           (match_operand:SF 2 "gpc_reg_operand" "f"))
5105                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
5106   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5107   "fmadds %0,%1,%2,%3"
5108   [(set_attr "type" "fp")])
5109
5110 (define_insn ""
5111   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5112         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5113                           (match_operand:SF 2 "gpc_reg_operand" "f"))
5114                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
5115   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5116   "{fma|fmadd} %0,%1,%2,%3"
5117   [(set_attr "type" "dmul")])
5118
5119 (define_insn ""
5120   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5121         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5122                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5123                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
5124   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5125   "fmsubs %0,%1,%2,%3"
5126   [(set_attr "type" "fp")])
5127
5128 (define_insn ""
5129   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5130         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5131                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5132                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
5133   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5134   "{fms|fmsub} %0,%1,%2,%3"
5135   [(set_attr "type" "dmul")])
5136
5137 (define_insn ""
5138   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5139         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5140                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
5141                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5142   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5143    && HONOR_SIGNED_ZEROS (SFmode)"
5144   "fnmadds %0,%1,%2,%3"
5145   [(set_attr "type" "fp")])
5146
5147 (define_insn ""
5148   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5149         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
5150                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5151                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5152   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5153    && ! HONOR_SIGNED_ZEROS (SFmode)"
5154   "fnmadds %0,%1,%2,%3"
5155   [(set_attr "type" "fp")])
5156
5157 (define_insn ""
5158   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5159         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5160                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
5161                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5162   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5163   "{fnma|fnmadd} %0,%1,%2,%3"
5164   [(set_attr "type" "dmul")])
5165
5166 (define_insn ""
5167   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5168         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
5169                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5170                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5171   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5172    && ! HONOR_SIGNED_ZEROS (SFmode)"
5173   "{fnma|fnmadd} %0,%1,%2,%3"
5174   [(set_attr "type" "dmul")])
5175
5176 (define_insn ""
5177   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5178         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5179                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
5180                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5181   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5182    && HONOR_SIGNED_ZEROS (SFmode)"
5183   "fnmsubs %0,%1,%2,%3"
5184   [(set_attr "type" "fp")])
5185
5186 (define_insn ""
5187   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5188         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
5189                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5190                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
5191   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5192    && ! HONOR_SIGNED_ZEROS (SFmode)"
5193   "fnmsubs %0,%1,%2,%3"
5194   [(set_attr "type" "fp")])
5195
5196 (define_insn ""
5197   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5198         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5199                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
5200                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5201   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5202   "{fnms|fnmsub} %0,%1,%2,%3"
5203   [(set_attr "type" "dmul")])
5204
5205 (define_insn ""
5206   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5207         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
5208                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5209                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
5210   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5211    && ! HONOR_SIGNED_ZEROS (SFmode)"
5212   "{fnms|fnmsub} %0,%1,%2,%3"
5213   [(set_attr "type" "dmul")])
5214
5215 (define_expand "sqrtsf2"
5216   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5217         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5218   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
5219   "")
5220
5221 (define_insn ""
5222   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5223         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5224   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5225   "fsqrts %0,%1"
5226   [(set_attr "type" "ssqrt")])
5227
5228 (define_insn ""
5229   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5230         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5231   "TARGET_POWER2 && TARGET_HARD_FLOAT && TARGET_FPRS"
5232   "fsqrt %0,%1"
5233   [(set_attr "type" "dsqrt")])
5234
5235 (define_expand "copysignsf3"
5236   [(set (match_dup 3)
5237         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))
5238    (set (match_dup 4)
5239         (neg:SF (abs:SF (match_dup 1))))
5240    (set (match_operand:SF 0 "gpc_reg_operand" "")
5241         (if_then_else:SF (ge (match_operand:SF 2 "gpc_reg_operand" "")
5242                              (match_dup 5))
5243                          (match_dup 3)
5244                          (match_dup 4)))]
5245   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS
5246    && !HONOR_NANS (SFmode) && !HONOR_SIGNED_ZEROS (SFmode)"
5247   {
5248      operands[3] = gen_reg_rtx (SFmode);
5249      operands[4] = gen_reg_rtx (SFmode);
5250      operands[5] = CONST0_RTX (SFmode);
5251   })
5252
5253 (define_expand "copysigndf3"
5254   [(set (match_dup 3)
5255         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))
5256    (set (match_dup 4)
5257         (neg:DF (abs:DF (match_dup 1))))
5258    (set (match_operand:DF 0 "gpc_reg_operand" "")
5259         (if_then_else:DF (ge (match_operand:DF 2 "gpc_reg_operand" "")
5260                              (match_dup 5))
5261                          (match_dup 3)
5262                          (match_dup 4)))]
5263   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS
5264    && !HONOR_NANS (DFmode) && !HONOR_SIGNED_ZEROS (DFmode)"
5265   {
5266      operands[3] = gen_reg_rtx (DFmode);
5267      operands[4] = gen_reg_rtx (DFmode);
5268      operands[5] = CONST0_RTX (DFmode);
5269   })
5270
5271 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
5272 ;; fsel instruction and some auxiliary computations.  Then we just have a
5273 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
5274 ;; combine.
5275 (define_expand "smaxsf3"
5276   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5277         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
5278                              (match_operand:SF 2 "gpc_reg_operand" ""))
5279                          (match_dup 1)
5280                          (match_dup 2)))]
5281   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5282   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
5283
5284 (define_expand "sminsf3"
5285   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5286         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
5287                              (match_operand:SF 2 "gpc_reg_operand" ""))
5288                          (match_dup 2)
5289                          (match_dup 1)))]
5290   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5291   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
5292
5293 (define_split
5294   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5295         (match_operator:SF 3 "min_max_operator"
5296          [(match_operand:SF 1 "gpc_reg_operand" "")
5297           (match_operand:SF 2 "gpc_reg_operand" "")]))]
5298   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5299   [(const_int 0)]
5300   "
5301 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5302                       operands[1], operands[2]);
5303   DONE;
5304 }")
5305
5306 (define_expand "movsicc"
5307    [(set (match_operand:SI 0 "gpc_reg_operand" "")
5308          (if_then_else:SI (match_operand 1 "comparison_operator" "")
5309                           (match_operand:SI 2 "gpc_reg_operand" "")
5310                           (match_operand:SI 3 "gpc_reg_operand" "")))]
5311   "TARGET_ISEL"
5312   "
5313 {
5314   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5315     DONE;
5316   else
5317     FAIL;
5318 }")
5319
5320 ;; We use the BASE_REGS for the isel input operands because, if rA is
5321 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
5322 ;; because we may switch the operands and rB may end up being rA.
5323 ;;
5324 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
5325 ;; leave out the mode in operand 4 and use one pattern, but reload can
5326 ;; change the mode underneath our feet and then gets confused trying
5327 ;; to reload the value.
5328 (define_insn "isel_signed"
5329   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5330         (if_then_else:SI
5331          (match_operator 1 "comparison_operator"
5332                          [(match_operand:CC 4 "cc_reg_operand" "y")
5333                           (const_int 0)])
5334          (match_operand:SI 2 "gpc_reg_operand" "b")
5335          (match_operand:SI 3 "gpc_reg_operand" "b")))]
5336   "TARGET_ISEL"
5337   "*
5338 { return output_isel (operands); }"
5339   [(set_attr "length" "4")])
5340
5341 (define_insn "isel_unsigned"
5342   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5343         (if_then_else:SI
5344          (match_operator 1 "comparison_operator"
5345                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
5346                           (const_int 0)])
5347          (match_operand:SI 2 "gpc_reg_operand" "b")
5348          (match_operand:SI 3 "gpc_reg_operand" "b")))]
5349   "TARGET_ISEL"
5350   "*
5351 { return output_isel (operands); }"
5352   [(set_attr "length" "4")])
5353
5354 (define_expand "movsfcc"
5355    [(set (match_operand:SF 0 "gpc_reg_operand" "")
5356          (if_then_else:SF (match_operand 1 "comparison_operator" "")
5357                           (match_operand:SF 2 "gpc_reg_operand" "")
5358                           (match_operand:SF 3 "gpc_reg_operand" "")))]
5359   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5360   "
5361 {
5362   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5363     DONE;
5364   else
5365     FAIL;
5366 }")
5367
5368 (define_insn "*fselsfsf4"
5369   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5370         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5371                              (match_operand:SF 4 "zero_fp_constant" "F"))
5372                          (match_operand:SF 2 "gpc_reg_operand" "f")
5373                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5374   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5375   "fsel %0,%1,%2,%3"
5376   [(set_attr "type" "fp")])
5377
5378 (define_insn "*fseldfsf4"
5379   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5380         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
5381                              (match_operand:DF 4 "zero_fp_constant" "F"))
5382                          (match_operand:SF 2 "gpc_reg_operand" "f")
5383                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5384   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5385   "fsel %0,%1,%2,%3"
5386   [(set_attr "type" "fp")])
5387
5388 (define_expand "negdf2"
5389   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5390         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
5391   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5392   "")
5393
5394 (define_insn "*negdf2_fpr"
5395   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5396         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5397   "TARGET_HARD_FLOAT && TARGET_FPRS"
5398   "fneg %0,%1"
5399   [(set_attr "type" "fp")])
5400
5401 (define_expand "absdf2"
5402   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5403         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
5404   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5405   "")
5406
5407 (define_insn "*absdf2_fpr"
5408   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5409         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5410   "TARGET_HARD_FLOAT && TARGET_FPRS"
5411   "fabs %0,%1"
5412   [(set_attr "type" "fp")])
5413
5414 (define_insn "*nabsdf2_fpr"
5415   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5416         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f"))))]
5417   "TARGET_HARD_FLOAT && TARGET_FPRS"
5418   "fnabs %0,%1"
5419   [(set_attr "type" "fp")])
5420
5421 (define_expand "adddf3"
5422   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5423         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "")
5424                  (match_operand:DF 2 "gpc_reg_operand" "")))]
5425   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5426   "")
5427
5428 (define_insn "*adddf3_fpr"
5429   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5430         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5431                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
5432   "TARGET_HARD_FLOAT && TARGET_FPRS"
5433   "{fa|fadd} %0,%1,%2"
5434   [(set_attr "type" "fp")])
5435
5436 (define_expand "subdf3"
5437   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5438         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "")
5439                   (match_operand:DF 2 "gpc_reg_operand" "")))]
5440   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5441   "")
5442
5443 (define_insn "*subdf3_fpr"
5444   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5445         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5446                   (match_operand:DF 2 "gpc_reg_operand" "f")))]
5447   "TARGET_HARD_FLOAT && TARGET_FPRS"
5448   "{fs|fsub} %0,%1,%2"
5449   [(set_attr "type" "fp")])
5450
5451 (define_expand "muldf3"
5452   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5453         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "")
5454                  (match_operand:DF 2 "gpc_reg_operand" "")))]
5455   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5456   "")
5457
5458 (define_insn "*muldf3_fpr"
5459   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5460         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5461                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
5462   "TARGET_HARD_FLOAT && TARGET_FPRS"
5463   "{fm|fmul} %0,%1,%2"
5464   [(set_attr "type" "dmul")])
5465
5466 (define_insn "fred"
5467   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5468         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
5469   "TARGET_POPCNTB && flag_finite_math_only"
5470   "fre %0,%1"
5471   [(set_attr "type" "fp")])
5472
5473 (define_expand "divdf3"
5474   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5475         (div:DF (match_operand:DF 1 "gpc_reg_operand" "")
5476                 (match_operand:DF 2 "gpc_reg_operand" "")))]
5477   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5478 {
5479   if (swdiv && !optimize_size && TARGET_POPCNTB
5480   && flag_finite_math_only && !flag_trapping_math)
5481     {
5482       rs6000_emit_swdivdf (operands[0], operands[1], operands[2]);
5483       DONE;
5484     }
5485 })
5486
5487 (define_insn "*divdf3_fpr"
5488   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5489         (div:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5490                 (match_operand:DF 2 "gpc_reg_operand" "f")))]
5491   "TARGET_HARD_FLOAT && TARGET_FPRS"
5492   "{fd|fdiv} %0,%1,%2"
5493   [(set_attr "type" "ddiv")])
5494
5495 (define_insn ""
5496   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5497         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5498                           (match_operand:DF 2 "gpc_reg_operand" "f"))
5499                  (match_operand:DF 3 "gpc_reg_operand" "f")))]
5500   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5501   "{fma|fmadd} %0,%1,%2,%3"
5502   [(set_attr "type" "dmul")])
5503
5504 (define_insn ""
5505   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5506         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5507                            (match_operand:DF 2 "gpc_reg_operand" "f"))
5508                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
5509   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5510   "{fms|fmsub} %0,%1,%2,%3"
5511   [(set_attr "type" "dmul")])
5512
5513 (define_insn ""
5514   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5515         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5516                                   (match_operand:DF 2 "gpc_reg_operand" "f"))
5517                          (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5518   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5519    && HONOR_SIGNED_ZEROS (DFmode)"
5520   "{fnma|fnmadd} %0,%1,%2,%3"
5521   [(set_attr "type" "dmul")])
5522
5523 (define_insn ""
5524   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5525         (minus:DF (mult:DF (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f"))
5526                            (match_operand:DF 2 "gpc_reg_operand" "f"))
5527                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
5528   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5529    && ! HONOR_SIGNED_ZEROS (DFmode)"
5530   "{fnma|fnmadd} %0,%1,%2,%3"
5531   [(set_attr "type" "dmul")])
5532
5533 (define_insn ""
5534   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5535         (neg:DF (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5536                                    (match_operand:DF 2 "gpc_reg_operand" "f"))
5537                           (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5538   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5539    && HONOR_SIGNED_ZEROS (DFmode)"
5540   "{fnms|fnmsub} %0,%1,%2,%3"
5541   [(set_attr "type" "dmul")])
5542
5543 (define_insn ""
5544   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5545         (minus:DF (match_operand:DF 3 "gpc_reg_operand" "f")
5546                   (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5547                            (match_operand:DF 2 "gpc_reg_operand" "f"))))]
5548   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5549    && ! HONOR_SIGNED_ZEROS (DFmode)"
5550   "{fnms|fnmsub} %0,%1,%2,%3"
5551   [(set_attr "type" "dmul")])
5552
5553 (define_insn "sqrtdf2"
5554   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5555         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5556   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
5557   "fsqrt %0,%1"
5558   [(set_attr "type" "dsqrt")])
5559
5560 ;; The conditional move instructions allow us to perform max and min
5561 ;; operations even when
5562
5563 (define_expand "smaxdf3"
5564   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5565         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5566                              (match_operand:DF 2 "gpc_reg_operand" ""))
5567                          (match_dup 1)
5568                          (match_dup 2)))]
5569   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5570   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
5571
5572 (define_expand "smindf3"
5573   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5574         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5575                              (match_operand:DF 2 "gpc_reg_operand" ""))
5576                          (match_dup 2)
5577                          (match_dup 1)))]
5578   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5579   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
5580
5581 (define_split
5582   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5583         (match_operator:DF 3 "min_max_operator"
5584          [(match_operand:DF 1 "gpc_reg_operand" "")
5585           (match_operand:DF 2 "gpc_reg_operand" "")]))]
5586   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5587   [(const_int 0)]
5588   "
5589 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5590                       operands[1], operands[2]);
5591   DONE;
5592 }")
5593
5594 (define_expand "movdfcc"
5595    [(set (match_operand:DF 0 "gpc_reg_operand" "")
5596          (if_then_else:DF (match_operand 1 "comparison_operator" "")
5597                           (match_operand:DF 2 "gpc_reg_operand" "")
5598                           (match_operand:DF 3 "gpc_reg_operand" "")))]
5599   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5600   "
5601 {
5602   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5603     DONE;
5604   else
5605     FAIL;
5606 }")
5607
5608 (define_insn "*fseldfdf4"
5609   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5610         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
5611                              (match_operand:DF 4 "zero_fp_constant" "F"))
5612                          (match_operand:DF 2 "gpc_reg_operand" "f")
5613                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
5614   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5615   "fsel %0,%1,%2,%3"
5616   [(set_attr "type" "fp")])
5617
5618 (define_insn "*fselsfdf4"
5619   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5620         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5621                              (match_operand:SF 4 "zero_fp_constant" "F"))
5622                          (match_operand:DF 2 "gpc_reg_operand" "f")
5623                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
5624   "TARGET_PPC_GFXOPT"
5625   "fsel %0,%1,%2,%3"
5626   [(set_attr "type" "fp")])
5627 \f
5628 ;; Conversions to and from floating-point.
5629
5630 (define_expand "fixuns_truncsfsi2"
5631   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5632         (unsigned_fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
5633   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5634   "")
5635
5636 (define_expand "fix_truncsfsi2"
5637   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5638         (fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
5639   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5640   "")
5641
5642 ; For each of these conversions, there is a define_expand, a define_insn
5643 ; with a '#' template, and a define_split (with C code).  The idea is
5644 ; to allow constant folding with the template of the define_insn,
5645 ; then to have the insns split later (between sched1 and final).
5646
5647 (define_expand "floatsidf2"
5648   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5649                    (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5650               (use (match_dup 2))
5651               (use (match_dup 3))
5652               (clobber (match_dup 4))
5653               (clobber (match_dup 5))
5654               (clobber (match_dup 6))])]
5655   "TARGET_HARD_FLOAT && TARGET_FPRS"
5656   "
5657 {
5658   if (TARGET_E500_DOUBLE)
5659     {
5660       emit_insn (gen_spe_floatsidf2 (operands[0], operands[1]));
5661       DONE;
5662     }
5663   if (TARGET_POWERPC64)
5664     {
5665       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5666       rtx t1 = gen_reg_rtx (DImode);
5667       rtx t2 = gen_reg_rtx (DImode);
5668       emit_insn (gen_floatsidf_ppc64 (operands[0], operands[1], mem, t1, t2));
5669       DONE;
5670     }
5671
5672   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5673   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
5674   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5675   operands[5] = gen_reg_rtx (DFmode);
5676   operands[6] = gen_reg_rtx (SImode);
5677 }")
5678
5679 (define_insn_and_split "*floatsidf2_internal"
5680   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5681         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5682    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5683    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5684    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5685    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))
5686    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
5687   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5688   "#"
5689   "&& (!no_new_pseudos || offsettable_nonstrict_memref_p (operands[4]))"
5690   [(pc)]
5691   "
5692 {
5693   rtx lowword, highword;
5694   gcc_assert (MEM_P (operands[4]));
5695   highword = adjust_address (operands[4], SImode, 0);
5696   lowword = adjust_address (operands[4], SImode, 4);
5697   if (! WORDS_BIG_ENDIAN)
5698     {
5699       rtx tmp;
5700       tmp = highword; highword = lowword; lowword = tmp;
5701     }
5702
5703   emit_insn (gen_xorsi3 (operands[6], operands[1],
5704                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
5705   emit_move_insn (lowword, operands[6]);
5706   emit_move_insn (highword, operands[2]);
5707   emit_move_insn (operands[5], operands[4]);
5708   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5709   DONE;
5710 }"
5711   [(set_attr "length" "24")])
5712
5713 (define_expand "floatunssisf2"
5714   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5715         (unsigned_float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5716   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5717   "")
5718
5719 (define_expand "floatunssidf2"
5720   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5721                    (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5722               (use (match_dup 2))
5723               (use (match_dup 3))
5724               (clobber (match_dup 4))
5725               (clobber (match_dup 5))])]
5726   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5727   "
5728 {
5729   if (TARGET_E500_DOUBLE)
5730     {
5731       emit_insn (gen_spe_floatunssidf2 (operands[0], operands[1]));
5732       DONE;
5733     }
5734   if (TARGET_POWERPC64)
5735     {
5736       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5737       rtx t1 = gen_reg_rtx (DImode);
5738       rtx t2 = gen_reg_rtx (DImode);
5739       emit_insn (gen_floatunssidf_ppc64 (operands[0], operands[1], mem,
5740                                          t1, t2));
5741       DONE;
5742     }
5743
5744   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5745   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
5746   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5747   operands[5] = gen_reg_rtx (DFmode);
5748 }")
5749
5750 (define_insn_and_split "*floatunssidf2_internal"
5751   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5752         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5753    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5754    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5755    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5756    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))]
5757   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5758   "#"
5759   "&& (!no_new_pseudos || offsettable_nonstrict_memref_p (operands[4]))"
5760   [(pc)]
5761   "
5762 {
5763   rtx lowword, highword;
5764   gcc_assert (MEM_P (operands[4]));
5765   highword = adjust_address (operands[4], SImode, 0);
5766   lowword = adjust_address (operands[4], SImode, 4);
5767   if (! WORDS_BIG_ENDIAN)
5768     {
5769       rtx tmp;
5770       tmp = highword; highword = lowword; lowword = tmp;
5771     }
5772
5773   emit_move_insn (lowword, operands[1]);
5774   emit_move_insn (highword, operands[2]);
5775   emit_move_insn (operands[5], operands[4]);
5776   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5777   DONE;
5778 }"
5779   [(set_attr "length" "20")])
5780
5781 (define_expand "fix_truncdfsi2"
5782   [(parallel [(set (match_operand:SI 0 "fix_trunc_dest_operand" "")
5783                    (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5784               (clobber (match_dup 2))
5785               (clobber (match_dup 3))])]
5786   "(TARGET_POWER2 || TARGET_POWERPC)
5787    && TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5788   "
5789 {
5790   if (TARGET_E500_DOUBLE)
5791     {
5792      emit_insn (gen_spe_fix_truncdfsi2 (operands[0], operands[1]));
5793      DONE;
5794     }
5795   operands[2] = gen_reg_rtx (DImode);
5796   if (TARGET_PPC_GFXOPT)
5797     {
5798       rtx orig_dest = operands[0];
5799       if (! memory_operand (orig_dest, GET_MODE (orig_dest)))
5800         operands[0] = assign_stack_temp (SImode, GET_MODE_SIZE (SImode), 0);
5801       emit_insn (gen_fix_truncdfsi2_internal_gfxopt (operands[0], operands[1],
5802                                                      operands[2]));
5803       if (operands[0] != orig_dest)
5804         emit_move_insn (orig_dest, operands[0]);
5805       DONE;
5806     }
5807   operands[3] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5808 }")
5809
5810 (define_insn_and_split "*fix_truncdfsi2_internal"
5811   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5812         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5813    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))
5814    (clobber (match_operand:DI 3 "memory_operand" "=o"))]
5815   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5816   "#"
5817   "&& (!no_new_pseudos || offsettable_nonstrict_memref_p (operands[3]))"
5818   [(pc)]
5819   "
5820 {
5821   rtx lowword;
5822   gcc_assert (MEM_P (operands[3]));
5823   lowword = adjust_address (operands[3], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
5824
5825   emit_insn (gen_fctiwz (operands[2], operands[1]));
5826   emit_move_insn (operands[3], operands[2]);
5827   emit_move_insn (operands[0], lowword);
5828   DONE;
5829 }"
5830   [(set_attr "length" "16")])
5831
5832 (define_insn_and_split "fix_truncdfsi2_internal_gfxopt"
5833   [(set (match_operand:SI 0 "memory_operand" "=Z")
5834         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5835    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))]
5836   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS
5837    && TARGET_PPC_GFXOPT"
5838   "#"
5839   "&& 1"
5840   [(pc)]
5841   "
5842 {
5843   emit_insn (gen_fctiwz (operands[2], operands[1]));
5844   emit_insn (gen_stfiwx (operands[0], operands[2]));
5845   DONE;
5846 }"
5847   [(set_attr "length" "16")])
5848
5849 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
5850 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
5851 ; because the first makes it clear that operand 0 is not live
5852 ; before the instruction.
5853 (define_insn "fctiwz"
5854   [(set (match_operand:DI 0 "gpc_reg_operand" "=f")
5855         (unspec:DI [(fix:SI (match_operand:DF 1 "gpc_reg_operand" "f"))]
5856                    UNSPEC_FCTIWZ))]
5857   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5858   "{fcirz|fctiwz} %0,%1"
5859   [(set_attr "type" "fp")])
5860
5861 (define_insn "btruncdf2"
5862   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5863         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIZ))]
5864   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5865   "friz %0,%1"
5866   [(set_attr "type" "fp")])
5867
5868 (define_insn "btruncsf2"
5869   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5870         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIZ))]
5871   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5872   "friz %0,%1"
5873   [(set_attr "type" "fp")])
5874
5875 (define_insn "ceildf2"
5876   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5877         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIP))]
5878   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5879   "frip %0,%1"
5880   [(set_attr "type" "fp")])
5881
5882 (define_insn "ceilsf2"
5883  [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5884         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIP))]
5885   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5886   "frip %0,%1"
5887   [(set_attr "type" "fp")])
5888
5889 (define_insn "floordf2"
5890   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5891         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIM))]
5892   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5893   "frim %0,%1"
5894   [(set_attr "type" "fp")])
5895
5896 (define_insn "floorsf2"
5897   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5898         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIM))]
5899   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5900   "frim %0,%1"
5901   [(set_attr "type" "fp")])
5902
5903 (define_insn "rounddf2"
5904   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5905         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIN))]
5906   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5907   "frin %0,%1"
5908   [(set_attr "type" "fp")])
5909
5910 (define_insn "roundsf2"
5911   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5912         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIN))]
5913   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5914   "frin %0,%1"
5915   [(set_attr "type" "fp")])
5916
5917 ; An UNSPEC is used so we don't have to support SImode in FP registers.
5918 (define_insn "stfiwx"
5919   [(set (match_operand:SI 0 "memory_operand" "=Z")
5920         (unspec:SI [(match_operand:DI 1 "gpc_reg_operand" "f")]
5921                    UNSPEC_STFIWX))]
5922   "TARGET_PPC_GFXOPT"
5923   "stfiwx %1,%y0"
5924   [(set_attr "type" "fpstore")])
5925
5926 (define_expand "floatsisf2"
5927   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5928         (float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5929   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5930   "")
5931
5932 (define_insn "floatdidf2"
5933   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5934         (float:DF (match_operand:DI 1 "gpc_reg_operand" "*f")))]
5935   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5936   "fcfid %0,%1"
5937   [(set_attr "type" "fp")])
5938
5939 (define_insn_and_split "floatsidf_ppc64"
5940   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5941         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5942    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5943    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5944    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5945   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5946   "#"
5947   "&& 1"
5948   [(set (match_dup 3) (sign_extend:DI (match_dup 1)))
5949    (set (match_dup 2) (match_dup 3))
5950    (set (match_dup 4) (match_dup 2))
5951    (set (match_dup 0) (float:DF (match_dup 4)))]
5952   "")
5953
5954 (define_insn_and_split "floatunssidf_ppc64"
5955   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5956         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5957    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5958    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5959    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5960   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5961   "#"
5962   "&& 1"
5963   [(set (match_dup 3) (zero_extend:DI (match_dup 1)))
5964    (set (match_dup 2) (match_dup 3))
5965    (set (match_dup 4) (match_dup 2))
5966    (set (match_dup 0) (float:DF (match_dup 4)))]
5967   "")
5968
5969 (define_insn "fix_truncdfdi2"
5970   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
5971         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "f")))]
5972   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5973   "fctidz %0,%1"
5974   [(set_attr "type" "fp")])
5975
5976 (define_expand "floatdisf2"
5977   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5978         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
5979   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5980   "
5981 {
5982   rtx val = operands[1];
5983   if (!flag_unsafe_math_optimizations)
5984     {
5985       rtx label = gen_label_rtx ();
5986       val = gen_reg_rtx (DImode);
5987       emit_insn (gen_floatdisf2_internal2 (val, operands[1], label));
5988       emit_label (label);
5989     }
5990   emit_insn (gen_floatdisf2_internal1 (operands[0], val));
5991   DONE;
5992 }")
5993
5994 ;; This is not IEEE compliant if rounding mode is "round to nearest".
5995 ;; If the DI->DF conversion is inexact, then it's possible to suffer
5996 ;; from double rounding.
5997 (define_insn_and_split "floatdisf2_internal1"
5998   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5999         (float:SF (match_operand:DI 1 "gpc_reg_operand" "*f")))
6000    (clobber (match_scratch:DF 2 "=f"))]
6001   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
6002   "#"
6003   "&& reload_completed"
6004   [(set (match_dup 2)
6005         (float:DF (match_dup 1)))
6006    (set (match_dup 0)
6007         (float_truncate:SF (match_dup 2)))]
6008   "")
6009
6010 ;; Twiddles bits to avoid double rounding.
6011 ;; Bits that might be truncated when converting to DFmode are replaced
6012 ;; by a bit that won't be lost at that stage, but is below the SFmode
6013 ;; rounding position.
6014 (define_expand "floatdisf2_internal2"
6015   [(set (match_dup 3) (ashiftrt:DI (match_operand:DI 1 "" "")
6016                                    (const_int 53)))
6017    (parallel [(set (match_operand:DI 0 "" "") (and:DI (match_dup 1)
6018                                                       (const_int 2047)))
6019               (clobber (scratch:CC))])
6020    (set (match_dup 3) (plus:DI (match_dup 3)
6021                                (const_int 1)))
6022    (set (match_dup 0) (plus:DI (match_dup 0)
6023                                (const_int 2047)))
6024    (set (match_dup 4) (compare:CCUNS (match_dup 3)
6025                                      (const_int 2)))
6026    (set (match_dup 0) (ior:DI (match_dup 0)
6027                               (match_dup 1)))
6028    (parallel [(set (match_dup 0) (and:DI (match_dup 0)
6029                                          (const_int -2048)))
6030               (clobber (scratch:CC))])
6031    (set (pc) (if_then_else (geu (match_dup 4) (const_int 0))
6032                            (label_ref (match_operand:DI 2 "" ""))
6033                            (pc)))
6034    (set (match_dup 0) (match_dup 1))]
6035   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
6036   "
6037 {
6038   operands[3] = gen_reg_rtx (DImode);
6039   operands[4] = gen_reg_rtx (CCUNSmode);
6040 }")
6041 \f
6042 ;; Define the DImode operations that can be done in a small number
6043 ;; of instructions.  The & constraints are to prevent the register
6044 ;; allocator from allocating registers that overlap with the inputs
6045 ;; (for example, having an input in 7,8 and an output in 6,7).  We
6046 ;; also allow for the output being the same as one of the inputs.
6047
6048 (define_insn "*adddi3_noppc64"
6049   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
6050         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
6051                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
6052   "! TARGET_POWERPC64"
6053   "*
6054 {
6055   if (WORDS_BIG_ENDIAN)
6056     return (GET_CODE (operands[2])) != CONST_INT
6057             ? \"{a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2\"
6058             : \"{ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1\";
6059   else
6060     return (GET_CODE (operands[2])) != CONST_INT
6061             ? \"{a|addc} %0,%1,%2\;{ae|adde} %L0,%L1,%L2\"
6062             : \"{ai|addic} %0,%1,%2\;{a%G2e|add%G2e} %L0,%L1\";
6063 }"
6064   [(set_attr "type" "two")
6065    (set_attr "length" "8")])
6066
6067 (define_insn "*subdi3_noppc64"
6068   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
6069         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
6070                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
6071   "! TARGET_POWERPC64"
6072   "*
6073 {
6074   if (WORDS_BIG_ENDIAN)
6075     return (GET_CODE (operands[1]) != CONST_INT)
6076             ? \"{sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1\"
6077             : \"{sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2\";
6078   else
6079     return (GET_CODE (operands[1]) != CONST_INT)
6080             ? \"{sf|subfc} %0,%2,%1\;{sfe|subfe} %L0,%L2,%L1\"
6081             : \"{sfi|subfic} %0,%2,%1\;{sf%G1e|subf%G1e} %L0,%L2\";
6082 }"
6083   [(set_attr "type" "two")
6084    (set_attr "length" "8")])
6085
6086 (define_insn "*negdi2_noppc64"
6087   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6088         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
6089   "! TARGET_POWERPC64"
6090   "*
6091 {
6092   return (WORDS_BIG_ENDIAN)
6093     ? \"{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1\"
6094     : \"{sfi|subfic} %0,%1,0\;{sfze|subfze} %L0,%L1\";
6095 }"
6096   [(set_attr "type" "two")
6097    (set_attr "length" "8")])
6098
6099 (define_expand "mulsidi3"
6100   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6101         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6102                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6103   "! TARGET_POWERPC64"
6104   "
6105 {
6106   if (! TARGET_POWER && ! TARGET_POWERPC)
6107     {
6108       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
6109       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
6110       emit_insn (gen_mull_call ());
6111       if (WORDS_BIG_ENDIAN)
6112         emit_move_insn (operands[0], gen_rtx_REG (DImode, 3));
6113       else
6114         {
6115           emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
6116                           gen_rtx_REG (SImode, 3));
6117           emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
6118                           gen_rtx_REG (SImode, 4));
6119         }
6120       DONE;
6121     }
6122   else if (TARGET_POWER)
6123     {
6124       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
6125       DONE;
6126     }
6127 }")
6128
6129 (define_insn "mulsidi3_mq"
6130   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6131         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6132                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
6133    (clobber (match_scratch:SI 3 "=q"))]
6134   "TARGET_POWER"
6135   "mul %0,%1,%2\;mfmq %L0"
6136   [(set_attr "type" "imul")
6137    (set_attr "length" "8")])
6138
6139 (define_insn "*mulsidi3_no_mq"
6140   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6141         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6142                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6143   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
6144   "*
6145 {
6146   return (WORDS_BIG_ENDIAN)
6147     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
6148     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
6149 }"
6150   [(set_attr "type" "imul")
6151    (set_attr "length" "8")])
6152
6153 (define_split
6154   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6155         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6156                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6157   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
6158   [(set (match_dup 3)
6159         (truncate:SI
6160          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
6161                                (sign_extend:DI (match_dup 2)))
6162                       (const_int 32))))
6163    (set (match_dup 4)
6164         (mult:SI (match_dup 1)
6165                  (match_dup 2)))]
6166   "
6167 {
6168   int endian = (WORDS_BIG_ENDIAN == 0);
6169   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6170   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6171 }")
6172
6173 (define_expand "umulsidi3"
6174   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6175         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6176                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6177   "TARGET_POWERPC && ! TARGET_POWERPC64"
6178   "
6179 {
6180   if (TARGET_POWER)
6181     {
6182       emit_insn (gen_umulsidi3_mq (operands[0], operands[1], operands[2]));
6183       DONE;
6184     }
6185 }")
6186
6187 (define_insn "umulsidi3_mq"
6188   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6189         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6190                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
6191    (clobber (match_scratch:SI 3 "=q"))]
6192   "TARGET_POWERPC && TARGET_POWER"
6193   "*
6194 {
6195   return (WORDS_BIG_ENDIAN)
6196     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
6197     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
6198 }"
6199   [(set_attr "type" "imul")
6200    (set_attr "length" "8")])
6201
6202 (define_insn "*umulsidi3_no_mq"
6203   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6204         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6205                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6206   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
6207   "*
6208 {
6209   return (WORDS_BIG_ENDIAN)
6210     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
6211     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
6212 }"
6213   [(set_attr "type" "imul")
6214    (set_attr "length" "8")])
6215
6216 (define_split
6217   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6218         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6219                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6220   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
6221   [(set (match_dup 3)
6222         (truncate:SI
6223          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
6224                                (zero_extend:DI (match_dup 2)))
6225                       (const_int 32))))
6226    (set (match_dup 4)
6227         (mult:SI (match_dup 1)
6228                  (match_dup 2)))]
6229   "
6230 {
6231   int endian = (WORDS_BIG_ENDIAN == 0);
6232   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6233   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6234 }")
6235
6236 (define_expand "smulsi3_highpart"
6237   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6238         (truncate:SI
6239          (lshiftrt:DI (mult:DI (sign_extend:DI
6240                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6241                                (sign_extend:DI
6242                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6243                       (const_int 32))))]
6244   ""
6245   "
6246 {
6247   if (! TARGET_POWER && ! TARGET_POWERPC)
6248     {
6249       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
6250       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
6251       emit_insn (gen_mulh_call ());
6252       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
6253       DONE;
6254     }
6255   else if (TARGET_POWER)
6256     {
6257       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
6258       DONE;
6259     }
6260 }")
6261
6262 (define_insn "smulsi3_highpart_mq"
6263   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6264         (truncate:SI
6265          (lshiftrt:DI (mult:DI (sign_extend:DI
6266                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6267                                (sign_extend:DI
6268                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6269                       (const_int 32))))
6270    (clobber (match_scratch:SI 3 "=q"))]
6271   "TARGET_POWER"
6272   "mul %0,%1,%2"
6273   [(set_attr "type" "imul")])
6274
6275 (define_insn "*smulsi3_highpart_no_mq"
6276   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6277         (truncate:SI
6278          (lshiftrt:DI (mult:DI (sign_extend:DI
6279                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6280                                (sign_extend:DI
6281                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6282                       (const_int 32))))]
6283   "TARGET_POWERPC && ! TARGET_POWER"
6284   "mulhw %0,%1,%2"
6285   [(set_attr "type" "imul")])
6286
6287 (define_expand "umulsi3_highpart"
6288   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6289         (truncate:SI
6290          (lshiftrt:DI (mult:DI (zero_extend:DI
6291                                 (match_operand:SI 1 "gpc_reg_operand" ""))
6292                                (zero_extend:DI
6293                                 (match_operand:SI 2 "gpc_reg_operand" "")))
6294                       (const_int 32))))]
6295   "TARGET_POWERPC"
6296   "
6297 {
6298   if (TARGET_POWER)
6299     {
6300       emit_insn (gen_umulsi3_highpart_mq (operands[0], operands[1], operands[2]));
6301       DONE;
6302     }
6303 }")
6304
6305 (define_insn "umulsi3_highpart_mq"
6306   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6307         (truncate:SI
6308          (lshiftrt:DI (mult:DI (zero_extend:DI
6309                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6310                                (zero_extend:DI
6311                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6312                       (const_int 32))))
6313    (clobber (match_scratch:SI 3 "=q"))]
6314   "TARGET_POWERPC && TARGET_POWER"
6315   "mulhwu %0,%1,%2"
6316   [(set_attr "type" "imul")])
6317
6318 (define_insn "*umulsi3_highpart_no_mq"
6319   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6320         (truncate:SI
6321          (lshiftrt:DI (mult:DI (zero_extend:DI
6322                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6323                                (zero_extend:DI
6324                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6325                       (const_int 32))))]
6326   "TARGET_POWERPC && ! TARGET_POWER"
6327   "mulhwu %0,%1,%2"
6328   [(set_attr "type" "imul")])
6329
6330 ;; If operands 0 and 2 are in the same register, we have a problem.  But
6331 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
6332 ;; why we have the strange constraints below.
6333 (define_insn "ashldi3_power"
6334   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
6335         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
6336                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
6337    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
6338   "TARGET_POWER"
6339   "@
6340    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
6341    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
6342    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
6343    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
6344   [(set_attr "length" "8")])
6345
6346 (define_insn "lshrdi3_power"
6347   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
6348         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
6349                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
6350    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
6351   "TARGET_POWER"
6352   "@
6353    {s%A2i|s%A2wi} %L0,%1,%h2\;{cal %0,0(0)|li %0,0}
6354    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
6355    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
6356    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
6357   [(set_attr "length" "8")])
6358
6359 ;; Shift by a variable amount is too complex to be worth open-coding.  We
6360 ;; just handle shifts by constants.
6361 (define_insn "ashrdi3_power"
6362   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6363         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6364                      (match_operand:SI 2 "const_int_operand" "M,i")))
6365    (clobber (match_scratch:SI 3 "=X,q"))]
6366   "TARGET_POWER"
6367   "@
6368    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
6369    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
6370   [(set_attr "length" "8")])
6371
6372 (define_insn "ashrdi3_no_power"
6373   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
6374         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6375                      (match_operand:SI 2 "const_int_operand" "M,i")))]
6376   "TARGET_32BIT && !TARGET_POWERPC64 && !TARGET_POWER && WORDS_BIG_ENDIAN"
6377   "@
6378    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
6379    {sri|srwi} %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;{srai|srawi} %0,%1,%h2"
6380   [(set_attr "type" "two,three")
6381    (set_attr "length" "8,12")])
6382
6383 (define_insn "*ashrdisi3_noppc64"
6384   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6385         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6386                                 (const_int 32)) 4))]
6387   "TARGET_32BIT && !TARGET_POWERPC64"
6388   "*
6389 {
6390   if (REGNO (operands[0]) == REGNO (operands[1]))
6391     return \"\";
6392   else
6393     return \"mr %0,%1\";
6394 }"
6395    [(set_attr "length" "4")])
6396
6397 \f
6398 ;; PowerPC64 DImode operations.
6399
6400 (define_insn_and_split "absdi2"
6401   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6402         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
6403    (clobber (match_scratch:DI 2 "=&r,&r"))]
6404   "TARGET_POWERPC64"
6405   "#"
6406   "&& reload_completed"
6407   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
6408    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
6409    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
6410   "")
6411
6412 (define_insn_and_split "*nabsdi2"
6413   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6414         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
6415    (clobber (match_scratch:DI 2 "=&r,&r"))]
6416   "TARGET_POWERPC64"
6417   "#"
6418   "&& reload_completed"
6419   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
6420    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
6421    (set (match_dup 0) (minus:DI (match_dup 2) (match_dup 0)))]
6422   "")
6423
6424 (define_insn "muldi3"
6425   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6426         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6427                  (match_operand:DI 2 "reg_or_short_operand" "r,I")))]
6428   "TARGET_POWERPC64"
6429   "@
6430    mulld %0,%1,%2
6431    mulli %0,%1,%2"
6432    [(set (attr "type")
6433       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
6434                 (const_string "imul3")
6435              (match_operand:SI 2 "short_cint_operand" "")
6436                 (const_string "imul2")]
6437         (const_string "lmul")))])
6438
6439 (define_insn "*muldi3_internal1"
6440   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6441         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6442                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6443                     (const_int 0)))
6444    (clobber (match_scratch:DI 3 "=r,r"))]
6445   "TARGET_POWERPC64"
6446   "@
6447    mulld. %3,%1,%2
6448    #"
6449   [(set_attr "type" "lmul_compare")
6450    (set_attr "length" "4,8")])
6451
6452 (define_split
6453   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6454         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6455                              (match_operand:DI 2 "gpc_reg_operand" ""))
6456                     (const_int 0)))
6457    (clobber (match_scratch:DI 3 ""))]
6458   "TARGET_POWERPC64 && reload_completed"
6459   [(set (match_dup 3)
6460         (mult:DI (match_dup 1) (match_dup 2)))
6461    (set (match_dup 0)
6462         (compare:CC (match_dup 3)
6463                     (const_int 0)))]
6464   "")
6465
6466 (define_insn "*muldi3_internal2"
6467   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6468         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6469                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6470                     (const_int 0)))
6471    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6472         (mult:DI (match_dup 1) (match_dup 2)))]
6473   "TARGET_POWERPC64"
6474   "@
6475    mulld. %0,%1,%2
6476    #"
6477   [(set_attr "type" "lmul_compare")
6478    (set_attr "length" "4,8")])
6479
6480 (define_split
6481   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6482         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6483                              (match_operand:DI 2 "gpc_reg_operand" ""))
6484                     (const_int 0)))
6485    (set (match_operand:DI 0 "gpc_reg_operand" "")
6486         (mult:DI (match_dup 1) (match_dup 2)))]
6487   "TARGET_POWERPC64 && reload_completed"
6488   [(set (match_dup 0)
6489         (mult:DI (match_dup 1) (match_dup 2)))
6490    (set (match_dup 3)
6491         (compare:CC (match_dup 0)
6492                     (const_int 0)))]
6493   "")
6494
6495 (define_insn "smuldi3_highpart"
6496   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6497         (truncate:DI
6498          (lshiftrt:TI (mult:TI (sign_extend:TI
6499                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6500                                (sign_extend:TI
6501                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6502                       (const_int 64))))]
6503   "TARGET_POWERPC64"
6504   "mulhd %0,%1,%2"
6505   [(set_attr "type" "lmul")])
6506
6507 (define_insn "umuldi3_highpart"
6508   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6509         (truncate:DI
6510          (lshiftrt:TI (mult:TI (zero_extend:TI
6511                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6512                                (zero_extend:TI
6513                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6514                       (const_int 64))))]
6515   "TARGET_POWERPC64"
6516   "mulhdu %0,%1,%2"
6517   [(set_attr "type" "lmul")])
6518
6519 (define_insn "rotldi3"
6520   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6521         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6522                    (match_operand:DI 2 "reg_or_cint_operand" "ri")))]
6523   "TARGET_POWERPC64"
6524   "rld%I2cl %0,%1,%H2,0")
6525
6526 (define_insn "*rotldi3_internal2"
6527   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6528         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6529                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6530                     (const_int 0)))
6531    (clobber (match_scratch:DI 3 "=r,r"))]
6532   "TARGET_64BIT"
6533   "@
6534    rld%I2cl. %3,%1,%H2,0
6535    #"
6536   [(set_attr "type" "delayed_compare")
6537    (set_attr "length" "4,8")])
6538
6539 (define_split
6540   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6541         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6542                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6543                     (const_int 0)))
6544    (clobber (match_scratch:DI 3 ""))]
6545   "TARGET_POWERPC64 && reload_completed"
6546   [(set (match_dup 3)
6547         (rotate:DI (match_dup 1) (match_dup 2)))
6548    (set (match_dup 0)
6549         (compare:CC (match_dup 3)
6550                     (const_int 0)))]
6551   "")
6552
6553 (define_insn "*rotldi3_internal3"
6554   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6555         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6556                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6557                     (const_int 0)))
6558    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6559         (rotate:DI (match_dup 1) (match_dup 2)))]
6560   "TARGET_64BIT"
6561   "@
6562    rld%I2cl. %0,%1,%H2,0
6563    #"
6564   [(set_attr "type" "delayed_compare")
6565    (set_attr "length" "4,8")])
6566
6567 (define_split
6568   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6569         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6570                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6571                     (const_int 0)))
6572    (set (match_operand:DI 0 "gpc_reg_operand" "")
6573         (rotate:DI (match_dup 1) (match_dup 2)))]
6574   "TARGET_POWERPC64 && reload_completed"
6575   [(set (match_dup 0)
6576         (rotate:DI (match_dup 1) (match_dup 2)))
6577    (set (match_dup 3)
6578         (compare:CC (match_dup 0)
6579                     (const_int 0)))]
6580   "")
6581
6582 (define_insn "*rotldi3_internal4"
6583   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6584         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6585                            (match_operand:DI 2 "reg_or_cint_operand" "ri"))
6586                 (match_operand:DI 3 "mask64_operand" "n")))]
6587   "TARGET_POWERPC64"
6588   "rld%I2c%B3 %0,%1,%H2,%S3")
6589
6590 (define_insn "*rotldi3_internal5"
6591   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6592         (compare:CC (and:DI
6593                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6594                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6595                      (match_operand:DI 3 "mask64_operand" "n,n"))
6596                     (const_int 0)))
6597    (clobber (match_scratch:DI 4 "=r,r"))]
6598   "TARGET_64BIT"
6599   "@
6600    rld%I2c%B3. %4,%1,%H2,%S3
6601    #"
6602   [(set_attr "type" "delayed_compare")
6603    (set_attr "length" "4,8")])
6604
6605 (define_split
6606   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6607         (compare:CC (and:DI
6608                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6609                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6610                      (match_operand:DI 3 "mask64_operand" ""))
6611                     (const_int 0)))
6612    (clobber (match_scratch:DI 4 ""))]
6613   "TARGET_POWERPC64 && reload_completed"
6614   [(set (match_dup 4)
6615         (and:DI (rotate:DI (match_dup 1)
6616                                 (match_dup 2))
6617                      (match_dup 3)))
6618    (set (match_dup 0)
6619         (compare:CC (match_dup 4)
6620                     (const_int 0)))]
6621   "")
6622
6623 (define_insn "*rotldi3_internal6"
6624   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6625         (compare:CC (and:DI
6626                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6627                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6628                      (match_operand:DI 3 "mask64_operand" "n,n"))
6629                     (const_int 0)))
6630    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6631         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6632   "TARGET_64BIT"
6633   "@
6634    rld%I2c%B3. %0,%1,%H2,%S3
6635    #"
6636   [(set_attr "type" "delayed_compare")
6637    (set_attr "length" "4,8")])
6638
6639 (define_split
6640   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6641         (compare:CC (and:DI
6642                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6643                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6644                      (match_operand:DI 3 "mask64_operand" ""))
6645                     (const_int 0)))
6646    (set (match_operand:DI 0 "gpc_reg_operand" "")
6647         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6648   "TARGET_POWERPC64 && reload_completed"
6649   [(set (match_dup 0)
6650         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
6651    (set (match_dup 4)
6652         (compare:CC (match_dup 0)
6653                     (const_int 0)))]
6654   "")
6655
6656 (define_insn "*rotldi3_internal7"
6657   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6658         (zero_extend:DI
6659          (subreg:QI
6660           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6661                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6662   "TARGET_POWERPC64"
6663   "rld%I2cl %0,%1,%H2,56")
6664
6665 (define_insn "*rotldi3_internal8"
6666   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6667         (compare:CC (zero_extend:DI
6668                      (subreg:QI
6669                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6670                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6671                     (const_int 0)))
6672    (clobber (match_scratch:DI 3 "=r,r"))]
6673   "TARGET_64BIT"
6674   "@
6675    rld%I2cl. %3,%1,%H2,56
6676    #"
6677   [(set_attr "type" "delayed_compare")
6678    (set_attr "length" "4,8")])
6679
6680 (define_split
6681   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6682         (compare:CC (zero_extend:DI
6683                      (subreg:QI
6684                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6685                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6686                     (const_int 0)))
6687    (clobber (match_scratch:DI 3 ""))]
6688   "TARGET_POWERPC64 && reload_completed"
6689   [(set (match_dup 3)
6690         (zero_extend:DI (subreg:QI
6691                       (rotate:DI (match_dup 1)
6692                                  (match_dup 2)) 0)))
6693    (set (match_dup 0)
6694         (compare:CC (match_dup 3)
6695                     (const_int 0)))]
6696   "")
6697
6698 (define_insn "*rotldi3_internal9"
6699   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6700         (compare:CC (zero_extend:DI
6701                      (subreg:QI
6702                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6703                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6704                     (const_int 0)))
6705    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6706         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6707   "TARGET_64BIT"
6708   "@
6709    rld%I2cl. %0,%1,%H2,56
6710    #"
6711   [(set_attr "type" "delayed_compare")
6712    (set_attr "length" "4,8")])
6713
6714 (define_split
6715   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6716         (compare:CC (zero_extend:DI
6717                      (subreg:QI
6718                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6719                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6720                     (const_int 0)))
6721    (set (match_operand:DI 0 "gpc_reg_operand" "")
6722         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6723   "TARGET_POWERPC64 && reload_completed"
6724   [(set (match_dup 0)
6725         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6726    (set (match_dup 3)
6727         (compare:CC (match_dup 0)
6728                     (const_int 0)))]
6729   "")
6730
6731 (define_insn "*rotldi3_internal10"
6732   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6733         (zero_extend:DI
6734          (subreg:HI
6735           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6736                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6737   "TARGET_POWERPC64"
6738   "rld%I2cl %0,%1,%H2,48")
6739
6740 (define_insn "*rotldi3_internal11"
6741   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6742         (compare:CC (zero_extend:DI
6743                      (subreg:HI
6744                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6745                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6746                     (const_int 0)))
6747    (clobber (match_scratch:DI 3 "=r,r"))]
6748   "TARGET_64BIT"
6749   "@
6750    rld%I2cl. %3,%1,%H2,48
6751    #"
6752   [(set_attr "type" "delayed_compare")
6753    (set_attr "length" "4,8")])
6754
6755 (define_split
6756   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6757         (compare:CC (zero_extend:DI
6758                      (subreg:HI
6759                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6760                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6761                     (const_int 0)))
6762    (clobber (match_scratch:DI 3 ""))]
6763   "TARGET_POWERPC64 && reload_completed"
6764   [(set (match_dup 3)
6765         (zero_extend:DI (subreg:HI
6766                       (rotate:DI (match_dup 1)
6767                                  (match_dup 2)) 0)))
6768    (set (match_dup 0)
6769         (compare:CC (match_dup 3)
6770                     (const_int 0)))]
6771   "")
6772
6773 (define_insn "*rotldi3_internal12"
6774   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6775         (compare:CC (zero_extend:DI
6776                      (subreg:HI
6777                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6778                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6779                     (const_int 0)))
6780    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6781         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6782   "TARGET_64BIT"
6783   "@
6784    rld%I2cl. %0,%1,%H2,48
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 (zero_extend:DI
6792                      (subreg:HI
6793                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6794                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6795                     (const_int 0)))
6796    (set (match_operand:DI 0 "gpc_reg_operand" "")
6797         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6798   "TARGET_POWERPC64 && reload_completed"
6799   [(set (match_dup 0)
6800         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6801    (set (match_dup 3)
6802         (compare:CC (match_dup 0)
6803                     (const_int 0)))]
6804   "")
6805
6806 (define_insn "*rotldi3_internal13"
6807   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6808         (zero_extend:DI
6809          (subreg:SI
6810           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6811                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6812   "TARGET_POWERPC64"
6813   "rld%I2cl %0,%1,%H2,32")
6814
6815 (define_insn "*rotldi3_internal14"
6816   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6817         (compare:CC (zero_extend:DI
6818                      (subreg:SI
6819                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6820                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6821                     (const_int 0)))
6822    (clobber (match_scratch:DI 3 "=r,r"))]
6823   "TARGET_64BIT"
6824   "@
6825    rld%I2cl. %3,%1,%H2,32
6826    #"
6827   [(set_attr "type" "delayed_compare")
6828    (set_attr "length" "4,8")])
6829
6830 (define_split
6831   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6832         (compare:CC (zero_extend:DI
6833                      (subreg:SI
6834                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6835                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6836                     (const_int 0)))
6837    (clobber (match_scratch:DI 3 ""))]
6838   "TARGET_POWERPC64 && reload_completed"
6839   [(set (match_dup 3)
6840         (zero_extend:DI (subreg:SI
6841                       (rotate:DI (match_dup 1)
6842                                  (match_dup 2)) 0)))
6843    (set (match_dup 0)
6844         (compare:CC (match_dup 3)
6845                     (const_int 0)))]
6846   "")
6847
6848 (define_insn "*rotldi3_internal15"
6849   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6850         (compare:CC (zero_extend:DI
6851                      (subreg:SI
6852                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6853                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6854                     (const_int 0)))
6855    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6856         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6857   "TARGET_64BIT"
6858   "@
6859    rld%I2cl. %0,%1,%H2,32
6860    #"
6861   [(set_attr "type" "delayed_compare")
6862    (set_attr "length" "4,8")])
6863
6864 (define_split
6865   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6866         (compare:CC (zero_extend:DI
6867                      (subreg:SI
6868                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6869                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6870                     (const_int 0)))
6871    (set (match_operand:DI 0 "gpc_reg_operand" "")
6872         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6873   "TARGET_POWERPC64 && reload_completed"
6874   [(set (match_dup 0)
6875         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6876    (set (match_dup 3)
6877         (compare:CC (match_dup 0)
6878                     (const_int 0)))]
6879   "")
6880
6881 (define_expand "ashldi3"
6882   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6883         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6884                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
6885   "TARGET_POWERPC64 || TARGET_POWER"
6886   "
6887 {
6888   if (TARGET_POWERPC64)
6889     ;
6890   else if (TARGET_POWER)
6891     {
6892       emit_insn (gen_ashldi3_power (operands[0], operands[1], operands[2]));
6893       DONE;
6894     }
6895   else
6896     FAIL;
6897 }")
6898
6899 (define_insn "*ashldi3_internal1"
6900   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6901         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6902                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6903   "TARGET_POWERPC64"
6904   "sld%I2 %0,%1,%H2")
6905
6906 (define_insn "*ashldi3_internal2"
6907   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6908         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6909                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6910                     (const_int 0)))
6911    (clobber (match_scratch:DI 3 "=r,r"))]
6912   "TARGET_64BIT"
6913   "@
6914    sld%I2. %3,%1,%H2
6915    #"
6916   [(set_attr "type" "delayed_compare")
6917    (set_attr "length" "4,8")])
6918
6919 (define_split
6920   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6921         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6922                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6923                     (const_int 0)))
6924    (clobber (match_scratch:DI 3 ""))]
6925   "TARGET_POWERPC64 && reload_completed"
6926   [(set (match_dup 3)
6927         (ashift:DI (match_dup 1) (match_dup 2)))
6928    (set (match_dup 0)
6929         (compare:CC (match_dup 3)
6930                     (const_int 0)))]
6931   "")
6932
6933 (define_insn "*ashldi3_internal3"
6934   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6935         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6936                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6937                     (const_int 0)))
6938    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6939         (ashift:DI (match_dup 1) (match_dup 2)))]
6940   "TARGET_64BIT"
6941   "@
6942    sld%I2. %0,%1,%H2
6943    #"
6944   [(set_attr "type" "delayed_compare")
6945    (set_attr "length" "4,8")])
6946
6947 (define_split
6948   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6949         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6950                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6951                     (const_int 0)))
6952    (set (match_operand:DI 0 "gpc_reg_operand" "")
6953         (ashift:DI (match_dup 1) (match_dup 2)))]
6954   "TARGET_POWERPC64 && reload_completed"
6955   [(set (match_dup 0)
6956         (ashift:DI (match_dup 1) (match_dup 2)))
6957    (set (match_dup 3)
6958         (compare:CC (match_dup 0)
6959                     (const_int 0)))]
6960   "")
6961
6962 (define_insn "*ashldi3_internal4"
6963   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6964         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6965                            (match_operand:SI 2 "const_int_operand" "i"))
6966                 (match_operand:DI 3 "const_int_operand" "n")))]
6967   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
6968   "rldic %0,%1,%H2,%W3")
6969
6970 (define_insn "ashldi3_internal5"
6971   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6972         (compare:CC
6973          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6974                             (match_operand:SI 2 "const_int_operand" "i,i"))
6975                  (match_operand:DI 3 "const_int_operand" "n,n"))
6976          (const_int 0)))
6977    (clobber (match_scratch:DI 4 "=r,r"))]
6978   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6979   "@
6980    rldic. %4,%1,%H2,%W3
6981    #"
6982   [(set_attr "type" "compare")
6983    (set_attr "length" "4,8")])
6984
6985 (define_split
6986   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6987         (compare:CC
6988          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6989                             (match_operand:SI 2 "const_int_operand" ""))
6990                  (match_operand:DI 3 "const_int_operand" ""))
6991          (const_int 0)))
6992    (clobber (match_scratch:DI 4 ""))]
6993   "TARGET_POWERPC64 && reload_completed
6994    && includes_rldic_lshift_p (operands[2], operands[3])"
6995   [(set (match_dup 4)
6996         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6997                 (match_dup 3)))
6998    (set (match_dup 0)
6999         (compare:CC (match_dup 4)
7000                     (const_int 0)))]
7001   "")
7002
7003 (define_insn "*ashldi3_internal6"
7004   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7005         (compare:CC
7006          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7007                             (match_operand:SI 2 "const_int_operand" "i,i"))
7008                     (match_operand:DI 3 "const_int_operand" "n,n"))
7009          (const_int 0)))
7010    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7011         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7012   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
7013   "@
7014    rldic. %0,%1,%H2,%W3
7015    #"
7016   [(set_attr "type" "compare")
7017    (set_attr "length" "4,8")])
7018
7019 (define_split
7020   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
7021         (compare:CC
7022          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7023                             (match_operand:SI 2 "const_int_operand" ""))
7024                  (match_operand:DI 3 "const_int_operand" ""))
7025          (const_int 0)))
7026    (set (match_operand:DI 0 "gpc_reg_operand" "")
7027         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7028   "TARGET_POWERPC64 && reload_completed
7029    && includes_rldic_lshift_p (operands[2], operands[3])"
7030   [(set (match_dup 0)
7031         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7032                 (match_dup 3)))
7033    (set (match_dup 4)
7034         (compare:CC (match_dup 0)
7035                     (const_int 0)))]
7036   "")
7037
7038 (define_insn "*ashldi3_internal7"
7039   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7040         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7041                            (match_operand:SI 2 "const_int_operand" "i"))
7042                 (match_operand:DI 3 "mask64_operand" "n")))]
7043   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
7044   "rldicr %0,%1,%H2,%S3")
7045
7046 (define_insn "ashldi3_internal8"
7047   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7048         (compare:CC
7049          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7050                             (match_operand:SI 2 "const_int_operand" "i,i"))
7051                  (match_operand:DI 3 "mask64_operand" "n,n"))
7052          (const_int 0)))
7053    (clobber (match_scratch:DI 4 "=r,r"))]
7054   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7055   "@
7056    rldicr. %4,%1,%H2,%S3
7057    #"
7058   [(set_attr "type" "compare")
7059    (set_attr "length" "4,8")])
7060
7061 (define_split
7062   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7063         (compare:CC
7064          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7065                             (match_operand:SI 2 "const_int_operand" ""))
7066                  (match_operand:DI 3 "mask64_operand" ""))
7067          (const_int 0)))
7068    (clobber (match_scratch:DI 4 ""))]
7069   "TARGET_POWERPC64 && reload_completed
7070    && includes_rldicr_lshift_p (operands[2], operands[3])"
7071   [(set (match_dup 4)
7072         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7073                 (match_dup 3)))
7074    (set (match_dup 0)
7075         (compare:CC (match_dup 4)
7076                     (const_int 0)))]
7077   "")
7078
7079 (define_insn "*ashldi3_internal9"
7080   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7081         (compare:CC
7082          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7083                             (match_operand:SI 2 "const_int_operand" "i,i"))
7084                     (match_operand:DI 3 "mask64_operand" "n,n"))
7085          (const_int 0)))
7086    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7087         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7088   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7089   "@
7090    rldicr. %0,%1,%H2,%S3
7091    #"
7092   [(set_attr "type" "compare")
7093    (set_attr "length" "4,8")])
7094
7095 (define_split
7096   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
7097         (compare:CC
7098          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7099                             (match_operand:SI 2 "const_int_operand" ""))
7100                  (match_operand:DI 3 "mask64_operand" ""))
7101          (const_int 0)))
7102    (set (match_operand:DI 0 "gpc_reg_operand" "")
7103         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7104   "TARGET_POWERPC64 && reload_completed
7105    && includes_rldicr_lshift_p (operands[2], operands[3])"
7106   [(set (match_dup 0)
7107         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7108                 (match_dup 3)))
7109    (set (match_dup 4)
7110         (compare:CC (match_dup 0)
7111                     (const_int 0)))]
7112   "")
7113
7114 (define_expand "lshrdi3"
7115   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7116         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7117                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7118   "TARGET_POWERPC64 || TARGET_POWER"
7119   "
7120 {
7121   if (TARGET_POWERPC64)
7122     ;
7123   else if (TARGET_POWER)
7124     {
7125       emit_insn (gen_lshrdi3_power (operands[0], operands[1], operands[2]));
7126       DONE;
7127     }
7128   else
7129     FAIL;
7130 }")
7131
7132 (define_insn "*lshrdi3_internal1"
7133   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7134         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7135                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
7136   "TARGET_POWERPC64"
7137   "srd%I2 %0,%1,%H2")
7138
7139 (define_insn "*lshrdi3_internal2"
7140   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7141         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7142                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7143                     (const_int 0)))
7144    (clobber (match_scratch:DI 3 "=r,r"))]
7145   "TARGET_64BIT "
7146   "@
7147    srd%I2. %3,%1,%H2
7148    #"
7149   [(set_attr "type" "delayed_compare")
7150    (set_attr "length" "4,8")])
7151
7152 (define_split
7153   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7154         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7155                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7156                     (const_int 0)))
7157    (clobber (match_scratch:DI 3 ""))]
7158   "TARGET_POWERPC64 && reload_completed"
7159   [(set (match_dup 3)
7160         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7161    (set (match_dup 0)
7162         (compare:CC (match_dup 3)
7163                     (const_int 0)))]
7164   "")
7165
7166 (define_insn "*lshrdi3_internal3"
7167   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7168         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7169                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7170                     (const_int 0)))
7171    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7172         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7173   "TARGET_64BIT"
7174   "@
7175    srd%I2. %0,%1,%H2
7176    #"
7177   [(set_attr "type" "delayed_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 (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7183                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7184                     (const_int 0)))
7185    (set (match_operand:DI 0 "gpc_reg_operand" "")
7186         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7187   "TARGET_POWERPC64 && reload_completed"
7188   [(set (match_dup 0)
7189         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7190    (set (match_dup 3)
7191         (compare:CC (match_dup 0)
7192                     (const_int 0)))]
7193   "")
7194
7195 (define_expand "ashrdi3"
7196   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7197         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7198                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7199   "WORDS_BIG_ENDIAN"
7200   "
7201 {
7202   if (TARGET_POWERPC64)
7203     ;
7204   else if (TARGET_POWER && GET_CODE (operands[2]) == CONST_INT)
7205     {
7206       emit_insn (gen_ashrdi3_power (operands[0], operands[1], operands[2]));
7207       DONE;
7208     }
7209   else if (TARGET_32BIT && GET_CODE (operands[2]) == CONST_INT
7210            && WORDS_BIG_ENDIAN)
7211     {
7212       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
7213       DONE;
7214     }
7215   else
7216     FAIL;
7217 }")
7218
7219 (define_insn "*ashrdi3_internal1"
7220   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7221         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7222                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
7223   "TARGET_POWERPC64"
7224   "srad%I2 %0,%1,%H2")
7225
7226 (define_insn "*ashrdi3_internal2"
7227   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7228         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7229                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7230                     (const_int 0)))
7231    (clobber (match_scratch:DI 3 "=r,r"))]
7232   "TARGET_64BIT"
7233   "@
7234    srad%I2. %3,%1,%H2
7235    #"
7236   [(set_attr "type" "delayed_compare")
7237    (set_attr "length" "4,8")])
7238
7239 (define_split
7240   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7241         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7242                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7243                     (const_int 0)))
7244    (clobber (match_scratch:DI 3 ""))]
7245   "TARGET_POWERPC64 && reload_completed"
7246   [(set (match_dup 3)
7247         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7248    (set (match_dup 0)
7249         (compare:CC (match_dup 3)
7250                     (const_int 0)))]
7251   "")
7252
7253 (define_insn "*ashrdi3_internal3"
7254   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7255         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7256                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7257                     (const_int 0)))
7258    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7259         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7260   "TARGET_64BIT"
7261   "@
7262    srad%I2. %0,%1,%H2
7263    #"
7264   [(set_attr "type" "delayed_compare")
7265    (set_attr "length" "4,8")])
7266
7267 (define_split
7268   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7269         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7270                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7271                     (const_int 0)))
7272    (set (match_operand:DI 0 "gpc_reg_operand" "")
7273         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7274   "TARGET_POWERPC64 && reload_completed"
7275   [(set (match_dup 0)
7276         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7277    (set (match_dup 3)
7278         (compare:CC (match_dup 0)
7279                     (const_int 0)))]
7280   "")
7281
7282 (define_insn "anddi3"
7283   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
7284         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r")
7285                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,K,J,t")))
7286    (clobber (match_scratch:CC 3 "=X,X,X,x,x,X"))]
7287   "TARGET_POWERPC64"
7288   "@
7289    and %0,%1,%2
7290    rldic%B2 %0,%1,0,%S2
7291    rlwinm %0,%1,0,%m2,%M2
7292    andi. %0,%1,%b2
7293    andis. %0,%1,%u2
7294    #"
7295   [(set_attr "type" "*,*,*,compare,compare,*")
7296    (set_attr "length" "4,4,4,4,4,8")])
7297
7298 (define_split
7299   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7300         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7301                 (match_operand:DI 2 "mask64_2_operand" "")))
7302    (clobber (match_scratch:CC 3 ""))]
7303   "TARGET_POWERPC64
7304     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7305     && !mask_operand (operands[2], DImode)
7306     && !mask64_operand (operands[2], DImode)"
7307   [(set (match_dup 0)
7308         (and:DI (rotate:DI (match_dup 1)
7309                            (match_dup 4))
7310                 (match_dup 5)))
7311    (set (match_dup 0)
7312         (and:DI (rotate:DI (match_dup 0)
7313                            (match_dup 6))
7314                 (match_dup 7)))]
7315 {
7316   build_mask64_2_operands (operands[2], &operands[4]);
7317 })
7318
7319 (define_insn "*anddi3_internal2"
7320   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
7321         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
7322                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
7323                     (const_int 0)))
7324    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r,r,r"))
7325    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
7326   "TARGET_64BIT"
7327   "@
7328    and. %3,%1,%2
7329    rldic%B2. %3,%1,0,%S2
7330    rlwinm. %3,%1,0,%m2,%M2
7331    andi. %3,%1,%b2
7332    andis. %3,%1,%u2
7333    #
7334    #
7335    #
7336    #
7337    #
7338    #
7339    #"
7340   [(set_attr "type" "compare,compare,compare,compare,compare,compare,compare,compare,compare,compare,compare,compare")
7341    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
7342
7343 (define_split
7344   [(set (match_operand:CC 0 "cc_reg_operand" "")
7345         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7346                             (match_operand:DI 2 "mask64_2_operand" ""))
7347                     (const_int 0)))
7348    (clobber (match_scratch:DI 3 ""))
7349    (clobber (match_scratch:CC 4 ""))]
7350   "TARGET_64BIT && reload_completed
7351     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7352     && !mask_operand (operands[2], DImode)
7353     && !mask64_operand (operands[2], DImode)"
7354   [(set (match_dup 3)
7355         (and:DI (rotate:DI (match_dup 1)
7356                            (match_dup 5))
7357                 (match_dup 6)))
7358    (parallel [(set (match_dup 0)
7359                    (compare:CC (and:DI (rotate:DI (match_dup 3)
7360                                                   (match_dup 7))
7361                                        (match_dup 8))
7362                                (const_int 0)))
7363               (clobber (match_dup 3))])]
7364   "
7365 {
7366   build_mask64_2_operands (operands[2], &operands[5]);
7367 }")
7368
7369 (define_insn "*anddi3_internal3"
7370   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
7371         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
7372                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
7373                     (const_int 0)))
7374    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r,r,r")
7375         (and:DI (match_dup 1) (match_dup 2)))
7376    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
7377   "TARGET_64BIT"
7378   "@
7379    and. %0,%1,%2
7380    rldic%B2. %0,%1,0,%S2
7381    rlwinm. %0,%1,0,%m2,%M2
7382    andi. %0,%1,%b2
7383    andis. %0,%1,%u2
7384    #
7385    #
7386    #
7387    #
7388    #
7389    #
7390    #"
7391   [(set_attr "type" "compare,compare,compare,compare,compare,compare,compare,compare,compare,compare,compare,compare")
7392    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
7393
7394 (define_split
7395   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7396         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7397                             (match_operand:DI 2 "and64_2_operand" ""))
7398                     (const_int 0)))
7399    (set (match_operand:DI 0 "gpc_reg_operand" "")
7400         (and:DI (match_dup 1) (match_dup 2)))
7401    (clobber (match_scratch:CC 4 ""))]
7402   "TARGET_64BIT && reload_completed"
7403   [(parallel [(set (match_dup 0)
7404                     (and:DI (match_dup 1) (match_dup 2)))
7405                (clobber (match_dup 4))])
7406    (set (match_dup 3)
7407         (compare:CC (match_dup 0)
7408                     (const_int 0)))]
7409   "")
7410
7411 (define_split
7412   [(set (match_operand:CC 3 "cc_reg_operand" "")
7413         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7414                             (match_operand:DI 2 "mask64_2_operand" ""))
7415                     (const_int 0)))
7416    (set (match_operand:DI 0 "gpc_reg_operand" "")
7417         (and:DI (match_dup 1) (match_dup 2)))
7418    (clobber (match_scratch:CC 4 ""))]
7419   "TARGET_64BIT && reload_completed
7420     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7421     && !mask_operand (operands[2], DImode)
7422     && !mask64_operand (operands[2], DImode)"
7423   [(set (match_dup 0)
7424         (and:DI (rotate:DI (match_dup 1)
7425                            (match_dup 5))
7426                 (match_dup 6)))
7427    (parallel [(set (match_dup 3)
7428                    (compare:CC (and:DI (rotate:DI (match_dup 0)
7429                                                   (match_dup 7))
7430                                        (match_dup 8))
7431                                (const_int 0)))
7432               (set (match_dup 0)
7433                    (and:DI (rotate:DI (match_dup 0)
7434                                       (match_dup 7))
7435                            (match_dup 8)))])]
7436   "
7437 {
7438   build_mask64_2_operands (operands[2], &operands[5]);
7439 }")
7440
7441 (define_expand "iordi3"
7442   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7443         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
7444                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7445   "TARGET_POWERPC64"
7446   "
7447 {
7448   if (non_logical_cint_operand (operands[2], DImode))
7449     {
7450       HOST_WIDE_INT value;
7451       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7452                  ? operands[0] : gen_reg_rtx (DImode));
7453
7454       if (GET_CODE (operands[2]) == CONST_INT)
7455         {
7456           value = INTVAL (operands[2]);
7457           emit_insn (gen_iordi3 (tmp, operands[1],
7458                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7459         }
7460       else
7461         {
7462           value = CONST_DOUBLE_LOW (operands[2]);
7463           emit_insn (gen_iordi3 (tmp, operands[1],
7464                                  immed_double_const (value
7465                                                      & (~ (HOST_WIDE_INT) 0xffff),
7466                                                      0, DImode)));
7467         }
7468
7469       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7470       DONE;
7471     }
7472 }")
7473
7474 (define_expand "xordi3"
7475   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7476         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
7477                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7478   "TARGET_POWERPC64"
7479   "
7480 {
7481   if (non_logical_cint_operand (operands[2], DImode))
7482     {
7483       HOST_WIDE_INT value;
7484       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7485                  ? operands[0] : gen_reg_rtx (DImode));
7486
7487       if (GET_CODE (operands[2]) == CONST_INT)
7488         {
7489           value = INTVAL (operands[2]);
7490           emit_insn (gen_xordi3 (tmp, operands[1],
7491                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7492         }
7493       else
7494         {
7495           value = CONST_DOUBLE_LOW (operands[2]);
7496           emit_insn (gen_xordi3 (tmp, operands[1],
7497                                  immed_double_const (value
7498                                                      & (~ (HOST_WIDE_INT) 0xffff),
7499                                                      0, DImode)));
7500         }
7501
7502       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7503       DONE;
7504     }
7505 }")
7506
7507 (define_insn "*booldi3_internal1"
7508   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
7509         (match_operator:DI 3 "boolean_or_operator"
7510          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
7511           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
7512   "TARGET_POWERPC64"
7513   "@
7514    %q3 %0,%1,%2
7515    %q3i %0,%1,%b2
7516    %q3is %0,%1,%u2")
7517
7518 (define_insn "*booldi3_internal2"
7519   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7520         (compare:CC (match_operator:DI 4 "boolean_or_operator"
7521          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7522           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7523          (const_int 0)))
7524    (clobber (match_scratch:DI 3 "=r,r"))]
7525   "TARGET_64BIT"
7526   "@
7527    %q4. %3,%1,%2
7528    #"
7529   [(set_attr "type" "compare")
7530    (set_attr "length" "4,8")])
7531
7532 (define_split
7533   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7534         (compare:CC (match_operator:DI 4 "boolean_operator"
7535          [(match_operand:DI 1 "gpc_reg_operand" "")
7536           (match_operand:DI 2 "gpc_reg_operand" "")])
7537          (const_int 0)))
7538    (clobber (match_scratch:DI 3 ""))]
7539   "TARGET_POWERPC64 && reload_completed"
7540   [(set (match_dup 3) (match_dup 4))
7541    (set (match_dup 0)
7542         (compare:CC (match_dup 3)
7543                     (const_int 0)))]
7544   "")
7545
7546 (define_insn "*booldi3_internal3"
7547   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7548         (compare:CC (match_operator:DI 4 "boolean_operator"
7549          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7550           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7551          (const_int 0)))
7552    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7553         (match_dup 4))]
7554   "TARGET_64BIT"
7555   "@
7556    %q4. %0,%1,%2
7557    #"
7558   [(set_attr "type" "compare")
7559    (set_attr "length" "4,8")])
7560
7561 (define_split
7562   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7563         (compare:CC (match_operator:DI 4 "boolean_operator"
7564          [(match_operand:DI 1 "gpc_reg_operand" "")
7565           (match_operand:DI 2 "gpc_reg_operand" "")])
7566          (const_int 0)))
7567    (set (match_operand:DI 0 "gpc_reg_operand" "")
7568         (match_dup 4))]
7569   "TARGET_POWERPC64 && reload_completed"
7570   [(set (match_dup 0) (match_dup 4))
7571    (set (match_dup 3)
7572         (compare:CC (match_dup 0)
7573                     (const_int 0)))]
7574   "")
7575
7576 ;; Split a logical operation that we can't do in one insn into two insns,
7577 ;; each of which does one 16-bit part.  This is used by combine.
7578
7579 (define_split
7580   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7581         (match_operator:DI 3 "boolean_or_operator"
7582          [(match_operand:DI 1 "gpc_reg_operand" "")
7583           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
7584   "TARGET_POWERPC64"
7585   [(set (match_dup 0) (match_dup 4))
7586    (set (match_dup 0) (match_dup 5))]
7587 "
7588 {
7589   rtx i3,i4;
7590
7591   if (GET_CODE (operands[2]) == CONST_DOUBLE)
7592     {
7593       HOST_WIDE_INT value = CONST_DOUBLE_LOW (operands[2]);
7594       i3 = immed_double_const (value & (~ (HOST_WIDE_INT) 0xffff),
7595                                         0, DImode);
7596       i4 = GEN_INT (value & 0xffff);
7597     }
7598   else
7599     {
7600       i3 = GEN_INT (INTVAL (operands[2])
7601                              & (~ (HOST_WIDE_INT) 0xffff));
7602       i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
7603     }
7604   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7605                                 operands[1], i3);
7606   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7607                                 operands[0], i4);
7608 }")
7609
7610 (define_insn "*boolcdi3_internal1"
7611   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7612         (match_operator:DI 3 "boolean_operator"
7613          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7614           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
7615   "TARGET_POWERPC64"
7616   "%q3 %0,%2,%1")
7617
7618 (define_insn "*boolcdi3_internal2"
7619   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7620         (compare:CC (match_operator:DI 4 "boolean_operator"
7621          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7622           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7623          (const_int 0)))
7624    (clobber (match_scratch:DI 3 "=r,r"))]
7625   "TARGET_64BIT"
7626   "@
7627    %q4. %3,%2,%1
7628    #"
7629   [(set_attr "type" "compare")
7630    (set_attr "length" "4,8")])
7631
7632 (define_split
7633   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7634         (compare:CC (match_operator:DI 4 "boolean_operator"
7635          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7636           (match_operand:DI 2 "gpc_reg_operand" "")])
7637          (const_int 0)))
7638    (clobber (match_scratch:DI 3 ""))]
7639   "TARGET_POWERPC64 && reload_completed"
7640   [(set (match_dup 3) (match_dup 4))
7641    (set (match_dup 0)
7642         (compare:CC (match_dup 3)
7643                     (const_int 0)))]
7644   "")
7645
7646 (define_insn "*boolcdi3_internal3"
7647   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7648         (compare:CC (match_operator:DI 4 "boolean_operator"
7649          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7650           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7651          (const_int 0)))
7652    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7653         (match_dup 4))]
7654   "TARGET_64BIT"
7655   "@
7656    %q4. %0,%2,%1
7657    #"
7658   [(set_attr "type" "compare")
7659    (set_attr "length" "4,8")])
7660
7661 (define_split
7662   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7663         (compare:CC (match_operator:DI 4 "boolean_operator"
7664          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7665           (match_operand:DI 2 "gpc_reg_operand" "")])
7666          (const_int 0)))
7667    (set (match_operand:DI 0 "gpc_reg_operand" "")
7668         (match_dup 4))]
7669   "TARGET_POWERPC64 && reload_completed"
7670   [(set (match_dup 0) (match_dup 4))
7671    (set (match_dup 3)
7672         (compare:CC (match_dup 0)
7673                     (const_int 0)))]
7674   "")
7675
7676 (define_insn "*boolccdi3_internal1"
7677   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7678         (match_operator:DI 3 "boolean_operator"
7679          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7680           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
7681   "TARGET_POWERPC64"
7682   "%q3 %0,%1,%2")
7683
7684 (define_insn "*boolccdi3_internal2"
7685   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7686         (compare:CC (match_operator:DI 4 "boolean_operator"
7687          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7688           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7689          (const_int 0)))
7690    (clobber (match_scratch:DI 3 "=r,r"))]
7691   "TARGET_64BIT"
7692   "@
7693    %q4. %3,%1,%2
7694    #"
7695   [(set_attr "type" "compare")
7696    (set_attr "length" "4,8")])
7697
7698 (define_split
7699   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7700         (compare:CC (match_operator:DI 4 "boolean_operator"
7701          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7702           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7703          (const_int 0)))
7704    (clobber (match_scratch:DI 3 ""))]
7705   "TARGET_POWERPC64 && reload_completed"
7706   [(set (match_dup 3) (match_dup 4))
7707    (set (match_dup 0)
7708         (compare:CC (match_dup 3)
7709                     (const_int 0)))]
7710   "")
7711
7712 (define_insn "*boolccdi3_internal3"
7713   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7714         (compare:CC (match_operator:DI 4 "boolean_operator"
7715          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7716           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7717          (const_int 0)))
7718    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7719         (match_dup 4))]
7720   "TARGET_64BIT"
7721   "@
7722    %q4. %0,%1,%2
7723    #"
7724   [(set_attr "type" "compare")
7725    (set_attr "length" "4,8")])
7726
7727 (define_split
7728   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7729         (compare:CC (match_operator:DI 4 "boolean_operator"
7730          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7731           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7732          (const_int 0)))
7733    (set (match_operand:DI 0 "gpc_reg_operand" "")
7734         (match_dup 4))]
7735   "TARGET_POWERPC64 && reload_completed"
7736   [(set (match_dup 0) (match_dup 4))
7737    (set (match_dup 3)
7738         (compare:CC (match_dup 0)
7739                     (const_int 0)))]
7740   "")
7741 \f
7742 ;; Now define ways of moving data around.
7743
7744 ;; Set up a register with a value from the GOT table
7745
7746 (define_expand "movsi_got"
7747   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7748         (unspec:SI [(match_operand:SI 1 "got_operand" "")
7749                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
7750   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7751   "
7752 {
7753   if (GET_CODE (operands[1]) == CONST)
7754     {
7755       rtx offset = const0_rtx;
7756       HOST_WIDE_INT value;
7757
7758       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
7759       value = INTVAL (offset);
7760       if (value != 0)
7761         {
7762           rtx tmp = (no_new_pseudos ? operands[0] : gen_reg_rtx (Pmode));
7763           emit_insn (gen_movsi_got (tmp, operands[1]));
7764           emit_insn (gen_addsi3 (operands[0], tmp, offset));
7765           DONE;
7766         }
7767     }
7768
7769   operands[2] = rs6000_got_register (operands[1]);
7770 }")
7771
7772 (define_insn "*movsi_got_internal"
7773   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7774         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7775                     (match_operand:SI 2 "gpc_reg_operand" "b")]
7776                    UNSPEC_MOVSI_GOT))]
7777   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7778   "{l|lwz} %0,%a1@got(%2)"
7779   [(set_attr "type" "load")])
7780
7781 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
7782 ;; didn't get allocated to a hard register.
7783 (define_split
7784   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7785         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7786                     (match_operand:SI 2 "memory_operand" "")]
7787                    UNSPEC_MOVSI_GOT))]
7788   "DEFAULT_ABI == ABI_V4
7789     && flag_pic == 1
7790     && (reload_in_progress || reload_completed)"
7791   [(set (match_dup 0) (match_dup 2))
7792    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
7793                                  UNSPEC_MOVSI_GOT))]
7794   "")
7795
7796 ;; For SI, we special-case integers that can't be loaded in one insn.  We
7797 ;; do the load 16-bits at a time.  We could do this by loading from memory,
7798 ;; and this is even supposed to be faster, but it is simpler not to get
7799 ;; integers in the TOC.
7800 (define_insn "movsi_low"
7801   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7802         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7803                            (match_operand 2 "" ""))))]
7804   "TARGET_MACHO && ! TARGET_64BIT"
7805   "{l|lwz} %0,lo16(%2)(%1)"
7806   [(set_attr "type" "load")
7807    (set_attr "length" "4")])
7808
7809 (define_insn "*movsi_internal1"
7810   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h")
7811         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0"))]
7812   "gpc_reg_operand (operands[0], SImode)
7813    || gpc_reg_operand (operands[1], SImode)"
7814   "@
7815    mr %0,%1
7816    {cal|la} %0,%a1
7817    {l%U1%X1|lwz%U1%X1} %0,%1
7818    {st%U0%X0|stw%U0%X0} %1,%0
7819    {lil|li} %0,%1
7820    {liu|lis} %0,%v1
7821    #
7822    {cal|la} %0,%a1
7823    mf%1 %0
7824    mt%0 %1
7825    mt%0 %1
7826    mt%0 %1
7827    {cror 0,0,0|nop}"
7828   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*")
7829    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
7830
7831 ;; Split a load of a large constant into the appropriate two-insn
7832 ;; sequence.
7833
7834 (define_split
7835   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7836         (match_operand:SI 1 "const_int_operand" ""))]
7837   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
7838    && (INTVAL (operands[1]) & 0xffff) != 0"
7839   [(set (match_dup 0)
7840         (match_dup 2))
7841    (set (match_dup 0)
7842         (ior:SI (match_dup 0)
7843                 (match_dup 3)))]
7844   "
7845 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
7846
7847   if (tem == operands[0])
7848     DONE;
7849   else
7850     FAIL;
7851 }")
7852
7853 (define_insn "*mov<mode>_internal2"
7854   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
7855         (compare:CC (match_operand:P 1 "gpc_reg_operand" "0,r,r")
7856                     (const_int 0)))
7857    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
7858   ""
7859   "@
7860    {cmpi|cmp<wd>i} %2,%0,0
7861    mr. %0,%1
7862    #"
7863   [(set_attr "type" "cmp,compare,cmp")
7864    (set_attr "length" "4,4,8")])
7865
7866 (define_split
7867   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
7868         (compare:CC (match_operand:P 1 "gpc_reg_operand" "")
7869                     (const_int 0)))
7870    (set (match_operand:P 0 "gpc_reg_operand" "") (match_dup 1))]
7871   "reload_completed"
7872   [(set (match_dup 0) (match_dup 1))
7873    (set (match_dup 2)
7874         (compare:CC (match_dup 0)
7875                     (const_int 0)))]
7876   "")
7877 \f
7878 (define_insn "*movhi_internal"
7879   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7880         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7881   "gpc_reg_operand (operands[0], HImode)
7882    || gpc_reg_operand (operands[1], HImode)"
7883   "@
7884    mr %0,%1
7885    lhz%U1%X1 %0,%1
7886    sth%U0%X0 %1,%0
7887    {lil|li} %0,%w1
7888    mf%1 %0
7889    mt%0 %1
7890    mt%0 %1
7891    {cror 0,0,0|nop}"
7892   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7893
7894 (define_expand "mov<mode>"
7895   [(set (match_operand:INT 0 "general_operand" "")
7896         (match_operand:INT 1 "any_operand" ""))]
7897   ""
7898   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
7899
7900 (define_insn "*movqi_internal"
7901   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7902         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7903   "gpc_reg_operand (operands[0], QImode)
7904    || gpc_reg_operand (operands[1], QImode)"
7905   "@
7906    mr %0,%1
7907    lbz%U1%X1 %0,%1
7908    stb%U0%X0 %1,%0
7909    {lil|li} %0,%1
7910    mf%1 %0
7911    mt%0 %1
7912    mt%0 %1
7913    {cror 0,0,0|nop}"
7914   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7915 \f
7916 ;; Here is how to move condition codes around.  When we store CC data in
7917 ;; an integer register or memory, we store just the high-order 4 bits.
7918 ;; This lets us not shift in the most common case of CR0.
7919 (define_expand "movcc"
7920   [(set (match_operand:CC 0 "nonimmediate_operand" "")
7921         (match_operand:CC 1 "nonimmediate_operand" ""))]
7922   ""
7923   "")
7924
7925 (define_insn "*movcc_internal1"
7926   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,y,r,r,r,r,r,q,cl,r,m")
7927         (match_operand:CC 1 "general_operand" "y,r,r,O,x,y,r,I,h,r,r,m,r"))]
7928   "register_operand (operands[0], CCmode)
7929    || register_operand (operands[1], CCmode)"
7930   "@
7931    mcrf %0,%1
7932    mtcrf 128,%1
7933    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
7934    crxor %0,%0,%0
7935    mfcr %0%Q1
7936    mfcr %0%Q1\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
7937    mr %0,%1
7938    {lil|li} %0,%1
7939    mf%1 %0
7940    mt%0 %1
7941    mt%0 %1
7942    {l%U1%X1|lwz%U1%X1} %0,%1
7943    {st%U0%U1|stw%U0%U1} %1,%0"
7944   [(set (attr "type")
7945      (cond [(eq_attr "alternative" "0,3")
7946                 (const_string "cr_logical")
7947             (eq_attr "alternative" "1,2")
7948                 (const_string "mtcr")
7949             (eq_attr "alternative" "6,7,9")
7950                 (const_string "integer")
7951             (eq_attr "alternative" "8")
7952                 (const_string "mfjmpr")
7953             (eq_attr "alternative" "10")
7954                 (const_string "mtjmpr")
7955             (eq_attr "alternative" "11")
7956                 (const_string "load")
7957             (eq_attr "alternative" "12")
7958                 (const_string "store")
7959             (ne (symbol_ref "TARGET_MFCRF") (const_int 0))
7960                 (const_string "mfcrf")
7961            ]
7962         (const_string "mfcr")))
7963    (set_attr "length" "4,4,12,4,4,8,4,4,4,4,4,4,4")])
7964 \f
7965 ;; For floating-point, we normally deal with the floating-point registers
7966 ;; unless -msoft-float is used.  The sole exception is that parameter passing
7967 ;; can produce floating-point values in fixed-point registers.  Unless the
7968 ;; value is a simple constant or already in memory, we deal with this by
7969 ;; allocating memory and copying the value explicitly via that memory location.
7970 (define_expand "movsf"
7971   [(set (match_operand:SF 0 "nonimmediate_operand" "")
7972         (match_operand:SF 1 "any_operand" ""))]
7973   ""
7974   "{ rs6000_emit_move (operands[0], operands[1], SFmode); DONE; }")
7975
7976 (define_split
7977   [(set (match_operand:SF 0 "gpc_reg_operand" "")
7978         (match_operand:SF 1 "const_double_operand" ""))]
7979   "reload_completed
7980    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7981        || (GET_CODE (operands[0]) == SUBREG
7982            && GET_CODE (SUBREG_REG (operands[0])) == REG
7983            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7984   [(set (match_dup 2) (match_dup 3))]
7985   "
7986 {
7987   long l;
7988   REAL_VALUE_TYPE rv;
7989
7990   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7991   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
7992
7993   if (! TARGET_POWERPC64)
7994     operands[2] = operand_subword (operands[0], 0, 0, SFmode);
7995   else
7996     operands[2] = gen_lowpart (SImode, operands[0]);
7997
7998   operands[3] = gen_int_mode (l, SImode);
7999 }")
8000
8001 (define_insn "*movsf_hardfloat"
8002   [(set (match_operand:SF 0 "nonimmediate_operand" "=!r,!r,m,f,f,m,*c*l,*q,!r,*h,!r,!r")
8003         (match_operand:SF 1 "input_operand" "r,m,r,f,m,f,r,r,h,0,G,Fn"))]
8004   "(gpc_reg_operand (operands[0], SFmode)
8005    || gpc_reg_operand (operands[1], SFmode))
8006    && (TARGET_HARD_FLOAT && TARGET_FPRS)"
8007   "@
8008    mr %0,%1
8009    {l%U1%X1|lwz%U1%X1} %0,%1
8010    {st%U0%X0|stw%U0%X0} %1,%0
8011    fmr %0,%1
8012    lfs%U1%X1 %0,%1
8013    stfs%U0%X0 %1,%0
8014    mt%0 %1
8015    mt%0 %1
8016    mf%1 %0
8017    {cror 0,0,0|nop}
8018    #
8019    #"
8020   [(set_attr "type" "*,load,store,fp,fpload,fpstore,mtjmpr,*,mfjmpr,*,*,*")
8021    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,8")])
8022
8023 (define_insn "*movsf_softfloat"
8024   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,cl,q,r,r,m,r,r,r,r,r,*h")
8025         (match_operand:SF 1 "input_operand" "r,r,r,h,m,r,I,L,R,G,Fn,0"))]
8026   "(gpc_reg_operand (operands[0], SFmode)
8027    || gpc_reg_operand (operands[1], SFmode))
8028    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
8029   "@
8030    mr %0,%1
8031    mt%0 %1
8032    mt%0 %1
8033    mf%1 %0
8034    {l%U1%X1|lwz%U1%X1} %0,%1
8035    {st%U0%X0|stw%U0%X0} %1,%0
8036    {lil|li} %0,%1
8037    {liu|lis} %0,%v1
8038    {cal|la} %0,%a1
8039    #
8040    #
8041    {cror 0,0,0|nop}"
8042   [(set_attr "type" "*,mtjmpr,*,mfjmpr,load,store,*,*,*,*,*,*")
8043    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,4")])
8044
8045 \f
8046 (define_expand "movdf"
8047   [(set (match_operand:DF 0 "nonimmediate_operand" "")
8048         (match_operand:DF 1 "any_operand" ""))]
8049   ""
8050   "{ rs6000_emit_move (operands[0], operands[1], DFmode); DONE; }")
8051
8052 (define_split
8053   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8054         (match_operand:DF 1 "const_int_operand" ""))]
8055   "! TARGET_POWERPC64 && reload_completed
8056    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8057        || (GET_CODE (operands[0]) == SUBREG
8058            && GET_CODE (SUBREG_REG (operands[0])) == REG
8059            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8060   [(set (match_dup 2) (match_dup 4))
8061    (set (match_dup 3) (match_dup 1))]
8062   "
8063 {
8064   int endian = (WORDS_BIG_ENDIAN == 0);
8065   HOST_WIDE_INT value = INTVAL (operands[1]);
8066
8067   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
8068   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
8069 #if HOST_BITS_PER_WIDE_INT == 32
8070   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8071 #else
8072   operands[4] = GEN_INT (value >> 32);
8073   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8074 #endif
8075 }")
8076
8077 (define_split
8078   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8079         (match_operand:DF 1 "const_double_operand" ""))]
8080   "! TARGET_POWERPC64 && reload_completed
8081    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8082        || (GET_CODE (operands[0]) == SUBREG
8083            && GET_CODE (SUBREG_REG (operands[0])) == REG
8084            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8085   [(set (match_dup 2) (match_dup 4))
8086    (set (match_dup 3) (match_dup 5))]
8087   "
8088 {
8089   int endian = (WORDS_BIG_ENDIAN == 0);
8090   long l[2];
8091   REAL_VALUE_TYPE rv;
8092
8093   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8094   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8095
8096   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
8097   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
8098   operands[4] = gen_int_mode (l[endian], SImode);
8099   operands[5] = gen_int_mode (l[1 - endian], SImode);
8100 }")
8101
8102 (define_split
8103   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8104         (match_operand:DF 1 "const_double_operand" ""))]
8105   "TARGET_POWERPC64 && reload_completed
8106    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8107        || (GET_CODE (operands[0]) == SUBREG
8108            && GET_CODE (SUBREG_REG (operands[0])) == REG
8109            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8110   [(set (match_dup 2) (match_dup 3))]
8111   "
8112 {
8113   int endian = (WORDS_BIG_ENDIAN == 0);
8114   long l[2];
8115   REAL_VALUE_TYPE rv;
8116 #if HOST_BITS_PER_WIDE_INT >= 64
8117   HOST_WIDE_INT val;
8118 #endif
8119
8120   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8121   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8122
8123   operands[2] = gen_lowpart (DImode, operands[0]);
8124   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
8125 #if HOST_BITS_PER_WIDE_INT >= 64
8126   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
8127          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
8128
8129   operands[3] = gen_int_mode (val, DImode);
8130 #else
8131   operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
8132 #endif
8133 }")
8134
8135 ;; Don't have reload use general registers to load a constant.  First,
8136 ;; it might not work if the output operand is the equivalent of
8137 ;; a non-offsettable memref, but also it is less efficient than loading
8138 ;; the constant into an FP register, since it will probably be used there.
8139 ;; The "??" is a kludge until we can figure out a more reasonable way
8140 ;; of handling these non-offsettable values.
8141 (define_insn "*movdf_hardfloat32"
8142   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,m,f,f,m,!r,!r,!r")
8143         (match_operand:DF 1 "input_operand" "r,m,r,f,m,f,G,H,F"))]
8144   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8145    && (gpc_reg_operand (operands[0], DFmode)
8146        || gpc_reg_operand (operands[1], DFmode))"
8147   "*
8148 {
8149   switch (which_alternative)
8150     {
8151     default:
8152       gcc_unreachable ();
8153     case 0:
8154       /* We normally copy the low-numbered register first.  However, if
8155          the first register operand 0 is the same as the second register
8156          of operand 1, we must copy in the opposite order.  */
8157       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8158         return \"mr %L0,%L1\;mr %0,%1\";
8159       else
8160         return \"mr %0,%1\;mr %L0,%L1\";
8161     case 1:
8162       if (rs6000_offsettable_memref_p (operands[1])
8163           || (GET_CODE (operands[1]) == MEM
8164               && (GET_CODE (XEXP (operands[1], 0)) == LO_SUM
8165                   || GET_CODE (XEXP (operands[1], 0)) == PRE_INC
8166                   || GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)))
8167         {
8168           /* If the low-address word is used in the address, we must load
8169              it last.  Otherwise, load it first.  Note that we cannot have
8170              auto-increment in that case since the address register is
8171              known to be dead.  */
8172           if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8173                                  operands[1], 0))
8174             return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8175           else
8176             return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8177         }
8178       else
8179         {
8180           rtx addreg;
8181
8182           addreg = find_addr_reg (XEXP (operands[1], 0));
8183           if (refers_to_regno_p (REGNO (operands[0]),
8184                                  REGNO (operands[0]) + 1,
8185                                  operands[1], 0))
8186             {
8187               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8188               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
8189               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8190               return \"{lx|lwzx} %0,%1\";
8191             }
8192           else
8193             {
8194               output_asm_insn (\"{lx|lwzx} %0,%1\", operands);
8195               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8196               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
8197               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8198               return \"\";
8199             }
8200         }
8201     case 2:
8202       if (rs6000_offsettable_memref_p (operands[0])
8203           || (GET_CODE (operands[0]) == MEM
8204               && (GET_CODE (XEXP (operands[0], 0)) == LO_SUM
8205                   || GET_CODE (XEXP (operands[0], 0)) == PRE_INC
8206                   || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)))
8207         return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8208       else
8209         {
8210           rtx addreg;
8211
8212           addreg = find_addr_reg (XEXP (operands[0], 0));
8213           output_asm_insn (\"{stx|stwx} %1,%0\", operands);
8214           output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8215           output_asm_insn (\"{stx|stwx} %L1,%0\", operands);
8216           output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8217           return \"\";
8218         }
8219     case 3:
8220       return \"fmr %0,%1\";
8221     case 4:
8222       return \"lfd%U1%X1 %0,%1\";
8223     case 5:
8224       return \"stfd%U0%X0 %1,%0\";
8225     case 6:
8226     case 7:
8227     case 8:
8228       return \"#\";
8229     }
8230 }"
8231   [(set_attr "type" "two,load,store,fp,fpload,fpstore,*,*,*")
8232    (set_attr "length" "8,16,16,4,4,4,8,12,16")])
8233
8234 (define_insn "*movdf_softfloat32"
8235   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
8236         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F"))]
8237   "! TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || TARGET_E500_SINGLE)
8238    && (gpc_reg_operand (operands[0], DFmode)
8239        || gpc_reg_operand (operands[1], DFmode))"
8240   "*
8241 {
8242   switch (which_alternative)
8243     {
8244     default:
8245       gcc_unreachable ();
8246     case 0:
8247       /* We normally copy the low-numbered register first.  However, if
8248          the first register operand 0 is the same as the second register of
8249          operand 1, we must copy in the opposite order.  */
8250       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8251         return \"mr %L0,%L1\;mr %0,%1\";
8252       else
8253         return \"mr %0,%1\;mr %L0,%L1\";
8254     case 1:
8255       /* If the low-address word is used in the address, we must load
8256          it last.  Otherwise, load it first.  Note that we cannot have
8257          auto-increment in that case since the address register is
8258          known to be dead.  */
8259       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8260                              operands[1], 0))
8261         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8262       else
8263         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8264     case 2:
8265       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8266     case 3:
8267     case 4:
8268     case 5:
8269       return \"#\";
8270     }
8271 }"
8272   [(set_attr "type" "two,load,store,*,*,*")
8273    (set_attr "length" "8,8,8,8,12,16")])
8274
8275 ; ld/std require word-aligned displacements -> 'Y' constraint.
8276 ; List Y->r and r->Y before r->r for reload.
8277 (define_insn "*movdf_hardfloat64"
8278   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,!r,f,f,m,*c*l,!r,*h,!r,!r,!r")
8279         (match_operand:DF 1 "input_operand" "r,Y,r,f,m,f,r,h,0,G,H,F"))]
8280   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8281    && (gpc_reg_operand (operands[0], DFmode)
8282        || gpc_reg_operand (operands[1], DFmode))"
8283   "@
8284    std%U0%X0 %1,%0
8285    ld%U1%X1 %0,%1
8286    mr %0,%1
8287    fmr %0,%1
8288    lfd%U1%X1 %0,%1
8289    stfd%U0%X0 %1,%0
8290    mt%0 %1
8291    mf%1 %0
8292    {cror 0,0,0|nop}
8293    #
8294    #
8295    #"
8296   [(set_attr "type" "store,load,*,fp,fpload,fpstore,mtjmpr,mfjmpr,*,*,*,*")
8297    (set_attr "length" "4,4,4,4,4,4,4,4,4,8,12,16")])
8298
8299 (define_insn "*movdf_softfloat64"
8300   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,Y,r,cl,r,r,r,r,*h")
8301         (match_operand:DF 1 "input_operand" "Y,r,r,r,h,G,H,F,0"))]
8302   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8303    && (gpc_reg_operand (operands[0], DFmode)
8304        || gpc_reg_operand (operands[1], DFmode))"
8305   "@
8306    ld%U1%X1 %0,%1
8307    std%U0%X0 %1,%0
8308    mr %0,%1
8309    mt%0 %1
8310    mf%1 %0
8311    #
8312    #
8313    #
8314    {cror 0,0,0|nop}"
8315   [(set_attr "type" "load,store,*,mtjmpr,mfjmpr,*,*,*,*")
8316    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
8317 \f
8318 (define_expand "movtf"
8319   [(set (match_operand:TF 0 "general_operand" "")
8320         (match_operand:TF 1 "any_operand" ""))]
8321   "!TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128"
8322   "{ rs6000_emit_move (operands[0], operands[1], TFmode); DONE; }")
8323
8324 ; It's important to list the o->f and f->o moves before f->f because
8325 ; otherwise reload, given m->f, will try to pick f->f and reload it,
8326 ; which doesn't make progress.  Likewise r->Y must be before r->r.
8327 (define_insn_and_split "*movtf_internal"
8328   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,f,r,Y,r")
8329         (match_operand:TF 1 "input_operand"         "f,o,f,YGHF,r,r"))]
8330   "!TARGET_IEEEQUAD
8331    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
8332    && (gpc_reg_operand (operands[0], TFmode)
8333        || gpc_reg_operand (operands[1], TFmode))"
8334   "#"
8335   "&& reload_completed"
8336   [(pc)]
8337 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
8338   [(set_attr "length" "8,8,8,20,20,16")])
8339
8340 (define_insn_and_split "*movtf_softfloat"
8341   [(set (match_operand:TF 0 "nonimmediate_operand" "=r,Y,r")
8342         (match_operand:TF 1 "input_operand"         "YGHF,r,r"))]
8343   "!TARGET_IEEEQUAD
8344    && (TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_LONG_DOUBLE_128
8345    && (gpc_reg_operand (operands[0], TFmode)
8346        || gpc_reg_operand (operands[1], TFmode))"
8347   "#"
8348   "&& reload_completed"
8349   [(pc)]
8350 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
8351   [(set_attr "length" "20,20,16")])
8352
8353 (define_expand "extenddftf2"
8354   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
8355                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
8356               (use (match_dup 2))])]
8357   "!TARGET_IEEEQUAD
8358    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8359 {
8360   operands[2] = CONST0_RTX (DFmode);
8361   /* Generate GOT reference early for SVR4 PIC.  */
8362   if (DEFAULT_ABI == ABI_V4 && flag_pic)
8363     operands[2] = validize_mem (force_const_mem (DFmode, operands[2]));
8364 })
8365
8366 (define_insn_and_split "*extenddftf2_internal"
8367   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,&f,r")
8368        (float_extend:TF (match_operand:DF 1 "input_operand" "fr,mf,mf,rmGHF")))
8369    (use (match_operand:DF 2 "zero_reg_mem_operand" "rf,m,f,n"))]
8370   "!TARGET_IEEEQUAD
8371    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8372   "#"
8373   "&& reload_completed"
8374   [(pc)]
8375 {
8376   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8377   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8378   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
8379                   operands[1]);
8380   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
8381                   operands[2]);
8382   DONE;
8383 })
8384
8385 (define_expand "extendsftf2"
8386   [(set (match_operand:TF 0 "nonimmediate_operand" "")
8387         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
8388   "!TARGET_IEEEQUAD
8389    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8390 {
8391   rtx tmp = gen_reg_rtx (DFmode);
8392   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
8393   emit_insn (gen_extenddftf2 (operands[0], tmp));
8394   DONE;
8395 })
8396
8397 (define_expand "trunctfdf2"
8398   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8399         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))]
8400   "!TARGET_IEEEQUAD
8401    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8402   "")
8403
8404 (define_insn_and_split "trunctfdf2_internal1"
8405   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,?f")
8406         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "0,f")))]
8407   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
8408    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8409   "@
8410    #
8411    fmr %0,%1"
8412   "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
8413   [(const_int 0)]
8414 {
8415   emit_note (NOTE_INSN_DELETED);
8416   DONE;
8417 }
8418   [(set_attr "type" "fp")])
8419
8420 (define_insn "trunctfdf2_internal2"
8421   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8422         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8423   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
8424    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8425   "fadd %0,%1,%L1"
8426   [(set_attr "type" "fp")])
8427
8428 (define_insn_and_split "trunctfsf2"
8429   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
8430         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "f")))
8431    (clobber (match_scratch:DF 2 "=f"))]
8432   "!TARGET_IEEEQUAD
8433    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8434   "#"
8435   "&& reload_completed"
8436   [(set (match_dup 2)
8437         (float_truncate:DF (match_dup 1)))
8438    (set (match_dup 0)
8439         (float_truncate:SF (match_dup 2)))]
8440   "")
8441
8442 (define_expand "floatsitf2"
8443   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8444         (float:TF (match_operand:SI 1 "gpc_reg_operand" "")))]
8445   "!TARGET_IEEEQUAD
8446    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8447 {
8448   rtx tmp = gen_reg_rtx (DFmode);
8449   expand_float (tmp, operands[1], false);
8450   emit_insn (gen_extenddftf2 (operands[0], tmp));
8451   DONE;
8452 })
8453
8454 ; fadd, but rounding towards zero.
8455 ; This is probably not the optimal code sequence.
8456 (define_insn "fix_trunc_helper"
8457   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8458         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "f")]
8459                    UNSPEC_FIX_TRUNC_TF))
8460    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&f"))]
8461   "TARGET_HARD_FLOAT && TARGET_FPRS"
8462   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
8463   [(set_attr "type" "fp")
8464    (set_attr "length" "20")])
8465
8466 (define_expand "fix_trunctfsi2"
8467   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
8468                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
8469               (clobber (match_dup 2))
8470               (clobber (match_dup 3))
8471               (clobber (match_dup 4))
8472               (clobber (match_dup 5))])]
8473   "!TARGET_IEEEQUAD
8474    && (TARGET_POWER2 || TARGET_POWERPC)
8475    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8476 {
8477   operands[2] = gen_reg_rtx (DFmode);
8478   operands[3] = gen_reg_rtx (DFmode);
8479   operands[4] = gen_reg_rtx (DImode);
8480   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
8481 })
8482
8483 (define_insn_and_split "*fix_trunctfsi2_internal"
8484   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8485         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "f")))
8486    (clobber (match_operand:DF 2 "gpc_reg_operand" "=f"))
8487    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&f"))
8488    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))
8489    (clobber (match_operand:DI 5 "memory_operand" "=o"))]
8490   "!TARGET_IEEEQUAD
8491    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8492   "#"
8493   "&& (!no_new_pseudos || offsettable_nonstrict_memref_p (operands[5]))"
8494   [(pc)]
8495 {
8496   rtx lowword;
8497   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
8498
8499   gcc_assert (MEM_P (operands[5]));
8500   lowword = adjust_address (operands[5], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
8501
8502   emit_insn (gen_fctiwz (operands[4], operands[2]));
8503   emit_move_insn (operands[5], operands[4]);
8504   emit_move_insn (operands[0], lowword);
8505   DONE;
8506 })
8507
8508 (define_insn "negtf2"
8509   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8510         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8511   "!TARGET_IEEEQUAD
8512    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8513   "*
8514 {
8515   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8516     return \"fneg %L0,%L1\;fneg %0,%1\";
8517   else
8518     return \"fneg %0,%1\;fneg %L0,%L1\";
8519 }"
8520   [(set_attr "type" "fp")
8521    (set_attr "length" "8")])
8522
8523 (define_expand "abstf2"
8524   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8525         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8526   "!TARGET_IEEEQUAD
8527    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8528   "
8529 {
8530   rtx label = gen_label_rtx ();
8531   emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
8532   emit_label (label);
8533   DONE;
8534 }")
8535
8536 (define_expand "abstf2_internal"
8537   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8538         (match_operand:TF 1 "gpc_reg_operand" "f"))
8539    (set (match_dup 3) (match_dup 5))
8540    (set (match_dup 5) (abs:DF (match_dup 5)))
8541    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
8542    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
8543                            (label_ref (match_operand 2 "" ""))
8544                            (pc)))
8545    (set (match_dup 6) (neg:DF (match_dup 6)))]
8546   "!TARGET_IEEEQUAD
8547    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8548   "
8549 {
8550   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8551   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8552   operands[3] = gen_reg_rtx (DFmode);
8553   operands[4] = gen_reg_rtx (CCFPmode);
8554   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
8555   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
8556 }")
8557 \f
8558 ;; Next come the multi-word integer load and store and the load and store
8559 ;; multiple insns.
8560
8561 ; List r->r after r->"o<>", otherwise reload will try to reload a
8562 ; non-offsettable address by using r->r which won't make progress.
8563 (define_insn "*movdi_internal32"
8564   [(set (match_operand:DI 0 "nonimmediate_operand" "=o<>,r,r,*f,*f,m,r")
8565         (match_operand:DI 1 "input_operand" "r,r,m,f,m,f,IJKnGHF"))]
8566   "! TARGET_POWERPC64
8567    && (gpc_reg_operand (operands[0], DImode)
8568        || gpc_reg_operand (operands[1], DImode))"
8569   "@
8570    #
8571    #
8572    #
8573    fmr %0,%1
8574    lfd%U1%X1 %0,%1
8575    stfd%U0%X0 %1,%0
8576    #"
8577   [(set_attr "type" "load,*,store,fp,fpload,fpstore,*")])
8578
8579 (define_split
8580   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8581         (match_operand:DI 1 "const_int_operand" ""))]
8582   "! TARGET_POWERPC64 && reload_completed"
8583   [(set (match_dup 2) (match_dup 4))
8584    (set (match_dup 3) (match_dup 1))]
8585   "
8586 {
8587   HOST_WIDE_INT value = INTVAL (operands[1]);
8588   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8589                                        DImode);
8590   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8591                                        DImode);
8592 #if HOST_BITS_PER_WIDE_INT == 32
8593   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8594 #else
8595   operands[4] = GEN_INT (value >> 32);
8596   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8597 #endif
8598 }")
8599
8600 (define_split
8601   [(set (match_operand:DI 0 "nonimmediate_operand" "")
8602         (match_operand:DI 1 "input_operand" ""))]
8603   "reload_completed && !TARGET_POWERPC64
8604    && gpr_or_gpr_p (operands[0], operands[1])"
8605   [(pc)]
8606 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8607
8608 (define_insn "*movdi_internal64"
8609   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,*f,*f,m,r,*h,*h")
8610         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,f,m,f,*h,r,0"))]
8611   "TARGET_POWERPC64
8612    && (gpc_reg_operand (operands[0], DImode)
8613        || gpc_reg_operand (operands[1], DImode))"
8614   "@
8615    mr %0,%1
8616    ld%U1%X1 %0,%1
8617    std%U0%X0 %1,%0
8618    li %0,%1
8619    lis %0,%v1
8620    #
8621    {cal|la} %0,%a1
8622    fmr %0,%1
8623    lfd%U1%X1 %0,%1
8624    stfd%U0%X0 %1,%0
8625    mf%1 %0
8626    mt%0 %1
8627    {cror 0,0,0|nop}"
8628   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*")
8629    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4")])
8630
8631 ;; immediate value valid for a single instruction hiding in a const_double
8632 (define_insn ""
8633   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8634         (match_operand:DI 1 "const_double_operand" "F"))]
8635   "HOST_BITS_PER_WIDE_INT == 32 && TARGET_POWERPC64
8636    && GET_CODE (operands[1]) == CONST_DOUBLE
8637    && num_insns_constant (operands[1], DImode) == 1"
8638   "*
8639 {
8640   return ((unsigned HOST_WIDE_INT)
8641           (CONST_DOUBLE_LOW (operands[1]) + 0x8000) < 0x10000)
8642          ? \"li %0,%1\" : \"lis %0,%v1\";
8643 }")
8644
8645 ;; Generate all one-bits and clear left or right.
8646 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
8647 (define_split
8648   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8649         (match_operand:DI 1 "mask64_operand" ""))]
8650   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8651   [(set (match_dup 0) (const_int -1))
8652    (set (match_dup 0)
8653         (and:DI (rotate:DI (match_dup 0)
8654                            (const_int 0))
8655                 (match_dup 1)))]
8656   "")
8657
8658 ;; Split a load of a large constant into the appropriate five-instruction
8659 ;; sequence.  Handle anything in a constant number of insns.
8660 ;; When non-easy constants can go in the TOC, this should use
8661 ;; easy_fp_constant predicate.
8662 (define_split
8663   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8664         (match_operand:DI 1 "const_int_operand" ""))]
8665   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8666   [(set (match_dup 0) (match_dup 2))
8667    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8668   "
8669 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8670
8671   if (tem == operands[0])
8672     DONE;
8673   else
8674     FAIL;
8675 }")
8676
8677 (define_split
8678   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8679         (match_operand:DI 1 "const_double_operand" ""))]
8680   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8681   [(set (match_dup 0) (match_dup 2))
8682    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8683   "
8684 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8685
8686   if (tem == operands[0])
8687     DONE;
8688   else
8689     FAIL;
8690 }")
8691 \f
8692 ;; TImode is similar, except that we usually want to compute the address into
8693 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
8694 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
8695
8696 ;; We say that MQ is clobbered in the last alternative because the first
8697 ;; alternative would never get used otherwise since it would need a reload
8698 ;; while the 2nd alternative would not.  We put memory cases first so they
8699 ;; are preferred.  Otherwise, we'd try to reload the output instead of
8700 ;; giving the SCRATCH mq.
8701
8702 (define_insn "*movti_power"
8703   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r,r")
8704         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))
8705    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X,X"))]
8706   "TARGET_POWER && ! TARGET_POWERPC64
8707    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8708   "*
8709 {
8710   switch (which_alternative)
8711     {
8712     default:
8713       gcc_unreachable ();
8714
8715     case 0:
8716       if (TARGET_STRING)
8717         return \"{stsi|stswi} %1,%P0,16\";
8718     case 1:
8719     case 2:
8720       return \"#\";
8721     case 3:
8722       /* If the address is not used in the output, we can use lsi.  Otherwise,
8723          fall through to generating four loads.  */
8724       if (TARGET_STRING
8725           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8726         return \"{lsi|lswi} %0,%P1,16\";
8727       /* ... fall through ...  */
8728     case 4:
8729     case 5:
8730       return \"#\";
8731     }
8732 }"
8733   [(set_attr "type" "store,store,*,load,load,*")])
8734
8735 (define_insn "*movti_string"
8736   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,o<>,????r,????r,????r,r")
8737         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))]
8738   "! TARGET_POWER && ! TARGET_POWERPC64
8739    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8740   "*
8741 {
8742   switch (which_alternative)
8743     {
8744     default:
8745       gcc_unreachable ();
8746     case 0:
8747       if (TARGET_STRING)
8748         return \"{stsi|stswi} %1,%P0,16\";
8749     case 1:
8750     case 2:
8751       return \"#\";
8752     case 3:
8753       /* If the address is not used in the output, we can use lsi.  Otherwise,
8754          fall through to generating four loads.  */
8755       if (TARGET_STRING
8756           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8757         return \"{lsi|lswi} %0,%P1,16\";
8758       /* ... fall through ...  */
8759     case 4:
8760     case 5:
8761       return \"#\";
8762     }
8763 }"
8764   [(set_attr "type" "store_ux,store_ux,*,load_ux,load_ux,*")])
8765
8766 (define_insn "*movti_ppc64"
8767   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,o<>,r")
8768         (match_operand:TI 1 "input_operand" "r,r,m"))]
8769   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
8770    || gpc_reg_operand (operands[1], TImode))"
8771   "#"
8772   [(set_attr "type" "*,load,store")])
8773
8774 (define_split
8775   [(set (match_operand:TI 0 "gpc_reg_operand" "")
8776         (match_operand:TI 1 "const_double_operand" ""))]
8777   "TARGET_POWERPC64"
8778   [(set (match_dup 2) (match_dup 4))
8779    (set (match_dup 3) (match_dup 5))]
8780   "
8781 {
8782   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8783                                        TImode);
8784   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8785                                        TImode);
8786   if (GET_CODE (operands[1]) == CONST_DOUBLE)
8787     {
8788       operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
8789       operands[5] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
8790     }
8791   else if (GET_CODE (operands[1]) == CONST_INT)
8792     {
8793       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
8794       operands[5] = operands[1];
8795     }
8796   else
8797     FAIL;
8798 }")
8799
8800 (define_split
8801   [(set (match_operand:TI 0 "nonimmediate_operand" "")
8802         (match_operand:TI 1 "input_operand" ""))]
8803   "reload_completed
8804    && gpr_or_gpr_p (operands[0], operands[1])"
8805   [(pc)]
8806 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8807 \f
8808 (define_expand "load_multiple"
8809   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8810                           (match_operand:SI 1 "" ""))
8811                      (use (match_operand:SI 2 "" ""))])]
8812   "TARGET_STRING && !TARGET_POWERPC64"
8813   "
8814 {
8815   int regno;
8816   int count;
8817   rtx op1;
8818   int i;
8819
8820   /* Support only loading a constant number of fixed-point registers from
8821      memory and only bother with this if more than two; the machine
8822      doesn't support more than eight.  */
8823   if (GET_CODE (operands[2]) != CONST_INT
8824       || INTVAL (operands[2]) <= 2
8825       || INTVAL (operands[2]) > 8
8826       || GET_CODE (operands[1]) != MEM
8827       || GET_CODE (operands[0]) != REG
8828       || REGNO (operands[0]) >= 32)
8829     FAIL;
8830
8831   count = INTVAL (operands[2]);
8832   regno = REGNO (operands[0]);
8833
8834   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
8835   op1 = replace_equiv_address (operands[1],
8836                                force_reg (SImode, XEXP (operands[1], 0)));
8837
8838   for (i = 0; i < count; i++)
8839     XVECEXP (operands[3], 0, i)
8840       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
8841                      adjust_address_nv (op1, SImode, i * 4));
8842 }")
8843
8844 (define_insn "*ldmsi8"
8845   [(match_parallel 0 "load_multiple_operation"
8846     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8847           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8848      (set (match_operand:SI 3 "gpc_reg_operand" "")
8849           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8850      (set (match_operand:SI 4 "gpc_reg_operand" "")
8851           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8852      (set (match_operand:SI 5 "gpc_reg_operand" "")
8853           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8854      (set (match_operand:SI 6 "gpc_reg_operand" "")
8855           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8856      (set (match_operand:SI 7 "gpc_reg_operand" "")
8857           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8858      (set (match_operand:SI 8 "gpc_reg_operand" "")
8859           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
8860      (set (match_operand:SI 9 "gpc_reg_operand" "")
8861           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
8862   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
8863   "*
8864 { return rs6000_output_load_multiple (operands); }"
8865   [(set_attr "type" "load_ux")
8866    (set_attr "length" "32")])
8867
8868 (define_insn "*ldmsi7"
8869   [(match_parallel 0 "load_multiple_operation"
8870     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8871           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8872      (set (match_operand:SI 3 "gpc_reg_operand" "")
8873           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8874      (set (match_operand:SI 4 "gpc_reg_operand" "")
8875           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8876      (set (match_operand:SI 5 "gpc_reg_operand" "")
8877           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8878      (set (match_operand:SI 6 "gpc_reg_operand" "")
8879           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8880      (set (match_operand:SI 7 "gpc_reg_operand" "")
8881           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8882      (set (match_operand:SI 8 "gpc_reg_operand" "")
8883           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
8884   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
8885   "*
8886 { return rs6000_output_load_multiple (operands); }"
8887   [(set_attr "type" "load_ux")
8888    (set_attr "length" "32")])
8889
8890 (define_insn "*ldmsi6"
8891   [(match_parallel 0 "load_multiple_operation"
8892     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8893           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8894      (set (match_operand:SI 3 "gpc_reg_operand" "")
8895           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8896      (set (match_operand:SI 4 "gpc_reg_operand" "")
8897           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8898      (set (match_operand:SI 5 "gpc_reg_operand" "")
8899           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8900      (set (match_operand:SI 6 "gpc_reg_operand" "")
8901           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8902      (set (match_operand:SI 7 "gpc_reg_operand" "")
8903           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
8904   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
8905   "*
8906 { return rs6000_output_load_multiple (operands); }"
8907   [(set_attr "type" "load_ux")
8908    (set_attr "length" "32")])
8909
8910 (define_insn "*ldmsi5"
8911   [(match_parallel 0 "load_multiple_operation"
8912     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8913           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8914      (set (match_operand:SI 3 "gpc_reg_operand" "")
8915           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8916      (set (match_operand:SI 4 "gpc_reg_operand" "")
8917           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8918      (set (match_operand:SI 5 "gpc_reg_operand" "")
8919           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8920      (set (match_operand:SI 6 "gpc_reg_operand" "")
8921           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
8922   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
8923   "*
8924 { return rs6000_output_load_multiple (operands); }"
8925   [(set_attr "type" "load_ux")
8926    (set_attr "length" "32")])
8927
8928 (define_insn "*ldmsi4"
8929   [(match_parallel 0 "load_multiple_operation"
8930     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8931           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8932      (set (match_operand:SI 3 "gpc_reg_operand" "")
8933           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8934      (set (match_operand:SI 4 "gpc_reg_operand" "")
8935           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8936      (set (match_operand:SI 5 "gpc_reg_operand" "")
8937           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
8938   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
8939   "*
8940 { return rs6000_output_load_multiple (operands); }"
8941   [(set_attr "type" "load_ux")
8942    (set_attr "length" "32")])
8943
8944 (define_insn "*ldmsi3"
8945   [(match_parallel 0 "load_multiple_operation"
8946     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8947           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8948      (set (match_operand:SI 3 "gpc_reg_operand" "")
8949           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8950      (set (match_operand:SI 4 "gpc_reg_operand" "")
8951           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
8952   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
8953   "*
8954 { return rs6000_output_load_multiple (operands); }"
8955   [(set_attr "type" "load_ux")
8956    (set_attr "length" "32")])
8957
8958 (define_expand "store_multiple"
8959   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8960                           (match_operand:SI 1 "" ""))
8961                      (clobber (scratch:SI))
8962                      (use (match_operand:SI 2 "" ""))])]
8963   "TARGET_STRING && !TARGET_POWERPC64"
8964   "
8965 {
8966   int regno;
8967   int count;
8968   rtx to;
8969   rtx op0;
8970   int i;
8971
8972   /* Support only storing a constant number of fixed-point registers to
8973      memory and only bother with this if more than two; the machine
8974      doesn't support more than eight.  */
8975   if (GET_CODE (operands[2]) != CONST_INT
8976       || INTVAL (operands[2]) <= 2
8977       || INTVAL (operands[2]) > 8
8978       || GET_CODE (operands[0]) != MEM
8979       || GET_CODE (operands[1]) != REG
8980       || REGNO (operands[1]) >= 32)
8981     FAIL;
8982
8983   count = INTVAL (operands[2]);
8984   regno = REGNO (operands[1]);
8985
8986   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
8987   to = force_reg (SImode, XEXP (operands[0], 0));
8988   op0 = replace_equiv_address (operands[0], to);
8989
8990   XVECEXP (operands[3], 0, 0)
8991     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
8992   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
8993                                                  gen_rtx_SCRATCH (SImode));
8994
8995   for (i = 1; i < count; i++)
8996     XVECEXP (operands[3], 0, i + 1)
8997       = gen_rtx_SET (VOIDmode,
8998                      adjust_address_nv (op0, SImode, i * 4),
8999                      gen_rtx_REG (SImode, regno + i));
9000 }")
9001
9002 (define_insn "*stmsi8"
9003   [(match_parallel 0 "store_multiple_operation"
9004     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9005           (match_operand:SI 2 "gpc_reg_operand" "r"))
9006      (clobber (match_scratch:SI 3 "=X"))
9007      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9008           (match_operand:SI 4 "gpc_reg_operand" "r"))
9009      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9010           (match_operand:SI 5 "gpc_reg_operand" "r"))
9011      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9012           (match_operand:SI 6 "gpc_reg_operand" "r"))
9013      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9014           (match_operand:SI 7 "gpc_reg_operand" "r"))
9015      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9016           (match_operand:SI 8 "gpc_reg_operand" "r"))
9017      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9018           (match_operand:SI 9 "gpc_reg_operand" "r"))
9019      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
9020           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
9021   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 9"
9022   "{stsi|stswi} %2,%1,%O0"
9023   [(set_attr "type" "store_ux")])
9024
9025 (define_insn "*stmsi7"
9026   [(match_parallel 0 "store_multiple_operation"
9027     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9028           (match_operand:SI 2 "gpc_reg_operand" "r"))
9029      (clobber (match_scratch:SI 3 "=X"))
9030      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9031           (match_operand:SI 4 "gpc_reg_operand" "r"))
9032      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9033           (match_operand:SI 5 "gpc_reg_operand" "r"))
9034      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9035           (match_operand:SI 6 "gpc_reg_operand" "r"))
9036      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9037           (match_operand:SI 7 "gpc_reg_operand" "r"))
9038      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9039           (match_operand:SI 8 "gpc_reg_operand" "r"))
9040      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9041           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
9042   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 8"
9043   "{stsi|stswi} %2,%1,%O0"
9044   [(set_attr "type" "store_ux")])
9045
9046 (define_insn "*stmsi6"
9047   [(match_parallel 0 "store_multiple_operation"
9048     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9049           (match_operand:SI 2 "gpc_reg_operand" "r"))
9050      (clobber (match_scratch:SI 3 "=X"))
9051      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9052           (match_operand:SI 4 "gpc_reg_operand" "r"))
9053      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9054           (match_operand:SI 5 "gpc_reg_operand" "r"))
9055      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9056           (match_operand:SI 6 "gpc_reg_operand" "r"))
9057      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9058           (match_operand:SI 7 "gpc_reg_operand" "r"))
9059      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9060           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
9061   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 7"
9062   "{stsi|stswi} %2,%1,%O0"
9063   [(set_attr "type" "store_ux")])
9064
9065 (define_insn "*stmsi5"
9066   [(match_parallel 0 "store_multiple_operation"
9067     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9068           (match_operand:SI 2 "gpc_reg_operand" "r"))
9069      (clobber (match_scratch:SI 3 "=X"))
9070      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9071           (match_operand:SI 4 "gpc_reg_operand" "r"))
9072      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9073           (match_operand:SI 5 "gpc_reg_operand" "r"))
9074      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9075           (match_operand:SI 6 "gpc_reg_operand" "r"))
9076      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9077           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
9078   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 6"
9079   "{stsi|stswi} %2,%1,%O0"
9080   [(set_attr "type" "store_ux")])
9081
9082 (define_insn "*stmsi4"
9083   [(match_parallel 0 "store_multiple_operation"
9084     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9085           (match_operand:SI 2 "gpc_reg_operand" "r"))
9086      (clobber (match_scratch:SI 3 "=X"))
9087      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9088           (match_operand:SI 4 "gpc_reg_operand" "r"))
9089      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9090           (match_operand:SI 5 "gpc_reg_operand" "r"))
9091      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9092           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
9093   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 5"
9094   "{stsi|stswi} %2,%1,%O0"
9095   [(set_attr "type" "store_ux")])
9096
9097 (define_insn "*stmsi3"
9098   [(match_parallel 0 "store_multiple_operation"
9099     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9100           (match_operand:SI 2 "gpc_reg_operand" "r"))
9101      (clobber (match_scratch:SI 3 "=X"))
9102      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9103           (match_operand:SI 4 "gpc_reg_operand" "r"))
9104      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9105           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
9106   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 4"
9107   "{stsi|stswi} %2,%1,%O0"
9108   [(set_attr "type" "store_ux")])
9109
9110 (define_insn "*stmsi8_power"
9111   [(match_parallel 0 "store_multiple_operation"
9112     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9113           (match_operand:SI 2 "gpc_reg_operand" "r"))
9114      (clobber (match_scratch:SI 3 "=q"))
9115      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9116           (match_operand:SI 4 "gpc_reg_operand" "r"))
9117      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9118           (match_operand:SI 5 "gpc_reg_operand" "r"))
9119      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9120           (match_operand:SI 6 "gpc_reg_operand" "r"))
9121      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9122           (match_operand:SI 7 "gpc_reg_operand" "r"))
9123      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9124           (match_operand:SI 8 "gpc_reg_operand" "r"))
9125      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9126           (match_operand:SI 9 "gpc_reg_operand" "r"))
9127      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
9128           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
9129   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 9"
9130   "{stsi|stswi} %2,%1,%O0"
9131   [(set_attr "type" "store_ux")])
9132
9133 (define_insn "*stmsi7_power"
9134   [(match_parallel 0 "store_multiple_operation"
9135     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9136           (match_operand:SI 2 "gpc_reg_operand" "r"))
9137      (clobber (match_scratch:SI 3 "=q"))
9138      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9139           (match_operand:SI 4 "gpc_reg_operand" "r"))
9140      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9141           (match_operand:SI 5 "gpc_reg_operand" "r"))
9142      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9143           (match_operand:SI 6 "gpc_reg_operand" "r"))
9144      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9145           (match_operand:SI 7 "gpc_reg_operand" "r"))
9146      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9147           (match_operand:SI 8 "gpc_reg_operand" "r"))
9148      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9149           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
9150   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 8"
9151   "{stsi|stswi} %2,%1,%O0"
9152   [(set_attr "type" "store_ux")])
9153
9154 (define_insn "*stmsi6_power"
9155   [(match_parallel 0 "store_multiple_operation"
9156     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9157           (match_operand:SI 2 "gpc_reg_operand" "r"))
9158      (clobber (match_scratch:SI 3 "=q"))
9159      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9160           (match_operand:SI 4 "gpc_reg_operand" "r"))
9161      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9162           (match_operand:SI 5 "gpc_reg_operand" "r"))
9163      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9164           (match_operand:SI 6 "gpc_reg_operand" "r"))
9165      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9166           (match_operand:SI 7 "gpc_reg_operand" "r"))
9167      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9168           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
9169   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 7"
9170   "{stsi|stswi} %2,%1,%O0"
9171   [(set_attr "type" "store_ux")])
9172
9173 (define_insn "*stmsi5_power"
9174   [(match_parallel 0 "store_multiple_operation"
9175     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9176           (match_operand:SI 2 "gpc_reg_operand" "r"))
9177      (clobber (match_scratch:SI 3 "=q"))
9178      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9179           (match_operand:SI 4 "gpc_reg_operand" "r"))
9180      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9181           (match_operand:SI 5 "gpc_reg_operand" "r"))
9182      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9183           (match_operand:SI 6 "gpc_reg_operand" "r"))
9184      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9185           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
9186   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 6"
9187   "{stsi|stswi} %2,%1,%O0"
9188   [(set_attr "type" "store_ux")])
9189
9190 (define_insn "*stmsi4_power"
9191   [(match_parallel 0 "store_multiple_operation"
9192     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9193           (match_operand:SI 2 "gpc_reg_operand" "r"))
9194      (clobber (match_scratch:SI 3 "=q"))
9195      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9196           (match_operand:SI 4 "gpc_reg_operand" "r"))
9197      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9198           (match_operand:SI 5 "gpc_reg_operand" "r"))
9199      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9200           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
9201   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 5"
9202   "{stsi|stswi} %2,%1,%O0"
9203   [(set_attr "type" "store_ux")])
9204
9205 (define_insn "*stmsi3_power"
9206   [(match_parallel 0 "store_multiple_operation"
9207     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9208           (match_operand:SI 2 "gpc_reg_operand" "r"))
9209      (clobber (match_scratch:SI 3 "=q"))
9210      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9211           (match_operand:SI 4 "gpc_reg_operand" "r"))
9212      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9213           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
9214   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 4"
9215   "{stsi|stswi} %2,%1,%O0"
9216   [(set_attr "type" "store_ux")])
9217 \f
9218 (define_expand "setmemsi"
9219   [(parallel [(set (match_operand:BLK 0 "" "")
9220                    (match_operand 2 "const_int_operand" ""))
9221               (use (match_operand:SI 1 "" ""))
9222               (use (match_operand:SI 3 "" ""))])]
9223   ""
9224   "
9225 {
9226   /* If value to set is not zero, use the library routine.  */
9227   if (operands[2] != const0_rtx)
9228     FAIL;
9229
9230   if (expand_block_clear (operands))
9231     DONE;
9232   else
9233     FAIL;
9234 }")
9235
9236 ;; String/block move insn.
9237 ;; Argument 0 is the destination
9238 ;; Argument 1 is the source
9239 ;; Argument 2 is the length
9240 ;; Argument 3 is the alignment
9241
9242 (define_expand "movmemsi"
9243   [(parallel [(set (match_operand:BLK 0 "" "")
9244                    (match_operand:BLK 1 "" ""))
9245               (use (match_operand:SI 2 "" ""))
9246               (use (match_operand:SI 3 "" ""))])]
9247   ""
9248   "
9249 {
9250   if (expand_block_move (operands))
9251     DONE;
9252   else
9253     FAIL;
9254 }")
9255
9256 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
9257 ;; register allocator doesn't have a clue about allocating 8 word registers.
9258 ;; rD/rS = r5 is preferred, efficient form.
9259 (define_expand "movmemsi_8reg"
9260   [(parallel [(set (match_operand 0 "" "")
9261                    (match_operand 1 "" ""))
9262               (use (match_operand 2 "" ""))
9263               (use (match_operand 3 "" ""))
9264               (clobber (reg:SI  5))
9265               (clobber (reg:SI  6))
9266               (clobber (reg:SI  7))
9267               (clobber (reg:SI  8))
9268               (clobber (reg:SI  9))
9269               (clobber (reg:SI 10))
9270               (clobber (reg:SI 11))
9271               (clobber (reg:SI 12))
9272               (clobber (match_scratch:SI 4 ""))])]
9273   "TARGET_STRING"
9274   "")
9275
9276 (define_insn ""
9277   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9278         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9279    (use (match_operand:SI 2 "immediate_operand" "i"))
9280    (use (match_operand:SI 3 "immediate_operand" "i"))
9281    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9282    (clobber (reg:SI  6))
9283    (clobber (reg:SI  7))
9284    (clobber (reg:SI  8))
9285    (clobber (reg:SI  9))
9286    (clobber (reg:SI 10))
9287    (clobber (reg:SI 11))
9288    (clobber (reg:SI 12))
9289    (clobber (match_scratch:SI 5 "=q"))]
9290   "TARGET_STRING && TARGET_POWER
9291    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9292        || INTVAL (operands[2]) == 0)
9293    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9294    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9295    && REGNO (operands[4]) == 5"
9296   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9297   [(set_attr "type" "store_ux")
9298    (set_attr "length" "8")])
9299
9300 (define_insn ""
9301   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9302         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9303    (use (match_operand:SI 2 "immediate_operand" "i"))
9304    (use (match_operand:SI 3 "immediate_operand" "i"))
9305    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9306    (clobber (reg:SI  6))
9307    (clobber (reg:SI  7))
9308    (clobber (reg:SI  8))
9309    (clobber (reg:SI  9))
9310    (clobber (reg:SI 10))
9311    (clobber (reg:SI 11))
9312    (clobber (reg:SI 12))
9313    (clobber (match_scratch:SI 5 "=X"))]
9314   "TARGET_STRING && ! TARGET_POWER
9315    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9316        || INTVAL (operands[2]) == 0)
9317    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9318    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9319    && REGNO (operands[4]) == 5"
9320   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9321   [(set_attr "type" "store_ux")
9322    (set_attr "length" "8")])
9323
9324 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
9325 ;; register allocator doesn't have a clue about allocating 6 word registers.
9326 ;; rD/rS = r5 is preferred, efficient form.
9327 (define_expand "movmemsi_6reg"
9328   [(parallel [(set (match_operand 0 "" "")
9329                    (match_operand 1 "" ""))
9330               (use (match_operand 2 "" ""))
9331               (use (match_operand 3 "" ""))
9332               (clobber (reg:SI  5))
9333               (clobber (reg:SI  6))
9334               (clobber (reg:SI  7))
9335               (clobber (reg:SI  8))
9336               (clobber (reg:SI  9))
9337               (clobber (reg:SI 10))
9338               (clobber (match_scratch:SI 4 ""))])]
9339   "TARGET_STRING"
9340   "")
9341
9342 (define_insn ""
9343   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9344         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9345    (use (match_operand:SI 2 "immediate_operand" "i"))
9346    (use (match_operand:SI 3 "immediate_operand" "i"))
9347    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9348    (clobber (reg:SI  6))
9349    (clobber (reg:SI  7))
9350    (clobber (reg:SI  8))
9351    (clobber (reg:SI  9))
9352    (clobber (reg:SI 10))
9353    (clobber (match_scratch:SI 5 "=q"))]
9354   "TARGET_STRING && TARGET_POWER
9355    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
9356    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9357    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9358    && REGNO (operands[4]) == 5"
9359   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9360   [(set_attr "type" "store_ux")
9361    (set_attr "length" "8")])
9362
9363 (define_insn ""
9364   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9365         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9366    (use (match_operand:SI 2 "immediate_operand" "i"))
9367    (use (match_operand:SI 3 "immediate_operand" "i"))
9368    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9369    (clobber (reg:SI  6))
9370    (clobber (reg:SI  7))
9371    (clobber (reg:SI  8))
9372    (clobber (reg:SI  9))
9373    (clobber (reg:SI 10))
9374    (clobber (match_scratch:SI 5 "=X"))]
9375   "TARGET_STRING && ! TARGET_POWER
9376    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9377    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9378    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9379    && REGNO (operands[4]) == 5"
9380   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9381   [(set_attr "type" "store_ux")
9382    (set_attr "length" "8")])
9383
9384 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
9385 ;; problems with TImode.
9386 ;; rD/rS = r5 is preferred, efficient form.
9387 (define_expand "movmemsi_4reg"
9388   [(parallel [(set (match_operand 0 "" "")
9389                    (match_operand 1 "" ""))
9390               (use (match_operand 2 "" ""))
9391               (use (match_operand 3 "" ""))
9392               (clobber (reg:SI 5))
9393               (clobber (reg:SI 6))
9394               (clobber (reg:SI 7))
9395               (clobber (reg:SI 8))
9396               (clobber (match_scratch:SI 4 ""))])]
9397   "TARGET_STRING"
9398   "")
9399
9400 (define_insn ""
9401   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9402         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9403    (use (match_operand:SI 2 "immediate_operand" "i"))
9404    (use (match_operand:SI 3 "immediate_operand" "i"))
9405    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9406    (clobber (reg:SI 6))
9407    (clobber (reg:SI 7))
9408    (clobber (reg:SI 8))
9409    (clobber (match_scratch:SI 5 "=q"))]
9410   "TARGET_STRING && TARGET_POWER
9411    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9412    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9413    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9414    && REGNO (operands[4]) == 5"
9415   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9416   [(set_attr "type" "store_ux")
9417    (set_attr "length" "8")])
9418
9419 (define_insn ""
9420   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9421         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9422    (use (match_operand:SI 2 "immediate_operand" "i"))
9423    (use (match_operand:SI 3 "immediate_operand" "i"))
9424    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9425    (clobber (reg:SI 6))
9426    (clobber (reg:SI 7))
9427    (clobber (reg:SI 8))
9428    (clobber (match_scratch:SI 5 "=X"))]
9429   "TARGET_STRING && ! TARGET_POWER
9430    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9431    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9432    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9433    && REGNO (operands[4]) == 5"
9434   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9435   [(set_attr "type" "store_ux")
9436    (set_attr "length" "8")])
9437
9438 ;; Move up to 8 bytes at a time.
9439 (define_expand "movmemsi_2reg"
9440   [(parallel [(set (match_operand 0 "" "")
9441                    (match_operand 1 "" ""))
9442               (use (match_operand 2 "" ""))
9443               (use (match_operand 3 "" ""))
9444               (clobber (match_scratch:DI 4 ""))
9445               (clobber (match_scratch:SI 5 ""))])]
9446   "TARGET_STRING && ! TARGET_POWERPC64"
9447   "")
9448
9449 (define_insn ""
9450   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9451         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9452    (use (match_operand:SI 2 "immediate_operand" "i"))
9453    (use (match_operand:SI 3 "immediate_operand" "i"))
9454    (clobber (match_scratch:DI 4 "=&r"))
9455    (clobber (match_scratch:SI 5 "=q"))]
9456   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
9457    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9458   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9459   [(set_attr "type" "store_ux")
9460    (set_attr "length" "8")])
9461
9462 (define_insn ""
9463   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9464         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9465    (use (match_operand:SI 2 "immediate_operand" "i"))
9466    (use (match_operand:SI 3 "immediate_operand" "i"))
9467    (clobber (match_scratch:DI 4 "=&r"))
9468    (clobber (match_scratch:SI 5 "=X"))]
9469   "TARGET_STRING && ! TARGET_POWER && ! TARGET_POWERPC64
9470    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9471   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9472   [(set_attr "type" "store_ux")
9473    (set_attr "length" "8")])
9474
9475 ;; Move up to 4 bytes at a time.
9476 (define_expand "movmemsi_1reg"
9477   [(parallel [(set (match_operand 0 "" "")
9478                    (match_operand 1 "" ""))
9479               (use (match_operand 2 "" ""))
9480               (use (match_operand 3 "" ""))
9481               (clobber (match_scratch:SI 4 ""))
9482               (clobber (match_scratch:SI 5 ""))])]
9483   "TARGET_STRING"
9484   "")
9485
9486 (define_insn ""
9487   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9488         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9489    (use (match_operand:SI 2 "immediate_operand" "i"))
9490    (use (match_operand:SI 3 "immediate_operand" "i"))
9491    (clobber (match_scratch:SI 4 "=&r"))
9492    (clobber (match_scratch:SI 5 "=q"))]
9493   "TARGET_STRING && TARGET_POWER
9494    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9495   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9496   [(set_attr "type" "store_ux")
9497    (set_attr "length" "8")])
9498
9499 (define_insn ""
9500   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9501         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9502    (use (match_operand:SI 2 "immediate_operand" "i"))
9503    (use (match_operand:SI 3 "immediate_operand" "i"))
9504    (clobber (match_scratch:SI 4 "=&r"))
9505    (clobber (match_scratch:SI 5 "=X"))]
9506   "TARGET_STRING && ! TARGET_POWER
9507    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9508   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9509   [(set_attr "type" "store_ux")
9510    (set_attr "length" "8")])
9511 \f
9512 ;; Define insns that do load or store with update.  Some of these we can
9513 ;; get by using pre-decrement or pre-increment, but the hardware can also
9514 ;; do cases where the increment is not the size of the object.
9515 ;;
9516 ;; In all these cases, we use operands 0 and 1 for the register being
9517 ;; incremented because those are the operands that local-alloc will
9518 ;; tie and these are the pair most likely to be tieable (and the ones
9519 ;; that will benefit the most).
9520
9521 (define_insn "*movdi_update1"
9522   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
9523         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9524                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
9525    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9526         (plus:DI (match_dup 1) (match_dup 2)))]
9527   "TARGET_POWERPC64 && TARGET_UPDATE"
9528   "@
9529    ldux %3,%0,%2
9530    ldu %3,%2(%0)"
9531   [(set_attr "type" "load_ux,load_u")])
9532
9533 (define_insn "movdi_<mode>_update"
9534   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
9535                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
9536         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
9537    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
9538         (plus:P (match_dup 1) (match_dup 2)))]
9539   "TARGET_POWERPC64 && TARGET_UPDATE"
9540   "@
9541    stdux %3,%0,%2
9542    stdu %3,%2(%0)"
9543   [(set_attr "type" "store_ux,store_u")])
9544
9545 (define_insn "*movsi_update1"
9546   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9547         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9548                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9549    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9550         (plus:SI (match_dup 1) (match_dup 2)))]
9551   "TARGET_UPDATE"
9552   "@
9553    {lux|lwzux} %3,%0,%2
9554    {lu|lwzu} %3,%2(%0)"
9555   [(set_attr "type" "load_ux,load_u")])
9556
9557 (define_insn "*movsi_update2"
9558   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
9559         (sign_extend:DI
9560          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
9561                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
9562    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
9563         (plus:DI (match_dup 1) (match_dup 2)))]
9564   "TARGET_POWERPC64"
9565   "lwaux %3,%0,%2"
9566   [(set_attr "type" "load_ext_ux")])
9567
9568 (define_insn "movsi_update"
9569   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9570                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9571         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
9572    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9573         (plus:SI (match_dup 1) (match_dup 2)))]
9574   "TARGET_UPDATE"
9575   "@
9576    {stux|stwux} %3,%0,%2
9577    {stu|stwu} %3,%2(%0)"
9578   [(set_attr "type" "store_ux,store_u")])
9579
9580 (define_insn "*movhi_update1"
9581   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
9582         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9583                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9584    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9585         (plus:SI (match_dup 1) (match_dup 2)))]
9586   "TARGET_UPDATE"
9587   "@
9588    lhzux %3,%0,%2
9589    lhzu %3,%2(%0)"
9590   [(set_attr "type" "load_ux,load_u")])
9591
9592 (define_insn "*movhi_update2"
9593   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9594         (zero_extend:SI
9595          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9596                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9597    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9598         (plus:SI (match_dup 1) (match_dup 2)))]
9599   "TARGET_UPDATE"
9600   "@
9601    lhzux %3,%0,%2
9602    lhzu %3,%2(%0)"
9603   [(set_attr "type" "load_ux,load_u")])
9604
9605 (define_insn "*movhi_update3"
9606   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9607         (sign_extend:SI
9608          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9609                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9610    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9611         (plus:SI (match_dup 1) (match_dup 2)))]
9612   "TARGET_UPDATE"
9613   "@
9614    lhaux %3,%0,%2
9615    lhau %3,%2(%0)"
9616   [(set_attr "type" "load_ext_ux,load_ext_u")])
9617
9618 (define_insn "*movhi_update4"
9619   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9620                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9621         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
9622    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9623         (plus:SI (match_dup 1) (match_dup 2)))]
9624   "TARGET_UPDATE"
9625   "@
9626    sthux %3,%0,%2
9627    sthu %3,%2(%0)"
9628   [(set_attr "type" "store_ux,store_u")])
9629
9630 (define_insn "*movqi_update1"
9631   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
9632         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9633                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9634    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9635         (plus:SI (match_dup 1) (match_dup 2)))]
9636   "TARGET_UPDATE"
9637   "@
9638    lbzux %3,%0,%2
9639    lbzu %3,%2(%0)"
9640   [(set_attr "type" "load_ux,load_u")])
9641
9642 (define_insn "*movqi_update2"
9643   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9644         (zero_extend:SI
9645          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9646                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9647    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9648         (plus:SI (match_dup 1) (match_dup 2)))]
9649   "TARGET_UPDATE"
9650   "@
9651    lbzux %3,%0,%2
9652    lbzu %3,%2(%0)"
9653   [(set_attr "type" "load_ux,load_u")])
9654
9655 (define_insn "*movqi_update3"
9656   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9657                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9658         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
9659    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9660         (plus:SI (match_dup 1) (match_dup 2)))]
9661   "TARGET_UPDATE"
9662   "@
9663    stbux %3,%0,%2
9664    stbu %3,%2(%0)"
9665   [(set_attr "type" "store_ux,store_u")])
9666
9667 (define_insn "*movsf_update1"
9668   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
9669         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9670                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9671    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9672         (plus:SI (match_dup 1) (match_dup 2)))]
9673   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9674   "@
9675    lfsux %3,%0,%2
9676    lfsu %3,%2(%0)"
9677   [(set_attr "type" "fpload_ux,fpload_u")])
9678
9679 (define_insn "*movsf_update2"
9680   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9681                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9682         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
9683    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9684         (plus:SI (match_dup 1) (match_dup 2)))]
9685   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9686   "@
9687    stfsux %3,%0,%2
9688    stfsu %3,%2(%0)"
9689   [(set_attr "type" "fpstore_ux,fpstore_u")])
9690
9691 (define_insn "*movsf_update3"
9692   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
9693         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9694                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9695    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9696         (plus:SI (match_dup 1) (match_dup 2)))]
9697   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9698   "@
9699    {lux|lwzux} %3,%0,%2
9700    {lu|lwzu} %3,%2(%0)"
9701   [(set_attr "type" "load_ux,load_u")])
9702
9703 (define_insn "*movsf_update4"
9704   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9705                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9706         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
9707    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9708         (plus:SI (match_dup 1) (match_dup 2)))]
9709   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9710   "@
9711    {stux|stwux} %3,%0,%2
9712    {stu|stwu} %3,%2(%0)"
9713   [(set_attr "type" "store_ux,store_u")])
9714
9715 (define_insn "*movdf_update1"
9716   [(set (match_operand:DF 3 "gpc_reg_operand" "=f,f")
9717         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9718                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9719    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9720         (plus:SI (match_dup 1) (match_dup 2)))]
9721   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9722   "@
9723    lfdux %3,%0,%2
9724    lfdu %3,%2(%0)"
9725   [(set_attr "type" "fpload_ux,fpload_u")])
9726
9727 (define_insn "*movdf_update2"
9728   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9729                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9730         (match_operand:DF 3 "gpc_reg_operand" "f,f"))
9731    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9732         (plus:SI (match_dup 1) (match_dup 2)))]
9733   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9734   "@
9735    stfdux %3,%0,%2
9736    stfdu %3,%2(%0)"
9737   [(set_attr "type" "fpstore_ux,fpstore_u")])
9738
9739 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
9740
9741 (define_insn "*lfq_power2"
9742   [(set (match_operand:V2DF 0 "gpc_reg_operand" "=f")
9743         (match_operand:V2DF 1 "memory_operand" ""))]
9744   "TARGET_POWER2
9745    && TARGET_HARD_FLOAT && TARGET_FPRS"
9746   "lfq%U1%X1 %0,%1")
9747
9748 (define_peephole2
9749   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9750         (match_operand:DF 1 "memory_operand" ""))
9751    (set (match_operand:DF 2 "gpc_reg_operand" "")
9752         (match_operand:DF 3 "memory_operand" ""))]
9753   "TARGET_POWER2
9754    && TARGET_HARD_FLOAT && TARGET_FPRS
9755    && registers_ok_for_quad_peep (operands[0], operands[2])
9756    && mems_ok_for_quad_peep (operands[1], operands[3])"
9757   [(set (match_dup 0)
9758         (match_dup 1))]
9759   "operands[1] = widen_memory_access (operands[1], V2DFmode, 0);
9760    operands[0] = gen_rtx_REG (V2DFmode, REGNO (operands[0]));")
9761
9762 (define_insn "*stfq_power2"
9763   [(set (match_operand:V2DF 0 "memory_operand" "")
9764         (match_operand:V2DF 1 "gpc_reg_operand" "f"))]
9765   "TARGET_POWER2
9766    && TARGET_HARD_FLOAT && TARGET_FPRS"
9767   "stfq%U0%X0 %1,%0")
9768
9769
9770 (define_peephole2
9771   [(set (match_operand:DF 0 "memory_operand" "")
9772         (match_operand:DF 1 "gpc_reg_operand" ""))
9773    (set (match_operand:DF 2 "memory_operand" "")
9774         (match_operand:DF 3 "gpc_reg_operand" ""))]
9775   "TARGET_POWER2
9776    && TARGET_HARD_FLOAT && TARGET_FPRS
9777    && registers_ok_for_quad_peep (operands[1], operands[3])
9778    && mems_ok_for_quad_peep (operands[0], operands[2])"
9779   [(set (match_dup 0)
9780         (match_dup 1))]
9781   "operands[0] = widen_memory_access (operands[0], V2DFmode, 0);
9782    operands[1] = gen_rtx_REG (V2DFmode, REGNO (operands[1]));")
9783
9784 ;; After inserting conditional returns we can sometimes have
9785 ;; unnecessary register moves.  Unfortunately we cannot have a
9786 ;; modeless peephole here, because some single SImode sets have early
9787 ;; clobber outputs.  Although those sets expand to multi-ppc-insn
9788 ;; sequences, using get_attr_length here will smash the operands
9789 ;; array.  Neither is there an early_cobbler_p predicate.
9790 ;; Disallow subregs for E500 so we don't munge frob_di_df_2.
9791 (define_peephole2
9792   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9793         (match_operand:DF 1 "any_operand" ""))
9794    (set (match_operand:DF 2 "gpc_reg_operand" "")
9795         (match_dup 0))]
9796   "!(TARGET_E500_DOUBLE && GET_CODE (operands[2]) == SUBREG)
9797    && peep2_reg_dead_p (2, operands[0])"
9798   [(set (match_dup 2) (match_dup 1))])
9799
9800 (define_peephole2
9801   [(set (match_operand:SF 0 "gpc_reg_operand" "")
9802         (match_operand:SF 1 "any_operand" ""))
9803    (set (match_operand:SF 2 "gpc_reg_operand" "")
9804         (match_dup 0))]
9805   "peep2_reg_dead_p (2, operands[0])"
9806   [(set (match_dup 2) (match_dup 1))])
9807
9808 \f
9809 ;; TLS support.
9810
9811 ;; "b" output constraint here and on tls_ld to support tls linker optimization.
9812 (define_insn "tls_gd_32"
9813   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9814         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9815                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9816                    UNSPEC_TLSGD))]
9817   "HAVE_AS_TLS && !TARGET_64BIT"
9818   "addi %0,%1,%2@got@tlsgd")
9819
9820 (define_insn "tls_gd_64"
9821   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9822         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9823                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9824                    UNSPEC_TLSGD))]
9825   "HAVE_AS_TLS && TARGET_64BIT"
9826   "addi %0,%1,%2@got@tlsgd")
9827
9828 (define_insn "tls_ld_32"
9829   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9830         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")]
9831                    UNSPEC_TLSLD))]
9832   "HAVE_AS_TLS && !TARGET_64BIT"
9833   "addi %0,%1,%&@got@tlsld")
9834
9835 (define_insn "tls_ld_64"
9836   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9837         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")]
9838                    UNSPEC_TLSLD))]
9839   "HAVE_AS_TLS && TARGET_64BIT"
9840   "addi %0,%1,%&@got@tlsld")
9841
9842 (define_insn "tls_dtprel_32"
9843   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9844         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9845                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9846                    UNSPEC_TLSDTPREL))]
9847   "HAVE_AS_TLS && !TARGET_64BIT"
9848   "addi %0,%1,%2@dtprel")
9849
9850 (define_insn "tls_dtprel_64"
9851   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9852         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9853                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9854                    UNSPEC_TLSDTPREL))]
9855   "HAVE_AS_TLS && TARGET_64BIT"
9856   "addi %0,%1,%2@dtprel")
9857
9858 (define_insn "tls_dtprel_ha_32"
9859   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9860         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9861                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9862                    UNSPEC_TLSDTPRELHA))]
9863   "HAVE_AS_TLS && !TARGET_64BIT"
9864   "addis %0,%1,%2@dtprel@ha")
9865
9866 (define_insn "tls_dtprel_ha_64"
9867   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9868         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9869                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9870                    UNSPEC_TLSDTPRELHA))]
9871   "HAVE_AS_TLS && TARGET_64BIT"
9872   "addis %0,%1,%2@dtprel@ha")
9873
9874 (define_insn "tls_dtprel_lo_32"
9875   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9876         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9877                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9878                    UNSPEC_TLSDTPRELLO))]
9879   "HAVE_AS_TLS && !TARGET_64BIT"
9880   "addi %0,%1,%2@dtprel@l")
9881
9882 (define_insn "tls_dtprel_lo_64"
9883   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9884         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9885                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9886                    UNSPEC_TLSDTPRELLO))]
9887   "HAVE_AS_TLS && TARGET_64BIT"
9888   "addi %0,%1,%2@dtprel@l")
9889
9890 (define_insn "tls_got_dtprel_32"
9891   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9892         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9893                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9894                    UNSPEC_TLSGOTDTPREL))]
9895   "HAVE_AS_TLS && !TARGET_64BIT"
9896   "lwz %0,%2@got@dtprel(%1)")
9897
9898 (define_insn "tls_got_dtprel_64"
9899   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9900         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9901                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9902                    UNSPEC_TLSGOTDTPREL))]
9903   "HAVE_AS_TLS && TARGET_64BIT"
9904   "ld %0,%2@got@dtprel(%1)")
9905
9906 (define_insn "tls_tprel_32"
9907   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9908         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9909                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9910                    UNSPEC_TLSTPREL))]
9911   "HAVE_AS_TLS && !TARGET_64BIT"
9912   "addi %0,%1,%2@tprel")
9913
9914 (define_insn "tls_tprel_64"
9915   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9916         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9917                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9918                    UNSPEC_TLSTPREL))]
9919   "HAVE_AS_TLS && TARGET_64BIT"
9920   "addi %0,%1,%2@tprel")
9921
9922 (define_insn "tls_tprel_ha_32"
9923   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9924         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9925                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9926                    UNSPEC_TLSTPRELHA))]
9927   "HAVE_AS_TLS && !TARGET_64BIT"
9928   "addis %0,%1,%2@tprel@ha")
9929
9930 (define_insn "tls_tprel_ha_64"
9931   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9932         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9933                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9934                    UNSPEC_TLSTPRELHA))]
9935   "HAVE_AS_TLS && TARGET_64BIT"
9936   "addis %0,%1,%2@tprel@ha")
9937
9938 (define_insn "tls_tprel_lo_32"
9939   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9940         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9941                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9942                    UNSPEC_TLSTPRELLO))]
9943   "HAVE_AS_TLS && !TARGET_64BIT"
9944   "addi %0,%1,%2@tprel@l")
9945
9946 (define_insn "tls_tprel_lo_64"
9947   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9948         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9949                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9950                    UNSPEC_TLSTPRELLO))]
9951   "HAVE_AS_TLS && TARGET_64BIT"
9952   "addi %0,%1,%2@tprel@l")
9953
9954 ;; "b" output constraint here and on tls_tls input to support linker tls
9955 ;; optimization.  The linker may edit the instructions emitted by a
9956 ;; tls_got_tprel/tls_tls pair to addis,addi.
9957 (define_insn "tls_got_tprel_32"
9958   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9959         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9960                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9961                    UNSPEC_TLSGOTTPREL))]
9962   "HAVE_AS_TLS && !TARGET_64BIT"
9963   "lwz %0,%2@got@tprel(%1)")
9964
9965 (define_insn "tls_got_tprel_64"
9966   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9967         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9968                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9969                    UNSPEC_TLSGOTTPREL))]
9970   "HAVE_AS_TLS && TARGET_64BIT"
9971   "ld %0,%2@got@tprel(%1)")
9972
9973 (define_insn "tls_tls_32"
9974   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9975         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9976                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9977                    UNSPEC_TLSTLS))]
9978   "HAVE_AS_TLS && !TARGET_64BIT"
9979   "add %0,%1,%2@tls")
9980
9981 (define_insn "tls_tls_64"
9982   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9983         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9984                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9985                    UNSPEC_TLSTLS))]
9986   "HAVE_AS_TLS && TARGET_64BIT"
9987   "add %0,%1,%2@tls")
9988 \f
9989 ;; Next come insns related to the calling sequence.
9990 ;;
9991 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
9992 ;; We move the back-chain and decrement the stack pointer.
9993
9994 (define_expand "allocate_stack"
9995   [(set (match_operand 0 "gpc_reg_operand" "=r")
9996         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
9997    (set (reg 1)
9998         (minus (reg 1) (match_dup 1)))]
9999   ""
10000   "
10001 { rtx chain = gen_reg_rtx (Pmode);
10002   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
10003   rtx neg_op0;
10004
10005   emit_move_insn (chain, stack_bot);
10006
10007   /* Check stack bounds if necessary.  */
10008   if (current_function_limit_stack)
10009     {
10010       rtx available;
10011       available = expand_binop (Pmode, sub_optab,
10012                                 stack_pointer_rtx, stack_limit_rtx,
10013                                 NULL_RTX, 1, OPTAB_WIDEN);
10014       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
10015     }
10016
10017   if (GET_CODE (operands[1]) != CONST_INT
10018       || INTVAL (operands[1]) < -32767
10019       || INTVAL (operands[1]) > 32768)
10020     {
10021       neg_op0 = gen_reg_rtx (Pmode);
10022       if (TARGET_32BIT)
10023         emit_insn (gen_negsi2 (neg_op0, operands[1]));
10024       else
10025         emit_insn (gen_negdi2 (neg_op0, operands[1]));
10026     }
10027   else
10028     neg_op0 = GEN_INT (- INTVAL (operands[1]));
10029
10030   if (TARGET_UPDATE)
10031     emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update : gen_movdi_di_update))
10032                 (stack_pointer_rtx, stack_pointer_rtx, neg_op0, chain));
10033
10034   else
10035     {
10036       emit_insn ((* ((TARGET_32BIT) ? gen_addsi3 : gen_adddi3))
10037                  (stack_pointer_rtx, stack_pointer_rtx, neg_op0));
10038       emit_move_insn (gen_rtx_MEM (Pmode, stack_pointer_rtx), chain);
10039     }
10040
10041   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
10042   DONE;
10043 }")
10044
10045 ;; These patterns say how to save and restore the stack pointer.  We need not
10046 ;; save the stack pointer at function level since we are careful to
10047 ;; preserve the backchain.  At block level, we have to restore the backchain
10048 ;; when we restore the stack pointer.
10049 ;;
10050 ;; For nonlocal gotos, we must save both the stack pointer and its
10051 ;; backchain and restore both.  Note that in the nonlocal case, the
10052 ;; save area is a memory location.
10053
10054 (define_expand "save_stack_function"
10055   [(match_operand 0 "any_operand" "")
10056    (match_operand 1 "any_operand" "")]
10057   ""
10058   "DONE;")
10059
10060 (define_expand "restore_stack_function"
10061   [(match_operand 0 "any_operand" "")
10062    (match_operand 1 "any_operand" "")]
10063   ""
10064   "DONE;")
10065
10066 ;; Adjust stack pointer (op0) to a new value (op1).
10067 ;; First copy old stack backchain to new location, and ensure that the
10068 ;; scheduler won't reorder the sp assignment before the backchain write.
10069 (define_expand "restore_stack_block"
10070   [(set (match_dup 2) (match_dup 3))
10071    (set (match_dup 4) (match_dup 2))
10072    (set (match_dup 5) (unspec:BLK [(match_dup 5)] UNSPEC_TIE))
10073    (set (match_operand 0 "register_operand" "")
10074         (match_operand 1 "register_operand" ""))]
10075   ""
10076   "
10077 {
10078   operands[1] = force_reg (Pmode, operands[1]);
10079   operands[2] = gen_reg_rtx (Pmode);
10080   operands[3] = gen_frame_mem (Pmode, operands[0]);
10081   operands[4] = gen_frame_mem (Pmode, operands[1]);
10082   operands[5] = gen_frame_mem (BLKmode, operands[0]);
10083 }")
10084
10085 (define_expand "save_stack_nonlocal"
10086   [(set (match_dup 3) (match_dup 4))
10087    (set (match_operand 0 "memory_operand" "") (match_dup 3))
10088    (set (match_dup 2) (match_operand 1 "register_operand" ""))]
10089   ""
10090   "
10091 {
10092   int units_per_word = (TARGET_32BIT) ? 4 : 8;
10093
10094   /* Copy the backchain to the first word, sp to the second.  */
10095   operands[0] = adjust_address_nv (operands[0], Pmode, 0);
10096   operands[2] = adjust_address_nv (operands[0], Pmode, units_per_word);
10097   operands[3] = gen_reg_rtx (Pmode);
10098   operands[4] = gen_frame_mem (Pmode, operands[1]);
10099 }")
10100
10101 (define_expand "restore_stack_nonlocal"
10102   [(set (match_dup 2) (match_operand 1 "memory_operand" ""))
10103    (set (match_dup 3) (match_dup 4))
10104    (set (match_dup 5) (match_dup 2))
10105    (set (match_dup 6) (unspec:BLK [(match_dup 6)] UNSPEC_TIE))
10106    (set (match_operand 0 "register_operand" "") (match_dup 3))]
10107   ""
10108   "
10109 {
10110   int units_per_word = (TARGET_32BIT) ? 4 : 8;
10111
10112   /* Restore the backchain from the first word, sp from the second.  */
10113   operands[2] = gen_reg_rtx (Pmode);
10114   operands[3] = gen_reg_rtx (Pmode);
10115   operands[1] = adjust_address_nv (operands[1], Pmode, 0);
10116   operands[4] = adjust_address_nv (operands[1], Pmode, units_per_word);
10117   operands[5] = gen_frame_mem (Pmode, operands[3]);
10118   operands[6] = gen_frame_mem (BLKmode, operands[0]);
10119 }")
10120 \f
10121 ;; TOC register handling.
10122
10123 ;; Code to initialize the TOC register...
10124
10125 (define_insn "load_toc_aix_si"
10126   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10127                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
10128               (use (reg:SI 2))])]
10129   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
10130   "*
10131 {
10132   char buf[30];
10133   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10134   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10135   operands[2] = gen_rtx_REG (Pmode, 2);
10136   return \"{l|lwz} %0,%1(%2)\";
10137 }"
10138   [(set_attr "type" "load")])
10139
10140 (define_insn "load_toc_aix_di"
10141   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10142                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
10143               (use (reg:DI 2))])]
10144   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
10145   "*
10146 {
10147   char buf[30];
10148 #ifdef TARGET_RELOCATABLE
10149   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
10150                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
10151 #else
10152   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10153 #endif
10154   if (TARGET_ELF)
10155     strcat (buf, \"@toc\");
10156   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10157   operands[2] = gen_rtx_REG (Pmode, 2);
10158   return \"ld %0,%1(%2)\";
10159 }"
10160   [(set_attr "type" "load")])
10161
10162 (define_insn "load_toc_v4_pic_si"
10163   [(set (match_operand:SI 0 "register_operand" "=l")
10164         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
10165   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
10166   "bl _GLOBAL_OFFSET_TABLE_@local-4"
10167   [(set_attr "type" "branch")
10168    (set_attr "length" "4")])
10169
10170 (define_insn "load_toc_v4_PIC_1"
10171   [(set (match_operand:SI 0 "register_operand" "=l")
10172         (match_operand:SI 1 "immediate_operand" "s"))
10173    (use (unspec [(match_dup 1)] UNSPEC_TOC))]
10174   "TARGET_ELF && DEFAULT_ABI != ABI_AIX
10175    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
10176   "bcl 20,31,%1\\n%1:"
10177   [(set_attr "type" "branch")
10178    (set_attr "length" "4")])
10179
10180 (define_insn "load_toc_v4_PIC_1b"
10181   [(set (match_operand:SI 0 "register_operand" "=l")
10182         (unspec:SI [(match_operand:SI 1 "immediate_operand" "s")]
10183                 UNSPEC_TOCPTR))]
10184   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10185   "bcl 20,31,$+8\\n\\t.long %1-$"
10186   [(set_attr "type" "branch")
10187    (set_attr "length" "8")])
10188
10189 (define_insn "load_toc_v4_PIC_2"
10190   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10191         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10192                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
10193                              (match_operand:SI 3 "immediate_operand" "s")))))]
10194   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10195   "{l|lwz} %0,%2-%3(%1)"
10196   [(set_attr "type" "load")])
10197
10198 (define_insn "load_toc_v4_PIC_3b"
10199   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
10200         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
10201                  (high:SI
10202                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
10203                              (match_operand:SI 3 "symbol_ref_operand" "s")))))]
10204   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
10205   "{cau|addis} %0,%1,%2-%3@ha")
10206
10207 (define_insn "load_toc_v4_PIC_3c"
10208   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10209         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10210                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
10211                              (match_operand:SI 3 "symbol_ref_operand" "s"))))]
10212   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
10213   "{cal|addi} %0,%1,%2-%3@l")
10214
10215 ;; If the TOC is shared over a translation unit, as happens with all
10216 ;; the kinds of PIC that we support, we need to restore the TOC
10217 ;; pointer only when jumping over units of translation.
10218 ;; On Darwin, we need to reload the picbase.
10219
10220 (define_expand "builtin_setjmp_receiver"
10221   [(use (label_ref (match_operand 0 "" "")))]
10222   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
10223    || (TARGET_TOC && TARGET_MINIMAL_TOC)
10224    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
10225   "
10226 {
10227 #if TARGET_MACHO
10228   if (DEFAULT_ABI == ABI_DARWIN)
10229     {
10230       const char *picbase = machopic_function_base_name ();
10231       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (picbase));
10232       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
10233       rtx tmplabrtx;
10234       char tmplab[20];
10235
10236       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
10237                                   CODE_LABEL_NUMBER (operands[0]));
10238       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
10239
10240       emit_insn (gen_load_macho_picbase (picreg, tmplabrtx));
10241       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
10242     }
10243   else
10244 #endif
10245     rs6000_emit_load_toc_table (FALSE);
10246   DONE;
10247 }")
10248
10249 ;; Elf specific ways of loading addresses for non-PIC code.
10250 ;; The output of this could be r0, but we make a very strong
10251 ;; preference for a base register because it will usually
10252 ;; be needed there.
10253 (define_insn "elf_high"
10254   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
10255         (high:SI (match_operand 1 "" "")))]
10256   "TARGET_ELF && ! TARGET_64BIT"
10257   "{liu|lis} %0,%1@ha")
10258
10259 (define_insn "elf_low"
10260   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
10261         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
10262                    (match_operand 2 "" "")))]
10263    "TARGET_ELF && ! TARGET_64BIT"
10264    "@
10265     {cal|la} %0,%2@l(%1)
10266     {ai|addic} %0,%1,%K2")
10267 \f
10268 ;; A function pointer under AIX is a pointer to a data area whose first word
10269 ;; contains the actual address of the function, whose second word contains a
10270 ;; pointer to its TOC, and whose third word contains a value to place in the
10271 ;; static chain register (r11).  Note that if we load the static chain, our
10272 ;; "trampoline" need not have any executable code.
10273
10274 (define_expand "call_indirect_aix32"
10275   [(set (match_dup 2)
10276         (mem:SI (match_operand:SI 0 "gpc_reg_operand" "")))
10277    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10278         (reg:SI 2))
10279    (set (reg:SI 2)
10280         (mem:SI (plus:SI (match_dup 0)
10281                          (const_int 4))))
10282    (set (reg:SI 11)
10283         (mem:SI (plus:SI (match_dup 0)
10284                          (const_int 8))))
10285    (parallel [(call (mem:SI (match_dup 2))
10286                     (match_operand 1 "" ""))
10287               (use (reg:SI 2))
10288               (use (reg:SI 11))
10289               (set (reg:SI 2)
10290                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10291               (clobber (scratch:SI))])]
10292   "TARGET_32BIT"
10293   "
10294 { operands[2] = gen_reg_rtx (SImode); }")
10295
10296 (define_expand "call_indirect_aix64"
10297   [(set (match_dup 2)
10298         (mem:DI (match_operand:DI 0 "gpc_reg_operand" "")))
10299    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10300         (reg:DI 2))
10301    (set (reg:DI 2)
10302         (mem:DI (plus:DI (match_dup 0)
10303                          (const_int 8))))
10304    (set (reg:DI 11)
10305         (mem:DI (plus:DI (match_dup 0)
10306                          (const_int 16))))
10307    (parallel [(call (mem:SI (match_dup 2))
10308                     (match_operand 1 "" ""))
10309               (use (reg:DI 2))
10310               (use (reg:DI 11))
10311               (set (reg:DI 2)
10312                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10313               (clobber (scratch:SI))])]
10314   "TARGET_64BIT"
10315   "
10316 { operands[2] = gen_reg_rtx (DImode); }")
10317
10318 (define_expand "call_value_indirect_aix32"
10319   [(set (match_dup 3)
10320         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
10321    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10322         (reg:SI 2))
10323    (set (reg:SI 2)
10324         (mem:SI (plus:SI (match_dup 1)
10325                          (const_int 4))))
10326    (set (reg:SI 11)
10327         (mem:SI (plus:SI (match_dup 1)
10328                          (const_int 8))))
10329    (parallel [(set (match_operand 0 "" "")
10330                    (call (mem:SI (match_dup 3))
10331                          (match_operand 2 "" "")))
10332               (use (reg:SI 2))
10333               (use (reg:SI 11))
10334               (set (reg:SI 2)
10335                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10336               (clobber (scratch:SI))])]
10337   "TARGET_32BIT"
10338   "
10339 { operands[3] = gen_reg_rtx (SImode); }")
10340
10341 (define_expand "call_value_indirect_aix64"
10342   [(set (match_dup 3)
10343         (mem:DI (match_operand:DI 1 "gpc_reg_operand" "")))
10344    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10345         (reg:DI 2))
10346    (set (reg:DI 2)
10347         (mem:DI (plus:DI (match_dup 1)
10348                          (const_int 8))))
10349    (set (reg:DI 11)
10350         (mem:DI (plus:DI (match_dup 1)
10351                          (const_int 16))))
10352    (parallel [(set (match_operand 0 "" "")
10353                    (call (mem:SI (match_dup 3))
10354                          (match_operand 2 "" "")))
10355               (use (reg:DI 2))
10356               (use (reg:DI 11))
10357               (set (reg:DI 2)
10358                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10359               (clobber (scratch:SI))])]
10360   "TARGET_64BIT"
10361   "
10362 { operands[3] = gen_reg_rtx (DImode); }")
10363
10364 ;; Now the definitions for the call and call_value insns
10365 (define_expand "call"
10366   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10367                     (match_operand 1 "" ""))
10368               (use (match_operand 2 "" ""))
10369               (clobber (scratch:SI))])]
10370   ""
10371   "
10372 {
10373 #if TARGET_MACHO
10374   if (MACHOPIC_INDIRECT)
10375     operands[0] = machopic_indirect_call_target (operands[0]);
10376 #endif
10377
10378   gcc_assert (GET_CODE (operands[0]) == MEM);
10379   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
10380
10381   operands[0] = XEXP (operands[0], 0);
10382
10383   if (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT
10384       && flag_pic
10385       && GET_CODE (operands[0]) == SYMBOL_REF
10386       && !SYMBOL_REF_LOCAL_P (operands[0]))
10387     {
10388       rtx call;
10389       rtvec tmp;
10390
10391       tmp = gen_rtvec (3,
10392                        gen_rtx_CALL (VOIDmode,
10393                                      gen_rtx_MEM (SImode, operands[0]),
10394                                      operands[1]),
10395                        gen_rtx_USE (VOIDmode, operands[2]),
10396                        gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (SImode)));
10397       call = emit_call_insn (gen_rtx_PARALLEL (VOIDmode, tmp));
10398       use_reg (&CALL_INSN_FUNCTION_USAGE (call), pic_offset_table_rtx);
10399       DONE;
10400     }
10401
10402   if (GET_CODE (operands[0]) != SYMBOL_REF
10403       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
10404       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
10405     {
10406       if (INTVAL (operands[2]) & CALL_LONG)
10407         operands[0] = rs6000_longcall_ref (operands[0]);
10408
10409       switch (DEFAULT_ABI)
10410         {
10411         case ABI_V4:
10412         case ABI_DARWIN:
10413           operands[0] = force_reg (Pmode, operands[0]);
10414           break;
10415
10416         case ABI_AIX:
10417           /* AIX function pointers are really pointers to a three word
10418              area.  */
10419           emit_call_insn (TARGET_32BIT
10420                           ? gen_call_indirect_aix32 (force_reg (SImode,
10421                                                                 operands[0]),
10422                                                      operands[1])
10423                           : gen_call_indirect_aix64 (force_reg (DImode,
10424                                                                 operands[0]),
10425                                                      operands[1]));
10426           DONE;
10427
10428         default:
10429           gcc_unreachable ();
10430         }
10431     }
10432 }")
10433
10434 (define_expand "call_value"
10435   [(parallel [(set (match_operand 0 "" "")
10436                    (call (mem:SI (match_operand 1 "address_operand" ""))
10437                          (match_operand 2 "" "")))
10438               (use (match_operand 3 "" ""))
10439               (clobber (scratch:SI))])]
10440   ""
10441   "
10442 {
10443 #if TARGET_MACHO
10444   if (MACHOPIC_INDIRECT)
10445     operands[1] = machopic_indirect_call_target (operands[1]);
10446 #endif
10447
10448   gcc_assert (GET_CODE (operands[1]) == MEM);
10449   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
10450
10451   operands[1] = XEXP (operands[1], 0);
10452
10453   if (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT
10454       && flag_pic
10455       && GET_CODE (operands[1]) == SYMBOL_REF
10456       && !SYMBOL_REF_LOCAL_P (operands[1]))
10457     {
10458       rtx call;
10459       rtvec tmp;
10460
10461       tmp = gen_rtvec (3,
10462                        gen_rtx_SET (VOIDmode,
10463                                     operands[0],
10464                                     gen_rtx_CALL (VOIDmode,
10465                                                   gen_rtx_MEM (SImode,
10466                                                                operands[1]),
10467                                                   operands[2])),
10468                        gen_rtx_USE (VOIDmode, operands[3]),
10469                        gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (SImode)));
10470       call = emit_call_insn (gen_rtx_PARALLEL (VOIDmode, tmp));
10471       use_reg (&CALL_INSN_FUNCTION_USAGE (call), pic_offset_table_rtx);
10472       DONE;
10473     }
10474
10475   if (GET_CODE (operands[1]) != SYMBOL_REF
10476       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
10477       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
10478     {
10479       if (INTVAL (operands[3]) & CALL_LONG)
10480         operands[1] = rs6000_longcall_ref (operands[1]);
10481
10482       switch (DEFAULT_ABI)
10483         {
10484         case ABI_V4:
10485         case ABI_DARWIN:
10486           operands[1] = force_reg (Pmode, operands[1]);
10487           break;
10488
10489         case ABI_AIX:
10490           /* AIX function pointers are really pointers to a three word
10491              area.  */
10492           emit_call_insn (TARGET_32BIT
10493                           ? gen_call_value_indirect_aix32 (operands[0],
10494                                                            force_reg (SImode,
10495                                                                       operands[1]),
10496                                                            operands[2])
10497                           : gen_call_value_indirect_aix64 (operands[0],
10498                                                            force_reg (DImode,
10499                                                                       operands[1]),
10500                                                            operands[2]));
10501           DONE;
10502
10503         default:
10504           gcc_unreachable ();
10505         }
10506     }
10507 }")
10508
10509 ;; Call to function in current module.  No TOC pointer reload needed.
10510 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10511 ;; either the function was not prototyped, or it was prototyped as a
10512 ;; variable argument function.  It is > 0 if FP registers were passed
10513 ;; and < 0 if they were not.
10514
10515 (define_insn "*call_local32"
10516   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10517          (match_operand 1 "" "g,g"))
10518    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10519    (clobber (match_scratch:SI 3 "=l,l"))]
10520   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10521   "*
10522 {
10523   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10524     output_asm_insn (\"crxor 6,6,6\", operands);
10525
10526   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10527     output_asm_insn (\"creqv 6,6,6\", operands);
10528
10529   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10530 }"
10531   [(set_attr "type" "branch")
10532    (set_attr "length" "4,8")])
10533
10534 (define_insn "*call_local64"
10535   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10536          (match_operand 1 "" "g,g"))
10537    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10538    (clobber (match_scratch:SI 3 "=l,l"))]
10539   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10540   "*
10541 {
10542   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10543     output_asm_insn (\"crxor 6,6,6\", operands);
10544
10545   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10546     output_asm_insn (\"creqv 6,6,6\", operands);
10547
10548   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10549 }"
10550   [(set_attr "type" "branch")
10551    (set_attr "length" "4,8")])
10552
10553 (define_insn "*call_value_local32"
10554   [(set (match_operand 0 "" "")
10555         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10556               (match_operand 2 "" "g,g")))
10557    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10558    (clobber (match_scratch:SI 4 "=l,l"))]
10559   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10560   "*
10561 {
10562   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10563     output_asm_insn (\"crxor 6,6,6\", operands);
10564
10565   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10566     output_asm_insn (\"creqv 6,6,6\", operands);
10567
10568   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10569 }"
10570   [(set_attr "type" "branch")
10571    (set_attr "length" "4,8")])
10572
10573
10574 (define_insn "*call_value_local64"
10575   [(set (match_operand 0 "" "")
10576         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10577               (match_operand 2 "" "g,g")))
10578    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10579    (clobber (match_scratch:SI 4 "=l,l"))]
10580   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10581   "*
10582 {
10583   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10584     output_asm_insn (\"crxor 6,6,6\", operands);
10585
10586   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10587     output_asm_insn (\"creqv 6,6,6\", operands);
10588
10589   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10590 }"
10591   [(set_attr "type" "branch")
10592    (set_attr "length" "4,8")])
10593
10594 ;; Call to function which may be in another module.  Restore the TOC
10595 ;; pointer (r2) after the call unless this is System V.
10596 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10597 ;; either the function was not prototyped, or it was prototyped as a
10598 ;; variable argument function.  It is > 0 if FP registers were passed
10599 ;; and < 0 if they were not.
10600
10601 (define_insn "*call_indirect_nonlocal_aix32"
10602   [(call (mem:SI (match_operand:SI 0 "register_operand" "c,*l"))
10603          (match_operand 1 "" "g,g"))
10604    (use (reg:SI 2))
10605    (use (reg:SI 11))
10606    (set (reg:SI 2)
10607         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10608    (clobber (match_scratch:SI 2 "=l,l"))]
10609   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10610   "b%T0l\;{l|lwz} 2,20(1)"
10611   [(set_attr "type" "jmpreg")
10612    (set_attr "length" "8")])
10613
10614 (define_insn "*call_nonlocal_aix32"
10615   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10616          (match_operand 1 "" "g"))
10617    (use (match_operand:SI 2 "immediate_operand" "O"))
10618    (clobber (match_scratch:SI 3 "=l"))]
10619   "TARGET_32BIT
10620    && DEFAULT_ABI == ABI_AIX
10621    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10622   "bl %z0\;%."
10623   [(set_attr "type" "branch")
10624    (set_attr "length" "8")])
10625
10626 (define_insn "*call_indirect_nonlocal_aix64"
10627   [(call (mem:SI (match_operand:DI 0 "register_operand" "c,*l"))
10628          (match_operand 1 "" "g,g"))
10629    (use (reg:DI 2))
10630    (use (reg:DI 11))
10631    (set (reg:DI 2)
10632         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10633    (clobber (match_scratch:SI 2 "=l,l"))]
10634   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10635   "b%T0l\;ld 2,40(1)"
10636   [(set_attr "type" "jmpreg")
10637    (set_attr "length" "8")])
10638
10639 (define_insn "*call_nonlocal_aix64"
10640   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10641          (match_operand 1 "" "g"))
10642    (use (match_operand:SI 2 "immediate_operand" "O"))
10643    (clobber (match_scratch:SI 3 "=l"))]
10644   "TARGET_64BIT
10645    && DEFAULT_ABI == ABI_AIX
10646    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10647   "bl %z0\;%."
10648   [(set_attr "type" "branch")
10649    (set_attr "length" "8")])
10650
10651 (define_insn "*call_value_indirect_nonlocal_aix32"
10652   [(set (match_operand 0 "" "")
10653         (call (mem:SI (match_operand:SI 1 "register_operand" "c,*l"))
10654               (match_operand 2 "" "g,g")))
10655    (use (reg:SI 2))
10656    (use (reg:SI 11))
10657    (set (reg:SI 2)
10658         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10659    (clobber (match_scratch:SI 3 "=l,l"))]
10660   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10661   "b%T1l\;{l|lwz} 2,20(1)"
10662   [(set_attr "type" "jmpreg")
10663    (set_attr "length" "8")])
10664
10665 (define_insn "*call_value_nonlocal_aix32"
10666   [(set (match_operand 0 "" "")
10667         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10668               (match_operand 2 "" "g")))
10669    (use (match_operand:SI 3 "immediate_operand" "O"))
10670    (clobber (match_scratch:SI 4 "=l"))]
10671   "TARGET_32BIT
10672    && DEFAULT_ABI == ABI_AIX
10673    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10674   "bl %z1\;%."
10675   [(set_attr "type" "branch")
10676    (set_attr "length" "8")])
10677
10678 (define_insn "*call_value_indirect_nonlocal_aix64"
10679   [(set (match_operand 0 "" "")
10680         (call (mem:SI (match_operand:DI 1 "register_operand" "c,*l"))
10681               (match_operand 2 "" "g,g")))
10682    (use (reg:DI 2))
10683    (use (reg:DI 11))
10684    (set (reg:DI 2)
10685         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10686    (clobber (match_scratch:SI 3 "=l,l"))]
10687   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10688   "b%T1l\;ld 2,40(1)"
10689   [(set_attr "type" "jmpreg")
10690    (set_attr "length" "8")])
10691
10692 (define_insn "*call_value_nonlocal_aix64"
10693   [(set (match_operand 0 "" "")
10694         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10695               (match_operand 2 "" "g")))
10696    (use (match_operand:SI 3 "immediate_operand" "O"))
10697    (clobber (match_scratch:SI 4 "=l"))]
10698   "TARGET_64BIT
10699    && DEFAULT_ABI == ABI_AIX
10700    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10701   "bl %z1\;%."
10702   [(set_attr "type" "branch")
10703    (set_attr "length" "8")])
10704
10705 ;; A function pointer under System V is just a normal pointer
10706 ;; operands[0] is the function pointer
10707 ;; operands[1] is the stack size to clean up
10708 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
10709 ;; which indicates how to set cr1
10710
10711 (define_insn "*call_indirect_nonlocal_sysv<mode>"
10712   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l,c,*l"))
10713          (match_operand 1 "" "g,g,g,g"))
10714    (use (match_operand:SI 2 "immediate_operand" "O,O,n,n"))
10715    (clobber (match_scratch:SI 3 "=l,l,l,l"))]
10716   "DEFAULT_ABI == ABI_V4
10717    || DEFAULT_ABI == ABI_DARWIN"
10718 {
10719   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10720     output_asm_insn ("crxor 6,6,6", operands);
10721
10722   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10723     output_asm_insn ("creqv 6,6,6", operands);
10724
10725   return "b%T0l";
10726 }
10727   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
10728    (set_attr "length" "4,4,8,8")])
10729
10730 (define_insn "*call_nonlocal_sysv<mode>"
10731   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
10732          (match_operand 1 "" "g,g"))
10733    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10734    (clobber (match_scratch:SI 3 "=l,l"))]
10735   "(DEFAULT_ABI == ABI_DARWIN
10736    || (DEFAULT_ABI == ABI_V4
10737        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
10738 {
10739   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10740     output_asm_insn ("crxor 6,6,6", operands);
10741
10742   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10743     output_asm_insn ("creqv 6,6,6", operands);
10744
10745 #if TARGET_MACHO
10746   return output_call(insn, operands, 0, 2);
10747 #else
10748   if (DEFAULT_ABI == ABI_V4 && flag_pic)
10749     {
10750       if (TARGET_SECURE_PLT && flag_pic == 2)
10751         /* The magic 32768 offset here and in the other sysv call insns
10752            corresponds to the offset of r30 in .got2, as given by LCTOC1.
10753            See sysv4.h:toc_section.  */
10754         return "bl %z0+32768@plt";
10755       else
10756         return "bl %z0@plt";
10757     }
10758   else
10759     return "bl %z0";
10760 #endif
10761 }
10762   [(set_attr "type" "branch,branch")
10763    (set_attr "length" "4,8")])
10764
10765 (define_insn "*call_value_indirect_nonlocal_sysv<mode>"
10766   [(set (match_operand 0 "" "")
10767         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l,c,*l"))
10768               (match_operand 2 "" "g,g,g,g")))
10769    (use (match_operand:SI 3 "immediate_operand" "O,O,n,n"))
10770    (clobber (match_scratch:SI 4 "=l,l,l,l"))]
10771   "DEFAULT_ABI == ABI_V4
10772    || DEFAULT_ABI == ABI_DARWIN"
10773 {
10774   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10775     output_asm_insn ("crxor 6,6,6", operands);
10776
10777   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10778     output_asm_insn ("creqv 6,6,6", operands);
10779
10780   return "b%T1l";
10781 }
10782   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
10783    (set_attr "length" "4,4,8,8")])
10784
10785 (define_insn "*call_value_nonlocal_sysv<mode>"
10786   [(set (match_operand 0 "" "")
10787         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
10788               (match_operand 2 "" "g,g")))
10789    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10790    (clobber (match_scratch:SI 4 "=l,l"))]
10791   "(DEFAULT_ABI == ABI_DARWIN
10792    || (DEFAULT_ABI == ABI_V4
10793        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
10794 {
10795   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10796     output_asm_insn ("crxor 6,6,6", operands);
10797
10798   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10799     output_asm_insn ("creqv 6,6,6", operands);
10800
10801 #if TARGET_MACHO
10802   return output_call(insn, operands, 1, 3);
10803 #else
10804   if (DEFAULT_ABI == ABI_V4 && flag_pic)
10805     {
10806       if (TARGET_SECURE_PLT && flag_pic == 2)
10807         return "bl %z1+32768@plt";
10808       else
10809         return "bl %z1@plt";
10810     }
10811   else
10812     return "bl %z1";
10813 #endif
10814 }
10815   [(set_attr "type" "branch,branch")
10816    (set_attr "length" "4,8")])
10817
10818 ;; Call subroutine returning any type.
10819 (define_expand "untyped_call"
10820   [(parallel [(call (match_operand 0 "" "")
10821                     (const_int 0))
10822               (match_operand 1 "" "")
10823               (match_operand 2 "" "")])]
10824   ""
10825   "
10826 {
10827   int i;
10828
10829   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
10830
10831   for (i = 0; i < XVECLEN (operands[2], 0); i++)
10832     {
10833       rtx set = XVECEXP (operands[2], 0, i);
10834       emit_move_insn (SET_DEST (set), SET_SRC (set));
10835     }
10836
10837   /* The optimizer does not know that the call sets the function value
10838      registers we stored in the result block.  We avoid problems by
10839      claiming that all hard registers are used and clobbered at this
10840      point.  */
10841   emit_insn (gen_blockage ());
10842
10843   DONE;
10844 }")
10845
10846 ;; sibling call patterns
10847 (define_expand "sibcall"
10848   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10849                     (match_operand 1 "" ""))
10850               (use (match_operand 2 "" ""))
10851               (use (match_operand 3 "" ""))
10852               (return)])]
10853   ""
10854   "
10855 {
10856 #if TARGET_MACHO
10857   if (MACHOPIC_INDIRECT)
10858     operands[0] = machopic_indirect_call_target (operands[0]);
10859 #endif
10860
10861   gcc_assert (GET_CODE (operands[0]) == MEM);
10862   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
10863
10864   operands[0] = XEXP (operands[0], 0);
10865   operands[3] = gen_reg_rtx (SImode);
10866
10867 }")
10868
10869 ;; this and similar patterns must be marked as using LR, otherwise
10870 ;; dataflow will try to delete the store into it.  This is true
10871 ;; even when the actual reg to jump to is in CTR, when LR was
10872 ;; saved and restored around the PIC-setting BCL.
10873 (define_insn "*sibcall_local32"
10874   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10875          (match_operand 1 "" "g,g"))
10876    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10877    (use (match_operand:SI 3 "register_operand" "l,l"))
10878    (return)]
10879   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10880   "*
10881 {
10882   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10883     output_asm_insn (\"crxor 6,6,6\", operands);
10884
10885   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10886     output_asm_insn (\"creqv 6,6,6\", operands);
10887
10888   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
10889 }"
10890   [(set_attr "type" "branch")
10891    (set_attr "length" "4,8")])
10892
10893 (define_insn "*sibcall_local64"
10894   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10895          (match_operand 1 "" "g,g"))
10896    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10897    (use (match_operand:SI 3 "register_operand" "l,l"))
10898    (return)]
10899   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10900   "*
10901 {
10902   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10903     output_asm_insn (\"crxor 6,6,6\", operands);
10904
10905   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10906     output_asm_insn (\"creqv 6,6,6\", operands);
10907
10908   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
10909 }"
10910   [(set_attr "type" "branch")
10911    (set_attr "length" "4,8")])
10912
10913 (define_insn "*sibcall_value_local32"
10914   [(set (match_operand 0 "" "")
10915         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10916               (match_operand 2 "" "g,g")))
10917    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10918    (use (match_operand:SI 4 "register_operand" "l,l"))
10919    (return)]
10920   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10921   "*
10922 {
10923   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10924     output_asm_insn (\"crxor 6,6,6\", operands);
10925
10926   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10927     output_asm_insn (\"creqv 6,6,6\", operands);
10928
10929   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
10930 }"
10931   [(set_attr "type" "branch")
10932    (set_attr "length" "4,8")])
10933
10934
10935 (define_insn "*sibcall_value_local64"
10936   [(set (match_operand 0 "" "")
10937         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10938               (match_operand 2 "" "g,g")))
10939    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10940    (use (match_operand:SI 4 "register_operand" "l,l"))
10941    (return)]
10942   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10943   "*
10944 {
10945   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10946     output_asm_insn (\"crxor 6,6,6\", operands);
10947
10948   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10949     output_asm_insn (\"creqv 6,6,6\", operands);
10950
10951   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
10952 }"
10953   [(set_attr "type" "branch")
10954    (set_attr "length" "4,8")])
10955
10956 (define_insn "*sibcall_nonlocal_aix32"
10957   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10958          (match_operand 1 "" "g"))
10959    (use (match_operand:SI 2 "immediate_operand" "O"))
10960    (use (match_operand:SI 3 "register_operand" "l"))
10961    (return)]
10962   "TARGET_32BIT
10963    && DEFAULT_ABI == ABI_AIX
10964    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10965   "b %z0"
10966   [(set_attr "type" "branch")
10967    (set_attr "length" "4")])
10968
10969 (define_insn "*sibcall_nonlocal_aix64"
10970   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10971          (match_operand 1 "" "g"))
10972    (use (match_operand:SI 2 "immediate_operand" "O"))
10973    (use (match_operand:SI 3 "register_operand" "l"))
10974    (return)]
10975   "TARGET_64BIT
10976    && DEFAULT_ABI == ABI_AIX
10977    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10978   "b %z0"
10979   [(set_attr "type" "branch")
10980    (set_attr "length" "4")])
10981
10982 (define_insn "*sibcall_value_nonlocal_aix32"
10983   [(set (match_operand 0 "" "")
10984         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10985               (match_operand 2 "" "g")))
10986    (use (match_operand:SI 3 "immediate_operand" "O"))
10987    (use (match_operand:SI 4 "register_operand" "l"))
10988    (return)]
10989   "TARGET_32BIT
10990    && DEFAULT_ABI == ABI_AIX
10991    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10992   "b %z1"
10993   [(set_attr "type" "branch")
10994    (set_attr "length" "4")])
10995
10996 (define_insn "*sibcall_value_nonlocal_aix64"
10997   [(set (match_operand 0 "" "")
10998         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10999               (match_operand 2 "" "g")))
11000    (use (match_operand:SI 3 "immediate_operand" "O"))
11001    (use (match_operand:SI 4 "register_operand" "l"))
11002    (return)]
11003   "TARGET_64BIT
11004    && DEFAULT_ABI == ABI_AIX
11005    && (INTVAL (operands[3]) & CALL_LONG) == 0"
11006   "b %z1"
11007   [(set_attr "type" "branch")
11008    (set_attr "length" "4")])
11009
11010 (define_insn "*sibcall_nonlocal_sysv<mode>"
11011   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
11012          (match_operand 1 "" ""))
11013    (use (match_operand 2 "immediate_operand" "O,n"))
11014    (use (match_operand:SI 3 "register_operand" "l,l"))
11015    (return)]
11016   "(DEFAULT_ABI == ABI_DARWIN
11017      || DEFAULT_ABI == ABI_V4)
11018    && (INTVAL (operands[2]) & CALL_LONG) == 0"
11019   "*
11020 {
11021   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11022     output_asm_insn (\"crxor 6,6,6\", operands);
11023
11024   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11025     output_asm_insn (\"creqv 6,6,6\", operands);
11026
11027   if (DEFAULT_ABI == ABI_V4 && flag_pic)
11028     {
11029       if (TARGET_SECURE_PLT && flag_pic == 2)
11030         return \"b %z0+32768@plt\";
11031       else
11032         return \"b %z0@plt\";
11033     }
11034   else
11035     return \"b %z0\";
11036 }"
11037   [(set_attr "type" "branch,branch")
11038    (set_attr "length" "4,8")])
11039
11040 (define_expand "sibcall_value"
11041   [(parallel [(set (match_operand 0 "register_operand" "")
11042                 (call (mem:SI (match_operand 1 "address_operand" ""))
11043                       (match_operand 2 "" "")))
11044               (use (match_operand 3 "" ""))
11045               (use (match_operand 4 "" ""))
11046               (return)])]
11047   ""
11048   "
11049 {
11050 #if TARGET_MACHO
11051   if (MACHOPIC_INDIRECT)
11052     operands[1] = machopic_indirect_call_target (operands[1]);
11053 #endif
11054
11055   gcc_assert (GET_CODE (operands[1]) == MEM);
11056   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
11057
11058   operands[1] = XEXP (operands[1], 0);
11059   operands[4] = gen_reg_rtx (SImode);
11060
11061 }")
11062
11063 (define_insn "*sibcall_value_nonlocal_sysv<mode>"
11064   [(set (match_operand 0 "" "")
11065         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
11066               (match_operand 2 "" "")))
11067    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11068    (use (match_operand:SI 4 "register_operand" "l,l"))
11069    (return)]
11070   "(DEFAULT_ABI == ABI_DARWIN
11071        || DEFAULT_ABI == ABI_V4)
11072    && (INTVAL (operands[3]) & CALL_LONG) == 0"
11073   "*
11074 {
11075   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11076     output_asm_insn (\"crxor 6,6,6\", operands);
11077
11078   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11079     output_asm_insn (\"creqv 6,6,6\", operands);
11080
11081   if (DEFAULT_ABI == ABI_V4 && flag_pic)
11082     {
11083       if (TARGET_SECURE_PLT && flag_pic == 2)
11084         return \"b %z1+32768@plt\";
11085       else
11086         return \"b %z1@plt\";
11087     }
11088   else
11089     return \"b %z1\";
11090 }"
11091   [(set_attr "type" "branch,branch")
11092    (set_attr "length" "4,8")])
11093
11094 (define_expand "sibcall_epilogue"
11095   [(use (const_int 0))]
11096   "TARGET_SCHED_PROLOG"
11097   "
11098 {
11099       rs6000_emit_epilogue (TRUE);
11100       DONE;
11101 }")
11102
11103 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
11104 ;; all of memory.  This blocks insns from being moved across this point.
11105
11106 (define_insn "blockage"
11107   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
11108   ""
11109   "")
11110 \f
11111 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
11112 ;; signed & unsigned, and one type of branch.
11113 ;;
11114 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
11115 ;; insns, and branches.  We store the operands of compares until we see
11116 ;; how it is used.
11117 (define_expand "cmp<mode>"
11118   [(set (cc0)
11119         (compare (match_operand:GPR 0 "gpc_reg_operand" "")
11120                  (match_operand:GPR 1 "reg_or_short_operand" "")))]
11121   ""
11122   "
11123 {
11124   /* Take care of the possibility that operands[1] might be negative but
11125      this might be a logical operation.  That insn doesn't exist.  */
11126   if (GET_CODE (operands[1]) == CONST_INT
11127       && INTVAL (operands[1]) < 0)
11128     operands[1] = force_reg (<MODE>mode, operands[1]);
11129
11130   rs6000_compare_op0 = operands[0];
11131   rs6000_compare_op1 = operands[1];
11132   rs6000_compare_fp_p = 0;
11133   DONE;
11134 }")
11135
11136 (define_expand "cmp<mode>"
11137   [(set (cc0) (compare (match_operand:FP 0 "gpc_reg_operand" "")
11138                        (match_operand:FP 1 "gpc_reg_operand" "")))]
11139   ""
11140   "
11141 {
11142   rs6000_compare_op0 = operands[0];
11143   rs6000_compare_op1 = operands[1];
11144   rs6000_compare_fp_p = 1;
11145   DONE;
11146 }")
11147
11148 (define_expand "beq"
11149   [(use (match_operand 0 "" ""))]
11150   ""
11151   "{ rs6000_emit_cbranch (EQ, operands[0]); DONE; }")
11152
11153 (define_expand "bne"
11154   [(use (match_operand 0 "" ""))]
11155   ""
11156   "{ rs6000_emit_cbranch (NE, operands[0]); DONE; }")
11157
11158 (define_expand "bge"
11159   [(use (match_operand 0 "" ""))]
11160   ""
11161   "{ rs6000_emit_cbranch (GE, operands[0]); DONE; }")
11162
11163 (define_expand "bgt"
11164   [(use (match_operand 0 "" ""))]
11165   ""
11166   "{ rs6000_emit_cbranch (GT, operands[0]); DONE; }")
11167
11168 (define_expand "ble"
11169   [(use (match_operand 0 "" ""))]
11170   ""
11171   "{ rs6000_emit_cbranch (LE, operands[0]); DONE; }")
11172
11173 (define_expand "blt"
11174   [(use (match_operand 0 "" ""))]
11175   ""
11176   "{ rs6000_emit_cbranch (LT, operands[0]); DONE; }")
11177
11178 (define_expand "bgeu"
11179   [(use (match_operand 0 "" ""))]
11180   ""
11181   "{ rs6000_emit_cbranch (GEU, operands[0]); DONE; }")
11182
11183 (define_expand "bgtu"
11184   [(use (match_operand 0 "" ""))]
11185   ""
11186   "{ rs6000_emit_cbranch (GTU, operands[0]); DONE; }")
11187
11188 (define_expand "bleu"
11189   [(use (match_operand 0 "" ""))]
11190   ""
11191   "{ rs6000_emit_cbranch (LEU, operands[0]); DONE; }")
11192
11193 (define_expand "bltu"
11194   [(use (match_operand 0 "" ""))]
11195   ""
11196   "{ rs6000_emit_cbranch (LTU, operands[0]); DONE; }")
11197
11198 (define_expand "bunordered"
11199   [(use (match_operand 0 "" ""))]
11200   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
11201   "{ rs6000_emit_cbranch (UNORDERED, operands[0]); DONE; }")
11202
11203 (define_expand "bordered"
11204   [(use (match_operand 0 "" ""))]
11205   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
11206   "{ rs6000_emit_cbranch (ORDERED, operands[0]); DONE; }")
11207
11208 (define_expand "buneq"
11209   [(use (match_operand 0 "" ""))]
11210   ""
11211   "{ rs6000_emit_cbranch (UNEQ, operands[0]); DONE; }")
11212
11213 (define_expand "bunge"
11214   [(use (match_operand 0 "" ""))]
11215   ""
11216   "{ rs6000_emit_cbranch (UNGE, operands[0]); DONE; }")
11217
11218 (define_expand "bungt"
11219   [(use (match_operand 0 "" ""))]
11220   ""
11221   "{ rs6000_emit_cbranch (UNGT, operands[0]); DONE; }")
11222
11223 (define_expand "bunle"
11224   [(use (match_operand 0 "" ""))]
11225   ""
11226   "{ rs6000_emit_cbranch (UNLE, operands[0]); DONE; }")
11227
11228 (define_expand "bunlt"
11229   [(use (match_operand 0 "" ""))]
11230   ""
11231   "{ rs6000_emit_cbranch (UNLT, operands[0]); DONE; }")
11232
11233 (define_expand "bltgt"
11234   [(use (match_operand 0 "" ""))]
11235   ""
11236   "{ rs6000_emit_cbranch (LTGT, operands[0]); DONE; }")
11237
11238 ;; For SNE, we would prefer that the xor/abs sequence be used for integers.
11239 ;; For SEQ, likewise, except that comparisons with zero should be done
11240 ;; with an scc insns.  However, due to the order that combine see the
11241 ;; resulting insns, we must, in fact, allow SEQ for integers.  Fail in
11242 ;; the cases we don't want to handle.
11243 (define_expand "seq"
11244   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11245   ""
11246   "{ rs6000_emit_sCOND (EQ, operands[0]); DONE; }")
11247
11248 (define_expand "sne"
11249   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11250   ""
11251   "
11252 {
11253   if (! rs6000_compare_fp_p)
11254     FAIL;
11255
11256   rs6000_emit_sCOND (NE, operands[0]);
11257   DONE;
11258 }")
11259
11260 ;; A >= 0 is best done the portable way for A an integer.
11261 (define_expand "sge"
11262   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11263   ""
11264   "
11265 {
11266   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
11267     FAIL;
11268
11269   rs6000_emit_sCOND (GE, operands[0]);
11270   DONE;
11271 }")
11272
11273 ;; A > 0 is best done using the portable sequence, so fail in that case.
11274 (define_expand "sgt"
11275   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11276   ""
11277   "
11278 {
11279   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
11280     FAIL;
11281
11282   rs6000_emit_sCOND (GT, operands[0]);
11283   DONE;
11284 }")
11285
11286 ;; A <= 0 is best done the portable way for A an integer.
11287 (define_expand "sle"
11288   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11289   ""
11290   "
11291 {
11292   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
11293     FAIL;
11294
11295   rs6000_emit_sCOND (LE, operands[0]);
11296   DONE;
11297 }")
11298
11299 ;; A < 0 is best done in the portable way for A an integer.
11300 (define_expand "slt"
11301   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11302   ""
11303   "
11304 {
11305   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
11306     FAIL;
11307
11308   rs6000_emit_sCOND (LT, operands[0]);
11309   DONE;
11310 }")
11311
11312 (define_expand "sgeu"
11313   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11314   ""
11315   "{ rs6000_emit_sCOND (GEU, operands[0]); DONE; }")
11316
11317 (define_expand "sgtu"
11318   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11319   ""
11320   "{ rs6000_emit_sCOND (GTU, operands[0]); DONE; }")
11321
11322 (define_expand "sleu"
11323   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11324   ""
11325   "{ rs6000_emit_sCOND (LEU, operands[0]); DONE; }")
11326
11327 (define_expand "sltu"
11328   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11329   ""
11330   "{ rs6000_emit_sCOND (LTU, operands[0]); DONE; }")
11331
11332 (define_expand "sunordered"
11333   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11334   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
11335   "{ rs6000_emit_sCOND (UNORDERED, operands[0]); DONE; }")
11336
11337 (define_expand "sordered"
11338   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11339   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
11340   "{ rs6000_emit_sCOND (ORDERED, operands[0]); DONE; }")
11341
11342 (define_expand "suneq"
11343   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11344   ""
11345   "{ rs6000_emit_sCOND (UNEQ, operands[0]); DONE; }")
11346
11347 (define_expand "sunge"
11348   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11349   ""
11350   "{ rs6000_emit_sCOND (UNGE, operands[0]); DONE; }")
11351
11352 (define_expand "sungt"
11353   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11354   ""
11355   "{ rs6000_emit_sCOND (UNGT, operands[0]); DONE; }")
11356
11357 (define_expand "sunle"
11358   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11359   ""
11360   "{ rs6000_emit_sCOND (UNLE, operands[0]); DONE; }")
11361
11362 (define_expand "sunlt"
11363   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11364   ""
11365   "{ rs6000_emit_sCOND (UNLT, operands[0]); DONE; }")
11366
11367 (define_expand "sltgt"
11368   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11369   ""
11370   "{ rs6000_emit_sCOND (LTGT, operands[0]); DONE; }")
11371
11372 (define_expand "stack_protect_set"
11373   [(match_operand 0 "memory_operand" "")
11374    (match_operand 1 "memory_operand" "")]
11375   ""
11376 {
11377 #ifdef TARGET_THREAD_SSP_OFFSET
11378   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
11379   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
11380   operands[1] = gen_rtx_MEM (Pmode, addr);
11381 #endif
11382   if (TARGET_64BIT)
11383     emit_insn (gen_stack_protect_setdi (operands[0], operands[1]));
11384   else
11385     emit_insn (gen_stack_protect_setsi (operands[0], operands[1]));
11386   DONE;
11387 })
11388
11389 (define_insn "stack_protect_setsi"
11390   [(set (match_operand:SI 0 "memory_operand" "=m")
11391         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
11392    (set (match_scratch:SI 2 "=&r") (const_int 0))]
11393   "TARGET_32BIT"
11394   "{l%U1%X1|lwz%U1%X1} %2,%1\;{st%U0%X0|stw%U0%X0} %2,%0\;{lil|li} %2,0"
11395   [(set_attr "type" "three")
11396    (set_attr "length" "12")])
11397
11398 (define_insn "stack_protect_setdi"
11399   [(set (match_operand:DI 0 "memory_operand" "=m")
11400         (unspec:DI [(match_operand:DI 1 "memory_operand" "m")] UNSPEC_SP_SET))
11401    (set (match_scratch:DI 2 "=&r") (const_int 0))]
11402   "TARGET_64BIT"
11403   "ld%U1%X1 %2,%1\;std%U0%X0 %2,%0\;{lil|li} %2,0"
11404   [(set_attr "type" "three")
11405    (set_attr "length" "12")])
11406
11407 (define_expand "stack_protect_test"
11408   [(match_operand 0 "memory_operand" "")
11409    (match_operand 1 "memory_operand" "")
11410    (match_operand 2 "" "")]
11411   ""
11412 {
11413 #ifdef TARGET_THREAD_SSP_OFFSET
11414   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
11415   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
11416   operands[1] = gen_rtx_MEM (Pmode, addr);
11417 #endif
11418   rs6000_compare_op0 = operands[0];
11419   rs6000_compare_op1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, operands[1]),
11420                                        UNSPEC_SP_TEST);
11421   rs6000_compare_fp_p = 0;
11422   emit_jump_insn (gen_beq (operands[2]));
11423   DONE;
11424 })
11425
11426 (define_insn "stack_protect_testsi"
11427   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
11428         (unspec:CCEQ [(match_operand:SI 1 "memory_operand" "m,m")
11429                       (match_operand:SI 2 "memory_operand" "m,m")]
11430                      UNSPEC_SP_TEST))
11431    (set (match_scratch:SI 4 "=r,r") (const_int 0))
11432    (clobber (match_scratch:SI 3 "=&r,&r"))]
11433   "TARGET_32BIT"
11434   "@
11435    {l%U1%X1|lwz%U1%X1} %3,%1\;{l%U2%X2|lwz%U2%X2} %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
11436    {l%U1%X1|lwz%U1%X1} %3,%1\;{l%U2%X2|lwz%U2%X2} %4,%2\;{cmpl|cmplw} %0,%3,%4\;{lil|li} %3,0\;{lil|li} %4,0"
11437   [(set_attr "length" "16,20")])
11438
11439 (define_insn "stack_protect_testdi"
11440   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
11441         (unspec:CCEQ [(match_operand:DI 1 "memory_operand" "m,m")
11442                       (match_operand:DI 2 "memory_operand" "m,m")]
11443                      UNSPEC_SP_TEST))
11444    (set (match_scratch:DI 4 "=r,r") (const_int 0))
11445    (clobber (match_scratch:DI 3 "=&r,&r"))]
11446   "TARGET_64BIT"
11447   "@
11448    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
11449    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;cmpld %0,%3,%4\;{lil|li} %3,0\;{lil|li} %4,0"
11450   [(set_attr "length" "16,20")])
11451
11452 \f
11453 ;; Here are the actual compare insns.
11454 (define_insn "*cmp<mode>_internal1"
11455   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11456         (compare:CC (match_operand:GPR 1 "gpc_reg_operand" "r")
11457                     (match_operand:GPR 2 "reg_or_short_operand" "rI")))]
11458   ""
11459   "{cmp%I2|cmp<wd>%I2} %0,%1,%2"
11460   [(set_attr "type" "cmp")])
11461
11462 ;; If we are comparing a register for equality with a large constant,
11463 ;; we can do this with an XOR followed by a compare.  But this is profitable
11464 ;; only if the large constant is only used for the comparison (and in this
11465 ;; case we already have a register to reuse as scratch).
11466 ;;
11467 ;; For 64-bit registers, we could only do so if the constant's bit 15 is clear:
11468 ;; otherwise we'd need to XOR with FFFFFFFF????0000 which is not available.
11469
11470 (define_peephole2
11471   [(set (match_operand:SI 0 "register_operand")
11472         (match_operand:SI 1 "logical_const_operand" ""))
11473    (set (match_dup 0) (match_operator:SI 3 "boolean_or_operator"
11474                        [(match_dup 0)
11475                         (match_operand:SI 2 "logical_const_operand" "")]))
11476    (set (match_operand:CC 4 "cc_reg_operand" "")
11477         (compare:CC (match_operand:SI 5 "gpc_reg_operand" "")
11478                     (match_dup 0)))
11479    (set (pc)
11480         (if_then_else (match_operator 6 "equality_operator"
11481                        [(match_dup 4) (const_int 0)])
11482                       (match_operand 7 "" "")
11483                       (match_operand 8 "" "")))]
11484   "peep2_reg_dead_p (3, operands[0])
11485    && peep2_reg_dead_p (4, operands[4])"
11486  [(set (match_dup 0) (xor:SI (match_dup 5) (match_dup 9)))
11487   (set (match_dup 4) (compare:CC (match_dup 0) (match_dup 10)))
11488   (set (pc) (if_then_else (match_dup 6) (match_dup 7) (match_dup 8)))]
11489  
11490 {
11491   /* Get the constant we are comparing against, and see what it looks like
11492      when sign-extended from 16 to 32 bits.  Then see what constant we could
11493      XOR with SEXTC to get the sign-extended value.  */
11494   rtx cnst = simplify_const_binary_operation (GET_CODE (operands[3]),
11495                                               SImode,
11496                                               operands[1], operands[2]);
11497   HOST_WIDE_INT c = INTVAL (cnst);
11498   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
11499   HOST_WIDE_INT xorv = c ^ sextc;
11500
11501   operands[9] = GEN_INT (xorv);
11502   operands[10] = GEN_INT (sextc);
11503 })
11504
11505 (define_insn "*cmpsi_internal2"
11506   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11507         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11508                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
11509   ""
11510   "{cmpl%I2|cmplw%I2} %0,%1,%b2"
11511   [(set_attr "type" "cmp")])
11512
11513 (define_insn "*cmpdi_internal2"
11514   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11515         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
11516                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
11517   ""
11518   "cmpld%I2 %0,%1,%b2"
11519   [(set_attr "type" "cmp")])
11520
11521 ;; The following two insns don't exist as single insns, but if we provide
11522 ;; them, we can swap an add and compare, which will enable us to overlap more
11523 ;; of the required delay between a compare and branch.  We generate code for
11524 ;; them by splitting.
11525
11526 (define_insn ""
11527   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
11528         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11529                     (match_operand:SI 2 "short_cint_operand" "i")))
11530    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11531         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11532   ""
11533   "#"
11534   [(set_attr "length" "8")])
11535
11536 (define_insn ""
11537   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
11538         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11539                        (match_operand:SI 2 "u_short_cint_operand" "i")))
11540    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11541         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11542   ""
11543   "#"
11544   [(set_attr "length" "8")])
11545
11546 (define_split
11547   [(set (match_operand:CC 3 "cc_reg_operand" "")
11548         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11549                     (match_operand:SI 2 "short_cint_operand" "")))
11550    (set (match_operand:SI 0 "gpc_reg_operand" "")
11551         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11552   ""
11553   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
11554    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11555
11556 (define_split
11557   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
11558         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
11559                        (match_operand:SI 2 "u_short_cint_operand" "")))
11560    (set (match_operand:SI 0 "gpc_reg_operand" "")
11561         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11562   ""
11563   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
11564    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11565
11566 (define_insn "*cmpsf_internal1"
11567   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11568         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
11569                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
11570   "TARGET_HARD_FLOAT && TARGET_FPRS"
11571   "fcmpu %0,%1,%2"
11572   [(set_attr "type" "fpcompare")])
11573
11574 (define_insn "*cmpdf_internal1"
11575   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11576         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "f")
11577                       (match_operand:DF 2 "gpc_reg_operand" "f")))]
11578   "TARGET_HARD_FLOAT && TARGET_FPRS"
11579   "fcmpu %0,%1,%2"
11580   [(set_attr "type" "fpcompare")])
11581
11582 ;; Only need to compare second words if first words equal
11583 (define_insn "*cmptf_internal1"
11584   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11585         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11586                       (match_operand:TF 2 "gpc_reg_operand" "f")))]
11587   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
11588    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
11589   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
11590   [(set_attr "type" "fpcompare")
11591    (set_attr "length" "12")])
11592
11593 (define_insn_and_split "*cmptf_internal2"
11594   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11595         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11596                       (match_operand:TF 2 "gpc_reg_operand" "f")))
11597     (clobber (match_scratch:DF 3 "=f"))
11598     (clobber (match_scratch:DF 4 "=f"))
11599     (clobber (match_scratch:DF 5 "=f"))
11600     (clobber (match_scratch:DF 6 "=f"))
11601     (clobber (match_scratch:DF 7 "=f"))
11602     (clobber (match_scratch:DF 8 "=f"))
11603     (clobber (match_scratch:DF 9 "=f"))
11604     (clobber (match_scratch:DF 10 "=f"))]
11605   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
11606    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
11607   "#"
11608   "&& reload_completed"
11609   [(set (match_dup 3) (match_dup 13))
11610    (set (match_dup 4) (match_dup 14))
11611    (set (match_dup 9) (abs:DF (match_dup 5)))
11612    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
11613    (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
11614                            (label_ref (match_dup 11))
11615                            (pc)))
11616    (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
11617    (set (pc) (label_ref (match_dup 12)))
11618    (match_dup 11)
11619    (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
11620    (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
11621    (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
11622    (set (match_dup 0) (compare:CCFP (match_dup 7) (match_dup 4)))
11623    (match_dup 12)]
11624 {
11625   REAL_VALUE_TYPE rv;
11626   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
11627   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
11628
11629   operands[5] = simplify_gen_subreg (DFmode, operands[1], TFmode, hi_word);
11630   operands[6] = simplify_gen_subreg (DFmode, operands[1], TFmode, lo_word);
11631   operands[7] = simplify_gen_subreg (DFmode, operands[2], TFmode, hi_word);
11632   operands[8] = simplify_gen_subreg (DFmode, operands[2], TFmode, lo_word);
11633   operands[11] = gen_label_rtx ();
11634   operands[12] = gen_label_rtx ();
11635   real_inf (&rv);
11636   operands[13] = force_const_mem (DFmode,
11637                                   CONST_DOUBLE_FROM_REAL_VALUE (rv, DFmode));
11638   operands[14] = force_const_mem (DFmode,
11639                                   CONST_DOUBLE_FROM_REAL_VALUE (dconst0,
11640                                                                 DFmode));
11641   if (TARGET_TOC)
11642     {
11643       operands[13] = gen_const_mem (DFmode,
11644                                     create_TOC_reference (XEXP (operands[13], 0)));
11645       operands[14] = gen_const_mem (DFmode,
11646                                     create_TOC_reference (XEXP (operands[14], 0)));
11647       set_mem_alias_set (operands[13], get_TOC_alias_set ());
11648       set_mem_alias_set (operands[14], get_TOC_alias_set ());
11649     }
11650 })
11651 \f
11652 ;; Now we have the scc insns.  We can do some combinations because of the
11653 ;; way the machine works.
11654 ;;
11655 ;; Note that this is probably faster if we can put an insn between the
11656 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
11657 ;; cases the insns below which don't use an intermediate CR field will
11658 ;; be used instead.
11659 (define_insn ""
11660   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11661         (match_operator:SI 1 "scc_comparison_operator"
11662                            [(match_operand 2 "cc_reg_operand" "y")
11663                             (const_int 0)]))]
11664   ""
11665   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11666   [(set (attr "type")
11667      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11668                 (const_string "mfcrf")
11669            ]
11670         (const_string "mfcr")))
11671    (set_attr "length" "8")])
11672
11673 ;; Same as above, but get the GT bit.
11674 (define_insn "move_from_CR_gt_bit"
11675   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11676         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
11677   "TARGET_E500"
11678   "mfcr %0\;{rlinm|rlwinm} %0,%0,%D1,31,31"
11679   [(set_attr "type" "mfcr")
11680    (set_attr "length" "8")])
11681
11682 ;; Same as above, but get the OV/ORDERED bit.
11683 (define_insn "move_from_CR_ov_bit"
11684   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11685         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_OV))]
11686   "TARGET_ISEL"
11687   "mfcr %0\;{rlinm|rlwinm} %0,%0,%t1,1"
11688   [(set_attr "type" "mfcr")
11689    (set_attr "length" "8")])
11690
11691 (define_insn ""
11692   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11693         (match_operator:DI 1 "scc_comparison_operator"
11694                            [(match_operand 2 "cc_reg_operand" "y")
11695                             (const_int 0)]))]
11696   "TARGET_POWERPC64"
11697   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11698   [(set (attr "type")
11699      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11700                 (const_string "mfcrf")
11701            ]
11702         (const_string "mfcr")))
11703    (set_attr "length" "8")])
11704
11705 (define_insn ""
11706   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11707         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11708                                        [(match_operand 2 "cc_reg_operand" "y,y")
11709                                         (const_int 0)])
11710                     (const_int 0)))
11711    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11712         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11713   "TARGET_32BIT"
11714   "@
11715    mfcr %3%Q2\;{rlinm.|rlwinm.} %3,%3,%J1,1
11716    #"
11717   [(set_attr "type" "delayed_compare")
11718    (set_attr "length" "8,16")])
11719
11720 (define_split
11721   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11722         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11723                                        [(match_operand 2 "cc_reg_operand" "")
11724                                         (const_int 0)])
11725                     (const_int 0)))
11726    (set (match_operand:SI 3 "gpc_reg_operand" "")
11727         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11728   "TARGET_32BIT && reload_completed"
11729   [(set (match_dup 3)
11730         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
11731    (set (match_dup 0)
11732         (compare:CC (match_dup 3)
11733                     (const_int 0)))]
11734   "")
11735
11736 (define_insn ""
11737   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11738         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11739                                       [(match_operand 2 "cc_reg_operand" "y")
11740                                        (const_int 0)])
11741                    (match_operand:SI 3 "const_int_operand" "n")))]
11742   ""
11743   "*
11744 {
11745   int is_bit = ccr_bit (operands[1], 1);
11746   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11747   int count;
11748
11749   if (is_bit >= put_bit)
11750     count = is_bit - put_bit;
11751   else
11752     count = 32 - (put_bit - is_bit);
11753
11754   operands[4] = GEN_INT (count);
11755   operands[5] = GEN_INT (put_bit);
11756
11757   return \"mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
11758 }"
11759   [(set (attr "type")
11760      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11761                 (const_string "mfcrf")
11762            ]
11763         (const_string "mfcr")))
11764    (set_attr "length" "8")])
11765
11766 (define_insn ""
11767   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11768         (compare:CC
11769          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11770                                        [(match_operand 2 "cc_reg_operand" "y,y")
11771                                         (const_int 0)])
11772                     (match_operand:SI 3 "const_int_operand" "n,n"))
11773          (const_int 0)))
11774    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
11775         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11776                    (match_dup 3)))]
11777   ""
11778   "*
11779 {
11780   int is_bit = ccr_bit (operands[1], 1);
11781   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11782   int count;
11783
11784   /* Force split for non-cc0 compare.  */
11785   if (which_alternative == 1)
11786      return \"#\";
11787
11788   if (is_bit >= put_bit)
11789     count = is_bit - put_bit;
11790   else
11791     count = 32 - (put_bit - is_bit);
11792
11793   operands[5] = GEN_INT (count);
11794   operands[6] = GEN_INT (put_bit);
11795
11796   return \"mfcr %4%Q2\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
11797 }"
11798   [(set_attr "type" "delayed_compare")
11799    (set_attr "length" "8,16")])
11800
11801 (define_split
11802   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11803         (compare:CC
11804          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11805                                        [(match_operand 2 "cc_reg_operand" "")
11806                                         (const_int 0)])
11807                     (match_operand:SI 3 "const_int_operand" ""))
11808          (const_int 0)))
11809    (set (match_operand:SI 4 "gpc_reg_operand" "")
11810         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11811                    (match_dup 3)))]
11812   "reload_completed"
11813   [(set (match_dup 4)
11814         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11815                    (match_dup 3)))
11816    (set (match_dup 0)
11817         (compare:CC (match_dup 4)
11818                     (const_int 0)))]
11819   "")
11820
11821 ;; There is a 3 cycle delay between consecutive mfcr instructions
11822 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
11823
11824 (define_peephole
11825   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11826         (match_operator:SI 1 "scc_comparison_operator"
11827                            [(match_operand 2 "cc_reg_operand" "y")
11828                             (const_int 0)]))
11829    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
11830         (match_operator:SI 4 "scc_comparison_operator"
11831                            [(match_operand 5 "cc_reg_operand" "y")
11832                             (const_int 0)]))]
11833   "REGNO (operands[2]) != REGNO (operands[5])"
11834   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11835   [(set_attr "type" "mfcr")
11836    (set_attr "length" "12")])
11837
11838 (define_peephole
11839   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11840         (match_operator:DI 1 "scc_comparison_operator"
11841                            [(match_operand 2 "cc_reg_operand" "y")
11842                             (const_int 0)]))
11843    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
11844         (match_operator:DI 4 "scc_comparison_operator"
11845                            [(match_operand 5 "cc_reg_operand" "y")
11846                             (const_int 0)]))]
11847   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
11848   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11849   [(set_attr "type" "mfcr")
11850    (set_attr "length" "12")])
11851
11852 ;; There are some scc insns that can be done directly, without a compare.
11853 ;; These are faster because they don't involve the communications between
11854 ;; the FXU and branch units.   In fact, we will be replacing all of the
11855 ;; integer scc insns here or in the portable methods in emit_store_flag.
11856 ;;
11857 ;; Also support (neg (scc ..)) since that construct is used to replace
11858 ;; branches, (plus (scc ..) ..) since that construct is common and
11859 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
11860 ;; cases where it is no more expensive than (neg (scc ..)).
11861
11862 ;; Have reload force a constant into a register for the simple insns that
11863 ;; otherwise won't accept constants.  We do this because it is faster than
11864 ;; the cmp/mfcr sequence we would otherwise generate.
11865
11866 (define_mode_attr scc_eq_op2 [(SI "rKLI")
11867                               (DI "rKJI")])
11868
11869 (define_insn_and_split "*eq<mode>"
11870   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
11871         (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
11872                 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))]
11873   "!TARGET_POWER"
11874   "#"
11875   "!TARGET_POWER"
11876   [(set (match_dup 0)
11877         (clz:GPR (match_dup 3)))
11878    (set (match_dup 0)
11879         (lshiftrt:GPR (match_dup 0) (match_dup 4)))]
11880   {
11881     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
11882       {
11883         /* Use output operand as intermediate.  */
11884         operands[3] = operands[0];
11885
11886         if (logical_operand (operands[2], <MODE>mode))
11887           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
11888                                   gen_rtx_XOR (<MODE>mode,
11889                                                operands[1], operands[2])));
11890         else
11891           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
11892                                   gen_rtx_PLUS (<MODE>mode, operands[1],
11893                                                 negate_rtx (<MODE>mode,
11894                                                             operands[2]))));
11895       }
11896     else
11897       operands[3] = operands[1];
11898
11899     operands[4] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
11900   })
11901
11902 (define_insn_and_split "*eq<mode>_compare"
11903   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
11904         (compare:CC
11905          (eq:P (match_operand:P 1 "gpc_reg_operand" "=r")
11906                (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))
11907          (const_int 0)))
11908    (set (match_operand:P 0 "gpc_reg_operand" "=r")
11909         (eq:P (match_dup 1) (match_dup 2)))]
11910   "!TARGET_POWER && optimize_size"
11911   "#"
11912   "!TARGET_POWER && optimize_size"
11913   [(set (match_dup 0)
11914         (clz:P (match_dup 4)))
11915    (parallel [(set (match_dup 3)
11916                    (compare:CC (lshiftrt:P (match_dup 0) (match_dup 5))
11917                                (const_int 0)))
11918               (set (match_dup 0)
11919                    (lshiftrt:P (match_dup 0) (match_dup 5)))])]
11920   {
11921     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
11922       {
11923         /* Use output operand as intermediate.  */
11924         operands[4] = operands[0];
11925
11926         if (logical_operand (operands[2], <MODE>mode))
11927           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
11928                                   gen_rtx_XOR (<MODE>mode,
11929                                                operands[1], operands[2])));
11930         else
11931           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
11932                                   gen_rtx_PLUS (<MODE>mode, operands[1],
11933                                                 negate_rtx (<MODE>mode,
11934                                                             operands[2]))));
11935       }
11936     else
11937       operands[4] = operands[1];
11938
11939     operands[5] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
11940   })
11941
11942 (define_insn "*eqsi_power"
11943   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
11944         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11945                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I")))
11946    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
11947   "TARGET_POWER"
11948   "@
11949    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11950    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
11951    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11952    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11953    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
11954   [(set_attr "type" "three,two,three,three,three")
11955    (set_attr "length" "12,8,12,12,12")])
11956
11957 ;; We have insns of the form shown by the first define_insn below.  If
11958 ;; there is something inside the comparison operation, we must split it.
11959 (define_split
11960   [(set (match_operand:SI 0 "gpc_reg_operand" "")
11961         (plus:SI (match_operator 1 "comparison_operator"
11962                                  [(match_operand:SI 2 "" "")
11963                                   (match_operand:SI 3
11964                                                     "reg_or_cint_operand" "")])
11965                  (match_operand:SI 4 "gpc_reg_operand" "")))
11966    (clobber (match_operand:SI 5 "register_operand" ""))]
11967   "! gpc_reg_operand (operands[2], SImode)"
11968   [(set (match_dup 5) (match_dup 2))
11969    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
11970                                (match_dup 4)))])
11971
11972 (define_insn "*plus_eqsi"
11973   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
11974         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11975                         (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I"))
11976                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
11977   "TARGET_32BIT"
11978   "@
11979    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11980    {sfi|subfic} %0,%1,0\;{aze|addze} %0,%3
11981    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11982    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11983    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
11984   [(set_attr "type" "three,two,three,three,three")
11985    (set_attr "length" "12,8,12,12,12")])
11986
11987 (define_insn "*compare_plus_eqsi"
11988   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11989         (compare:CC
11990          (plus:SI
11991           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11992                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
11993           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11994          (const_int 0)))
11995    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
11996   "TARGET_32BIT && optimize_size"
11997   "@
11998    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11999    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
12000    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12001    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12002    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12003    #
12004    #
12005    #
12006    #
12007    #"
12008   [(set_attr "type" "compare")
12009    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
12010
12011 (define_split
12012   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12013         (compare:CC
12014          (plus:SI
12015           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
12016                  (match_operand:SI 2 "scc_eq_operand" ""))
12017           (match_operand:SI 3 "gpc_reg_operand" ""))
12018          (const_int 0)))
12019    (clobber (match_scratch:SI 4 ""))]
12020   "TARGET_32BIT && optimize_size && reload_completed"
12021   [(set (match_dup 4)
12022         (plus:SI (eq:SI (match_dup 1)
12023                  (match_dup 2))
12024           (match_dup 3)))
12025    (set (match_dup 0)
12026         (compare:CC (match_dup 4)
12027                     (const_int 0)))]
12028   "")
12029
12030 (define_insn "*plus_eqsi_compare"
12031   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
12032         (compare:CC
12033          (plus:SI
12034           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
12035                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
12036           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
12037          (const_int 0)))
12038    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
12039         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12040   "TARGET_32BIT && optimize_size"
12041   "@
12042    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12043    {sfi|subfic} %0,%1,0\;{aze.|addze.} %0,%3
12044    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12045    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12046    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12047    #
12048    #
12049    #
12050    #
12051    #"
12052   [(set_attr "type" "compare")
12053    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
12054
12055 (define_split
12056   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12057         (compare:CC
12058          (plus:SI
12059           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
12060                  (match_operand:SI 2 "scc_eq_operand" ""))
12061           (match_operand:SI 3 "gpc_reg_operand" ""))
12062          (const_int 0)))
12063    (set (match_operand:SI 0 "gpc_reg_operand" "")
12064         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12065   "TARGET_32BIT && optimize_size && reload_completed"
12066   [(set (match_dup 0)
12067         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12068    (set (match_dup 4)
12069         (compare:CC (match_dup 0)
12070                     (const_int 0)))]
12071   "")
12072
12073 (define_insn "*neg_eq0<mode>"
12074   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12075         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "r")
12076                      (const_int 0))))]
12077   ""
12078   "{ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0"
12079   [(set_attr "type" "two")
12080    (set_attr "length" "8")])
12081
12082 (define_insn_and_split "*neg_eq<mode>"
12083   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12084         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "%r")
12085                      (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))]
12086   ""
12087   "#"
12088   ""
12089   [(set (match_dup 0) (neg:P (eq:P (match_dup 3) (const_int 0))))]
12090   {
12091     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
12092       {
12093         /* Use output operand as intermediate.  */
12094         operands[3] = operands[0];
12095
12096         if (logical_operand (operands[2], <MODE>mode))
12097           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
12098                                   gen_rtx_XOR (<MODE>mode,
12099                                                operands[1], operands[2])));
12100         else
12101           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
12102                                   gen_rtx_PLUS (<MODE>mode, operands[1],
12103                                                 negate_rtx (<MODE>mode,
12104                                                             operands[2]))));
12105       }
12106     else
12107       operands[3] = operands[1];
12108   })
12109
12110 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
12111 ;; since it nabs/sr is just as fast.
12112 (define_insn "*ne0si"
12113   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12114         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
12115                      (const_int 31)))
12116    (clobber (match_scratch:SI 2 "=&r"))]
12117   "! TARGET_POWER && TARGET_32BIT && !TARGET_ISEL"
12118   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
12119   [(set_attr "type" "two")
12120    (set_attr "length" "8")])
12121
12122 (define_insn "*ne0di"
12123   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12124         (lshiftrt:DI (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
12125                      (const_int 63)))
12126    (clobber (match_scratch:DI 2 "=&r"))]
12127   "TARGET_64BIT"
12128   "addic %2,%1,-1\;subfe %0,%2,%1"
12129   [(set_attr "type" "two")
12130    (set_attr "length" "8")])
12131
12132 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
12133 (define_insn "*plus_ne0si"
12134   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12135         (plus:SI (lshiftrt:SI
12136                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
12137                   (const_int 31))
12138                  (match_operand:SI 2 "gpc_reg_operand" "r")))
12139    (clobber (match_scratch:SI 3 "=&r"))]
12140   "TARGET_32BIT"
12141   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
12142   [(set_attr "type" "two")
12143    (set_attr "length" "8")])
12144
12145 (define_insn "*plus_ne0di"
12146   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12147         (plus:DI (lshiftrt:DI
12148                   (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
12149                   (const_int 63))
12150                  (match_operand:DI 2 "gpc_reg_operand" "r")))
12151    (clobber (match_scratch:DI 3 "=&r"))]
12152   "TARGET_64BIT"
12153   "addic %3,%1,-1\;addze %0,%2"
12154   [(set_attr "type" "two")
12155    (set_attr "length" "8")])
12156
12157 (define_insn "*compare_plus_ne0si"
12158   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12159         (compare:CC
12160          (plus:SI (lshiftrt:SI
12161                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
12162                    (const_int 31))
12163                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
12164          (const_int 0)))
12165    (clobber (match_scratch:SI 3 "=&r,&r"))
12166    (clobber (match_scratch:SI 4 "=X,&r"))]
12167   "TARGET_32BIT"
12168   "@
12169    {ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2
12170    #"
12171   [(set_attr "type" "compare")
12172    (set_attr "length" "8,12")])
12173
12174 (define_split
12175   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12176         (compare:CC
12177          (plus:SI (lshiftrt:SI
12178                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
12179                    (const_int 31))
12180                   (match_operand:SI 2 "gpc_reg_operand" ""))
12181          (const_int 0)))
12182    (clobber (match_scratch:SI 3 ""))
12183    (clobber (match_scratch:SI 4 ""))]
12184   "TARGET_32BIT && reload_completed"
12185   [(parallel [(set (match_dup 3)
12186                    (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1)))
12187                                          (const_int 31))
12188                             (match_dup 2)))
12189               (clobber (match_dup 4))])
12190    (set (match_dup 0)
12191         (compare:CC (match_dup 3)
12192                     (const_int 0)))]
12193   "")
12194
12195 (define_insn "*compare_plus_ne0di"
12196   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12197         (compare:CC
12198          (plus:DI (lshiftrt:DI
12199                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
12200                    (const_int 63))
12201                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
12202          (const_int 0)))
12203    (clobber (match_scratch:DI 3 "=&r,&r"))]
12204   "TARGET_64BIT"
12205   "@
12206    addic %3,%1,-1\;addze. %3,%2
12207    #"
12208   [(set_attr "type" "compare")
12209    (set_attr "length" "8,12")])
12210
12211 (define_split
12212   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12213         (compare:CC
12214          (plus:DI (lshiftrt:DI
12215                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
12216                    (const_int 63))
12217                   (match_operand:DI 2 "gpc_reg_operand" ""))
12218          (const_int 0)))
12219    (clobber (match_scratch:DI 3 ""))]
12220   "TARGET_64BIT && reload_completed"
12221   [(set (match_dup 3)
12222         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1)))
12223                    (const_int 63))
12224                   (match_dup 2)))
12225    (set (match_dup 0)
12226         (compare:CC (match_dup 3)
12227                     (const_int 0)))]
12228   "")
12229
12230 (define_insn "*plus_ne0si_compare"
12231   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12232         (compare:CC
12233          (plus:SI (lshiftrt:SI
12234                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
12235                    (const_int 31))
12236                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
12237          (const_int 0)))
12238    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12239         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
12240                  (match_dup 2)))
12241    (clobber (match_scratch:SI 3 "=&r,&r"))]
12242   "TARGET_32BIT"
12243   "@
12244    {ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2
12245    #"
12246   [(set_attr "type" "compare")
12247    (set_attr "length" "8,12")])
12248
12249 (define_split
12250   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12251         (compare:CC
12252          (plus:SI (lshiftrt:SI
12253                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
12254                    (const_int 31))
12255                   (match_operand:SI 2 "gpc_reg_operand" ""))
12256          (const_int 0)))
12257    (set (match_operand:SI 0 "gpc_reg_operand" "")
12258         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
12259                  (match_dup 2)))
12260    (clobber (match_scratch:SI 3 ""))]
12261   "TARGET_32BIT && reload_completed"
12262   [(parallel [(set (match_dup 0)
12263         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
12264                  (match_dup 2)))
12265    (clobber (match_dup 3))])
12266    (set (match_dup 4)
12267         (compare:CC (match_dup 0)
12268                     (const_int 0)))]
12269   "")
12270
12271 (define_insn "*plus_ne0di_compare"
12272   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12273         (compare:CC
12274          (plus:DI (lshiftrt:DI
12275                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
12276                    (const_int 63))
12277                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
12278          (const_int 0)))
12279    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12280         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
12281                  (match_dup 2)))
12282    (clobber (match_scratch:DI 3 "=&r,&r"))]
12283   "TARGET_64BIT"
12284   "@
12285    addic %3,%1,-1\;addze. %0,%2
12286    #"
12287   [(set_attr "type" "compare")
12288    (set_attr "length" "8,12")])
12289
12290 (define_split
12291   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12292         (compare:CC
12293          (plus:DI (lshiftrt:DI
12294                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
12295                    (const_int 63))
12296                   (match_operand:DI 2 "gpc_reg_operand" ""))
12297          (const_int 0)))
12298    (set (match_operand:DI 0 "gpc_reg_operand" "")
12299         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
12300                  (match_dup 2)))
12301    (clobber (match_scratch:DI 3 ""))]
12302   "TARGET_64BIT && reload_completed"
12303   [(parallel [(set (match_dup 0)
12304         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
12305                  (match_dup 2)))
12306    (clobber (match_dup 3))])
12307    (set (match_dup 4)
12308         (compare:CC (match_dup 0)
12309                     (const_int 0)))]
12310   "")
12311
12312 (define_insn ""
12313   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12314         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12315                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
12316    (clobber (match_scratch:SI 3 "=r,X"))]
12317   "TARGET_POWER"
12318   "@
12319    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
12320    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
12321   [(set_attr "length" "12")])
12322
12323 (define_insn ""
12324   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12325         (compare:CC
12326          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12327                 (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12328          (const_int 0)))
12329    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12330         (le:SI (match_dup 1) (match_dup 2)))
12331    (clobber (match_scratch:SI 3 "=r,X,r,X"))]
12332   "TARGET_POWER"
12333   "@
12334    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
12335    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31
12336    #
12337    #"
12338   [(set_attr "type" "compare,delayed_compare,compare,delayed_compare")
12339    (set_attr "length" "12,12,16,16")])
12340
12341 (define_split
12342   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12343         (compare:CC
12344          (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12345                 (match_operand:SI 2 "reg_or_short_operand" ""))
12346          (const_int 0)))
12347    (set (match_operand:SI 0 "gpc_reg_operand" "")
12348         (le:SI (match_dup 1) (match_dup 2)))
12349    (clobber (match_scratch:SI 3 ""))]
12350   "TARGET_POWER && reload_completed"
12351   [(parallel [(set (match_dup 0)
12352         (le:SI (match_dup 1) (match_dup 2)))
12353    (clobber (match_dup 3))])
12354    (set (match_dup 4)
12355         (compare:CC (match_dup 0)
12356                     (const_int 0)))]
12357   "")
12358
12359 (define_insn ""
12360   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12361         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12362                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
12363                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12364   "TARGET_POWER"
12365   "@
12366    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
12367    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze|addze} %0,%3"
12368   [(set_attr "length" "12")])
12369
12370 (define_insn ""
12371   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12372         (compare:CC
12373          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12374                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12375                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12376          (const_int 0)))
12377    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12378   "TARGET_POWER"
12379   "@
12380    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12381    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3
12382    #
12383    #"
12384   [(set_attr "type" "compare")
12385    (set_attr "length" "12,12,16,16")])
12386
12387 (define_split
12388   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12389         (compare:CC
12390          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12391                          (match_operand:SI 2 "reg_or_short_operand" ""))
12392                   (match_operand:SI 3 "gpc_reg_operand" ""))
12393          (const_int 0)))
12394    (clobber (match_scratch:SI 4 ""))]
12395   "TARGET_POWER && reload_completed"
12396   [(set (match_dup 4)
12397         (plus:SI (le:SI (match_dup 1) (match_dup 2))
12398                  (match_dup 3)))
12399    (set (match_dup 0)
12400         (compare:CC (match_dup 4)
12401                     (const_int 0)))]
12402   "")
12403
12404 (define_insn ""
12405   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12406         (compare:CC
12407          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12408                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12409                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12410          (const_int 0)))
12411    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12412         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12413   "TARGET_POWER"
12414   "@
12415    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12416    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze.|addze.} %0,%3
12417    #
12418    #"
12419   [(set_attr "type" "compare")
12420    (set_attr "length" "12,12,16,16")])
12421
12422 (define_split
12423   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12424         (compare:CC
12425          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12426                          (match_operand:SI 2 "reg_or_short_operand" ""))
12427                   (match_operand:SI 3 "gpc_reg_operand" ""))
12428          (const_int 0)))
12429    (set (match_operand:SI 0 "gpc_reg_operand" "")
12430         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12431   "TARGET_POWER && reload_completed"
12432   [(set (match_dup 0)
12433         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12434    (set (match_dup 4)
12435         (compare:CC (match_dup 0)
12436                     (const_int 0)))]
12437   "")
12438
12439 (define_insn ""
12440   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12441         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12442                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
12443   "TARGET_POWER"
12444   "@
12445    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
12446    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
12447   [(set_attr "length" "12")])
12448
12449 (define_insn "*leu<mode>"
12450   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12451         (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12452                (match_operand:P 2 "reg_or_short_operand" "rI")))]
12453   ""
12454   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12455   [(set_attr "type" "three")
12456    (set_attr "length" "12")])
12457
12458 (define_insn "*leu<mode>_compare"
12459   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12460         (compare:CC
12461          (leu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12462                 (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
12463          (const_int 0)))
12464    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12465         (leu:P (match_dup 1) (match_dup 2)))]
12466   ""
12467   "@
12468    {sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12469    #"
12470   [(set_attr "type" "compare")
12471    (set_attr "length" "12,16")])
12472
12473 (define_split
12474   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12475         (compare:CC
12476          (leu:P (match_operand:P 1 "gpc_reg_operand" "")
12477                 (match_operand:P 2 "reg_or_short_operand" ""))
12478          (const_int 0)))
12479    (set (match_operand:P 0 "gpc_reg_operand" "")
12480         (leu:P (match_dup 1) (match_dup 2)))]
12481   "reload_completed"
12482   [(set (match_dup 0)
12483         (leu:P (match_dup 1) (match_dup 2)))
12484    (set (match_dup 3)
12485         (compare:CC (match_dup 0)
12486                     (const_int 0)))]
12487   "")
12488
12489 (define_insn "*plus_leu<mode>"
12490   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
12491         (plus:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12492                        (match_operand:P 2 "reg_or_short_operand" "rI"))
12493                 (match_operand:P 3 "gpc_reg_operand" "r")))]
12494   ""
12495   "{sf%I2|subf%I2c} %0,%1,%2\;{aze|addze} %0,%3"
12496   [(set_attr "type" "two")
12497    (set_attr "length" "8")])
12498
12499 (define_insn ""
12500   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12501         (compare:CC
12502          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12503                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12504                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12505          (const_int 0)))
12506    (clobber (match_scratch:SI 4 "=&r,&r"))]
12507   "TARGET_32BIT"
12508   "@
12509    {sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3
12510    #"
12511   [(set_attr "type" "compare")
12512    (set_attr "length" "8,12")])
12513
12514 (define_split
12515   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12516         (compare:CC
12517          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12518                           (match_operand:SI 2 "reg_or_short_operand" ""))
12519                   (match_operand:SI 3 "gpc_reg_operand" ""))
12520          (const_int 0)))
12521    (clobber (match_scratch:SI 4 ""))]
12522   "TARGET_32BIT && reload_completed"
12523   [(set (match_dup 4)
12524         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
12525                   (match_dup 3)))
12526    (set (match_dup 0)
12527         (compare:CC (match_dup 4)
12528                     (const_int 0)))]
12529   "")
12530
12531 (define_insn ""
12532   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12533         (compare:CC
12534          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12535                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12536                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12537          (const_int 0)))
12538    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12539         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12540   "TARGET_32BIT"
12541   "@
12542    {sf%I2|subf%I2c} %0,%1,%2\;{aze.|addze.} %0,%3
12543    #"
12544   [(set_attr "type" "compare")
12545    (set_attr "length" "8,12")])
12546
12547 (define_split
12548   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12549         (compare:CC
12550          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12551                           (match_operand:SI 2 "reg_or_short_operand" ""))
12552                   (match_operand:SI 3 "gpc_reg_operand" ""))
12553          (const_int 0)))
12554    (set (match_operand:SI 0 "gpc_reg_operand" "")
12555         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12556   "TARGET_32BIT && reload_completed"
12557   [(set (match_dup 0)
12558         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12559    (set (match_dup 4)
12560         (compare:CC (match_dup 0)
12561                     (const_int 0)))]
12562   "")
12563
12564 (define_insn "*neg_leu<mode>"
12565   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12566         (neg:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12567                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
12568   ""
12569   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
12570    [(set_attr "type" "three")
12571     (set_attr "length" "12")])
12572
12573 (define_insn "*and_neg_leu<mode>"
12574   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
12575         (and:P (neg:P
12576                  (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12577                         (match_operand:P 2 "reg_or_short_operand" "rI")))
12578                 (match_operand:P 3 "gpc_reg_operand" "r")))]
12579   ""
12580   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12581   [(set_attr "type" "three")
12582    (set_attr "length" "12")])
12583
12584 (define_insn ""
12585   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12586         (compare:CC
12587          (and:SI (neg:SI
12588                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12589                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12590                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12591          (const_int 0)))
12592    (clobber (match_scratch:SI 4 "=&r,&r"))]
12593   "TARGET_32BIT"
12594   "@
12595    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12596    #"
12597   [(set_attr "type" "compare")
12598    (set_attr "length" "12,16")])
12599
12600 (define_split
12601   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12602         (compare:CC
12603          (and:SI (neg:SI
12604                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12605                           (match_operand:SI 2 "reg_or_short_operand" "")))
12606                  (match_operand:SI 3 "gpc_reg_operand" ""))
12607          (const_int 0)))
12608    (clobber (match_scratch:SI 4 ""))]
12609   "TARGET_32BIT && reload_completed"
12610   [(set (match_dup 4)
12611         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12612                 (match_dup 3)))
12613    (set (match_dup 0)
12614         (compare:CC (match_dup 4)
12615                     (const_int 0)))]
12616   "")
12617
12618 (define_insn ""
12619   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12620         (compare:CC
12621          (and:SI (neg:SI
12622                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12623                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12624                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12625          (const_int 0)))
12626    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12627         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12628   "TARGET_32BIT"
12629   "@
12630    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12631    #"
12632   [(set_attr "type" "compare")
12633    (set_attr "length" "12,16")])
12634
12635 (define_split
12636   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12637         (compare:CC
12638          (and:SI (neg:SI
12639                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12640                           (match_operand:SI 2 "reg_or_short_operand" "")))
12641                  (match_operand:SI 3 "gpc_reg_operand" ""))
12642          (const_int 0)))
12643    (set (match_operand:SI 0 "gpc_reg_operand" "")
12644         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12645   "TARGET_32BIT && reload_completed"
12646   [(set (match_dup 0)
12647         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12648                 (match_dup 3)))
12649    (set (match_dup 4)
12650         (compare:CC (match_dup 0)
12651                     (const_int 0)))]
12652   "")
12653
12654 (define_insn ""
12655   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12656         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12657                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12658   "TARGET_POWER"
12659   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
12660    [(set_attr "length" "12")])
12661
12662 (define_insn ""
12663   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12664         (compare:CC
12665          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12666                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12667          (const_int 0)))
12668    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12669         (lt:SI (match_dup 1) (match_dup 2)))]
12670   "TARGET_POWER"
12671   "@
12672    doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
12673    #"
12674   [(set_attr "type" "delayed_compare")
12675    (set_attr "length" "12,16")])
12676
12677 (define_split
12678   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12679         (compare:CC
12680          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12681                 (match_operand:SI 2 "reg_or_short_operand" ""))
12682          (const_int 0)))
12683    (set (match_operand:SI 0 "gpc_reg_operand" "")
12684         (lt:SI (match_dup 1) (match_dup 2)))]
12685   "TARGET_POWER && reload_completed"
12686   [(set (match_dup 0)
12687         (lt:SI (match_dup 1) (match_dup 2)))
12688    (set (match_dup 3)
12689         (compare:CC (match_dup 0)
12690                     (const_int 0)))]
12691   "")
12692
12693 (define_insn ""
12694   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12695         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12696                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12697                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12698   "TARGET_POWER"
12699   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
12700   [(set_attr "length" "12")])
12701
12702 (define_insn ""
12703   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12704         (compare:CC
12705          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12706                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12707                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12708          (const_int 0)))
12709    (clobber (match_scratch:SI 4 "=&r,&r"))]
12710   "TARGET_POWER"
12711   "@
12712    doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
12713    #"
12714   [(set_attr "type" "compare")
12715    (set_attr "length" "12,16")])
12716
12717 (define_split
12718   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12719         (compare:CC
12720          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12721                          (match_operand:SI 2 "reg_or_short_operand" ""))
12722                   (match_operand:SI 3 "gpc_reg_operand" ""))
12723          (const_int 0)))
12724    (clobber (match_scratch:SI 4 ""))]
12725   "TARGET_POWER && reload_completed"
12726   [(set (match_dup 4)
12727         (plus:SI (lt:SI (match_dup 1) (match_dup 2))
12728                  (match_dup 3)))
12729    (set (match_dup 0)
12730         (compare:CC (match_dup 4)
12731                     (const_int 0)))]
12732   "")
12733
12734 (define_insn ""
12735   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12736         (compare:CC
12737          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12738                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12739                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12740          (const_int 0)))
12741    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12742         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12743   "TARGET_POWER"
12744   "@
12745    doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
12746    #"
12747   [(set_attr "type" "compare")
12748    (set_attr "length" "12,16")])
12749
12750 (define_split
12751   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12752         (compare:CC
12753          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12754                          (match_operand:SI 2 "reg_or_short_operand" ""))
12755                   (match_operand:SI 3 "gpc_reg_operand" ""))
12756          (const_int 0)))
12757    (set (match_operand:SI 0 "gpc_reg_operand" "")
12758         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12759   "TARGET_POWER && reload_completed"
12760   [(set (match_dup 0)
12761         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12762    (set (match_dup 4)
12763         (compare:CC (match_dup 0)
12764                     (const_int 0)))]
12765   "")
12766
12767 (define_insn ""
12768   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12769         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12770                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12771   "TARGET_POWER"
12772   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
12773   [(set_attr "length" "12")])
12774
12775 (define_insn_and_split "*ltu<mode>"
12776   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12777         (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12778                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
12779   ""
12780   "#"
12781   ""
12782   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
12783    (set (match_dup 0) (neg:P (match_dup 0)))]
12784   "")
12785
12786 (define_insn_and_split "*ltu<mode>_compare"
12787   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12788         (compare:CC
12789          (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
12790                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
12791          (const_int 0)))
12792    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
12793         (ltu:P (match_dup 1) (match_dup 2)))]
12794   ""
12795   "#"
12796   ""
12797   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
12798    (parallel [(set (match_dup 3)
12799                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
12800               (set (match_dup 0) (neg:P (match_dup 0)))])]
12801   "")
12802
12803 (define_insn_and_split "*plus_ltu<mode>"
12804   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,r")
12805         (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12806                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
12807                 (match_operand:P 3 "reg_or_short_operand" "rI,rI")))]
12808   ""
12809   "#"
12810   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
12811   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
12812    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
12813   "")
12814
12815 (define_insn_and_split "*plus_ltu<mode>_compare"
12816   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12817         (compare:CC
12818          (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
12819                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
12820                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
12821          (const_int 0)))
12822    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12823         (plus:P (ltu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
12824   ""
12825   "#"
12826   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
12827   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
12828    (parallel [(set (match_dup 4)
12829                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
12830                                (const_int 0)))
12831               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
12832   "")
12833
12834 (define_insn "*neg_ltu<mode>"
12835   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12836         (neg:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12837                       (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))))]
12838   ""
12839   "@
12840    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
12841    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
12842   [(set_attr "type" "two")
12843    (set_attr "length" "8")])
12844
12845 (define_insn ""
12846   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12847         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12848                (match_operand:SI 2 "reg_or_short_operand" "rI")))
12849    (clobber (match_scratch:SI 3 "=r"))]
12850   "TARGET_POWER"
12851   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
12852    [(set_attr "length" "12")])
12853
12854 (define_insn ""
12855   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12856         (compare:CC
12857          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12858                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12859          (const_int 0)))
12860    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12861         (ge:SI (match_dup 1) (match_dup 2)))
12862    (clobber (match_scratch:SI 3 "=r,r"))]
12863   "TARGET_POWER"
12864   "@
12865    doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
12866    #"
12867   [(set_attr "type" "compare")
12868    (set_attr "length" "12,16")])
12869
12870 (define_split
12871   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12872         (compare:CC
12873          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12874                 (match_operand:SI 2 "reg_or_short_operand" ""))
12875          (const_int 0)))
12876    (set (match_operand:SI 0 "gpc_reg_operand" "")
12877         (ge:SI (match_dup 1) (match_dup 2)))
12878    (clobber (match_scratch:SI 3 ""))]
12879   "TARGET_POWER && reload_completed"
12880   [(parallel [(set (match_dup 0)
12881                    (ge:SI (match_dup 1) (match_dup 2)))
12882               (clobber (match_dup 3))])
12883    (set (match_dup 4)
12884         (compare:CC (match_dup 0)
12885                     (const_int 0)))]
12886   "")
12887
12888 (define_insn ""
12889   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12890         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12891                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12892                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12893   "TARGET_POWER"
12894   "doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
12895   [(set_attr "length" "12")])
12896
12897 (define_insn ""
12898   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12899         (compare:CC
12900          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12901                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12902                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12903          (const_int 0)))
12904    (clobber (match_scratch:SI 4 "=&r,&r"))]
12905   "TARGET_POWER"
12906   "@
12907    doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12908    #"
12909   [(set_attr "type" "compare")
12910    (set_attr "length" "12,16")])
12911
12912 (define_split
12913   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12914         (compare:CC
12915          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12916                          (match_operand:SI 2 "reg_or_short_operand" ""))
12917                   (match_operand:SI 3 "gpc_reg_operand" ""))
12918          (const_int 0)))
12919    (clobber (match_scratch:SI 4 ""))]
12920   "TARGET_POWER && reload_completed"
12921   [(set (match_dup 4)
12922         (plus:SI (ge:SI (match_dup 1) (match_dup 2))
12923                  (match_dup 3)))
12924    (set (match_dup 0)
12925         (compare:CC (match_dup 4)
12926                     (const_int 0)))]
12927   "")
12928
12929 (define_insn ""
12930   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12931         (compare:CC
12932          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12933                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12934                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12935          (const_int 0)))
12936    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12937         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12938   "TARGET_POWER"
12939   "@
12940    doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12941    #"
12942   [(set_attr "type" "compare")
12943    (set_attr "length" "12,16")])
12944
12945 (define_split
12946   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12947         (compare:CC
12948          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12949                          (match_operand:SI 2 "reg_or_short_operand" ""))
12950                   (match_operand:SI 3 "gpc_reg_operand" ""))
12951          (const_int 0)))
12952    (set (match_operand:SI 0 "gpc_reg_operand" "")
12953         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12954   "TARGET_POWER && reload_completed"
12955   [(set (match_dup 0)
12956         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12957    (set (match_dup 4)
12958         (compare:CC (match_dup 0)
12959                     (const_int 0)))]
12960   "")
12961
12962 (define_insn ""
12963   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12964         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12965                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12966   "TARGET_POWER"
12967   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
12968   [(set_attr "length" "12")])
12969
12970 (define_insn "*geu<mode>"
12971   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12972         (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12973                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
12974   ""
12975   "@
12976    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
12977    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12978   [(set_attr "type" "three")
12979    (set_attr "length" "12")])
12980
12981 (define_insn "*geu<mode>_compare"
12982   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12983         (compare:CC
12984          (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
12985                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
12986          (const_int 0)))
12987    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
12988         (geu:P (match_dup 1) (match_dup 2)))]
12989   ""
12990   "@
12991    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12992    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12993    #
12994    #"
12995   [(set_attr "type" "compare")
12996    (set_attr "length" "12,12,16,16")])
12997
12998 (define_split
12999   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13000         (compare:CC
13001          (geu:P (match_operand:P 1 "gpc_reg_operand" "")
13002                 (match_operand:P 2 "reg_or_neg_short_operand" ""))
13003          (const_int 0)))
13004    (set (match_operand:P 0 "gpc_reg_operand" "")
13005         (geu:P (match_dup 1) (match_dup 2)))]
13006   "reload_completed"
13007   [(set (match_dup 0)
13008         (geu:P (match_dup 1) (match_dup 2)))
13009    (set (match_dup 3)
13010         (compare:CC (match_dup 0)
13011                     (const_int 0)))]
13012   "")
13013
13014 (define_insn "*plus_geu<mode>"
13015   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
13016         (plus:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13017                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
13018                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
13019   ""
13020   "@
13021    {sf|subfc} %0,%2,%1\;{aze|addze} %0,%3
13022    {ai|addic} %0,%1,%n2\;{aze|addze} %0,%3"
13023   [(set_attr "type" "two")
13024    (set_attr "length" "8")])
13025
13026 (define_insn ""
13027   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13028         (compare:CC
13029          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13030                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
13031                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13032          (const_int 0)))
13033    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13034   "TARGET_32BIT"
13035   "@
13036    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
13037    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3
13038    #
13039    #"
13040   [(set_attr "type" "compare")
13041    (set_attr "length" "8,8,12,12")])
13042
13043 (define_split
13044   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13045         (compare:CC
13046          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13047                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
13048                   (match_operand:SI 3 "gpc_reg_operand" ""))
13049          (const_int 0)))
13050    (clobber (match_scratch:SI 4 ""))]
13051   "TARGET_32BIT && reload_completed"
13052   [(set (match_dup 4)
13053         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
13054                   (match_dup 3)))
13055    (set (match_dup 0)
13056         (compare:CC (match_dup 4)
13057                     (const_int 0)))]
13058   "")
13059
13060 (define_insn ""
13061   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13062         (compare:CC
13063          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13064                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
13065                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13066          (const_int 0)))
13067    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13068         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13069   "TARGET_32BIT"
13070   "@
13071    {sf|subfc} %0,%2,%1\;{aze.|addze.} %0,%3
13072    {ai|addic} %0,%1,%n2\;{aze.|addze.} %0,%3
13073    #
13074    #"
13075   [(set_attr "type" "compare")
13076    (set_attr "length" "8,8,12,12")])
13077
13078 (define_split
13079   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13080         (compare:CC
13081          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13082                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
13083                   (match_operand:SI 3 "gpc_reg_operand" ""))
13084          (const_int 0)))
13085    (set (match_operand:SI 0 "gpc_reg_operand" "")
13086         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13087   "TARGET_32BIT && reload_completed"
13088   [(set (match_dup 0)
13089         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13090    (set (match_dup 4)
13091         (compare:CC (match_dup 0)
13092                     (const_int 0)))]
13093   "")
13094
13095 (define_insn "*neg_geu<mode>"
13096   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13097         (neg:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13098                       (match_operand:P 2 "reg_or_short_operand" "r,I"))))]
13099   ""
13100   "@
13101    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
13102    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
13103   [(set_attr "type" "three")
13104    (set_attr "length" "12")])
13105
13106 (define_insn "*and_neg_geu<mode>"
13107   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
13108         (and:P (neg:P
13109                  (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13110                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))
13111                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
13112   ""
13113   "@
13114    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0
13115    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
13116   [(set_attr "type" "three")
13117    (set_attr "length" "12")])
13118
13119 (define_insn ""
13120   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13121         (compare:CC
13122          (and:SI (neg:SI
13123                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13124                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
13125                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13126          (const_int 0)))
13127    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13128   "TARGET_32BIT"
13129   "@
13130    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
13131    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
13132    #
13133    #"
13134   [(set_attr "type" "compare")
13135    (set_attr "length" "12,12,16,16")])
13136
13137 (define_split
13138   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13139         (compare:CC
13140          (and:SI (neg:SI
13141                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13142                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
13143                  (match_operand:SI 3 "gpc_reg_operand" ""))
13144          (const_int 0)))
13145    (clobber (match_scratch:SI 4 ""))]
13146   "TARGET_32BIT && reload_completed"
13147   [(set (match_dup 4)
13148         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
13149                 (match_dup 3)))
13150    (set (match_dup 0)
13151         (compare:CC (match_dup 4)
13152                     (const_int 0)))]
13153   "")
13154
13155 (define_insn ""
13156   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13157         (compare:CC
13158          (and:SI (neg:SI
13159                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13160                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
13161                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13162          (const_int 0)))
13163    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13164         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13165   "TARGET_32BIT"
13166   "@
13167    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
13168    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
13169    #
13170    #"
13171   [(set_attr "type" "compare")
13172    (set_attr "length" "12,12,16,16")])
13173
13174 (define_split
13175   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13176         (compare:CC
13177          (and:SI (neg:SI
13178                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13179                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
13180                  (match_operand:SI 3 "gpc_reg_operand" ""))
13181          (const_int 0)))
13182    (set (match_operand:SI 0 "gpc_reg_operand" "")
13183         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13184   "TARGET_32BIT && reload_completed"
13185   [(set (match_dup 0)
13186         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
13187    (set (match_dup 4)
13188         (compare:CC (match_dup 0)
13189                     (const_int 0)))]
13190   "")
13191
13192 (define_insn ""
13193   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13194         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13195                (match_operand:SI 2 "reg_or_short_operand" "r")))]
13196   "TARGET_POWER"
13197   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
13198   [(set_attr "length" "12")])
13199
13200 (define_insn ""
13201   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13202         (compare:CC
13203          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13204                 (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13205          (const_int 0)))
13206    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13207         (gt:SI (match_dup 1) (match_dup 2)))]
13208   "TARGET_POWER"
13209   "@
13210    doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
13211    #"
13212   [(set_attr "type" "delayed_compare")
13213    (set_attr "length" "12,16")])
13214
13215 (define_split
13216   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13217         (compare:CC
13218          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13219                 (match_operand:SI 2 "reg_or_short_operand" ""))
13220          (const_int 0)))
13221    (set (match_operand:SI 0 "gpc_reg_operand" "")
13222         (gt:SI (match_dup 1) (match_dup 2)))]
13223   "TARGET_POWER && reload_completed"
13224   [(set (match_dup 0)
13225         (gt:SI (match_dup 1) (match_dup 2)))
13226    (set (match_dup 3)
13227         (compare:CC (match_dup 0)
13228                     (const_int 0)))]
13229   "")
13230
13231 (define_insn "*plus_gt0<mode>"
13232   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13233         (plus:P (gt:P (match_operand:P 1 "gpc_reg_operand" "r")
13234                       (const_int 0))
13235                  (match_operand:P 2 "gpc_reg_operand" "r")))]
13236   ""
13237   "{a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze|addze} %0,%2"
13238   [(set_attr "type" "three")
13239    (set_attr "length" "12")])
13240
13241 (define_insn ""
13242   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13243         (compare:CC
13244          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13245                          (const_int 0))
13246                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13247          (const_int 0)))
13248    (clobber (match_scratch:SI 3 "=&r,&r"))]
13249   "TARGET_32BIT"
13250   "@
13251    {a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2
13252    #"
13253   [(set_attr "type" "compare")
13254    (set_attr "length" "12,16")])
13255
13256 (define_split
13257   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13258         (compare:CC
13259          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13260                          (const_int 0))
13261                   (match_operand:SI 2 "gpc_reg_operand" ""))
13262          (const_int 0)))
13263    (clobber (match_scratch:SI 3 ""))]
13264   "TARGET_32BIT && reload_completed"
13265   [(set (match_dup 3)
13266         (plus:SI (gt:SI (match_dup 1) (const_int 0))
13267                   (match_dup 2)))
13268    (set (match_dup 0)
13269         (compare:CC (match_dup 3)
13270                     (const_int 0)))]
13271   "")
13272
13273 (define_insn ""
13274   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13275         (compare:CC
13276          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13277                          (const_int 0))
13278                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13279          (const_int 0)))
13280    (clobber (match_scratch:DI 3 "=&r,&r"))]
13281   "TARGET_64BIT"
13282   "@
13283    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
13284    #"
13285   [(set_attr "type" "compare")
13286    (set_attr "length" "12,16")])
13287
13288 (define_split
13289   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13290         (compare:CC
13291          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13292                          (const_int 0))
13293                   (match_operand:DI 2 "gpc_reg_operand" ""))
13294          (const_int 0)))
13295    (clobber (match_scratch:DI 3 ""))]
13296   "TARGET_64BIT && reload_completed"
13297   [(set (match_dup 3)
13298         (plus:DI (gt:DI (match_dup 1) (const_int 0))
13299                  (match_dup 2)))
13300    (set (match_dup 0)
13301         (compare:CC (match_dup 3)
13302                     (const_int 0)))]
13303   "")
13304
13305 (define_insn ""
13306   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13307         (compare:CC
13308          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13309                          (const_int 0))
13310                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13311          (const_int 0)))
13312    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13313         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13314   "TARGET_32BIT"
13315   "@
13316    {a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze.|addze.} %0,%2
13317    #"
13318   [(set_attr "type" "compare")
13319    (set_attr "length" "12,16")])
13320
13321 (define_split
13322   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13323         (compare:CC
13324          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13325                          (const_int 0))
13326                   (match_operand:SI 2 "gpc_reg_operand" ""))
13327          (const_int 0)))
13328    (set (match_operand:SI 0 "gpc_reg_operand" "")
13329         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13330   "TARGET_32BIT && reload_completed"
13331   [(set (match_dup 0)
13332         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
13333    (set (match_dup 3)
13334         (compare:CC (match_dup 0)
13335                     (const_int 0)))]
13336   "")
13337
13338 (define_insn ""
13339   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13340         (compare:CC
13341          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13342                          (const_int 0))
13343                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13344          (const_int 0)))
13345    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
13346         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13347   "TARGET_64BIT"
13348   "@
13349    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
13350    #"
13351   [(set_attr "type" "compare")
13352    (set_attr "length" "12,16")])
13353
13354 (define_split
13355   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13356         (compare:CC
13357          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13358                          (const_int 0))
13359                   (match_operand:DI 2 "gpc_reg_operand" ""))
13360          (const_int 0)))
13361    (set (match_operand:DI 0 "gpc_reg_operand" "")
13362         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13363   "TARGET_64BIT && reload_completed"
13364   [(set (match_dup 0)
13365         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
13366    (set (match_dup 3)
13367         (compare:CC (match_dup 0)
13368                     (const_int 0)))]
13369   "")
13370
13371 (define_insn ""
13372   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13373         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13374                         (match_operand:SI 2 "reg_or_short_operand" "r"))
13375                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
13376   "TARGET_POWER"
13377   "doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
13378   [(set_attr "length" "12")])
13379
13380 (define_insn ""
13381   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13382         (compare:CC
13383          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13384                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13385                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13386          (const_int 0)))
13387    (clobber (match_scratch:SI 4 "=&r,&r"))]
13388   "TARGET_POWER"
13389   "@
13390    doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
13391    #"
13392   [(set_attr "type" "compare")
13393    (set_attr "length" "12,16")])
13394
13395 (define_split
13396   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13397         (compare:CC
13398          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13399                          (match_operand:SI 2 "reg_or_short_operand" ""))
13400                   (match_operand:SI 3 "gpc_reg_operand" ""))
13401          (const_int 0)))
13402    (clobber (match_scratch:SI 4 ""))]
13403   "TARGET_POWER && reload_completed"
13404   [(set (match_dup 4)
13405         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13406    (set (match_dup 0)
13407         (compare:CC (match_dup 4)
13408                     (const_int 0)))]
13409   "")
13410
13411 (define_insn ""
13412   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13413         (compare:CC
13414          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13415                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13416                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13417          (const_int 0)))
13418    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13419         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13420   "TARGET_POWER"
13421   "@
13422    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
13423    #"
13424   [(set_attr "type" "compare")
13425    (set_attr "length" "12,16")])
13426
13427 (define_split
13428   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13429         (compare:CC
13430          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13431                          (match_operand:SI 2 "reg_or_short_operand" ""))
13432                   (match_operand:SI 3 "gpc_reg_operand" ""))
13433          (const_int 0)))
13434    (set (match_operand:SI 0 "gpc_reg_operand" "")
13435         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13436   "TARGET_POWER && reload_completed"
13437   [(set (match_dup 0)
13438         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13439    (set (match_dup 4)
13440         (compare:CC (match_dup 0)
13441                     (const_int 0)))]
13442   "")
13443
13444 (define_insn ""
13445   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13446         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13447                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
13448   "TARGET_POWER"
13449   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
13450   [(set_attr "length" "12")])
13451
13452 (define_insn_and_split "*gtu<mode>"
13453   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13454         (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
13455                (match_operand:P 2 "reg_or_short_operand" "rI")))]
13456   ""
13457   "#"
13458   ""
13459   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
13460    (set (match_dup 0) (neg:P (match_dup 0)))]
13461   "")
13462
13463 (define_insn_and_split "*gtu<mode>_compare"
13464   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13465         (compare:CC
13466          (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13467                  (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
13468          (const_int 0)))
13469    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13470         (gtu:P (match_dup 1) (match_dup 2)))]
13471   ""
13472   "#"
13473   ""
13474   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
13475    (parallel [(set (match_dup 3)
13476                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
13477               (set (match_dup 0) (neg:P (match_dup 0)))])]
13478   "")
13479
13480 (define_insn_and_split "*plus_gtu<mode>"
13481   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13482         (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
13483                        (match_operand:P 2 "reg_or_short_operand" "rI"))
13484                 (match_operand:P 3 "reg_or_short_operand" "rI")))]
13485   ""
13486   "#"
13487   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13488   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
13489    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
13490   "")
13491
13492 (define_insn_and_split "*plus_gtu<mode>_compare"
13493   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13494         (compare:CC
13495          (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13496                         (match_operand:P 2 "reg_or_short_operand" "I,r,I,r"))
13497                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
13498          (const_int 0)))
13499    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13500         (plus:P (gtu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
13501   ""
13502   "#"
13503   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13504   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
13505    (parallel [(set (match_dup 4)
13506                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
13507                                (const_int 0)))
13508               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
13509   "")
13510
13511 (define_insn "*neg_gtu<mode>"
13512   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13513         (neg:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
13514                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
13515   ""
13516   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
13517   [(set_attr "type" "two")
13518    (set_attr "length" "8")])
13519
13520 \f
13521 ;; Define both directions of branch and return.  If we need a reload
13522 ;; register, we'd rather use CR0 since it is much easier to copy a
13523 ;; register CC value to there.
13524
13525 (define_insn ""
13526   [(set (pc)
13527         (if_then_else (match_operator 1 "branch_comparison_operator"
13528                                       [(match_operand 2
13529                                                       "cc_reg_operand" "y")
13530                                        (const_int 0)])
13531                       (label_ref (match_operand 0 "" ""))
13532                       (pc)))]
13533   ""
13534   "*
13535 {
13536   return output_cbranch (operands[1], \"%l0\", 0, insn);
13537 }"
13538   [(set_attr "type" "branch")])
13539
13540 (define_insn ""
13541   [(set (pc)
13542         (if_then_else (match_operator 0 "branch_comparison_operator"
13543                                       [(match_operand 1
13544                                                       "cc_reg_operand" "y")
13545                                        (const_int 0)])
13546                       (return)
13547                       (pc)))]
13548   "direct_return ()"
13549   "*
13550 {
13551   return output_cbranch (operands[0], NULL, 0, insn);
13552 }"
13553   [(set_attr "type" "jmpreg")
13554    (set_attr "length" "4")])
13555
13556 (define_insn ""
13557   [(set (pc)
13558         (if_then_else (match_operator 1 "branch_comparison_operator"
13559                                       [(match_operand 2
13560                                                       "cc_reg_operand" "y")
13561                                        (const_int 0)])
13562                       (pc)
13563                       (label_ref (match_operand 0 "" ""))))]
13564   ""
13565   "*
13566 {
13567   return output_cbranch (operands[1], \"%l0\", 1, insn);
13568 }"
13569   [(set_attr "type" "branch")])
13570
13571 (define_insn ""
13572   [(set (pc)
13573         (if_then_else (match_operator 0 "branch_comparison_operator"
13574                                       [(match_operand 1
13575                                                       "cc_reg_operand" "y")
13576                                        (const_int 0)])
13577                       (pc)
13578                       (return)))]
13579   "direct_return ()"
13580   "*
13581 {
13582   return output_cbranch (operands[0], NULL, 1, insn);
13583 }"
13584   [(set_attr "type" "jmpreg")
13585    (set_attr "length" "4")])
13586
13587 ;; Logic on condition register values.
13588
13589 ; This pattern matches things like
13590 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
13591 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
13592 ;                                  (const_int 1)))
13593 ; which are generated by the branch logic.
13594 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
13595
13596 (define_insn "*cceq_ior_compare"
13597   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13598         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
13599                         [(match_operator:SI 2
13600                                       "branch_positive_comparison_operator"
13601                                       [(match_operand 3
13602                                                       "cc_reg_operand" "y,y")
13603                                        (const_int 0)])
13604                          (match_operator:SI 4
13605                                       "branch_positive_comparison_operator"
13606                                       [(match_operand 5
13607                                                       "cc_reg_operand" "0,y")
13608                                        (const_int 0)])])
13609                       (const_int 1)))]
13610   ""
13611   "cr%q1 %E0,%j2,%j4"
13612   [(set_attr "type" "cr_logical,delayed_cr")])
13613
13614 ; Why is the constant -1 here, but 1 in the previous pattern?
13615 ; Because ~1 has all but the low bit set.
13616 (define_insn ""
13617   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13618         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
13619                         [(not:SI (match_operator:SI 2
13620                                       "branch_positive_comparison_operator"
13621                                       [(match_operand 3
13622                                                       "cc_reg_operand" "y,y")
13623                                        (const_int 0)]))
13624                          (match_operator:SI 4
13625                                 "branch_positive_comparison_operator"
13626                                 [(match_operand 5
13627                                                 "cc_reg_operand" "0,y")
13628                                  (const_int 0)])])
13629                       (const_int -1)))]
13630   ""
13631   "cr%q1 %E0,%j2,%j4"
13632   [(set_attr "type" "cr_logical,delayed_cr")])
13633
13634 (define_insn "*cceq_rev_compare"
13635   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13636         (compare:CCEQ (match_operator:SI 1
13637                                       "branch_positive_comparison_operator"
13638                                       [(match_operand 2
13639                                                       "cc_reg_operand" "0,y")
13640                                        (const_int 0)])
13641                       (const_int 0)))]
13642   ""
13643   "{crnor %E0,%j1,%j1|crnot %E0,%j1}"
13644   [(set_attr "type" "cr_logical,delayed_cr")])
13645
13646 ;; If we are comparing the result of two comparisons, this can be done
13647 ;; using creqv or crxor.
13648
13649 (define_insn_and_split ""
13650   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
13651         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
13652                               [(match_operand 2 "cc_reg_operand" "y")
13653                                (const_int 0)])
13654                       (match_operator 3 "branch_comparison_operator"
13655                               [(match_operand 4 "cc_reg_operand" "y")
13656                                (const_int 0)])))]
13657   ""
13658   "#"
13659   ""
13660   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
13661                                     (match_dup 5)))]
13662   "
13663 {
13664   int positive_1, positive_2;
13665
13666   positive_1 = branch_positive_comparison_operator (operands[1],
13667                                                     GET_MODE (operands[1]));
13668   positive_2 = branch_positive_comparison_operator (operands[3],
13669                                                     GET_MODE (operands[3]));
13670
13671   if (! positive_1)
13672     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
13673                                                             GET_CODE (operands[1])),
13674                                   SImode,
13675                                   operands[2], const0_rtx);
13676   else if (GET_MODE (operands[1]) != SImode)
13677     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
13678                                   operands[2], const0_rtx);
13679
13680   if (! positive_2)
13681     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
13682                                                             GET_CODE (operands[3])),
13683                                   SImode,
13684                                   operands[4], const0_rtx);
13685   else if (GET_MODE (operands[3]) != SImode)
13686     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
13687                                   operands[4], const0_rtx);
13688
13689   if (positive_1 == positive_2)
13690     {
13691       operands[1] = gen_rtx_NOT (SImode, operands[1]);
13692       operands[5] = constm1_rtx;
13693     }
13694   else
13695     {
13696       operands[5] = const1_rtx;
13697     }
13698 }")
13699
13700 ;; Unconditional branch and return.
13701
13702 (define_insn "jump"
13703   [(set (pc)
13704         (label_ref (match_operand 0 "" "")))]
13705   ""
13706   "b %l0"
13707   [(set_attr "type" "branch")])
13708
13709 (define_insn "return"
13710   [(return)]
13711   "direct_return ()"
13712   "{br|blr}"
13713   [(set_attr "type" "jmpreg")])
13714
13715 (define_expand "indirect_jump"
13716   [(set (pc) (match_operand 0 "register_operand" ""))])
13717
13718 (define_insn "*indirect_jump<mode>"
13719   [(set (pc) (match_operand:P 0 "register_operand" "c,*l"))]
13720   ""
13721   "@
13722    bctr
13723    {br|blr}"
13724   [(set_attr "type" "jmpreg")])
13725
13726 ;; Table jump for switch statements:
13727 (define_expand "tablejump"
13728   [(use (match_operand 0 "" ""))
13729    (use (label_ref (match_operand 1 "" "")))]
13730   ""
13731   "
13732 {
13733   if (TARGET_32BIT)
13734     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
13735   else
13736     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
13737   DONE;
13738 }")
13739
13740 (define_expand "tablejumpsi"
13741   [(set (match_dup 3)
13742         (plus:SI (match_operand:SI 0 "" "")
13743                  (match_dup 2)))
13744    (parallel [(set (pc) (match_dup 3))
13745               (use (label_ref (match_operand 1 "" "")))])]
13746   "TARGET_32BIT"
13747   "
13748 { operands[0] = force_reg (SImode, operands[0]);
13749   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
13750   operands[3] = gen_reg_rtx (SImode);
13751 }")
13752
13753 (define_expand "tablejumpdi"
13754   [(set (match_dup 4)
13755         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "rm")))
13756    (set (match_dup 3)
13757         (plus:DI (match_dup 4)
13758                  (match_dup 2)))
13759    (parallel [(set (pc) (match_dup 3))
13760               (use (label_ref (match_operand 1 "" "")))])]
13761   "TARGET_64BIT"
13762   "
13763 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
13764   operands[3] = gen_reg_rtx (DImode);
13765   operands[4] = gen_reg_rtx (DImode);
13766 }")
13767
13768 (define_insn "*tablejump<mode>_internal1"
13769   [(set (pc)
13770         (match_operand:P 0 "register_operand" "c,*l"))
13771    (use (label_ref (match_operand 1 "" "")))]
13772   ""
13773   "@
13774    bctr
13775    {br|blr}"
13776   [(set_attr "type" "jmpreg")])
13777
13778 (define_insn "nop"
13779   [(const_int 0)]
13780   ""
13781   "{cror 0,0,0|nop}")
13782 \f
13783 ;; Define the subtract-one-and-jump insns, starting with the template
13784 ;; so loop.c knows what to generate.
13785
13786 (define_expand "doloop_end"
13787   [(use (match_operand 0 "" ""))        ; loop pseudo
13788    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
13789    (use (match_operand 2 "" ""))        ; max iterations
13790    (use (match_operand 3 "" ""))        ; loop level
13791    (use (match_operand 4 "" ""))]       ; label
13792   ""
13793   "
13794 {
13795   /* Only use this on innermost loops.  */
13796   if (INTVAL (operands[3]) > 1)
13797     FAIL;
13798   if (TARGET_64BIT)
13799     {
13800       if (GET_MODE (operands[0]) != DImode)
13801         FAIL;
13802       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
13803     }
13804   else
13805     {
13806       if (GET_MODE (operands[0]) != SImode)
13807         FAIL;
13808       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
13809     }
13810   DONE;
13811 }")
13812
13813 (define_expand "ctr<mode>"
13814   [(parallel [(set (pc)
13815                    (if_then_else (ne (match_operand:P 0 "register_operand" "")
13816                                      (const_int 1))
13817                                  (label_ref (match_operand 1 "" ""))
13818                                  (pc)))
13819               (set (match_dup 0)
13820                    (plus:P (match_dup 0)
13821                             (const_int -1)))
13822               (clobber (match_scratch:CC 2 ""))
13823               (clobber (match_scratch:P 3 ""))])]
13824   ""
13825   "")
13826
13827 ;; We need to be able to do this for any operand, including MEM, or we
13828 ;; will cause reload to blow up since we don't allow output reloads on
13829 ;; JUMP_INSNs.
13830 ;; For the length attribute to be calculated correctly, the
13831 ;; label MUST be operand 0.
13832
13833 (define_insn "*ctr<mode>_internal1"
13834   [(set (pc)
13835         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
13836                           (const_int 1))
13837                       (label_ref (match_operand 0 "" ""))
13838                       (pc)))
13839    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
13840         (plus:P (match_dup 1)
13841                  (const_int -1)))
13842    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13843    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13844   ""
13845   "*
13846 {
13847   if (which_alternative != 0)
13848     return \"#\";
13849   else if (get_attr_length (insn) == 4)
13850     return \"{bdn|bdnz} %l0\";
13851   else
13852     return \"bdz $+8\;b %l0\";
13853 }"
13854   [(set_attr "type" "branch")
13855    (set_attr "length" "*,12,16,16")])
13856
13857 (define_insn "*ctr<mode>_internal2"
13858   [(set (pc)
13859         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
13860                           (const_int 1))
13861                       (pc)
13862                       (label_ref (match_operand 0 "" ""))))
13863    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
13864         (plus:P (match_dup 1)
13865                  (const_int -1)))
13866    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13867    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13868   ""
13869   "*
13870 {
13871   if (which_alternative != 0)
13872     return \"#\";
13873   else if (get_attr_length (insn) == 4)
13874     return \"bdz %l0\";
13875   else
13876     return \"{bdn|bdnz} $+8\;b %l0\";
13877 }"
13878   [(set_attr "type" "branch")
13879    (set_attr "length" "*,12,16,16")])
13880
13881 ;; Similar but use EQ
13882
13883 (define_insn "*ctr<mode>_internal5"
13884   [(set (pc)
13885         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
13886                           (const_int 1))
13887                       (label_ref (match_operand 0 "" ""))
13888                       (pc)))
13889    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
13890         (plus:P (match_dup 1)
13891                  (const_int -1)))
13892    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13893    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13894   ""
13895   "*
13896 {
13897   if (which_alternative != 0)
13898     return \"#\";
13899   else if (get_attr_length (insn) == 4)
13900     return \"bdz %l0\";
13901   else
13902     return \"{bdn|bdnz} $+8\;b %l0\";
13903 }"
13904   [(set_attr "type" "branch")
13905    (set_attr "length" "*,12,16,16")])
13906
13907 (define_insn "*ctr<mode>_internal6"
13908   [(set (pc)
13909         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
13910                           (const_int 1))
13911                       (pc)
13912                       (label_ref (match_operand 0 "" ""))))
13913    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
13914         (plus:P (match_dup 1)
13915                  (const_int -1)))
13916    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13917    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13918   ""
13919   "*
13920 {
13921   if (which_alternative != 0)
13922     return \"#\";
13923   else if (get_attr_length (insn) == 4)
13924     return \"{bdn|bdnz} %l0\";
13925   else
13926     return \"bdz $+8\;b %l0\";
13927 }"
13928   [(set_attr "type" "branch")
13929    (set_attr "length" "*,12,16,16")])
13930
13931 ;; Now the splitters if we could not allocate the CTR register
13932
13933 (define_split
13934   [(set (pc)
13935         (if_then_else (match_operator 2 "comparison_operator"
13936                                       [(match_operand:P 1 "gpc_reg_operand" "")
13937                                        (const_int 1)])
13938                       (match_operand 5 "" "")
13939                       (match_operand 6 "" "")))
13940    (set (match_operand:P 0 "gpc_reg_operand" "")
13941         (plus:P (match_dup 1) (const_int -1)))
13942    (clobber (match_scratch:CC 3 ""))
13943    (clobber (match_scratch:P 4 ""))]
13944   "reload_completed"
13945   [(parallel [(set (match_dup 3)
13946                    (compare:CC (plus:P (match_dup 1)
13947                                         (const_int -1))
13948                                (const_int 0)))
13949               (set (match_dup 0)
13950                    (plus:P (match_dup 1)
13951                             (const_int -1)))])
13952    (set (pc) (if_then_else (match_dup 7)
13953                            (match_dup 5)
13954                            (match_dup 6)))]
13955   "
13956 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
13957                                 operands[3], const0_rtx); }")
13958
13959 (define_split
13960   [(set (pc)
13961         (if_then_else (match_operator 2 "comparison_operator"
13962                                       [(match_operand:P 1 "gpc_reg_operand" "")
13963                                        (const_int 1)])
13964                       (match_operand 5 "" "")
13965                       (match_operand 6 "" "")))
13966    (set (match_operand:P 0 "nonimmediate_operand" "")
13967         (plus:P (match_dup 1) (const_int -1)))
13968    (clobber (match_scratch:CC 3 ""))
13969    (clobber (match_scratch:P 4 ""))]
13970   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
13971   [(parallel [(set (match_dup 3)
13972                    (compare:CC (plus:P (match_dup 1)
13973                                         (const_int -1))
13974                                (const_int 0)))
13975               (set (match_dup 4)
13976                    (plus:P (match_dup 1)
13977                             (const_int -1)))])
13978    (set (match_dup 0)
13979         (match_dup 4))
13980    (set (pc) (if_then_else (match_dup 7)
13981                            (match_dup 5)
13982                            (match_dup 6)))]
13983   "
13984 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
13985                                 operands[3], const0_rtx); }")
13986 \f
13987 (define_insn "trap"
13988   [(trap_if (const_int 1) (const_int 0))]
13989   ""
13990   "{t 31,0,0|trap}")
13991
13992 (define_expand "conditional_trap"
13993   [(trap_if (match_operator 0 "trap_comparison_operator"
13994                             [(match_dup 2) (match_dup 3)])
13995             (match_operand 1 "const_int_operand" ""))]
13996   ""
13997   "if (rs6000_compare_fp_p || operands[1] != const0_rtx) FAIL;
13998    operands[2] = rs6000_compare_op0;
13999    operands[3] = rs6000_compare_op1;")
14000
14001 (define_insn ""
14002   [(trap_if (match_operator 0 "trap_comparison_operator"
14003                             [(match_operand:GPR 1 "register_operand" "r")
14004                              (match_operand:GPR 2 "reg_or_short_operand" "rI")])
14005             (const_int 0))]
14006   ""
14007   "{t|t<wd>}%V0%I2 %1,%2")
14008 \f
14009 ;; Insns related to generating the function prologue and epilogue.
14010
14011 (define_expand "prologue"
14012   [(use (const_int 0))]
14013   "TARGET_SCHED_PROLOG"
14014   "
14015 {
14016       rs6000_emit_prologue ();
14017       DONE;
14018 }")
14019
14020 (define_insn "*movesi_from_cr_one"
14021   [(match_parallel 0 "mfcr_operation"
14022                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14023                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
14024                                      (match_operand 3 "immediate_operand" "n")]
14025                           UNSPEC_MOVESI_FROM_CR))])]
14026   "TARGET_MFCRF"
14027   "*
14028 {
14029   int mask = 0;
14030   int i;
14031   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14032   {
14033     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14034     operands[4] = GEN_INT (mask);
14035     output_asm_insn (\"mfcr %1,%4\", operands);
14036   }
14037   return \"\";
14038 }"
14039   [(set_attr "type" "mfcrf")])
14040
14041 (define_insn "movesi_from_cr"
14042   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14043         (unspec:SI [(reg:CC 68) (reg:CC 69) (reg:CC 70) (reg:CC 71)
14044                     (reg:CC 72) (reg:CC 73) (reg:CC 74) (reg:CC 75)]
14045                    UNSPEC_MOVESI_FROM_CR))]
14046   ""
14047   "mfcr %0"
14048   [(set_attr "type" "mfcr")])
14049
14050 (define_insn "*stmw"
14051   [(match_parallel 0 "stmw_operation"
14052                    [(set (match_operand:SI 1 "memory_operand" "=m")
14053                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
14054   "TARGET_MULTIPLE"
14055   "{stm|stmw} %2,%1"
14056   [(set_attr "type" "store_ux")])
14057
14058 (define_insn "*save_fpregs_<mode>"
14059   [(match_parallel 0 "any_parallel_operand"
14060                    [(clobber (match_operand:P 1 "register_operand" "=l"))
14061                     (use (match_operand:P 2 "call_operand" "s"))
14062                     (set (match_operand:DF 3 "memory_operand" "=m")
14063                          (match_operand:DF 4 "gpc_reg_operand" "f"))])]
14064   ""
14065   "bl %z2"
14066   [(set_attr "type" "branch")
14067    (set_attr "length" "4")])
14068
14069 ; These are to explain that changes to the stack pointer should
14070 ; not be moved over stores to stack memory.
14071 (define_insn "stack_tie"
14072   [(set (match_operand:BLK 0 "memory_operand" "+m")
14073         (unspec:BLK [(match_dup 0)] UNSPEC_TIE))]
14074   ""
14075   ""
14076   [(set_attr "length" "0")])
14077
14078
14079 (define_expand "epilogue"
14080   [(use (const_int 0))]
14081   "TARGET_SCHED_PROLOG"
14082   "
14083 {
14084       rs6000_emit_epilogue (FALSE);
14085       DONE;
14086 }")
14087
14088 ; On some processors, doing the mtcrf one CC register at a time is
14089 ; faster (like on the 604e).  On others, doing them all at once is
14090 ; faster; for instance, on the 601 and 750.
14091
14092 (define_expand "movsi_to_cr_one"
14093   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14094         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14095                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
14096   ""
14097   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
14098
14099 (define_insn "*movsi_to_cr"
14100   [(match_parallel 0 "mtcrf_operation"
14101                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
14102                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
14103                                      (match_operand 3 "immediate_operand" "n")]
14104                                     UNSPEC_MOVESI_TO_CR))])]
14105  ""
14106  "*
14107 {
14108   int mask = 0;
14109   int i;
14110   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14111     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14112   operands[4] = GEN_INT (mask);
14113   return \"mtcrf %4,%2\";
14114 }"
14115   [(set_attr "type" "mtcr")])
14116
14117 (define_insn "*mtcrfsi"
14118   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14119         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14120                     (match_operand 2 "immediate_operand" "n")]
14121                    UNSPEC_MOVESI_TO_CR))]
14122   "GET_CODE (operands[0]) == REG
14123    && CR_REGNO_P (REGNO (operands[0]))
14124    && GET_CODE (operands[2]) == CONST_INT
14125    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
14126   "mtcrf %R0,%1"
14127   [(set_attr "type" "mtcr")])
14128
14129 ; The load-multiple instructions have similar properties.
14130 ; Note that "load_multiple" is a name known to the machine-independent
14131 ; code that actually corresponds to the PowerPC load-string.
14132
14133 (define_insn "*lmw"
14134   [(match_parallel 0 "lmw_operation"
14135                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14136                          (match_operand:SI 2 "memory_operand" "m"))])]
14137   "TARGET_MULTIPLE"
14138   "{lm|lmw} %1,%2"
14139   [(set_attr "type" "load_ux")])
14140
14141 (define_insn "*return_internal_<mode>"
14142   [(return)
14143    (use (match_operand:P 0 "register_operand" "lc"))]
14144   ""
14145   "b%T0"
14146   [(set_attr "type" "jmpreg")])
14147
14148 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
14149 ; stuff was in GCC.  Oh, and "any_parallel_operand" is a bit flexible...
14150
14151 (define_insn "*return_and_restore_fpregs_<mode>"
14152  [(match_parallel 0 "any_parallel_operand"
14153                   [(return)
14154                    (use (match_operand:P 1 "register_operand" "l"))
14155                    (use (match_operand:P 2 "call_operand" "s"))
14156                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
14157                         (match_operand:DF 4 "memory_operand" "m"))])]
14158  ""
14159  "b %z2")
14160
14161 ; This is used in compiling the unwind routines.
14162 (define_expand "eh_return"
14163   [(use (match_operand 0 "general_operand" ""))]
14164   ""
14165   "
14166 {
14167   if (TARGET_32BIT)
14168     emit_insn (gen_eh_set_lr_si (operands[0]));
14169   else
14170     emit_insn (gen_eh_set_lr_di (operands[0]));
14171   DONE;
14172 }")
14173
14174 ; We can't expand this before we know where the link register is stored.
14175 (define_insn "eh_set_lr_<mode>"
14176   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
14177                     UNSPECV_EH_RR)
14178    (clobber (match_scratch:P 1 "=&b"))]
14179   ""
14180   "#")
14181
14182 (define_split
14183   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
14184    (clobber (match_scratch 1 ""))]
14185   "reload_completed"
14186   [(const_int 0)]
14187   "
14188 {
14189   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
14190   DONE;
14191 }")
14192
14193 (define_insn "prefetch"
14194   [(prefetch (match_operand 0 "indexed_or_indirect_address" "a")
14195              (match_operand:SI 1 "const_int_operand" "n")
14196              (match_operand:SI 2 "const_int_operand" "n"))]
14197   "TARGET_POWERPC"
14198   "*
14199 {
14200   if (GET_CODE (operands[0]) == REG)
14201     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
14202   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
14203 }"
14204   [(set_attr "type" "load")])
14205 \f
14206
14207 (include "sync.md")
14208 (include "altivec.md")
14209 (include "spe.md")