OSDN Git Service

1157c4e2ee349a12704896f24d29eb555abadade
[pf3gnuchains/gcc-fork.git] / gcc / config / rs6000 / rs6000.md
1 ;; Machine description for IBM RISC System 6000 (POWER) for GNU C compiler
2 ;; Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 ;; 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
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,var_delayed_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,shift,trap,insert_dword,var_shift_rotate,cntlz,exts,mffgpr,mftgpr"
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,power6,cell"
110   (const (symbol_ref "rs6000_cpu_attr")))
111
112
113 ;; If this instruction is microcoded on the CELL processor
114 ; The default for load and stores is conditional
115 ; The default for load extended and the recorded instructions is always microcoded
116 (define_attr "cell_micro" "not,conditional,always"
117   (if_then_else (ior (ior (eq_attr "type" "load")
118                           (eq_attr "type" "store"))
119                      (ior (eq_attr "type" "fpload")
120                           (eq_attr "type" "fpstore")))
121                 (const_string "conditional")
122                 (if_then_else (ior (eq_attr "type" "load_ext")
123                                    (ior (eq_attr "type" "compare")
124                                         (eq_attr "type" "delayed_compare")))
125                               (const_string "always")
126                               (const_string "not"))))
127
128
129 (automata_option "ndfa")
130
131 (include "rios1.md")
132 (include "rios2.md")
133 (include "rs64.md")
134 (include "mpc.md")
135 (include "40x.md")
136 (include "440.md")
137 (include "603.md")
138 (include "6xx.md")
139 (include "7xx.md")
140 (include "7450.md")
141 (include "8540.md")
142 (include "power4.md")
143 (include "power5.md")
144 (include "power6.md")
145 (include "cell.md")
146
147 (include "predicates.md")
148 (include "constraints.md")
149
150 (include "darwin.md")
151
152 \f
153 ;; Mode macros
154
155 ; This mode macro allows :GPR to be used to indicate the allowable size
156 ; of whole values in GPRs.
157 (define_mode_macro GPR [SI (DI "TARGET_POWERPC64")])
158
159 ; Any supported integer mode.
160 (define_mode_macro INT [QI HI SI DI TI])
161
162 ; Any supported integer mode that fits in one register.
163 (define_mode_macro INT1 [QI HI SI (DI "TARGET_POWERPC64")])
164
165 ; extend modes for DImode
166 (define_mode_macro QHSI [QI HI SI])
167
168 ; SImode or DImode, even if DImode doesn't fit in GPRs.
169 (define_mode_macro SDI [SI DI])
170
171 ; The size of a pointer.  Also, the size of the value that a record-condition
172 ; (one with a '.') will compare.
173 (define_mode_macro P [(SI "TARGET_32BIT") (DI "TARGET_64BIT")])
174
175 ; Any hardware-supported floating-point mode
176 (define_mode_macro FP [(SF "TARGET_HARD_FLOAT")
177   (DF "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)")
178   (TF "!TARGET_IEEEQUAD
179    && TARGET_HARD_FLOAT
180    && (TARGET_FPRS || TARGET_E500_DOUBLE)
181    && TARGET_LONG_DOUBLE_128")])
182
183 ; Various instructions that come in SI and DI forms.
184 ; A generic w/d attribute, for things like cmpw/cmpd.
185 (define_mode_attr wd [(QI "b") (HI "h") (SI "w") (DI "d")])
186
187 ; DImode bits
188 (define_mode_attr dbits [(QI "56") (HI "48") (SI "32")])
189
190 \f
191 ;; Start with fixed-point load and store insns.  Here we put only the more
192 ;; complex forms.  Basic data transfer is done later.
193
194 (define_expand "zero_extend<mode>di2"
195   [(set (match_operand:DI 0 "gpc_reg_operand" "")
196         (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "")))]
197   "TARGET_POWERPC64"
198   "")
199
200 (define_insn "*zero_extend<mode>di2_internal1"
201   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
202         (zero_extend:DI (match_operand:QHSI 1 "reg_or_mem_operand" "m,r")))]
203   "TARGET_POWERPC64"
204   "@
205    l<wd>z%U1%X1 %0,%1
206    rldicl %0,%1,0,<dbits>"
207   [(set_attr "type" "load,*")])
208
209 (define_insn "*zero_extend<mode>di2_internal2"
210   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
211         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
212                     (const_int 0)))
213    (clobber (match_scratch:DI 2 "=r,r"))]
214   "TARGET_64BIT"
215   "@
216    rldicl. %2,%1,0,<dbits>
217    #"
218   [(set_attr "type" "compare")
219    (set_attr "length" "4,8")])
220
221 (define_split
222   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
223         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
224                     (const_int 0)))
225    (clobber (match_scratch:DI 2 ""))]
226   "TARGET_POWERPC64 && reload_completed"
227   [(set (match_dup 2)
228         (zero_extend:DI (match_dup 1)))
229    (set (match_dup 0)
230         (compare:CC (match_dup 2)
231                     (const_int 0)))]
232   "")
233
234 (define_insn "*zero_extend<mode>di2_internal3"
235   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
236         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
237                     (const_int 0)))
238    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
239         (zero_extend:DI (match_dup 1)))]
240   "TARGET_64BIT"
241   "@
242    rldicl. %0,%1,0,<dbits>
243    #"
244   [(set_attr "type" "compare")
245    (set_attr "length" "4,8")])
246
247 (define_split
248   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
249         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
250                     (const_int 0)))
251    (set (match_operand:DI 0 "gpc_reg_operand" "")
252         (zero_extend:DI (match_dup 1)))]
253   "TARGET_POWERPC64 && reload_completed"
254   [(set (match_dup 0)
255         (zero_extend:DI (match_dup 1)))
256    (set (match_dup 2)
257         (compare:CC (match_dup 0)
258                     (const_int 0)))]
259   "")
260
261 (define_insn "extendqidi2"
262   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
263         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
264   "TARGET_POWERPC64"
265   "extsb %0,%1"
266   [(set_attr "type" "exts")])
267
268 (define_insn ""
269   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
270         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
271                     (const_int 0)))
272    (clobber (match_scratch:DI 2 "=r,r"))]
273   "TARGET_64BIT"
274   "@
275    extsb. %2,%1
276    #"
277   [(set_attr "type" "compare")
278    (set_attr "length" "4,8")])
279
280 (define_split
281   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
282         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
283                     (const_int 0)))
284    (clobber (match_scratch:DI 2 ""))]
285   "TARGET_POWERPC64 && reload_completed"
286   [(set (match_dup 2)
287         (sign_extend:DI (match_dup 1)))
288    (set (match_dup 0)
289         (compare:CC (match_dup 2)
290                     (const_int 0)))]
291   "")
292
293 (define_insn ""
294   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
295         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
296                     (const_int 0)))
297    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
298         (sign_extend:DI (match_dup 1)))]
299   "TARGET_64BIT"
300   "@
301    extsb. %0,%1
302    #"
303   [(set_attr "type" "compare")
304    (set_attr "length" "4,8")])
305
306 (define_split
307   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
308         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
309                     (const_int 0)))
310    (set (match_operand:DI 0 "gpc_reg_operand" "")
311         (sign_extend:DI (match_dup 1)))]
312   "TARGET_POWERPC64 && reload_completed"
313   [(set (match_dup 0)
314         (sign_extend:DI (match_dup 1)))
315    (set (match_dup 2)
316         (compare:CC (match_dup 0)
317                     (const_int 0)))]
318   "")
319
320 (define_expand "extendhidi2"
321   [(set (match_operand:DI 0 "gpc_reg_operand" "")
322         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
323   "TARGET_POWERPC64"
324   "")
325
326 (define_insn ""
327   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
328         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
329   "TARGET_POWERPC64"
330   "@
331    lha%U1%X1 %0,%1
332    extsh %0,%1"
333   [(set_attr "type" "load_ext,exts")])
334
335 (define_insn ""
336   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
337         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
338                     (const_int 0)))
339    (clobber (match_scratch:DI 2 "=r,r"))]
340   "TARGET_64BIT"
341   "@
342    extsh. %2,%1
343    #"
344   [(set_attr "type" "compare")
345    (set_attr "length" "4,8")])
346
347 (define_split
348   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
349         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
350                     (const_int 0)))
351    (clobber (match_scratch:DI 2 ""))]
352   "TARGET_POWERPC64 && reload_completed"
353   [(set (match_dup 2)
354         (sign_extend:DI (match_dup 1)))
355    (set (match_dup 0)
356         (compare:CC (match_dup 2)
357                     (const_int 0)))]
358   "")
359
360 (define_insn ""
361   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
362         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
363                     (const_int 0)))
364    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
365         (sign_extend:DI (match_dup 1)))]
366   "TARGET_64BIT"
367   "@
368    extsh. %0,%1
369    #"
370   [(set_attr "type" "compare")
371    (set_attr "length" "4,8")])
372
373 (define_split
374   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
375         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
376                     (const_int 0)))
377    (set (match_operand:DI 0 "gpc_reg_operand" "")
378         (sign_extend:DI (match_dup 1)))]
379   "TARGET_POWERPC64 && reload_completed"
380   [(set (match_dup 0)
381         (sign_extend:DI (match_dup 1)))
382    (set (match_dup 2)
383         (compare:CC (match_dup 0)
384                     (const_int 0)))]
385   "")
386
387 (define_expand "extendsidi2"
388   [(set (match_operand:DI 0 "gpc_reg_operand" "")
389         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
390   "TARGET_POWERPC64"
391   "")
392
393 (define_insn ""
394   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
395         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
396   "TARGET_POWERPC64"
397   "@
398    lwa%U1%X1 %0,%1
399    extsw %0,%1"
400   [(set_attr "type" "load_ext,exts")])
401
402 (define_insn ""
403   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
404         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
405                     (const_int 0)))
406    (clobber (match_scratch:DI 2 "=r,r"))]
407   "TARGET_64BIT"
408   "@
409    extsw. %2,%1
410    #"
411   [(set_attr "type" "compare")
412    (set_attr "length" "4,8")])
413
414 (define_split
415   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
416         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
417                     (const_int 0)))
418    (clobber (match_scratch:DI 2 ""))]
419   "TARGET_POWERPC64 && reload_completed"
420   [(set (match_dup 2)
421         (sign_extend:DI (match_dup 1)))
422    (set (match_dup 0)
423         (compare:CC (match_dup 2)
424                     (const_int 0)))]
425   "")
426
427 (define_insn ""
428   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
429         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
430                     (const_int 0)))
431    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
432         (sign_extend:DI (match_dup 1)))]
433   "TARGET_64BIT"
434   "@
435    extsw. %0,%1
436    #"
437   [(set_attr "type" "compare")
438    (set_attr "length" "4,8")])
439
440 (define_split
441   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
442         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
443                     (const_int 0)))
444    (set (match_operand:DI 0 "gpc_reg_operand" "")
445         (sign_extend:DI (match_dup 1)))]
446   "TARGET_POWERPC64 && reload_completed"
447   [(set (match_dup 0)
448         (sign_extend:DI (match_dup 1)))
449    (set (match_dup 2)
450         (compare:CC (match_dup 0)
451                     (const_int 0)))]
452   "")
453
454 (define_expand "zero_extendqisi2"
455   [(set (match_operand:SI 0 "gpc_reg_operand" "")
456         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
457   ""
458   "")
459
460 (define_insn ""
461   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
462         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
463   ""
464   "@
465    lbz%U1%X1 %0,%1
466    {rlinm|rlwinm} %0,%1,0,0xff"
467   [(set_attr "type" "load,*")])
468
469 (define_insn ""
470   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
471         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
472                     (const_int 0)))
473    (clobber (match_scratch:SI 2 "=r,r"))]
474   ""
475   "@
476    {andil.|andi.} %2,%1,0xff
477    #"
478   [(set_attr "type" "compare")
479    (set_attr "length" "4,8")])
480
481 (define_split
482   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
483         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
484                     (const_int 0)))
485    (clobber (match_scratch:SI 2 ""))]
486   "reload_completed"
487   [(set (match_dup 2)
488         (zero_extend:SI (match_dup 1)))
489    (set (match_dup 0)
490         (compare:CC (match_dup 2)
491                     (const_int 0)))]
492   "")
493
494 (define_insn ""
495   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
496         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
497                     (const_int 0)))
498    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
499         (zero_extend:SI (match_dup 1)))]
500   ""
501   "@
502    {andil.|andi.} %0,%1,0xff
503    #"
504   [(set_attr "type" "compare")
505    (set_attr "length" "4,8")])
506
507 (define_split
508   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
509         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
510                     (const_int 0)))
511    (set (match_operand:SI 0 "gpc_reg_operand" "")
512         (zero_extend:SI (match_dup 1)))]
513   "reload_completed"
514   [(set (match_dup 0)
515         (zero_extend:SI (match_dup 1)))
516    (set (match_dup 2)
517         (compare:CC (match_dup 0)
518                     (const_int 0)))]
519   "")
520
521 (define_expand "extendqisi2"
522   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
523    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
524   ""
525   "
526 {
527   if (TARGET_POWERPC)
528     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
529   else if (TARGET_POWER)
530     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
531   else
532     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
533   DONE;
534 }")
535
536 (define_insn "extendqisi2_ppc"
537   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
538         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
539   "TARGET_POWERPC"
540   "extsb %0,%1"
541   [(set_attr "type" "exts")])
542
543 (define_insn ""
544   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
545         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
546                     (const_int 0)))
547    (clobber (match_scratch:SI 2 "=r,r"))]
548   "TARGET_POWERPC"
549   "@
550    extsb. %2,%1
551    #"
552   [(set_attr "type" "compare")
553    (set_attr "length" "4,8")])
554
555 (define_split
556   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
557         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
558                     (const_int 0)))
559    (clobber (match_scratch:SI 2 ""))]
560   "TARGET_POWERPC && reload_completed"
561   [(set (match_dup 2)
562         (sign_extend:SI (match_dup 1)))
563    (set (match_dup 0)
564         (compare:CC (match_dup 2)
565                     (const_int 0)))]
566   "")
567
568 (define_insn ""
569   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
570         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
571                     (const_int 0)))
572    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
573         (sign_extend:SI (match_dup 1)))]
574   "TARGET_POWERPC"
575   "@
576    extsb. %0,%1
577    #"
578   [(set_attr "type" "compare")
579    (set_attr "length" "4,8")])
580
581 (define_split
582   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
583         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
584                     (const_int 0)))
585    (set (match_operand:SI 0 "gpc_reg_operand" "")
586         (sign_extend:SI (match_dup 1)))]
587   "TARGET_POWERPC && reload_completed"
588   [(set (match_dup 0)
589         (sign_extend:SI (match_dup 1)))
590    (set (match_dup 2)
591         (compare:CC (match_dup 0)
592                     (const_int 0)))]
593   "")
594
595 (define_expand "extendqisi2_power"
596   [(parallel [(set (match_dup 2)
597                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
598                               (const_int 24)))
599               (clobber (scratch:SI))])
600    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
601                    (ashiftrt:SI (match_dup 2)
602                                 (const_int 24)))
603               (clobber (scratch:SI))])]
604   "TARGET_POWER"
605   "
606 { operands[1] = gen_lowpart (SImode, operands[1]);
607   operands[2] = gen_reg_rtx (SImode); }")
608
609 (define_expand "extendqisi2_no_power"
610   [(set (match_dup 2)
611         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
612                    (const_int 24)))
613    (set (match_operand:SI 0 "gpc_reg_operand" "")
614         (ashiftrt:SI (match_dup 2)
615                      (const_int 24)))]
616   "! TARGET_POWER && ! TARGET_POWERPC"
617   "
618 { operands[1] = gen_lowpart (SImode, operands[1]);
619   operands[2] = gen_reg_rtx (SImode); }")
620
621 (define_expand "zero_extendqihi2"
622   [(set (match_operand:HI 0 "gpc_reg_operand" "")
623         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
624   ""
625   "")
626
627 (define_insn ""
628   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
629         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
630   ""
631   "@
632    lbz%U1%X1 %0,%1
633    {rlinm|rlwinm} %0,%1,0,0xff"
634   [(set_attr "type" "load,*")])
635
636 (define_insn ""
637   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
638         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
639                     (const_int 0)))
640    (clobber (match_scratch:HI 2 "=r,r"))]
641   ""
642   "@
643    {andil.|andi.} %2,%1,0xff
644    #"
645   [(set_attr "type" "compare")
646    (set_attr "length" "4,8")])
647
648 (define_split
649   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
650         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
651                     (const_int 0)))
652    (clobber (match_scratch:HI 2 ""))]
653   "reload_completed"
654   [(set (match_dup 2)
655         (zero_extend:HI (match_dup 1)))
656    (set (match_dup 0)
657         (compare:CC (match_dup 2)
658                     (const_int 0)))]
659   "")
660
661 (define_insn ""
662   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
663         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
664                     (const_int 0)))
665    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
666         (zero_extend:HI (match_dup 1)))]
667   ""
668   "@
669    {andil.|andi.} %0,%1,0xff
670    #"
671   [(set_attr "type" "compare")
672    (set_attr "length" "4,8")])
673
674 (define_split
675   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
676         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
677                     (const_int 0)))
678    (set (match_operand:HI 0 "gpc_reg_operand" "")
679         (zero_extend:HI (match_dup 1)))]
680   "reload_completed"
681   [(set (match_dup 0)
682         (zero_extend:HI (match_dup 1)))
683    (set (match_dup 2)
684         (compare:CC (match_dup 0)
685                     (const_int 0)))]
686   "")
687
688 (define_expand "extendqihi2"
689   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
690    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
691   ""
692   "
693 {
694   if (TARGET_POWERPC)
695     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
696   else if (TARGET_POWER)
697     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
698   else
699     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
700   DONE;
701 }")
702
703 (define_insn "extendqihi2_ppc"
704   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
705         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
706   "TARGET_POWERPC"
707   "extsb %0,%1"
708   [(set_attr "type" "exts")])
709
710 (define_insn ""
711   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
712         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
713                     (const_int 0)))
714    (clobber (match_scratch:HI 2 "=r,r"))]
715   "TARGET_POWERPC"
716   "@
717    extsb. %2,%1
718    #"
719   [(set_attr "type" "compare")
720    (set_attr "length" "4,8")])
721
722 (define_split
723   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
724         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
725                     (const_int 0)))
726    (clobber (match_scratch:HI 2 ""))]
727   "TARGET_POWERPC && reload_completed"
728   [(set (match_dup 2)
729         (sign_extend:HI (match_dup 1)))
730    (set (match_dup 0)
731         (compare:CC (match_dup 2)
732                     (const_int 0)))]
733   "")
734
735 (define_insn ""
736   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
737         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
738                     (const_int 0)))
739    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
740         (sign_extend:HI (match_dup 1)))]
741   "TARGET_POWERPC"
742   "@
743    extsb. %0,%1
744    #"
745   [(set_attr "type" "compare")
746    (set_attr "length" "4,8")])
747
748 (define_split
749   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
750         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
751                     (const_int 0)))
752    (set (match_operand:HI 0 "gpc_reg_operand" "")
753         (sign_extend:HI (match_dup 1)))]
754   "TARGET_POWERPC && reload_completed"
755   [(set (match_dup 0)
756         (sign_extend:HI (match_dup 1)))
757    (set (match_dup 2)
758         (compare:CC (match_dup 0)
759                     (const_int 0)))]
760   "")
761
762 (define_expand "extendqihi2_power"
763   [(parallel [(set (match_dup 2)
764                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
765                               (const_int 24)))
766               (clobber (scratch:SI))])
767    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
768                    (ashiftrt:SI (match_dup 2)
769                                 (const_int 24)))
770               (clobber (scratch:SI))])]
771   "TARGET_POWER"
772   "
773 { operands[0] = gen_lowpart (SImode, operands[0]);
774   operands[1] = gen_lowpart (SImode, operands[1]);
775   operands[2] = gen_reg_rtx (SImode); }")
776
777 (define_expand "extendqihi2_no_power"
778   [(set (match_dup 2)
779         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
780                    (const_int 24)))
781    (set (match_operand:HI 0 "gpc_reg_operand" "")
782         (ashiftrt:SI (match_dup 2)
783                      (const_int 24)))]
784   "! TARGET_POWER && ! TARGET_POWERPC"
785   "
786 { operands[0] = gen_lowpart (SImode, operands[0]);
787   operands[1] = gen_lowpart (SImode, operands[1]);
788   operands[2] = gen_reg_rtx (SImode); }")
789
790 (define_expand "zero_extendhisi2"
791   [(set (match_operand:SI 0 "gpc_reg_operand" "")
792         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
793   ""
794   "")
795
796 (define_insn ""
797   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
798         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
799   ""
800   "@
801    lhz%U1%X1 %0,%1
802    {rlinm|rlwinm} %0,%1,0,0xffff"
803   [(set_attr "type" "load,*")])
804
805 (define_insn ""
806   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
807         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
808                     (const_int 0)))
809    (clobber (match_scratch:SI 2 "=r,r"))]
810   ""
811   "@
812    {andil.|andi.} %2,%1,0xffff
813    #"
814   [(set_attr "type" "compare")
815    (set_attr "length" "4,8")])
816
817 (define_split
818   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
819         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
820                     (const_int 0)))
821    (clobber (match_scratch:SI 2 ""))]
822   "reload_completed"
823   [(set (match_dup 2)
824         (zero_extend:SI (match_dup 1)))
825    (set (match_dup 0)
826         (compare:CC (match_dup 2)
827                     (const_int 0)))]
828   "")
829
830 (define_insn ""
831   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
832         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
833                     (const_int 0)))
834    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
835         (zero_extend:SI (match_dup 1)))]
836   ""
837   "@
838    {andil.|andi.} %0,%1,0xffff
839    #"
840   [(set_attr "type" "compare")
841    (set_attr "length" "4,8")])
842
843 (define_split
844   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
845         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
846                     (const_int 0)))
847    (set (match_operand:SI 0 "gpc_reg_operand" "")
848         (zero_extend:SI (match_dup 1)))]
849   "reload_completed"
850   [(set (match_dup 0)
851         (zero_extend:SI (match_dup 1)))
852    (set (match_dup 2)
853         (compare:CC (match_dup 0)
854                     (const_int 0)))]
855   "")
856
857 (define_expand "extendhisi2"
858   [(set (match_operand:SI 0 "gpc_reg_operand" "")
859         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
860   ""
861   "")
862
863 (define_insn ""
864   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
865         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
866   ""
867   "@
868    lha%U1%X1 %0,%1
869    {exts|extsh} %0,%1"
870   [(set_attr "type" "load_ext,exts")])
871
872 (define_insn ""
873   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
874         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
875                     (const_int 0)))
876    (clobber (match_scratch:SI 2 "=r,r"))]
877   ""
878   "@
879    {exts.|extsh.} %2,%1
880    #"
881   [(set_attr "type" "compare")
882    (set_attr "length" "4,8")])
883
884 (define_split
885   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
886         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
887                     (const_int 0)))
888    (clobber (match_scratch:SI 2 ""))]
889   "reload_completed"
890   [(set (match_dup 2)
891         (sign_extend:SI (match_dup 1)))
892    (set (match_dup 0)
893         (compare:CC (match_dup 2)
894                     (const_int 0)))]
895   "")
896
897 (define_insn ""
898   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
899         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
900                     (const_int 0)))
901    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
902         (sign_extend:SI (match_dup 1)))]
903   ""
904   "@
905    {exts.|extsh.} %0,%1
906    #"
907   [(set_attr "type" "compare")
908    (set_attr "length" "4,8")])
909 \f
910 ;; IBM 405 and 440 half-word multiplication operations.
911
912 (define_insn "*macchwc"
913   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
914         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
915                                        (match_operand:SI 2 "gpc_reg_operand" "r")
916                                        (const_int 16))
917                                       (sign_extend:SI
918                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
919                              (match_operand:SI 4 "gpc_reg_operand" "0"))
920                     (const_int 0)))
921    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
922         (plus:SI (mult:SI (ashiftrt:SI
923                            (match_dup 2)
924                            (const_int 16))
925                           (sign_extend:SI
926                            (match_dup 1)))
927                  (match_dup 4)))]
928   "TARGET_MULHW"
929   "macchw. %0, %1, %2"
930   [(set_attr "type" "imul3")])
931
932 (define_insn "*macchw"
933   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
934         (plus:SI (mult:SI (ashiftrt:SI
935                            (match_operand:SI 2 "gpc_reg_operand" "r")
936                            (const_int 16))
937                           (sign_extend:SI
938                            (match_operand:HI 1 "gpc_reg_operand" "r")))
939                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
940   "TARGET_MULHW"
941   "macchw %0, %1, %2"
942   [(set_attr "type" "imul3")])
943
944 (define_insn "*macchwuc"
945   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
946         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
947                                        (match_operand:SI 2 "gpc_reg_operand" "r")
948                                        (const_int 16))
949                                       (zero_extend:SI
950                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
951                              (match_operand:SI 4 "gpc_reg_operand" "0"))
952                     (const_int 0)))
953    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
954         (plus:SI (mult:SI (lshiftrt:SI
955                            (match_dup 2)
956                            (const_int 16))
957                           (zero_extend:SI
958                            (match_dup 1)))
959                  (match_dup 4)))]
960   "TARGET_MULHW"
961   "macchwu. %0, %1, %2"
962   [(set_attr "type" "imul3")])
963
964 (define_insn "*macchwu"
965   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
966         (plus:SI (mult:SI (lshiftrt:SI
967                            (match_operand:SI 2 "gpc_reg_operand" "r")
968                            (const_int 16))
969                           (zero_extend:SI
970                            (match_operand:HI 1 "gpc_reg_operand" "r")))
971                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
972   "TARGET_MULHW"
973   "macchwu %0, %1, %2"
974   [(set_attr "type" "imul3")])
975
976 (define_insn "*machhwc"
977   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
978         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
979                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
980                                        (const_int 16))
981                                       (ashiftrt:SI
982                                        (match_operand:SI 2 "gpc_reg_operand" "r")
983                                        (const_int 16)))
984                              (match_operand:SI 4 "gpc_reg_operand" "0"))
985                     (const_int 0)))
986    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
987         (plus:SI (mult:SI (ashiftrt:SI
988                            (match_dup 1)
989                            (const_int 16))
990                           (ashiftrt:SI
991                            (match_dup 2)
992                            (const_int 16)))
993                  (match_dup 4)))]
994   "TARGET_MULHW"
995   "machhw. %0, %1, %2"
996   [(set_attr "type" "imul3")])
997
998 (define_insn "*machhw"
999   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1000         (plus:SI (mult:SI (ashiftrt:SI
1001                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1002                            (const_int 16))
1003                           (ashiftrt:SI
1004                            (match_operand:SI 2 "gpc_reg_operand" "r")
1005                            (const_int 16)))
1006                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1007   "TARGET_MULHW"
1008   "machhw %0, %1, %2"
1009   [(set_attr "type" "imul3")])
1010
1011 (define_insn "*machhwuc"
1012   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1013         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1014                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1015                                        (const_int 16))
1016                                       (lshiftrt:SI
1017                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1018                                        (const_int 16)))
1019                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1020                     (const_int 0)))
1021    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1022         (plus:SI (mult:SI (lshiftrt:SI
1023                            (match_dup 1)
1024                            (const_int 16))
1025                           (lshiftrt:SI
1026                            (match_dup 2)
1027                            (const_int 16)))
1028                  (match_dup 4)))]
1029   "TARGET_MULHW"
1030   "machhwu. %0, %1, %2"
1031   [(set_attr "type" "imul3")])
1032
1033 (define_insn "*machhwu"
1034   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1035         (plus:SI (mult:SI (lshiftrt:SI
1036                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1037                            (const_int 16))
1038                           (lshiftrt:SI
1039                            (match_operand:SI 2 "gpc_reg_operand" "r")
1040                            (const_int 16)))
1041                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1042   "TARGET_MULHW"
1043   "machhwu %0, %1, %2"
1044   [(set_attr "type" "imul3")])
1045
1046 (define_insn "*maclhwc"
1047   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1048         (compare:CC (plus:SI (mult:SI (sign_extend:SI
1049                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1050                                       (sign_extend:SI
1051                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1052                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1053                     (const_int 0)))
1054    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1055         (plus:SI (mult:SI (sign_extend:SI
1056                            (match_dup 1))
1057                           (sign_extend:SI
1058                            (match_dup 2)))
1059                  (match_dup 4)))]
1060   "TARGET_MULHW"
1061   "maclhw. %0, %1, %2"
1062   [(set_attr "type" "imul3")])
1063
1064 (define_insn "*maclhw"
1065   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1066         (plus:SI (mult:SI (sign_extend:SI
1067                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1068                           (sign_extend:SI
1069                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1070                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1071   "TARGET_MULHW"
1072   "maclhw %0, %1, %2"
1073   [(set_attr "type" "imul3")])
1074
1075 (define_insn "*maclhwuc"
1076   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1077         (compare:CC (plus:SI (mult:SI (zero_extend:SI
1078                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1079                                       (zero_extend:SI
1080                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1081                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1082                     (const_int 0)))
1083    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1084         (plus:SI (mult:SI (zero_extend:SI
1085                            (match_dup 1))
1086                           (zero_extend:SI
1087                            (match_dup 2)))
1088                  (match_dup 4)))]
1089   "TARGET_MULHW"
1090   "maclhwu. %0, %1, %2"
1091   [(set_attr "type" "imul3")])
1092
1093 (define_insn "*maclhwu"
1094   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1095         (plus:SI (mult:SI (zero_extend:SI
1096                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1097                           (zero_extend:SI
1098                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1099                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1100   "TARGET_MULHW"
1101   "maclhwu %0, %1, %2"
1102   [(set_attr "type" "imul3")])
1103
1104 (define_insn "*nmacchwc"
1105   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1106         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1107                               (mult:SI (ashiftrt:SI
1108                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1109                                         (const_int 16))
1110                                        (sign_extend:SI
1111                                         (match_operand:HI 1 "gpc_reg_operand" "r"))))
1112                     (const_int 0)))
1113    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1114         (minus:SI (match_dup 4)
1115                   (mult:SI (ashiftrt:SI
1116                             (match_dup 2)
1117                             (const_int 16))
1118                            (sign_extend:SI
1119                             (match_dup 1)))))]
1120   "TARGET_MULHW"
1121   "nmacchw. %0, %1, %2"
1122   [(set_attr "type" "imul3")])
1123
1124 (define_insn "*nmacchw"
1125   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1126         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1127                   (mult:SI (ashiftrt:SI
1128                             (match_operand:SI 2 "gpc_reg_operand" "r")
1129                             (const_int 16))
1130                            (sign_extend:SI
1131                             (match_operand:HI 1 "gpc_reg_operand" "r")))))]
1132   "TARGET_MULHW"
1133   "nmacchw %0, %1, %2"
1134   [(set_attr "type" "imul3")])
1135
1136 (define_insn "*nmachhwc"
1137   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1138         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1139                               (mult:SI (ashiftrt:SI
1140                                         (match_operand:SI 1 "gpc_reg_operand" "%r")
1141                                         (const_int 16))
1142                                        (ashiftrt:SI
1143                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1144                                         (const_int 16))))
1145                     (const_int 0)))
1146    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1147         (minus:SI (match_dup 4)
1148                   (mult:SI (ashiftrt:SI
1149                             (match_dup 1)
1150                             (const_int 16))
1151                            (ashiftrt:SI
1152                             (match_dup 2)
1153                             (const_int 16)))))]
1154   "TARGET_MULHW"
1155   "nmachhw. %0, %1, %2"
1156   [(set_attr "type" "imul3")])
1157
1158 (define_insn "*nmachhw"
1159   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1160         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1161                   (mult:SI (ashiftrt:SI
1162                             (match_operand:SI 1 "gpc_reg_operand" "%r")
1163                             (const_int 16))
1164                            (ashiftrt:SI
1165                             (match_operand:SI 2 "gpc_reg_operand" "r")
1166                             (const_int 16)))))]
1167   "TARGET_MULHW"
1168   "nmachhw %0, %1, %2"
1169   [(set_attr "type" "imul3")])
1170
1171 (define_insn "*nmaclhwc"
1172   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1173         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1174                               (mult:SI (sign_extend:SI
1175                                         (match_operand:HI 1 "gpc_reg_operand" "%r"))
1176                                        (sign_extend:SI
1177                                         (match_operand:HI 2 "gpc_reg_operand" "r"))))
1178                     (const_int 0)))
1179    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1180         (minus:SI (match_dup 4)
1181                   (mult:SI (sign_extend:SI
1182                             (match_dup 1))
1183                            (sign_extend:SI
1184                             (match_dup 2)))))]
1185   "TARGET_MULHW"
1186   "nmaclhw. %0, %1, %2"
1187   [(set_attr "type" "imul3")])
1188
1189 (define_insn "*nmaclhw"
1190   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1191         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1192                   (mult:SI (sign_extend:SI
1193                             (match_operand:HI 1 "gpc_reg_operand" "%r"))
1194                            (sign_extend:SI
1195                             (match_operand:HI 2 "gpc_reg_operand" "r")))))]
1196   "TARGET_MULHW"
1197   "nmaclhw %0, %1, %2"
1198   [(set_attr "type" "imul3")])
1199
1200 (define_insn "*mulchwc"
1201   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1202         (compare:CC (mult:SI (ashiftrt:SI
1203                               (match_operand:SI 2 "gpc_reg_operand" "r")
1204                               (const_int 16))
1205                              (sign_extend:SI
1206                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1207                     (const_int 0)))
1208    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1209         (mult:SI (ashiftrt:SI
1210                   (match_dup 2)
1211                   (const_int 16))
1212                  (sign_extend:SI
1213                   (match_dup 1))))]
1214   "TARGET_MULHW"
1215   "mulchw. %0, %1, %2"
1216   [(set_attr "type" "imul3")])
1217
1218 (define_insn "*mulchw"
1219   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1220         (mult:SI (ashiftrt:SI
1221                   (match_operand:SI 2 "gpc_reg_operand" "r")
1222                   (const_int 16))
1223                  (sign_extend:SI
1224                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1225   "TARGET_MULHW"
1226   "mulchw %0, %1, %2"
1227   [(set_attr "type" "imul3")])
1228
1229 (define_insn "*mulchwuc"
1230   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1231         (compare:CC (mult:SI (lshiftrt:SI
1232                               (match_operand:SI 2 "gpc_reg_operand" "r")
1233                               (const_int 16))
1234                              (zero_extend:SI
1235                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1236                     (const_int 0)))
1237    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1238         (mult:SI (lshiftrt:SI
1239                   (match_dup 2)
1240                   (const_int 16))
1241                  (zero_extend:SI
1242                   (match_dup 1))))]
1243   "TARGET_MULHW"
1244   "mulchwu. %0, %1, %2"
1245   [(set_attr "type" "imul3")])
1246
1247 (define_insn "*mulchwu"
1248   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1249         (mult:SI (lshiftrt:SI
1250                   (match_operand:SI 2 "gpc_reg_operand" "r")
1251                   (const_int 16))
1252                  (zero_extend:SI
1253                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1254   "TARGET_MULHW"
1255   "mulchwu %0, %1, %2"
1256   [(set_attr "type" "imul3")])
1257
1258 (define_insn "*mulhhwc"
1259   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1260         (compare:CC (mult:SI (ashiftrt:SI
1261                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1262                               (const_int 16))
1263                              (ashiftrt:SI
1264                               (match_operand:SI 2 "gpc_reg_operand" "r")
1265                               (const_int 16)))
1266                     (const_int 0)))
1267    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1268         (mult:SI (ashiftrt:SI
1269                   (match_dup 1)
1270                   (const_int 16))
1271                  (ashiftrt:SI
1272                   (match_dup 2)
1273                   (const_int 16))))]
1274   "TARGET_MULHW"
1275   "mulhhw. %0, %1, %2"
1276   [(set_attr "type" "imul3")])
1277
1278 (define_insn "*mulhhw"
1279   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1280         (mult:SI (ashiftrt:SI
1281                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1282                   (const_int 16))
1283                  (ashiftrt:SI
1284                   (match_operand:SI 2 "gpc_reg_operand" "r")
1285                   (const_int 16))))]
1286   "TARGET_MULHW"
1287   "mulhhw %0, %1, %2"
1288   [(set_attr "type" "imul3")])
1289
1290 (define_insn "*mulhhwuc"
1291   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1292         (compare:CC (mult:SI (lshiftrt:SI
1293                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1294                               (const_int 16))
1295                              (lshiftrt:SI
1296                               (match_operand:SI 2 "gpc_reg_operand" "r")
1297                               (const_int 16)))
1298                     (const_int 0)))
1299    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1300         (mult:SI (lshiftrt:SI
1301                   (match_dup 1)
1302                   (const_int 16))
1303                  (lshiftrt:SI
1304                   (match_dup 2)
1305                   (const_int 16))))]
1306   "TARGET_MULHW"
1307   "mulhhwu. %0, %1, %2"
1308   [(set_attr "type" "imul3")])
1309
1310 (define_insn "*mulhhwu"
1311   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1312         (mult:SI (lshiftrt:SI
1313                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1314                   (const_int 16))
1315                  (lshiftrt:SI
1316                   (match_operand:SI 2 "gpc_reg_operand" "r")
1317                   (const_int 16))))]
1318   "TARGET_MULHW"
1319   "mulhhwu %0, %1, %2"
1320   [(set_attr "type" "imul3")])
1321
1322 (define_insn "*mullhwc"
1323   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1324         (compare:CC (mult:SI (sign_extend:SI
1325                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1326                              (sign_extend:SI
1327                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1328                     (const_int 0)))
1329    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1330         (mult:SI (sign_extend:SI
1331                   (match_dup 1))
1332                  (sign_extend:SI
1333                   (match_dup 2))))]
1334   "TARGET_MULHW"
1335   "mullhw. %0, %1, %2"
1336   [(set_attr "type" "imul3")])
1337
1338 (define_insn "*mullhw"
1339   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1340         (mult:SI (sign_extend:SI
1341                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1342                  (sign_extend:SI
1343                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1344   "TARGET_MULHW"
1345   "mullhw %0, %1, %2"
1346   [(set_attr "type" "imul3")])
1347
1348 (define_insn "*mullhwuc"
1349   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1350         (compare:CC (mult:SI (zero_extend:SI
1351                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1352                              (zero_extend:SI
1353                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1354                     (const_int 0)))
1355    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1356         (mult:SI (zero_extend:SI
1357                   (match_dup 1))
1358                  (zero_extend:SI
1359                   (match_dup 2))))]
1360   "TARGET_MULHW"
1361   "mullhwu. %0, %1, %2"
1362   [(set_attr "type" "imul3")])
1363
1364 (define_insn "*mullhwu"
1365   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1366         (mult:SI (zero_extend:SI
1367                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1368                  (zero_extend:SI
1369                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1370   "TARGET_MULHW"
1371   "mullhwu %0, %1, %2"
1372   [(set_attr "type" "imul3")])
1373 \f
1374 ;; IBM 405 and 440 string-search dlmzb instruction support.
1375 (define_insn "dlmzb"
1376   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1377         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
1378                     (match_operand:SI 2 "gpc_reg_operand" "r")]
1379                    UNSPEC_DLMZB_CR))
1380    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1381         (unspec:SI [(match_dup 1)
1382                     (match_dup 2)]
1383                    UNSPEC_DLMZB))]
1384   "TARGET_DLMZB"
1385   "dlmzb. %0, %1, %2")
1386
1387 (define_expand "strlensi"
1388   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1389         (unspec:SI [(match_operand:BLK 1 "general_operand" "")
1390                     (match_operand:QI 2 "const_int_operand" "")
1391                     (match_operand 3 "const_int_operand" "")]
1392                    UNSPEC_DLMZB_STRLEN))
1393    (clobber (match_scratch:CC 4 "=x"))]
1394   "TARGET_DLMZB && WORDS_BIG_ENDIAN && !optimize_size"
1395 {
1396   rtx result = operands[0];
1397   rtx src = operands[1];
1398   rtx search_char = operands[2];
1399   rtx align = operands[3];
1400   rtx addr, scratch_string, word1, word2, scratch_dlmzb;
1401   rtx loop_label, end_label, mem, cr0, cond;
1402   if (search_char != const0_rtx
1403       || GET_CODE (align) != CONST_INT
1404       || INTVAL (align) < 8)
1405         FAIL;
1406   word1 = gen_reg_rtx (SImode);
1407   word2 = gen_reg_rtx (SImode);
1408   scratch_dlmzb = gen_reg_rtx (SImode);
1409   scratch_string = gen_reg_rtx (Pmode);
1410   loop_label = gen_label_rtx ();
1411   end_label = gen_label_rtx ();
1412   addr = force_reg (Pmode, XEXP (src, 0));
1413   emit_move_insn (scratch_string, addr);
1414   emit_label (loop_label);
1415   mem = change_address (src, SImode, scratch_string);
1416   emit_move_insn (word1, mem);
1417   emit_move_insn (word2, adjust_address (mem, SImode, 4));
1418   cr0 = gen_rtx_REG (CCmode, CR0_REGNO);
1419   emit_insn (gen_dlmzb (scratch_dlmzb, word1, word2, cr0));
1420   cond = gen_rtx_NE (VOIDmode, cr0, const0_rtx);
1421   emit_jump_insn (gen_rtx_SET (VOIDmode,
1422                                pc_rtx,
1423                                gen_rtx_IF_THEN_ELSE (VOIDmode,
1424                                                      cond,
1425                                                      gen_rtx_LABEL_REF
1426                                                        (VOIDmode,
1427                                                         end_label),
1428                                                      pc_rtx)));
1429   emit_insn (gen_addsi3 (scratch_string, scratch_string, GEN_INT (8)));
1430   emit_jump_insn (gen_rtx_SET (VOIDmode,
1431                                pc_rtx,
1432                                gen_rtx_LABEL_REF (VOIDmode, loop_label)));
1433   emit_barrier ();
1434   emit_label (end_label);
1435   emit_insn (gen_addsi3 (scratch_string, scratch_string, scratch_dlmzb));
1436   emit_insn (gen_subsi3 (result, scratch_string, addr));
1437   emit_insn (gen_subsi3 (result, result, const1_rtx));
1438   DONE;
1439 })
1440 \f
1441 (define_split
1442   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1443         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1444                     (const_int 0)))
1445    (set (match_operand:SI 0 "gpc_reg_operand" "")
1446         (sign_extend:SI (match_dup 1)))]
1447   "reload_completed"
1448   [(set (match_dup 0)
1449         (sign_extend:SI (match_dup 1)))
1450    (set (match_dup 2)
1451         (compare:CC (match_dup 0)
1452                     (const_int 0)))]
1453   "")
1454
1455 ;; Fixed-point arithmetic insns.
1456
1457 (define_expand "add<mode>3"
1458   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1459         (plus:SDI (match_operand:SDI 1 "gpc_reg_operand" "")
1460                   (match_operand:SDI 2 "reg_or_add_cint_operand" "")))]
1461   ""
1462 {
1463   if (<MODE>mode == DImode && ! TARGET_POWERPC64)
1464     {
1465       if (non_short_cint_operand (operands[2], DImode))
1466         FAIL;
1467     }
1468   else if (GET_CODE (operands[2]) == CONST_INT
1469            && ! add_operand (operands[2], <MODE>mode))
1470     {
1471       rtx tmp = ((!can_create_pseudo_p ()
1472                   || rtx_equal_p (operands[0], operands[1]))
1473                  ? operands[0] : gen_reg_rtx (<MODE>mode));
1474
1475       HOST_WIDE_INT val = INTVAL (operands[2]);
1476       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1477       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1478
1479       if (<MODE>mode == DImode && !satisfies_constraint_L (GEN_INT (rest)))
1480         FAIL;
1481
1482       /* The ordering here is important for the prolog expander.
1483          When space is allocated from the stack, adding 'low' first may
1484          produce a temporary deallocation (which would be bad).  */
1485       emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1486       emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1487       DONE;
1488     }
1489 })
1490
1491 ;; Discourage ai/addic because of carry but provide it in an alternative
1492 ;; allowing register zero as source.
1493 (define_insn "*add<mode>3_internal1"
1494   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,?r,r")
1495         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,r,b")
1496                   (match_operand:GPR 2 "add_operand" "r,I,I,L")))]
1497   "!DECIMAL_FLOAT_MODE_P (GET_MODE (operands[0])) && !DECIMAL_FLOAT_MODE_P (GET_MODE (operands[1]))"
1498   "@
1499    {cax|add} %0,%1,%2
1500    {cal %0,%2(%1)|addi %0,%1,%2}
1501    {ai|addic} %0,%1,%2
1502    {cau|addis} %0,%1,%v2"
1503   [(set_attr "length" "4,4,4,4")])
1504
1505 (define_insn "addsi3_high"
1506   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1507         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1508                  (high:SI (match_operand 2 "" ""))))]
1509   "TARGET_MACHO && !TARGET_64BIT"
1510   "{cau|addis} %0,%1,ha16(%2)"
1511   [(set_attr "length" "4")])
1512
1513 (define_insn "*add<mode>3_internal2"
1514   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1515         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1516                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1517                     (const_int 0)))
1518    (clobber (match_scratch:P 3 "=r,r,r,r"))]
1519   ""
1520   "@
1521    {cax.|add.} %3,%1,%2
1522    {ai.|addic.} %3,%1,%2
1523    #
1524    #"
1525   [(set_attr "type" "fast_compare,compare,compare,compare")
1526    (set_attr "length" "4,4,8,8")])
1527
1528 (define_split
1529   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1530         (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1531                               (match_operand:GPR 2 "reg_or_short_operand" ""))
1532                     (const_int 0)))
1533    (clobber (match_scratch:GPR 3 ""))]
1534   "reload_completed"
1535   [(set (match_dup 3)
1536         (plus:GPR (match_dup 1)
1537                  (match_dup 2)))
1538    (set (match_dup 0)
1539         (compare:CC (match_dup 3)
1540                     (const_int 0)))]
1541   "")
1542
1543 (define_insn "*add<mode>3_internal3"
1544   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1545         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1546                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1547                     (const_int 0)))
1548    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
1549         (plus:P (match_dup 1)
1550                 (match_dup 2)))]
1551   ""
1552   "@
1553    {cax.|add.} %0,%1,%2
1554    {ai.|addic.} %0,%1,%2
1555    #
1556    #"
1557   [(set_attr "type" "fast_compare,compare,compare,compare")
1558    (set_attr "length" "4,4,8,8")])
1559
1560 (define_split
1561   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1562         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "")
1563                             (match_operand:P 2 "reg_or_short_operand" ""))
1564                     (const_int 0)))
1565    (set (match_operand:P 0 "gpc_reg_operand" "")
1566         (plus:P (match_dup 1) (match_dup 2)))]
1567   "reload_completed"
1568   [(set (match_dup 0)
1569         (plus:P (match_dup 1)
1570                 (match_dup 2)))
1571    (set (match_dup 3)
1572         (compare:CC (match_dup 0)
1573                     (const_int 0)))]
1574   "")
1575
1576 ;; Split an add that we can't do in one insn into two insns, each of which
1577 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1578 ;; add should be last in case the result gets used in an address.
1579
1580 (define_split
1581   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1582         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1583                   (match_operand:GPR 2 "non_add_cint_operand" "")))]
1584   ""
1585   [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1586    (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
1587 {
1588   HOST_WIDE_INT val = INTVAL (operands[2]);
1589   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1590   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1591
1592   operands[4] = GEN_INT (low);
1593   if (<MODE>mode == SImode || satisfies_constraint_L (GEN_INT (rest)))
1594     operands[3] = GEN_INT (rest);
1595   else if (can_create_pseudo_p ())
1596     {
1597       operands[3] = gen_reg_rtx (DImode);
1598       emit_move_insn (operands[3], operands[2]);
1599       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
1600       DONE;
1601     }
1602   else
1603     FAIL;
1604 })
1605
1606 (define_insn "one_cmpl<mode>2"
1607   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1608         (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1609   ""
1610   "nor %0,%1,%1")
1611
1612 (define_insn ""
1613   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1614         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1615                     (const_int 0)))
1616    (clobber (match_scratch:P 2 "=r,r"))]
1617   ""
1618   "@
1619    nor. %2,%1,%1
1620    #"
1621   [(set_attr "type" "compare")
1622    (set_attr "length" "4,8")])
1623
1624 (define_split
1625   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1626         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1627                     (const_int 0)))
1628    (clobber (match_scratch:P 2 ""))]
1629   "reload_completed"
1630   [(set (match_dup 2)
1631         (not:P (match_dup 1)))
1632    (set (match_dup 0)
1633         (compare:CC (match_dup 2)
1634                     (const_int 0)))]
1635   "")
1636
1637 (define_insn ""
1638   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1639         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1640                     (const_int 0)))
1641    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1642         (not:P (match_dup 1)))]
1643   ""
1644   "@
1645    nor. %0,%1,%1
1646    #"
1647   [(set_attr "type" "compare")
1648    (set_attr "length" "4,8")])
1649
1650 (define_split
1651   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1652         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1653                     (const_int 0)))
1654    (set (match_operand:P 0 "gpc_reg_operand" "")
1655         (not:P (match_dup 1)))]
1656   "reload_completed"
1657   [(set (match_dup 0)
1658         (not:P (match_dup 1)))
1659    (set (match_dup 2)
1660         (compare:CC (match_dup 0)
1661                     (const_int 0)))]
1662   "")
1663
1664 (define_insn ""
1665   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1666         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
1667                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
1668   "! TARGET_POWERPC"
1669   "{sf%I1|subf%I1c} %0,%2,%1")
1670
1671 (define_insn ""
1672   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
1673         (minus:GPR (match_operand:GPR 1 "reg_or_short_operand" "r,I")
1674                    (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
1675   "TARGET_POWERPC"
1676   "@
1677    subf %0,%2,%1
1678    subfic %0,%2,%1")
1679
1680 (define_insn ""
1681   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1682         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1683                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1684                     (const_int 0)))
1685    (clobber (match_scratch:SI 3 "=r,r"))]
1686   "! TARGET_POWERPC"
1687   "@
1688    {sf.|subfc.} %3,%2,%1
1689    #"
1690   [(set_attr "type" "compare")
1691    (set_attr "length" "4,8")])
1692
1693 (define_insn ""
1694   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1695         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1696                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1697                     (const_int 0)))
1698    (clobber (match_scratch:P 3 "=r,r"))]
1699   "TARGET_POWERPC"
1700   "@
1701    subf. %3,%2,%1
1702    #"
1703   [(set_attr "type" "fast_compare")
1704    (set_attr "length" "4,8")])
1705
1706 (define_split
1707   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1708         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1709                              (match_operand:P 2 "gpc_reg_operand" ""))
1710                     (const_int 0)))
1711    (clobber (match_scratch:P 3 ""))]
1712   "reload_completed"
1713   [(set (match_dup 3)
1714         (minus:P (match_dup 1)
1715                   (match_dup 2)))
1716    (set (match_dup 0)
1717         (compare:CC (match_dup 3)
1718                     (const_int 0)))]
1719   "")
1720
1721 (define_insn ""
1722   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1723         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1724                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1725                     (const_int 0)))
1726    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1727         (minus:SI (match_dup 1) (match_dup 2)))]
1728   "! TARGET_POWERPC"
1729   "@
1730    {sf.|subfc.} %0,%2,%1
1731    #"
1732   [(set_attr "type" "compare")
1733    (set_attr "length" "4,8")])
1734
1735 (define_insn ""
1736   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1737         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1738                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1739                     (const_int 0)))
1740    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1741         (minus:P (match_dup 1)
1742                   (match_dup 2)))]
1743   "TARGET_POWERPC"
1744   "@
1745    subf. %0,%2,%1
1746    #"
1747   [(set_attr "type" "fast_compare")
1748    (set_attr "length" "4,8")])
1749
1750 (define_split
1751   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1752         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1753                              (match_operand:P 2 "gpc_reg_operand" ""))
1754                     (const_int 0)))
1755    (set (match_operand:P 0 "gpc_reg_operand" "")
1756         (minus:P (match_dup 1)
1757                   (match_dup 2)))]
1758   "reload_completed"
1759   [(set (match_dup 0)
1760         (minus:P (match_dup 1)
1761                   (match_dup 2)))
1762    (set (match_dup 3)
1763         (compare:CC (match_dup 0)
1764                     (const_int 0)))]
1765   "")
1766
1767 (define_expand "sub<mode>3"
1768   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1769         (minus:SDI (match_operand:SDI 1 "reg_or_short_operand" "")
1770                    (match_operand:SDI 2 "reg_or_sub_cint_operand" "")))]
1771   ""
1772   "
1773 {
1774   if (GET_CODE (operands[2]) == CONST_INT)
1775     {
1776       emit_insn (gen_add<mode>3 (operands[0], operands[1],
1777                                  negate_rtx (<MODE>mode, operands[2])));
1778       DONE;
1779     }
1780 }")
1781
1782 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1783 ;; instruction and some auxiliary computations.  Then we just have a single
1784 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1785 ;; combine.
1786
1787 (define_expand "sminsi3"
1788   [(set (match_dup 3)
1789         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1790                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1791                          (const_int 0)
1792                          (minus:SI (match_dup 2) (match_dup 1))))
1793    (set (match_operand:SI 0 "gpc_reg_operand" "")
1794         (minus:SI (match_dup 2) (match_dup 3)))]
1795   "TARGET_POWER || TARGET_ISEL"
1796   "
1797 {
1798   if (TARGET_ISEL)
1799     {
1800       operands[2] = force_reg (SImode, operands[2]);
1801       rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
1802       DONE;
1803     }
1804
1805   operands[3] = gen_reg_rtx (SImode);
1806 }")
1807
1808 (define_split
1809   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1810         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1811                  (match_operand:SI 2 "reg_or_short_operand" "")))
1812    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1813   "TARGET_POWER"
1814   [(set (match_dup 3)
1815         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1816                          (const_int 0)
1817                          (minus:SI (match_dup 2) (match_dup 1))))
1818    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1819   "")
1820
1821 (define_expand "smaxsi3"
1822   [(set (match_dup 3)
1823         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1824                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1825                          (const_int 0)
1826                          (minus:SI (match_dup 2) (match_dup 1))))
1827    (set (match_operand:SI 0 "gpc_reg_operand" "")
1828         (plus:SI (match_dup 3) (match_dup 1)))]
1829   "TARGET_POWER || TARGET_ISEL"
1830   "
1831 {
1832   if (TARGET_ISEL)
1833     {
1834       operands[2] = force_reg (SImode, operands[2]);
1835       rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
1836       DONE;
1837     }
1838   operands[3] = gen_reg_rtx (SImode);
1839 }")
1840
1841 (define_split
1842   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1843         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1844                  (match_operand:SI 2 "reg_or_short_operand" "")))
1845    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1846   "TARGET_POWER"
1847   [(set (match_dup 3)
1848         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1849                          (const_int 0)
1850                          (minus:SI (match_dup 2) (match_dup 1))))
1851    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1852   "")
1853
1854 (define_expand "uminsi3"
1855   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1856                               (match_dup 5)))
1857    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1858                               (match_dup 5)))
1859    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1860                                        (const_int 0)
1861                                        (minus:SI (match_dup 4) (match_dup 3))))
1862    (set (match_operand:SI 0 "gpc_reg_operand" "")
1863         (minus:SI (match_dup 2) (match_dup 3)))]
1864   "TARGET_POWER || TARGET_ISEL"
1865   "
1866 {
1867   if (TARGET_ISEL)
1868     {
1869       rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
1870       DONE;
1871     }
1872   operands[3] = gen_reg_rtx (SImode);
1873   operands[4] = gen_reg_rtx (SImode);
1874   operands[5] = GEN_INT (-2147483647 - 1);
1875 }")
1876
1877 (define_expand "umaxsi3"
1878   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1879                               (match_dup 5)))
1880    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1881                               (match_dup 5)))
1882    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1883                                        (const_int 0)
1884                                        (minus:SI (match_dup 4) (match_dup 3))))
1885    (set (match_operand:SI 0 "gpc_reg_operand" "")
1886         (plus:SI (match_dup 3) (match_dup 1)))]
1887   "TARGET_POWER || TARGET_ISEL"
1888   "
1889 {
1890   if (TARGET_ISEL)
1891     {
1892       rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
1893       DONE;
1894     }
1895   operands[3] = gen_reg_rtx (SImode);
1896   operands[4] = gen_reg_rtx (SImode);
1897   operands[5] = GEN_INT (-2147483647 - 1);
1898 }")
1899
1900 (define_insn ""
1901   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1902         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1903                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
1904                          (const_int 0)
1905                          (minus:SI (match_dup 2) (match_dup 1))))]
1906   "TARGET_POWER"
1907   "doz%I2 %0,%1,%2")
1908
1909 (define_insn ""
1910   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1911         (compare:CC
1912          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1913                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1914                           (const_int 0)
1915                           (minus:SI (match_dup 2) (match_dup 1)))
1916          (const_int 0)))
1917    (clobber (match_scratch:SI 3 "=r,r"))]
1918   "TARGET_POWER"
1919   "@
1920    doz%I2. %3,%1,%2
1921    #"
1922   [(set_attr "type" "delayed_compare")
1923    (set_attr "length" "4,8")])
1924
1925 (define_split
1926   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1927         (compare:CC
1928          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1929                               (match_operand:SI 2 "reg_or_short_operand" ""))
1930                           (const_int 0)
1931                           (minus:SI (match_dup 2) (match_dup 1)))
1932          (const_int 0)))
1933    (clobber (match_scratch:SI 3 ""))]
1934   "TARGET_POWER && reload_completed"
1935   [(set (match_dup 3)
1936         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1937                           (const_int 0)
1938                           (minus:SI (match_dup 2) (match_dup 1))))
1939    (set (match_dup 0)
1940         (compare:CC (match_dup 3)
1941                     (const_int 0)))]
1942   "")
1943
1944 (define_insn ""
1945   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1946         (compare:CC
1947          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1948                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1949                           (const_int 0)
1950                           (minus:SI (match_dup 2) (match_dup 1)))
1951          (const_int 0)))
1952    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1953         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1954                          (const_int 0)
1955                          (minus:SI (match_dup 2) (match_dup 1))))]
1956   "TARGET_POWER"
1957   "@
1958    doz%I2. %0,%1,%2
1959    #"
1960   [(set_attr "type" "delayed_compare")
1961    (set_attr "length" "4,8")])
1962
1963 (define_split
1964   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1965         (compare:CC
1966          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1967                               (match_operand:SI 2 "reg_or_short_operand" ""))
1968                           (const_int 0)
1969                           (minus:SI (match_dup 2) (match_dup 1)))
1970          (const_int 0)))
1971    (set (match_operand:SI 0 "gpc_reg_operand" "")
1972         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1973                          (const_int 0)
1974                          (minus:SI (match_dup 2) (match_dup 1))))]
1975   "TARGET_POWER && reload_completed"
1976   [(set (match_dup 0)
1977         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1978                          (const_int 0)
1979                          (minus:SI (match_dup 2) (match_dup 1))))
1980    (set (match_dup 3)
1981         (compare:CC (match_dup 0)
1982                     (const_int 0)))]
1983   "")
1984
1985 ;; We don't need abs with condition code because such comparisons should
1986 ;; never be done.
1987 (define_expand "abssi2"
1988   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1989         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
1990   ""
1991   "
1992 {
1993   if (TARGET_ISEL)
1994     {
1995       emit_insn (gen_abssi2_isel (operands[0], operands[1]));
1996       DONE;
1997     }
1998   else if (! TARGET_POWER)
1999     {
2000       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
2001       DONE;
2002     }
2003 }")
2004
2005 (define_insn "*abssi2_power"
2006   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2007         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
2008   "TARGET_POWER"
2009   "abs %0,%1")
2010
2011 (define_insn_and_split "abssi2_isel"
2012   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2013         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
2014    (clobber (match_scratch:SI 2 "=&b"))
2015    (clobber (match_scratch:CC 3 "=y"))]
2016   "TARGET_ISEL"
2017   "#"
2018   "&& reload_completed"
2019   [(set (match_dup 2) (neg:SI (match_dup 1)))
2020    (set (match_dup 3)
2021         (compare:CC (match_dup 1)
2022                     (const_int 0)))
2023    (set (match_dup 0)
2024         (if_then_else:SI (ge (match_dup 3)
2025                              (const_int 0))
2026                          (match_dup 1)
2027                          (match_dup 2)))]
2028   "")
2029
2030 (define_insn_and_split "abssi2_nopower"
2031   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
2032         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
2033    (clobber (match_scratch:SI 2 "=&r,&r"))]
2034   "! TARGET_POWER && ! TARGET_ISEL"
2035   "#"
2036   "&& reload_completed"
2037   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
2038    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
2039    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
2040   "")
2041
2042 (define_insn "*nabs_power"
2043   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2044         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
2045   "TARGET_POWER"
2046   "nabs %0,%1")
2047
2048 (define_insn_and_split "*nabs_nopower"
2049   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
2050         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
2051    (clobber (match_scratch:SI 2 "=&r,&r"))]
2052   "! TARGET_POWER"
2053   "#"
2054   "&& reload_completed"
2055   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
2056    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
2057    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
2058   "")
2059
2060 (define_expand "neg<mode>2"
2061   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
2062         (neg:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
2063   ""
2064   "")
2065
2066 (define_insn "*neg<mode>2_internal"
2067   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2068         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2069   ""
2070   "neg %0,%1")
2071
2072 (define_insn ""
2073   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2074         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2075                     (const_int 0)))
2076    (clobber (match_scratch:P 2 "=r,r"))]
2077   ""
2078   "@
2079    neg. %2,%1
2080    #"
2081   [(set_attr "type" "fast_compare")
2082    (set_attr "length" "4,8")])
2083
2084 (define_split
2085   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2086         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2087                     (const_int 0)))
2088    (clobber (match_scratch:P 2 ""))]
2089   "reload_completed"
2090   [(set (match_dup 2)
2091         (neg:P (match_dup 1)))
2092    (set (match_dup 0)
2093         (compare:CC (match_dup 2)
2094                     (const_int 0)))]
2095   "")
2096
2097 (define_insn ""
2098   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2099         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2100                     (const_int 0)))
2101    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2102         (neg:P (match_dup 1)))]
2103   ""
2104   "@
2105    neg. %0,%1
2106    #"
2107   [(set_attr "type" "fast_compare")
2108    (set_attr "length" "4,8")])
2109
2110 (define_split
2111   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
2112         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2113                     (const_int 0)))
2114    (set (match_operand:P 0 "gpc_reg_operand" "")
2115         (neg:P (match_dup 1)))]
2116   "reload_completed"
2117   [(set (match_dup 0)
2118         (neg:P (match_dup 1)))
2119    (set (match_dup 2)
2120         (compare:CC (match_dup 0)
2121                     (const_int 0)))]
2122   "")
2123
2124 (define_insn "clz<mode>2"
2125   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2126         (clz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2127   ""
2128   "{cntlz|cntlz<wd>} %0,%1"
2129   [(set_attr "type" "cntlz")])
2130
2131 (define_expand "ctz<mode>2"
2132   [(set (match_dup 2)
2133         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2134    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2135                                           (match_dup 2)))
2136               (clobber (scratch:CC))])
2137    (set (match_dup 4) (clz:GPR (match_dup 3)))
2138    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2139         (minus:GPR (match_dup 5) (match_dup 4)))]
2140   ""
2141   {
2142      operands[2] = gen_reg_rtx (<MODE>mode);
2143      operands[3] = gen_reg_rtx (<MODE>mode);
2144      operands[4] = gen_reg_rtx (<MODE>mode);
2145      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 1);
2146   })
2147
2148 (define_expand "ffs<mode>2"
2149   [(set (match_dup 2)
2150         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2151    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2152                                           (match_dup 2)))
2153               (clobber (scratch:CC))])
2154    (set (match_dup 4) (clz:GPR (match_dup 3)))
2155    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2156         (minus:GPR (match_dup 5) (match_dup 4)))]
2157   ""
2158   {
2159      operands[2] = gen_reg_rtx (<MODE>mode);
2160      operands[3] = gen_reg_rtx (<MODE>mode);
2161      operands[4] = gen_reg_rtx (<MODE>mode);
2162      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
2163   })
2164
2165 (define_insn "popcntb<mode>2"
2166   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2167         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
2168                      UNSPEC_POPCNTB))]
2169   "TARGET_POPCNTB"
2170   "popcntb %0,%1")
2171
2172 (define_expand "popcount<mode>2"
2173   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2174         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2175   "TARGET_POPCNTB"
2176   {
2177     rs6000_emit_popcount (operands[0], operands[1]);
2178     DONE;
2179   })
2180
2181 (define_expand "parity<mode>2"
2182   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2183         (parity:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2184   "TARGET_POPCNTB"
2185   {
2186     rs6000_emit_parity (operands[0], operands[1]);
2187     DONE;
2188   })
2189
2190 (define_insn "bswapsi2"
2191   [(set (match_operand:SI 0 "reg_or_mem_operand" "=r,Z,&r")
2192         (bswap:SI (match_operand:SI 1 "reg_or_mem_operand" "Z,r,r")))]
2193   ""
2194   "@
2195    {lbrx|lwbrx} %0,%y1
2196    {stbrx|stwbrx} %1,%y0
2197    #"
2198   [(set_attr "length" "4,4,12")])
2199
2200 (define_split
2201   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2202         (bswap:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
2203   "reload_completed"
2204   [(set (match_dup 0)
2205         (rotate:SI (match_dup 1) (const_int 8)))
2206    (set (zero_extract:SI (match_dup 0)
2207                          (const_int 8)
2208                          (const_int 0))
2209         (match_dup 1))
2210    (set (zero_extract:SI (match_dup 0)
2211                          (const_int 8)
2212                          (const_int 16))
2213         (rotate:SI (match_dup 1)
2214                    (const_int 16)))]
2215   "")
2216
2217 (define_expand "mulsi3"
2218   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2219    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2220    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
2221   ""
2222   "
2223 {
2224   if (TARGET_POWER)
2225     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
2226   else
2227     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
2228   DONE;
2229 }")
2230
2231 (define_insn "mulsi3_mq"
2232   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2233         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2234                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
2235    (clobber (match_scratch:SI 3 "=q,q"))]
2236   "TARGET_POWER"
2237   "@
2238    {muls|mullw} %0,%1,%2
2239    {muli|mulli} %0,%1,%2"
2240    [(set (attr "type")
2241       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2242                 (const_string "imul3")
2243              (match_operand:SI 2 "short_cint_operand" "")
2244                 (const_string "imul2")]
2245         (const_string "imul")))])
2246
2247 (define_insn "mulsi3_no_mq"
2248   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2249         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2250                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
2251   "! TARGET_POWER"
2252   "@
2253    {muls|mullw} %0,%1,%2
2254    {muli|mulli} %0,%1,%2"
2255    [(set (attr "type")
2256       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2257                 (const_string "imul3")
2258              (match_operand:SI 2 "short_cint_operand" "")
2259                 (const_string "imul2")]
2260         (const_string "imul")))])
2261
2262 (define_insn "*mulsi3_mq_internal1"
2263   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2264         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2265                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2266                     (const_int 0)))
2267    (clobber (match_scratch:SI 3 "=r,r"))
2268    (clobber (match_scratch:SI 4 "=q,q"))]
2269   "TARGET_POWER"
2270   "@
2271    {muls.|mullw.} %3,%1,%2
2272    #"
2273   [(set_attr "type" "imul_compare")
2274    (set_attr "length" "4,8")])
2275
2276 (define_split
2277   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2278         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2279                              (match_operand:SI 2 "gpc_reg_operand" ""))
2280                     (const_int 0)))
2281    (clobber (match_scratch:SI 3 ""))
2282    (clobber (match_scratch:SI 4 ""))]
2283   "TARGET_POWER && reload_completed"
2284   [(parallel [(set (match_dup 3)
2285         (mult:SI (match_dup 1) (match_dup 2)))
2286    (clobber (match_dup 4))])
2287    (set (match_dup 0)
2288         (compare:CC (match_dup 3)
2289                     (const_int 0)))]
2290   "")
2291
2292 (define_insn "*mulsi3_no_mq_internal1"
2293   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2294         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2295                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2296                     (const_int 0)))
2297    (clobber (match_scratch:SI 3 "=r,r"))]
2298   "! TARGET_POWER"
2299   "@
2300    {muls.|mullw.} %3,%1,%2
2301    #"
2302   [(set_attr "type" "imul_compare")
2303    (set_attr "length" "4,8")])
2304
2305 (define_split
2306   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2307         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2308                              (match_operand:SI 2 "gpc_reg_operand" ""))
2309                     (const_int 0)))
2310    (clobber (match_scratch:SI 3 ""))]
2311   "! TARGET_POWER && reload_completed"
2312   [(set (match_dup 3)
2313         (mult:SI (match_dup 1) (match_dup 2)))
2314    (set (match_dup 0)
2315         (compare:CC (match_dup 3)
2316                     (const_int 0)))]
2317   "")
2318
2319 (define_insn "*mulsi3_mq_internal2"
2320   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2321         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2322                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2323                     (const_int 0)))
2324    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2325         (mult:SI (match_dup 1) (match_dup 2)))
2326    (clobber (match_scratch:SI 4 "=q,q"))]
2327   "TARGET_POWER"
2328   "@
2329    {muls.|mullw.} %0,%1,%2
2330    #"
2331   [(set_attr "type" "imul_compare")
2332    (set_attr "length" "4,8")])
2333
2334 (define_split
2335   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2336         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2337                              (match_operand:SI 2 "gpc_reg_operand" ""))
2338                     (const_int 0)))
2339    (set (match_operand:SI 0 "gpc_reg_operand" "")
2340         (mult:SI (match_dup 1) (match_dup 2)))
2341    (clobber (match_scratch:SI 4 ""))]
2342   "TARGET_POWER && reload_completed"
2343   [(parallel [(set (match_dup 0)
2344         (mult:SI (match_dup 1) (match_dup 2)))
2345    (clobber (match_dup 4))])
2346    (set (match_dup 3)
2347         (compare:CC (match_dup 0)
2348                     (const_int 0)))]
2349   "")
2350
2351 (define_insn "*mulsi3_no_mq_internal2"
2352   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2353         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2354                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2355                     (const_int 0)))
2356    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2357         (mult:SI (match_dup 1) (match_dup 2)))]
2358   "! TARGET_POWER"
2359   "@
2360    {muls.|mullw.} %0,%1,%2
2361    #"
2362   [(set_attr "type" "imul_compare")
2363    (set_attr "length" "4,8")])
2364
2365 (define_split
2366   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2367         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2368                              (match_operand:SI 2 "gpc_reg_operand" ""))
2369                     (const_int 0)))
2370    (set (match_operand:SI 0 "gpc_reg_operand" "")
2371         (mult:SI (match_dup 1) (match_dup 2)))]
2372   "! TARGET_POWER && reload_completed"
2373   [(set (match_dup 0)
2374         (mult:SI (match_dup 1) (match_dup 2)))
2375    (set (match_dup 3)
2376         (compare:CC (match_dup 0)
2377                     (const_int 0)))]
2378   "")
2379
2380 ;; Operand 1 is divided by operand 2; quotient goes to operand
2381 ;; 0 and remainder to operand 3.
2382 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
2383
2384 (define_expand "divmodsi4"
2385   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2386                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2387                            (match_operand:SI 2 "gpc_reg_operand" "")))
2388               (set (match_operand:SI 3 "register_operand" "")
2389                    (mod:SI (match_dup 1) (match_dup 2)))])]
2390   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
2391   "
2392 {
2393   if (! TARGET_POWER && ! TARGET_POWERPC)
2394     {
2395       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2396       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2397       emit_insn (gen_divss_call ());
2398       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2399       emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2400       DONE;
2401     }
2402 }")
2403
2404 (define_insn "*divmodsi4_internal"
2405   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2406         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2407                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2408    (set (match_operand:SI 3 "register_operand" "=q")
2409         (mod:SI (match_dup 1) (match_dup 2)))]
2410   "TARGET_POWER"
2411   "divs %0,%1,%2"
2412   [(set_attr "type" "idiv")])
2413
2414 (define_expand "udiv<mode>3"
2415   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2416         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2417                   (match_operand:GPR 2 "gpc_reg_operand" "")))]
2418   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
2419   "
2420 {
2421   if (! TARGET_POWER && ! TARGET_POWERPC)
2422     {
2423       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2424       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2425       emit_insn (gen_quous_call ());
2426       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2427       DONE;
2428     }
2429   else if (TARGET_POWER)
2430     {
2431       emit_insn (gen_udivsi3_mq (operands[0], operands[1], operands[2]));
2432       DONE;
2433     }
2434 }")
2435
2436 (define_insn "udivsi3_mq"
2437   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2438         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2439                  (match_operand:SI 2 "gpc_reg_operand" "r")))
2440    (clobber (match_scratch:SI 3 "=q"))]
2441   "TARGET_POWERPC && TARGET_POWER"
2442   "divwu %0,%1,%2"
2443   [(set_attr "type" "idiv")])
2444
2445 (define_insn "*udivsi3_no_mq"
2446   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2447         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2448                   (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2449   "TARGET_POWERPC && ! TARGET_POWER"
2450   "div<wd>u %0,%1,%2"
2451    [(set (attr "type")
2452       (cond [(match_operand:SI 0 "" "")
2453                 (const_string "idiv")]
2454         (const_string "ldiv")))])
2455
2456
2457 ;; For powers of two we can do srai/aze for divide and then adjust for
2458 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
2459 ;; used; for PowerPC, force operands into register and do a normal divide;
2460 ;; for AIX common-mode, use quoss call on register operands.
2461 (define_expand "div<mode>3"
2462   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2463         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2464                  (match_operand:GPR 2 "reg_or_cint_operand" "")))]
2465   ""
2466   "
2467 {
2468   if (GET_CODE (operands[2]) == CONST_INT
2469       && INTVAL (operands[2]) > 0
2470       && exact_log2 (INTVAL (operands[2])) >= 0)
2471     ;
2472   else if (TARGET_POWERPC)
2473     {
2474       operands[2] = force_reg (<MODE>mode, operands[2]);
2475       if (TARGET_POWER)
2476         {
2477           emit_insn (gen_divsi3_mq (operands[0], operands[1], operands[2]));
2478           DONE;
2479         }
2480     }
2481   else if (TARGET_POWER)
2482     FAIL;
2483   else
2484     {
2485       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2486       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2487       emit_insn (gen_quoss_call ());
2488       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2489       DONE;
2490     }
2491 }")
2492
2493 (define_insn "divsi3_mq"
2494   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2495         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2496                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2497    (clobber (match_scratch:SI 3 "=q"))]
2498   "TARGET_POWERPC && TARGET_POWER"
2499   "divw %0,%1,%2"
2500   [(set_attr "type" "idiv")])
2501
2502 (define_insn "*div<mode>3_no_mq"
2503   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2504         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2505                  (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2506   "TARGET_POWERPC && ! TARGET_POWER"
2507   "div<wd> %0,%1,%2"
2508   [(set (attr "type")
2509      (cond [(match_operand:SI 0 "" "")
2510                 (const_string "idiv")]
2511         (const_string "ldiv")))])
2512
2513 (define_expand "mod<mode>3"
2514   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
2515    (use (match_operand:GPR 1 "gpc_reg_operand" ""))
2516    (use (match_operand:GPR 2 "reg_or_cint_operand" ""))]
2517   ""
2518   "
2519 {
2520   int i;
2521   rtx temp1;
2522   rtx temp2;
2523
2524   if (GET_CODE (operands[2]) != CONST_INT
2525       || INTVAL (operands[2]) <= 0
2526       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
2527     FAIL;
2528
2529   temp1 = gen_reg_rtx (<MODE>mode);
2530   temp2 = gen_reg_rtx (<MODE>mode);
2531
2532   emit_insn (gen_div<mode>3 (temp1, operands[1], operands[2]));
2533   emit_insn (gen_ashl<mode>3 (temp2, temp1, GEN_INT (i)));
2534   emit_insn (gen_sub<mode>3 (operands[0], operands[1], temp2));
2535   DONE;
2536 }")
2537
2538 (define_insn ""
2539   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2540         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2541                  (match_operand:GPR 2 "exact_log2_cint_operand" "N")))]
2542   ""
2543   "{srai|sra<wd>i} %0,%1,%p2\;{aze|addze} %0,%0"
2544   [(set_attr "type" "two")
2545    (set_attr "length" "8")])
2546
2547 (define_insn ""
2548   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2549         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2550                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2551                     (const_int 0)))
2552    (clobber (match_scratch:P 3 "=r,r"))]
2553   ""
2554   "@
2555    {srai|sra<wd>i} %3,%1,%p2\;{aze.|addze.} %3,%3
2556    #"
2557   [(set_attr "type" "compare")
2558    (set_attr "length" "8,12")])
2559
2560 (define_split
2561   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2562         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2563                              (match_operand:GPR 2 "exact_log2_cint_operand"
2564                               ""))
2565                     (const_int 0)))
2566    (clobber (match_scratch:GPR 3 ""))]
2567   "reload_completed"
2568   [(set (match_dup 3)
2569         (div:<MODE> (match_dup 1) (match_dup 2)))
2570    (set (match_dup 0)
2571         (compare:CC (match_dup 3)
2572                     (const_int 0)))]
2573   "")
2574
2575 (define_insn ""
2576   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2577         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2578                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2579                     (const_int 0)))
2580    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2581         (div:P (match_dup 1) (match_dup 2)))]
2582   ""
2583   "@
2584    {srai|sra<wd>i} %0,%1,%p2\;{aze.|addze.} %0,%0
2585    #"
2586   [(set_attr "type" "compare")
2587    (set_attr "length" "8,12")])
2588
2589 (define_split
2590   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2591         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2592                              (match_operand:GPR 2 "exact_log2_cint_operand"
2593                               ""))
2594                     (const_int 0)))
2595    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2596         (div:GPR (match_dup 1) (match_dup 2)))]
2597   "reload_completed"
2598   [(set (match_dup 0)
2599         (div:<MODE> (match_dup 1) (match_dup 2)))
2600    (set (match_dup 3)
2601         (compare:CC (match_dup 0)
2602                     (const_int 0)))]
2603   "")
2604
2605 (define_insn ""
2606   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2607         (udiv:SI
2608          (plus:DI (ashift:DI
2609                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
2610                    (const_int 32))
2611                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
2612          (match_operand:SI 3 "gpc_reg_operand" "r")))
2613    (set (match_operand:SI 2 "register_operand" "=*q")
2614         (umod:SI
2615          (plus:DI (ashift:DI
2616                    (zero_extend:DI (match_dup 1)) (const_int 32))
2617                   (zero_extend:DI (match_dup 4)))
2618          (match_dup 3)))]
2619   "TARGET_POWER"
2620   "div %0,%1,%3"
2621   [(set_attr "type" "idiv")])
2622
2623 ;; To do unsigned divide we handle the cases of the divisor looking like a
2624 ;; negative number.  If it is a constant that is less than 2**31, we don't
2625 ;; have to worry about the branches.  So make a few subroutines here.
2626 ;;
2627 ;; First comes the normal case.
2628 (define_expand "udivmodsi4_normal"
2629   [(set (match_dup 4) (const_int 0))
2630    (parallel [(set (match_operand:SI 0 "" "")
2631                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2632                                                 (const_int 32))
2633                                      (zero_extend:DI (match_operand:SI 1 "" "")))
2634                             (match_operand:SI 2 "" "")))
2635               (set (match_operand:SI 3 "" "")
2636                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2637                                                 (const_int 32))
2638                                      (zero_extend:DI (match_dup 1)))
2639                             (match_dup 2)))])]
2640   "TARGET_POWER"
2641   "
2642 { operands[4] = gen_reg_rtx (SImode); }")
2643
2644 ;; This handles the branches.
2645 (define_expand "udivmodsi4_tests"
2646   [(set (match_operand:SI 0 "" "") (const_int 0))
2647    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
2648    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
2649    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
2650                            (label_ref (match_operand:SI 4 "" "")) (pc)))
2651    (set (match_dup 0) (const_int 1))
2652    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
2653    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
2654    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
2655                            (label_ref (match_dup 4)) (pc)))]
2656   "TARGET_POWER"
2657   "
2658 { operands[5] = gen_reg_rtx (CCUNSmode);
2659   operands[6] = gen_reg_rtx (CCmode);
2660 }")
2661
2662 (define_expand "udivmodsi4"
2663   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2664                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
2665                             (match_operand:SI 2 "reg_or_cint_operand" "")))
2666               (set (match_operand:SI 3 "gpc_reg_operand" "")
2667                    (umod:SI (match_dup 1) (match_dup 2)))])]
2668   ""
2669   "
2670 {
2671   rtx label = 0;
2672
2673   if (! TARGET_POWER)
2674     {
2675       if (! TARGET_POWERPC)
2676         {
2677           emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2678           emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2679           emit_insn (gen_divus_call ());
2680           emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2681           emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2682           DONE;
2683         }
2684       else
2685         FAIL;
2686     }
2687
2688   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
2689     {
2690       operands[2] = force_reg (SImode, operands[2]);
2691       label = gen_label_rtx ();
2692       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
2693                                   operands[3], label));
2694     }
2695   else
2696     operands[2] = force_reg (SImode, operands[2]);
2697
2698   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
2699                                operands[3]));
2700   if (label)
2701     emit_label (label);
2702
2703   DONE;
2704 }")
2705
2706 ;; AIX architecture-independent common-mode multiply (DImode),
2707 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
2708 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
2709 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
2710 ;; assumed unused if generating common-mode, so ignore.
2711 (define_insn "mulh_call"
2712   [(set (reg:SI 3)
2713         (truncate:SI
2714          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
2715                                (sign_extend:DI (reg:SI 4)))
2716                       (const_int 32))))
2717    (clobber (reg:SI 65))]
2718   "! TARGET_POWER && ! TARGET_POWERPC"
2719   "bla __mulh"
2720   [(set_attr "type" "imul")])
2721
2722 (define_insn "mull_call"
2723   [(set (reg:DI 3)
2724         (mult:DI (sign_extend:DI (reg:SI 3))
2725                  (sign_extend:DI (reg:SI 4))))
2726    (clobber (reg:SI 65))
2727    (clobber (reg:SI 0))]
2728   "! TARGET_POWER && ! TARGET_POWERPC"
2729   "bla __mull"
2730   [(set_attr "type" "imul")])
2731
2732 (define_insn "divss_call"
2733   [(set (reg:SI 3)
2734         (div:SI (reg:SI 3) (reg:SI 4)))
2735    (set (reg:SI 4)
2736         (mod:SI (reg:SI 3) (reg:SI 4)))
2737    (clobber (reg:SI 65))
2738    (clobber (reg:SI 0))]
2739   "! TARGET_POWER && ! TARGET_POWERPC"
2740   "bla __divss"
2741   [(set_attr "type" "idiv")])
2742
2743 (define_insn "divus_call"
2744   [(set (reg:SI 3)
2745         (udiv:SI (reg:SI 3) (reg:SI 4)))
2746    (set (reg:SI 4)
2747         (umod:SI (reg:SI 3) (reg:SI 4)))
2748    (clobber (reg:SI 65))
2749    (clobber (reg:SI 0))
2750    (clobber (match_scratch:CC 0 "=x"))
2751    (clobber (reg:CC 69))]
2752   "! TARGET_POWER && ! TARGET_POWERPC"
2753   "bla __divus"
2754   [(set_attr "type" "idiv")])
2755
2756 (define_insn "quoss_call"
2757   [(set (reg:SI 3)
2758         (div:SI (reg:SI 3) (reg:SI 4)))
2759    (clobber (reg:SI 65))]
2760   "! TARGET_POWER && ! TARGET_POWERPC"
2761   "bla __quoss"
2762   [(set_attr "type" "idiv")])
2763
2764 (define_insn "quous_call"
2765   [(set (reg:SI 3)
2766         (udiv:SI (reg:SI 3) (reg:SI 4)))
2767    (clobber (reg:SI 65))
2768    (clobber (reg:SI 0))
2769    (clobber (match_scratch:CC 0 "=x"))
2770    (clobber (reg:CC 69))]
2771   "! TARGET_POWER && ! TARGET_POWERPC"
2772   "bla __quous"
2773   [(set_attr "type" "idiv")])
2774 \f
2775 ;; Logical instructions
2776 ;; The logical instructions are mostly combined by using match_operator,
2777 ;; but the plain AND insns are somewhat different because there is no
2778 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2779 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2780
2781 (define_insn "andsi3"
2782   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2783         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2784                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2785    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2786   ""
2787   "@
2788    and %0,%1,%2
2789    {rlinm|rlwinm} %0,%1,0,%m2,%M2
2790    {andil.|andi.} %0,%1,%b2
2791    {andiu.|andis.} %0,%1,%u2"
2792   [(set_attr "type" "*,*,compare,compare")])
2793
2794 ;; Note to set cr's other than cr0 we do the and immediate and then
2795 ;; the test again -- this avoids a mfcr which on the higher end
2796 ;; machines causes an execution serialization
2797
2798 (define_insn "*andsi3_internal2"
2799   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2800         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2801                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2802                     (const_int 0)))
2803    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2804    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2805   "TARGET_32BIT"
2806   "@
2807    and. %3,%1,%2
2808    {andil.|andi.} %3,%1,%b2
2809    {andiu.|andis.} %3,%1,%u2
2810    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2811    #
2812    #
2813    #
2814    #"
2815   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2816    (set_attr "length" "4,4,4,4,8,8,8,8")])
2817
2818 (define_insn "*andsi3_internal3"
2819   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2820         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2821                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2822                     (const_int 0)))
2823    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2824    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2825   "TARGET_64BIT"
2826   "@
2827    #
2828    {andil.|andi.} %3,%1,%b2
2829    {andiu.|andis.} %3,%1,%u2
2830    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2831    #
2832    #
2833    #
2834    #"
2835   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2836    (set_attr "length" "8,4,4,4,8,8,8,8")])
2837
2838 (define_split
2839   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2840         (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2841                              (match_operand:GPR 2 "and_operand" ""))
2842                     (const_int 0)))
2843    (clobber (match_scratch:GPR 3 ""))
2844    (clobber (match_scratch:CC 4 ""))]
2845   "reload_completed"
2846   [(parallel [(set (match_dup 3)
2847                    (and:<MODE> (match_dup 1)
2848                                (match_dup 2)))
2849               (clobber (match_dup 4))])
2850    (set (match_dup 0)
2851         (compare:CC (match_dup 3)
2852                     (const_int 0)))]
2853   "")
2854
2855 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
2856 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
2857
2858 (define_split
2859   [(set (match_operand:CC 0 "cc_reg_operand" "")
2860         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2861                             (match_operand:SI 2 "gpc_reg_operand" ""))
2862                     (const_int 0)))
2863    (clobber (match_scratch:SI 3 ""))
2864    (clobber (match_scratch:CC 4 ""))]
2865   "TARGET_POWERPC64 && reload_completed"
2866   [(parallel [(set (match_dup 3)
2867                    (and:SI (match_dup 1)
2868                            (match_dup 2)))
2869               (clobber (match_dup 4))])
2870    (set (match_dup 0)
2871         (compare:CC (match_dup 3)
2872                     (const_int 0)))]
2873   "")
2874
2875 (define_insn "*andsi3_internal4"
2876   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2877         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2878                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2879                     (const_int 0)))
2880    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2881         (and:SI (match_dup 1)
2882                 (match_dup 2)))
2883    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2884   "TARGET_32BIT"
2885   "@
2886    and. %0,%1,%2
2887    {andil.|andi.} %0,%1,%b2
2888    {andiu.|andis.} %0,%1,%u2
2889    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2890    #
2891    #
2892    #
2893    #"
2894   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2895    (set_attr "length" "4,4,4,4,8,8,8,8")])
2896
2897 (define_insn "*andsi3_internal5"
2898   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2899         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2900                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2901                     (const_int 0)))
2902    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2903         (and:SI (match_dup 1)
2904                 (match_dup 2)))
2905    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2906   "TARGET_64BIT"
2907   "@
2908    #
2909    {andil.|andi.} %0,%1,%b2
2910    {andiu.|andis.} %0,%1,%u2
2911    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2912    #
2913    #
2914    #
2915    #"
2916   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2917    (set_attr "length" "8,4,4,4,8,8,8,8")])
2918
2919 (define_split
2920   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2921         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2922                             (match_operand:SI 2 "and_operand" ""))
2923                     (const_int 0)))
2924    (set (match_operand:SI 0 "gpc_reg_operand" "")
2925         (and:SI (match_dup 1)
2926                 (match_dup 2)))
2927    (clobber (match_scratch:CC 4 ""))]
2928   "reload_completed"
2929   [(parallel [(set (match_dup 0)
2930                    (and:SI (match_dup 1)
2931                            (match_dup 2)))
2932               (clobber (match_dup 4))])
2933    (set (match_dup 3)
2934         (compare:CC (match_dup 0)
2935                     (const_int 0)))]
2936   "")
2937
2938 (define_split
2939   [(set (match_operand:CC 3 "cc_reg_operand" "")
2940         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2941                             (match_operand:SI 2 "gpc_reg_operand" ""))
2942                     (const_int 0)))
2943    (set (match_operand:SI 0 "gpc_reg_operand" "")
2944         (and:SI (match_dup 1)
2945                 (match_dup 2)))
2946    (clobber (match_scratch:CC 4 ""))]
2947   "TARGET_POWERPC64 && reload_completed"
2948   [(parallel [(set (match_dup 0)
2949                    (and:SI (match_dup 1)
2950                            (match_dup 2)))
2951               (clobber (match_dup 4))])
2952    (set (match_dup 3)
2953         (compare:CC (match_dup 0)
2954                     (const_int 0)))]
2955   "")
2956
2957 ;; Handle the PowerPC64 rlwinm corner case
2958
2959 (define_insn_and_split "*andsi3_internal6"
2960   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2961         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2962                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
2963   "TARGET_POWERPC64"
2964   "#"
2965   "TARGET_POWERPC64"
2966   [(set (match_dup 0)
2967         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
2968                 (match_dup 4)))
2969    (set (match_dup 0)
2970         (rotate:SI (match_dup 0) (match_dup 5)))]
2971   "
2972 {
2973   int mb = extract_MB (operands[2]);
2974   int me = extract_ME (operands[2]);
2975   operands[3] = GEN_INT (me + 1);
2976   operands[5] = GEN_INT (32 - (me + 1));
2977   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2978 }"
2979   [(set_attr "length" "8")])
2980
2981 (define_expand "iorsi3"
2982   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2983         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
2984                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2985   ""
2986   "
2987 {
2988   if (GET_CODE (operands[2]) == CONST_INT
2989       && ! logical_operand (operands[2], SImode))
2990     {
2991       HOST_WIDE_INT value = INTVAL (operands[2]);
2992       rtx tmp = ((!can_create_pseudo_p ()
2993                   || rtx_equal_p (operands[0], operands[1]))
2994                  ? operands[0] : gen_reg_rtx (SImode));
2995
2996       emit_insn (gen_iorsi3 (tmp, operands[1],
2997                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2998       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2999       DONE;
3000     }
3001 }")
3002
3003 (define_expand "xorsi3"
3004   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3005         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
3006                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3007   ""
3008   "
3009 {
3010   if (GET_CODE (operands[2]) == CONST_INT
3011       && ! logical_operand (operands[2], SImode))
3012     {
3013       HOST_WIDE_INT value = INTVAL (operands[2]);
3014       rtx tmp = ((!can_create_pseudo_p ()
3015                   || rtx_equal_p (operands[0], operands[1]))
3016                  ? operands[0] : gen_reg_rtx (SImode));
3017
3018       emit_insn (gen_xorsi3 (tmp, operands[1],
3019                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3020       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3021       DONE;
3022     }
3023 }")
3024
3025 (define_insn "*boolsi3_internal1"
3026   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
3027         (match_operator:SI 3 "boolean_or_operator"
3028          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
3029           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
3030   ""
3031   "@
3032    %q3 %0,%1,%2
3033    {%q3il|%q3i} %0,%1,%b2
3034    {%q3iu|%q3is} %0,%1,%u2")
3035
3036 (define_insn "*boolsi3_internal2"
3037   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3038         (compare:CC (match_operator:SI 4 "boolean_or_operator"
3039          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3040           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3041          (const_int 0)))
3042    (clobber (match_scratch:SI 3 "=r,r"))]
3043   "TARGET_32BIT"
3044   "@
3045    %q4. %3,%1,%2
3046    #"
3047   [(set_attr "type" "compare")
3048    (set_attr "length" "4,8")])
3049
3050 (define_split
3051   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3052         (compare:CC (match_operator:SI 4 "boolean_operator"
3053          [(match_operand:SI 1 "gpc_reg_operand" "")
3054           (match_operand:SI 2 "gpc_reg_operand" "")])
3055          (const_int 0)))
3056    (clobber (match_scratch:SI 3 ""))]
3057   "TARGET_32BIT && reload_completed"
3058   [(set (match_dup 3) (match_dup 4))
3059    (set (match_dup 0)
3060         (compare:CC (match_dup 3)
3061                     (const_int 0)))]
3062   "")
3063
3064 (define_insn "*boolsi3_internal3"
3065   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3066         (compare:CC (match_operator:SI 4 "boolean_operator"
3067          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3068           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3069          (const_int 0)))
3070    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3071         (match_dup 4))]
3072   "TARGET_32BIT"
3073   "@
3074    %q4. %0,%1,%2
3075    #"
3076   [(set_attr "type" "compare")
3077    (set_attr "length" "4,8")])
3078
3079 (define_split
3080   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3081         (compare:CC (match_operator:SI 4 "boolean_operator"
3082          [(match_operand:SI 1 "gpc_reg_operand" "")
3083           (match_operand:SI 2 "gpc_reg_operand" "")])
3084          (const_int 0)))
3085    (set (match_operand:SI 0 "gpc_reg_operand" "")
3086         (match_dup 4))]
3087   "TARGET_32BIT && reload_completed"
3088   [(set (match_dup 0) (match_dup 4))
3089    (set (match_dup 3)
3090         (compare:CC (match_dup 0)
3091                     (const_int 0)))]
3092   "")
3093
3094 ;; Split a logical operation that we can't do in one insn into two insns,
3095 ;; each of which does one 16-bit part.  This is used by combine.
3096
3097 (define_split
3098   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3099         (match_operator:SI 3 "boolean_or_operator"
3100          [(match_operand:SI 1 "gpc_reg_operand" "")
3101           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
3102   ""
3103   [(set (match_dup 0) (match_dup 4))
3104    (set (match_dup 0) (match_dup 5))]
3105 "
3106 {
3107   rtx i;
3108   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
3109   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3110                                 operands[1], i);
3111   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
3112   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3113                                 operands[0], i);
3114 }")
3115
3116 (define_insn "*boolcsi3_internal1"
3117   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3118         (match_operator:SI 3 "boolean_operator"
3119          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3120           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
3121   ""
3122   "%q3 %0,%2,%1")
3123
3124 (define_insn "*boolcsi3_internal2"
3125   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3126         (compare:CC (match_operator:SI 4 "boolean_operator"
3127          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3128           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3129          (const_int 0)))
3130    (clobber (match_scratch:SI 3 "=r,r"))]
3131   "TARGET_32BIT"
3132   "@
3133    %q4. %3,%2,%1
3134    #"
3135   [(set_attr "type" "compare")
3136    (set_attr "length" "4,8")])
3137
3138 (define_split
3139   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3140         (compare:CC (match_operator:SI 4 "boolean_operator"
3141          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3142           (match_operand:SI 2 "gpc_reg_operand" "")])
3143          (const_int 0)))
3144    (clobber (match_scratch:SI 3 ""))]
3145   "TARGET_32BIT && reload_completed"
3146   [(set (match_dup 3) (match_dup 4))
3147    (set (match_dup 0)
3148         (compare:CC (match_dup 3)
3149                     (const_int 0)))]
3150   "")
3151
3152 (define_insn "*boolcsi3_internal3"
3153   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3154         (compare:CC (match_operator:SI 4 "boolean_operator"
3155          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3156           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3157          (const_int 0)))
3158    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3159         (match_dup 4))]
3160   "TARGET_32BIT"
3161   "@
3162    %q4. %0,%2,%1
3163    #"
3164   [(set_attr "type" "compare")
3165    (set_attr "length" "4,8")])
3166
3167 (define_split
3168   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3169         (compare:CC (match_operator:SI 4 "boolean_operator"
3170          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3171           (match_operand:SI 2 "gpc_reg_operand" "")])
3172          (const_int 0)))
3173    (set (match_operand:SI 0 "gpc_reg_operand" "")
3174         (match_dup 4))]
3175   "TARGET_32BIT && reload_completed"
3176   [(set (match_dup 0) (match_dup 4))
3177    (set (match_dup 3)
3178         (compare:CC (match_dup 0)
3179                     (const_int 0)))]
3180   "")
3181
3182 (define_insn "*boolccsi3_internal1"
3183   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3184         (match_operator:SI 3 "boolean_operator"
3185          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3186           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
3187   ""
3188   "%q3 %0,%1,%2")
3189
3190 (define_insn "*boolccsi3_internal2"
3191   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3192         (compare:CC (match_operator:SI 4 "boolean_operator"
3193          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3194           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3195          (const_int 0)))
3196    (clobber (match_scratch:SI 3 "=r,r"))]
3197   "TARGET_32BIT"
3198   "@
3199    %q4. %3,%1,%2
3200    #"
3201   [(set_attr "type" "compare")
3202    (set_attr "length" "4,8")])
3203
3204 (define_split
3205   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3206         (compare:CC (match_operator:SI 4 "boolean_operator"
3207          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3208           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3209          (const_int 0)))
3210    (clobber (match_scratch:SI 3 ""))]
3211   "TARGET_32BIT && reload_completed"
3212   [(set (match_dup 3) (match_dup 4))
3213    (set (match_dup 0)
3214         (compare:CC (match_dup 3)
3215                     (const_int 0)))]
3216   "")
3217
3218 (define_insn "*boolccsi3_internal3"
3219   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3220         (compare:CC (match_operator:SI 4 "boolean_operator"
3221          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3222           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3223          (const_int 0)))
3224    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3225         (match_dup 4))]
3226   "TARGET_32BIT"
3227   "@
3228    %q4. %0,%1,%2
3229    #"
3230   [(set_attr "type" "compare")
3231    (set_attr "length" "4,8")])
3232
3233 (define_split
3234   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3235         (compare:CC (match_operator:SI 4 "boolean_operator"
3236          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3237           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3238          (const_int 0)))
3239    (set (match_operand:SI 0 "gpc_reg_operand" "")
3240         (match_dup 4))]
3241   "TARGET_32BIT && reload_completed"
3242   [(set (match_dup 0) (match_dup 4))
3243    (set (match_dup 3)
3244         (compare:CC (match_dup 0)
3245                     (const_int 0)))]
3246   "")
3247
3248 ;; maskir insn.  We need four forms because things might be in arbitrary
3249 ;; orders.  Don't define forms that only set CR fields because these
3250 ;; would modify an input register.
3251
3252 (define_insn "*maskir_internal1"
3253   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3254         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3255                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3256                 (and:SI (match_dup 2)
3257                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
3258   "TARGET_POWER"
3259   "maskir %0,%3,%2")
3260
3261 (define_insn "*maskir_internal2"
3262   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3263         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3264                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3265                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3266                         (match_dup 2))))]
3267   "TARGET_POWER"
3268   "maskir %0,%3,%2")
3269
3270 (define_insn "*maskir_internal3"
3271   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3272         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
3273                         (match_operand:SI 3 "gpc_reg_operand" "r"))
3274                 (and:SI (not:SI (match_dup 2))
3275                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3276   "TARGET_POWER"
3277   "maskir %0,%3,%2")
3278
3279 (define_insn "*maskir_internal4"
3280   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3281         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3282                         (match_operand:SI 2 "gpc_reg_operand" "r"))
3283                 (and:SI (not:SI (match_dup 2))
3284                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3285   "TARGET_POWER"
3286   "maskir %0,%3,%2")
3287
3288 (define_insn "*maskir_internal5"
3289   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3290         (compare:CC
3291          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3292                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3293                  (and:SI (match_dup 2)
3294                          (match_operand:SI 3 "gpc_reg_operand" "r,r")))
3295          (const_int 0)))
3296    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3297         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3298                 (and:SI (match_dup 2) (match_dup 3))))]
3299   "TARGET_POWER"
3300   "@
3301    maskir. %0,%3,%2
3302    #"
3303   [(set_attr "type" "compare")
3304    (set_attr "length" "4,8")])
3305
3306 (define_split
3307   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3308         (compare:CC
3309          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3310                          (match_operand:SI 1 "gpc_reg_operand" ""))
3311                  (and:SI (match_dup 2)
3312                          (match_operand:SI 3 "gpc_reg_operand" "")))
3313          (const_int 0)))
3314    (set (match_operand:SI 0 "gpc_reg_operand" "")
3315         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3316                 (and:SI (match_dup 2) (match_dup 3))))]
3317   "TARGET_POWER && reload_completed"
3318   [(set (match_dup 0)
3319         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3320                 (and:SI (match_dup 2) (match_dup 3))))
3321    (set (match_dup 4)
3322         (compare:CC (match_dup 0)
3323                     (const_int 0)))]
3324   "")
3325
3326 (define_insn "*maskir_internal6"
3327   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3328         (compare:CC
3329          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3330                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3331                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
3332                          (match_dup 2)))
3333          (const_int 0)))
3334    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3335         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3336                 (and:SI (match_dup 3) (match_dup 2))))]
3337   "TARGET_POWER"
3338   "@
3339    maskir. %0,%3,%2
3340    #"
3341   [(set_attr "type" "compare")
3342    (set_attr "length" "4,8")])
3343
3344 (define_split
3345   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3346         (compare:CC
3347          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3348                          (match_operand:SI 1 "gpc_reg_operand" ""))
3349                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
3350                          (match_dup 2)))
3351          (const_int 0)))
3352    (set (match_operand:SI 0 "gpc_reg_operand" "")
3353         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3354                 (and:SI (match_dup 3) (match_dup 2))))]
3355   "TARGET_POWER && reload_completed"
3356   [(set (match_dup 0)
3357         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3358                 (and:SI (match_dup 3) (match_dup 2))))
3359    (set (match_dup 4)
3360         (compare:CC (match_dup 0)
3361                     (const_int 0)))]
3362   "")
3363
3364 (define_insn "*maskir_internal7"
3365   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3366         (compare:CC
3367          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r,r")
3368                          (match_operand:SI 3 "gpc_reg_operand" "r,r"))
3369                  (and:SI (not:SI (match_dup 2))
3370                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
3371          (const_int 0)))
3372    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3373         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3374                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3375   "TARGET_POWER"
3376   "@
3377    maskir. %0,%3,%2
3378    #"
3379   [(set_attr "type" "compare")
3380    (set_attr "length" "4,8")])
3381
3382 (define_split
3383   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3384         (compare:CC
3385          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "")
3386                          (match_operand:SI 3 "gpc_reg_operand" ""))
3387                  (and:SI (not:SI (match_dup 2))
3388                          (match_operand:SI 1 "gpc_reg_operand" "")))
3389          (const_int 0)))
3390    (set (match_operand:SI 0 "gpc_reg_operand" "")
3391         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3392                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3393   "TARGET_POWER && reload_completed"
3394   [(set (match_dup 0)
3395         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3396                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
3397    (set (match_dup 4)
3398         (compare:CC (match_dup 0)
3399                     (const_int 0)))]
3400   "")
3401
3402 (define_insn "*maskir_internal8"
3403   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3404         (compare:CC
3405          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
3406                          (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3407                  (and:SI (not:SI (match_dup 2))
3408                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
3409          (const_int 0)))
3410    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3411         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3412                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3413   "TARGET_POWER"
3414   "@
3415    maskir. %0,%3,%2
3416    #"
3417   [(set_attr "type" "compare")
3418    (set_attr "length" "4,8")])
3419
3420 (define_split
3421   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3422         (compare:CC
3423          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
3424                          (match_operand:SI 2 "gpc_reg_operand" ""))
3425                  (and:SI (not:SI (match_dup 2))
3426                          (match_operand:SI 1 "gpc_reg_operand" "")))
3427          (const_int 0)))
3428    (set (match_operand:SI 0 "gpc_reg_operand" "")
3429         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3430                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3431   "TARGET_POWER && reload_completed"
3432   [(set (match_dup 0)
3433         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3434                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
3435    (set (match_dup 4)
3436         (compare:CC (match_dup 0)
3437                     (const_int 0)))]
3438   "")
3439 \f
3440 ;; Rotate and shift insns, in all their variants.  These support shifts,
3441 ;; field inserts and extracts, and various combinations thereof.
3442 (define_expand "insv"
3443   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
3444                        (match_operand:SI 1 "const_int_operand" "")
3445                        (match_operand:SI 2 "const_int_operand" ""))
3446         (match_operand 3 "gpc_reg_operand" ""))]
3447   ""
3448   "
3449 {
3450   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3451      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3452      compiler if the address of the structure is taken later.  Likewise, do
3453      not handle invalid E500 subregs.  */
3454   if (GET_CODE (operands[0]) == SUBREG
3455       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD
3456           || ((TARGET_E500_DOUBLE || TARGET_SPE)
3457               && invalid_e500_subreg (operands[0], GET_MODE (operands[0])))))
3458     FAIL;
3459
3460   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
3461     emit_insn (gen_insvdi (operands[0], operands[1], operands[2], operands[3]));
3462   else
3463     emit_insn (gen_insvsi (operands[0], operands[1], operands[2], operands[3]));
3464   DONE;
3465 }")
3466
3467 (define_insn "insvsi"
3468   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3469                          (match_operand:SI 1 "const_int_operand" "i")
3470                          (match_operand:SI 2 "const_int_operand" "i"))
3471         (match_operand:SI 3 "gpc_reg_operand" "r"))]
3472   ""
3473   "*
3474 {
3475   int start = INTVAL (operands[2]) & 31;
3476   int size = INTVAL (operands[1]) & 31;
3477
3478   operands[4] = GEN_INT (32 - start - size);
3479   operands[1] = GEN_INT (start + size - 1);
3480   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3481 }"
3482   [(set_attr "type" "insert_word")])
3483
3484 (define_insn "*insvsi_internal1"
3485   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3486                          (match_operand:SI 1 "const_int_operand" "i")
3487                          (match_operand:SI 2 "const_int_operand" "i"))
3488         (rotate:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3489                    (match_operand:SI 4 "const_int_operand" "i")))]
3490   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3491   "*
3492 {
3493   int shift = INTVAL (operands[4]) & 31;
3494   int start = INTVAL (operands[2]) & 31;
3495   int size = INTVAL (operands[1]) & 31;
3496
3497   operands[4] = GEN_INT (shift - start - size);
3498   operands[1] = GEN_INT (start + size - 1);
3499   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3500 }"
3501   [(set_attr "type" "insert_word")])
3502
3503 (define_insn "*insvsi_internal2"
3504   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3505                          (match_operand:SI 1 "const_int_operand" "i")
3506                          (match_operand:SI 2 "const_int_operand" "i"))
3507         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3508                      (match_operand:SI 4 "const_int_operand" "i")))]
3509   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3510   "*
3511 {
3512   int shift = INTVAL (operands[4]) & 31;
3513   int start = INTVAL (operands[2]) & 31;
3514   int size = INTVAL (operands[1]) & 31;
3515
3516   operands[4] = GEN_INT (32 - shift - start - size);
3517   operands[1] = GEN_INT (start + size - 1);
3518   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3519 }"
3520   [(set_attr "type" "insert_word")])
3521
3522 (define_insn "*insvsi_internal3"
3523   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3524                          (match_operand:SI 1 "const_int_operand" "i")
3525                          (match_operand:SI 2 "const_int_operand" "i"))
3526         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3527                      (match_operand:SI 4 "const_int_operand" "i")))]
3528   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3529   "*
3530 {
3531   int shift = INTVAL (operands[4]) & 31;
3532   int start = INTVAL (operands[2]) & 31;
3533   int size = INTVAL (operands[1]) & 31;
3534
3535   operands[4] = GEN_INT (32 - shift - start - size);
3536   operands[1] = GEN_INT (start + size - 1);
3537   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3538 }"
3539   [(set_attr "type" "insert_word")])
3540
3541 (define_insn "*insvsi_internal4"
3542   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3543                          (match_operand:SI 1 "const_int_operand" "i")
3544                          (match_operand:SI 2 "const_int_operand" "i"))
3545         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3546                          (match_operand:SI 4 "const_int_operand" "i")
3547                          (match_operand:SI 5 "const_int_operand" "i")))]
3548   "INTVAL (operands[4]) >= INTVAL (operands[1])"
3549   "*
3550 {
3551   int extract_start = INTVAL (operands[5]) & 31;
3552   int extract_size = INTVAL (operands[4]) & 31;
3553   int insert_start = INTVAL (operands[2]) & 31;
3554   int insert_size = INTVAL (operands[1]) & 31;
3555
3556 /* Align extract field with insert field */
3557   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
3558   operands[1] = GEN_INT (insert_start + insert_size - 1);
3559   return \"{rlimi|rlwimi} %0,%3,%h5,%h2,%h1\";
3560 }"
3561   [(set_attr "type" "insert_word")])
3562
3563 ;; combine patterns for rlwimi
3564 (define_insn "*insvsi_internal5"
3565   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3566         (ior:SI (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3567                         (match_operand:SI 1 "mask_operand" "i"))
3568                 (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3569                                      (match_operand:SI 2 "const_int_operand" "i"))
3570                         (match_operand:SI 5 "mask_operand" "i"))))]
3571   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
3572   "*
3573 {
3574  int me = extract_ME(operands[5]);
3575  int mb = extract_MB(operands[5]);
3576  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3577  operands[2] = GEN_INT(mb);
3578  operands[1] = GEN_INT(me);
3579  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3580 }"
3581   [(set_attr "type" "insert_word")])
3582
3583 (define_insn "*insvsi_internal6"
3584   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3585         (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3586                                      (match_operand:SI 2 "const_int_operand" "i"))
3587                         (match_operand:SI 5 "mask_operand" "i"))
3588                 (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3589                         (match_operand:SI 1 "mask_operand" "i"))))]
3590   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
3591   "*
3592 {
3593  int me = extract_ME(operands[5]);
3594  int mb = extract_MB(operands[5]);
3595  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3596  operands[2] = GEN_INT(mb);
3597  operands[1] = GEN_INT(me);
3598  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3599 }"
3600   [(set_attr "type" "insert_word")])
3601
3602 (define_insn "insvdi"
3603   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3604                          (match_operand:SI 1 "const_int_operand" "i")
3605                          (match_operand:SI 2 "const_int_operand" "i"))
3606         (match_operand:DI 3 "gpc_reg_operand" "r"))]
3607   "TARGET_POWERPC64"
3608   "*
3609 {
3610   int start = INTVAL (operands[2]) & 63;
3611   int size = INTVAL (operands[1]) & 63;
3612
3613   operands[1] = GEN_INT (64 - start - size);
3614   return \"rldimi %0,%3,%H1,%H2\";
3615 }"
3616   [(set_attr "type" "insert_dword")])
3617
3618 (define_insn "*insvdi_internal2"
3619   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3620                          (match_operand:SI 1 "const_int_operand" "i")
3621                          (match_operand:SI 2 "const_int_operand" "i"))
3622         (ashiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3623                      (match_operand:SI 4 "const_int_operand" "i")))]
3624   "TARGET_POWERPC64
3625    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3626   "*
3627 {
3628   int shift = INTVAL (operands[4]) & 63;
3629   int start = (INTVAL (operands[2]) & 63) - 32;
3630   int size = INTVAL (operands[1]) & 63;
3631
3632   operands[4] = GEN_INT (64 - shift - start - size);
3633   operands[2] = GEN_INT (start);
3634   operands[1] = GEN_INT (start + size - 1);
3635   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3636 }")
3637
3638 (define_insn "*insvdi_internal3"
3639   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3640                          (match_operand:SI 1 "const_int_operand" "i")
3641                          (match_operand:SI 2 "const_int_operand" "i"))
3642         (lshiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3643                      (match_operand:SI 4 "const_int_operand" "i")))]
3644   "TARGET_POWERPC64
3645    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3646   "*
3647 {
3648   int shift = INTVAL (operands[4]) & 63;
3649   int start = (INTVAL (operands[2]) & 63) - 32;
3650   int size = INTVAL (operands[1]) & 63;
3651
3652   operands[4] = GEN_INT (64 - shift - start - size);
3653   operands[2] = GEN_INT (start);
3654   operands[1] = GEN_INT (start + size - 1);
3655   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3656 }")
3657
3658 (define_expand "extzv"
3659   [(set (match_operand 0 "gpc_reg_operand" "")
3660         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3661                        (match_operand:SI 2 "const_int_operand" "")
3662                        (match_operand:SI 3 "const_int_operand" "")))]
3663   ""
3664   "
3665 {
3666   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3667      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3668      compiler if the address of the structure is taken later.  */
3669   if (GET_CODE (operands[0]) == SUBREG
3670       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3671     FAIL;
3672
3673   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3674     emit_insn (gen_extzvdi (operands[0], operands[1], operands[2], operands[3]));
3675   else
3676     emit_insn (gen_extzvsi (operands[0], operands[1], operands[2], operands[3]));
3677   DONE;
3678 }")
3679
3680 (define_insn "extzvsi"
3681   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3682         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3683                          (match_operand:SI 2 "const_int_operand" "i")
3684                          (match_operand:SI 3 "const_int_operand" "i")))]
3685   ""
3686   "*
3687 {
3688   int start = INTVAL (operands[3]) & 31;
3689   int size = INTVAL (operands[2]) & 31;
3690
3691   if (start + size >= 32)
3692     operands[3] = const0_rtx;
3693   else
3694     operands[3] = GEN_INT (start + size);
3695   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
3696 }")
3697
3698 (define_insn "*extzvsi_internal1"
3699   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3700         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3701                          (match_operand:SI 2 "const_int_operand" "i,i")
3702                          (match_operand:SI 3 "const_int_operand" "i,i"))
3703                     (const_int 0)))
3704    (clobber (match_scratch:SI 4 "=r,r"))]
3705   ""
3706   "*
3707 {
3708   int start = INTVAL (operands[3]) & 31;
3709   int size = INTVAL (operands[2]) & 31;
3710
3711   /* Force split for non-cc0 compare.  */
3712   if (which_alternative == 1)
3713      return \"#\";
3714
3715   /* If the bit-field being tested fits in the upper or lower half of a
3716      word, it is possible to use andiu. or andil. to test it.  This is
3717      useful because the condition register set-use delay is smaller for
3718      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3719      position is 0 because the LT and GT bits may be set wrong.  */
3720
3721   if ((start > 0 && start + size <= 16) || start >= 16)
3722     {
3723       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3724                               - (1 << (16 - (start & 15) - size))));
3725       if (start < 16)
3726         return \"{andiu.|andis.} %4,%1,%3\";
3727       else
3728         return \"{andil.|andi.} %4,%1,%3\";
3729     }
3730
3731   if (start + size >= 32)
3732     operands[3] = const0_rtx;
3733   else
3734     operands[3] = GEN_INT (start + size);
3735   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
3736 }"
3737   [(set_attr "type" "delayed_compare")
3738    (set_attr "length" "4,8")])
3739
3740 (define_split
3741   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3742         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3743                          (match_operand:SI 2 "const_int_operand" "")
3744                          (match_operand:SI 3 "const_int_operand" ""))
3745                     (const_int 0)))
3746    (clobber (match_scratch:SI 4 ""))]
3747   "reload_completed"
3748   [(set (match_dup 4)
3749         (zero_extract:SI (match_dup 1) (match_dup 2)
3750                          (match_dup 3)))
3751    (set (match_dup 0)
3752         (compare:CC (match_dup 4)
3753                     (const_int 0)))]
3754   "")
3755
3756 (define_insn "*extzvsi_internal2"
3757   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3758         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3759                          (match_operand:SI 2 "const_int_operand" "i,i")
3760                          (match_operand:SI 3 "const_int_operand" "i,i"))
3761                     (const_int 0)))
3762    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3763         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3764   ""
3765   "*
3766 {
3767   int start = INTVAL (operands[3]) & 31;
3768   int size = INTVAL (operands[2]) & 31;
3769
3770   /* Force split for non-cc0 compare.  */
3771   if (which_alternative == 1)
3772      return \"#\";
3773
3774   /* Since we are using the output value, we can't ignore any need for
3775      a shift.  The bit-field must end at the LSB.  */
3776   if (start >= 16 && start + size == 32)
3777     {
3778       operands[3] = GEN_INT ((1 << size) - 1);
3779       return \"{andil.|andi.} %0,%1,%3\";
3780     }
3781
3782   if (start + size >= 32)
3783     operands[3] = const0_rtx;
3784   else
3785     operands[3] = GEN_INT (start + size);
3786   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
3787 }"
3788   [(set_attr "type" "delayed_compare")
3789    (set_attr "length" "4,8")])
3790
3791 (define_split
3792   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3793         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3794                          (match_operand:SI 2 "const_int_operand" "")
3795                          (match_operand:SI 3 "const_int_operand" ""))
3796                     (const_int 0)))
3797    (set (match_operand:SI 0 "gpc_reg_operand" "")
3798         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3799   "reload_completed"
3800   [(set (match_dup 0)
3801         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3802    (set (match_dup 4)
3803         (compare:CC (match_dup 0)
3804                     (const_int 0)))]
3805   "")
3806
3807 (define_insn "extzvdi"
3808   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3809         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3810                          (match_operand:SI 2 "const_int_operand" "i")
3811                          (match_operand:SI 3 "const_int_operand" "i")))]
3812   "TARGET_POWERPC64"
3813   "*
3814 {
3815   int start = INTVAL (operands[3]) & 63;
3816   int size = INTVAL (operands[2]) & 63;
3817
3818   if (start + size >= 64)
3819     operands[3] = const0_rtx;
3820   else
3821     operands[3] = GEN_INT (start + size);
3822   operands[2] = GEN_INT (64 - size);
3823   return \"rldicl %0,%1,%3,%2\";
3824 }")
3825
3826 (define_insn "*extzvdi_internal1"
3827   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3828         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3829                          (match_operand:SI 2 "const_int_operand" "i")
3830                          (match_operand:SI 3 "const_int_operand" "i"))
3831                     (const_int 0)))
3832    (clobber (match_scratch:DI 4 "=r"))]
3833   "TARGET_64BIT"
3834   "*
3835 {
3836   int start = INTVAL (operands[3]) & 63;
3837   int size = INTVAL (operands[2]) & 63;
3838
3839   if (start + size >= 64)
3840     operands[3] = const0_rtx;
3841   else
3842     operands[3] = GEN_INT (start + size);
3843   operands[2] = GEN_INT (64 - size);
3844   return \"rldicl. %4,%1,%3,%2\";
3845 }"
3846   [(set_attr "type" "compare")])
3847
3848 (define_insn "*extzvdi_internal2"
3849   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3850         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3851                          (match_operand:SI 2 "const_int_operand" "i")
3852                          (match_operand:SI 3 "const_int_operand" "i"))
3853                     (const_int 0)))
3854    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3855         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3856   "TARGET_64BIT"
3857   "*
3858 {
3859   int start = INTVAL (operands[3]) & 63;
3860   int size = INTVAL (operands[2]) & 63;
3861
3862   if (start + size >= 64)
3863     operands[3] = const0_rtx;
3864   else
3865     operands[3] = GEN_INT (start + size);
3866   operands[2] = GEN_INT (64 - size);
3867   return \"rldicl. %0,%1,%3,%2\";
3868 }"
3869   [(set_attr "type" "compare")])
3870
3871 (define_insn "rotlsi3"
3872   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3873         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3874                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
3875   ""
3876   "@
3877    {rlnm|rlwnm} %0,%1,%2,0xffffffff
3878    {rlinm|rlwinm} %0,%1,%h2,0xffffffff"
3879   [(set_attr "type" "var_shift_rotate,integer")])
3880
3881 (define_insn "*rotlsi3_internal2"
3882   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3883         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3884                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3885                     (const_int 0)))
3886    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
3887   ""
3888   "@
3889    {rlnm.|rlwnm.} %3,%1,%2,0xffffffff
3890    {rlinm.|rlwinm.} %3,%1,%h2,0xffffffff
3891    #
3892    #"
3893   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3894    (set_attr "length" "4,4,8,8")])
3895
3896 (define_split
3897   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3898         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3899                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3900                     (const_int 0)))
3901    (clobber (match_scratch:SI 3 ""))]
3902   "reload_completed"
3903   [(set (match_dup 3)
3904         (rotate:SI (match_dup 1) (match_dup 2)))
3905    (set (match_dup 0)
3906         (compare:CC (match_dup 3)
3907                     (const_int 0)))]
3908   "")
3909
3910 (define_insn "*rotlsi3_internal3"
3911   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3912         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3913                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3914                     (const_int 0)))
3915    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3916         (rotate:SI (match_dup 1) (match_dup 2)))]
3917   ""
3918   "@
3919    {rlnm.|rlwnm.} %0,%1,%2,0xffffffff
3920    {rlinm.|rlwinm.} %0,%1,%h2,0xffffffff
3921    #
3922    #"
3923   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3924    (set_attr "length" "4,4,8,8")])
3925
3926 (define_split
3927   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3928         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3929                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3930                     (const_int 0)))
3931    (set (match_operand:SI 0 "gpc_reg_operand" "")
3932         (rotate:SI (match_dup 1) (match_dup 2)))]
3933   "reload_completed"
3934   [(set (match_dup 0)
3935         (rotate:SI (match_dup 1) (match_dup 2)))
3936    (set (match_dup 3)
3937         (compare:CC (match_dup 0)
3938                     (const_int 0)))]
3939   "")
3940
3941 (define_insn "*rotlsi3_internal4"
3942   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3943         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3944                            (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
3945                 (match_operand:SI 3 "mask_operand" "n,n")))]
3946   ""
3947   "@
3948    {rlnm|rlwnm} %0,%1,%2,%m3,%M3
3949    {rlinm|rlwinm} %0,%1,%h2,%m3,%M3"
3950   [(set_attr "type" "var_shift_rotate,integer")])
3951
3952 (define_insn "*rotlsi3_internal5"
3953   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3954         (compare:CC (and:SI
3955                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3956                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3957                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
3958                     (const_int 0)))
3959    (clobber (match_scratch:SI 4 "=r,r,r,r"))]
3960   ""
3961   "@
3962    {rlnm.|rlwnm.} %4,%1,%2,%m3,%M3
3963    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
3964    #
3965    #"
3966   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3967    (set_attr "length" "4,4,8,8")])
3968
3969 (define_split
3970   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3971         (compare:CC (and:SI
3972                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3973                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3974                      (match_operand:SI 3 "mask_operand" ""))
3975                     (const_int 0)))
3976    (clobber (match_scratch:SI 4 ""))]
3977   "reload_completed"
3978   [(set (match_dup 4)
3979         (and:SI (rotate:SI (match_dup 1)
3980                                 (match_dup 2))
3981                      (match_dup 3)))
3982    (set (match_dup 0)
3983         (compare:CC (match_dup 4)
3984                     (const_int 0)))]
3985   "")
3986
3987 (define_insn "*rotlsi3_internal6"
3988   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
3989         (compare:CC (and:SI
3990                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3991                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3992                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
3993                     (const_int 0)))
3994    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3995         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3996   ""
3997   "@
3998    {rlnm.|rlwnm.} %0,%1,%2,%m3,%M3
3999    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
4000    #
4001    #"
4002   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4003    (set_attr "length" "4,4,8,8")])
4004
4005 (define_split
4006   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4007         (compare:CC (and:SI
4008                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4009                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
4010                      (match_operand:SI 3 "mask_operand" ""))
4011                     (const_int 0)))
4012    (set (match_operand:SI 0 "gpc_reg_operand" "")
4013         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4014   "reload_completed"
4015   [(set (match_dup 0)
4016         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4017    (set (match_dup 4)
4018         (compare:CC (match_dup 0)
4019                     (const_int 0)))]
4020   "")
4021
4022 (define_insn "*rotlsi3_internal7"
4023   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4024         (zero_extend:SI
4025          (subreg:QI
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,0xff")
4030
4031 (define_insn "*rotlsi3_internal8"
4032   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4033         (compare:CC (zero_extend:SI
4034                      (subreg:QI
4035                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4036                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4037                     (const_int 0)))
4038    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4039   ""
4040   "@
4041    {rlnm.|rlwnm.} %3,%1,%2,0xff
4042    {rlinm.|rlwinm.} %3,%1,%h2,0xff
4043    #
4044    #"
4045   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4046    (set_attr "length" "4,4,8,8")])
4047
4048 (define_split
4049   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4050         (compare:CC (zero_extend:SI
4051                      (subreg:QI
4052                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4053                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4054                     (const_int 0)))
4055    (clobber (match_scratch:SI 3 ""))]
4056   "reload_completed"
4057   [(set (match_dup 3)
4058         (zero_extend:SI (subreg:QI
4059                       (rotate:SI (match_dup 1)
4060                                  (match_dup 2)) 0)))
4061    (set (match_dup 0)
4062         (compare:CC (match_dup 3)
4063                     (const_int 0)))]
4064   "")
4065
4066 (define_insn "*rotlsi3_internal9"
4067   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4068         (compare:CC (zero_extend:SI
4069                      (subreg:QI
4070                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4071                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4072                     (const_int 0)))
4073    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4074         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4075   ""
4076   "@
4077    {rlnm.|rlwnm.} %0,%1,%2,0xff
4078    {rlinm.|rlwinm.} %0,%1,%h2,0xff
4079    #
4080    #"
4081   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4082    (set_attr "length" "4,4,8,8")])
4083
4084 (define_split
4085   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4086         (compare:CC (zero_extend:SI
4087                      (subreg:QI
4088                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4089                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4090                     (const_int 0)))
4091    (set (match_operand:SI 0 "gpc_reg_operand" "")
4092         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4093   "reload_completed"
4094   [(set (match_dup 0)
4095         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4096    (set (match_dup 3)
4097         (compare:CC (match_dup 0)
4098                     (const_int 0)))]
4099   "")
4100
4101 (define_insn "*rotlsi3_internal10"
4102   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4103         (zero_extend:SI
4104          (subreg:HI
4105           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4106                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")) 0)))]
4107   ""
4108   "@
4109    {rlnm|rlwnm} %0,%1,%2,0xffff
4110    {rlinm|rlwinm} %0,%1,%h2,0xffff"
4111   [(set_attr "type" "var_shift_rotate,integer")])
4112
4113
4114 (define_insn "*rotlsi3_internal11"
4115   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4116         (compare:CC (zero_extend:SI
4117                      (subreg:HI
4118                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4119                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4120                     (const_int 0)))
4121    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4122   ""
4123   "@
4124    {rlnm.|rlwnm.} %3,%1,%2,0xffff
4125    {rlinm.|rlwinm.} %3,%1,%h2,0xffff
4126    #
4127    #"
4128   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4129    (set_attr "length" "4,4,8,8")])
4130
4131 (define_split
4132   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4133         (compare:CC (zero_extend:SI
4134                      (subreg:HI
4135                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4136                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4137                     (const_int 0)))
4138    (clobber (match_scratch:SI 3 ""))]
4139   "reload_completed"
4140   [(set (match_dup 3)
4141         (zero_extend:SI (subreg:HI
4142                       (rotate:SI (match_dup 1)
4143                                  (match_dup 2)) 0)))
4144    (set (match_dup 0)
4145         (compare:CC (match_dup 3)
4146                     (const_int 0)))]
4147   "")
4148
4149 (define_insn "*rotlsi3_internal12"
4150   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4151         (compare:CC (zero_extend:SI
4152                      (subreg:HI
4153                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4154                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4155                     (const_int 0)))
4156    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4157         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4158   ""
4159   "@
4160    {rlnm.|rlwnm.} %0,%1,%2,0xffff
4161    {rlinm.|rlwinm.} %0,%1,%h2,0xffff
4162    #
4163    #"
4164   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4165    (set_attr "length" "4,4,8,8")])
4166
4167 (define_split
4168   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4169         (compare:CC (zero_extend:SI
4170                      (subreg:HI
4171                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4172                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4173                     (const_int 0)))
4174    (set (match_operand:SI 0 "gpc_reg_operand" "")
4175         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4176   "reload_completed"
4177   [(set (match_dup 0)
4178         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4179    (set (match_dup 3)
4180         (compare:CC (match_dup 0)
4181                     (const_int 0)))]
4182   "")
4183
4184 ;; Note that we use "sle." instead of "sl." so that we can set
4185 ;; SHIFT_COUNT_TRUNCATED.
4186
4187 (define_expand "ashlsi3"
4188   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
4189    (use (match_operand:SI 1 "gpc_reg_operand" ""))
4190    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
4191   ""
4192   "
4193 {
4194   if (TARGET_POWER)
4195     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
4196   else
4197     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
4198   DONE;
4199 }")
4200
4201 (define_insn "ashlsi3_power"
4202   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4203         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4204                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4205    (clobber (match_scratch:SI 3 "=q,X"))]
4206   "TARGET_POWER"
4207   "@
4208    sle %0,%1,%2
4209    {sli|slwi} %0,%1,%h2")
4210
4211 (define_insn "ashlsi3_no_power"
4212   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4213         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4214                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
4215   "! TARGET_POWER"
4216   "@
4217    {sl|slw} %0,%1,%2
4218    {sli|slwi} %0,%1,%h2"
4219   [(set_attr "type" "var_shift_rotate,shift")])
4220
4221 (define_insn ""
4222   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4223         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4224                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4225                     (const_int 0)))
4226    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4227    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4228   "TARGET_POWER"
4229   "@
4230    sle. %3,%1,%2
4231    {sli.|slwi.} %3,%1,%h2
4232    #
4233    #"
4234   [(set_attr "type" "delayed_compare")
4235    (set_attr "length" "4,4,8,8")])
4236
4237 (define_split
4238   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4239         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4240                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4241                     (const_int 0)))
4242    (clobber (match_scratch:SI 3 ""))
4243    (clobber (match_scratch:SI 4 ""))]
4244   "TARGET_POWER && reload_completed"
4245   [(parallel [(set (match_dup 3)
4246         (ashift:SI (match_dup 1) (match_dup 2)))
4247    (clobber (match_dup 4))])
4248    (set (match_dup 0)
4249         (compare:CC (match_dup 3)
4250                     (const_int 0)))]
4251   "")
4252
4253 (define_insn ""
4254   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4255         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4256                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4257                     (const_int 0)))
4258    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4259   "! TARGET_POWER && TARGET_32BIT"
4260   "@
4261    {sl.|slw.} %3,%1,%2
4262    {sli.|slwi.} %3,%1,%h2
4263    #
4264    #"
4265   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4266    (set_attr "length" "4,4,8,8")])
4267
4268 (define_split
4269   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4270         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4271                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4272                     (const_int 0)))
4273    (clobber (match_scratch:SI 3 ""))]
4274   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4275   [(set (match_dup 3)
4276         (ashift:SI (match_dup 1) (match_dup 2)))
4277    (set (match_dup 0)
4278         (compare:CC (match_dup 3)
4279                     (const_int 0)))]
4280   "")
4281
4282 (define_insn ""
4283   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4284         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4285                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4286                     (const_int 0)))
4287    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4288         (ashift:SI (match_dup 1) (match_dup 2)))
4289    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4290   "TARGET_POWER"
4291   "@
4292    sle. %0,%1,%2
4293    {sli.|slwi.} %0,%1,%h2
4294    #
4295    #"
4296   [(set_attr "type" "delayed_compare")
4297    (set_attr "length" "4,4,8,8")])
4298
4299 (define_split
4300   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4301         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4302                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4303                     (const_int 0)))
4304    (set (match_operand:SI 0 "gpc_reg_operand" "")
4305         (ashift:SI (match_dup 1) (match_dup 2)))
4306    (clobber (match_scratch:SI 4 ""))]
4307   "TARGET_POWER && reload_completed"
4308   [(parallel [(set (match_dup 0)
4309         (ashift:SI (match_dup 1) (match_dup 2)))
4310    (clobber (match_dup 4))])
4311    (set (match_dup 3)
4312         (compare:CC (match_dup 0)
4313                     (const_int 0)))]
4314   "")
4315
4316 (define_insn ""
4317   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4318         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4319                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4320                     (const_int 0)))
4321    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4322         (ashift:SI (match_dup 1) (match_dup 2)))]
4323   "! TARGET_POWER && TARGET_32BIT"
4324   "@
4325    {sl.|slw.} %0,%1,%2
4326    {sli.|slwi.} %0,%1,%h2
4327    #
4328    #"
4329   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4330    (set_attr "length" "4,4,8,8")])
4331
4332 (define_split
4333   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4334         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4335                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4336                     (const_int 0)))
4337    (set (match_operand:SI 0 "gpc_reg_operand" "")
4338         (ashift:SI (match_dup 1) (match_dup 2)))]
4339   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4340   [(set (match_dup 0)
4341         (ashift:SI (match_dup 1) (match_dup 2)))
4342    (set (match_dup 3)
4343         (compare:CC (match_dup 0)
4344                     (const_int 0)))]
4345   "")
4346
4347 (define_insn "rlwinm"
4348   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4349         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4350                            (match_operand:SI 2 "const_int_operand" "i"))
4351                 (match_operand:SI 3 "mask_operand" "n")))]
4352   "includes_lshift_p (operands[2], operands[3])"
4353   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
4354
4355 (define_insn ""
4356   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4357         (compare:CC
4358          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4359                             (match_operand:SI 2 "const_int_operand" "i,i"))
4360                  (match_operand:SI 3 "mask_operand" "n,n"))
4361          (const_int 0)))
4362    (clobber (match_scratch:SI 4 "=r,r"))]
4363   "includes_lshift_p (operands[2], operands[3])"
4364   "@
4365    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
4366    #"
4367   [(set_attr "type" "delayed_compare")
4368    (set_attr "length" "4,8")])
4369
4370 (define_split
4371   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4372         (compare:CC
4373          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4374                             (match_operand:SI 2 "const_int_operand" ""))
4375                  (match_operand:SI 3 "mask_operand" ""))
4376          (const_int 0)))
4377    (clobber (match_scratch:SI 4 ""))]
4378   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4379   [(set (match_dup 4)
4380         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
4381                  (match_dup 3)))
4382    (set (match_dup 0)
4383         (compare:CC (match_dup 4)
4384                     (const_int 0)))]
4385   "")
4386
4387 (define_insn ""
4388   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4389         (compare:CC
4390          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4391                             (match_operand:SI 2 "const_int_operand" "i,i"))
4392                  (match_operand:SI 3 "mask_operand" "n,n"))
4393          (const_int 0)))
4394    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4395         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4396   "includes_lshift_p (operands[2], operands[3])"
4397   "@
4398    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
4399    #"
4400   [(set_attr "type" "delayed_compare")
4401    (set_attr "length" "4,8")])
4402
4403 (define_split
4404   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4405         (compare:CC
4406          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4407                             (match_operand:SI 2 "const_int_operand" ""))
4408                  (match_operand:SI 3 "mask_operand" ""))
4409          (const_int 0)))
4410    (set (match_operand:SI 0 "gpc_reg_operand" "")
4411         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4412   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4413   [(set (match_dup 0)
4414         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4415    (set (match_dup 4)
4416         (compare:CC (match_dup 0)
4417                     (const_int 0)))]
4418   "")
4419
4420 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
4421 ;; "sli x,x,0".
4422 (define_expand "lshrsi3"
4423   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
4424    (use (match_operand:SI 1 "gpc_reg_operand" ""))
4425    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
4426   ""
4427   "
4428 {
4429   if (TARGET_POWER)
4430     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
4431   else
4432     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
4433   DONE;
4434 }")
4435
4436 (define_insn "lshrsi3_power"
4437   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
4438         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
4439                      (match_operand:SI 2 "reg_or_cint_operand" "r,O,i")))
4440    (clobber (match_scratch:SI 3 "=q,X,X"))]
4441   "TARGET_POWER"
4442   "@
4443   sre %0,%1,%2
4444   mr %0,%1
4445   {s%A2i|s%A2wi} %0,%1,%h2")
4446
4447 (define_insn "lshrsi3_no_power"
4448   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
4449         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
4450                      (match_operand:SI 2 "reg_or_cint_operand" "O,r,i")))]
4451   "! TARGET_POWER"
4452   "@
4453   mr %0,%1
4454   {sr|srw} %0,%1,%2
4455   {sri|srwi} %0,%1,%h2"
4456   [(set_attr "type" "integer,var_shift_rotate,shift")])
4457
4458 (define_insn ""
4459   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4460         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4461                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
4462                     (const_int 0)))
4463    (clobber (match_scratch:SI 3 "=r,X,r,r,X,r"))
4464    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
4465   "TARGET_POWER"
4466   "@
4467   sre. %3,%1,%2
4468   mr. %1,%1
4469   {s%A2i.|s%A2wi.} %3,%1,%h2
4470   #
4471   #
4472   #"
4473   [(set_attr "type" "delayed_compare")
4474    (set_attr "length" "4,4,4,8,8,8")])
4475
4476 (define_split
4477   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4478         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4479                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4480                     (const_int 0)))
4481    (clobber (match_scratch:SI 3 ""))
4482    (clobber (match_scratch:SI 4 ""))]
4483   "TARGET_POWER && reload_completed"
4484   [(parallel [(set (match_dup 3)
4485         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4486    (clobber (match_dup 4))])
4487    (set (match_dup 0)
4488         (compare:CC (match_dup 3)
4489                     (const_int 0)))]
4490   "")
4491
4492 (define_insn ""
4493   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4494         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4495                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
4496                     (const_int 0)))
4497    (clobber (match_scratch:SI 3 "=X,r,r,X,r,r"))]
4498   "! TARGET_POWER && TARGET_32BIT"
4499   "@
4500    mr. %1,%1
4501    {sr.|srw.} %3,%1,%2
4502    {sri.|srwi.} %3,%1,%h2
4503    #
4504    #
4505    #"
4506   [(set_attr "type" "delayed_compare,var_delayed_compare,delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4507    (set_attr "length" "4,4,4,8,8,8")])
4508
4509 (define_split
4510   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4511         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4512                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4513                     (const_int 0)))
4514    (clobber (match_scratch:SI 3 ""))]
4515   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4516   [(set (match_dup 3)
4517         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4518    (set (match_dup 0)
4519         (compare:CC (match_dup 3)
4520                     (const_int 0)))]
4521   "")
4522
4523 (define_insn ""
4524   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4525         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4526                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
4527                     (const_int 0)))
4528    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
4529         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4530    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
4531   "TARGET_POWER"
4532   "@
4533   sre. %0,%1,%2
4534   mr. %0,%1
4535   {s%A2i.|s%A2wi.} %0,%1,%h2
4536   #
4537   #
4538   #"
4539   [(set_attr "type" "delayed_compare")
4540    (set_attr "length" "4,4,4,8,8,8")])
4541
4542 (define_split
4543   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4544         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4545                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4546                     (const_int 0)))
4547    (set (match_operand:SI 0 "gpc_reg_operand" "")
4548         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4549    (clobber (match_scratch:SI 4 ""))]
4550   "TARGET_POWER && reload_completed"
4551   [(parallel [(set (match_dup 0)
4552         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4553    (clobber (match_dup 4))])
4554    (set (match_dup 3)
4555         (compare:CC (match_dup 0)
4556                     (const_int 0)))]
4557   "")
4558
4559 (define_insn ""
4560   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4561         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4562                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
4563                     (const_int 0)))
4564    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
4565         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4566   "! TARGET_POWER && TARGET_32BIT"
4567   "@
4568    mr. %0,%1
4569    {sr.|srw.} %0,%1,%2
4570    {sri.|srwi.} %0,%1,%h2
4571    #
4572    #
4573    #"
4574   [(set_attr "type" "delayed_compare,var_delayed_compare,delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4575    (set_attr "length" "4,4,4,8,8,8")])
4576
4577 (define_split
4578   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4579         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4580                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4581                     (const_int 0)))
4582    (set (match_operand:SI 0 "gpc_reg_operand" "")
4583         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4584   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4585   [(set (match_dup 0)
4586         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4587    (set (match_dup 3)
4588         (compare:CC (match_dup 0)
4589                     (const_int 0)))]
4590   "")
4591
4592 (define_insn ""
4593   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4594         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4595                              (match_operand:SI 2 "const_int_operand" "i"))
4596                 (match_operand:SI 3 "mask_operand" "n")))]
4597   "includes_rshift_p (operands[2], operands[3])"
4598   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
4599
4600 (define_insn ""
4601   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4602         (compare:CC
4603          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4604                               (match_operand:SI 2 "const_int_operand" "i,i"))
4605                  (match_operand:SI 3 "mask_operand" "n,n"))
4606          (const_int 0)))
4607    (clobber (match_scratch:SI 4 "=r,r"))]
4608   "includes_rshift_p (operands[2], operands[3])"
4609   "@
4610    {rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3
4611    #"
4612   [(set_attr "type" "delayed_compare")
4613    (set_attr "length" "4,8")])
4614
4615 (define_split
4616   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4617         (compare:CC
4618          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4619                               (match_operand:SI 2 "const_int_operand" ""))
4620                  (match_operand:SI 3 "mask_operand" ""))
4621          (const_int 0)))
4622    (clobber (match_scratch:SI 4 ""))]
4623   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4624   [(set (match_dup 4)
4625         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
4626                  (match_dup 3)))
4627    (set (match_dup 0)
4628         (compare:CC (match_dup 4)
4629                     (const_int 0)))]
4630   "")
4631
4632 (define_insn ""
4633   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4634         (compare:CC
4635          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4636                               (match_operand:SI 2 "const_int_operand" "i,i"))
4637                  (match_operand:SI 3 "mask_operand" "n,n"))
4638          (const_int 0)))
4639    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4640         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4641   "includes_rshift_p (operands[2], operands[3])"
4642   "@
4643    {rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3
4644    #"
4645   [(set_attr "type" "delayed_compare")
4646    (set_attr "length" "4,8")])
4647
4648 (define_split
4649   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4650         (compare:CC
4651          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4652                               (match_operand:SI 2 "const_int_operand" ""))
4653                  (match_operand:SI 3 "mask_operand" ""))
4654          (const_int 0)))
4655    (set (match_operand:SI 0 "gpc_reg_operand" "")
4656         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4657   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4658   [(set (match_dup 0)
4659         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4660    (set (match_dup 4)
4661         (compare:CC (match_dup 0)
4662                     (const_int 0)))]
4663   "")
4664
4665 (define_insn ""
4666   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4667         (zero_extend:SI
4668          (subreg:QI
4669           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4670                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4671   "includes_rshift_p (operands[2], GEN_INT (255))"
4672   "{rlinm|rlwinm} %0,%1,%s2,0xff")
4673
4674 (define_insn ""
4675   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4676         (compare:CC
4677          (zero_extend:SI
4678           (subreg:QI
4679            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4680                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4681          (const_int 0)))
4682    (clobber (match_scratch:SI 3 "=r,r"))]
4683   "includes_rshift_p (operands[2], GEN_INT (255))"
4684   "@
4685    {rlinm.|rlwinm.} %3,%1,%s2,0xff
4686    #"
4687   [(set_attr "type" "delayed_compare")
4688    (set_attr "length" "4,8")])
4689
4690 (define_split
4691   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4692         (compare:CC
4693          (zero_extend:SI
4694           (subreg:QI
4695            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4696                         (match_operand:SI 2 "const_int_operand" "")) 0))
4697          (const_int 0)))
4698    (clobber (match_scratch:SI 3 ""))]
4699   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4700   [(set (match_dup 3)
4701         (zero_extend:SI (subreg:QI
4702            (lshiftrt:SI (match_dup 1)
4703                         (match_dup 2)) 0)))
4704    (set (match_dup 0)
4705         (compare:CC (match_dup 3)
4706                     (const_int 0)))]
4707   "")
4708
4709 (define_insn ""
4710   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4711         (compare:CC
4712          (zero_extend:SI
4713           (subreg:QI
4714            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4715                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4716          (const_int 0)))
4717    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4718         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4719   "includes_rshift_p (operands[2], GEN_INT (255))"
4720   "@
4721    {rlinm.|rlwinm.} %0,%1,%s2,0xff
4722    #"
4723   [(set_attr "type" "delayed_compare")
4724    (set_attr "length" "4,8")])
4725
4726 (define_split
4727   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4728         (compare:CC
4729          (zero_extend:SI
4730           (subreg:QI
4731            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4732                         (match_operand:SI 2 "const_int_operand" "")) 0))
4733          (const_int 0)))
4734    (set (match_operand:SI 0 "gpc_reg_operand" "")
4735         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4736   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4737   [(set (match_dup 0)
4738         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4739    (set (match_dup 3)
4740         (compare:CC (match_dup 0)
4741                     (const_int 0)))]
4742   "")
4743
4744 (define_insn ""
4745   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4746         (zero_extend:SI
4747          (subreg:HI
4748           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4749                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4750   "includes_rshift_p (operands[2], GEN_INT (65535))"
4751   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
4752
4753 (define_insn ""
4754   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4755         (compare:CC
4756          (zero_extend:SI
4757           (subreg:HI
4758            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4759                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4760          (const_int 0)))
4761    (clobber (match_scratch:SI 3 "=r,r"))]
4762   "includes_rshift_p (operands[2], GEN_INT (65535))"
4763   "@
4764    {rlinm.|rlwinm.} %3,%1,%s2,0xffff
4765    #"
4766   [(set_attr "type" "delayed_compare")
4767    (set_attr "length" "4,8")])
4768
4769 (define_split
4770   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4771         (compare:CC
4772          (zero_extend:SI
4773           (subreg:HI
4774            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4775                         (match_operand:SI 2 "const_int_operand" "")) 0))
4776          (const_int 0)))
4777    (clobber (match_scratch:SI 3 ""))]
4778   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4779   [(set (match_dup 3)
4780         (zero_extend:SI (subreg:HI
4781            (lshiftrt:SI (match_dup 1)
4782                         (match_dup 2)) 0)))
4783    (set (match_dup 0)
4784         (compare:CC (match_dup 3)
4785                     (const_int 0)))]
4786   "")
4787
4788 (define_insn ""
4789   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4790         (compare:CC
4791          (zero_extend:SI
4792           (subreg:HI
4793            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4794                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4795          (const_int 0)))
4796    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4797         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4798   "includes_rshift_p (operands[2], GEN_INT (65535))"
4799   "@
4800    {rlinm.|rlwinm.} %0,%1,%s2,0xffff
4801    #"
4802   [(set_attr "type" "delayed_compare")
4803    (set_attr "length" "4,8")])
4804
4805 (define_split
4806   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4807         (compare:CC
4808          (zero_extend:SI
4809           (subreg:HI
4810            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4811                         (match_operand:SI 2 "const_int_operand" "")) 0))
4812          (const_int 0)))
4813    (set (match_operand:SI 0 "gpc_reg_operand" "")
4814         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4815   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4816   [(set (match_dup 0)
4817         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4818    (set (match_dup 3)
4819         (compare:CC (match_dup 0)
4820                     (const_int 0)))]
4821   "")
4822
4823 (define_insn ""
4824   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4825                          (const_int 1)
4826                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4827         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4828                      (const_int 31)))]
4829   "TARGET_POWER"
4830   "rrib %0,%1,%2")
4831
4832 (define_insn ""
4833   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4834                          (const_int 1)
4835                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4836         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4837                      (const_int 31)))]
4838   "TARGET_POWER"
4839   "rrib %0,%1,%2")
4840
4841 (define_insn ""
4842   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4843                          (const_int 1)
4844                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4845         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4846                          (const_int 1)
4847                          (const_int 0)))]
4848   "TARGET_POWER"
4849   "rrib %0,%1,%2")
4850
4851 (define_expand "ashrsi3"
4852   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4853         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4854                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
4855   ""
4856   "
4857 {
4858   if (TARGET_POWER)
4859     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
4860   else
4861     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
4862   DONE;
4863 }")
4864
4865 (define_insn "ashrsi3_power"
4866   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4867         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4868                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4869    (clobber (match_scratch:SI 3 "=q,X"))]
4870   "TARGET_POWER"
4871   "@
4872    srea %0,%1,%2
4873    {srai|srawi} %0,%1,%h2"
4874   [(set_attr "type" "shift")])
4875
4876 (define_insn "ashrsi3_no_power"
4877   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4878         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4879                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
4880   "! TARGET_POWER"
4881   "@
4882    {sra|sraw} %0,%1,%2
4883    {srai|srawi} %0,%1,%h2"
4884   [(set_attr "type" "var_shift_rotate,shift")])
4885
4886 (define_insn ""
4887   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4888         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4889                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4890                     (const_int 0)))
4891    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4892    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4893   "TARGET_POWER"
4894   "@
4895    srea. %3,%1,%2
4896    {srai.|srawi.} %3,%1,%h2
4897    #
4898    #"
4899   [(set_attr "type" "delayed_compare")
4900    (set_attr "length" "4,4,8,8")])
4901
4902 (define_split
4903   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4904         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4905                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4906                     (const_int 0)))
4907    (clobber (match_scratch:SI 3 ""))
4908    (clobber (match_scratch:SI 4 ""))]
4909   "TARGET_POWER && reload_completed"
4910   [(parallel [(set (match_dup 3)
4911         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4912    (clobber (match_dup 4))])
4913    (set (match_dup 0)
4914         (compare:CC (match_dup 3)
4915                     (const_int 0)))]
4916   "")
4917
4918 (define_insn ""
4919   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4920         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4921                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4922                     (const_int 0)))
4923    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4924   "! TARGET_POWER"
4925   "@
4926    {sra.|sraw.} %3,%1,%2
4927    {srai.|srawi.} %3,%1,%h2
4928    #
4929    #"
4930   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4931    (set_attr "length" "4,4,8,8")])
4932
4933 (define_split
4934   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4935         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4936                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4937                     (const_int 0)))
4938    (clobber (match_scratch:SI 3 ""))]
4939   "! TARGET_POWER && reload_completed"
4940   [(set (match_dup 3)
4941         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4942    (set (match_dup 0)
4943         (compare:CC (match_dup 3)
4944                     (const_int 0)))]
4945   "")
4946
4947 (define_insn ""
4948   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4949         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4950                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4951                     (const_int 0)))
4952    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4953         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4954    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4955   "TARGET_POWER"
4956   "@
4957    srea. %0,%1,%2
4958    {srai.|srawi.} %0,%1,%h2
4959    #
4960    #"
4961   [(set_attr "type" "delayed_compare")
4962    (set_attr "length" "4,4,8,8")])
4963
4964 (define_split
4965   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4966         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4967                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4968                     (const_int 0)))
4969    (set (match_operand:SI 0 "gpc_reg_operand" "")
4970         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4971    (clobber (match_scratch:SI 4 ""))]
4972   "TARGET_POWER && reload_completed"
4973   [(parallel [(set (match_dup 0)
4974         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4975    (clobber (match_dup 4))])
4976    (set (match_dup 3)
4977         (compare:CC (match_dup 0)
4978                     (const_int 0)))]
4979   "")
4980
4981 (define_insn ""
4982   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4983         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4984                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4985                     (const_int 0)))
4986    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4987         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4988   "! TARGET_POWER"
4989   "@
4990    {sra.|sraw.} %0,%1,%2
4991    {srai.|srawi.} %0,%1,%h2
4992    #
4993    #"
4994   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4995    (set_attr "length" "4,4,8,8")])
4996 \f
4997 (define_split
4998   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4999         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5000                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5001                     (const_int 0)))
5002    (set (match_operand:SI 0 "gpc_reg_operand" "")
5003         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
5004   "! TARGET_POWER && reload_completed"
5005   [(set (match_dup 0)
5006         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5007    (set (match_dup 3)
5008         (compare:CC (match_dup 0)
5009                     (const_int 0)))]
5010   "")
5011
5012 ;; Floating-point insns, excluding normal data motion.
5013 ;;
5014 ;; PowerPC has a full set of single-precision floating point instructions.
5015 ;;
5016 ;; For the POWER architecture, we pretend that we have both SFmode and
5017 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
5018 ;; The only conversions we will do will be when storing to memory.  In that
5019 ;; case, we will use the "frsp" instruction before storing.
5020 ;;
5021 ;; Note that when we store into a single-precision memory location, we need to
5022 ;; use the frsp insn first.  If the register being stored isn't dead, we
5023 ;; need a scratch register for the frsp.  But this is difficult when the store
5024 ;; is done by reload.  It is not incorrect to do the frsp on the register in
5025 ;; this case, we just lose precision that we would have otherwise gotten but
5026 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
5027
5028 (define_expand "extendsfdf2"
5029   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5030         (float_extend:DF (match_operand:SF 1 "reg_or_none500mem_operand" "")))]
5031   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5032   "")
5033
5034 (define_insn_and_split "*extendsfdf2_fpr"
5035   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,?f,f")
5036         (float_extend:DF (match_operand:SF 1 "reg_or_mem_operand" "0,f,m")))]
5037   "TARGET_HARD_FLOAT && TARGET_FPRS"
5038   "@
5039    #
5040    fmr %0,%1
5041    lfs%U1%X1 %0,%1"
5042   "&& reload_completed && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])"
5043   [(const_int 0)]
5044 {
5045   emit_note (NOTE_INSN_DELETED);
5046   DONE;
5047 }
5048   [(set_attr "type" "fp,fp,fpload")])
5049
5050 (define_expand "truncdfsf2"
5051   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5052         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "")))]
5053   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5054   "")
5055
5056 (define_insn "*truncdfsf2_fpr"
5057   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5058         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5059   "TARGET_HARD_FLOAT && TARGET_FPRS"
5060   "frsp %0,%1"
5061   [(set_attr "type" "fp")])
5062
5063 (define_insn "aux_truncdfsf2"
5064   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5065         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRSP))]
5066   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5067   "frsp %0,%1"
5068   [(set_attr "type" "fp")])
5069
5070 (define_expand "negsf2"
5071   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5072         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5073   "TARGET_HARD_FLOAT"
5074   "")
5075
5076 (define_insn "*negsf2"
5077   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5078         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5079   "TARGET_HARD_FLOAT && TARGET_FPRS"
5080   "fneg %0,%1"
5081   [(set_attr "type" "fp")])
5082
5083 (define_expand "abssf2"
5084   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5085         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5086   "TARGET_HARD_FLOAT"
5087   "")
5088
5089 (define_insn "*abssf2"
5090   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5091         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5092   "TARGET_HARD_FLOAT && TARGET_FPRS"
5093   "fabs %0,%1"
5094   [(set_attr "type" "fp")])
5095
5096 (define_insn ""
5097   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5098         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
5099   "TARGET_HARD_FLOAT && TARGET_FPRS"
5100   "fnabs %0,%1"
5101   [(set_attr "type" "fp")])
5102
5103 (define_expand "addsf3"
5104   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5105         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
5106                  (match_operand:SF 2 "gpc_reg_operand" "")))]
5107   "TARGET_HARD_FLOAT"
5108   "")
5109
5110 (define_insn ""
5111   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5112         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5113                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5114   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5115   "fadds %0,%1,%2"
5116   [(set_attr "type" "fp")])
5117
5118 (define_insn ""
5119   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5120         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5121                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5122   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5123   "{fa|fadd} %0,%1,%2"
5124   [(set_attr "type" "fp")])
5125
5126 (define_expand "subsf3"
5127   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5128         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
5129                   (match_operand:SF 2 "gpc_reg_operand" "")))]
5130   "TARGET_HARD_FLOAT"
5131   "")
5132
5133 (define_insn ""
5134   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5135         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5136                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
5137   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5138   "fsubs %0,%1,%2"
5139   [(set_attr "type" "fp")])
5140
5141 (define_insn ""
5142   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5143         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5144                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
5145   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5146   "{fs|fsub} %0,%1,%2"
5147   [(set_attr "type" "fp")])
5148
5149 (define_expand "mulsf3"
5150   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5151         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
5152                  (match_operand:SF 2 "gpc_reg_operand" "")))]
5153   "TARGET_HARD_FLOAT"
5154   "")
5155
5156 (define_insn ""
5157   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5158         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5159                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5160   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5161   "fmuls %0,%1,%2"
5162   [(set_attr "type" "fp")])
5163
5164 (define_insn ""
5165   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5166         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5167                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5168   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5169   "{fm|fmul} %0,%1,%2"
5170   [(set_attr "type" "dmul")])
5171
5172 (define_insn "fres"
5173   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5174         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
5175   "TARGET_PPC_GFXOPT && flag_finite_math_only"
5176   "fres %0,%1"
5177   [(set_attr "type" "fp")])
5178
5179 (define_expand "divsf3"
5180   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5181         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
5182                 (match_operand:SF 2 "gpc_reg_operand" "")))]
5183   "TARGET_HARD_FLOAT"
5184 {
5185   if (swdiv && !optimize_size && TARGET_PPC_GFXOPT
5186   && flag_finite_math_only && !flag_trapping_math)
5187     {
5188       rs6000_emit_swdivsf (operands[0], operands[1], operands[2]);
5189       DONE;
5190     }
5191 })
5192
5193 (define_insn ""
5194   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5195         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5196                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5197   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5198   "fdivs %0,%1,%2"
5199   [(set_attr "type" "sdiv")])
5200
5201 (define_insn ""
5202   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5203         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5204                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5205   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5206   "{fd|fdiv} %0,%1,%2"
5207   [(set_attr "type" "ddiv")])
5208
5209 (define_insn ""
5210   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5211         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5212                           (match_operand:SF 2 "gpc_reg_operand" "f"))
5213                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
5214   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5215   "fmadds %0,%1,%2,%3"
5216   [(set_attr "type" "fp")])
5217
5218 (define_insn ""
5219   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5220         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5221                           (match_operand:SF 2 "gpc_reg_operand" "f"))
5222                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
5223   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5224   "{fma|fmadd} %0,%1,%2,%3"
5225   [(set_attr "type" "dmul")])
5226
5227 (define_insn ""
5228   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5229         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5230                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5231                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
5232   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5233   "fmsubs %0,%1,%2,%3"
5234   [(set_attr "type" "fp")])
5235
5236 (define_insn ""
5237   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5238         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5239                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5240                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
5241   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5242   "{fms|fmsub} %0,%1,%2,%3"
5243   [(set_attr "type" "dmul")])
5244
5245 (define_insn ""
5246   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5247         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5248                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
5249                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5250   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5251    && HONOR_SIGNED_ZEROS (SFmode)"
5252   "fnmadds %0,%1,%2,%3"
5253   [(set_attr "type" "fp")])
5254
5255 (define_insn ""
5256   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5257         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
5258                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5259                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5260   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5261    && ! HONOR_SIGNED_ZEROS (SFmode)"
5262   "fnmadds %0,%1,%2,%3"
5263   [(set_attr "type" "fp")])
5264
5265 (define_insn ""
5266   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5267         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5268                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
5269                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5270   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5271   "{fnma|fnmadd} %0,%1,%2,%3"
5272   [(set_attr "type" "dmul")])
5273
5274 (define_insn ""
5275   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5276         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
5277                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5278                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5279   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5280    && ! HONOR_SIGNED_ZEROS (SFmode)"
5281   "{fnma|fnmadd} %0,%1,%2,%3"
5282   [(set_attr "type" "dmul")])
5283
5284 (define_insn ""
5285   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5286         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5287                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
5288                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5289   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5290    && HONOR_SIGNED_ZEROS (SFmode)"
5291   "fnmsubs %0,%1,%2,%3"
5292   [(set_attr "type" "fp")])
5293
5294 (define_insn ""
5295   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5296         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
5297                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5298                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
5299   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5300    && ! HONOR_SIGNED_ZEROS (SFmode)"
5301   "fnmsubs %0,%1,%2,%3"
5302   [(set_attr "type" "fp")])
5303
5304 (define_insn ""
5305   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5306         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5307                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
5308                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5309   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5310   "{fnms|fnmsub} %0,%1,%2,%3"
5311   [(set_attr "type" "dmul")])
5312
5313 (define_insn ""
5314   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5315         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
5316                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5317                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
5318   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5319    && ! HONOR_SIGNED_ZEROS (SFmode)"
5320   "{fnms|fnmsub} %0,%1,%2,%3"
5321   [(set_attr "type" "dmul")])
5322
5323 (define_expand "sqrtsf2"
5324   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5325         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5326   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
5327   "")
5328
5329 (define_insn ""
5330   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5331         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5332   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5333   "fsqrts %0,%1"
5334   [(set_attr "type" "ssqrt")])
5335
5336 (define_insn ""
5337   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5338         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5339   "TARGET_POWER2 && TARGET_HARD_FLOAT && TARGET_FPRS"
5340   "fsqrt %0,%1"
5341   [(set_attr "type" "dsqrt")])
5342
5343 (define_expand "copysignsf3"
5344   [(set (match_dup 3)
5345         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))
5346    (set (match_dup 4)
5347         (neg:SF (abs:SF (match_dup 1))))
5348    (set (match_operand:SF 0 "gpc_reg_operand" "")
5349         (if_then_else:SF (ge (match_operand:SF 2 "gpc_reg_operand" "")
5350                              (match_dup 5))
5351                          (match_dup 3)
5352                          (match_dup 4)))]
5353   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS
5354    && !HONOR_NANS (SFmode) && !HONOR_SIGNED_ZEROS (SFmode)"
5355   {
5356      operands[3] = gen_reg_rtx (SFmode);
5357      operands[4] = gen_reg_rtx (SFmode);
5358      operands[5] = CONST0_RTX (SFmode);
5359   })
5360
5361 (define_expand "copysigndf3"
5362   [(set (match_dup 3)
5363         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))
5364    (set (match_dup 4)
5365         (neg:DF (abs:DF (match_dup 1))))
5366    (set (match_operand:DF 0 "gpc_reg_operand" "")
5367         (if_then_else:DF (ge (match_operand:DF 2 "gpc_reg_operand" "")
5368                              (match_dup 5))
5369                          (match_dup 3)
5370                          (match_dup 4)))]
5371   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS
5372    && !HONOR_NANS (DFmode) && !HONOR_SIGNED_ZEROS (DFmode)"
5373   {
5374      operands[3] = gen_reg_rtx (DFmode);
5375      operands[4] = gen_reg_rtx (DFmode);
5376      operands[5] = CONST0_RTX (DFmode);
5377   })
5378
5379 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
5380 ;; fsel instruction and some auxiliary computations.  Then we just have a
5381 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
5382 ;; combine.
5383 (define_expand "smaxsf3"
5384   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5385         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
5386                              (match_operand:SF 2 "gpc_reg_operand" ""))
5387                          (match_dup 1)
5388                          (match_dup 2)))]
5389   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5390   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
5391
5392 (define_expand "sminsf3"
5393   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5394         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
5395                              (match_operand:SF 2 "gpc_reg_operand" ""))
5396                          (match_dup 2)
5397                          (match_dup 1)))]
5398   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5399   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
5400
5401 (define_split
5402   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5403         (match_operator:SF 3 "min_max_operator"
5404          [(match_operand:SF 1 "gpc_reg_operand" "")
5405           (match_operand:SF 2 "gpc_reg_operand" "")]))]
5406   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5407   [(const_int 0)]
5408   "
5409 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5410                       operands[1], operands[2]);
5411   DONE;
5412 }")
5413
5414 (define_expand "movsicc"
5415    [(set (match_operand:SI 0 "gpc_reg_operand" "")
5416          (if_then_else:SI (match_operand 1 "comparison_operator" "")
5417                           (match_operand:SI 2 "gpc_reg_operand" "")
5418                           (match_operand:SI 3 "gpc_reg_operand" "")))]
5419   "TARGET_ISEL"
5420   "
5421 {
5422   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5423     DONE;
5424   else
5425     FAIL;
5426 }")
5427
5428 ;; We use the BASE_REGS for the isel input operands because, if rA is
5429 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
5430 ;; because we may switch the operands and rB may end up being rA.
5431 ;;
5432 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
5433 ;; leave out the mode in operand 4 and use one pattern, but reload can
5434 ;; change the mode underneath our feet and then gets confused trying
5435 ;; to reload the value.
5436 (define_insn "isel_signed"
5437   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5438         (if_then_else:SI
5439          (match_operator 1 "comparison_operator"
5440                          [(match_operand:CC 4 "cc_reg_operand" "y")
5441                           (const_int 0)])
5442          (match_operand:SI 2 "gpc_reg_operand" "b")
5443          (match_operand:SI 3 "gpc_reg_operand" "b")))]
5444   "TARGET_ISEL"
5445   "*
5446 { return output_isel (operands); }"
5447   [(set_attr "length" "4")])
5448
5449 (define_insn "isel_unsigned"
5450   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5451         (if_then_else:SI
5452          (match_operator 1 "comparison_operator"
5453                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
5454                           (const_int 0)])
5455          (match_operand:SI 2 "gpc_reg_operand" "b")
5456          (match_operand:SI 3 "gpc_reg_operand" "b")))]
5457   "TARGET_ISEL"
5458   "*
5459 { return output_isel (operands); }"
5460   [(set_attr "length" "4")])
5461
5462 (define_expand "movsfcc"
5463    [(set (match_operand:SF 0 "gpc_reg_operand" "")
5464          (if_then_else:SF (match_operand 1 "comparison_operator" "")
5465                           (match_operand:SF 2 "gpc_reg_operand" "")
5466                           (match_operand:SF 3 "gpc_reg_operand" "")))]
5467   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5468   "
5469 {
5470   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5471     DONE;
5472   else
5473     FAIL;
5474 }")
5475
5476 (define_insn "*fselsfsf4"
5477   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5478         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5479                              (match_operand:SF 4 "zero_fp_constant" "F"))
5480                          (match_operand:SF 2 "gpc_reg_operand" "f")
5481                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5482   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5483   "fsel %0,%1,%2,%3"
5484   [(set_attr "type" "fp")])
5485
5486 (define_insn "*fseldfsf4"
5487   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5488         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
5489                              (match_operand:DF 4 "zero_fp_constant" "F"))
5490                          (match_operand:SF 2 "gpc_reg_operand" "f")
5491                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5492   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5493   "fsel %0,%1,%2,%3"
5494   [(set_attr "type" "fp")])
5495
5496 (define_expand "negdf2"
5497   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5498         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
5499   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5500   "")
5501
5502 (define_insn "*negdf2_fpr"
5503   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5504         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5505   "TARGET_HARD_FLOAT && TARGET_FPRS"
5506   "fneg %0,%1"
5507   [(set_attr "type" "fp")])
5508
5509 (define_expand "absdf2"
5510   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5511         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
5512   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5513   "")
5514
5515 (define_insn "*absdf2_fpr"
5516   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5517         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5518   "TARGET_HARD_FLOAT && TARGET_FPRS"
5519   "fabs %0,%1"
5520   [(set_attr "type" "fp")])
5521
5522 (define_insn "*nabsdf2_fpr"
5523   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5524         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f"))))]
5525   "TARGET_HARD_FLOAT && TARGET_FPRS"
5526   "fnabs %0,%1"
5527   [(set_attr "type" "fp")])
5528
5529 (define_expand "adddf3"
5530   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5531         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "")
5532                  (match_operand:DF 2 "gpc_reg_operand" "")))]
5533   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5534   "")
5535
5536 (define_insn "*adddf3_fpr"
5537   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5538         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5539                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
5540   "TARGET_HARD_FLOAT && TARGET_FPRS"
5541   "{fa|fadd} %0,%1,%2"
5542   [(set_attr "type" "fp")])
5543
5544 (define_expand "subdf3"
5545   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5546         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "")
5547                   (match_operand:DF 2 "gpc_reg_operand" "")))]
5548   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5549   "")
5550
5551 (define_insn "*subdf3_fpr"
5552   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5553         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5554                   (match_operand:DF 2 "gpc_reg_operand" "f")))]
5555   "TARGET_HARD_FLOAT && TARGET_FPRS"
5556   "{fs|fsub} %0,%1,%2"
5557   [(set_attr "type" "fp")])
5558
5559 (define_expand "muldf3"
5560   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5561         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "")
5562                  (match_operand:DF 2 "gpc_reg_operand" "")))]
5563   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5564   "")
5565
5566 (define_insn "*muldf3_fpr"
5567   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5568         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5569                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
5570   "TARGET_HARD_FLOAT && TARGET_FPRS"
5571   "{fm|fmul} %0,%1,%2"
5572   [(set_attr "type" "dmul")])
5573
5574 (define_insn "fred"
5575   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5576         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
5577   "TARGET_POPCNTB && flag_finite_math_only"
5578   "fre %0,%1"
5579   [(set_attr "type" "fp")])
5580
5581 (define_expand "divdf3"
5582   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5583         (div:DF (match_operand:DF 1 "gpc_reg_operand" "")
5584                 (match_operand:DF 2 "gpc_reg_operand" "")))]
5585   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5586 {
5587   if (swdiv && !optimize_size && TARGET_POPCNTB
5588   && flag_finite_math_only && !flag_trapping_math)
5589     {
5590       rs6000_emit_swdivdf (operands[0], operands[1], operands[2]);
5591       DONE;
5592     }
5593 })
5594
5595 (define_insn "*divdf3_fpr"
5596   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5597         (div:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5598                 (match_operand:DF 2 "gpc_reg_operand" "f")))]
5599   "TARGET_HARD_FLOAT && TARGET_FPRS"
5600   "{fd|fdiv} %0,%1,%2"
5601   [(set_attr "type" "ddiv")])
5602
5603 (define_insn ""
5604   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5605         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5606                           (match_operand:DF 2 "gpc_reg_operand" "f"))
5607                  (match_operand:DF 3 "gpc_reg_operand" "f")))]
5608   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5609   "{fma|fmadd} %0,%1,%2,%3"
5610   [(set_attr "type" "dmul")])
5611
5612 (define_insn ""
5613   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5614         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5615                            (match_operand:DF 2 "gpc_reg_operand" "f"))
5616                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
5617   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5618   "{fms|fmsub} %0,%1,%2,%3"
5619   [(set_attr "type" "dmul")])
5620
5621 (define_insn ""
5622   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5623         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5624                                   (match_operand:DF 2 "gpc_reg_operand" "f"))
5625                          (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5626   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5627    && HONOR_SIGNED_ZEROS (DFmode)"
5628   "{fnma|fnmadd} %0,%1,%2,%3"
5629   [(set_attr "type" "dmul")])
5630
5631 (define_insn ""
5632   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5633         (minus:DF (mult:DF (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f"))
5634                            (match_operand:DF 2 "gpc_reg_operand" "f"))
5635                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
5636   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5637    && ! HONOR_SIGNED_ZEROS (DFmode)"
5638   "{fnma|fnmadd} %0,%1,%2,%3"
5639   [(set_attr "type" "dmul")])
5640
5641 (define_insn ""
5642   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5643         (neg:DF (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5644                                    (match_operand:DF 2 "gpc_reg_operand" "f"))
5645                           (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5646   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5647    && HONOR_SIGNED_ZEROS (DFmode)"
5648   "{fnms|fnmsub} %0,%1,%2,%3"
5649   [(set_attr "type" "dmul")])
5650
5651 (define_insn ""
5652   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5653         (minus:DF (match_operand:DF 3 "gpc_reg_operand" "f")
5654                   (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5655                            (match_operand:DF 2 "gpc_reg_operand" "f"))))]
5656   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5657    && ! HONOR_SIGNED_ZEROS (DFmode)"
5658   "{fnms|fnmsub} %0,%1,%2,%3"
5659   [(set_attr "type" "dmul")])
5660
5661 (define_insn "sqrtdf2"
5662   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5663         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5664   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
5665   "fsqrt %0,%1"
5666   [(set_attr "type" "dsqrt")])
5667
5668 ;; The conditional move instructions allow us to perform max and min
5669 ;; operations even when
5670
5671 (define_expand "smaxdf3"
5672   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5673         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5674                              (match_operand:DF 2 "gpc_reg_operand" ""))
5675                          (match_dup 1)
5676                          (match_dup 2)))]
5677   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5678   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
5679
5680 (define_expand "smindf3"
5681   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5682         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5683                              (match_operand:DF 2 "gpc_reg_operand" ""))
5684                          (match_dup 2)
5685                          (match_dup 1)))]
5686   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5687   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
5688
5689 (define_split
5690   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5691         (match_operator:DF 3 "min_max_operator"
5692          [(match_operand:DF 1 "gpc_reg_operand" "")
5693           (match_operand:DF 2 "gpc_reg_operand" "")]))]
5694   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5695   [(const_int 0)]
5696   "
5697 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5698                       operands[1], operands[2]);
5699   DONE;
5700 }")
5701
5702 (define_expand "movdfcc"
5703    [(set (match_operand:DF 0 "gpc_reg_operand" "")
5704          (if_then_else:DF (match_operand 1 "comparison_operator" "")
5705                           (match_operand:DF 2 "gpc_reg_operand" "")
5706                           (match_operand:DF 3 "gpc_reg_operand" "")))]
5707   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5708   "
5709 {
5710   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5711     DONE;
5712   else
5713     FAIL;
5714 }")
5715
5716 (define_insn "*fseldfdf4"
5717   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5718         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
5719                              (match_operand:DF 4 "zero_fp_constant" "F"))
5720                          (match_operand:DF 2 "gpc_reg_operand" "f")
5721                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
5722   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5723   "fsel %0,%1,%2,%3"
5724   [(set_attr "type" "fp")])
5725
5726 (define_insn "*fselsfdf4"
5727   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5728         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5729                              (match_operand:SF 4 "zero_fp_constant" "F"))
5730                          (match_operand:DF 2 "gpc_reg_operand" "f")
5731                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
5732   "TARGET_PPC_GFXOPT"
5733   "fsel %0,%1,%2,%3"
5734   [(set_attr "type" "fp")])
5735 \f
5736 ;; Conversions to and from floating-point.
5737
5738 (define_expand "fixuns_truncsfsi2"
5739   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5740         (unsigned_fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
5741   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5742   "")
5743
5744 (define_expand "fix_truncsfsi2"
5745   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5746         (fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
5747   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5748   "")
5749
5750 ; For each of these conversions, there is a define_expand, a define_insn
5751 ; with a '#' template, and a define_split (with C code).  The idea is
5752 ; to allow constant folding with the template of the define_insn,
5753 ; then to have the insns split later (between sched1 and final).
5754
5755 (define_expand "floatsidf2"
5756   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5757                    (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5758               (use (match_dup 2))
5759               (use (match_dup 3))
5760               (clobber (match_dup 4))
5761               (clobber (match_dup 5))
5762               (clobber (match_dup 6))])]
5763   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5764   "
5765 {
5766   if (TARGET_E500_DOUBLE)
5767     {
5768       emit_insn (gen_spe_floatsidf2 (operands[0], operands[1]));
5769       DONE;
5770     }
5771   if (TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS)
5772     {
5773       rtx t1 = gen_reg_rtx (DImode);
5774       emit_insn (gen_floatsidf_ppc64_mfpgpr (operands[0], operands[1], t1));
5775       DONE;
5776     }
5777   if (TARGET_POWERPC64)
5778     {
5779       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5780       rtx t1 = gen_reg_rtx (DImode);
5781       rtx t2 = gen_reg_rtx (DImode);
5782       emit_insn (gen_floatsidf_ppc64 (operands[0], operands[1], mem, t1, t2));
5783       DONE;
5784     }
5785
5786   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5787   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
5788   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5789   operands[5] = gen_reg_rtx (DFmode);
5790   operands[6] = gen_reg_rtx (SImode);
5791 }")
5792
5793 (define_insn_and_split "*floatsidf2_internal"
5794   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5795         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5796    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5797    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5798    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5799    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))
5800    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
5801   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5802   "#"
5803   "&& (can_create_pseudo_p () || offsettable_nonstrict_memref_p (operands[4]))"
5804   [(pc)]
5805   "
5806 {
5807   rtx lowword, highword;
5808   gcc_assert (MEM_P (operands[4]));
5809   highword = adjust_address (operands[4], SImode, 0);
5810   lowword = adjust_address (operands[4], SImode, 4);
5811   if (! WORDS_BIG_ENDIAN)
5812     {
5813       rtx tmp;
5814       tmp = highword; highword = lowword; lowword = tmp;
5815     }
5816
5817   emit_insn (gen_xorsi3 (operands[6], operands[1],
5818                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
5819   emit_move_insn (lowword, operands[6]);
5820   emit_move_insn (highword, operands[2]);
5821   emit_move_insn (operands[5], operands[4]);
5822   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5823   DONE;
5824 }"
5825   [(set_attr "length" "24")])
5826
5827 (define_expand "floatunssisf2"
5828   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5829         (unsigned_float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5830   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5831   "")
5832
5833 (define_expand "floatunssidf2"
5834   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5835                    (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5836               (use (match_dup 2))
5837               (use (match_dup 3))
5838               (clobber (match_dup 4))
5839               (clobber (match_dup 5))])]
5840   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5841   "
5842 {
5843   if (TARGET_E500_DOUBLE)
5844     {
5845       emit_insn (gen_spe_floatunssidf2 (operands[0], operands[1]));
5846       DONE;
5847     }
5848   if (TARGET_POWERPC64)
5849     {
5850       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5851       rtx t1 = gen_reg_rtx (DImode);
5852       rtx t2 = gen_reg_rtx (DImode);
5853       emit_insn (gen_floatunssidf_ppc64 (operands[0], operands[1], mem,
5854                                          t1, t2));
5855       DONE;
5856     }
5857
5858   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5859   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
5860   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5861   operands[5] = gen_reg_rtx (DFmode);
5862 }")
5863
5864 (define_insn_and_split "*floatunssidf2_internal"
5865   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5866         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5867    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5868    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5869    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5870    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))]
5871   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5872   "#"
5873   "&& (can_create_pseudo_p () || offsettable_nonstrict_memref_p (operands[4]))"
5874   [(pc)]
5875   "
5876 {
5877   rtx lowword, highword;
5878   gcc_assert (MEM_P (operands[4]));
5879   highword = adjust_address (operands[4], SImode, 0);
5880   lowword = adjust_address (operands[4], SImode, 4);
5881   if (! WORDS_BIG_ENDIAN)
5882     {
5883       rtx tmp;
5884       tmp = highword; highword = lowword; lowword = tmp;
5885     }
5886
5887   emit_move_insn (lowword, operands[1]);
5888   emit_move_insn (highword, operands[2]);
5889   emit_move_insn (operands[5], operands[4]);
5890   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5891   DONE;
5892 }"
5893   [(set_attr "length" "20")])
5894
5895 (define_expand "fix_truncdfsi2"
5896   [(parallel [(set (match_operand:SI 0 "fix_trunc_dest_operand" "")
5897                    (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5898               (clobber (match_dup 2))
5899               (clobber (match_dup 3))])]
5900   "(TARGET_POWER2 || TARGET_POWERPC)
5901    && TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5902   "
5903 {
5904   if (TARGET_E500_DOUBLE)
5905     {
5906      emit_insn (gen_spe_fix_truncdfsi2 (operands[0], operands[1]));
5907      DONE;
5908     }
5909   operands[2] = gen_reg_rtx (DImode);
5910   if (TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS
5911       && gpc_reg_operand(operands[0], GET_MODE (operands[0])))
5912     {
5913       operands[3] = gen_reg_rtx (DImode);
5914       emit_insn (gen_fix_truncdfsi2_mfpgpr (operands[0], operands[1],
5915                                             operands[2], operands[3]));
5916       DONE;
5917     }
5918   if (TARGET_PPC_GFXOPT)
5919     {
5920       rtx orig_dest = operands[0];
5921       if (! memory_operand (orig_dest, GET_MODE (orig_dest)))
5922         operands[0] = assign_stack_temp (SImode, GET_MODE_SIZE (SImode), 0);
5923       emit_insn (gen_fix_truncdfsi2_internal_gfxopt (operands[0], operands[1],
5924                                                      operands[2]));
5925       if (operands[0] != orig_dest)
5926         emit_move_insn (orig_dest, operands[0]);
5927       DONE;
5928     }
5929   operands[3] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5930 }")
5931
5932 (define_insn_and_split "*fix_truncdfsi2_internal"
5933   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5934         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5935    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))
5936    (clobber (match_operand:DI 3 "memory_operand" "=o"))]
5937   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5938   "#"
5939   "&& (can_create_pseudo_p () || offsettable_nonstrict_memref_p (operands[3]))"
5940   [(pc)]
5941   "
5942 {
5943   rtx lowword;
5944   gcc_assert (MEM_P (operands[3]));
5945   lowword = adjust_address (operands[3], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
5946
5947   emit_insn (gen_fctiwz (operands[2], operands[1]));
5948   emit_move_insn (operands[3], operands[2]);
5949   emit_move_insn (operands[0], lowword);
5950   DONE;
5951 }"
5952   [(set_attr "length" "16")])
5953
5954 (define_insn_and_split "fix_truncdfsi2_internal_gfxopt"
5955   [(set (match_operand:SI 0 "memory_operand" "=Z")
5956         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5957    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))]
5958   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS
5959    && TARGET_PPC_GFXOPT"
5960   "#"
5961   "&& 1"
5962   [(pc)]
5963   "
5964 {
5965   emit_insn (gen_fctiwz (operands[2], operands[1]));
5966   emit_insn (gen_stfiwx (operands[0], operands[2]));
5967   DONE;
5968 }"
5969   [(set_attr "length" "16")])
5970
5971 (define_insn_and_split "fix_truncdfsi2_mfpgpr"
5972   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5973         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5974    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))
5975    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))]
5976   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS"
5977   "#"
5978   "&& 1"
5979   [(set (match_dup 2) (unspec:DI [(fix:SI (match_dup 1))] UNSPEC_FCTIWZ))
5980    (set (match_dup 3) (match_dup 2))
5981    (set (match_dup 0) (subreg:SI (match_dup 3) 4))]
5982   ""
5983   [(set_attr "length" "12")])
5984
5985 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
5986 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
5987 ; because the first makes it clear that operand 0 is not live
5988 ; before the instruction.
5989 (define_insn "fctiwz"
5990   [(set (match_operand:DI 0 "gpc_reg_operand" "=f")
5991         (unspec:DI [(fix:SI (match_operand:DF 1 "gpc_reg_operand" "f"))]
5992                    UNSPEC_FCTIWZ))]
5993   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5994   "{fcirz|fctiwz} %0,%1"
5995   [(set_attr "type" "fp")])
5996
5997 (define_insn "btruncdf2"
5998   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5999         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIZ))]
6000   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
6001   "friz %0,%1"
6002   [(set_attr "type" "fp")])
6003
6004 (define_insn "btruncsf2"
6005   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6006         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIZ))]
6007   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
6008   "friz %0,%1"
6009   [(set_attr "type" "fp")])
6010
6011 (define_insn "ceildf2"
6012   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6013         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIP))]
6014   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
6015   "frip %0,%1"
6016   [(set_attr "type" "fp")])
6017
6018 (define_insn "ceilsf2"
6019  [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6020         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIP))]
6021   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
6022   "frip %0,%1"
6023   [(set_attr "type" "fp")])
6024
6025 (define_insn "floordf2"
6026   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6027         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIM))]
6028   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
6029   "frim %0,%1"
6030   [(set_attr "type" "fp")])
6031
6032 (define_insn "floorsf2"
6033   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6034         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIM))]
6035   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
6036   "frim %0,%1"
6037   [(set_attr "type" "fp")])
6038
6039 (define_insn "rounddf2"
6040   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6041         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIN))]
6042   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
6043   "frin %0,%1"
6044   [(set_attr "type" "fp")])
6045
6046 (define_insn "roundsf2"
6047   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6048         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIN))]
6049   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
6050   "frin %0,%1"
6051   [(set_attr "type" "fp")])
6052
6053 ; An UNSPEC is used so we don't have to support SImode in FP registers.
6054 (define_insn "stfiwx"
6055   [(set (match_operand:SI 0 "memory_operand" "=Z")
6056         (unspec:SI [(match_operand:DI 1 "gpc_reg_operand" "f")]
6057                    UNSPEC_STFIWX))]
6058   "TARGET_PPC_GFXOPT"
6059   "stfiwx %1,%y0"
6060   [(set_attr "type" "fpstore")])
6061
6062 (define_expand "floatsisf2"
6063   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6064         (float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
6065   "TARGET_HARD_FLOAT && !TARGET_FPRS"
6066   "")
6067
6068 (define_insn "floatdidf2"
6069   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6070         (float:DF (match_operand:DI 1 "gpc_reg_operand" "*f")))]
6071   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
6072   "fcfid %0,%1"
6073   [(set_attr "type" "fp")])
6074
6075 (define_insn_and_split "floatsidf_ppc64_mfpgpr"
6076   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6077         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
6078    (clobber (match_operand:DI 2 "gpc_reg_operand" "=r"))]
6079   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS"
6080   "#"
6081   "&& 1"
6082   [(set (match_dup 2) (sign_extend:DI (match_dup 1)))
6083    (set (match_dup 0) (float:DF (match_dup 2)))]
6084   "")
6085
6086 (define_insn_and_split "floatsidf_ppc64"
6087   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6088         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
6089    (clobber (match_operand:DI 2 "memory_operand" "=o"))
6090    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
6091    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
6092   "TARGET_POWERPC64 && !TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS"
6093   "#"
6094   "&& 1"
6095   [(set (match_dup 3) (sign_extend:DI (match_dup 1)))
6096    (set (match_dup 2) (match_dup 3))
6097    (set (match_dup 4) (match_dup 2))
6098    (set (match_dup 0) (float:DF (match_dup 4)))]
6099   "")
6100
6101 (define_insn_and_split "floatunssidf_ppc64"
6102   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6103         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
6104    (clobber (match_operand:DI 2 "memory_operand" "=o"))
6105    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
6106    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
6107   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
6108   "#"
6109   "&& 1"
6110   [(set (match_dup 3) (zero_extend:DI (match_dup 1)))
6111    (set (match_dup 2) (match_dup 3))
6112    (set (match_dup 4) (match_dup 2))
6113    (set (match_dup 0) (float:DF (match_dup 4)))]
6114   "")
6115
6116 (define_insn "fix_truncdfdi2"
6117   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
6118         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "f")))]
6119   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
6120   "fctidz %0,%1"
6121   [(set_attr "type" "fp")])
6122
6123 (define_expand "floatdisf2"
6124   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6125         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
6126   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
6127   "
6128 {
6129   rtx val = operands[1];
6130   if (!flag_unsafe_math_optimizations)
6131     {
6132       rtx label = gen_label_rtx ();
6133       val = gen_reg_rtx (DImode);
6134       emit_insn (gen_floatdisf2_internal2 (val, operands[1], label));
6135       emit_label (label);
6136     }
6137   emit_insn (gen_floatdisf2_internal1 (operands[0], val));
6138   DONE;
6139 }")
6140
6141 ;; This is not IEEE compliant if rounding mode is "round to nearest".
6142 ;; If the DI->DF conversion is inexact, then it's possible to suffer
6143 ;; from double rounding.
6144 (define_insn_and_split "floatdisf2_internal1"
6145   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6146         (float:SF (match_operand:DI 1 "gpc_reg_operand" "*f")))
6147    (clobber (match_scratch:DF 2 "=f"))]
6148   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
6149   "#"
6150   "&& reload_completed"
6151   [(set (match_dup 2)
6152         (float:DF (match_dup 1)))
6153    (set (match_dup 0)
6154         (float_truncate:SF (match_dup 2)))]
6155   "")
6156
6157 ;; Twiddles bits to avoid double rounding.
6158 ;; Bits that might be truncated when converting to DFmode are replaced
6159 ;; by a bit that won't be lost at that stage, but is below the SFmode
6160 ;; rounding position.
6161 (define_expand "floatdisf2_internal2"
6162   [(set (match_dup 3) (ashiftrt:DI (match_operand:DI 1 "" "")
6163                                    (const_int 53)))
6164    (parallel [(set (match_operand:DI 0 "" "") (and:DI (match_dup 1)
6165                                                       (const_int 2047)))
6166               (clobber (scratch:CC))])
6167    (set (match_dup 3) (plus:DI (match_dup 3)
6168                                (const_int 1)))
6169    (set (match_dup 0) (plus:DI (match_dup 0)
6170                                (const_int 2047)))
6171    (set (match_dup 4) (compare:CCUNS (match_dup 3)
6172                                      (const_int 2)))
6173    (set (match_dup 0) (ior:DI (match_dup 0)
6174                               (match_dup 1)))
6175    (parallel [(set (match_dup 0) (and:DI (match_dup 0)
6176                                          (const_int -2048)))
6177               (clobber (scratch:CC))])
6178    (set (pc) (if_then_else (geu (match_dup 4) (const_int 0))
6179                            (label_ref (match_operand:DI 2 "" ""))
6180                            (pc)))
6181    (set (match_dup 0) (match_dup 1))]
6182   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
6183   "
6184 {
6185   operands[3] = gen_reg_rtx (DImode);
6186   operands[4] = gen_reg_rtx (CCUNSmode);
6187 }")
6188 \f
6189 ;; Define the DImode operations that can be done in a small number
6190 ;; of instructions.  The & constraints are to prevent the register
6191 ;; allocator from allocating registers that overlap with the inputs
6192 ;; (for example, having an input in 7,8 and an output in 6,7).  We
6193 ;; also allow for the output being the same as one of the inputs.
6194
6195 (define_insn "*adddi3_noppc64"
6196   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
6197         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
6198                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
6199   "! TARGET_POWERPC64"
6200   "*
6201 {
6202   if (WORDS_BIG_ENDIAN)
6203     return (GET_CODE (operands[2])) != CONST_INT
6204             ? \"{a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2\"
6205             : \"{ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1\";
6206   else
6207     return (GET_CODE (operands[2])) != CONST_INT
6208             ? \"{a|addc} %0,%1,%2\;{ae|adde} %L0,%L1,%L2\"
6209             : \"{ai|addic} %0,%1,%2\;{a%G2e|add%G2e} %L0,%L1\";
6210 }"
6211   [(set_attr "type" "two")
6212    (set_attr "length" "8")])
6213
6214 (define_insn "*subdi3_noppc64"
6215   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
6216         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
6217                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
6218   "! TARGET_POWERPC64"
6219   "*
6220 {
6221   if (WORDS_BIG_ENDIAN)
6222     return (GET_CODE (operands[1]) != CONST_INT)
6223             ? \"{sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1\"
6224             : \"{sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2\";
6225   else
6226     return (GET_CODE (operands[1]) != CONST_INT)
6227             ? \"{sf|subfc} %0,%2,%1\;{sfe|subfe} %L0,%L2,%L1\"
6228             : \"{sfi|subfic} %0,%2,%1\;{sf%G1e|subf%G1e} %L0,%L2\";
6229 }"
6230   [(set_attr "type" "two")
6231    (set_attr "length" "8")])
6232
6233 (define_insn "*negdi2_noppc64"
6234   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6235         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
6236   "! TARGET_POWERPC64"
6237   "*
6238 {
6239   return (WORDS_BIG_ENDIAN)
6240     ? \"{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1\"
6241     : \"{sfi|subfic} %0,%1,0\;{sfze|subfze} %L0,%L1\";
6242 }"
6243   [(set_attr "type" "two")
6244    (set_attr "length" "8")])
6245
6246 (define_expand "mulsidi3"
6247   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6248         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6249                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6250   "! TARGET_POWERPC64"
6251   "
6252 {
6253   if (! TARGET_POWER && ! TARGET_POWERPC)
6254     {
6255       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
6256       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
6257       emit_insn (gen_mull_call ());
6258       if (WORDS_BIG_ENDIAN)
6259         emit_move_insn (operands[0], gen_rtx_REG (DImode, 3));
6260       else
6261         {
6262           emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
6263                           gen_rtx_REG (SImode, 3));
6264           emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
6265                           gen_rtx_REG (SImode, 4));
6266         }
6267       DONE;
6268     }
6269   else if (TARGET_POWER)
6270     {
6271       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
6272       DONE;
6273     }
6274 }")
6275
6276 (define_insn "mulsidi3_mq"
6277   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6278         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6279                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
6280    (clobber (match_scratch:SI 3 "=q"))]
6281   "TARGET_POWER"
6282   "mul %0,%1,%2\;mfmq %L0"
6283   [(set_attr "type" "imul")
6284    (set_attr "length" "8")])
6285
6286 (define_insn "*mulsidi3_no_mq"
6287   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6288         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6289                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6290   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
6291   "*
6292 {
6293   return (WORDS_BIG_ENDIAN)
6294     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
6295     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
6296 }"
6297   [(set_attr "type" "imul")
6298    (set_attr "length" "8")])
6299
6300 (define_split
6301   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6302         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6303                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6304   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
6305   [(set (match_dup 3)
6306         (truncate:SI
6307          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
6308                                (sign_extend:DI (match_dup 2)))
6309                       (const_int 32))))
6310    (set (match_dup 4)
6311         (mult:SI (match_dup 1)
6312                  (match_dup 2)))]
6313   "
6314 {
6315   int endian = (WORDS_BIG_ENDIAN == 0);
6316   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6317   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6318 }")
6319
6320 (define_expand "umulsidi3"
6321   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6322         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6323                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6324   "TARGET_POWERPC && ! TARGET_POWERPC64"
6325   "
6326 {
6327   if (TARGET_POWER)
6328     {
6329       emit_insn (gen_umulsidi3_mq (operands[0], operands[1], operands[2]));
6330       DONE;
6331     }
6332 }")
6333
6334 (define_insn "umulsidi3_mq"
6335   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6336         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6337                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
6338    (clobber (match_scratch:SI 3 "=q"))]
6339   "TARGET_POWERPC && TARGET_POWER"
6340   "*
6341 {
6342   return (WORDS_BIG_ENDIAN)
6343     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
6344     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
6345 }"
6346   [(set_attr "type" "imul")
6347    (set_attr "length" "8")])
6348
6349 (define_insn "*umulsidi3_no_mq"
6350   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6351         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6352                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6353   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
6354   "*
6355 {
6356   return (WORDS_BIG_ENDIAN)
6357     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
6358     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
6359 }"
6360   [(set_attr "type" "imul")
6361    (set_attr "length" "8")])
6362
6363 (define_split
6364   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6365         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6366                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6367   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
6368   [(set (match_dup 3)
6369         (truncate:SI
6370          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
6371                                (zero_extend:DI (match_dup 2)))
6372                       (const_int 32))))
6373    (set (match_dup 4)
6374         (mult:SI (match_dup 1)
6375                  (match_dup 2)))]
6376   "
6377 {
6378   int endian = (WORDS_BIG_ENDIAN == 0);
6379   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6380   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6381 }")
6382
6383 (define_expand "smulsi3_highpart"
6384   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6385         (truncate:SI
6386          (lshiftrt:DI (mult:DI (sign_extend:DI
6387                                 (match_operand:SI 1 "gpc_reg_operand" ""))
6388                                (sign_extend:DI
6389                                 (match_operand:SI 2 "gpc_reg_operand" "")))
6390                       (const_int 32))))]
6391   ""
6392   "
6393 {
6394   if (! TARGET_POWER && ! TARGET_POWERPC)
6395     {
6396       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
6397       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
6398       emit_insn (gen_mulh_call ());
6399       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
6400       DONE;
6401     }
6402   else if (TARGET_POWER)
6403     {
6404       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
6405       DONE;
6406     }
6407 }")
6408
6409 (define_insn "smulsi3_highpart_mq"
6410   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6411         (truncate:SI
6412          (lshiftrt:DI (mult:DI (sign_extend:DI
6413                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6414                                (sign_extend:DI
6415                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6416                       (const_int 32))))
6417    (clobber (match_scratch:SI 3 "=q"))]
6418   "TARGET_POWER"
6419   "mul %0,%1,%2"
6420   [(set_attr "type" "imul")])
6421
6422 (define_insn "*smulsi3_highpart_no_mq"
6423   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6424         (truncate:SI
6425          (lshiftrt:DI (mult:DI (sign_extend:DI
6426                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6427                                (sign_extend:DI
6428                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6429                       (const_int 32))))]
6430   "TARGET_POWERPC && ! TARGET_POWER"
6431   "mulhw %0,%1,%2"
6432   [(set_attr "type" "imul")])
6433
6434 (define_expand "umulsi3_highpart"
6435   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6436         (truncate:SI
6437          (lshiftrt:DI (mult:DI (zero_extend:DI
6438                                 (match_operand:SI 1 "gpc_reg_operand" ""))
6439                                (zero_extend:DI
6440                                 (match_operand:SI 2 "gpc_reg_operand" "")))
6441                       (const_int 32))))]
6442   "TARGET_POWERPC"
6443   "
6444 {
6445   if (TARGET_POWER)
6446     {
6447       emit_insn (gen_umulsi3_highpart_mq (operands[0], operands[1], operands[2]));
6448       DONE;
6449     }
6450 }")
6451
6452 (define_insn "umulsi3_highpart_mq"
6453   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6454         (truncate:SI
6455          (lshiftrt:DI (mult:DI (zero_extend:DI
6456                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6457                                (zero_extend:DI
6458                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6459                       (const_int 32))))
6460    (clobber (match_scratch:SI 3 "=q"))]
6461   "TARGET_POWERPC && TARGET_POWER"
6462   "mulhwu %0,%1,%2"
6463   [(set_attr "type" "imul")])
6464
6465 (define_insn "*umulsi3_highpart_no_mq"
6466   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6467         (truncate:SI
6468          (lshiftrt:DI (mult:DI (zero_extend:DI
6469                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6470                                (zero_extend:DI
6471                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6472                       (const_int 32))))]
6473   "TARGET_POWERPC && ! TARGET_POWER"
6474   "mulhwu %0,%1,%2"
6475   [(set_attr "type" "imul")])
6476
6477 ;; If operands 0 and 2 are in the same register, we have a problem.  But
6478 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
6479 ;; why we have the strange constraints below.
6480 (define_insn "ashldi3_power"
6481   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
6482         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
6483                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
6484    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
6485   "TARGET_POWER"
6486   "@
6487    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
6488    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
6489    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
6490    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
6491   [(set_attr "length" "8")])
6492
6493 (define_insn "lshrdi3_power"
6494   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
6495         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
6496                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
6497    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
6498   "TARGET_POWER"
6499   "@
6500    {s%A2i|s%A2wi} %L0,%1,%h2\;{cal %0,0(0)|li %0,0}
6501    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
6502    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
6503    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
6504   [(set_attr "length" "8")])
6505
6506 ;; Shift by a variable amount is too complex to be worth open-coding.  We
6507 ;; just handle shifts by constants.
6508 (define_insn "ashrdi3_power"
6509   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6510         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6511                      (match_operand:SI 2 "const_int_operand" "M,i")))
6512    (clobber (match_scratch:SI 3 "=X,q"))]
6513   "TARGET_POWER"
6514   "@
6515    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
6516    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
6517   [(set_attr "type" "shift")
6518    (set_attr "length" "8")])
6519
6520 (define_insn "ashrdi3_no_power"
6521   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
6522         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6523                      (match_operand:SI 2 "const_int_operand" "M,i")))]
6524   "TARGET_32BIT && !TARGET_POWERPC64 && !TARGET_POWER && WORDS_BIG_ENDIAN"
6525   "@
6526    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
6527    {sri|srwi} %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;{srai|srawi} %0,%1,%h2"
6528   [(set_attr "type" "two,three")
6529    (set_attr "length" "8,12")])
6530
6531 (define_insn "*ashrdisi3_noppc64"
6532   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6533         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6534                                 (const_int 32)) 4))]
6535   "TARGET_32BIT && !TARGET_POWERPC64"
6536   "*
6537 {
6538   if (REGNO (operands[0]) == REGNO (operands[1]))
6539     return \"\";
6540   else
6541     return \"mr %0,%1\";
6542 }"
6543    [(set_attr "length" "4")])
6544
6545 \f
6546 ;; PowerPC64 DImode operations.
6547
6548 (define_insn_and_split "absdi2"
6549   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6550         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
6551    (clobber (match_scratch:DI 2 "=&r,&r"))]
6552   "TARGET_POWERPC64"
6553   "#"
6554   "&& reload_completed"
6555   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
6556    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
6557    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
6558   "")
6559
6560 (define_insn_and_split "*nabsdi2"
6561   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6562         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
6563    (clobber (match_scratch:DI 2 "=&r,&r"))]
6564   "TARGET_POWERPC64"
6565   "#"
6566   "&& reload_completed"
6567   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
6568    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
6569    (set (match_dup 0) (minus:DI (match_dup 2) (match_dup 0)))]
6570   "")
6571
6572 (define_insn "muldi3"
6573   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6574         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6575                  (match_operand:DI 2 "reg_or_short_operand" "r,I")))]
6576   "TARGET_POWERPC64"
6577   "@
6578    mulld %0,%1,%2
6579    mulli %0,%1,%2"
6580    [(set (attr "type")
6581       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
6582                 (const_string "imul3")
6583              (match_operand:SI 2 "short_cint_operand" "")
6584                 (const_string "imul2")]
6585         (const_string "lmul")))])
6586
6587 (define_insn "*muldi3_internal1"
6588   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6589         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6590                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6591                     (const_int 0)))
6592    (clobber (match_scratch:DI 3 "=r,r"))]
6593   "TARGET_POWERPC64"
6594   "@
6595    mulld. %3,%1,%2
6596    #"
6597   [(set_attr "type" "lmul_compare")
6598    (set_attr "length" "4,8")])
6599
6600 (define_split
6601   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6602         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6603                              (match_operand:DI 2 "gpc_reg_operand" ""))
6604                     (const_int 0)))
6605    (clobber (match_scratch:DI 3 ""))]
6606   "TARGET_POWERPC64 && reload_completed"
6607   [(set (match_dup 3)
6608         (mult:DI (match_dup 1) (match_dup 2)))
6609    (set (match_dup 0)
6610         (compare:CC (match_dup 3)
6611                     (const_int 0)))]
6612   "")
6613
6614 (define_insn "*muldi3_internal2"
6615   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6616         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6617                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6618                     (const_int 0)))
6619    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6620         (mult:DI (match_dup 1) (match_dup 2)))]
6621   "TARGET_POWERPC64"
6622   "@
6623    mulld. %0,%1,%2
6624    #"
6625   [(set_attr "type" "lmul_compare")
6626    (set_attr "length" "4,8")])
6627
6628 (define_split
6629   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6630         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6631                              (match_operand:DI 2 "gpc_reg_operand" ""))
6632                     (const_int 0)))
6633    (set (match_operand:DI 0 "gpc_reg_operand" "")
6634         (mult:DI (match_dup 1) (match_dup 2)))]
6635   "TARGET_POWERPC64 && reload_completed"
6636   [(set (match_dup 0)
6637         (mult:DI (match_dup 1) (match_dup 2)))
6638    (set (match_dup 3)
6639         (compare:CC (match_dup 0)
6640                     (const_int 0)))]
6641   "")
6642
6643 (define_insn "smuldi3_highpart"
6644   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6645         (truncate:DI
6646          (lshiftrt:TI (mult:TI (sign_extend:TI
6647                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6648                                (sign_extend:TI
6649                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6650                       (const_int 64))))]
6651   "TARGET_POWERPC64"
6652   "mulhd %0,%1,%2"
6653   [(set_attr "type" "lmul")])
6654
6655 (define_insn "umuldi3_highpart"
6656   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6657         (truncate:DI
6658          (lshiftrt:TI (mult:TI (zero_extend:TI
6659                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6660                                (zero_extend:TI
6661                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6662                       (const_int 64))))]
6663   "TARGET_POWERPC64"
6664   "mulhdu %0,%1,%2"
6665   [(set_attr "type" "lmul")])
6666
6667 (define_insn "rotldi3"
6668   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6669         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6670                    (match_operand:DI 2 "reg_or_cint_operand" "r,i")))]
6671   "TARGET_POWERPC64"
6672   "@
6673    rldcl %0,%1,%2,0
6674    rldicl %0,%1,%H2,0"
6675   [(set_attr "type" "var_shift_rotate,integer")])
6676
6677 (define_insn "*rotldi3_internal2"
6678   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6679         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6680                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6681                     (const_int 0)))
6682    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
6683   "TARGET_64BIT"
6684   "@
6685    rldcl. %3,%1,%2,0
6686    rldicl. %3,%1,%H2,0
6687    #
6688    #"
6689   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6690    (set_attr "length" "4,4,8,8")])
6691
6692 (define_split
6693   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6694         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6695                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6696                     (const_int 0)))
6697    (clobber (match_scratch:DI 3 ""))]
6698   "TARGET_POWERPC64 && reload_completed"
6699   [(set (match_dup 3)
6700         (rotate:DI (match_dup 1) (match_dup 2)))
6701    (set (match_dup 0)
6702         (compare:CC (match_dup 3)
6703                     (const_int 0)))]
6704   "")
6705
6706 (define_insn "*rotldi3_internal3"
6707   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
6708         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6709                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6710                     (const_int 0)))
6711    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6712         (rotate:DI (match_dup 1) (match_dup 2)))]
6713   "TARGET_64BIT"
6714   "@
6715    rldcl. %0,%1,%2,0
6716    rldicl. %0,%1,%H2,0
6717    #
6718    #"
6719   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6720    (set_attr "length" "4,4,8,8")])
6721
6722 (define_split
6723   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6724         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6725                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6726                     (const_int 0)))
6727    (set (match_operand:DI 0 "gpc_reg_operand" "")
6728         (rotate:DI (match_dup 1) (match_dup 2)))]
6729   "TARGET_POWERPC64 && reload_completed"
6730   [(set (match_dup 0)
6731         (rotate:DI (match_dup 1) (match_dup 2)))
6732    (set (match_dup 3)
6733         (compare:CC (match_dup 0)
6734                     (const_int 0)))]
6735   "")
6736
6737 (define_insn "*rotldi3_internal4"
6738   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6739         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6740                            (match_operand:DI 2 "reg_or_cint_operand" "r,i"))
6741                 (match_operand:DI 3 "mask64_operand" "n,n")))]
6742   "TARGET_POWERPC64"
6743   "@
6744    rldc%B3 %0,%1,%2,%S3
6745    rldic%B3 %0,%1,%H2,%S3"
6746   [(set_attr "type" "var_shift_rotate,integer")])
6747
6748 (define_insn "*rotldi3_internal5"
6749   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6750         (compare:CC (and:DI
6751                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6752                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6753                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
6754                     (const_int 0)))
6755    (clobber (match_scratch:DI 4 "=r,r,r,r"))]
6756   "TARGET_64BIT"
6757   "@
6758    rldc%B3. %4,%1,%2,%S3
6759    rldic%B3. %4,%1,%H2,%S3
6760    #
6761    #"
6762   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6763    (set_attr "length" "4,4,8,8")])
6764
6765 (define_split
6766   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6767         (compare:CC (and:DI
6768                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6769                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6770                      (match_operand:DI 3 "mask64_operand" ""))
6771                     (const_int 0)))
6772    (clobber (match_scratch:DI 4 ""))]
6773   "TARGET_POWERPC64 && reload_completed"
6774   [(set (match_dup 4)
6775         (and:DI (rotate:DI (match_dup 1)
6776                                 (match_dup 2))
6777                      (match_dup 3)))
6778    (set (match_dup 0)
6779         (compare:CC (match_dup 4)
6780                     (const_int 0)))]
6781   "")
6782
6783 (define_insn "*rotldi3_internal6"
6784   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
6785         (compare:CC (and:DI
6786                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6787                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6788                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
6789                     (const_int 0)))
6790    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6791         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6792   "TARGET_64BIT"
6793   "@
6794    rldc%B3. %0,%1,%2,%S3
6795    rldic%B3. %0,%1,%H2,%S3
6796    #
6797    #"
6798   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6799    (set_attr "length" "4,4,8,8")])
6800
6801 (define_split
6802   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6803         (compare:CC (and:DI
6804                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6805                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6806                      (match_operand:DI 3 "mask64_operand" ""))
6807                     (const_int 0)))
6808    (set (match_operand:DI 0 "gpc_reg_operand" "")
6809         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6810   "TARGET_POWERPC64 && reload_completed"
6811   [(set (match_dup 0)
6812         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
6813    (set (match_dup 4)
6814         (compare:CC (match_dup 0)
6815                     (const_int 0)))]
6816   "")
6817
6818 (define_insn "*rotldi3_internal7"
6819   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6820         (zero_extend:DI
6821          (subreg:QI
6822           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6823                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
6824   "TARGET_POWERPC64"
6825   "@
6826    rldcl %0,%1,%2,56
6827    rldicl %0,%1,%H2,56"
6828   [(set_attr "type" "var_shift_rotate,integer")])
6829
6830 (define_insn "*rotldi3_internal8"
6831   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6832         (compare:CC (zero_extend:DI
6833                      (subreg:QI
6834                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6835                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
6836                     (const_int 0)))
6837    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
6838   "TARGET_64BIT"
6839   "@
6840    rldcl. %3,%1,%2,56
6841    rldicl. %3,%1,%H2,56
6842    #
6843    #"
6844   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6845    (set_attr "length" "4,4,8,8")])
6846
6847 (define_split
6848   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6849         (compare:CC (zero_extend:DI
6850                      (subreg:QI
6851                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6852                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6853                     (const_int 0)))
6854    (clobber (match_scratch:DI 3 ""))]
6855   "TARGET_POWERPC64 && reload_completed"
6856   [(set (match_dup 3)
6857         (zero_extend:DI (subreg:QI
6858                       (rotate:DI (match_dup 1)
6859                                  (match_dup 2)) 0)))
6860    (set (match_dup 0)
6861         (compare:CC (match_dup 3)
6862                     (const_int 0)))]
6863   "")
6864
6865 (define_insn "*rotldi3_internal9"
6866   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
6867         (compare:CC (zero_extend:DI
6868                      (subreg:QI
6869                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6870                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
6871                     (const_int 0)))
6872    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6873         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6874   "TARGET_64BIT"
6875   "@
6876    rldcl. %0,%1,%2,56
6877    rldicl. %0,%1,%H2,56
6878    #
6879    #"
6880   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6881    (set_attr "length" "4,4,8,8")])
6882
6883 (define_split
6884   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6885         (compare:CC (zero_extend:DI
6886                      (subreg:QI
6887                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6888                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6889                     (const_int 0)))
6890    (set (match_operand:DI 0 "gpc_reg_operand" "")
6891         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6892   "TARGET_POWERPC64 && reload_completed"
6893   [(set (match_dup 0)
6894         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6895    (set (match_dup 3)
6896         (compare:CC (match_dup 0)
6897                     (const_int 0)))]
6898   "")
6899
6900 (define_insn "*rotldi3_internal10"
6901   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6902         (zero_extend:DI
6903          (subreg:HI
6904           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6905                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
6906   "TARGET_POWERPC64"
6907   "@
6908    rldcl %0,%1,%2,48
6909    rldicl %0,%1,%H2,48"
6910   [(set_attr "type" "var_shift_rotate,integer")])
6911
6912 (define_insn "*rotldi3_internal11"
6913   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6914         (compare:CC (zero_extend:DI
6915                      (subreg:HI
6916                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6917                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
6918                     (const_int 0)))
6919    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
6920   "TARGET_64BIT"
6921   "@
6922    rldcl. %3,%1,%2,48
6923    rldicl. %3,%1,%H2,48
6924    #
6925    #"
6926   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6927    (set_attr "length" "4,4,8,8")])
6928
6929 (define_split
6930   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6931         (compare:CC (zero_extend:DI
6932                      (subreg:HI
6933                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6934                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6935                     (const_int 0)))
6936    (clobber (match_scratch:DI 3 ""))]
6937   "TARGET_POWERPC64 && reload_completed"
6938   [(set (match_dup 3)
6939         (zero_extend:DI (subreg:HI
6940                       (rotate:DI (match_dup 1)
6941                                  (match_dup 2)) 0)))
6942    (set (match_dup 0)
6943         (compare:CC (match_dup 3)
6944                     (const_int 0)))]
6945   "")
6946
6947 (define_insn "*rotldi3_internal12"
6948   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
6949         (compare:CC (zero_extend:DI
6950                      (subreg:HI
6951                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6952                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
6953                     (const_int 0)))
6954    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6955         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6956   "TARGET_64BIT"
6957   "@
6958    rldcl. %0,%1,%2,48
6959    rldicl. %0,%1,%H2,48
6960    #
6961    #"
6962   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6963    (set_attr "length" "4,4,8,8")])
6964
6965 (define_split
6966   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6967         (compare:CC (zero_extend:DI
6968                      (subreg:HI
6969                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6970                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6971                     (const_int 0)))
6972    (set (match_operand:DI 0 "gpc_reg_operand" "")
6973         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6974   "TARGET_POWERPC64 && reload_completed"
6975   [(set (match_dup 0)
6976         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6977    (set (match_dup 3)
6978         (compare:CC (match_dup 0)
6979                     (const_int 0)))]
6980   "")
6981
6982 (define_insn "*rotldi3_internal13"
6983   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6984         (zero_extend:DI
6985          (subreg:SI
6986           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6987                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
6988   "TARGET_POWERPC64"
6989   "@
6990    rldcl %0,%1,%2,32
6991    rldicl %0,%1,%H2,32"
6992   [(set_attr "type" "var_shift_rotate,integer")])
6993
6994 (define_insn "*rotldi3_internal14"
6995   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6996         (compare:CC (zero_extend:DI
6997                      (subreg:SI
6998                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6999                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7000                     (const_int 0)))
7001    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7002   "TARGET_64BIT"
7003   "@
7004    rldcl. %3,%1,%2,32
7005    rldicl. %3,%1,%H2,32
7006    #
7007    #"
7008   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7009    (set_attr "length" "4,4,8,8")])
7010
7011 (define_split
7012   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7013         (compare:CC (zero_extend:DI
7014                      (subreg:SI
7015                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7016                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7017                     (const_int 0)))
7018    (clobber (match_scratch:DI 3 ""))]
7019   "TARGET_POWERPC64 && reload_completed"
7020   [(set (match_dup 3)
7021         (zero_extend:DI (subreg:SI
7022                       (rotate:DI (match_dup 1)
7023                                  (match_dup 2)) 0)))
7024    (set (match_dup 0)
7025         (compare:CC (match_dup 3)
7026                     (const_int 0)))]
7027   "")
7028
7029 (define_insn "*rotldi3_internal15"
7030   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7031         (compare:CC (zero_extend:DI
7032                      (subreg:SI
7033                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7034                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7035                     (const_int 0)))
7036    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7037         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7038   "TARGET_64BIT"
7039   "@
7040    rldcl. %0,%1,%2,32
7041    rldicl. %0,%1,%H2,32
7042    #
7043    #"
7044   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7045    (set_attr "length" "4,4,8,8")])
7046
7047 (define_split
7048   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7049         (compare:CC (zero_extend:DI
7050                      (subreg:SI
7051                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7052                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7053                     (const_int 0)))
7054    (set (match_operand:DI 0 "gpc_reg_operand" "")
7055         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7056   "TARGET_POWERPC64 && reload_completed"
7057   [(set (match_dup 0)
7058         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7059    (set (match_dup 3)
7060         (compare:CC (match_dup 0)
7061                     (const_int 0)))]
7062   "")
7063
7064 (define_expand "ashldi3"
7065   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7066         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7067                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
7068   "TARGET_POWERPC64 || TARGET_POWER"
7069   "
7070 {
7071   if (TARGET_POWERPC64)
7072     ;
7073   else if (TARGET_POWER)
7074     {
7075       emit_insn (gen_ashldi3_power (operands[0], operands[1], operands[2]));
7076       DONE;
7077     }
7078   else
7079     FAIL;
7080 }")
7081
7082 (define_insn "*ashldi3_internal1"
7083   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7084         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7085                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
7086   "TARGET_POWERPC64"
7087   "@
7088    sld %0,%1,%2
7089    sldi %0,%1,%H2"
7090   [(set_attr "type" "var_shift_rotate,shift")])
7091
7092 (define_insn "*ashldi3_internal2"
7093   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7094         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7095                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7096                     (const_int 0)))
7097    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7098   "TARGET_64BIT"
7099   "@
7100    sld. %3,%1,%2
7101    sldi. %3,%1,%H2
7102    #
7103    #"
7104   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7105    (set_attr "length" "4,4,8,8")])
7106
7107 (define_split
7108   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7109         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7110                                (match_operand:SI 2 "reg_or_cint_operand" ""))
7111                     (const_int 0)))
7112    (clobber (match_scratch:DI 3 ""))]
7113   "TARGET_POWERPC64 && reload_completed"
7114   [(set (match_dup 3)
7115         (ashift:DI (match_dup 1) (match_dup 2)))
7116    (set (match_dup 0)
7117         (compare:CC (match_dup 3)
7118                     (const_int 0)))]
7119   "")
7120
7121 (define_insn "*ashldi3_internal3"
7122   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7123         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7124                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7125                     (const_int 0)))
7126    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7127         (ashift:DI (match_dup 1) (match_dup 2)))]
7128   "TARGET_64BIT"
7129   "@
7130    sld. %0,%1,%2
7131    sldi. %0,%1,%H2
7132    #
7133    #"
7134   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7135    (set_attr "length" "4,4,8,8")])
7136
7137 (define_split
7138   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7139         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7140                                (match_operand:SI 2 "reg_or_cint_operand" ""))
7141                     (const_int 0)))
7142    (set (match_operand:DI 0 "gpc_reg_operand" "")
7143         (ashift:DI (match_dup 1) (match_dup 2)))]
7144   "TARGET_POWERPC64 && reload_completed"
7145   [(set (match_dup 0)
7146         (ashift:DI (match_dup 1) (match_dup 2)))
7147    (set (match_dup 3)
7148         (compare:CC (match_dup 0)
7149                     (const_int 0)))]
7150   "")
7151
7152 (define_insn "*ashldi3_internal4"
7153   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7154         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7155                            (match_operand:SI 2 "const_int_operand" "i"))
7156                 (match_operand:DI 3 "const_int_operand" "n")))]
7157   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
7158   "rldic %0,%1,%H2,%W3")
7159
7160 (define_insn "ashldi3_internal5"
7161   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7162         (compare:CC
7163          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7164                             (match_operand:SI 2 "const_int_operand" "i,i"))
7165                  (match_operand:DI 3 "const_int_operand" "n,n"))
7166          (const_int 0)))
7167    (clobber (match_scratch:DI 4 "=r,r"))]
7168   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
7169   "@
7170    rldic. %4,%1,%H2,%W3
7171    #"
7172   [(set_attr "type" "compare")
7173    (set_attr "length" "4,8")])
7174
7175 (define_split
7176   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7177         (compare:CC
7178          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7179                             (match_operand:SI 2 "const_int_operand" ""))
7180                  (match_operand:DI 3 "const_int_operand" ""))
7181          (const_int 0)))
7182    (clobber (match_scratch:DI 4 ""))]
7183   "TARGET_POWERPC64 && reload_completed
7184    && includes_rldic_lshift_p (operands[2], operands[3])"
7185   [(set (match_dup 4)
7186         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7187                 (match_dup 3)))
7188    (set (match_dup 0)
7189         (compare:CC (match_dup 4)
7190                     (const_int 0)))]
7191   "")
7192
7193 (define_insn "*ashldi3_internal6"
7194   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7195         (compare:CC
7196          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7197                             (match_operand:SI 2 "const_int_operand" "i,i"))
7198                     (match_operand:DI 3 "const_int_operand" "n,n"))
7199          (const_int 0)))
7200    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7201         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7202   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
7203   "@
7204    rldic. %0,%1,%H2,%W3
7205    #"
7206   [(set_attr "type" "compare")
7207    (set_attr "length" "4,8")])
7208
7209 (define_split
7210   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
7211         (compare:CC
7212          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7213                             (match_operand:SI 2 "const_int_operand" ""))
7214                  (match_operand:DI 3 "const_int_operand" ""))
7215          (const_int 0)))
7216    (set (match_operand:DI 0 "gpc_reg_operand" "")
7217         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7218   "TARGET_POWERPC64 && reload_completed
7219    && includes_rldic_lshift_p (operands[2], operands[3])"
7220   [(set (match_dup 0)
7221         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7222                 (match_dup 3)))
7223    (set (match_dup 4)
7224         (compare:CC (match_dup 0)
7225                     (const_int 0)))]
7226   "")
7227
7228 (define_insn "*ashldi3_internal7"
7229   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7230         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7231                            (match_operand:SI 2 "const_int_operand" "i"))
7232                 (match_operand:DI 3 "mask64_operand" "n")))]
7233   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
7234   "rldicr %0,%1,%H2,%S3")
7235
7236 (define_insn "ashldi3_internal8"
7237   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7238         (compare:CC
7239          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7240                             (match_operand:SI 2 "const_int_operand" "i,i"))
7241                  (match_operand:DI 3 "mask64_operand" "n,n"))
7242          (const_int 0)))
7243    (clobber (match_scratch:DI 4 "=r,r"))]
7244   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7245   "@
7246    rldicr. %4,%1,%H2,%S3
7247    #"
7248   [(set_attr "type" "compare")
7249    (set_attr "length" "4,8")])
7250
7251 (define_split
7252   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7253         (compare:CC
7254          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7255                             (match_operand:SI 2 "const_int_operand" ""))
7256                  (match_operand:DI 3 "mask64_operand" ""))
7257          (const_int 0)))
7258    (clobber (match_scratch:DI 4 ""))]
7259   "TARGET_POWERPC64 && reload_completed
7260    && includes_rldicr_lshift_p (operands[2], operands[3])"
7261   [(set (match_dup 4)
7262         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7263                 (match_dup 3)))
7264    (set (match_dup 0)
7265         (compare:CC (match_dup 4)
7266                     (const_int 0)))]
7267   "")
7268
7269 (define_insn "*ashldi3_internal9"
7270   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7271         (compare:CC
7272          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7273                             (match_operand:SI 2 "const_int_operand" "i,i"))
7274                     (match_operand:DI 3 "mask64_operand" "n,n"))
7275          (const_int 0)))
7276    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7277         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7278   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7279   "@
7280    rldicr. %0,%1,%H2,%S3
7281    #"
7282   [(set_attr "type" "compare")
7283    (set_attr "length" "4,8")])
7284
7285 (define_split
7286   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
7287         (compare:CC
7288          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7289                             (match_operand:SI 2 "const_int_operand" ""))
7290                  (match_operand:DI 3 "mask64_operand" ""))
7291          (const_int 0)))
7292    (set (match_operand:DI 0 "gpc_reg_operand" "")
7293         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7294   "TARGET_POWERPC64 && reload_completed
7295    && includes_rldicr_lshift_p (operands[2], operands[3])"
7296   [(set (match_dup 0)
7297         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7298                 (match_dup 3)))
7299    (set (match_dup 4)
7300         (compare:CC (match_dup 0)
7301                     (const_int 0)))]
7302   "")
7303
7304 (define_expand "lshrdi3"
7305   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7306         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7307                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7308   "TARGET_POWERPC64 || TARGET_POWER"
7309   "
7310 {
7311   if (TARGET_POWERPC64)
7312     ;
7313   else if (TARGET_POWER)
7314     {
7315       emit_insn (gen_lshrdi3_power (operands[0], operands[1], operands[2]));
7316       DONE;
7317     }
7318   else
7319     FAIL;
7320 }")
7321
7322 (define_insn "*lshrdi3_internal1"
7323   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7324         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7325                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
7326   "TARGET_POWERPC64"
7327   "@
7328    srd %0,%1,%2
7329    srdi %0,%1,%H2"
7330   [(set_attr "type" "var_shift_rotate,shift")])
7331
7332 (define_insn "*lshrdi3_internal2"
7333   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7334         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7335                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7336                     (const_int 0)))
7337    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7338   "TARGET_64BIT "
7339   "@
7340    srd. %3,%1,%2
7341    srdi. %3,%1,%H2
7342    #
7343    #"
7344   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7345    (set_attr "length" "4,4,8,8")])
7346
7347 (define_split
7348   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7349         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7350                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7351                     (const_int 0)))
7352    (clobber (match_scratch:DI 3 ""))]
7353   "TARGET_POWERPC64 && reload_completed"
7354   [(set (match_dup 3)
7355         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7356    (set (match_dup 0)
7357         (compare:CC (match_dup 3)
7358                     (const_int 0)))]
7359   "")
7360
7361 (define_insn "*lshrdi3_internal3"
7362   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7363         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7364                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7365                     (const_int 0)))
7366    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7367         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7368   "TARGET_64BIT"
7369   "@
7370    srd. %0,%1,%2
7371    srdi. %0,%1,%H2
7372    #
7373    #"
7374   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7375    (set_attr "length" "4,4,8,8")])
7376
7377 (define_split
7378   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7379         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7380                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7381                     (const_int 0)))
7382    (set (match_operand:DI 0 "gpc_reg_operand" "")
7383         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7384   "TARGET_POWERPC64 && reload_completed"
7385   [(set (match_dup 0)
7386         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7387    (set (match_dup 3)
7388         (compare:CC (match_dup 0)
7389                     (const_int 0)))]
7390   "")
7391
7392 (define_expand "ashrdi3"
7393   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7394         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7395                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7396   "WORDS_BIG_ENDIAN"
7397   "
7398 {
7399   if (TARGET_POWERPC64)
7400     ;
7401   else if (TARGET_POWER && GET_CODE (operands[2]) == CONST_INT)
7402     {
7403       emit_insn (gen_ashrdi3_power (operands[0], operands[1], operands[2]));
7404       DONE;
7405     }
7406   else if (TARGET_32BIT && GET_CODE (operands[2]) == CONST_INT
7407            && WORDS_BIG_ENDIAN)
7408     {
7409       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
7410       DONE;
7411     }
7412   else
7413     FAIL;
7414 }")
7415
7416 (define_insn "*ashrdi3_internal1"
7417   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7418         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7419                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
7420   "TARGET_POWERPC64"
7421   "@
7422    srad %0,%1,%2
7423    sradi %0,%1,%H2"
7424   [(set_attr "type" "var_shift_rotate,shift")])
7425
7426 (define_insn "*ashrdi3_internal2"
7427   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7428         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7429                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7430                     (const_int 0)))
7431    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7432   "TARGET_64BIT"
7433   "@
7434    srad. %3,%1,%2
7435    sradi. %3,%1,%H2
7436    #
7437    #"
7438   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7439    (set_attr "length" "4,4,8,8")])
7440
7441 (define_split
7442   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7443         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7444                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7445                     (const_int 0)))
7446    (clobber (match_scratch:DI 3 ""))]
7447   "TARGET_POWERPC64 && reload_completed"
7448   [(set (match_dup 3)
7449         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7450    (set (match_dup 0)
7451         (compare:CC (match_dup 3)
7452                     (const_int 0)))]
7453   "")
7454
7455 (define_insn "*ashrdi3_internal3"
7456   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7457         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7458                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7459                     (const_int 0)))
7460    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7461         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7462   "TARGET_64BIT"
7463   "@
7464    srad. %0,%1,%2
7465    sradi. %0,%1,%H2
7466    #
7467    #"
7468   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7469    (set_attr "length" "4,4,8,8")])
7470
7471 (define_split
7472   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7473         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7474                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7475                     (const_int 0)))
7476    (set (match_operand:DI 0 "gpc_reg_operand" "")
7477         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7478   "TARGET_POWERPC64 && reload_completed"
7479   [(set (match_dup 0)
7480         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7481    (set (match_dup 3)
7482         (compare:CC (match_dup 0)
7483                     (const_int 0)))]
7484   "")
7485
7486 (define_insn "anddi3"
7487   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
7488         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r")
7489                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,K,J,t")))
7490    (clobber (match_scratch:CC 3 "=X,X,X,x,x,X"))]
7491   "TARGET_POWERPC64"
7492   "@
7493    and %0,%1,%2
7494    rldic%B2 %0,%1,0,%S2
7495    rlwinm %0,%1,0,%m2,%M2
7496    andi. %0,%1,%b2
7497    andis. %0,%1,%u2
7498    #"
7499   [(set_attr "type" "*,*,*,compare,compare,*")
7500    (set_attr "length" "4,4,4,4,4,8")])
7501
7502 (define_split
7503   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7504         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7505                 (match_operand:DI 2 "mask64_2_operand" "")))
7506    (clobber (match_scratch:CC 3 ""))]
7507   "TARGET_POWERPC64
7508     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7509     && !mask_operand (operands[2], DImode)
7510     && !mask64_operand (operands[2], DImode)"
7511   [(set (match_dup 0)
7512         (and:DI (rotate:DI (match_dup 1)
7513                            (match_dup 4))
7514                 (match_dup 5)))
7515    (set (match_dup 0)
7516         (and:DI (rotate:DI (match_dup 0)
7517                            (match_dup 6))
7518                 (match_dup 7)))]
7519 {
7520   build_mask64_2_operands (operands[2], &operands[4]);
7521 })
7522
7523 (define_insn "*anddi3_internal2"
7524   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
7525         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
7526                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
7527                     (const_int 0)))
7528    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r,r,r"))
7529    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
7530   "TARGET_64BIT"
7531   "@
7532    and. %3,%1,%2
7533    rldic%B2. %3,%1,0,%S2
7534    rlwinm. %3,%1,0,%m2,%M2
7535    andi. %3,%1,%b2
7536    andis. %3,%1,%u2
7537    #
7538    #
7539    #
7540    #
7541    #
7542    #
7543    #"
7544   [(set_attr "type" "compare,compare,delayed_compare,compare,compare,compare,compare,compare,compare,compare,compare,compare")
7545    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
7546
7547 (define_split
7548   [(set (match_operand:CC 0 "cc_reg_operand" "")
7549         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7550                             (match_operand:DI 2 "mask64_2_operand" ""))
7551                     (const_int 0)))
7552    (clobber (match_scratch:DI 3 ""))
7553    (clobber (match_scratch:CC 4 ""))]
7554   "TARGET_64BIT && reload_completed
7555     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7556     && !mask_operand (operands[2], DImode)
7557     && !mask64_operand (operands[2], DImode)"
7558   [(set (match_dup 3)
7559         (and:DI (rotate:DI (match_dup 1)
7560                            (match_dup 5))
7561                 (match_dup 6)))
7562    (parallel [(set (match_dup 0)
7563                    (compare:CC (and:DI (rotate:DI (match_dup 3)
7564                                                   (match_dup 7))
7565                                        (match_dup 8))
7566                                (const_int 0)))
7567               (clobber (match_dup 3))])]
7568   "
7569 {
7570   build_mask64_2_operands (operands[2], &operands[5]);
7571 }")
7572
7573 (define_insn "*anddi3_internal3"
7574   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
7575         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
7576                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
7577                     (const_int 0)))
7578    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r,r,r")
7579         (and:DI (match_dup 1) (match_dup 2)))
7580    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
7581   "TARGET_64BIT"
7582   "@
7583    and. %0,%1,%2
7584    rldic%B2. %0,%1,0,%S2
7585    rlwinm. %0,%1,0,%m2,%M2
7586    andi. %0,%1,%b2
7587    andis. %0,%1,%u2
7588    #
7589    #
7590    #
7591    #
7592    #
7593    #
7594    #"
7595   [(set_attr "type" "compare,compare,delayed_compare,compare,compare,compare,compare,compare,compare,compare,compare,compare")
7596    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
7597
7598 (define_split
7599   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7600         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7601                             (match_operand:DI 2 "and64_2_operand" ""))
7602                     (const_int 0)))
7603    (set (match_operand:DI 0 "gpc_reg_operand" "")
7604         (and:DI (match_dup 1) (match_dup 2)))
7605    (clobber (match_scratch:CC 4 ""))]
7606   "TARGET_64BIT && reload_completed"
7607   [(parallel [(set (match_dup 0)
7608                     (and:DI (match_dup 1) (match_dup 2)))
7609                (clobber (match_dup 4))])
7610    (set (match_dup 3)
7611         (compare:CC (match_dup 0)
7612                     (const_int 0)))]
7613   "")
7614
7615 (define_split
7616   [(set (match_operand:CC 3 "cc_reg_operand" "")
7617         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7618                             (match_operand:DI 2 "mask64_2_operand" ""))
7619                     (const_int 0)))
7620    (set (match_operand:DI 0 "gpc_reg_operand" "")
7621         (and:DI (match_dup 1) (match_dup 2)))
7622    (clobber (match_scratch:CC 4 ""))]
7623   "TARGET_64BIT && reload_completed
7624     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7625     && !mask_operand (operands[2], DImode)
7626     && !mask64_operand (operands[2], DImode)"
7627   [(set (match_dup 0)
7628         (and:DI (rotate:DI (match_dup 1)
7629                            (match_dup 5))
7630                 (match_dup 6)))
7631    (parallel [(set (match_dup 3)
7632                    (compare:CC (and:DI (rotate:DI (match_dup 0)
7633                                                   (match_dup 7))
7634                                        (match_dup 8))
7635                                (const_int 0)))
7636               (set (match_dup 0)
7637                    (and:DI (rotate:DI (match_dup 0)
7638                                       (match_dup 7))
7639                            (match_dup 8)))])]
7640   "
7641 {
7642   build_mask64_2_operands (operands[2], &operands[5]);
7643 }")
7644
7645 (define_expand "iordi3"
7646   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7647         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
7648                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7649   "TARGET_POWERPC64"
7650   "
7651 {
7652   if (non_logical_cint_operand (operands[2], DImode))
7653     {
7654       HOST_WIDE_INT value;
7655       rtx tmp = ((!can_create_pseudo_p ()
7656                   || rtx_equal_p (operands[0], operands[1]))
7657                  ? operands[0] : gen_reg_rtx (DImode));
7658
7659       if (GET_CODE (operands[2]) == CONST_INT)
7660         {
7661           value = INTVAL (operands[2]);
7662           emit_insn (gen_iordi3 (tmp, operands[1],
7663                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7664         }
7665       else
7666         {
7667           value = CONST_DOUBLE_LOW (operands[2]);
7668           emit_insn (gen_iordi3 (tmp, operands[1],
7669                                  immed_double_const (value
7670                                                      & (~ (HOST_WIDE_INT) 0xffff),
7671                                                      0, DImode)));
7672         }
7673
7674       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7675       DONE;
7676     }
7677 }")
7678
7679 (define_expand "xordi3"
7680   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7681         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
7682                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7683   "TARGET_POWERPC64"
7684   "
7685 {
7686   if (non_logical_cint_operand (operands[2], DImode))
7687     {
7688       HOST_WIDE_INT value;
7689       rtx tmp = ((!can_create_pseudo_p ()
7690                   || rtx_equal_p (operands[0], operands[1]))
7691                  ? operands[0] : gen_reg_rtx (DImode));
7692
7693       if (GET_CODE (operands[2]) == CONST_INT)
7694         {
7695           value = INTVAL (operands[2]);
7696           emit_insn (gen_xordi3 (tmp, operands[1],
7697                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7698         }
7699       else
7700         {
7701           value = CONST_DOUBLE_LOW (operands[2]);
7702           emit_insn (gen_xordi3 (tmp, operands[1],
7703                                  immed_double_const (value
7704                                                      & (~ (HOST_WIDE_INT) 0xffff),
7705                                                      0, DImode)));
7706         }
7707
7708       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7709       DONE;
7710     }
7711 }")
7712
7713 (define_insn "*booldi3_internal1"
7714   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
7715         (match_operator:DI 3 "boolean_or_operator"
7716          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
7717           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
7718   "TARGET_POWERPC64"
7719   "@
7720    %q3 %0,%1,%2
7721    %q3i %0,%1,%b2
7722    %q3is %0,%1,%u2")
7723
7724 (define_insn "*booldi3_internal2"
7725   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7726         (compare:CC (match_operator:DI 4 "boolean_or_operator"
7727          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7728           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7729          (const_int 0)))
7730    (clobber (match_scratch:DI 3 "=r,r"))]
7731   "TARGET_64BIT"
7732   "@
7733    %q4. %3,%1,%2
7734    #"
7735   [(set_attr "type" "compare")
7736    (set_attr "length" "4,8")])
7737
7738 (define_split
7739   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7740         (compare:CC (match_operator:DI 4 "boolean_operator"
7741          [(match_operand:DI 1 "gpc_reg_operand" "")
7742           (match_operand:DI 2 "gpc_reg_operand" "")])
7743          (const_int 0)))
7744    (clobber (match_scratch:DI 3 ""))]
7745   "TARGET_POWERPC64 && reload_completed"
7746   [(set (match_dup 3) (match_dup 4))
7747    (set (match_dup 0)
7748         (compare:CC (match_dup 3)
7749                     (const_int 0)))]
7750   "")
7751
7752 (define_insn "*booldi3_internal3"
7753   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7754         (compare:CC (match_operator:DI 4 "boolean_operator"
7755          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7756           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7757          (const_int 0)))
7758    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7759         (match_dup 4))]
7760   "TARGET_64BIT"
7761   "@
7762    %q4. %0,%1,%2
7763    #"
7764   [(set_attr "type" "compare")
7765    (set_attr "length" "4,8")])
7766
7767 (define_split
7768   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7769         (compare:CC (match_operator:DI 4 "boolean_operator"
7770          [(match_operand:DI 1 "gpc_reg_operand" "")
7771           (match_operand:DI 2 "gpc_reg_operand" "")])
7772          (const_int 0)))
7773    (set (match_operand:DI 0 "gpc_reg_operand" "")
7774         (match_dup 4))]
7775   "TARGET_POWERPC64 && reload_completed"
7776   [(set (match_dup 0) (match_dup 4))
7777    (set (match_dup 3)
7778         (compare:CC (match_dup 0)
7779                     (const_int 0)))]
7780   "")
7781
7782 ;; Split a logical operation that we can't do in one insn into two insns,
7783 ;; each of which does one 16-bit part.  This is used by combine.
7784
7785 (define_split
7786   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7787         (match_operator:DI 3 "boolean_or_operator"
7788          [(match_operand:DI 1 "gpc_reg_operand" "")
7789           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
7790   "TARGET_POWERPC64"
7791   [(set (match_dup 0) (match_dup 4))
7792    (set (match_dup 0) (match_dup 5))]
7793 "
7794 {
7795   rtx i3,i4;
7796
7797   if (GET_CODE (operands[2]) == CONST_DOUBLE)
7798     {
7799       HOST_WIDE_INT value = CONST_DOUBLE_LOW (operands[2]);
7800       i3 = immed_double_const (value & (~ (HOST_WIDE_INT) 0xffff),
7801                                         0, DImode);
7802       i4 = GEN_INT (value & 0xffff);
7803     }
7804   else
7805     {
7806       i3 = GEN_INT (INTVAL (operands[2])
7807                              & (~ (HOST_WIDE_INT) 0xffff));
7808       i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
7809     }
7810   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7811                                 operands[1], i3);
7812   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7813                                 operands[0], i4);
7814 }")
7815
7816 (define_insn "*boolcdi3_internal1"
7817   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7818         (match_operator:DI 3 "boolean_operator"
7819          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7820           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
7821   "TARGET_POWERPC64"
7822   "%q3 %0,%2,%1")
7823
7824 (define_insn "*boolcdi3_internal2"
7825   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7826         (compare:CC (match_operator:DI 4 "boolean_operator"
7827          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7828           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7829          (const_int 0)))
7830    (clobber (match_scratch:DI 3 "=r,r"))]
7831   "TARGET_64BIT"
7832   "@
7833    %q4. %3,%2,%1
7834    #"
7835   [(set_attr "type" "compare")
7836    (set_attr "length" "4,8")])
7837
7838 (define_split
7839   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7840         (compare:CC (match_operator:DI 4 "boolean_operator"
7841          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7842           (match_operand:DI 2 "gpc_reg_operand" "")])
7843          (const_int 0)))
7844    (clobber (match_scratch:DI 3 ""))]
7845   "TARGET_POWERPC64 && reload_completed"
7846   [(set (match_dup 3) (match_dup 4))
7847    (set (match_dup 0)
7848         (compare:CC (match_dup 3)
7849                     (const_int 0)))]
7850   "")
7851
7852 (define_insn "*boolcdi3_internal3"
7853   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7854         (compare:CC (match_operator:DI 4 "boolean_operator"
7855          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7856           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7857          (const_int 0)))
7858    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7859         (match_dup 4))]
7860   "TARGET_64BIT"
7861   "@
7862    %q4. %0,%2,%1
7863    #"
7864   [(set_attr "type" "compare")
7865    (set_attr "length" "4,8")])
7866
7867 (define_split
7868   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7869         (compare:CC (match_operator:DI 4 "boolean_operator"
7870          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7871           (match_operand:DI 2 "gpc_reg_operand" "")])
7872          (const_int 0)))
7873    (set (match_operand:DI 0 "gpc_reg_operand" "")
7874         (match_dup 4))]
7875   "TARGET_POWERPC64 && reload_completed"
7876   [(set (match_dup 0) (match_dup 4))
7877    (set (match_dup 3)
7878         (compare:CC (match_dup 0)
7879                     (const_int 0)))]
7880   "")
7881
7882 (define_insn "*boolccdi3_internal1"
7883   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7884         (match_operator:DI 3 "boolean_operator"
7885          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7886           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
7887   "TARGET_POWERPC64"
7888   "%q3 %0,%1,%2")
7889
7890 (define_insn "*boolccdi3_internal2"
7891   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7892         (compare:CC (match_operator:DI 4 "boolean_operator"
7893          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7894           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7895          (const_int 0)))
7896    (clobber (match_scratch:DI 3 "=r,r"))]
7897   "TARGET_64BIT"
7898   "@
7899    %q4. %3,%1,%2
7900    #"
7901   [(set_attr "type" "compare")
7902    (set_attr "length" "4,8")])
7903
7904 (define_split
7905   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7906         (compare:CC (match_operator:DI 4 "boolean_operator"
7907          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7908           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7909          (const_int 0)))
7910    (clobber (match_scratch:DI 3 ""))]
7911   "TARGET_POWERPC64 && reload_completed"
7912   [(set (match_dup 3) (match_dup 4))
7913    (set (match_dup 0)
7914         (compare:CC (match_dup 3)
7915                     (const_int 0)))]
7916   "")
7917
7918 (define_insn "*boolccdi3_internal3"
7919   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7920         (compare:CC (match_operator:DI 4 "boolean_operator"
7921          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7922           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7923          (const_int 0)))
7924    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7925         (match_dup 4))]
7926   "TARGET_64BIT"
7927   "@
7928    %q4. %0,%1,%2
7929    #"
7930   [(set_attr "type" "compare")
7931    (set_attr "length" "4,8")])
7932
7933 (define_split
7934   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7935         (compare:CC (match_operator:DI 4 "boolean_operator"
7936          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7937           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7938          (const_int 0)))
7939    (set (match_operand:DI 0 "gpc_reg_operand" "")
7940         (match_dup 4))]
7941   "TARGET_POWERPC64 && reload_completed"
7942   [(set (match_dup 0) (match_dup 4))
7943    (set (match_dup 3)
7944         (compare:CC (match_dup 0)
7945                     (const_int 0)))]
7946   "")
7947 \f
7948 ;; Now define ways of moving data around.
7949
7950 ;; Set up a register with a value from the GOT table
7951
7952 (define_expand "movsi_got"
7953   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7954         (unspec:SI [(match_operand:SI 1 "got_operand" "")
7955                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
7956   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7957   "
7958 {
7959   if (GET_CODE (operands[1]) == CONST)
7960     {
7961       rtx offset = const0_rtx;
7962       HOST_WIDE_INT value;
7963
7964       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
7965       value = INTVAL (offset);
7966       if (value != 0)
7967         {
7968           rtx tmp = (!can_create_pseudo_p ()
7969                      ? operands[0]
7970                      : gen_reg_rtx (Pmode));
7971           emit_insn (gen_movsi_got (tmp, operands[1]));
7972           emit_insn (gen_addsi3 (operands[0], tmp, offset));
7973           DONE;
7974         }
7975     }
7976
7977   operands[2] = rs6000_got_register (operands[1]);
7978 }")
7979
7980 (define_insn "*movsi_got_internal"
7981   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7982         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7983                     (match_operand:SI 2 "gpc_reg_operand" "b")]
7984                    UNSPEC_MOVSI_GOT))]
7985   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7986   "{l|lwz} %0,%a1@got(%2)"
7987   [(set_attr "type" "load")])
7988
7989 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
7990 ;; didn't get allocated to a hard register.
7991 (define_split
7992   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7993         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7994                     (match_operand:SI 2 "memory_operand" "")]
7995                    UNSPEC_MOVSI_GOT))]
7996   "DEFAULT_ABI == ABI_V4
7997     && flag_pic == 1
7998     && (reload_in_progress || reload_completed)"
7999   [(set (match_dup 0) (match_dup 2))
8000    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
8001                                  UNSPEC_MOVSI_GOT))]
8002   "")
8003
8004 ;; For SI, we special-case integers that can't be loaded in one insn.  We
8005 ;; do the load 16-bits at a time.  We could do this by loading from memory,
8006 ;; and this is even supposed to be faster, but it is simpler not to get
8007 ;; integers in the TOC.
8008 (define_insn "movsi_low"
8009   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8010         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
8011                            (match_operand 2 "" ""))))]
8012   "TARGET_MACHO && ! TARGET_64BIT"
8013   "{l|lwz} %0,lo16(%2)(%1)"
8014   [(set_attr "type" "load")
8015    (set_attr "length" "4")])
8016
8017 (define_insn "*movsi_internal1"
8018   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h")
8019         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0"))]
8020   "gpc_reg_operand (operands[0], SImode)
8021    || gpc_reg_operand (operands[1], SImode)"
8022   "@
8023    mr %0,%1
8024    {cal|la} %0,%a1
8025    {l%U1%X1|lwz%U1%X1} %0,%1
8026    {st%U0%X0|stw%U0%X0} %1,%0
8027    {lil|li} %0,%1
8028    {liu|lis} %0,%v1
8029    #
8030    {cal|la} %0,%a1
8031    mf%1 %0
8032    mt%0 %1
8033    mt%0 %1
8034    mt%0 %1
8035    {cror 0,0,0|nop}"
8036   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*")
8037    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
8038
8039 ;; Split a load of a large constant into the appropriate two-insn
8040 ;; sequence.
8041
8042 (define_split
8043   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8044         (match_operand:SI 1 "const_int_operand" ""))]
8045   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
8046    && (INTVAL (operands[1]) & 0xffff) != 0"
8047   [(set (match_dup 0)
8048         (match_dup 2))
8049    (set (match_dup 0)
8050         (ior:SI (match_dup 0)
8051                 (match_dup 3)))]
8052   "
8053 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
8054
8055   if (tem == operands[0])
8056     DONE;
8057   else
8058     FAIL;
8059 }")
8060
8061 (define_insn "*mov<mode>_internal2"
8062   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
8063         (compare:CC (match_operand:P 1 "gpc_reg_operand" "0,r,r")
8064                     (const_int 0)))
8065    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
8066   ""
8067   "@
8068    {cmpi|cmp<wd>i} %2,%0,0
8069    mr. %0,%1
8070    #"
8071   [(set_attr "type" "cmp,compare,cmp")
8072    (set_attr "length" "4,4,8")])
8073
8074 (define_split
8075   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
8076         (compare:CC (match_operand:P 1 "gpc_reg_operand" "")
8077                     (const_int 0)))
8078    (set (match_operand:P 0 "gpc_reg_operand" "") (match_dup 1))]
8079   "reload_completed"
8080   [(set (match_dup 0) (match_dup 1))
8081    (set (match_dup 2)
8082         (compare:CC (match_dup 0)
8083                     (const_int 0)))]
8084   "")
8085 \f
8086 (define_insn "*movhi_internal"
8087   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
8088         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
8089   "gpc_reg_operand (operands[0], HImode)
8090    || gpc_reg_operand (operands[1], HImode)"
8091   "@
8092    mr %0,%1
8093    lhz%U1%X1 %0,%1
8094    sth%U0%X0 %1,%0
8095    {lil|li} %0,%w1
8096    mf%1 %0
8097    mt%0 %1
8098    mt%0 %1
8099    {cror 0,0,0|nop}"
8100   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
8101
8102 (define_expand "mov<mode>"
8103   [(set (match_operand:INT 0 "general_operand" "")
8104         (match_operand:INT 1 "any_operand" ""))]
8105   ""
8106   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
8107
8108 (define_insn "*movqi_internal"
8109   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
8110         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
8111   "gpc_reg_operand (operands[0], QImode)
8112    || gpc_reg_operand (operands[1], QImode)"
8113   "@
8114    mr %0,%1
8115    lbz%U1%X1 %0,%1
8116    stb%U0%X0 %1,%0
8117    {lil|li} %0,%1
8118    mf%1 %0
8119    mt%0 %1
8120    mt%0 %1
8121    {cror 0,0,0|nop}"
8122   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
8123 \f
8124 ;; Here is how to move condition codes around.  When we store CC data in
8125 ;; an integer register or memory, we store just the high-order 4 bits.
8126 ;; This lets us not shift in the most common case of CR0.
8127 (define_expand "movcc"
8128   [(set (match_operand:CC 0 "nonimmediate_operand" "")
8129         (match_operand:CC 1 "nonimmediate_operand" ""))]
8130   ""
8131   "")
8132
8133 (define_insn "*movcc_internal1"
8134   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,y,r,r,r,r,r,q,cl,r,m")
8135         (match_operand:CC 1 "general_operand" "y,r,r,O,x,y,r,I,h,r,r,m,r"))]
8136   "register_operand (operands[0], CCmode)
8137    || register_operand (operands[1], CCmode)"
8138   "@
8139    mcrf %0,%1
8140    mtcrf 128,%1
8141    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
8142    crxor %0,%0,%0
8143    mfcr %0%Q1
8144    mfcr %0%Q1\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
8145    mr %0,%1
8146    {lil|li} %0,%1
8147    mf%1 %0
8148    mt%0 %1
8149    mt%0 %1
8150    {l%U1%X1|lwz%U1%X1} %0,%1
8151    {st%U0%U1|stw%U0%U1} %1,%0"
8152   [(set (attr "type")
8153      (cond [(eq_attr "alternative" "0,3")
8154                 (const_string "cr_logical")
8155             (eq_attr "alternative" "1,2")
8156                 (const_string "mtcr")
8157             (eq_attr "alternative" "6,7,9")
8158                 (const_string "integer")
8159             (eq_attr "alternative" "8")
8160                 (const_string "mfjmpr")
8161             (eq_attr "alternative" "10")
8162                 (const_string "mtjmpr")
8163             (eq_attr "alternative" "11")
8164                 (const_string "load")
8165             (eq_attr "alternative" "12")
8166                 (const_string "store")
8167             (ne (symbol_ref "TARGET_MFCRF") (const_int 0))
8168                 (const_string "mfcrf")
8169            ]
8170         (const_string "mfcr")))
8171    (set_attr "length" "4,4,12,4,4,8,4,4,4,4,4,4,4")])
8172 \f
8173 ;; For floating-point, we normally deal with the floating-point registers
8174 ;; unless -msoft-float is used.  The sole exception is that parameter passing
8175 ;; can produce floating-point values in fixed-point registers.  Unless the
8176 ;; value is a simple constant or already in memory, we deal with this by
8177 ;; allocating memory and copying the value explicitly via that memory location.
8178 (define_expand "movsf"
8179   [(set (match_operand:SF 0 "nonimmediate_operand" "")
8180         (match_operand:SF 1 "any_operand" ""))]
8181   ""
8182   "{ rs6000_emit_move (operands[0], operands[1], SFmode); DONE; }")
8183
8184 (define_split
8185   [(set (match_operand:SF 0 "gpc_reg_operand" "")
8186         (match_operand:SF 1 "const_double_operand" ""))]
8187   "reload_completed
8188    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8189        || (GET_CODE (operands[0]) == SUBREG
8190            && GET_CODE (SUBREG_REG (operands[0])) == REG
8191            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8192   [(set (match_dup 2) (match_dup 3))]
8193   "
8194 {
8195   long l;
8196   REAL_VALUE_TYPE rv;
8197
8198   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8199   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
8200
8201   if (! TARGET_POWERPC64)
8202     operands[2] = operand_subword (operands[0], 0, 0, SFmode);
8203   else
8204     operands[2] = gen_lowpart (SImode, operands[0]);
8205
8206   operands[3] = gen_int_mode (l, SImode);
8207 }")
8208
8209 (define_insn "*movsf_hardfloat"
8210   [(set (match_operand:SF 0 "nonimmediate_operand" "=!r,!r,m,f,f,m,*c*l,*q,!r,*h,!r,!r")
8211         (match_operand:SF 1 "input_operand" "r,m,r,f,m,f,r,r,h,0,G,Fn"))]
8212   "(gpc_reg_operand (operands[0], SFmode)
8213    || gpc_reg_operand (operands[1], SFmode))
8214    && (TARGET_HARD_FLOAT && TARGET_FPRS)"
8215   "@
8216    mr %0,%1
8217    {l%U1%X1|lwz%U1%X1} %0,%1
8218    {st%U0%X0|stw%U0%X0} %1,%0
8219    fmr %0,%1
8220    lfs%U1%X1 %0,%1
8221    stfs%U0%X0 %1,%0
8222    mt%0 %1
8223    mt%0 %1
8224    mf%1 %0
8225    {cror 0,0,0|nop}
8226    #
8227    #"
8228   [(set_attr "type" "*,load,store,fp,fpload,fpstore,mtjmpr,*,mfjmpr,*,*,*")
8229    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,8")])
8230
8231 (define_insn "*movsf_softfloat"
8232   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,cl,q,r,r,m,r,r,r,r,r,*h")
8233         (match_operand:SF 1 "input_operand" "r,r,r,h,m,r,I,L,R,G,Fn,0"))]
8234   "(gpc_reg_operand (operands[0], SFmode)
8235    || gpc_reg_operand (operands[1], SFmode))
8236    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
8237   "@
8238    mr %0,%1
8239    mt%0 %1
8240    mt%0 %1
8241    mf%1 %0
8242    {l%U1%X1|lwz%U1%X1} %0,%1
8243    {st%U0%X0|stw%U0%X0} %1,%0
8244    {lil|li} %0,%1
8245    {liu|lis} %0,%v1
8246    {cal|la} %0,%a1
8247    #
8248    #
8249    {cror 0,0,0|nop}"
8250   [(set_attr "type" "*,mtjmpr,*,mfjmpr,load,store,*,*,*,*,*,*")
8251    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,4")])
8252
8253 \f
8254 (define_expand "movdf"
8255   [(set (match_operand:DF 0 "nonimmediate_operand" "")
8256         (match_operand:DF 1 "any_operand" ""))]
8257   ""
8258   "{ rs6000_emit_move (operands[0], operands[1], DFmode); DONE; }")
8259
8260 (define_split
8261   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8262         (match_operand:DF 1 "const_int_operand" ""))]
8263   "! TARGET_POWERPC64 && reload_completed
8264    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8265        || (GET_CODE (operands[0]) == SUBREG
8266            && GET_CODE (SUBREG_REG (operands[0])) == REG
8267            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8268   [(set (match_dup 2) (match_dup 4))
8269    (set (match_dup 3) (match_dup 1))]
8270   "
8271 {
8272   int endian = (WORDS_BIG_ENDIAN == 0);
8273   HOST_WIDE_INT value = INTVAL (operands[1]);
8274
8275   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
8276   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
8277 #if HOST_BITS_PER_WIDE_INT == 32
8278   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8279 #else
8280   operands[4] = GEN_INT (value >> 32);
8281   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8282 #endif
8283 }")
8284
8285 (define_split
8286   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8287         (match_operand:DF 1 "const_double_operand" ""))]
8288   "! TARGET_POWERPC64 && reload_completed
8289    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8290        || (GET_CODE (operands[0]) == SUBREG
8291            && GET_CODE (SUBREG_REG (operands[0])) == REG
8292            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8293   [(set (match_dup 2) (match_dup 4))
8294    (set (match_dup 3) (match_dup 5))]
8295   "
8296 {
8297   int endian = (WORDS_BIG_ENDIAN == 0);
8298   long l[2];
8299   REAL_VALUE_TYPE rv;
8300
8301   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8302   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8303
8304   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
8305   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
8306   operands[4] = gen_int_mode (l[endian], SImode);
8307   operands[5] = gen_int_mode (l[1 - endian], SImode);
8308 }")
8309
8310 (define_split
8311   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8312         (match_operand:DF 1 "const_double_operand" ""))]
8313   "TARGET_POWERPC64 && reload_completed
8314    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8315        || (GET_CODE (operands[0]) == SUBREG
8316            && GET_CODE (SUBREG_REG (operands[0])) == REG
8317            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8318   [(set (match_dup 2) (match_dup 3))]
8319   "
8320 {
8321   int endian = (WORDS_BIG_ENDIAN == 0);
8322   long l[2];
8323   REAL_VALUE_TYPE rv;
8324 #if HOST_BITS_PER_WIDE_INT >= 64
8325   HOST_WIDE_INT val;
8326 #endif
8327
8328   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8329   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8330
8331   operands[2] = gen_lowpart (DImode, operands[0]);
8332   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
8333 #if HOST_BITS_PER_WIDE_INT >= 64
8334   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
8335          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
8336
8337   operands[3] = gen_int_mode (val, DImode);
8338 #else
8339   operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
8340 #endif
8341 }")
8342
8343 ;; Don't have reload use general registers to load a constant.  First,
8344 ;; it might not work if the output operand is the equivalent of
8345 ;; a non-offsettable memref, but also it is less efficient than loading
8346 ;; the constant into an FP register, since it will probably be used there.
8347 ;; The "??" is a kludge until we can figure out a more reasonable way
8348 ;; of handling these non-offsettable values.
8349 (define_insn "*movdf_hardfloat32"
8350   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,m,f,f,m,!r,!r,!r")
8351         (match_operand:DF 1 "input_operand" "r,m,r,f,m,f,G,H,F"))]
8352   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8353    && (gpc_reg_operand (operands[0], DFmode)
8354        || gpc_reg_operand (operands[1], DFmode))"
8355   "*
8356 {
8357   switch (which_alternative)
8358     {
8359     default:
8360       gcc_unreachable ();
8361     case 0:
8362       /* We normally copy the low-numbered register first.  However, if
8363          the first register operand 0 is the same as the second register
8364          of operand 1, we must copy in the opposite order.  */
8365       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8366         return \"mr %L0,%L1\;mr %0,%1\";
8367       else
8368         return \"mr %0,%1\;mr %L0,%L1\";
8369     case 1:
8370       if (rs6000_offsettable_memref_p (operands[1])
8371           || (GET_CODE (operands[1]) == MEM
8372               && (GET_CODE (XEXP (operands[1], 0)) == LO_SUM
8373                   || GET_CODE (XEXP (operands[1], 0)) == PRE_INC
8374                   || GET_CODE (XEXP (operands[1], 0)) == PRE_DEC
8375                   || GET_CODE (XEXP (operands[1], 0)) == PRE_MODIFY)))
8376         {
8377           /* If the low-address word is used in the address, we must load
8378              it last.  Otherwise, load it first.  Note that we cannot have
8379              auto-increment in that case since the address register is
8380              known to be dead.  */
8381           if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8382                                  operands[1], 0))
8383             return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8384           else
8385             return \"{l%U1%X1|lwz%U1%X1} %0,%1\;{l|lwz} %L0,%L1\";
8386         }
8387       else
8388         {
8389           rtx addreg;
8390
8391           addreg = find_addr_reg (XEXP (operands[1], 0));
8392           if (refers_to_regno_p (REGNO (operands[0]),
8393                                  REGNO (operands[0]) + 1,
8394                                  operands[1], 0))
8395             {
8396               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8397               output_asm_insn (\"{l%X1|lwz%X1} %L0,%1\", operands);
8398               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8399               return \"{l%X1|lwz%X1} %0,%1\";
8400             }
8401           else
8402             {
8403               output_asm_insn (\"{l%X1|lwz%X1} %0,%1\", operands);
8404               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8405               output_asm_insn (\"{l%X1|lwz%X1} %L0,%1\", operands);
8406               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8407               return \"\";
8408             }
8409         }
8410     case 2:
8411       if (rs6000_offsettable_memref_p (operands[0])
8412           || (GET_CODE (operands[0]) == MEM
8413               && (GET_CODE (XEXP (operands[0], 0)) == LO_SUM
8414                   || GET_CODE (XEXP (operands[0], 0)) == PRE_INC
8415                   || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
8416                   || GET_CODE (XEXP (operands[0], 0)) == PRE_MODIFY)))
8417         return \"{st%U0%X0|stw%U0%X0} %1,%0\;{st|stw} %L1,%L0\";
8418       else
8419         {
8420           rtx addreg;
8421
8422           addreg = find_addr_reg (XEXP (operands[0], 0));
8423           output_asm_insn (\"{st%X0|stw%X0} %1,%0\", operands);
8424           output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8425           output_asm_insn (\"{st%X0|stw%X0} %L1,%0\", operands);
8426           output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8427           return \"\";
8428         }
8429     case 3:
8430       return \"fmr %0,%1\";
8431     case 4:
8432       return \"lfd%U1%X1 %0,%1\";
8433     case 5:
8434       return \"stfd%U0%X0 %1,%0\";
8435     case 6:
8436     case 7:
8437     case 8:
8438       return \"#\";
8439     }
8440 }"
8441   [(set_attr "type" "two,load,store,fp,fpload,fpstore,*,*,*")
8442    (set_attr "length" "8,16,16,4,4,4,8,12,16")])
8443
8444 (define_insn "*movdf_softfloat32"
8445   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
8446         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F"))]
8447   "! TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || TARGET_E500_SINGLE)
8448    && (gpc_reg_operand (operands[0], DFmode)
8449        || gpc_reg_operand (operands[1], DFmode))"
8450   "*
8451 {
8452   switch (which_alternative)
8453     {
8454     default:
8455       gcc_unreachable ();
8456     case 0:
8457       /* We normally copy the low-numbered register first.  However, if
8458          the first register operand 0 is the same as the second register of
8459          operand 1, we must copy in the opposite order.  */
8460       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8461         return \"mr %L0,%L1\;mr %0,%1\";
8462       else
8463         return \"mr %0,%1\;mr %L0,%L1\";
8464     case 1:
8465       /* If the low-address word is used in the address, we must load
8466          it last.  Otherwise, load it first.  Note that we cannot have
8467          auto-increment in that case since the address register is
8468          known to be dead.  */
8469       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8470                              operands[1], 0))
8471         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8472       else
8473         return \"{l%U1%X1|lwz%U1%X1} %0,%1\;{l|lwz} %L0,%L1\";
8474     case 2:
8475       return \"{st%U0%X0|stw%U0%X0} %1,%0\;{st|stw} %L1,%L0\";
8476     case 3:
8477     case 4:
8478     case 5:
8479       return \"#\";
8480     }
8481 }"
8482   [(set_attr "type" "two,load,store,*,*,*")
8483    (set_attr "length" "8,8,8,8,12,16")])
8484
8485 ; ld/std require word-aligned displacements -> 'Y' constraint.
8486 ; List Y->r and r->Y before r->r for reload.
8487 (define_insn "*movdf_hardfloat64_mfpgpr"
8488   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,!r,f,f,m,*c*l,!r,*h,!r,!r,!r,r,f")
8489         (match_operand:DF 1 "input_operand" "r,Y,r,f,m,f,r,h,0,G,H,F,f,r"))]
8490   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS
8491    && (gpc_reg_operand (operands[0], DFmode)
8492        || gpc_reg_operand (operands[1], DFmode))"
8493   "@
8494    std%U0%X0 %1,%0
8495    ld%U1%X1 %0,%1
8496    mr %0,%1
8497    fmr %0,%1
8498    lfd%U1%X1 %0,%1
8499    stfd%U0%X0 %1,%0
8500    mt%0 %1
8501    mf%1 %0
8502    {cror 0,0,0|nop}
8503    #
8504    #
8505    #
8506    mftgpr %0,%1
8507    mffgpr %0,%1"
8508   [(set_attr "type" "store,load,*,fp,fpload,fpstore,mtjmpr,mfjmpr,*,*,*,*,mftgpr,mffgpr")
8509    (set_attr "length" "4,4,4,4,4,4,4,4,4,8,12,16,4,4")])
8510
8511 ; ld/std require word-aligned displacements -> 'Y' constraint.
8512 ; List Y->r and r->Y before r->r for reload.
8513 (define_insn "*movdf_hardfloat64"
8514   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,!r,f,f,m,*c*l,!r,*h,!r,!r,!r")
8515         (match_operand:DF 1 "input_operand" "r,Y,r,f,m,f,r,h,0,G,H,F"))]
8516   "TARGET_POWERPC64 && !TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS
8517    && (gpc_reg_operand (operands[0], DFmode)
8518        || gpc_reg_operand (operands[1], DFmode))"
8519   "@
8520    std%U0%X0 %1,%0
8521    ld%U1%X1 %0,%1
8522    mr %0,%1
8523    fmr %0,%1
8524    lfd%U1%X1 %0,%1
8525    stfd%U0%X0 %1,%0
8526    mt%0 %1
8527    mf%1 %0
8528    {cror 0,0,0|nop}
8529    #
8530    #
8531    #"
8532   [(set_attr "type" "store,load,*,fp,fpload,fpstore,mtjmpr,mfjmpr,*,*,*,*")
8533    (set_attr "length" "4,4,4,4,4,4,4,4,4,8,12,16")])
8534
8535 (define_insn "*movdf_softfloat64"
8536   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,Y,r,cl,r,r,r,r,*h")
8537         (match_operand:DF 1 "input_operand" "Y,r,r,r,h,G,H,F,0"))]
8538   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8539    && (gpc_reg_operand (operands[0], DFmode)
8540        || gpc_reg_operand (operands[1], DFmode))"
8541   "@
8542    ld%U1%X1 %0,%1
8543    std%U0%X0 %1,%0
8544    mr %0,%1
8545    mt%0 %1
8546    mf%1 %0
8547    #
8548    #
8549    #
8550    {cror 0,0,0|nop}"
8551   [(set_attr "type" "load,store,*,mtjmpr,mfjmpr,*,*,*,*")
8552    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
8553 \f
8554 (define_expand "movtf"
8555   [(set (match_operand:TF 0 "general_operand" "")
8556         (match_operand:TF 1 "any_operand" ""))]
8557   "!TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128"
8558   "{ rs6000_emit_move (operands[0], operands[1], TFmode); DONE; }")
8559
8560 ; It's important to list the o->f and f->o moves before f->f because
8561 ; otherwise reload, given m->f, will try to pick f->f and reload it,
8562 ; which doesn't make progress.  Likewise r->Y must be before r->r.
8563 (define_insn_and_split "*movtf_internal"
8564   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,f,r,Y,r")
8565         (match_operand:TF 1 "input_operand"         "f,o,f,YGHF,r,r"))]
8566   "!TARGET_IEEEQUAD
8567    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
8568    && (gpc_reg_operand (operands[0], TFmode)
8569        || gpc_reg_operand (operands[1], TFmode))"
8570   "#"
8571   "&& reload_completed"
8572   [(pc)]
8573 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
8574   [(set_attr "length" "8,8,8,20,20,16")])
8575
8576 (define_insn_and_split "*movtf_softfloat"
8577   [(set (match_operand:TF 0 "rs6000_nonimmediate_operand" "=r,Y,r")
8578         (match_operand:TF 1 "input_operand"         "YGHF,r,r"))]
8579   "!TARGET_IEEEQUAD
8580    && (TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_LONG_DOUBLE_128
8581    && (gpc_reg_operand (operands[0], TFmode)
8582        || gpc_reg_operand (operands[1], TFmode))"
8583   "#"
8584   "&& reload_completed"
8585   [(pc)]
8586 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
8587   [(set_attr "length" "20,20,16")])
8588
8589 (define_expand "extenddftf2"
8590   [(set (match_operand:TF 0 "nonimmediate_operand" "")
8591         (float_extend:TF (match_operand:DF 1 "input_operand" "")))]
8592   "!TARGET_IEEEQUAD
8593    && TARGET_HARD_FLOAT
8594    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8595    && TARGET_LONG_DOUBLE_128"
8596 {
8597   if (TARGET_E500_DOUBLE)
8598     emit_insn (gen_spe_extenddftf2 (operands[0], operands[1]));
8599   else
8600     emit_insn (gen_extenddftf2_fprs (operands[0], operands[1]));
8601   DONE;
8602 })
8603
8604 (define_expand "extenddftf2_fprs"
8605   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
8606                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
8607               (use (match_dup 2))])]
8608   "!TARGET_IEEEQUAD
8609    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8610 {
8611   operands[2] = CONST0_RTX (DFmode);
8612   /* Generate GOT reference early for SVR4 PIC.  */
8613   if (DEFAULT_ABI == ABI_V4 && flag_pic)
8614     operands[2] = validize_mem (force_const_mem (DFmode, operands[2]));
8615 })
8616
8617 (define_insn_and_split "*extenddftf2_internal"
8618   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,&f,r")
8619        (float_extend:TF (match_operand:DF 1 "input_operand" "fr,mf,mf,rmGHF")))
8620    (use (match_operand:DF 2 "zero_reg_mem_operand" "rf,m,f,n"))]
8621   "!TARGET_IEEEQUAD
8622    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8623   "#"
8624   "&& reload_completed"
8625   [(pc)]
8626 {
8627   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8628   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8629   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
8630                   operands[1]);
8631   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
8632                   operands[2]);
8633   DONE;
8634 })
8635
8636 (define_expand "extendsftf2"
8637   [(set (match_operand:TF 0 "nonimmediate_operand" "")
8638         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
8639   "!TARGET_IEEEQUAD
8640    && TARGET_HARD_FLOAT
8641    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8642    && TARGET_LONG_DOUBLE_128"
8643 {
8644   rtx tmp = gen_reg_rtx (DFmode);
8645   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
8646   emit_insn (gen_extenddftf2 (operands[0], tmp));
8647   DONE;
8648 })
8649
8650 (define_expand "trunctfdf2"
8651   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8652         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))]
8653   "!TARGET_IEEEQUAD
8654    && TARGET_HARD_FLOAT
8655    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8656    && TARGET_LONG_DOUBLE_128"
8657   "")
8658
8659 (define_insn_and_split "trunctfdf2_internal1"
8660   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,?f")
8661         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "0,f")))]
8662   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
8663    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8664   "@
8665    #
8666    fmr %0,%1"
8667   "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
8668   [(const_int 0)]
8669 {
8670   emit_note (NOTE_INSN_DELETED);
8671   DONE;
8672 }
8673   [(set_attr "type" "fp")])
8674
8675 (define_insn "trunctfdf2_internal2"
8676   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8677         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8678   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
8679    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8680   "fadd %0,%1,%L1"
8681   [(set_attr "type" "fp")])
8682
8683 (define_expand "trunctfsf2"
8684   [(set (match_operand:SF 0 "gpc_reg_operand" "")
8685         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "")))]
8686   "!TARGET_IEEEQUAD
8687    && TARGET_HARD_FLOAT
8688    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8689    && TARGET_LONG_DOUBLE_128"
8690 {
8691   if (TARGET_E500_DOUBLE)
8692     emit_insn (gen_spe_trunctfsf2 (operands[0], operands[1]));
8693   else
8694     emit_insn (gen_trunctfsf2_fprs (operands[0], operands[1]));
8695   DONE;
8696 })
8697
8698 (define_insn_and_split "trunctfsf2_fprs"
8699   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
8700         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "f")))
8701    (clobber (match_scratch:DF 2 "=f"))]
8702   "!TARGET_IEEEQUAD
8703    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8704   "#"
8705   "&& reload_completed"
8706   [(set (match_dup 2)
8707         (float_truncate:DF (match_dup 1)))
8708    (set (match_dup 0)
8709         (float_truncate:SF (match_dup 2)))]
8710   "")
8711
8712 (define_expand "floatsitf2"
8713   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8714         (float:TF (match_operand:SI 1 "gpc_reg_operand" "")))]
8715   "!TARGET_IEEEQUAD
8716    && TARGET_HARD_FLOAT
8717    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8718    && TARGET_LONG_DOUBLE_128"
8719 {
8720   rtx tmp = gen_reg_rtx (DFmode);
8721   expand_float (tmp, operands[1], false);
8722   emit_insn (gen_extenddftf2 (operands[0], tmp));
8723   DONE;
8724 })
8725
8726 ; fadd, but rounding towards zero.
8727 ; This is probably not the optimal code sequence.
8728 (define_insn "fix_trunc_helper"
8729   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8730         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "f")]
8731                    UNSPEC_FIX_TRUNC_TF))
8732    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&f"))]
8733   "TARGET_HARD_FLOAT && TARGET_FPRS"
8734   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
8735   [(set_attr "type" "fp")
8736    (set_attr "length" "20")])
8737
8738 (define_expand "fix_trunctfsi2"
8739   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8740         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))]
8741   "!TARGET_IEEEQUAD
8742    && (TARGET_POWER2 || TARGET_POWERPC)
8743    && TARGET_HARD_FLOAT
8744    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8745    && TARGET_LONG_DOUBLE_128"
8746 {
8747   if (TARGET_E500_DOUBLE)
8748     emit_insn (gen_spe_fix_trunctfsi2 (operands[0], operands[1]));
8749   else
8750     emit_insn (gen_fix_trunctfsi2_fprs (operands[0], operands[1]));
8751   DONE;
8752 })
8753
8754 (define_expand "fix_trunctfsi2_fprs"
8755   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
8756                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
8757               (clobber (match_dup 2))
8758               (clobber (match_dup 3))
8759               (clobber (match_dup 4))
8760               (clobber (match_dup 5))])]
8761   "!TARGET_IEEEQUAD
8762    && (TARGET_POWER2 || TARGET_POWERPC)
8763    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8764 {
8765   operands[2] = gen_reg_rtx (DFmode);
8766   operands[3] = gen_reg_rtx (DFmode);
8767   operands[4] = gen_reg_rtx (DImode);
8768   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
8769 })
8770
8771 (define_insn_and_split "*fix_trunctfsi2_internal"
8772   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8773         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "f")))
8774    (clobber (match_operand:DF 2 "gpc_reg_operand" "=f"))
8775    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&f"))
8776    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))
8777    (clobber (match_operand:DI 5 "memory_operand" "=o"))]
8778   "!TARGET_IEEEQUAD
8779    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8780   "#"
8781   "&& (can_create_pseudo_p () || offsettable_nonstrict_memref_p (operands[5]))"
8782   [(pc)]
8783 {
8784   rtx lowword;
8785   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
8786
8787   gcc_assert (MEM_P (operands[5]));
8788   lowword = adjust_address (operands[5], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
8789
8790   emit_insn (gen_fctiwz (operands[4], operands[2]));
8791   emit_move_insn (operands[5], operands[4]);
8792   emit_move_insn (operands[0], lowword);
8793   DONE;
8794 })
8795
8796 (define_expand "negtf2"
8797   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8798         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
8799   "!TARGET_IEEEQUAD
8800    && TARGET_HARD_FLOAT
8801    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8802    && TARGET_LONG_DOUBLE_128"
8803   "")
8804
8805 (define_insn "negtf2_internal"
8806   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8807         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8808   "!TARGET_IEEEQUAD
8809    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8810   "*
8811 {
8812   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8813     return \"fneg %L0,%L1\;fneg %0,%1\";
8814   else
8815     return \"fneg %0,%1\;fneg %L0,%L1\";
8816 }"
8817   [(set_attr "type" "fp")
8818    (set_attr "length" "8")])
8819
8820 (define_expand "abstf2"
8821   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8822         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
8823   "!TARGET_IEEEQUAD
8824    && TARGET_HARD_FLOAT
8825    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8826    && TARGET_LONG_DOUBLE_128"
8827   "
8828 {
8829   rtx label = gen_label_rtx ();
8830   if (TARGET_E500_DOUBLE)
8831     {
8832       if (flag_unsafe_math_optimizations)
8833         emit_insn (gen_spe_abstf2_tst (operands[0], operands[1], label));
8834       else
8835         emit_insn (gen_spe_abstf2_cmp (operands[0], operands[1], label));
8836     }
8837   else
8838     emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
8839   emit_label (label);
8840   DONE;
8841 }")
8842
8843 (define_expand "abstf2_internal"
8844   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8845         (match_operand:TF 1 "gpc_reg_operand" ""))
8846    (set (match_dup 3) (match_dup 5))
8847    (set (match_dup 5) (abs:DF (match_dup 5)))
8848    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
8849    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
8850                            (label_ref (match_operand 2 "" ""))
8851                            (pc)))
8852    (set (match_dup 6) (neg:DF (match_dup 6)))]
8853   "!TARGET_IEEEQUAD
8854    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8855   "
8856 {
8857   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8858   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8859   operands[3] = gen_reg_rtx (DFmode);
8860   operands[4] = gen_reg_rtx (CCFPmode);
8861   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
8862   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
8863 }")
8864 \f
8865 ;; Next come the multi-word integer load and store and the load and store
8866 ;; multiple insns.
8867
8868 ; List r->r after r->"o<>", otherwise reload will try to reload a
8869 ; non-offsettable address by using r->r which won't make progress.
8870 (define_insn "*movdi_internal32"
8871   [(set (match_operand:DI 0 "rs6000_nonimmediate_operand" "=o<>,r,r,*f,*f,m,r")
8872         (match_operand:DI 1 "input_operand" "r,r,m,f,m,f,IJKnGHF"))]
8873   "! TARGET_POWERPC64
8874    && (gpc_reg_operand (operands[0], DImode)
8875        || gpc_reg_operand (operands[1], DImode))"
8876   "@
8877    #
8878    #
8879    #
8880    fmr %0,%1
8881    lfd%U1%X1 %0,%1
8882    stfd%U0%X0 %1,%0
8883    #"
8884   [(set_attr "type" "load,*,store,fp,fpload,fpstore,*")])
8885
8886 (define_split
8887   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8888         (match_operand:DI 1 "const_int_operand" ""))]
8889   "! TARGET_POWERPC64 && reload_completed"
8890   [(set (match_dup 2) (match_dup 4))
8891    (set (match_dup 3) (match_dup 1))]
8892   "
8893 {
8894   HOST_WIDE_INT value = INTVAL (operands[1]);
8895   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8896                                        DImode);
8897   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8898                                        DImode);
8899 #if HOST_BITS_PER_WIDE_INT == 32
8900   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8901 #else
8902   operands[4] = GEN_INT (value >> 32);
8903   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8904 #endif
8905 }")
8906
8907 (define_split
8908   [(set (match_operand:DI 0 "rs6000_nonimmediate_operand" "")
8909         (match_operand:DI 1 "input_operand" ""))]
8910   "reload_completed && !TARGET_POWERPC64
8911    && gpr_or_gpr_p (operands[0], operands[1])"
8912   [(pc)]
8913 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8914
8915 (define_insn "*movdi_mfpgpr"
8916   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,*f,*f,m,r,*h,*h,r,*f")
8917         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,f,m,f,*h,r,0,*f,r"))]
8918   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS
8919    && (gpc_reg_operand (operands[0], DImode)
8920        || gpc_reg_operand (operands[1], DImode))"
8921   "@
8922    mr %0,%1
8923    ld%U1%X1 %0,%1
8924    std%U0%X0 %1,%0
8925    li %0,%1
8926    lis %0,%v1
8927    #
8928    {cal|la} %0,%a1
8929    fmr %0,%1
8930    lfd%U1%X1 %0,%1
8931    stfd%U0%X0 %1,%0
8932    mf%1 %0
8933    mt%0 %1
8934    {cror 0,0,0|nop}
8935    mftgpr %0,%1
8936    mffgpr %0,%1"
8937   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*,mftgpr,mffgpr")
8938    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4,4,4")])
8939
8940 (define_insn "*movdi_internal64"
8941   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,*f,*f,m,r,*h,*h")
8942         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,f,m,f,*h,r,0"))]
8943   "TARGET_POWERPC64 && (!TARGET_MFPGPR || !TARGET_HARD_FLOAT || !TARGET_FPRS)
8944    && (gpc_reg_operand (operands[0], DImode)
8945        || gpc_reg_operand (operands[1], DImode))"
8946   "@
8947    mr %0,%1
8948    ld%U1%X1 %0,%1
8949    std%U0%X0 %1,%0
8950    li %0,%1
8951    lis %0,%v1
8952    #
8953    {cal|la} %0,%a1
8954    fmr %0,%1
8955    lfd%U1%X1 %0,%1
8956    stfd%U0%X0 %1,%0
8957    mf%1 %0
8958    mt%0 %1
8959    {cror 0,0,0|nop}"
8960   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*")
8961    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4")])
8962
8963 ;; immediate value valid for a single instruction hiding in a const_double
8964 (define_insn ""
8965   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8966         (match_operand:DI 1 "const_double_operand" "F"))]
8967   "HOST_BITS_PER_WIDE_INT == 32 && TARGET_POWERPC64
8968    && GET_CODE (operands[1]) == CONST_DOUBLE
8969    && num_insns_constant (operands[1], DImode) == 1"
8970   "*
8971 {
8972   return ((unsigned HOST_WIDE_INT)
8973           (CONST_DOUBLE_LOW (operands[1]) + 0x8000) < 0x10000)
8974          ? \"li %0,%1\" : \"lis %0,%v1\";
8975 }")
8976
8977 ;; Generate all one-bits and clear left or right.
8978 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
8979 (define_split
8980   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8981         (match_operand:DI 1 "mask64_operand" ""))]
8982   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8983   [(set (match_dup 0) (const_int -1))
8984    (set (match_dup 0)
8985         (and:DI (rotate:DI (match_dup 0)
8986                            (const_int 0))
8987                 (match_dup 1)))]
8988   "")
8989
8990 ;; Split a load of a large constant into the appropriate five-instruction
8991 ;; sequence.  Handle anything in a constant number of insns.
8992 ;; When non-easy constants can go in the TOC, this should use
8993 ;; easy_fp_constant predicate.
8994 (define_split
8995   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8996         (match_operand:DI 1 "const_int_operand" ""))]
8997   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8998   [(set (match_dup 0) (match_dup 2))
8999    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
9000   "
9001 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
9002
9003   if (tem == operands[0])
9004     DONE;
9005   else
9006     FAIL;
9007 }")
9008
9009 (define_split
9010   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9011         (match_operand:DI 1 "const_double_operand" ""))]
9012   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
9013   [(set (match_dup 0) (match_dup 2))
9014    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
9015   "
9016 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
9017
9018   if (tem == operands[0])
9019     DONE;
9020   else
9021     FAIL;
9022 }")
9023 \f
9024 ;; TImode is similar, except that we usually want to compute the address into
9025 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
9026 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
9027
9028 ;; We say that MQ is clobbered in the last alternative because the first
9029 ;; alternative would never get used otherwise since it would need a reload
9030 ;; while the 2nd alternative would not.  We put memory cases first so they
9031 ;; are preferred.  Otherwise, we'd try to reload the output instead of
9032 ;; giving the SCRATCH mq.
9033
9034 (define_insn "*movti_power"
9035   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r,r")
9036         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))
9037    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X,X"))]
9038   "TARGET_POWER && ! TARGET_POWERPC64
9039    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
9040   "*
9041 {
9042   switch (which_alternative)
9043     {
9044     default:
9045       gcc_unreachable ();
9046
9047     case 0:
9048       if (TARGET_STRING)
9049         return \"{stsi|stswi} %1,%P0,16\";
9050     case 1:
9051     case 2:
9052       return \"#\";
9053     case 3:
9054       /* If the address is not used in the output, we can use lsi.  Otherwise,
9055          fall through to generating four loads.  */
9056       if (TARGET_STRING
9057           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
9058         return \"{lsi|lswi} %0,%P1,16\";
9059       /* ... fall through ...  */
9060     case 4:
9061     case 5:
9062       return \"#\";
9063     }
9064 }"
9065   [(set_attr "type" "store,store,*,load,load,*")])
9066
9067 (define_insn "*movti_string"
9068   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,o<>,????r,????r,????r,r")
9069         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))]
9070   "! TARGET_POWER && ! TARGET_POWERPC64
9071    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
9072   "*
9073 {
9074   switch (which_alternative)
9075     {
9076     default:
9077       gcc_unreachable ();
9078     case 0:
9079       if (TARGET_STRING)
9080         return \"{stsi|stswi} %1,%P0,16\";
9081     case 1:
9082     case 2:
9083       return \"#\";
9084     case 3:
9085       /* If the address is not used in the output, we can use lsi.  Otherwise,
9086          fall through to generating four loads.  */
9087       if (TARGET_STRING
9088           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
9089         return \"{lsi|lswi} %0,%P1,16\";
9090       /* ... fall through ...  */
9091     case 4:
9092     case 5:
9093       return \"#\";
9094     }
9095 }"
9096   [(set_attr "type" "store_ux,store_ux,*,load_ux,load_ux,*")])
9097
9098 (define_insn "*movti_ppc64"
9099   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,o<>,r")
9100         (match_operand:TI 1 "input_operand" "r,r,m"))]
9101   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
9102    || gpc_reg_operand (operands[1], TImode))"
9103   "#"
9104   [(set_attr "type" "*,load,store")])
9105
9106 (define_split
9107   [(set (match_operand:TI 0 "gpc_reg_operand" "")
9108         (match_operand:TI 1 "const_double_operand" ""))]
9109   "TARGET_POWERPC64"
9110   [(set (match_dup 2) (match_dup 4))
9111    (set (match_dup 3) (match_dup 5))]
9112   "
9113 {
9114   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
9115                                        TImode);
9116   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
9117                                        TImode);
9118   if (GET_CODE (operands[1]) == CONST_DOUBLE)
9119     {
9120       operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
9121       operands[5] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
9122     }
9123   else if (GET_CODE (operands[1]) == CONST_INT)
9124     {
9125       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
9126       operands[5] = operands[1];
9127     }
9128   else
9129     FAIL;
9130 }")
9131
9132 (define_split
9133   [(set (match_operand:TI 0 "nonimmediate_operand" "")
9134         (match_operand:TI 1 "input_operand" ""))]
9135   "reload_completed
9136    && gpr_or_gpr_p (operands[0], operands[1])"
9137   [(pc)]
9138 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
9139 \f
9140 (define_expand "load_multiple"
9141   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
9142                           (match_operand:SI 1 "" ""))
9143                      (use (match_operand:SI 2 "" ""))])]
9144   "TARGET_STRING && !TARGET_POWERPC64"
9145   "
9146 {
9147   int regno;
9148   int count;
9149   rtx op1;
9150   int i;
9151
9152   /* Support only loading a constant number of fixed-point registers from
9153      memory and only bother with this if more than two; the machine
9154      doesn't support more than eight.  */
9155   if (GET_CODE (operands[2]) != CONST_INT
9156       || INTVAL (operands[2]) <= 2
9157       || INTVAL (operands[2]) > 8
9158       || GET_CODE (operands[1]) != MEM
9159       || GET_CODE (operands[0]) != REG
9160       || REGNO (operands[0]) >= 32)
9161     FAIL;
9162
9163   count = INTVAL (operands[2]);
9164   regno = REGNO (operands[0]);
9165
9166   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
9167   op1 = replace_equiv_address (operands[1],
9168                                force_reg (SImode, XEXP (operands[1], 0)));
9169
9170   for (i = 0; i < count; i++)
9171     XVECEXP (operands[3], 0, i)
9172       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
9173                      adjust_address_nv (op1, SImode, i * 4));
9174 }")
9175
9176 (define_insn "*ldmsi8"
9177   [(match_parallel 0 "load_multiple_operation"
9178     [(set (match_operand:SI 2 "gpc_reg_operand" "")
9179           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
9180      (set (match_operand:SI 3 "gpc_reg_operand" "")
9181           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
9182      (set (match_operand:SI 4 "gpc_reg_operand" "")
9183           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
9184      (set (match_operand:SI 5 "gpc_reg_operand" "")
9185           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
9186      (set (match_operand:SI 6 "gpc_reg_operand" "")
9187           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
9188      (set (match_operand:SI 7 "gpc_reg_operand" "")
9189           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
9190      (set (match_operand:SI 8 "gpc_reg_operand" "")
9191           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
9192      (set (match_operand:SI 9 "gpc_reg_operand" "")
9193           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
9194   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
9195   "*
9196 { return rs6000_output_load_multiple (operands); }"
9197   [(set_attr "type" "load_ux")
9198    (set_attr "length" "32")])
9199
9200 (define_insn "*ldmsi7"
9201   [(match_parallel 0 "load_multiple_operation"
9202     [(set (match_operand:SI 2 "gpc_reg_operand" "")
9203           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
9204      (set (match_operand:SI 3 "gpc_reg_operand" "")
9205           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
9206      (set (match_operand:SI 4 "gpc_reg_operand" "")
9207           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
9208      (set (match_operand:SI 5 "gpc_reg_operand" "")
9209           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
9210      (set (match_operand:SI 6 "gpc_reg_operand" "")
9211           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
9212      (set (match_operand:SI 7 "gpc_reg_operand" "")
9213           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
9214      (set (match_operand:SI 8 "gpc_reg_operand" "")
9215           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
9216   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
9217   "*
9218 { return rs6000_output_load_multiple (operands); }"
9219   [(set_attr "type" "load_ux")
9220    (set_attr "length" "32")])
9221
9222 (define_insn "*ldmsi6"
9223   [(match_parallel 0 "load_multiple_operation"
9224     [(set (match_operand:SI 2 "gpc_reg_operand" "")
9225           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
9226      (set (match_operand:SI 3 "gpc_reg_operand" "")
9227           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
9228      (set (match_operand:SI 4 "gpc_reg_operand" "")
9229           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
9230      (set (match_operand:SI 5 "gpc_reg_operand" "")
9231           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
9232      (set (match_operand:SI 6 "gpc_reg_operand" "")
9233           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
9234      (set (match_operand:SI 7 "gpc_reg_operand" "")
9235           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
9236   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
9237   "*
9238 { return rs6000_output_load_multiple (operands); }"
9239   [(set_attr "type" "load_ux")
9240    (set_attr "length" "32")])
9241
9242 (define_insn "*ldmsi5"
9243   [(match_parallel 0 "load_multiple_operation"
9244     [(set (match_operand:SI 2 "gpc_reg_operand" "")
9245           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
9246      (set (match_operand:SI 3 "gpc_reg_operand" "")
9247           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
9248      (set (match_operand:SI 4 "gpc_reg_operand" "")
9249           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
9250      (set (match_operand:SI 5 "gpc_reg_operand" "")
9251           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
9252      (set (match_operand:SI 6 "gpc_reg_operand" "")
9253           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
9254   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
9255   "*
9256 { return rs6000_output_load_multiple (operands); }"
9257   [(set_attr "type" "load_ux")
9258    (set_attr "length" "32")])
9259
9260 (define_insn "*ldmsi4"
9261   [(match_parallel 0 "load_multiple_operation"
9262     [(set (match_operand:SI 2 "gpc_reg_operand" "")
9263           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
9264      (set (match_operand:SI 3 "gpc_reg_operand" "")
9265           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
9266      (set (match_operand:SI 4 "gpc_reg_operand" "")
9267           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
9268      (set (match_operand:SI 5 "gpc_reg_operand" "")
9269           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
9270   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
9271   "*
9272 { return rs6000_output_load_multiple (operands); }"
9273   [(set_attr "type" "load_ux")
9274    (set_attr "length" "32")])
9275
9276 (define_insn "*ldmsi3"
9277   [(match_parallel 0 "load_multiple_operation"
9278     [(set (match_operand:SI 2 "gpc_reg_operand" "")
9279           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
9280      (set (match_operand:SI 3 "gpc_reg_operand" "")
9281           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
9282      (set (match_operand:SI 4 "gpc_reg_operand" "")
9283           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
9284   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
9285   "*
9286 { return rs6000_output_load_multiple (operands); }"
9287   [(set_attr "type" "load_ux")
9288    (set_attr "length" "32")])
9289
9290 (define_expand "store_multiple"
9291   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
9292                           (match_operand:SI 1 "" ""))
9293                      (clobber (scratch:SI))
9294                      (use (match_operand:SI 2 "" ""))])]
9295   "TARGET_STRING && !TARGET_POWERPC64"
9296   "
9297 {
9298   int regno;
9299   int count;
9300   rtx to;
9301   rtx op0;
9302   int i;
9303
9304   /* Support only storing a constant number of fixed-point registers to
9305      memory and only bother with this if more than two; the machine
9306      doesn't support more than eight.  */
9307   if (GET_CODE (operands[2]) != CONST_INT
9308       || INTVAL (operands[2]) <= 2
9309       || INTVAL (operands[2]) > 8
9310       || GET_CODE (operands[0]) != MEM
9311       || GET_CODE (operands[1]) != REG
9312       || REGNO (operands[1]) >= 32)
9313     FAIL;
9314
9315   count = INTVAL (operands[2]);
9316   regno = REGNO (operands[1]);
9317
9318   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
9319   to = force_reg (SImode, XEXP (operands[0], 0));
9320   op0 = replace_equiv_address (operands[0], to);
9321
9322   XVECEXP (operands[3], 0, 0)
9323     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
9324   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
9325                                                  gen_rtx_SCRATCH (SImode));
9326
9327   for (i = 1; i < count; i++)
9328     XVECEXP (operands[3], 0, i + 1)
9329       = gen_rtx_SET (VOIDmode,
9330                      adjust_address_nv (op0, SImode, i * 4),
9331                      gen_rtx_REG (SImode, regno + i));
9332 }")
9333
9334 (define_insn "*stmsi8"
9335   [(match_parallel 0 "store_multiple_operation"
9336     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9337           (match_operand:SI 2 "gpc_reg_operand" "r"))
9338      (clobber (match_scratch:SI 3 "=X"))
9339      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9340           (match_operand:SI 4 "gpc_reg_operand" "r"))
9341      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9342           (match_operand:SI 5 "gpc_reg_operand" "r"))
9343      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9344           (match_operand:SI 6 "gpc_reg_operand" "r"))
9345      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9346           (match_operand:SI 7 "gpc_reg_operand" "r"))
9347      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9348           (match_operand:SI 8 "gpc_reg_operand" "r"))
9349      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9350           (match_operand:SI 9 "gpc_reg_operand" "r"))
9351      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
9352           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
9353   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 9"
9354   "{stsi|stswi} %2,%1,%O0"
9355   [(set_attr "type" "store_ux")])
9356
9357 (define_insn "*stmsi7"
9358   [(match_parallel 0 "store_multiple_operation"
9359     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9360           (match_operand:SI 2 "gpc_reg_operand" "r"))
9361      (clobber (match_scratch:SI 3 "=X"))
9362      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9363           (match_operand:SI 4 "gpc_reg_operand" "r"))
9364      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9365           (match_operand:SI 5 "gpc_reg_operand" "r"))
9366      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9367           (match_operand:SI 6 "gpc_reg_operand" "r"))
9368      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9369           (match_operand:SI 7 "gpc_reg_operand" "r"))
9370      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9371           (match_operand:SI 8 "gpc_reg_operand" "r"))
9372      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9373           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
9374   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 8"
9375   "{stsi|stswi} %2,%1,%O0"
9376   [(set_attr "type" "store_ux")])
9377
9378 (define_insn "*stmsi6"
9379   [(match_parallel 0 "store_multiple_operation"
9380     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9381           (match_operand:SI 2 "gpc_reg_operand" "r"))
9382      (clobber (match_scratch:SI 3 "=X"))
9383      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9384           (match_operand:SI 4 "gpc_reg_operand" "r"))
9385      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9386           (match_operand:SI 5 "gpc_reg_operand" "r"))
9387      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9388           (match_operand:SI 6 "gpc_reg_operand" "r"))
9389      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9390           (match_operand:SI 7 "gpc_reg_operand" "r"))
9391      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9392           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
9393   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 7"
9394   "{stsi|stswi} %2,%1,%O0"
9395   [(set_attr "type" "store_ux")])
9396
9397 (define_insn "*stmsi5"
9398   [(match_parallel 0 "store_multiple_operation"
9399     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9400           (match_operand:SI 2 "gpc_reg_operand" "r"))
9401      (clobber (match_scratch:SI 3 "=X"))
9402      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9403           (match_operand:SI 4 "gpc_reg_operand" "r"))
9404      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9405           (match_operand:SI 5 "gpc_reg_operand" "r"))
9406      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9407           (match_operand:SI 6 "gpc_reg_operand" "r"))
9408      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9409           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
9410   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 6"
9411   "{stsi|stswi} %2,%1,%O0"
9412   [(set_attr "type" "store_ux")])
9413
9414 (define_insn "*stmsi4"
9415   [(match_parallel 0 "store_multiple_operation"
9416     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9417           (match_operand:SI 2 "gpc_reg_operand" "r"))
9418      (clobber (match_scratch:SI 3 "=X"))
9419      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9420           (match_operand:SI 4 "gpc_reg_operand" "r"))
9421      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9422           (match_operand:SI 5 "gpc_reg_operand" "r"))
9423      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9424           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
9425   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 5"
9426   "{stsi|stswi} %2,%1,%O0"
9427   [(set_attr "type" "store_ux")])
9428
9429 (define_insn "*stmsi3"
9430   [(match_parallel 0 "store_multiple_operation"
9431     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9432           (match_operand:SI 2 "gpc_reg_operand" "r"))
9433      (clobber (match_scratch:SI 3 "=X"))
9434      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9435           (match_operand:SI 4 "gpc_reg_operand" "r"))
9436      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9437           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
9438   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 4"
9439   "{stsi|stswi} %2,%1,%O0"
9440   [(set_attr "type" "store_ux")])
9441
9442 (define_insn "*stmsi8_power"
9443   [(match_parallel 0 "store_multiple_operation"
9444     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9445           (match_operand:SI 2 "gpc_reg_operand" "r"))
9446      (clobber (match_scratch:SI 3 "=q"))
9447      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9448           (match_operand:SI 4 "gpc_reg_operand" "r"))
9449      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9450           (match_operand:SI 5 "gpc_reg_operand" "r"))
9451      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9452           (match_operand:SI 6 "gpc_reg_operand" "r"))
9453      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9454           (match_operand:SI 7 "gpc_reg_operand" "r"))
9455      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9456           (match_operand:SI 8 "gpc_reg_operand" "r"))
9457      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9458           (match_operand:SI 9 "gpc_reg_operand" "r"))
9459      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
9460           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
9461   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 9"
9462   "{stsi|stswi} %2,%1,%O0"
9463   [(set_attr "type" "store_ux")])
9464
9465 (define_insn "*stmsi7_power"
9466   [(match_parallel 0 "store_multiple_operation"
9467     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9468           (match_operand:SI 2 "gpc_reg_operand" "r"))
9469      (clobber (match_scratch:SI 3 "=q"))
9470      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9471           (match_operand:SI 4 "gpc_reg_operand" "r"))
9472      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9473           (match_operand:SI 5 "gpc_reg_operand" "r"))
9474      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9475           (match_operand:SI 6 "gpc_reg_operand" "r"))
9476      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9477           (match_operand:SI 7 "gpc_reg_operand" "r"))
9478      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9479           (match_operand:SI 8 "gpc_reg_operand" "r"))
9480      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9481           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
9482   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 8"
9483   "{stsi|stswi} %2,%1,%O0"
9484   [(set_attr "type" "store_ux")])
9485
9486 (define_insn "*stmsi6_power"
9487   [(match_parallel 0 "store_multiple_operation"
9488     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9489           (match_operand:SI 2 "gpc_reg_operand" "r"))
9490      (clobber (match_scratch:SI 3 "=q"))
9491      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9492           (match_operand:SI 4 "gpc_reg_operand" "r"))
9493      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9494           (match_operand:SI 5 "gpc_reg_operand" "r"))
9495      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9496           (match_operand:SI 6 "gpc_reg_operand" "r"))
9497      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9498           (match_operand:SI 7 "gpc_reg_operand" "r"))
9499      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9500           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
9501   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 7"
9502   "{stsi|stswi} %2,%1,%O0"
9503   [(set_attr "type" "store_ux")])
9504
9505 (define_insn "*stmsi5_power"
9506   [(match_parallel 0 "store_multiple_operation"
9507     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9508           (match_operand:SI 2 "gpc_reg_operand" "r"))
9509      (clobber (match_scratch:SI 3 "=q"))
9510      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9511           (match_operand:SI 4 "gpc_reg_operand" "r"))
9512      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9513           (match_operand:SI 5 "gpc_reg_operand" "r"))
9514      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9515           (match_operand:SI 6 "gpc_reg_operand" "r"))
9516      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9517           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
9518   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 6"
9519   "{stsi|stswi} %2,%1,%O0"
9520   [(set_attr "type" "store_ux")])
9521
9522 (define_insn "*stmsi4_power"
9523   [(match_parallel 0 "store_multiple_operation"
9524     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9525           (match_operand:SI 2 "gpc_reg_operand" "r"))
9526      (clobber (match_scratch:SI 3 "=q"))
9527      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9528           (match_operand:SI 4 "gpc_reg_operand" "r"))
9529      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9530           (match_operand:SI 5 "gpc_reg_operand" "r"))
9531      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9532           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
9533   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 5"
9534   "{stsi|stswi} %2,%1,%O0"
9535   [(set_attr "type" "store_ux")])
9536
9537 (define_insn "*stmsi3_power"
9538   [(match_parallel 0 "store_multiple_operation"
9539     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9540           (match_operand:SI 2 "gpc_reg_operand" "r"))
9541      (clobber (match_scratch:SI 3 "=q"))
9542      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9543           (match_operand:SI 4 "gpc_reg_operand" "r"))
9544      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9545           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
9546   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 4"
9547   "{stsi|stswi} %2,%1,%O0"
9548   [(set_attr "type" "store_ux")])
9549 \f
9550 (define_expand "setmemsi"
9551   [(parallel [(set (match_operand:BLK 0 "" "")
9552                    (match_operand 2 "const_int_operand" ""))
9553               (use (match_operand:SI 1 "" ""))
9554               (use (match_operand:SI 3 "" ""))])]
9555   ""
9556   "
9557 {
9558   /* If value to set is not zero, use the library routine.  */
9559   if (operands[2] != const0_rtx)
9560     FAIL;
9561
9562   if (expand_block_clear (operands))
9563     DONE;
9564   else
9565     FAIL;
9566 }")
9567
9568 ;; String/block move insn.
9569 ;; Argument 0 is the destination
9570 ;; Argument 1 is the source
9571 ;; Argument 2 is the length
9572 ;; Argument 3 is the alignment
9573
9574 (define_expand "movmemsi"
9575   [(parallel [(set (match_operand:BLK 0 "" "")
9576                    (match_operand:BLK 1 "" ""))
9577               (use (match_operand:SI 2 "" ""))
9578               (use (match_operand:SI 3 "" ""))])]
9579   ""
9580   "
9581 {
9582   if (expand_block_move (operands))
9583     DONE;
9584   else
9585     FAIL;
9586 }")
9587
9588 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
9589 ;; register allocator doesn't have a clue about allocating 8 word registers.
9590 ;; rD/rS = r5 is preferred, efficient form.
9591 (define_expand "movmemsi_8reg"
9592   [(parallel [(set (match_operand 0 "" "")
9593                    (match_operand 1 "" ""))
9594               (use (match_operand 2 "" ""))
9595               (use (match_operand 3 "" ""))
9596               (clobber (reg:SI  5))
9597               (clobber (reg:SI  6))
9598               (clobber (reg:SI  7))
9599               (clobber (reg:SI  8))
9600               (clobber (reg:SI  9))
9601               (clobber (reg:SI 10))
9602               (clobber (reg:SI 11))
9603               (clobber (reg:SI 12))
9604               (clobber (match_scratch:SI 4 ""))])]
9605   "TARGET_STRING"
9606   "")
9607
9608 (define_insn ""
9609   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9610         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9611    (use (match_operand:SI 2 "immediate_operand" "i"))
9612    (use (match_operand:SI 3 "immediate_operand" "i"))
9613    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9614    (clobber (reg:SI  6))
9615    (clobber (reg:SI  7))
9616    (clobber (reg:SI  8))
9617    (clobber (reg:SI  9))
9618    (clobber (reg:SI 10))
9619    (clobber (reg:SI 11))
9620    (clobber (reg:SI 12))
9621    (clobber (match_scratch:SI 5 "=q"))]
9622   "TARGET_STRING && TARGET_POWER
9623    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9624        || INTVAL (operands[2]) == 0)
9625    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9626    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9627    && REGNO (operands[4]) == 5"
9628   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9629   [(set_attr "type" "store_ux")
9630    (set_attr "length" "8")])
9631
9632 (define_insn ""
9633   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9634         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9635    (use (match_operand:SI 2 "immediate_operand" "i"))
9636    (use (match_operand:SI 3 "immediate_operand" "i"))
9637    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9638    (clobber (reg:SI  6))
9639    (clobber (reg:SI  7))
9640    (clobber (reg:SI  8))
9641    (clobber (reg:SI  9))
9642    (clobber (reg:SI 10))
9643    (clobber (reg:SI 11))
9644    (clobber (reg:SI 12))
9645    (clobber (match_scratch:SI 5 "=X"))]
9646   "TARGET_STRING && ! TARGET_POWER
9647    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9648        || INTVAL (operands[2]) == 0)
9649    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9650    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9651    && REGNO (operands[4]) == 5"
9652   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9653   [(set_attr "type" "store_ux")
9654    (set_attr "length" "8")])
9655
9656 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
9657 ;; register allocator doesn't have a clue about allocating 6 word registers.
9658 ;; rD/rS = r5 is preferred, efficient form.
9659 (define_expand "movmemsi_6reg"
9660   [(parallel [(set (match_operand 0 "" "")
9661                    (match_operand 1 "" ""))
9662               (use (match_operand 2 "" ""))
9663               (use (match_operand 3 "" ""))
9664               (clobber (reg:SI  5))
9665               (clobber (reg:SI  6))
9666               (clobber (reg:SI  7))
9667               (clobber (reg:SI  8))
9668               (clobber (reg:SI  9))
9669               (clobber (reg:SI 10))
9670               (clobber (match_scratch:SI 4 ""))])]
9671   "TARGET_STRING"
9672   "")
9673
9674 (define_insn ""
9675   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9676         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9677    (use (match_operand:SI 2 "immediate_operand" "i"))
9678    (use (match_operand:SI 3 "immediate_operand" "i"))
9679    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9680    (clobber (reg:SI  6))
9681    (clobber (reg:SI  7))
9682    (clobber (reg:SI  8))
9683    (clobber (reg:SI  9))
9684    (clobber (reg:SI 10))
9685    (clobber (match_scratch:SI 5 "=q"))]
9686   "TARGET_STRING && TARGET_POWER
9687    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
9688    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9689    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9690    && REGNO (operands[4]) == 5"
9691   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9692   [(set_attr "type" "store_ux")
9693    (set_attr "length" "8")])
9694
9695 (define_insn ""
9696   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9697         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9698    (use (match_operand:SI 2 "immediate_operand" "i"))
9699    (use (match_operand:SI 3 "immediate_operand" "i"))
9700    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9701    (clobber (reg:SI  6))
9702    (clobber (reg:SI  7))
9703    (clobber (reg:SI  8))
9704    (clobber (reg:SI  9))
9705    (clobber (reg:SI 10))
9706    (clobber (match_scratch:SI 5 "=X"))]
9707   "TARGET_STRING && ! TARGET_POWER
9708    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9709    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9710    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9711    && REGNO (operands[4]) == 5"
9712   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9713   [(set_attr "type" "store_ux")
9714    (set_attr "length" "8")])
9715
9716 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
9717 ;; problems with TImode.
9718 ;; rD/rS = r5 is preferred, efficient form.
9719 (define_expand "movmemsi_4reg"
9720   [(parallel [(set (match_operand 0 "" "")
9721                    (match_operand 1 "" ""))
9722               (use (match_operand 2 "" ""))
9723               (use (match_operand 3 "" ""))
9724               (clobber (reg:SI 5))
9725               (clobber (reg:SI 6))
9726               (clobber (reg:SI 7))
9727               (clobber (reg:SI 8))
9728               (clobber (match_scratch:SI 4 ""))])]
9729   "TARGET_STRING"
9730   "")
9731
9732 (define_insn ""
9733   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9734         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9735    (use (match_operand:SI 2 "immediate_operand" "i"))
9736    (use (match_operand:SI 3 "immediate_operand" "i"))
9737    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9738    (clobber (reg:SI 6))
9739    (clobber (reg:SI 7))
9740    (clobber (reg:SI 8))
9741    (clobber (match_scratch:SI 5 "=q"))]
9742   "TARGET_STRING && TARGET_POWER
9743    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9744    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9745    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9746    && REGNO (operands[4]) == 5"
9747   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9748   [(set_attr "type" "store_ux")
9749    (set_attr "length" "8")])
9750
9751 (define_insn ""
9752   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9753         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9754    (use (match_operand:SI 2 "immediate_operand" "i"))
9755    (use (match_operand:SI 3 "immediate_operand" "i"))
9756    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9757    (clobber (reg:SI 6))
9758    (clobber (reg:SI 7))
9759    (clobber (reg:SI 8))
9760    (clobber (match_scratch:SI 5 "=X"))]
9761   "TARGET_STRING && ! TARGET_POWER
9762    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9763    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9764    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9765    && REGNO (operands[4]) == 5"
9766   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9767   [(set_attr "type" "store_ux")
9768    (set_attr "length" "8")])
9769
9770 ;; Move up to 8 bytes at a time.
9771 (define_expand "movmemsi_2reg"
9772   [(parallel [(set (match_operand 0 "" "")
9773                    (match_operand 1 "" ""))
9774               (use (match_operand 2 "" ""))
9775               (use (match_operand 3 "" ""))
9776               (clobber (match_scratch:DI 4 ""))
9777               (clobber (match_scratch:SI 5 ""))])]
9778   "TARGET_STRING && ! TARGET_POWERPC64"
9779   "")
9780
9781 (define_insn ""
9782   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9783         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9784    (use (match_operand:SI 2 "immediate_operand" "i"))
9785    (use (match_operand:SI 3 "immediate_operand" "i"))
9786    (clobber (match_scratch:DI 4 "=&r"))
9787    (clobber (match_scratch:SI 5 "=q"))]
9788   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
9789    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9790   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9791   [(set_attr "type" "store_ux")
9792    (set_attr "length" "8")])
9793
9794 (define_insn ""
9795   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9796         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9797    (use (match_operand:SI 2 "immediate_operand" "i"))
9798    (use (match_operand:SI 3 "immediate_operand" "i"))
9799    (clobber (match_scratch:DI 4 "=&r"))
9800    (clobber (match_scratch:SI 5 "=X"))]
9801   "TARGET_STRING && ! TARGET_POWER && ! TARGET_POWERPC64
9802    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9803   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9804   [(set_attr "type" "store_ux")
9805    (set_attr "length" "8")])
9806
9807 ;; Move up to 4 bytes at a time.
9808 (define_expand "movmemsi_1reg"
9809   [(parallel [(set (match_operand 0 "" "")
9810                    (match_operand 1 "" ""))
9811               (use (match_operand 2 "" ""))
9812               (use (match_operand 3 "" ""))
9813               (clobber (match_scratch:SI 4 ""))
9814               (clobber (match_scratch:SI 5 ""))])]
9815   "TARGET_STRING"
9816   "")
9817
9818 (define_insn ""
9819   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9820         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9821    (use (match_operand:SI 2 "immediate_operand" "i"))
9822    (use (match_operand:SI 3 "immediate_operand" "i"))
9823    (clobber (match_scratch:SI 4 "=&r"))
9824    (clobber (match_scratch:SI 5 "=q"))]
9825   "TARGET_STRING && TARGET_POWER
9826    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9827   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9828   [(set_attr "type" "store_ux")
9829    (set_attr "length" "8")])
9830
9831 (define_insn ""
9832   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9833         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9834    (use (match_operand:SI 2 "immediate_operand" "i"))
9835    (use (match_operand:SI 3 "immediate_operand" "i"))
9836    (clobber (match_scratch:SI 4 "=&r"))
9837    (clobber (match_scratch:SI 5 "=X"))]
9838   "TARGET_STRING && ! TARGET_POWER
9839    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9840   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9841   [(set_attr "type" "store_ux")
9842    (set_attr "length" "8")])
9843 \f
9844 ;; Define insns that do load or store with update.  Some of these we can
9845 ;; get by using pre-decrement or pre-increment, but the hardware can also
9846 ;; do cases where the increment is not the size of the object.
9847 ;;
9848 ;; In all these cases, we use operands 0 and 1 for the register being
9849 ;; incremented because those are the operands that local-alloc will
9850 ;; tie and these are the pair most likely to be tieable (and the ones
9851 ;; that will benefit the most).
9852
9853 (define_insn "*movdi_update1"
9854   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
9855         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9856                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
9857    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9858         (plus:DI (match_dup 1) (match_dup 2)))]
9859   "TARGET_POWERPC64 && TARGET_UPDATE"
9860   "@
9861    ldux %3,%0,%2
9862    ldu %3,%2(%0)"
9863   [(set_attr "type" "load_ux,load_u")])
9864
9865 (define_insn "movdi_<mode>_update"
9866   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
9867                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
9868         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
9869    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
9870         (plus:P (match_dup 1) (match_dup 2)))]
9871   "TARGET_POWERPC64 && TARGET_UPDATE"
9872   "@
9873    stdux %3,%0,%2
9874    stdu %3,%2(%0)"
9875   [(set_attr "type" "store_ux,store_u")])
9876
9877 (define_insn "*movsi_update1"
9878   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9879         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9880                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9881    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9882         (plus:SI (match_dup 1) (match_dup 2)))]
9883   "TARGET_UPDATE"
9884   "@
9885    {lux|lwzux} %3,%0,%2
9886    {lu|lwzu} %3,%2(%0)"
9887   [(set_attr "type" "load_ux,load_u")])
9888
9889 (define_insn "*movsi_update2"
9890   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
9891         (sign_extend:DI
9892          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
9893                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
9894    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
9895         (plus:DI (match_dup 1) (match_dup 2)))]
9896   "TARGET_POWERPC64"
9897   "lwaux %3,%0,%2"
9898   [(set_attr "type" "load_ext_ux")])
9899
9900 (define_insn "movsi_update"
9901   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9902                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9903         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
9904    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9905         (plus:SI (match_dup 1) (match_dup 2)))]
9906   "TARGET_UPDATE"
9907   "@
9908    {stux|stwux} %3,%0,%2
9909    {stu|stwu} %3,%2(%0)"
9910   [(set_attr "type" "store_ux,store_u")])
9911
9912 (define_insn "*movhi_update1"
9913   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
9914         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9915                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9916    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9917         (plus:SI (match_dup 1) (match_dup 2)))]
9918   "TARGET_UPDATE"
9919   "@
9920    lhzux %3,%0,%2
9921    lhzu %3,%2(%0)"
9922   [(set_attr "type" "load_ux,load_u")])
9923
9924 (define_insn "*movhi_update2"
9925   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9926         (zero_extend:SI
9927          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9928                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9929    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9930         (plus:SI (match_dup 1) (match_dup 2)))]
9931   "TARGET_UPDATE"
9932   "@
9933    lhzux %3,%0,%2
9934    lhzu %3,%2(%0)"
9935   [(set_attr "type" "load_ux,load_u")])
9936
9937 (define_insn "*movhi_update3"
9938   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9939         (sign_extend:SI
9940          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9941                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9942    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9943         (plus:SI (match_dup 1) (match_dup 2)))]
9944   "TARGET_UPDATE"
9945   "@
9946    lhaux %3,%0,%2
9947    lhau %3,%2(%0)"
9948   [(set_attr "type" "load_ext_ux,load_ext_u")])
9949
9950 (define_insn "*movhi_update4"
9951   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9952                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9953         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
9954    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9955         (plus:SI (match_dup 1) (match_dup 2)))]
9956   "TARGET_UPDATE"
9957   "@
9958    sthux %3,%0,%2
9959    sthu %3,%2(%0)"
9960   [(set_attr "type" "store_ux,store_u")])
9961
9962 (define_insn "*movqi_update1"
9963   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
9964         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9965                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9966    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9967         (plus:SI (match_dup 1) (match_dup 2)))]
9968   "TARGET_UPDATE"
9969   "@
9970    lbzux %3,%0,%2
9971    lbzu %3,%2(%0)"
9972   [(set_attr "type" "load_ux,load_u")])
9973
9974 (define_insn "*movqi_update2"
9975   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9976         (zero_extend:SI
9977          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9978                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9979    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9980         (plus:SI (match_dup 1) (match_dup 2)))]
9981   "TARGET_UPDATE"
9982   "@
9983    lbzux %3,%0,%2
9984    lbzu %3,%2(%0)"
9985   [(set_attr "type" "load_ux,load_u")])
9986
9987 (define_insn "*movqi_update3"
9988   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9989                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9990         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
9991    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9992         (plus:SI (match_dup 1) (match_dup 2)))]
9993   "TARGET_UPDATE"
9994   "@
9995    stbux %3,%0,%2
9996    stbu %3,%2(%0)"
9997   [(set_attr "type" "store_ux,store_u")])
9998
9999 (define_insn "*movsf_update1"
10000   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
10001         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10002                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10003    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10004         (plus:SI (match_dup 1) (match_dup 2)))]
10005   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
10006   "@
10007    lfsux %3,%0,%2
10008    lfsu %3,%2(%0)"
10009   [(set_attr "type" "fpload_ux,fpload_u")])
10010
10011 (define_insn "*movsf_update2"
10012   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10013                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10014         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
10015    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10016         (plus:SI (match_dup 1) (match_dup 2)))]
10017   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
10018   "@
10019    stfsux %3,%0,%2
10020    stfsu %3,%2(%0)"
10021   [(set_attr "type" "fpstore_ux,fpstore_u")])
10022
10023 (define_insn "*movsf_update3"
10024   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
10025         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10026                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10027    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10028         (plus:SI (match_dup 1) (match_dup 2)))]
10029   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
10030   "@
10031    {lux|lwzux} %3,%0,%2
10032    {lu|lwzu} %3,%2(%0)"
10033   [(set_attr "type" "load_ux,load_u")])
10034
10035 (define_insn "*movsf_update4"
10036   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10037                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10038         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
10039    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10040         (plus:SI (match_dup 1) (match_dup 2)))]
10041   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
10042   "@
10043    {stux|stwux} %3,%0,%2
10044    {stu|stwu} %3,%2(%0)"
10045   [(set_attr "type" "store_ux,store_u")])
10046
10047 (define_insn "*movdf_update1"
10048   [(set (match_operand:DF 3 "gpc_reg_operand" "=f,f")
10049         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10050                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10051    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10052         (plus:SI (match_dup 1) (match_dup 2)))]
10053   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
10054   "@
10055    lfdux %3,%0,%2
10056    lfdu %3,%2(%0)"
10057   [(set_attr "type" "fpload_ux,fpload_u")])
10058
10059 (define_insn "*movdf_update2"
10060   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10061                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10062         (match_operand:DF 3 "gpc_reg_operand" "f,f"))
10063    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10064         (plus:SI (match_dup 1) (match_dup 2)))]
10065   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
10066   "@
10067    stfdux %3,%0,%2
10068    stfdu %3,%2(%0)"
10069   [(set_attr "type" "fpstore_ux,fpstore_u")])
10070
10071 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
10072
10073 (define_insn "*lfq_power2"
10074   [(set (match_operand:V2DF 0 "gpc_reg_operand" "=f")
10075         (match_operand:V2DF 1 "memory_operand" ""))]
10076   "TARGET_POWER2
10077    && TARGET_HARD_FLOAT && TARGET_FPRS"
10078   "lfq%U1%X1 %0,%1")
10079
10080 (define_peephole2
10081   [(set (match_operand:DF 0 "gpc_reg_operand" "")
10082         (match_operand:DF 1 "memory_operand" ""))
10083    (set (match_operand:DF 2 "gpc_reg_operand" "")
10084         (match_operand:DF 3 "memory_operand" ""))]
10085   "TARGET_POWER2
10086    && TARGET_HARD_FLOAT && TARGET_FPRS
10087    && registers_ok_for_quad_peep (operands[0], operands[2])
10088    && mems_ok_for_quad_peep (operands[1], operands[3])"
10089   [(set (match_dup 0)
10090         (match_dup 1))]
10091   "operands[1] = widen_memory_access (operands[1], V2DFmode, 0);
10092    operands[0] = gen_rtx_REG (V2DFmode, REGNO (operands[0]));")
10093
10094 (define_insn "*stfq_power2"
10095   [(set (match_operand:V2DF 0 "memory_operand" "")
10096         (match_operand:V2DF 1 "gpc_reg_operand" "f"))]
10097   "TARGET_POWER2
10098    && TARGET_HARD_FLOAT && TARGET_FPRS"
10099   "stfq%U0%X0 %1,%0")
10100
10101
10102 (define_peephole2
10103   [(set (match_operand:DF 0 "memory_operand" "")
10104         (match_operand:DF 1 "gpc_reg_operand" ""))
10105    (set (match_operand:DF 2 "memory_operand" "")
10106         (match_operand:DF 3 "gpc_reg_operand" ""))]
10107   "TARGET_POWER2
10108    && TARGET_HARD_FLOAT && TARGET_FPRS
10109    && registers_ok_for_quad_peep (operands[1], operands[3])
10110    && mems_ok_for_quad_peep (operands[0], operands[2])"
10111   [(set (match_dup 0)
10112         (match_dup 1))]
10113   "operands[0] = widen_memory_access (operands[0], V2DFmode, 0);
10114    operands[1] = gen_rtx_REG (V2DFmode, REGNO (operands[1]));")
10115
10116 ;; After inserting conditional returns we can sometimes have
10117 ;; unnecessary register moves.  Unfortunately we cannot have a
10118 ;; modeless peephole here, because some single SImode sets have early
10119 ;; clobber outputs.  Although those sets expand to multi-ppc-insn
10120 ;; sequences, using get_attr_length here will smash the operands
10121 ;; array.  Neither is there an early_cobbler_p predicate.
10122 ;; Disallow subregs for E500 so we don't munge frob_di_df_2.
10123 (define_peephole2
10124   [(set (match_operand:DF 0 "gpc_reg_operand" "")
10125         (match_operand:DF 1 "any_operand" ""))
10126    (set (match_operand:DF 2 "gpc_reg_operand" "")
10127         (match_dup 0))]
10128   "!(TARGET_E500_DOUBLE && GET_CODE (operands[2]) == SUBREG)
10129    && peep2_reg_dead_p (2, operands[0])"
10130   [(set (match_dup 2) (match_dup 1))])
10131
10132 (define_peephole2
10133   [(set (match_operand:SF 0 "gpc_reg_operand" "")
10134         (match_operand:SF 1 "any_operand" ""))
10135    (set (match_operand:SF 2 "gpc_reg_operand" "")
10136         (match_dup 0))]
10137   "peep2_reg_dead_p (2, operands[0])"
10138   [(set (match_dup 2) (match_dup 1))])
10139
10140 \f
10141 ;; TLS support.
10142
10143 ;; "b" output constraint here and on tls_ld to support tls linker optimization.
10144 (define_insn "tls_gd_32"
10145   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
10146         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
10147                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
10148                    UNSPEC_TLSGD))]
10149   "HAVE_AS_TLS && !TARGET_64BIT"
10150   "addi %0,%1,%2@got@tlsgd")
10151
10152 (define_insn "tls_gd_64"
10153   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
10154         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
10155                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
10156                    UNSPEC_TLSGD))]
10157   "HAVE_AS_TLS && TARGET_64BIT"
10158   "addi %0,%1,%2@got@tlsgd")
10159
10160 (define_insn "tls_ld_32"
10161   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
10162         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")]
10163                    UNSPEC_TLSLD))]
10164   "HAVE_AS_TLS && !TARGET_64BIT"
10165   "addi %0,%1,%&@got@tlsld")
10166
10167 (define_insn "tls_ld_64"
10168   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
10169         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")]
10170                    UNSPEC_TLSLD))]
10171   "HAVE_AS_TLS && TARGET_64BIT"
10172   "addi %0,%1,%&@got@tlsld")
10173
10174 (define_insn "tls_dtprel_32"
10175   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10176         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
10177                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
10178                    UNSPEC_TLSDTPREL))]
10179   "HAVE_AS_TLS && !TARGET_64BIT"
10180   "addi %0,%1,%2@dtprel")
10181
10182 (define_insn "tls_dtprel_64"
10183   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10184         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
10185                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
10186                    UNSPEC_TLSDTPREL))]
10187   "HAVE_AS_TLS && TARGET_64BIT"
10188   "addi %0,%1,%2@dtprel")
10189
10190 (define_insn "tls_dtprel_ha_32"
10191   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10192         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
10193                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
10194                    UNSPEC_TLSDTPRELHA))]
10195   "HAVE_AS_TLS && !TARGET_64BIT"
10196   "addis %0,%1,%2@dtprel@ha")
10197
10198 (define_insn "tls_dtprel_ha_64"
10199   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10200         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
10201                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
10202                    UNSPEC_TLSDTPRELHA))]
10203   "HAVE_AS_TLS && TARGET_64BIT"
10204   "addis %0,%1,%2@dtprel@ha")
10205
10206 (define_insn "tls_dtprel_lo_32"
10207   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10208         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
10209                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
10210                    UNSPEC_TLSDTPRELLO))]
10211   "HAVE_AS_TLS && !TARGET_64BIT"
10212   "addi %0,%1,%2@dtprel@l")
10213
10214 (define_insn "tls_dtprel_lo_64"
10215   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10216         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
10217                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
10218                    UNSPEC_TLSDTPRELLO))]
10219   "HAVE_AS_TLS && TARGET_64BIT"
10220   "addi %0,%1,%2@dtprel@l")
10221
10222 (define_insn "tls_got_dtprel_32"
10223   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10224         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
10225                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
10226                    UNSPEC_TLSGOTDTPREL))]
10227   "HAVE_AS_TLS && !TARGET_64BIT"
10228   "lwz %0,%2@got@dtprel(%1)")
10229
10230 (define_insn "tls_got_dtprel_64"
10231   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10232         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
10233                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
10234                    UNSPEC_TLSGOTDTPREL))]
10235   "HAVE_AS_TLS && TARGET_64BIT"
10236   "ld %0,%2@got@dtprel(%1)")
10237
10238 (define_insn "tls_tprel_32"
10239   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10240         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
10241                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
10242                    UNSPEC_TLSTPREL))]
10243   "HAVE_AS_TLS && !TARGET_64BIT"
10244   "addi %0,%1,%2@tprel")
10245
10246 (define_insn "tls_tprel_64"
10247   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10248         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
10249                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
10250                    UNSPEC_TLSTPREL))]
10251   "HAVE_AS_TLS && TARGET_64BIT"
10252   "addi %0,%1,%2@tprel")
10253
10254 (define_insn "tls_tprel_ha_32"
10255   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10256         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
10257                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
10258                    UNSPEC_TLSTPRELHA))]
10259   "HAVE_AS_TLS && !TARGET_64BIT"
10260   "addis %0,%1,%2@tprel@ha")
10261
10262 (define_insn "tls_tprel_ha_64"
10263   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10264         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
10265                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
10266                    UNSPEC_TLSTPRELHA))]
10267   "HAVE_AS_TLS && TARGET_64BIT"
10268   "addis %0,%1,%2@tprel@ha")
10269
10270 (define_insn "tls_tprel_lo_32"
10271   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10272         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
10273                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
10274                    UNSPEC_TLSTPRELLO))]
10275   "HAVE_AS_TLS && !TARGET_64BIT"
10276   "addi %0,%1,%2@tprel@l")
10277
10278 (define_insn "tls_tprel_lo_64"
10279   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10280         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
10281                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
10282                    UNSPEC_TLSTPRELLO))]
10283   "HAVE_AS_TLS && TARGET_64BIT"
10284   "addi %0,%1,%2@tprel@l")
10285
10286 ;; "b" output constraint here and on tls_tls input to support linker tls
10287 ;; optimization.  The linker may edit the instructions emitted by a
10288 ;; tls_got_tprel/tls_tls pair to addis,addi.
10289 (define_insn "tls_got_tprel_32"
10290   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
10291         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
10292                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
10293                    UNSPEC_TLSGOTTPREL))]
10294   "HAVE_AS_TLS && !TARGET_64BIT"
10295   "lwz %0,%2@got@tprel(%1)")
10296
10297 (define_insn "tls_got_tprel_64"
10298   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
10299         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
10300                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
10301                    UNSPEC_TLSGOTTPREL))]
10302   "HAVE_AS_TLS && TARGET_64BIT"
10303   "ld %0,%2@got@tprel(%1)")
10304
10305 (define_insn "tls_tls_32"
10306   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10307         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
10308                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
10309                    UNSPEC_TLSTLS))]
10310   "HAVE_AS_TLS && !TARGET_64BIT"
10311   "add %0,%1,%2@tls")
10312
10313 (define_insn "tls_tls_64"
10314   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10315         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
10316                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
10317                    UNSPEC_TLSTLS))]
10318   "HAVE_AS_TLS && TARGET_64BIT"
10319   "add %0,%1,%2@tls")
10320 \f
10321 ;; Next come insns related to the calling sequence.
10322 ;;
10323 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
10324 ;; We move the back-chain and decrement the stack pointer.
10325
10326 (define_expand "allocate_stack"
10327   [(set (match_operand 0 "gpc_reg_operand" "")
10328         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
10329    (set (reg 1)
10330         (minus (reg 1) (match_dup 1)))]
10331   ""
10332   "
10333 { rtx chain = gen_reg_rtx (Pmode);
10334   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
10335   rtx neg_op0;
10336
10337   emit_move_insn (chain, stack_bot);
10338
10339   /* Check stack bounds if necessary.  */
10340   if (current_function_limit_stack)
10341     {
10342       rtx available;
10343       available = expand_binop (Pmode, sub_optab,
10344                                 stack_pointer_rtx, stack_limit_rtx,
10345                                 NULL_RTX, 1, OPTAB_WIDEN);
10346       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
10347     }
10348
10349   if (GET_CODE (operands[1]) != CONST_INT
10350       || INTVAL (operands[1]) < -32767
10351       || INTVAL (operands[1]) > 32768)
10352     {
10353       neg_op0 = gen_reg_rtx (Pmode);
10354       if (TARGET_32BIT)
10355         emit_insn (gen_negsi2 (neg_op0, operands[1]));
10356       else
10357         emit_insn (gen_negdi2 (neg_op0, operands[1]));
10358     }
10359   else
10360     neg_op0 = GEN_INT (- INTVAL (operands[1]));
10361
10362   if (TARGET_UPDATE)
10363     emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update : gen_movdi_di_update))
10364                 (stack_pointer_rtx, stack_pointer_rtx, neg_op0, chain));
10365
10366   else
10367     {
10368       emit_insn ((* ((TARGET_32BIT) ? gen_addsi3 : gen_adddi3))
10369                  (stack_pointer_rtx, stack_pointer_rtx, neg_op0));
10370       emit_move_insn (gen_rtx_MEM (Pmode, stack_pointer_rtx), chain);
10371     }
10372
10373   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
10374   DONE;
10375 }")
10376
10377 ;; These patterns say how to save and restore the stack pointer.  We need not
10378 ;; save the stack pointer at function level since we are careful to
10379 ;; preserve the backchain.  At block level, we have to restore the backchain
10380 ;; when we restore the stack pointer.
10381 ;;
10382 ;; For nonlocal gotos, we must save both the stack pointer and its
10383 ;; backchain and restore both.  Note that in the nonlocal case, the
10384 ;; save area is a memory location.
10385
10386 (define_expand "save_stack_function"
10387   [(match_operand 0 "any_operand" "")
10388    (match_operand 1 "any_operand" "")]
10389   ""
10390   "DONE;")
10391
10392 (define_expand "restore_stack_function"
10393   [(match_operand 0 "any_operand" "")
10394    (match_operand 1 "any_operand" "")]
10395   ""
10396   "DONE;")
10397
10398 ;; Adjust stack pointer (op0) to a new value (op1).
10399 ;; First copy old stack backchain to new location, and ensure that the
10400 ;; scheduler won't reorder the sp assignment before the backchain write.
10401 (define_expand "restore_stack_block"
10402   [(set (match_dup 2) (match_dup 3))
10403    (set (match_dup 4) (match_dup 2))
10404    (set (match_dup 5) (unspec:BLK [(match_dup 5)] UNSPEC_TIE))
10405    (set (match_operand 0 "register_operand" "")
10406         (match_operand 1 "register_operand" ""))]
10407   ""
10408   "
10409 {
10410   operands[2] = gen_reg_rtx (Pmode);
10411   operands[3] = gen_frame_mem (Pmode, operands[0]);
10412   operands[4] = gen_frame_mem (Pmode, operands[1]);
10413   operands[5] = gen_frame_mem (BLKmode, operands[0]);
10414 }")
10415
10416 (define_expand "save_stack_nonlocal"
10417   [(set (match_dup 3) (match_dup 4))
10418    (set (match_operand 0 "memory_operand" "") (match_dup 3))
10419    (set (match_dup 2) (match_operand 1 "register_operand" ""))]
10420   ""
10421   "
10422 {
10423   int units_per_word = (TARGET_32BIT) ? 4 : 8;
10424
10425   /* Copy the backchain to the first word, sp to the second.  */
10426   operands[0] = adjust_address_nv (operands[0], Pmode, 0);
10427   operands[2] = adjust_address_nv (operands[0], Pmode, units_per_word);
10428   operands[3] = gen_reg_rtx (Pmode);
10429   operands[4] = gen_frame_mem (Pmode, operands[1]);
10430 }")
10431
10432 (define_expand "restore_stack_nonlocal"
10433   [(set (match_dup 2) (match_operand 1 "memory_operand" ""))
10434    (set (match_dup 3) (match_dup 4))
10435    (set (match_dup 5) (match_dup 2))
10436    (set (match_dup 6) (unspec:BLK [(match_dup 6)] UNSPEC_TIE))
10437    (set (match_operand 0 "register_operand" "") (match_dup 3))]
10438   ""
10439   "
10440 {
10441   int units_per_word = (TARGET_32BIT) ? 4 : 8;
10442
10443   /* Restore the backchain from the first word, sp from the second.  */
10444   operands[2] = gen_reg_rtx (Pmode);
10445   operands[3] = gen_reg_rtx (Pmode);
10446   operands[1] = adjust_address_nv (operands[1], Pmode, 0);
10447   operands[4] = adjust_address_nv (operands[1], Pmode, units_per_word);
10448   operands[5] = gen_frame_mem (Pmode, operands[3]);
10449   operands[6] = gen_frame_mem (BLKmode, operands[0]);
10450 }")
10451 \f
10452 ;; TOC register handling.
10453
10454 ;; Code to initialize the TOC register...
10455
10456 (define_insn "load_toc_aix_si"
10457   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10458                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
10459               (use (reg:SI 2))])]
10460   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
10461   "*
10462 {
10463   char buf[30];
10464   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10465   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10466   operands[2] = gen_rtx_REG (Pmode, 2);
10467   return \"{l|lwz} %0,%1(%2)\";
10468 }"
10469   [(set_attr "type" "load")])
10470
10471 (define_insn "load_toc_aix_di"
10472   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10473                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
10474               (use (reg:DI 2))])]
10475   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
10476   "*
10477 {
10478   char buf[30];
10479 #ifdef TARGET_RELOCATABLE
10480   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
10481                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
10482 #else
10483   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10484 #endif
10485   if (TARGET_ELF)
10486     strcat (buf, \"@toc\");
10487   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10488   operands[2] = gen_rtx_REG (Pmode, 2);
10489   return \"ld %0,%1(%2)\";
10490 }"
10491   [(set_attr "type" "load")])
10492
10493 (define_insn "load_toc_v4_pic_si"
10494   [(set (reg:SI 65)
10495         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
10496   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
10497   "bl _GLOBAL_OFFSET_TABLE_@local-4"
10498   [(set_attr "type" "branch")
10499    (set_attr "length" "4")])
10500
10501 (define_insn "load_toc_v4_PIC_1"
10502   [(set (reg:SI 65)
10503         (match_operand:SI 0 "immediate_operand" "s"))
10504    (use (unspec [(match_dup 0)] UNSPEC_TOC))]
10505   "TARGET_ELF && DEFAULT_ABI != ABI_AIX
10506    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
10507   "bcl 20,31,%0\\n%0:"
10508   [(set_attr "type" "branch")
10509    (set_attr "length" "4")])
10510
10511 (define_insn "load_toc_v4_PIC_1b"
10512   [(set (reg:SI 65)
10513         (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")]
10514                 UNSPEC_TOCPTR))]
10515   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10516   "bcl 20,31,$+8\\n\\t.long %0-$"
10517   [(set_attr "type" "branch")
10518    (set_attr "length" "8")])
10519
10520 (define_insn "load_toc_v4_PIC_2"
10521   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10522         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10523                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
10524                              (match_operand:SI 3 "immediate_operand" "s")))))]
10525   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10526   "{l|lwz} %0,%2-%3(%1)"
10527   [(set_attr "type" "load")])
10528
10529 (define_insn "load_toc_v4_PIC_3b"
10530   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
10531         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
10532                  (high:SI
10533                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
10534                              (match_operand:SI 3 "symbol_ref_operand" "s")))))]
10535   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
10536   "{cau|addis} %0,%1,%2-%3@ha")
10537
10538 (define_insn "load_toc_v4_PIC_3c"
10539   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10540         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10541                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
10542                              (match_operand:SI 3 "symbol_ref_operand" "s"))))]
10543   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
10544   "{cal|addi} %0,%1,%2-%3@l")
10545
10546 ;; If the TOC is shared over a translation unit, as happens with all
10547 ;; the kinds of PIC that we support, we need to restore the TOC
10548 ;; pointer only when jumping over units of translation.
10549 ;; On Darwin, we need to reload the picbase.
10550
10551 (define_expand "builtin_setjmp_receiver"
10552   [(use (label_ref (match_operand 0 "" "")))]
10553   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
10554    || (TARGET_TOC && TARGET_MINIMAL_TOC)
10555    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
10556   "
10557 {
10558 #if TARGET_MACHO
10559   if (DEFAULT_ABI == ABI_DARWIN)
10560     {
10561       const char *picbase = machopic_function_base_name ();
10562       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (picbase));
10563       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
10564       rtx tmplabrtx;
10565       char tmplab[20];
10566
10567       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
10568                                   CODE_LABEL_NUMBER (operands[0]));
10569       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
10570
10571       emit_insn (gen_load_macho_picbase (tmplabrtx));
10572       emit_move_insn (picreg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
10573       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
10574     }
10575   else
10576 #endif
10577     rs6000_emit_load_toc_table (FALSE);
10578   DONE;
10579 }")
10580
10581 ;; Elf specific ways of loading addresses for non-PIC code.
10582 ;; The output of this could be r0, but we make a very strong
10583 ;; preference for a base register because it will usually
10584 ;; be needed there.
10585 (define_insn "elf_high"
10586   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
10587         (high:SI (match_operand 1 "" "")))]
10588   "TARGET_ELF && ! TARGET_64BIT"
10589   "{liu|lis} %0,%1@ha")
10590
10591 (define_insn "elf_low"
10592   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
10593         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
10594                    (match_operand 2 "" "")))]
10595    "TARGET_ELF && ! TARGET_64BIT"
10596    "@
10597     {cal|la} %0,%2@l(%1)
10598     {ai|addic} %0,%1,%K2")
10599 \f
10600 ;; A function pointer under AIX is a pointer to a data area whose first word
10601 ;; contains the actual address of the function, whose second word contains a
10602 ;; pointer to its TOC, and whose third word contains a value to place in the
10603 ;; static chain register (r11).  Note that if we load the static chain, our
10604 ;; "trampoline" need not have any executable code.
10605
10606 (define_expand "call_indirect_aix32"
10607   [(set (match_dup 2)
10608         (mem:SI (match_operand:SI 0 "gpc_reg_operand" "")))
10609    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10610         (reg:SI 2))
10611    (set (reg:SI 2)
10612         (mem:SI (plus:SI (match_dup 0)
10613                          (const_int 4))))
10614    (set (reg:SI 11)
10615         (mem:SI (plus:SI (match_dup 0)
10616                          (const_int 8))))
10617    (parallel [(call (mem:SI (match_dup 2))
10618                     (match_operand 1 "" ""))
10619               (use (reg:SI 2))
10620               (use (reg:SI 11))
10621               (set (reg:SI 2)
10622                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10623               (clobber (reg:SI 65))])]
10624   "TARGET_32BIT"
10625   "
10626 { operands[2] = gen_reg_rtx (SImode); }")
10627
10628 (define_expand "call_indirect_aix64"
10629   [(set (match_dup 2)
10630         (mem:DI (match_operand:DI 0 "gpc_reg_operand" "")))
10631    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10632         (reg:DI 2))
10633    (set (reg:DI 2)
10634         (mem:DI (plus:DI (match_dup 0)
10635                          (const_int 8))))
10636    (set (reg:DI 11)
10637         (mem:DI (plus:DI (match_dup 0)
10638                          (const_int 16))))
10639    (parallel [(call (mem:SI (match_dup 2))
10640                     (match_operand 1 "" ""))
10641               (use (reg:DI 2))
10642               (use (reg:DI 11))
10643               (set (reg:DI 2)
10644                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10645               (clobber (reg:SI 65))])]
10646   "TARGET_64BIT"
10647   "
10648 { operands[2] = gen_reg_rtx (DImode); }")
10649
10650 (define_expand "call_value_indirect_aix32"
10651   [(set (match_dup 3)
10652         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
10653    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10654         (reg:SI 2))
10655    (set (reg:SI 2)
10656         (mem:SI (plus:SI (match_dup 1)
10657                          (const_int 4))))
10658    (set (reg:SI 11)
10659         (mem:SI (plus:SI (match_dup 1)
10660                          (const_int 8))))
10661    (parallel [(set (match_operand 0 "" "")
10662                    (call (mem:SI (match_dup 3))
10663                          (match_operand 2 "" "")))
10664               (use (reg:SI 2))
10665               (use (reg:SI 11))
10666               (set (reg:SI 2)
10667                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10668               (clobber (reg:SI 65))])]
10669   "TARGET_32BIT"
10670   "
10671 { operands[3] = gen_reg_rtx (SImode); }")
10672
10673 (define_expand "call_value_indirect_aix64"
10674   [(set (match_dup 3)
10675         (mem:DI (match_operand:DI 1 "gpc_reg_operand" "")))
10676    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10677         (reg:DI 2))
10678    (set (reg:DI 2)
10679         (mem:DI (plus:DI (match_dup 1)
10680                          (const_int 8))))
10681    (set (reg:DI 11)
10682         (mem:DI (plus:DI (match_dup 1)
10683                          (const_int 16))))
10684    (parallel [(set (match_operand 0 "" "")
10685                    (call (mem:SI (match_dup 3))
10686                          (match_operand 2 "" "")))
10687               (use (reg:DI 2))
10688               (use (reg:DI 11))
10689               (set (reg:DI 2)
10690                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10691               (clobber (reg:SI 65))])]
10692   "TARGET_64BIT"
10693   "
10694 { operands[3] = gen_reg_rtx (DImode); }")
10695
10696 ;; Now the definitions for the call and call_value insns
10697 (define_expand "call"
10698   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10699                     (match_operand 1 "" ""))
10700               (use (match_operand 2 "" ""))
10701               (clobber (reg:SI 65))])]
10702   ""
10703   "
10704 {
10705 #if TARGET_MACHO
10706   if (MACHOPIC_INDIRECT)
10707     operands[0] = machopic_indirect_call_target (operands[0]);
10708 #endif
10709
10710   gcc_assert (GET_CODE (operands[0]) == MEM);
10711   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
10712
10713   operands[0] = XEXP (operands[0], 0);
10714
10715   if (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT
10716       && flag_pic
10717       && GET_CODE (operands[0]) == SYMBOL_REF
10718       && !SYMBOL_REF_LOCAL_P (operands[0]))
10719     {
10720       rtx call;
10721       rtvec tmp;
10722
10723       tmp = gen_rtvec (3,
10724                        gen_rtx_CALL (VOIDmode,
10725                                      gen_rtx_MEM (SImode, operands[0]),
10726                                      operands[1]),
10727                        gen_rtx_USE (VOIDmode, operands[2]),
10728                        gen_rtx_CLOBBER (VOIDmode,
10729                                         gen_rtx_REG (Pmode,
10730                                                      LINK_REGISTER_REGNUM)));
10731       call = emit_call_insn (gen_rtx_PARALLEL (VOIDmode, tmp));
10732       use_reg (&CALL_INSN_FUNCTION_USAGE (call), pic_offset_table_rtx);
10733       DONE;
10734     }
10735
10736   if (GET_CODE (operands[0]) != SYMBOL_REF
10737       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
10738       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
10739     {
10740       if (INTVAL (operands[2]) & CALL_LONG)
10741         operands[0] = rs6000_longcall_ref (operands[0]);
10742
10743       switch (DEFAULT_ABI)
10744         {
10745         case ABI_V4:
10746         case ABI_DARWIN:
10747           operands[0] = force_reg (Pmode, operands[0]);
10748           break;
10749
10750         case ABI_AIX:
10751           /* AIX function pointers are really pointers to a three word
10752              area.  */
10753           emit_call_insn (TARGET_32BIT
10754                           ? gen_call_indirect_aix32 (force_reg (SImode,
10755                                                                 operands[0]),
10756                                                      operands[1])
10757                           : gen_call_indirect_aix64 (force_reg (DImode,
10758                                                                 operands[0]),
10759                                                      operands[1]));
10760           DONE;
10761
10762         default:
10763           gcc_unreachable ();
10764         }
10765     }
10766 }")
10767
10768 (define_expand "call_value"
10769   [(parallel [(set (match_operand 0 "" "")
10770                    (call (mem:SI (match_operand 1 "address_operand" ""))
10771                          (match_operand 2 "" "")))
10772               (use (match_operand 3 "" ""))
10773               (clobber (reg:SI 65))])]
10774   ""
10775   "
10776 {
10777 #if TARGET_MACHO
10778   if (MACHOPIC_INDIRECT)
10779     operands[1] = machopic_indirect_call_target (operands[1]);
10780 #endif
10781
10782   gcc_assert (GET_CODE (operands[1]) == MEM);
10783   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
10784
10785   operands[1] = XEXP (operands[1], 0);
10786
10787   if (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT
10788       && flag_pic
10789       && GET_CODE (operands[1]) == SYMBOL_REF
10790       && !SYMBOL_REF_LOCAL_P (operands[1]))
10791     {
10792       rtx call;
10793       rtvec tmp;
10794
10795       tmp = gen_rtvec (3,
10796                        gen_rtx_SET (VOIDmode,
10797                                     operands[0],
10798                                     gen_rtx_CALL (VOIDmode,
10799                                                   gen_rtx_MEM (SImode,
10800                                                                operands[1]),
10801                                                   operands[2])),
10802                        gen_rtx_USE (VOIDmode, operands[3]),
10803                        gen_rtx_CLOBBER (VOIDmode, 
10804                                         gen_rtx_REG (Pmode,
10805                                                      LINK_REGISTER_REGNUM)));
10806       call = emit_call_insn (gen_rtx_PARALLEL (VOIDmode, tmp));
10807       use_reg (&CALL_INSN_FUNCTION_USAGE (call), pic_offset_table_rtx);
10808       DONE;
10809     }
10810
10811   if (GET_CODE (operands[1]) != SYMBOL_REF
10812       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
10813       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
10814     {
10815       if (INTVAL (operands[3]) & CALL_LONG)
10816         operands[1] = rs6000_longcall_ref (operands[1]);
10817
10818       switch (DEFAULT_ABI)
10819         {
10820         case ABI_V4:
10821         case ABI_DARWIN:
10822           operands[1] = force_reg (Pmode, operands[1]);
10823           break;
10824
10825         case ABI_AIX:
10826           /* AIX function pointers are really pointers to a three word
10827              area.  */
10828           emit_call_insn (TARGET_32BIT
10829                           ? gen_call_value_indirect_aix32 (operands[0],
10830                                                            force_reg (SImode,
10831                                                                       operands[1]),
10832                                                            operands[2])
10833                           : gen_call_value_indirect_aix64 (operands[0],
10834                                                            force_reg (DImode,
10835                                                                       operands[1]),
10836                                                            operands[2]));
10837           DONE;
10838
10839         default:
10840           gcc_unreachable ();
10841         }
10842     }
10843 }")
10844
10845 ;; Call to function in current module.  No TOC pointer reload needed.
10846 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10847 ;; either the function was not prototyped, or it was prototyped as a
10848 ;; variable argument function.  It is > 0 if FP registers were passed
10849 ;; and < 0 if they were not.
10850
10851 (define_insn "*call_local32"
10852   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10853          (match_operand 1 "" "g,g"))
10854    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10855    (clobber (reg:SI 65))]
10856   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10857   "*
10858 {
10859   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10860     output_asm_insn (\"crxor 6,6,6\", operands);
10861
10862   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10863     output_asm_insn (\"creqv 6,6,6\", operands);
10864
10865   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10866 }"
10867   [(set_attr "type" "branch")
10868    (set_attr "length" "4,8")])
10869
10870 (define_insn "*call_local64"
10871   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10872          (match_operand 1 "" "g,g"))
10873    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10874    (clobber (reg:SI 65))]
10875   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10876   "*
10877 {
10878   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10879     output_asm_insn (\"crxor 6,6,6\", operands);
10880
10881   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10882     output_asm_insn (\"creqv 6,6,6\", operands);
10883
10884   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10885 }"
10886   [(set_attr "type" "branch")
10887    (set_attr "length" "4,8")])
10888
10889 (define_insn "*call_value_local32"
10890   [(set (match_operand 0 "" "")
10891         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10892               (match_operand 2 "" "g,g")))
10893    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10894    (clobber (reg:SI 65))]
10895   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10896   "*
10897 {
10898   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10899     output_asm_insn (\"crxor 6,6,6\", operands);
10900
10901   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10902     output_asm_insn (\"creqv 6,6,6\", operands);
10903
10904   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10905 }"
10906   [(set_attr "type" "branch")
10907    (set_attr "length" "4,8")])
10908
10909
10910 (define_insn "*call_value_local64"
10911   [(set (match_operand 0 "" "")
10912         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10913               (match_operand 2 "" "g,g")))
10914    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10915    (clobber (reg:SI 65))]
10916   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10917   "*
10918 {
10919   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10920     output_asm_insn (\"crxor 6,6,6\", operands);
10921
10922   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10923     output_asm_insn (\"creqv 6,6,6\", operands);
10924
10925   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10926 }"
10927   [(set_attr "type" "branch")
10928    (set_attr "length" "4,8")])
10929
10930 ;; Call to function which may be in another module.  Restore the TOC
10931 ;; pointer (r2) after the call unless this is System V.
10932 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10933 ;; either the function was not prototyped, or it was prototyped as a
10934 ;; variable argument function.  It is > 0 if FP registers were passed
10935 ;; and < 0 if they were not.
10936
10937 (define_insn "*call_indirect_nonlocal_aix32"
10938   [(call (mem:SI (match_operand:SI 0 "register_operand" "c,*l"))
10939          (match_operand 1 "" "g,g"))
10940    (use (reg:SI 2))
10941    (use (reg:SI 11))
10942    (set (reg:SI 2)
10943         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10944    (clobber (reg:SI 65))]
10945   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10946   "b%T0l\;{l|lwz} 2,20(1)"
10947   [(set_attr "type" "jmpreg")
10948    (set_attr "length" "8")])
10949
10950 (define_insn "*call_nonlocal_aix32"
10951   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10952          (match_operand 1 "" "g"))
10953    (use (match_operand:SI 2 "immediate_operand" "O"))
10954    (clobber (reg:SI 65))]
10955   "TARGET_32BIT
10956    && DEFAULT_ABI == ABI_AIX
10957    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10958   "bl %z0\;%."
10959   [(set_attr "type" "branch")
10960    (set_attr "length" "8")])
10961
10962 (define_insn "*call_indirect_nonlocal_aix64"
10963   [(call (mem:SI (match_operand:DI 0 "register_operand" "c,*l"))
10964          (match_operand 1 "" "g,g"))
10965    (use (reg:DI 2))
10966    (use (reg:DI 11))
10967    (set (reg:DI 2)
10968         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10969    (clobber (reg:SI 65))]
10970   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10971   "b%T0l\;ld 2,40(1)"
10972   [(set_attr "type" "jmpreg")
10973    (set_attr "length" "8")])
10974
10975 (define_insn "*call_nonlocal_aix64"
10976   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10977          (match_operand 1 "" "g"))
10978    (use (match_operand:SI 2 "immediate_operand" "O"))
10979    (clobber (reg:SI 65))]
10980   "TARGET_64BIT
10981    && DEFAULT_ABI == ABI_AIX
10982    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10983   "bl %z0\;%."
10984   [(set_attr "type" "branch")
10985    (set_attr "length" "8")])
10986
10987 (define_insn "*call_value_indirect_nonlocal_aix32"
10988   [(set (match_operand 0 "" "")
10989         (call (mem:SI (match_operand:SI 1 "register_operand" "c,*l"))
10990               (match_operand 2 "" "g,g")))
10991    (use (reg:SI 2))
10992    (use (reg:SI 11))
10993    (set (reg:SI 2)
10994         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10995    (clobber (reg:SI 65))]
10996   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10997   "b%T1l\;{l|lwz} 2,20(1)"
10998   [(set_attr "type" "jmpreg")
10999    (set_attr "length" "8")])
11000
11001 (define_insn "*call_value_nonlocal_aix32"
11002   [(set (match_operand 0 "" "")
11003         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
11004               (match_operand 2 "" "g")))
11005    (use (match_operand:SI 3 "immediate_operand" "O"))
11006    (clobber (reg:SI 65))]
11007   "TARGET_32BIT
11008    && DEFAULT_ABI == ABI_AIX
11009    && (INTVAL (operands[3]) & CALL_LONG) == 0"
11010   "bl %z1\;%."
11011   [(set_attr "type" "branch")
11012    (set_attr "length" "8")])
11013
11014 (define_insn "*call_value_indirect_nonlocal_aix64"
11015   [(set (match_operand 0 "" "")
11016         (call (mem:SI (match_operand:DI 1 "register_operand" "c,*l"))
11017               (match_operand 2 "" "g,g")))
11018    (use (reg:DI 2))
11019    (use (reg:DI 11))
11020    (set (reg:DI 2)
11021         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
11022    (clobber (reg:SI 65))]
11023   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
11024   "b%T1l\;ld 2,40(1)"
11025   [(set_attr "type" "jmpreg")
11026    (set_attr "length" "8")])
11027
11028 (define_insn "*call_value_nonlocal_aix64"
11029   [(set (match_operand 0 "" "")
11030         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
11031               (match_operand 2 "" "g")))
11032    (use (match_operand:SI 3 "immediate_operand" "O"))
11033    (clobber (reg:SI 65))]
11034   "TARGET_64BIT
11035    && DEFAULT_ABI == ABI_AIX
11036    && (INTVAL (operands[3]) & CALL_LONG) == 0"
11037   "bl %z1\;%."
11038   [(set_attr "type" "branch")
11039    (set_attr "length" "8")])
11040
11041 ;; A function pointer under System V is just a normal pointer
11042 ;; operands[0] is the function pointer
11043 ;; operands[1] is the stack size to clean up
11044 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
11045 ;; which indicates how to set cr1
11046
11047 (define_insn "*call_indirect_nonlocal_sysv<mode>"
11048   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l,c,*l"))
11049          (match_operand 1 "" "g,g,g,g"))
11050    (use (match_operand:SI 2 "immediate_operand" "O,O,n,n"))
11051    (clobber (reg:SI 65))]
11052   "DEFAULT_ABI == ABI_V4
11053    || DEFAULT_ABI == ABI_DARWIN"
11054 {
11055   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11056     output_asm_insn ("crxor 6,6,6", operands);
11057
11058   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11059     output_asm_insn ("creqv 6,6,6", operands);
11060
11061   return "b%T0l";
11062 }
11063   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
11064    (set_attr "length" "4,4,8,8")])
11065
11066 (define_insn "*call_nonlocal_sysv<mode>"
11067   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
11068          (match_operand 1 "" "g,g"))
11069    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11070    (clobber (reg:SI 65))]
11071   "(DEFAULT_ABI == ABI_DARWIN
11072    || (DEFAULT_ABI == ABI_V4
11073        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
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 TARGET_MACHO
11082   return output_call(insn, operands, 0, 2);
11083 #else
11084   if (DEFAULT_ABI == ABI_V4 && flag_pic)
11085     {
11086       if (TARGET_SECURE_PLT && flag_pic == 2)
11087         /* The magic 32768 offset here and in the other sysv call insns
11088            corresponds to the offset of r30 in .got2, as given by LCTOC1.
11089            See sysv4.h:toc_section.  */
11090         return "bl %z0+32768@plt";
11091       else
11092         return "bl %z0@plt";
11093     }
11094   else
11095     return "bl %z0";
11096 #endif
11097 }
11098   [(set_attr "type" "branch,branch")
11099    (set_attr "length" "4,8")])
11100
11101 (define_insn "*call_value_indirect_nonlocal_sysv<mode>"
11102   [(set (match_operand 0 "" "")
11103         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l,c,*l"))
11104               (match_operand 2 "" "g,g,g,g")))
11105    (use (match_operand:SI 3 "immediate_operand" "O,O,n,n"))
11106    (clobber (reg:SI 65))]
11107   "DEFAULT_ABI == ABI_V4
11108    || DEFAULT_ABI == ABI_DARWIN"
11109 {
11110   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11111     output_asm_insn ("crxor 6,6,6", operands);
11112
11113   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11114     output_asm_insn ("creqv 6,6,6", operands);
11115
11116   return "b%T1l";
11117 }
11118   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
11119    (set_attr "length" "4,4,8,8")])
11120
11121 (define_insn "*call_value_nonlocal_sysv<mode>"
11122   [(set (match_operand 0 "" "")
11123         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
11124               (match_operand 2 "" "g,g")))
11125    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11126    (clobber (reg:SI 65))]
11127   "(DEFAULT_ABI == ABI_DARWIN
11128    || (DEFAULT_ABI == ABI_V4
11129        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
11130 {
11131   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11132     output_asm_insn ("crxor 6,6,6", operands);
11133
11134   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11135     output_asm_insn ("creqv 6,6,6", operands);
11136
11137 #if TARGET_MACHO
11138   return output_call(insn, operands, 1, 3);
11139 #else
11140   if (DEFAULT_ABI == ABI_V4 && flag_pic)
11141     {
11142       if (TARGET_SECURE_PLT && flag_pic == 2)
11143         return "bl %z1+32768@plt";
11144       else
11145         return "bl %z1@plt";
11146     }
11147   else
11148     return "bl %z1";
11149 #endif
11150 }
11151   [(set_attr "type" "branch,branch")
11152    (set_attr "length" "4,8")])
11153
11154 ;; Call subroutine returning any type.
11155 (define_expand "untyped_call"
11156   [(parallel [(call (match_operand 0 "" "")
11157                     (const_int 0))
11158               (match_operand 1 "" "")
11159               (match_operand 2 "" "")])]
11160   ""
11161   "
11162 {
11163   int i;
11164
11165   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
11166
11167   for (i = 0; i < XVECLEN (operands[2], 0); i++)
11168     {
11169       rtx set = XVECEXP (operands[2], 0, i);
11170       emit_move_insn (SET_DEST (set), SET_SRC (set));
11171     }
11172
11173   /* The optimizer does not know that the call sets the function value
11174      registers we stored in the result block.  We avoid problems by
11175      claiming that all hard registers are used and clobbered at this
11176      point.  */
11177   emit_insn (gen_blockage ());
11178
11179   DONE;
11180 }")
11181
11182 ;; sibling call patterns
11183 (define_expand "sibcall"
11184   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
11185                     (match_operand 1 "" ""))
11186               (use (match_operand 2 "" ""))
11187               (use (reg:SI 65))
11188               (return)])]
11189   ""
11190   "
11191 {
11192 #if TARGET_MACHO
11193   if (MACHOPIC_INDIRECT)
11194     operands[0] = machopic_indirect_call_target (operands[0]);
11195 #endif
11196
11197   gcc_assert (GET_CODE (operands[0]) == MEM);
11198   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
11199
11200   operands[0] = XEXP (operands[0], 0);
11201 }")
11202
11203 ;; this and similar patterns must be marked as using LR, otherwise
11204 ;; dataflow will try to delete the store into it.  This is true
11205 ;; even when the actual reg to jump to is in CTR, when LR was
11206 ;; saved and restored around the PIC-setting BCL.
11207 (define_insn "*sibcall_local32"
11208   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
11209          (match_operand 1 "" "g,g"))
11210    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11211    (use (reg:SI 65))
11212    (return)]
11213   "(INTVAL (operands[2]) & CALL_LONG) == 0"
11214   "*
11215 {
11216   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11217     output_asm_insn (\"crxor 6,6,6\", operands);
11218
11219   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11220     output_asm_insn (\"creqv 6,6,6\", operands);
11221
11222   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
11223 }"
11224   [(set_attr "type" "branch")
11225    (set_attr "length" "4,8")])
11226
11227 (define_insn "*sibcall_local64"
11228   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
11229          (match_operand 1 "" "g,g"))
11230    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11231    (use (reg:SI 65))
11232    (return)]
11233   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
11234   "*
11235 {
11236   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11237     output_asm_insn (\"crxor 6,6,6\", operands);
11238
11239   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11240     output_asm_insn (\"creqv 6,6,6\", operands);
11241
11242   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
11243 }"
11244   [(set_attr "type" "branch")
11245    (set_attr "length" "4,8")])
11246
11247 (define_insn "*sibcall_value_local32"
11248   [(set (match_operand 0 "" "")
11249         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
11250               (match_operand 2 "" "g,g")))
11251    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11252    (use (reg:SI 65))
11253    (return)]
11254   "(INTVAL (operands[3]) & CALL_LONG) == 0"
11255   "*
11256 {
11257   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11258     output_asm_insn (\"crxor 6,6,6\", operands);
11259
11260   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11261     output_asm_insn (\"creqv 6,6,6\", operands);
11262
11263   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
11264 }"
11265   [(set_attr "type" "branch")
11266    (set_attr "length" "4,8")])
11267
11268
11269 (define_insn "*sibcall_value_local64"
11270   [(set (match_operand 0 "" "")
11271         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
11272               (match_operand 2 "" "g,g")))
11273    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11274    (use (reg:SI 65))
11275    (return)]
11276   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
11277   "*
11278 {
11279   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11280     output_asm_insn (\"crxor 6,6,6\", operands);
11281
11282   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11283     output_asm_insn (\"creqv 6,6,6\", operands);
11284
11285   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
11286 }"
11287   [(set_attr "type" "branch")
11288    (set_attr "length" "4,8")])
11289
11290 (define_insn "*sibcall_nonlocal_aix32"
11291   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
11292          (match_operand 1 "" "g"))
11293    (use (match_operand:SI 2 "immediate_operand" "O"))
11294    (use (reg:SI 65))
11295    (return)]
11296   "TARGET_32BIT
11297    && DEFAULT_ABI == ABI_AIX
11298    && (INTVAL (operands[2]) & CALL_LONG) == 0"
11299   "b %z0"
11300   [(set_attr "type" "branch")
11301    (set_attr "length" "4")])
11302
11303 (define_insn "*sibcall_nonlocal_aix64"
11304   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
11305          (match_operand 1 "" "g"))
11306    (use (match_operand:SI 2 "immediate_operand" "O"))
11307    (use (reg:SI 65))
11308    (return)]
11309   "TARGET_64BIT
11310    && DEFAULT_ABI == ABI_AIX
11311    && (INTVAL (operands[2]) & CALL_LONG) == 0"
11312   "b %z0"
11313   [(set_attr "type" "branch")
11314    (set_attr "length" "4")])
11315
11316 (define_insn "*sibcall_value_nonlocal_aix32"
11317   [(set (match_operand 0 "" "")
11318         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
11319               (match_operand 2 "" "g")))
11320    (use (match_operand:SI 3 "immediate_operand" "O"))
11321    (use (reg:SI 65))
11322    (return)]
11323   "TARGET_32BIT
11324    && DEFAULT_ABI == ABI_AIX
11325    && (INTVAL (operands[3]) & CALL_LONG) == 0"
11326   "b %z1"
11327   [(set_attr "type" "branch")
11328    (set_attr "length" "4")])
11329
11330 (define_insn "*sibcall_value_nonlocal_aix64"
11331   [(set (match_operand 0 "" "")
11332         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
11333               (match_operand 2 "" "g")))
11334    (use (match_operand:SI 3 "immediate_operand" "O"))
11335    (use (reg:SI 65))
11336    (return)]
11337   "TARGET_64BIT
11338    && DEFAULT_ABI == ABI_AIX
11339    && (INTVAL (operands[3]) & CALL_LONG) == 0"
11340   "b %z1"
11341   [(set_attr "type" "branch")
11342    (set_attr "length" "4")])
11343
11344 (define_insn "*sibcall_nonlocal_sysv<mode>"
11345   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
11346          (match_operand 1 "" ""))
11347    (use (match_operand 2 "immediate_operand" "O,n"))
11348    (use (reg:SI 65))
11349    (return)]
11350   "(DEFAULT_ABI == ABI_DARWIN
11351      || DEFAULT_ABI == ABI_V4)
11352    && (INTVAL (operands[2]) & CALL_LONG) == 0"
11353   "*
11354 {
11355   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11356     output_asm_insn (\"crxor 6,6,6\", operands);
11357
11358   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11359     output_asm_insn (\"creqv 6,6,6\", operands);
11360
11361   if (DEFAULT_ABI == ABI_V4 && flag_pic)
11362     {
11363       if (TARGET_SECURE_PLT && flag_pic == 2)
11364         return \"b %z0+32768@plt\";
11365       else
11366         return \"b %z0@plt\";
11367     }
11368   else
11369     return \"b %z0\";
11370 }"
11371   [(set_attr "type" "branch,branch")
11372    (set_attr "length" "4,8")])
11373
11374 (define_expand "sibcall_value"
11375   [(parallel [(set (match_operand 0 "register_operand" "")
11376                 (call (mem:SI (match_operand 1 "address_operand" ""))
11377                       (match_operand 2 "" "")))
11378               (use (match_operand 3 "" ""))
11379               (use (reg:SI 65))
11380               (return)])]
11381   ""
11382   "
11383 {
11384 #if TARGET_MACHO
11385   if (MACHOPIC_INDIRECT)
11386     operands[1] = machopic_indirect_call_target (operands[1]);
11387 #endif
11388
11389   gcc_assert (GET_CODE (operands[1]) == MEM);
11390   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
11391
11392   operands[1] = XEXP (operands[1], 0);
11393 }")
11394
11395 (define_insn "*sibcall_value_nonlocal_sysv<mode>"
11396   [(set (match_operand 0 "" "")
11397         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
11398               (match_operand 2 "" "")))
11399    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11400    (use (reg:SI 65))
11401    (return)]
11402   "(DEFAULT_ABI == ABI_DARWIN
11403        || DEFAULT_ABI == ABI_V4)
11404    && (INTVAL (operands[3]) & CALL_LONG) == 0"
11405   "*
11406 {
11407   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11408     output_asm_insn (\"crxor 6,6,6\", operands);
11409
11410   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11411     output_asm_insn (\"creqv 6,6,6\", operands);
11412
11413   if (DEFAULT_ABI == ABI_V4 && flag_pic)
11414     {
11415       if (TARGET_SECURE_PLT && flag_pic == 2)
11416         return \"b %z1+32768@plt\";
11417       else
11418         return \"b %z1@plt\";
11419     }
11420   else
11421     return \"b %z1\";
11422 }"
11423   [(set_attr "type" "branch,branch")
11424    (set_attr "length" "4,8")])
11425
11426 (define_expand "sibcall_epilogue"
11427   [(use (const_int 0))]
11428   "TARGET_SCHED_PROLOG"
11429   "
11430 {
11431       rs6000_emit_epilogue (TRUE);
11432       DONE;
11433 }")
11434
11435 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
11436 ;; all of memory.  This blocks insns from being moved across this point.
11437
11438 (define_insn "blockage"
11439   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
11440   ""
11441   "")
11442 \f
11443 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
11444 ;; signed & unsigned, and one type of branch.
11445 ;;
11446 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
11447 ;; insns, and branches.  We store the operands of compares until we see
11448 ;; how it is used.
11449 (define_expand "cmp<mode>"
11450   [(set (cc0)
11451         (compare (match_operand:GPR 0 "gpc_reg_operand" "")
11452                  (match_operand:GPR 1 "reg_or_short_operand" "")))]
11453   ""
11454   "
11455 {
11456   /* Take care of the possibility that operands[1] might be negative but
11457      this might be a logical operation.  That insn doesn't exist.  */
11458   if (GET_CODE (operands[1]) == CONST_INT
11459       && INTVAL (operands[1]) < 0)
11460     operands[1] = force_reg (<MODE>mode, operands[1]);
11461
11462   rs6000_compare_op0 = operands[0];
11463   rs6000_compare_op1 = operands[1];
11464   rs6000_compare_fp_p = 0;
11465   DONE;
11466 }")
11467
11468 (define_expand "cmp<mode>"
11469   [(set (cc0) (compare (match_operand:FP 0 "gpc_reg_operand" "")
11470                        (match_operand:FP 1 "gpc_reg_operand" "")))]
11471   ""
11472   "
11473 {
11474   rs6000_compare_op0 = operands[0];
11475   rs6000_compare_op1 = operands[1];
11476   rs6000_compare_fp_p = 1;
11477   DONE;
11478 }")
11479
11480 (define_expand "beq"
11481   [(use (match_operand 0 "" ""))]
11482   ""
11483   "{ rs6000_emit_cbranch (EQ, operands[0]); DONE; }")
11484
11485 (define_expand "bne"
11486   [(use (match_operand 0 "" ""))]
11487   ""
11488   "{ rs6000_emit_cbranch (NE, operands[0]); DONE; }")
11489
11490 (define_expand "bge"
11491   [(use (match_operand 0 "" ""))]
11492   ""
11493   "{ rs6000_emit_cbranch (GE, operands[0]); DONE; }")
11494
11495 (define_expand "bgt"
11496   [(use (match_operand 0 "" ""))]
11497   ""
11498   "{ rs6000_emit_cbranch (GT, operands[0]); DONE; }")
11499
11500 (define_expand "ble"
11501   [(use (match_operand 0 "" ""))]
11502   ""
11503   "{ rs6000_emit_cbranch (LE, operands[0]); DONE; }")
11504
11505 (define_expand "blt"
11506   [(use (match_operand 0 "" ""))]
11507   ""
11508   "{ rs6000_emit_cbranch (LT, operands[0]); DONE; }")
11509
11510 (define_expand "bgeu"
11511   [(use (match_operand 0 "" ""))]
11512   ""
11513   "{ rs6000_emit_cbranch (GEU, operands[0]); DONE; }")
11514
11515 (define_expand "bgtu"
11516   [(use (match_operand 0 "" ""))]
11517   ""
11518   "{ rs6000_emit_cbranch (GTU, operands[0]); DONE; }")
11519
11520 (define_expand "bleu"
11521   [(use (match_operand 0 "" ""))]
11522   ""
11523   "{ rs6000_emit_cbranch (LEU, operands[0]); DONE; }")
11524
11525 (define_expand "bltu"
11526   [(use (match_operand 0 "" ""))]
11527   ""
11528   "{ rs6000_emit_cbranch (LTU, operands[0]); DONE; }")
11529
11530 (define_expand "bunordered"
11531   [(use (match_operand 0 "" ""))]
11532   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11533   "{ rs6000_emit_cbranch (UNORDERED, operands[0]); DONE; }")
11534
11535 (define_expand "bordered"
11536   [(use (match_operand 0 "" ""))]
11537   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11538   "{ rs6000_emit_cbranch (ORDERED, operands[0]); DONE; }")
11539
11540 (define_expand "buneq"
11541   [(use (match_operand 0 "" ""))]
11542   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11543   "{ rs6000_emit_cbranch (UNEQ, operands[0]); DONE; }")
11544
11545 (define_expand "bunge"
11546   [(use (match_operand 0 "" ""))]
11547   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11548   "{ rs6000_emit_cbranch (UNGE, operands[0]); DONE; }")
11549
11550 (define_expand "bungt"
11551   [(use (match_operand 0 "" ""))]
11552   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11553   "{ rs6000_emit_cbranch (UNGT, operands[0]); DONE; }")
11554
11555 (define_expand "bunle"
11556   [(use (match_operand 0 "" ""))]
11557   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11558   "{ rs6000_emit_cbranch (UNLE, operands[0]); DONE; }")
11559
11560 (define_expand "bunlt"
11561   [(use (match_operand 0 "" ""))]
11562   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11563   "{ rs6000_emit_cbranch (UNLT, operands[0]); DONE; }")
11564
11565 (define_expand "bltgt"
11566   [(use (match_operand 0 "" ""))]
11567   ""
11568   "{ rs6000_emit_cbranch (LTGT, operands[0]); DONE; }")
11569
11570 ;; For SNE, we would prefer that the xor/abs sequence be used for integers.
11571 ;; For SEQ, likewise, except that comparisons with zero should be done
11572 ;; with an scc insns.  However, due to the order that combine see the
11573 ;; resulting insns, we must, in fact, allow SEQ for integers.  Fail in
11574 ;; the cases we don't want to handle.
11575 (define_expand "seq"
11576   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11577   ""
11578   "{ rs6000_emit_sCOND (EQ, operands[0]); DONE; }")
11579
11580 (define_expand "sne"
11581   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11582   ""
11583   "
11584 {
11585   if (! rs6000_compare_fp_p)
11586     FAIL;
11587
11588   rs6000_emit_sCOND (NE, operands[0]);
11589   DONE;
11590 }")
11591
11592 ;; A >= 0 is best done the portable way for A an integer.
11593 (define_expand "sge"
11594   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11595   ""
11596   "
11597 {
11598   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
11599     FAIL;
11600
11601   rs6000_emit_sCOND (GE, operands[0]);
11602   DONE;
11603 }")
11604
11605 ;; A > 0 is best done using the portable sequence, so fail in that case.
11606 (define_expand "sgt"
11607   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11608   ""
11609   "
11610 {
11611   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
11612     FAIL;
11613
11614   rs6000_emit_sCOND (GT, operands[0]);
11615   DONE;
11616 }")
11617
11618 ;; A <= 0 is best done the portable way for A an integer.
11619 (define_expand "sle"
11620   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11621   ""
11622   "
11623 {
11624   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
11625     FAIL;
11626
11627   rs6000_emit_sCOND (LE, operands[0]);
11628   DONE;
11629 }")
11630
11631 ;; A < 0 is best done in the portable way for A an integer.
11632 (define_expand "slt"
11633   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11634   ""
11635   "
11636 {
11637   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
11638     FAIL;
11639
11640   rs6000_emit_sCOND (LT, operands[0]);
11641   DONE;
11642 }")
11643
11644 (define_expand "sgeu"
11645   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11646   ""
11647   "{ rs6000_emit_sCOND (GEU, operands[0]); DONE; }")
11648
11649 (define_expand "sgtu"
11650   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11651   ""
11652   "{ rs6000_emit_sCOND (GTU, operands[0]); DONE; }")
11653
11654 (define_expand "sleu"
11655   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11656   ""
11657   "{ rs6000_emit_sCOND (LEU, operands[0]); DONE; }")
11658
11659 (define_expand "sltu"
11660   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11661   ""
11662   "{ rs6000_emit_sCOND (LTU, operands[0]); DONE; }")
11663
11664 (define_expand "sunordered"
11665   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11666   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11667   "{ rs6000_emit_sCOND (UNORDERED, operands[0]); DONE; }")
11668
11669 (define_expand "sordered"
11670   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11671   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11672   "{ rs6000_emit_sCOND (ORDERED, operands[0]); DONE; }")
11673
11674 (define_expand "suneq"
11675   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11676   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11677   "{ rs6000_emit_sCOND (UNEQ, operands[0]); DONE; }")
11678
11679 (define_expand "sunge"
11680   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11681   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11682   "{ rs6000_emit_sCOND (UNGE, operands[0]); DONE; }")
11683
11684 (define_expand "sungt"
11685   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11686   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11687   "{ rs6000_emit_sCOND (UNGT, operands[0]); DONE; }")
11688
11689 (define_expand "sunle"
11690   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11691   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11692   "{ rs6000_emit_sCOND (UNLE, operands[0]); DONE; }")
11693
11694 (define_expand "sunlt"
11695   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11696   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11697   "{ rs6000_emit_sCOND (UNLT, operands[0]); DONE; }")
11698
11699 (define_expand "sltgt"
11700   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11701   ""
11702   "{ rs6000_emit_sCOND (LTGT, operands[0]); DONE; }")
11703
11704 (define_expand "stack_protect_set"
11705   [(match_operand 0 "memory_operand" "")
11706    (match_operand 1 "memory_operand" "")]
11707   ""
11708 {
11709 #ifdef TARGET_THREAD_SSP_OFFSET
11710   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
11711   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
11712   operands[1] = gen_rtx_MEM (Pmode, addr);
11713 #endif
11714   if (TARGET_64BIT)
11715     emit_insn (gen_stack_protect_setdi (operands[0], operands[1]));
11716   else
11717     emit_insn (gen_stack_protect_setsi (operands[0], operands[1]));
11718   DONE;
11719 })
11720
11721 (define_insn "stack_protect_setsi"
11722   [(set (match_operand:SI 0 "memory_operand" "=m")
11723         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
11724    (set (match_scratch:SI 2 "=&r") (const_int 0))]
11725   "TARGET_32BIT"
11726   "{l%U1%X1|lwz%U1%X1} %2,%1\;{st%U0%X0|stw%U0%X0} %2,%0\;{lil|li} %2,0"
11727   [(set_attr "type" "three")
11728    (set_attr "length" "12")])
11729
11730 (define_insn "stack_protect_setdi"
11731   [(set (match_operand:DI 0 "memory_operand" "=m")
11732         (unspec:DI [(match_operand:DI 1 "memory_operand" "m")] UNSPEC_SP_SET))
11733    (set (match_scratch:DI 2 "=&r") (const_int 0))]
11734   "TARGET_64BIT"
11735   "ld%U1%X1 %2,%1\;std%U0%X0 %2,%0\;{lil|li} %2,0"
11736   [(set_attr "type" "three")
11737    (set_attr "length" "12")])
11738
11739 (define_expand "stack_protect_test"
11740   [(match_operand 0 "memory_operand" "")
11741    (match_operand 1 "memory_operand" "")
11742    (match_operand 2 "" "")]
11743   ""
11744 {
11745 #ifdef TARGET_THREAD_SSP_OFFSET
11746   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
11747   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
11748   operands[1] = gen_rtx_MEM (Pmode, addr);
11749 #endif
11750   rs6000_compare_op0 = operands[0];
11751   rs6000_compare_op1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, operands[1]),
11752                                        UNSPEC_SP_TEST);
11753   rs6000_compare_fp_p = 0;
11754   emit_jump_insn (gen_beq (operands[2]));
11755   DONE;
11756 })
11757
11758 (define_insn "stack_protect_testsi"
11759   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
11760         (unspec:CCEQ [(match_operand:SI 1 "memory_operand" "m,m")
11761                       (match_operand:SI 2 "memory_operand" "m,m")]
11762                      UNSPEC_SP_TEST))
11763    (set (match_scratch:SI 4 "=r,r") (const_int 0))
11764    (clobber (match_scratch:SI 3 "=&r,&r"))]
11765   "TARGET_32BIT"
11766   "@
11767    {l%U1%X1|lwz%U1%X1} %3,%1\;{l%U2%X2|lwz%U2%X2} %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
11768    {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"
11769   [(set_attr "length" "16,20")])
11770
11771 (define_insn "stack_protect_testdi"
11772   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
11773         (unspec:CCEQ [(match_operand:DI 1 "memory_operand" "m,m")
11774                       (match_operand:DI 2 "memory_operand" "m,m")]
11775                      UNSPEC_SP_TEST))
11776    (set (match_scratch:DI 4 "=r,r") (const_int 0))
11777    (clobber (match_scratch:DI 3 "=&r,&r"))]
11778   "TARGET_64BIT"
11779   "@
11780    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
11781    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;cmpld %0,%3,%4\;{lil|li} %3,0\;{lil|li} %4,0"
11782   [(set_attr "length" "16,20")])
11783
11784 \f
11785 ;; Here are the actual compare insns.
11786 (define_insn "*cmp<mode>_internal1"
11787   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11788         (compare:CC (match_operand:GPR 1 "gpc_reg_operand" "r")
11789                     (match_operand:GPR 2 "reg_or_short_operand" "rI")))]
11790   ""
11791   "{cmp%I2|cmp<wd>%I2} %0,%1,%2"
11792   [(set_attr "type" "cmp")])
11793
11794 ;; If we are comparing a register for equality with a large constant,
11795 ;; we can do this with an XOR followed by a compare.  But this is profitable
11796 ;; only if the large constant is only used for the comparison (and in this
11797 ;; case we already have a register to reuse as scratch).
11798 ;;
11799 ;; For 64-bit registers, we could only do so if the constant's bit 15 is clear:
11800 ;; otherwise we'd need to XOR with FFFFFFFF????0000 which is not available.
11801
11802 (define_peephole2
11803   [(set (match_operand:SI 0 "register_operand")
11804         (match_operand:SI 1 "logical_const_operand" ""))
11805    (set (match_dup 0) (match_operator:SI 3 "boolean_or_operator"
11806                        [(match_dup 0)
11807                         (match_operand:SI 2 "logical_const_operand" "")]))
11808    (set (match_operand:CC 4 "cc_reg_operand" "")
11809         (compare:CC (match_operand:SI 5 "gpc_reg_operand" "")
11810                     (match_dup 0)))
11811    (set (pc)
11812         (if_then_else (match_operator 6 "equality_operator"
11813                        [(match_dup 4) (const_int 0)])
11814                       (match_operand 7 "" "")
11815                       (match_operand 8 "" "")))]
11816   "peep2_reg_dead_p (3, operands[0])
11817    && peep2_reg_dead_p (4, operands[4])"
11818  [(set (match_dup 0) (xor:SI (match_dup 5) (match_dup 9)))
11819   (set (match_dup 4) (compare:CC (match_dup 0) (match_dup 10)))
11820   (set (pc) (if_then_else (match_dup 6) (match_dup 7) (match_dup 8)))]
11821  
11822 {
11823   /* Get the constant we are comparing against, and see what it looks like
11824      when sign-extended from 16 to 32 bits.  Then see what constant we could
11825      XOR with SEXTC to get the sign-extended value.  */
11826   rtx cnst = simplify_const_binary_operation (GET_CODE (operands[3]),
11827                                               SImode,
11828                                               operands[1], operands[2]);
11829   HOST_WIDE_INT c = INTVAL (cnst);
11830   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
11831   HOST_WIDE_INT xorv = c ^ sextc;
11832
11833   operands[9] = GEN_INT (xorv);
11834   operands[10] = GEN_INT (sextc);
11835 })
11836
11837 (define_insn "*cmpsi_internal2"
11838   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11839         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11840                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
11841   ""
11842   "{cmpl%I2|cmplw%I2} %0,%1,%b2"
11843   [(set_attr "type" "cmp")])
11844
11845 (define_insn "*cmpdi_internal2"
11846   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11847         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
11848                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
11849   ""
11850   "cmpld%I2 %0,%1,%b2"
11851   [(set_attr "type" "cmp")])
11852
11853 ;; The following two insns don't exist as single insns, but if we provide
11854 ;; them, we can swap an add and compare, which will enable us to overlap more
11855 ;; of the required delay between a compare and branch.  We generate code for
11856 ;; them by splitting.
11857
11858 (define_insn ""
11859   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
11860         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11861                     (match_operand:SI 2 "short_cint_operand" "i")))
11862    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11863         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11864   ""
11865   "#"
11866   [(set_attr "length" "8")])
11867
11868 (define_insn ""
11869   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
11870         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11871                        (match_operand:SI 2 "u_short_cint_operand" "i")))
11872    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11873         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11874   ""
11875   "#"
11876   [(set_attr "length" "8")])
11877
11878 (define_split
11879   [(set (match_operand:CC 3 "cc_reg_operand" "")
11880         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11881                     (match_operand:SI 2 "short_cint_operand" "")))
11882    (set (match_operand:SI 0 "gpc_reg_operand" "")
11883         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11884   ""
11885   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
11886    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11887
11888 (define_split
11889   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
11890         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
11891                        (match_operand:SI 2 "u_short_cint_operand" "")))
11892    (set (match_operand:SI 0 "gpc_reg_operand" "")
11893         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11894   ""
11895   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
11896    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11897
11898 (define_insn "*cmpsf_internal1"
11899   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11900         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
11901                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
11902   "TARGET_HARD_FLOAT && TARGET_FPRS"
11903   "fcmpu %0,%1,%2"
11904   [(set_attr "type" "fpcompare")])
11905
11906 (define_insn "*cmpdf_internal1"
11907   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11908         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "f")
11909                       (match_operand:DF 2 "gpc_reg_operand" "f")))]
11910   "TARGET_HARD_FLOAT && TARGET_FPRS"
11911   "fcmpu %0,%1,%2"
11912   [(set_attr "type" "fpcompare")])
11913
11914 ;; Only need to compare second words if first words equal
11915 (define_insn "*cmptf_internal1"
11916   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11917         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11918                       (match_operand:TF 2 "gpc_reg_operand" "f")))]
11919   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
11920    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
11921   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
11922   [(set_attr "type" "fpcompare")
11923    (set_attr "length" "12")])
11924
11925 (define_insn_and_split "*cmptf_internal2"
11926   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11927         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11928                       (match_operand:TF 2 "gpc_reg_operand" "f")))
11929     (clobber (match_scratch:DF 3 "=f"))
11930     (clobber (match_scratch:DF 4 "=f"))
11931     (clobber (match_scratch:DF 5 "=f"))
11932     (clobber (match_scratch:DF 6 "=f"))
11933     (clobber (match_scratch:DF 7 "=f"))
11934     (clobber (match_scratch:DF 8 "=f"))
11935     (clobber (match_scratch:DF 9 "=f"))
11936     (clobber (match_scratch:DF 10 "=f"))]
11937   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
11938    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
11939   "#"
11940   "&& reload_completed"
11941   [(set (match_dup 3) (match_dup 13))
11942    (set (match_dup 4) (match_dup 14))
11943    (set (match_dup 9) (abs:DF (match_dup 5)))
11944    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
11945    (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
11946                            (label_ref (match_dup 11))
11947                            (pc)))
11948    (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
11949    (set (pc) (label_ref (match_dup 12)))
11950    (match_dup 11)
11951    (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
11952    (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
11953    (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
11954    (set (match_dup 0) (compare:CCFP (match_dup 7) (match_dup 4)))
11955    (match_dup 12)]
11956 {
11957   REAL_VALUE_TYPE rv;
11958   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
11959   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
11960
11961   operands[5] = simplify_gen_subreg (DFmode, operands[1], TFmode, hi_word);
11962   operands[6] = simplify_gen_subreg (DFmode, operands[1], TFmode, lo_word);
11963   operands[7] = simplify_gen_subreg (DFmode, operands[2], TFmode, hi_word);
11964   operands[8] = simplify_gen_subreg (DFmode, operands[2], TFmode, lo_word);
11965   operands[11] = gen_label_rtx ();
11966   operands[12] = gen_label_rtx ();
11967   real_inf (&rv);
11968   operands[13] = force_const_mem (DFmode,
11969                                   CONST_DOUBLE_FROM_REAL_VALUE (rv, DFmode));
11970   operands[14] = force_const_mem (DFmode,
11971                                   CONST_DOUBLE_FROM_REAL_VALUE (dconst0,
11972                                                                 DFmode));
11973   if (TARGET_TOC)
11974     {
11975       operands[13] = gen_const_mem (DFmode,
11976                                     create_TOC_reference (XEXP (operands[13], 0)));
11977       operands[14] = gen_const_mem (DFmode,
11978                                     create_TOC_reference (XEXP (operands[14], 0)));
11979       set_mem_alias_set (operands[13], get_TOC_alias_set ());
11980       set_mem_alias_set (operands[14], get_TOC_alias_set ());
11981     }
11982 })
11983 \f
11984 ;; Now we have the scc insns.  We can do some combinations because of the
11985 ;; way the machine works.
11986 ;;
11987 ;; Note that this is probably faster if we can put an insn between the
11988 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
11989 ;; cases the insns below which don't use an intermediate CR field will
11990 ;; be used instead.
11991 (define_insn ""
11992   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11993         (match_operator:SI 1 "scc_comparison_operator"
11994                            [(match_operand 2 "cc_reg_operand" "y")
11995                             (const_int 0)]))]
11996   ""
11997   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11998   [(set (attr "type")
11999      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
12000                 (const_string "mfcrf")
12001            ]
12002         (const_string "mfcr")))
12003    (set_attr "length" "8")])
12004
12005 ;; Same as above, but get the GT bit.
12006 (define_insn "move_from_CR_gt_bit"
12007   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12008         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
12009   "TARGET_E500"
12010   "mfcr %0\;{rlinm|rlwinm} %0,%0,%D1,31,31"
12011   [(set_attr "type" "mfcr")
12012    (set_attr "length" "8")])
12013
12014 ;; Same as above, but get the OV/ORDERED bit.
12015 (define_insn "move_from_CR_ov_bit"
12016   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12017         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_OV))]
12018   "TARGET_ISEL"
12019   "mfcr %0\;{rlinm|rlwinm} %0,%0,%t1,1"
12020   [(set_attr "type" "mfcr")
12021    (set_attr "length" "8")])
12022
12023 (define_insn ""
12024   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12025         (match_operator:DI 1 "scc_comparison_operator"
12026                            [(match_operand 2 "cc_reg_operand" "y")
12027                             (const_int 0)]))]
12028   "TARGET_POWERPC64"
12029   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
12030   [(set (attr "type")
12031      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
12032                 (const_string "mfcrf")
12033            ]
12034         (const_string "mfcr")))
12035    (set_attr "length" "8")])
12036
12037 (define_insn ""
12038   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12039         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
12040                                        [(match_operand 2 "cc_reg_operand" "y,y")
12041                                         (const_int 0)])
12042                     (const_int 0)))
12043    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
12044         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
12045   "TARGET_32BIT"
12046   "@
12047    mfcr %3%Q2\;{rlinm.|rlwinm.} %3,%3,%J1,1
12048    #"
12049   [(set_attr "type" "delayed_compare")
12050    (set_attr "length" "8,16")])
12051
12052 (define_split
12053   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12054         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
12055                                        [(match_operand 2 "cc_reg_operand" "")
12056                                         (const_int 0)])
12057                     (const_int 0)))
12058    (set (match_operand:SI 3 "gpc_reg_operand" "")
12059         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
12060   "TARGET_32BIT && reload_completed"
12061   [(set (match_dup 3)
12062         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
12063    (set (match_dup 0)
12064         (compare:CC (match_dup 3)
12065                     (const_int 0)))]
12066   "")
12067
12068 (define_insn ""
12069   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12070         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
12071                                       [(match_operand 2 "cc_reg_operand" "y")
12072                                        (const_int 0)])
12073                    (match_operand:SI 3 "const_int_operand" "n")))]
12074   ""
12075   "*
12076 {
12077   int is_bit = ccr_bit (operands[1], 1);
12078   int put_bit = 31 - (INTVAL (operands[3]) & 31);
12079   int count;
12080
12081   if (is_bit >= put_bit)
12082     count = is_bit - put_bit;
12083   else
12084     count = 32 - (put_bit - is_bit);
12085
12086   operands[4] = GEN_INT (count);
12087   operands[5] = GEN_INT (put_bit);
12088
12089   return \"mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
12090 }"
12091   [(set (attr "type")
12092      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
12093                 (const_string "mfcrf")
12094            ]
12095         (const_string "mfcr")))
12096    (set_attr "length" "8")])
12097
12098 (define_insn ""
12099   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12100         (compare:CC
12101          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
12102                                        [(match_operand 2 "cc_reg_operand" "y,y")
12103                                         (const_int 0)])
12104                     (match_operand:SI 3 "const_int_operand" "n,n"))
12105          (const_int 0)))
12106    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
12107         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
12108                    (match_dup 3)))]
12109   ""
12110   "*
12111 {
12112   int is_bit = ccr_bit (operands[1], 1);
12113   int put_bit = 31 - (INTVAL (operands[3]) & 31);
12114   int count;
12115
12116   /* Force split for non-cc0 compare.  */
12117   if (which_alternative == 1)
12118      return \"#\";
12119
12120   if (is_bit >= put_bit)
12121     count = is_bit - put_bit;
12122   else
12123     count = 32 - (put_bit - is_bit);
12124
12125   operands[5] = GEN_INT (count);
12126   operands[6] = GEN_INT (put_bit);
12127
12128   return \"mfcr %4%Q2\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
12129 }"
12130   [(set_attr "type" "delayed_compare")
12131    (set_attr "length" "8,16")])
12132
12133 (define_split
12134   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12135         (compare:CC
12136          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
12137                                        [(match_operand 2 "cc_reg_operand" "")
12138                                         (const_int 0)])
12139                     (match_operand:SI 3 "const_int_operand" ""))
12140          (const_int 0)))
12141    (set (match_operand:SI 4 "gpc_reg_operand" "")
12142         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
12143                    (match_dup 3)))]
12144   "reload_completed"
12145   [(set (match_dup 4)
12146         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
12147                    (match_dup 3)))
12148    (set (match_dup 0)
12149         (compare:CC (match_dup 4)
12150                     (const_int 0)))]
12151   "")
12152
12153 ;; There is a 3 cycle delay between consecutive mfcr instructions
12154 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
12155
12156 (define_peephole
12157   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12158         (match_operator:SI 1 "scc_comparison_operator"
12159                            [(match_operand 2 "cc_reg_operand" "y")
12160                             (const_int 0)]))
12161    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
12162         (match_operator:SI 4 "scc_comparison_operator"
12163                            [(match_operand 5 "cc_reg_operand" "y")
12164                             (const_int 0)]))]
12165   "REGNO (operands[2]) != REGNO (operands[5])"
12166   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
12167   [(set_attr "type" "mfcr")
12168    (set_attr "length" "12")])
12169
12170 (define_peephole
12171   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12172         (match_operator:DI 1 "scc_comparison_operator"
12173                            [(match_operand 2 "cc_reg_operand" "y")
12174                             (const_int 0)]))
12175    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
12176         (match_operator:DI 4 "scc_comparison_operator"
12177                            [(match_operand 5 "cc_reg_operand" "y")
12178                             (const_int 0)]))]
12179   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
12180   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
12181   [(set_attr "type" "mfcr")
12182    (set_attr "length" "12")])
12183
12184 ;; There are some scc insns that can be done directly, without a compare.
12185 ;; These are faster because they don't involve the communications between
12186 ;; the FXU and branch units.   In fact, we will be replacing all of the
12187 ;; integer scc insns here or in the portable methods in emit_store_flag.
12188 ;;
12189 ;; Also support (neg (scc ..)) since that construct is used to replace
12190 ;; branches, (plus (scc ..) ..) since that construct is common and
12191 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
12192 ;; cases where it is no more expensive than (neg (scc ..)).
12193
12194 ;; Have reload force a constant into a register for the simple insns that
12195 ;; otherwise won't accept constants.  We do this because it is faster than
12196 ;; the cmp/mfcr sequence we would otherwise generate.
12197
12198 (define_mode_attr scc_eq_op2 [(SI "rKLI")
12199                               (DI "rKJI")])
12200
12201 (define_insn_and_split "*eq<mode>"
12202   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
12203         (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
12204                 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))]
12205   "!TARGET_POWER"
12206   "#"
12207   "!TARGET_POWER"
12208   [(set (match_dup 0)
12209         (clz:GPR (match_dup 3)))
12210    (set (match_dup 0)
12211         (lshiftrt:GPR (match_dup 0) (match_dup 4)))]
12212   {
12213     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
12214       {
12215         /* Use output operand as intermediate.  */
12216         operands[3] = operands[0];
12217
12218         if (logical_operand (operands[2], <MODE>mode))
12219           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
12220                                   gen_rtx_XOR (<MODE>mode,
12221                                                operands[1], operands[2])));
12222         else
12223           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
12224                                   gen_rtx_PLUS (<MODE>mode, operands[1],
12225                                                 negate_rtx (<MODE>mode,
12226                                                             operands[2]))));
12227       }
12228     else
12229       operands[3] = operands[1];
12230
12231     operands[4] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
12232   })
12233
12234 (define_insn_and_split "*eq<mode>_compare"
12235   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
12236         (compare:CC
12237          (eq:P (match_operand:P 1 "gpc_reg_operand" "=r")
12238                (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))
12239          (const_int 0)))
12240    (set (match_operand:P 0 "gpc_reg_operand" "=r")
12241         (eq:P (match_dup 1) (match_dup 2)))]
12242   "!TARGET_POWER && optimize_size"
12243   "#"
12244   "!TARGET_POWER && optimize_size"
12245   [(set (match_dup 0)
12246         (clz:P (match_dup 4)))
12247    (parallel [(set (match_dup 3)
12248                    (compare:CC (lshiftrt:P (match_dup 0) (match_dup 5))
12249                                (const_int 0)))
12250               (set (match_dup 0)
12251                    (lshiftrt:P (match_dup 0) (match_dup 5)))])]
12252   {
12253     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
12254       {
12255         /* Use output operand as intermediate.  */
12256         operands[4] = operands[0];
12257
12258         if (logical_operand (operands[2], <MODE>mode))
12259           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
12260                                   gen_rtx_XOR (<MODE>mode,
12261                                                operands[1], operands[2])));
12262         else
12263           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
12264                                   gen_rtx_PLUS (<MODE>mode, operands[1],
12265                                                 negate_rtx (<MODE>mode,
12266                                                             operands[2]))));
12267       }
12268     else
12269       operands[4] = operands[1];
12270
12271     operands[5] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
12272   })
12273
12274 (define_insn "*eqsi_power"
12275   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
12276         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
12277                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I")))
12278    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
12279   "TARGET_POWER"
12280   "@
12281    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
12282    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
12283    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
12284    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
12285    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
12286   [(set_attr "type" "three,two,three,three,three")
12287    (set_attr "length" "12,8,12,12,12")])
12288
12289 ;; We have insns of the form shown by the first define_insn below.  If
12290 ;; there is something inside the comparison operation, we must split it.
12291 (define_split
12292   [(set (match_operand:SI 0 "gpc_reg_operand" "")
12293         (plus:SI (match_operator 1 "comparison_operator"
12294                                  [(match_operand:SI 2 "" "")
12295                                   (match_operand:SI 3
12296                                                     "reg_or_cint_operand" "")])
12297                  (match_operand:SI 4 "gpc_reg_operand" "")))
12298    (clobber (match_operand:SI 5 "register_operand" ""))]
12299   "! gpc_reg_operand (operands[2], SImode)"
12300   [(set (match_dup 5) (match_dup 2))
12301    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
12302                                (match_dup 4)))])
12303
12304 (define_insn "*plus_eqsi"
12305   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
12306         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
12307                         (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I"))
12308                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
12309   "TARGET_32BIT"
12310   "@
12311    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
12312    {sfi|subfic} %0,%1,0\;{aze|addze} %0,%3
12313    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
12314    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
12315    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
12316   [(set_attr "type" "three,two,three,three,three")
12317    (set_attr "length" "12,8,12,12,12")])
12318
12319 (define_insn "*compare_plus_eqsi"
12320   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
12321         (compare:CC
12322          (plus:SI
12323           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
12324                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
12325           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
12326          (const_int 0)))
12327    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
12328   "TARGET_32BIT && optimize_size"
12329   "@
12330    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12331    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
12332    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12333    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12334    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12335    #
12336    #
12337    #
12338    #
12339    #"
12340   [(set_attr "type" "compare")
12341    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
12342
12343 (define_split
12344   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12345         (compare:CC
12346          (plus:SI
12347           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
12348                  (match_operand:SI 2 "scc_eq_operand" ""))
12349           (match_operand:SI 3 "gpc_reg_operand" ""))
12350          (const_int 0)))
12351    (clobber (match_scratch:SI 4 ""))]
12352   "TARGET_32BIT && optimize_size && reload_completed"
12353   [(set (match_dup 4)
12354         (plus:SI (eq:SI (match_dup 1)
12355                  (match_dup 2))
12356           (match_dup 3)))
12357    (set (match_dup 0)
12358         (compare:CC (match_dup 4)
12359                     (const_int 0)))]
12360   "")
12361
12362 (define_insn "*plus_eqsi_compare"
12363   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
12364         (compare:CC
12365          (plus:SI
12366           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
12367                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
12368           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
12369          (const_int 0)))
12370    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
12371         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12372   "TARGET_32BIT && optimize_size"
12373   "@
12374    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12375    {sfi|subfic} %0,%1,0\;{aze.|addze.} %0,%3
12376    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12377    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12378    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12379    #
12380    #
12381    #
12382    #
12383    #"
12384   [(set_attr "type" "compare")
12385    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
12386
12387 (define_split
12388   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12389         (compare:CC
12390          (plus:SI
12391           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
12392                  (match_operand:SI 2 "scc_eq_operand" ""))
12393           (match_operand:SI 3 "gpc_reg_operand" ""))
12394          (const_int 0)))
12395    (set (match_operand:SI 0 "gpc_reg_operand" "")
12396         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12397   "TARGET_32BIT && optimize_size && reload_completed"
12398   [(set (match_dup 0)
12399         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12400    (set (match_dup 4)
12401         (compare:CC (match_dup 0)
12402                     (const_int 0)))]
12403   "")
12404
12405 (define_insn "*neg_eq0<mode>"
12406   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12407         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "r")
12408                      (const_int 0))))]
12409   ""
12410   "{ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0"
12411   [(set_attr "type" "two")
12412    (set_attr "length" "8")])
12413
12414 (define_insn_and_split "*neg_eq<mode>"
12415   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12416         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "%r")
12417                      (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))]
12418   ""
12419   "#"
12420   ""
12421   [(set (match_dup 0) (neg:P (eq:P (match_dup 3) (const_int 0))))]
12422   {
12423     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
12424       {
12425         /* Use output operand as intermediate.  */
12426         operands[3] = operands[0];
12427
12428         if (logical_operand (operands[2], <MODE>mode))
12429           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
12430                                   gen_rtx_XOR (<MODE>mode,
12431                                                operands[1], operands[2])));
12432         else
12433           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
12434                                   gen_rtx_PLUS (<MODE>mode, operands[1],
12435                                                 negate_rtx (<MODE>mode,
12436                                                             operands[2]))));
12437       }
12438     else
12439       operands[3] = operands[1];
12440   })
12441
12442 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
12443 ;; since it nabs/sr is just as fast.
12444 (define_insn "*ne0si"
12445   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12446         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
12447                      (const_int 31)))
12448    (clobber (match_scratch:SI 2 "=&r"))]
12449   "! TARGET_POWER && TARGET_32BIT && !TARGET_ISEL"
12450   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
12451   [(set_attr "type" "two")
12452    (set_attr "length" "8")])
12453
12454 (define_insn "*ne0di"
12455   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12456         (lshiftrt:DI (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
12457                      (const_int 63)))
12458    (clobber (match_scratch:DI 2 "=&r"))]
12459   "TARGET_64BIT"
12460   "addic %2,%1,-1\;subfe %0,%2,%1"
12461   [(set_attr "type" "two")
12462    (set_attr "length" "8")])
12463
12464 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
12465 (define_insn "*plus_ne0si"
12466   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12467         (plus:SI (lshiftrt:SI
12468                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
12469                   (const_int 31))
12470                  (match_operand:SI 2 "gpc_reg_operand" "r")))
12471    (clobber (match_scratch:SI 3 "=&r"))]
12472   "TARGET_32BIT"
12473   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
12474   [(set_attr "type" "two")
12475    (set_attr "length" "8")])
12476
12477 (define_insn "*plus_ne0di"
12478   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12479         (plus:DI (lshiftrt:DI
12480                   (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
12481                   (const_int 63))
12482                  (match_operand:DI 2 "gpc_reg_operand" "r")))
12483    (clobber (match_scratch:DI 3 "=&r"))]
12484   "TARGET_64BIT"
12485   "addic %3,%1,-1\;addze %0,%2"
12486   [(set_attr "type" "two")
12487    (set_attr "length" "8")])
12488
12489 (define_insn "*compare_plus_ne0si"
12490   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12491         (compare:CC
12492          (plus:SI (lshiftrt:SI
12493                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
12494                    (const_int 31))
12495                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
12496          (const_int 0)))
12497    (clobber (match_scratch:SI 3 "=&r,&r"))
12498    (clobber (match_scratch:SI 4 "=X,&r"))]
12499   "TARGET_32BIT"
12500   "@
12501    {ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2
12502    #"
12503   [(set_attr "type" "compare")
12504    (set_attr "length" "8,12")])
12505
12506 (define_split
12507   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12508         (compare:CC
12509          (plus:SI (lshiftrt:SI
12510                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
12511                    (const_int 31))
12512                   (match_operand:SI 2 "gpc_reg_operand" ""))
12513          (const_int 0)))
12514    (clobber (match_scratch:SI 3 ""))
12515    (clobber (match_scratch:SI 4 ""))]
12516   "TARGET_32BIT && reload_completed"
12517   [(parallel [(set (match_dup 3)
12518                    (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1)))
12519                                          (const_int 31))
12520                             (match_dup 2)))
12521               (clobber (match_dup 4))])
12522    (set (match_dup 0)
12523         (compare:CC (match_dup 3)
12524                     (const_int 0)))]
12525   "")
12526
12527 (define_insn "*compare_plus_ne0di"
12528   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12529         (compare:CC
12530          (plus:DI (lshiftrt:DI
12531                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
12532                    (const_int 63))
12533                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
12534          (const_int 0)))
12535    (clobber (match_scratch:DI 3 "=&r,&r"))]
12536   "TARGET_64BIT"
12537   "@
12538    addic %3,%1,-1\;addze. %3,%2
12539    #"
12540   [(set_attr "type" "compare")
12541    (set_attr "length" "8,12")])
12542
12543 (define_split
12544   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12545         (compare:CC
12546          (plus:DI (lshiftrt:DI
12547                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
12548                    (const_int 63))
12549                   (match_operand:DI 2 "gpc_reg_operand" ""))
12550          (const_int 0)))
12551    (clobber (match_scratch:DI 3 ""))]
12552   "TARGET_64BIT && reload_completed"
12553   [(set (match_dup 3)
12554         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1)))
12555                    (const_int 63))
12556                   (match_dup 2)))
12557    (set (match_dup 0)
12558         (compare:CC (match_dup 3)
12559                     (const_int 0)))]
12560   "")
12561
12562 (define_insn "*plus_ne0si_compare"
12563   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12564         (compare:CC
12565          (plus:SI (lshiftrt:SI
12566                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
12567                    (const_int 31))
12568                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
12569          (const_int 0)))
12570    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12571         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
12572                  (match_dup 2)))
12573    (clobber (match_scratch:SI 3 "=&r,&r"))]
12574   "TARGET_32BIT"
12575   "@
12576    {ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2
12577    #"
12578   [(set_attr "type" "compare")
12579    (set_attr "length" "8,12")])
12580
12581 (define_split
12582   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12583         (compare:CC
12584          (plus:SI (lshiftrt:SI
12585                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
12586                    (const_int 31))
12587                   (match_operand:SI 2 "gpc_reg_operand" ""))
12588          (const_int 0)))
12589    (set (match_operand:SI 0 "gpc_reg_operand" "")
12590         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
12591                  (match_dup 2)))
12592    (clobber (match_scratch:SI 3 ""))]
12593   "TARGET_32BIT && reload_completed"
12594   [(parallel [(set (match_dup 0)
12595         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
12596                  (match_dup 2)))
12597    (clobber (match_dup 3))])
12598    (set (match_dup 4)
12599         (compare:CC (match_dup 0)
12600                     (const_int 0)))]
12601   "")
12602
12603 (define_insn "*plus_ne0di_compare"
12604   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12605         (compare:CC
12606          (plus:DI (lshiftrt:DI
12607                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
12608                    (const_int 63))
12609                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
12610          (const_int 0)))
12611    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12612         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
12613                  (match_dup 2)))
12614    (clobber (match_scratch:DI 3 "=&r,&r"))]
12615   "TARGET_64BIT"
12616   "@
12617    addic %3,%1,-1\;addze. %0,%2
12618    #"
12619   [(set_attr "type" "compare")
12620    (set_attr "length" "8,12")])
12621
12622 (define_split
12623   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12624         (compare:CC
12625          (plus:DI (lshiftrt:DI
12626                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
12627                    (const_int 63))
12628                   (match_operand:DI 2 "gpc_reg_operand" ""))
12629          (const_int 0)))
12630    (set (match_operand:DI 0 "gpc_reg_operand" "")
12631         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
12632                  (match_dup 2)))
12633    (clobber (match_scratch:DI 3 ""))]
12634   "TARGET_64BIT && reload_completed"
12635   [(parallel [(set (match_dup 0)
12636         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
12637                  (match_dup 2)))
12638    (clobber (match_dup 3))])
12639    (set (match_dup 4)
12640         (compare:CC (match_dup 0)
12641                     (const_int 0)))]
12642   "")
12643
12644 (define_insn ""
12645   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12646         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12647                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
12648    (clobber (match_scratch:SI 3 "=r,X"))]
12649   "TARGET_POWER"
12650   "@
12651    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
12652    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
12653   [(set_attr "length" "12")])
12654
12655 (define_insn ""
12656   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12657         (compare:CC
12658          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12659                 (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12660          (const_int 0)))
12661    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12662         (le:SI (match_dup 1) (match_dup 2)))
12663    (clobber (match_scratch:SI 3 "=r,X,r,X"))]
12664   "TARGET_POWER"
12665   "@
12666    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
12667    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31
12668    #
12669    #"
12670   [(set_attr "type" "compare,delayed_compare,compare,delayed_compare")
12671    (set_attr "length" "12,12,16,16")])
12672
12673 (define_split
12674   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12675         (compare:CC
12676          (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12677                 (match_operand:SI 2 "reg_or_short_operand" ""))
12678          (const_int 0)))
12679    (set (match_operand:SI 0 "gpc_reg_operand" "")
12680         (le:SI (match_dup 1) (match_dup 2)))
12681    (clobber (match_scratch:SI 3 ""))]
12682   "TARGET_POWER && reload_completed"
12683   [(parallel [(set (match_dup 0)
12684         (le:SI (match_dup 1) (match_dup 2)))
12685    (clobber (match_dup 3))])
12686    (set (match_dup 4)
12687         (compare:CC (match_dup 0)
12688                     (const_int 0)))]
12689   "")
12690
12691 (define_insn ""
12692   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12693         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12694                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
12695                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12696   "TARGET_POWER"
12697   "@
12698    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
12699    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze|addze} %0,%3"
12700   [(set_attr "length" "12")])
12701
12702 (define_insn ""
12703   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12704         (compare:CC
12705          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12706                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12707                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12708          (const_int 0)))
12709    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12710   "TARGET_POWER"
12711   "@
12712    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12713    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3
12714    #
12715    #"
12716   [(set_attr "type" "compare")
12717    (set_attr "length" "12,12,16,16")])
12718
12719 (define_split
12720   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12721         (compare:CC
12722          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12723                          (match_operand:SI 2 "reg_or_short_operand" ""))
12724                   (match_operand:SI 3 "gpc_reg_operand" ""))
12725          (const_int 0)))
12726    (clobber (match_scratch:SI 4 ""))]
12727   "TARGET_POWER && reload_completed"
12728   [(set (match_dup 4)
12729         (plus:SI (le:SI (match_dup 1) (match_dup 2))
12730                  (match_dup 3)))
12731    (set (match_dup 0)
12732         (compare:CC (match_dup 4)
12733                     (const_int 0)))]
12734   "")
12735
12736 (define_insn ""
12737   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12738         (compare:CC
12739          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12740                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12741                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12742          (const_int 0)))
12743    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12744         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12745   "TARGET_POWER"
12746   "@
12747    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12748    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze.|addze.} %0,%3
12749    #
12750    #"
12751   [(set_attr "type" "compare")
12752    (set_attr "length" "12,12,16,16")])
12753
12754 (define_split
12755   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12756         (compare:CC
12757          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12758                          (match_operand:SI 2 "reg_or_short_operand" ""))
12759                   (match_operand:SI 3 "gpc_reg_operand" ""))
12760          (const_int 0)))
12761    (set (match_operand:SI 0 "gpc_reg_operand" "")
12762         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12763   "TARGET_POWER && reload_completed"
12764   [(set (match_dup 0)
12765         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12766    (set (match_dup 4)
12767         (compare:CC (match_dup 0)
12768                     (const_int 0)))]
12769   "")
12770
12771 (define_insn ""
12772   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12773         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12774                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
12775   "TARGET_POWER"
12776   "@
12777    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
12778    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
12779   [(set_attr "length" "12")])
12780
12781 (define_insn "*leu<mode>"
12782   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12783         (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12784                (match_operand:P 2 "reg_or_short_operand" "rI")))]
12785   ""
12786   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12787   [(set_attr "type" "three")
12788    (set_attr "length" "12")])
12789
12790 (define_insn "*leu<mode>_compare"
12791   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12792         (compare:CC
12793          (leu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12794                 (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
12795          (const_int 0)))
12796    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12797         (leu:P (match_dup 1) (match_dup 2)))]
12798   ""
12799   "@
12800    {sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12801    #"
12802   [(set_attr "type" "compare")
12803    (set_attr "length" "12,16")])
12804
12805 (define_split
12806   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12807         (compare:CC
12808          (leu:P (match_operand:P 1 "gpc_reg_operand" "")
12809                 (match_operand:P 2 "reg_or_short_operand" ""))
12810          (const_int 0)))
12811    (set (match_operand:P 0 "gpc_reg_operand" "")
12812         (leu:P (match_dup 1) (match_dup 2)))]
12813   "reload_completed"
12814   [(set (match_dup 0)
12815         (leu:P (match_dup 1) (match_dup 2)))
12816    (set (match_dup 3)
12817         (compare:CC (match_dup 0)
12818                     (const_int 0)))]
12819   "")
12820
12821 (define_insn "*plus_leu<mode>"
12822   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
12823         (plus:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12824                        (match_operand:P 2 "reg_or_short_operand" "rI"))
12825                 (match_operand:P 3 "gpc_reg_operand" "r")))]
12826   ""
12827   "{sf%I2|subf%I2c} %0,%1,%2\;{aze|addze} %0,%3"
12828   [(set_attr "type" "two")
12829    (set_attr "length" "8")])
12830
12831 (define_insn ""
12832   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12833         (compare:CC
12834          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12835                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12836                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12837          (const_int 0)))
12838    (clobber (match_scratch:SI 4 "=&r,&r"))]
12839   "TARGET_32BIT"
12840   "@
12841    {sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3
12842    #"
12843   [(set_attr "type" "compare")
12844    (set_attr "length" "8,12")])
12845
12846 (define_split
12847   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12848         (compare:CC
12849          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12850                           (match_operand:SI 2 "reg_or_short_operand" ""))
12851                   (match_operand:SI 3 "gpc_reg_operand" ""))
12852          (const_int 0)))
12853    (clobber (match_scratch:SI 4 ""))]
12854   "TARGET_32BIT && reload_completed"
12855   [(set (match_dup 4)
12856         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
12857                   (match_dup 3)))
12858    (set (match_dup 0)
12859         (compare:CC (match_dup 4)
12860                     (const_int 0)))]
12861   "")
12862
12863 (define_insn ""
12864   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12865         (compare:CC
12866          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12867                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12868                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12869          (const_int 0)))
12870    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12871         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12872   "TARGET_32BIT"
12873   "@
12874    {sf%I2|subf%I2c} %0,%1,%2\;{aze.|addze.} %0,%3
12875    #"
12876   [(set_attr "type" "compare")
12877    (set_attr "length" "8,12")])
12878
12879 (define_split
12880   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12881         (compare:CC
12882          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12883                           (match_operand:SI 2 "reg_or_short_operand" ""))
12884                   (match_operand:SI 3 "gpc_reg_operand" ""))
12885          (const_int 0)))
12886    (set (match_operand:SI 0 "gpc_reg_operand" "")
12887         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12888   "TARGET_32BIT && reload_completed"
12889   [(set (match_dup 0)
12890         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12891    (set (match_dup 4)
12892         (compare:CC (match_dup 0)
12893                     (const_int 0)))]
12894   "")
12895
12896 (define_insn "*neg_leu<mode>"
12897   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12898         (neg:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12899                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
12900   ""
12901   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
12902    [(set_attr "type" "three")
12903     (set_attr "length" "12")])
12904
12905 (define_insn "*and_neg_leu<mode>"
12906   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
12907         (and:P (neg:P
12908                  (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12909                         (match_operand:P 2 "reg_or_short_operand" "rI")))
12910                 (match_operand:P 3 "gpc_reg_operand" "r")))]
12911   ""
12912   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12913   [(set_attr "type" "three")
12914    (set_attr "length" "12")])
12915
12916 (define_insn ""
12917   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12918         (compare:CC
12919          (and:SI (neg:SI
12920                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12921                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12922                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12923          (const_int 0)))
12924    (clobber (match_scratch:SI 4 "=&r,&r"))]
12925   "TARGET_32BIT"
12926   "@
12927    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12928    #"
12929   [(set_attr "type" "compare")
12930    (set_attr "length" "12,16")])
12931
12932 (define_split
12933   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12934         (compare:CC
12935          (and:SI (neg:SI
12936                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12937                           (match_operand:SI 2 "reg_or_short_operand" "")))
12938                  (match_operand:SI 3 "gpc_reg_operand" ""))
12939          (const_int 0)))
12940    (clobber (match_scratch:SI 4 ""))]
12941   "TARGET_32BIT && reload_completed"
12942   [(set (match_dup 4)
12943         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12944                 (match_dup 3)))
12945    (set (match_dup 0)
12946         (compare:CC (match_dup 4)
12947                     (const_int 0)))]
12948   "")
12949
12950 (define_insn ""
12951   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12952         (compare:CC
12953          (and:SI (neg:SI
12954                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12955                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12956                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12957          (const_int 0)))
12958    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12959         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12960   "TARGET_32BIT"
12961   "@
12962    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12963    #"
12964   [(set_attr "type" "compare")
12965    (set_attr "length" "12,16")])
12966
12967 (define_split
12968   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12969         (compare:CC
12970          (and:SI (neg:SI
12971                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12972                           (match_operand:SI 2 "reg_or_short_operand" "")))
12973                  (match_operand:SI 3 "gpc_reg_operand" ""))
12974          (const_int 0)))
12975    (set (match_operand:SI 0 "gpc_reg_operand" "")
12976         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12977   "TARGET_32BIT && reload_completed"
12978   [(set (match_dup 0)
12979         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12980                 (match_dup 3)))
12981    (set (match_dup 4)
12982         (compare:CC (match_dup 0)
12983                     (const_int 0)))]
12984   "")
12985
12986 (define_insn ""
12987   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12988         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12989                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12990   "TARGET_POWER"
12991   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
12992    [(set_attr "length" "12")])
12993
12994 (define_insn ""
12995   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12996         (compare:CC
12997          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12998                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12999          (const_int 0)))
13000    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13001         (lt:SI (match_dup 1) (match_dup 2)))]
13002   "TARGET_POWER"
13003   "@
13004    doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
13005    #"
13006   [(set_attr "type" "delayed_compare")
13007    (set_attr "length" "12,16")])
13008
13009 (define_split
13010   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13011         (compare:CC
13012          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13013                 (match_operand:SI 2 "reg_or_short_operand" ""))
13014          (const_int 0)))
13015    (set (match_operand:SI 0 "gpc_reg_operand" "")
13016         (lt:SI (match_dup 1) (match_dup 2)))]
13017   "TARGET_POWER && reload_completed"
13018   [(set (match_dup 0)
13019         (lt:SI (match_dup 1) (match_dup 2)))
13020    (set (match_dup 3)
13021         (compare:CC (match_dup 0)
13022                     (const_int 0)))]
13023   "")
13024
13025 (define_insn ""
13026   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13027         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13028                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
13029                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
13030   "TARGET_POWER"
13031   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
13032   [(set_attr "length" "12")])
13033
13034 (define_insn ""
13035   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13036         (compare:CC
13037          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13038                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13039                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13040          (const_int 0)))
13041    (clobber (match_scratch:SI 4 "=&r,&r"))]
13042   "TARGET_POWER"
13043   "@
13044    doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
13045    #"
13046   [(set_attr "type" "compare")
13047    (set_attr "length" "12,16")])
13048
13049 (define_split
13050   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13051         (compare:CC
13052          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13053                          (match_operand:SI 2 "reg_or_short_operand" ""))
13054                   (match_operand:SI 3 "gpc_reg_operand" ""))
13055          (const_int 0)))
13056    (clobber (match_scratch:SI 4 ""))]
13057   "TARGET_POWER && reload_completed"
13058   [(set (match_dup 4)
13059         (plus:SI (lt:SI (match_dup 1) (match_dup 2))
13060                  (match_dup 3)))
13061    (set (match_dup 0)
13062         (compare:CC (match_dup 4)
13063                     (const_int 0)))]
13064   "")
13065
13066 (define_insn ""
13067   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13068         (compare:CC
13069          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13070                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13071                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13072          (const_int 0)))
13073    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13074         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13075   "TARGET_POWER"
13076   "@
13077    doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
13078    #"
13079   [(set_attr "type" "compare")
13080    (set_attr "length" "12,16")])
13081
13082 (define_split
13083   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13084         (compare:CC
13085          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13086                          (match_operand:SI 2 "reg_or_short_operand" ""))
13087                   (match_operand:SI 3 "gpc_reg_operand" ""))
13088          (const_int 0)))
13089    (set (match_operand:SI 0 "gpc_reg_operand" "")
13090         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13091   "TARGET_POWER && reload_completed"
13092   [(set (match_dup 0)
13093         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13094    (set (match_dup 4)
13095         (compare:CC (match_dup 0)
13096                     (const_int 0)))]
13097   "")
13098
13099 (define_insn ""
13100   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13101         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13102                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
13103   "TARGET_POWER"
13104   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
13105   [(set_attr "length" "12")])
13106
13107 (define_insn_and_split "*ltu<mode>"
13108   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13109         (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13110                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
13111   ""
13112   "#"
13113   ""
13114   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13115    (set (match_dup 0) (neg:P (match_dup 0)))]
13116   "")
13117
13118 (define_insn_and_split "*ltu<mode>_compare"
13119   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
13120         (compare:CC
13121          (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13122                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
13123          (const_int 0)))
13124    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
13125         (ltu:P (match_dup 1) (match_dup 2)))]
13126   ""
13127   "#"
13128   ""
13129   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13130    (parallel [(set (match_dup 3)
13131                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
13132               (set (match_dup 0) (neg:P (match_dup 0)))])]
13133   "")
13134
13135 (define_insn_and_split "*plus_ltu<mode>"
13136   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,r")
13137         (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13138                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
13139                 (match_operand:P 3 "reg_or_short_operand" "rI,rI")))]
13140   ""
13141   "#"
13142   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13143   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13144    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
13145   "")
13146
13147 (define_insn_and_split "*plus_ltu<mode>_compare"
13148   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13149         (compare:CC
13150          (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13151                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
13152                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
13153          (const_int 0)))
13154    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13155         (plus:P (ltu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
13156   ""
13157   "#"
13158   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13159   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13160    (parallel [(set (match_dup 4)
13161                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
13162                                (const_int 0)))
13163               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
13164   "")
13165
13166 (define_insn "*neg_ltu<mode>"
13167   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13168         (neg:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13169                       (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))))]
13170   ""
13171   "@
13172    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
13173    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
13174   [(set_attr "type" "two")
13175    (set_attr "length" "8")])
13176
13177 (define_insn ""
13178   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13179         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13180                (match_operand:SI 2 "reg_or_short_operand" "rI")))
13181    (clobber (match_scratch:SI 3 "=r"))]
13182   "TARGET_POWER"
13183   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
13184    [(set_attr "length" "12")])
13185
13186 (define_insn ""
13187   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13188         (compare:CC
13189          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13190                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13191          (const_int 0)))
13192    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13193         (ge:SI (match_dup 1) (match_dup 2)))
13194    (clobber (match_scratch:SI 3 "=r,r"))]
13195   "TARGET_POWER"
13196   "@
13197    doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
13198    #"
13199   [(set_attr "type" "compare")
13200    (set_attr "length" "12,16")])
13201
13202 (define_split
13203   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13204         (compare:CC
13205          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
13206                 (match_operand:SI 2 "reg_or_short_operand" ""))
13207          (const_int 0)))
13208    (set (match_operand:SI 0 "gpc_reg_operand" "")
13209         (ge:SI (match_dup 1) (match_dup 2)))
13210    (clobber (match_scratch:SI 3 ""))]
13211   "TARGET_POWER && reload_completed"
13212   [(parallel [(set (match_dup 0)
13213                    (ge:SI (match_dup 1) (match_dup 2)))
13214               (clobber (match_dup 3))])
13215    (set (match_dup 4)
13216         (compare:CC (match_dup 0)
13217                     (const_int 0)))]
13218   "")
13219
13220 (define_insn ""
13221   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13222         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13223                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
13224                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
13225   "TARGET_POWER"
13226   "doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
13227   [(set_attr "length" "12")])
13228
13229 (define_insn ""
13230   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13231         (compare:CC
13232          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13233                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13234                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13235          (const_int 0)))
13236    (clobber (match_scratch:SI 4 "=&r,&r"))]
13237   "TARGET_POWER"
13238   "@
13239    doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13240    #"
13241   [(set_attr "type" "compare")
13242    (set_attr "length" "12,16")])
13243
13244 (define_split
13245   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13246         (compare:CC
13247          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
13248                          (match_operand:SI 2 "reg_or_short_operand" ""))
13249                   (match_operand:SI 3 "gpc_reg_operand" ""))
13250          (const_int 0)))
13251    (clobber (match_scratch:SI 4 ""))]
13252   "TARGET_POWER && reload_completed"
13253   [(set (match_dup 4)
13254         (plus:SI (ge:SI (match_dup 1) (match_dup 2))
13255                  (match_dup 3)))
13256    (set (match_dup 0)
13257         (compare:CC (match_dup 4)
13258                     (const_int 0)))]
13259   "")
13260
13261 (define_insn ""
13262   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13263         (compare:CC
13264          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13265                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13266                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13267          (const_int 0)))
13268    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13269         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13270   "TARGET_POWER"
13271   "@
13272    doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13273    #"
13274   [(set_attr "type" "compare")
13275    (set_attr "length" "12,16")])
13276
13277 (define_split
13278   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13279         (compare:CC
13280          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
13281                          (match_operand:SI 2 "reg_or_short_operand" ""))
13282                   (match_operand:SI 3 "gpc_reg_operand" ""))
13283          (const_int 0)))
13284    (set (match_operand:SI 0 "gpc_reg_operand" "")
13285         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13286   "TARGET_POWER && reload_completed"
13287   [(set (match_dup 0)
13288         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13289    (set (match_dup 4)
13290         (compare:CC (match_dup 0)
13291                     (const_int 0)))]
13292   "")
13293
13294 (define_insn ""
13295   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13296         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13297                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
13298   "TARGET_POWER"
13299   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
13300   [(set_attr "length" "12")])
13301
13302 (define_insn "*geu<mode>"
13303   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13304         (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13305                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
13306   ""
13307   "@
13308    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
13309    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
13310   [(set_attr "type" "three")
13311    (set_attr "length" "12")])
13312
13313 (define_insn "*geu<mode>_compare"
13314   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
13315         (compare:CC
13316          (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13317                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
13318          (const_int 0)))
13319    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
13320         (geu:P (match_dup 1) (match_dup 2)))]
13321   ""
13322   "@
13323    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
13324    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
13325    #
13326    #"
13327   [(set_attr "type" "compare")
13328    (set_attr "length" "12,12,16,16")])
13329
13330 (define_split
13331   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13332         (compare:CC
13333          (geu:P (match_operand:P 1 "gpc_reg_operand" "")
13334                 (match_operand:P 2 "reg_or_neg_short_operand" ""))
13335          (const_int 0)))
13336    (set (match_operand:P 0 "gpc_reg_operand" "")
13337         (geu:P (match_dup 1) (match_dup 2)))]
13338   "reload_completed"
13339   [(set (match_dup 0)
13340         (geu:P (match_dup 1) (match_dup 2)))
13341    (set (match_dup 3)
13342         (compare:CC (match_dup 0)
13343                     (const_int 0)))]
13344   "")
13345
13346 (define_insn "*plus_geu<mode>"
13347   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
13348         (plus:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13349                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
13350                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
13351   ""
13352   "@
13353    {sf|subfc} %0,%2,%1\;{aze|addze} %0,%3
13354    {ai|addic} %0,%1,%n2\;{aze|addze} %0,%3"
13355   [(set_attr "type" "two")
13356    (set_attr "length" "8")])
13357
13358 (define_insn ""
13359   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13360         (compare:CC
13361          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13362                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
13363                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13364          (const_int 0)))
13365    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13366   "TARGET_32BIT"
13367   "@
13368    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
13369    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3
13370    #
13371    #"
13372   [(set_attr "type" "compare")
13373    (set_attr "length" "8,8,12,12")])
13374
13375 (define_split
13376   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13377         (compare:CC
13378          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13379                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
13380                   (match_operand:SI 3 "gpc_reg_operand" ""))
13381          (const_int 0)))
13382    (clobber (match_scratch:SI 4 ""))]
13383   "TARGET_32BIT && reload_completed"
13384   [(set (match_dup 4)
13385         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
13386                   (match_dup 3)))
13387    (set (match_dup 0)
13388         (compare:CC (match_dup 4)
13389                     (const_int 0)))]
13390   "")
13391
13392 (define_insn ""
13393   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13394         (compare:CC
13395          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13396                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
13397                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13398          (const_int 0)))
13399    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13400         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13401   "TARGET_32BIT"
13402   "@
13403    {sf|subfc} %0,%2,%1\;{aze.|addze.} %0,%3
13404    {ai|addic} %0,%1,%n2\;{aze.|addze.} %0,%3
13405    #
13406    #"
13407   [(set_attr "type" "compare")
13408    (set_attr "length" "8,8,12,12")])
13409
13410 (define_split
13411   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13412         (compare:CC
13413          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13414                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
13415                   (match_operand:SI 3 "gpc_reg_operand" ""))
13416          (const_int 0)))
13417    (set (match_operand:SI 0 "gpc_reg_operand" "")
13418         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13419   "TARGET_32BIT && reload_completed"
13420   [(set (match_dup 0)
13421         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13422    (set (match_dup 4)
13423         (compare:CC (match_dup 0)
13424                     (const_int 0)))]
13425   "")
13426
13427 (define_insn "*neg_geu<mode>"
13428   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13429         (neg:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13430                       (match_operand:P 2 "reg_or_short_operand" "r,I"))))]
13431   ""
13432   "@
13433    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
13434    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
13435   [(set_attr "type" "three")
13436    (set_attr "length" "12")])
13437
13438 (define_insn "*and_neg_geu<mode>"
13439   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
13440         (and:P (neg:P
13441                  (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13442                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))
13443                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
13444   ""
13445   "@
13446    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0
13447    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
13448   [(set_attr "type" "three")
13449    (set_attr "length" "12")])
13450
13451 (define_insn ""
13452   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13453         (compare:CC
13454          (and:SI (neg:SI
13455                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13456                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
13457                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13458          (const_int 0)))
13459    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13460   "TARGET_32BIT"
13461   "@
13462    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
13463    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
13464    #
13465    #"
13466   [(set_attr "type" "compare")
13467    (set_attr "length" "12,12,16,16")])
13468
13469 (define_split
13470   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13471         (compare:CC
13472          (and:SI (neg:SI
13473                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13474                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
13475                  (match_operand:SI 3 "gpc_reg_operand" ""))
13476          (const_int 0)))
13477    (clobber (match_scratch:SI 4 ""))]
13478   "TARGET_32BIT && reload_completed"
13479   [(set (match_dup 4)
13480         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
13481                 (match_dup 3)))
13482    (set (match_dup 0)
13483         (compare:CC (match_dup 4)
13484                     (const_int 0)))]
13485   "")
13486
13487 (define_insn ""
13488   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13489         (compare:CC
13490          (and:SI (neg:SI
13491                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13492                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
13493                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13494          (const_int 0)))
13495    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13496         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13497   "TARGET_32BIT"
13498   "@
13499    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
13500    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
13501    #
13502    #"
13503   [(set_attr "type" "compare")
13504    (set_attr "length" "12,12,16,16")])
13505
13506 (define_split
13507   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13508         (compare:CC
13509          (and:SI (neg:SI
13510                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13511                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
13512                  (match_operand:SI 3 "gpc_reg_operand" ""))
13513          (const_int 0)))
13514    (set (match_operand:SI 0 "gpc_reg_operand" "")
13515         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13516   "TARGET_32BIT && reload_completed"
13517   [(set (match_dup 0)
13518         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
13519    (set (match_dup 4)
13520         (compare:CC (match_dup 0)
13521                     (const_int 0)))]
13522   "")
13523
13524 (define_insn ""
13525   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13526         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13527                (match_operand:SI 2 "reg_or_short_operand" "r")))]
13528   "TARGET_POWER"
13529   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
13530   [(set_attr "length" "12")])
13531
13532 (define_insn ""
13533   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13534         (compare:CC
13535          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13536                 (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13537          (const_int 0)))
13538    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13539         (gt:SI (match_dup 1) (match_dup 2)))]
13540   "TARGET_POWER"
13541   "@
13542    doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
13543    #"
13544   [(set_attr "type" "delayed_compare")
13545    (set_attr "length" "12,16")])
13546
13547 (define_split
13548   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13549         (compare:CC
13550          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13551                 (match_operand:SI 2 "reg_or_short_operand" ""))
13552          (const_int 0)))
13553    (set (match_operand:SI 0 "gpc_reg_operand" "")
13554         (gt:SI (match_dup 1) (match_dup 2)))]
13555   "TARGET_POWER && reload_completed"
13556   [(set (match_dup 0)
13557         (gt:SI (match_dup 1) (match_dup 2)))
13558    (set (match_dup 3)
13559         (compare:CC (match_dup 0)
13560                     (const_int 0)))]
13561   "")
13562
13563 (define_insn "*plus_gt0<mode>"
13564   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13565         (plus:P (gt:P (match_operand:P 1 "gpc_reg_operand" "r")
13566                       (const_int 0))
13567                  (match_operand:P 2 "gpc_reg_operand" "r")))]
13568   ""
13569   "{a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze|addze} %0,%2"
13570   [(set_attr "type" "three")
13571    (set_attr "length" "12")])
13572
13573 (define_insn ""
13574   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13575         (compare:CC
13576          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13577                          (const_int 0))
13578                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13579          (const_int 0)))
13580    (clobber (match_scratch:SI 3 "=&r,&r"))]
13581   "TARGET_32BIT"
13582   "@
13583    {a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2
13584    #"
13585   [(set_attr "type" "compare")
13586    (set_attr "length" "12,16")])
13587
13588 (define_split
13589   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13590         (compare:CC
13591          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13592                          (const_int 0))
13593                   (match_operand:SI 2 "gpc_reg_operand" ""))
13594          (const_int 0)))
13595    (clobber (match_scratch:SI 3 ""))]
13596   "TARGET_32BIT && reload_completed"
13597   [(set (match_dup 3)
13598         (plus:SI (gt:SI (match_dup 1) (const_int 0))
13599                   (match_dup 2)))
13600    (set (match_dup 0)
13601         (compare:CC (match_dup 3)
13602                     (const_int 0)))]
13603   "")
13604
13605 (define_insn ""
13606   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13607         (compare:CC
13608          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13609                          (const_int 0))
13610                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13611          (const_int 0)))
13612    (clobber (match_scratch:DI 3 "=&r,&r"))]
13613   "TARGET_64BIT"
13614   "@
13615    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
13616    #"
13617   [(set_attr "type" "compare")
13618    (set_attr "length" "12,16")])
13619
13620 (define_split
13621   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13622         (compare:CC
13623          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13624                          (const_int 0))
13625                   (match_operand:DI 2 "gpc_reg_operand" ""))
13626          (const_int 0)))
13627    (clobber (match_scratch:DI 3 ""))]
13628   "TARGET_64BIT && reload_completed"
13629   [(set (match_dup 3)
13630         (plus:DI (gt:DI (match_dup 1) (const_int 0))
13631                  (match_dup 2)))
13632    (set (match_dup 0)
13633         (compare:CC (match_dup 3)
13634                     (const_int 0)))]
13635   "")
13636
13637 (define_insn ""
13638   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13639         (compare:CC
13640          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13641                          (const_int 0))
13642                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13643          (const_int 0)))
13644    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13645         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13646   "TARGET_32BIT"
13647   "@
13648    {a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze.|addze.} %0,%2
13649    #"
13650   [(set_attr "type" "compare")
13651    (set_attr "length" "12,16")])
13652
13653 (define_split
13654   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13655         (compare:CC
13656          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13657                          (const_int 0))
13658                   (match_operand:SI 2 "gpc_reg_operand" ""))
13659          (const_int 0)))
13660    (set (match_operand:SI 0 "gpc_reg_operand" "")
13661         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13662   "TARGET_32BIT && reload_completed"
13663   [(set (match_dup 0)
13664         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
13665    (set (match_dup 3)
13666         (compare:CC (match_dup 0)
13667                     (const_int 0)))]
13668   "")
13669
13670 (define_insn ""
13671   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13672         (compare:CC
13673          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13674                          (const_int 0))
13675                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13676          (const_int 0)))
13677    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
13678         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13679   "TARGET_64BIT"
13680   "@
13681    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
13682    #"
13683   [(set_attr "type" "compare")
13684    (set_attr "length" "12,16")])
13685
13686 (define_split
13687   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13688         (compare:CC
13689          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13690                          (const_int 0))
13691                   (match_operand:DI 2 "gpc_reg_operand" ""))
13692          (const_int 0)))
13693    (set (match_operand:DI 0 "gpc_reg_operand" "")
13694         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13695   "TARGET_64BIT && reload_completed"
13696   [(set (match_dup 0)
13697         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
13698    (set (match_dup 3)
13699         (compare:CC (match_dup 0)
13700                     (const_int 0)))]
13701   "")
13702
13703 (define_insn ""
13704   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13705         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13706                         (match_operand:SI 2 "reg_or_short_operand" "r"))
13707                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
13708   "TARGET_POWER"
13709   "doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
13710   [(set_attr "length" "12")])
13711
13712 (define_insn ""
13713   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13714         (compare:CC
13715          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13716                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13717                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13718          (const_int 0)))
13719    (clobber (match_scratch:SI 4 "=&r,&r"))]
13720   "TARGET_POWER"
13721   "@
13722    doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
13723    #"
13724   [(set_attr "type" "compare")
13725    (set_attr "length" "12,16")])
13726
13727 (define_split
13728   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13729         (compare:CC
13730          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13731                          (match_operand:SI 2 "reg_or_short_operand" ""))
13732                   (match_operand:SI 3 "gpc_reg_operand" ""))
13733          (const_int 0)))
13734    (clobber (match_scratch:SI 4 ""))]
13735   "TARGET_POWER && reload_completed"
13736   [(set (match_dup 4)
13737         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13738    (set (match_dup 0)
13739         (compare:CC (match_dup 4)
13740                     (const_int 0)))]
13741   "")
13742
13743 (define_insn ""
13744   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13745         (compare:CC
13746          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13747                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13748                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13749          (const_int 0)))
13750    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13751         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13752   "TARGET_POWER"
13753   "@
13754    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
13755    #"
13756   [(set_attr "type" "compare")
13757    (set_attr "length" "12,16")])
13758
13759 (define_split
13760   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13761         (compare:CC
13762          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13763                          (match_operand:SI 2 "reg_or_short_operand" ""))
13764                   (match_operand:SI 3 "gpc_reg_operand" ""))
13765          (const_int 0)))
13766    (set (match_operand:SI 0 "gpc_reg_operand" "")
13767         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13768   "TARGET_POWER && reload_completed"
13769   [(set (match_dup 0)
13770         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13771    (set (match_dup 4)
13772         (compare:CC (match_dup 0)
13773                     (const_int 0)))]
13774   "")
13775
13776 (define_insn ""
13777   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13778         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13779                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
13780   "TARGET_POWER"
13781   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
13782   [(set_attr "length" "12")])
13783
13784 (define_insn_and_split "*gtu<mode>"
13785   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13786         (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
13787                (match_operand:P 2 "reg_or_short_operand" "rI")))]
13788   ""
13789   "#"
13790   ""
13791   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
13792    (set (match_dup 0) (neg:P (match_dup 0)))]
13793   "")
13794
13795 (define_insn_and_split "*gtu<mode>_compare"
13796   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13797         (compare:CC
13798          (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13799                  (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
13800          (const_int 0)))
13801    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13802         (gtu:P (match_dup 1) (match_dup 2)))]
13803   ""
13804   "#"
13805   ""
13806   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
13807    (parallel [(set (match_dup 3)
13808                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
13809               (set (match_dup 0) (neg:P (match_dup 0)))])]
13810   "")
13811
13812 (define_insn_and_split "*plus_gtu<mode>"
13813   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13814         (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
13815                        (match_operand:P 2 "reg_or_short_operand" "rI"))
13816                 (match_operand:P 3 "reg_or_short_operand" "rI")))]
13817   ""
13818   "#"
13819   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13820   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
13821    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
13822   "")
13823
13824 (define_insn_and_split "*plus_gtu<mode>_compare"
13825   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13826         (compare:CC
13827          (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13828                         (match_operand:P 2 "reg_or_short_operand" "I,r,I,r"))
13829                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
13830          (const_int 0)))
13831    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13832         (plus:P (gtu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
13833   ""
13834   "#"
13835   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13836   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
13837    (parallel [(set (match_dup 4)
13838                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
13839                                (const_int 0)))
13840               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
13841   "")
13842
13843 (define_insn "*neg_gtu<mode>"
13844   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13845         (neg:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
13846                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
13847   ""
13848   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
13849   [(set_attr "type" "two")
13850    (set_attr "length" "8")])
13851
13852 \f
13853 ;; Define both directions of branch and return.  If we need a reload
13854 ;; register, we'd rather use CR0 since it is much easier to copy a
13855 ;; register CC value to there.
13856
13857 (define_insn ""
13858   [(set (pc)
13859         (if_then_else (match_operator 1 "branch_comparison_operator"
13860                                       [(match_operand 2
13861                                                       "cc_reg_operand" "y")
13862                                        (const_int 0)])
13863                       (label_ref (match_operand 0 "" ""))
13864                       (pc)))]
13865   ""
13866   "*
13867 {
13868   return output_cbranch (operands[1], \"%l0\", 0, insn);
13869 }"
13870   [(set_attr "type" "branch")])
13871
13872 (define_insn ""
13873   [(set (pc)
13874         (if_then_else (match_operator 0 "branch_comparison_operator"
13875                                       [(match_operand 1
13876                                                       "cc_reg_operand" "y")
13877                                        (const_int 0)])
13878                       (return)
13879                       (pc)))]
13880   "direct_return ()"
13881   "*
13882 {
13883   return output_cbranch (operands[0], NULL, 0, insn);
13884 }"
13885   [(set_attr "type" "jmpreg")
13886    (set_attr "length" "4")])
13887
13888 (define_insn ""
13889   [(set (pc)
13890         (if_then_else (match_operator 1 "branch_comparison_operator"
13891                                       [(match_operand 2
13892                                                       "cc_reg_operand" "y")
13893                                        (const_int 0)])
13894                       (pc)
13895                       (label_ref (match_operand 0 "" ""))))]
13896   ""
13897   "*
13898 {
13899   return output_cbranch (operands[1], \"%l0\", 1, insn);
13900 }"
13901   [(set_attr "type" "branch")])
13902
13903 (define_insn ""
13904   [(set (pc)
13905         (if_then_else (match_operator 0 "branch_comparison_operator"
13906                                       [(match_operand 1
13907                                                       "cc_reg_operand" "y")
13908                                        (const_int 0)])
13909                       (pc)
13910                       (return)))]
13911   "direct_return ()"
13912   "*
13913 {
13914   return output_cbranch (operands[0], NULL, 1, insn);
13915 }"
13916   [(set_attr "type" "jmpreg")
13917    (set_attr "length" "4")])
13918
13919 ;; Logic on condition register values.
13920
13921 ; This pattern matches things like
13922 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
13923 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
13924 ;                                  (const_int 1)))
13925 ; which are generated by the branch logic.
13926 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
13927
13928 (define_insn "*cceq_ior_compare"
13929   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13930         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
13931                         [(match_operator:SI 2
13932                                       "branch_positive_comparison_operator"
13933                                       [(match_operand 3
13934                                                       "cc_reg_operand" "y,y")
13935                                        (const_int 0)])
13936                          (match_operator:SI 4
13937                                       "branch_positive_comparison_operator"
13938                                       [(match_operand 5
13939                                                       "cc_reg_operand" "0,y")
13940                                        (const_int 0)])])
13941                       (const_int 1)))]
13942   ""
13943   "cr%q1 %E0,%j2,%j4"
13944   [(set_attr "type" "cr_logical,delayed_cr")])
13945
13946 ; Why is the constant -1 here, but 1 in the previous pattern?
13947 ; Because ~1 has all but the low bit set.
13948 (define_insn ""
13949   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13950         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
13951                         [(not:SI (match_operator:SI 2
13952                                       "branch_positive_comparison_operator"
13953                                       [(match_operand 3
13954                                                       "cc_reg_operand" "y,y")
13955                                        (const_int 0)]))
13956                          (match_operator:SI 4
13957                                 "branch_positive_comparison_operator"
13958                                 [(match_operand 5
13959                                                 "cc_reg_operand" "0,y")
13960                                  (const_int 0)])])
13961                       (const_int -1)))]
13962   ""
13963   "cr%q1 %E0,%j2,%j4"
13964   [(set_attr "type" "cr_logical,delayed_cr")])
13965
13966 (define_insn "*cceq_rev_compare"
13967   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13968         (compare:CCEQ (match_operator:SI 1
13969                                       "branch_positive_comparison_operator"
13970                                       [(match_operand 2
13971                                                       "cc_reg_operand" "0,y")
13972                                        (const_int 0)])
13973                       (const_int 0)))]
13974   ""
13975   "{crnor %E0,%j1,%j1|crnot %E0,%j1}"
13976   [(set_attr "type" "cr_logical,delayed_cr")])
13977
13978 ;; If we are comparing the result of two comparisons, this can be done
13979 ;; using creqv or crxor.
13980
13981 (define_insn_and_split ""
13982   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
13983         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
13984                               [(match_operand 2 "cc_reg_operand" "y")
13985                                (const_int 0)])
13986                       (match_operator 3 "branch_comparison_operator"
13987                               [(match_operand 4 "cc_reg_operand" "y")
13988                                (const_int 0)])))]
13989   ""
13990   "#"
13991   ""
13992   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
13993                                     (match_dup 5)))]
13994   "
13995 {
13996   int positive_1, positive_2;
13997
13998   positive_1 = branch_positive_comparison_operator (operands[1],
13999                                                     GET_MODE (operands[1]));
14000   positive_2 = branch_positive_comparison_operator (operands[3],
14001                                                     GET_MODE (operands[3]));
14002
14003   if (! positive_1)
14004     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
14005                                                             GET_CODE (operands[1])),
14006                                   SImode,
14007                                   operands[2], const0_rtx);
14008   else if (GET_MODE (operands[1]) != SImode)
14009     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
14010                                   operands[2], const0_rtx);
14011
14012   if (! positive_2)
14013     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
14014                                                             GET_CODE (operands[3])),
14015                                   SImode,
14016                                   operands[4], const0_rtx);
14017   else if (GET_MODE (operands[3]) != SImode)
14018     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
14019                                   operands[4], const0_rtx);
14020
14021   if (positive_1 == positive_2)
14022     {
14023       operands[1] = gen_rtx_NOT (SImode, operands[1]);
14024       operands[5] = constm1_rtx;
14025     }
14026   else
14027     {
14028       operands[5] = const1_rtx;
14029     }
14030 }")
14031
14032 ;; Unconditional branch and return.
14033
14034 (define_insn "jump"
14035   [(set (pc)
14036         (label_ref (match_operand 0 "" "")))]
14037   ""
14038   "b %l0"
14039   [(set_attr "type" "branch")])
14040
14041 (define_insn "return"
14042   [(return)]
14043   "direct_return ()"
14044   "{br|blr}"
14045   [(set_attr "type" "jmpreg")])
14046
14047 (define_expand "indirect_jump"
14048   [(set (pc) (match_operand 0 "register_operand" ""))])
14049
14050 (define_insn "*indirect_jump<mode>"
14051   [(set (pc) (match_operand:P 0 "register_operand" "c,*l"))]
14052   ""
14053   "@
14054    bctr
14055    {br|blr}"
14056   [(set_attr "type" "jmpreg")])
14057
14058 ;; Table jump for switch statements:
14059 (define_expand "tablejump"
14060   [(use (match_operand 0 "" ""))
14061    (use (label_ref (match_operand 1 "" "")))]
14062   ""
14063   "
14064 {
14065   if (TARGET_32BIT)
14066     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
14067   else
14068     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
14069   DONE;
14070 }")
14071
14072 (define_expand "tablejumpsi"
14073   [(set (match_dup 3)
14074         (plus:SI (match_operand:SI 0 "" "")
14075                  (match_dup 2)))
14076    (parallel [(set (pc) (match_dup 3))
14077               (use (label_ref (match_operand 1 "" "")))])]
14078   "TARGET_32BIT"
14079   "
14080 { operands[0] = force_reg (SImode, operands[0]);
14081   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
14082   operands[3] = gen_reg_rtx (SImode);
14083 }")
14084
14085 (define_expand "tablejumpdi"
14086   [(set (match_dup 4)
14087         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "")))
14088    (set (match_dup 3)
14089         (plus:DI (match_dup 4)
14090                  (match_dup 2)))
14091    (parallel [(set (pc) (match_dup 3))
14092               (use (label_ref (match_operand 1 "" "")))])]
14093   "TARGET_64BIT"
14094   "
14095 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
14096   operands[3] = gen_reg_rtx (DImode);
14097   operands[4] = gen_reg_rtx (DImode);
14098 }")
14099
14100 (define_insn "*tablejump<mode>_internal1"
14101   [(set (pc)
14102         (match_operand:P 0 "register_operand" "c,*l"))
14103    (use (label_ref (match_operand 1 "" "")))]
14104   ""
14105   "@
14106    bctr
14107    {br|blr}"
14108   [(set_attr "type" "jmpreg")])
14109
14110 (define_insn "nop"
14111   [(const_int 0)]
14112   ""
14113   "{cror 0,0,0|nop}")
14114 \f
14115 ;; Define the subtract-one-and-jump insns, starting with the template
14116 ;; so loop.c knows what to generate.
14117
14118 (define_expand "doloop_end"
14119   [(use (match_operand 0 "" ""))        ; loop pseudo
14120    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
14121    (use (match_operand 2 "" ""))        ; max iterations
14122    (use (match_operand 3 "" ""))        ; loop level
14123    (use (match_operand 4 "" ""))]       ; label
14124   ""
14125   "
14126 {
14127   /* Only use this on innermost loops.  */
14128   if (INTVAL (operands[3]) > 1)
14129     FAIL;
14130   if (TARGET_64BIT)
14131     {
14132       if (GET_MODE (operands[0]) != DImode)
14133         FAIL;
14134       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
14135     }
14136   else
14137     {
14138       if (GET_MODE (operands[0]) != SImode)
14139         FAIL;
14140       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
14141     }
14142   DONE;
14143 }")
14144
14145 (define_expand "ctr<mode>"
14146   [(parallel [(set (pc)
14147                    (if_then_else (ne (match_operand:P 0 "register_operand" "")
14148                                      (const_int 1))
14149                                  (label_ref (match_operand 1 "" ""))
14150                                  (pc)))
14151               (set (match_dup 0)
14152                    (plus:P (match_dup 0)
14153                             (const_int -1)))
14154               (clobber (match_scratch:CC 2 ""))
14155               (clobber (match_scratch:P 3 ""))])]
14156   ""
14157   "")
14158
14159 ;; We need to be able to do this for any operand, including MEM, or we
14160 ;; will cause reload to blow up since we don't allow output reloads on
14161 ;; JUMP_INSNs.
14162 ;; For the length attribute to be calculated correctly, the
14163 ;; label MUST be operand 0.
14164
14165 (define_insn "*ctr<mode>_internal1"
14166   [(set (pc)
14167         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14168                           (const_int 1))
14169                       (label_ref (match_operand 0 "" ""))
14170                       (pc)))
14171    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14172         (plus:P (match_dup 1)
14173                  (const_int -1)))
14174    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14175    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14176   ""
14177   "*
14178 {
14179   if (which_alternative != 0)
14180     return \"#\";
14181   else if (get_attr_length (insn) == 4)
14182     return \"{bdn|bdnz} %l0\";
14183   else
14184     return \"bdz $+8\;b %l0\";
14185 }"
14186   [(set_attr "type" "branch")
14187    (set_attr "length" "*,12,16,16")])
14188
14189 (define_insn "*ctr<mode>_internal2"
14190   [(set (pc)
14191         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14192                           (const_int 1))
14193                       (pc)
14194                       (label_ref (match_operand 0 "" ""))))
14195    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14196         (plus:P (match_dup 1)
14197                  (const_int -1)))
14198    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14199    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14200   ""
14201   "*
14202 {
14203   if (which_alternative != 0)
14204     return \"#\";
14205   else if (get_attr_length (insn) == 4)
14206     return \"bdz %l0\";
14207   else
14208     return \"{bdn|bdnz} $+8\;b %l0\";
14209 }"
14210   [(set_attr "type" "branch")
14211    (set_attr "length" "*,12,16,16")])
14212
14213 ;; Similar but use EQ
14214
14215 (define_insn "*ctr<mode>_internal5"
14216   [(set (pc)
14217         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14218                           (const_int 1))
14219                       (label_ref (match_operand 0 "" ""))
14220                       (pc)))
14221    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14222         (plus:P (match_dup 1)
14223                  (const_int -1)))
14224    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14225    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14226   ""
14227   "*
14228 {
14229   if (which_alternative != 0)
14230     return \"#\";
14231   else if (get_attr_length (insn) == 4)
14232     return \"bdz %l0\";
14233   else
14234     return \"{bdn|bdnz} $+8\;b %l0\";
14235 }"
14236   [(set_attr "type" "branch")
14237    (set_attr "length" "*,12,16,16")])
14238
14239 (define_insn "*ctr<mode>_internal6"
14240   [(set (pc)
14241         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14242                           (const_int 1))
14243                       (pc)
14244                       (label_ref (match_operand 0 "" ""))))
14245    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14246         (plus:P (match_dup 1)
14247                  (const_int -1)))
14248    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14249    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14250   ""
14251   "*
14252 {
14253   if (which_alternative != 0)
14254     return \"#\";
14255   else if (get_attr_length (insn) == 4)
14256     return \"{bdn|bdnz} %l0\";
14257   else
14258     return \"bdz $+8\;b %l0\";
14259 }"
14260   [(set_attr "type" "branch")
14261    (set_attr "length" "*,12,16,16")])
14262
14263 ;; Now the splitters if we could not allocate the CTR register
14264
14265 (define_split
14266   [(set (pc)
14267         (if_then_else (match_operator 2 "comparison_operator"
14268                                       [(match_operand:P 1 "gpc_reg_operand" "")
14269                                        (const_int 1)])
14270                       (match_operand 5 "" "")
14271                       (match_operand 6 "" "")))
14272    (set (match_operand:P 0 "gpc_reg_operand" "")
14273         (plus:P (match_dup 1) (const_int -1)))
14274    (clobber (match_scratch:CC 3 ""))
14275    (clobber (match_scratch:P 4 ""))]
14276   "reload_completed"
14277   [(parallel [(set (match_dup 3)
14278                    (compare:CC (plus:P (match_dup 1)
14279                                         (const_int -1))
14280                                (const_int 0)))
14281               (set (match_dup 0)
14282                    (plus:P (match_dup 1)
14283                             (const_int -1)))])
14284    (set (pc) (if_then_else (match_dup 7)
14285                            (match_dup 5)
14286                            (match_dup 6)))]
14287   "
14288 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14289                                 operands[3], const0_rtx); }")
14290
14291 (define_split
14292   [(set (pc)
14293         (if_then_else (match_operator 2 "comparison_operator"
14294                                       [(match_operand:P 1 "gpc_reg_operand" "")
14295                                        (const_int 1)])
14296                       (match_operand 5 "" "")
14297                       (match_operand 6 "" "")))
14298    (set (match_operand:P 0 "nonimmediate_operand" "")
14299         (plus:P (match_dup 1) (const_int -1)))
14300    (clobber (match_scratch:CC 3 ""))
14301    (clobber (match_scratch:P 4 ""))]
14302   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
14303   [(parallel [(set (match_dup 3)
14304                    (compare:CC (plus:P (match_dup 1)
14305                                         (const_int -1))
14306                                (const_int 0)))
14307               (set (match_dup 4)
14308                    (plus:P (match_dup 1)
14309                             (const_int -1)))])
14310    (set (match_dup 0)
14311         (match_dup 4))
14312    (set (pc) (if_then_else (match_dup 7)
14313                            (match_dup 5)
14314                            (match_dup 6)))]
14315   "
14316 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14317                                 operands[3], const0_rtx); }")
14318 \f
14319 (define_insn "trap"
14320   [(trap_if (const_int 1) (const_int 0))]
14321   ""
14322   "{t 31,0,0|trap}"
14323   [(set_attr "type" "trap")])
14324
14325 (define_expand "conditional_trap"
14326   [(trap_if (match_operator 0 "trap_comparison_operator"
14327                             [(match_dup 2) (match_dup 3)])
14328             (match_operand 1 "const_int_operand" ""))]
14329   ""
14330   "if (rs6000_compare_fp_p || operands[1] != const0_rtx) FAIL;
14331    operands[2] = rs6000_compare_op0;
14332    operands[3] = rs6000_compare_op1;")
14333
14334 (define_insn ""
14335   [(trap_if (match_operator 0 "trap_comparison_operator"
14336                             [(match_operand:GPR 1 "register_operand" "r")
14337                              (match_operand:GPR 2 "reg_or_short_operand" "rI")])
14338             (const_int 0))]
14339   ""
14340   "{t|t<wd>}%V0%I2 %1,%2"
14341   [(set_attr "type" "trap")])
14342 \f
14343 ;; Insns related to generating the function prologue and epilogue.
14344
14345 (define_expand "prologue"
14346   [(use (const_int 0))]
14347   "TARGET_SCHED_PROLOG"
14348   "
14349 {
14350       rs6000_emit_prologue ();
14351       DONE;
14352 }")
14353
14354 (define_insn "*movesi_from_cr_one"
14355   [(match_parallel 0 "mfcr_operation"
14356                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14357                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
14358                                      (match_operand 3 "immediate_operand" "n")]
14359                           UNSPEC_MOVESI_FROM_CR))])]
14360   "TARGET_MFCRF"
14361   "*
14362 {
14363   int mask = 0;
14364   int i;
14365   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14366   {
14367     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14368     operands[4] = GEN_INT (mask);
14369     output_asm_insn (\"mfcr %1,%4\", operands);
14370   }
14371   return \"\";
14372 }"
14373   [(set_attr "type" "mfcrf")])
14374
14375 (define_insn "movesi_from_cr"
14376   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14377         (unspec:SI [(reg:CC 68) (reg:CC 69) (reg:CC 70) (reg:CC 71)
14378                     (reg:CC 72) (reg:CC 73) (reg:CC 74) (reg:CC 75)]
14379                    UNSPEC_MOVESI_FROM_CR))]
14380   ""
14381   "mfcr %0"
14382   [(set_attr "type" "mfcr")])
14383
14384 (define_insn "*stmw"
14385   [(match_parallel 0 "stmw_operation"
14386                    [(set (match_operand:SI 1 "memory_operand" "=m")
14387                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
14388   "TARGET_MULTIPLE"
14389   "{stm|stmw} %2,%1"
14390   [(set_attr "type" "store_ux")])
14391
14392 (define_insn "*save_fpregs_<mode>"
14393   [(match_parallel 0 "any_parallel_operand"
14394                    [(clobber (reg:P 65))
14395                     (use (match_operand:P 1 "call_operand" "s"))
14396                     (set (match_operand:DF 2 "memory_operand" "=m")
14397                          (match_operand:DF 3 "gpc_reg_operand" "f"))])]
14398   ""
14399   "bl %z1"
14400   [(set_attr "type" "branch")
14401    (set_attr "length" "4")])
14402
14403 ; These are to explain that changes to the stack pointer should
14404 ; not be moved over stores to stack memory.
14405 (define_insn "stack_tie"
14406   [(set (match_operand:BLK 0 "memory_operand" "+m")
14407         (unspec:BLK [(match_dup 0)] UNSPEC_TIE))]
14408   ""
14409   ""
14410   [(set_attr "length" "0")])
14411
14412
14413 (define_expand "epilogue"
14414   [(use (const_int 0))]
14415   "TARGET_SCHED_PROLOG"
14416   "
14417 {
14418       rs6000_emit_epilogue (FALSE);
14419       DONE;
14420 }")
14421
14422 ; On some processors, doing the mtcrf one CC register at a time is
14423 ; faster (like on the 604e).  On others, doing them all at once is
14424 ; faster; for instance, on the 601 and 750.
14425
14426 (define_expand "movsi_to_cr_one"
14427   [(set (match_operand:CC 0 "cc_reg_operand" "")
14428         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "")
14429                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
14430   ""
14431   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
14432
14433 (define_insn "*movsi_to_cr"
14434   [(match_parallel 0 "mtcrf_operation"
14435                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
14436                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
14437                                      (match_operand 3 "immediate_operand" "n")]
14438                                     UNSPEC_MOVESI_TO_CR))])]
14439  ""
14440  "*
14441 {
14442   int mask = 0;
14443   int i;
14444   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14445     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14446   operands[4] = GEN_INT (mask);
14447   return \"mtcrf %4,%2\";
14448 }"
14449   [(set_attr "type" "mtcr")])
14450
14451 (define_insn "*mtcrfsi"
14452   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14453         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14454                     (match_operand 2 "immediate_operand" "n")]
14455                    UNSPEC_MOVESI_TO_CR))]
14456   "GET_CODE (operands[0]) == REG
14457    && CR_REGNO_P (REGNO (operands[0]))
14458    && GET_CODE (operands[2]) == CONST_INT
14459    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
14460   "mtcrf %R0,%1"
14461   [(set_attr "type" "mtcr")])
14462
14463 ; The load-multiple instructions have similar properties.
14464 ; Note that "load_multiple" is a name known to the machine-independent
14465 ; code that actually corresponds to the PowerPC load-string.
14466
14467 (define_insn "*lmw"
14468   [(match_parallel 0 "lmw_operation"
14469                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14470                          (match_operand:SI 2 "memory_operand" "m"))])]
14471   "TARGET_MULTIPLE"
14472   "{lm|lmw} %1,%2"
14473   [(set_attr "type" "load_ux")])
14474
14475 (define_insn "*return_internal_<mode>"
14476   [(return)
14477    (use (match_operand:P 0 "register_operand" "lc"))]
14478   ""
14479   "b%T0"
14480   [(set_attr "type" "jmpreg")])
14481
14482 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
14483 ; stuff was in GCC.  Oh, and "any_parallel_operand" is a bit flexible...
14484
14485 (define_insn "*return_and_restore_fpregs_<mode>"
14486  [(match_parallel 0 "any_parallel_operand"
14487                   [(return)
14488                    (use (reg:P 65))
14489                    (use (match_operand:P 1 "call_operand" "s"))
14490                    (set (match_operand:DF 2 "gpc_reg_operand" "=f")
14491                         (match_operand:DF 3 "memory_operand" "m"))])]
14492  ""
14493  "b %z1")
14494
14495 ; This is used in compiling the unwind routines.
14496 (define_expand "eh_return"
14497   [(use (match_operand 0 "general_operand" ""))]
14498   ""
14499   "
14500 {
14501   if (TARGET_32BIT)
14502     emit_insn (gen_eh_set_lr_si (operands[0]));
14503   else
14504     emit_insn (gen_eh_set_lr_di (operands[0]));
14505   DONE;
14506 }")
14507
14508 ; We can't expand this before we know where the link register is stored.
14509 (define_insn "eh_set_lr_<mode>"
14510   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
14511                     UNSPECV_EH_RR)
14512    (clobber (match_scratch:P 1 "=&b"))]
14513   ""
14514   "#")
14515
14516 (define_split
14517   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
14518    (clobber (match_scratch 1 ""))]
14519   "reload_completed"
14520   [(const_int 0)]
14521   "
14522 {
14523   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
14524   DONE;
14525 }")
14526
14527 (define_insn "prefetch"
14528   [(prefetch (match_operand 0 "indexed_or_indirect_address" "a")
14529              (match_operand:SI 1 "const_int_operand" "n")
14530              (match_operand:SI 2 "const_int_operand" "n"))]
14531   "TARGET_POWERPC"
14532   "*
14533 {
14534   if (GET_CODE (operands[0]) == REG)
14535     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
14536   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
14537 }"
14538   [(set_attr "type" "load")])
14539 \f
14540
14541 (include "sync.md")
14542 (include "altivec.md")
14543 (include "spe.md")
14544 (include "dfp.md")